From 9659cdfed40df1afc53c9baa4366004a55fe3e77 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 30 Mar 2010 07:18:49 +0000 Subject: [PATCH 0001/1766] Initial empty git commit. Migrated the OpenZAP project from Subversion to Git in March 2010. From 92cfdfe2625f22f16b7b93c3318f4d924be257cc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 20:36:40 +0000 Subject: [PATCH 0002/1766] w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@2 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 54 ++++++ libs/openzap/hashtable.c | 274 +++++++++++++++++++++++++++++++ libs/openzap/hashtable.h | 199 ++++++++++++++++++++++ libs/openzap/hashtable_itr.c | 176 ++++++++++++++++++++ libs/openzap/hashtable_itr.h | 104 ++++++++++++ libs/openzap/hashtable_private.h | 82 +++++++++ libs/openzap/openzap.c | 256 +++++++++++++++++++++++++++++ libs/openzap/openzap.h | 190 +++++++++++++++++++++ libs/openzap/zap_config.c | 220 +++++++++++++++++++++++++ libs/openzap/zap_config.h | 131 +++++++++++++++ libs/openzap/zap_skel.c | 48 ++++++ libs/openzap/zap_skel.h | 41 +++++ libs/openzap/zap_wanpipe.c | 48 ++++++ libs/openzap/zap_wanpipe.h | 41 +++++ libs/openzap/zap_zt.c | 48 ++++++ libs/openzap/zap_zt.h | 41 +++++ 16 files changed, 1953 insertions(+) create mode 100644 libs/openzap/Makefile create mode 100644 libs/openzap/hashtable.c create mode 100644 libs/openzap/hashtable.h create mode 100644 libs/openzap/hashtable_itr.c create mode 100644 libs/openzap/hashtable_itr.h create mode 100644 libs/openzap/hashtable_private.h create mode 100644 libs/openzap/openzap.c create mode 100644 libs/openzap/openzap.h create mode 100644 libs/openzap/zap_config.c create mode 100644 libs/openzap/zap_config.h create mode 100644 libs/openzap/zap_skel.c create mode 100644 libs/openzap/zap_skel.h create mode 100644 libs/openzap/zap_wanpipe.c create mode 100644 libs/openzap/zap_wanpipe.h create mode 100644 libs/openzap/zap_zt.c create mode 100644 libs/openzap/zap_zt.h diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile new file mode 100644 index 0000000000..a9a87dbd6d --- /dev/null +++ b/libs/openzap/Makefile @@ -0,0 +1,54 @@ +# Copyright (c) 2007, Anthony Minessale II +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the original author; nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +CC=gcc +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o +CFLAGS=$(USER_CFLAGS) -Wall -Werror -Wextra -std=c99 -pedantic -ansi +MYLIB=libopenzap.a + +CFLAGS +=-DZAP_WANPIPE_SUPPORT +OBJS += zap_wanpipe.o + +#CFLAGS +=-DZAP_ZT_SUPPORT +#OBJS += zap_zt.o + + +$(MYLIB): $(OBJS) + ar rcs $(MYLIB) $(OBJS) + ranlib $(MYLIB) +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +all: $(MYLIB) + +clean: + rm -f *.o $(MYLIB) *~ \#* + diff --git a/libs/openzap/hashtable.c b/libs/openzap/hashtable.c new file mode 100644 index 0000000000..763357edce --- /dev/null +++ b/libs/openzap/hashtable.c @@ -0,0 +1,274 @@ +/* Copyright (C) 2004 Christopher Clark */ + +#include "hashtable.h" +#include "hashtable_private.h" +#include +#include +#include +#include + +/* +Credit for primes table: Aaron Krowne + http://br.endernet.org/~akrowne/ + http://planetmath.org/encyclopedia/GoodHashTablePrimes.html +*/ +static const unsigned int primes[] = { +53, 97, 193, 389, +769, 1543, 3079, 6151, +12289, 24593, 49157, 98317, +196613, 393241, 786433, 1572869, +3145739, 6291469, 12582917, 25165843, +50331653, 100663319, 201326611, 402653189, +805306457, 1610612741 +}; +const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); +const float max_load_factor = 0.65; + +/*****************************************************************************/ +struct hashtable * +create_hashtable(unsigned int minsize, + unsigned int (*hashf) (void*), + int (*eqf) (void*,void*)) +{ + struct hashtable *h; + unsigned int pindex, size = primes[0]; + /* Check requested hashtable isn't too large */ + if (minsize > (1u << 30)) return NULL; + /* Enforce size as prime */ + for (pindex=0; pindex < prime_table_length; pindex++) { + if (primes[pindex] > minsize) { size = primes[pindex]; break; } + } + h = (struct hashtable *)malloc(sizeof(struct hashtable)); + if (NULL == h) return NULL; /*oom*/ + h->table = (struct entry **)malloc(sizeof(struct entry*) * size); + if (NULL == h->table) { free(h); return NULL; } /*oom*/ + memset(h->table, 0, size * sizeof(struct entry *)); + h->tablelength = size; + h->primeindex = pindex; + h->entrycount = 0; + h->hashfn = hashf; + h->eqfn = eqf; + h->loadlimit = (unsigned int) ceil(size * max_load_factor); + return h; +} + +/*****************************************************************************/ +unsigned int +hash(struct hashtable *h, void *k) +{ + /* Aim to protect against poor hash functions by adding logic here + * - logic taken from java 1.4 hashtable source */ + unsigned int i = h->hashfn(k); + i += ~(i << 9); + i ^= ((i >> 14) | (i << 18)); /* >>> */ + i += (i << 4); + i ^= ((i >> 10) | (i << 22)); /* >>> */ + return i; +} + +/*****************************************************************************/ +static int +hashtable_expand(struct hashtable *h) +{ + /* Double the size of the table to accomodate more entries */ + struct entry **newtable; + struct entry *e; + struct entry **pE; + unsigned int newsize, i, index; + /* Check we're not hitting max capacity */ + if (h->primeindex == (prime_table_length - 1)) return 0; + newsize = primes[++(h->primeindex)]; + + newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); + if (NULL != newtable) + { + memset(newtable, 0, newsize * sizeof(struct entry *)); + /* This algorithm is not 'stable'. ie. it reverses the list + * when it transfers entries between the tables */ + for (i = 0; i < h->tablelength; i++) { + while (NULL != (e = h->table[i])) { + h->table[i] = e->next; + index = indexFor(newsize,e->h); + e->next = newtable[index]; + newtable[index] = e; + } + } + free(h->table); + h->table = newtable; + } + /* Plan B: realloc instead */ + else + { + newtable = (struct entry **) + realloc(h->table, newsize * sizeof(struct entry *)); + if (NULL == newtable) { (h->primeindex)--; return 0; } + h->table = newtable; + memset(newtable[h->tablelength], 0, newsize - h->tablelength); + for (i = 0; i < h->tablelength; i++) { + for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { + index = indexFor(newsize,e->h); + if (index == i) + { + pE = &(e->next); + } + else + { + *pE = e->next; + e->next = newtable[index]; + newtable[index] = e; + } + } + } + } + h->tablelength = newsize; + h->loadlimit = (unsigned int) ceil(newsize * max_load_factor); + return -1; +} + +/*****************************************************************************/ +unsigned int +hashtable_count(struct hashtable *h) +{ + return h->entrycount; +} + +/*****************************************************************************/ +int +hashtable_insert(struct hashtable *h, void *k, void *v) +{ + /* This method allows duplicate keys - but they shouldn't be used */ + unsigned int index; + struct entry *e; + if (++(h->entrycount) > h->loadlimit) + { + /* Ignore the return value. If expand fails, we should + * still try cramming just this value into the existing table + * -- we may not have memory for a larger table, but one more + * element may be ok. Next time we insert, we'll try expanding again.*/ + hashtable_expand(h); + } + e = (struct entry *)malloc(sizeof(struct entry)); + if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ + e->h = hash(h,k); + index = indexFor(h->tablelength,e->h); + e->k = k; + e->v = v; + e->next = h->table[index]; + h->table[index] = e; + return -1; +} + +/*****************************************************************************/ +void * /* returns value associated with key */ +hashtable_search(struct hashtable *h, void *k) +{ + struct entry *e; + unsigned int hashvalue, index; + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hashvalue); + e = h->table[index]; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; + e = e->next; + } + return NULL; +} + +/*****************************************************************************/ +void * /* returns value associated with key */ +hashtable_remove(struct hashtable *h, void *k) +{ + /* TODO: consider compacting the table when the load factor drops enough, + * or provide a 'compact' method. */ + + struct entry *e; + struct entry **pE; + void *v; + unsigned int hashvalue, index; + + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hash(h,k)); + pE = &(h->table[index]); + e = *pE; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + *pE = e->next; + h->entrycount--; + v = e->v; + freekey(e->k); + free(e); + return v; + } + pE = &(e->next); + e = e->next; + } + return NULL; +} + +/*****************************************************************************/ +/* destroy */ +void +hashtable_destroy(struct hashtable *h, int free_values) +{ + unsigned int i; + struct entry *e, *f; + struct entry **table = h->table; + if (free_values) + { + for (i = 0; i < h->tablelength; i++) + { + e = table[i]; + while (NULL != e) + { f = e; e = e->next; freekey(f->k); free(f->v); free(f); } + } + } + else + { + for (i = 0; i < h->tablelength; i++) + { + e = table[i]; + while (NULL != e) + { f = e; e = e->next; freekey(f->k); free(f); } + } + } + free(h->table); + free(h); +} + +/* + * Copyright (c) 2002, Christopher Clark + * 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. +*/ diff --git a/libs/openzap/hashtable.h b/libs/openzap/hashtable.h new file mode 100644 index 0000000000..b90781abd4 --- /dev/null +++ b/libs/openzap/hashtable.h @@ -0,0 +1,199 @@ +/* Copyright (C) 2002 Christopher Clark */ + +#ifndef __HASHTABLE_CWC22_H__ +#define __HASHTABLE_CWC22_H__ + +struct hashtable; + +/* Example of use: + * + * struct hashtable *h; + * struct some_key *k; + * struct some_value *v; + * + * static unsigned int hash_from_key_fn( void *k ); + * static int keys_equal_fn ( void *key1, void *key2 ); + * + * h = create_hashtable(16, hash_from_key_fn, keys_equal_fn); + * k = (struct some_key *) malloc(sizeof(struct some_key)); + * v = (struct some_value *) malloc(sizeof(struct some_value)); + * + * (initialise k and v to suitable values) + * + * if (! hashtable_insert(h,k,v) ) + * { exit(-1); } + * + * if (NULL == (found = hashtable_search(h,k) )) + * { printf("not found!"); } + * + * if (NULL == (found = hashtable_remove(h,k) )) + * { printf("Not found\n"); } + * + */ + +/* Macros may be used to define type-safe(r) hashtable access functions, with + * methods specialized to take known key and value types as parameters. + * + * Example: + * + * Insert this at the start of your file: + * + * DEFINE_HASHTABLE_INSERT(insert_some, struct some_key, struct some_value); + * DEFINE_HASHTABLE_SEARCH(search_some, struct some_key, struct some_value); + * DEFINE_HASHTABLE_REMOVE(remove_some, struct some_key, struct some_value); + * + * This defines the functions 'insert_some', 'search_some' and 'remove_some'. + * These operate just like hashtable_insert etc., with the same parameters, + * but their function signatures have 'struct some_key *' rather than + * 'void *', and hence can generate compile time errors if your program is + * supplying incorrect data as a key (and similarly for value). + * + * Note that the hash and key equality functions passed to create_hashtable + * still take 'void *' parameters instead of 'some key *'. This shouldn't be + * a difficult issue as they're only defined and passed once, and the other + * functions will ensure that only valid keys are supplied to them. + * + * The cost for this checking is increased code size and runtime overhead + * - if performance is important, it may be worth switching back to the + * unsafe methods once your program has been debugged with the safe methods. + * This just requires switching to some simple alternative defines - eg: + * #define insert_some hashtable_insert + * + */ + +/***************************************************************************** + * create_hashtable + + * @name create_hashtable + * @param minsize minimum initial size of hashtable + * @param hashfunction function for hashing keys + * @param key_eq_fn function for determining key equality + * @return newly created hashtable or NULL on failure + */ + +struct hashtable * +create_hashtable(unsigned int minsize, + unsigned int (*hashfunction) (void*), + int (*key_eq_fn) (void*,void*)); + +/***************************************************************************** + * hashtable_insert + + * @name hashtable_insert + * @param h the hashtable to insert into + * @param k the key - hashtable claims ownership and will free on removal + * @param v the value - does not claim ownership + * @return non-zero for successful insertion + * + * This function will cause the table to expand if the insertion would take + * the ratio of entries to table size over the maximum load factor. + * + * This function does not check for repeated insertions with a duplicate key. + * The value returned when using a duplicate key is undefined -- when + * the hashtable changes size, the order of retrieval of duplicate key + * entries is reversed. + * If in doubt, remove before insert. + */ + +int +hashtable_insert(struct hashtable *h, void *k, void *v); + +#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ +int fnname (struct hashtable *h, keytype *k, valuetype *v) \ +{ \ + return hashtable_insert(h,k,v); \ +} + +/***************************************************************************** + * hashtable_search + + * @name hashtable_search + * @param h the hashtable to search + * @param k the key to search for - does not claim ownership + * @return the value associated with the key, or NULL if none found + */ + +void * +hashtable_search(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ +valuetype * fnname (struct hashtable *h, keytype *k) \ +{ \ + return (valuetype *) (hashtable_search(h,k)); \ +} + +/***************************************************************************** + * hashtable_remove + + * @name hashtable_remove + * @param h the hashtable to remove the item from + * @param k the key to search for - does not claim ownership + * @return the value associated with the key, or NULL if none found + */ + +void * /* returns value */ +hashtable_remove(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ +valuetype * fnname (struct hashtable *h, keytype *k) \ +{ \ + return (valuetype *) (hashtable_remove(h,k)); \ +} + + +/***************************************************************************** + * hashtable_count + + * @name hashtable_count + * @param h the hashtable + * @return the number of items stored in the hashtable + */ +unsigned int +hashtable_count(struct hashtable *h); + + +/***************************************************************************** + * hashtable_destroy + + * @name hashtable_destroy + * @param h the hashtable + * @param free_values whether to call 'free' on the remaining values + */ + +void +hashtable_destroy(struct hashtable *h, int free_values); + +#endif /* __HASHTABLE_CWC22_H__ */ + +/* + * Copyright (c) 2002, Christopher Clark + * 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. +*/ diff --git a/libs/openzap/hashtable_itr.c b/libs/openzap/hashtable_itr.c new file mode 100644 index 0000000000..defac691f0 --- /dev/null +++ b/libs/openzap/hashtable_itr.c @@ -0,0 +1,176 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#include "hashtable.h" +#include "hashtable_private.h" +#include "hashtable_itr.h" +#include /* defines NULL */ + +/*****************************************************************************/ +/* hashtable_iterator - iterator constructor */ + +struct hashtable_itr * +hashtable_iterator(struct hashtable *h) +{ + unsigned int i, tablelength; + struct hashtable_itr *itr = (struct hashtable_itr *) + malloc(sizeof(struct hashtable_itr)); + if (NULL == itr) return NULL; + itr->h = h; + itr->e = NULL; + itr->parent = NULL; + tablelength = h->tablelength; + itr->index = tablelength; + if (0 == h->entrycount) return itr; + + for (i = 0; i < tablelength; i++) + { + if (NULL != h->table[i]) + { + itr->e = h->table[i]; + itr->index = i; + break; + } + } + return itr; +} + +/*****************************************************************************/ +/* advance - advance the iterator to the next element + * returns zero if advanced to end of table */ + +int +hashtable_iterator_advance(struct hashtable_itr *itr) +{ + unsigned int j,tablelength; + struct entry **table; + struct entry *next; + if (NULL == itr->e) return 0; /* stupidity check */ + + next = itr->e->next; + if (NULL != next) + { + itr->parent = itr->e; + itr->e = next; + return -1; + } + tablelength = itr->h->tablelength; + itr->parent = NULL; + if (tablelength <= (j = ++(itr->index))) + { + itr->e = NULL; + return 0; + } + table = itr->h->table; + while (NULL == (next = table[j])) + { + if (++j >= tablelength) + { + itr->index = tablelength; + itr->e = NULL; + return 0; + } + } + itr->index = j; + itr->e = next; + return -1; +} + +/*****************************************************************************/ +/* remove - remove the entry at the current iterator position + * and advance the iterator, if there is a successive + * element. + * If you want the value, read it before you remove: + * beware memory leaks if you don't. + * Returns zero if end of iteration. */ + +int +hashtable_iterator_remove(struct hashtable_itr *itr) +{ + struct entry *remember_e, *remember_parent; + int ret; + + /* Do the removal */ + if (NULL == (itr->parent)) + { + /* element is head of a chain */ + itr->h->table[itr->index] = itr->e->next; + } else { + /* element is mid-chain */ + itr->parent->next = itr->e->next; + } + /* itr->e is now outside the hashtable */ + remember_e = itr->e; + itr->h->entrycount--; + freekey(remember_e->k); + + /* Advance the iterator, correcting the parent */ + remember_parent = itr->parent; + ret = hashtable_iterator_advance(itr); + if (itr->parent == remember_e) { itr->parent = remember_parent; } + free(remember_e); + return ret; +} + +/*****************************************************************************/ +int /* returns zero if not found */ +hashtable_iterator_search(struct hashtable_itr *itr, + struct hashtable *h, void *k) +{ + struct entry *e, *parent; + unsigned int hashvalue, index; + + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hashvalue); + + e = h->table[index]; + parent = NULL; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + itr->index = index; + itr->e = e; + itr->parent = parent; + itr->h = h; + return -1; + } + parent = e; + e = e->next; + } + return 0; +} + + +/* + * Copyright (c) 2002, 2004, Christopher Clark + * 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. +*/ diff --git a/libs/openzap/hashtable_itr.h b/libs/openzap/hashtable_itr.h new file mode 100644 index 0000000000..50ea10420a --- /dev/null +++ b/libs/openzap/hashtable_itr.h @@ -0,0 +1,104 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#ifndef __HASHTABLE_ITR_CWC22__ +#define __HASHTABLE_ITR_CWC22__ +#include "hashtable.h" +#include "hashtable_private.h" /* needed to enable inlining */ + +/*****************************************************************************/ +/* This struct is only concrete here to allow the inlining of two of the + * accessor functions. */ +struct hashtable_itr +{ + struct hashtable *h; + struct entry *e; + struct entry *parent; + unsigned int index; +}; + + +/*****************************************************************************/ +/* hashtable_iterator + */ + +struct hashtable_itr * +hashtable_iterator(struct hashtable *h); + +/*****************************************************************************/ +/* hashtable_iterator_key + * - return the value of the (key,value) pair at the current position */ + +#define hashtable_iterator_key(i) (void *)i->e->k + +/*****************************************************************************/ +/* value - return the value of the (key,value) pair at the current position */ + +#define hashtable_iterator_value (void *)i->e->v + +/*****************************************************************************/ +/* advance - advance the iterator to the next element + * returns zero if advanced to end of table */ + +int +hashtable_iterator_advance(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* remove - remove current element and advance the iterator to the next element + * NB: if you need the value to free it, read it before + * removing. ie: beware memory leaks! + * returns zero if advanced to end of table */ + +int +hashtable_iterator_remove(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* search - overwrite the supplied iterator, to point to the entry + * matching the supplied key. + h points to the hashtable to be searched. + * returns zero if not found. */ +int +hashtable_iterator_search(struct hashtable_itr *itr, + struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ +int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ +{ \ + return (hashtable_iterator_search(i,h,k)); \ +} + + + +#endif /* __HASHTABLE_ITR_CWC22__*/ + +/* + * Copyright (c) 2002, 2004, Christopher Clark + * 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. +*/ diff --git a/libs/openzap/hashtable_private.h b/libs/openzap/hashtable_private.h new file mode 100644 index 0000000000..cb261e9af2 --- /dev/null +++ b/libs/openzap/hashtable_private.h @@ -0,0 +1,82 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#ifndef __HASHTABLE_PRIVATE_CWC22_H__ +#define __HASHTABLE_PRIVATE_CWC22_H__ + +#include "hashtable.h" + +/*****************************************************************************/ +struct entry +{ + void *k, *v; + unsigned int h; + struct entry *next; +}; + +struct hashtable { + unsigned int tablelength; + struct entry **table; + unsigned int entrycount; + unsigned int loadlimit; + unsigned int primeindex; + unsigned int (*hashfn) (void *k); + int (*eqfn) (void *k1, void *k2); +}; + +/*****************************************************************************/ +unsigned int +hash(struct hashtable *h, void *k); + +/*****************************************************************************/ +/* indexFor */ +#define indexFor(hashvalue, tablelength) (unsigned int)(hashvalue % tablelength) + +/* Only works if tablelength == 2^N */ +/*static inline unsigned int +indexFor(unsigned int tablelength, unsigned int hashvalue) +{ + return (hashvalue & (tablelength - 1u)); +} +*/ + +/*****************************************************************************/ +#define freekey(X) free(X) +/*define freekey(X) ; */ + + +/*****************************************************************************/ + +#endif /* __HASHTABLE_PRIVATE_CWC22_H__*/ + +/* + * Copyright (c) 2002, Christopher Clark + * 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. +*/ diff --git a/libs/openzap/openzap.c b/libs/openzap/openzap.c new file mode 100644 index 0000000000..0ac20f533a --- /dev/null +++ b/libs/openzap/openzap.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#ifdef ZAP_WANPIPE_SUPPORT +#include "zap_wanpipe.h" +#endif +#ifdef ZAP_ZT_SUPPORT +#include "zap_zt.h" +#endif + +static struct { + zap_hash_t *interface_hash; +} globals; + + +static int equalkeys(void *k1, void *k2) +{ + return strcmp((char *) k1, (char *) k2) ? 0 : 1; +} + +static unsigned hashfromstring(void *ky) +{ + unsigned char *str = (unsigned char *) ky; + unsigned hash = 0; + int c; + + while ((c = *str++)) { + hash = c + (hash << 6) + (hash << 16) - hash; + } + + return hash; +} + +zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) +{ + zap_span_t *new_span = NULL; + + assert(zint != NULL); + + if (zint->span_index < ZAP_MAX_SPANS_INTERFACE) { + new_span = &zint->spans[++zint->span_index]; + memset(new_span, 0, sizeof(*new_span)); + zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); + new_span->span_id = zint->span_index; + new_span->zint = zint; + *span = new_span; + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) +{ + if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { + zap_channel_t *new_chan; + new_chan = &span->channels[++span->chan_count]; + new_chan->type = type; + new_chan->sockfd = sockfd; + new_chan->zint = span->zint; + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); + *chan = new_chan; + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +zap_status_t zap_span_destroy(zap_span_t **span); + +zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) +{ + zap_software_interface_t *zint; + + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && + (zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (void *)name))) { + zap_channel_t *check; + check = &zint->spans[span_id].channels[chan_id]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return ZAP_SUCCESS; + } + } + + return ZAP_FAIL; +} + +zap_status_t zap_channel_close(zap_channel_t **zchan) +{ + zap_channel_t *check; + *zchan = NULL; + + assert(zchan != NULL); + check = *zchan; + assert(check != NULL); + + if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + zap_clear_flag(check, ZAP_CHANNEL_OPEN); + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + + +zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->set_codec(zchan, codec); + +} + +zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->set_interval(zchan, ms); + +} + +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->wait(zchan, flags); + +} + + +zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->read(zchan, data, datalen); + +} + + +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->write(zchan, data, datalen); + +} + +zap_status_t zap_global_init(void) +{ + zap_config_t cfg; + char *var, *val; + unsigned configured = 0; + zap_software_interface_t *zint; + + assert(zint = NULL); + + globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); + +#ifdef ZAP_WANPIPE_SUPPORT + if (wanpipe_init(&zint) == ZAP_SUCCESS) { + hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + } +#endif +#ifdef ZAP_ZT_SUPPORT + if (zt_init(&zint) == ZAP_SUCCESS) { + hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + } +#endif + + + if (!zap_config_open_file(&cfg, "openzap.conf")) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "openzap")) { + if (!strcmp(var, "load")) { + zap_software_interface_t *zint; + + if ((zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val))) { + if (zint->configure(zint) == ZAP_SUCCESS) { + configured++; + } + } + } + } + } + + return configured ? ZAP_SUCCESS : ZAP_FAIL; +} + +zap_status_t zap_global_destroy(void) +{ + hashtable_destroy(globals.interface_hash, 1); + +#ifdef ZAP_ZT_SUPPORT + zt_destroy(); +#endif +#ifdef ZAP_WANPIPE_SUPPORT + wanpipe_destroy(); +#endif + return ZAP_SUCCESS; +} diff --git a/libs/openzap/openzap.h b/libs/openzap/openzap.h new file mode 100644 index 0000000000..dcb43ef14f --- /dev/null +++ b/libs/openzap/openzap.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef OPENZAP_H +#define OPENZAP_H + +#define _XOPEN_SOURCE 500 +#include +#include +#include +#ifndef _MSC_VER +#include +#endif +#include +#include "hashtable.h" +#include "zap_config.h" + +#define ZAP_MAX_CHANNELS_SPAN 513 +#define ZAP_MAX_SPANS_INTERFACE 33 + +typedef int zap_socket_t; +typedef size_t zap_size_t; +struct zap_software_interface; + +#define zap_copy_string(x,y,z) strncpy(x, y, z - 1) + +/*! + \brief Test for the existance of a flag on an arbitary object + \param obj the object to test + \param flag the or'd list of flags to test + \return true value if the object has the flags defined +*/ +#define zap_test_flag(obj, flag) ((obj)->flags & flag) + +/*! + \brief Set a flag on an arbitrary object + \param obj the object to set the flags on + \param flag the or'd list of flags to set +*/ +#define zap_set_flag(obj, flag) (obj)->flags |= (flag) + +/*! + \brief Clear a flag on an arbitrary object while locked + \param obj the object to test + \param flag the or'd list of flags to clear +*/ +#define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) + +/*! + \brief Copy flags from one arbitrary object to another + \param dest the object to copy the flags to + \param src the object to copy the flags from + \param flags the flags to copy +*/ +#define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) + + +/*! + \brief Free a pointer and set it to NULL unless it already is NULL + \param it the pointer +*/ +#define zap_safe_free(it) if (it) {free(it);it=NULL;} + +typedef enum { + ZAP_SUCCESS, + ZAP_FAIL +} zap_status_t; + +typedef enum { + ZAP_READ = (1 << 0), + ZAP_WRITE = (1 << 1), + ZAP_ERROR = (1 << 2), + ZAP_EVENT = (1 << 3) +} zap_wait_flag_t; + +typedef enum { + ZAP_CODEC_ULAW = 0, + ZAP_CODEC_ALAW = 8, + ZAP_CODEC_SLIN = 10 +} zap_codec_t; + +typedef enum { + ZAP_SPAN_CONFIGURED = (1 << 0), + ZAP_SPAN_READY = (1 << 1) +} 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_t; + +typedef enum { + ZAP_CHANNEL_CONFIGURED = (1 << 0), + ZAP_CHANNEL_READY = (1 << 1), + ZAP_CHANNEL_OPEN = (1 << 2) +} zap_channel_flag_t; + +struct zap_channel { + unsigned span_id; + unsigned chan_id; + zap_chan_type_t type; + zap_socket_t sockfd; + zap_channel_flag_t flags; + struct zap_software_interface *zint; +}; +typedef struct zap_channel zap_channel_t; + +struct zap_span { + unsigned span_id; + unsigned chan_count; + zap_span_flag_t flags; + struct zap_software_interface *zint; + zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; +}; +typedef struct zap_span zap_span_t; + +typedef zap_status_t (*zint_configure_t)(struct zap_software_interface *zint); +typedef zap_status_t (*zint_open_t)(unsigned span_id, unsigned chan_id, zap_channel_t **zchan); +typedef zap_status_t (*zint_close_t)(zap_channel_t **zchan); +typedef zap_status_t (*zint_set_codec_t)(zap_channel_t *zchan, zap_codec_t codec); +typedef zap_status_t (*zint_set_interval_t)(zap_channel_t *zchan, unsigned ms); +typedef zap_status_t (*zint_wait_t)(zap_channel_t *zchan, zap_wait_flag_t flags); +typedef zap_status_t (*zint_read_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); +typedef zap_status_t (*zint_write_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); + +struct zap_software_interface { + const char *name; + zint_configure_t configure; + zint_open_t open; + zint_close_t close; + zint_set_codec_t set_codec; + zint_set_interval_t set_interval; + zint_wait_t wait; + zint_read_t read; + zint_write_t write; + unsigned span_index; + struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; +}; +typedef struct zap_software_interface zap_software_interface_t; + +zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); +zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); +zap_status_t zap_span_destroy(zap_span_t **span); + +zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_close(zap_channel_t **zchan); +zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec); +zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags); +zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); +zap_status_t zap_global_init(void); +zap_status_t zap_global_destroy(void); + +typedef struct hashtable zap_hash_t; + +#endif diff --git a/libs/openzap/zap_config.c b/libs/openzap/zap_config.c new file mode 100644 index 0000000000..17fa4d0596 --- /dev/null +++ b/libs/openzap/zap_config.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "zap_config.h" + +int zap_config_open_file(zap_config_t *cfg, char *file_path) +{ + FILE *f; + 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; + + if (!(f = fopen(path, "r"))) { + 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; + 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; + 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 = ""; + *val = ""; + 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, '#')) != 0 || (end = strchr(*var, ';')) != 0) { + *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; + +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/zap_config.h b/libs/openzap/zap_config.h new file mode 100644 index 0000000000..61aa93c177 --- /dev/null +++ b/libs/openzap/zap_config.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup config Config File Parser + * @ingroup config + * This module implements a basic interface and file format parser + * + *
+ *
+ * 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; + /*! 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, 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); + + +/** @} */ +#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 expandtab: + */ diff --git a/libs/openzap/zap_skel.c b/libs/openzap/zap_skel.c new file mode 100644 index 0000000000..2cefd04603 --- /dev/null +++ b/libs/openzap/zap_skel.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_skel.h" + +zap_status_t skel_init(zap_software_interface_t **zint) +{ + assert(zint != NULL); + + return ZAP_FAIL; +} + +zap_status_t skel_destroy(void) +{ + return ZAP_FAIL; +} diff --git a/libs/openzap/zap_skel.h b/libs/openzap/zap_skel.h new file mode 100644 index 0000000000..9fdaadf7b5 --- /dev/null +++ b/libs/openzap/zap_skel.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_SKEL_H +#define ZAP_SKEL_H +#include "openzap.h" + +zap_status_t skel_init(zap_software_interface_t **zint); +zap_status_t skel_destroy(void); + +#endif diff --git a/libs/openzap/zap_wanpipe.c b/libs/openzap/zap_wanpipe.c new file mode 100644 index 0000000000..7cce6d6783 --- /dev/null +++ b/libs/openzap/zap_wanpipe.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_wanpipe.h" + +zap_status_t wanpipe_init(zap_software_interface_t **zint) +{ + assert(zint != NULL); + + return ZAP_FAIL; +} + +zap_status_t wanpipe_destroy(void) +{ + return ZAP_FAIL; +} diff --git a/libs/openzap/zap_wanpipe.h b/libs/openzap/zap_wanpipe.h new file mode 100644 index 0000000000..90cd9a0997 --- /dev/null +++ b/libs/openzap/zap_wanpipe.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_WANPIPE_H +#define ZAP_WANPIPE_H +#include "openzap.h" + +zap_status_t wanpipe_init(zap_software_interface_t **zint); +zap_status_t wanpipe_destroy(void); + +#endif diff --git a/libs/openzap/zap_zt.c b/libs/openzap/zap_zt.c new file mode 100644 index 0000000000..012abc76b7 --- /dev/null +++ b/libs/openzap/zap_zt.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_zt.h" + +zap_status_t zt_init(zap_software_interface_t **zint) +{ + assert(zint != NULL); + + return ZAP_FAIL; +} + +zap_status_t zt_destroy(void) +{ + return ZAP_FAIL; +} diff --git a/libs/openzap/zap_zt.h b/libs/openzap/zap_zt.h new file mode 100644 index 0000000000..f9c2f59e0a --- /dev/null +++ b/libs/openzap/zap_zt.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_ZT_H +#define ZAP_ZT_H +#include "openzap.h" + +zap_status_t zt_init(zap_software_interface_t **zint); +zap_status_t zt_destroy(void); + +#endif From 01b7a87d3b6e6120e9e61ef8e7cf35adeb7850ed Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 30 Mar 2010 07:19:21 +0000 Subject: [PATCH 0003/1766] Initial empty git commit. Migrated the FreeTDM project from Subversion to Git in March 2010. From a714b72dfe7a3248c9487046837004860f64610e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 20:36:40 +0000 Subject: [PATCH 0004/1766] w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@2 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 54 ++++++ libs/freetdm/hashtable.c | 274 +++++++++++++++++++++++++++++++ libs/freetdm/hashtable.h | 199 ++++++++++++++++++++++ libs/freetdm/hashtable_itr.c | 176 ++++++++++++++++++++ libs/freetdm/hashtable_itr.h | 104 ++++++++++++ libs/freetdm/hashtable_private.h | 82 +++++++++ libs/freetdm/openzap.c | 256 +++++++++++++++++++++++++++++ libs/freetdm/openzap.h | 190 +++++++++++++++++++++ libs/freetdm/zap_config.c | 220 +++++++++++++++++++++++++ libs/freetdm/zap_config.h | 131 +++++++++++++++ libs/freetdm/zap_skel.c | 48 ++++++ libs/freetdm/zap_skel.h | 41 +++++ libs/freetdm/zap_wanpipe.c | 48 ++++++ libs/freetdm/zap_wanpipe.h | 41 +++++ libs/freetdm/zap_zt.c | 48 ++++++ libs/freetdm/zap_zt.h | 41 +++++ 16 files changed, 1953 insertions(+) create mode 100644 libs/freetdm/Makefile create mode 100644 libs/freetdm/hashtable.c create mode 100644 libs/freetdm/hashtable.h create mode 100644 libs/freetdm/hashtable_itr.c create mode 100644 libs/freetdm/hashtable_itr.h create mode 100644 libs/freetdm/hashtable_private.h create mode 100644 libs/freetdm/openzap.c create mode 100644 libs/freetdm/openzap.h create mode 100644 libs/freetdm/zap_config.c create mode 100644 libs/freetdm/zap_config.h create mode 100644 libs/freetdm/zap_skel.c create mode 100644 libs/freetdm/zap_skel.h create mode 100644 libs/freetdm/zap_wanpipe.c create mode 100644 libs/freetdm/zap_wanpipe.h create mode 100644 libs/freetdm/zap_zt.c create mode 100644 libs/freetdm/zap_zt.h diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile new file mode 100644 index 0000000000..a9a87dbd6d --- /dev/null +++ b/libs/freetdm/Makefile @@ -0,0 +1,54 @@ +# Copyright (c) 2007, Anthony Minessale II +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the original author; nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +CC=gcc +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o +CFLAGS=$(USER_CFLAGS) -Wall -Werror -Wextra -std=c99 -pedantic -ansi +MYLIB=libopenzap.a + +CFLAGS +=-DZAP_WANPIPE_SUPPORT +OBJS += zap_wanpipe.o + +#CFLAGS +=-DZAP_ZT_SUPPORT +#OBJS += zap_zt.o + + +$(MYLIB): $(OBJS) + ar rcs $(MYLIB) $(OBJS) + ranlib $(MYLIB) +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +all: $(MYLIB) + +clean: + rm -f *.o $(MYLIB) *~ \#* + diff --git a/libs/freetdm/hashtable.c b/libs/freetdm/hashtable.c new file mode 100644 index 0000000000..763357edce --- /dev/null +++ b/libs/freetdm/hashtable.c @@ -0,0 +1,274 @@ +/* Copyright (C) 2004 Christopher Clark */ + +#include "hashtable.h" +#include "hashtable_private.h" +#include +#include +#include +#include + +/* +Credit for primes table: Aaron Krowne + http://br.endernet.org/~akrowne/ + http://planetmath.org/encyclopedia/GoodHashTablePrimes.html +*/ +static const unsigned int primes[] = { +53, 97, 193, 389, +769, 1543, 3079, 6151, +12289, 24593, 49157, 98317, +196613, 393241, 786433, 1572869, +3145739, 6291469, 12582917, 25165843, +50331653, 100663319, 201326611, 402653189, +805306457, 1610612741 +}; +const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); +const float max_load_factor = 0.65; + +/*****************************************************************************/ +struct hashtable * +create_hashtable(unsigned int minsize, + unsigned int (*hashf) (void*), + int (*eqf) (void*,void*)) +{ + struct hashtable *h; + unsigned int pindex, size = primes[0]; + /* Check requested hashtable isn't too large */ + if (minsize > (1u << 30)) return NULL; + /* Enforce size as prime */ + for (pindex=0; pindex < prime_table_length; pindex++) { + if (primes[pindex] > minsize) { size = primes[pindex]; break; } + } + h = (struct hashtable *)malloc(sizeof(struct hashtable)); + if (NULL == h) return NULL; /*oom*/ + h->table = (struct entry **)malloc(sizeof(struct entry*) * size); + if (NULL == h->table) { free(h); return NULL; } /*oom*/ + memset(h->table, 0, size * sizeof(struct entry *)); + h->tablelength = size; + h->primeindex = pindex; + h->entrycount = 0; + h->hashfn = hashf; + h->eqfn = eqf; + h->loadlimit = (unsigned int) ceil(size * max_load_factor); + return h; +} + +/*****************************************************************************/ +unsigned int +hash(struct hashtable *h, void *k) +{ + /* Aim to protect against poor hash functions by adding logic here + * - logic taken from java 1.4 hashtable source */ + unsigned int i = h->hashfn(k); + i += ~(i << 9); + i ^= ((i >> 14) | (i << 18)); /* >>> */ + i += (i << 4); + i ^= ((i >> 10) | (i << 22)); /* >>> */ + return i; +} + +/*****************************************************************************/ +static int +hashtable_expand(struct hashtable *h) +{ + /* Double the size of the table to accomodate more entries */ + struct entry **newtable; + struct entry *e; + struct entry **pE; + unsigned int newsize, i, index; + /* Check we're not hitting max capacity */ + if (h->primeindex == (prime_table_length - 1)) return 0; + newsize = primes[++(h->primeindex)]; + + newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); + if (NULL != newtable) + { + memset(newtable, 0, newsize * sizeof(struct entry *)); + /* This algorithm is not 'stable'. ie. it reverses the list + * when it transfers entries between the tables */ + for (i = 0; i < h->tablelength; i++) { + while (NULL != (e = h->table[i])) { + h->table[i] = e->next; + index = indexFor(newsize,e->h); + e->next = newtable[index]; + newtable[index] = e; + } + } + free(h->table); + h->table = newtable; + } + /* Plan B: realloc instead */ + else + { + newtable = (struct entry **) + realloc(h->table, newsize * sizeof(struct entry *)); + if (NULL == newtable) { (h->primeindex)--; return 0; } + h->table = newtable; + memset(newtable[h->tablelength], 0, newsize - h->tablelength); + for (i = 0; i < h->tablelength; i++) { + for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { + index = indexFor(newsize,e->h); + if (index == i) + { + pE = &(e->next); + } + else + { + *pE = e->next; + e->next = newtable[index]; + newtable[index] = e; + } + } + } + } + h->tablelength = newsize; + h->loadlimit = (unsigned int) ceil(newsize * max_load_factor); + return -1; +} + +/*****************************************************************************/ +unsigned int +hashtable_count(struct hashtable *h) +{ + return h->entrycount; +} + +/*****************************************************************************/ +int +hashtable_insert(struct hashtable *h, void *k, void *v) +{ + /* This method allows duplicate keys - but they shouldn't be used */ + unsigned int index; + struct entry *e; + if (++(h->entrycount) > h->loadlimit) + { + /* Ignore the return value. If expand fails, we should + * still try cramming just this value into the existing table + * -- we may not have memory for a larger table, but one more + * element may be ok. Next time we insert, we'll try expanding again.*/ + hashtable_expand(h); + } + e = (struct entry *)malloc(sizeof(struct entry)); + if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ + e->h = hash(h,k); + index = indexFor(h->tablelength,e->h); + e->k = k; + e->v = v; + e->next = h->table[index]; + h->table[index] = e; + return -1; +} + +/*****************************************************************************/ +void * /* returns value associated with key */ +hashtable_search(struct hashtable *h, void *k) +{ + struct entry *e; + unsigned int hashvalue, index; + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hashvalue); + e = h->table[index]; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; + e = e->next; + } + return NULL; +} + +/*****************************************************************************/ +void * /* returns value associated with key */ +hashtable_remove(struct hashtable *h, void *k) +{ + /* TODO: consider compacting the table when the load factor drops enough, + * or provide a 'compact' method. */ + + struct entry *e; + struct entry **pE; + void *v; + unsigned int hashvalue, index; + + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hash(h,k)); + pE = &(h->table[index]); + e = *pE; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + *pE = e->next; + h->entrycount--; + v = e->v; + freekey(e->k); + free(e); + return v; + } + pE = &(e->next); + e = e->next; + } + return NULL; +} + +/*****************************************************************************/ +/* destroy */ +void +hashtable_destroy(struct hashtable *h, int free_values) +{ + unsigned int i; + struct entry *e, *f; + struct entry **table = h->table; + if (free_values) + { + for (i = 0; i < h->tablelength; i++) + { + e = table[i]; + while (NULL != e) + { f = e; e = e->next; freekey(f->k); free(f->v); free(f); } + } + } + else + { + for (i = 0; i < h->tablelength; i++) + { + e = table[i]; + while (NULL != e) + { f = e; e = e->next; freekey(f->k); free(f); } + } + } + free(h->table); + free(h); +} + +/* + * Copyright (c) 2002, Christopher Clark + * 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. +*/ diff --git a/libs/freetdm/hashtable.h b/libs/freetdm/hashtable.h new file mode 100644 index 0000000000..b90781abd4 --- /dev/null +++ b/libs/freetdm/hashtable.h @@ -0,0 +1,199 @@ +/* Copyright (C) 2002 Christopher Clark */ + +#ifndef __HASHTABLE_CWC22_H__ +#define __HASHTABLE_CWC22_H__ + +struct hashtable; + +/* Example of use: + * + * struct hashtable *h; + * struct some_key *k; + * struct some_value *v; + * + * static unsigned int hash_from_key_fn( void *k ); + * static int keys_equal_fn ( void *key1, void *key2 ); + * + * h = create_hashtable(16, hash_from_key_fn, keys_equal_fn); + * k = (struct some_key *) malloc(sizeof(struct some_key)); + * v = (struct some_value *) malloc(sizeof(struct some_value)); + * + * (initialise k and v to suitable values) + * + * if (! hashtable_insert(h,k,v) ) + * { exit(-1); } + * + * if (NULL == (found = hashtable_search(h,k) )) + * { printf("not found!"); } + * + * if (NULL == (found = hashtable_remove(h,k) )) + * { printf("Not found\n"); } + * + */ + +/* Macros may be used to define type-safe(r) hashtable access functions, with + * methods specialized to take known key and value types as parameters. + * + * Example: + * + * Insert this at the start of your file: + * + * DEFINE_HASHTABLE_INSERT(insert_some, struct some_key, struct some_value); + * DEFINE_HASHTABLE_SEARCH(search_some, struct some_key, struct some_value); + * DEFINE_HASHTABLE_REMOVE(remove_some, struct some_key, struct some_value); + * + * This defines the functions 'insert_some', 'search_some' and 'remove_some'. + * These operate just like hashtable_insert etc., with the same parameters, + * but their function signatures have 'struct some_key *' rather than + * 'void *', and hence can generate compile time errors if your program is + * supplying incorrect data as a key (and similarly for value). + * + * Note that the hash and key equality functions passed to create_hashtable + * still take 'void *' parameters instead of 'some key *'. This shouldn't be + * a difficult issue as they're only defined and passed once, and the other + * functions will ensure that only valid keys are supplied to them. + * + * The cost for this checking is increased code size and runtime overhead + * - if performance is important, it may be worth switching back to the + * unsafe methods once your program has been debugged with the safe methods. + * This just requires switching to some simple alternative defines - eg: + * #define insert_some hashtable_insert + * + */ + +/***************************************************************************** + * create_hashtable + + * @name create_hashtable + * @param minsize minimum initial size of hashtable + * @param hashfunction function for hashing keys + * @param key_eq_fn function for determining key equality + * @return newly created hashtable or NULL on failure + */ + +struct hashtable * +create_hashtable(unsigned int minsize, + unsigned int (*hashfunction) (void*), + int (*key_eq_fn) (void*,void*)); + +/***************************************************************************** + * hashtable_insert + + * @name hashtable_insert + * @param h the hashtable to insert into + * @param k the key - hashtable claims ownership and will free on removal + * @param v the value - does not claim ownership + * @return non-zero for successful insertion + * + * This function will cause the table to expand if the insertion would take + * the ratio of entries to table size over the maximum load factor. + * + * This function does not check for repeated insertions with a duplicate key. + * The value returned when using a duplicate key is undefined -- when + * the hashtable changes size, the order of retrieval of duplicate key + * entries is reversed. + * If in doubt, remove before insert. + */ + +int +hashtable_insert(struct hashtable *h, void *k, void *v); + +#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ +int fnname (struct hashtable *h, keytype *k, valuetype *v) \ +{ \ + return hashtable_insert(h,k,v); \ +} + +/***************************************************************************** + * hashtable_search + + * @name hashtable_search + * @param h the hashtable to search + * @param k the key to search for - does not claim ownership + * @return the value associated with the key, or NULL if none found + */ + +void * +hashtable_search(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ +valuetype * fnname (struct hashtable *h, keytype *k) \ +{ \ + return (valuetype *) (hashtable_search(h,k)); \ +} + +/***************************************************************************** + * hashtable_remove + + * @name hashtable_remove + * @param h the hashtable to remove the item from + * @param k the key to search for - does not claim ownership + * @return the value associated with the key, or NULL if none found + */ + +void * /* returns value */ +hashtable_remove(struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ +valuetype * fnname (struct hashtable *h, keytype *k) \ +{ \ + return (valuetype *) (hashtable_remove(h,k)); \ +} + + +/***************************************************************************** + * hashtable_count + + * @name hashtable_count + * @param h the hashtable + * @return the number of items stored in the hashtable + */ +unsigned int +hashtable_count(struct hashtable *h); + + +/***************************************************************************** + * hashtable_destroy + + * @name hashtable_destroy + * @param h the hashtable + * @param free_values whether to call 'free' on the remaining values + */ + +void +hashtable_destroy(struct hashtable *h, int free_values); + +#endif /* __HASHTABLE_CWC22_H__ */ + +/* + * Copyright (c) 2002, Christopher Clark + * 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. +*/ diff --git a/libs/freetdm/hashtable_itr.c b/libs/freetdm/hashtable_itr.c new file mode 100644 index 0000000000..defac691f0 --- /dev/null +++ b/libs/freetdm/hashtable_itr.c @@ -0,0 +1,176 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#include "hashtable.h" +#include "hashtable_private.h" +#include "hashtable_itr.h" +#include /* defines NULL */ + +/*****************************************************************************/ +/* hashtable_iterator - iterator constructor */ + +struct hashtable_itr * +hashtable_iterator(struct hashtable *h) +{ + unsigned int i, tablelength; + struct hashtable_itr *itr = (struct hashtable_itr *) + malloc(sizeof(struct hashtable_itr)); + if (NULL == itr) return NULL; + itr->h = h; + itr->e = NULL; + itr->parent = NULL; + tablelength = h->tablelength; + itr->index = tablelength; + if (0 == h->entrycount) return itr; + + for (i = 0; i < tablelength; i++) + { + if (NULL != h->table[i]) + { + itr->e = h->table[i]; + itr->index = i; + break; + } + } + return itr; +} + +/*****************************************************************************/ +/* advance - advance the iterator to the next element + * returns zero if advanced to end of table */ + +int +hashtable_iterator_advance(struct hashtable_itr *itr) +{ + unsigned int j,tablelength; + struct entry **table; + struct entry *next; + if (NULL == itr->e) return 0; /* stupidity check */ + + next = itr->e->next; + if (NULL != next) + { + itr->parent = itr->e; + itr->e = next; + return -1; + } + tablelength = itr->h->tablelength; + itr->parent = NULL; + if (tablelength <= (j = ++(itr->index))) + { + itr->e = NULL; + return 0; + } + table = itr->h->table; + while (NULL == (next = table[j])) + { + if (++j >= tablelength) + { + itr->index = tablelength; + itr->e = NULL; + return 0; + } + } + itr->index = j; + itr->e = next; + return -1; +} + +/*****************************************************************************/ +/* remove - remove the entry at the current iterator position + * and advance the iterator, if there is a successive + * element. + * If you want the value, read it before you remove: + * beware memory leaks if you don't. + * Returns zero if end of iteration. */ + +int +hashtable_iterator_remove(struct hashtable_itr *itr) +{ + struct entry *remember_e, *remember_parent; + int ret; + + /* Do the removal */ + if (NULL == (itr->parent)) + { + /* element is head of a chain */ + itr->h->table[itr->index] = itr->e->next; + } else { + /* element is mid-chain */ + itr->parent->next = itr->e->next; + } + /* itr->e is now outside the hashtable */ + remember_e = itr->e; + itr->h->entrycount--; + freekey(remember_e->k); + + /* Advance the iterator, correcting the parent */ + remember_parent = itr->parent; + ret = hashtable_iterator_advance(itr); + if (itr->parent == remember_e) { itr->parent = remember_parent; } + free(remember_e); + return ret; +} + +/*****************************************************************************/ +int /* returns zero if not found */ +hashtable_iterator_search(struct hashtable_itr *itr, + struct hashtable *h, void *k) +{ + struct entry *e, *parent; + unsigned int hashvalue, index; + + hashvalue = hash(h,k); + index = indexFor(h->tablelength,hashvalue); + + e = h->table[index]; + parent = NULL; + while (NULL != e) + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + itr->index = index; + itr->e = e; + itr->parent = parent; + itr->h = h; + return -1; + } + parent = e; + e = e->next; + } + return 0; +} + + +/* + * Copyright (c) 2002, 2004, Christopher Clark + * 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. +*/ diff --git a/libs/freetdm/hashtable_itr.h b/libs/freetdm/hashtable_itr.h new file mode 100644 index 0000000000..50ea10420a --- /dev/null +++ b/libs/freetdm/hashtable_itr.h @@ -0,0 +1,104 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#ifndef __HASHTABLE_ITR_CWC22__ +#define __HASHTABLE_ITR_CWC22__ +#include "hashtable.h" +#include "hashtable_private.h" /* needed to enable inlining */ + +/*****************************************************************************/ +/* This struct is only concrete here to allow the inlining of two of the + * accessor functions. */ +struct hashtable_itr +{ + struct hashtable *h; + struct entry *e; + struct entry *parent; + unsigned int index; +}; + + +/*****************************************************************************/ +/* hashtable_iterator + */ + +struct hashtable_itr * +hashtable_iterator(struct hashtable *h); + +/*****************************************************************************/ +/* hashtable_iterator_key + * - return the value of the (key,value) pair at the current position */ + +#define hashtable_iterator_key(i) (void *)i->e->k + +/*****************************************************************************/ +/* value - return the value of the (key,value) pair at the current position */ + +#define hashtable_iterator_value (void *)i->e->v + +/*****************************************************************************/ +/* advance - advance the iterator to the next element + * returns zero if advanced to end of table */ + +int +hashtable_iterator_advance(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* remove - remove current element and advance the iterator to the next element + * NB: if you need the value to free it, read it before + * removing. ie: beware memory leaks! + * returns zero if advanced to end of table */ + +int +hashtable_iterator_remove(struct hashtable_itr *itr); + +/*****************************************************************************/ +/* search - overwrite the supplied iterator, to point to the entry + * matching the supplied key. + h points to the hashtable to be searched. + * returns zero if not found. */ +int +hashtable_iterator_search(struct hashtable_itr *itr, + struct hashtable *h, void *k); + +#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ +int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ +{ \ + return (hashtable_iterator_search(i,h,k)); \ +} + + + +#endif /* __HASHTABLE_ITR_CWC22__*/ + +/* + * Copyright (c) 2002, 2004, Christopher Clark + * 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. +*/ diff --git a/libs/freetdm/hashtable_private.h b/libs/freetdm/hashtable_private.h new file mode 100644 index 0000000000..cb261e9af2 --- /dev/null +++ b/libs/freetdm/hashtable_private.h @@ -0,0 +1,82 @@ +/* Copyright (C) 2002, 2004 Christopher Clark */ + +#ifndef __HASHTABLE_PRIVATE_CWC22_H__ +#define __HASHTABLE_PRIVATE_CWC22_H__ + +#include "hashtable.h" + +/*****************************************************************************/ +struct entry +{ + void *k, *v; + unsigned int h; + struct entry *next; +}; + +struct hashtable { + unsigned int tablelength; + struct entry **table; + unsigned int entrycount; + unsigned int loadlimit; + unsigned int primeindex; + unsigned int (*hashfn) (void *k); + int (*eqfn) (void *k1, void *k2); +}; + +/*****************************************************************************/ +unsigned int +hash(struct hashtable *h, void *k); + +/*****************************************************************************/ +/* indexFor */ +#define indexFor(hashvalue, tablelength) (unsigned int)(hashvalue % tablelength) + +/* Only works if tablelength == 2^N */ +/*static inline unsigned int +indexFor(unsigned int tablelength, unsigned int hashvalue) +{ + return (hashvalue & (tablelength - 1u)); +} +*/ + +/*****************************************************************************/ +#define freekey(X) free(X) +/*define freekey(X) ; */ + + +/*****************************************************************************/ + +#endif /* __HASHTABLE_PRIVATE_CWC22_H__*/ + +/* + * Copyright (c) 2002, Christopher Clark + * 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. +*/ diff --git a/libs/freetdm/openzap.c b/libs/freetdm/openzap.c new file mode 100644 index 0000000000..0ac20f533a --- /dev/null +++ b/libs/freetdm/openzap.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#ifdef ZAP_WANPIPE_SUPPORT +#include "zap_wanpipe.h" +#endif +#ifdef ZAP_ZT_SUPPORT +#include "zap_zt.h" +#endif + +static struct { + zap_hash_t *interface_hash; +} globals; + + +static int equalkeys(void *k1, void *k2) +{ + return strcmp((char *) k1, (char *) k2) ? 0 : 1; +} + +static unsigned hashfromstring(void *ky) +{ + unsigned char *str = (unsigned char *) ky; + unsigned hash = 0; + int c; + + while ((c = *str++)) { + hash = c + (hash << 6) + (hash << 16) - hash; + } + + return hash; +} + +zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) +{ + zap_span_t *new_span = NULL; + + assert(zint != NULL); + + if (zint->span_index < ZAP_MAX_SPANS_INTERFACE) { + new_span = &zint->spans[++zint->span_index]; + memset(new_span, 0, sizeof(*new_span)); + zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); + new_span->span_id = zint->span_index; + new_span->zint = zint; + *span = new_span; + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) +{ + if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { + zap_channel_t *new_chan; + new_chan = &span->channels[++span->chan_count]; + new_chan->type = type; + new_chan->sockfd = sockfd; + new_chan->zint = span->zint; + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); + *chan = new_chan; + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +zap_status_t zap_span_destroy(zap_span_t **span); + +zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) +{ + zap_software_interface_t *zint; + + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && + (zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (void *)name))) { + zap_channel_t *check; + check = &zint->spans[span_id].channels[chan_id]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return ZAP_SUCCESS; + } + } + + return ZAP_FAIL; +} + +zap_status_t zap_channel_close(zap_channel_t **zchan) +{ + zap_channel_t *check; + *zchan = NULL; + + assert(zchan != NULL); + check = *zchan; + assert(check != NULL); + + if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + zap_clear_flag(check, ZAP_CHANNEL_OPEN); + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + + +zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->set_codec(zchan, codec); + +} + +zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->set_interval(zchan, ms); + +} + +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->wait(zchan, flags); + +} + + +zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->read(zchan, data, datalen); + +} + + +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) +{ + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + return ZAP_FAIL; + } + + return zchan->zint->write(zchan, data, datalen); + +} + +zap_status_t zap_global_init(void) +{ + zap_config_t cfg; + char *var, *val; + unsigned configured = 0; + zap_software_interface_t *zint; + + assert(zint = NULL); + + globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); + +#ifdef ZAP_WANPIPE_SUPPORT + if (wanpipe_init(&zint) == ZAP_SUCCESS) { + hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + } +#endif +#ifdef ZAP_ZT_SUPPORT + if (zt_init(&zint) == ZAP_SUCCESS) { + hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + } +#endif + + + if (!zap_config_open_file(&cfg, "openzap.conf")) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "openzap")) { + if (!strcmp(var, "load")) { + zap_software_interface_t *zint; + + if ((zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val))) { + if (zint->configure(zint) == ZAP_SUCCESS) { + configured++; + } + } + } + } + } + + return configured ? ZAP_SUCCESS : ZAP_FAIL; +} + +zap_status_t zap_global_destroy(void) +{ + hashtable_destroy(globals.interface_hash, 1); + +#ifdef ZAP_ZT_SUPPORT + zt_destroy(); +#endif +#ifdef ZAP_WANPIPE_SUPPORT + wanpipe_destroy(); +#endif + return ZAP_SUCCESS; +} diff --git a/libs/freetdm/openzap.h b/libs/freetdm/openzap.h new file mode 100644 index 0000000000..dcb43ef14f --- /dev/null +++ b/libs/freetdm/openzap.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef OPENZAP_H +#define OPENZAP_H + +#define _XOPEN_SOURCE 500 +#include +#include +#include +#ifndef _MSC_VER +#include +#endif +#include +#include "hashtable.h" +#include "zap_config.h" + +#define ZAP_MAX_CHANNELS_SPAN 513 +#define ZAP_MAX_SPANS_INTERFACE 33 + +typedef int zap_socket_t; +typedef size_t zap_size_t; +struct zap_software_interface; + +#define zap_copy_string(x,y,z) strncpy(x, y, z - 1) + +/*! + \brief Test for the existance of a flag on an arbitary object + \param obj the object to test + \param flag the or'd list of flags to test + \return true value if the object has the flags defined +*/ +#define zap_test_flag(obj, flag) ((obj)->flags & flag) + +/*! + \brief Set a flag on an arbitrary object + \param obj the object to set the flags on + \param flag the or'd list of flags to set +*/ +#define zap_set_flag(obj, flag) (obj)->flags |= (flag) + +/*! + \brief Clear a flag on an arbitrary object while locked + \param obj the object to test + \param flag the or'd list of flags to clear +*/ +#define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) + +/*! + \brief Copy flags from one arbitrary object to another + \param dest the object to copy the flags to + \param src the object to copy the flags from + \param flags the flags to copy +*/ +#define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) + + +/*! + \brief Free a pointer and set it to NULL unless it already is NULL + \param it the pointer +*/ +#define zap_safe_free(it) if (it) {free(it);it=NULL;} + +typedef enum { + ZAP_SUCCESS, + ZAP_FAIL +} zap_status_t; + +typedef enum { + ZAP_READ = (1 << 0), + ZAP_WRITE = (1 << 1), + ZAP_ERROR = (1 << 2), + ZAP_EVENT = (1 << 3) +} zap_wait_flag_t; + +typedef enum { + ZAP_CODEC_ULAW = 0, + ZAP_CODEC_ALAW = 8, + ZAP_CODEC_SLIN = 10 +} zap_codec_t; + +typedef enum { + ZAP_SPAN_CONFIGURED = (1 << 0), + ZAP_SPAN_READY = (1 << 1) +} 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_t; + +typedef enum { + ZAP_CHANNEL_CONFIGURED = (1 << 0), + ZAP_CHANNEL_READY = (1 << 1), + ZAP_CHANNEL_OPEN = (1 << 2) +} zap_channel_flag_t; + +struct zap_channel { + unsigned span_id; + unsigned chan_id; + zap_chan_type_t type; + zap_socket_t sockfd; + zap_channel_flag_t flags; + struct zap_software_interface *zint; +}; +typedef struct zap_channel zap_channel_t; + +struct zap_span { + unsigned span_id; + unsigned chan_count; + zap_span_flag_t flags; + struct zap_software_interface *zint; + zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; +}; +typedef struct zap_span zap_span_t; + +typedef zap_status_t (*zint_configure_t)(struct zap_software_interface *zint); +typedef zap_status_t (*zint_open_t)(unsigned span_id, unsigned chan_id, zap_channel_t **zchan); +typedef zap_status_t (*zint_close_t)(zap_channel_t **zchan); +typedef zap_status_t (*zint_set_codec_t)(zap_channel_t *zchan, zap_codec_t codec); +typedef zap_status_t (*zint_set_interval_t)(zap_channel_t *zchan, unsigned ms); +typedef zap_status_t (*zint_wait_t)(zap_channel_t *zchan, zap_wait_flag_t flags); +typedef zap_status_t (*zint_read_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); +typedef zap_status_t (*zint_write_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); + +struct zap_software_interface { + const char *name; + zint_configure_t configure; + zint_open_t open; + zint_close_t close; + zint_set_codec_t set_codec; + zint_set_interval_t set_interval; + zint_wait_t wait; + zint_read_t read; + zint_write_t write; + unsigned span_index; + struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; +}; +typedef struct zap_software_interface zap_software_interface_t; + +zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); +zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); +zap_status_t zap_span_destroy(zap_span_t **span); + +zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_close(zap_channel_t **zchan); +zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec); +zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags); +zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); +zap_status_t zap_global_init(void); +zap_status_t zap_global_destroy(void); + +typedef struct hashtable zap_hash_t; + +#endif diff --git a/libs/freetdm/zap_config.c b/libs/freetdm/zap_config.c new file mode 100644 index 0000000000..17fa4d0596 --- /dev/null +++ b/libs/freetdm/zap_config.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "zap_config.h" + +int zap_config_open_file(zap_config_t *cfg, char *file_path) +{ + FILE *f; + 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; + + if (!(f = fopen(path, "r"))) { + 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; + 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; + 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 = ""; + *val = ""; + 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, '#')) != 0 || (end = strchr(*var, ';')) != 0) { + *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; + +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/zap_config.h b/libs/freetdm/zap_config.h new file mode 100644 index 0000000000..61aa93c177 --- /dev/null +++ b/libs/freetdm/zap_config.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup config Config File Parser + * @ingroup config + * This module implements a basic interface and file format parser + * + *
+ *
+ * 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; + /*! 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, 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); + + +/** @} */ +#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 expandtab: + */ diff --git a/libs/freetdm/zap_skel.c b/libs/freetdm/zap_skel.c new file mode 100644 index 0000000000..2cefd04603 --- /dev/null +++ b/libs/freetdm/zap_skel.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_skel.h" + +zap_status_t skel_init(zap_software_interface_t **zint) +{ + assert(zint != NULL); + + return ZAP_FAIL; +} + +zap_status_t skel_destroy(void) +{ + return ZAP_FAIL; +} diff --git a/libs/freetdm/zap_skel.h b/libs/freetdm/zap_skel.h new file mode 100644 index 0000000000..9fdaadf7b5 --- /dev/null +++ b/libs/freetdm/zap_skel.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_SKEL_H +#define ZAP_SKEL_H +#include "openzap.h" + +zap_status_t skel_init(zap_software_interface_t **zint); +zap_status_t skel_destroy(void); + +#endif diff --git a/libs/freetdm/zap_wanpipe.c b/libs/freetdm/zap_wanpipe.c new file mode 100644 index 0000000000..7cce6d6783 --- /dev/null +++ b/libs/freetdm/zap_wanpipe.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_wanpipe.h" + +zap_status_t wanpipe_init(zap_software_interface_t **zint) +{ + assert(zint != NULL); + + return ZAP_FAIL; +} + +zap_status_t wanpipe_destroy(void) +{ + return ZAP_FAIL; +} diff --git a/libs/freetdm/zap_wanpipe.h b/libs/freetdm/zap_wanpipe.h new file mode 100644 index 0000000000..90cd9a0997 --- /dev/null +++ b/libs/freetdm/zap_wanpipe.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_WANPIPE_H +#define ZAP_WANPIPE_H +#include "openzap.h" + +zap_status_t wanpipe_init(zap_software_interface_t **zint); +zap_status_t wanpipe_destroy(void); + +#endif diff --git a/libs/freetdm/zap_zt.c b/libs/freetdm/zap_zt.c new file mode 100644 index 0000000000..012abc76b7 --- /dev/null +++ b/libs/freetdm/zap_zt.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_zt.h" + +zap_status_t zt_init(zap_software_interface_t **zint) +{ + assert(zint != NULL); + + return ZAP_FAIL; +} + +zap_status_t zt_destroy(void) +{ + return ZAP_FAIL; +} diff --git a/libs/freetdm/zap_zt.h b/libs/freetdm/zap_zt.h new file mode 100644 index 0000000000..f9c2f59e0a --- /dev/null +++ b/libs/freetdm/zap_zt.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_ZT_H +#define ZAP_ZT_H +#include "openzap.h" + +zap_status_t zt_init(zap_software_interface_t **zint); +zap_status_t zt_destroy(void); + +#endif From fc1a44c41d732d17053143ff16a58495639dd2e6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:12:07 +0000 Subject: [PATCH 0005/1766] move git-svn-id: http://svn.openzap.org/svn/openzap/trunk@3 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/{ => src}/Makefile | 0 libs/openzap/{ => src}/hashtable.c | 0 libs/openzap/{ => src}/hashtable.h | 0 libs/openzap/{ => src}/hashtable_itr.c | 0 libs/openzap/{ => src}/hashtable_itr.h | 0 libs/openzap/{ => src}/hashtable_private.h | 0 libs/openzap/{ => src}/openzap.c | 0 libs/openzap/{ => src}/openzap.h | 0 libs/openzap/{ => src}/zap_config.c | 0 libs/openzap/{ => src}/zap_config.h | 0 libs/openzap/{ => src}/zap_skel.c | 0 libs/openzap/{ => src}/zap_skel.h | 0 libs/openzap/{ => src}/zap_wanpipe.c | 0 libs/openzap/{ => src}/zap_wanpipe.h | 0 libs/openzap/{ => src}/zap_zt.c | 0 libs/openzap/{ => src}/zap_zt.h | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/{ => src}/Makefile (100%) rename libs/openzap/{ => src}/hashtable.c (100%) rename libs/openzap/{ => src}/hashtable.h (100%) rename libs/openzap/{ => src}/hashtable_itr.c (100%) rename libs/openzap/{ => src}/hashtable_itr.h (100%) rename libs/openzap/{ => src}/hashtable_private.h (100%) rename libs/openzap/{ => src}/openzap.c (100%) rename libs/openzap/{ => src}/openzap.h (100%) rename libs/openzap/{ => src}/zap_config.c (100%) rename libs/openzap/{ => src}/zap_config.h (100%) rename libs/openzap/{ => src}/zap_skel.c (100%) rename libs/openzap/{ => src}/zap_skel.h (100%) rename libs/openzap/{ => src}/zap_wanpipe.c (100%) rename libs/openzap/{ => src}/zap_wanpipe.h (100%) rename libs/openzap/{ => src}/zap_zt.c (100%) rename libs/openzap/{ => src}/zap_zt.h (100%) diff --git a/libs/openzap/Makefile b/libs/openzap/src/Makefile similarity index 100% rename from libs/openzap/Makefile rename to libs/openzap/src/Makefile diff --git a/libs/openzap/hashtable.c b/libs/openzap/src/hashtable.c similarity index 100% rename from libs/openzap/hashtable.c rename to libs/openzap/src/hashtable.c diff --git a/libs/openzap/hashtable.h b/libs/openzap/src/hashtable.h similarity index 100% rename from libs/openzap/hashtable.h rename to libs/openzap/src/hashtable.h diff --git a/libs/openzap/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c similarity index 100% rename from libs/openzap/hashtable_itr.c rename to libs/openzap/src/hashtable_itr.c diff --git a/libs/openzap/hashtable_itr.h b/libs/openzap/src/hashtable_itr.h similarity index 100% rename from libs/openzap/hashtable_itr.h rename to libs/openzap/src/hashtable_itr.h diff --git a/libs/openzap/hashtable_private.h b/libs/openzap/src/hashtable_private.h similarity index 100% rename from libs/openzap/hashtable_private.h rename to libs/openzap/src/hashtable_private.h diff --git a/libs/openzap/openzap.c b/libs/openzap/src/openzap.c similarity index 100% rename from libs/openzap/openzap.c rename to libs/openzap/src/openzap.c diff --git a/libs/openzap/openzap.h b/libs/openzap/src/openzap.h similarity index 100% rename from libs/openzap/openzap.h rename to libs/openzap/src/openzap.h diff --git a/libs/openzap/zap_config.c b/libs/openzap/src/zap_config.c similarity index 100% rename from libs/openzap/zap_config.c rename to libs/openzap/src/zap_config.c diff --git a/libs/openzap/zap_config.h b/libs/openzap/src/zap_config.h similarity index 100% rename from libs/openzap/zap_config.h rename to libs/openzap/src/zap_config.h diff --git a/libs/openzap/zap_skel.c b/libs/openzap/src/zap_skel.c similarity index 100% rename from libs/openzap/zap_skel.c rename to libs/openzap/src/zap_skel.c diff --git a/libs/openzap/zap_skel.h b/libs/openzap/src/zap_skel.h similarity index 100% rename from libs/openzap/zap_skel.h rename to libs/openzap/src/zap_skel.h diff --git a/libs/openzap/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c similarity index 100% rename from libs/openzap/zap_wanpipe.c rename to libs/openzap/src/zap_wanpipe.c diff --git a/libs/openzap/zap_wanpipe.h b/libs/openzap/src/zap_wanpipe.h similarity index 100% rename from libs/openzap/zap_wanpipe.h rename to libs/openzap/src/zap_wanpipe.h diff --git a/libs/openzap/zap_zt.c b/libs/openzap/src/zap_zt.c similarity index 100% rename from libs/openzap/zap_zt.c rename to libs/openzap/src/zap_zt.c diff --git a/libs/openzap/zap_zt.h b/libs/openzap/src/zap_zt.h similarity index 100% rename from libs/openzap/zap_zt.h rename to libs/openzap/src/zap_zt.h From e441245852320585b09b06872f013ec3847381de Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:12:07 +0000 Subject: [PATCH 0006/1766] move git-svn-id: http://svn.openzap.org/svn/openzap/trunk@3 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/{ => src}/Makefile | 0 libs/freetdm/{ => src}/hashtable.c | 0 libs/freetdm/{ => src}/hashtable.h | 0 libs/freetdm/{ => src}/hashtable_itr.c | 0 libs/freetdm/{ => src}/hashtable_itr.h | 0 libs/freetdm/{ => src}/hashtable_private.h | 0 libs/freetdm/{ => src}/openzap.c | 0 libs/freetdm/{ => src}/openzap.h | 0 libs/freetdm/{ => src}/zap_config.c | 0 libs/freetdm/{ => src}/zap_config.h | 0 libs/freetdm/{ => src}/zap_skel.c | 0 libs/freetdm/{ => src}/zap_skel.h | 0 libs/freetdm/{ => src}/zap_wanpipe.c | 0 libs/freetdm/{ => src}/zap_wanpipe.h | 0 libs/freetdm/{ => src}/zap_zt.c | 0 libs/freetdm/{ => src}/zap_zt.h | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/{ => src}/Makefile (100%) rename libs/freetdm/{ => src}/hashtable.c (100%) rename libs/freetdm/{ => src}/hashtable.h (100%) rename libs/freetdm/{ => src}/hashtable_itr.c (100%) rename libs/freetdm/{ => src}/hashtable_itr.h (100%) rename libs/freetdm/{ => src}/hashtable_private.h (100%) rename libs/freetdm/{ => src}/openzap.c (100%) rename libs/freetdm/{ => src}/openzap.h (100%) rename libs/freetdm/{ => src}/zap_config.c (100%) rename libs/freetdm/{ => src}/zap_config.h (100%) rename libs/freetdm/{ => src}/zap_skel.c (100%) rename libs/freetdm/{ => src}/zap_skel.h (100%) rename libs/freetdm/{ => src}/zap_wanpipe.c (100%) rename libs/freetdm/{ => src}/zap_wanpipe.h (100%) rename libs/freetdm/{ => src}/zap_zt.c (100%) rename libs/freetdm/{ => src}/zap_zt.h (100%) diff --git a/libs/freetdm/Makefile b/libs/freetdm/src/Makefile similarity index 100% rename from libs/freetdm/Makefile rename to libs/freetdm/src/Makefile diff --git a/libs/freetdm/hashtable.c b/libs/freetdm/src/hashtable.c similarity index 100% rename from libs/freetdm/hashtable.c rename to libs/freetdm/src/hashtable.c diff --git a/libs/freetdm/hashtable.h b/libs/freetdm/src/hashtable.h similarity index 100% rename from libs/freetdm/hashtable.h rename to libs/freetdm/src/hashtable.h diff --git a/libs/freetdm/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c similarity index 100% rename from libs/freetdm/hashtable_itr.c rename to libs/freetdm/src/hashtable_itr.c diff --git a/libs/freetdm/hashtable_itr.h b/libs/freetdm/src/hashtable_itr.h similarity index 100% rename from libs/freetdm/hashtable_itr.h rename to libs/freetdm/src/hashtable_itr.h diff --git a/libs/freetdm/hashtable_private.h b/libs/freetdm/src/hashtable_private.h similarity index 100% rename from libs/freetdm/hashtable_private.h rename to libs/freetdm/src/hashtable_private.h diff --git a/libs/freetdm/openzap.c b/libs/freetdm/src/openzap.c similarity index 100% rename from libs/freetdm/openzap.c rename to libs/freetdm/src/openzap.c diff --git a/libs/freetdm/openzap.h b/libs/freetdm/src/openzap.h similarity index 100% rename from libs/freetdm/openzap.h rename to libs/freetdm/src/openzap.h diff --git a/libs/freetdm/zap_config.c b/libs/freetdm/src/zap_config.c similarity index 100% rename from libs/freetdm/zap_config.c rename to libs/freetdm/src/zap_config.c diff --git a/libs/freetdm/zap_config.h b/libs/freetdm/src/zap_config.h similarity index 100% rename from libs/freetdm/zap_config.h rename to libs/freetdm/src/zap_config.h diff --git a/libs/freetdm/zap_skel.c b/libs/freetdm/src/zap_skel.c similarity index 100% rename from libs/freetdm/zap_skel.c rename to libs/freetdm/src/zap_skel.c diff --git a/libs/freetdm/zap_skel.h b/libs/freetdm/src/zap_skel.h similarity index 100% rename from libs/freetdm/zap_skel.h rename to libs/freetdm/src/zap_skel.h diff --git a/libs/freetdm/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c similarity index 100% rename from libs/freetdm/zap_wanpipe.c rename to libs/freetdm/src/zap_wanpipe.c diff --git a/libs/freetdm/zap_wanpipe.h b/libs/freetdm/src/zap_wanpipe.h similarity index 100% rename from libs/freetdm/zap_wanpipe.h rename to libs/freetdm/src/zap_wanpipe.h diff --git a/libs/freetdm/zap_zt.c b/libs/freetdm/src/zap_zt.c similarity index 100% rename from libs/freetdm/zap_zt.c rename to libs/freetdm/src/zap_zt.c diff --git a/libs/freetdm/zap_zt.h b/libs/freetdm/src/zap_zt.h similarity index 100% rename from libs/freetdm/zap_zt.h rename to libs/freetdm/src/zap_zt.h From 6c06cee9e5d9fabc88365109a1f8a4f86b17cb7c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:13:07 +0000 Subject: [PATCH 0007/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@4 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/README | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libs/openzap/README diff --git a/libs/openzap/README b/libs/openzap/README new file mode 100644 index 0000000000..4ef720b10a --- /dev/null +++ b/libs/openzap/README @@ -0,0 +1,3 @@ +OPENZAP (WORK IN PROGRESS) + +*shrug* From 0c15ed5dfa4b77a07ec73496ced8fb5519851937 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:13:07 +0000 Subject: [PATCH 0008/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@4 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/README | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libs/freetdm/README diff --git a/libs/freetdm/README b/libs/freetdm/README new file mode 100644 index 0000000000..4ef720b10a --- /dev/null +++ b/libs/freetdm/README @@ -0,0 +1,3 @@ +OPENZAP (WORK IN PROGRESS) + +*shrug* From c991a3c52d91d50614d357afc3421c3b587ac669 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:15:51 +0000 Subject: [PATCH 0009/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@5 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 2 +- libs/openzap/src/{ => include}/hashtable.h | 0 libs/openzap/src/{ => include}/hashtable_itr.h | 0 libs/openzap/src/{ => include}/hashtable_private.h | 0 libs/openzap/src/{ => include}/openzap.h | 0 libs/openzap/src/{ => include}/zap_config.h | 0 libs/openzap/src/{ => include}/zap_skel.h | 0 libs/openzap/src/{ => include}/zap_wanpipe.h | 0 libs/openzap/src/{ => include}/zap_zt.h | 0 9 files changed, 1 insertion(+), 1 deletion(-) rename libs/openzap/src/{ => include}/hashtable.h (100%) rename libs/openzap/src/{ => include}/hashtable_itr.h (100%) rename libs/openzap/src/{ => include}/hashtable_private.h (100%) rename libs/openzap/src/{ => include}/openzap.h (100%) rename libs/openzap/src/{ => include}/zap_config.h (100%) rename libs/openzap/src/{ => include}/zap_skel.h (100%) rename libs/openzap/src/{ => include}/zap_wanpipe.h (100%) rename libs/openzap/src/{ => include}/zap_zt.h (100%) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index a9a87dbd6d..1a7ca47cce 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -31,7 +31,7 @@ CC=gcc OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o -CFLAGS=$(USER_CFLAGS) -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CFLAGS=$(USER_CFLAGS) -Iinclude -Wall -Werror -Wextra -std=c99 -pedantic -ansi MYLIB=libopenzap.a CFLAGS +=-DZAP_WANPIPE_SUPPORT diff --git a/libs/openzap/src/hashtable.h b/libs/openzap/src/include/hashtable.h similarity index 100% rename from libs/openzap/src/hashtable.h rename to libs/openzap/src/include/hashtable.h diff --git a/libs/openzap/src/hashtable_itr.h b/libs/openzap/src/include/hashtable_itr.h similarity index 100% rename from libs/openzap/src/hashtable_itr.h rename to libs/openzap/src/include/hashtable_itr.h diff --git a/libs/openzap/src/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h similarity index 100% rename from libs/openzap/src/hashtable_private.h rename to libs/openzap/src/include/hashtable_private.h diff --git a/libs/openzap/src/openzap.h b/libs/openzap/src/include/openzap.h similarity index 100% rename from libs/openzap/src/openzap.h rename to libs/openzap/src/include/openzap.h diff --git a/libs/openzap/src/zap_config.h b/libs/openzap/src/include/zap_config.h similarity index 100% rename from libs/openzap/src/zap_config.h rename to libs/openzap/src/include/zap_config.h diff --git a/libs/openzap/src/zap_skel.h b/libs/openzap/src/include/zap_skel.h similarity index 100% rename from libs/openzap/src/zap_skel.h rename to libs/openzap/src/include/zap_skel.h diff --git a/libs/openzap/src/zap_wanpipe.h b/libs/openzap/src/include/zap_wanpipe.h similarity index 100% rename from libs/openzap/src/zap_wanpipe.h rename to libs/openzap/src/include/zap_wanpipe.h diff --git a/libs/openzap/src/zap_zt.h b/libs/openzap/src/include/zap_zt.h similarity index 100% rename from libs/openzap/src/zap_zt.h rename to libs/openzap/src/include/zap_zt.h From 236288e2a163de06f17ff22b8d60932f600559e1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:15:51 +0000 Subject: [PATCH 0010/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@5 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 2 +- libs/freetdm/src/{ => include}/hashtable.h | 0 libs/freetdm/src/{ => include}/hashtable_itr.h | 0 libs/freetdm/src/{ => include}/hashtable_private.h | 0 libs/freetdm/src/{ => include}/openzap.h | 0 libs/freetdm/src/{ => include}/zap_config.h | 0 libs/freetdm/src/{ => include}/zap_skel.h | 0 libs/freetdm/src/{ => include}/zap_wanpipe.h | 0 libs/freetdm/src/{ => include}/zap_zt.h | 0 9 files changed, 1 insertion(+), 1 deletion(-) rename libs/freetdm/src/{ => include}/hashtable.h (100%) rename libs/freetdm/src/{ => include}/hashtable_itr.h (100%) rename libs/freetdm/src/{ => include}/hashtable_private.h (100%) rename libs/freetdm/src/{ => include}/openzap.h (100%) rename libs/freetdm/src/{ => include}/zap_config.h (100%) rename libs/freetdm/src/{ => include}/zap_skel.h (100%) rename libs/freetdm/src/{ => include}/zap_wanpipe.h (100%) rename libs/freetdm/src/{ => include}/zap_zt.h (100%) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index a9a87dbd6d..1a7ca47cce 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -31,7 +31,7 @@ CC=gcc OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o -CFLAGS=$(USER_CFLAGS) -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CFLAGS=$(USER_CFLAGS) -Iinclude -Wall -Werror -Wextra -std=c99 -pedantic -ansi MYLIB=libopenzap.a CFLAGS +=-DZAP_WANPIPE_SUPPORT diff --git a/libs/freetdm/src/hashtable.h b/libs/freetdm/src/include/hashtable.h similarity index 100% rename from libs/freetdm/src/hashtable.h rename to libs/freetdm/src/include/hashtable.h diff --git a/libs/freetdm/src/hashtable_itr.h b/libs/freetdm/src/include/hashtable_itr.h similarity index 100% rename from libs/freetdm/src/hashtable_itr.h rename to libs/freetdm/src/include/hashtable_itr.h diff --git a/libs/freetdm/src/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h similarity index 100% rename from libs/freetdm/src/hashtable_private.h rename to libs/freetdm/src/include/hashtable_private.h diff --git a/libs/freetdm/src/openzap.h b/libs/freetdm/src/include/openzap.h similarity index 100% rename from libs/freetdm/src/openzap.h rename to libs/freetdm/src/include/openzap.h diff --git a/libs/freetdm/src/zap_config.h b/libs/freetdm/src/include/zap_config.h similarity index 100% rename from libs/freetdm/src/zap_config.h rename to libs/freetdm/src/include/zap_config.h diff --git a/libs/freetdm/src/zap_skel.h b/libs/freetdm/src/include/zap_skel.h similarity index 100% rename from libs/freetdm/src/zap_skel.h rename to libs/freetdm/src/include/zap_skel.h diff --git a/libs/freetdm/src/zap_wanpipe.h b/libs/freetdm/src/include/zap_wanpipe.h similarity index 100% rename from libs/freetdm/src/zap_wanpipe.h rename to libs/freetdm/src/include/zap_wanpipe.h diff --git a/libs/freetdm/src/zap_zt.h b/libs/freetdm/src/include/zap_zt.h similarity index 100% rename from libs/freetdm/src/zap_zt.h rename to libs/freetdm/src/include/zap_zt.h From b1993a6533dbd581a875e60678a99939b2ff39d0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:59:11 +0000 Subject: [PATCH 0011/1766] organizw git-svn-id: http://svn.openzap.org/svn/openzap/trunk@6 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 30 ++++++++++++++-- libs/openzap/src/zap_skel.c | 62 ++++++++++++++++++++++++++++++++++ libs/openzap/src/zap_wanpipe.c | 62 ++++++++++++++++++++++++++++++++++ libs/openzap/src/zap_zt.c | 62 ++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 0ac20f533a..4905f230bb 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -139,10 +139,15 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + + if (!zchan->zint->set_codec) { + return ZAP_FAIL; + } return zchan->zint->set_codec(zchan, codec); @@ -151,24 +156,34 @@ zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + if (!zchan->zint->set_interval) { + return ZAP_FAIL; + } + return zchan->zint->set_interval(zchan, ms); } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } - return zchan->zint->wait(zchan, flags); + if (!zchan->zint->wait) { + return ZAP_FAIL; + } + + return zchan->zint->wait(zchan, flags, to); } @@ -176,11 +191,17 @@ zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags) zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { assert(zchan != NULL); + assert(zchan->zint != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + if (!zchan->zint->read) { + return ZAP_FAIL; + } + return zchan->zint->read(zchan, data, datalen); } @@ -189,11 +210,16 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + if (!zchan->zint->write) { + return ZAP_FAIL; + } + return zchan->zint->write(zchan, data, datalen); } diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index 2cefd04603..4341309649 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -35,9 +35,71 @@ #include "openzap.h" #include "zap_skel.h" +static ZINT_CONFIGURE_FUNCTION(skel_configure) +{ + ZINT_CONFIGURE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_OPEN_FUNCTION(skel_open) +{ + ZINT_OPEN_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_CLOSE_FUNCTION(skel_close) +{ + ZINT_CLOSE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_CODEC_FUNCTION(skel_set_codec) +{ + ZINT_SET_CODEC_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_INTERVAL_FUNCTION(skel_set_interval) +{ + ZINT_SET_INTERVAL_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WAIT_FUNCTION(skel_wait) +{ + ZINT_WAIT_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_READ_FUNCTION(skel_read) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(skel_write) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +static zap_software_interface_t skel_interface; + zap_status_t skel_init(zap_software_interface_t **zint) { assert(zint != NULL); + memset(&skel_interface, 0, sizeof(skel_interface)); + + skel_interface.name = "skel"; + skel_interface.configure = skel_configure; + skel_interface.open = skel_open; + skel_interface.close = skel_close; + skel_interface.set_codec = skel_set_codec; + skel_interface.set_interval = skel_set_interval; + skel_interface.wait = skel_wait; + skel_interface.read = skel_read; + skel_interface.write = skel_write; + *zint = &skel_interface; return ZAP_FAIL; } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 7cce6d6783..ba05bfd586 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -35,9 +35,71 @@ #include "openzap.h" #include "zap_wanpipe.h" +static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) +{ + ZINT_CONFIGURE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_OPEN_FUNCTION(wanpipe_open) +{ + ZINT_OPEN_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_CLOSE_FUNCTION(wanpipe_close) +{ + ZINT_CLOSE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_CODEC_FUNCTION(wanpipe_set_codec) +{ + ZINT_SET_CODEC_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_INTERVAL_FUNCTION(wanpipe_set_interval) +{ + ZINT_SET_INTERVAL_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WAIT_FUNCTION(wanpipe_wait) +{ + ZINT_WAIT_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_READ_FUNCTION(wanpipe_read) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(wanpipe_write) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +static zap_software_interface_t wanpipe_interface; + zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); + memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); + + wanpipe_interface.name = "wanpipe"; + wanpipe_interface.configure = wanpipe_configure; + wanpipe_interface.open = wanpipe_open; + wanpipe_interface.close = wanpipe_close; + wanpipe_interface.set_codec = wanpipe_set_codec; + wanpipe_interface.set_interval = wanpipe_set_interval; + wanpipe_interface.wait = wanpipe_wait; + wanpipe_interface.read = wanpipe_read; + wanpipe_interface.write = wanpipe_write; + *zint = &wanpipe_interface; return ZAP_FAIL; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 012abc76b7..802523d393 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -35,9 +35,71 @@ #include "openzap.h" #include "zap_zt.h" +static ZINT_CONFIGURE_FUNCTION(zt_configure) +{ + ZINT_CONFIGURE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_OPEN_FUNCTION(zt_open) +{ + ZINT_OPEN_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_CLOSE_FUNCTION(zt_close) +{ + ZINT_CLOSE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_CODEC_FUNCTION(zt_set_codec) +{ + ZINT_SET_CODEC_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_INTERVAL_FUNCTION(zt_set_interval) +{ + ZINT_SET_INTERVAL_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WAIT_FUNCTION(zt_wait) +{ + ZINT_WAIT_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_READ_FUNCTION(zt_read) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(zt_write) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +static zap_software_interface_t zt_interface; + zap_status_t zt_init(zap_software_interface_t **zint) { assert(zint != NULL); + memset(&zt_interface, 0, sizeof(zt_interface)); + + zt_interface.name = "zt"; + zt_interface.configure = zt_configure; + zt_interface.open = zt_open; + zt_interface.close = zt_close; + zt_interface.set_codec = zt_set_codec; + zt_interface.set_interval = zt_set_interval; + zt_interface.wait = zt_wait; + zt_interface.read = zt_read; + zt_interface.write = zt_write; + *zint = &zt_interface; return ZAP_FAIL; } From 9027db1dcb65a23a425084a8f50f5eac10b8ec5d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 21:59:11 +0000 Subject: [PATCH 0012/1766] organizw git-svn-id: http://svn.openzap.org/svn/openzap/trunk@6 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 30 ++++++++++++++-- libs/freetdm/src/zap_skel.c | 62 ++++++++++++++++++++++++++++++++++ libs/freetdm/src/zap_wanpipe.c | 62 ++++++++++++++++++++++++++++++++++ libs/freetdm/src/zap_zt.c | 62 ++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 0ac20f533a..4905f230bb 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -139,10 +139,15 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + + if (!zchan->zint->set_codec) { + return ZAP_FAIL; + } return zchan->zint->set_codec(zchan, codec); @@ -151,24 +156,34 @@ zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + if (!zchan->zint->set_interval) { + return ZAP_FAIL; + } + return zchan->zint->set_interval(zchan, ms); } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } - return zchan->zint->wait(zchan, flags); + if (!zchan->zint->wait) { + return ZAP_FAIL; + } + + return zchan->zint->wait(zchan, flags, to); } @@ -176,11 +191,17 @@ zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags) zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { assert(zchan != NULL); + assert(zchan->zint != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + if (!zchan->zint->read) { + return ZAP_FAIL; + } + return zchan->zint->read(zchan, data, datalen); } @@ -189,11 +210,16 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { assert(zchan != NULL); + assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } + if (!zchan->zint->write) { + return ZAP_FAIL; + } + return zchan->zint->write(zchan, data, datalen); } diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index 2cefd04603..4341309649 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -35,9 +35,71 @@ #include "openzap.h" #include "zap_skel.h" +static ZINT_CONFIGURE_FUNCTION(skel_configure) +{ + ZINT_CONFIGURE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_OPEN_FUNCTION(skel_open) +{ + ZINT_OPEN_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_CLOSE_FUNCTION(skel_close) +{ + ZINT_CLOSE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_CODEC_FUNCTION(skel_set_codec) +{ + ZINT_SET_CODEC_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_INTERVAL_FUNCTION(skel_set_interval) +{ + ZINT_SET_INTERVAL_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WAIT_FUNCTION(skel_wait) +{ + ZINT_WAIT_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_READ_FUNCTION(skel_read) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(skel_write) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +static zap_software_interface_t skel_interface; + zap_status_t skel_init(zap_software_interface_t **zint) { assert(zint != NULL); + memset(&skel_interface, 0, sizeof(skel_interface)); + + skel_interface.name = "skel"; + skel_interface.configure = skel_configure; + skel_interface.open = skel_open; + skel_interface.close = skel_close; + skel_interface.set_codec = skel_set_codec; + skel_interface.set_interval = skel_set_interval; + skel_interface.wait = skel_wait; + skel_interface.read = skel_read; + skel_interface.write = skel_write; + *zint = &skel_interface; return ZAP_FAIL; } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 7cce6d6783..ba05bfd586 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -35,9 +35,71 @@ #include "openzap.h" #include "zap_wanpipe.h" +static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) +{ + ZINT_CONFIGURE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_OPEN_FUNCTION(wanpipe_open) +{ + ZINT_OPEN_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_CLOSE_FUNCTION(wanpipe_close) +{ + ZINT_CLOSE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_CODEC_FUNCTION(wanpipe_set_codec) +{ + ZINT_SET_CODEC_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_INTERVAL_FUNCTION(wanpipe_set_interval) +{ + ZINT_SET_INTERVAL_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WAIT_FUNCTION(wanpipe_wait) +{ + ZINT_WAIT_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_READ_FUNCTION(wanpipe_read) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(wanpipe_write) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +static zap_software_interface_t wanpipe_interface; + zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); + memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); + + wanpipe_interface.name = "wanpipe"; + wanpipe_interface.configure = wanpipe_configure; + wanpipe_interface.open = wanpipe_open; + wanpipe_interface.close = wanpipe_close; + wanpipe_interface.set_codec = wanpipe_set_codec; + wanpipe_interface.set_interval = wanpipe_set_interval; + wanpipe_interface.wait = wanpipe_wait; + wanpipe_interface.read = wanpipe_read; + wanpipe_interface.write = wanpipe_write; + *zint = &wanpipe_interface; return ZAP_FAIL; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 012abc76b7..802523d393 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -35,9 +35,71 @@ #include "openzap.h" #include "zap_zt.h" +static ZINT_CONFIGURE_FUNCTION(zt_configure) +{ + ZINT_CONFIGURE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_OPEN_FUNCTION(zt_open) +{ + ZINT_OPEN_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_CLOSE_FUNCTION(zt_close) +{ + ZINT_CLOSE_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_CODEC_FUNCTION(zt_set_codec) +{ + ZINT_SET_CODEC_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_SET_INTERVAL_FUNCTION(zt_set_interval) +{ + ZINT_SET_INTERVAL_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WAIT_FUNCTION(zt_wait) +{ + ZINT_WAIT_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_READ_FUNCTION(zt_read) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(zt_write) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +static zap_software_interface_t zt_interface; + zap_status_t zt_init(zap_software_interface_t **zint) { assert(zint != NULL); + memset(&zt_interface, 0, sizeof(zt_interface)); + + zt_interface.name = "zt"; + zt_interface.configure = zt_configure; + zt_interface.open = zt_open; + zt_interface.close = zt_close; + zt_interface.set_codec = zt_set_codec; + zt_interface.set_interval = zt_set_interval; + zt_interface.wait = zt_wait; + zt_interface.read = zt_read; + zt_interface.write = zt_write; + *zint = &zt_interface; return ZAP_FAIL; } From fb39783d8325ef025f215eba5cd118d078f86ee3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 22:04:22 +0000 Subject: [PATCH 0013/1766] organize git-svn-id: http://svn.openzap.org/svn/openzap/trunk@7 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 46 ++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index dcb43ef14f..a3214c356c 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -147,14 +147,42 @@ struct zap_span { }; typedef struct zap_span zap_span_t; -typedef zap_status_t (*zint_configure_t)(struct zap_software_interface *zint); -typedef zap_status_t (*zint_open_t)(unsigned span_id, unsigned chan_id, zap_channel_t **zchan); -typedef zap_status_t (*zint_close_t)(zap_channel_t **zchan); -typedef zap_status_t (*zint_set_codec_t)(zap_channel_t *zchan, zap_codec_t codec); -typedef zap_status_t (*zint_set_interval_t)(zap_channel_t *zchan, unsigned ms); -typedef zap_status_t (*zint_wait_t)(zap_channel_t *zchan, zap_wait_flag_t flags); -typedef zap_status_t (*zint_read_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); -typedef zap_status_t (*zint_write_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); +#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) +#define ZINT_OPEN_ARGS (unsigned span_id, unsigned chan_id, zap_channel_t **zchan) +#define ZINT_CLOSE_ARGS (zap_channel_t **zchan) +#define ZINT_SET_CODEC_ARGS (zap_channel_t *zchan, zap_codec_t codec) +#define ZINT_SET_INTERVAL_ARGS (zap_channel_t *zchan, unsigned ms) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) +#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) + +typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; +typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; +typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; +typedef zap_status_t (*zint_set_codec_t) ZINT_SET_CODEC_ARGS ; +typedef zap_status_t (*zint_set_interval_t) ZINT_SET_INTERVAL_ARGS ; +typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; +typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; +typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; + +#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS +#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS +#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS +#define ZINT_SET_CODEC_FUNCTION(name) zap_status_t name ZINT_SET_CODEC_ARGS +#define ZINT_SET_INTERVAL_FUNCTION(name) zap_status_t name ZINT_SET_INTERVAL_ARGS +#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS +#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS +#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS + +#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) +#define ZINT_OPEN_MUZZLE assert(span_id != 0); assert(chan_id != 0); assert(zchan != NULL) +#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) +#define ZINT_SET_CODEC_MUZZLE assert(zchan != NULL); assert(codec != 0) +#define ZINT_SET_INTERVAL_MUZZLE assert(zchan != NULL); assert(ms != 0) +#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) +#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) + struct zap_software_interface { const char *name; @@ -179,7 +207,7 @@ zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_ zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec); zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); From 7b09fa69788e088081e5a45945584989ec1a3dd5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 May 2007 22:04:22 +0000 Subject: [PATCH 0014/1766] organize git-svn-id: http://svn.openzap.org/svn/openzap/trunk@7 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 46 ++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index dcb43ef14f..a3214c356c 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -147,14 +147,42 @@ struct zap_span { }; typedef struct zap_span zap_span_t; -typedef zap_status_t (*zint_configure_t)(struct zap_software_interface *zint); -typedef zap_status_t (*zint_open_t)(unsigned span_id, unsigned chan_id, zap_channel_t **zchan); -typedef zap_status_t (*zint_close_t)(zap_channel_t **zchan); -typedef zap_status_t (*zint_set_codec_t)(zap_channel_t *zchan, zap_codec_t codec); -typedef zap_status_t (*zint_set_interval_t)(zap_channel_t *zchan, unsigned ms); -typedef zap_status_t (*zint_wait_t)(zap_channel_t *zchan, zap_wait_flag_t flags); -typedef zap_status_t (*zint_read_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); -typedef zap_status_t (*zint_write_t)(zap_channel_t *zchan, void *data, zap_size_t *datalen); +#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) +#define ZINT_OPEN_ARGS (unsigned span_id, unsigned chan_id, zap_channel_t **zchan) +#define ZINT_CLOSE_ARGS (zap_channel_t **zchan) +#define ZINT_SET_CODEC_ARGS (zap_channel_t *zchan, zap_codec_t codec) +#define ZINT_SET_INTERVAL_ARGS (zap_channel_t *zchan, unsigned ms) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) +#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) + +typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; +typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; +typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; +typedef zap_status_t (*zint_set_codec_t) ZINT_SET_CODEC_ARGS ; +typedef zap_status_t (*zint_set_interval_t) ZINT_SET_INTERVAL_ARGS ; +typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; +typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; +typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; + +#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS +#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS +#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS +#define ZINT_SET_CODEC_FUNCTION(name) zap_status_t name ZINT_SET_CODEC_ARGS +#define ZINT_SET_INTERVAL_FUNCTION(name) zap_status_t name ZINT_SET_INTERVAL_ARGS +#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS +#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS +#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS + +#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) +#define ZINT_OPEN_MUZZLE assert(span_id != 0); assert(chan_id != 0); assert(zchan != NULL) +#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) +#define ZINT_SET_CODEC_MUZZLE assert(zchan != NULL); assert(codec != 0) +#define ZINT_SET_INTERVAL_MUZZLE assert(zchan != NULL); assert(ms != 0) +#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) +#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) + struct zap_software_interface { const char *name; @@ -179,7 +207,7 @@ zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_ zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec); zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); From ae336c48942abff827b57a0fab77bed29180378d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 16 May 2007 22:56:27 +0000 Subject: [PATCH 0015/1766] initial check-in of msvc build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@8 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 227 +++++++++++++++++++ libs/openzap/src/hashtable.c | 10 +- libs/openzap/src/include/hashtable.h | 6 +- libs/openzap/src/include/hashtable_private.h | 4 +- libs/openzap/src/include/openzap.h | 18 ++ libs/openzap/src/openzap.c | 18 +- libs/openzap/src/zap_config.c | 4 +- 7 files changed, 267 insertions(+), 20 deletions(-) create mode 100644 libs/openzap/openzap.vcproj diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj new file mode 100644 index 0000000000..001ce13352 --- /dev/null +++ b/libs/openzap/openzap.vcproj @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index 763357edce..e03013ba10 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -22,13 +22,13 @@ static const unsigned int primes[] = { 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); -const float max_load_factor = 0.65; +const float max_load_factor = 0.65f; /*****************************************************************************/ struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashf) (void*), - int (*eqf) (void*,void*)) + unsigned int (*hashf) (const void*), + int (*eqf) (const void*,const void*)) { struct hashtable *h; unsigned int pindex, size = primes[0]; @@ -54,7 +54,7 @@ create_hashtable(unsigned int minsize, /*****************************************************************************/ unsigned int -hash(struct hashtable *h, void *k) +hash(struct hashtable *h, const void *k) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -160,7 +160,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) /*****************************************************************************/ void * /* returns value associated with key */ -hashtable_search(struct hashtable *h, void *k) +hashtable_search(struct hashtable *h, const void *k) { struct entry *e; unsigned int hashvalue, index; diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index b90781abd4..88d76572e8 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -73,8 +73,8 @@ struct hashtable; struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashfunction) (void*), - int (*key_eq_fn) (void*,void*)); + unsigned int (*hashfunction) (const void*), + int (*key_eq_fn) (const void*,const void*)); /***************************************************************************** * hashtable_insert @@ -114,7 +114,7 @@ int fnname (struct hashtable *h, keytype *k, valuetype *v) \ */ void * -hashtable_search(struct hashtable *h, void *k); +hashtable_search(struct hashtable *h, const void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ valuetype * fnname (struct hashtable *h, keytype *k) \ diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index cb261e9af2..3087b8eaa1 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -19,8 +19,8 @@ struct hashtable { unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; - unsigned int (*hashfn) (void *k); - int (*eqfn) (void *k1, void *k2); + unsigned int (*hashfn) (const void *k); + int (*eqfn) (const void *k1, const void *k2); }; /*****************************************************************************/ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index a3214c356c..ca80a3874c 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -35,6 +35,24 @@ #define OPENZAP_H #define _XOPEN_SOURCE 500 + +#ifdef _MSC_VER +#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 snprintf +#define snprintf _snprintf +#endif +#endif + #include #include #include diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 4905f230bb..170bc727eb 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -45,12 +45,12 @@ static struct { } globals; -static int equalkeys(void *k1, void *k2) +static int equalkeys(const void *k1, const void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static unsigned hashfromstring(void *ky) +static unsigned hashfromstring(const void *ky) { unsigned char *str = (unsigned char *) ky; unsigned hash = 0; @@ -102,10 +102,9 @@ zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint; + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, name); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && - (zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (void *)name))) { + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; check = &zint->spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { @@ -229,10 +228,10 @@ zap_status_t zap_global_init(void) zap_config_t cfg; char *var, *val; unsigned configured = 0; - zap_software_interface_t *zint; - - assert(zint = NULL); + zap_software_interface_t *zint = NULL; + zint, 0; + globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); #ifdef ZAP_WANPIPE_SUPPORT @@ -256,7 +255,8 @@ zap_status_t zap_global_init(void) if (!strcmp(var, "load")) { zap_software_interface_t *zint; - if ((zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val))) { + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); + if (zint) { if (zint->configure(zint) == ZAP_SUCCESS) { configured++; } diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index 17fa4d0596..eb65fb3809 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -54,7 +54,9 @@ int zap_config_open_file(zap_config_t *cfg, char *file_path) memset(cfg, 0, sizeof(*cfg)); cfg->lockto = -1; - if (!(f = fopen(path, "r"))) { + f = fopen(path, "r"); + + if (!f) { if (file_path[0] != '/') { int last = -1; char *var, *val; From 96300781c84ceb147957cb98d4f5e7beaf2251f1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 16 May 2007 22:56:27 +0000 Subject: [PATCH 0016/1766] initial check-in of msvc build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@8 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 227 +++++++++++++++++++ libs/freetdm/src/hashtable.c | 10 +- libs/freetdm/src/include/hashtable.h | 6 +- libs/freetdm/src/include/hashtable_private.h | 4 +- libs/freetdm/src/include/openzap.h | 18 ++ libs/freetdm/src/openzap.c | 18 +- libs/freetdm/src/zap_config.c | 4 +- 7 files changed, 267 insertions(+), 20 deletions(-) create mode 100644 libs/freetdm/openzap.vcproj diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj new file mode 100644 index 0000000000..001ce13352 --- /dev/null +++ b/libs/freetdm/openzap.vcproj @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 763357edce..e03013ba10 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -22,13 +22,13 @@ static const unsigned int primes[] = { 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); -const float max_load_factor = 0.65; +const float max_load_factor = 0.65f; /*****************************************************************************/ struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashf) (void*), - int (*eqf) (void*,void*)) + unsigned int (*hashf) (const void*), + int (*eqf) (const void*,const void*)) { struct hashtable *h; unsigned int pindex, size = primes[0]; @@ -54,7 +54,7 @@ create_hashtable(unsigned int minsize, /*****************************************************************************/ unsigned int -hash(struct hashtable *h, void *k) +hash(struct hashtable *h, const void *k) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -160,7 +160,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) /*****************************************************************************/ void * /* returns value associated with key */ -hashtable_search(struct hashtable *h, void *k) +hashtable_search(struct hashtable *h, const void *k) { struct entry *e; unsigned int hashvalue, index; diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index b90781abd4..88d76572e8 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -73,8 +73,8 @@ struct hashtable; struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashfunction) (void*), - int (*key_eq_fn) (void*,void*)); + unsigned int (*hashfunction) (const void*), + int (*key_eq_fn) (const void*,const void*)); /***************************************************************************** * hashtable_insert @@ -114,7 +114,7 @@ int fnname (struct hashtable *h, keytype *k, valuetype *v) \ */ void * -hashtable_search(struct hashtable *h, void *k); +hashtable_search(struct hashtable *h, const void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ valuetype * fnname (struct hashtable *h, keytype *k) \ diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index cb261e9af2..3087b8eaa1 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -19,8 +19,8 @@ struct hashtable { unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; - unsigned int (*hashfn) (void *k); - int (*eqfn) (void *k1, void *k2); + unsigned int (*hashfn) (const void *k); + int (*eqfn) (const void *k1, const void *k2); }; /*****************************************************************************/ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index a3214c356c..ca80a3874c 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -35,6 +35,24 @@ #define OPENZAP_H #define _XOPEN_SOURCE 500 + +#ifdef _MSC_VER +#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 snprintf +#define snprintf _snprintf +#endif +#endif + #include #include #include diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 4905f230bb..170bc727eb 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -45,12 +45,12 @@ static struct { } globals; -static int equalkeys(void *k1, void *k2) +static int equalkeys(const void *k1, const void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static unsigned hashfromstring(void *ky) +static unsigned hashfromstring(const void *ky) { unsigned char *str = (unsigned char *) ky; unsigned hash = 0; @@ -102,10 +102,9 @@ zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint; + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, name); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && - (zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (void *)name))) { + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; check = &zint->spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { @@ -229,10 +228,10 @@ zap_status_t zap_global_init(void) zap_config_t cfg; char *var, *val; unsigned configured = 0; - zap_software_interface_t *zint; - - assert(zint = NULL); + zap_software_interface_t *zint = NULL; + zint, 0; + globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); #ifdef ZAP_WANPIPE_SUPPORT @@ -256,7 +255,8 @@ zap_status_t zap_global_init(void) if (!strcmp(var, "load")) { zap_software_interface_t *zint; - if ((zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val))) { + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); + if (zint) { if (zint->configure(zint) == ZAP_SUCCESS) { configured++; } diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index 17fa4d0596..eb65fb3809 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -54,7 +54,9 @@ int zap_config_open_file(zap_config_t *cfg, char *file_path) memset(cfg, 0, sizeof(*cfg)); cfg->lockto = -1; - if (!(f = fopen(path, "r"))) { + f = fopen(path, "r"); + + if (!f) { if (file_path[0] != '/') { int last = -1; char *var, *val; From fcbd79567c15f007808e4f88e7b822a04d34c12d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 01:54:30 +0000 Subject: [PATCH 0017/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@9 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 10 ++-------- libs/openzap/src/general.makefile | 3 +++ libs/openzap/src/include/hashtable_private.h | 2 +- libs/openzap/src/openzap.c | 6 +++--- libs/openzap/src/wanpipe | 2 ++ libs/openzap/src/zt | 2 ++ 6 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 libs/openzap/src/general.makefile create mode 100644 libs/openzap/src/wanpipe create mode 100644 libs/openzap/src/zt diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 1a7ca47cce..ae2bf9db0c 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -29,17 +29,11 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CC=gcc OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o -CFLAGS=$(USER_CFLAGS) -Iinclude -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a -CFLAGS +=-DZAP_WANPIPE_SUPPORT -OBJS += zap_wanpipe.o - -#CFLAGS +=-DZAP_ZT_SUPPORT -#OBJS += zap_zt.o - +include general.makefile $(ZAP_MODS) $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) diff --git a/libs/openzap/src/general.makefile b/libs/openzap/src/general.makefile new file mode 100644 index 0000000000..c27766a22f --- /dev/null +++ b/libs/openzap/src/general.makefile @@ -0,0 +1,3 @@ +CC=gcc +CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi + diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index 3087b8eaa1..8668d58e32 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -25,7 +25,7 @@ struct hashtable { /*****************************************************************************/ unsigned int -hash(struct hashtable *h, void *k); +hash(struct hashtable *h, const void *k); /*****************************************************************************/ /* indexFor */ diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 170bc727eb..ee795bb8db 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -228,17 +228,17 @@ zap_status_t zap_global_init(void) zap_config_t cfg; char *var, *val; unsigned configured = 0; - zap_software_interface_t *zint = NULL; + zap_software_interface_t *zint; - zint, 0; - globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); + zint = NULL; #ifdef ZAP_WANPIPE_SUPPORT if (wanpipe_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); } #endif + zint = NULL; #ifdef ZAP_ZT_SUPPORT if (zt_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); diff --git a/libs/openzap/src/wanpipe b/libs/openzap/src/wanpipe new file mode 100644 index 0000000000..aef6e1cbac --- /dev/null +++ b/libs/openzap/src/wanpipe @@ -0,0 +1,2 @@ +CFLAGS +=-DZAP_WANPIPE_SUPPORT +OBJS += zap_wanpipe.o diff --git a/libs/openzap/src/zt b/libs/openzap/src/zt new file mode 100644 index 0000000000..d23da58c15 --- /dev/null +++ b/libs/openzap/src/zt @@ -0,0 +1,2 @@ +CFLAGS +=-DZAP_ZT_SUPPORT +OBJS += zap_zt.o From ef2aac954f80a5db1afcf583deb48c1ab0021200 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 01:54:30 +0000 Subject: [PATCH 0018/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@9 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 10 ++-------- libs/freetdm/src/general.makefile | 3 +++ libs/freetdm/src/include/hashtable_private.h | 2 +- libs/freetdm/src/openzap.c | 6 +++--- libs/freetdm/src/wanpipe | 2 ++ libs/freetdm/src/zt | 2 ++ 6 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 libs/freetdm/src/general.makefile create mode 100644 libs/freetdm/src/wanpipe create mode 100644 libs/freetdm/src/zt diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 1a7ca47cce..ae2bf9db0c 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -29,17 +29,11 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CC=gcc OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o -CFLAGS=$(USER_CFLAGS) -Iinclude -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a -CFLAGS +=-DZAP_WANPIPE_SUPPORT -OBJS += zap_wanpipe.o - -#CFLAGS +=-DZAP_ZT_SUPPORT -#OBJS += zap_zt.o - +include general.makefile $(ZAP_MODS) $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) diff --git a/libs/freetdm/src/general.makefile b/libs/freetdm/src/general.makefile new file mode 100644 index 0000000000..c27766a22f --- /dev/null +++ b/libs/freetdm/src/general.makefile @@ -0,0 +1,3 @@ +CC=gcc +CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi + diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index 3087b8eaa1..8668d58e32 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -25,7 +25,7 @@ struct hashtable { /*****************************************************************************/ unsigned int -hash(struct hashtable *h, void *k); +hash(struct hashtable *h, const void *k); /*****************************************************************************/ /* indexFor */ diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 170bc727eb..ee795bb8db 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -228,17 +228,17 @@ zap_status_t zap_global_init(void) zap_config_t cfg; char *var, *val; unsigned configured = 0; - zap_software_interface_t *zint = NULL; + zap_software_interface_t *zint; - zint, 0; - globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); + zint = NULL; #ifdef ZAP_WANPIPE_SUPPORT if (wanpipe_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); } #endif + zint = NULL; #ifdef ZAP_ZT_SUPPORT if (zt_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); diff --git a/libs/freetdm/src/wanpipe b/libs/freetdm/src/wanpipe new file mode 100644 index 0000000000..aef6e1cbac --- /dev/null +++ b/libs/freetdm/src/wanpipe @@ -0,0 +1,2 @@ +CFLAGS +=-DZAP_WANPIPE_SUPPORT +OBJS += zap_wanpipe.o diff --git a/libs/freetdm/src/zt b/libs/freetdm/src/zt new file mode 100644 index 0000000000..d23da58c15 --- /dev/null +++ b/libs/freetdm/src/zt @@ -0,0 +1,2 @@ +CFLAGS +=-DZAP_ZT_SUPPORT +OBJS += zap_zt.o From 7e3412baf1f0147c84a3a494e89d9a4cd6a6e682 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 03:31:21 +0000 Subject: [PATCH 0019/1766] add core wanpipe headers etc and tweak build flags git-svn-id: http://svn.openzap.org/svn/openzap/trunk@10 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 13 +++++++++--- libs/openzap/src/general.makefile | 2 +- libs/openzap/src/include/openzap.h | 2 -- libs/openzap/src/openzap.c | 4 +++- libs/openzap/src/wanpipe | 9 ++++++++ libs/openzap/src/zap_wanpipe.c | 34 +++++++++++++++++++++++++++++- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index ae2bf9db0c..ac6a8ffdec 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -35,13 +35,20 @@ MYLIB=libopenzap.a include general.makefile $(ZAP_MODS) +all: $(MYLIB) + $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ -all: $(MYLIB) +zap_wanpipe.o: zap_wanpipe.c + $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ + +zap_zt.o: zap_zt.c + $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@ + +%.o: %.c + $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: rm -f *.o $(MYLIB) *~ \#* diff --git a/libs/openzap/src/general.makefile b/libs/openzap/src/general.makefile index c27766a22f..b1177dc860 100644 --- a/libs/openzap/src/general.makefile +++ b/libs/openzap/src/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index ca80a3874c..725196225d 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -102,7 +102,6 @@ struct zap_software_interface; */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) - /*! \brief Free a pointer and set it to NULL unless it already is NULL \param it the pointer @@ -201,7 +200,6 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) - struct zap_software_interface { const char *name; zint_configure_t configure; diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index ee795bb8db..40c3173975 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -229,7 +229,7 @@ zap_status_t zap_global_init(void) char *var, *val; unsigned configured = 0; zap_software_interface_t *zint; - + globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); zint = NULL; @@ -265,6 +265,8 @@ zap_status_t zap_global_init(void) } } + zap_config_close_file(&cfg); + return configured ? ZAP_SUCCESS : ZAP_FAIL; } diff --git a/libs/openzap/src/wanpipe b/libs/openzap/src/wanpipe index aef6e1cbac..4f410a083b 100644 --- a/libs/openzap/src/wanpipe +++ b/libs/openzap/src/wanpipe @@ -1,2 +1,11 @@ CFLAGS +=-DZAP_WANPIPE_SUPPORT OBJS += zap_wanpipe.o +WANPIPE_INCLUDE=/usr/include/wanpipe +#WANPIPE_INCLUDE=../../wanpipe-3.1.0.p18/patches/kdrivers/include + +WP_CFLAGS =-I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include +WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API + + + + diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index ba05bfd586..cea8594bac 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -31,13 +31,45 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "openzap.h" #include "zap_wanpipe.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct wanpipe_channel { + struct zap_channel zchan; + int x; +}; static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { + zap_config_t cfg; + char *var, *val; + int catno = -1; + ZINT_CONFIGURE_MUZZLE; + + if (!zap_config_open_file(&cfg, "wanpipe.conf")) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "span")) { + if (cfg.catno != catno) { + + } + } + } + zap_config_close_file(&cfg); + return ZAP_FAIL; } From 3768451efb7df19fca743c01940f6ac0101bbda5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 03:31:21 +0000 Subject: [PATCH 0020/1766] add core wanpipe headers etc and tweak build flags git-svn-id: http://svn.openzap.org/svn/openzap/trunk@10 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 13 +++++++++--- libs/freetdm/src/general.makefile | 2 +- libs/freetdm/src/include/openzap.h | 2 -- libs/freetdm/src/openzap.c | 4 +++- libs/freetdm/src/wanpipe | 9 ++++++++ libs/freetdm/src/zap_wanpipe.c | 34 +++++++++++++++++++++++++++++- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index ae2bf9db0c..ac6a8ffdec 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -35,13 +35,20 @@ MYLIB=libopenzap.a include general.makefile $(ZAP_MODS) +all: $(MYLIB) + $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ -all: $(MYLIB) +zap_wanpipe.o: zap_wanpipe.c + $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ + +zap_zt.o: zap_zt.c + $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@ + +%.o: %.c + $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: rm -f *.o $(MYLIB) *~ \#* diff --git a/libs/freetdm/src/general.makefile b/libs/freetdm/src/general.makefile index c27766a22f..b1177dc860 100644 --- a/libs/freetdm/src/general.makefile +++ b/libs/freetdm/src/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ca80a3874c..725196225d 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -102,7 +102,6 @@ struct zap_software_interface; */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) - /*! \brief Free a pointer and set it to NULL unless it already is NULL \param it the pointer @@ -201,7 +200,6 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) - struct zap_software_interface { const char *name; zint_configure_t configure; diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index ee795bb8db..40c3173975 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -229,7 +229,7 @@ zap_status_t zap_global_init(void) char *var, *val; unsigned configured = 0; zap_software_interface_t *zint; - + globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); zint = NULL; @@ -265,6 +265,8 @@ zap_status_t zap_global_init(void) } } + zap_config_close_file(&cfg); + return configured ? ZAP_SUCCESS : ZAP_FAIL; } diff --git a/libs/freetdm/src/wanpipe b/libs/freetdm/src/wanpipe index aef6e1cbac..4f410a083b 100644 --- a/libs/freetdm/src/wanpipe +++ b/libs/freetdm/src/wanpipe @@ -1,2 +1,11 @@ CFLAGS +=-DZAP_WANPIPE_SUPPORT OBJS += zap_wanpipe.o +WANPIPE_INCLUDE=/usr/include/wanpipe +#WANPIPE_INCLUDE=../../wanpipe-3.1.0.p18/patches/kdrivers/include + +WP_CFLAGS =-I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include +WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API + + + + diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index ba05bfd586..cea8594bac 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -31,13 +31,45 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "openzap.h" #include "zap_wanpipe.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct wanpipe_channel { + struct zap_channel zchan; + int x; +}; static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { + zap_config_t cfg; + char *var, *val; + int catno = -1; + ZINT_CONFIGURE_MUZZLE; + + if (!zap_config_open_file(&cfg, "wanpipe.conf")) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "span")) { + if (cfg.catno != catno) { + + } + } + } + zap_config_close_file(&cfg); + return ZAP_FAIL; } From 4ce6cb1cf9dd1c8256bfa829d404f6dff1b0bc0d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 03:42:38 +0000 Subject: [PATCH 0021/1766] clean up windows build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@11 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 24 ++++++++++++++++++++++++ libs/openzap/src/include/openzap.h | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index 001ce13352..6cb321a698 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -45,10 +45,14 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" + DisableLanguageExtensions="true" + RuntimeTypeInfo="false" UsePrecompiledHeader="0" WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + CompileAs="1" /> + + + + + + = 1400) // VC8+ +#if (_MSC_VER >= 1400) /* VC8+ */ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE #endif @@ -63,6 +63,11 @@ #include "hashtable.h" #include "zap_config.h" +#ifdef NDEBUG +#undef assert +#define assert(_Expression) ((void)(_Expression)) +#endif + #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 From 9439dbf98e3fe1c675b598b178c13532bb39d468 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 03:42:38 +0000 Subject: [PATCH 0022/1766] clean up windows build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@11 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 24 ++++++++++++++++++++++++ libs/freetdm/src/include/openzap.h | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index 001ce13352..6cb321a698 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -45,10 +45,14 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" + DisableLanguageExtensions="true" + RuntimeTypeInfo="false" UsePrecompiledHeader="0" WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + CompileAs="1" /> + + + + + + = 1400) // VC8+ +#if (_MSC_VER >= 1400) /* VC8+ */ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE #endif @@ -63,6 +63,11 @@ #include "hashtable.h" #include "zap_config.h" +#ifdef NDEBUG +#undef assert +#define assert(_Expression) ((void)(_Expression)) +#endif + #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 From db0801c82dea5d47925b39c534cea42117d5daf5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 04:16:52 +0000 Subject: [PATCH 0023/1766] more windows build tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@12 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 6 ++++-- libs/openzap/src/zap_wanpipe.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index 6cb321a698..f6ca7e8c6d 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -45,7 +45,7 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" - DisableLanguageExtensions="true" + DisableLanguageExtensions="false" RuntimeTypeInfo="false" UsePrecompiledHeader="0" WarningLevel="4" @@ -110,7 +110,7 @@ AdditionalIncludeDirectories="src/include" PreprocessorDefinitions="WIN32;NDEBUG;_LIB" RuntimeLibrary="2" - DisableLanguageExtensions="true" + DisableLanguageExtensions="false" RuntimeTypeInfo="false" UsePrecompiledHeader="0" WarningLevel="4" @@ -185,6 +185,7 @@ > diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index cea8594bac..945382c412 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -31,11 +31,38 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define WANPIPE_TDM_API 1 + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#define __WINDOWS__ +#endif +#endif + #include "openzap.h" #include "zap_wanpipe.h" + +#ifdef __WINDOWS__ +#ifdef _MSC_VER +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4200) +#endif +#include +#include +#include +#include +typedef unsigned __int16 u_int16_t; +typedef unsigned __int32 u_int32_t; +#endif + #include #include #include +#ifdef __WINDOWS__ +#include +#include +#endif #include #include #include From 699c263d0473ea0e084793d86b3d917d0f3dbbeb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 04:16:52 +0000 Subject: [PATCH 0024/1766] more windows build tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@12 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 6 ++++-- libs/freetdm/src/zap_wanpipe.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index 6cb321a698..f6ca7e8c6d 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -45,7 +45,7 @@ MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" - DisableLanguageExtensions="true" + DisableLanguageExtensions="false" RuntimeTypeInfo="false" UsePrecompiledHeader="0" WarningLevel="4" @@ -110,7 +110,7 @@ AdditionalIncludeDirectories="src/include" PreprocessorDefinitions="WIN32;NDEBUG;_LIB" RuntimeLibrary="2" - DisableLanguageExtensions="true" + DisableLanguageExtensions="false" RuntimeTypeInfo="false" UsePrecompiledHeader="0" WarningLevel="4" @@ -185,6 +185,7 @@ > diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index cea8594bac..945382c412 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -31,11 +31,38 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define WANPIPE_TDM_API 1 + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#define __WINDOWS__ +#endif +#endif + #include "openzap.h" #include "zap_wanpipe.h" + +#ifdef __WINDOWS__ +#ifdef _MSC_VER +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4200) +#endif +#include +#include +#include +#include +typedef unsigned __int16 u_int16_t; +typedef unsigned __int32 u_int32_t; +#endif + #include #include #include +#ifdef __WINDOWS__ +#include +#include +#endif #include #include #include From f0b32746aa5b7994655419c5ab2210b03cbe97e7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 14:56:12 +0000 Subject: [PATCH 0025/1766] add some weapons to arsenal git-svn-id: http://svn.openzap.org/svn/openzap/trunk@13 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 6 +- libs/openzap/src/include/g711.h | 384 ++++++++++++++ libs/openzap/src/include/libteletone.h | 126 +++++ libs/openzap/src/include/libteletone_detect.h | 280 +++++++++++ .../src/include/libteletone_generate.h | 215 ++++++++ libs/openzap/src/include/openzap.h | 22 +- libs/openzap/src/include/zap_buffer.h | 138 ++++++ libs/openzap/src/libteletone_detect.c | 453 +++++++++++++++++ libs/openzap/src/libteletone_generate.c | 467 ++++++++++++++++++ libs/openzap/src/openzap.c | 73 +++ libs/openzap/src/wanpipe | 3 +- libs/openzap/src/zap_buffer.c | 264 ++++++++++ libs/openzap/src/zt | 2 +- 13 files changed, 2428 insertions(+), 5 deletions(-) create mode 100644 libs/openzap/src/include/g711.h create mode 100644 libs/openzap/src/include/libteletone.h create mode 100644 libs/openzap/src/include/libteletone_detect.h create mode 100644 libs/openzap/src/include/libteletone_generate.h create mode 100644 libs/openzap/src/include/zap_buffer.h create mode 100644 libs/openzap/src/libteletone_detect.c create mode 100644 libs/openzap/src/libteletone_generate.c create mode 100644 libs/openzap/src/zap_buffer.c diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index ac6a8ffdec..2f7055b09c 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -29,7 +29,8 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o + +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o libteletone_detect.o libteletone_generate.o zap_buffer.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a @@ -41,6 +42,9 @@ $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) +openzap.o: openzap.c + $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + zap_wanpipe.o: zap_wanpipe.c $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ diff --git a/libs/openzap/src/include/g711.h b/libs/openzap/src/include/g711.h new file mode 100644 index 0000000000..8d1f6bf43a --- /dev/null +++ b/libs/openzap/src/include/g711.h @@ -0,0 +1,384 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * g711.h - In line A-law and u-law conversion routines + * + * Written by Steve Underwood + * + * Copyright (C) 2001 Steve Underwood + * + * Despite my general liking of the GPL, I place this code in the + * public domain for the benefit of all mankind - even the slimy + * ones who might try to proprietize my work and use it to my + * detriment. + * + * $Id: g711.h,v 1.1 2006/06/07 15:46:39 steveu Exp $ + */ + +/*! \file */ + +/*! \page g711_page A-law and mu-law handling +Lookup tables for A-law and u-law look attractive, until you consider the impact +on the CPU cache. If it causes a substantial area of your processor cache to get +hit too often, cache sloshing will severely slow things down. The main reason +these routines are slow in C, is the lack of direct access to the CPU's "find +the first 1" instruction. A little in-line assembler fixes that, and the +conversion routines can be faster than lookup tables, in most real world usage. +A "find the first 1" instruction is available on most modern CPUs, and is a +much underused feature. + +If an assembly language method of bit searching is not available, these routines +revert to a method that can be a little slow, so the cache thrashing might not +seem so bad :( + +Feel free to submit patches to add fast "find the first 1" support for your own +favourite processor. + +Look up tables are used for transcoding between A-law and u-law, since it is +difficult to achieve the precise transcoding procedure laid down in the G.711 +specification by other means. +*/ + +#if !defined(_G711_H_) +#define _G711_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +typedef unsigned __int8 uint8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef unsigned __int16 uint16_t; +#else +#include +#endif + +#if defined(__i386__) +/*! \brief Find the bit position of the highest set bit in a word + \param bits The word to be searched + \return The bit number of the highest set bit, or -1 if the word is zero. */ +static __inline__ int top_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsrl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Find the bit position of the lowest set bit in a word + \param bits The word to be searched + \return The bit number of the lowest set bit, or -1 if the word is zero. */ +static __inline__ int bottom_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsfl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ +#elif defined(__x86_64__) +static __inline__ int top_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsrq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ + +static __inline__ int bottom_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsfq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ +#else +static __inline__ int top_bit(unsigned int bits) +{ + int i; + + if (bits == 0) + return -1; + i = 0; + if (bits & 0xFFFF0000) + { + bits &= 0xFFFF0000; + i += 16; + } + if (bits & 0xFF00FF00) + { + bits &= 0xFF00FF00; + i += 8; + } + if (bits & 0xF0F0F0F0) + { + bits &= 0xF0F0F0F0; + i += 4; + } + if (bits & 0xCCCCCCCC) + { + bits &= 0xCCCCCCCC; + i += 2; + } + if (bits & 0xAAAAAAAA) + { + bits &= 0xAAAAAAAA; + i += 1; + } + return i; +} +/*- End of function --------------------------------------------------------*/ + +static __inline__ int bottom_bit(unsigned int bits) +{ + int i; + + if (bits == 0) + return -1; + i = 32; + if (bits & 0x0000FFFF) + { + bits &= 0x0000FFFF; + i -= 16; + } + if (bits & 0x00FF00FF) + { + bits &= 0x00FF00FF; + i -= 8; + } + if (bits & 0x0F0F0F0F) + { + bits &= 0x0F0F0F0F; + i -= 4; + } + if (bits & 0x33333333) + { + bits &= 0x33333333; + i -= 2; + } + if (bits & 0x55555555) + { + bits &= 0x55555555; + i -= 1; + } + return i; +} +/*- End of function --------------------------------------------------------*/ +#endif + +/* N.B. It is tempting to use look-up tables for A-law and u-law conversion. + * However, you should consider the cache footprint. + * + * A 64K byte table for linear to x-law and a 512 byte table for x-law to + * linear sound like peanuts these days, and shouldn't an array lookup be + * real fast? No! When the cache sloshes as badly as this one will, a tight + * calculation may be better. The messiest part is normally finding the + * segment, but a little inline assembly can fix that on an i386, x86_64 and + * many other modern processors. + */ + +/* + * Mu-law is basically as follows: + * + * Biased Linear Input Code Compressed Code + * ------------------------ --------------- + * 00000001wxyza 000wxyz + * 0000001wxyzab 001wxyz + * 000001wxyzabc 010wxyz + * 00001wxyzabcd 011wxyz + * 0001wxyzabcde 100wxyz + * 001wxyzabcdef 101wxyz + * 01wxyzabcdefg 110wxyz + * 1wxyzabcdefgh 111wxyz + * + * Each biased linear code has a leading 1 which identifies the segment + * number. The value of the segment number is equal to 7 minus the number + * of leading 0's. The quantization interval is directly available as the + * four bits wxyz. * The trailing bits (a - h) are ignored. + * + * Ordinarily the complement of the resulting code word is used for + * transmission, and so the code word is complemented before it is returned. + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ + +/*#define ULAW_ZEROTRAP*/ /* turn on the trap as per the MIL-STD */ +#define ULAW_BIAS 0x84 /* Bias for linear code. */ + +/*! \brief Encode a linear sample to u-law + \param linear The sample to encode. + \return The u-law value. +*/ +static __inline__ uint8_t linear_to_ulaw(int linear) +{ + uint8_t u_val; + int mask; + int seg; + + /* Get the sign and the magnitude of the value. */ + if (linear < 0) + { + linear = ULAW_BIAS - linear; + mask = 0x7F; + } + else + { + linear = ULAW_BIAS + linear; + mask = 0xFF; + } + + seg = top_bit(linear | 0xFF) - 7; + + /* + * Combine the sign, segment, quantization bits, + * and complement the code word. + */ + if (seg >= 8) + u_val = (uint8_t) (0x7F ^ mask); + else + u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); +#ifdef ULAW_ZEROTRAP + /* Optional ITU trap */ + if (u_val == 0) + u_val = 0x02; +#endif + return u_val; +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Decode an u-law sample to a linear value. + \param ulaw The u-law sample to decode. + \return The linear value. +*/ +static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) +{ + int t; + + /* Complement to obtain normal u-law value. */ + ulaw = ~ulaw; + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); + return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); +} +/*- End of function --------------------------------------------------------*/ + +/* + * A-law is basically as follows: + * + * Linear Input Code Compressed Code + * ----------------- --------------- + * 0000000wxyza 000wxyz + * 0000001wxyza 001wxyz + * 000001wxyzab 010wxyz + * 00001wxyzabc 011wxyz + * 0001wxyzabcd 100wxyz + * 001wxyzabcde 101wxyz + * 01wxyzabcdef 110wxyz + * 1wxyzabcdefg 111wxyz + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ + +#define ALAW_AMI_MASK 0x55 + +/*! \brief Encode a linear sample to A-law + \param linear The sample to encode. + \return The A-law value. +*/ +static __inline__ uint8_t linear_to_alaw(int linear) +{ + int mask; + int seg; + + if (linear >= 0) + { + /* Sign (bit 7) bit = 1 */ + mask = ALAW_AMI_MASK | 0x80; + } + else + { + /* Sign (bit 7) bit = 0 */ + mask = ALAW_AMI_MASK; + linear = -linear - 8; + } + + /* Convert the scaled magnitude to segment number. */ + seg = top_bit(linear | 0xFF) - 7; + if (seg >= 8) + { + if (linear >= 0) + { + /* Out of range. Return maximum value. */ + return (uint8_t) (0x7F ^ mask); + } + /* We must be just a tiny step below zero */ + return (uint8_t) (0x00 ^ mask); + } + /* Combine the sign, segment, and quantization bits. */ + return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Decode an A-law sample to a linear value. + \param alaw The A-law sample to decode. + \return The linear value. +*/ +static __inline__ int16_t alaw_to_linear(uint8_t alaw) +{ + int i; + int seg; + + alaw ^= ALAW_AMI_MASK; + i = ((alaw & 0x0F) << 4); + seg = (((int) alaw & 0x70) >> 4); + if (seg) + i = (i + 0x108) << (seg - 1); + else + i += 8; + return (int16_t) ((alaw & 0x80) ? i : -i); +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. + \param alaw The A-law sample to transcode. + \return The best matching u-law value. +*/ +uint8_t alaw_to_ulaw(uint8_t alaw); + +/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. + \param alaw The u-law sample to transcode. + \return The best matching A-law value. +*/ +uint8_t ulaw_to_alaw(uint8_t ulaw); + +#ifdef __cplusplus +} +#endif + +#endif +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h new file mode 100644 index 0000000000..aaf7b0ed47 --- /dev/null +++ b/libs/openzap/src/include/libteletone.h @@ -0,0 +1,126 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libteletone + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * libteletone.h -- Tone Generator/Detector + * + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef LIBTELETONE_H +#define LIBTELETONE_H + +#ifdef __cplusplus +extern "C" { +#endif +#define TELETONE_MAX_DTMF_DIGITS 128 +#define TELETONE_MAX_TONES 6 +#define TELETONE_TONE_RANGE 127 + +typedef double teletone_process_t; + +/*! \file libteletone.h + \brief Top level include file + + This file should be included by applications using the library +*/ + +/*! \brief An abstraction to store a tone mapping */ +typedef struct { + /*! An array of tone frequencies */ + teletone_process_t freqs[TELETONE_MAX_TONES]; +} teletone_tone_map_t; + +#if !defined(M_PI) +/* C99 systems may not define M_PI */ +#define M_PI 3.14159265358979323846264338327 +#endif + +#ifdef _MSC_VER +typedef __int16 int16_t; +#endif + +#include +#include + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h new file mode 100644 index 0000000000..eda4e49514 --- /dev/null +++ b/libs/openzap/src/include/libteletone_detect.h @@ -0,0 +1,280 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. + * + * + * The Initial Developer of the Original Code is + * Stephen Underwood + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * The the original interface designed by Steve Underwood was preserved to retain + *the optimizations when considering DTMF tones though the names were changed in the interest + * of namespace. + * + * 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 + * + * + ********************************************************************************* + * + * Derived from tone_detect.h - 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. + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBTELETONE_DETECT_H +#define LIBTELETONE_DETECT_H + +#ifdef __cplusplus +extern "C" { +#endif +#include + +/*! \file libteletone_detect.h + \brief Tone Detection Routines + + This module is responsible for tone detection specifics +*/ + +#ifndef FALSE +#define FALSE 0 +#ifndef TRUE +#define TRUE (!FALSE) +#endif +#endif + +/* Basic DTMF specs: + * + * Minimum tone on = 40ms + * Minimum tone off = 50ms + * Maximum digit rate = 10 per second + * Normal twist <= 8dB accepted + * Reverse twist <= 4dB accepted + * S/N >= 15dB will detect OK + * Attenuation <= 26dB will detect OK + * Frequency tolerance +- 1.5% will detect, +-3.5% will reject + */ + +#define DTMF_THRESHOLD 8.0e7 +#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ +#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ +#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ +#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ +#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ +#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ +#define GRID_FACTOR 4 +#define BLOCK_LEN 102 +#define M_TWO_PI 2.0*M_PI + +/*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ +typedef struct { + teletone_process_t v2; + teletone_process_t v3; + teletone_process_t fac; +} teletone_goertzel_state_t; + +/*! \brief A container for a DTMF detection state.*/ +typedef struct { + int hit1; + int hit2; + int hit3; + int hit4; + int mhit; + + teletone_goertzel_state_t row_out[GRID_FACTOR]; + teletone_goertzel_state_t col_out[GRID_FACTOR]; + teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; + teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; + teletone_process_t energy; + + int current_sample; + char digits[TELETONE_MAX_DTMF_DIGITS + 1]; + int current_digits; + int detected_digits; + int lost_digits; + int digit_hits[16]; +} teletone_dtmf_detect_state_t; + +/*! \brief An abstraction to store the coefficient of a tone frequency */ +typedef struct { + teletone_process_t fac; +} teletone_detection_descriptor_t; + +/*! \brief A container for a single multi-tone detection +TELETONE_MAX_TONES dictates the maximum simultaneous tones that can be present +in a multi-tone representation. +*/ +typedef struct { + int sample_rate; + + teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; + int tone_count; + + teletone_process_t energy; + int current_sample; + + int min_samples; + int total_samples; + + int positives; + int negatives; + int hits; + + int positive_factor; + int negative_factor; + int hit_factor; + +} teletone_multi_tone_t; + + +/*! + \brief Initilize a multi-frequency tone detector + \param mt the multi-frequency tone descriptor + \param map a representation of the multi-frequency tone +*/ +void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); + +/*! + \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt + \param mt the multi-frequency tone descriptor + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when the tone was detected or false when it is not +*/ +int teletone_multi_tone_detect (teletone_multi_tone_t *mt, + int16_t sample_buffer[], + int samples); + +/*! + \brief Initilize a DTMF detection state object + \param dtmf_detect_state the DTMF detection state to initilize + \param sample_rate the desired sample rate +*/ +void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); + +/*! + \brief Check a sample buffer for the presence of DTMF digits + \param dtmf_detect_state the detection state object to check + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when DTMF was detected or false when it is not +*/ +int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, + int16_t sample_buffer[], + int samples); +/*! + \brief retrieve any collected digits into a string buffer + \param dtmf_detect_state the detection state object to check + \param buf the string buffer to write to + \param max the maximum length of buf + \return the number of characters written to buf +*/ +int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, + char *buf, + int max); + +/*! + \brief Step through the Goertzel Algorithm for each sample in a buffer + \param goertzel_state the goertzel state to step the samples through + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer +*/ +void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + int16_t sample_buffer[], + int samples); + +/*! + \brief Compute the result of the last applied step of the Goertzel Algorithm + \param goertzel_state the goertzel state to retrieve from + \return the computed value for consideration in furthur audio tests +*/ +teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); + + + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h new file mode 100644 index 0000000000..3d625e8f52 --- /dev/null +++ b/libs/openzap/src/include/libteletone_generate.h @@ -0,0 +1,215 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libteletone + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * libteletone.h -- Tone Generator + * + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef LIBTELETONE_GENERATE_H +#define LIBTELETONE_GENERATE_H +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include +#include +#ifndef _MSC_VER +#include +#endif +#include +#include +#include +#include +#include +#include + + + +/*! \file libteletone_generate.h + \brief Tone Generation Routines + + This module is responsible for tone generation specifics +*/ + +typedef int16_t teletone_audio_t; +struct teletone_generation_session; +typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); + +/*! \brief An abstraction to store a tone generation session */ +struct teletone_generation_session { + /*! An array of tone mappings to character mappings */ + teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; + /*! The number of channels the output audio should be in */ + int channels; + /*! The Rate in hz of the output audio */ + int rate; + /*! The duration (in samples) of the output audio */ + int duration; + /*! The duration of silence to append after the initial audio is generated */ + int wait; + /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ + int tmp_duration; + /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ + int tmp_wait; + /*! Number of loops to repeat a single instruction*/ + int loops; + /*! Number of loops to repeat the entire set of instructions*/ + int LOOPS; + /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ + int decay_factor; + /*! Direction to perform volume increase/decrease 1/-1*/ + int decay_direction; + /*! Number of samples between increase/decrease of volume */ + int decay_step; + /*! Volume factor of the tone */ + int volume; + /*! Debug on/off */ + int debug; + /*! FILE stream to write debug data to */ + FILE *debug_stream; + /*! Extra user data to attach to the session*/ + void *user_data; + /*! Buffer for storing sample data (dynamic) */ + teletone_audio_t *buffer; + /*! Size of the buffer */ + int datalen; + /*! In-Use size of the buffer */ + int samples; + /*! Callback function called during generation */ + int dynamic; + tone_handler handler; +}; + +typedef struct teletone_generation_session teletone_generation_session_t; + + +/*! + \brief Assign a set of tones to a tone_session indexed by a paticular index/character + \param ts the tone generation session + \param index the index to map the tone to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); + +/*! + \brief Assign a set of tones to a single tone map + \param map the map to assign the tones to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_map(teletone_tone_map_t *map, ...); + +/*! + \brief Initilize a tone generation session + \param ts the tone generation session to initilize + \param buflen the size of the buffer(in samples) to dynamically allocate + \param handler a callback function to execute when a tone generation instruction is complete + \param user_data optional user data to send + \return 0 +*/ +int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + +/*! + \brief Free the buffer allocated by a tone generation session + \param ts the tone generation session to destroy + \return 0 +*/ +int teletone_destroy_session(teletone_generation_session_t *ts); + +/*! + \brief Execute a single tone generation instruction + \param ts the tone generation session to consult for parameters + \param map the tone mapping to use for the frequencies + \return 0 +*/ +int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); + +/*! + \brief Execute a tone generation script and call callbacks after each instruction + \param ts the tone generation session to execute on + \param cmd the script to execute + \return 0 +*/ +int teletone_run(teletone_generation_session_t *ts, char *cmd); + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3424a4ca47..07d0f20f2f 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -62,6 +62,8 @@ #include #include "hashtable.h" #include "zap_config.h" +#include "g711.h" +#include "libteletone.h" #ifdef NDEBUG #undef assert @@ -115,7 +117,8 @@ struct zap_software_interface; typedef enum { ZAP_SUCCESS, - ZAP_FAIL + ZAP_FAIL, + ZAP_MEMERR } zap_status_t; typedef enum { @@ -205,6 +208,20 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ +#define ZAP_LOG_DEBUG ZAP_PRE, 7 +#define ZAP_LOG_INFO ZAP_PRE, 6 +#define ZAP_LOG_NOTICE ZAP_PRE, 5 +#define ZAP_LOG_WARNING ZAP_PRE, 4 +#define ZAP_LOG_ERROR ZAP_PRE, 3 +#define ZAP_LOG_CRIT ZAP_PRE, 2 +#define ZAP_LOG_ALERT ZAP_PRE, 1 +#define ZAP_LOG_EMERG ZAP_PRE, 0 + +typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); +extern zap_logger_t global_logger; +#define zap_log global_logger; + struct zap_software_interface { const char *name; zint_configure_t configure; @@ -220,6 +237,7 @@ struct zap_software_interface { }; typedef struct zap_software_interface zap_software_interface_t; + zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_destroy(zap_span_t **span); @@ -233,6 +251,8 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); +void zap_global_set_logger(zap_logger_t logger); +void zap_global_set_default_logger(void); typedef struct hashtable zap_hash_t; diff --git a/libs/openzap/src/include/zap_buffer.h b/libs/openzap/src/include/zap_buffer.h new file mode 100644 index 0000000000..cd16825787 --- /dev/null +++ b/libs/openzap/src/include/zap_buffer.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_BUFFER_H +#define ZAP_BUFFER_H + +#include "openzap.h" + +/** + * @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 + */ +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. + */ +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. + */ +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 + */ +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 + */ +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. + */ +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) + */ +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 + */ +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 + */ +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 + */ +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) + */ +void zap_buffer_destroy(zap_buffer_t **buffer); + +/** @} */ + + +#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 expandtab: + */ diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c new file mode 100644 index 0000000000..8df7d569a4 --- /dev/null +++ b/libs/openzap/src/libteletone_detect.c @@ -0,0 +1,453 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. + * + * + * The Initial Developer of the Original Code is + * Stephen Underwood + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * The the original interface designed by Steve Underwood was preserved to retain + *the optimizations when considering DTMF tones though the names were changed in the interest + * of namespace. + * + * 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 + * + * + ********************************************************************************* + * + * 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. + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef _MSC_VER +#include +#endif +#include +#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 teletone_process_t dtmf_row[] = {697.0, 770.0, 852.0, 941.0}; +static teletone_process_t dtmf_col[] = {1209.0, 1336.0, 1477.0, 1633.0}; + + +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; +} + +void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + int16_t sample_buffer[], + int samples) +{ + int i; + teletone_process_t v1; + + for (i = 0; i < samples; i++) { + v1 = goertzel_state->v2; + goertzel_state->v2 = goertzel_state->v3; + goertzel_state->v3 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; + } +} + +teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state) +{ + return goertzel_state->v3 * goertzel_state->v3 + goertzel_state->v2 * goertzel_state->v2 - goertzel_state->v2 * goertzel_state->v3 * goertzel_state->fac; +} + +void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) +{ + int i; + teletone_process_t theta; + + dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; + + for (i = 0; i < GRID_FACTOR; i++) { + theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); + dtmf_detect_row[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); + dtmf_detect_col[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_col_2nd[i].fac = 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; +} + +void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) +{ + teletone_process_t theta = 0; + int x = 0; + + if(!mt->min_samples) { + mt->min_samples = 102; + } + + if (!mt->positive_factor) { + mt->positive_factor = 2; + } + + if(!mt->negative_factor) { + mt->negative_factor = 10; + } + + if (!mt->hit_factor) { + mt->hit_factor = 2; + } + + if (!mt->sample_rate) { + mt->sample_rate = 8000; + } + + for(x = 0; x < TELETONE_MAX_TONES; x++) { + if ((int) map->freqs[x] == 0) { + break; + } + mt->tone_count++; + theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); + mt->tdd[x].fac = 2.0 * cos(theta); + goertzel_init (&mt->gs[x], &mt->tdd[x]); + goertzel_init (&mt->gs2[x], &mt->tdd[x]); + } + +} + +int teletone_multi_tone_detect (teletone_multi_tone_t *mt, + int16_t sample_buffer[], + int samples) +{ + int sample, limit, j, x = 0; + teletone_process_t v1, famp; + teletone_process_t eng_sum = 0, eng_all[TELETONE_MAX_TONES]; + int gtest = 0, see_hit = 0; + + for (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; + } + + for (j = sample; j < limit; j++) { + famp = sample_buffer[j]; + + mt->energy += famp*famp; + + for(x = 0; x < mt->tone_count; x++) { + v1 = mt->gs[x].v2; + mt->gs[x].v2 = mt->gs[x].v3; + mt->gs[x].v3 = 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 = 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 < mt->tone_count; x++) { + eng_all[x] = teletone_goertzel_result (&mt->gs[x]); + eng_sum += eng_all[x]; + } + + gtest = 0; + for(x = 0; 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 < 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; +} + + +int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, + int16_t sample_buffer[], + int samples) +{ + teletone_process_t row_energy[GRID_FACTOR]; + teletone_process_t col_energy[GRID_FACTOR]; + teletone_process_t famp; + teletone_process_t 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 = 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 = 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 = 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 = 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); +} + + +int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, + char *buf, + int max) +{ + 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 expandtab: + */ diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c new file mode 100644 index 0000000000..4e388c8d3b --- /dev/null +++ b/libs/openzap/src/libteletone_generate.c @@ -0,0 +1,467 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libteletone + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * libteletone.c -- Tone Generator + * + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#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 + + +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; + +} + +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; + +} + +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 = 1500; + ts->decay_step = 0; + 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; +} + +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) { + ts->datalen = need + ts->dynamic; + if (!(ts->buffer = realloc(ts->buffer, ts->datalen))) { + return -1; + } + } + + return 0; +} + +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_process_t tones[TELETONE_MAX_TONES]; + int decay = 0; + int duration; + int wait = 0; + teletone_process_t sample; + + ts->samples = 0; + + 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) { + if (ts->decay_step) { + if (ts->decay_factor) { + decay = (duration - (duration / ts->decay_factor)); + } else { + decay = 0; + } + } + if (ts->volume < 0) { + ts->volume = 0; + } + + for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { + tones[freqlen] = (teletone_process_t) map->freqs[freqlen] * (2 * M_PI); + } + + 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_step && !(ts->samples % ts->decay_step) && ts->volume > 0 && ts->samples > decay) { + ts->volume += ts->decay_direction; + } + + sample = (teletone_process_t) 128; + + for (i = 0; i < freqlen; i++) { + sample += ((teletone_process_t) 2 * (ts->volume > 0 ? ts->volume : 1) * cos(tones[i] * ts->samples * period)); + } + normalize_to_16bit(sample); + 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 %d; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %d; decay_step %d; 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->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); +} + +int teletone_run(teletone_generation_session_t *ts, 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': + ts->volume = atoi(cur + 2); + break; + case '>': + ts->decay_factor = atoi(cur + 2); + ts->decay_direction = -1; + break; + case '<': + ts->decay_factor = atoi(cur + 2); + ts->decay_direction = 1; + break; + case '+': + ts->decay_step = atoi(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 expandtab: + */ diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 40c3173975..acf21e14f2 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -33,6 +33,7 @@ #include "openzap.h" +#include #ifdef ZAP_WANPIPE_SUPPORT #include "zap_wanpipe.h" #endif @@ -44,6 +45,78 @@ static struct { zap_hash_t *interface_hash; } globals; +static char *LEVEL_NAMES[] = { + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + NULL +}; + +static char *cut_path(char *in) +{ + char *p, *ret = in; + char delims[] = "/\\"; + char *i; + + for (i = delims; *i; i++) { + p = in; + while ((p = strchr(p, *i)) != 0) { + ret = ++p; + } + } + return ret; +} + +static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + if (0) { + null_logger(file, func, line, level, fmt); + } +} + +static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + char *fp; + char data[1024]; + + va_list ap; + + fp = cut_path(file); + + va_start(ap, fmt); + + vsnprintf(data, sizeof(data), fmt, ap); + + if (level < 0 || level > 7) { + level = 7; + } + + fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data); + + va_end(ap); + +} + +zap_logger_t global_logger = null_logger; + +void zap_global_set_logger(zap_logger_t logger) +{ + if (logger) { + global_logger = logger; + } else { + global_logger = null_logger; + } +} + +void zap_global_set_default_logger(void) +{ + global_logger = default_logger; +} static int equalkeys(const void *k1, const void *k2) { diff --git a/libs/openzap/src/wanpipe b/libs/openzap/src/wanpipe index 4f410a083b..917220c04e 100644 --- a/libs/openzap/src/wanpipe +++ b/libs/openzap/src/wanpipe @@ -1,7 +1,6 @@ -CFLAGS +=-DZAP_WANPIPE_SUPPORT +MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT OBJS += zap_wanpipe.o WANPIPE_INCLUDE=/usr/include/wanpipe -#WANPIPE_INCLUDE=../../wanpipe-3.1.0.p18/patches/kdrivers/include WP_CFLAGS =-I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c new file mode 100644 index 0000000000..b3df9ba0ab --- /dev/null +++ b/libs/openzap/src/zap_buffer.c @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "zap_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; +}; + + +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; + + if ((new_buffer = malloc(sizeof(*new_buffer)))) { + memset(new_buffer, 0, sizeof(*new_buffer)); + + if (start_len) { + if (!(new_buffer->data = malloc(start_len))) { + 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; +} + +zap_size_t zap_buffer_len(zap_buffer_t *buffer) +{ + + assert(buffer != NULL); + + return buffer->datalen; + +} + + +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; + +} + +zap_size_t zap_buffer_inuse(zap_buffer_t *buffer) +{ + assert(buffer != NULL); + + return buffer->used; +} + +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; +} + +void zap_buffer_set_loops(zap_buffer_t *buffer, int loops) +{ + buffer->loops = loops; +} + +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)) == 0) { + if (buffer->loops == 0) { + return 0; + } + buffer->head = buffer->data; + buffer->used = buffer->actually_used; + len = zap_buffer_read(buffer, data, datalen); + buffer->loops--; + } + return len; +} + +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; +} + +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) { + 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; + + 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; + if (!(buffer->data = realloc(buffer->data, new_size))) { + return 0; + } + 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; +} + +void zap_buffer_zero(zap_buffer_t *buffer) +{ + assert(buffer != NULL); + assert(buffer->data != NULL); + + buffer->used = 0; + buffer->head = buffer->data; +} + +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 expandtab: + */ diff --git a/libs/openzap/src/zt b/libs/openzap/src/zt index d23da58c15..9e0f14d57c 100644 --- a/libs/openzap/src/zt +++ b/libs/openzap/src/zt @@ -1,2 +1,2 @@ -CFLAGS +=-DZAP_ZT_SUPPORT +MOD_CFLAGS +=-DZAP_ZT_SUPPORT OBJS += zap_zt.o From 26a46f5dd04a7f9c420e09a7c6f07e7af7b8c070 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 14:56:12 +0000 Subject: [PATCH 0026/1766] add some weapons to arsenal git-svn-id: http://svn.openzap.org/svn/openzap/trunk@13 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 6 +- libs/freetdm/src/include/g711.h | 384 ++++++++++++++ libs/freetdm/src/include/libteletone.h | 126 +++++ libs/freetdm/src/include/libteletone_detect.h | 280 +++++++++++ .../src/include/libteletone_generate.h | 215 ++++++++ libs/freetdm/src/include/openzap.h | 22 +- libs/freetdm/src/include/zap_buffer.h | 138 ++++++ libs/freetdm/src/libteletone_detect.c | 453 +++++++++++++++++ libs/freetdm/src/libteletone_generate.c | 467 ++++++++++++++++++ libs/freetdm/src/openzap.c | 73 +++ libs/freetdm/src/wanpipe | 3 +- libs/freetdm/src/zap_buffer.c | 264 ++++++++++ libs/freetdm/src/zt | 2 +- 13 files changed, 2428 insertions(+), 5 deletions(-) create mode 100644 libs/freetdm/src/include/g711.h create mode 100644 libs/freetdm/src/include/libteletone.h create mode 100644 libs/freetdm/src/include/libteletone_detect.h create mode 100644 libs/freetdm/src/include/libteletone_generate.h create mode 100644 libs/freetdm/src/include/zap_buffer.h create mode 100644 libs/freetdm/src/libteletone_detect.c create mode 100644 libs/freetdm/src/libteletone_generate.c create mode 100644 libs/freetdm/src/zap_buffer.c diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index ac6a8ffdec..2f7055b09c 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -29,7 +29,8 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o + +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o libteletone_detect.o libteletone_generate.o zap_buffer.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a @@ -41,6 +42,9 @@ $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) +openzap.o: openzap.c + $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + zap_wanpipe.o: zap_wanpipe.c $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ diff --git a/libs/freetdm/src/include/g711.h b/libs/freetdm/src/include/g711.h new file mode 100644 index 0000000000..8d1f6bf43a --- /dev/null +++ b/libs/freetdm/src/include/g711.h @@ -0,0 +1,384 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * g711.h - In line A-law and u-law conversion routines + * + * Written by Steve Underwood + * + * Copyright (C) 2001 Steve Underwood + * + * Despite my general liking of the GPL, I place this code in the + * public domain for the benefit of all mankind - even the slimy + * ones who might try to proprietize my work and use it to my + * detriment. + * + * $Id: g711.h,v 1.1 2006/06/07 15:46:39 steveu Exp $ + */ + +/*! \file */ + +/*! \page g711_page A-law and mu-law handling +Lookup tables for A-law and u-law look attractive, until you consider the impact +on the CPU cache. If it causes a substantial area of your processor cache to get +hit too often, cache sloshing will severely slow things down. The main reason +these routines are slow in C, is the lack of direct access to the CPU's "find +the first 1" instruction. A little in-line assembler fixes that, and the +conversion routines can be faster than lookup tables, in most real world usage. +A "find the first 1" instruction is available on most modern CPUs, and is a +much underused feature. + +If an assembly language method of bit searching is not available, these routines +revert to a method that can be a little slow, so the cache thrashing might not +seem so bad :( + +Feel free to submit patches to add fast "find the first 1" support for your own +favourite processor. + +Look up tables are used for transcoding between A-law and u-law, since it is +difficult to achieve the precise transcoding procedure laid down in the G.711 +specification by other means. +*/ + +#if !defined(_G711_H_) +#define _G711_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +typedef unsigned __int8 uint8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef unsigned __int16 uint16_t; +#else +#include +#endif + +#if defined(__i386__) +/*! \brief Find the bit position of the highest set bit in a word + \param bits The word to be searched + \return The bit number of the highest set bit, or -1 if the word is zero. */ +static __inline__ int top_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsrl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Find the bit position of the lowest set bit in a word + \param bits The word to be searched + \return The bit number of the lowest set bit, or -1 if the word is zero. */ +static __inline__ int bottom_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsfl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ +#elif defined(__x86_64__) +static __inline__ int top_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsrq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ + +static __inline__ int bottom_bit(unsigned int bits) +{ + int res; + + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsfq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; +} +/*- End of function --------------------------------------------------------*/ +#else +static __inline__ int top_bit(unsigned int bits) +{ + int i; + + if (bits == 0) + return -1; + i = 0; + if (bits & 0xFFFF0000) + { + bits &= 0xFFFF0000; + i += 16; + } + if (bits & 0xFF00FF00) + { + bits &= 0xFF00FF00; + i += 8; + } + if (bits & 0xF0F0F0F0) + { + bits &= 0xF0F0F0F0; + i += 4; + } + if (bits & 0xCCCCCCCC) + { + bits &= 0xCCCCCCCC; + i += 2; + } + if (bits & 0xAAAAAAAA) + { + bits &= 0xAAAAAAAA; + i += 1; + } + return i; +} +/*- End of function --------------------------------------------------------*/ + +static __inline__ int bottom_bit(unsigned int bits) +{ + int i; + + if (bits == 0) + return -1; + i = 32; + if (bits & 0x0000FFFF) + { + bits &= 0x0000FFFF; + i -= 16; + } + if (bits & 0x00FF00FF) + { + bits &= 0x00FF00FF; + i -= 8; + } + if (bits & 0x0F0F0F0F) + { + bits &= 0x0F0F0F0F; + i -= 4; + } + if (bits & 0x33333333) + { + bits &= 0x33333333; + i -= 2; + } + if (bits & 0x55555555) + { + bits &= 0x55555555; + i -= 1; + } + return i; +} +/*- End of function --------------------------------------------------------*/ +#endif + +/* N.B. It is tempting to use look-up tables for A-law and u-law conversion. + * However, you should consider the cache footprint. + * + * A 64K byte table for linear to x-law and a 512 byte table for x-law to + * linear sound like peanuts these days, and shouldn't an array lookup be + * real fast? No! When the cache sloshes as badly as this one will, a tight + * calculation may be better. The messiest part is normally finding the + * segment, but a little inline assembly can fix that on an i386, x86_64 and + * many other modern processors. + */ + +/* + * Mu-law is basically as follows: + * + * Biased Linear Input Code Compressed Code + * ------------------------ --------------- + * 00000001wxyza 000wxyz + * 0000001wxyzab 001wxyz + * 000001wxyzabc 010wxyz + * 00001wxyzabcd 011wxyz + * 0001wxyzabcde 100wxyz + * 001wxyzabcdef 101wxyz + * 01wxyzabcdefg 110wxyz + * 1wxyzabcdefgh 111wxyz + * + * Each biased linear code has a leading 1 which identifies the segment + * number. The value of the segment number is equal to 7 minus the number + * of leading 0's. The quantization interval is directly available as the + * four bits wxyz. * The trailing bits (a - h) are ignored. + * + * Ordinarily the complement of the resulting code word is used for + * transmission, and so the code word is complemented before it is returned. + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ + +/*#define ULAW_ZEROTRAP*/ /* turn on the trap as per the MIL-STD */ +#define ULAW_BIAS 0x84 /* Bias for linear code. */ + +/*! \brief Encode a linear sample to u-law + \param linear The sample to encode. + \return The u-law value. +*/ +static __inline__ uint8_t linear_to_ulaw(int linear) +{ + uint8_t u_val; + int mask; + int seg; + + /* Get the sign and the magnitude of the value. */ + if (linear < 0) + { + linear = ULAW_BIAS - linear; + mask = 0x7F; + } + else + { + linear = ULAW_BIAS + linear; + mask = 0xFF; + } + + seg = top_bit(linear | 0xFF) - 7; + + /* + * Combine the sign, segment, quantization bits, + * and complement the code word. + */ + if (seg >= 8) + u_val = (uint8_t) (0x7F ^ mask); + else + u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); +#ifdef ULAW_ZEROTRAP + /* Optional ITU trap */ + if (u_val == 0) + u_val = 0x02; +#endif + return u_val; +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Decode an u-law sample to a linear value. + \param ulaw The u-law sample to decode. + \return The linear value. +*/ +static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) +{ + int t; + + /* Complement to obtain normal u-law value. */ + ulaw = ~ulaw; + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); + return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); +} +/*- End of function --------------------------------------------------------*/ + +/* + * A-law is basically as follows: + * + * Linear Input Code Compressed Code + * ----------------- --------------- + * 0000000wxyza 000wxyz + * 0000001wxyza 001wxyz + * 000001wxyzab 010wxyz + * 00001wxyzabc 011wxyz + * 0001wxyzabcd 100wxyz + * 001wxyzabcde 101wxyz + * 01wxyzabcdef 110wxyz + * 1wxyzabcdefg 111wxyz + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ + +#define ALAW_AMI_MASK 0x55 + +/*! \brief Encode a linear sample to A-law + \param linear The sample to encode. + \return The A-law value. +*/ +static __inline__ uint8_t linear_to_alaw(int linear) +{ + int mask; + int seg; + + if (linear >= 0) + { + /* Sign (bit 7) bit = 1 */ + mask = ALAW_AMI_MASK | 0x80; + } + else + { + /* Sign (bit 7) bit = 0 */ + mask = ALAW_AMI_MASK; + linear = -linear - 8; + } + + /* Convert the scaled magnitude to segment number. */ + seg = top_bit(linear | 0xFF) - 7; + if (seg >= 8) + { + if (linear >= 0) + { + /* Out of range. Return maximum value. */ + return (uint8_t) (0x7F ^ mask); + } + /* We must be just a tiny step below zero */ + return (uint8_t) (0x00 ^ mask); + } + /* Combine the sign, segment, and quantization bits. */ + return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Decode an A-law sample to a linear value. + \param alaw The A-law sample to decode. + \return The linear value. +*/ +static __inline__ int16_t alaw_to_linear(uint8_t alaw) +{ + int i; + int seg; + + alaw ^= ALAW_AMI_MASK; + i = ((alaw & 0x0F) << 4); + seg = (((int) alaw & 0x70) >> 4); + if (seg) + i = (i + 0x108) << (seg - 1); + else + i += 8; + return (int16_t) ((alaw & 0x80) ? i : -i); +} +/*- End of function --------------------------------------------------------*/ + +/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. + \param alaw The A-law sample to transcode. + \return The best matching u-law value. +*/ +uint8_t alaw_to_ulaw(uint8_t alaw); + +/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. + \param alaw The u-law sample to transcode. + \return The best matching A-law value. +*/ +uint8_t ulaw_to_alaw(uint8_t ulaw); + +#ifdef __cplusplus +} +#endif + +#endif +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h new file mode 100644 index 0000000000..aaf7b0ed47 --- /dev/null +++ b/libs/freetdm/src/include/libteletone.h @@ -0,0 +1,126 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libteletone + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * libteletone.h -- Tone Generator/Detector + * + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef LIBTELETONE_H +#define LIBTELETONE_H + +#ifdef __cplusplus +extern "C" { +#endif +#define TELETONE_MAX_DTMF_DIGITS 128 +#define TELETONE_MAX_TONES 6 +#define TELETONE_TONE_RANGE 127 + +typedef double teletone_process_t; + +/*! \file libteletone.h + \brief Top level include file + + This file should be included by applications using the library +*/ + +/*! \brief An abstraction to store a tone mapping */ +typedef struct { + /*! An array of tone frequencies */ + teletone_process_t freqs[TELETONE_MAX_TONES]; +} teletone_tone_map_t; + +#if !defined(M_PI) +/* C99 systems may not define M_PI */ +#define M_PI 3.14159265358979323846264338327 +#endif + +#ifdef _MSC_VER +typedef __int16 int16_t; +#endif + +#include +#include + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h new file mode 100644 index 0000000000..eda4e49514 --- /dev/null +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -0,0 +1,280 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. + * + * + * The Initial Developer of the Original Code is + * Stephen Underwood + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * The the original interface designed by Steve Underwood was preserved to retain + *the optimizations when considering DTMF tones though the names were changed in the interest + * of namespace. + * + * 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 + * + * + ********************************************************************************* + * + * Derived from tone_detect.h - 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. + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBTELETONE_DETECT_H +#define LIBTELETONE_DETECT_H + +#ifdef __cplusplus +extern "C" { +#endif +#include + +/*! \file libteletone_detect.h + \brief Tone Detection Routines + + This module is responsible for tone detection specifics +*/ + +#ifndef FALSE +#define FALSE 0 +#ifndef TRUE +#define TRUE (!FALSE) +#endif +#endif + +/* Basic DTMF specs: + * + * Minimum tone on = 40ms + * Minimum tone off = 50ms + * Maximum digit rate = 10 per second + * Normal twist <= 8dB accepted + * Reverse twist <= 4dB accepted + * S/N >= 15dB will detect OK + * Attenuation <= 26dB will detect OK + * Frequency tolerance +- 1.5% will detect, +-3.5% will reject + */ + +#define DTMF_THRESHOLD 8.0e7 +#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ +#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ +#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ +#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ +#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ +#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ +#define GRID_FACTOR 4 +#define BLOCK_LEN 102 +#define M_TWO_PI 2.0*M_PI + +/*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ +typedef struct { + teletone_process_t v2; + teletone_process_t v3; + teletone_process_t fac; +} teletone_goertzel_state_t; + +/*! \brief A container for a DTMF detection state.*/ +typedef struct { + int hit1; + int hit2; + int hit3; + int hit4; + int mhit; + + teletone_goertzel_state_t row_out[GRID_FACTOR]; + teletone_goertzel_state_t col_out[GRID_FACTOR]; + teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; + teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; + teletone_process_t energy; + + int current_sample; + char digits[TELETONE_MAX_DTMF_DIGITS + 1]; + int current_digits; + int detected_digits; + int lost_digits; + int digit_hits[16]; +} teletone_dtmf_detect_state_t; + +/*! \brief An abstraction to store the coefficient of a tone frequency */ +typedef struct { + teletone_process_t fac; +} teletone_detection_descriptor_t; + +/*! \brief A container for a single multi-tone detection +TELETONE_MAX_TONES dictates the maximum simultaneous tones that can be present +in a multi-tone representation. +*/ +typedef struct { + int sample_rate; + + teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; + int tone_count; + + teletone_process_t energy; + int current_sample; + + int min_samples; + int total_samples; + + int positives; + int negatives; + int hits; + + int positive_factor; + int negative_factor; + int hit_factor; + +} teletone_multi_tone_t; + + +/*! + \brief Initilize a multi-frequency tone detector + \param mt the multi-frequency tone descriptor + \param map a representation of the multi-frequency tone +*/ +void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); + +/*! + \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt + \param mt the multi-frequency tone descriptor + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when the tone was detected or false when it is not +*/ +int teletone_multi_tone_detect (teletone_multi_tone_t *mt, + int16_t sample_buffer[], + int samples); + +/*! + \brief Initilize a DTMF detection state object + \param dtmf_detect_state the DTMF detection state to initilize + \param sample_rate the desired sample rate +*/ +void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); + +/*! + \brief Check a sample buffer for the presence of DTMF digits + \param dtmf_detect_state the detection state object to check + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when DTMF was detected or false when it is not +*/ +int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, + int16_t sample_buffer[], + int samples); +/*! + \brief retrieve any collected digits into a string buffer + \param dtmf_detect_state the detection state object to check + \param buf the string buffer to write to + \param max the maximum length of buf + \return the number of characters written to buf +*/ +int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, + char *buf, + int max); + +/*! + \brief Step through the Goertzel Algorithm for each sample in a buffer + \param goertzel_state the goertzel state to step the samples through + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer +*/ +void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + int16_t sample_buffer[], + int samples); + +/*! + \brief Compute the result of the last applied step of the Goertzel Algorithm + \param goertzel_state the goertzel state to retrieve from + \return the computed value for consideration in furthur audio tests +*/ +teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); + + + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h new file mode 100644 index 0000000000..3d625e8f52 --- /dev/null +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -0,0 +1,215 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libteletone + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * libteletone.h -- Tone Generator + * + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef LIBTELETONE_GENERATE_H +#define LIBTELETONE_GENERATE_H +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include +#include +#ifndef _MSC_VER +#include +#endif +#include +#include +#include +#include +#include +#include + + + +/*! \file libteletone_generate.h + \brief Tone Generation Routines + + This module is responsible for tone generation specifics +*/ + +typedef int16_t teletone_audio_t; +struct teletone_generation_session; +typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); + +/*! \brief An abstraction to store a tone generation session */ +struct teletone_generation_session { + /*! An array of tone mappings to character mappings */ + teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; + /*! The number of channels the output audio should be in */ + int channels; + /*! The Rate in hz of the output audio */ + int rate; + /*! The duration (in samples) of the output audio */ + int duration; + /*! The duration of silence to append after the initial audio is generated */ + int wait; + /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ + int tmp_duration; + /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ + int tmp_wait; + /*! Number of loops to repeat a single instruction*/ + int loops; + /*! Number of loops to repeat the entire set of instructions*/ + int LOOPS; + /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ + int decay_factor; + /*! Direction to perform volume increase/decrease 1/-1*/ + int decay_direction; + /*! Number of samples between increase/decrease of volume */ + int decay_step; + /*! Volume factor of the tone */ + int volume; + /*! Debug on/off */ + int debug; + /*! FILE stream to write debug data to */ + FILE *debug_stream; + /*! Extra user data to attach to the session*/ + void *user_data; + /*! Buffer for storing sample data (dynamic) */ + teletone_audio_t *buffer; + /*! Size of the buffer */ + int datalen; + /*! In-Use size of the buffer */ + int samples; + /*! Callback function called during generation */ + int dynamic; + tone_handler handler; +}; + +typedef struct teletone_generation_session teletone_generation_session_t; + + +/*! + \brief Assign a set of tones to a tone_session indexed by a paticular index/character + \param ts the tone generation session + \param index the index to map the tone to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); + +/*! + \brief Assign a set of tones to a single tone map + \param map the map to assign the tones to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_map(teletone_tone_map_t *map, ...); + +/*! + \brief Initilize a tone generation session + \param ts the tone generation session to initilize + \param buflen the size of the buffer(in samples) to dynamically allocate + \param handler a callback function to execute when a tone generation instruction is complete + \param user_data optional user data to send + \return 0 +*/ +int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + +/*! + \brief Free the buffer allocated by a tone generation session + \param ts the tone generation session to destroy + \return 0 +*/ +int teletone_destroy_session(teletone_generation_session_t *ts); + +/*! + \brief Execute a single tone generation instruction + \param ts the tone generation session to consult for parameters + \param map the tone mapping to use for the frequencies + \return 0 +*/ +int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); + +/*! + \brief Execute a tone generation script and call callbacks after each instruction + \param ts the tone generation session to execute on + \param cmd the script to execute + \return 0 +*/ +int teletone_run(teletone_generation_session_t *ts, char *cmd); + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 3424a4ca47..07d0f20f2f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -62,6 +62,8 @@ #include #include "hashtable.h" #include "zap_config.h" +#include "g711.h" +#include "libteletone.h" #ifdef NDEBUG #undef assert @@ -115,7 +117,8 @@ struct zap_software_interface; typedef enum { ZAP_SUCCESS, - ZAP_FAIL + ZAP_FAIL, + ZAP_MEMERR } zap_status_t; typedef enum { @@ -205,6 +208,20 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ +#define ZAP_LOG_DEBUG ZAP_PRE, 7 +#define ZAP_LOG_INFO ZAP_PRE, 6 +#define ZAP_LOG_NOTICE ZAP_PRE, 5 +#define ZAP_LOG_WARNING ZAP_PRE, 4 +#define ZAP_LOG_ERROR ZAP_PRE, 3 +#define ZAP_LOG_CRIT ZAP_PRE, 2 +#define ZAP_LOG_ALERT ZAP_PRE, 1 +#define ZAP_LOG_EMERG ZAP_PRE, 0 + +typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); +extern zap_logger_t global_logger; +#define zap_log global_logger; + struct zap_software_interface { const char *name; zint_configure_t configure; @@ -220,6 +237,7 @@ struct zap_software_interface { }; typedef struct zap_software_interface zap_software_interface_t; + zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_destroy(zap_span_t **span); @@ -233,6 +251,8 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); +void zap_global_set_logger(zap_logger_t logger); +void zap_global_set_default_logger(void); typedef struct hashtable zap_hash_t; diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h new file mode 100644 index 0000000000..cd16825787 --- /dev/null +++ b/libs/freetdm/src/include/zap_buffer.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_BUFFER_H +#define ZAP_BUFFER_H + +#include "openzap.h" + +/** + * @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 + */ +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. + */ +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. + */ +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 + */ +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 + */ +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. + */ +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) + */ +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 + */ +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 + */ +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 + */ +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) + */ +void zap_buffer_destroy(zap_buffer_t **buffer); + +/** @} */ + + +#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 expandtab: + */ diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c new file mode 100644 index 0000000000..8df7d569a4 --- /dev/null +++ b/libs/freetdm/src/libteletone_detect.c @@ -0,0 +1,453 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. + * + * + * The Initial Developer of the Original Code is + * Stephen Underwood + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * The the original interface designed by Steve Underwood was preserved to retain + *the optimizations when considering DTMF tones though the names were changed in the interest + * of namespace. + * + * 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 + * + * + ********************************************************************************* + * + * 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. + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef _MSC_VER +#include +#endif +#include +#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 teletone_process_t dtmf_row[] = {697.0, 770.0, 852.0, 941.0}; +static teletone_process_t dtmf_col[] = {1209.0, 1336.0, 1477.0, 1633.0}; + + +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; +} + +void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + int16_t sample_buffer[], + int samples) +{ + int i; + teletone_process_t v1; + + for (i = 0; i < samples; i++) { + v1 = goertzel_state->v2; + goertzel_state->v2 = goertzel_state->v3; + goertzel_state->v3 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; + } +} + +teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state) +{ + return goertzel_state->v3 * goertzel_state->v3 + goertzel_state->v2 * goertzel_state->v2 - goertzel_state->v2 * goertzel_state->v3 * goertzel_state->fac; +} + +void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) +{ + int i; + teletone_process_t theta; + + dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; + + for (i = 0; i < GRID_FACTOR; i++) { + theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); + dtmf_detect_row[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); + dtmf_detect_col[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_col_2nd[i].fac = 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; +} + +void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) +{ + teletone_process_t theta = 0; + int x = 0; + + if(!mt->min_samples) { + mt->min_samples = 102; + } + + if (!mt->positive_factor) { + mt->positive_factor = 2; + } + + if(!mt->negative_factor) { + mt->negative_factor = 10; + } + + if (!mt->hit_factor) { + mt->hit_factor = 2; + } + + if (!mt->sample_rate) { + mt->sample_rate = 8000; + } + + for(x = 0; x < TELETONE_MAX_TONES; x++) { + if ((int) map->freqs[x] == 0) { + break; + } + mt->tone_count++; + theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); + mt->tdd[x].fac = 2.0 * cos(theta); + goertzel_init (&mt->gs[x], &mt->tdd[x]); + goertzel_init (&mt->gs2[x], &mt->tdd[x]); + } + +} + +int teletone_multi_tone_detect (teletone_multi_tone_t *mt, + int16_t sample_buffer[], + int samples) +{ + int sample, limit, j, x = 0; + teletone_process_t v1, famp; + teletone_process_t eng_sum = 0, eng_all[TELETONE_MAX_TONES]; + int gtest = 0, see_hit = 0; + + for (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; + } + + for (j = sample; j < limit; j++) { + famp = sample_buffer[j]; + + mt->energy += famp*famp; + + for(x = 0; x < mt->tone_count; x++) { + v1 = mt->gs[x].v2; + mt->gs[x].v2 = mt->gs[x].v3; + mt->gs[x].v3 = 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 = 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 < mt->tone_count; x++) { + eng_all[x] = teletone_goertzel_result (&mt->gs[x]); + eng_sum += eng_all[x]; + } + + gtest = 0; + for(x = 0; 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 < 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; +} + + +int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, + int16_t sample_buffer[], + int samples) +{ + teletone_process_t row_energy[GRID_FACTOR]; + teletone_process_t col_energy[GRID_FACTOR]; + teletone_process_t famp; + teletone_process_t 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 = 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 = 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 = 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 = 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); +} + + +int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, + char *buf, + int max) +{ + 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 expandtab: + */ diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c new file mode 100644 index 0000000000..4e388c8d3b --- /dev/null +++ b/libs/freetdm/src/libteletone_generate.c @@ -0,0 +1,467 @@ +/* + * libteletone + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is libteletone + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * libteletone.c -- Tone Generator + * + * + * + * Exception: + * The author hereby grants the use of this source code under the + * following license if and only if the source code is distributed + * as part of the openzap library. Any use or distribution of this + * source code outside the scope of the openzap library will nullify the + * following license and reinact the MPL 1.1 as stated above. + * + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#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 + + +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; + +} + +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; + +} + +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 = 1500; + ts->decay_step = 0; + 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; +} + +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) { + ts->datalen = need + ts->dynamic; + if (!(ts->buffer = realloc(ts->buffer, ts->datalen))) { + return -1; + } + } + + return 0; +} + +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_process_t tones[TELETONE_MAX_TONES]; + int decay = 0; + int duration; + int wait = 0; + teletone_process_t sample; + + ts->samples = 0; + + 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) { + if (ts->decay_step) { + if (ts->decay_factor) { + decay = (duration - (duration / ts->decay_factor)); + } else { + decay = 0; + } + } + if (ts->volume < 0) { + ts->volume = 0; + } + + for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { + tones[freqlen] = (teletone_process_t) map->freqs[freqlen] * (2 * M_PI); + } + + 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_step && !(ts->samples % ts->decay_step) && ts->volume > 0 && ts->samples > decay) { + ts->volume += ts->decay_direction; + } + + sample = (teletone_process_t) 128; + + for (i = 0; i < freqlen; i++) { + sample += ((teletone_process_t) 2 * (ts->volume > 0 ? ts->volume : 1) * cos(tones[i] * ts->samples * period)); + } + normalize_to_16bit(sample); + 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 %d; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %d; decay_step %d; 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->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); +} + +int teletone_run(teletone_generation_session_t *ts, 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': + ts->volume = atoi(cur + 2); + break; + case '>': + ts->decay_factor = atoi(cur + 2); + ts->decay_direction = -1; + break; + case '<': + ts->decay_factor = atoi(cur + 2); + ts->decay_direction = 1; + break; + case '+': + ts->decay_step = atoi(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 expandtab: + */ diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 40c3173975..acf21e14f2 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -33,6 +33,7 @@ #include "openzap.h" +#include #ifdef ZAP_WANPIPE_SUPPORT #include "zap_wanpipe.h" #endif @@ -44,6 +45,78 @@ static struct { zap_hash_t *interface_hash; } globals; +static char *LEVEL_NAMES[] = { + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + NULL +}; + +static char *cut_path(char *in) +{ + char *p, *ret = in; + char delims[] = "/\\"; + char *i; + + for (i = delims; *i; i++) { + p = in; + while ((p = strchr(p, *i)) != 0) { + ret = ++p; + } + } + return ret; +} + +static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + if (0) { + null_logger(file, func, line, level, fmt); + } +} + +static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + char *fp; + char data[1024]; + + va_list ap; + + fp = cut_path(file); + + va_start(ap, fmt); + + vsnprintf(data, sizeof(data), fmt, ap); + + if (level < 0 || level > 7) { + level = 7; + } + + fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data); + + va_end(ap); + +} + +zap_logger_t global_logger = null_logger; + +void zap_global_set_logger(zap_logger_t logger) +{ + if (logger) { + global_logger = logger; + } else { + global_logger = null_logger; + } +} + +void zap_global_set_default_logger(void) +{ + global_logger = default_logger; +} static int equalkeys(const void *k1, const void *k2) { diff --git a/libs/freetdm/src/wanpipe b/libs/freetdm/src/wanpipe index 4f410a083b..917220c04e 100644 --- a/libs/freetdm/src/wanpipe +++ b/libs/freetdm/src/wanpipe @@ -1,7 +1,6 @@ -CFLAGS +=-DZAP_WANPIPE_SUPPORT +MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT OBJS += zap_wanpipe.o WANPIPE_INCLUDE=/usr/include/wanpipe -#WANPIPE_INCLUDE=../../wanpipe-3.1.0.p18/patches/kdrivers/include WP_CFLAGS =-I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c new file mode 100644 index 0000000000..b3df9ba0ab --- /dev/null +++ b/libs/freetdm/src/zap_buffer.c @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "zap_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; +}; + + +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; + + if ((new_buffer = malloc(sizeof(*new_buffer)))) { + memset(new_buffer, 0, sizeof(*new_buffer)); + + if (start_len) { + if (!(new_buffer->data = malloc(start_len))) { + 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; +} + +zap_size_t zap_buffer_len(zap_buffer_t *buffer) +{ + + assert(buffer != NULL); + + return buffer->datalen; + +} + + +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; + +} + +zap_size_t zap_buffer_inuse(zap_buffer_t *buffer) +{ + assert(buffer != NULL); + + return buffer->used; +} + +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; +} + +void zap_buffer_set_loops(zap_buffer_t *buffer, int loops) +{ + buffer->loops = loops; +} + +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)) == 0) { + if (buffer->loops == 0) { + return 0; + } + buffer->head = buffer->data; + buffer->used = buffer->actually_used; + len = zap_buffer_read(buffer, data, datalen); + buffer->loops--; + } + return len; +} + +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; +} + +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) { + 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; + + 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; + if (!(buffer->data = realloc(buffer->data, new_size))) { + return 0; + } + 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; +} + +void zap_buffer_zero(zap_buffer_t *buffer) +{ + assert(buffer != NULL); + assert(buffer->data != NULL); + + buffer->used = 0; + buffer->head = buffer->data; +} + +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 expandtab: + */ diff --git a/libs/freetdm/src/zt b/libs/freetdm/src/zt index d23da58c15..9e0f14d57c 100644 --- a/libs/freetdm/src/zt +++ b/libs/freetdm/src/zt @@ -1,2 +1,2 @@ -CFLAGS +=-DZAP_ZT_SUPPORT +MOD_CFLAGS +=-DZAP_ZT_SUPPORT OBJS += zap_zt.o From 719bc150570a29f8665fc0393e38f513b5c510e4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 15:08:37 +0000 Subject: [PATCH 0027/1766] windows build, add missing files. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@14 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 32 ++++++++++++++++++++++++++++++++ libs/openzap/src/openzap.c | 5 +++-- libs/openzap/src/zap_buffer.c | 9 ++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index f6ca7e8c6d..7c3f70d4ee 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -164,10 +164,22 @@ RelativePath=".\src\hashtable_itr.c" > + + + + + + @@ -208,6 +220,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -220,10 +236,26 @@ RelativePath=".\src\include\hashtable_private.h" > + + + + + + + + diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index acf21e14f2..6626ccef77 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -74,9 +74,10 @@ static char *cut_path(char *in) static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) { - if (0) { - null_logger(file, func, line, level, fmt); + if (file && func && line && level && fmt) { + return; } + return; } static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index b3df9ba0ab..63ae360414 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -53,11 +53,13 @@ zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_ { zap_buffer_t *new_buffer; - if ((new_buffer = malloc(sizeof(*new_buffer)))) { + new_buffer = malloc(sizeof(*new_buffer)); + if (new_buffer) { memset(new_buffer, 0, sizeof(*new_buffer)); if (start_len) { - if (!(new_buffer->data = malloc(start_len))) { + new_buffer->data = malloc(start_len); + if (!new_buffer->data) { free(new_buffer); return ZAP_MEMERR; } @@ -211,7 +213,8 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d new_size = new_block_size; } buffer->head = buffer->data; - if (!(buffer->data = realloc(buffer->data, new_size))) { + buffer->data = realloc(buffer->data, new_size); + if (!buffer->data) { return 0; } buffer->head = buffer->data; From 22433a9970e96c4ecda8bfefb5346b09503ab924 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 15:08:37 +0000 Subject: [PATCH 0028/1766] windows build, add missing files. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@14 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 32 ++++++++++++++++++++++++++++++++ libs/freetdm/src/openzap.c | 5 +++-- libs/freetdm/src/zap_buffer.c | 9 ++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index f6ca7e8c6d..7c3f70d4ee 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -164,10 +164,22 @@ RelativePath=".\src\hashtable_itr.c" > + + + + + + @@ -208,6 +220,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -220,10 +236,26 @@ RelativePath=".\src\include\hashtable_private.h" > + + + + + + + + diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index acf21e14f2..6626ccef77 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -74,9 +74,10 @@ static char *cut_path(char *in) static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) { - if (0) { - null_logger(file, func, line, level, fmt); + if (file && func && line && level && fmt) { + return; } + return; } static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index b3df9ba0ab..63ae360414 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -53,11 +53,13 @@ zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_ { zap_buffer_t *new_buffer; - if ((new_buffer = malloc(sizeof(*new_buffer)))) { + new_buffer = malloc(sizeof(*new_buffer)); + if (new_buffer) { memset(new_buffer, 0, sizeof(*new_buffer)); if (start_len) { - if (!(new_buffer->data = malloc(start_len))) { + new_buffer->data = malloc(start_len); + if (!new_buffer->data) { free(new_buffer); return ZAP_MEMERR; } @@ -211,7 +213,8 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d new_size = new_block_size; } buffer->head = buffer->data; - if (!(buffer->data = realloc(buffer->data, new_size))) { + buffer->data = realloc(buffer->data, new_size); + if (!buffer->data) { return 0; } buffer->head = buffer->data; From de432ce258c0cc7e6bc97cec86d5afc1db28e577 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 16:57:26 +0000 Subject: [PATCH 0029/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@15 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 3 + libs/openzap/src/hashtable.c | 10 +-- libs/openzap/src/hashtable_itr.c | 12 ++++ libs/openzap/src/include/hashtable.h | 11 ++- libs/openzap/src/include/hashtable_itr.h | 12 +++- libs/openzap/src/include/hashtable_private.h | 12 ++-- libs/openzap/src/include/openzap.h | 31 ++++++--- libs/openzap/src/openzap.c | 70 ++++++++++++++------ libs/openzap/src/testapp.c | 9 +++ libs/openzap/src/zap_wanpipe.c | 25 +++++-- 10 files changed, 145 insertions(+), 50 deletions(-) create mode 100644 libs/openzap/src/testapp.c diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 2f7055b09c..fa8c8d601c 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -42,6 +42,9 @@ $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) +testapp: testapp.c $(MYLIB) + $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm + openzap.o: openzap.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index e03013ba10..763357edce 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -22,13 +22,13 @@ static const unsigned int primes[] = { 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); -const float max_load_factor = 0.65f; +const float max_load_factor = 0.65; /*****************************************************************************/ struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashf) (const void*), - int (*eqf) (const void*,const void*)) + unsigned int (*hashf) (void*), + int (*eqf) (void*,void*)) { struct hashtable *h; unsigned int pindex, size = primes[0]; @@ -54,7 +54,7 @@ create_hashtable(unsigned int minsize, /*****************************************************************************/ unsigned int -hash(struct hashtable *h, const void *k) +hash(struct hashtable *h, void *k) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -160,7 +160,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) /*****************************************************************************/ void * /* returns value associated with key */ -hashtable_search(struct hashtable *h, const void *k) +hashtable_search(struct hashtable *h, void *k) { struct entry *e; unsigned int hashvalue, index; diff --git a/libs/openzap/src/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c index defac691f0..5dced841f3 100644 --- a/libs/openzap/src/hashtable_itr.c +++ b/libs/openzap/src/hashtable_itr.c @@ -34,6 +34,18 @@ hashtable_iterator(struct hashtable *h) return itr; } +/*****************************************************************************/ +/* key - return the key of the (key,value) pair at the current position */ +/* value - return the value of the (key,value) pair at the current position */ + +void * +hashtable_iterator_key(struct hashtable_itr *i) +{ return i->e->k; } + +void * +hashtable_iterator_value(struct hashtable_itr *i) +{ return i->e->v; } + /*****************************************************************************/ /* advance - advance the iterator to the next element * returns zero if advanced to end of table */ diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index 88d76572e8..e6d23ff52f 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -2,6 +2,11 @@ #ifndef __HASHTABLE_CWC22_H__ #define __HASHTABLE_CWC22_H__ +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +#endif struct hashtable; @@ -73,8 +78,8 @@ struct hashtable; struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashfunction) (const void*), - int (*key_eq_fn) (const void*,const void*)); + unsigned int (*hashfunction) (void*), + int (*key_eq_fn) (void*,void*)); /***************************************************************************** * hashtable_insert @@ -114,7 +119,7 @@ int fnname (struct hashtable *h, keytype *k, valuetype *v) \ */ void * -hashtable_search(struct hashtable *h, const void *k); +hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ valuetype * fnname (struct hashtable *h, keytype *k) \ diff --git a/libs/openzap/src/include/hashtable_itr.h b/libs/openzap/src/include/hashtable_itr.h index 50ea10420a..aacf86825a 100644 --- a/libs/openzap/src/include/hashtable_itr.h +++ b/libs/openzap/src/include/hashtable_itr.h @@ -28,12 +28,20 @@ hashtable_iterator(struct hashtable *h); /* hashtable_iterator_key * - return the value of the (key,value) pair at the current position */ -#define hashtable_iterator_key(i) (void *)i->e->k +extern __inline__ void * +hashtable_iterator_key(struct hashtable_itr *i) +{ + return i->e->k; +} /*****************************************************************************/ /* value - return the value of the (key,value) pair at the current position */ -#define hashtable_iterator_value (void *)i->e->v +extern __inline__ void * +hashtable_iterator_value(struct hashtable_itr *i) +{ + return i->e->v; +} /*****************************************************************************/ /* advance - advance the iterator to the next element diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index 8668d58e32..edf59efe18 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -5,6 +5,7 @@ #include "hashtable.h" + /*****************************************************************************/ struct entry { @@ -19,17 +20,20 @@ struct hashtable { unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; - unsigned int (*hashfn) (const void *k); - int (*eqfn) (const void *k1, const void *k2); + unsigned int (*hashfn) (void *k); + int (*eqfn) (void *k1, void *k2); }; /*****************************************************************************/ unsigned int -hash(struct hashtable *h, const void *k); +hash(struct hashtable *h, void *k); /*****************************************************************************/ /* indexFor */ -#define indexFor(hashvalue, tablelength) (unsigned int)(hashvalue % tablelength) +static __inline__ unsigned int +indexFor(unsigned int tablelength, unsigned int hashvalue) { + return (hashvalue % tablelength); +} /* Only works if tablelength == 2^N */ /*static inline unsigned int diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 07d0f20f2f..3e9d74a830 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -209,18 +209,27 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ -#define ZAP_LOG_DEBUG ZAP_PRE, 7 -#define ZAP_LOG_INFO ZAP_PRE, 6 -#define ZAP_LOG_NOTICE ZAP_PRE, 5 -#define ZAP_LOG_WARNING ZAP_PRE, 4 -#define ZAP_LOG_ERROR ZAP_PRE, 3 -#define ZAP_LOG_CRIT ZAP_PRE, 2 -#define ZAP_LOG_ALERT ZAP_PRE, 1 -#define ZAP_LOG_EMERG ZAP_PRE, 0 + +#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 void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); -extern zap_logger_t global_logger; -#define zap_log global_logger; +extern zap_logger_t zap_log; struct zap_software_interface { const char *name; @@ -252,7 +261,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); -void zap_global_set_default_logger(void); +void zap_global_set_default_logger(int level); typedef struct hashtable zap_hash_t; diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 6626ccef77..a56ced9db6 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -74,18 +74,25 @@ static char *cut_path(char *in) static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) { - if (file && func && line && level && fmt) { - return; + if (0) { + null_logger(file, func, line, level, fmt, fmt + sizeof(fmt)); } - return; } +static int zap_log_level; + static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) { char *fp; char data[1024]; - va_list ap; + + if (level < 0 || level > 7) { + level = 7; + } + if (level > zap_log_level) { + return; + } fp = cut_path(file); @@ -93,9 +100,6 @@ static void default_logger(char *file, const char *func, int line, int level, ch vsnprintf(data, sizeof(data), fmt, ap); - if (level < 0 || level > 7) { - level = 7; - } fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data); @@ -103,37 +107,42 @@ static void default_logger(char *file, const char *func, int line, int level, ch } -zap_logger_t global_logger = null_logger; +zap_logger_t zap_log = null_logger; void zap_global_set_logger(zap_logger_t logger) { if (logger) { - global_logger = logger; + zap_log = logger; } else { - global_logger = null_logger; + zap_log = null_logger; } } -void zap_global_set_default_logger(void) +void zap_global_set_default_logger(int level) { - global_logger = default_logger; + if (level < 0 || level > 7) { + level = 7; + } + + zap_log = default_logger; + zap_log_level = level; } -static int equalkeys(const void *k1, const void *k2) +static int equalkeys(void *k1, void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static unsigned hashfromstring(const void *ky) +static unsigned hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; unsigned hash = 0; int c; - + while ((c = *str++)) { hash = c + (hash << 6) + (hash << 16) - hash; } - + return hash; } @@ -176,7 +185,7 @@ zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, name); + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; @@ -303,37 +312,51 @@ zap_status_t zap_global_init(void) char *var, *val; unsigned configured = 0; zap_software_interface_t *zint; + int modcount; globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); zint = NULL; + modcount = 0; #ifdef ZAP_WANPIPE_SUPPORT if (wanpipe_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + modcount++; + } else { + zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n"); } #endif zint = NULL; #ifdef ZAP_ZT_SUPPORT if (zt_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + modcount++; + } else { + zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n"); } #endif - - if (!zap_config_open_file(&cfg, "openzap.conf")) { + if (!modcount) { + zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); return ZAP_FAIL; } + if (!zap_config_open_file(&cfg, "openzap.conf")) { + return ZAP_FAIL; + } + while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "openzap")) { if (!strcmp(var, "load")) { zap_software_interface_t *zint; - + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); if (zint) { if (zint->configure(zint) == ZAP_SUCCESS) { configured++; } + } else { + zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val); } } } @@ -341,7 +364,12 @@ zap_status_t zap_global_init(void) zap_config_close_file(&cfg); - return configured ? ZAP_SUCCESS : ZAP_FAIL; + if (configured) { + return ZAP_SUCCESS; + } + + zap_log(ZAP_LOG_ERROR, "No modules configured!\n"); + return ZAP_FAIL; } zap_status_t zap_global_destroy(void) diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c new file mode 100644 index 0000000000..c53bfed6f5 --- /dev/null +++ b/libs/openzap/src/testapp.c @@ -0,0 +1,9 @@ +#include "openzap.h" + +int main(int argc, char *argv[]) +{ + printf("hello\n"); + + zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + zap_global_init(); +} diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 945382c412..e699626b3f 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -71,6 +71,8 @@ typedef unsigned __int32 u_int32_t; #include #include +static zap_software_interface_t wanpipe_interface; + struct wanpipe_channel { struct zap_channel zchan; int x; @@ -81,18 +83,35 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) zap_config_t cfg; char *var, *val; int catno = -1; + zap_span_t *span = NULL; ZINT_CONFIGURE_MUZZLE; + zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n"); if (!zap_config_open_file(&cfg, "wanpipe.conf")) { return ZAP_FAIL; } - + while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "span")) { if (cfg.catno != catno) { + zap_log(ZAP_LOG_DEBUG, "found config for span %d\n", cfg.catno); + catno = cfg.catno; + if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); + } else { + zap_log(ZAP_LOG_CRIT, "failure creating span\n"); + span = NULL; + } + continue; } + + if (!span) { + continue; + } + + zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); } } zap_config_close_file(&cfg); @@ -142,8 +161,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write) return ZAP_FAIL; } -static zap_software_interface_t wanpipe_interface; - zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); @@ -160,7 +177,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.write = wanpipe_write; *zint = &wanpipe_interface; - return ZAP_FAIL; + return ZAP_SUCCESS; } zap_status_t wanpipe_destroy(void) From f57307bf9140bbf1f0bf9f9ec5b1292fdffe01f6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 16:57:26 +0000 Subject: [PATCH 0030/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@15 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 3 + libs/freetdm/src/hashtable.c | 10 +-- libs/freetdm/src/hashtable_itr.c | 12 ++++ libs/freetdm/src/include/hashtable.h | 11 ++- libs/freetdm/src/include/hashtable_itr.h | 12 +++- libs/freetdm/src/include/hashtable_private.h | 12 ++-- libs/freetdm/src/include/openzap.h | 31 ++++++--- libs/freetdm/src/openzap.c | 70 ++++++++++++++------ libs/freetdm/src/testapp.c | 9 +++ libs/freetdm/src/zap_wanpipe.c | 25 +++++-- 10 files changed, 145 insertions(+), 50 deletions(-) create mode 100644 libs/freetdm/src/testapp.c diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 2f7055b09c..fa8c8d601c 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -42,6 +42,9 @@ $(MYLIB): $(OBJS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) +testapp: testapp.c $(MYLIB) + $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm + openzap.o: openzap.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index e03013ba10..763357edce 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -22,13 +22,13 @@ static const unsigned int primes[] = { 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); -const float max_load_factor = 0.65f; +const float max_load_factor = 0.65; /*****************************************************************************/ struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashf) (const void*), - int (*eqf) (const void*,const void*)) + unsigned int (*hashf) (void*), + int (*eqf) (void*,void*)) { struct hashtable *h; unsigned int pindex, size = primes[0]; @@ -54,7 +54,7 @@ create_hashtable(unsigned int minsize, /*****************************************************************************/ unsigned int -hash(struct hashtable *h, const void *k) +hash(struct hashtable *h, void *k) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -160,7 +160,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) /*****************************************************************************/ void * /* returns value associated with key */ -hashtable_search(struct hashtable *h, const void *k) +hashtable_search(struct hashtable *h, void *k) { struct entry *e; unsigned int hashvalue, index; diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index defac691f0..5dced841f3 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -34,6 +34,18 @@ hashtable_iterator(struct hashtable *h) return itr; } +/*****************************************************************************/ +/* key - return the key of the (key,value) pair at the current position */ +/* value - return the value of the (key,value) pair at the current position */ + +void * +hashtable_iterator_key(struct hashtable_itr *i) +{ return i->e->k; } + +void * +hashtable_iterator_value(struct hashtable_itr *i) +{ return i->e->v; } + /*****************************************************************************/ /* advance - advance the iterator to the next element * returns zero if advanced to end of table */ diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 88d76572e8..e6d23ff52f 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -2,6 +2,11 @@ #ifndef __HASHTABLE_CWC22_H__ #define __HASHTABLE_CWC22_H__ +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +#endif struct hashtable; @@ -73,8 +78,8 @@ struct hashtable; struct hashtable * create_hashtable(unsigned int minsize, - unsigned int (*hashfunction) (const void*), - int (*key_eq_fn) (const void*,const void*)); + unsigned int (*hashfunction) (void*), + int (*key_eq_fn) (void*,void*)); /***************************************************************************** * hashtable_insert @@ -114,7 +119,7 @@ int fnname (struct hashtable *h, keytype *k, valuetype *v) \ */ void * -hashtable_search(struct hashtable *h, const void *k); +hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ valuetype * fnname (struct hashtable *h, keytype *k) \ diff --git a/libs/freetdm/src/include/hashtable_itr.h b/libs/freetdm/src/include/hashtable_itr.h index 50ea10420a..aacf86825a 100644 --- a/libs/freetdm/src/include/hashtable_itr.h +++ b/libs/freetdm/src/include/hashtable_itr.h @@ -28,12 +28,20 @@ hashtable_iterator(struct hashtable *h); /* hashtable_iterator_key * - return the value of the (key,value) pair at the current position */ -#define hashtable_iterator_key(i) (void *)i->e->k +extern __inline__ void * +hashtable_iterator_key(struct hashtable_itr *i) +{ + return i->e->k; +} /*****************************************************************************/ /* value - return the value of the (key,value) pair at the current position */ -#define hashtable_iterator_value (void *)i->e->v +extern __inline__ void * +hashtable_iterator_value(struct hashtable_itr *i) +{ + return i->e->v; +} /*****************************************************************************/ /* advance - advance the iterator to the next element diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index 8668d58e32..edf59efe18 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -5,6 +5,7 @@ #include "hashtable.h" + /*****************************************************************************/ struct entry { @@ -19,17 +20,20 @@ struct hashtable { unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; - unsigned int (*hashfn) (const void *k); - int (*eqfn) (const void *k1, const void *k2); + unsigned int (*hashfn) (void *k); + int (*eqfn) (void *k1, void *k2); }; /*****************************************************************************/ unsigned int -hash(struct hashtable *h, const void *k); +hash(struct hashtable *h, void *k); /*****************************************************************************/ /* indexFor */ -#define indexFor(hashvalue, tablelength) (unsigned int)(hashvalue % tablelength) +static __inline__ unsigned int +indexFor(unsigned int tablelength, unsigned int hashvalue) { + return (hashvalue % tablelength); +} /* Only works if tablelength == 2^N */ /*static inline unsigned int diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 07d0f20f2f..3e9d74a830 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -209,18 +209,27 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ -#define ZAP_LOG_DEBUG ZAP_PRE, 7 -#define ZAP_LOG_INFO ZAP_PRE, 6 -#define ZAP_LOG_NOTICE ZAP_PRE, 5 -#define ZAP_LOG_WARNING ZAP_PRE, 4 -#define ZAP_LOG_ERROR ZAP_PRE, 3 -#define ZAP_LOG_CRIT ZAP_PRE, 2 -#define ZAP_LOG_ALERT ZAP_PRE, 1 -#define ZAP_LOG_EMERG ZAP_PRE, 0 + +#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 void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); -extern zap_logger_t global_logger; -#define zap_log global_logger; +extern zap_logger_t zap_log; struct zap_software_interface { const char *name; @@ -252,7 +261,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); -void zap_global_set_default_logger(void); +void zap_global_set_default_logger(int level); typedef struct hashtable zap_hash_t; diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 6626ccef77..a56ced9db6 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -74,18 +74,25 @@ static char *cut_path(char *in) static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) { - if (file && func && line && level && fmt) { - return; + if (0) { + null_logger(file, func, line, level, fmt, fmt + sizeof(fmt)); } - return; } +static int zap_log_level; + static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) { char *fp; char data[1024]; - va_list ap; + + if (level < 0 || level > 7) { + level = 7; + } + if (level > zap_log_level) { + return; + } fp = cut_path(file); @@ -93,9 +100,6 @@ static void default_logger(char *file, const char *func, int line, int level, ch vsnprintf(data, sizeof(data), fmt, ap); - if (level < 0 || level > 7) { - level = 7; - } fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data); @@ -103,37 +107,42 @@ static void default_logger(char *file, const char *func, int line, int level, ch } -zap_logger_t global_logger = null_logger; +zap_logger_t zap_log = null_logger; void zap_global_set_logger(zap_logger_t logger) { if (logger) { - global_logger = logger; + zap_log = logger; } else { - global_logger = null_logger; + zap_log = null_logger; } } -void zap_global_set_default_logger(void) +void zap_global_set_default_logger(int level) { - global_logger = default_logger; + if (level < 0 || level > 7) { + level = 7; + } + + zap_log = default_logger; + zap_log_level = level; } -static int equalkeys(const void *k1, const void *k2) +static int equalkeys(void *k1, void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static unsigned hashfromstring(const void *ky) +static unsigned hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; unsigned hash = 0; int c; - + while ((c = *str++)) { hash = c + (hash << 6) + (hash << 16) - hash; } - + return hash; } @@ -176,7 +185,7 @@ zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, name); + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; @@ -303,37 +312,51 @@ zap_status_t zap_global_init(void) char *var, *val; unsigned configured = 0; zap_software_interface_t *zint; + int modcount; globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); zint = NULL; + modcount = 0; #ifdef ZAP_WANPIPE_SUPPORT if (wanpipe_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + modcount++; + } else { + zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n"); } #endif zint = NULL; #ifdef ZAP_ZT_SUPPORT if (zt_init(&zint) == ZAP_SUCCESS) { hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + modcount++; + } else { + zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n"); } #endif - - if (!zap_config_open_file(&cfg, "openzap.conf")) { + if (!modcount) { + zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); return ZAP_FAIL; } + if (!zap_config_open_file(&cfg, "openzap.conf")) { + return ZAP_FAIL; + } + while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "openzap")) { if (!strcmp(var, "load")) { zap_software_interface_t *zint; - + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); if (zint) { if (zint->configure(zint) == ZAP_SUCCESS) { configured++; } + } else { + zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val); } } } @@ -341,7 +364,12 @@ zap_status_t zap_global_init(void) zap_config_close_file(&cfg); - return configured ? ZAP_SUCCESS : ZAP_FAIL; + if (configured) { + return ZAP_SUCCESS; + } + + zap_log(ZAP_LOG_ERROR, "No modules configured!\n"); + return ZAP_FAIL; } zap_status_t zap_global_destroy(void) diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c new file mode 100644 index 0000000000..c53bfed6f5 --- /dev/null +++ b/libs/freetdm/src/testapp.c @@ -0,0 +1,9 @@ +#include "openzap.h" + +int main(int argc, char *argv[]) +{ + printf("hello\n"); + + zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + zap_global_init(); +} diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 945382c412..e699626b3f 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -71,6 +71,8 @@ typedef unsigned __int32 u_int32_t; #include #include +static zap_software_interface_t wanpipe_interface; + struct wanpipe_channel { struct zap_channel zchan; int x; @@ -81,18 +83,35 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) zap_config_t cfg; char *var, *val; int catno = -1; + zap_span_t *span = NULL; ZINT_CONFIGURE_MUZZLE; + zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n"); if (!zap_config_open_file(&cfg, "wanpipe.conf")) { return ZAP_FAIL; } - + while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "span")) { if (cfg.catno != catno) { + zap_log(ZAP_LOG_DEBUG, "found config for span %d\n", cfg.catno); + catno = cfg.catno; + if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); + } else { + zap_log(ZAP_LOG_CRIT, "failure creating span\n"); + span = NULL; + } + continue; } + + if (!span) { + continue; + } + + zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); } } zap_config_close_file(&cfg); @@ -142,8 +161,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write) return ZAP_FAIL; } -static zap_software_interface_t wanpipe_interface; - zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); @@ -160,7 +177,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.write = wanpipe_write; *zint = &wanpipe_interface; - return ZAP_FAIL; + return ZAP_SUCCESS; } zap_status_t wanpipe_destroy(void) From 5175361bcce41e7f0ebc75833a7c2ca30111322d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 16:58:11 +0000 Subject: [PATCH 0031/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@16 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index a56ced9db6..533e820bc0 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -79,7 +79,7 @@ static void null_logger(char *file, const char *func, int line, int level, char } } -static int zap_log_level; +static int zap_log_level = 7; static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) { From ead9df37447a3d4ba8862c89e8532ce90b7a889e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 16:58:11 +0000 Subject: [PATCH 0032/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@16 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index a56ced9db6..533e820bc0 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -79,7 +79,7 @@ static void null_logger(char *file, const char *func, int line, int level, char } } -static int zap_log_level; +static int zap_log_level = 7; static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) { From 93f95458f5ba6ccd1892d8805b8b7d600070330c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 17:25:01 +0000 Subject: [PATCH 0033/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@17 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/hashtable_itr.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libs/openzap/src/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c index 5dced841f3..1fed1ed9a7 100644 --- a/libs/openzap/src/hashtable_itr.c +++ b/libs/openzap/src/hashtable_itr.c @@ -38,14 +38,6 @@ hashtable_iterator(struct hashtable *h) /* key - return the key of the (key,value) pair at the current position */ /* value - return the value of the (key,value) pair at the current position */ -void * -hashtable_iterator_key(struct hashtable_itr *i) -{ return i->e->k; } - -void * -hashtable_iterator_value(struct hashtable_itr *i) -{ return i->e->v; } - /*****************************************************************************/ /* advance - advance the iterator to the next element * returns zero if advanced to end of table */ From 783b7bd890a22ae636ef360f76b0ad99cdcc60ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 17:25:01 +0000 Subject: [PATCH 0034/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@17 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/hashtable_itr.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index 5dced841f3..1fed1ed9a7 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -38,14 +38,6 @@ hashtable_iterator(struct hashtable *h) /* key - return the key of the (key,value) pair at the current position */ /* value - return the value of the (key,value) pair at the current position */ -void * -hashtable_iterator_key(struct hashtable_itr *i) -{ return i->e->k; } - -void * -hashtable_iterator_value(struct hashtable_itr *i) -{ return i->e->v; } - /*****************************************************************************/ /* advance - advance the iterator to the next element * returns zero if advanced to end of table */ From 5cf9a1a6084fcd8a6471c6794da1c443c9a7a218 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 17:25:13 +0000 Subject: [PATCH 0035/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@18 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/hashtable_itr.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/openzap/src/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c index 1fed1ed9a7..defac691f0 100644 --- a/libs/openzap/src/hashtable_itr.c +++ b/libs/openzap/src/hashtable_itr.c @@ -34,10 +34,6 @@ hashtable_iterator(struct hashtable *h) return itr; } -/*****************************************************************************/ -/* key - return the key of the (key,value) pair at the current position */ -/* value - return the value of the (key,value) pair at the current position */ - /*****************************************************************************/ /* advance - advance the iterator to the next element * returns zero if advanced to end of table */ From 929af2d40d63dc9bf545550265c9ed0514d871a8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 17:25:13 +0000 Subject: [PATCH 0036/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@18 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/hashtable_itr.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index 1fed1ed9a7..defac691f0 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -34,10 +34,6 @@ hashtable_iterator(struct hashtable *h) return itr; } -/*****************************************************************************/ -/* key - return the key of the (key,value) pair at the current position */ -/* value - return the value of the (key,value) pair at the current position */ - /*****************************************************************************/ /* advance - advance the iterator to the next element * returns zero if advanced to end of table */ From ff19eef0d07efa71f8692d379e1e50ce09150d4b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 17:26:36 +0000 Subject: [PATCH 0037/1766] explicitly make initialized value a float. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@19 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/hashtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index 763357edce..c903d3ca67 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -22,7 +22,7 @@ static const unsigned int primes[] = { 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); -const float max_load_factor = 0.65; +const float max_load_factor = 0.65f; /*****************************************************************************/ struct hashtable * From ab71cd66b129a5668cdbd4780341d35c45e4cc87 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 17:26:36 +0000 Subject: [PATCH 0038/1766] explicitly make initialized value a float. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@19 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/hashtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 763357edce..c903d3ca67 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -22,7 +22,7 @@ static const unsigned int primes[] = { 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); -const float max_load_factor = 0.65; +const float max_load_factor = 0.65f; /*****************************************************************************/ struct hashtable * From 27239d5f78b1f20acfe5d23f79265e96c7fc83ad Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 17:28:35 +0000 Subject: [PATCH 0039/1766] conditional expression is constant git-svn-id: http://svn.openzap.org/svn/openzap/trunk@20 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 533e820bc0..58341cdef9 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -74,9 +74,10 @@ static char *cut_path(char *in) static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) { - if (0) { - null_logger(file, func, line, level, fmt, fmt + sizeof(fmt)); + if (file && func && line && level && fmt) { + return; } + return; } static int zap_log_level = 7; From 39de1d92c5f257e49c97a4470d4748ca21fbc462 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 17:28:35 +0000 Subject: [PATCH 0040/1766] conditional expression is constant git-svn-id: http://svn.openzap.org/svn/openzap/trunk@20 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 533e820bc0..58341cdef9 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -74,9 +74,10 @@ static char *cut_path(char *in) static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) { - if (0) { - null_logger(file, func, line, level, fmt, fmt + sizeof(fmt)); + if (file && func && line && level && fmt) { + return; } + return; } static int zap_log_level = 7; From 7d5bd9cd6ec5968ecb69da00c44df1c52732722f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 19:19:03 +0000 Subject: [PATCH 0041/1766] zap_wanpipe.c now builds clean on windows, you need to have AFT_beta_6_0_2_5 in a paralell directory to the main openzap directory. File available from: ftp://ftp.sangoma.com/WINDOWS/AFT/AFT_beta_6_0_2_5.zip git-svn-id: http://svn.openzap.org/svn/openzap/trunk@21 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 6 ++---- libs/openzap/src/zap_wanpipe.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index 7c3f70d4ee..2cae0acfce 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -193,20 +193,18 @@ > diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index e699626b3f..1552504560 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -46,7 +46,7 @@ #ifdef _MSC_VER /* disable warning for zero length array in a struct */ /* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4200) +#pragma warning(disable:4200 4201 4214) #endif #include #include From fc1d625d1e18c3adc8696c4a2b2c28da7c9c1ef7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 17 May 2007 19:19:03 +0000 Subject: [PATCH 0042/1766] zap_wanpipe.c now builds clean on windows, you need to have AFT_beta_6_0_2_5 in a paralell directory to the main openzap directory. File available from: ftp://ftp.sangoma.com/WINDOWS/AFT/AFT_beta_6_0_2_5.zip git-svn-id: http://svn.openzap.org/svn/openzap/trunk@21 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 6 ++---- libs/freetdm/src/zap_wanpipe.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index 7c3f70d4ee..2cae0acfce 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -193,20 +193,18 @@ > diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index e699626b3f..1552504560 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -46,7 +46,7 @@ #ifdef _MSC_VER /* disable warning for zero length array in a struct */ /* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4200) +#pragma warning(disable:4200 4201 4214) #endif #include #include From 0c1eacbf2515369aa44ae6b0054fdeeebc7dd996 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 20:28:38 +0000 Subject: [PATCH 0043/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@22 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 23 ++- libs/openzap/src/openzap.c | 59 ++++++- libs/openzap/src/testapp.c | 13 +- libs/openzap/src/zap_wanpipe.c | 249 +++++++++++++++++++++++++++-- 4 files changed, 325 insertions(+), 19 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3e9d74a830..b47acfdbbe 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -73,10 +73,24 @@ #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 +#ifdef WIN32 +#include +typedef HANDLE zap_socket_t; +#else typedef int zap_socket_t; +#endif + typedef size_t zap_size_t; struct zap_software_interface; +#define zap_true(expr)\ + (expr && ( !strcasecmp(expr, "yes") ||\ + !strcasecmp(expr, "on") ||\ + !strcasecmp(expr, "true") ||\ + !strcasecmp(expr, "enabled") ||\ + !strcasecmp(expr, "active") ||\ + atoi(expr))) ? 1 : 0 + #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) /*! @@ -115,6 +129,8 @@ struct zap_software_interface; */ #define zap_safe_free(it) if (it) {free(it);it=NULL;} +#define zap_socket_close(it) if (it > -1) { close(it); it = -1;} + typedef enum { ZAP_SUCCESS, ZAP_FAIL, @@ -249,7 +265,6 @@ typedef struct zap_software_interface zap_software_interface_t; zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); @@ -262,7 +277,9 @@ zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); - +unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen); typedef struct hashtable zap_hash_t; - +typedef struct hashtable_itr zap_hash_itr_t; +typedef struct key zap_hash_key_t; +typedef struct value zap_hash_val_t; #endif diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 58341cdef9..4644444811 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -108,6 +108,7 @@ static void default_logger(char *file, const char *func, int line, int level, ch } + zap_logger_t zap_log = null_logger; void zap_global_set_logger(zap_logger_t logger) @@ -174,6 +175,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->type = type; new_chan->sockfd = sockfd; new_chan->zint = span->zint; + new_chan->span_id = span->span_id; + new_chan->chan_id = span->chan_count; zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -182,7 +185,6 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { @@ -375,7 +377,6 @@ zap_status_t zap_global_init(void) zap_status_t zap_global_destroy(void) { - hashtable_destroy(globals.interface_hash, 1); #ifdef ZAP_ZT_SUPPORT zt_destroy(); @@ -383,5 +384,59 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_WANPIPE_SUPPORT wanpipe_destroy(); #endif + + hashtable_destroy(globals.interface_hash, 0); + return ZAP_SUCCESS; } + + +unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen) +{ + int argc; + char *ptr; + int quot = 0; + char qc = '"'; + char *e; + int x; + + if (!buf || !array || !arraylen) { + return 0; + } + + memset(array, 0, arraylen * sizeof(*array)); + + ptr = buf; + + for (argc = 0; *ptr && (argc < arraylen - 1); argc++) { + array[argc] = ptr; + for (; *ptr; ptr++) { + if (*ptr == qc) { + if (quot) { + quot--; + } else { + quot++; + } + } else if ((*ptr == delim) && !quot) { + *ptr++ = '\0'; + break; + } + } + } + + if (*ptr) { + array[argc++] = ptr; + } + + /* strip quotes */ + for (x = 0; x < argc; x++) { + if (*(array[x]) == qc) { + (array[x])++; + if ((e = strchr(array[x], qc))) { + *e = '\0'; + } + } + } + + return argc; +} diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index c53bfed6f5..d760206313 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -2,8 +2,15 @@ int main(int argc, char *argv[]) { - printf("hello\n"); - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); - zap_global_init(); + + if (zap_global_init() != ZAP_SUCCESS) { + fprintf(stderr, "Error loading OpenZAP\n"); + exit(-1); + } + + printf("OpenZAP loaded\n"); + sleep(2); + zap_global_destroy(); + } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 1552504560..d76b802988 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -70,6 +70,7 @@ typedef unsigned __int32 u_int32_t; #include #include #include +#include static zap_software_interface_t wanpipe_interface; @@ -78,12 +79,196 @@ struct wanpipe_channel { int x; }; + + +unsigned wp_open_lapd(zap_span_t *span, const char *name) +{ + struct wan_sockaddr_ll sa; + zap_socket_t sock = -1; + + errno = 0; + sock = socket(AF_WANPIPE, SOCK_RAW, 0); + memset(&sa,0,sizeof(struct wan_sockaddr_ll)); + + zap_log(ZAP_LOG_DEBUG, "attempting to open lapd device socket %s\n", name); + + if( sock < 0 ) { + zap_log(ZAP_LOG_ERROR, "socket error!\n"); + return 0; + } + + zap_copy_string(sa.sll_device, name, sizeof(sa.sll_device)); + zap_copy_string(sa.sll_card, "wanpipe1", sizeof(sa.sll_card)); + + sa.sll_protocol = htons(PVC_PROT); + sa.sll_family = AF_WANPIPE; + + if(bind(sock, (struct sockaddr *)&sa, sizeof(struct wan_sockaddr_ll)) < 0){ + zap_log(ZAP_LOG_ERROR, "socket bind error!\n"); + return 0; + } + + { + unsigned customer_id; + int err = ioctl(sock,SIOC_AFT_CUSTOMER_ID,&customer_id); + if (err){ + perror("Customer ID: "); + }else{ + printf("Customer ID 0x%X\n",customer_id); + return 1; + } + + + } + + + return 0; +} + + +static zap_socket_t wp_open_device(int span, int chan) +{ + char fname[256]; +#if defined(WIN32) + + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + return CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); +#else + int fd=-1; + + sprintf(fname, "/dev/wptdm_s%dc%d", span, chan); + + fd = open(fname, O_RDWR); + + return fd; +#endif +} + +static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type) +{ + unsigned configured = 0, x; + + for(x = start; x < end; x++) { + zap_channel_t *chan; + zap_socket_t sockfd = -1; + + sockfd = wp_open_device(spanno, x); + + if (sockfd > -1 && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + configured++; + } else { + zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + } + } + + return configured; +} + +static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type) +{ + int items, i; + char *mydata, *item_list[10]; + char *sp, *ch, *mx; + int channo; + int spanno; + int top = 0; + int x; + unsigned configured = 0; + + assert(str != NULL); + + if (type == ZAP_CHAN_TYPE_DQ921) { + char *flag, *name; + + flag = str; + if ((name = strchr(flag, ':'))) { + name++; + } else { + name = flag; + flag = NULL; + } + + if (flag) { + if (strstr(flag, "q931")) { + type = ZAP_CHAN_TYPE_DQ931; + configured += wp_open_lapd(span, name); + return configured; + } + + } + } + + 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, "Invalid input on line %d\n", cfg->lineno); + 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; + } + + configured += wp_open_range(span, spanno, channo, top, type); + + } + + free(mydata); + + return configured; +} + static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; char *var, *val; int catno = -1; zap_span_t *span = NULL; + int new_span = 0; + unsigned configured = 0, d = 0; ZINT_CONFIGURE_MUZZLE; @@ -95,28 +280,52 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "span")) { if (cfg.catno != catno) { - zap_log(ZAP_LOG_DEBUG, "found config for span %d\n", cfg.catno); + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; - if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span\n"); - span = NULL; - } - - continue; + new_span = 1; + span = NULL; } + if (new_span) { + if (!strcasecmp(var, "enabled") && ! zap_true(val)) { + zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); + } else { + if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); + } else { + zap_log(ZAP_LOG_CRIT, "failure creating span\n"); + span = NULL; + } + } + new_span = 0; + continue; + } + if (!span) { continue; } zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); + + if (!strcasecmp(var, "enabled")) { + zap_log(ZAP_LOG_WARNING, "'enabled' param ignored when it's not the first param in a [span]\n"); + } else if (!strcasecmp(var, "b-channel")) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); + } else if (!strcasecmp(var, "d-channel")) { + if (d) { + zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); + } else { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_DQ921); + d++; + } + } } } zap_config_close_file(&cfg); - return ZAP_FAIL; + zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); + + return configured ? ZAP_SUCCESS : ZAP_FAIL; } static ZINT_OPEN_FUNCTION(wanpipe_open) @@ -182,5 +391,23 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) zap_status_t wanpipe_destroy(void) { - return ZAP_FAIL; + int i,j; + + for(i = 1; i <= wanpipe_interface.span_index; i++) { + zap_span_t *cur_span = &wanpipe_interface.spans[i]; + + if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { + for(j = 1; j <= cur_span->chan_count; j++) { + zap_channel_t *cur_chan = &cur_span->channels[j]; + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); + zap_socket_close(cur_chan->sockfd); + } + } + } + } + + memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); + + return ZAP_SUCCESS; } From 98ab4f440c3bf695b6bd58286b38c66e297015e0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 20:28:38 +0000 Subject: [PATCH 0044/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@22 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 23 ++- libs/freetdm/src/openzap.c | 59 ++++++- libs/freetdm/src/testapp.c | 13 +- libs/freetdm/src/zap_wanpipe.c | 249 +++++++++++++++++++++++++++-- 4 files changed, 325 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 3e9d74a830..b47acfdbbe 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -73,10 +73,24 @@ #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 +#ifdef WIN32 +#include +typedef HANDLE zap_socket_t; +#else typedef int zap_socket_t; +#endif + typedef size_t zap_size_t; struct zap_software_interface; +#define zap_true(expr)\ + (expr && ( !strcasecmp(expr, "yes") ||\ + !strcasecmp(expr, "on") ||\ + !strcasecmp(expr, "true") ||\ + !strcasecmp(expr, "enabled") ||\ + !strcasecmp(expr, "active") ||\ + atoi(expr))) ? 1 : 0 + #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) /*! @@ -115,6 +129,8 @@ struct zap_software_interface; */ #define zap_safe_free(it) if (it) {free(it);it=NULL;} +#define zap_socket_close(it) if (it > -1) { close(it); it = -1;} + typedef enum { ZAP_SUCCESS, ZAP_FAIL, @@ -249,7 +265,6 @@ typedef struct zap_software_interface zap_software_interface_t; zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); @@ -262,7 +277,9 @@ zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); - +unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen); typedef struct hashtable zap_hash_t; - +typedef struct hashtable_itr zap_hash_itr_t; +typedef struct key zap_hash_key_t; +typedef struct value zap_hash_val_t; #endif diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 58341cdef9..4644444811 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -108,6 +108,7 @@ static void default_logger(char *file, const char *func, int line, int level, ch } + zap_logger_t zap_log = null_logger; void zap_global_set_logger(zap_logger_t logger) @@ -174,6 +175,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->type = type; new_chan->sockfd = sockfd; new_chan->zint = span->zint; + new_chan->span_id = span->span_id; + new_chan->chan_id = span->chan_count; zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -182,7 +185,6 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_destroy(zap_span_t **span); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { @@ -375,7 +377,6 @@ zap_status_t zap_global_init(void) zap_status_t zap_global_destroy(void) { - hashtable_destroy(globals.interface_hash, 1); #ifdef ZAP_ZT_SUPPORT zt_destroy(); @@ -383,5 +384,59 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_WANPIPE_SUPPORT wanpipe_destroy(); #endif + + hashtable_destroy(globals.interface_hash, 0); + return ZAP_SUCCESS; } + + +unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen) +{ + int argc; + char *ptr; + int quot = 0; + char qc = '"'; + char *e; + int x; + + if (!buf || !array || !arraylen) { + return 0; + } + + memset(array, 0, arraylen * sizeof(*array)); + + ptr = buf; + + for (argc = 0; *ptr && (argc < arraylen - 1); argc++) { + array[argc] = ptr; + for (; *ptr; ptr++) { + if (*ptr == qc) { + if (quot) { + quot--; + } else { + quot++; + } + } else if ((*ptr == delim) && !quot) { + *ptr++ = '\0'; + break; + } + } + } + + if (*ptr) { + array[argc++] = ptr; + } + + /* strip quotes */ + for (x = 0; x < argc; x++) { + if (*(array[x]) == qc) { + (array[x])++; + if ((e = strchr(array[x], qc))) { + *e = '\0'; + } + } + } + + return argc; +} diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index c53bfed6f5..d760206313 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -2,8 +2,15 @@ int main(int argc, char *argv[]) { - printf("hello\n"); - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); - zap_global_init(); + + if (zap_global_init() != ZAP_SUCCESS) { + fprintf(stderr, "Error loading OpenZAP\n"); + exit(-1); + } + + printf("OpenZAP loaded\n"); + sleep(2); + zap_global_destroy(); + } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 1552504560..d76b802988 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -70,6 +70,7 @@ typedef unsigned __int32 u_int32_t; #include #include #include +#include static zap_software_interface_t wanpipe_interface; @@ -78,12 +79,196 @@ struct wanpipe_channel { int x; }; + + +unsigned wp_open_lapd(zap_span_t *span, const char *name) +{ + struct wan_sockaddr_ll sa; + zap_socket_t sock = -1; + + errno = 0; + sock = socket(AF_WANPIPE, SOCK_RAW, 0); + memset(&sa,0,sizeof(struct wan_sockaddr_ll)); + + zap_log(ZAP_LOG_DEBUG, "attempting to open lapd device socket %s\n", name); + + if( sock < 0 ) { + zap_log(ZAP_LOG_ERROR, "socket error!\n"); + return 0; + } + + zap_copy_string(sa.sll_device, name, sizeof(sa.sll_device)); + zap_copy_string(sa.sll_card, "wanpipe1", sizeof(sa.sll_card)); + + sa.sll_protocol = htons(PVC_PROT); + sa.sll_family = AF_WANPIPE; + + if(bind(sock, (struct sockaddr *)&sa, sizeof(struct wan_sockaddr_ll)) < 0){ + zap_log(ZAP_LOG_ERROR, "socket bind error!\n"); + return 0; + } + + { + unsigned customer_id; + int err = ioctl(sock,SIOC_AFT_CUSTOMER_ID,&customer_id); + if (err){ + perror("Customer ID: "); + }else{ + printf("Customer ID 0x%X\n",customer_id); + return 1; + } + + + } + + + return 0; +} + + +static zap_socket_t wp_open_device(int span, int chan) +{ + char fname[256]; +#if defined(WIN32) + + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + return CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); +#else + int fd=-1; + + sprintf(fname, "/dev/wptdm_s%dc%d", span, chan); + + fd = open(fname, O_RDWR); + + return fd; +#endif +} + +static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type) +{ + unsigned configured = 0, x; + + for(x = start; x < end; x++) { + zap_channel_t *chan; + zap_socket_t sockfd = -1; + + sockfd = wp_open_device(spanno, x); + + if (sockfd > -1 && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + configured++; + } else { + zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + } + } + + return configured; +} + +static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type) +{ + int items, i; + char *mydata, *item_list[10]; + char *sp, *ch, *mx; + int channo; + int spanno; + int top = 0; + int x; + unsigned configured = 0; + + assert(str != NULL); + + if (type == ZAP_CHAN_TYPE_DQ921) { + char *flag, *name; + + flag = str; + if ((name = strchr(flag, ':'))) { + name++; + } else { + name = flag; + flag = NULL; + } + + if (flag) { + if (strstr(flag, "q931")) { + type = ZAP_CHAN_TYPE_DQ931; + configured += wp_open_lapd(span, name); + return configured; + } + + } + } + + 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, "Invalid input on line %d\n", cfg->lineno); + 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; + } + + configured += wp_open_range(span, spanno, channo, top, type); + + } + + free(mydata); + + return configured; +} + static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; char *var, *val; int catno = -1; zap_span_t *span = NULL; + int new_span = 0; + unsigned configured = 0, d = 0; ZINT_CONFIGURE_MUZZLE; @@ -95,28 +280,52 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "span")) { if (cfg.catno != catno) { - zap_log(ZAP_LOG_DEBUG, "found config for span %d\n", cfg.catno); + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; - if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span\n"); - span = NULL; - } - - continue; + new_span = 1; + span = NULL; } + if (new_span) { + if (!strcasecmp(var, "enabled") && ! zap_true(val)) { + zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); + } else { + if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); + } else { + zap_log(ZAP_LOG_CRIT, "failure creating span\n"); + span = NULL; + } + } + new_span = 0; + continue; + } + if (!span) { continue; } zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); + + if (!strcasecmp(var, "enabled")) { + zap_log(ZAP_LOG_WARNING, "'enabled' param ignored when it's not the first param in a [span]\n"); + } else if (!strcasecmp(var, "b-channel")) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); + } else if (!strcasecmp(var, "d-channel")) { + if (d) { + zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); + } else { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_DQ921); + d++; + } + } } } zap_config_close_file(&cfg); - return ZAP_FAIL; + zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); + + return configured ? ZAP_SUCCESS : ZAP_FAIL; } static ZINT_OPEN_FUNCTION(wanpipe_open) @@ -182,5 +391,23 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) zap_status_t wanpipe_destroy(void) { - return ZAP_FAIL; + int i,j; + + for(i = 1; i <= wanpipe_interface.span_index; i++) { + zap_span_t *cur_span = &wanpipe_interface.spans[i]; + + if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { + for(j = 1; j <= cur_span->chan_count; j++) { + zap_channel_t *cur_chan = &cur_span->channels[j]; + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); + zap_socket_close(cur_chan->sockfd); + } + } + } + } + + memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); + + return ZAP_SUCCESS; } From 2dcf9de997efca73363bbe794439a342e5d7b469 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 21:58:11 +0000 Subject: [PATCH 0045/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@23 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 7 +-- libs/openzap/src/openzap.c | 24 ++++++--- libs/openzap/src/zap_wanpipe.c | 81 +++--------------------------- 3 files changed, 28 insertions(+), 84 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index b47acfdbbe..61981dd9fb 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -175,6 +175,7 @@ struct zap_channel { zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; + void *mod_data; struct zap_software_interface *zint; }; typedef struct zap_channel zap_channel_t; @@ -189,8 +190,8 @@ struct zap_span { typedef struct zap_span zap_span_t; #define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) -#define ZINT_OPEN_ARGS (unsigned span_id, unsigned chan_id, zap_channel_t **zchan) -#define ZINT_CLOSE_ARGS (zap_channel_t **zchan) +#define ZINT_OPEN_ARGS (zap_channel_t *zchan) +#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) #define ZINT_SET_CODEC_ARGS (zap_channel_t *zchan, zap_codec_t codec) #define ZINT_SET_INTERVAL_ARGS (zap_channel_t *zchan, unsigned ms) #define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) @@ -216,7 +217,7 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS #define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLE assert(span_id != 0); assert(chan_id != 0); assert(zchan != NULL) +#define ZINT_OPEN_MUZZLEE assert(zchan != NULL) #define ZINT_CLOSE_MUZZLE assert(zchan != NULL) #define ZINT_SET_CODEC_MUZZLE assert(zchan != NULL); assert(codec != 0) #define ZINT_SET_INTERVAL_MUZZLE assert(zchan != NULL); assert(ms != 0) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 4644444811..8f3383b759 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -189,35 +189,43 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_status_t status = ZAP_FAIL; if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; check = &zint->spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; - return ZAP_SUCCESS; + status = check->zint->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + } + return status; } } - return ZAP_FAIL; + return status; } zap_status_t zap_channel_close(zap_channel_t **zchan) { zap_channel_t *check; + zap_status_t status = ZAP_FAIL; + *zchan = NULL; - assert(zchan != NULL); check = *zchan; assert(check != NULL); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - zap_clear_flag(check, ZAP_CHANNEL_OPEN); - return ZAP_SUCCESS; + status = check->zint->close(check); + if (status == ZAP_SUCCESS) { + zap_clear_flag(check, ZAP_CHANNEL_OPEN); + *zchan = NULL; + } } - return ZAP_FAIL; + return status; } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index d76b802988..a165afea70 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -74,58 +74,6 @@ typedef unsigned __int32 u_int32_t; static zap_software_interface_t wanpipe_interface; -struct wanpipe_channel { - struct zap_channel zchan; - int x; -}; - - - -unsigned wp_open_lapd(zap_span_t *span, const char *name) -{ - struct wan_sockaddr_ll sa; - zap_socket_t sock = -1; - - errno = 0; - sock = socket(AF_WANPIPE, SOCK_RAW, 0); - memset(&sa,0,sizeof(struct wan_sockaddr_ll)); - - zap_log(ZAP_LOG_DEBUG, "attempting to open lapd device socket %s\n", name); - - if( sock < 0 ) { - zap_log(ZAP_LOG_ERROR, "socket error!\n"); - return 0; - } - - zap_copy_string(sa.sll_device, name, sizeof(sa.sll_device)); - zap_copy_string(sa.sll_card, "wanpipe1", sizeof(sa.sll_card)); - - sa.sll_protocol = htons(PVC_PROT); - sa.sll_family = AF_WANPIPE; - - if(bind(sock, (struct sockaddr *)&sa, sizeof(struct wan_sockaddr_ll)) < 0){ - zap_log(ZAP_LOG_ERROR, "socket bind error!\n"); - return 0; - } - - { - unsigned customer_id; - int err = ioctl(sock,SIOC_AFT_CUSTOMER_ID,&customer_id); - if (err){ - perror("Customer ID: "); - }else{ - printf("Customer ID 0x%X\n",customer_id); - return 1; - } - - - } - - - return 0; -} - - static zap_socket_t wp_open_device(int span, int chan) { char fname[256]; @@ -186,26 +134,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa assert(str != NULL); - if (type == ZAP_CHAN_TYPE_DQ921) { - char *flag, *name; - - flag = str; - if ((name = strchr(flag, ':'))) { - name++; - } else { - name = flag; - flag = NULL; - } - - if (flag) { - if (strstr(flag, "q931")) { - type = ZAP_CHAN_TYPE_DQ931; - configured += wp_open_lapd(span, name); - return configured; - } - - } - } mydata = strdup(str); assert(mydata != NULL); @@ -315,7 +243,14 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); } else { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_DQ921); + zap_chan_type_t qtype; + if (!strncasecmp(val, "lapd:", 5)) { + qtype = ZAP_CHAN_TYPE_DQ931; + val += 5; + } else { + qtype = ZAP_CHAN_TYPE_DQ921; + } + configured += wp_configure_channel(&cfg, val, span, qtype); d++; } } From f35e97b5e4201e11e81718ef712c318c105d9d6d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 May 2007 21:58:11 +0000 Subject: [PATCH 0046/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@23 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 7 +-- libs/freetdm/src/openzap.c | 24 ++++++--- libs/freetdm/src/zap_wanpipe.c | 81 +++--------------------------- 3 files changed, 28 insertions(+), 84 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index b47acfdbbe..61981dd9fb 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -175,6 +175,7 @@ struct zap_channel { zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; + void *mod_data; struct zap_software_interface *zint; }; typedef struct zap_channel zap_channel_t; @@ -189,8 +190,8 @@ struct zap_span { typedef struct zap_span zap_span_t; #define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) -#define ZINT_OPEN_ARGS (unsigned span_id, unsigned chan_id, zap_channel_t **zchan) -#define ZINT_CLOSE_ARGS (zap_channel_t **zchan) +#define ZINT_OPEN_ARGS (zap_channel_t *zchan) +#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) #define ZINT_SET_CODEC_ARGS (zap_channel_t *zchan, zap_codec_t codec) #define ZINT_SET_INTERVAL_ARGS (zap_channel_t *zchan, unsigned ms) #define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) @@ -216,7 +217,7 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS #define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLE assert(span_id != 0); assert(chan_id != 0); assert(zchan != NULL) +#define ZINT_OPEN_MUZZLEE assert(zchan != NULL) #define ZINT_CLOSE_MUZZLE assert(zchan != NULL) #define ZINT_SET_CODEC_MUZZLE assert(zchan != NULL); assert(codec != 0) #define ZINT_SET_INTERVAL_MUZZLE assert(zchan != NULL); assert(ms != 0) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 4644444811..8f3383b759 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -189,35 +189,43 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_status_t status = ZAP_FAIL; if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; check = &zint->spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; - return ZAP_SUCCESS; + status = check->zint->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + } + return status; } } - return ZAP_FAIL; + return status; } zap_status_t zap_channel_close(zap_channel_t **zchan) { zap_channel_t *check; + zap_status_t status = ZAP_FAIL; + *zchan = NULL; - assert(zchan != NULL); check = *zchan; assert(check != NULL); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - zap_clear_flag(check, ZAP_CHANNEL_OPEN); - return ZAP_SUCCESS; + status = check->zint->close(check); + if (status == ZAP_SUCCESS) { + zap_clear_flag(check, ZAP_CHANNEL_OPEN); + *zchan = NULL; + } } - return ZAP_FAIL; + return status; } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index d76b802988..a165afea70 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -74,58 +74,6 @@ typedef unsigned __int32 u_int32_t; static zap_software_interface_t wanpipe_interface; -struct wanpipe_channel { - struct zap_channel zchan; - int x; -}; - - - -unsigned wp_open_lapd(zap_span_t *span, const char *name) -{ - struct wan_sockaddr_ll sa; - zap_socket_t sock = -1; - - errno = 0; - sock = socket(AF_WANPIPE, SOCK_RAW, 0); - memset(&sa,0,sizeof(struct wan_sockaddr_ll)); - - zap_log(ZAP_LOG_DEBUG, "attempting to open lapd device socket %s\n", name); - - if( sock < 0 ) { - zap_log(ZAP_LOG_ERROR, "socket error!\n"); - return 0; - } - - zap_copy_string(sa.sll_device, name, sizeof(sa.sll_device)); - zap_copy_string(sa.sll_card, "wanpipe1", sizeof(sa.sll_card)); - - sa.sll_protocol = htons(PVC_PROT); - sa.sll_family = AF_WANPIPE; - - if(bind(sock, (struct sockaddr *)&sa, sizeof(struct wan_sockaddr_ll)) < 0){ - zap_log(ZAP_LOG_ERROR, "socket bind error!\n"); - return 0; - } - - { - unsigned customer_id; - int err = ioctl(sock,SIOC_AFT_CUSTOMER_ID,&customer_id); - if (err){ - perror("Customer ID: "); - }else{ - printf("Customer ID 0x%X\n",customer_id); - return 1; - } - - - } - - - return 0; -} - - static zap_socket_t wp_open_device(int span, int chan) { char fname[256]; @@ -186,26 +134,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa assert(str != NULL); - if (type == ZAP_CHAN_TYPE_DQ921) { - char *flag, *name; - - flag = str; - if ((name = strchr(flag, ':'))) { - name++; - } else { - name = flag; - flag = NULL; - } - - if (flag) { - if (strstr(flag, "q931")) { - type = ZAP_CHAN_TYPE_DQ931; - configured += wp_open_lapd(span, name); - return configured; - } - - } - } mydata = strdup(str); assert(mydata != NULL); @@ -315,7 +243,14 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); } else { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_DQ921); + zap_chan_type_t qtype; + if (!strncasecmp(val, "lapd:", 5)) { + qtype = ZAP_CHAN_TYPE_DQ931; + val += 5; + } else { + qtype = ZAP_CHAN_TYPE_DQ921; + } + configured += wp_configure_channel(&cfg, val, span, qtype); d++; } } From 40ae249d894b90b0fa2f0254086a13a42c407f05 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 03:31:09 +0000 Subject: [PATCH 0047/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@24 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 56 +++++----- libs/openzap/src/openzap.c | 27 +---- libs/openzap/src/zap_wanpipe.c | 170 ++++++++++++++++++++++++++--- 3 files changed, 189 insertions(+), 64 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 61981dd9fb..36f47bd290 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -95,37 +95,37 @@ struct zap_software_interface; /*! \brief Test for the existance of a flag on an arbitary object - \param obj the object to test - \param flag the or'd list of flags to test + \command obj the object to test + \command flag the or'd list of flags to test \return true value if the object has the flags defined */ #define zap_test_flag(obj, flag) ((obj)->flags & flag) /*! \brief Set a flag on an arbitrary object - \param obj the object to set the flags on - \param flag the or'd list of flags to set + \command obj the object to set the flags on + \command flag the or'd list of flags to set */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) /*! \brief Clear a flag on an arbitrary object while locked - \param obj the object to test - \param flag the or'd list of flags to clear + \command obj the object to test + \command flag the or'd list of flags to clear */ #define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) /*! \brief Copy flags from one arbitrary object to another - \param dest the object to copy the flags to - \param src the object to copy the flags from - \param flags the flags to copy + \command dest the object to copy the flags to + \command src the object to copy the flags from + \command flags the flags to copy */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) /*! \brief Free a pointer and set it to NULL unless it already is NULL - \param it the pointer + \command it the pointer */ #define zap_safe_free(it) if (it) {free(it);it=NULL;} @@ -134,14 +134,15 @@ struct zap_software_interface; typedef enum { ZAP_SUCCESS, ZAP_FAIL, - ZAP_MEMERR + ZAP_MEMERR, + ZAP_TIMEOUT } zap_status_t; typedef enum { + ZAP_NO_FLAGS = 0, ZAP_READ = (1 << 0), ZAP_WRITE = (1 << 1), - ZAP_ERROR = (1 << 2), - ZAP_EVENT = (1 << 3) + ZAP_ERROR = (1 << 2) } zap_wait_flag_t; typedef enum { @@ -150,6 +151,11 @@ typedef enum { ZAP_CODEC_SLIN = 10 } zap_codec_t; +typedef enum { + ZAP_COMMAND_SET_INTERVAL, + ZAP_COMMAND_GET_INTERVAL +} zap_command_t; + typedef enum { ZAP_SPAN_CONFIGURED = (1 << 0), ZAP_SPAN_READY = (1 << 1) @@ -192,17 +198,15 @@ typedef struct zap_span zap_span_t; #define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) #define ZINT_OPEN_ARGS (zap_channel_t *zchan) #define ZINT_CLOSE_ARGS (zap_channel_t *zchan) -#define ZINT_SET_CODEC_ARGS (zap_channel_t *zchan, zap_codec_t codec) -#define ZINT_SET_INTERVAL_ARGS (zap_channel_t *zchan, unsigned ms) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) +#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) #define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) #define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; -typedef zap_status_t (*zint_set_codec_t) ZINT_SET_CODEC_ARGS ; -typedef zap_status_t (*zint_set_interval_t) ZINT_SET_INTERVAL_ARGS ; +typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; @@ -210,17 +214,15 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS #define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS #define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS -#define ZINT_SET_CODEC_FUNCTION(name) zap_status_t name ZINT_SET_CODEC_ARGS -#define ZINT_SET_INTERVAL_FUNCTION(name) zap_status_t name ZINT_SET_INTERVAL_ARGS +#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS #define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS #define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS #define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS #define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLEE assert(zchan != NULL) +#define ZINT_OPEN_MUZZLE assert(zchan != NULL) #define ZINT_CLOSE_MUZZLE assert(zchan != NULL) -#define ZINT_SET_CODEC_MUZZLE assert(zchan != NULL); assert(codec != 0) -#define ZINT_SET_INTERVAL_MUZZLE assert(zchan != NULL); assert(ms != 0) +#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) #define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) #define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) @@ -253,8 +255,7 @@ struct zap_software_interface { zint_configure_t configure; zint_open_t open; zint_close_t close; - zint_set_codec_t set_codec; - zint_set_interval_t set_interval; + zint_command_t command; zint_wait_t wait; zint_read_t read; zint_write_t write; @@ -269,9 +270,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); -zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec); -zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to); +zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 8f3383b759..dbb831b3e1 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -229,24 +229,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) } -zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) -{ - assert(zchan != NULL); - assert(zchan->zint != NULL); - - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - return ZAP_FAIL; - } - - if (!zchan->zint->set_codec) { - return ZAP_FAIL; - } - - return zchan->zint->set_codec(zchan, codec); - -} - -zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) +zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -255,15 +238,15 @@ zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) return ZAP_FAIL; } - if (!zchan->zint->set_interval) { + if (!zchan->zint->command) { return ZAP_FAIL; } - return zchan->zint->set_interval(zchan, ms); + return zchan->zint->command(zchan, command, obj); } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -286,7 +269,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data assert(zchan != NULL); assert(zchan->zint != NULL); assert(zchan->zint != NULL); - + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index a165afea70..a7412eab8a 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -236,7 +236,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); if (!strcasecmp(var, "enabled")) { - zap_log(ZAP_LOG_WARNING, "'enabled' param ignored when it's not the first param in a [span]\n"); + zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { @@ -266,42 +266,185 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) static ZINT_OPEN_FUNCTION(wanpipe_open) { ZINT_OPEN_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } static ZINT_CLOSE_FUNCTION(wanpipe_close) { ZINT_CLOSE_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } -static ZINT_SET_CODEC_FUNCTION(wanpipe_set_codec) +static ZINT_COMMAND_FUNCTION(wanpipe_command) { - ZINT_SET_CODEC_MUZZLE; - return ZAP_FAIL; -} + wanpipe_tdm_api_t tdm_api; + int err; -static ZINT_SET_INTERVAL_FUNCTION(wanpipe_set_interval) -{ - ZINT_SET_INTERVAL_MUZZLE; - return ZAP_FAIL; + ZINT_COMMAND_MUZZLE; + + memset(&tdm_api, 0, sizeof(tdm_api)); + + switch(command) { + case ZAP_COMMAND_GET_INTERVAL: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; + + if (!(err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api))) { + *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; + } + + } + break; + case ZAP_COMMAND_SET_INTERVAL: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; + tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); + err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api); + } + break; + }; + + return err ? ZAP_FAIL : ZAP_SUCCESS; } static ZINT_WAIT_FUNCTION(wanpipe_wait) { + fd_set read_fds, write_fds, error_fds, *r = NULL, *w = NULL, *e = NULL; + zap_wait_flag_t inflags = *flags; + int s; + struct timeval tv, *tvp = NULL; + ZINT_WAIT_MUZZLE; - return ZAP_FAIL; + + if (to) { + memset(&tv, 0, sizeof(tv)); + tv.tv_sec = to / 1000; + tv.tv_usec = (to % 1000) * 1000; + tvp = &tv; + } + + FD_ZERO(&read_fds); + FD_ZERO(&write_fds); + FD_ZERO(&error_fds); + + + if (inflags & ZAP_READ) { + r = &read_fds; + FD_SET(zchan->sockfd, r); + } + + if (inflags & ZAP_WRITE) { + w = &write_fds; + FD_SET(zchan->sockfd, w); + } + + if (inflags & ZAP_ERROR) { + e = &error_fds; + FD_SET(zchan->sockfd, e); + } + + *flags = ZAP_NO_FLAGS; + s = select(zchan->sockfd + 1, r, w, e, tvp); + + if (s < 0) { + return ZAP_FAIL; + } + + if (s > 0) { + if (r && FD_ISSET(zchan->sockfd, r)) { + *flags |= ZAP_READ; + } + + if (w && FD_ISSET(zchan->sockfd, w)) { + *flags |= ZAP_WRITE; + } + + if (e && FD_ISSET(zchan->sockfd, e)) { + *flags |= ZAP_ERROR; + } + } + + if (s == 0) { + return ZAP_TIMEOUT; + } + +} + +static ZINT_READ_FUNCTION(wanpipe_read_unix) +{ + int rx_len = 0; + struct msghdr msg; + struct iovec iov[2]; + wp_tdm_api_rx_hdr_t hdrframe; + + memset(&msg, 0, sizeof(struct msghdr)); + + iov[0].iov_len = sizeof(hdrframe); + iov[0].iov_base = &hdrframe; + + iov[1].iov_len = *datalen; + iov[1].iov_base = data; + + msg.msg_iovlen = 2; + msg.msg_iov = iov; + + rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + + if (rx_len <= sizeof(hdrframe)) { + return ZAP_FAIL; + } + + rx_len -= sizeof(hdrframe); + *datalen = rx_len; + + return ZAP_SUCCESS; } static ZINT_READ_FUNCTION(wanpipe_read) { ZINT_READ_MUZZLE; + +#ifndef WIN32 + return wanpipe_read_unix(zchan, data, datalen); +#endif + return ZAP_FAIL; } +static ZINT_WRITE_FUNCTION(wanpipe_write_unix) +{ + int bsent; + struct msghdr msg; + struct iovec iov[2]; + wp_tdm_api_rx_hdr_t hdrframe; + + memset(&msg, 0, sizeof(struct msghdr)); + + iov[0].iov_len = sizeof(hdrframe); + iov[0].iov_base = &hdrframe; + + iov[1].iov_len = *datalen; + iov[1].iov_base = data; + + msg.msg_iovlen = 2; + msg.msg_iov = iov; + + bsent = write(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + + if (bsent > 0){ + bsent -= sizeof(wp_tdm_api_tx_hdr_t); + } + +} + static ZINT_WRITE_FUNCTION(wanpipe_write) { ZINT_WRITE_MUZZLE; + +#ifndef WIN32 + return wanpipe_write_unix(zchan, data, datalen); +#endif + return ZAP_FAIL; } @@ -314,8 +457,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.configure = wanpipe_configure; wanpipe_interface.open = wanpipe_open; wanpipe_interface.close = wanpipe_close; - wanpipe_interface.set_codec = wanpipe_set_codec; - wanpipe_interface.set_interval = wanpipe_set_interval; + wanpipe_interface.command = wanpipe_command; wanpipe_interface.wait = wanpipe_wait; wanpipe_interface.read = wanpipe_read; wanpipe_interface.write = wanpipe_write; From 8e5d077ed702a17301daa3694b39819811eeba2e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 03:31:09 +0000 Subject: [PATCH 0048/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@24 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 56 +++++----- libs/freetdm/src/openzap.c | 27 +---- libs/freetdm/src/zap_wanpipe.c | 170 ++++++++++++++++++++++++++--- 3 files changed, 189 insertions(+), 64 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 61981dd9fb..36f47bd290 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -95,37 +95,37 @@ struct zap_software_interface; /*! \brief Test for the existance of a flag on an arbitary object - \param obj the object to test - \param flag the or'd list of flags to test + \command obj the object to test + \command flag the or'd list of flags to test \return true value if the object has the flags defined */ #define zap_test_flag(obj, flag) ((obj)->flags & flag) /*! \brief Set a flag on an arbitrary object - \param obj the object to set the flags on - \param flag the or'd list of flags to set + \command obj the object to set the flags on + \command flag the or'd list of flags to set */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) /*! \brief Clear a flag on an arbitrary object while locked - \param obj the object to test - \param flag the or'd list of flags to clear + \command obj the object to test + \command flag the or'd list of flags to clear */ #define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) /*! \brief Copy flags from one arbitrary object to another - \param dest the object to copy the flags to - \param src the object to copy the flags from - \param flags the flags to copy + \command dest the object to copy the flags to + \command src the object to copy the flags from + \command flags the flags to copy */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) /*! \brief Free a pointer and set it to NULL unless it already is NULL - \param it the pointer + \command it the pointer */ #define zap_safe_free(it) if (it) {free(it);it=NULL;} @@ -134,14 +134,15 @@ struct zap_software_interface; typedef enum { ZAP_SUCCESS, ZAP_FAIL, - ZAP_MEMERR + ZAP_MEMERR, + ZAP_TIMEOUT } zap_status_t; typedef enum { + ZAP_NO_FLAGS = 0, ZAP_READ = (1 << 0), ZAP_WRITE = (1 << 1), - ZAP_ERROR = (1 << 2), - ZAP_EVENT = (1 << 3) + ZAP_ERROR = (1 << 2) } zap_wait_flag_t; typedef enum { @@ -150,6 +151,11 @@ typedef enum { ZAP_CODEC_SLIN = 10 } zap_codec_t; +typedef enum { + ZAP_COMMAND_SET_INTERVAL, + ZAP_COMMAND_GET_INTERVAL +} zap_command_t; + typedef enum { ZAP_SPAN_CONFIGURED = (1 << 0), ZAP_SPAN_READY = (1 << 1) @@ -192,17 +198,15 @@ typedef struct zap_span zap_span_t; #define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) #define ZINT_OPEN_ARGS (zap_channel_t *zchan) #define ZINT_CLOSE_ARGS (zap_channel_t *zchan) -#define ZINT_SET_CODEC_ARGS (zap_channel_t *zchan, zap_codec_t codec) -#define ZINT_SET_INTERVAL_ARGS (zap_channel_t *zchan, unsigned ms) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) +#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) #define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) #define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; -typedef zap_status_t (*zint_set_codec_t) ZINT_SET_CODEC_ARGS ; -typedef zap_status_t (*zint_set_interval_t) ZINT_SET_INTERVAL_ARGS ; +typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; @@ -210,17 +214,15 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS #define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS #define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS -#define ZINT_SET_CODEC_FUNCTION(name) zap_status_t name ZINT_SET_CODEC_ARGS -#define ZINT_SET_INTERVAL_FUNCTION(name) zap_status_t name ZINT_SET_INTERVAL_ARGS +#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS #define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS #define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS #define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS #define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLEE assert(zchan != NULL) +#define ZINT_OPEN_MUZZLE assert(zchan != NULL) #define ZINT_CLOSE_MUZZLE assert(zchan != NULL) -#define ZINT_SET_CODEC_MUZZLE assert(zchan != NULL); assert(codec != 0) -#define ZINT_SET_INTERVAL_MUZZLE assert(zchan != NULL); assert(ms != 0) +#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) #define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) #define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) @@ -253,8 +255,7 @@ struct zap_software_interface { zint_configure_t configure; zint_open_t open; zint_close_t close; - zint_set_codec_t set_codec; - zint_set_interval_t set_interval; + zint_command_t command; zint_wait_t wait; zint_read_t read; zint_write_t write; @@ -269,9 +270,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); -zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec); -zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to); +zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 8f3383b759..dbb831b3e1 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -229,24 +229,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) } -zap_status_t zap_channel_set_codec(zap_channel_t *zchan, zap_codec_t codec) -{ - assert(zchan != NULL); - assert(zchan->zint != NULL); - - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - return ZAP_FAIL; - } - - if (!zchan->zint->set_codec) { - return ZAP_FAIL; - } - - return zchan->zint->set_codec(zchan, codec); - -} - -zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) +zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -255,15 +238,15 @@ zap_status_t zap_channel_set_interval(zap_channel_t *zchan, unsigned ms) return ZAP_FAIL; } - if (!zchan->zint->set_interval) { + if (!zchan->zint->command) { return ZAP_FAIL; } - return zchan->zint->set_interval(zchan, ms); + return zchan->zint->command(zchan, command, obj); } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t flags, unsigned to) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -286,7 +269,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data assert(zchan != NULL); assert(zchan->zint != NULL); assert(zchan->zint != NULL); - + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { return ZAP_FAIL; } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index a165afea70..a7412eab8a 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -236,7 +236,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); if (!strcasecmp(var, "enabled")) { - zap_log(ZAP_LOG_WARNING, "'enabled' param ignored when it's not the first param in a [span]\n"); + zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { @@ -266,42 +266,185 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) static ZINT_OPEN_FUNCTION(wanpipe_open) { ZINT_OPEN_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } static ZINT_CLOSE_FUNCTION(wanpipe_close) { ZINT_CLOSE_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } -static ZINT_SET_CODEC_FUNCTION(wanpipe_set_codec) +static ZINT_COMMAND_FUNCTION(wanpipe_command) { - ZINT_SET_CODEC_MUZZLE; - return ZAP_FAIL; -} + wanpipe_tdm_api_t tdm_api; + int err; -static ZINT_SET_INTERVAL_FUNCTION(wanpipe_set_interval) -{ - ZINT_SET_INTERVAL_MUZZLE; - return ZAP_FAIL; + ZINT_COMMAND_MUZZLE; + + memset(&tdm_api, 0, sizeof(tdm_api)); + + switch(command) { + case ZAP_COMMAND_GET_INTERVAL: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; + + if (!(err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api))) { + *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; + } + + } + break; + case ZAP_COMMAND_SET_INTERVAL: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; + tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); + err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api); + } + break; + }; + + return err ? ZAP_FAIL : ZAP_SUCCESS; } static ZINT_WAIT_FUNCTION(wanpipe_wait) { + fd_set read_fds, write_fds, error_fds, *r = NULL, *w = NULL, *e = NULL; + zap_wait_flag_t inflags = *flags; + int s; + struct timeval tv, *tvp = NULL; + ZINT_WAIT_MUZZLE; - return ZAP_FAIL; + + if (to) { + memset(&tv, 0, sizeof(tv)); + tv.tv_sec = to / 1000; + tv.tv_usec = (to % 1000) * 1000; + tvp = &tv; + } + + FD_ZERO(&read_fds); + FD_ZERO(&write_fds); + FD_ZERO(&error_fds); + + + if (inflags & ZAP_READ) { + r = &read_fds; + FD_SET(zchan->sockfd, r); + } + + if (inflags & ZAP_WRITE) { + w = &write_fds; + FD_SET(zchan->sockfd, w); + } + + if (inflags & ZAP_ERROR) { + e = &error_fds; + FD_SET(zchan->sockfd, e); + } + + *flags = ZAP_NO_FLAGS; + s = select(zchan->sockfd + 1, r, w, e, tvp); + + if (s < 0) { + return ZAP_FAIL; + } + + if (s > 0) { + if (r && FD_ISSET(zchan->sockfd, r)) { + *flags |= ZAP_READ; + } + + if (w && FD_ISSET(zchan->sockfd, w)) { + *flags |= ZAP_WRITE; + } + + if (e && FD_ISSET(zchan->sockfd, e)) { + *flags |= ZAP_ERROR; + } + } + + if (s == 0) { + return ZAP_TIMEOUT; + } + +} + +static ZINT_READ_FUNCTION(wanpipe_read_unix) +{ + int rx_len = 0; + struct msghdr msg; + struct iovec iov[2]; + wp_tdm_api_rx_hdr_t hdrframe; + + memset(&msg, 0, sizeof(struct msghdr)); + + iov[0].iov_len = sizeof(hdrframe); + iov[0].iov_base = &hdrframe; + + iov[1].iov_len = *datalen; + iov[1].iov_base = data; + + msg.msg_iovlen = 2; + msg.msg_iov = iov; + + rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + + if (rx_len <= sizeof(hdrframe)) { + return ZAP_FAIL; + } + + rx_len -= sizeof(hdrframe); + *datalen = rx_len; + + return ZAP_SUCCESS; } static ZINT_READ_FUNCTION(wanpipe_read) { ZINT_READ_MUZZLE; + +#ifndef WIN32 + return wanpipe_read_unix(zchan, data, datalen); +#endif + return ZAP_FAIL; } +static ZINT_WRITE_FUNCTION(wanpipe_write_unix) +{ + int bsent; + struct msghdr msg; + struct iovec iov[2]; + wp_tdm_api_rx_hdr_t hdrframe; + + memset(&msg, 0, sizeof(struct msghdr)); + + iov[0].iov_len = sizeof(hdrframe); + iov[0].iov_base = &hdrframe; + + iov[1].iov_len = *datalen; + iov[1].iov_base = data; + + msg.msg_iovlen = 2; + msg.msg_iov = iov; + + bsent = write(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + + if (bsent > 0){ + bsent -= sizeof(wp_tdm_api_tx_hdr_t); + } + +} + static ZINT_WRITE_FUNCTION(wanpipe_write) { ZINT_WRITE_MUZZLE; + +#ifndef WIN32 + return wanpipe_write_unix(zchan, data, datalen); +#endif + return ZAP_FAIL; } @@ -314,8 +457,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.configure = wanpipe_configure; wanpipe_interface.open = wanpipe_open; wanpipe_interface.close = wanpipe_close; - wanpipe_interface.set_codec = wanpipe_set_codec; - wanpipe_interface.set_interval = wanpipe_set_interval; + wanpipe_interface.command = wanpipe_command; wanpipe_interface.wait = wanpipe_wait; wanpipe_interface.read = wanpipe_read; wanpipe_interface.write = wanpipe_write; From 73ca7fc464856b0cb38920f9f1fed2e785f0e948 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 04:18:19 +0000 Subject: [PATCH 0049/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@25 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/testapp.c | 30 +++++++++++++++++++++++-- libs/openzap/src/zap_wanpipe.c | 35 +++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 36f47bd290..5626df6adc 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -152,6 +152,7 @@ typedef enum { } zap_codec_t; typedef enum { + ZAP_COMMAND_NOOP, ZAP_COMMAND_SET_INTERVAL, ZAP_COMMAND_GET_INTERVAL } zap_command_t; diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index d760206313..20727dd677 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -3,14 +3,40 @@ int main(int argc, char *argv[]) { zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); - + zap_channel_t *chan; + unsigned ms = 20; + if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); exit(-1); } printf("OpenZAP loaded\n"); - sleep(2); + + + if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + int x = 0; + + if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { + zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms); + printf("interval set to %u\n", ms); + } else { + printf("set interval failed\n"); + } + + + for(x = 0; x < 25; x++) { + unsigned char buf[160]; + zap_size_t len = sizeof(buf); + if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { + printf("READ: %d\n", len); + } else { + printf("FAIL! %d\n", len); + break; + } + } + } + zap_global_destroy(); } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index a7412eab8a..026ba4d070 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -189,6 +189,18 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } +static zap_status_t wp_tdm_cmd_exec(zap_socket_t fd, wanpipe_tdm_api_t *tdm_api) +{ + int err; + +#if defined(WIN32) + err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd); +#else + err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd); +#endif + return err ? ZAP_FAIL : ZAP_SUCCESS; +} + static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; @@ -289,7 +301,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - if (!(err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api))) { + if (!(err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api))) { *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; } @@ -299,7 +311,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); - err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api); + err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api); } break; }; @@ -377,7 +389,9 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) struct iovec iov[2]; wp_tdm_api_rx_hdr_t hdrframe; - memset(&msg, 0, sizeof(struct msghdr)); + memset(&msg, 0, sizeof(msg)); + memset(&hdrframe, 0, sizeof(hdrframe)); + memset(iov, 0, sizeof(iov[0])*2); iov[0].iov_len = sizeof(hdrframe); iov[0].iov_base = &hdrframe; @@ -388,15 +402,18 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) msg.msg_iovlen = 2; msg.msg_iov = iov; - rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); - if (rx_len <= sizeof(hdrframe)) { - return ZAP_FAIL; + if (rx_len > 0) { + rx_len -= sizeof(hdrframe); } - rx_len -= sizeof(hdrframe); *datalen = rx_len; + if (rx_len <= 0) { + return ZAP_FAIL; + } + return ZAP_SUCCESS; } @@ -418,7 +435,9 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) struct iovec iov[2]; wp_tdm_api_rx_hdr_t hdrframe; - memset(&msg, 0, sizeof(struct msghdr)); + memset(&msg, 0, sizeof(msg)); + memset(&hdrframe, 0, sizeof(hdrframe)); + memset(iov, 0, sizeof(iov[0])*2); iov[0].iov_len = sizeof(hdrframe); iov[0].iov_base = &hdrframe; From a2485caac08f2a2b635a3dbae5517aa02ad1a822 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 04:18:19 +0000 Subject: [PATCH 0050/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@25 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/testapp.c | 30 +++++++++++++++++++++++-- libs/freetdm/src/zap_wanpipe.c | 35 +++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 36f47bd290..5626df6adc 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -152,6 +152,7 @@ typedef enum { } zap_codec_t; typedef enum { + ZAP_COMMAND_NOOP, ZAP_COMMAND_SET_INTERVAL, ZAP_COMMAND_GET_INTERVAL } zap_command_t; diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index d760206313..20727dd677 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -3,14 +3,40 @@ int main(int argc, char *argv[]) { zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); - + zap_channel_t *chan; + unsigned ms = 20; + if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); exit(-1); } printf("OpenZAP loaded\n"); - sleep(2); + + + if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + int x = 0; + + if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { + zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms); + printf("interval set to %u\n", ms); + } else { + printf("set interval failed\n"); + } + + + for(x = 0; x < 25; x++) { + unsigned char buf[160]; + zap_size_t len = sizeof(buf); + if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { + printf("READ: %d\n", len); + } else { + printf("FAIL! %d\n", len); + break; + } + } + } + zap_global_destroy(); } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index a7412eab8a..026ba4d070 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -189,6 +189,18 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } +static zap_status_t wp_tdm_cmd_exec(zap_socket_t fd, wanpipe_tdm_api_t *tdm_api) +{ + int err; + +#if defined(WIN32) + err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd); +#else + err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd); +#endif + return err ? ZAP_FAIL : ZAP_SUCCESS; +} + static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; @@ -289,7 +301,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - if (!(err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api))) { + if (!(err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api))) { *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; } @@ -299,7 +311,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); - err = sangoma_tdm_cmd_exec(zchan->sockfd, tdm_api); + err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api); } break; }; @@ -377,7 +389,9 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) struct iovec iov[2]; wp_tdm_api_rx_hdr_t hdrframe; - memset(&msg, 0, sizeof(struct msghdr)); + memset(&msg, 0, sizeof(msg)); + memset(&hdrframe, 0, sizeof(hdrframe)); + memset(iov, 0, sizeof(iov[0])*2); iov[0].iov_len = sizeof(hdrframe); iov[0].iov_base = &hdrframe; @@ -388,15 +402,18 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) msg.msg_iovlen = 2; msg.msg_iov = iov; - rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); - if (rx_len <= sizeof(hdrframe)) { - return ZAP_FAIL; + if (rx_len > 0) { + rx_len -= sizeof(hdrframe); } - rx_len -= sizeof(hdrframe); *datalen = rx_len; + if (rx_len <= 0) { + return ZAP_FAIL; + } + return ZAP_SUCCESS; } @@ -418,7 +435,9 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) struct iovec iov[2]; wp_tdm_api_rx_hdr_t hdrframe; - memset(&msg, 0, sizeof(struct msghdr)); + memset(&msg, 0, sizeof(msg)); + memset(&hdrframe, 0, sizeof(hdrframe)); + memset(iov, 0, sizeof(iov[0])*2); iov[0].iov_len = sizeof(hdrframe); iov[0].iov_base = &hdrframe; From 60e7073544b3a26b4d927281d1643704d6fc7e5b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 04:46:42 +0000 Subject: [PATCH 0051/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@26 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testapp.c | 18 ++++++++++++------ libs/openzap/src/zap_wanpipe.c | 7 +++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 20727dd677..bb6b8d91cf 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -24,15 +24,21 @@ int main(int argc, char *argv[]) printf("set interval failed\n"); } - for(x = 0; x < 25; x++) { - unsigned char buf[160]; + unsigned char buf[80]; zap_size_t len = sizeof(buf); - if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { - printf("READ: %d\n", len); + zap_wait_flag_t flags = ZAP_READ; + + zap_channel_wait(chan, &flags, 0); + if (flags & ZAP_READ) { + if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { + printf("READ: %d\n", len); + } else { + printf("READ FAIL! %d\n", len); + break; + } } else { - printf("FAIL! %d\n", len); - break; + printf("wait fail\n"); } } } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 026ba4d070..53ce0cc9d0 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -326,8 +326,6 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) int s; struct timeval tv, *tvp = NULL; - ZINT_WAIT_MUZZLE; - if (to) { memset(&tv, 0, sizeof(tv)); tv.tv_sec = to / 1000; @@ -357,7 +355,7 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) *flags = ZAP_NO_FLAGS; s = select(zchan->sockfd + 1, r, w, e, tvp); - + if (s < 0) { return ZAP_FAIL; } @@ -411,6 +409,7 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) *datalen = rx_len; if (rx_len <= 0) { + perror("wtf"); return ZAP_FAIL; } @@ -433,7 +432,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) int bsent; struct msghdr msg; struct iovec iov[2]; - wp_tdm_api_rx_hdr_t hdrframe; + wp_tdm_api_tx_hdr_t hdrframe; memset(&msg, 0, sizeof(msg)); memset(&hdrframe, 0, sizeof(hdrframe)); From 5c59ad5abfefef013fa7f2dd7c6e4091191d2723 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 04:46:42 +0000 Subject: [PATCH 0052/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@26 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testapp.c | 18 ++++++++++++------ libs/freetdm/src/zap_wanpipe.c | 7 +++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 20727dd677..bb6b8d91cf 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -24,15 +24,21 @@ int main(int argc, char *argv[]) printf("set interval failed\n"); } - for(x = 0; x < 25; x++) { - unsigned char buf[160]; + unsigned char buf[80]; zap_size_t len = sizeof(buf); - if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { - printf("READ: %d\n", len); + zap_wait_flag_t flags = ZAP_READ; + + zap_channel_wait(chan, &flags, 0); + if (flags & ZAP_READ) { + if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { + printf("READ: %d\n", len); + } else { + printf("READ FAIL! %d\n", len); + break; + } } else { - printf("FAIL! %d\n", len); - break; + printf("wait fail\n"); } } } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 026ba4d070..53ce0cc9d0 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -326,8 +326,6 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) int s; struct timeval tv, *tvp = NULL; - ZINT_WAIT_MUZZLE; - if (to) { memset(&tv, 0, sizeof(tv)); tv.tv_sec = to / 1000; @@ -357,7 +355,7 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) *flags = ZAP_NO_FLAGS; s = select(zchan->sockfd + 1, r, w, e, tvp); - + if (s < 0) { return ZAP_FAIL; } @@ -411,6 +409,7 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) *datalen = rx_len; if (rx_len <= 0) { + perror("wtf"); return ZAP_FAIL; } @@ -433,7 +432,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) int bsent; struct msghdr msg; struct iovec iov[2]; - wp_tdm_api_rx_hdr_t hdrframe; + wp_tdm_api_tx_hdr_t hdrframe; memset(&msg, 0, sizeof(msg)); memset(&hdrframe, 0, sizeof(hdrframe)); From 2511f8ff0e0e05aa8d57490116395749bcd4f948 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 18 May 2007 05:33:19 +0000 Subject: [PATCH 0053/1766] step towards building on windows again. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@27 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 40 +- libs/openzap/src/include/openzap.h | 20 +- .../openzap/src/include/zap_wanpipe_windows.h | 363 ++++++++++++++++++ libs/openzap/src/zap_wanpipe.c | 65 ++-- 4 files changed, 454 insertions(+), 34 deletions(-) create mode 100644 libs/openzap/src/include/zap_wanpipe_windows.h diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index 2cae0acfce..bdcaead122 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="4" - CharacterSet="1" + CharacterSet="2" > + + + + + + + + + + + + + + diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 5626df6adc..4ee1e3a6fe 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -36,6 +36,19 @@ #define _XOPEN_SOURCE 500 +#ifndef HAVE_STRINGS_H +#define HAVE_STRINGS_H 1 +#endif +#ifndef HAVE_SYS_SOCKET_H +#define HAVE_SYS_SOCKET_H 1 +#endif + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#define __WINDOWS__ +#endif +#endif + #ifdef _MSC_VER #if (_MSC_VER >= 1400) /* VC8+ */ #ifndef _CRT_SECURE_NO_DEPRECATE @@ -51,12 +64,17 @@ #ifndef snprintf #define snprintf _snprintf #endif +#undef HAVE_STRINGS_H +#undef HAVE_SYS_SOCKET_H +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4706) #endif #include #include #include -#ifndef _MSC_VER +#ifdef HAVE_STRINGS_H #include #endif #include diff --git a/libs/openzap/src/include/zap_wanpipe_windows.h b/libs/openzap/src/include/zap_wanpipe_windows.h new file mode 100644 index 0000000000..d5773da640 --- /dev/null +++ b/libs/openzap/src/include/zap_wanpipe_windows.h @@ -0,0 +1,363 @@ +/***************************************************************************** + * win_api_common.h Windows Sangoma API Code Library + * + * Author(s): David Rokhvarg + * + * Copyright: (c) 1984-2006 Sangoma Technologies Inc. + * + * ============================================================================ + */ + +#ifndef _WIN_API_COMMON_H +#define _WIN_API_COMMON_H + +#define DEV_NAME_LEN 100 +char device_name[DEV_NAME_LEN]; + +/* IOCTL management structures and variables*/ +wan_udp_hdr_t wan_udp; + +static wan_cmd_api_t api_cmd; +static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; + +/* keeps the LAST (and single) event received */ +static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; + +static +int +tdmv_api_ioctl( + HANDLE fd, + wanpipe_tdm_api_cmd_t *tdm_api_cmd + ) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; + wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)tdm_api_cmd, + sizeof(wanpipe_tdm_api_cmd_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //actual ioctl failed + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + //ioctl ok, but command failed + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)tdm_api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wanpipe_tdm_api_cmd_t)); + return 0; +} + +static +int +wanpipe_api_ioctl( + HANDLE fd, + wan_cmd_api_t *api_cmd + ) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; + wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)api_cmd, + sizeof(wan_cmd_api_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wan_cmd_api_t)); + return 0; +} + +// Blocking read command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +USHORT +DoReadCommand( + HANDLE drv, + RX_DATA_STRUCT * pRx + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlReadCommand, + (LPVOID)NULL, + 0L, + (LPVOID)pRx, + sizeof(RX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //check messages log + return 1; + }else{ + return 0; + } +} + +// Blocking write command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +UCHAR +DoWriteCommand( + HANDLE drv, + TX_DATA_STRUCT * pTx + ) +{ + DWORD ln; + + if(DeviceIoControl( + drv, + IoctlWriteCommand, + (LPVOID)pTx, + (ULONG)sizeof(TX_DATA_STRUCT), + (LPVOID)pTx, + sizeof(TX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +// Blocking API Poll command. +static +USHORT +DoApiPollCommand( + HANDLE drv, + API_POLL_STRUCT *api_poll_ptr + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlApiPoll, + (LPVOID)NULL, + 0L, + (LPVOID)api_poll_ptr, + sizeof(API_POLL_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +static +int +DoManagementCommand( + HANDLE drv, + wan_udp_hdr_t* wan_udp + ) +{ + DWORD ln; + static unsigned char id = 0; + + wan_udp->wan_udphdr_request_reply = 0x01; + wan_udp->wan_udphdr_id = id++; + wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + if(DeviceIoControl( + drv, + IoctlManagementCommand, + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +/////////////////////////////////////////////////////////////////////////// +// +//structures and definitions used for queueing data +// +typedef struct +{ + void* previous; + TX_RX_DATA_STRUCT tx_rx_data; +}api_queue_element_t; + +#define API_Q_MUTEX_TIMEOUT 1000//1 second +#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue + +enum API_Q_STATUS{ + API_Q_SUCCESS=0, + API_Q_GEN_FAILURE, + API_Q_MEM_ALLOC_FAILURE, + API_Q_FULL, + API_Q_EMPTY +}; + +typedef struct +{ + //number of nodes in the list + USHORT size; + //insert at tail + api_queue_element_t * tail; + //remove from head + api_queue_element_t * head; + //mutex for synchronizing access to the queue + HANDLE api_queue_mutex; +}api_queue_t; + + +static __inline int api_enqueue( api_queue_t* api_queue, + unsigned char * buffer, + unsigned short length) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == API_Q_MAX_SIZE){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_FULL; + } + + element = malloc(sizeof(api_queue_element_t)); + if(element == NULL){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_MEM_ALLOC_FAILURE; + } + + //now copy everything in to the element + memcpy(element->tx_rx_data.data, buffer, length); + + element->tx_rx_data.api_header.data_length = length; + element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; + + //insert element at the tail of the queue + element->previous = NULL; + + if(api_queue->size == 0){ + //special case of a previously empty queue + api_queue->head = element; + api_queue->tail = element; + }else{ + api_queue->tail->previous = element; + api_queue->tail = element; + } + api_queue->size++; + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +static __inline int api_dequeue( api_queue_t* api_queue, + TX_RX_DATA_STRUCT* destination) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == 0){ + //tx queue is empty + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_EMPTY; + } + + //remove from the head of the queue + element = api_queue->head; + api_queue->head = element->previous; + + //now copy everything in to the user buffer + memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); + + free(element); + api_queue->size--; + if(api_queue->size == 0){ + api_queue->head = NULL; + api_queue->tail = NULL; + } + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +//remove all elements from the queue +static __inline void empty_api_queue(api_queue_t* api_queue) +{ + TX_DATA_STRUCT tx_rx_data; + + while(api_dequeue(api_queue, &tx_rx_data) == 0){ + ; + } +} + +/////////////////////////////////////////////////////////////////////////// +#endif /* _WIN_API_COMMON_H */ diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 53ce0cc9d0..55c037d25a 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -33,12 +33,6 @@ #define WANPIPE_TDM_API 1 -#ifndef __WINDOWS__ -#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) -#define __WINDOWS__ -#endif -#endif - #include "openzap.h" #include "zap_wanpipe.h" @@ -49,28 +43,30 @@ #pragma warning(disable:4200 4201 4214) #endif #include -#include -#include -#include -typedef unsigned __int16 u_int16_t; -typedef unsigned __int32 u_int32_t; +#define FNAME_LEN 50 +#define WP_INVALID_SOCKET INVALID_HANDLE_VALUE +#else +#define WP_INVALID_SOCKET -1 #endif #include #include #include +#include #ifdef __WINDOWS__ #include #include #endif -#include -#include -#include -#include -#include -#include #include + +#ifdef HAVE_SYS_SOCKET_H #include +#endif + +#if defined(__WINDOWS__) +#include +#endif + static zap_software_interface_t wanpipe_interface; @@ -96,6 +92,10 @@ static zap_socket_t wp_open_device(int span, int chan) fd = open(fname, O_RDWR); + if (fd < 0) { + fd = WP_INVALID_SOCKET; + } + return fd; #endif } @@ -106,11 +106,11 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, for(x = start; x < end; x++) { zap_channel_t *chan; - zap_socket_t sockfd = -1; + zap_socket_t sockfd = WP_INVALID_SOCKET; sockfd = wp_open_device(spanno, x); - if (sockfd > -1 && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; } else { @@ -129,7 +129,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa int channo; int spanno; int top = 0; - int x; unsigned configured = 0; assert(str != NULL); @@ -380,6 +379,8 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) } +#ifndef __WINDOWS__ + static ZINT_READ_FUNCTION(wanpipe_read_unix) { int rx_len = 0; @@ -416,17 +417,6 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) return ZAP_SUCCESS; } -static ZINT_READ_FUNCTION(wanpipe_read) -{ - ZINT_READ_MUZZLE; - -#ifndef WIN32 - return wanpipe_read_unix(zchan, data, datalen); -#endif - - return ZAP_FAIL; -} - static ZINT_WRITE_FUNCTION(wanpipe_write_unix) { int bsent; @@ -455,6 +445,19 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) } +#endif + +static ZINT_READ_FUNCTION(wanpipe_read) +{ + ZINT_READ_MUZZLE; + +#ifndef WIN32 + return wanpipe_read_unix(zchan, data, datalen); +#endif + + return ZAP_FAIL; +} + static ZINT_WRITE_FUNCTION(wanpipe_write) { ZINT_WRITE_MUZZLE; From eb0262ddc084d8abaa1379cf0c62d63a33b77897 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 18 May 2007 05:33:19 +0000 Subject: [PATCH 0054/1766] step towards building on windows again. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@27 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 40 +- libs/freetdm/src/include/openzap.h | 20 +- .../freetdm/src/include/zap_wanpipe_windows.h | 363 ++++++++++++++++++ libs/freetdm/src/zap_wanpipe.c | 65 ++-- 4 files changed, 454 insertions(+), 34 deletions(-) create mode 100644 libs/freetdm/src/include/zap_wanpipe_windows.h diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index 2cae0acfce..bdcaead122 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="4" - CharacterSet="1" + CharacterSet="2" > + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 5626df6adc..4ee1e3a6fe 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -36,6 +36,19 @@ #define _XOPEN_SOURCE 500 +#ifndef HAVE_STRINGS_H +#define HAVE_STRINGS_H 1 +#endif +#ifndef HAVE_SYS_SOCKET_H +#define HAVE_SYS_SOCKET_H 1 +#endif + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#define __WINDOWS__ +#endif +#endif + #ifdef _MSC_VER #if (_MSC_VER >= 1400) /* VC8+ */ #ifndef _CRT_SECURE_NO_DEPRECATE @@ -51,12 +64,17 @@ #ifndef snprintf #define snprintf _snprintf #endif +#undef HAVE_STRINGS_H +#undef HAVE_SYS_SOCKET_H +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4706) #endif #include #include #include -#ifndef _MSC_VER +#ifdef HAVE_STRINGS_H #include #endif #include diff --git a/libs/freetdm/src/include/zap_wanpipe_windows.h b/libs/freetdm/src/include/zap_wanpipe_windows.h new file mode 100644 index 0000000000..d5773da640 --- /dev/null +++ b/libs/freetdm/src/include/zap_wanpipe_windows.h @@ -0,0 +1,363 @@ +/***************************************************************************** + * win_api_common.h Windows Sangoma API Code Library + * + * Author(s): David Rokhvarg + * + * Copyright: (c) 1984-2006 Sangoma Technologies Inc. + * + * ============================================================================ + */ + +#ifndef _WIN_API_COMMON_H +#define _WIN_API_COMMON_H + +#define DEV_NAME_LEN 100 +char device_name[DEV_NAME_LEN]; + +/* IOCTL management structures and variables*/ +wan_udp_hdr_t wan_udp; + +static wan_cmd_api_t api_cmd; +static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; + +/* keeps the LAST (and single) event received */ +static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; + +static +int +tdmv_api_ioctl( + HANDLE fd, + wanpipe_tdm_api_cmd_t *tdm_api_cmd + ) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; + wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)tdm_api_cmd, + sizeof(wanpipe_tdm_api_cmd_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //actual ioctl failed + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + //ioctl ok, but command failed + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)tdm_api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wanpipe_tdm_api_cmd_t)); + return 0; +} + +static +int +wanpipe_api_ioctl( + HANDLE fd, + wan_cmd_api_t *api_cmd + ) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; + wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)api_cmd, + sizeof(wan_cmd_api_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wan_cmd_api_t)); + return 0; +} + +// Blocking read command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +USHORT +DoReadCommand( + HANDLE drv, + RX_DATA_STRUCT * pRx + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlReadCommand, + (LPVOID)NULL, + 0L, + (LPVOID)pRx, + sizeof(RX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //check messages log + return 1; + }else{ + return 0; + } +} + +// Blocking write command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +UCHAR +DoWriteCommand( + HANDLE drv, + TX_DATA_STRUCT * pTx + ) +{ + DWORD ln; + + if(DeviceIoControl( + drv, + IoctlWriteCommand, + (LPVOID)pTx, + (ULONG)sizeof(TX_DATA_STRUCT), + (LPVOID)pTx, + sizeof(TX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +// Blocking API Poll command. +static +USHORT +DoApiPollCommand( + HANDLE drv, + API_POLL_STRUCT *api_poll_ptr + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlApiPoll, + (LPVOID)NULL, + 0L, + (LPVOID)api_poll_ptr, + sizeof(API_POLL_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +static +int +DoManagementCommand( + HANDLE drv, + wan_udp_hdr_t* wan_udp + ) +{ + DWORD ln; + static unsigned char id = 0; + + wan_udp->wan_udphdr_request_reply = 0x01; + wan_udp->wan_udphdr_id = id++; + wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + if(DeviceIoControl( + drv, + IoctlManagementCommand, + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +/////////////////////////////////////////////////////////////////////////// +// +//structures and definitions used for queueing data +// +typedef struct +{ + void* previous; + TX_RX_DATA_STRUCT tx_rx_data; +}api_queue_element_t; + +#define API_Q_MUTEX_TIMEOUT 1000//1 second +#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue + +enum API_Q_STATUS{ + API_Q_SUCCESS=0, + API_Q_GEN_FAILURE, + API_Q_MEM_ALLOC_FAILURE, + API_Q_FULL, + API_Q_EMPTY +}; + +typedef struct +{ + //number of nodes in the list + USHORT size; + //insert at tail + api_queue_element_t * tail; + //remove from head + api_queue_element_t * head; + //mutex for synchronizing access to the queue + HANDLE api_queue_mutex; +}api_queue_t; + + +static __inline int api_enqueue( api_queue_t* api_queue, + unsigned char * buffer, + unsigned short length) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == API_Q_MAX_SIZE){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_FULL; + } + + element = malloc(sizeof(api_queue_element_t)); + if(element == NULL){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_MEM_ALLOC_FAILURE; + } + + //now copy everything in to the element + memcpy(element->tx_rx_data.data, buffer, length); + + element->tx_rx_data.api_header.data_length = length; + element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; + + //insert element at the tail of the queue + element->previous = NULL; + + if(api_queue->size == 0){ + //special case of a previously empty queue + api_queue->head = element; + api_queue->tail = element; + }else{ + api_queue->tail->previous = element; + api_queue->tail = element; + } + api_queue->size++; + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +static __inline int api_dequeue( api_queue_t* api_queue, + TX_RX_DATA_STRUCT* destination) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == 0){ + //tx queue is empty + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_EMPTY; + } + + //remove from the head of the queue + element = api_queue->head; + api_queue->head = element->previous; + + //now copy everything in to the user buffer + memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); + + free(element); + api_queue->size--; + if(api_queue->size == 0){ + api_queue->head = NULL; + api_queue->tail = NULL; + } + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +//remove all elements from the queue +static __inline void empty_api_queue(api_queue_t* api_queue) +{ + TX_DATA_STRUCT tx_rx_data; + + while(api_dequeue(api_queue, &tx_rx_data) == 0){ + ; + } +} + +/////////////////////////////////////////////////////////////////////////// +#endif /* _WIN_API_COMMON_H */ diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 53ce0cc9d0..55c037d25a 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -33,12 +33,6 @@ #define WANPIPE_TDM_API 1 -#ifndef __WINDOWS__ -#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) -#define __WINDOWS__ -#endif -#endif - #include "openzap.h" #include "zap_wanpipe.h" @@ -49,28 +43,30 @@ #pragma warning(disable:4200 4201 4214) #endif #include -#include -#include -#include -typedef unsigned __int16 u_int16_t; -typedef unsigned __int32 u_int32_t; +#define FNAME_LEN 50 +#define WP_INVALID_SOCKET INVALID_HANDLE_VALUE +#else +#define WP_INVALID_SOCKET -1 #endif #include #include #include +#include #ifdef __WINDOWS__ #include #include #endif -#include -#include -#include -#include -#include -#include #include + +#ifdef HAVE_SYS_SOCKET_H #include +#endif + +#if defined(__WINDOWS__) +#include +#endif + static zap_software_interface_t wanpipe_interface; @@ -96,6 +92,10 @@ static zap_socket_t wp_open_device(int span, int chan) fd = open(fname, O_RDWR); + if (fd < 0) { + fd = WP_INVALID_SOCKET; + } + return fd; #endif } @@ -106,11 +106,11 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, for(x = start; x < end; x++) { zap_channel_t *chan; - zap_socket_t sockfd = -1; + zap_socket_t sockfd = WP_INVALID_SOCKET; sockfd = wp_open_device(spanno, x); - if (sockfd > -1 && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; } else { @@ -129,7 +129,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa int channo; int spanno; int top = 0; - int x; unsigned configured = 0; assert(str != NULL); @@ -380,6 +379,8 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) } +#ifndef __WINDOWS__ + static ZINT_READ_FUNCTION(wanpipe_read_unix) { int rx_len = 0; @@ -416,17 +417,6 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) return ZAP_SUCCESS; } -static ZINT_READ_FUNCTION(wanpipe_read) -{ - ZINT_READ_MUZZLE; - -#ifndef WIN32 - return wanpipe_read_unix(zchan, data, datalen); -#endif - - return ZAP_FAIL; -} - static ZINT_WRITE_FUNCTION(wanpipe_write_unix) { int bsent; @@ -455,6 +445,19 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) } +#endif + +static ZINT_READ_FUNCTION(wanpipe_read) +{ + ZINT_READ_MUZZLE; + +#ifndef WIN32 + return wanpipe_read_unix(zchan, data, datalen); +#endif + + return ZAP_FAIL; +} + static ZINT_WRITE_FUNCTION(wanpipe_write) { ZINT_WRITE_MUZZLE; From 09e864a8ba09dac4dcf74fb2224234c01f920851 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 14:08:30 +0000 Subject: [PATCH 0055/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@28 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/testapp.c | 17 ++++++++++------- libs/openzap/src/zap_wanpipe.c | 30 ++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4ee1e3a6fe..077e4a098f 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -200,6 +200,7 @@ struct zap_channel { zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; + char last_error[256]; void *mod_data; struct zap_software_interface *zint; }; diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index bb6b8d91cf..0950c2acee 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -18,27 +18,30 @@ int main(int argc, char *argv[]) int x = 0; if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { - zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms); + ms = 0; + zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &ms); printf("interval set to %u\n", ms); } else { - printf("set interval failed\n"); + printf("set interval failed [%s]\n", chan->last_error); } for(x = 0; x < 25; x++) { - unsigned char buf[80]; + unsigned char buf[2048]; zap_size_t len = sizeof(buf); zap_wait_flag_t flags = ZAP_READ; - - zap_channel_wait(chan, &flags, 0); + + if (zap_channel_wait(chan, &flags, 0) == ZAP_FAIL) { + printf("wait FAIL! %d [%s]\n", len, chan->last_error); + } if (flags & ZAP_READ) { if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { printf("READ: %d\n", len); } else { - printf("READ FAIL! %d\n", len); + printf("READ FAIL! %d [%s]\n", len, chan->last_error); break; } } else { - printf("wait fail\n"); + printf("wait fail [%s]\n", chan->last_error); } } } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 55c037d25a..7b5fabfd3d 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -188,16 +188,22 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static zap_status_t wp_tdm_cmd_exec(zap_socket_t fd, wanpipe_tdm_api_t *tdm_api) +static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) { int err; #if defined(WIN32) - err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd); + err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); #else - err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd); + err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); #endif - return err ? ZAP_FAIL : ZAP_SUCCESS; + + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + return ZAP_SUCCESS; } static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) @@ -300,7 +306,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - if (!(err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api))) { + if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; } @@ -310,12 +316,18 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); - err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api); + err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; }; - return err ? ZAP_FAIL : ZAP_SUCCESS; + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + + return ZAP_SUCCESS; } static ZINT_WAIT_FUNCTION(wanpipe_wait) @@ -356,6 +368,7 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) s = select(zchan->sockfd + 1, r, w, e, tvp); if (s < 0) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -410,7 +423,7 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) *datalen = rx_len; if (rx_len <= 0) { - perror("wtf"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -443,6 +456,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) bsent -= sizeof(wp_tdm_api_tx_hdr_t); } + *datalen = bsent; } #endif From 084d5f4a5b51a98011deaaf7659245f9eaef646f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 14:08:30 +0000 Subject: [PATCH 0056/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@28 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/testapp.c | 17 ++++++++++------- libs/freetdm/src/zap_wanpipe.c | 30 ++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4ee1e3a6fe..077e4a098f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -200,6 +200,7 @@ struct zap_channel { zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; + char last_error[256]; void *mod_data; struct zap_software_interface *zint; }; diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index bb6b8d91cf..0950c2acee 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -18,27 +18,30 @@ int main(int argc, char *argv[]) int x = 0; if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { - zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms); + ms = 0; + zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &ms); printf("interval set to %u\n", ms); } else { - printf("set interval failed\n"); + printf("set interval failed [%s]\n", chan->last_error); } for(x = 0; x < 25; x++) { - unsigned char buf[80]; + unsigned char buf[2048]; zap_size_t len = sizeof(buf); zap_wait_flag_t flags = ZAP_READ; - - zap_channel_wait(chan, &flags, 0); + + if (zap_channel_wait(chan, &flags, 0) == ZAP_FAIL) { + printf("wait FAIL! %d [%s]\n", len, chan->last_error); + } if (flags & ZAP_READ) { if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { printf("READ: %d\n", len); } else { - printf("READ FAIL! %d\n", len); + printf("READ FAIL! %d [%s]\n", len, chan->last_error); break; } } else { - printf("wait fail\n"); + printf("wait fail [%s]\n", chan->last_error); } } } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 55c037d25a..7b5fabfd3d 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -188,16 +188,22 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static zap_status_t wp_tdm_cmd_exec(zap_socket_t fd, wanpipe_tdm_api_t *tdm_api) +static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) { int err; #if defined(WIN32) - err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd); + err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); #else - err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd); + err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); #endif - return err ? ZAP_FAIL : ZAP_SUCCESS; + + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + return ZAP_SUCCESS; } static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) @@ -300,7 +306,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - if (!(err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api))) { + if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; } @@ -310,12 +316,18 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); - err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api); + err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; }; - return err ? ZAP_FAIL : ZAP_SUCCESS; + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + + return ZAP_SUCCESS; } static ZINT_WAIT_FUNCTION(wanpipe_wait) @@ -356,6 +368,7 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) s = select(zchan->sockfd + 1, r, w, e, tvp); if (s < 0) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -410,7 +423,7 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) *datalen = rx_len; if (rx_len <= 0) { - perror("wtf"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -443,6 +456,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) bsent -= sizeof(wp_tdm_api_tx_hdr_t); } + *datalen = bsent; } #endif From d11cf99269d64f87a9889cee74886c9dcf18e914 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 18 May 2007 15:17:27 +0000 Subject: [PATCH 0057/1766] type tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@29 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 7b5fabfd3d..fef68ab584 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -503,7 +503,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) zap_status_t wanpipe_destroy(void) { - int i,j; + unsigned int i,j; for(i = 1; i <= wanpipe_interface.span_index; i++) { zap_span_t *cur_span = &wanpipe_interface.spans[i]; From 85d0641395424b215e4c0c134456eec3e9fd9ef9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 18 May 2007 15:17:27 +0000 Subject: [PATCH 0058/1766] type tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@29 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 7b5fabfd3d..fef68ab584 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -503,7 +503,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) zap_status_t wanpipe_destroy(void) { - int i,j; + unsigned int i,j; for(i = 1; i <= wanpipe_interface.span_index; i++) { zap_span_t *cur_span = &wanpipe_interface.spans[i]; From 6afad1d2d0691611d91be3df32986d899a47609b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 17:50:37 +0000 Subject: [PATCH 0059/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@30 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 11 +++++++ libs/openzap/src/include/openzap.h | 11 ++++++- libs/openzap/src/openzap.c | 42 +++++++++++++++++++++++- libs/openzap/src/testapp.c | 9 ++++++ libs/openzap/src/zap_wanpipe.c | 51 ++++++++++++++++++++++++++++-- 5 files changed, 120 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index fa8c8d601c..9c6788826c 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -33,6 +33,7 @@ OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o libteletone_detect.o libteletone_generate.o zap_buffer.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a +TMP=-I../../libpri-1.2.4 -Iinclude -I. -w include general.makefile $(ZAP_MODS) @@ -45,6 +46,16 @@ $(MYLIB): $(OBJS) testapp: testapp.c $(MYLIB) $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm + +priserver.o: priserver.c + $(CC) $(TMP) -c priserver.c -o priserver.o + +sangoma_pri.o: sangoma_pri.c + $(CC) $(TMP) -c sangoma_pri.c -o sangoma_pri.o + +priserver: $(MYLIB) priserver.o sangoma_pri.o + $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm ../../libpri-1.2.4/libpri.a + openzap.o: openzap.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 077e4a098f..08201a2a41 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -149,6 +149,11 @@ struct zap_software_interface; #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} +typedef enum { + ZAP_TOP_DOWN, + ZAP_BOTTOM_UP +} zap_direction_t; + typedef enum { ZAP_SUCCESS, ZAP_FAIL, @@ -164,6 +169,7 @@ typedef enum { } zap_wait_flag_t; typedef enum { + ZAP_CODEC_NONE = (1 << 31), ZAP_CODEC_ULAW = 0, ZAP_CODEC_ALAW = 8, ZAP_CODEC_SLIN = 10 @@ -172,7 +178,9 @@ typedef enum { typedef enum { ZAP_COMMAND_NOOP, ZAP_COMMAND_SET_INTERVAL, - ZAP_COMMAND_GET_INTERVAL + ZAP_COMMAND_GET_INTERVAL, + ZAP_COMMAND_SET_CODEC, + ZAP_COMMAND_GET_CODEC } zap_command_t; typedef enum { @@ -289,6 +297,7 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to); diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index dbb831b3e1..c7fe7b5199 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -186,6 +186,46 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha } +zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan) +{ + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_status_t status = ZAP_FAIL; + + if (span_id < ZAP_MAX_SPANS_INTERFACE && zint) { + zap_channel_t *check; + zap_span_t *span = &zint->spans[span_id]; + unsigned i; + + if (direction == ZAP_TOP_DOWN) { + for(i = 1; i <= span->chan_count; i++) { + check = &span->channels[i]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zint->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return status; + } + } + } + } else if (direction == ZAP_BOTTOM_UP) { + for(i = span->chan_count; i > 0; i--) { + check = &span->channels[i]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zint->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return status; + } + } + } + } + } + + return status; +} + zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); @@ -212,10 +252,10 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) zap_channel_t *check; zap_status_t status = ZAP_FAIL; - *zchan = NULL; assert(zchan != NULL); check = *zchan; assert(check != NULL); + *zchan = NULL; if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zint->close(check); diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 0950c2acee..dbd7d989ee 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -5,6 +5,7 @@ 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; if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); @@ -25,6 +26,14 @@ int main(int argc, char *argv[]) printf("set interval failed [%s]\n", chan->last_error); } + 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); diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index fef68ab584..d73a293e96 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -319,6 +319,51 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; + + case ZAP_COMMAND_SET_CODEC: + { + zap_codec_t codec = *((int *)obj); + unsigned wp_codec = 0; + + switch(codec) { + case ZAP_CODEC_SLIN: + wp_codec = WP_SLINEAR; + break; + default: + break; + }; + + if (wp_codec) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; + tdm_api.wp_tdm_cmd.tdm_codec = wp_codec; + err = wp_tdm_cmd_exec(zchan, &tdm_api); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Invalid Codec"); + return ZAP_FAIL; + } + } + break; + case ZAP_COMMAND_GET_CODEC: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC; + + if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + unsigned wp_codec = tdm_api.wp_tdm_cmd.tdm_codec; + zap_codec_t codec = ZAP_CODEC_NONE; + switch(wp_codec) { + case WP_SLINEAR: + codec = ZAP_CODEC_SLIN; + break; + default: + break; + }; + + *((int *)obj) = codec; + } + } + break; + default: + break; }; if (err) { @@ -449,14 +494,16 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) msg.msg_iovlen = 2; msg.msg_iov = iov; - - bsent = write(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + + bsent = write(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); if (bsent > 0){ bsent -= sizeof(wp_tdm_api_tx_hdr_t); } *datalen = bsent; + + return ZAP_SUCCESS; } #endif From 155febcccf707b8e9a30a2e8947769af74e1f882 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 17:50:37 +0000 Subject: [PATCH 0060/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@30 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 11 +++++++ libs/freetdm/src/include/openzap.h | 11 ++++++- libs/freetdm/src/openzap.c | 42 +++++++++++++++++++++++- libs/freetdm/src/testapp.c | 9 ++++++ libs/freetdm/src/zap_wanpipe.c | 51 ++++++++++++++++++++++++++++-- 5 files changed, 120 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index fa8c8d601c..9c6788826c 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -33,6 +33,7 @@ OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o libteletone_detect.o libteletone_generate.o zap_buffer.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a +TMP=-I../../libpri-1.2.4 -Iinclude -I. -w include general.makefile $(ZAP_MODS) @@ -45,6 +46,16 @@ $(MYLIB): $(OBJS) testapp: testapp.c $(MYLIB) $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm + +priserver.o: priserver.c + $(CC) $(TMP) -c priserver.c -o priserver.o + +sangoma_pri.o: sangoma_pri.c + $(CC) $(TMP) -c sangoma_pri.c -o sangoma_pri.o + +priserver: $(MYLIB) priserver.o sangoma_pri.o + $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm ../../libpri-1.2.4/libpri.a + openzap.o: openzap.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 077e4a098f..08201a2a41 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -149,6 +149,11 @@ struct zap_software_interface; #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} +typedef enum { + ZAP_TOP_DOWN, + ZAP_BOTTOM_UP +} zap_direction_t; + typedef enum { ZAP_SUCCESS, ZAP_FAIL, @@ -164,6 +169,7 @@ typedef enum { } zap_wait_flag_t; typedef enum { + ZAP_CODEC_NONE = (1 << 31), ZAP_CODEC_ULAW = 0, ZAP_CODEC_ALAW = 8, ZAP_CODEC_SLIN = 10 @@ -172,7 +178,9 @@ typedef enum { typedef enum { ZAP_COMMAND_NOOP, ZAP_COMMAND_SET_INTERVAL, - ZAP_COMMAND_GET_INTERVAL + ZAP_COMMAND_GET_INTERVAL, + ZAP_COMMAND_SET_CODEC, + ZAP_COMMAND_GET_CODEC } zap_command_t; typedef enum { @@ -289,6 +297,7 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to); diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index dbb831b3e1..c7fe7b5199 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -186,6 +186,46 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha } +zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan) +{ + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_status_t status = ZAP_FAIL; + + if (span_id < ZAP_MAX_SPANS_INTERFACE && zint) { + zap_channel_t *check; + zap_span_t *span = &zint->spans[span_id]; + unsigned i; + + if (direction == ZAP_TOP_DOWN) { + for(i = 1; i <= span->chan_count; i++) { + check = &span->channels[i]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zint->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return status; + } + } + } + } else if (direction == ZAP_BOTTOM_UP) { + for(i = span->chan_count; i > 0; i--) { + check = &span->channels[i]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zint->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return status; + } + } + } + } + } + + return status; +} + zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); @@ -212,10 +252,10 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) zap_channel_t *check; zap_status_t status = ZAP_FAIL; - *zchan = NULL; assert(zchan != NULL); check = *zchan; assert(check != NULL); + *zchan = NULL; if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zint->close(check); diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 0950c2acee..dbd7d989ee 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -5,6 +5,7 @@ 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; if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); @@ -25,6 +26,14 @@ int main(int argc, char *argv[]) printf("set interval failed [%s]\n", chan->last_error); } + 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); diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index fef68ab584..d73a293e96 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -319,6 +319,51 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; + + case ZAP_COMMAND_SET_CODEC: + { + zap_codec_t codec = *((int *)obj); + unsigned wp_codec = 0; + + switch(codec) { + case ZAP_CODEC_SLIN: + wp_codec = WP_SLINEAR; + break; + default: + break; + }; + + if (wp_codec) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; + tdm_api.wp_tdm_cmd.tdm_codec = wp_codec; + err = wp_tdm_cmd_exec(zchan, &tdm_api); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Invalid Codec"); + return ZAP_FAIL; + } + } + break; + case ZAP_COMMAND_GET_CODEC: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC; + + if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + unsigned wp_codec = tdm_api.wp_tdm_cmd.tdm_codec; + zap_codec_t codec = ZAP_CODEC_NONE; + switch(wp_codec) { + case WP_SLINEAR: + codec = ZAP_CODEC_SLIN; + break; + default: + break; + }; + + *((int *)obj) = codec; + } + } + break; + default: + break; }; if (err) { @@ -449,14 +494,16 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) msg.msg_iovlen = 2; msg.msg_iov = iov; - - bsent = write(zchan->sockfd, &msg, iov[1].iov_len + sizeof(hdrframe)); + + bsent = write(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); if (bsent > 0){ bsent -= sizeof(wp_tdm_api_tx_hdr_t); } *datalen = bsent; + + return ZAP_SUCCESS; } #endif From 604913efef1e2797bbc2b608ee656ff93b68774d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:17:33 +0000 Subject: [PATCH 0061/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@31 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 102 ++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 24 deletions(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index c7fe7b5199..1a8509080a 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -190,36 +190,90 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_status_t status = ZAP_FAIL; - - if (span_id < ZAP_MAX_SPANS_INTERFACE && zint) { - zap_channel_t *check; - zap_span_t *span = &zint->spans[span_id]; - unsigned i; + zap_channel_t *check; + unsigned i,j; + zap_span_t *span; + unsigned span_max; + + if (!zint) { + zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); + return ZAP_FAIL; + } + + if (span_id) { + span_max = span_id; + } else { + span_max = zint->span_index; + } + + if (direction == ZAP_BOTTOM_UP) { + j = 1; + } else { + j = span_max; + } + + for(;;) { + span = &zint->spans[j]; + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + goto next_loop; + } + if (direction == ZAP_TOP_DOWN) { - for(i = 1; i <= span->chan_count; i++) { - check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; - return status; - } + if (j == span_max) { + break; + } + } else { + if (j == 0) { + break; + } + } + + if (direction == ZAP_TOP_DOWN) { + i = 1; + } else { + i = span->chan_count; + } + + for(;;) { + + if (direction == ZAP_TOP_DOWN) { + if (i == span->chan_count) { + break; + } + } else { + if (i == 0) { + break; } } - } else if (direction == ZAP_BOTTOM_UP) { - for(i = span->chan_count; i > 0; i--) { - check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; - return status; - } + + check = &span->channels[i]; + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + + status = check->zint->open(check); + + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return status; } } + + if (direction == ZAP_TOP_DOWN) { + i++; + } else { + i--; + } + + } + + next_loop: + + if (direction == ZAP_TOP_DOWN) { + j++; + } else { + j--; } } From 0c40796e0f41a000bbfcaacf2238de16001adadf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:17:33 +0000 Subject: [PATCH 0062/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@31 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 102 ++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index c7fe7b5199..1a8509080a 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -190,36 +190,90 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_status_t status = ZAP_FAIL; - - if (span_id < ZAP_MAX_SPANS_INTERFACE && zint) { - zap_channel_t *check; - zap_span_t *span = &zint->spans[span_id]; - unsigned i; + zap_channel_t *check; + unsigned i,j; + zap_span_t *span; + unsigned span_max; + + if (!zint) { + zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); + return ZAP_FAIL; + } + + if (span_id) { + span_max = span_id; + } else { + span_max = zint->span_index; + } + + if (direction == ZAP_BOTTOM_UP) { + j = 1; + } else { + j = span_max; + } + + for(;;) { + span = &zint->spans[j]; + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + goto next_loop; + } + if (direction == ZAP_TOP_DOWN) { - for(i = 1; i <= span->chan_count; i++) { - check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; - return status; - } + if (j == span_max) { + break; + } + } else { + if (j == 0) { + break; + } + } + + if (direction == ZAP_TOP_DOWN) { + i = 1; + } else { + i = span->chan_count; + } + + for(;;) { + + if (direction == ZAP_TOP_DOWN) { + if (i == span->chan_count) { + break; + } + } else { + if (i == 0) { + break; } } - } else if (direction == ZAP_BOTTOM_UP) { - for(i = span->chan_count; i > 0; i--) { - check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; - return status; - } + + check = &span->channels[i]; + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + + status = check->zint->open(check); + + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + *zchan = check; + return status; } } + + if (direction == ZAP_TOP_DOWN) { + i++; + } else { + i--; + } + + } + + next_loop: + + if (direction == ZAP_TOP_DOWN) { + j++; + } else { + j--; } } From f595e44975e9dbfd512b2ee4a778f1f239808291 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:20:10 +0000 Subject: [PATCH 0063/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@32 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 1a8509080a..58f881f356 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -206,7 +206,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct span_max = zint->span_index; } - if (direction == ZAP_BOTTOM_UP) { + if (direction == TOP_DOWN) { j = 1; } else { j = span_max; From b647d8783cfce314c5b00046325444abd338ae38 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:20:10 +0000 Subject: [PATCH 0064/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@32 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 1a8509080a..58f881f356 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -206,7 +206,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct span_max = zint->span_index; } - if (direction == ZAP_BOTTOM_UP) { + if (direction == TOP_DOWN) { j = 1; } else { j = span_max; From bb5824c1604a329a33e3e920655d1f2d8d5354b3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:20:27 +0000 Subject: [PATCH 0065/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@33 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 58f881f356..c82f6f7608 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -206,7 +206,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct span_max = zint->span_index; } - if (direction == TOP_DOWN) { + if (direction == ZAP_TOP_DOWN) { j = 1; } else { j = span_max; From 2c0331cfb980028455df5ad7a7efa3e868d97efd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:20:27 +0000 Subject: [PATCH 0066/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@33 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 58f881f356..c82f6f7608 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -206,7 +206,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct span_max = zint->span_index; } - if (direction == TOP_DOWN) { + if (direction == ZAP_TOP_DOWN) { j = 1; } else { j = span_max; From 8364a82fe94c2bf2cbc8e93284f9b0ad013279ba Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:28:32 +0000 Subject: [PATCH 0067/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@34 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.c | 12 +++++++----- libs/openzap/src/testapp.c | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index c82f6f7608..a33bcdbc98 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -212,15 +212,17 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct j = span_max; } + + for(;;) { span = &zint->spans[j]; - + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } if (direction == ZAP_TOP_DOWN) { - if (j == span_max) { + if (j > span_max) { break; } } else { @@ -228,7 +230,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct break; } } - + if (direction == ZAP_TOP_DOWN) { i = 1; } else { @@ -238,7 +240,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct for(;;) { if (direction == ZAP_TOP_DOWN) { - if (i == span->chan_count) { + if (i > span->chan_count) { break; } } else { @@ -246,7 +248,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct break; } } - + check = &span->channels[i]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index dbd7d989ee..ab429f0f79 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -15,8 +15,9 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { int x = 0; + printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { ms = 0; @@ -53,6 +54,8 @@ int main(int argc, char *argv[]) printf("wait fail [%s]\n", chan->last_error); } } + } else { + printf("open fail [%s]\n", chan->last_error); } zap_global_destroy(); From 32c4d00007f2609ba05c1ad6f2c0cb6c7922c9f3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 18 May 2007 18:28:32 +0000 Subject: [PATCH 0068/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@34 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.c | 12 +++++++----- libs/freetdm/src/testapp.c | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index c82f6f7608..a33bcdbc98 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -212,15 +212,17 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct j = span_max; } + + for(;;) { span = &zint->spans[j]; - + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } if (direction == ZAP_TOP_DOWN) { - if (j == span_max) { + if (j > span_max) { break; } } else { @@ -228,7 +230,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct break; } } - + if (direction == ZAP_TOP_DOWN) { i = 1; } else { @@ -238,7 +240,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct for(;;) { if (direction == ZAP_TOP_DOWN) { - if (i == span->chan_count) { + if (i > span->chan_count) { break; } } else { @@ -246,7 +248,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct break; } } - + check = &span->channels[i]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index dbd7d989ee..ab429f0f79 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -15,8 +15,9 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { int x = 0; + printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { ms = 0; @@ -53,6 +54,8 @@ int main(int argc, char *argv[]) printf("wait fail [%s]\n", chan->last_error); } } + } else { + printf("open fail [%s]\n", chan->last_error); } zap_global_destroy(); From f2be1a9a22a3d3e775be8471a30dfe280848797e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 May 2007 00:50:50 +0000 Subject: [PATCH 0069/1766] add a bunch of goodies git-svn-id: http://svn.openzap.org/svn/openzap/trunk@35 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 4 +- libs/openzap/src/include/openzap.h | 98 ++++++--- libs/openzap/src/openzap.c | 331 ++++++++++++++++++++++++++++- libs/openzap/src/testapp.c | 12 +- libs/openzap/src/wanpipe | 2 +- libs/openzap/src/zap_wanpipe.c | 133 ++++++------ 6 files changed, 482 insertions(+), 98 deletions(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 9c6788826c..301d5836a9 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -30,7 +30,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o libteletone_detect.o libteletone_generate.o zap_buffer.o +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w @@ -69,5 +69,5 @@ zap_zt.o: zap_zt.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o $(MYLIB) *~ \#* + rm -f *.o $(MYLIB) *~ \#* testapp priserver diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 08201a2a41..67db68761a 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -101,6 +101,8 @@ typedef int zap_socket_t; typedef size_t zap_size_t; struct zap_software_interface; +#define ZAP_COMMAND_OBJ_INT *((int *)obj) + #define zap_true(expr)\ (expr && ( !strcasecmp(expr, "yes") ||\ !strcasecmp(expr, "on") ||\ @@ -111,6 +113,11 @@ struct zap_software_interface; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) + +#define zap_channel_test_feature(obj, flag) ((obj)->features & flag) +#define zap_channel_set_feature(obj, flag) (obj)->features |= (flag) +#define zap_channel_clear_feature(obj, flag) (obj)->features &= ~(flag) + /*! \brief Test for the existance of a flag on an arbitary object \command obj the object to test @@ -169,18 +176,24 @@ typedef enum { } zap_wait_flag_t; typedef enum { - ZAP_CODEC_NONE = (1 << 31), ZAP_CODEC_ULAW = 0, ZAP_CODEC_ALAW = 8, - ZAP_CODEC_SLIN = 10 + ZAP_CODEC_SLIN = 10, + ZAP_CODEC_NONE = (1 << 31) } 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_GET_CODEC, + ZAP_COMMAND_ENABLE_TONE_DETECT, + ZAP_COMMAND_DISABLE_TONE_DETECT } zap_command_t; typedef enum { @@ -196,33 +209,23 @@ typedef enum { ZAP_CHAN_TYPE_FXO } zap_chan_type_t; +typedef enum { + ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0) +} zap_channel_feature_t; + typedef enum { ZAP_CHANNEL_CONFIGURED = (1 << 0), ZAP_CHANNEL_READY = (1 << 1), - ZAP_CHANNEL_OPEN = (1 << 2) + ZAP_CHANNEL_OPEN = (1 << 2), + ZAP_CHANNEL_DTMF_DETECT = (1 << 3), + ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4) } zap_channel_flag_t; -struct zap_channel { - unsigned span_id; - unsigned chan_id; - zap_chan_type_t type; - zap_socket_t sockfd; - zap_channel_flag_t flags; - char last_error[256]; - void *mod_data; - struct zap_software_interface *zint; -}; typedef struct zap_channel zap_channel_t; +typedef struct zap_event zap_event_t; -struct zap_span { - unsigned span_id; - unsigned chan_count; - zap_span_flag_t flags; - struct zap_software_interface *zint; - zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; -}; -typedef struct zap_span zap_span_t; - +#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) +#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) #define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) #define ZINT_OPEN_ARGS (zap_channel_t *zchan) #define ZINT_CLOSE_ARGS (zap_channel_t *zchan) @@ -231,6 +234,8 @@ typedef struct zap_span zap_span_t; #define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) #define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; +typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; @@ -239,6 +244,8 @@ typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; +#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS +#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS #define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS #define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS #define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS @@ -275,6 +282,47 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT #define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG +typedef enum { + ZAP_EVENT_NONE, + ZAP_EVENT_DTMF +} zap_event_type_t; + +struct zap_event { + zap_event_type_t e_type; + void *data; +}; + +struct zap_channel { + unsigned span_id; + unsigned chan_id; + zap_chan_type_t type; + zap_socket_t sockfd; + zap_channel_flag_t flags; + zap_channel_feature_t features; + zap_codec_t effective_codec; + zap_codec_t native_codec; + teletone_dtmf_detect_state_t dtmf_detect; + zap_event_t event_header; + char last_error[256]; + zint_event_cb_t event_callback; + void *mod_data; + unsigned skip_read_frames; + struct zap_span *span; + struct zap_software_interface *zint; +}; + + +struct zap_span { + unsigned span_id; + unsigned chan_count; + zap_span_flag_t flags; + struct zap_software_interface *zint; + zint_event_cb_t event_callback; + zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; +}; +typedef struct zap_span zap_span_t; + + typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); extern zap_logger_t zap_log; @@ -293,9 +341,11 @@ struct zap_software_interface { typedef struct zap_software_interface zap_software_interface_t; +zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span); zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); - +zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index a33bcdbc98..1e215cf785 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -177,6 +177,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->zint = span->zint; new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; + new_chan->span = span; zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -185,6 +186,42 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } +zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span) +{ + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_span_t *fspan; + + if (!zint) { + return ZAP_FAIL; + } + + if (id > ZAP_MAX_SPANS_INTERFACE) { + return ZAP_FAIL; + } + + fspan = &zint->spans[id]; + + if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { + return ZAP_FAIL; + } + + *span = fspan; + + return ZAP_SUCCESS; + +} + +zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback) +{ + span->event_callback = event_callback; + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback) +{ + zchan->event_callback = event_callback; + return ZAP_SUCCESS; +} zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan) { @@ -317,6 +354,9 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) status = check->zint->close(check); if (status == ZAP_SUCCESS) { zap_clear_flag(check, ZAP_CHANNEL_OPEN); + check->event_callback = NULL; + zap_clear_flag(check, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(check, ZAP_CHANNEL_SUPRESS_DTMF); *zchan = NULL; } } @@ -331,10 +371,50 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } + switch(command) { + case ZAP_COMMAND_ENABLE_TONE_DETECT: + { + /* if they don't have thier own, use ours */ + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; + if (tt == ZAP_TONE_DTMF) { + teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + zap_set_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_set_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); + return ZAP_FAIL; + } + } + } + break; + case ZAP_COMMAND_DISABLE_TONE_DETECT: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; + if (tt == ZAP_TONE_DTMF) { + teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); + return ZAP_FAIL; + } + } + } + break; + default: + break; + } + if (!zchan->zint->command) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } @@ -348,10 +428,12 @@ zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsi assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } if (!zchan->zint->wait) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } @@ -359,41 +441,282 @@ zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsi } +/*******************************/ +ZINT_CODEC_FUNCTION(zint_slin2ulaw) +{ + int16_t sln_buf[512] = {0}, *sln = sln_buf; + uint8_t *lp = data; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(sln, data, max); + + for(i = 0; i < max; i++) { + *lp++ = linear_to_ulaw(*sln++); + } + + *datalen = max / 2; + + return ZAP_SUCCESS; + +} + + +ZINT_CODEC_FUNCTION(zint_ulaw2slin) +{ + int16_t *sln = data; + uint8_t law[1024] = {0}, *lp = law; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(law, data, max); + + for(i = 0; i < max; i++) { + *sln++ = ulaw_to_linear(*lp++); + } + + *datalen = max * 2; + + return ZAP_SUCCESS; +} + +ZINT_CODEC_FUNCTION(zint_slin2alaw) +{ + int16_t sln_buf[512] = {0}, *sln = sln_buf; + uint8_t *lp = data; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(sln, data, max); + + for(i = 0; i < max; i++) { + *lp++ = linear_to_alaw(*sln++); + } + + *datalen = max / 2; + + return ZAP_SUCCESS; + +} + + +ZINT_CODEC_FUNCTION(zint_alaw2slin) +{ + int16_t *sln = data; + uint8_t law[1024] = {0}, *lp = law; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(law, data, max); + + for(i = 0; i < max; i++) { + *sln++ = alaw_to_linear(*lp++); + } + + *datalen = max * 2; + + return ZAP_SUCCESS; +} + +ZINT_CODEC_FUNCTION(zint_ulaw2alaw) +{ + zap_size_t len = *datalen; + unsigned i; + uint8_t *lp = data; + + if (max > len) { + max = len; + } + + for(i = 0; i < max; i++) { + *lp = ulaw_to_alaw(*lp); + lp++; + } + + return ZAP_SUCCESS; +} + +ZINT_CODEC_FUNCTION(zint_alaw2ulaw) +{ + zap_size_t len = *datalen; + unsigned i; + uint8_t *lp = data; + + if (max > len) { + max = len; + } + + for(i = 0; i < max; i++) { + *lp = alaw_to_ulaw(*lp); + lp++; + } + + return ZAP_SUCCESS; +} + +/******************************/ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { + zap_status_t status = ZAP_FAIL; + zint_codec_t codec_func; + zap_size_t max = *datalen; + assert(zchan != NULL); assert(zchan->zint != NULL); assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } if (!zchan->zint->read) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - return zchan->zint->read(zchan, data, datalen); - + status = zchan->zint->read(zchan, data, datalen); + + if (status == ZAP_SUCCESS && zchan->effective_codec != zchan->native_codec) { + if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_ulaw2slin; + } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { + codec_func = zint_ulaw2alaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_alaw2slin; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { + codec_func = zint_alaw2ulaw; + } + + if (codec_func) { + status = codec_func(data, max, datalen); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + status = ZAP_FAIL; + } + } + + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + int16_t sln_buf[1024], *sln = sln_buf; + zap_size_t slen; + char digit_str[80] = ""; + + if (zchan->effective_codec == ZAP_CODEC_SLIN) { + sln = data; + slen = *datalen / 2; + } else { + zap_size_t len = *datalen; + unsigned i; + uint8_t *lp = data; + slen = max; + + if (slen > len) { + slen = len; + } + + if (zchan->effective_codec == ZAP_CODEC_ULAW) { + for(i = 0; i < max; i++) { + *sln++ = ulaw_to_linear(*lp++); + } + } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { + for(i = 0; i < max; i++) { + *sln++ = alaw_to_linear(*lp++); + } + } + + sln = sln_buf; + } + + teletone_dtmf_detect (&zchan->dtmf_detect, sln, slen); + teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); + if(digit_str[0]) { + zint_event_cb_t event_callback = NULL; + if (zchan->span->event_callback) { + event_callback = zchan->span->event_callback; + } else if (zchan->event_callback) { + event_callback = zchan->event_callback; + } + + if (event_callback) { + zchan->event_header.e_type = ZAP_EVENT_DTMF; + zchan->event_header.data = digit_str; + event_callback(zchan, &zchan->event_header); + zchan->event_header.e_type = ZAP_EVENT_NONE; + zchan->event_header.data = NULL; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { + zchan->skip_read_frames = 20; + } + if (zchan->skip_read_frames > 0) { + memset(data, 0, *datalen); + zchan->skip_read_frames--; + } + } + } + + return status; } zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { + zap_status_t status = ZAP_FAIL; + zint_codec_t codec_func; + zap_size_t max = *datalen; + assert(zchan != NULL); assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } if (!zchan->zint->write) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - - return zchan->zint->write(zchan, data, datalen); + + if (zchan->effective_codec != zchan->native_codec) { + if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_slin2ulaw; + } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { + codec_func = zint_alaw2ulaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_slin2alaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { + codec_func = zint_ulaw2alaw; + } + + if (codec_func) { + status = codec_func(data, max, datalen); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + status = ZAP_FAIL; + } + } + + status = zchan->zint->write(zchan, data, datalen); + + return status; } zap_status_t zap_global_init(void) diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index ab429f0f79..8b9ae692ba 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -6,7 +6,8 @@ int main(int argc, char *argv[]) zap_channel_t *chan; unsigned ms = 20; zap_codec_t codec = ZAP_CODEC_SLIN; - + unsigned runs = 4; + if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); exit(-1); @@ -14,11 +15,12 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - + top: if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &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); @@ -26,7 +28,7 @@ int main(int argc, char *argv[]) } 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); @@ -54,10 +56,14 @@ int main(int argc, char *argv[]) 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(); } diff --git a/libs/openzap/src/wanpipe b/libs/openzap/src/wanpipe index 917220c04e..ae554a11c2 100644 --- a/libs/openzap/src/wanpipe +++ b/libs/openzap/src/wanpipe @@ -2,7 +2,7 @@ MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT OBJS += zap_wanpipe.o WANPIPE_INCLUDE=/usr/include/wanpipe -WP_CFLAGS =-I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include +WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index d73a293e96..0cfaa92e49 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -47,6 +47,7 @@ #define WP_INVALID_SOCKET INVALID_HANDLE_VALUE #else #define WP_INVALID_SOCKET -1 +#include #endif #include @@ -67,9 +68,30 @@ #include #endif +static struct { + unsigned codec_ms; +} wp_globals; static zap_software_interface_t wanpipe_interface; +static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) +{ + int err; + +#if defined(WIN32) + err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); +#else + err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); +#endif + + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + return ZAP_SUCCESS; +} + static zap_socket_t wp_open_device(int span, int chan) { char fname[256]; @@ -113,6 +135,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; + } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } @@ -188,24 +211,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) -{ - int err; - -#if defined(WIN32) - err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); -#else - err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); -#endif - - if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; - } - - return ZAP_SUCCESS; -} - static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; @@ -223,7 +228,16 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "span")) { + if (!strcasecmp(cfg.category, "defaults")) { + if (!strcasecmp(var, "codec_ms")) { + unsigned codec_ms = atoi(val); + if (codec_ms < 10 || codec_ms > 60) { + zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", cfg.lineno); + } else { + wp_globals.codec_ms = codec_ms; + } + } + } else if (!strcasecmp(cfg.category, "span")) { if (cfg.catno != catno) { zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; @@ -282,7 +296,28 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) static ZINT_OPEN_FUNCTION(wanpipe_open) { - ZINT_OPEN_MUZZLE; + + wanpipe_tdm_api_t tdm_api; + + if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; + } else { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; + tdm_api.wp_tdm_cmd.tdm_codec = WP_NONE; + wp_tdm_cmd_exec(zchan, &tdm_api); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; + tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; + wp_tdm_cmd_exec(zchan, &tdm_api); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; + if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; + } else { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; + } + } + return ZAP_SUCCESS; } @@ -307,7 +342,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { - *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; + ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; } } @@ -315,51 +350,22 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_SET_INTERVAL: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; - tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); + tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; - + case ZAP_COMMAND_SET_CODEC: { - zap_codec_t codec = *((int *)obj); - unsigned wp_codec = 0; - - switch(codec) { - case ZAP_CODEC_SLIN: - wp_codec = WP_SLINEAR; - break; - default: - break; - }; - - if (wp_codec) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = wp_codec; - err = wp_tdm_cmd_exec(zchan, &tdm_api); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Invalid Codec"); - return ZAP_FAIL; - } + zchan->effective_codec = ZAP_COMMAND_OBJ_INT; + err = 0; } break; + case ZAP_COMMAND_GET_CODEC: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC; - - if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { - unsigned wp_codec = tdm_api.wp_tdm_cmd.tdm_codec; - zap_codec_t codec = ZAP_CODEC_NONE; - switch(wp_codec) { - case WP_SLINEAR: - codec = ZAP_CODEC_SLIN; - break; - default: - break; - }; - - *((int *)obj) = codec; - } + ZAP_COMMAND_OBJ_INT = zchan->effective_codec; + err = 0; } break; default: @@ -413,7 +419,7 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) s = select(zchan->sockfd + 1, r, w, e, tvp); if (s < 0) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + snprintf(zchan->last_error, sizeof(zchan->last_error), "select: %s", strerror(errno)); return ZAP_FAIL; } @@ -434,7 +440,8 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) if (s == 0) { return ZAP_TIMEOUT; } - + + return ZAP_SUCCESS; } #ifndef __WINDOWS__ @@ -494,7 +501,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) msg.msg_iovlen = 2; msg.msg_iov = iov; - bsent = write(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); if (bsent > 0){ @@ -510,13 +516,11 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) static ZINT_READ_FUNCTION(wanpipe_read) { - ZINT_READ_MUZZLE; - + #ifndef WIN32 return wanpipe_read_unix(zchan, data, datalen); #endif - - return ZAP_FAIL; + } static ZINT_WRITE_FUNCTION(wanpipe_write) @@ -535,6 +539,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) assert(zint != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); + wp_globals.codec_ms = 20; wanpipe_interface.name = "wanpipe"; wanpipe_interface.configure = wanpipe_configure; wanpipe_interface.open = wanpipe_open; From e21ca79927e7a1cd79ad69aa155b6823f36afb4c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 May 2007 00:50:50 +0000 Subject: [PATCH 0070/1766] add a bunch of goodies git-svn-id: http://svn.openzap.org/svn/openzap/trunk@35 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 4 +- libs/freetdm/src/include/openzap.h | 98 ++++++--- libs/freetdm/src/openzap.c | 331 ++++++++++++++++++++++++++++- libs/freetdm/src/testapp.c | 12 +- libs/freetdm/src/wanpipe | 2 +- libs/freetdm/src/zap_wanpipe.c | 133 ++++++------ 6 files changed, 482 insertions(+), 98 deletions(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 9c6788826c..301d5836a9 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -30,7 +30,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o libteletone_detect.o libteletone_generate.o zap_buffer.o +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w @@ -69,5 +69,5 @@ zap_zt.o: zap_zt.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o $(MYLIB) *~ \#* + rm -f *.o $(MYLIB) *~ \#* testapp priserver diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 08201a2a41..67db68761a 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -101,6 +101,8 @@ typedef int zap_socket_t; typedef size_t zap_size_t; struct zap_software_interface; +#define ZAP_COMMAND_OBJ_INT *((int *)obj) + #define zap_true(expr)\ (expr && ( !strcasecmp(expr, "yes") ||\ !strcasecmp(expr, "on") ||\ @@ -111,6 +113,11 @@ struct zap_software_interface; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) + +#define zap_channel_test_feature(obj, flag) ((obj)->features & flag) +#define zap_channel_set_feature(obj, flag) (obj)->features |= (flag) +#define zap_channel_clear_feature(obj, flag) (obj)->features &= ~(flag) + /*! \brief Test for the existance of a flag on an arbitary object \command obj the object to test @@ -169,18 +176,24 @@ typedef enum { } zap_wait_flag_t; typedef enum { - ZAP_CODEC_NONE = (1 << 31), ZAP_CODEC_ULAW = 0, ZAP_CODEC_ALAW = 8, - ZAP_CODEC_SLIN = 10 + ZAP_CODEC_SLIN = 10, + ZAP_CODEC_NONE = (1 << 31) } 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_GET_CODEC, + ZAP_COMMAND_ENABLE_TONE_DETECT, + ZAP_COMMAND_DISABLE_TONE_DETECT } zap_command_t; typedef enum { @@ -196,33 +209,23 @@ typedef enum { ZAP_CHAN_TYPE_FXO } zap_chan_type_t; +typedef enum { + ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0) +} zap_channel_feature_t; + typedef enum { ZAP_CHANNEL_CONFIGURED = (1 << 0), ZAP_CHANNEL_READY = (1 << 1), - ZAP_CHANNEL_OPEN = (1 << 2) + ZAP_CHANNEL_OPEN = (1 << 2), + ZAP_CHANNEL_DTMF_DETECT = (1 << 3), + ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4) } zap_channel_flag_t; -struct zap_channel { - unsigned span_id; - unsigned chan_id; - zap_chan_type_t type; - zap_socket_t sockfd; - zap_channel_flag_t flags; - char last_error[256]; - void *mod_data; - struct zap_software_interface *zint; -}; typedef struct zap_channel zap_channel_t; +typedef struct zap_event zap_event_t; -struct zap_span { - unsigned span_id; - unsigned chan_count; - zap_span_flag_t flags; - struct zap_software_interface *zint; - zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; -}; -typedef struct zap_span zap_span_t; - +#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) +#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) #define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) #define ZINT_OPEN_ARGS (zap_channel_t *zchan) #define ZINT_CLOSE_ARGS (zap_channel_t *zchan) @@ -231,6 +234,8 @@ typedef struct zap_span zap_span_t; #define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) #define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; +typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; @@ -239,6 +244,8 @@ typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; +#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS +#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS #define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS #define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS #define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS @@ -275,6 +282,47 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT #define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG +typedef enum { + ZAP_EVENT_NONE, + ZAP_EVENT_DTMF +} zap_event_type_t; + +struct zap_event { + zap_event_type_t e_type; + void *data; +}; + +struct zap_channel { + unsigned span_id; + unsigned chan_id; + zap_chan_type_t type; + zap_socket_t sockfd; + zap_channel_flag_t flags; + zap_channel_feature_t features; + zap_codec_t effective_codec; + zap_codec_t native_codec; + teletone_dtmf_detect_state_t dtmf_detect; + zap_event_t event_header; + char last_error[256]; + zint_event_cb_t event_callback; + void *mod_data; + unsigned skip_read_frames; + struct zap_span *span; + struct zap_software_interface *zint; +}; + + +struct zap_span { + unsigned span_id; + unsigned chan_count; + zap_span_flag_t flags; + struct zap_software_interface *zint; + zint_event_cb_t event_callback; + zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; +}; +typedef struct zap_span zap_span_t; + + typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); extern zap_logger_t zap_log; @@ -293,9 +341,11 @@ struct zap_software_interface { typedef struct zap_software_interface zap_software_interface_t; +zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span); zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); - +zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index a33bcdbc98..1e215cf785 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -177,6 +177,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->zint = span->zint; new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; + new_chan->span = span; zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -185,6 +186,42 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } +zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span) +{ + zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_span_t *fspan; + + if (!zint) { + return ZAP_FAIL; + } + + if (id > ZAP_MAX_SPANS_INTERFACE) { + return ZAP_FAIL; + } + + fspan = &zint->spans[id]; + + if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { + return ZAP_FAIL; + } + + *span = fspan; + + return ZAP_SUCCESS; + +} + +zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback) +{ + span->event_callback = event_callback; + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback) +{ + zchan->event_callback = event_callback; + return ZAP_SUCCESS; +} zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan) { @@ -317,6 +354,9 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) status = check->zint->close(check); if (status == ZAP_SUCCESS) { zap_clear_flag(check, ZAP_CHANNEL_OPEN); + check->event_callback = NULL; + zap_clear_flag(check, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(check, ZAP_CHANNEL_SUPRESS_DTMF); *zchan = NULL; } } @@ -331,10 +371,50 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } + switch(command) { + case ZAP_COMMAND_ENABLE_TONE_DETECT: + { + /* if they don't have thier own, use ours */ + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; + if (tt == ZAP_TONE_DTMF) { + teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + zap_set_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_set_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); + return ZAP_FAIL; + } + } + } + break; + case ZAP_COMMAND_DISABLE_TONE_DETECT: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; + if (tt == ZAP_TONE_DTMF) { + teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); + return ZAP_FAIL; + } + } + } + break; + default: + break; + } + if (!zchan->zint->command) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } @@ -348,10 +428,12 @@ zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsi assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } if (!zchan->zint->wait) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } @@ -359,41 +441,282 @@ zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsi } +/*******************************/ +ZINT_CODEC_FUNCTION(zint_slin2ulaw) +{ + int16_t sln_buf[512] = {0}, *sln = sln_buf; + uint8_t *lp = data; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(sln, data, max); + + for(i = 0; i < max; i++) { + *lp++ = linear_to_ulaw(*sln++); + } + + *datalen = max / 2; + + return ZAP_SUCCESS; + +} + + +ZINT_CODEC_FUNCTION(zint_ulaw2slin) +{ + int16_t *sln = data; + uint8_t law[1024] = {0}, *lp = law; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(law, data, max); + + for(i = 0; i < max; i++) { + *sln++ = ulaw_to_linear(*lp++); + } + + *datalen = max * 2; + + return ZAP_SUCCESS; +} + +ZINT_CODEC_FUNCTION(zint_slin2alaw) +{ + int16_t sln_buf[512] = {0}, *sln = sln_buf; + uint8_t *lp = data; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(sln, data, max); + + for(i = 0; i < max; i++) { + *lp++ = linear_to_alaw(*sln++); + } + + *datalen = max / 2; + + return ZAP_SUCCESS; + +} + + +ZINT_CODEC_FUNCTION(zint_alaw2slin) +{ + int16_t *sln = data; + uint8_t law[1024] = {0}, *lp = law; + unsigned i; + zap_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(law, data, max); + + for(i = 0; i < max; i++) { + *sln++ = alaw_to_linear(*lp++); + } + + *datalen = max * 2; + + return ZAP_SUCCESS; +} + +ZINT_CODEC_FUNCTION(zint_ulaw2alaw) +{ + zap_size_t len = *datalen; + unsigned i; + uint8_t *lp = data; + + if (max > len) { + max = len; + } + + for(i = 0; i < max; i++) { + *lp = ulaw_to_alaw(*lp); + lp++; + } + + return ZAP_SUCCESS; +} + +ZINT_CODEC_FUNCTION(zint_alaw2ulaw) +{ + zap_size_t len = *datalen; + unsigned i; + uint8_t *lp = data; + + if (max > len) { + max = len; + } + + for(i = 0; i < max; i++) { + *lp = alaw_to_ulaw(*lp); + lp++; + } + + return ZAP_SUCCESS; +} + +/******************************/ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { + zap_status_t status = ZAP_FAIL; + zint_codec_t codec_func; + zap_size_t max = *datalen; + assert(zchan != NULL); assert(zchan->zint != NULL); assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } if (!zchan->zint->read) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - return zchan->zint->read(zchan, data, datalen); - + status = zchan->zint->read(zchan, data, datalen); + + if (status == ZAP_SUCCESS && zchan->effective_codec != zchan->native_codec) { + if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_ulaw2slin; + } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { + codec_func = zint_ulaw2alaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_alaw2slin; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { + codec_func = zint_alaw2ulaw; + } + + if (codec_func) { + status = codec_func(data, max, datalen); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + status = ZAP_FAIL; + } + } + + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + int16_t sln_buf[1024], *sln = sln_buf; + zap_size_t slen; + char digit_str[80] = ""; + + if (zchan->effective_codec == ZAP_CODEC_SLIN) { + sln = data; + slen = *datalen / 2; + } else { + zap_size_t len = *datalen; + unsigned i; + uint8_t *lp = data; + slen = max; + + if (slen > len) { + slen = len; + } + + if (zchan->effective_codec == ZAP_CODEC_ULAW) { + for(i = 0; i < max; i++) { + *sln++ = ulaw_to_linear(*lp++); + } + } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { + for(i = 0; i < max; i++) { + *sln++ = alaw_to_linear(*lp++); + } + } + + sln = sln_buf; + } + + teletone_dtmf_detect (&zchan->dtmf_detect, sln, slen); + teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); + if(digit_str[0]) { + zint_event_cb_t event_callback = NULL; + if (zchan->span->event_callback) { + event_callback = zchan->span->event_callback; + } else if (zchan->event_callback) { + event_callback = zchan->event_callback; + } + + if (event_callback) { + zchan->event_header.e_type = ZAP_EVENT_DTMF; + zchan->event_header.data = digit_str; + event_callback(zchan, &zchan->event_header); + zchan->event_header.e_type = ZAP_EVENT_NONE; + zchan->event_header.data = NULL; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { + zchan->skip_read_frames = 20; + } + if (zchan->skip_read_frames > 0) { + memset(data, 0, *datalen); + zchan->skip_read_frames--; + } + } + } + + return status; } zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { + zap_status_t status = ZAP_FAIL; + zint_codec_t codec_func; + zap_size_t max = *datalen; + assert(zchan != NULL); assert(zchan->zint != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } if (!zchan->zint->write) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - - return zchan->zint->write(zchan, data, datalen); + + if (zchan->effective_codec != zchan->native_codec) { + if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_slin2ulaw; + } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { + codec_func = zint_alaw2ulaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { + codec_func = zint_slin2alaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { + codec_func = zint_ulaw2alaw; + } + + if (codec_func) { + status = codec_func(data, max, datalen); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + status = ZAP_FAIL; + } + } + + status = zchan->zint->write(zchan, data, datalen); + + return status; } zap_status_t zap_global_init(void) diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index ab429f0f79..8b9ae692ba 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -6,7 +6,8 @@ int main(int argc, char *argv[]) zap_channel_t *chan; unsigned ms = 20; zap_codec_t codec = ZAP_CODEC_SLIN; - + unsigned runs = 4; + if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); exit(-1); @@ -14,11 +15,12 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - + top: if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &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); @@ -26,7 +28,7 @@ int main(int argc, char *argv[]) } 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); @@ -54,10 +56,14 @@ int main(int argc, char *argv[]) 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(); } diff --git a/libs/freetdm/src/wanpipe b/libs/freetdm/src/wanpipe index 917220c04e..ae554a11c2 100644 --- a/libs/freetdm/src/wanpipe +++ b/libs/freetdm/src/wanpipe @@ -2,7 +2,7 @@ MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT OBJS += zap_wanpipe.o WANPIPE_INCLUDE=/usr/include/wanpipe -WP_CFLAGS =-I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include +WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index d73a293e96..0cfaa92e49 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -47,6 +47,7 @@ #define WP_INVALID_SOCKET INVALID_HANDLE_VALUE #else #define WP_INVALID_SOCKET -1 +#include #endif #include @@ -67,9 +68,30 @@ #include #endif +static struct { + unsigned codec_ms; +} wp_globals; static zap_software_interface_t wanpipe_interface; +static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) +{ + int err; + +#if defined(WIN32) + err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); +#else + err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); +#endif + + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + return ZAP_SUCCESS; +} + static zap_socket_t wp_open_device(int span, int chan) { char fname[256]; @@ -113,6 +135,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; + } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } @@ -188,24 +211,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) -{ - int err; - -#if defined(WIN32) - err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); -#else - err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); -#endif - - if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; - } - - return ZAP_SUCCESS; -} - static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; @@ -223,7 +228,16 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "span")) { + if (!strcasecmp(cfg.category, "defaults")) { + if (!strcasecmp(var, "codec_ms")) { + unsigned codec_ms = atoi(val); + if (codec_ms < 10 || codec_ms > 60) { + zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", cfg.lineno); + } else { + wp_globals.codec_ms = codec_ms; + } + } + } else if (!strcasecmp(cfg.category, "span")) { if (cfg.catno != catno) { zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; @@ -282,7 +296,28 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) static ZINT_OPEN_FUNCTION(wanpipe_open) { - ZINT_OPEN_MUZZLE; + + wanpipe_tdm_api_t tdm_api; + + if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; + } else { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; + tdm_api.wp_tdm_cmd.tdm_codec = WP_NONE; + wp_tdm_cmd_exec(zchan, &tdm_api); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; + tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; + wp_tdm_cmd_exec(zchan, &tdm_api); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; + if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; + } else { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; + } + } + return ZAP_SUCCESS; } @@ -307,7 +342,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { - *((int *)obj) = tdm_api.wp_tdm_cmd.usr_period; + ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; } } @@ -315,51 +350,22 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_SET_INTERVAL: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; - tdm_api.wp_tdm_cmd.usr_period = *((int *)obj); + tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; - + case ZAP_COMMAND_SET_CODEC: { - zap_codec_t codec = *((int *)obj); - unsigned wp_codec = 0; - - switch(codec) { - case ZAP_CODEC_SLIN: - wp_codec = WP_SLINEAR; - break; - default: - break; - }; - - if (wp_codec) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = wp_codec; - err = wp_tdm_cmd_exec(zchan, &tdm_api); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Invalid Codec"); - return ZAP_FAIL; - } + zchan->effective_codec = ZAP_COMMAND_OBJ_INT; + err = 0; } break; + case ZAP_COMMAND_GET_CODEC: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC; - - if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { - unsigned wp_codec = tdm_api.wp_tdm_cmd.tdm_codec; - zap_codec_t codec = ZAP_CODEC_NONE; - switch(wp_codec) { - case WP_SLINEAR: - codec = ZAP_CODEC_SLIN; - break; - default: - break; - }; - - *((int *)obj) = codec; - } + ZAP_COMMAND_OBJ_INT = zchan->effective_codec; + err = 0; } break; default: @@ -413,7 +419,7 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) s = select(zchan->sockfd + 1, r, w, e, tvp); if (s < 0) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + snprintf(zchan->last_error, sizeof(zchan->last_error), "select: %s", strerror(errno)); return ZAP_FAIL; } @@ -434,7 +440,8 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) if (s == 0) { return ZAP_TIMEOUT; } - + + return ZAP_SUCCESS; } #ifndef __WINDOWS__ @@ -494,7 +501,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) msg.msg_iovlen = 2; msg.msg_iov = iov; - bsent = write(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); if (bsent > 0){ @@ -510,13 +516,11 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) static ZINT_READ_FUNCTION(wanpipe_read) { - ZINT_READ_MUZZLE; - + #ifndef WIN32 return wanpipe_read_unix(zchan, data, datalen); #endif - - return ZAP_FAIL; + } static ZINT_WRITE_FUNCTION(wanpipe_write) @@ -535,6 +539,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) assert(zint != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); + wp_globals.codec_ms = 20; wanpipe_interface.name = "wanpipe"; wanpipe_interface.configure = wanpipe_configure; wanpipe_interface.open = wanpipe_open; From 9fd18e7e1a2b1776efb5226f4a6a5cb104980906 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 May 2007 04:07:48 +0000 Subject: [PATCH 0071/1766] add dtmf generation and pause to let mike have a turn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@36 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 177 +++------------------- libs/openzap/src/include/zap_types.h | 196 +++++++++++++++++++++++++ libs/openzap/src/openzap.c | 211 +++++++++++++++++++++++---- libs/openzap/src/zap_wanpipe.c | 14 -- 4 files changed, 398 insertions(+), 200 deletions(-) create mode 100644 libs/openzap/src/include/zap_types.h diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 67db68761a..c6e4e79343 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -78,10 +78,12 @@ #include #endif #include +#include "zap_types.h" #include "hashtable.h" #include "zap_config.h" #include "g711.h" #include "libteletone.h" +#include "zap_buffer.h" #ifdef NDEBUG #undef assert @@ -91,17 +93,7 @@ #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 -#ifdef WIN32 -#include -typedef HANDLE zap_socket_t; -#else -typedef int zap_socket_t; -#endif -typedef size_t zap_size_t; -struct zap_software_interface; - -#define ZAP_COMMAND_OBJ_INT *((int *)obj) #define zap_true(expr)\ (expr && ( !strcasecmp(expr, "yes") ||\ @@ -156,136 +148,6 @@ struct zap_software_interface; #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} -typedef enum { - ZAP_TOP_DOWN, - ZAP_BOTTOM_UP -} zap_direction_t; - -typedef enum { - ZAP_SUCCESS, - ZAP_FAIL, - ZAP_MEMERR, - ZAP_TIMEOUT -} zap_status_t; - -typedef enum { - ZAP_NO_FLAGS = 0, - ZAP_READ = (1 << 0), - ZAP_WRITE = (1 << 1), - ZAP_ERROR = (1 << 2) -} zap_wait_flag_t; - -typedef enum { - ZAP_CODEC_ULAW = 0, - ZAP_CODEC_ALAW = 8, - ZAP_CODEC_SLIN = 10, - ZAP_CODEC_NONE = (1 << 31) -} 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_ENABLE_TONE_DETECT, - ZAP_COMMAND_DISABLE_TONE_DETECT -} zap_command_t; - -typedef enum { - ZAP_SPAN_CONFIGURED = (1 << 0), - ZAP_SPAN_READY = (1 << 1) -} 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_t; - -typedef enum { - ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0) -} zap_channel_feature_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_flag_t; - -typedef struct zap_channel zap_channel_t; -typedef struct zap_event zap_event_t; - -#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) -#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) -#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) -#define ZINT_OPEN_ARGS (zap_channel_t *zchan) -#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) -#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) -#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) -#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) - -typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; -typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; -typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; -typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; -typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; -typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; -typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; -typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; -typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; - -#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS -#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS -#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS -#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS -#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS -#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS -#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS -#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS -#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS - -#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLE assert(zchan != NULL) -#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) -#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) -#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) -#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) -#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) - -#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 enum { - ZAP_EVENT_NONE, - ZAP_EVENT_DTMF -} zap_event_type_t; struct zap_event { zap_event_type_t e_type; @@ -293,8 +155,8 @@ struct zap_event { }; struct zap_channel { - unsigned span_id; - unsigned chan_id; + uint32_t span_id; + uint32_t chan_id; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; @@ -306,24 +168,26 @@ struct zap_channel { char last_error[256]; zint_event_cb_t event_callback; void *mod_data; - unsigned skip_read_frames; + uint32_t skip_read_frames; + zap_buffer_t *dtmf_buffer; + uint32_t dtmf_on; + uint32_t dtmf_off; + teletone_generation_session_t tone_session; struct zap_span *span; struct zap_software_interface *zint; }; struct zap_span { - unsigned span_id; - unsigned chan_count; + uint32_t span_id; + uint32_t chan_count; zap_span_flag_t flags; struct zap_software_interface *zint; zint_event_cb_t event_callback; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; -typedef struct zap_span zap_span_t; -typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); extern zap_logger_t zap_log; struct zap_software_interface { @@ -335,31 +199,26 @@ struct zap_software_interface { zint_wait_t wait; zint_read_t read; zint_write_t write; - unsigned span_index; + uint32_t span_index; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; -typedef struct zap_software_interface zap_software_interface_t; - -zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span); +zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); -zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); -zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan); +zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); -unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen); -typedef struct hashtable zap_hash_t; -typedef struct hashtable_itr zap_hash_itr_t; -typedef struct key zap_hash_key_t; -typedef struct value zap_hash_val_t; +uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); + #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h new file mode 100644 index 0000000000..b8613e613b --- /dev/null +++ b/libs/openzap/src/include/zap_types.h @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_TYPES_H +#define ZAP_TYPES_H + +#ifdef WIN32 +#include +typedef HANDLE zap_socket_t; +#else +#include +typedef int zap_socket_t; +#endif + +typedef size_t zap_size_t; +struct zap_software_interface; + +#define ZAP_COMMAND_OBJ_INT *((int *)obj) +#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj + +typedef enum { + ZAP_TOP_DOWN, + ZAP_BOTTOM_UP +} zap_direction_t; + +typedef enum { + ZAP_SUCCESS, + ZAP_FAIL, + ZAP_MEMERR, + ZAP_TIMEOUT +} zap_status_t; + +typedef enum { + ZAP_NO_FLAGS = 0, + ZAP_READ = (1 << 0), + ZAP_WRITE = (1 << 1), + ZAP_ERROR = (1 << 2) +} zap_wait_flag_t; + +typedef enum { + ZAP_CODEC_ULAW = 0, + ZAP_CODEC_ALAW = 8, + ZAP_CODEC_SLIN = 10, + ZAP_CODEC_NONE = (1 << 31) +} 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_ENABLE_TONE_DETECT, + ZAP_COMMAND_DISABLE_TONE_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_t; + +typedef enum { + ZAP_SPAN_CONFIGURED = (1 << 0), + ZAP_SPAN_READY = (1 << 1) +} 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_t; + +typedef enum { + ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), + ZAP_CHANNEL_FEATURE_CODECS = (1 << 1) +} zap_channel_feature_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_flag_t; + +typedef struct zap_channel zap_channel_t; +typedef struct zap_event zap_event_t; + +#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) +#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) +#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) +#define ZINT_OPEN_ARGS (zap_channel_t *zchan) +#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) +#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) +#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) + +typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; +typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; +typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; +typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; +typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; +typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; +typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; +typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; +typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; + +#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS +#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS +#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS +#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS +#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS +#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS +#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS +#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS +#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS + +#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) +#define ZINT_OPEN_MUZZLE assert(zchan != NULL) +#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) +#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) +#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) +#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) + +#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 enum { + ZAP_EVENT_NONE, + ZAP_EVENT_DTMF +} zap_event_type_t; + +typedef struct zap_span zap_span_t; +typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); +typedef struct zap_software_interface zap_software_interface_t; +typedef struct hashtable zap_hash_t; +typedef struct hashtable_itr zap_hash_itr_t; +typedef struct key zap_hash_key_t; +typedef struct value zap_hash_val_t; +#endif diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 1e215cf785..37a39c71cf 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -31,7 +31,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "openzap.h" #include #ifdef ZAP_WANPIPE_SUPPORT @@ -108,7 +107,6 @@ static void default_logger(char *file, const char *func, int line, int level, ch } - zap_logger_t zap_log = null_logger; void zap_global_set_logger(zap_logger_t logger) @@ -135,10 +133,10 @@ static int equalkeys(void *k1, void *k2) return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static unsigned hashfromstring(void *ky) +static uint32_t hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; - unsigned hash = 0; + uint32_t hash = 0; int c; while ((c = *str++)) { @@ -186,7 +184,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span) +zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_span_t *fspan; @@ -223,14 +221,14 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_ return ZAP_SUCCESS; } -zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_status_t status = ZAP_FAIL; zap_channel_t *check; - unsigned i,j; + uint32_t i,j; zap_span_t *span; - unsigned span_max; + uint32_t span_max; if (!zint) { zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); @@ -319,7 +317,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct return status; } -zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) +zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_status_t status = ZAP_FAIL; @@ -357,6 +355,14 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) check->event_callback = NULL; zap_clear_flag(check, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(check, ZAP_CHANNEL_SUPRESS_DTMF); + if (check->tone_session.buffer) { + teletone_destroy_session(&check->tone_session); + memset(&check->tone_session, 0, sizeof(check->tone_session)); + } + if (check->dtmf_buffer) { + zap_buffer_destroy(&check->dtmf_buffer); + } + check->dtmf_on = check->dtmf_off = 0; *zchan = NULL; } } @@ -365,6 +371,38 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) } +static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) +{ + + if (zchan->dtmf_buffer) { + return ZAP_SUCCESS; + } + + if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); + return ZAP_FAIL; + } else { + zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); + } + + if (!zchan->dtmf_on) { + zchan->dtmf_on = 150; + } + + if (!zchan->dtmf_off) { + zchan->dtmf_off = 50; + } + + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + teletone_init_session(&zchan->tone_session, 1024, NULL, NULL); + + zchan->tone_session.rate = 8000; + zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); + zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); + return ZAP_SUCCESS; +} + zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { assert(zchan != NULL); @@ -376,10 +414,32 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } switch(command) { + case ZAP_COMMAND_SET_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + zchan->effective_codec = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_codec == zchan->native_codec) { + zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); + } + return ZAP_SUCCESS; + } + } + break; + + case ZAP_COMMAND_GET_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + ZAP_COMMAND_OBJ_INT = zchan->effective_codec; + return ZAP_SUCCESS; + } + } + break; case ZAP_COMMAND_ENABLE_TONE_DETECT: { /* if they don't have thier own, use ours */ - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); @@ -395,7 +455,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_DISABLE_TONE_DETECT: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); @@ -408,6 +468,74 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } } + case ZAP_COMMAND_GET_DTMF_ON_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_GET_DTMF_OFF_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_SET_DTMF_ON_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + int val = ZAP_COMMAND_OBJ_INT; + if (val > 10 && val < 1000) { + zchan->dtmf_on = val; + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); + return ZAP_FAIL; + } + } + } + break; + case ZAP_COMMAND_SET_DTMF_OFF_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + int val = ZAP_COMMAND_OBJ_INT; + if (val > 10 && val < 1000) { + zchan->dtmf_off = val; + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); + return ZAP_FAIL; + } + } + } + break; + case ZAP_COMMAND_SEND_DTMF: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + zap_status_t status; + char *cur; + char *digits = ZAP_COMMAND_OBJ_CHAR_P; + if (!zchan->dtmf_buffer) { + if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { + return status; + } + } + zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); + + for (cur = digits; *cur; cur++) { + int wrote = 0; + if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { + zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); + } + } + + zchan->skip_read_frames = 200; + return ZAP_SUCCESS; + } + } break; default: break; @@ -422,7 +550,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -446,7 +574,7 @@ ZINT_CODEC_FUNCTION(zint_slin2ulaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -470,7 +598,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -482,7 +610,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin) for(i = 0; i < max; i++) { *sln++ = ulaw_to_linear(*lp++); } - + *datalen = max * 2; return ZAP_SUCCESS; @@ -492,7 +620,7 @@ ZINT_CODEC_FUNCTION(zint_slin2alaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -516,7 +644,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -537,7 +665,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin) ZINT_CODEC_FUNCTION(zint_ulaw2alaw) { zap_size_t len = *datalen; - unsigned i; + uint32_t i; uint8_t *lp = data; if (max > len) { @@ -555,7 +683,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2alaw) ZINT_CODEC_FUNCTION(zint_alaw2ulaw) { zap_size_t len = *datalen; - unsigned i; + uint32_t i; uint8_t *lp = data; if (max > len) { @@ -594,7 +722,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data status = zchan->zint->read(zchan, data, datalen); - if (status == ZAP_SUCCESS && zchan->effective_codec != zchan->native_codec) { + if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { codec_func = zint_ulaw2slin; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { @@ -623,7 +751,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data slen = *datalen / 2; } else { zap_size_t len = *datalen; - unsigned i; + uint32_t i; uint8_t *lp = data; slen = max; @@ -679,8 +807,8 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat { zap_status_t status = ZAP_FAIL; zint_codec_t codec_func; - zap_size_t max = *datalen; - + zap_size_t dtmf_blen, max = *datalen; + assert(zchan != NULL); assert(zchan->zint != NULL); @@ -694,8 +822,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat return ZAP_FAIL; } - - if (zchan->effective_codec != zchan->native_codec) { + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { codec_func = zint_slin2ulaw; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { @@ -714,6 +841,36 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat } } + if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + zap_size_t dlen = *datalen; + uint8_t auxbuf[1024]; + uint32_t len, br; + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + dlen *= 2; + } + + len = dtmf_blen > dlen ? dlen : dtmf_blen; + + br = zap_buffer_read(zchan->dtmf_buffer, auxbuf, len); + + if (br < dlen) { + memset(auxbuf + br, 0, dlen - br); + } + + memcpy(data, auxbuf, dlen); + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + if (zchan->native_codec == ZAP_CODEC_ULAW) { + *datalen = dlen; + zint_slin2ulaw(data, max, datalen); + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + *datalen = dlen; + zint_slin2alaw(data, max, datalen); + } + } + } + status = zchan->zint->write(zchan, data, datalen); return status; @@ -723,7 +880,7 @@ zap_status_t zap_global_init(void) { zap_config_t cfg; char *var, *val; - unsigned configured = 0; + uint32_t configured = 0; zap_software_interface_t *zint; int modcount; @@ -801,7 +958,7 @@ zap_status_t zap_global_destroy(void) } -unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen) +uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) { int argc; char *ptr; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 0cfaa92e49..cc86622b57 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -354,20 +354,6 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; - - case ZAP_COMMAND_SET_CODEC: - { - zchan->effective_codec = ZAP_COMMAND_OBJ_INT; - err = 0; - } - break; - - case ZAP_COMMAND_GET_CODEC: - { - ZAP_COMMAND_OBJ_INT = zchan->effective_codec; - err = 0; - } - break; default: break; }; From 43e6b6fa23ac87fc720b12011bf4f3926c572513 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 May 2007 04:07:48 +0000 Subject: [PATCH 0072/1766] add dtmf generation and pause to let mike have a turn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@36 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 177 +++------------------- libs/freetdm/src/include/zap_types.h | 196 +++++++++++++++++++++++++ libs/freetdm/src/openzap.c | 211 +++++++++++++++++++++++---- libs/freetdm/src/zap_wanpipe.c | 14 -- 4 files changed, 398 insertions(+), 200 deletions(-) create mode 100644 libs/freetdm/src/include/zap_types.h diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 67db68761a..c6e4e79343 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -78,10 +78,12 @@ #include #endif #include +#include "zap_types.h" #include "hashtable.h" #include "zap_config.h" #include "g711.h" #include "libteletone.h" +#include "zap_buffer.h" #ifdef NDEBUG #undef assert @@ -91,17 +93,7 @@ #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 -#ifdef WIN32 -#include -typedef HANDLE zap_socket_t; -#else -typedef int zap_socket_t; -#endif -typedef size_t zap_size_t; -struct zap_software_interface; - -#define ZAP_COMMAND_OBJ_INT *((int *)obj) #define zap_true(expr)\ (expr && ( !strcasecmp(expr, "yes") ||\ @@ -156,136 +148,6 @@ struct zap_software_interface; #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} -typedef enum { - ZAP_TOP_DOWN, - ZAP_BOTTOM_UP -} zap_direction_t; - -typedef enum { - ZAP_SUCCESS, - ZAP_FAIL, - ZAP_MEMERR, - ZAP_TIMEOUT -} zap_status_t; - -typedef enum { - ZAP_NO_FLAGS = 0, - ZAP_READ = (1 << 0), - ZAP_WRITE = (1 << 1), - ZAP_ERROR = (1 << 2) -} zap_wait_flag_t; - -typedef enum { - ZAP_CODEC_ULAW = 0, - ZAP_CODEC_ALAW = 8, - ZAP_CODEC_SLIN = 10, - ZAP_CODEC_NONE = (1 << 31) -} 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_ENABLE_TONE_DETECT, - ZAP_COMMAND_DISABLE_TONE_DETECT -} zap_command_t; - -typedef enum { - ZAP_SPAN_CONFIGURED = (1 << 0), - ZAP_SPAN_READY = (1 << 1) -} 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_t; - -typedef enum { - ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0) -} zap_channel_feature_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_flag_t; - -typedef struct zap_channel zap_channel_t; -typedef struct zap_event zap_event_t; - -#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) -#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) -#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) -#define ZINT_OPEN_ARGS (zap_channel_t *zchan) -#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) -#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) -#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) -#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) - -typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; -typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; -typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; -typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; -typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; -typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; -typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; -typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; -typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; - -#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS -#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS -#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS -#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS -#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS -#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS -#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS -#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS -#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS - -#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLE assert(zchan != NULL) -#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) -#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) -#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) -#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) -#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) - -#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 enum { - ZAP_EVENT_NONE, - ZAP_EVENT_DTMF -} zap_event_type_t; struct zap_event { zap_event_type_t e_type; @@ -293,8 +155,8 @@ struct zap_event { }; struct zap_channel { - unsigned span_id; - unsigned chan_id; + uint32_t span_id; + uint32_t chan_id; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; @@ -306,24 +168,26 @@ struct zap_channel { char last_error[256]; zint_event_cb_t event_callback; void *mod_data; - unsigned skip_read_frames; + uint32_t skip_read_frames; + zap_buffer_t *dtmf_buffer; + uint32_t dtmf_on; + uint32_t dtmf_off; + teletone_generation_session_t tone_session; struct zap_span *span; struct zap_software_interface *zint; }; struct zap_span { - unsigned span_id; - unsigned chan_count; + uint32_t span_id; + uint32_t chan_count; zap_span_flag_t flags; struct zap_software_interface *zint; zint_event_cb_t event_callback; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; -typedef struct zap_span zap_span_t; -typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); extern zap_logger_t zap_log; struct zap_software_interface { @@ -335,31 +199,26 @@ struct zap_software_interface { zint_wait_t wait; zint_read_t read; zint_write_t write; - unsigned span_index; + uint32_t span_index; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; -typedef struct zap_software_interface zap_software_interface_t; - -zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span); +zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); -zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan); -zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan); +zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); -unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen); -typedef struct hashtable zap_hash_t; -typedef struct hashtable_itr zap_hash_itr_t; -typedef struct key zap_hash_key_t; -typedef struct value zap_hash_val_t; +uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); + #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h new file mode 100644 index 0000000000..b8613e613b --- /dev/null +++ b/libs/freetdm/src/include/zap_types.h @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_TYPES_H +#define ZAP_TYPES_H + +#ifdef WIN32 +#include +typedef HANDLE zap_socket_t; +#else +#include +typedef int zap_socket_t; +#endif + +typedef size_t zap_size_t; +struct zap_software_interface; + +#define ZAP_COMMAND_OBJ_INT *((int *)obj) +#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj + +typedef enum { + ZAP_TOP_DOWN, + ZAP_BOTTOM_UP +} zap_direction_t; + +typedef enum { + ZAP_SUCCESS, + ZAP_FAIL, + ZAP_MEMERR, + ZAP_TIMEOUT +} zap_status_t; + +typedef enum { + ZAP_NO_FLAGS = 0, + ZAP_READ = (1 << 0), + ZAP_WRITE = (1 << 1), + ZAP_ERROR = (1 << 2) +} zap_wait_flag_t; + +typedef enum { + ZAP_CODEC_ULAW = 0, + ZAP_CODEC_ALAW = 8, + ZAP_CODEC_SLIN = 10, + ZAP_CODEC_NONE = (1 << 31) +} 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_ENABLE_TONE_DETECT, + ZAP_COMMAND_DISABLE_TONE_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_t; + +typedef enum { + ZAP_SPAN_CONFIGURED = (1 << 0), + ZAP_SPAN_READY = (1 << 1) +} 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_t; + +typedef enum { + ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), + ZAP_CHANNEL_FEATURE_CODECS = (1 << 1) +} zap_channel_feature_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_flag_t; + +typedef struct zap_channel zap_channel_t; +typedef struct zap_event zap_event_t; + +#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) +#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) +#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) +#define ZINT_OPEN_ARGS (zap_channel_t *zchan) +#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) +#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) +#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) + +typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; +typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; +typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; +typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; +typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; +typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; +typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; +typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; +typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; + +#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS +#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS +#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS +#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS +#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS +#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS +#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS +#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS +#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS + +#define ZINT_CONFIGURE_MUZZLE assert(zint != NULL) +#define ZINT_OPEN_MUZZLE assert(zchan != NULL) +#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) +#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) +#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) +#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) + +#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 enum { + ZAP_EVENT_NONE, + ZAP_EVENT_DTMF +} zap_event_type_t; + +typedef struct zap_span zap_span_t; +typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); +typedef struct zap_software_interface zap_software_interface_t; +typedef struct hashtable zap_hash_t; +typedef struct hashtable_itr zap_hash_itr_t; +typedef struct key zap_hash_key_t; +typedef struct value zap_hash_val_t; +#endif diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 1e215cf785..37a39c71cf 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -31,7 +31,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include "openzap.h" #include #ifdef ZAP_WANPIPE_SUPPORT @@ -108,7 +107,6 @@ static void default_logger(char *file, const char *func, int line, int level, ch } - zap_logger_t zap_log = null_logger; void zap_global_set_logger(zap_logger_t logger) @@ -135,10 +133,10 @@ static int equalkeys(void *k1, void *k2) return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static unsigned hashfromstring(void *ky) +static uint32_t hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; - unsigned hash = 0; + uint32_t hash = 0; int c; while ((c = *str++)) { @@ -186,7 +184,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_find(const char *name, unsigned id, zap_span_t **span) +zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_span_t *fspan; @@ -223,14 +221,14 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_ return ZAP_SUCCESS; } -zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direction_t direction, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_status_t status = ZAP_FAIL; zap_channel_t *check; - unsigned i,j; + uint32_t i,j; zap_span_t *span; - unsigned span_max; + uint32_t span_max; if (!zint) { zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); @@ -319,7 +317,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct return status; } -zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan) +zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_status_t status = ZAP_FAIL; @@ -357,6 +355,14 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) check->event_callback = NULL; zap_clear_flag(check, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(check, ZAP_CHANNEL_SUPRESS_DTMF); + if (check->tone_session.buffer) { + teletone_destroy_session(&check->tone_session); + memset(&check->tone_session, 0, sizeof(check->tone_session)); + } + if (check->dtmf_buffer) { + zap_buffer_destroy(&check->dtmf_buffer); + } + check->dtmf_on = check->dtmf_off = 0; *zchan = NULL; } } @@ -365,6 +371,38 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) } +static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) +{ + + if (zchan->dtmf_buffer) { + return ZAP_SUCCESS; + } + + if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); + return ZAP_FAIL; + } else { + zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); + } + + if (!zchan->dtmf_on) { + zchan->dtmf_on = 150; + } + + if (!zchan->dtmf_off) { + zchan->dtmf_off = 50; + } + + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + teletone_init_session(&zchan->tone_session, 1024, NULL, NULL); + + zchan->tone_session.rate = 8000; + zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); + zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); + return ZAP_SUCCESS; +} + zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { assert(zchan != NULL); @@ -376,10 +414,32 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } switch(command) { + case ZAP_COMMAND_SET_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + zchan->effective_codec = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_codec == zchan->native_codec) { + zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); + } + return ZAP_SUCCESS; + } + } + break; + + case ZAP_COMMAND_GET_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + ZAP_COMMAND_OBJ_INT = zchan->effective_codec; + return ZAP_SUCCESS; + } + } + break; case ZAP_COMMAND_ENABLE_TONE_DETECT: { /* if they don't have thier own, use ours */ - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); @@ -395,7 +455,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_DISABLE_TONE_DETECT: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); @@ -408,6 +468,74 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } } + case ZAP_COMMAND_GET_DTMF_ON_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_GET_DTMF_OFF_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_SET_DTMF_ON_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + int val = ZAP_COMMAND_OBJ_INT; + if (val > 10 && val < 1000) { + zchan->dtmf_on = val; + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); + return ZAP_FAIL; + } + } + } + break; + case ZAP_COMMAND_SET_DTMF_OFF_PERIOD: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + int val = ZAP_COMMAND_OBJ_INT; + if (val > 10 && val < 1000) { + zchan->dtmf_off = val; + return ZAP_SUCCESS; + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); + return ZAP_FAIL; + } + } + } + break; + case ZAP_COMMAND_SEND_DTMF: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + zap_status_t status; + char *cur; + char *digits = ZAP_COMMAND_OBJ_CHAR_P; + if (!zchan->dtmf_buffer) { + if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { + return status; + } + } + zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); + + for (cur = digits; *cur; cur++) { + int wrote = 0; + if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { + zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); + } + } + + zchan->skip_read_frames = 200; + return ZAP_SUCCESS; + } + } break; default: break; @@ -422,7 +550,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, unsigned to) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -446,7 +574,7 @@ ZINT_CODEC_FUNCTION(zint_slin2ulaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -470,7 +598,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -482,7 +610,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin) for(i = 0; i < max; i++) { *sln++ = ulaw_to_linear(*lp++); } - + *datalen = max * 2; return ZAP_SUCCESS; @@ -492,7 +620,7 @@ ZINT_CODEC_FUNCTION(zint_slin2alaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -516,7 +644,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; - unsigned i; + uint32_t i; zap_size_t len = *datalen; if (max > len) { @@ -537,7 +665,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin) ZINT_CODEC_FUNCTION(zint_ulaw2alaw) { zap_size_t len = *datalen; - unsigned i; + uint32_t i; uint8_t *lp = data; if (max > len) { @@ -555,7 +683,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2alaw) ZINT_CODEC_FUNCTION(zint_alaw2ulaw) { zap_size_t len = *datalen; - unsigned i; + uint32_t i; uint8_t *lp = data; if (max > len) { @@ -594,7 +722,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data status = zchan->zint->read(zchan, data, datalen); - if (status == ZAP_SUCCESS && zchan->effective_codec != zchan->native_codec) { + if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { codec_func = zint_ulaw2slin; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { @@ -623,7 +751,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data slen = *datalen / 2; } else { zap_size_t len = *datalen; - unsigned i; + uint32_t i; uint8_t *lp = data; slen = max; @@ -679,8 +807,8 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat { zap_status_t status = ZAP_FAIL; zint_codec_t codec_func; - zap_size_t max = *datalen; - + zap_size_t dtmf_blen, max = *datalen; + assert(zchan != NULL); assert(zchan->zint != NULL); @@ -694,8 +822,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat return ZAP_FAIL; } - - if (zchan->effective_codec != zchan->native_codec) { + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { codec_func = zint_slin2ulaw; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { @@ -714,6 +841,36 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat } } + if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + zap_size_t dlen = *datalen; + uint8_t auxbuf[1024]; + uint32_t len, br; + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + dlen *= 2; + } + + len = dtmf_blen > dlen ? dlen : dtmf_blen; + + br = zap_buffer_read(zchan->dtmf_buffer, auxbuf, len); + + if (br < dlen) { + memset(auxbuf + br, 0, dlen - br); + } + + memcpy(data, auxbuf, dlen); + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + if (zchan->native_codec == ZAP_CODEC_ULAW) { + *datalen = dlen; + zint_slin2ulaw(data, max, datalen); + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + *datalen = dlen; + zint_slin2alaw(data, max, datalen); + } + } + } + status = zchan->zint->write(zchan, data, datalen); return status; @@ -723,7 +880,7 @@ zap_status_t zap_global_init(void) { zap_config_t cfg; char *var, *val; - unsigned configured = 0; + uint32_t configured = 0; zap_software_interface_t *zint; int modcount; @@ -801,7 +958,7 @@ zap_status_t zap_global_destroy(void) } -unsigned zap_separate_string(char *buf, char delim, char **array, int arraylen) +uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) { int argc; char *ptr; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 0cfaa92e49..cc86622b57 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -354,20 +354,6 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) err = wp_tdm_cmd_exec(zchan, &tdm_api); } break; - - case ZAP_COMMAND_SET_CODEC: - { - zchan->effective_codec = ZAP_COMMAND_OBJ_INT; - err = 0; - } - break; - - case ZAP_COMMAND_GET_CODEC: - { - ZAP_COMMAND_OBJ_INT = zchan->effective_codec; - err = 0; - } - break; default: break; }; From ed59987e25a4600fcb1f7192a2cd6dc459a2ffad Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 19 May 2007 05:05:29 +0000 Subject: [PATCH 0073/1766] windows build building again. most of the functions filled in for windows. more to come! git-svn-id: http://svn.openzap.org/svn/openzap/trunk@37 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 3 + libs/openzap/src/include/zap_types.h | 1 + libs/openzap/src/openzap.c | 8 +-- libs/openzap/src/zap_wanpipe.c | 101 ++++++++++++++++++++++++--- 4 files changed, 98 insertions(+), 15 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index c6e4e79343..d2a6fc08e6 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -61,6 +61,9 @@ #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 diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index b8613e613b..1d274de2b6 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -37,6 +37,7 @@ #ifdef WIN32 #include typedef HANDLE zap_socket_t; +typedef unsigned __int32 uint32_t; #else #include typedef int zap_socket_t; diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index 37a39c71cf..eb32bb35ec 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -703,7 +703,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2ulaw) zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func; + zint_codec_t codec_func = NULL; zap_size_t max = *datalen; assert(zchan != NULL); @@ -772,7 +772,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data sln = sln_buf; } - teletone_dtmf_detect (&zchan->dtmf_detect, sln, slen); + teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); if(digit_str[0]) { zint_event_cb_t event_callback = NULL; @@ -806,7 +806,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func; + zint_codec_t codec_func = NULL; zap_size_t dtmf_blen, max = *datalen; assert(zchan != NULL); @@ -844,7 +844,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer))) { zap_size_t dlen = *datalen; uint8_t auxbuf[1024]; - uint32_t len, br; + zap_size_t len, br; if (zchan->native_codec != ZAP_CODEC_SLIN) { dlen *= 2; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index cc86622b57..b3fb8b297f 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -330,7 +330,7 @@ static ZINT_CLOSE_FUNCTION(wanpipe_close) static ZINT_COMMAND_FUNCTION(wanpipe_command) { wanpipe_tdm_api_t tdm_api; - int err; + int err = 0; ZINT_COMMAND_MUZZLE; @@ -367,7 +367,74 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) return ZAP_SUCCESS; } -static ZINT_WAIT_FUNCTION(wanpipe_wait) +#ifdef __WINDOWS__ + +static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) +{ + API_POLL_STRUCT api_poll; + zap_wait_flag_t inflags = *flags; + + memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); + + api_poll.user_flags_bitmap = inflags; + api_poll.timeout = to; + + if(DoApiPollCommand(zchan->sockfd, &api_poll)){ + snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); + return ZAP_FAIL; + } + + *flags = ZAP_NO_FLAGS; + + switch(api_poll.operation_status) + { + case SANG_STATUS_RX_DATA_AVAILABLE: + break; + + default: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown Operation Status: %d\n", api_poll.operation_status); + return ZAP_FAIL; + } + + if(api_poll.poll_events_bitmap == 0){ + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid Poll Events bitmap: 0x%X\n", api_poll.poll_events_bitmap); + return ZAP_FAIL; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { + return ZAP_TIMEOUT; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_RX_DATA) { + *flags |= ZAP_READ; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_TX_READY) { + *flags |= ZAP_WRITE; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_LINK_STATE) { + *flags |= ZAP_ERROR; + } + + return ZAP_SUCCESS; +} + +static ZINT_READ_FUNCTION(wanpipe_read_windows) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(wanpipe_write_windows) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +#else + +static ZINT_WAIT_FUNCTION(wanpipe_wait_unix) { fd_set read_fds, write_fds, error_fds, *r = NULL, *w = NULL, *e = NULL; zap_wait_flag_t inflags = *flags; @@ -430,8 +497,6 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } -#ifndef __WINDOWS__ - static ZINT_READ_FUNCTION(wanpipe_read_unix) { int rx_len = 0; @@ -502,8 +567,9 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) static ZINT_READ_FUNCTION(wanpipe_read) { - -#ifndef WIN32 +#ifdef __WINDOWS__ + return wanpipe_read_windows(zchan, data, datalen); +#else return wanpipe_read_unix(zchan, data, datalen); #endif @@ -511,13 +577,20 @@ static ZINT_READ_FUNCTION(wanpipe_read) static ZINT_WRITE_FUNCTION(wanpipe_write) { - ZINT_WRITE_MUZZLE; - -#ifndef WIN32 +#ifdef __WINDOWS__ + return wanpipe_write_windows(zchan, data, datalen); +#else return wanpipe_write_unix(zchan, data, datalen); #endif +} - return ZAP_FAIL; +static ZINT_WAIT_FUNCTION(wanpipe_wait) +{ +#ifdef __WINDOWS__ + return wanpipe_wait_windows(zchan, flags, to); +#else + return wanpipe_wait_unix(zchan, flags, to); +#endif } zap_status_t wanpipe_init(zap_software_interface_t **zint) @@ -539,6 +612,12 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) return ZAP_SUCCESS; } +#if defined(__WINDOWS__) +#define close(handle) CloseHandle(handle) +#endif + +#define zap_wanpipe_socket_close(it) if (it != WP_INVALID_SOCKET) { close(it); it = WP_INVALID_SOCKET;} + zap_status_t wanpipe_destroy(void) { unsigned int i,j; @@ -551,7 +630,7 @@ zap_status_t wanpipe_destroy(void) zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - zap_socket_close(cur_chan->sockfd); + zap_wanpipe_socket_close(cur_chan->sockfd); } } } From 79a13d303ca55f14e74f3d0bd62e7de04f3820ca Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 19 May 2007 05:05:29 +0000 Subject: [PATCH 0074/1766] windows build building again. most of the functions filled in for windows. more to come! git-svn-id: http://svn.openzap.org/svn/openzap/trunk@37 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 3 + libs/freetdm/src/include/zap_types.h | 1 + libs/freetdm/src/openzap.c | 8 +-- libs/freetdm/src/zap_wanpipe.c | 101 ++++++++++++++++++++++++--- 4 files changed, 98 insertions(+), 15 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index c6e4e79343..d2a6fc08e6 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -61,6 +61,9 @@ #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 diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b8613e613b..1d274de2b6 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -37,6 +37,7 @@ #ifdef WIN32 #include typedef HANDLE zap_socket_t; +typedef unsigned __int32 uint32_t; #else #include typedef int zap_socket_t; diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index 37a39c71cf..eb32bb35ec 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -703,7 +703,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2ulaw) zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func; + zint_codec_t codec_func = NULL; zap_size_t max = *datalen; assert(zchan != NULL); @@ -772,7 +772,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data sln = sln_buf; } - teletone_dtmf_detect (&zchan->dtmf_detect, sln, slen); + teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); if(digit_str[0]) { zint_event_cb_t event_callback = NULL; @@ -806,7 +806,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func; + zint_codec_t codec_func = NULL; zap_size_t dtmf_blen, max = *datalen; assert(zchan != NULL); @@ -844,7 +844,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer))) { zap_size_t dlen = *datalen; uint8_t auxbuf[1024]; - uint32_t len, br; + zap_size_t len, br; if (zchan->native_codec != ZAP_CODEC_SLIN) { dlen *= 2; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index cc86622b57..b3fb8b297f 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -330,7 +330,7 @@ static ZINT_CLOSE_FUNCTION(wanpipe_close) static ZINT_COMMAND_FUNCTION(wanpipe_command) { wanpipe_tdm_api_t tdm_api; - int err; + int err = 0; ZINT_COMMAND_MUZZLE; @@ -367,7 +367,74 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) return ZAP_SUCCESS; } -static ZINT_WAIT_FUNCTION(wanpipe_wait) +#ifdef __WINDOWS__ + +static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) +{ + API_POLL_STRUCT api_poll; + zap_wait_flag_t inflags = *flags; + + memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); + + api_poll.user_flags_bitmap = inflags; + api_poll.timeout = to; + + if(DoApiPollCommand(zchan->sockfd, &api_poll)){ + snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); + return ZAP_FAIL; + } + + *flags = ZAP_NO_FLAGS; + + switch(api_poll.operation_status) + { + case SANG_STATUS_RX_DATA_AVAILABLE: + break; + + default: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown Operation Status: %d\n", api_poll.operation_status); + return ZAP_FAIL; + } + + if(api_poll.poll_events_bitmap == 0){ + snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid Poll Events bitmap: 0x%X\n", api_poll.poll_events_bitmap); + return ZAP_FAIL; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { + return ZAP_TIMEOUT; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_RX_DATA) { + *flags |= ZAP_READ; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_TX_READY) { + *flags |= ZAP_WRITE; + } + + if (api_poll.poll_events_bitmap & POLL_EVENT_LINK_STATE) { + *flags |= ZAP_ERROR; + } + + return ZAP_SUCCESS; +} + +static ZINT_READ_FUNCTION(wanpipe_read_windows) +{ + ZINT_READ_MUZZLE; + return ZAP_FAIL; +} + +static ZINT_WRITE_FUNCTION(wanpipe_write_windows) +{ + ZINT_WRITE_MUZZLE; + return ZAP_FAIL; +} + +#else + +static ZINT_WAIT_FUNCTION(wanpipe_wait_unix) { fd_set read_fds, write_fds, error_fds, *r = NULL, *w = NULL, *e = NULL; zap_wait_flag_t inflags = *flags; @@ -430,8 +497,6 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } -#ifndef __WINDOWS__ - static ZINT_READ_FUNCTION(wanpipe_read_unix) { int rx_len = 0; @@ -502,8 +567,9 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) static ZINT_READ_FUNCTION(wanpipe_read) { - -#ifndef WIN32 +#ifdef __WINDOWS__ + return wanpipe_read_windows(zchan, data, datalen); +#else return wanpipe_read_unix(zchan, data, datalen); #endif @@ -511,13 +577,20 @@ static ZINT_READ_FUNCTION(wanpipe_read) static ZINT_WRITE_FUNCTION(wanpipe_write) { - ZINT_WRITE_MUZZLE; - -#ifndef WIN32 +#ifdef __WINDOWS__ + return wanpipe_write_windows(zchan, data, datalen); +#else return wanpipe_write_unix(zchan, data, datalen); #endif +} - return ZAP_FAIL; +static ZINT_WAIT_FUNCTION(wanpipe_wait) +{ +#ifdef __WINDOWS__ + return wanpipe_wait_windows(zchan, flags, to); +#else + return wanpipe_wait_unix(zchan, flags, to); +#endif } zap_status_t wanpipe_init(zap_software_interface_t **zint) @@ -539,6 +612,12 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) return ZAP_SUCCESS; } +#if defined(__WINDOWS__) +#define close(handle) CloseHandle(handle) +#endif + +#define zap_wanpipe_socket_close(it) if (it != WP_INVALID_SOCKET) { close(it); it = WP_INVALID_SOCKET;} + zap_status_t wanpipe_destroy(void) { unsigned int i,j; @@ -551,7 +630,7 @@ zap_status_t wanpipe_destroy(void) zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - zap_socket_close(cur_chan->sockfd); + zap_wanpipe_socket_close(cur_chan->sockfd); } } } From 03ec9197c6582b0878b02e9cf3a144eb16ff1e65 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 19 May 2007 23:00:58 +0000 Subject: [PATCH 0075/1766] windows implementations for wanpipe read and write functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@38 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 93 ++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index b3fb8b297f..4087137691 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -422,13 +422,100 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) static ZINT_READ_FUNCTION(wanpipe_read_windows) { - ZINT_READ_MUZZLE; - return ZAP_FAIL; + zap_size_t rx_len = 0; + zap_status_t status = ZAP_FAIL; + + /* should we just pass in abuffer big enough in the first place instead of having to use rx_data and memcpy here? */ + static RX_DATA_STRUCT rx_data; + + if(DoReadCommand(zchan->sockfd, &rx_data)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoReadCommand() failed! Check messages log.\n"); + goto done; + } + + switch(rx_data.api_header.operation_status) + { + case SANG_STATUS_RX_DATA_AVAILABLE: + if(rx_data.api_header.data_length > *datalen){ + snprintf(zchan->last_error, sizeof(zchan->last_error), "Buffer overrun.\n"); + break; + } + memcpy(data, rx_data.data, rx_data.api_header.data_length); + rx_len = rx_data.api_header.data_length; + status = ZAP_SUCCESS; + break; + + case SANG_STATUS_TDM_EVENT_AVAILABLE: + memcpy(data, rx_data.data, rx_data.api_header.data_length); + rx_len = rx_data.api_header.data_length; + status = ZAP_SUCCESS; + break; + + case SANG_STATUS_RX_DATA_TIMEOUT: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Timeout on read.\n"); + break; + + case SANG_STATUS_BUFFER_TOO_SMALL: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Received data longer than buffer passed to API.\n"); + break; + + case SANG_STATUS_LINE_DISCONNECTED: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Line disconnected.\n"); + break; + + default: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Rx:Unknown Operation Status: %d\n", rx_data.api_header.operation_status); + break; + } + +done: + *datalen = rx_len; + return status; } static ZINT_WRITE_FUNCTION(wanpipe_write_windows) { - ZINT_WRITE_MUZZLE; + static TX_DATA_STRUCT local_tx_data; + + /* why don't we just provide the big enough buffer to start with so we can avoid the memcpy ? */ + memcpy(local_tx_data.data, data, *datalen); + + /* queue data for transmission */ + if(DoWriteCommand(zchan->sockfd, &local_tx_data)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoWriteCommand() failed!! Check messages log.\n"); + *datalen = 0; + return ZAP_FAIL; + } + + if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { + return ZAP_SUCCESS; + } + + *datalen = 0; + + switch(local_tx_data.api_header.operation_status) + { + case SANG_STATUS_TX_TIMEOUT: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** Error: SANG_STATUS_TX_TIMEOUT ******\n"); + break; + + case SANG_STATUS_TX_DATA_TOO_LONG: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n"); + break; + + case SANG_STATUS_TX_DATA_TOO_SHORT: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n"); + break; + + case SANG_STATUS_LINE_DISCONNECTED: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_LINE_DISCONNECTED ******\n"); + break; + + default: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown return code (0x%X) on transmission!\n", local_tx_data.api_header.operation_status); + break; + } + return ZAP_FAIL; } From 9a6edf6fff97ceccf56b744daf914d5575440b55 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 19 May 2007 23:00:58 +0000 Subject: [PATCH 0076/1766] windows implementations for wanpipe read and write functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@38 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 93 ++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index b3fb8b297f..4087137691 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -422,13 +422,100 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) static ZINT_READ_FUNCTION(wanpipe_read_windows) { - ZINT_READ_MUZZLE; - return ZAP_FAIL; + zap_size_t rx_len = 0; + zap_status_t status = ZAP_FAIL; + + /* should we just pass in abuffer big enough in the first place instead of having to use rx_data and memcpy here? */ + static RX_DATA_STRUCT rx_data; + + if(DoReadCommand(zchan->sockfd, &rx_data)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoReadCommand() failed! Check messages log.\n"); + goto done; + } + + switch(rx_data.api_header.operation_status) + { + case SANG_STATUS_RX_DATA_AVAILABLE: + if(rx_data.api_header.data_length > *datalen){ + snprintf(zchan->last_error, sizeof(zchan->last_error), "Buffer overrun.\n"); + break; + } + memcpy(data, rx_data.data, rx_data.api_header.data_length); + rx_len = rx_data.api_header.data_length; + status = ZAP_SUCCESS; + break; + + case SANG_STATUS_TDM_EVENT_AVAILABLE: + memcpy(data, rx_data.data, rx_data.api_header.data_length); + rx_len = rx_data.api_header.data_length; + status = ZAP_SUCCESS; + break; + + case SANG_STATUS_RX_DATA_TIMEOUT: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Timeout on read.\n"); + break; + + case SANG_STATUS_BUFFER_TOO_SMALL: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Received data longer than buffer passed to API.\n"); + break; + + case SANG_STATUS_LINE_DISCONNECTED: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Line disconnected.\n"); + break; + + default: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Rx:Unknown Operation Status: %d\n", rx_data.api_header.operation_status); + break; + } + +done: + *datalen = rx_len; + return status; } static ZINT_WRITE_FUNCTION(wanpipe_write_windows) { - ZINT_WRITE_MUZZLE; + static TX_DATA_STRUCT local_tx_data; + + /* why don't we just provide the big enough buffer to start with so we can avoid the memcpy ? */ + memcpy(local_tx_data.data, data, *datalen); + + /* queue data for transmission */ + if(DoWriteCommand(zchan->sockfd, &local_tx_data)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoWriteCommand() failed!! Check messages log.\n"); + *datalen = 0; + return ZAP_FAIL; + } + + if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { + return ZAP_SUCCESS; + } + + *datalen = 0; + + switch(local_tx_data.api_header.operation_status) + { + case SANG_STATUS_TX_TIMEOUT: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** Error: SANG_STATUS_TX_TIMEOUT ******\n"); + break; + + case SANG_STATUS_TX_DATA_TOO_LONG: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n"); + break; + + case SANG_STATUS_TX_DATA_TOO_SHORT: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n"); + break; + + case SANG_STATUS_LINE_DISCONNECTED: + snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_LINE_DISCONNECTED ******\n"); + break; + + default: + snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown return code (0x%X) on transmission!\n", local_tx_data.api_header.operation_status); + break; + } + return ZAP_FAIL; } From 69bd1dab467b625f199fd33523d7f99326b9b7cd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 19 May 2007 23:41:02 +0000 Subject: [PATCH 0077/1766] little cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@39 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 44 +++++++++------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 4087137691..89489bdede 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -78,7 +78,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm { int err; -#if defined(WIN32) +#if defined(__WINDOWS__) err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); #else err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); @@ -95,7 +95,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm static zap_socket_t wp_open_device(int span, int chan) { char fname[256]; -#if defined(WIN32) +#if defined(__WINDOWS__) _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); @@ -652,34 +652,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) #endif -static ZINT_READ_FUNCTION(wanpipe_read) -{ -#ifdef __WINDOWS__ - return wanpipe_read_windows(zchan, data, datalen); -#else - return wanpipe_read_unix(zchan, data, datalen); -#endif - -} - -static ZINT_WRITE_FUNCTION(wanpipe_write) -{ -#ifdef __WINDOWS__ - return wanpipe_write_windows(zchan, data, datalen); -#else - return wanpipe_write_unix(zchan, data, datalen); -#endif -} - -static ZINT_WAIT_FUNCTION(wanpipe_wait) -{ -#ifdef __WINDOWS__ - return wanpipe_wait_windows(zchan, flags, to); -#else - return wanpipe_wait_unix(zchan, flags, to); -#endif -} - zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); @@ -691,9 +663,15 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) 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; +#ifdef __WINDOWS__ + wanpipe_interface.wait = wanpipe_wait_windows; + wanpipe_interface.read = wanpipe_read_windows; + wanpipe_interface.write = wanpipe_write_windows; +#else + wanpipe_interface.wait = wanpipe_wait_unix; + wanpipe_interface.read = wanpipe_read_unix; + wanpipe_interface.write = wanpipe_write_unix; +#endif *zint = &wanpipe_interface; return ZAP_SUCCESS; From 72609fa965e5ceb71856ca66be45ccc97af86ec0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 19 May 2007 23:41:02 +0000 Subject: [PATCH 0078/1766] little cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@39 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 44 +++++++++------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 4087137691..89489bdede 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -78,7 +78,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm { int err; -#if defined(WIN32) +#if defined(__WINDOWS__) err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); #else err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); @@ -95,7 +95,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm static zap_socket_t wp_open_device(int span, int chan) { char fname[256]; -#if defined(WIN32) +#if defined(__WINDOWS__) _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); @@ -652,34 +652,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) #endif -static ZINT_READ_FUNCTION(wanpipe_read) -{ -#ifdef __WINDOWS__ - return wanpipe_read_windows(zchan, data, datalen); -#else - return wanpipe_read_unix(zchan, data, datalen); -#endif - -} - -static ZINT_WRITE_FUNCTION(wanpipe_write) -{ -#ifdef __WINDOWS__ - return wanpipe_write_windows(zchan, data, datalen); -#else - return wanpipe_write_unix(zchan, data, datalen); -#endif -} - -static ZINT_WAIT_FUNCTION(wanpipe_wait) -{ -#ifdef __WINDOWS__ - return wanpipe_wait_windows(zchan, flags, to); -#else - return wanpipe_wait_unix(zchan, flags, to); -#endif -} - zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); @@ -691,9 +663,15 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) 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; +#ifdef __WINDOWS__ + wanpipe_interface.wait = wanpipe_wait_windows; + wanpipe_interface.read = wanpipe_read_windows; + wanpipe_interface.write = wanpipe_write_windows; +#else + wanpipe_interface.wait = wanpipe_wait_unix; + wanpipe_interface.read = wanpipe_read_unix; + wanpipe_interface.write = wanpipe_write_unix; +#endif *zint = &wanpipe_interface; return ZAP_SUCCESS; From 425083a45d27ac1bd2a3b60804360de10b9c0593 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 00:11:11 +0000 Subject: [PATCH 0079/1766] some cross platform cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@40 a93c3328-9c30-0410-af19-c9cd2b2d52af --- ...ap_wanpipe_windows.h => sangoma_tdm_api.h} | 781 ++++++++++-------- libs/openzap/src/zap_wanpipe.c | 63 +- 2 files changed, 427 insertions(+), 417 deletions(-) rename libs/openzap/src/include/{zap_wanpipe_windows.h => sangoma_tdm_api.h} (76%) diff --git a/libs/openzap/src/include/zap_wanpipe_windows.h b/libs/openzap/src/include/sangoma_tdm_api.h similarity index 76% rename from libs/openzap/src/include/zap_wanpipe_windows.h rename to libs/openzap/src/include/sangoma_tdm_api.h index d5773da640..1e9c610287 100644 --- a/libs/openzap/src/include/zap_wanpipe_windows.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -1,363 +1,432 @@ -/***************************************************************************** - * win_api_common.h Windows Sangoma API Code Library - * - * Author(s): David Rokhvarg - * - * Copyright: (c) 1984-2006 Sangoma Technologies Inc. - * - * ============================================================================ - */ - -#ifndef _WIN_API_COMMON_H -#define _WIN_API_COMMON_H - +/***************************************************************************** + * sangoma_tdm_api.h Sangoma API Code Library + * + * Author(s): David Rokhvarg + * + * Copyright: (c) 1984-2006 Sangoma Technologies Inc. + * + * ============================================================================ + */ + +#ifndef _SANGOMA_TDM_API_H +#define _SANGOMA_TDM_API_H + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#define __WINDOWS__ +#endif +#endif + +#ifdef __WINDOWS__ +#ifdef _MSC_VER +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4200 4201 4214) +#endif +#include +#define WP_INVALID_SOCKET INVALID_HANDLE_VALUE +#else +#define WP_INVALID_SOCKET -1 +#include +#endif + +#include +#include +#include +#include +#ifdef __WINDOWS__ +#include +#include +#endif +#include + +#define FNAME_LEN 50 #define DEV_NAME_LEN 100 char device_name[DEV_NAME_LEN]; + +#ifdef __WINDOWS__ + /* IOCTL management structures and variables*/ wan_udp_hdr_t wan_udp; static wan_cmd_api_t api_cmd; -static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; - -/* keeps the LAST (and single) event received */ -static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; - -static -int -tdmv_api_ioctl( - HANDLE fd, - wanpipe_tdm_api_cmd_t *tdm_api_cmd - ) -{ - DWORD ln; - unsigned char id = 0; - int err = 0; - - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; - wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); - - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)tdm_api_cmd, - sizeof(wanpipe_tdm_api_cmd_t)); - - if(DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - //actual ioctl failed - err = 1; - return err; - }else{ - err = 0; - } - - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - //ioctl ok, but command failed - return 2; - } - - //copy data from driver's buffer to caller's buffer - memcpy( (void*)tdm_api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wanpipe_tdm_api_cmd_t)); - return 0; -} - -static -int -wanpipe_api_ioctl( - HANDLE fd, - wan_cmd_api_t *api_cmd - ) -{ - DWORD ln; - unsigned char id = 0; - int err = 0; - - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; - wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); - - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)api_cmd, - sizeof(wan_cmd_api_t)); - - if(DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - err = 1; - return err; - }else{ - err = 0; - } - - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - return 2; - } - - //copy data from driver's buffer to caller's buffer - memcpy( (void*)api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wan_cmd_api_t)); - return 0; -} - -// Blocking read command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -USHORT -DoReadCommand( - HANDLE drv, - RX_DATA_STRUCT * pRx - ) -{ - DWORD ln; - - if (DeviceIoControl( - drv, - IoctlReadCommand, - (LPVOID)NULL, - 0L, - (LPVOID)pRx, - sizeof(RX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - //check messages log - return 1; - }else{ - return 0; - } -} - -// Blocking write command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -UCHAR -DoWriteCommand( - HANDLE drv, - TX_DATA_STRUCT * pTx - ) -{ - DWORD ln; - - if(DeviceIoControl( - drv, - IoctlWriteCommand, - (LPVOID)pTx, - (ULONG)sizeof(TX_DATA_STRUCT), - (LPVOID)pTx, - sizeof(TX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -// Blocking API Poll command. -static -USHORT -DoApiPollCommand( - HANDLE drv, - API_POLL_STRUCT *api_poll_ptr - ) -{ - DWORD ln; - - if (DeviceIoControl( - drv, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)api_poll_ptr, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -static -int -DoManagementCommand( - HANDLE drv, - wan_udp_hdr_t* wan_udp - ) -{ - DWORD ln; - static unsigned char id = 0; - - wan_udp->wan_udphdr_request_reply = 0x01; - wan_udp->wan_udphdr_id = id++; - wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - if(DeviceIoControl( - drv, - IoctlManagementCommand, - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -/////////////////////////////////////////////////////////////////////////// -// -//structures and definitions used for queueing data -// -typedef struct -{ - void* previous; - TX_RX_DATA_STRUCT tx_rx_data; -}api_queue_element_t; - -#define API_Q_MUTEX_TIMEOUT 1000//1 second -#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue - -enum API_Q_STATUS{ - API_Q_SUCCESS=0, - API_Q_GEN_FAILURE, - API_Q_MEM_ALLOC_FAILURE, - API_Q_FULL, - API_Q_EMPTY -}; - -typedef struct -{ - //number of nodes in the list - USHORT size; - //insert at tail - api_queue_element_t * tail; - //remove from head - api_queue_element_t * head; - //mutex for synchronizing access to the queue - HANDLE api_queue_mutex; -}api_queue_t; - - -static __inline int api_enqueue( api_queue_t* api_queue, - unsigned char * buffer, - unsigned short length) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == API_Q_MAX_SIZE){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_FULL; - } - - element = malloc(sizeof(api_queue_element_t)); - if(element == NULL){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_MEM_ALLOC_FAILURE; - } - - //now copy everything in to the element - memcpy(element->tx_rx_data.data, buffer, length); - - element->tx_rx_data.api_header.data_length = length; - element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; - - //insert element at the tail of the queue - element->previous = NULL; - - if(api_queue->size == 0){ - //special case of a previously empty queue - api_queue->head = element; - api_queue->tail = element; - }else{ - api_queue->tail->previous = element; - api_queue->tail = element; - } - api_queue->size++; - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -static __inline int api_dequeue( api_queue_t* api_queue, - TX_RX_DATA_STRUCT* destination) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == 0){ - //tx queue is empty - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_EMPTY; - } - - //remove from the head of the queue - element = api_queue->head; - api_queue->head = element->previous; - - //now copy everything in to the user buffer - memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); - - free(element); - api_queue->size--; - if(api_queue->size == 0){ - api_queue->head = NULL; - api_queue->tail = NULL; - } - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -//remove all elements from the queue -static __inline void empty_api_queue(api_queue_t* api_queue) -{ - TX_DATA_STRUCT tx_rx_data; - - while(api_dequeue(api_queue, &tx_rx_data) == 0){ - ; - } -} - -/////////////////////////////////////////////////////////////////////////// -#endif /* _WIN_API_COMMON_H */ +static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; + +/* keeps the LAST (and single) event received */ +static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; +#endif + +#ifdef __WINDOWS__ +static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; + wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)tdm_api_cmd, + sizeof(wanpipe_tdm_api_cmd_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //actual ioctl failed + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + //ioctl ok, but command failed + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)tdm_api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wanpipe_tdm_api_cmd_t)); + return 0; +} + +#else +static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +{ + return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); +} +#endif + +static sng_fd_t tdmv_api_open_span_chan(int span, int chan) +{ + char fname[FNAME_LEN]; +#if defined(__WINDOWS__) + + //NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. + // Subtract 1 from 'chan'. + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + //prn(verbose, "Opening device: %s...\n", fname); + + return CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); +#else + int fd = WP_INVALID_SOCKET; + + sprintf(fname,"/dev/wptdm_s%dc%d",span,chan); + + fd = open(fname, O_RDWR); + + if (fd < 0) { + fd = WP_INVALID_SOCKET; + } + + return fd; +#endif +} + +#ifdef __WINDOWS__ +static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; + wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)api_cmd, + sizeof(wan_cmd_api_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wan_cmd_api_t)); + return 0; +} + +// Blocking read command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +USHORT +DoReadCommand( + sng_fd_t drv, + RX_DATA_STRUCT * pRx + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlReadCommand, + (LPVOID)NULL, + 0L, + (LPVOID)pRx, + sizeof(RX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //check messages log + return 1; + }else{ + return 0; + } +} + +// Blocking write command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +UCHAR +DoWriteCommand( + sng_fd_t drv, + TX_DATA_STRUCT * pTx + ) +{ + DWORD ln; + + if(DeviceIoControl( + drv, + IoctlWriteCommand, + (LPVOID)pTx, + (ULONG)sizeof(TX_DATA_STRUCT), + (LPVOID)pTx, + sizeof(TX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +// Blocking API Poll command. +static +USHORT +DoApiPollCommand( + sng_fd_t drv, + API_POLL_STRUCT *api_poll_ptr + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlApiPoll, + (LPVOID)NULL, + 0L, + (LPVOID)api_poll_ptr, + sizeof(API_POLL_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +static +int +DoManagementCommand( + sng_fd_t drv, + wan_udp_hdr_t* wan_udp + ) +{ + DWORD ln; + static unsigned char id = 0; + + wan_udp->wan_udphdr_request_reply = 0x01; + wan_udp->wan_udphdr_id = id++; + wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + if(DeviceIoControl( + drv, + IoctlManagementCommand, + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +/////////////////////////////////////////////////////////////////////////// +// +//structures and definitions used for queueing data +// +typedef struct +{ + void* previous; + TX_RX_DATA_STRUCT tx_rx_data; +}api_queue_element_t; + +#define API_Q_MUTEX_TIMEOUT 1000//1 second +#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue + +enum API_Q_STATUS{ + API_Q_SUCCESS=0, + API_Q_GEN_FAILURE, + API_Q_MEM_ALLOC_FAILURE, + API_Q_FULL, + API_Q_EMPTY +}; + +typedef struct +{ + //number of nodes in the list + USHORT size; + //insert at tail + api_queue_element_t * tail; + //remove from head + api_queue_element_t * head; + //mutex for synchronizing access to the queue + sng_fd_t api_queue_mutex; +}api_queue_t; + + +static __inline int api_enqueue( api_queue_t* api_queue, + unsigned char * buffer, + unsigned short length) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == API_Q_MAX_SIZE){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_FULL; + } + + element = malloc(sizeof(api_queue_element_t)); + if(element == NULL){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_MEM_ALLOC_FAILURE; + } + + //now copy everything in to the element + memcpy(element->tx_rx_data.data, buffer, length); + + element->tx_rx_data.api_header.data_length = length; + element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; + + //insert element at the tail of the queue + element->previous = NULL; + + if(api_queue->size == 0){ + //special case of a previously empty queue + api_queue->head = element; + api_queue->tail = element; + }else{ + api_queue->tail->previous = element; + api_queue->tail = element; + } + api_queue->size++; + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +static __inline int api_dequeue( api_queue_t* api_queue, + TX_RX_DATA_STRUCT* destination) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == 0){ + //tx queue is empty + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_EMPTY; + } + + //remove from the head of the queue + element = api_queue->head; + api_queue->head = element->previous; + + //now copy everything in to the user buffer + memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); + + free(element); + api_queue->size--; + if(api_queue->size == 0){ + api_queue->head = NULL; + api_queue->tail = NULL; + } + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +//remove all elements from the queue +static __inline void empty_api_queue(api_queue_t* api_queue) +{ + TX_DATA_STRUCT tx_rx_data; + + while(api_dequeue(api_queue, &tx_rx_data) == 0){ + ; + } +} + +/////////////////////////////////////////////////////////////////////////// +#endif + +#endif /* _SANGOMA_TDM_API_H */ diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 89489bdede..e9f879effb 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -36,37 +36,12 @@ #include "openzap.h" #include "zap_wanpipe.h" -#ifdef __WINDOWS__ -#ifdef _MSC_VER -/* disable warning for zero length array in a struct */ -/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4200 4201 4214) -#endif -#include -#define FNAME_LEN 50 -#define WP_INVALID_SOCKET INVALID_HANDLE_VALUE -#else -#define WP_INVALID_SOCKET -1 -#include -#endif - -#include -#include -#include -#include -#ifdef __WINDOWS__ -#include -#include -#endif -#include +#include #ifdef HAVE_SYS_SOCKET_H #include #endif -#if defined(__WINDOWS__) -#include -#endif static struct { unsigned codec_ms; @@ -78,11 +53,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm { int err; -#if defined(__WINDOWS__) err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); -#else - err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); -#endif if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); @@ -92,36 +63,6 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm return ZAP_SUCCESS; } -static zap_socket_t wp_open_device(int span, int chan) -{ - char fname[256]; -#if defined(__WINDOWS__) - - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - return CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); -#else - int fd=-1; - - sprintf(fname, "/dev/wptdm_s%dc%d", span, chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - - return fd; -#endif -} - static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type) { unsigned configured = 0, x; @@ -130,7 +71,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_channel_t *chan; zap_socket_t sockfd = WP_INVALID_SOCKET; - sockfd = wp_open_device(spanno, x); + sockfd = tdmv_api_open_span_chan(spanno, x); if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); From 6b557785605a84f3028f2b626564f8547515f5ae Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 00:11:11 +0000 Subject: [PATCH 0080/1766] some cross platform cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@40 a93c3328-9c30-0410-af19-c9cd2b2d52af --- ...ap_wanpipe_windows.h => sangoma_tdm_api.h} | 781 ++++++++++-------- libs/freetdm/src/zap_wanpipe.c | 63 +- 2 files changed, 427 insertions(+), 417 deletions(-) rename libs/freetdm/src/include/{zap_wanpipe_windows.h => sangoma_tdm_api.h} (76%) diff --git a/libs/freetdm/src/include/zap_wanpipe_windows.h b/libs/freetdm/src/include/sangoma_tdm_api.h similarity index 76% rename from libs/freetdm/src/include/zap_wanpipe_windows.h rename to libs/freetdm/src/include/sangoma_tdm_api.h index d5773da640..1e9c610287 100644 --- a/libs/freetdm/src/include/zap_wanpipe_windows.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -1,363 +1,432 @@ -/***************************************************************************** - * win_api_common.h Windows Sangoma API Code Library - * - * Author(s): David Rokhvarg - * - * Copyright: (c) 1984-2006 Sangoma Technologies Inc. - * - * ============================================================================ - */ - -#ifndef _WIN_API_COMMON_H -#define _WIN_API_COMMON_H - +/***************************************************************************** + * sangoma_tdm_api.h Sangoma API Code Library + * + * Author(s): David Rokhvarg + * + * Copyright: (c) 1984-2006 Sangoma Technologies Inc. + * + * ============================================================================ + */ + +#ifndef _SANGOMA_TDM_API_H +#define _SANGOMA_TDM_API_H + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#define __WINDOWS__ +#endif +#endif + +#ifdef __WINDOWS__ +#ifdef _MSC_VER +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4200 4201 4214) +#endif +#include +#define WP_INVALID_SOCKET INVALID_HANDLE_VALUE +#else +#define WP_INVALID_SOCKET -1 +#include +#endif + +#include +#include +#include +#include +#ifdef __WINDOWS__ +#include +#include +#endif +#include + +#define FNAME_LEN 50 #define DEV_NAME_LEN 100 char device_name[DEV_NAME_LEN]; + +#ifdef __WINDOWS__ + /* IOCTL management structures and variables*/ wan_udp_hdr_t wan_udp; static wan_cmd_api_t api_cmd; -static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; - -/* keeps the LAST (and single) event received */ -static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; - -static -int -tdmv_api_ioctl( - HANDLE fd, - wanpipe_tdm_api_cmd_t *tdm_api_cmd - ) -{ - DWORD ln; - unsigned char id = 0; - int err = 0; - - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; - wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); - - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)tdm_api_cmd, - sizeof(wanpipe_tdm_api_cmd_t)); - - if(DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - //actual ioctl failed - err = 1; - return err; - }else{ - err = 0; - } - - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - //ioctl ok, but command failed - return 2; - } - - //copy data from driver's buffer to caller's buffer - memcpy( (void*)tdm_api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wanpipe_tdm_api_cmd_t)); - return 0; -} - -static -int -wanpipe_api_ioctl( - HANDLE fd, - wan_cmd_api_t *api_cmd - ) -{ - DWORD ln; - unsigned char id = 0; - int err = 0; - - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; - wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); - - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)api_cmd, - sizeof(wan_cmd_api_t)); - - if(DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - err = 1; - return err; - }else{ - err = 0; - } - - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - return 2; - } - - //copy data from driver's buffer to caller's buffer - memcpy( (void*)api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wan_cmd_api_t)); - return 0; -} - -// Blocking read command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -USHORT -DoReadCommand( - HANDLE drv, - RX_DATA_STRUCT * pRx - ) -{ - DWORD ln; - - if (DeviceIoControl( - drv, - IoctlReadCommand, - (LPVOID)NULL, - 0L, - (LPVOID)pRx, - sizeof(RX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - //check messages log - return 1; - }else{ - return 0; - } -} - -// Blocking write command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -UCHAR -DoWriteCommand( - HANDLE drv, - TX_DATA_STRUCT * pTx - ) -{ - DWORD ln; - - if(DeviceIoControl( - drv, - IoctlWriteCommand, - (LPVOID)pTx, - (ULONG)sizeof(TX_DATA_STRUCT), - (LPVOID)pTx, - sizeof(TX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -// Blocking API Poll command. -static -USHORT -DoApiPollCommand( - HANDLE drv, - API_POLL_STRUCT *api_poll_ptr - ) -{ - DWORD ln; - - if (DeviceIoControl( - drv, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)api_poll_ptr, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -static -int -DoManagementCommand( - HANDLE drv, - wan_udp_hdr_t* wan_udp - ) -{ - DWORD ln; - static unsigned char id = 0; - - wan_udp->wan_udphdr_request_reply = 0x01; - wan_udp->wan_udphdr_id = id++; - wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - if(DeviceIoControl( - drv, - IoctlManagementCommand, - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -/////////////////////////////////////////////////////////////////////////// -// -//structures and definitions used for queueing data -// -typedef struct -{ - void* previous; - TX_RX_DATA_STRUCT tx_rx_data; -}api_queue_element_t; - -#define API_Q_MUTEX_TIMEOUT 1000//1 second -#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue - -enum API_Q_STATUS{ - API_Q_SUCCESS=0, - API_Q_GEN_FAILURE, - API_Q_MEM_ALLOC_FAILURE, - API_Q_FULL, - API_Q_EMPTY -}; - -typedef struct -{ - //number of nodes in the list - USHORT size; - //insert at tail - api_queue_element_t * tail; - //remove from head - api_queue_element_t * head; - //mutex for synchronizing access to the queue - HANDLE api_queue_mutex; -}api_queue_t; - - -static __inline int api_enqueue( api_queue_t* api_queue, - unsigned char * buffer, - unsigned short length) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == API_Q_MAX_SIZE){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_FULL; - } - - element = malloc(sizeof(api_queue_element_t)); - if(element == NULL){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_MEM_ALLOC_FAILURE; - } - - //now copy everything in to the element - memcpy(element->tx_rx_data.data, buffer, length); - - element->tx_rx_data.api_header.data_length = length; - element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; - - //insert element at the tail of the queue - element->previous = NULL; - - if(api_queue->size == 0){ - //special case of a previously empty queue - api_queue->head = element; - api_queue->tail = element; - }else{ - api_queue->tail->previous = element; - api_queue->tail = element; - } - api_queue->size++; - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -static __inline int api_dequeue( api_queue_t* api_queue, - TX_RX_DATA_STRUCT* destination) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == 0){ - //tx queue is empty - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_EMPTY; - } - - //remove from the head of the queue - element = api_queue->head; - api_queue->head = element->previous; - - //now copy everything in to the user buffer - memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); - - free(element); - api_queue->size--; - if(api_queue->size == 0){ - api_queue->head = NULL; - api_queue->tail = NULL; - } - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -//remove all elements from the queue -static __inline void empty_api_queue(api_queue_t* api_queue) -{ - TX_DATA_STRUCT tx_rx_data; - - while(api_dequeue(api_queue, &tx_rx_data) == 0){ - ; - } -} - -/////////////////////////////////////////////////////////////////////////// -#endif /* _WIN_API_COMMON_H */ +static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; + +/* keeps the LAST (and single) event received */ +static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; +#endif + +#ifdef __WINDOWS__ +static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; + wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)tdm_api_cmd, + sizeof(wanpipe_tdm_api_cmd_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //actual ioctl failed + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + //ioctl ok, but command failed + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)tdm_api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wanpipe_tdm_api_cmd_t)); + return 0; +} + +#else +static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +{ + return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); +} +#endif + +static sng_fd_t tdmv_api_open_span_chan(int span, int chan) +{ + char fname[FNAME_LEN]; +#if defined(__WINDOWS__) + + //NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. + // Subtract 1 from 'chan'. + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + //prn(verbose, "Opening device: %s...\n", fname); + + return CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); +#else + int fd = WP_INVALID_SOCKET; + + sprintf(fname,"/dev/wptdm_s%dc%d",span,chan); + + fd = open(fname, O_RDWR); + + if (fd < 0) { + fd = WP_INVALID_SOCKET; + } + + return fd; +#endif +} + +#ifdef __WINDOWS__ +static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) +{ + DWORD ln; + unsigned char id = 0; + int err = 0; + + wan_udp.wan_udphdr_request_reply = 0x01; + wan_udp.wan_udphdr_id = id; + wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; + wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); + + //copy data from caller's buffer to driver's buffer + memcpy( wan_udp.wan_udphdr_data, + (void*)api_cmd, + sizeof(wan_cmd_api_t)); + + if(DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + err = 1; + return err; + }else{ + err = 0; + } + + if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + return 2; + } + + //copy data from driver's buffer to caller's buffer + memcpy( (void*)api_cmd, + wan_udp.wan_udphdr_data, + sizeof(wan_cmd_api_t)); + return 0; +} + +// Blocking read command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +USHORT +DoReadCommand( + sng_fd_t drv, + RX_DATA_STRUCT * pRx + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlReadCommand, + (LPVOID)NULL, + 0L, + (LPVOID)pRx, + sizeof(RX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + //check messages log + return 1; + }else{ + return 0; + } +} + +// Blocking write command. If used after DoApiPollCommand(), +// it will return immediatly, without blocking. +static +UCHAR +DoWriteCommand( + sng_fd_t drv, + TX_DATA_STRUCT * pTx + ) +{ + DWORD ln; + + if(DeviceIoControl( + drv, + IoctlWriteCommand, + (LPVOID)pTx, + (ULONG)sizeof(TX_DATA_STRUCT), + (LPVOID)pTx, + sizeof(TX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +// Blocking API Poll command. +static +USHORT +DoApiPollCommand( + sng_fd_t drv, + API_POLL_STRUCT *api_poll_ptr + ) +{ + DWORD ln; + + if (DeviceIoControl( + drv, + IoctlApiPoll, + (LPVOID)NULL, + 0L, + (LPVOID)api_poll_ptr, + sizeof(API_POLL_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +static +int +DoManagementCommand( + sng_fd_t drv, + wan_udp_hdr_t* wan_udp + ) +{ + DWORD ln; + static unsigned char id = 0; + + wan_udp->wan_udphdr_request_reply = 0x01; + wan_udp->wan_udphdr_id = id++; + wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; + + if(DeviceIoControl( + drv, + IoctlManagementCommand, + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ + return 1; + }else{ + return 0; + } +} + +/////////////////////////////////////////////////////////////////////////// +// +//structures and definitions used for queueing data +// +typedef struct +{ + void* previous; + TX_RX_DATA_STRUCT tx_rx_data; +}api_queue_element_t; + +#define API_Q_MUTEX_TIMEOUT 1000//1 second +#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue + +enum API_Q_STATUS{ + API_Q_SUCCESS=0, + API_Q_GEN_FAILURE, + API_Q_MEM_ALLOC_FAILURE, + API_Q_FULL, + API_Q_EMPTY +}; + +typedef struct +{ + //number of nodes in the list + USHORT size; + //insert at tail + api_queue_element_t * tail; + //remove from head + api_queue_element_t * head; + //mutex for synchronizing access to the queue + sng_fd_t api_queue_mutex; +}api_queue_t; + + +static __inline int api_enqueue( api_queue_t* api_queue, + unsigned char * buffer, + unsigned short length) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == API_Q_MAX_SIZE){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_FULL; + } + + element = malloc(sizeof(api_queue_element_t)); + if(element == NULL){ + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_MEM_ALLOC_FAILURE; + } + + //now copy everything in to the element + memcpy(element->tx_rx_data.data, buffer, length); + + element->tx_rx_data.api_header.data_length = length; + element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; + + //insert element at the tail of the queue + element->previous = NULL; + + if(api_queue->size == 0){ + //special case of a previously empty queue + api_queue->head = element; + api_queue->tail = element; + }else{ + api_queue->tail->previous = element; + api_queue->tail = element; + } + api_queue->size++; + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +static __inline int api_dequeue( api_queue_t* api_queue, + TX_RX_DATA_STRUCT* destination) +{ + api_queue_element_t *element; + DWORD mresult; + + mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); + if (mresult != WAIT_OBJECT_0) { + return API_Q_GEN_FAILURE; + } + + if(api_queue->size == 0){ + //tx queue is empty + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_EMPTY; + } + + //remove from the head of the queue + element = api_queue->head; + api_queue->head = element->previous; + + //now copy everything in to the user buffer + memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); + + free(element); + api_queue->size--; + if(api_queue->size == 0){ + api_queue->head = NULL; + api_queue->tail = NULL; + } + ReleaseMutex(api_queue->api_queue_mutex); + return API_Q_SUCCESS; +} + +//remove all elements from the queue +static __inline void empty_api_queue(api_queue_t* api_queue) +{ + TX_DATA_STRUCT tx_rx_data; + + while(api_dequeue(api_queue, &tx_rx_data) == 0){ + ; + } +} + +/////////////////////////////////////////////////////////////////////////// +#endif + +#endif /* _SANGOMA_TDM_API_H */ diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 89489bdede..e9f879effb 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -36,37 +36,12 @@ #include "openzap.h" #include "zap_wanpipe.h" -#ifdef __WINDOWS__ -#ifdef _MSC_VER -/* disable warning for zero length array in a struct */ -/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4200 4201 4214) -#endif -#include -#define FNAME_LEN 50 -#define WP_INVALID_SOCKET INVALID_HANDLE_VALUE -#else -#define WP_INVALID_SOCKET -1 -#include -#endif - -#include -#include -#include -#include -#ifdef __WINDOWS__ -#include -#include -#endif -#include +#include #ifdef HAVE_SYS_SOCKET_H #include #endif -#if defined(__WINDOWS__) -#include -#endif static struct { unsigned codec_ms; @@ -78,11 +53,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm { int err; -#if defined(__WINDOWS__) err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); -#else - err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd); -#endif if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); @@ -92,36 +63,6 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm return ZAP_SUCCESS; } -static zap_socket_t wp_open_device(int span, int chan) -{ - char fname[256]; -#if defined(__WINDOWS__) - - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - return CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); -#else - int fd=-1; - - sprintf(fname, "/dev/wptdm_s%dc%d", span, chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - - return fd; -#endif -} - static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type) { unsigned configured = 0, x; @@ -130,7 +71,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_channel_t *chan; zap_socket_t sockfd = WP_INVALID_SOCKET; - sockfd = wp_open_device(spanno, x); + sockfd = tdmv_api_open_span_chan(spanno, x); if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); From 426739b6b9614d1d3bf6aab98d9bca4d56d5fb1b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 20 May 2007 01:50:01 +0000 Subject: [PATCH 0081/1766] interval git-svn-id: http://svn.openzap.org/svn/openzap/trunk@41 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 3 +++ libs/openzap/src/include/zap_types.h | 6 ++++-- libs/openzap/src/openzap.c | 25 ++++++++++++++++++++++++- libs/openzap/src/zap_wanpipe.c | 7 +++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d2a6fc08e6..8f4b012a80 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -166,6 +166,9 @@ struct zap_channel { zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; + uint32_t effective_interval; + uint32_t native_interval; + uint32_t packet_len; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1d274de2b6..a4fdae24fd 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -109,7 +109,8 @@ typedef enum { typedef enum { ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), - ZAP_CHANNEL_FEATURE_CODECS = (1 << 1) + ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), + ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) } zap_channel_feature_t; typedef enum { @@ -118,7 +119,8 @@ typedef enum { ZAP_CHANNEL_OPEN = (1 << 2), ZAP_CHANNEL_DTMF_DETECT = (1 << 3), ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4), - ZAP_CHANNEL_TRANSCODE = (1 << 5) + ZAP_CHANNEL_TRANSCODE = (1 << 5), + ZAP_CHANNEL_BUFFER = (1 << 6) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index eb32bb35ec..b10227bb63 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -414,7 +414,29 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } switch(command) { - case ZAP_COMMAND_SET_CODEC: + case ZAP_COMMAND_SET_INTERVAL: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { + zchan->effective_interval = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_interval == zchan->native_interval) { + zap_clear_flag(zchan, ZAP_CHANNEL_BUFFER); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_BUFFER); + } + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_GET_INTERVAL: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { + ZAP_COMMAND_OBJ_INT = zchan->effective_interval; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_SET_CODEC: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { zchan->effective_codec = ZAP_COMMAND_OBJ_INT; @@ -423,6 +445,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } else { zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); } + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); return ZAP_SUCCESS; } } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index e9f879effb..7d5c9a8de9 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -76,7 +76,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; - } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } @@ -250,7 +249,10 @@ static ZINT_OPEN_FUNCTION(wanpipe_open) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; wp_tdm_cmd_exec(zchan, &tdm_api); - + 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; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; @@ -293,6 +295,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; err = wp_tdm_cmd_exec(zchan, &tdm_api); + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); } break; default: From 110d452c60a4aca994a806bff5274284b55a0f27 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 20 May 2007 01:50:01 +0000 Subject: [PATCH 0082/1766] interval git-svn-id: http://svn.openzap.org/svn/openzap/trunk@41 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 3 +++ libs/freetdm/src/include/zap_types.h | 6 ++++-- libs/freetdm/src/openzap.c | 25 ++++++++++++++++++++++++- libs/freetdm/src/zap_wanpipe.c | 7 +++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index d2a6fc08e6..8f4b012a80 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -166,6 +166,9 @@ struct zap_channel { zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; + uint32_t effective_interval; + uint32_t native_interval; + uint32_t packet_len; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 1d274de2b6..a4fdae24fd 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -109,7 +109,8 @@ typedef enum { typedef enum { ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), - ZAP_CHANNEL_FEATURE_CODECS = (1 << 1) + ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), + ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) } zap_channel_feature_t; typedef enum { @@ -118,7 +119,8 @@ typedef enum { ZAP_CHANNEL_OPEN = (1 << 2), ZAP_CHANNEL_DTMF_DETECT = (1 << 3), ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4), - ZAP_CHANNEL_TRANSCODE = (1 << 5) + ZAP_CHANNEL_TRANSCODE = (1 << 5), + ZAP_CHANNEL_BUFFER = (1 << 6) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index eb32bb35ec..b10227bb63 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -414,7 +414,29 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } switch(command) { - case ZAP_COMMAND_SET_CODEC: + case ZAP_COMMAND_SET_INTERVAL: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { + zchan->effective_interval = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_interval == zchan->native_interval) { + zap_clear_flag(zchan, ZAP_CHANNEL_BUFFER); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_BUFFER); + } + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_GET_INTERVAL: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { + ZAP_COMMAND_OBJ_INT = zchan->effective_interval; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_SET_CODEC: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { zchan->effective_codec = ZAP_COMMAND_OBJ_INT; @@ -423,6 +445,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } else { zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); } + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); return ZAP_SUCCESS; } } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index e9f879effb..7d5c9a8de9 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -76,7 +76,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; - } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } @@ -250,7 +249,10 @@ static ZINT_OPEN_FUNCTION(wanpipe_open) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; wp_tdm_cmd_exec(zchan, &tdm_api); - + 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; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; @@ -293,6 +295,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; err = wp_tdm_cmd_exec(zchan, &tdm_api); + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); } break; default: From 6424510af96443b3fca037db6ae4c7d481bb7f97 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:14:23 +0000 Subject: [PATCH 0083/1766] move wanpipe's close function to the cross platform abstraction. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@42 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 12 ++++++++++++ libs/openzap/src/zap_wanpipe.c | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 1e9c610287..98033bb523 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -146,6 +146,18 @@ static sng_fd_t tdmv_api_open_span_chan(int span, int chan) #endif } +void tdmv_api_close_socket(sng_fd_t *sp) +{ + if( *sp != INVALID_HANDLE_VALUE){ +#if defined(__WINDOWS__) + CloseHandle(*sp); +#else + close(*sp); +#endif + *sp = INVALID_HANDLE_VALUE; + } +} + #ifdef __WINDOWS__ static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) { diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 7d5c9a8de9..57c1aa7400 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -621,12 +621,6 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) return ZAP_SUCCESS; } -#if defined(__WINDOWS__) -#define close(handle) CloseHandle(handle) -#endif - -#define zap_wanpipe_socket_close(it) if (it != WP_INVALID_SOCKET) { close(it); it = WP_INVALID_SOCKET;} - zap_status_t wanpipe_destroy(void) { unsigned int i,j; @@ -639,7 +633,7 @@ zap_status_t wanpipe_destroy(void) zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - zap_wanpipe_socket_close(cur_chan->sockfd); + tdmv_api_close_socket(cur_chan->sockfd); } } } From 3bf6d4d8f3281ca4922c3276f03881bfd60b83b6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:14:23 +0000 Subject: [PATCH 0084/1766] move wanpipe's close function to the cross platform abstraction. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@42 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 12 ++++++++++++ libs/freetdm/src/zap_wanpipe.c | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index 1e9c610287..98033bb523 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -146,6 +146,18 @@ static sng_fd_t tdmv_api_open_span_chan(int span, int chan) #endif } +void tdmv_api_close_socket(sng_fd_t *sp) +{ + if( *sp != INVALID_HANDLE_VALUE){ +#if defined(__WINDOWS__) + CloseHandle(*sp); +#else + close(*sp); +#endif + *sp = INVALID_HANDLE_VALUE; + } +} + #ifdef __WINDOWS__ static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) { diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 7d5c9a8de9..57c1aa7400 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -621,12 +621,6 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) return ZAP_SUCCESS; } -#if defined(__WINDOWS__) -#define close(handle) CloseHandle(handle) -#endif - -#define zap_wanpipe_socket_close(it) if (it != WP_INVALID_SOCKET) { close(it); it = WP_INVALID_SOCKET;} - zap_status_t wanpipe_destroy(void) { unsigned int i,j; @@ -639,7 +633,7 @@ zap_status_t wanpipe_destroy(void) zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - zap_wanpipe_socket_close(cur_chan->sockfd); + tdmv_api_close_socket(cur_chan->sockfd); } } } From deb8d2bb3688ea1e8580f0d06849d3a597474fed Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:48:56 +0000 Subject: [PATCH 0085/1766] fix on timeout git-svn-id: http://svn.openzap.org/svn/openzap/trunk@43 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 57c1aa7400..70f9ffefa5 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -323,13 +323,13 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) api_poll.user_flags_bitmap = inflags; api_poll.timeout = to; + *flags = ZAP_NO_FLAGS; + if(DoApiPollCommand(zchan->sockfd, &api_poll)){ snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); return ZAP_FAIL; } - *flags = ZAP_NO_FLAGS; - switch(api_poll.operation_status) { case SANG_STATUS_RX_DATA_AVAILABLE: From 6671691130129407da281797a1633886a8acaf7c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:48:56 +0000 Subject: [PATCH 0086/1766] fix on timeout git-svn-id: http://svn.openzap.org/svn/openzap/trunk@43 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 57c1aa7400..70f9ffefa5 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -323,13 +323,13 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) api_poll.user_flags_bitmap = inflags; api_poll.timeout = to; + *flags = ZAP_NO_FLAGS; + if(DoApiPollCommand(zchan->sockfd, &api_poll)){ snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); return ZAP_FAIL; } - *flags = ZAP_NO_FLAGS; - switch(api_poll.operation_status) { case SANG_STATUS_RX_DATA_AVAILABLE: From 90577e48753c569ff0efe18c0ec48ea7b1b6d259 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:56:51 +0000 Subject: [PATCH 0087/1766] an attempt to put a cross platform poll into the header file. This is really wrong as we can't differentiate between in band and oob on windows right now. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@44 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 98033bb523..a2ede350c3 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -441,4 +441,70 @@ static __inline void empty_api_queue(api_queue_t* api_queue) /////////////////////////////////////////////////////////////////////////// #endif +#if defined(__WINDOWS__) +/* This is broken, we don't actually get real results for oob messages on windows */ +#define POLLPRI (POLL_EVENT_LINK_STATE | POLL_EVENT_LINK_CONNECT | POLL_EVENT_LINK_DISCONNECT) +#endif + +/* return -1 for error, 0 for timeout, or POLLIN | POLLOUT | POLLPRI based on the result of the poll */ +int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) +{ +#if defined(__WINDOWS__) + API_POLL_STRUCT api_poll; + + memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); + + api_poll.user_flags_bitmap = flags; + api_poll.timeout = timeout; + + if(DoApiPollCommand(fd, &api_poll)) { + return -1; + } + + 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; + } + + return api_poll.poll_events_bitmap; +#else + struct pollfd pfds[1]; + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); + pfds[0].fd = fd; + pfds[0].events = flags; + res = poll(pfds, 1, timeout); + + if (res == 0) { + return 0; + } + + if (res < 0) { + return -1; + } + + if ((pfds[0].revents & POLLERR)) { + return -1; + } + + return pfds[0].revents; +#endif +} + #endif /* _SANGOMA_TDM_API_H */ From 631e7e61bbb5f51db44ffddc37a5e5b8735aacd8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:56:51 +0000 Subject: [PATCH 0088/1766] an attempt to put a cross platform poll into the header file. This is really wrong as we can't differentiate between in band and oob on windows right now. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@44 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index 98033bb523..a2ede350c3 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -441,4 +441,70 @@ static __inline void empty_api_queue(api_queue_t* api_queue) /////////////////////////////////////////////////////////////////////////// #endif +#if defined(__WINDOWS__) +/* This is broken, we don't actually get real results for oob messages on windows */ +#define POLLPRI (POLL_EVENT_LINK_STATE | POLL_EVENT_LINK_CONNECT | POLL_EVENT_LINK_DISCONNECT) +#endif + +/* return -1 for error, 0 for timeout, or POLLIN | POLLOUT | POLLPRI based on the result of the poll */ +int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) +{ +#if defined(__WINDOWS__) + API_POLL_STRUCT api_poll; + + memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); + + api_poll.user_flags_bitmap = flags; + api_poll.timeout = timeout; + + if(DoApiPollCommand(fd, &api_poll)) { + return -1; + } + + 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; + } + + return api_poll.poll_events_bitmap; +#else + struct pollfd pfds[1]; + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); + pfds[0].fd = fd; + pfds[0].events = flags; + res = poll(pfds, 1, timeout); + + if (res == 0) { + return 0; + } + + if (res < 0) { + return -1; + } + + if ((pfds[0].revents & POLLERR)) { + return -1; + } + + return pfds[0].revents; +#endif +} + #endif /* _SANGOMA_TDM_API_H */ From e8c38d85a8bea0d8b4a354a2915f11053bf6cc93 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:46:09 +0000 Subject: [PATCH 0089/1766] implement the openzap wanpipe wait function using the cross platform poll from last commit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@45 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 150 ++++++++------------------------- 1 file changed, 34 insertions(+), 116 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 70f9ffefa5..6b351fb61f 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -313,57 +313,6 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) #ifdef __WINDOWS__ -static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) -{ - API_POLL_STRUCT api_poll; - zap_wait_flag_t inflags = *flags; - - memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); - - api_poll.user_flags_bitmap = inflags; - api_poll.timeout = to; - - *flags = ZAP_NO_FLAGS; - - if(DoApiPollCommand(zchan->sockfd, &api_poll)){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); - return ZAP_FAIL; - } - - switch(api_poll.operation_status) - { - case SANG_STATUS_RX_DATA_AVAILABLE: - break; - - default: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown Operation Status: %d\n", api_poll.operation_status); - return ZAP_FAIL; - } - - if(api_poll.poll_events_bitmap == 0){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid Poll Events bitmap: 0x%X\n", api_poll.poll_events_bitmap); - return ZAP_FAIL; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { - return ZAP_TIMEOUT; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_RX_DATA) { - *flags |= ZAP_READ; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_TX_READY) { - *flags |= ZAP_WRITE; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_LINK_STATE) { - *flags |= ZAP_ERROR; - } - - return ZAP_SUCCESS; -} - static ZINT_READ_FUNCTION(wanpipe_read_windows) { zap_size_t rx_len = 0; @@ -465,69 +414,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_windows) #else -static ZINT_WAIT_FUNCTION(wanpipe_wait_unix) -{ - fd_set read_fds, write_fds, error_fds, *r = NULL, *w = NULL, *e = NULL; - zap_wait_flag_t inflags = *flags; - int s; - struct timeval tv, *tvp = NULL; - - if (to) { - memset(&tv, 0, sizeof(tv)); - tv.tv_sec = to / 1000; - tv.tv_usec = (to % 1000) * 1000; - tvp = &tv; - } - - FD_ZERO(&read_fds); - FD_ZERO(&write_fds); - FD_ZERO(&error_fds); - - - if (inflags & ZAP_READ) { - r = &read_fds; - FD_SET(zchan->sockfd, r); - } - - if (inflags & ZAP_WRITE) { - w = &write_fds; - FD_SET(zchan->sockfd, w); - } - - if (inflags & ZAP_ERROR) { - e = &error_fds; - FD_SET(zchan->sockfd, e); - } - - *flags = ZAP_NO_FLAGS; - s = select(zchan->sockfd + 1, r, w, e, tvp); - - if (s < 0) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "select: %s", strerror(errno)); - return ZAP_FAIL; - } - - if (s > 0) { - if (r && FD_ISSET(zchan->sockfd, r)) { - *flags |= ZAP_READ; - } - - if (w && FD_ISSET(zchan->sockfd, w)) { - *flags |= ZAP_WRITE; - } - - if (e && FD_ISSET(zchan->sockfd, e)) { - *flags |= ZAP_ERROR; - } - } - - if (s == 0) { - return ZAP_TIMEOUT; - } - - return ZAP_SUCCESS; -} - static ZINT_READ_FUNCTION(wanpipe_read_unix) { int rx_len = 0; @@ -596,6 +482,39 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) #endif +static ZINT_WAIT_FUNCTION(wanpipe_wait) +{ + zap_wait_flag_t inflags = *flags; + int result; + + result = tdmv_api_wait_socket(zchan->sockfd, 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 (result & POLLIN) { + *flags |= ZAP_READ; + } + + if (result & POLLOUT) { + *flags |= ZAP_WRITE; + } + + if (result & POLLPRI) { + *flags |= ZAP_ERROR; + } + + return ZAP_SUCCESS; +} + zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); @@ -607,12 +526,11 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.open = wanpipe_open; wanpipe_interface.close = wanpipe_close; wanpipe_interface.command = wanpipe_command; + wanpipe_interface.wait = wanpipe_wait; #ifdef __WINDOWS__ - wanpipe_interface.wait = wanpipe_wait_windows; wanpipe_interface.read = wanpipe_read_windows; wanpipe_interface.write = wanpipe_write_windows; #else - wanpipe_interface.wait = wanpipe_wait_unix; wanpipe_interface.read = wanpipe_read_unix; wanpipe_interface.write = wanpipe_write_unix; #endif From 3685804c98a07e3066dc8ac8a0a65021a0df6c7d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:46:09 +0000 Subject: [PATCH 0090/1766] implement the openzap wanpipe wait function using the cross platform poll from last commit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@45 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 150 ++++++++------------------------- 1 file changed, 34 insertions(+), 116 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 70f9ffefa5..6b351fb61f 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -313,57 +313,6 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) #ifdef __WINDOWS__ -static ZINT_WAIT_FUNCTION(wanpipe_wait_windows) -{ - API_POLL_STRUCT api_poll; - zap_wait_flag_t inflags = *flags; - - memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); - - api_poll.user_flags_bitmap = inflags; - api_poll.timeout = to; - - *flags = ZAP_NO_FLAGS; - - if(DoApiPollCommand(zchan->sockfd, &api_poll)){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); - return ZAP_FAIL; - } - - switch(api_poll.operation_status) - { - case SANG_STATUS_RX_DATA_AVAILABLE: - break; - - default: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown Operation Status: %d\n", api_poll.operation_status); - return ZAP_FAIL; - } - - if(api_poll.poll_events_bitmap == 0){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid Poll Events bitmap: 0x%X\n", api_poll.poll_events_bitmap); - return ZAP_FAIL; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { - return ZAP_TIMEOUT; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_RX_DATA) { - *flags |= ZAP_READ; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_TX_READY) { - *flags |= ZAP_WRITE; - } - - if (api_poll.poll_events_bitmap & POLL_EVENT_LINK_STATE) { - *flags |= ZAP_ERROR; - } - - return ZAP_SUCCESS; -} - static ZINT_READ_FUNCTION(wanpipe_read_windows) { zap_size_t rx_len = 0; @@ -465,69 +414,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_windows) #else -static ZINT_WAIT_FUNCTION(wanpipe_wait_unix) -{ - fd_set read_fds, write_fds, error_fds, *r = NULL, *w = NULL, *e = NULL; - zap_wait_flag_t inflags = *flags; - int s; - struct timeval tv, *tvp = NULL; - - if (to) { - memset(&tv, 0, sizeof(tv)); - tv.tv_sec = to / 1000; - tv.tv_usec = (to % 1000) * 1000; - tvp = &tv; - } - - FD_ZERO(&read_fds); - FD_ZERO(&write_fds); - FD_ZERO(&error_fds); - - - if (inflags & ZAP_READ) { - r = &read_fds; - FD_SET(zchan->sockfd, r); - } - - if (inflags & ZAP_WRITE) { - w = &write_fds; - FD_SET(zchan->sockfd, w); - } - - if (inflags & ZAP_ERROR) { - e = &error_fds; - FD_SET(zchan->sockfd, e); - } - - *flags = ZAP_NO_FLAGS; - s = select(zchan->sockfd + 1, r, w, e, tvp); - - if (s < 0) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "select: %s", strerror(errno)); - return ZAP_FAIL; - } - - if (s > 0) { - if (r && FD_ISSET(zchan->sockfd, r)) { - *flags |= ZAP_READ; - } - - if (w && FD_ISSET(zchan->sockfd, w)) { - *flags |= ZAP_WRITE; - } - - if (e && FD_ISSET(zchan->sockfd, e)) { - *flags |= ZAP_ERROR; - } - } - - if (s == 0) { - return ZAP_TIMEOUT; - } - - return ZAP_SUCCESS; -} - static ZINT_READ_FUNCTION(wanpipe_read_unix) { int rx_len = 0; @@ -596,6 +482,39 @@ static ZINT_WRITE_FUNCTION(wanpipe_write_unix) #endif +static ZINT_WAIT_FUNCTION(wanpipe_wait) +{ + zap_wait_flag_t inflags = *flags; + int result; + + result = tdmv_api_wait_socket(zchan->sockfd, 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 (result & POLLIN) { + *flags |= ZAP_READ; + } + + if (result & POLLOUT) { + *flags |= ZAP_WRITE; + } + + if (result & POLLPRI) { + *flags |= ZAP_ERROR; + } + + return ZAP_SUCCESS; +} + zap_status_t wanpipe_init(zap_software_interface_t **zint) { assert(zint != NULL); @@ -607,12 +526,11 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.open = wanpipe_open; wanpipe_interface.close = wanpipe_close; wanpipe_interface.command = wanpipe_command; + wanpipe_interface.wait = wanpipe_wait; #ifdef __WINDOWS__ - wanpipe_interface.wait = wanpipe_wait_windows; wanpipe_interface.read = wanpipe_read_windows; wanpipe_interface.write = wanpipe_write_windows; #else - wanpipe_interface.wait = wanpipe_wait_unix; wanpipe_interface.read = wanpipe_read_unix; wanpipe_interface.write = wanpipe_write_unix; #endif From 65cc17159c17e0ec04357877bea7e410a81b4358 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:47:37 +0000 Subject: [PATCH 0091/1766] use WP_INVALID_SOCKET for invalid handles. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@46 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index a2ede350c3..cbaa89f379 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -148,13 +148,13 @@ static sng_fd_t tdmv_api_open_span_chan(int span, int chan) void tdmv_api_close_socket(sng_fd_t *sp) { - if( *sp != INVALID_HANDLE_VALUE){ + if( *sp != WP_INVALID_SOCKET){ #if defined(__WINDOWS__) CloseHandle(*sp); #else close(*sp); #endif - *sp = INVALID_HANDLE_VALUE; + *sp = WP_INVALID_SOCKET; } } From 20c41323a72a5cc6417e46f525972900a820014f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:47:37 +0000 Subject: [PATCH 0092/1766] use WP_INVALID_SOCKET for invalid handles. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@46 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index a2ede350c3..cbaa89f379 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -148,13 +148,13 @@ static sng_fd_t tdmv_api_open_span_chan(int span, int chan) void tdmv_api_close_socket(sng_fd_t *sp) { - if( *sp != INVALID_HANDLE_VALUE){ + if( *sp != WP_INVALID_SOCKET){ #if defined(__WINDOWS__) CloseHandle(*sp); #else close(*sp); #endif - *sp = INVALID_HANDLE_VALUE; + *sp = WP_INVALID_SOCKET; } } From 4ad07a3d0529ac03dfbce57e804e6f40dd53183c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:48:46 +0000 Subject: [PATCH 0093/1766] missing header file. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@47 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index cbaa89f379..ddcae6ffa3 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -28,6 +28,7 @@ #else #define WP_INVALID_SOCKET -1 #include +#include #endif #include From 7c68876fc86daa94665be6e32954a128cb4b4a54 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:48:46 +0000 Subject: [PATCH 0094/1766] missing header file. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@47 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index cbaa89f379..ddcae6ffa3 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -28,6 +28,7 @@ #else #define WP_INVALID_SOCKET -1 #include +#include #endif #include From 0b334f6c681a15f581282480b6234f3dc22313af Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:51:40 +0000 Subject: [PATCH 0095/1766] need to pass in pointer. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@48 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 6b351fb61f..fc7142dc48 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -551,7 +551,7 @@ zap_status_t wanpipe_destroy(void) zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - tdmv_api_close_socket(cur_chan->sockfd); + tdmv_api_close_socket(&cur_chan->sockfd); } } } From 42f8586ab1c0903f9866e62d03b322b96fe843e2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:51:40 +0000 Subject: [PATCH 0096/1766] need to pass in pointer. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@48 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 6b351fb61f..fc7142dc48 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -551,7 +551,7 @@ zap_status_t wanpipe_destroy(void) zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - tdmv_api_close_socket(cur_chan->sockfd); + tdmv_api_close_socket(&cur_chan->sockfd); } } } From 7b34a53f9f75f5807d3e1d28727983df76e8a142 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:59:51 +0000 Subject: [PATCH 0097/1766] cleanup, eliminate some global variables. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@49 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index ddcae6ffa3..fcd18cfa6b 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -42,25 +42,11 @@ #include #define FNAME_LEN 50 -#define DEV_NAME_LEN 100 -char device_name[DEV_NAME_LEN]; - - -#ifdef __WINDOWS__ - -/* IOCTL management structures and variables*/ -wan_udp_hdr_t wan_udp; - -static wan_cmd_api_t api_cmd; -static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; - -/* keeps the LAST (and single) event received */ -static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; -#endif #ifdef __WINDOWS__ static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) { + wan_udp_hdr_t wan_udp; DWORD ln; unsigned char id = 0; int err = 0; @@ -135,7 +121,7 @@ static sng_fd_t tdmv_api_open_span_chan(int span, int chan) #else int fd = WP_INVALID_SOCKET; - sprintf(fname,"/dev/wptdm_s%dc%d",span,chan); + snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); fd = open(fname, O_RDWR); @@ -160,6 +146,7 @@ void tdmv_api_close_socket(sng_fd_t *sp) } #ifdef __WINDOWS__ +#if 0 static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) { DWORD ln; @@ -204,7 +191,7 @@ static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) sizeof(wan_cmd_api_t)); return 0; } - +#endif // Blocking read command. If used after DoApiPollCommand(), // it will return immediatly, without blocking. static From 119b53dbb8b1a916378da82bb02ef6401632f2a0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 05:59:51 +0000 Subject: [PATCH 0098/1766] cleanup, eliminate some global variables. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@49 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index ddcae6ffa3..fcd18cfa6b 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -42,25 +42,11 @@ #include #define FNAME_LEN 50 -#define DEV_NAME_LEN 100 -char device_name[DEV_NAME_LEN]; - - -#ifdef __WINDOWS__ - -/* IOCTL management structures and variables*/ -wan_udp_hdr_t wan_udp; - -static wan_cmd_api_t api_cmd; -static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data; - -/* keeps the LAST (and single) event received */ -static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer; -#endif #ifdef __WINDOWS__ static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) { + wan_udp_hdr_t wan_udp; DWORD ln; unsigned char id = 0; int err = 0; @@ -135,7 +121,7 @@ static sng_fd_t tdmv_api_open_span_chan(int span, int chan) #else int fd = WP_INVALID_SOCKET; - sprintf(fname,"/dev/wptdm_s%dc%d",span,chan); + snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); fd = open(fname, O_RDWR); @@ -160,6 +146,7 @@ void tdmv_api_close_socket(sng_fd_t *sp) } #ifdef __WINDOWS__ +#if 0 static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) { DWORD ln; @@ -204,7 +191,7 @@ static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) sizeof(wan_cmd_api_t)); return 0; } - +#endif // Blocking read command. If used after DoApiPollCommand(), // it will return immediatly, without blocking. static From d3efe9d8dd6a8db20d97fc9ee5b087b696295ceb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 06:26:05 +0000 Subject: [PATCH 0099/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@50 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 236 +-------------------- 1 file changed, 10 insertions(+), 226 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index fcd18cfa6b..0d3f14da96 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -146,52 +146,7 @@ void tdmv_api_close_socket(sng_fd_t *sp) } #ifdef __WINDOWS__ -#if 0 -static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) -{ - DWORD ln; - unsigned char id = 0; - int err = 0; - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; - wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); - - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)api_cmd, - sizeof(wan_cmd_api_t)); - - if(DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - err = 1; - return err; - }else{ - err = 0; - } - - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - return 2; - } - - //copy data from driver's buffer to caller's buffer - memcpy( (void*)api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wan_cmd_api_t)); - return 0; -} -#endif // Blocking read command. If used after DoApiPollCommand(), // it will return immediatly, without blocking. static @@ -247,186 +202,6 @@ DoWriteCommand( } } -// Blocking API Poll command. -static -USHORT -DoApiPollCommand( - sng_fd_t drv, - API_POLL_STRUCT *api_poll_ptr - ) -{ - DWORD ln; - - if (DeviceIoControl( - drv, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)api_poll_ptr, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -static -int -DoManagementCommand( - sng_fd_t drv, - wan_udp_hdr_t* wan_udp - ) -{ - DWORD ln; - static unsigned char id = 0; - - wan_udp->wan_udphdr_request_reply = 0x01; - wan_udp->wan_udphdr_id = id++; - wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - if(DeviceIoControl( - drv, - IoctlManagementCommand, - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -/////////////////////////////////////////////////////////////////////////// -// -//structures and definitions used for queueing data -// -typedef struct -{ - void* previous; - TX_RX_DATA_STRUCT tx_rx_data; -}api_queue_element_t; - -#define API_Q_MUTEX_TIMEOUT 1000//1 second -#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue - -enum API_Q_STATUS{ - API_Q_SUCCESS=0, - API_Q_GEN_FAILURE, - API_Q_MEM_ALLOC_FAILURE, - API_Q_FULL, - API_Q_EMPTY -}; - -typedef struct -{ - //number of nodes in the list - USHORT size; - //insert at tail - api_queue_element_t * tail; - //remove from head - api_queue_element_t * head; - //mutex for synchronizing access to the queue - sng_fd_t api_queue_mutex; -}api_queue_t; - - -static __inline int api_enqueue( api_queue_t* api_queue, - unsigned char * buffer, - unsigned short length) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == API_Q_MAX_SIZE){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_FULL; - } - - element = malloc(sizeof(api_queue_element_t)); - if(element == NULL){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_MEM_ALLOC_FAILURE; - } - - //now copy everything in to the element - memcpy(element->tx_rx_data.data, buffer, length); - - element->tx_rx_data.api_header.data_length = length; - element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; - - //insert element at the tail of the queue - element->previous = NULL; - - if(api_queue->size == 0){ - //special case of a previously empty queue - api_queue->head = element; - api_queue->tail = element; - }else{ - api_queue->tail->previous = element; - api_queue->tail = element; - } - api_queue->size++; - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -static __inline int api_dequeue( api_queue_t* api_queue, - TX_RX_DATA_STRUCT* destination) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == 0){ - //tx queue is empty - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_EMPTY; - } - - //remove from the head of the queue - element = api_queue->head; - api_queue->head = element->previous; - - //now copy everything in to the user buffer - memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); - - free(element); - api_queue->size--; - if(api_queue->size == 0){ - api_queue->head = NULL; - api_queue->tail = NULL; - } - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -//remove all elements from the queue -static __inline void empty_api_queue(api_queue_t* api_queue) -{ - TX_DATA_STRUCT tx_rx_data; - - while(api_dequeue(api_queue, &tx_rx_data) == 0){ - ; - } -} - -/////////////////////////////////////////////////////////////////////////// #endif #if defined(__WINDOWS__) @@ -438,6 +213,7 @@ static __inline void empty_api_queue(api_queue_t* api_queue) 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)); @@ -445,7 +221,15 @@ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) api_poll.user_flags_bitmap = flags; api_poll.timeout = timeout; - if(DoApiPollCommand(fd, &api_poll)) { + if (!DeviceIoControl( + fd, + IoctlApiPoll, + (LPVOID)NULL, + 0L, + (LPVOID)&api_poll, + sizeof(API_POLL_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL)) { return -1; } From 12a9ba1af0b7a8320e2f0134ef20854138763889 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 06:26:05 +0000 Subject: [PATCH 0100/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@50 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 236 +-------------------- 1 file changed, 10 insertions(+), 226 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index fcd18cfa6b..0d3f14da96 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -146,52 +146,7 @@ void tdmv_api_close_socket(sng_fd_t *sp) } #ifdef __WINDOWS__ -#if 0 -static int wanpipe_api_ioctl(sng_fd_t fd, wan_cmd_api_t *api_cmd) -{ - DWORD ln; - unsigned char id = 0; - int err = 0; - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = SIOC_WANPIPE_API; - wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t); - - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)api_cmd, - sizeof(wan_cmd_api_t)); - - if(DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - err = 1; - return err; - }else{ - err = 0; - } - - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - return 2; - } - - //copy data from driver's buffer to caller's buffer - memcpy( (void*)api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wan_cmd_api_t)); - return 0; -} -#endif // Blocking read command. If used after DoApiPollCommand(), // it will return immediatly, without blocking. static @@ -247,186 +202,6 @@ DoWriteCommand( } } -// Blocking API Poll command. -static -USHORT -DoApiPollCommand( - sng_fd_t drv, - API_POLL_STRUCT *api_poll_ptr - ) -{ - DWORD ln; - - if (DeviceIoControl( - drv, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)api_poll_ptr, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -static -int -DoManagementCommand( - sng_fd_t drv, - wan_udp_hdr_t* wan_udp - ) -{ - DWORD ln; - static unsigned char id = 0; - - wan_udp->wan_udphdr_request_reply = 0x01; - wan_udp->wan_udphdr_id = id++; - wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - if(DeviceIoControl( - drv, - IoctlManagementCommand, - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; - } -} - -/////////////////////////////////////////////////////////////////////////// -// -//structures and definitions used for queueing data -// -typedef struct -{ - void* previous; - TX_RX_DATA_STRUCT tx_rx_data; -}api_queue_element_t; - -#define API_Q_MUTEX_TIMEOUT 1000//1 second -#define API_Q_MAX_SIZE 100//optimal length. for short data may need longer queue - -enum API_Q_STATUS{ - API_Q_SUCCESS=0, - API_Q_GEN_FAILURE, - API_Q_MEM_ALLOC_FAILURE, - API_Q_FULL, - API_Q_EMPTY -}; - -typedef struct -{ - //number of nodes in the list - USHORT size; - //insert at tail - api_queue_element_t * tail; - //remove from head - api_queue_element_t * head; - //mutex for synchronizing access to the queue - sng_fd_t api_queue_mutex; -}api_queue_t; - - -static __inline int api_enqueue( api_queue_t* api_queue, - unsigned char * buffer, - unsigned short length) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == API_Q_MAX_SIZE){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_FULL; - } - - element = malloc(sizeof(api_queue_element_t)); - if(element == NULL){ - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_MEM_ALLOC_FAILURE; - } - - //now copy everything in to the element - memcpy(element->tx_rx_data.data, buffer, length); - - element->tx_rx_data.api_header.data_length = length; - element->tx_rx_data.api_header.operation_status = SANG_STATUS_TX_TIMEOUT; - - //insert element at the tail of the queue - element->previous = NULL; - - if(api_queue->size == 0){ - //special case of a previously empty queue - api_queue->head = element; - api_queue->tail = element; - }else{ - api_queue->tail->previous = element; - api_queue->tail = element; - } - api_queue->size++; - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -static __inline int api_dequeue( api_queue_t* api_queue, - TX_RX_DATA_STRUCT* destination) -{ - api_queue_element_t *element; - DWORD mresult; - - mresult = WaitForSingleObject(api_queue->api_queue_mutex, API_Q_MUTEX_TIMEOUT); - if (mresult != WAIT_OBJECT_0) { - return API_Q_GEN_FAILURE; - } - - if(api_queue->size == 0){ - //tx queue is empty - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_EMPTY; - } - - //remove from the head of the queue - element = api_queue->head; - api_queue->head = element->previous; - - //now copy everything in to the user buffer - memcpy(destination, &element->tx_rx_data, sizeof(TX_DATA_STRUCT)); - - free(element); - api_queue->size--; - if(api_queue->size == 0){ - api_queue->head = NULL; - api_queue->tail = NULL; - } - ReleaseMutex(api_queue->api_queue_mutex); - return API_Q_SUCCESS; -} - -//remove all elements from the queue -static __inline void empty_api_queue(api_queue_t* api_queue) -{ - TX_DATA_STRUCT tx_rx_data; - - while(api_dequeue(api_queue, &tx_rx_data) == 0){ - ; - } -} - -/////////////////////////////////////////////////////////////////////////// #endif #if defined(__WINDOWS__) @@ -438,6 +213,7 @@ static __inline void empty_api_queue(api_queue_t* api_queue) 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)); @@ -445,7 +221,15 @@ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) api_poll.user_flags_bitmap = flags; api_poll.timeout = timeout; - if(DoApiPollCommand(fd, &api_poll)) { + if (!DeviceIoControl( + fd, + IoctlApiPoll, + (LPVOID)NULL, + 0L, + (LPVOID)&api_poll, + sizeof(API_POLL_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL)) { return -1; } From f0834d471c8d4dc0a692ef0b1621df4a1f7b9d6a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 10:30:51 +0000 Subject: [PATCH 0101/1766] implementations for the cross platform read and write in sangoma_tdm_api.h. move zap_wanpipe.c to use the read and write from sangoma_tdm_api.h. cleanups and lots of comments added to sangoma_tdm_api.h some fixes to sangoma_tdm_api.h to make the api more consistent between windows and nix. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@51 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 375 ++++++++++++++------- libs/openzap/src/zap_wanpipe.c | 162 +-------- 2 files changed, 271 insertions(+), 266 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 0d3f14da96..a795507c92 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -1,9 +1,14 @@ /***************************************************************************** - * sangoma_tdm_api.h Sangoma API Code Library + * sangoma_tdm_api.h Sangoma TDM API Portability functions * - * Author(s): David Rokhvarg + * Author(s): Anthony Minessale II + * Nenad Corbic + * Michael Jerris + * David Rokhvarg * - * Copyright: (c) 1984-2006 Sangoma Technologies Inc. + * Copyright: (c) 2006 Nenad Corbic + * Anthony Minessale II + * (c) 1984-2007 Sangoma Technologies Inc. * * ============================================================================ */ @@ -11,21 +16,59 @@ #ifndef _SANGOMA_TDM_API_H #define _SANGOMA_TDM_API_H +/* This entire block of defines and includes from this line, through #define FNAME_LEN probably dont belong here */ +/* most of them probably belong in wanpipe_defines.h, then each header file listed included below properly included */ +/* in the header files that depend on them, leaving only the include for wanpipe_tdm_api.h left in this file or */ +/* possibly integrating the rest of this file diretly into wanpipe_tdm_api.h */ #ifndef __WINDOWS__ #if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) #define __WINDOWS__ -#endif -#endif +#endif /* defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) */ +#endif /* ndef __WINDOWS__ */ -#ifdef __WINDOWS__ -#ifdef _MSC_VER -/* disable warning for zero length array in a struct */ -/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4200 4201 4214) -#endif +#if defined(__WINDOWS__) +#if defined(_MSC_VER) +/* disable some warnings caused by wanpipe headers that will need to be fixed in those headers */ +#pragma warning(disable:4201 4214) + +/* sang_api.h(74) : warning C4201: nonstandard extension used : nameless struct/union */ + +/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ +/* wanpipe_defines.h(220) : warning C4214: nonstandard extension used : bit field types other than int */ +/* this will break for any compilers that are strict ansi or strict c99 */ + +/* The following definition for that struct should resolve this warning and work for 32 and 64 bit */ +#if 0 +struct iphdr { + +#if defined(__LITTLE_ENDIAN_BITFIELD) + unsigned ihl:4, + version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + unsigned version:4, + ihl:4; +#else +# error "unknown byteorder!" +#endif + unsigned tos:8; + unsigned tot_len:16; + unsigned id:16; + unsigned frag_off:16; + __u8 ttl; + __u8 protocol; + __u16 check; + __u32 saddr; + __u32 daddr; + /*The options start here. */ +}; +#endif /* #if 0 */ + +#define __inline__ __inline +#endif /* defined(_MSC_VER) */ #include +/* do we like the name WP_INVALID_SOCKET or should it be changed? */ #define WP_INVALID_SOCKET INVALID_HANDLE_VALUE -#else +#else /* defined(__WINDOWS__) */ #define WP_INVALID_SOCKET -1 #include #include @@ -43,13 +86,16 @@ #define FNAME_LEN 50 +/* what should the returns from this function be?? */ +/* I dont think they are currently consistant between windows and *nix */ #ifdef __WINDOWS__ -static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) { + /* can we make the structure passed for this on nix and windows the same */ + /* so we don't have to do the extra 2 memcpy's on windows for this ? */ wan_udp_hdr_t wan_udp; DWORD ln; unsigned char id = 0; - int err = 0; wan_udp.wan_udphdr_request_reply = 0x01; wan_udp.wan_udphdr_id = id; @@ -58,10 +104,7 @@ static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)tdm_api_cmd, - sizeof(wanpipe_tdm_api_cmd_t)); + memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); if(DeviceIoControl( fd, @@ -73,67 +116,25 @@ static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) (LPDWORD)(&ln), (LPOVERLAPPED)NULL ) == FALSE){ - //actual ioctl failed - err = 1; - return err; - }else{ - err = 0; + return 1; } if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - //ioctl ok, but command failed return 2; } - //copy data from driver's buffer to caller's buffer - memcpy( (void*)tdm_api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wanpipe_tdm_api_cmd_t)); + memcpy( (void*)tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t)); return 0; } #else -static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) { return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); } #endif -static sng_fd_t tdmv_api_open_span_chan(int span, int chan) -{ - char fname[FNAME_LEN]; -#if defined(__WINDOWS__) - - //NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. - // Subtract 1 from 'chan'. - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - //prn(verbose, "Opening device: %s...\n", fname); - - return CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); -#else - int fd = WP_INVALID_SOCKET; - - snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - - return fd; -#endif -} - -void tdmv_api_close_socket(sng_fd_t *sp) +void __inline__ tdmv_api_close_socket(sng_fd_t *sp) { if( *sp != WP_INVALID_SOCKET){ #if defined(__WINDOWS__) @@ -145,72 +146,78 @@ void tdmv_api_close_socket(sng_fd_t *sp) } } -#ifdef __WINDOWS__ - -// Blocking read command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -USHORT -DoReadCommand( - sng_fd_t drv, - RX_DATA_STRUCT * pRx - ) +static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) { - DWORD ln; + char fname[FNAME_LEN]; + sng_fd_t fd = WP_INVALID_SOCKET; +#if defined(__WINDOWS__) + DWORD ln; + wan_udp_hdr_t wan_udp; - if (DeviceIoControl( - drv, - IoctlReadCommand, - (LPVOID)NULL, - 0L, - (LPVOID)pRx, - sizeof(RX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - //check messages log - return 1; - }else{ - return 0; + /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ + /* Subtract 1 from 'chan'. */ + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + fd = CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); + + /* make sure that we are the only ones who have this chan open */ + /* is this a threadsafe way to make sure that we are ok and will */ + /* never return a valid handle to more than one thread for the same channel? */ + + wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; + wan_udp.wan_udphdr_data_len = 0; + + DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ); + + if((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ + /* somone already has this channel, or somthing else is not right. */ + tdmv_api_close_socket(&fd); } -} -// Blocking write command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -UCHAR -DoWriteCommand( - sng_fd_t drv, - TX_DATA_STRUCT * pTx - ) -{ - DWORD ln; +#else + /* Does this fail if another thread already has this chan open? */ + /* if not, we need to add some code to make sure it does */ + snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - if(DeviceIoControl( - drv, - IoctlWriteCommand, - (LPVOID)pTx, - (ULONG)sizeof(TX_DATA_STRUCT), - (LPVOID)pTx, - sizeof(TX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; + fd = open(fname, O_RDWR); + + if (fd < 0) { + fd = WP_INVALID_SOCKET; } -} #endif + return fd; +} #if defined(__WINDOWS__) -/* This is broken, we don't actually get real results for oob messages on 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 POLLIN | POLLOUT | POLLPRI based on the result of the poll */ -int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) +/* 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; @@ -279,4 +286,140 @@ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) #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 */ diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index fc7142dc48..013da15be5 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -311,135 +311,15 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) return ZAP_SUCCESS; } -#ifdef __WINDOWS__ - -static ZINT_READ_FUNCTION(wanpipe_read_windows) -{ - zap_size_t rx_len = 0; - zap_status_t status = ZAP_FAIL; - - /* should we just pass in abuffer big enough in the first place instead of having to use rx_data and memcpy here? */ - static RX_DATA_STRUCT rx_data; - - if(DoReadCommand(zchan->sockfd, &rx_data)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoReadCommand() failed! Check messages log.\n"); - goto done; - } - - switch(rx_data.api_header.operation_status) - { - case SANG_STATUS_RX_DATA_AVAILABLE: - if(rx_data.api_header.data_length > *datalen){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "Buffer overrun.\n"); - break; - } - memcpy(data, rx_data.data, rx_data.api_header.data_length); - rx_len = rx_data.api_header.data_length; - status = ZAP_SUCCESS; - break; - - case SANG_STATUS_TDM_EVENT_AVAILABLE: - memcpy(data, rx_data.data, rx_data.api_header.data_length); - rx_len = rx_data.api_header.data_length; - status = ZAP_SUCCESS; - break; - - case SANG_STATUS_RX_DATA_TIMEOUT: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Timeout on read.\n"); - break; - - case SANG_STATUS_BUFFER_TOO_SMALL: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Received data longer than buffer passed to API.\n"); - break; - - case SANG_STATUS_LINE_DISCONNECTED: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Line disconnected.\n"); - break; - - default: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Rx:Unknown Operation Status: %d\n", rx_data.api_header.operation_status); - break; - } - -done: - *datalen = rx_len; - return status; -} - -static ZINT_WRITE_FUNCTION(wanpipe_write_windows) -{ - static TX_DATA_STRUCT local_tx_data; - - /* why don't we just provide the big enough buffer to start with so we can avoid the memcpy ? */ - memcpy(local_tx_data.data, data, *datalen); - - /* queue data for transmission */ - if(DoWriteCommand(zchan->sockfd, &local_tx_data)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoWriteCommand() failed!! Check messages log.\n"); - *datalen = 0; - return ZAP_FAIL; - } - - if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { - return ZAP_SUCCESS; - } - - *datalen = 0; - - switch(local_tx_data.api_header.operation_status) - { - case SANG_STATUS_TX_TIMEOUT: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** Error: SANG_STATUS_TX_TIMEOUT ******\n"); - break; - - case SANG_STATUS_TX_DATA_TOO_LONG: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n"); - break; - - case SANG_STATUS_TX_DATA_TOO_SHORT: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n"); - break; - - case SANG_STATUS_LINE_DISCONNECTED: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_LINE_DISCONNECTED ******\n"); - break; - - default: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown return code (0x%X) on transmission!\n", local_tx_data.api_header.operation_status); - break; - } - - return ZAP_FAIL; -} - -#else - -static ZINT_READ_FUNCTION(wanpipe_read_unix) +static ZINT_READ_FUNCTION(wanpipe_read) { int rx_len = 0; - struct msghdr msg; - struct iovec iov[2]; wp_tdm_api_rx_hdr_t hdrframe; - memset(&msg, 0, sizeof(msg)); memset(&hdrframe, 0, sizeof(hdrframe)); - memset(iov, 0, sizeof(iov[0])*2); - iov[0].iov_len = sizeof(hdrframe); - iov[0].iov_base = &hdrframe; + rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); - iov[1].iov_len = *datalen; - iov[1].iov_base = data; - - msg.msg_iovlen = 2; - msg.msg_iov = iov; - - rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); - - if (rx_len > 0) { - rx_len -= sizeof(hdrframe); - } - *datalen = rx_len; if (rx_len <= 0) { @@ -450,37 +330,24 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) return ZAP_SUCCESS; } -static ZINT_WRITE_FUNCTION(wanpipe_write_unix) +static ZINT_WRITE_FUNCTION(wanpipe_write) { int bsent; - struct msghdr msg; - struct iovec iov[2]; wp_tdm_api_tx_hdr_t hdrframe; - memset(&msg, 0, sizeof(msg)); + /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ memset(&hdrframe, 0, sizeof(hdrframe)); - memset(iov, 0, sizeof(iov[0])*2); - - iov[0].iov_len = sizeof(hdrframe); - iov[0].iov_base = &hdrframe; + bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); - iov[1].iov_len = *datalen; - iov[1].iov_base = data; - - msg.msg_iovlen = 2; - msg.msg_iov = iov; - bsent = write(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); - - if (bsent > 0){ - bsent -= sizeof(wp_tdm_api_tx_hdr_t); + /* should we be checking if bsent == *datalen here? */ + if (bsent > 0) { + *datalen = bsent; + return ZAP_SUCCESS; } - *datalen = bsent; - - return ZAP_SUCCESS; + return ZAP_FAIL; } -#endif static ZINT_WAIT_FUNCTION(wanpipe_wait) { @@ -527,13 +394,8 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.close = wanpipe_close; wanpipe_interface.command = wanpipe_command; wanpipe_interface.wait = wanpipe_wait; -#ifdef __WINDOWS__ - wanpipe_interface.read = wanpipe_read_windows; - wanpipe_interface.write = wanpipe_write_windows; -#else - wanpipe_interface.read = wanpipe_read_unix; - wanpipe_interface.write = wanpipe_write_unix; -#endif + wanpipe_interface.read = wanpipe_read; + wanpipe_interface.write = wanpipe_write; *zint = &wanpipe_interface; return ZAP_SUCCESS; From 7a96481d0980cd26a6992fffd161e96643ceb31c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 10:30:51 +0000 Subject: [PATCH 0102/1766] implementations for the cross platform read and write in sangoma_tdm_api.h. move zap_wanpipe.c to use the read and write from sangoma_tdm_api.h. cleanups and lots of comments added to sangoma_tdm_api.h some fixes to sangoma_tdm_api.h to make the api more consistent between windows and nix. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@51 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 375 ++++++++++++++------- libs/freetdm/src/zap_wanpipe.c | 162 +-------- 2 files changed, 271 insertions(+), 266 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index 0d3f14da96..a795507c92 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -1,9 +1,14 @@ /***************************************************************************** - * sangoma_tdm_api.h Sangoma API Code Library + * sangoma_tdm_api.h Sangoma TDM API Portability functions * - * Author(s): David Rokhvarg + * Author(s): Anthony Minessale II + * Nenad Corbic + * Michael Jerris + * David Rokhvarg * - * Copyright: (c) 1984-2006 Sangoma Technologies Inc. + * Copyright: (c) 2006 Nenad Corbic + * Anthony Minessale II + * (c) 1984-2007 Sangoma Technologies Inc. * * ============================================================================ */ @@ -11,21 +16,59 @@ #ifndef _SANGOMA_TDM_API_H #define _SANGOMA_TDM_API_H +/* This entire block of defines and includes from this line, through #define FNAME_LEN probably dont belong here */ +/* most of them probably belong in wanpipe_defines.h, then each header file listed included below properly included */ +/* in the header files that depend on them, leaving only the include for wanpipe_tdm_api.h left in this file or */ +/* possibly integrating the rest of this file diretly into wanpipe_tdm_api.h */ #ifndef __WINDOWS__ #if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) #define __WINDOWS__ -#endif -#endif +#endif /* defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) */ +#endif /* ndef __WINDOWS__ */ -#ifdef __WINDOWS__ -#ifdef _MSC_VER -/* disable warning for zero length array in a struct */ -/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4200 4201 4214) -#endif +#if defined(__WINDOWS__) +#if defined(_MSC_VER) +/* disable some warnings caused by wanpipe headers that will need to be fixed in those headers */ +#pragma warning(disable:4201 4214) + +/* sang_api.h(74) : warning C4201: nonstandard extension used : nameless struct/union */ + +/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ +/* wanpipe_defines.h(220) : warning C4214: nonstandard extension used : bit field types other than int */ +/* this will break for any compilers that are strict ansi or strict c99 */ + +/* The following definition for that struct should resolve this warning and work for 32 and 64 bit */ +#if 0 +struct iphdr { + +#if defined(__LITTLE_ENDIAN_BITFIELD) + unsigned ihl:4, + version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + unsigned version:4, + ihl:4; +#else +# error "unknown byteorder!" +#endif + unsigned tos:8; + unsigned tot_len:16; + unsigned id:16; + unsigned frag_off:16; + __u8 ttl; + __u8 protocol; + __u16 check; + __u32 saddr; + __u32 daddr; + /*The options start here. */ +}; +#endif /* #if 0 */ + +#define __inline__ __inline +#endif /* defined(_MSC_VER) */ #include +/* do we like the name WP_INVALID_SOCKET or should it be changed? */ #define WP_INVALID_SOCKET INVALID_HANDLE_VALUE -#else +#else /* defined(__WINDOWS__) */ #define WP_INVALID_SOCKET -1 #include #include @@ -43,13 +86,16 @@ #define FNAME_LEN 50 +/* what should the returns from this function be?? */ +/* I dont think they are currently consistant between windows and *nix */ #ifdef __WINDOWS__ -static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) { + /* can we make the structure passed for this on nix and windows the same */ + /* so we don't have to do the extra 2 memcpy's on windows for this ? */ wan_udp_hdr_t wan_udp; DWORD ln; unsigned char id = 0; - int err = 0; wan_udp.wan_udphdr_request_reply = 0x01; wan_udp.wan_udphdr_id = id; @@ -58,10 +104,7 @@ static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); - //copy data from caller's buffer to driver's buffer - memcpy( wan_udp.wan_udphdr_data, - (void*)tdm_api_cmd, - sizeof(wanpipe_tdm_api_cmd_t)); + memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); if(DeviceIoControl( fd, @@ -73,67 +116,25 @@ static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) (LPDWORD)(&ln), (LPOVERLAPPED)NULL ) == FALSE){ - //actual ioctl failed - err = 1; - return err; - }else{ - err = 0; + return 1; } if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - //ioctl ok, but command failed return 2; } - //copy data from driver's buffer to caller's buffer - memcpy( (void*)tdm_api_cmd, - wan_udp.wan_udphdr_data, - sizeof(wanpipe_tdm_api_cmd_t)); + memcpy( (void*)tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t)); return 0; } #else -static int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) { return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); } #endif -static sng_fd_t tdmv_api_open_span_chan(int span, int chan) -{ - char fname[FNAME_LEN]; -#if defined(__WINDOWS__) - - //NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. - // Subtract 1 from 'chan'. - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - //prn(verbose, "Opening device: %s...\n", fname); - - return CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); -#else - int fd = WP_INVALID_SOCKET; - - snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - - return fd; -#endif -} - -void tdmv_api_close_socket(sng_fd_t *sp) +void __inline__ tdmv_api_close_socket(sng_fd_t *sp) { if( *sp != WP_INVALID_SOCKET){ #if defined(__WINDOWS__) @@ -145,72 +146,78 @@ void tdmv_api_close_socket(sng_fd_t *sp) } } -#ifdef __WINDOWS__ - -// Blocking read command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -USHORT -DoReadCommand( - sng_fd_t drv, - RX_DATA_STRUCT * pRx - ) +static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) { - DWORD ln; + char fname[FNAME_LEN]; + sng_fd_t fd = WP_INVALID_SOCKET; +#if defined(__WINDOWS__) + DWORD ln; + wan_udp_hdr_t wan_udp; - if (DeviceIoControl( - drv, - IoctlReadCommand, - (LPVOID)NULL, - 0L, - (LPVOID)pRx, - sizeof(RX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - //check messages log - return 1; - }else{ - return 0; + /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ + /* Subtract 1 from 'chan'. */ + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + fd = CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); + + /* make sure that we are the only ones who have this chan open */ + /* is this a threadsafe way to make sure that we are ok and will */ + /* never return a valid handle to more than one thread for the same channel? */ + + wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; + wan_udp.wan_udphdr_data_len = 0; + + DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ); + + if((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ + /* somone already has this channel, or somthing else is not right. */ + tdmv_api_close_socket(&fd); } -} -// Blocking write command. If used after DoApiPollCommand(), -// it will return immediatly, without blocking. -static -UCHAR -DoWriteCommand( - sng_fd_t drv, - TX_DATA_STRUCT * pTx - ) -{ - DWORD ln; +#else + /* Does this fail if another thread already has this chan open? */ + /* if not, we need to add some code to make sure it does */ + snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - if(DeviceIoControl( - drv, - IoctlWriteCommand, - (LPVOID)pTx, - (ULONG)sizeof(TX_DATA_STRUCT), - (LPVOID)pTx, - sizeof(TX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - }else{ - return 0; + fd = open(fname, O_RDWR); + + if (fd < 0) { + fd = WP_INVALID_SOCKET; } -} #endif + return fd; +} #if defined(__WINDOWS__) -/* This is broken, we don't actually get real results for oob messages on 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 POLLIN | POLLOUT | POLLPRI based on the result of the poll */ -int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) +/* 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; @@ -279,4 +286,140 @@ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) #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 */ diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index fc7142dc48..013da15be5 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -311,135 +311,15 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) return ZAP_SUCCESS; } -#ifdef __WINDOWS__ - -static ZINT_READ_FUNCTION(wanpipe_read_windows) -{ - zap_size_t rx_len = 0; - zap_status_t status = ZAP_FAIL; - - /* should we just pass in abuffer big enough in the first place instead of having to use rx_data and memcpy here? */ - static RX_DATA_STRUCT rx_data; - - if(DoReadCommand(zchan->sockfd, &rx_data)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoReadCommand() failed! Check messages log.\n"); - goto done; - } - - switch(rx_data.api_header.operation_status) - { - case SANG_STATUS_RX_DATA_AVAILABLE: - if(rx_data.api_header.data_length > *datalen){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "Buffer overrun.\n"); - break; - } - memcpy(data, rx_data.data, rx_data.api_header.data_length); - rx_len = rx_data.api_header.data_length; - status = ZAP_SUCCESS; - break; - - case SANG_STATUS_TDM_EVENT_AVAILABLE: - memcpy(data, rx_data.data, rx_data.api_header.data_length); - rx_len = rx_data.api_header.data_length; - status = ZAP_SUCCESS; - break; - - case SANG_STATUS_RX_DATA_TIMEOUT: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Timeout on read.\n"); - break; - - case SANG_STATUS_BUFFER_TOO_SMALL: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Received data longer than buffer passed to API.\n"); - break; - - case SANG_STATUS_LINE_DISCONNECTED: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: Line disconnected.\n"); - break; - - default: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Rx:Unknown Operation Status: %d\n", rx_data.api_header.operation_status); - break; - } - -done: - *datalen = rx_len; - return status; -} - -static ZINT_WRITE_FUNCTION(wanpipe_write_windows) -{ - static TX_DATA_STRUCT local_tx_data; - - /* why don't we just provide the big enough buffer to start with so we can avoid the memcpy ? */ - memcpy(local_tx_data.data, data, *datalen); - - /* queue data for transmission */ - if(DoWriteCommand(zchan->sockfd, &local_tx_data)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Error: DoWriteCommand() failed!! Check messages log.\n"); - *datalen = 0; - return ZAP_FAIL; - } - - if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { - return ZAP_SUCCESS; - } - - *datalen = 0; - - switch(local_tx_data.api_header.operation_status) - { - case SANG_STATUS_TX_TIMEOUT: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** Error: SANG_STATUS_TX_TIMEOUT ******\n"); - break; - - case SANG_STATUS_TX_DATA_TOO_LONG: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n"); - break; - - case SANG_STATUS_TX_DATA_TOO_SHORT: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n"); - break; - - case SANG_STATUS_LINE_DISCONNECTED: - snprintf(zchan->last_error, sizeof(zchan->last_error), "****** SANG_STATUS_LINE_DISCONNECTED ******\n"); - break; - - default: - snprintf(zchan->last_error, sizeof(zchan->last_error), "Unknown return code (0x%X) on transmission!\n", local_tx_data.api_header.operation_status); - break; - } - - return ZAP_FAIL; -} - -#else - -static ZINT_READ_FUNCTION(wanpipe_read_unix) +static ZINT_READ_FUNCTION(wanpipe_read) { int rx_len = 0; - struct msghdr msg; - struct iovec iov[2]; wp_tdm_api_rx_hdr_t hdrframe; - memset(&msg, 0, sizeof(msg)); memset(&hdrframe, 0, sizeof(hdrframe)); - memset(iov, 0, sizeof(iov[0])*2); - iov[0].iov_len = sizeof(hdrframe); - iov[0].iov_base = &hdrframe; + rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); - iov[1].iov_len = *datalen; - iov[1].iov_base = data; - - msg.msg_iovlen = 2; - msg.msg_iov = iov; - - rx_len = read(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); - - if (rx_len > 0) { - rx_len -= sizeof(hdrframe); - } - *datalen = rx_len; if (rx_len <= 0) { @@ -450,37 +330,24 @@ static ZINT_READ_FUNCTION(wanpipe_read_unix) return ZAP_SUCCESS; } -static ZINT_WRITE_FUNCTION(wanpipe_write_unix) +static ZINT_WRITE_FUNCTION(wanpipe_write) { int bsent; - struct msghdr msg; - struct iovec iov[2]; wp_tdm_api_tx_hdr_t hdrframe; - memset(&msg, 0, sizeof(msg)); + /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ memset(&hdrframe, 0, sizeof(hdrframe)); - memset(iov, 0, sizeof(iov[0])*2); - - iov[0].iov_len = sizeof(hdrframe); - iov[0].iov_base = &hdrframe; + bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); - iov[1].iov_len = *datalen; - iov[1].iov_base = data; - - msg.msg_iovlen = 2; - msg.msg_iov = iov; - bsent = write(zchan->sockfd, &msg, iov[1].iov_len + iov[0].iov_len); - - if (bsent > 0){ - bsent -= sizeof(wp_tdm_api_tx_hdr_t); + /* should we be checking if bsent == *datalen here? */ + if (bsent > 0) { + *datalen = bsent; + return ZAP_SUCCESS; } - *datalen = bsent; - - return ZAP_SUCCESS; + return ZAP_FAIL; } -#endif static ZINT_WAIT_FUNCTION(wanpipe_wait) { @@ -527,13 +394,8 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.close = wanpipe_close; wanpipe_interface.command = wanpipe_command; wanpipe_interface.wait = wanpipe_wait; -#ifdef __WINDOWS__ - wanpipe_interface.read = wanpipe_read_windows; - wanpipe_interface.write = wanpipe_write_windows; -#else - wanpipe_interface.read = wanpipe_read_unix; - wanpipe_interface.write = wanpipe_write_unix; -#endif + wanpipe_interface.read = wanpipe_read; + wanpipe_interface.write = wanpipe_write; *zint = &wanpipe_interface; return ZAP_SUCCESS; From 8f340bf0e5c1ce83150e3f08dc51c52509a7461d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 10:35:07 +0000 Subject: [PATCH 0103/1766] add missing header file to sangoma_tdm_api.h. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@52 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 1 + libs/openzap/src/zap_wanpipe.c | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index a795507c92..24f601c2de 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -72,6 +72,7 @@ struct iphdr { #define WP_INVALID_SOCKET -1 #include #include +#include #endif #include diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 013da15be5..9b5fbf43da 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -38,11 +38,6 @@ #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - - static struct { unsigned codec_ms; } wp_globals; From 4ac6d61adc3066063ff2b138d00b9b4fa6c50cf6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 10:35:07 +0000 Subject: [PATCH 0104/1766] add missing header file to sangoma_tdm_api.h. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@52 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 1 + libs/freetdm/src/zap_wanpipe.c | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index a795507c92..24f601c2de 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -72,6 +72,7 @@ struct iphdr { #define WP_INVALID_SOCKET -1 #include #include +#include #endif #include diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 013da15be5..9b5fbf43da 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -38,11 +38,6 @@ #include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - - static struct { unsigned codec_ms; } wp_globals; From e73424f36dbfec59656986fdd2880bbd693f6379 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 15:27:29 +0000 Subject: [PATCH 0105/1766] tweak types git-svn-id: http://svn.openzap.org/svn/openzap/trunk@53 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 290 ++++++++++----------- 1 file changed, 145 insertions(+), 145 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 24f601c2de..a58caf5d8d 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -33,34 +33,34 @@ /* sang_api.h(74) : warning C4201: nonstandard extension used : nameless struct/union */ -/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ +/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ /* wanpipe_defines.h(220) : warning C4214: nonstandard extension used : bit field types other than int */ /* this will break for any compilers that are strict ansi or strict c99 */ /* The following definition for that struct should resolve this warning and work for 32 and 64 bit */ #if 0 -struct iphdr { - -#if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned ihl:4, - version:4; -#elif defined (__BIG_ENDIAN_BITFIELD) - unsigned version:4, - ihl:4; -#else -# error "unknown byteorder!" -#endif - unsigned tos:8; - unsigned tot_len:16; - unsigned id:16; - unsigned frag_off:16; - __u8 ttl; - __u8 protocol; - __u16 check; - __u32 saddr; - __u32 daddr; - /*The options start here. */ -}; +struct iphdr { + +#if defined(__LITTLE_ENDIAN_BITFIELD) + unsigned ihl:4, + version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + unsigned version:4, + ihl:4; +#else +# error "unknown byteorder!" +#endif + unsigned tos:8; + unsigned tot_len:16; + unsigned id:16; + unsigned frag_off:16; + __u8 ttl; + __u8 protocol; + __u16 check; + __u32 saddr; + __u32 daddr; + /*The options start here. */ +}; #endif /* #if 0 */ #define __inline__ __inline @@ -90,7 +90,7 @@ struct iphdr { /* what should the returns from this function be?? */ /* I dont think they are currently consistant between windows and *nix */ #ifdef __WINDOWS__ -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) { /* can we make the structure passed for this on nix and windows the same */ /* so we don't have to do the extra 2 memcpy's on windows for this ? */ @@ -129,7 +129,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api } #else -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) { return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); } @@ -291,22 +291,22 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) /* 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; +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(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ + return -1; + } + if(!DeviceIoControl( fd, IoctlReadCommand, @@ -316,111 +316,111 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen 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; -} + )){ + return -1; + } -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; -} + 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 */ From da6aefb5cbd8b898f8f56ec9222084d44b2c637e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 15:27:29 +0000 Subject: [PATCH 0106/1766] tweak types git-svn-id: http://svn.openzap.org/svn/openzap/trunk@53 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 290 ++++++++++----------- 1 file changed, 145 insertions(+), 145 deletions(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index 24f601c2de..a58caf5d8d 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -33,34 +33,34 @@ /* sang_api.h(74) : warning C4201: nonstandard extension used : nameless struct/union */ -/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ +/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ /* wanpipe_defines.h(220) : warning C4214: nonstandard extension used : bit field types other than int */ /* this will break for any compilers that are strict ansi or strict c99 */ /* The following definition for that struct should resolve this warning and work for 32 and 64 bit */ #if 0 -struct iphdr { - -#if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned ihl:4, - version:4; -#elif defined (__BIG_ENDIAN_BITFIELD) - unsigned version:4, - ihl:4; -#else -# error "unknown byteorder!" -#endif - unsigned tos:8; - unsigned tot_len:16; - unsigned id:16; - unsigned frag_off:16; - __u8 ttl; - __u8 protocol; - __u16 check; - __u32 saddr; - __u32 daddr; - /*The options start here. */ -}; +struct iphdr { + +#if defined(__LITTLE_ENDIAN_BITFIELD) + unsigned ihl:4, + version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + unsigned version:4, + ihl:4; +#else +# error "unknown byteorder!" +#endif + unsigned tos:8; + unsigned tot_len:16; + unsigned id:16; + unsigned frag_off:16; + __u8 ttl; + __u8 protocol; + __u16 check; + __u32 saddr; + __u32 daddr; + /*The options start here. */ +}; #endif /* #if 0 */ #define __inline__ __inline @@ -90,7 +90,7 @@ struct iphdr { /* what should the returns from this function be?? */ /* I dont think they are currently consistant between windows and *nix */ #ifdef __WINDOWS__ -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) { /* can we make the structure passed for this on nix and windows the same */ /* so we don't have to do the extra 2 memcpy's on windows for this ? */ @@ -129,7 +129,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api } #else -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) +static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) { return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); } @@ -291,22 +291,22 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) /* 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; +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(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ + return -1; + } + if(!DeviceIoControl( fd, IoctlReadCommand, @@ -316,111 +316,111 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen 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; -} + )){ + return -1; + } -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; -} + 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 */ From 18b8c77d74eb6d206d786a77d199e8cc2b927b2b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 15:28:49 +0000 Subject: [PATCH 0107/1766] tweak types git-svn-id: http://svn.openzap.org/svn/openzap/trunk@54 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 9b5fbf43da..98325449e9 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -48,7 +48,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm { int err; - err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); + err = tdmv_api_ioctl(zchan->sockfd, tdm_api); if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); From 16811e43589e034377d39f67d206cbea0f4cfe33 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 15:28:49 +0000 Subject: [PATCH 0108/1766] tweak types git-svn-id: http://svn.openzap.org/svn/openzap/trunk@54 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 9b5fbf43da..98325449e9 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -48,7 +48,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm { int err; - err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd); + err = tdmv_api_ioctl(zchan->sockfd, tdm_api); if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); From 89e4d886b2000904bcca58a1b8ea8f9145243eb2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 20:30:31 +0000 Subject: [PATCH 0109/1766] initial check in of cross platform thread and mutex abstraction (just recursive mutexes so far). git-svn-id: http://svn.openzap.org/svn/openzap/trunk@55 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 8 ++ libs/openzap/src/Makefile | 2 +- libs/openzap/src/include/zap_threadmutex.h | 37 ++++++ libs/openzap/src/zap_threadmutex.c | 124 +++++++++++++++++++++ 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 libs/openzap/src/include/zap_threadmutex.h create mode 100644 libs/openzap/src/zap_threadmutex.c diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index bdcaead122..455a3bbf6e 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -204,6 +204,10 @@ /> + + @@ -294,6 +298,10 @@ RelativePath=".\src\include\zap_skel.h" > + + diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 301d5836a9..8ec0c6dd2d 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -30,7 +30,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o zap_threadmutex.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h new file mode 100644 index 0000000000..091520f69c --- /dev/null +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -0,0 +1,37 @@ +/* + * 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 + +typedef struct mutex mutex_t; + +typedef enum mutex_status { + MUTEX_SUCCESS, + MUTEX_FAILURE +} mutex_status_t; + +mutex_status_t zap_mutex_create(mutex_t **mutex); +mutex_status_t zap_mutex_destroy(mutex_t *mutex); +mutex_status_t zap_mutex_lock(mutex_t *mutex); +mutex_status_t zap_mutex_trylock(mutex_t *mutex); +mutex_status_t zap_mutex_unlock(mutex_t *mutex); + +#endif diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c new file mode 100644 index 0000000000..6fee969142 --- /dev/null +++ b/libs/openzap/src/zap_threadmutex.c @@ -0,0 +1,124 @@ +/* + * 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. + * + */ + +#define _XOPEN_SOURCE 600 +#include +#include "zap_threadmutex.h" + + +#ifdef WIN32 +#define _WIN32_WINNT 0x0400 +#include +struct mutex { + CRITICAL_SECTION mutex; +}; + +#else + +#include +struct mutex { + pthread_mutex_t mutex; +}; + +#endif + + +mutex_status_t zap_mutex_create(mutex_t **mutex) +{ + mutex_status_t status = MUTEX_FAILURE; +#ifndef WIN32 + pthread_mutexattr_t attr; +#endif + mutex_t *check = NULL; + + check = (mutex_t *)malloc(sizeof(**mutex)); + if (!check) + goto done; +#ifdef WIN32 + InitializeCriticalSection(&check->mutex); +#else + if (pthread_mutexattr_init(&attr)) + goto done; + + if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) + goto fail; + + if (pthread_mutex_init(&check->mutex, &attr)) + goto fail; + + goto success; + +fail: + pthread_mutexattr_destroy(&attr); + goto done; + +success: +#endif + *mutex = check; + status = MUTEX_SUCCESS; + +done: + return status; +} + +mutex_status_t zap_mutex_destroy(mutex_t *mutex) +{ +#ifdef WIN32 + DeleteCriticalSection(&mutex->mutex); +#else + if (pthread_mutex_destroy(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + free(mutex); + return MUTEX_SUCCESS; +} + +mutex_status_t zap_mutex_lock(mutex_t *mutex) +{ +#ifdef WIN32 + EnterCriticalSection(&mutex->mutex); +#else + if (pthread_mutex_lock(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + return MUTEX_SUCCESS; +} + +mutex_status_t zap_mutex_trylock(mutex_t *mutex) +{ +#ifdef WIN32 + if (!TryEnterCriticalSection(&mutex->mutex)) + return MUTEX_FAILURE; +#else + if (pthread_mutex_trylock(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + return MUTEX_SUCCESS; +} + +mutex_status_t zap_mutex_unlock(mutex_t *mutex) +{ +#ifdef WIN32 + LeaveCriticalSection(&mutex->mutex); +#else + if (pthread_mutex_unlock(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + return MUTEX_SUCCESS; +} From ff24de2bb802604f2e4cc1314b746056f96bfcba Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 20:30:31 +0000 Subject: [PATCH 0110/1766] initial check in of cross platform thread and mutex abstraction (just recursive mutexes so far). git-svn-id: http://svn.openzap.org/svn/openzap/trunk@55 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 8 ++ libs/freetdm/src/Makefile | 2 +- libs/freetdm/src/include/zap_threadmutex.h | 37 ++++++ libs/freetdm/src/zap_threadmutex.c | 124 +++++++++++++++++++++ 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 libs/freetdm/src/include/zap_threadmutex.h create mode 100644 libs/freetdm/src/zap_threadmutex.c diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index bdcaead122..455a3bbf6e 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -204,6 +204,10 @@ /> + + @@ -294,6 +298,10 @@ RelativePath=".\src\include\zap_skel.h" > + + diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 301d5836a9..8ec0c6dd2d 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -30,7 +30,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o +OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o zap_threadmutex.o CFLAGS=$(ZAP_CFLAGS) -Iinclude MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h new file mode 100644 index 0000000000..091520f69c --- /dev/null +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -0,0 +1,37 @@ +/* + * 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 + +typedef struct mutex mutex_t; + +typedef enum mutex_status { + MUTEX_SUCCESS, + MUTEX_FAILURE +} mutex_status_t; + +mutex_status_t zap_mutex_create(mutex_t **mutex); +mutex_status_t zap_mutex_destroy(mutex_t *mutex); +mutex_status_t zap_mutex_lock(mutex_t *mutex); +mutex_status_t zap_mutex_trylock(mutex_t *mutex); +mutex_status_t zap_mutex_unlock(mutex_t *mutex); + +#endif diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c new file mode 100644 index 0000000000..6fee969142 --- /dev/null +++ b/libs/freetdm/src/zap_threadmutex.c @@ -0,0 +1,124 @@ +/* + * 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. + * + */ + +#define _XOPEN_SOURCE 600 +#include +#include "zap_threadmutex.h" + + +#ifdef WIN32 +#define _WIN32_WINNT 0x0400 +#include +struct mutex { + CRITICAL_SECTION mutex; +}; + +#else + +#include +struct mutex { + pthread_mutex_t mutex; +}; + +#endif + + +mutex_status_t zap_mutex_create(mutex_t **mutex) +{ + mutex_status_t status = MUTEX_FAILURE; +#ifndef WIN32 + pthread_mutexattr_t attr; +#endif + mutex_t *check = NULL; + + check = (mutex_t *)malloc(sizeof(**mutex)); + if (!check) + goto done; +#ifdef WIN32 + InitializeCriticalSection(&check->mutex); +#else + if (pthread_mutexattr_init(&attr)) + goto done; + + if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) + goto fail; + + if (pthread_mutex_init(&check->mutex, &attr)) + goto fail; + + goto success; + +fail: + pthread_mutexattr_destroy(&attr); + goto done; + +success: +#endif + *mutex = check; + status = MUTEX_SUCCESS; + +done: + return status; +} + +mutex_status_t zap_mutex_destroy(mutex_t *mutex) +{ +#ifdef WIN32 + DeleteCriticalSection(&mutex->mutex); +#else + if (pthread_mutex_destroy(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + free(mutex); + return MUTEX_SUCCESS; +} + +mutex_status_t zap_mutex_lock(mutex_t *mutex) +{ +#ifdef WIN32 + EnterCriticalSection(&mutex->mutex); +#else + if (pthread_mutex_lock(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + return MUTEX_SUCCESS; +} + +mutex_status_t zap_mutex_trylock(mutex_t *mutex) +{ +#ifdef WIN32 + if (!TryEnterCriticalSection(&mutex->mutex)) + return MUTEX_FAILURE; +#else + if (pthread_mutex_trylock(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + return MUTEX_SUCCESS; +} + +mutex_status_t zap_mutex_unlock(mutex_t *mutex) +{ +#ifdef WIN32 + LeaveCriticalSection(&mutex->mutex); +#else + if (pthread_mutex_unlock(&mutex->mutex)) + return MUTEX_FAILURE; +#endif + return MUTEX_SUCCESS; +} From 424f6107a65d62374c119a24b0fdd382225d4619 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:40:06 +0000 Subject: [PATCH 0111/1766] add detached thread abstraction. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@56 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 16 +++ libs/openzap/src/include/zap_threadmutex.h | 22 ++-- libs/openzap/src/include/zap_types.h | 17 ++- libs/openzap/src/zap_threadmutex.c | 142 +++++++++++++++++---- 4 files changed, 156 insertions(+), 41 deletions(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index 455a3bbf6e..cfc5413696 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -321,6 +321,22 @@ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" > + + + + + + + + diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index 091520f69c..9a9b336ed1 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -21,17 +21,19 @@ #ifndef _ZAP_THREADMUTEX_H #define _ZAP_THREADMUTEX_H -typedef struct mutex mutex_t; +#include "openzap.h" -typedef enum mutex_status { - MUTEX_SUCCESS, - MUTEX_FAILURE -} mutex_status_t; +typedef struct zap_mutex zap_mutex_t; +typedef struct zap_thread zap_thread_t; +typedef void *(*zap_thread_function_t) (zap_thread_t *, void *); -mutex_status_t zap_mutex_create(mutex_t **mutex); -mutex_status_t zap_mutex_destroy(mutex_t *mutex); -mutex_status_t zap_mutex_lock(mutex_t *mutex); -mutex_status_t zap_mutex_trylock(mutex_t *mutex); -mutex_status_t zap_mutex_unlock(mutex_t *mutex); +zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data); +zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); +void zap_thread_override_default_stacksize(zap_size_t size); +zap_status_t zap_mutex_create(zap_mutex_t **mutex); +zap_status_t zap_mutex_destroy(zap_mutex_t *mutex); +zap_status_t zap_mutex_lock(zap_mutex_t *mutex); +zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); +zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index a4fdae24fd..d4ba2428db 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -58,7 +58,10 @@ typedef enum { ZAP_SUCCESS, ZAP_FAIL, ZAP_MEMERR, - ZAP_TIMEOUT + ZAP_TIMEOUT, + ZAP_NOTIMPL, + + ZAP_STATUS_COUNT } zap_status_t; typedef enum { @@ -91,7 +94,9 @@ typedef enum { 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_GET_DTMF_OFF_PERIOD, + + ZAP_COMMAND_COUNT } zap_command_t; typedef enum { @@ -104,7 +109,9 @@ typedef enum { ZAP_CHAN_TYPE_DQ921, ZAP_CHAN_TYPE_DQ931, ZAP_CHAN_TYPE_FXS, - ZAP_CHAN_TYPE_FXO + ZAP_CHAN_TYPE_FXO, + + ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; typedef enum { @@ -186,7 +193,9 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; typedef enum { ZAP_EVENT_NONE, - ZAP_EVENT_DTMF + ZAP_EVENT_DTMF, + + ZAP_EVENT_COUNT } zap_event_type_t; typedef struct zap_span zap_span_t; diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 6fee969142..27dc8b1cbd 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -17,37 +17,125 @@ * */ -#define _XOPEN_SOURCE 600 -#include +#ifdef WIN32 +/* required for TryEnterCriticalSection definition. Must be defined before windows.h include */ +#define _WIN32_WINNT 0x0400 +#endif + +#include "openzap.h" #include "zap_threadmutex.h" - #ifdef WIN32 -#define _WIN32_WINNT 0x0400 -#include -struct mutex { +#include + +#define ZAP_THREAD_CALLING_CONVENTION __stdcall + +struct zap_mutex { CRITICAL_SECTION mutex; }; #else #include -struct mutex { - pthread_mutex_t mutex; + +#define ZAP_THREAD_CALLING_CONVENTION + +struct zap_mutex { + pthread_zap_mutex_t mutex; }; #endif +struct zap_thread { +#ifdef WIN32 + void *handle; +#else + pthread_t handle; +#endif + void *private_data; + zap_thread_function_t function; + zap_size_t stack_size; +#ifndef WIN32 + pthread_attr_t attribute; +#endif +}; -mutex_status_t zap_mutex_create(mutex_t **mutex) +zap_size_t thread_default_stacksize = 0; + +void zap_thread_override_default_stacksize(zap_size_t size) { - mutex_status_t status = MUTEX_FAILURE; + thread_default_stacksize = size; +} + +static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) +{ + void *exit_val; + zap_thread_t *thread = (zap_thread_t *)args; + exit_val = thread->function(thread, thread->private_data); +#ifndef WIN32 + pthread_attr_destroy(&thread->attribute); +#endif + free(thread); + + return exit_val; +} + +zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data) +{ + return zap_thread_create_detached_ex(func, data, thread_default_stacksize); +} + +zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) +{ + zap_thread_t *thread = NULL; + zap_status_t status = ZAP_FAIL; + + if (!func || !(thread = (zap_thread_t *)malloc(sizeof(zap_thread_t)))) { + goto done; + } + + thread->private_data = data; + thread->function = func; + thread->stack_size = stack_size; + +#if defined(WIN32) + thread->handle = (void *)_beginthreadex(NULL, (unsigned)thread->stack_size, (unsigned int (__stdcall *)(void *))thread_launch, thread, 0, NULL); + if (!thread->handle) { + goto fail; + } + CloseHandle(thread->handle); +#else + + if (pthread_attr_init(&thread->attribute) != 0) goto fail; + + if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; + + if (stacksize && pthread_attr_setstacksize(&thread->attribute, stacksize) != 0) goto fail; + + if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; + +#endif + status = ZAP_SUCCESS; + goto done; + +fail: + if (thread) { + free(thread); + } +done: + return status; +} + + +zap_status_t zap_mutex_create(zap_mutex_t **mutex) +{ + zap_status_t status = ZAP_FAIL; #ifndef WIN32 pthread_mutexattr_t attr; #endif - mutex_t *check = NULL; + zap_mutex_t *check = NULL; - check = (mutex_t *)malloc(sizeof(**mutex)); + check = (zap_mutex_t *)malloc(sizeof(**mutex)); if (!check) goto done; #ifdef WIN32 @@ -71,54 +159,54 @@ fail: success: #endif *mutex = check; - status = MUTEX_SUCCESS; + status = ZAP_SUCCESS; done: return status; } -mutex_status_t zap_mutex_destroy(mutex_t *mutex) +zap_status_t zap_mutex_destroy(zap_mutex_t *mutex) { #ifdef WIN32 DeleteCriticalSection(&mutex->mutex); #else if (pthread_mutex_destroy(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #endif free(mutex); - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } -mutex_status_t zap_mutex_lock(mutex_t *mutex) +zap_status_t zap_mutex_lock(zap_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); #else if (pthread_mutex_lock(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #endif - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } -mutex_status_t zap_mutex_trylock(mutex_t *mutex) +zap_status_t zap_zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #else - if (pthread_mutex_trylock(&mutex->mutex)) - return MUTEX_FAILURE; + if (pthread_zap_mutex_trylock(&mutex->mutex)) + return ZAP_FAIL; #endif - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } -mutex_status_t zap_mutex_unlock(mutex_t *mutex) +zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); #else if (pthread_mutex_unlock(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #endif - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } From 8546385c61551c647ad324829bd3e505c2e322bc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:40:06 +0000 Subject: [PATCH 0112/1766] add detached thread abstraction. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@56 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 16 +++ libs/freetdm/src/include/zap_threadmutex.h | 22 ++-- libs/freetdm/src/include/zap_types.h | 17 ++- libs/freetdm/src/zap_threadmutex.c | 142 +++++++++++++++++---- 4 files changed, 156 insertions(+), 41 deletions(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index 455a3bbf6e..cfc5413696 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -321,6 +321,22 @@ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" > + + + + + + + + diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index 091520f69c..9a9b336ed1 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -21,17 +21,19 @@ #ifndef _ZAP_THREADMUTEX_H #define _ZAP_THREADMUTEX_H -typedef struct mutex mutex_t; +#include "openzap.h" -typedef enum mutex_status { - MUTEX_SUCCESS, - MUTEX_FAILURE -} mutex_status_t; +typedef struct zap_mutex zap_mutex_t; +typedef struct zap_thread zap_thread_t; +typedef void *(*zap_thread_function_t) (zap_thread_t *, void *); -mutex_status_t zap_mutex_create(mutex_t **mutex); -mutex_status_t zap_mutex_destroy(mutex_t *mutex); -mutex_status_t zap_mutex_lock(mutex_t *mutex); -mutex_status_t zap_mutex_trylock(mutex_t *mutex); -mutex_status_t zap_mutex_unlock(mutex_t *mutex); +zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data); +zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); +void zap_thread_override_default_stacksize(zap_size_t size); +zap_status_t zap_mutex_create(zap_mutex_t **mutex); +zap_status_t zap_mutex_destroy(zap_mutex_t *mutex); +zap_status_t zap_mutex_lock(zap_mutex_t *mutex); +zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); +zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index a4fdae24fd..d4ba2428db 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -58,7 +58,10 @@ typedef enum { ZAP_SUCCESS, ZAP_FAIL, ZAP_MEMERR, - ZAP_TIMEOUT + ZAP_TIMEOUT, + ZAP_NOTIMPL, + + ZAP_STATUS_COUNT } zap_status_t; typedef enum { @@ -91,7 +94,9 @@ typedef enum { 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_GET_DTMF_OFF_PERIOD, + + ZAP_COMMAND_COUNT } zap_command_t; typedef enum { @@ -104,7 +109,9 @@ typedef enum { ZAP_CHAN_TYPE_DQ921, ZAP_CHAN_TYPE_DQ931, ZAP_CHAN_TYPE_FXS, - ZAP_CHAN_TYPE_FXO + ZAP_CHAN_TYPE_FXO, + + ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; typedef enum { @@ -186,7 +193,9 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; typedef enum { ZAP_EVENT_NONE, - ZAP_EVENT_DTMF + ZAP_EVENT_DTMF, + + ZAP_EVENT_COUNT } zap_event_type_t; typedef struct zap_span zap_span_t; diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 6fee969142..27dc8b1cbd 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -17,37 +17,125 @@ * */ -#define _XOPEN_SOURCE 600 -#include +#ifdef WIN32 +/* required for TryEnterCriticalSection definition. Must be defined before windows.h include */ +#define _WIN32_WINNT 0x0400 +#endif + +#include "openzap.h" #include "zap_threadmutex.h" - #ifdef WIN32 -#define _WIN32_WINNT 0x0400 -#include -struct mutex { +#include + +#define ZAP_THREAD_CALLING_CONVENTION __stdcall + +struct zap_mutex { CRITICAL_SECTION mutex; }; #else #include -struct mutex { - pthread_mutex_t mutex; + +#define ZAP_THREAD_CALLING_CONVENTION + +struct zap_mutex { + pthread_zap_mutex_t mutex; }; #endif +struct zap_thread { +#ifdef WIN32 + void *handle; +#else + pthread_t handle; +#endif + void *private_data; + zap_thread_function_t function; + zap_size_t stack_size; +#ifndef WIN32 + pthread_attr_t attribute; +#endif +}; -mutex_status_t zap_mutex_create(mutex_t **mutex) +zap_size_t thread_default_stacksize = 0; + +void zap_thread_override_default_stacksize(zap_size_t size) { - mutex_status_t status = MUTEX_FAILURE; + thread_default_stacksize = size; +} + +static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) +{ + void *exit_val; + zap_thread_t *thread = (zap_thread_t *)args; + exit_val = thread->function(thread, thread->private_data); +#ifndef WIN32 + pthread_attr_destroy(&thread->attribute); +#endif + free(thread); + + return exit_val; +} + +zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data) +{ + return zap_thread_create_detached_ex(func, data, thread_default_stacksize); +} + +zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) +{ + zap_thread_t *thread = NULL; + zap_status_t status = ZAP_FAIL; + + if (!func || !(thread = (zap_thread_t *)malloc(sizeof(zap_thread_t)))) { + goto done; + } + + thread->private_data = data; + thread->function = func; + thread->stack_size = stack_size; + +#if defined(WIN32) + thread->handle = (void *)_beginthreadex(NULL, (unsigned)thread->stack_size, (unsigned int (__stdcall *)(void *))thread_launch, thread, 0, NULL); + if (!thread->handle) { + goto fail; + } + CloseHandle(thread->handle); +#else + + if (pthread_attr_init(&thread->attribute) != 0) goto fail; + + if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; + + if (stacksize && pthread_attr_setstacksize(&thread->attribute, stacksize) != 0) goto fail; + + if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; + +#endif + status = ZAP_SUCCESS; + goto done; + +fail: + if (thread) { + free(thread); + } +done: + return status; +} + + +zap_status_t zap_mutex_create(zap_mutex_t **mutex) +{ + zap_status_t status = ZAP_FAIL; #ifndef WIN32 pthread_mutexattr_t attr; #endif - mutex_t *check = NULL; + zap_mutex_t *check = NULL; - check = (mutex_t *)malloc(sizeof(**mutex)); + check = (zap_mutex_t *)malloc(sizeof(**mutex)); if (!check) goto done; #ifdef WIN32 @@ -71,54 +159,54 @@ fail: success: #endif *mutex = check; - status = MUTEX_SUCCESS; + status = ZAP_SUCCESS; done: return status; } -mutex_status_t zap_mutex_destroy(mutex_t *mutex) +zap_status_t zap_mutex_destroy(zap_mutex_t *mutex) { #ifdef WIN32 DeleteCriticalSection(&mutex->mutex); #else if (pthread_mutex_destroy(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #endif free(mutex); - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } -mutex_status_t zap_mutex_lock(mutex_t *mutex) +zap_status_t zap_mutex_lock(zap_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); #else if (pthread_mutex_lock(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #endif - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } -mutex_status_t zap_mutex_trylock(mutex_t *mutex) +zap_status_t zap_zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #else - if (pthread_mutex_trylock(&mutex->mutex)) - return MUTEX_FAILURE; + if (pthread_zap_mutex_trylock(&mutex->mutex)) + return ZAP_FAIL; #endif - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } -mutex_status_t zap_mutex_unlock(mutex_t *mutex) +zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); #else if (pthread_mutex_unlock(&mutex->mutex)) - return MUTEX_FAILURE; + return ZAP_FAIL; #endif - return MUTEX_SUCCESS; + return ZAP_SUCCESS; } From d072950e7d7c95d2223e5843e16a81076350d443 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:41:36 +0000 Subject: [PATCH 0113/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@57 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_threadmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 27dc8b1cbd..0ca028472e 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -41,7 +41,7 @@ struct zap_mutex { #define ZAP_THREAD_CALLING_CONVENTION struct zap_mutex { - pthread_zap_mutex_t mutex; + pthread_mutex_t mutex; }; #endif From 7e5d396bc30195a36b333c682226a0ee85d760f3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:41:36 +0000 Subject: [PATCH 0114/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@57 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 27dc8b1cbd..0ca028472e 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -41,7 +41,7 @@ struct zap_mutex { #define ZAP_THREAD_CALLING_CONVENTION struct zap_mutex { - pthread_zap_mutex_t mutex; + pthread_mutex_t mutex; }; #endif From eec3cb0975363d6bb640cda5d2f27cd3ab89ed9a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:43:38 +0000 Subject: [PATCH 0115/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@58 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_threadmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 0ca028472e..4f9db6c1a6 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -110,7 +110,7 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; - if (stacksize && pthread_attr_setstacksize(&thread->attribute, stacksize) != 0) goto fail; + if (stacksize && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; From 6b47b11c88af9aff0f38f4e2f7fcc57ec6c5e554 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:43:38 +0000 Subject: [PATCH 0116/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@58 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 0ca028472e..4f9db6c1a6 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -110,7 +110,7 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; - if (stacksize && pthread_attr_setstacksize(&thread->attribute, stacksize) != 0) goto fail; + if (stacksize && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; From 45d3a0a08ee2f6936b10904965d361c83dd7bafd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:45:52 +0000 Subject: [PATCH 0117/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@59 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_threadmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 4f9db6c1a6..c05a95c260 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -110,7 +110,7 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; - if (stacksize && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; + if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; From b1cf76c682003ec412a0da6106c34011f5be4681 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:45:52 +0000 Subject: [PATCH 0118/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@59 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 4f9db6c1a6..c05a95c260 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -110,7 +110,7 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; - if (stacksize && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; + if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; From f37fb06241aa73b383a690ab2b222ea3f4572098 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:47:32 +0000 Subject: [PATCH 0119/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@60 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_threadmutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index c05a95c260..baea9bcbf1 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -188,13 +188,13 @@ zap_status_t zap_mutex_lock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t zap_zap_mutex_trylock(zap_mutex_t *mutex) +zap_status_t zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) return ZAP_FAIL; #else - if (pthread_zap_mutex_trylock(&mutex->mutex)) + if (pthread_mutex_trylock(&mutex->mutex)) return ZAP_FAIL; #endif return ZAP_SUCCESS; From c38285a05bf3aeb19651bea07e1ce3d908e24c47 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 02:47:32 +0000 Subject: [PATCH 0120/1766] typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@60 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index c05a95c260..baea9bcbf1 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -188,13 +188,13 @@ zap_status_t zap_mutex_lock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t zap_zap_mutex_trylock(zap_mutex_t *mutex) +zap_status_t zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) return ZAP_FAIL; #else - if (pthread_zap_mutex_trylock(&mutex->mutex)) + if (pthread_mutex_trylock(&mutex->mutex)) return ZAP_FAIL; #endif return ZAP_SUCCESS; From 491d7a2fe4a7879489df09bf5466d1efbfba4d4d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 15:38:35 +0000 Subject: [PATCH 0121/1766] fix leak on pthread failures. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@61 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_threadmutex.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index baea9bcbf1..8fc4632fd3 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -104,19 +104,24 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat goto fail; } CloseHandle(thread->handle); + + status = ZAP_SUCCESS; + goto done; #else if (pthread_attr_init(&thread->attribute) != 0) goto fail; - if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; + if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto failpthread; - if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; + if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto failpthread; - if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; + if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto failpthread; -#endif status = ZAP_SUCCESS; goto done; +failpthread: + pthread_attr_destroy(&thread->attribute); +#endif fail: if (thread) { From e5fb4a3cc022dbe543f4a97807c8357e78612080 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 15:38:35 +0000 Subject: [PATCH 0122/1766] fix leak on pthread failures. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@61 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index baea9bcbf1..8fc4632fd3 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -104,19 +104,24 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat goto fail; } CloseHandle(thread->handle); + + status = ZAP_SUCCESS; + goto done; #else if (pthread_attr_init(&thread->attribute) != 0) goto fail; - if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto fail; + if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto failpthread; - if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto fail; + if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto failpthread; - if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto fail; + if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto failpthread; -#endif status = ZAP_SUCCESS; goto done; +failpthread: + pthread_attr_destroy(&thread->attribute); +#endif fail: if (thread) { From 5724bd4d6aedc4c79478facc12ced27357d15d91 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 17:48:13 +0000 Subject: [PATCH 0123/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@62 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 4 +- libs/openzap/src/g711.c | 92 +++++++++++ libs/openzap/src/include/openzap.h | 7 +- libs/openzap/src/include/sangoma_tdm_api.h | 63 +++---- libs/openzap/src/include/zap_threadmutex.h | 2 +- libs/openzap/src/include/zap_types.h | 8 +- libs/openzap/src/openzap.c | 184 +++++++++++++++------ libs/openzap/src/testapp.c | 5 +- libs/openzap/src/zap_threadmutex.c | 10 +- libs/openzap/src/zap_wanpipe.c | 28 +++- 10 files changed, 297 insertions(+), 106 deletions(-) create mode 100644 libs/openzap/src/g711.c diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 8ec0c6dd2d..50e4b6ba7b 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -44,7 +44,7 @@ $(MYLIB): $(OBJS) ranlib $(MYLIB) testapp: testapp.c $(MYLIB) - $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm + $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm -lpthread priserver.o: priserver.c @@ -54,7 +54,7 @@ sangoma_pri.o: sangoma_pri.c $(CC) $(TMP) -c sangoma_pri.c -o sangoma_pri.o priserver: $(MYLIB) priserver.o sangoma_pri.o - $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm ../../libpri-1.2.4/libpri.a + $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a openzap.o: openzap.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/openzap/src/g711.c b/libs/openzap/src/g711.c new file mode 100644 index 0000000000..8a5c58b835 --- /dev/null +++ b/libs/openzap/src/g711.c @@ -0,0 +1,92 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * g711.c - A-law and u-law transcoding routines + * + * Written by Steve Underwood + * + * Copyright (C) 2006 Steve Underwood + * + * Despite my general liking of the GPL, I place this code in the + * public domain for the benefit of all mankind - even the slimy + * ones who might try to proprietize my work and use it to my + * detriment. + * + * $Id: g711.c,v 1.1 2006/06/07 15:46:39 steveu Exp $ + */ + +/*! \file */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#ifndef _MSC_VER +#include +#ifdef HAVE_TGMATH_H +#include +#endif +#endif + +#include "g711.h" + +/* Copied from the CCITT G.711 specification */ +static const uint8_t ulaw_to_alaw_table[256] = +{ + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26, + 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106, + 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120, + 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77, + 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93, + 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154, + 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234, + 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248, + 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205, + 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221, + 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213 +}; + +/* These transcoding tables are copied from the CCITT G.711 specification. To achieve + optimal results, do not change them. */ + +static const uint8_t alaw_to_ulaw_table[256] = +{ + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, + 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, + 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94, + 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109, + 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67, + 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133, + 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, + 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222, + 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237, + 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195, + 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209 +}; + +uint8_t alaw_to_ulaw(uint8_t alaw) +{ + return alaw_to_ulaw_table[alaw]; +} +/*- End of function --------------------------------------------------------*/ + +uint8_t ulaw_to_alaw(uint8_t ulaw) +{ + return ulaw_to_alaw_table[ulaw]; +} +/*- End of function --------------------------------------------------------*/ +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 8f4b012a80..256b4e8f9b 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -87,6 +87,7 @@ #include "g711.h" #include "libteletone.h" #include "zap_buffer.h" +#include "zap_threadmutex.h" #ifdef NDEBUG #undef assert @@ -96,7 +97,7 @@ #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 - +#define GOTO_STATUS(label,st) status = st; goto label ; #define zap_true(expr)\ (expr && ( !strcasecmp(expr, "yes") ||\ @@ -190,6 +191,7 @@ struct zap_span { zap_span_flag_t flags; struct zap_software_interface *zint; zint_event_cb_t event_callback; + zap_mutex_t *mutex; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -211,6 +213,7 @@ struct zap_software_interface { zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); +zap_status_t zap_span_close_all(zap_software_interface_t *zint); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); @@ -218,7 +221,7 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index a58caf5d8d..b8b40d61fb 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -107,7 +107,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); - if(DeviceIoControl( + if (DeviceIoControl( fd, IoctlManagementCommand, (LPVOID)&wan_udp, @@ -120,7 +120,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd return 1; } - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ return 2; } @@ -137,7 +137,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd void __inline__ tdmv_api_close_socket(sng_fd_t *sp) { - if( *sp != WP_INVALID_SOCKET){ + if ( *sp != WP_INVALID_SOCKET){ #if defined(__WINDOWS__) CloseHandle(*sp); #else @@ -186,7 +186,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) (LPOVERLAPPED)NULL ); - if((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ + if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ /* somone already has this channel, or somthing else is not right. */ tdmv_api_close_socket(&fd); } @@ -218,7 +218,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) /* 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) +static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) { #if defined(__WINDOWS__) DWORD ln; @@ -226,7 +226,7 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); - api_poll.user_flags_bitmap = flags; + api_poll.user_flags_bitmap = *flags; api_poll.timeout = timeout; if (!DeviceIoControl( @@ -241,6 +241,8 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) return -1; } + *flags = 0; + switch(api_poll.operation_status) { case SANG_STATUS_RX_DATA_AVAILABLE: @@ -253,37 +255,36 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) return -1; } - if(api_poll.poll_events_bitmap == 0){ + if (api_poll.poll_events_bitmap == 0){ return -1; } - if(api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT){ + if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { return 0; } - return api_poll.poll_events_bitmap; + *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; + pfds[0].events = *flags; res = poll(pfds, 1, timeout); + *flags = 0; - if (res == 0) { - return 0; + if (pfds[0].revents & POLLERR) { + res = -1; } - if (res < 0) { - return -1; + if (res > 0) { + *flags = pfds[0].revents; } - if ((pfds[0].revents & POLLERR)) { - return -1; - } - - return pfds[0].revents; + return res; #endif } @@ -303,11 +304,11 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen 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)){ + if (hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ return -1; } - if(!DeviceIoControl( + if (!DeviceIoControl( fd, IoctlReadCommand, (LPVOID)NULL, @@ -328,7 +329,7 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen switch(pri->operation_status) { case SANG_STATUS_RX_DATA_AVAILABLE: - if(pri->data_length > datalen){ + if (pri->data_length > datalen){ break; } memcpy(databuf, rx_data.data, pri->data_length); @@ -384,7 +385,7 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle pri->data_length = datalen; memcpy(local_tx_data.data, databuf, pri->data_length); - if(!DeviceIoControl( + if (!DeviceIoControl( fd, IoctlWriteCommand, (LPVOID)&local_tx_data, @@ -406,18 +407,18 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle memset(&msg,0,sizeof(struct msghdr)); - iov[0].iov_len=hdrlen; - iov[0].iov_base=hdrbuf; + iov[0].iov_len = hdrlen; + iov[0].iov_base = hdrbuf; - iov[1].iov_len=datalen; - iov[1].iov_base=databuf; + iov[1].iov_len = datalen; + iov[1].iov_base = databuf; - msg.msg_iovlen=2; - msg.msg_iov=iov; + msg.msg_iovlen = 2; + msg.msg_iov = iov; - bsent = write(fd,&msg,datalen+hdrlen); + bsent = write(fd, &msg, datalen + hdrlen); if (bsent > 0){ - bsent-=sizeof(wp_tdm_api_tx_hdr_t); + bsent -= sizeof(wp_tdm_api_tx_hdr_t); } #endif return bsent; diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index 9a9b336ed1..557f23ea51 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -31,7 +31,7 @@ zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data); zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); void zap_thread_override_default_stacksize(zap_size_t size); zap_status_t zap_mutex_create(zap_mutex_t **mutex); -zap_status_t zap_mutex_destroy(zap_mutex_t *mutex); +zap_status_t zap_mutex_destroy(zap_mutex_t **mutex); zap_status_t zap_mutex_lock(zap_mutex_t *mutex); zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index d4ba2428db..9e189a138a 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -66,9 +66,9 @@ typedef enum { typedef enum { ZAP_NO_FLAGS = 0, - ZAP_READ = (1 << 0), - ZAP_WRITE = (1 << 1), - ZAP_ERROR = (1 << 2) + ZAP_READ = (1 << 0), + ZAP_WRITE = (1 << 1), + ZAP_EVENTS = (1 << 2) } zap_wait_flag_t; typedef enum { @@ -139,7 +139,7 @@ typedef struct zap_event zap_event_t; #define ZINT_OPEN_ARGS (zap_channel_t *zchan) #define ZINT_CLOSE_ARGS (zap_channel_t *zchan) #define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) #define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) #define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index b10227bb63..3550fed880 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -42,6 +42,7 @@ static struct { zap_hash_t *interface_hash; + zap_mutex_t *mutex; } globals; static char *LEVEL_NAMES[] = { @@ -158,6 +159,7 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); new_span->span_id = zint->span_index; new_span->zint = zint; + zap_mutex_create(&new_span->mutex); *span = new_span; return ZAP_SUCCESS; } @@ -165,6 +167,21 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) return ZAP_FAIL; } +zap_status_t zap_span_close_all(zap_software_interface_t *zint) +{ + zap_span_t *span; + uint32_t i; + + for(i = 0; i < zint->span_index; i++) { + span = &zint->spans[i]; + if (span->mutex) { + zap_mutex_destroy(&span->mutex); + } + } + + return i ? ZAP_SUCCESS : ZAP_FAIL; +} + zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { @@ -186,9 +203,13 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_software_interface_t *zint; zap_span_t *fspan; + zap_mutex_lock(globals.mutex); + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_mutex_unlock(globals.mutex); + if (!zint) { return ZAP_FAIL; } @@ -211,25 +232,33 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback) { + zap_mutex_lock(span->mutex); span->event_callback = event_callback; + zap_mutex_unlock(span->mutex); return ZAP_SUCCESS; } zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback) { + zap_mutex_lock(zchan->span->mutex); zchan->event_callback = event_callback; + zap_mutex_unlock(zchan->span->mutex); return ZAP_SUCCESS; } zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_software_interface_t *zint; zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; zap_span_t *span; uint32_t span_max; + zap_mutex_lock(globals.mutex); + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_mutex_unlock(globals.mutex); + if (!zint) { zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); return ZAP_FAIL; @@ -247,7 +276,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct j = span_max; } - + zap_mutex_lock(globals.mutex); for(;;) { span = &zint->spans[j]; @@ -314,25 +343,60 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct } } + zap_mutex_unlock(globals.mutex); + return status; } +static zap_status_t zap_channel_reset(zap_channel_t *zchan) +{ + zap_clear_flag(zchan, ZAP_CHANNEL_OPEN); + zchan->event_callback = NULL; + zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + if (zchan->tone_session.buffer) { + teletone_destroy_session(&zchan->tone_session); + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + } + if (zchan->dtmf_buffer) { + zap_buffer_destroy(&zchan->dtmf_buffer); + } + zchan->dtmf_on = zchan->dtmf_off = 0; + + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { + zchan->effective_codec = zchan->native_codec; + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); + } + + return ZAP_SUCCESS; +} + + + zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_software_interface_t *zint; zap_status_t status = ZAP_FAIL; + zap_mutex_lock(globals.mutex); + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_mutex_unlock(globals.mutex); + + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; + zap_mutex_lock(zint->spans[span_id].mutex); check = &zint->spans[span_id].channels[chan_id]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zint->open(check); if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_OPEN); *zchan = check; } - return status; } + zap_mutex_unlock(zint->spans[span_id].mutex); } return status; @@ -347,25 +411,17 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) check = *zchan; assert(check != NULL); *zchan = NULL; - + + zap_mutex_lock(check->span->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zint->close(check); if (status == ZAP_SUCCESS) { - zap_clear_flag(check, ZAP_CHANNEL_OPEN); - check->event_callback = NULL; - zap_clear_flag(check, ZAP_CHANNEL_DTMF_DETECT); - zap_clear_flag(check, ZAP_CHANNEL_SUPRESS_DTMF); - if (check->tone_session.buffer) { - teletone_destroy_session(&check->tone_session); - memset(&check->tone_session, 0, sizeof(check->tone_session)); - } - if (check->dtmf_buffer) { - zap_buffer_destroy(&check->dtmf_buffer); - } - check->dtmf_on = check->dtmf_off = 0; + zap_channel_reset(check); *zchan = NULL; } } + + zap_mutex_unlock(check->span->mutex); return status; } @@ -405,6 +461,8 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { + zap_status_t status = ZAP_FAIL; + assert(zchan != NULL); assert(zchan->zint != NULL); @@ -413,6 +471,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo return ZAP_FAIL; } + zap_mutex_lock(zchan->span->mutex); + switch(command) { case ZAP_COMMAND_SET_INTERVAL: { @@ -424,7 +484,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_set_flag(zchan, ZAP_CHANNEL_BUFFER); } zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -432,7 +492,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { ZAP_COMMAND_OBJ_INT = zchan->effective_interval; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -446,7 +506,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); } zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -455,7 +515,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { ZAP_COMMAND_OBJ_INT = zchan->effective_codec; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -468,10 +528,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); zap_set_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_set_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -484,10 +544,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -495,7 +555,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -503,7 +563,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -513,10 +573,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_on = val; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -527,10 +587,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_off = val; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -538,16 +598,15 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_SEND_DTMF: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { - zap_status_t status; char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; if (!zchan->dtmf_buffer) { if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { - return status; + GOTO_STATUS(done, status); } } zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); - + for (cur = digits; *cur; cur++) { int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { @@ -556,7 +615,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } zchan->skip_read_frames = 200; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -566,14 +625,18 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zchan->zint->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } - return zchan->zint->command(zchan, command, obj); + status = zchan->zint->command(zchan, command, obj); + + done: + zap_mutex_unlock(zchan->span->mutex); + return status; } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -899,30 +962,39 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat return status; } +static struct { + zap_software_interface_t *wanpipe_interface; + zap_software_interface_t *zt_interface; +} interfaces; + zap_status_t zap_global_init(void) { zap_config_t cfg; char *var, *val; uint32_t configured = 0; - zap_software_interface_t *zint; int modcount; + memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); - zint = NULL; modcount = 0; - + zap_mutex_create(&globals.mutex); + #ifdef ZAP_WANPIPE_SUPPORT - if (wanpipe_init(&zint) == ZAP_SUCCESS) { - hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); + zap_mutex_unlock(globals.mutex); modcount++; } else { zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n"); } #endif - zint = NULL; + #ifdef ZAP_ZT_SUPPORT - if (zt_init(&zint) == ZAP_SUCCESS) { - hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) { + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface); + zap_mutex_unlock(globals.mutex); modcount++; } else { zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n"); @@ -942,8 +1014,11 @@ zap_status_t zap_global_init(void) if (!strcasecmp(cfg.category, "openzap")) { if (!strcmp(var, "load")) { zap_software_interface_t *zint; - + + zap_mutex_lock(globals.mutex); zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); + zap_mutex_unlock(globals.mutex); + if (zint) { if (zint->configure(zint) == ZAP_SUCCESS) { configured++; @@ -967,16 +1042,21 @@ zap_status_t zap_global_init(void) zap_status_t zap_global_destroy(void) { - #ifdef ZAP_ZT_SUPPORT - zt_destroy(); + if (interfaces.zt_interface) { + zt_destroy(); + zap_span_close_all(interfaces.zt_interface); + } #endif #ifdef ZAP_WANPIPE_SUPPORT - wanpipe_destroy(); + if (interfaces.wanpipe_interface) { + wanpipe_destroy(); + zap_span_close_all(interfaces.wanpipe_interface); + } #endif hashtable_destroy(globals.interface_hash, 0); - + zap_mutex_destroy(&globals.mutex); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 8b9ae692ba..8160496c29 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -16,7 +16,8 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); top: - if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { + //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { + if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); @@ -42,7 +43,7 @@ int main(int argc, char *argv[]) zap_size_t len = sizeof(buf); zap_wait_flag_t flags = ZAP_READ; - if (zap_channel_wait(chan, &flags, 0) == ZAP_FAIL) { + if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { printf("wait FAIL! %d [%s]\n", len, chan->last_error); } if (flags & ZAP_READ) { diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 8fc4632fd3..34e23bec5c 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -170,15 +170,17 @@ done: return status; } -zap_status_t zap_mutex_destroy(zap_mutex_t *mutex) +zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) { + zap_mutex_t *mp = *mutex; + *mutex = NULL; #ifdef WIN32 - DeleteCriticalSection(&mutex->mutex); + DeleteCriticalSection(&mp->mutex); #else - if (pthread_mutex_destroy(&mutex->mutex)) + if (pthread_mutex_destroy(&mp->mutex)) return ZAP_FAIL; #endif - free(mutex); + free(mp); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 98325449e9..6386741e1f 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -346,14 +346,26 @@ static ZINT_WRITE_FUNCTION(wanpipe_write) static ZINT_WAIT_FUNCTION(wanpipe_wait) { - zap_wait_flag_t inflags = *flags; + int32_t inflags = 0; int result; - - result = tdmv_api_wait_socket(zchan->sockfd, to, inflags); + + if (*flags & ZAP_READ) { + inflags |= POLLIN; + } + + if (*flags & ZAP_WRITE) { + inflags |= POLLOUT; + } + + if (*flags & ZAP_EVENTS) { + inflags |= POLLPRI; + } + + result = tdmv_api_wait_socket(zchan->sockfd, to, &inflags); *flags = ZAP_NO_FLAGS; - if(result < 0){ + if (result < 0){ snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); return ZAP_FAIL; } @@ -362,16 +374,16 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) return ZAP_TIMEOUT; } - if (result & POLLIN) { + if (inflags & POLLIN) { *flags |= ZAP_READ; } - if (result & POLLOUT) { + if (inflags & POLLOUT) { *flags |= ZAP_WRITE; } - if (result & POLLPRI) { - *flags |= ZAP_ERROR; + if (inflags & POLLPRI) { + *flags |= ZAP_EVENTS; } return ZAP_SUCCESS; From 5013baf37a0464c158a3bc948f322e81a9ce99bc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 17:48:13 +0000 Subject: [PATCH 0124/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@62 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 4 +- libs/freetdm/src/g711.c | 92 +++++++++++ libs/freetdm/src/include/openzap.h | 7 +- libs/freetdm/src/include/sangoma_tdm_api.h | 63 +++---- libs/freetdm/src/include/zap_threadmutex.h | 2 +- libs/freetdm/src/include/zap_types.h | 8 +- libs/freetdm/src/openzap.c | 184 +++++++++++++++------ libs/freetdm/src/testapp.c | 5 +- libs/freetdm/src/zap_threadmutex.c | 10 +- libs/freetdm/src/zap_wanpipe.c | 28 +++- 10 files changed, 297 insertions(+), 106 deletions(-) create mode 100644 libs/freetdm/src/g711.c diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 8ec0c6dd2d..50e4b6ba7b 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -44,7 +44,7 @@ $(MYLIB): $(OBJS) ranlib $(MYLIB) testapp: testapp.c $(MYLIB) - $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm + $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm -lpthread priserver.o: priserver.c @@ -54,7 +54,7 @@ sangoma_pri.o: sangoma_pri.c $(CC) $(TMP) -c sangoma_pri.c -o sangoma_pri.o priserver: $(MYLIB) priserver.o sangoma_pri.o - $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm ../../libpri-1.2.4/libpri.a + $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a openzap.o: openzap.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/freetdm/src/g711.c b/libs/freetdm/src/g711.c new file mode 100644 index 0000000000..8a5c58b835 --- /dev/null +++ b/libs/freetdm/src/g711.c @@ -0,0 +1,92 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * g711.c - A-law and u-law transcoding routines + * + * Written by Steve Underwood + * + * Copyright (C) 2006 Steve Underwood + * + * Despite my general liking of the GPL, I place this code in the + * public domain for the benefit of all mankind - even the slimy + * ones who might try to proprietize my work and use it to my + * detriment. + * + * $Id: g711.c,v 1.1 2006/06/07 15:46:39 steveu Exp $ + */ + +/*! \file */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#ifndef _MSC_VER +#include +#ifdef HAVE_TGMATH_H +#include +#endif +#endif + +#include "g711.h" + +/* Copied from the CCITT G.711 specification */ +static const uint8_t ulaw_to_alaw_table[256] = +{ + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26, + 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106, + 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120, + 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77, + 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93, + 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154, + 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234, + 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248, + 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205, + 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221, + 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213 +}; + +/* These transcoding tables are copied from the CCITT G.711 specification. To achieve + optimal results, do not change them. */ + +static const uint8_t alaw_to_ulaw_table[256] = +{ + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, + 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, + 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94, + 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109, + 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67, + 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133, + 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, + 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222, + 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237, + 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195, + 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209 +}; + +uint8_t alaw_to_ulaw(uint8_t alaw) +{ + return alaw_to_ulaw_table[alaw]; +} +/*- End of function --------------------------------------------------------*/ + +uint8_t ulaw_to_alaw(uint8_t ulaw) +{ + return ulaw_to_alaw_table[ulaw]; +} +/*- End of function --------------------------------------------------------*/ +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 8f4b012a80..256b4e8f9b 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -87,6 +87,7 @@ #include "g711.h" #include "libteletone.h" #include "zap_buffer.h" +#include "zap_threadmutex.h" #ifdef NDEBUG #undef assert @@ -96,7 +97,7 @@ #define ZAP_MAX_CHANNELS_SPAN 513 #define ZAP_MAX_SPANS_INTERFACE 33 - +#define GOTO_STATUS(label,st) status = st; goto label ; #define zap_true(expr)\ (expr && ( !strcasecmp(expr, "yes") ||\ @@ -190,6 +191,7 @@ struct zap_span { zap_span_flag_t flags; struct zap_software_interface *zint; zint_event_cb_t event_callback; + zap_mutex_t *mutex; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -211,6 +213,7 @@ struct zap_software_interface { zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); +zap_status_t zap_span_close_all(zap_software_interface_t *zint); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); @@ -218,7 +221,7 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to); +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_global_init(void); diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index a58caf5d8d..b8b40d61fb 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -107,7 +107,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); - if(DeviceIoControl( + if (DeviceIoControl( fd, IoctlManagementCommand, (LPVOID)&wan_udp, @@ -120,7 +120,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd return 1; } - if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ + if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ return 2; } @@ -137,7 +137,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd void __inline__ tdmv_api_close_socket(sng_fd_t *sp) { - if( *sp != WP_INVALID_SOCKET){ + if ( *sp != WP_INVALID_SOCKET){ #if defined(__WINDOWS__) CloseHandle(*sp); #else @@ -186,7 +186,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) (LPOVERLAPPED)NULL ); - if((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ + if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ /* somone already has this channel, or somthing else is not right. */ tdmv_api_close_socket(&fd); } @@ -218,7 +218,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) /* 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) +static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) { #if defined(__WINDOWS__) DWORD ln; @@ -226,7 +226,7 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); - api_poll.user_flags_bitmap = flags; + api_poll.user_flags_bitmap = *flags; api_poll.timeout = timeout; if (!DeviceIoControl( @@ -241,6 +241,8 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) return -1; } + *flags = 0; + switch(api_poll.operation_status) { case SANG_STATUS_RX_DATA_AVAILABLE: @@ -253,37 +255,36 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) return -1; } - if(api_poll.poll_events_bitmap == 0){ + if (api_poll.poll_events_bitmap == 0){ return -1; } - if(api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT){ + if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { return 0; } - return api_poll.poll_events_bitmap; + *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; + pfds[0].events = *flags; res = poll(pfds, 1, timeout); + *flags = 0; - if (res == 0) { - return 0; + if (pfds[0].revents & POLLERR) { + res = -1; } - if (res < 0) { - return -1; + if (res > 0) { + *flags = pfds[0].revents; } - if ((pfds[0].revents & POLLERR)) { - return -1; - } - - return pfds[0].revents; + return res; #endif } @@ -303,11 +304,11 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen 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)){ + if (hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ return -1; } - if(!DeviceIoControl( + if (!DeviceIoControl( fd, IoctlReadCommand, (LPVOID)NULL, @@ -328,7 +329,7 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen switch(pri->operation_status) { case SANG_STATUS_RX_DATA_AVAILABLE: - if(pri->data_length > datalen){ + if (pri->data_length > datalen){ break; } memcpy(databuf, rx_data.data, pri->data_length); @@ -384,7 +385,7 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle pri->data_length = datalen; memcpy(local_tx_data.data, databuf, pri->data_length); - if(!DeviceIoControl( + if (!DeviceIoControl( fd, IoctlWriteCommand, (LPVOID)&local_tx_data, @@ -406,18 +407,18 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle memset(&msg,0,sizeof(struct msghdr)); - iov[0].iov_len=hdrlen; - iov[0].iov_base=hdrbuf; + iov[0].iov_len = hdrlen; + iov[0].iov_base = hdrbuf; - iov[1].iov_len=datalen; - iov[1].iov_base=databuf; + iov[1].iov_len = datalen; + iov[1].iov_base = databuf; - msg.msg_iovlen=2; - msg.msg_iov=iov; + msg.msg_iovlen = 2; + msg.msg_iov = iov; - bsent = write(fd,&msg,datalen+hdrlen); + bsent = write(fd, &msg, datalen + hdrlen); if (bsent > 0){ - bsent-=sizeof(wp_tdm_api_tx_hdr_t); + bsent -= sizeof(wp_tdm_api_tx_hdr_t); } #endif return bsent; diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index 9a9b336ed1..557f23ea51 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -31,7 +31,7 @@ zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data); zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); void zap_thread_override_default_stacksize(zap_size_t size); zap_status_t zap_mutex_create(zap_mutex_t **mutex); -zap_status_t zap_mutex_destroy(zap_mutex_t *mutex); +zap_status_t zap_mutex_destroy(zap_mutex_t **mutex); zap_status_t zap_mutex_lock(zap_mutex_t *mutex); zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index d4ba2428db..9e189a138a 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -66,9 +66,9 @@ typedef enum { typedef enum { ZAP_NO_FLAGS = 0, - ZAP_READ = (1 << 0), - ZAP_WRITE = (1 << 1), - ZAP_ERROR = (1 << 2) + ZAP_READ = (1 << 0), + ZAP_WRITE = (1 << 1), + ZAP_EVENTS = (1 << 2) } zap_wait_flag_t; typedef enum { @@ -139,7 +139,7 @@ typedef struct zap_event zap_event_t; #define ZINT_OPEN_ARGS (zap_channel_t *zchan) #define ZINT_CLOSE_ARGS (zap_channel_t *zchan) #define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) +#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) #define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) #define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index b10227bb63..3550fed880 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -42,6 +42,7 @@ static struct { zap_hash_t *interface_hash; + zap_mutex_t *mutex; } globals; static char *LEVEL_NAMES[] = { @@ -158,6 +159,7 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); new_span->span_id = zint->span_index; new_span->zint = zint; + zap_mutex_create(&new_span->mutex); *span = new_span; return ZAP_SUCCESS; } @@ -165,6 +167,21 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) return ZAP_FAIL; } +zap_status_t zap_span_close_all(zap_software_interface_t *zint) +{ + zap_span_t *span; + uint32_t i; + + for(i = 0; i < zint->span_index; i++) { + span = &zint->spans[i]; + if (span->mutex) { + zap_mutex_destroy(&span->mutex); + } + } + + return i ? ZAP_SUCCESS : ZAP_FAIL; +} + zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { @@ -186,9 +203,13 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_software_interface_t *zint; zap_span_t *fspan; + zap_mutex_lock(globals.mutex); + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_mutex_unlock(globals.mutex); + if (!zint) { return ZAP_FAIL; } @@ -211,25 +232,33 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback) { + zap_mutex_lock(span->mutex); span->event_callback = event_callback; + zap_mutex_unlock(span->mutex); return ZAP_SUCCESS; } zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback) { + zap_mutex_lock(zchan->span->mutex); zchan->event_callback = event_callback; + zap_mutex_unlock(zchan->span->mutex); return ZAP_SUCCESS; } zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_software_interface_t *zint; zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; zap_span_t *span; uint32_t span_max; + zap_mutex_lock(globals.mutex); + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_mutex_unlock(globals.mutex); + if (!zint) { zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); return ZAP_FAIL; @@ -247,7 +276,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct j = span_max; } - + zap_mutex_lock(globals.mutex); for(;;) { span = &zint->spans[j]; @@ -314,25 +343,60 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct } } + zap_mutex_unlock(globals.mutex); + return status; } +static zap_status_t zap_channel_reset(zap_channel_t *zchan) +{ + zap_clear_flag(zchan, ZAP_CHANNEL_OPEN); + zchan->event_callback = NULL; + zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + if (zchan->tone_session.buffer) { + teletone_destroy_session(&zchan->tone_session); + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + } + if (zchan->dtmf_buffer) { + zap_buffer_destroy(&zchan->dtmf_buffer); + } + zchan->dtmf_on = zchan->dtmf_off = 0; + + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { + zchan->effective_codec = zchan->native_codec; + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); + } + + return ZAP_SUCCESS; +} + + + zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_software_interface_t *zint; zap_status_t status = ZAP_FAIL; + zap_mutex_lock(globals.mutex); + zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zap_mutex_unlock(globals.mutex); + + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { zap_channel_t *check; + zap_mutex_lock(zint->spans[span_id].mutex); check = &zint->spans[span_id].channels[chan_id]; + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zint->open(check); if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_OPEN); *zchan = check; } - return status; } + zap_mutex_unlock(zint->spans[span_id].mutex); } return status; @@ -347,25 +411,17 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) check = *zchan; assert(check != NULL); *zchan = NULL; - + + zap_mutex_lock(check->span->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zint->close(check); if (status == ZAP_SUCCESS) { - zap_clear_flag(check, ZAP_CHANNEL_OPEN); - check->event_callback = NULL; - zap_clear_flag(check, ZAP_CHANNEL_DTMF_DETECT); - zap_clear_flag(check, ZAP_CHANNEL_SUPRESS_DTMF); - if (check->tone_session.buffer) { - teletone_destroy_session(&check->tone_session); - memset(&check->tone_session, 0, sizeof(check->tone_session)); - } - if (check->dtmf_buffer) { - zap_buffer_destroy(&check->dtmf_buffer); - } - check->dtmf_on = check->dtmf_off = 0; + zap_channel_reset(check); *zchan = NULL; } } + + zap_mutex_unlock(check->span->mutex); return status; } @@ -405,6 +461,8 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { + zap_status_t status = ZAP_FAIL; + assert(zchan != NULL); assert(zchan->zint != NULL); @@ -413,6 +471,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo return ZAP_FAIL; } + zap_mutex_lock(zchan->span->mutex); + switch(command) { case ZAP_COMMAND_SET_INTERVAL: { @@ -424,7 +484,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_set_flag(zchan, ZAP_CHANNEL_BUFFER); } zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -432,7 +492,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { ZAP_COMMAND_OBJ_INT = zchan->effective_interval; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -446,7 +506,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); } zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -455,7 +515,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { ZAP_COMMAND_OBJ_INT = zchan->effective_codec; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -468,10 +528,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); zap_set_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_set_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -484,10 +544,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -495,7 +555,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -503,7 +563,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -513,10 +573,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_on = val; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -527,10 +587,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_off = val; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } } } @@ -538,16 +598,15 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_SEND_DTMF: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { - zap_status_t status; char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; if (!zchan->dtmf_buffer) { if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { - return status; + GOTO_STATUS(done, status); } } zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); - + for (cur = digits; *cur; cur++) { int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { @@ -556,7 +615,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } zchan->skip_read_frames = 200; - return ZAP_SUCCESS; + GOTO_STATUS(done, ZAP_SUCCESS); } } break; @@ -566,14 +625,18 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zchan->zint->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - return ZAP_FAIL; + GOTO_STATUS(done, ZAP_FAIL); } - return zchan->zint->command(zchan, command, obj); + status = zchan->zint->command(zchan, command, obj); + + done: + zap_mutex_unlock(zchan->span->mutex); + return status; } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, uint32_t to) +zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) { assert(zchan != NULL); assert(zchan->zint != NULL); @@ -899,30 +962,39 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat return status; } +static struct { + zap_software_interface_t *wanpipe_interface; + zap_software_interface_t *zt_interface; +} interfaces; + zap_status_t zap_global_init(void) { zap_config_t cfg; char *var, *val; uint32_t configured = 0; - zap_software_interface_t *zint; int modcount; + memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); - zint = NULL; modcount = 0; - + zap_mutex_create(&globals.mutex); + #ifdef ZAP_WANPIPE_SUPPORT - if (wanpipe_init(&zint) == ZAP_SUCCESS) { - hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); + zap_mutex_unlock(globals.mutex); modcount++; } else { zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n"); } #endif - zint = NULL; + #ifdef ZAP_ZT_SUPPORT - if (zt_init(&zint) == ZAP_SUCCESS) { - hashtable_insert(globals.interface_hash, (void *)zint->name, zint); + if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) { + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface); + zap_mutex_unlock(globals.mutex); modcount++; } else { zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n"); @@ -942,8 +1014,11 @@ zap_status_t zap_global_init(void) if (!strcasecmp(cfg.category, "openzap")) { if (!strcmp(var, "load")) { zap_software_interface_t *zint; - + + zap_mutex_lock(globals.mutex); zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); + zap_mutex_unlock(globals.mutex); + if (zint) { if (zint->configure(zint) == ZAP_SUCCESS) { configured++; @@ -967,16 +1042,21 @@ zap_status_t zap_global_init(void) zap_status_t zap_global_destroy(void) { - #ifdef ZAP_ZT_SUPPORT - zt_destroy(); + if (interfaces.zt_interface) { + zt_destroy(); + zap_span_close_all(interfaces.zt_interface); + } #endif #ifdef ZAP_WANPIPE_SUPPORT - wanpipe_destroy(); + if (interfaces.wanpipe_interface) { + wanpipe_destroy(); + zap_span_close_all(interfaces.wanpipe_interface); + } #endif hashtable_destroy(globals.interface_hash, 0); - + zap_mutex_destroy(&globals.mutex); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 8b9ae692ba..8160496c29 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -16,7 +16,8 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); top: - if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { + //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { + if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); @@ -42,7 +43,7 @@ int main(int argc, char *argv[]) zap_size_t len = sizeof(buf); zap_wait_flag_t flags = ZAP_READ; - if (zap_channel_wait(chan, &flags, 0) == ZAP_FAIL) { + if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { printf("wait FAIL! %d [%s]\n", len, chan->last_error); } if (flags & ZAP_READ) { diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 8fc4632fd3..34e23bec5c 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -170,15 +170,17 @@ done: return status; } -zap_status_t zap_mutex_destroy(zap_mutex_t *mutex) +zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) { + zap_mutex_t *mp = *mutex; + *mutex = NULL; #ifdef WIN32 - DeleteCriticalSection(&mutex->mutex); + DeleteCriticalSection(&mp->mutex); #else - if (pthread_mutex_destroy(&mutex->mutex)) + if (pthread_mutex_destroy(&mp->mutex)) return ZAP_FAIL; #endif - free(mutex); + free(mp); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 98325449e9..6386741e1f 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -346,14 +346,26 @@ static ZINT_WRITE_FUNCTION(wanpipe_write) static ZINT_WAIT_FUNCTION(wanpipe_wait) { - zap_wait_flag_t inflags = *flags; + int32_t inflags = 0; int result; - - result = tdmv_api_wait_socket(zchan->sockfd, to, inflags); + + if (*flags & ZAP_READ) { + inflags |= POLLIN; + } + + if (*flags & ZAP_WRITE) { + inflags |= POLLOUT; + } + + if (*flags & ZAP_EVENTS) { + inflags |= POLLPRI; + } + + result = tdmv_api_wait_socket(zchan->sockfd, to, &inflags); *flags = ZAP_NO_FLAGS; - if(result < 0){ + if (result < 0){ snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); return ZAP_FAIL; } @@ -362,16 +374,16 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) return ZAP_TIMEOUT; } - if (result & POLLIN) { + if (inflags & POLLIN) { *flags |= ZAP_READ; } - if (result & POLLOUT) { + if (inflags & POLLOUT) { *flags |= ZAP_WRITE; } - if (result & POLLPRI) { - *flags |= ZAP_ERROR; + if (inflags & POLLPRI) { + *flags |= ZAP_EVENTS; } return ZAP_SUCCESS; From 379379d7b7448566bd734bc0730e863fc3337d11 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 17:51:57 +0000 Subject: [PATCH 0125/1766] windows build fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@63 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 9e189a138a..2e7d5447f6 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -38,6 +38,7 @@ #include typedef HANDLE zap_socket_t; typedef unsigned __int32 uint32_t; +typedef __int32 int32_t; #else #include typedef int zap_socket_t; From 50de6bdc926a06ba17041c1e15316b97faee98e5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 17:51:57 +0000 Subject: [PATCH 0126/1766] windows build fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@63 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 9e189a138a..2e7d5447f6 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -38,6 +38,7 @@ #include typedef HANDLE zap_socket_t; typedef unsigned __int32 uint32_t; +typedef __int32 int32_t; #else #include typedef int zap_socket_t; From 5ab3190cc85544801e62a4a5954e2b53367d1b65 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 17:52:09 +0000 Subject: [PATCH 0127/1766] fix comment git-svn-id: http://svn.openzap.org/svn/openzap/trunk@64 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index b8b40d61fb..a9ef56add4 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -211,7 +211,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) #define POLLPRI (POLL_EVENT_LINK_STATE | POLL_EVENT_LINK_CONNECT | POLL_EVENT_LINK_DISCONNECT) #endif -/* return -1 for error, 0 for timeout, or POLLIN | POLLOUT | POLLPRI based on the result of the poll */ +/* 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? */ From eda2e86f5a1c8c93810cb2502db98cdb2a33b770 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 17:52:09 +0000 Subject: [PATCH 0128/1766] fix comment git-svn-id: http://svn.openzap.org/svn/openzap/trunk@64 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/sangoma_tdm_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index b8b40d61fb..a9ef56add4 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -211,7 +211,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) #define POLLPRI (POLL_EVENT_LINK_STATE | POLL_EVENT_LINK_CONNECT | POLL_EVENT_LINK_DISCONNECT) #endif -/* return -1 for error, 0 for timeout, or POLLIN | POLLOUT | POLLPRI based on the result of the poll */ +/* 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? */ From 70f5fc615326393ccff7cd92c30055d6a246f1c6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 18:25:36 +0000 Subject: [PATCH 0129/1766] checkin q931/q932/q921 code. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@65 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/EuroISDNStateNT.c | 46 + libs/openzap/src/isdn/EuroISDNStateTE.c | 57 + libs/openzap/src/isdn/Q921.c | 477 ++++ libs/openzap/src/isdn/Q931.c | 664 +++++ libs/openzap/src/isdn/Q931StateNT.c | 1259 ++++++++++ libs/openzap/src/isdn/Q931StateTE.c | 1315 ++++++++++ libs/openzap/src/isdn/Q931api.c | 614 +++++ libs/openzap/src/isdn/Q931ie.c | 2951 +++++++++++++++++++++++ libs/openzap/src/isdn/Q931mes.c | 1931 +++++++++++++++ libs/openzap/src/isdn/Q932mes.c | 311 +++ libs/openzap/src/isdn/include/Q921.h | 102 + libs/openzap/src/isdn/include/Q931.h | 2408 ++++++++++++++++++ libs/openzap/src/isdn/include/Q932.h | 191 ++ libs/openzap/src/isdn/include/mfifo.h | 83 + libs/openzap/src/isdn/mfifo.c | 296 +++ 15 files changed, 12705 insertions(+) create mode 100644 libs/openzap/src/isdn/EuroISDNStateNT.c create mode 100644 libs/openzap/src/isdn/EuroISDNStateTE.c create mode 100644 libs/openzap/src/isdn/Q921.c create mode 100644 libs/openzap/src/isdn/Q931.c create mode 100644 libs/openzap/src/isdn/Q931StateNT.c create mode 100644 libs/openzap/src/isdn/Q931StateTE.c create mode 100644 libs/openzap/src/isdn/Q931api.c create mode 100644 libs/openzap/src/isdn/Q931ie.c create mode 100644 libs/openzap/src/isdn/Q931mes.c create mode 100644 libs/openzap/src/isdn/Q932mes.c create mode 100644 libs/openzap/src/isdn/include/Q921.h create mode 100644 libs/openzap/src/isdn/include/Q931.h create mode 100644 libs/openzap/src/isdn/include/Q932.h create mode 100644 libs/openzap/src/isdn/include/mfifo.h create mode 100644 libs/openzap/src/isdn/mfifo.c diff --git a/libs/openzap/src/isdn/EuroISDNStateNT.c b/libs/openzap/src/isdn/EuroISDNStateNT.c new file mode 100644 index 0000000000..9c2fc45616 --- /dev/null +++ b/libs/openzap/src/isdn/EuroISDNStateNT.c @@ -0,0 +1,46 @@ +/***************************************************************************** + + 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 new file mode 100644 index 0000000000..cf0631c92b --- /dev/null +++ b/libs/openzap/src/isdn/EuroISDNStateTE.c @@ -0,0 +1,57 @@ +/***************************************************************************** + + 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 +*/ + +void EuroISDNCreateTE(L3UCHAR i) +{ + Q931CreateTE(i); +} diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c new file mode 100644 index 0000000000..c6be948c19 --- /dev/null +++ b/libs/openzap/src/isdn/Q921.c @@ -0,0 +1,477 @@ +/***************************************************************************** + + FileName: q921.c + + Description: Contains the implementation of a Q.921 protocol on top of the + Comet Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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. + +*****************************************************************************/ +#include "q921.h" +#include +#include "mfifo.h" + +/***************************************************************************** + Global Tables & Variables. +*****************************************************************************/ +Q921Data Q921DevSpace[Q921MAXTRUNK]; +int Q921HeaderSpace={0}; + +int (*Q921Tx21Proc)(int dev, unsigned char *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, unsigned char *, int)={NULL}; + +/***************************************************************************** + + Function: Q921Init + + Decription: Initialize the Q.921 stack so it is ready for use. This + function MUST be called as part of initializing the + application. + +*****************************************************************************/ +void Q921Init() +{ + int x; + for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ +// Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c new file mode 100644 index 0000000000..42b76ecdb3 --- /dev/null +++ b/libs/openzap/src/isdn/Q931.c @@ -0,0 +1,664 @@ +/***************************************************************************** + + 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 "Q931.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 dielects 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. + +*****************************************************************************/ +L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +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. + +*****************************************************************************/ + +L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + /* callback for messages to be send to */ + /* layer 4. */ + +L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); + /* callback ptr for messages to be send */ + /* to layer 2. */ + +void (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); + /* callback for error messages. */ + +L3ULONG (*Q931GetTimeProc) ()=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: Q931 + + Description: Dummy function for message processing. + +*****************************************************************************/ +L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) +{ + return Q931E_INTERNAL; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931PieDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931TxDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) +{ + return Q931E_MISSING_CB; +} + +/***************************************************************************** + + Function: Q931ErrorDummy + + Description: Dummy function for error processing + +*****************************************************************************/ +void Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) +{ +} + +/***************************************************************************** + + 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 diealect 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 */ + Q931Tx34Proc = Q931TxDummy; + Q931Tx32Proc = Q931TxDummy; + 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 0 : Warning + see q931errors.h for details. + +*****************************************************************************/ +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) +{ + L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; + L3INT ISize; + L3INT IOff = 0; + + /* Protocol Discriminator */ + m->ProtDisc = Mes[IOff++]; + + /* CRV */ + m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); + + /* Message Type */ + m->MesType = Mes[IOff++]; + + /* Call table proc to unpack codec message */ + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + } + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Tx34 + + Description: Called from the stac 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 *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + return Q931Tx34Proc(pTrunk, Mes, Size); +} + +/***************************************************************************** + + 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 *pTrunk,L3UCHAR * buf, L3INT Size) +{ + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + + 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 Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + L3INT OSize; + Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; + L3INT RetCode = Q931E_NO_ERROR; + L3INT iDialect = pTrunk->Dialect; + + /* Call pack function through table. */ + RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); + } + + 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 *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) +{ + Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); +} + +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx34Proc = Q931Tx34Par; +} + +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx32Proc = Q931Tx32Par; +} + +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) +{ + 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 *pTrunk, L3INT * callIndex) +{ + L3INT CRV = Q931GetUniqueCRV(pTrunk); + + return Q931AllocateCRV(pTrunk, CRV, callIndex); +} + +/***************************************************************************** + + 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 *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 *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 */ +} + +/***************************************************************************** + + Function: Q931StartTimer + + Description: Start a timer. + + Parameters: pTrunk Trunk number + callindex call index. + iTimer timer id +*****************************************************************************/ +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimerID) +{ + pTrunk->call[callIndex].Timer = Q931GetTime(); + pTrunk->call[callIndex].TimerID = iTimerID; + return 0; +} + +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimerID) +{ + if(pTrunk->call[callindex].TimerID == iTimerID) + pTrunk->call[callindex].TimerID = 0; + return 0; +} + +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState) +{ + pTrunk->call[callIndex].State = iState; + + return 0; +} + +L3ULONG Q931GetTime() +{ + L3ULONG tNow; + static L3ULONG tLast={0}; + if(Q931GetTimeProc != NULL) + { + tNow = Q931GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { + // todo + } + tLast = tNow; + } + return tNow; +} + +void Q931SetGetTimeCB(L3ULONG (*callback)()) +{ + Q931GetTimeProc = callback; +} + +L3INT Q931FindCRV(Q931_TrunkInfo *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 - sequensial 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; +} diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c new file mode 100644 index 0000000000..21adcfa05b --- /dev/null +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -0,0 +1,1259 @@ +/***************************************************************************** + + 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); + + /* 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 +} + +/***************************************************************************** + + Function: Q931ProcAlertingNT + +*****************************************************************************/ +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingNT + +*****************************************************************************/ +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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; + } + + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); + + Q931StartTimer(pTrunk, callIndex, 303); + } + + 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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 new file mode 100644 index 0000000000..f2a3507473 --- /dev/null +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -0,0 +1,1315 @@ +/***************************************************************************** + + 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); + + /* 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: Q931ProcAlertingTE + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingTE + +*****************************************************************************/ +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcConnectAckTE + +*****************************************************************************/ +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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; + } + + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); + + Q931StartTimer(pTrunk, callIndex, 303); + } + + 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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); + if(ret != Q931E_NO_ERROR) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + Q931StartTimer(pTrunk, callIndex, 303); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeTE + +*****************************************************************************/ +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; +// L3INT chanIndex; + 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=Q931Tx32(pTrunk,buf, pMes->Size); + if(ret != Q931E_NO_ERROR) + return ret; + + /* Start timer T318 */ + Q931StartTimer(pTrunk, callIndex, 318); + + /*set state U17 */ + Q931SetState(pTrunk, callIndex, Q931_U17); + } + else + { + return Q931E_ILLEGAL_MESSAGE; + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeAckTE + +*****************************************************************************/ +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + ret = Q931ReleaseComplete(pTrunk, iFrom); + } + else + { + ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); + } + + return ret; +} + +/***************************************************************************** + + Function: Q931ProcReleaseCompleteTE + +*****************************************************************************/ +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + /* no action */ + } + return 0; +} + +/***************************************************************************** + + Function: Q931ProcRestartTE + +*****************************************************************************/ +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcRestartAckTE + +*****************************************************************************/ +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 new file mode 100644 index 0000000000..079ae8301c --- /dev/null +++ b/libs/openzap/src/isdn/Q931api.c @@ -0,0 +1,614 @@ +/***************************************************************************** + + 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" + +/* +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; +} +*/ + +void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) +{ + int y; + pTrunk->LastCRV = 0; + pTrunk->Dialect = 0; + pTrunk->Enabled = 0; + pTrunk->TrunkType = Q931_TrType_E1; + pTrunk->NetUser = Q931_TE; + pTrunk->TrunkState = 0; + for(y=0; y < Q931MAXCHPERTRUNK; y++) + { + pTrunk->ch[y].Available = 1; + + /* Set up E1 scheme by default */ + if(y==0) + { + pTrunk->ch[y].ChanType = Q931_ChType_Sync; + } + else if(y==16) + { + pTrunk->ch[y].ChanType = Q931_ChType_D; + } + else + { + pTrunk->ch[y].ChanType = Q931_ChType_B; + } + } + + for(y=0; y < Q931MAXCALLPERTRUNK; y++) + { + pTrunk->call[y].InUse = 0; + + } +} + +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +) +{ + 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, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +) +{ + if(Q931PieProc != NULL) + Q931Pie[dialect][iec] = Q931PieProc; + if(Q931UieProc != NULL) + Q931Uie[dialect][iec] = Q931UieProc; +} + +#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} + +/***************************************************************************** + + Function: Q931GetIEBuf + + Description: Return a ptr to the buf used for IE in the message. + +*****************************************************************************/ +L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) +{ + L3UCHAR * s=NULL; + Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + switch(pMes->MesType) + { + case Q931mes_ALERTING : + trampoline(Q931mes_Alerting); + break; + + case Q931mes_CALL_PROCEEDING : + trampoline(Q931mes_CallProceeding); + break; + + case Q931mes_CONNECT : + trampoline(Q931mes_Connect); + break; + + case Q931mes_CONNECT_ACKNOWLEDGE : + trampoline(Q931mes_ConnectAck); + break; + + case Q931mes_PROGRESS : + trampoline(Q931mes_Progress); + break; + + case Q931mes_SETUP : + trampoline(Q931mes_Setup); + break; + + case Q931mes_SETUP_ACKNOWLEDGE : + trampoline(Q931mes_SetupAck); + break; + + case Q931mes_RESUME : + trampoline(Q931mes_Resume); + break; + + case Q931mes_RESUME_ACKNOWLEDGE : + trampoline(Q931mes_ResumeAck); + break; + + case Q931mes_RESUME_REJECT : + trampoline(Q931mes_ResumeReject); + break; + + case Q932mes_RETRIEVE : + trampoline(Q932mes_Retrieve); + break; + + case Q932mes_RETRIEVE_ACKNOWLEDGE : + trampoline(Q932mes_RetrieveAck); + break; + + case Q932mes_RETRIEVE_REJECT : + trampoline(Q932mes_RetrieveReject); + break; + + case Q931mes_SUSPEND : + trampoline(Q931mes_Suspend); + break; + + case Q931mes_SUSPEND_ACKNOWLEDGE : + trampoline(Q931mes_SuspendAck); + break; + + case Q931mes_SUSPEND_REJECT : + trampoline(Q931mes_SuspendReject); + break; + + case Q931mes_USER_INFORMATION : + trampoline(Q931mes_UserInformation); + break; + + case Q931mes_DISCONNECT : + trampoline(Q931mes_Disconnect); + break; + + case Q931mes_RELEASE : + trampoline(Q931mes_Release); + break; + + case Q931mes_RELEASE_COMPLETE : + trampoline(Q931mes_ReleaseComplete); + break; + + case Q931mes_RESTART : + trampoline(Q931mes_Restart); + break; + + case Q931mes_RESTART_ACKNOWLEDGE : + trampoline(Q931mes_RestartAck); + break; + + case Q931mes_CONGESTION_CONTROL : + trampoline(Q931mes_CongestionControl); + break; + +// case Q931mes_FACILITY : +// trampoline(Q931mes_Facility); +// break; + + case Q931mes_INFORMATION : + trampoline(Q931mes_Information); + break; + + case Q931mes_NOTIFY : + trampoline(Q931mes_Notify); + break; + +// case Q931mes_REGISTER : +// trampoline(Q931mes_Register); +// break; + + case Q931mes_STATUS : + trampoline(Q931mes_Status); + break; + + case Q931mes_STATUS_ENQUIRY : + trampoline(Q931mes_StatusEnquiry); + break; + + case Q931mes_SEGMENT : + trampoline(Q931mes_Segment); + break; + + default: + s = 0; + break; + } + + return s; +} + +L3INT Q931GetMesSize(L3UCHAR *pMes) +{ + + L3UCHAR *p = Q931GetIEBuf(pMes); + L3INT Size = (L3INT)(p - 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_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; + L3INT iISize = pIE->Size; + + L3UCHAR *pBuf = Q931GetIEBuf(pm); + L3INT Off = pMes->Size - (pBuf - pm); + IE = Off | 0x8000; + + memcpy(&pm[pMes->Size], pi, iISize); + + pMes->Size += iISize; + + return IE; +} + +/***************************************************************************** +*****************************************************************************/ +L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) +{ + static L3INT crv={1}; + return crv++; +} + +L3INT Q931InitMesSetup(Q931mes_Setup *pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_SETUP; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + + pMes->SendComplete =0; /* Sending Complete */ + pMes->RepeatInd =0; /* Repeat Indicator */ + pMes->BearerCap =0; /* Bearer Capability */ + pMes->ChanID =0; /* Channel ID */ + pMes->ProgInd =0; /* Progress Indicator */ + pMes->NetFac =0; /* Network-specific facilities */ + pMes->Display =0; /* Display */ + pMes->DateTime =0; /* Date/Time */ + pMes->KeypadFac =0; /* Keypad Facility */ + pMes->Signal =0; /* Signal */ + pMes->CallingNum =0; /* Calling party number */ + pMes->CallingSub =0; /* Calling party sub address */ + pMes->CalledNum =0; /* Called party number */ + pMes->CalledSub =0; /* Called party sub address */ + pMes->TransNetSel =0; /* Transit network selection */ + pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ + pMes->LLComp =0; /* Low layer compatibility */ + pMes->HLComp =0; /* High layer compatibility */ + + return 0; +} + +L3INT Q931InitMesResume(Q931mes_Resume * pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_RESUME; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->CallID = 0; /* Channel Identification */ + 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 */ +// pIE->ModeX25op = 0; /* Mode of operation X.25 */ + 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 *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + return 0; +} + +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + return 0; +} + +L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) +{ + return 0; +} + +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) +{ + return 0; +} diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c new file mode 100644 index 0000000000..d9cddbb16d --- /dev/null +++ b/libs/openzap/src/isdn/Q931ie.c @@ -0,0 +1,2951 @@ +/***************************************************************************** + + 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" + +/***************************************************************************** + + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; + L3INT rc=0; + L3INT Beg=*Octet;/* remember current offset */ + L3INT li; + + OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; + li=(*Octet)++; /* remember length position */ + + /* Octet 3 - Coding standard / Information transfer capability */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); + + /* Octet 4 - Transfer mode / Information transfer rate */ + if(pIE->ITR == 0x18) + { + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + } + else + { + OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + + /* Octet 4.1 - Rate Multiplier */ + OBuf[(*Octet)++] = 0x80 | pIE->RateMul; + } + + /* 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) | (pIE->UIL1Prot & 0x15); + + /* Octet 5a - SyncAsync/Negot/UserRate */ + OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (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) + | (pIE->NIConTx << 4) + | (pIE->NIConRx << 3) + | (pIE->FlowCtlTx << 2) + | (pIE->FlowCtlRx << 1); + } + else if(pIE->UIL1Prot == 0x08) /* ITU V.120 */ + { + /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/ + OBuf[(*Octet)++] = 0x00 + | (pIE->InterRate << 6) + | (pIE->MultiFrame << 5) + | (pIE->Mode << 4) + | (pIE->LLInegot << 3) + | (pIE->Assignor << 2) + | (pIE->InBandNeg << 1); + } + + /* Octet 5c - NumStopBits/NumStartBits/Parity */ + OBuf[(*Octet)++] = 0x00 + | (pIE->NumStopBits << 5 ) + | (pIE->NumDataBits << 3 ) + | (pIE->Parity); + + /* Octet 5d - Duplex Mode/Modem Type */ + OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); + } + } + + /* Octet 6 - Layer2Ident/User information layer 2 prtocol */ + if(pIE->Layer2Ident == 0x02) + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot); + } + + /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ + if(pIE->Layer3Ident == 0x03) + { + if(pIE->UIL3Prot == 0x0c) + { + OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + + /* Octet 7a - Additional information layer 3 msb */ + OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); + + /* Octet 7b - Additional information layer 3 lsb */ + OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + } + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + do{ + pie->CallId[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while(IBuf[Octet+Off]&0x80 != 0 && x < 10); + + Q931IESizeTest(Q931E_CALLID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; + pie->Size = sizeof(Q931ie_CallID) + x -1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallState); + pie->Size = sizeof(Q931ie_CallState); + + Q931SetIE(*pIE, *OOff); + + 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 *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)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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(IBuf[Octet+Off]&0x80 != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLEDSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = sizeof(Q931ie_CalledSub) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; /* # digits in this case */ + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; + pie->NumPlanID = IBuf[Octet+Off] & 0x0f; + Octet ++; + + /* Octet 4*/ + for (x = 0; x < IESize && x < 20; x++) + { + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = sizeof(Q931ie_CalledNum) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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_NUMBER; + 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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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 4a*/ + x=0; + do{ + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGNUM); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = sizeof(Q931ie_CallingNum) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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_CalledSub) + 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 3a */ + /* + + Details about the use and how to detect if Octet 3a is used + are very weak. Temp left out. + + Octet 3 msb is set to 1 to indicate that this is not present + + */ + + /* Octet 4 */ + for(x=0;xDigit[x]; + } + + OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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(IBuf[Octet+Off]&0x80 != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; + pie->Size = sizeof(Q931ie_CallingSub) + x -1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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; + + Q931IESizeTest(Q931E_CAUSE); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Cause); + pie->Size = sizeof(Q931ie_Cause); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->CongLevel = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CongLevel); + pie->Size = sizeof(Q931ie_CongLevel); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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], Off); + Octet++; + + /* 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++; + } + else + { + /* 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; + Off = Q931ReadExt(&IBuf[Octet+Off], Off); + Off++; + } + } + + Q931IESizeTest(Q931E_CHANID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *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) + | (pIE->IntType<<5) + | (pIE->PrefExcl<<3) + | pIE->InfoChanSel; + + /* Octet 3.1 - Interface Identifier */ + if(pIE->IntIDPresent) + { + OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID; + } + else + { + /* Octet 3.2 & 3.3 - PRI */ + if(pIE->IntType == 1) + { + OBuf[(*Octet)++] = 0x80 + | (pIE->CodStand << 5) + | (pIE->NumMap << 4) + | pIE->ChanMapType; + + /* Octet 3.2 Channel number/slot map */ + OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; + } + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + L3INT Octet = *IOff; + L3INT l = IBuf[Octet]; + L3USHORT CRV; + Octet++; /*Octet 2 is length indicator */ + + if(l == 1) /* One octet CRV */ + { + CRV = IBuf[Octet]; + Octet++; + } + else if(l==2) /* two octet CRV */ + { + CRV = IBuf[Octet] << 8; + CRV += IBuf[Octet+1]; + Octet += 2; + } + else + { + /* Long CRV is not used, so we skip this */ + 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 *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize=0; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + IESize = 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 + ********************************************************************/ + pie->Format=0; + + /* Octet 6 - Hour (optional)*/ + if(IESize >= 6) + { + pie->Format = 1; + pie->Hour = IBuf[Octet++]; + + /* Octet 7 - Minute (optional)*/ + if(IESize >= 7) + { + pie->Format = 2; + pie->Minute = IBuf[Octet++]; + + /* Octet 8 - Second (optional)*/ + if(IESize >= 8) + { + pie->Format = 3; + pie->Second = IBuf[Octet++]; + } + } + } + + Q931IESizeTest(Q931E_DATETIME); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_DateTime); + pie->Size = sizeof(Q931ie_DateTime); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Display * pie = (Q931ie_Display*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_DISPLAY); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; + pie->Size = sizeof(Q931ie_Display) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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) + 1; + + for(x=0; x< DSize; x++) + { + + OBuf[(*Octet)++] = pIE->Display[x]; + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_HLComp); + pie->Size = sizeof(Q931ie_HLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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) | (pIE->Interpret << 2) | pIE->PresMeth; + + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->HLCharID; + + /* Octet 4a */ + if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) + { + OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; + } + else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) + { + OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; + } + else + { + OBuf[(*Octet)-1] |= 0x80; + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_KEYPADFAC); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = sizeof(Q931ie_KeypadFac) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; + pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; + pie->Parity =IBuf[Octet+Off] & 0x07; + Off++; + + /* Octet 5d */ + if(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + pie->DefPackSize = IBuf[Octet+Off] & 0x0f; + Off++; + + /* Octet 7c */ + if(IBuf[Octet+Off-1] & 0x80 != 0) + { + pie->PackWinSize= IBuf[Octet+Off] & 0x7f; + } + } + } + } + } + else + { + Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); + return Q931E_LLCOMP; + } + + Q931IESizeTest(Q931E_LLCOMP); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_LLComp); + pie->Size = sizeof(Q931ie_LLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; + pie->Size = sizeof(Q931ie_NetFac) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Notification = IBuf[Octet+Off] & 0x7f; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_NOTIFIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NotifInd); + pie->Size = sizeof(Q931ie_NotifInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ProgInd); + pie->Size = sizeof(Q931ie_ProgInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->RepeatInd = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); + pie->Size = sizeof(Q931ie_RepeatInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + ie iE; + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Class = IBuf[Octet+Off] & 0x07; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_RESTARTIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RestartInd); + pie->Size = sizeof(Q931ie_RestartInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Segment); + pie->Size = sizeof(Q931ie_Segment); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_SendComplete); + pie->Size = sizeof(Q931ie_SendComplete); + + Q931SetIE(*pIE, *OOff); + + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; + L3INT rc=Q931E_NO_ERROR; + L3INT Beg=*Octet; +// L3INT li; + + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Signal = IBuf[Octet+Off]; + Octet++; + + Q931IESizeTest(Q931E_SIGNAL); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Signal); + pie->Size = sizeof(Q931ie_Signal); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* 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++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = sizeof(Q931ie_TransNetSel) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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;xNetID[x]; + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* Octet 3*/ + pie->ProtDisc = IBuf[Octet+Off]; + Octet++; + + for(x=0; x < l; x++) + { + pie->User[x] = IBuf[Octet+Off]; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; + pie->Size = sizeof(Q931ie_UserUser) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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;xUser[x]; + } + + OBuf[li] = (*Octet)-Beg; + return rc; +} + diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c new file mode 100644 index 0000000000..d2066d0358 --- /dev/null +++ b/libs/openzap/src/isdn/Q931mes.c @@ -0,0 +1,1931 @@ +/***************************************************************************** + + 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" + +/***************************************************************************** + + Function: Q931Umes_Alerting + +*****************************************************************************/ + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; + L3INT rc=Q931E_NO_ERROR; + L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; + while(IOff < Size) + { + switch(mescode) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Alerting + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CallProceeding + +*****************************************************************************/ +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_CallProceeding + +*****************************************************************************/ +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CongestionControl + +*****************************************************************************/ +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + + +/***************************************************************************** + + Function: Q931Pmes_CongestionControl + +*****************************************************************************/ +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Connect + +*****************************************************************************/ +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Connect + +*****************************************************************************/ +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Low Layer Compatibility */ + if(Q931IsIEPresent(pMes->LLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ConnectAck + +*****************************************************************************/ +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ConnectAck + +*****************************************************************************/ +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Disconnect + +*****************************************************************************/ +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Disconnect + +*****************************************************************************/ +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Information + +*****************************************************************************/ +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Information *mes = (Q931mes_Information*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Information) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Information + +*****************************************************************************/ +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Information *pMes = (Q931mes_Information *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Sending Complete */ + if(Q931IsIEPresent(pMes->SendComplete)) + OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Notify + +*****************************************************************************/ +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_NOTIFICATION_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + } + } + mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Notify + +*****************************************************************************/ +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Progress + +*****************************************************************************/ +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Progress + +*****************************************************************************/ +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Release + +*****************************************************************************/ +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Release *mes = (Q931mes_Release*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Release) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Release + +*****************************************************************************/ +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Release *pMes = (Q931mes_Release *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Resume + +*****************************************************************************/ +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Resume + +*****************************************************************************/ +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeAck + +*****************************************************************************/ +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeAck + +*****************************************************************************/ +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeReject + +*****************************************************************************/ +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeReject + +*****************************************************************************/ +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +{ + L3INT i = IOff; + + return IOff - i; +} + +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Setup + +*****************************************************************************/ +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_REPEAT_INDICATOR: + if(ir==0) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else if(ir==1) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else + { + return Q931E_ILLEGAL_IE; + } + break; + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_NETWORK_SPECIFIC_FACILITIES: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_TRANSIT_NETWORK_SELECTION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Setup + + Decription: Pack a Q931mes_Setup 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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Network spesific facilities */ + if(Q931IsIEPresent(pMes->NetFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Number */ + if(Q931IsIEPresent(pMes->CallingNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Subaddress */ + if(Q931IsIEPresent(pMes->CallingSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called party subaddress */ + if(Q931IsIEPresent(pMes->CalledSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Transit network selection */ + if(Q931IsIEPresent(pMes->TransNetSel)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Repeat Indicator */ + if(Q931IsIEPresent(pMes->LLRepeatInd)) + ;//TODO + + /* Low Layer Compatibility */ + if(Q931IsIEPresent(pMes->LLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SetupAck + +*****************************************************************************/ +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SetupAck + +*****************************************************************************/ +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Status + +*****************************************************************************/ +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Status *mes = (Q931mes_Status*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALL_STATE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Status) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_Status + +*****************************************************************************/ +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Status *pMes = (Q931mes_Status *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Call State */ + if(Q931IsIEPresent(pMes->CallState)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Suspend + +*****************************************************************************/ +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Suspend + +*****************************************************************************/ +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendAck + +*****************************************************************************/ +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendAck + +*****************************************************************************/ +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendReject + +*****************************************************************************/ +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendReject + +*****************************************************************************/ +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_UserInformation + +*****************************************************************************/ +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_UserInformation + +*****************************************************************************/ +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c new file mode 100644 index 0000000000..0540fa80f0 --- /dev/null +++ b/libs/openzap/src/isdn/Q932mes.c @@ -0,0 +1,311 @@ +/***************************************************************************** + + 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 *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + L3INT rc=Q931E_NO_ERROR; + Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Facility + +*****************************************************************************/ +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Hold + +*****************************************************************************/ + +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Hold + +*****************************************************************************/ +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldAck + +*****************************************************************************/ + +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldAck + +*****************************************************************************/ +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldReject + +*****************************************************************************/ + +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldReject + +*****************************************************************************/ +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Register + +*****************************************************************************/ + +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_Register *mes = (Q932mes_Register*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Register) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Register + +*****************************************************************************/ +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Retrieve + +*****************************************************************************/ + +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Retrieve + +*****************************************************************************/ +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveAck + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveAck + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveReject + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveReject + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h new file mode 100644 index 0000000000..acb830383f --- /dev/null +++ b/libs/openzap/src/isdn/include/Q921.h @@ -0,0 +1,102 @@ +/***************************************************************************** + + FileName: q921.h + + Description: Contains headers of a Q.921 protocol on top of the Comet + Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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 3 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. + + Q921Tx23 Send a message to layer 3. + + OnQ921Error Function called every if an error is + deteceted. + + OnQ921Log Function called if logging is active. + + + Maintenance/Configuration interface + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXTRUNK 4 +#define Q921MAXHDLCSPACE 3000 + +typedef struct +{ + char HDLCInQueue[Q921MAXHDLCSPACE]; + unsigned char vs; + unsigned char vr; + int state; +}Q921Data; + +void Q921Init(); +void Q921SetHeaderSpace(int hspace); +void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)); +void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)); +int Q921QueueHDLCFrame(int trunk, char *b, int size); +int Q921Rx12(long trunk); + +#endif + diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h new file mode 100644 index 0000000000..dd8261cff3 --- /dev/null +++ b/libs/openzap/src/isdn/include/Q931.h @@ -0,0 +1,2408 @@ +/****************************************************************************** + + 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" + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 Q931L4BUF 1000 /* size of message buffer */ + +#define Q931L2BUF 300 /* size of message buffer */ + +#define Q931MAXTRUNKS 1 /* 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + L3USHORT 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 */ + L3USHORT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ + +typedef struct +{ + enum _NetUser /* Network/User Mode. */ + { + Q931_TE=0, /* 0 : User Mode */ + Q931_NT=1 /* 1 : Network Mode */ + }NetUser; + + L3UCHAR Dialect; /* Q.931 Based dielact index. */ + + enum _TrunkType /* 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 */ + }TrunkType; + + L3UCHAR Enabled; /* Enabled/Disabled */ + /* 0 = Disabled */ + /* 1 = Enabled */ + + enum _TrState /* Trunk State */ + { + Q931_TrState_NoAlignment=0, /* Trunk not aligned */ + Q931_TrState_Aligning=1, /* Aligning in progress */ + Q931_TrState_Aligned=2, /* Trunk Aligned */ + }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 send 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. */ + + /* 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 + { + enum _ChanType{ + 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 */ + }ChanType; + + 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }call[Q931MAXCALLPERTRUNK]; + +}Q931_TrunkInfo; + +/***************************************************************************** + + 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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); +void Q931CreateTE(L3UCHAR i); +void Q931CreateNT(L3UCHAR i); +void Q931SetMesCreateCB(L3INT (*callback)()); +void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +#endif /* _Q931_NL */ diff --git a/libs/openzap/src/isdn/include/Q932.h b/libs/openzap/src/isdn/include/Q932.h new file mode 100644 index 0000000000..fa17e38ae7 --- /dev/null +++ b/libs/openzap/src/isdn/include/Q932.h @@ -0,0 +1,191 @@ +/***************************************************************************** + + 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 */ + +/***************************************************************************** + Struct: Q932ie_Facility +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Facility; + +/***************************************************************************** + Struct: Q932ie_Hold +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Hold; + +/***************************************************************************** + Struct: Q932ie_HoldAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldAck; + +/***************************************************************************** + Struct: Q932ie_HoldReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldReject; + +/***************************************************************************** + Struct: Q932ie_Register +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Register; + +/***************************************************************************** + Struct: Q932ie_Retrieve +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Retrieve; + +/***************************************************************************** + Struct: Q932ie_RetrieveAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveAck; + +/***************************************************************************** + Struct: Q932ie_RetrieveReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveReject; + +/***************************************************************************** + Function Prototypes. +*****************************************************************************/ +L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); diff --git a/libs/openzap/src/isdn/include/mfifo.h b/libs/openzap/src/isdn/include/mfifo.h new file mode 100644 index 0000000000..21a053173e --- /dev/null +++ b/libs/openzap/src/isdn/include/mfifo.h @@ -0,0 +1,83 @@ +/***************************************************************************** + + 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 _mfifo +{ + int first; /* first out */ + int last; /* last in + 1 */ + int bsize; /* buffer size */ + char *buf; /* ptr to start of buffer */ + int ixsize; /* index size */ + MINDEX ix[1]; /* message index */ +}MFIFO; + +/***************************************************************************** + Function prototypes. +*****************************************************************************/ +int MFIFOCreate(char *buf, int size, int index); +void MFIFOClear(char * buf); +int MFIFOGetLBOffset(char *buf); +int MFIFOGetFBOffset(char *buf); +void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off); +int MFIFOWriteMes(char *buf, char *mes, int size); +char * MFIFOGetMesPtr(char *buf, int *size); +void MFIFOKillNext(char *buf); + +#endif diff --git a/libs/openzap/src/isdn/mfifo.c b/libs/openzap/src/isdn/mfifo.c new file mode 100644 index 0000000000..adf6bc9ebd --- /dev/null +++ b/libs/openzap/src/isdn/mfifo.c @@ -0,0 +1,296 @@ +/***************************************************************************** + + 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(char *buf, int size, int index) +{ + MFIFO * mf; + mf = (MFIFO*)buf; + + mf->first = mf->last = 0; + mf->ixsize = index; + mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; + + if(mf->buf > & buf[size]) + return 0; + + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); + + return 1; +} + +/***************************************************************************** + + Function: MFIFOClear + + Description: Clear the FIFO + + Paremeters: buf ptr to fifo + + Return Value: none + +*****************************************************************************/ +void MFIFOClear(char * buf) +{ + MFIFO * mf; + 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(char *buf) +{ + MFIFO * mf; + 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(char *buf) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->last == mf->first) + return 0; + x=mf->first; + x--; + if(x<0) + x=mf->ixsize; + 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(char *buf, char *mes, int size, int ix, int off) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + 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(char *buf, char *mes, int size) +{ + int of,ol,x; + MFIFO * mf; + mf = (MFIFO*)buf; + + 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: + +*****************************************************************************/ +char * MFIFOGetMesPtr(char *buf, int *size) +{ + MFIFO * mf; + 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(char *buf) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->first!=mf->last) + { + x = mf->last+1; + if(x > mf->ixsize) + x=0; + mf->last=x; + } +} From 3925468083c336407a114faa27de45404c63d4a9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 18:25:36 +0000 Subject: [PATCH 0130/1766] checkin q931/q932/q921 code. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@65 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/EuroISDNStateNT.c | 46 + libs/freetdm/src/isdn/EuroISDNStateTE.c | 57 + libs/freetdm/src/isdn/Q921.c | 477 ++++ libs/freetdm/src/isdn/Q931.c | 664 +++++ libs/freetdm/src/isdn/Q931StateNT.c | 1259 ++++++++++ libs/freetdm/src/isdn/Q931StateTE.c | 1315 ++++++++++ libs/freetdm/src/isdn/Q931api.c | 614 +++++ libs/freetdm/src/isdn/Q931ie.c | 2951 +++++++++++++++++++++++ libs/freetdm/src/isdn/Q931mes.c | 1931 +++++++++++++++ libs/freetdm/src/isdn/Q932mes.c | 311 +++ libs/freetdm/src/isdn/include/Q921.h | 102 + libs/freetdm/src/isdn/include/Q931.h | 2408 ++++++++++++++++++ libs/freetdm/src/isdn/include/Q932.h | 191 ++ libs/freetdm/src/isdn/include/mfifo.h | 83 + libs/freetdm/src/isdn/mfifo.c | 296 +++ 15 files changed, 12705 insertions(+) create mode 100644 libs/freetdm/src/isdn/EuroISDNStateNT.c create mode 100644 libs/freetdm/src/isdn/EuroISDNStateTE.c create mode 100644 libs/freetdm/src/isdn/Q921.c create mode 100644 libs/freetdm/src/isdn/Q931.c create mode 100644 libs/freetdm/src/isdn/Q931StateNT.c create mode 100644 libs/freetdm/src/isdn/Q931StateTE.c create mode 100644 libs/freetdm/src/isdn/Q931api.c create mode 100644 libs/freetdm/src/isdn/Q931ie.c create mode 100644 libs/freetdm/src/isdn/Q931mes.c create mode 100644 libs/freetdm/src/isdn/Q932mes.c create mode 100644 libs/freetdm/src/isdn/include/Q921.h create mode 100644 libs/freetdm/src/isdn/include/Q931.h create mode 100644 libs/freetdm/src/isdn/include/Q932.h create mode 100644 libs/freetdm/src/isdn/include/mfifo.h create mode 100644 libs/freetdm/src/isdn/mfifo.c diff --git a/libs/freetdm/src/isdn/EuroISDNStateNT.c b/libs/freetdm/src/isdn/EuroISDNStateNT.c new file mode 100644 index 0000000000..9c2fc45616 --- /dev/null +++ b/libs/freetdm/src/isdn/EuroISDNStateNT.c @@ -0,0 +1,46 @@ +/***************************************************************************** + + 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/freetdm/src/isdn/EuroISDNStateTE.c b/libs/freetdm/src/isdn/EuroISDNStateTE.c new file mode 100644 index 0000000000..cf0631c92b --- /dev/null +++ b/libs/freetdm/src/isdn/EuroISDNStateTE.c @@ -0,0 +1,57 @@ +/***************************************************************************** + + 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 +*/ + +void EuroISDNCreateTE(L3UCHAR i) +{ + Q931CreateTE(i); +} diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c new file mode 100644 index 0000000000..c6be948c19 --- /dev/null +++ b/libs/freetdm/src/isdn/Q921.c @@ -0,0 +1,477 @@ +/***************************************************************************** + + FileName: q921.c + + Description: Contains the implementation of a Q.921 protocol on top of the + Comet Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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. + +*****************************************************************************/ +#include "q921.h" +#include +#include "mfifo.h" + +/***************************************************************************** + Global Tables & Variables. +*****************************************************************************/ +Q921Data Q921DevSpace[Q921MAXTRUNK]; +int Q921HeaderSpace={0}; + +int (*Q921Tx21Proc)(int dev, unsigned char *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, unsigned char *, int)={NULL}; + +/***************************************************************************** + + Function: Q921Init + + Decription: Initialize the Q.921 stack so it is ready for use. This + function MUST be called as part of initializing the + application. + +*****************************************************************************/ +void Q921Init() +{ + int x; + for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ +// Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c new file mode 100644 index 0000000000..42b76ecdb3 --- /dev/null +++ b/libs/freetdm/src/isdn/Q931.c @@ -0,0 +1,664 @@ +/***************************************************************************** + + 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 "Q931.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 dielects 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. + +*****************************************************************************/ +L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +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. + +*****************************************************************************/ + +L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + /* callback for messages to be send to */ + /* layer 4. */ + +L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); + /* callback ptr for messages to be send */ + /* to layer 2. */ + +void (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); + /* callback for error messages. */ + +L3ULONG (*Q931GetTimeProc) ()=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: Q931 + + Description: Dummy function for message processing. + +*****************************************************************************/ +L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) +{ + return Q931E_INTERNAL; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931PieDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931TxDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) +{ + return Q931E_MISSING_CB; +} + +/***************************************************************************** + + Function: Q931ErrorDummy + + Description: Dummy function for error processing + +*****************************************************************************/ +void Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) +{ +} + +/***************************************************************************** + + 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 diealect 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 */ + Q931Tx34Proc = Q931TxDummy; + Q931Tx32Proc = Q931TxDummy; + 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 0 : Warning + see q931errors.h for details. + +*****************************************************************************/ +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) +{ + L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; + L3INT ISize; + L3INT IOff = 0; + + /* Protocol Discriminator */ + m->ProtDisc = Mes[IOff++]; + + /* CRV */ + m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); + + /* Message Type */ + m->MesType = Mes[IOff++]; + + /* Call table proc to unpack codec message */ + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + } + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Tx34 + + Description: Called from the stac 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 *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + return Q931Tx34Proc(pTrunk, Mes, Size); +} + +/***************************************************************************** + + 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 *pTrunk,L3UCHAR * buf, L3INT Size) +{ + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + + 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 Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + L3INT OSize; + Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; + L3INT RetCode = Q931E_NO_ERROR; + L3INT iDialect = pTrunk->Dialect; + + /* Call pack function through table. */ + RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); + } + + 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 *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) +{ + Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); +} + +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx34Proc = Q931Tx34Par; +} + +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx32Proc = Q931Tx32Par; +} + +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) +{ + 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 *pTrunk, L3INT * callIndex) +{ + L3INT CRV = Q931GetUniqueCRV(pTrunk); + + return Q931AllocateCRV(pTrunk, CRV, callIndex); +} + +/***************************************************************************** + + 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 *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 *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 */ +} + +/***************************************************************************** + + Function: Q931StartTimer + + Description: Start a timer. + + Parameters: pTrunk Trunk number + callindex call index. + iTimer timer id +*****************************************************************************/ +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimerID) +{ + pTrunk->call[callIndex].Timer = Q931GetTime(); + pTrunk->call[callIndex].TimerID = iTimerID; + return 0; +} + +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimerID) +{ + if(pTrunk->call[callindex].TimerID == iTimerID) + pTrunk->call[callindex].TimerID = 0; + return 0; +} + +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState) +{ + pTrunk->call[callIndex].State = iState; + + return 0; +} + +L3ULONG Q931GetTime() +{ + L3ULONG tNow; + static L3ULONG tLast={0}; + if(Q931GetTimeProc != NULL) + { + tNow = Q931GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { + // todo + } + tLast = tNow; + } + return tNow; +} + +void Q931SetGetTimeCB(L3ULONG (*callback)()) +{ + Q931GetTimeProc = callback; +} + +L3INT Q931FindCRV(Q931_TrunkInfo *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 - sequensial 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; +} diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c new file mode 100644 index 0000000000..21adcfa05b --- /dev/null +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -0,0 +1,1259 @@ +/***************************************************************************** + + 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); + + /* 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 +} + +/***************************************************************************** + + Function: Q931ProcAlertingNT + +*****************************************************************************/ +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingNT + +*****************************************************************************/ +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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; + } + + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); + + Q931StartTimer(pTrunk, callIndex, 303); + } + + 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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c new file mode 100644 index 0000000000..f2a3507473 --- /dev/null +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -0,0 +1,1315 @@ +/***************************************************************************** + + 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); + + /* 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: Q931ProcAlertingTE + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingTE + +*****************************************************************************/ +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcConnectAckTE + +*****************************************************************************/ +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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; + } + + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); + + Q931StartTimer(pTrunk, callIndex, 303); + } + + 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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); + if(ret != Q931E_NO_ERROR) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + Q931StartTimer(pTrunk, callIndex, 303); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeTE + +*****************************************************************************/ +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; +// L3INT chanIndex; + 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=Q931Tx32(pTrunk,buf, pMes->Size); + if(ret != Q931E_NO_ERROR) + return ret; + + /* Start timer T318 */ + Q931StartTimer(pTrunk, callIndex, 318); + + /*set state U17 */ + Q931SetState(pTrunk, callIndex, Q931_U17); + } + else + { + return Q931E_ILLEGAL_MESSAGE; + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeAckTE + +*****************************************************************************/ +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + ret = Q931ReleaseComplete(pTrunk, iFrom); + } + else + { + ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); + } + + return ret; +} + +/***************************************************************************** + + Function: Q931ProcReleaseCompleteTE + +*****************************************************************************/ +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + /* no action */ + } + return 0; +} + +/***************************************************************************** + + Function: Q931ProcRestartTE + +*****************************************************************************/ +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcRestartAckTE + +*****************************************************************************/ +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c new file mode 100644 index 0000000000..079ae8301c --- /dev/null +++ b/libs/freetdm/src/isdn/Q931api.c @@ -0,0 +1,614 @@ +/***************************************************************************** + + 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" + +/* +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; +} +*/ + +void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) +{ + int y; + pTrunk->LastCRV = 0; + pTrunk->Dialect = 0; + pTrunk->Enabled = 0; + pTrunk->TrunkType = Q931_TrType_E1; + pTrunk->NetUser = Q931_TE; + pTrunk->TrunkState = 0; + for(y=0; y < Q931MAXCHPERTRUNK; y++) + { + pTrunk->ch[y].Available = 1; + + /* Set up E1 scheme by default */ + if(y==0) + { + pTrunk->ch[y].ChanType = Q931_ChType_Sync; + } + else if(y==16) + { + pTrunk->ch[y].ChanType = Q931_ChType_D; + } + else + { + pTrunk->ch[y].ChanType = Q931_ChType_B; + } + } + + for(y=0; y < Q931MAXCALLPERTRUNK; y++) + { + pTrunk->call[y].InUse = 0; + + } +} + +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +) +{ + 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, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +) +{ + if(Q931PieProc != NULL) + Q931Pie[dialect][iec] = Q931PieProc; + if(Q931UieProc != NULL) + Q931Uie[dialect][iec] = Q931UieProc; +} + +#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} + +/***************************************************************************** + + Function: Q931GetIEBuf + + Description: Return a ptr to the buf used for IE in the message. + +*****************************************************************************/ +L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) +{ + L3UCHAR * s=NULL; + Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + switch(pMes->MesType) + { + case Q931mes_ALERTING : + trampoline(Q931mes_Alerting); + break; + + case Q931mes_CALL_PROCEEDING : + trampoline(Q931mes_CallProceeding); + break; + + case Q931mes_CONNECT : + trampoline(Q931mes_Connect); + break; + + case Q931mes_CONNECT_ACKNOWLEDGE : + trampoline(Q931mes_ConnectAck); + break; + + case Q931mes_PROGRESS : + trampoline(Q931mes_Progress); + break; + + case Q931mes_SETUP : + trampoline(Q931mes_Setup); + break; + + case Q931mes_SETUP_ACKNOWLEDGE : + trampoline(Q931mes_SetupAck); + break; + + case Q931mes_RESUME : + trampoline(Q931mes_Resume); + break; + + case Q931mes_RESUME_ACKNOWLEDGE : + trampoline(Q931mes_ResumeAck); + break; + + case Q931mes_RESUME_REJECT : + trampoline(Q931mes_ResumeReject); + break; + + case Q932mes_RETRIEVE : + trampoline(Q932mes_Retrieve); + break; + + case Q932mes_RETRIEVE_ACKNOWLEDGE : + trampoline(Q932mes_RetrieveAck); + break; + + case Q932mes_RETRIEVE_REJECT : + trampoline(Q932mes_RetrieveReject); + break; + + case Q931mes_SUSPEND : + trampoline(Q931mes_Suspend); + break; + + case Q931mes_SUSPEND_ACKNOWLEDGE : + trampoline(Q931mes_SuspendAck); + break; + + case Q931mes_SUSPEND_REJECT : + trampoline(Q931mes_SuspendReject); + break; + + case Q931mes_USER_INFORMATION : + trampoline(Q931mes_UserInformation); + break; + + case Q931mes_DISCONNECT : + trampoline(Q931mes_Disconnect); + break; + + case Q931mes_RELEASE : + trampoline(Q931mes_Release); + break; + + case Q931mes_RELEASE_COMPLETE : + trampoline(Q931mes_ReleaseComplete); + break; + + case Q931mes_RESTART : + trampoline(Q931mes_Restart); + break; + + case Q931mes_RESTART_ACKNOWLEDGE : + trampoline(Q931mes_RestartAck); + break; + + case Q931mes_CONGESTION_CONTROL : + trampoline(Q931mes_CongestionControl); + break; + +// case Q931mes_FACILITY : +// trampoline(Q931mes_Facility); +// break; + + case Q931mes_INFORMATION : + trampoline(Q931mes_Information); + break; + + case Q931mes_NOTIFY : + trampoline(Q931mes_Notify); + break; + +// case Q931mes_REGISTER : +// trampoline(Q931mes_Register); +// break; + + case Q931mes_STATUS : + trampoline(Q931mes_Status); + break; + + case Q931mes_STATUS_ENQUIRY : + trampoline(Q931mes_StatusEnquiry); + break; + + case Q931mes_SEGMENT : + trampoline(Q931mes_Segment); + break; + + default: + s = 0; + break; + } + + return s; +} + +L3INT Q931GetMesSize(L3UCHAR *pMes) +{ + + L3UCHAR *p = Q931GetIEBuf(pMes); + L3INT Size = (L3INT)(p - 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_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; + L3INT iISize = pIE->Size; + + L3UCHAR *pBuf = Q931GetIEBuf(pm); + L3INT Off = pMes->Size - (pBuf - pm); + IE = Off | 0x8000; + + memcpy(&pm[pMes->Size], pi, iISize); + + pMes->Size += iISize; + + return IE; +} + +/***************************************************************************** +*****************************************************************************/ +L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) +{ + static L3INT crv={1}; + return crv++; +} + +L3INT Q931InitMesSetup(Q931mes_Setup *pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_SETUP; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + + pMes->SendComplete =0; /* Sending Complete */ + pMes->RepeatInd =0; /* Repeat Indicator */ + pMes->BearerCap =0; /* Bearer Capability */ + pMes->ChanID =0; /* Channel ID */ + pMes->ProgInd =0; /* Progress Indicator */ + pMes->NetFac =0; /* Network-specific facilities */ + pMes->Display =0; /* Display */ + pMes->DateTime =0; /* Date/Time */ + pMes->KeypadFac =0; /* Keypad Facility */ + pMes->Signal =0; /* Signal */ + pMes->CallingNum =0; /* Calling party number */ + pMes->CallingSub =0; /* Calling party sub address */ + pMes->CalledNum =0; /* Called party number */ + pMes->CalledSub =0; /* Called party sub address */ + pMes->TransNetSel =0; /* Transit network selection */ + pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ + pMes->LLComp =0; /* Low layer compatibility */ + pMes->HLComp =0; /* High layer compatibility */ + + return 0; +} + +L3INT Q931InitMesResume(Q931mes_Resume * pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_RESUME; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->CallID = 0; /* Channel Identification */ + 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 */ +// pIE->ModeX25op = 0; /* Mode of operation X.25 */ + 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 *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + return 0; +} + +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + return 0; +} + +L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) +{ + return 0; +} + +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) +{ + return 0; +} diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c new file mode 100644 index 0000000000..d9cddbb16d --- /dev/null +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -0,0 +1,2951 @@ +/***************************************************************************** + + 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" + +/***************************************************************************** + + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; + L3INT rc=0; + L3INT Beg=*Octet;/* remember current offset */ + L3INT li; + + OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; + li=(*Octet)++; /* remember length position */ + + /* Octet 3 - Coding standard / Information transfer capability */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); + + /* Octet 4 - Transfer mode / Information transfer rate */ + if(pIE->ITR == 0x18) + { + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + } + else + { + OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + + /* Octet 4.1 - Rate Multiplier */ + OBuf[(*Octet)++] = 0x80 | pIE->RateMul; + } + + /* 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) | (pIE->UIL1Prot & 0x15); + + /* Octet 5a - SyncAsync/Negot/UserRate */ + OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (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) + | (pIE->NIConTx << 4) + | (pIE->NIConRx << 3) + | (pIE->FlowCtlTx << 2) + | (pIE->FlowCtlRx << 1); + } + else if(pIE->UIL1Prot == 0x08) /* ITU V.120 */ + { + /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/ + OBuf[(*Octet)++] = 0x00 + | (pIE->InterRate << 6) + | (pIE->MultiFrame << 5) + | (pIE->Mode << 4) + | (pIE->LLInegot << 3) + | (pIE->Assignor << 2) + | (pIE->InBandNeg << 1); + } + + /* Octet 5c - NumStopBits/NumStartBits/Parity */ + OBuf[(*Octet)++] = 0x00 + | (pIE->NumStopBits << 5 ) + | (pIE->NumDataBits << 3 ) + | (pIE->Parity); + + /* Octet 5d - Duplex Mode/Modem Type */ + OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); + } + } + + /* Octet 6 - Layer2Ident/User information layer 2 prtocol */ + if(pIE->Layer2Ident == 0x02) + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot); + } + + /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ + if(pIE->Layer3Ident == 0x03) + { + if(pIE->UIL3Prot == 0x0c) + { + OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + + /* Octet 7a - Additional information layer 3 msb */ + OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); + + /* Octet 7b - Additional information layer 3 lsb */ + OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + } + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + do{ + pie->CallId[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while(IBuf[Octet+Off]&0x80 != 0 && x < 10); + + Q931IESizeTest(Q931E_CALLID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; + pie->Size = sizeof(Q931ie_CallID) + x -1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallState); + pie->Size = sizeof(Q931ie_CallState); + + Q931SetIE(*pIE, *OOff); + + 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 *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)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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(IBuf[Octet+Off]&0x80 != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLEDSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = sizeof(Q931ie_CalledSub) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; /* # digits in this case */ + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; + pie->NumPlanID = IBuf[Octet+Off] & 0x0f; + Octet ++; + + /* Octet 4*/ + for (x = 0; x < IESize && x < 20; x++) + { + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = sizeof(Q931ie_CalledNum) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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_NUMBER; + 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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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 4a*/ + x=0; + do{ + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGNUM); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = sizeof(Q931ie_CallingNum) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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_CalledSub) + 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 3a */ + /* + + Details about the use and how to detect if Octet 3a is used + are very weak. Temp left out. + + Octet 3 msb is set to 1 to indicate that this is not present + + */ + + /* Octet 4 */ + for(x=0;xDigit[x]; + } + + OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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(IBuf[Octet+Off]&0x80 != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; + pie->Size = sizeof(Q931ie_CallingSub) + x -1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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; + + Q931IESizeTest(Q931E_CAUSE); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Cause); + pie->Size = sizeof(Q931ie_Cause); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->CongLevel = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CongLevel); + pie->Size = sizeof(Q931ie_CongLevel); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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], Off); + Octet++; + + /* 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++; + } + else + { + /* 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; + Off = Q931ReadExt(&IBuf[Octet+Off], Off); + Off++; + } + } + + Q931IESizeTest(Q931E_CHANID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *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) + | (pIE->IntType<<5) + | (pIE->PrefExcl<<3) + | pIE->InfoChanSel; + + /* Octet 3.1 - Interface Identifier */ + if(pIE->IntIDPresent) + { + OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID; + } + else + { + /* Octet 3.2 & 3.3 - PRI */ + if(pIE->IntType == 1) + { + OBuf[(*Octet)++] = 0x80 + | (pIE->CodStand << 5) + | (pIE->NumMap << 4) + | pIE->ChanMapType; + + /* Octet 3.2 Channel number/slot map */ + OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; + } + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + L3INT Octet = *IOff; + L3INT l = IBuf[Octet]; + L3USHORT CRV; + Octet++; /*Octet 2 is length indicator */ + + if(l == 1) /* One octet CRV */ + { + CRV = IBuf[Octet]; + Octet++; + } + else if(l==2) /* two octet CRV */ + { + CRV = IBuf[Octet] << 8; + CRV += IBuf[Octet+1]; + Octet += 2; + } + else + { + /* Long CRV is not used, so we skip this */ + 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 *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize=0; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + IESize = 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 + ********************************************************************/ + pie->Format=0; + + /* Octet 6 - Hour (optional)*/ + if(IESize >= 6) + { + pie->Format = 1; + pie->Hour = IBuf[Octet++]; + + /* Octet 7 - Minute (optional)*/ + if(IESize >= 7) + { + pie->Format = 2; + pie->Minute = IBuf[Octet++]; + + /* Octet 8 - Second (optional)*/ + if(IESize >= 8) + { + pie->Format = 3; + pie->Second = IBuf[Octet++]; + } + } + } + + Q931IESizeTest(Q931E_DATETIME); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_DateTime); + pie->Size = sizeof(Q931ie_DateTime); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Display * pie = (Q931ie_Display*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_DISPLAY); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; + pie->Size = sizeof(Q931ie_Display) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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) + 1; + + for(x=0; x< DSize; x++) + { + + OBuf[(*Octet)++] = pIE->Display[x]; + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_HLComp); + pie->Size = sizeof(Q931ie_HLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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) | (pIE->Interpret << 2) | pIE->PresMeth; + + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->HLCharID; + + /* Octet 4a */ + if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) + { + OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; + } + else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) + { + OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; + } + else + { + OBuf[(*Octet)-1] |= 0x80; + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_KEYPADFAC); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = sizeof(Q931ie_KeypadFac) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; + pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; + pie->Parity =IBuf[Octet+Off] & 0x07; + Off++; + + /* Octet 5d */ + if(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + + 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(IBuf[Octet+Off-1] & 0x80 != 0) + { + pie->DefPackSize = IBuf[Octet+Off] & 0x0f; + Off++; + + /* Octet 7c */ + if(IBuf[Octet+Off-1] & 0x80 != 0) + { + pie->PackWinSize= IBuf[Octet+Off] & 0x7f; + } + } + } + } + } + else + { + Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); + return Q931E_LLCOMP; + } + + Q931IESizeTest(Q931E_LLCOMP); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_LLComp); + pie->Size = sizeof(Q931ie_LLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; + pie->Size = sizeof(Q931ie_NetFac) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Notification = IBuf[Octet+Off] & 0x7f; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_NOTIFIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NotifInd); + pie->Size = sizeof(Q931ie_NotifInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ProgInd); + pie->Size = sizeof(Q931ie_ProgInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->RepeatInd = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); + pie->Size = sizeof(Q931ie_RepeatInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + ie iE; + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Class = IBuf[Octet+Off] & 0x07; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_RESTARTIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RestartInd); + pie->Size = sizeof(Q931ie_RestartInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Segment); + pie->Size = sizeof(Q931ie_Segment); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_SendComplete); + pie->Size = sizeof(Q931ie_SendComplete); + + Q931SetIE(*pIE, *OOff); + + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; + L3INT rc=Q931E_NO_ERROR; + L3INT Beg=*Octet; +// L3INT li; + + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Signal = IBuf[Octet+Off]; + Octet++; + + Q931IESizeTest(Q931E_SIGNAL); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Signal); + pie->Size = sizeof(Q931ie_Signal); + + Q931SetIE(*pIE, *OOff); + + 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 *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] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* 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++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = sizeof(Q931ie_TransNetSel) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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;xNetID[x]; + } + + OBuf[li] = (*Octet)-Beg; + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* Octet 3*/ + pie->ProtDisc = IBuf[Octet+Off]; + Octet++; + + for(x=0; x < l; x++) + { + pie->User[x] = IBuf[Octet+Off]; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; + pie->Size = sizeof(Q931ie_UserUser) + x - 1; + + Q931SetIE(*pIE, *OOff); + + 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 *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;xUser[x]; + } + + OBuf[li] = (*Octet)-Beg; + return rc; +} + diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c new file mode 100644 index 0000000000..d2066d0358 --- /dev/null +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -0,0 +1,1931 @@ +/***************************************************************************** + + 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" + +/***************************************************************************** + + Function: Q931Umes_Alerting + +*****************************************************************************/ + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; + L3INT rc=Q931E_NO_ERROR; + L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; + while(IOff < Size) + { + switch(mescode) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Alerting + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CallProceeding + +*****************************************************************************/ +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_CallProceeding + +*****************************************************************************/ +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CongestionControl + +*****************************************************************************/ +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + + +/***************************************************************************** + + Function: Q931Pmes_CongestionControl + +*****************************************************************************/ +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Connect + +*****************************************************************************/ +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Connect + +*****************************************************************************/ +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Low Layer Compatibility */ + if(Q931IsIEPresent(pMes->LLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ConnectAck + +*****************************************************************************/ +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ConnectAck + +*****************************************************************************/ +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Disconnect + +*****************************************************************************/ +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Disconnect + +*****************************************************************************/ +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Information + +*****************************************************************************/ +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Information *mes = (Q931mes_Information*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Information) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Information + +*****************************************************************************/ +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Information *pMes = (Q931mes_Information *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Sending Complete */ + if(Q931IsIEPresent(pMes->SendComplete)) + OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Notify + +*****************************************************************************/ +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_NOTIFICATION_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + } + } + mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Notify + +*****************************************************************************/ +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Progress + +*****************************************************************************/ +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Progress + +*****************************************************************************/ +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Release + +*****************************************************************************/ +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Release *mes = (Q931mes_Release*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Release) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Release + +*****************************************************************************/ +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Release *pMes = (Q931mes_Release *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Resume + +*****************************************************************************/ +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Resume + +*****************************************************************************/ +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeAck + +*****************************************************************************/ +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeAck + +*****************************************************************************/ +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeReject + +*****************************************************************************/ +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeReject + +*****************************************************************************/ +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +{ + L3INT i = IOff; + + return IOff - i; +} + +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Setup + +*****************************************************************************/ +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_REPEAT_INDICATOR: + if(ir==0) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else if(ir==1) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else + { + return Q931E_ILLEGAL_IE; + } + break; + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_NETWORK_SPECIFIC_FACILITIES: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_TRANSIT_NETWORK_SELECTION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Setup + + Decription: Pack a Q931mes_Setup 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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Network spesific facilities */ + if(Q931IsIEPresent(pMes->NetFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Number */ + if(Q931IsIEPresent(pMes->CallingNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Subaddress */ + if(Q931IsIEPresent(pMes->CallingSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called party subaddress */ + if(Q931IsIEPresent(pMes->CalledSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Transit network selection */ + if(Q931IsIEPresent(pMes->TransNetSel)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Repeat Indicator */ + if(Q931IsIEPresent(pMes->LLRepeatInd)) + ;//TODO + + /* Low Layer Compatibility */ + if(Q931IsIEPresent(pMes->LLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SetupAck + +*****************************************************************************/ +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SetupAck + +*****************************************************************************/ +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Status + +*****************************************************************************/ +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Status *mes = (Q931mes_Status*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALL_STATE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Status) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_Status + +*****************************************************************************/ +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Status *pMes = (Q931mes_Status *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Call State */ + if(Q931IsIEPresent(pMes->CallState)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Suspend + +*****************************************************************************/ +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Suspend + +*****************************************************************************/ +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendAck + +*****************************************************************************/ +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendAck + +*****************************************************************************/ +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendReject + +*****************************************************************************/ +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendReject + +*****************************************************************************/ +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_UserInformation + +*****************************************************************************/ +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_UserInformation + +*****************************************************************************/ +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c new file mode 100644 index 0000000000..0540fa80f0 --- /dev/null +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -0,0 +1,311 @@ +/***************************************************************************** + + 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 *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + L3INT rc=Q931E_NO_ERROR; + Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Facility + +*****************************************************************************/ +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Hold + +*****************************************************************************/ + +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Hold + +*****************************************************************************/ +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldAck + +*****************************************************************************/ + +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldAck + +*****************************************************************************/ +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldReject + +*****************************************************************************/ + +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldReject + +*****************************************************************************/ +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Register + +*****************************************************************************/ + +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_Register *mes = (Q932mes_Register*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Register) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Register + +*****************************************************************************/ +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Retrieve + +*****************************************************************************/ + +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Retrieve + +*****************************************************************************/ +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveAck + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveAck + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveReject + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT i = IOff; + L3INT ir=0; + L3INT OOff=0; + Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; + + //TODO + + mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveReject + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h new file mode 100644 index 0000000000..acb830383f --- /dev/null +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -0,0 +1,102 @@ +/***************************************************************************** + + FileName: q921.h + + Description: Contains headers of a Q.921 protocol on top of the Comet + Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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 3 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. + + Q921Tx23 Send a message to layer 3. + + OnQ921Error Function called every if an error is + deteceted. + + OnQ921Log Function called if logging is active. + + + Maintenance/Configuration interface + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXTRUNK 4 +#define Q921MAXHDLCSPACE 3000 + +typedef struct +{ + char HDLCInQueue[Q921MAXHDLCSPACE]; + unsigned char vs; + unsigned char vr; + int state; +}Q921Data; + +void Q921Init(); +void Q921SetHeaderSpace(int hspace); +void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)); +void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)); +int Q921QueueHDLCFrame(int trunk, char *b, int size); +int Q921Rx12(long trunk); + +#endif + diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h new file mode 100644 index 0000000000..dd8261cff3 --- /dev/null +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -0,0 +1,2408 @@ +/****************************************************************************** + + 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" + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 Q931L4BUF 1000 /* size of message buffer */ + +#define Q931L2BUF 300 /* size of message buffer */ + +#define Q931MAXTRUNKS 1 /* 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + L3USHORT 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 */ + L3USHORT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ + +typedef struct +{ + enum _NetUser /* Network/User Mode. */ + { + Q931_TE=0, /* 0 : User Mode */ + Q931_NT=1 /* 1 : Network Mode */ + }NetUser; + + L3UCHAR Dialect; /* Q.931 Based dielact index. */ + + enum _TrunkType /* 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 */ + }TrunkType; + + L3UCHAR Enabled; /* Enabled/Disabled */ + /* 0 = Disabled */ + /* 1 = Enabled */ + + enum _TrState /* Trunk State */ + { + Q931_TrState_NoAlignment=0, /* Trunk not aligned */ + Q931_TrState_Aligning=1, /* Aligning in progress */ + Q931_TrState_Aligned=2, /* Trunk Aligned */ + }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 send 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. */ + + /* 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 + { + enum _ChanType{ + 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 */ + }ChanType; + + 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }call[Q931MAXCALLPERTRUNK]; + +}Q931_TrunkInfo; + +/***************************************************************************** + + 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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); +void Q931CreateTE(L3UCHAR i); +void Q931CreateNT(L3UCHAR i); +void Q931SetMesCreateCB(L3INT (*callback)()); +void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +#endif /* _Q931_NL */ diff --git a/libs/freetdm/src/isdn/include/Q932.h b/libs/freetdm/src/isdn/include/Q932.h new file mode 100644 index 0000000000..fa17e38ae7 --- /dev/null +++ b/libs/freetdm/src/isdn/include/Q932.h @@ -0,0 +1,191 @@ +/***************************************************************************** + + 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 */ + +/***************************************************************************** + Struct: Q932ie_Facility +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Facility; + +/***************************************************************************** + Struct: Q932ie_Hold +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Hold; + +/***************************************************************************** + Struct: Q932ie_HoldAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldAck; + +/***************************************************************************** + Struct: Q932ie_HoldReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldReject; + +/***************************************************************************** + Struct: Q932ie_Register +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Register; + +/***************************************************************************** + Struct: Q932ie_Retrieve +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Retrieve; + +/***************************************************************************** + Struct: Q932ie_RetrieveAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveAck; + +/***************************************************************************** + Struct: Q932ie_RetrieveReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveReject; + +/***************************************************************************** + Function Prototypes. +*****************************************************************************/ +L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); diff --git a/libs/freetdm/src/isdn/include/mfifo.h b/libs/freetdm/src/isdn/include/mfifo.h new file mode 100644 index 0000000000..21a053173e --- /dev/null +++ b/libs/freetdm/src/isdn/include/mfifo.h @@ -0,0 +1,83 @@ +/***************************************************************************** + + 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 _mfifo +{ + int first; /* first out */ + int last; /* last in + 1 */ + int bsize; /* buffer size */ + char *buf; /* ptr to start of buffer */ + int ixsize; /* index size */ + MINDEX ix[1]; /* message index */ +}MFIFO; + +/***************************************************************************** + Function prototypes. +*****************************************************************************/ +int MFIFOCreate(char *buf, int size, int index); +void MFIFOClear(char * buf); +int MFIFOGetLBOffset(char *buf); +int MFIFOGetFBOffset(char *buf); +void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off); +int MFIFOWriteMes(char *buf, char *mes, int size); +char * MFIFOGetMesPtr(char *buf, int *size); +void MFIFOKillNext(char *buf); + +#endif diff --git a/libs/freetdm/src/isdn/mfifo.c b/libs/freetdm/src/isdn/mfifo.c new file mode 100644 index 0000000000..adf6bc9ebd --- /dev/null +++ b/libs/freetdm/src/isdn/mfifo.c @@ -0,0 +1,296 @@ +/***************************************************************************** + + 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(char *buf, int size, int index) +{ + MFIFO * mf; + mf = (MFIFO*)buf; + + mf->first = mf->last = 0; + mf->ixsize = index; + mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; + + if(mf->buf > & buf[size]) + return 0; + + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); + + return 1; +} + +/***************************************************************************** + + Function: MFIFOClear + + Description: Clear the FIFO + + Paremeters: buf ptr to fifo + + Return Value: none + +*****************************************************************************/ +void MFIFOClear(char * buf) +{ + MFIFO * mf; + 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(char *buf) +{ + MFIFO * mf; + 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(char *buf) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->last == mf->first) + return 0; + x=mf->first; + x--; + if(x<0) + x=mf->ixsize; + 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(char *buf, char *mes, int size, int ix, int off) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + 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(char *buf, char *mes, int size) +{ + int of,ol,x; + MFIFO * mf; + mf = (MFIFO*)buf; + + 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: + +*****************************************************************************/ +char * MFIFOGetMesPtr(char *buf, int *size) +{ + MFIFO * mf; + 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(char *buf) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->first!=mf->last) + { + x = mf->last+1; + if(x > mf->ixsize) + x=0; + mf->last=x; + } +} From 0ae4f34c0c46eb91e5332ef5169030eade56a59e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 18:34:46 +0000 Subject: [PATCH 0131/1766] fixing make... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@66 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 25 +++++++++++++++++++++++-- libs/openzap/src/isdn/Q921.c | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 50e4b6ba7b..c657c3f179 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -30,8 +30,29 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o zap_threadmutex.o -CFLAGS=$(ZAP_CFLAGS) -Iinclude +OBJS=hashtable.o \ +hashtable_itr.o \ +openzap.o \ +zap_config.o \ +g711.o \ +libteletone_detect.o \ +libteletone_generate.o \ +zap_buffer.o \ +zap_threadmutex.o \ +isdn/EuroISDNStateNT.o \ +isdn/EuroISDNStateTE.o \ +isdn/mfifo.o \ +isdn/Q921.o \ +isdn/Q931api.o \ +isdn/Q931.o \ +isdn/Q931ie.o \ +isdn/Q931mes.o \ +isdn/Q931StateNT.o \ +isdn/Q931StateTE.o \ +isdn/Q932mes.o + + +CFLAGS=$(ZAP_CFLAGS) -I`pwd`/include -I`pwd`/isdn/include MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index c6be948c19..81e709ba19 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "q921.h" +#include "Q921.h" #include #include "mfifo.h" From 40bd360d8976ebf7746c7ba2055149e3d8f4decf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 18:34:46 +0000 Subject: [PATCH 0132/1766] fixing make... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@66 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 25 +++++++++++++++++++++++-- libs/freetdm/src/isdn/Q921.c | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 50e4b6ba7b..c657c3f179 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -30,8 +30,29 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -OBJS=hashtable.o hashtable_itr.o openzap.o zap_config.o g711.o libteletone_detect.o libteletone_generate.o zap_buffer.o zap_threadmutex.o -CFLAGS=$(ZAP_CFLAGS) -Iinclude +OBJS=hashtable.o \ +hashtable_itr.o \ +openzap.o \ +zap_config.o \ +g711.o \ +libteletone_detect.o \ +libteletone_generate.o \ +zap_buffer.o \ +zap_threadmutex.o \ +isdn/EuroISDNStateNT.o \ +isdn/EuroISDNStateTE.o \ +isdn/mfifo.o \ +isdn/Q921.o \ +isdn/Q931api.o \ +isdn/Q931.o \ +isdn/Q931ie.o \ +isdn/Q931mes.o \ +isdn/Q931StateNT.o \ +isdn/Q931StateTE.o \ +isdn/Q932mes.o + + +CFLAGS=$(ZAP_CFLAGS) -I`pwd`/include -I`pwd`/isdn/include MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index c6be948c19..81e709ba19 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "q921.h" +#include "Q921.h" #include #include "mfifo.h" From 23043a7e4dd833f254f0a47c3c287e56991f1088 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 18:51:13 +0000 Subject: [PATCH 0133/1766] windows build add isdn files git-svn-id: http://svn.openzap.org/svn/openzap/trunk@67 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 72 +++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index cfc5413696..e37c43672c 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -40,7 +40,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From db59ea91139bfcb45b79be41a31c81d51ebefe6d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 18:51:13 +0000 Subject: [PATCH 0134/1766] windows build add isdn files git-svn-id: http://svn.openzap.org/svn/openzap/trunk@67 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 72 +++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index cfc5413696..e37c43672c 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -40,7 +40,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From bd9ea0319792ba5be0932ae9cdc9b2c610af9095 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 18:53:58 +0000 Subject: [PATCH 0135/1766] normalize using unsigned char for buffers instead of mixed signed/unsigned in isdn code. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@68 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 26 +++++++++++++------------- libs/openzap/src/isdn/Q932mes.c | 1 - libs/openzap/src/isdn/include/Q921.h | 4 ++-- libs/openzap/src/isdn/include/Q931.h | 6 ++++++ libs/openzap/src/isdn/include/mfifo.h | 18 +++++++++--------- libs/openzap/src/isdn/mfifo.c | 16 ++++++++-------- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 81e709ba19..1396471570 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "Q921.h" +#include "q921.h" #include #include "mfifo.h" @@ -111,7 +111,7 @@ void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, char *b, int size) +int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) { return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); } @@ -135,7 +135,7 @@ int Q921QueueHDLCFrame(int trunk, char *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, char *mes, int size) +int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, unsigned char *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -164,7 +164,7 @@ int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -191,7 +191,7 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -218,7 +218,7 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -245,7 +245,7 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -271,7 +271,7 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -316,7 +316,7 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -342,7 +342,7 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -389,7 +389,7 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) //{ //} -int Q921ProcSABME(int trunk, char *mes, int size) +int Q921ProcSABME(int trunk, unsigned char *mes, int size) { Q921DevSpace[trunk].vr=0; Q921DevSpace[trunk].vs=0; @@ -417,9 +417,9 @@ int Q921ProcSABME(int trunk, char *mes, int size) *****************************************************************************/ int Q921Rx12(long trunk) { - char *mes; + unsigned char *mes; int rs,size; /* receive size & Q921 frame size*/ - char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + unsigned char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index 0540fa80f0..c0cf6505c3 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -48,7 +48,6 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT i = IOff; L3INT ir=0; L3INT OOff=0; - L3INT rc=Q931E_NO_ERROR; Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; //TODO diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index acb830383f..5537a17aeb 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -85,7 +85,7 @@ typedef struct { - char HDLCInQueue[Q921MAXHDLCSPACE]; + unsigned char HDLCInQueue[Q921MAXHDLCSPACE]; unsigned char vs; unsigned char vr; int state; @@ -95,7 +95,7 @@ void Q921Init(); void Q921SetHeaderSpace(int hspace); void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)); void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)); -int Q921QueueHDLCFrame(int trunk, char *b, int size); +int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size); int Q921Rx12(long trunk); #endif diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index dd8261cff3..6e71a27420 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -112,6 +112,12 @@ #include "stdio.h" +#ifdef _MSC_VER +/* warning C4100 : unreferenced formal parameter */ +/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled*/ +#pragma warning(disable:4100 4189) +#endif + /***************************************************************************** Error Codes diff --git a/libs/openzap/src/isdn/include/mfifo.h b/libs/openzap/src/isdn/include/mfifo.h index 21a053173e..788adfdb10 100644 --- a/libs/openzap/src/isdn/include/mfifo.h +++ b/libs/openzap/src/isdn/include/mfifo.h @@ -63,7 +63,7 @@ typedef struct _mfifo int first; /* first out */ int last; /* last in + 1 */ int bsize; /* buffer size */ - char *buf; /* ptr to start of buffer */ + unsigned char *buf; /* ptr to start of buffer */ int ixsize; /* index size */ MINDEX ix[1]; /* message index */ }MFIFO; @@ -71,13 +71,13 @@ typedef struct _mfifo /***************************************************************************** Function prototypes. *****************************************************************************/ -int MFIFOCreate(char *buf, int size, int index); -void MFIFOClear(char * buf); -int MFIFOGetLBOffset(char *buf); -int MFIFOGetFBOffset(char *buf); -void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off); -int MFIFOWriteMes(char *buf, char *mes, int size); -char * MFIFOGetMesPtr(char *buf, int *size); -void MFIFOKillNext(char *buf); +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); #endif diff --git a/libs/openzap/src/isdn/mfifo.c b/libs/openzap/src/isdn/mfifo.c index adf6bc9ebd..9e409f8a92 100644 --- a/libs/openzap/src/isdn/mfifo.c +++ b/libs/openzap/src/isdn/mfifo.c @@ -82,7 +82,7 @@ Return value: 0 if failure, 1 if ok. *****************************************************************************/ -int MFIFOCreate(char *buf, int size, int index) +int MFIFOCreate(unsigned char *buf, int size, int index) { MFIFO * mf; mf = (MFIFO*)buf; @@ -110,7 +110,7 @@ int MFIFOCreate(char *buf, int size, int index) Return Value: none *****************************************************************************/ -void MFIFOClear(char * buf) +void MFIFOClear(unsigned char * buf) { MFIFO * mf; mf = (MFIFO*)buf; @@ -128,7 +128,7 @@ void MFIFOClear(char * buf) Return Value: offset. *****************************************************************************/ -int MFIFOGetLBOffset(char *buf) +int MFIFOGetLBOffset(unsigned char *buf) { MFIFO * mf; mf = (MFIFO*)buf; @@ -151,7 +151,7 @@ int MFIFOGetLBOffset(char *buf) Return Value: offset *****************************************************************************/ -int MFIFOGetFBOffset(char *buf) +int MFIFOGetFBOffset(unsigned char *buf) { int x; MFIFO * mf; @@ -182,7 +182,7 @@ int MFIFOGetFBOffset(char *buf) Return Value: none *****************************************************************************/ -void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off) +void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off) { int x; MFIFO * mf; @@ -207,7 +207,7 @@ void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off) Return Value: *****************************************************************************/ -int MFIFOWriteMes(char *buf, char *mes, int size) +int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { int of,ol,x; MFIFO * mf; @@ -260,7 +260,7 @@ int MFIFOWriteMes(char *buf, char *mes, int size) Return Value: *****************************************************************************/ -char * MFIFOGetMesPtr(char *buf, int *size) +unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) { MFIFO * mf; mf = (MFIFO*)buf; @@ -281,7 +281,7 @@ char * MFIFOGetMesPtr(char *buf, int *size) Return Value: *****************************************************************************/ -void MFIFOKillNext(char *buf) +void MFIFOKillNext(unsigned char *buf) { int x; MFIFO * mf; From 5c09881a14622f7d611d2d6361895e6d2c1ab644 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 18:53:58 +0000 Subject: [PATCH 0136/1766] normalize using unsigned char for buffers instead of mixed signed/unsigned in isdn code. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@68 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 26 +++++++++++++------------- libs/freetdm/src/isdn/Q932mes.c | 1 - libs/freetdm/src/isdn/include/Q921.h | 4 ++-- libs/freetdm/src/isdn/include/Q931.h | 6 ++++++ libs/freetdm/src/isdn/include/mfifo.h | 18 +++++++++--------- libs/freetdm/src/isdn/mfifo.c | 16 ++++++++-------- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 81e709ba19..1396471570 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "Q921.h" +#include "q921.h" #include #include "mfifo.h" @@ -111,7 +111,7 @@ void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, char *b, int size) +int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) { return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); } @@ -135,7 +135,7 @@ int Q921QueueHDLCFrame(int trunk, char *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, char *mes, int size) +int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, unsigned char *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -164,7 +164,7 @@ int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -191,7 +191,7 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -218,7 +218,7 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -245,7 +245,7 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -271,7 +271,7 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -316,7 +316,7 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -342,7 +342,7 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) { - char mes[400]; + unsigned char mes[400]; mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -389,7 +389,7 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) //{ //} -int Q921ProcSABME(int trunk, char *mes, int size) +int Q921ProcSABME(int trunk, unsigned char *mes, int size) { Q921DevSpace[trunk].vr=0; Q921DevSpace[trunk].vs=0; @@ -417,9 +417,9 @@ int Q921ProcSABME(int trunk, char *mes, int size) *****************************************************************************/ int Q921Rx12(long trunk) { - char *mes; + unsigned char *mes; int rs,size; /* receive size & Q921 frame size*/ - char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + unsigned char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index 0540fa80f0..c0cf6505c3 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -48,7 +48,6 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT i = IOff; L3INT ir=0; L3INT OOff=0; - L3INT rc=Q931E_NO_ERROR; Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; //TODO diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index acb830383f..5537a17aeb 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -85,7 +85,7 @@ typedef struct { - char HDLCInQueue[Q921MAXHDLCSPACE]; + unsigned char HDLCInQueue[Q921MAXHDLCSPACE]; unsigned char vs; unsigned char vr; int state; @@ -95,7 +95,7 @@ void Q921Init(); void Q921SetHeaderSpace(int hspace); void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)); void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)); -int Q921QueueHDLCFrame(int trunk, char *b, int size); +int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size); int Q921Rx12(long trunk); #endif diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index dd8261cff3..6e71a27420 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -112,6 +112,12 @@ #include "stdio.h" +#ifdef _MSC_VER +/* warning C4100 : unreferenced formal parameter */ +/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled*/ +#pragma warning(disable:4100 4189) +#endif + /***************************************************************************** Error Codes diff --git a/libs/freetdm/src/isdn/include/mfifo.h b/libs/freetdm/src/isdn/include/mfifo.h index 21a053173e..788adfdb10 100644 --- a/libs/freetdm/src/isdn/include/mfifo.h +++ b/libs/freetdm/src/isdn/include/mfifo.h @@ -63,7 +63,7 @@ typedef struct _mfifo int first; /* first out */ int last; /* last in + 1 */ int bsize; /* buffer size */ - char *buf; /* ptr to start of buffer */ + unsigned char *buf; /* ptr to start of buffer */ int ixsize; /* index size */ MINDEX ix[1]; /* message index */ }MFIFO; @@ -71,13 +71,13 @@ typedef struct _mfifo /***************************************************************************** Function prototypes. *****************************************************************************/ -int MFIFOCreate(char *buf, int size, int index); -void MFIFOClear(char * buf); -int MFIFOGetLBOffset(char *buf); -int MFIFOGetFBOffset(char *buf); -void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off); -int MFIFOWriteMes(char *buf, char *mes, int size); -char * MFIFOGetMesPtr(char *buf, int *size); -void MFIFOKillNext(char *buf); +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); #endif diff --git a/libs/freetdm/src/isdn/mfifo.c b/libs/freetdm/src/isdn/mfifo.c index adf6bc9ebd..9e409f8a92 100644 --- a/libs/freetdm/src/isdn/mfifo.c +++ b/libs/freetdm/src/isdn/mfifo.c @@ -82,7 +82,7 @@ Return value: 0 if failure, 1 if ok. *****************************************************************************/ -int MFIFOCreate(char *buf, int size, int index) +int MFIFOCreate(unsigned char *buf, int size, int index) { MFIFO * mf; mf = (MFIFO*)buf; @@ -110,7 +110,7 @@ int MFIFOCreate(char *buf, int size, int index) Return Value: none *****************************************************************************/ -void MFIFOClear(char * buf) +void MFIFOClear(unsigned char * buf) { MFIFO * mf; mf = (MFIFO*)buf; @@ -128,7 +128,7 @@ void MFIFOClear(char * buf) Return Value: offset. *****************************************************************************/ -int MFIFOGetLBOffset(char *buf) +int MFIFOGetLBOffset(unsigned char *buf) { MFIFO * mf; mf = (MFIFO*)buf; @@ -151,7 +151,7 @@ int MFIFOGetLBOffset(char *buf) Return Value: offset *****************************************************************************/ -int MFIFOGetFBOffset(char *buf) +int MFIFOGetFBOffset(unsigned char *buf) { int x; MFIFO * mf; @@ -182,7 +182,7 @@ int MFIFOGetFBOffset(char *buf) Return Value: none *****************************************************************************/ -void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off) +void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off) { int x; MFIFO * mf; @@ -207,7 +207,7 @@ void MFIFOWriteIX(char *buf, char *mes, int size, int ix, int off) Return Value: *****************************************************************************/ -int MFIFOWriteMes(char *buf, char *mes, int size) +int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { int of,ol,x; MFIFO * mf; @@ -260,7 +260,7 @@ int MFIFOWriteMes(char *buf, char *mes, int size) Return Value: *****************************************************************************/ -char * MFIFOGetMesPtr(char *buf, int *size) +unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) { MFIFO * mf; mf = (MFIFO*)buf; @@ -281,7 +281,7 @@ char * MFIFOGetMesPtr(char *buf, int *size) Return Value: *****************************************************************************/ -void MFIFOKillNext(char *buf) +void MFIFOKillNext(unsigned char *buf) { int x; MFIFO * mf; From 0c54b8b50b5f3b9681c812c44c85cd56621d2907 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 18:57:23 +0000 Subject: [PATCH 0137/1766] fixing make... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@69 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 61 ++---------------------------------- 1 file changed, 2 insertions(+), 59 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 1396471570..dc6b7395b0 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "q921.h" +#include "Q921.h" #include #include "mfifo.h" @@ -280,25 +280,6 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -/***************************************************************************** - - Function: Q921 - - Description: - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 4 - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -//int Q921SendUI(...) -//{ -//} - /***************************************************************************** Function: Q921SendDISC @@ -351,44 +332,6 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -/***************************************************************************** - - Function: Q921 - - Description: - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -//int Q921SendFRMR(...) -//{ -//} - -/***************************************************************************** - - Function: Q921 - - Description: - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -//int Q921SendXID(...) -//{ -//} - int Q921ProcSABME(int trunk, unsigned char *mes, int size) { Q921DevSpace[trunk].vr=0; @@ -464,7 +407,7 @@ int Q921Rx12(long trunk) else { /* what the ? Issue an error */ -// Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ /* todo: REJ or FRMR */ } From 9215cb2586a118459717e5fcb822cb17d5ec7d20 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 18:57:23 +0000 Subject: [PATCH 0138/1766] fixing make... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@69 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 61 ++---------------------------------- 1 file changed, 2 insertions(+), 59 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 1396471570..dc6b7395b0 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "q921.h" +#include "Q921.h" #include #include "mfifo.h" @@ -280,25 +280,6 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -/***************************************************************************** - - Function: Q921 - - Description: - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 4 - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -//int Q921SendUI(...) -//{ -//} - /***************************************************************************** Function: Q921SendDISC @@ -351,44 +332,6 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -/***************************************************************************** - - Function: Q921 - - Description: - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -//int Q921SendFRMR(...) -//{ -//} - -/***************************************************************************** - - Function: Q921 - - Description: - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -//int Q921SendXID(...) -//{ -//} - int Q921ProcSABME(int trunk, unsigned char *mes, int size) { Q921DevSpace[trunk].vr=0; @@ -464,7 +407,7 @@ int Q921Rx12(long trunk) else { /* what the ? Issue an error */ -// Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ /* todo: REJ or FRMR */ } From f2a4b8b14d46314c10b41db4bfaa7e0e6e0d8efb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:00:38 +0000 Subject: [PATCH 0139/1766] Q921.c should build now under heavier warning levels. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@70 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index dc6b7395b0..bdac9b8416 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -47,6 +47,11 @@ #include #include "mfifo.h" +#ifdef _MSC_VER +/* temporary disable */ +#pragma warning(disable: 4244) +#endif + /***************************************************************************** Global Tables & Variables. *****************************************************************************/ @@ -334,6 +339,10 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) int Q921ProcSABME(int trunk, unsigned char *mes, int size) { + /* TODO: Do we need these paramaters? */ + (void)mes; + (void)size; + Q921DevSpace[trunk].vr=0; Q921DevSpace[trunk].vs=0; From 6fc08b3dd949abe290654ede0b1ae12135f5aa9e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:00:38 +0000 Subject: [PATCH 0140/1766] Q921.c should build now under heavier warning levels. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@70 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index dc6b7395b0..bdac9b8416 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -47,6 +47,11 @@ #include #include "mfifo.h" +#ifdef _MSC_VER +/* temporary disable */ +#pragma warning(disable: 4244) +#endif + /***************************************************************************** Global Tables & Variables. *****************************************************************************/ @@ -334,6 +339,10 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) int Q921ProcSABME(int trunk, unsigned char *mes, int size) { + /* TODO: Do we need these paramaters? */ + (void)mes; + (void)size; + Q921DevSpace[trunk].vr=0; Q921DevSpace[trunk].vs=0; From 23d2d673c10da221a476a50569b7ab44c3965278 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:02:28 +0000 Subject: [PATCH 0141/1766] warning levels on nix build prohibits // comments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@71 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 6e71a27420..8e7b0066b7 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -108,7 +108,7 @@ #define _Q931_NL /* uncomment the #define below to add x.25 support to the Q.931 */ -//#define Q931_X25_SUPPORT +/* #define Q931_X25_SUPPORT */ #include "stdio.h" From 98b699c8dd1e4f5ee5490819476cd895fbf78d9a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:02:28 +0000 Subject: [PATCH 0142/1766] warning levels on nix build prohibits // comments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@71 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 6e71a27420..8e7b0066b7 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -108,7 +108,7 @@ #define _Q931_NL /* uncomment the #define below to add x.25 support to the Q.931 */ -//#define Q931_X25_SUPPORT +/* #define Q931_X25_SUPPORT */ #include "stdio.h" From 1f16b98ca8ea9f3e03e80091d9d42005de49a7b0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:23:01 +0000 Subject: [PATCH 0143/1766] warnings cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@72 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 6 +-- libs/openzap/src/isdn/Q931StateNT.c | 6 ++- libs/openzap/src/isdn/Q931StateTE.c | 4 +- libs/openzap/src/isdn/Q931api.c | 45 ++++++++++++++++----- libs/openzap/src/isdn/include/Q931.h | 60 ++++++++++++++-------------- 5 files changed, 76 insertions(+), 45 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 42b76ecdb3..ed736284d0 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -548,14 +548,14 @@ L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV) callindex call index. iTimer timer id *****************************************************************************/ -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimerID) +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) { pTrunk->call[callIndex].Timer = Q931GetTime(); pTrunk->call[callIndex].TimerID = iTimerID; return 0; } -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimerID) +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) { if(pTrunk->call[callindex].TimerID == iTimerID) pTrunk->call[callindex].TimerID = 0; @@ -571,7 +571,7 @@ L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState) L3ULONG Q931GetTime() { - L3ULONG tNow; + L3ULONG tNow = 0; static L3ULONG tLast={0}; if(Q931GetTimeProc != NULL) { diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 21adcfa05b..fc245902bb 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -347,11 +347,15 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; } +#if 0 + /* TODO: Unreachable code??? */ /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); Q931StartTimer(pTrunk, callIndex, 303); - } +#endif + + } return rc; } diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index f2a3507473..745d0bc790 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -428,11 +428,13 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81); return ret; } - +#if 0 + /* TODO: Unreachable code??? */ /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); Q931StartTimer(pTrunk, callIndex, 303); +#endif } return rc; diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 079ae8301c..f1da2c9aa0 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -234,10 +234,11 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) case Q931mes_CONGESTION_CONTROL : trampoline(Q931mes_CongestionControl); break; - -// case Q931mes_FACILITY : -// trampoline(Q931mes_Facility); -// break; +#if 0 + case Q931mes_FACILITY : + trampoline(Q931mes_Facility); + break; +#endif case Q931mes_INFORMATION : trampoline(Q931mes_Information); @@ -247,9 +248,11 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) trampoline(Q931mes_Notify); break; -// case Q931mes_REGISTER : -// trampoline(Q931mes_Register); -// break; +#if 0 + case Q931mes_REGISTER : + trampoline(Q931mes_Register); + break; +#endif case Q931mes_STATUS : trampoline(Q931mes_Status); @@ -301,7 +304,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) L3UCHAR *pBuf = Q931GetIEBuf(pm); L3INT Off = pMes->Size - (pBuf - pm); - IE = Off | 0x8000; + IE = (ie)(Off | 0x8000); memcpy(&pm[pMes->Size], pi, iISize); @@ -577,7 +580,9 @@ L3INT Q931InitIELLComp(Q931ie_LLComp * pIE) pIE->Layer3Ident = 0; /* Layer 3 ident */ pIE->OptL3Info = 0; /* Optional layer 3 protocol info. */ pIE->ModeL3 = 0; /* Mode of operation */ -// pIE->ModeX25op = 0; /* Mode of operation X.25 */ +#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 */ @@ -595,20 +600,40 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE) L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) { + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + return 0; } L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) { + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + return 0; } L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) { + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + (void)iCRV; + (void)iCause; + return 0; } L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) { - return 0; + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + + return 0; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 8e7b0066b7..0ed40e5147 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1348,7 +1348,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ }Q931mes_Header; /***************************************************************************** @@ -1364,7 +1364,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Shift; ie MoreData; @@ -1424,7 +1424,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1445,7 +1445,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1465,7 +1465,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1488,7 +1488,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Display; /* Display */ ie Signal; /* Signal */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1505,7 +1505,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie ProgInd; /* Progress Indicator */ ie Display; /* Display */ @@ -1527,7 +1527,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie SendComplete; /* Sending Complete */ ie Display; /* Display */ ie KeypadFac; /* Keypad facility */ @@ -1550,7 +1550,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie NotifInd; /* Notification Indicator */ ie Display; /* Display */ @@ -1568,7 +1568,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie Cause; /* Cause */ ie ProgInd; /* Progress Indicator */ @@ -1588,7 +1588,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ ie Signal; /* Signal */ @@ -1609,7 +1609,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ ie Signal; /* Signal */ @@ -1629,7 +1629,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie CallID; /* Call Identity */ L3UCHAR buf[1]; }Q931mes_Resume; @@ -1645,7 +1645,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel ID */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1662,7 +1662,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1679,7 +1679,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_Segment; @@ -1694,7 +1694,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie SendComplete; /* Sending Complete */ ie RepeatInd; /* Repeat Indicator */ ie BearerCap; /* Bearer Capability */ @@ -1743,7 +1743,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel ID */ ie ProgInd; /* Progress Indicator */ ie Display; /* Display */ @@ -1762,7 +1762,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie CallState; /* Call State */ ie Display; /* Display */ @@ -1780,7 +1780,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_StatusEnquiry; @@ -1796,7 +1796,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie CallID; /* Call Identity */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_Suspend; @@ -1812,7 +1812,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_SuspendAck; @@ -1828,7 +1828,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1845,7 +1845,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie CongLevel; /* Congestion level */ ie Cause; /* Cause */ ie Display; /* Display */ @@ -1863,7 +1863,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie MoreData; /* More data */ ie UserUser; /* User-user */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1880,7 +1880,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel identification */ ie Display; /* Display */ ie RestartInd; /* Restart indicator */ @@ -1898,7 +1898,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel identification */ ie Display; /* Display */ ie RestartWin; /* Restart Window */ @@ -1946,7 +1946,7 @@ typedef struct { Q931_TrState_NoAlignment=0, /* Trunk not aligned */ Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2, /* Trunk Aligned */ + Q931_TrState_Aligned=2 /* Trunk Aligned */ }TrunkState; L3INT LastCRV; /* Last used crv for the trunk. */ @@ -2377,8 +2377,8 @@ L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimer); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); L3ULONG Q931GetTime(); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); From e02b3354d51fdcada8f942aa40ef5db57ff432be Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:23:01 +0000 Subject: [PATCH 0144/1766] warnings cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@72 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 6 +-- libs/freetdm/src/isdn/Q931StateNT.c | 6 ++- libs/freetdm/src/isdn/Q931StateTE.c | 4 +- libs/freetdm/src/isdn/Q931api.c | 45 ++++++++++++++++----- libs/freetdm/src/isdn/include/Q931.h | 60 ++++++++++++++-------------- 5 files changed, 76 insertions(+), 45 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 42b76ecdb3..ed736284d0 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -548,14 +548,14 @@ L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV) callindex call index. iTimer timer id *****************************************************************************/ -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimerID) +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) { pTrunk->call[callIndex].Timer = Q931GetTime(); pTrunk->call[callIndex].TimerID = iTimerID; return 0; } -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimerID) +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) { if(pTrunk->call[callindex].TimerID == iTimerID) pTrunk->call[callindex].TimerID = 0; @@ -571,7 +571,7 @@ L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState) L3ULONG Q931GetTime() { - L3ULONG tNow; + L3ULONG tNow = 0; static L3ULONG tLast={0}; if(Q931GetTimeProc != NULL) { diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 21adcfa05b..fc245902bb 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -347,11 +347,15 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; } +#if 0 + /* TODO: Unreachable code??? */ /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); Q931StartTimer(pTrunk, callIndex, 303); - } +#endif + + } return rc; } diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index f2a3507473..745d0bc790 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -428,11 +428,13 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81); return ret; } - +#if 0 + /* TODO: Unreachable code??? */ /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); Q931StartTimer(pTrunk, callIndex, 303); +#endif } return rc; diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 079ae8301c..f1da2c9aa0 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -234,10 +234,11 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) case Q931mes_CONGESTION_CONTROL : trampoline(Q931mes_CongestionControl); break; - -// case Q931mes_FACILITY : -// trampoline(Q931mes_Facility); -// break; +#if 0 + case Q931mes_FACILITY : + trampoline(Q931mes_Facility); + break; +#endif case Q931mes_INFORMATION : trampoline(Q931mes_Information); @@ -247,9 +248,11 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) trampoline(Q931mes_Notify); break; -// case Q931mes_REGISTER : -// trampoline(Q931mes_Register); -// break; +#if 0 + case Q931mes_REGISTER : + trampoline(Q931mes_Register); + break; +#endif case Q931mes_STATUS : trampoline(Q931mes_Status); @@ -301,7 +304,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) L3UCHAR *pBuf = Q931GetIEBuf(pm); L3INT Off = pMes->Size - (pBuf - pm); - IE = Off | 0x8000; + IE = (ie)(Off | 0x8000); memcpy(&pm[pMes->Size], pi, iISize); @@ -577,7 +580,9 @@ L3INT Q931InitIELLComp(Q931ie_LLComp * pIE) pIE->Layer3Ident = 0; /* Layer 3 ident */ pIE->OptL3Info = 0; /* Optional layer 3 protocol info. */ pIE->ModeL3 = 0; /* Mode of operation */ -// pIE->ModeX25op = 0; /* Mode of operation X.25 */ +#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 */ @@ -595,20 +600,40 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE) L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) { + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + return 0; } L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) { + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + return 0; } L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) { + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + (void)iCRV; + (void)iCause; + return 0; } L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) { - return 0; + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + + return 0; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 8e7b0066b7..0ed40e5147 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1348,7 +1348,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ }Q931mes_Header; /***************************************************************************** @@ -1364,7 +1364,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Shift; ie MoreData; @@ -1424,7 +1424,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1445,7 +1445,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1465,7 +1465,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1488,7 +1488,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Display; /* Display */ ie Signal; /* Signal */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1505,7 +1505,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie ProgInd; /* Progress Indicator */ ie Display; /* Display */ @@ -1527,7 +1527,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie SendComplete; /* Sending Complete */ ie Display; /* Display */ ie KeypadFac; /* Keypad facility */ @@ -1550,7 +1550,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie NotifInd; /* Notification Indicator */ ie Display; /* Display */ @@ -1568,7 +1568,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie BearerCap; /* Bearer Capability */ ie Cause; /* Cause */ ie ProgInd; /* Progress Indicator */ @@ -1588,7 +1588,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ ie Signal; /* Signal */ @@ -1609,7 +1609,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ ie Signal; /* Signal */ @@ -1629,7 +1629,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie CallID; /* Call Identity */ L3UCHAR buf[1]; }Q931mes_Resume; @@ -1645,7 +1645,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel ID */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1662,7 +1662,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1679,7 +1679,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_Segment; @@ -1694,7 +1694,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie SendComplete; /* Sending Complete */ ie RepeatInd; /* Repeat Indicator */ ie BearerCap; /* Bearer Capability */ @@ -1743,7 +1743,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel ID */ ie ProgInd; /* Progress Indicator */ ie Display; /* Display */ @@ -1762,7 +1762,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie CallState; /* Call State */ ie Display; /* Display */ @@ -1780,7 +1780,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_StatusEnquiry; @@ -1796,7 +1796,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie CallID; /* Call Identity */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_Suspend; @@ -1812,7 +1812,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_SuspendAck; @@ -1828,7 +1828,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie Cause; /* Cause */ ie Display; /* Display */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1845,7 +1845,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie CongLevel; /* Congestion level */ ie Cause; /* Cause */ ie Display; /* Display */ @@ -1863,7 +1863,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie MoreData; /* More data */ ie UserUser; /* User-user */ L3UCHAR buf[1]; /* Dynamic buffer */ @@ -1880,7 +1880,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel identification */ ie Display; /* Display */ ie RestartInd; /* Restart indicator */ @@ -1898,7 +1898,7 @@ typedef struct L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ + L3INT CRV; /* Call reference value */ ie ChanID; /* Channel identification */ ie Display; /* Display */ ie RestartWin; /* Restart Window */ @@ -1946,7 +1946,7 @@ typedef struct { Q931_TrState_NoAlignment=0, /* Trunk not aligned */ Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2, /* Trunk Aligned */ + Q931_TrState_Aligned=2 /* Trunk Aligned */ }TrunkState; L3INT LastCRV; /* Last used crv for the trunk. */ @@ -2377,8 +2377,8 @@ L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3INT iTimer); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); L3ULONG Q931GetTime(); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); From 443fe5b18335a5dd182d0b75dbeaea03acc95b12 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:34:43 +0000 Subject: [PATCH 0145/1766] more warning stuff. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@73 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 0ed40e5147..f320504e6a 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -113,9 +113,11 @@ #include "stdio.h" #ifdef _MSC_VER -/* warning C4100 : unreferenced formal parameter */ -/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled*/ -#pragma warning(disable:4100 4189) +/* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ +/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ +/* warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence TODO: This one should not be disabled */ +/* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ +#pragma warning(disable:4244 4189 4554 4267) #endif /***************************************************************************** From 19d39722eb7d09c018dec5c9c0948839a302b726 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:34:43 +0000 Subject: [PATCH 0146/1766] more warning stuff. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@73 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 0ed40e5147..f320504e6a 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -113,9 +113,11 @@ #include "stdio.h" #ifdef _MSC_VER -/* warning C4100 : unreferenced formal parameter */ -/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled*/ -#pragma warning(disable:4100 4189) +/* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ +/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ +/* warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence TODO: This one should not be disabled */ +/* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ +#pragma warning(disable:4244 4189 4554 4267) #endif /***************************************************************************** From c7747664b3f88a19d030e9ff6c88c73869279ab2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:37:52 +0000 Subject: [PATCH 0147/1766] warning levels on nix build prohibits // comments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@74 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index ed736284d0..01966b389e 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -286,12 +286,13 @@ void Q931Initialize() *****************************************************************************/ void Q931TimeTick(L3ULONG ms) { - ms=ms; // avoid warning for now. + ms=ms; /* avoid warning for now. */ - // TODO: Loop through all active calls, check timers and call timour procs - // if timers are expired. - // Implement an function array so each dialect can deal with their own - // timeouts. + /* TODO: Loop through all active calls, check timers and call timour procs + * if timers are expired. + * Implement an function array so each dialect can deal with their own + * timeouts. + */ } /***************************************************************************** @@ -578,7 +579,7 @@ L3ULONG Q931GetTime() tNow = Q931GetTimeProc(); if(tNow < tLast) /* wrapped */ { - // todo + /* TODO */ } tLast = tNow; } @@ -632,7 +633,7 @@ void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) Q931st[x].State = iState; Q931st[x].Message = iMes; Q931st[x].Direction = cDir; - // TODO Sort table and use bsearch + /* TODO Sort table and use bsearch */ return; } } @@ -650,7 +651,7 @@ void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) { int x; - // TODO Sort table and use bsearch + /* TODO Sort table and use bsearch */ for(x=0; x < Q931MAXSTATE; x++) { if( Q931st[x].State == iState From 8b89bdd9b37b504ab19c968b91c40fd4115faab1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:37:52 +0000 Subject: [PATCH 0148/1766] warning levels on nix build prohibits // comments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@74 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index ed736284d0..01966b389e 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -286,12 +286,13 @@ void Q931Initialize() *****************************************************************************/ void Q931TimeTick(L3ULONG ms) { - ms=ms; // avoid warning for now. + ms=ms; /* avoid warning for now. */ - // TODO: Loop through all active calls, check timers and call timour procs - // if timers are expired. - // Implement an function array so each dialect can deal with their own - // timeouts. + /* TODO: Loop through all active calls, check timers and call timour procs + * if timers are expired. + * Implement an function array so each dialect can deal with their own + * timeouts. + */ } /***************************************************************************** @@ -578,7 +579,7 @@ L3ULONG Q931GetTime() tNow = Q931GetTimeProc(); if(tNow < tLast) /* wrapped */ { - // todo + /* TODO */ } tLast = tNow; } @@ -632,7 +633,7 @@ void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) Q931st[x].State = iState; Q931st[x].Message = iMes; Q931st[x].Direction = cDir; - // TODO Sort table and use bsearch + /* TODO Sort table and use bsearch */ return; } } @@ -650,7 +651,7 @@ void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) { int x; - // TODO Sort table and use bsearch + /* TODO Sort table and use bsearch */ for(x=0; x < Q931MAXSTATE; x++) { if( Q931st[x].State == iState From d2e3cc0b8d014167d8294439724887d4c278cab9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:43:20 +0000 Subject: [PATCH 0149/1766] builds on windows again. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@75 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 5 +++-- libs/openzap/src/isdn/Q931ie.c | 2 ++ libs/openzap/src/isdn/include/Q931.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 01966b389e..ac22d79d25 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -96,7 +96,7 @@ L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); /* callback ptr for messages to be send */ /* to layer 2. */ -void (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); +L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); /* callback for error messages. */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ @@ -210,8 +210,9 @@ L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) Description: Dummy function for error processing *****************************************************************************/ -void Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) +L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) { + return 0; } /***************************************************************************** diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index d9cddbb16d..28b1845ca7 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1310,6 +1310,8 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT else { /* Long CRV is not used, so we skip this */ + /* TODO: is it right to set to 0 here? */ + CRV = 0; Octet+=l; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index f320504e6a..663d18d2da 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -117,7 +117,7 @@ /* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ /* warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence TODO: This one should not be disabled */ /* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4244 4189 4554 4267) +#pragma warning(disable:4100 4244 4189 4554 4267) #endif /***************************************************************************** From caeb4d430879910afd61789800dcc82bdb8116fd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:43:20 +0000 Subject: [PATCH 0150/1766] builds on windows again. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@75 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 5 +++-- libs/freetdm/src/isdn/Q931ie.c | 2 ++ libs/freetdm/src/isdn/include/Q931.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 01966b389e..ac22d79d25 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -96,7 +96,7 @@ L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); /* callback ptr for messages to be send */ /* to layer 2. */ -void (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); +L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); /* callback for error messages. */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ @@ -210,8 +210,9 @@ L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) Description: Dummy function for error processing *****************************************************************************/ -void Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) +L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) { + return 0; } /***************************************************************************** diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index d9cddbb16d..28b1845ca7 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1310,6 +1310,8 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT else { /* Long CRV is not used, so we skip this */ + /* TODO: is it right to set to 0 here? */ + CRV = 0; Octet+=l; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index f320504e6a..663d18d2da 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -117,7 +117,7 @@ /* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ /* warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence TODO: This one should not be disabled */ /* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4244 4189 4554 4267) +#pragma warning(disable:4100 4244 4189 4554 4267) #endif /***************************************************************************** From 5356f273b17bb7a9bb8fc47603a3d0f59b88ed00 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:48:51 +0000 Subject: [PATCH 0151/1766] warning levels on nix build prohibits // comments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@76 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateNT.c | 2 +- libs/openzap/src/isdn/Q931StateTE.c | 1 - libs/openzap/src/isdn/Q931ie.c | 3 +-- libs/openzap/src/isdn/Q931mes.c | 2 +- libs/openzap/src/isdn/Q932mes.c | 16 ++++++++-------- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index fc245902bb..0b03170566 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -120,7 +120,7 @@ void Q931CreateNT(L3UCHAR i) /* 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 + /* TODO define state table here */ } /***************************************************************************** diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 745d0bc790..c1a51ab649 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -483,7 +483,6 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; -// L3INT chanIndex; L3INT callIndex; L3INT ret = Q931E_NO_ERROR; diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 28b1845ca7..3bcf30623e 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1580,7 +1580,7 @@ L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * } else { - // error Octet 4a indicated, but invalid value in Octet 4. + /* error Octet 4a indicated, but invalid value in Octet 4. */ Q931SetError(pTrunk,Q931E_HLCOMP, 4, Off); return Q931E_HLCOMP; } @@ -2690,7 +2690,6 @@ L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; L3INT rc=Q931E_NO_ERROR; L3INT Beg=*Octet; -// L3INT li; OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index d2066d0358..c536d94799 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1482,7 +1482,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR /* Repeat Indicator */ if(Q931IsIEPresent(pMes->LLRepeatInd)) - ;//TODO + ;/* TODO */ /* Low Layer Compatibility */ if(Q931IsIEPresent(pMes->LLComp)) diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index c0cf6505c3..a404018fa7 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -50,7 +50,7 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT OOff=0; Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; return Q931E_NO_ERROR; @@ -84,7 +84,7 @@ L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT I L3INT OOff=0; Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; return Q931E_NO_ERROR; @@ -118,7 +118,7 @@ L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN L3INT OOff=0; Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; return Q931E_NO_ERROR; @@ -152,7 +152,7 @@ L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT OOff=0; Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; return Q931E_NO_ERROR; @@ -186,7 +186,7 @@ L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT OOff=0; Q932mes_Register *mes = (Q932mes_Register*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Register) - 1 + OOff; return Q931E_NO_ERROR; @@ -220,7 +220,7 @@ L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT OOff=0; Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; return Q931E_NO_ERROR; @@ -254,7 +254,7 @@ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT OOff=0; Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; return Q931E_NO_ERROR; @@ -288,7 +288,7 @@ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBu L3INT OOff=0; Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; return Q931E_NO_ERROR; From 86710f5d2feeb8afdb31c1a80cf5ce364f96c8ab Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:48:51 +0000 Subject: [PATCH 0152/1766] warning levels on nix build prohibits // comments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@76 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateNT.c | 2 +- libs/freetdm/src/isdn/Q931StateTE.c | 1 - libs/freetdm/src/isdn/Q931ie.c | 3 +-- libs/freetdm/src/isdn/Q931mes.c | 2 +- libs/freetdm/src/isdn/Q932mes.c | 16 ++++++++-------- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index fc245902bb..0b03170566 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -120,7 +120,7 @@ void Q931CreateNT(L3UCHAR i) /* 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 + /* TODO define state table here */ } /***************************************************************************** diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 745d0bc790..c1a51ab649 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -483,7 +483,6 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; -// L3INT chanIndex; L3INT callIndex; L3INT ret = Q931E_NO_ERROR; diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 28b1845ca7..3bcf30623e 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1580,7 +1580,7 @@ L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * } else { - // error Octet 4a indicated, but invalid value in Octet 4. + /* error Octet 4a indicated, but invalid value in Octet 4. */ Q931SetError(pTrunk,Q931E_HLCOMP, 4, Off); return Q931E_HLCOMP; } @@ -2690,7 +2690,6 @@ L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; L3INT rc=Q931E_NO_ERROR; L3INT Beg=*Octet; -// L3INT li; OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index d2066d0358..c536d94799 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1482,7 +1482,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR /* Repeat Indicator */ if(Q931IsIEPresent(pMes->LLRepeatInd)) - ;//TODO + ;/* TODO */ /* Low Layer Compatibility */ if(Q931IsIEPresent(pMes->LLComp)) diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index c0cf6505c3..a404018fa7 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -50,7 +50,7 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT OOff=0; Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; return Q931E_NO_ERROR; @@ -84,7 +84,7 @@ L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT I L3INT OOff=0; Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; return Q931E_NO_ERROR; @@ -118,7 +118,7 @@ L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN L3INT OOff=0; Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; return Q931E_NO_ERROR; @@ -152,7 +152,7 @@ L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT OOff=0; Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; return Q931E_NO_ERROR; @@ -186,7 +186,7 @@ L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT OOff=0; Q932mes_Register *mes = (Q932mes_Register*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Register) - 1 + OOff; return Q931E_NO_ERROR; @@ -220,7 +220,7 @@ L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT OOff=0; Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; return Q931E_NO_ERROR; @@ -254,7 +254,7 @@ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT OOff=0; Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; return Q931E_NO_ERROR; @@ -288,7 +288,7 @@ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBu L3INT OOff=0; Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; - //TODO + /* TODO */ mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; return Q931E_NO_ERROR; From ddc578bc1c3c26bb1d024e774454e06a4ab0ffe0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:54:27 +0000 Subject: [PATCH 0153/1766] use () around & ops to clarify order precedence git-svn-id: http://svn.openzap.org/svn/openzap/trunk@77 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 38 ++++++++++++++-------------- libs/openzap/src/isdn/include/Q931.h | 3 +-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 3bcf30623e..fe649f56a7 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -453,7 +453,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * pie->CallId[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 10); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); Q931IESizeTest(Q931E_CALLID); @@ -622,7 +622,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLEDSUB); @@ -805,7 +805,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA pie->NumPlanID = IBuf[Octet+Off] & 0x0f; /* Octet 3a */ - if(IBuf[Octet+Off] & 0x80 != 0) + if((IBuf[Octet+Off] & 0x80) != 0) { Off++; pie->PresInd = (IBuf[Octet+Off] >> 5) & 0x03; @@ -819,7 +819,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLINGNUM); @@ -925,7 +925,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLINGSUB); @@ -1013,7 +1013,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * O pie->Location = IBuf[Octet+Off] & 0x0f; /* Octet 3a */ - if(IBuf[Octet+Off] & 0x80 != 0) + if((IBuf[Octet+Off] & 0x80) != 0) { Off++; pie->Recom = IBuf[Octet+Off] & 0x7f; @@ -1764,7 +1764,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Octet++; /* Octet 3a*/ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->NegotInd = (IBuf[Octet+Off] >> 6) & 0x01; Off++; @@ -1784,7 +1784,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 5 - Layer 1 Ident */ - if(IBuf[Octet+Off] & 0x60 == 0x20) /* 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; @@ -1792,7 +1792,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Octet++; /* Octet 5a */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->SyncAsync = (IBuf[Octet+Off] >> 6) & 0x01; pie->Negot = (IBuf[Octet+Off] >> 5) & 0x01; @@ -1800,7 +1800,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Off++; /* Octet 5b - 2 options */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { if(pie->UIL1Prot == 0x01) /* V.110, I.460 and X.30*/ { @@ -1833,7 +1833,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 5c */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; @@ -1841,7 +1841,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Off++; /* Octet 5d */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->DuplexMode = (IBuf[Octet+Off] >> 6) & 0x01; pie->ModemType = IBuf[Octet+Off] & 0x3f; @@ -1854,14 +1854,14 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 6 - Layer 2 Ident */ - if(IBuf[Octet+Off] & 0x60 == 0x40) /* Layer 1 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(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { if(pie->UIL2Prot == 0x10) /* 2nd 6a */ { @@ -1875,7 +1875,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Off++; } /* Octet 6b*/ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->WindowSize = IBuf[Octet+Off] & 0x7f; Off++; @@ -1884,14 +1884,14 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 7 - layer 3 Ident */ - if(IBuf[Octet+Off] & 0x60 == 0x60) /* 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(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { if(pie->UIL3Prot == 0x0b) @@ -1915,13 +1915,13 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 7b*/ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->DefPackSize = IBuf[Octet+Off] & 0x0f; Off++; /* Octet 7c */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->PackWinSize= IBuf[Octet+Off] & 0x7f; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 663d18d2da..79f5ac9f00 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -115,9 +115,8 @@ #ifdef _MSC_VER /* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ /* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ -/* warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence TODO: This one should not be disabled */ /* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244 4189 4554 4267) +#pragma warning(disable:4100 4244 4189 4267) #endif /***************************************************************************** From 83db56f73a53f62013b7f351ee0f301f6a27e977 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 19:54:27 +0000 Subject: [PATCH 0154/1766] use () around & ops to clarify order precedence git-svn-id: http://svn.openzap.org/svn/openzap/trunk@77 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 38 ++++++++++++++-------------- libs/freetdm/src/isdn/include/Q931.h | 3 +-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 3bcf30623e..fe649f56a7 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -453,7 +453,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * pie->CallId[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 10); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); Q931IESizeTest(Q931E_CALLID); @@ -622,7 +622,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLEDSUB); @@ -805,7 +805,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA pie->NumPlanID = IBuf[Octet+Off] & 0x0f; /* Octet 3a */ - if(IBuf[Octet+Off] & 0x80 != 0) + if((IBuf[Octet+Off] & 0x80) != 0) { Off++; pie->PresInd = (IBuf[Octet+Off] >> 5) & 0x03; @@ -819,7 +819,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLINGNUM); @@ -925,7 +925,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while(IBuf[Octet+Off]&0x80 != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLINGSUB); @@ -1013,7 +1013,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * O pie->Location = IBuf[Octet+Off] & 0x0f; /* Octet 3a */ - if(IBuf[Octet+Off] & 0x80 != 0) + if((IBuf[Octet+Off] & 0x80) != 0) { Off++; pie->Recom = IBuf[Octet+Off] & 0x7f; @@ -1764,7 +1764,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Octet++; /* Octet 3a*/ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->NegotInd = (IBuf[Octet+Off] >> 6) & 0x01; Off++; @@ -1784,7 +1784,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 5 - Layer 1 Ident */ - if(IBuf[Octet+Off] & 0x60 == 0x20) /* 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; @@ -1792,7 +1792,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Octet++; /* Octet 5a */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->SyncAsync = (IBuf[Octet+Off] >> 6) & 0x01; pie->Negot = (IBuf[Octet+Off] >> 5) & 0x01; @@ -1800,7 +1800,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Off++; /* Octet 5b - 2 options */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { if(pie->UIL1Prot == 0x01) /* V.110, I.460 and X.30*/ { @@ -1833,7 +1833,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 5c */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; @@ -1841,7 +1841,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Off++; /* Octet 5d */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->DuplexMode = (IBuf[Octet+Off] >> 6) & 0x01; pie->ModemType = IBuf[Octet+Off] & 0x3f; @@ -1854,14 +1854,14 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 6 - Layer 2 Ident */ - if(IBuf[Octet+Off] & 0x60 == 0x40) /* Layer 1 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(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { if(pie->UIL2Prot == 0x10) /* 2nd 6a */ { @@ -1875,7 +1875,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Off++; } /* Octet 6b*/ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->WindowSize = IBuf[Octet+Off] & 0x7f; Off++; @@ -1884,14 +1884,14 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 7 - layer 3 Ident */ - if(IBuf[Octet+Off] & 0x60 == 0x60) /* 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(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { if(pie->UIL3Prot == 0x0b) @@ -1915,13 +1915,13 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O } /* Octet 7b*/ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->DefPackSize = IBuf[Octet+Off] & 0x0f; Off++; /* Octet 7c */ - if(IBuf[Octet+Off-1] & 0x80 != 0) + if((IBuf[Octet+Off-1] & 0x80) != 0) { pie->PackWinSize= IBuf[Octet+Off] & 0x7f; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 663d18d2da..79f5ac9f00 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -115,9 +115,8 @@ #ifdef _MSC_VER /* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ /* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ -/* warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence TODO: This one should not be disabled */ /* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244 4189 4554 4267) +#pragma warning(disable:4100 4244 4189 4267) #endif /***************************************************************************** From fa37b6630b7e19ecc1ebba115c5554cff5d13aea Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:04:50 +0000 Subject: [PATCH 0155/1766] fix error for unused local variable. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@78 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 2 +- libs/openzap/src/isdn/Q931ie.c | 8 +-- libs/openzap/src/isdn/Q931mes.c | 78 ++++++++++++++-------------- libs/openzap/src/isdn/Q932mes.c | 32 ++++++------ libs/openzap/src/isdn/include/Q931.h | 3 +- 5 files changed, 61 insertions(+), 62 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index c1a51ab649..7e870224a8 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -779,7 +779,7 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr { /* no action */ } - return 0; + return ret; } /***************************************************************************** diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index fe649f56a7..a36eca1261 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1121,7 +1121,7 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 { Q931ie_CongLevel * pIE = (Q931ie_CongLevel*)IBuf; L3INT rc=0; - L3INT Beg=*Octet; + /* L3INT Beg=*Octet; */ OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel; @@ -2429,7 +2429,7 @@ L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 { Q931ie_RepeatInd * pIE = (Q931ie_RepeatInd*)IBuf; L3INT rc=0; - L3INT Beg=*Octet; + /* L3INT Beg=*Octet; */ OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd; @@ -2687,9 +2687,9 @@ L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH *****************************************************************************/ L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; + /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */ L3INT rc=Q931E_NO_ERROR; - L3INT Beg=*Octet; + /* L3INT Beg=*Octet; */ OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index c536d94799..21dd181616 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -51,8 +51,8 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -161,8 +161,8 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -291,8 +291,8 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISi *****************************************************************************/ L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -420,8 +420,8 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -489,8 +489,8 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -576,8 +576,8 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Information *mes = (Q931mes_Information*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -671,8 +671,8 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L *****************************************************************************/ L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -744,8 +744,8 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -840,8 +840,8 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Release *mes = (Q931mes_Release*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -915,8 +915,8 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1050,8 +1050,8 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1107,8 +1107,8 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1174,8 +1174,8 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U *****************************************************************************/ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1255,7 +1255,7 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; + /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; @@ -1504,8 +1504,8 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *****************************************************************************/ L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1591,8 +1591,8 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Status *mes = (Q931mes_Status*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1667,8 +1667,8 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1724,8 +1724,8 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, *****************************************************************************/ L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1781,8 +1781,8 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1839,8 +1839,8 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; L3INT rc=Q931E_NO_ERROR; diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index a404018fa7..97e4fe1a42 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -45,8 +45,8 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; @@ -79,8 +79,8 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; @@ -113,8 +113,8 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; @@ -147,8 +147,8 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; @@ -181,8 +181,8 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Register *mes = (Q932mes_Register*)IBuf; @@ -215,8 +215,8 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; @@ -249,8 +249,8 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; @@ -283,8 +283,8 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 79f5ac9f00..813f4a9bc8 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -114,9 +114,8 @@ #ifdef _MSC_VER /* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ -/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ /* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244 4189 4267) +#pragma warning(disable:4100 4244 4267) #endif /***************************************************************************** From 283dd646f1d721caeccbda9c36d5fb3d00b49309 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:04:50 +0000 Subject: [PATCH 0156/1766] fix error for unused local variable. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@78 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 2 +- libs/freetdm/src/isdn/Q931ie.c | 8 +-- libs/freetdm/src/isdn/Q931mes.c | 78 ++++++++++++++-------------- libs/freetdm/src/isdn/Q932mes.c | 32 ++++++------ libs/freetdm/src/isdn/include/Q931.h | 3 +- 5 files changed, 61 insertions(+), 62 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index c1a51ab649..7e870224a8 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -779,7 +779,7 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr { /* no action */ } - return 0; + return ret; } /***************************************************************************** diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index fe649f56a7..a36eca1261 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1121,7 +1121,7 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 { Q931ie_CongLevel * pIE = (Q931ie_CongLevel*)IBuf; L3INT rc=0; - L3INT Beg=*Octet; + /* L3INT Beg=*Octet; */ OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel; @@ -2429,7 +2429,7 @@ L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 { Q931ie_RepeatInd * pIE = (Q931ie_RepeatInd*)IBuf; L3INT rc=0; - L3INT Beg=*Octet; + /* L3INT Beg=*Octet; */ OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd; @@ -2687,9 +2687,9 @@ L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH *****************************************************************************/ L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; + /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */ L3INT rc=Q931E_NO_ERROR; - L3INT Beg=*Octet; + /* L3INT Beg=*Octet; */ OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index c536d94799..21dd181616 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -51,8 +51,8 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -161,8 +161,8 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -291,8 +291,8 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISi *****************************************************************************/ L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -420,8 +420,8 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -489,8 +489,8 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -576,8 +576,8 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Information *mes = (Q931mes_Information*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -671,8 +671,8 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L *****************************************************************************/ L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -744,8 +744,8 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -840,8 +840,8 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Release *mes = (Q931mes_Release*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -915,8 +915,8 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1050,8 +1050,8 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1107,8 +1107,8 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1174,8 +1174,8 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U *****************************************************************************/ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1255,7 +1255,7 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; + /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; @@ -1504,8 +1504,8 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *****************************************************************************/ L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1591,8 +1591,8 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Status *mes = (Q931mes_Status*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1667,8 +1667,8 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1724,8 +1724,8 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, *****************************************************************************/ L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1781,8 +1781,8 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; L3INT rc=Q931E_NO_ERROR; @@ -1839,8 +1839,8 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; L3INT rc=Q931E_NO_ERROR; diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index a404018fa7..97e4fe1a42 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -45,8 +45,8 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; @@ -79,8 +79,8 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; @@ -113,8 +113,8 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; @@ -147,8 +147,8 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; @@ -181,8 +181,8 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Register *mes = (Q932mes_Register*)IBuf; @@ -215,8 +215,8 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; @@ -249,8 +249,8 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; @@ -283,8 +283,8 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { - L3INT i = IOff; - L3INT ir=0; + /* L3INT i = IOff; */ + /* L3INT ir=0; */ L3INT OOff=0; Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 79f5ac9f00..813f4a9bc8 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -114,9 +114,8 @@ #ifdef _MSC_VER /* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ -/* warning C4189 : local variable is initialized but not referenced TODO: This one should not be disabled */ /* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244 4189 4267) +#pragma warning(disable:4100 4244 4267) #endif /***************************************************************************** From 56007735e4f708eb3b9326e968084fa6865b45c6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:08:52 +0000 Subject: [PATCH 0157/1766] empty if body on ie that has not yet been implemented. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@79 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 21dd181616..8451ff48d5 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1482,7 +1482,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR /* Repeat Indicator */ if(Q931IsIEPresent(pMes->LLRepeatInd)) - ;/* TODO */ + rc = Q931E_UNKNOWN_IE;/* TODO */ /* Low Layer Compatibility */ if(Q931IsIEPresent(pMes->LLComp)) From 0e1333c7d238a7d875cd8e880f56cc9996d62bea Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:08:52 +0000 Subject: [PATCH 0158/1766] empty if body on ie that has not yet been implemented. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@79 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 21dd181616..8451ff48d5 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1482,7 +1482,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR /* Repeat Indicator */ if(Q931IsIEPresent(pMes->LLRepeatInd)) - ;/* TODO */ + rc = Q931E_UNKNOWN_IE;/* TODO */ /* Low Layer Compatibility */ if(Q931IsIEPresent(pMes->LLComp)) From 38237eb3822be5da1c1ea33b7ef842239c02b10c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:28:13 +0000 Subject: [PATCH 0159/1766] fix some type overflow warnings in q921 caused by the math implicitly becoming int. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@80 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 85 +++++++++++++--------------- libs/openzap/src/isdn/include/Q921.h | 27 +++++++-- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index bdac9b8416..b36c76965d 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -47,19 +47,14 @@ #include #include "mfifo.h" -#ifdef _MSC_VER -/* temporary disable */ -#pragma warning(disable: 4244) -#endif - /***************************************************************************** Global Tables & Variables. *****************************************************************************/ Q921Data Q921DevSpace[Q921MAXTRUNK]; int Q921HeaderSpace={0}; -int (*Q921Tx21Proc)(int dev, unsigned char *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, unsigned char *, int)={NULL}; +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; /***************************************************************************** @@ -87,12 +82,12 @@ void Q921SetHeaderSpace(int hspace) Q921HeaderSpace=hspace; } -void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)) +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) { Q921Tx21Proc = callback; } -void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) { Q921Tx23Proc = callback; } @@ -116,7 +111,7 @@ void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) { return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); } @@ -140,7 +135,7 @@ int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, unsigned char *mes, int size) +int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -169,12 +164,12 @@ int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x01; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -196,12 +191,12 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x05; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -223,12 +218,12 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x09; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -250,11 +245,11 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x6f | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -276,11 +271,11 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x0f | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -302,11 +297,11 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x43 | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -328,16 +323,16 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x63 | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -int Q921ProcSABME(int trunk, unsigned char *mes, int size) +int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) { /* TODO: Do we need these paramaters? */ (void)mes; @@ -369,9 +364,9 @@ int Q921ProcSABME(int trunk, unsigned char *mes, int size) *****************************************************************************/ int Q921Rx12(long trunk) { - unsigned char *mes; + L2UCHAR *mes; int rs,size; /* receive size & Q921 frame size*/ - unsigned char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 5537a17aeb..3a0e1b02ac 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -83,19 +83,34 @@ #define Q921MAXTRUNK 4 #define Q921MAXHDLCSPACE 3000 +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + or larger. + +*****************************************************************************/ + +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ + typedef struct { - unsigned char HDLCInQueue[Q921MAXHDLCSPACE]; - unsigned char vs; - unsigned char vr; + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR vr; int state; }Q921Data; void Q921Init(); void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)); -void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)); -int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); int Q921Rx12(long trunk); #endif From 0dfe5be1def0bfc6e0c40f2364396aac7fa08942 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:28:13 +0000 Subject: [PATCH 0160/1766] fix some type overflow warnings in q921 caused by the math implicitly becoming int. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@80 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 85 +++++++++++++--------------- libs/freetdm/src/isdn/include/Q921.h | 27 +++++++-- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index bdac9b8416..b36c76965d 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -47,19 +47,14 @@ #include #include "mfifo.h" -#ifdef _MSC_VER -/* temporary disable */ -#pragma warning(disable: 4244) -#endif - /***************************************************************************** Global Tables & Variables. *****************************************************************************/ Q921Data Q921DevSpace[Q921MAXTRUNK]; int Q921HeaderSpace={0}; -int (*Q921Tx21Proc)(int dev, unsigned char *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, unsigned char *, int)={NULL}; +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; /***************************************************************************** @@ -87,12 +82,12 @@ void Q921SetHeaderSpace(int hspace) Q921HeaderSpace=hspace; } -void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)) +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) { Q921Tx21Proc = callback; } -void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) { Q921Tx23Proc = callback; } @@ -116,7 +111,7 @@ void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) { return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); } @@ -140,7 +135,7 @@ int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf, unsigned char *mes, int size) +int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; @@ -169,12 +164,12 @@ int Q921SendI(int trunk, unsigned char Sapi, char cr, unsigned char Tei, char pf int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x01; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -196,12 +191,12 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x05; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -223,12 +218,12 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x09; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -250,11 +245,11 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x6f | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -276,11 +271,11 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x0f | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -302,11 +297,11 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x43 | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } @@ -328,16 +323,16 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) *****************************************************************************/ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) { - unsigned char mes[400]; + L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = 0x63 | ((pf<<4)&0x10); + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -int Q921ProcSABME(int trunk, unsigned char *mes, int size) +int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) { /* TODO: Do we need these paramaters? */ (void)mes; @@ -369,9 +364,9 @@ int Q921ProcSABME(int trunk, unsigned char *mes, int size) *****************************************************************************/ int Q921Rx12(long trunk) { - unsigned char *mes; + L2UCHAR *mes; int rs,size; /* receive size & Q921 frame size*/ - unsigned char *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 5537a17aeb..3a0e1b02ac 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -83,19 +83,34 @@ #define Q921MAXTRUNK 4 #define Q921MAXHDLCSPACE 3000 +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + or larger. + +*****************************************************************************/ + +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ + typedef struct { - unsigned char HDLCInQueue[Q921MAXHDLCSPACE]; - unsigned char vs; - unsigned char vr; + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR vr; int state; }Q921Data; void Q921Init(); void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, unsigned char *, int)); -void Q921SetTx23CB(int (*callback)(int dev, unsigned char *, int)); -int Q921QueueHDLCFrame(int trunk, unsigned char *b, int size); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); int Q921Rx12(long trunk); #endif From 2cf4daf1e5971ed197448d93bf4a68fc761b4a56 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:34:49 +0000 Subject: [PATCH 0161/1766] resolve msvc warning C4267 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@81 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 20 ++++++++++---------- libs/openzap/src/isdn/include/Q931.h | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index a36eca1261..d10e5cdfc3 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -459,7 +459,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; - pie->Size = sizeof(Q931ie_CallID) + x -1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CallID) + x -1; Q931SetIE(*pIE, *OOff); @@ -628,7 +628,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; - pie->Size = sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CalledSub) + x - 1; Q931SetIE(*pIE, *OOff); @@ -721,7 +721,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; - pie->Size = sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CalledNum) + x - 1; Q931SetIE(*pIE, *OOff); @@ -825,7 +825,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CallingNum) + x - 1; Q931SetIE(*pIE, *OOff); @@ -931,7 +931,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CallingSub) + x -1; Q931SetIE(*pIE, *OOff); @@ -1480,7 +1480,7 @@ L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; - pie->Size = sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_Display) + x - 1; Q931SetIE(*pIE, *OOff); @@ -1684,7 +1684,7 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; - pie->Size = sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_KeypadFac) + x - 1; Q931SetIE(*pIE, *OOff); @@ -2165,7 +2165,7 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_NetFac) + x - 1; Q931SetIE(*pIE, *OOff); @@ -2817,7 +2817,7 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_TransNetSel) + x - 1; Q931SetIE(*pIE, *OOff); @@ -2906,7 +2906,7 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_UserUser) + x - 1; Q931SetIE(*pIE, *OOff); diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 813f4a9bc8..ed1471494d 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -114,8 +114,7 @@ #ifdef _MSC_VER /* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ -/* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244 4267) +#pragma warning(disable:4100 4244) #endif /***************************************************************************** From 2201f355ee933d35d9192e5ce58631adf63cf16f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:34:49 +0000 Subject: [PATCH 0162/1766] resolve msvc warning C4267 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@81 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 20 ++++++++++---------- libs/freetdm/src/isdn/include/Q931.h | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index a36eca1261..d10e5cdfc3 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -459,7 +459,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; - pie->Size = sizeof(Q931ie_CallID) + x -1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CallID) + x -1; Q931SetIE(*pIE, *OOff); @@ -628,7 +628,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; - pie->Size = sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CalledSub) + x - 1; Q931SetIE(*pIE, *OOff); @@ -721,7 +721,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; - pie->Size = sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CalledNum) + x - 1; Q931SetIE(*pIE, *OOff); @@ -825,7 +825,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CallingNum) + x - 1; Q931SetIE(*pIE, *OOff); @@ -931,7 +931,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)sizeof(Q931ie_CallingSub) + x -1; Q931SetIE(*pIE, *OOff); @@ -1480,7 +1480,7 @@ L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; - pie->Size = sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_Display) + x - 1; Q931SetIE(*pIE, *OOff); @@ -1684,7 +1684,7 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; - pie->Size = sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_KeypadFac) + x - 1; Q931SetIE(*pIE, *OOff); @@ -2165,7 +2165,7 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_NetFac) + x - 1; Q931SetIE(*pIE, *OOff); @@ -2817,7 +2817,7 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_TransNetSel) + x - 1; Q931SetIE(*pIE, *OOff); @@ -2906,7 +2906,7 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)sizeof(Q931ie_UserUser) + x - 1; Q931SetIE(*pIE, *OOff); diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 813f4a9bc8..ed1471494d 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -114,8 +114,7 @@ #ifdef _MSC_VER /* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ -/* warning C4267: '=' : conversion from 'size_t' to 'unsigned char', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244 4267) +#pragma warning(disable:4100 4244) #endif /***************************************************************************** From 38c513f42f5f471e9e6640faec682e5be8861e9a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:41:41 +0000 Subject: [PATCH 0163/1766] resolve msvc warning C4244 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@82 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 66 ++++++++++++++-------------- libs/openzap/src/isdn/include/Q931.h | 3 +- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index d10e5cdfc3..642783e75c 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -410,7 +410,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 } } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -459,7 +459,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CallID) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); Q931SetIE(*pIE, *OOff); @@ -497,7 +497,7 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT OBuf[(*Octet)-1] |= 0x80; /* set complete flag at last octet*/ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -574,7 +574,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -628,7 +628,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); Q931SetIE(*pIE, *OOff); @@ -670,7 +670,7 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -721,7 +721,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); Q931SetIE(*pIE, *OOff); @@ -763,7 +763,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -825,7 +825,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); Q931SetIE(*pIE, *OOff); @@ -877,7 +877,7 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -931,7 +931,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); Q931SetIE(*pIE, *OOff); @@ -973,7 +973,7 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1065,7 +1065,7 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT /* Octet 5 - diagnostics not supported in send */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1261,7 +1261,7 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT } } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1304,7 +1304,7 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT else if(l==2) /* two octet CRV */ { CRV = IBuf[Octet] << 8; - CRV += IBuf[Octet+1]; + CRV = CRV + IBuf[Octet+1]; Octet += 2; } else @@ -1435,7 +1435,7 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1480,7 +1480,7 @@ L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); Q931SetIE(*pIE, *OOff); @@ -1518,7 +1518,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN OBuf[(*Octet)++] = pIE->Display[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1639,7 +1639,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT OBuf[(*Octet)-1] |= 0x80; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1684,7 +1684,7 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); Q931SetIE(*pIE, *OOff); @@ -1721,7 +1721,7 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = pIE->KeypadFac[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2102,7 +2102,7 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT rc = Q931E_LLCOMP; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2165,7 +2165,7 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); Q931SetIE(*pIE, *OOff); @@ -2212,7 +2212,7 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT /* Octet 4*/ OBuf[(*Octet)++] = pIE->NetFac; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2288,7 +2288,7 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 3*/ OBuf[(*Octet)++] = pIE->Notification; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2373,7 +2373,7 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN /* Octet 4*/ OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2553,7 +2553,7 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* Octet 3*/ OBuf[(*Octet)++] = 0x80 | pIE->Class ; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2635,7 +2635,7 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN /* Octet 4 */ OBuf[(*Octet)++] = pIE->SegType; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2766,7 +2766,7 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT /* Octet 3*/ OBuf[(*Octet)++] = pIE->Signal; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2817,7 +2817,7 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); Q931SetIE(*pIE, *OOff); @@ -2857,7 +2857,7 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = pIE->NetID[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2906,7 +2906,7 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); Q931SetIE(*pIE, *OOff); @@ -2946,7 +2946,7 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I OBuf[(*Octet)++] = pIE->User[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index ed1471494d..04697bedc5 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -113,8 +113,7 @@ #include "stdio.h" #ifdef _MSC_VER -/* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244) +#pragma warning(disable:4100) #endif /***************************************************************************** From bf315e8b3845079e0143dc57b1d28cc3f77f93c6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 21 May 2007 20:41:41 +0000 Subject: [PATCH 0164/1766] resolve msvc warning C4244 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@82 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 66 ++++++++++++++-------------- libs/freetdm/src/isdn/include/Q931.h | 3 +- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index d10e5cdfc3..642783e75c 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -410,7 +410,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 } } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -459,7 +459,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CallID) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); Q931SetIE(*pIE, *OOff); @@ -497,7 +497,7 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT OBuf[(*Octet)-1] |= 0x80; /* set complete flag at last octet*/ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -574,7 +574,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -628,7 +628,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); Q931SetIE(*pIE, *OOff); @@ -670,7 +670,7 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -721,7 +721,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); Q931SetIE(*pIE, *OOff); @@ -763,7 +763,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -825,7 +825,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); Q931SetIE(*pIE, *OOff); @@ -877,7 +877,7 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -931,7 +931,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); Q931SetIE(*pIE, *OOff); @@ -973,7 +973,7 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1065,7 +1065,7 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT /* Octet 5 - diagnostics not supported in send */ - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1261,7 +1261,7 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT } } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1304,7 +1304,7 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT else if(l==2) /* two octet CRV */ { CRV = IBuf[Octet] << 8; - CRV += IBuf[Octet+1]; + CRV = CRV + IBuf[Octet+1]; Octet += 2; } else @@ -1435,7 +1435,7 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1480,7 +1480,7 @@ L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); Q931SetIE(*pIE, *OOff); @@ -1518,7 +1518,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN OBuf[(*Octet)++] = pIE->Display[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1639,7 +1639,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT OBuf[(*Octet)-1] |= 0x80; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -1684,7 +1684,7 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); Q931SetIE(*pIE, *OOff); @@ -1721,7 +1721,7 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = pIE->KeypadFac[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2102,7 +2102,7 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT rc = Q931E_LLCOMP; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2165,7 +2165,7 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); Q931SetIE(*pIE, *OOff); @@ -2212,7 +2212,7 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT /* Octet 4*/ OBuf[(*Octet)++] = pIE->NetFac; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2288,7 +2288,7 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 3*/ OBuf[(*Octet)++] = pIE->Notification; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2373,7 +2373,7 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN /* Octet 4*/ OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2553,7 +2553,7 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* Octet 3*/ OBuf[(*Octet)++] = 0x80 | pIE->Class ; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2635,7 +2635,7 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN /* Octet 4 */ OBuf[(*Octet)++] = pIE->SegType; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2766,7 +2766,7 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT /* Octet 3*/ OBuf[(*Octet)++] = pIE->Signal; - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2817,7 +2817,7 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); Q931SetIE(*pIE, *OOff); @@ -2857,7 +2857,7 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = pIE->NetID[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } @@ -2906,7 +2906,7 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); Q931SetIE(*pIE, *OOff); @@ -2946,7 +2946,7 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I OBuf[(*Octet)++] = pIE->User[x]; } - OBuf[li] = (*Octet)-Beg; + OBuf[li] = (L3UCHAR)((*Octet)-Beg); return rc; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index ed1471494d..04697bedc5 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -113,8 +113,7 @@ #include "stdio.h" #ifdef _MSC_VER -/* warning C4244: conversion from 'type a' to 'type b', possible loss of data TODO: This one should not be disabled */ -#pragma warning(disable:4100 4244) +#pragma warning(disable:4100) #endif /***************************************************************************** From 4de078c9e8cad34fb413f792690f23696e033b3c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 20:45:45 +0000 Subject: [PATCH 0165/1766] dont error on unused function paramaters git-svn-id: http://svn.openzap.org/svn/openzap/trunk@83 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/general.makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/general.makefile b/libs/openzap/src/general.makefile index b1177dc860..e642a7d88e 100644 --- a/libs/openzap/src/general.makefile +++ b/libs/openzap/src/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi -Wno-unused-parameter From f83966fdd694dc6bade6fc6f08543f1f73c11657 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 20:45:45 +0000 Subject: [PATCH 0166/1766] dont error on unused function paramaters git-svn-id: http://svn.openzap.org/svn/openzap/trunk@83 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/general.makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/general.makefile b/libs/freetdm/src/general.makefile index b1177dc860..e642a7d88e 100644 --- a/libs/freetdm/src/general.makefile +++ b/libs/freetdm/src/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi -Wno-unused-parameter From 4fb5220f5bd57a6c19f01685fac17c95126e4f5d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 21:47:30 +0000 Subject: [PATCH 0167/1766] update makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@84 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index c657c3f179..7b5c211e66 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -90,5 +90,5 @@ zap_zt.o: zap_zt.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o $(MYLIB) *~ \#* testapp priserver + rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver From b3551097c930a3608dffc8ff278f29c48b470bff Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 21:47:30 +0000 Subject: [PATCH 0168/1766] update makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@84 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index c657c3f179..7b5c211e66 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -90,5 +90,5 @@ zap_zt.o: zap_zt.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o $(MYLIB) *~ \#* testapp priserver + rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver From 65bf12a04827c785355394920889281a450699cf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 23:29:33 +0000 Subject: [PATCH 0169/1766] change linefeeds git-svn-id: http://svn.openzap.org/svn/openzap/trunk@85 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/EuroISDNStateNT.c | 92 +- libs/openzap/src/isdn/EuroISDNStateTE.c | 114 +- libs/openzap/src/isdn/Q921.c | 848 ++-- libs/openzap/src/isdn/Q931.c | 1332 ++--- libs/openzap/src/isdn/Q931StateNT.c | 2526 +++++----- libs/openzap/src/isdn/Q931StateTE.c | 2632 +++++----- libs/openzap/src/isdn/Q931api.c | 1278 ++--- libs/openzap/src/isdn/Q931ie.c | 5904 +++++++++++------------ libs/openzap/src/isdn/Q931mes.c | 3862 +++++++-------- libs/openzap/src/isdn/Q932mes.c | 620 +-- libs/openzap/src/isdn/include/Q921.h | 234 +- libs/openzap/src/isdn/include/Q931.h | 4824 +++++++++--------- libs/openzap/src/isdn/include/Q932.h | 382 +- libs/openzap/src/isdn/include/mfifo.h | 166 +- libs/openzap/src/isdn/mfifo.c | 592 +-- 15 files changed, 12703 insertions(+), 12703 deletions(-) diff --git a/libs/openzap/src/isdn/EuroISDNStateNT.c b/libs/openzap/src/isdn/EuroISDNStateNT.c index 9c2fc45616..ccfaba0d16 100644 --- a/libs/openzap/src/isdn/EuroISDNStateNT.c +++ b/libs/openzap/src/isdn/EuroISDNStateNT.c @@ -1,46 +1,46 @@ -/***************************************************************************** - - 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" - - +/***************************************************************************** + + 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 index cf0631c92b..250d33ffd2 100644 --- a/libs/openzap/src/isdn/EuroISDNStateTE.c +++ b/libs/openzap/src/isdn/EuroISDNStateTE.c @@ -1,57 +1,57 @@ -/***************************************************************************** - - 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 -*/ - -void EuroISDNCreateTE(L3UCHAR i) -{ - Q931CreateTE(i); -} +/***************************************************************************** + + 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 +*/ + +void EuroISDNCreateTE(L3UCHAR i) +{ + Q931CreateTE(i); +} diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index b36c76965d..27802d877d 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -1,424 +1,424 @@ -/***************************************************************************** - - FileName: q921.c - - Description: Contains the implementation of a Q.921 protocol on top of the - Comet Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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. - -*****************************************************************************/ -#include "Q921.h" -#include -#include "mfifo.h" - -/***************************************************************************** - Global Tables & Variables. -*****************************************************************************/ -Q921Data Q921DevSpace[Q921MAXTRUNK]; -int Q921HeaderSpace={0}; - -int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; - -/***************************************************************************** - - Function: Q921Init - - Decription: Initialize the Q.921 stack so it is ready for use. This - function MUST be called as part of initializing the - application. - -*****************************************************************************/ -void Q921Init() -{ - int x; - for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - } - } - - /* check for RR */ - else if(mes[2] ==0x01) - { - /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); - - return 1; - } - return 0; -} - +/***************************************************************************** + + FileName: q921.c + + Description: Contains the implementation of a Q.921 protocol on top of the + Comet Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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. + +*****************************************************************************/ +#include "Q921.h" +#include +#include "mfifo.h" + +/***************************************************************************** + Global Tables & Variables. +*****************************************************************************/ +Q921Data Q921DevSpace[Q921MAXTRUNK]; +int Q921HeaderSpace={0}; + +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; + +/***************************************************************************** + + Function: Q921Init + + Decription: Initialize the Q.921 stack so it is ready for use. This + function MUST be called as part of initializing the + application. + +*****************************************************************************/ +void Q921Init() +{ + int x; + for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index ac22d79d25..09cbaf0b76 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -1,666 +1,666 @@ -/***************************************************************************** - - 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 "Q931.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 dielects 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. - -*****************************************************************************/ -L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -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. - -*****************************************************************************/ - -L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - /* callback for messages to be send to */ - /* layer 4. */ - -L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); - /* callback ptr for messages to be send */ - /* to layer 2. */ - -L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); - /* callback for error messages. */ - -L3ULONG (*Q931GetTimeProc) ()=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: Q931 - - Description: Dummy function for message processing. - -*****************************************************************************/ -L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) -{ - return Q931E_INTERNAL; -} - -/***************************************************************************** - - Function: Q931 - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - return Q931E_UNKNOWN_MESSAGE; -} - -/***************************************************************************** - - Function: Q931 - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - return Q931E_UNKNOWN_IE; -} - -/***************************************************************************** - - Function: Q931 - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - return Q931E_UNKNOWN_MESSAGE; -} - -/***************************************************************************** - - Function: Q931PieDummy - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) -{ - return Q931E_UNKNOWN_IE; -} - -/***************************************************************************** - - Function: Q931TxDummy - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) -{ - return Q931E_MISSING_CB; -} - -/***************************************************************************** - - Function: Q931ErrorDummy - - Description: Dummy function for error processing - -*****************************************************************************/ -L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,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 diealect 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 */ - Q931Tx34Proc = Q931TxDummy; - Q931Tx32Proc = Q931TxDummy; - 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 0 : Warning - see q931errors.h for details. - -*****************************************************************************/ -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) -{ - L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; - - Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; - L3INT ISize; - L3INT IOff = 0; - - /* Protocol Discriminator */ - m->ProtDisc = Mes[IOff++]; - - /* CRV */ - m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); - - /* Message Type */ - m->MesType = Mes[IOff++]; - - /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); - if(RetCode >= Q931E_NO_ERROR) - { - RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); - } - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Tx34 - - Description: Called from the stac 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 *pTrunk, L3UCHAR * Mes, L3INT Size) -{ - return Q931Tx34Proc(pTrunk, Mes, Size); -} - -/***************************************************************************** - - 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 *pTrunk,L3UCHAR * buf, L3INT Size) -{ - Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; - - RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); - - 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 Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) -{ - L3INT OSize; - Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; - L3INT RetCode = Q931E_NO_ERROR; - L3INT iDialect = pTrunk->Dialect; - - /* Call pack function through table. */ - RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { - RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); - } - - 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 *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) -{ - Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); -} - -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx34Proc = Q931Tx34Par; -} - -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx32Proc = Q931Tx32Par; -} - -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) -{ - 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 *pTrunk, L3INT * callIndex) -{ - L3INT CRV = Q931GetUniqueCRV(pTrunk); - - return Q931AllocateCRV(pTrunk, CRV, callIndex); -} - -/***************************************************************************** - - 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 *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 *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 */ -} - -/***************************************************************************** - - Function: Q931StartTimer - - Description: Start a timer. - - Parameters: pTrunk Trunk number - callindex call index. - iTimer timer id -*****************************************************************************/ -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) -{ - pTrunk->call[callIndex].Timer = Q931GetTime(); - pTrunk->call[callIndex].TimerID = iTimerID; - return 0; -} - -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) -{ - if(pTrunk->call[callindex].TimerID == iTimerID) - pTrunk->call[callindex].TimerID = 0; - return 0; -} - -L3INT Q931SetState(Q931_TrunkInfo *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)()) -{ - Q931GetTimeProc = callback; -} - -L3INT Q931FindCRV(Q931_TrunkInfo *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 - sequensial 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; -} +/***************************************************************************** + + 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 "Q931.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 dielects 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. + +*****************************************************************************/ +L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +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. + +*****************************************************************************/ + +L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + /* callback for messages to be send to */ + /* layer 4. */ + +L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); + /* callback ptr for messages to be send */ + /* to layer 2. */ + +L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); + /* callback for error messages. */ + +L3ULONG (*Q931GetTimeProc) ()=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: Q931 + + Description: Dummy function for message processing. + +*****************************************************************************/ +L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) +{ + return Q931E_INTERNAL; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931PieDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931TxDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) +{ + return Q931E_MISSING_CB; +} + +/***************************************************************************** + + Function: Q931ErrorDummy + + Description: Dummy function for error processing + +*****************************************************************************/ +L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,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 diealect 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 */ + Q931Tx34Proc = Q931TxDummy; + Q931Tx32Proc = Q931TxDummy; + 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 0 : Warning + see q931errors.h for details. + +*****************************************************************************/ +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) +{ + L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; + L3INT ISize; + L3INT IOff = 0; + + /* Protocol Discriminator */ + m->ProtDisc = Mes[IOff++]; + + /* CRV */ + m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); + + /* Message Type */ + m->MesType = Mes[IOff++]; + + /* Call table proc to unpack codec message */ + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + } + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Tx34 + + Description: Called from the stac 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 *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + return Q931Tx34Proc(pTrunk, Mes, Size); +} + +/***************************************************************************** + + 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 *pTrunk,L3UCHAR * buf, L3INT Size) +{ + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + + 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 Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + L3INT OSize; + Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; + L3INT RetCode = Q931E_NO_ERROR; + L3INT iDialect = pTrunk->Dialect; + + /* Call pack function through table. */ + RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); + } + + 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 *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) +{ + Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); +} + +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx34Proc = Q931Tx34Par; +} + +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx32Proc = Q931Tx32Par; +} + +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) +{ + 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 *pTrunk, L3INT * callIndex) +{ + L3INT CRV = Q931GetUniqueCRV(pTrunk); + + return Q931AllocateCRV(pTrunk, CRV, callIndex); +} + +/***************************************************************************** + + 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 *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 *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 */ +} + +/***************************************************************************** + + Function: Q931StartTimer + + Description: Start a timer. + + Parameters: pTrunk Trunk number + callindex call index. + iTimer timer id +*****************************************************************************/ +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) +{ + pTrunk->call[callIndex].Timer = Q931GetTime(); + pTrunk->call[callIndex].TimerID = iTimerID; + return 0; +} + +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) +{ + if(pTrunk->call[callindex].TimerID == iTimerID) + pTrunk->call[callindex].TimerID = 0; + return 0; +} + +L3INT Q931SetState(Q931_TrunkInfo *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)()) +{ + Q931GetTimeProc = callback; +} + +L3INT Q931FindCRV(Q931_TrunkInfo *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 - sequensial 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; +} diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 0b03170566..2d2a3c5671 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -1,1263 +1,1263 @@ -/***************************************************************************** - - 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); - - /* 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 */ -} - -/***************************************************************************** - - Function: Q931ProcAlertingNT - -*****************************************************************************/ -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcCallProceedingNT - -*****************************************************************************/ -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; - 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 = Q931Tx32(pTrunk,buf,pMes->Size); - if(ret) - return ret; - - Q931StartTimer(pTrunk, callIndex, 303); - - 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) - 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, 303); -#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - +/***************************************************************************** + + 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); + + /* 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 */ +} + +/***************************************************************************** + + Function: Q931ProcAlertingNT + +*****************************************************************************/ +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingNT + +*****************************************************************************/ +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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, 303); +#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 index 7e870224a8..7941326b05 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -1,1316 +1,1316 @@ -/***************************************************************************** - - 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); - - /* 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: Q931ProcAlertingTE - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcCallProceedingTE - -*****************************************************************************/ -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcConnectAckTE - -*****************************************************************************/ -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; - 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 = Q931Tx32(pTrunk,buf,pMes->Size); - if(ret) - return ret; - - Q931StartTimer(pTrunk, callIndex, 303); - - 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) - 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, 303); -#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); - if(ret != Q931E_NO_ERROR) - return ret; - - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - Q931StartTimer(pTrunk, callIndex, 303); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcResumeTE - -*****************************************************************************/ -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - Q931mes_Resume * pMes = (Q931mes_Resume *)&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=Q931Tx32(pTrunk,buf, pMes->Size); - if(ret != Q931E_NO_ERROR) - return ret; - - /* Start timer T318 */ - Q931StartTimer(pTrunk, callIndex, 318); - - /*set state U17 */ - Q931SetState(pTrunk, callIndex, Q931_U17); - } - else - { - return Q931E_ILLEGAL_MESSAGE; - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcResumeAckTE - -*****************************************************************************/ -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; - L3INT state = Q931GetCallState(pTrunk, pMes->CRV); - L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) - { - ret = Q931ReleaseComplete(pTrunk, iFrom); - } - else - { - ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); - } - - return ret; -} - -/***************************************************************************** - - Function: Q931ProcReleaseCompleteTE - -*****************************************************************************/ -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; - L3INT state = Q931GetCallState(pTrunk, pMes->CRV); - L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) - { - /* no action */ - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcRestartTE - -*****************************************************************************/ -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcRestartAckTE - -*****************************************************************************/ -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - +/***************************************************************************** + + 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); + + /* 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: Q931ProcAlertingTE + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingTE + +*****************************************************************************/ +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcConnectAckTE + +*****************************************************************************/ +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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, 303); +#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); + if(ret != Q931E_NO_ERROR) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + Q931StartTimer(pTrunk, callIndex, 303); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeTE + +*****************************************************************************/ +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Resume * pMes = (Q931mes_Resume *)&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=Q931Tx32(pTrunk,buf, pMes->Size); + if(ret != Q931E_NO_ERROR) + return ret; + + /* Start timer T318 */ + Q931StartTimer(pTrunk, callIndex, 318); + + /*set state U17 */ + Q931SetState(pTrunk, callIndex, Q931_U17); + } + else + { + return Q931E_ILLEGAL_MESSAGE; + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeAckTE + +*****************************************************************************/ +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + ret = Q931ReleaseComplete(pTrunk, iFrom); + } + else + { + ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); + } + + return ret; +} + +/***************************************************************************** + + Function: Q931ProcReleaseCompleteTE + +*****************************************************************************/ +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + /* no action */ + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcRestartTE + +*****************************************************************************/ +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcRestartAckTE + +*****************************************************************************/ +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 index f1da2c9aa0..e93b43193b 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -1,639 +1,639 @@ -/***************************************************************************** - - 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" - -/* -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; -} -*/ - -void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) -{ - int y; - pTrunk->LastCRV = 0; - pTrunk->Dialect = 0; - pTrunk->Enabled = 0; - pTrunk->TrunkType = Q931_TrType_E1; - pTrunk->NetUser = Q931_TE; - pTrunk->TrunkState = 0; - for(y=0; y < Q931MAXCHPERTRUNK; y++) - { - pTrunk->ch[y].Available = 1; - - /* Set up E1 scheme by default */ - if(y==0) - { - pTrunk->ch[y].ChanType = Q931_ChType_Sync; - } - else if(y==16) - { - pTrunk->ch[y].ChanType = Q931_ChType_D; - } - else - { - pTrunk->ch[y].ChanType = Q931_ChType_B; - } - } - - for(y=0; y < Q931MAXCALLPERTRUNK; y++) - { - pTrunk->call[y].InUse = 0; - - } -} - -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -) -{ - 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, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -) -{ - if(Q931PieProc != NULL) - Q931Pie[dialect][iec] = Q931PieProc; - if(Q931UieProc != NULL) - Q931Uie[dialect][iec] = Q931UieProc; -} - -#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} - -/***************************************************************************** - - Function: Q931GetIEBuf - - Description: Return a ptr to the buf used for IE in the message. - -*****************************************************************************/ -L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) -{ - L3UCHAR * s=NULL; - Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; - switch(pMes->MesType) - { - case Q931mes_ALERTING : - trampoline(Q931mes_Alerting); - break; - - case Q931mes_CALL_PROCEEDING : - trampoline(Q931mes_CallProceeding); - break; - - case Q931mes_CONNECT : - trampoline(Q931mes_Connect); - break; - - case Q931mes_CONNECT_ACKNOWLEDGE : - trampoline(Q931mes_ConnectAck); - break; - - case Q931mes_PROGRESS : - trampoline(Q931mes_Progress); - break; - - case Q931mes_SETUP : - trampoline(Q931mes_Setup); - break; - - case Q931mes_SETUP_ACKNOWLEDGE : - trampoline(Q931mes_SetupAck); - break; - - case Q931mes_RESUME : - trampoline(Q931mes_Resume); - break; - - case Q931mes_RESUME_ACKNOWLEDGE : - trampoline(Q931mes_ResumeAck); - break; - - case Q931mes_RESUME_REJECT : - trampoline(Q931mes_ResumeReject); - break; - - case Q932mes_RETRIEVE : - trampoline(Q932mes_Retrieve); - break; - - case Q932mes_RETRIEVE_ACKNOWLEDGE : - trampoline(Q932mes_RetrieveAck); - break; - - case Q932mes_RETRIEVE_REJECT : - trampoline(Q932mes_RetrieveReject); - break; - - case Q931mes_SUSPEND : - trampoline(Q931mes_Suspend); - break; - - case Q931mes_SUSPEND_ACKNOWLEDGE : - trampoline(Q931mes_SuspendAck); - break; - - case Q931mes_SUSPEND_REJECT : - trampoline(Q931mes_SuspendReject); - break; - - case Q931mes_USER_INFORMATION : - trampoline(Q931mes_UserInformation); - break; - - case Q931mes_DISCONNECT : - trampoline(Q931mes_Disconnect); - break; - - case Q931mes_RELEASE : - trampoline(Q931mes_Release); - break; - - case Q931mes_RELEASE_COMPLETE : - trampoline(Q931mes_ReleaseComplete); - break; - - case Q931mes_RESTART : - trampoline(Q931mes_Restart); - break; - - case Q931mes_RESTART_ACKNOWLEDGE : - trampoline(Q931mes_RestartAck); - break; - - case Q931mes_CONGESTION_CONTROL : - trampoline(Q931mes_CongestionControl); - break; -#if 0 - case Q931mes_FACILITY : - trampoline(Q931mes_Facility); - break; -#endif - - case Q931mes_INFORMATION : - trampoline(Q931mes_Information); - break; - - case Q931mes_NOTIFY : - trampoline(Q931mes_Notify); - break; - -#if 0 - case Q931mes_REGISTER : - trampoline(Q931mes_Register); - break; -#endif - - case Q931mes_STATUS : - trampoline(Q931mes_Status); - break; - - case Q931mes_STATUS_ENQUIRY : - trampoline(Q931mes_StatusEnquiry); - break; - - case Q931mes_SEGMENT : - trampoline(Q931mes_Segment); - break; - - default: - s = 0; - break; - } - - return s; -} - -L3INT Q931GetMesSize(L3UCHAR *pMes) -{ - - L3UCHAR *p = Q931GetIEBuf(pMes); - L3INT Size = (L3INT)(p - 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_Alerting * pMes= (Q931mes_Alerting *)pm; - Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; - L3INT iISize = pIE->Size; - - L3UCHAR *pBuf = Q931GetIEBuf(pm); - L3INT Off = pMes->Size - (pBuf - pm); - IE = (ie)(Off | 0x8000); - - memcpy(&pm[pMes->Size], pi, iISize); - - pMes->Size += iISize; - - return IE; -} - -/***************************************************************************** -*****************************************************************************/ -L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) -{ - static L3INT crv={1}; - return crv++; -} - -L3INT Q931InitMesSetup(Q931mes_Setup *pMes) -{ - pMes->ProtDisc = 0x80; - pMes->CRV = 0; /* CRV to be allocated, might be receive*/ - pMes->MesType = Q931mes_SETUP; - - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); - - pMes->SendComplete =0; /* Sending Complete */ - pMes->RepeatInd =0; /* Repeat Indicator */ - pMes->BearerCap =0; /* Bearer Capability */ - pMes->ChanID =0; /* Channel ID */ - pMes->ProgInd =0; /* Progress Indicator */ - pMes->NetFac =0; /* Network-specific facilities */ - pMes->Display =0; /* Display */ - pMes->DateTime =0; /* Date/Time */ - pMes->KeypadFac =0; /* Keypad Facility */ - pMes->Signal =0; /* Signal */ - pMes->CallingNum =0; /* Calling party number */ - pMes->CallingSub =0; /* Calling party sub address */ - pMes->CalledNum =0; /* Called party number */ - pMes->CalledSub =0; /* Called party sub address */ - pMes->TransNetSel =0; /* Transit network selection */ - pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ - pMes->LLComp =0; /* Low layer compatibility */ - pMes->HLComp =0; /* High layer compatibility */ - - return 0; -} - -L3INT Q931InitMesResume(Q931mes_Resume * pMes) -{ - pMes->ProtDisc = 0x80; - pMes->CRV = 0; /* CRV to be allocated, might be receive*/ - pMes->MesType = Q931mes_RESUME; - - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); - pMes->CallID = 0; /* Channel Identification */ - 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 *pTrunk,L3UCHAR * b, L3INT iFrom) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)b; - (void)iFrom; - - return 0; -} - -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)b; - (void)iFrom; - - return 0; -} - -L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)iTo; - (void)iCRV; - (void)iCause; - - return 0; -} - -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)iTo; - - return 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" + +/* +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; +} +*/ + +void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) +{ + int y; + pTrunk->LastCRV = 0; + pTrunk->Dialect = 0; + pTrunk->Enabled = 0; + pTrunk->TrunkType = Q931_TrType_E1; + pTrunk->NetUser = Q931_TE; + pTrunk->TrunkState = 0; + for(y=0; y < Q931MAXCHPERTRUNK; y++) + { + pTrunk->ch[y].Available = 1; + + /* Set up E1 scheme by default */ + if(y==0) + { + pTrunk->ch[y].ChanType = Q931_ChType_Sync; + } + else if(y==16) + { + pTrunk->ch[y].ChanType = Q931_ChType_D; + } + else + { + pTrunk->ch[y].ChanType = Q931_ChType_B; + } + } + + for(y=0; y < Q931MAXCALLPERTRUNK; y++) + { + pTrunk->call[y].InUse = 0; + + } +} + +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +) +{ + 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, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +) +{ + if(Q931PieProc != NULL) + Q931Pie[dialect][iec] = Q931PieProc; + if(Q931UieProc != NULL) + Q931Uie[dialect][iec] = Q931UieProc; +} + +#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} + +/***************************************************************************** + + Function: Q931GetIEBuf + + Description: Return a ptr to the buf used for IE in the message. + +*****************************************************************************/ +L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) +{ + L3UCHAR * s=NULL; + Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + switch(pMes->MesType) + { + case Q931mes_ALERTING : + trampoline(Q931mes_Alerting); + break; + + case Q931mes_CALL_PROCEEDING : + trampoline(Q931mes_CallProceeding); + break; + + case Q931mes_CONNECT : + trampoline(Q931mes_Connect); + break; + + case Q931mes_CONNECT_ACKNOWLEDGE : + trampoline(Q931mes_ConnectAck); + break; + + case Q931mes_PROGRESS : + trampoline(Q931mes_Progress); + break; + + case Q931mes_SETUP : + trampoline(Q931mes_Setup); + break; + + case Q931mes_SETUP_ACKNOWLEDGE : + trampoline(Q931mes_SetupAck); + break; + + case Q931mes_RESUME : + trampoline(Q931mes_Resume); + break; + + case Q931mes_RESUME_ACKNOWLEDGE : + trampoline(Q931mes_ResumeAck); + break; + + case Q931mes_RESUME_REJECT : + trampoline(Q931mes_ResumeReject); + break; + + case Q932mes_RETRIEVE : + trampoline(Q932mes_Retrieve); + break; + + case Q932mes_RETRIEVE_ACKNOWLEDGE : + trampoline(Q932mes_RetrieveAck); + break; + + case Q932mes_RETRIEVE_REJECT : + trampoline(Q932mes_RetrieveReject); + break; + + case Q931mes_SUSPEND : + trampoline(Q931mes_Suspend); + break; + + case Q931mes_SUSPEND_ACKNOWLEDGE : + trampoline(Q931mes_SuspendAck); + break; + + case Q931mes_SUSPEND_REJECT : + trampoline(Q931mes_SuspendReject); + break; + + case Q931mes_USER_INFORMATION : + trampoline(Q931mes_UserInformation); + break; + + case Q931mes_DISCONNECT : + trampoline(Q931mes_Disconnect); + break; + + case Q931mes_RELEASE : + trampoline(Q931mes_Release); + break; + + case Q931mes_RELEASE_COMPLETE : + trampoline(Q931mes_ReleaseComplete); + break; + + case Q931mes_RESTART : + trampoline(Q931mes_Restart); + break; + + case Q931mes_RESTART_ACKNOWLEDGE : + trampoline(Q931mes_RestartAck); + break; + + case Q931mes_CONGESTION_CONTROL : + trampoline(Q931mes_CongestionControl); + break; +#if 0 + case Q931mes_FACILITY : + trampoline(Q931mes_Facility); + break; +#endif + + case Q931mes_INFORMATION : + trampoline(Q931mes_Information); + break; + + case Q931mes_NOTIFY : + trampoline(Q931mes_Notify); + break; + +#if 0 + case Q931mes_REGISTER : + trampoline(Q931mes_Register); + break; +#endif + + case Q931mes_STATUS : + trampoline(Q931mes_Status); + break; + + case Q931mes_STATUS_ENQUIRY : + trampoline(Q931mes_StatusEnquiry); + break; + + case Q931mes_SEGMENT : + trampoline(Q931mes_Segment); + break; + + default: + s = 0; + break; + } + + return s; +} + +L3INT Q931GetMesSize(L3UCHAR *pMes) +{ + + L3UCHAR *p = Q931GetIEBuf(pMes); + L3INT Size = (L3INT)(p - 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_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; + L3INT iISize = pIE->Size; + + L3UCHAR *pBuf = Q931GetIEBuf(pm); + L3INT Off = pMes->Size - (pBuf - pm); + IE = (ie)(Off | 0x8000); + + memcpy(&pm[pMes->Size], pi, iISize); + + pMes->Size += iISize; + + return IE; +} + +/***************************************************************************** +*****************************************************************************/ +L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) +{ + static L3INT crv={1}; + return crv++; +} + +L3INT Q931InitMesSetup(Q931mes_Setup *pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_SETUP; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + + pMes->SendComplete =0; /* Sending Complete */ + pMes->RepeatInd =0; /* Repeat Indicator */ + pMes->BearerCap =0; /* Bearer Capability */ + pMes->ChanID =0; /* Channel ID */ + pMes->ProgInd =0; /* Progress Indicator */ + pMes->NetFac =0; /* Network-specific facilities */ + pMes->Display =0; /* Display */ + pMes->DateTime =0; /* Date/Time */ + pMes->KeypadFac =0; /* Keypad Facility */ + pMes->Signal =0; /* Signal */ + pMes->CallingNum =0; /* Calling party number */ + pMes->CallingSub =0; /* Calling party sub address */ + pMes->CalledNum =0; /* Called party number */ + pMes->CalledSub =0; /* Called party sub address */ + pMes->TransNetSel =0; /* Transit network selection */ + pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ + pMes->LLComp =0; /* Low layer compatibility */ + pMes->HLComp =0; /* High layer compatibility */ + + return 0; +} + +L3INT Q931InitMesResume(Q931mes_Resume * pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_RESUME; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->CallID = 0; /* Channel Identification */ + 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 *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + + return 0; +} + +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + + return 0; +} + +L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + (void)iCRV; + (void)iCause; + + return 0; +} + +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + + return 0; +} diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 642783e75c..15e93bfee8 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1,2952 +1,2952 @@ -/***************************************************************************** - - 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" - -/***************************************************************************** - - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); - - Q931SetIE(*pIE, *OOff); - - 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) -{ - Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; - L3INT rc=0; - L3INT Beg=*Octet;/* remember current offset */ - L3INT li; - - OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; - li=(*Octet)++; /* remember length position */ - - /* Octet 3 - Coding standard / Information transfer capability */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); - - /* Octet 4 - Transfer mode / Information transfer rate */ - if(pIE->ITR == 0x18) - { - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - } - else - { - OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - - /* Octet 4.1 - Rate Multiplier */ - OBuf[(*Octet)++] = 0x80 | pIE->RateMul; - } - - /* 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) | (pIE->UIL1Prot & 0x15); - - /* Octet 5a - SyncAsync/Negot/UserRate */ - OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (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) - | (pIE->NIConTx << 4) - | (pIE->NIConRx << 3) - | (pIE->FlowCtlTx << 2) - | (pIE->FlowCtlRx << 1); - } - else if(pIE->UIL1Prot == 0x08) /* ITU V.120 */ - { - /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/ - OBuf[(*Octet)++] = 0x00 - | (pIE->InterRate << 6) - | (pIE->MultiFrame << 5) - | (pIE->Mode << 4) - | (pIE->LLInegot << 3) - | (pIE->Assignor << 2) - | (pIE->InBandNeg << 1); - } - - /* Octet 5c - NumStopBits/NumStartBits/Parity */ - OBuf[(*Octet)++] = 0x00 - | (pIE->NumStopBits << 5 ) - | (pIE->NumDataBits << 3 ) - | (pIE->Parity); - - /* Octet 5d - Duplex Mode/Modem Type */ - OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); - } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); - } - } - - /* Octet 6 - Layer2Ident/User information layer 2 prtocol */ - if(pIE->Layer2Ident == 0x02) - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot); - } - - /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ - if(pIE->Layer3Ident == 0x03) - { - if(pIE->UIL3Prot == 0x0c) - { - OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); - - /* Octet 7a - Additional information layer 3 msb */ - OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); - - /* Octet 7b - Additional information layer 3 lsb */ - OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); - } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); - } - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - do{ - pie->CallId[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); - - Q931IESizeTest(Q931E_CALLID); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallState); - pie->Size = sizeof(Q931ie_CallState); - - Q931SetIE(*pIE, *OOff); - - 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 *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)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); - - Q931IESizeTest(Q931E_CALLEDSUB); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; /* # digits in this case */ - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; - pie->NumPlanID = IBuf[Octet+Off] & 0x0f; - Octet ++; - - /* Octet 4*/ - for (x = 0; x < IESize && x < 20; x++) - { - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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_NUMBER; - 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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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 4a*/ - x=0; - do{ - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); - - Q931IESizeTest(Q931E_CALLINGNUM); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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_CalledSub) + 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 3a */ - /* - - Details about the use and how to detect if Octet 3a is used - are very weak. Temp left out. - - Octet 3 msb is set to 1 to indicate that this is not present - - */ - - /* Octet 4 */ - for(x=0;xDigit[x]; - } - - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); - - Q931IESizeTest(Q931E_CALLINGSUB); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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; - - Q931IESizeTest(Q931E_CAUSE); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Cause); - pie->Size = sizeof(Q931ie_Cause); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - - *pIE=0; - - pie->IEId = IBuf[Octet] & 0xf0; - pie->CongLevel = IBuf[Octet] & 0x0f; - Octet ++; - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CongLevel); - pie->Size = sizeof(Q931ie_CongLevel); - - Q931SetIE(*pIE, *OOff); - - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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], Off); - Octet++; - - /* 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++; - } - else - { - /* 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; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); - Off++; - } - } - - Q931IESizeTest(Q931E_CHANID); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); - - Q931SetIE(*pIE, *OOff); - - 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 *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) - | (pIE->IntType<<5) - | (pIE->PrefExcl<<3) - | pIE->InfoChanSel; - - /* Octet 3.1 - Interface Identifier */ - if(pIE->IntIDPresent) - { - OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID; - } - else - { - /* Octet 3.2 & 3.3 - PRI */ - if(pIE->IntType == 1) - { - OBuf[(*Octet)++] = 0x80 - | (pIE->CodStand << 5) - | (pIE->NumMap << 4) - | pIE->ChanMapType; - - /* Octet 3.2 Channel number/slot map */ - OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; - } - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) -{ - L3INT Octet = *IOff; - L3INT l = IBuf[Octet]; - L3USHORT CRV; - Octet++; /*Octet 2 is length indicator */ - - if(l == 1) /* One octet CRV */ - { - CRV = IBuf[Octet]; - Octet++; - } - else if(l==2) /* two octet CRV */ - { - CRV = IBuf[Octet] << 8; - CRV = CRV + IBuf[Octet+1]; - Octet += 2; - } - 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 *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize=0; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - IESize = 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 - ********************************************************************/ - pie->Format=0; - - /* Octet 6 - Hour (optional)*/ - if(IESize >= 6) - { - pie->Format = 1; - pie->Hour = IBuf[Octet++]; - - /* Octet 7 - Minute (optional)*/ - if(IESize >= 7) - { - pie->Format = 2; - pie->Minute = IBuf[Octet++]; - - /* Octet 8 - Second (optional)*/ - if(IESize >= 8) - { - pie->Format = 3; - pie->Second = IBuf[Octet++]; - } - } - } - - Q931IESizeTest(Q931E_DATETIME); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_DateTime); - pie->Size = sizeof(Q931ie_DateTime); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Display * pie = (Q931ie_Display*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - IESize = IBuf[Octet ++]; - - for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } - - Q931IESizeTest(Q931E_DISPLAY); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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) + 1; - - for(x=0; x< DSize; x++) - { - - OBuf[(*Octet)++] = pIE->Display[x]; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_HLComp); - pie->Size = sizeof(Q931ie_HLComp); - - Q931SetIE(*pIE, *OOff); - - 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 *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) | (pIE->Interpret << 2) | pIE->PresMeth; - - /* Octet 4 */ - OBuf[(*Octet)++] = pIE->HLCharID; - - /* Octet 4a */ - if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) - { - OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; - } - else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) - { - OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; - } - else - { - OBuf[(*Octet)-1] |= 0x80; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - IESize = IBuf[Octet ++]; - - for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } - - Q931IESizeTest(Q931E_KEYPADFAC); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; - pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; - pie->Parity =IBuf[Octet+Off] & 0x07; - Off++; - - /* Octet 5d */ - if((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - pie->DefPackSize = IBuf[Octet+Off] & 0x0f; - Off++; - - /* Octet 7c */ - if((IBuf[Octet+Off-1] & 0x80) != 0) - { - pie->PackWinSize= IBuf[Octet+Off] & 0x7f; - } - } - } - } - } - else - { - Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); - return Q931E_LLCOMP; - } - - Q931IESizeTest(Q931E_LLCOMP); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_LLComp); - pie->Size = sizeof(Q931ie_LLComp); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2*/ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->Notification = IBuf[Octet+Off] & 0x7f; - - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; - - Q931IESizeTest(Q931E_NOTIFIND); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NotifInd); - pie->Size = sizeof(Q931ie_NotifInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_ProgInd); - pie->Size = sizeof(Q931ie_ProgInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - - *pIE=0; - - pie->IEId = IBuf[Octet] & 0xf0; - pie->RepeatInd = IBuf[Octet] & 0x0f; - Octet ++; - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); - pie->Size = sizeof(Q931ie_RepeatInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - ie iE; - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2*/ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->Class = IBuf[Octet+Off] & 0x07; - - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; - - Q931IESizeTest(Q931E_RESTARTIND); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RestartInd); - pie->Size = sizeof(Q931ie_RestartInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Segment); - pie->Size = sizeof(Q931ie_Segment); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - - *pIE=0; - - Octet ++; - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_SendComplete); - pie->Size = sizeof(Q931ie_SendComplete); - - Q931SetIE(*pIE, *OOff); - - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2*/ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->Signal = IBuf[Octet+Off]; - Octet++; - - Q931IESizeTest(Q931E_SIGNAL); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Signal); - pie->Size = sizeof(Q931ie_Signal); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; - - /* 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++; - } - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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;xNetID[x]; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; - - /* Octet 3*/ - pie->ProtDisc = IBuf[Octet+Off]; - Octet++; - - for(x=0; x < l; x++) - { - pie->User[x] = IBuf[Octet+Off]; - Off++; - } - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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;xUser[x]; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - return rc; -} - +/***************************************************************************** + + 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" + +/***************************************************************************** + + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; + L3INT rc=0; + L3INT Beg=*Octet;/* remember current offset */ + L3INT li; + + OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; + li=(*Octet)++; /* remember length position */ + + /* Octet 3 - Coding standard / Information transfer capability */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); + + /* Octet 4 - Transfer mode / Information transfer rate */ + if(pIE->ITR == 0x18) + { + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + } + else + { + OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + + /* Octet 4.1 - Rate Multiplier */ + OBuf[(*Octet)++] = 0x80 | pIE->RateMul; + } + + /* 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) | (pIE->UIL1Prot & 0x15); + + /* Octet 5a - SyncAsync/Negot/UserRate */ + OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (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) + | (pIE->NIConTx << 4) + | (pIE->NIConRx << 3) + | (pIE->FlowCtlTx << 2) + | (pIE->FlowCtlRx << 1); + } + else if(pIE->UIL1Prot == 0x08) /* ITU V.120 */ + { + /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/ + OBuf[(*Octet)++] = 0x00 + | (pIE->InterRate << 6) + | (pIE->MultiFrame << 5) + | (pIE->Mode << 4) + | (pIE->LLInegot << 3) + | (pIE->Assignor << 2) + | (pIE->InBandNeg << 1); + } + + /* Octet 5c - NumStopBits/NumStartBits/Parity */ + OBuf[(*Octet)++] = 0x00 + | (pIE->NumStopBits << 5 ) + | (pIE->NumDataBits << 3 ) + | (pIE->Parity); + + /* Octet 5d - Duplex Mode/Modem Type */ + OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); + } + } + + /* Octet 6 - Layer2Ident/User information layer 2 prtocol */ + if(pIE->Layer2Ident == 0x02) + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot); + } + + /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ + if(pIE->Layer3Ident == 0x03) + { + if(pIE->UIL3Prot == 0x0c) + { + OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + + /* Octet 7a - Additional information layer 3 msb */ + OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); + + /* Octet 7b - Additional information layer 3 lsb */ + OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + } + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + do{ + pie->CallId[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); + + Q931IESizeTest(Q931E_CALLID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallState); + pie->Size = sizeof(Q931ie_CallState); + + Q931SetIE(*pIE, *OOff); + + 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 *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)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLEDSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; /* # digits in this case */ + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; + pie->NumPlanID = IBuf[Octet+Off] & 0x0f; + Octet ++; + + /* Octet 4*/ + for (x = 0; x < IESize && x < 20; x++) + { + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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_NUMBER; + 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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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 4a*/ + x=0; + do{ + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGNUM); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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_CalledSub) + 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 3a */ + /* + + Details about the use and how to detect if Octet 3a is used + are very weak. Temp left out. + + Octet 3 msb is set to 1 to indicate that this is not present + + */ + + /* Octet 4 */ + for(x=0;xDigit[x]; + } + + OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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; + + Q931IESizeTest(Q931E_CAUSE); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Cause); + pie->Size = sizeof(Q931ie_Cause); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->CongLevel = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CongLevel); + pie->Size = sizeof(Q931ie_CongLevel); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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], Off); + Octet++; + + /* 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++; + } + else + { + /* 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; + Off = Q931ReadExt(&IBuf[Octet+Off], Off); + Off++; + } + } + + Q931IESizeTest(Q931E_CHANID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *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) + | (pIE->IntType<<5) + | (pIE->PrefExcl<<3) + | pIE->InfoChanSel; + + /* Octet 3.1 - Interface Identifier */ + if(pIE->IntIDPresent) + { + OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID; + } + else + { + /* Octet 3.2 & 3.3 - PRI */ + if(pIE->IntType == 1) + { + OBuf[(*Octet)++] = 0x80 + | (pIE->CodStand << 5) + | (pIE->NumMap << 4) + | pIE->ChanMapType; + + /* Octet 3.2 Channel number/slot map */ + OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; + } + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + L3INT Octet = *IOff; + L3INT l = IBuf[Octet]; + L3USHORT CRV; + Octet++; /*Octet 2 is length indicator */ + + if(l == 1) /* One octet CRV */ + { + CRV = IBuf[Octet]; + Octet++; + } + else if(l==2) /* two octet CRV */ + { + CRV = IBuf[Octet] << 8; + CRV = CRV + IBuf[Octet+1]; + Octet += 2; + } + 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 *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize=0; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + IESize = 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 + ********************************************************************/ + pie->Format=0; + + /* Octet 6 - Hour (optional)*/ + if(IESize >= 6) + { + pie->Format = 1; + pie->Hour = IBuf[Octet++]; + + /* Octet 7 - Minute (optional)*/ + if(IESize >= 7) + { + pie->Format = 2; + pie->Minute = IBuf[Octet++]; + + /* Octet 8 - Second (optional)*/ + if(IESize >= 8) + { + pie->Format = 3; + pie->Second = IBuf[Octet++]; + } + } + } + + Q931IESizeTest(Q931E_DATETIME); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_DateTime); + pie->Size = sizeof(Q931ie_DateTime); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Display * pie = (Q931ie_Display*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_DISPLAY); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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) + 1; + + for(x=0; x< DSize; x++) + { + + OBuf[(*Octet)++] = pIE->Display[x]; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_HLComp); + pie->Size = sizeof(Q931ie_HLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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) | (pIE->Interpret << 2) | pIE->PresMeth; + + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->HLCharID; + + /* Octet 4a */ + if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) + { + OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; + } + else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) + { + OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; + } + else + { + OBuf[(*Octet)-1] |= 0x80; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_KEYPADFAC); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; + pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; + pie->Parity =IBuf[Octet+Off] & 0x07; + Off++; + + /* Octet 5d */ + if((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + pie->DefPackSize = IBuf[Octet+Off] & 0x0f; + Off++; + + /* Octet 7c */ + if((IBuf[Octet+Off-1] & 0x80) != 0) + { + pie->PackWinSize= IBuf[Octet+Off] & 0x7f; + } + } + } + } + } + else + { + Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); + return Q931E_LLCOMP; + } + + Q931IESizeTest(Q931E_LLCOMP); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_LLComp); + pie->Size = sizeof(Q931ie_LLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Notification = IBuf[Octet+Off] & 0x7f; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_NOTIFIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NotifInd); + pie->Size = sizeof(Q931ie_NotifInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ProgInd); + pie->Size = sizeof(Q931ie_ProgInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->RepeatInd = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); + pie->Size = sizeof(Q931ie_RepeatInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + ie iE; + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Class = IBuf[Octet+Off] & 0x07; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_RESTARTIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RestartInd); + pie->Size = sizeof(Q931ie_RestartInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Segment); + pie->Size = sizeof(Q931ie_Segment); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_SendComplete); + pie->Size = sizeof(Q931ie_SendComplete); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Signal = IBuf[Octet+Off]; + Octet++; + + Q931IESizeTest(Q931E_SIGNAL); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Signal); + pie->Size = sizeof(Q931ie_Signal); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* 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++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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;xNetID[x]; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* Octet 3*/ + pie->ProtDisc = IBuf[Octet+Off]; + Octet++; + + for(x=0; x < l; x++) + { + pie->User[x] = IBuf[Octet+Off]; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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;xUser[x]; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + return rc; +} + diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 8451ff48d5..d376f8d176 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1,1931 +1,1931 @@ -/***************************************************************************** - - 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" - -/***************************************************************************** - - Function: Q931Umes_Alerting - -*****************************************************************************/ - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; - L3INT rc=Q931E_NO_ERROR; - L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; - while(IOff < Size) - { - switch(mescode) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Alerting - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_CallProceeding - -*****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_CallProceeding - -*****************************************************************************/ -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_CongestionControl - -*****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - - -/***************************************************************************** - - Function: Q931Pmes_CongestionControl - -*****************************************************************************/ -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_Connect - -*****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Connect - -*****************************************************************************/ -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Date/Time */ - if(Q931IsIEPresent(pMes->DateTime)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Low Layer Compatibility */ - if(Q931IsIEPresent(pMes->LLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ConnectAck - -*****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_ConnectAck - -*****************************************************************************/ -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Disconnect - -*****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Disconnect - -*****************************************************************************/ -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Information - -*****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Information *mes = (Q931mes_Information*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Information) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Information - -*****************************************************************************/ -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Information *pMes = (Q931mes_Information *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Sending Complete */ - if(Q931IsIEPresent(pMes->SendComplete)) - OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Keypad Facility */ - if(Q931IsIEPresent(pMes->KeypadFac)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Called Party number */ - if(Q931IsIEPresent(pMes->CalledNum)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Notify - -*****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - } - } - mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Notify - -*****************************************************************************/ -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Progress - -*****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Progress - -*****************************************************************************/ -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Release - -*****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Release *mes = (Q931mes_Release*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Release) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Release - -*****************************************************************************/ -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Release *pMes = (Q931mes_Release *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ReleaseComplete - -*****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_ReleaseComplete - -*****************************************************************************/ -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Restart - -*****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_Restart - -*****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_RestartAck - -*****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_Resume - -*****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Resume - -*****************************************************************************/ -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Call Identity */ - if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ResumeAck - -*****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_ResumeAck - -*****************************************************************************/ -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ResumeReject - -*****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_ResumeReject - -*****************************************************************************/ -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) -{ - L3INT i = IOff; - - return IOff - i; -} - -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_Setup - -*****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - L3INT ir=0; - L3INT OOff=0; - Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_REPEAT_INDICATOR: - if(ir==0) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - ir++; - } - else if(ir==1) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - ir++; - } - else - { - return Q931E_ILLEGAL_IE; - } - break; - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Setup - - Decription: Pack a Q931mes_Setup 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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* 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][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Network spesific facilities */ - if(Q931IsIEPresent(pMes->NetFac)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Date/Time */ - if(Q931IsIEPresent(pMes->DateTime)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Keypad Facility */ - if(Q931IsIEPresent(pMes->KeypadFac)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Calling Party Number */ - if(Q931IsIEPresent(pMes->CallingNum)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Calling Party Subaddress */ - if(Q931IsIEPresent(pMes->CallingSub)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Called Party number */ - if(Q931IsIEPresent(pMes->CalledNum)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Called party subaddress */ - if(Q931IsIEPresent(pMes->CalledSub)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Transit network selection */ - if(Q931IsIEPresent(pMes->TransNetSel)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_SetupAck - -*****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_SetupAck - -*****************************************************************************/ -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Status - -*****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Status *mes = (Q931mes_Status*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Status) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_Status - -*****************************************************************************/ -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Status *pMes = (Q931mes_Status *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Call State */ - if(Q931IsIEPresent(pMes->CallState)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_StatusEnquiry - -*****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_StatusEnquiry - -*****************************************************************************/ -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Suspend - -*****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Suspend - -*****************************************************************************/ -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Call Identity */ - if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_SuspendAck - -*****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - - { - switch(IBuf[IOff]) - { - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_SuspendAck - -*****************************************************************************/ -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_SuspendReject - -*****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_SuspendReject - -*****************************************************************************/ -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_UserInformation - -*****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_UserInformation - -*****************************************************************************/ -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - +/***************************************************************************** + + 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" + +/***************************************************************************** + + Function: Q931Umes_Alerting + +*****************************************************************************/ + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; + L3INT rc=Q931E_NO_ERROR; + L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; + while(IOff < Size) + { + switch(mescode) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Alerting + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CallProceeding + +*****************************************************************************/ +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_CallProceeding + +*****************************************************************************/ +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CongestionControl + +*****************************************************************************/ +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + + +/***************************************************************************** + + Function: Q931Pmes_CongestionControl + +*****************************************************************************/ +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Connect + +*****************************************************************************/ +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Connect + +*****************************************************************************/ +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Low Layer Compatibility */ + if(Q931IsIEPresent(pMes->LLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ConnectAck + +*****************************************************************************/ +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ConnectAck + +*****************************************************************************/ +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Disconnect + +*****************************************************************************/ +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Disconnect + +*****************************************************************************/ +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Information + +*****************************************************************************/ +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Information *mes = (Q931mes_Information*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Information) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Information + +*****************************************************************************/ +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Information *pMes = (Q931mes_Information *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Sending Complete */ + if(Q931IsIEPresent(pMes->SendComplete)) + OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Notify + +*****************************************************************************/ +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_NOTIFICATION_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + } + } + mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Notify + +*****************************************************************************/ +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Progress + +*****************************************************************************/ +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Progress + +*****************************************************************************/ +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Release + +*****************************************************************************/ +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Release *mes = (Q931mes_Release*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Release) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Release + +*****************************************************************************/ +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Release *pMes = (Q931mes_Release *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Resume + +*****************************************************************************/ +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Resume + +*****************************************************************************/ +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeAck + +*****************************************************************************/ +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeAck + +*****************************************************************************/ +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeReject + +*****************************************************************************/ +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeReject + +*****************************************************************************/ +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +{ + L3INT i = IOff; + + return IOff - i; +} + +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Setup + +*****************************************************************************/ +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + L3INT ir=0; + L3INT OOff=0; + Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_REPEAT_INDICATOR: + if(ir==0) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else if(ir==1) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else + { + return Q931E_ILLEGAL_IE; + } + break; + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_NETWORK_SPECIFIC_FACILITIES: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_TRANSIT_NETWORK_SELECTION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Setup + + Decription: Pack a Q931mes_Setup 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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Network spesific facilities */ + if(Q931IsIEPresent(pMes->NetFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Number */ + if(Q931IsIEPresent(pMes->CallingNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Subaddress */ + if(Q931IsIEPresent(pMes->CallingSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called party subaddress */ + if(Q931IsIEPresent(pMes->CalledSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Transit network selection */ + if(Q931IsIEPresent(pMes->TransNetSel)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SetupAck + +*****************************************************************************/ +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SetupAck + +*****************************************************************************/ +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Status + +*****************************************************************************/ +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Status *mes = (Q931mes_Status*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALL_STATE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Status) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_Status + +*****************************************************************************/ +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Status *pMes = (Q931mes_Status *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Call State */ + if(Q931IsIEPresent(pMes->CallState)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Suspend + +*****************************************************************************/ +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Suspend + +*****************************************************************************/ +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendAck + +*****************************************************************************/ +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendAck + +*****************************************************************************/ +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendReject + +*****************************************************************************/ +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendReject + +*****************************************************************************/ +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_UserInformation + +*****************************************************************************/ +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_UserInformation + +*****************************************************************************/ +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index 97e4fe1a42..c04d4f7ee4 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -1,310 +1,310 @@ -/***************************************************************************** - - 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 *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Facility - -*****************************************************************************/ -L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_Hold - -*****************************************************************************/ - -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Hold - -*****************************************************************************/ -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_HoldAck - -*****************************************************************************/ - -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_HoldAck - -*****************************************************************************/ -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_HoldReject - -*****************************************************************************/ - -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_HoldReject - -*****************************************************************************/ -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_Register - -*****************************************************************************/ - -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Register *mes = (Q932mes_Register*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Register) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Register - -*****************************************************************************/ -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_Retrieve - -*****************************************************************************/ - -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Retrieve - -*****************************************************************************/ -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_RetrieveAck - -*****************************************************************************/ - -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_RetrieveAck - -*****************************************************************************/ -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_RetrieveReject - -*****************************************************************************/ - -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_RetrieveReject - -*****************************************************************************/ -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} +/***************************************************************************** + + 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 *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Facility + +*****************************************************************************/ +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Hold + +*****************************************************************************/ + +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Hold + +*****************************************************************************/ +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldAck + +*****************************************************************************/ + +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldAck + +*****************************************************************************/ +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldReject + +*****************************************************************************/ + +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldReject + +*****************************************************************************/ +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Register + +*****************************************************************************/ + +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Register *mes = (Q932mes_Register*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Register) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Register + +*****************************************************************************/ +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Retrieve + +*****************************************************************************/ + +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Retrieve + +*****************************************************************************/ +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveAck + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveAck + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveReject + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveReject + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 3a0e1b02ac..26d4699c73 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -1,117 +1,117 @@ -/***************************************************************************** - - FileName: q921.h - - Description: Contains headers of a Q.921 protocol on top of the Comet - Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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 3 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. - - Q921Tx23 Send a message to layer 3. - - OnQ921Error Function called every if an error is - deteceted. - - OnQ921Log Function called if logging is active. - - - Maintenance/Configuration interface - - 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. - -*****************************************************************************/ - -#ifndef _Q921 -#define _Q921 - -#define Q921MAXTRUNK 4 -#define Q921MAXHDLCSPACE 3000 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit - or larger. - -*****************************************************************************/ - -#define L2UCHAR unsigned char /* Min 8 bit */ -#define L2INT int /* Min 16 bit signed */ - -typedef struct -{ - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; - L2UCHAR vs; - L2UCHAR vr; - int state; -}Q921Data; - -void Q921Init(); -void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); -int Q921Rx12(long trunk); - -#endif - +/***************************************************************************** + + FileName: q921.h + + Description: Contains headers of a Q.921 protocol on top of the Comet + Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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 3 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. + + Q921Tx23 Send a message to layer 3. + + OnQ921Error Function called every if an error is + deteceted. + + OnQ921Log Function called if logging is active. + + + Maintenance/Configuration interface + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXTRUNK 4 +#define Q921MAXHDLCSPACE 3000 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + or larger. + +*****************************************************************************/ + +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ + +typedef struct +{ + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR vr; + int state; +}Q921Data; + +void Q921Init(); +void Q921SetHeaderSpace(int hspace); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); +int Q921Rx12(long trunk); + +#endif + diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 04697bedc5..247937e97d 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1,2412 +1,2412 @@ -/****************************************************************************** - - 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) -#endif - -/***************************************************************************** - - Error Codes - -*****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have 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 - -/***************************************************************************** - - 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 Q931L4BUF 1000 /* size of message buffer */ - -#define Q931L2BUF 300 /* size of message buffer */ - -#define Q931MAXTRUNKS 1 /* 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. */ - -/***************************************************************************** - - 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 schoose 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 2 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ - - -#define Q931MAXMES 255 /* Number of messages */ - -#define Q931MAXIE 255 /* Number of IE */ - -#define Q931MAXSTATE 100 /* Size of state tables */ - -/***************************************************************************** - - 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 0x7a /* 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 */ - - -/* Single octet information elements */ -#define Q931ie_SHIFT 0x90 /* 1001 ---- */ -#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; - -/***************************************************************************** - - 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 */ - 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 */ - L3INT CRV; /* Call reference value */ - - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; - - ie Segment; /* Segmented message */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie CallID; /* Call Identity */ - ie ChanID; /* Channel Identification */ - 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 RestartInd; /* Restart Indicator */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High Layer Compatibility */ - ie UserUser; /* User-user */ - ie Escape; /* Escape for extension */ - L3UCHAR buf[1]; /* Buffer for IE's */ - -}Q931mes_Generic; - -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; - -/***************************************************************************** - - Struct: Q931_TrunkInfo - - Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated - channels in the system. - - The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. - -*****************************************************************************/ - -typedef struct -{ - enum _NetUser /* Network/User Mode. */ - { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ - }NetUser; - - L3UCHAR Dialect; /* Q.931 Based dielact index. */ - - enum _TrunkType /* 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 */ - }TrunkType; - - L3UCHAR Enabled; /* Enabled/Disabled */ - /* 0 = Disabled */ - /* 1 = Enabled */ - - enum _TrState /* Trunk State */ - { - Q931_TrState_NoAlignment=0, /* Trunk not aligned */ - Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2 /* Trunk Aligned */ - }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 send 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. */ - - /* 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 - { - enum _ChanType{ - 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 */ - }ChanType; - - 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 _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - -}Q931_TrunkInfo; - -/***************************************************************************** - - 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 define it's own state table and the logic only need - to 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. - -*****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -/***************************************************************************** - - 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) (&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. - -*****************************************************************************/ - -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; - -#include "Q932.h" - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - -/***************************************************************************** - - Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); - -/***************************************************************************** - - Q.931 Process Function Prototyping. Implemented in Q931StateTE.c - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -/***************************************************************************** - - Interface Function Prototypes. Implemented in Q931.c - -*****************************************************************************/ -void Q931TimeTick(L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); -void Q931CreateTE(L3UCHAR i); -void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); -void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); -void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); - -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); - -void Q931Initialize(); -void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); - -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); -L3ULONG Q931GetTime(); -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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); - -#endif /* _Q931_NL */ +/****************************************************************************** + + 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) +#endif + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 Q931L4BUF 1000 /* size of message buffer */ + +#define Q931L2BUF 300 /* size of message buffer */ + +#define Q931MAXTRUNKS 1 /* 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + 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 */ + L3INT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ + +typedef struct +{ + enum _NetUser /* Network/User Mode. */ + { + Q931_TE=0, /* 0 : User Mode */ + Q931_NT=1 /* 1 : Network Mode */ + }NetUser; + + L3UCHAR Dialect; /* Q.931 Based dielact index. */ + + enum _TrunkType /* 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 */ + }TrunkType; + + L3UCHAR Enabled; /* Enabled/Disabled */ + /* 0 = Disabled */ + /* 1 = Enabled */ + + enum _TrState /* Trunk State */ + { + Q931_TrState_NoAlignment=0, /* Trunk not aligned */ + Q931_TrState_Aligning=1, /* Aligning in progress */ + Q931_TrState_Aligned=2 /* Trunk Aligned */ + }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 send 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. */ + + /* 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 + { + enum _ChanType{ + 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 */ + }ChanType; + + 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }call[Q931MAXCALLPERTRUNK]; + +}Q931_TrunkInfo; + +/***************************************************************************** + + 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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); +void Q931CreateTE(L3UCHAR i); +void Q931CreateNT(L3UCHAR i); +void Q931SetMesCreateCB(L3INT (*callback)()); +void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +#endif /* _Q931_NL */ diff --git a/libs/openzap/src/isdn/include/Q932.h b/libs/openzap/src/isdn/include/Q932.h index fa17e38ae7..19b5c4c149 100644 --- a/libs/openzap/src/isdn/include/Q932.h +++ b/libs/openzap/src/isdn/include/Q932.h @@ -1,191 +1,191 @@ -/***************************************************************************** - - 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 */ - -/***************************************************************************** - Struct: Q932ie_Facility -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Facility; - -/***************************************************************************** - Struct: Q932ie_Hold -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Hold; - -/***************************************************************************** - Struct: Q932ie_HoldAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldAck; - -/***************************************************************************** - Struct: Q932ie_HoldReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldReject; - -/***************************************************************************** - Struct: Q932ie_Register -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Register; - -/***************************************************************************** - Struct: Q932ie_Retrieve -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Retrieve; - -/***************************************************************************** - Struct: Q932ie_RetrieveAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveAck; - -/***************************************************************************** - Struct: Q932ie_RetrieveReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveReject; - -/***************************************************************************** - Function Prototypes. -*****************************************************************************/ -L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); - -L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); - -L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +/***************************************************************************** + + 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 */ + +/***************************************************************************** + Struct: Q932ie_Facility +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Facility; + +/***************************************************************************** + Struct: Q932ie_Hold +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Hold; + +/***************************************************************************** + Struct: Q932ie_HoldAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldAck; + +/***************************************************************************** + Struct: Q932ie_HoldReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldReject; + +/***************************************************************************** + Struct: Q932ie_Register +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Register; + +/***************************************************************************** + Struct: Q932ie_Retrieve +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Retrieve; + +/***************************************************************************** + Struct: Q932ie_RetrieveAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveAck; + +/***************************************************************************** + Struct: Q932ie_RetrieveReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveReject; + +/***************************************************************************** + Function Prototypes. +*****************************************************************************/ +L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); diff --git a/libs/openzap/src/isdn/include/mfifo.h b/libs/openzap/src/isdn/include/mfifo.h index 788adfdb10..99faa1d1ba 100644 --- a/libs/openzap/src/isdn/include/mfifo.h +++ b/libs/openzap/src/isdn/include/mfifo.h @@ -1,83 +1,83 @@ -/***************************************************************************** - - 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 _mfifo -{ - 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); - -#endif +/***************************************************************************** + + 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 _mfifo +{ + 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); + +#endif diff --git a/libs/openzap/src/isdn/mfifo.c b/libs/openzap/src/isdn/mfifo.c index 9e409f8a92..a1e85dedf4 100644 --- a/libs/openzap/src/isdn/mfifo.c +++ b/libs/openzap/src/isdn/mfifo.c @@ -1,296 +1,296 @@ -/***************************************************************************** - - 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; - mf = (MFIFO*)buf; - - mf->first = mf->last = 0; - mf->ixsize = index; - mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; - - if(mf->buf > & buf[size]) - return 0; - - mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); - - return 1; -} - -/***************************************************************************** - - Function: MFIFOClear - - Description: Clear the FIFO - - Paremeters: buf ptr to fifo - - Return Value: none - -*****************************************************************************/ -void MFIFOClear(unsigned char * buf) -{ - MFIFO * mf; - 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; - 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) -{ - int x; - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->last == mf->first) - return 0; - x=mf->first; - x--; - if(x<0) - x=mf->ixsize; - 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) -{ - int x; - MFIFO * mf; - mf = (MFIFO*)buf; - 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) -{ - int of,ol,x; - MFIFO * mf; - mf = (MFIFO*)buf; - - 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; - 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) -{ - int x; - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->first!=mf->last) - { - x = mf->last+1; - if(x > mf->ixsize) - x=0; - mf->last=x; - } -} +/***************************************************************************** + + 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; + mf = (MFIFO*)buf; + + mf->first = mf->last = 0; + mf->ixsize = index; + mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; + + if(mf->buf > & buf[size]) + return 0; + + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); + + return 1; +} + +/***************************************************************************** + + Function: MFIFOClear + + Description: Clear the FIFO + + Paremeters: buf ptr to fifo + + Return Value: none + +*****************************************************************************/ +void MFIFOClear(unsigned char * buf) +{ + MFIFO * mf; + 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; + 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) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->last == mf->first) + return 0; + x=mf->first; + x--; + if(x<0) + x=mf->ixsize; + 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) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + 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) +{ + int of,ol,x; + MFIFO * mf; + mf = (MFIFO*)buf; + + 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; + 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) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->first!=mf->last) + { + x = mf->last+1; + if(x > mf->ixsize) + x=0; + mf->last=x; + } +} From f969341e86f9762ea5af96fe59f69fa17813b12a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 May 2007 23:29:33 +0000 Subject: [PATCH 0170/1766] change linefeeds git-svn-id: http://svn.openzap.org/svn/openzap/trunk@85 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/EuroISDNStateNT.c | 92 +- libs/freetdm/src/isdn/EuroISDNStateTE.c | 114 +- libs/freetdm/src/isdn/Q921.c | 848 ++-- libs/freetdm/src/isdn/Q931.c | 1332 ++--- libs/freetdm/src/isdn/Q931StateNT.c | 2526 +++++----- libs/freetdm/src/isdn/Q931StateTE.c | 2632 +++++----- libs/freetdm/src/isdn/Q931api.c | 1278 ++--- libs/freetdm/src/isdn/Q931ie.c | 5904 +++++++++++------------ libs/freetdm/src/isdn/Q931mes.c | 3862 +++++++-------- libs/freetdm/src/isdn/Q932mes.c | 620 +-- libs/freetdm/src/isdn/include/Q921.h | 234 +- libs/freetdm/src/isdn/include/Q931.h | 4824 +++++++++--------- libs/freetdm/src/isdn/include/Q932.h | 382 +- libs/freetdm/src/isdn/include/mfifo.h | 166 +- libs/freetdm/src/isdn/mfifo.c | 592 +-- 15 files changed, 12703 insertions(+), 12703 deletions(-) diff --git a/libs/freetdm/src/isdn/EuroISDNStateNT.c b/libs/freetdm/src/isdn/EuroISDNStateNT.c index 9c2fc45616..ccfaba0d16 100644 --- a/libs/freetdm/src/isdn/EuroISDNStateNT.c +++ b/libs/freetdm/src/isdn/EuroISDNStateNT.c @@ -1,46 +1,46 @@ -/***************************************************************************** - - 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" - - +/***************************************************************************** + + 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/freetdm/src/isdn/EuroISDNStateTE.c b/libs/freetdm/src/isdn/EuroISDNStateTE.c index cf0631c92b..250d33ffd2 100644 --- a/libs/freetdm/src/isdn/EuroISDNStateTE.c +++ b/libs/freetdm/src/isdn/EuroISDNStateTE.c @@ -1,57 +1,57 @@ -/***************************************************************************** - - 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 -*/ - -void EuroISDNCreateTE(L3UCHAR i) -{ - Q931CreateTE(i); -} +/***************************************************************************** + + 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 +*/ + +void EuroISDNCreateTE(L3UCHAR i) +{ + Q931CreateTE(i); +} diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index b36c76965d..27802d877d 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -1,424 +1,424 @@ -/***************************************************************************** - - FileName: q921.c - - Description: Contains the implementation of a Q.921 protocol on top of the - Comet Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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. - -*****************************************************************************/ -#include "Q921.h" -#include -#include "mfifo.h" - -/***************************************************************************** - Global Tables & Variables. -*****************************************************************************/ -Q921Data Q921DevSpace[Q921MAXTRUNK]; -int Q921HeaderSpace={0}; - -int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; - -/***************************************************************************** - - Function: Q921Init - - Decription: Initialize the Q.921 stack so it is ready for use. This - function MUST be called as part of initializing the - application. - -*****************************************************************************/ -void Q921Init() -{ - int x; - for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - } - } - - /* check for RR */ - else if(mes[2] ==0x01) - { - /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); - - return 1; - } - return 0; -} - +/***************************************************************************** + + FileName: q921.c + + Description: Contains the implementation of a Q.921 protocol on top of the + Comet Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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. + +*****************************************************************************/ +#include "Q921.h" +#include +#include "mfifo.h" + +/***************************************************************************** + Global Tables & Variables. +*****************************************************************************/ +Q921Data Q921DevSpace[Q921MAXTRUNK]; +int Q921HeaderSpace={0}; + +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; + +/***************************************************************************** + + Function: Q921Init + + Decription: Initialize the Q.921 stack so it is ready for use. This + function MUST be called as part of initializing the + application. + +*****************************************************************************/ +void Q921Init() +{ + int x; + for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index ac22d79d25..09cbaf0b76 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -1,666 +1,666 @@ -/***************************************************************************** - - 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 "Q931.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 dielects 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. - -*****************************************************************************/ -L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -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. - -*****************************************************************************/ - -L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - /* callback for messages to be send to */ - /* layer 4. */ - -L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); - /* callback ptr for messages to be send */ - /* to layer 2. */ - -L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); - /* callback for error messages. */ - -L3ULONG (*Q931GetTimeProc) ()=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: Q931 - - Description: Dummy function for message processing. - -*****************************************************************************/ -L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) -{ - return Q931E_INTERNAL; -} - -/***************************************************************************** - - Function: Q931 - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - return Q931E_UNKNOWN_MESSAGE; -} - -/***************************************************************************** - - Function: Q931 - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - return Q931E_UNKNOWN_IE; -} - -/***************************************************************************** - - Function: Q931 - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - return Q931E_UNKNOWN_MESSAGE; -} - -/***************************************************************************** - - Function: Q931PieDummy - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) -{ - return Q931E_UNKNOWN_IE; -} - -/***************************************************************************** - - Function: Q931TxDummy - - Description: Dummy function for message processing - -*****************************************************************************/ -L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) -{ - return Q931E_MISSING_CB; -} - -/***************************************************************************** - - Function: Q931ErrorDummy - - Description: Dummy function for error processing - -*****************************************************************************/ -L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,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 diealect 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 */ - Q931Tx34Proc = Q931TxDummy; - Q931Tx32Proc = Q931TxDummy; - 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 0 : Warning - see q931errors.h for details. - -*****************************************************************************/ -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) -{ - L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; - - Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; - L3INT ISize; - L3INT IOff = 0; - - /* Protocol Discriminator */ - m->ProtDisc = Mes[IOff++]; - - /* CRV */ - m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); - - /* Message Type */ - m->MesType = Mes[IOff++]; - - /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); - if(RetCode >= Q931E_NO_ERROR) - { - RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); - } - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Tx34 - - Description: Called from the stac 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 *pTrunk, L3UCHAR * Mes, L3INT Size) -{ - return Q931Tx34Proc(pTrunk, Mes, Size); -} - -/***************************************************************************** - - 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 *pTrunk,L3UCHAR * buf, L3INT Size) -{ - Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; - - RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); - - 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 Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) -{ - L3INT OSize; - Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; - L3INT RetCode = Q931E_NO_ERROR; - L3INT iDialect = pTrunk->Dialect; - - /* Call pack function through table. */ - RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { - RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); - } - - 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 *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) -{ - Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); -} - -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx34Proc = Q931Tx34Par; -} - -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx32Proc = Q931Tx32Par; -} - -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) -{ - 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 *pTrunk, L3INT * callIndex) -{ - L3INT CRV = Q931GetUniqueCRV(pTrunk); - - return Q931AllocateCRV(pTrunk, CRV, callIndex); -} - -/***************************************************************************** - - 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 *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 *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 */ -} - -/***************************************************************************** - - Function: Q931StartTimer - - Description: Start a timer. - - Parameters: pTrunk Trunk number - callindex call index. - iTimer timer id -*****************************************************************************/ -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) -{ - pTrunk->call[callIndex].Timer = Q931GetTime(); - pTrunk->call[callIndex].TimerID = iTimerID; - return 0; -} - -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) -{ - if(pTrunk->call[callindex].TimerID == iTimerID) - pTrunk->call[callindex].TimerID = 0; - return 0; -} - -L3INT Q931SetState(Q931_TrunkInfo *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)()) -{ - Q931GetTimeProc = callback; -} - -L3INT Q931FindCRV(Q931_TrunkInfo *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 - sequensial 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; -} +/***************************************************************************** + + 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 "Q931.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 dielects 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. + +*****************************************************************************/ +L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +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. + +*****************************************************************************/ + +L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + /* callback for messages to be send to */ + /* layer 4. */ + +L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); + /* callback ptr for messages to be send */ + /* to layer 2. */ + +L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); + /* callback for error messages. */ + +L3ULONG (*Q931GetTimeProc) ()=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: Q931 + + Description: Dummy function for message processing. + +*****************************************************************************/ +L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) +{ + return Q931E_INTERNAL; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931 + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + return Q931E_UNKNOWN_MESSAGE; +} + +/***************************************************************************** + + Function: Q931PieDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + return Q931E_UNKNOWN_IE; +} + +/***************************************************************************** + + Function: Q931TxDummy + + Description: Dummy function for message processing + +*****************************************************************************/ +L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) +{ + return Q931E_MISSING_CB; +} + +/***************************************************************************** + + Function: Q931ErrorDummy + + Description: Dummy function for error processing + +*****************************************************************************/ +L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,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 diealect 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 */ + Q931Tx34Proc = Q931TxDummy; + Q931Tx32Proc = Q931TxDummy; + 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 0 : Warning + see q931errors.h for details. + +*****************************************************************************/ +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) +{ + L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; + L3INT ISize; + L3INT IOff = 0; + + /* Protocol Discriminator */ + m->ProtDisc = Mes[IOff++]; + + /* CRV */ + m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); + + /* Message Type */ + m->MesType = Mes[IOff++]; + + /* Call table proc to unpack codec message */ + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + } + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Tx34 + + Description: Called from the stac 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 *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + return Q931Tx34Proc(pTrunk, Mes, Size); +} + +/***************************************************************************** + + 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 *pTrunk,L3UCHAR * buf, L3INT Size) +{ + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + L3INT RetCode = Q931E_NO_ERROR; + + RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + + 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 Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +{ + L3INT OSize; + Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; + L3INT RetCode = Q931E_NO_ERROR; + L3INT iDialect = pTrunk->Dialect; + + /* Call pack function through table. */ + RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); + if(RetCode >= Q931E_NO_ERROR) + { + RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); + } + + 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 *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) +{ + Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); +} + +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx34Proc = Q931Tx34Par; +} + +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) +{ + Q931Tx32Proc = Q931Tx32Par; +} + +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) +{ + 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 *pTrunk, L3INT * callIndex) +{ + L3INT CRV = Q931GetUniqueCRV(pTrunk); + + return Q931AllocateCRV(pTrunk, CRV, callIndex); +} + +/***************************************************************************** + + 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 *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 *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 */ +} + +/***************************************************************************** + + Function: Q931StartTimer + + Description: Start a timer. + + Parameters: pTrunk Trunk number + callindex call index. + iTimer timer id +*****************************************************************************/ +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) +{ + pTrunk->call[callIndex].Timer = Q931GetTime(); + pTrunk->call[callIndex].TimerID = iTimerID; + return 0; +} + +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) +{ + if(pTrunk->call[callindex].TimerID == iTimerID) + pTrunk->call[callindex].TimerID = 0; + return 0; +} + +L3INT Q931SetState(Q931_TrunkInfo *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)()) +{ + Q931GetTimeProc = callback; +} + +L3INT Q931FindCRV(Q931_TrunkInfo *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 - sequensial 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; +} diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 0b03170566..2d2a3c5671 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -1,1263 +1,1263 @@ -/***************************************************************************** - - 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); - - /* 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 */ -} - -/***************************************************************************** - - Function: Q931ProcAlertingNT - -*****************************************************************************/ -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcCallProceedingNT - -*****************************************************************************/ -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; - 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 = Q931Tx32(pTrunk,buf,pMes->Size); - if(ret) - return ret; - - Q931StartTimer(pTrunk, callIndex, 303); - - 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) - 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, 303); -#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - +/***************************************************************************** + + 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); + + /* 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 */ +} + +/***************************************************************************** + + Function: Q931ProcAlertingNT + +*****************************************************************************/ +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingNT + +*****************************************************************************/ +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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, 303); +#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 7e870224a8..7941326b05 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -1,1316 +1,1316 @@ -/***************************************************************************** - - 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); - - /* 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: Q931ProcAlertingTE - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcCallProceedingTE - -*****************************************************************************/ -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcConnectAckTE - -*****************************************************************************/ -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; - 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 = Q931Tx32(pTrunk,buf,pMes->Size); - if(ret) - return ret; - - Q931StartTimer(pTrunk, callIndex, 303); - - 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) - 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, 303); -#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); - if(ret != Q931E_NO_ERROR) - return ret; - - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - Q931StartTimer(pTrunk, callIndex, 303); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcResumeTE - -*****************************************************************************/ -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - Q931mes_Resume * pMes = (Q931mes_Resume *)&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=Q931Tx32(pTrunk,buf, pMes->Size); - if(ret != Q931E_NO_ERROR) - return ret; - - /* Start timer T318 */ - Q931StartTimer(pTrunk, callIndex, 318); - - /*set state U17 */ - Q931SetState(pTrunk, callIndex, Q931_U17); - } - else - { - return Q931E_ILLEGAL_MESSAGE; - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcResumeAckTE - -*****************************************************************************/ -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; - L3INT state = Q931GetCallState(pTrunk, pMes->CRV); - L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) - { - ret = Q931ReleaseComplete(pTrunk, iFrom); - } - else - { - ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); - } - - return ret; -} - -/***************************************************************************** - - Function: Q931ProcReleaseCompleteTE - -*****************************************************************************/ -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; - L3INT state = Q931GetCallState(pTrunk, pMes->CRV); - L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) - { - /* no action */ - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcRestartTE - -*****************************************************************************/ -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - -/***************************************************************************** - - Function: Q931ProcRestartAckTE - -*****************************************************************************/ -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - /* 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; -} - +/***************************************************************************** + + 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); + + /* 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: Q931ProcAlertingTE + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcCallProceedingTE + +*****************************************************************************/ +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcConnectAckTE + +*****************************************************************************/ +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT rc=0; + Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + 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 = Q931Tx32(pTrunk,buf,pMes->Size); + if(ret) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + + 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) + 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, 303); +#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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); + if(ret != Q931E_NO_ERROR) + return ret; + + Q931StartTimer(pTrunk, callIndex, 303); + if(iFrom == 4) + { + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + Q931StartTimer(pTrunk, callIndex, 303); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeTE + +*****************************************************************************/ +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Resume * pMes = (Q931mes_Resume *)&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=Q931Tx32(pTrunk,buf, pMes->Size); + if(ret != Q931E_NO_ERROR) + return ret; + + /* Start timer T318 */ + Q931StartTimer(pTrunk, callIndex, 318); + + /*set state U17 */ + Q931SetState(pTrunk, callIndex, Q931_U17); + } + else + { + return Q931E_ILLEGAL_MESSAGE; + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcResumeAckTE + +*****************************************************************************/ +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + ret = Q931ReleaseComplete(pTrunk, iFrom); + } + else + { + ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); + } + + return ret; +} + +/***************************************************************************** + + Function: Q931ProcReleaseCompleteTE + +*****************************************************************************/ +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; + L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + L3INT ret = Q931E_NO_ERROR; + if(state == Q931_U0 && iFrom == 2) + { + /* no action */ + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcRestartTE + +*****************************************************************************/ +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + +/***************************************************************************** + + Function: Q931ProcRestartAckTE + +*****************************************************************************/ +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + /* 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, 303); + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; +} + diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index f1da2c9aa0..e93b43193b 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -1,639 +1,639 @@ -/***************************************************************************** - - 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" - -/* -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; -} -*/ - -void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) -{ - int y; - pTrunk->LastCRV = 0; - pTrunk->Dialect = 0; - pTrunk->Enabled = 0; - pTrunk->TrunkType = Q931_TrType_E1; - pTrunk->NetUser = Q931_TE; - pTrunk->TrunkState = 0; - for(y=0; y < Q931MAXCHPERTRUNK; y++) - { - pTrunk->ch[y].Available = 1; - - /* Set up E1 scheme by default */ - if(y==0) - { - pTrunk->ch[y].ChanType = Q931_ChType_Sync; - } - else if(y==16) - { - pTrunk->ch[y].ChanType = Q931_ChType_D; - } - else - { - pTrunk->ch[y].ChanType = Q931_ChType_B; - } - } - - for(y=0; y < Q931MAXCALLPERTRUNK; y++) - { - pTrunk->call[y].InUse = 0; - - } -} - -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -) -{ - 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, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -) -{ - if(Q931PieProc != NULL) - Q931Pie[dialect][iec] = Q931PieProc; - if(Q931UieProc != NULL) - Q931Uie[dialect][iec] = Q931UieProc; -} - -#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} - -/***************************************************************************** - - Function: Q931GetIEBuf - - Description: Return a ptr to the buf used for IE in the message. - -*****************************************************************************/ -L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) -{ - L3UCHAR * s=NULL; - Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; - switch(pMes->MesType) - { - case Q931mes_ALERTING : - trampoline(Q931mes_Alerting); - break; - - case Q931mes_CALL_PROCEEDING : - trampoline(Q931mes_CallProceeding); - break; - - case Q931mes_CONNECT : - trampoline(Q931mes_Connect); - break; - - case Q931mes_CONNECT_ACKNOWLEDGE : - trampoline(Q931mes_ConnectAck); - break; - - case Q931mes_PROGRESS : - trampoline(Q931mes_Progress); - break; - - case Q931mes_SETUP : - trampoline(Q931mes_Setup); - break; - - case Q931mes_SETUP_ACKNOWLEDGE : - trampoline(Q931mes_SetupAck); - break; - - case Q931mes_RESUME : - trampoline(Q931mes_Resume); - break; - - case Q931mes_RESUME_ACKNOWLEDGE : - trampoline(Q931mes_ResumeAck); - break; - - case Q931mes_RESUME_REJECT : - trampoline(Q931mes_ResumeReject); - break; - - case Q932mes_RETRIEVE : - trampoline(Q932mes_Retrieve); - break; - - case Q932mes_RETRIEVE_ACKNOWLEDGE : - trampoline(Q932mes_RetrieveAck); - break; - - case Q932mes_RETRIEVE_REJECT : - trampoline(Q932mes_RetrieveReject); - break; - - case Q931mes_SUSPEND : - trampoline(Q931mes_Suspend); - break; - - case Q931mes_SUSPEND_ACKNOWLEDGE : - trampoline(Q931mes_SuspendAck); - break; - - case Q931mes_SUSPEND_REJECT : - trampoline(Q931mes_SuspendReject); - break; - - case Q931mes_USER_INFORMATION : - trampoline(Q931mes_UserInformation); - break; - - case Q931mes_DISCONNECT : - trampoline(Q931mes_Disconnect); - break; - - case Q931mes_RELEASE : - trampoline(Q931mes_Release); - break; - - case Q931mes_RELEASE_COMPLETE : - trampoline(Q931mes_ReleaseComplete); - break; - - case Q931mes_RESTART : - trampoline(Q931mes_Restart); - break; - - case Q931mes_RESTART_ACKNOWLEDGE : - trampoline(Q931mes_RestartAck); - break; - - case Q931mes_CONGESTION_CONTROL : - trampoline(Q931mes_CongestionControl); - break; -#if 0 - case Q931mes_FACILITY : - trampoline(Q931mes_Facility); - break; -#endif - - case Q931mes_INFORMATION : - trampoline(Q931mes_Information); - break; - - case Q931mes_NOTIFY : - trampoline(Q931mes_Notify); - break; - -#if 0 - case Q931mes_REGISTER : - trampoline(Q931mes_Register); - break; -#endif - - case Q931mes_STATUS : - trampoline(Q931mes_Status); - break; - - case Q931mes_STATUS_ENQUIRY : - trampoline(Q931mes_StatusEnquiry); - break; - - case Q931mes_SEGMENT : - trampoline(Q931mes_Segment); - break; - - default: - s = 0; - break; - } - - return s; -} - -L3INT Q931GetMesSize(L3UCHAR *pMes) -{ - - L3UCHAR *p = Q931GetIEBuf(pMes); - L3INT Size = (L3INT)(p - 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_Alerting * pMes= (Q931mes_Alerting *)pm; - Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; - L3INT iISize = pIE->Size; - - L3UCHAR *pBuf = Q931GetIEBuf(pm); - L3INT Off = pMes->Size - (pBuf - pm); - IE = (ie)(Off | 0x8000); - - memcpy(&pm[pMes->Size], pi, iISize); - - pMes->Size += iISize; - - return IE; -} - -/***************************************************************************** -*****************************************************************************/ -L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) -{ - static L3INT crv={1}; - return crv++; -} - -L3INT Q931InitMesSetup(Q931mes_Setup *pMes) -{ - pMes->ProtDisc = 0x80; - pMes->CRV = 0; /* CRV to be allocated, might be receive*/ - pMes->MesType = Q931mes_SETUP; - - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); - - pMes->SendComplete =0; /* Sending Complete */ - pMes->RepeatInd =0; /* Repeat Indicator */ - pMes->BearerCap =0; /* Bearer Capability */ - pMes->ChanID =0; /* Channel ID */ - pMes->ProgInd =0; /* Progress Indicator */ - pMes->NetFac =0; /* Network-specific facilities */ - pMes->Display =0; /* Display */ - pMes->DateTime =0; /* Date/Time */ - pMes->KeypadFac =0; /* Keypad Facility */ - pMes->Signal =0; /* Signal */ - pMes->CallingNum =0; /* Calling party number */ - pMes->CallingSub =0; /* Calling party sub address */ - pMes->CalledNum =0; /* Called party number */ - pMes->CalledSub =0; /* Called party sub address */ - pMes->TransNetSel =0; /* Transit network selection */ - pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ - pMes->LLComp =0; /* Low layer compatibility */ - pMes->HLComp =0; /* High layer compatibility */ - - return 0; -} - -L3INT Q931InitMesResume(Q931mes_Resume * pMes) -{ - pMes->ProtDisc = 0x80; - pMes->CRV = 0; /* CRV to be allocated, might be receive*/ - pMes->MesType = Q931mes_RESUME; - - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); - pMes->CallID = 0; /* Channel Identification */ - 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 *pTrunk,L3UCHAR * b, L3INT iFrom) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)b; - (void)iFrom; - - return 0; -} - -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)b; - (void)iFrom; - - return 0; -} - -L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)iTo; - (void)iCRV; - (void)iCause; - - return 0; -} - -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) -{ - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)iTo; - - return 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" + +/* +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; +} +*/ + +void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) +{ + int y; + pTrunk->LastCRV = 0; + pTrunk->Dialect = 0; + pTrunk->Enabled = 0; + pTrunk->TrunkType = Q931_TrType_E1; + pTrunk->NetUser = Q931_TE; + pTrunk->TrunkState = 0; + for(y=0; y < Q931MAXCHPERTRUNK; y++) + { + pTrunk->ch[y].Available = 1; + + /* Set up E1 scheme by default */ + if(y==0) + { + pTrunk->ch[y].ChanType = Q931_ChType_Sync; + } + else if(y==16) + { + pTrunk->ch[y].ChanType = Q931_ChType_D; + } + else + { + pTrunk->ch[y].ChanType = Q931_ChType_B; + } + } + + for(y=0; y < Q931MAXCALLPERTRUNK; y++) + { + pTrunk->call[y].InUse = 0; + + } +} + +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +) +{ + 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, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +) +{ + if(Q931PieProc != NULL) + Q931Pie[dialect][iec] = Q931PieProc; + if(Q931UieProc != NULL) + Q931Uie[dialect][iec] = Q931UieProc; +} + +#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} + +/***************************************************************************** + + Function: Q931GetIEBuf + + Description: Return a ptr to the buf used for IE in the message. + +*****************************************************************************/ +L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) +{ + L3UCHAR * s=NULL; + Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + switch(pMes->MesType) + { + case Q931mes_ALERTING : + trampoline(Q931mes_Alerting); + break; + + case Q931mes_CALL_PROCEEDING : + trampoline(Q931mes_CallProceeding); + break; + + case Q931mes_CONNECT : + trampoline(Q931mes_Connect); + break; + + case Q931mes_CONNECT_ACKNOWLEDGE : + trampoline(Q931mes_ConnectAck); + break; + + case Q931mes_PROGRESS : + trampoline(Q931mes_Progress); + break; + + case Q931mes_SETUP : + trampoline(Q931mes_Setup); + break; + + case Q931mes_SETUP_ACKNOWLEDGE : + trampoline(Q931mes_SetupAck); + break; + + case Q931mes_RESUME : + trampoline(Q931mes_Resume); + break; + + case Q931mes_RESUME_ACKNOWLEDGE : + trampoline(Q931mes_ResumeAck); + break; + + case Q931mes_RESUME_REJECT : + trampoline(Q931mes_ResumeReject); + break; + + case Q932mes_RETRIEVE : + trampoline(Q932mes_Retrieve); + break; + + case Q932mes_RETRIEVE_ACKNOWLEDGE : + trampoline(Q932mes_RetrieveAck); + break; + + case Q932mes_RETRIEVE_REJECT : + trampoline(Q932mes_RetrieveReject); + break; + + case Q931mes_SUSPEND : + trampoline(Q931mes_Suspend); + break; + + case Q931mes_SUSPEND_ACKNOWLEDGE : + trampoline(Q931mes_SuspendAck); + break; + + case Q931mes_SUSPEND_REJECT : + trampoline(Q931mes_SuspendReject); + break; + + case Q931mes_USER_INFORMATION : + trampoline(Q931mes_UserInformation); + break; + + case Q931mes_DISCONNECT : + trampoline(Q931mes_Disconnect); + break; + + case Q931mes_RELEASE : + trampoline(Q931mes_Release); + break; + + case Q931mes_RELEASE_COMPLETE : + trampoline(Q931mes_ReleaseComplete); + break; + + case Q931mes_RESTART : + trampoline(Q931mes_Restart); + break; + + case Q931mes_RESTART_ACKNOWLEDGE : + trampoline(Q931mes_RestartAck); + break; + + case Q931mes_CONGESTION_CONTROL : + trampoline(Q931mes_CongestionControl); + break; +#if 0 + case Q931mes_FACILITY : + trampoline(Q931mes_Facility); + break; +#endif + + case Q931mes_INFORMATION : + trampoline(Q931mes_Information); + break; + + case Q931mes_NOTIFY : + trampoline(Q931mes_Notify); + break; + +#if 0 + case Q931mes_REGISTER : + trampoline(Q931mes_Register); + break; +#endif + + case Q931mes_STATUS : + trampoline(Q931mes_Status); + break; + + case Q931mes_STATUS_ENQUIRY : + trampoline(Q931mes_StatusEnquiry); + break; + + case Q931mes_SEGMENT : + trampoline(Q931mes_Segment); + break; + + default: + s = 0; + break; + } + + return s; +} + +L3INT Q931GetMesSize(L3UCHAR *pMes) +{ + + L3UCHAR *p = Q931GetIEBuf(pMes); + L3INT Size = (L3INT)(p - 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_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; + L3INT iISize = pIE->Size; + + L3UCHAR *pBuf = Q931GetIEBuf(pm); + L3INT Off = pMes->Size - (pBuf - pm); + IE = (ie)(Off | 0x8000); + + memcpy(&pm[pMes->Size], pi, iISize); + + pMes->Size += iISize; + + return IE; +} + +/***************************************************************************** +*****************************************************************************/ +L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) +{ + static L3INT crv={1}; + return crv++; +} + +L3INT Q931InitMesSetup(Q931mes_Setup *pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_SETUP; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + + pMes->SendComplete =0; /* Sending Complete */ + pMes->RepeatInd =0; /* Repeat Indicator */ + pMes->BearerCap =0; /* Bearer Capability */ + pMes->ChanID =0; /* Channel ID */ + pMes->ProgInd =0; /* Progress Indicator */ + pMes->NetFac =0; /* Network-specific facilities */ + pMes->Display =0; /* Display */ + pMes->DateTime =0; /* Date/Time */ + pMes->KeypadFac =0; /* Keypad Facility */ + pMes->Signal =0; /* Signal */ + pMes->CallingNum =0; /* Calling party number */ + pMes->CallingSub =0; /* Calling party sub address */ + pMes->CalledNum =0; /* Called party number */ + pMes->CalledSub =0; /* Called party sub address */ + pMes->TransNetSel =0; /* Transit network selection */ + pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ + pMes->LLComp =0; /* Low layer compatibility */ + pMes->HLComp =0; /* High layer compatibility */ + + return 0; +} + +L3INT Q931InitMesResume(Q931mes_Resume * pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_RESUME; + + pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->CallID = 0; /* Channel Identification */ + 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 *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + + return 0; +} + +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)b; + (void)iFrom; + + return 0; +} + +L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + (void)iCRV; + (void)iCause; + + return 0; +} + +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) +{ + /* TODO: Unhandled paramaters */ + (void)pTrunk; + (void)iTo; + + return 0; +} diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 642783e75c..15e93bfee8 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1,2952 +1,2952 @@ -/***************************************************************************** - - 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" - -/***************************************************************************** - - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); - - Q931SetIE(*pIE, *OOff); - - 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) -{ - Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; - L3INT rc=0; - L3INT Beg=*Octet;/* remember current offset */ - L3INT li; - - OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; - li=(*Octet)++; /* remember length position */ - - /* Octet 3 - Coding standard / Information transfer capability */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); - - /* Octet 4 - Transfer mode / Information transfer rate */ - if(pIE->ITR == 0x18) - { - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - } - else - { - OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - - /* Octet 4.1 - Rate Multiplier */ - OBuf[(*Octet)++] = 0x80 | pIE->RateMul; - } - - /* 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) | (pIE->UIL1Prot & 0x15); - - /* Octet 5a - SyncAsync/Negot/UserRate */ - OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (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) - | (pIE->NIConTx << 4) - | (pIE->NIConRx << 3) - | (pIE->FlowCtlTx << 2) - | (pIE->FlowCtlRx << 1); - } - else if(pIE->UIL1Prot == 0x08) /* ITU V.120 */ - { - /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/ - OBuf[(*Octet)++] = 0x00 - | (pIE->InterRate << 6) - | (pIE->MultiFrame << 5) - | (pIE->Mode << 4) - | (pIE->LLInegot << 3) - | (pIE->Assignor << 2) - | (pIE->InBandNeg << 1); - } - - /* Octet 5c - NumStopBits/NumStartBits/Parity */ - OBuf[(*Octet)++] = 0x00 - | (pIE->NumStopBits << 5 ) - | (pIE->NumDataBits << 3 ) - | (pIE->Parity); - - /* Octet 5d - Duplex Mode/Modem Type */ - OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); - } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); - } - } - - /* Octet 6 - Layer2Ident/User information layer 2 prtocol */ - if(pIE->Layer2Ident == 0x02) - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot); - } - - /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ - if(pIE->Layer3Ident == 0x03) - { - if(pIE->UIL3Prot == 0x0c) - { - OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); - - /* Octet 7a - Additional information layer 3 msb */ - OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); - - /* Octet 7b - Additional information layer 3 lsb */ - OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); - } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); - } - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - do{ - pie->CallId[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); - - Q931IESizeTest(Q931E_CALLID); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallState); - pie->Size = sizeof(Q931ie_CallState); - - Q931SetIE(*pIE, *OOff); - - 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 *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)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); - - Q931IESizeTest(Q931E_CALLEDSUB); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; /* # digits in this case */ - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; - pie->NumPlanID = IBuf[Octet+Off] & 0x0f; - Octet ++; - - /* Octet 4*/ - for (x = 0; x < IESize && x < 20; x++) - { - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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_NUMBER; - 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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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 4a*/ - x=0; - do{ - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); - - Q931IESizeTest(Q931E_CALLINGNUM); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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_CalledSub) + 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 3a */ - /* - - Details about the use and how to detect if Octet 3a is used - are very weak. Temp left out. - - Octet 3 msb is set to 1 to indicate that this is not present - - */ - - /* Octet 4 */ - for(x=0;xDigit[x]; - } - - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); - - Q931IESizeTest(Q931E_CALLINGSUB); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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; - - Q931IESizeTest(Q931E_CAUSE); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Cause); - pie->Size = sizeof(Q931ie_Cause); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - - *pIE=0; - - pie->IEId = IBuf[Octet] & 0xf0; - pie->CongLevel = IBuf[Octet] & 0x0f; - Octet ++; - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CongLevel); - pie->Size = sizeof(Q931ie_CongLevel); - - Q931SetIE(*pIE, *OOff); - - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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], Off); - Octet++; - - /* 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++; - } - else - { - /* 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; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); - Off++; - } - } - - Q931IESizeTest(Q931E_CHANID); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); - - Q931SetIE(*pIE, *OOff); - - 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 *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) - | (pIE->IntType<<5) - | (pIE->PrefExcl<<3) - | pIE->InfoChanSel; - - /* Octet 3.1 - Interface Identifier */ - if(pIE->IntIDPresent) - { - OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID; - } - else - { - /* Octet 3.2 & 3.3 - PRI */ - if(pIE->IntType == 1) - { - OBuf[(*Octet)++] = 0x80 - | (pIE->CodStand << 5) - | (pIE->NumMap << 4) - | pIE->ChanMapType; - - /* Octet 3.2 Channel number/slot map */ - OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; - } - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) -{ - L3INT Octet = *IOff; - L3INT l = IBuf[Octet]; - L3USHORT CRV; - Octet++; /*Octet 2 is length indicator */ - - if(l == 1) /* One octet CRV */ - { - CRV = IBuf[Octet]; - Octet++; - } - else if(l==2) /* two octet CRV */ - { - CRV = IBuf[Octet] << 8; - CRV = CRV + IBuf[Octet+1]; - Octet += 2; - } - 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 *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize=0; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - IESize = 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 - ********************************************************************/ - pie->Format=0; - - /* Octet 6 - Hour (optional)*/ - if(IESize >= 6) - { - pie->Format = 1; - pie->Hour = IBuf[Octet++]; - - /* Octet 7 - Minute (optional)*/ - if(IESize >= 7) - { - pie->Format = 2; - pie->Minute = IBuf[Octet++]; - - /* Octet 8 - Second (optional)*/ - if(IESize >= 8) - { - pie->Format = 3; - pie->Second = IBuf[Octet++]; - } - } - } - - Q931IESizeTest(Q931E_DATETIME); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_DateTime); - pie->Size = sizeof(Q931ie_DateTime); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Display * pie = (Q931ie_Display*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - IESize = IBuf[Octet ++]; - - for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } - - Q931IESizeTest(Q931E_DISPLAY); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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) + 1; - - for(x=0; x< DSize; x++) - { - - OBuf[(*Octet)++] = pIE->Display[x]; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_HLComp); - pie->Size = sizeof(Q931ie_HLComp); - - Q931SetIE(*pIE, *OOff); - - 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 *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) | (pIE->Interpret << 2) | pIE->PresMeth; - - /* Octet 4 */ - OBuf[(*Octet)++] = pIE->HLCharID; - - /* Octet 4a */ - if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) - { - OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; - } - else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) - { - OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; - } - else - { - OBuf[(*Octet)-1] |= 0x80; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - IESize = IBuf[Octet ++]; - - for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } - - Q931IESizeTest(Q931E_KEYPADFAC); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; - pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; - pie->Parity =IBuf[Octet+Off] & 0x07; - Off++; - - /* Octet 5d */ - if((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - - 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((IBuf[Octet+Off-1] & 0x80) != 0) - { - pie->DefPackSize = IBuf[Octet+Off] & 0x0f; - Off++; - - /* Octet 7c */ - if((IBuf[Octet+Off-1] & 0x80) != 0) - { - pie->PackWinSize= IBuf[Octet+Off] & 0x7f; - } - } - } - } - } - else - { - Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); - return Q931E_LLCOMP; - } - - Q931IESizeTest(Q931E_LLCOMP); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_LLComp); - pie->Size = sizeof(Q931ie_LLComp); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2*/ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->Notification = IBuf[Octet+Off] & 0x7f; - - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; - - Q931IESizeTest(Q931E_NOTIFIND); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NotifInd); - pie->Size = sizeof(Q931ie_NotifInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_ProgInd); - pie->Size = sizeof(Q931ie_ProgInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - - *pIE=0; - - pie->IEId = IBuf[Octet] & 0xf0; - pie->RepeatInd = IBuf[Octet] & 0x0f; - Octet ++; - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); - pie->Size = sizeof(Q931ie_RepeatInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - ie iE; - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2*/ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->Class = IBuf[Octet+Off] & 0x07; - - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; - - Q931IESizeTest(Q931E_RESTARTIND); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RestartInd); - pie->Size = sizeof(Q931ie_RestartInd); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; - 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); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Segment); - pie->Size = sizeof(Q931ie_Segment); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - - *pIE=0; - - Octet ++; - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_SendComplete); - pie->Size = sizeof(Q931ie_SendComplete); - - Q931SetIE(*pIE, *OOff); - - 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2*/ - IESize = IBuf[Octet ++]; - - /* Octet 3 */ - pie->Signal = IBuf[Octet+Off]; - Octet++; - - Q931IESizeTest(Q931E_SIGNAL); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Signal); - pie->Size = sizeof(Q931ie_Signal); - - Q931SetIE(*pIE, *OOff); - - 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 *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); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; - - /* 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++; - } - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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;xNetID[x]; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; - - *pIE=0; - - pie->IEId = IBuf[Octet]; - Octet ++; - - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; - - /* Octet 3*/ - pie->ProtDisc = IBuf[Octet+Off]; - Octet++; - - for(x=0; x < l; x++) - { - pie->User[x] = IBuf[Octet+Off]; - Off++; - } - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); - - Q931SetIE(*pIE, *OOff); - - 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 *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;xUser[x]; - } - - OBuf[li] = (L3UCHAR)((*Octet)-Beg); - return rc; -} - +/***************************************************************************** + + 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" + +/***************************************************************************** + + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; + L3INT rc=0; + L3INT Beg=*Octet;/* remember current offset */ + L3INT li; + + OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; + li=(*Octet)++; /* remember length position */ + + /* Octet 3 - Coding standard / Information transfer capability */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); + + /* Octet 4 - Transfer mode / Information transfer rate */ + if(pIE->ITR == 0x18) + { + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + } + else + { + OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + + /* Octet 4.1 - Rate Multiplier */ + OBuf[(*Octet)++] = 0x80 | pIE->RateMul; + } + + /* 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) | (pIE->UIL1Prot & 0x15); + + /* Octet 5a - SyncAsync/Negot/UserRate */ + OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (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) + | (pIE->NIConTx << 4) + | (pIE->NIConRx << 3) + | (pIE->FlowCtlTx << 2) + | (pIE->FlowCtlRx << 1); + } + else if(pIE->UIL1Prot == 0x08) /* ITU V.120 */ + { + /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/ + OBuf[(*Octet)++] = 0x00 + | (pIE->InterRate << 6) + | (pIE->MultiFrame << 5) + | (pIE->Mode << 4) + | (pIE->LLInegot << 3) + | (pIE->Assignor << 2) + | (pIE->InBandNeg << 1); + } + + /* Octet 5c - NumStopBits/NumStartBits/Parity */ + OBuf[(*Octet)++] = 0x00 + | (pIE->NumStopBits << 5 ) + | (pIE->NumDataBits << 3 ) + | (pIE->Parity); + + /* Octet 5d - Duplex Mode/Modem Type */ + OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); + } + } + + /* Octet 6 - Layer2Ident/User information layer 2 prtocol */ + if(pIE->Layer2Ident == 0x02) + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot); + } + + /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ + if(pIE->Layer3Ident == 0x03) + { + if(pIE->UIL3Prot == 0x0c) + { + OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + + /* Octet 7a - Additional information layer 3 msb */ + OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); + + /* Octet 7b - Additional information layer 3 lsb */ + OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); + } + else + { + OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + } + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + do{ + pie->CallId[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); + + Q931IESizeTest(Q931E_CALLID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallState); + pie->Size = sizeof(Q931ie_CallState); + + Q931SetIE(*pIE, *OOff); + + 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 *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)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLEDSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; /* # digits in this case */ + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; + pie->NumPlanID = IBuf[Octet+Off] & 0x0f; + Octet ++; + + /* Octet 4*/ + for (x = 0; x < IESize && x < 20; x++) + { + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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_NUMBER; + 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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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 4a*/ + x=0; + do{ + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGNUM); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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_CalledSub) + 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 3a */ + /* + + Details about the use and how to detect if Octet 3a is used + are very weak. Temp left out. + + Octet 3 msb is set to 1 to indicate that this is not present + + */ + + /* Octet 4 */ + for(x=0;xDigit[x]; + } + + OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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((IBuf[Octet+Off]&0x80) != 0 && x < 20); + + Q931IESizeTest(Q931E_CALLINGSUB); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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; + + Q931IESizeTest(Q931E_CAUSE); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Cause); + pie->Size = sizeof(Q931ie_Cause); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->CongLevel = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CongLevel); + pie->Size = sizeof(Q931ie_CongLevel); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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], Off); + Octet++; + + /* 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++; + } + else + { + /* 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; + Off = Q931ReadExt(&IBuf[Octet+Off], Off); + Off++; + } + } + + Q931IESizeTest(Q931E_CHANID); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); + + Q931SetIE(*pIE, *OOff); + + 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 *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) + | (pIE->IntType<<5) + | (pIE->PrefExcl<<3) + | pIE->InfoChanSel; + + /* Octet 3.1 - Interface Identifier */ + if(pIE->IntIDPresent) + { + OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID; + } + else + { + /* Octet 3.2 & 3.3 - PRI */ + if(pIE->IntType == 1) + { + OBuf[(*Octet)++] = 0x80 + | (pIE->CodStand << 5) + | (pIE->NumMap << 4) + | pIE->ChanMapType; + + /* Octet 3.2 Channel number/slot map */ + OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; + } + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + L3INT Octet = *IOff; + L3INT l = IBuf[Octet]; + L3USHORT CRV; + Octet++; /*Octet 2 is length indicator */ + + if(l == 1) /* One octet CRV */ + { + CRV = IBuf[Octet]; + Octet++; + } + else if(l==2) /* two octet CRV */ + { + CRV = IBuf[Octet] << 8; + CRV = CRV + IBuf[Octet+1]; + Octet += 2; + } + 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 *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize=0; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + IESize = 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 + ********************************************************************/ + pie->Format=0; + + /* Octet 6 - Hour (optional)*/ + if(IESize >= 6) + { + pie->Format = 1; + pie->Hour = IBuf[Octet++]; + + /* Octet 7 - Minute (optional)*/ + if(IESize >= 7) + { + pie->Format = 2; + pie->Minute = IBuf[Octet++]; + + /* Octet 8 - Second (optional)*/ + if(IESize >= 8) + { + pie->Format = 3; + pie->Second = IBuf[Octet++]; + } + } + } + + Q931IESizeTest(Q931E_DATETIME); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_DateTime); + pie->Size = sizeof(Q931ie_DateTime); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Display * pie = (Q931ie_Display*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_DISPLAY); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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) + 1; + + for(x=0; x< DSize; x++) + { + + OBuf[(*Octet)++] = pIE->Display[x]; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_HLComp); + pie->Size = sizeof(Q931ie_HLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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) | (pIE->Interpret << 2) | pIE->PresMeth; + + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->HLCharID; + + /* Octet 4a */ + if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) + { + OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; + } + else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) + { + OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; + } + else + { + OBuf[(*Octet)-1] |= 0x80; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + IESize = IBuf[Octet ++]; + + for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; + Off++; + } + + Q931IESizeTest(Q931E_KEYPADFAC); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; + pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; + pie->Parity =IBuf[Octet+Off] & 0x07; + Off++; + + /* Octet 5d */ + if((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + + 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((IBuf[Octet+Off-1] & 0x80) != 0) + { + pie->DefPackSize = IBuf[Octet+Off] & 0x0f; + Off++; + + /* Octet 7c */ + if((IBuf[Octet+Off-1] & 0x80) != 0) + { + pie->PackWinSize= IBuf[Octet+Off] & 0x7f; + } + } + } + } + } + else + { + Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); + return Q931E_LLCOMP; + } + + Q931IESizeTest(Q931E_LLCOMP); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_LLComp); + pie->Size = sizeof(Q931ie_LLComp); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Notification = IBuf[Octet+Off] & 0x7f; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_NOTIFIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NotifInd); + pie->Size = sizeof(Q931ie_NotifInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ProgInd); + pie->Size = sizeof(Q931ie_ProgInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + pie->IEId = IBuf[Octet] & 0xf0; + pie->RepeatInd = IBuf[Octet] & 0x0f; + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); + pie->Size = sizeof(Q931ie_RepeatInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + ie iE; + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Class = IBuf[Octet+Off] & 0x07; + + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; + + Q931IESizeTest(Q931E_RESTARTIND); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RestartInd); + pie->Size = sizeof(Q931ie_RestartInd); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; + 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); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Segment); + pie->Size = sizeof(Q931ie_Segment); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + + *pIE=0; + + Octet ++; + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_SendComplete); + pie->Size = sizeof(Q931ie_SendComplete); + + Q931SetIE(*pIE, *OOff); + + 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 *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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2*/ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Signal = IBuf[Octet+Off]; + Octet++; + + Q931IESizeTest(Q931E_SIGNAL); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Signal); + pie->Size = sizeof(Q931ie_Signal); + + Q931SetIE(*pIE, *OOff); + + 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 *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); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* 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++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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;xNetID[x]; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + 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 *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT l; + + *pIE=0; + + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + l = IBuf[Octet] - 3; + Octet++; + + /* Octet 3*/ + pie->ProtDisc = IBuf[Octet+Off]; + Octet++; + + for(x=0; x < l; x++) + { + pie->User[x] = IBuf[Octet+Off]; + Off++; + } + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); + + Q931SetIE(*pIE, *OOff); + + 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 *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;xUser[x]; + } + + OBuf[li] = (L3UCHAR)((*Octet)-Beg); + return rc; +} + diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 8451ff48d5..d376f8d176 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1,1931 +1,1931 @@ -/***************************************************************************** - - 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" - -/***************************************************************************** - - Function: Q931Umes_Alerting - -*****************************************************************************/ - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; - L3INT rc=Q931E_NO_ERROR; - L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; - while(IOff < Size) - { - switch(mescode) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Alerting - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_CallProceeding - -*****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_CallProceeding - -*****************************************************************************/ -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_CongestionControl - -*****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - - -/***************************************************************************** - - Function: Q931Pmes_CongestionControl - -*****************************************************************************/ -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_Connect - -*****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Connect - -*****************************************************************************/ -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Date/Time */ - if(Q931IsIEPresent(pMes->DateTime)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Low Layer Compatibility */ - if(Q931IsIEPresent(pMes->LLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ConnectAck - -*****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_ConnectAck - -*****************************************************************************/ -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Disconnect - -*****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Disconnect - -*****************************************************************************/ -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Information - -*****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Information *mes = (Q931mes_Information*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Information) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Information - -*****************************************************************************/ -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Information *pMes = (Q931mes_Information *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Sending Complete */ - if(Q931IsIEPresent(pMes->SendComplete)) - OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Keypad Facility */ - if(Q931IsIEPresent(pMes->KeypadFac)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Called Party number */ - if(Q931IsIEPresent(pMes->CalledNum)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Notify - -*****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - } - } - mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Notify - -*****************************************************************************/ -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Progress - -*****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Progress - -*****************************************************************************/ -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Bearer capability */ - if(Q931IsIEPresent(pMes->BearerCap)) - { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) - return rc; - } - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Release - -*****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Release *mes = (Q931mes_Release*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Release) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Release - -*****************************************************************************/ -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Release *pMes = (Q931mes_Release *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ReleaseComplete - -*****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_ReleaseComplete - -*****************************************************************************/ -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Restart - -*****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_Restart - -*****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_RestartAck - -*****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_Resume - -*****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Resume - -*****************************************************************************/ -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Call Identity */ - if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ResumeAck - -*****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_ResumeAck - -*****************************************************************************/ -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_ResumeReject - -*****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_ResumeReject - -*****************************************************************************/ -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) -{ - L3INT i = IOff; - - return IOff - i; -} - -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_Setup - -*****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - L3INT ir=0; - L3INT OOff=0; - Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_REPEAT_INDICATOR: - if(ir==0) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - ir++; - } - else if(ir==1) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - ir++; - } - else - { - return Q931E_ILLEGAL_IE; - } - break; - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Setup - - Decription: Pack a Q931mes_Setup 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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* 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][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Network spesific facilities */ - if(Q931IsIEPresent(pMes->NetFac)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Date/Time */ - if(Q931IsIEPresent(pMes->DateTime)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Keypad Facility */ - if(Q931IsIEPresent(pMes->KeypadFac)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Calling Party Number */ - if(Q931IsIEPresent(pMes->CallingNum)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Calling Party Subaddress */ - if(Q931IsIEPresent(pMes->CallingSub)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Called Party number */ - if(Q931IsIEPresent(pMes->CalledNum)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Called party subaddress */ - if(Q931IsIEPresent(pMes->CalledSub)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Transit network selection */ - if(Q931IsIEPresent(pMes->TransNetSel)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* High Layer Compatibility */ - if(Q931IsIEPresent(pMes->HLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_SetupAck - -*****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_SetupAck - -*****************************************************************************/ -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Channel Identification */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Progress indicator */ - if(Q931IsIEPresent(pMes->ProgInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Signal */ - if(Q931IsIEPresent(pMes->Signal)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Status - -*****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Status *mes = (Q931mes_Status*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Status) - 1 + OOff; - return Q931E_NO_ERROR; -} - - -/***************************************************************************** - - Function: Q931Pmes_Status - -*****************************************************************************/ -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Status *pMes = (Q931mes_Status *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Call State */ - if(Q931IsIEPresent(pMes->CallState)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_StatusEnquiry - -*****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_StatusEnquiry - -*****************************************************************************/ -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_Suspend - -*****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Suspend - -*****************************************************************************/ -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Call Identity */ - if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_SuspendAck - -*****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - - { - switch(IBuf[IOff]) - { - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_SuspendAck - -*****************************************************************************/ -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_SuspendReject - -*****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_SuspendReject - -*****************************************************************************/ -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Cause */ - if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) - return rc; - - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_UserInformation - -*****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_UserInformation - -*****************************************************************************/ -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - +/***************************************************************************** + + 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" + +/***************************************************************************** + + Function: Q931Umes_Alerting + +*****************************************************************************/ + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; + L3INT rc=Q931E_NO_ERROR; + L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; + while(IOff < Size) + { + switch(mescode) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Alerting + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CallProceeding + +*****************************************************************************/ +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_CallProceeding + +*****************************************************************************/ +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_CongestionControl + +*****************************************************************************/ +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + + +/***************************************************************************** + + Function: Q931Pmes_CongestionControl + +*****************************************************************************/ +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Connect + +*****************************************************************************/ +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Connect + +*****************************************************************************/ +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Low Layer Compatibility */ + if(Q931IsIEPresent(pMes->LLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ConnectAck + +*****************************************************************************/ +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ConnectAck + +*****************************************************************************/ +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Disconnect + +*****************************************************************************/ +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Disconnect + +*****************************************************************************/ +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Information + +*****************************************************************************/ +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Information *mes = (Q931mes_Information*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Information) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Information + +*****************************************************************************/ +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Information *pMes = (Q931mes_Information *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Sending Complete */ + if(Q931IsIEPresent(pMes->SendComplete)) + OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Notify + +*****************************************************************************/ +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_NOTIFICATION_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + } + } + mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Notify + +*****************************************************************************/ +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Progress + +*****************************************************************************/ +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Progress + +*****************************************************************************/ +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Bearer capability */ + if(Q931IsIEPresent(pMes->BearerCap)) + { + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + return rc; + } + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Release + +*****************************************************************************/ +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Release *mes = (Q931mes_Release*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Release) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Release + +*****************************************************************************/ +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Release *pMes = (Q931mes_Release *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_ReleaseComplete + +*****************************************************************************/ +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Resume + +*****************************************************************************/ +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Resume + +*****************************************************************************/ +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeAck + +*****************************************************************************/ +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeAck + +*****************************************************************************/ +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_ResumeReject + +*****************************************************************************/ +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_ResumeReject + +*****************************************************************************/ +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +{ + L3INT i = IOff; + + return IOff - i; +} + +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Umes_Setup + +*****************************************************************************/ +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + L3INT ir=0; + L3INT OOff=0; + Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_REPEAT_INDICATOR: + if(ir==0) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else if(ir==1) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + ir++; + } + else + { + return Q931E_ILLEGAL_IE; + } + break; + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_NETWORK_SPECIFIC_FACILITIES: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_TRANSIT_NETWORK_SELECTION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Setup + + Decription: Pack a Q931mes_Setup 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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Network spesific facilities */ + if(Q931IsIEPresent(pMes->NetFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Date/Time */ + if(Q931IsIEPresent(pMes->DateTime)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Keypad Facility */ + if(Q931IsIEPresent(pMes->KeypadFac)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Number */ + if(Q931IsIEPresent(pMes->CallingNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Calling Party Subaddress */ + if(Q931IsIEPresent(pMes->CallingSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called Party number */ + if(Q931IsIEPresent(pMes->CalledNum)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Called party subaddress */ + if(Q931IsIEPresent(pMes->CalledSub)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Transit network selection */ + if(Q931IsIEPresent(pMes->TransNetSel)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* High Layer Compatibility */ + if(Q931IsIEPresent(pMes->HLComp)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SetupAck + +*****************************************************************************/ +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SetupAck + +*****************************************************************************/ +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Channel Identification */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Progress indicator */ + if(Q931IsIEPresent(pMes->ProgInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Signal */ + if(Q931IsIEPresent(pMes->Signal)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Status + +*****************************************************************************/ +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Status *mes = (Q931mes_Status*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALL_STATE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Status) - 1 + OOff; + return Q931E_NO_ERROR; +} + + +/***************************************************************************** + + Function: Q931Pmes_Status + +*****************************************************************************/ +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Status *pMes = (Q931mes_Status *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Call State */ + if(Q931IsIEPresent(pMes->CallState)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_StatusEnquiry + +*****************************************************************************/ +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_Suspend + +*****************************************************************************/ +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CALL_IDENTITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Suspend + +*****************************************************************************/ +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Call Identity */ + if(Q931IsIEPresent(pMes->CallID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendAck + +*****************************************************************************/ +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + + { + switch(IBuf[IOff]) + { + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendAck + +*****************************************************************************/ +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_SuspendReject + +*****************************************************************************/ +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CAUSE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_SuspendReject + +*****************************************************************************/ +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* Cause */ + if(Q931IsIEPresent(pMes->Cause)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + return rc; + + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_UserInformation + +*****************************************************************************/ +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q931Pmes_UserInformation + +*****************************************************************************/ +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index 97e4fe1a42..c04d4f7ee4 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -1,310 +1,310 @@ -/***************************************************************************** - - 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 *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Facility - -*****************************************************************************/ -L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_Hold - -*****************************************************************************/ - -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Hold - -*****************************************************************************/ -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_HoldAck - -*****************************************************************************/ - -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_HoldAck - -*****************************************************************************/ -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_HoldReject - -*****************************************************************************/ - -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_HoldReject - -*****************************************************************************/ -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_Register - -*****************************************************************************/ - -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Register *mes = (Q932mes_Register*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Register) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Register - -*****************************************************************************/ -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_Retrieve - -*****************************************************************************/ - -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Retrieve - -*****************************************************************************/ -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_RetrieveAck - -*****************************************************************************/ - -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_RetrieveAck - -*****************************************************************************/ -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q932Umes_RetrieveReject - -*****************************************************************************/ - -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - /* L3INT i = IOff; */ - /* L3INT ir=0; */ - L3INT OOff=0; - Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; - - /* TODO */ - - mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_RetrieveReject - -*****************************************************************************/ -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} +/***************************************************************************** + + 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 *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Facility + +*****************************************************************************/ +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Hold + +*****************************************************************************/ + +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Hold + +*****************************************************************************/ +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldAck + +*****************************************************************************/ + +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldAck + +*****************************************************************************/ +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_HoldReject + +*****************************************************************************/ + +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_HoldReject + +*****************************************************************************/ +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Register + +*****************************************************************************/ + +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Register *mes = (Q932mes_Register*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Register) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Register + +*****************************************************************************/ +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_Retrieve + +*****************************************************************************/ + +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Retrieve + +*****************************************************************************/ +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveAck + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveAck + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} + +/***************************************************************************** + + Function: Q932Umes_RetrieveReject + +*****************************************************************************/ + +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + /* L3INT ir=0; */ + L3INT OOff=0; + Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; + + /* TODO */ + + mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RetrieveReject + +*****************************************************************************/ +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3BOOL RetCode = L3FALSE; + + NoWarning(OBuf); + NoWarning(IBuf); + + return RetCode; +} diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 3a0e1b02ac..26d4699c73 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -1,117 +1,117 @@ -/***************************************************************************** - - FileName: q921.h - - Description: Contains headers of a Q.921 protocol on top of the Comet - Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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 3 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. - - Q921Tx23 Send a message to layer 3. - - OnQ921Error Function called every if an error is - deteceted. - - OnQ921Log Function called if logging is active. - - - Maintenance/Configuration interface - - 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. - -*****************************************************************************/ - -#ifndef _Q921 -#define _Q921 - -#define Q921MAXTRUNK 4 -#define Q921MAXHDLCSPACE 3000 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit - or larger. - -*****************************************************************************/ - -#define L2UCHAR unsigned char /* Min 8 bit */ -#define L2INT int /* Min 16 bit signed */ - -typedef struct -{ - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; - L2UCHAR vs; - L2UCHAR vr; - int state; -}Q921Data; - -void Q921Init(); -void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); -int Q921Rx12(long trunk); - -#endif - +/***************************************************************************** + + FileName: q921.h + + Description: Contains headers of a Q.921 protocol on top of the Comet + Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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 3 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. + + Q921Tx23 Send a message to layer 3. + + OnQ921Error Function called every if an error is + deteceted. + + OnQ921Log Function called if logging is active. + + + Maintenance/Configuration interface + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXTRUNK 4 +#define Q921MAXHDLCSPACE 3000 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + or larger. + +*****************************************************************************/ + +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ + +typedef struct +{ + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR vr; + int state; +}Q921Data; + +void Q921Init(); +void Q921SetHeaderSpace(int hspace); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); +int Q921Rx12(long trunk); + +#endif + diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 04697bedc5..247937e97d 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1,2412 +1,2412 @@ -/****************************************************************************** - - 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) -#endif - -/***************************************************************************** - - Error Codes - -*****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have 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 - -/***************************************************************************** - - 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 Q931L4BUF 1000 /* size of message buffer */ - -#define Q931L2BUF 300 /* size of message buffer */ - -#define Q931MAXTRUNKS 1 /* 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. */ - -/***************************************************************************** - - 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 schoose 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 2 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ - - -#define Q931MAXMES 255 /* Number of messages */ - -#define Q931MAXIE 255 /* Number of IE */ - -#define Q931MAXSTATE 100 /* Size of state tables */ - -/***************************************************************************** - - 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 0x7a /* 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 */ - - -/* Single octet information elements */ -#define Q931ie_SHIFT 0x90 /* 1001 ---- */ -#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; - -/***************************************************************************** - - 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 */ - 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 */ - L3INT CRV; /* Call reference value */ - - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; - - ie Segment; /* Segmented message */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie CallID; /* Call Identity */ - ie ChanID; /* Channel Identification */ - 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 RestartInd; /* Restart Indicator */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High Layer Compatibility */ - ie UserUser; /* User-user */ - ie Escape; /* Escape for extension */ - L3UCHAR buf[1]; /* Buffer for IE's */ - -}Q931mes_Generic; - -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; - -/***************************************************************************** - - Struct: Q931_TrunkInfo - - Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated - channels in the system. - - The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. - -*****************************************************************************/ - -typedef struct -{ - enum _NetUser /* Network/User Mode. */ - { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ - }NetUser; - - L3UCHAR Dialect; /* Q.931 Based dielact index. */ - - enum _TrunkType /* 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 */ - }TrunkType; - - L3UCHAR Enabled; /* Enabled/Disabled */ - /* 0 = Disabled */ - /* 1 = Enabled */ - - enum _TrState /* Trunk State */ - { - Q931_TrState_NoAlignment=0, /* Trunk not aligned */ - Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2 /* Trunk Aligned */ - }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 send 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. */ - - /* 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 - { - enum _ChanType{ - 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 */ - }ChanType; - - 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 _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - -}Q931_TrunkInfo; - -/***************************************************************************** - - 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 define it's own state table and the logic only need - to 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. - -*****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -/***************************************************************************** - - 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) (&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. - -*****************************************************************************/ - -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; - -#include "Q932.h" - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - -/***************************************************************************** - - Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); - -/***************************************************************************** - - Q.931 Process Function Prototyping. Implemented in Q931StateTE.c - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -/***************************************************************************** - - Interface Function Prototypes. Implemented in Q931.c - -*****************************************************************************/ -void Q931TimeTick(L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); -void Q931CreateTE(L3UCHAR i); -void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); -void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); -void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); - -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); - -void Q931Initialize(); -void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); - -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); -L3ULONG Q931GetTime(); -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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); - -#endif /* _Q931_NL */ +/****************************************************************************** + + 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) +#endif + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 Q931L4BUF 1000 /* size of message buffer */ + +#define Q931L2BUF 300 /* size of message buffer */ + +#define Q931MAXTRUNKS 1 /* 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + 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 */ + L3INT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ + +typedef struct +{ + enum _NetUser /* Network/User Mode. */ + { + Q931_TE=0, /* 0 : User Mode */ + Q931_NT=1 /* 1 : Network Mode */ + }NetUser; + + L3UCHAR Dialect; /* Q.931 Based dielact index. */ + + enum _TrunkType /* 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 */ + }TrunkType; + + L3UCHAR Enabled; /* Enabled/Disabled */ + /* 0 = Disabled */ + /* 1 = Enabled */ + + enum _TrState /* Trunk State */ + { + Q931_TrState_NoAlignment=0, /* Trunk not aligned */ + Q931_TrState_Aligning=1, /* Aligning in progress */ + Q931_TrState_Aligned=2 /* Trunk Aligned */ + }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 send 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. */ + + /* 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 + { + enum _ChanType{ + 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 */ + }ChanType; + + 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }call[Q931MAXCALLPERTRUNK]; + +}Q931_TrunkInfo; + +/***************************************************************************** + + 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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); +void Q931CreateTE(L3UCHAR i); +void Q931CreateNT(L3UCHAR i); +void Q931SetMesCreateCB(L3INT (*callback)()); +void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +#endif /* _Q931_NL */ diff --git a/libs/freetdm/src/isdn/include/Q932.h b/libs/freetdm/src/isdn/include/Q932.h index fa17e38ae7..19b5c4c149 100644 --- a/libs/freetdm/src/isdn/include/Q932.h +++ b/libs/freetdm/src/isdn/include/Q932.h @@ -1,191 +1,191 @@ -/***************************************************************************** - - 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 */ - -/***************************************************************************** - Struct: Q932ie_Facility -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Facility; - -/***************************************************************************** - Struct: Q932ie_Hold -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Hold; - -/***************************************************************************** - Struct: Q932ie_HoldAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldAck; - -/***************************************************************************** - Struct: Q932ie_HoldReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldReject; - -/***************************************************************************** - Struct: Q932ie_Register -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Register; - -/***************************************************************************** - Struct: Q932ie_Retrieve -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Retrieve; - -/***************************************************************************** - Struct: Q932ie_RetrieveAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveAck; - -/***************************************************************************** - Struct: Q932ie_RetrieveReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveReject; - -/***************************************************************************** - Function Prototypes. -*****************************************************************************/ -L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); - -L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); - -L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +/***************************************************************************** + + 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 */ + +/***************************************************************************** + Struct: Q932ie_Facility +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Facility; + +/***************************************************************************** + Struct: Q932ie_Hold +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Hold; + +/***************************************************************************** + Struct: Q932ie_HoldAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldAck; + +/***************************************************************************** + Struct: Q932ie_HoldReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_HoldReject; + +/***************************************************************************** + Struct: Q932ie_Register +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Register; + +/***************************************************************************** + Struct: Q932ie_Retrieve +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_Retrieve; + +/***************************************************************************** + Struct: Q932ie_RetrieveAck +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveAck; + +/***************************************************************************** + Struct: Q932ie_RetrieveReject +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3USHORT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q932mes_RetrieveReject; + +/***************************************************************************** + Function Prototypes. +*****************************************************************************/ +L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); + +L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); diff --git a/libs/freetdm/src/isdn/include/mfifo.h b/libs/freetdm/src/isdn/include/mfifo.h index 788adfdb10..99faa1d1ba 100644 --- a/libs/freetdm/src/isdn/include/mfifo.h +++ b/libs/freetdm/src/isdn/include/mfifo.h @@ -1,83 +1,83 @@ -/***************************************************************************** - - 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 _mfifo -{ - 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); - -#endif +/***************************************************************************** + + 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 _mfifo +{ + 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); + +#endif diff --git a/libs/freetdm/src/isdn/mfifo.c b/libs/freetdm/src/isdn/mfifo.c index 9e409f8a92..a1e85dedf4 100644 --- a/libs/freetdm/src/isdn/mfifo.c +++ b/libs/freetdm/src/isdn/mfifo.c @@ -1,296 +1,296 @@ -/***************************************************************************** - - 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; - mf = (MFIFO*)buf; - - mf->first = mf->last = 0; - mf->ixsize = index; - mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; - - if(mf->buf > & buf[size]) - return 0; - - mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); - - return 1; -} - -/***************************************************************************** - - Function: MFIFOClear - - Description: Clear the FIFO - - Paremeters: buf ptr to fifo - - Return Value: none - -*****************************************************************************/ -void MFIFOClear(unsigned char * buf) -{ - MFIFO * mf; - 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; - 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) -{ - int x; - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->last == mf->first) - return 0; - x=mf->first; - x--; - if(x<0) - x=mf->ixsize; - 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) -{ - int x; - MFIFO * mf; - mf = (MFIFO*)buf; - 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) -{ - int of,ol,x; - MFIFO * mf; - mf = (MFIFO*)buf; - - 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; - 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) -{ - int x; - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->first!=mf->last) - { - x = mf->last+1; - if(x > mf->ixsize) - x=0; - mf->last=x; - } -} +/***************************************************************************** + + 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; + mf = (MFIFO*)buf; + + mf->first = mf->last = 0; + mf->ixsize = index; + mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; + + if(mf->buf > & buf[size]) + return 0; + + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); + + return 1; +} + +/***************************************************************************** + + Function: MFIFOClear + + Description: Clear the FIFO + + Paremeters: buf ptr to fifo + + Return Value: none + +*****************************************************************************/ +void MFIFOClear(unsigned char * buf) +{ + MFIFO * mf; + 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; + 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) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->last == mf->first) + return 0; + x=mf->first; + x--; + if(x<0) + x=mf->ixsize; + 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) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + 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) +{ + int of,ol,x; + MFIFO * mf; + mf = (MFIFO*)buf; + + 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; + 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) +{ + int x; + MFIFO * mf; + mf = (MFIFO*)buf; + if(mf->first!=mf->last) + { + x = mf->last+1; + if(x > mf->ixsize) + x=0; + mf->last=x; + } +} From 45268b86af31583d7fba96e97623c250c227e487 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:25:35 +0000 Subject: [PATCH 0171/1766] add functions to initialize a trunk, and a public function to receive from layer 3 that sends an I frame. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@86 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 882 ++++++++++++++------------- libs/openzap/src/isdn/include/Q921.h | 245 ++++---- 2 files changed, 586 insertions(+), 541 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 27802d877d..3f768e4116 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -1,424 +1,458 @@ -/***************************************************************************** - - FileName: q921.c - - Description: Contains the implementation of a Q.921 protocol on top of the - Comet Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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. - -*****************************************************************************/ -#include "Q921.h" -#include -#include "mfifo.h" - -/***************************************************************************** - Global Tables & Variables. -*****************************************************************************/ -Q921Data Q921DevSpace[Q921MAXTRUNK]; -int Q921HeaderSpace={0}; - -int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; - -/***************************************************************************** - - Function: Q921Init - - Decription: Initialize the Q.921 stack so it is ready for use. This - function MUST be called as part of initializing the - application. - -*****************************************************************************/ -void Q921Init() -{ - int x; - for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - } - } - - /* check for RR */ - else if(mes[2] ==0x01) - { - /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); - - return 1; - } - return 0; -} - +/***************************************************************************** + + FileName: q921.c + + Description: Contains the implementation of a Q.921 protocol on top of the + Comet Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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. + +*****************************************************************************/ +#include "Q921.h" +#include +#include "mfifo.h" + +/***************************************************************************** + Global Tables & Variables. +*****************************************************************************/ +Q921Data Q921DevSpace[Q921MAXTRUNK]; +int Q921HeaderSpace={0}; + +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; + +/***************************************************************************** + + Function: Q921Init + + Decription: Initialize the Q.921 stack so it is ready for use. This + function MUST be called as part of initializing the + application. + +*****************************************************************************/ +void Q921Init() +{ + int x; + for(x=0; x Q921MAXTRUNK) + return 0; + + Q921DevSpace[trunk].sapi = sapi; + Q921DevSpace[trunk].tei = tei; + Q921DevSpace[trunk].NetUser = NetUser; + return 1; +} + +void Q921SetHeaderSpace(int hspace) +{ + Q921HeaderSpace=hspace; +} + +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) +{ + Q921Tx21Proc = callback; +} + +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) +{ + Q921Tx23Proc = 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(int trunk, L2UCHAR *b, int size) +{ + return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); +} + +/***************************************************************************** + + Function: Q921SendI + + Description: Compose and Send I Frame to layer. Will receive an I frame + with space for L2 header and fill out that header before + it call Q921Tx21Proc. + + Parameters: trunk trunk # + Sapi Sapi + cr C/R field. + Tei Tei. + pf P fiels octet 5 + mes ptr to I frame message. + size size of message in bytes. + + Return Value: 0 if failed, 1 if Send. + +*****************************************************************************/ +int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) +{ + mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); + mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; + mes[Q921HeaderSpace+2] = Q921DevSpace[trunk].vs<<1; + mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + Q921DevSpace[trunk].vs++; + + return Q921Tx21Proc(trunk, mes, size); +} + +int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) +{ + return Q921SendI(trunk, + Q921DevSpace[x].sapi, + Q921DevSpace[x].NetUser == Q921_TE ? 0 : 1; + Q921DevSpace[x].tei, + 0, + Mes, + Size); +} +/***************************************************************************** + + 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. + +*****************************************************************************/ + +int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); +} + +/***************************************************************************** + + Function: Q921SendDM + + Description: Comose 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. + +*****************************************************************************/ +int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); +} + +int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) +{ + /* TODO: Do we need these paramaters? */ + (void)mes; + (void)size; + + Q921DevSpace[trunk].vr=0; + Q921DevSpace[trunk].vs=0; + + return 1; +} + +/***************************************************************************** + + 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(long trunk) +{ + L2UCHAR *mes; + int rs,size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + if(smes != NULL) + { + rs = size - Q921HeaderSpace; + mes = &smes[Q921HeaderSpace]; + /* check for I frame */ + if((mes[2] & 0x01) == 0) + { + if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ + { + Q921DevSpace[trunk].vr++; + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 26d4699c73..cec349820a 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -1,117 +1,128 @@ -/***************************************************************************** - - FileName: q921.h - - Description: Contains headers of a Q.921 protocol on top of the Comet - Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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 3 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. - - Q921Tx23 Send a message to layer 3. - - OnQ921Error Function called every if an error is - deteceted. - - OnQ921Log Function called if logging is active. - - - Maintenance/Configuration interface - - 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. - -*****************************************************************************/ - -#ifndef _Q921 -#define _Q921 - -#define Q921MAXTRUNK 4 -#define Q921MAXHDLCSPACE 3000 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit - or larger. - -*****************************************************************************/ - -#define L2UCHAR unsigned char /* Min 8 bit */ -#define L2INT int /* Min 16 bit signed */ - -typedef struct -{ - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; - L2UCHAR vs; - L2UCHAR vr; - int state; -}Q921Data; - -void Q921Init(); -void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); -int Q921Rx12(long trunk); - -#endif - +/***************************************************************************** + + FileName: q921.h + + Description: Contains headers of a Q.921 protocol on top of the Comet + Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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 3 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. + + Q921Tx23 Send a message to layer 3. + + OnQ921Error Function called every if an error is + deteceted. + + OnQ921Log Function called if logging is active. + + + Maintenance/Configuration interface + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXTRUNK 4 +#define Q921MAXHDLCSPACE 3000 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + or larger. + +*****************************************************************************/ + +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ + +typedef enum /* Network/User Mode. */ +{ + Q921_TE=0, /* 0 : User Mode */ + Q921_NT=1 /* 1 : Network Mode */ +} Q921NetUser_t; + +typedef struct +{ + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR vr; + L2INT state; + L2INT sapi; + L2INT tei; + Q921NetUser_t NetUser; + +}Q921Data; + +void Q921Init(); +int Q921_InitTrunk(long trunk, int sapi, int tei, Q921NetUser_t NetUser); +void Q921SetHeaderSpace(int hspace); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); +int Q921Rx12(long trunk); + +#endif + From ca278fa2f140164655540a0458257b69028e2d09 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:25:35 +0000 Subject: [PATCH 0172/1766] add functions to initialize a trunk, and a public function to receive from layer 3 that sends an I frame. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@86 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 882 ++++++++++++++------------- libs/freetdm/src/isdn/include/Q921.h | 245 ++++---- 2 files changed, 586 insertions(+), 541 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 27802d877d..3f768e4116 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -1,424 +1,458 @@ -/***************************************************************************** - - FileName: q921.c - - Description: Contains the implementation of a Q.921 protocol on top of the - Comet Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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. - -*****************************************************************************/ -#include "Q921.h" -#include -#include "mfifo.h" - -/***************************************************************************** - Global Tables & Variables. -*****************************************************************************/ -Q921Data Q921DevSpace[Q921MAXTRUNK]; -int Q921HeaderSpace={0}; - -int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; - -/***************************************************************************** - - Function: Q921Init - - Decription: Initialize the Q.921 stack so it is ready for use. This - function MUST be called as part of initializing the - application. - -*****************************************************************************/ -void Q921Init() -{ - int x; - for(x=0; x>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - } - } - - /* check for RR */ - else if(mes[2] ==0x01) - { - /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); - - return 1; - } - return 0; -} - +/***************************************************************************** + + FileName: q921.c + + Description: Contains the implementation of a Q.921 protocol on top of the + Comet Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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. + +*****************************************************************************/ +#include "Q921.h" +#include +#include "mfifo.h" + +/***************************************************************************** + Global Tables & Variables. +*****************************************************************************/ +Q921Data Q921DevSpace[Q921MAXTRUNK]; +int Q921HeaderSpace={0}; + +int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; + +/***************************************************************************** + + Function: Q921Init + + Decription: Initialize the Q.921 stack so it is ready for use. This + function MUST be called as part of initializing the + application. + +*****************************************************************************/ +void Q921Init() +{ + int x; + for(x=0; x Q921MAXTRUNK) + return 0; + + Q921DevSpace[trunk].sapi = sapi; + Q921DevSpace[trunk].tei = tei; + Q921DevSpace[trunk].NetUser = NetUser; + return 1; +} + +void Q921SetHeaderSpace(int hspace) +{ + Q921HeaderSpace=hspace; +} + +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) +{ + Q921Tx21Proc = callback; +} + +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) +{ + Q921Tx23Proc = 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(int trunk, L2UCHAR *b, int size) +{ + return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); +} + +/***************************************************************************** + + Function: Q921SendI + + Description: Compose and Send I Frame to layer. Will receive an I frame + with space for L2 header and fill out that header before + it call Q921Tx21Proc. + + Parameters: trunk trunk # + Sapi Sapi + cr C/R field. + Tei Tei. + pf P fiels octet 5 + mes ptr to I frame message. + size size of message in bytes. + + Return Value: 0 if failed, 1 if Send. + +*****************************************************************************/ +int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) +{ + mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); + mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; + mes[Q921HeaderSpace+2] = Q921DevSpace[trunk].vs<<1; + mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); + Q921DevSpace[trunk].vs++; + + return Q921Tx21Proc(trunk, mes, size); +} + +int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) +{ + return Q921SendI(trunk, + Q921DevSpace[x].sapi, + Q921DevSpace[x].NetUser == Q921_TE ? 0 : 1; + Q921DevSpace[x].tei, + 0, + Mes, + Size); +} +/***************************************************************************** + + 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. + +*****************************************************************************/ + +int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); +} + +/***************************************************************************** + + Function: Q921SendDM + + Description: Comose 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. + +*****************************************************************************/ +int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, 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. + +*****************************************************************************/ +int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); +} + +int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) +{ + /* TODO: Do we need these paramaters? */ + (void)mes; + (void)size; + + Q921DevSpace[trunk].vr=0; + Q921DevSpace[trunk].vs=0; + + return 1; +} + +/***************************************************************************** + + 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(long trunk) +{ + L2UCHAR *mes; + int rs,size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + if(smes != NULL) + { + rs = size - Q921HeaderSpace; + mes = &smes[Q921HeaderSpace]; + /* check for I frame */ + if((mes[2] & 0x01) == 0) + { + if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ + { + Q921DevSpace[trunk].vr++; + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 26d4699c73..cec349820a 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -1,117 +1,128 @@ -/***************************************************************************** - - FileName: q921.h - - Description: Contains headers of a Q.921 protocol on top of the Comet - Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. - - 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 3 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. - - Q921Tx23 Send a message to layer 3. - - OnQ921Error Function called every if an error is - deteceted. - - OnQ921Log Function called if logging is active. - - - Maintenance/Configuration interface - - 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. - -*****************************************************************************/ - -#ifndef _Q921 -#define _Q921 - -#define Q921MAXTRUNK 4 -#define Q921MAXHDLCSPACE 3000 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit - or larger. - -*****************************************************************************/ - -#define L2UCHAR unsigned char /* Min 8 bit */ -#define L2INT int /* Min 16 bit signed */ - -typedef struct -{ - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; - L2UCHAR vs; - L2UCHAR vr; - int state; -}Q921Data; - -void Q921Init(); -void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); -int Q921Rx12(long trunk); - -#endif - +/***************************************************************************** + + FileName: q921.h + + Description: Contains headers of a Q.921 protocol on top of the Comet + Driver. + + Most of the work required to execute a Q.921 protocol is + taken care of by the Comet ship and it's driver. This layer + will simply configure and make use of these features to + complete a Q.921 implementation. + + 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 3 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. + + Q921Tx23 Send a message to layer 3. + + OnQ921Error Function called every if an error is + deteceted. + + OnQ921Log Function called if logging is active. + + + Maintenance/Configuration interface + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXTRUNK 4 +#define Q921MAXHDLCSPACE 3000 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + or larger. + +*****************************************************************************/ + +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ + +typedef enum /* Network/User Mode. */ +{ + Q921_TE=0, /* 0 : User Mode */ + Q921_NT=1 /* 1 : Network Mode */ +} Q921NetUser_t; + +typedef struct +{ + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2UCHAR vs; + L2UCHAR vr; + L2INT state; + L2INT sapi; + L2INT tei; + Q921NetUser_t NetUser; + +}Q921Data; + +void Q921Init(); +int Q921_InitTrunk(long trunk, int sapi, int tei, Q921NetUser_t NetUser); +void Q921SetHeaderSpace(int hspace); +void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); +int Q921Rx12(long trunk); + +#endif + From ec4ee146d9dfdf4aec58ff285fe5bc8914d24945 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:26:00 +0000 Subject: [PATCH 0173/1766] default to 4 trunks max at compile time. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@87 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 4824 +++++++++++++------------- 1 file changed, 2412 insertions(+), 2412 deletions(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 247937e97d..f420b9d5ae 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1,2412 +1,2412 @@ -/****************************************************************************** - - 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) -#endif - -/***************************************************************************** - - Error Codes - -*****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have 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 - -/***************************************************************************** - - 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 Q931L4BUF 1000 /* size of message buffer */ - -#define Q931L2BUF 300 /* size of message buffer */ - -#define Q931MAXTRUNKS 1 /* 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. */ - -/***************************************************************************** - - 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 schoose 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 2 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ - - -#define Q931MAXMES 255 /* Number of messages */ - -#define Q931MAXIE 255 /* Number of IE */ - -#define Q931MAXSTATE 100 /* Size of state tables */ - -/***************************************************************************** - - 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 0x7a /* 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 */ - - -/* Single octet information elements */ -#define Q931ie_SHIFT 0x90 /* 1001 ---- */ -#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; - -/***************************************************************************** - - 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 */ - 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 */ - L3INT CRV; /* Call reference value */ - - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; - - ie Segment; /* Segmented message */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie CallID; /* Call Identity */ - ie ChanID; /* Channel Identification */ - 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 RestartInd; /* Restart Indicator */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High Layer Compatibility */ - ie UserUser; /* User-user */ - ie Escape; /* Escape for extension */ - L3UCHAR buf[1]; /* Buffer for IE's */ - -}Q931mes_Generic; - -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; - -/***************************************************************************** - - Struct: Q931_TrunkInfo - - Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated - channels in the system. - - The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. - -*****************************************************************************/ - -typedef struct -{ - enum _NetUser /* Network/User Mode. */ - { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ - }NetUser; - - L3UCHAR Dialect; /* Q.931 Based dielact index. */ - - enum _TrunkType /* 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 */ - }TrunkType; - - L3UCHAR Enabled; /* Enabled/Disabled */ - /* 0 = Disabled */ - /* 1 = Enabled */ - - enum _TrState /* Trunk State */ - { - Q931_TrState_NoAlignment=0, /* Trunk not aligned */ - Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2 /* Trunk Aligned */ - }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 send 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. */ - - /* 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 - { - enum _ChanType{ - 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 */ - }ChanType; - - 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 _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - -}Q931_TrunkInfo; - -/***************************************************************************** - - 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 define it's own state table and the logic only need - to 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. - -*****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -/***************************************************************************** - - 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) (&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. - -*****************************************************************************/ - -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; - -#include "Q932.h" - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - -/***************************************************************************** - - Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); - -/***************************************************************************** - - Q.931 Process Function Prototyping. Implemented in Q931StateTE.c - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -/***************************************************************************** - - Interface Function Prototypes. Implemented in Q931.c - -*****************************************************************************/ -void Q931TimeTick(L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); -void Q931CreateTE(L3UCHAR i); -void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); -void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); -void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); - -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); - -void Q931Initialize(); -void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); - -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); -L3ULONG Q931GetTime(); -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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); - -#endif /* _Q931_NL */ +/****************************************************************************** + + 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) +#endif + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + 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 */ + L3INT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ + +typedef struct +{ + enum _NetUser /* Network/User Mode. */ + { + Q931_TE=0, /* 0 : User Mode */ + Q931_NT=1 /* 1 : Network Mode */ + }NetUser; + + L3UCHAR Dialect; /* Q.931 Based dielact index. */ + + enum _TrunkType /* 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 */ + }TrunkType; + + L3UCHAR Enabled; /* Enabled/Disabled */ + /* 0 = Disabled */ + /* 1 = Enabled */ + + enum _TrState /* Trunk State */ + { + Q931_TrState_NoAlignment=0, /* Trunk not aligned */ + Q931_TrState_Aligning=1, /* Aligning in progress */ + Q931_TrState_Aligned=2 /* Trunk Aligned */ + }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 send 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. */ + + /* 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 + { + enum _ChanType{ + 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 */ + }ChanType; + + 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }call[Q931MAXCALLPERTRUNK]; + +}Q931_TrunkInfo; + +/***************************************************************************** + + 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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); +void Q931CreateTE(L3UCHAR i); +void Q931CreateNT(L3UCHAR i); +void Q931SetMesCreateCB(L3INT (*callback)()); +void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +#endif /* _Q931_NL */ From 1ae656094cd8cd4136c0729ebd4efb91f947a5d3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:26:00 +0000 Subject: [PATCH 0174/1766] default to 4 trunks max at compile time. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@87 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 4824 +++++++++++++------------- 1 file changed, 2412 insertions(+), 2412 deletions(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 247937e97d..f420b9d5ae 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1,2412 +1,2412 @@ -/****************************************************************************** - - 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) -#endif - -/***************************************************************************** - - Error Codes - -*****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have 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 - -/***************************************************************************** - - 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 Q931L4BUF 1000 /* size of message buffer */ - -#define Q931L2BUF 300 /* size of message buffer */ - -#define Q931MAXTRUNKS 1 /* 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. */ - -/***************************************************************************** - - 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 schoose 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 2 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ - - -#define Q931MAXMES 255 /* Number of messages */ - -#define Q931MAXIE 255 /* Number of IE */ - -#define Q931MAXSTATE 100 /* Size of state tables */ - -/***************************************************************************** - - 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 0x7a /* 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 */ - - -/* Single octet information elements */ -#define Q931ie_SHIFT 0x90 /* 1001 ---- */ -#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; - -/***************************************************************************** - - 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 */ - 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 */ - L3INT CRV; /* Call reference value */ - - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; - - ie Segment; /* Segmented message */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie CallID; /* Call Identity */ - ie ChanID; /* Channel Identification */ - 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 RestartInd; /* Restart Indicator */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High Layer Compatibility */ - ie UserUser; /* User-user */ - ie Escape; /* Escape for extension */ - L3UCHAR buf[1]; /* Buffer for IE's */ - -}Q931mes_Generic; - -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; - -/***************************************************************************** - - Struct: Q931_TrunkInfo - - Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated - channels in the system. - - The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. - -*****************************************************************************/ - -typedef struct -{ - enum _NetUser /* Network/User Mode. */ - { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ - }NetUser; - - L3UCHAR Dialect; /* Q.931 Based dielact index. */ - - enum _TrunkType /* 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 */ - }TrunkType; - - L3UCHAR Enabled; /* Enabled/Disabled */ - /* 0 = Disabled */ - /* 1 = Enabled */ - - enum _TrState /* Trunk State */ - { - Q931_TrState_NoAlignment=0, /* Trunk not aligned */ - Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2 /* Trunk Aligned */ - }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 send 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. */ - - /* 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 - { - enum _ChanType{ - 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 */ - }ChanType; - - 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 _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - -}Q931_TrunkInfo; - -/***************************************************************************** - - 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 define it's own state table and the logic only need - to 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. - -*****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -/***************************************************************************** - - 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) (&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. - -*****************************************************************************/ - -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; - -#include "Q932.h" - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - -/***************************************************************************** - - Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); - -/***************************************************************************** - - Q.931 Process Function Prototyping. Implemented in Q931StateTE.c - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -/***************************************************************************** - - Interface Function Prototypes. Implemented in Q931.c - -*****************************************************************************/ -void Q931TimeTick(L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); -void Q931CreateTE(L3UCHAR i); -void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); -void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); -void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); - -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); - -void Q931Initialize(); -void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); - -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); -L3ULONG Q931GetTime(); -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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); - -#endif /* _Q931_NL */ +/****************************************************************************** + + 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) +#endif + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + 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 */ + L3INT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ + +typedef struct +{ + enum _NetUser /* Network/User Mode. */ + { + Q931_TE=0, /* 0 : User Mode */ + Q931_NT=1 /* 1 : Network Mode */ + }NetUser; + + L3UCHAR Dialect; /* Q.931 Based dielact index. */ + + enum _TrunkType /* 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 */ + }TrunkType; + + L3UCHAR Enabled; /* Enabled/Disabled */ + /* 0 = Disabled */ + /* 1 = Enabled */ + + enum _TrState /* Trunk State */ + { + Q931_TrState_NoAlignment=0, /* Trunk not aligned */ + Q931_TrState_Aligning=1, /* Aligning in progress */ + Q931_TrState_Aligned=2 /* Trunk Aligned */ + }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 send 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. */ + + /* 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 + { + enum _ChanType{ + 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 */ + }ChanType; + + 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }call[Q931MAXCALLPERTRUNK]; + +}Q931_TrunkInfo; + +/***************************************************************************** + + 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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); +void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); +void Q931CreateTE(L3UCHAR i); +void Q931CreateNT(L3UCHAR i); +void Q931SetMesCreateCB(L3INT (*callback)()); +void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +#endif /* _Q931_NL */ From 36411f16acddd4bc48545a21e526ae2e3181b6c3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:26:15 +0000 Subject: [PATCH 0175/1766] add missing header files to the project file. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@88 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index e37c43672c..80eed02239 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -286,6 +286,10 @@ RelativePath=".\src\include\openzap.h" > + + @@ -302,6 +306,10 @@ RelativePath=".\src\include\zap_threadmutex.h" > + + From 252496d12c3a48e85b4fec64f6d45ec8b04df461 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:26:15 +0000 Subject: [PATCH 0176/1766] add missing header files to the project file. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@88 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index e37c43672c..80eed02239 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -286,6 +286,10 @@ RelativePath=".\src\include\openzap.h" > + + @@ -302,6 +306,10 @@ RelativePath=".\src\include\zap_threadmutex.h" > + + From b8635f17e7395fa58542eef7ae3542888aa092e9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:29:31 +0000 Subject: [PATCH 0177/1766] missing changes from previous commit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@89 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 8 ++++---- libs/openzap/src/isdn/include/Q921.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 3f768e4116..1a7e3d402b 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -90,7 +90,7 @@ void Q921Init() if your trunk is not TE (user) mode (i.e. NET). *****************************************************************************/ -int Q921_InitTrunk(long trunk, int sapi, int tei, Q921NetUser_t NetUser) +int Q921_InitTrunk(long trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser) { if (trunk > Q921MAXTRUNK) return 0; @@ -173,9 +173,9 @@ int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *m int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) { return Q921SendI(trunk, - Q921DevSpace[x].sapi, - Q921DevSpace[x].NetUser == Q921_TE ? 0 : 1; - Q921DevSpace[x].tei, + Q921DevSpace[trunk].sapi, + Q921DevSpace[trunk].NetUser == Q921_TE ? 0 : 1, + Q921DevSpace[trunk].tei, 0, Mes, Size); diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index cec349820a..aba3fab9a0 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -110,19 +110,19 @@ typedef struct L2UCHAR vs; L2UCHAR vr; L2INT state; - L2INT sapi; - L2INT tei; + L2UCHAR sapi; + L2UCHAR tei; Q921NetUser_t NetUser; }Q921Data; void Q921Init(); -int Q921_InitTrunk(long trunk, int sapi, int tei, Q921NetUser_t NetUser); +int Q921_InitTrunk(long trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); void Q921SetHeaderSpace(int hspace); void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); int Q921Rx12(long trunk); - +int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size); #endif From 3ad3dca0f39f00578a2f1ec9ecf0d07aa5f247f7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 01:29:31 +0000 Subject: [PATCH 0178/1766] missing changes from previous commit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@89 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 8 ++++---- libs/freetdm/src/isdn/include/Q921.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 3f768e4116..1a7e3d402b 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -90,7 +90,7 @@ void Q921Init() if your trunk is not TE (user) mode (i.e. NET). *****************************************************************************/ -int Q921_InitTrunk(long trunk, int sapi, int tei, Q921NetUser_t NetUser) +int Q921_InitTrunk(long trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser) { if (trunk > Q921MAXTRUNK) return 0; @@ -173,9 +173,9 @@ int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *m int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) { return Q921SendI(trunk, - Q921DevSpace[x].sapi, - Q921DevSpace[x].NetUser == Q921_TE ? 0 : 1; - Q921DevSpace[x].tei, + Q921DevSpace[trunk].sapi, + Q921DevSpace[trunk].NetUser == Q921_TE ? 0 : 1, + Q921DevSpace[trunk].tei, 0, Mes, Size); diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index cec349820a..aba3fab9a0 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -110,19 +110,19 @@ typedef struct L2UCHAR vs; L2UCHAR vr; L2INT state; - L2INT sapi; - L2INT tei; + L2UCHAR sapi; + L2UCHAR tei; Q921NetUser_t NetUser; }Q921Data; void Q921Init(); -int Q921_InitTrunk(long trunk, int sapi, int tei, Q921NetUser_t NetUser); +int Q921_InitTrunk(long trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); void Q921SetHeaderSpace(int hspace); void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); int Q921Rx12(long trunk); - +int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size); #endif From 62eea6fd8143d5887bba299164be423fbadbc75c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 22 May 2007 02:27:50 +0000 Subject: [PATCH 0179/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@90 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 6 +- libs/openzap/src/include/openzap.h | 33 +++--- libs/openzap/src/include/zap_types.h | 104 ++++++++++------- libs/openzap/src/include/zap_wanpipe.h | 2 +- libs/openzap/src/{openzap.c => zap_io.c} | 136 +++++++++++------------ libs/openzap/src/zap_wanpipe.c | 28 ++--- 6 files changed, 165 insertions(+), 144 deletions(-) rename libs/openzap/src/{openzap.c => zap_io.c} (89%) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 7b5c211e66..3cb6bad5d2 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -32,7 +32,9 @@ OBJS=hashtable.o \ hashtable_itr.o \ -openzap.o \ +zap_io.o \ +zap_isdn.o \ +zap_analog.o \ zap_config.o \ g711.o \ libteletone_detect.o \ @@ -77,7 +79,7 @@ sangoma_pri.o: sangoma_pri.c priserver: $(MYLIB) priserver.o sangoma_pri.o $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a -openzap.o: openzap.c +zap_io.o: zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ zap_wanpipe.o: zap_wanpipe.c diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 256b4e8f9b..29e23b14cf 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -173,7 +173,7 @@ struct zap_channel { teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; - zint_event_cb_t event_callback; + zio_event_cb_t event_callback; void *mod_data; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; @@ -181,7 +181,7 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; struct zap_span *span; - struct zap_software_interface *zint; + struct zap_io_interface *zio; }; @@ -189,34 +189,35 @@ struct zap_span { uint32_t span_id; uint32_t chan_count; zap_span_flag_t flags; - struct zap_software_interface *zint; - zint_event_cb_t event_callback; + struct zap_io_interface *zio; + zio_event_cb_t event_callback; zap_mutex_t *mutex; + zap_signal_type_t signal_type; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; extern zap_logger_t zap_log; -struct zap_software_interface { +struct zap_io_interface { const char *name; - zint_configure_t configure; - zint_open_t open; - zint_close_t close; - zint_command_t command; - zint_wait_t wait; - zint_read_t read; - zint_write_t write; + zio_configure_t configure; + zio_open_t open; + zio_close_t close; + zio_command_t command; + zio_wait_t wait; + zio_read_t read; + zio_write_t write; uint32_t span_index; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); -zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); -zap_status_t zap_span_close_all(zap_software_interface_t *zint); +zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); +zap_status_t zap_span_close_all(zap_io_interface_t *zio); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); +zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 2e7d5447f6..0cfa2e9468 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -45,11 +45,36 @@ typedef int zap_socket_t; #endif typedef size_t zap_size_t; -struct zap_software_interface; +struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +typedef enum { + ZAP_SIGTYPE_NONE, + ZAP_SIGTYPE_ISDN, + ZAP_SIGTYPE_RBS, + ZAP_SIGTYPE_ANALOG +} zap_signal_type_t; + +typedef enum { + ZAP_SIGEVENT_CALL_START, + ZAP_SIGEVENT_CALL_STOP, + ZAP_SIGEVENT_CALL_TRANSFER, + ZAP_SIGEVENT_ANSWER, + ZAP_SIGEVENT_PROGRESS, + ZAP_SIGEVENT_PROGRESS_MEDIA, + ZAP_SIGEVENT_NOTIFY, + ZAP_SIGEVENT_MISC +} zap_signal_event_t; + +typedef enum { + ZAP_EVENT_NONE, + ZAP_EVENT_DTMF, + + ZAP_EVENT_COUNT +} zap_event_type_t; + typedef enum { ZAP_TOP_DOWN, ZAP_BOTTOM_UP @@ -134,43 +159,43 @@ typedef enum { typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; -#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) -#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) -#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) -#define ZINT_OPEN_ARGS (zap_channel_t *zchan) -#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) -#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) -#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) -#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +#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_ARGS (struct zap_io_interface *zio) +#define ZIO_OPEN_ARGS (zap_channel_t *zchan) +#define ZIO_CLOSE_ARGS (zap_channel_t *zchan) +#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_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) -typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; -typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; -typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; -typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; -typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; -typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; -typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; -typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; -typedef zap_status_t (*zint_write_t) ZINT_WRITE_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_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_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 ; -#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS -#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS -#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS -#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS -#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS -#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS -#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS -#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS -#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS +#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS +#define ZIO_CODEC_FUNCTION(name) zap_status_t name ZIO_CODEC_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_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 ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLE assert(zchan != NULL) -#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) -#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) -#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) -#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) -#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZIO_CONFIGURE_MUZZLE assert(zio != NULL) +#define ZIO_OPEN_MUZZLE assert(zchan != NULL) +#define ZIO_CLOSE_MUZZLE assert(zchan != NULL) +#define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) +#define ZIO_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) +#define ZIO_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZIO_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ @@ -192,16 +217,9 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT #define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG -typedef enum { - ZAP_EVENT_NONE, - ZAP_EVENT_DTMF, - - ZAP_EVENT_COUNT -} zap_event_type_t; - typedef struct zap_span zap_span_t; typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); -typedef struct zap_software_interface zap_software_interface_t; +typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; typedef struct hashtable_itr zap_hash_itr_t; typedef struct key zap_hash_key_t; diff --git a/libs/openzap/src/include/zap_wanpipe.h b/libs/openzap/src/include/zap_wanpipe.h index 90cd9a0997..fa78f41f74 100644 --- a/libs/openzap/src/include/zap_wanpipe.h +++ b/libs/openzap/src/include/zap_wanpipe.h @@ -35,7 +35,7 @@ #define ZAP_WANPIPE_H #include "openzap.h" -zap_status_t wanpipe_init(zap_software_interface_t **zint); +zap_status_t wanpipe_init(zap_io_interface_t **zint); zap_status_t wanpipe_destroy(void); #endif diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/zap_io.c similarity index 89% rename from libs/openzap/src/openzap.c rename to libs/openzap/src/zap_io.c index 3550fed880..9a55b2cb27 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/zap_io.c @@ -147,18 +147,18 @@ static uint32_t hashfromstring(void *ky) return hash; } -zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) +zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; - assert(zint != NULL); + assert(zio != NULL); - if (zint->span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = &zint->spans[++zint->span_index]; + if (zio->span_index < ZAP_MAX_SPANS_INTERFACE) { + new_span = &zio->spans[++zio->span_index]; memset(new_span, 0, sizeof(*new_span)); zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = zint->span_index; - new_span->zint = zint; + new_span->span_id = zio->span_index; + new_span->zio = zio; zap_mutex_create(&new_span->mutex); *span = new_span; return ZAP_SUCCESS; @@ -167,13 +167,13 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) return ZAP_FAIL; } -zap_status_t zap_span_close_all(zap_software_interface_t *zint) +zap_status_t zap_span_close_all(zap_io_interface_t *zio) { zap_span_t *span; uint32_t i; - for(i = 0; i < zint->span_index; i++) { - span = &zint->spans[i]; + for(i = 0; i < zio->span_index; i++) { + span = &zio->spans[i]; if (span->mutex) { zap_mutex_destroy(&span->mutex); } @@ -189,7 +189,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan = &span->channels[++span->chan_count]; new_chan->type = type; new_chan->sockfd = sockfd; - new_chan->zint = span->zint; + new_chan->zio = span->zio; new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; @@ -203,14 +203,14 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_span_t *fspan; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (!zint) { + if (!zio) { return ZAP_FAIL; } @@ -218,7 +218,7 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) return ZAP_FAIL; } - fspan = &zint->spans[id]; + fspan = &zio->spans[id]; if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; @@ -230,7 +230,7 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) } -zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback) +zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) { zap_mutex_lock(span->mutex); span->event_callback = event_callback; @@ -238,7 +238,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event return ZAP_SUCCESS; } -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback) +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->span->mutex); zchan->event_callback = event_callback; @@ -248,7 +248,7 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; @@ -256,10 +256,10 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct uint32_t span_max; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (!zint) { + if (!zio) { zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); return ZAP_FAIL; } @@ -267,7 +267,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct if (span_id) { span_max = span_id; } else { - span_max = zint->span_index; + span_max = zio->span_index; } if (direction == ZAP_TOP_DOWN) { @@ -279,7 +279,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct zap_mutex_lock(globals.mutex); for(;;) { - span = &zint->spans[j]; + span = &zio->spans[j]; if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; @@ -317,7 +317,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); + status = check->zio->open(check); if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_OPEN); @@ -376,27 +376,27 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { zap_channel_t *check; - zap_mutex_lock(zint->spans[span_id].mutex); - check = &zint->spans[span_id].channels[chan_id]; + zap_mutex_lock(zio->spans[span_id].mutex); + check = &zio->spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); + status = check->zio->open(check); if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_OPEN); *zchan = check; } } - zap_mutex_unlock(zint->spans[span_id].mutex); + zap_mutex_unlock(zio->spans[span_id].mutex); } return status; @@ -414,7 +414,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) zap_mutex_lock(check->span->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->close(check); + status = check->zio->close(check); if (status == ZAP_SUCCESS) { zap_channel_reset(check); *zchan = NULL; @@ -464,7 +464,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t status = ZAP_FAIL; assert(zchan != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); @@ -623,12 +623,12 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; } - if (!zchan->zint->command) { + if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); GOTO_STATUS(done, ZAP_FAIL); } - status = zchan->zint->command(zchan, command, obj); + status = zchan->zio->command(zchan, command, obj); done: zap_mutex_unlock(zchan->span->mutex); @@ -639,24 +639,24 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) { assert(zchan != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } - if (!zchan->zint->wait) { + if (!zchan->zio->wait) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - return zchan->zint->wait(zchan, flags, to); + return zchan->zio->wait(zchan, flags, to); } /*******************************/ -ZINT_CODEC_FUNCTION(zint_slin2ulaw) +ZIO_CODEC_FUNCTION(zio_slin2ulaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; @@ -680,7 +680,7 @@ ZINT_CODEC_FUNCTION(zint_slin2ulaw) } -ZINT_CODEC_FUNCTION(zint_ulaw2slin) +ZIO_CODEC_FUNCTION(zio_ulaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; @@ -702,7 +702,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin) return ZAP_SUCCESS; } -ZINT_CODEC_FUNCTION(zint_slin2alaw) +ZIO_CODEC_FUNCTION(zio_slin2alaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; @@ -726,7 +726,7 @@ ZINT_CODEC_FUNCTION(zint_slin2alaw) } -ZINT_CODEC_FUNCTION(zint_alaw2slin) +ZIO_CODEC_FUNCTION(zio_alaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; @@ -748,7 +748,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin) return ZAP_SUCCESS; } -ZINT_CODEC_FUNCTION(zint_ulaw2alaw) +ZIO_CODEC_FUNCTION(zio_ulaw2alaw) { zap_size_t len = *datalen; uint32_t i; @@ -766,7 +766,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2alaw) return ZAP_SUCCESS; } -ZINT_CODEC_FUNCTION(zint_alaw2ulaw) +ZIO_CODEC_FUNCTION(zio_alaw2ulaw) { zap_size_t len = *datalen; uint32_t i; @@ -789,34 +789,34 @@ ZINT_CODEC_FUNCTION(zint_alaw2ulaw) zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func = NULL; + zio_codec_t codec_func = NULL; zap_size_t max = *datalen; assert(zchan != NULL); - assert(zchan->zint != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } - if (!zchan->zint->read) { + if (!zchan->zio->read) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - status = zchan->zint->read(zchan, data, datalen); + status = zchan->zio->read(zchan, data, datalen); if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_ulaw2slin; + codec_func = zio_ulaw2slin; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { - codec_func = zint_ulaw2alaw; + codec_func = zio_ulaw2alaw; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_alaw2slin; + codec_func = zio_alaw2slin; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { - codec_func = zint_alaw2ulaw; + codec_func = zio_alaw2ulaw; } if (codec_func) { @@ -861,7 +861,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); if(digit_str[0]) { - zint_event_cb_t event_callback = NULL; + zio_event_cb_t event_callback = NULL; if (zchan->span->event_callback) { event_callback = zchan->span->event_callback; } else if (zchan->event_callback) { @@ -892,31 +892,31 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func = NULL; + zio_codec_t codec_func = NULL; zap_size_t dtmf_blen, max = *datalen; assert(zchan != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } - if (!zchan->zint->write) { + if (!zchan->zio->write) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_slin2ulaw; + codec_func = zio_slin2ulaw; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { - codec_func = zint_alaw2ulaw; + codec_func = zio_alaw2ulaw; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_slin2alaw; + codec_func = zio_slin2alaw; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { - codec_func = zint_ulaw2alaw; + codec_func = zio_ulaw2alaw; } if (codec_func) { @@ -949,22 +949,22 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat if (zchan->native_codec != ZAP_CODEC_SLIN) { if (zchan->native_codec == ZAP_CODEC_ULAW) { *datalen = dlen; - zint_slin2ulaw(data, max, datalen); + zio_slin2ulaw(data, max, datalen); } else if (zchan->native_codec == ZAP_CODEC_ALAW) { *datalen = dlen; - zint_slin2alaw(data, max, datalen); + zio_slin2alaw(data, max, datalen); } } } - status = zchan->zint->write(zchan, data, datalen); + status = zchan->zio->write(zchan, data, datalen); return status; } static struct { - zap_software_interface_t *wanpipe_interface; - zap_software_interface_t *zt_interface; + zap_io_interface_t *wanpipe_interface; + zap_io_interface_t *zt_interface; } interfaces; zap_status_t zap_global_init(void) @@ -1013,14 +1013,14 @@ zap_status_t zap_global_init(void) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "openzap")) { if (!strcmp(var, "load")) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, val); zap_mutex_unlock(globals.mutex); - if (zint) { - if (zint->configure(zint) == ZAP_SUCCESS) { + if (zio) { + if (zio->configure(zio) == ZAP_SUCCESS) { configured++; } } else { diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 6386741e1f..c3ddbcbb9a 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -42,7 +42,7 @@ static struct { unsigned codec_ms; } wp_globals; -static zap_software_interface_t wanpipe_interface; +static zap_io_interface_t wanpipe_interface; static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) { @@ -146,7 +146,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) +static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; char *var, *val; @@ -155,7 +155,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) int new_span = 0; unsigned configured = 0, d = 0; - ZINT_CONFIGURE_MUZZLE; + ZIO_CONFIGURE_MUZZLE; zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n"); if (!zap_config_open_file(&cfg, "wanpipe.conf")) { @@ -229,7 +229,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) return configured ? ZAP_SUCCESS : ZAP_FAIL; } -static ZINT_OPEN_FUNCTION(wanpipe_open) +static ZIO_OPEN_FUNCTION(wanpipe_open) { wanpipe_tdm_api_t tdm_api; @@ -259,18 +259,18 @@ static ZINT_OPEN_FUNCTION(wanpipe_open) return ZAP_SUCCESS; } -static ZINT_CLOSE_FUNCTION(wanpipe_close) +static ZIO_CLOSE_FUNCTION(wanpipe_close) { - ZINT_CLOSE_MUZZLE; + ZIO_CLOSE_MUZZLE; return ZAP_SUCCESS; } -static ZINT_COMMAND_FUNCTION(wanpipe_command) +static ZIO_COMMAND_FUNCTION(wanpipe_command) { wanpipe_tdm_api_t tdm_api; int err = 0; - ZINT_COMMAND_MUZZLE; + ZIO_COMMAND_MUZZLE; memset(&tdm_api, 0, sizeof(tdm_api)); @@ -306,7 +306,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) return ZAP_SUCCESS; } -static ZINT_READ_FUNCTION(wanpipe_read) +static ZIO_READ_FUNCTION(wanpipe_read) { int rx_len = 0; wp_tdm_api_rx_hdr_t hdrframe; @@ -325,7 +325,7 @@ static ZINT_READ_FUNCTION(wanpipe_read) return ZAP_SUCCESS; } -static ZINT_WRITE_FUNCTION(wanpipe_write) +static ZIO_WRITE_FUNCTION(wanpipe_write) { int bsent; wp_tdm_api_tx_hdr_t hdrframe; @@ -344,7 +344,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write) } -static ZINT_WAIT_FUNCTION(wanpipe_wait) +static ZIO_WAIT_FUNCTION(wanpipe_wait) { int32_t inflags = 0; int result; @@ -389,9 +389,9 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } -zap_status_t wanpipe_init(zap_software_interface_t **zint) +zap_status_t wanpipe_init(zap_io_interface_t **zio) { - assert(zint != NULL); + assert(zio != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); wp_globals.codec_ms = 20; @@ -403,7 +403,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.wait = wanpipe_wait; wanpipe_interface.read = wanpipe_read; wanpipe_interface.write = wanpipe_write; - *zint = &wanpipe_interface; + *zio = &wanpipe_interface; return ZAP_SUCCESS; } From ba239e2936ca7bccfdbd1aeaa381e2c57e050dc2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 22 May 2007 02:27:50 +0000 Subject: [PATCH 0180/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@90 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 6 +- libs/freetdm/src/include/openzap.h | 33 +++--- libs/freetdm/src/include/zap_types.h | 104 ++++++++++------- libs/freetdm/src/include/zap_wanpipe.h | 2 +- libs/freetdm/src/{openzap.c => zap_io.c} | 136 +++++++++++------------ libs/freetdm/src/zap_wanpipe.c | 28 ++--- 6 files changed, 165 insertions(+), 144 deletions(-) rename libs/freetdm/src/{openzap.c => zap_io.c} (89%) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 7b5c211e66..3cb6bad5d2 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -32,7 +32,9 @@ OBJS=hashtable.o \ hashtable_itr.o \ -openzap.o \ +zap_io.o \ +zap_isdn.o \ +zap_analog.o \ zap_config.o \ g711.o \ libteletone_detect.o \ @@ -77,7 +79,7 @@ sangoma_pri.o: sangoma_pri.c priserver: $(MYLIB) priserver.o sangoma_pri.o $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a -openzap.o: openzap.c +zap_io.o: zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ zap_wanpipe.o: zap_wanpipe.c diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 256b4e8f9b..29e23b14cf 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -173,7 +173,7 @@ struct zap_channel { teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; - zint_event_cb_t event_callback; + zio_event_cb_t event_callback; void *mod_data; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; @@ -181,7 +181,7 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; struct zap_span *span; - struct zap_software_interface *zint; + struct zap_io_interface *zio; }; @@ -189,34 +189,35 @@ struct zap_span { uint32_t span_id; uint32_t chan_count; zap_span_flag_t flags; - struct zap_software_interface *zint; - zint_event_cb_t event_callback; + struct zap_io_interface *zio; + zio_event_cb_t event_callback; zap_mutex_t *mutex; + zap_signal_type_t signal_type; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; extern zap_logger_t zap_log; -struct zap_software_interface { +struct zap_io_interface { const char *name; - zint_configure_t configure; - zint_open_t open; - zint_close_t close; - zint_command_t command; - zint_wait_t wait; - zint_read_t read; - zint_write_t write; + zio_configure_t configure; + zio_open_t open; + zio_close_t close; + zio_command_t command; + zio_wait_t wait; + zio_read_t read; + zio_write_t write; uint32_t span_index; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); -zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span); -zap_status_t zap_span_close_all(zap_software_interface_t *zint); +zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); +zap_status_t zap_span_close_all(zap_io_interface_t *zio); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback); -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback); +zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 2e7d5447f6..0cfa2e9468 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -45,11 +45,36 @@ typedef int zap_socket_t; #endif typedef size_t zap_size_t; -struct zap_software_interface; +struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +typedef enum { + ZAP_SIGTYPE_NONE, + ZAP_SIGTYPE_ISDN, + ZAP_SIGTYPE_RBS, + ZAP_SIGTYPE_ANALOG +} zap_signal_type_t; + +typedef enum { + ZAP_SIGEVENT_CALL_START, + ZAP_SIGEVENT_CALL_STOP, + ZAP_SIGEVENT_CALL_TRANSFER, + ZAP_SIGEVENT_ANSWER, + ZAP_SIGEVENT_PROGRESS, + ZAP_SIGEVENT_PROGRESS_MEDIA, + ZAP_SIGEVENT_NOTIFY, + ZAP_SIGEVENT_MISC +} zap_signal_event_t; + +typedef enum { + ZAP_EVENT_NONE, + ZAP_EVENT_DTMF, + + ZAP_EVENT_COUNT +} zap_event_type_t; + typedef enum { ZAP_TOP_DOWN, ZAP_BOTTOM_UP @@ -134,43 +159,43 @@ typedef enum { typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; -#define ZINT_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) -#define ZINT_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) -#define ZINT_CONFIGURE_ARGS (struct zap_software_interface *zint) -#define ZINT_OPEN_ARGS (zap_channel_t *zchan) -#define ZINT_CLOSE_ARGS (zap_channel_t *zchan) -#define ZINT_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZINT_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) -#define ZINT_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) -#define ZINT_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) +#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_ARGS (struct zap_io_interface *zio) +#define ZIO_OPEN_ARGS (zap_channel_t *zchan) +#define ZIO_CLOSE_ARGS (zap_channel_t *zchan) +#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_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) -typedef zap_status_t (*zint_event_cb_t) ZINT_EVENT_CB_ARGS ; -typedef zap_status_t (*zint_codec_t) ZINT_CODEC_ARGS ; -typedef zap_status_t (*zint_configure_t) ZINT_CONFIGURE_ARGS ; -typedef zap_status_t (*zint_open_t) ZINT_OPEN_ARGS ; -typedef zap_status_t (*zint_close_t) ZINT_CLOSE_ARGS ; -typedef zap_status_t (*zint_command_t) ZINT_COMMAND_ARGS ; -typedef zap_status_t (*zint_wait_t) ZINT_WAIT_ARGS ; -typedef zap_status_t (*zint_read_t) ZINT_READ_ARGS ; -typedef zap_status_t (*zint_write_t) ZINT_WRITE_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_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_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 ; -#define ZINT_EVENT_CB_FUNCTION(name) zap_status_t name ZINT_EVENT_CB_ARGS -#define ZINT_CODEC_FUNCTION(name) zap_status_t name ZINT_CODEC_ARGS -#define ZINT_CONFIGURE_FUNCTION(name) zap_status_t name ZINT_CONFIGURE_ARGS -#define ZINT_OPEN_FUNCTION(name) zap_status_t name ZINT_OPEN_ARGS -#define ZINT_CLOSE_FUNCTION(name) zap_status_t name ZINT_CLOSE_ARGS -#define ZINT_COMMAND_FUNCTION(name) zap_status_t name ZINT_COMMAND_ARGS -#define ZINT_WAIT_FUNCTION(name) zap_status_t name ZINT_WAIT_ARGS -#define ZINT_READ_FUNCTION(name) zap_status_t name ZINT_READ_ARGS -#define ZINT_WRITE_FUNCTION(name) zap_status_t name ZINT_WRITE_ARGS +#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS +#define ZIO_CODEC_FUNCTION(name) zap_status_t name ZIO_CODEC_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_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 ZINT_CONFIGURE_MUZZLE assert(zint != NULL) -#define ZINT_OPEN_MUZZLE assert(zchan != NULL) -#define ZINT_CLOSE_MUZZLE assert(zchan != NULL) -#define ZINT_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) -#define ZINT_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) -#define ZINT_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) -#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZIO_CONFIGURE_MUZZLE assert(zio != NULL) +#define ZIO_OPEN_MUZZLE assert(zchan != NULL) +#define ZIO_CLOSE_MUZZLE assert(zchan != NULL) +#define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) +#define ZIO_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) +#define ZIO_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) +#define ZIO_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ @@ -192,16 +217,9 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ; #define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT #define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG -typedef enum { - ZAP_EVENT_NONE, - ZAP_EVENT_DTMF, - - ZAP_EVENT_COUNT -} zap_event_type_t; - typedef struct zap_span zap_span_t; typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); -typedef struct zap_software_interface zap_software_interface_t; +typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; typedef struct hashtable_itr zap_hash_itr_t; typedef struct key zap_hash_key_t; diff --git a/libs/freetdm/src/include/zap_wanpipe.h b/libs/freetdm/src/include/zap_wanpipe.h index 90cd9a0997..fa78f41f74 100644 --- a/libs/freetdm/src/include/zap_wanpipe.h +++ b/libs/freetdm/src/include/zap_wanpipe.h @@ -35,7 +35,7 @@ #define ZAP_WANPIPE_H #include "openzap.h" -zap_status_t wanpipe_init(zap_software_interface_t **zint); +zap_status_t wanpipe_init(zap_io_interface_t **zint); zap_status_t wanpipe_destroy(void); #endif diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/zap_io.c similarity index 89% rename from libs/freetdm/src/openzap.c rename to libs/freetdm/src/zap_io.c index 3550fed880..9a55b2cb27 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/zap_io.c @@ -147,18 +147,18 @@ static uint32_t hashfromstring(void *ky) return hash; } -zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) +zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; - assert(zint != NULL); + assert(zio != NULL); - if (zint->span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = &zint->spans[++zint->span_index]; + if (zio->span_index < ZAP_MAX_SPANS_INTERFACE) { + new_span = &zio->spans[++zio->span_index]; memset(new_span, 0, sizeof(*new_span)); zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = zint->span_index; - new_span->zint = zint; + new_span->span_id = zio->span_index; + new_span->zio = zio; zap_mutex_create(&new_span->mutex); *span = new_span; return ZAP_SUCCESS; @@ -167,13 +167,13 @@ zap_status_t zap_span_create(zap_software_interface_t *zint, zap_span_t **span) return ZAP_FAIL; } -zap_status_t zap_span_close_all(zap_software_interface_t *zint) +zap_status_t zap_span_close_all(zap_io_interface_t *zio) { zap_span_t *span; uint32_t i; - for(i = 0; i < zint->span_index; i++) { - span = &zint->spans[i]; + for(i = 0; i < zio->span_index; i++) { + span = &zio->spans[i]; if (span->mutex) { zap_mutex_destroy(&span->mutex); } @@ -189,7 +189,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan = &span->channels[++span->chan_count]; new_chan->type = type; new_chan->sockfd = sockfd; - new_chan->zint = span->zint; + new_chan->zio = span->zio; new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; @@ -203,14 +203,14 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_span_t *fspan; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (!zint) { + if (!zio) { return ZAP_FAIL; } @@ -218,7 +218,7 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) return ZAP_FAIL; } - fspan = &zint->spans[id]; + fspan = &zio->spans[id]; if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; @@ -230,7 +230,7 @@ zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) } -zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event_callback) +zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) { zap_mutex_lock(span->mutex); span->event_callback = event_callback; @@ -238,7 +238,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zint_event_cb_t event return ZAP_SUCCESS; } -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_t event_callback) +zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->span->mutex); zchan->event_callback = event_callback; @@ -248,7 +248,7 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zint_event_cb_ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; @@ -256,10 +256,10 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct uint32_t span_max; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (!zint) { + if (!zio) { zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); return ZAP_FAIL; } @@ -267,7 +267,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct if (span_id) { span_max = span_id; } else { - span_max = zint->span_index; + span_max = zio->span_index; } if (direction == ZAP_TOP_DOWN) { @@ -279,7 +279,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct zap_mutex_lock(globals.mutex); for(;;) { - span = &zint->spans[j]; + span = &zio->spans[j]; if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; @@ -317,7 +317,7 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); + status = check->zio->open(check); if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_OPEN); @@ -376,27 +376,27 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) { + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { zap_channel_t *check; - zap_mutex_lock(zint->spans[span_id].mutex); - check = &zint->spans[span_id].channels[chan_id]; + zap_mutex_lock(zio->spans[span_id].mutex); + check = &zio->spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->open(check); + status = check->zio->open(check); if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_OPEN); *zchan = check; } } - zap_mutex_unlock(zint->spans[span_id].mutex); + zap_mutex_unlock(zio->spans[span_id].mutex); } return status; @@ -414,7 +414,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) zap_mutex_lock(check->span->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zint->close(check); + status = check->zio->close(check); if (status == ZAP_SUCCESS) { zap_channel_reset(check); *zchan = NULL; @@ -464,7 +464,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t status = ZAP_FAIL; assert(zchan != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); @@ -623,12 +623,12 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; } - if (!zchan->zint->command) { + if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); GOTO_STATUS(done, ZAP_FAIL); } - status = zchan->zint->command(zchan, command, obj); + status = zchan->zio->command(zchan, command, obj); done: zap_mutex_unlock(zchan->span->mutex); @@ -639,24 +639,24 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) { assert(zchan != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } - if (!zchan->zint->wait) { + if (!zchan->zio->wait) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - return zchan->zint->wait(zchan, flags, to); + return zchan->zio->wait(zchan, flags, to); } /*******************************/ -ZINT_CODEC_FUNCTION(zint_slin2ulaw) +ZIO_CODEC_FUNCTION(zio_slin2ulaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; @@ -680,7 +680,7 @@ ZINT_CODEC_FUNCTION(zint_slin2ulaw) } -ZINT_CODEC_FUNCTION(zint_ulaw2slin) +ZIO_CODEC_FUNCTION(zio_ulaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; @@ -702,7 +702,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2slin) return ZAP_SUCCESS; } -ZINT_CODEC_FUNCTION(zint_slin2alaw) +ZIO_CODEC_FUNCTION(zio_slin2alaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; @@ -726,7 +726,7 @@ ZINT_CODEC_FUNCTION(zint_slin2alaw) } -ZINT_CODEC_FUNCTION(zint_alaw2slin) +ZIO_CODEC_FUNCTION(zio_alaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; @@ -748,7 +748,7 @@ ZINT_CODEC_FUNCTION(zint_alaw2slin) return ZAP_SUCCESS; } -ZINT_CODEC_FUNCTION(zint_ulaw2alaw) +ZIO_CODEC_FUNCTION(zio_ulaw2alaw) { zap_size_t len = *datalen; uint32_t i; @@ -766,7 +766,7 @@ ZINT_CODEC_FUNCTION(zint_ulaw2alaw) return ZAP_SUCCESS; } -ZINT_CODEC_FUNCTION(zint_alaw2ulaw) +ZIO_CODEC_FUNCTION(zio_alaw2ulaw) { zap_size_t len = *datalen; uint32_t i; @@ -789,34 +789,34 @@ ZINT_CODEC_FUNCTION(zint_alaw2ulaw) zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func = NULL; + zio_codec_t codec_func = NULL; zap_size_t max = *datalen; assert(zchan != NULL); - assert(zchan->zint != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } - if (!zchan->zint->read) { + if (!zchan->zio->read) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } - status = zchan->zint->read(zchan, data, datalen); + status = zchan->zio->read(zchan, data, datalen); if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_ulaw2slin; + codec_func = zio_ulaw2slin; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { - codec_func = zint_ulaw2alaw; + codec_func = zio_ulaw2alaw; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_alaw2slin; + codec_func = zio_alaw2slin; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { - codec_func = zint_alaw2ulaw; + codec_func = zio_alaw2ulaw; } if (codec_func) { @@ -861,7 +861,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); if(digit_str[0]) { - zint_event_cb_t event_callback = NULL; + zio_event_cb_t event_callback = NULL; if (zchan->span->event_callback) { event_callback = zchan->span->event_callback; } else if (zchan->event_callback) { @@ -892,31 +892,31 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; - zint_codec_t codec_func = NULL; + zio_codec_t codec_func = NULL; zap_size_t dtmf_blen, max = *datalen; assert(zchan != NULL); - assert(zchan->zint != NULL); + assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; } - if (!zchan->zint->write) { + if (!zchan->zio->write) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); return ZAP_FAIL; } if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_slin2ulaw; + codec_func = zio_slin2ulaw; } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { - codec_func = zint_alaw2ulaw; + codec_func = zio_alaw2ulaw; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zint_slin2alaw; + codec_func = zio_slin2alaw; } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { - codec_func = zint_ulaw2alaw; + codec_func = zio_ulaw2alaw; } if (codec_func) { @@ -949,22 +949,22 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat if (zchan->native_codec != ZAP_CODEC_SLIN) { if (zchan->native_codec == ZAP_CODEC_ULAW) { *datalen = dlen; - zint_slin2ulaw(data, max, datalen); + zio_slin2ulaw(data, max, datalen); } else if (zchan->native_codec == ZAP_CODEC_ALAW) { *datalen = dlen; - zint_slin2alaw(data, max, datalen); + zio_slin2alaw(data, max, datalen); } } } - status = zchan->zint->write(zchan, data, datalen); + status = zchan->zio->write(zchan, data, datalen); return status; } static struct { - zap_software_interface_t *wanpipe_interface; - zap_software_interface_t *zt_interface; + zap_io_interface_t *wanpipe_interface; + zap_io_interface_t *zt_interface; } interfaces; zap_status_t zap_global_init(void) @@ -1013,14 +1013,14 @@ zap_status_t zap_global_init(void) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "openzap")) { if (!strcmp(var, "load")) { - zap_software_interface_t *zint; + zap_io_interface_t *zio; zap_mutex_lock(globals.mutex); - zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, val); zap_mutex_unlock(globals.mutex); - if (zint) { - if (zint->configure(zint) == ZAP_SUCCESS) { + if (zio) { + if (zio->configure(zio) == ZAP_SUCCESS) { configured++; } } else { diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 6386741e1f..c3ddbcbb9a 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -42,7 +42,7 @@ static struct { unsigned codec_ms; } wp_globals; -static zap_software_interface_t wanpipe_interface; +static zap_io_interface_t wanpipe_interface; static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) { @@ -146,7 +146,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) +static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) { zap_config_t cfg; char *var, *val; @@ -155,7 +155,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) int new_span = 0; unsigned configured = 0, d = 0; - ZINT_CONFIGURE_MUZZLE; + ZIO_CONFIGURE_MUZZLE; zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n"); if (!zap_config_open_file(&cfg, "wanpipe.conf")) { @@ -229,7 +229,7 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure) return configured ? ZAP_SUCCESS : ZAP_FAIL; } -static ZINT_OPEN_FUNCTION(wanpipe_open) +static ZIO_OPEN_FUNCTION(wanpipe_open) { wanpipe_tdm_api_t tdm_api; @@ -259,18 +259,18 @@ static ZINT_OPEN_FUNCTION(wanpipe_open) return ZAP_SUCCESS; } -static ZINT_CLOSE_FUNCTION(wanpipe_close) +static ZIO_CLOSE_FUNCTION(wanpipe_close) { - ZINT_CLOSE_MUZZLE; + ZIO_CLOSE_MUZZLE; return ZAP_SUCCESS; } -static ZINT_COMMAND_FUNCTION(wanpipe_command) +static ZIO_COMMAND_FUNCTION(wanpipe_command) { wanpipe_tdm_api_t tdm_api; int err = 0; - ZINT_COMMAND_MUZZLE; + ZIO_COMMAND_MUZZLE; memset(&tdm_api, 0, sizeof(tdm_api)); @@ -306,7 +306,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) return ZAP_SUCCESS; } -static ZINT_READ_FUNCTION(wanpipe_read) +static ZIO_READ_FUNCTION(wanpipe_read) { int rx_len = 0; wp_tdm_api_rx_hdr_t hdrframe; @@ -325,7 +325,7 @@ static ZINT_READ_FUNCTION(wanpipe_read) return ZAP_SUCCESS; } -static ZINT_WRITE_FUNCTION(wanpipe_write) +static ZIO_WRITE_FUNCTION(wanpipe_write) { int bsent; wp_tdm_api_tx_hdr_t hdrframe; @@ -344,7 +344,7 @@ static ZINT_WRITE_FUNCTION(wanpipe_write) } -static ZINT_WAIT_FUNCTION(wanpipe_wait) +static ZIO_WAIT_FUNCTION(wanpipe_wait) { int32_t inflags = 0; int result; @@ -389,9 +389,9 @@ static ZINT_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } -zap_status_t wanpipe_init(zap_software_interface_t **zint) +zap_status_t wanpipe_init(zap_io_interface_t **zio) { - assert(zint != NULL); + assert(zio != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); wp_globals.codec_ms = 20; @@ -403,7 +403,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint) wanpipe_interface.wait = wanpipe_wait; wanpipe_interface.read = wanpipe_read; wanpipe_interface.write = wanpipe_write; - *zint = &wanpipe_interface; + *zio = &wanpipe_interface; return ZAP_SUCCESS; } From 7eebf19e08eed787bd1a0f21d3eee7ac0eb32986 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 02:45:21 +0000 Subject: [PATCH 0181/1766] adjust to filename change. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@91 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index 80eed02239..f9eb82b703 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -172,10 +172,6 @@ RelativePath=".\src\libteletone_generate.c" > - - @@ -184,6 +180,10 @@ RelativePath=".\src\zap_config.c" > + + @@ -248,6 +248,12 @@ /> + + - - From 8fec552dda7a60053312b1336829a0cf9fa638bf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 02:45:21 +0000 Subject: [PATCH 0182/1766] adjust to filename change. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@91 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index 80eed02239..f9eb82b703 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -172,10 +172,6 @@ RelativePath=".\src\libteletone_generate.c" > - - @@ -184,6 +180,10 @@ RelativePath=".\src\zap_config.c" > + + @@ -248,6 +248,12 @@ /> + + - - From 36d6b40908769cab81125ef4aedeb0aa8880639e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 02:45:42 +0000 Subject: [PATCH 0183/1766] add function to initialize a new trunk. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@92 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 43 ++++++++++++++---- libs/openzap/src/isdn/include/Q931.h | 67 +++++++++++++++++----------- 2 files changed, 77 insertions(+), 33 deletions(-) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index e93b43193b..04d1685991 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -68,28 +68,54 @@ L3INT Q931CreateIEIndex(L3INT iec) } */ -void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) { - int y; + int y, dchannel, maxchans; + + switch(TrunkType) + { + case Q931_TrType_E1: + dchannel = 16; + maxchans = 31; + break; + + case Q931_TrType_T1: + case Q931_TrType_J1: + dchannel = 24; + maxchans = 24; + break; + + case Q931_TrType_BRI: + dchannel = 3; + maxchans = 3; + break; + + default: + return 0; + } + pTrunk->LastCRV = 0; - pTrunk->Dialect = 0; + pTrunk->Dialect = Dialect; pTrunk->Enabled = 0; - pTrunk->TrunkType = Q931_TrType_E1; - pTrunk->NetUser = Q931_TE; + pTrunk->TrunkType = TrunkType; + pTrunk->NetUser = NetUser; pTrunk->TrunkState = 0; for(y=0; y < Q931MAXCHPERTRUNK; y++) { pTrunk->ch[y].Available = 1; - /* Set up E1 scheme by default */ - if(y==0) + if(y == 0) { pTrunk->ch[y].ChanType = Q931_ChType_Sync; } - else if(y==16) + 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; @@ -101,6 +127,7 @@ void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) pTrunk->call[y].InUse = 0; } + return 1; } void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index f420b9d5ae..1fc31190c8 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1918,34 +1918,54 @@ typedef struct *****************************************************************************/ +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_Count +} 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_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; + typedef struct { - enum _NetUser /* Network/User Mode. */ - { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ - }NetUser; + Q931NetUser_t NetUser; /* Network/User Mode. */ - L3UCHAR Dialect; /* Q.931 Based dielact index. */ + Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ - enum _TrunkType /* 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 */ - }TrunkType; + Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ L3UCHAR Enabled; /* Enabled/Disabled */ /* 0 = Disabled */ /* 1 = Enabled */ - enum _TrState /* Trunk State */ - { - Q931_TrState_NoAlignment=0, /* Trunk not aligned */ - Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2 /* Trunk Aligned */ - }TrunkState; + Q931_TrunkState_t TrunkState; L3INT LastCRV; /* Last used crv for the trunk. */ @@ -1972,12 +1992,7 @@ typedef struct /* channels to fit an E1 since T1/J1 and BRI will fit inside a E1. */ struct _charray { - enum _ChanType{ - 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 */ - }ChanType; + Q931_ChanType_t ChanType; /* Unused, B, D, Sync */ L3UCHAR Available; /* Channel Available Flag */ /* 0 : Avaiabled */ @@ -2409,4 +2424,6 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType); + #endif /* _Q931_NL */ From ce854247e3ed01d7d91a9111394d0024f180f4f6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 02:45:42 +0000 Subject: [PATCH 0184/1766] add function to initialize a new trunk. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@92 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 43 ++++++++++++++---- libs/freetdm/src/isdn/include/Q931.h | 67 +++++++++++++++++----------- 2 files changed, 77 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index e93b43193b..04d1685991 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -68,28 +68,54 @@ L3INT Q931CreateIEIndex(L3INT iec) } */ -void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) { - int y; + int y, dchannel, maxchans; + + switch(TrunkType) + { + case Q931_TrType_E1: + dchannel = 16; + maxchans = 31; + break; + + case Q931_TrType_T1: + case Q931_TrType_J1: + dchannel = 24; + maxchans = 24; + break; + + case Q931_TrType_BRI: + dchannel = 3; + maxchans = 3; + break; + + default: + return 0; + } + pTrunk->LastCRV = 0; - pTrunk->Dialect = 0; + pTrunk->Dialect = Dialect; pTrunk->Enabled = 0; - pTrunk->TrunkType = Q931_TrType_E1; - pTrunk->NetUser = Q931_TE; + pTrunk->TrunkType = TrunkType; + pTrunk->NetUser = NetUser; pTrunk->TrunkState = 0; for(y=0; y < Q931MAXCHPERTRUNK; y++) { pTrunk->ch[y].Available = 1; - /* Set up E1 scheme by default */ - if(y==0) + if(y == 0) { pTrunk->ch[y].ChanType = Q931_ChType_Sync; } - else if(y==16) + 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; @@ -101,6 +127,7 @@ void Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk) pTrunk->call[y].InUse = 0; } + return 1; } void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index f420b9d5ae..1fc31190c8 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1918,34 +1918,54 @@ typedef struct *****************************************************************************/ +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_Count +} 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_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; + typedef struct { - enum _NetUser /* Network/User Mode. */ - { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ - }NetUser; + Q931NetUser_t NetUser; /* Network/User Mode. */ - L3UCHAR Dialect; /* Q.931 Based dielact index. */ + Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ - enum _TrunkType /* 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 */ - }TrunkType; + Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ L3UCHAR Enabled; /* Enabled/Disabled */ /* 0 = Disabled */ /* 1 = Enabled */ - enum _TrState /* Trunk State */ - { - Q931_TrState_NoAlignment=0, /* Trunk not aligned */ - Q931_TrState_Aligning=1, /* Aligning in progress */ - Q931_TrState_Aligned=2 /* Trunk Aligned */ - }TrunkState; + Q931_TrunkState_t TrunkState; L3INT LastCRV; /* Last used crv for the trunk. */ @@ -1972,12 +1992,7 @@ typedef struct /* channels to fit an E1 since T1/J1 and BRI will fit inside a E1. */ struct _charray { - enum _ChanType{ - 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 */ - }ChanType; + Q931_ChanType_t ChanType; /* Unused, B, D, Sync */ L3UCHAR Available; /* Channel Available Flag */ /* 0 : Avaiabled */ @@ -2409,4 +2424,6 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType); + #endif /* _Q931_NL */ From f3dd2b1cd7c3b5a5995039e2df8069bb81182973 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 03:18:23 +0000 Subject: [PATCH 0185/1766] fix default channel setup for things not E1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@93 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 04d1685991..aea264efd6 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -70,13 +70,14 @@ L3INT Q931CreateIEIndex(L3INT iec) L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) { - int y, dchannel, maxchans; + 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: @@ -104,7 +105,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUs { pTrunk->ch[y].Available = 1; - if(y == 0) + if(has_sync && y == 0) { pTrunk->ch[y].ChanType = Q931_ChType_Sync; } From 20421f48107f05d3d59b6155bcbf0a7c42833ebe Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 03:18:23 +0000 Subject: [PATCH 0186/1766] fix default channel setup for things not E1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@93 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 04d1685991..aea264efd6 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -70,13 +70,14 @@ L3INT Q931CreateIEIndex(L3INT iec) L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) { - int y, dchannel, maxchans; + 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: @@ -104,7 +105,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUs { pTrunk->ch[y].Available = 1; - if(y == 0) + if(has_sync && y == 0) { pTrunk->ch[y].ChanType = Q931_ChType_Sync; } From 4373a35c25a02aa75a1c91a39798536d758957f4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 04:25:04 +0000 Subject: [PATCH 0187/1766] let us use either static or dynamic trunk handles. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@94 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 91 ++++++++++++++-------------- libs/openzap/src/isdn/include/Q921.h | 22 +++++-- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 1a7e3d402b..2a7ed18604 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -53,8 +53,8 @@ Q921Data Q921DevSpace[Q921MAXTRUNK]; int Q921HeaderSpace={0}; -int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; /***************************************************************************** @@ -67,17 +67,13 @@ int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; *****************************************************************************/ void Q921Init() { +#ifdef Q921_HANDLE_STATIC int x; for(x=0; x Q921MAXTRUNK) - return 0; - - Q921DevSpace[trunk].sapi = sapi; - Q921DevSpace[trunk].tei = tei; - Q921DevSpace[trunk].NetUser = NetUser; - return 1; + if (L2TRUNKHANDLE(trunk).initialized != INITIALIZED_MAGIC) { + MFIFOCreate(L2TRUNKHANDLE(trunk).HDLCInQueue, Q921MAXHDLCSPACE, 10); + L2TRUNKHANDLE(trunk).initialized = INITIALIZED_MAGIC; + } + L2TRUNKHANDLE(trunk).vr = 0; + L2TRUNKHANDLE(trunk).vs = 0; + L2TRUNKHANDLE(trunk).state = 0; + L2TRUNKHANDLE(trunk).sapi = sapi; + L2TRUNKHANDLE(trunk).tei = tei; + L2TRUNKHANDLE(trunk).NetUser = NetUser; } void Q921SetHeaderSpace(int hspace) @@ -106,12 +105,12 @@ void Q921SetHeaderSpace(int hspace) Q921HeaderSpace=hspace; } -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) +void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) { Q921Tx21Proc = callback; } -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) +void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) { Q921Tx23Proc = callback; } @@ -135,9 +134,9 @@ void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) { - return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); + return MFIFOWriteMes(L2TRUNKHANDLE(trunk).HDLCInQueue, b, size); } /***************************************************************************** @@ -159,23 +158,23 @@ int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = Q921DevSpace[trunk].vs<<1; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); - Q921DevSpace[trunk].vs++; + mes[Q921HeaderSpace+2] = L2TRUNKHANDLE(trunk).vs<<1; + mes[Q921HeaderSpace+3] = (L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01); + L2TRUNKHANDLE(trunk).vs++; return Q921Tx21Proc(trunk, mes, size); } -int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) { return Q921SendI(trunk, - Q921DevSpace[trunk].sapi, - Q921DevSpace[trunk].NetUser == Q921_TE ? 0 : 1, - Q921DevSpace[trunk].tei, + L2TRUNKHANDLE(trunk).sapi, + L2TRUNKHANDLE(trunk).NetUser == Q921_TE ? 0 : 1, + L2TRUNKHANDLE(trunk).tei, 0, Mes, Size); @@ -196,14 +195,14 @@ int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) *****************************************************************************/ -int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -223,14 +222,14 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -250,14 +249,14 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -277,7 +276,7 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -303,7 +302,7 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -329,7 +328,7 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -355,7 +354,7 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -366,14 +365,14 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) { /* TODO: Do we need these paramaters? */ (void)mes; (void)size; - Q921DevSpace[trunk].vr=0; - Q921DevSpace[trunk].vs=0; + L2TRUNKHANDLE(trunk).vr=0; + L2TRUNKHANDLE(trunk).vs=0; return 1; } @@ -396,11 +395,11 @@ int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) Return Value: # messages processed (always 1 or 0). *****************************************************************************/ -int Q921Rx12(long trunk) +int Q921Rx12(L2TRUNK trunk) { L2UCHAR *mes; int rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + L2UCHAR *smes = MFIFOGetMesPtr(L2TRUNKHANDLE(trunk).HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; @@ -410,7 +409,7 @@ int Q921Rx12(long trunk) { if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ { - Q921DevSpace[trunk].vr++; + L2TRUNKHANDLE(trunk).vr++; Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); } else @@ -449,7 +448,7 @@ int Q921Rx12(long trunk) /* todo: REJ or FRMR */ } - MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + MFIFOKillNext(L2TRUNKHANDLE(trunk).HDLCInQueue); return 1; } diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index aba3fab9a0..6ed40d9a90 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -98,15 +98,25 @@ #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ +#ifdef Q921_HANDLE_STATIC +#define L2TRUNK long +#define L2TRUNKHANDLE(trunk) Q921DevSpace[trunk] +#else +#define L2TRUNK Q921Data * +#define L2TRUNKHANDLE(trunk) (*trunk) +#endif + typedef enum /* Network/User Mode. */ { Q921_TE=0, /* 0 : User Mode */ Q921_NT=1 /* 1 : Network Mode */ } Q921NetUser_t; +#define INITIALIZED_MAGIC 42 typedef struct { L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2INT initialized; L2UCHAR vs; L2UCHAR vr; L2INT state; @@ -117,12 +127,12 @@ typedef struct }Q921Data; void Q921Init(); -int Q921_InitTrunk(long trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); +void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); -int Q921Rx12(long trunk); -int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size); +void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size); +int Q921Rx12(L2TRUNK trunk); +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); #endif From f88576f4bb8ce487bce5d51098a275ddb3029fe9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 04:25:04 +0000 Subject: [PATCH 0188/1766] let us use either static or dynamic trunk handles. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@94 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 91 ++++++++++++++-------------- libs/freetdm/src/isdn/include/Q921.h | 22 +++++-- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 1a7e3d402b..2a7ed18604 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -53,8 +53,8 @@ Q921Data Q921DevSpace[Q921MAXTRUNK]; int Q921HeaderSpace={0}; -int (*Q921Tx21Proc)(int dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; +int (*Q921Tx23Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; /***************************************************************************** @@ -67,17 +67,13 @@ int (*Q921Tx23Proc)(int dev, L2UCHAR *, int)={NULL}; *****************************************************************************/ void Q921Init() { +#ifdef Q921_HANDLE_STATIC int x; for(x=0; x Q921MAXTRUNK) - return 0; - - Q921DevSpace[trunk].sapi = sapi; - Q921DevSpace[trunk].tei = tei; - Q921DevSpace[trunk].NetUser = NetUser; - return 1; + if (L2TRUNKHANDLE(trunk).initialized != INITIALIZED_MAGIC) { + MFIFOCreate(L2TRUNKHANDLE(trunk).HDLCInQueue, Q921MAXHDLCSPACE, 10); + L2TRUNKHANDLE(trunk).initialized = INITIALIZED_MAGIC; + } + L2TRUNKHANDLE(trunk).vr = 0; + L2TRUNKHANDLE(trunk).vs = 0; + L2TRUNKHANDLE(trunk).state = 0; + L2TRUNKHANDLE(trunk).sapi = sapi; + L2TRUNKHANDLE(trunk).tei = tei; + L2TRUNKHANDLE(trunk).NetUser = NetUser; } void Q921SetHeaderSpace(int hspace) @@ -106,12 +105,12 @@ void Q921SetHeaderSpace(int hspace) Q921HeaderSpace=hspace; } -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)) +void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) { Q921Tx21Proc = callback; } -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) +void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) { Q921Tx23Proc = callback; } @@ -135,9 +134,9 @@ void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) { - return MFIFOWriteMes(Q921DevSpace[trunk].HDLCInQueue, b, size); + return MFIFOWriteMes(L2TRUNKHANDLE(trunk).HDLCInQueue, b, size); } /***************************************************************************** @@ -159,23 +158,23 @@ int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(int trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) { mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = Q921DevSpace[trunk].vs<<1; - mes[Q921HeaderSpace+3] = (Q921DevSpace[trunk].vr<<1) | (pf & 0x01); - Q921DevSpace[trunk].vs++; + mes[Q921HeaderSpace+2] = L2TRUNKHANDLE(trunk).vs<<1; + mes[Q921HeaderSpace+3] = (L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01); + L2TRUNKHANDLE(trunk).vs++; return Q921Tx21Proc(trunk, mes, size); } -int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) { return Q921SendI(trunk, - Q921DevSpace[trunk].sapi, - Q921DevSpace[trunk].NetUser == Q921_TE ? 0 : 1, - Q921DevSpace[trunk].tei, + L2TRUNKHANDLE(trunk).sapi, + L2TRUNKHANDLE(trunk).NetUser == Q921_TE ? 0 : 1, + L2TRUNKHANDLE(trunk).tei, 0, Mes, Size); @@ -196,14 +195,14 @@ int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size) *****************************************************************************/ -int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -223,14 +222,14 @@ int Q921SendRR(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -250,14 +249,14 @@ int Q921SendRNR(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[Q921HeaderSpace+3] = (L2UCHAR)((Q921DevSpace[trunk].vr<<1) | (pf & 0x01)); + mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); } @@ -277,7 +276,7 @@ int Q921SendREJ(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -303,7 +302,7 @@ int Q921SendSABME(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -329,7 +328,7 @@ int Q921SendDM(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -355,7 +354,7 @@ int Q921SendDISC(int trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) +int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; @@ -366,14 +365,14 @@ int Q921SendUA(int trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); } -int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) { /* TODO: Do we need these paramaters? */ (void)mes; (void)size; - Q921DevSpace[trunk].vr=0; - Q921DevSpace[trunk].vs=0; + L2TRUNKHANDLE(trunk).vr=0; + L2TRUNKHANDLE(trunk).vs=0; return 1; } @@ -396,11 +395,11 @@ int Q921ProcSABME(int trunk, L2UCHAR *mes, int size) Return Value: # messages processed (always 1 or 0). *****************************************************************************/ -int Q921Rx12(long trunk) +int Q921Rx12(L2TRUNK trunk) { L2UCHAR *mes; int rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(Q921DevSpace[trunk].HDLCInQueue, &size); + L2UCHAR *smes = MFIFOGetMesPtr(L2TRUNKHANDLE(trunk).HDLCInQueue, &size); if(smes != NULL) { rs = size - Q921HeaderSpace; @@ -410,7 +409,7 @@ int Q921Rx12(long trunk) { if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ { - Q921DevSpace[trunk].vr++; + L2TRUNKHANDLE(trunk).vr++; Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); } else @@ -449,7 +448,7 @@ int Q921Rx12(long trunk) /* todo: REJ or FRMR */ } - MFIFOKillNext(Q921DevSpace[trunk].HDLCInQueue); + MFIFOKillNext(L2TRUNKHANDLE(trunk).HDLCInQueue); return 1; } diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index aba3fab9a0..6ed40d9a90 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -98,15 +98,25 @@ #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ +#ifdef Q921_HANDLE_STATIC +#define L2TRUNK long +#define L2TRUNKHANDLE(trunk) Q921DevSpace[trunk] +#else +#define L2TRUNK Q921Data * +#define L2TRUNKHANDLE(trunk) (*trunk) +#endif + typedef enum /* Network/User Mode. */ { Q921_TE=0, /* 0 : User Mode */ Q921_NT=1 /* 1 : Network Mode */ } Q921NetUser_t; +#define INITIALIZED_MAGIC 42 typedef struct { L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2INT initialized; L2UCHAR vs; L2UCHAR vr; L2INT state; @@ -117,12 +127,12 @@ typedef struct }Q921Data; void Q921Init(); -int Q921_InitTrunk(long trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); +void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(int dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(int dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(int trunk, L2UCHAR *b, int size); -int Q921Rx12(long trunk); -int Q921Rx32(long trunk, L2UCHAR * Mes, L2INT Size); +void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); +void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size); +int Q921Rx12(L2TRUNK trunk); +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); #endif From 5daa050cb5aa6f34c15dc6cebf838ba4562f631c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 04:33:31 +0000 Subject: [PATCH 0189/1766] missed this one from the last commit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@95 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 2a7ed18604..65e0d06fa0 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -50,7 +50,10 @@ /***************************************************************************** Global Tables & Variables. *****************************************************************************/ +#ifdef Q921_HANDLE_STATIC Q921Data Q921DevSpace[Q921MAXTRUNK]; +#endif + int Q921HeaderSpace={0}; int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; From 629ed3ef24bf76bab68eb383993d695c1b529bd2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 04:33:31 +0000 Subject: [PATCH 0190/1766] missed this one from the last commit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@95 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 2a7ed18604..65e0d06fa0 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -50,7 +50,10 @@ /***************************************************************************** Global Tables & Variables. *****************************************************************************/ +#ifdef Q921_HANDLE_STATIC Q921Data Q921DevSpace[Q921MAXTRUNK]; +#endif + int Q921HeaderSpace={0}; int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; From f59812b19cb99dba3cc9243a3c629ee0167d59cc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 08:03:20 +0000 Subject: [PATCH 0191/1766] rework 921/931 api. Move the Tx callbacks on each to be trunk specific, not global so that we can set them per trunk. Change prototypes for the Tx callbacks so that they pass a trunk specific private pointer to the Tx callbacks so that 921 and 931 can call each other directly. change 921 so that it doesn't use a static array for it's trunk structure to match 931 use more enums. more to come.... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@96 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 189 +- libs/openzap/src/isdn/Q931.c | 43 +- libs/openzap/src/isdn/Q931api.c | 14 +- libs/openzap/src/isdn/include/Q921.h | 66 +- libs/openzap/src/isdn/include/Q931.h | 4874 +++++++++++++------------- 5 files changed, 2580 insertions(+), 2606 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 65e0d06fa0..d0a0bce29e 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -2,13 +2,7 @@ FileName: q921.c - Description: Contains the implementation of a Q.921 protocol on top of the - Comet Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. + Description: Contains the implementation of a Q.921 protocol Created: 27.dec.2000/JVB @@ -47,75 +41,48 @@ #include #include "mfifo.h" -/***************************************************************************** - Global Tables & Variables. -*****************************************************************************/ -#ifdef Q921_HANDLE_STATIC -Q921Data Q921DevSpace[Q921MAXTRUNK]; -#endif - -int Q921HeaderSpace={0}; - -int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; - -/***************************************************************************** - - Function: Q921Init - - Decription: Initialize the Q.921 stack so it is ready for use. This - function MUST be called as part of initializing the - application. - -*****************************************************************************/ -void Q921Init() -{ -#ifdef Q921_HANDLE_STATIC - int x; - for(x=0; xinitialized != INITIALIZED_MAGIC) { + MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); + trunk->initialized = INITIALIZED_MAGIC; } - L2TRUNKHANDLE(trunk).vr = 0; - L2TRUNKHANDLE(trunk).vs = 0; - L2TRUNKHANDLE(trunk).state = 0; - L2TRUNKHANDLE(trunk).sapi = sapi; - L2TRUNKHANDLE(trunk).tei = tei; - L2TRUNKHANDLE(trunk).NetUser = NetUser; + trunk->vr = 0; + trunk->vs = 0; + trunk->state = 0; + trunk->sapi = sapi; + trunk->tei = tei; + trunk->NetUser = NetUser; + trunk->Q921Tx21Proc = cb21; + trunk->Q921Tx23Proc = cb23; + trunk->PrivateData = priv; + trunk->Q921HeaderSpace = hsize; } -void Q921SetHeaderSpace(int hspace) +static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - Q921HeaderSpace=hspace; + return trunk->Q921Tx21Proc(trunk->PrivateData, Msg, size); } -void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) +int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - Q921Tx21Proc = callback; -} + return trunk->Q921Tx23Proc(trunk->PrivateData, Msg, size); -void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) -{ - Q921Tx23Proc = callback; } /***************************************************************************** @@ -137,9 +104,9 @@ void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size) { - return MFIFOWriteMes(L2TRUNKHANDLE(trunk).HDLCInQueue, b, size); + return MFIFOWriteMes(trunk->HDLCInQueue, b, size); } /***************************************************************************** @@ -161,13 +128,13 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size) { - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = L2TRUNKHANDLE(trunk).vs<<1; - mes[Q921HeaderSpace+3] = (L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01); - L2TRUNKHANDLE(trunk).vs++; + mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); + mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; + mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; + mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); + trunk->vs++; return Q921Tx21Proc(trunk, mes, size); } @@ -175,9 +142,9 @@ int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHA int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) { return Q921SendI(trunk, - L2TRUNKHANDLE(trunk).sapi, - L2TRUNKHANDLE(trunk).NetUser == Q921_TE ? 0 : 1, - L2TRUNKHANDLE(trunk).tei, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, 0, Mes, Size); @@ -202,12 +169,12 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -229,12 +196,12 @@ int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -256,12 +223,12 @@ int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -283,11 +250,11 @@ int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -309,11 +276,11 @@ int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -335,11 +302,11 @@ int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -361,21 +328,21 @@ int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) { /* TODO: Do we need these paramaters? */ (void)mes; (void)size; - L2TRUNKHANDLE(trunk).vr=0; - L2TRUNKHANDLE(trunk).vs=0; + trunk->vr=0; + trunk->vs=0; return 1; } @@ -401,18 +368,18 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) int Q921Rx12(L2TRUNK trunk) { L2UCHAR *mes; - int rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(L2TRUNKHANDLE(trunk).HDLCInQueue, &size); + L2INT rs,size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); if(smes != NULL) { - rs = size - Q921HeaderSpace; - mes = &smes[Q921HeaderSpace]; + rs = size - trunk->Q921HeaderSpace; + mes = &smes[trunk->Q921HeaderSpace]; /* check for I frame */ if((mes[2] & 0x01) == 0) { if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ { - L2TRUNKHANDLE(trunk).vr++; + trunk->vr++; Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); } else @@ -451,7 +418,7 @@ int Q921Rx12(L2TRUNK trunk) /* todo: REJ or FRMR */ } - MFIFOKillNext(L2TRUNKHANDLE(trunk).HDLCInQueue); + MFIFOKillNext(trunk->HDLCInQueue); return 1; } diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 09cbaf0b76..9bf16f2c78 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -88,15 +88,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ *****************************************************************************/ -L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - /* callback for messages to be send to */ - /* layer 4. */ - -L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); - /* callback ptr for messages to be send */ - /* to layer 2. */ - -L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); +Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ @@ -210,7 +202,7 @@ L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) Description: Dummy function for error processing *****************************************************************************/ -L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) +L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) { return 0; } @@ -235,8 +227,6 @@ void Q931Initialize() L3INT x,y; /* Secure the callbacks to default procs */ - Q931Tx34Proc = Q931TxDummy; - Q931Tx32Proc = Q931TxDummy; Q931ErrorProc = Q931ErrorDummy; /* The user will only add the message handlers and IE handlers he need, */ @@ -360,7 +350,10 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) *****************************************************************************/ L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) { - return Q931Tx34Proc(pTrunk, Mes, Size); + if (pTrunk->Q931Tx34CBProc) { + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData, Mes, Size); + } + return Q931E_MISSING_CB; } /***************************************************************************** @@ -415,7 +408,11 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); if(RetCode >= Q931E_NO_ERROR) { - RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); + if (pTrunk->Q931Tx32CBProc) { + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData, pTrunk->L2Buf, Size); + } else { + RetCode = Q931E_MISSING_CB; + } } return RetCode; @@ -436,20 +433,14 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) *****************************************************************************/ void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) { - Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); + if (pTrunk->Q931ErrorCBProc) { + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + } else { + Q931ErrorProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + } } -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx34Proc = Q931Tx34Par; -} - -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx32Proc = Q931Tx32Par; -} - -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) +void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) { Q931ErrorProc = Q931ErrorPar; } diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index aea264efd6..8de8c717b6 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -68,7 +68,14 @@ L3INT Q931CreateIEIndex(L3INT iec) } */ -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, + Q931Dialect_t Dialect, + Q931NetUser_t NetUser, + Q931_TrunkType_t TrunkType, + Q931TxCB_t Q931Tx34CBProc, + Q931TxCB_t Q931Tx32CBProc, + Q931ErrorCB_t Q931ErrorCBProc, + void *PrivateData) { int y, dchannel, maxchans, has_sync = 0; @@ -95,6 +102,11 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUs return 0; } + pTrunk->Q931Tx34CBProc = Q931Tx34CBProc; + pTrunk->Q931Tx32CBProc = Q931Tx32CBProc; + pTrunk->Q931ErrorCBProc = Q931ErrorCBProc; + pTrunk->PrivateData = PrivateData; + pTrunk->LastCRV = 0; pTrunk->Dialect = Dialect; pTrunk->Enabled = 0; diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 6ed40d9a90..314464d69c 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -2,13 +2,7 @@ FileName: q921.h - Description: Contains headers of a Q.921 protocol on top of the Comet - Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. + 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. @@ -19,7 +13,7 @@ - One driver layer. The interface layer contains the interface functions required - for a layer 3 stack to be able to send and receive messages. + 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. @@ -33,7 +27,8 @@ Q921Rx32 Receive message from layer 3. Called by the layer 3 stack to send a message. - Q921Tx23 Send a message to layer 3. + + NOTE: The following are not yet implemented OnQ921Error Function called every if an error is deteceted. @@ -42,6 +37,10 @@ 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 @@ -80,31 +79,10 @@ #ifndef _Q921 #define _Q921 -#define Q921MAXTRUNK 4 #define Q921MAXHDLCSPACE 3000 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit - or larger. - -*****************************************************************************/ - #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ - -#ifdef Q921_HANDLE_STATIC -#define L2TRUNK long -#define L2TRUNKHANDLE(trunk) Q921DevSpace[trunk] -#else -#define L2TRUNK Q921Data * -#define L2TRUNKHANDLE(trunk) (*trunk) -#endif +#define L2TRUNK Q921Data_t * typedef enum /* Network/User Mode. */ { @@ -112,8 +90,11 @@ typedef enum /* Network/User Mode. */ Q921_NT=1 /* 1 : Network Mode */ } Q921NetUser_t; +typedef struct Q921Data Q921Data_t; +typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); + #define INITIALIZED_MAGIC 42 -typedef struct +struct Q921Data { L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2INT initialized; @@ -123,15 +104,22 @@ typedef struct L2UCHAR sapi; L2UCHAR tei; Q921NetUser_t NetUser; + Q921TxCB_t Q921Tx21Proc; + Q921TxCB_t Q921Tx23Proc; + void *PrivateData; + L2INT Q921HeaderSpace; -}Q921Data; +}; -void Q921Init(); -void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); -void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size); +void Q921_InitTrunk(L2TRUNK trunk, + L2UCHAR sapi, + L2UCHAR tei, + Q921NetUser_t NetUser, + L2INT hsize, + Q921TxCB_t cb21, + Q921TxCB_t cb23, + void *priv); +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); #endif diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 1fc31190c8..b546858e07 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1,2429 +1,2445 @@ -/****************************************************************************** - - 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) -#endif - -/***************************************************************************** - - Error Codes - -*****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have 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 - -/***************************************************************************** - - 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 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. */ - -/***************************************************************************** - - 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 schoose 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 2 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ - - -#define Q931MAXMES 255 /* Number of messages */ - -#define Q931MAXIE 255 /* Number of IE */ - -#define Q931MAXSTATE 100 /* Size of state tables */ - -/***************************************************************************** - - 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 0x7a /* 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 */ - - -/* Single octet information elements */ -#define Q931ie_SHIFT 0x90 /* 1001 ---- */ -#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; - -/***************************************************************************** - - 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 */ - 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 */ - L3INT CRV; /* Call reference value */ - - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; - - ie Segment; /* Segmented message */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie CallID; /* Call Identity */ - ie ChanID; /* Channel Identification */ - 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 RestartInd; /* Restart Indicator */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High Layer Compatibility */ - ie UserUser; /* User-user */ - ie Escape; /* Escape for extension */ - L3UCHAR buf[1]; /* Buffer for IE's */ - -}Q931mes_Generic; - -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; - -/***************************************************************************** - - Struct: Q931_TrunkInfo - - Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated - channels in the system. - - The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. - -*****************************************************************************/ - -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_Count -} 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_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; - -typedef struct -{ - Q931NetUser_t NetUser; /* Network/User Mode. */ - - Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ - - Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ - - 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 send 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. */ - - /* 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 _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - -}Q931_TrunkInfo; - -/***************************************************************************** - - 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 define it's own state table and the logic only need - to 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. - -*****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -/***************************************************************************** - - 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) (&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. - -*****************************************************************************/ - -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; - -#include "Q932.h" - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - -/***************************************************************************** - - Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); - -/***************************************************************************** - - Q.931 Process Function Prototyping. Implemented in Q931StateTE.c - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -/***************************************************************************** - - Interface Function Prototypes. Implemented in Q931.c - -*****************************************************************************/ -void Q931TimeTick(L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); -void Q931CreateTE(L3UCHAR i); -void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); -void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); -void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); - -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); - -void Q931Initialize(); -void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); - -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); -L3ULONG Q931GetTime(); -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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); - -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType); - -#endif /* _Q931_NL */ +/****************************************************************************** + + 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) +#endif + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + 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 */ + L3INT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ +typedef struct Q931_TrunkInfo Q931_TrunkInfo; + +typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT); +typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,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_Count +} 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_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_TrunkInfo +{ + Q931NetUser_t NetUser; /* Network/User Mode. */ + + Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ + + Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ + + Q931TxCB_t Q931Tx34CBProc; + Q931TxCB_t Q931Tx32CBProc; + Q931ErrorCB_t Q931ErrorCBProc; + void *PrivateData; + + 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 send 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. */ + + /* 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *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 Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, + Q931Dialect_t Dialect, + Q931NetUser_t NetUser, + Q931_TrunkType_t TrunkType, + Q931TxCB_t Q931Tx34CBProc, + Q931TxCB_t Q931Tx32CBProc, + Q931ErrorCB_t Q931ErrorCBProc, + void *PrivateData); + +#endif /* _Q931_NL */ From 598d8df49a66d2055d15fd6b5045780598920695 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 08:03:20 +0000 Subject: [PATCH 0192/1766] rework 921/931 api. Move the Tx callbacks on each to be trunk specific, not global so that we can set them per trunk. Change prototypes for the Tx callbacks so that they pass a trunk specific private pointer to the Tx callbacks so that 921 and 931 can call each other directly. change 921 so that it doesn't use a static array for it's trunk structure to match 931 use more enums. more to come.... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@96 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 189 +- libs/freetdm/src/isdn/Q931.c | 43 +- libs/freetdm/src/isdn/Q931api.c | 14 +- libs/freetdm/src/isdn/include/Q921.h | 66 +- libs/freetdm/src/isdn/include/Q931.h | 4874 +++++++++++++------------- 5 files changed, 2580 insertions(+), 2606 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 65e0d06fa0..d0a0bce29e 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -2,13 +2,7 @@ FileName: q921.c - Description: Contains the implementation of a Q.921 protocol on top of the - Comet Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. + Description: Contains the implementation of a Q.921 protocol Created: 27.dec.2000/JVB @@ -47,75 +41,48 @@ #include #include "mfifo.h" -/***************************************************************************** - Global Tables & Variables. -*****************************************************************************/ -#ifdef Q921_HANDLE_STATIC -Q921Data Q921DevSpace[Q921MAXTRUNK]; -#endif - -int Q921HeaderSpace={0}; - -int (*Q921Tx21Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; -int (*Q921Tx23Proc)(L2TRUNK dev, L2UCHAR *, int)={NULL}; - -/***************************************************************************** - - Function: Q921Init - - Decription: Initialize the Q.921 stack so it is ready for use. This - function MUST be called as part of initializing the - application. - -*****************************************************************************/ -void Q921Init() -{ -#ifdef Q921_HANDLE_STATIC - int x; - for(x=0; xinitialized != INITIALIZED_MAGIC) { + MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); + trunk->initialized = INITIALIZED_MAGIC; } - L2TRUNKHANDLE(trunk).vr = 0; - L2TRUNKHANDLE(trunk).vs = 0; - L2TRUNKHANDLE(trunk).state = 0; - L2TRUNKHANDLE(trunk).sapi = sapi; - L2TRUNKHANDLE(trunk).tei = tei; - L2TRUNKHANDLE(trunk).NetUser = NetUser; + trunk->vr = 0; + trunk->vs = 0; + trunk->state = 0; + trunk->sapi = sapi; + trunk->tei = tei; + trunk->NetUser = NetUser; + trunk->Q921Tx21Proc = cb21; + trunk->Q921Tx23Proc = cb23; + trunk->PrivateData = priv; + trunk->Q921HeaderSpace = hsize; } -void Q921SetHeaderSpace(int hspace) +static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - Q921HeaderSpace=hspace; + return trunk->Q921Tx21Proc(trunk->PrivateData, Msg, size); } -void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) +int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - Q921Tx21Proc = callback; -} + return trunk->Q921Tx23Proc(trunk->PrivateData, Msg, size); -void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) -{ - Q921Tx23Proc = callback; } /***************************************************************************** @@ -137,9 +104,9 @@ void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)) size size of frame in bytes *****************************************************************************/ -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size) { - return MFIFOWriteMes(L2TRUNKHANDLE(trunk).HDLCInQueue, b, size); + return MFIFOWriteMes(trunk->HDLCInQueue, b, size); } /***************************************************************************** @@ -161,13 +128,13 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, int size) +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size) { - mes[Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[Q921HeaderSpace+2] = L2TRUNKHANDLE(trunk).vs<<1; - mes[Q921HeaderSpace+3] = (L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01); - L2TRUNKHANDLE(trunk).vs++; + mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); + mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; + mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; + mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); + trunk->vs++; return Q921Tx21Proc(trunk, mes, size); } @@ -175,9 +142,9 @@ int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHA int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) { return Q921SendI(trunk, - L2TRUNKHANDLE(trunk).sapi, - L2TRUNKHANDLE(trunk).NetUser == Q921_TE ? 0 : 1, - L2TRUNKHANDLE(trunk).tei, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, 0, Mes, Size); @@ -202,12 +169,12 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -229,12 +196,12 @@ int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -256,12 +223,12 @@ int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[Q921HeaderSpace+3] = (L2UCHAR)((L2TRUNKHANDLE(trunk).vr<<1) | (pf & 0x01)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+4); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -283,11 +250,11 @@ int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -309,11 +276,11 @@ int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -335,11 +302,11 @@ int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -361,21 +328,21 @@ int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { L2UCHAR mes[400]; - mes[Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); - return Q921Tx21Proc(trunk, mes, Q921HeaderSpace+3); + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) { /* TODO: Do we need these paramaters? */ (void)mes; (void)size; - L2TRUNKHANDLE(trunk).vr=0; - L2TRUNKHANDLE(trunk).vs=0; + trunk->vr=0; + trunk->vs=0; return 1; } @@ -401,18 +368,18 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, int size) int Q921Rx12(L2TRUNK trunk) { L2UCHAR *mes; - int rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(L2TRUNKHANDLE(trunk).HDLCInQueue, &size); + L2INT rs,size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); if(smes != NULL) { - rs = size - Q921HeaderSpace; - mes = &smes[Q921HeaderSpace]; + rs = size - trunk->Q921HeaderSpace; + mes = &smes[trunk->Q921HeaderSpace]; /* check for I frame */ if((mes[2] & 0x01) == 0) { if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ { - L2TRUNKHANDLE(trunk).vr++; + trunk->vr++; Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); } else @@ -451,7 +418,7 @@ int Q921Rx12(L2TRUNK trunk) /* todo: REJ or FRMR */ } - MFIFOKillNext(L2TRUNKHANDLE(trunk).HDLCInQueue); + MFIFOKillNext(trunk->HDLCInQueue); return 1; } diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 09cbaf0b76..9bf16f2c78 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -88,15 +88,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ *****************************************************************************/ -L3INT (*Q931Tx34Proc)(Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - /* callback for messages to be send to */ - /* layer 4. */ - -L3INT (*Q931Tx32Proc)(Q931_TrunkInfo *pTrunk,L3UCHAR *,L3INT); - /* callback ptr for messages to be send */ - /* to layer 2. */ - -L3INT (*Q931ErrorProc)(Q931_TrunkInfo *pTrunk, L3INT,L3INT,L3INT); +Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ @@ -210,7 +202,7 @@ L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) Description: Dummy function for error processing *****************************************************************************/ -L3INT Q931ErrorDummy(Q931_TrunkInfo *pTrunk,L3INT a, L3INT b, L3INT c) +L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) { return 0; } @@ -235,8 +227,6 @@ void Q931Initialize() L3INT x,y; /* Secure the callbacks to default procs */ - Q931Tx34Proc = Q931TxDummy; - Q931Tx32Proc = Q931TxDummy; Q931ErrorProc = Q931ErrorDummy; /* The user will only add the message handlers and IE handlers he need, */ @@ -360,7 +350,10 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) *****************************************************************************/ L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) { - return Q931Tx34Proc(pTrunk, Mes, Size); + if (pTrunk->Q931Tx34CBProc) { + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData, Mes, Size); + } + return Q931E_MISSING_CB; } /***************************************************************************** @@ -415,7 +408,11 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); if(RetCode >= Q931E_NO_ERROR) { - RetCode = Q931Tx32Proc(pTrunk, pTrunk->L2Buf, Size); + if (pTrunk->Q931Tx32CBProc) { + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData, pTrunk->L2Buf, Size); + } else { + RetCode = Q931E_MISSING_CB; + } } return RetCode; @@ -436,20 +433,14 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) *****************************************************************************/ void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) { - Q931ErrorProc(pTrunk,ErrID, ErrPar1, ErrPar2); + if (pTrunk->Q931ErrorCBProc) { + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + } else { + Q931ErrorProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + } } -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx34Proc = Q931Tx34Par; -} - -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)) -{ - Q931Tx32Proc = Q931Tx32Par; -} - -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)) +void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) { Q931ErrorProc = Q931ErrorPar; } diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index aea264efd6..8de8c717b6 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -68,7 +68,14 @@ L3INT Q931CreateIEIndex(L3INT iec) } */ -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType) +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, + Q931Dialect_t Dialect, + Q931NetUser_t NetUser, + Q931_TrunkType_t TrunkType, + Q931TxCB_t Q931Tx34CBProc, + Q931TxCB_t Q931Tx32CBProc, + Q931ErrorCB_t Q931ErrorCBProc, + void *PrivateData) { int y, dchannel, maxchans, has_sync = 0; @@ -95,6 +102,11 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUs return 0; } + pTrunk->Q931Tx34CBProc = Q931Tx34CBProc; + pTrunk->Q931Tx32CBProc = Q931Tx32CBProc; + pTrunk->Q931ErrorCBProc = Q931ErrorCBProc; + pTrunk->PrivateData = PrivateData; + pTrunk->LastCRV = 0; pTrunk->Dialect = Dialect; pTrunk->Enabled = 0; diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 6ed40d9a90..314464d69c 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -2,13 +2,7 @@ FileName: q921.h - Description: Contains headers of a Q.921 protocol on top of the Comet - Driver. - - Most of the work required to execute a Q.921 protocol is - taken care of by the Comet ship and it's driver. This layer - will simply configure and make use of these features to - complete a Q.921 implementation. + 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. @@ -19,7 +13,7 @@ - One driver layer. The interface layer contains the interface functions required - for a layer 3 stack to be able to send and receive messages. + 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. @@ -33,7 +27,8 @@ Q921Rx32 Receive message from layer 3. Called by the layer 3 stack to send a message. - Q921Tx23 Send a message to layer 3. + + NOTE: The following are not yet implemented OnQ921Error Function called every if an error is deteceted. @@ -42,6 +37,10 @@ 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 @@ -80,31 +79,10 @@ #ifndef _Q921 #define _Q921 -#define Q921MAXTRUNK 4 #define Q921MAXHDLCSPACE 3000 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit - or larger. - -*****************************************************************************/ - #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ - -#ifdef Q921_HANDLE_STATIC -#define L2TRUNK long -#define L2TRUNKHANDLE(trunk) Q921DevSpace[trunk] -#else -#define L2TRUNK Q921Data * -#define L2TRUNKHANDLE(trunk) (*trunk) -#endif +#define L2TRUNK Q921Data_t * typedef enum /* Network/User Mode. */ { @@ -112,8 +90,11 @@ typedef enum /* Network/User Mode. */ Q921_NT=1 /* 1 : Network Mode */ } Q921NetUser_t; +typedef struct Q921Data Q921Data_t; +typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); + #define INITIALIZED_MAGIC 42 -typedef struct +struct Q921Data { L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2INT initialized; @@ -123,15 +104,22 @@ typedef struct L2UCHAR sapi; L2UCHAR tei; Q921NetUser_t NetUser; + Q921TxCB_t Q921Tx21Proc; + Q921TxCB_t Q921Tx23Proc; + void *PrivateData; + L2INT Q921HeaderSpace; -}Q921Data; +}; -void Q921Init(); -void Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser); -void Q921SetHeaderSpace(int hspace); -void Q921SetTx21CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); -void Q921SetTx23CB(int (*callback)(L2TRUNK dev, L2UCHAR *, int)); -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, int size); +void Q921_InitTrunk(L2TRUNK trunk, + L2UCHAR sapi, + L2UCHAR tei, + Q921NetUser_t NetUser, + L2INT hsize, + Q921TxCB_t cb21, + Q921TxCB_t cb23, + void *priv); +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); #endif diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 1fc31190c8..b546858e07 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1,2429 +1,2445 @@ -/****************************************************************************** - - 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) -#endif - -/***************************************************************************** - - Error Codes - -*****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 - -/***************************************************************************** - - Some speed optimization can be achieved by changing all variables to the - word size of your processor. A 32 bit processor have to do a lot of extra - work to read a packed 8 bit integer. Changing all fields to 32 bit integer - will ressult in usage of some extra space, but speed up the stack. - - The stack have 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 - -/***************************************************************************** - - 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 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. */ - -/***************************************************************************** - - 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 schoose 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 2 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ - - -#define Q931MAXMES 255 /* Number of messages */ - -#define Q931MAXIE 255 /* Number of IE */ - -#define Q931MAXSTATE 100 /* Size of state tables */ - -/***************************************************************************** - - 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 0x7a /* 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 */ - - -/* Single octet information elements */ -#define Q931ie_SHIFT 0x90 /* 1001 ---- */ -#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; - -/***************************************************************************** - - 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 */ - 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 */ - L3INT CRV; /* Call reference value */ - - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; - - ie Segment; /* Segmented message */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie CallID; /* Call Identity */ - ie ChanID; /* Channel Identification */ - 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 RestartInd; /* Restart Indicator */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High Layer Compatibility */ - ie UserUser; /* User-user */ - ie Escape; /* Escape for extension */ - L3UCHAR buf[1]; /* Buffer for IE's */ - -}Q931mes_Generic; - -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; - -/***************************************************************************** - - Struct: Q931_TrunkInfo - - Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated - channels in the system. - - The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. - -*****************************************************************************/ - -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_Count -} 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_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; - -typedef struct -{ - Q931NetUser_t NetUser; /* Network/User Mode. */ - - Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ - - Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ - - 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 send 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. */ - - /* 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 _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - -}Q931_TrunkInfo; - -/***************************************************************************** - - 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 define it's own state table and the logic only need - to 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. - -*****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); - -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -/***************************************************************************** - - 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) (&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. - -*****************************************************************************/ - -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; - -#include "Q932.h" - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - -/***************************************************************************** - - Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c - -*****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); - -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); - -/***************************************************************************** - - Q.931 Process Function Prototyping. Implemented in Q931StateTE.c - -*****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); - -/***************************************************************************** - - Interface Function Prototypes. Implemented in Q931.c - -*****************************************************************************/ -void Q931TimeTick(L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); -void Q931SetTx34CB(L3INT (*Q931Tx34Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetTx32CB(L3INT (*Q931Tx32Par)(Q931_TrunkInfo *pTrunk,L3UCHAR * Mes, L3INT Size)); -void Q931SetErrorCB(L3INT (*Q931ErrorPar)(Q931_TrunkInfo *pTrunk,L3INT,L3INT,L3INT)); -void Q931CreateTE(L3UCHAR i); -void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); -void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); -void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); - -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); - -void Q931Initialize(); -void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); - -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); -L3ULONG Q931GetTime(); -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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); - -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType); - -#endif /* _Q931_NL */ +/****************************************************************************** + + 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) +#endif + +/***************************************************************************** + + Error Codes + +*****************************************************************************/ +#define Q931E_NO_ERROR 0 +#define Q931E_UNKNOWN_MESSAGE -3001 +#define Q931E_ILLEGAL_IE -3002 +#define Q931E_UNKNOWN_IE -3003 +#define Q931E_BEARERCAP -3004 +#define Q931E_HLCOMP -3005 +#define Q931E_LLCOMP -3006 +#define Q931E_INTERNAL -3007 +#define Q931E_MISSING_CB -3008 +#define Q931E_UNEXPECTED_MESSAGE -3009 +#define Q931E_ILLEGAL_MESSAGE -3010 +#define Q931E_TOMANYCALLS -3011 +#define Q931E_INVALID_CRV -3012 +#define Q931E_CALLID -3013 +#define Q931E_CALLSTATE -3014 +#define Q931E_CALLEDSUB -3015 +#define Q931E_CALLEDNUM -3016 +#define Q931E_CALLINGNUM -3017 +#define Q931E_CALLINGSUB -3018 +#define Q931E_CAUSE -3019 +#define Q931E_CHANID -3020 +#define Q931E_DATETIME -3021 +#define Q931E_DISPLAY -3022 +#define Q931E_KEYPADFAC -3023 +#define Q931E_NETFAC -3024 +#define Q931E_NOTIFIND -3025 +#define Q931E_PROGIND -3026 +#define Q931E_RESTARTIND -3027 +#define Q931E_SEGMENT -3028 +#define Q931E_SIGNAL -3029 + +/***************************************************************************** + + Some speed optimization can be achieved by changing all variables to the + word size of your processor. A 32 bit processor have to do a lot of extra + work to read a packed 8 bit integer. Changing all fields to 32 bit integer + will ressult in usage of some extra space, but speed up the stack. + + The stack have 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 + +/***************************************************************************** + + 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 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. */ + +/***************************************************************************** + + 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 schoose 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 2 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ + + +#define Q931MAXMES 255 /* Number of messages */ + +#define Q931MAXIE 255 /* Number of IE */ + +#define Q931MAXSTATE 100 /* Size of state tables */ + +/***************************************************************************** + + 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 0x7a /* 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 */ + + +/* Single octet information elements */ +#define Q931ie_SHIFT 0x90 /* 1001 ---- */ +#define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#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_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 */ + +/***************************************************************************** + + 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 indicate error */ + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + +/***************************************************************************** + + 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 */ + 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 */ + L3INT CRV; /* Call reference value */ + + ie Shift; + ie MoreData; + ie SendComplete; + ie CongestionLevel; + ie RepeatInd; + + ie Segment; /* Segmented message */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie CallID; /* Call Identity */ + ie ChanID; /* Channel Identification */ + 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 RestartInd; /* Restart Indicator */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High Layer Compatibility */ + ie UserUser; /* User-user */ + ie Escape; /* Escape for extension */ + L3UCHAR buf[1]; /* Buffer for IE's */ + +}Q931mes_Generic; + +/***************************************************************************** + + Struct: Q931mes_Alerting + + Description: This message is send by the called party to indicate that + the phone is ringing. + + The message consist of an header that MUST be identical with + Q931mes_Header, a fixed number of IE flags w/offset, and + a dynamic buffer storing normalized IE's. + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Alerting; + +/***************************************************************************** + + Struct: Q931mes_CallProceeding + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CallProceeding; + +/***************************************************************************** + + Struct: Q931mes_Connect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel Identification */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie Signal; /* Signal */ + ie LLComp; /* Low Layer Compatibility */ + ie HLComp; /* High layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Connect; + +/***************************************************************************** + + Struct: Q931mes_ConnectAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ConnectAck; + +/***************************************************************************** + + Struct: Q931mes_Disconnect + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User - user. Packed Mode. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Disconnect; + +/***************************************************************************** + + Struct: Q931mes_Information + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie Display; /* Display */ + ie KeypadFac; /* Keypad facility */ + ie Signal; /* Signal */ + ie CalledNum; /* Called party number */ +#ifdef Q931_X25_SUPPORT + ie Cause; /* Cause (packed only) */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Information; + +/***************************************************************************** + + Struct: Q931mes_Notify + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie NotifInd; /* Notification Indicator */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Notify; + +/***************************************************************************** + + Struct: Q931mes_Progress + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie BearerCap; /* Bearer Capability */ + ie Cause; /* Cause */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie HLComp; /* High Layer Compatibility */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Progress; + +/***************************************************************************** + + Struct: Q931mes_Release + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Release; + +/***************************************************************************** + + Struct: Q931mes_ReleaseComplete + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + ie Signal; /* Signal */ +#ifdef Q931_X25_SUPPORT + ie UserUser; /* User-User packed mode */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ReleaseComplete; + +/***************************************************************************** + + Struct: Q931mes_Resume + +*****************************************************************************/ +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; +}Q931mes_Resume; + +/***************************************************************************** + + Struct: Q931mes_ResumeAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeAck; + +/***************************************************************************** + + Struct: Q931mes_ResumeReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_ResumeReject; + +/***************************************************************************** + + Struct: Q931mes_Segment + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Segment; + +/***************************************************************************** + + Struct: Q931mes_Setup + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie SendComplete; /* Sending Complete */ + ie RepeatInd; /* Repeat Indicator */ + ie BearerCap; /* Bearer Capability */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie NetFac; /* Network-specific facilities */ + /* Note: Up to 4 NetFac's may be */ + /* included. */ + ie Display; /* Display */ + ie DateTime; /* Date/Time */ + ie KeypadFac; /* Keypad Facility */ + ie Signal; /* Signal */ + ie CallingNum; /* Calling party number */ + ie CallingSub; /* Calling party sub address */ + ie CalledNum; /* Called party number */ + ie CalledSub; /* Called party sub address */ + ie TransNetSel; /* Transit network selection */ + ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ + ie LLComp; /* Low layer compatibility */ + ie HLComp; /* High layer compatibility */ + +#ifdef Q931_X25_SUPPORT + /* Packed mode additions */ + ie IndoRate; /* Information Rate */ + ie EndEndDelay; /* End-end transit delay */ + ie TransDelayInd; /* TRansit delay selection and ind. */ + ie PackParam; /* Packed layer binary parameters */ + ie PackWinSize; /* Packed layer window size */ + ie PackSize; /* Packet Size */ + ie ClosedUserGrp; /* Closed User Group */ + ie RevChargInd; /* Reverse charhing indicator */ + ie RedirNum; /* Redirection number */ + ie UserUser; /* User-user. */ +#endif + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Setup; + +/***************************************************************************** + + Struct: Q931mes_SetupAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel ID */ + ie ProgInd; /* Progress Indicator */ + ie Display; /* Display */ + ie Signal; /* Signal */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SetupAck; + +/***************************************************************************** + + Struct: Q931mes_Status + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie CallState; /* Call State */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Status; + +/***************************************************************************** + + Struct: Q931mes_StatusEnquire + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_StatusEnquiry; + +/***************************************************************************** + + Struct: Q931mes_Suspend + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CallID; /* Call Identity */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Suspend; + +/***************************************************************************** + + Struct: Q931mes_SuspendAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendAck; + +/***************************************************************************** + + Struct: Q931mes_SuspendReject + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_SuspendReject; + +/***************************************************************************** + + Struct: Q931mes_CongestionControl + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie CongLevel; /* Congestion level */ + ie Cause; /* Cause */ + ie Display; /* Display */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_CongestionControl; + +/***************************************************************************** + + Struct: Q931mes_UserInformation + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie MoreData; /* More data */ + ie UserUser; /* User-user */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_UserInformation; + +/***************************************************************************** + + Struct: Q931mes_Restart + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartInd; /* Restart indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_Restart; + +/***************************************************************************** + + Struct: Q931mes_RestartAck + +*****************************************************************************/ + +typedef struct +{ + L3UINT Size; /* Size of message in bytes */ + L3UCHAR ProtDisc; /* Protocol Discriminator */ + L3UCHAR MesType; /* Message type */ + L3INT CRV; /* Call reference value */ + ie ChanID; /* Channel identification */ + ie Display; /* Display */ + ie RestartWin; /* Restart Window */ + ie RestartInd; /* Restart Indicator */ + L3UCHAR buf[1]; /* Dynamic buffer */ +}Q931mes_RestartAck; + +/***************************************************************************** + + Struct: Q931_TrunkInfo + + Description: TrunkInfo is the struct entry used to store Q.931 related + information and state for E1/T1/J1 trunks and assosiated + channels in the system. + + The user should store this information outside this stack + and need to feed the interface functions with a pointer to + the trunk Info entry. + +*****************************************************************************/ +typedef struct Q931_TrunkInfo Q931_TrunkInfo; + +typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT); +typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,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_Count +} 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_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_TrunkInfo +{ + Q931NetUser_t NetUser; /* Network/User Mode. */ + + Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ + + Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ + + Q931TxCB_t Q931Tx34CBProc; + Q931TxCB_t Q931Tx32CBProc; + Q931ErrorCB_t Q931ErrorCBProc; + void *PrivateData; + + 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 send 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. */ + + /* 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 _ccarray + { + L3UCHAR InUse; /* Indicate if entry is in use. */ + /* 0 = Not in Use */ + /* 1 = Active Call. */ + + 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 */ + + }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 define it's own state table and the logic only need + to 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. + +*****************************************************************************/ +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); + +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +/***************************************************************************** + + 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) (&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. + +*****************************************************************************/ + +extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; + +#include "Q932.h" + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c + +*****************************************************************************/ +L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); + +/***************************************************************************** + + Q.931 Process Function Prototyping. Implemented in Q931StateTE.c + +*****************************************************************************/ +L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); + +/***************************************************************************** + + Interface Function Prototypes. Implemented in Q931.c + +*****************************************************************************/ +void Q931TimeTick(L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); +void Q931SetError(Q931_TrunkInfo *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 Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); +void Q931SetHeaderSpace(L3INT space); +void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, + L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + +void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, + L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + +void Q931Initialize(); +void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); +L3INT Q931InitMesSetup(Q931mes_Setup *p); + +L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); +L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); +L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); +L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); +L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); +L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); +L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3ULONG Q931GetTime(); +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 *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 *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); + +L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, + Q931Dialect_t Dialect, + Q931NetUser_t NetUser, + Q931_TrunkType_t TrunkType, + Q931TxCB_t Q931Tx34CBProc, + Q931TxCB_t Q931Tx32CBProc, + Q931ErrorCB_t Q931ErrorCBProc, + void *PrivateData); + +#endif /* _Q931_NL */ From 50aba550c9c6a1a2a6a0b69e3c62506498466012 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 16:27:40 +0000 Subject: [PATCH 0193/1766] add separate private data for tx to 1 and 3. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@97 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 10 ++++++---- libs/openzap/src/isdn/include/Q921.h | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index d0a0bce29e..9eab78b99e 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -56,7 +56,8 @@ void Q921_InitTrunk(L2TRUNK trunk, L2INT hsize, Q921TxCB_t cb21, Q921TxCB_t cb23, - void *priv) + void *priv21, + void *priv23) { if (trunk->initialized != INITIALIZED_MAGIC) { MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); @@ -70,18 +71,19 @@ void Q921_InitTrunk(L2TRUNK trunk, trunk->NetUser = NetUser; trunk->Q921Tx21Proc = cb21; trunk->Q921Tx23Proc = cb23; - trunk->PrivateData = priv; + trunk->PrivateData21 = priv21; + trunk->PrivateData23 = priv23; trunk->Q921HeaderSpace = hsize; } static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - return trunk->Q921Tx21Proc(trunk->PrivateData, Msg, size); + return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); } int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - return trunk->Q921Tx23Proc(trunk->PrivateData, Msg, size); + return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); } diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 314464d69c..9338a49c99 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -106,7 +106,8 @@ struct Q921Data Q921NetUser_t NetUser; Q921TxCB_t Q921Tx21Proc; Q921TxCB_t Q921Tx23Proc; - void *PrivateData; + void *PrivateData21; + void *PrivateData23; L2INT Q921HeaderSpace; }; @@ -118,7 +119,8 @@ void Q921_InitTrunk(L2TRUNK trunk, L2INT hsize, Q921TxCB_t cb21, Q921TxCB_t cb23, - void *priv); + void *priv21, + void *priv23); int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); From 29d460e72504faf63eab39e22556ec11f49f9ea8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 16:27:40 +0000 Subject: [PATCH 0194/1766] add separate private data for tx to 1 and 3. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@97 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 10 ++++++---- libs/freetdm/src/isdn/include/Q921.h | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index d0a0bce29e..9eab78b99e 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -56,7 +56,8 @@ void Q921_InitTrunk(L2TRUNK trunk, L2INT hsize, Q921TxCB_t cb21, Q921TxCB_t cb23, - void *priv) + void *priv21, + void *priv23) { if (trunk->initialized != INITIALIZED_MAGIC) { MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); @@ -70,18 +71,19 @@ void Q921_InitTrunk(L2TRUNK trunk, trunk->NetUser = NetUser; trunk->Q921Tx21Proc = cb21; trunk->Q921Tx23Proc = cb23; - trunk->PrivateData = priv; + trunk->PrivateData21 = priv21; + trunk->PrivateData23 = priv23; trunk->Q921HeaderSpace = hsize; } static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - return trunk->Q921Tx21Proc(trunk->PrivateData, Msg, size); + return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); } int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { - return trunk->Q921Tx23Proc(trunk->PrivateData, Msg, size); + return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); } diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 314464d69c..9338a49c99 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -106,7 +106,8 @@ struct Q921Data Q921NetUser_t NetUser; Q921TxCB_t Q921Tx21Proc; Q921TxCB_t Q921Tx23Proc; - void *PrivateData; + void *PrivateData21; + void *PrivateData23; L2INT Q921HeaderSpace; }; @@ -118,7 +119,8 @@ void Q921_InitTrunk(L2TRUNK trunk, L2INT hsize, Q921TxCB_t cb21, Q921TxCB_t cb23, - void *priv); + void *priv21, + void *priv23); int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); From b06d0d2589f38f07255d0099cd64167673811c13 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 16:33:13 +0000 Subject: [PATCH 0195/1766] add separate private data for tx to 2 and 4. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@98 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 8 ++++---- libs/openzap/src/isdn/Q931api.c | 6 ++++-- libs/openzap/src/isdn/include/Q931.h | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 9bf16f2c78..3d76b23051 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -351,7 +351,7 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) { if (pTrunk->Q931Tx34CBProc) { - return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData, Mes, Size); + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); } return Q931E_MISSING_CB; } @@ -409,7 +409,7 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) if(RetCode >= Q931E_NO_ERROR) { if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData, pTrunk->L2Buf, Size); + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, Size); } else { RetCode = Q931E_MISSING_CB; } @@ -434,9 +434,9 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) { if (pTrunk->Q931ErrorCBProc) { - pTrunk->Q931ErrorCBProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); } else { - Q931ErrorProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); } } diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 8de8c717b6..95ce6620a4 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -75,7 +75,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931TxCB_t Q931Tx34CBProc, Q931TxCB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, - void *PrivateData) + void *PrivateData32, + void *PrivateData34) { int y, dchannel, maxchans, has_sync = 0; @@ -105,7 +106,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, pTrunk->Q931Tx34CBProc = Q931Tx34CBProc; pTrunk->Q931Tx32CBProc = Q931Tx32CBProc; pTrunk->Q931ErrorCBProc = Q931ErrorCBProc; - pTrunk->PrivateData = PrivateData; + pTrunk->PrivateData32 = PrivateData32; + pTrunk->PrivateData34 = PrivateData34; pTrunk->LastCRV = 0; pTrunk->Dialect = Dialect; diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index b546858e07..00c54a4ad5 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1968,7 +1968,8 @@ struct Q931_TrunkInfo Q931TxCB_t Q931Tx34CBProc; Q931TxCB_t Q931Tx32CBProc; Q931ErrorCB_t Q931ErrorCBProc; - void *PrivateData; + void *PrivateData32; + void *PrivateData34; L3UCHAR Enabled; /* Enabled/Disabled */ /* 0 = Disabled */ @@ -2440,6 +2441,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931TxCB_t Q931Tx34CBProc, Q931TxCB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, - void *PrivateData); + void *PrivateData32, + void *PrivateData34); #endif /* _Q931_NL */ From 33f9f436aa55c493f01955ee03bd68481ccb61f8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 16:33:13 +0000 Subject: [PATCH 0196/1766] add separate private data for tx to 2 and 4. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@98 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 8 ++++---- libs/freetdm/src/isdn/Q931api.c | 6 ++++-- libs/freetdm/src/isdn/include/Q931.h | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 9bf16f2c78..3d76b23051 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -351,7 +351,7 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) { if (pTrunk->Q931Tx34CBProc) { - return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData, Mes, Size); + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); } return Q931E_MISSING_CB; } @@ -409,7 +409,7 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) if(RetCode >= Q931E_NO_ERROR) { if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData, pTrunk->L2Buf, Size); + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, Size); } else { RetCode = Q931E_MISSING_CB; } @@ -434,9 +434,9 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) { if (pTrunk->Q931ErrorCBProc) { - pTrunk->Q931ErrorCBProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); } else { - Q931ErrorProc(pTrunk->PrivateData, ErrID, ErrPar1, ErrPar2); + Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); } } diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 8de8c717b6..95ce6620a4 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -75,7 +75,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931TxCB_t Q931Tx34CBProc, Q931TxCB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, - void *PrivateData) + void *PrivateData32, + void *PrivateData34) { int y, dchannel, maxchans, has_sync = 0; @@ -105,7 +106,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, pTrunk->Q931Tx34CBProc = Q931Tx34CBProc; pTrunk->Q931Tx32CBProc = Q931Tx32CBProc; pTrunk->Q931ErrorCBProc = Q931ErrorCBProc; - pTrunk->PrivateData = PrivateData; + pTrunk->PrivateData32 = PrivateData32; + pTrunk->PrivateData34 = PrivateData34; pTrunk->LastCRV = 0; pTrunk->Dialect = Dialect; diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index b546858e07..00c54a4ad5 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1968,7 +1968,8 @@ struct Q931_TrunkInfo Q931TxCB_t Q931Tx34CBProc; Q931TxCB_t Q931Tx32CBProc; Q931ErrorCB_t Q931ErrorCBProc; - void *PrivateData; + void *PrivateData32; + void *PrivateData34; L3UCHAR Enabled; /* Enabled/Disabled */ /* 0 = Disabled */ @@ -2440,6 +2441,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, Q931TxCB_t Q931Tx34CBProc, Q931TxCB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, - void *PrivateData); + void *PrivateData32, + void *PrivateData34); #endif /* _Q931_NL */ From 4b3113f56d93f27864147ca7601be85a9c6d5b7a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 17:17:32 +0000 Subject: [PATCH 0197/1766] correct initialization to set the right dialect. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@99 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 8 ++++---- libs/openzap/src/isdn/Q931api.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 3d76b23051..ab8fb9a841 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -247,11 +247,11 @@ void Q931Initialize() } } - if(Q931CreateDialectCB[0] == NULL) - Q931AddDialect(0, Q931CreateTE); + if(Q931CreateDialectCB[Q931_Dialect_Q931 + Q931_TE] == NULL) + Q931AddDialect(Q931_Dialect_Q931 + Q931_TE, Q931CreateTE); - if(Q931CreateDialectCB[1] == NULL) - Q931AddDialect(1, Q931CreateNT); + if(Q931CreateDialectCB[Q931_Dialect_Q931 + Q931_NT] == NULL) + Q931AddDialect(Q931_Dialect_Q931 + Q931_NT, Q931CreateNT); /* The last step we do is to call the callbacks to create the dialects */ for(x=0; x< Q931MAXDLCT; x++) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 95ce6620a4..780c29fb15 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -110,7 +110,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, pTrunk->PrivateData34 = PrivateData34; pTrunk->LastCRV = 0; - pTrunk->Dialect = Dialect; + pTrunk->Dialect = Dialect + NetUser; pTrunk->Enabled = 0; pTrunk->TrunkType = TrunkType; pTrunk->NetUser = NetUser; From b57d5390d3443be14cabf9dd6d2c16ae44f03a0b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 17:17:32 +0000 Subject: [PATCH 0198/1766] correct initialization to set the right dialect. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@99 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 8 ++++---- libs/freetdm/src/isdn/Q931api.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 3d76b23051..ab8fb9a841 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -247,11 +247,11 @@ void Q931Initialize() } } - if(Q931CreateDialectCB[0] == NULL) - Q931AddDialect(0, Q931CreateTE); + if(Q931CreateDialectCB[Q931_Dialect_Q931 + Q931_TE] == NULL) + Q931AddDialect(Q931_Dialect_Q931 + Q931_TE, Q931CreateTE); - if(Q931CreateDialectCB[1] == NULL) - Q931AddDialect(1, Q931CreateNT); + if(Q931CreateDialectCB[Q931_Dialect_Q931 + Q931_NT] == NULL) + Q931AddDialect(Q931_Dialect_Q931 + Q931_NT, Q931CreateNT); /* The last step we do is to call the callbacks to create the dialects */ for(x=0; x< Q931MAXDLCT; x++) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 95ce6620a4..780c29fb15 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -110,7 +110,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, pTrunk->PrivateData34 = PrivateData34; pTrunk->LastCRV = 0; - pTrunk->Dialect = Dialect; + pTrunk->Dialect = Dialect + NetUser; pTrunk->Enabled = 0; pTrunk->TrunkType = TrunkType; pTrunk->NetUser = NetUser; From b9d3b8636300ddb827f32c87b7bff32813625413 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 19:21:55 +0000 Subject: [PATCH 0199/1766] add Q921Start git-svn-id: http://svn.openzap.org/svn/openzap/trunk@100 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 9 +++++++++ libs/openzap/src/isdn/include/Q921.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 9eab78b99e..956a9e180c 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -259,6 +259,15 @@ int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } +int Q921Start(L2TRUNK trunk) +{ + return Q921SendSABME(trunk, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, + 0); +} + /***************************************************************************** Function: Q921SendDM diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 9338a49c99..4acdf8ece9 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -124,5 +124,6 @@ void Q921_InitTrunk(L2TRUNK trunk, int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); +int Q921Start(L2TRUNK trunk); #endif From 6be4a026fd92b9c1073e9d1b9481d81e24711817 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 19:21:55 +0000 Subject: [PATCH 0200/1766] add Q921Start git-svn-id: http://svn.openzap.org/svn/openzap/trunk@100 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 9 +++++++++ libs/freetdm/src/isdn/include/Q921.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 9eab78b99e..956a9e180c 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -259,6 +259,15 @@ int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); } +int Q921Start(L2TRUNK trunk) +{ + return Q921SendSABME(trunk, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, + 0); +} + /***************************************************************************** Function: Q921SendDM diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 9338a49c99..4acdf8ece9 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -124,5 +124,6 @@ void Q921_InitTrunk(L2TRUNK trunk, int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); +int Q921Start(L2TRUNK trunk); #endif From 2ffac0617811ecb3000200669e55d33a42a9719b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 19:22:09 +0000 Subject: [PATCH 0201/1766] change prototype git-svn-id: http://svn.openzap.org/svn/openzap/trunk@101 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 3 ++- libs/openzap/src/isdn/include/Q931.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index ab8fb9a841..1b0650f8e2 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -275,8 +275,9 @@ void Q931Initialize() Return Value: none *****************************************************************************/ -void Q931TimeTick(L3ULONG ms) +void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms) { + (void)pTrunk; ms=ms; /* avoid warning for now. */ /* TODO: Loop through all active calls, check timers and call timour procs diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 00c54a4ad5..3d9eee0338 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -2369,7 +2369,7 @@ L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) Interface Function Prototypes. Implemented in Q931.c *****************************************************************************/ -void Q931TimeTick(L3ULONG ms); +void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms); L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); From 2e097a54ef28b6214bbc66920fbaec48284a0160 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 19:22:09 +0000 Subject: [PATCH 0202/1766] change prototype git-svn-id: http://svn.openzap.org/svn/openzap/trunk@101 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 3 ++- libs/freetdm/src/isdn/include/Q931.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index ab8fb9a841..1b0650f8e2 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -275,8 +275,9 @@ void Q931Initialize() Return Value: none *****************************************************************************/ -void Q931TimeTick(L3ULONG ms) +void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms) { + (void)pTrunk; ms=ms; /* avoid warning for now. */ /* TODO: Loop through all active calls, check timers and call timour procs diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 00c54a4ad5..3d9eee0338 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -2369,7 +2369,7 @@ L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) Interface Function Prototypes. Implemented in Q931.c *****************************************************************************/ -void Q931TimeTick(L3ULONG ms); +void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms); L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); From 795f2f6d316a7184e1e5010d32f50479e71c7420 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 22 May 2007 22:07:05 +0000 Subject: [PATCH 0203/1766] w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@102 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 13 +- libs/openzap/src/include/openzap.h | 29 + libs/openzap/src/include/zap_isdn.h | 49 ++ libs/openzap/src/include/zap_types.h | 16 +- libs/openzap/src/isdn/Q921.c | 879 ++++++++++++++------------- libs/openzap/src/isdn/Q931.c | 57 +- libs/openzap/src/isdn/Q931StateNT.c | 66 +- libs/openzap/src/isdn/Q931StateTE.c | 66 +- libs/openzap/src/isdn/Q931api.c | 22 +- libs/openzap/src/isdn/Q931ie.c | 106 ++-- libs/openzap/src/isdn/Q931mes.c | 100 +-- libs/openzap/src/isdn/Q932mes.c | 32 +- libs/openzap/src/isdn/include/Q921.h | 258 ++++---- libs/openzap/src/isdn/include/Q931.h | 362 +++++------ libs/openzap/src/isdn/include/Q932.h | 64 +- libs/openzap/src/testapp.c | 2 +- libs/openzap/src/testisdn.c | 36 ++ libs/openzap/src/zap_analog.c | 34 ++ libs/openzap/src/zap_io.c | 73 ++- libs/openzap/src/zap_isdn.c | 205 +++++++ libs/openzap/src/zap_wanpipe.c | 3 + 21 files changed, 1458 insertions(+), 1014 deletions(-) create mode 100644 libs/openzap/src/include/zap_isdn.h create mode 100644 libs/openzap/src/testisdn.c create mode 100644 libs/openzap/src/zap_analog.c create mode 100644 libs/openzap/src/zap_isdn.c diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 3cb6bad5d2..8041ea3a7d 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -53,8 +53,9 @@ isdn/Q931StateNT.o \ isdn/Q931StateTE.o \ isdn/Q932mes.o - -CFLAGS=$(ZAP_CFLAGS) -I`pwd`/include -I`pwd`/isdn/include +PWD=$(shell pwd) +INCS=-I$(PWD)/include -I$(PWD)/isdn/include +CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w @@ -67,14 +68,16 @@ $(MYLIB): $(OBJS) ranlib $(MYLIB) testapp: testapp.c $(MYLIB) - $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm -lpthread + $(CC) $(INCS) -L. testapp.c -o testapp -lopenzap -lm -lpthread +testisdn: testisdn.c $(MYLIB) + $(CC) $(INCS) -L. testisdn.c -o testisdn -lopenzap -lm -lpthread priserver.o: priserver.c - $(CC) $(TMP) -c priserver.c -o priserver.o + $(CC) $(INCS) $(TMP) -c priserver.c -o priserver.o sangoma_pri.o: sangoma_pri.c - $(CC) $(TMP) -c sangoma_pri.c -o sangoma_pri.o + $(CC) $(INCS) $(TMP) -c sangoma_pri.c -o sangoma_pri.o priserver: $(MYLIB) priserver.o sangoma_pri.o $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 29e23b14cf..5a0f74fafa 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -88,6 +88,8 @@ #include "libteletone.h" #include "zap_buffer.h" #include "zap_threadmutex.h" +#include "Q931.h" +#include "Q921.h" #ifdef NDEBUG #undef assert @@ -185,6 +187,26 @@ struct zap_channel { }; +struct zap_sigmsg { + zap_signal_event_t event_id; + uint32_t chan_id; + char cid_name[80]; + char ani[25]; + char aniII[25]; + char dnis[25]; +}; + + +struct zap_isdn_data { + Q921Data_t q921; + Q931_TrunkInfo_t q931; + zap_channel_t *dchan; + zap_channel_t *dchans[2]; + struct zap_sigmsg sigmsg; + zio_signal_cb_t sig_cb; + uint32_t flags; +}; + struct zap_span { uint32_t span_id; uint32_t chan_count; @@ -192,7 +214,10 @@ struct zap_span { struct zap_io_interface *zio; zio_event_cb_t event_callback; zap_mutex_t *mutex; + zap_trunk_type_t trunk_type; zap_signal_type_t signal_type; + struct zap_isdn_data *isdn_data; + char last_error[256]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -212,6 +237,8 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; +zap_trunk_type_t str2zap_trunk_type(char *name); +char *zap_trunk_type2str(zap_trunk_type_t type); zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); zap_status_t zap_span_close_all(zap_io_interface_t *zio); @@ -230,5 +257,7 @@ zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e); + #endif diff --git a/libs/openzap/src/include/zap_isdn.h b/libs/openzap/src/include/zap_isdn.h new file mode 100644 index 0000000000..7117304a03 --- /dev/null +++ b/libs/openzap/src/include/zap_isdn.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_ISDN_H +#define ZAP_ISDN_H +#include "openzap.h" + +typedef enum { + ZAP_ISDN_RUNNING = (1 << 0) +} zap_isdn_flag_t; + + +typedef struct zap_isdn_data zap_isdn_data_t; + +zap_status_t zap_isdn_start(zap_span_t *span); +zap_status_t zap_isdn_init(void); +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb); + +#endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 0cfa2e9468..ee958c6bfb 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -50,6 +50,14 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +typedef enum { + ZAP_TRUNK_E1, + ZAP_TRUNK_T1, + ZAP_TRUNK_J1, + ZAP_TRUNK_BRI, + ZAP_TRUNK_NONE +} zap_trunk_type_t; + typedef enum { ZAP_SIGTYPE_NONE, ZAP_SIGTYPE_ISDN, @@ -71,7 +79,6 @@ typedef enum { typedef enum { ZAP_EVENT_NONE, ZAP_EVENT_DTMF, - ZAP_EVENT_COUNT } zap_event_type_t; @@ -158,7 +165,10 @@ typedef enum { 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; +#define ZIO_SIGNAL_CB_ARGS (zap_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len) #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_ARGS (struct zap_io_interface *zio) @@ -169,6 +179,7 @@ typedef struct zap_event zap_event_t; #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) +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_t) ZIO_CONFIGURE_ARGS ; @@ -179,6 +190,7 @@ 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 ; +#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) zap_status_t name ZIO_CODEC_ARGS #define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS @@ -217,7 +229,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; #define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT #define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG -typedef struct zap_span zap_span_t; + typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 956a9e180c..afabf833ad 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -1,438 +1,441 @@ -/***************************************************************************** - - 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. - -*****************************************************************************/ -#include "Q921.h" -#include -#include "mfifo.h" - -/***************************************************************************** - - 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. - -*****************************************************************************/ -void Q921_InitTrunk(L2TRUNK trunk, - L2UCHAR sapi, - L2UCHAR tei, - Q921NetUser_t NetUser, - L2INT hsize, - Q921TxCB_t cb21, - Q921TxCB_t cb23, - void *priv21, - void *priv23) -{ - if (trunk->initialized != INITIALIZED_MAGIC) { - MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); - trunk->initialized = INITIALIZED_MAGIC; - } - trunk->vr = 0; - trunk->vs = 0; - trunk->state = 0; - trunk->sapi = sapi; - trunk->tei = tei; - trunk->NetUser = NetUser; - trunk->Q921Tx21Proc = cb21; - trunk->Q921Tx23Proc = cb23; - trunk->PrivateData21 = priv21; - trunk->PrivateData23 = priv23; - trunk->Q921HeaderSpace = hsize; -} - -static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) -{ - return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); -} - -int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) -{ - return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); - -} - -/***************************************************************************** - - 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); -} - -/***************************************************************************** - - Function: Q921SendI - - Description: Compose and Send I Frame to layer. Will receive an I frame - with space for L2 header and fill out that header before - it call Q921Tx21Proc. - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - mes ptr to I frame message. - size size of message in bytes. - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size) -{ - mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; - mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); - trunk->vs++; - - return Q921Tx21Proc(trunk, mes, size); -} - -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) -{ - return Q921SendI(trunk, - trunk->sapi, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, - 0, - Mes, - Size); -} -/***************************************************************************** - - 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. - -*****************************************************************************/ - -int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); -} - -int Q921Start(L2TRUNK trunk) -{ - return Q921SendSABME(trunk, - trunk->sapi, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, - 0); -} - -/***************************************************************************** - - Function: Q921SendDM - - Description: Comose 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. - -*****************************************************************************/ -int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); -} - -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) -{ - /* TODO: Do we need these paramaters? */ - (void)mes; - (void)size; - - trunk->vr=0; - trunk->vs=0; - - return 1; -} - -/***************************************************************************** - - 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) -{ - L2UCHAR *mes; - L2INT rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - if(smes != NULL) - { - rs = size - trunk->Q921HeaderSpace; - mes = &smes[trunk->Q921HeaderSpace]; - /* check for I frame */ - if((mes[2] & 0x01) == 0) - { - if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ - { - trunk->vr++; - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - } - } - - /* check for RR */ - else if(mes[2] ==0x01) - { - /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(trunk->HDLCInQueue); - - return 1; - } - return 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. + +*****************************************************************************/ +#include "Q921.h" +#include +#include +#include "mfifo.h" + +/***************************************************************************** + + 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. + +*****************************************************************************/ +void Q921_InitTrunk(L2TRUNK trunk, + L2UCHAR sapi, + L2UCHAR tei, + Q921NetUser_t NetUser, + L2INT hsize, + Q921TxCB_t cb21, + Q921TxCB_t cb23, + void *priv21, + void *priv23) +{ + if (trunk->initialized != INITIALIZED_MAGIC) { + MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); + trunk->initialized = INITIALIZED_MAGIC; + } + trunk->vr = 0; + trunk->vs = 0; + trunk->state = 0; + trunk->sapi = sapi; + trunk->tei = tei; + trunk->NetUser = NetUser; + trunk->Q921Tx21Proc = cb21; + trunk->Q921Tx23Proc = cb23; + trunk->PrivateData21 = priv21; + trunk->PrivateData23 = priv23; + trunk->Q921HeaderSpace = hsize; +} + +static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) +{ + return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); +} + +int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) +{ + return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); + +} + +/***************************************************************************** + + 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); +} + +/***************************************************************************** + + Function: Q921SendI + + Description: Compose and Send I Frame to layer. Will receive an I frame + with space for L2 header and fill out that header before + it call Q921Tx21Proc. + + Parameters: trunk trunk # + Sapi Sapi + cr C/R field. + Tei Tei. + pf P fiels octet 5 + mes ptr to I frame message. + size size of message in bytes. + + Return Value: 0 if failed, 1 if Send. + +*****************************************************************************/ +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size) +{ + mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); + mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; + mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; + mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); + trunk->vs++; + + return Q921Tx21Proc(trunk, mes, size); +} + +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) +{ + return Q921SendI(trunk, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, + 0, + Mes, + Size); +} +/***************************************************************************** + + 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. + +*****************************************************************************/ + +int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); +} + +int Q921Start(L2TRUNK trunk) +{ + return Q921SendSABME(trunk, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, + 1); +} + +/***************************************************************************** + + Function: Q921SendDM + + Description: Comose 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. + +*****************************************************************************/ +int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); +} + +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) +{ + /* TODO: Do we need these paramaters? */ + (void)mes; + (void)size; + + trunk->vr=0; + trunk->vs=0; + + return 1; +} + +/***************************************************************************** + + 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) +{ + L2UCHAR *mes; + L2INT rs,size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); + + if(smes != NULL) + { + rs = size - trunk->Q921HeaderSpace; + mes = &smes[trunk->Q921HeaderSpace]; + + /* check for I frame */ + if((mes[2] & 0x01) == 0) + { + if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ + { + trunk->vr++; + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(trunk->HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 1b0650f8e2..8976924b72 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -55,13 +55,13 @@ these table entries during system inititialization of a stack. *****************************************************************************/ -L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); +L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)= { @@ -130,7 +130,7 @@ void Q931SetL2HeaderSpace(L3INT space) Description: Dummy function for message processing. *****************************************************************************/ -L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) +L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) { return Q931E_INTERNAL; } @@ -142,7 +142,7 @@ L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { return Q931E_UNKNOWN_MESSAGE; } @@ -154,7 +154,7 @@ L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT I Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { return Q931E_UNKNOWN_IE; } @@ -166,7 +166,7 @@ L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { return Q931E_UNKNOWN_MESSAGE; } @@ -178,7 +178,7 @@ L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR * Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { return Q931E_UNKNOWN_IE; } @@ -190,7 +190,7 @@ L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *O Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) +L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n) { return Q931E_MISSING_CB; } @@ -275,7 +275,7 @@ void Q931Initialize() Return Value: none *****************************************************************************/ -void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms) +void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms) { (void)pTrunk; ms=ms; /* avoid warning for now. */ @@ -308,26 +308,27 @@ void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) +L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) { L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; - - Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; + Q931mes_Alerting *m = (Q931mes_Alerting *) pTrunk->L3Buf; L3INT ISize; + L3INT IOff = 0; /* Protocol Discriminator */ m->ProtDisc = Mes[IOff++]; /* CRV */ - m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); + m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); /* Message Type */ m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace, Size - Q931L4HeaderSpace); + if(RetCode >= Q931E_NO_ERROR) { RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); @@ -349,7 +350,7 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { if (pTrunk->Q931Tx34CBProc) { return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); @@ -371,7 +372,7 @@ L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk,L3UCHAR * buf, L3INT Size) +L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) { Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; @@ -398,7 +399,7 @@ L3INT Q931Rx43(Q931_TrunkInfo *pTrunk,L3UCHAR * buf, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { L3INT OSize; Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; @@ -432,7 +433,7 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) *****************************************************************************/ -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) +void Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) { if (pTrunk->Q931ErrorCBProc) { pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); @@ -461,7 +462,7 @@ void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) see q931errors.h for details. *****************************************************************************/ -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex) +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) { L3INT CRV = Q931GetUniqueCRV(pTrunk); @@ -483,7 +484,7 @@ L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex) see q931errors.h for details. *****************************************************************************/ -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex) +L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) { L3INT x; for(x=0; x < Q931MAXCALLPERTRUNK; x++) @@ -516,7 +517,7 @@ L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex) Return Value: Call State. *****************************************************************************/ -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV) +L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) { L3INT x; for(x=0; x < Q931MAXCALLPERTRUNK; x++) @@ -542,21 +543,21 @@ L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV) callindex call index. iTimer timer id *****************************************************************************/ -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) +L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerID) { pTrunk->call[callIndex].Timer = Q931GetTime(); pTrunk->call[callIndex].TimerID = iTimerID; return 0; } -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) +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 *pTrunk, L3INT callIndex, L3INT iState) +L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) { pTrunk->call[callIndex].State = iState; @@ -584,7 +585,7 @@ void Q931SetGetTimeCB(L3ULONG (*callback)()) Q931GetTimeProc = callback; } -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex) +L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex) { L3INT x; for(x=0; x < Q931MAXCALLPERTRUNK; x++) diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 2d2a3c5671..55857c7268 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -128,7 +128,7 @@ void Q931CreateNT(L3UCHAR i) Function: Q931ProcAlertingNT *****************************************************************************/ -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -157,7 +157,7 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCallProceedingNT *****************************************************************************/ -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -190,7 +190,7 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFro Function: Q931ProcConnectNT *****************************************************************************/ -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -223,7 +223,7 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcConnectAckNT *****************************************************************************/ -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -256,7 +256,7 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcProgressNT *****************************************************************************/ -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -291,7 +291,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Description: Process a SETUP message. *****************************************************************************/ -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; @@ -371,7 +371,7 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) NT side. *****************************************************************************/ -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -404,7 +404,7 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeNT *****************************************************************************/ -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -437,7 +437,7 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeAckNT *****************************************************************************/ -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -470,7 +470,7 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeRejectNT *****************************************************************************/ -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -503,7 +503,7 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendNT *****************************************************************************/ -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -536,7 +536,7 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendAckNT *****************************************************************************/ -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -569,7 +569,7 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendRejectNT *****************************************************************************/ -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -602,7 +602,7 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcInformationNT *****************************************************************************/ -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -635,7 +635,7 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcDisconnectNT *****************************************************************************/ -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -668,7 +668,7 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseNT *****************************************************************************/ -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -701,7 +701,7 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseCompleteNT *****************************************************************************/ -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -734,7 +734,7 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcRestartNT *****************************************************************************/ -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -767,7 +767,7 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRestartAckNT *****************************************************************************/ -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -800,7 +800,7 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCongestionControlNT *****************************************************************************/ -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -833,7 +833,7 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT i Function: Q931ProcInformationNT *****************************************************************************/ -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -866,7 +866,7 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcNotifyNT *****************************************************************************/ -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -899,7 +899,7 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusNT *****************************************************************************/ -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -932,7 +932,7 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusEnquiryNT *****************************************************************************/ -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -965,7 +965,7 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcSegmentNT *****************************************************************************/ -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1002,7 +1002,7 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcFacilityNT *****************************************************************************/ -L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1035,7 +1035,7 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcHoldNT *****************************************************************************/ -L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1068,7 +1068,7 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcHoldAckNT *****************************************************************************/ -L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1101,7 +1101,7 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcHoldRejectNT *****************************************************************************/ -L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1134,7 +1134,7 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRegisterTE *****************************************************************************/ -L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1167,7 +1167,7 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveNT *****************************************************************************/ -L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1200,7 +1200,7 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveAckNT *****************************************************************************/ -L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1233,7 +1233,7 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveRejectNT *****************************************************************************/ -L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 7941326b05..e0653b125d 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -212,7 +212,7 @@ void Q931CreateTE(L3UCHAR i) Function: Q931ProcAlertingTE *****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -241,7 +241,7 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCallProceedingTE *****************************************************************************/ -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -274,7 +274,7 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFro Function: Q931ProcConnectTE *****************************************************************************/ -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -307,7 +307,7 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcConnectAckTE *****************************************************************************/ -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -340,7 +340,7 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcProgressTE *****************************************************************************/ -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -373,7 +373,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSetupTE *****************************************************************************/ -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; @@ -453,7 +453,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) NT side. *****************************************************************************/ -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -480,7 +480,7 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeTE *****************************************************************************/ -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; L3INT callIndex; @@ -517,7 +517,7 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeAckTE *****************************************************************************/ -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -550,7 +550,7 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeRejectTE *****************************************************************************/ -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -583,7 +583,7 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendTE *****************************************************************************/ -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -616,7 +616,7 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendAckTE *****************************************************************************/ -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -649,7 +649,7 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendRejectTE *****************************************************************************/ -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -682,7 +682,7 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcInformationTE *****************************************************************************/ -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -715,7 +715,7 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcDisconnectTE *****************************************************************************/ -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -748,7 +748,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseTE *****************************************************************************/ -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); @@ -770,7 +770,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseCompleteTE *****************************************************************************/ -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); @@ -787,7 +787,7 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcRestartTE *****************************************************************************/ -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -820,7 +820,7 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRestartAckTE *****************************************************************************/ -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -853,7 +853,7 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCongestionControlTE *****************************************************************************/ -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -886,7 +886,7 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT i Function: Q931ProcInformationTE *****************************************************************************/ -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -919,7 +919,7 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcNotifyTE *****************************************************************************/ -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -952,7 +952,7 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusTE *****************************************************************************/ -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -985,7 +985,7 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusEnquiryTE *****************************************************************************/ -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1018,7 +1018,7 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcSegmentTE *****************************************************************************/ -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1055,7 +1055,7 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1088,7 +1088,7 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1121,7 +1121,7 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1154,7 +1154,7 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1187,7 +1187,7 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRegisterTE *****************************************************************************/ -L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1220,7 +1220,7 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1253,7 +1253,7 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveAckTE *****************************************************************************/ -L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1286,7 +1286,7 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveRejectTE *****************************************************************************/ -L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 780c29fb15..c2662dbefa 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -68,7 +68,7 @@ L3INT Q931CreateIEIndex(L3INT iec) } */ -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, +L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, @@ -146,9 +146,9 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, } void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) + L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) ) { if(Q931ProcFunc != NULL) @@ -160,8 +160,8 @@ void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, } void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) + L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) ) { if(Q931PieProc != NULL) @@ -357,7 +357,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) /***************************************************************************** *****************************************************************************/ -L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) +L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) { static L3INT crv={1}; return crv++; @@ -640,7 +640,7 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE) return 0; } -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom) { /* TODO: Unhandled paramaters */ (void)pTrunk; @@ -650,7 +650,7 @@ L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) return 0; } -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom) { /* TODO: Unhandled paramaters */ (void)pTrunk; @@ -660,7 +660,7 @@ L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) return 0; } -L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) +L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) { /* TODO: Unhandled paramaters */ (void)pTrunk; @@ -671,7 +671,7 @@ L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause return 0; } -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) +L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo) { /* TODO: Unhandled paramaters */ (void)pTrunk; diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 15e93bfee8..0f89459360 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -126,7 +126,7 @@ L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off) *****************************************************************************/ -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; L3INT Off = 0; @@ -310,7 +310,7 @@ L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR *****************************************************************************/ -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; L3INT rc=0; @@ -431,7 +431,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; L3INT Off = 0; @@ -478,7 +478,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *****************************************************************************/ -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallID * pIE = (Q931ie_CallID*)IBuf; L3INT rc=0; @@ -517,7 +517,7 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; L3INT Off = 0; @@ -562,7 +562,7 @@ L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallState * pIE = (Q931ie_CallState*)IBuf; L3INT rc=0; @@ -594,7 +594,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; L3INT Off = 0; @@ -646,7 +646,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf; L3INT rc=0; @@ -690,7 +690,7 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; L3INT Off = 0; @@ -739,7 +739,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf; L3INT rc=0; @@ -783,7 +783,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; L3INT Off = 0; @@ -843,7 +843,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallingSub * pIE = (Q931ie_CallingSub*)IBuf; L3INT rc=0; @@ -897,7 +897,7 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; L3INT Off = 0; @@ -949,7 +949,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallingSub * pIE = (Q931ie_CallingSub*)IBuf; L3INT rc=0; @@ -993,7 +993,7 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; L3INT Off = 0; @@ -1045,7 +1045,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Cause * pIE = (Q931ie_Cause*)IBuf; L3INT rc=0; @@ -1085,7 +1085,7 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CongLevel(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; L3INT Off = 0; @@ -1117,7 +1117,7 @@ L3INT Q931Uie_CongLevel(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CongLevel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CongLevel * pIE = (Q931ie_CongLevel*)IBuf; L3INT rc=0; @@ -1143,7 +1143,7 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; L3INT Off = 0; @@ -1224,7 +1224,7 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OB Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_ChanID * pIE = (Q931ie_ChanID*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -1289,7 +1289,7 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: CRV *****************************************************************************/ -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { L3INT Octet = *IOff; L3INT l = IBuf[Octet]; @@ -1336,7 +1336,7 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; L3INT Off = 0; @@ -1409,7 +1409,7 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_DateTime * pIE = (Q931ie_DateTime*)IBuf; L3INT rc=0; @@ -1455,7 +1455,7 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Display * pie = (Q931ie_Display*)OBuf; L3INT Off = 0; @@ -1498,7 +1498,7 @@ L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Display * pIE = (Q931ie_Display*)IBuf; L3INT rc=0; @@ -1538,7 +1538,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; L3INT Off = 0; @@ -1609,7 +1609,7 @@ L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_HLComp * pIE = (Q931ie_HLComp*)IBuf; L3INT rc=0; @@ -1659,7 +1659,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; L3INT Off = 0; @@ -1702,7 +1702,7 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_KeypadFac * pIE = (Q931ie_KeypadFac*)IBuf; L3INT rc=0; @@ -1741,7 +1741,7 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; L3INT Off = 0; @@ -1957,7 +1957,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_LLComp * pIE = (Q931ie_LLComp*)IBuf; L3INT rc=0; @@ -2122,7 +2122,7 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; L3INT Off = 0; @@ -2183,7 +2183,7 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_NetFac * pIE = (Q931ie_NetFac*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2232,7 +2232,7 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; L3INT Off = 0; @@ -2275,7 +2275,7 @@ L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_NotifInd * pIE = (Q931ie_NotifInd*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2308,7 +2308,7 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; L3INT Off = 0; @@ -2357,7 +2357,7 @@ L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_ProgInd * pIE = (Q931ie_ProgInd*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2393,7 +2393,7 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; L3INT Off = 0; @@ -2425,7 +2425,7 @@ L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_RepeatInd * pIE = (Q931ie_RepeatInd*)IBuf; L3INT rc=0; @@ -2452,7 +2452,7 @@ L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { ie iE; Q931SetIE(iE, *OOff); @@ -2471,7 +2471,7 @@ L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { L3BOOL RetCode = L3FALSE; @@ -2497,7 +2497,7 @@ L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; L3INT Off = 0; @@ -2540,7 +2540,7 @@ L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_RestartInd * pIE = (Q931ie_RestartInd*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2573,7 +2573,7 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; L3INT Off = 0; @@ -2619,7 +2619,7 @@ L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Segment * pIE = (Q931ie_Segment*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2655,7 +2655,7 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; L3INT Off = 0; @@ -2685,7 +2685,7 @@ L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */ L3INT rc=Q931E_NO_ERROR; @@ -2712,7 +2712,7 @@ L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; L3INT Off = 0; @@ -2753,7 +2753,7 @@ L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Signal * pIE = (Q931ie_Signal*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2786,7 +2786,7 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; L3INT Off = 0; @@ -2835,7 +2835,7 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_TransNetSel * pIE = (Q931ie_TransNetSel*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2877,7 +2877,7 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; L3INT Off = 0; @@ -2924,7 +2924,7 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_UserUser * pIE = (Q931ie_UserUser*)IBuf; L3INT rc=Q931E_NO_ERROR; diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index d376f8d176..d52a06efc8 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -49,7 +49,7 @@ *****************************************************************************/ -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -105,7 +105,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Alerting *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; @@ -159,7 +159,7 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_CallProceeding *****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -209,7 +209,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_CallProceeding *****************************************************************************/ -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; @@ -258,7 +258,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_CongestionControl *****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -274,7 +274,7 @@ L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * Function: Q931Pmes_CongestionControl *****************************************************************************/ -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -289,7 +289,7 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISi Function: Q931Umes_Connect *****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -354,7 +354,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Connect *****************************************************************************/ -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; @@ -418,7 +418,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_ConnectAck *****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -455,7 +455,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_ConnectAck *****************************************************************************/ -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; @@ -487,7 +487,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Disconnect *****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -532,7 +532,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Disconnect *****************************************************************************/ -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; @@ -574,7 +574,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Information *****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -623,7 +623,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Information *****************************************************************************/ -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Information *pMes = (Q931mes_Information *)IBuf; @@ -669,7 +669,7 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L Function: Q931Umes_Notify *****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -708,7 +708,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_Notify *****************************************************************************/ -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; @@ -742,7 +742,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA Function: Q931Umes_Progress *****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -792,7 +792,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Progress *****************************************************************************/ -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; @@ -838,7 +838,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_Release *****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -878,7 +878,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Release *****************************************************************************/ -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Release *pMes = (Q931mes_Release *)IBuf; @@ -913,7 +913,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_ReleaseComplete *****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -953,7 +953,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_ReleaseComplete *****************************************************************************/ -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; @@ -988,7 +988,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_Restart *****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -1003,7 +1003,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3 Function: Q931Pmes_Restart *****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1018,7 +1018,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_RestartAck *****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -1033,7 +1033,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, Function: Q931Pmes_RestartAck *****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1048,7 +1048,7 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Resume *****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1078,7 +1078,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_Resume *****************************************************************************/ -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; @@ -1105,7 +1105,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA Function: Q931Umes_ResumeAck *****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1141,7 +1141,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_ResumeAck *****************************************************************************/ -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; @@ -1172,7 +1172,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_ResumeReject *****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1208,7 +1208,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBu Function: Q931Pmes_ResumeReject *****************************************************************************/ -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; @@ -1234,14 +1234,14 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, return rc; } -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) { L3INT i = IOff; return IOff - i; } -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1253,7 +1253,7 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_Setup *****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ L3INT ir=0; @@ -1387,7 +1387,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Called By: Q931ProcSetup *****************************************************************************/ -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; @@ -1502,7 +1502,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR Function: Q931Umes_SetupAck *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1547,7 +1547,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_SetupAck *****************************************************************************/ -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; @@ -1589,7 +1589,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_Status *****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1630,7 +1630,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_Status *****************************************************************************/ -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Status *pMes = (Q931mes_Status *)IBuf; @@ -1665,7 +1665,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA Function: Q931Umes_StatusEnquiry *****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1695,7 +1695,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_StatusEnquiry *****************************************************************************/ -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; @@ -1722,7 +1722,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1752,7 +1752,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Suspend *****************************************************************************/ -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; @@ -1779,7 +1779,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_SuspendAck *****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1810,7 +1810,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_SuspendAck *****************************************************************************/ -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; @@ -1837,7 +1837,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_SuspendReject *****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1872,7 +1872,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_SuspendReject *****************************************************************************/ -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; @@ -1904,7 +1904,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_UserInformation *****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -1919,7 +1919,7 @@ L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * Function: Q931Pmes_UserInformation *****************************************************************************/ -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index c04d4f7ee4..b6dce79443 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -43,7 +43,7 @@ *****************************************************************************/ -L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -61,7 +61,7 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Facility *****************************************************************************/ -L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -77,7 +77,7 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -95,7 +95,7 @@ L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT I Function: Q931Pmes_Hold *****************************************************************************/ -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -111,7 +111,7 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *****************************************************************************/ -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -129,7 +129,7 @@ L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_HoldAck *****************************************************************************/ -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -145,7 +145,7 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -163,7 +163,7 @@ L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_HoldReject *****************************************************************************/ -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -179,7 +179,7 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -197,7 +197,7 @@ L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Register *****************************************************************************/ -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -213,7 +213,7 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -231,7 +231,7 @@ L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Retrieve *****************************************************************************/ -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -247,7 +247,7 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -265,7 +265,7 @@ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_RetrieveAck *****************************************************************************/ -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -281,7 +281,7 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L *****************************************************************************/ -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -299,7 +299,7 @@ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_RetrieveReject *****************************************************************************/ -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 4acdf8ece9..1f7f53a99b 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -1,129 +1,129 @@ -/***************************************************************************** - - 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 - deteceted. - - 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. - -*****************************************************************************/ - -#ifndef _Q921 -#define _Q921 - -#define Q921MAXHDLCSPACE 3000 -#define L2UCHAR unsigned char /* Min 8 bit */ -#define L2INT int /* Min 16 bit signed */ -#define L2TRUNK Q921Data_t * - -typedef enum /* Network/User Mode. */ -{ - Q921_TE=0, /* 0 : User Mode */ - Q921_NT=1 /* 1 : Network Mode */ -} Q921NetUser_t; - -typedef struct Q921Data Q921Data_t; -typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); - -#define INITIALIZED_MAGIC 42 -struct Q921Data -{ - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; - L2INT initialized; - L2UCHAR vs; - L2UCHAR vr; - L2INT state; - L2UCHAR sapi; - L2UCHAR tei; - Q921NetUser_t NetUser; - Q921TxCB_t Q921Tx21Proc; - Q921TxCB_t Q921Tx23Proc; - void *PrivateData21; - void *PrivateData23; - L2INT Q921HeaderSpace; - -}; - -void Q921_InitTrunk(L2TRUNK trunk, - L2UCHAR sapi, - L2UCHAR tei, - Q921NetUser_t NetUser, - L2INT hsize, - Q921TxCB_t cb21, - Q921TxCB_t cb23, - void *priv21, - void *priv23); -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); -int Q921Rx12(L2TRUNK trunk); -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); -int Q921Start(L2TRUNK trunk); -#endif - +/***************************************************************************** + + 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 + deteceted. + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXHDLCSPACE 3000 +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ +#define L2TRUNK Q921Data_t * + +typedef enum /* Network/User Mode. */ +{ + Q921_TE=0, /* 0 : User Mode */ + Q921_NT=1 /* 1 : Network Mode */ +} Q921NetUser_t; + +typedef struct Q921Data Q921Data_t; +typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); + +#define INITIALIZED_MAGIC 42 +struct Q921Data +{ + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2INT initialized; + L2UCHAR vs; + L2UCHAR vr; + L2INT state; + L2UCHAR sapi; + L2UCHAR tei; + Q921NetUser_t NetUser; + Q921TxCB_t Q921Tx21Proc; + Q921TxCB_t Q921Tx23Proc; + void *PrivateData21; + void *PrivateData23; + L2INT Q921HeaderSpace; + +}; + +void Q921_InitTrunk(L2TRUNK trunk, + L2UCHAR sapi, + L2UCHAR tei, + Q921NetUser_t NetUser, + L2INT hsize, + Q921TxCB_t cb21, + Q921TxCB_t cb23, + void *priv21, + void *priv23); +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); +int Q921Rx12(L2TRUNK trunk); +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); +int Q921Start(L2TRUNK trunk); +#endif + diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 3d9eee0338..fe8d3a8e8c 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1917,7 +1917,7 @@ typedef struct the trunk Info entry. *****************************************************************************/ -typedef struct Q931_TrunkInfo Q931_TrunkInfo; +typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT); typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT); @@ -2070,13 +2070,13 @@ typedef struct The proc tables are defined in Q931.c and initialized in Q931Initialize. *****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); /***************************************************************************** @@ -2185,7 +2185,7 @@ extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3 *****************************************************************************/ -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; +extern Q931_TrunkInfo_t Q931Trunk[Q931MAXTRUNKS]; #include "Q932.h" @@ -2195,186 +2195,186 @@ extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; *****************************************************************************/ -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); /***************************************************************************** Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); /***************************************************************************** Q.931 Process Function Prototyping. Implemented in Q931StateTE.c *****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +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 *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *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 *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *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 Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, 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); @@ -2384,25 +2384,25 @@ void Q931SetMesCreateCB(L3INT (*callback)()); void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); void Q931SetHeaderSpace(L3INT space); void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); void Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); L3INT Q931InitMesSetup(Q931mes_Setup *p); -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex); +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 Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); @@ -2413,7 +2413,7 @@ L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); *****************************************************************************/ ie Q931AppendIE(L3UCHAR *pm, L3UCHAR *pi); -L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk); +L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk); L3INT Q931InitIEBearerCap(Q931ie_BearerCap *p); L3INT Q931InitIEChanID(Q931ie_ChanID *p); @@ -2431,10 +2431,10 @@ L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE); L3INT Q931InitIELLComp(Q931ie_LLComp * pIE); L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); -L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); +L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo); -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, +L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, diff --git a/libs/openzap/src/isdn/include/Q932.h b/libs/openzap/src/isdn/include/Q932.h index 19b5c4c149..5d018a9187 100644 --- a/libs/openzap/src/isdn/include/Q932.h +++ b/libs/openzap/src/isdn/include/Q932.h @@ -154,38 +154,38 @@ typedef struct /***************************************************************************** Function Prototypes. *****************************************************************************/ -L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +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 *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 8160496c29..75ddae66e5 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -6,7 +6,7 @@ int main(int argc, char *argv[]) zap_channel_t *chan; unsigned ms = 20; zap_codec_t codec = ZAP_CODEC_SLIN; - unsigned runs = 4; + unsigned runs = 1; if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c new file mode 100644 index 0000000000..c55905d3f4 --- /dev/null +++ b/libs/openzap/src/testisdn.c @@ -0,0 +1,36 @@ +#include "openzap.h" +#include "zap_isdn.h" + +static ZIO_SIGNAL_CB_FUNCTION(on_signal) +{ + return ZAP_FAIL; +} + +int main(int argc, char *argv[]) +{ + zap_span_t *span; + + 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"); + + if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + fprintf(stderr, "Error finding OpenZAP span\n"); + } + + + zap_isdn_configure_span(span, Q931_TE, 0, on_signal); + zap_isdn_start(span); + + while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { + sleep(1); + } + + zap_global_destroy(); + +} diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c new file mode 100644 index 0000000000..dabea87c4e --- /dev/null +++ b/libs/openzap/src/zap_analog.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 9a55b2cb27..5a65e0d52e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -32,6 +32,7 @@ */ #include "openzap.h" +#include "zap_isdn.h" #include #ifdef ZAP_WANPIPE_SUPPORT #include "zap_wanpipe.h" @@ -45,6 +46,16 @@ static struct { zap_mutex_t *mutex; } globals; + +static char *TRUNK_TYPE_NAMES[] = { + "E1", + "T1", + "J1", + "BRI", + "NONE", + NULL +}; + static char *LEVEL_NAMES[] = { "EMERG", "ALERT", @@ -57,6 +68,31 @@ static char *LEVEL_NAMES[] = { NULL }; + +zap_trunk_type_t str2zap_trunk_type(char *name) +{ + int i; + zap_trunk_type_t t = ZAP_TRUNK_NONE; + + for (i = 0; i < ZAP_TRUNK_NONE; i++) { + if (!strcasecmp(name, TRUNK_TYPE_NAMES[i])) { + t = (zap_trunk_type_t) i; + break; + } + } + + return t; +} + +char *zap_trunk_type2str(zap_trunk_type_t type) +{ + if (type > ZAP_TRUNK_NONE) { + type = ZAP_TRUNK_NONE; + } + return TRUNK_TYPE_NAMES[(int)type]; +} + + static char *cut_path(char *in) { char *p, *ret = in; @@ -177,6 +213,9 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) if (span->mutex) { zap_mutex_destroy(&span->mutex); } + if (span->isdn_data) { + free(span->isdn_data); + } } return i ? ZAP_SUCCESS : ZAP_FAIL; @@ -383,12 +422,11 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { zap_channel_t *check; zap_mutex_lock(zio->spans[span_id].mutex); check = &zio->spans[span_id].channels[chan_id]; - + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->open(check); if (status == ZAP_SUCCESS) { @@ -974,6 +1012,8 @@ zap_status_t zap_global_init(void) uint32_t configured = 0; int modcount; + zap_isdn_init(); + memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); modcount = 0; @@ -1110,3 +1150,32 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } + +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) +{ + int i,j = 0,k; + + if (blen < (bl * 10) + 2) { + return; + } + + for (k = 0 ; k < bl; k++) { + buf[j++] = '['; + if (e) { + for(i = 7; i >= 0; i--) { + buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); + } + } else { + for(i = 0; i < 8; i++) { + buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); + } + } + buf[j++] = ']'; + buf[j++] = '\n'; + } + + buf[j++] = '\0'; + +} + + diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c new file mode 100644 index 0000000000..fbcc31bafc --- /dev/null +++ b/libs/openzap/src/zap_isdn.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "zap_isdn.h" +#include "Q931.h" +#include "Q921.h" + + +static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) +{ + zap_log(ZAP_LOG_ERROR, "ERROR: %d %d %d", id, p1, p2); + return 0; +} + +static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) +{ + zap_span_t *span = (zap_span_t *) pvt; + Q931mes_Generic *gen = (Q931mes_Generic *) msg; + + assert(span != NULL); + + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d\n", gen->MesType); + + return 0; +} + +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; + assert(span != NULL); + return zap_channel_write(span->isdn_data->dchan, msg, &len) == ZAP_SUCCESS ? 0 : -1; +} + + +static void *zap_isdn_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_isdn_data_t *data = span->isdn_data; + unsigned char buf[1024]; + zap_size_t len = sizeof(buf); + + zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n"); + + Q921Start(&data->q921); + + while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { + zap_wait_flag_t flags = ZAP_READ; + zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); + + 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!"); + goto done; + } + break; + case ZAP_TIMEOUT: + { + /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ + /*Q931TimeTick(data->q931, L3ULONG ms);*/ + } + break; + default: + { + if (flags & ZAP_READ) { + len = sizeof(buf); + if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { + /*char bb[512] = ""; + + print_bits(buf, (int)len, bb, sizeof(bb), 1); + zap_log(ZAP_LOG_DEBUG, "Read %d bytes\n%s\n", (int)len, bb); + */ + + Q921QueueHDLCFrame(&data->q921, buf, (int)len); + Q921Rx12(&data->q921); + } + } else { + zap_log(ZAP_LOG_DEBUG, "No Read FLAG!\n"); + } + } + break; + } + + } + + done: + + zap_channel_close(&data->dchans[0]); + zap_channel_close(&data->dchans[1]); + zap_clear_flag(span->isdn_data, ZAP_ISDN_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n"); + return NULL; +} + +zap_status_t zap_isdn_init(void) +{ + Q931Initialize(); + + return ZAP_SUCCESS; +} + +zap_status_t zap_isdn_start(zap_span_t *span) +{ + zap_set_flag(span->isdn_data, ZAP_ISDN_RUNNING); + return zap_thread_create_detached(zap_isdn_run, span); +} + +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) +{ + uint32_t x,i; + zap_channel_t *dchans[2] = {0}; + + if (span->signal_type) { + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + return ZAP_FAIL; + } + + if (span->trunk_type >= ZAP_TRUNK_NONE) { + snprintf(span->last_error, sizeof(span->last_error), "Unknown trunk type!"); + return ZAP_FAIL; + } + + for(i = 1; i <= span->chan_count; i++) { + if (span->channels[i].type == ZAP_CHAN_TYPE_DQ921) { + if (zap_channel_open(span->zio->name, 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); + x++; + } + } + } + + if (!x) { + snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!"); + return ZAP_FAIL; + } + + + span->isdn_data = malloc(sizeof(*span->isdn_data)); + assert(span->isdn_data != NULL); + memset(span->isdn_data, 0, sizeof(*span->isdn_data)); + + span->isdn_data->sig_cb = sig_cb; + span->isdn_data->dchans[0] = dchans[0]; + span->isdn_data->dchans[1] = dchans[1]; + span->isdn_data->dchan = span->isdn_data->dchans[0]; + + Q921_InitTrunk(&span->isdn_data->q921, + 0, + 0, + mode, + 0, + zap_isdn_921_21, + (Q921TxCB_t)Q931Rx23, + span, + &span->isdn_data->q931); + + Q931Api_InitTrunk(&span->isdn_data->q931, + dialect, + mode, + span->trunk_type, + zap_isdn_931_34, + (Q931TxCB_t)Q921Rx32, + zap_isdn_931_err, + &span->isdn_data->q921, + span); + + + span->signal_type = ZAP_SIGTYPE_ISDN; + + return ZAP_SUCCESS; +} diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index c3ddbcbb9a..04dc44d507 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -203,6 +203,9 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) if (!strcasecmp(var, "enabled")) { zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); + } else if (!strcasecmp(var, "trunk_type")) { + span->trunk_type = str2zap_trunk_type(val); + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { From b67a52b142c1a88d40c27c21fcccc4350b87df39 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 22 May 2007 22:07:05 +0000 Subject: [PATCH 0204/1766] w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@102 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 13 +- libs/freetdm/src/include/openzap.h | 29 + libs/freetdm/src/include/zap_isdn.h | 49 ++ libs/freetdm/src/include/zap_types.h | 16 +- libs/freetdm/src/isdn/Q921.c | 879 ++++++++++++++------------- libs/freetdm/src/isdn/Q931.c | 57 +- libs/freetdm/src/isdn/Q931StateNT.c | 66 +- libs/freetdm/src/isdn/Q931StateTE.c | 66 +- libs/freetdm/src/isdn/Q931api.c | 22 +- libs/freetdm/src/isdn/Q931ie.c | 106 ++-- libs/freetdm/src/isdn/Q931mes.c | 100 +-- libs/freetdm/src/isdn/Q932mes.c | 32 +- libs/freetdm/src/isdn/include/Q921.h | 258 ++++---- libs/freetdm/src/isdn/include/Q931.h | 362 +++++------ libs/freetdm/src/isdn/include/Q932.h | 64 +- libs/freetdm/src/testapp.c | 2 +- libs/freetdm/src/testisdn.c | 36 ++ libs/freetdm/src/zap_analog.c | 34 ++ libs/freetdm/src/zap_io.c | 73 ++- libs/freetdm/src/zap_isdn.c | 205 +++++++ libs/freetdm/src/zap_wanpipe.c | 3 + 21 files changed, 1458 insertions(+), 1014 deletions(-) create mode 100644 libs/freetdm/src/include/zap_isdn.h create mode 100644 libs/freetdm/src/testisdn.c create mode 100644 libs/freetdm/src/zap_analog.c create mode 100644 libs/freetdm/src/zap_isdn.c diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 3cb6bad5d2..8041ea3a7d 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -53,8 +53,9 @@ isdn/Q931StateNT.o \ isdn/Q931StateTE.o \ isdn/Q932mes.o - -CFLAGS=$(ZAP_CFLAGS) -I`pwd`/include -I`pwd`/isdn/include +PWD=$(shell pwd) +INCS=-I$(PWD)/include -I$(PWD)/isdn/include +CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a TMP=-I../../libpri-1.2.4 -Iinclude -I. -w @@ -67,14 +68,16 @@ $(MYLIB): $(OBJS) ranlib $(MYLIB) testapp: testapp.c $(MYLIB) - $(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm -lpthread + $(CC) $(INCS) -L. testapp.c -o testapp -lopenzap -lm -lpthread +testisdn: testisdn.c $(MYLIB) + $(CC) $(INCS) -L. testisdn.c -o testisdn -lopenzap -lm -lpthread priserver.o: priserver.c - $(CC) $(TMP) -c priserver.c -o priserver.o + $(CC) $(INCS) $(TMP) -c priserver.c -o priserver.o sangoma_pri.o: sangoma_pri.c - $(CC) $(TMP) -c sangoma_pri.c -o sangoma_pri.o + $(CC) $(INCS) $(TMP) -c sangoma_pri.c -o sangoma_pri.o priserver: $(MYLIB) priserver.o sangoma_pri.o $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 29e23b14cf..5a0f74fafa 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -88,6 +88,8 @@ #include "libteletone.h" #include "zap_buffer.h" #include "zap_threadmutex.h" +#include "Q931.h" +#include "Q921.h" #ifdef NDEBUG #undef assert @@ -185,6 +187,26 @@ struct zap_channel { }; +struct zap_sigmsg { + zap_signal_event_t event_id; + uint32_t chan_id; + char cid_name[80]; + char ani[25]; + char aniII[25]; + char dnis[25]; +}; + + +struct zap_isdn_data { + Q921Data_t q921; + Q931_TrunkInfo_t q931; + zap_channel_t *dchan; + zap_channel_t *dchans[2]; + struct zap_sigmsg sigmsg; + zio_signal_cb_t sig_cb; + uint32_t flags; +}; + struct zap_span { uint32_t span_id; uint32_t chan_count; @@ -192,7 +214,10 @@ struct zap_span { struct zap_io_interface *zio; zio_event_cb_t event_callback; zap_mutex_t *mutex; + zap_trunk_type_t trunk_type; zap_signal_type_t signal_type; + struct zap_isdn_data *isdn_data; + char last_error[256]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -212,6 +237,8 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; +zap_trunk_type_t str2zap_trunk_type(char *name); +char *zap_trunk_type2str(zap_trunk_type_t type); zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); zap_status_t zap_span_close_all(zap_io_interface_t *zio); @@ -230,5 +257,7 @@ zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e); + #endif diff --git a/libs/freetdm/src/include/zap_isdn.h b/libs/freetdm/src/include/zap_isdn.h new file mode 100644 index 0000000000..7117304a03 --- /dev/null +++ b/libs/freetdm/src/include/zap_isdn.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_ISDN_H +#define ZAP_ISDN_H +#include "openzap.h" + +typedef enum { + ZAP_ISDN_RUNNING = (1 << 0) +} zap_isdn_flag_t; + + +typedef struct zap_isdn_data zap_isdn_data_t; + +zap_status_t zap_isdn_start(zap_span_t *span); +zap_status_t zap_isdn_init(void); +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb); + +#endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 0cfa2e9468..ee958c6bfb 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -50,6 +50,14 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +typedef enum { + ZAP_TRUNK_E1, + ZAP_TRUNK_T1, + ZAP_TRUNK_J1, + ZAP_TRUNK_BRI, + ZAP_TRUNK_NONE +} zap_trunk_type_t; + typedef enum { ZAP_SIGTYPE_NONE, ZAP_SIGTYPE_ISDN, @@ -71,7 +79,6 @@ typedef enum { typedef enum { ZAP_EVENT_NONE, ZAP_EVENT_DTMF, - ZAP_EVENT_COUNT } zap_event_type_t; @@ -158,7 +165,10 @@ typedef enum { 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; +#define ZIO_SIGNAL_CB_ARGS (zap_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len) #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_ARGS (struct zap_io_interface *zio) @@ -169,6 +179,7 @@ typedef struct zap_event zap_event_t; #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) +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_t) ZIO_CONFIGURE_ARGS ; @@ -179,6 +190,7 @@ 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 ; +#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) zap_status_t name ZIO_CODEC_ARGS #define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS @@ -217,7 +229,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; #define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT #define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG -typedef struct zap_span zap_span_t; + typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...); typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 956a9e180c..afabf833ad 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -1,438 +1,441 @@ -/***************************************************************************** - - 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. - -*****************************************************************************/ -#include "Q921.h" -#include -#include "mfifo.h" - -/***************************************************************************** - - 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. - -*****************************************************************************/ -void Q921_InitTrunk(L2TRUNK trunk, - L2UCHAR sapi, - L2UCHAR tei, - Q921NetUser_t NetUser, - L2INT hsize, - Q921TxCB_t cb21, - Q921TxCB_t cb23, - void *priv21, - void *priv23) -{ - if (trunk->initialized != INITIALIZED_MAGIC) { - MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); - trunk->initialized = INITIALIZED_MAGIC; - } - trunk->vr = 0; - trunk->vs = 0; - trunk->state = 0; - trunk->sapi = sapi; - trunk->tei = tei; - trunk->NetUser = NetUser; - trunk->Q921Tx21Proc = cb21; - trunk->Q921Tx23Proc = cb23; - trunk->PrivateData21 = priv21; - trunk->PrivateData23 = priv23; - trunk->Q921HeaderSpace = hsize; -} - -static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) -{ - return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); -} - -int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) -{ - return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); - -} - -/***************************************************************************** - - 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); -} - -/***************************************************************************** - - Function: Q921SendI - - Description: Compose and Send I Frame to layer. Will receive an I frame - with space for L2 header and fill out that header before - it call Q921Tx21Proc. - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - mes ptr to I frame message. - size size of message in bytes. - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size) -{ - mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; - mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); - trunk->vs++; - - return Q921Tx21Proc(trunk, mes, size); -} - -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) -{ - return Q921SendI(trunk, - trunk->sapi, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, - 0, - Mes, - Size); -} -/***************************************************************************** - - 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. - -*****************************************************************************/ - -int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); -} - -int Q921Start(L2TRUNK trunk) -{ - return Q921SendSABME(trunk, - trunk->sapi, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, - 0); -} - -/***************************************************************************** - - Function: Q921SendDM - - Description: Comose 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. - -*****************************************************************************/ -int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, 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. - -*****************************************************************************/ -int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) -{ - L2UCHAR mes[400]; - - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); -} - -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) -{ - /* TODO: Do we need these paramaters? */ - (void)mes; - (void)size; - - trunk->vr=0; - trunk->vs=0; - - return 1; -} - -/***************************************************************************** - - 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) -{ - L2UCHAR *mes; - L2INT rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - if(smes != NULL) - { - rs = size - trunk->Q921HeaderSpace; - mes = &smes[trunk->Q921HeaderSpace]; - /* check for I frame */ - if((mes[2] & 0x01) == 0) - { - if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ - { - trunk->vr++; - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - } - } - - /* check for RR */ - else if(mes[2] ==0x01) - { - /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(trunk->HDLCInQueue); - - return 1; - } - return 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. + +*****************************************************************************/ +#include "Q921.h" +#include +#include +#include "mfifo.h" + +/***************************************************************************** + + 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. + +*****************************************************************************/ +void Q921_InitTrunk(L2TRUNK trunk, + L2UCHAR sapi, + L2UCHAR tei, + Q921NetUser_t NetUser, + L2INT hsize, + Q921TxCB_t cb21, + Q921TxCB_t cb23, + void *priv21, + void *priv23) +{ + if (trunk->initialized != INITIALIZED_MAGIC) { + MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); + trunk->initialized = INITIALIZED_MAGIC; + } + trunk->vr = 0; + trunk->vs = 0; + trunk->state = 0; + trunk->sapi = sapi; + trunk->tei = tei; + trunk->NetUser = NetUser; + trunk->Q921Tx21Proc = cb21; + trunk->Q921Tx23Proc = cb23; + trunk->PrivateData21 = priv21; + trunk->PrivateData23 = priv23; + trunk->Q921HeaderSpace = hsize; +} + +static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) +{ + return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); +} + +int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) +{ + return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); + +} + +/***************************************************************************** + + 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); +} + +/***************************************************************************** + + Function: Q921SendI + + Description: Compose and Send I Frame to layer. Will receive an I frame + with space for L2 header and fill out that header before + it call Q921Tx21Proc. + + Parameters: trunk trunk # + Sapi Sapi + cr C/R field. + Tei Tei. + pf P fiels octet 5 + mes ptr to I frame message. + size size of message in bytes. + + Return Value: 0 if failed, 1 if Send. + +*****************************************************************************/ +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size) +{ + mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); + mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; + mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; + mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); + trunk->vs++; + + return Q921Tx21Proc(trunk, mes, size); +} + +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) +{ + return Q921SendI(trunk, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, + 0, + Mes, + Size); +} +/***************************************************************************** + + 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. + +*****************************************************************************/ + +int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; + mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); +} + +int Q921Start(L2TRUNK trunk) +{ + return Q921SendSABME(trunk, + trunk->sapi, + trunk->NetUser == Q921_TE ? 0 : 1, + trunk->tei, + 1); +} + +/***************************************************************************** + + Function: Q921SendDM + + Description: Comose 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. + +*****************************************************************************/ +int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, 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. + +*****************************************************************************/ +int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +{ + L2UCHAR mes[400]; + + mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); + mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); + mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); + + return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); +} + +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) +{ + /* TODO: Do we need these paramaters? */ + (void)mes; + (void)size; + + trunk->vr=0; + trunk->vs=0; + + return 1; +} + +/***************************************************************************** + + 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) +{ + L2UCHAR *mes; + L2INT rs,size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); + + if(smes != NULL) + { + rs = size - trunk->Q921HeaderSpace; + mes = &smes[trunk->Q921HeaderSpace]; + + /* check for I frame */ + if((mes[2] & 0x01) == 0) + { + if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ + { + trunk->vr++; + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + else + { + /* todo: whatever*/ + } + } + + /* check for RR */ + else if(mes[2] ==0x01) + { + /* todo: check if RR is responce to I */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + } + + /* check for RNR */ + /* check for REJ */ + /* check for SABME */ + else if((mes[2] & 0xef) == 0x6f) + { + Q921ProcSABME(trunk, mes, rs); + Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); + } + + /* check for DM */ + /* check for UI */ + /* check for DISC */ + /* check for UA */ + /* check for FRMR */ + /* check for XID */ + + else + { + /* what the ? Issue an error */ + /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ + /* todo: REJ or FRMR */ + } + + MFIFOKillNext(trunk->HDLCInQueue); + + return 1; + } + return 0; +} + diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 1b0650f8e2..8976924b72 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -55,13 +55,13 @@ these table entries during system inititialization of a stack. *****************************************************************************/ -L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); +L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)= { @@ -130,7 +130,7 @@ void Q931SetL2HeaderSpace(L3INT space) Description: Dummy function for message processing. *****************************************************************************/ -L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) +L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) { return Q931E_INTERNAL; } @@ -142,7 +142,7 @@ L3INT Q931ProcDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b,L3INT c) Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { return Q931E_UNKNOWN_MESSAGE; } @@ -154,7 +154,7 @@ L3INT Q931UmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT I Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { return Q931E_UNKNOWN_IE; } @@ -166,7 +166,7 @@ L3INT Q931UieDummy(Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { return Q931E_UNKNOWN_MESSAGE; } @@ -178,7 +178,7 @@ L3INT Q931PmesDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR * Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { return Q931E_UNKNOWN_IE; } @@ -190,7 +190,7 @@ L3INT Q931PieDummy(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *O Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931TxDummy(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT n) +L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n) { return Q931E_MISSING_CB; } @@ -275,7 +275,7 @@ void Q931Initialize() Return Value: none *****************************************************************************/ -void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms) +void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms) { (void)pTrunk; ms=ms; /* avoid warning for now. */ @@ -308,26 +308,27 @@ void Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) +L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) { L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; - - Q931mes_Alerting * m = (Q931mes_Alerting*)Mes; + Q931mes_Alerting *m = (Q931mes_Alerting *) pTrunk->L3Buf; L3INT ISize; + L3INT IOff = 0; /* Protocol Discriminator */ m->ProtDisc = Mes[IOff++]; /* CRV */ - m->CRV = Q931Uie_CRV(pTrunk, Mes,m->buf, &IOff, &ISize); + m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); /* Message Type */ m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf,Q931L4HeaderSpace,Size- Q931L4HeaderSpace); + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace, Size - Q931L4HeaderSpace); + if(RetCode >= Q931E_NO_ERROR) { RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); @@ -349,7 +350,7 @@ L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { if (pTrunk->Q931Tx34CBProc) { return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); @@ -371,7 +372,7 @@ L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk,L3UCHAR * buf, L3INT Size) +L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) { Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; @@ -398,7 +399,7 @@ L3INT Q931Rx43(Q931_TrunkInfo *pTrunk,L3UCHAR * buf, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) +L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { L3INT OSize; Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; @@ -432,7 +433,7 @@ L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size) *****************************************************************************/ -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) +void Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2) { if (pTrunk->Q931ErrorCBProc) { pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); @@ -461,7 +462,7 @@ void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) see q931errors.h for details. *****************************************************************************/ -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex) +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) { L3INT CRV = Q931GetUniqueCRV(pTrunk); @@ -483,7 +484,7 @@ L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex) see q931errors.h for details. *****************************************************************************/ -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex) +L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) { L3INT x; for(x=0; x < Q931MAXCALLPERTRUNK; x++) @@ -516,7 +517,7 @@ L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex) Return Value: Call State. *****************************************************************************/ -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV) +L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) { L3INT x; for(x=0; x < Q931MAXCALLPERTRUNK; x++) @@ -542,21 +543,21 @@ L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV) callindex call index. iTimer timer id *****************************************************************************/ -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimerID) +L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerID) { pTrunk->call[callIndex].Timer = Q931GetTime(); pTrunk->call[callIndex].TimerID = iTimerID; return 0; } -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimerID) +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 *pTrunk, L3INT callIndex, L3INT iState) +L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) { pTrunk->call[callIndex].State = iState; @@ -584,7 +585,7 @@ void Q931SetGetTimeCB(L3ULONG (*callback)()) Q931GetTimeProc = callback; } -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex) +L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex) { L3INT x; for(x=0; x < Q931MAXCALLPERTRUNK; x++) diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 2d2a3c5671..55857c7268 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -128,7 +128,7 @@ void Q931CreateNT(L3UCHAR i) Function: Q931ProcAlertingNT *****************************************************************************/ -L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -157,7 +157,7 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCallProceedingNT *****************************************************************************/ -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -190,7 +190,7 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFro Function: Q931ProcConnectNT *****************************************************************************/ -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -223,7 +223,7 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcConnectAckNT *****************************************************************************/ -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -256,7 +256,7 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcProgressNT *****************************************************************************/ -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -291,7 +291,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Description: Process a SETUP message. *****************************************************************************/ -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; @@ -371,7 +371,7 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) NT side. *****************************************************************************/ -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -404,7 +404,7 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeNT *****************************************************************************/ -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -437,7 +437,7 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeAckNT *****************************************************************************/ -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -470,7 +470,7 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeRejectNT *****************************************************************************/ -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -503,7 +503,7 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendNT *****************************************************************************/ -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -536,7 +536,7 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendAckNT *****************************************************************************/ -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -569,7 +569,7 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendRejectNT *****************************************************************************/ -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -602,7 +602,7 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcInformationNT *****************************************************************************/ -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -635,7 +635,7 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcDisconnectNT *****************************************************************************/ -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -668,7 +668,7 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseNT *****************************************************************************/ -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -701,7 +701,7 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseCompleteNT *****************************************************************************/ -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -734,7 +734,7 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcRestartNT *****************************************************************************/ -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -767,7 +767,7 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRestartAckNT *****************************************************************************/ -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -800,7 +800,7 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCongestionControlNT *****************************************************************************/ -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -833,7 +833,7 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT i Function: Q931ProcInformationNT *****************************************************************************/ -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -866,7 +866,7 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcNotifyNT *****************************************************************************/ -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -899,7 +899,7 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusNT *****************************************************************************/ -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -932,7 +932,7 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusEnquiryNT *****************************************************************************/ -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -965,7 +965,7 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcSegmentNT *****************************************************************************/ -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1002,7 +1002,7 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcFacilityNT *****************************************************************************/ -L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1035,7 +1035,7 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcHoldNT *****************************************************************************/ -L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1068,7 +1068,7 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcHoldAckNT *****************************************************************************/ -L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1101,7 +1101,7 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcHoldRejectNT *****************************************************************************/ -L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1134,7 +1134,7 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRegisterTE *****************************************************************************/ -L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1167,7 +1167,7 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveNT *****************************************************************************/ -L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1200,7 +1200,7 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveAckNT *****************************************************************************/ -L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1233,7 +1233,7 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveRejectNT *****************************************************************************/ -L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 7941326b05..e0653b125d 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -212,7 +212,7 @@ void Q931CreateTE(L3UCHAR i) Function: Q931ProcAlertingTE *****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -241,7 +241,7 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCallProceedingTE *****************************************************************************/ -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -274,7 +274,7 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFro Function: Q931ProcConnectTE *****************************************************************************/ -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -307,7 +307,7 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcConnectAckTE *****************************************************************************/ -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -340,7 +340,7 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcProgressTE *****************************************************************************/ -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -373,7 +373,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSetupTE *****************************************************************************/ -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; @@ -453,7 +453,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) NT side. *****************************************************************************/ -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -480,7 +480,7 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeTE *****************************************************************************/ -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; L3INT callIndex; @@ -517,7 +517,7 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeAckTE *****************************************************************************/ -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -550,7 +550,7 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcResumeRejectTE *****************************************************************************/ -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -583,7 +583,7 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendTE *****************************************************************************/ -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -616,7 +616,7 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendAckTE *****************************************************************************/ -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -649,7 +649,7 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcSuspendRejectTE *****************************************************************************/ -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -682,7 +682,7 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcInformationTE *****************************************************************************/ -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -715,7 +715,7 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcDisconnectTE *****************************************************************************/ -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -748,7 +748,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseTE *****************************************************************************/ -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); @@ -770,7 +770,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcReleaseCompleteTE *****************************************************************************/ -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); @@ -787,7 +787,7 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFr Function: Q931ProcRestartTE *****************************************************************************/ -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -820,7 +820,7 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRestartAckTE *****************************************************************************/ -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -853,7 +853,7 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcCongestionControlTE *****************************************************************************/ -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -886,7 +886,7 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT i Function: Q931ProcInformationTE *****************************************************************************/ -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -919,7 +919,7 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcNotifyTE *****************************************************************************/ -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -952,7 +952,7 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusTE *****************************************************************************/ -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -985,7 +985,7 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcStatusEnquiryTE *****************************************************************************/ -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1018,7 +1018,7 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom Function: Q931ProcSegmentTE *****************************************************************************/ -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1055,7 +1055,7 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1088,7 +1088,7 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1121,7 +1121,7 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1154,7 +1154,7 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1187,7 +1187,7 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRegisterTE *****************************************************************************/ -L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1220,7 +1220,7 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q932ProcRetrieveTE *****************************************************************************/ -L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1253,7 +1253,7 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveAckTE *****************************************************************************/ -L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -1286,7 +1286,7 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) Function: Q931ProcRetrieveRejectTE *****************************************************************************/ -L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * buf, L3INT iFrom) +L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT callIndex; L3INT ret=Q931E_NO_ERROR; diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 780c29fb15..c2662dbefa 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -68,7 +68,7 @@ L3INT Q931CreateIEIndex(L3INT iec) } */ -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, +L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, @@ -146,9 +146,9 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, } void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) + L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) ) { if(Q931ProcFunc != NULL) @@ -160,8 +160,8 @@ void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, } void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) + L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) ) { if(Q931PieProc != NULL) @@ -357,7 +357,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) /***************************************************************************** *****************************************************************************/ -L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk) +L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) { static L3INT crv={1}; return crv++; @@ -640,7 +640,7 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE) return 0; } -L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +L3INT Q931ProcUnknownMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom) { /* TODO: Unhandled paramaters */ (void)pTrunk; @@ -650,7 +650,7 @@ L3INT Q931ProcUnknownMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) return 0; } -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) +L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFrom) { /* TODO: Unhandled paramaters */ (void)pTrunk; @@ -660,7 +660,7 @@ L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom) return 0; } -L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) +L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause) { /* TODO: Unhandled paramaters */ (void)pTrunk; @@ -671,7 +671,7 @@ L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause return 0; } -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo) +L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo) { /* TODO: Unhandled paramaters */ (void)pTrunk; diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 15e93bfee8..0f89459360 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -126,7 +126,7 @@ L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off) *****************************************************************************/ -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; L3INT Off = 0; @@ -310,7 +310,7 @@ L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR *****************************************************************************/ -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf; L3INT rc=0; @@ -431,7 +431,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallID * pie = (Q931ie_CallID*)OBuf; L3INT Off = 0; @@ -478,7 +478,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * *****************************************************************************/ -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallID * pIE = (Q931ie_CallID*)IBuf; L3INT rc=0; @@ -517,7 +517,7 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallState * pie = (Q931ie_CallState*)OBuf; L3INT Off = 0; @@ -562,7 +562,7 @@ L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallState * pIE = (Q931ie_CallState*)IBuf; L3INT rc=0; @@ -594,7 +594,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CalledSub * pie = (Q931ie_CalledSub*)OBuf; L3INT Off = 0; @@ -646,7 +646,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf; L3INT rc=0; @@ -690,7 +690,7 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CalledNum * pie = (Q931ie_CalledNum*)OBuf; L3INT Off = 0; @@ -739,7 +739,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf; L3INT rc=0; @@ -783,7 +783,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; L3INT Off = 0; @@ -843,7 +843,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHA Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallingSub * pIE = (Q931ie_CallingSub*)IBuf; L3INT rc=0; @@ -897,7 +897,7 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CallingSub * pie = (Q931ie_CallingSub*)OBuf; L3INT Off = 0; @@ -949,7 +949,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CallingSub * pIE = (Q931ie_CallingSub*)IBuf; L3INT rc=0; @@ -993,7 +993,7 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Cause * pie = (Q931ie_Cause*)OBuf; L3INT Off = 0; @@ -1045,7 +1045,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Cause * pIE = (Q931ie_Cause*)IBuf; L3INT rc=0; @@ -1085,7 +1085,7 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CongLevel(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; L3INT Off = 0; @@ -1117,7 +1117,7 @@ L3INT Q931Uie_CongLevel(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_CongLevel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_CongLevel * pIE = (Q931ie_CongLevel*)IBuf; L3INT rc=0; @@ -1143,7 +1143,7 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; L3INT Off = 0; @@ -1224,7 +1224,7 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OB Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_ChanID * pIE = (Q931ie_ChanID*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -1289,7 +1289,7 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: CRV *****************************************************************************/ -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { L3INT Octet = *IOff; L3INT l = IBuf[Octet]; @@ -1336,7 +1336,7 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; L3INT Off = 0; @@ -1409,7 +1409,7 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_DateTime * pIE = (Q931ie_DateTime*)IBuf; L3INT rc=0; @@ -1455,7 +1455,7 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Display * pie = (Q931ie_Display*)OBuf; L3INT Off = 0; @@ -1498,7 +1498,7 @@ L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Display * pIE = (Q931ie_Display*)IBuf; L3INT rc=0; @@ -1538,7 +1538,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; L3INT Off = 0; @@ -1609,7 +1609,7 @@ L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_HLComp * pIE = (Q931ie_HLComp*)IBuf; L3INT rc=0; @@ -1659,7 +1659,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_KeypadFac * pie = (Q931ie_KeypadFac*)OBuf; L3INT Off = 0; @@ -1702,7 +1702,7 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_KeypadFac * pIE = (Q931ie_KeypadFac*)IBuf; L3INT rc=0; @@ -1741,7 +1741,7 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_LLComp * pie = (Q931ie_LLComp*)OBuf; L3INT Off = 0; @@ -1957,7 +1957,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_LLComp * pIE = (Q931ie_LLComp*)IBuf; L3INT rc=0; @@ -2122,7 +2122,7 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_NetFac * pie = (Q931ie_NetFac*)OBuf; L3INT Off = 0; @@ -2183,7 +2183,7 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_NetFac * pIE = (Q931ie_NetFac*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2232,7 +2232,7 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_NotifInd * pie = (Q931ie_NotifInd*)OBuf; L3INT Off = 0; @@ -2275,7 +2275,7 @@ L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_NotifInd * pIE = (Q931ie_NotifInd*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2308,7 +2308,7 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_ProgInd * pie = (Q931ie_ProgInd*)OBuf; L3INT Off = 0; @@ -2357,7 +2357,7 @@ L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_ProgInd * pIE = (Q931ie_ProgInd*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2393,7 +2393,7 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; L3INT Off = 0; @@ -2425,7 +2425,7 @@ L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_RepeatInd * pIE = (Q931ie_RepeatInd*)IBuf; L3INT rc=0; @@ -2452,7 +2452,7 @@ L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { ie iE; Q931SetIE(iE, *OOff); @@ -2471,7 +2471,7 @@ L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { L3BOOL RetCode = L3FALSE; @@ -2497,7 +2497,7 @@ L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_RestartInd * pie = (Q931ie_RestartInd*)OBuf; L3INT Off = 0; @@ -2540,7 +2540,7 @@ L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_RestartInd * pIE = (Q931ie_RestartInd*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2573,7 +2573,7 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Segment * pie = (Q931ie_Segment*)OBuf; L3INT Off = 0; @@ -2619,7 +2619,7 @@ L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Segment * pIE = (Q931ie_Segment*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2655,7 +2655,7 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; L3INT Off = 0; @@ -2685,7 +2685,7 @@ L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */ L3INT rc=Q931E_NO_ERROR; @@ -2712,7 +2712,7 @@ L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_Signal * pie = (Q931ie_Signal*)OBuf; L3INT Off = 0; @@ -2753,7 +2753,7 @@ L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * O Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_Signal * pIE = (Q931ie_Signal*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2786,7 +2786,7 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_TransNetSel * pie = (Q931ie_TransNetSel*)OBuf; L3INT Off = 0; @@ -2835,7 +2835,7 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_TransNetSel * pIE = (Q931ie_TransNetSel*)IBuf; L3INT rc=Q931E_NO_ERROR; @@ -2877,7 +2877,7 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { Q931ie_UserUser * pie = (Q931ie_UserUser*)OBuf; L3INT Off = 0; @@ -2924,7 +2924,7 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { Q931ie_UserUser * pIE = (Q931ie_UserUser*)IBuf; L3INT rc=Q931E_NO_ERROR; diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index d376f8d176..d52a06efc8 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -49,7 +49,7 @@ *****************************************************************************/ -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -105,7 +105,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Alerting *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; @@ -159,7 +159,7 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_CallProceeding *****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -209,7 +209,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_CallProceeding *****************************************************************************/ -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; @@ -258,7 +258,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_CongestionControl *****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -274,7 +274,7 @@ L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR * Function: Q931Pmes_CongestionControl *****************************************************************************/ -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -289,7 +289,7 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3INT ISi Function: Q931Umes_Connect *****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -354,7 +354,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Connect *****************************************************************************/ -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; @@ -418,7 +418,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_ConnectAck *****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -455,7 +455,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_ConnectAck *****************************************************************************/ -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; @@ -487,7 +487,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Disconnect *****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -532,7 +532,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Disconnect *****************************************************************************/ -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; @@ -574,7 +574,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Information *****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -623,7 +623,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Information *****************************************************************************/ -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Information *pMes = (Q931mes_Information *)IBuf; @@ -669,7 +669,7 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L Function: Q931Umes_Notify *****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -708,7 +708,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_Notify *****************************************************************************/ -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; @@ -742,7 +742,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA Function: Q931Umes_Progress *****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -792,7 +792,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Progress *****************************************************************************/ -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; @@ -838,7 +838,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_Release *****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -878,7 +878,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Release *****************************************************************************/ -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Release *pMes = (Q931mes_Release *)IBuf; @@ -913,7 +913,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_ReleaseComplete *****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -953,7 +953,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_ReleaseComplete *****************************************************************************/ -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; @@ -988,7 +988,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_Restart *****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -1003,7 +1003,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3 Function: Q931Pmes_Restart *****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1018,7 +1018,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_RestartAck *****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -1033,7 +1033,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, Function: Q931Pmes_RestartAck *****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1048,7 +1048,7 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Resume *****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1078,7 +1078,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_Resume *****************************************************************************/ -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; @@ -1105,7 +1105,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA Function: Q931Umes_ResumeAck *****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1141,7 +1141,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_ResumeAck *****************************************************************************/ -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; @@ -1172,7 +1172,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_ResumeReject *****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1208,7 +1208,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBu Function: Q931Pmes_ResumeReject *****************************************************************************/ -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; @@ -1234,14 +1234,14 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, return rc; } -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) { L3INT i = IOff; return IOff - i; } -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1253,7 +1253,7 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_Setup *****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ L3INT ir=0; @@ -1387,7 +1387,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Called By: Q931ProcSetup *****************************************************************************/ -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; @@ -1502,7 +1502,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR Function: Q931Umes_SetupAck *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1547,7 +1547,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_SetupAck *****************************************************************************/ -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; @@ -1589,7 +1589,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_Status *****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1630,7 +1630,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_Status *****************************************************************************/ -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Status *pMes = (Q931mes_Status *)IBuf; @@ -1665,7 +1665,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA Function: Q931Umes_StatusEnquiry *****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1695,7 +1695,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_StatusEnquiry *****************************************************************************/ -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; @@ -1722,7 +1722,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1752,7 +1752,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Suspend *****************************************************************************/ -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; @@ -1779,7 +1779,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_SuspendAck *****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1810,7 +1810,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_SuspendAck *****************************************************************************/ -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; @@ -1837,7 +1837,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_SuspendReject *****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1872,7 +1872,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_SuspendReject *****************************************************************************/ -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; @@ -1904,7 +1904,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_UserInformation *****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -1919,7 +1919,7 @@ L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * Function: Q931Pmes_UserInformation *****************************************************************************/ -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index c04d4f7ee4..b6dce79443 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -43,7 +43,7 @@ *****************************************************************************/ -L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -61,7 +61,7 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Facility *****************************************************************************/ -L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -77,7 +77,7 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -95,7 +95,7 @@ L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT I Function: Q931Pmes_Hold *****************************************************************************/ -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -111,7 +111,7 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *****************************************************************************/ -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -129,7 +129,7 @@ L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Function: Q931Pmes_HoldAck *****************************************************************************/ -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -145,7 +145,7 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH *****************************************************************************/ -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -163,7 +163,7 @@ L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_HoldReject *****************************************************************************/ -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -179,7 +179,7 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -197,7 +197,7 @@ L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Register *****************************************************************************/ -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -213,7 +213,7 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -231,7 +231,7 @@ L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Retrieve *****************************************************************************/ -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -247,7 +247,7 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC *****************************************************************************/ -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -265,7 +265,7 @@ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_RetrieveAck *****************************************************************************/ -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -281,7 +281,7 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L *****************************************************************************/ -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -299,7 +299,7 @@ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_RetrieveReject *****************************************************************************/ -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 4acdf8ece9..1f7f53a99b 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -1,129 +1,129 @@ -/***************************************************************************** - - 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 - deteceted. - - 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. - -*****************************************************************************/ - -#ifndef _Q921 -#define _Q921 - -#define Q921MAXHDLCSPACE 3000 -#define L2UCHAR unsigned char /* Min 8 bit */ -#define L2INT int /* Min 16 bit signed */ -#define L2TRUNK Q921Data_t * - -typedef enum /* Network/User Mode. */ -{ - Q921_TE=0, /* 0 : User Mode */ - Q921_NT=1 /* 1 : Network Mode */ -} Q921NetUser_t; - -typedef struct Q921Data Q921Data_t; -typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); - -#define INITIALIZED_MAGIC 42 -struct Q921Data -{ - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; - L2INT initialized; - L2UCHAR vs; - L2UCHAR vr; - L2INT state; - L2UCHAR sapi; - L2UCHAR tei; - Q921NetUser_t NetUser; - Q921TxCB_t Q921Tx21Proc; - Q921TxCB_t Q921Tx23Proc; - void *PrivateData21; - void *PrivateData23; - L2INT Q921HeaderSpace; - -}; - -void Q921_InitTrunk(L2TRUNK trunk, - L2UCHAR sapi, - L2UCHAR tei, - Q921NetUser_t NetUser, - L2INT hsize, - Q921TxCB_t cb21, - Q921TxCB_t cb23, - void *priv21, - void *priv23); -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); -int Q921Rx12(L2TRUNK trunk); -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); -int Q921Start(L2TRUNK trunk); -#endif - +/***************************************************************************** + + 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 + deteceted. + + 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. + +*****************************************************************************/ + +#ifndef _Q921 +#define _Q921 + +#define Q921MAXHDLCSPACE 3000 +#define L2UCHAR unsigned char /* Min 8 bit */ +#define L2INT int /* Min 16 bit signed */ +#define L2TRUNK Q921Data_t * + +typedef enum /* Network/User Mode. */ +{ + Q921_TE=0, /* 0 : User Mode */ + Q921_NT=1 /* 1 : Network Mode */ +} Q921NetUser_t; + +typedef struct Q921Data Q921Data_t; +typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); + +#define INITIALIZED_MAGIC 42 +struct Q921Data +{ + L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; + L2INT initialized; + L2UCHAR vs; + L2UCHAR vr; + L2INT state; + L2UCHAR sapi; + L2UCHAR tei; + Q921NetUser_t NetUser; + Q921TxCB_t Q921Tx21Proc; + Q921TxCB_t Q921Tx23Proc; + void *PrivateData21; + void *PrivateData23; + L2INT Q921HeaderSpace; + +}; + +void Q921_InitTrunk(L2TRUNK trunk, + L2UCHAR sapi, + L2UCHAR tei, + Q921NetUser_t NetUser, + L2INT hsize, + Q921TxCB_t cb21, + Q921TxCB_t cb23, + void *priv21, + void *priv23); +int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); +int Q921Rx12(L2TRUNK trunk); +int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); +int Q921Start(L2TRUNK trunk); +#endif + diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 3d9eee0338..fe8d3a8e8c 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1917,7 +1917,7 @@ typedef struct the trunk Info entry. *****************************************************************************/ -typedef struct Q931_TrunkInfo Q931_TrunkInfo; +typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT); typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT); @@ -2070,13 +2070,13 @@ typedef struct The proc tables are defined in Q931.c and initialized in Q931Initialize. *****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *,L3INT); +extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); /***************************************************************************** @@ -2185,7 +2185,7 @@ extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo *pTrunk,L3 *****************************************************************************/ -extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; +extern Q931_TrunkInfo_t Q931Trunk[Q931MAXTRUNKS]; #include "Q932.h" @@ -2195,186 +2195,186 @@ extern Q931_TrunkInfo Q931Trunk[Q931MAXTRUNKS]; *****************************************************************************/ -L3INT Q931Pie_BearerCap(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Uie_BearerCap(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); /***************************************************************************** Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Umes_Alerting(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); /***************************************************************************** Q.931 Process Function Prototyping. Implemented in Q931StateTE.c *****************************************************************************/ -L3INT Q931ProcAlertingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentTE(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); +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 *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcConnectAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcProgressNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSetupAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUserInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcDisconnectNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcRestartAckNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcInformationNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcNotifyNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcSegmentNT(Q931_TrunkInfo *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 *pTrunk,L3UCHAR * b, L3INT iFrom); -L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo *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 Q931TimeTick(Q931_TrunkInfo *pTrunk, L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Rx43(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx34(Q931_TrunkInfo *pTrunk, L3UCHAR * Mes, L3INT Size); -void Q931SetError(Q931_TrunkInfo *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2); +void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms); +L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size); +L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, 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); @@ -2384,25 +2384,25 @@ void Q931SetMesCreateCB(L3INT (*callback)()); void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); void Q931SetHeaderSpace(L3INT space); void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); + L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), + L3INT (*Q931UieProc)(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); void Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); L3INT Q931InitMesSetup(Q931mes_Setup *p); -L3INT Q931CreateCRV(Q931_TrunkInfo *pTrunk, L3INT * callIndex); -L3INT Q931AllocateCRV(Q931_TrunkInfo *pTrunk, L3INT iCRV, L3INT * callIndex); -L3INT Q931FindCRV(Q931_TrunkInfo *pTrunk, L3INT crv, L3INT *callindex); -L3INT Q931GetCallState(Q931_TrunkInfo *pTrunk, L3INT iCRV); -L3INT Q931StartTimer(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3USHORT iTimer); -L3INT Q931StopTimer(Q931_TrunkInfo *pTrunk, L3INT callindex, L3USHORT iTimer); -L3INT Q931SetState(Q931_TrunkInfo *pTrunk, L3INT callIndex, L3INT iState); +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex); +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 Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); @@ -2413,7 +2413,7 @@ L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); *****************************************************************************/ ie Q931AppendIE(L3UCHAR *pm, L3UCHAR *pi); -L3INT Q931GetUniqueCRV(Q931_TrunkInfo *pTrunk); +L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk); L3INT Q931InitIEBearerCap(Q931ie_BearerCap *p); L3INT Q931InitIEChanID(Q931ie_ChanID *p); @@ -2431,10 +2431,10 @@ L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE); L3INT Q931InitIELLComp(Q931ie_LLComp * pIE); L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); -L3INT Q931Disconnect(Q931_TrunkInfo *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); -L3INT Q931ReleaseComplete(Q931_TrunkInfo *pTrunk, L3INT iTo); +L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); +L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo); -L3INT Q931Api_InitTrunk(Q931_TrunkInfo *pTrunk, +L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, diff --git a/libs/freetdm/src/isdn/include/Q932.h b/libs/freetdm/src/isdn/include/Q932.h index 19b5c4c149..5d018a9187 100644 --- a/libs/freetdm/src/isdn/include/Q932.h +++ b/libs/freetdm/src/isdn/include/Q932.h @@ -154,38 +154,38 @@ typedef struct /***************************************************************************** Function Prototypes. *****************************************************************************/ -L3INT Q932ProcFacilityTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); +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 *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRegisterNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo *pTrunk, L3UCHAR * b, L3INT iFrom); -L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo *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 *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Umes_Facility(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Hold(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Register(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Retrieve(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 8160496c29..75ddae66e5 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -6,7 +6,7 @@ int main(int argc, char *argv[]) zap_channel_t *chan; unsigned ms = 20; zap_codec_t codec = ZAP_CODEC_SLIN; - unsigned runs = 4; + unsigned runs = 1; if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c new file mode 100644 index 0000000000..c55905d3f4 --- /dev/null +++ b/libs/freetdm/src/testisdn.c @@ -0,0 +1,36 @@ +#include "openzap.h" +#include "zap_isdn.h" + +static ZIO_SIGNAL_CB_FUNCTION(on_signal) +{ + return ZAP_FAIL; +} + +int main(int argc, char *argv[]) +{ + zap_span_t *span; + + 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"); + + if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + fprintf(stderr, "Error finding OpenZAP span\n"); + } + + + zap_isdn_configure_span(span, Q931_TE, 0, on_signal); + zap_isdn_start(span); + + while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { + sleep(1); + } + + zap_global_destroy(); + +} diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c new file mode 100644 index 0000000000..dabea87c4e --- /dev/null +++ b/libs/freetdm/src/zap_analog.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 9a55b2cb27..5a65e0d52e 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -32,6 +32,7 @@ */ #include "openzap.h" +#include "zap_isdn.h" #include #ifdef ZAP_WANPIPE_SUPPORT #include "zap_wanpipe.h" @@ -45,6 +46,16 @@ static struct { zap_mutex_t *mutex; } globals; + +static char *TRUNK_TYPE_NAMES[] = { + "E1", + "T1", + "J1", + "BRI", + "NONE", + NULL +}; + static char *LEVEL_NAMES[] = { "EMERG", "ALERT", @@ -57,6 +68,31 @@ static char *LEVEL_NAMES[] = { NULL }; + +zap_trunk_type_t str2zap_trunk_type(char *name) +{ + int i; + zap_trunk_type_t t = ZAP_TRUNK_NONE; + + for (i = 0; i < ZAP_TRUNK_NONE; i++) { + if (!strcasecmp(name, TRUNK_TYPE_NAMES[i])) { + t = (zap_trunk_type_t) i; + break; + } + } + + return t; +} + +char *zap_trunk_type2str(zap_trunk_type_t type) +{ + if (type > ZAP_TRUNK_NONE) { + type = ZAP_TRUNK_NONE; + } + return TRUNK_TYPE_NAMES[(int)type]; +} + + static char *cut_path(char *in) { char *p, *ret = in; @@ -177,6 +213,9 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) if (span->mutex) { zap_mutex_destroy(&span->mutex); } + if (span->isdn_data) { + free(span->isdn_data); + } } return i ? ZAP_SUCCESS : ZAP_FAIL; @@ -383,12 +422,11 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); zap_mutex_unlock(globals.mutex); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { zap_channel_t *check; zap_mutex_lock(zio->spans[span_id].mutex); check = &zio->spans[span_id].channels[chan_id]; - + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->open(check); if (status == ZAP_SUCCESS) { @@ -974,6 +1012,8 @@ zap_status_t zap_global_init(void) uint32_t configured = 0; int modcount; + zap_isdn_init(); + memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); modcount = 0; @@ -1110,3 +1150,32 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } + +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) +{ + int i,j = 0,k; + + if (blen < (bl * 10) + 2) { + return; + } + + for (k = 0 ; k < bl; k++) { + buf[j++] = '['; + if (e) { + for(i = 7; i >= 0; i--) { + buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); + } + } else { + for(i = 0; i < 8; i++) { + buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); + } + } + buf[j++] = ']'; + buf[j++] = '\n'; + } + + buf[j++] = '\0'; + +} + + diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c new file mode 100644 index 0000000000..fbcc31bafc --- /dev/null +++ b/libs/freetdm/src/zap_isdn.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "zap_isdn.h" +#include "Q931.h" +#include "Q921.h" + + +static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) +{ + zap_log(ZAP_LOG_ERROR, "ERROR: %d %d %d", id, p1, p2); + return 0; +} + +static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) +{ + zap_span_t *span = (zap_span_t *) pvt; + Q931mes_Generic *gen = (Q931mes_Generic *) msg; + + assert(span != NULL); + + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d\n", gen->MesType); + + return 0; +} + +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; + assert(span != NULL); + return zap_channel_write(span->isdn_data->dchan, msg, &len) == ZAP_SUCCESS ? 0 : -1; +} + + +static void *zap_isdn_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_isdn_data_t *data = span->isdn_data; + unsigned char buf[1024]; + zap_size_t len = sizeof(buf); + + zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n"); + + Q921Start(&data->q921); + + while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { + zap_wait_flag_t flags = ZAP_READ; + zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); + + 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!"); + goto done; + } + break; + case ZAP_TIMEOUT: + { + /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ + /*Q931TimeTick(data->q931, L3ULONG ms);*/ + } + break; + default: + { + if (flags & ZAP_READ) { + len = sizeof(buf); + if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { + /*char bb[512] = ""; + + print_bits(buf, (int)len, bb, sizeof(bb), 1); + zap_log(ZAP_LOG_DEBUG, "Read %d bytes\n%s\n", (int)len, bb); + */ + + Q921QueueHDLCFrame(&data->q921, buf, (int)len); + Q921Rx12(&data->q921); + } + } else { + zap_log(ZAP_LOG_DEBUG, "No Read FLAG!\n"); + } + } + break; + } + + } + + done: + + zap_channel_close(&data->dchans[0]); + zap_channel_close(&data->dchans[1]); + zap_clear_flag(span->isdn_data, ZAP_ISDN_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n"); + return NULL; +} + +zap_status_t zap_isdn_init(void) +{ + Q931Initialize(); + + return ZAP_SUCCESS; +} + +zap_status_t zap_isdn_start(zap_span_t *span) +{ + zap_set_flag(span->isdn_data, ZAP_ISDN_RUNNING); + return zap_thread_create_detached(zap_isdn_run, span); +} + +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) +{ + uint32_t x,i; + zap_channel_t *dchans[2] = {0}; + + if (span->signal_type) { + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + return ZAP_FAIL; + } + + if (span->trunk_type >= ZAP_TRUNK_NONE) { + snprintf(span->last_error, sizeof(span->last_error), "Unknown trunk type!"); + return ZAP_FAIL; + } + + for(i = 1; i <= span->chan_count; i++) { + if (span->channels[i].type == ZAP_CHAN_TYPE_DQ921) { + if (zap_channel_open(span->zio->name, 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); + x++; + } + } + } + + if (!x) { + snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!"); + return ZAP_FAIL; + } + + + span->isdn_data = malloc(sizeof(*span->isdn_data)); + assert(span->isdn_data != NULL); + memset(span->isdn_data, 0, sizeof(*span->isdn_data)); + + span->isdn_data->sig_cb = sig_cb; + span->isdn_data->dchans[0] = dchans[0]; + span->isdn_data->dchans[1] = dchans[1]; + span->isdn_data->dchan = span->isdn_data->dchans[0]; + + Q921_InitTrunk(&span->isdn_data->q921, + 0, + 0, + mode, + 0, + zap_isdn_921_21, + (Q921TxCB_t)Q931Rx23, + span, + &span->isdn_data->q931); + + Q931Api_InitTrunk(&span->isdn_data->q931, + dialect, + mode, + span->trunk_type, + zap_isdn_931_34, + (Q931TxCB_t)Q921Rx32, + zap_isdn_931_err, + &span->isdn_data->q921, + span); + + + span->signal_type = ZAP_SIGTYPE_ISDN; + + return ZAP_SUCCESS; +} diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index c3ddbcbb9a..04dc44d507 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -203,6 +203,9 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) if (!strcasecmp(var, "enabled")) { zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); + } else if (!strcasecmp(var, "trunk_type")) { + span->trunk_type = str2zap_trunk_type(val); + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { From aecacc27df3eef5081fdb82a2736feba3d6621a6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 22:24:43 +0000 Subject: [PATCH 0205/1766] add Q931InitMesRestartAck git-svn-id: http://svn.openzap.org/svn/openzap/trunk@103 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 14 ++++++++++++++ libs/openzap/src/isdn/include/Q931.h | 1 + 2 files changed, 15 insertions(+) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index c2662dbefa..b5e3662316 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -404,6 +404,20 @@ L3INT Q931InitMesResume(Q931mes_Resume * pMes) return 0; } +L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE; + + pMes->Size = Q931GetMesSize((L3UCHAR*)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; diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index fe8d3a8e8c..c68f5268a9 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -2395,6 +2395,7 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, void Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); L3INT Q931InitMesSetup(Q931mes_Setup *p); +L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes); L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex); L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex); From f2eb322de858cacd55ac6a1c488c4be91df765a2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 22 May 2007 22:24:43 +0000 Subject: [PATCH 0206/1766] add Q931InitMesRestartAck git-svn-id: http://svn.openzap.org/svn/openzap/trunk@103 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 14 ++++++++++++++ libs/freetdm/src/isdn/include/Q931.h | 1 + 2 files changed, 15 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index c2662dbefa..b5e3662316 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -404,6 +404,20 @@ L3INT Q931InitMesResume(Q931mes_Resume * pMes) return 0; } +L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes) +{ + pMes->ProtDisc = 0x80; + pMes->CRV = 0; /* CRV to be allocated, might be receive*/ + pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE; + + pMes->Size = Q931GetMesSize((L3UCHAR*)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; diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index fe8d3a8e8c..c68f5268a9 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -2395,6 +2395,7 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, void Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); L3INT Q931InitMesSetup(Q931mes_Setup *p); +L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes); L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex); L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex); From bc07decb593da9f680a1307b4d32506f069cbba5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 04:05:34 +0000 Subject: [PATCH 0207/1766] little formatting... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@104 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 8976924b72..8c311dfa57 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -331,7 +331,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) if(RetCode >= Q931E_NO_ERROR) { - RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); } return RetCode; From 3885bde05b29655e04027b787fdab61affa9e23f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 04:05:34 +0000 Subject: [PATCH 0208/1766] little formatting... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@104 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 8976924b72..8c311dfa57 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -331,7 +331,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) if(RetCode >= Q931E_NO_ERROR) { - RetCode=Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); } return RetCode; From ce51441fa02cddbfecde9cbacde8f88584485f29 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 04:10:50 +0000 Subject: [PATCH 0209/1766] add message pack and unpack functions for Restart and RestartAck from Jan. Thanks Jan. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@105 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 204 +++++++++++++++++++++++--------- 1 file changed, 145 insertions(+), 59 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index d52a06efc8..a75db9db2e 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -983,65 +983,151 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS return rc; } -/***************************************************************************** - - Function: Q931Umes_Restart - -*****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_Restart - -*****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_RestartAck - -*****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Restart) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* RestartInd */ + if(Q931IsIEPresent(pMes->RestartInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* RestartInd */ + if(Q931IsIEPresent(pMes->RestartInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} /***************************************************************************** From 82c66d25abbde4e4049b77886bccc21fd61ec424 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 04:10:50 +0000 Subject: [PATCH 0210/1766] add message pack and unpack functions for Restart and RestartAck from Jan. Thanks Jan. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@105 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 204 +++++++++++++++++++++++--------- 1 file changed, 145 insertions(+), 59 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index d52a06efc8..a75db9db2e 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -983,65 +983,151 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS return rc; } -/***************************************************************************** - - Function: Q931Umes_Restart - -*****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_Restart - -*****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Umes_RestartAck - -*****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} - -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3BOOL RetCode = L3FALSE; - - NoWarning(OBuf); - NoWarning(IBuf); - - return RetCode; -} +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Restart) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* RestartInd */ + if(Q931IsIEPresent(pMes->RestartInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* RestartInd */ + if(Q931IsIEPresent(pMes->RestartInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} /***************************************************************************** From 5f0b5353d2b3a08a34e39a05fa2019b9994c9e13 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:11:36 +0000 Subject: [PATCH 0211/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@106 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 293 ++++++++++++++++---------------- 1 file changed, 148 insertions(+), 145 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index a75db9db2e..e2ab66aa93 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -983,151 +983,154 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS return rc; } -/***************************************************************************** - - Function: Q931Umes_Restart - -*****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - L3INT OOff=0; - Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Restart) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Restart - -*****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* ChanID */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* RestartInd */ - if(Q931IsIEPresent(pMes->RestartInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_RestartAck - -*****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - L3INT OOff=0; - Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* ChanID */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* RestartInd */ - if(Q931IsIEPresent(pMes->RestartInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&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_Restart) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* RestartInd */ + if(Q931IsIEPresent(pMes->RestartInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; + L3INT Octet = 0; + *OSize = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + printf("WTF: %d\n", Octet); + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](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; + printf("WTF: %d\n", Octet); + *OSize = Octet; + return rc; +} /***************************************************************************** From 8697d65b4b013ecebebe4c7fbdc7740919554d54 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:11:36 +0000 Subject: [PATCH 0212/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@106 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 293 ++++++++++++++++---------------- 1 file changed, 148 insertions(+), 145 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index a75db9db2e..e2ab66aa93 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -983,151 +983,154 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS return rc; } -/***************************************************************************** - - Function: Q931Umes_Restart - -*****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - L3INT OOff=0; - Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_Restart) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_Restart - -*****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* ChanID */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* RestartInd */ - if(Q931IsIEPresent(pMes->RestartInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} - -/***************************************************************************** - - Function: Q931Umes_RestartAck - -*****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) -{ - L3INT OOff=0; - Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; - L3INT rc=Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - default: - return Q931E_ILLEGAL_IE; - break; - } - } - mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; - L3INT Octet = 0; - - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* ChanID */ - if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* Display */ - if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) - return rc; - /* RestartInd */ - if(Q931IsIEPresent(pMes->RestartInd)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) - return rc; - - return rc; -} +/***************************************************************************** + + Function: Q931Umes_Restart + +*****************************************************************************/ +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&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_Restart) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_Restart + +*****************************************************************************/ +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* RestartInd */ + if(Q931IsIEPresent(pMes->RestartInd)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + return rc; + + return rc; +} + +/***************************************************************************** + + Function: Q931Umes_RestartAck + +*****************************************************************************/ +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_RESTART_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: Q931Pmes_RestartAck + +*****************************************************************************/ +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; + L3INT Octet = 0; + *OSize = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + printf("WTF: %d\n", Octet); + /* ChanID */ + if(Q931IsIEPresent(pMes->ChanID)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + return rc; + /* Display */ + if(Q931IsIEPresent(pMes->Display)) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](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; + printf("WTF: %d\n", Octet); + *OSize = Octet; + return rc; +} /***************************************************************************** From 5e1d3ea15dc60e041a6e1149e40cb4b7254a002f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:14:15 +0000 Subject: [PATCH 0213/1766] set size and location correctly git-svn-id: http://svn.openzap.org/svn/openzap/trunk@107 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 0f89459360..4e7410b120 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -2520,11 +2520,12 @@ L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH Q931IESizeTest(Q931E_RESTARTIND); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_RestartInd); pie->Size = sizeof(Q931ie_RestartInd); - Q931SetIE(*pIE, *OOff); return Q931E_NO_ERROR; } @@ -2553,7 +2554,7 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* Octet 3*/ OBuf[(*Octet)++] = 0x80 | pIE->Class ; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } From 10b0f6998e5d1cc3886fa8ca00c3fcb533cacc7f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:14:15 +0000 Subject: [PATCH 0214/1766] set size and location correctly git-svn-id: http://svn.openzap.org/svn/openzap/trunk@107 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 0f89459360..4e7410b120 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -2520,11 +2520,12 @@ L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH Q931IESizeTest(Q931E_RESTARTIND); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_RestartInd); pie->Size = sizeof(Q931ie_RestartInd); - Q931SetIE(*pIE, *OOff); return Q931E_NO_ERROR; } @@ -2553,7 +2554,7 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* Octet 3*/ OBuf[(*Octet)++] = 0x80 | pIE->Class ; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } From 9443d750280dc2afcb0bb690feb2c2440d2556aa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:14:47 +0000 Subject: [PATCH 0215/1766] cast git-svn-id: http://svn.openzap.org/svn/openzap/trunk@108 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index c68f5268a9..da3466a8d0 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1881,6 +1881,7 @@ typedef struct L3INT CRV; /* Call reference value */ ie ChanID; /* Channel identification */ ie Display; /* Display */ + ie RestartWin; /* Restart Window */ ie RestartInd; /* Restart indicator */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_Restart; @@ -2127,7 +2128,7 @@ extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk, Description: Compute a Ptr to the information element. *****************************************************************************/ -#define Q931GetIEPtr(ie,buf) (&buf[Q931GetIEOffset(ie)]) +#define Q931GetIEPtr(ie,buf) ((void *)&buf[Q931GetIEOffset(ie)]) /***************************************************************************** From 25e0f9443dc211045737bed3364e8e384ac3438b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:14:47 +0000 Subject: [PATCH 0216/1766] cast git-svn-id: http://svn.openzap.org/svn/openzap/trunk@108 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index c68f5268a9..da3466a8d0 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1881,6 +1881,7 @@ typedef struct L3INT CRV; /* Call reference value */ ie ChanID; /* Channel identification */ ie Display; /* Display */ + ie RestartWin; /* Restart Window */ ie RestartInd; /* Restart indicator */ L3UCHAR buf[1]; /* Dynamic buffer */ }Q931mes_Restart; @@ -2127,7 +2128,7 @@ extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk, Description: Compute a Ptr to the information element. *****************************************************************************/ -#define Q931GetIEPtr(ie,buf) (&buf[Q931GetIEOffset(ie)]) +#define Q931GetIEPtr(ie,buf) ((void *)&buf[Q931GetIEOffset(ie)]) /***************************************************************************** From db1af075b63eb1eff8be096ca1f1e059a23098ec Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:15:48 +0000 Subject: [PATCH 0217/1766] use the correct sizes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@109 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 8c311dfa57..f230b5973a 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -327,7 +327,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace, Size - Q931L4HeaderSpace); + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); if(RetCode >= Q931E_NO_ERROR) { @@ -411,7 +411,7 @@ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) if(RetCode >= Q931E_NO_ERROR) { if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, Size); + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); } else { RetCode = Q931E_MISSING_CB; } From 43bc6035d2c68a9ce957dc03b6575b5cdc08b0c3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 16:15:48 +0000 Subject: [PATCH 0218/1766] use the correct sizes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@109 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 8c311dfa57..f230b5973a 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -327,7 +327,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace, Size - Q931L4HeaderSpace); + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); if(RetCode >= Q931E_NO_ERROR) { @@ -411,7 +411,7 @@ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) if(RetCode >= Q931E_NO_ERROR) { if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, Size); + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); } else { RetCode = Q931E_MISSING_CB; } From 31f79bf237c56d14fc79ce37216394fd08cd8069 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 18:19:04 +0000 Subject: [PATCH 0219/1766] add more couters, better process vs and vr git-svn-id: http://svn.openzap.org/svn/openzap/trunk@110 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 33 ++++++++++++++++++++++------ libs/openzap/src/isdn/include/Q921.h | 1 + 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index afabf833ad..e1e326acd9 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -64,8 +64,9 @@ void Q921_InitTrunk(L2TRUNK trunk, MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); trunk->initialized = INITIALIZED_MAGIC; } + trunk->va = 0; + trunk->vs = 0; trunk->vr = 0; - trunk->vs = 0; trunk->state = 0; trunk->sapi = sapi; trunk->tei = tei; @@ -355,6 +356,7 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) trunk->vr=0; trunk->vs=0; + trunk->va=0; return 1; } @@ -382,29 +384,46 @@ int Q921Rx12(L2TRUNK trunk) L2UCHAR *mes; L2INT rs,size; /* receive size & Q921 frame size*/ L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - + L2UCHAR nr; + if(smes != NULL) { + if ((mes[2] & 3) != 3) { + /* we have an S or I frame */ + /* if nr is between va and vs, update our va counter */ + nr = (mes[3] >> 1); + if (nr >= trunk->va && nr <= trunk->vs) { + trunk->va = nr; + } + } + rs = size - trunk->Q921HeaderSpace; mes = &smes[trunk->Q921HeaderSpace]; /* check for I frame */ if((mes[2] & 0x01) == 0) { - if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ + L2INT vs = trunk->vs; + /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ + trunk->vr++; + if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ { - trunk->vr++; - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } + if (vs == trunk->vs) { + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + } else { /* todo: whatever*/ - } + trunk->vr--; + } } /* check for RR */ else if(mes[2] ==0x01) { + + /* todo: we probably should schedule to send RR at timeout here */ /* todo: check if RR is responce to I */ Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); } diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 1f7f53a99b..89061c2fdc 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -98,6 +98,7 @@ struct Q921Data { L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2INT initialized; + L2UCHAR va; L2UCHAR vs; L2UCHAR vr; L2INT state; From b5d1ff62b64c02b72bbee043dc500ab594d0fb3f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 18:19:04 +0000 Subject: [PATCH 0220/1766] add more couters, better process vs and vr git-svn-id: http://svn.openzap.org/svn/openzap/trunk@110 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 33 ++++++++++++++++++++++------ libs/freetdm/src/isdn/include/Q921.h | 1 + 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index afabf833ad..e1e326acd9 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -64,8 +64,9 @@ void Q921_InitTrunk(L2TRUNK trunk, MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); trunk->initialized = INITIALIZED_MAGIC; } + trunk->va = 0; + trunk->vs = 0; trunk->vr = 0; - trunk->vs = 0; trunk->state = 0; trunk->sapi = sapi; trunk->tei = tei; @@ -355,6 +356,7 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) trunk->vr=0; trunk->vs=0; + trunk->va=0; return 1; } @@ -382,29 +384,46 @@ int Q921Rx12(L2TRUNK trunk) L2UCHAR *mes; L2INT rs,size; /* receive size & Q921 frame size*/ L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - + L2UCHAR nr; + if(smes != NULL) { + if ((mes[2] & 3) != 3) { + /* we have an S or I frame */ + /* if nr is between va and vs, update our va counter */ + nr = (mes[3] >> 1); + if (nr >= trunk->va && nr <= trunk->vs) { + trunk->va = nr; + } + } + rs = size - trunk->Q921HeaderSpace; mes = &smes[trunk->Q921HeaderSpace]; /* check for I frame */ if((mes[2] & 0x01) == 0) { - if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ + L2INT vs = trunk->vs; + /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ + trunk->vr++; + if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ { - trunk->vr++; - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); - } + if (vs == trunk->vs) { + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + } + } else { /* todo: whatever*/ - } + trunk->vr--; + } } /* check for RR */ else if(mes[2] ==0x01) { + + /* todo: we probably should schedule to send RR at timeout here */ /* todo: check if RR is responce to I */ Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); } diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 1f7f53a99b..89061c2fdc 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -98,6 +98,7 @@ struct Q921Data { L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2INT initialized; + L2UCHAR va; L2UCHAR vs; L2UCHAR vr; L2INT state; From 04d4509a329eb6e42606d5f7e124261a35532e10 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 18:25:23 +0000 Subject: [PATCH 0221/1766] getting closer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@111 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 8 +++++-- libs/openzap/src/zap_isdn.c | 44 +++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 5a65e0d52e..f4dbeeeade 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1153,7 +1153,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) { - int i,j = 0,k; + int i,j = 0, k, l = 0; if (blen < (bl * 10) + 2) { return; @@ -1171,7 +1171,11 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) } } buf[j++] = ']'; - buf[j++] = '\n'; + buf[j++] = ' '; + if (++l == 6) { + buf[j++] = '\n'; + l = 0; + } } buf[j++] = '\0'; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index fbcc31bafc..978504a1e9 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -35,7 +35,8 @@ #include "zap_isdn.h" #include "Q931.h" #include "Q921.h" - +#define LINE "--------------------------------------------------------------------------------" +#define IODEBUG static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) { @@ -46,12 +47,27 @@ static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { zap_span_t *span = (zap_span_t *) pvt; + zap_isdn_data_t *data = span->isdn_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; + + Q931mes_Restart * restart = (Q931mes_Restart*)msg; + + L3INT ieoff = Q931GetIEOffset(restart->RestartInd); + Q931ie_RestartInd * restartind = (void *)(&restart->buf + (ieoff * sizeof(restart->buf[1]))); + + assert(span != NULL); - - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d\n", gen->MesType); - + assert(data != NULL); + printf("WTF: %d", ((Q931mes_Restart*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Restart*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "send ack %d\n", restartind->Class); + zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Restart*)gen)->Size); + + printf("XXXXXXXXXXXXx"); + gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; + Q931Rx43(&data->q931, msg, 12); + return 0; } @@ -59,11 +75,17 @@ 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; +#ifdef IODEBUG + char bb[512] = ""; + print_bits(msg, (int)len, bb, sizeof(bb), 1); + 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(span->isdn_data->dchan, msg, &len) == ZAP_SUCCESS ? 0 : -1; } - static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; @@ -78,7 +100,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); - + switch(status) { case ZAP_FAIL: { @@ -98,11 +120,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { - /*char bb[512] = ""; - - print_bits(buf, (int)len, bb, sizeof(bb), 1); - zap_log(ZAP_LOG_DEBUG, "Read %d bytes\n%s\n", (int)len, bb); - */ +#ifdef IODEBUG + char bb[512] = ""; + print_bits(buf, (int)len, bb, sizeof(bb), 1); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); +#endif Q921QueueHDLCFrame(&data->q921, buf, (int)len); Q921Rx12(&data->q921); From 80435e6f81d87d954377c0fab723d606146a6e59 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 18:25:23 +0000 Subject: [PATCH 0222/1766] getting closer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@111 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 8 +++++-- libs/freetdm/src/zap_isdn.c | 44 +++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5a65e0d52e..f4dbeeeade 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1153,7 +1153,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) { - int i,j = 0,k; + int i,j = 0, k, l = 0; if (blen < (bl * 10) + 2) { return; @@ -1171,7 +1171,11 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) } } buf[j++] = ']'; - buf[j++] = '\n'; + buf[j++] = ' '; + if (++l == 6) { + buf[j++] = '\n'; + l = 0; + } } buf[j++] = '\0'; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index fbcc31bafc..978504a1e9 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -35,7 +35,8 @@ #include "zap_isdn.h" #include "Q931.h" #include "Q921.h" - +#define LINE "--------------------------------------------------------------------------------" +#define IODEBUG static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) { @@ -46,12 +47,27 @@ static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { zap_span_t *span = (zap_span_t *) pvt; + zap_isdn_data_t *data = span->isdn_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; + + Q931mes_Restart * restart = (Q931mes_Restart*)msg; + + L3INT ieoff = Q931GetIEOffset(restart->RestartInd); + Q931ie_RestartInd * restartind = (void *)(&restart->buf + (ieoff * sizeof(restart->buf[1]))); + + assert(span != NULL); - - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d\n", gen->MesType); - + assert(data != NULL); + printf("WTF: %d", ((Q931mes_Restart*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Restart*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "send ack %d\n", restartind->Class); + zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Restart*)gen)->Size); + + printf("XXXXXXXXXXXXx"); + gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; + Q931Rx43(&data->q931, msg, 12); + return 0; } @@ -59,11 +75,17 @@ 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; +#ifdef IODEBUG + char bb[512] = ""; + print_bits(msg, (int)len, bb, sizeof(bb), 1); + 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(span->isdn_data->dchan, msg, &len) == ZAP_SUCCESS ? 0 : -1; } - static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; @@ -78,7 +100,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); - + switch(status) { case ZAP_FAIL: { @@ -98,11 +120,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { - /*char bb[512] = ""; - - print_bits(buf, (int)len, bb, sizeof(bb), 1); - zap_log(ZAP_LOG_DEBUG, "Read %d bytes\n%s\n", (int)len, bb); - */ +#ifdef IODEBUG + char bb[512] = ""; + print_bits(buf, (int)len, bb, sizeof(bb), 1); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); +#endif Q921QueueHDLCFrame(&data->q921, buf, (int)len); Q921Rx12(&data->q921); From 11bb923c0ba71a60187a09d64014f62ba5c7885d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 18:25:46 +0000 Subject: [PATCH 0223/1766] remove some extra debug messages git-svn-id: http://svn.openzap.org/svn/openzap/trunk@112 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index e2ab66aa93..2b92190352 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1114,7 +1114,6 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ - printf("WTF: %d\n", Octet); /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) @@ -1127,7 +1126,6 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if(Q931IsIEPresent(pMes->RestartInd)) if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; - printf("WTF: %d\n", Octet); *OSize = Octet; return rc; } From 381d8d8fb275fa2cd13343ae7c6a42d7ebaba546 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 18:25:46 +0000 Subject: [PATCH 0224/1766] remove some extra debug messages git-svn-id: http://svn.openzap.org/svn/openzap/trunk@112 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index e2ab66aa93..2b92190352 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1114,7 +1114,6 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ - printf("WTF: %d\n", Octet); /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) @@ -1127,7 +1126,6 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if(Q931IsIEPresent(pMes->RestartInd)) if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; - printf("WTF: %d\n", Octet); *OSize = Octet; return rc; } From fe0bbb839624479d86be391810737c86d67c5d77 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 19:26:53 +0000 Subject: [PATCH 0225/1766] add some timers git-svn-id: http://svn.openzap.org/svn/openzap/trunk@113 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 108 +++++++++++++++++++++++++-- libs/openzap/src/isdn/include/Q921.h | 7 ++ libs/openzap/src/isdn/include/Q931.h | 1 + 3 files changed, 111 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index e1e326acd9..c69f074812 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -42,6 +42,8 @@ #include #include "mfifo.h" +int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); + /***************************************************************************** Function: Q921_InitTrunk @@ -76,6 +78,10 @@ void Q921_InitTrunk(L2TRUNK trunk, trunk->PrivateData21 = priv21; trunk->PrivateData23 = priv23; trunk->Q921HeaderSpace = hsize; + trunk->T200 = 0; + trunk->T203 = 0; + trunk->T200Timeout = 1000; + trunk->T203Timeout = 10000; } static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) @@ -88,6 +94,98 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); } + +/***************************************************************************** + + Function: Q921TimeTick + + Description: Called periodically from an external source to allow the + stack to process and maintain it's own timers. + + Return Value: none + +*****************************************************************************/ +L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ +static L2ULONG tLast={0}; + +L2ULONG Q921GetTime() +{ + L2ULONG tNow = 0; + if(Q921GetTimeProc != NULL) + { + tNow = Q921GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { + /* TODO */ + } + tLast = tNow; + } + return tNow; +} + +void Q921T200TimerStart(L2TRUNK trunk) +{ + if (!trunk->T200) { + trunk->T200 = Q921GetTime() + trunk->T200Timeout; + } +} + +void Q921T200TimerStop(L2TRUNK trunk) +{ + trunk->T200 = 0; +} + +void Q921T200TimerReset(L2TRUNK trunk) +{ + Q921T200TimerStop(trunk); + Q921T200TimerStart(trunk); +} + +void Q921T203TimerStart(L2TRUNK trunk) +{ + if (!trunk->T203) { + trunk->T203 = Q921GetTime() + trunk->T203Timeout; + } +} + +void Q921T203TimerStop(L2TRUNK trunk) +{ + trunk->T203 = 0; +} + +void Q921T203TimerReset(L2TRUNK trunk) +{ + Q921T203TimerStop(trunk); + Q921T203TimerStart(trunk); +} + +void Q921T200TimerExpire(L2TRUNK trunk) +{ + (void)trunk; +} + +void Q921T203TimerExpire(L2TRUNK trunk) +{ + Q921T203TimerReset(trunk); + Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); +} + +void Q921TimerTick(L2TRUNK trunk) +{ + L2ULONG tNow = Q921GetTime(); + if (trunk->T200 && tNow > trunk->T200) { + Q921T200TimerExpire(trunk); + } + if (trunk->T203 && tNow > trunk->T203) { + Q921T203TimerExpire(trunk); + } +} + + +void Q921SetGetTimeCB(L2ULONG (*callback)()) +{ + Q921GetTimeProc = callback; +} /***************************************************************************** @@ -388,6 +486,9 @@ int Q921Rx12(L2TRUNK trunk) if(smes != NULL) { + rs = size - trunk->Q921HeaderSpace; + mes = &smes[trunk->Q921HeaderSpace]; + if ((mes[2] & 3) != 3) { /* we have an S or I frame */ /* if nr is between va and vs, update our va counter */ @@ -397,9 +498,6 @@ int Q921Rx12(L2TRUNK trunk) } } - rs = size - trunk->Q921HeaderSpace; - mes = &smes[trunk->Q921HeaderSpace]; - /* check for I frame */ if((mes[2] & 0x01) == 0) { @@ -409,7 +507,7 @@ int Q921Rx12(L2TRUNK trunk) if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ { if (vs == trunk->vs) { - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } } else @@ -425,7 +523,7 @@ int Q921Rx12(L2TRUNK trunk) /* todo: we probably should schedule to send RR at timeout here */ /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + Q921T203TimerStart(trunk); } /* check for RNR */ diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 89061c2fdc..672f60b0c5 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -82,6 +82,7 @@ #define Q921MAXHDLCSPACE 3000 #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ +#define L2ULONG unsigned long /* Min 32 bit */ #define L2TRUNK Q921Data_t * typedef enum /* Network/User Mode. */ @@ -105,6 +106,10 @@ struct Q921Data L2UCHAR sapi; L2UCHAR tei; Q921NetUser_t NetUser; + L2ULONG T200; + L2ULONG T203; + L2ULONG T200Timeout; + L2ULONG T203Timeout; Q921TxCB_t Q921Tx21Proc; Q921TxCB_t Q921Tx23Proc; void *PrivateData21; @@ -126,5 +131,7 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Start(L2TRUNK trunk); +void Q921SetGetTimeCB(L2ULONG (*callback)()); +void Q921TimerTick(L2TRUNK trunk); #endif diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index da3466a8d0..b5251e2d7a 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -2406,6 +2406,7 @@ 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 Q931SetGetTimeCB(L3ULONG (*callback)()); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); From b208dfd2377b2ec774335494d259eddd76fdd846 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 19:26:53 +0000 Subject: [PATCH 0226/1766] add some timers git-svn-id: http://svn.openzap.org/svn/openzap/trunk@113 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 108 +++++++++++++++++++++++++-- libs/freetdm/src/isdn/include/Q921.h | 7 ++ libs/freetdm/src/isdn/include/Q931.h | 1 + 3 files changed, 111 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index e1e326acd9..c69f074812 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -42,6 +42,8 @@ #include #include "mfifo.h" +int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); + /***************************************************************************** Function: Q921_InitTrunk @@ -76,6 +78,10 @@ void Q921_InitTrunk(L2TRUNK trunk, trunk->PrivateData21 = priv21; trunk->PrivateData23 = priv23; trunk->Q921HeaderSpace = hsize; + trunk->T200 = 0; + trunk->T203 = 0; + trunk->T200Timeout = 1000; + trunk->T203Timeout = 10000; } static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) @@ -88,6 +94,98 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); } + +/***************************************************************************** + + Function: Q921TimeTick + + Description: Called periodically from an external source to allow the + stack to process and maintain it's own timers. + + Return Value: none + +*****************************************************************************/ +L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ +static L2ULONG tLast={0}; + +L2ULONG Q921GetTime() +{ + L2ULONG tNow = 0; + if(Q921GetTimeProc != NULL) + { + tNow = Q921GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { + /* TODO */ + } + tLast = tNow; + } + return tNow; +} + +void Q921T200TimerStart(L2TRUNK trunk) +{ + if (!trunk->T200) { + trunk->T200 = Q921GetTime() + trunk->T200Timeout; + } +} + +void Q921T200TimerStop(L2TRUNK trunk) +{ + trunk->T200 = 0; +} + +void Q921T200TimerReset(L2TRUNK trunk) +{ + Q921T200TimerStop(trunk); + Q921T200TimerStart(trunk); +} + +void Q921T203TimerStart(L2TRUNK trunk) +{ + if (!trunk->T203) { + trunk->T203 = Q921GetTime() + trunk->T203Timeout; + } +} + +void Q921T203TimerStop(L2TRUNK trunk) +{ + trunk->T203 = 0; +} + +void Q921T203TimerReset(L2TRUNK trunk) +{ + Q921T203TimerStop(trunk); + Q921T203TimerStart(trunk); +} + +void Q921T200TimerExpire(L2TRUNK trunk) +{ + (void)trunk; +} + +void Q921T203TimerExpire(L2TRUNK trunk) +{ + Q921T203TimerReset(trunk); + Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); +} + +void Q921TimerTick(L2TRUNK trunk) +{ + L2ULONG tNow = Q921GetTime(); + if (trunk->T200 && tNow > trunk->T200) { + Q921T200TimerExpire(trunk); + } + if (trunk->T203 && tNow > trunk->T203) { + Q921T203TimerExpire(trunk); + } +} + + +void Q921SetGetTimeCB(L2ULONG (*callback)()) +{ + Q921GetTimeProc = callback; +} /***************************************************************************** @@ -388,6 +486,9 @@ int Q921Rx12(L2TRUNK trunk) if(smes != NULL) { + rs = size - trunk->Q921HeaderSpace; + mes = &smes[trunk->Q921HeaderSpace]; + if ((mes[2] & 3) != 3) { /* we have an S or I frame */ /* if nr is between va and vs, update our va counter */ @@ -397,9 +498,6 @@ int Q921Rx12(L2TRUNK trunk) } } - rs = size - trunk->Q921HeaderSpace; - mes = &smes[trunk->Q921HeaderSpace]; - /* check for I frame */ if((mes[2] & 0x01) == 0) { @@ -409,7 +507,7 @@ int Q921Rx12(L2TRUNK trunk) if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ { if (vs == trunk->vs) { - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01); + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } } else @@ -425,7 +523,7 @@ int Q921Rx12(L2TRUNK trunk) /* todo: we probably should schedule to send RR at timeout here */ /* todo: check if RR is responce to I */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01); + Q921T203TimerStart(trunk); } /* check for RNR */ diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 89061c2fdc..672f60b0c5 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -82,6 +82,7 @@ #define Q921MAXHDLCSPACE 3000 #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ +#define L2ULONG unsigned long /* Min 32 bit */ #define L2TRUNK Q921Data_t * typedef enum /* Network/User Mode. */ @@ -105,6 +106,10 @@ struct Q921Data L2UCHAR sapi; L2UCHAR tei; Q921NetUser_t NetUser; + L2ULONG T200; + L2ULONG T203; + L2ULONG T200Timeout; + L2ULONG T203Timeout; Q921TxCB_t Q921Tx21Proc; Q921TxCB_t Q921Tx23Proc; void *PrivateData21; @@ -126,5 +131,7 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Start(L2TRUNK trunk); +void Q921SetGetTimeCB(L2ULONG (*callback)()); +void Q921TimerTick(L2TRUNK trunk); #endif diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index da3466a8d0..b5251e2d7a 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -2406,6 +2406,7 @@ 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 Q931SetGetTimeCB(L3ULONG (*callback)()); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); From 0ca281c3a9046aa5b59a03319858f561fe405866 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 19:47:35 +0000 Subject: [PATCH 0227/1766] kindof working t203 timer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@114 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q921.h | 4 ++-- libs/openzap/src/zap_isdn.c | 31 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 672f60b0c5..793d256c6b 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -131,7 +131,7 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Start(L2TRUNK trunk); -void Q921SetGetTimeCB(L2ULONG (*callback)()); -void Q921TimerTick(L2TRUNK trunk); +void Q921SetGetTimeCB(L2ULONG (*callback)()); +void Q921TimerTick(L2TRUNK trunk); #endif diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 978504a1e9..e1f59d4565 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -35,9 +35,26 @@ #include "zap_isdn.h" #include "Q931.h" #include "Q921.h" +#ifdef WIN32 +#include +#else +#include +#endif + #define LINE "--------------------------------------------------------------------------------" #define IODEBUG +static L2ULONG zap_time_now() +{ +#ifdef WIN32 + return timeGetTime(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); +#endif +} + static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) { zap_log(ZAP_LOG_ERROR, "ERROR: %d %d %d", id, p1, p2); @@ -93,6 +110,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) unsigned char buf[1024]; zap_size_t len = sizeof(buf); +#ifdef WIN32 + timeBeginPeriod(1); +#endif + zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n"); Q921Start(&data->q921); @@ -100,7 +121,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); - + + Q921TimerTick(&data->q921); + switch(status) { case ZAP_FAIL: { @@ -144,6 +167,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_channel_close(&data->dchans[1]); zap_clear_flag(span->isdn_data, ZAP_ISDN_RUNNING); +#ifdef WIN32 + timeEndPeriod(1); +#endif + zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n"); return NULL; } @@ -151,6 +178,8 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_status_t zap_isdn_init(void) { Q931Initialize(); + + Q921SetGetTimeCB(zap_time_now); return ZAP_SUCCESS; } From 46b96bac7d48b261b883d0acc11091d204e1ac80 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 19:47:35 +0000 Subject: [PATCH 0228/1766] kindof working t203 timer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@114 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q921.h | 4 ++-- libs/freetdm/src/zap_isdn.c | 31 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 672f60b0c5..793d256c6b 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -131,7 +131,7 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Start(L2TRUNK trunk); -void Q921SetGetTimeCB(L2ULONG (*callback)()); -void Q921TimerTick(L2TRUNK trunk); +void Q921SetGetTimeCB(L2ULONG (*callback)()); +void Q921TimerTick(L2TRUNK trunk); #endif diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 978504a1e9..e1f59d4565 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -35,9 +35,26 @@ #include "zap_isdn.h" #include "Q931.h" #include "Q921.h" +#ifdef WIN32 +#include +#else +#include +#endif + #define LINE "--------------------------------------------------------------------------------" #define IODEBUG +static L2ULONG zap_time_now() +{ +#ifdef WIN32 + return timeGetTime(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); +#endif +} + static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) { zap_log(ZAP_LOG_ERROR, "ERROR: %d %d %d", id, p1, p2); @@ -93,6 +110,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) unsigned char buf[1024]; zap_size_t len = sizeof(buf); +#ifdef WIN32 + timeBeginPeriod(1); +#endif + zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n"); Q921Start(&data->q921); @@ -100,7 +121,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); - + + Q921TimerTick(&data->q921); + switch(status) { case ZAP_FAIL: { @@ -144,6 +167,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_channel_close(&data->dchans[1]); zap_clear_flag(span->isdn_data, ZAP_ISDN_RUNNING); +#ifdef WIN32 + timeEndPeriod(1); +#endif + zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n"); return NULL; } @@ -151,6 +178,8 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_status_t zap_isdn_init(void) { Q931Initialize(); + + Q921SetGetTimeCB(zap_time_now); return ZAP_SUCCESS; } From 375100f1a36f0c1f98cb4cbb93166376c6ec2283 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:10:20 +0000 Subject: [PATCH 0229/1766] the size in ie packets is the size of the contents, not the whole ie. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@115 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 42 ++++++++++++++-------------- libs/openzap/src/isdn/include/Q921.h | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 4e7410b120..9aae4a5966 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -410,7 +410,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, } } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -497,7 +497,7 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I OBuf[(*Octet)-1] |= 0x80; /* set complete flag at last octet*/ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -574,7 +574,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -670,7 +670,7 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -763,7 +763,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -877,7 +877,7 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -973,7 +973,7 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1065,7 +1065,7 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN /* Octet 5 - diagnostics not supported in send */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1261,7 +1261,7 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1435,7 +1435,7 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L } } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1518,7 +1518,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = pIE->Display[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1639,7 +1639,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I OBuf[(*Octet)-1] |= 0x80; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1721,7 +1721,7 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = pIE->KeypadFac[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2102,7 +2102,7 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I rc = Q931E_LLCOMP; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2212,7 +2212,7 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 4*/ OBuf[(*Octet)++] = pIE->NetFac; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2288,7 +2288,7 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* Octet 3*/ OBuf[(*Octet)++] = pIE->Notification; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2373,7 +2373,7 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* Octet 4*/ OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2636,7 +2636,7 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* Octet 4 */ OBuf[(*Octet)++] = pIE->SegType; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2767,7 +2767,7 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 3*/ OBuf[(*Octet)++] = pIE->Signal; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2858,7 +2858,7 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf OBuf[(*Octet)++] = pIE->NetID[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2947,7 +2947,7 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L OBuf[(*Octet)++] = pIE->User[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 793d256c6b..97e9e5b867 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -82,7 +82,7 @@ #define Q921MAXHDLCSPACE 3000 #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ -#define L2ULONG unsigned long /* Min 32 bit */ +#define L2ULONG unsigned long /* Min 32 bit */ #define L2TRUNK Q921Data_t * typedef enum /* Network/User Mode. */ From 71f4590889baaff4403ea74de6f54126c291f766 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:10:20 +0000 Subject: [PATCH 0230/1766] the size in ie packets is the size of the contents, not the whole ie. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@115 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 42 ++++++++++++++-------------- libs/freetdm/src/isdn/include/Q921.h | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 4e7410b120..9aae4a5966 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -410,7 +410,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, } } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -497,7 +497,7 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I OBuf[(*Octet)-1] |= 0x80; /* set complete flag at last octet*/ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -574,7 +574,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -670,7 +670,7 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -763,7 +763,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -877,7 +877,7 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -973,7 +973,7 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1065,7 +1065,7 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN /* Octet 5 - diagnostics not supported in send */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1261,7 +1261,7 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1435,7 +1435,7 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L } } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1518,7 +1518,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = pIE->Display[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1639,7 +1639,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I OBuf[(*Octet)-1] |= 0x80; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1721,7 +1721,7 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = pIE->KeypadFac[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2102,7 +2102,7 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I rc = Q931E_LLCOMP; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2212,7 +2212,7 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 4*/ OBuf[(*Octet)++] = pIE->NetFac; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2288,7 +2288,7 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* Octet 3*/ OBuf[(*Octet)++] = pIE->Notification; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2373,7 +2373,7 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* Octet 4*/ OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2636,7 +2636,7 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* Octet 4 */ OBuf[(*Octet)++] = pIE->SegType; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2767,7 +2767,7 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 3*/ OBuf[(*Octet)++] = pIE->Signal; - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2858,7 +2858,7 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf OBuf[(*Octet)++] = pIE->NetID[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -2947,7 +2947,7 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L OBuf[(*Octet)++] = pIE->User[x]; } - OBuf[li] = (L3UCHAR)((*Octet)-Beg); + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 793d256c6b..97e9e5b867 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -82,7 +82,7 @@ #define Q921MAXHDLCSPACE 3000 #define L2UCHAR unsigned char /* Min 8 bit */ #define L2INT int /* Min 16 bit signed */ -#define L2ULONG unsigned long /* Min 32 bit */ +#define L2ULONG unsigned long /* Min 32 bit */ #define L2TRUNK Q921Data_t * typedef enum /* Network/User Mode. */ From cfcaaa148b1742b6abda8d51ce5dfeed6ffb3fcf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:15:05 +0000 Subject: [PATCH 0231/1766] set the ie to point to the first byte of the ie struct, not the last. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@116 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 106 ++++++++++++++++----------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 9aae4a5966..1435e3abc7 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -285,12 +285,12 @@ L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH Q931IESizeTest(Q931E_BEARERCAP); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_BearerCap); pie->Size = sizeof(Q931ie_BearerCap); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -457,12 +457,12 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_CALLID); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -542,12 +542,12 @@ L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA Q931IESizeTest(Q931E_CALLSTATE); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallState); pie->Size = sizeof(Q931ie_CallState); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -626,12 +626,12 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA Q931IESizeTest(Q931E_CALLEDSUB); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -719,12 +719,12 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH Off++; } - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -823,12 +823,12 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC Q931IESizeTest(Q931E_CALLINGNUM); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -929,12 +929,12 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1025,12 +1025,12 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_CAUSE); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Cause); pie->Size = sizeof(Q931ie_Cause); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1097,12 +1097,12 @@ L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH pie->CongLevel = IBuf[Octet] & 0x0f; Octet ++; + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CongLevel); pie->Size = sizeof(Q931ie_CongLevel); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1204,12 +1204,12 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_CHANID); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_BearerCap); pie->Size = sizeof(Q931ie_BearerCap); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1389,12 +1389,12 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR Q931IESizeTest(Q931E_DATETIME); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_DateTime); pie->Size = sizeof(Q931ie_DateTime); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1478,12 +1478,12 @@ L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1589,12 +1589,12 @@ L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_HLCOMP); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_HLComp); pie->Size = sizeof(Q931ie_HLComp); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1682,12 +1682,12 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1937,12 +1937,12 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_LLCOMP); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_LLComp); pie->Size = sizeof(Q931ie_LLComp); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2163,12 +2163,12 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2255,12 +2255,12 @@ L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_NOTIFIND); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_NotifInd); pie->Size = sizeof(Q931ie_NotifInd); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2337,12 +2337,12 @@ L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_PROGIND); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_ProgInd); pie->Size = sizeof(Q931ie_ProgInd); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2405,12 +2405,12 @@ L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA pie->RepeatInd = IBuf[Octet] & 0x0f; Octet ++; + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); pie->Size = sizeof(Q931ie_RepeatInd); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2600,12 +2600,12 @@ L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_SEGMENT); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Segment); pie->Size = sizeof(Q931ie_Segment); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2666,12 +2666,12 @@ L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3U Octet ++; + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_SendComplete); pie->Size = sizeof(Q931ie_SendComplete); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2734,12 +2734,12 @@ L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_SIGNAL); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Signal); pie->Size = sizeof(Q931ie_Signal); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2816,12 +2816,12 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UC Off++; } + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2905,12 +2905,12 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Off++; } + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } From 5de359b32d7b623101605ef0cd00ff5185fb7c6a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:15:05 +0000 Subject: [PATCH 0232/1766] set the ie to point to the first byte of the ie struct, not the last. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@116 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 106 ++++++++++++++++----------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 9aae4a5966..1435e3abc7 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -285,12 +285,12 @@ L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH Q931IESizeTest(Q931E_BEARERCAP); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_BearerCap); pie->Size = sizeof(Q931ie_BearerCap); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -457,12 +457,12 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_CALLID); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallID) + x -1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x -1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -542,12 +542,12 @@ L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA Q931IESizeTest(Q931E_CALLSTATE); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallState); pie->Size = sizeof(Q931ie_CallState); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -626,12 +626,12 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA Q931IESizeTest(Q931E_CALLEDSUB); - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -719,12 +719,12 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH Off++; } - *IOff = (*IOff) + Octet + Off; + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -823,12 +823,12 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC Q931IESizeTest(Q931E_CALLINGNUM); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -929,12 +929,12 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1025,12 +1025,12 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_CAUSE); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Cause); pie->Size = sizeof(Q931ie_Cause); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1097,12 +1097,12 @@ L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH pie->CongLevel = IBuf[Octet] & 0x0f; Octet ++; + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_CongLevel); pie->Size = sizeof(Q931ie_CongLevel); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1204,12 +1204,12 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_CHANID); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_BearerCap); pie->Size = sizeof(Q931ie_BearerCap); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1389,12 +1389,12 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR Q931IESizeTest(Q931E_DATETIME); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_DateTime); pie->Size = sizeof(Q931ie_DateTime); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1478,12 +1478,12 @@ L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1589,12 +1589,12 @@ L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_HLCOMP); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_HLComp); pie->Size = sizeof(Q931ie_HLComp); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1682,12 +1682,12 @@ L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -1937,12 +1937,12 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_LLCOMP); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_LLComp); pie->Size = sizeof(Q931ie_LLComp); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2163,12 +2163,12 @@ L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * 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); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2255,12 +2255,12 @@ L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_NOTIFIND); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_NotifInd); pie->Size = sizeof(Q931ie_NotifInd); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2337,12 +2337,12 @@ L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_PROGIND); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_ProgInd); pie->Size = sizeof(Q931ie_ProgInd); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2405,12 +2405,12 @@ L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA pie->RepeatInd = IBuf[Octet] & 0x0f; Octet ++; + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); pie->Size = sizeof(Q931ie_RepeatInd); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2600,12 +2600,12 @@ L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Q931IESizeTest(Q931E_SEGMENT); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Segment); pie->Size = sizeof(Q931ie_Segment); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2666,12 +2666,12 @@ L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3U Octet ++; + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_SendComplete); pie->Size = sizeof(Q931ie_SendComplete); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2734,12 +2734,12 @@ L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * Q931IESizeTest(Q931E_SIGNAL); + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_Signal); pie->Size = sizeof(Q931ie_Signal); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2816,12 +2816,12 @@ L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UC Off++; } + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } @@ -2905,12 +2905,12 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR Off++; } + Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); - Q931SetIE(*pIE, *OOff); - return Q931E_NO_ERROR; } From 6228923000ebce1bca52c45d5053de07f2eb72b4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:27:03 +0000 Subject: [PATCH 0233/1766] unpack ie's into the ie buffer space, not overwriting the rest of the message structure. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@117 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 167 ++++++++++++++++---------------- 1 file changed, 83 insertions(+), 84 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 2b92190352..96a8309333 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -62,32 +62,32 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(mescode) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -171,27 +171,27 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -301,42 +301,42 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -430,13 +430,13 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -499,22 +499,22 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -586,25 +586,25 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -681,19 +681,19 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -754,27 +754,27 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -850,17 +850,17 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -925,17 +925,17 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1071,17 +1071,17 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1104,7 +1104,6 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3INT rc = Q931E_NO_ERROR; Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; L3INT Octet = 0; - *OSize = 0; /* Q931 Message Header */ @@ -1124,9 +1123,9 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, return rc; /* RestartInd */ if(Q931IsIEPresent(pMes->RestartInd)) - if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; - *OSize = Octet; + return rc; } @@ -1147,7 +1146,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1204,12 +1203,12 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1271,12 +1270,12 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1352,19 +1351,19 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: if(ir==0) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else if(ir==1) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else @@ -1373,77 +1372,77 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } break; case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1601,22 +1600,22 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1688,17 +1687,17 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1764,7 +1763,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1821,7 +1820,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1879,7 +1878,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1936,12 +1935,12 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; From 9cf72575f1b754cb58e0e8c85e1634d6e68cb3bf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:27:03 +0000 Subject: [PATCH 0234/1766] unpack ie's into the ie buffer space, not overwriting the rest of the message structure. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@117 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 167 ++++++++++++++++---------------- 1 file changed, 83 insertions(+), 84 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 2b92190352..96a8309333 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -62,32 +62,32 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(mescode) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -171,27 +171,27 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -301,42 +301,42 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -430,13 +430,13 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -499,22 +499,22 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -586,25 +586,25 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -681,19 +681,19 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -754,27 +754,27 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -850,17 +850,17 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -925,17 +925,17 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1071,17 +1071,17 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1104,7 +1104,6 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3INT rc = Q931E_NO_ERROR; Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; L3INT Octet = 0; - *OSize = 0; /* Q931 Message Header */ @@ -1124,9 +1123,9 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, return rc; /* RestartInd */ if(Q931IsIEPresent(pMes->RestartInd)) - if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; - *OSize = Octet; + return rc; } @@ -1147,7 +1146,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1204,12 +1203,12 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1271,12 +1270,12 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1352,19 +1351,19 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: if(ir==0) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else if(ir==1) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else @@ -1373,77 +1372,77 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } break; case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1601,22 +1600,22 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1688,17 +1687,17 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1764,7 +1763,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1821,7 +1820,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1879,7 +1878,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1936,12 +1935,12 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &OBuf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; From 52bed6bc1b2592965e260a07069294291eeb04a3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:47:59 +0000 Subject: [PATCH 0235/1766] pass the correct index to the Q931Pie table for the ie pack function. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@118 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 160 ++++++++++++++++---------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 96a8309333..409c37bee6 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -122,33 +122,33 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3U /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -226,28 +226,28 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISiz /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -371,43 +371,43 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -471,12 +471,12 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -548,22 +548,22 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -643,22 +643,22 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -725,13 +725,13 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -809,25 +809,25 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -894,15 +894,15 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -969,15 +969,15 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1042,15 +1042,15 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1115,15 +1115,15 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1180,7 +1180,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1243,11 +1243,11 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1309,12 +1309,12 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1498,7 +1498,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) return rc; } else @@ -1508,62 +1508,62 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0) return rc; /* Repeat Indicator */ @@ -1572,12 +1572,12 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH /* Low Layer Compatibility */ if(Q931IsIEPresent(pMes->LLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1649,22 +1649,22 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1732,15 +1732,15 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1797,7 +1797,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1854,7 +1854,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1912,7 +1912,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1974,12 +1974,12 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; From f7c8f572706f7ab4b38d7298ae09dcd87391f464 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 20:47:59 +0000 Subject: [PATCH 0236/1766] pass the correct index to the Q931Pie table for the ie pack function. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@118 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 160 ++++++++++++++++---------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 96a8309333..409c37bee6 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -122,33 +122,33 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3U /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -226,28 +226,28 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISiz /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -371,43 +371,43 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -471,12 +471,12 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -548,22 +548,22 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -643,22 +643,22 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -725,13 +725,13 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -809,25 +809,25 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -894,15 +894,15 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -969,15 +969,15 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1042,15 +1042,15 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1115,15 +1115,15 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1180,7 +1180,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1243,11 +1243,11 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1309,12 +1309,12 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1498,7 +1498,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) { - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_BEARER_CAPABILITY](pTrunk, Q931GetIEPtr(pMes->BearerCap,pMes->buf), OBuf, &Octet))!=0) return rc; } else @@ -1508,62 +1508,62 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->NetFac,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->DateTime,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->KeypadFac,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingNum,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallingSub,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CalledSub,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_TRANSIT_NETWORK_SELECTION](pTrunk, Q931GetIEPtr(pMes->TransNetSel,pMes->buf), OBuf, &Octet))!=0) return rc; /* Repeat Indicator */ @@ -1572,12 +1572,12 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH /* Low Layer Compatibility */ if(Q931IsIEPresent(pMes->LLComp)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->LLComp,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1649,22 +1649,22 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->ProgInd,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1732,15 +1732,15 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallState,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1797,7 +1797,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1854,7 +1854,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1912,7 +1912,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, /* Display */ if(Q931IsIEPresent(pMes->Display)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; @@ -1974,12 +1974,12 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz /* Cause */ if(Q931IsIEPresent(pMes->Cause)) - if((rc=Q931Pie[pTrunk->Dialect][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Cause,pMes->buf), OBuf, &Octet))!=0) + 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][pMes->MesType](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) + if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; return rc; From 2b9ed2d39811aa207aa049ed649c0a289696b488 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 21:06:33 +0000 Subject: [PATCH 0237/1766] Return the correct size from the Q931Pmes functions git-svn-id: http://svn.openzap.org/svn/openzap/trunk@119 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 409c37bee6..b1c9851611 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -151,6 +151,8 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -250,6 +252,8 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISiz if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -281,6 +285,8 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT I NoWarning(OBuf); NoWarning(IBuf); + *OSize = 0; + return RetCode; } @@ -410,6 +416,8 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -479,6 +487,8 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -566,6 +576,8 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -661,6 +673,8 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -734,6 +748,8 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -830,6 +846,8 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -905,6 +923,8 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -980,6 +1000,8 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1053,6 +1075,8 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1125,6 +1149,8 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, 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; } @@ -1183,6 +1209,8 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1250,6 +1278,8 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1317,6 +1347,8 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1331,6 +1363,8 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U { L3BOOL RetCode = L3FALSE; + *OSize = 0; + return RetCode; } @@ -1580,6 +1614,8 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1667,6 +1703,8 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1743,6 +1781,8 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1800,6 +1840,8 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1857,6 +1899,8 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1915,6 +1959,8 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1982,6 +2028,8 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -2012,6 +2060,8 @@ L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS NoWarning(OBuf); NoWarning(IBuf); + *OSize = 0; + return RetCode; } From 0d8ef69f03a08bb5b189f77efa0ad7b6ddbb96af Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 21:06:33 +0000 Subject: [PATCH 0238/1766] Return the correct size from the Q931Pmes functions git-svn-id: http://svn.openzap.org/svn/openzap/trunk@119 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 409c37bee6..b1c9851611 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -151,6 +151,8 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -250,6 +252,8 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISiz if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -281,6 +285,8 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT I NoWarning(OBuf); NoWarning(IBuf); + *OSize = 0; + return RetCode; } @@ -410,6 +416,8 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -479,6 +487,8 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -566,6 +576,8 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -661,6 +673,8 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALLED_PARTY_NUMBER](pTrunk, Q931GetIEPtr(pMes->CalledNum,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -734,6 +748,8 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -830,6 +846,8 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -905,6 +923,8 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -980,6 +1000,8 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1053,6 +1075,8 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1125,6 +1149,8 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, 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; } @@ -1183,6 +1209,8 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1250,6 +1278,8 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1317,6 +1347,8 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1331,6 +1363,8 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U { L3BOOL RetCode = L3FALSE; + *OSize = 0; + return RetCode; } @@ -1580,6 +1614,8 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH if((rc=Q931Pie[pTrunk->Dialect][Q931ie_HIGH_LAYER_COMPATIBILITY](pTrunk, Q931GetIEPtr(pMes->HLComp,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1667,6 +1703,8 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 if((rc=Q931Pie[pTrunk->Dialect][Q931ie_SIGNAL](pTrunk, Q931GetIEPtr(pMes->Signal,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1743,6 +1781,8 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1800,6 +1840,8 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1857,6 +1899,8 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1915,6 +1959,8 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -1982,6 +2028,8 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0) return rc; + *OSize = Octet; + return rc; } @@ -2012,6 +2060,8 @@ L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS NoWarning(OBuf); NoWarning(IBuf); + *OSize = 0; + return RetCode; } From 04ac959cbcbcb2fc55fb2f41d02b8bf4a9a63888 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 21:15:38 +0000 Subject: [PATCH 0239/1766] big enough buffer for the whole message for our debug git-svn-id: http://svn.openzap.org/svn/openzap/trunk@120 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index e1f59d4565..d952aa3418 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -93,7 +93,7 @@ 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; #ifdef IODEBUG - char bb[512] = ""; + char bb[4096] = ""; print_bits(msg, (int)len, bb, sizeof(bb), 1); zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb); @@ -144,7 +144,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG - char bb[512] = ""; + char bb[4096] = ""; print_bits(buf, (int)len, bb, sizeof(bb), 1); zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif From 56a341e2ce6fcf779abb42362e9f4ccd6a8d5752 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 May 2007 21:15:38 +0000 Subject: [PATCH 0240/1766] big enough buffer for the whole message for our debug git-svn-id: http://svn.openzap.org/svn/openzap/trunk@120 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index e1f59d4565..d952aa3418 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -93,7 +93,7 @@ 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; #ifdef IODEBUG - char bb[512] = ""; + char bb[4096] = ""; print_bits(msg, (int)len, bb, sizeof(bb), 1); zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb); @@ -144,7 +144,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG - char bb[512] = ""; + char bb[4096] = ""; print_bits(buf, (int)len, bb, sizeof(bb), 1); zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif From 9e864e6ed7c850fd4fa55cc42dbaa85e1930cf45 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 22:58:56 +0000 Subject: [PATCH 0241/1766] quick hack to try to get somthing working. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@121 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 1435e3abc7..46e0173aa4 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -819,7 +819,8 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); +/* }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Temporary dirty hack. */ + }while(Octet+Off < IESize); Q931IESizeTest(Q931E_CALLINGNUM); From 2366b78c8a51028254ef5e2af9eef7d25da55cad Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 23 May 2007 22:58:56 +0000 Subject: [PATCH 0242/1766] quick hack to try to get somthing working. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@121 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 1435e3abc7..46e0173aa4 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -819,7 +819,8 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); +/* }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Temporary dirty hack. */ + }while(Octet+Off < IESize); Q931IESizeTest(Q931E_CALLINGNUM); From 1ba035044f23250300a71112fd373bc7102c1b60 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 00:51:56 +0000 Subject: [PATCH 0243/1766] make this work for a few more things.. this will probably need to move to a dialect git-svn-id: http://svn.openzap.org/svn/openzap/trunk@122 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 46e0173aa4..f6d29610d9 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -820,7 +820,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC Off++; x++; /* }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Temporary dirty hack. */ - }while(Octet+Off < IESize); + }while(Q931MoreIE()); Q931IESizeTest(Q931E_CALLINGNUM); From 37bc1f714ad5ddf9c6d22c0872dcbc9e72ff578a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 00:51:56 +0000 Subject: [PATCH 0244/1766] make this work for a few more things.. this will probably need to move to a dialect git-svn-id: http://svn.openzap.org/svn/openzap/trunk@122 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 46e0173aa4..f6d29610d9 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -820,7 +820,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC Off++; x++; /* }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Temporary dirty hack. */ - }while(Octet+Off < IESize); + }while(Q931MoreIE()); Q931IESizeTest(Q931E_CALLINGNUM); From 6e28089604f732ba31b4981b03b9c193710d3c34 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 00:53:06 +0000 Subject: [PATCH 0245/1766] this is much more correct, we respond to the NT sending RR commands instead of us sending RR commands on the timer. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@123 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index c69f074812..6a35596762 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -501,14 +501,12 @@ int Q921Rx12(L2TRUNK trunk) /* check for I frame */ if((mes[2] & 0x01) == 0) { - L2INT vs = trunk->vs; + /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ trunk->vr++; if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ { - if (vs == trunk->vs) { - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); - } + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } else { @@ -519,11 +517,11 @@ int Q921Rx12(L2TRUNK trunk) /* check for RR */ else if(mes[2] ==0x01) - { - - /* todo: we probably should schedule to send RR at timeout here */ - /* todo: check if RR is responce to I */ - Q921T203TimerStart(trunk); + { + if (((mes[0]>>1)&0x01) == (trunk->NetUser == Q921_TE ? 1 : 0)) { /* if this is a command */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[2]&0x01); + } + } /* check for RNR */ From 06f3ac640269495c18d4a61aa03362168d7b7de6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 00:53:06 +0000 Subject: [PATCH 0246/1766] this is much more correct, we respond to the NT sending RR commands instead of us sending RR commands on the timer. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@123 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index c69f074812..6a35596762 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -501,14 +501,12 @@ int Q921Rx12(L2TRUNK trunk) /* check for I frame */ if((mes[2] & 0x01) == 0) { - L2INT vs = trunk->vs; + /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ trunk->vr++; if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ { - if (vs == trunk->vs) { - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); - } + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } else { @@ -519,11 +517,11 @@ int Q921Rx12(L2TRUNK trunk) /* check for RR */ else if(mes[2] ==0x01) - { - - /* todo: we probably should schedule to send RR at timeout here */ - /* todo: check if RR is responce to I */ - Q921T203TimerStart(trunk); + { + if (((mes[0]>>1)&0x01) == (trunk->NetUser == Q921_TE ? 1 : 0)) { /* if this is a command */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[2]&0x01); + } + } /* check for RNR */ From 9c21da494e59f00a2a6553c2e17f4f74fc27fa1f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 01:01:50 +0000 Subject: [PATCH 0247/1766] uninitialized var. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@124 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index d952aa3418..2ac84395e5 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -192,7 +192,7 @@ zap_status_t zap_isdn_start(zap_span_t *span) zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) { - uint32_t x,i; + uint32_t i, x = 0; zap_channel_t *dchans[2] = {0}; if (span->signal_type) { From 479657d1af613ad746321e4ac2ee1543662ea027 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 01:01:50 +0000 Subject: [PATCH 0248/1766] uninitialized var. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@124 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index d952aa3418..2ac84395e5 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -192,7 +192,7 @@ zap_status_t zap_isdn_start(zap_span_t *span) zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) { - uint32_t x,i; + uint32_t i, x = 0; zap_channel_t *dchans[2] = {0}; if (span->signal_type) { From 89046a6e5b766d61d024ded0faec17a37326c59c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 01:02:13 +0000 Subject: [PATCH 0249/1766] add zap_isdn.c to windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@125 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index f9eb82b703..af00754f66 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -184,6 +184,10 @@ RelativePath=".\src\zap_io.c" > + + @@ -304,6 +308,10 @@ RelativePath=".\src\include\zap_config.h" > + + From 743414e00f3630f4ea70f36df119f92555c7786e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 01:02:13 +0000 Subject: [PATCH 0250/1766] add zap_isdn.c to windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@125 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index f9eb82b703..af00754f66 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -184,6 +184,10 @@ RelativePath=".\src\zap_io.c" > + + @@ -304,6 +308,10 @@ RelativePath=".\src\include\zap_config.h" > + + From 96de29a23b92cf1705c8e3e1b7e2c7750c9e4e6d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 01:02:25 +0000 Subject: [PATCH 0251/1766] dos2unix. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@126 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 182 +++++++++++++++++------------------ 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 6a35596762..944a8a5a31 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -94,98 +94,98 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); } - -/***************************************************************************** - - Function: Q921TimeTick - - Description: Called periodically from an external source to allow the - stack to process and maintain it's own timers. - - Return Value: none - -*****************************************************************************/ -L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ -static L2ULONG tLast={0}; - -L2ULONG Q921GetTime() -{ - L2ULONG tNow = 0; - if(Q921GetTimeProc != NULL) - { - tNow = Q921GetTimeProc(); - if(tNow < tLast) /* wrapped */ - { - /* TODO */ - } - tLast = tNow; - } - return tNow; -} - -void Q921T200TimerStart(L2TRUNK trunk) -{ - if (!trunk->T200) { - trunk->T200 = Q921GetTime() + trunk->T200Timeout; - } -} - -void Q921T200TimerStop(L2TRUNK trunk) -{ - trunk->T200 = 0; -} - -void Q921T200TimerReset(L2TRUNK trunk) -{ - Q921T200TimerStop(trunk); - Q921T200TimerStart(trunk); -} -void Q921T203TimerStart(L2TRUNK trunk) -{ - if (!trunk->T203) { - trunk->T203 = Q921GetTime() + trunk->T203Timeout; - } -} - -void Q921T203TimerStop(L2TRUNK trunk) -{ - trunk->T203 = 0; -} - -void Q921T203TimerReset(L2TRUNK trunk) -{ - Q921T203TimerStop(trunk); - Q921T203TimerStart(trunk); -} - -void Q921T200TimerExpire(L2TRUNK trunk) -{ - (void)trunk; -} - -void Q921T203TimerExpire(L2TRUNK trunk) -{ - Q921T203TimerReset(trunk); - Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); -} - -void Q921TimerTick(L2TRUNK trunk) -{ - L2ULONG tNow = Q921GetTime(); - if (trunk->T200 && tNow > trunk->T200) { - Q921T200TimerExpire(trunk); - } - if (trunk->T203 && tNow > trunk->T203) { - Q921T203TimerExpire(trunk); - } -} - - -void Q921SetGetTimeCB(L2ULONG (*callback)()) -{ - Q921GetTimeProc = callback; -} +/***************************************************************************** + + Function: Q921TimeTick + + Description: Called periodically from an external source to allow the + stack to process and maintain it's own timers. + + Return Value: none + +*****************************************************************************/ +L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ +static L2ULONG tLast={0}; + +L2ULONG Q921GetTime() +{ + L2ULONG tNow = 0; + if(Q921GetTimeProc != NULL) + { + tNow = Q921GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { + /* TODO */ + } + tLast = tNow; + } + return tNow; +} + +void Q921T200TimerStart(L2TRUNK trunk) +{ + if (!trunk->T200) { + trunk->T200 = Q921GetTime() + trunk->T200Timeout; + } +} + +void Q921T200TimerStop(L2TRUNK trunk) +{ + trunk->T200 = 0; +} + +void Q921T200TimerReset(L2TRUNK trunk) +{ + Q921T200TimerStop(trunk); + Q921T200TimerStart(trunk); +} + +void Q921T203TimerStart(L2TRUNK trunk) +{ + if (!trunk->T203) { + trunk->T203 = Q921GetTime() + trunk->T203Timeout; + } +} + +void Q921T203TimerStop(L2TRUNK trunk) +{ + trunk->T203 = 0; +} + +void Q921T203TimerReset(L2TRUNK trunk) +{ + Q921T203TimerStop(trunk); + Q921T203TimerStart(trunk); +} + +void Q921T200TimerExpire(L2TRUNK trunk) +{ + (void)trunk; +} + +void Q921T203TimerExpire(L2TRUNK trunk) +{ + Q921T203TimerReset(trunk); + Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); +} + +void Q921TimerTick(L2TRUNK trunk) +{ + L2ULONG tNow = Q921GetTime(); + if (trunk->T200 && tNow > trunk->T200) { + Q921T200TimerExpire(trunk); + } + if (trunk->T203 && tNow > trunk->T203) { + Q921T203TimerExpire(trunk); + } +} + + +void Q921SetGetTimeCB(L2ULONG (*callback)()) +{ + Q921GetTimeProc = callback; +} /***************************************************************************** From 397eebfd0942c8e8f05e041684d5b80e986c7b9a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 01:02:25 +0000 Subject: [PATCH 0252/1766] dos2unix. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@126 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 182 +++++++++++++++++------------------ 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 6a35596762..944a8a5a31 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -94,98 +94,98 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) return trunk->Q921Tx23Proc(trunk->PrivateData23, Msg, size); } - -/***************************************************************************** - - Function: Q921TimeTick - - Description: Called periodically from an external source to allow the - stack to process and maintain it's own timers. - - Return Value: none - -*****************************************************************************/ -L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ -static L2ULONG tLast={0}; - -L2ULONG Q921GetTime() -{ - L2ULONG tNow = 0; - if(Q921GetTimeProc != NULL) - { - tNow = Q921GetTimeProc(); - if(tNow < tLast) /* wrapped */ - { - /* TODO */ - } - tLast = tNow; - } - return tNow; -} - -void Q921T200TimerStart(L2TRUNK trunk) -{ - if (!trunk->T200) { - trunk->T200 = Q921GetTime() + trunk->T200Timeout; - } -} - -void Q921T200TimerStop(L2TRUNK trunk) -{ - trunk->T200 = 0; -} - -void Q921T200TimerReset(L2TRUNK trunk) -{ - Q921T200TimerStop(trunk); - Q921T200TimerStart(trunk); -} -void Q921T203TimerStart(L2TRUNK trunk) -{ - if (!trunk->T203) { - trunk->T203 = Q921GetTime() + trunk->T203Timeout; - } -} - -void Q921T203TimerStop(L2TRUNK trunk) -{ - trunk->T203 = 0; -} - -void Q921T203TimerReset(L2TRUNK trunk) -{ - Q921T203TimerStop(trunk); - Q921T203TimerStart(trunk); -} - -void Q921T200TimerExpire(L2TRUNK trunk) -{ - (void)trunk; -} - -void Q921T203TimerExpire(L2TRUNK trunk) -{ - Q921T203TimerReset(trunk); - Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); -} - -void Q921TimerTick(L2TRUNK trunk) -{ - L2ULONG tNow = Q921GetTime(); - if (trunk->T200 && tNow > trunk->T200) { - Q921T200TimerExpire(trunk); - } - if (trunk->T203 && tNow > trunk->T203) { - Q921T203TimerExpire(trunk); - } -} - - -void Q921SetGetTimeCB(L2ULONG (*callback)()) -{ - Q921GetTimeProc = callback; -} +/***************************************************************************** + + Function: Q921TimeTick + + Description: Called periodically from an external source to allow the + stack to process and maintain it's own timers. + + Return Value: none + +*****************************************************************************/ +L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ +static L2ULONG tLast={0}; + +L2ULONG Q921GetTime() +{ + L2ULONG tNow = 0; + if(Q921GetTimeProc != NULL) + { + tNow = Q921GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { + /* TODO */ + } + tLast = tNow; + } + return tNow; +} + +void Q921T200TimerStart(L2TRUNK trunk) +{ + if (!trunk->T200) { + trunk->T200 = Q921GetTime() + trunk->T200Timeout; + } +} + +void Q921T200TimerStop(L2TRUNK trunk) +{ + trunk->T200 = 0; +} + +void Q921T200TimerReset(L2TRUNK trunk) +{ + Q921T200TimerStop(trunk); + Q921T200TimerStart(trunk); +} + +void Q921T203TimerStart(L2TRUNK trunk) +{ + if (!trunk->T203) { + trunk->T203 = Q921GetTime() + trunk->T203Timeout; + } +} + +void Q921T203TimerStop(L2TRUNK trunk) +{ + trunk->T203 = 0; +} + +void Q921T203TimerReset(L2TRUNK trunk) +{ + Q921T203TimerStop(trunk); + Q921T203TimerStart(trunk); +} + +void Q921T200TimerExpire(L2TRUNK trunk) +{ + (void)trunk; +} + +void Q921T203TimerExpire(L2TRUNK trunk) +{ + Q921T203TimerReset(trunk); + Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); +} + +void Q921TimerTick(L2TRUNK trunk) +{ + L2ULONG tNow = Q921GetTime(); + if (trunk->T200 && tNow > trunk->T200) { + Q921T200TimerExpire(trunk); + } + if (trunk->T203 && tNow > trunk->T203) { + Q921T203TimerExpire(trunk); + } +} + + +void Q921SetGetTimeCB(L2ULONG (*callback)()) +{ + Q921GetTimeProc = callback; +} /***************************************************************************** From 7ebb574f030f902ada7ad224fee07487559652c9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 01:55:26 +0000 Subject: [PATCH 0253/1766] revert back to previous api for 921 callbacks expected return git-svn-id: http://svn.openzap.org/svn/openzap/trunk@127 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 2 +- libs/openzap/src/zap_isdn.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 944a8a5a31..7b084fe230 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -504,7 +504,7 @@ int Q921Rx12(L2TRUNK trunk) /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ trunk->vr++; - if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ + if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ { Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 2ac84395e5..339dd02a73 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -88,6 +88,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) return 0; } +static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) +{ + return ((Q931Rx23(pvt, msg, mlen) >= 0) ? 1 : 0); +} + static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) { zap_span_t *span = (zap_span_t *) pvt; @@ -235,7 +240,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D mode, 0, zap_isdn_921_21, - (Q921TxCB_t)Q931Rx23, + (Q921TxCB_t)zap_isdn_921_23, span, &span->isdn_data->q931); From e79c497e6e8fdd38f92e72a88670faa5ea7f191f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 01:55:26 +0000 Subject: [PATCH 0254/1766] revert back to previous api for 921 callbacks expected return git-svn-id: http://svn.openzap.org/svn/openzap/trunk@127 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 2 +- libs/freetdm/src/zap_isdn.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 944a8a5a31..7b084fe230 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -504,7 +504,7 @@ int Q921Rx12(L2TRUNK trunk) /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ trunk->vr++; - if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */ + if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ { Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 2ac84395e5..339dd02a73 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -88,6 +88,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) return 0; } +static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) +{ + return ((Q931Rx23(pvt, msg, mlen) >= 0) ? 1 : 0); +} + static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) { zap_span_t *span = (zap_span_t *) pvt; @@ -235,7 +240,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D mode, 0, zap_isdn_921_21, - (Q921TxCB_t)Q931Rx23, + (Q921TxCB_t)zap_isdn_921_23, span, &span->isdn_data->q931); From a4363ac2a9905c5ce3a58e96db10099e5ab39d81 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 01:59:26 +0000 Subject: [PATCH 0255/1766] add debug error msg for 931 parse error git-svn-id: http://svn.openzap.org/svn/openzap/trunk@128 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 339dd02a73..814a19c237 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -90,7 +90,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { - return ((Q931Rx23(pvt, msg, mlen) >= 0) ? 1 : 0); + int ret = Q931Rx23(pvt, msg, mlen); + if (ret != 0) + zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] \n", ret); + return ((ret >= 0) ? 1 : 0); } static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) From bb1e193a4168deab14fb415321ee52417e6d9ab5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 01:59:26 +0000 Subject: [PATCH 0256/1766] add debug error msg for 931 parse error git-svn-id: http://svn.openzap.org/svn/openzap/trunk@128 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 339dd02a73..814a19c237 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -90,7 +90,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { - return ((Q931Rx23(pvt, msg, mlen) >= 0) ? 1 : 0); + int ret = Q931Rx23(pvt, msg, mlen); + if (ret != 0) + zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] \n", ret); + return ((ret >= 0) ? 1 : 0); } static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) From 4b46d222e629e826a1516c79394b3f823ae68a6c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 02:27:08 +0000 Subject: [PATCH 0257/1766] ease debugging for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@129 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 7b084fe230..10e90972fb 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -511,7 +511,9 @@ int Q921Rx12(L2TRUNK trunk) else { /* todo: whatever*/ - trunk->vr--; + /* trunk->vr--; */ + /* for now, lets just respond for easier debugging on errors */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } } From 17c249c2106d515e4bf4b648d189206043d2f867 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 02:27:08 +0000 Subject: [PATCH 0258/1766] ease debugging for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@129 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 7b084fe230..10e90972fb 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -511,7 +511,9 @@ int Q921Rx12(L2TRUNK trunk) else { /* todo: whatever*/ - trunk->vr--; + /* trunk->vr--; */ + /* for now, lets just respond for easier debugging on errors */ + Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); } } From 6e8a5139ec63383954ed72bde1745a64197ac461 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 03:42:40 +0000 Subject: [PATCH 0259/1766] add basics for analog (wip) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@130 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 5 +- libs/openzap/src/include/openzap.h | 40 +++++ libs/openzap/src/include/zap_analog.h | 48 ++++++ libs/openzap/src/include/zap_types.h | 34 ++++- libs/openzap/src/testanalog.c | 36 +++++ libs/openzap/src/zap_analog.c | 209 ++++++++++++++++++++++++++ libs/openzap/src/zap_io.c | 186 ++++++++++++++++++++++- libs/openzap/src/zap_wanpipe.c | 166 +++++++++++++++++++- 8 files changed, 709 insertions(+), 15 deletions(-) create mode 100644 libs/openzap/src/include/zap_analog.h create mode 100644 libs/openzap/src/testanalog.c diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 8041ea3a7d..8e9ba7b093 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -73,6 +73,9 @@ testapp: testapp.c $(MYLIB) testisdn: testisdn.c $(MYLIB) $(CC) $(INCS) -L. testisdn.c -o testisdn -lopenzap -lm -lpthread +testanalog: testanalog.c $(MYLIB) + $(CC) $(INCS) -L. testanalog.c -o testanalog -lopenzap -lm -lpthread + priserver.o: priserver.c $(CC) $(INCS) $(TMP) -c priserver.c -o priserver.o @@ -95,5 +98,5 @@ zap_zt.o: zap_zt.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver + rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 5a0f74fafa..8235d30846 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -74,6 +74,11 @@ #pragma warning(disable:4706) #endif +#ifndef WIN32 +#include +#include +#endif + #include #include #include @@ -91,6 +96,8 @@ #include "Q931.h" #include "Q921.h" +#define XX if (0) + #ifdef NDEBUG #undef assert #define assert(_Expression) ((void)(_Expression)) @@ -131,6 +138,11 @@ */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) +#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL);\ +zap_mutex_lock(obj->mutex);\ +(obj)->flags |= (flag);\ +zap_mutex_unlock(obj->mutex); + /*! \brief Clear a flag on an arbitrary object while locked \command obj the object to test @@ -138,6 +150,12 @@ */ #define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) +#define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); + +#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); obj->state = s; zap_mutex_unlock(obj->mutex); + +#define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) + /*! \brief Copy flags from one arbitrary object to another \command dest the object to copy the flags to @@ -157,6 +175,8 @@ struct zap_event { zap_event_type_t e_type; + uint32_t enum_id; + zap_channel_t *channel; void *data; }; @@ -172,6 +192,8 @@ struct zap_channel { uint32_t effective_interval; uint32_t native_interval; uint32_t packet_len; + zap_channel_state_t state; + zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; @@ -179,9 +201,11 @@ struct zap_channel { void *mod_data; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; + zap_buffer_t *digit_buffer; uint32_t dtmf_on; uint32_t dtmf_off; teletone_generation_session_t tone_session; + zap_time_t last_event_time; struct zap_span *span; struct zap_io_interface *zio; }; @@ -207,6 +231,10 @@ struct zap_isdn_data { uint32_t flags; }; +struct zap_analog_data { + uint32_t flags; +}; + struct zap_span { uint32_t span_id; uint32_t chan_count; @@ -217,6 +245,8 @@ struct zap_span { zap_trunk_type_t trunk_type; zap_signal_type_t signal_type; struct zap_isdn_data *isdn_data; + struct zap_analog_data *analog_data; + zap_event_t event_header; char last_error[256]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -233,12 +263,21 @@ struct zap_io_interface { zio_wait_t wait; zio_read_t read; zio_write_t write; + zio_span_poll_event_t poll_event; + zio_span_next_event_t next_event; uint32_t span_index; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; +zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); +zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); +zap_time_t zap_current_time_in_ms(void); +zap_oob_event_t str2zap_oob_signal(char *name); +char *zap_oob_signal2str(zap_oob_event_t type); zap_trunk_type_t str2zap_trunk_type(char *name); char *zap_trunk_type2str(zap_trunk_type_t type); +zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); +zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); zap_status_t zap_span_close_all(zap_io_interface_t *zio); @@ -246,6 +285,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open_chan(zap_channel_t *zchan); zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); diff --git a/libs/openzap/src/include/zap_analog.h b/libs/openzap/src/include/zap_analog.h new file mode 100644 index 0000000000..8c12797bf2 --- /dev/null +++ b/libs/openzap/src/include/zap_analog.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_ANALOG_H +#define ZAP_ANALOG_H +#include "openzap.h" + +typedef enum { + ZAP_ANALOG_RUNNING = (1 << 0) +} zap_analog_flag_t; + + +typedef struct zap_analog_data zap_analog_data_t; + +zap_status_t zap_analog_start(zap_span_t *span); +zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb); + +#endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index ee958c6bfb..03d6ba8510 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -50,6 +50,8 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +typedef uint64_t zap_time_t; + typedef enum { ZAP_TRUNK_E1, ZAP_TRUNK_T1, @@ -79,6 +81,7 @@ typedef enum { typedef enum { ZAP_EVENT_NONE, ZAP_EVENT_DTMF, + ZAP_EVENT_OOB, ZAP_EVENT_COUNT } zap_event_type_t; @@ -143,7 +146,6 @@ typedef enum { ZAP_CHAN_TYPE_DQ931, ZAP_CHAN_TYPE_FXS, ZAP_CHAN_TYPE_FXO, - ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; @@ -153,6 +155,13 @@ typedef enum { ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) } zap_channel_feature_t; +typedef enum { + ZAP_CHANNEL_STATE_DOWN, + ZAP_CHANNEL_STATE_UP, + ZAP_CHANNEL_STATE_DIALTONE, + ZAP_CHANNEL_STATE_COLLECT +} zap_channel_state_t; + typedef enum { ZAP_CHANNEL_CONFIGURED = (1 << 0), ZAP_CHANNEL_READY = (1 << 1), @@ -160,14 +169,31 @@ typedef enum { ZAP_CHANNEL_DTMF_DETECT = (1 << 3), ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4), ZAP_CHANNEL_TRANSCODE = (1 << 5), - ZAP_CHANNEL_BUFFER = (1 << 6) + 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_flag_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_INVALID +} zap_oob_event_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; +#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_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len) #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) @@ -179,6 +205,8 @@ typedef struct zap_span zap_span_t; #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) +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 ; @@ -190,6 +218,8 @@ 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 ; +#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) zap_status_t name ZIO_CODEC_ARGS diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c new file mode 100644 index 0000000000..7254bf455e --- /dev/null +++ b/libs/openzap/src/testanalog.c @@ -0,0 +1,36 @@ +#include "openzap.h" +#include "zap_analog.h" + +static ZIO_SIGNAL_CB_FUNCTION(on_signal) +{ + return ZAP_FAIL; +} + +int main(int argc, char *argv[]) +{ + zap_span_t *span; + + 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"); + + if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + fprintf(stderr, "Error finding OpenZAP span\n"); + } + + + zap_analog_configure_span(span, on_signal); + zap_analog_start(span); + + while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { + sleep(1); + } + + zap_global_destroy(); + +} diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index dabea87c4e..c9e93bdb83 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -32,3 +32,212 @@ */ #include "openzap.h" +#include "zap_analog.h" + +zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb) +{ + if (span->signal_type) { + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + return ZAP_FAIL; + } + + span->analog_data = malloc(sizeof(*span->analog_data)); + assert(span->analog_data != NULL); + memset(span->analog_data, 0, sizeof(*span->analog_data)); + span->signal_type = ZAP_SIGTYPE_ANALOG; + + return ZAP_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); + printf("add %d\n", wrote * 2); + return 0; +} + +static void *zap_analog_channel_run(zap_thread_t *me, void *obj) +{ + zap_channel_t *chan = (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_codec_t codec = ZAP_CODEC_SLIN, old_codec; + char *tones[] = { "%(1000,0,350,440)", + "%(500,500,480,620)", + "v=2000;%(100,100,1400,2060,2450,2600)", + NULL }; + + time_t start; + int isbz = 0; + int wtime = 10; + zap_tone_type_t tt = ZAP_TONE_DTMF; + int play_tones = 1; + + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); + + if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { + goto done; + } + + if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + goto done; + } + + if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + goto done; + } + /*zap_channel_set_event_callback(chan, my_zap_event_handler);*/ + + + zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); + + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); + ts.rate = 8000; + ts.debug = 1; + ts.debug_stream = stdout; + teletone_run(&ts, tones[isbz++]); + zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + zap_buffer_set_loops(dt_buffer, -1); + + time(&start); + + + + while (chan->state >= ZAP_CHANNEL_STATE_DIALTONE && zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { + zap_wait_flag_t flags = ZAP_READ; + char dtmf[128]; + zap_size_t dlen = 0; + + len = sizeof(frame); + + if (play_tones && tones[isbz] && time(NULL) - start > wtime) { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, tones[isbz++]); + time(&start); + wtime *= 2; + } + + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf, sizeof(dtmf)))) { + printf("DTMF %s\n", dtmf); + play_tones = 0; + } + + if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { + goto done; + } + + if (flags & ZAP_READ) { + if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + if (play_tones) { + zap_channel_write(chan, frame, &rlen); + } + } else { + goto done; + } + } + } + + done: + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); + if (ts.buffer) { + teletone_destroy_session(&ts); + } + if (dt_buffer) { + zap_buffer_destroy(&dt_buffer); + } + + zap_clear_flag(chan, ZAP_CHANNEL_INTHREAD); + zap_channel_close(&chan); + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended. %d\n", old_codec); + return NULL; +} + +static zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_signal2str(event->enum_id), event->channel->span_id, event->channel->chan_id); + + switch(event->enum_id) { + case ZAP_OOB_ONHOOK: + { + 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_thread_create_detached(zap_analog_channel_run, event->channel); + } + } + } + + + return ZAP_SUCCESS; +} + +static void *zap_analog_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_analog_data_t *data = span->analog_data; + + zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); + + while(zap_test_flag(data, ZAP_ANALOG_RUNNING)) { + int waitms = 10; + zap_status_t status; + + status = zap_span_poll_event(span, waitms); + + switch(status) { + case ZAP_TIMEOUT: + case ZAP_SUCCESS: + { + zap_event_t *event; + while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { + if (process_event(span, event) != ZAP_SUCCESS) { + goto end; + } + } + } + break; + case ZAP_FAIL: + { + zap_log(ZAP_LOG_DEBUG, "Failure!\n"); + goto end; + } + break; + default: + break; + } + + } + + end: + + zap_clear_flag(data, ZAP_ANALOG_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n"); + + return NULL; +} + + + +zap_status_t zap_analog_start(zap_span_t *span) +{ + zap_set_flag(span->analog_data, ZAP_ANALOG_RUNNING); + return zap_thread_create_detached(zap_analog_run, span); +} + diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f4dbeeeade..f0ca7dd395 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -41,6 +41,35 @@ #include "zap_zt.h" #endif +static int time_is_init = 0; + +static void time_init(void) +{ +#ifdef WIN32_TIME_GET_TIME + timeBeginPeriod(1); +#endif + time_is_init = 1; +} + +static void time_end(void) +{ +#ifdef WIN32_TIME_GET_TIME + timeEndPeriod(1); +#endif + time_is_init = 0; +} + +zap_time_t zap_current_time_in_ms(void) +{ +#ifdef WIN32_TIME_GET_TIME + return timeGetTime(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); +#endif +} + static struct { zap_hash_t *interface_hash; zap_mutex_t *mutex; @@ -56,6 +85,41 @@ static char *TRUNK_TYPE_NAMES[] = { NULL }; +static char *OOB_NAMES[] = { + "ZAP_OOB_DTMF", + "ZAP_OOB_ONHOOK", + "ZAP_OOB_OFFHOOK", + "WINK", + "FLASH", + "ZAP_OOB_RING_START", + "ZAP_OOB_RING_STOP", + "INVALID", + NULL +}; + +zap_oob_event_t str2zap_oob_signal(char *name) +{ + int i; + zap_trunk_type_t t = ZAP_OOB_INVALID; + + for (i = 0; i < ZAP_OOB_INVALID; i++) { + if (!strcasecmp(name, OOB_NAMES[i])) { + t = (zap_oob_event_t) i; + break; + } + } + + return t; +} + +char *zap_oob_signal2str(zap_oob_event_t type) +{ + if (type > ZAP_OOB_INVALID) { + type = ZAP_OOB_INVALID; + } + return OOB_NAMES[(int)type]; +} + static char *LEVEL_NAMES[] = { "EMERG", "ALERT", @@ -206,16 +270,26 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_status_t zap_span_close_all(zap_io_interface_t *zio) { zap_span_t *span; - uint32_t i; + uint32_t i, j; for(i = 0; i < zio->span_index; i++) { span = &zio->spans[i]; + + for(j = 0; j < span->chan_count; j++) { + zap_mutex_destroy(&span->channels[j].mutex); + zap_buffer_destroy(&span->channels[j].digit_buffer); + zap_buffer_destroy(&span->channels[j].dtmf_buffer); + } + if (span->mutex) { zap_mutex_destroy(&span->mutex); } if (span->isdn_data) { free(span->isdn_data); } + if (span->analog_data) { + free(span->isdn_data); + } } return i ? ZAP_SUCCESS : ZAP_FAIL; @@ -232,6 +306,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; + zap_mutex_create(&new_chan->mutex); + zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -277,6 +353,29 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ return ZAP_SUCCESS; } + +zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) +{ + assert(span->zio != NULL); + + if (span->zio->poll_event) { + return span->zio->poll_event(span, ms); + } + + return ZAP_NOTIMPL; +} + +zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) +{ + assert(span->zio != NULL); + + if (span->zio->next_event) { + return span->zio->next_event(span, event); + } + + return ZAP_NOTIMPL; +} + zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->span->mutex); @@ -397,9 +496,15 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) teletone_destroy_session(&zchan->tone_session); memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); } + if (zchan->dtmf_buffer) { - zap_buffer_destroy(&zchan->dtmf_buffer); + zap_buffer_zero(zchan->dtmf_buffer); } + + if (zchan->digit_buffer) { + zap_buffer_zero(zchan->digit_buffer); + } + zchan->dtmf_on = zchan->dtmf_off = 0; if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { @@ -411,7 +516,21 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) return ZAP_SUCCESS; } +zap_status_t zap_channel_open_chan(zap_channel_t *zchan) +{ + zap_status_t status; + zap_mutex_lock(zchan->span->mutex); + if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + status = zchan->span->zio->open(zchan); + if (status == ZAP_SUCCESS) { + zap_set_flag(zchan, ZAP_CHANNEL_OPEN); + } + } + zap_mutex_unlock(zchan->span->mutex); + + return status; +} zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { @@ -824,6 +943,56 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) /******************************/ +zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) +{ + zap_size_t bytes; + + assert(zchan != NULL); + + zap_mutex_lock(zchan->mutex); + if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { + *(dtmf + bytes) = '\0'; + } + zap_mutex_unlock(zchan->mutex); + + return bytes; +} + + +zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) +{ + zap_status_t status; + register zap_size_t len, inuse; + zap_size_t wr = 0; + const char *p; + + assert(zchan != NULL); + + zap_mutex_lock(zchan->mutex); + + inuse = zap_buffer_inuse(zchan->digit_buffer); + len = strlen(dtmf); + + if (len + inuse > zap_buffer_len(zchan->digit_buffer)) { + zap_buffer_toss(zchan->digit_buffer, strlen(dtmf)); + } + + p = dtmf; + while (wr < len && p) { + if (zap_is_dtmf(*p)) { + wr++; + } else { + break; + } + p++; + } + + status = zap_buffer_write(zchan->digit_buffer, dtmf, wr) ? ZAP_SUCCESS : ZAP_FAIL; + zap_mutex_unlock(zchan->mutex); + + return status; +} + zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; @@ -895,11 +1064,15 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data sln = sln_buf; } - + XX printf("WTF %d\n", (int) slen); teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); - if(digit_str[0]) { + + if(*digit_str) { zio_event_cb_t event_callback = NULL; + + zap_channel_queue_dtmf(zchan, digit_str); + if (zchan->span->event_callback) { event_callback = zchan->span->event_callback; } else if (zchan->event_callback) { @@ -907,6 +1080,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (event_callback) { + zchan->event_header.channel = zchan; zchan->event_header.e_type = ZAP_EVENT_DTMF; zchan->event_header.data = digit_str; event_callback(zchan, &zchan->event_header); @@ -1012,6 +1186,7 @@ zap_status_t zap_global_init(void) uint32_t configured = 0; int modcount; + time_init(); zap_isdn_init(); memset(&interfaces, 0, sizeof(interfaces)); @@ -1047,6 +1222,7 @@ zap_status_t zap_global_init(void) } if (!zap_config_open_file(&cfg, "openzap.conf")) { + zap_log(ZAP_LOG_ERROR, "Cannot open openzap.conf!\n"); return ZAP_FAIL; } @@ -1082,6 +1258,8 @@ zap_status_t zap_global_init(void) zap_status_t zap_global_destroy(void) { + time_end(); + #ifdef ZAP_ZT_SUPPORT if (interfaces.zt_interface) { zt_destroy(); diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 04dc44d507..9eab6fcc42 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -39,7 +39,9 @@ #include static struct { - unsigned codec_ms; + uint32_t codec_ms; + uint32_t wink_ms; + uint32_t flash_ms; } wp_globals; static zap_io_interface_t wanpipe_interface; @@ -70,6 +72,25 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + wanpipe_tdm_api_t tdm_api; + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS; + wp_tdm_cmd_exec(chan, &tdm_api); + + if (type == ZAP_CHAN_TYPE_FXS) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RING_DETECT_EVENTS; + wp_tdm_cmd_exec(chan, &tdm_api); + } + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; + wp_tdm_cmd_exec(chan, &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; + } + } configured++; } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); @@ -206,6 +227,10 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } else if (!strcasecmp(var, "trunk_type")) { span->trunk_type = str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "fxo-channel")) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + } else if (!strcasecmp(var, "fxs-channel")) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { @@ -250,13 +275,8 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) 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; - - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; - if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; - } else { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; - } + zchan->native_codec = zchan->effective_codec; + } return ZAP_SUCCESS; @@ -392,12 +412,140 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } +ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) +{ + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + int i, j = 0, k = 0, 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; + //printf("set %d=%d\n", j, pfds[j].fd); + j++; + } + + r = poll(pfds, j, ms); + + if (r == 0) { + return 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++) { + 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++; + } + } + + return k ? ZAP_SUCCESS : ZAP_FAIL; +} + +ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) +{ + int i; + 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 = 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); + 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); + event_id = ZAP_OOB_ONHOOK; + goto event; + } + } + } + if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { + wanpipe_tdm_api_t tdm_api; + zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; + if (wp_tdm_cmd_exec(&span->channels[i], &tdm_api) != ZAP_SUCCESS) { + snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { + case WP_TDM_EVENT_RXHOOK: + { + event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rxhook_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; + } + break; + case WP_TDM_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; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RING_DETECT_EVENTS; + wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + } + 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; + +} + zap_status_t wanpipe_init(zap_io_interface_t **zio) { 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; wanpipe_interface.name = "wanpipe"; wanpipe_interface.configure = wanpipe_configure; wanpipe_interface.open = wanpipe_open; @@ -406,6 +554,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) 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; *zio = &wanpipe_interface; return ZAP_SUCCESS; From d97b50a9c97a594f7550d74f10b9958547db8faf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 03:42:40 +0000 Subject: [PATCH 0260/1766] add basics for analog (wip) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@130 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 5 +- libs/freetdm/src/include/openzap.h | 40 +++++ libs/freetdm/src/include/zap_analog.h | 48 ++++++ libs/freetdm/src/include/zap_types.h | 34 ++++- libs/freetdm/src/testanalog.c | 36 +++++ libs/freetdm/src/zap_analog.c | 209 ++++++++++++++++++++++++++ libs/freetdm/src/zap_io.c | 186 ++++++++++++++++++++++- libs/freetdm/src/zap_wanpipe.c | 166 +++++++++++++++++++- 8 files changed, 709 insertions(+), 15 deletions(-) create mode 100644 libs/freetdm/src/include/zap_analog.h create mode 100644 libs/freetdm/src/testanalog.c diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 8041ea3a7d..8e9ba7b093 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -73,6 +73,9 @@ testapp: testapp.c $(MYLIB) testisdn: testisdn.c $(MYLIB) $(CC) $(INCS) -L. testisdn.c -o testisdn -lopenzap -lm -lpthread +testanalog: testanalog.c $(MYLIB) + $(CC) $(INCS) -L. testanalog.c -o testanalog -lopenzap -lm -lpthread + priserver.o: priserver.c $(CC) $(INCS) $(TMP) -c priserver.c -o priserver.o @@ -95,5 +98,5 @@ zap_zt.o: zap_zt.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver + rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 5a0f74fafa..8235d30846 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -74,6 +74,11 @@ #pragma warning(disable:4706) #endif +#ifndef WIN32 +#include +#include +#endif + #include #include #include @@ -91,6 +96,8 @@ #include "Q931.h" #include "Q921.h" +#define XX if (0) + #ifdef NDEBUG #undef assert #define assert(_Expression) ((void)(_Expression)) @@ -131,6 +138,11 @@ */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) +#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL);\ +zap_mutex_lock(obj->mutex);\ +(obj)->flags |= (flag);\ +zap_mutex_unlock(obj->mutex); + /*! \brief Clear a flag on an arbitrary object while locked \command obj the object to test @@ -138,6 +150,12 @@ */ #define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) +#define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); + +#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); obj->state = s; zap_mutex_unlock(obj->mutex); + +#define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) + /*! \brief Copy flags from one arbitrary object to another \command dest the object to copy the flags to @@ -157,6 +175,8 @@ struct zap_event { zap_event_type_t e_type; + uint32_t enum_id; + zap_channel_t *channel; void *data; }; @@ -172,6 +192,8 @@ struct zap_channel { uint32_t effective_interval; uint32_t native_interval; uint32_t packet_len; + zap_channel_state_t state; + zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; @@ -179,9 +201,11 @@ struct zap_channel { void *mod_data; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; + zap_buffer_t *digit_buffer; uint32_t dtmf_on; uint32_t dtmf_off; teletone_generation_session_t tone_session; + zap_time_t last_event_time; struct zap_span *span; struct zap_io_interface *zio; }; @@ -207,6 +231,10 @@ struct zap_isdn_data { uint32_t flags; }; +struct zap_analog_data { + uint32_t flags; +}; + struct zap_span { uint32_t span_id; uint32_t chan_count; @@ -217,6 +245,8 @@ struct zap_span { zap_trunk_type_t trunk_type; zap_signal_type_t signal_type; struct zap_isdn_data *isdn_data; + struct zap_analog_data *analog_data; + zap_event_t event_header; char last_error[256]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -233,12 +263,21 @@ struct zap_io_interface { zio_wait_t wait; zio_read_t read; zio_write_t write; + zio_span_poll_event_t poll_event; + zio_span_next_event_t next_event; uint32_t span_index; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; +zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); +zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); +zap_time_t zap_current_time_in_ms(void); +zap_oob_event_t str2zap_oob_signal(char *name); +char *zap_oob_signal2str(zap_oob_event_t type); zap_trunk_type_t str2zap_trunk_type(char *name); char *zap_trunk_type2str(zap_trunk_type_t type); +zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); +zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); zap_status_t zap_span_close_all(zap_io_interface_t *zio); @@ -246,6 +285,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open_chan(zap_channel_t *zchan); zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); diff --git a/libs/freetdm/src/include/zap_analog.h b/libs/freetdm/src/include/zap_analog.h new file mode 100644 index 0000000000..8c12797bf2 --- /dev/null +++ b/libs/freetdm/src/include/zap_analog.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_ANALOG_H +#define ZAP_ANALOG_H +#include "openzap.h" + +typedef enum { + ZAP_ANALOG_RUNNING = (1 << 0) +} zap_analog_flag_t; + + +typedef struct zap_analog_data zap_analog_data_t; + +zap_status_t zap_analog_start(zap_span_t *span); +zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb); + +#endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index ee958c6bfb..03d6ba8510 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -50,6 +50,8 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +typedef uint64_t zap_time_t; + typedef enum { ZAP_TRUNK_E1, ZAP_TRUNK_T1, @@ -79,6 +81,7 @@ typedef enum { typedef enum { ZAP_EVENT_NONE, ZAP_EVENT_DTMF, + ZAP_EVENT_OOB, ZAP_EVENT_COUNT } zap_event_type_t; @@ -143,7 +146,6 @@ typedef enum { ZAP_CHAN_TYPE_DQ931, ZAP_CHAN_TYPE_FXS, ZAP_CHAN_TYPE_FXO, - ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; @@ -153,6 +155,13 @@ typedef enum { ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) } zap_channel_feature_t; +typedef enum { + ZAP_CHANNEL_STATE_DOWN, + ZAP_CHANNEL_STATE_UP, + ZAP_CHANNEL_STATE_DIALTONE, + ZAP_CHANNEL_STATE_COLLECT +} zap_channel_state_t; + typedef enum { ZAP_CHANNEL_CONFIGURED = (1 << 0), ZAP_CHANNEL_READY = (1 << 1), @@ -160,14 +169,31 @@ typedef enum { ZAP_CHANNEL_DTMF_DETECT = (1 << 3), ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4), ZAP_CHANNEL_TRANSCODE = (1 << 5), - ZAP_CHANNEL_BUFFER = (1 << 6) + 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_flag_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_INVALID +} zap_oob_event_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; +#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_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len) #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) @@ -179,6 +205,8 @@ typedef struct zap_span zap_span_t; #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) +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 ; @@ -190,6 +218,8 @@ 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 ; +#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) zap_status_t name ZIO_CODEC_ARGS diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c new file mode 100644 index 0000000000..7254bf455e --- /dev/null +++ b/libs/freetdm/src/testanalog.c @@ -0,0 +1,36 @@ +#include "openzap.h" +#include "zap_analog.h" + +static ZIO_SIGNAL_CB_FUNCTION(on_signal) +{ + return ZAP_FAIL; +} + +int main(int argc, char *argv[]) +{ + zap_span_t *span; + + 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"); + + if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + fprintf(stderr, "Error finding OpenZAP span\n"); + } + + + zap_analog_configure_span(span, on_signal); + zap_analog_start(span); + + while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { + sleep(1); + } + + zap_global_destroy(); + +} diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index dabea87c4e..c9e93bdb83 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -32,3 +32,212 @@ */ #include "openzap.h" +#include "zap_analog.h" + +zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb) +{ + if (span->signal_type) { + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + return ZAP_FAIL; + } + + span->analog_data = malloc(sizeof(*span->analog_data)); + assert(span->analog_data != NULL); + memset(span->analog_data, 0, sizeof(*span->analog_data)); + span->signal_type = ZAP_SIGTYPE_ANALOG; + + return ZAP_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); + printf("add %d\n", wrote * 2); + return 0; +} + +static void *zap_analog_channel_run(zap_thread_t *me, void *obj) +{ + zap_channel_t *chan = (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_codec_t codec = ZAP_CODEC_SLIN, old_codec; + char *tones[] = { "%(1000,0,350,440)", + "%(500,500,480,620)", + "v=2000;%(100,100,1400,2060,2450,2600)", + NULL }; + + time_t start; + int isbz = 0; + int wtime = 10; + zap_tone_type_t tt = ZAP_TONE_DTMF; + int play_tones = 1; + + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); + + if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { + goto done; + } + + if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + goto done; + } + + if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + goto done; + } + /*zap_channel_set_event_callback(chan, my_zap_event_handler);*/ + + + zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); + + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); + ts.rate = 8000; + ts.debug = 1; + ts.debug_stream = stdout; + teletone_run(&ts, tones[isbz++]); + zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + zap_buffer_set_loops(dt_buffer, -1); + + time(&start); + + + + while (chan->state >= ZAP_CHANNEL_STATE_DIALTONE && zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { + zap_wait_flag_t flags = ZAP_READ; + char dtmf[128]; + zap_size_t dlen = 0; + + len = sizeof(frame); + + if (play_tones && tones[isbz] && time(NULL) - start > wtime) { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, tones[isbz++]); + time(&start); + wtime *= 2; + } + + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf, sizeof(dtmf)))) { + printf("DTMF %s\n", dtmf); + play_tones = 0; + } + + if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { + goto done; + } + + if (flags & ZAP_READ) { + if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + if (play_tones) { + zap_channel_write(chan, frame, &rlen); + } + } else { + goto done; + } + } + } + + done: + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); + if (ts.buffer) { + teletone_destroy_session(&ts); + } + if (dt_buffer) { + zap_buffer_destroy(&dt_buffer); + } + + zap_clear_flag(chan, ZAP_CHANNEL_INTHREAD); + zap_channel_close(&chan); + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended. %d\n", old_codec); + return NULL; +} + +static zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_signal2str(event->enum_id), event->channel->span_id, event->channel->chan_id); + + switch(event->enum_id) { + case ZAP_OOB_ONHOOK: + { + 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_thread_create_detached(zap_analog_channel_run, event->channel); + } + } + } + + + return ZAP_SUCCESS; +} + +static void *zap_analog_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_analog_data_t *data = span->analog_data; + + zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); + + while(zap_test_flag(data, ZAP_ANALOG_RUNNING)) { + int waitms = 10; + zap_status_t status; + + status = zap_span_poll_event(span, waitms); + + switch(status) { + case ZAP_TIMEOUT: + case ZAP_SUCCESS: + { + zap_event_t *event; + while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { + if (process_event(span, event) != ZAP_SUCCESS) { + goto end; + } + } + } + break; + case ZAP_FAIL: + { + zap_log(ZAP_LOG_DEBUG, "Failure!\n"); + goto end; + } + break; + default: + break; + } + + } + + end: + + zap_clear_flag(data, ZAP_ANALOG_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n"); + + return NULL; +} + + + +zap_status_t zap_analog_start(zap_span_t *span) +{ + zap_set_flag(span->analog_data, ZAP_ANALOG_RUNNING); + return zap_thread_create_detached(zap_analog_run, span); +} + diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f4dbeeeade..f0ca7dd395 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -41,6 +41,35 @@ #include "zap_zt.h" #endif +static int time_is_init = 0; + +static void time_init(void) +{ +#ifdef WIN32_TIME_GET_TIME + timeBeginPeriod(1); +#endif + time_is_init = 1; +} + +static void time_end(void) +{ +#ifdef WIN32_TIME_GET_TIME + timeEndPeriod(1); +#endif + time_is_init = 0; +} + +zap_time_t zap_current_time_in_ms(void) +{ +#ifdef WIN32_TIME_GET_TIME + return timeGetTime(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); +#endif +} + static struct { zap_hash_t *interface_hash; zap_mutex_t *mutex; @@ -56,6 +85,41 @@ static char *TRUNK_TYPE_NAMES[] = { NULL }; +static char *OOB_NAMES[] = { + "ZAP_OOB_DTMF", + "ZAP_OOB_ONHOOK", + "ZAP_OOB_OFFHOOK", + "WINK", + "FLASH", + "ZAP_OOB_RING_START", + "ZAP_OOB_RING_STOP", + "INVALID", + NULL +}; + +zap_oob_event_t str2zap_oob_signal(char *name) +{ + int i; + zap_trunk_type_t t = ZAP_OOB_INVALID; + + for (i = 0; i < ZAP_OOB_INVALID; i++) { + if (!strcasecmp(name, OOB_NAMES[i])) { + t = (zap_oob_event_t) i; + break; + } + } + + return t; +} + +char *zap_oob_signal2str(zap_oob_event_t type) +{ + if (type > ZAP_OOB_INVALID) { + type = ZAP_OOB_INVALID; + } + return OOB_NAMES[(int)type]; +} + static char *LEVEL_NAMES[] = { "EMERG", "ALERT", @@ -206,16 +270,26 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_status_t zap_span_close_all(zap_io_interface_t *zio) { zap_span_t *span; - uint32_t i; + uint32_t i, j; for(i = 0; i < zio->span_index; i++) { span = &zio->spans[i]; + + for(j = 0; j < span->chan_count; j++) { + zap_mutex_destroy(&span->channels[j].mutex); + zap_buffer_destroy(&span->channels[j].digit_buffer); + zap_buffer_destroy(&span->channels[j].dtmf_buffer); + } + if (span->mutex) { zap_mutex_destroy(&span->mutex); } if (span->isdn_data) { free(span->isdn_data); } + if (span->analog_data) { + free(span->isdn_data); + } } return i ? ZAP_SUCCESS : ZAP_FAIL; @@ -232,6 +306,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; + zap_mutex_create(&new_chan->mutex); + zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -277,6 +353,29 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ return ZAP_SUCCESS; } + +zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) +{ + assert(span->zio != NULL); + + if (span->zio->poll_event) { + return span->zio->poll_event(span, ms); + } + + return ZAP_NOTIMPL; +} + +zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) +{ + assert(span->zio != NULL); + + if (span->zio->next_event) { + return span->zio->next_event(span, event); + } + + return ZAP_NOTIMPL; +} + zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->span->mutex); @@ -397,9 +496,15 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) teletone_destroy_session(&zchan->tone_session); memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); } + if (zchan->dtmf_buffer) { - zap_buffer_destroy(&zchan->dtmf_buffer); + zap_buffer_zero(zchan->dtmf_buffer); } + + if (zchan->digit_buffer) { + zap_buffer_zero(zchan->digit_buffer); + } + zchan->dtmf_on = zchan->dtmf_off = 0; if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { @@ -411,7 +516,21 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) return ZAP_SUCCESS; } +zap_status_t zap_channel_open_chan(zap_channel_t *zchan) +{ + zap_status_t status; + zap_mutex_lock(zchan->span->mutex); + if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + status = zchan->span->zio->open(zchan); + if (status == ZAP_SUCCESS) { + zap_set_flag(zchan, ZAP_CHANNEL_OPEN); + } + } + zap_mutex_unlock(zchan->span->mutex); + + return status; +} zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { @@ -824,6 +943,56 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) /******************************/ +zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) +{ + zap_size_t bytes; + + assert(zchan != NULL); + + zap_mutex_lock(zchan->mutex); + if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { + *(dtmf + bytes) = '\0'; + } + zap_mutex_unlock(zchan->mutex); + + return bytes; +} + + +zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) +{ + zap_status_t status; + register zap_size_t len, inuse; + zap_size_t wr = 0; + const char *p; + + assert(zchan != NULL); + + zap_mutex_lock(zchan->mutex); + + inuse = zap_buffer_inuse(zchan->digit_buffer); + len = strlen(dtmf); + + if (len + inuse > zap_buffer_len(zchan->digit_buffer)) { + zap_buffer_toss(zchan->digit_buffer, strlen(dtmf)); + } + + p = dtmf; + while (wr < len && p) { + if (zap_is_dtmf(*p)) { + wr++; + } else { + break; + } + p++; + } + + status = zap_buffer_write(zchan->digit_buffer, dtmf, wr) ? ZAP_SUCCESS : ZAP_FAIL; + zap_mutex_unlock(zchan->mutex); + + return status; +} + zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; @@ -895,11 +1064,15 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data sln = sln_buf; } - + XX printf("WTF %d\n", (int) slen); teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); - if(digit_str[0]) { + + if(*digit_str) { zio_event_cb_t event_callback = NULL; + + zap_channel_queue_dtmf(zchan, digit_str); + if (zchan->span->event_callback) { event_callback = zchan->span->event_callback; } else if (zchan->event_callback) { @@ -907,6 +1080,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (event_callback) { + zchan->event_header.channel = zchan; zchan->event_header.e_type = ZAP_EVENT_DTMF; zchan->event_header.data = digit_str; event_callback(zchan, &zchan->event_header); @@ -1012,6 +1186,7 @@ zap_status_t zap_global_init(void) uint32_t configured = 0; int modcount; + time_init(); zap_isdn_init(); memset(&interfaces, 0, sizeof(interfaces)); @@ -1047,6 +1222,7 @@ zap_status_t zap_global_init(void) } if (!zap_config_open_file(&cfg, "openzap.conf")) { + zap_log(ZAP_LOG_ERROR, "Cannot open openzap.conf!\n"); return ZAP_FAIL; } @@ -1082,6 +1258,8 @@ zap_status_t zap_global_init(void) zap_status_t zap_global_destroy(void) { + time_end(); + #ifdef ZAP_ZT_SUPPORT if (interfaces.zt_interface) { zt_destroy(); diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 04dc44d507..9eab6fcc42 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -39,7 +39,9 @@ #include static struct { - unsigned codec_ms; + uint32_t codec_ms; + uint32_t wink_ms; + uint32_t flash_ms; } wp_globals; static zap_io_interface_t wanpipe_interface; @@ -70,6 +72,25 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + wanpipe_tdm_api_t tdm_api; + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS; + wp_tdm_cmd_exec(chan, &tdm_api); + + if (type == ZAP_CHAN_TYPE_FXS) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RING_DETECT_EVENTS; + wp_tdm_cmd_exec(chan, &tdm_api); + } + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; + wp_tdm_cmd_exec(chan, &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; + } + } configured++; } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); @@ -206,6 +227,10 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } else if (!strcasecmp(var, "trunk_type")) { span->trunk_type = str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "fxo-channel")) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + } else if (!strcasecmp(var, "fxs-channel")) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { @@ -250,13 +275,8 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) 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; - - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; - if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; - } else { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; - } + zchan->native_codec = zchan->effective_codec; + } return ZAP_SUCCESS; @@ -392,12 +412,140 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } +ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) +{ + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + int i, j = 0, k = 0, 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; + //printf("set %d=%d\n", j, pfds[j].fd); + j++; + } + + r = poll(pfds, j, ms); + + if (r == 0) { + return 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++) { + 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++; + } + } + + return k ? ZAP_SUCCESS : ZAP_FAIL; +} + +ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) +{ + int i; + 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 = 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); + 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); + event_id = ZAP_OOB_ONHOOK; + goto event; + } + } + } + if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { + wanpipe_tdm_api_t tdm_api; + zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; + if (wp_tdm_cmd_exec(&span->channels[i], &tdm_api) != ZAP_SUCCESS) { + snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { + case WP_TDM_EVENT_RXHOOK: + { + event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rxhook_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; + } + break; + case WP_TDM_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; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RING_DETECT_EVENTS; + wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + } + 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; + +} + zap_status_t wanpipe_init(zap_io_interface_t **zio) { 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; wanpipe_interface.name = "wanpipe"; wanpipe_interface.configure = wanpipe_configure; wanpipe_interface.open = wanpipe_open; @@ -406,6 +554,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) 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; *zio = &wanpipe_interface; return ZAP_SUCCESS; From 8ad644fe35193c5326115ca29edc1faf64e24ab6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 04:11:32 +0000 Subject: [PATCH 0261/1766] get building on windows again. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@131 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 1 + libs/openzap/src/isdn/include/national.h | 121 +++++++++++++++++++++++ libs/openzap/src/zap_io.c | 10 +- libs/openzap/src/zap_wanpipe.c | 11 ++- 4 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 libs/openzap/src/isdn/include/national.h diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 03d6ba8510..1c609a16d6 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -37,6 +37,7 @@ #ifdef WIN32 #include typedef HANDLE zap_socket_t; +typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef __int32 int32_t; #else diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h new file mode 100644 index 0000000000..0bc1fa9e2d --- /dev/null +++ b/libs/openzap/src/isdn/include/national.h @@ -0,0 +1,121 @@ +/****************************************************************************** + + 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 + +*****************************************************************************/ + + +/* Single octet information elements */ + +/* Variable Length Information Elements */ +#define nationalie_GENERIC_DIGITS 0x37 /* 0011 0111 */ + + + +/***************************************************************************** + + Struct: nationalie_GenericDigits + + +*****************************************************************************/ + +typedef struct +{ + L3UCHAR IEId; /* 00110111 */ + L3UCHAR Size; /* Length of Information Element */ +}nationalie_GenericDigits; + + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in nationalie.c + +*****************************************************************************/ + +L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT nationalPie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); + + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c + +*****************************************************************************/ +L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +/***************************************************************************** + + 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/zap_io.c b/libs/openzap/src/zap_io.c index f0ca7dd395..f0e382f2e6 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -45,7 +45,7 @@ static int time_is_init = 0; static void time_init(void) { -#ifdef WIN32_TIME_GET_TIME +#ifdef WIN32 timeBeginPeriod(1); #endif time_is_init = 1; @@ -53,7 +53,7 @@ static void time_init(void) static void time_end(void) { -#ifdef WIN32_TIME_GET_TIME +#ifdef WIN32 timeEndPeriod(1); #endif time_is_init = 0; @@ -61,7 +61,7 @@ static void time_end(void) zap_time_t zap_current_time_in_ms(void) { -#ifdef WIN32_TIME_GET_TIME +#ifdef WIN32 return timeGetTime(); #else struct timeval tv; @@ -518,7 +518,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { - zap_status_t status; + zap_status_t status = ZAP_FAIL; zap_mutex_lock(zchan->span->mutex); if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { @@ -1064,7 +1064,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data sln = sln_buf; } - XX printf("WTF %d\n", (int) slen); + teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 9eab6fcc42..dbe48cd061 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -412,6 +412,7 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } +#ifndef WIN32 ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; @@ -445,15 +446,17 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) return k ? ZAP_SUCCESS : ZAP_FAIL; } +#endif + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { - int i; + uint32_t i; 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 = 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); + 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); @@ -554,7 +557,9 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wanpipe_interface.wait = wanpipe_wait; wanpipe_interface.read = wanpipe_read; wanpipe_interface.write = wanpipe_write; +#ifndef WIN32 wanpipe_interface.poll_event = wanpipe_poll_event; +#endif wanpipe_interface.next_event = wanpipe_next_event; *zio = &wanpipe_interface; From 803b42ac7674f2ea90047223978449b934ba7d36 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 04:11:32 +0000 Subject: [PATCH 0262/1766] get building on windows again. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@131 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 1 + libs/freetdm/src/isdn/include/national.h | 121 +++++++++++++++++++++++ libs/freetdm/src/zap_io.c | 10 +- libs/freetdm/src/zap_wanpipe.c | 11 ++- 4 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 libs/freetdm/src/isdn/include/national.h diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 03d6ba8510..1c609a16d6 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -37,6 +37,7 @@ #ifdef WIN32 #include typedef HANDLE zap_socket_t; +typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef __int32 int32_t; #else diff --git a/libs/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h new file mode 100644 index 0000000000..0bc1fa9e2d --- /dev/null +++ b/libs/freetdm/src/isdn/include/national.h @@ -0,0 +1,121 @@ +/****************************************************************************** + + 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 + +*****************************************************************************/ + + +/* Single octet information elements */ + +/* Variable Length Information Elements */ +#define nationalie_GENERIC_DIGITS 0x37 /* 0011 0111 */ + + + +/***************************************************************************** + + Struct: nationalie_GenericDigits + + +*****************************************************************************/ + +typedef struct +{ + L3UCHAR IEId; /* 00110111 */ + L3UCHAR Size; /* Length of Information Element */ +}nationalie_GenericDigits; + + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in nationalie.c + +*****************************************************************************/ + +L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT nationalPie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); + + +/***************************************************************************** + + Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c + +*****************************************************************************/ +L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); +L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); + +/***************************************************************************** + + 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/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f0ca7dd395..f0e382f2e6 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -45,7 +45,7 @@ static int time_is_init = 0; static void time_init(void) { -#ifdef WIN32_TIME_GET_TIME +#ifdef WIN32 timeBeginPeriod(1); #endif time_is_init = 1; @@ -53,7 +53,7 @@ static void time_init(void) static void time_end(void) { -#ifdef WIN32_TIME_GET_TIME +#ifdef WIN32 timeEndPeriod(1); #endif time_is_init = 0; @@ -61,7 +61,7 @@ static void time_end(void) zap_time_t zap_current_time_in_ms(void) { -#ifdef WIN32_TIME_GET_TIME +#ifdef WIN32 return timeGetTime(); #else struct timeval tv; @@ -518,7 +518,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { - zap_status_t status; + zap_status_t status = ZAP_FAIL; zap_mutex_lock(zchan->span->mutex); if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { @@ -1064,7 +1064,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data sln = sln_buf; } - XX printf("WTF %d\n", (int) slen); + teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 9eab6fcc42..dbe48cd061 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -412,6 +412,7 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } +#ifndef WIN32 ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; @@ -445,15 +446,17 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) return k ? ZAP_SUCCESS : ZAP_FAIL; } +#endif + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { - int i; + uint32_t i; 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 = 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); + 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); @@ -554,7 +557,9 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wanpipe_interface.wait = wanpipe_wait; wanpipe_interface.read = wanpipe_read; wanpipe_interface.write = wanpipe_write; +#ifndef WIN32 wanpipe_interface.poll_event = wanpipe_poll_event; +#endif wanpipe_interface.next_event = wanpipe_next_event; *zio = &wanpipe_interface; From 74b55a890e5c62c35144abba179b7679a79ea8f4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 04:12:15 +0000 Subject: [PATCH 0263/1766] add initial National ISDN Dialect. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@132 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.vcproj | 20 ++ libs/openzap/src/isdn/Q931.c | 7 + libs/openzap/src/isdn/Q931ie.c | 3 +- libs/openzap/src/isdn/include/Q931.h | 3 +- libs/openzap/src/isdn/nationalStateNT.c | 126 ++++++++++ libs/openzap/src/isdn/nationalStateTE.c | 210 +++++++++++++++++ libs/openzap/src/isdn/nationalie.c | 254 ++++++++++++++++++++ libs/openzap/src/isdn/nationalmes.c | 301 ++++++++++++++++++++++++ 8 files changed, 921 insertions(+), 3 deletions(-) create mode 100644 libs/openzap/src/isdn/nationalStateNT.c create mode 100644 libs/openzap/src/isdn/nationalStateTE.c create mode 100644 libs/openzap/src/isdn/nationalie.c create mode 100644 libs/openzap/src/isdn/nationalmes.c diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj index af00754f66..aaacf7578b 100644 --- a/libs/openzap/openzap.vcproj +++ b/libs/openzap/openzap.vcproj @@ -368,6 +368,22 @@ RelativePath=".\src\isdn\mfifo.c" > + + + + + + + + @@ -407,6 +423,10 @@ RelativePath=".\src\isdn\include\mfifo.h" > + + diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index f230b5973a..0e130a3668 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -37,6 +37,7 @@ *****************************************************************************/ #include "Q931.h" +#include "national.h" /***************************************************************************** @@ -253,6 +254,12 @@ void Q931Initialize() 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); + /* The last step we do is to call the callbacks to create the dialects */ for(x=0; x< Q931MAXDLCT; x++) { diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index f6d29610d9..1435e3abc7 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -819,8 +819,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; -/* }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Temporary dirty hack. */ - }while(Q931MoreIE()); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLINGNUM); diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index b5251e2d7a..00e4f3738f 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -222,7 +222,7 @@ /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 2 /* Max dialects included in this */ +#define Q931MAXDLCT 4 /* Max dialects included in this */ /* compile. User and Network count as */ /* one dialect each. */ @@ -1932,6 +1932,7 @@ typedef enum /* Network/User Mode. */ typedef enum /* Dialect enum */ { Q931_Dialect_Q931 = 0, + Q931_Dialect_National = 1, Q931_Dialect_Count } Q931Dialect_t; diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c new file mode 100644 index 0000000000..c18e185b5a --- /dev/null +++ b/libs/openzap/src/isdn/nationalStateNT.c @@ -0,0 +1,126 @@ +/***************************************************************************** + + 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,nationalPie_CallingNum, nationalUie_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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_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/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c new file mode 100644 index 0000000000..f8b8a9f90c --- /dev/null +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -0,0 +1,210 @@ +/***************************************************************************** + + 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" + +/***************************************************************************** + 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,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, 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_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,nationalPie_CallingNum, nationalUie_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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_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, +*/ +} diff --git a/libs/openzap/src/isdn/nationalie.c b/libs/openzap/src/isdn/nationalie.c new file mode 100644 index 0000000000..b6e2446350 --- /dev/null +++ b/libs/openzap/src/isdn/nationalie.c @@ -0,0 +1,254 @@ +/***************************************************************************** + + FileName: nationalie.c + + Contents: Information Element Pack/Unpack functions. + + These functions will pack out a National ISDN 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: + + nationalPie_XXX Pack struct into Q.931 IE + nationalUie_XXX Unpack Q.931 IE into struct + nationalInitIEXXX Initialize IE (see nationalapi.c). + + 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" + +/***************************************************************************** + + 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: nationalUie_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 nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + nationalie_GenericDigits * pie = (nationalie_GenericDigits*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; + + /* Octet 2 */ + IESize = IBuf[Octet++]; + + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(nationalie_GenericDigits) + x -1; + + pie->Size = (L3UCHAR)(sizeof(nationalie_GenericDigits) + x -1); + + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalPie_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 nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + OBuf[(*Octet)++] = nationalie_GENERIC_DIGITS ; + OBuf[(*Octet)++] = 2; + + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalUie_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 nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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 4a*/ + x=0; + do{ + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while(Q931MoreIE()); + + Q931IESizeTest(Q931E_CALLINGNUM); + + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); + + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalPie_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 nationalPie_CallingNum(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_CalledSub) + 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 3a */ + /* + + Details about the use and how to detect if Octet 3a is used + are very weak. Temp left out. + + Octet 3 msb is set to 1 to indicate that this is not present + + */ + + /* Octet 4 */ + for(x=0;xDigit[x]; + } + + OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ + + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; + return rc; +} diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c new file mode 100644 index 0000000000..c32398d00d --- /dev/null +++ b/libs/openzap/src/isdn/nationalmes.c @@ -0,0 +1,301 @@ +/***************************************************************************** + + 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, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + L3INT ir=0; + L3INT OOff=0; + Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_REPEAT_INDICATOR: + if(ir==0) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + ir++; + } + else if(ir==1) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + ir++; + } + else + { + return Q931E_ILLEGAL_IE; + } + break; + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_NETWORK_SPECIFIC_FACILITIES: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_TRANSIT_NETWORK_SELECTION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case nationalie_GENERIC_DIGITS: + /* TODO: Implement this ie */ + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalPmes_Setup + + Decription: Pack a Q931mes_Setup 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, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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; +} From 8a47dc9b4cd6aa39bb3d4b551e78490277caba36 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 04:12:15 +0000 Subject: [PATCH 0264/1766] add initial National ISDN Dialect. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@132 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.vcproj | 20 ++ libs/freetdm/src/isdn/Q931.c | 7 + libs/freetdm/src/isdn/Q931ie.c | 3 +- libs/freetdm/src/isdn/include/Q931.h | 3 +- libs/freetdm/src/isdn/nationalStateNT.c | 126 ++++++++++ libs/freetdm/src/isdn/nationalStateTE.c | 210 +++++++++++++++++ libs/freetdm/src/isdn/nationalie.c | 254 ++++++++++++++++++++ libs/freetdm/src/isdn/nationalmes.c | 301 ++++++++++++++++++++++++ 8 files changed, 921 insertions(+), 3 deletions(-) create mode 100644 libs/freetdm/src/isdn/nationalStateNT.c create mode 100644 libs/freetdm/src/isdn/nationalStateTE.c create mode 100644 libs/freetdm/src/isdn/nationalie.c create mode 100644 libs/freetdm/src/isdn/nationalmes.c diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj index af00754f66..aaacf7578b 100644 --- a/libs/freetdm/openzap.vcproj +++ b/libs/freetdm/openzap.vcproj @@ -368,6 +368,22 @@ RelativePath=".\src\isdn\mfifo.c" > + + + + + + + + @@ -407,6 +423,10 @@ RelativePath=".\src\isdn\include\mfifo.h" > + + diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index f230b5973a..0e130a3668 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -37,6 +37,7 @@ *****************************************************************************/ #include "Q931.h" +#include "national.h" /***************************************************************************** @@ -253,6 +254,12 @@ void Q931Initialize() 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); + /* The last step we do is to call the callbacks to create the dialects */ for(x=0; x< Q931MAXDLCT; x++) { diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index f6d29610d9..1435e3abc7 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -819,8 +819,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; -/* }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Temporary dirty hack. */ - }while(Q931MoreIE()); + }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); Q931IESizeTest(Q931E_CALLINGNUM); diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index b5251e2d7a..00e4f3738f 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -222,7 +222,7 @@ /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 2 /* Max dialects included in this */ +#define Q931MAXDLCT 4 /* Max dialects included in this */ /* compile. User and Network count as */ /* one dialect each. */ @@ -1932,6 +1932,7 @@ typedef enum /* Network/User Mode. */ typedef enum /* Dialect enum */ { Q931_Dialect_Q931 = 0, + Q931_Dialect_National = 1, Q931_Dialect_Count } Q931Dialect_t; diff --git a/libs/freetdm/src/isdn/nationalStateNT.c b/libs/freetdm/src/isdn/nationalStateNT.c new file mode 100644 index 0000000000..c18e185b5a --- /dev/null +++ b/libs/freetdm/src/isdn/nationalStateNT.c @@ -0,0 +1,126 @@ +/***************************************************************************** + + 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,nationalPie_CallingNum, nationalUie_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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_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/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c new file mode 100644 index 0000000000..f8b8a9f90c --- /dev/null +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -0,0 +1,210 @@ +/***************************************************************************** + + 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" + +/***************************************************************************** + 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,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, 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_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,nationalPie_CallingNum, nationalUie_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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_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, +*/ +} diff --git a/libs/freetdm/src/isdn/nationalie.c b/libs/freetdm/src/isdn/nationalie.c new file mode 100644 index 0000000000..b6e2446350 --- /dev/null +++ b/libs/freetdm/src/isdn/nationalie.c @@ -0,0 +1,254 @@ +/***************************************************************************** + + FileName: nationalie.c + + Contents: Information Element Pack/Unpack functions. + + These functions will pack out a National ISDN 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: + + nationalPie_XXX Pack struct into Q.931 IE + nationalUie_XXX Unpack Q.931 IE into struct + nationalInitIEXXX Initialize IE (see nationalapi.c). + + 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" + +/***************************************************************************** + + 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: nationalUie_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 nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + nationalie_GenericDigits * pie = (nationalie_GenericDigits*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; + + /* Octet 2 */ + IESize = IBuf[Octet++]; + + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(nationalie_GenericDigits) + x -1; + + pie->Size = (L3UCHAR)(sizeof(nationalie_GenericDigits) + x -1); + + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalPie_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 nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) +{ + OBuf[(*Octet)++] = nationalie_GENERIC_DIGITS ; + OBuf[(*Octet)++] = 2; + + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalUie_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 nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +{ + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + 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 4a*/ + x=0; + do{ + pie->Digit[x] = IBuf[Octet+Off] & 0x7f; + Off++; + x++; + }while(Q931MoreIE()); + + Q931IESizeTest(Q931E_CALLINGNUM); + + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); + + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalPie_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 nationalPie_CallingNum(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_CalledSub) + 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 3a */ + /* + + Details about the use and how to detect if Octet 3a is used + are very weak. Temp left out. + + Octet 3 msb is set to 1 to indicate that this is not present + + */ + + /* Octet 4 */ + for(x=0;xDigit[x]; + } + + OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ + + OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; + return rc; +} diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c new file mode 100644 index 0000000000..c32398d00d --- /dev/null +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -0,0 +1,301 @@ +/***************************************************************************** + + 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, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +{ + /* L3INT i = IOff; */ + L3INT ir=0; + L3INT OOff=0; + Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_SENDING_COMPLETE: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_REPEAT_INDICATOR: + if(ir==0) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + ir++; + } + else if(ir==1) + { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + ir++; + } + else + { + return Q931E_ILLEGAL_IE; + } + break; + case Q931ie_BEARER_CAPABILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_PROGRESS_INDICATOR: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_NETWORK_SPECIFIC_FACILITIES: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DISPLAY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_DATETIME: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_KEYPAD_FACILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_SIGNAL: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLING_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_NUMBER: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_CALLED_PARTY_SUBADDRESS: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_TRANSIT_NETWORK_SELECTION: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_LOW_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case Q931ie_HIGH_LAYER_COMPATIBILITY: + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(rc != Q931E_NO_ERROR) + return rc; + break; + case nationalie_GENERIC_DIGITS: + /* TODO: Implement this ie */ + break; + default: + return Q931E_ILLEGAL_IE; + break; + } + } + mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + return Q931E_NO_ERROR; +} + +/***************************************************************************** + + Function: nationalPmes_Setup + + Decription: Pack a Q931mes_Setup 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, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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; +} From df76bafd6d279491f917c72b1023a95ed6a0f952 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:39:40 +0000 Subject: [PATCH 0265/1766] merge git-svn-id: http://svn.openzap.org/svn/openzap/trunk@133 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 1 - libs/openzap/src/zap_wanpipe.c | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index c9e93bdb83..1021dbae27 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -201,7 +201,6 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) status = zap_span_poll_event(span, waitms); switch(status) { - case ZAP_TIMEOUT: case ZAP_SUCCESS: { zap_event_t *event; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index dbe48cd061..448bc146cd 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -416,20 +416,26 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; - int i, j = 0, k = 0, r; + int i, j = 0, k = 0, l = 0, 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; - //printf("set %d=%d\n", j, pfds[j].fd); + if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_WINK) || zap_test_flag((&span->channels[i]), ZAP_CHANNEL_FLASH)) { + l++; + } j++; } + if (l) { + ms = 5; + } + r = poll(pfds, j, ms); if (r == 0) { - return ZAP_TIMEOUT; + return l ? ZAP_SUCCESS : ZAP_TIMEOUT; } else if (r < 0) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); return ZAP_FAIL; From bc1b0ef116ffd985b08febef9cf83185093103b5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:39:40 +0000 Subject: [PATCH 0266/1766] merge git-svn-id: http://svn.openzap.org/svn/openzap/trunk@133 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 1 - libs/freetdm/src/zap_wanpipe.c | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index c9e93bdb83..1021dbae27 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -201,7 +201,6 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) status = zap_span_poll_event(span, waitms); switch(status) { - case ZAP_TIMEOUT: case ZAP_SUCCESS: { zap_event_t *event; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index dbe48cd061..448bc146cd 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -416,20 +416,26 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; - int i, j = 0, k = 0, r; + int i, j = 0, k = 0, l = 0, 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; - //printf("set %d=%d\n", j, pfds[j].fd); + if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_WINK) || zap_test_flag((&span->channels[i]), ZAP_CHANNEL_FLASH)) { + l++; + } j++; } + if (l) { + ms = 5; + } + r = poll(pfds, j, ms); if (r == 0) { - return ZAP_TIMEOUT; + return l ? ZAP_SUCCESS : ZAP_TIMEOUT; } else if (r < 0) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); return ZAP_FAIL; From bbc2c82acabfeedf433269d7701f17eda04f84c0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:41:43 +0000 Subject: [PATCH 0267/1766] add new file to Makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@134 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 8e9ba7b093..cd2040f9c5 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -51,6 +51,7 @@ isdn/Q931ie.o \ isdn/Q931mes.o \ isdn/Q931StateNT.o \ isdn/Q931StateTE.o \ +isdn/nationalStateNT.o\ isdn/Q932mes.o PWD=$(shell pwd) From d67257f22969874c55ad9c0543356543dc85226a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:41:43 +0000 Subject: [PATCH 0268/1766] add new file to Makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@134 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 8e9ba7b093..cd2040f9c5 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -51,6 +51,7 @@ isdn/Q931ie.o \ isdn/Q931mes.o \ isdn/Q931StateNT.o \ isdn/Q931StateTE.o \ +isdn/nationalStateNT.o\ isdn/Q932mes.o PWD=$(shell pwd) From 71eae48913aced5097cc78f91fef2ea713054820 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:43:44 +0000 Subject: [PATCH 0269/1766] add new file to Makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@135 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index cd2040f9c5..1703dfd9df 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -51,7 +51,10 @@ isdn/Q931ie.o \ isdn/Q931mes.o \ isdn/Q931StateNT.o \ isdn/Q931StateTE.o \ -isdn/nationalStateNT.o\ +isdn/nationalie.o \ +isdn/nationalmes.o \ +isdn/nationalStateNT.o \ +isdn/nationalStateTE.o \ isdn/Q932mes.o PWD=$(shell pwd) From 2a7297278d785575ca62cd82bc4c12cfe621846a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:43:44 +0000 Subject: [PATCH 0270/1766] add new file to Makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@135 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index cd2040f9c5..1703dfd9df 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -51,7 +51,10 @@ isdn/Q931ie.o \ isdn/Q931mes.o \ isdn/Q931StateNT.o \ isdn/Q931StateTE.o \ -isdn/nationalStateNT.o\ +isdn/nationalie.o \ +isdn/nationalmes.o \ +isdn/nationalStateNT.o \ +isdn/nationalStateTE.o \ isdn/Q932mes.o PWD=$(shell pwd) From 0f491775ec6cb3764b0a145724ef44eb5467bdff Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:46:54 +0000 Subject: [PATCH 0271/1766] fix test app git-svn-id: http://svn.openzap.org/svn/openzap/trunk@136 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testisdn.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index c55905d3f4..11e945ec79 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -21,16 +21,23 @@ int main(int argc, char *argv[]) if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { fprintf(stderr, "Error finding OpenZAP span\n"); + goto done; } - zap_isdn_configure_span(span, Q931_TE, 0, on_signal); - zap_isdn_start(span); + if (zap_isdn_configure_span(span, Q931_TE, 0, on_signal) == ZAP_SUCCESS) { + zap_isdn_start(span); + } else { + fprintf(stderr, "Error starting ISDN D-Channel\n"); + goto done; + } while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { sleep(1); } + done: + zap_global_destroy(); } From 8ab54893ce174edcd8e7e8c468d4db81495803a1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 13:46:54 +0000 Subject: [PATCH 0272/1766] fix test app git-svn-id: http://svn.openzap.org/svn/openzap/trunk@136 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testisdn.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index c55905d3f4..11e945ec79 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -21,16 +21,23 @@ int main(int argc, char *argv[]) if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { fprintf(stderr, "Error finding OpenZAP span\n"); + goto done; } - zap_isdn_configure_span(span, Q931_TE, 0, on_signal); - zap_isdn_start(span); + if (zap_isdn_configure_span(span, Q931_TE, 0, on_signal) == ZAP_SUCCESS) { + zap_isdn_start(span); + } else { + fprintf(stderr, "Error starting ISDN D-Channel\n"); + goto done; + } while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { sleep(1); } + done: + zap_global_destroy(); } From 2111722eb08124a9f2191a137b2d5adf84c7ad3d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 14:27:20 +0000 Subject: [PATCH 0273/1766] Use the same Q931mes_Generic for all messages for simplicity. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@137 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 4 +- libs/openzap/src/isdn/Q931StateNT.c | 2 +- libs/openzap/src/isdn/Q931StateTE.c | 8 +- libs/openzap/src/isdn/Q931api.c | 60 ++-- libs/openzap/src/isdn/Q931mes.c | 134 +++---- libs/openzap/src/isdn/include/Q931.h | 506 +-------------------------- libs/openzap/src/isdn/nationalmes.c | 8 +- libs/openzap/src/zap_isdn.c | 8 +- 8 files changed, 117 insertions(+), 613 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 0e130a3668..ef2ddd63c2 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -319,7 +319,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) { L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; - Q931mes_Alerting *m = (Q931mes_Alerting *) pTrunk->L3Buf; + Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; L3INT ISize; L3INT IOff = 0; @@ -409,7 +409,7 @@ L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { L3INT OSize; - Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; + Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; L3INT RetCode = Q931E_NO_ERROR; L3INT iDialect = pTrunk->Dialect; diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 55857c7268..3343170786 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -294,7 +294,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT callIndex; L3INT ret=Q931E_NO_ERROR; diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index e0653b125d..eb9c2a38fb 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -376,7 +376,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -482,7 +482,7 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT callIndex; L3INT ret = Q931E_NO_ERROR; @@ -750,7 +750,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; if(state == Q931_U0 && iFrom == 2) @@ -772,7 +772,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; if(state == Q931_U0 && iFrom == 2) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index b5e3662316..eba3c23acb 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -182,47 +182,47 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) { L3UCHAR * s=NULL; - Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931mes_Generic * pMes= (Q931mes_Generic *)pm; switch(pMes->MesType) { case Q931mes_ALERTING : - trampoline(Q931mes_Alerting); + trampoline(Q931mes_Generic); break; case Q931mes_CALL_PROCEEDING : - trampoline(Q931mes_CallProceeding); + trampoline(Q931mes_Generic); break; case Q931mes_CONNECT : - trampoline(Q931mes_Connect); + trampoline(Q931mes_Generic); break; case Q931mes_CONNECT_ACKNOWLEDGE : - trampoline(Q931mes_ConnectAck); + trampoline(Q931mes_Generic); break; case Q931mes_PROGRESS : - trampoline(Q931mes_Progress); + trampoline(Q931mes_Generic); break; case Q931mes_SETUP : - trampoline(Q931mes_Setup); + trampoline(Q931mes_Generic); break; case Q931mes_SETUP_ACKNOWLEDGE : - trampoline(Q931mes_SetupAck); + trampoline(Q931mes_Generic); break; case Q931mes_RESUME : - trampoline(Q931mes_Resume); + trampoline(Q931mes_Generic); break; case Q931mes_RESUME_ACKNOWLEDGE : - trampoline(Q931mes_ResumeAck); + trampoline(Q931mes_Generic); break; case Q931mes_RESUME_REJECT : - trampoline(Q931mes_ResumeReject); + trampoline(Q931mes_Generic); break; case Q932mes_RETRIEVE : @@ -238,43 +238,43 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) break; case Q931mes_SUSPEND : - trampoline(Q931mes_Suspend); + trampoline(Q931mes_Generic); break; case Q931mes_SUSPEND_ACKNOWLEDGE : - trampoline(Q931mes_SuspendAck); + trampoline(Q931mes_Generic); break; case Q931mes_SUSPEND_REJECT : - trampoline(Q931mes_SuspendReject); + trampoline(Q931mes_Generic); break; case Q931mes_USER_INFORMATION : - trampoline(Q931mes_UserInformation); + trampoline(Q931mes_Generic); break; case Q931mes_DISCONNECT : - trampoline(Q931mes_Disconnect); + trampoline(Q931mes_Generic); break; case Q931mes_RELEASE : - trampoline(Q931mes_Release); + trampoline(Q931mes_Generic); break; case Q931mes_RELEASE_COMPLETE : - trampoline(Q931mes_ReleaseComplete); + trampoline(Q931mes_Generic); break; case Q931mes_RESTART : - trampoline(Q931mes_Restart); + trampoline(Q931mes_Generic); break; case Q931mes_RESTART_ACKNOWLEDGE : - trampoline(Q931mes_RestartAck); + trampoline(Q931mes_Generic); break; case Q931mes_CONGESTION_CONTROL : - trampoline(Q931mes_CongestionControl); + trampoline(Q931mes_Generic); break; #if 0 case Q931mes_FACILITY : @@ -283,11 +283,11 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) #endif case Q931mes_INFORMATION : - trampoline(Q931mes_Information); + trampoline(Q931mes_Generic); break; case Q931mes_NOTIFY : - trampoline(Q931mes_Notify); + trampoline(Q931mes_Generic); break; #if 0 @@ -297,15 +297,15 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) #endif case Q931mes_STATUS : - trampoline(Q931mes_Status); + trampoline(Q931mes_Generic); break; case Q931mes_STATUS_ENQUIRY : - trampoline(Q931mes_StatusEnquiry); + trampoline(Q931mes_Generic); break; case Q931mes_SEGMENT : - trampoline(Q931mes_Segment); + trampoline(Q931mes_Generic); break; default: @@ -340,7 +340,7 @@ L3INT Q931GetMesSize(L3UCHAR *pMes) ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) { ie IE = 0; - Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931mes_Generic * pMes= (Q931mes_Generic *)pm; Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; L3INT iISize = pIE->Size; @@ -363,7 +363,7 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) return crv++; } -L3INT Q931InitMesSetup(Q931mes_Setup *pMes) +L3INT Q931InitMesSetup(Q931mes_Generic *pMes) { pMes->ProtDisc = 0x80; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ @@ -393,7 +393,7 @@ L3INT Q931InitMesSetup(Q931mes_Setup *pMes) return 0; } -L3INT Q931InitMesResume(Q931mes_Resume * pMes) +L3INT Q931InitMesResume(Q931mes_Generic * pMes) { pMes->ProtDisc = 0x80; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ @@ -404,7 +404,7 @@ L3INT Q931InitMesResume(Q931mes_Resume * pMes) return 0; } -L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes) +L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes) { pMes->ProtDisc = 0x80; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index b1c9851611..62777dd13f 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -54,7 +54,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; while(IOff < Size) @@ -96,7 +96,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -108,7 +108,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -166,7 +166,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -202,7 +202,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O break; } } - mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -214,7 +214,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -300,7 +300,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -351,7 +351,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -363,7 +363,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -431,7 +431,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -453,7 +453,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -466,7 +466,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -502,7 +502,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -533,7 +533,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -545,7 +545,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -591,7 +591,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Information *mes = (Q931mes_Information*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -626,7 +626,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu break; } } - mes->Size = sizeof(Q931mes_Information) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -638,7 +638,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Information *pMes = (Q931mes_Information *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -688,7 +688,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -713,7 +713,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 break; } } - mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -725,7 +725,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -763,7 +763,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -799,7 +799,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -811,7 +811,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -861,7 +861,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Release *mes = (Q931mes_Release*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -887,7 +887,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Release) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -899,7 +899,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Release *pMes = (Q931mes_Release *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -938,7 +938,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -964,7 +964,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR break; } } - mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -976,7 +976,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1013,7 +1013,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; - Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1039,7 +1039,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Restart) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1051,7 +1051,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1088,7 +1088,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; - Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1114,7 +1114,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1126,7 +1126,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1165,7 +1165,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1181,7 +1181,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 break; } } - mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1193,7 +1193,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1224,7 +1224,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1245,7 +1245,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1258,7 +1258,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1293,7 +1293,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1314,7 +1314,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O break; } } - mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1327,7 +1327,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1378,7 +1378,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1485,7 +1485,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I break; } } - mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1493,7 +1493,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Setup - Decription: Pack a Q931mes_Setup into a real Q.931 message. The user will + 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 @@ -1510,7 +1510,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1629,7 +1629,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1660,7 +1660,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1672,7 +1672,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1718,7 +1718,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Status *mes = (Q931mes_Status*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1744,7 +1744,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 break; } } - mes->Size = sizeof(Q931mes_Status) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1757,7 +1757,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Status *pMes = (Q931mes_Status *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1796,7 +1796,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1812,7 +1812,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O break; } } - mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1824,7 +1824,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1855,7 +1855,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1871,7 +1871,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1883,7 +1883,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1914,7 +1914,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) @@ -1931,7 +1931,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1943,7 +1943,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1974,7 +1974,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1995,7 +1995,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O break; } } - mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -2007,7 +2007,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 00e4f3738f..28b16873ea 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1373,6 +1373,7 @@ typedef struct ie Segment; /* Segmented message */ ie BearerCap; /* Bearer Capability */ ie Cause; /* Cause */ + ie CallState; /* Call State */ ie CallID; /* Call Identity */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1396,6 +1397,8 @@ typedef struct 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 */ @@ -1405,505 +1408,6 @@ typedef struct }Q931mes_Generic; -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; /***************************************************************************** @@ -2396,8 +1900,8 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, void Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); -L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes); +L3INT Q931InitMesSetup(Q931mes_Generic *p); +L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes); L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex); L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex); diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index c32398d00d..70f995d245 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -56,7 +56,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -166,7 +166,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -174,7 +174,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: nationalPmes_Setup - Decription: Pack a Q931mes_Setup into a real Q.931 message. The user will + 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 @@ -191,7 +191,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 814a19c237..7da934b0bb 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -68,7 +68,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931mes_Generic *gen = (Q931mes_Generic *) msg; - Q931mes_Restart * restart = (Q931mes_Restart*)msg; + Q931mes_Generic * restart = (Q931mes_Generic*)msg; L3INT ieoff = Q931GetIEOffset(restart->RestartInd); Q931ie_RestartInd * restartind = (void *)(&restart->buf + (ieoff * sizeof(restart->buf[1]))); @@ -76,10 +76,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) assert(span != NULL); assert(data != NULL); - printf("WTF: %d", ((Q931mes_Restart*)gen)->Size); - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Restart*)gen)->Size); + printf("WTF: %d", ((Q931mes_Generic*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Generic*)gen)->Size); zap_log(ZAP_LOG_DEBUG, "send ack %d\n", restartind->Class); - zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Restart*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Generic*)gen)->Size); printf("XXXXXXXXXXXXx"); gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; From 4f86bcc241a9aa4d964bca8b50a0ae5c92c8a3d3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 14:27:20 +0000 Subject: [PATCH 0274/1766] Use the same Q931mes_Generic for all messages for simplicity. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@137 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 4 +- libs/freetdm/src/isdn/Q931StateNT.c | 2 +- libs/freetdm/src/isdn/Q931StateTE.c | 8 +- libs/freetdm/src/isdn/Q931api.c | 60 ++-- libs/freetdm/src/isdn/Q931mes.c | 134 +++---- libs/freetdm/src/isdn/include/Q931.h | 506 +-------------------------- libs/freetdm/src/isdn/nationalmes.c | 8 +- libs/freetdm/src/zap_isdn.c | 8 +- 8 files changed, 117 insertions(+), 613 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 0e130a3668..ef2ddd63c2 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -319,7 +319,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) { L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; - Q931mes_Alerting *m = (Q931mes_Alerting *) pTrunk->L3Buf; + Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; L3INT ISize; L3INT IOff = 0; @@ -409,7 +409,7 @@ L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { L3INT OSize; - Q931mes_Alerting *ptr = (Q931mes_Alerting*)Mes; + Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; L3INT RetCode = Q931E_NO_ERROR; L3INT iDialect = pTrunk->Dialect; diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 55857c7268..3343170786 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -294,7 +294,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT callIndex; L3INT ret=Q931E_NO_ERROR; diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index e0653b125d..eb9c2a38fb 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -376,7 +376,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { L3INT rc=0; - Q931mes_Setup *pMes = (Q931mes_Setup *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT callIndex; L3INT ret=Q931E_NO_ERROR; @@ -482,7 +482,7 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Resume * pMes = (Q931mes_Resume *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT callIndex; L3INT ret = Q931E_NO_ERROR; @@ -750,7 +750,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Release *pMes = (Q931mes_Release *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; if(state == Q931_U0 && iFrom == 2) @@ -772,7 +772,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)&buf[Q931L4HeaderSpace]; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; if(state == Q931_U0 && iFrom == 2) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index b5e3662316..eba3c23acb 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -182,47 +182,47 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) { L3UCHAR * s=NULL; - Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931mes_Generic * pMes= (Q931mes_Generic *)pm; switch(pMes->MesType) { case Q931mes_ALERTING : - trampoline(Q931mes_Alerting); + trampoline(Q931mes_Generic); break; case Q931mes_CALL_PROCEEDING : - trampoline(Q931mes_CallProceeding); + trampoline(Q931mes_Generic); break; case Q931mes_CONNECT : - trampoline(Q931mes_Connect); + trampoline(Q931mes_Generic); break; case Q931mes_CONNECT_ACKNOWLEDGE : - trampoline(Q931mes_ConnectAck); + trampoline(Q931mes_Generic); break; case Q931mes_PROGRESS : - trampoline(Q931mes_Progress); + trampoline(Q931mes_Generic); break; case Q931mes_SETUP : - trampoline(Q931mes_Setup); + trampoline(Q931mes_Generic); break; case Q931mes_SETUP_ACKNOWLEDGE : - trampoline(Q931mes_SetupAck); + trampoline(Q931mes_Generic); break; case Q931mes_RESUME : - trampoline(Q931mes_Resume); + trampoline(Q931mes_Generic); break; case Q931mes_RESUME_ACKNOWLEDGE : - trampoline(Q931mes_ResumeAck); + trampoline(Q931mes_Generic); break; case Q931mes_RESUME_REJECT : - trampoline(Q931mes_ResumeReject); + trampoline(Q931mes_Generic); break; case Q932mes_RETRIEVE : @@ -238,43 +238,43 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) break; case Q931mes_SUSPEND : - trampoline(Q931mes_Suspend); + trampoline(Q931mes_Generic); break; case Q931mes_SUSPEND_ACKNOWLEDGE : - trampoline(Q931mes_SuspendAck); + trampoline(Q931mes_Generic); break; case Q931mes_SUSPEND_REJECT : - trampoline(Q931mes_SuspendReject); + trampoline(Q931mes_Generic); break; case Q931mes_USER_INFORMATION : - trampoline(Q931mes_UserInformation); + trampoline(Q931mes_Generic); break; case Q931mes_DISCONNECT : - trampoline(Q931mes_Disconnect); + trampoline(Q931mes_Generic); break; case Q931mes_RELEASE : - trampoline(Q931mes_Release); + trampoline(Q931mes_Generic); break; case Q931mes_RELEASE_COMPLETE : - trampoline(Q931mes_ReleaseComplete); + trampoline(Q931mes_Generic); break; case Q931mes_RESTART : - trampoline(Q931mes_Restart); + trampoline(Q931mes_Generic); break; case Q931mes_RESTART_ACKNOWLEDGE : - trampoline(Q931mes_RestartAck); + trampoline(Q931mes_Generic); break; case Q931mes_CONGESTION_CONTROL : - trampoline(Q931mes_CongestionControl); + trampoline(Q931mes_Generic); break; #if 0 case Q931mes_FACILITY : @@ -283,11 +283,11 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) #endif case Q931mes_INFORMATION : - trampoline(Q931mes_Information); + trampoline(Q931mes_Generic); break; case Q931mes_NOTIFY : - trampoline(Q931mes_Notify); + trampoline(Q931mes_Generic); break; #if 0 @@ -297,15 +297,15 @@ L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) #endif case Q931mes_STATUS : - trampoline(Q931mes_Status); + trampoline(Q931mes_Generic); break; case Q931mes_STATUS_ENQUIRY : - trampoline(Q931mes_StatusEnquiry); + trampoline(Q931mes_Generic); break; case Q931mes_SEGMENT : - trampoline(Q931mes_Segment); + trampoline(Q931mes_Generic); break; default: @@ -340,7 +340,7 @@ L3INT Q931GetMesSize(L3UCHAR *pMes) ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) { ie IE = 0; - Q931mes_Alerting * pMes= (Q931mes_Alerting *)pm; + Q931mes_Generic * pMes= (Q931mes_Generic *)pm; Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; L3INT iISize = pIE->Size; @@ -363,7 +363,7 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) return crv++; } -L3INT Q931InitMesSetup(Q931mes_Setup *pMes) +L3INT Q931InitMesSetup(Q931mes_Generic *pMes) { pMes->ProtDisc = 0x80; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ @@ -393,7 +393,7 @@ L3INT Q931InitMesSetup(Q931mes_Setup *pMes) return 0; } -L3INT Q931InitMesResume(Q931mes_Resume * pMes) +L3INT Q931InitMesResume(Q931mes_Generic * pMes) { pMes->ProtDisc = 0x80; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ @@ -404,7 +404,7 @@ L3INT Q931InitMesResume(Q931mes_Resume * pMes) return 0; } -L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes) +L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes) { pMes->ProtDisc = 0x80; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index b1c9851611..62777dd13f 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -54,7 +54,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Alerting *mes = (Q931mes_Alerting*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; while(IOff < Size) @@ -96,7 +96,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_Alerting) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -108,7 +108,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Alerting *pMes = (Q931mes_Alerting *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -166,7 +166,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_CallProceeding *mes = (Q931mes_CallProceeding*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -202,7 +202,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O break; } } - mes->Size = sizeof(Q931mes_CallProceeding) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -214,7 +214,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_CallProceeding *pMes = (Q931mes_CallProceeding *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -300,7 +300,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Connect *mes = (Q931mes_Connect*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -351,7 +351,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Connect) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -363,7 +363,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Connect *pMes = (Q931mes_Connect *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -431,7 +431,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ConnectAck *mes = (Q931mes_ConnectAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -453,7 +453,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_ConnectAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -466,7 +466,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ConnectAck *pMes = (Q931mes_ConnectAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -502,7 +502,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Disconnect *mes = (Q931mes_Disconnect*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -533,7 +533,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_Disconnect) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -545,7 +545,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Disconnect *pMes = (Q931mes_Disconnect *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -591,7 +591,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Information *mes = (Q931mes_Information*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -626,7 +626,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu break; } } - mes->Size = sizeof(Q931mes_Information) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -638,7 +638,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Information *pMes = (Q931mes_Information *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -688,7 +688,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Notify *mes = (Q931mes_Notify*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -713,7 +713,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 break; } } - mes->Size = sizeof(Q931mes_Notify) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -725,7 +725,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Notify *pMes = (Q931mes_Notify *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -763,7 +763,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Progress *mes = (Q931mes_Progress*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -799,7 +799,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_Progress) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -811,7 +811,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Progress *pMes = (Q931mes_Progress *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -861,7 +861,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Release *mes = (Q931mes_Release*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -887,7 +887,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Release) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -899,7 +899,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Release *pMes = (Q931mes_Release *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -938,7 +938,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ReleaseComplete *mes = (Q931mes_ReleaseComplete*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -964,7 +964,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR break; } } - mes->Size = sizeof(Q931mes_ReleaseComplete) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -976,7 +976,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ReleaseComplete *pMes = (Q931mes_ReleaseComplete *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1013,7 +1013,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; - Q931mes_Restart *mes = (Q931mes_Restart*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1039,7 +1039,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Restart) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1051,7 +1051,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Restart *pMes = (Q931mes_Restart *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1088,7 +1088,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; - Q931mes_RestartAck *mes = (Q931mes_RestartAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1114,7 +1114,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_RestartAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1126,7 +1126,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_RestartAck *pMes = (Q931mes_RestartAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1165,7 +1165,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Resume *mes = (Q931mes_Resume*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1181,7 +1181,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 break; } } - mes->Size = sizeof(Q931mes_Resume) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1193,7 +1193,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Resume *pMes = (Q931mes_Resume *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1224,7 +1224,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ResumeAck *mes = (Q931mes_ResumeAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1245,7 +1245,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_ResumeAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1258,7 +1258,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeAck *pMes = (Q931mes_ResumeAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1293,7 +1293,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_ResumeReject *mes = (Q931mes_ResumeReject*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1314,7 +1314,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O break; } } - mes->Size = sizeof(Q931mes_ResumeReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1327,7 +1327,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_ResumeReject *pMes = (Q931mes_ResumeReject *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1378,7 +1378,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1485,7 +1485,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I break; } } - mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1493,7 +1493,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Function: Q931Pmes_Setup - Decription: Pack a Q931mes_Setup into a real Q.931 message. The user will + 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 @@ -1510,7 +1510,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1629,7 +1629,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_SetupAck *mes = (Q931mes_SetupAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1660,7 +1660,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_SetupAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1672,7 +1672,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_SetupAck *pMes = (Q931mes_SetupAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1718,7 +1718,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Status *mes = (Q931mes_Status*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1744,7 +1744,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 break; } } - mes->Size = sizeof(Q931mes_Status) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1757,7 +1757,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Status *pMes = (Q931mes_Status *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1796,7 +1796,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_StatusEnquiry *mes = (Q931mes_StatusEnquiry*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1812,7 +1812,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O break; } } - mes->Size = sizeof(Q931mes_StatusEnquiry) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1824,7 +1824,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_StatusEnquiry *pMes = (Q931mes_StatusEnquiry *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1855,7 +1855,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Suspend *mes = (Q931mes_Suspend*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1871,7 +1871,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L break; } } - mes->Size = sizeof(Q931mes_Suspend) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1883,7 +1883,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Suspend *pMes = (Q931mes_Suspend *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1914,7 +1914,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_SuspendAck *mes = (Q931mes_SuspendAck*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) @@ -1931,7 +1931,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf break; } } - mes->Size = sizeof(Q931mes_SuspendAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -1943,7 +1943,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendAck *pMes = (Q931mes_SuspendAck *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ @@ -1974,7 +1974,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_SuspendReject *mes = (Q931mes_SuspendReject*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -1995,7 +1995,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O break; } } - mes->Size = sizeof(Q931mes_SuspendReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -2007,7 +2007,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_SuspendReject *pMes = (Q931mes_SuspendReject *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 00e4f3738f..28b16873ea 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1373,6 +1373,7 @@ typedef struct ie Segment; /* Segmented message */ ie BearerCap; /* Bearer Capability */ ie Cause; /* Cause */ + ie CallState; /* Call State */ ie CallID; /* Call Identity */ ie ChanID; /* Channel Identification */ ie ProgInd; /* Progress Indicator */ @@ -1396,6 +1397,8 @@ typedef struct 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 */ @@ -1405,505 +1408,6 @@ typedef struct }Q931mes_Generic; -/***************************************************************************** - - Struct: Q931mes_Alerting - - Description: This message is send by the called party to indicate that - the phone is ringing. - - The message consist of an header that MUST be identical with - Q931mes_Header, a fixed number of IE flags w/offset, and - a dynamic buffer storing normalized IE's. - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Alerting; - -/***************************************************************************** - - Struct: Q931mes_CallProceeding - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CallProceeding; - -/***************************************************************************** - - Struct: Q931mes_Connect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel Identification */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie Signal; /* Signal */ - ie LLComp; /* Low Layer Compatibility */ - ie HLComp; /* High layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Connect; - -/***************************************************************************** - - Struct: Q931mes_ConnectAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ConnectAck; - -/***************************************************************************** - - Struct: Q931mes_Disconnect - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User - user. Packed Mode. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Disconnect; - -/***************************************************************************** - - Struct: Q931mes_Information - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie Display; /* Display */ - ie KeypadFac; /* Keypad facility */ - ie Signal; /* Signal */ - ie CalledNum; /* Called party number */ -#ifdef Q931_X25_SUPPORT - ie Cause; /* Cause (packed only) */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Information; - -/***************************************************************************** - - Struct: Q931mes_Notify - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie NotifInd; /* Notification Indicator */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Notify; - -/***************************************************************************** - - Struct: Q931mes_Progress - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie BearerCap; /* Bearer Capability */ - ie Cause; /* Cause */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie HLComp; /* High Layer Compatibility */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Progress; - -/***************************************************************************** - - Struct: Q931mes_Release - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Release; - -/***************************************************************************** - - Struct: Q931mes_ReleaseComplete - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - ie Signal; /* Signal */ -#ifdef Q931_X25_SUPPORT - ie UserUser; /* User-User packed mode */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ReleaseComplete; - -/***************************************************************************** - - Struct: Q931mes_Resume - -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; -}Q931mes_Resume; - -/***************************************************************************** - - Struct: Q931mes_ResumeAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeAck; - -/***************************************************************************** - - Struct: Q931mes_ResumeReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_ResumeReject; - -/***************************************************************************** - - Struct: Q931mes_Segment - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Segment; - -/***************************************************************************** - - Struct: Q931mes_Setup - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie SendComplete; /* Sending Complete */ - ie RepeatInd; /* Repeat Indicator */ - ie BearerCap; /* Bearer Capability */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie NetFac; /* Network-specific facilities */ - /* Note: Up to 4 NetFac's may be */ - /* included. */ - ie Display; /* Display */ - ie DateTime; /* Date/Time */ - ie KeypadFac; /* Keypad Facility */ - ie Signal; /* Signal */ - ie CallingNum; /* Calling party number */ - ie CallingSub; /* Calling party sub address */ - ie CalledNum; /* Called party number */ - ie CalledSub; /* Called party sub address */ - ie TransNetSel; /* Transit network selection */ - ie LLRepeatInd; /* Repeat Indicator 2 LLComp */ - ie LLComp; /* Low layer compatibility */ - ie HLComp; /* High layer compatibility */ - -#ifdef Q931_X25_SUPPORT - /* Packed mode additions */ - ie IndoRate; /* Information Rate */ - ie EndEndDelay; /* End-end transit delay */ - ie TransDelayInd; /* TRansit delay selection and ind. */ - ie PackParam; /* Packed layer binary parameters */ - ie PackWinSize; /* Packed layer window size */ - ie PackSize; /* Packet Size */ - ie ClosedUserGrp; /* Closed User Group */ - ie RevChargInd; /* Reverse charhing indicator */ - ie RedirNum; /* Redirection number */ - ie UserUser; /* User-user. */ -#endif - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Setup; - -/***************************************************************************** - - Struct: Q931mes_SetupAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel ID */ - ie ProgInd; /* Progress Indicator */ - ie Display; /* Display */ - ie Signal; /* Signal */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SetupAck; - -/***************************************************************************** - - Struct: Q931mes_Status - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie CallState; /* Call State */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Status; - -/***************************************************************************** - - Struct: Q931mes_StatusEnquire - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_StatusEnquiry; - -/***************************************************************************** - - Struct: Q931mes_Suspend - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CallID; /* Call Identity */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Suspend; - -/***************************************************************************** - - Struct: Q931mes_SuspendAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendAck; - -/***************************************************************************** - - Struct: Q931mes_SuspendReject - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_SuspendReject; - -/***************************************************************************** - - Struct: Q931mes_CongestionControl - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie CongLevel; /* Congestion level */ - ie Cause; /* Cause */ - ie Display; /* Display */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_CongestionControl; - -/***************************************************************************** - - Struct: Q931mes_UserInformation - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie MoreData; /* More data */ - ie UserUser; /* User-user */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_UserInformation; - -/***************************************************************************** - - Struct: Q931mes_Restart - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_Restart; - -/***************************************************************************** - - Struct: Q931mes_RestartAck - -*****************************************************************************/ - -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3INT CRV; /* Call reference value */ - ie ChanID; /* Channel identification */ - ie Display; /* Display */ - ie RestartWin; /* Restart Window */ - ie RestartInd; /* Restart Indicator */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q931mes_RestartAck; /***************************************************************************** @@ -2396,8 +1900,8 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, void Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); -L3INT Q931InitMesSetup(Q931mes_Setup *p); -L3INT Q931InitMesRestartAck(Q931mes_RestartAck * pMes); +L3INT Q931InitMesSetup(Q931mes_Generic *p); +L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes); L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex); L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex); diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index c32398d00d..70f995d245 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -56,7 +56,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Setup *mes = (Q931mes_Setup*)OBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; while(IOff < Size) { @@ -166,7 +166,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, break; } } - mes->Size = sizeof(Q931mes_Setup) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -174,7 +174,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: nationalPmes_Setup - Decription: Pack a Q931mes_Setup into a real Q.931 message. The user will + 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 @@ -191,7 +191,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; - Q931mes_Setup *pMes = (Q931mes_Setup *)IBuf; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 814a19c237..7da934b0bb 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -68,7 +68,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931mes_Generic *gen = (Q931mes_Generic *) msg; - Q931mes_Restart * restart = (Q931mes_Restart*)msg; + Q931mes_Generic * restart = (Q931mes_Generic*)msg; L3INT ieoff = Q931GetIEOffset(restart->RestartInd); Q931ie_RestartInd * restartind = (void *)(&restart->buf + (ieoff * sizeof(restart->buf[1]))); @@ -76,10 +76,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) assert(span != NULL); assert(data != NULL); - printf("WTF: %d", ((Q931mes_Restart*)gen)->Size); - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Restart*)gen)->Size); + printf("WTF: %d", ((Q931mes_Generic*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Generic*)gen)->Size); zap_log(ZAP_LOG_DEBUG, "send ack %d\n", restartind->Class); - zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Restart*)gen)->Size); + zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Generic*)gen)->Size); printf("XXXXXXXXXXXXx"); gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; From 0187adfae7f52fef22e94331d8864568629e75ad Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 14:30:36 +0000 Subject: [PATCH 0275/1766] cleanup from generic message header change git-svn-id: http://svn.openzap.org/svn/openzap/trunk@138 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 7da934b0bb..f88f120231 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -67,23 +67,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_isdn_data_t *data = span->isdn_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; - - Q931mes_Generic * restart = (Q931mes_Generic*)msg; - - L3INT ieoff = Q931GetIEOffset(restart->RestartInd); - Q931ie_RestartInd * restartind = (void *)(&restart->buf + (ieoff * sizeof(restart->buf[1]))); - - assert(span != NULL); assert(data != NULL); - printf("WTF: %d", ((Q931mes_Generic*)gen)->Size); - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Generic*)gen)->Size); - zap_log(ZAP_LOG_DEBUG, "send ack %d\n", restartind->Class); - zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Generic*)gen)->Size); - printf("XXXXXXXXXXXXx"); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); + gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; - Q931Rx43(&data->q931, msg, 12); + Q931Rx43(&data->q931, msg, gen->Size); return 0; } From e1cff2315e83bcd51f6b1219b0643382ff4694fc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 14:30:36 +0000 Subject: [PATCH 0276/1766] cleanup from generic message header change git-svn-id: http://svn.openzap.org/svn/openzap/trunk@138 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 7da934b0bb..f88f120231 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -67,23 +67,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_isdn_data_t *data = span->isdn_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; - - Q931mes_Generic * restart = (Q931mes_Generic*)msg; - - L3INT ieoff = Q931GetIEOffset(restart->RestartInd); - Q931ie_RestartInd * restartind = (void *)(&restart->buf + (ieoff * sizeof(restart->buf[1]))); - - assert(span != NULL); assert(data != NULL); - printf("WTF: %d", ((Q931mes_Generic*)gen)->Size); - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! %d %d\n", gen->MesType, ((Q931mes_Generic*)gen)->Size); - zap_log(ZAP_LOG_DEBUG, "send ack %d\n", restartind->Class); - zap_log(ZAP_LOG_DEBUG, "send ack %d\n", ((Q931mes_Generic*)gen)->Size); - printf("XXXXXXXXXXXXx"); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); + gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; - Q931Rx43(&data->q931, msg, 12); + Q931Rx43(&data->q931, msg, gen->Size); return 0; } From 770b88eac0f94c80c7e51f732734c8e6c437c341 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 14:42:00 +0000 Subject: [PATCH 0277/1766] cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@139 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 159 ++------------------------------ 1 file changed, 7 insertions(+), 152 deletions(-) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index eba3c23acb..5ed12702fc 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -170,157 +170,12 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, Q931Uie[dialect][iec] = Q931UieProc; } -#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} -/***************************************************************************** - - Function: Q931GetIEBuf - - Description: Return a ptr to the buf used for IE in the message. - -*****************************************************************************/ -L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) -{ - L3UCHAR * s=NULL; - Q931mes_Generic * pMes= (Q931mes_Generic *)pm; - switch(pMes->MesType) - { - case Q931mes_ALERTING : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CALL_PROCEEDING : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CONNECT : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CONNECT_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_PROGRESS : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SETUP : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SETUP_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESUME : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESUME_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESUME_REJECT : - trampoline(Q931mes_Generic); - break; - - case Q932mes_RETRIEVE : - trampoline(Q932mes_Retrieve); - break; - - case Q932mes_RETRIEVE_ACKNOWLEDGE : - trampoline(Q932mes_RetrieveAck); - break; - - case Q932mes_RETRIEVE_REJECT : - trampoline(Q932mes_RetrieveReject); - break; - - case Q931mes_SUSPEND : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SUSPEND_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SUSPEND_REJECT : - trampoline(Q931mes_Generic); - break; - - case Q931mes_USER_INFORMATION : - trampoline(Q931mes_Generic); - break; - - case Q931mes_DISCONNECT : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RELEASE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RELEASE_COMPLETE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESTART : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESTART_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CONGESTION_CONTROL : - trampoline(Q931mes_Generic); - break; -#if 0 - case Q931mes_FACILITY : - trampoline(Q931mes_Facility); - break; -#endif - - case Q931mes_INFORMATION : - trampoline(Q931mes_Generic); - break; - - case Q931mes_NOTIFY : - trampoline(Q931mes_Generic); - break; - -#if 0 - case Q931mes_REGISTER : - trampoline(Q931mes_Register); - break; -#endif - - case Q931mes_STATUS : - trampoline(Q931mes_Generic); - break; - - case Q931mes_STATUS_ENQUIRY : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SEGMENT : - trampoline(Q931mes_Generic); - break; - - default: - s = 0; - break; - } - - return s; -} - -L3INT Q931GetMesSize(L3UCHAR *pMes) +L3INT Q931GetMesSize(Q931mes_Generic *pMes) { - L3UCHAR *p = Q931GetIEBuf(pMes); - L3INT Size = (L3INT)(p - pMes); + L3UCHAR *p = &pMes->buf[0]; + L3INT Size = (L3INT)(p - (L3UCHAR *)pMes); return Size; } @@ -344,7 +199,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; L3INT iISize = pIE->Size; - L3UCHAR *pBuf = Q931GetIEBuf(pm); + L3UCHAR *pBuf = &pMes->buf[0]; L3INT Off = pMes->Size - (pBuf - pm); IE = (ie)(Off | 0x8000); @@ -369,7 +224,7 @@ L3INT Q931InitMesSetup(Q931mes_Generic *pMes) pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_SETUP; - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->Size = Q931GetMesSize(pMes); pMes->SendComplete =0; /* Sending Complete */ pMes->RepeatInd =0; /* Repeat Indicator */ @@ -399,7 +254,7 @@ L3INT Q931InitMesResume(Q931mes_Generic * pMes) pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESUME; - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->Size = Q931GetMesSize(pMes); pMes->CallID = 0; /* Channel Identification */ return 0; } @@ -410,7 +265,7 @@ L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes) pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE; - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->Size = Q931GetMesSize(pMes); pMes->ChanID = 0; /* Channel Identification */ pMes->Display = 0; pMes->RestartInd = 0; From dd283a1e6c97083e992a4c544851edcccdfe3d84 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 14:42:00 +0000 Subject: [PATCH 0278/1766] cleanup. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@139 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 159 ++------------------------------ 1 file changed, 7 insertions(+), 152 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index eba3c23acb..5ed12702fc 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -170,157 +170,12 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, Q931Uie[dialect][iec] = Q931UieProc; } -#define trampoline(x) {x * t = (x *)pm; s = &t->buf[0];} -/***************************************************************************** - - Function: Q931GetIEBuf - - Description: Return a ptr to the buf used for IE in the message. - -*****************************************************************************/ -L3UCHAR * Q931GetIEBuf(L3UCHAR *pm) -{ - L3UCHAR * s=NULL; - Q931mes_Generic * pMes= (Q931mes_Generic *)pm; - switch(pMes->MesType) - { - case Q931mes_ALERTING : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CALL_PROCEEDING : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CONNECT : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CONNECT_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_PROGRESS : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SETUP : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SETUP_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESUME : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESUME_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESUME_REJECT : - trampoline(Q931mes_Generic); - break; - - case Q932mes_RETRIEVE : - trampoline(Q932mes_Retrieve); - break; - - case Q932mes_RETRIEVE_ACKNOWLEDGE : - trampoline(Q932mes_RetrieveAck); - break; - - case Q932mes_RETRIEVE_REJECT : - trampoline(Q932mes_RetrieveReject); - break; - - case Q931mes_SUSPEND : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SUSPEND_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SUSPEND_REJECT : - trampoline(Q931mes_Generic); - break; - - case Q931mes_USER_INFORMATION : - trampoline(Q931mes_Generic); - break; - - case Q931mes_DISCONNECT : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RELEASE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RELEASE_COMPLETE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESTART : - trampoline(Q931mes_Generic); - break; - - case Q931mes_RESTART_ACKNOWLEDGE : - trampoline(Q931mes_Generic); - break; - - case Q931mes_CONGESTION_CONTROL : - trampoline(Q931mes_Generic); - break; -#if 0 - case Q931mes_FACILITY : - trampoline(Q931mes_Facility); - break; -#endif - - case Q931mes_INFORMATION : - trampoline(Q931mes_Generic); - break; - - case Q931mes_NOTIFY : - trampoline(Q931mes_Generic); - break; - -#if 0 - case Q931mes_REGISTER : - trampoline(Q931mes_Register); - break; -#endif - - case Q931mes_STATUS : - trampoline(Q931mes_Generic); - break; - - case Q931mes_STATUS_ENQUIRY : - trampoline(Q931mes_Generic); - break; - - case Q931mes_SEGMENT : - trampoline(Q931mes_Generic); - break; - - default: - s = 0; - break; - } - - return s; -} - -L3INT Q931GetMesSize(L3UCHAR *pMes) +L3INT Q931GetMesSize(Q931mes_Generic *pMes) { - L3UCHAR *p = Q931GetIEBuf(pMes); - L3INT Size = (L3INT)(p - pMes); + L3UCHAR *p = &pMes->buf[0]; + L3INT Size = (L3INT)(p - (L3UCHAR *)pMes); return Size; } @@ -344,7 +199,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) Q931ie_BearerCap * pIE= (Q931ie_BearerCap *)pi; L3INT iISize = pIE->Size; - L3UCHAR *pBuf = Q931GetIEBuf(pm); + L3UCHAR *pBuf = &pMes->buf[0]; L3INT Off = pMes->Size - (pBuf - pm); IE = (ie)(Off | 0x8000); @@ -369,7 +224,7 @@ L3INT Q931InitMesSetup(Q931mes_Generic *pMes) pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_SETUP; - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->Size = Q931GetMesSize(pMes); pMes->SendComplete =0; /* Sending Complete */ pMes->RepeatInd =0; /* Repeat Indicator */ @@ -399,7 +254,7 @@ L3INT Q931InitMesResume(Q931mes_Generic * pMes) pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESUME; - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->Size = Q931GetMesSize(pMes); pMes->CallID = 0; /* Channel Identification */ return 0; } @@ -410,7 +265,7 @@ L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes) pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE; - pMes->Size = Q931GetMesSize((L3UCHAR*)pMes); + pMes->Size = Q931GetMesSize(pMes); pMes->ChanID = 0; /* Channel Identification */ pMes->Display = 0; pMes->RestartInd = 0; From bbd85a8e9961bdb2874db95de470ee67bb0d8fb1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 16:21:57 +0000 Subject: [PATCH 0279/1766] api rework to pass the Q931mes_Generic pointer into the message pack functions, and out of the message unpack functions. Move Q932 to use the generic message type. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@140 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 12 +-- libs/openzap/src/isdn/Q931api.c | 4 +- libs/openzap/src/isdn/Q931mes.c | 100 +++++++++--------- libs/openzap/src/isdn/Q932mes.c | 64 ++++++------ libs/openzap/src/isdn/include/Q931.h | 108 +++++++++---------- libs/openzap/src/isdn/include/Q932.h | 128 +++-------------------- libs/openzap/src/isdn/include/national.h | 4 +- libs/openzap/src/isdn/nationalmes.c | 4 +- 8 files changed, 164 insertions(+), 260 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index ef2ddd63c2..d7bf935ff0 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -58,8 +58,8 @@ *****************************************************************************/ L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); @@ -143,7 +143,7 @@ L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { return Q931E_UNKNOWN_MESSAGE; } @@ -167,7 +167,7 @@ L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OB Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk,Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { return Q931E_UNKNOWN_MESSAGE; } @@ -334,7 +334,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); if(RetCode >= Q931E_NO_ERROR) { @@ -414,7 +414,7 @@ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) L3INT iDialect = pTrunk->Dialect; /* Call pack function through table. */ - RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); + RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); if(RetCode >= Q931E_NO_ERROR) { if (pTrunk->Q931Tx32CBProc) { diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 5ed12702fc..7ed7f4ce90 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -147,8 +147,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) ) { if(Q931ProcFunc != NULL) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 62777dd13f..b2ef7b7edc 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -49,7 +49,7 @@ *****************************************************************************/ -L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -105,7 +105,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Alerting *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -161,7 +161,7 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_CallProceeding *****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -211,7 +211,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_CallProceeding *****************************************************************************/ -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -262,7 +262,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_CongestionControl *****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { L3BOOL RetCode = L3FALSE; @@ -278,7 +278,7 @@ L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR Function: Q931Pmes_CongestionControl *****************************************************************************/ -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -295,7 +295,7 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT I Function: Q931Umes_Connect *****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -360,7 +360,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Connect *****************************************************************************/ -L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -426,7 +426,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_ConnectAck *****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -463,7 +463,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_ConnectAck *****************************************************************************/ -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -497,7 +497,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Disconnect *****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -542,7 +542,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_Disconnect *****************************************************************************/ -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -586,7 +586,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Information *****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -635,7 +635,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_Information *****************************************************************************/ -L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -683,7 +683,7 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Notify *****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -722,7 +722,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Notify *****************************************************************************/ -L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -758,7 +758,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_Progress *****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -808,7 +808,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Progress *****************************************************************************/ -L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -856,7 +856,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Release *****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -896,7 +896,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Release *****************************************************************************/ -L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -933,7 +933,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_ReleaseComplete *****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -973,7 +973,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR Function: Q931Pmes_ReleaseComplete *****************************************************************************/ -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1010,7 +1010,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS Function: Q931Umes_Restart *****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; @@ -1048,7 +1048,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Restart *****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1085,7 +1085,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_RestartAck *****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; @@ -1123,7 +1123,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_RestartAck *****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1160,7 +1160,7 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Resume *****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1190,7 +1190,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Resume *****************************************************************************/ -L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1219,7 +1219,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_ResumeAck *****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1255,7 +1255,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_ResumeAck *****************************************************************************/ -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1288,7 +1288,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L Function: Q931Umes_ResumeReject *****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1324,7 +1324,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O Function: Q931Pmes_ResumeReject *****************************************************************************/ -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1352,14 +1352,14 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize return rc; } -L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT OOff) { L3INT i = IOff; return IOff - i; } -L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1373,7 +1373,7 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_Setup *****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ L3INT ir=0; @@ -1507,7 +1507,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Called By: Q931ProcSetup *****************************************************************************/ -L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_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; @@ -1624,7 +1624,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_SetupAck *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1669,7 +1669,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_SetupAck *****************************************************************************/ -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1713,7 +1713,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Status *****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1754,7 +1754,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Status *****************************************************************************/ -L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1791,7 +1791,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_StatusEnquiry *****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1821,7 +1821,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_StatusEnquiry *****************************************************************************/ -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1850,7 +1850,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1880,7 +1880,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Suspend *****************************************************************************/ -L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1909,7 +1909,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_SuspendAck *****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1940,7 +1940,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_SuspendAck *****************************************************************************/ -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1969,7 +1969,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_SuspendReject *****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -2004,7 +2004,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_SuspendReject *****************************************************************************/ -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -2038,7 +2038,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_UserInformation *****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -2053,7 +2053,7 @@ L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR Function: Q931Pmes_UserInformation *****************************************************************************/ -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index b6dce79443..a7f85d1672 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -43,16 +43,16 @@ *****************************************************************************/ -L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -61,7 +61,7 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Facility *****************************************************************************/ -L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -77,16 +77,16 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -95,7 +95,7 @@ L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Function: Q931Pmes_Hold *****************************************************************************/ -L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -111,16 +111,16 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ -L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -129,7 +129,7 @@ L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_HoldAck *****************************************************************************/ -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -145,16 +145,16 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U *****************************************************************************/ -L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -163,7 +163,7 @@ L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_HoldReject *****************************************************************************/ -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -179,16 +179,16 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, *****************************************************************************/ -L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Register *mes = (Q932mes_Register*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Register) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -197,7 +197,7 @@ L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Register *****************************************************************************/ -L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -213,16 +213,16 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -231,7 +231,7 @@ L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Retrieve *****************************************************************************/ -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -247,16 +247,16 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -265,7 +265,7 @@ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_RetrieveAck *****************************************************************************/ -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -281,16 +281,16 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, *****************************************************************************/ -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -299,7 +299,7 @@ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_RetrieveReject *****************************************************************************/ -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 28b16873ea..a8682527e5 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1578,8 +1578,8 @@ typedef struct *****************************************************************************/ extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); @@ -1758,57 +1758,57 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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 Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +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); /***************************************************************************** @@ -1891,8 +1891,8 @@ void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); void Q931SetHeaderSpace(L3INT space); void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), diff --git a/libs/openzap/src/isdn/include/Q932.h b/libs/openzap/src/isdn/include/Q932.h index 5d018a9187..34ba9ffa4b 100644 --- a/libs/openzap/src/isdn/include/Q932.h +++ b/libs/openzap/src/isdn/include/Q932.h @@ -55,102 +55,6 @@ *****************************************************************************/ #define Q932ie_FACILITY 0x1c /* 0001 1100 */ -/***************************************************************************** - Struct: Q932ie_Facility -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Facility; - -/***************************************************************************** - Struct: Q932ie_Hold -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Hold; - -/***************************************************************************** - Struct: Q932ie_HoldAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldAck; - -/***************************************************************************** - Struct: Q932ie_HoldReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldReject; - -/***************************************************************************** - Struct: Q932ie_Register -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Register; - -/***************************************************************************** - Struct: Q932ie_Retrieve -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Retrieve; - -/***************************************************************************** - Struct: Q932ie_RetrieveAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveAck; - -/***************************************************************************** - Struct: Q932ie_RetrieveReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveReject; - /***************************************************************************** Function Prototypes. *****************************************************************************/ @@ -172,20 +76,20 @@ 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, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +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/national.h b/libs/openzap/src/isdn/include/national.h index 0bc1fa9e2d..98ad07609b 100644 --- a/libs/openzap/src/isdn/include/national.h +++ b/libs/openzap/src/isdn/include/national.h @@ -104,8 +104,8 @@ L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c *****************************************************************************/ -L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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); /***************************************************************************** diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 70f995d245..d41d7ec751 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -51,7 +51,7 @@ Function: nationalUmes_Setup *****************************************************************************/ -L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ L3INT ir=0; @@ -188,7 +188,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Called By: Q931ProcSetup *****************************************************************************/ -L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +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; From b8bfc4c8e42a203ba55b56fc5f2f1e215bd29cad Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 16:21:57 +0000 Subject: [PATCH 0280/1766] api rework to pass the Q931mes_Generic pointer into the message pack functions, and out of the message unpack functions. Move Q932 to use the generic message type. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@140 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 12 +-- libs/freetdm/src/isdn/Q931api.c | 4 +- libs/freetdm/src/isdn/Q931mes.c | 100 +++++++++--------- libs/freetdm/src/isdn/Q932mes.c | 64 ++++++------ libs/freetdm/src/isdn/include/Q931.h | 108 +++++++++---------- libs/freetdm/src/isdn/include/Q932.h | 128 +++-------------------- libs/freetdm/src/isdn/include/national.h | 4 +- libs/freetdm/src/isdn/nationalmes.c | 4 +- 8 files changed, 164 insertions(+), 260 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index ef2ddd63c2..d7bf935ff0 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -58,8 +58,8 @@ *****************************************************************************/ L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); +L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); @@ -143,7 +143,7 @@ L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { return Q931E_UNKNOWN_MESSAGE; } @@ -167,7 +167,7 @@ L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OB Description: Dummy function for message processing *****************************************************************************/ -L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk,Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { return Q931E_UNKNOWN_MESSAGE; } @@ -334,7 +334,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); if(RetCode >= Q931E_NO_ERROR) { @@ -414,7 +414,7 @@ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) L3INT iDialect = pTrunk->Dialect; /* Call pack function through table. */ - RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk,Mes,Size,&pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); + RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); if(RetCode >= Q931E_NO_ERROR) { if (pTrunk->Q931Tx32CBProc) { diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 5ed12702fc..7ed7f4ce90 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -147,8 +147,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) ) { if(Q931ProcFunc != NULL) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 62777dd13f..b2ef7b7edc 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -49,7 +49,7 @@ *****************************************************************************/ -L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -105,7 +105,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Alerting *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -161,7 +161,7 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_CallProceeding *****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -211,7 +211,7 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_CallProceeding *****************************************************************************/ -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -262,7 +262,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_CongestionControl *****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { L3BOOL RetCode = L3FALSE; @@ -278,7 +278,7 @@ L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR Function: Q931Pmes_CongestionControl *****************************************************************************/ -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -295,7 +295,7 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3INT I Function: Q931Umes_Connect *****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -360,7 +360,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Connect *****************************************************************************/ -L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -426,7 +426,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_ConnectAck *****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -463,7 +463,7 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_ConnectAck *****************************************************************************/ -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -497,7 +497,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Disconnect *****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -542,7 +542,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_Disconnect *****************************************************************************/ -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -586,7 +586,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Information *****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -635,7 +635,7 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Function: Q931Pmes_Information *****************************************************************************/ -L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -683,7 +683,7 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Notify *****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -722,7 +722,7 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Notify *****************************************************************************/ -L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -758,7 +758,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_Progress *****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -808,7 +808,7 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_Progress *****************************************************************************/ -L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -856,7 +856,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Release *****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -896,7 +896,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Release *****************************************************************************/ -L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -933,7 +933,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_ReleaseComplete *****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -973,7 +973,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR Function: Q931Pmes_ReleaseComplete *****************************************************************************/ -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1010,7 +1010,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT IS Function: Q931Umes_Restart *****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; @@ -1048,7 +1048,7 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Restart *****************************************************************************/ -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1085,7 +1085,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_RestartAck *****************************************************************************/ -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { L3INT OOff=0; Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; @@ -1123,7 +1123,7 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_RestartAck *****************************************************************************/ -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1160,7 +1160,7 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_Resume *****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1190,7 +1190,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Resume *****************************************************************************/ -L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1219,7 +1219,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_ResumeAck *****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1255,7 +1255,7 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_ResumeAck *****************************************************************************/ -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1288,7 +1288,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L Function: Q931Umes_ResumeReject *****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1324,7 +1324,7 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * O Function: Q931Pmes_ResumeReject *****************************************************************************/ -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1352,14 +1352,14 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize return rc; } -L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT OOff) +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT OOff) { L3INT i = IOff; return IOff - i; } -L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -1373,7 +1373,7 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_Setup *****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ L3INT ir=0; @@ -1507,7 +1507,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Called By: Q931ProcSetup *****************************************************************************/ -L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_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; @@ -1624,7 +1624,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCH Function: Q931Umes_SetupAck *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1669,7 +1669,7 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_SetupAck *****************************************************************************/ -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1713,7 +1713,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 Function: Q931Umes_Status *****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1754,7 +1754,7 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_Status *****************************************************************************/ -L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1791,7 +1791,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UC Function: Q931Umes_StatusEnquiry *****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1821,7 +1821,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_StatusEnquiry *****************************************************************************/ -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1850,7 +1850,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1880,7 +1880,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Suspend *****************************************************************************/ -L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1909,7 +1909,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U Function: Q931Umes_SuspendAck *****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -1940,7 +1940,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_SuspendAck *****************************************************************************/ -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -1969,7 +1969,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, Function: Q931Umes_SuspendReject *****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ @@ -2004,7 +2004,7 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_SuspendReject *****************************************************************************/ -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; @@ -2038,7 +2038,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISiz Function: Q931Umes_UserInformation *****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O) +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; @@ -2053,7 +2053,7 @@ L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR Function: Q931Pmes_UserInformation *****************************************************************************/ -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index b6dce79443..a7f85d1672 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -43,16 +43,16 @@ *****************************************************************************/ -L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Facility *mes = (Q932mes_Facility*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Facility) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -61,7 +61,7 @@ L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Facility *****************************************************************************/ -L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -77,16 +77,16 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Hold *mes = (Q932mes_Hold*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Hold) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -95,7 +95,7 @@ L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT Function: Q931Pmes_Hold *****************************************************************************/ -L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -111,16 +111,16 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHA *****************************************************************************/ -L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_HoldAck *mes = (Q932mes_HoldAck*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_HoldAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -129,7 +129,7 @@ L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Function: Q931Pmes_HoldAck *****************************************************************************/ -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -145,16 +145,16 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3U *****************************************************************************/ -L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_HoldReject *mes = (Q932mes_HoldReject*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_HoldReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -163,7 +163,7 @@ L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, Function: Q931Pmes_HoldReject *****************************************************************************/ -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -179,16 +179,16 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, *****************************************************************************/ -L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Register *mes = (Q932mes_Register*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Register) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -197,7 +197,7 @@ L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Register *****************************************************************************/ -L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -213,16 +213,16 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_Retrieve *mes = (Q932mes_Retrieve*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_Retrieve) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -231,7 +231,7 @@ L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L Function: Q931Pmes_Retrieve *****************************************************************************/ -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -247,16 +247,16 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3 *****************************************************************************/ -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_RetrieveAck *mes = (Q932mes_RetrieveAck*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_RetrieveAck) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -265,7 +265,7 @@ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf Function: Q931Pmes_RetrieveAck *****************************************************************************/ -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; @@ -281,16 +281,16 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, *****************************************************************************/ -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ /* L3INT ir=0; */ L3INT OOff=0; - Q932mes_RetrieveReject *mes = (Q932mes_RetrieveReject*)IBuf; + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ - mes->Size = sizeof(Q932mes_RetrieveReject) - 1 + OOff; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; return Q931E_NO_ERROR; } @@ -299,7 +299,7 @@ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *O Function: Q931Pmes_RetrieveReject *****************************************************************************/ -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { L3BOOL RetCode = L3FALSE; diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 28b16873ea..a8682527e5 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1578,8 +1578,8 @@ typedef struct *****************************************************************************/ extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); +extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); @@ -1758,57 +1758,57 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c *****************************************************************************/ -L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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 Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +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); /***************************************************************************** @@ -1891,8 +1891,8 @@ void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); void Q931SetHeaderSpace(L3INT space); void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); + L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size), + L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), diff --git a/libs/freetdm/src/isdn/include/Q932.h b/libs/freetdm/src/isdn/include/Q932.h index 5d018a9187..34ba9ffa4b 100644 --- a/libs/freetdm/src/isdn/include/Q932.h +++ b/libs/freetdm/src/isdn/include/Q932.h @@ -55,102 +55,6 @@ *****************************************************************************/ #define Q932ie_FACILITY 0x1c /* 0001 1100 */ -/***************************************************************************** - Struct: Q932ie_Facility -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Facility; - -/***************************************************************************** - Struct: Q932ie_Hold -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Hold; - -/***************************************************************************** - Struct: Q932ie_HoldAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldAck; - -/***************************************************************************** - Struct: Q932ie_HoldReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_HoldReject; - -/***************************************************************************** - Struct: Q932ie_Register -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Register; - -/***************************************************************************** - Struct: Q932ie_Retrieve -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_Retrieve; - -/***************************************************************************** - Struct: Q932ie_RetrieveAck -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveAck; - -/***************************************************************************** - Struct: Q932ie_RetrieveReject -*****************************************************************************/ -typedef struct -{ - L3UINT Size; /* Size of message in bytes */ - L3UCHAR ProtDisc; /* Protocol Discriminator */ - L3UCHAR MesType; /* Message type */ - L3USHORT CRV; /* Call reference value */ - L3UCHAR buf[1]; /* Dynamic buffer */ -}Q932mes_RetrieveReject; - /***************************************************************************** Function Prototypes. *****************************************************************************/ @@ -172,20 +76,20 @@ 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, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); -L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR * OBuf, L3INT I, L3INT O); +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/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h index 0bc1fa9e2d..98ad07609b 100644 --- a/libs/freetdm/src/isdn/include/national.h +++ b/libs/freetdm/src/isdn/include/national.h @@ -104,8 +104,8 @@ L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c *****************************************************************************/ -L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size); -L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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); /***************************************************************************** diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 70f995d245..d41d7ec751 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -51,7 +51,7 @@ Function: nationalUmes_Setup *****************************************************************************/ -L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT IOff, L3INT Size) +L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { /* L3INT i = IOff; */ L3INT ir=0; @@ -188,7 +188,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Called By: Q931ProcSetup *****************************************************************************/ -L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) +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; From 824cf6414f1f31e99f4e971f9d03b166089e49db Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 16:40:03 +0000 Subject: [PATCH 0281/1766] cleanup and simplify the message unpack functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@141 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 304 ++++++++++++---------------- libs/openzap/src/isdn/Q932mes.c | 40 +--- libs/openzap/src/isdn/nationalmes.c | 41 ++-- 3 files changed, 160 insertions(+), 225 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index b2ef7b7edc..04ad6c4fff 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -49,45 +49,42 @@ *****************************************************************************/ -L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; - L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; + while(IOff < Size) { - switch(mescode) + switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -161,39 +158,37 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I Function: Q931Umes_CallProceeding *****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -262,11 +257,11 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L Function: Q931Umes_CongestionControl *****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); + NoWarning(mes); NoWarning(IBuf); return RetCode; @@ -295,54 +290,52 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf Function: Q931Umes_Connect *****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -426,25 +419,23 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_ConnectAck *****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -497,34 +488,32 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_Disconnect *****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -586,37 +575,35 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_Information *****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -683,31 +670,29 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN Function: Q931Umes_Notify *****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -758,39 +743,37 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi Function: Q931Umes_Progress *****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -856,29 +839,27 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I Function: Q931Umes_Release *****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -933,29 +914,27 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_ReleaseComplete *****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1010,27 +989,27 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, Function: Q931Umes_Restart *****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1095,17 +1074,17 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1160,19 +1139,17 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_Resume *****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1219,24 +1196,22 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi Function: Q931Umes_ResumeAck *****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1288,24 +1263,22 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_ResumeReject *****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1352,7 +1325,7 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I return rc; } -L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT OOff) +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT OOff) { L3INT i = IOff; @@ -1373,31 +1346,30 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_Setup *****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: if(ir==0) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else if(ir==1) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else @@ -1406,77 +1378,77 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *O } break; case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1624,34 +1596,32 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz Function: Q931Umes_SetupAck *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1713,29 +1683,27 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I Function: Q931Umes_Status *****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1791,19 +1759,17 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi Function: Q931Umes_StatusEnquiry *****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1850,19 +1816,17 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1909,20 +1873,18 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_SuspendAck *****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1969,24 +1931,22 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_SuspendReject *****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -2038,11 +1998,11 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 Function: Q931Umes_UserInformation *****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O) +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); + NoWarning(mes); NoWarning(IBuf); return RetCode; diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index a7f85d1672..8e011deb31 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -43,12 +43,9 @@ *****************************************************************************/ -L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -77,12 +74,9 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I *****************************************************************************/ -L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -111,12 +105,9 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize *****************************************************************************/ -L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -145,12 +136,9 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS *****************************************************************************/ -L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -179,12 +167,9 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT *****************************************************************************/ -L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -213,12 +198,9 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I *****************************************************************************/ -L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -247,12 +229,9 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I *****************************************************************************/ -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -281,12 +260,9 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN *****************************************************************************/ -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index d41d7ec751..23eb68d185 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -51,31 +51,30 @@ Function: nationalUmes_Setup *****************************************************************************/ -L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: if(ir==0) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else if(ir==1) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else @@ -84,77 +83,77 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi } break; case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; From ea0cd7baf8af2133322901ac44ce8f9d384b55e2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 16:40:03 +0000 Subject: [PATCH 0282/1766] cleanup and simplify the message unpack functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@141 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 304 ++++++++++++---------------- libs/freetdm/src/isdn/Q932mes.c | 40 +--- libs/freetdm/src/isdn/nationalmes.c | 41 ++-- 3 files changed, 160 insertions(+), 225 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index b2ef7b7edc..04ad6c4fff 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -49,45 +49,42 @@ *****************************************************************************/ -L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; - L3UCHAR mescode = (L3UCHAR)IBuf[IOff]; + while(IOff < Size) { - switch(mescode) + switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][mescode](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -161,39 +158,37 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I Function: Q931Umes_CallProceeding *****************************************************************************/ -L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -262,11 +257,11 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L Function: Q931Umes_CongestionControl *****************************************************************************/ -L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); + NoWarning(mes); NoWarning(IBuf); return RetCode; @@ -295,54 +290,52 @@ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf Function: Q931Umes_Connect *****************************************************************************/ -L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -426,25 +419,23 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_ConnectAck *****************************************************************************/ -L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -497,34 +488,32 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_Disconnect *****************************************************************************/ -L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -586,37 +575,35 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_Information *****************************************************************************/ -L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -683,31 +670,29 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN Function: Q931Umes_Notify *****************************************************************************/ -L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -758,39 +743,37 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi Function: Q931Umes_Progress *****************************************************************************/ -L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -856,29 +839,27 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I Function: Q931Umes_Release *****************************************************************************/ -L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -933,29 +914,27 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_ReleaseComplete *****************************************************************************/ -L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1010,27 +989,27 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, Function: Q931Umes_Restart *****************************************************************************/ -L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1095,17 +1074,17 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1160,19 +1139,17 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_Resume *****************************************************************************/ -L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1219,24 +1196,22 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi Function: Q931Umes_ResumeAck *****************************************************************************/ -L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1288,24 +1263,22 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_ResumeReject *****************************************************************************/ -L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1352,7 +1325,7 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I return rc; } -L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT OOff) +L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT OOff) { L3INT i = IOff; @@ -1373,31 +1346,30 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_Setup *****************************************************************************/ -L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: if(ir==0) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else if(ir==1) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else @@ -1406,77 +1378,77 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *O } break; case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1624,34 +1596,32 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz Function: Q931Umes_SetupAck *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1713,29 +1683,27 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I Function: Q931Umes_Status *****************************************************************************/ -L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1791,19 +1759,17 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi Function: Q931Umes_StatusEnquiry *****************************************************************************/ -L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1850,19 +1816,17 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1909,20 +1873,18 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS Function: Q931Umes_SuspendAck *****************************************************************************/ -L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1969,24 +1931,22 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Function: Q931Umes_SuspendReject *****************************************************************************/ -L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -2038,11 +1998,11 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 Function: Q931Umes_UserInformation *****************************************************************************/ -L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT I, L3INT O) +L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT I, L3INT O) { L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); + NoWarning(mes); NoWarning(IBuf); return RetCode; diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index a7f85d1672..8e011deb31 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -43,12 +43,9 @@ *****************************************************************************/ -L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -77,12 +74,9 @@ L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I *****************************************************************************/ -L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -111,12 +105,9 @@ L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize *****************************************************************************/ -L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -145,12 +136,9 @@ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS *****************************************************************************/ -L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -179,12 +167,9 @@ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT *****************************************************************************/ -L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -213,12 +198,9 @@ L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I *****************************************************************************/ -L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -247,12 +229,9 @@ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I *****************************************************************************/ -L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ @@ -281,12 +260,9 @@ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN *****************************************************************************/ -L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ - /* L3INT ir=0; */ L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; /* TODO */ diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index d41d7ec751..23eb68d185 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -51,31 +51,30 @@ Function: nationalUmes_Setup *****************************************************************************/ -L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) +L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - /* L3INT i = IOff; */ L3INT ir=0; L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; L3INT rc=Q931E_NO_ERROR; + while(IOff < Size) { switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: if(ir==0) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else if(ir==1) { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else @@ -84,77 +83,77 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi } break; case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp,&IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; From 5c243c76be7133a2137b28f1e101dc04e4d4fa34 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 16:42:38 +0000 Subject: [PATCH 0283/1766] update some macros and analog stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@142 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 56 ++++++++--- libs/openzap/src/include/zap_analog.h | 3 +- libs/openzap/src/include/zap_types.h | 37 ++++--- libs/openzap/src/testanalog.c | 2 +- libs/openzap/src/zap_analog.c | 28 +++--- libs/openzap/src/zap_io.c | 134 +++++++++++--------------- libs/openzap/src/zap_wanpipe.c | 2 +- 7 files changed, 140 insertions(+), 122 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 8235d30846..cb7e4178be 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -74,6 +74,39 @@ #pragma warning(disable:4706) #endif +#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; +#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ + _TYPE _FUNC1 (char *name) \ + { \ + int i; \ + _TYPE t = _MAX ; \ + \ + for (i = 0; i < _MAX ; i++) { \ + if (!strcasecmp(name, _STRINGS[i])) { \ + t = (_TYPE) i; \ + break; \ + } \ + } \ + \ + return t; \ + } \ + char * _FUNC2 (_TYPE type) \ + { \ + if (type > _MAX) { \ + type = _MAX; \ + } \ + return _STRINGS[(int)type]; \ + } \ + +#define zap_true(expr) \ + (expr && ( !strcasecmp(expr, "yes") || \ + !strcasecmp(expr, "on") || \ + !strcasecmp(expr, "true") || \ + !strcasecmp(expr, "enabled") || \ + !strcasecmp(expr, "active") || \ + atoi(expr))) ? 1 : 0 + #ifndef WIN32 #include #include @@ -108,14 +141,6 @@ #define GOTO_STATUS(label,st) status = st; goto label ; -#define zap_true(expr)\ - (expr && ( !strcasecmp(expr, "yes") ||\ - !strcasecmp(expr, "on") ||\ - !strcasecmp(expr, "true") ||\ - !strcasecmp(expr, "enabled") ||\ - !strcasecmp(expr, "active") ||\ - atoi(expr))) ? 1 : 0 - #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) @@ -138,10 +163,10 @@ */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) -#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL);\ -zap_mutex_lock(obj->mutex);\ -(obj)->flags |= (flag);\ -zap_mutex_unlock(obj->mutex); +#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ + zap_mutex_lock(obj->mutex); \ + (obj)->flags |= (flag); \ + zap_mutex_unlock(obj->mutex); /*! \brief Clear a flag on an arbitrary object while locked @@ -248,6 +273,7 @@ struct zap_span { struct zap_analog_data *analog_data; zap_event_t event_header; char last_error[256]; + char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -269,13 +295,11 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; + +zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); zap_time_t zap_current_time_in_ms(void); -zap_oob_event_t str2zap_oob_signal(char *name); -char *zap_oob_signal2str(zap_oob_event_t type); -zap_trunk_type_t str2zap_trunk_type(char *name); -char *zap_trunk_type2str(zap_trunk_type_t type); zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); diff --git a/libs/openzap/src/include/zap_analog.h b/libs/openzap/src/include/zap_analog.h index 8c12797bf2..ff0919877d 100644 --- a/libs/openzap/src/include/zap_analog.h +++ b/libs/openzap/src/include/zap_analog.h @@ -43,6 +43,5 @@ typedef enum { typedef struct zap_analog_data zap_analog_data_t; zap_status_t zap_analog_start(zap_span_t *span); -zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb); - +zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb); #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1c609a16d6..9fafa28d65 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -51,7 +51,18 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj -typedef uint64_t zap_time_t; +typedef uint64_t zap_time_t; + +#define ZAP_TONEMAP_LEN 128 +typedef enum { + ZAP_TONEMAP_DIAL, + ZAP_TONEMAP_RING, + ZAP_TONEMAP_BUSY, + ZAP_TONEMAP_ATTN, + ZAP_TONEMAP_INVALID +} zap_tonemap_t; +#define TONEMAP_STRINGS "DIAL", "RING", "BUSY", "ATTN", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) typedef enum { ZAP_TRUNK_E1, @@ -60,6 +71,20 @@ typedef enum { ZAP_TRUNK_BRI, ZAP_TRUNK_NONE } zap_trunk_type_t; +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "NONE" +ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_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_INVALID +} zap_oob_event_t; +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t) typedef enum { ZAP_SIGTYPE_NONE, @@ -177,16 +202,6 @@ typedef enum { ZAP_CHANNEL_FLASH = (1 << 10) } zap_channel_flag_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_INVALID -} zap_oob_event_t; typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 7254bf455e..0bec2444b1 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) } - zap_analog_configure_span(span, on_signal); + zap_analog_configure_span(span, "us", on_signal); zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 1021dbae27..0029430615 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -34,17 +34,19 @@ #include "openzap.h" #include "zap_analog.h" -zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb) +zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb) { + if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); return ZAP_FAIL; } - + span->analog_data = malloc(sizeof(*span->analog_data)); assert(span->analog_data != NULL); memset(span->analog_data, 0, sizeof(*span->analog_data)); span->signal_type = ZAP_SIGTYPE_ANALOG; + zap_span_load_tones(span, tonemap); return ZAP_SUCCESS; @@ -60,7 +62,6 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map } wrote = teletone_mux_tones(ts, map); zap_buffer_write(dt_buffer, ts->buffer, wrote * 2); - printf("add %d\n", wrote * 2); return 0; } @@ -72,17 +73,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_codec_t codec = ZAP_CODEC_SLIN, old_codec; - char *tones[] = { "%(1000,0,350,440)", - "%(500,500,480,620)", - "v=2000;%(100,100,1400,2060,2450,2600)", - NULL }; - + char *tones[4] = {0}; time_t start; int isbz = 0; int wtime = 10; zap_tone_type_t tt = ZAP_TONE_DTMF; int play_tones = 1; + + tones[0] = chan->span->tone_map[ZAP_TONEMAP_DIAL]; + tones[1] = chan->span->tone_map[ZAP_TONEMAP_BUSY]; + tones[2] = chan->span->tone_map[ZAP_TONEMAP_ATTN]; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { @@ -96,16 +98,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { goto done; } - /*zap_channel_set_event_callback(chan, my_zap_event_handler);*/ - zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); teletone_init_session(&ts, 0, teletone_handler, dt_buffer); - ts.rate = 8000; +#if 0 ts.debug = 1; ts.debug_stream = stdout; +#endif + ts.rate = 8000; teletone_run(&ts, tones[isbz++]); zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); @@ -113,8 +115,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) time(&start); - - while (chan->state >= ZAP_CHANNEL_STATE_DIALTONE && zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; char dtmf[128]; @@ -167,7 +167,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { - zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_signal2str(event->enum_id), event->channel->span_id, event->channel->chan_id); + zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id); switch(event->enum_id) { case ZAP_OOB_ONHOOK: diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f0e382f2e6..71014be2bc 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -76,85 +76,15 @@ static struct { } globals; -static char *TRUNK_TYPE_NAMES[] = { - "E1", - "T1", - "J1", - "BRI", - "NONE", - NULL -}; +/* enum lookup funcs */ +ZAP_ENUM_NAMES(TONEMAP_NAMES, TONEMAP_STRINGS) +ZAP_STR2ENUM(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t, TONEMAP_NAMES, ZAP_TONEMAP_INVALID) -static char *OOB_NAMES[] = { - "ZAP_OOB_DTMF", - "ZAP_OOB_ONHOOK", - "ZAP_OOB_OFFHOOK", - "WINK", - "FLASH", - "ZAP_OOB_RING_START", - "ZAP_OOB_RING_STOP", - "INVALID", - NULL -}; +ZAP_ENUM_NAMES(OOB_NAMES, OOB_STRINGS) +ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAMES, ZAP_OOB_INVALID) -zap_oob_event_t str2zap_oob_signal(char *name) -{ - int i; - zap_trunk_type_t t = ZAP_OOB_INVALID; - - for (i = 0; i < ZAP_OOB_INVALID; i++) { - if (!strcasecmp(name, OOB_NAMES[i])) { - t = (zap_oob_event_t) i; - break; - } - } - - return t; -} - -char *zap_oob_signal2str(zap_oob_event_t type) -{ - if (type > ZAP_OOB_INVALID) { - type = ZAP_OOB_INVALID; - } - return OOB_NAMES[(int)type]; -} - -static char *LEVEL_NAMES[] = { - "EMERG", - "ALERT", - "CRIT", - "ERROR", - "WARNING", - "NOTICE", - "INFO", - "DEBUG", - NULL -}; - - -zap_trunk_type_t str2zap_trunk_type(char *name) -{ - int i; - zap_trunk_type_t t = ZAP_TRUNK_NONE; - - for (i = 0; i < ZAP_TRUNK_NONE; i++) { - if (!strcasecmp(name, TRUNK_TYPE_NAMES[i])) { - t = (zap_trunk_type_t) i; - break; - } - } - - return t; -} - -char *zap_trunk_type2str(zap_trunk_type_t type) -{ - if (type > ZAP_TRUNK_NONE) { - type = ZAP_TRUNK_NONE; - } - return TRUNK_TYPE_NAMES[(int)type]; -} +ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) +ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) static char *cut_path(char *in) @@ -180,6 +110,19 @@ static void null_logger(char *file, const char *func, int line, int level, char return; } + +static char *LEVEL_NAMES[] = { + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + NULL +}; + static int zap_log_level = 7; static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) @@ -260,6 +203,10 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) new_span->span_id = zio->span_index; new_span->zio = zio; zap_mutex_create(&new_span->mutex); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); *span = new_span; return ZAP_SUCCESS; } @@ -295,6 +242,39 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) return i ? ZAP_SUCCESS : ZAP_FAIL; } +zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) +{ + zap_config_t cfg; + char *var, *val; + int x = 0; + + if (!zap_config_open_file(&cfg, "tones.conf")) { + snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, mapname) && var && val) { + int index = zap_str2zap_tonemap(var); + if (index > ZAP_TONEMAP_INVALID) { + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); + } else { + zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s] %d\n", var, val, index); + zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); + x++; + } + } + } + + if (!x) { + snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); + return ZAP_FAIL; + } + + return ZAP_SUCCESS; + +} + zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 448bc146cd..81aeef82df 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -225,7 +225,7 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) if (!strcasecmp(var, "enabled")) { zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); } else if (!strcasecmp(var, "trunk_type")) { - span->trunk_type = str2zap_trunk_type(val); + span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "fxo-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); From 7973f377e7405e321acfbb1ff44e16ecd4d7f2cb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 16:42:38 +0000 Subject: [PATCH 0284/1766] update some macros and analog stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@142 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 56 ++++++++--- libs/freetdm/src/include/zap_analog.h | 3 +- libs/freetdm/src/include/zap_types.h | 37 ++++--- libs/freetdm/src/testanalog.c | 2 +- libs/freetdm/src/zap_analog.c | 28 +++--- libs/freetdm/src/zap_io.c | 134 +++++++++++--------------- libs/freetdm/src/zap_wanpipe.c | 2 +- 7 files changed, 140 insertions(+), 122 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 8235d30846..cb7e4178be 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -74,6 +74,39 @@ #pragma warning(disable:4706) #endif +#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; +#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ + _TYPE _FUNC1 (char *name) \ + { \ + int i; \ + _TYPE t = _MAX ; \ + \ + for (i = 0; i < _MAX ; i++) { \ + if (!strcasecmp(name, _STRINGS[i])) { \ + t = (_TYPE) i; \ + break; \ + } \ + } \ + \ + return t; \ + } \ + char * _FUNC2 (_TYPE type) \ + { \ + if (type > _MAX) { \ + type = _MAX; \ + } \ + return _STRINGS[(int)type]; \ + } \ + +#define zap_true(expr) \ + (expr && ( !strcasecmp(expr, "yes") || \ + !strcasecmp(expr, "on") || \ + !strcasecmp(expr, "true") || \ + !strcasecmp(expr, "enabled") || \ + !strcasecmp(expr, "active") || \ + atoi(expr))) ? 1 : 0 + #ifndef WIN32 #include #include @@ -108,14 +141,6 @@ #define GOTO_STATUS(label,st) status = st; goto label ; -#define zap_true(expr)\ - (expr && ( !strcasecmp(expr, "yes") ||\ - !strcasecmp(expr, "on") ||\ - !strcasecmp(expr, "true") ||\ - !strcasecmp(expr, "enabled") ||\ - !strcasecmp(expr, "active") ||\ - atoi(expr))) ? 1 : 0 - #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) @@ -138,10 +163,10 @@ */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) -#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL);\ -zap_mutex_lock(obj->mutex);\ -(obj)->flags |= (flag);\ -zap_mutex_unlock(obj->mutex); +#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ + zap_mutex_lock(obj->mutex); \ + (obj)->flags |= (flag); \ + zap_mutex_unlock(obj->mutex); /*! \brief Clear a flag on an arbitrary object while locked @@ -248,6 +273,7 @@ struct zap_span { struct zap_analog_data *analog_data; zap_event_t event_header; char last_error[256]; + char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; }; @@ -269,13 +295,11 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; + +zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); zap_time_t zap_current_time_in_ms(void); -zap_oob_event_t str2zap_oob_signal(char *name); -char *zap_oob_signal2str(zap_oob_event_t type); -zap_trunk_type_t str2zap_trunk_type(char *name); -char *zap_trunk_type2str(zap_trunk_type_t type); zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); diff --git a/libs/freetdm/src/include/zap_analog.h b/libs/freetdm/src/include/zap_analog.h index 8c12797bf2..ff0919877d 100644 --- a/libs/freetdm/src/include/zap_analog.h +++ b/libs/freetdm/src/include/zap_analog.h @@ -43,6 +43,5 @@ typedef enum { typedef struct zap_analog_data zap_analog_data_t; zap_status_t zap_analog_start(zap_span_t *span); -zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb); - +zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb); #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 1c609a16d6..9fafa28d65 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -51,7 +51,18 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj -typedef uint64_t zap_time_t; +typedef uint64_t zap_time_t; + +#define ZAP_TONEMAP_LEN 128 +typedef enum { + ZAP_TONEMAP_DIAL, + ZAP_TONEMAP_RING, + ZAP_TONEMAP_BUSY, + ZAP_TONEMAP_ATTN, + ZAP_TONEMAP_INVALID +} zap_tonemap_t; +#define TONEMAP_STRINGS "DIAL", "RING", "BUSY", "ATTN", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) typedef enum { ZAP_TRUNK_E1, @@ -60,6 +71,20 @@ typedef enum { ZAP_TRUNK_BRI, ZAP_TRUNK_NONE } zap_trunk_type_t; +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "NONE" +ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_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_INVALID +} zap_oob_event_t; +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t) typedef enum { ZAP_SIGTYPE_NONE, @@ -177,16 +202,6 @@ typedef enum { ZAP_CHANNEL_FLASH = (1 << 10) } zap_channel_flag_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_INVALID -} zap_oob_event_t; typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 7254bf455e..0bec2444b1 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) } - zap_analog_configure_span(span, on_signal); + zap_analog_configure_span(span, "us", on_signal); zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 1021dbae27..0029430615 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -34,17 +34,19 @@ #include "openzap.h" #include "zap_analog.h" -zap_status_t zap_analog_configure_span(zap_span_t *span, zio_signal_cb_t sig_cb) +zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb) { + if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); return ZAP_FAIL; } - + span->analog_data = malloc(sizeof(*span->analog_data)); assert(span->analog_data != NULL); memset(span->analog_data, 0, sizeof(*span->analog_data)); span->signal_type = ZAP_SIGTYPE_ANALOG; + zap_span_load_tones(span, tonemap); return ZAP_SUCCESS; @@ -60,7 +62,6 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map } wrote = teletone_mux_tones(ts, map); zap_buffer_write(dt_buffer, ts->buffer, wrote * 2); - printf("add %d\n", wrote * 2); return 0; } @@ -72,17 +73,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_codec_t codec = ZAP_CODEC_SLIN, old_codec; - char *tones[] = { "%(1000,0,350,440)", - "%(500,500,480,620)", - "v=2000;%(100,100,1400,2060,2450,2600)", - NULL }; - + char *tones[4] = {0}; time_t start; int isbz = 0; int wtime = 10; zap_tone_type_t tt = ZAP_TONE_DTMF; int play_tones = 1; + + tones[0] = chan->span->tone_map[ZAP_TONEMAP_DIAL]; + tones[1] = chan->span->tone_map[ZAP_TONEMAP_BUSY]; + tones[2] = chan->span->tone_map[ZAP_TONEMAP_ATTN]; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { @@ -96,16 +98,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { goto done; } - /*zap_channel_set_event_callback(chan, my_zap_event_handler);*/ - zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); teletone_init_session(&ts, 0, teletone_handler, dt_buffer); - ts.rate = 8000; +#if 0 ts.debug = 1; ts.debug_stream = stdout; +#endif + ts.rate = 8000; teletone_run(&ts, tones[isbz++]); zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); @@ -113,8 +115,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) time(&start); - - while (chan->state >= ZAP_CHANNEL_STATE_DIALTONE && zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; char dtmf[128]; @@ -167,7 +167,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { - zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_signal2str(event->enum_id), event->channel->span_id, event->channel->chan_id); + zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id); switch(event->enum_id) { case ZAP_OOB_ONHOOK: diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f0e382f2e6..71014be2bc 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -76,85 +76,15 @@ static struct { } globals; -static char *TRUNK_TYPE_NAMES[] = { - "E1", - "T1", - "J1", - "BRI", - "NONE", - NULL -}; +/* enum lookup funcs */ +ZAP_ENUM_NAMES(TONEMAP_NAMES, TONEMAP_STRINGS) +ZAP_STR2ENUM(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t, TONEMAP_NAMES, ZAP_TONEMAP_INVALID) -static char *OOB_NAMES[] = { - "ZAP_OOB_DTMF", - "ZAP_OOB_ONHOOK", - "ZAP_OOB_OFFHOOK", - "WINK", - "FLASH", - "ZAP_OOB_RING_START", - "ZAP_OOB_RING_STOP", - "INVALID", - NULL -}; +ZAP_ENUM_NAMES(OOB_NAMES, OOB_STRINGS) +ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAMES, ZAP_OOB_INVALID) -zap_oob_event_t str2zap_oob_signal(char *name) -{ - int i; - zap_trunk_type_t t = ZAP_OOB_INVALID; - - for (i = 0; i < ZAP_OOB_INVALID; i++) { - if (!strcasecmp(name, OOB_NAMES[i])) { - t = (zap_oob_event_t) i; - break; - } - } - - return t; -} - -char *zap_oob_signal2str(zap_oob_event_t type) -{ - if (type > ZAP_OOB_INVALID) { - type = ZAP_OOB_INVALID; - } - return OOB_NAMES[(int)type]; -} - -static char *LEVEL_NAMES[] = { - "EMERG", - "ALERT", - "CRIT", - "ERROR", - "WARNING", - "NOTICE", - "INFO", - "DEBUG", - NULL -}; - - -zap_trunk_type_t str2zap_trunk_type(char *name) -{ - int i; - zap_trunk_type_t t = ZAP_TRUNK_NONE; - - for (i = 0; i < ZAP_TRUNK_NONE; i++) { - if (!strcasecmp(name, TRUNK_TYPE_NAMES[i])) { - t = (zap_trunk_type_t) i; - break; - } - } - - return t; -} - -char *zap_trunk_type2str(zap_trunk_type_t type) -{ - if (type > ZAP_TRUNK_NONE) { - type = ZAP_TRUNK_NONE; - } - return TRUNK_TYPE_NAMES[(int)type]; -} +ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) +ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) static char *cut_path(char *in) @@ -180,6 +110,19 @@ static void null_logger(char *file, const char *func, int line, int level, char return; } + +static char *LEVEL_NAMES[] = { + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + NULL +}; + static int zap_log_level = 7; static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) @@ -260,6 +203,10 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) new_span->span_id = zio->span_index; new_span->zio = zio; zap_mutex_create(&new_span->mutex); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); + zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); *span = new_span; return ZAP_SUCCESS; } @@ -295,6 +242,39 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) return i ? ZAP_SUCCESS : ZAP_FAIL; } +zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) +{ + zap_config_t cfg; + char *var, *val; + int x = 0; + + if (!zap_config_open_file(&cfg, "tones.conf")) { + snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, mapname) && var && val) { + int index = zap_str2zap_tonemap(var); + if (index > ZAP_TONEMAP_INVALID) { + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); + } else { + zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s] %d\n", var, val, index); + zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); + x++; + } + } + } + + if (!x) { + snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); + return ZAP_FAIL; + } + + return ZAP_SUCCESS; + +} + zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 448bc146cd..81aeef82df 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -225,7 +225,7 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) if (!strcasecmp(var, "enabled")) { zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); } else if (!strcasecmp(var, "trunk_type")) { - span->trunk_type = str2zap_trunk_type(val); + span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "fxo-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); From b9cd7f91603beaf7cf2f564542948571f0f74724 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 17:19:03 +0000 Subject: [PATCH 0285/1766] error -> error name. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@143 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 58 +++++++++++++++++++++++ libs/openzap/src/isdn/include/Q931.h | 69 ++++++++++++++++------------ libs/openzap/src/zap_isdn.c | 4 +- 3 files changed, 99 insertions(+), 32 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index d7bf935ff0..cc5ff4f00b 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -664,3 +664,61 @@ L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) } 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 - sequensial 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 */ + +}; + +#define Q931_MAX_ERROR 29 + +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]; +} \ No newline at end of file diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index a8682527e5..29f7fa7373 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -121,36 +121,45 @@ Error Codes *****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 +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 + +} 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); /***************************************************************************** diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index f88f120231..2076419ba8 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -57,7 +57,7 @@ static L2ULONG zap_time_now() static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) { - zap_log(ZAP_LOG_ERROR, "ERROR: %d %d %d", id, p1, p2); + zap_log(ZAP_LOG_ERROR, "ERROR: [%s] [%d] [%d]\n", q931_error_to_name(id), p1, p2); return 0; } @@ -82,7 +82,7 @@ static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) - zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] \n", ret); + zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); return ((ret >= 0) ? 1 : 0); } From 3e8c6d83b240d57278a4d17eeb1ebd851148a86e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 17:19:03 +0000 Subject: [PATCH 0286/1766] error -> error name. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@143 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 58 +++++++++++++++++++++++ libs/freetdm/src/isdn/include/Q931.h | 69 ++++++++++++++++------------ libs/freetdm/src/zap_isdn.c | 4 +- 3 files changed, 99 insertions(+), 32 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index d7bf935ff0..cc5ff4f00b 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -664,3 +664,61 @@ L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) } 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 - sequensial 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 */ + +}; + +#define Q931_MAX_ERROR 29 + +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]; +} \ No newline at end of file diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index a8682527e5..29f7fa7373 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -121,36 +121,45 @@ Error Codes *****************************************************************************/ -#define Q931E_NO_ERROR 0 -#define Q931E_UNKNOWN_MESSAGE -3001 -#define Q931E_ILLEGAL_IE -3002 -#define Q931E_UNKNOWN_IE -3003 -#define Q931E_BEARERCAP -3004 -#define Q931E_HLCOMP -3005 -#define Q931E_LLCOMP -3006 -#define Q931E_INTERNAL -3007 -#define Q931E_MISSING_CB -3008 -#define Q931E_UNEXPECTED_MESSAGE -3009 -#define Q931E_ILLEGAL_MESSAGE -3010 -#define Q931E_TOMANYCALLS -3011 -#define Q931E_INVALID_CRV -3012 -#define Q931E_CALLID -3013 -#define Q931E_CALLSTATE -3014 -#define Q931E_CALLEDSUB -3015 -#define Q931E_CALLEDNUM -3016 -#define Q931E_CALLINGNUM -3017 -#define Q931E_CALLINGSUB -3018 -#define Q931E_CAUSE -3019 -#define Q931E_CHANID -3020 -#define Q931E_DATETIME -3021 -#define Q931E_DISPLAY -3022 -#define Q931E_KEYPADFAC -3023 -#define Q931E_NETFAC -3024 -#define Q931E_NOTIFIND -3025 -#define Q931E_PROGIND -3026 -#define Q931E_RESTARTIND -3027 -#define Q931E_SEGMENT -3028 -#define Q931E_SIGNAL -3029 +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 + +} 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); /***************************************************************************** diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index f88f120231..2076419ba8 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -57,7 +57,7 @@ static L2ULONG zap_time_now() static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) { - zap_log(ZAP_LOG_ERROR, "ERROR: %d %d %d", id, p1, p2); + zap_log(ZAP_LOG_ERROR, "ERROR: [%s] [%d] [%d]\n", q931_error_to_name(id), p1, p2); return 0; } @@ -82,7 +82,7 @@ static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) - zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] \n", ret); + zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); return ((ret >= 0) ? 1 : 0); } From 0b76265c6161e66f2ae36397e3e6163b8f2d6b9e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 17:20:27 +0000 Subject: [PATCH 0287/1766] need blank line at end of file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@144 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 3 ++- libs/openzap/src/testisdn.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index cc5ff4f00b..afc57539d0 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -721,4 +721,5 @@ const char *q931_error_to_name(q931_error_t error) return ""; } return q931_error_names[index]; -} \ No newline at end of file +} + diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 11e945ec79..78f3e18a41 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) } - if (zap_isdn_configure_span(span, Q931_TE, 0, on_signal) == ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, on_signal) == ZAP_SUCCESS) { zap_isdn_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); From 499335adf76efd429fec0940cd25009d5a694bed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 17:20:27 +0000 Subject: [PATCH 0288/1766] need blank line at end of file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@144 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 3 ++- libs/freetdm/src/testisdn.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index cc5ff4f00b..afc57539d0 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -721,4 +721,5 @@ const char *q931_error_to_name(q931_error_t error) return ""; } return q931_error_names[index]; -} \ No newline at end of file +} + diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 11e945ec79..78f3e18a41 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) } - if (zap_isdn_configure_span(span, Q931_TE, 0, on_signal) == ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, on_signal) == ZAP_SUCCESS) { zap_isdn_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); From adb55eaedc6f2446f6f9f950e9be0ce9f20f195c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 17:29:22 +0000 Subject: [PATCH 0289/1766] need to count by 2's git-svn-id: http://svn.openzap.org/svn/openzap/trunk@145 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 29f7fa7373..445f948c96 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1445,7 +1445,7 @@ typedef enum /* Network/User Mode. */ typedef enum /* Dialect enum */ { Q931_Dialect_Q931 = 0, - Q931_Dialect_National = 1, + Q931_Dialect_National = 2, Q931_Dialect_Count } Q931Dialect_t; From 47ce357ccb96a23ce5a98640f1dc4f0654fb1a49 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 17:29:22 +0000 Subject: [PATCH 0290/1766] need to count by 2's git-svn-id: http://svn.openzap.org/svn/openzap/trunk@145 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 29f7fa7373..445f948c96 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1445,7 +1445,7 @@ typedef enum /* Network/User Mode. */ typedef enum /* Dialect enum */ { Q931_Dialect_Q931 = 0, - Q931_Dialect_National = 1, + Q931_Dialect_National = 2, Q931_Dialect_Count } Q931Dialect_t; From afb3f35a8287623a82222e5d04f37b6938f0e2be Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 18:16:04 +0000 Subject: [PATCH 0291/1766] Steps towards parsing NI2 Setup message. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@146 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 5 ++++- libs/openzap/src/isdn/nationalie.c | 4 ++-- libs/openzap/src/isdn/nationalmes.c | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index 1703dfd9df..f913e93e65 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -57,6 +57,9 @@ isdn/nationalStateNT.o \ isdn/nationalStateTE.o \ isdn/Q932mes.o +HEADERS=isdn/include/Q931.h \ + include/openzap.h + PWD=$(shell pwd) INCS=-I$(PWD)/include -I$(PWD)/isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) @@ -67,7 +70,7 @@ include general.makefile $(ZAP_MODS) all: $(MYLIB) -$(MYLIB): $(OBJS) +$(MYLIB): $(OBJS) $(HEADERS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) diff --git a/libs/openzap/src/isdn/nationalie.c b/libs/openzap/src/isdn/nationalie.c index b6e2446350..184c11aa18 100644 --- a/libs/openzap/src/isdn/nationalie.c +++ b/libs/openzap/src/isdn/nationalie.c @@ -66,10 +66,10 @@ the current IE. *****************************************************************************/ -#define Q931MoreIE() (Octet+Off - 2 < IESize) +#define Q931MoreIE() (Octet+Off - 2< IESize) #define Q931IESizeTest(x) {\ - if(Octet+Off-2 != IESize)\ + if(Octet + Off - 2!= IESize)\ {\ Q931SetError(pTrunk,x, Octet, Off);\ return x;\ diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 23eb68d185..971016167f 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -159,6 +159,11 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi break; case nationalie_GENERIC_DIGITS: /* TODO: Implement this ie */ + IOff = IOff + 4; + break; + case Q931ie_SHIFT: + /* TODO: Implement this ie */ + IOff++; break; default: return Q931E_ILLEGAL_IE; From 2995ab7be141eba3166e9a7c20a1abadd74def82 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 18:16:04 +0000 Subject: [PATCH 0292/1766] Steps towards parsing NI2 Setup message. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@146 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 5 ++++- libs/freetdm/src/isdn/nationalie.c | 4 ++-- libs/freetdm/src/isdn/nationalmes.c | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index 1703dfd9df..f913e93e65 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -57,6 +57,9 @@ isdn/nationalStateNT.o \ isdn/nationalStateTE.o \ isdn/Q932mes.o +HEADERS=isdn/include/Q931.h \ + include/openzap.h + PWD=$(shell pwd) INCS=-I$(PWD)/include -I$(PWD)/isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) @@ -67,7 +70,7 @@ include general.makefile $(ZAP_MODS) all: $(MYLIB) -$(MYLIB): $(OBJS) +$(MYLIB): $(OBJS) $(HEADERS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) diff --git a/libs/freetdm/src/isdn/nationalie.c b/libs/freetdm/src/isdn/nationalie.c index b6e2446350..184c11aa18 100644 --- a/libs/freetdm/src/isdn/nationalie.c +++ b/libs/freetdm/src/isdn/nationalie.c @@ -66,10 +66,10 @@ the current IE. *****************************************************************************/ -#define Q931MoreIE() (Octet+Off - 2 < IESize) +#define Q931MoreIE() (Octet+Off - 2< IESize) #define Q931IESizeTest(x) {\ - if(Octet+Off-2 != IESize)\ + if(Octet + Off - 2!= IESize)\ {\ Q931SetError(pTrunk,x, Octet, Off);\ return x;\ diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 23eb68d185..971016167f 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -159,6 +159,11 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi break; case nationalie_GENERIC_DIGITS: /* TODO: Implement this ie */ + IOff = IOff + 4; + break; + case Q931ie_SHIFT: + /* TODO: Implement this ie */ + IOff++; break; default: return Q931E_ILLEGAL_IE; From 16735718420e480e8b48bbc7664a4370f4899edc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 May 2007 20:16:45 +0000 Subject: [PATCH 0293/1766] add Q931MegGetIE function to simplify the Pmes functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@147 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 153 +++++++++++++++++++++++++++ libs/openzap/src/isdn/include/Q931.h | 8 ++ 2 files changed, 161 insertions(+) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index afc57539d0..2f3bf63028 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -64,6 +64,156 @@ L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_ L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3UINT Q931MsgieOffset[Q931MAXIE]; + +void Q931Initialize_MsgieOffset() +{ + L3INT x; + Q931mes_Generic msg; + ie *index; + + for(x=0; x Date: Thu, 24 May 2007 20:16:45 +0000 Subject: [PATCH 0294/1766] add Q931MegGetIE function to simplify the Pmes functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@147 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 153 +++++++++++++++++++++++++++ libs/freetdm/src/isdn/include/Q931.h | 8 ++ 2 files changed, 161 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index afc57539d0..2f3bf63028 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -64,6 +64,156 @@ L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_ L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3UINT Q931MsgieOffset[Q931MAXIE]; + +void Q931Initialize_MsgieOffset() +{ + L3INT x; + Q931mes_Generic msg; + ie *index; + + for(x=0; x Date: Thu, 24 May 2007 21:57:03 +0000 Subject: [PATCH 0295/1766] state machine and echo test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@148 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 20 ++- libs/openzap/src/include/zap_analog.h | 3 +- libs/openzap/src/include/zap_types.h | 25 +++- libs/openzap/src/testanalog.c | 55 +++++++- libs/openzap/src/zap_analog.c | 192 +++++++++++++++++++++----- libs/openzap/src/zap_io.c | 8 +- 6 files changed, 256 insertions(+), 47 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index cb7e4178be..dca0bc3d06 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -131,6 +131,12 @@ #define XX if (0) +#ifdef WIN32 +#define zap_sleep(x) Sleep(x) +#else +#define zap_sleep(x) usleep(x * 1000) +#endif + #ifdef NDEBUG #undef assert #define assert(_Expression) ((void)(_Expression)) @@ -177,7 +183,10 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); -#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); obj->state = s; zap_mutex_unlock(obj->mutex); +#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex);\ + zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s));\ + zap_set_flag(obj, ZAP_CHANNEL_STATE_CHANGE);\ + obj->last_state = obj->state; obj->state = s; zap_mutex_unlock(obj->mutex); #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -218,6 +227,7 @@ struct zap_channel { uint32_t native_interval; uint32_t packet_len; zap_channel_state_t state; + zap_channel_state_t last_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; @@ -239,10 +249,15 @@ struct zap_channel { struct zap_sigmsg { zap_signal_event_t event_id; uint32_t chan_id; + uint32_t span_id; + zap_channel_t *channel; + zap_span_t *span; char cid_name[80]; char ani[25]; char aniII[25]; char dnis[25]; + void *raw_data; + uint32_t raw_data_len; }; @@ -258,6 +273,9 @@ struct zap_isdn_data { struct zap_analog_data { uint32_t flags; + uint32_t max_dialstr; + uint32_t digit_timeout; + zio_signal_cb_t sig_cb; }; struct zap_span { diff --git a/libs/openzap/src/include/zap_analog.h b/libs/openzap/src/include/zap_analog.h index ff0919877d..82badfcea9 100644 --- a/libs/openzap/src/include/zap_analog.h +++ b/libs/openzap/src/include/zap_analog.h @@ -43,5 +43,6 @@ typedef enum { typedef struct zap_analog_data zap_analog_data_t; zap_status_t zap_analog_start(zap_span_t *span); -zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb); +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); + #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 9fafa28d65..41a45af4a7 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -94,15 +94,18 @@ typedef enum { } zap_signal_type_t; typedef enum { - ZAP_SIGEVENT_CALL_START, - ZAP_SIGEVENT_CALL_STOP, - ZAP_SIGEVENT_CALL_TRANSFER, + ZAP_SIGEVENT_START, + ZAP_SIGEVENT_STOP, + ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, - ZAP_SIGEVENT_MISC + ZAP_SIGEVENT_MISC, + ZAP_SIGEVENT_INVALID } zap_signal_event_t; +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { ZAP_EVENT_NONE, @@ -185,8 +188,15 @@ typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_DIALTONE, - ZAP_CHANNEL_STATE_COLLECT + ZAP_CHANNEL_STATE_COLLECT, + ZAP_CHANNEL_STATE_RING, + ZAP_CHANNEL_STATE_BUSY, + ZAP_CHANNEL_STATE_ATTN, + ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { ZAP_CHANNEL_CONFIGURED = (1 << 0), @@ -199,7 +209,8 @@ typedef enum { ZAP_CHANNEL_EVENT = (1 << 7), ZAP_CHANNEL_INTHREAD = (1 << 8), ZAP_CHANNEL_WINK = (1 << 9), - ZAP_CHANNEL_FLASH = (1 << 10) + ZAP_CHANNEL_FLASH = (1 << 10), + ZAP_CHANNEL_STATE_CHANGE = (1 << 11) } zap_channel_flag_t; @@ -210,7 +221,7 @@ typedef struct zap_span zap_span_t; #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_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len) +#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_ARGS (struct zap_io_interface *zio) diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 0bec2444b1..c61cf5138a 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -1,9 +1,60 @@ #include "openzap.h" #include "zap_analog.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; + + + sleep(5); + + printf("answer call\n"); + + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + + 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) { + //printf("WRITE %d\n", len); + zap_channel_write(chan, frame, &len); + } else { + break; + } + } + } + + if (chan->state == ZAP_CHANNEL_STATE_UP) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + + printf("call over\n"); + +} + static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - return ZAP_FAIL; + printf("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); + printf("launching thread and indicating ring\n"); + zap_thread_create_detached(test_call, sigmsg->channel); + break; + default: + break; + } + + return ZAP_SUCCESS; } int main(int argc, char *argv[]) @@ -24,7 +75,7 @@ int main(int argc, char *argv[]) } - zap_analog_configure_span(span, "us", on_signal); + zap_analog_configure_span(span, "us", 2000, 11, on_signal); zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 0029430615..5a68aabd96 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -34,20 +34,34 @@ #include "openzap.h" #include "zap_analog.h" -zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb) +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) { + 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; } + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > 20) { + max_dialstr = 11; + } + span->analog_data = malloc(sizeof(*span->analog_data)); - assert(span->analog_data != NULL); memset(span->analog_data, 0, sizeof(*span->analog_data)); + assert(span->analog_data != NULL); + + span->analog_data->digit_timeout = digit_timeout; + span->analog_data->max_dialstr = max_dialstr; + span->analog_data->sig_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; zap_span_load_tones(span, tonemap); - + return ZAP_SUCCESS; } @@ -73,17 +87,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_codec_t codec = ZAP_CODEC_SLIN, old_codec; - char *tones[4] = {0}; - time_t start; - int isbz = 0; - int wtime = 10; zap_tone_type_t tt = ZAP_TONE_DTMF; - int play_tones = 1; - - - tones[0] = chan->span->tone_map[ZAP_TONEMAP_DIAL]; - tones[1] = chan->span->tone_map[ZAP_TONEMAP_BUSY]; - tones[2] = chan->span->tone_map[ZAP_TONEMAP_ATTN]; + char dtmf[128]; + int dtmf_offset = 0; + zap_analog_data_t *data = chan->span->analog_data; + zap_channel_t *closed_chan; + uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; + zap_sigmsg_t sig; zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); @@ -100,7 +110,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); + + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); #if 0 @@ -108,40 +119,144 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.debug_stream = stdout; #endif ts.rate = 8000; - teletone_run(&ts, tones[isbz++]); zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_buffer_set_loops(dt_buffer, -1); - time(&start); - - while (chan->state >= ZAP_CHANNEL_STATE_DIALTONE && zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { + while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; - char dtmf[128]; zap_size_t dlen = 0; len = sizeof(frame); + + elapsed += interval; + state_counter += interval; + XX printf("WTF %s %s\n", zap_channel_state2str(chan->state), zap_channel_state2str(chan->last_state)); + if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { + switch(chan->state) { + case ZAP_CHANNEL_STATE_DIALTONE: + { + if (state_counter > 10000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + } + break; + case ZAP_CHANNEL_STATE_BUSY: + { + if (state_counter > 20000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_ATTN); + } + } + break; + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + { + zap_sleep(interval * 1000); + } + break; + default: + break; - if (play_tones && tones[isbz] && time(NULL) - start > wtime) { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, tones[isbz++]); - time(&start); - wtime *= 2; + } + } else { + zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + switch(chan->state) { + case ZAP_CHANNEL_STATE_UP: + { + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); + sig.event_id = ZAP_SIGEVENT_ANSWER; + data->sig_cb(&sig); + continue; + } + break; + case ZAP_CHANNEL_STATE_IDLE: + { + memset(&sig, 0, sizeof(sig)); + sig.event_id = ZAP_SIGEVENT_START; + sig.chan_id = chan->chan_id; + sig.span_id = chan->span_id; + sig.channel = chan; + sig.span = chan->span; + zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); + data->sig_cb(&sig); + } + break; + case ZAP_CHANNEL_STATE_DOWN: + { + sig.event_id = ZAP_SIGEVENT_STOP; + data->sig_cb(&sig); + goto done; + } + break; + case ZAP_CHANNEL_STATE_DIALTONE: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_DIAL]); + indicate = 1; + } + break; + + case ZAP_CHANNEL_STATE_RING: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); + indicate = 1; + } + break; + + case ZAP_CHANNEL_STATE_BUSY: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); + indicate = 1; + } + break; + + case ZAP_CHANNEL_STATE_ATTN: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); + indicate = 1; + } + break; + default: + indicate = 0; + break; + } + + state_counter = 0; + } + + + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { + zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf, sizeof(dtmf)))) { - printf("DTMF %s\n", dtmf); - play_tones = 0; + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; } - + if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { goto done; } - + if (flags & ZAP_READ) { if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (play_tones) { + if (indicate) { + if (chan->effective_codec != codec) { + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + } zap_channel_write(chan, frame, &rlen); } } else { @@ -151,7 +266,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } done: - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); + + + closed_chan = chan; + zap_channel_close(&chan); + + zap_channel_command(closed_chan, ZAP_COMMAND_SET_CODEC, &old_codec); + if (ts.buffer) { teletone_destroy_session(&ts); } @@ -159,9 +280,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_destroy(&dt_buffer); } - zap_clear_flag(chan, ZAP_CHANNEL_INTHREAD); - zap_channel_close(&chan); - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended. %d\n", old_codec); + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); return NULL; } @@ -178,6 +299,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) case ZAP_OOB_OFFHOOK: { if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); zap_thread_create_detached(zap_analog_channel_run, event->channel); } } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 71014be2bc..5f2ec84db2 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -86,6 +86,11 @@ ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAME ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) +ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) +ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) + +ZAP_ENUM_NAMES(CHANNEL_STATE_NAMES, CHANNEL_STATE_STRINGS) +ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t, CHANNEL_STATE_NAMES, ZAP_CHANNEL_STATE_INVALID) static char *cut_path(char *in) { @@ -259,7 +264,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) if (index > ZAP_TONEMAP_INVALID) { zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); } else { - zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s] %d\n", var, val, index); + zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s]\n", var, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); x++; } @@ -637,6 +642,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { zchan->effective_codec = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_codec == zchan->native_codec) { zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); } else { From 062e5dd82adf1b6b44ace0bd13c6f87419055545 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 21:57:03 +0000 Subject: [PATCH 0296/1766] state machine and echo test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@148 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 20 ++- libs/freetdm/src/include/zap_analog.h | 3 +- libs/freetdm/src/include/zap_types.h | 25 +++- libs/freetdm/src/testanalog.c | 55 +++++++- libs/freetdm/src/zap_analog.c | 192 +++++++++++++++++++++----- libs/freetdm/src/zap_io.c | 8 +- 6 files changed, 256 insertions(+), 47 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index cb7e4178be..dca0bc3d06 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -131,6 +131,12 @@ #define XX if (0) +#ifdef WIN32 +#define zap_sleep(x) Sleep(x) +#else +#define zap_sleep(x) usleep(x * 1000) +#endif + #ifdef NDEBUG #undef assert #define assert(_Expression) ((void)(_Expression)) @@ -177,7 +183,10 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); -#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); obj->state = s; zap_mutex_unlock(obj->mutex); +#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex);\ + zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s));\ + zap_set_flag(obj, ZAP_CHANNEL_STATE_CHANGE);\ + obj->last_state = obj->state; obj->state = s; zap_mutex_unlock(obj->mutex); #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -218,6 +227,7 @@ struct zap_channel { uint32_t native_interval; uint32_t packet_len; zap_channel_state_t state; + zap_channel_state_t last_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; @@ -239,10 +249,15 @@ struct zap_channel { struct zap_sigmsg { zap_signal_event_t event_id; uint32_t chan_id; + uint32_t span_id; + zap_channel_t *channel; + zap_span_t *span; char cid_name[80]; char ani[25]; char aniII[25]; char dnis[25]; + void *raw_data; + uint32_t raw_data_len; }; @@ -258,6 +273,9 @@ struct zap_isdn_data { struct zap_analog_data { uint32_t flags; + uint32_t max_dialstr; + uint32_t digit_timeout; + zio_signal_cb_t sig_cb; }; struct zap_span { diff --git a/libs/freetdm/src/include/zap_analog.h b/libs/freetdm/src/include/zap_analog.h index ff0919877d..82badfcea9 100644 --- a/libs/freetdm/src/include/zap_analog.h +++ b/libs/freetdm/src/include/zap_analog.h @@ -43,5 +43,6 @@ typedef enum { typedef struct zap_analog_data zap_analog_data_t; zap_status_t zap_analog_start(zap_span_t *span); -zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb); +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); + #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 9fafa28d65..41a45af4a7 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -94,15 +94,18 @@ typedef enum { } zap_signal_type_t; typedef enum { - ZAP_SIGEVENT_CALL_START, - ZAP_SIGEVENT_CALL_STOP, - ZAP_SIGEVENT_CALL_TRANSFER, + ZAP_SIGEVENT_START, + ZAP_SIGEVENT_STOP, + ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, - ZAP_SIGEVENT_MISC + ZAP_SIGEVENT_MISC, + ZAP_SIGEVENT_INVALID } zap_signal_event_t; +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { ZAP_EVENT_NONE, @@ -185,8 +188,15 @@ typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_DIALTONE, - ZAP_CHANNEL_STATE_COLLECT + ZAP_CHANNEL_STATE_COLLECT, + ZAP_CHANNEL_STATE_RING, + ZAP_CHANNEL_STATE_BUSY, + ZAP_CHANNEL_STATE_ATTN, + ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { ZAP_CHANNEL_CONFIGURED = (1 << 0), @@ -199,7 +209,8 @@ typedef enum { ZAP_CHANNEL_EVENT = (1 << 7), ZAP_CHANNEL_INTHREAD = (1 << 8), ZAP_CHANNEL_WINK = (1 << 9), - ZAP_CHANNEL_FLASH = (1 << 10) + ZAP_CHANNEL_FLASH = (1 << 10), + ZAP_CHANNEL_STATE_CHANGE = (1 << 11) } zap_channel_flag_t; @@ -210,7 +221,7 @@ typedef struct zap_span zap_span_t; #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_span_t *span, zap_sigmsg_t *sigmsg, void *raw_data, uint32_t raw_data_len) +#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_ARGS (struct zap_io_interface *zio) diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 0bec2444b1..c61cf5138a 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -1,9 +1,60 @@ #include "openzap.h" #include "zap_analog.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; + + + sleep(5); + + printf("answer call\n"); + + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + + 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) { + //printf("WRITE %d\n", len); + zap_channel_write(chan, frame, &len); + } else { + break; + } + } + } + + if (chan->state == ZAP_CHANNEL_STATE_UP) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + + printf("call over\n"); + +} + static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - return ZAP_FAIL; + printf("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); + printf("launching thread and indicating ring\n"); + zap_thread_create_detached(test_call, sigmsg->channel); + break; + default: + break; + } + + return ZAP_SUCCESS; } int main(int argc, char *argv[]) @@ -24,7 +75,7 @@ int main(int argc, char *argv[]) } - zap_analog_configure_span(span, "us", on_signal); + zap_analog_configure_span(span, "us", 2000, 11, on_signal); zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 0029430615..5a68aabd96 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -34,20 +34,34 @@ #include "openzap.h" #include "zap_analog.h" -zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, zio_signal_cb_t sig_cb) +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) { + 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; } + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > 20) { + max_dialstr = 11; + } + span->analog_data = malloc(sizeof(*span->analog_data)); - assert(span->analog_data != NULL); memset(span->analog_data, 0, sizeof(*span->analog_data)); + assert(span->analog_data != NULL); + + span->analog_data->digit_timeout = digit_timeout; + span->analog_data->max_dialstr = max_dialstr; + span->analog_data->sig_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; zap_span_load_tones(span, tonemap); - + return ZAP_SUCCESS; } @@ -73,17 +87,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_codec_t codec = ZAP_CODEC_SLIN, old_codec; - char *tones[4] = {0}; - time_t start; - int isbz = 0; - int wtime = 10; zap_tone_type_t tt = ZAP_TONE_DTMF; - int play_tones = 1; - - - tones[0] = chan->span->tone_map[ZAP_TONEMAP_DIAL]; - tones[1] = chan->span->tone_map[ZAP_TONEMAP_BUSY]; - tones[2] = chan->span->tone_map[ZAP_TONEMAP_ATTN]; + char dtmf[128]; + int dtmf_offset = 0; + zap_analog_data_t *data = chan->span->analog_data; + zap_channel_t *closed_chan; + uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; + zap_sigmsg_t sig; zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); @@ -100,7 +110,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); + + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); #if 0 @@ -108,40 +119,144 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.debug_stream = stdout; #endif ts.rate = 8000; - teletone_run(&ts, tones[isbz++]); zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_buffer_set_loops(dt_buffer, -1); - time(&start); - - while (chan->state >= ZAP_CHANNEL_STATE_DIALTONE && zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { + while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; - char dtmf[128]; zap_size_t dlen = 0; len = sizeof(frame); + + elapsed += interval; + state_counter += interval; + XX printf("WTF %s %s\n", zap_channel_state2str(chan->state), zap_channel_state2str(chan->last_state)); + if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { + switch(chan->state) { + case ZAP_CHANNEL_STATE_DIALTONE: + { + if (state_counter > 10000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + } + break; + case ZAP_CHANNEL_STATE_BUSY: + { + if (state_counter > 20000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_ATTN); + } + } + break; + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + { + zap_sleep(interval * 1000); + } + break; + default: + break; - if (play_tones && tones[isbz] && time(NULL) - start > wtime) { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, tones[isbz++]); - time(&start); - wtime *= 2; + } + } else { + zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + switch(chan->state) { + case ZAP_CHANNEL_STATE_UP: + { + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); + sig.event_id = ZAP_SIGEVENT_ANSWER; + data->sig_cb(&sig); + continue; + } + break; + case ZAP_CHANNEL_STATE_IDLE: + { + memset(&sig, 0, sizeof(sig)); + sig.event_id = ZAP_SIGEVENT_START; + sig.chan_id = chan->chan_id; + sig.span_id = chan->span_id; + sig.channel = chan; + sig.span = chan->span; + zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); + data->sig_cb(&sig); + } + break; + case ZAP_CHANNEL_STATE_DOWN: + { + sig.event_id = ZAP_SIGEVENT_STOP; + data->sig_cb(&sig); + goto done; + } + break; + case ZAP_CHANNEL_STATE_DIALTONE: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_DIAL]); + indicate = 1; + } + break; + + case ZAP_CHANNEL_STATE_RING: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); + indicate = 1; + } + break; + + case ZAP_CHANNEL_STATE_BUSY: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); + indicate = 1; + } + break; + + case ZAP_CHANNEL_STATE_ATTN: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); + indicate = 1; + } + break; + default: + indicate = 0; + break; + } + + state_counter = 0; + } + + + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { + zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf, sizeof(dtmf)))) { - printf("DTMF %s\n", dtmf); - play_tones = 0; + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; } - + if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { goto done; } - + if (flags & ZAP_READ) { if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (play_tones) { + if (indicate) { + if (chan->effective_codec != codec) { + zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + } zap_channel_write(chan, frame, &rlen); } } else { @@ -151,7 +266,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } done: - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); + + + closed_chan = chan; + zap_channel_close(&chan); + + zap_channel_command(closed_chan, ZAP_COMMAND_SET_CODEC, &old_codec); + if (ts.buffer) { teletone_destroy_session(&ts); } @@ -159,9 +280,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_destroy(&dt_buffer); } - zap_clear_flag(chan, ZAP_CHANNEL_INTHREAD); - zap_channel_close(&chan); - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended. %d\n", old_codec); + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); return NULL; } @@ -178,6 +299,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) case ZAP_OOB_OFFHOOK: { if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); zap_thread_create_detached(zap_analog_channel_run, event->channel); } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 71014be2bc..5f2ec84db2 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -86,6 +86,11 @@ ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAME ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) +ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) +ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) + +ZAP_ENUM_NAMES(CHANNEL_STATE_NAMES, CHANNEL_STATE_STRINGS) +ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t, CHANNEL_STATE_NAMES, ZAP_CHANNEL_STATE_INVALID) static char *cut_path(char *in) { @@ -259,7 +264,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) if (index > ZAP_TONEMAP_INVALID) { zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); } else { - zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s] %d\n", var, val, index); + zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s]\n", var, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); x++; } @@ -637,6 +642,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { zchan->effective_codec = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_codec == zchan->native_codec) { zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); } else { From dc6deb4af8653b27a2946b54e530602c67348c98 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 22:09:44 +0000 Subject: [PATCH 0297/1766] add dox git-svn-id: http://svn.openzap.org/svn/openzap/trunk@149 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/Makefile | 2 + libs/openzap/src/docs/Doxygen.conf | 265 +++++++++++++++++++++++++++++ 2 files changed, 267 insertions(+) create mode 100644 libs/openzap/src/docs/Doxygen.conf diff --git a/libs/openzap/src/Makefile b/libs/openzap/src/Makefile index f913e93e65..e7bed960d4 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/src/Makefile @@ -104,6 +104,8 @@ zap_zt.o: zap_zt.c %.o: %.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ +dox: + cd docs && doxygen $(PWD)/docs/Doxygen.conf clean: rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog diff --git a/libs/openzap/src/docs/Doxygen.conf b/libs/openzap/src/docs/Doxygen.conf new file mode 100644 index 0000000000..03800ac6ff --- /dev/null +++ b/libs/openzap/src/docs/Doxygen.conf @@ -0,0 +1,265 @@ +# Doxyfile 1.4.6 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = OpenZAP +PROJECT_NUMBER = +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +IGNORE_PREFIX = zap_ ZAP_ Q921 Q931 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = .. ../include ../isdn ../isdn/include +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.d \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.dox \ + *.py +RECURSIVE = NO +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = YES +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +USE_HTAGS = YES +VERBATIM_HEADERS = NO +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 1 +IGNORE_PREFIX = zap_ +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = freeswitch.chm +HHC_LOCATION = +GENERATE_CHI = YES +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = NO +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = *.h +PREDEFINED = ZAP_DECLARE(x)=x \ + APR_DECLARE(x)=x \ + ZAP_MOD_DECLARE(x)=x \ + DoxyDefine(x)=x + +EXPAND_AS_DEFINED = NO +SKIP_FUNCTION_MACROS = NO +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = YES +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = YES +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = jpg +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO From c2fd8a81e85507c88c0cedfc5eeffbc72410e813 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 May 2007 22:09:44 +0000 Subject: [PATCH 0298/1766] add dox git-svn-id: http://svn.openzap.org/svn/openzap/trunk@149 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/Makefile | 2 + libs/freetdm/src/docs/Doxygen.conf | 265 +++++++++++++++++++++++++++++ 2 files changed, 267 insertions(+) create mode 100644 libs/freetdm/src/docs/Doxygen.conf diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/src/Makefile index f913e93e65..e7bed960d4 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/src/Makefile @@ -104,6 +104,8 @@ zap_zt.o: zap_zt.c %.o: %.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ +dox: + cd docs && doxygen $(PWD)/docs/Doxygen.conf clean: rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog diff --git a/libs/freetdm/src/docs/Doxygen.conf b/libs/freetdm/src/docs/Doxygen.conf new file mode 100644 index 0000000000..03800ac6ff --- /dev/null +++ b/libs/freetdm/src/docs/Doxygen.conf @@ -0,0 +1,265 @@ +# Doxyfile 1.4.6 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = OpenZAP +PROJECT_NUMBER = +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +IGNORE_PREFIX = zap_ ZAP_ Q921 Q931 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = .. ../include ../isdn ../isdn/include +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.d \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.dox \ + *.py +RECURSIVE = NO +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = YES +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +USE_HTAGS = YES +VERBATIM_HEADERS = NO +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 1 +IGNORE_PREFIX = zap_ +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = freeswitch.chm +HHC_LOCATION = +GENERATE_CHI = YES +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = NO +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = *.h +PREDEFINED = ZAP_DECLARE(x)=x \ + APR_DECLARE(x)=x \ + ZAP_MOD_DECLARE(x)=x \ + DoxyDefine(x)=x + +EXPAND_AS_DEFINED = NO +SKIP_FUNCTION_MACROS = NO +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = YES +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = YES +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = jpg +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO From dd2f271ce57c9babeaea6a2d1b93bc37202c38cd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 14:42:34 +0000 Subject: [PATCH 0299/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@150 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 4 +++- libs/openzap/src/testanalog.c | 19 +++++++++--------- libs/openzap/src/zap_analog.c | 13 +++--------- libs/openzap/src/zap_io.c | 30 +++++++++++++++++----------- libs/openzap/src/zap_wanpipe.c | 20 +++++++++++++++++-- 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 41a45af4a7..23bfaf9170 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -69,9 +69,11 @@ typedef enum { ZAP_TRUNK_T1, ZAP_TRUNK_J1, ZAP_TRUNK_BRI, + ZAP_TRUNK_FXO, + ZAP_TRUNK_FXS, ZAP_TRUNK_NONE } zap_trunk_type_t; -#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "NONE" +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE" ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) typedef enum { diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index c61cf5138a..9670564348 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -9,9 +9,9 @@ static void *test_call(zap_thread_t *me, void *obj) zap_size_t len; - sleep(5); + sleep(10); - printf("answer call\n"); + zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n"); zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); @@ -24,7 +24,7 @@ static void *test_call(zap_thread_t *me, void *obj) len = sizeof(frame); if (flags & ZAP_READ) { if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { - //printf("WRITE %d\n", len); + //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", len); zap_channel_write(chan, frame, &len); } else { break; @@ -36,18 +36,18 @@ static void *test_call(zap_thread_t *me, void *obj) zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } - printf("call over\n"); + zap_log(ZAP_LOG_DEBUG, "call over\n"); } static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - printf("got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + 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); - printf("launching thread and indicating ring\n"); + zap_log(ZAP_LOG_DEBUG, "launching thread and indicating ring\n"); zap_thread_create_detached(test_call, sigmsg->channel); break; default: @@ -64,17 +64,16 @@ int main(int argc, char *argv[]) zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); exit(-1); } - printf("OpenZAP loaded\n"); + zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); } - zap_analog_configure_span(span, "us", 2000, 11, on_signal); zap_analog_start(span); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 5a68aabd96..d4f80a1ff8 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -110,18 +110,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); - - - teletone_init_session(&ts, 0, teletone_handler, dt_buffer); -#if 0 - ts.debug = 1; - ts.debug_stream = stdout; -#endif ts.rate = 8000; zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); - zap_buffer_set_loops(dt_buffer, -1); while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { @@ -132,7 +124,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) elapsed += interval; state_counter += interval; - XX printf("WTF %s %s\n", zap_channel_state2str(chan->state), zap_channel_state2str(chan->last_state)); + if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { case ZAP_CHANNEL_STATE_DIALTONE: @@ -152,7 +144,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { - zap_sleep(interval * 1000); + zap_sleep(interval); + continue; } break; default: diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 5f2ec84db2..a1f6a0bcba 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -212,6 +212,7 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); + new_span->trunk_type = ZAP_TRUNK_NONE; *span = new_span; return ZAP_SUCCESS; } @@ -363,9 +364,9 @@ zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { - zap_mutex_lock(zchan->span->mutex); + zap_mutex_lock(zchan->mutex); zchan->event_callback = event_callback; - zap_mutex_unlock(zchan->span->mutex); + zap_mutex_unlock(zchan->mutex); return ZAP_SUCCESS; } @@ -504,15 +505,17 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; - - zap_mutex_lock(zchan->span->mutex); + + if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { + return status; + } if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); } } - zap_mutex_unlock(zchan->span->mutex); + zap_mutex_unlock(zchan->mutex); return status; } @@ -528,9 +531,12 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { zap_channel_t *check; - zap_mutex_lock(zio->spans[span_id].mutex); + check = &zio->spans[span_id].channels[chan_id]; - + if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + return status; + } + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->open(check); if (status == ZAP_SUCCESS) { @@ -538,7 +544,7 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ *zchan = check; } } - zap_mutex_unlock(zio->spans[span_id].mutex); + zap_mutex_unlock(check->mutex); } return status; @@ -554,7 +560,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(check != NULL); *zchan = NULL; - zap_mutex_lock(check->span->mutex); + zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); if (status == ZAP_SUCCESS) { @@ -563,7 +569,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) } } - zap_mutex_unlock(check->span->mutex); + zap_mutex_unlock(check->mutex); return status; } @@ -613,7 +619,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo return ZAP_FAIL; } - zap_mutex_lock(zchan->span->mutex); + zap_mutex_lock(zchan->mutex); switch(command) { case ZAP_COMMAND_SET_INTERVAL: @@ -774,7 +780,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo status = zchan->zio->command(zchan, command, obj); done: - zap_mutex_unlock(zchan->span->mutex); + zap_mutex_unlock(zchan->mutex); return status; } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 81aeef82df..175cdc50da 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -228,9 +228,25 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "fxo-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXO; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXO) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); + } } else if (!strcasecmp(var, "fxs-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXS; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXS) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); + } } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { From 500be2a492faa94ad601552d5ae881e2d7005a30 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 14:42:34 +0000 Subject: [PATCH 0300/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@150 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 4 +++- libs/freetdm/src/testanalog.c | 19 +++++++++--------- libs/freetdm/src/zap_analog.c | 13 +++--------- libs/freetdm/src/zap_io.c | 30 +++++++++++++++++----------- libs/freetdm/src/zap_wanpipe.c | 20 +++++++++++++++++-- 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 41a45af4a7..23bfaf9170 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -69,9 +69,11 @@ typedef enum { ZAP_TRUNK_T1, ZAP_TRUNK_J1, ZAP_TRUNK_BRI, + ZAP_TRUNK_FXO, + ZAP_TRUNK_FXS, ZAP_TRUNK_NONE } zap_trunk_type_t; -#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "NONE" +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE" ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) typedef enum { diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index c61cf5138a..9670564348 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -9,9 +9,9 @@ static void *test_call(zap_thread_t *me, void *obj) zap_size_t len; - sleep(5); + sleep(10); - printf("answer call\n"); + zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n"); zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); @@ -24,7 +24,7 @@ static void *test_call(zap_thread_t *me, void *obj) len = sizeof(frame); if (flags & ZAP_READ) { if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { - //printf("WRITE %d\n", len); + //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", len); zap_channel_write(chan, frame, &len); } else { break; @@ -36,18 +36,18 @@ static void *test_call(zap_thread_t *me, void *obj) zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } - printf("call over\n"); + zap_log(ZAP_LOG_DEBUG, "call over\n"); } static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - printf("got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + 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); - printf("launching thread and indicating ring\n"); + zap_log(ZAP_LOG_DEBUG, "launching thread and indicating ring\n"); zap_thread_create_detached(test_call, sigmsg->channel); break; default: @@ -64,17 +64,16 @@ int main(int argc, char *argv[]) zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); exit(-1); } - printf("OpenZAP loaded\n"); + zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); } - zap_analog_configure_span(span, "us", 2000, 11, on_signal); zap_analog_start(span); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 5a68aabd96..d4f80a1ff8 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -110,18 +110,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); - - - teletone_init_session(&ts, 0, teletone_handler, dt_buffer); -#if 0 - ts.debug = 1; - ts.debug_stream = stdout; -#endif ts.rate = 8000; zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); - zap_buffer_set_loops(dt_buffer, -1); while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { @@ -132,7 +124,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) elapsed += interval; state_counter += interval; - XX printf("WTF %s %s\n", zap_channel_state2str(chan->state), zap_channel_state2str(chan->last_state)); + if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { case ZAP_CHANNEL_STATE_DIALTONE: @@ -152,7 +144,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { - zap_sleep(interval * 1000); + zap_sleep(interval); + continue; } break; default: diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5f2ec84db2..a1f6a0bcba 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -212,6 +212,7 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); + new_span->trunk_type = ZAP_TRUNK_NONE; *span = new_span; return ZAP_SUCCESS; } @@ -363,9 +364,9 @@ zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { - zap_mutex_lock(zchan->span->mutex); + zap_mutex_lock(zchan->mutex); zchan->event_callback = event_callback; - zap_mutex_unlock(zchan->span->mutex); + zap_mutex_unlock(zchan->mutex); return ZAP_SUCCESS; } @@ -504,15 +505,17 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; - - zap_mutex_lock(zchan->span->mutex); + + if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { + return status; + } if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); } } - zap_mutex_unlock(zchan->span->mutex); + zap_mutex_unlock(zchan->mutex); return status; } @@ -528,9 +531,12 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { zap_channel_t *check; - zap_mutex_lock(zio->spans[span_id].mutex); + check = &zio->spans[span_id].channels[chan_id]; - + if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + return status; + } + if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->open(check); if (status == ZAP_SUCCESS) { @@ -538,7 +544,7 @@ zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_ *zchan = check; } } - zap_mutex_unlock(zio->spans[span_id].mutex); + zap_mutex_unlock(check->mutex); } return status; @@ -554,7 +560,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(check != NULL); *zchan = NULL; - zap_mutex_lock(check->span->mutex); + zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); if (status == ZAP_SUCCESS) { @@ -563,7 +569,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) } } - zap_mutex_unlock(check->span->mutex); + zap_mutex_unlock(check->mutex); return status; } @@ -613,7 +619,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo return ZAP_FAIL; } - zap_mutex_lock(zchan->span->mutex); + zap_mutex_lock(zchan->mutex); switch(command) { case ZAP_COMMAND_SET_INTERVAL: @@ -774,7 +780,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo status = zchan->zio->command(zchan, command, obj); done: - zap_mutex_unlock(zchan->span->mutex); + zap_mutex_unlock(zchan->mutex); return status; } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 81aeef82df..175cdc50da 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -228,9 +228,25 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "fxo-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXO; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXO) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); + } } else if (!strcasecmp(var, "fxs-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXS; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXS) { + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); + } } else if (!strcasecmp(var, "b-channel")) { configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); } else if (!strcasecmp(var, "d-channel")) { From 6c47bd9db1802eeeb3b14914e370522f7934eddb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 14:57:07 +0000 Subject: [PATCH 0301/1766] add git-svn-id: http://svn.openzap.org/svn/openzap/trunk@151 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/openzap.conf.ex | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libs/openzap/src/openzap.conf.ex diff --git a/libs/openzap/src/openzap.conf.ex b/libs/openzap/src/openzap.conf.ex new file mode 100644 index 0000000000..3a01165ef9 --- /dev/null +++ b/libs/openzap/src/openzap.conf.ex @@ -0,0 +1,38 @@ +[openzap] +load => wanpipe +;load => zt + +[+wanpipe.conf] +[span] +enabled => 1 +fxs-channel => 1:3-4 + + +[span] +enabled => 1 +fxo-channel => 1:1-2 + + +[+zt.conf] + +[span] +enabled => 0 +b-channel => 1-23 +d-channel=> 24 + +[span] +enabled => 0 +b-channel => 25-47 +d-channel=> 48 + +[span] +enabled => 0 +fxo-channel => 49 +fxs-channel => 50 + +[+tones.conf] +[us] +dial => %(1000,0,350,440) +ring => %(2000,4000,440,480) +busy => %(500,500,480,620) +attn => %(100,100,1400,2060,2450,2600) From 65837986074a8305979b780f957fd7db97cd8f7b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 14:57:07 +0000 Subject: [PATCH 0302/1766] add git-svn-id: http://svn.openzap.org/svn/openzap/trunk@151 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/openzap.conf.ex | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libs/freetdm/src/openzap.conf.ex diff --git a/libs/freetdm/src/openzap.conf.ex b/libs/freetdm/src/openzap.conf.ex new file mode 100644 index 0000000000..3a01165ef9 --- /dev/null +++ b/libs/freetdm/src/openzap.conf.ex @@ -0,0 +1,38 @@ +[openzap] +load => wanpipe +;load => zt + +[+wanpipe.conf] +[span] +enabled => 1 +fxs-channel => 1:3-4 + + +[span] +enabled => 1 +fxo-channel => 1:1-2 + + +[+zt.conf] + +[span] +enabled => 0 +b-channel => 1-23 +d-channel=> 24 + +[span] +enabled => 0 +b-channel => 25-47 +d-channel=> 48 + +[span] +enabled => 0 +fxo-channel => 49 +fxs-channel => 50 + +[+tones.conf] +[us] +dial => %(1000,0,350,440) +ring => %(2000,4000,440,480) +busy => %(500,500,480,620) +attn => %(100,100,1400,2060,2450,2600) From 9f03a0ffd6b3973bccaf39ea0375d1451fbeee67 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 19:37:16 +0000 Subject: [PATCH 0303/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@152 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 6 ++++++ libs/openzap/src/zap_io.c | 4 ++-- libs/openzap/src/zap_wanpipe.c | 34 ++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index dca0bc3d06..f1a2c93854 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -34,7 +34,9 @@ #ifndef OPENZAP_H #define OPENZAP_H +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 500 +#endif #ifndef HAVE_STRINGS_H #define HAVE_STRINGS_H 1 @@ -148,6 +150,7 @@ #define GOTO_STATUS(label,st) status = st; goto label ; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) +#define zap_strlen_zero(s) (!s || *s == '\0') #define zap_channel_test_feature(obj, flag) ((obj)->features & flag) @@ -241,6 +244,8 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; + char chan_name[80]; + char chan_number[25]; struct zap_span *span; struct zap_io_interface *zio; }; @@ -293,6 +298,7 @@ struct zap_span { char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + void *app_data; }; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a1f6a0bcba..61c73bb966 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1045,11 +1045,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zchan->effective_codec == ZAP_CODEC_ULAW) { - for(i = 0; i < max; i++) { + for(i = 0; i < slen; i++) { *sln++ = ulaw_to_linear(*lp++); } } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { - for(i = 0; i < max; i++) { + for(i = 0; i < slen; i++) { *sln++ = alaw_to_linear(*lp++); } } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 175cdc50da..65385c11e4 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -60,7 +60,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm return ZAP_SUCCESS; } -static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type) +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 configured = 0, x; @@ -91,6 +91,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + 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++; } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); @@ -100,7 +106,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, return configured; } -static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type) +static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type, char *name, char *number) { int items, i; char *mydata, *item_list[10]; @@ -158,7 +164,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa continue; } - configured += wp_open_range(span, spanno, channo, top, type); + configured += wp_open_range(span, spanno, channo, top, type, name, number); } @@ -175,6 +181,8 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) zap_span_t *span = NULL; int new_span = 0; unsigned configured = 0, d = 0; + char name[80] = ""; + char number[25] = ""; ZIO_CONFIGURE_MUZZLE; @@ -227,13 +235,25 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } else if (!strcasecmp(var, "trunk_type")) { span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "name")) { + if (!strcasecmp(val, "undef")) { + *name = '\0'; + } else { + zap_copy_string(name, val, sizeof(name)); + } + } else if (!strcasecmp(var, "number")) { + if (!strcasecmp(val, "undef")) { + *number = '\0'; + } else { + zap_copy_string(number, val, sizeof(number)); + } } else if (!strcasecmp(var, "fxo-channel")) { if (span->trunk_type == ZAP_TRUNK_NONE) { span->trunk_type = ZAP_TRUNK_FXO; zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO, name, number); } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); } @@ -243,12 +263,12 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS, name, number); } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } } else if (!strcasecmp(var, "b-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B, name, number); } else if (!strcasecmp(var, "d-channel")) { if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); @@ -260,7 +280,7 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } else { qtype = ZAP_CHAN_TYPE_DQ921; } - configured += wp_configure_channel(&cfg, val, span, qtype); + configured += wp_configure_channel(&cfg, val, span, qtype, name, number); d++; } } From e25f92120a8870b644cfb5113ce31cc7454f7cd8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 19:37:16 +0000 Subject: [PATCH 0304/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@152 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 6 ++++++ libs/freetdm/src/zap_io.c | 4 ++-- libs/freetdm/src/zap_wanpipe.c | 34 ++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index dca0bc3d06..f1a2c93854 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -34,7 +34,9 @@ #ifndef OPENZAP_H #define OPENZAP_H +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 500 +#endif #ifndef HAVE_STRINGS_H #define HAVE_STRINGS_H 1 @@ -148,6 +150,7 @@ #define GOTO_STATUS(label,st) status = st; goto label ; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) +#define zap_strlen_zero(s) (!s || *s == '\0') #define zap_channel_test_feature(obj, flag) ((obj)->features & flag) @@ -241,6 +244,8 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; + char chan_name[80]; + char chan_number[25]; struct zap_span *span; struct zap_io_interface *zio; }; @@ -293,6 +298,7 @@ struct zap_span { char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + void *app_data; }; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a1f6a0bcba..61c73bb966 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1045,11 +1045,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zchan->effective_codec == ZAP_CODEC_ULAW) { - for(i = 0; i < max; i++) { + for(i = 0; i < slen; i++) { *sln++ = ulaw_to_linear(*lp++); } } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { - for(i = 0; i < max; i++) { + for(i = 0; i < slen; i++) { *sln++ = alaw_to_linear(*lp++); } } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 175cdc50da..65385c11e4 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -60,7 +60,7 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm return ZAP_SUCCESS; } -static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type) +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 configured = 0, x; @@ -91,6 +91,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + 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++; } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); @@ -100,7 +106,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, return configured; } -static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type) +static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type, char *name, char *number) { int items, i; char *mydata, *item_list[10]; @@ -158,7 +164,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa continue; } - configured += wp_open_range(span, spanno, channo, top, type); + configured += wp_open_range(span, spanno, channo, top, type, name, number); } @@ -175,6 +181,8 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) zap_span_t *span = NULL; int new_span = 0; unsigned configured = 0, d = 0; + char name[80] = ""; + char number[25] = ""; ZIO_CONFIGURE_MUZZLE; @@ -227,13 +235,25 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } else if (!strcasecmp(var, "trunk_type")) { span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "name")) { + if (!strcasecmp(val, "undef")) { + *name = '\0'; + } else { + zap_copy_string(name, val, sizeof(name)); + } + } else if (!strcasecmp(var, "number")) { + if (!strcasecmp(val, "undef")) { + *number = '\0'; + } else { + zap_copy_string(number, val, sizeof(number)); + } } else if (!strcasecmp(var, "fxo-channel")) { if (span->trunk_type == ZAP_TRUNK_NONE) { span->trunk_type = ZAP_TRUNK_FXO; zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO); + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO, name, number); } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); } @@ -243,12 +263,12 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS); + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS, name, number); } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } } else if (!strcasecmp(var, "b-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B); + configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B, name, number); } else if (!strcasecmp(var, "d-channel")) { if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); @@ -260,7 +280,7 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } else { qtype = ZAP_CHAN_TYPE_DQ921; } - configured += wp_configure_channel(&cfg, val, span, qtype); + configured += wp_configure_channel(&cfg, val, span, qtype, name, number); d++; } } From 864fd5fc6b8945ebc4e0e8fd0102c39bb1e0a898 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 23:39:01 +0000 Subject: [PATCH 0305/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@153 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 12 +++- libs/openzap/src/include/zap_types.h | 5 +- libs/openzap/src/zap_analog.c | 43 ++++++++---- libs/openzap/src/zap_io.c | 97 ++++++++++++++++++++++------ 4 files changed, 122 insertions(+), 35 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index f1a2c93854..b3e0f51a4a 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -188,8 +188,8 @@ #define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex);\ zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s));\ - zap_set_flag(obj, ZAP_CHANNEL_STATE_CHANGE);\ - obj->last_state = obj->state; obj->state = s; zap_mutex_unlock(obj->mutex); + zap_channel_set_state(obj, s); + #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -319,7 +319,7 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; - +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); @@ -346,6 +346,12 @@ void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e); +ZIO_CODEC_FUNCTION(zio_slin2ulaw); +ZIO_CODEC_FUNCTION(zio_ulaw2slin); +ZIO_CODEC_FUNCTION(zio_slin2alaw); +ZIO_CODEC_FUNCTION(zio_alaw2slin); +ZIO_CODEC_FUNCTION(zio_ulaw2alaw); +ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 23bfaf9170..3801012105 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -100,13 +100,14 @@ typedef enum { ZAP_SIGEVENT_STOP, ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, + ZAP_SIGEVENT_UP, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -155,6 +156,8 @@ typedef enum { 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_TONE_DETECT, ZAP_COMMAND_DISABLE_TONE_DETECT, ZAP_COMMAND_SEND_DTMF, diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index d4f80a1ff8..5852dd8a02 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -86,7 +86,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) teletone_generation_session_t ts; uint8_t frame[1024]; zap_size_t len, rlen; - zap_codec_t codec = ZAP_CODEC_SLIN, old_codec; zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128]; int dtmf_offset = 0; @@ -112,19 +111,19 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); teletone_init_session(&ts, 0, teletone_handler, dt_buffer); ts.rate = 8000; - zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); + zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); while (zap_test_flag(chan, 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(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { case ZAP_CHANNEL_STATE_DIALTONE: @@ -144,6 +143,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { + zap_sleep(interval); continue; } @@ -153,13 +153,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } else { + zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); - sig.event_id = ZAP_SIGEVENT_ANSWER; + sig.event_id = ZAP_SIGEVENT_UP; data->sig_cb(&sig); + continue; } break; @@ -173,6 +174,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.span = chan->span; zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); data->sig_cb(&sig); + continue; } break; case ZAP_CHANNEL_STATE_DOWN: @@ -221,7 +223,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) state_counter = 0; } - + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); @@ -245,11 +247,30 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (indicate) { - if (chan->effective_codec != codec) { - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + + if (indicate) { + zio_codec_t codec_func = NULL; + zap_status_t status; + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + status = ZAP_FAIL; + } } + zap_channel_write(chan, frame, &rlen); } } else { @@ -264,7 +285,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) closed_chan = chan; zap_channel_close(&chan); - zap_channel_command(closed_chan, ZAP_COMMAND_SET_CODEC, &old_codec); + zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); if (ts.buffer) { teletone_destroy_session(&ts); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 61c73bb966..a651b624a2 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -370,6 +370,39 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } + +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) +{ + int ok = 1; + + zap_mutex_unlock(zchan->mutex); + + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + + switch(state) { + case ZAP_CHANNEL_STATE_BUSY: + ok = 0; + break; + default: + break; + } + } + + if (state == zchan->state) { + ok = 0; + } + + if (ok) { + zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); + zchan->last_state = zchan->state; + zchan->state = state; + } + + zap_mutex_unlock(zchan->mutex); + + return ok ? ZAP_SUCCESS : ZAP_FAIL; +} + zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { zap_io_interface_t *zio; @@ -660,6 +693,17 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } break; + case ZAP_COMMAND_SET_NATIVE_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + zchan->effective_codec = zchan->native_codec; + zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + GOTO_STATUS(done, ZAP_SUCCESS); + } + } + break; + case ZAP_COMMAND_GET_CODEC: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { @@ -668,6 +712,14 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } break; + case ZAP_COMMAND_GET_NATIVE_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + ZAP_COMMAND_OBJ_INT = zchan->native_codec; + GOTO_STATUS(done, ZAP_SUCCESS); + } + } + break; case ZAP_COMMAND_ENABLE_TONE_DETECT: { /* if they don't have thier own, use ours */ @@ -937,15 +989,17 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) { - zap_size_t bytes; + zap_size_t bytes = 0; assert(zchan != NULL); - zap_mutex_lock(zchan->mutex); - if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { - *(dtmf + bytes) = '\0'; + if (zap_buffer_inuse(zchan->digit_buffer)) { + zap_mutex_lock(zchan->mutex); + if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { + *(dtmf + bytes) = '\0'; + } + zap_mutex_unlock(zchan->mutex); } - zap_mutex_unlock(zchan->mutex); return bytes; } @@ -1027,8 +1081,9 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { - int16_t sln_buf[1024], *sln = sln_buf; - zap_size_t slen; + uint8_t sln_buf[2048] = {0}; + int16_t *sln; + zap_size_t slen = 0; char digit_str[80] = ""; if (zchan->effective_codec == ZAP_CODEC_SLIN) { @@ -1038,23 +1093,25 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_size_t len = *datalen; uint32_t i; uint8_t *lp = data; - slen = max; + + slen = sizeof(sln_buf); + if (len > slen) { + len = slen; + } - if (slen > len) { - slen = len; - } - - if (zchan->effective_codec == ZAP_CODEC_ULAW) { - for(i = 0; i < slen; i++) { + sln = (int16_t *) sln_buf; + for(i = 0; i < len; i++) { + if (zchan->effective_codec == ZAP_CODEC_ULAW) { *sln++ = ulaw_to_linear(*lp++); - } - } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { - for(i = 0; i < slen; i++) { + } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { *sln++ = alaw_to_linear(*lp++); - } + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + return ZAP_FAIL; + } } - - sln = sln_buf; + sln = (int16_t *) sln_buf; + slen = len; } teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); From b4fa2bdd33ef292c429c9da9d58d2ad7cdb51305 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 May 2007 23:39:01 +0000 Subject: [PATCH 0306/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@153 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 12 +++- libs/freetdm/src/include/zap_types.h | 5 +- libs/freetdm/src/zap_analog.c | 43 ++++++++---- libs/freetdm/src/zap_io.c | 97 ++++++++++++++++++++++------ 4 files changed, 122 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index f1a2c93854..b3e0f51a4a 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -188,8 +188,8 @@ #define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex);\ zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s));\ - zap_set_flag(obj, ZAP_CHANNEL_STATE_CHANGE);\ - obj->last_state = obj->state; obj->state = s; zap_mutex_unlock(obj->mutex); + zap_channel_set_state(obj, s); + #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -319,7 +319,7 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; - +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); @@ -346,6 +346,12 @@ void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e); +ZIO_CODEC_FUNCTION(zio_slin2ulaw); +ZIO_CODEC_FUNCTION(zio_ulaw2slin); +ZIO_CODEC_FUNCTION(zio_slin2alaw); +ZIO_CODEC_FUNCTION(zio_alaw2slin); +ZIO_CODEC_FUNCTION(zio_ulaw2alaw); +ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 23bfaf9170..3801012105 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -100,13 +100,14 @@ typedef enum { ZAP_SIGEVENT_STOP, ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, + ZAP_SIGEVENT_UP, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -155,6 +156,8 @@ typedef enum { 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_TONE_DETECT, ZAP_COMMAND_DISABLE_TONE_DETECT, ZAP_COMMAND_SEND_DTMF, diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index d4f80a1ff8..5852dd8a02 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -86,7 +86,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) teletone_generation_session_t ts; uint8_t frame[1024]; zap_size_t len, rlen; - zap_codec_t codec = ZAP_CODEC_SLIN, old_codec; zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128]; int dtmf_offset = 0; @@ -112,19 +111,19 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_flag_locked(chan, ZAP_CHANNEL_INTHREAD); teletone_init_session(&ts, 0, teletone_handler, dt_buffer); ts.rate = 8000; - zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &old_codec); + zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); while (zap_test_flag(chan, 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(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { case ZAP_CHANNEL_STATE_DIALTONE: @@ -144,6 +143,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { + zap_sleep(interval); continue; } @@ -153,13 +153,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } else { + zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &old_codec); - sig.event_id = ZAP_SIGEVENT_ANSWER; + sig.event_id = ZAP_SIGEVENT_UP; data->sig_cb(&sig); + continue; } break; @@ -173,6 +174,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.span = chan->span; zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); data->sig_cb(&sig); + continue; } break; case ZAP_CHANNEL_STATE_DOWN: @@ -221,7 +223,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) state_counter = 0; } - + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); @@ -245,11 +247,30 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (indicate) { - if (chan->effective_codec != codec) { - zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec); + + if (indicate) { + zio_codec_t codec_func = NULL; + zap_status_t status; + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + status = ZAP_FAIL; + } } + zap_channel_write(chan, frame, &rlen); } } else { @@ -264,7 +285,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) closed_chan = chan; zap_channel_close(&chan); - zap_channel_command(closed_chan, ZAP_COMMAND_SET_CODEC, &old_codec); + zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); if (ts.buffer) { teletone_destroy_session(&ts); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 61c73bb966..a651b624a2 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -370,6 +370,39 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } + +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) +{ + int ok = 1; + + zap_mutex_unlock(zchan->mutex); + + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + + switch(state) { + case ZAP_CHANNEL_STATE_BUSY: + ok = 0; + break; + default: + break; + } + } + + if (state == zchan->state) { + ok = 0; + } + + if (ok) { + zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); + zchan->last_state = zchan->state; + zchan->state = state; + } + + zap_mutex_unlock(zchan->mutex); + + return ok ? ZAP_SUCCESS : ZAP_FAIL; +} + zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { zap_io_interface_t *zio; @@ -660,6 +693,17 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } break; + case ZAP_COMMAND_SET_NATIVE_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + zchan->effective_codec = zchan->native_codec; + zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + GOTO_STATUS(done, ZAP_SUCCESS); + } + } + break; + case ZAP_COMMAND_GET_CODEC: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { @@ -668,6 +712,14 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } break; + case ZAP_COMMAND_GET_NATIVE_CODEC: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { + ZAP_COMMAND_OBJ_INT = zchan->native_codec; + GOTO_STATUS(done, ZAP_SUCCESS); + } + } + break; case ZAP_COMMAND_ENABLE_TONE_DETECT: { /* if they don't have thier own, use ours */ @@ -937,15 +989,17 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) { - zap_size_t bytes; + zap_size_t bytes = 0; assert(zchan != NULL); - zap_mutex_lock(zchan->mutex); - if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { - *(dtmf + bytes) = '\0'; + if (zap_buffer_inuse(zchan->digit_buffer)) { + zap_mutex_lock(zchan->mutex); + if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { + *(dtmf + bytes) = '\0'; + } + zap_mutex_unlock(zchan->mutex); } - zap_mutex_unlock(zchan->mutex); return bytes; } @@ -1027,8 +1081,9 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { - int16_t sln_buf[1024], *sln = sln_buf; - zap_size_t slen; + uint8_t sln_buf[2048] = {0}; + int16_t *sln; + zap_size_t slen = 0; char digit_str[80] = ""; if (zchan->effective_codec == ZAP_CODEC_SLIN) { @@ -1038,23 +1093,25 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data zap_size_t len = *datalen; uint32_t i; uint8_t *lp = data; - slen = max; + + slen = sizeof(sln_buf); + if (len > slen) { + len = slen; + } - if (slen > len) { - slen = len; - } - - if (zchan->effective_codec == ZAP_CODEC_ULAW) { - for(i = 0; i < slen; i++) { + sln = (int16_t *) sln_buf; + for(i = 0; i < len; i++) { + if (zchan->effective_codec == ZAP_CODEC_ULAW) { *sln++ = ulaw_to_linear(*lp++); - } - } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { - for(i = 0; i < slen; i++) { + } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { *sln++ = alaw_to_linear(*lp++); - } + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + return ZAP_FAIL; + } } - - sln = sln_buf; + sln = (int16_t *) sln_buf; + slen = len; } teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); From 65983aa84e3d8156c57b4af84b20ec802f3b9f62 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 26 May 2007 01:02:43 +0000 Subject: [PATCH 0307/1766] better compliance with Q.931 on a few ie pack/unpack functions. Revert to using the corrected functions for national dialect. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@154 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 10 +- libs/openzap/src/isdn/include/national.h | 3 - libs/openzap/src/isdn/nationalStateNT.c | 2 +- libs/openzap/src/isdn/nationalStateTE.c | 2 +- libs/openzap/src/isdn/nationalie.c | 113 ----------------------- 5 files changed, 7 insertions(+), 123 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 1435e3abc7..0e112675d2 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -453,7 +453,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR pie->CallId[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); + }while(Q931MoreIE()); Q931IESizeTest(Q931E_CALLID); @@ -622,7 +622,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + }while(Q931MoreIE() && x < 20); Q931IESizeTest(Q931E_CALLEDSUB); @@ -713,7 +713,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH Octet ++; /* Octet 4*/ - for (x = 0; x < IESize && x < 20; x++) + for (x = 0; x < IESize; x++) { pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; @@ -819,7 +819,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); Q931IESizeTest(Q931E_CALLINGNUM); @@ -925,7 +925,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + }while(Q931MoreIE() && x < 20); Q931IESizeTest(Q931E_CALLINGSUB); diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h index 98ad07609b..1e9f5b1f8f 100644 --- a/libs/openzap/src/isdn/include/national.h +++ b/libs/openzap/src/isdn/include/national.h @@ -93,9 +93,6 @@ typedef struct *****************************************************************************/ L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT nationalPie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c index c18e185b5a..2465853fe1 100644 --- a/libs/openzap/src/isdn/nationalStateNT.c +++ b/libs/openzap/src/isdn/nationalStateNT.c @@ -107,7 +107,7 @@ void nationalCreateNT(L3UCHAR i) 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,nationalPie_CallingNum, nationalUie_CallingNum); + 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); diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index f8b8a9f90c..0f3186e288 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -114,7 +114,7 @@ void nationalCreateTE(L3UCHAR i) 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,nationalPie_CallingNum, nationalUie_CallingNum); + 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); diff --git a/libs/openzap/src/isdn/nationalie.c b/libs/openzap/src/isdn/nationalie.c index 184c11aa18..bf9afbad80 100644 --- a/libs/openzap/src/isdn/nationalie.c +++ b/libs/openzap/src/isdn/nationalie.c @@ -139,116 +139,3 @@ L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR return Q931E_NO_ERROR; } -/***************************************************************************** - - Function: nationalUie_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 nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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 4a*/ - x=0; - do{ - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while(Q931MoreIE()); - - Q931IESizeTest(Q931E_CALLINGNUM); - - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); - - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: nationalPie_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 nationalPie_CallingNum(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_CalledSub) + 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 3a */ - /* - - Details about the use and how to detect if Octet 3a is used - are very weak. Temp left out. - - Octet 3 msb is set to 1 to indicate that this is not present - - */ - - /* Octet 4 */ - for(x=0;xDigit[x]; - } - - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; -} From 479628543d9ef998093642b2747352445dbc86a8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 26 May 2007 01:02:43 +0000 Subject: [PATCH 0308/1766] better compliance with Q.931 on a few ie pack/unpack functions. Revert to using the corrected functions for national dialect. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@154 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 10 +- libs/freetdm/src/isdn/include/national.h | 3 - libs/freetdm/src/isdn/nationalStateNT.c | 2 +- libs/freetdm/src/isdn/nationalStateTE.c | 2 +- libs/freetdm/src/isdn/nationalie.c | 113 ----------------------- 5 files changed, 7 insertions(+), 123 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 1435e3abc7..0e112675d2 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -453,7 +453,7 @@ L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR pie->CallId[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 10); + }while(Q931MoreIE()); Q931IESizeTest(Q931E_CALLID); @@ -622,7 +622,7 @@ L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHA pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + }while(Q931MoreIE() && x < 20); Q931IESizeTest(Q931E_CALLEDSUB); @@ -713,7 +713,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCH Octet ++; /* Octet 4*/ - for (x = 0; x < IESize && x < 20; x++) + for (x = 0; x < IESize; x++) { pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; @@ -819,7 +819,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UC pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + }while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); Q931IESizeTest(Q931E_CALLINGNUM); @@ -925,7 +925,7 @@ L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCH pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) != 0 && x < 20); + }while(Q931MoreIE() && x < 20); Q931IESizeTest(Q931E_CALLINGSUB); diff --git a/libs/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h index 98ad07609b..1e9f5b1f8f 100644 --- a/libs/freetdm/src/isdn/include/national.h +++ b/libs/freetdm/src/isdn/include/national.h @@ -93,9 +93,6 @@ typedef struct *****************************************************************************/ L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT nationalPie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); diff --git a/libs/freetdm/src/isdn/nationalStateNT.c b/libs/freetdm/src/isdn/nationalStateNT.c index c18e185b5a..2465853fe1 100644 --- a/libs/freetdm/src/isdn/nationalStateNT.c +++ b/libs/freetdm/src/isdn/nationalStateNT.c @@ -107,7 +107,7 @@ void nationalCreateNT(L3UCHAR i) 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,nationalPie_CallingNum, nationalUie_CallingNum); + 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); diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index f8b8a9f90c..0f3186e288 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -114,7 +114,7 @@ void nationalCreateTE(L3UCHAR i) 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,nationalPie_CallingNum, nationalUie_CallingNum); + 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); diff --git a/libs/freetdm/src/isdn/nationalie.c b/libs/freetdm/src/isdn/nationalie.c index 184c11aa18..bf9afbad80 100644 --- a/libs/freetdm/src/isdn/nationalie.c +++ b/libs/freetdm/src/isdn/nationalie.c @@ -139,116 +139,3 @@ L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR return Q931E_NO_ERROR; } -/***************************************************************************** - - Function: nationalUie_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 nationalUie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - 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 4a*/ - x=0; - do{ - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while(Q931MoreIE()); - - Q931IESizeTest(Q931E_CALLINGNUM); - - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); - - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: nationalPie_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 nationalPie_CallingNum(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_CalledSub) + 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 3a */ - /* - - Details about the use and how to detect if Octet 3a is used - are very weak. Temp left out. - - Octet 3 msb is set to 1 to indicate that this is not present - - */ - - /* Octet 4 */ - for(x=0;xDigit[x]; - } - - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; -} From f7bbb688471431baf59e3be4087d427d2245521b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 03:27:31 +0000 Subject: [PATCH 0309/1766] analog update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@155 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 86 +++++++++++++++++------------------ libs/openzap/src/zap_buffer.c | 1 + libs/openzap/src/zap_io.c | 6 +-- 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 5852dd8a02..21702cafed 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -93,7 +93,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; zap_sigmsg_t sig; - + zap_status_t status; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { @@ -101,10 +102,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + snprintf(chan->last_error, sizeof(chan->last_error), "memory error!"); goto done; } if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); goto done; } @@ -143,18 +146,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { - zap_sleep(interval); continue; } break; default: break; - } } else { - zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + indicate = 0; + state_counter = 0; switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { @@ -191,7 +193,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; - case ZAP_CHANNEL_STATE_RING: { zap_buffer_zero(dt_buffer); @@ -199,7 +200,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; - case ZAP_CHANNEL_STATE_BUSY: { zap_buffer_zero(dt_buffer); @@ -207,7 +207,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; - case ZAP_CHANNEL_STATE_ATTN: { zap_buffer_zero(dt_buffer); @@ -216,13 +215,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } break; default: - indicate = 0; break; } - - state_counter = 0; } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { @@ -241,55 +236,59 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) last_digit = 0; } - if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { + if (zap_channel_wait(chan, &flags, interval * 2) == ZAP_FAIL) { goto done; } - if (flags & ZAP_READ) { - if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { - if (chan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } - rlen = zap_buffer_read_loop(dt_buffer, frame, len); - - if (indicate) { - zio_codec_t codec_func = NULL; - zap_status_t status; - - if (chan->effective_codec != ZAP_CODEC_SLIN) { - if (chan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } - - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); - status = ZAP_FAIL; - } - } + if (!(flags & ZAP_READ)) { + continue; + } - zap_channel_write(chan, frame, &rlen); - } + if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + goto done; + } + + if (!indicate) { + continue; + } + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } + + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); goto done; } } - } - - done: + zap_channel_write(chan, frame, &rlen); + } + + done: closed_chan = chan; zap_channel_close(&chan); - + 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); } @@ -297,6 +296,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); + return NULL; } diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 63ae360414..d4edbe6e29 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -242,6 +242,7 @@ void zap_buffer_zero(zap_buffer_t *buffer) assert(buffer->data != NULL); buffer->used = 0; + buffer->actually_used = 0; buffer->head = buffer->data; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a651b624a2..6041844a0e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1081,7 +1081,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { - uint8_t sln_buf[2048] = {0}; + uint8_t sln_buf[1024] = {0}; int16_t *sln; zap_size_t slen = 0; char digit_str[80] = ""; @@ -1094,11 +1094,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data uint32_t i; uint8_t *lp = data; - slen = sizeof(sln_buf); + slen = sizeof(sln_buf) / 2; if (len > slen) { len = slen; } - + sln = (int16_t *) sln_buf; for(i = 0; i < len; i++) { if (zchan->effective_codec == ZAP_CODEC_ULAW) { From 08e7a925eccdebb99025510834b5318051b1b381 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 03:27:31 +0000 Subject: [PATCH 0310/1766] analog update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@155 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 86 +++++++++++++++++------------------ libs/freetdm/src/zap_buffer.c | 1 + libs/freetdm/src/zap_io.c | 6 +-- 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 5852dd8a02..21702cafed 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -93,7 +93,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; zap_sigmsg_t sig; - + zap_status_t status; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { @@ -101,10 +102,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + snprintf(chan->last_error, sizeof(chan->last_error), "memory error!"); goto done; } if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); goto done; } @@ -143,18 +146,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { - zap_sleep(interval); continue; } break; default: break; - } } else { - zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + indicate = 0; + state_counter = 0; switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { @@ -191,7 +193,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; - case ZAP_CHANNEL_STATE_RING: { zap_buffer_zero(dt_buffer); @@ -199,7 +200,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; - case ZAP_CHANNEL_STATE_BUSY: { zap_buffer_zero(dt_buffer); @@ -207,7 +207,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; - case ZAP_CHANNEL_STATE_ATTN: { zap_buffer_zero(dt_buffer); @@ -216,13 +215,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } break; default: - indicate = 0; break; } - - state_counter = 0; } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { @@ -241,55 +236,59 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) last_digit = 0; } - if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { + if (zap_channel_wait(chan, &flags, interval * 2) == ZAP_FAIL) { goto done; } - if (flags & ZAP_READ) { - if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { - if (chan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } - rlen = zap_buffer_read_loop(dt_buffer, frame, len); - - if (indicate) { - zio_codec_t codec_func = NULL; - zap_status_t status; - - if (chan->effective_codec != ZAP_CODEC_SLIN) { - if (chan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } - - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); - status = ZAP_FAIL; - } - } + if (!(flags & ZAP_READ)) { + continue; + } - zap_channel_write(chan, frame, &rlen); - } + if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + goto done; + } + + if (!indicate) { + continue; + } + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } + + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); goto done; } } - } - - done: + zap_channel_write(chan, frame, &rlen); + } + + done: closed_chan = chan; zap_channel_close(&chan); - + 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); } @@ -297,6 +296,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); + return NULL; } diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 63ae360414..d4edbe6e29 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -242,6 +242,7 @@ void zap_buffer_zero(zap_buffer_t *buffer) assert(buffer->data != NULL); buffer->used = 0; + buffer->actually_used = 0; buffer->head = buffer->data; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a651b624a2..6041844a0e 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1081,7 +1081,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { - uint8_t sln_buf[2048] = {0}; + uint8_t sln_buf[1024] = {0}; int16_t *sln; zap_size_t slen = 0; char digit_str[80] = ""; @@ -1094,11 +1094,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data uint32_t i; uint8_t *lp = data; - slen = sizeof(sln_buf); + slen = sizeof(sln_buf) / 2; if (len > slen) { len = slen; } - + sln = (int16_t *) sln_buf; for(i = 0; i < len; i++) { if (zchan->effective_codec == ZAP_CODEC_ULAW) { From 1dfb53e3ef01fdfd476e5c8938c348f37f63f134 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:09:46 +0000 Subject: [PATCH 0311/1766] change config engine to be more modular git-svn-id: http://svn.openzap.org/svn/openzap/trunk@156 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_types.h | 7 +- libs/openzap/src/zap_config.c | 1 - libs/openzap/src/zap_io.c | 123 ++++++++++++++++++++++- libs/openzap/src/zap_wanpipe.c | 143 ++++----------------------- 5 files changed, 146 insertions(+), 129 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index b3e0f51a4a..db2c3ba5d4 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -306,6 +306,7 @@ extern zap_logger_t zap_log; struct zap_io_interface { const char *name; + zio_configure_span_t configure_span; zio_configure_t configure; zio_open_t open; zio_close_t close; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 3801012105..cf1b25cf76 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -229,7 +229,8 @@ typedef struct zap_span zap_span_t; #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_ARGS (struct zap_io_interface *zio) +#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_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) @@ -242,6 +243,7 @@ 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 ; @@ -255,6 +257,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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) 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 @@ -263,7 +266,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_CONFIGURE_MUZZLE assert(zio != NULL) +#define ZIO_CONFIGURE_SPAN_MUZZLE assert(zio != NULL) #define ZIO_OPEN_MUZZLE assert(zchan != NULL) #define ZIO_CLOSE_MUZZLE assert(zchan != NULL) #define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index eb65fb3809..e4d4116244 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -91,7 +91,6 @@ int zap_config_open_file(zap_config_t *cfg, char *file_path) } } - void zap_config_close_file(zap_config_t *cfg) { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6041844a0e..eff007f119 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1228,6 +1228,125 @@ static struct { zap_io_interface_t *zt_interface; } interfaces; + +static uint32_t load_config(zap_io_interface_t *zio) +{ + char cfg_name[256]; + zap_config_t cfg; + char *var, *val; + int catno = -1; + zap_span_t *span = NULL; + int new_span = 0; + unsigned configured = 0, d = 0; + char name[80] = ""; + char number[25] = ""; + + assert(zio != NULL); + snprintf(cfg_name, sizeof(cfg_name), "%s.conf", zio->name); + + zap_log(ZAP_LOG_DEBUG, "configuring %s\n", zio->name); + + if (!zap_config_open_file(&cfg, cfg_name)) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "span")) { + if (cfg.catno != catno) { + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); + catno = cfg.catno; + new_span = 1; + span = NULL; + } + + if (new_span) { + if (!strcasecmp(var, "enabled") && ! zap_true(val)) { + zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); + } else { + if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); + } else { + zap_log(ZAP_LOG_CRIT, "failure creating span\n"); + span = NULL; + } + } + new_span = 0; + continue; + } + + if (!span) { + continue; + } + + zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); + + if (!strcasecmp(var, "enabled")) { + zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); + } else if (!strcasecmp(var, "trunk_type")) { + span->trunk_type = zap_str2zap_trunk_type(val); + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "name")) { + if (!strcasecmp(val, "undef")) { + *name = '\0'; + } else { + zap_copy_string(name, val, sizeof(name)); + } + } else if (!strcasecmp(var, "number")) { + if (!strcasecmp(val, "undef")) { + *number = '\0'; + } else { + zap_copy_string(number, val, sizeof(number)); + } + } else if (!strcasecmp(var, "fxo-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXO; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXO) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); + } + } else if (!strcasecmp(var, "fxs-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXS; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXS) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); + } + } else if (!strcasecmp(var, "b-channel")) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); + } else if (!strcasecmp(var, "d-channel")) { + if (d) { + zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); + } else { + zap_chan_type_t qtype; + if (!strncasecmp(val, "lapd:", 5)) { + qtype = ZAP_CHAN_TYPE_DQ931; + val += 5; + } else { + qtype = ZAP_CHAN_TYPE_DQ921; + } + configured += zio->configure_span(span, val, qtype, name, number); + d++; + } + } + } else if (zio->configure) { + zio->configure(cfg.category, var, val, cfg.lineno); + } else { + zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); + } + } + zap_config_close_file(&cfg); + + zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); + + return configured; +} + zap_status_t zap_global_init(void) { zap_config_t cfg; @@ -1285,9 +1404,7 @@ zap_status_t zap_global_init(void) zap_mutex_unlock(globals.mutex); if (zio) { - if (zio->configure(zio) == ZAP_SUCCESS) { - configured++; - } + configured += load_config(zio); } else { zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val); } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 65385c11e4..fc14f0ad8f 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -106,7 +106,23 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, return configured; } -static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type, char *name, char *number) +static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) +{ + if (!strcasecmp(category, "defaults")) { + if (!strcasecmp(var, "codec_ms")) { + unsigned codec_ms = atoi(val); + if (codec_ms < 10 || codec_ms > 60) { + zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno); + } else { + wp_globals.codec_ms = codec_ms; + } + } + } + + return ZAP_SUCCESS; +} + +static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) { int items, i; char *mydata, *item_list[10]; @@ -132,7 +148,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa } if (!(sp && ch)) { - zap_log(ZAP_LOG_ERROR, "Invalid input on line %d\n", cfg->lineno); + zap_log(ZAP_LOG_ERROR, "Invalid input\n"); continue; } @@ -173,126 +189,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) -{ - zap_config_t cfg; - char *var, *val; - int catno = -1; - zap_span_t *span = NULL; - int new_span = 0; - unsigned configured = 0, d = 0; - char name[80] = ""; - char number[25] = ""; - - ZIO_CONFIGURE_MUZZLE; - - zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n"); - if (!zap_config_open_file(&cfg, "wanpipe.conf")) { - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "defaults")) { - if (!strcasecmp(var, "codec_ms")) { - unsigned codec_ms = atoi(val); - if (codec_ms < 10 || codec_ms > 60) { - zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", cfg.lineno); - } else { - wp_globals.codec_ms = codec_ms; - } - } - } else if (!strcasecmp(cfg.category, "span")) { - if (cfg.catno != catno) { - zap_log(ZAP_LOG_DEBUG, "found config for span\n"); - catno = cfg.catno; - new_span = 1; - span = NULL; - } - - if (new_span) { - if (!strcasecmp(var, "enabled") && ! zap_true(val)) { - zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); - } else { - if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span\n"); - span = NULL; - } - } - new_span = 0; - continue; - } - - if (!span) { - continue; - } - - zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); - - if (!strcasecmp(var, "enabled")) { - zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); - } else if (!strcasecmp(var, "trunk_type")) { - span->trunk_type = zap_str2zap_trunk_type(val); - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } else if (!strcasecmp(var, "name")) { - if (!strcasecmp(val, "undef")) { - *name = '\0'; - } else { - zap_copy_string(name, val, sizeof(name)); - } - } else if (!strcasecmp(var, "number")) { - if (!strcasecmp(val, "undef")) { - *number = '\0'; - } else { - zap_copy_string(number, val, sizeof(number)); - } - } else if (!strcasecmp(var, "fxo-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXO; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } - if (span->trunk_type == ZAP_TRUNK_FXO) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); - } - } else if (!strcasecmp(var, "fxs-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXS; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } - if (span->trunk_type == ZAP_TRUNK_FXS) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); - } - } else if (!strcasecmp(var, "b-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B, name, number); - } else if (!strcasecmp(var, "d-channel")) { - if (d) { - zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); - } else { - zap_chan_type_t qtype; - if (!strncasecmp(val, "lapd:", 5)) { - qtype = ZAP_CHAN_TYPE_DQ931; - val += 5; - } else { - qtype = ZAP_CHAN_TYPE_DQ921; - } - configured += wp_configure_channel(&cfg, val, span, qtype, name, number); - d++; - } - } - } - } - zap_config_close_file(&cfg); - - zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); - - return configured ? ZAP_SUCCESS : ZAP_FAIL; -} - static ZIO_OPEN_FUNCTION(wanpipe_open) { @@ -592,7 +488,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wp_globals.wink_ms = 150; wp_globals.flash_ms = 750; wanpipe_interface.name = "wanpipe"; - wanpipe_interface.configure = wanpipe_configure; + 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; From ae45a511519581e501e6e099414b1fbfb96171fb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:09:46 +0000 Subject: [PATCH 0312/1766] change config engine to be more modular git-svn-id: http://svn.openzap.org/svn/openzap/trunk@156 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 7 +- libs/freetdm/src/zap_config.c | 1 - libs/freetdm/src/zap_io.c | 123 ++++++++++++++++++++++- libs/freetdm/src/zap_wanpipe.c | 143 ++++----------------------- 5 files changed, 146 insertions(+), 129 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index b3e0f51a4a..db2c3ba5d4 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -306,6 +306,7 @@ extern zap_logger_t zap_log; struct zap_io_interface { const char *name; + zio_configure_span_t configure_span; zio_configure_t configure; zio_open_t open; zio_close_t close; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 3801012105..cf1b25cf76 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -229,7 +229,8 @@ typedef struct zap_span zap_span_t; #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_ARGS (struct zap_io_interface *zio) +#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_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) @@ -242,6 +243,7 @@ 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 ; @@ -255,6 +257,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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) 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 @@ -263,7 +266,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_CONFIGURE_MUZZLE assert(zio != NULL) +#define ZIO_CONFIGURE_SPAN_MUZZLE assert(zio != NULL) #define ZIO_OPEN_MUZZLE assert(zchan != NULL) #define ZIO_CLOSE_MUZZLE assert(zchan != NULL) #define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index eb65fb3809..e4d4116244 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -91,7 +91,6 @@ int zap_config_open_file(zap_config_t *cfg, char *file_path) } } - void zap_config_close_file(zap_config_t *cfg) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6041844a0e..eff007f119 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1228,6 +1228,125 @@ static struct { zap_io_interface_t *zt_interface; } interfaces; + +static uint32_t load_config(zap_io_interface_t *zio) +{ + char cfg_name[256]; + zap_config_t cfg; + char *var, *val; + int catno = -1; + zap_span_t *span = NULL; + int new_span = 0; + unsigned configured = 0, d = 0; + char name[80] = ""; + char number[25] = ""; + + assert(zio != NULL); + snprintf(cfg_name, sizeof(cfg_name), "%s.conf", zio->name); + + zap_log(ZAP_LOG_DEBUG, "configuring %s\n", zio->name); + + if (!zap_config_open_file(&cfg, cfg_name)) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "span")) { + if (cfg.catno != catno) { + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); + catno = cfg.catno; + new_span = 1; + span = NULL; + } + + if (new_span) { + if (!strcasecmp(var, "enabled") && ! zap_true(val)) { + zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); + } else { + if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); + } else { + zap_log(ZAP_LOG_CRIT, "failure creating span\n"); + span = NULL; + } + } + new_span = 0; + continue; + } + + if (!span) { + continue; + } + + zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); + + if (!strcasecmp(var, "enabled")) { + zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); + } else if (!strcasecmp(var, "trunk_type")) { + span->trunk_type = zap_str2zap_trunk_type(val); + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "name")) { + if (!strcasecmp(val, "undef")) { + *name = '\0'; + } else { + zap_copy_string(name, val, sizeof(name)); + } + } else if (!strcasecmp(var, "number")) { + if (!strcasecmp(val, "undef")) { + *number = '\0'; + } else { + zap_copy_string(number, val, sizeof(number)); + } + } else if (!strcasecmp(var, "fxo-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXO; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXO) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); + } + } else if (!strcasecmp(var, "fxs-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXS; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + } + if (span->trunk_type == ZAP_TRUNK_FXS) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); + } + } else if (!strcasecmp(var, "b-channel")) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); + } else if (!strcasecmp(var, "d-channel")) { + if (d) { + zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); + } else { + zap_chan_type_t qtype; + if (!strncasecmp(val, "lapd:", 5)) { + qtype = ZAP_CHAN_TYPE_DQ931; + val += 5; + } else { + qtype = ZAP_CHAN_TYPE_DQ921; + } + configured += zio->configure_span(span, val, qtype, name, number); + d++; + } + } + } else if (zio->configure) { + zio->configure(cfg.category, var, val, cfg.lineno); + } else { + zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); + } + } + zap_config_close_file(&cfg); + + zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); + + return configured; +} + zap_status_t zap_global_init(void) { zap_config_t cfg; @@ -1285,9 +1404,7 @@ zap_status_t zap_global_init(void) zap_mutex_unlock(globals.mutex); if (zio) { - if (zio->configure(zio) == ZAP_SUCCESS) { - configured++; - } + configured += load_config(zio); } else { zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val); } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 65385c11e4..fc14f0ad8f 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -106,7 +106,23 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, return configured; } -static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_span_t *span, zap_chan_type_t type, char *name, char *number) +static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) +{ + if (!strcasecmp(category, "defaults")) { + if (!strcasecmp(var, "codec_ms")) { + unsigned codec_ms = atoi(val); + if (codec_ms < 10 || codec_ms > 60) { + zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno); + } else { + wp_globals.codec_ms = codec_ms; + } + } + } + + return ZAP_SUCCESS; +} + +static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) { int items, i; char *mydata, *item_list[10]; @@ -132,7 +148,7 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa } if (!(sp && ch)) { - zap_log(ZAP_LOG_ERROR, "Invalid input on line %d\n", cfg->lineno); + zap_log(ZAP_LOG_ERROR, "Invalid input\n"); continue; } @@ -173,126 +189,6 @@ static unsigned wp_configure_channel(zap_config_t *cfg, const char *str, zap_spa return configured; } -static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) -{ - zap_config_t cfg; - char *var, *val; - int catno = -1; - zap_span_t *span = NULL; - int new_span = 0; - unsigned configured = 0, d = 0; - char name[80] = ""; - char number[25] = ""; - - ZIO_CONFIGURE_MUZZLE; - - zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n"); - if (!zap_config_open_file(&cfg, "wanpipe.conf")) { - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "defaults")) { - if (!strcasecmp(var, "codec_ms")) { - unsigned codec_ms = atoi(val); - if (codec_ms < 10 || codec_ms > 60) { - zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", cfg.lineno); - } else { - wp_globals.codec_ms = codec_ms; - } - } - } else if (!strcasecmp(cfg.category, "span")) { - if (cfg.catno != catno) { - zap_log(ZAP_LOG_DEBUG, "found config for span\n"); - catno = cfg.catno; - new_span = 1; - span = NULL; - } - - if (new_span) { - if (!strcasecmp(var, "enabled") && ! zap_true(val)) { - zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); - } else { - if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span\n"); - span = NULL; - } - } - new_span = 0; - continue; - } - - if (!span) { - continue; - } - - zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); - - if (!strcasecmp(var, "enabled")) { - zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); - } else if (!strcasecmp(var, "trunk_type")) { - span->trunk_type = zap_str2zap_trunk_type(val); - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } else if (!strcasecmp(var, "name")) { - if (!strcasecmp(val, "undef")) { - *name = '\0'; - } else { - zap_copy_string(name, val, sizeof(name)); - } - } else if (!strcasecmp(var, "number")) { - if (!strcasecmp(val, "undef")) { - *number = '\0'; - } else { - zap_copy_string(number, val, sizeof(number)); - } - } else if (!strcasecmp(var, "fxo-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXO; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } - if (span->trunk_type == ZAP_TRUNK_FXO) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXO, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); - } - } else if (!strcasecmp(var, "fxs-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXS; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } - if (span->trunk_type == ZAP_TRUNK_FXS) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_FXS, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); - } - } else if (!strcasecmp(var, "b-channel")) { - configured += wp_configure_channel(&cfg, val, span, ZAP_CHAN_TYPE_B, name, number); - } else if (!strcasecmp(var, "d-channel")) { - if (d) { - zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); - } else { - zap_chan_type_t qtype; - if (!strncasecmp(val, "lapd:", 5)) { - qtype = ZAP_CHAN_TYPE_DQ931; - val += 5; - } else { - qtype = ZAP_CHAN_TYPE_DQ921; - } - configured += wp_configure_channel(&cfg, val, span, qtype, name, number); - d++; - } - } - } - } - zap_config_close_file(&cfg); - - zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); - - return configured ? ZAP_SUCCESS : ZAP_FAIL; -} - static ZIO_OPEN_FUNCTION(wanpipe_open) { @@ -592,7 +488,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wp_globals.wink_ms = 150; wp_globals.flash_ms = 750; wanpipe_interface.name = "wanpipe"; - wanpipe_interface.configure = wanpipe_configure; + 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; From 3a7c7cbc6deed4d37305d7922aa7a79eb36fe3d6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:44:41 +0000 Subject: [PATCH 0313/1766] refactor build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@157 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/{src => }/Makefile | 109 +++++++++++++---------- libs/openzap/{src => }/docs/Doxygen.conf | 0 libs/openzap/{src => }/general.makefile | 0 libs/openzap/{src => }/wanpipe | 2 +- libs/openzap/{src => }/zt | 2 +- 5 files changed, 63 insertions(+), 50 deletions(-) rename libs/openzap/{src => }/Makefile (50%) rename libs/openzap/{src => }/docs/Doxygen.conf (100%) rename libs/openzap/{src => }/general.makefile (100%) rename libs/openzap/{src => }/wanpipe (91%) rename libs/openzap/{src => }/zt (55%) diff --git a/libs/openzap/src/Makefile b/libs/openzap/Makefile similarity index 50% rename from libs/openzap/src/Makefile rename to libs/openzap/Makefile index e7bed960d4..1c04d82ba0 100644 --- a/libs/openzap/src/Makefile +++ b/libs/openzap/Makefile @@ -29,42 +29,43 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SRC=src +OBJS=\ +$(SRC)/hashtable.o \ +$(SRC)/hashtable_itr.o \ +$(SRC)/zap_io.o \ +$(SRC)/zap_isdn.o \ +$(SRC)/zap_analog.o \ +$(SRC)/zap_config.o \ +$(SRC)/g711.o \ +$(SRC)/libteletone_detect.o \ +$(SRC)/libteletone_generate.o \ +$(SRC)/zap_buffer.o \ +$(SRC)/zap_threadmutex.o \ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalie.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/Q932mes.o -OBJS=hashtable.o \ -hashtable_itr.o \ -zap_io.o \ -zap_isdn.o \ -zap_analog.o \ -zap_config.o \ -g711.o \ -libteletone_detect.o \ -libteletone_generate.o \ -zap_buffer.o \ -zap_threadmutex.o \ -isdn/EuroISDNStateNT.o \ -isdn/EuroISDNStateTE.o \ -isdn/mfifo.o \ -isdn/Q921.o \ -isdn/Q931api.o \ -isdn/Q931.o \ -isdn/Q931ie.o \ -isdn/Q931mes.o \ -isdn/Q931StateNT.o \ -isdn/Q931StateTE.o \ -isdn/nationalie.o \ -isdn/nationalmes.o \ -isdn/nationalStateNT.o \ -isdn/nationalStateTE.o \ -isdn/Q932mes.o - -HEADERS=isdn/include/Q931.h \ - include/openzap.h +HEADERS=$(SRC)/isdn/include/Q931.h \ + $(SRC)/include/openzap.h PWD=$(shell pwd) -INCS=-I$(PWD)/include -I$(PWD)/isdn/include +INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a -TMP=-I../../libpri-1.2.4 -Iinclude -I. -w +TMP=-I../libpri-1.2.4 -I$(SRC)/include -I./src -w include general.makefile $(ZAP_MODS) @@ -74,31 +75,31 @@ $(MYLIB): $(OBJS) $(HEADERS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) -testapp: testapp.c $(MYLIB) - $(CC) $(INCS) -L. testapp.c -o testapp -lopenzap -lm -lpthread +testapp: $(SRC)/testapp.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread -testisdn: testisdn.c $(MYLIB) - $(CC) $(INCS) -L. testisdn.c -o testisdn -lopenzap -lm -lpthread +testisdn: $(SRC)/testisdn.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread -testanalog: testanalog.c $(MYLIB) - $(CC) $(INCS) -L. testanalog.c -o testanalog -lopenzap -lm -lpthread +testanalog: $(SRC)/testanalog.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread -priserver.o: priserver.c - $(CC) $(INCS) $(TMP) -c priserver.c -o priserver.o +priserver.o: $(SRC)/priserver.c + $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o -sangoma_pri.o: sangoma_pri.c - $(CC) $(INCS) $(TMP) -c sangoma_pri.c -o sangoma_pri.o +$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c + $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o -priserver: $(MYLIB) priserver.o sangoma_pri.o - $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a -zap_io.o: zap_io.c +$(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -zap_wanpipe.o: zap_wanpipe.c +$(SRC)/zap_wanpipe.o: $(SRC)/zap_wanpipe.c $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ -zap_zt.o: zap_zt.c +$(SRC)/zap_zt.o: $(SRC)/zap_zt.c $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@ %.o: %.c @@ -106,6 +107,18 @@ zap_zt.o: zap_zt.c dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf -clean: - rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog + +mod_openzap/mod_openzap.so: $(MYLIB) + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.so + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + cd mod_openzap && make clean + +clean: mod_openzap-clean + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog diff --git a/libs/openzap/src/docs/Doxygen.conf b/libs/openzap/docs/Doxygen.conf similarity index 100% rename from libs/openzap/src/docs/Doxygen.conf rename to libs/openzap/docs/Doxygen.conf diff --git a/libs/openzap/src/general.makefile b/libs/openzap/general.makefile similarity index 100% rename from libs/openzap/src/general.makefile rename to libs/openzap/general.makefile diff --git a/libs/openzap/src/wanpipe b/libs/openzap/wanpipe similarity index 91% rename from libs/openzap/src/wanpipe rename to libs/openzap/wanpipe index ae554a11c2..4165283537 100644 --- a/libs/openzap/src/wanpipe +++ b/libs/openzap/wanpipe @@ -1,5 +1,5 @@ MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT -OBJS += zap_wanpipe.o +OBJS += $(SRC)/zap_wanpipe.o WANPIPE_INCLUDE=/usr/include/wanpipe WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include diff --git a/libs/openzap/src/zt b/libs/openzap/zt similarity index 55% rename from libs/openzap/src/zt rename to libs/openzap/zt index 9e0f14d57c..28934f3b56 100644 --- a/libs/openzap/src/zt +++ b/libs/openzap/zt @@ -1,2 +1,2 @@ MOD_CFLAGS +=-DZAP_ZT_SUPPORT -OBJS += zap_zt.o +OBJS += $(SRC)/zap_zt.o From 0c40cb90167e265554592adf5e8940538824db47 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:44:41 +0000 Subject: [PATCH 0314/1766] refactor build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@157 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/{src => }/Makefile | 109 +++++++++++++---------- libs/freetdm/{src => }/docs/Doxygen.conf | 0 libs/freetdm/{src => }/general.makefile | 0 libs/freetdm/{src => }/wanpipe | 2 +- libs/freetdm/{src => }/zt | 2 +- 5 files changed, 63 insertions(+), 50 deletions(-) rename libs/freetdm/{src => }/Makefile (50%) rename libs/freetdm/{src => }/docs/Doxygen.conf (100%) rename libs/freetdm/{src => }/general.makefile (100%) rename libs/freetdm/{src => }/wanpipe (91%) rename libs/freetdm/{src => }/zt (55%) diff --git a/libs/freetdm/src/Makefile b/libs/freetdm/Makefile similarity index 50% rename from libs/freetdm/src/Makefile rename to libs/freetdm/Makefile index e7bed960d4..1c04d82ba0 100644 --- a/libs/freetdm/src/Makefile +++ b/libs/freetdm/Makefile @@ -29,42 +29,43 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SRC=src +OBJS=\ +$(SRC)/hashtable.o \ +$(SRC)/hashtable_itr.o \ +$(SRC)/zap_io.o \ +$(SRC)/zap_isdn.o \ +$(SRC)/zap_analog.o \ +$(SRC)/zap_config.o \ +$(SRC)/g711.o \ +$(SRC)/libteletone_detect.o \ +$(SRC)/libteletone_generate.o \ +$(SRC)/zap_buffer.o \ +$(SRC)/zap_threadmutex.o \ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalie.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/Q932mes.o -OBJS=hashtable.o \ -hashtable_itr.o \ -zap_io.o \ -zap_isdn.o \ -zap_analog.o \ -zap_config.o \ -g711.o \ -libteletone_detect.o \ -libteletone_generate.o \ -zap_buffer.o \ -zap_threadmutex.o \ -isdn/EuroISDNStateNT.o \ -isdn/EuroISDNStateTE.o \ -isdn/mfifo.o \ -isdn/Q921.o \ -isdn/Q931api.o \ -isdn/Q931.o \ -isdn/Q931ie.o \ -isdn/Q931mes.o \ -isdn/Q931StateNT.o \ -isdn/Q931StateTE.o \ -isdn/nationalie.o \ -isdn/nationalmes.o \ -isdn/nationalStateNT.o \ -isdn/nationalStateTE.o \ -isdn/Q932mes.o - -HEADERS=isdn/include/Q931.h \ - include/openzap.h +HEADERS=$(SRC)/isdn/include/Q931.h \ + $(SRC)/include/openzap.h PWD=$(shell pwd) -INCS=-I$(PWD)/include -I$(PWD)/isdn/include +INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a -TMP=-I../../libpri-1.2.4 -Iinclude -I. -w +TMP=-I../libpri-1.2.4 -I$(SRC)/include -I./src -w include general.makefile $(ZAP_MODS) @@ -74,31 +75,31 @@ $(MYLIB): $(OBJS) $(HEADERS) ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) -testapp: testapp.c $(MYLIB) - $(CC) $(INCS) -L. testapp.c -o testapp -lopenzap -lm -lpthread +testapp: $(SRC)/testapp.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread -testisdn: testisdn.c $(MYLIB) - $(CC) $(INCS) -L. testisdn.c -o testisdn -lopenzap -lm -lpthread +testisdn: $(SRC)/testisdn.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread -testanalog: testanalog.c $(MYLIB) - $(CC) $(INCS) -L. testanalog.c -o testanalog -lopenzap -lm -lpthread +testanalog: $(SRC)/testanalog.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread -priserver.o: priserver.c - $(CC) $(INCS) $(TMP) -c priserver.c -o priserver.o +priserver.o: $(SRC)/priserver.c + $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o -sangoma_pri.o: sangoma_pri.c - $(CC) $(INCS) $(TMP) -c sangoma_pri.c -o sangoma_pri.o +$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c + $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o -priserver: $(MYLIB) priserver.o sangoma_pri.o - $(CC) sangoma_pri.o priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a -zap_io.o: zap_io.c +$(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -zap_wanpipe.o: zap_wanpipe.c +$(SRC)/zap_wanpipe.o: $(SRC)/zap_wanpipe.c $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ -zap_zt.o: zap_zt.c +$(SRC)/zap_zt.o: $(SRC)/zap_zt.c $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@ %.o: %.c @@ -106,6 +107,18 @@ zap_zt.o: zap_zt.c dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf -clean: - rm -f *.o isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog + +mod_openzap/mod_openzap.so: $(MYLIB) + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.so + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + cd mod_openzap && make clean + +clean: mod_openzap-clean + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog diff --git a/libs/freetdm/src/docs/Doxygen.conf b/libs/freetdm/docs/Doxygen.conf similarity index 100% rename from libs/freetdm/src/docs/Doxygen.conf rename to libs/freetdm/docs/Doxygen.conf diff --git a/libs/freetdm/src/general.makefile b/libs/freetdm/general.makefile similarity index 100% rename from libs/freetdm/src/general.makefile rename to libs/freetdm/general.makefile diff --git a/libs/freetdm/src/wanpipe b/libs/freetdm/wanpipe similarity index 91% rename from libs/freetdm/src/wanpipe rename to libs/freetdm/wanpipe index ae554a11c2..4165283537 100644 --- a/libs/freetdm/src/wanpipe +++ b/libs/freetdm/wanpipe @@ -1,5 +1,5 @@ MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT -OBJS += zap_wanpipe.o +OBJS += $(SRC)/zap_wanpipe.o WANPIPE_INCLUDE=/usr/include/wanpipe WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include diff --git a/libs/freetdm/src/zt b/libs/freetdm/zt similarity index 55% rename from libs/freetdm/src/zt rename to libs/freetdm/zt index 9e0f14d57c..28934f3b56 100644 --- a/libs/freetdm/src/zt +++ b/libs/freetdm/zt @@ -1,2 +1,2 @@ MOD_CFLAGS +=-DZAP_ZT_SUPPORT -OBJS += zap_zt.o +OBJS += $(SRC)/zap_zt.o From 219ac87d22c7d72a6291bea9c519e8da5a0202ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:45:31 +0000 Subject: [PATCH 0315/1766] refactor build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@158 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 14 + libs/openzap/mod_openzap/mod_openzap.c | 774 +++++++++++++++++++++++++ 2 files changed, 788 insertions(+) create mode 100644 libs/openzap/mod_openzap/Makefile create mode 100644 libs/openzap/mod_openzap/mod_openzap.c diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile new file mode 100644 index 0000000000..2ff7f24232 --- /dev/null +++ b/libs/openzap/mod_openzap/Makefile @@ -0,0 +1,14 @@ +BASE=/usr/src/freeswitch.trunk +OZ_DIR=.. +VERBOSE=1 +OZA=$(OZ_DIR)/libopenzap.a +LOCAL_CFLAGS=-w -I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include +LOCAL_LIBADD=$(OZA) +include $(BASE)/build/modmake.rules + +local_depend: $(OZA) + +$(OZA): + cd $(OZ_DIR) && $(MAKE) ZAP_MODS=wanpipe + + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c new file mode 100644 index 0000000000..ffdab55b1f --- /dev/null +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -0,0 +1,774 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * mod_openzap.c -- OPENZAP Endpoint Module + * + */ +#include +#include "openzap.h" +#include "zap_analog.h" +#include "zap_isdn.h" + +static const char modname[] = "mod_openzap"; + +static switch_memory_pool_t *module_pool = NULL; +static int running = 1; + +struct span_config { + zap_span_t *span; + char dialplan[80]; + char context[80]; +}; + +static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; + + +typedef enum { + TFLAG_IO = (1 << 0), + TFLAG_INBOUND = (1 << 1), + TFLAG_OUTBOUND = (1 << 2), + TFLAG_DTMF = (1 << 3), + TFLAG_VOICE = (1 << 4), + TFLAG_HANGUP = (1 << 5), + TFLAG_LINEAR = (1 << 6), + TFLAG_CODEC = (1 << 7), + TFLAG_BREAK = (1 << 8) +} TFLAGS; + + +static struct { + int debug; + char *dialplan; + char *codec_string; + char *codec_order[SWITCH_MAX_CODECS]; + int codec_order_last; + char *codec_rates_string; + char *codec_rates[SWITCH_MAX_CODECS]; + int codec_rates_last; + unsigned int flags; + int fd; + int calls; + switch_mutex_t *mutex; +} globals; + +struct private_object { + unsigned int flags; + switch_codec_t read_codec; + switch_codec_t write_codec; + switch_frame_t read_frame; + unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; + switch_core_session_t *session; + switch_caller_profile_t *caller_profile; + unsigned int codec; + unsigned int codecs; + unsigned short samprate; + switch_mutex_t *mutex; + switch_mutex_t *flag_mutex; + zap_channel_t *zchan; +}; + +typedef struct private_object private_t; + + +static switch_status_t channel_on_init(switch_core_session_t *session); +static switch_status_t channel_on_hangup(switch_core_session_t *session); +static switch_status_t channel_on_ring(switch_core_session_t *session); +static switch_status_t channel_on_loopback(switch_core_session_t *session); +static switch_status_t channel_on_transmit(switch_core_session_t *session); +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, + switch_caller_profile_t *outbound_profile, + switch_core_session_t **new_session, switch_memory_pool_t **pool); +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); + + +static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) +{ + char *dname = NULL; + uint32_t interval = 0, srate = 8000; + zap_codec_t codec; + + tech_pvt->zchan = zchan; + tech_pvt->read_frame.data = tech_pvt->databuf; + tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); + switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + switch_core_session_set_private(session, tech_pvt); + tech_pvt->session = session; + + zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec); + + + switch(codec) { + case ZAP_CODEC_ULAW: + { + dname = "PCMU"; + } + break; + case ZAP_CODEC_ALAW: + { + dname = "PCMA"; + } + break; + case ZAP_CODEC_SLIN: + { + dname = "L16"; + } + break; + } + + + if (switch_core_codec_init(&tech_pvt->read_codec, + dname, + NULL, + srate, + interval, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); + return SWITCH_STATUS_GENERR; + } else { + if (switch_core_codec_init(&tech_pvt->write_codec, + dname, + NULL, + srate, + interval, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); + switch_core_codec_destroy(&tech_pvt->read_codec); + return SWITCH_STATUS_GENERR; + } + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set codec %s %dms\n", dname, interval); + switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); + switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); + switch_set_flag_locked(tech_pvt, TFLAG_CODEC); + tech_pvt->read_frame.codec = &tech_pvt->read_codec; + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_on_init(switch_core_session_t *session) +{ + switch_channel_t *channel; + private_t *tech_pvt = NULL; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + switch_set_flag_locked(tech_pvt, TFLAG_IO); + + /* Move Channel's State Machine to RING */ + switch_channel_set_state(channel, CS_RING); + switch_mutex_lock(globals.mutex); + globals.calls++; + switch_mutex_unlock(globals.mutex); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_ring(switch_core_session_t *session) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel)); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_execute(switch_core_session_t *session) +{ + + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); + + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_hangup(switch_core_session_t *session) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); + } + + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); + switch_mutex_lock(globals.mutex); + globals.calls--; + if (globals.calls < 0) { + globals.calls = 0; + } + switch_mutex_unlock(globals.mutex); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (sig) { + case SWITCH_SIG_KILL: + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); + } + break; + case SWITCH_SIG_BREAK: + switch_set_flag_locked(tech_pvt, TFLAG_BREAK); + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_loopback(switch_core_session_t *session) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_transmit(switch_core_session_t *session) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n"); + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id) +{ + private_t *tech_pvt = NULL; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id) +{ + private_t *tech_pvt = NULL; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf) +{ + private_t *tech_pvt = NULL; + char *digit; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, dtmf); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + zap_size_t len; + zap_wait_flag_t wflags = ZAP_READ; + uint8_t dtmf[128] = ""; + zap_status_t status; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + assert(tech_pvt->zchan != NULL); + + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { + return SWITCH_STATUS_GENERR; + } + + status = zap_channel_wait(tech_pvt->zchan, &wflags, timeout); + + if (status == ZAP_FAIL) { + return SWITCH_STATUS_GENERR; + } + + if (status == ZAP_TIMEOUT) { + return SWITCH_STATUS_BREAK; + } + + if (!(wflags & ZAP_READ)) { + return SWITCH_STATUS_GENERR; + } + + len = tech_pvt->read_frame.buflen; + if (zap_channel_read(tech_pvt->zchan, tech_pvt->read_frame.data, &len) != ZAP_SUCCESS) { + return SWITCH_STATUS_GENERR; + } + + *frame = &tech_pvt->read_frame; + tech_pvt->read_frame.datalen = len; + tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; + + if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { + tech_pvt->read_frame.samples /= 2; + } + + if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { + switch_channel_queue_dtmf(channel, dtmf); + } + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + zap_size_t len; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + assert(tech_pvt->zchan != NULL); + + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { + return SWITCH_STATUS_GENERR; + } + + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { + return SWITCH_STATUS_FALSE; + } + + len = frame->datalen; + if (zap_channel_write(tech_pvt->zchan, frame->data, &len) != ZAP_SUCCESS) { + return SWITCH_STATUS_GENERR; + } + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_ANSWER: + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + break; + case SWITCH_MESSAGE_INDICATE_RINGING: + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} + +static const switch_state_handler_table_t channel_event_handlers = { + /*.on_init */ channel_on_init, + /*.on_ring */ channel_on_ring, + /*.on_execute */ channel_on_execute, + /*.on_hangup */ channel_on_hangup, + /*.on_loopback */ channel_on_loopback, + /*.on_transmit */ channel_on_transmit +}; + +static const switch_io_routines_t channel_io_routines = { + /*.outgoing_channel */ channel_outgoing_channel, + /*.read_frame */ channel_read_frame, + /*.write_frame */ channel_write_frame, + /*.kill_channel */ channel_kill_channel, + /*.waitfor_read */ channel_waitfor_read, + /*.waitfor_write */ channel_waitfor_write, + /*.send_dtmf */ channel_send_dtmf, + /*.receive_message*/ channel_receive_message +}; + +static const switch_endpoint_interface_t channel_endpoint_interface = { + /*.interface_name */ "openzap", + /*.io_routines */ &channel_io_routines, + /*.event_handlers */ &channel_event_handlers, + /*.private */ NULL, + /*.next */ NULL +}; + +static const switch_loadable_module_interface_t channel_module_interface = { + /*.module_name */ modname, + /*.endpoint_interface */ &channel_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL +}; + + +/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines +that allocate memory or you will have 1 channel with memory allocated from another channel's pool! +*/ +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, + switch_caller_profile_t *outbound_profile, + switch_core_session_t **new_session, switch_memory_pool_t **pool) +{ + if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { + private_t *tech_pvt; + switch_channel_t *channel; + switch_caller_profile_t *caller_profile; + unsigned int req = 0, cap = 0; + unsigned short samprate = 0; + + switch_core_session_add_stream(*new_session, NULL); + if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { + channel = switch_core_session_get_channel(*new_session); + tech_init(tech_pvt, *new_session, NULL); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); + switch_core_session_destroy(new_session); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if (outbound_profile) { + char name[128]; + + snprintf(name, sizeof(name), "OPENZAP/%s-%04x", outbound_profile->destination_number, rand() & 0xffff); + switch_channel_set_name(channel, name); + + caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + switch_channel_set_caller_profile(channel, caller_profile); + tech_pvt->caller_profile = caller_profile; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); + switch_core_session_destroy(new_session); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + + switch_channel_set_flag(channel, CF_OUTBOUND); + switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); + switch_channel_set_state(channel, CS_INIT); + return SWITCH_CAUSE_SUCCESS; + } + + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + +} + +static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) +{ + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + return ZAP_SUCCESS; +} +static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +{ + switch_core_session_t *session = NULL; + private_t *tech_pvt = NULL; + switch_channel_t *channel = NULL; + char name[128]; + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + return ZAP_SUCCESS; + } + + switch_core_session_add_stream(session, NULL); + + tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t)); + assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); + switch_core_session_destroy(&session); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + return ZAP_SUCCESS; + } + + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), + "OpenZAP", + SPAN_CONFIG[sigmsg->span->span_id].dialplan, + sigmsg->channel->chan_name, + sigmsg->channel->chan_number, + NULL, + sigmsg->channel->chan_number, + NULL, + NULL, + (char *) modname, + SPAN_CONFIG[sigmsg->span->span_id].context, + sigmsg->dnis); + assert(tech_pvt->caller_profile != NULL); + + snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); + switch_channel_set_name(channel, name); + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + + switch_channel_set_state(channel, CS_INIT); + if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); + switch_core_session_destroy(&session); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + return ZAP_SUCCESS; + } + + //zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING); + + break; + default: + break; + } + + return ZAP_SUCCESS; +} + + + +static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + char *data = NULL; + va_list ap; + + va_start(ap, fmt); + + if (switch_vasprintf(&data, fmt, ap) != -1) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, data); + free(data); + } + + va_end(ap); + +} + +static switch_status_t load_config(void) +{ + char *cf = "openzap.conf"; + switch_xml_t cfg, xml, settings, param, spans, span; + + memset(&globals, 0, sizeof(globals)); + switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); + if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); + return SWITCH_STATUS_TERM; + } + + if ((settings = switch_xml_child(cfg, "settings"))) { + for (param = switch_xml_child(settings, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "debug")) { + globals.debug = atoi(val); + } + } + } + + if ((spans = switch_xml_child(cfg, "analog_spans"))) { + for (span = switch_xml_child(spans, "span"); span; span = span->next) { + char *mod = (char *) switch_xml_attr_soft(span, "module"); + char *id = (char *) switch_xml_attr_soft(span, "id"); + char *context = "default"; + char *dialplan = "XML"; + char *tonegroup = NULL; + char *digit_timeout = NULL; + char *max_digits = NULL; + uint32_t span_id = 0, to = 0, max = 0; + zap_span_t *span = NULL; + + for (param = switch_xml_child(span, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "digit_timeout")) { + digit_timeout = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "max_digits")) { + digit_timeout = val; + } + } + + if (!mod) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'module'\n"); + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (digit_timeout) { + to = atoi(digit_timeout); + } + + if (max_digits) { + max = atoi(max_digits); + } + + if (zap_span_find(mod, span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s:%d\n", mod, span_id); + continue; + } + + if (zap_analog_configure_span(span, tonegroup, to, max, span->trunk_type == ZAP_TRUNK_FXS ? on_fxs_signal : on_fxo_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %s:%d\n", mod, span_id); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + + + zap_analog_start(span); + } + } + + + switch_xml_free(xml); + + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename) +{ + + if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n"); + return SWITCH_STATUS_TERM; + } + + zap_global_set_logger(zap_logger); + + if (zap_global_init() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); + return SWITCH_STATUS_TERM; + } + + if (load_config() != SWITCH_STATUS_SUCCESS) { + zap_global_destroy(); + return SWITCH_STATUS_TERM; + } + + /* connect my internal structure to the blank pointer passed to me */ + *module_interface = &channel_module_interface; + + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; +} + + + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ From fa21c6bfc983d447f376597cb892ac2aa8076796 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:45:31 +0000 Subject: [PATCH 0316/1766] refactor build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@158 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 14 + libs/freetdm/mod_openzap/mod_openzap.c | 774 +++++++++++++++++++++++++ 2 files changed, 788 insertions(+) create mode 100644 libs/freetdm/mod_openzap/Makefile create mode 100644 libs/freetdm/mod_openzap/mod_openzap.c diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile new file mode 100644 index 0000000000..2ff7f24232 --- /dev/null +++ b/libs/freetdm/mod_openzap/Makefile @@ -0,0 +1,14 @@ +BASE=/usr/src/freeswitch.trunk +OZ_DIR=.. +VERBOSE=1 +OZA=$(OZ_DIR)/libopenzap.a +LOCAL_CFLAGS=-w -I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include +LOCAL_LIBADD=$(OZA) +include $(BASE)/build/modmake.rules + +local_depend: $(OZA) + +$(OZA): + cd $(OZ_DIR) && $(MAKE) ZAP_MODS=wanpipe + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c new file mode 100644 index 0000000000..ffdab55b1f --- /dev/null +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -0,0 +1,774 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * mod_openzap.c -- OPENZAP Endpoint Module + * + */ +#include +#include "openzap.h" +#include "zap_analog.h" +#include "zap_isdn.h" + +static const char modname[] = "mod_openzap"; + +static switch_memory_pool_t *module_pool = NULL; +static int running = 1; + +struct span_config { + zap_span_t *span; + char dialplan[80]; + char context[80]; +}; + +static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; + + +typedef enum { + TFLAG_IO = (1 << 0), + TFLAG_INBOUND = (1 << 1), + TFLAG_OUTBOUND = (1 << 2), + TFLAG_DTMF = (1 << 3), + TFLAG_VOICE = (1 << 4), + TFLAG_HANGUP = (1 << 5), + TFLAG_LINEAR = (1 << 6), + TFLAG_CODEC = (1 << 7), + TFLAG_BREAK = (1 << 8) +} TFLAGS; + + +static struct { + int debug; + char *dialplan; + char *codec_string; + char *codec_order[SWITCH_MAX_CODECS]; + int codec_order_last; + char *codec_rates_string; + char *codec_rates[SWITCH_MAX_CODECS]; + int codec_rates_last; + unsigned int flags; + int fd; + int calls; + switch_mutex_t *mutex; +} globals; + +struct private_object { + unsigned int flags; + switch_codec_t read_codec; + switch_codec_t write_codec; + switch_frame_t read_frame; + unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; + switch_core_session_t *session; + switch_caller_profile_t *caller_profile; + unsigned int codec; + unsigned int codecs; + unsigned short samprate; + switch_mutex_t *mutex; + switch_mutex_t *flag_mutex; + zap_channel_t *zchan; +}; + +typedef struct private_object private_t; + + +static switch_status_t channel_on_init(switch_core_session_t *session); +static switch_status_t channel_on_hangup(switch_core_session_t *session); +static switch_status_t channel_on_ring(switch_core_session_t *session); +static switch_status_t channel_on_loopback(switch_core_session_t *session); +static switch_status_t channel_on_transmit(switch_core_session_t *session); +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, + switch_caller_profile_t *outbound_profile, + switch_core_session_t **new_session, switch_memory_pool_t **pool); +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); + + +static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) +{ + char *dname = NULL; + uint32_t interval = 0, srate = 8000; + zap_codec_t codec; + + tech_pvt->zchan = zchan; + tech_pvt->read_frame.data = tech_pvt->databuf; + tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); + switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + switch_core_session_set_private(session, tech_pvt); + tech_pvt->session = session; + + zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec); + + + switch(codec) { + case ZAP_CODEC_ULAW: + { + dname = "PCMU"; + } + break; + case ZAP_CODEC_ALAW: + { + dname = "PCMA"; + } + break; + case ZAP_CODEC_SLIN: + { + dname = "L16"; + } + break; + } + + + if (switch_core_codec_init(&tech_pvt->read_codec, + dname, + NULL, + srate, + interval, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); + return SWITCH_STATUS_GENERR; + } else { + if (switch_core_codec_init(&tech_pvt->write_codec, + dname, + NULL, + srate, + interval, + 1, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); + switch_core_codec_destroy(&tech_pvt->read_codec); + return SWITCH_STATUS_GENERR; + } + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set codec %s %dms\n", dname, interval); + switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); + switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); + switch_set_flag_locked(tech_pvt, TFLAG_CODEC); + tech_pvt->read_frame.codec = &tech_pvt->read_codec; + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_on_init(switch_core_session_t *session) +{ + switch_channel_t *channel; + private_t *tech_pvt = NULL; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + switch_set_flag_locked(tech_pvt, TFLAG_IO); + + /* Move Channel's State Machine to RING */ + switch_channel_set_state(channel, CS_RING); + switch_mutex_lock(globals.mutex); + globals.calls++; + switch_mutex_unlock(globals.mutex); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_ring(switch_core_session_t *session) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel)); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_execute(switch_core_session_t *session) +{ + + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); + + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_hangup(switch_core_session_t *session) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); + } + + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); + switch_mutex_lock(globals.mutex); + globals.calls--; + if (globals.calls < 0) { + globals.calls = 0; + } + switch_mutex_unlock(globals.mutex); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (sig) { + case SWITCH_SIG_KILL: + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); + } + break; + case SWITCH_SIG_BREAK: + switch_set_flag_locked(tech_pvt, TFLAG_BREAK); + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_loopback(switch_core_session_t *session) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_transmit(switch_core_session_t *session) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n"); + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id) +{ + private_t *tech_pvt = NULL; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id) +{ + private_t *tech_pvt = NULL; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf) +{ + private_t *tech_pvt = NULL; + char *digit; + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, dtmf); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + zap_size_t len; + zap_wait_flag_t wflags = ZAP_READ; + uint8_t dtmf[128] = ""; + zap_status_t status; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + assert(tech_pvt->zchan != NULL); + + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { + return SWITCH_STATUS_GENERR; + } + + status = zap_channel_wait(tech_pvt->zchan, &wflags, timeout); + + if (status == ZAP_FAIL) { + return SWITCH_STATUS_GENERR; + } + + if (status == ZAP_TIMEOUT) { + return SWITCH_STATUS_BREAK; + } + + if (!(wflags & ZAP_READ)) { + return SWITCH_STATUS_GENERR; + } + + len = tech_pvt->read_frame.buflen; + if (zap_channel_read(tech_pvt->zchan, tech_pvt->read_frame.data, &len) != ZAP_SUCCESS) { + return SWITCH_STATUS_GENERR; + } + + *frame = &tech_pvt->read_frame; + tech_pvt->read_frame.datalen = len; + tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; + + if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { + tech_pvt->read_frame.samples /= 2; + } + + if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { + switch_channel_queue_dtmf(channel, dtmf); + } + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + zap_size_t len; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + assert(tech_pvt->zchan != NULL); + + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { + return SWITCH_STATUS_GENERR; + } + + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { + return SWITCH_STATUS_FALSE; + } + + len = frame->datalen; + if (zap_channel_write(tech_pvt->zchan, frame->data, &len) != ZAP_SUCCESS) { + return SWITCH_STATUS_GENERR; + } + + return SWITCH_STATUS_SUCCESS; + +} + +static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_ANSWER: + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + break; + case SWITCH_MESSAGE_INDICATE_RINGING: + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} + +static const switch_state_handler_table_t channel_event_handlers = { + /*.on_init */ channel_on_init, + /*.on_ring */ channel_on_ring, + /*.on_execute */ channel_on_execute, + /*.on_hangup */ channel_on_hangup, + /*.on_loopback */ channel_on_loopback, + /*.on_transmit */ channel_on_transmit +}; + +static const switch_io_routines_t channel_io_routines = { + /*.outgoing_channel */ channel_outgoing_channel, + /*.read_frame */ channel_read_frame, + /*.write_frame */ channel_write_frame, + /*.kill_channel */ channel_kill_channel, + /*.waitfor_read */ channel_waitfor_read, + /*.waitfor_write */ channel_waitfor_write, + /*.send_dtmf */ channel_send_dtmf, + /*.receive_message*/ channel_receive_message +}; + +static const switch_endpoint_interface_t channel_endpoint_interface = { + /*.interface_name */ "openzap", + /*.io_routines */ &channel_io_routines, + /*.event_handlers */ &channel_event_handlers, + /*.private */ NULL, + /*.next */ NULL +}; + +static const switch_loadable_module_interface_t channel_module_interface = { + /*.module_name */ modname, + /*.endpoint_interface */ &channel_endpoint_interface, + /*.timer_interface */ NULL, + /*.dialplan_interface */ NULL, + /*.codec_interface */ NULL, + /*.application_interface */ NULL +}; + + +/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines +that allocate memory or you will have 1 channel with memory allocated from another channel's pool! +*/ +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, + switch_caller_profile_t *outbound_profile, + switch_core_session_t **new_session, switch_memory_pool_t **pool) +{ + if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { + private_t *tech_pvt; + switch_channel_t *channel; + switch_caller_profile_t *caller_profile; + unsigned int req = 0, cap = 0; + unsigned short samprate = 0; + + switch_core_session_add_stream(*new_session, NULL); + if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { + channel = switch_core_session_get_channel(*new_session); + tech_init(tech_pvt, *new_session, NULL); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); + switch_core_session_destroy(new_session); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if (outbound_profile) { + char name[128]; + + snprintf(name, sizeof(name), "OPENZAP/%s-%04x", outbound_profile->destination_number, rand() & 0xffff); + switch_channel_set_name(channel, name); + + caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + switch_channel_set_caller_profile(channel, caller_profile); + tech_pvt->caller_profile = caller_profile; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); + switch_core_session_destroy(new_session); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + + switch_channel_set_flag(channel, CF_OUTBOUND); + switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); + switch_channel_set_state(channel, CS_INIT); + return SWITCH_CAUSE_SUCCESS; + } + + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + +} + +static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) +{ + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + return ZAP_SUCCESS; +} +static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +{ + switch_core_session_t *session = NULL; + private_t *tech_pvt = NULL; + switch_channel_t *channel = NULL; + char name[128]; + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + return ZAP_SUCCESS; + } + + switch_core_session_add_stream(session, NULL); + + tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t)); + assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); + switch_core_session_destroy(&session); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + return ZAP_SUCCESS; + } + + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), + "OpenZAP", + SPAN_CONFIG[sigmsg->span->span_id].dialplan, + sigmsg->channel->chan_name, + sigmsg->channel->chan_number, + NULL, + sigmsg->channel->chan_number, + NULL, + NULL, + (char *) modname, + SPAN_CONFIG[sigmsg->span->span_id].context, + sigmsg->dnis); + assert(tech_pvt->caller_profile != NULL); + + snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); + switch_channel_set_name(channel, name); + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + + switch_channel_set_state(channel, CS_INIT); + if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); + switch_core_session_destroy(&session); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + return ZAP_SUCCESS; + } + + //zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING); + + break; + default: + break; + } + + return ZAP_SUCCESS; +} + + + +static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) +{ + char *data = NULL; + va_list ap; + + va_start(ap, fmt); + + if (switch_vasprintf(&data, fmt, ap) != -1) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, data); + free(data); + } + + va_end(ap); + +} + +static switch_status_t load_config(void) +{ + char *cf = "openzap.conf"; + switch_xml_t cfg, xml, settings, param, spans, span; + + memset(&globals, 0, sizeof(globals)); + switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); + if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); + return SWITCH_STATUS_TERM; + } + + if ((settings = switch_xml_child(cfg, "settings"))) { + for (param = switch_xml_child(settings, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "debug")) { + globals.debug = atoi(val); + } + } + } + + if ((spans = switch_xml_child(cfg, "analog_spans"))) { + for (span = switch_xml_child(spans, "span"); span; span = span->next) { + char *mod = (char *) switch_xml_attr_soft(span, "module"); + char *id = (char *) switch_xml_attr_soft(span, "id"); + char *context = "default"; + char *dialplan = "XML"; + char *tonegroup = NULL; + char *digit_timeout = NULL; + char *max_digits = NULL; + uint32_t span_id = 0, to = 0, max = 0; + zap_span_t *span = NULL; + + for (param = switch_xml_child(span, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "digit_timeout")) { + digit_timeout = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "max_digits")) { + digit_timeout = val; + } + } + + if (!mod) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'module'\n"); + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (digit_timeout) { + to = atoi(digit_timeout); + } + + if (max_digits) { + max = atoi(max_digits); + } + + if (zap_span_find(mod, span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s:%d\n", mod, span_id); + continue; + } + + if (zap_analog_configure_span(span, tonegroup, to, max, span->trunk_type == ZAP_TRUNK_FXS ? on_fxs_signal : on_fxo_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %s:%d\n", mod, span_id); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + + + zap_analog_start(span); + } + } + + + switch_xml_free(xml); + + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename) +{ + + if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n"); + return SWITCH_STATUS_TERM; + } + + zap_global_set_logger(zap_logger); + + if (zap_global_init() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); + return SWITCH_STATUS_TERM; + } + + if (load_config() != SWITCH_STATUS_SUCCESS) { + zap_global_destroy(); + return SWITCH_STATUS_TERM; + } + + /* connect my internal structure to the blank pointer passed to me */ + *module_interface = &channel_module_interface; + + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; +} + + + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ From b06e0aeea2decb117d582e5b411c30df8945587a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:58:35 +0000 Subject: [PATCH 0317/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@159 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 16 +- libs/openzap/src/priserver.c | 316 +++++++++++++++++++++++++++++++++ libs/openzap/src/sangoma_pri.c | 240 +++++++++++++++++++++++++ libs/openzap/src/sangoma_pri.h | 100 +++++++++++ 4 files changed, 667 insertions(+), 5 deletions(-) create mode 100644 libs/openzap/src/priserver.c create mode 100644 libs/openzap/src/sangoma_pri.c create mode 100644 libs/openzap/src/sangoma_pri.h diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 1c04d82ba0..1fdd40748b 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -65,7 +65,9 @@ PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a -TMP=-I../libpri-1.2.4 -I$(SRC)/include -I./src -w +LIBPRIA=libpri.a +LIBPRI=./libpri +TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w include general.makefile $(ZAP_MODS) @@ -84,14 +86,17 @@ testisdn: $(SRC)/testisdn.c $(MYLIB) testanalog: $(SRC)/testanalog.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread -priserver.o: $(SRC)/priserver.c +$(SRC)/priserver.o: $(SRC)/priserver.c $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o $(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a +$(LIBPRI)/$(LIBPRIA): + cd libpri && make + +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ @@ -117,8 +122,9 @@ mod_openzap-install: mod_openzap cd mod_openzap && make install mod_openzap-clean: - cd mod_openzap && make clean + @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog + @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c new file mode 100644 index 0000000000..5612e19a15 --- /dev/null +++ b/libs/openzap/src/priserver.c @@ -0,0 +1,316 @@ +/***************************************************************************** + * priserver.c Refactoring of pritest.c + * + * Author(s): Anthony Minessale II + * Nenad Corbic + * + * Copyright: (c) 2005 Anthony Minessale II + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * ============================================================================ + */ + +#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("wanpipe", 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_TONE_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, &len); + } else { + printf("BREAK"); + break; + } + } + + printf("loop done\n"); + + //sangoma_get_full_cfg(fd, &tdm_api); + close(file); + //close(ifd); + + + 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"); + + + + 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; +} + diff --git a/libs/openzap/src/sangoma_pri.c b/libs/openzap/src/sangoma_pri.c new file mode 100644 index 0000000000..b4692216d0 --- /dev/null +++ b/libs/openzap/src/sangoma_pri.c @@ -0,0 +1,240 @@ +/***************************************************************************** + * sangoma_pri.c libpri Sangoma integration + * + * Author(s): Anthony Minessale II + * Nenad Corbic + * + * Copyright: (c) 2005 Anthony Minessale II + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * ============================================================================ + */ + +#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); + 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, &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); + 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("wanpipe", 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; + +} + diff --git a/libs/openzap/src/sangoma_pri.h b/libs/openzap/src/sangoma_pri.h new file mode 100644 index 0000000000..5ea21eb7b5 --- /dev/null +++ b/libs/openzap/src/sangoma_pri.h @@ -0,0 +1,100 @@ +/***************************************************************************** + * libsangoma.c AFT T1/E1: HDLC API Code Library + * + * Author(s): Anthony Minessale II + * Nenad Corbic + * + * Copyright: (c) 2005 Anthony Minessale II + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * ============================================================================ + */ + +#ifndef _SANGOMA_PRI_H +#define _SANGOMA_PRI_H +#include +#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 From 0f4848dca439aed94cc00d858c0361f225360f84 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 04:58:35 +0000 Subject: [PATCH 0318/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@159 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 16 +- libs/freetdm/src/priserver.c | 316 +++++++++++++++++++++++++++++++++ libs/freetdm/src/sangoma_pri.c | 240 +++++++++++++++++++++++++ libs/freetdm/src/sangoma_pri.h | 100 +++++++++++ 4 files changed, 667 insertions(+), 5 deletions(-) create mode 100644 libs/freetdm/src/priserver.c create mode 100644 libs/freetdm/src/sangoma_pri.c create mode 100644 libs/freetdm/src/sangoma_pri.h diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 1c04d82ba0..1fdd40748b 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -65,7 +65,9 @@ PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a -TMP=-I../libpri-1.2.4 -I$(SRC)/include -I./src -w +LIBPRIA=libpri.a +LIBPRI=./libpri +TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w include general.makefile $(ZAP_MODS) @@ -84,14 +86,17 @@ testisdn: $(SRC)/testisdn.c $(MYLIB) testanalog: $(SRC)/testanalog.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread -priserver.o: $(SRC)/priserver.c +$(SRC)/priserver.o: $(SRC)/priserver.c $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o $(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread ../../libpri-1.2.4/libpri.a +$(LIBPRI)/$(LIBPRIA): + cd libpri && make + +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ @@ -117,8 +122,9 @@ mod_openzap-install: mod_openzap cd mod_openzap && make install mod_openzap-clean: - cd mod_openzap && make clean + @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog + @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c new file mode 100644 index 0000000000..5612e19a15 --- /dev/null +++ b/libs/freetdm/src/priserver.c @@ -0,0 +1,316 @@ +/***************************************************************************** + * priserver.c Refactoring of pritest.c + * + * Author(s): Anthony Minessale II + * Nenad Corbic + * + * Copyright: (c) 2005 Anthony Minessale II + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * ============================================================================ + */ + +#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("wanpipe", 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_TONE_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, &len); + } else { + printf("BREAK"); + break; + } + } + + printf("loop done\n"); + + //sangoma_get_full_cfg(fd, &tdm_api); + close(file); + //close(ifd); + + + 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"); + + + + 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; +} + diff --git a/libs/freetdm/src/sangoma_pri.c b/libs/freetdm/src/sangoma_pri.c new file mode 100644 index 0000000000..b4692216d0 --- /dev/null +++ b/libs/freetdm/src/sangoma_pri.c @@ -0,0 +1,240 @@ +/***************************************************************************** + * sangoma_pri.c libpri Sangoma integration + * + * Author(s): Anthony Minessale II + * Nenad Corbic + * + * Copyright: (c) 2005 Anthony Minessale II + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * ============================================================================ + */ + +#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); + 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, &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); + 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("wanpipe", 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; + +} + diff --git a/libs/freetdm/src/sangoma_pri.h b/libs/freetdm/src/sangoma_pri.h new file mode 100644 index 0000000000..5ea21eb7b5 --- /dev/null +++ b/libs/freetdm/src/sangoma_pri.h @@ -0,0 +1,100 @@ +/***************************************************************************** + * libsangoma.c AFT T1/E1: HDLC API Code Library + * + * Author(s): Anthony Minessale II + * Nenad Corbic + * + * Copyright: (c) 2005 Anthony Minessale II + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * ============================================================================ + */ + +#ifndef _SANGOMA_PRI_H +#define _SANGOMA_PRI_H +#include +#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 From 02be5554d1cfd491ceab442ef96bde88a3143aae Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 16:28:46 +0000 Subject: [PATCH 0319/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@160 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/{src => }/openzap.conf.ex | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/{src => }/openzap.conf.ex (100%) diff --git a/libs/openzap/src/openzap.conf.ex b/libs/openzap/openzap.conf.ex similarity index 100% rename from libs/openzap/src/openzap.conf.ex rename to libs/openzap/openzap.conf.ex From 4d6372b31eee6c2bd9c9c04016cd9b833b79783b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 May 2007 16:28:46 +0000 Subject: [PATCH 0320/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@160 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/{src => }/openzap.conf.ex | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/{src => }/openzap.conf.ex (100%) diff --git a/libs/freetdm/src/openzap.conf.ex b/libs/freetdm/openzap.conf.ex similarity index 100% rename from libs/freetdm/src/openzap.conf.ex rename to libs/freetdm/openzap.conf.ex From 8377f1b192142189b02b7941ecaf4c86d59a0bee Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 04:42:10 +0000 Subject: [PATCH 0321/1766] update windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@161 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 467 ++++++++++++++++++ .../openzap/msvc/testanalog/testanalog.vcproj | 189 +++++++ libs/openzap/msvc/testisdn/testisdn.vcproj | 189 +++++++ libs/openzap/openzap.sln | 46 ++ libs/openzap/openzap.vcproj | 447 ----------------- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/testanalog.c | 5 +- libs/openzap/src/testisdn.c | 2 +- libs/openzap/src/zap_analog.c | 4 +- 9 files changed, 899 insertions(+), 451 deletions(-) create mode 100644 libs/openzap/msvc/openzap.vcproj create mode 100644 libs/openzap/msvc/testanalog/testanalog.vcproj create mode 100644 libs/openzap/msvc/testisdn/testisdn.vcproj create mode 100644 libs/openzap/openzap.sln delete mode 100644 libs/openzap/openzap.vcproj diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj new file mode 100644 index 0000000000..f4917c18a3 --- /dev/null +++ b/libs/openzap/msvc/openzap.vcproj @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/testanalog/testanalog.vcproj b/libs/openzap/msvc/testanalog/testanalog.vcproj new file mode 100644 index 0000000000..df5ccd2fba --- /dev/null +++ b/libs/openzap/msvc/testanalog/testanalog.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/testisdn/testisdn.vcproj b/libs/openzap/msvc/testisdn/testisdn.vcproj new file mode 100644 index 0000000000..dac179de1a --- /dev/null +++ b/libs/openzap/msvc/testisdn/testisdn.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/openzap.sln b/libs/openzap/openzap.sln new file mode 100644 index 0000000000..873dd25d72 --- /dev/null +++ b/libs/openzap/openzap.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unix Makefiles", "Unix Makefiles", "{214C60D6-6E30-4912-B919-DB76A20CC682}" + ProjectSection(SolutionItems) = preProject + general.makefile = general.makefile + Makefile = Makefile + wanpipe = wanpipe + zt = zt + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.ActiveCfg = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.Build.0 = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.ActiveCfg = Release|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.Build.0 = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.ActiveCfg = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.Build.0 = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.ActiveCfg = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.Build.0 = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.ActiveCfg = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/openzap/openzap.vcproj b/libs/openzap/openzap.vcproj deleted file mode 100644 index aaacf7578b..0000000000 --- a/libs/openzap/openzap.vcproj +++ /dev/null @@ -1,447 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index db2c3ba5d4..3475997c50 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -74,6 +74,7 @@ /* disable warning for zero length array in a struct */ /* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ #pragma warning(disable:4706) +#pragma comment(lib, "Winmm") #endif #define ZAP_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 9670564348..82e9e8df89 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -9,7 +9,7 @@ static void *test_call(zap_thread_t *me, void *obj) zap_size_t len; - sleep(10); + zap_sleep(10 * 1000); zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n"); @@ -38,6 +38,7 @@ static void *test_call(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "call over\n"); + return 0; } static ZIO_SIGNAL_CB_FUNCTION(on_signal) @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { - sleep(1); + zap_sleep(1 * 1000); } zap_global_destroy(); diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 78f3e18a41..d268436eb5 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) } while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { - sleep(1); + zap_sleep(1 * 1000); } done: diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 21702cafed..0377fc4ad9 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -88,7 +88,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_size_t len, rlen; zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128]; - int dtmf_offset = 0; + zap_size_t dtmf_offset = 0; zap_analog_data_t *data = chan->span->analog_data; zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; @@ -97,6 +97,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); + ts.buffer = NULL; + if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { goto done; } From 0d228c71f4d60b8584ba5a7f11e45344adb6f574 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 04:42:10 +0000 Subject: [PATCH 0322/1766] update windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@161 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 467 ++++++++++++++++++ .../freetdm/msvc/testanalog/testanalog.vcproj | 189 +++++++ libs/freetdm/msvc/testisdn/testisdn.vcproj | 189 +++++++ libs/freetdm/openzap.sln | 46 ++ libs/freetdm/openzap.vcproj | 447 ----------------- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/testanalog.c | 5 +- libs/freetdm/src/testisdn.c | 2 +- libs/freetdm/src/zap_analog.c | 4 +- 9 files changed, 899 insertions(+), 451 deletions(-) create mode 100644 libs/freetdm/msvc/openzap.vcproj create mode 100644 libs/freetdm/msvc/testanalog/testanalog.vcproj create mode 100644 libs/freetdm/msvc/testisdn/testisdn.vcproj create mode 100644 libs/freetdm/openzap.sln delete mode 100644 libs/freetdm/openzap.vcproj diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj new file mode 100644 index 0000000000..f4917c18a3 --- /dev/null +++ b/libs/freetdm/msvc/openzap.vcproj @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testanalog/testanalog.vcproj b/libs/freetdm/msvc/testanalog/testanalog.vcproj new file mode 100644 index 0000000000..df5ccd2fba --- /dev/null +++ b/libs/freetdm/msvc/testanalog/testanalog.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testisdn/testisdn.vcproj b/libs/freetdm/msvc/testisdn/testisdn.vcproj new file mode 100644 index 0000000000..dac179de1a --- /dev/null +++ b/libs/freetdm/msvc/testisdn/testisdn.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/openzap.sln b/libs/freetdm/openzap.sln new file mode 100644 index 0000000000..873dd25d72 --- /dev/null +++ b/libs/freetdm/openzap.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unix Makefiles", "Unix Makefiles", "{214C60D6-6E30-4912-B919-DB76A20CC682}" + ProjectSection(SolutionItems) = preProject + general.makefile = general.makefile + Makefile = Makefile + wanpipe = wanpipe + zt = zt + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.ActiveCfg = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.Build.0 = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.ActiveCfg = Release|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.Build.0 = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.ActiveCfg = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.Build.0 = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.ActiveCfg = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.Build.0 = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.ActiveCfg = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/freetdm/openzap.vcproj b/libs/freetdm/openzap.vcproj deleted file mode 100644 index aaacf7578b..0000000000 --- a/libs/freetdm/openzap.vcproj +++ /dev/null @@ -1,447 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index db2c3ba5d4..3475997c50 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -74,6 +74,7 @@ /* disable warning for zero length array in a struct */ /* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ #pragma warning(disable:4706) +#pragma comment(lib, "Winmm") #endif #define ZAP_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 9670564348..82e9e8df89 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -9,7 +9,7 @@ static void *test_call(zap_thread_t *me, void *obj) zap_size_t len; - sleep(10); + zap_sleep(10 * 1000); zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n"); @@ -38,6 +38,7 @@ static void *test_call(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "call over\n"); + return 0; } static ZIO_SIGNAL_CB_FUNCTION(on_signal) @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { - sleep(1); + zap_sleep(1 * 1000); } zap_global_destroy(); diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 78f3e18a41..d268436eb5 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) } while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { - sleep(1); + zap_sleep(1 * 1000); } done: diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 21702cafed..0377fc4ad9 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -88,7 +88,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_size_t len, rlen; zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128]; - int dtmf_offset = 0; + zap_size_t dtmf_offset = 0; zap_analog_data_t *data = chan->span->analog_data; zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; @@ -97,6 +97,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); + ts.buffer = NULL; + if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { goto done; } From 1fcd860d739eb79fed35d6cd8af3d52cdefe63f5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 05:23:28 +0000 Subject: [PATCH 0323/1766] windows build for mod_openzap. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@162 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 +- libs/openzap/mod_openzap/mod_openzap.vcproj | 201 ++++++++++++++++++ .../openzap/msvc/testanalog/testanalog.vcproj | 6 +- libs/openzap/msvc/testisdn/testisdn.vcproj | 6 +- libs/openzap/openzap.sln | 9 + 5 files changed, 225 insertions(+), 14 deletions(-) create mode 100644 libs/openzap/mod_openzap/mod_openzap.vcproj diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ffdab55b1f..27ca737669 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -338,7 +338,6 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf) { private_t *tech_pvt = NULL; - char *digit; tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); @@ -352,9 +351,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - zap_size_t len; + uint32_t len; zap_wait_flag_t wflags = ZAP_READ; - uint8_t dtmf[128] = ""; + char dtmf[128] = ""; zap_status_t status; channel = switch_core_session_get_channel(session); @@ -509,8 +508,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi private_t *tech_pvt; switch_channel_t *channel; switch_caller_profile_t *caller_profile; - unsigned int req = 0, cap = 0; - unsigned short samprate = 0; switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { @@ -637,7 +634,7 @@ static void zap_logger(char *file, const char *func, int line, int level, char * static switch_status_t load_config(void) { char *cf = "openzap.conf"; - switch_xml_t cfg, xml, settings, param, spans, span; + switch_xml_t cfg, xml, settings, param, spans, myspan; memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); @@ -658,9 +655,9 @@ static switch_status_t load_config(void) } if ((spans = switch_xml_child(cfg, "analog_spans"))) { - for (span = switch_xml_child(spans, "span"); span; span = span->next) { - char *mod = (char *) switch_xml_attr_soft(span, "module"); - char *id = (char *) switch_xml_attr_soft(span, "id"); + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *mod = (char *) switch_xml_attr_soft(myspan, "module"); + char *id = (char *) switch_xml_attr_soft(myspan, "id"); char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -669,7 +666,7 @@ static switch_status_t load_config(void) uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; - for (param = switch_xml_child(span, "param"); param; param = param->next) { + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); diff --git a/libs/openzap/mod_openzap/mod_openzap.vcproj b/libs/openzap/mod_openzap/mod_openzap.vcproj new file mode 100644 index 0000000000..a1ebe71e9a --- /dev/null +++ b/libs/openzap/mod_openzap/mod_openzap.vcproj @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/testanalog/testanalog.vcproj b/libs/openzap/msvc/testanalog/testanalog.vcproj index df5ccd2fba..7f762fe4ad 100644 --- a/libs/openzap/msvc/testanalog/testanalog.vcproj +++ b/libs/openzap/msvc/testanalog/testanalog.vcproj @@ -47,7 +47,8 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> @@ -122,7 +123,8 @@ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="2" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> diff --git a/libs/openzap/msvc/testisdn/testisdn.vcproj b/libs/openzap/msvc/testisdn/testisdn.vcproj index dac179de1a..cce13b7653 100644 --- a/libs/openzap/msvc/testisdn/testisdn.vcproj +++ b/libs/openzap/msvc/testisdn/testisdn.vcproj @@ -47,7 +47,8 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> @@ -122,7 +123,8 @@ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="2" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> diff --git a/libs/openzap/openzap.sln b/libs/openzap/openzap.sln index 873dd25d72..ab53115d35 100644 --- a/libs/openzap/openzap.sln +++ b/libs/openzap/openzap.sln @@ -21,6 +21,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\t {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -39,6 +44,10 @@ Global {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.ActiveCfg = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From f26e35023c960c7e7dba3318cde0e5043940952a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 05:23:28 +0000 Subject: [PATCH 0324/1766] windows build for mod_openzap. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@162 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 17 +- libs/freetdm/mod_openzap/mod_openzap.vcproj | 201 ++++++++++++++++++ .../freetdm/msvc/testanalog/testanalog.vcproj | 6 +- libs/freetdm/msvc/testisdn/testisdn.vcproj | 6 +- libs/freetdm/openzap.sln | 9 + 5 files changed, 225 insertions(+), 14 deletions(-) create mode 100644 libs/freetdm/mod_openzap/mod_openzap.vcproj diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ffdab55b1f..27ca737669 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -338,7 +338,6 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf) { private_t *tech_pvt = NULL; - char *digit; tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); @@ -352,9 +351,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - zap_size_t len; + uint32_t len; zap_wait_flag_t wflags = ZAP_READ; - uint8_t dtmf[128] = ""; + char dtmf[128] = ""; zap_status_t status; channel = switch_core_session_get_channel(session); @@ -509,8 +508,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi private_t *tech_pvt; switch_channel_t *channel; switch_caller_profile_t *caller_profile; - unsigned int req = 0, cap = 0; - unsigned short samprate = 0; switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { @@ -637,7 +634,7 @@ static void zap_logger(char *file, const char *func, int line, int level, char * static switch_status_t load_config(void) { char *cf = "openzap.conf"; - switch_xml_t cfg, xml, settings, param, spans, span; + switch_xml_t cfg, xml, settings, param, spans, myspan; memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); @@ -658,9 +655,9 @@ static switch_status_t load_config(void) } if ((spans = switch_xml_child(cfg, "analog_spans"))) { - for (span = switch_xml_child(spans, "span"); span; span = span->next) { - char *mod = (char *) switch_xml_attr_soft(span, "module"); - char *id = (char *) switch_xml_attr_soft(span, "id"); + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *mod = (char *) switch_xml_attr_soft(myspan, "module"); + char *id = (char *) switch_xml_attr_soft(myspan, "id"); char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -669,7 +666,7 @@ static switch_status_t load_config(void) uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; - for (param = switch_xml_child(span, "param"); param; param = param->next) { + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); diff --git a/libs/freetdm/mod_openzap/mod_openzap.vcproj b/libs/freetdm/mod_openzap/mod_openzap.vcproj new file mode 100644 index 0000000000..a1ebe71e9a --- /dev/null +++ b/libs/freetdm/mod_openzap/mod_openzap.vcproj @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testanalog/testanalog.vcproj b/libs/freetdm/msvc/testanalog/testanalog.vcproj index df5ccd2fba..7f762fe4ad 100644 --- a/libs/freetdm/msvc/testanalog/testanalog.vcproj +++ b/libs/freetdm/msvc/testanalog/testanalog.vcproj @@ -47,7 +47,8 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> @@ -122,7 +123,8 @@ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="2" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> diff --git a/libs/freetdm/msvc/testisdn/testisdn.vcproj b/libs/freetdm/msvc/testisdn/testisdn.vcproj index dac179de1a..cce13b7653 100644 --- a/libs/freetdm/msvc/testisdn/testisdn.vcproj +++ b/libs/freetdm/msvc/testisdn/testisdn.vcproj @@ -47,7 +47,8 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> @@ -122,7 +123,8 @@ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="2" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> diff --git a/libs/freetdm/openzap.sln b/libs/freetdm/openzap.sln index 873dd25d72..ab53115d35 100644 --- a/libs/freetdm/openzap.sln +++ b/libs/freetdm/openzap.sln @@ -21,6 +21,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\t {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -39,6 +44,10 @@ Global {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.ActiveCfg = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 23b3c6936e393d8c62cea74068d711416b932a97 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 27 May 2007 14:58:01 +0000 Subject: [PATCH 0325/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@163 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 218 +++++++++++++++---------- libs/openzap/src/include/openzap.h | 6 +- libs/openzap/src/include/zap_types.h | 3 +- libs/openzap/src/zap_analog.c | 7 + libs/openzap/src/zap_io.c | 12 ++ 6 files changed, 162 insertions(+), 86 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 1fdd40748b..f5cbeee8ab 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -113,7 +113,7 @@ $(SRC)/zap_zt.o: $(SRC)/zap_zt.c dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf -mod_openzap/mod_openzap.so: $(MYLIB) +mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c cd mod_openzap && make mod_openzap: mod_openzap/mod_openzap.so diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 27ca737669..72060facba 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -47,20 +47,14 @@ struct span_config { static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; - typedef enum { TFLAG_IO = (1 << 0), - TFLAG_INBOUND = (1 << 1), - TFLAG_OUTBOUND = (1 << 2), - TFLAG_DTMF = (1 << 3), - TFLAG_VOICE = (1 << 4), - TFLAG_HANGUP = (1 << 5), - TFLAG_LINEAR = (1 << 6), - TFLAG_CODEC = (1 << 7), - TFLAG_BREAK = (1 << 8) + TFLAG_OUTBOUND = (1 << 1), + TFLAG_DTMF = (1 << 2), + TFLAG_CODEC = (1 << 3), + TFLAG_BREAK = (1 << 4) } TFLAGS; - static struct { int debug; char *dialplan; @@ -247,13 +241,26 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - switch_clear_flag_locked(tech_pvt, TFLAG_IO); - switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + zap_channel_set_token(tech_pvt->zchan, NULL); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); + switch (tech_pvt->zchan->type) { + case ZAP_CHAN_TYPE_FXO: + case ZAP_CHAN_TYPE_FXS: + { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); + } + break; } + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + if (tech_pvt->read_codec.implementation) { switch_core_codec_destroy(&tech_pvt->read_codec); } @@ -287,10 +294,6 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int switch (sig) { case SWITCH_SIG_KILL: switch_clear_flag_locked(tech_pvt, TFLAG_IO); - switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); - } break; case SWITCH_SIG_BREAK: switch_set_flag_locked(tech_pvt, TFLAG_BREAK); @@ -364,8 +367,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { - return SWITCH_STATUS_GENERR; + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { + return SWITCH_STATUS_FALSE; } status = zap_channel_wait(tech_pvt->zchan, &wflags, timeout); @@ -417,10 +420,6 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc assert(tech_pvt->zchan != NULL); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { - return SWITCH_STATUS_GENERR; - } - if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } @@ -545,75 +544,130 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } -static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) -{ - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); - return ZAP_SUCCESS; -} -static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp) { switch_core_session_t *session = NULL; private_t *tech_pvt = NULL; switch_channel_t *channel = NULL; char name[128]; - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); - switch(sigmsg->event_id) { - case ZAP_SIGEVENT_START: - if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); - return ZAP_SUCCESS; - } + *sp = NULL; + + if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + return ZAP_FAIL; + } + + switch_core_session_add_stream(session, NULL); + + tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t)); + assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); + switch_core_session_destroy(&session); + return ZAP_FAIL; + } + + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), + "OpenZAP", + SPAN_CONFIG[sigmsg->span->span_id].dialplan, + sigmsg->channel->chan_name, + sigmsg->channel->chan_number, + NULL, + sigmsg->channel->chan_number, + NULL, + NULL, + (char *) modname, + SPAN_CONFIG[sigmsg->span->span_id].context, + sigmsg->dnis); + assert(tech_pvt->caller_profile != NULL); + + snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); + switch_channel_set_name(channel, name); + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + + switch_channel_set_state(channel, CS_INIT); + if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); + switch_core_session_destroy(&session); + return ZAP_FAIL; + } - switch_core_session_add_stream(session, NULL); - - tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t)); - assert(tech_pvt != NULL); - channel = switch_core_session_get_channel(session); - if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); - switch_core_session_destroy(&session); - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); - return ZAP_SUCCESS; - } - - tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), - "OpenZAP", - SPAN_CONFIG[sigmsg->span->span_id].dialplan, - sigmsg->channel->chan_name, - sigmsg->channel->chan_number, - NULL, - sigmsg->channel->chan_number, - NULL, - NULL, - (char *) modname, - SPAN_CONFIG[sigmsg->span->span_id].context, - sigmsg->dnis); - assert(tech_pvt->caller_profile != NULL); - - snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); - switch_channel_set_name(channel, name); - switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - - switch_channel_set_state(channel, CS_INIT); - if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); - switch_core_session_destroy(&session); - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); - return ZAP_SUCCESS; - } - - //zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING); - - break; - default: - break; - } + switch_copy_string(sigmsg->channel->token, switch_core_session_get_uuid(session), sizeof(sigmsg->channel->token)); + *sp = session; return ZAP_SUCCESS; } +static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) +{ + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + return ZAP_SUCCESS; +} +static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +{ + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + zap_status_t status; + int rwlock = 0; + + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + if (!switch_strlen_zero(sigmsg->channel->token)) { + if ((session = switch_core_session_locate(sigmsg->channel->token))) { + channel = switch_core_session_get_channel(session); + rwlock++; + } + } + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + { + status = zap_channel_from_event(sigmsg, &session); + if (status != ZAP_SUCCESS) { + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + } + } + break; + case ZAP_SIGEVENT_STOP: + { + if (channel) { + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + zap_channel_set_token(sigmsg->channel, NULL); + } + } + break; + } + + if (session && rwlock) { + switch_core_session_rwunlock(session); + } + + return status; +} + +static ZIO_SIGNAL_CB_FUNCTION(on_zap_signal) +{ + switch (sigmsg->channel->type) { + case ZAP_CHAN_TYPE_FXO: + { + on_fxo_signal(sigmsg); + } + break; + case ZAP_CHAN_TYPE_FXS: + { + on_fxs_signal(sigmsg); + } + break; + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } +} static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) { @@ -710,7 +764,7 @@ static switch_status_t load_config(void) continue; } - if (zap_analog_configure_span(span, tonegroup, to, max, span->trunk_type == ZAP_TRUNK_FXS ? on_fxs_signal : on_fxo_signal) != ZAP_SUCCESS) { + if (zap_analog_configure_span(span, tonegroup, to, max, on_zap_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %s:%d\n", mod, span_id); continue; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3475997c50..a4e24f2394 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -245,8 +245,9 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; - char chan_name[80]; - char chan_number[25]; + char token[128]; + char chan_name[128]; + char chan_number[32]; struct zap_span *span; struct zap_io_interface *zio; }; @@ -321,6 +322,7 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; +zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index cf1b25cf76..236217278f 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -192,6 +192,7 @@ typedef enum { typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_UP, + ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_COLLECT, ZAP_CHANNEL_STATE_RING, @@ -200,7 +201,7 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 0377fc4ad9..3032e0200b 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -145,6 +145,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } break; + case ZAP_CHANNEL_STATE_HANGUP: + { + if (state_counter > 2000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + } + break; case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index eff007f119..1c3da3c2c7 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -370,6 +370,18 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } +zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token) +{ + zap_mutex_lock(zchan->mutex); + if (token) { + zap_copy_string(zchan->token, token, sizeof(zchan->token)); + } else { + *zchan->token = '\0'; + } + zap_mutex_unlock(zchan->mutex); + return ZAP_SUCCESS; +} + zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) { From 3f6d31484ac119f05e8cf516bd6ca819629ec3f0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 27 May 2007 14:58:01 +0000 Subject: [PATCH 0326/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@163 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 218 +++++++++++++++---------- libs/freetdm/src/include/openzap.h | 6 +- libs/freetdm/src/include/zap_types.h | 3 +- libs/freetdm/src/zap_analog.c | 7 + libs/freetdm/src/zap_io.c | 12 ++ 6 files changed, 162 insertions(+), 86 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 1fdd40748b..f5cbeee8ab 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -113,7 +113,7 @@ $(SRC)/zap_zt.o: $(SRC)/zap_zt.c dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf -mod_openzap/mod_openzap.so: $(MYLIB) +mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c cd mod_openzap && make mod_openzap: mod_openzap/mod_openzap.so diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 27ca737669..72060facba 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -47,20 +47,14 @@ struct span_config { static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; - typedef enum { TFLAG_IO = (1 << 0), - TFLAG_INBOUND = (1 << 1), - TFLAG_OUTBOUND = (1 << 2), - TFLAG_DTMF = (1 << 3), - TFLAG_VOICE = (1 << 4), - TFLAG_HANGUP = (1 << 5), - TFLAG_LINEAR = (1 << 6), - TFLAG_CODEC = (1 << 7), - TFLAG_BREAK = (1 << 8) + TFLAG_OUTBOUND = (1 << 1), + TFLAG_DTMF = (1 << 2), + TFLAG_CODEC = (1 << 3), + TFLAG_BREAK = (1 << 4) } TFLAGS; - static struct { int debug; char *dialplan; @@ -247,13 +241,26 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - switch_clear_flag_locked(tech_pvt, TFLAG_IO); - switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + zap_channel_set_token(tech_pvt->zchan, NULL); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); + switch (tech_pvt->zchan->type) { + case ZAP_CHAN_TYPE_FXO: + case ZAP_CHAN_TYPE_FXS: + { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); + } + break; } + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + if (tech_pvt->read_codec.implementation) { switch_core_codec_destroy(&tech_pvt->read_codec); } @@ -287,10 +294,6 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int switch (sig) { case SWITCH_SIG_KILL: switch_clear_flag_locked(tech_pvt, TFLAG_IO); - switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_BUSY); - } break; case SWITCH_SIG_BREAK: switch_set_flag_locked(tech_pvt, TFLAG_BREAK); @@ -364,8 +367,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { - return SWITCH_STATUS_GENERR; + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { + return SWITCH_STATUS_FALSE; } status = zap_channel_wait(tech_pvt->zchan, &wflags, timeout); @@ -417,10 +420,6 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc assert(tech_pvt->zchan != NULL); - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_UP) { - return SWITCH_STATUS_GENERR; - } - if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } @@ -545,75 +544,130 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } -static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) -{ - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); - return ZAP_SUCCESS; -} -static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp) { switch_core_session_t *session = NULL; private_t *tech_pvt = NULL; switch_channel_t *channel = NULL; char name[128]; - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); - switch(sigmsg->event_id) { - case ZAP_SIGEVENT_START: - if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); - return ZAP_SUCCESS; - } + *sp = NULL; + + if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + return ZAP_FAIL; + } + + switch_core_session_add_stream(session, NULL); + + tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t)); + assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); + switch_core_session_destroy(&session); + return ZAP_FAIL; + } + + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), + "OpenZAP", + SPAN_CONFIG[sigmsg->span->span_id].dialplan, + sigmsg->channel->chan_name, + sigmsg->channel->chan_number, + NULL, + sigmsg->channel->chan_number, + NULL, + NULL, + (char *) modname, + SPAN_CONFIG[sigmsg->span->span_id].context, + sigmsg->dnis); + assert(tech_pvt->caller_profile != NULL); + + snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); + switch_channel_set_name(channel, name); + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + + switch_channel_set_state(channel, CS_INIT); + if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); + switch_core_session_destroy(&session); + return ZAP_FAIL; + } - switch_core_session_add_stream(session, NULL); - - tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t)); - assert(tech_pvt != NULL); - channel = switch_core_session_get_channel(session); - if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); - switch_core_session_destroy(&session); - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); - return ZAP_SUCCESS; - } - - tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), - "OpenZAP", - SPAN_CONFIG[sigmsg->span->span_id].dialplan, - sigmsg->channel->chan_name, - sigmsg->channel->chan_number, - NULL, - sigmsg->channel->chan_number, - NULL, - NULL, - (char *) modname, - SPAN_CONFIG[sigmsg->span->span_id].context, - sigmsg->dnis); - assert(tech_pvt->caller_profile != NULL); - - snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); - switch_channel_set_name(channel, name); - switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - - switch_channel_set_state(channel, CS_INIT); - if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); - switch_core_session_destroy(&session); - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); - return ZAP_SUCCESS; - } - - //zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING); - - break; - default: - break; - } + switch_copy_string(sigmsg->channel->token, switch_core_session_get_uuid(session), sizeof(sigmsg->channel->token)); + *sp = session; return ZAP_SUCCESS; } +static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) +{ + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + return ZAP_SUCCESS; +} +static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +{ + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + zap_status_t status; + int rwlock = 0; + + zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + if (!switch_strlen_zero(sigmsg->channel->token)) { + if ((session = switch_core_session_locate(sigmsg->channel->token))) { + channel = switch_core_session_get_channel(session); + rwlock++; + } + } + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + { + status = zap_channel_from_event(sigmsg, &session); + if (status != ZAP_SUCCESS) { + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + } + } + break; + case ZAP_SIGEVENT_STOP: + { + if (channel) { + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + zap_channel_set_token(sigmsg->channel, NULL); + } + } + break; + } + + if (session && rwlock) { + switch_core_session_rwunlock(session); + } + + return status; +} + +static ZIO_SIGNAL_CB_FUNCTION(on_zap_signal) +{ + switch (sigmsg->channel->type) { + case ZAP_CHAN_TYPE_FXO: + { + on_fxo_signal(sigmsg); + } + break; + case ZAP_CHAN_TYPE_FXS: + { + on_fxs_signal(sigmsg); + } + break; + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } +} static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) { @@ -710,7 +764,7 @@ static switch_status_t load_config(void) continue; } - if (zap_analog_configure_span(span, tonegroup, to, max, span->trunk_type == ZAP_TRUNK_FXS ? on_fxs_signal : on_fxo_signal) != ZAP_SUCCESS) { + if (zap_analog_configure_span(span, tonegroup, to, max, on_zap_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %s:%d\n", mod, span_id); continue; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 3475997c50..a4e24f2394 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -245,8 +245,9 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; - char chan_name[80]; - char chan_number[25]; + char token[128]; + char chan_name[128]; + char chan_number[32]; struct zap_span *span; struct zap_io_interface *zio; }; @@ -321,6 +322,7 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; +zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index cf1b25cf76..236217278f 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -192,6 +192,7 @@ typedef enum { typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_UP, + ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_COLLECT, ZAP_CHANNEL_STATE_RING, @@ -200,7 +201,7 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 0377fc4ad9..3032e0200b 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -145,6 +145,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } break; + case ZAP_CHANNEL_STATE_HANGUP: + { + if (state_counter > 2000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + } + break; case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index eff007f119..1c3da3c2c7 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -370,6 +370,18 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } +zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token) +{ + zap_mutex_lock(zchan->mutex); + if (token) { + zap_copy_string(zchan->token, token, sizeof(zchan->token)); + } else { + *zchan->token = '\0'; + } + zap_mutex_unlock(zchan->mutex); + return ZAP_SUCCESS; +} + zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) { From 0c8704da07d0f9f9d14bde19b49f073253fb1808 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 15:01:40 +0000 Subject: [PATCH 0327/1766] Tweak and add some defines. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@164 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 2b5a51700c..83b94df8a8 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -231,17 +231,27 @@ const char *q931_error_to_name(q931_error_t error); /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 4 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ +#define Q931MAXDLCT 4 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ -#define Q931MAXMES 255 /* Number of messages */ +#define Q931MAXMES 128 /* Number of messages */ -#define Q931MAXIE 255 /* Number of IE */ +#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 */ +/***************************************************************************** + + + +*****************************************************************************/ + /***************************************************************************** Call States for ITU-T Q.931 TE (User Mode) From f1ba087a11822be7d8fd42466b2b8ade7ac6e8cd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 15:01:40 +0000 Subject: [PATCH 0328/1766] Tweak and add some defines. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@164 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 2b5a51700c..83b94df8a8 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -231,17 +231,27 @@ const char *q931_error_to_name(q931_error_t error); /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 4 /* Max dialects included in this */ - /* compile. User and Network count as */ - /* one dialect each. */ +#define Q931MAXDLCT 4 /* Max dialects included in this */ + /* compile. User and Network count as */ + /* one dialect each. */ -#define Q931MAXMES 255 /* Number of messages */ +#define Q931MAXMES 128 /* Number of messages */ -#define Q931MAXIE 255 /* Number of IE */ +#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 */ +/***************************************************************************** + + + +*****************************************************************************/ + /***************************************************************************** Call States for ITU-T Q.931 TE (User Mode) From 605f70877f2d2b1afc96e238527101b98067fd94 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 27 May 2007 16:37:52 +0000 Subject: [PATCH 0329/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@165 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 78 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 2f3bf63028..bdc9324c5c 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -75,118 +75,118 @@ void Q931Initialize_MsgieOffset() for(x=0; x Date: Sun, 27 May 2007 16:37:52 +0000 Subject: [PATCH 0330/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@165 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 78 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 2f3bf63028..bdc9324c5c 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -75,118 +75,118 @@ void Q931Initialize_MsgieOffset() for(x=0; x Date: Sun, 27 May 2007 18:14:49 +0000 Subject: [PATCH 0331/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@166 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 93 +++++++++++++++++++++----- libs/openzap/src/include/openzap.h | 11 ++- libs/openzap/src/include/zap_types.h | 11 ++- libs/openzap/src/zap_analog.c | 65 +++++++++++++++--- libs/openzap/src/zap_io.c | 55 +++++++++++++-- 5 files changed, 197 insertions(+), 38 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 72060facba..19530cf755 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -52,7 +52,8 @@ typedef enum { TFLAG_OUTBOUND = (1 << 1), TFLAG_DTMF = (1 << 2), TFLAG_CODEC = (1 << 3), - TFLAG_BREAK = (1 << 4) + TFLAG_BREAK = (1 << 4), + TFLAG_HOLD = (1 << 5) } TFLAGS; static struct { @@ -76,6 +77,8 @@ struct private_object { switch_codec_t write_codec; switch_frame_t read_frame; unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; + switch_frame_t cng_frame; + unsigned char cng_databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; switch_core_session_t *session; switch_caller_profile_t *caller_profile; unsigned int codec; @@ -84,6 +87,7 @@ struct private_object { switch_mutex_t *mutex; switch_mutex_t *flag_mutex; zap_channel_t *zchan; + int32_t token_id; }; typedef struct private_object private_t; @@ -111,6 +115,9 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses tech_pvt->zchan = zchan; tech_pvt->read_frame.data = tech_pvt->databuf; tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); + tech_pvt->cng_frame.data = tech_pvt->cng_databuf; + tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); + memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.buflen); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_core_session_set_private(session, tech_pvt); @@ -241,7 +248,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_channel_set_token(tech_pvt->zchan, NULL); + zap_channel_clear_token(tech_pvt->zchan, tech_pvt->token_id); switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: @@ -367,6 +374,17 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + switch_yield(tech_pvt->zchan->effective_interval * 1000); + *frame = &tech_pvt->cng_frame; + tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; + tech_pvt->cng_frame.samples = tech_pvt->cng_frame.datalen; + if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { + tech_pvt->cng_frame.samples /= 2; + } + return SWITCH_STATUS_SUCCESS; + } + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } @@ -420,6 +438,10 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc assert(tech_pvt->zchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + return SWITCH_STATUS_SUCCESS; + } + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } @@ -593,12 +615,26 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_FAIL; } - switch_copy_string(sigmsg->channel->token, switch_core_session_get_uuid(session), sizeof(sigmsg->channel->token)); + if ((tech_pvt->token_id = zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session))) < 0) { + switch_core_session_destroy(&session); + return ZAP_FAIL; + } *sp = session; return ZAP_SUCCESS; } +static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) +{ + switch_core_session_t *session = NULL; + + if (!switch_strlen_zero(channel->tokens[id])) { + session = switch_core_session_locate(channel->tokens[id]); + } + + return session; +} + static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -609,18 +645,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; zap_status_t status; - int rwlock = 0; zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); - if (!switch_strlen_zero(sigmsg->channel->token)) { - if ((session = switch_core_session_locate(sigmsg->channel->token))) { - channel = switch_core_session_get_channel(session); - rwlock++; - } - } - switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: { @@ -632,16 +661,48 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_STOP: { - if (channel) { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_channel_clear_token(sigmsg->channel, 0); + channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - zap_channel_set_token(sigmsg->channel, NULL); + switch_core_session_rwunlock(session); } } break; - } - if (session && rwlock) { - switch_core_session_rwunlock(session); + case ZAP_SIGEVENT_FLASH: + { + uint32_t i = 0; + for (i = 0; i < sigmsg->channel->token_count; i++) { + if ((session = zap_channel_get_session(sigmsg->channel, i))) { + tech_pvt = switch_core_session_get_private(session); + if (i) { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } + switch_core_session_rwunlock(session); + } + } + } + case ZAP_SIGEVENT_HOLD: + { + if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { + tech_pvt = switch_core_session_get_private(session); + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_UNHOLD: + { + if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { + tech_pvt = switch_core_session_get_private(session); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + switch_core_session_rwunlock(session); + } + } + break; } return status; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index a4e24f2394..3f47bc7a68 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -157,6 +157,7 @@ #define zap_channel_test_feature(obj, flag) ((obj)->features & flag) #define zap_channel_set_feature(obj, flag) (obj)->features |= (flag) #define zap_channel_clear_feature(obj, flag) (obj)->features &= ~(flag) +#define zap_channel_set_member_locked(obj, _m, _v) zap_mutex_lock(obj->mutex); obj->_m = _v; zap_mutex_unlock(obj->mutex) /*! \brief Test for the existance of a flag on an arbitary object @@ -218,6 +219,9 @@ struct zap_event { void *data; }; +#define ZAP_TOKEN_STRLEN 128 +#define ZAP_MAX_TOKENS 10 + struct zap_channel { uint32_t span_id; uint32_t chan_id; @@ -245,7 +249,8 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; - char token[128]; + char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; + uint32_t token_count; char chan_name[128]; char chan_number[32]; struct zap_span *span; @@ -322,7 +327,9 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; -zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token); +void zap_channel_rotate_tokens(zap_channel_t *zchan); +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 236217278f..d1fcb9248d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -101,13 +101,16 @@ typedef enum { ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, ZAP_SIGEVENT_UP, + ZAP_SIGEVENT_HOLD, + ZAP_SIGEVENT_UNHOLD, + ZAP_SIGEVENT_FLASH, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "HOLD", "UNHOLD", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -193,6 +196,7 @@ typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_HANGUP, + ZAP_CHANNEL_STATE_HOLD, ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_COLLECT, ZAP_CHANNEL_STATE_RING, @@ -201,7 +205,7 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -216,7 +220,8 @@ typedef enum { ZAP_CHANNEL_INTHREAD = (1 << 8), ZAP_CHANNEL_WINK = (1 << 9), ZAP_CHANNEL_FLASH = (1 << 10), - ZAP_CHANNEL_STATE_CHANGE = (1 << 11) + ZAP_CHANNEL_STATE_CHANGE = (1 << 11), + ZAP_CHANNEL_HOLD = (1 << 12) } zap_channel_flag_t; diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 3032e0200b..b6314dc339 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -87,7 +87,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_tone_type_t tt = ZAP_TONE_DTMF; - char dtmf[128]; + char dtmf[128] = ""; zap_size_t dtmf_offset = 0; zap_analog_data_t *data = chan->span->analog_data; zap_channel_t *closed_chan; @@ -119,6 +119,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = chan->chan_id; + sig.span_id = chan->span_id; + sig.channel = chan; + sig.span = chan->span; while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -169,20 +175,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { - sig.event_id = ZAP_SIGEVENT_UP; + if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { + sig.event_id = ZAP_SIGEVENT_UNHOLD; + } else { + sig.event_id = ZAP_SIGEVENT_UP; + } data->sig_cb(&sig); - continue; } break; case ZAP_CHANNEL_STATE_IDLE: { - memset(&sig, 0, sizeof(sig)); sig.event_id = ZAP_SIGEVENT_START; - sig.chan_id = chan->chan_id; - sig.span_id = chan->span_id; - sig.channel = chan; - sig.span = chan->span; zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); data->sig_cb(&sig); continue; @@ -195,8 +199,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } break; + case ZAP_CHANNEL_STATE_HOLD: + { + sig.event_id = ZAP_SIGEVENT_HOLD; + data->sig_cb(&sig); + zap_set_flag_locked(chan, ZAP_CHANNEL_HOLD); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); + } + break; case ZAP_CHANNEL_STATE_DIALTONE: { + *dtmf = '\0'; + dtmf_offset = 0; zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_DIAL]); indicate = 1; @@ -245,8 +259,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) last_digit = 0; } - if (zap_channel_wait(chan, &flags, interval * 2) == ZAP_FAIL) { - goto done; + if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; } if (!(flags & ZAP_READ)) { @@ -313,12 +327,41 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id); + zap_mutex_lock(event->channel->mutex); + + switch(event->enum_id) { case ZAP_OOB_ONHOOK: { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } break; + case ZAP_OOB_FLASH: + { + zap_sigmsg_t sig; + zap_analog_data_t *data = event->channel->span->analog_data; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; + sig.span = event->channel->span; + + if (event->channel->state == ZAP_CHANNEL_STATE_UP) { + if (event->channel->token_count > 1) { + zap_channel_rotate_tokens(event->channel); + sig.event_id = ZAP_SIGEVENT_FLASH; + data->sig_cb(&sig); + } else { + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + zap_clear_flag_locked(event->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); + } else { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_HOLD); + } + } + } + } + break; case ZAP_OOB_OFFHOOK: { if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { @@ -328,7 +371,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) } } - + zap_mutex_unlock(event->channel->mutex); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 1c3da3c2c7..845cba7ef9 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -370,16 +370,54 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } -zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token) +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) { + zap_status_t status = ZAP_FAIL; + zap_mutex_lock(zchan->mutex); - if (token) { - zap_copy_string(zchan->token, token, sizeof(zchan->token)); - } else { - *zchan->token = '\0'; + if (token_id == -1) { + memset(zchan->tokens, 0, sizeof(zchan->tokens)); + zchan->token_count = 0; + } else if (*zchan->tokens[token_id] != '\0') { + char tokens[ZAP_MAX_TOKENS][ZAP_TOKEN_STRLEN]; + int32_t i, count = zchan->token_count; + memcpy(tokens, zchan->tokens, sizeof(tokens)); + memset(zchan->tokens, 0, sizeof(zchan->tokens)); + zchan->token_count = 0; + + for (i = 0; i < count; i++) { + if (i != token_id) { + zap_copy_string(zchan->tokens[zchan->token_count], tokens[i], sizeof(zchan->tokens[zchan->token_count])); + zchan->token_count++; + } + } + + status = ZAP_SUCCESS; } zap_mutex_unlock(zchan->mutex); - return ZAP_SUCCESS; + + return status; +} + +void zap_channel_rotate_tokens(zap_channel_t *zchan) +{ + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); + *zchan->tokens[zchan->token_count] = '\0'; +} + +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) +{ + zap_status_t status = ZAP_FAIL; + + zap_mutex_lock(zchan->mutex); + if (zchan->token_count < ZAP_MAX_TOKENS) { + zap_copy_string(zchan->tokens[zchan->token_count], token, sizeof(zchan->tokens[zchan->token_count])); + zchan->token_count++; + } + zap_mutex_unlock(zchan->mutex); + + return status; } @@ -523,6 +561,10 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->event_callback = NULL; zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); + memset(zchan->tokens, 0, sizeof(zchan->tokens)); + zchan->token_count = 0; + if (zchan->tone_session.buffer) { teletone_destroy_session(&zchan->tone_session); memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); @@ -605,6 +647,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(check != NULL); *zchan = NULL; + zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); From 58c313c2af55c264c9c164663fca37bc9c2d530b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 27 May 2007 18:14:49 +0000 Subject: [PATCH 0332/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@166 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 93 +++++++++++++++++++++----- libs/freetdm/src/include/openzap.h | 11 ++- libs/freetdm/src/include/zap_types.h | 11 ++- libs/freetdm/src/zap_analog.c | 65 +++++++++++++++--- libs/freetdm/src/zap_io.c | 55 +++++++++++++-- 5 files changed, 197 insertions(+), 38 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 72060facba..19530cf755 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -52,7 +52,8 @@ typedef enum { TFLAG_OUTBOUND = (1 << 1), TFLAG_DTMF = (1 << 2), TFLAG_CODEC = (1 << 3), - TFLAG_BREAK = (1 << 4) + TFLAG_BREAK = (1 << 4), + TFLAG_HOLD = (1 << 5) } TFLAGS; static struct { @@ -76,6 +77,8 @@ struct private_object { switch_codec_t write_codec; switch_frame_t read_frame; unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; + switch_frame_t cng_frame; + unsigned char cng_databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; switch_core_session_t *session; switch_caller_profile_t *caller_profile; unsigned int codec; @@ -84,6 +87,7 @@ struct private_object { switch_mutex_t *mutex; switch_mutex_t *flag_mutex; zap_channel_t *zchan; + int32_t token_id; }; typedef struct private_object private_t; @@ -111,6 +115,9 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses tech_pvt->zchan = zchan; tech_pvt->read_frame.data = tech_pvt->databuf; tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); + tech_pvt->cng_frame.data = tech_pvt->cng_databuf; + tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); + memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.buflen); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_core_session_set_private(session, tech_pvt); @@ -241,7 +248,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_channel_set_token(tech_pvt->zchan, NULL); + zap_channel_clear_token(tech_pvt->zchan, tech_pvt->token_id); switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: @@ -367,6 +374,17 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + switch_yield(tech_pvt->zchan->effective_interval * 1000); + *frame = &tech_pvt->cng_frame; + tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; + tech_pvt->cng_frame.samples = tech_pvt->cng_frame.datalen; + if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { + tech_pvt->cng_frame.samples /= 2; + } + return SWITCH_STATUS_SUCCESS; + } + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } @@ -420,6 +438,10 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc assert(tech_pvt->zchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + return SWITCH_STATUS_SUCCESS; + } + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } @@ -593,12 +615,26 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_FAIL; } - switch_copy_string(sigmsg->channel->token, switch_core_session_get_uuid(session), sizeof(sigmsg->channel->token)); + if ((tech_pvt->token_id = zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session))) < 0) { + switch_core_session_destroy(&session); + return ZAP_FAIL; + } *sp = session; return ZAP_SUCCESS; } +static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) +{ + switch_core_session_t *session = NULL; + + if (!switch_strlen_zero(channel->tokens[id])) { + session = switch_core_session_locate(channel->tokens[id]); + } + + return session; +} + static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -609,18 +645,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; zap_status_t status; - int rwlock = 0; zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); - if (!switch_strlen_zero(sigmsg->channel->token)) { - if ((session = switch_core_session_locate(sigmsg->channel->token))) { - channel = switch_core_session_get_channel(session); - rwlock++; - } - } - switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: { @@ -632,16 +661,48 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_STOP: { - if (channel) { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_channel_clear_token(sigmsg->channel, 0); + channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - zap_channel_set_token(sigmsg->channel, NULL); + switch_core_session_rwunlock(session); } } break; - } - if (session && rwlock) { - switch_core_session_rwunlock(session); + case ZAP_SIGEVENT_FLASH: + { + uint32_t i = 0; + for (i = 0; i < sigmsg->channel->token_count; i++) { + if ((session = zap_channel_get_session(sigmsg->channel, i))) { + tech_pvt = switch_core_session_get_private(session); + if (i) { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } + switch_core_session_rwunlock(session); + } + } + } + case ZAP_SIGEVENT_HOLD: + { + if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { + tech_pvt = switch_core_session_get_private(session); + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_UNHOLD: + { + if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { + tech_pvt = switch_core_session_get_private(session); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + switch_core_session_rwunlock(session); + } + } + break; } return status; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index a4e24f2394..3f47bc7a68 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -157,6 +157,7 @@ #define zap_channel_test_feature(obj, flag) ((obj)->features & flag) #define zap_channel_set_feature(obj, flag) (obj)->features |= (flag) #define zap_channel_clear_feature(obj, flag) (obj)->features &= ~(flag) +#define zap_channel_set_member_locked(obj, _m, _v) zap_mutex_lock(obj->mutex); obj->_m = _v; zap_mutex_unlock(obj->mutex) /*! \brief Test for the existance of a flag on an arbitary object @@ -218,6 +219,9 @@ struct zap_event { void *data; }; +#define ZAP_TOKEN_STRLEN 128 +#define ZAP_MAX_TOKENS 10 + struct zap_channel { uint32_t span_id; uint32_t chan_id; @@ -245,7 +249,8 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; - char token[128]; + char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; + uint32_t token_count; char chan_name[128]; char chan_number[32]; struct zap_span *span; @@ -322,7 +327,9 @@ struct zap_io_interface { struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; -zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token); +void zap_channel_rotate_tokens(zap_channel_t *zchan); +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 236217278f..d1fcb9248d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -101,13 +101,16 @@ typedef enum { ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, ZAP_SIGEVENT_UP, + ZAP_SIGEVENT_HOLD, + ZAP_SIGEVENT_UNHOLD, + ZAP_SIGEVENT_FLASH, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "HOLD", "UNHOLD", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -193,6 +196,7 @@ typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_HANGUP, + ZAP_CHANNEL_STATE_HOLD, ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_COLLECT, ZAP_CHANNEL_STATE_RING, @@ -201,7 +205,7 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -216,7 +220,8 @@ typedef enum { ZAP_CHANNEL_INTHREAD = (1 << 8), ZAP_CHANNEL_WINK = (1 << 9), ZAP_CHANNEL_FLASH = (1 << 10), - ZAP_CHANNEL_STATE_CHANGE = (1 << 11) + ZAP_CHANNEL_STATE_CHANGE = (1 << 11), + ZAP_CHANNEL_HOLD = (1 << 12) } zap_channel_flag_t; diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 3032e0200b..b6314dc339 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -87,7 +87,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_tone_type_t tt = ZAP_TONE_DTMF; - char dtmf[128]; + char dtmf[128] = ""; zap_size_t dtmf_offset = 0; zap_analog_data_t *data = chan->span->analog_data; zap_channel_t *closed_chan; @@ -119,6 +119,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = chan->chan_id; + sig.span_id = chan->span_id; + sig.channel = chan; + sig.span = chan->span; while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -169,20 +175,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { - sig.event_id = ZAP_SIGEVENT_UP; + if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { + sig.event_id = ZAP_SIGEVENT_UNHOLD; + } else { + sig.event_id = ZAP_SIGEVENT_UP; + } data->sig_cb(&sig); - continue; } break; case ZAP_CHANNEL_STATE_IDLE: { - memset(&sig, 0, sizeof(sig)); sig.event_id = ZAP_SIGEVENT_START; - sig.chan_id = chan->chan_id; - sig.span_id = chan->span_id; - sig.channel = chan; - sig.span = chan->span; zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); data->sig_cb(&sig); continue; @@ -195,8 +199,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } break; + case ZAP_CHANNEL_STATE_HOLD: + { + sig.event_id = ZAP_SIGEVENT_HOLD; + data->sig_cb(&sig); + zap_set_flag_locked(chan, ZAP_CHANNEL_HOLD); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); + } + break; case ZAP_CHANNEL_STATE_DIALTONE: { + *dtmf = '\0'; + dtmf_offset = 0; zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_DIAL]); indicate = 1; @@ -245,8 +259,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) last_digit = 0; } - if (zap_channel_wait(chan, &flags, interval * 2) == ZAP_FAIL) { - goto done; + if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; } if (!(flags & ZAP_READ)) { @@ -313,12 +327,41 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id); + zap_mutex_lock(event->channel->mutex); + + switch(event->enum_id) { case ZAP_OOB_ONHOOK: { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } break; + case ZAP_OOB_FLASH: + { + zap_sigmsg_t sig; + zap_analog_data_t *data = event->channel->span->analog_data; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; + sig.span = event->channel->span; + + if (event->channel->state == ZAP_CHANNEL_STATE_UP) { + if (event->channel->token_count > 1) { + zap_channel_rotate_tokens(event->channel); + sig.event_id = ZAP_SIGEVENT_FLASH; + data->sig_cb(&sig); + } else { + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + zap_clear_flag_locked(event->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); + } else { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_HOLD); + } + } + } + } + break; case ZAP_OOB_OFFHOOK: { if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { @@ -328,7 +371,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) } } - + zap_mutex_unlock(event->channel->mutex); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1c3da3c2c7..845cba7ef9 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -370,16 +370,54 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } -zap_status_t zap_channel_set_token(zap_channel_t *zchan, char *token) +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) { + zap_status_t status = ZAP_FAIL; + zap_mutex_lock(zchan->mutex); - if (token) { - zap_copy_string(zchan->token, token, sizeof(zchan->token)); - } else { - *zchan->token = '\0'; + if (token_id == -1) { + memset(zchan->tokens, 0, sizeof(zchan->tokens)); + zchan->token_count = 0; + } else if (*zchan->tokens[token_id] != '\0') { + char tokens[ZAP_MAX_TOKENS][ZAP_TOKEN_STRLEN]; + int32_t i, count = zchan->token_count; + memcpy(tokens, zchan->tokens, sizeof(tokens)); + memset(zchan->tokens, 0, sizeof(zchan->tokens)); + zchan->token_count = 0; + + for (i = 0; i < count; i++) { + if (i != token_id) { + zap_copy_string(zchan->tokens[zchan->token_count], tokens[i], sizeof(zchan->tokens[zchan->token_count])); + zchan->token_count++; + } + } + + status = ZAP_SUCCESS; } zap_mutex_unlock(zchan->mutex); - return ZAP_SUCCESS; + + return status; +} + +void zap_channel_rotate_tokens(zap_channel_t *zchan) +{ + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); + *zchan->tokens[zchan->token_count] = '\0'; +} + +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) +{ + zap_status_t status = ZAP_FAIL; + + zap_mutex_lock(zchan->mutex); + if (zchan->token_count < ZAP_MAX_TOKENS) { + zap_copy_string(zchan->tokens[zchan->token_count], token, sizeof(zchan->tokens[zchan->token_count])); + zchan->token_count++; + } + zap_mutex_unlock(zchan->mutex); + + return status; } @@ -523,6 +561,10 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->event_callback = NULL; zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); + memset(zchan->tokens, 0, sizeof(zchan->tokens)); + zchan->token_count = 0; + if (zchan->tone_session.buffer) { teletone_destroy_session(&zchan->tone_session); memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); @@ -605,6 +647,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(check != NULL); *zchan = NULL; + zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); From 12eb05c035bf01a8e1903f88cf84a01d7b5e9218 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 02:59:34 +0000 Subject: [PATCH 0333/1766] add codeset enum. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@167 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 83b94df8a8..1ac19ed7dd 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -330,6 +330,20 @@ const char *q931_error_to_name(q931_error_t error); #define Q931mes_STATUS_ENQUIRY 0x75 /* 0111 0101 */ #define Q931mes_SEGMENT 0x60 /* 0110 0000 */ +/* 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 ---- */ From 009cf92d2137c569e87d6fa1f0b437d31b174075 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 02:59:34 +0000 Subject: [PATCH 0334/1766] add codeset enum. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@167 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 83b94df8a8..1ac19ed7dd 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -330,6 +330,20 @@ const char *q931_error_to_name(q931_error_t error); #define Q931mes_STATUS_ENQUIRY 0x75 /* 0111 0101 */ #define Q931mes_SEGMENT 0x60 /* 0110 0000 */ +/* 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 ---- */ From 3599a316bb8faad1aaa27b517d3dda308470e4a3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 03:14:24 +0000 Subject: [PATCH 0335/1766] move ie definitions and declarations to a new header file. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@168 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 4 + libs/openzap/src/isdn/include/Q931.h | 1117 +---------------------- libs/openzap/src/isdn/include/Q931ie.h | 1123 ++++++++++++++++++++++++ 3 files changed, 1145 insertions(+), 1099 deletions(-) create mode 100644 libs/openzap/src/isdn/include/Q931ie.h diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index f4917c18a3..d396d9dc86 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -178,6 +178,10 @@ RelativePath="..\src\isdn\include\Q931.h" > + + diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 1ac19ed7dd..a14bf85856 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -183,6 +183,22 @@ const char *q931_error_to_name(q931_error_t error); #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 indicate error */ + /***************************************************************************** MAXTRUNKS sets how many physical trunks this system might have. This @@ -246,11 +262,6 @@ const char *q931_error_to_name(q931_error_t error); #define Q931MAXSTATE 100 /* Size of state tables */ -/***************************************************************************** - - - -*****************************************************************************/ /***************************************************************************** @@ -330,1042 +341,6 @@ const char *q931_error_to_name(q931_error_t error); #define Q931mes_STATUS_ENQUIRY 0x75 /* 0111 0101 */ #define Q931mes_SEGMENT 0x60 /* 0110 0000 */ -/* 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 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; /***************************************************************************** @@ -1732,66 +707,10 @@ extern L3UINT Q931MsgieOffset[Q931MAXIE]; extern Q931_TrunkInfo_t Q931Trunk[Q931MAXTRUNKS]; +#include "Q931ie.h" + #include "Q932.h" -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - /***************************************************************************** Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h new file mode 100644 index 0000000000..ad296951d0 --- /dev/null +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -0,0 +1,1123 @@ +/****************************************************************************** + + 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 0000 */ +#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_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 */ + + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +#endif /* _Q931IE_NL */ From 231762faaea4712597470dd3ebbda63739afe662 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 03:14:24 +0000 Subject: [PATCH 0336/1766] move ie definitions and declarations to a new header file. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@168 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 4 + libs/freetdm/src/isdn/include/Q931.h | 1117 +---------------------- libs/freetdm/src/isdn/include/Q931ie.h | 1123 ++++++++++++++++++++++++ 3 files changed, 1145 insertions(+), 1099 deletions(-) create mode 100644 libs/freetdm/src/isdn/include/Q931ie.h diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index f4917c18a3..d396d9dc86 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -178,6 +178,10 @@ RelativePath="..\src\isdn\include\Q931.h" > + + diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 1ac19ed7dd..a14bf85856 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -183,6 +183,22 @@ const char *q931_error_to_name(q931_error_t error); #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 indicate error */ + /***************************************************************************** MAXTRUNKS sets how many physical trunks this system might have. This @@ -246,11 +262,6 @@ const char *q931_error_to_name(q931_error_t error); #define Q931MAXSTATE 100 /* Size of state tables */ -/***************************************************************************** - - - -*****************************************************************************/ /***************************************************************************** @@ -330,1042 +341,6 @@ const char *q931_error_to_name(q931_error_t error); #define Q931mes_STATUS_ENQUIRY 0x75 /* 0111 0101 */ #define Q931mes_SEGMENT 0x60 /* 0110 0000 */ -/* 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 0000 */ -#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_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 */ - -/***************************************************************************** - - 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 indicate error */ - -/***************************************************************************** - - 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 Class; /* Class */ - /* 000 Indicate channels */ - /* 110 Single interface */ - /* 111 All interfaces */ -}Q931ie_RestartInd; /***************************************************************************** @@ -1732,66 +707,10 @@ extern L3UINT Q931MsgieOffset[Q931MAXIE]; extern Q931_TrunkInfo_t Q931Trunk[Q931MAXTRUNKS]; +#include "Q931ie.h" + #include "Q932.h" -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c - -*****************************************************************************/ - -L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); - -L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); - /***************************************************************************** Q.931 Message Pack/Unpack functions. Implemented in Q931mes.c diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h new file mode 100644 index 0000000000..ad296951d0 --- /dev/null +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -0,0 +1,1123 @@ +/****************************************************************************** + + 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 0000 */ +#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_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 */ + + +/***************************************************************************** + + 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 Class; /* Class */ + /* 000 Indicate channels */ + /* 110 Single interface */ + /* 111 All interfaces */ +}Q931ie_RestartInd; + + +/***************************************************************************** + + Q.931 Information Element Pack/Unpack functions. Implemented in Q931ie.c + +*****************************************************************************/ + +L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); + +L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); +L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +#endif /* _Q931IE_NL */ From 4b82de25cc1bb97f409f92dcff24257822d72fe8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 22:00:14 +0000 Subject: [PATCH 0337/1766] Added typedefs for some functions to simplify the declarations for the function pointer tables and the header files. API rework to simplify the Umes functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@169 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 1 - libs/openzap/msvc/openzap.vcproj | 4 - libs/openzap/src/isdn/Q931.c | 166 +---------- libs/openzap/src/isdn/Q931api.c | 11 +- libs/openzap/src/isdn/Q931ie.c | 80 ++++-- libs/openzap/src/isdn/Q931mes.c | 335 +++-------------------- libs/openzap/src/isdn/include/Q931.h | 36 +-- libs/openzap/src/isdn/include/Q931ie.h | 119 ++++---- libs/openzap/src/isdn/include/national.h | 31 --- libs/openzap/src/isdn/nationalStateNT.c | 2 +- libs/openzap/src/isdn/nationalStateTE.c | 2 +- libs/openzap/src/isdn/nationalie.c | 141 ---------- libs/openzap/src/isdn/nationalmes.c | 108 ++------ 13 files changed, 213 insertions(+), 823 deletions(-) delete mode 100644 libs/openzap/src/isdn/nationalie.c diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index f5cbeee8ab..628702c594 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -52,7 +52,6 @@ $(SRC)/isdn/Q931ie.o \ $(SRC)/isdn/Q931mes.o \ $(SRC)/isdn/Q931StateNT.o \ $(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalie.o \ $(SRC)/isdn/nationalmes.o \ $(SRC)/isdn/nationalStateNT.o \ $(SRC)/isdn/nationalStateTE.o \ diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index d396d9dc86..1a60eded45 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -202,10 +202,6 @@ RelativePath="..\src\isdn\mfifo.c" > - - diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index bdc9324c5c..d522db0cc4 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -56,163 +56,14 @@ these table entries during system inititialization of a stack. *****************************************************************************/ -L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); +q931proc_func_t *Q931Proc[Q931MAXDLCT][Q931MAXMES]; -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +q931umes_func_t *Q931Umes[Q931MAXDLCT][Q931MAXMES]; +q931pmes_func_t *Q931Pmes[Q931MAXDLCT][Q931MAXMES]; -L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +q931uie_func_t *Q931Uie[Q931MAXDLCT][Q931MAXIE]; +q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE]; -L3UINT Q931MsgieOffset[Q931MAXIE]; - -void Q931Initialize_MsgieOffset() -{ - L3INT x; - Q931mes_Generic msg; - ie *index; - - for(x=0; xBearerCap; L3INT Off = 0; L3INT Octet = 0; L3INT IESize; @@ -431,9 +432,10 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -517,9 +519,10 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -594,9 +597,10 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -690,9 +694,10 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -783,9 +788,10 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { - Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + ie *pIE = &pMsg->CallingNum; L3INT Off = 0; L3INT Octet = 0; L3INT x; @@ -897,9 +903,10 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -993,9 +1000,10 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1085,9 +1093,10 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1143,9 +1152,10 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1336,9 +1346,10 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1455,9 +1466,10 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1538,9 +1550,10 @@ L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1659,9 +1672,10 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1741,9 +1755,10 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2122,9 +2137,10 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2232,9 +2248,10 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2308,9 +2325,10 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2393,9 +2411,10 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2452,9 +2471,10 @@ L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2497,9 +2517,10 @@ L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2574,9 +2595,10 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2656,9 +2678,10 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2713,9 +2736,10 @@ L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2787,9 +2811,10 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2878,9 +2903,10 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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 x=0; diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 04ad6c4fff..bc2facd7cb 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -59,32 +59,12 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -168,27 +148,11 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_G switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -300,42 +264,14 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -429,13 +365,8 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -498,22 +429,10 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -585,29 +504,13 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gene switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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; @@ -680,19 +583,9 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -753,27 +646,11 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -849,17 +726,9 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -924,17 +793,9 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_ switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -999,17 +860,9 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1074,17 +927,9 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1149,7 +994,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1206,12 +1051,8 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1273,12 +1114,8 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gen switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1357,101 +1194,33 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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==0) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(ir < 2) { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; - } - else if(ir==1) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - ir++; - } - else - { + } else { return Q931E_ILLEGAL_IE; } break; - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; default: return Q931E_ILLEGAL_IE; break; @@ -1606,22 +1375,10 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1693,17 +1450,9 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1769,7 +1518,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Ge switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1826,7 +1575,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1884,7 +1633,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1941,12 +1690,8 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Ge switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index a14bf85856..6c580d8bb6 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -371,6 +371,11 @@ typedef struct L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ L3INT CRV; /* Call reference value */ + L3UINT codeset; /* Current Codeset - Temporary variable */ + /* used for the Q931Uie functions */ + /* in a parsed message this will only */ + /* indicate the codeset of the last */ + /* ie parsed */ ie Shift; ie MoreData; @@ -588,15 +593,21 @@ typedef struct The proc tables are defined in Q931.c and initialized in Q931Initialize. *****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); +typedef L3INT (q931proc_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *, L3INT); -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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); -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +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); -extern L3UINT Q931MsgieOffset[Q931MAXIE]; +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]; /***************************************************************************** @@ -705,8 +716,6 @@ extern L3UINT Q931MsgieOffset[Q931MAXIE]; *****************************************************************************/ -extern Q931_TrunkInfo_t Q931Trunk[Q931MAXTRUNKS]; - #include "Q931ie.h" #include "Q932.h" @@ -847,14 +856,9 @@ void Q931CreateNT(L3UCHAR i); void Q931SetMesCreateCB(L3INT (*callback)()); void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); +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 Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); @@ -873,8 +877,6 @@ void Q931SetGetTimeCB(L3ULONG (*callback)()); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); -ie *Q931MegGetIE(Q931mes_Generic *msg, L3UINT ie_type); - /***************************************************************************** Q.931 Low Level API Function Prototyping. Implemented in Q931API.c diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index ad296951d0..27e292d1f9 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -96,6 +96,9 @@ typedef enum { #define Q931ie_USER_USER 0x7e /* 0111 1110 */ #define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */ +#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ + + /***************************************************************************** @@ -1061,6 +1064,19 @@ typedef struct /* 111 All interfaces */ }Q931ie_RestartInd; +/***************************************************************************** + + Struct: Q931ie_GenericDigits + + +*****************************************************************************/ + +typedef struct +{ + L3UCHAR IEId; /* 00110111 */ + L3UCHAR Size; /* Length of Information Element */ +} Q931ie_GenericDigits; + /***************************************************************************** @@ -1068,56 +1084,61 @@ typedef struct *****************************************************************************/ -L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +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; -L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +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; #endif /* _Q931IE_NL */ diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h index 1e9f5b1f8f..f6c79ed4c9 100644 --- a/libs/openzap/src/isdn/include/national.h +++ b/libs/openzap/src/isdn/include/national.h @@ -65,37 +65,6 @@ *****************************************************************************/ -/* Single octet information elements */ - -/* Variable Length Information Elements */ -#define nationalie_GENERIC_DIGITS 0x37 /* 0011 0111 */ - - - -/***************************************************************************** - - Struct: nationalie_GenericDigits - - -*****************************************************************************/ - -typedef struct -{ - L3UCHAR IEId; /* 00110111 */ - L3UCHAR Size; /* Length of Information Element */ -}nationalie_GenericDigits; - - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in nationalie.c - -*****************************************************************************/ - -L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); - - /***************************************************************************** Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c index 2465853fe1..29f766e073 100644 --- a/libs/openzap/src/isdn/nationalStateNT.c +++ b/libs/openzap/src/isdn/nationalStateNT.c @@ -116,7 +116,7 @@ void nationalCreateNT(L3UCHAR i) 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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_GenericDigits); + 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 */ diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index 0f3186e288..fb2e7139c2 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -123,7 +123,7 @@ void nationalCreateTE(L3UCHAR i) 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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_GenericDigits); + 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 */ diff --git a/libs/openzap/src/isdn/nationalie.c b/libs/openzap/src/isdn/nationalie.c deleted file mode 100644 index bf9afbad80..0000000000 --- a/libs/openzap/src/isdn/nationalie.c +++ /dev/null @@ -1,141 +0,0 @@ -/***************************************************************************** - - FileName: nationalie.c - - Contents: Information Element Pack/Unpack functions. - - These functions will pack out a National ISDN 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: - - nationalPie_XXX Pack struct into Q.931 IE - nationalUie_XXX Unpack Q.931 IE into struct - nationalInitIEXXX Initialize IE (see nationalapi.c). - - 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" - -/***************************************************************************** - - 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: nationalUie_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 nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - nationalie_GenericDigits * pie = (nationalie_GenericDigits*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet++]; - - /* Octet 2 */ - IESize = IBuf[Octet++]; - - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(nationalie_GenericDigits) + x -1; - - pie->Size = (L3UCHAR)(sizeof(nationalie_GenericDigits) + x -1); - - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: nationalPie_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 nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) -{ - OBuf[(*Octet)++] = nationalie_GENERIC_DIGITS ; - OBuf[(*Octet)++] = 2; - - return Q931E_NO_ERROR; -} - diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 971016167f..b256a318d6 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -62,102 +62,34 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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==0) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(ir < 2) { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; - } - else if(ir==1) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - ir++; - } - else - { + } else { return Q931E_ILLEGAL_IE; } break; - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case nationalie_GENERIC_DIGITS: + case Q931ie_GENERIC_DIGITS: /* TODO: Implement this ie */ IOff = IOff + 4; break; From 53f6f60ba83ed60003e448d84372bc72e9c93b9d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 22:00:14 +0000 Subject: [PATCH 0338/1766] Added typedefs for some functions to simplify the declarations for the function pointer tables and the header files. API rework to simplify the Umes functions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@169 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 1 - libs/freetdm/msvc/openzap.vcproj | 4 - libs/freetdm/src/isdn/Q931.c | 166 +---------- libs/freetdm/src/isdn/Q931api.c | 11 +- libs/freetdm/src/isdn/Q931ie.c | 80 ++++-- libs/freetdm/src/isdn/Q931mes.c | 335 +++-------------------- libs/freetdm/src/isdn/include/Q931.h | 36 +-- libs/freetdm/src/isdn/include/Q931ie.h | 119 ++++---- libs/freetdm/src/isdn/include/national.h | 31 --- libs/freetdm/src/isdn/nationalStateNT.c | 2 +- libs/freetdm/src/isdn/nationalStateTE.c | 2 +- libs/freetdm/src/isdn/nationalie.c | 141 ---------- libs/freetdm/src/isdn/nationalmes.c | 108 ++------ 13 files changed, 213 insertions(+), 823 deletions(-) delete mode 100644 libs/freetdm/src/isdn/nationalie.c diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index f5cbeee8ab..628702c594 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -52,7 +52,6 @@ $(SRC)/isdn/Q931ie.o \ $(SRC)/isdn/Q931mes.o \ $(SRC)/isdn/Q931StateNT.o \ $(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalie.o \ $(SRC)/isdn/nationalmes.o \ $(SRC)/isdn/nationalStateNT.o \ $(SRC)/isdn/nationalStateTE.o \ diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index d396d9dc86..1a60eded45 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -202,10 +202,6 @@ RelativePath="..\src\isdn\mfifo.c" > - - diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index bdc9324c5c..d522db0cc4 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -56,163 +56,14 @@ these table entries during system inititialization of a stack. *****************************************************************************/ -L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); +q931proc_func_t *Q931Proc[Q931MAXDLCT][Q931MAXMES]; -L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); -L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +q931umes_func_t *Q931Umes[Q931MAXDLCT][Q931MAXMES]; +q931pmes_func_t *Q931Pmes[Q931MAXDLCT][Q931MAXMES]; -L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +q931uie_func_t *Q931Uie[Q931MAXDLCT][Q931MAXIE]; +q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE]; -L3UINT Q931MsgieOffset[Q931MAXIE]; - -void Q931Initialize_MsgieOffset() -{ - L3INT x; - Q931mes_Generic msg; - ie *index; - - for(x=0; xBearerCap; L3INT Off = 0; L3INT Octet = 0; L3INT IESize; @@ -431,9 +432,10 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -517,9 +519,10 @@ L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -594,9 +597,10 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -690,9 +694,10 @@ L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -783,9 +788,10 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { - Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + Q931ie_CallingNum * pie = (Q931ie_CallingNum*)OBuf; + ie *pIE = &pMsg->CallingNum; L3INT Off = 0; L3INT Octet = 0; L3INT x; @@ -897,9 +903,10 @@ L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -993,9 +1000,10 @@ L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1085,9 +1093,10 @@ L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3IN Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_CongLevel(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1143,9 +1152,10 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error code, 0 = OK *****************************************************************************/ -L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1336,9 +1346,10 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1455,9 +1466,10 @@ L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1538,9 +1550,10 @@ L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1659,9 +1672,10 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -1741,9 +1755,10 @@ L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2122,9 +2137,10 @@ L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2232,9 +2248,10 @@ L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2308,9 +2325,10 @@ L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2393,9 +2411,10 @@ L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2452,9 +2471,10 @@ L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2497,9 +2517,10 @@ L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2574,9 +2595,10 @@ L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2656,9 +2678,10 @@ L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2713,9 +2736,10 @@ L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2787,9 +2811,10 @@ L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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; @@ -2878,9 +2903,10 @@ L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf Return Value: Error Message *****************************************************************************/ -L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) +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 x=0; diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 04ad6c4fff..bc2facd7cb 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -59,32 +59,12 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -168,27 +148,11 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_G switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -300,42 +264,14 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -429,13 +365,8 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -498,22 +429,10 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -585,29 +504,13 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gene switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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; @@ -680,19 +583,9 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NOTIFICATION_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NotifInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -753,27 +646,11 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -849,17 +726,9 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -924,17 +793,9 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_ switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -999,17 +860,9 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1074,17 +927,9 @@ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_RESTART_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RestartInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1149,7 +994,7 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1206,12 +1051,8 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1273,12 +1114,8 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gen switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1357,101 +1194,33 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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==0) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(ir < 2) { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; - } - else if(ir==1) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - ir++; - } - else - { + } else { return Q931E_ILLEGAL_IE; } break; - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; default: return Q931E_ILLEGAL_IE; break; @@ -1606,22 +1375,10 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1693,17 +1450,9 @@ L3INT Q931Umes_Status(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_CALL_STATE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallState, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1769,7 +1518,7 @@ L3INT Q931Umes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Ge switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1826,7 +1575,7 @@ L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic switch(IBuf[IOff]) { case Q931ie_CALL_IDENTITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1884,7 +1633,7 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener switch(IBuf[IOff]) { case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; @@ -1941,12 +1690,8 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Ge switch(IBuf[IOff]) { case Q931ie_CAUSE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Cause, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index a14bf85856..6c580d8bb6 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -371,6 +371,11 @@ typedef struct L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ L3INT CRV; /* Call reference value */ + L3UINT codeset; /* Current Codeset - Temporary variable */ + /* used for the Q931Uie functions */ + /* in a parsed message this will only */ + /* indicate the codeset of the last */ + /* ie parsed */ ie Shift; ie MoreData; @@ -588,15 +593,21 @@ typedef struct The proc tables are defined in Q931.c and initialized in Q931Initialize. *****************************************************************************/ -extern L3INT (*Q931Proc [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *,L3INT); +typedef L3INT (q931proc_func_t) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *, L3INT); -extern L3INT (*Q931Umes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size); -extern L3INT (*Q931Pmes [Q931MAXDLCT][Q931MAXMES]) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize); +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); -extern L3INT (*Q931Uie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,ie *pIE,L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -extern L3INT (*Q931Pie [Q931MAXDLCT][Q931MAXIE] ) (Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +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); -extern L3UINT Q931MsgieOffset[Q931MAXIE]; +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]; /***************************************************************************** @@ -705,8 +716,6 @@ extern L3UINT Q931MsgieOffset[Q931MAXIE]; *****************************************************************************/ -extern Q931_TrunkInfo_t Q931Trunk[Q931MAXTRUNKS]; - #include "Q931ie.h" #include "Q932.h" @@ -847,14 +856,9 @@ void Q931CreateNT(L3UCHAR i); void Q931SetMesCreateCB(L3INT (*callback)()); void Q931SetDialectCreateCB(L3INT (*callback)(L3INT)); void Q931SetHeaderSpace(L3INT space); -void Q931SetMesProc(L3UCHAR mes, L3UCHAR dialect, - L3INT (*Q931ProcFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT iFrom), - L3INT (*Q931UmesFunc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size), - L3INT (*Q931PmesFunc)(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)); -void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, - L3INT (*Q931PieProc)(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet), - L3INT (*Q931UieProc)(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)); +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 Q931Initialize(); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); @@ -873,8 +877,6 @@ void Q931SetGetTimeCB(L3ULONG (*callback)()); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); -ie *Q931MegGetIE(Q931mes_Generic *msg, L3UINT ie_type); - /***************************************************************************** Q.931 Low Level API Function Prototyping. Implemented in Q931API.c diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index ad296951d0..27e292d1f9 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -96,6 +96,9 @@ typedef enum { #define Q931ie_USER_USER 0x7e /* 0111 1110 */ #define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */ +#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ + + /***************************************************************************** @@ -1061,6 +1064,19 @@ typedef struct /* 111 All interfaces */ }Q931ie_RestartInd; +/***************************************************************************** + + Struct: Q931ie_GenericDigits + + +*****************************************************************************/ + +typedef struct +{ + L3UCHAR IEId; /* 00110111 */ + L3UCHAR Size; /* Length of Information Element */ +} Q931ie_GenericDigits; + /***************************************************************************** @@ -1068,56 +1084,61 @@ typedef struct *****************************************************************************/ -L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_ProgInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Signal(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Segment(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_Cause(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_SendComplete(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_KeypadFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NotifInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallID(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RepeatInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_NetFac(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallingSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledSub(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_TransNetSel(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_LLComp(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_RestartInd(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); +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; -L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk,L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_ProgInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Signal(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_HLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Segment(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_SendComplete(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_KeypadFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NotifInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallID(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RepeatInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_NetFac(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallingSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CalledSub(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_TransNetSel(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); -L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff); + +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; #endif /* _Q931IE_NL */ diff --git a/libs/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h index 1e9f5b1f8f..f6c79ed4c9 100644 --- a/libs/freetdm/src/isdn/include/national.h +++ b/libs/freetdm/src/isdn/include/national.h @@ -65,37 +65,6 @@ *****************************************************************************/ -/* Single octet information elements */ - -/* Variable Length Information Elements */ -#define nationalie_GENERIC_DIGITS 0x37 /* 0011 0111 */ - - - -/***************************************************************************** - - Struct: nationalie_GenericDigits - - -*****************************************************************************/ - -typedef struct -{ - L3UCHAR IEId; /* 00110111 */ - L3UCHAR Size; /* Length of Information Element */ -}nationalie_GenericDigits; - - -/***************************************************************************** - - Q.931 Information Element Pack/Unpack functions. Implemented in nationalie.c - -*****************************************************************************/ - -L3INT nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet); -L3INT nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk,ie *pIE, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff); - - /***************************************************************************** Q.931 Message Pack/Unpack functions. Implemented in nationalmes.c diff --git a/libs/freetdm/src/isdn/nationalStateNT.c b/libs/freetdm/src/isdn/nationalStateNT.c index 2465853fe1..29f766e073 100644 --- a/libs/freetdm/src/isdn/nationalStateNT.c +++ b/libs/freetdm/src/isdn/nationalStateNT.c @@ -116,7 +116,7 @@ void nationalCreateNT(L3UCHAR i) 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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_GenericDigits); + 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 */ diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index 0f3186e288..fb2e7139c2 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -123,7 +123,7 @@ void nationalCreateTE(L3UCHAR i) 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(nationalie_GENERIC_DIGITS, i,nationalPie_GenericDigits, nationalUie_GenericDigits); + 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 */ diff --git a/libs/freetdm/src/isdn/nationalie.c b/libs/freetdm/src/isdn/nationalie.c deleted file mode 100644 index bf9afbad80..0000000000 --- a/libs/freetdm/src/isdn/nationalie.c +++ /dev/null @@ -1,141 +0,0 @@ -/***************************************************************************** - - FileName: nationalie.c - - Contents: Information Element Pack/Unpack functions. - - These functions will pack out a National ISDN 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: - - nationalPie_XXX Pack struct into Q.931 IE - nationalUie_XXX Unpack Q.931 IE into struct - nationalInitIEXXX Initialize IE (see nationalapi.c). - - 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" - -/***************************************************************************** - - 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: nationalUie_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 nationalUie_GenericDigits(Q931_TrunkInfo_t *pTrunk, ie *pIE, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) -{ - nationalie_GenericDigits * pie = (nationalie_GenericDigits*)OBuf; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet++]; - - /* Octet 2 */ - IESize = IBuf[Octet++]; - - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(nationalie_GenericDigits) + x -1; - - pie->Size = (L3UCHAR)(sizeof(nationalie_GenericDigits) + x -1); - - return Q931E_NO_ERROR; -} - -/***************************************************************************** - - Function: nationalPie_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 nationalPie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) -{ - OBuf[(*Octet)++] = nationalie_GENERIC_DIGITS ; - OBuf[(*Octet)++] = 2; - - return Q931E_NO_ERROR; -} - diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 971016167f..b256a318d6 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -62,102 +62,34 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->SendComplete, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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==0) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->RepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + if(ir < 2) { + rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; - } - else if(ir==1) - { - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLRepeatInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - ir++; - } - else - { + } else { return Q931E_ILLEGAL_IE; } break; - case Q931ie_BEARER_CAPABILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->BearerCap, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ChanID, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_PROGRESS_INDICATOR: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->ProgInd, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_NETWORK_SPECIFIC_FACILITIES: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->NetFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DISPLAY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Display, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_DATETIME: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->DateTime, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_KEYPAD_FACILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->KeypadFac, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_SIGNAL: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->Signal, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingNum, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLING_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CallingSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_NUMBER: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_CALLED_PARTY_SUBADDRESS: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->CalledSub, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_TRANSIT_NETWORK_SELECTION: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->TransNetSel, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_LOW_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->LLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case Q931ie_HIGH_LAYER_COMPATIBILITY: - rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, &mes->HLComp, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) - return rc; - break; - case nationalie_GENERIC_DIGITS: + case Q931ie_GENERIC_DIGITS: /* TODO: Implement this ie */ IOff = IOff + 4; break; From f3fe8c1743f0144b51be920d9085bca9d51b86d8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 22:48:13 +0000 Subject: [PATCH 0339/1766] Start of support for codesets and shift operation in messages. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@170 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 3 ++ libs/openzap/src/isdn/Q931ie.c | 63 ++++++++++++++++++++++++++ libs/openzap/src/isdn/include/Q931.h | 1 + libs/openzap/src/isdn/include/Q931ie.h | 4 +- libs/openzap/src/isdn/nationalmes.c | 18 ++++++-- 5 files changed, 83 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index d522db0cc4..29fff86284 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -334,6 +334,9 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Message Type */ m->MesType = Mes[IOff++]; + /* Starting Codeset */ + m->codeset = Q931_CODESET_0; + /* Call table proc to unpack codec message */ RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 87069633c3..75531cad82 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -2977,3 +2977,66 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L 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=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; + + /* Octet 2 */ + IESize = IBuf[Octet++]; + + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_GenericDigits) + x -1; + + pie->Size = (L3UCHAR)(sizeof(Q931ie_GenericDigits) + 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)++] = 2; + + return Q931E_NO_ERROR; +} diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 6c580d8bb6..346460a2ba 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -420,6 +420,7 @@ typedef struct ie Switchhook; ie FeatAct; ie FeatInd; + ie GenericDigits; L3UCHAR buf[1]; /* Buffer for IE's */ diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index 27e292d1f9..76633e1882 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -96,7 +96,9 @@ typedef enum { #define Q931ie_USER_USER 0x7e /* 0111 1110 */ #define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */ -#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ +/* Variable Length Codeset 6 Information Elements */ + +#define Q931ie_GENERIC_DIGITS Q931_CODESET_6 | 0x37 /* 0011 0111 */ diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index b256a318d6..a0b4f195bd 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -56,10 +56,22 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi L3INT ir=0; L3INT OOff=0; L3INT rc=Q931E_NO_ERROR; + L3UINT last_codeset = mes->codeset; + L3UCHAR shift_lock = 1; while(IOff < Size) { - switch(IBuf[IOff]) + if (!shift_lock) { + mes->codeset = last_codeset; + } + + if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) { + mes->codeset = ((IBuf[IOff] & 0x07) << 8); + shift_lock = (IBuf[IOff] & 0x08); + IOff++; + } + + switch(mes->codeset | IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: case Q931ie_BEARER_CAPABILITY: @@ -93,10 +105,6 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi /* TODO: Implement this ie */ IOff = IOff + 4; break; - case Q931ie_SHIFT: - /* TODO: Implement this ie */ - IOff++; - break; default: return Q931E_ILLEGAL_IE; break; From 7c17b9c136f082c898ee65dda897b42c8449b6d7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 22:48:13 +0000 Subject: [PATCH 0340/1766] Start of support for codesets and shift operation in messages. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@170 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 3 ++ libs/freetdm/src/isdn/Q931ie.c | 63 ++++++++++++++++++++++++++ libs/freetdm/src/isdn/include/Q931.h | 1 + libs/freetdm/src/isdn/include/Q931ie.h | 4 +- libs/freetdm/src/isdn/nationalmes.c | 18 ++++++-- 5 files changed, 83 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index d522db0cc4..29fff86284 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -334,6 +334,9 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Message Type */ m->MesType = Mes[IOff++]; + /* Starting Codeset */ + m->codeset = Q931_CODESET_0; + /* Call table proc to unpack codec message */ RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 87069633c3..75531cad82 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -2977,3 +2977,66 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L 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=0; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; + + /* Octet 2 */ + IESize = IBuf[Octet++]; + + Q931SetIE(*pIE, *OOff); + + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_GenericDigits) + x -1; + + pie->Size = (L3UCHAR)(sizeof(Q931ie_GenericDigits) + 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)++] = 2; + + return Q931E_NO_ERROR; +} diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 6c580d8bb6..346460a2ba 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -420,6 +420,7 @@ typedef struct ie Switchhook; ie FeatAct; ie FeatInd; + ie GenericDigits; L3UCHAR buf[1]; /* Buffer for IE's */ diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index 27e292d1f9..76633e1882 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -96,7 +96,9 @@ typedef enum { #define Q931ie_USER_USER 0x7e /* 0111 1110 */ #define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */ -#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ +/* Variable Length Codeset 6 Information Elements */ + +#define Q931ie_GENERIC_DIGITS Q931_CODESET_6 | 0x37 /* 0011 0111 */ diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index b256a318d6..a0b4f195bd 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -56,10 +56,22 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi L3INT ir=0; L3INT OOff=0; L3INT rc=Q931E_NO_ERROR; + L3UINT last_codeset = mes->codeset; + L3UCHAR shift_lock = 1; while(IOff < Size) { - switch(IBuf[IOff]) + if (!shift_lock) { + mes->codeset = last_codeset; + } + + if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) { + mes->codeset = ((IBuf[IOff] & 0x07) << 8); + shift_lock = (IBuf[IOff] & 0x08); + IOff++; + } + + switch(mes->codeset | IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: case Q931ie_BEARER_CAPABILITY: @@ -93,10 +105,6 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi /* TODO: Implement this ie */ IOff = IOff + 4; break; - case Q931ie_SHIFT: - /* TODO: Implement this ie */ - IOff++; - break; default: return Q931E_ILLEGAL_IE; break; From 27cfa656c3e0239624e8d8399ce9a68fecd25a57 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 22:49:54 +0000 Subject: [PATCH 0341/1766] missing () git-svn-id: http://svn.openzap.org/svn/openzap/trunk@171 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931ie.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index 76633e1882..c5e4a31534 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -98,7 +98,7 @@ typedef enum { /* Variable Length Codeset 6 Information Elements */ -#define Q931ie_GENERIC_DIGITS Q931_CODESET_6 | 0x37 /* 0011 0111 */ +#define Q931ie_GENERIC_DIGITS (Q931_CODESET_6 | 0x37) /* 0011 0111 */ From fcade4c016ee44023de20022c88093eb3d162378 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 May 2007 22:49:54 +0000 Subject: [PATCH 0342/1766] missing () git-svn-id: http://svn.openzap.org/svn/openzap/trunk@171 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931ie.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index 76633e1882..c5e4a31534 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -98,7 +98,7 @@ typedef enum { /* Variable Length Codeset 6 Information Elements */ -#define Q931ie_GENERIC_DIGITS Q931_CODESET_6 | 0x37 /* 0011 0111 */ +#define Q931ie_GENERIC_DIGITS (Q931_CODESET_6 | 0x37) /* 0011 0111 */ From 68b898c69e9a924df676557685479bb92f37372a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 02:42:32 +0000 Subject: [PATCH 0343/1766] better implement Q931Uie_GenericDigits. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@172 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 1 + libs/openzap/src/isdn/Q931ie.c | 81 +++++++++++++++++++------- libs/openzap/src/isdn/include/Q931.h | 3 +- libs/openzap/src/isdn/include/Q931ie.h | 3 + 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 29fff86284..533e10c4df 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -710,6 +710,7 @@ static const char *q931_error_names[] = { "Q931E_RESTARTIND", /* -3027 */ "Q931E_SEGMENT", /* -3028 */ "Q931E_SIGNAL", /* -3029 */ + "Q931E_GENERIC_DIGITS" /* -3030 */ }; diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 75531cad82..c25a8f47dd 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -2998,27 +2998,64 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U { Q931ie_GenericDigits * pie = (Q931ie_GenericDigits*)OBuf; ie *pIE = &pMsg->GenericDigits; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet++]; - - /* Octet 2 */ - IESize = IBuf[Octet++]; - - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_GenericDigits) + x -1; - - pie->Size = (L3UCHAR)(sizeof(Q931ie_GenericDigits) + x -1); - - return Q931E_NO_ERROR; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Type = (IBuf[Octet]) & 0x1F; + pie->Encoding = (IBuf[Octet] >> 5) & 0x07; + Octet ++; + + /* Octet 4*/ + if (pie->Type == 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->Type == 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->Type == 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; } /***************************************************************************** @@ -3036,7 +3073,7 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U L3INT Q931Pie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { OBuf[(*Octet)++] = (Q931ie_GENERIC_DIGITS & 0xFF); - OBuf[(*Octet)++] = 2; + OBuf[(*Octet)++] = 0; return Q931E_NO_ERROR; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 346460a2ba..87f0bb8d62 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -153,7 +153,8 @@ typedef enum { Q931E_PROGIND = -3026, Q931E_RESTARTIND = -3027, Q931E_SEGMENT = -3028, - Q931E_SIGNAL = -3029 + Q931E_SIGNAL = -3029, + Q931E_GENERIC_DIGITS = -3030 } q931_error_t; diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index c5e4a31534..4f498670da 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -1077,6 +1077,9 @@ 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; From 0d489b1a52f539f7fad04a7b16720023bc6e0a95 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 02:42:32 +0000 Subject: [PATCH 0344/1766] better implement Q931Uie_GenericDigits. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@172 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 1 + libs/freetdm/src/isdn/Q931ie.c | 81 +++++++++++++++++++------- libs/freetdm/src/isdn/include/Q931.h | 3 +- libs/freetdm/src/isdn/include/Q931ie.h | 3 + 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 29fff86284..533e10c4df 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -710,6 +710,7 @@ static const char *q931_error_names[] = { "Q931E_RESTARTIND", /* -3027 */ "Q931E_SEGMENT", /* -3028 */ "Q931E_SIGNAL", /* -3029 */ + "Q931E_GENERIC_DIGITS" /* -3030 */ }; diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 75531cad82..c25a8f47dd 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -2998,27 +2998,64 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U { Q931ie_GenericDigits * pie = (Q931ie_GenericDigits*)OBuf; ie *pIE = &pMsg->GenericDigits; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; - - *pIE=0; - - /* Octet 1 */ - pie->IEId = IBuf[Octet++]; - - /* Octet 2 */ - IESize = IBuf[Octet++]; - - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_GenericDigits) + x -1; - - pie->Size = (L3UCHAR)(sizeof(Q931ie_GenericDigits) + x -1); - - return Q931E_NO_ERROR; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; + + *pIE=0; + + /* Octet 1 */ + pie->IEId = IBuf[Octet]; + Octet ++; + + /* Octet 2 */ + IESize = IBuf[Octet ++]; + + /* Octet 3 */ + pie->Type = (IBuf[Octet]) & 0x1F; + pie->Encoding = (IBuf[Octet] >> 5) & 0x07; + Octet ++; + + /* Octet 4*/ + if (pie->Type == 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->Type == 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->Type == 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; } /***************************************************************************** @@ -3036,7 +3073,7 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U L3INT Q931Pie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { OBuf[(*Octet)++] = (Q931ie_GENERIC_DIGITS & 0xFF); - OBuf[(*Octet)++] = 2; + OBuf[(*Octet)++] = 0; return Q931E_NO_ERROR; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 346460a2ba..87f0bb8d62 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -153,7 +153,8 @@ typedef enum { Q931E_PROGIND = -3026, Q931E_RESTARTIND = -3027, Q931E_SEGMENT = -3028, - Q931E_SIGNAL = -3029 + Q931E_SIGNAL = -3029, + Q931E_GENERIC_DIGITS = -3030 } q931_error_t; diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index c5e4a31534..4f498670da 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -1077,6 +1077,9 @@ 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; From 8f76c671c1fcb376b0d4f8715730dc2e515d5ed8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 02:44:14 +0000 Subject: [PATCH 0345/1766] use Q931Uie_GenericDigits for national isdn setup message parser. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@173 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/nationalmes.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index a0b4f195bd..7d40b273ee 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -89,6 +89,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi case Q931ie_TRANSIT_NETWORK_SELECTION: case Q931ie_LOW_LAYER_COMPATIBILITY: case Q931ie_HIGH_LAYER_COMPATIBILITY: + 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; @@ -101,10 +102,6 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi return Q931E_ILLEGAL_IE; } break; - case Q931ie_GENERIC_DIGITS: - /* TODO: Implement this ie */ - IOff = IOff + 4; - break; default: return Q931E_ILLEGAL_IE; break; From 620c9f583386a647f83207e4b9491b80b1022b77 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 02:44:14 +0000 Subject: [PATCH 0346/1766] use Q931Uie_GenericDigits for national isdn setup message parser. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@173 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/nationalmes.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index a0b4f195bd..7d40b273ee 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -89,6 +89,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi case Q931ie_TRANSIT_NETWORK_SELECTION: case Q931ie_LOW_LAYER_COMPATIBILITY: case Q931ie_HIGH_LAYER_COMPATIBILITY: + 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; @@ -101,10 +102,6 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi return Q931E_ILLEGAL_IE; } break; - case Q931ie_GENERIC_DIGITS: - /* TODO: Implement this ie */ - IOff = IOff + 4; - break; default: return Q931E_ILLEGAL_IE; break; From 8c0b033418f93d863d7d5205d886c00bc473ccb7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 03:08:41 +0000 Subject: [PATCH 0347/1766] off by 1 error in Q931Uie_CalledNum. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@174 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index c25a8f47dd..ab3d683612 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -706,8 +706,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *pIE=0; /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; /* Octet 2 */ IESize = IBuf[Octet ++]; @@ -718,7 +717,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR Octet ++; /* Octet 4*/ - for (x = 0; x < IESize; x++) + for (x = 0; x < IESize - 1; x++) { pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; From b928b60c87fb0e8729b8c4e810973f059dfea604 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 03:08:41 +0000 Subject: [PATCH 0348/1766] off by 1 error in Q931Uie_CalledNum. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@174 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index c25a8f47dd..ab3d683612 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -706,8 +706,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *pIE=0; /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; /* Octet 2 */ IESize = IBuf[Octet ++]; @@ -718,7 +717,7 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR Octet ++; /* Octet 4*/ - for (x = 0; x < IESize; x++) + for (x = 0; x < IESize - 1; x++) { pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; From 524ed2ba1c37ddf32af20e4480304712d3a00662 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 03:15:18 +0000 Subject: [PATCH 0349/1766] typos. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@175 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 2 +- libs/openzap/src/isdn/Q931ie.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 533e10c4df..191797d01d 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -714,7 +714,7 @@ static const char *q931_error_names[] = { }; -#define Q931_MAX_ERROR 29 +#define Q931_MAX_ERROR 30 const char *q931_error_to_name(q931_error_t error) { diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index ab3d683612..5c3ea473fc 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -3017,14 +3017,14 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U Octet ++; /* Octet 4*/ - if (pie->Type == 0) { /* BCD Even */ + 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->Type == 1) { /* BCD Odd */ + } else if (pie->Encoding == 1) { /* BCD Odd */ x = 0; do { pie->Digit[x++] = IBuf[Octet+Off] & 0x0f; @@ -3034,7 +3034,7 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U x++; Off++; } while (Q931MoreIE()); - } else if (pie->Type == 2) { /* IA5 */ + } else if (pie->Encoding == 2) { /* IA5 */ x = 0; do { pie->Digit[x++] = IBuf[Octet+Off] & 0x7f; From e5f0aba40beaa087eaa7138903b6af1a2f05504d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 03:15:18 +0000 Subject: [PATCH 0350/1766] typos. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@175 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 2 +- libs/freetdm/src/isdn/Q931ie.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 533e10c4df..191797d01d 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -714,7 +714,7 @@ static const char *q931_error_names[] = { }; -#define Q931_MAX_ERROR 29 +#define Q931_MAX_ERROR 30 const char *q931_error_to_name(q931_error_t error) { diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index ab3d683612..5c3ea473fc 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -3017,14 +3017,14 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U Octet ++; /* Octet 4*/ - if (pie->Type == 0) { /* BCD Even */ + 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->Type == 1) { /* BCD Odd */ + } else if (pie->Encoding == 1) { /* BCD Odd */ x = 0; do { pie->Digit[x++] = IBuf[Octet+Off] & 0x0f; @@ -3034,7 +3034,7 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U x++; Off++; } while (Q931MoreIE()); - } else if (pie->Type == 2) { /* IA5 */ + } else if (pie->Encoding == 2) { /* IA5 */ x = 0; do { pie->Digit[x++] = IBuf[Octet+Off] & 0x7f; From c48ce7994f2962e3ff32edaf4917c0cdbf2c55a0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 04:13:24 +0000 Subject: [PATCH 0351/1766] Correct crv handling. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@176 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 8 ++++++-- libs/openzap/src/isdn/Q931StateTE.c | 30 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 191797d01d..f57365ecda 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -337,6 +337,10 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Starting Codeset */ m->codeset = Q931_CODESET_0; + if (m->ProtDisc != 8) { + return Q931E_UNKNOWN_MESSAGE; + } + /* Call table proc to unpack codec message */ RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); @@ -533,7 +537,7 @@ 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].InUse) { if(pTrunk->call[x].CRV == iCRV) { @@ -601,7 +605,7 @@ 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].InUse) { if(pTrunk->call[x].CRV == crv) { diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index eb9c2a38fb..941d683710 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -793,15 +793,19 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret=Q931E_NO_ERROR; Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - /* Find the call using CRV */ - ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); - if(ret != Q931E_NO_ERROR) - return ret; + + 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, 303); + } /* TODO chack against state table for illegal or unexpected message here*/ - /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { /* TODO Add proc here*/ @@ -826,15 +830,17 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret=Q931E_NO_ERROR; Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - /* Find the call using CRV */ - ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); - if(ret != Q931E_NO_ERROR) - return ret; + 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, 303); + } /* TODO chack against state table for illegal or unexpected message here*/ - /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { /* TODO Add proc here*/ From d831192a876932910e108b97800329fd6fd5ca14 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 04:13:24 +0000 Subject: [PATCH 0352/1766] Correct crv handling. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@176 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 8 ++++++-- libs/freetdm/src/isdn/Q931StateTE.c | 30 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 191797d01d..f57365ecda 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -337,6 +337,10 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Starting Codeset */ m->codeset = Q931_CODESET_0; + if (m->ProtDisc != 8) { + return Q931E_UNKNOWN_MESSAGE; + } + /* Call table proc to unpack codec message */ RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); @@ -533,7 +537,7 @@ 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].InUse) { if(pTrunk->call[x].CRV == iCRV) { @@ -601,7 +605,7 @@ 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].InUse) { if(pTrunk->call[x].CRV == crv) { diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index eb9c2a38fb..941d683710 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -793,15 +793,19 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret=Q931E_NO_ERROR; Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - /* Find the call using CRV */ - ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); - if(ret != Q931E_NO_ERROR) - return ret; + + 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, 303); + } /* TODO chack against state table for illegal or unexpected message here*/ - /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { /* TODO Add proc here*/ @@ -826,15 +830,17 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret=Q931E_NO_ERROR; Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - /* Find the call using CRV */ - ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex); - if(ret != Q931E_NO_ERROR) - return ret; + 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, 303); + } /* TODO chack against state table for illegal or unexpected message here*/ - /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { /* TODO Add proc here*/ From 722cd2117042d55b31377a7e64c4d696bccfa8b2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 06:53:39 +0000 Subject: [PATCH 0353/1766] prepwork for zt hardware interface. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@177 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 2 - libs/openzap/src/include/zap_zt.h | 154 +++++++++++++++++++++++++++++- libs/openzap/src/zap_zt.c | 36 +++---- 3 files changed, 167 insertions(+), 25 deletions(-) diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 1a60eded45..9e936194cf 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -344,7 +344,6 @@ > Date: Tue, 29 May 2007 06:53:39 +0000 Subject: [PATCH 0354/1766] prepwork for zt hardware interface. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@177 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 2 - libs/freetdm/src/include/zap_zt.h | 154 +++++++++++++++++++++++++++++- libs/freetdm/src/zap_zt.c | 36 +++---- 3 files changed, 167 insertions(+), 25 deletions(-) diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 1a60eded45..9e936194cf 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -344,7 +344,6 @@ > Date: Tue, 29 May 2007 15:32:37 +0000 Subject: [PATCH 0355/1766] remove codeset form generic message struct, it doesn't belong there, this is still messy, need a cleaner way. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@178 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 3 - libs/openzap/src/isdn/include/Q931.h | 5 -- libs/openzap/src/isdn/include/Q931ie.h | 2 +- libs/openzap/src/isdn/nationalmes.c | 85 ++++++++++++++++---------- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index f57365ecda..6c0b65613c 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -334,9 +334,6 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Message Type */ m->MesType = Mes[IOff++]; - /* Starting Codeset */ - m->codeset = Q931_CODESET_0; - if (m->ProtDisc != 8) { return Q931E_UNKNOWN_MESSAGE; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 87f0bb8d62..4e16a2a555 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -372,11 +372,6 @@ typedef struct L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ L3INT CRV; /* Call reference value */ - L3UINT codeset; /* Current Codeset - Temporary variable */ - /* used for the Q931Uie functions */ - /* in a parsed message this will only */ - /* indicate the codeset of the last */ - /* ie parsed */ ie Shift; ie MoreData; diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index 4f498670da..f6f2870db0 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -98,7 +98,7 @@ typedef enum { /* Variable Length Codeset 6 Information Elements */ -#define Q931ie_GENERIC_DIGITS (Q931_CODESET_6 | 0x37) /* 0011 0111 */ +#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 7d40b273ee..62cecf9270 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -56,55 +56,74 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi L3INT ir=0; L3INT OOff=0; L3INT rc=Q931E_NO_ERROR; - L3UINT last_codeset = mes->codeset; + L3UCHAR last_codeset = 0, codeset = 0; L3UCHAR shift_lock = 1; while(IOff < Size) { if (!shift_lock) { - mes->codeset = last_codeset; + codeset = last_codeset; } if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) { - mes->codeset = ((IBuf[IOff] & 0x07) << 8); shift_lock = (IBuf[IOff] & 0x08); + if (shift_lock) { + last_codeset = codeset; + } + codeset = ((IBuf[IOff] & 0x07) << 8); IOff++; } - switch(mes->codeset | 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_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; - case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + 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); - ir++; - } else { + 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; } - break; - default: + } 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; - break; } } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; From ecfacdef7e194cbf27515e0ff6b88e52e700cdf5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 15:32:37 +0000 Subject: [PATCH 0356/1766] remove codeset form generic message struct, it doesn't belong there, this is still messy, need a cleaner way. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@178 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 3 - libs/freetdm/src/isdn/include/Q931.h | 5 -- libs/freetdm/src/isdn/include/Q931ie.h | 2 +- libs/freetdm/src/isdn/nationalmes.c | 85 ++++++++++++++++---------- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index f57365ecda..6c0b65613c 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -334,9 +334,6 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Message Type */ m->MesType = Mes[IOff++]; - /* Starting Codeset */ - m->codeset = Q931_CODESET_0; - if (m->ProtDisc != 8) { return Q931E_UNKNOWN_MESSAGE; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 87f0bb8d62..4e16a2a555 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -372,11 +372,6 @@ typedef struct L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ L3INT CRV; /* Call reference value */ - L3UINT codeset; /* Current Codeset - Temporary variable */ - /* used for the Q931Uie functions */ - /* in a parsed message this will only */ - /* indicate the codeset of the last */ - /* ie parsed */ ie Shift; ie MoreData; diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index 4f498670da..f6f2870db0 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -98,7 +98,7 @@ typedef enum { /* Variable Length Codeset 6 Information Elements */ -#define Q931ie_GENERIC_DIGITS (Q931_CODESET_6 | 0x37) /* 0011 0111 */ +#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 7d40b273ee..62cecf9270 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -56,55 +56,74 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi L3INT ir=0; L3INT OOff=0; L3INT rc=Q931E_NO_ERROR; - L3UINT last_codeset = mes->codeset; + L3UCHAR last_codeset = 0, codeset = 0; L3UCHAR shift_lock = 1; while(IOff < Size) { if (!shift_lock) { - mes->codeset = last_codeset; + codeset = last_codeset; } if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) { - mes->codeset = ((IBuf[IOff] & 0x07) << 8); shift_lock = (IBuf[IOff] & 0x08); + if (shift_lock) { + last_codeset = codeset; + } + codeset = ((IBuf[IOff] & 0x07) << 8); IOff++; } - switch(mes->codeset | 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_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; - case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + 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); - ir++; - } else { + 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; } - break; - default: + } 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; - break; } } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; From c8f9f19b14d2c1f594a70f6ed74713634cf33eed Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 16:30:20 +0000 Subject: [PATCH 0357/1766] Add beginning of auto-restart functionality git-svn-id: http://svn.openzap.org/svn/openzap/trunk@179 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 3 +++ libs/openzap/src/isdn/Q931api.c | 27 +++++++++++++++++++++------ libs/openzap/src/isdn/include/Q931.h | 1 + libs/openzap/src/zap_isdn.c | 6 ++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 941d683710..fbdd9f08a7 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -813,6 +813,9 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else if (iFrom ==2) { + if (pTrunk->autoRestartAck) { + Q931AckRestart(pTrunk, buf); + } /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); } diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 36764e95a0..7930fa53db 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -39,6 +39,8 @@ #include "Q931.h" #include "memory.h" +extern L3INT Q931L4HeaderSpace; + /* L3INT Q931CreateMesIndex(L3INT mc) { @@ -109,12 +111,13 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, 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->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; @@ -541,3 +544,15 @@ L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo) return 0; } + +L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) +{ + L3INT RetCode; + + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; + + RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); + + return RetCode; +} diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 4e16a2a555..10a2e6e5dd 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -900,6 +900,7 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo); +L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf); L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 2076419ba8..55b58e890f 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -72,9 +72,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); - gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; - Q931Rx43(&data->q931, msg, gen->Size); - return 0; } @@ -246,7 +243,8 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D zap_isdn_931_err, &span->isdn_data->q921, span); - + + span->isdn_data->q931.autoRestartAck = 1; span->signal_type = ZAP_SIGTYPE_ISDN; From 577ffc85b558c4e6e3ed19d545db014910b2af11 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 16:30:20 +0000 Subject: [PATCH 0358/1766] Add beginning of auto-restart functionality git-svn-id: http://svn.openzap.org/svn/openzap/trunk@179 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 3 +++ libs/freetdm/src/isdn/Q931api.c | 27 +++++++++++++++++++++------ libs/freetdm/src/isdn/include/Q931.h | 1 + libs/freetdm/src/zap_isdn.c | 6 ++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 941d683710..fbdd9f08a7 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -813,6 +813,9 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else if (iFrom ==2) { + if (pTrunk->autoRestartAck) { + Q931AckRestart(pTrunk, buf); + } /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); } diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 36764e95a0..7930fa53db 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -39,6 +39,8 @@ #include "Q931.h" #include "memory.h" +extern L3INT Q931L4HeaderSpace; + /* L3INT Q931CreateMesIndex(L3INT mc) { @@ -109,12 +111,13 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, 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->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; @@ -541,3 +544,15 @@ L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo) return 0; } + +L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) +{ + L3INT RetCode; + + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; + + RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); + + return RetCode; +} diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 4e16a2a555..10a2e6e5dd 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -900,6 +900,7 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo); +L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf); L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 2076419ba8..55b58e890f 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -72,9 +72,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); - gen->MesType = Q931mes_RESTART_ACKNOWLEDGE; - Q931Rx43(&data->q931, msg, gen->Size); - return 0; } @@ -246,7 +243,8 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D zap_isdn_931_err, &span->isdn_data->q921, span); - + + span->isdn_data->q931.autoRestartAck = 1; span->signal_type = ZAP_SIGTYPE_ISDN; From d06d911671938bf6c3a1ebcb4e8332587626337b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 16:38:04 +0000 Subject: [PATCH 0359/1766] Don't mess with the message before we send it up to level 4. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@180 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index fbdd9f08a7..6d92423ec7 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -813,11 +813,12 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else if (iFrom ==2) { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + if (pTrunk->autoRestartAck) { Q931AckRestart(pTrunk, buf); } - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); } return ret; } From bd02ef423532b5b610154294922ed372242fc338 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 16:38:04 +0000 Subject: [PATCH 0360/1766] Don't mess with the message before we send it up to level 4. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@180 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index fbdd9f08a7..6d92423ec7 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -813,11 +813,12 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else if (iFrom ==2) { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + if (pTrunk->autoRestartAck) { Q931AckRestart(pTrunk, buf); } - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); } return ret; } From 99b102efc4e5f41a37dadba993a74d414b0b8be7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 16:47:22 +0000 Subject: [PATCH 0361/1766] fix setting of current codeset. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@181 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/nationalmes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 62cecf9270..41de1531c6 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -70,7 +70,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi if (shift_lock) { last_codeset = codeset; } - codeset = ((IBuf[IOff] & 0x07) << 8); + codeset = ((IBuf[IOff] & 0x07)); IOff++; } From acbb50c0573254b9ed923a9d8fd390f16ccc7c6c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 16:47:22 +0000 Subject: [PATCH 0362/1766] fix setting of current codeset. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@181 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/nationalmes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 62cecf9270..41de1531c6 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -70,7 +70,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi if (shift_lock) { last_codeset = codeset; } - codeset = ((IBuf[IOff] & 0x07) << 8); + codeset = ((IBuf[IOff] & 0x07)); IOff++; } From cadd9d569b86b75a4abe42aa44ed774f8235ae44 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 17:51:23 +0000 Subject: [PATCH 0363/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@182 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 146 +++++++++++++++--------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index ce52c3eae8..1b85af49ad 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -79,7 +79,7 @@ struct zt_confinfo { /* 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 receive_gain[256]; /* Receive gain table */ unsigned char transmit_gain[256]; /* Transmit gain table */ }; @@ -93,97 +93,97 @@ typedef enum { } 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_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_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_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_ONHOOK = 0, + ZT_OFFHOOK = 1, + ZT_WINK = 2, + ZT_FLASH = 3, + ZT_START = 4, + ZT_RING = 5, + ZT_RINGOFF = 6 } zt_hookstate_t; /* Defines */ -#define ZT_MAX_BLOCKSIZE 8192 -#define ZT_DEFAULT_MTU_MRU 2048 +#define ZT_MAX_BLOCKSIZE 8192 +#define ZT_DEFAULT_MTU_MRU 2048 /* ioctl defines */ #define ZT_CODE 'J' -#define ZT_GET_BLOCKSIZE _IOW (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_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_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */ - -#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_GET_BLOCKSIZE _IOW (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_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_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */ + +#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 */ + /* Openzap ZT hardware interface functions */ From 8cad28c2b19eade8b2e0d58ebd970f6ea590fae0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 17:51:23 +0000 Subject: [PATCH 0364/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@182 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 146 +++++++++++++++--------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index ce52c3eae8..1b85af49ad 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -79,7 +79,7 @@ struct zt_confinfo { /* 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 receive_gain[256]; /* Receive gain table */ unsigned char transmit_gain[256]; /* Transmit gain table */ }; @@ -93,97 +93,97 @@ typedef enum { } 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_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_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_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_ONHOOK = 0, + ZT_OFFHOOK = 1, + ZT_WINK = 2, + ZT_FLASH = 3, + ZT_START = 4, + ZT_RING = 5, + ZT_RINGOFF = 6 } zt_hookstate_t; /* Defines */ -#define ZT_MAX_BLOCKSIZE 8192 -#define ZT_DEFAULT_MTU_MRU 2048 +#define ZT_MAX_BLOCKSIZE 8192 +#define ZT_DEFAULT_MTU_MRU 2048 /* ioctl defines */ #define ZT_CODE 'J' -#define ZT_GET_BLOCKSIZE _IOW (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_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_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */ - -#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_GET_BLOCKSIZE _IOW (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_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_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */ + +#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 */ + /* Openzap ZT hardware interface functions */ From 68bc45d429613722f6fa1c6a635cb57fbca9515f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 20:22:10 +0000 Subject: [PATCH 0365/1766] add zt_spaninfo and ZT_SPANSTAT git-svn-id: http://svn.openzap.org/svn/openzap/trunk@183 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 1b85af49ad..b1defdb476 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -83,6 +83,25 @@ struct zt_gains { 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*/ +}; + /* Enumerations */ /* Values in zt_params structure for member g711_type */ @@ -159,6 +178,7 @@ typedef enum { #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_GETCONF _IOWR (ZT_CODE, 12, struct zt_confinfo) /* Get Conference Mode */ #define ZT_SETCONF _IOWR (ZT_CODE, 13, struct zt_confinfo) /* Set Conference Mode */ From 07f9009c3518d0ebee06f868f95e83267307cf17 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 20:22:10 +0000 Subject: [PATCH 0366/1766] add zt_spaninfo and ZT_SPANSTAT git-svn-id: http://svn.openzap.org/svn/openzap/trunk@183 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 1b85af49ad..b1defdb476 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -83,6 +83,25 @@ struct zt_gains { 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*/ +}; + /* Enumerations */ /* Values in zt_params structure for member g711_type */ @@ -159,6 +178,7 @@ typedef enum { #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_GETCONF _IOWR (ZT_CODE, 12, struct zt_confinfo) /* Get Conference Mode */ #define ZT_SETCONF _IOWR (ZT_CODE, 13, struct zt_confinfo) /* Set Conference Mode */ From 9ece0d8ba59d76c318214bf97dc9e4cfbcff887d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 20:29:46 +0000 Subject: [PATCH 0367/1766] add zt_maintinfo and ZT_MAINT ioctl. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@184 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index b1defdb476..bc070302d1 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -102,6 +102,11 @@ struct zt_spaninfo { int span_count; /* Total count of zaptel spans on the system*/ }; +struct zt_maintinfo { + int span_no; /* span number */ + int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */ +}; + /* Enumerations */ /* Values in zt_params structure for member g711_type */ @@ -159,6 +164,15 @@ typedef enum { 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; + /* Defines */ @@ -179,7 +193,7 @@ typedef enum { #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 */ From 77634068da14da88c7f6c43fbfc8941ec4524e60 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 29 May 2007 20:29:46 +0000 Subject: [PATCH 0368/1766] add zt_maintinfo and ZT_MAINT ioctl. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@184 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index b1defdb476..bc070302d1 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -102,6 +102,11 @@ struct zt_spaninfo { int span_count; /* Total count of zaptel spans on the system*/ }; +struct zt_maintinfo { + int span_no; /* span number */ + int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */ +}; + /* Enumerations */ /* Values in zt_params structure for member g711_type */ @@ -159,6 +164,15 @@ typedef enum { 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; + /* Defines */ @@ -179,7 +193,7 @@ typedef enum { #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 */ From 0f997a1fb95639896379321d890ffff491c466ca Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 May 2007 01:01:32 +0000 Subject: [PATCH 0369/1766] add guts for zt git-svn-id: http://svn.openzap.org/svn/openzap/trunk@185 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 2 +- libs/openzap/src/hashtable.c | 20 +- libs/openzap/src/include/hashtable.h | 2 +- libs/openzap/src/include/zap_types.h | 1 + libs/openzap/src/include/zap_zt.h | 18 +- libs/openzap/src/testanalog.c | 8 +- libs/openzap/src/testapp.c | 4 +- libs/openzap/src/zap_analog.c | 1 + libs/openzap/src/zap_io.c | 19 +- libs/openzap/src/zap_zt.c | 373 ++++++++++++++++++++++++++- 10 files changed, 405 insertions(+), 43 deletions(-) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index 2ff7f24232..7edd420cdf 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -9,6 +9,6 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) $(OZA): - cd $(OZ_DIR) && $(MAKE) ZAP_MODS=wanpipe + cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb" diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index c903d3ca67..fff5e99347 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -213,29 +213,19 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ void -hashtable_destroy(struct hashtable *h, int free_values) +hashtable_destroy(struct hashtable *h, int free_keys, int free_values) { unsigned int i; struct entry *e, *f; struct entry **table = h->table; - if (free_values) - { - for (i = 0; i < h->tablelength; i++) + + for (i = 0; i < h->tablelength; i++) { e = table[i]; while (NULL != e) - { f = e; e = e->next; freekey(f->k); free(f->v); free(f); } + { f = e; e = e->next; if (free_keys) freekey(f->k); if (free_values) free(f->v); free(f); } } - } - else - { - for (i = 0; i < h->tablelength; i++) - { - e = table[i]; - while (NULL != e) - { f = e; e = e->next; freekey(f->k); free(f); } - } - } + free(h->table); free(h); } diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index e6d23ff52f..4019a69ff9 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -166,7 +166,7 @@ hashtable_count(struct hashtable *h); */ void -hashtable_destroy(struct hashtable *h, int free_values); +hashtable_destroy(struct hashtable *h, int free_keys, int free_values); #endif /* __HASHTABLE_CWC22_H__ */ diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index d1fcb9248d..2c97f40aed 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -46,6 +46,7 @@ typedef int zap_socket_t; #endif typedef size_t zap_size_t; +typedef ssize_t zap_ssize_t; struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index bc070302d1..47b5470b7f 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -34,6 +34,8 @@ #ifndef ZAP_ZT_H #define ZAP_ZT_H #include "openzap.h" +#include +#include /* Hardware interface structures and defines */ /* Based on documentation of the structures required for the hardware interface */ @@ -69,6 +71,8 @@ struct zt_params { int pulse_after_time; }; +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 */ @@ -164,13 +168,13 @@ typedef enum { 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 */ +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; diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 82e9e8df89..c42f40fc46 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -71,11 +71,15 @@ int main(int argc, char *argv[]) zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); - if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + if (zap_span_find("zt", 1, &span) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); + exit(-1); } - zap_analog_configure_span(span, "us", 2000, 11, on_signal); + if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); + exit(-1); + } zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 75ddae66e5..d980a034df 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) top: //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open("zt", 1, 1, &chan) == ZAP_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) 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! %d [%s]\n", len, chan->last_error); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index b6314dc339..eb5c381d7d 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -253,6 +253,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 845cba7ef9..7890ceaaa2 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -229,9 +229,11 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) span = &zio->spans[i]; for(j = 0; j < span->chan_count; j++) { - zap_mutex_destroy(&span->channels[j].mutex); - zap_buffer_destroy(&span->channels[j].digit_buffer); - zap_buffer_destroy(&span->channels[j].dtmf_buffer); + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_CONFIGURED)) { + zap_mutex_destroy(&span->channels[j].mutex); + zap_buffer_destroy(&span->channels[j].digit_buffer); + zap_buffer_destroy(&span->channels[j].dtmf_buffer); + } } if (span->mutex) { @@ -1417,7 +1419,8 @@ zap_status_t zap_global_init(void) modcount = 0; zap_mutex_create(&globals.mutex); -#ifdef ZAP_WANPIPE_SUPPORT +#ifdef Z +AP_WANPIPE_SUPPORT if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { zap_mutex_lock(globals.mutex); hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); @@ -1483,18 +1486,20 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_ZT_SUPPORT if (interfaces.zt_interface) { - zt_destroy(); zap_span_close_all(interfaces.zt_interface); + zt_destroy(); } #endif #ifdef ZAP_WANPIPE_SUPPORT if (interfaces.wanpipe_interface) { - wanpipe_destroy(); zap_span_close_all(interfaces.wanpipe_interface); + wanpipe_destroy(); } #endif - hashtable_destroy(globals.interface_hash, 0); + zap_mutex_lock(globals.mutex); + hashtable_destroy(globals.interface_hash, 0, 0); + zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 57d006e8d3..c91c585c70 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -35,45 +35,393 @@ #include "openzap.h" #include "zap_zt.h" + +static struct { + uint32_t codec_ms; + uint32_t wink_ms; + uint32_t flash_ms; +} zt_globals; + +#define ZT_INVALID_SOCKET -1 + +static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) +{ + unsigned configured = 0, x; + char path[128] = ""; + zt_params_t ztp = {0}; + + for(x = start; x < end; x++) { + zap_channel_t *chan; + zap_socket_t sockfd = ZT_INVALID_SOCKET; + int command; + int len = zt_globals.codec_ms * 8; + + snprintf(path, sizeof(path), "/dev/zap/%d", x); + sockfd = open(path, O_RDWR); + + if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + command = ZT_START; +#if 0 + + if (ioctl(sockfd, ZT_HOOK, &command)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + + continue; + } +#endif + + if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } else { + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; + + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; + } + } + + + if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { + close(sockfd); + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + continue; + } + zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + if (ztp.g711_type == ZT_G711_ALAW) { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + } else { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + } + } + + 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++; + } else { + zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", path); + } + } + + return configured; +} + static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { - return ZAP_FAIL; + + int items, i; + char *mydata, *item_list[10]; + char *ch, *mx; + 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; + } + + configured += zt_open_range(span, channo, top, type, name, number); + + } + + free(mydata); + + return configured; + } static ZIO_CONFIGURE_FUNCTION(zt_configure) { - return ZAP_FAIL; + if (!strcasecmp(category, "defaults")) { + if (!strcasecmp(var, "codec_ms")) { + unsigned codec_ms = atoi(val); + if (codec_ms < 10 || codec_ms > 60) { + zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno); + } else { + zt_globals.codec_ms = codec_ms; + } + } + } + + return ZAP_SUCCESS; } static ZIO_OPEN_FUNCTION(zt_open) { ZIO_OPEN_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } static ZIO_CLOSE_FUNCTION(zt_close) { ZIO_CLOSE_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } static ZIO_COMMAND_FUNCTION(zt_command) { - return ZAP_FAIL; + zt_params_t ztp = {0}; + int err = 0; + + ZIO_COMMAND_MUZZLE; + + switch(command) { + case ZAP_COMMAND_GET_INTERVAL: + { + if (!(err = ioctl(zchan->sockfd, ZT_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, ZT_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; + default: + break; + }; + + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + + return ZAP_SUCCESS; } static ZIO_WAIT_FUNCTION(zt_wait) { - return ZAP_FAIL; + 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) { + *flags = 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; + } +ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) +{ + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + int i, j = 0, k = 0, r, e; + + for(i = 1; i <= span->chan_count; i++) { + e = ZT_IOMUX_SIGEVENT; + memset(&pfds[j], 0, sizeof(pfds[j])); + pfds[j].fd = span->channels[i].sockfd; + pfds[j].events = POLLPRI; + ioctl(span->channels[i].sockfd ,ZT_IOMUX, &e); + 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++; + } + } + + return k ? ZAP_SUCCESS : ZAP_FAIL; +} + +ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) +{ + uint32_t i, event_id; + zap_oob_event_t zt_event_id; + + 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, ZT_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_ONHOOK: + { + event_id = ZAP_OOB_ONHOOK; + } + break; + case ZT_EVENT_RINGOFFHOOK: + { + if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { + event_id = ZAP_OOB_OFFHOOK; + } else if (span->channels[i].type == ZAP_CHAN_TYPE_FXO) { + event_id = ZAP_OOB_RING_START; + } + } + break; + default: + { + zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); + 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; + +} + + static ZIO_READ_FUNCTION(zt_read) { + zap_ssize_t r = 0; + + *datalen = zchan->packet_len; + r = read(zchan->sockfd, data, *datalen); + + if (r >= 0) { + *datalen = r; + return ZAP_SUCCESS; + } + return ZAP_FAIL; } static ZIO_WRITE_FUNCTION(zt_write) { + zap_ssize_t w = 0; + + w = write(zchan->sockfd, data, *datalen); + + if (w >= 0) { + *datalen = w; + return ZAP_SUCCESS; + } + return ZAP_FAIL; } @@ -83,17 +431,26 @@ zap_status_t zt_init(zap_io_interface_t **zio) { assert(zio != NULL); memset(&zt_interface, 0, sizeof(zt_interface)); + memset(&zt_globals, 0, sizeof(zt_globals)); + + zt_globals.codec_ms = 20; + zt_globals.wink_ms = 150; + zt_globals.flash_ms = 750; zt_interface.name = "zt"; - zt_interface.configure = zt_configure; + zt_interface.configure = zt_configure; + zt_interface.configure_span = zt_configure_span; zt_interface.open = zt_open; zt_interface.close = zt_close; 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; + *zio = &zt_interface; - return ZAP_FAIL; + return ZAP_SUCCESS; } zap_status_t zt_destroy(void) From a04655dce59c2bfb60a44951279921e0cf8d2f5f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 May 2007 01:01:32 +0000 Subject: [PATCH 0370/1766] add guts for zt git-svn-id: http://svn.openzap.org/svn/openzap/trunk@185 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 2 +- libs/freetdm/src/hashtable.c | 20 +- libs/freetdm/src/include/hashtable.h | 2 +- libs/freetdm/src/include/zap_types.h | 1 + libs/freetdm/src/include/zap_zt.h | 18 +- libs/freetdm/src/testanalog.c | 8 +- libs/freetdm/src/testapp.c | 4 +- libs/freetdm/src/zap_analog.c | 1 + libs/freetdm/src/zap_io.c | 19 +- libs/freetdm/src/zap_zt.c | 373 ++++++++++++++++++++++++++- 10 files changed, 405 insertions(+), 43 deletions(-) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index 2ff7f24232..7edd420cdf 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -9,6 +9,6 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) $(OZA): - cd $(OZ_DIR) && $(MAKE) ZAP_MODS=wanpipe + cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb" diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index c903d3ca67..fff5e99347 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -213,29 +213,19 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ void -hashtable_destroy(struct hashtable *h, int free_values) +hashtable_destroy(struct hashtable *h, int free_keys, int free_values) { unsigned int i; struct entry *e, *f; struct entry **table = h->table; - if (free_values) - { - for (i = 0; i < h->tablelength; i++) + + for (i = 0; i < h->tablelength; i++) { e = table[i]; while (NULL != e) - { f = e; e = e->next; freekey(f->k); free(f->v); free(f); } + { f = e; e = e->next; if (free_keys) freekey(f->k); if (free_values) free(f->v); free(f); } } - } - else - { - for (i = 0; i < h->tablelength; i++) - { - e = table[i]; - while (NULL != e) - { f = e; e = e->next; freekey(f->k); free(f); } - } - } + free(h->table); free(h); } diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index e6d23ff52f..4019a69ff9 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -166,7 +166,7 @@ hashtable_count(struct hashtable *h); */ void -hashtable_destroy(struct hashtable *h, int free_values); +hashtable_destroy(struct hashtable *h, int free_keys, int free_values); #endif /* __HASHTABLE_CWC22_H__ */ diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index d1fcb9248d..2c97f40aed 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -46,6 +46,7 @@ typedef int zap_socket_t; #endif typedef size_t zap_size_t; +typedef ssize_t zap_ssize_t; struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index bc070302d1..47b5470b7f 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -34,6 +34,8 @@ #ifndef ZAP_ZT_H #define ZAP_ZT_H #include "openzap.h" +#include +#include /* Hardware interface structures and defines */ /* Based on documentation of the structures required for the hardware interface */ @@ -69,6 +71,8 @@ struct zt_params { int pulse_after_time; }; +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 */ @@ -164,13 +168,13 @@ typedef enum { 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 */ +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; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 82e9e8df89..c42f40fc46 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -71,11 +71,15 @@ int main(int argc, char *argv[]) zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); - if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + if (zap_span_find("zt", 1, &span) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); + exit(-1); } - zap_analog_configure_span(span, "us", 2000, 11, on_signal); + if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); + exit(-1); + } zap_analog_start(span); while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 75ddae66e5..d980a034df 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) top: //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open("zt", 1, 1, &chan) == ZAP_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) 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! %d [%s]\n", len, chan->last_error); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index b6314dc339..eb5c381d7d 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -253,6 +253,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 845cba7ef9..7890ceaaa2 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -229,9 +229,11 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) span = &zio->spans[i]; for(j = 0; j < span->chan_count; j++) { - zap_mutex_destroy(&span->channels[j].mutex); - zap_buffer_destroy(&span->channels[j].digit_buffer); - zap_buffer_destroy(&span->channels[j].dtmf_buffer); + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_CONFIGURED)) { + zap_mutex_destroy(&span->channels[j].mutex); + zap_buffer_destroy(&span->channels[j].digit_buffer); + zap_buffer_destroy(&span->channels[j].dtmf_buffer); + } } if (span->mutex) { @@ -1417,7 +1419,8 @@ zap_status_t zap_global_init(void) modcount = 0; zap_mutex_create(&globals.mutex); -#ifdef ZAP_WANPIPE_SUPPORT +#ifdef Z +AP_WANPIPE_SUPPORT if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { zap_mutex_lock(globals.mutex); hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); @@ -1483,18 +1486,20 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_ZT_SUPPORT if (interfaces.zt_interface) { - zt_destroy(); zap_span_close_all(interfaces.zt_interface); + zt_destroy(); } #endif #ifdef ZAP_WANPIPE_SUPPORT if (interfaces.wanpipe_interface) { - wanpipe_destroy(); zap_span_close_all(interfaces.wanpipe_interface); + wanpipe_destroy(); } #endif - hashtable_destroy(globals.interface_hash, 0); + zap_mutex_lock(globals.mutex); + hashtable_destroy(globals.interface_hash, 0, 0); + zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 57d006e8d3..c91c585c70 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -35,45 +35,393 @@ #include "openzap.h" #include "zap_zt.h" + +static struct { + uint32_t codec_ms; + uint32_t wink_ms; + uint32_t flash_ms; +} zt_globals; + +#define ZT_INVALID_SOCKET -1 + +static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) +{ + unsigned configured = 0, x; + char path[128] = ""; + zt_params_t ztp = {0}; + + for(x = start; x < end; x++) { + zap_channel_t *chan; + zap_socket_t sockfd = ZT_INVALID_SOCKET; + int command; + int len = zt_globals.codec_ms * 8; + + snprintf(path, sizeof(path), "/dev/zap/%d", x); + sockfd = open(path, O_RDWR); + + if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + command = ZT_START; +#if 0 + + if (ioctl(sockfd, ZT_HOOK, &command)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + + continue; + } +#endif + + if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } else { + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; + + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; + } + } + + + if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { + close(sockfd); + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + continue; + } + zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + if (ztp.g711_type == ZT_G711_ALAW) { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + } else { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + } + } + + 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++; + } else { + zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", path); + } + } + + return configured; +} + static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { - return ZAP_FAIL; + + int items, i; + char *mydata, *item_list[10]; + char *ch, *mx; + 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; + } + + configured += zt_open_range(span, channo, top, type, name, number); + + } + + free(mydata); + + return configured; + } static ZIO_CONFIGURE_FUNCTION(zt_configure) { - return ZAP_FAIL; + if (!strcasecmp(category, "defaults")) { + if (!strcasecmp(var, "codec_ms")) { + unsigned codec_ms = atoi(val); + if (codec_ms < 10 || codec_ms > 60) { + zap_log(ZAP_LOG_WARNING, "invalid codec ms at line %d\n", lineno); + } else { + zt_globals.codec_ms = codec_ms; + } + } + } + + return ZAP_SUCCESS; } static ZIO_OPEN_FUNCTION(zt_open) { ZIO_OPEN_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } static ZIO_CLOSE_FUNCTION(zt_close) { ZIO_CLOSE_MUZZLE; - return ZAP_FAIL; + return ZAP_SUCCESS; } static ZIO_COMMAND_FUNCTION(zt_command) { - return ZAP_FAIL; + zt_params_t ztp = {0}; + int err = 0; + + ZIO_COMMAND_MUZZLE; + + switch(command) { + case ZAP_COMMAND_GET_INTERVAL: + { + if (!(err = ioctl(zchan->sockfd, ZT_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, ZT_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; + default: + break; + }; + + if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } + + + return ZAP_SUCCESS; } static ZIO_WAIT_FUNCTION(zt_wait) { - return ZAP_FAIL; + 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) { + *flags = 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; + } +ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) +{ + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + int i, j = 0, k = 0, r, e; + + for(i = 1; i <= span->chan_count; i++) { + e = ZT_IOMUX_SIGEVENT; + memset(&pfds[j], 0, sizeof(pfds[j])); + pfds[j].fd = span->channels[i].sockfd; + pfds[j].events = POLLPRI; + ioctl(span->channels[i].sockfd ,ZT_IOMUX, &e); + 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++; + } + } + + return k ? ZAP_SUCCESS : ZAP_FAIL; +} + +ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) +{ + uint32_t i, event_id; + zap_oob_event_t zt_event_id; + + 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, ZT_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_ONHOOK: + { + event_id = ZAP_OOB_ONHOOK; + } + break; + case ZT_EVENT_RINGOFFHOOK: + { + if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { + event_id = ZAP_OOB_OFFHOOK; + } else if (span->channels[i].type == ZAP_CHAN_TYPE_FXO) { + event_id = ZAP_OOB_RING_START; + } + } + break; + default: + { + zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); + 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; + +} + + static ZIO_READ_FUNCTION(zt_read) { + zap_ssize_t r = 0; + + *datalen = zchan->packet_len; + r = read(zchan->sockfd, data, *datalen); + + if (r >= 0) { + *datalen = r; + return ZAP_SUCCESS; + } + return ZAP_FAIL; } static ZIO_WRITE_FUNCTION(zt_write) { + zap_ssize_t w = 0; + + w = write(zchan->sockfd, data, *datalen); + + if (w >= 0) { + *datalen = w; + return ZAP_SUCCESS; + } + return ZAP_FAIL; } @@ -83,17 +431,26 @@ zap_status_t zt_init(zap_io_interface_t **zio) { assert(zio != NULL); memset(&zt_interface, 0, sizeof(zt_interface)); + memset(&zt_globals, 0, sizeof(zt_globals)); + + zt_globals.codec_ms = 20; + zt_globals.wink_ms = 150; + zt_globals.flash_ms = 750; zt_interface.name = "zt"; - zt_interface.configure = zt_configure; + zt_interface.configure = zt_configure; + zt_interface.configure_span = zt_configure_span; zt_interface.open = zt_open; zt_interface.close = zt_close; 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; + *zio = &zt_interface; - return ZAP_FAIL; + return ZAP_SUCCESS; } zap_status_t zt_destroy(void) From a2dea73797bb17be37870360523da9ff0a0e8d42 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 May 2007 02:41:50 +0000 Subject: [PATCH 0371/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@186 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/openzap.conf | 19 ++ libs/openzap/conf/tones.conf | 5 + libs/openzap/conf/wanpipe.conf | 4 + libs/openzap/conf/zt.conf | 4 + libs/openzap/mod_openzap/mod_openzap.c | 67 +++--- libs/openzap/openzap.conf.ex | 38 ---- libs/openzap/src/include/openzap.h | 9 +- libs/openzap/src/include/zap_types.h | 10 +- libs/openzap/src/include/zap_zt.h | 30 +-- libs/openzap/src/testanalog.c | 17 +- libs/openzap/src/testapp.c | 11 +- libs/openzap/src/zap_analog.c | 254 +++++++++++------------ libs/openzap/src/zap_io.c | 274 ++++++++++++++----------- libs/openzap/src/zap_isdn.c | 2 +- libs/openzap/src/zap_wanpipe.c | 48 +++-- libs/openzap/src/zap_zt.c | 79 +++++-- 16 files changed, 488 insertions(+), 383 deletions(-) create mode 100644 libs/openzap/conf/openzap.conf create mode 100644 libs/openzap/conf/tones.conf create mode 100644 libs/openzap/conf/wanpipe.conf create mode 100644 libs/openzap/conf/zt.conf delete mode 100644 libs/openzap/openzap.conf.ex diff --git a/libs/openzap/conf/openzap.conf b/libs/openzap/conf/openzap.conf new file mode 100644 index 0000000000..d8a2f4b792 --- /dev/null +++ b/libs/openzap/conf/openzap.conf @@ -0,0 +1,19 @@ +[span wanpipe] +name => OpenZAP +number => 1 +fxs-channel => 1:3-4 + +[span wanpipe] +fxo-channel => 1:1-2 + +[span zt] +name => OpenZAP +number => 2 +fxs-channel => 1 + +[span zt] +name => OpenZAP +number => 2 +fxo-channel => 3 + + diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf new file mode 100644 index 0000000000..2032823d0c --- /dev/null +++ b/libs/openzap/conf/tones.conf @@ -0,0 +1,5 @@ +[us] +dial => %(1000,0,350,440) +ring => %(2000,4000,440,480) +busy => %(500,500,480,620) +attn => %(100,100,1400,2060,2450,2600) diff --git a/libs/openzap/conf/wanpipe.conf b/libs/openzap/conf/wanpipe.conf new file mode 100644 index 0000000000..ba609ac42e --- /dev/null +++ b/libs/openzap/conf/wanpipe.conf @@ -0,0 +1,4 @@ +[defaults] +codec_ms => 20 +wink_ms => 150 +flash_ms => 750 diff --git a/libs/openzap/conf/zt.conf b/libs/openzap/conf/zt.conf new file mode 100644 index 0000000000..ba609ac42e --- /dev/null +++ b/libs/openzap/conf/zt.conf @@ -0,0 +1,4 @@ +[defaults] +codec_ms => 20 +wink_ms => 150 +flash_ms => 750 diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 19530cf755..25612c196f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -88,6 +88,7 @@ struct private_object { switch_mutex_t *flag_mutex; zap_channel_t *zchan; int32_t token_id; + uint32_t wr_error; }; typedef struct private_object private_t; @@ -365,6 +366,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch zap_wait_flag_t wflags = ZAP_READ; char dtmf[128] = ""; zap_status_t status; + int total_to = timeout; + int chunk; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -374,6 +377,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); + chunk = tech_pvt->zchan->effective_interval * 2; + top: if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { switch_yield(tech_pvt->zchan->effective_interval * 1000); *frame = &tech_pvt->cng_frame; @@ -389,14 +394,20 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_FALSE; } - status = zap_channel_wait(tech_pvt->zchan, &wflags, timeout); + status = zap_channel_wait(tech_pvt->zchan, &wflags, chunk); if (status == ZAP_FAIL) { return SWITCH_STATUS_GENERR; } - + if (status == ZAP_TIMEOUT) { - return SWITCH_STATUS_BREAK; + if (timeout > 0 && !switch_test_flag(tech_pvt, TFLAG_HOLD)) { + total_to -= chunk; + if (total_to <= 0) { + return SWITCH_STATUS_BREAK; + } + } + goto top; } if (!(wflags & ZAP_READ)) { @@ -445,12 +456,16 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } - + len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, &len) != ZAP_SUCCESS) { - return SWITCH_STATUS_GENERR; + if (++tech_pvt->wr_error > 10) { + return SWITCH_STATUS_GENERR; + } } + tech_pvt->wr_error = 0; + return SWITCH_STATUS_SUCCESS; } @@ -628,6 +643,10 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in { switch_core_session_t *session = NULL; + if (id > ZAP_MAX_TOKENS) { + return NULL; + } + if (!switch_strlen_zero(channel->tokens[id])) { session = switch_core_session_locate(channel->tokens[id]); } @@ -648,7 +667,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) private_t *tech_pvt = NULL; zap_status_t status; - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: @@ -676,7 +695,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) for (i = 0; i < sigmsg->channel->token_count; i++) { if ((session = zap_channel_get_session(sigmsg->channel, i))) { tech_pvt = switch_core_session_get_private(session); - if (i) { + if (sigmsg->channel->token_count == 1) { + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } + } else if (i) { switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); @@ -685,23 +710,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } } } - case ZAP_SIGEVENT_HOLD: - { - if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { - tech_pvt = switch_core_session_get_private(session); - switch_set_flag_locked(tech_pvt, TFLAG_HOLD); - switch_core_session_rwunlock(session); - } - } - break; - case ZAP_SIGEVENT_UNHOLD: - { - if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { - tech_pvt = switch_core_session_get_private(session); - switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); - switch_core_session_rwunlock(session); - } - } break; } @@ -771,7 +779,6 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *mod = (char *) switch_xml_attr_soft(myspan, "module"); char *id = (char *) switch_xml_attr_soft(myspan, "id"); char *context = "default"; char *dialplan = "XML"; @@ -798,10 +805,6 @@ static switch_status_t load_config(void) } } - if (!mod) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'module'\n"); - } - if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); } @@ -820,13 +823,13 @@ static switch_status_t load_config(void) max = atoi(max_digits); } - if (zap_span_find(mod, span_id, &span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s:%d\n", mod, span_id); + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } if (zap_analog_configure_span(span, tonegroup, to, max, on_zap_signal) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %s:%d\n", mod, span_id); + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } diff --git a/libs/openzap/openzap.conf.ex b/libs/openzap/openzap.conf.ex deleted file mode 100644 index 3a01165ef9..0000000000 --- a/libs/openzap/openzap.conf.ex +++ /dev/null @@ -1,38 +0,0 @@ -[openzap] -load => wanpipe -;load => zt - -[+wanpipe.conf] -[span] -enabled => 1 -fxs-channel => 1:3-4 - - -[span] -enabled => 1 -fxo-channel => 1:1-2 - - -[+zt.conf] - -[span] -enabled => 0 -b-channel => 1-23 -d-channel=> 24 - -[span] -enabled => 0 -b-channel => 25-47 -d-channel=> 48 - -[span] -enabled => 0 -fxo-channel => 49 -fxs-channel => 50 - -[+tones.conf] -[us] -dial => %(1000,0,350,440) -ring => %(2000,4000,440,480) -busy => %(500,500,480,620) -attn => %(100,100,1400,2060,2450,2600) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3f47bc7a68..0d43156956 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -317,14 +317,13 @@ struct zap_io_interface { zio_configure_t configure; zio_open_t open; zio_close_t close; + zio_destroy_channel_t destroy_channel; zio_command_t command; zio_wait_t wait; zio_read_t read; zio_write_t write; zio_span_poll_event_t poll_event; zio_span_next_event_t next_event; - uint32_t span_index; - struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; void zap_channel_rotate_tokens(zap_channel_t *zchan); @@ -337,15 +336,15 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); zap_time_t zap_current_time_in_ms(void); zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); -zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); +zap_status_t zap_span_find(uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); zap_status_t zap_span_close_all(zap_io_interface_t *zio); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); -zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 2c97f40aed..9eb2082ec2 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -102,8 +102,6 @@ typedef enum { ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, ZAP_SIGEVENT_UP, - ZAP_SIGEVENT_HOLD, - ZAP_SIGEVENT_UNHOLD, ZAP_SIGEVENT_FLASH, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, @@ -111,7 +109,7 @@ typedef enum { ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "HOLD", "UNHOLD", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -222,7 +220,8 @@ typedef enum { ZAP_CHANNEL_WINK = (1 << 9), ZAP_CHANNEL_FLASH = (1 << 10), ZAP_CHANNEL_STATE_CHANGE = (1 << 11), - ZAP_CHANNEL_HOLD = (1 << 12) + ZAP_CHANNEL_HOLD = (1 << 12), + ZAP_CHANNEL_INUSE = (1 << 13) } zap_channel_flag_t; @@ -240,6 +239,7 @@ typedef struct zap_span zap_span_t; #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_DESTROY_CHANNEL_ARGS (zap_channel_t *zchan) #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_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) @@ -254,6 +254,7 @@ 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_destroy_channel_t) ZIO_DESTROY_CHANNEL_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 ; @@ -268,6 +269,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_DESTROY_CHANNEL_FUNCTION(name) zap_status_t name ZIO_DESTROY_CHANNEL_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 diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 47b5470b7f..48ee34bbc9 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -89,25 +89,25 @@ struct zt_gains { /* 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_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*/ }; struct zt_maintinfo { - int span_no; /* span number */ + int span_no; /* span number */ int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */ }; diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index c42f40fc46..5e27509259 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -61,6 +61,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) int main(int argc, char *argv[]) { zap_span_t *span; + int span_id; + + 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); @@ -71,14 +79,14 @@ int main(int argc, char *argv[]) zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); - if (zap_span_find("zt", 1, &span) != ZAP_SUCCESS) { + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); - exit(-1); + goto done; } if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); - exit(-1); + goto done; } zap_analog_start(span); @@ -86,6 +94,9 @@ int main(int argc, char *argv[]) zap_sleep(1 * 1000); } + + done: + zap_global_destroy(); } diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index d980a034df..309239c3d4 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -8,6 +8,12 @@ int main(int argc, char *argv[]) zap_codec_t codec = ZAP_CODEC_SLIN; unsigned runs = 1; + if (!argv[1]) { + printf("usage %s \n", argv[0]); + exit(-1); + } + + if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); exit(-1); @@ -17,7 +23,7 @@ int main(int argc, char *argv[]) top: //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open("zt", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open(argv[1], 1, 1, &chan) == ZAP_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); @@ -65,6 +71,9 @@ int main(int argc, char *argv[]) if(--runs) { goto top; } + + end: + zap_global_destroy(); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index eb5c381d7d..55acc7814e 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -165,6 +165,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } break; + case ZAP_CHANNEL_STATE_DOWN: + { + goto done; + } + break; default: break; } @@ -176,10 +181,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: { if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { - sig.event_id = ZAP_SIGEVENT_UNHOLD; + zap_clear_flag(chan, ZAP_CHANNEL_HOLD); + sig.event_id = ZAP_SIGEVENT_FLASH; } else { sig.event_id = ZAP_SIGEVENT_UP; } + data->sig_cb(&sig); continue; } @@ -199,14 +206,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } break; - case ZAP_CHANNEL_STATE_HOLD: - { - sig.event_id = ZAP_SIGEVENT_HOLD; - data->sig_cb(&sig); - zap_set_flag_locked(chan, ZAP_CHANNEL_HOLD); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); - } - break; case ZAP_CHANNEL_STATE_DIALTONE: { *dtmf = '\0'; @@ -242,126 +241,127 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { - zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); - } - dtmf_offset = strlen(dtmf); - last_digit = elapsed; - } - } - - - if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { - zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); - last_digit = 0; - } - - if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { - continue; - } - - if (!(flags & ZAP_READ)) { - continue; - } - - if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { - goto done; - } - - if (!indicate) { - continue; - } - - if (chan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } - - rlen = zap_buffer_read_loop(dt_buffer, frame, len); - - if (chan->effective_codec != ZAP_CODEC_SLIN) { - zio_codec_t codec_func = NULL; - - if (chan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } - - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); - goto done; - } - } - - zap_channel_write(chan, frame, &rlen); - } - - done: - - closed_chan = chan; - zap_channel_close(&chan); - - 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 CHANNEL thread ended.\n"); - - return NULL; -} - -static zap_status_t process_event(zap_span_t *span, zap_event_t *event) -{ - zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id); - - zap_mutex_lock(event->channel->mutex); + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { + zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + } + } - switch(event->enum_id) { - case ZAP_OOB_ONHOOK: - { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - break; - case ZAP_OOB_FLASH: - { - zap_sigmsg_t sig; - zap_analog_data_t *data = event->channel->span->analog_data; - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - sig.span = event->channel->span; - - if (event->channel->state == ZAP_CHANNEL_STATE_UP) { - if (event->channel->token_count > 1) { - zap_channel_rotate_tokens(event->channel); - sig.event_id = ZAP_SIGEVENT_FLASH; - data->sig_cb(&sig); - } else { - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { - zap_clear_flag_locked(event->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_HOLD); - } - } - } - } + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; + } + + if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; + } + + if (!(flags & ZAP_READ)) { + continue; + } + + if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + goto done; + } + + if (!indicate) { + continue; + } + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } + + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + goto done; + } + } + + zap_channel_write(chan, frame, &rlen); + } + + done: + + closed_chan = chan; + zap_channel_close(&chan); + + 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 CHANNEL thread ended.\n"); + + return NULL; + } + + static zap_status_t process_event(zap_span_t *span, zap_event_t *event) + { + zap_sigmsg_t sig; + zap_analog_data_t *data = event->channel->span->analog_data; + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; + sig.span = event->channel->span; + + 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); + + + switch(event->enum_id) { + case ZAP_OOB_ONHOOK: + { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); + } + break; + case ZAP_OOB_FLASH: + { + + sig.event_id = ZAP_SIGEVENT_FLASH; + zap_channel_rotate_tokens(event->channel); + + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); + } else { + data->sig_cb(&sig); + if (event->channel->token_count == 1) { + zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + } + } + } break; case ZAP_OOB_OFFHOOK: { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 7890ceaaa2..3154ac2c05 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -73,6 +73,8 @@ zap_time_t zap_current_time_in_ms(void) static struct { zap_hash_t *interface_hash; zap_mutex_t *mutex; + struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; + uint32_t span_index; } globals; @@ -198,14 +200,16 @@ static uint32_t hashfromstring(void *ky) zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; + zap_status_t status = ZAP_FAIL; assert(zio != NULL); - if (zio->span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = &zio->spans[++zio->span_index]; + zap_mutex_lock(globals.mutex); + if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { + new_span = &globals.spans[++globals.span_index]; memset(new_span, 0, sizeof(*new_span)); zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = zio->span_index; + new_span->span_id = globals.span_index; new_span->zio = zio; zap_mutex_create(&new_span->mutex); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); @@ -214,10 +218,11 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); new_span->trunk_type = ZAP_TRUNK_NONE; *span = new_span; - return ZAP_SUCCESS; + status = ZAP_SUCCESS; } - - return ZAP_FAIL; + zap_mutex_unlock(globals.mutex); + + return status; } zap_status_t zap_span_close_all(zap_io_interface_t *zio) @@ -225,8 +230,9 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) zap_span_t *span; uint32_t i, j; - for(i = 0; i < zio->span_index; i++) { - span = &zio->spans[i]; + zap_mutex_lock(globals.mutex); + for(i = 0; i < globals.span_index; i++) { + span = &globals.spans[i]; for(j = 0; j < span->chan_count; j++) { if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_CONFIGURED)) { @@ -246,7 +252,8 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) free(span->isdn_data); } } - + zap_mutex_unlock(globals.mutex); + return i ? ZAP_SUCCESS : ZAP_FAIL; } @@ -304,24 +311,17 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) +zap_status_t zap_span_find(uint32_t id, zap_span_t **span) { - zap_io_interface_t *zio; zap_span_t *fspan; - zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); - zap_mutex_unlock(globals.mutex); - - if (!zio) { - return ZAP_FAIL; - } - if (id > ZAP_MAX_SPANS_INTERFACE) { return ZAP_FAIL; } - fspan = &zio->spans[id]; + zap_mutex_lock(globals.mutex); + fspan = &globals.spans[id]; + zap_mutex_unlock(globals.mutex); if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; @@ -348,6 +348,8 @@ zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) if (span->zio->poll_event) { return span->zio->poll_event(span, ms); + } else { + zap_log(ZAP_LOG_ERROR, "poll_event method not implemented in module %s!", span->zio->name); } return ZAP_NOTIMPL; @@ -359,8 +361,10 @@ zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) if (span->zio->next_event) { return span->zio->next_event(span, event); + } else { + zap_log(ZAP_LOG_ERROR, "next_event method not implemented in module %s!", span->zio->name); } - + return ZAP_NOTIMPL; } @@ -403,9 +407,11 @@ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) void zap_channel_rotate_tokens(zap_channel_t *zchan) { - memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); - zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); - *zchan->tokens[zchan->token_count] = '\0'; + if (zchan->token_count) { + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); + *zchan->tokens[zchan->token_count] = '\0'; + } } zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) @@ -414,7 +420,8 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) zap_mutex_lock(zchan->mutex); if (zchan->token_count < ZAP_MAX_TOKENS) { - zap_copy_string(zchan->tokens[zchan->token_count], token, sizeof(zchan->tokens[zchan->token_count])); + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); zchan->token_count++; } zap_mutex_unlock(zchan->mutex); @@ -455,9 +462,8 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { - zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; @@ -465,18 +471,11 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct uint32_t span_max; zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); - zap_mutex_unlock(globals.mutex); - - if (!zio) { - zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); - return ZAP_FAIL; - } if (span_id) { span_max = span_id; } else { - span_max = zio->span_index; + span_max = globals.span_index; } if (direction == ZAP_TOP_DOWN) { @@ -485,10 +484,8 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct j = span_max; } - zap_mutex_lock(globals.mutex); - for(;;) { - span = &zio->spans[j]; + span = &globals.spans[j]; if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; @@ -523,13 +520,13 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct } check = &span->channels[i]; - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { status = check->zio->open(check); - + if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); + zap_set_flag(check, ZAP_CHANNEL_INUSE); *zchan = check; return status; } @@ -563,6 +560,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->event_callback = NULL; zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + zap_clear_flag(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; @@ -598,7 +596,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } - if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && !zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); @@ -609,33 +607,40 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) return status; } -zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) +zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { - zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); - zap_mutex_unlock(globals.mutex); - - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { + + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; - check = &zio->spans[span_id].channels[chan_id]; - if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { - return status; - } + check = &globals.spans[span_id].channels[chan_id]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; + if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + goto done; + } + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zio->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + } + } else { + status = ZAP_SUCCESS; } + zap_set_flag(check, ZAP_CHANNEL_INUSE); + *zchan = check; } zap_mutex_unlock(check->mutex); } + done: + + zap_mutex_unlock(globals.mutex); + return status; } @@ -649,7 +654,6 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(check != NULL); *zchan = NULL; - zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); @@ -1286,49 +1290,56 @@ static struct { } interfaces; -static uint32_t load_config(zap_io_interface_t *zio) +static zap_status_t load_config(void) { - char cfg_name[256]; + char cfg_name[] = "openzap.conf"; zap_config_t cfg; char *var, *val; int catno = -1; zap_span_t *span = NULL; - int new_span = 0; unsigned configured = 0, d = 0; char name[80] = ""; char number[25] = ""; - - assert(zio != NULL); - snprintf(cfg_name, sizeof(cfg_name), "%s.conf", zio->name); - - zap_log(ZAP_LOG_DEBUG, "configuring %s\n", zio->name); + zap_io_interface_t *zio = NULL; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "span")) { + if (!strncasecmp(cfg.category, "span", 4)) { if (cfg.catno != catno) { + char *type = cfg.category + 4; + if (*type == ' ') { + type++; + } + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; - new_span = 1; - span = NULL; - } - - if (new_span) { - if (!strcasecmp(var, "enabled") && ! zap_true(val)) { - zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); + + if (zap_strlen_zero(type)) { + zap_log(ZAP_LOG_CRIT, "failure creating span, no type specified.\n"); + span = NULL; + continue; + } + + zap_mutex_lock(globals.mutex); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type); + zap_mutex_unlock(globals.mutex); + + if (!zio) { + zap_log(ZAP_LOG_CRIT, "failure creating span, no such type '%s'\n", type); + span = NULL; + continue; + } + + if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); } else { - if (zap_span_create(zio, &span) == ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span\n"); - span = NULL; - } + zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); + span = NULL; + continue; } - new_span = 0; - continue; } if (!span) { @@ -1337,9 +1348,7 @@ static uint32_t load_config(zap_io_interface_t *zio) zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); - if (!strcasecmp(var, "enabled")) { - zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); - } else if (!strcasecmp(var, "trunk_type")) { + if (!strcasecmp(var, "trunk_type")) { span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "name")) { @@ -1391,24 +1400,47 @@ static uint32_t load_config(zap_io_interface_t *zio) d++; } } - } else if (zio->configure) { - zio->configure(cfg.category, var, val, cfg.lineno); } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); } } zap_config_close_file(&cfg); - zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); + zap_log(ZAP_LOG_INFO, "Configured %u channel(s)\n", configured); - return configured; + return configured ? ZAP_SUCCESS : ZAP_FAIL; +} + +static zap_status_t process_module_config(zap_io_interface_t *zio) +{ + zap_config_t cfg; + char *var, *val; + char filename[256] = ""; + assert(zio != NULL); + + snprintf(filename, sizeof(filename), "%s.conf", zio->name); + + if (!zio->configure) { + zap_log(ZAP_LOG_ERROR, "Module %s does not support configuration.\n", zio->name); + return ZAP_FAIL; + } + + if (!zap_config_open_file(&cfg, filename)) { + zap_log(ZAP_LOG_ERROR, "Cannot open %s\n", filename); + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + zio->configure(cfg.category, var, val, cfg.lineno); + } + + zap_config_close_file(&cfg); + + return ZAP_SUCCESS; } zap_status_t zap_global_init(void) { - zap_config_t cfg; - char *var, *val; - uint32_t configured = 0; int modcount; time_init(); @@ -1419,11 +1451,11 @@ zap_status_t zap_global_init(void) modcount = 0; zap_mutex_create(&globals.mutex); -#ifdef Z -AP_WANPIPE_SUPPORT +#ifdef ZAP_WANPIPE_SUPPORT if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { zap_mutex_lock(globals.mutex); hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); + process_module_config(interfaces.wanpipe_interface); zap_mutex_unlock(globals.mutex); modcount++; } else { @@ -1435,6 +1467,7 @@ AP_WANPIPE_SUPPORT if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) { zap_mutex_lock(globals.mutex); hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface); + process_module_config(interfaces.zt_interface); zap_mutex_unlock(globals.mutex); modcount++; } else { @@ -1447,32 +1480,7 @@ AP_WANPIPE_SUPPORT return ZAP_FAIL; } - if (!zap_config_open_file(&cfg, "openzap.conf")) { - zap_log(ZAP_LOG_ERROR, "Cannot open openzap.conf!\n"); - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "openzap")) { - if (!strcmp(var, "load")) { - zap_io_interface_t *zio; - - zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, val); - zap_mutex_unlock(globals.mutex); - - if (zio) { - configured += load_config(zio); - } else { - zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val); - } - } - } - } - - zap_config_close_file(&cfg); - - if (configured) { + if (load_config() == ZAP_SUCCESS) { return ZAP_SUCCESS; } @@ -1482,7 +1490,31 @@ AP_WANPIPE_SUPPORT zap_status_t zap_global_destroy(void) { + unsigned int i,j; time_end(); + + for(i = 1; i <= globals.span_index; i++) { + zap_span_t *cur_span = &globals.spans[i]; + + if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { + zap_mutex_lock(cur_span->mutex); + for(j = 1; j <= cur_span->chan_count; j++) { + zap_channel_t *cur_chan = &cur_span->channels[j]; + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + if (cur_span->zio->destroy_channel) { + zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); + if (cur_span->zio->destroy_channel(cur_chan) == ZAP_SUCCESS) { + zap_clear_flag_locked(cur_chan, ZAP_CHANNEL_CONFIGURED); + } else { + zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); + } + } + } + } + zap_mutex_unlock(cur_span->mutex); + } + } + #ifdef ZAP_ZT_SUPPORT if (interfaces.zt_interface) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 55b58e890f..7bca3922b1 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -202,7 +202,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D for(i = 1; i <= span->chan_count; i++) { if (span->channels[i].type == ZAP_CHAN_TYPE_DQ921) { - if (zap_channel_open(span->zio->name, span->span_id, i, &dchans[x]) == ZAP_SUCCESS) { + 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); x++; } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index fc14f0ad8f..9d3dcc43f1 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -108,13 +108,29 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) { + int num; + if (!strcasecmp(category, "defaults")) { if (!strcasecmp(var, "codec_ms")) { - unsigned codec_ms = atoi(val); - if (codec_ms < 10 || codec_ms > 60) { + 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 = codec_ms; + wp_globals.codec_ms = num; + } + } else if (!strcasecmp(var, "wink_ms")) { + num = atoi(val); + if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno); + } else { + wp_globals.flash_ms = num; } } } @@ -479,6 +495,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } +static ZIO_DESTROY_CHANNEL_FUNCTION(wanpipe_destroy_channel) +{ + tdmv_api_close_socket(&zchan->sockfd); + zchan->sockfd = WP_INVALID_SOCKET; + + return ZAP_SUCCESS; +} + zap_status_t wanpipe_init(zap_io_interface_t **zio) { assert(zio != NULL); @@ -500,6 +524,7 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wanpipe_interface.poll_event = wanpipe_poll_event; #endif wanpipe_interface.next_event = wanpipe_next_event; + wanpipe_interface.destroy_channel = wanpipe_destroy_channel; *zio = &wanpipe_interface; return ZAP_SUCCESS; @@ -507,23 +532,6 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) zap_status_t wanpipe_destroy(void) { - unsigned int i,j; - - for(i = 1; i <= wanpipe_interface.span_index; i++) { - zap_span_t *cur_span = &wanpipe_interface.spans[i]; - - if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { - for(j = 1; j <= cur_span->chan_count; j++) { - zap_channel_t *cur_chan = &cur_span->channels[j]; - if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - tdmv_api_close_socket(&cur_chan->sockfd); - } - } - } - } - memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); - return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index c91c585c70..9f86ffe01f 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -54,7 +54,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_channel_t *chan; zap_socket_t sockfd = ZT_INVALID_SOCKET; int command; - int len = zt_globals.codec_ms * 8; + int len; snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); @@ -70,25 +70,26 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za continue; } #endif - + + + len = zt_globals.codec_ms * 8; if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; - } else { - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; - - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; - } + } + + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; + + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; } - if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { - close(sockfd); zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); continue; } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); @@ -100,7 +101,16 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + + ztp.wink_time = zt_globals.wink_ms; + ztp.flash_time = zt_globals.flash_ms; + if (ioctl(sockfd, ZT_SET_PARAMS, &ztp) < 0) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); } @@ -175,17 +185,34 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) static ZIO_CONFIGURE_FUNCTION(zt_configure) { + + int num; + if (!strcasecmp(category, "defaults")) { if (!strcasecmp(var, "codec_ms")) { - unsigned codec_ms = atoi(val); - if (codec_ms < 10 || codec_ms > 60) { + 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 = codec_ms; + zt_globals.codec_ms = num; + } + } else if (!strcasecmp(var, "wink_ms")) { + num = atoi(val); + if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno); + } else { + zt_globals.flash_ms = num; } } } - + return ZAP_SUCCESS; } @@ -364,6 +391,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) event_id = ZAP_OOB_ONHOOK; } break; + case ZT_EVENT_WINKFLASH: + { + if (span->channels[i].state == ZAP_CHANNEL_STATE_DOWN) { + 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) { @@ -425,6 +461,14 @@ static ZIO_WRITE_FUNCTION(zt_write) return ZAP_FAIL; } +static ZIO_DESTROY_CHANNEL_FUNCTION(zt_destroy_channel) +{ + close(zchan->sockfd); + zchan->sockfd = ZT_INVALID_SOCKET; + + return ZAP_SUCCESS; +} + static zap_io_interface_t zt_interface; zap_status_t zt_init(zap_io_interface_t **zio) @@ -447,6 +491,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_interface.write = zt_write; zt_interface.poll_event = zt_poll_event; zt_interface.next_event = zt_next_event; + zt_interface.destroy_channel = zt_destroy_channel; *zio = &zt_interface; @@ -455,5 +500,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zap_status_t zt_destroy(void) { - return ZAP_FAIL; + + memset(&zt_interface, 0, sizeof(zt_interface)); + return ZAP_SUCCESS; } From 4b5e0836806bb1e63cd5510ad2aa53957f2d81bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 May 2007 02:41:50 +0000 Subject: [PATCH 0372/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@186 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/openzap.conf | 19 ++ libs/freetdm/conf/tones.conf | 5 + libs/freetdm/conf/wanpipe.conf | 4 + libs/freetdm/conf/zt.conf | 4 + libs/freetdm/mod_openzap/mod_openzap.c | 67 +++--- libs/freetdm/openzap.conf.ex | 38 ---- libs/freetdm/src/include/openzap.h | 9 +- libs/freetdm/src/include/zap_types.h | 10 +- libs/freetdm/src/include/zap_zt.h | 30 +-- libs/freetdm/src/testanalog.c | 17 +- libs/freetdm/src/testapp.c | 11 +- libs/freetdm/src/zap_analog.c | 254 +++++++++++------------ libs/freetdm/src/zap_io.c | 274 ++++++++++++++----------- libs/freetdm/src/zap_isdn.c | 2 +- libs/freetdm/src/zap_wanpipe.c | 48 +++-- libs/freetdm/src/zap_zt.c | 79 +++++-- 16 files changed, 488 insertions(+), 383 deletions(-) create mode 100644 libs/freetdm/conf/openzap.conf create mode 100644 libs/freetdm/conf/tones.conf create mode 100644 libs/freetdm/conf/wanpipe.conf create mode 100644 libs/freetdm/conf/zt.conf delete mode 100644 libs/freetdm/openzap.conf.ex diff --git a/libs/freetdm/conf/openzap.conf b/libs/freetdm/conf/openzap.conf new file mode 100644 index 0000000000..d8a2f4b792 --- /dev/null +++ b/libs/freetdm/conf/openzap.conf @@ -0,0 +1,19 @@ +[span wanpipe] +name => OpenZAP +number => 1 +fxs-channel => 1:3-4 + +[span wanpipe] +fxo-channel => 1:1-2 + +[span zt] +name => OpenZAP +number => 2 +fxs-channel => 1 + +[span zt] +name => OpenZAP +number => 2 +fxo-channel => 3 + + diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf new file mode 100644 index 0000000000..2032823d0c --- /dev/null +++ b/libs/freetdm/conf/tones.conf @@ -0,0 +1,5 @@ +[us] +dial => %(1000,0,350,440) +ring => %(2000,4000,440,480) +busy => %(500,500,480,620) +attn => %(100,100,1400,2060,2450,2600) diff --git a/libs/freetdm/conf/wanpipe.conf b/libs/freetdm/conf/wanpipe.conf new file mode 100644 index 0000000000..ba609ac42e --- /dev/null +++ b/libs/freetdm/conf/wanpipe.conf @@ -0,0 +1,4 @@ +[defaults] +codec_ms => 20 +wink_ms => 150 +flash_ms => 750 diff --git a/libs/freetdm/conf/zt.conf b/libs/freetdm/conf/zt.conf new file mode 100644 index 0000000000..ba609ac42e --- /dev/null +++ b/libs/freetdm/conf/zt.conf @@ -0,0 +1,4 @@ +[defaults] +codec_ms => 20 +wink_ms => 150 +flash_ms => 750 diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 19530cf755..25612c196f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -88,6 +88,7 @@ struct private_object { switch_mutex_t *flag_mutex; zap_channel_t *zchan; int32_t token_id; + uint32_t wr_error; }; typedef struct private_object private_t; @@ -365,6 +366,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch zap_wait_flag_t wflags = ZAP_READ; char dtmf[128] = ""; zap_status_t status; + int total_to = timeout; + int chunk; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -374,6 +377,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); + chunk = tech_pvt->zchan->effective_interval * 2; + top: if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { switch_yield(tech_pvt->zchan->effective_interval * 1000); *frame = &tech_pvt->cng_frame; @@ -389,14 +394,20 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_FALSE; } - status = zap_channel_wait(tech_pvt->zchan, &wflags, timeout); + status = zap_channel_wait(tech_pvt->zchan, &wflags, chunk); if (status == ZAP_FAIL) { return SWITCH_STATUS_GENERR; } - + if (status == ZAP_TIMEOUT) { - return SWITCH_STATUS_BREAK; + if (timeout > 0 && !switch_test_flag(tech_pvt, TFLAG_HOLD)) { + total_to -= chunk; + if (total_to <= 0) { + return SWITCH_STATUS_BREAK; + } + } + goto top; } if (!(wflags & ZAP_READ)) { @@ -445,12 +456,16 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } - + len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, &len) != ZAP_SUCCESS) { - return SWITCH_STATUS_GENERR; + if (++tech_pvt->wr_error > 10) { + return SWITCH_STATUS_GENERR; + } } + tech_pvt->wr_error = 0; + return SWITCH_STATUS_SUCCESS; } @@ -628,6 +643,10 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in { switch_core_session_t *session = NULL; + if (id > ZAP_MAX_TOKENS) { + return NULL; + } + if (!switch_strlen_zero(channel->tokens[id])) { session = switch_core_session_locate(channel->tokens[id]); } @@ -648,7 +667,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) private_t *tech_pvt = NULL; zap_status_t status; - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: @@ -676,7 +695,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) for (i = 0; i < sigmsg->channel->token_count; i++) { if ((session = zap_channel_get_session(sigmsg->channel, i))) { tech_pvt = switch_core_session_get_private(session); - if (i) { + if (sigmsg->channel->token_count == 1) { + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } + } else if (i) { switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); @@ -685,23 +710,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } } } - case ZAP_SIGEVENT_HOLD: - { - if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { - tech_pvt = switch_core_session_get_private(session); - switch_set_flag_locked(tech_pvt, TFLAG_HOLD); - switch_core_session_rwunlock(session); - } - } - break; - case ZAP_SIGEVENT_UNHOLD: - { - if ((session = zap_channel_get_session(sigmsg->channel, sigmsg->channel->token_count-1))) { - tech_pvt = switch_core_session_get_private(session); - switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); - switch_core_session_rwunlock(session); - } - } break; } @@ -771,7 +779,6 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *mod = (char *) switch_xml_attr_soft(myspan, "module"); char *id = (char *) switch_xml_attr_soft(myspan, "id"); char *context = "default"; char *dialplan = "XML"; @@ -798,10 +805,6 @@ static switch_status_t load_config(void) } } - if (!mod) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'module'\n"); - } - if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); } @@ -820,13 +823,13 @@ static switch_status_t load_config(void) max = atoi(max_digits); } - if (zap_span_find(mod, span_id, &span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s:%d\n", mod, span_id); + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } if (zap_analog_configure_span(span, tonegroup, to, max, on_zap_signal) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %s:%d\n", mod, span_id); + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } diff --git a/libs/freetdm/openzap.conf.ex b/libs/freetdm/openzap.conf.ex deleted file mode 100644 index 3a01165ef9..0000000000 --- a/libs/freetdm/openzap.conf.ex +++ /dev/null @@ -1,38 +0,0 @@ -[openzap] -load => wanpipe -;load => zt - -[+wanpipe.conf] -[span] -enabled => 1 -fxs-channel => 1:3-4 - - -[span] -enabled => 1 -fxo-channel => 1:1-2 - - -[+zt.conf] - -[span] -enabled => 0 -b-channel => 1-23 -d-channel=> 24 - -[span] -enabled => 0 -b-channel => 25-47 -d-channel=> 48 - -[span] -enabled => 0 -fxo-channel => 49 -fxs-channel => 50 - -[+tones.conf] -[us] -dial => %(1000,0,350,440) -ring => %(2000,4000,440,480) -busy => %(500,500,480,620) -attn => %(100,100,1400,2060,2450,2600) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 3f47bc7a68..0d43156956 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -317,14 +317,13 @@ struct zap_io_interface { zio_configure_t configure; zio_open_t open; zio_close_t close; + zio_destroy_channel_t destroy_channel; zio_command_t command; zio_wait_t wait; zio_read_t read; zio_write_t write; zio_span_poll_event_t poll_event; zio_span_next_event_t next_event; - uint32_t span_index; - struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; }; void zap_channel_rotate_tokens(zap_channel_t *zchan); @@ -337,15 +336,15 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); zap_time_t zap_current_time_in_ms(void); zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); -zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span); +zap_status_t zap_span_find(uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); zap_status_t zap_span_close_all(zap_io_interface_t *zio); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); -zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 2c97f40aed..9eb2082ec2 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -102,8 +102,6 @@ typedef enum { ZAP_SIGEVENT_TRANSFER, ZAP_SIGEVENT_ANSWER, ZAP_SIGEVENT_UP, - ZAP_SIGEVENT_HOLD, - ZAP_SIGEVENT_UNHOLD, ZAP_SIGEVENT_FLASH, ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, @@ -111,7 +109,7 @@ typedef enum { ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "HOLD", "UNHOLD", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -222,7 +220,8 @@ typedef enum { ZAP_CHANNEL_WINK = (1 << 9), ZAP_CHANNEL_FLASH = (1 << 10), ZAP_CHANNEL_STATE_CHANGE = (1 << 11), - ZAP_CHANNEL_HOLD = (1 << 12) + ZAP_CHANNEL_HOLD = (1 << 12), + ZAP_CHANNEL_INUSE = (1 << 13) } zap_channel_flag_t; @@ -240,6 +239,7 @@ typedef struct zap_span zap_span_t; #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_DESTROY_CHANNEL_ARGS (zap_channel_t *zchan) #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_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) @@ -254,6 +254,7 @@ 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_destroy_channel_t) ZIO_DESTROY_CHANNEL_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 ; @@ -268,6 +269,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_DESTROY_CHANNEL_FUNCTION(name) zap_status_t name ZIO_DESTROY_CHANNEL_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 diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 47b5470b7f..48ee34bbc9 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -89,25 +89,25 @@ struct zt_gains { /* 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_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*/ }; struct zt_maintinfo { - int span_no; /* span number */ + int span_no; /* span number */ int command; /* Maintenance mode to set (from zt_maintenance_mode_t) */ }; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index c42f40fc46..5e27509259 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -61,6 +61,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) int main(int argc, char *argv[]) { zap_span_t *span; + int span_id; + + 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); @@ -71,14 +79,14 @@ int main(int argc, char *argv[]) zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); - if (zap_span_find("zt", 1, &span) != ZAP_SUCCESS) { + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); - exit(-1); + goto done; } if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); - exit(-1); + goto done; } zap_analog_start(span); @@ -86,6 +94,9 @@ int main(int argc, char *argv[]) zap_sleep(1 * 1000); } + + done: + zap_global_destroy(); } diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index d980a034df..309239c3d4 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -8,6 +8,12 @@ int main(int argc, char *argv[]) zap_codec_t codec = ZAP_CODEC_SLIN; unsigned runs = 1; + if (!argv[1]) { + printf("usage %s \n", argv[0]); + exit(-1); + } + + if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); exit(-1); @@ -17,7 +23,7 @@ int main(int argc, char *argv[]) top: //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open("zt", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open(argv[1], 1, 1, &chan) == ZAP_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); @@ -65,6 +71,9 @@ int main(int argc, char *argv[]) if(--runs) { goto top; } + + end: + zap_global_destroy(); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index eb5c381d7d..55acc7814e 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -165,6 +165,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } break; + case ZAP_CHANNEL_STATE_DOWN: + { + goto done; + } + break; default: break; } @@ -176,10 +181,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: { if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { - sig.event_id = ZAP_SIGEVENT_UNHOLD; + zap_clear_flag(chan, ZAP_CHANNEL_HOLD); + sig.event_id = ZAP_SIGEVENT_FLASH; } else { sig.event_id = ZAP_SIGEVENT_UP; } + data->sig_cb(&sig); continue; } @@ -199,14 +206,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } break; - case ZAP_CHANNEL_STATE_HOLD: - { - sig.event_id = ZAP_SIGEVENT_HOLD; - data->sig_cb(&sig); - zap_set_flag_locked(chan, ZAP_CHANNEL_HOLD); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DIALTONE); - } - break; case ZAP_CHANNEL_STATE_DIALTONE: { *dtmf = '\0'; @@ -242,126 +241,127 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { - zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); - } - dtmf_offset = strlen(dtmf); - last_digit = elapsed; - } - } - - - if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { - zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); - last_digit = 0; - } - - if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { - continue; - } - - if (!(flags & ZAP_READ)) { - continue; - } - - if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { - goto done; - } - - if (!indicate) { - continue; - } - - if (chan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } - - rlen = zap_buffer_read_loop(dt_buffer, frame, len); - - if (chan->effective_codec != ZAP_CODEC_SLIN) { - zio_codec_t codec_func = NULL; - - if (chan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } - - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); - goto done; - } - } - - zap_channel_write(chan, frame, &rlen); - } - - done: - - closed_chan = chan; - zap_channel_close(&chan); - - 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 CHANNEL thread ended.\n"); - - return NULL; -} - -static zap_status_t process_event(zap_span_t *span, zap_event_t *event) -{ - zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d]\n", zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id); - - zap_mutex_lock(event->channel->mutex); + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { + zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + } + } - switch(event->enum_id) { - case ZAP_OOB_ONHOOK: - { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - break; - case ZAP_OOB_FLASH: - { - zap_sigmsg_t sig; - zap_analog_data_t *data = event->channel->span->analog_data; - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - sig.span = event->channel->span; - - if (event->channel->state == ZAP_CHANNEL_STATE_UP) { - if (event->channel->token_count > 1) { - zap_channel_rotate_tokens(event->channel); - sig.event_id = ZAP_SIGEVENT_FLASH; - data->sig_cb(&sig); - } else { - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { - zap_clear_flag_locked(event->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_HOLD); - } - } - } - } + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; + } + + if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; + } + + if (!(flags & ZAP_READ)) { + continue; + } + + if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + goto done; + } + + if (!indicate) { + continue; + } + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } + + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + + if (chan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + goto done; + } + } + + zap_channel_write(chan, frame, &rlen); + } + + done: + + closed_chan = chan; + zap_channel_close(&chan); + + 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 CHANNEL thread ended.\n"); + + return NULL; + } + + static zap_status_t process_event(zap_span_t *span, zap_event_t *event) + { + zap_sigmsg_t sig; + zap_analog_data_t *data = event->channel->span->analog_data; + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; + sig.span = event->channel->span; + + 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); + + + switch(event->enum_id) { + case ZAP_OOB_ONHOOK: + { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); + } + break; + case ZAP_OOB_FLASH: + { + + sig.event_id = ZAP_SIGEVENT_FLASH; + zap_channel_rotate_tokens(event->channel); + + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); + } else { + data->sig_cb(&sig); + if (event->channel->token_count == 1) { + zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + } + } + } break; case ZAP_OOB_OFFHOOK: { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 7890ceaaa2..3154ac2c05 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -73,6 +73,8 @@ zap_time_t zap_current_time_in_ms(void) static struct { zap_hash_t *interface_hash; zap_mutex_t *mutex; + struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; + uint32_t span_index; } globals; @@ -198,14 +200,16 @@ static uint32_t hashfromstring(void *ky) zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; + zap_status_t status = ZAP_FAIL; assert(zio != NULL); - if (zio->span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = &zio->spans[++zio->span_index]; + zap_mutex_lock(globals.mutex); + if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { + new_span = &globals.spans[++globals.span_index]; memset(new_span, 0, sizeof(*new_span)); zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = zio->span_index; + new_span->span_id = globals.span_index; new_span->zio = zio; zap_mutex_create(&new_span->mutex); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); @@ -214,10 +218,11 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); new_span->trunk_type = ZAP_TRUNK_NONE; *span = new_span; - return ZAP_SUCCESS; + status = ZAP_SUCCESS; } - - return ZAP_FAIL; + zap_mutex_unlock(globals.mutex); + + return status; } zap_status_t zap_span_close_all(zap_io_interface_t *zio) @@ -225,8 +230,9 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) zap_span_t *span; uint32_t i, j; - for(i = 0; i < zio->span_index; i++) { - span = &zio->spans[i]; + zap_mutex_lock(globals.mutex); + for(i = 0; i < globals.span_index; i++) { + span = &globals.spans[i]; for(j = 0; j < span->chan_count; j++) { if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_CONFIGURED)) { @@ -246,7 +252,8 @@ zap_status_t zap_span_close_all(zap_io_interface_t *zio) free(span->isdn_data); } } - + zap_mutex_unlock(globals.mutex); + return i ? ZAP_SUCCESS : ZAP_FAIL; } @@ -304,24 +311,17 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_find(const char *name, uint32_t id, zap_span_t **span) +zap_status_t zap_span_find(uint32_t id, zap_span_t **span) { - zap_io_interface_t *zio; zap_span_t *fspan; - zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); - zap_mutex_unlock(globals.mutex); - - if (!zio) { - return ZAP_FAIL; - } - if (id > ZAP_MAX_SPANS_INTERFACE) { return ZAP_FAIL; } - fspan = &zio->spans[id]; + zap_mutex_lock(globals.mutex); + fspan = &globals.spans[id]; + zap_mutex_unlock(globals.mutex); if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; @@ -348,6 +348,8 @@ zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) if (span->zio->poll_event) { return span->zio->poll_event(span, ms); + } else { + zap_log(ZAP_LOG_ERROR, "poll_event method not implemented in module %s!", span->zio->name); } return ZAP_NOTIMPL; @@ -359,8 +361,10 @@ zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) if (span->zio->next_event) { return span->zio->next_event(span, event); + } else { + zap_log(ZAP_LOG_ERROR, "next_event method not implemented in module %s!", span->zio->name); } - + return ZAP_NOTIMPL; } @@ -403,9 +407,11 @@ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) void zap_channel_rotate_tokens(zap_channel_t *zchan) { - memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); - zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); - *zchan->tokens[zchan->token_count] = '\0'; + if (zchan->token_count) { + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); + *zchan->tokens[zchan->token_count] = '\0'; + } } zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) @@ -414,7 +420,8 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) zap_mutex_lock(zchan->mutex); if (zchan->token_count < ZAP_MAX_TOKENS) { - zap_copy_string(zchan->tokens[zchan->token_count], token, sizeof(zchan->tokens[zchan->token_count])); + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); zchan->token_count++; } zap_mutex_unlock(zchan->mutex); @@ -455,9 +462,8 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) { - zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; @@ -465,18 +471,11 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct uint32_t span_max; zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); - zap_mutex_unlock(globals.mutex); - - if (!zio) { - zap_log(ZAP_LOG_ERROR, "Invalid interface name!\n"); - return ZAP_FAIL; - } if (span_id) { span_max = span_id; } else { - span_max = zio->span_index; + span_max = globals.span_index; } if (direction == ZAP_TOP_DOWN) { @@ -485,10 +484,8 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct j = span_max; } - zap_mutex_lock(globals.mutex); - for(;;) { - span = &zio->spans[j]; + span = &globals.spans[j]; if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; @@ -523,13 +520,13 @@ zap_status_t zap_channel_open_any(const char *name, uint32_t span_id, zap_direct } check = &span->channels[i]; - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { status = check->zio->open(check); - + if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); + zap_set_flag(check, ZAP_CHANNEL_INUSE); *zchan = check; return status; } @@ -563,6 +560,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->event_callback = NULL; zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + zap_clear_flag(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; @@ -598,7 +596,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } - if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && ! zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && !zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); @@ -609,33 +607,40 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) return status; } -zap_status_t zap_channel_open(const char *name, uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) +zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { - zap_io_interface_t *zio; zap_status_t status = ZAP_FAIL; zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (char *)name); - zap_mutex_unlock(globals.mutex); - - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zio) { + + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; - check = &zio->spans[span_id].channels[chan_id]; - if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { - return status; - } + check = &globals.spans[span_id].channels[chan_id]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && ! zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - *zchan = check; + if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + goto done; + } + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zio->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + } + } else { + status = ZAP_SUCCESS; } + zap_set_flag(check, ZAP_CHANNEL_INUSE); + *zchan = check; } zap_mutex_unlock(check->mutex); } + done: + + zap_mutex_unlock(globals.mutex); + return status; } @@ -649,7 +654,6 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(check != NULL); *zchan = NULL; - zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); @@ -1286,49 +1290,56 @@ static struct { } interfaces; -static uint32_t load_config(zap_io_interface_t *zio) +static zap_status_t load_config(void) { - char cfg_name[256]; + char cfg_name[] = "openzap.conf"; zap_config_t cfg; char *var, *val; int catno = -1; zap_span_t *span = NULL; - int new_span = 0; unsigned configured = 0, d = 0; char name[80] = ""; char number[25] = ""; - - assert(zio != NULL); - snprintf(cfg_name, sizeof(cfg_name), "%s.conf", zio->name); - - zap_log(ZAP_LOG_DEBUG, "configuring %s\n", zio->name); + zap_io_interface_t *zio = NULL; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "span")) { + if (!strncasecmp(cfg.category, "span", 4)) { if (cfg.catno != catno) { + char *type = cfg.category + 4; + if (*type == ' ') { + type++; + } + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; - new_span = 1; - span = NULL; - } - - if (new_span) { - if (!strcasecmp(var, "enabled") && ! zap_true(val)) { - zap_log(ZAP_LOG_DEBUG, "span (disabled)\n"); + + if (zap_strlen_zero(type)) { + zap_log(ZAP_LOG_CRIT, "failure creating span, no type specified.\n"); + span = NULL; + continue; + } + + zap_mutex_lock(globals.mutex); + zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type); + zap_mutex_unlock(globals.mutex); + + if (!zio) { + zap_log(ZAP_LOG_CRIT, "failure creating span, no such type '%s'\n", type); + span = NULL; + continue; + } + + if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); } else { - if (zap_span_create(zio, &span) == ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id); - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span\n"); - span = NULL; - } + zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); + span = NULL; + continue; } - new_span = 0; - continue; } if (!span) { @@ -1337,9 +1348,7 @@ static uint32_t load_config(zap_io_interface_t *zio) zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); - if (!strcasecmp(var, "enabled")) { - zap_log(ZAP_LOG_WARNING, "'enabled' command ignored when it's not the first command in a [span]\n"); - } else if (!strcasecmp(var, "trunk_type")) { + if (!strcasecmp(var, "trunk_type")) { span->trunk_type = zap_str2zap_trunk_type(val); zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); } else if (!strcasecmp(var, "name")) { @@ -1391,24 +1400,47 @@ static uint32_t load_config(zap_io_interface_t *zio) d++; } } - } else if (zio->configure) { - zio->configure(cfg.category, var, val, cfg.lineno); } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); } } zap_config_close_file(&cfg); - zap_log(ZAP_LOG_INFO, "wanpipe configured %u channel(s)\n", configured); + zap_log(ZAP_LOG_INFO, "Configured %u channel(s)\n", configured); - return configured; + return configured ? ZAP_SUCCESS : ZAP_FAIL; +} + +static zap_status_t process_module_config(zap_io_interface_t *zio) +{ + zap_config_t cfg; + char *var, *val; + char filename[256] = ""; + assert(zio != NULL); + + snprintf(filename, sizeof(filename), "%s.conf", zio->name); + + if (!zio->configure) { + zap_log(ZAP_LOG_ERROR, "Module %s does not support configuration.\n", zio->name); + return ZAP_FAIL; + } + + if (!zap_config_open_file(&cfg, filename)) { + zap_log(ZAP_LOG_ERROR, "Cannot open %s\n", filename); + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + zio->configure(cfg.category, var, val, cfg.lineno); + } + + zap_config_close_file(&cfg); + + return ZAP_SUCCESS; } zap_status_t zap_global_init(void) { - zap_config_t cfg; - char *var, *val; - uint32_t configured = 0; int modcount; time_init(); @@ -1419,11 +1451,11 @@ zap_status_t zap_global_init(void) modcount = 0; zap_mutex_create(&globals.mutex); -#ifdef Z -AP_WANPIPE_SUPPORT +#ifdef ZAP_WANPIPE_SUPPORT if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { zap_mutex_lock(globals.mutex); hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); + process_module_config(interfaces.wanpipe_interface); zap_mutex_unlock(globals.mutex); modcount++; } else { @@ -1435,6 +1467,7 @@ AP_WANPIPE_SUPPORT if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) { zap_mutex_lock(globals.mutex); hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface); + process_module_config(interfaces.zt_interface); zap_mutex_unlock(globals.mutex); modcount++; } else { @@ -1447,32 +1480,7 @@ AP_WANPIPE_SUPPORT return ZAP_FAIL; } - if (!zap_config_open_file(&cfg, "openzap.conf")) { - zap_log(ZAP_LOG_ERROR, "Cannot open openzap.conf!\n"); - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "openzap")) { - if (!strcmp(var, "load")) { - zap_io_interface_t *zio; - - zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, val); - zap_mutex_unlock(globals.mutex); - - if (zio) { - configured += load_config(zio); - } else { - zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val); - } - } - } - } - - zap_config_close_file(&cfg); - - if (configured) { + if (load_config() == ZAP_SUCCESS) { return ZAP_SUCCESS; } @@ -1482,7 +1490,31 @@ AP_WANPIPE_SUPPORT zap_status_t zap_global_destroy(void) { + unsigned int i,j; time_end(); + + for(i = 1; i <= globals.span_index; i++) { + zap_span_t *cur_span = &globals.spans[i]; + + if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { + zap_mutex_lock(cur_span->mutex); + for(j = 1; j <= cur_span->chan_count; j++) { + zap_channel_t *cur_chan = &cur_span->channels[j]; + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + if (cur_span->zio->destroy_channel) { + zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); + if (cur_span->zio->destroy_channel(cur_chan) == ZAP_SUCCESS) { + zap_clear_flag_locked(cur_chan, ZAP_CHANNEL_CONFIGURED); + } else { + zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); + } + } + } + } + zap_mutex_unlock(cur_span->mutex); + } + } + #ifdef ZAP_ZT_SUPPORT if (interfaces.zt_interface) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 55b58e890f..7bca3922b1 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -202,7 +202,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D for(i = 1; i <= span->chan_count; i++) { if (span->channels[i].type == ZAP_CHAN_TYPE_DQ921) { - if (zap_channel_open(span->zio->name, span->span_id, i, &dchans[x]) == ZAP_SUCCESS) { + 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); x++; } diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index fc14f0ad8f..9d3dcc43f1 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -108,13 +108,29 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) { + int num; + if (!strcasecmp(category, "defaults")) { if (!strcasecmp(var, "codec_ms")) { - unsigned codec_ms = atoi(val); - if (codec_ms < 10 || codec_ms > 60) { + 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 = codec_ms; + wp_globals.codec_ms = num; + } + } else if (!strcasecmp(var, "wink_ms")) { + num = atoi(val); + if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno); + } else { + wp_globals.flash_ms = num; } } } @@ -479,6 +495,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } +static ZIO_DESTROY_CHANNEL_FUNCTION(wanpipe_destroy_channel) +{ + tdmv_api_close_socket(&zchan->sockfd); + zchan->sockfd = WP_INVALID_SOCKET; + + return ZAP_SUCCESS; +} + zap_status_t wanpipe_init(zap_io_interface_t **zio) { assert(zio != NULL); @@ -500,6 +524,7 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wanpipe_interface.poll_event = wanpipe_poll_event; #endif wanpipe_interface.next_event = wanpipe_next_event; + wanpipe_interface.destroy_channel = wanpipe_destroy_channel; *zio = &wanpipe_interface; return ZAP_SUCCESS; @@ -507,23 +532,6 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) zap_status_t wanpipe_destroy(void) { - unsigned int i,j; - - for(i = 1; i <= wanpipe_interface.span_index; i++) { - zap_span_t *cur_span = &wanpipe_interface.spans[i]; - - if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { - for(j = 1; j <= cur_span->chan_count; j++) { - zap_channel_t *cur_chan = &cur_span->channels[j]; - if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - tdmv_api_close_socket(&cur_chan->sockfd); - } - } - } - } - memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); - return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index c91c585c70..9f86ffe01f 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -54,7 +54,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_channel_t *chan; zap_socket_t sockfd = ZT_INVALID_SOCKET; int command; - int len = zt_globals.codec_ms * 8; + int len; snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); @@ -70,25 +70,26 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za continue; } #endif - + + + len = zt_globals.codec_ms * 8; if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; - } else { - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; - - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; - } + } + + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; + + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; } - if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { - close(sockfd); zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); continue; } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); @@ -100,7 +101,16 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + + ztp.wink_time = zt_globals.wink_ms; + ztp.flash_time = zt_globals.flash_ms; + if (ioctl(sockfd, ZT_SET_PARAMS, &ztp) < 0) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); } @@ -175,17 +185,34 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) static ZIO_CONFIGURE_FUNCTION(zt_configure) { + + int num; + if (!strcasecmp(category, "defaults")) { if (!strcasecmp(var, "codec_ms")) { - unsigned codec_ms = atoi(val); - if (codec_ms < 10 || codec_ms > 60) { + 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 = codec_ms; + zt_globals.codec_ms = num; + } + } else if (!strcasecmp(var, "wink_ms")) { + num = atoi(val); + if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno); + } else { + zt_globals.flash_ms = num; } } } - + return ZAP_SUCCESS; } @@ -364,6 +391,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) event_id = ZAP_OOB_ONHOOK; } break; + case ZT_EVENT_WINKFLASH: + { + if (span->channels[i].state == ZAP_CHANNEL_STATE_DOWN) { + 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) { @@ -425,6 +461,14 @@ static ZIO_WRITE_FUNCTION(zt_write) return ZAP_FAIL; } +static ZIO_DESTROY_CHANNEL_FUNCTION(zt_destroy_channel) +{ + close(zchan->sockfd); + zchan->sockfd = ZT_INVALID_SOCKET; + + return ZAP_SUCCESS; +} + static zap_io_interface_t zt_interface; zap_status_t zt_init(zap_io_interface_t **zio) @@ -447,6 +491,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_interface.write = zt_write; zt_interface.poll_event = zt_poll_event; zt_interface.next_event = zt_next_event; + zt_interface.destroy_channel = zt_destroy_channel; *zio = &zt_interface; @@ -455,5 +500,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zap_status_t zt_destroy(void) { - return ZAP_FAIL; + + memset(&zt_interface, 0, sizeof(zt_interface)); + return ZAP_SUCCESS; } From 65228c6815df23faad51f843f53a7714ae8104ea Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 May 2007 03:04:26 +0000 Subject: [PATCH 0373/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@187 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 71 +++++++++++++++++--------- libs/openzap/src/include/openzap.h | 2 + libs/openzap/src/zap_analog.c | 9 ++++ libs/openzap/src/zap_io.c | 20 ++++++++ 4 files changed, 78 insertions(+), 24 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 25612c196f..db17d6a95f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -49,11 +49,10 @@ static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; typedef enum { TFLAG_IO = (1 << 0), - TFLAG_OUTBOUND = (1 << 1), - TFLAG_DTMF = (1 << 2), - TFLAG_CODEC = (1 << 3), - TFLAG_BREAK = (1 << 4), - TFLAG_HOLD = (1 << 5) + TFLAG_DTMF = (1 << 1), + TFLAG_CODEC = (1 << 2), + TFLAG_BREAK = (1 << 3), + TFLAG_HOLD = (1 << 4) } TFLAGS; static struct { @@ -540,6 +539,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool) { + + char *dest; + int span_id = 0; + zap_channel_t *zchan = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + char name[128]; + + if (!outbound_profile) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if ((dest = strchr('/', outbound_profile->destination_number))) { + dest++; + span_id = atoi(outbound_profile->destination_number); + } + + if (!span_id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if (zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan) != ZAP_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; @@ -548,36 +574,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { channel = switch_core_session_get_channel(*new_session); - tech_init(tech_pvt, *new_session, NULL); + tech_init(tech_pvt, *new_session, zchan); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_core_session_destroy(new_session); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } - - if (outbound_profile) { - char name[128]; - - snprintf(name, sizeof(name), "OPENZAP/%s-%04x", outbound_profile->destination_number, rand() & 0xffff); - switch_channel_set_name(channel, name); - - caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); - switch_channel_set_caller_profile(channel, caller_profile); - tech_pvt->caller_profile = caller_profile; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); - switch_core_session_destroy(new_session); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; } + snprintf(name, sizeof(name), "OPENZAP/%s", outbound_profile->destination_number); + switch_channel_set_name(channel, name); + + caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + switch_channel_set_caller_profile(channel, caller_profile); + tech_pvt->caller_profile = caller_profile; + switch_channel_set_flag(channel, CF_OUTBOUND); - switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_channel_set_state(channel, CS_INIT); return SWITCH_CAUSE_SUCCESS; } - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + + fail: + if (zchan) { + zap_channel_done(zchan); + } + return cause; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 0d43156956..acddd89f23 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -346,6 +346,8 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_status_t zap_channel_open_chan(zap_channel_t *zchan); zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); +zap_status_t zap_channel_done(zap_channel_t *zchan); +zap_status_t zap_channel_use(zap_channel_t *zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 55acc7814e..dd41ebe8fa 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -167,6 +167,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { + zap_channel_done(chan); goto done; } break; @@ -180,6 +181,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { + zap_channel_use(chan); if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { zap_clear_flag(chan, ZAP_CHANNEL_HOLD); sig.event_id = ZAP_SIGEVENT_FLASH; @@ -193,6 +195,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_IDLE: { + zap_channel_use(chan); sig.event_id = ZAP_SIGEVENT_START; zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); data->sig_cb(&sig); @@ -201,6 +204,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { + zap_channel_done(chan); sig.event_id = ZAP_SIGEVENT_STOP; data->sig_cb(&sig); goto done; @@ -208,6 +212,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { + zap_channel_done(chan); *dtmf = '\0'; dtmf_offset = 0; zap_buffer_zero(dt_buffer); @@ -217,6 +222,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_RING: { + zap_channel_done(chan); zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); indicate = 1; @@ -224,6 +230,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_BUSY: { + zap_channel_done(chan); zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); indicate = 1; @@ -231,12 +238,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_ATTN: { + zap_channel_done(chan); zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); indicate = 1; } break; default: + zap_channel_done(chan); break; } } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3154ac2c05..813a263846 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -644,6 +644,26 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t return status; } +zap_status_t zap_channel_done(zap_channel_t *zchan) +{ + + assert(zchan != NULL); + + zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); + + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_use(zap_channel_t *zchan) +{ + + assert(zchan != NULL); + + zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); + + return ZAP_SUCCESS; +} + zap_status_t zap_channel_close(zap_channel_t **zchan) { zap_channel_t *check; From 9cdf5515410f6fc1c1e04d7eb8db0d66bd7f9115 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 May 2007 03:04:26 +0000 Subject: [PATCH 0374/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@187 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 71 +++++++++++++++++--------- libs/freetdm/src/include/openzap.h | 2 + libs/freetdm/src/zap_analog.c | 9 ++++ libs/freetdm/src/zap_io.c | 20 ++++++++ 4 files changed, 78 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 25612c196f..db17d6a95f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -49,11 +49,10 @@ static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; typedef enum { TFLAG_IO = (1 << 0), - TFLAG_OUTBOUND = (1 << 1), - TFLAG_DTMF = (1 << 2), - TFLAG_CODEC = (1 << 3), - TFLAG_BREAK = (1 << 4), - TFLAG_HOLD = (1 << 5) + TFLAG_DTMF = (1 << 1), + TFLAG_CODEC = (1 << 2), + TFLAG_BREAK = (1 << 3), + TFLAG_HOLD = (1 << 4) } TFLAGS; static struct { @@ -540,6 +539,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool) { + + char *dest; + int span_id = 0; + zap_channel_t *zchan = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + char name[128]; + + if (!outbound_profile) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if ((dest = strchr('/', outbound_profile->destination_number))) { + dest++; + span_id = atoi(outbound_profile->destination_number); + } + + if (!span_id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if (zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan) != ZAP_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; @@ -548,36 +574,33 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { channel = switch_core_session_get_channel(*new_session); - tech_init(tech_pvt, *new_session, NULL); + tech_init(tech_pvt, *new_session, zchan); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_core_session_destroy(new_session); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } - - if (outbound_profile) { - char name[128]; - - snprintf(name, sizeof(name), "OPENZAP/%s-%04x", outbound_profile->destination_number, rand() & 0xffff); - switch_channel_set_name(channel, name); - - caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); - switch_channel_set_caller_profile(channel, caller_profile); - tech_pvt->caller_profile = caller_profile; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); - switch_core_session_destroy(new_session); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; } + snprintf(name, sizeof(name), "OPENZAP/%s", outbound_profile->destination_number); + switch_channel_set_name(channel, name); + + caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + switch_channel_set_caller_profile(channel, caller_profile); + tech_pvt->caller_profile = caller_profile; + switch_channel_set_flag(channel, CF_OUTBOUND); - switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_channel_set_state(channel, CS_INIT); return SWITCH_CAUSE_SUCCESS; } - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + + fail: + if (zchan) { + zap_channel_done(zchan); + } + return cause; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 0d43156956..acddd89f23 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -346,6 +346,8 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_status_t zap_channel_open_chan(zap_channel_t *zchan); zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); +zap_status_t zap_channel_done(zap_channel_t *zchan); +zap_status_t zap_channel_use(zap_channel_t *zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 55acc7814e..dd41ebe8fa 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -167,6 +167,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { + zap_channel_done(chan); goto done; } break; @@ -180,6 +181,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { + zap_channel_use(chan); if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { zap_clear_flag(chan, ZAP_CHANNEL_HOLD); sig.event_id = ZAP_SIGEVENT_FLASH; @@ -193,6 +195,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_IDLE: { + zap_channel_use(chan); sig.event_id = ZAP_SIGEVENT_START; zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); data->sig_cb(&sig); @@ -201,6 +204,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { + zap_channel_done(chan); sig.event_id = ZAP_SIGEVENT_STOP; data->sig_cb(&sig); goto done; @@ -208,6 +212,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { + zap_channel_done(chan); *dtmf = '\0'; dtmf_offset = 0; zap_buffer_zero(dt_buffer); @@ -217,6 +222,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_RING: { + zap_channel_done(chan); zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); indicate = 1; @@ -224,6 +230,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_BUSY: { + zap_channel_done(chan); zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); indicate = 1; @@ -231,12 +238,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_ATTN: { + zap_channel_done(chan); zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); indicate = 1; } break; default: + zap_channel_done(chan); break; } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3154ac2c05..813a263846 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -644,6 +644,26 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t return status; } +zap_status_t zap_channel_done(zap_channel_t *zchan) +{ + + assert(zchan != NULL); + + zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); + + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_use(zap_channel_t *zchan) +{ + + assert(zchan != NULL); + + zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); + + return ZAP_SUCCESS; +} + zap_status_t zap_channel_close(zap_channel_t **zchan) { zap_channel_t *check; From f5f5991fc81d77c8f1c672b5c8f74643bdc832d1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 31 May 2007 03:12:02 +0000 Subject: [PATCH 0375/1766] windows tweak. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@188 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 2 ++ libs/openzap/src/include/zap_types.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 9e936194cf..1a60eded45 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -344,6 +344,7 @@ > typedef int zap_socket_t; +typedef ssize_t zap_ssize_t; #endif typedef size_t zap_size_t; -typedef ssize_t zap_ssize_t; struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) From 625669f4f189d2a8ee66281fa6c24b6f70b01e78 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 31 May 2007 03:12:02 +0000 Subject: [PATCH 0376/1766] windows tweak. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@188 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 2 ++ libs/freetdm/src/include/zap_types.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 9e936194cf..1a60eded45 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -344,6 +344,7 @@ > typedef int zap_socket_t; +typedef ssize_t zap_ssize_t; #endif typedef size_t zap_size_t; -typedef ssize_t zap_ssize_t; struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) From 4c9db695b5a2689b9ebcca515dbc7f7545de8cbc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 May 2007 20:15:16 +0000 Subject: [PATCH 0377/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@189 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 144 +++++++++++-- libs/openzap/src/include/openzap.h | 18 +- libs/openzap/src/include/zap_types.h | 27 +-- libs/openzap/src/testanalog.c | 2 +- libs/openzap/src/zap_analog.c | 268 ++++++++++++++++--------- libs/openzap/src/zap_io.c | 34 ++-- libs/openzap/src/zap_wanpipe.c | 3 - libs/openzap/src/zap_zt.c | 75 +++++-- 8 files changed, 402 insertions(+), 169 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index db17d6a95f..0e970d772d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -126,7 +126,6 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec); - switch(codec) { case ZAP_CODEC_ULAW: { @@ -252,6 +251,12 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: + { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; case ZAP_CHAN_TYPE_FXS: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { @@ -366,7 +371,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch char dtmf[128] = ""; zap_status_t status; int total_to = timeout; - int chunk; + int chunk, do_break = 0; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -377,8 +382,15 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); chunk = tech_pvt->zchan->effective_interval * 2; + top: - if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + + if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { + switch_clear_flag_locked(tech_pvt, TFLAG_BREAK); + do_break = 1; + } + + if (switch_test_flag(tech_pvt, TFLAG_HOLD) || do_break) { switch_yield(tech_pvt->zchan->effective_interval * 1000); *frame = &tech_pvt->cng_frame; tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; @@ -406,6 +418,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_BREAK; } } + goto top; } @@ -461,15 +474,20 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (++tech_pvt->wr_error > 10) { return SWITCH_STATUS_GENERR; } + } else { + tech_pvt->wr_error = 0; } - tech_pvt->wr_error = 0; - return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + return SWITCH_STATUS_FALSE; +} + +static switch_status_t channel_receive_message_fxo(switch_core_session_t *session, switch_core_session_message_t *msg) { switch_channel_t *channel; private_t *tech_pvt; @@ -481,8 +499,36 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s assert(tech_pvt != NULL); switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_receive_message_fxs(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_ANSWER: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } break; case SWITCH_MESSAGE_INDICATE_RINGING: zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); @@ -494,6 +540,25 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s return SWITCH_STATUS_SUCCESS; } +static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + private_t *tech_pvt; + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (tech_pvt->zchan->type) { + case ZAP_CHAN_TYPE_FXS: + return channel_receive_message_fxs(session, msg); + case ZAP_CHAN_TYPE_FXO: + return channel_receive_message_fxo(session, msg); + case ZAP_CHAN_TYPE_B: + return channel_receive_message_b(session, msg); + default: + return SWITCH_STATUS_FALSE; + } +} + static const switch_state_handler_table_t channel_event_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, @@ -540,20 +605,25 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_t **new_session, switch_memory_pool_t **pool) { - char *dest; - int span_id = 0; + char *p, *dest; + int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; + zap_status_t status; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if ((dest = strchr('/', outbound_profile->destination_number))) { - dest++; + if ((p = strchr(outbound_profile->destination_number, '/'))) { + dest = p + 1; span_id = atoi(outbound_profile->destination_number); + if ((p = strchr(dest, '/'))) { + chan_id = atoi(dest); + dest = p + 1; + } } if (!span_id) { @@ -561,7 +631,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan) != ZAP_SUCCESS) { + if (chan_id) { + status = zap_channel_open(span_id, chan_id, &zchan); + } else { + status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); + + } + + if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -582,9 +659,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - snprintf(name, sizeof(name), "OPENZAP/%s", outbound_profile->destination_number); + snprintf(name, sizeof(name), "OPENZAP/%s", dest); switch_channel_set_name(channel, name); - + zap_set_string(zchan->caller_data.ani, dest); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -592,6 +669,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); + if ((tech_pvt->token_id = zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session))) < 0) { + switch_core_session_destroy(new_session); + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; + } + + zap_channel_outgoing_call(zchan); return SWITCH_CAUSE_SUCCESS; } @@ -630,7 +714,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), "OpenZAP", - SPAN_CONFIG[sigmsg->span->span_id].dialplan, + SPAN_CONFIG[sigmsg->channel->span_id].dialplan, sigmsg->channel->chan_name, sigmsg->channel->chan_number, NULL, @@ -638,8 +722,8 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t NULL, NULL, (char *) modname, - SPAN_CONFIG[sigmsg->span->span_id].context, - sigmsg->dnis); + SPAN_CONFIG[sigmsg->channel->span_id].context, + sigmsg->channel->caller_data.dnis); assert(tech_pvt->caller_profile != NULL); snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); @@ -679,7 +763,22 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + switch_core_session_t *session = NULL; + zap_status_t status; + + zap_log(ZAP_LOG_DEBUG, "got fxo sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + { + status = zap_channel_from_event(sigmsg, &session); + if (status != ZAP_SUCCESS) { + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + } + return ZAP_SUCCESS; } @@ -693,6 +792,15 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_START: { status = zap_channel_from_event(sigmsg, &session); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index acddd89f23..1804090136 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -151,6 +151,7 @@ #define GOTO_STATUS(label,st) status = st; goto label ; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) +#define zap_set_string(x,y) strncpy(x, y, sizeof(x)-1) #define zap_strlen_zero(s) (!s || *s == '\0') @@ -222,6 +223,15 @@ struct zap_event { #define ZAP_TOKEN_STRLEN 128 #define ZAP_MAX_TOKENS 10 + + +struct zap_caller_data { + char cid_name[80]; + char ani[25]; + char aniII[25]; + char dnis[25]; +}; + struct zap_channel { uint32_t span_id; uint32_t chan_id; @@ -253,6 +263,7 @@ struct zap_channel { uint32_t token_count; char chan_name[128]; char chan_number[32]; + struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; }; @@ -263,11 +274,6 @@ struct zap_sigmsg { uint32_t chan_id; uint32_t span_id; zap_channel_t *channel; - zap_span_t *span; - char cid_name[80]; - char ani[25]; - char aniII[25]; - char dnis[25]; void *raw_data; uint32_t raw_data_len; }; @@ -305,6 +311,7 @@ struct zap_span { char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + zio_channel_outgoing_call_t outgoing_call; void *app_data; }; @@ -326,6 +333,7 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 4abc83a23c..b1431878f1 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -79,7 +79,8 @@ typedef enum { ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) typedef enum { - ZAP_OOB_DTMF, ZAP_OOB_ONHOOK, + ZAP_OOB_DTMF, + ZAP_OOB_ONHOOK, ZAP_OOB_OFFHOOK, ZAP_OOB_WINK, ZAP_OOB_FLASH, @@ -168,7 +169,10 @@ typedef enum { 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_COUNT } zap_command_t; @@ -203,9 +207,10 @@ typedef enum { ZAP_CHANNEL_STATE_BUSY, ZAP_CHANNEL_STATE_ATTN, ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -222,7 +227,9 @@ typedef enum { ZAP_CHANNEL_FLASH = (1 << 10), ZAP_CHANNEL_STATE_CHANGE = (1 << 11), ZAP_CHANNEL_HOLD = (1 << 12), - ZAP_CHANNEL_INUSE = (1 << 13) + ZAP_CHANNEL_INUSE = (1 << 13), + ZAP_CHANNEL_OFFHOOK = (1 << 14), + ZAP_CHANNEL_RINGING = (1 << 15) } zap_channel_flag_t; @@ -231,6 +238,7 @@ typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; +#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) @@ -246,6 +254,7 @@ typedef struct zap_span zap_span_t; #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) +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 ; @@ -261,6 +270,7 @@ 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 ; +#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 @@ -276,16 +286,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_CONFIGURE_SPAN_MUZZLE assert(zio != NULL) -#define ZIO_OPEN_MUZZLE assert(zchan != NULL) -#define ZIO_CLOSE_MUZZLE assert(zchan != NULL) -#define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) -#define ZIO_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) -#define ZIO_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) -#define ZIO_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) - #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ - #define ZAP_LOG_LEVEL_DEBUG 7 #define ZAP_LOG_LEVEL_INFO 6 #define ZAP_LOG_LEVEL_NOTICE 5 diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 5e27509259..086eab7514 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) { zap_span_t *span; int span_id; - + if (argc < 2) { printf("usage %s \n", argv[0]); exit(-1); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index dd41ebe8fa..400a8999ac 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -34,6 +34,24 @@ #include "openzap.h" #include "zap_analog.h" +static void *zap_analog_channel_run(zap_thread_t *me, void *obj); + +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) +{ + return ZAP_FAIL; +} + +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_GENRING); + zap_thread_create_detached(zap_analog_channel_run, zchan); + } + + return ZAP_SUCCESS; +} + 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) { @@ -60,6 +78,7 @@ zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t span->analog_data->max_dialstr = max_dialstr; span->analog_data->sig_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; + 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; @@ -124,7 +143,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.chan_id = chan->chan_id; sig.span_id = chan->span_id; sig.channel = chan; - sig.span = chan->span; + while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -137,6 +156,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { + case ZAP_CHANNEL_STATE_GENRING: + { + if (state_counter > 60000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_sleep(interval); + continue; + } + } + break; case ZAP_CHANNEL_STATE_DIALTONE: { if (state_counter > 10000) { @@ -182,6 +211,15 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: { zap_channel_use(chan); + + if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + } + + if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } + if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { zap_clear_flag(chan, ZAP_CHANNEL_HOLD); sig.event_id = ZAP_SIGEVENT_FLASH; @@ -197,7 +235,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_use(chan); sig.event_id = ZAP_SIGEVENT_START; - zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); + zap_copy_string(chan->caller_data.dnis, dtmf, sizeof(chan->caller_data.dnis)); data->sig_cb(&sig); continue; } @@ -220,6 +258,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; + case ZAP_CHANNEL_STATE_GENRING: + { + zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); + } + break; case ZAP_CHANNEL_STATE_RING: { zap_channel_done(chan); @@ -250,137 +293,168 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { - zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); - } - dtmf_offset = strlen(dtmf); - last_digit = elapsed; - } - } + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { + zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + } + } - if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { - zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); - last_digit = 0; - } + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; + } - if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { - continue; - } + if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; + } - if (!(flags & ZAP_READ)) { - continue; - } + if (!(flags & ZAP_READ)) { + continue; + } - if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { - goto done; - } + if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + goto done; + } - if (!indicate) { - continue; - } + if (!indicate) { + continue; + } - if (chan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } + if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + } - rlen = zap_buffer_read_loop(dt_buffer, frame, len); + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } - if (chan->effective_codec != ZAP_CODEC_SLIN) { - zio_codec_t codec_func = NULL; + rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (chan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } + if (chan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); - goto done; - } - } + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } - zap_channel_write(chan, frame, &rlen); - } + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + goto done; + } + } - done: + zap_channel_write(chan, frame, &rlen); + } - closed_chan = chan; - zap_channel_close(&chan); + done: - zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); + if (chan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(chan, ZAP_COMMAND_ONHOOK, NULL); + } - if (ts.buffer) { - teletone_destroy_session(&ts); - } + if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } - if (dt_buffer) { - zap_buffer_destroy(&dt_buffer); - } + + closed_chan = chan; + zap_channel_close(&chan); - zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); + if (ts.buffer) { + teletone_destroy_session(&ts); + } - return NULL; - } + if (dt_buffer) { + zap_buffer_destroy(&dt_buffer); + } - static zap_status_t process_event(zap_span_t *span, zap_event_t *event) - { - zap_sigmsg_t sig; - zap_analog_data_t *data = event->channel->span->analog_data; + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - sig.span = event->channel->span; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); - 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)); + return NULL; +} - zap_mutex_lock(event->channel->mutex); +static zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_sigmsg_t sig; + zap_analog_data_t *data = event->channel->span->analog_data; + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; - switch(event->enum_id) { - case ZAP_OOB_ONHOOK: - { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - break; - case ZAP_OOB_FLASH: - { + 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)); - sig.event_id = ZAP_SIGEVENT_FLASH; - zap_channel_rotate_tokens(event->channel); + zap_mutex_lock(event->channel->mutex); - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - data->sig_cb(&sig); - if (event->channel->token_count == 1) { - zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - } - } - } + + switch(event->enum_id) { + case ZAP_OOB_RING_START: + { + + if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + sig.event_id = ZAP_SIGEVENT_START; + zap_set_string(event->channel->caller_data.dnis, event->channel->chan_number); + data->sig_cb(&sig); + zap_channel_command(event->channel, ZAP_COMMAND_OFFHOOK, NULL); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RING); + zap_thread_create_detached(zap_analog_channel_run, event->channel); + } + } + break; + case ZAP_OOB_ONHOOK: + { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); + } + break; + case ZAP_OOB_FLASH: + { + + sig.event_id = ZAP_SIGEVENT_FLASH; + zap_channel_rotate_tokens(event->channel); + + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); + } else { + data->sig_cb(&sig); + if (event->channel->token_count == 1) { + zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + } + } + } break; case ZAP_OOB_OFFHOOK: { - if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + if (event->channel->type == ZAP_CHAN_TYPE_FXS && 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 { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); zap_thread_create_detached(zap_analog_channel_run, event->channel); } } } - + zap_mutex_unlock(event->channel->mutex); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 813a263846..49bc73e73a 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -474,19 +474,18 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z if (span_id) { span_max = span_id; + j = span_id; } else { span_max = globals.span_index; - } - - if (direction == ZAP_TOP_DOWN) { - j = 1; - } else { - j = span_max; + if (direction == ZAP_TOP_DOWN) { + j = 1; + } else { + j = span_max; + } } for(;;) { span = &globals.spans[j]; - if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } @@ -527,6 +526,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_INUSE); + zap_channel_open_chan(check); *zchan = check; return status; } @@ -560,7 +560,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->event_callback = NULL; zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - zap_clear_flag(zchan, ZAP_CHANNEL_INUSE); + zap_channel_done(zchan); zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; @@ -644,11 +644,24 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t return status; } +zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) +{ + assert(zchan != NULL); + if (zchan->span->outgoing_call) { + return zchan->span->outgoing_call(zchan); + } else { + zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n"); + } + + return ZAP_FAIL; +} + zap_status_t zap_channel_done(zap_channel_t *zchan) { assert(zchan != NULL); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); return ZAP_SUCCESS; @@ -728,11 +741,6 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo assert(zchan != NULL); assert(zchan->zio != NULL); - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); - return ZAP_FAIL; - } - zap_mutex_lock(zchan->mutex); switch(command) { diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 9d3dcc43f1..191e010c41 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -232,7 +232,6 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) static ZIO_CLOSE_FUNCTION(wanpipe_close) { - ZIO_CLOSE_MUZZLE; return ZAP_SUCCESS; } @@ -241,8 +240,6 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) wanpipe_tdm_api_t tdm_api; int err = 0; - ZIO_COMMAND_MUZZLE; - memset(&tdm_api, 0, sizeof(tdm_api)); switch(command) { diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 9f86ffe01f..c5486ab8cf 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -53,25 +53,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za for(x = start; x < end; x++) { zap_channel_t *chan; zap_socket_t sockfd = ZT_INVALID_SOCKET; - int command; int len; snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - command = ZT_START; -#if 0 - - if (ioctl(sockfd, ZT_HOOK, &command)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - - continue; - } -#endif - - len = zt_globals.codec_ms * 8; if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", @@ -218,13 +205,11 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) static ZIO_OPEN_FUNCTION(zt_open) { - ZIO_OPEN_MUZZLE; return ZAP_SUCCESS; } static ZIO_CLOSE_FUNCTION(zt_close) { - ZIO_CLOSE_MUZZLE; return ZAP_SUCCESS; } @@ -233,9 +218,47 @@ static ZIO_COMMAND_FUNCTION(zt_command) zt_params_t ztp = {0}; int err = 0; - ZIO_COMMAND_MUZZLE; - switch(command) { + case ZAP_COMMAND_OFFHOOK: + { + int command = ZT_OFFHOOK; + if (ioctl(zchan->sockfd, ZT_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, ZT_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_GENERATE_RING_ON: + { + int command = ZT_RING; + if (ioctl(zchan->sockfd, ZT_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, ZT_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, ZT_GET_BLOCKSIZE, &zchan->packet_len))) { @@ -344,11 +367,9 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) int i, j = 0, k = 0, r, e; for(i = 1; i <= span->chan_count; i++) { - e = ZT_IOMUX_SIGEVENT; memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i].sockfd; pfds[j].events = POLLPRI; - ioctl(span->channels[i].sockfd ,ZT_IOMUX, &e); j++; } @@ -386,6 +407,21 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) } 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; @@ -486,6 +522,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) 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; From 69acc519209c8650f919630fa60f891c8bb90e0b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 May 2007 20:15:16 +0000 Subject: [PATCH 0378/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@189 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 144 +++++++++++-- libs/freetdm/src/include/openzap.h | 18 +- libs/freetdm/src/include/zap_types.h | 27 +-- libs/freetdm/src/testanalog.c | 2 +- libs/freetdm/src/zap_analog.c | 268 ++++++++++++++++--------- libs/freetdm/src/zap_io.c | 34 ++-- libs/freetdm/src/zap_wanpipe.c | 3 - libs/freetdm/src/zap_zt.c | 75 +++++-- 8 files changed, 402 insertions(+), 169 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index db17d6a95f..0e970d772d 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -126,7 +126,6 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec); - switch(codec) { case ZAP_CODEC_ULAW: { @@ -252,6 +251,12 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: + { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; case ZAP_CHAN_TYPE_FXS: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { @@ -366,7 +371,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch char dtmf[128] = ""; zap_status_t status; int total_to = timeout; - int chunk; + int chunk, do_break = 0; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -377,8 +382,15 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); chunk = tech_pvt->zchan->effective_interval * 2; + top: - if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + + if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { + switch_clear_flag_locked(tech_pvt, TFLAG_BREAK); + do_break = 1; + } + + if (switch_test_flag(tech_pvt, TFLAG_HOLD) || do_break) { switch_yield(tech_pvt->zchan->effective_interval * 1000); *frame = &tech_pvt->cng_frame; tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; @@ -406,6 +418,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_BREAK; } } + goto top; } @@ -461,15 +474,20 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (++tech_pvt->wr_error > 10) { return SWITCH_STATUS_GENERR; } + } else { + tech_pvt->wr_error = 0; } - tech_pvt->wr_error = 0; - return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + return SWITCH_STATUS_FALSE; +} + +static switch_status_t channel_receive_message_fxo(switch_core_session_t *session, switch_core_session_message_t *msg) { switch_channel_t *channel; private_t *tech_pvt; @@ -481,8 +499,36 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s assert(tech_pvt != NULL); switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_receive_message_fxs(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_ANSWER: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } break; case SWITCH_MESSAGE_INDICATE_RINGING: zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); @@ -494,6 +540,25 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s return SWITCH_STATUS_SUCCESS; } +static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + private_t *tech_pvt; + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (tech_pvt->zchan->type) { + case ZAP_CHAN_TYPE_FXS: + return channel_receive_message_fxs(session, msg); + case ZAP_CHAN_TYPE_FXO: + return channel_receive_message_fxo(session, msg); + case ZAP_CHAN_TYPE_B: + return channel_receive_message_b(session, msg); + default: + return SWITCH_STATUS_FALSE; + } +} + static const switch_state_handler_table_t channel_event_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, @@ -540,20 +605,25 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_t **new_session, switch_memory_pool_t **pool) { - char *dest; - int span_id = 0; + char *p, *dest; + int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; + zap_status_t status; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if ((dest = strchr('/', outbound_profile->destination_number))) { - dest++; + if ((p = strchr(outbound_profile->destination_number, '/'))) { + dest = p + 1; span_id = atoi(outbound_profile->destination_number); + if ((p = strchr(dest, '/'))) { + chan_id = atoi(dest); + dest = p + 1; + } } if (!span_id) { @@ -561,7 +631,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan) != ZAP_SUCCESS) { + if (chan_id) { + status = zap_channel_open(span_id, chan_id, &zchan); + } else { + status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); + + } + + if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -582,9 +659,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - snprintf(name, sizeof(name), "OPENZAP/%s", outbound_profile->destination_number); + snprintf(name, sizeof(name), "OPENZAP/%s", dest); switch_channel_set_name(channel, name); - + zap_set_string(zchan->caller_data.ani, dest); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -592,6 +669,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); + if ((tech_pvt->token_id = zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session))) < 0) { + switch_core_session_destroy(new_session); + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; + } + + zap_channel_outgoing_call(zchan); return SWITCH_CAUSE_SUCCESS; } @@ -630,7 +714,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), "OpenZAP", - SPAN_CONFIG[sigmsg->span->span_id].dialplan, + SPAN_CONFIG[sigmsg->channel->span_id].dialplan, sigmsg->channel->chan_name, sigmsg->channel->chan_number, NULL, @@ -638,8 +722,8 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t NULL, NULL, (char *) modname, - SPAN_CONFIG[sigmsg->span->span_id].context, - sigmsg->dnis); + SPAN_CONFIG[sigmsg->channel->span_id].context, + sigmsg->channel->caller_data.dnis); assert(tech_pvt->caller_profile != NULL); snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); @@ -679,7 +763,22 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + switch_core_session_t *session = NULL; + zap_status_t status; + + zap_log(ZAP_LOG_DEBUG, "got fxo sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + { + status = zap_channel_from_event(sigmsg, &session); + if (status != ZAP_SUCCESS) { + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + } + return ZAP_SUCCESS; } @@ -693,6 +792,15 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_START: { status = zap_channel_from_event(sigmsg, &session); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index acddd89f23..1804090136 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -151,6 +151,7 @@ #define GOTO_STATUS(label,st) status = st; goto label ; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) +#define zap_set_string(x,y) strncpy(x, y, sizeof(x)-1) #define zap_strlen_zero(s) (!s || *s == '\0') @@ -222,6 +223,15 @@ struct zap_event { #define ZAP_TOKEN_STRLEN 128 #define ZAP_MAX_TOKENS 10 + + +struct zap_caller_data { + char cid_name[80]; + char ani[25]; + char aniII[25]; + char dnis[25]; +}; + struct zap_channel { uint32_t span_id; uint32_t chan_id; @@ -253,6 +263,7 @@ struct zap_channel { uint32_t token_count; char chan_name[128]; char chan_number[32]; + struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; }; @@ -263,11 +274,6 @@ struct zap_sigmsg { uint32_t chan_id; uint32_t span_id; zap_channel_t *channel; - zap_span_t *span; - char cid_name[80]; - char ani[25]; - char aniII[25]; - char dnis[25]; void *raw_data; uint32_t raw_data_len; }; @@ -305,6 +311,7 @@ struct zap_span { char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + zio_channel_outgoing_call_t outgoing_call; void *app_data; }; @@ -326,6 +333,7 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 4abc83a23c..b1431878f1 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -79,7 +79,8 @@ typedef enum { ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) typedef enum { - ZAP_OOB_DTMF, ZAP_OOB_ONHOOK, + ZAP_OOB_DTMF, + ZAP_OOB_ONHOOK, ZAP_OOB_OFFHOOK, ZAP_OOB_WINK, ZAP_OOB_FLASH, @@ -168,7 +169,10 @@ typedef enum { 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_COUNT } zap_command_t; @@ -203,9 +207,10 @@ typedef enum { ZAP_CHANNEL_STATE_BUSY, ZAP_CHANNEL_STATE_ATTN, ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -222,7 +227,9 @@ typedef enum { ZAP_CHANNEL_FLASH = (1 << 10), ZAP_CHANNEL_STATE_CHANGE = (1 << 11), ZAP_CHANNEL_HOLD = (1 << 12), - ZAP_CHANNEL_INUSE = (1 << 13) + ZAP_CHANNEL_INUSE = (1 << 13), + ZAP_CHANNEL_OFFHOOK = (1 << 14), + ZAP_CHANNEL_RINGING = (1 << 15) } zap_channel_flag_t; @@ -231,6 +238,7 @@ typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; +#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) @@ -246,6 +254,7 @@ typedef struct zap_span zap_span_t; #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) +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 ; @@ -261,6 +270,7 @@ 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 ; +#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 @@ -276,16 +286,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_CONFIGURE_SPAN_MUZZLE assert(zio != NULL) -#define ZIO_OPEN_MUZZLE assert(zchan != NULL) -#define ZIO_CLOSE_MUZZLE assert(zchan != NULL) -#define ZIO_COMMAND_MUZZLE assert(zchan != NULL); assert(command != 0); assert(obj != NULL) -#define ZIO_WAIT_MUZZLE assert(zchan != NULL); assert(flags != 0); assert(to != 0) -#define ZIO_READ_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) -#define ZIO_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL) - #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ - #define ZAP_LOG_LEVEL_DEBUG 7 #define ZAP_LOG_LEVEL_INFO 6 #define ZAP_LOG_LEVEL_NOTICE 5 diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 5e27509259..086eab7514 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) { zap_span_t *span; int span_id; - + if (argc < 2) { printf("usage %s \n", argv[0]); exit(-1); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index dd41ebe8fa..400a8999ac 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -34,6 +34,24 @@ #include "openzap.h" #include "zap_analog.h" +static void *zap_analog_channel_run(zap_thread_t *me, void *obj); + +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) +{ + return ZAP_FAIL; +} + +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_GENRING); + zap_thread_create_detached(zap_analog_channel_run, zchan); + } + + return ZAP_SUCCESS; +} + 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) { @@ -60,6 +78,7 @@ zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t span->analog_data->max_dialstr = max_dialstr; span->analog_data->sig_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; + 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; @@ -124,7 +143,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.chan_id = chan->chan_id; sig.span_id = chan->span_id; sig.channel = chan; - sig.span = chan->span; + while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -137,6 +156,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { + case ZAP_CHANNEL_STATE_GENRING: + { + if (state_counter > 60000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_sleep(interval); + continue; + } + } + break; case ZAP_CHANNEL_STATE_DIALTONE: { if (state_counter > 10000) { @@ -182,6 +211,15 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: { zap_channel_use(chan); + + if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + } + + if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } + if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { zap_clear_flag(chan, ZAP_CHANNEL_HOLD); sig.event_id = ZAP_SIGEVENT_FLASH; @@ -197,7 +235,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_use(chan); sig.event_id = ZAP_SIGEVENT_START; - zap_copy_string(sig.dnis, dtmf, sizeof(sig.dnis)); + zap_copy_string(chan->caller_data.dnis, dtmf, sizeof(chan->caller_data.dnis)); data->sig_cb(&sig); continue; } @@ -220,6 +258,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; + case ZAP_CHANNEL_STATE_GENRING: + { + zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); + } + break; case ZAP_CHANNEL_STATE_RING: { zap_channel_done(chan); @@ -250,137 +293,168 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { - zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); - } - dtmf_offset = strlen(dtmf); - last_digit = elapsed; - } - } + if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { + zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + } + } - if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { - zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); - last_digit = 0; - } + if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; + } - if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { - continue; - } + if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; + } - if (!(flags & ZAP_READ)) { - continue; - } + if (!(flags & ZAP_READ)) { + continue; + } - if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { - goto done; - } + if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + goto done; + } - if (!indicate) { - continue; - } + if (!indicate) { + continue; + } - if (chan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } + if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + } - rlen = zap_buffer_read_loop(dt_buffer, frame, len); + if (chan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } - if (chan->effective_codec != ZAP_CODEC_SLIN) { - zio_codec_t codec_func = NULL; + rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (chan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } + if (chan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); - goto done; - } - } + if (chan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (chan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } - zap_channel_write(chan, frame, &rlen); - } + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + goto done; + } + } - done: + zap_channel_write(chan, frame, &rlen); + } - closed_chan = chan; - zap_channel_close(&chan); + done: - zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); + if (chan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(chan, ZAP_COMMAND_ONHOOK, NULL); + } - if (ts.buffer) { - teletone_destroy_session(&ts); - } + if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } - if (dt_buffer) { - zap_buffer_destroy(&dt_buffer); - } + + closed_chan = chan; + zap_channel_close(&chan); - zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); + if (ts.buffer) { + teletone_destroy_session(&ts); + } - return NULL; - } + if (dt_buffer) { + zap_buffer_destroy(&dt_buffer); + } - static zap_status_t process_event(zap_span_t *span, zap_event_t *event) - { - zap_sigmsg_t sig; - zap_analog_data_t *data = event->channel->span->analog_data; + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - sig.span = event->channel->span; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); - 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)); + return NULL; +} - zap_mutex_lock(event->channel->mutex); +static zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_sigmsg_t sig; + zap_analog_data_t *data = event->channel->span->analog_data; + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; - switch(event->enum_id) { - case ZAP_OOB_ONHOOK: - { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - break; - case ZAP_OOB_FLASH: - { + 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)); - sig.event_id = ZAP_SIGEVENT_FLASH; - zap_channel_rotate_tokens(event->channel); + zap_mutex_lock(event->channel->mutex); - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - data->sig_cb(&sig); - if (event->channel->token_count == 1) { - zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - } - } - } + + switch(event->enum_id) { + case ZAP_OOB_RING_START: + { + + if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + sig.event_id = ZAP_SIGEVENT_START; + zap_set_string(event->channel->caller_data.dnis, event->channel->chan_number); + data->sig_cb(&sig); + zap_channel_command(event->channel, ZAP_COMMAND_OFFHOOK, NULL); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RING); + zap_thread_create_detached(zap_analog_channel_run, event->channel); + } + } + break; + case ZAP_OOB_ONHOOK: + { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); + } + break; + case ZAP_OOB_FLASH: + { + + sig.event_id = ZAP_SIGEVENT_FLASH; + zap_channel_rotate_tokens(event->channel); + + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); + } else { + data->sig_cb(&sig); + if (event->channel->token_count == 1) { + zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + } + } + } break; case ZAP_OOB_OFFHOOK: { - if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + if (event->channel->type == ZAP_CHAN_TYPE_FXS && 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 { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); zap_thread_create_detached(zap_analog_channel_run, event->channel); } } } - + zap_mutex_unlock(event->channel->mutex); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 813a263846..49bc73e73a 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -474,19 +474,18 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z if (span_id) { span_max = span_id; + j = span_id; } else { span_max = globals.span_index; - } - - if (direction == ZAP_TOP_DOWN) { - j = 1; - } else { - j = span_max; + if (direction == ZAP_TOP_DOWN) { + j = 1; + } else { + j = span_max; + } } for(;;) { span = &globals.spans[j]; - if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } @@ -527,6 +526,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z if (status == ZAP_SUCCESS) { zap_set_flag(check, ZAP_CHANNEL_INUSE); + zap_channel_open_chan(check); *zchan = check; return status; } @@ -560,7 +560,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->event_callback = NULL; zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - zap_clear_flag(zchan, ZAP_CHANNEL_INUSE); + zap_channel_done(zchan); zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; @@ -644,11 +644,24 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t return status; } +zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) +{ + assert(zchan != NULL); + if (zchan->span->outgoing_call) { + return zchan->span->outgoing_call(zchan); + } else { + zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n"); + } + + return ZAP_FAIL; +} + zap_status_t zap_channel_done(zap_channel_t *zchan) { assert(zchan != NULL); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); return ZAP_SUCCESS; @@ -728,11 +741,6 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo assert(zchan != NULL); assert(zchan->zio != NULL); - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); - return ZAP_FAIL; - } - zap_mutex_lock(zchan->mutex); switch(command) { diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 9d3dcc43f1..191e010c41 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -232,7 +232,6 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) static ZIO_CLOSE_FUNCTION(wanpipe_close) { - ZIO_CLOSE_MUZZLE; return ZAP_SUCCESS; } @@ -241,8 +240,6 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) wanpipe_tdm_api_t tdm_api; int err = 0; - ZIO_COMMAND_MUZZLE; - memset(&tdm_api, 0, sizeof(tdm_api)); switch(command) { diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 9f86ffe01f..c5486ab8cf 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -53,25 +53,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za for(x = start; x < end; x++) { zap_channel_t *chan; zap_socket_t sockfd = ZT_INVALID_SOCKET; - int command; int len; snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - command = ZT_START; -#if 0 - - if (ioctl(sockfd, ZT_HOOK, &command)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - - continue; - } -#endif - - len = zt_globals.codec_ms * 8; if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", @@ -218,13 +205,11 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) static ZIO_OPEN_FUNCTION(zt_open) { - ZIO_OPEN_MUZZLE; return ZAP_SUCCESS; } static ZIO_CLOSE_FUNCTION(zt_close) { - ZIO_CLOSE_MUZZLE; return ZAP_SUCCESS; } @@ -233,9 +218,47 @@ static ZIO_COMMAND_FUNCTION(zt_command) zt_params_t ztp = {0}; int err = 0; - ZIO_COMMAND_MUZZLE; - switch(command) { + case ZAP_COMMAND_OFFHOOK: + { + int command = ZT_OFFHOOK; + if (ioctl(zchan->sockfd, ZT_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, ZT_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_GENERATE_RING_ON: + { + int command = ZT_RING; + if (ioctl(zchan->sockfd, ZT_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, ZT_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, ZT_GET_BLOCKSIZE, &zchan->packet_len))) { @@ -344,11 +367,9 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) int i, j = 0, k = 0, r, e; for(i = 1; i <= span->chan_count; i++) { - e = ZT_IOMUX_SIGEVENT; memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i].sockfd; pfds[j].events = POLLPRI; - ioctl(span->channels[i].sockfd ,ZT_IOMUX, &e); j++; } @@ -386,6 +407,21 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) } 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; @@ -486,6 +522,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) 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; From 91ba4e6786c107b209e9d89725a5fa7445720fce Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 00:31:50 +0000 Subject: [PATCH 0379/1766] analog for zt works, still need some more for wanpipe git-svn-id: http://svn.openzap.org/svn/openzap/trunk@190 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 12 ++- libs/openzap/src/include/openzap.h | 8 +- libs/openzap/src/include/zap_types.h | 14 ++- libs/openzap/src/include/zap_zt.h | 4 +- libs/openzap/src/testanalog.c | 2 +- libs/openzap/src/testapp.c | 7 +- libs/openzap/src/zap_analog.c | 83 ++++++++++++++- libs/openzap/src/zap_io.c | 137 ++++++++++++++++++------- libs/openzap/src/zap_isdn.c | 2 +- libs/openzap/src/zap_zt.c | 8 ++ 10 files changed, 221 insertions(+), 56 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 0e970d772d..a2c974a599 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -470,7 +470,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, &len) != ZAP_SUCCESS) { + if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { return SWITCH_STATUS_GENERR; } @@ -764,11 +764,21 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; zap_status_t status; zap_log(ZAP_LOG_DEBUG, "got fxo sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_START: { status = zap_channel_from_event(sigmsg, &session); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 1804090136..55a5e8d14e 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -248,6 +248,7 @@ struct zap_channel { zap_channel_state_t last_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; + uint32_t dtmf_delay; zap_event_t event_header; char last_error[256]; zio_event_cb_t event_callback; @@ -260,9 +261,12 @@ struct zap_channel { teletone_generation_session_t tone_session; zap_time_t last_event_time; char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; + uint8_t need_tone[ZAP_TONEMAP_INVALID+1]; uint32_t token_count; char chan_name[128]; char chan_number[32]; + zap_tonemap_t detected_tone; + zap_tonemap_t last_detected_tone; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -310,6 +314,8 @@ struct zap_span { zap_event_t event_header; char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; + teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; + teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; zio_channel_outgoing_call_t outgoing_call; void *app_data; @@ -359,7 +365,7 @@ zap_status_t zap_channel_use(zap_channel_t *zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index b1431878f1..2a828965e1 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -57,13 +57,14 @@ typedef uint64_t zap_time_t; #define ZAP_TONEMAP_LEN 128 typedef enum { + ZAP_TONEMAP_NONE, ZAP_TONEMAP_DIAL, ZAP_TONEMAP_RING, ZAP_TONEMAP_BUSY, ZAP_TONEMAP_ATTN, ZAP_TONEMAP_INVALID } zap_tonemap_t; -#define TONEMAP_STRINGS "DIAL", "RING", "BUSY", "ATTN", "INVALID" +#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "ATTN", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) typedef enum { @@ -108,10 +109,11 @@ typedef enum { ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, + ZAP_SIGEVENT_TONE_DETECTED, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -173,6 +175,8 @@ typedef enum { ZAP_COMMAND_GENERATE_RING_OFF, ZAP_COMMAND_OFFHOOK, ZAP_COMMAND_ONHOOK, + ZAP_COMMAND_ENABLE_PROGRESS_DETECT, + ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_COUNT } zap_command_t; @@ -208,9 +212,10 @@ typedef enum { ZAP_CHANNEL_STATE_ATTN, ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_GENRING, + ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -229,7 +234,8 @@ typedef enum { ZAP_CHANNEL_HOLD = (1 << 12), ZAP_CHANNEL_INUSE = (1 << 13), ZAP_CHANNEL_OFFHOOK = (1 << 14), - ZAP_CHANNEL_RINGING = (1 << 15) + ZAP_CHANNEL_RINGING = (1 << 15), + ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16) } zap_channel_flag_t; diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 48ee34bbc9..1ad2e65c20 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -207,7 +207,7 @@ typedef enum { #define ZT_SETGAINS _IOWR (ZT_CODE, 17, struct zt_gains) /* Set Channel audio gains */ #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 */ @@ -221,7 +221,7 @@ typedef enum { #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 */ /* Openzap ZT hardware interface functions */ diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 086eab7514..e1f17d23fd 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -25,7 +25,7 @@ static void *test_call(zap_thread_t *me, void *obj) 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, &len); + zap_channel_write(chan, frame, sizeof(frame), &len); } else { break; } diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 309239c3d4..12b22b30b3 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -8,11 +8,6 @@ int main(int argc, char *argv[]) zap_codec_t codec = ZAP_CODEC_SLIN; unsigned runs = 1; - if (!argv[1]) { - printf("usage %s \n", argv[0]); - exit(-1); - } - if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); @@ -23,7 +18,7 @@ int main(int argc, char *argv[]) top: //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open(argv[1], 1, 1, &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); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 400a8999ac..a6feaabc07 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -38,6 +38,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); + zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL); + zchan->need_tone[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; } @@ -114,6 +122,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_sigmsg_t sig; zap_status_t status; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); ts.buffer = NULL; @@ -156,6 +165,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { + case ZAP_CHANNEL_STATE_DIALING: + { + if (state_counter > 5000) { + if (chan->need_tone[ZAP_TONEMAP_DIAL]) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } else { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + } + } + } + break; case ZAP_CHANNEL_STATE_GENRING: { if (state_counter > 60000) { @@ -183,7 +203,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_HANGUP: { if (state_counter > 2000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (chan->type == ZAP_CHAN_TYPE_FXO) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } } } break; @@ -231,6 +255,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } break; + case ZAP_CHANNEL_STATE_DIALING: + { + zap_channel_use(chan); + } + break; case ZAP_CHANNEL_STATE_IDLE: { zap_channel_use(chan); @@ -323,6 +352,55 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } + if (chan->detected_tone) { + zap_sigmsg_t sig; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = chan->chan_id; + sig.span_id = chan->span_id; + sig.channel = chan; + sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; + zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tone)); + data->sig_cb(&sig); + + if (chan->type == ZAP_CHAN_TYPE_FXO) { + + if (chan->need_tone[chan->detected_tone]) { + switch (chan->detected_tone) { + case ZAP_TONEMAP_DIAL: + { + zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); + state_counter = 0; + chan->need_tone[ZAP_TONEMAP_RING] = 1; + chan->need_tone[ZAP_TONEMAP_BUSY] = 1; + } + break; + case ZAP_TONEMAP_RING: + { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + } + break; + case ZAP_TONEMAP_BUSY: + { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + break; + default: + break; + } + chan->need_tone[chan->detected_tone] = 0; + } + } + chan->detected_tone = 0; + } + + if (chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) { + rlen = len; + memset(frame, 0, len); + zap_channel_write(chan, frame, sizeof(frame), &rlen); + continue; + } + + if (!indicate) { continue; } @@ -337,6 +415,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) rlen = zap_buffer_read_loop(dt_buffer, frame, len); + if (chan->effective_codec != ZAP_CODEC_SLIN) { zio_codec_t codec_func = NULL; @@ -354,7 +433,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - zap_channel_write(chan, frame, &rlen); + zap_channel_write(chan, frame, sizeof(frame), &rlen); } done: diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 49bc73e73a..6df7ee8bc4 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -271,9 +271,30 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, mapname) && var && val) { int index = zap_str2zap_tonemap(var); - if (index > ZAP_TONEMAP_INVALID) { + char valbuf[512]; + + if (index > ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); } else { + char *p, *next; + int i = 0; + zap_set_string(valbuf, val); + val = valbuf; + if ((p = strchr(val, ':'))) { + *p++ = '\0'; + do { + teletone_process_t this; + next = strchr(p, ','); + this = atof(p); + span->tone_detect_map[index].freqs[i++] = this; + if (next) { + p = next + 1; + } + } while (next); + + zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); + + } zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s]\n", var, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); x++; @@ -718,7 +739,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) } if (!zchan->dtmf_on) { - zchan->dtmf_on = 150; + zchan->dtmf_on = 250; } if (!zchan->dtmf_off) { @@ -726,11 +747,16 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) } memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - teletone_init_session(&zchan->tone_session, 1024, NULL, NULL); + teletone_init_session(&zchan->tone_session, 0, NULL, NULL); zchan->tone_session.rate = 8000; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); + /* + zchan->tone_session.debug = 1; + zchan->tone_session.debug_stream = stdout; + */ + return ZAP_SUCCESS; } @@ -809,6 +835,22 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } break; + case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: + { + /* if they don't have thier own, use ours */ + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, ZAP_SUCCESS); + } + break; + case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: + { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, ZAP_SUCCESS); + } + break; case ZAP_COMMAND_ENABLE_TONE_DETECT: { /* if they don't have thier own, use ours */ @@ -816,8 +858,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); - zap_set_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_set_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); @@ -890,6 +932,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; + int x = 0; + if (!zchan->dtmf_buffer) { if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { GOTO_STATUS(done, status); @@ -901,10 +945,11 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); + x++; } } - zchan->skip_read_frames = 200; + zchan->skip_read_frames = 200 * x; GOTO_STATUS(done, ZAP_SUCCESS); } } @@ -1169,7 +1214,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint8_t sln_buf[1024] = {0}; int16_t *sln; zap_size_t slen = 0; @@ -1203,47 +1248,62 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data slen = len; } - teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); - teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); - - if(*digit_str) { - zio_event_cb_t event_callback = NULL; - - zap_channel_queue_dtmf(zchan, digit_str); - - if (zchan->span->event_callback) { - event_callback = zchan->span->event_callback; - } else if (zchan->event_callback) { - event_callback = zchan->event_callback; + if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { + uint32_t i; + + for (i = 0; i < ZAP_TONEMAP_INVALID+1; i++) { + if (zchan->span->tone_finder[i].tone_count) { + if (teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen) && i != zchan->last_detected_tone) { + zchan->detected_tone = i; + zchan->last_detected_tone = i; + } + } } + } - if (event_callback) { - zchan->event_header.channel = zchan; - zchan->event_header.e_type = ZAP_EVENT_DTMF; - zchan->event_header.data = digit_str; - event_callback(zchan, &zchan->event_header); - zchan->event_header.e_type = ZAP_EVENT_NONE; - zchan->event_header.data = NULL; + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + + teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); + teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); + + if(*digit_str) { + zio_event_cb_t event_callback = NULL; + + zap_channel_queue_dtmf(zchan, digit_str); + + if (zchan->span->event_callback) { + event_callback = zchan->span->event_callback; + } else if (zchan->event_callback) { + event_callback = zchan->event_callback; + } + + if (event_callback) { + zchan->event_header.channel = zchan; + zchan->event_header.e_type = ZAP_EVENT_DTMF; + zchan->event_header.data = digit_str; + event_callback(zchan, &zchan->event_header); + zchan->event_header.e_type = ZAP_EVENT_NONE; + zchan->event_header.data = NULL; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { + zchan->skip_read_frames = 20; + } + if (zchan->skip_read_frames > 0) { + memset(data, 0, *datalen); + zchan->skip_read_frames--; + } } - if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { - zchan->skip_read_frames = 20; - } - if (zchan->skip_read_frames > 0) { - memset(data, 0, *datalen); - zchan->skip_read_frames--; - } } } - return status; } -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t dtmf_blen, max = *datalen; + zap_size_t dtmf_blen, max = datasize; assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1277,11 +1337,11 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat } } - if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer)) && (!zchan->dtmf_delay || --zchan->dtmf_delay == 0)) { zap_size_t dlen = *datalen; uint8_t auxbuf[1024]; zap_size_t len, br; - + if (zchan->native_codec != ZAP_CODEC_SLIN) { dlen *= 2; } @@ -1305,6 +1365,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat zio_slin2alaw(data, max, datalen); } } + } status = zchan->zio->write(zchan, data, datalen); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 7bca3922b1..a8e7281460 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -95,7 +95,7 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) #endif assert(span != NULL); - return zap_channel_write(span->isdn_data->dchan, msg, &len) == ZAP_SUCCESS ? 0 : -1; + return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } static void *zap_isdn_run(zap_thread_t *me, void *obj) diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index c5486ab8cf..9b02a35b0f 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -59,6 +59,14 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + len = 64; + if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } + len = zt_globals.codec_ms * 8; if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", From d9ad22285aec51840ee7d2a842d53d5851d48a6c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 00:31:50 +0000 Subject: [PATCH 0380/1766] analog for zt works, still need some more for wanpipe git-svn-id: http://svn.openzap.org/svn/openzap/trunk@190 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 12 ++- libs/freetdm/src/include/openzap.h | 8 +- libs/freetdm/src/include/zap_types.h | 14 ++- libs/freetdm/src/include/zap_zt.h | 4 +- libs/freetdm/src/testanalog.c | 2 +- libs/freetdm/src/testapp.c | 7 +- libs/freetdm/src/zap_analog.c | 83 ++++++++++++++- libs/freetdm/src/zap_io.c | 137 ++++++++++++++++++------- libs/freetdm/src/zap_isdn.c | 2 +- libs/freetdm/src/zap_zt.c | 8 ++ 10 files changed, 221 insertions(+), 56 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 0e970d772d..a2c974a599 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -470,7 +470,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, &len) != ZAP_SUCCESS) { + if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { return SWITCH_STATUS_GENERR; } @@ -764,11 +764,21 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; zap_status_t status; zap_log(ZAP_LOG_DEBUG, "got fxo sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_START: { status = zap_channel_from_event(sigmsg, &session); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 1804090136..55a5e8d14e 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -248,6 +248,7 @@ struct zap_channel { zap_channel_state_t last_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; + uint32_t dtmf_delay; zap_event_t event_header; char last_error[256]; zio_event_cb_t event_callback; @@ -260,9 +261,12 @@ struct zap_channel { teletone_generation_session_t tone_session; zap_time_t last_event_time; char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; + uint8_t need_tone[ZAP_TONEMAP_INVALID+1]; uint32_t token_count; char chan_name[128]; char chan_number[32]; + zap_tonemap_t detected_tone; + zap_tonemap_t last_detected_tone; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -310,6 +314,8 @@ struct zap_span { zap_event_t event_header; char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; + teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; + teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; zio_channel_outgoing_call_t outgoing_call; void *app_data; @@ -359,7 +365,7 @@ zap_status_t zap_channel_use(zap_channel_t *zchan); zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen); +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b1431878f1..2a828965e1 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -57,13 +57,14 @@ typedef uint64_t zap_time_t; #define ZAP_TONEMAP_LEN 128 typedef enum { + ZAP_TONEMAP_NONE, ZAP_TONEMAP_DIAL, ZAP_TONEMAP_RING, ZAP_TONEMAP_BUSY, ZAP_TONEMAP_ATTN, ZAP_TONEMAP_INVALID } zap_tonemap_t; -#define TONEMAP_STRINGS "DIAL", "RING", "BUSY", "ATTN", "INVALID" +#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "ATTN", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) typedef enum { @@ -108,10 +109,11 @@ typedef enum { ZAP_SIGEVENT_PROGRESS, ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, + ZAP_SIGEVENT_TONE_DETECTED, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -173,6 +175,8 @@ typedef enum { ZAP_COMMAND_GENERATE_RING_OFF, ZAP_COMMAND_OFFHOOK, ZAP_COMMAND_ONHOOK, + ZAP_COMMAND_ENABLE_PROGRESS_DETECT, + ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_COUNT } zap_command_t; @@ -208,9 +212,10 @@ typedef enum { ZAP_CHANNEL_STATE_ATTN, ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_GENRING, + ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -229,7 +234,8 @@ typedef enum { ZAP_CHANNEL_HOLD = (1 << 12), ZAP_CHANNEL_INUSE = (1 << 13), ZAP_CHANNEL_OFFHOOK = (1 << 14), - ZAP_CHANNEL_RINGING = (1 << 15) + ZAP_CHANNEL_RINGING = (1 << 15), + ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16) } zap_channel_flag_t; diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 48ee34bbc9..1ad2e65c20 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -207,7 +207,7 @@ typedef enum { #define ZT_SETGAINS _IOWR (ZT_CODE, 17, struct zt_gains) /* Set Channel audio gains */ #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 */ @@ -221,7 +221,7 @@ typedef enum { #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 */ /* Openzap ZT hardware interface functions */ diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 086eab7514..e1f17d23fd 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -25,7 +25,7 @@ static void *test_call(zap_thread_t *me, void *obj) 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, &len); + zap_channel_write(chan, frame, sizeof(frame), &len); } else { break; } diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 309239c3d4..12b22b30b3 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -8,11 +8,6 @@ int main(int argc, char *argv[]) zap_codec_t codec = ZAP_CODEC_SLIN; unsigned runs = 1; - if (!argv[1]) { - printf("usage %s \n", argv[0]); - exit(-1); - } - if (zap_global_init() != ZAP_SUCCESS) { fprintf(stderr, "Error loading OpenZAP\n"); @@ -23,7 +18,7 @@ int main(int argc, char *argv[]) top: //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open(argv[1], 1, 1, &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); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 400a8999ac..a6feaabc07 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -38,6 +38,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); + zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL); + zchan->need_tone[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; } @@ -114,6 +122,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_sigmsg_t sig; zap_status_t status; + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); ts.buffer = NULL; @@ -156,6 +165,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { + case ZAP_CHANNEL_STATE_DIALING: + { + if (state_counter > 5000) { + if (chan->need_tone[ZAP_TONEMAP_DIAL]) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } else { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + } + } + } + break; case ZAP_CHANNEL_STATE_GENRING: { if (state_counter > 60000) { @@ -183,7 +203,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_HANGUP: { if (state_counter > 2000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (chan->type == ZAP_CHAN_TYPE_FXO) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } } } break; @@ -231,6 +255,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } break; + case ZAP_CHANNEL_STATE_DIALING: + { + zap_channel_use(chan); + } + break; case ZAP_CHANNEL_STATE_IDLE: { zap_channel_use(chan); @@ -323,6 +352,55 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } + if (chan->detected_tone) { + zap_sigmsg_t sig; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = chan->chan_id; + sig.span_id = chan->span_id; + sig.channel = chan; + sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; + zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tone)); + data->sig_cb(&sig); + + if (chan->type == ZAP_CHAN_TYPE_FXO) { + + if (chan->need_tone[chan->detected_tone]) { + switch (chan->detected_tone) { + case ZAP_TONEMAP_DIAL: + { + zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); + state_counter = 0; + chan->need_tone[ZAP_TONEMAP_RING] = 1; + chan->need_tone[ZAP_TONEMAP_BUSY] = 1; + } + break; + case ZAP_TONEMAP_RING: + { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + } + break; + case ZAP_TONEMAP_BUSY: + { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + break; + default: + break; + } + chan->need_tone[chan->detected_tone] = 0; + } + } + chan->detected_tone = 0; + } + + if (chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) { + rlen = len; + memset(frame, 0, len); + zap_channel_write(chan, frame, sizeof(frame), &rlen); + continue; + } + + if (!indicate) { continue; } @@ -337,6 +415,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) rlen = zap_buffer_read_loop(dt_buffer, frame, len); + if (chan->effective_codec != ZAP_CODEC_SLIN) { zio_codec_t codec_func = NULL; @@ -354,7 +433,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - zap_channel_write(chan, frame, &rlen); + zap_channel_write(chan, frame, sizeof(frame), &rlen); } done: diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 49bc73e73a..6df7ee8bc4 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -271,9 +271,30 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, mapname) && var && val) { int index = zap_str2zap_tonemap(var); - if (index > ZAP_TONEMAP_INVALID) { + char valbuf[512]; + + if (index > ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); } else { + char *p, *next; + int i = 0; + zap_set_string(valbuf, val); + val = valbuf; + if ((p = strchr(val, ':'))) { + *p++ = '\0'; + do { + teletone_process_t this; + next = strchr(p, ','); + this = atof(p); + span->tone_detect_map[index].freqs[i++] = this; + if (next) { + p = next + 1; + } + } while (next); + + zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); + + } zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s]\n", var, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); x++; @@ -718,7 +739,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) } if (!zchan->dtmf_on) { - zchan->dtmf_on = 150; + zchan->dtmf_on = 250; } if (!zchan->dtmf_off) { @@ -726,11 +747,16 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) } memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - teletone_init_session(&zchan->tone_session, 1024, NULL, NULL); + teletone_init_session(&zchan->tone_session, 0, NULL, NULL); zchan->tone_session.rate = 8000; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); + /* + zchan->tone_session.debug = 1; + zchan->tone_session.debug_stream = stdout; + */ + return ZAP_SUCCESS; } @@ -809,6 +835,22 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } break; + case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: + { + /* if they don't have thier own, use ours */ + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, ZAP_SUCCESS); + } + break; + case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: + { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, ZAP_SUCCESS); + } + break; case ZAP_COMMAND_ENABLE_TONE_DETECT: { /* if they don't have thier own, use ours */ @@ -816,8 +858,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); - zap_set_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_set_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); GOTO_STATUS(done, ZAP_SUCCESS); } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); @@ -890,6 +932,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; + int x = 0; + if (!zchan->dtmf_buffer) { if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { GOTO_STATUS(done, status); @@ -901,10 +945,11 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); + x++; } } - zchan->skip_read_frames = 200; + zchan->skip_read_frames = 200 * x; GOTO_STATUS(done, ZAP_SUCCESS); } } @@ -1169,7 +1214,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint8_t sln_buf[1024] = {0}; int16_t *sln; zap_size_t slen = 0; @@ -1203,47 +1248,62 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data slen = len; } - teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); - teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); - - if(*digit_str) { - zio_event_cb_t event_callback = NULL; - - zap_channel_queue_dtmf(zchan, digit_str); - - if (zchan->span->event_callback) { - event_callback = zchan->span->event_callback; - } else if (zchan->event_callback) { - event_callback = zchan->event_callback; + if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { + uint32_t i; + + for (i = 0; i < ZAP_TONEMAP_INVALID+1; i++) { + if (zchan->span->tone_finder[i].tone_count) { + if (teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen) && i != zchan->last_detected_tone) { + zchan->detected_tone = i; + zchan->last_detected_tone = i; + } + } } + } - if (event_callback) { - zchan->event_header.channel = zchan; - zchan->event_header.e_type = ZAP_EVENT_DTMF; - zchan->event_header.data = digit_str; - event_callback(zchan, &zchan->event_header); - zchan->event_header.e_type = ZAP_EVENT_NONE; - zchan->event_header.data = NULL; + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + + teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); + teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); + + if(*digit_str) { + zio_event_cb_t event_callback = NULL; + + zap_channel_queue_dtmf(zchan, digit_str); + + if (zchan->span->event_callback) { + event_callback = zchan->span->event_callback; + } else if (zchan->event_callback) { + event_callback = zchan->event_callback; + } + + if (event_callback) { + zchan->event_header.channel = zchan; + zchan->event_header.e_type = ZAP_EVENT_DTMF; + zchan->event_header.data = digit_str; + event_callback(zchan, &zchan->event_header); + zchan->event_header.e_type = ZAP_EVENT_NONE; + zchan->event_header.data = NULL; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { + zchan->skip_read_frames = 20; + } + if (zchan->skip_read_frames > 0) { + memset(data, 0, *datalen); + zchan->skip_read_frames--; + } } - if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { - zchan->skip_read_frames = 20; - } - if (zchan->skip_read_frames > 0) { - memset(data, 0, *datalen); - zchan->skip_read_frames--; - } } } - return status; } -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *datalen) +zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t dtmf_blen, max = *datalen; + zap_size_t dtmf_blen, max = datasize; assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1277,11 +1337,11 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat } } - if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer)) && (!zchan->dtmf_delay || --zchan->dtmf_delay == 0)) { zap_size_t dlen = *datalen; uint8_t auxbuf[1024]; zap_size_t len, br; - + if (zchan->native_codec != ZAP_CODEC_SLIN) { dlen *= 2; } @@ -1305,6 +1365,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat zio_slin2alaw(data, max, datalen); } } + } status = zchan->zio->write(zchan, data, datalen); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 7bca3922b1..a8e7281460 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -95,7 +95,7 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) #endif assert(span != NULL); - return zap_channel_write(span->isdn_data->dchan, msg, &len) == ZAP_SUCCESS ? 0 : -1; + return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } static void *zap_isdn_run(zap_thread_t *me, void *obj) diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index c5486ab8cf..9b02a35b0f 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -59,6 +59,14 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + len = 64; + if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } + len = zt_globals.codec_ms * 8; if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", From 6f98842659d43377524e2f124cb9163ca0ad1ede Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 00:35:58 +0000 Subject: [PATCH 0381/1766] add conf git-svn-id: http://svn.openzap.org/svn/openzap/trunk@191 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/openzap.conf.xml | 14 ++++++++++++++ libs/openzap/conf/tones.conf | 9 +++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 libs/openzap/conf/openzap.conf.xml diff --git a/libs/openzap/conf/openzap.conf.xml b/libs/openzap/conf/openzap.conf.xml new file mode 100644 index 0000000000..be802f9f5f --- /dev/null +++ b/libs/openzap/conf/openzap.conf.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index 2032823d0c..d7825b767e 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -1,5 +1,6 @@ [us] -dial => %(1000,0,350,440) -ring => %(2000,4000,440,480) -busy => %(500,500,480,620) -attn => %(100,100,1400,2060,2450,2600) +; tone_name => : +dial => %(1000,0,350,440):350,440 +ring => %(2000,4000,440,480):440:480 +busy => %(500,500,480,620):480:620 +attn => %(100,100,1400,2060,2450,2600):1400,2060,2450,2600 From 943586b1aae1a9b40c3fc3cf2999c78c4964d6dd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 00:35:58 +0000 Subject: [PATCH 0382/1766] add conf git-svn-id: http://svn.openzap.org/svn/openzap/trunk@191 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/openzap.conf.xml | 14 ++++++++++++++ libs/freetdm/conf/tones.conf | 9 +++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 libs/freetdm/conf/openzap.conf.xml diff --git a/libs/freetdm/conf/openzap.conf.xml b/libs/freetdm/conf/openzap.conf.xml new file mode 100644 index 0000000000..be802f9f5f --- /dev/null +++ b/libs/freetdm/conf/openzap.conf.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index 2032823d0c..d7825b767e 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -1,5 +1,6 @@ [us] -dial => %(1000,0,350,440) -ring => %(2000,4000,440,480) -busy => %(500,500,480,620) -attn => %(100,100,1400,2060,2450,2600) +; tone_name => : +dial => %(1000,0,350,440):350,440 +ring => %(2000,4000,440,480):440:480 +busy => %(500,500,480,620):480:620 +attn => %(100,100,1400,2060,2450,2600):1400,2060,2450,2600 From 9586880085581a66f6dce0a916007d8eed2af890 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:25:36 +0000 Subject: [PATCH 0383/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@192 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 9 ++-- libs/openzap/src/include/zap_types.h | 5 ++- libs/openzap/src/zap_analog.c | 64 +++++++++++++--------------- libs/openzap/src/zap_io.c | 58 ++++++++++++++++--------- 4 files changed, 78 insertions(+), 58 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 55a5e8d14e..1fdb372087 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -261,12 +261,13 @@ struct zap_channel { teletone_generation_session_t tone_session; zap_time_t last_event_time; char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; - uint8_t need_tone[ZAP_TONEMAP_INVALID+1]; + uint8_t needed_tones[ZAP_TONEMAP_INVALID]; + uint8_t detected_tones[ZAP_TONEMAP_INVALID]; + zap_tonemap_t last_detected_tone; + uint32_t token_count; char chan_name[128]; char chan_number[32]; - zap_tonemap_t detected_tone; - zap_tonemap_t last_detected_tone; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -341,6 +342,8 @@ struct zap_io_interface { zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); +void zap_channel_clear_detected_tones(zap_channel_t *zchan); +void zap_channel_clear_needed_tones(zap_channel_t *zchan); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 2a828965e1..3bd99d3b0d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -61,10 +61,13 @@ typedef enum { ZAP_TONEMAP_DIAL, ZAP_TONEMAP_RING, ZAP_TONEMAP_BUSY, + ZAP_TONEMAP_FAIL1, + ZAP_TONEMAP_FAIL2, + ZAP_TONEMAP_FAIL3, ZAP_TONEMAP_ATTN, ZAP_TONEMAP_INVALID } zap_tonemap_t; -#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "ATTN", "INVALID" +#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) typedef enum { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index a6feaabc07..ada2ca804e 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -41,7 +41,7 @@ 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_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL); - zchan->need_tone[ZAP_TONEMAP_DIAL] = 1; + 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; @@ -118,10 +118,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_size_t dtmf_offset = 0; zap_analog_data_t *data = chan->span->analog_data; zap_channel_t *closed_chan; - uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; + uint32_t state_counter = 0, elapsed = 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"); @@ -167,8 +166,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) switch(chan->state) { case ZAP_CHANNEL_STATE_DIALING: { - if (state_counter > 5000) { - if (chan->need_tone[ZAP_TONEMAP_DIAL]) { + if (state_counter > dial_timeout) { + if (chan->needed_tones[ZAP_TONEMAP_DIAL]) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } else { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); @@ -235,6 +234,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: { zap_channel_use(chan); + zap_channel_clear_needed_tones(chan); if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); @@ -352,45 +352,39 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } - if (chan->detected_tone) { + if (chan->type == ZAP_CHAN_TYPE_FXO && chan->detected_tones[0]) { zap_sigmsg_t sig; + int i; memset(&sig, 0, sizeof(sig)); sig.chan_id = chan->chan_id; sig.span_id = chan->span_id; sig.channel = chan; sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; - zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tone)); - data->sig_cb(&sig); - if (chan->type == ZAP_CHAN_TYPE_FXO) { - - if (chan->need_tone[chan->detected_tone]) { - switch (chan->detected_tone) { - case ZAP_TONEMAP_DIAL: - { - zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); - state_counter = 0; - chan->need_tone[ZAP_TONEMAP_RING] = 1; - chan->need_tone[ZAP_TONEMAP_BUSY] = 1; - } - break; - case ZAP_TONEMAP_RING: - { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); - } - break; - case ZAP_TONEMAP_BUSY: - { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); - } - break; - default: - break; - } - chan->need_tone[chan->detected_tone] = 0; + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { + if (chan->detected_tones[i]) { + zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tones[i])); + sig.raw_data = &i; + data->sig_cb(&sig); } } - chan->detected_tone = 0; + + if (chan->detected_tones[ZAP_TONEMAP_DIAL]) { + zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); + state_counter = 0; + chan->needed_tones[ZAP_TONEMAP_RING] = 1; + chan->needed_tones[ZAP_TONEMAP_BUSY] = 1; + chan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; + chan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; + chan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; + dial_timeout = (chan->dtmf_on + chan->dtmf_off) * strlen(chan->caller_data.ani) + 50; + } else if (chan->detected_tones[ZAP_TONEMAP_RING]) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + } else if (chan->detected_tones[ZAP_TONEMAP_BUSY]) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + + zap_channel_clear_detected_tones(chan); } if (chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6df7ee8bc4..7816c8d662 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -269,19 +269,27 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, mapname) && var && val) { - int index = zap_str2zap_tonemap(var); - char valbuf[512]; + int detect = 0; - if (index > ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { - zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); + if (!strcasecmp(cfg.category, mapname) && var && val) { + uint32_t index; + char *mapname; + + if (!strncasecmp(var, "detect-", 7)) { + mapname = var + 7; + detect = 1; + } else if (!strncasecmp(var, "generate-", 9)) { + mapname = var + 9; + } + + index = zap_str2zap_tonemap(mapname); + + if (index >= ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", mapname); } else { - char *p, *next; - int i = 0; - zap_set_string(valbuf, val); - val = valbuf; - if ((p = strchr(val, ':'))) { - *p++ = '\0'; + if (detect) { + char *p = val, *next; + int i = 0; do { teletone_process_t this; next = strchr(p, ','); @@ -291,12 +299,11 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) p = next + 1; } } while (next); - + zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", mapname, val); + } else { + zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", mapname, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); - } - zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s]\n", var, val); - zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); x++; } } @@ -848,6 +855,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: { zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); GOTO_STATUS(done, ZAP_SUCCESS); } break; @@ -1121,6 +1130,16 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) /******************************/ +void zap_channel_clear_detected_tones(zap_channel_t *zchan) +{ + memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); +} + +void zap_channel_clear_needed_tones(zap_channel_t *zchan) +{ + memset(zchan->needed_tones, 0, sizeof(zchan->needed_tones[0]) * ZAP_TONEMAP_INVALID); +} + zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) { zap_size_t bytes = 0; @@ -1251,11 +1270,12 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint32_t i; - for (i = 0; i < ZAP_TONEMAP_INVALID+1; i++) { + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { if (zchan->span->tone_finder[i].tone_count) { - if (teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen) && i != zchan->last_detected_tone) { - zchan->detected_tone = i; - zchan->last_detected_tone = i; + if (zchan->needed_tones[i] && teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen)) { + zchan->detected_tones[i] = 1; + zchan->needed_tones[i] = 0; + zchan->detected_tones[0]++; } } } From 43b18e4e500f4ae930d9ee26868766dc1aa52873 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:25:36 +0000 Subject: [PATCH 0384/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@192 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 9 ++-- libs/freetdm/src/include/zap_types.h | 5 ++- libs/freetdm/src/zap_analog.c | 64 +++++++++++++--------------- libs/freetdm/src/zap_io.c | 58 ++++++++++++++++--------- 4 files changed, 78 insertions(+), 58 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 55a5e8d14e..1fdb372087 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -261,12 +261,13 @@ struct zap_channel { teletone_generation_session_t tone_session; zap_time_t last_event_time; char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; - uint8_t need_tone[ZAP_TONEMAP_INVALID+1]; + uint8_t needed_tones[ZAP_TONEMAP_INVALID]; + uint8_t detected_tones[ZAP_TONEMAP_INVALID]; + zap_tonemap_t last_detected_tone; + uint32_t token_count; char chan_name[128]; char chan_number[32]; - zap_tonemap_t detected_tone; - zap_tonemap_t last_detected_tone; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -341,6 +342,8 @@ struct zap_io_interface { zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); +void zap_channel_clear_detected_tones(zap_channel_t *zchan); +void zap_channel_clear_needed_tones(zap_channel_t *zchan); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 2a828965e1..3bd99d3b0d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -61,10 +61,13 @@ typedef enum { ZAP_TONEMAP_DIAL, ZAP_TONEMAP_RING, ZAP_TONEMAP_BUSY, + ZAP_TONEMAP_FAIL1, + ZAP_TONEMAP_FAIL2, + ZAP_TONEMAP_FAIL3, ZAP_TONEMAP_ATTN, ZAP_TONEMAP_INVALID } zap_tonemap_t; -#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "ATTN", "INVALID" +#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) typedef enum { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index a6feaabc07..ada2ca804e 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -41,7 +41,7 @@ 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_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL); - zchan->need_tone[ZAP_TONEMAP_DIAL] = 1; + 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; @@ -118,10 +118,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_size_t dtmf_offset = 0; zap_analog_data_t *data = chan->span->analog_data; zap_channel_t *closed_chan; - uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; + uint32_t state_counter = 0, elapsed = 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"); @@ -167,8 +166,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) switch(chan->state) { case ZAP_CHANNEL_STATE_DIALING: { - if (state_counter > 5000) { - if (chan->need_tone[ZAP_TONEMAP_DIAL]) { + if (state_counter > dial_timeout) { + if (chan->needed_tones[ZAP_TONEMAP_DIAL]) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } else { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); @@ -235,6 +234,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_UP: { zap_channel_use(chan); + zap_channel_clear_needed_tones(chan); if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); @@ -352,45 +352,39 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } - if (chan->detected_tone) { + if (chan->type == ZAP_CHAN_TYPE_FXO && chan->detected_tones[0]) { zap_sigmsg_t sig; + int i; memset(&sig, 0, sizeof(sig)); sig.chan_id = chan->chan_id; sig.span_id = chan->span_id; sig.channel = chan; sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; - zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tone)); - data->sig_cb(&sig); - if (chan->type == ZAP_CHAN_TYPE_FXO) { - - if (chan->need_tone[chan->detected_tone]) { - switch (chan->detected_tone) { - case ZAP_TONEMAP_DIAL: - { - zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); - state_counter = 0; - chan->need_tone[ZAP_TONEMAP_RING] = 1; - chan->need_tone[ZAP_TONEMAP_BUSY] = 1; - } - break; - case ZAP_TONEMAP_RING: - { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); - } - break; - case ZAP_TONEMAP_BUSY: - { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); - } - break; - default: - break; - } - chan->need_tone[chan->detected_tone] = 0; + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { + if (chan->detected_tones[i]) { + zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tones[i])); + sig.raw_data = &i; + data->sig_cb(&sig); } } - chan->detected_tone = 0; + + if (chan->detected_tones[ZAP_TONEMAP_DIAL]) { + zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); + state_counter = 0; + chan->needed_tones[ZAP_TONEMAP_RING] = 1; + chan->needed_tones[ZAP_TONEMAP_BUSY] = 1; + chan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; + chan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; + chan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; + dial_timeout = (chan->dtmf_on + chan->dtmf_off) * strlen(chan->caller_data.ani) + 50; + } else if (chan->detected_tones[ZAP_TONEMAP_RING]) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + } else if (chan->detected_tones[ZAP_TONEMAP_BUSY]) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } + + zap_channel_clear_detected_tones(chan); } if (chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6df7ee8bc4..7816c8d662 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -269,19 +269,27 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, mapname) && var && val) { - int index = zap_str2zap_tonemap(var); - char valbuf[512]; + int detect = 0; - if (index > ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { - zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); + if (!strcasecmp(cfg.category, mapname) && var && val) { + uint32_t index; + char *mapname; + + if (!strncasecmp(var, "detect-", 7)) { + mapname = var + 7; + detect = 1; + } else if (!strncasecmp(var, "generate-", 9)) { + mapname = var + 9; + } + + index = zap_str2zap_tonemap(mapname); + + if (index >= ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", mapname); } else { - char *p, *next; - int i = 0; - zap_set_string(valbuf, val); - val = valbuf; - if ((p = strchr(val, ':'))) { - *p++ = '\0'; + if (detect) { + char *p = val, *next; + int i = 0; do { teletone_process_t this; next = strchr(p, ','); @@ -291,12 +299,11 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) p = next + 1; } } while (next); - + zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", mapname, val); + } else { + zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", mapname, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); - } - zap_log(ZAP_LOG_DEBUG, "added tone [%s] = [%s]\n", var, val); - zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); x++; } } @@ -848,6 +855,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: { zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); GOTO_STATUS(done, ZAP_SUCCESS); } break; @@ -1121,6 +1130,16 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) /******************************/ +void zap_channel_clear_detected_tones(zap_channel_t *zchan) +{ + memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); +} + +void zap_channel_clear_needed_tones(zap_channel_t *zchan) +{ + memset(zchan->needed_tones, 0, sizeof(zchan->needed_tones[0]) * ZAP_TONEMAP_INVALID); +} + zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) { zap_size_t bytes = 0; @@ -1251,11 +1270,12 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint32_t i; - for (i = 0; i < ZAP_TONEMAP_INVALID+1; i++) { + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { if (zchan->span->tone_finder[i].tone_count) { - if (teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen) && i != zchan->last_detected_tone) { - zchan->detected_tone = i; - zchan->last_detected_tone = i; + if (zchan->needed_tones[i] && teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen)) { + zchan->detected_tones[i] = 1; + zchan->needed_tones[i] = 0; + zchan->detected_tones[0]++; } } } From b389c6c056a9d0e74a7f243f88d50e6365918579 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:34:40 +0000 Subject: [PATCH 0385/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@193 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 7816c8d662..3877d5213d 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -273,19 +273,22 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) if (!strcasecmp(cfg.category, mapname) && var && val) { uint32_t index; - char *mapname; + char *name = NULL; if (!strncasecmp(var, "detect-", 7)) { - mapname = var + 7; + name = var + 7; detect = 1; } else if (!strncasecmp(var, "generate-", 9)) { - mapname = var + 9; + name = var + 9; + } else { + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); + continue; } - index = zap_str2zap_tonemap(mapname); + index = zap_str2zap_tonemap(name); if (index >= ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { - zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", mapname); + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", name); } else { if (detect) { char *p = val, *next; @@ -299,9 +302,9 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) p = next + 1; } } while (next); - zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", mapname, val); + zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", name, val); } else { - zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", mapname, val); + zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", name, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); } x++; From c2149312b341f118f4d2f89cf8c2d14e8af4805b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:34:40 +0000 Subject: [PATCH 0386/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@193 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 7816c8d662..3877d5213d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -273,19 +273,22 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) if (!strcasecmp(cfg.category, mapname) && var && val) { uint32_t index; - char *mapname; + char *name = NULL; if (!strncasecmp(var, "detect-", 7)) { - mapname = var + 7; + name = var + 7; detect = 1; } else if (!strncasecmp(var, "generate-", 9)) { - mapname = var + 9; + name = var + 9; + } else { + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); + continue; } - index = zap_str2zap_tonemap(mapname); + index = zap_str2zap_tonemap(name); if (index >= ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { - zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", mapname); + zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", name); } else { if (detect) { char *p = val, *next; @@ -299,9 +302,9 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) p = next + 1; } } while (next); - zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", mapname, val); + zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", name, val); } else { - zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", mapname, val); + zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", name, val); zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); } x++; From a8938b9a297053fc7688ede507f7d48bdb61243e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:40:12 +0000 Subject: [PATCH 0387/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@194 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a2c974a599..2a0e13c37e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -605,7 +605,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_t **new_session, switch_memory_pool_t **pool) { - char *p, *dest; + char *p, *dest = NULL; int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -626,6 +626,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } + if (!dest) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -797,7 +802,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - zap_status_t status; + zap_status_t status = ZAP_SUCCESS; zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -877,6 +882,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_zap_signal) } break; } + + return ZAP_SUCCESS; } static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) From 5b82eb38158a9921398f9a9bc976bd2ca7d40474 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:40:12 +0000 Subject: [PATCH 0388/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@194 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a2c974a599..2a0e13c37e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -605,7 +605,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_t **new_session, switch_memory_pool_t **pool) { - char *p, *dest; + char *p, *dest = NULL; int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -626,6 +626,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } + if (!dest) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -797,7 +802,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - zap_status_t status; + zap_status_t status = ZAP_SUCCESS; zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -877,6 +882,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_zap_signal) } break; } + + return ZAP_SUCCESS; } static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) From 39bca4d93787fca57aeda5aacfdc90a345165bf3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:48:14 +0000 Subject: [PATCH 0389/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@195 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/tones.conf | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index d7825b767e..e24ccccfcd 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -1,6 +1,18 @@ [us] -; tone_name => : -dial => %(1000,0,350,440):350,440 -ring => %(2000,4000,440,480):440:480 -busy => %(500,500,480,620):480:620 -attn => %(100,100,1400,2060,2450,2600):1400,2060,2450,2600 +generate-dial => %(1000,0,350,440) +detect-dial => 350,440 + +generate-ring => %(2000,4000,440,480) +detect-ring => 440,480 + +generate-busy => %(500,500,480,620) +detect-busy => 480,620 + +generate-attn => %(100,100,1400,2060,2450,2600) +detect-attn => 1400,2060,2450,2600 + +detect-fail1 => 913.8 +detect-fail2 => 1370.6 +detect-fail3 => 776.7 + + From b7e62bf17a8196a5d647f329de280543ddcabd65 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:48:14 +0000 Subject: [PATCH 0390/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@195 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/tones.conf | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index d7825b767e..e24ccccfcd 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -1,6 +1,18 @@ [us] -; tone_name => : -dial => %(1000,0,350,440):350,440 -ring => %(2000,4000,440,480):440:480 -busy => %(500,500,480,620):480:620 -attn => %(100,100,1400,2060,2450,2600):1400,2060,2450,2600 +generate-dial => %(1000,0,350,440) +detect-dial => 350,440 + +generate-ring => %(2000,4000,440,480) +detect-ring => 440,480 + +generate-busy => %(500,500,480,620) +detect-busy => 480,620 + +generate-attn => %(100,100,1400,2060,2450,2600) +detect-attn => 1400,2060,2450,2600 + +detect-fail1 => 913.8 +detect-fail2 => 1370.6 +detect-fail3 => 776.7 + + From d4fcd8d9201c0b19c85c1cd0e698cae5a555f628 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:58:27 +0000 Subject: [PATCH 0391/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@196 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/zt.conf | 1 + libs/openzap/src/zap_wanpipe.c | 4 ++-- libs/openzap/src/zap_zt.c | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libs/openzap/conf/zt.conf b/libs/openzap/conf/zt.conf index ba609ac42e..ac60475b25 100644 --- a/libs/openzap/conf/zt.conf +++ b/libs/openzap/conf/zt.conf @@ -2,3 +2,4 @@ codec_ms => 20 wink_ms => 150 flash_ms => 750 +echo_cancel_level => 64 diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 191e010c41..de3da19d59 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -120,14 +120,14 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } } else if (!strcasecmp(var, "wink_ms")) { num = atoi(val); - if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + if (num < 50 || num > 3000) { zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno); } else { wp_globals.flash_ms = num; diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 9b02a35b0f..bafc191117 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -40,6 +40,7 @@ static struct { uint32_t codec_ms; uint32_t wink_ms; uint32_t flash_ms; + uint32_t eclevel; } zt_globals; #define ZT_INVALID_SOCKET -1 @@ -59,7 +60,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - len = 64; + len = zt_globals.eclevel; if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); @@ -193,18 +194,26 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) } } else if (!strcasecmp(var, "wink_ms")) { num = atoi(val); - if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + 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; + } + } } @@ -524,7 +533,8 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_globals.codec_ms = 20; zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; - + zt_globals.eclevel = 64; + zt_interface.name = "zt"; zt_interface.configure = zt_configure; zt_interface.configure_span = zt_configure_span; From fe7acb5ba6cb41487ba8781dbfbad4392558c243 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Jun 2007 15:58:27 +0000 Subject: [PATCH 0392/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@196 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/zt.conf | 1 + libs/freetdm/src/zap_wanpipe.c | 4 ++-- libs/freetdm/src/zap_zt.c | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/conf/zt.conf b/libs/freetdm/conf/zt.conf index ba609ac42e..ac60475b25 100644 --- a/libs/freetdm/conf/zt.conf +++ b/libs/freetdm/conf/zt.conf @@ -2,3 +2,4 @@ codec_ms => 20 wink_ms => 150 flash_ms => 750 +echo_cancel_level => 64 diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 191e010c41..de3da19d59 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -120,14 +120,14 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } } else if (!strcasecmp(var, "wink_ms")) { num = atoi(val); - if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + if (num < 50 || num > 3000) { zap_log(ZAP_LOG_WARNING, "invalid flash ms at line %d\n", lineno); } else { wp_globals.flash_ms = num; diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 9b02a35b0f..bafc191117 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -40,6 +40,7 @@ static struct { uint32_t codec_ms; uint32_t wink_ms; uint32_t flash_ms; + uint32_t eclevel; } zt_globals; #define ZT_INVALID_SOCKET -1 @@ -59,7 +60,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - len = 64; + len = zt_globals.eclevel; if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); @@ -193,18 +194,26 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) } } else if (!strcasecmp(var, "wink_ms")) { num = atoi(val); - if (num < 500 || num > 2000) { + 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 < 500 || num > 2000) { + 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; + } + } } @@ -524,7 +533,8 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_globals.codec_ms = 20; zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; - + zt_globals.eclevel = 64; + zt_interface.name = "zt"; zt_interface.configure = zt_configure; zt_interface.configure_span = zt_configure_span; From 09516082c61cc5783df2d5d93f7bc90068d6cc09 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 2 Jun 2007 17:27:10 +0000 Subject: [PATCH 0393/1766] Add fsk demodulation code from Robert Krten. Thanks for the contribution! git-svn-id: http://svn.openzap.org/svn/openzap/trunk@197 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 32 +++ libs/openzap/src/dsp/bell202.c | 322 +++++++++++++++++++++++++++++++ libs/openzap/src/dsp/bell202.h | 87 +++++++++ libs/openzap/src/dsp/readme.txt | 50 +++++ libs/openzap/src/dsp/uart.c | 137 +++++++++++++ libs/openzap/src/dsp/uart.h | 79 ++++++++ 6 files changed, 707 insertions(+) create mode 100644 libs/openzap/src/dsp/bell202.c create mode 100644 libs/openzap/src/dsp/bell202.h create mode 100644 libs/openzap/src/dsp/readme.txt create mode 100644 libs/openzap/src/dsp/uart.c create mode 100644 libs/openzap/src/dsp/uart.h diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 1a60eded45..60f41cdf40 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -461,6 +461,38 @@ + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/dsp/bell202.c b/libs/openzap/src/dsp/bell202.c new file mode 100644 index 0000000000..7401a7f219 --- /dev/null +++ b/libs/openzap/src/dsp/bell202.c @@ -0,0 +1,322 @@ + +/* + * bell202.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 Bell-202 1200-baud FSK decoder, suitable for + * use in a library. The general style of the library calls is modeled + * after the POSIX pthread_*() functions. + * + * 2005 03 20 R. Krten created +*/ + +#include +#include +#include +#ifndef _MSC_VER +#include +#endif +#include +#include + +#include "bell202.h" +#include "uart.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +// local constants +#define BELL202_MARK 1200 +#define BELL202_SPACE 2200 +#define BELL202_BAUD 1200 + +/* + * dsp_bell202_attr_init + * + * Initializes the attributes structure; this must be done before the + * attributes structure is used. +*/ + +void +dsp_bell202_attr_init (dsp_bell202_attr_t *attr) +{ + memset (attr, 0, sizeof (*attr)); +} + +/* + * dsp_bell202_attr_get_bithandler + * dsp_bell202_attr_set_bithandler + * dsp_bell202_attr_get_bytehandler + * dsp_bell202_attr_set_bytehandler + * dsp_bell202_attr_getsamplerate + * dsp_bell202_attr_setsamplerate + * + * 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. +*/ + +void (* +dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attr, void **bithandler_arg)) (void *, int) +{ + *bithandler_arg = attr -> bithandler_arg; + return (attr -> bithandler); +} + +void +dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attr, void (*bithandler) (void *, int ), void *bithandler_arg) +{ + attr -> bithandler = bithandler; + attr -> bithandler_arg = bithandler_arg; +} + +void (* +dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attr, void **bytehandler_arg)) (void *, int) +{ + *bytehandler_arg = attr -> bytehandler_arg; + return (attr -> bytehandler); +} + +void +dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attr, void (*bytehandler) (void *, int ), void *bytehandler_arg) +{ + attr -> bytehandler = bytehandler; + attr -> bytehandler_arg = bytehandler_arg; +} + +int +dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) +{ + return (attr -> sample_rate); +} + +int +dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) +{ + if (samplerate <= 0) { + return (-1); + } + attr -> sample_rate = samplerate; + return (0); +} + +/* + * dsp_bell202_create + * + * Creates a handle for subsequent use. The handle is created to contain + * a context data structure for use by the sample handler function. The + * function expects an initialized attributes structure, and returns the + * handle or a NULL if there were errors. + * + * Once created, the handle can be used until it is destroyed. +*/ + +dsp_bell202_handle_t * +dsp_bell202_create (dsp_bell202_attr_t *attr) +{ + int i; + double phi_mark, phi_space; + dsp_bell202_handle_t *handle; + + handle = malloc (sizeof (*handle)); + if (handle == NULL) { + return (handle); + } + + memset (handle, 0, sizeof (*handle)); + + // fill the attributes member + memcpy (&handle -> attr, attr, sizeof (*attr)); + + // see if we can do downsampling. We only really need 6 samples to "match" + if (attr -> sample_rate / BELL202_MARK > 6) { + handle -> downsampling_count = attr -> sample_rate / BELL202_MARK / 6; + } else { + handle -> downsampling_count = 1; + } + handle -> current_downsample = 1; + + // calculate the correlate size (number of samples required for slowest wave) + handle -> corrsize = attr -> sample_rate / handle -> downsampling_count / BELL202_MARK; + + // allocate the correlation sin/cos arrays and initialize + for (i = 0; i < 4; i++) { + handle -> correlates [i] = malloc (sizeof (double) * handle -> corrsize); + if (handle -> correlates [i] == NULL) { + break; + } + } + if (i != 4) { // some failed, back out memory allocations + dsp_bell202_destroy (handle); + return (NULL); + } + + // now initialize them + phi_mark = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_MARK); + phi_space = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_SPACE); + + // printf ("phi_mark is %g, phi_space is %g\n", phi_mark, phi_space); + for (i = 0; i < handle -> corrsize; i++) { + handle -> correlates [0][i] = sin (phi_mark * (double) i); + handle -> correlates [1][i] = cos (phi_mark * (double) i); + handle -> correlates [2][i] = sin (phi_space * (double) i); + handle -> correlates [3][i] = cos (phi_space * (double) i); + // printf ("[%2d] MS %10.4f MC %10.4f SS %10.4f SC %10.4f\n", i, handle -> correlates [0][i], handle -> correlates [1][i], handle -> correlates [2][i], handle -> correlates [3][i]); + } + + // initialize the ring buffer + handle -> buffer = malloc (sizeof (double) * handle -> corrsize); + if (handle -> buffer == NULL) { // failed; back out memory allocations + dsp_bell202_destroy (handle); + return (NULL); + } + memset (handle -> buffer, 0, sizeof (double) * handle -> corrsize); + handle -> ringstart = 0; + + // initalize intra-cell position + handle -> cellpos = 0; + handle -> celladj = BELL202_BAUD / (double) attr -> sample_rate * (double) handle -> downsampling_count; + + // printf ("corrsize %d celladj %g\n", handle -> corrsize, handle -> celladj); + + // if they have provided a byte handler, add a UART to the processing chain + if (handle -> attr.bytehandler) { + dsp_uart_attr_t uart_attr; + dsp_uart_handle_t *uart_handle; + + dsp_uart_attr_init (&uart_attr); + dsp_uart_attr_set_bytehandler (&uart_attr, handle -> attr.bytehandler, handle -> attr.bytehandler_arg); + uart_handle = dsp_uart_create (&uart_attr); + if (uart_handle == NULL) { + dsp_bell202_destroy (handle); + return (NULL); + } + handle -> attr.bithandler = dsp_uart_bit_handler; + handle -> attr.bithandler_arg = uart_handle; + } + + return (handle); +} + +/* + * dsp_bell202_destroy + * + * Destroys a handle, releasing any associated memory. A destroyed handle + * should not be used for anything. +*/ + +void +dsp_bell202_destroy (dsp_bell202_handle_t *handle) +{ + int i; + + // if empty handle, just return + if (handle == NULL) { + return; + } + + for (i = 0; i < 4; i++) { + if (handle -> correlates [i] != NULL) { + free (handle -> correlates [i]); + handle -> correlates [i] = NULL; + } + } + + if (handle -> buffer != NULL) { + free (handle -> buffer); + handle -> buffer = NULL; + } + + free (handle); +} + +/* + * dsp_bell202_sample + * + * This is the main processing entry point. The function accepts a normalized + * sample (i.e., one whose range is between -1 and +1). The function performs + * the Bell-202 FSK modem decode processing, and, if it detects a valid bit, + * will call the bithandler associated with the attributes structure. + * + * For the Bell-202 standard, a logical zero (space) is 2200 Hz, and a logical + * one (mark) is 1200 Hz. +*/ + +void +dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample) +{ + double val; + double factors [4]; + int i, j; + + // if we can avoid processing samples, do so + if (handle -> downsampling_count != 1) { + if (handle -> current_downsample < handle -> downsampling_count) { + handle -> current_downsample++; + return; // throw this sample out + } + handle -> current_downsample = 1; + } + + // store sample in buffer + handle -> buffer [handle -> ringstart++] = normalized_sample; + if (handle -> ringstart >= handle -> corrsize) { + handle -> ringstart = 0; + } + + // do the correlation calculation + factors [0] = factors [1] = factors [2] = factors [3] = 0; // clear out intermediate sums + j = handle -> ringstart; + for (i = 0; i < handle -> corrsize; i++) { + if (j >= handle -> corrsize) { + j = 0; + } + val = handle -> buffer [j]; + factors [0] += handle -> correlates [0][i] * val; + factors [1] += handle -> correlates [1][i] * val; + factors [2] += handle -> correlates [2][i] * val; + factors [3] += handle -> correlates [3][i] * val; + j++; + } + + // store the bit (bit value is comparison of the two sets of correlate factors) + handle -> previous_bit = handle -> current_bit; + handle -> current_bit = (factors [0] * factors [0] + factors [1] * factors [1] > factors [2] * factors [2] + factors [3] * factors [3]); + + // printf ("Sample %10.4f factors %10.4f %10.4f %10.4f %10.4f (sum %10.4f) previous %d current %d cellpos %10.4f\n", normalized_sample, factors [0], factors [1], factors [2], factors [3], factors [0] * factors [0] + factors [1] * factors [1] - factors [2] * factors [2] - factors [3] * factors [3], handle -> previous_bit, handle -> current_bit, handle -> cellpos); + // if there's a transition, we can synchronize the cell position + if (handle -> previous_bit != handle -> current_bit) { + handle -> cellpos = 0.5; // adjust cell position to be in the middle of the cell + } + handle -> cellpos += handle -> celladj; // walk the cell along + + if (handle -> cellpos > 1.0) { + handle -> cellpos -= 1.0; + (*handle -> attr.bithandler) (handle -> attr.bithandler_arg, handle -> current_bit); + } +} + diff --git a/libs/openzap/src/dsp/bell202.h b/libs/openzap/src/dsp/bell202.h new file mode 100644 index 0000000000..caf144aec2 --- /dev/null +++ b/libs/openzap/src/dsp/bell202.h @@ -0,0 +1,87 @@ + +/* + * bell202.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 Bell-202 1200 baud FSK modem. + * + * 2005 03 20 R. Krten created +*/ + +#ifndef __BELL202_H__ +#define __BELL202_H__ + +typedef struct dsp_bell202_attr_s +{ + int sample_rate; // sample rate in HZ + void (*bithandler) (void *, int); // bit handler + void *bithandler_arg; // arbitrary ID passed to bithandler as first argument + void (*bytehandler) (void *, int); // byte handler + void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument +} dsp_bell202_attr_t; + +typedef struct +{ + dsp_bell202_attr_t attr; // attributes structure + double *correlates [4]; // one for each of sin/cos for mark/space + int corrsize; // correlate size (also number of samples in ring buffer) + double *buffer; // sample ring buffer + int ringstart; // ring buffer start offset + double cellpos; // bit cell position + double celladj; // bit cell adjustment for each sample + int previous_bit; // previous bit (for detecting a transition to sync-up cell position) + int current_bit; // current bit + int downsampling_count; // number of samples to skip + int current_downsample; // current skip count +} dsp_bell202_handle_t; + +/* + * Function prototypes + * + * General calling order is: + * a) create the attributes structure (dsp_bell202_attr_init) + * b) initialize fields in the attributes structure (dsp_bell202_attr_set_*) + * c) create a Bell-202 handle (dsp_bell202_create) + * d) feed samples through the handler (dsp_bell202_sample) +*/ + +extern void dsp_bell202_attr_init (dsp_bell202_attr_t *attributes); + +extern void (*dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attributes, void **bithandler_arg)) (void *, int); +extern void dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); +extern void (*dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attributes, void **bytehandler_arg)) (void *, int); +extern void dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); +extern int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attributes); +extern int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attributes, int samplerate); + +extern dsp_bell202_handle_t * dsp_bell202_create (dsp_bell202_attr_t *attributes); +extern void dsp_bell202_destroy (dsp_bell202_handle_t *handle); + +extern void dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample); + +#endif // __BELL202_H__ + diff --git a/libs/openzap/src/dsp/readme.txt b/libs/openzap/src/dsp/readme.txt new file mode 100644 index 0000000000..6283a4345e --- /dev/null +++ b/libs/openzap/src/dsp/readme.txt @@ -0,0 +1,50 @@ +I have only tested the library with samples at 8kHz. It *should* work with arbitrary sample rates; the "optr" variable in the code samples below is the sampling rate in Hz. + +The first thing you need to do is initialize a context structure: + + dsp_bell202_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem + dsp_bell202_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem + + // initialize: + dsp_bell202_attr_init (&fsk1200_attr); // clear attributes structure + dsp_bell202_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate + dsp_bell202_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler + + // create context: + fsk1200_handle = dsp_bell202_create (&fsk1200_attr); + + // error check: + if (fsk1200_handle == NULL) { + fprintf (stderr, "%s: can't dsp_bell202_create, errno %d (%s)\n", progname, errno, strerror (errno)); + exit (EXIT_FAILURE); + } + +If you are decoding multiple channels, you will need multiple context structures; one per channel. +The attributes ("dsp_bell202_attr_t") do not have to be persistent, but the handle does. +There's even a "dsp_bell202_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. + +Then, you need to feed samples into the software modem: + dsp_bell202_sample (fsk1200_handle, (double) sample / 32767.); + +It assumes the samples are between -1 and 1 as a double. + +It will outcall to your provided "clid_byte_handler()" function, which needs to have a prototype as follows: + + void clid_byte_handler (void *x, int data); + +The "x" is a context "void *" that you can associate in the fsk1200_handle (great for multiple channels). + +This will dribble bytes out to you at 1200 baud. + +From there, you are on your own. Canadian caller ID streams are different format than US caller ID streams IIRC. Both are trivial to figure out, as they have lots of ASCII data. I can supply some more code later on the Canadian one if you need it. + +Here's a sample of a Canadian caller ID stream from when you called: + +00000000: 55 55 55 55 55 55 55 55-55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU +00000010: 55 55 D5 80 1D 01 08 30-36 30 31 31 36 31 36 08 UU.....06011616. +00000020: 01 4F 03 0B 31 32 34 38-35 35 35 31 32 31 32 06 .O..12485551212. +00000030: 01 4C D1 85 00 02 54 00-02 C5 60 28 10 0A 80 30 .L....T...`(...0 + +The "UUUUU" is an alternating series of ones and zeros (which, when combined with the start and stop bits, creates the 0x55 character "U") used to train analog modems. +06011616 is the date and time (JUN 01 16:16), the "O" at 0x21 is an "Out of area" +qualifier for why your name didn't appear, and "1248..." is your DN. The "L" at 0x31 is a long distance qualifier. diff --git a/libs/openzap/src/dsp/uart.c b/libs/openzap/src/dsp/uart.c new file mode 100644 index 0000000000..67050e8316 --- /dev/null +++ b/libs/openzap/src/dsp/uart.c @@ -0,0 +1,137 @@ + +/* + * 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 +#ifndef _MSC_VER +#include +#endif +#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. +*/ + +void (* +dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg)) (void *, int) +{ + *bytehandler_arg = attr -> bytehandler_arg; + return (attr -> bytehandler); +} + +void +dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attr, void (*bytehandler) (void *, int ), 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 == NULL) { + return (handle); + } + memset (handle, 0, sizeof (handle)); + + // fill the attributes member + memcpy (&handle -> attr, attr, sizeof (*attr)); + + return (handle); +} + +void +dsp_uart_bit_handler (void *x, int bit) +{ + dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x; + +// printf ("bit %d handle -> have_start %d handle -> data %02X handle -> nbits %d\n", bit, handle -> have_start, handle -> data, handle -> nbits); + 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... +#if 0 + } else if (handle -> nbits > 8) { + if (!bit) { + // framing error; expected stop bit (mark, 1) + printf ("FRAME"); fflush (stdout); + } else { + handle -> have_start = 0; + handle -> nbits = 0; + } +#endif + } +} + diff --git a/libs/openzap/src/dsp/uart.h b/libs/openzap/src/dsp/uart.h new file mode 100644 index 0000000000..7c3a9164b0 --- /dev/null +++ b/libs/openzap/src/dsp/uart.h @@ -0,0 +1,79 @@ + +/* + * 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 struct dsp_uart_attr_s +{ + void (*bytehandler) (void *, int); // 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 samples through the handler (dsp_uart_sample) +*/ + +extern void dsp_uart_attr_init (dsp_uart_attr_t *attributes); + +extern void (*dsp_uart_attr_get_bithandler (dsp_uart_attr_t *attributes, void **bithandler_arg)) (void *, int); +extern void dsp_uart_attr_set_bithandler (dsp_uart_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); +extern void (*dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg)) (void *, int); +extern void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); +extern int dsp_uart_attr_get_samplerate (dsp_uart_attr_t *attributes); +extern int dsp_uart_attr_set_samplerate (dsp_uart_attr_t *attributes, int samplerate); + +extern dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); +extern void dsp_uart_destroy (dsp_uart_handle_t *handle); + +extern void dsp_uart_sample (dsp_uart_handle_t *handle, double normalized_sample); + +extern void dsp_uart_bit_handler (void *handle, int bit); + +#endif // __UART_H__ + From cb9dff97a4773314ac72972118ad8bba5b24c183 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 2 Jun 2007 17:27:10 +0000 Subject: [PATCH 0394/1766] Add fsk demodulation code from Robert Krten. Thanks for the contribution! git-svn-id: http://svn.openzap.org/svn/openzap/trunk@197 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 32 +++ libs/freetdm/src/dsp/bell202.c | 322 +++++++++++++++++++++++++++++++ libs/freetdm/src/dsp/bell202.h | 87 +++++++++ libs/freetdm/src/dsp/readme.txt | 50 +++++ libs/freetdm/src/dsp/uart.c | 137 +++++++++++++ libs/freetdm/src/dsp/uart.h | 79 ++++++++ 6 files changed, 707 insertions(+) create mode 100644 libs/freetdm/src/dsp/bell202.c create mode 100644 libs/freetdm/src/dsp/bell202.h create mode 100644 libs/freetdm/src/dsp/readme.txt create mode 100644 libs/freetdm/src/dsp/uart.c create mode 100644 libs/freetdm/src/dsp/uart.h diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 1a60eded45..60f41cdf40 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -461,6 +461,38 @@ + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/dsp/bell202.c b/libs/freetdm/src/dsp/bell202.c new file mode 100644 index 0000000000..7401a7f219 --- /dev/null +++ b/libs/freetdm/src/dsp/bell202.c @@ -0,0 +1,322 @@ + +/* + * bell202.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 Bell-202 1200-baud FSK decoder, suitable for + * use in a library. The general style of the library calls is modeled + * after the POSIX pthread_*() functions. + * + * 2005 03 20 R. Krten created +*/ + +#include +#include +#include +#ifndef _MSC_VER +#include +#endif +#include +#include + +#include "bell202.h" +#include "uart.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +// local constants +#define BELL202_MARK 1200 +#define BELL202_SPACE 2200 +#define BELL202_BAUD 1200 + +/* + * dsp_bell202_attr_init + * + * Initializes the attributes structure; this must be done before the + * attributes structure is used. +*/ + +void +dsp_bell202_attr_init (dsp_bell202_attr_t *attr) +{ + memset (attr, 0, sizeof (*attr)); +} + +/* + * dsp_bell202_attr_get_bithandler + * dsp_bell202_attr_set_bithandler + * dsp_bell202_attr_get_bytehandler + * dsp_bell202_attr_set_bytehandler + * dsp_bell202_attr_getsamplerate + * dsp_bell202_attr_setsamplerate + * + * 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. +*/ + +void (* +dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attr, void **bithandler_arg)) (void *, int) +{ + *bithandler_arg = attr -> bithandler_arg; + return (attr -> bithandler); +} + +void +dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attr, void (*bithandler) (void *, int ), void *bithandler_arg) +{ + attr -> bithandler = bithandler; + attr -> bithandler_arg = bithandler_arg; +} + +void (* +dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attr, void **bytehandler_arg)) (void *, int) +{ + *bytehandler_arg = attr -> bytehandler_arg; + return (attr -> bytehandler); +} + +void +dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attr, void (*bytehandler) (void *, int ), void *bytehandler_arg) +{ + attr -> bytehandler = bytehandler; + attr -> bytehandler_arg = bytehandler_arg; +} + +int +dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) +{ + return (attr -> sample_rate); +} + +int +dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) +{ + if (samplerate <= 0) { + return (-1); + } + attr -> sample_rate = samplerate; + return (0); +} + +/* + * dsp_bell202_create + * + * Creates a handle for subsequent use. The handle is created to contain + * a context data structure for use by the sample handler function. The + * function expects an initialized attributes structure, and returns the + * handle or a NULL if there were errors. + * + * Once created, the handle can be used until it is destroyed. +*/ + +dsp_bell202_handle_t * +dsp_bell202_create (dsp_bell202_attr_t *attr) +{ + int i; + double phi_mark, phi_space; + dsp_bell202_handle_t *handle; + + handle = malloc (sizeof (*handle)); + if (handle == NULL) { + return (handle); + } + + memset (handle, 0, sizeof (*handle)); + + // fill the attributes member + memcpy (&handle -> attr, attr, sizeof (*attr)); + + // see if we can do downsampling. We only really need 6 samples to "match" + if (attr -> sample_rate / BELL202_MARK > 6) { + handle -> downsampling_count = attr -> sample_rate / BELL202_MARK / 6; + } else { + handle -> downsampling_count = 1; + } + handle -> current_downsample = 1; + + // calculate the correlate size (number of samples required for slowest wave) + handle -> corrsize = attr -> sample_rate / handle -> downsampling_count / BELL202_MARK; + + // allocate the correlation sin/cos arrays and initialize + for (i = 0; i < 4; i++) { + handle -> correlates [i] = malloc (sizeof (double) * handle -> corrsize); + if (handle -> correlates [i] == NULL) { + break; + } + } + if (i != 4) { // some failed, back out memory allocations + dsp_bell202_destroy (handle); + return (NULL); + } + + // now initialize them + phi_mark = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_MARK); + phi_space = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_SPACE); + + // printf ("phi_mark is %g, phi_space is %g\n", phi_mark, phi_space); + for (i = 0; i < handle -> corrsize; i++) { + handle -> correlates [0][i] = sin (phi_mark * (double) i); + handle -> correlates [1][i] = cos (phi_mark * (double) i); + handle -> correlates [2][i] = sin (phi_space * (double) i); + handle -> correlates [3][i] = cos (phi_space * (double) i); + // printf ("[%2d] MS %10.4f MC %10.4f SS %10.4f SC %10.4f\n", i, handle -> correlates [0][i], handle -> correlates [1][i], handle -> correlates [2][i], handle -> correlates [3][i]); + } + + // initialize the ring buffer + handle -> buffer = malloc (sizeof (double) * handle -> corrsize); + if (handle -> buffer == NULL) { // failed; back out memory allocations + dsp_bell202_destroy (handle); + return (NULL); + } + memset (handle -> buffer, 0, sizeof (double) * handle -> corrsize); + handle -> ringstart = 0; + + // initalize intra-cell position + handle -> cellpos = 0; + handle -> celladj = BELL202_BAUD / (double) attr -> sample_rate * (double) handle -> downsampling_count; + + // printf ("corrsize %d celladj %g\n", handle -> corrsize, handle -> celladj); + + // if they have provided a byte handler, add a UART to the processing chain + if (handle -> attr.bytehandler) { + dsp_uart_attr_t uart_attr; + dsp_uart_handle_t *uart_handle; + + dsp_uart_attr_init (&uart_attr); + dsp_uart_attr_set_bytehandler (&uart_attr, handle -> attr.bytehandler, handle -> attr.bytehandler_arg); + uart_handle = dsp_uart_create (&uart_attr); + if (uart_handle == NULL) { + dsp_bell202_destroy (handle); + return (NULL); + } + handle -> attr.bithandler = dsp_uart_bit_handler; + handle -> attr.bithandler_arg = uart_handle; + } + + return (handle); +} + +/* + * dsp_bell202_destroy + * + * Destroys a handle, releasing any associated memory. A destroyed handle + * should not be used for anything. +*/ + +void +dsp_bell202_destroy (dsp_bell202_handle_t *handle) +{ + int i; + + // if empty handle, just return + if (handle == NULL) { + return; + } + + for (i = 0; i < 4; i++) { + if (handle -> correlates [i] != NULL) { + free (handle -> correlates [i]); + handle -> correlates [i] = NULL; + } + } + + if (handle -> buffer != NULL) { + free (handle -> buffer); + handle -> buffer = NULL; + } + + free (handle); +} + +/* + * dsp_bell202_sample + * + * This is the main processing entry point. The function accepts a normalized + * sample (i.e., one whose range is between -1 and +1). The function performs + * the Bell-202 FSK modem decode processing, and, if it detects a valid bit, + * will call the bithandler associated with the attributes structure. + * + * For the Bell-202 standard, a logical zero (space) is 2200 Hz, and a logical + * one (mark) is 1200 Hz. +*/ + +void +dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample) +{ + double val; + double factors [4]; + int i, j; + + // if we can avoid processing samples, do so + if (handle -> downsampling_count != 1) { + if (handle -> current_downsample < handle -> downsampling_count) { + handle -> current_downsample++; + return; // throw this sample out + } + handle -> current_downsample = 1; + } + + // store sample in buffer + handle -> buffer [handle -> ringstart++] = normalized_sample; + if (handle -> ringstart >= handle -> corrsize) { + handle -> ringstart = 0; + } + + // do the correlation calculation + factors [0] = factors [1] = factors [2] = factors [3] = 0; // clear out intermediate sums + j = handle -> ringstart; + for (i = 0; i < handle -> corrsize; i++) { + if (j >= handle -> corrsize) { + j = 0; + } + val = handle -> buffer [j]; + factors [0] += handle -> correlates [0][i] * val; + factors [1] += handle -> correlates [1][i] * val; + factors [2] += handle -> correlates [2][i] * val; + factors [3] += handle -> correlates [3][i] * val; + j++; + } + + // store the bit (bit value is comparison of the two sets of correlate factors) + handle -> previous_bit = handle -> current_bit; + handle -> current_bit = (factors [0] * factors [0] + factors [1] * factors [1] > factors [2] * factors [2] + factors [3] * factors [3]); + + // printf ("Sample %10.4f factors %10.4f %10.4f %10.4f %10.4f (sum %10.4f) previous %d current %d cellpos %10.4f\n", normalized_sample, factors [0], factors [1], factors [2], factors [3], factors [0] * factors [0] + factors [1] * factors [1] - factors [2] * factors [2] - factors [3] * factors [3], handle -> previous_bit, handle -> current_bit, handle -> cellpos); + // if there's a transition, we can synchronize the cell position + if (handle -> previous_bit != handle -> current_bit) { + handle -> cellpos = 0.5; // adjust cell position to be in the middle of the cell + } + handle -> cellpos += handle -> celladj; // walk the cell along + + if (handle -> cellpos > 1.0) { + handle -> cellpos -= 1.0; + (*handle -> attr.bithandler) (handle -> attr.bithandler_arg, handle -> current_bit); + } +} + diff --git a/libs/freetdm/src/dsp/bell202.h b/libs/freetdm/src/dsp/bell202.h new file mode 100644 index 0000000000..caf144aec2 --- /dev/null +++ b/libs/freetdm/src/dsp/bell202.h @@ -0,0 +1,87 @@ + +/* + * bell202.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 Bell-202 1200 baud FSK modem. + * + * 2005 03 20 R. Krten created +*/ + +#ifndef __BELL202_H__ +#define __BELL202_H__ + +typedef struct dsp_bell202_attr_s +{ + int sample_rate; // sample rate in HZ + void (*bithandler) (void *, int); // bit handler + void *bithandler_arg; // arbitrary ID passed to bithandler as first argument + void (*bytehandler) (void *, int); // byte handler + void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument +} dsp_bell202_attr_t; + +typedef struct +{ + dsp_bell202_attr_t attr; // attributes structure + double *correlates [4]; // one for each of sin/cos for mark/space + int corrsize; // correlate size (also number of samples in ring buffer) + double *buffer; // sample ring buffer + int ringstart; // ring buffer start offset + double cellpos; // bit cell position + double celladj; // bit cell adjustment for each sample + int previous_bit; // previous bit (for detecting a transition to sync-up cell position) + int current_bit; // current bit + int downsampling_count; // number of samples to skip + int current_downsample; // current skip count +} dsp_bell202_handle_t; + +/* + * Function prototypes + * + * General calling order is: + * a) create the attributes structure (dsp_bell202_attr_init) + * b) initialize fields in the attributes structure (dsp_bell202_attr_set_*) + * c) create a Bell-202 handle (dsp_bell202_create) + * d) feed samples through the handler (dsp_bell202_sample) +*/ + +extern void dsp_bell202_attr_init (dsp_bell202_attr_t *attributes); + +extern void (*dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attributes, void **bithandler_arg)) (void *, int); +extern void dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); +extern void (*dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attributes, void **bytehandler_arg)) (void *, int); +extern void dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); +extern int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attributes); +extern int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attributes, int samplerate); + +extern dsp_bell202_handle_t * dsp_bell202_create (dsp_bell202_attr_t *attributes); +extern void dsp_bell202_destroy (dsp_bell202_handle_t *handle); + +extern void dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample); + +#endif // __BELL202_H__ + diff --git a/libs/freetdm/src/dsp/readme.txt b/libs/freetdm/src/dsp/readme.txt new file mode 100644 index 0000000000..6283a4345e --- /dev/null +++ b/libs/freetdm/src/dsp/readme.txt @@ -0,0 +1,50 @@ +I have only tested the library with samples at 8kHz. It *should* work with arbitrary sample rates; the "optr" variable in the code samples below is the sampling rate in Hz. + +The first thing you need to do is initialize a context structure: + + dsp_bell202_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem + dsp_bell202_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem + + // initialize: + dsp_bell202_attr_init (&fsk1200_attr); // clear attributes structure + dsp_bell202_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate + dsp_bell202_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler + + // create context: + fsk1200_handle = dsp_bell202_create (&fsk1200_attr); + + // error check: + if (fsk1200_handle == NULL) { + fprintf (stderr, "%s: can't dsp_bell202_create, errno %d (%s)\n", progname, errno, strerror (errno)); + exit (EXIT_FAILURE); + } + +If you are decoding multiple channels, you will need multiple context structures; one per channel. +The attributes ("dsp_bell202_attr_t") do not have to be persistent, but the handle does. +There's even a "dsp_bell202_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. + +Then, you need to feed samples into the software modem: + dsp_bell202_sample (fsk1200_handle, (double) sample / 32767.); + +It assumes the samples are between -1 and 1 as a double. + +It will outcall to your provided "clid_byte_handler()" function, which needs to have a prototype as follows: + + void clid_byte_handler (void *x, int data); + +The "x" is a context "void *" that you can associate in the fsk1200_handle (great for multiple channels). + +This will dribble bytes out to you at 1200 baud. + +From there, you are on your own. Canadian caller ID streams are different format than US caller ID streams IIRC. Both are trivial to figure out, as they have lots of ASCII data. I can supply some more code later on the Canadian one if you need it. + +Here's a sample of a Canadian caller ID stream from when you called: + +00000000: 55 55 55 55 55 55 55 55-55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU +00000010: 55 55 D5 80 1D 01 08 30-36 30 31 31 36 31 36 08 UU.....06011616. +00000020: 01 4F 03 0B 31 32 34 38-35 35 35 31 32 31 32 06 .O..12485551212. +00000030: 01 4C D1 85 00 02 54 00-02 C5 60 28 10 0A 80 30 .L....T...`(...0 + +The "UUUUU" is an alternating series of ones and zeros (which, when combined with the start and stop bits, creates the 0x55 character "U") used to train analog modems. +06011616 is the date and time (JUN 01 16:16), the "O" at 0x21 is an "Out of area" +qualifier for why your name didn't appear, and "1248..." is your DN. The "L" at 0x31 is a long distance qualifier. diff --git a/libs/freetdm/src/dsp/uart.c b/libs/freetdm/src/dsp/uart.c new file mode 100644 index 0000000000..67050e8316 --- /dev/null +++ b/libs/freetdm/src/dsp/uart.c @@ -0,0 +1,137 @@ + +/* + * 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 +#ifndef _MSC_VER +#include +#endif +#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. +*/ + +void (* +dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg)) (void *, int) +{ + *bytehandler_arg = attr -> bytehandler_arg; + return (attr -> bytehandler); +} + +void +dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attr, void (*bytehandler) (void *, int ), 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 == NULL) { + return (handle); + } + memset (handle, 0, sizeof (handle)); + + // fill the attributes member + memcpy (&handle -> attr, attr, sizeof (*attr)); + + return (handle); +} + +void +dsp_uart_bit_handler (void *x, int bit) +{ + dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x; + +// printf ("bit %d handle -> have_start %d handle -> data %02X handle -> nbits %d\n", bit, handle -> have_start, handle -> data, handle -> nbits); + 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... +#if 0 + } else if (handle -> nbits > 8) { + if (!bit) { + // framing error; expected stop bit (mark, 1) + printf ("FRAME"); fflush (stdout); + } else { + handle -> have_start = 0; + handle -> nbits = 0; + } +#endif + } +} + diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h new file mode 100644 index 0000000000..7c3a9164b0 --- /dev/null +++ b/libs/freetdm/src/dsp/uart.h @@ -0,0 +1,79 @@ + +/* + * 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 struct dsp_uart_attr_s +{ + void (*bytehandler) (void *, int); // 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 samples through the handler (dsp_uart_sample) +*/ + +extern void dsp_uart_attr_init (dsp_uart_attr_t *attributes); + +extern void (*dsp_uart_attr_get_bithandler (dsp_uart_attr_t *attributes, void **bithandler_arg)) (void *, int); +extern void dsp_uart_attr_set_bithandler (dsp_uart_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); +extern void (*dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg)) (void *, int); +extern void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); +extern int dsp_uart_attr_get_samplerate (dsp_uart_attr_t *attributes); +extern int dsp_uart_attr_set_samplerate (dsp_uart_attr_t *attributes, int samplerate); + +extern dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); +extern void dsp_uart_destroy (dsp_uart_handle_t *handle); + +extern void dsp_uart_sample (dsp_uart_handle_t *handle, double normalized_sample); + +extern void dsp_uart_bit_handler (void *handle, int bit); + +#endif // __UART_H__ + From f7422f881b12f85a63544df5027201ed8f86f89d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 3 Jun 2007 01:44:27 +0000 Subject: [PATCH 0395/1766] remove unecessary inlcudes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@198 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/bell202.c | 3 --- libs/openzap/src/dsp/uart.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/libs/openzap/src/dsp/bell202.c b/libs/openzap/src/dsp/bell202.c index 7401a7f219..7f8faf536d 100644 --- a/libs/openzap/src/dsp/bell202.c +++ b/libs/openzap/src/dsp/bell202.c @@ -36,9 +36,6 @@ #include #include #include -#ifndef _MSC_VER -#include -#endif #include #include diff --git a/libs/openzap/src/dsp/uart.c b/libs/openzap/src/dsp/uart.c index 67050e8316..cbd81b2236 100644 --- a/libs/openzap/src/dsp/uart.c +++ b/libs/openzap/src/dsp/uart.c @@ -35,9 +35,6 @@ #include #include #include -#ifndef _MSC_VER -#include -#endif #include #include "uart.h" From c07438a6f52d765dcf8e938f5b72f7d38fb57fb8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 3 Jun 2007 01:44:27 +0000 Subject: [PATCH 0396/1766] remove unecessary inlcudes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@198 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/bell202.c | 3 --- libs/freetdm/src/dsp/uart.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/libs/freetdm/src/dsp/bell202.c b/libs/freetdm/src/dsp/bell202.c index 7401a7f219..7f8faf536d 100644 --- a/libs/freetdm/src/dsp/bell202.c +++ b/libs/freetdm/src/dsp/bell202.c @@ -36,9 +36,6 @@ #include #include #include -#ifndef _MSC_VER -#include -#endif #include #include diff --git a/libs/freetdm/src/dsp/uart.c b/libs/freetdm/src/dsp/uart.c index 67050e8316..cbd81b2236 100644 --- a/libs/freetdm/src/dsp/uart.c +++ b/libs/freetdm/src/dsp/uart.c @@ -35,9 +35,6 @@ #include #include #include -#ifndef _MSC_VER -#include -#endif #include #include "uart.h" From 98cdabe0c16080fc47282062b823a42761501b20 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 01:45:23 +0000 Subject: [PATCH 0397/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@199 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/bell202.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/dsp/bell202.c b/libs/openzap/src/dsp/bell202.c index 7f8faf536d..1213c2dcf5 100644 --- a/libs/openzap/src/dsp/bell202.c +++ b/libs/openzap/src/dsp/bell202.c @@ -42,9 +42,9 @@ #include "bell202.h" #include "uart.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif // local constants #define BELL202_MARK 1200 From 03de9509d6a78e6d526df04701afb25641016a9c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 01:45:23 +0000 Subject: [PATCH 0398/1766] dos2unix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@199 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/bell202.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/dsp/bell202.c b/libs/freetdm/src/dsp/bell202.c index 7f8faf536d..1213c2dcf5 100644 --- a/libs/freetdm/src/dsp/bell202.c +++ b/libs/freetdm/src/dsp/bell202.c @@ -42,9 +42,9 @@ #include "bell202.h" #include "uart.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif // local constants #define BELL202_MARK 1200 From 34d002aaa4ea7c5e627e500d8edd963433676d65 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 02:56:56 +0000 Subject: [PATCH 0399/1766] Remove unused prototypes. Add function pointer typedef. Switch to use /* */ comments to survive pickier compile flags. Add dsp_uart_destroy function (takes ** pointer so it can set the pointer back to NULL) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@200 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/uart.c | 33 ++++++++++++++++++--------------- libs/openzap/src/dsp/uart.h | 32 ++++++++++++++------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/libs/openzap/src/dsp/uart.c b/libs/openzap/src/dsp/uart.c index cbd81b2236..c6e2105fcc 100644 --- a/libs/openzap/src/dsp/uart.c +++ b/libs/openzap/src/dsp/uart.c @@ -46,8 +46,7 @@ * attributes structure is used. */ -void -dsp_uart_attr_init (dsp_uart_attr_t *attr) +void dsp_uart_attr_init (dsp_uart_attr_t *attr) { memset (attr, 0, sizeof (*attr)); } @@ -61,22 +60,19 @@ dsp_uart_attr_init (dsp_uart_attr_t *attr) * zero == ok, -1 == fail. */ -void (* -dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg)) (void *, int) +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, void (*bytehandler) (void *, int ), void *bytehandler_arg) +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 *dsp_uart_create (dsp_uart_attr_t *attr) { dsp_uart_handle_t *handle; @@ -86,21 +82,28 @@ dsp_uart_create (dsp_uart_attr_t *attr) } memset (handle, 0, sizeof (handle)); - // fill the attributes member + /* fill the attributes member */ memcpy (&handle -> attr, attr, sizeof (*attr)); return (handle); } -void -dsp_uart_bit_handler (void *x, int bit) +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; -// printf ("bit %d handle -> have_start %d handle -> data %02X handle -> nbits %d\n", bit, handle -> have_start, handle -> data, handle -> nbits); if (!handle -> have_start) { if (bit) { - return; // waiting for start bit (0) + return; /* waiting for start bit (0) */ } handle -> have_start = 1; handle -> data = 0; @@ -118,11 +121,11 @@ dsp_uart_bit_handler (void *x, int bit) handle -> data = 0; handle -> have_start = 0; -// might consider handling errors in the future... +/* might consider handling errors in the future... */ #if 0 } else if (handle -> nbits > 8) { if (!bit) { - // framing error; expected stop bit (mark, 1) + /* framing error; expected stop bit (mark, 1) */ printf ("FRAME"); fflush (stdout); } else { handle -> have_start = 0; diff --git a/libs/openzap/src/dsp/uart.h b/libs/openzap/src/dsp/uart.h index 7c3a9164b0..9989ab935d 100644 --- a/libs/openzap/src/dsp/uart.h +++ b/libs/openzap/src/dsp/uart.h @@ -35,18 +35,20 @@ #ifndef __UART_H__ #define __UART_H__ +typedef void (*bytehandler_func_t) (void *, int); + typedef struct dsp_uart_attr_s { - void (*bytehandler) (void *, int); // byte handler - void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument + 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 + 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; /* @@ -56,24 +58,18 @@ typedef struct * 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 samples through the handler (dsp_uart_sample) + * d) feed bits through dsp_uart_bit_handler */ -extern void dsp_uart_attr_init (dsp_uart_attr_t *attributes); +void dsp_uart_attr_init (dsp_uart_attr_t *attributes); -extern void (*dsp_uart_attr_get_bithandler (dsp_uart_attr_t *attributes, void **bithandler_arg)) (void *, int); -extern void dsp_uart_attr_set_bithandler (dsp_uart_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); -extern void (*dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg)) (void *, int); -extern void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); -extern int dsp_uart_attr_get_samplerate (dsp_uart_attr_t *attributes); -extern int dsp_uart_attr_set_samplerate (dsp_uart_attr_t *attributes, int samplerate); +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); -extern dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); -extern void dsp_uart_destroy (dsp_uart_handle_t *handle); +dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); +void dsp_uart_destroy (dsp_uart_handle_t **handle); -extern void dsp_uart_sample (dsp_uart_handle_t *handle, double normalized_sample); - -extern void dsp_uart_bit_handler (void *handle, int bit); +void dsp_uart_bit_handler (void *handle, int bit); #endif // __UART_H__ From ff448df407a5a7ede27caf6e9b7ff803dbd149ee Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 02:56:56 +0000 Subject: [PATCH 0400/1766] Remove unused prototypes. Add function pointer typedef. Switch to use /* */ comments to survive pickier compile flags. Add dsp_uart_destroy function (takes ** pointer so it can set the pointer back to NULL) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@200 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/uart.c | 33 ++++++++++++++++++--------------- libs/freetdm/src/dsp/uart.h | 32 ++++++++++++++------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/dsp/uart.c b/libs/freetdm/src/dsp/uart.c index cbd81b2236..c6e2105fcc 100644 --- a/libs/freetdm/src/dsp/uart.c +++ b/libs/freetdm/src/dsp/uart.c @@ -46,8 +46,7 @@ * attributes structure is used. */ -void -dsp_uart_attr_init (dsp_uart_attr_t *attr) +void dsp_uart_attr_init (dsp_uart_attr_t *attr) { memset (attr, 0, sizeof (*attr)); } @@ -61,22 +60,19 @@ dsp_uart_attr_init (dsp_uart_attr_t *attr) * zero == ok, -1 == fail. */ -void (* -dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg)) (void *, int) +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, void (*bytehandler) (void *, int ), void *bytehandler_arg) +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 *dsp_uart_create (dsp_uart_attr_t *attr) { dsp_uart_handle_t *handle; @@ -86,21 +82,28 @@ dsp_uart_create (dsp_uart_attr_t *attr) } memset (handle, 0, sizeof (handle)); - // fill the attributes member + /* fill the attributes member */ memcpy (&handle -> attr, attr, sizeof (*attr)); return (handle); } -void -dsp_uart_bit_handler (void *x, int bit) +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; -// printf ("bit %d handle -> have_start %d handle -> data %02X handle -> nbits %d\n", bit, handle -> have_start, handle -> data, handle -> nbits); if (!handle -> have_start) { if (bit) { - return; // waiting for start bit (0) + return; /* waiting for start bit (0) */ } handle -> have_start = 1; handle -> data = 0; @@ -118,11 +121,11 @@ dsp_uart_bit_handler (void *x, int bit) handle -> data = 0; handle -> have_start = 0; -// might consider handling errors in the future... +/* might consider handling errors in the future... */ #if 0 } else if (handle -> nbits > 8) { if (!bit) { - // framing error; expected stop bit (mark, 1) + /* framing error; expected stop bit (mark, 1) */ printf ("FRAME"); fflush (stdout); } else { handle -> have_start = 0; diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h index 7c3a9164b0..9989ab935d 100644 --- a/libs/freetdm/src/dsp/uart.h +++ b/libs/freetdm/src/dsp/uart.h @@ -35,18 +35,20 @@ #ifndef __UART_H__ #define __UART_H__ +typedef void (*bytehandler_func_t) (void *, int); + typedef struct dsp_uart_attr_s { - void (*bytehandler) (void *, int); // byte handler - void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument + 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 + 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; /* @@ -56,24 +58,18 @@ typedef struct * 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 samples through the handler (dsp_uart_sample) + * d) feed bits through dsp_uart_bit_handler */ -extern void dsp_uart_attr_init (dsp_uart_attr_t *attributes); +void dsp_uart_attr_init (dsp_uart_attr_t *attributes); -extern void (*dsp_uart_attr_get_bithandler (dsp_uart_attr_t *attributes, void **bithandler_arg)) (void *, int); -extern void dsp_uart_attr_set_bithandler (dsp_uart_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); -extern void (*dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg)) (void *, int); -extern void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); -extern int dsp_uart_attr_get_samplerate (dsp_uart_attr_t *attributes); -extern int dsp_uart_attr_set_samplerate (dsp_uart_attr_t *attributes, int samplerate); +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); -extern dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); -extern void dsp_uart_destroy (dsp_uart_handle_t *handle); +dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); +void dsp_uart_destroy (dsp_uart_handle_t **handle); -extern void dsp_uart_sample (dsp_uart_handle_t *handle, double normalized_sample); - -extern void dsp_uart_bit_handler (void *handle, int bit); +void dsp_uart_bit_handler (void *handle, int bit); #endif // __UART_H__ From 2a79a09b8f7a1a169a32ec4d7bfd57abe1657543 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 03:07:08 +0000 Subject: [PATCH 0401/1766] make code style consistent with the rest of the lib. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@201 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/uart.c | 73 +++++++++++++++---------------------- libs/openzap/src/dsp/uart.h | 12 +++--- 2 files changed, 36 insertions(+), 49 deletions(-) diff --git a/libs/openzap/src/dsp/uart.c b/libs/openzap/src/dsp/uart.c index c6e2105fcc..05a80753ec 100644 --- a/libs/openzap/src/dsp/uart.c +++ b/libs/openzap/src/dsp/uart.c @@ -60,35 +60,33 @@ void dsp_uart_attr_init (dsp_uart_attr_t *attr) * zero == ok, -1 == fail. */ -bytehandler_func_t dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg) +bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attr, void **bytehandler_arg) { - *bytehandler_arg = attr -> bytehandler_arg; - return (attr -> bytehandler); + *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) +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; + attr->bytehandler = bytehandler; + attr->bytehandler_arg = bytehandler_arg; } -dsp_uart_handle_t *dsp_uart_create (dsp_uart_attr_t *attr) +dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) { - dsp_uart_handle_t *handle; + dsp_uart_handle_t *handle; - handle = malloc (sizeof (*handle)); - if (handle == NULL) { - return (handle); + handle = malloc(sizeof (*handle)); + if (handle) { + memset(handle, 0, sizeof (handle)); + + /* fill the attributes member */ + memcpy(&handle->attr, attr, sizeof (*attr)); } - memset (handle, 0, sizeof (handle)); - - /* fill the attributes member */ - memcpy (&handle -> attr, attr, sizeof (*attr)); - - return (handle); + return handle; } -void dsp_uart_destroy (dsp_uart_handle_t **handle) +void dsp_uart_destroy(dsp_uart_handle_t **handle) { if (*handle) { free(*handle); @@ -97,41 +95,30 @@ void dsp_uart_destroy (dsp_uart_handle_t **handle) } -void dsp_uart_bit_handler (void *x, int bit) +void dsp_uart_bit_handler(void *x, int bit) { dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x; - if (!handle -> have_start) { + if (!handle->have_start) { if (bit) { return; /* waiting for start bit (0) */ } - handle -> have_start = 1; - handle -> data = 0; - handle -> nbits = 0; + handle->have_start = 1; + handle->data = 0; + handle->nbits = 0; return; } - handle -> data >>= 1; - handle -> data |= 0x80 * !!bit; + 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... */ -#if 0 - } else if (handle -> nbits > 8) { - if (!bit) { - /* framing error; expected stop bit (mark, 1) */ - printf ("FRAME"); fflush (stdout); - } else { - handle -> have_start = 0; - handle -> nbits = 0; - } -#endif + 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/dsp/uart.h b/libs/openzap/src/dsp/uart.h index 9989ab935d..91b2bd0880 100644 --- a/libs/openzap/src/dsp/uart.h +++ b/libs/openzap/src/dsp/uart.h @@ -61,15 +61,15 @@ typedef struct * d) feed bits through dsp_uart_bit_handler */ -void dsp_uart_attr_init (dsp_uart_attr_t *attributes); +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); +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); +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); +void dsp_uart_bit_handler(void *handle, int bit); #endif // __UART_H__ From 5eed6650f8cd31b25fa7f417df272c194082be0b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 03:07:08 +0000 Subject: [PATCH 0402/1766] make code style consistent with the rest of the lib. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@201 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/uart.c | 73 +++++++++++++++---------------------- libs/freetdm/src/dsp/uart.h | 12 +++--- 2 files changed, 36 insertions(+), 49 deletions(-) diff --git a/libs/freetdm/src/dsp/uart.c b/libs/freetdm/src/dsp/uart.c index c6e2105fcc..05a80753ec 100644 --- a/libs/freetdm/src/dsp/uart.c +++ b/libs/freetdm/src/dsp/uart.c @@ -60,35 +60,33 @@ void dsp_uart_attr_init (dsp_uart_attr_t *attr) * zero == ok, -1 == fail. */ -bytehandler_func_t dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg) +bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attr, void **bytehandler_arg) { - *bytehandler_arg = attr -> bytehandler_arg; - return (attr -> bytehandler); + *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) +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; + attr->bytehandler = bytehandler; + attr->bytehandler_arg = bytehandler_arg; } -dsp_uart_handle_t *dsp_uart_create (dsp_uart_attr_t *attr) +dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) { - dsp_uart_handle_t *handle; + dsp_uart_handle_t *handle; - handle = malloc (sizeof (*handle)); - if (handle == NULL) { - return (handle); + handle = malloc(sizeof (*handle)); + if (handle) { + memset(handle, 0, sizeof (handle)); + + /* fill the attributes member */ + memcpy(&handle->attr, attr, sizeof (*attr)); } - memset (handle, 0, sizeof (handle)); - - /* fill the attributes member */ - memcpy (&handle -> attr, attr, sizeof (*attr)); - - return (handle); + return handle; } -void dsp_uart_destroy (dsp_uart_handle_t **handle) +void dsp_uart_destroy(dsp_uart_handle_t **handle) { if (*handle) { free(*handle); @@ -97,41 +95,30 @@ void dsp_uart_destroy (dsp_uart_handle_t **handle) } -void dsp_uart_bit_handler (void *x, int bit) +void dsp_uart_bit_handler(void *x, int bit) { dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x; - if (!handle -> have_start) { + if (!handle->have_start) { if (bit) { return; /* waiting for start bit (0) */ } - handle -> have_start = 1; - handle -> data = 0; - handle -> nbits = 0; + handle->have_start = 1; + handle->data = 0; + handle->nbits = 0; return; } - handle -> data >>= 1; - handle -> data |= 0x80 * !!bit; + 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... */ -#if 0 - } else if (handle -> nbits > 8) { - if (!bit) { - /* framing error; expected stop bit (mark, 1) */ - printf ("FRAME"); fflush (stdout); - } else { - handle -> have_start = 0; - handle -> nbits = 0; - } -#endif + 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/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h index 9989ab935d..91b2bd0880 100644 --- a/libs/freetdm/src/dsp/uart.h +++ b/libs/freetdm/src/dsp/uart.h @@ -61,15 +61,15 @@ typedef struct * d) feed bits through dsp_uart_bit_handler */ -void dsp_uart_attr_init (dsp_uart_attr_t *attributes); +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); +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); +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); +void dsp_uart_bit_handler(void *handle, int bit); #endif // __UART_H__ From e56c64a6920e9588cce41e3c195702a9d55a5c6b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 04:06:36 +0000 Subject: [PATCH 0403/1766] Add function pointer typedef. Switch to use /* */ comments to survive pickier compile flags. Change destroy function to take ** pointer so it can set the pointer back to NULL make code style consistent with the rest of the lib. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@202 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/bell202.c | 245 ++++++++++++++++----------------- libs/openzap/src/dsp/bell202.h | 29 ++-- 2 files changed, 131 insertions(+), 143 deletions(-) diff --git a/libs/openzap/src/dsp/bell202.c b/libs/openzap/src/dsp/bell202.c index 1213c2dcf5..0a8eaa038d 100644 --- a/libs/openzap/src/dsp/bell202.c +++ b/libs/openzap/src/dsp/bell202.c @@ -46,7 +46,7 @@ #define M_PI 3.14159265358979323846 #endif -// local constants +/* local constants */ #define BELL202_MARK 1200 #define BELL202_SPACE 2200 #define BELL202_BAUD 1200 @@ -58,10 +58,9 @@ * attributes structure is used. */ -void -dsp_bell202_attr_init (dsp_bell202_attr_t *attr) +void dsp_bell202_attr_init (dsp_bell202_attr_t *attr) { - memset (attr, 0, sizeof (*attr)); + memset(attr, 0, sizeof(*attr)); } /* @@ -77,48 +76,42 @@ dsp_bell202_attr_init (dsp_bell202_attr_t *attr) * zero == ok, -1 == fail. */ -void (* -dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attr, void **bithandler_arg)) (void *, int) +bithandler_func_t dsp_bell202_attr_get_bithandler(dsp_bell202_attr_t *attr, void **bithandler_arg) { - *bithandler_arg = attr -> bithandler_arg; - return (attr -> bithandler); + *bithandler_arg = attr->bithandler_arg; + return attr->bithandler; } -void -dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attr, void (*bithandler) (void *, int ), void *bithandler_arg) +void dsp_bell202_attr_set_bithandler(dsp_bell202_attr_t *attr, bithandler_func_t bithandler, void *bithandler_arg) { - attr -> bithandler = bithandler; - attr -> bithandler_arg = bithandler_arg; + attr->bithandler = bithandler; + attr->bithandler_arg = bithandler_arg; } -void (* -dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attr, void **bytehandler_arg)) (void *, int) +bytehandler_func_t dsp_bell202_attr_get_bytehandler(dsp_bell202_attr_t *attr, void **bytehandler_arg) { - *bytehandler_arg = attr -> bytehandler_arg; - return (attr -> bytehandler); + *bytehandler_arg = attr->bytehandler_arg; + return attr->bytehandler; } -void -dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attr, void (*bytehandler) (void *, int ), void *bytehandler_arg) +void dsp_bell202_attr_set_bytehandler(dsp_bell202_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) { - attr -> bytehandler = bytehandler; - attr -> bytehandler_arg = bytehandler_arg; + attr->bytehandler = bytehandler; + attr->bytehandler_arg = bytehandler_arg; } -int -dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) +int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) { - return (attr -> sample_rate); + return attr->sample_rate; } -int -dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) +int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) { if (samplerate <= 0) { - return (-1); + return -1; } - attr -> sample_rate = samplerate; - return (0); + attr->sample_rate = samplerate; + return 0; } /* @@ -132,123 +125,116 @@ dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) * Once created, the handle can be used until it is destroyed. */ -dsp_bell202_handle_t * -dsp_bell202_create (dsp_bell202_attr_t *attr) +dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) { int i; double phi_mark, phi_space; dsp_bell202_handle_t *handle; - handle = malloc (sizeof (*handle)); - if (handle == NULL) { - return (handle); + handle = malloc(sizeof(*handle)); + if (!handle) { + return NULL; } - memset (handle, 0, sizeof (*handle)); + memset(handle, 0, sizeof(*handle)); - // fill the attributes member - memcpy (&handle -> attr, attr, sizeof (*attr)); + /* fill the attributes member */ + memcpy(&handle->attr, attr, sizeof(*attr)); - // see if we can do downsampling. We only really need 6 samples to "match" - if (attr -> sample_rate / BELL202_MARK > 6) { - handle -> downsampling_count = attr -> sample_rate / BELL202_MARK / 6; + /* see if we can do downsampling. We only really need 6 samples to "match" */ + if (attr->sample_rate / BELL202_MARK > 6) { + handle->downsampling_count = attr->sample_rate / BELL202_MARK / 6; } else { - handle -> downsampling_count = 1; + handle->downsampling_count = 1; } - handle -> current_downsample = 1; + handle->current_downsample = 1; - // calculate the correlate size (number of samples required for slowest wave) - handle -> corrsize = attr -> sample_rate / handle -> downsampling_count / BELL202_MARK; + /* calculate the correlate size (number of samples required for slowest wave) */ + handle->corrsize = attr->sample_rate / handle->downsampling_count / BELL202_MARK; - // allocate the correlation sin/cos arrays and initialize + /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { - handle -> correlates [i] = malloc (sizeof (double) * handle -> corrsize); - if (handle -> correlates [i] == NULL) { - break; + handle->correlates[i] = malloc(sizeof(double) * handle->corrsize); + if (handle->correlates[i] == NULL) { + /* some failed, back out memory allocations */ + dsp_bell202_destroy(&handle); + return NULL; } } - if (i != 4) { // some failed, back out memory allocations - dsp_bell202_destroy (handle); - return (NULL); + + /* now initialize them */ + phi_mark = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_MARK); + phi_space = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_SPACE); + + for (i = 0; i < handle->corrsize; i++) { + handle->correlates[0][i] = sin(phi_mark * (double) i); + handle->correlates[1][i] = cos(phi_mark * (double) i); + handle->correlates[2][i] = sin(phi_space * (double) i); + handle->correlates[3][i] = cos(phi_space * (double) i); } - // now initialize them - phi_mark = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_MARK); - phi_space = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_SPACE); - - // printf ("phi_mark is %g, phi_space is %g\n", phi_mark, phi_space); - for (i = 0; i < handle -> corrsize; i++) { - handle -> correlates [0][i] = sin (phi_mark * (double) i); - handle -> correlates [1][i] = cos (phi_mark * (double) i); - handle -> correlates [2][i] = sin (phi_space * (double) i); - handle -> correlates [3][i] = cos (phi_space * (double) i); - // printf ("[%2d] MS %10.4f MC %10.4f SS %10.4f SC %10.4f\n", i, handle -> correlates [0][i], handle -> correlates [1][i], handle -> correlates [2][i], handle -> correlates [3][i]); + /* initialize the ring buffer */ + handle->buffer = malloc(sizeof(double) * handle->corrsize); + if (!handle->buffer) { /* failed; back out memory allocations */ + dsp_bell202_destroy(&handle); + return NULL; } + memset(handle->buffer, 0, sizeof(double) * handle->corrsize); + handle->ringstart = 0; - // initialize the ring buffer - handle -> buffer = malloc (sizeof (double) * handle -> corrsize); - if (handle -> buffer == NULL) { // failed; back out memory allocations - dsp_bell202_destroy (handle); - return (NULL); - } - memset (handle -> buffer, 0, sizeof (double) * handle -> corrsize); - handle -> ringstart = 0; + /* initalize intra-cell position */ + handle->cellpos = 0; + handle->celladj = BELL202_BAUD / (double) attr->sample_rate * (double) handle->downsampling_count; - // initalize intra-cell position - handle -> cellpos = 0; - handle -> celladj = BELL202_BAUD / (double) attr -> sample_rate * (double) handle -> downsampling_count; - - // printf ("corrsize %d celladj %g\n", handle -> corrsize, handle -> celladj); - - // if they have provided a byte handler, add a UART to the processing chain - if (handle -> attr.bytehandler) { + /* if they have provided a byte handler, add a UART to the processing chain */ + if (handle->attr.bytehandler) { dsp_uart_attr_t uart_attr; dsp_uart_handle_t *uart_handle; - dsp_uart_attr_init (&uart_attr); - dsp_uart_attr_set_bytehandler (&uart_attr, handle -> attr.bytehandler, handle -> attr.bytehandler_arg); - uart_handle = dsp_uart_create (&uart_attr); + dsp_uart_attr_init(&uart_attr); + dsp_uart_attr_set_bytehandler(&uart_attr, handle->attr.bytehandler, handle->attr.bytehandler_arg); + uart_handle = dsp_uart_create(&uart_attr); if (uart_handle == NULL) { - dsp_bell202_destroy (handle); - return (NULL); + dsp_bell202_destroy(&handle); + return NULL; } - handle -> attr.bithandler = dsp_uart_bit_handler; - handle -> attr.bithandler_arg = uart_handle; + handle->attr.bithandler = dsp_uart_bit_handler; + handle->attr.bithandler_arg = uart_handle; } - return (handle); + return handle; } /* * dsp_bell202_destroy * - * Destroys a handle, releasing any associated memory. A destroyed handle - * should not be used for anything. + * Destroys a handle, releasing any associated memory. Sets handle pointer to NULL + * so A destroyed handle can not be used for anything after the destroy. */ -void -dsp_bell202_destroy (dsp_bell202_handle_t *handle) +void dsp_bell202_destroy(dsp_bell202_handle_t **handle) { int i; - // if empty handle, just return - if (handle == NULL) { + /* if empty handle, just return */ + if (*handle == NULL) { return; } for (i = 0; i < 4; i++) { - if (handle -> correlates [i] != NULL) { - free (handle -> correlates [i]); - handle -> correlates [i] = NULL; + if ((*handle)->correlates[i] != NULL) { + free((*handle)->correlates[i]); + (*handle)->correlates[i] = NULL; } } - if (handle -> buffer != NULL) { - free (handle -> buffer); - handle -> buffer = NULL; + if ((*handle)->buffer != NULL) { + free((*handle)->buffer); + (*handle)->buffer = NULL; } - free (handle); + free(*handle); + *handle = NULL; } /* @@ -267,53 +253,52 @@ void dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample) { double val; - double factors [4]; + double factors[4]; int i, j; - // if we can avoid processing samples, do so - if (handle -> downsampling_count != 1) { - if (handle -> current_downsample < handle -> downsampling_count) { - handle -> current_downsample++; - return; // throw this sample out + /* if we can avoid processing samples, do so */ + if (handle->downsampling_count != 1) { + if (handle->current_downsample < handle->downsampling_count) { + handle->current_downsample++; + return; /* throw this sample out */ } - handle -> current_downsample = 1; + handle->current_downsample = 1; } - // store sample in buffer - handle -> buffer [handle -> ringstart++] = normalized_sample; - if (handle -> ringstart >= handle -> corrsize) { - handle -> ringstart = 0; + /* store sample in buffer */ + handle->buffer[handle->ringstart++] = normalized_sample; + if (handle->ringstart >= handle->corrsize) { + handle->ringstart = 0; } - // do the correlation calculation - factors [0] = factors [1] = factors [2] = factors [3] = 0; // clear out intermediate sums - j = handle -> ringstart; - for (i = 0; i < handle -> corrsize; i++) { - if (j >= handle -> corrsize) { + /* do the correlation calculation */ + factors[0] = factors[1] = factors[2] = factors[3] = 0; /* clear out intermediate sums */ + j = handle->ringstart; + for (i = 0; i < handle->corrsize; i++) { + if (j >= handle->corrsize) { j = 0; } - val = handle -> buffer [j]; - factors [0] += handle -> correlates [0][i] * val; - factors [1] += handle -> correlates [1][i] * val; - factors [2] += handle -> correlates [2][i] * val; - factors [3] += handle -> correlates [3][i] * val; + val = handle->buffer[j]; + factors[0] += handle->correlates[0][i] * val; + factors[1] += handle->correlates[1][i] * val; + factors[2] += handle->correlates[2][i] * val; + factors[3] += handle->correlates[3][i] * val; j++; } - // store the bit (bit value is comparison of the two sets of correlate factors) - handle -> previous_bit = handle -> current_bit; - handle -> current_bit = (factors [0] * factors [0] + factors [1] * factors [1] > factors [2] * factors [2] + factors [3] * factors [3]); + /* store the bit (bit value is comparison of the two sets of correlate factors) */ + handle->previous_bit = handle->current_bit; + handle->current_bit = (factors[0] * factors[0] + factors[1] * factors[1] > factors[2] * factors[2] + factors[3] * factors[3]); - // printf ("Sample %10.4f factors %10.4f %10.4f %10.4f %10.4f (sum %10.4f) previous %d current %d cellpos %10.4f\n", normalized_sample, factors [0], factors [1], factors [2], factors [3], factors [0] * factors [0] + factors [1] * factors [1] - factors [2] * factors [2] - factors [3] * factors [3], handle -> previous_bit, handle -> current_bit, handle -> cellpos); - // if there's a transition, we can synchronize the cell position - if (handle -> previous_bit != handle -> current_bit) { - handle -> cellpos = 0.5; // adjust cell position to be in the middle of the cell + /* if there's a transition, we can synchronize the cell position */ + if (handle->previous_bit != handle->current_bit) { + handle->cellpos = 0.5; /* adjust cell position to be in the middle of the cell */ } - handle -> cellpos += handle -> celladj; // walk the cell along + handle->cellpos += handle->celladj; /* walk the cell along */ - if (handle -> cellpos > 1.0) { - handle -> cellpos -= 1.0; - (*handle -> attr.bithandler) (handle -> attr.bithandler_arg, handle -> current_bit); + if (handle->cellpos > 1.0) { + handle->cellpos -= 1.0; + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); } } diff --git a/libs/openzap/src/dsp/bell202.h b/libs/openzap/src/dsp/bell202.h index caf144aec2..9ab47a91ca 100644 --- a/libs/openzap/src/dsp/bell202.h +++ b/libs/openzap/src/dsp/bell202.h @@ -35,19 +35,22 @@ #ifndef __BELL202_H__ #define __BELL202_H__ +typedef void (*bytehandler_func_t) (void *, int); +typedef void (*bithandler_func_t) (void *, int); + typedef struct dsp_bell202_attr_s { int sample_rate; // sample rate in HZ - void (*bithandler) (void *, int); // bit handler + bithandler_func_t bithandler; // bit handler void *bithandler_arg; // arbitrary ID passed to bithandler as first argument - void (*bytehandler) (void *, int); // byte handler + bytehandler_func_t bytehandler; // byte handler void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument } dsp_bell202_attr_t; typedef struct { dsp_bell202_attr_t attr; // attributes structure - double *correlates [4]; // one for each of sin/cos for mark/space + double *correlates[4]; // one for each of sin/cos for mark/space int corrsize; // correlate size (also number of samples in ring buffer) double *buffer; // sample ring buffer int ringstart; // ring buffer start offset @@ -69,19 +72,19 @@ typedef struct * d) feed samples through the handler (dsp_bell202_sample) */ -extern void dsp_bell202_attr_init (dsp_bell202_attr_t *attributes); +void dsp_bell202_attr_init(dsp_bell202_attr_t *attributes); -extern void (*dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attributes, void **bithandler_arg)) (void *, int); -extern void dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); -extern void (*dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attributes, void **bytehandler_arg)) (void *, int); -extern void dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); -extern int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attributes); -extern int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attributes, int samplerate); +bithandler_func_t dsp_bell202_attr_get_bithandler(dsp_bell202_attr_t *attributes, void **bithandler_arg); +void dsp_bell202_attr_set_bithandler(dsp_bell202_attr_t *attributes, bithandler_func_t bithandler, void *bithandler_arg); +bytehandler_func_t dsp_bell202_attr_get_bytehandler(dsp_bell202_attr_t *attributes, void **bytehandler_arg); +void dsp_bell202_attr_set_bytehandler(dsp_bell202_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); +int dsp_bell202_attr_get_samplerate(dsp_bell202_attr_t *attributes); +int dsp_bell202_attr_set_samplerate(dsp_bell202_attr_t *attributes, int samplerate); -extern dsp_bell202_handle_t * dsp_bell202_create (dsp_bell202_attr_t *attributes); -extern void dsp_bell202_destroy (dsp_bell202_handle_t *handle); +dsp_bell202_handle_t * dsp_bell202_create(dsp_bell202_attr_t *attributes); +void dsp_bell202_destroy(dsp_bell202_handle_t **handle); -extern void dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample); +void dsp_bell202_sample(dsp_bell202_handle_t *handle, double normalized_sample); #endif // __BELL202_H__ From 68365e349e3f5b699fa661689b6f47f0af35d86c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 04:06:36 +0000 Subject: [PATCH 0404/1766] Add function pointer typedef. Switch to use /* */ comments to survive pickier compile flags. Change destroy function to take ** pointer so it can set the pointer back to NULL make code style consistent with the rest of the lib. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@202 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/bell202.c | 245 ++++++++++++++++----------------- libs/freetdm/src/dsp/bell202.h | 29 ++-- 2 files changed, 131 insertions(+), 143 deletions(-) diff --git a/libs/freetdm/src/dsp/bell202.c b/libs/freetdm/src/dsp/bell202.c index 1213c2dcf5..0a8eaa038d 100644 --- a/libs/freetdm/src/dsp/bell202.c +++ b/libs/freetdm/src/dsp/bell202.c @@ -46,7 +46,7 @@ #define M_PI 3.14159265358979323846 #endif -// local constants +/* local constants */ #define BELL202_MARK 1200 #define BELL202_SPACE 2200 #define BELL202_BAUD 1200 @@ -58,10 +58,9 @@ * attributes structure is used. */ -void -dsp_bell202_attr_init (dsp_bell202_attr_t *attr) +void dsp_bell202_attr_init (dsp_bell202_attr_t *attr) { - memset (attr, 0, sizeof (*attr)); + memset(attr, 0, sizeof(*attr)); } /* @@ -77,48 +76,42 @@ dsp_bell202_attr_init (dsp_bell202_attr_t *attr) * zero == ok, -1 == fail. */ -void (* -dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attr, void **bithandler_arg)) (void *, int) +bithandler_func_t dsp_bell202_attr_get_bithandler(dsp_bell202_attr_t *attr, void **bithandler_arg) { - *bithandler_arg = attr -> bithandler_arg; - return (attr -> bithandler); + *bithandler_arg = attr->bithandler_arg; + return attr->bithandler; } -void -dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attr, void (*bithandler) (void *, int ), void *bithandler_arg) +void dsp_bell202_attr_set_bithandler(dsp_bell202_attr_t *attr, bithandler_func_t bithandler, void *bithandler_arg) { - attr -> bithandler = bithandler; - attr -> bithandler_arg = bithandler_arg; + attr->bithandler = bithandler; + attr->bithandler_arg = bithandler_arg; } -void (* -dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attr, void **bytehandler_arg)) (void *, int) +bytehandler_func_t dsp_bell202_attr_get_bytehandler(dsp_bell202_attr_t *attr, void **bytehandler_arg) { - *bytehandler_arg = attr -> bytehandler_arg; - return (attr -> bytehandler); + *bytehandler_arg = attr->bytehandler_arg; + return attr->bytehandler; } -void -dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attr, void (*bytehandler) (void *, int ), void *bytehandler_arg) +void dsp_bell202_attr_set_bytehandler(dsp_bell202_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) { - attr -> bytehandler = bytehandler; - attr -> bytehandler_arg = bytehandler_arg; + attr->bytehandler = bytehandler; + attr->bytehandler_arg = bytehandler_arg; } -int -dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) +int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) { - return (attr -> sample_rate); + return attr->sample_rate; } -int -dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) +int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) { if (samplerate <= 0) { - return (-1); + return -1; } - attr -> sample_rate = samplerate; - return (0); + attr->sample_rate = samplerate; + return 0; } /* @@ -132,123 +125,116 @@ dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) * Once created, the handle can be used until it is destroyed. */ -dsp_bell202_handle_t * -dsp_bell202_create (dsp_bell202_attr_t *attr) +dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) { int i; double phi_mark, phi_space; dsp_bell202_handle_t *handle; - handle = malloc (sizeof (*handle)); - if (handle == NULL) { - return (handle); + handle = malloc(sizeof(*handle)); + if (!handle) { + return NULL; } - memset (handle, 0, sizeof (*handle)); + memset(handle, 0, sizeof(*handle)); - // fill the attributes member - memcpy (&handle -> attr, attr, sizeof (*attr)); + /* fill the attributes member */ + memcpy(&handle->attr, attr, sizeof(*attr)); - // see if we can do downsampling. We only really need 6 samples to "match" - if (attr -> sample_rate / BELL202_MARK > 6) { - handle -> downsampling_count = attr -> sample_rate / BELL202_MARK / 6; + /* see if we can do downsampling. We only really need 6 samples to "match" */ + if (attr->sample_rate / BELL202_MARK > 6) { + handle->downsampling_count = attr->sample_rate / BELL202_MARK / 6; } else { - handle -> downsampling_count = 1; + handle->downsampling_count = 1; } - handle -> current_downsample = 1; + handle->current_downsample = 1; - // calculate the correlate size (number of samples required for slowest wave) - handle -> corrsize = attr -> sample_rate / handle -> downsampling_count / BELL202_MARK; + /* calculate the correlate size (number of samples required for slowest wave) */ + handle->corrsize = attr->sample_rate / handle->downsampling_count / BELL202_MARK; - // allocate the correlation sin/cos arrays and initialize + /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { - handle -> correlates [i] = malloc (sizeof (double) * handle -> corrsize); - if (handle -> correlates [i] == NULL) { - break; + handle->correlates[i] = malloc(sizeof(double) * handle->corrsize); + if (handle->correlates[i] == NULL) { + /* some failed, back out memory allocations */ + dsp_bell202_destroy(&handle); + return NULL; } } - if (i != 4) { // some failed, back out memory allocations - dsp_bell202_destroy (handle); - return (NULL); + + /* now initialize them */ + phi_mark = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_MARK); + phi_space = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_SPACE); + + for (i = 0; i < handle->corrsize; i++) { + handle->correlates[0][i] = sin(phi_mark * (double) i); + handle->correlates[1][i] = cos(phi_mark * (double) i); + handle->correlates[2][i] = sin(phi_space * (double) i); + handle->correlates[3][i] = cos(phi_space * (double) i); } - // now initialize them - phi_mark = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_MARK); - phi_space = 2. * M_PI / ((double) attr -> sample_rate / (double) handle -> downsampling_count / (double) BELL202_SPACE); - - // printf ("phi_mark is %g, phi_space is %g\n", phi_mark, phi_space); - for (i = 0; i < handle -> corrsize; i++) { - handle -> correlates [0][i] = sin (phi_mark * (double) i); - handle -> correlates [1][i] = cos (phi_mark * (double) i); - handle -> correlates [2][i] = sin (phi_space * (double) i); - handle -> correlates [3][i] = cos (phi_space * (double) i); - // printf ("[%2d] MS %10.4f MC %10.4f SS %10.4f SC %10.4f\n", i, handle -> correlates [0][i], handle -> correlates [1][i], handle -> correlates [2][i], handle -> correlates [3][i]); + /* initialize the ring buffer */ + handle->buffer = malloc(sizeof(double) * handle->corrsize); + if (!handle->buffer) { /* failed; back out memory allocations */ + dsp_bell202_destroy(&handle); + return NULL; } + memset(handle->buffer, 0, sizeof(double) * handle->corrsize); + handle->ringstart = 0; - // initialize the ring buffer - handle -> buffer = malloc (sizeof (double) * handle -> corrsize); - if (handle -> buffer == NULL) { // failed; back out memory allocations - dsp_bell202_destroy (handle); - return (NULL); - } - memset (handle -> buffer, 0, sizeof (double) * handle -> corrsize); - handle -> ringstart = 0; + /* initalize intra-cell position */ + handle->cellpos = 0; + handle->celladj = BELL202_BAUD / (double) attr->sample_rate * (double) handle->downsampling_count; - // initalize intra-cell position - handle -> cellpos = 0; - handle -> celladj = BELL202_BAUD / (double) attr -> sample_rate * (double) handle -> downsampling_count; - - // printf ("corrsize %d celladj %g\n", handle -> corrsize, handle -> celladj); - - // if they have provided a byte handler, add a UART to the processing chain - if (handle -> attr.bytehandler) { + /* if they have provided a byte handler, add a UART to the processing chain */ + if (handle->attr.bytehandler) { dsp_uart_attr_t uart_attr; dsp_uart_handle_t *uart_handle; - dsp_uart_attr_init (&uart_attr); - dsp_uart_attr_set_bytehandler (&uart_attr, handle -> attr.bytehandler, handle -> attr.bytehandler_arg); - uart_handle = dsp_uart_create (&uart_attr); + dsp_uart_attr_init(&uart_attr); + dsp_uart_attr_set_bytehandler(&uart_attr, handle->attr.bytehandler, handle->attr.bytehandler_arg); + uart_handle = dsp_uart_create(&uart_attr); if (uart_handle == NULL) { - dsp_bell202_destroy (handle); - return (NULL); + dsp_bell202_destroy(&handle); + return NULL; } - handle -> attr.bithandler = dsp_uart_bit_handler; - handle -> attr.bithandler_arg = uart_handle; + handle->attr.bithandler = dsp_uart_bit_handler; + handle->attr.bithandler_arg = uart_handle; } - return (handle); + return handle; } /* * dsp_bell202_destroy * - * Destroys a handle, releasing any associated memory. A destroyed handle - * should not be used for anything. + * Destroys a handle, releasing any associated memory. Sets handle pointer to NULL + * so A destroyed handle can not be used for anything after the destroy. */ -void -dsp_bell202_destroy (dsp_bell202_handle_t *handle) +void dsp_bell202_destroy(dsp_bell202_handle_t **handle) { int i; - // if empty handle, just return - if (handle == NULL) { + /* if empty handle, just return */ + if (*handle == NULL) { return; } for (i = 0; i < 4; i++) { - if (handle -> correlates [i] != NULL) { - free (handle -> correlates [i]); - handle -> correlates [i] = NULL; + if ((*handle)->correlates[i] != NULL) { + free((*handle)->correlates[i]); + (*handle)->correlates[i] = NULL; } } - if (handle -> buffer != NULL) { - free (handle -> buffer); - handle -> buffer = NULL; + if ((*handle)->buffer != NULL) { + free((*handle)->buffer); + (*handle)->buffer = NULL; } - free (handle); + free(*handle); + *handle = NULL; } /* @@ -267,53 +253,52 @@ void dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample) { double val; - double factors [4]; + double factors[4]; int i, j; - // if we can avoid processing samples, do so - if (handle -> downsampling_count != 1) { - if (handle -> current_downsample < handle -> downsampling_count) { - handle -> current_downsample++; - return; // throw this sample out + /* if we can avoid processing samples, do so */ + if (handle->downsampling_count != 1) { + if (handle->current_downsample < handle->downsampling_count) { + handle->current_downsample++; + return; /* throw this sample out */ } - handle -> current_downsample = 1; + handle->current_downsample = 1; } - // store sample in buffer - handle -> buffer [handle -> ringstart++] = normalized_sample; - if (handle -> ringstart >= handle -> corrsize) { - handle -> ringstart = 0; + /* store sample in buffer */ + handle->buffer[handle->ringstart++] = normalized_sample; + if (handle->ringstart >= handle->corrsize) { + handle->ringstart = 0; } - // do the correlation calculation - factors [0] = factors [1] = factors [2] = factors [3] = 0; // clear out intermediate sums - j = handle -> ringstart; - for (i = 0; i < handle -> corrsize; i++) { - if (j >= handle -> corrsize) { + /* do the correlation calculation */ + factors[0] = factors[1] = factors[2] = factors[3] = 0; /* clear out intermediate sums */ + j = handle->ringstart; + for (i = 0; i < handle->corrsize; i++) { + if (j >= handle->corrsize) { j = 0; } - val = handle -> buffer [j]; - factors [0] += handle -> correlates [0][i] * val; - factors [1] += handle -> correlates [1][i] * val; - factors [2] += handle -> correlates [2][i] * val; - factors [3] += handle -> correlates [3][i] * val; + val = handle->buffer[j]; + factors[0] += handle->correlates[0][i] * val; + factors[1] += handle->correlates[1][i] * val; + factors[2] += handle->correlates[2][i] * val; + factors[3] += handle->correlates[3][i] * val; j++; } - // store the bit (bit value is comparison of the two sets of correlate factors) - handle -> previous_bit = handle -> current_bit; - handle -> current_bit = (factors [0] * factors [0] + factors [1] * factors [1] > factors [2] * factors [2] + factors [3] * factors [3]); + /* store the bit (bit value is comparison of the two sets of correlate factors) */ + handle->previous_bit = handle->current_bit; + handle->current_bit = (factors[0] * factors[0] + factors[1] * factors[1] > factors[2] * factors[2] + factors[3] * factors[3]); - // printf ("Sample %10.4f factors %10.4f %10.4f %10.4f %10.4f (sum %10.4f) previous %d current %d cellpos %10.4f\n", normalized_sample, factors [0], factors [1], factors [2], factors [3], factors [0] * factors [0] + factors [1] * factors [1] - factors [2] * factors [2] - factors [3] * factors [3], handle -> previous_bit, handle -> current_bit, handle -> cellpos); - // if there's a transition, we can synchronize the cell position - if (handle -> previous_bit != handle -> current_bit) { - handle -> cellpos = 0.5; // adjust cell position to be in the middle of the cell + /* if there's a transition, we can synchronize the cell position */ + if (handle->previous_bit != handle->current_bit) { + handle->cellpos = 0.5; /* adjust cell position to be in the middle of the cell */ } - handle -> cellpos += handle -> celladj; // walk the cell along + handle->cellpos += handle->celladj; /* walk the cell along */ - if (handle -> cellpos > 1.0) { - handle -> cellpos -= 1.0; - (*handle -> attr.bithandler) (handle -> attr.bithandler_arg, handle -> current_bit); + if (handle->cellpos > 1.0) { + handle->cellpos -= 1.0; + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); } } diff --git a/libs/freetdm/src/dsp/bell202.h b/libs/freetdm/src/dsp/bell202.h index caf144aec2..9ab47a91ca 100644 --- a/libs/freetdm/src/dsp/bell202.h +++ b/libs/freetdm/src/dsp/bell202.h @@ -35,19 +35,22 @@ #ifndef __BELL202_H__ #define __BELL202_H__ +typedef void (*bytehandler_func_t) (void *, int); +typedef void (*bithandler_func_t) (void *, int); + typedef struct dsp_bell202_attr_s { int sample_rate; // sample rate in HZ - void (*bithandler) (void *, int); // bit handler + bithandler_func_t bithandler; // bit handler void *bithandler_arg; // arbitrary ID passed to bithandler as first argument - void (*bytehandler) (void *, int); // byte handler + bytehandler_func_t bytehandler; // byte handler void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument } dsp_bell202_attr_t; typedef struct { dsp_bell202_attr_t attr; // attributes structure - double *correlates [4]; // one for each of sin/cos for mark/space + double *correlates[4]; // one for each of sin/cos for mark/space int corrsize; // correlate size (also number of samples in ring buffer) double *buffer; // sample ring buffer int ringstart; // ring buffer start offset @@ -69,19 +72,19 @@ typedef struct * d) feed samples through the handler (dsp_bell202_sample) */ -extern void dsp_bell202_attr_init (dsp_bell202_attr_t *attributes); +void dsp_bell202_attr_init(dsp_bell202_attr_t *attributes); -extern void (*dsp_bell202_attr_get_bithandler (dsp_bell202_attr_t *attributes, void **bithandler_arg)) (void *, int); -extern void dsp_bell202_attr_set_bithandler (dsp_bell202_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg); -extern void (*dsp_bell202_attr_get_bytehandler (dsp_bell202_attr_t *attributes, void **bytehandler_arg)) (void *, int); -extern void dsp_bell202_attr_set_bytehandler (dsp_bell202_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg); -extern int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attributes); -extern int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attributes, int samplerate); +bithandler_func_t dsp_bell202_attr_get_bithandler(dsp_bell202_attr_t *attributes, void **bithandler_arg); +void dsp_bell202_attr_set_bithandler(dsp_bell202_attr_t *attributes, bithandler_func_t bithandler, void *bithandler_arg); +bytehandler_func_t dsp_bell202_attr_get_bytehandler(dsp_bell202_attr_t *attributes, void **bytehandler_arg); +void dsp_bell202_attr_set_bytehandler(dsp_bell202_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); +int dsp_bell202_attr_get_samplerate(dsp_bell202_attr_t *attributes); +int dsp_bell202_attr_set_samplerate(dsp_bell202_attr_t *attributes, int samplerate); -extern dsp_bell202_handle_t * dsp_bell202_create (dsp_bell202_attr_t *attributes); -extern void dsp_bell202_destroy (dsp_bell202_handle_t *handle); +dsp_bell202_handle_t * dsp_bell202_create(dsp_bell202_attr_t *attributes); +void dsp_bell202_destroy(dsp_bell202_handle_t **handle); -extern void dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample); +void dsp_bell202_sample(dsp_bell202_handle_t *handle, double normalized_sample); #endif // __BELL202_H__ From b351047b149e728061f2d6721e2971250e2ec8f0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 04:14:39 +0000 Subject: [PATCH 0405/1766] fix destroy leak when using uart. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@203 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/bell202.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/src/dsp/bell202.c b/libs/openzap/src/dsp/bell202.c index 0a8eaa038d..cd1633febf 100644 --- a/libs/openzap/src/dsp/bell202.c +++ b/libs/openzap/src/dsp/bell202.c @@ -233,6 +233,10 @@ void dsp_bell202_destroy(dsp_bell202_handle_t **handle) (*handle)->buffer = NULL; } + if ((*handle)->attr.bytehandler) { + dsp_uart_destroy((dsp_uart_handle_t**)&(*handle)->attr.bithandler_arg); + } + free(*handle); *handle = NULL; } From 6c13e901e0604b4049b779718d57d77a28f26664 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 04:14:39 +0000 Subject: [PATCH 0406/1766] fix destroy leak when using uart. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@203 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/bell202.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/src/dsp/bell202.c b/libs/freetdm/src/dsp/bell202.c index 0a8eaa038d..cd1633febf 100644 --- a/libs/freetdm/src/dsp/bell202.c +++ b/libs/freetdm/src/dsp/bell202.c @@ -233,6 +233,10 @@ void dsp_bell202_destroy(dsp_bell202_handle_t **handle) (*handle)->buffer = NULL; } + if ((*handle)->attr.bytehandler) { + dsp_uart_destroy((dsp_uart_handle_t**)&(*handle)->attr.bithandler_arg); + } + free(*handle); *handle = NULL; } From f59addad71cc6cedb9ad837b7e2208cc6c84e10e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 17:51:20 +0000 Subject: [PATCH 0407/1766] change namespace on bell202 to fsk in preparation for generalizing the code for more kinds of fsk modems. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@204 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 4 +- libs/openzap/src/dsp/bell202.h | 90 ----------------------- libs/openzap/src/dsp/{bell202.c => fsk.c} | 52 +++++++------ libs/openzap/src/dsp/fsk.h | 90 +++++++++++++++++++++++ libs/openzap/src/dsp/readme.txt | 20 ++--- 5 files changed, 130 insertions(+), 126 deletions(-) delete mode 100644 libs/openzap/src/dsp/bell202.h rename libs/openzap/src/dsp/{bell202.c => fsk.c} (86%) create mode 100644 libs/openzap/src/dsp/fsk.h diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 60f41cdf40..84fe2d134b 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -472,7 +472,7 @@ Name="Header Files" > bithandler_arg; return attr->bithandler; } -void dsp_bell202_attr_set_bithandler(dsp_bell202_attr_t *attr, bithandler_func_t bithandler, void *bithandler_arg) +void dsp_fsk_attr_set_bithandler(dsp_fsk_attr_t *attr, bithandler_func_t bithandler, void *bithandler_arg) { attr->bithandler = bithandler; attr->bithandler_arg = bithandler_arg; } -bytehandler_func_t dsp_bell202_attr_get_bytehandler(dsp_bell202_attr_t *attr, void **bytehandler_arg) +bytehandler_func_t dsp_fsk_attr_get_bytehandler(dsp_fsk_attr_t *attr, void **bytehandler_arg) { *bytehandler_arg = attr->bytehandler_arg; return attr->bytehandler; } -void dsp_bell202_attr_set_bytehandler(dsp_bell202_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) +void dsp_fsk_attr_set_bytehandler(dsp_fsk_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) { attr->bytehandler = bytehandler; attr->bytehandler_arg = bytehandler_arg; } -int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) +int dsp_fsk_attr_get_samplerate (dsp_fsk_attr_t *attr) { return attr->sample_rate; } -int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) +int dsp_fsk_attr_set_samplerate (dsp_fsk_attr_t *attr, int samplerate) { if (samplerate <= 0) { return -1; @@ -115,7 +119,7 @@ int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) } /* - * dsp_bell202_create + * dsp_fsk_create * * Creates a handle for subsequent use. The handle is created to contain * a context data structure for use by the sample handler function. The @@ -125,11 +129,11 @@ int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) * Once created, the handle can be used until it is destroyed. */ -dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) +dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) { int i; double phi_mark, phi_space; - dsp_bell202_handle_t *handle; + dsp_fsk_handle_t *handle; handle = malloc(sizeof(*handle)); if (!handle) { @@ -157,7 +161,7 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) handle->correlates[i] = malloc(sizeof(double) * handle->corrsize); if (handle->correlates[i] == NULL) { /* some failed, back out memory allocations */ - dsp_bell202_destroy(&handle); + dsp_fsk_destroy(&handle); return NULL; } } @@ -176,7 +180,7 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) /* initialize the ring buffer */ handle->buffer = malloc(sizeof(double) * handle->corrsize); if (!handle->buffer) { /* failed; back out memory allocations */ - dsp_bell202_destroy(&handle); + dsp_fsk_destroy(&handle); return NULL; } memset(handle->buffer, 0, sizeof(double) * handle->corrsize); @@ -195,7 +199,7 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) dsp_uart_attr_set_bytehandler(&uart_attr, handle->attr.bytehandler, handle->attr.bytehandler_arg); uart_handle = dsp_uart_create(&uart_attr); if (uart_handle == NULL) { - dsp_bell202_destroy(&handle); + dsp_fsk_destroy(&handle); return NULL; } handle->attr.bithandler = dsp_uart_bit_handler; @@ -206,13 +210,13 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) } /* - * dsp_bell202_destroy + * dsp_fsk_destroy * * Destroys a handle, releasing any associated memory. Sets handle pointer to NULL * so A destroyed handle can not be used for anything after the destroy. */ -void dsp_bell202_destroy(dsp_bell202_handle_t **handle) +void dsp_fsk_destroy(dsp_fsk_handle_t **handle) { int i; @@ -242,7 +246,7 @@ void dsp_bell202_destroy(dsp_bell202_handle_t **handle) } /* - * dsp_bell202_sample + * dsp_fsk_sample * * This is the main processing entry point. The function accepts a normalized * sample (i.e., one whose range is between -1 and +1). The function performs @@ -254,7 +258,7 @@ void dsp_bell202_destroy(dsp_bell202_handle_t **handle) */ void -dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample) +dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) { double val; double factors[4]; diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/dsp/fsk.h new file mode 100644 index 0000000000..dfb6af369c --- /dev/null +++ b/libs/openzap/src/dsp/fsk.h @@ -0,0 +1,90 @@ + +/* + * bell202.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 Bell-202 1200 baud FSK modem. + * + * 2005 03 20 R. Krten created +*/ + +#ifndef __BELL202_H__ +#define __BELL202_H__ + +typedef void (*bytehandler_func_t) (void *, int); +typedef void (*bithandler_func_t) (void *, int); + +typedef struct dsp_fsk_attr_s +{ + int sample_rate; /* sample rate in HZ */ + bithandler_func_t bithandler; /* bit handler */ + void *bithandler_arg; /* arbitrary ID passed to bithandler as first argument */ + bytehandler_func_t bytehandler; /* byte handler */ + void *bytehandler_arg; /* arbitrary ID passed to bytehandler as first argument */ +} dsp_fsk_attr_t; + +typedef struct +{ + dsp_fsk_attr_t attr; /* attributes structure */ + double *correlates[4]; /* one for each of sin/cos for mark/space */ + int corrsize; /* correlate size (also number of samples in ring buffer) */ + double *buffer; /* sample ring buffer */ + int ringstart; /* ring buffer start offset */ + double cellpos; /* bit cell position */ + double celladj; /* bit cell adjustment for each sample */ + int previous_bit; /* previous bit (for detecting a transition to sync-up cell position) */ + int current_bit; /* current bit */ + int downsampling_count; /* number of samples to skip */ + int current_downsample; /* current skip count */ +} dsp_fsk_handle_t; + +/* + * Function prototypes + * + * General calling order is: + * a) create the attributes structure (dsp_fsk_attr_init) + * b) initialize fields in the attributes structure (dsp_fsk_attr_set_*) + * c) create a Bell-202 handle (dsp_fsk_create) + * d) feed samples through the handler (dsp_fsk_sample) +*/ + +void dsp_fsk_attr_init(dsp_fsk_attr_t *attributes); + +bithandler_func_t dsp_fsk_attr_get_bithandler(dsp_fsk_attr_t *attributes, void **bithandler_arg); +void dsp_fsk_attr_set_bithandler(dsp_fsk_attr_t *attributes, bithandler_func_t bithandler, void *bithandler_arg); +bytehandler_func_t dsp_fsk_attr_get_bytehandler(dsp_fsk_attr_t *attributes, void **bytehandler_arg); +void dsp_fsk_attr_set_bytehandler(dsp_fsk_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); +int dsp_fsk_attr_get_samplerate(dsp_fsk_attr_t *attributes); +int dsp_fsk_attr_set_samplerate(dsp_fsk_attr_t *attributes, int samplerate); + +dsp_fsk_handle_t * dsp_fsk_create(dsp_fsk_attr_t *attributes); +void dsp_fsk_destroy(dsp_fsk_handle_t **handle); + +void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); + +#endif // __BELL202_H__ + diff --git a/libs/openzap/src/dsp/readme.txt b/libs/openzap/src/dsp/readme.txt index 6283a4345e..6a71f9bf10 100644 --- a/libs/openzap/src/dsp/readme.txt +++ b/libs/openzap/src/dsp/readme.txt @@ -2,29 +2,29 @@ I have only tested the library with samples at 8kHz. It *should* work with arbi The first thing you need to do is initialize a context structure: - dsp_bell202_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem - dsp_bell202_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem + dsp_fsk_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem + dsp_fsk_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem // initialize: - dsp_bell202_attr_init (&fsk1200_attr); // clear attributes structure - dsp_bell202_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate - dsp_bell202_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler + dsp_fsk_attr_init (&fsk1200_attr); // clear attributes structure + dsp_fsk_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate + dsp_fsk_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler // create context: - fsk1200_handle = dsp_bell202_create (&fsk1200_attr); + fsk1200_handle = dsp_fsk_create (&fsk1200_attr); // error check: if (fsk1200_handle == NULL) { - fprintf (stderr, "%s: can't dsp_bell202_create, errno %d (%s)\n", progname, errno, strerror (errno)); + fprintf (stderr, "%s: can't dsp_fsk_create, errno %d (%s)\n", progname, errno, strerror (errno)); exit (EXIT_FAILURE); } If you are decoding multiple channels, you will need multiple context structures; one per channel. -The attributes ("dsp_bell202_attr_t") do not have to be persistent, but the handle does. -There's even a "dsp_bell202_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. +The attributes ("dsp_fsk_attr_t") do not have to be persistent, but the handle does. +There's even a "dsp_fsk_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. Then, you need to feed samples into the software modem: - dsp_bell202_sample (fsk1200_handle, (double) sample / 32767.); + dsp_fsk_sample (fsk1200_handle, (double) sample / 32767.); It assumes the samples are between -1 and 1 as a double. From d8ab108f0b768ffb5b245ad47f8e77761c556a0f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 17:51:20 +0000 Subject: [PATCH 0408/1766] change namespace on bell202 to fsk in preparation for generalizing the code for more kinds of fsk modems. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@204 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 4 +- libs/freetdm/src/dsp/bell202.h | 90 ----------------------- libs/freetdm/src/dsp/{bell202.c => fsk.c} | 52 +++++++------ libs/freetdm/src/dsp/fsk.h | 90 +++++++++++++++++++++++ libs/freetdm/src/dsp/readme.txt | 20 ++--- 5 files changed, 130 insertions(+), 126 deletions(-) delete mode 100644 libs/freetdm/src/dsp/bell202.h rename libs/freetdm/src/dsp/{bell202.c => fsk.c} (86%) create mode 100644 libs/freetdm/src/dsp/fsk.h diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 60f41cdf40..84fe2d134b 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -472,7 +472,7 @@ Name="Header Files" > bithandler_arg; return attr->bithandler; } -void dsp_bell202_attr_set_bithandler(dsp_bell202_attr_t *attr, bithandler_func_t bithandler, void *bithandler_arg) +void dsp_fsk_attr_set_bithandler(dsp_fsk_attr_t *attr, bithandler_func_t bithandler, void *bithandler_arg) { attr->bithandler = bithandler; attr->bithandler_arg = bithandler_arg; } -bytehandler_func_t dsp_bell202_attr_get_bytehandler(dsp_bell202_attr_t *attr, void **bytehandler_arg) +bytehandler_func_t dsp_fsk_attr_get_bytehandler(dsp_fsk_attr_t *attr, void **bytehandler_arg) { *bytehandler_arg = attr->bytehandler_arg; return attr->bytehandler; } -void dsp_bell202_attr_set_bytehandler(dsp_bell202_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) +void dsp_fsk_attr_set_bytehandler(dsp_fsk_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) { attr->bytehandler = bytehandler; attr->bytehandler_arg = bytehandler_arg; } -int dsp_bell202_attr_get_samplerate (dsp_bell202_attr_t *attr) +int dsp_fsk_attr_get_samplerate (dsp_fsk_attr_t *attr) { return attr->sample_rate; } -int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) +int dsp_fsk_attr_set_samplerate (dsp_fsk_attr_t *attr, int samplerate) { if (samplerate <= 0) { return -1; @@ -115,7 +119,7 @@ int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) } /* - * dsp_bell202_create + * dsp_fsk_create * * Creates a handle for subsequent use. The handle is created to contain * a context data structure for use by the sample handler function. The @@ -125,11 +129,11 @@ int dsp_bell202_attr_set_samplerate (dsp_bell202_attr_t *attr, int samplerate) * Once created, the handle can be used until it is destroyed. */ -dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) +dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) { int i; double phi_mark, phi_space; - dsp_bell202_handle_t *handle; + dsp_fsk_handle_t *handle; handle = malloc(sizeof(*handle)); if (!handle) { @@ -157,7 +161,7 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) handle->correlates[i] = malloc(sizeof(double) * handle->corrsize); if (handle->correlates[i] == NULL) { /* some failed, back out memory allocations */ - dsp_bell202_destroy(&handle); + dsp_fsk_destroy(&handle); return NULL; } } @@ -176,7 +180,7 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) /* initialize the ring buffer */ handle->buffer = malloc(sizeof(double) * handle->corrsize); if (!handle->buffer) { /* failed; back out memory allocations */ - dsp_bell202_destroy(&handle); + dsp_fsk_destroy(&handle); return NULL; } memset(handle->buffer, 0, sizeof(double) * handle->corrsize); @@ -195,7 +199,7 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) dsp_uart_attr_set_bytehandler(&uart_attr, handle->attr.bytehandler, handle->attr.bytehandler_arg); uart_handle = dsp_uart_create(&uart_attr); if (uart_handle == NULL) { - dsp_bell202_destroy(&handle); + dsp_fsk_destroy(&handle); return NULL; } handle->attr.bithandler = dsp_uart_bit_handler; @@ -206,13 +210,13 @@ dsp_bell202_handle_t *dsp_bell202_create(dsp_bell202_attr_t *attr) } /* - * dsp_bell202_destroy + * dsp_fsk_destroy * * Destroys a handle, releasing any associated memory. Sets handle pointer to NULL * so A destroyed handle can not be used for anything after the destroy. */ -void dsp_bell202_destroy(dsp_bell202_handle_t **handle) +void dsp_fsk_destroy(dsp_fsk_handle_t **handle) { int i; @@ -242,7 +246,7 @@ void dsp_bell202_destroy(dsp_bell202_handle_t **handle) } /* - * dsp_bell202_sample + * dsp_fsk_sample * * This is the main processing entry point. The function accepts a normalized * sample (i.e., one whose range is between -1 and +1). The function performs @@ -254,7 +258,7 @@ void dsp_bell202_destroy(dsp_bell202_handle_t **handle) */ void -dsp_bell202_sample (dsp_bell202_handle_t *handle, double normalized_sample) +dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) { double val; double factors[4]; diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/dsp/fsk.h new file mode 100644 index 0000000000..dfb6af369c --- /dev/null +++ b/libs/freetdm/src/dsp/fsk.h @@ -0,0 +1,90 @@ + +/* + * bell202.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 Bell-202 1200 baud FSK modem. + * + * 2005 03 20 R. Krten created +*/ + +#ifndef __BELL202_H__ +#define __BELL202_H__ + +typedef void (*bytehandler_func_t) (void *, int); +typedef void (*bithandler_func_t) (void *, int); + +typedef struct dsp_fsk_attr_s +{ + int sample_rate; /* sample rate in HZ */ + bithandler_func_t bithandler; /* bit handler */ + void *bithandler_arg; /* arbitrary ID passed to bithandler as first argument */ + bytehandler_func_t bytehandler; /* byte handler */ + void *bytehandler_arg; /* arbitrary ID passed to bytehandler as first argument */ +} dsp_fsk_attr_t; + +typedef struct +{ + dsp_fsk_attr_t attr; /* attributes structure */ + double *correlates[4]; /* one for each of sin/cos for mark/space */ + int corrsize; /* correlate size (also number of samples in ring buffer) */ + double *buffer; /* sample ring buffer */ + int ringstart; /* ring buffer start offset */ + double cellpos; /* bit cell position */ + double celladj; /* bit cell adjustment for each sample */ + int previous_bit; /* previous bit (for detecting a transition to sync-up cell position) */ + int current_bit; /* current bit */ + int downsampling_count; /* number of samples to skip */ + int current_downsample; /* current skip count */ +} dsp_fsk_handle_t; + +/* + * Function prototypes + * + * General calling order is: + * a) create the attributes structure (dsp_fsk_attr_init) + * b) initialize fields in the attributes structure (dsp_fsk_attr_set_*) + * c) create a Bell-202 handle (dsp_fsk_create) + * d) feed samples through the handler (dsp_fsk_sample) +*/ + +void dsp_fsk_attr_init(dsp_fsk_attr_t *attributes); + +bithandler_func_t dsp_fsk_attr_get_bithandler(dsp_fsk_attr_t *attributes, void **bithandler_arg); +void dsp_fsk_attr_set_bithandler(dsp_fsk_attr_t *attributes, bithandler_func_t bithandler, void *bithandler_arg); +bytehandler_func_t dsp_fsk_attr_get_bytehandler(dsp_fsk_attr_t *attributes, void **bytehandler_arg); +void dsp_fsk_attr_set_bytehandler(dsp_fsk_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); +int dsp_fsk_attr_get_samplerate(dsp_fsk_attr_t *attributes); +int dsp_fsk_attr_set_samplerate(dsp_fsk_attr_t *attributes, int samplerate); + +dsp_fsk_handle_t * dsp_fsk_create(dsp_fsk_attr_t *attributes); +void dsp_fsk_destroy(dsp_fsk_handle_t **handle); + +void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); + +#endif // __BELL202_H__ + diff --git a/libs/freetdm/src/dsp/readme.txt b/libs/freetdm/src/dsp/readme.txt index 6283a4345e..6a71f9bf10 100644 --- a/libs/freetdm/src/dsp/readme.txt +++ b/libs/freetdm/src/dsp/readme.txt @@ -2,29 +2,29 @@ I have only tested the library with samples at 8kHz. It *should* work with arbi The first thing you need to do is initialize a context structure: - dsp_bell202_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem - dsp_bell202_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem + dsp_fsk_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem + dsp_fsk_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem // initialize: - dsp_bell202_attr_init (&fsk1200_attr); // clear attributes structure - dsp_bell202_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate - dsp_bell202_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler + dsp_fsk_attr_init (&fsk1200_attr); // clear attributes structure + dsp_fsk_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate + dsp_fsk_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler // create context: - fsk1200_handle = dsp_bell202_create (&fsk1200_attr); + fsk1200_handle = dsp_fsk_create (&fsk1200_attr); // error check: if (fsk1200_handle == NULL) { - fprintf (stderr, "%s: can't dsp_bell202_create, errno %d (%s)\n", progname, errno, strerror (errno)); + fprintf (stderr, "%s: can't dsp_fsk_create, errno %d (%s)\n", progname, errno, strerror (errno)); exit (EXIT_FAILURE); } If you are decoding multiple channels, you will need multiple context structures; one per channel. -The attributes ("dsp_bell202_attr_t") do not have to be persistent, but the handle does. -There's even a "dsp_bell202_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. +The attributes ("dsp_fsk_attr_t") do not have to be persistent, but the handle does. +There's even a "dsp_fsk_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. Then, you need to feed samples into the software modem: - dsp_bell202_sample (fsk1200_handle, (double) sample / 32767.); + dsp_fsk_sample (fsk1200_handle, (double) sample / 32767.); It assumes the samples are between -1 and 1 as a double. From dce12e0eaa787dfde369ca621edc184c8d97fbd8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 4 Jun 2007 14:53:12 +0000 Subject: [PATCH 0409/1766] indent git-svn-id: http://svn.openzap.org/svn/openzap/trunk@205 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/g711.c | 84 ++- libs/openzap/src/hashtable.c | 160 ++--- libs/openzap/src/hashtable_itr.c | 98 +-- libs/openzap/src/include/g711.h | 615 +++++++++--------- libs/openzap/src/include/hashtable.h | 39 +- libs/openzap/src/include/hashtable_itr.h | 26 +- libs/openzap/src/include/hashtable_private.h | 20 +- libs/openzap/src/include/libteletone.h | 24 +- libs/openzap/src/include/libteletone_detect.h | 242 +++---- .../src/include/libteletone_generate.h | 192 +++--- libs/openzap/src/include/openzap.h | 21 +- libs/openzap/src/include/sangoma_tdm_api.h | 128 ++-- libs/openzap/src/include/zap_analog.h | 11 + libs/openzap/src/include/zap_isdn.h | 12 + libs/openzap/src/include/zap_skel.h | 11 + libs/openzap/src/include/zap_threadmutex.h | 12 + libs/openzap/src/include/zap_types.h | 20 +- libs/openzap/src/include/zap_wanpipe.h | 12 + libs/openzap/src/include/zap_zt.h | 11 + libs/openzap/src/libteletone_detect.c | 12 +- libs/openzap/src/priserver.c | 20 +- libs/openzap/src/sangoma_pri.c | 73 ++- libs/openzap/src/testanalog.c | 12 + libs/openzap/src/testapp.c | 11 + libs/openzap/src/testisdn.c | 11 + libs/openzap/src/zap_analog.c | 13 +- libs/openzap/src/zap_buffer.c | 10 +- libs/openzap/src/zap_io.c | 61 +- libs/openzap/src/zap_isdn.c | 11 + libs/openzap/src/zap_skel.c | 12 + libs/openzap/src/zap_threadmutex.c | 27 +- libs/openzap/src/zap_wanpipe.c | 13 + libs/openzap/src/zap_zt.c | 14 + 33 files changed, 1205 insertions(+), 833 deletions(-) diff --git a/libs/openzap/src/g711.c b/libs/openzap/src/g711.c index 8a5c58b835..97772c25f5 100644 --- a/libs/openzap/src/g711.c +++ b/libs/openzap/src/g711.c @@ -36,47 +36,47 @@ /* Copied from the CCITT G.711 specification */ static const uint8_t ulaw_to_alaw_table[256] = -{ - 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, - 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53, - 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26, - 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106, - 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120, - 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77, - 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93, - 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85, - 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, - 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181, - 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154, - 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234, - 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248, - 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205, - 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221, - 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213 -}; + { + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26, + 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106, + 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120, + 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77, + 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93, + 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154, + 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234, + 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248, + 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205, + 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221, + 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213 + }; /* These transcoding tables are copied from the CCITT G.711 specification. To achieve optimal results, do not change them. */ static const uint8_t alaw_to_ulaw_table[256] = -{ - 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, - 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52, - 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, - 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, - 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94, - 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109, - 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67, - 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81, - 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, - 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180, - 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133, - 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, - 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222, - 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237, - 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195, - 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209 -}; + { + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, + 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, + 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94, + 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109, + 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67, + 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133, + 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, + 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222, + 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237, + 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195, + 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209 + }; uint8_t alaw_to_ulaw(uint8_t alaw) { @@ -90,3 +90,15 @@ uint8_t ulaw_to_alaw(uint8_t ulaw) } /*- End of function --------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index fff5e99347..5cc2bb0c40 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -8,18 +8,18 @@ #include /* -Credit for primes table: Aaron Krowne - http://br.endernet.org/~akrowne/ - http://planetmath.org/encyclopedia/GoodHashTablePrimes.html + Credit for primes table: Aaron Krowne + http://br.endernet.org/~akrowne/ + http://planetmath.org/encyclopedia/GoodHashTablePrimes.html */ static const unsigned int primes[] = { -53, 97, 193, 389, -769, 1543, 3079, 6151, -12289, 24593, 49157, 98317, -196613, 393241, 786433, 1572869, -3145739, 6291469, 12582917, 25165843, -50331653, 100663319, 201326611, 402653189, -805306457, 1610612741 + 53, 97, 193, 389, + 769, 1543, 3079, 6151, + 12289, 24593, 49157, 98317, + 196613, 393241, 786433, 1572869, + 3145739, 6291469, 12582917, 25165843, + 50331653, 100663319, 201326611, 402653189, + 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); const float max_load_factor = 0.65f; @@ -81,45 +81,45 @@ hashtable_expand(struct hashtable *h) newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); if (NULL != newtable) - { - memset(newtable, 0, newsize * sizeof(struct entry *)); - /* This algorithm is not 'stable'. ie. it reverses the list - * when it transfers entries between the tables */ - for (i = 0; i < h->tablelength; i++) { - while (NULL != (e = h->table[i])) { - h->table[i] = e->next; - index = indexFor(newsize,e->h); - e->next = newtable[index]; - newtable[index] = e; - } - } - free(h->table); - h->table = newtable; - } + { + memset(newtable, 0, newsize * sizeof(struct entry *)); + /* This algorithm is not 'stable'. ie. it reverses the list + * when it transfers entries between the tables */ + for (i = 0; i < h->tablelength; i++) { + while (NULL != (e = h->table[i])) { + h->table[i] = e->next; + index = indexFor(newsize,e->h); + e->next = newtable[index]; + newtable[index] = e; + } + } + free(h->table); + h->table = newtable; + } /* Plan B: realloc instead */ else - { - newtable = (struct entry **) - realloc(h->table, newsize * sizeof(struct entry *)); - if (NULL == newtable) { (h->primeindex)--; return 0; } - h->table = newtable; - memset(newtable[h->tablelength], 0, newsize - h->tablelength); - for (i = 0; i < h->tablelength; i++) { - for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { - index = indexFor(newsize,e->h); - if (index == i) - { - pE = &(e->next); - } - else - { - *pE = e->next; - e->next = newtable[index]; - newtable[index] = e; - } - } - } - } + { + newtable = (struct entry **) + realloc(h->table, newsize * sizeof(struct entry *)); + if (NULL == newtable) { (h->primeindex)--; return 0; } + h->table = newtable; + memset(newtable[h->tablelength], 0, newsize - h->tablelength); + for (i = 0; i < h->tablelength; i++) { + for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { + index = indexFor(newsize,e->h); + if (index == i) + { + pE = &(e->next); + } + else + { + *pE = e->next; + e->next = newtable[index]; + newtable[index] = e; + } + } + } + } h->tablelength = newsize; h->loadlimit = (unsigned int) ceil(newsize * max_load_factor); return -1; @@ -140,13 +140,13 @@ hashtable_insert(struct hashtable *h, void *k, void *v) unsigned int index; struct entry *e; if (++(h->entrycount) > h->loadlimit) - { - /* Ignore the return value. If expand fails, we should - * still try cramming just this value into the existing table - * -- we may not have memory for a larger table, but one more - * element may be ok. Next time we insert, we'll try expanding again.*/ - hashtable_expand(h); - } + { + /* Ignore the return value. If expand fails, we should + * still try cramming just this value into the existing table + * -- we may not have memory for a larger table, but one more + * element may be ok. Next time we insert, we'll try expanding again.*/ + hashtable_expand(h); + } e = (struct entry *)malloc(sizeof(struct entry)); if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ e->h = hash(h,k); @@ -168,11 +168,11 @@ hashtable_search(struct hashtable *h, void *k) index = indexFor(h->tablelength,hashvalue); e = h->table[index]; while (NULL != e) - { - /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; - e = e->next; - } + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; + e = e->next; + } return NULL; } @@ -193,20 +193,20 @@ hashtable_remove(struct hashtable *h, void *k) pE = &(h->table[index]); e = *pE; while (NULL != e) - { - /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) - { - *pE = e->next; - h->entrycount--; - v = e->v; - freekey(e->k); - free(e); - return v; - } - pE = &(e->next); - e = e->next; - } + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + *pE = e->next; + h->entrycount--; + v = e->v; + freekey(e->k); + free(e); + return v; + } + pE = &(e->next); + e = e->next; + } return NULL; } @@ -261,4 +261,16 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values) * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c index defac691f0..a60965e911 100644 --- a/libs/openzap/src/hashtable_itr.c +++ b/libs/openzap/src/hashtable_itr.c @@ -23,14 +23,14 @@ hashtable_iterator(struct hashtable *h) if (0 == h->entrycount) return itr; for (i = 0; i < tablelength; i++) - { - if (NULL != h->table[i]) - { - itr->e = h->table[i]; - itr->index = i; - break; - } - } + { + if (NULL != h->table[i]) + { + itr->e = h->table[i]; + itr->index = i; + break; + } + } return itr; } @@ -48,28 +48,28 @@ hashtable_iterator_advance(struct hashtable_itr *itr) next = itr->e->next; if (NULL != next) - { - itr->parent = itr->e; - itr->e = next; - return -1; - } + { + itr->parent = itr->e; + itr->e = next; + return -1; + } tablelength = itr->h->tablelength; itr->parent = NULL; if (tablelength <= (j = ++(itr->index))) - { - itr->e = NULL; - return 0; - } + { + itr->e = NULL; + return 0; + } table = itr->h->table; while (NULL == (next = table[j])) - { - if (++j >= tablelength) - { - itr->index = tablelength; - itr->e = NULL; - return 0; - } - } + { + if (++j >= tablelength) + { + itr->index = tablelength; + itr->e = NULL; + return 0; + } + } itr->index = j; itr->e = next; return -1; @@ -91,10 +91,10 @@ hashtable_iterator_remove(struct hashtable_itr *itr) /* Do the removal */ if (NULL == (itr->parent)) - { - /* element is head of a chain */ - itr->h->table[itr->index] = itr->e->next; - } else { + { + /* element is head of a chain */ + itr->h->table[itr->index] = itr->e->next; + } else { /* element is mid-chain */ itr->parent->next = itr->e->next; } @@ -125,19 +125,19 @@ hashtable_iterator_search(struct hashtable_itr *itr, e = h->table[index]; parent = NULL; while (NULL != e) - { - /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) - { - itr->index = index; - itr->e = e; - itr->parent = parent; - itr->h = h; - return -1; - } - parent = e; - e = e->next; - } + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + itr->index = index; + itr->e = e; + itr->parent = parent; + itr->h = h; + return -1; + } + parent = e; + e = e->next; + } return 0; } @@ -173,4 +173,16 @@ hashtable_iterator_search(struct hashtable_itr *itr, * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/include/g711.h b/libs/openzap/src/include/g711.h index 8d1f6bf43a..2d7e481e48 100644 --- a/libs/openzap/src/include/g711.h +++ b/libs/openzap/src/include/g711.h @@ -18,25 +18,25 @@ /*! \file */ /*! \page g711_page A-law and mu-law handling -Lookup tables for A-law and u-law look attractive, until you consider the impact -on the CPU cache. If it causes a substantial area of your processor cache to get -hit too often, cache sloshing will severely slow things down. The main reason -these routines are slow in C, is the lack of direct access to the CPU's "find -the first 1" instruction. A little in-line assembler fixes that, and the -conversion routines can be faster than lookup tables, in most real world usage. -A "find the first 1" instruction is available on most modern CPUs, and is a -much underused feature. + Lookup tables for A-law and u-law look attractive, until you consider the impact + on the CPU cache. If it causes a substantial area of your processor cache to get + hit too often, cache sloshing will severely slow things down. The main reason + these routines are slow in C, is the lack of direct access to the CPU's "find + the first 1" instruction. A little in-line assembler fixes that, and the + conversion routines can be faster than lookup tables, in most real world usage. + A "find the first 1" instruction is available on most modern CPUs, and is a + much underused feature. -If an assembly language method of bit searching is not available, these routines -revert to a method that can be a little slow, so the cache thrashing might not -seem so bad :( + If an assembly language method of bit searching is not available, these routines + revert to a method that can be a little slow, so the cache thrashing might not + seem so bad :( -Feel free to submit patches to add fast "find the first 1" support for your own -favourite processor. + Feel free to submit patches to add fast "find the first 1" support for your own + favourite processor. -Look up tables are used for transcoding between A-law and u-law, since it is -difficult to achieve the precise transcoding procedure laid down in the G.711 -specification by other means. + Look up tables are used for transcoding between A-law and u-law, since it is + difficult to achieve the precise transcoding procedure laid down in the G.711 + specification by other means. */ #if !defined(_G711_H_) @@ -50,331 +50,331 @@ extern "C" { #ifndef __inline__ #define __inline__ __inline #endif -typedef unsigned __int8 uint8_t; -typedef __int16 int16_t; -typedef __int32 int32_t; -typedef unsigned __int16 uint16_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef unsigned __int16 uint16_t; #else #include #endif #if defined(__i386__) -/*! \brief Find the bit position of the highest set bit in a word - \param bits The word to be searched - \return The bit number of the highest set bit, or -1 if the word is zero. */ -static __inline__ int top_bit(unsigned int bits) -{ - int res; + /*! \brief Find the bit position of the highest set bit in a word + \param bits The word to be searched + \return The bit number of the highest set bit, or -1 if the word is zero. */ + static __inline__ int top_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movl $-1,%%edx;\n" - " bsrl %%eax,%%edx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsrl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Find the bit position of the lowest set bit in a word - \param bits The word to be searched - \return The bit number of the lowest set bit, or -1 if the word is zero. */ -static __inline__ int bottom_bit(unsigned int bits) -{ - int res; + /*! \brief Find the bit position of the lowest set bit in a word + \param bits The word to be searched + \return The bit number of the lowest set bit, or -1 if the word is zero. */ + static __inline__ int bottom_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movl $-1,%%edx;\n" - " bsfl %%eax,%%edx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsfl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ #elif defined(__x86_64__) -static __inline__ int top_bit(unsigned int bits) -{ - int res; + static __inline__ int top_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movq $-1,%%rdx;\n" - " bsrq %%rax,%%rdx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsrq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ -static __inline__ int bottom_bit(unsigned int bits) -{ - int res; + static __inline__ int bottom_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movq $-1,%%rdx;\n" - " bsfq %%rax,%%rdx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsfq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ #else -static __inline__ int top_bit(unsigned int bits) -{ - int i; + static __inline__ int top_bit(unsigned int bits) + { + int i; - if (bits == 0) - return -1; - i = 0; - if (bits & 0xFFFF0000) - { - bits &= 0xFFFF0000; - i += 16; - } - if (bits & 0xFF00FF00) - { - bits &= 0xFF00FF00; - i += 8; - } - if (bits & 0xF0F0F0F0) - { - bits &= 0xF0F0F0F0; - i += 4; - } - if (bits & 0xCCCCCCCC) - { - bits &= 0xCCCCCCCC; - i += 2; - } - if (bits & 0xAAAAAAAA) - { - bits &= 0xAAAAAAAA; - i += 1; - } - return i; -} -/*- End of function --------------------------------------------------------*/ + if (bits == 0) + return -1; + i = 0; + if (bits & 0xFFFF0000) + { + bits &= 0xFFFF0000; + i += 16; + } + if (bits & 0xFF00FF00) + { + bits &= 0xFF00FF00; + i += 8; + } + if (bits & 0xF0F0F0F0) + { + bits &= 0xF0F0F0F0; + i += 4; + } + if (bits & 0xCCCCCCCC) + { + bits &= 0xCCCCCCCC; + i += 2; + } + if (bits & 0xAAAAAAAA) + { + bits &= 0xAAAAAAAA; + i += 1; + } + return i; + } + /*- End of function --------------------------------------------------------*/ -static __inline__ int bottom_bit(unsigned int bits) -{ - int i; + static __inline__ int bottom_bit(unsigned int bits) + { + int i; - if (bits == 0) - return -1; - i = 32; - if (bits & 0x0000FFFF) - { - bits &= 0x0000FFFF; - i -= 16; - } - if (bits & 0x00FF00FF) - { - bits &= 0x00FF00FF; - i -= 8; - } - if (bits & 0x0F0F0F0F) - { - bits &= 0x0F0F0F0F; - i -= 4; - } - if (bits & 0x33333333) - { - bits &= 0x33333333; - i -= 2; - } - if (bits & 0x55555555) - { - bits &= 0x55555555; - i -= 1; - } - return i; -} -/*- End of function --------------------------------------------------------*/ + if (bits == 0) + return -1; + i = 32; + if (bits & 0x0000FFFF) + { + bits &= 0x0000FFFF; + i -= 16; + } + if (bits & 0x00FF00FF) + { + bits &= 0x00FF00FF; + i -= 8; + } + if (bits & 0x0F0F0F0F) + { + bits &= 0x0F0F0F0F; + i -= 4; + } + if (bits & 0x33333333) + { + bits &= 0x33333333; + i -= 2; + } + if (bits & 0x55555555) + { + bits &= 0x55555555; + i -= 1; + } + return i; + } + /*- End of function --------------------------------------------------------*/ #endif -/* N.B. It is tempting to use look-up tables for A-law and u-law conversion. - * However, you should consider the cache footprint. - * - * A 64K byte table for linear to x-law and a 512 byte table for x-law to - * linear sound like peanuts these days, and shouldn't an array lookup be - * real fast? No! When the cache sloshes as badly as this one will, a tight - * calculation may be better. The messiest part is normally finding the - * segment, but a little inline assembly can fix that on an i386, x86_64 and - * many other modern processors. - */ + /* N.B. It is tempting to use look-up tables for A-law and u-law conversion. + * However, you should consider the cache footprint. + * + * A 64K byte table for linear to x-law and a 512 byte table for x-law to + * linear sound like peanuts these days, and shouldn't an array lookup be + * real fast? No! When the cache sloshes as badly as this one will, a tight + * calculation may be better. The messiest part is normally finding the + * segment, but a little inline assembly can fix that on an i386, x86_64 and + * many other modern processors. + */ -/* - * Mu-law is basically as follows: - * - * Biased Linear Input Code Compressed Code - * ------------------------ --------------- - * 00000001wxyza 000wxyz - * 0000001wxyzab 001wxyz - * 000001wxyzabc 010wxyz - * 00001wxyzabcd 011wxyz - * 0001wxyzabcde 100wxyz - * 001wxyzabcdef 101wxyz - * 01wxyzabcdefg 110wxyz - * 1wxyzabcdefgh 111wxyz - * - * Each biased linear code has a leading 1 which identifies the segment - * number. The value of the segment number is equal to 7 minus the number - * of leading 0's. The quantization interval is directly available as the - * four bits wxyz. * The trailing bits (a - h) are ignored. - * - * Ordinarily the complement of the resulting code word is used for - * transmission, and so the code word is complemented before it is returned. - * - * For further information see John C. Bellamy's Digital Telephony, 1982, - * John Wiley & Sons, pps 98-111 and 472-476. - */ + /* + * Mu-law is basically as follows: + * + * Biased Linear Input Code Compressed Code + * ------------------------ --------------- + * 00000001wxyza 000wxyz + * 0000001wxyzab 001wxyz + * 000001wxyzabc 010wxyz + * 00001wxyzabcd 011wxyz + * 0001wxyzabcde 100wxyz + * 001wxyzabcdef 101wxyz + * 01wxyzabcdefg 110wxyz + * 1wxyzabcdefgh 111wxyz + * + * Each biased linear code has a leading 1 which identifies the segment + * number. The value of the segment number is equal to 7 minus the number + * of leading 0's. The quantization interval is directly available as the + * four bits wxyz. * The trailing bits (a - h) are ignored. + * + * Ordinarily the complement of the resulting code word is used for + * transmission, and so the code word is complemented before it is returned. + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ -/*#define ULAW_ZEROTRAP*/ /* turn on the trap as per the MIL-STD */ + /*#define ULAW_ZEROTRAP*/ /* turn on the trap as per the MIL-STD */ #define ULAW_BIAS 0x84 /* Bias for linear code. */ -/*! \brief Encode a linear sample to u-law - \param linear The sample to encode. - \return The u-law value. -*/ -static __inline__ uint8_t linear_to_ulaw(int linear) -{ - uint8_t u_val; - int mask; - int seg; + /*! \brief Encode a linear sample to u-law + \param linear The sample to encode. + \return The u-law value. + */ + static __inline__ uint8_t linear_to_ulaw(int linear) + { + uint8_t u_val; + int mask; + int seg; - /* Get the sign and the magnitude of the value. */ - if (linear < 0) - { - linear = ULAW_BIAS - linear; - mask = 0x7F; - } - else - { - linear = ULAW_BIAS + linear; - mask = 0xFF; - } + /* Get the sign and the magnitude of the value. */ + if (linear < 0) + { + linear = ULAW_BIAS - linear; + mask = 0x7F; + } + else + { + linear = ULAW_BIAS + linear; + mask = 0xFF; + } - seg = top_bit(linear | 0xFF) - 7; + seg = top_bit(linear | 0xFF) - 7; - /* - * Combine the sign, segment, quantization bits, - * and complement the code word. - */ - if (seg >= 8) - u_val = (uint8_t) (0x7F ^ mask); - else - u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); + /* + * Combine the sign, segment, quantization bits, + * and complement the code word. + */ + if (seg >= 8) + u_val = (uint8_t) (0x7F ^ mask); + else + u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); #ifdef ULAW_ZEROTRAP - /* Optional ITU trap */ - if (u_val == 0) - u_val = 0x02; + /* Optional ITU trap */ + if (u_val == 0) + u_val = 0x02; #endif - return u_val; -} -/*- End of function --------------------------------------------------------*/ + return u_val; + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Decode an u-law sample to a linear value. - \param ulaw The u-law sample to decode. - \return The linear value. -*/ -static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) -{ - int t; + /*! \brief Decode an u-law sample to a linear value. + \param ulaw The u-law sample to decode. + \return The linear value. + */ + static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) + { + int t; - /* Complement to obtain normal u-law value. */ - ulaw = ~ulaw; - /* - * Extract and bias the quantization bits. Then - * shift up by the segment number and subtract out the bias. - */ - t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); - return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); -} -/*- End of function --------------------------------------------------------*/ + /* Complement to obtain normal u-law value. */ + ulaw = ~ulaw; + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); + return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); + } + /*- End of function --------------------------------------------------------*/ -/* - * A-law is basically as follows: - * - * Linear Input Code Compressed Code - * ----------------- --------------- - * 0000000wxyza 000wxyz - * 0000001wxyza 001wxyz - * 000001wxyzab 010wxyz - * 00001wxyzabc 011wxyz - * 0001wxyzabcd 100wxyz - * 001wxyzabcde 101wxyz - * 01wxyzabcdef 110wxyz - * 1wxyzabcdefg 111wxyz - * - * For further information see John C. Bellamy's Digital Telephony, 1982, - * John Wiley & Sons, pps 98-111 and 472-476. - */ + /* + * A-law is basically as follows: + * + * Linear Input Code Compressed Code + * ----------------- --------------- + * 0000000wxyza 000wxyz + * 0000001wxyza 001wxyz + * 000001wxyzab 010wxyz + * 00001wxyzabc 011wxyz + * 0001wxyzabcd 100wxyz + * 001wxyzabcde 101wxyz + * 01wxyzabcdef 110wxyz + * 1wxyzabcdefg 111wxyz + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ #define ALAW_AMI_MASK 0x55 -/*! \brief Encode a linear sample to A-law - \param linear The sample to encode. - \return The A-law value. -*/ -static __inline__ uint8_t linear_to_alaw(int linear) -{ - int mask; - int seg; + /*! \brief Encode a linear sample to A-law + \param linear The sample to encode. + \return The A-law value. + */ + static __inline__ uint8_t linear_to_alaw(int linear) + { + int mask; + int seg; - if (linear >= 0) - { - /* Sign (bit 7) bit = 1 */ - mask = ALAW_AMI_MASK | 0x80; - } - else - { - /* Sign (bit 7) bit = 0 */ - mask = ALAW_AMI_MASK; - linear = -linear - 8; - } + if (linear >= 0) + { + /* Sign (bit 7) bit = 1 */ + mask = ALAW_AMI_MASK | 0x80; + } + else + { + /* Sign (bit 7) bit = 0 */ + mask = ALAW_AMI_MASK; + linear = -linear - 8; + } - /* Convert the scaled magnitude to segment number. */ - seg = top_bit(linear | 0xFF) - 7; - if (seg >= 8) - { - if (linear >= 0) - { - /* Out of range. Return maximum value. */ - return (uint8_t) (0x7F ^ mask); - } - /* We must be just a tiny step below zero */ - return (uint8_t) (0x00 ^ mask); - } - /* Combine the sign, segment, and quantization bits. */ - return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); -} -/*- End of function --------------------------------------------------------*/ + /* Convert the scaled magnitude to segment number. */ + seg = top_bit(linear | 0xFF) - 7; + if (seg >= 8) + { + if (linear >= 0) + { + /* Out of range. Return maximum value. */ + return (uint8_t) (0x7F ^ mask); + } + /* We must be just a tiny step below zero */ + return (uint8_t) (0x00 ^ mask); + } + /* Combine the sign, segment, and quantization bits. */ + return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Decode an A-law sample to a linear value. - \param alaw The A-law sample to decode. - \return The linear value. -*/ -static __inline__ int16_t alaw_to_linear(uint8_t alaw) -{ - int i; - int seg; + /*! \brief Decode an A-law sample to a linear value. + \param alaw The A-law sample to decode. + \return The linear value. + */ + static __inline__ int16_t alaw_to_linear(uint8_t alaw) + { + int i; + int seg; - alaw ^= ALAW_AMI_MASK; - i = ((alaw & 0x0F) << 4); - seg = (((int) alaw & 0x70) >> 4); - if (seg) - i = (i + 0x108) << (seg - 1); - else - i += 8; - return (int16_t) ((alaw & 0x80) ? i : -i); -} -/*- End of function --------------------------------------------------------*/ + alaw ^= ALAW_AMI_MASK; + i = ((alaw & 0x0F) << 4); + seg = (((int) alaw & 0x70) >> 4); + if (seg) + i = (i + 0x108) << (seg - 1); + else + i += 8; + return (int16_t) ((alaw & 0x80) ? i : -i); + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. - \param alaw The A-law sample to transcode. - \return The best matching u-law value. -*/ -uint8_t alaw_to_ulaw(uint8_t alaw); + /*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. + \param alaw The A-law sample to transcode. + \return The best matching u-law value. + */ + uint8_t alaw_to_ulaw(uint8_t alaw); -/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. - \param alaw The u-law sample to transcode. - \return The best matching A-law value. -*/ -uint8_t ulaw_to_alaw(uint8_t ulaw); + /*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. + \param alaw The u-law sample to transcode. + \return The best matching A-law value. + */ + uint8_t ulaw_to_alaw(uint8_t ulaw); #ifdef __cplusplus } @@ -382,3 +382,14 @@ uint8_t ulaw_to_alaw(uint8_t ulaw); #endif /*- End of file ------------------------------------------------------------*/ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index 4019a69ff9..4c3c48f4bf 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -103,11 +103,11 @@ create_hashtable(unsigned int minsize, int hashtable_insert(struct hashtable *h, void *k, void *v); -#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ -int fnname (struct hashtable *h, keytype *k, valuetype *v) \ -{ \ - return hashtable_insert(h,k,v); \ -} +#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ + int fnname (struct hashtable *h, keytype *k, valuetype *v) \ + { \ + return hashtable_insert(h,k,v); \ + } /***************************************************************************** * hashtable_search @@ -122,10 +122,10 @@ void * hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ -valuetype * fnname (struct hashtable *h, keytype *k) \ -{ \ - return (valuetype *) (hashtable_search(h,k)); \ -} + valuetype * fnname (struct hashtable *h, keytype *k) \ + { \ + return (valuetype *) (hashtable_search(h,k)); \ + } /***************************************************************************** * hashtable_remove @@ -140,10 +140,10 @@ void * /* returns value */ hashtable_remove(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ -valuetype * fnname (struct hashtable *h, keytype *k) \ -{ \ - return (valuetype *) (hashtable_remove(h,k)); \ -} + valuetype * fnname (struct hashtable *h, keytype *k) \ + { \ + return (valuetype *) (hashtable_remove(h,k)); \ + } /***************************************************************************** @@ -201,4 +201,15 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values); * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/include/hashtable_itr.h b/libs/openzap/src/include/hashtable_itr.h index aacf86825a..71c0d659ff 100644 --- a/libs/openzap/src/include/hashtable_itr.h +++ b/libs/openzap/src/include/hashtable_itr.h @@ -62,17 +62,17 @@ hashtable_iterator_remove(struct hashtable_itr *itr); /*****************************************************************************/ /* search - overwrite the supplied iterator, to point to the entry * matching the supplied key. - h points to the hashtable to be searched. + h points to the hashtable to be searched. * returns zero if not found. */ int hashtable_iterator_search(struct hashtable_itr *itr, struct hashtable *h, void *k); -#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ -int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ -{ \ - return (hashtable_iterator_search(i,h,k)); \ -} +#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ + int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ + { \ + return (hashtable_iterator_search(i,h,k)); \ + } @@ -109,4 +109,16 @@ int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index edf59efe18..ede652c654 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -37,10 +37,10 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) { /* Only works if tablelength == 2^N */ /*static inline unsigned int -indexFor(unsigned int tablelength, unsigned int hashvalue) -{ - return (hashvalue & (tablelength - 1u)); -} + indexFor(unsigned int tablelength, unsigned int hashvalue) + { + return (hashvalue & (tablelength - 1u)); + } */ /*****************************************************************************/ @@ -83,4 +83,14 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) * 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. -*/ + */ +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index aaf7b0ed47..e81ef5e90d 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -78,27 +78,27 @@ extern "C" { #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 -typedef double teletone_process_t; + typedef double teletone_process_t; -/*! \file libteletone.h - \brief Top level include file + /*! \file libteletone.h + \brief Top level include file - This file should be included by applications using the library -*/ + This file should be included by applications using the library + */ -/*! \brief An abstraction to store a tone mapping */ -typedef struct { - /*! An array of tone frequencies */ - teletone_process_t freqs[TELETONE_MAX_TONES]; -} teletone_tone_map_t; + /*! \brief An abstraction to store a tone mapping */ + typedef struct { + /*! An array of tone frequencies */ + teletone_process_t freqs[TELETONE_MAX_TONES]; + } teletone_tone_map_t; #if !defined(M_PI) -/* C99 systems may not define M_PI */ + /* C99 systems may not define M_PI */ #define M_PI 3.14159265358979323846264338327 #endif #ifdef _MSC_VER -typedef __int16 int16_t; + typedef __int16 int16_t; #endif #include diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index eda4e49514..15d5e9ddfb 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -98,11 +98,11 @@ extern "C" { #endif #include -/*! \file libteletone_detect.h - \brief Tone Detection Routines + /*! \file libteletone_detect.h + \brief Tone Detection Routines - This module is responsible for tone detection specifics -*/ + This module is responsible for tone detection specifics + */ #ifndef FALSE #define FALSE 0 @@ -111,17 +111,17 @@ extern "C" { #endif #endif -/* Basic DTMF specs: - * - * Minimum tone on = 40ms - * Minimum tone off = 50ms - * Maximum digit rate = 10 per second - * Normal twist <= 8dB accepted - * Reverse twist <= 4dB accepted - * S/N >= 15dB will detect OK - * Attenuation <= 26dB will detect OK - * Frequency tolerance +- 1.5% will detect, +-3.5% will reject - */ + /* Basic DTMF specs: + * + * Minimum tone on = 40ms + * Minimum tone off = 50ms + * Maximum digit rate = 10 per second + * Normal twist <= 8dB accepted + * Reverse twist <= 4dB accepted + * S/N >= 15dB will detect OK + * Attenuation <= 26dB will detect OK + * Frequency tolerance +- 1.5% will detect, +-3.5% will reject + */ #define DTMF_THRESHOLD 8.0e7 #define DTMF_NORMAL_TWIST 6.3 /* 8dB */ @@ -134,131 +134,131 @@ extern "C" { #define BLOCK_LEN 102 #define M_TWO_PI 2.0*M_PI -/*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ -typedef struct { - teletone_process_t v2; - teletone_process_t v3; - teletone_process_t fac; -} teletone_goertzel_state_t; + /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ + typedef struct { + teletone_process_t v2; + teletone_process_t v3; + teletone_process_t fac; + } teletone_goertzel_state_t; -/*! \brief A container for a DTMF detection state.*/ -typedef struct { - int hit1; - int hit2; - int hit3; - int hit4; - int mhit; + /*! \brief A container for a DTMF detection state.*/ + typedef struct { + int hit1; + int hit2; + int hit3; + int hit4; + int mhit; - teletone_goertzel_state_t row_out[GRID_FACTOR]; - teletone_goertzel_state_t col_out[GRID_FACTOR]; - teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; - teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; - teletone_process_t energy; + teletone_goertzel_state_t row_out[GRID_FACTOR]; + teletone_goertzel_state_t col_out[GRID_FACTOR]; + teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; + teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; + teletone_process_t energy; - int current_sample; - char digits[TELETONE_MAX_DTMF_DIGITS + 1]; - int current_digits; - int detected_digits; - int lost_digits; - int digit_hits[16]; -} teletone_dtmf_detect_state_t; + int current_sample; + char digits[TELETONE_MAX_DTMF_DIGITS + 1]; + int current_digits; + int detected_digits; + int lost_digits; + int digit_hits[16]; + } teletone_dtmf_detect_state_t; -/*! \brief An abstraction to store the coefficient of a tone frequency */ -typedef struct { - teletone_process_t fac; -} teletone_detection_descriptor_t; + /*! \brief An abstraction to store the coefficient of a tone frequency */ + typedef struct { + teletone_process_t fac; + } teletone_detection_descriptor_t; -/*! \brief A container for a single multi-tone detection -TELETONE_MAX_TONES dictates the maximum simultaneous tones that can be present -in a multi-tone representation. -*/ -typedef struct { - int sample_rate; + /*! \brief A container for a single multi-tone detection + TELETONE_MAX_TONES dictates the maximum simultaneous tones that can be present + in a multi-tone representation. + */ + typedef struct { + int sample_rate; - teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]; - teletone_goertzel_state_t gs[TELETONE_MAX_TONES]; - teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; - int tone_count; + teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; + int tone_count; - teletone_process_t energy; - int current_sample; + teletone_process_t energy; + int current_sample; - int min_samples; - int total_samples; + int min_samples; + int total_samples; - int positives; - int negatives; - int hits; + int positives; + int negatives; + int hits; - int positive_factor; - int negative_factor; - int hit_factor; + int positive_factor; + int negative_factor; + int hit_factor; -} teletone_multi_tone_t; + } teletone_multi_tone_t; -/*! - \brief Initilize a multi-frequency tone detector - \param mt the multi-frequency tone descriptor - \param map a representation of the multi-frequency tone -*/ -void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); + /*! + \brief Initilize a multi-frequency tone detector + \param mt the multi-frequency tone descriptor + \param map a representation of the multi-frequency tone + */ + void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); -/*! - \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt - \param mt the multi-frequency tone descriptor - \param sample_buffer an array aof 16 bit signed linear samples - \param samples the number of samples present in sample_buffer - \return true when the tone was detected or false when it is not -*/ -int teletone_multi_tone_detect (teletone_multi_tone_t *mt, - int16_t sample_buffer[], - int samples); + /*! + \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt + \param mt the multi-frequency tone descriptor + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when the tone was detected or false when it is not + */ + int teletone_multi_tone_detect (teletone_multi_tone_t *mt, + int16_t sample_buffer[], + int samples); -/*! - \brief Initilize a DTMF detection state object - \param dtmf_detect_state the DTMF detection state to initilize - \param sample_rate the desired sample rate -*/ -void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); + /*! + \brief Initilize a DTMF detection state object + \param dtmf_detect_state the DTMF detection state to initilize + \param sample_rate the desired sample rate + */ + void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); -/*! - \brief Check a sample buffer for the presence of DTMF digits - \param dtmf_detect_state the detection state object to check - \param sample_buffer an array aof 16 bit signed linear samples - \param samples the number of samples present in sample_buffer - \return true when DTMF was detected or false when it is not -*/ -int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, - int16_t sample_buffer[], - int samples); -/*! - \brief retrieve any collected digits into a string buffer - \param dtmf_detect_state the detection state object to check - \param buf the string buffer to write to - \param max the maximum length of buf - \return the number of characters written to buf -*/ -int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, - char *buf, - int max); - -/*! - \brief Step through the Goertzel Algorithm for each sample in a buffer - \param goertzel_state the goertzel state to step the samples through - \param sample_buffer an array aof 16 bit signed linear samples - \param samples the number of samples present in sample_buffer -*/ -void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + /*! + \brief Check a sample buffer for the presence of DTMF digits + \param dtmf_detect_state the detection state object to check + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when DTMF was detected or false when it is not + */ + int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples); + /*! + \brief retrieve any collected digits into a string buffer + \param dtmf_detect_state the detection state object to check + \param buf the string buffer to write to + \param max the maximum length of buf + \return the number of characters written to buf + */ + int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, + char *buf, + int max); -/*! - \brief Compute the result of the last applied step of the Goertzel Algorithm - \param goertzel_state the goertzel state to retrieve from - \return the computed value for consideration in furthur audio tests -*/ -teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); + /*! + \brief Step through the Goertzel Algorithm for each sample in a buffer + \param goertzel_state the goertzel state to step the samples through + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + */ + void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + int16_t sample_buffer[], + int samples); + + /*! + \brief Compute the result of the last applied step of the Goertzel Algorithm + \param goertzel_state the goertzel state to retrieve from + \return the computed value for consideration in furthur audio tests + */ + teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 3d625e8f52..e37778d278 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -89,113 +89,113 @@ extern "C" { -/*! \file libteletone_generate.h - \brief Tone Generation Routines + /*! \file libteletone_generate.h + \brief Tone Generation Routines - This module is responsible for tone generation specifics -*/ + This module is responsible for tone generation specifics + */ -typedef int16_t teletone_audio_t; -struct teletone_generation_session; -typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); + typedef int16_t teletone_audio_t; + struct teletone_generation_session; + typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); -/*! \brief An abstraction to store a tone generation session */ -struct teletone_generation_session { - /*! An array of tone mappings to character mappings */ - teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; - /*! The number of channels the output audio should be in */ - int channels; - /*! The Rate in hz of the output audio */ - int rate; - /*! The duration (in samples) of the output audio */ - int duration; - /*! The duration of silence to append after the initial audio is generated */ - int wait; - /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ - int tmp_duration; - /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ - int tmp_wait; - /*! Number of loops to repeat a single instruction*/ - int loops; - /*! Number of loops to repeat the entire set of instructions*/ - int LOOPS; - /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - int decay_factor; - /*! Direction to perform volume increase/decrease 1/-1*/ - int decay_direction; - /*! Number of samples between increase/decrease of volume */ - int decay_step; - /*! Volume factor of the tone */ - int volume; - /*! Debug on/off */ - int debug; - /*! FILE stream to write debug data to */ - FILE *debug_stream; - /*! Extra user data to attach to the session*/ - void *user_data; - /*! Buffer for storing sample data (dynamic) */ - teletone_audio_t *buffer; - /*! Size of the buffer */ - int datalen; - /*! In-Use size of the buffer */ - int samples; - /*! Callback function called during generation */ - int dynamic; - tone_handler handler; -}; + /*! \brief An abstraction to store a tone generation session */ + struct teletone_generation_session { + /*! An array of tone mappings to character mappings */ + teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; + /*! The number of channels the output audio should be in */ + int channels; + /*! The Rate in hz of the output audio */ + int rate; + /*! The duration (in samples) of the output audio */ + int duration; + /*! The duration of silence to append after the initial audio is generated */ + int wait; + /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ + int tmp_duration; + /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ + int tmp_wait; + /*! Number of loops to repeat a single instruction*/ + int loops; + /*! Number of loops to repeat the entire set of instructions*/ + int LOOPS; + /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ + int decay_factor; + /*! Direction to perform volume increase/decrease 1/-1*/ + int decay_direction; + /*! Number of samples between increase/decrease of volume */ + int decay_step; + /*! Volume factor of the tone */ + int volume; + /*! Debug on/off */ + int debug; + /*! FILE stream to write debug data to */ + FILE *debug_stream; + /*! Extra user data to attach to the session*/ + void *user_data; + /*! Buffer for storing sample data (dynamic) */ + teletone_audio_t *buffer; + /*! Size of the buffer */ + int datalen; + /*! In-Use size of the buffer */ + int samples; + /*! Callback function called during generation */ + int dynamic; + tone_handler handler; + }; -typedef struct teletone_generation_session teletone_generation_session_t; + typedef struct teletone_generation_session teletone_generation_session_t; -/*! - \brief Assign a set of tones to a tone_session indexed by a paticular index/character - \param ts the tone generation session - \param index the index to map the tone to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 -*/ -int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); + /*! + \brief Assign a set of tones to a tone_session indexed by a paticular index/character + \param ts the tone generation session + \param index the index to map the tone to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 + */ + int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); -/*! - \brief Assign a set of tones to a single tone map - \param map the map to assign the tones to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 -*/ -int teletone_set_map(teletone_tone_map_t *map, ...); + /*! + \brief Assign a set of tones to a single tone map + \param map the map to assign the tones to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 + */ + int teletone_set_map(teletone_tone_map_t *map, ...); -/*! - \brief Initilize a tone generation session - \param ts the tone generation session to initilize - \param buflen the size of the buffer(in samples) to dynamically allocate - \param handler a callback function to execute when a tone generation instruction is complete - \param user_data optional user data to send - \return 0 -*/ -int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + /*! + \brief Initilize a tone generation session + \param ts the tone generation session to initilize + \param buflen the size of the buffer(in samples) to dynamically allocate + \param handler a callback function to execute when a tone generation instruction is complete + \param user_data optional user data to send + \return 0 + */ + int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); -/*! - \brief Free the buffer allocated by a tone generation session - \param ts the tone generation session to destroy - \return 0 -*/ -int teletone_destroy_session(teletone_generation_session_t *ts); + /*! + \brief Free the buffer allocated by a tone generation session + \param ts the tone generation session to destroy + \return 0 + */ + int teletone_destroy_session(teletone_generation_session_t *ts); -/*! - \brief Execute a single tone generation instruction - \param ts the tone generation session to consult for parameters - \param map the tone mapping to use for the frequencies - \return 0 -*/ -int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); + /*! + \brief Execute a single tone generation instruction + \param ts the tone generation session to consult for parameters + \param map the tone mapping to use for the frequencies + \return 0 + */ + int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); -/*! - \brief Execute a tone generation script and call callbacks after each instruction - \param ts the tone generation session to execute on - \param cmd the script to execute - \return 0 -*/ -int teletone_run(teletone_generation_session_t *ts, char *cmd); + /*! + \brief Execute a tone generation script and call callbacks after each instruction + \param ts the tone generation session to execute on + \param cmd the script to execute + \return 0 + */ + int teletone_run(teletone_generation_session_t *ts, char *cmd); #ifdef __cplusplus } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 1fdb372087..53d2106d99 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -189,8 +189,8 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); -#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex);\ - zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s));\ +#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); \ + zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ zap_channel_set_state(obj, s); @@ -235,6 +235,8 @@ struct zap_caller_data { struct zap_channel { uint32_t span_id; uint32_t chan_id; + uint32_t physical_span_id; + uint32_t physical_chan_id; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; @@ -263,11 +265,11 @@ struct zap_channel { char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; uint8_t needed_tones[ZAP_TONEMAP_INVALID]; uint8_t detected_tones[ZAP_TONEMAP_INVALID]; - zap_tonemap_t last_detected_tone; - + zap_tonemap_t last_detected_tone; uint32_t token_count; char chan_name[128]; char chan_number[32]; + zap_filehandle_t fds[2]; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -384,3 +386,14 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #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 expandtab: + */ diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index a9ef56add4..d4e673cc5e 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -43,10 +43,10 @@ struct iphdr { #if defined(__LITTLE_ENDIAN_BITFIELD) unsigned ihl:4, - version:4; + version:4; #elif defined (__BIG_ENDIAN_BITFIELD) unsigned version:4, - ihl:4; + ihl:4; #else # error "unknown byteorder!" #endif @@ -108,15 +108,15 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); if (DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ return 1; } @@ -176,15 +176,15 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) wan_udp.wan_udphdr_data_len = 0; DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ); + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ); if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ /* somone already has this channel, or somthing else is not right. */ @@ -230,21 +230,21 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) api_poll.timeout = timeout; if (!DeviceIoControl( - fd, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)&api_poll, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL)) { + 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; @@ -253,7 +253,7 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) default: return -1; - } + } if (api_poll.poll_events_bitmap == 0){ return -1; @@ -309,15 +309,15 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen } if (!DeviceIoControl( - fd, - IoctlReadCommand, - (LPVOID)NULL, - 0L, - (LPVOID)&rx_data, - sizeof(RX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - )){ + fd, + IoctlReadCommand, + (LPVOID)NULL, + 0L, + (LPVOID)&rx_data, + sizeof(RX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + )){ return -1; } @@ -327,18 +327,18 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen 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){ + { + 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; } - memcpy(databuf, rx_data.data, pri->data_length); - rx_len = pri->data_length; - break; - - default: - break; - } #else struct msghdr msg; @@ -386,15 +386,15 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle 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 - )){ + 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; } @@ -425,3 +425,15 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle } #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 expandtab: + */ + diff --git a/libs/openzap/src/include/zap_analog.h b/libs/openzap/src/include/zap_analog.h index 82badfcea9..5322463577 100644 --- a/libs/openzap/src/include/zap_analog.h +++ b/libs/openzap/src/include/zap_analog.h @@ -46,3 +46,14 @@ zap_status_t zap_analog_start(zap_span_t *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); #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 expandtab: + */ diff --git a/libs/openzap/src/include/zap_isdn.h b/libs/openzap/src/include/zap_isdn.h index 7117304a03..0aea34973d 100644 --- a/libs/openzap/src/include/zap_isdn.h +++ b/libs/openzap/src/include/zap_isdn.h @@ -47,3 +47,15 @@ zap_status_t zap_isdn_init(void); zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb); #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 expandtab: + */ + diff --git a/libs/openzap/src/include/zap_skel.h b/libs/openzap/src/include/zap_skel.h index 9fdaadf7b5..a8a245837f 100644 --- a/libs/openzap/src/include/zap_skel.h +++ b/libs/openzap/src/include/zap_skel.h @@ -39,3 +39,14 @@ zap_status_t skel_init(zap_software_interface_t **zint); zap_status_t skel_destroy(void); #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 expandtab: + */ diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index 557f23ea51..1a9061429e 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -37,3 +37,15 @@ zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); #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 expandtab: + */ + diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 3bd99d3b0d..607fa03366 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -41,10 +41,12 @@ typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef __int32 int32_t; typedef intptr_t zap_ssize_t; +typedef int zap_filehandle_t; #else #include typedef int zap_socket_t; typedef ssize_t zap_ssize_t; +typedef int zap_filehandle_t; #endif typedef size_t zap_size_t; @@ -167,8 +169,8 @@ typedef enum { ZAP_COMMAND_GET_CODEC, ZAP_COMMAND_SET_NATIVE_CODEC, ZAP_COMMAND_GET_NATIVE_CODEC, - ZAP_COMMAND_ENABLE_TONE_DETECT, - ZAP_COMMAND_DISABLE_TONE_DETECT, + 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, @@ -180,6 +182,8 @@ typedef enum { ZAP_COMMAND_ONHOOK, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, ZAP_COMMAND_DISABLE_PROGRESS_DETECT, + ZAP_COMMAND_TRACE_INPUT, + ZAP_COMMAND_TRACE_OUTPUT, ZAP_COMMAND_COUNT } zap_command_t; @@ -322,3 +326,15 @@ typedef struct hashtable_itr zap_hash_itr_t; typedef struct key zap_hash_key_t; typedef struct value zap_hash_val_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 expandtab: + */ + diff --git a/libs/openzap/src/include/zap_wanpipe.h b/libs/openzap/src/include/zap_wanpipe.h index fa78f41f74..0b2f4a9c48 100644 --- a/libs/openzap/src/include/zap_wanpipe.h +++ b/libs/openzap/src/include/zap_wanpipe.h @@ -39,3 +39,15 @@ zap_status_t wanpipe_init(zap_io_interface_t **zint); zap_status_t wanpipe_destroy(void); #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 expandtab: + */ + diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 1ad2e65c20..9f3287f6a4 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -229,3 +229,14 @@ zap_status_t zt_init(zap_io_interface_t **zint); zap_status_t zt_destroy(void); #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 expandtab: + */ diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 8df7d569a4..1af9b8fc43 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -208,8 +208,8 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } int teletone_multi_tone_detect (teletone_multi_tone_t *mt, - int16_t sample_buffer[], - int samples) + int16_t sample_buffer[], + int samples) { int sample, limit, j, x = 0; teletone_process_t v1, famp; @@ -295,8 +295,8 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, - int16_t sample_buffer[], - int samples) + int16_t sample_buffer[], + int samples) { teletone_process_t row_energy[GRID_FACTOR]; teletone_process_t col_energy[GRID_FACTOR]; @@ -426,8 +426,8 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, - char *buf, - int max) + char *buf, + int max) { if (max > dtmf_detect_state->current_digits) { max = dtmf_detect_state->current_digits; diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c index 5612e19a15..9126a186af 100644 --- a/libs/openzap/src/priserver.c +++ b/libs/openzap/src/priserver.c @@ -137,11 +137,11 @@ static void launch_channel(struct sangoma_pri *spri, int channo) if (!lead && loops == 300) { #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, dtmf) != ZAP_SUCCESS) { - printf("Critical Error: Failed to send dtmf\n"); - zap_channel_close(&chan); - exit(-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 } @@ -314,3 +314,13 @@ int main(int argc, char *argv[]) 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 expandtab: + */ diff --git a/libs/openzap/src/sangoma_pri.c b/libs/openzap/src/sangoma_pri.c index b4692216d0..865fe4f476 100644 --- a/libs/openzap/src/sangoma_pri.c +++ b/libs/openzap/src/sangoma_pri.c @@ -23,39 +23,39 @@ 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; + 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(); + /** + ** 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; + Sec = Ticks/1000; + Usec = (Ticks - (Sec*1000))*1000; + tp->tv_sec = Sec; + tp->tv_usec = Usec; #endif /* WITHOUT_MM_LIB */ - (void)nothing; - return 0; + (void)nothing; + return 0; } #endif /* WIN32 */ #endif /* HAVE_GETTIMEOFDAY */ @@ -166,7 +166,7 @@ int sangoma_one_loop(struct sangoma_pri *spri) FD_ZERO(&efds); #ifdef _MSC_VER -//Windows macro for FD_SET includes a warning C4127: conditional expression is constant + //Windows macro for FD_SET includes a warning C4127: conditional expression is constant #pragma warning(push) #pragma warning(disable:4127) #endif @@ -238,3 +238,14 @@ int sangoma_run_pri(struct sangoma_pri *spri) } +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index e1f17d23fd..cd480e2ba5 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -100,3 +100,15 @@ int main(int argc, char *argv[]) zap_global_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 expandtab: + */ + diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 12b22b30b3..4f00ca600b 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -72,3 +72,14 @@ int main(int argc, char *argv[]) zap_global_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 expandtab: + */ diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index d268436eb5..93af26f752 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -41,3 +41,14 @@ int main(int argc, char *argv[]) zap_global_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 expandtab: + */ diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index ada2ca804e..e8944f2db6 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -135,7 +135,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); goto done; } @@ -483,6 +483,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + /*zap_channel_command(event->channel, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");*/ sig.event_id = ZAP_SIGEVENT_START; zap_set_string(event->channel->caller_data.dnis, event->channel->chan_number); data->sig_cb(&sig); @@ -585,3 +586,13 @@ zap_status_t zap_analog_start(zap_span_t *span) return zap_thread_create_detached(zap_analog_run, 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 expandtab: + */ diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index d4edbe6e29..1db918665d 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -197,11 +197,11 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d freespace = buffer->datalen - buffer->used; /* - if (buffer->data != buffer->head) { - memmove(buffer->data, buffer->head, buffer->used); - buffer->head = buffer->data; - } - */ + 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; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3877d5213d..bec1c5a1e8 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -332,6 +332,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; + new_chan->fds[0] = -1; + new_chan->fds[1] = -1; zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -689,12 +691,18 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) zap_status_t zap_channel_done(zap_channel_t *zchan) { + int i; assert(zchan != NULL); memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); - + for (i = 0; i < 2; i++) { + if (zchan->fds[i] > -1) { + close(zchan->fds[i]); + zchan->fds[i] = -1; + } + } return ZAP_SUCCESS; } @@ -780,6 +788,36 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_mutex_lock(zchan->mutex); switch(command) { + case ZAP_COMMAND_TRACE_INPUT: + { + char *path = (char *) obj; + if (zchan->fds[0] > 0) { + close(zchan->fds[0]); + zchan->fds[0] = -1; + } + if ((zchan->fds[0] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + GOTO_STATUS(done, ZAP_SUCCESS); + } + + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, ZAP_FAIL); + } + break; + case ZAP_COMMAND_TRACE_OUTPUT: + { + char *path = (char *) obj; + if (zchan->fds[1] > 0) { + close(zchan->fds[0]); + zchan->fds[1] = -1; + } + if ((zchan->fds[1] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + GOTO_STATUS(done, ZAP_SUCCESS); + } + + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, ZAP_FAIL); + } + break; case ZAP_COMMAND_SET_INTERVAL: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { @@ -863,7 +901,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo GOTO_STATUS(done, ZAP_SUCCESS); } break; - case ZAP_COMMAND_ENABLE_TONE_DETECT: + case ZAP_COMMAND_ENABLE_DTMF_DETECT: { /* if they don't have thier own, use ours */ if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { @@ -880,7 +918,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } break; - case ZAP_COMMAND_DISABLE_TONE_DETECT: + case ZAP_COMMAND_DISABLE_DTMF_DETECT: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; @@ -1216,6 +1254,9 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } status = zchan->zio->read(zchan, data, datalen); + if (zchan->fds[0]) { + write(zchan->fds[0], data, *datalen); + } if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { @@ -1391,6 +1432,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } + if (zchan->fds[1]) { + write(zchan->fds[1], data, *datalen); + } + status = zchan->zio->write(zchan, data, datalen); return status; @@ -1731,3 +1776,13 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) } +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index a8e7281460..76ad83ca25 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -250,3 +250,14 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index 4341309649..c5e9a0e85d 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -108,3 +108,15 @@ zap_status_t skel_destroy(void) { return ZAP_FAIL; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 34e23bec5c..e82d6a3937 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -119,15 +119,15 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat status = ZAP_SUCCESS; goto done; -failpthread: + failpthread: pthread_attr_destroy(&thread->attribute); #endif -fail: + fail: if (thread) { free(thread); } -done: + done: return status; } @@ -157,16 +157,16 @@ zap_status_t zap_mutex_create(zap_mutex_t **mutex) goto success; -fail: - pthread_mutexattr_destroy(&attr); - goto done; + fail: + pthread_mutexattr_destroy(&attr); + goto done; -success: + success: #endif *mutex = check; status = ZAP_SUCCESS; -done: + done: return status; } @@ -217,3 +217,14 @@ zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) #endif return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index de3da19d59..3e9e7501de 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -72,6 +72,8 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + chan->physical_span_id = spanno; + chan->physical_chan_id = x; if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; @@ -532,3 +534,14 @@ zap_status_t wanpipe_destroy(void) memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index bafc191117..49d9edea60 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -90,6 +90,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + chan->physical_span_id = ztp.span_no; + chan->physical_chan_id = ztp.chan_no; + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { if (ztp.g711_type == ZT_G711_ALAW) { chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; @@ -559,3 +562,14 @@ zap_status_t zt_destroy(void) memset(&zt_interface, 0, sizeof(zt_interface)); return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ From 68d431bab12c2373934d45f8298a9fa0069cd5d3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 4 Jun 2007 14:53:12 +0000 Subject: [PATCH 0410/1766] indent git-svn-id: http://svn.openzap.org/svn/openzap/trunk@205 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/g711.c | 84 ++- libs/freetdm/src/hashtable.c | 160 ++--- libs/freetdm/src/hashtable_itr.c | 98 +-- libs/freetdm/src/include/g711.h | 615 +++++++++--------- libs/freetdm/src/include/hashtable.h | 39 +- libs/freetdm/src/include/hashtable_itr.h | 26 +- libs/freetdm/src/include/hashtable_private.h | 20 +- libs/freetdm/src/include/libteletone.h | 24 +- libs/freetdm/src/include/libteletone_detect.h | 242 +++---- .../src/include/libteletone_generate.h | 192 +++--- libs/freetdm/src/include/openzap.h | 21 +- libs/freetdm/src/include/sangoma_tdm_api.h | 128 ++-- libs/freetdm/src/include/zap_analog.h | 11 + libs/freetdm/src/include/zap_isdn.h | 12 + libs/freetdm/src/include/zap_skel.h | 11 + libs/freetdm/src/include/zap_threadmutex.h | 12 + libs/freetdm/src/include/zap_types.h | 20 +- libs/freetdm/src/include/zap_wanpipe.h | 12 + libs/freetdm/src/include/zap_zt.h | 11 + libs/freetdm/src/libteletone_detect.c | 12 +- libs/freetdm/src/priserver.c | 20 +- libs/freetdm/src/sangoma_pri.c | 73 ++- libs/freetdm/src/testanalog.c | 12 + libs/freetdm/src/testapp.c | 11 + libs/freetdm/src/testisdn.c | 11 + libs/freetdm/src/zap_analog.c | 13 +- libs/freetdm/src/zap_buffer.c | 10 +- libs/freetdm/src/zap_io.c | 61 +- libs/freetdm/src/zap_isdn.c | 11 + libs/freetdm/src/zap_skel.c | 12 + libs/freetdm/src/zap_threadmutex.c | 27 +- libs/freetdm/src/zap_wanpipe.c | 13 + libs/freetdm/src/zap_zt.c | 14 + 33 files changed, 1205 insertions(+), 833 deletions(-) diff --git a/libs/freetdm/src/g711.c b/libs/freetdm/src/g711.c index 8a5c58b835..97772c25f5 100644 --- a/libs/freetdm/src/g711.c +++ b/libs/freetdm/src/g711.c @@ -36,47 +36,47 @@ /* Copied from the CCITT G.711 specification */ static const uint8_t ulaw_to_alaw_table[256] = -{ - 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, - 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53, - 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26, - 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106, - 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120, - 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77, - 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93, - 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85, - 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, - 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181, - 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154, - 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234, - 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248, - 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205, - 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221, - 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213 -}; + { + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26, + 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106, + 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120, + 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77, + 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93, + 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154, + 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234, + 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248, + 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205, + 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221, + 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213 + }; /* These transcoding tables are copied from the CCITT G.711 specification. To achieve optimal results, do not change them. */ static const uint8_t alaw_to_ulaw_table[256] = -{ - 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, - 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52, - 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, - 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, - 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94, - 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109, - 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67, - 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81, - 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, - 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180, - 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133, - 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, - 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222, - 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237, - 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195, - 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209 -}; + { + 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, + 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52, + 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, + 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, + 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94, + 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109, + 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67, + 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81, + 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165, + 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180, + 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133, + 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, + 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222, + 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237, + 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195, + 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209 + }; uint8_t alaw_to_ulaw(uint8_t alaw) { @@ -90,3 +90,15 @@ uint8_t ulaw_to_alaw(uint8_t ulaw) } /*- End of function --------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index fff5e99347..5cc2bb0c40 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -8,18 +8,18 @@ #include /* -Credit for primes table: Aaron Krowne - http://br.endernet.org/~akrowne/ - http://planetmath.org/encyclopedia/GoodHashTablePrimes.html + Credit for primes table: Aaron Krowne + http://br.endernet.org/~akrowne/ + http://planetmath.org/encyclopedia/GoodHashTablePrimes.html */ static const unsigned int primes[] = { -53, 97, 193, 389, -769, 1543, 3079, 6151, -12289, 24593, 49157, 98317, -196613, 393241, 786433, 1572869, -3145739, 6291469, 12582917, 25165843, -50331653, 100663319, 201326611, 402653189, -805306457, 1610612741 + 53, 97, 193, 389, + 769, 1543, 3079, 6151, + 12289, 24593, 49157, 98317, + 196613, 393241, 786433, 1572869, + 3145739, 6291469, 12582917, 25165843, + 50331653, 100663319, 201326611, 402653189, + 805306457, 1610612741 }; const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); const float max_load_factor = 0.65f; @@ -81,45 +81,45 @@ hashtable_expand(struct hashtable *h) newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); if (NULL != newtable) - { - memset(newtable, 0, newsize * sizeof(struct entry *)); - /* This algorithm is not 'stable'. ie. it reverses the list - * when it transfers entries between the tables */ - for (i = 0; i < h->tablelength; i++) { - while (NULL != (e = h->table[i])) { - h->table[i] = e->next; - index = indexFor(newsize,e->h); - e->next = newtable[index]; - newtable[index] = e; - } - } - free(h->table); - h->table = newtable; - } + { + memset(newtable, 0, newsize * sizeof(struct entry *)); + /* This algorithm is not 'stable'. ie. it reverses the list + * when it transfers entries between the tables */ + for (i = 0; i < h->tablelength; i++) { + while (NULL != (e = h->table[i])) { + h->table[i] = e->next; + index = indexFor(newsize,e->h); + e->next = newtable[index]; + newtable[index] = e; + } + } + free(h->table); + h->table = newtable; + } /* Plan B: realloc instead */ else - { - newtable = (struct entry **) - realloc(h->table, newsize * sizeof(struct entry *)); - if (NULL == newtable) { (h->primeindex)--; return 0; } - h->table = newtable; - memset(newtable[h->tablelength], 0, newsize - h->tablelength); - for (i = 0; i < h->tablelength; i++) { - for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { - index = indexFor(newsize,e->h); - if (index == i) - { - pE = &(e->next); - } - else - { - *pE = e->next; - e->next = newtable[index]; - newtable[index] = e; - } - } - } - } + { + newtable = (struct entry **) + realloc(h->table, newsize * sizeof(struct entry *)); + if (NULL == newtable) { (h->primeindex)--; return 0; } + h->table = newtable; + memset(newtable[h->tablelength], 0, newsize - h->tablelength); + for (i = 0; i < h->tablelength; i++) { + for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) { + index = indexFor(newsize,e->h); + if (index == i) + { + pE = &(e->next); + } + else + { + *pE = e->next; + e->next = newtable[index]; + newtable[index] = e; + } + } + } + } h->tablelength = newsize; h->loadlimit = (unsigned int) ceil(newsize * max_load_factor); return -1; @@ -140,13 +140,13 @@ hashtable_insert(struct hashtable *h, void *k, void *v) unsigned int index; struct entry *e; if (++(h->entrycount) > h->loadlimit) - { - /* Ignore the return value. If expand fails, we should - * still try cramming just this value into the existing table - * -- we may not have memory for a larger table, but one more - * element may be ok. Next time we insert, we'll try expanding again.*/ - hashtable_expand(h); - } + { + /* Ignore the return value. If expand fails, we should + * still try cramming just this value into the existing table + * -- we may not have memory for a larger table, but one more + * element may be ok. Next time we insert, we'll try expanding again.*/ + hashtable_expand(h); + } e = (struct entry *)malloc(sizeof(struct entry)); if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ e->h = hash(h,k); @@ -168,11 +168,11 @@ hashtable_search(struct hashtable *h, void *k) index = indexFor(h->tablelength,hashvalue); e = h->table[index]; while (NULL != e) - { - /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; - e = e->next; - } + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; + e = e->next; + } return NULL; } @@ -193,20 +193,20 @@ hashtable_remove(struct hashtable *h, void *k) pE = &(h->table[index]); e = *pE; while (NULL != e) - { - /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) - { - *pE = e->next; - h->entrycount--; - v = e->v; - freekey(e->k); - free(e); - return v; - } - pE = &(e->next); - e = e->next; - } + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + *pE = e->next; + h->entrycount--; + v = e->v; + freekey(e->k); + free(e); + return v; + } + pE = &(e->next); + e = e->next; + } return NULL; } @@ -261,4 +261,16 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values) * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index defac691f0..a60965e911 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -23,14 +23,14 @@ hashtable_iterator(struct hashtable *h) if (0 == h->entrycount) return itr; for (i = 0; i < tablelength; i++) - { - if (NULL != h->table[i]) - { - itr->e = h->table[i]; - itr->index = i; - break; - } - } + { + if (NULL != h->table[i]) + { + itr->e = h->table[i]; + itr->index = i; + break; + } + } return itr; } @@ -48,28 +48,28 @@ hashtable_iterator_advance(struct hashtable_itr *itr) next = itr->e->next; if (NULL != next) - { - itr->parent = itr->e; - itr->e = next; - return -1; - } + { + itr->parent = itr->e; + itr->e = next; + return -1; + } tablelength = itr->h->tablelength; itr->parent = NULL; if (tablelength <= (j = ++(itr->index))) - { - itr->e = NULL; - return 0; - } + { + itr->e = NULL; + return 0; + } table = itr->h->table; while (NULL == (next = table[j])) - { - if (++j >= tablelength) - { - itr->index = tablelength; - itr->e = NULL; - return 0; - } - } + { + if (++j >= tablelength) + { + itr->index = tablelength; + itr->e = NULL; + return 0; + } + } itr->index = j; itr->e = next; return -1; @@ -91,10 +91,10 @@ hashtable_iterator_remove(struct hashtable_itr *itr) /* Do the removal */ if (NULL == (itr->parent)) - { - /* element is head of a chain */ - itr->h->table[itr->index] = itr->e->next; - } else { + { + /* element is head of a chain */ + itr->h->table[itr->index] = itr->e->next; + } else { /* element is mid-chain */ itr->parent->next = itr->e->next; } @@ -125,19 +125,19 @@ hashtable_iterator_search(struct hashtable_itr *itr, e = h->table[index]; parent = NULL; while (NULL != e) - { - /* Check hash value to short circuit heavier comparison */ - if ((hashvalue == e->h) && (h->eqfn(k, e->k))) - { - itr->index = index; - itr->e = e; - itr->parent = parent; - itr->h = h; - return -1; - } - parent = e; - e = e->next; - } + { + /* Check hash value to short circuit heavier comparison */ + if ((hashvalue == e->h) && (h->eqfn(k, e->k))) + { + itr->index = index; + itr->e = e; + itr->parent = parent; + itr->h = h; + return -1; + } + parent = e; + e = e->next; + } return 0; } @@ -173,4 +173,16 @@ hashtable_iterator_search(struct hashtable_itr *itr, * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/include/g711.h b/libs/freetdm/src/include/g711.h index 8d1f6bf43a..2d7e481e48 100644 --- a/libs/freetdm/src/include/g711.h +++ b/libs/freetdm/src/include/g711.h @@ -18,25 +18,25 @@ /*! \file */ /*! \page g711_page A-law and mu-law handling -Lookup tables for A-law and u-law look attractive, until you consider the impact -on the CPU cache. If it causes a substantial area of your processor cache to get -hit too often, cache sloshing will severely slow things down. The main reason -these routines are slow in C, is the lack of direct access to the CPU's "find -the first 1" instruction. A little in-line assembler fixes that, and the -conversion routines can be faster than lookup tables, in most real world usage. -A "find the first 1" instruction is available on most modern CPUs, and is a -much underused feature. + Lookup tables for A-law and u-law look attractive, until you consider the impact + on the CPU cache. If it causes a substantial area of your processor cache to get + hit too often, cache sloshing will severely slow things down. The main reason + these routines are slow in C, is the lack of direct access to the CPU's "find + the first 1" instruction. A little in-line assembler fixes that, and the + conversion routines can be faster than lookup tables, in most real world usage. + A "find the first 1" instruction is available on most modern CPUs, and is a + much underused feature. -If an assembly language method of bit searching is not available, these routines -revert to a method that can be a little slow, so the cache thrashing might not -seem so bad :( + If an assembly language method of bit searching is not available, these routines + revert to a method that can be a little slow, so the cache thrashing might not + seem so bad :( -Feel free to submit patches to add fast "find the first 1" support for your own -favourite processor. + Feel free to submit patches to add fast "find the first 1" support for your own + favourite processor. -Look up tables are used for transcoding between A-law and u-law, since it is -difficult to achieve the precise transcoding procedure laid down in the G.711 -specification by other means. + Look up tables are used for transcoding between A-law and u-law, since it is + difficult to achieve the precise transcoding procedure laid down in the G.711 + specification by other means. */ #if !defined(_G711_H_) @@ -50,331 +50,331 @@ extern "C" { #ifndef __inline__ #define __inline__ __inline #endif -typedef unsigned __int8 uint8_t; -typedef __int16 int16_t; -typedef __int32 int32_t; -typedef unsigned __int16 uint16_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef unsigned __int16 uint16_t; #else #include #endif #if defined(__i386__) -/*! \brief Find the bit position of the highest set bit in a word - \param bits The word to be searched - \return The bit number of the highest set bit, or -1 if the word is zero. */ -static __inline__ int top_bit(unsigned int bits) -{ - int res; + /*! \brief Find the bit position of the highest set bit in a word + \param bits The word to be searched + \return The bit number of the highest set bit, or -1 if the word is zero. */ + static __inline__ int top_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movl $-1,%%edx;\n" - " bsrl %%eax,%%edx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsrl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Find the bit position of the lowest set bit in a word - \param bits The word to be searched - \return The bit number of the lowest set bit, or -1 if the word is zero. */ -static __inline__ int bottom_bit(unsigned int bits) -{ - int res; + /*! \brief Find the bit position of the lowest set bit in a word + \param bits The word to be searched + \return The bit number of the lowest set bit, or -1 if the word is zero. */ + static __inline__ int bottom_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movl $-1,%%edx;\n" - " bsfl %%eax,%%edx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movl $-1,%%edx;\n" + " bsfl %%eax,%%edx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ #elif defined(__x86_64__) -static __inline__ int top_bit(unsigned int bits) -{ - int res; + static __inline__ int top_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movq $-1,%%rdx;\n" - " bsrq %%rax,%%rdx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsrq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ -static __inline__ int bottom_bit(unsigned int bits) -{ - int res; + static __inline__ int bottom_bit(unsigned int bits) + { + int res; - __asm__ __volatile__(" movq $-1,%%rdx;\n" - " bsfq %%rax,%%rdx;\n" - : "=d" (res) - : "a" (bits)); - return res; -} -/*- End of function --------------------------------------------------------*/ + __asm__ __volatile__(" movq $-1,%%rdx;\n" + " bsfq %%rax,%%rdx;\n" + : "=d" (res) + : "a" (bits)); + return res; + } + /*- End of function --------------------------------------------------------*/ #else -static __inline__ int top_bit(unsigned int bits) -{ - int i; + static __inline__ int top_bit(unsigned int bits) + { + int i; - if (bits == 0) - return -1; - i = 0; - if (bits & 0xFFFF0000) - { - bits &= 0xFFFF0000; - i += 16; - } - if (bits & 0xFF00FF00) - { - bits &= 0xFF00FF00; - i += 8; - } - if (bits & 0xF0F0F0F0) - { - bits &= 0xF0F0F0F0; - i += 4; - } - if (bits & 0xCCCCCCCC) - { - bits &= 0xCCCCCCCC; - i += 2; - } - if (bits & 0xAAAAAAAA) - { - bits &= 0xAAAAAAAA; - i += 1; - } - return i; -} -/*- End of function --------------------------------------------------------*/ + if (bits == 0) + return -1; + i = 0; + if (bits & 0xFFFF0000) + { + bits &= 0xFFFF0000; + i += 16; + } + if (bits & 0xFF00FF00) + { + bits &= 0xFF00FF00; + i += 8; + } + if (bits & 0xF0F0F0F0) + { + bits &= 0xF0F0F0F0; + i += 4; + } + if (bits & 0xCCCCCCCC) + { + bits &= 0xCCCCCCCC; + i += 2; + } + if (bits & 0xAAAAAAAA) + { + bits &= 0xAAAAAAAA; + i += 1; + } + return i; + } + /*- End of function --------------------------------------------------------*/ -static __inline__ int bottom_bit(unsigned int bits) -{ - int i; + static __inline__ int bottom_bit(unsigned int bits) + { + int i; - if (bits == 0) - return -1; - i = 32; - if (bits & 0x0000FFFF) - { - bits &= 0x0000FFFF; - i -= 16; - } - if (bits & 0x00FF00FF) - { - bits &= 0x00FF00FF; - i -= 8; - } - if (bits & 0x0F0F0F0F) - { - bits &= 0x0F0F0F0F; - i -= 4; - } - if (bits & 0x33333333) - { - bits &= 0x33333333; - i -= 2; - } - if (bits & 0x55555555) - { - bits &= 0x55555555; - i -= 1; - } - return i; -} -/*- End of function --------------------------------------------------------*/ + if (bits == 0) + return -1; + i = 32; + if (bits & 0x0000FFFF) + { + bits &= 0x0000FFFF; + i -= 16; + } + if (bits & 0x00FF00FF) + { + bits &= 0x00FF00FF; + i -= 8; + } + if (bits & 0x0F0F0F0F) + { + bits &= 0x0F0F0F0F; + i -= 4; + } + if (bits & 0x33333333) + { + bits &= 0x33333333; + i -= 2; + } + if (bits & 0x55555555) + { + bits &= 0x55555555; + i -= 1; + } + return i; + } + /*- End of function --------------------------------------------------------*/ #endif -/* N.B. It is tempting to use look-up tables for A-law and u-law conversion. - * However, you should consider the cache footprint. - * - * A 64K byte table for linear to x-law and a 512 byte table for x-law to - * linear sound like peanuts these days, and shouldn't an array lookup be - * real fast? No! When the cache sloshes as badly as this one will, a tight - * calculation may be better. The messiest part is normally finding the - * segment, but a little inline assembly can fix that on an i386, x86_64 and - * many other modern processors. - */ + /* N.B. It is tempting to use look-up tables for A-law and u-law conversion. + * However, you should consider the cache footprint. + * + * A 64K byte table for linear to x-law and a 512 byte table for x-law to + * linear sound like peanuts these days, and shouldn't an array lookup be + * real fast? No! When the cache sloshes as badly as this one will, a tight + * calculation may be better. The messiest part is normally finding the + * segment, but a little inline assembly can fix that on an i386, x86_64 and + * many other modern processors. + */ -/* - * Mu-law is basically as follows: - * - * Biased Linear Input Code Compressed Code - * ------------------------ --------------- - * 00000001wxyza 000wxyz - * 0000001wxyzab 001wxyz - * 000001wxyzabc 010wxyz - * 00001wxyzabcd 011wxyz - * 0001wxyzabcde 100wxyz - * 001wxyzabcdef 101wxyz - * 01wxyzabcdefg 110wxyz - * 1wxyzabcdefgh 111wxyz - * - * Each biased linear code has a leading 1 which identifies the segment - * number. The value of the segment number is equal to 7 minus the number - * of leading 0's. The quantization interval is directly available as the - * four bits wxyz. * The trailing bits (a - h) are ignored. - * - * Ordinarily the complement of the resulting code word is used for - * transmission, and so the code word is complemented before it is returned. - * - * For further information see John C. Bellamy's Digital Telephony, 1982, - * John Wiley & Sons, pps 98-111 and 472-476. - */ + /* + * Mu-law is basically as follows: + * + * Biased Linear Input Code Compressed Code + * ------------------------ --------------- + * 00000001wxyza 000wxyz + * 0000001wxyzab 001wxyz + * 000001wxyzabc 010wxyz + * 00001wxyzabcd 011wxyz + * 0001wxyzabcde 100wxyz + * 001wxyzabcdef 101wxyz + * 01wxyzabcdefg 110wxyz + * 1wxyzabcdefgh 111wxyz + * + * Each biased linear code has a leading 1 which identifies the segment + * number. The value of the segment number is equal to 7 minus the number + * of leading 0's. The quantization interval is directly available as the + * four bits wxyz. * The trailing bits (a - h) are ignored. + * + * Ordinarily the complement of the resulting code word is used for + * transmission, and so the code word is complemented before it is returned. + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ -/*#define ULAW_ZEROTRAP*/ /* turn on the trap as per the MIL-STD */ + /*#define ULAW_ZEROTRAP*/ /* turn on the trap as per the MIL-STD */ #define ULAW_BIAS 0x84 /* Bias for linear code. */ -/*! \brief Encode a linear sample to u-law - \param linear The sample to encode. - \return The u-law value. -*/ -static __inline__ uint8_t linear_to_ulaw(int linear) -{ - uint8_t u_val; - int mask; - int seg; + /*! \brief Encode a linear sample to u-law + \param linear The sample to encode. + \return The u-law value. + */ + static __inline__ uint8_t linear_to_ulaw(int linear) + { + uint8_t u_val; + int mask; + int seg; - /* Get the sign and the magnitude of the value. */ - if (linear < 0) - { - linear = ULAW_BIAS - linear; - mask = 0x7F; - } - else - { - linear = ULAW_BIAS + linear; - mask = 0xFF; - } + /* Get the sign and the magnitude of the value. */ + if (linear < 0) + { + linear = ULAW_BIAS - linear; + mask = 0x7F; + } + else + { + linear = ULAW_BIAS + linear; + mask = 0xFF; + } - seg = top_bit(linear | 0xFF) - 7; + seg = top_bit(linear | 0xFF) - 7; - /* - * Combine the sign, segment, quantization bits, - * and complement the code word. - */ - if (seg >= 8) - u_val = (uint8_t) (0x7F ^ mask); - else - u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); + /* + * Combine the sign, segment, quantization bits, + * and complement the code word. + */ + if (seg >= 8) + u_val = (uint8_t) (0x7F ^ mask); + else + u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); #ifdef ULAW_ZEROTRAP - /* Optional ITU trap */ - if (u_val == 0) - u_val = 0x02; + /* Optional ITU trap */ + if (u_val == 0) + u_val = 0x02; #endif - return u_val; -} -/*- End of function --------------------------------------------------------*/ + return u_val; + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Decode an u-law sample to a linear value. - \param ulaw The u-law sample to decode. - \return The linear value. -*/ -static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) -{ - int t; + /*! \brief Decode an u-law sample to a linear value. + \param ulaw The u-law sample to decode. + \return The linear value. + */ + static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) + { + int t; - /* Complement to obtain normal u-law value. */ - ulaw = ~ulaw; - /* - * Extract and bias the quantization bits. Then - * shift up by the segment number and subtract out the bias. - */ - t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); - return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); -} -/*- End of function --------------------------------------------------------*/ + /* Complement to obtain normal u-law value. */ + ulaw = ~ulaw; + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); + return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); + } + /*- End of function --------------------------------------------------------*/ -/* - * A-law is basically as follows: - * - * Linear Input Code Compressed Code - * ----------------- --------------- - * 0000000wxyza 000wxyz - * 0000001wxyza 001wxyz - * 000001wxyzab 010wxyz - * 00001wxyzabc 011wxyz - * 0001wxyzabcd 100wxyz - * 001wxyzabcde 101wxyz - * 01wxyzabcdef 110wxyz - * 1wxyzabcdefg 111wxyz - * - * For further information see John C. Bellamy's Digital Telephony, 1982, - * John Wiley & Sons, pps 98-111 and 472-476. - */ + /* + * A-law is basically as follows: + * + * Linear Input Code Compressed Code + * ----------------- --------------- + * 0000000wxyza 000wxyz + * 0000001wxyza 001wxyz + * 000001wxyzab 010wxyz + * 00001wxyzabc 011wxyz + * 0001wxyzabcd 100wxyz + * 001wxyzabcde 101wxyz + * 01wxyzabcdef 110wxyz + * 1wxyzabcdefg 111wxyz + * + * For further information see John C. Bellamy's Digital Telephony, 1982, + * John Wiley & Sons, pps 98-111 and 472-476. + */ #define ALAW_AMI_MASK 0x55 -/*! \brief Encode a linear sample to A-law - \param linear The sample to encode. - \return The A-law value. -*/ -static __inline__ uint8_t linear_to_alaw(int linear) -{ - int mask; - int seg; + /*! \brief Encode a linear sample to A-law + \param linear The sample to encode. + \return The A-law value. + */ + static __inline__ uint8_t linear_to_alaw(int linear) + { + int mask; + int seg; - if (linear >= 0) - { - /* Sign (bit 7) bit = 1 */ - mask = ALAW_AMI_MASK | 0x80; - } - else - { - /* Sign (bit 7) bit = 0 */ - mask = ALAW_AMI_MASK; - linear = -linear - 8; - } + if (linear >= 0) + { + /* Sign (bit 7) bit = 1 */ + mask = ALAW_AMI_MASK | 0x80; + } + else + { + /* Sign (bit 7) bit = 0 */ + mask = ALAW_AMI_MASK; + linear = -linear - 8; + } - /* Convert the scaled magnitude to segment number. */ - seg = top_bit(linear | 0xFF) - 7; - if (seg >= 8) - { - if (linear >= 0) - { - /* Out of range. Return maximum value. */ - return (uint8_t) (0x7F ^ mask); - } - /* We must be just a tiny step below zero */ - return (uint8_t) (0x00 ^ mask); - } - /* Combine the sign, segment, and quantization bits. */ - return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); -} -/*- End of function --------------------------------------------------------*/ + /* Convert the scaled magnitude to segment number. */ + seg = top_bit(linear | 0xFF) - 7; + if (seg >= 8) + { + if (linear >= 0) + { + /* Out of range. Return maximum value. */ + return (uint8_t) (0x7F ^ mask); + } + /* We must be just a tiny step below zero */ + return (uint8_t) (0x00 ^ mask); + } + /* Combine the sign, segment, and quantization bits. */ + return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Decode an A-law sample to a linear value. - \param alaw The A-law sample to decode. - \return The linear value. -*/ -static __inline__ int16_t alaw_to_linear(uint8_t alaw) -{ - int i; - int seg; + /*! \brief Decode an A-law sample to a linear value. + \param alaw The A-law sample to decode. + \return The linear value. + */ + static __inline__ int16_t alaw_to_linear(uint8_t alaw) + { + int i; + int seg; - alaw ^= ALAW_AMI_MASK; - i = ((alaw & 0x0F) << 4); - seg = (((int) alaw & 0x70) >> 4); - if (seg) - i = (i + 0x108) << (seg - 1); - else - i += 8; - return (int16_t) ((alaw & 0x80) ? i : -i); -} -/*- End of function --------------------------------------------------------*/ + alaw ^= ALAW_AMI_MASK; + i = ((alaw & 0x0F) << 4); + seg = (((int) alaw & 0x70) >> 4); + if (seg) + i = (i + 0x108) << (seg - 1); + else + i += 8; + return (int16_t) ((alaw & 0x80) ? i : -i); + } + /*- End of function --------------------------------------------------------*/ -/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. - \param alaw The A-law sample to transcode. - \return The best matching u-law value. -*/ -uint8_t alaw_to_ulaw(uint8_t alaw); + /*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. + \param alaw The A-law sample to transcode. + \return The best matching u-law value. + */ + uint8_t alaw_to_ulaw(uint8_t alaw); -/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. - \param alaw The u-law sample to transcode. - \return The best matching A-law value. -*/ -uint8_t ulaw_to_alaw(uint8_t ulaw); + /*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. + \param alaw The u-law sample to transcode. + \return The best matching A-law value. + */ + uint8_t ulaw_to_alaw(uint8_t ulaw); #ifdef __cplusplus } @@ -382,3 +382,14 @@ uint8_t ulaw_to_alaw(uint8_t ulaw); #endif /*- End of file ------------------------------------------------------------*/ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 4019a69ff9..4c3c48f4bf 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -103,11 +103,11 @@ create_hashtable(unsigned int minsize, int hashtable_insert(struct hashtable *h, void *k, void *v); -#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ -int fnname (struct hashtable *h, keytype *k, valuetype *v) \ -{ \ - return hashtable_insert(h,k,v); \ -} +#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ + int fnname (struct hashtable *h, keytype *k, valuetype *v) \ + { \ + return hashtable_insert(h,k,v); \ + } /***************************************************************************** * hashtable_search @@ -122,10 +122,10 @@ void * hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ -valuetype * fnname (struct hashtable *h, keytype *k) \ -{ \ - return (valuetype *) (hashtable_search(h,k)); \ -} + valuetype * fnname (struct hashtable *h, keytype *k) \ + { \ + return (valuetype *) (hashtable_search(h,k)); \ + } /***************************************************************************** * hashtable_remove @@ -140,10 +140,10 @@ void * /* returns value */ hashtable_remove(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ -valuetype * fnname (struct hashtable *h, keytype *k) \ -{ \ - return (valuetype *) (hashtable_remove(h,k)); \ -} + valuetype * fnname (struct hashtable *h, keytype *k) \ + { \ + return (valuetype *) (hashtable_remove(h,k)); \ + } /***************************************************************************** @@ -201,4 +201,15 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values); * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/include/hashtable_itr.h b/libs/freetdm/src/include/hashtable_itr.h index aacf86825a..71c0d659ff 100644 --- a/libs/freetdm/src/include/hashtable_itr.h +++ b/libs/freetdm/src/include/hashtable_itr.h @@ -62,17 +62,17 @@ hashtable_iterator_remove(struct hashtable_itr *itr); /*****************************************************************************/ /* search - overwrite the supplied iterator, to point to the entry * matching the supplied key. - h points to the hashtable to be searched. + h points to the hashtable to be searched. * returns zero if not found. */ int hashtable_iterator_search(struct hashtable_itr *itr, struct hashtable *h, void *k); -#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ -int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ -{ \ - return (hashtable_iterator_search(i,h,k)); \ -} +#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \ + int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ + { \ + return (hashtable_iterator_search(i,h,k)); \ + } @@ -109,4 +109,16 @@ int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \ * 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. -*/ + */ + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index edf59efe18..ede652c654 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -37,10 +37,10 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) { /* Only works if tablelength == 2^N */ /*static inline unsigned int -indexFor(unsigned int tablelength, unsigned int hashvalue) -{ - return (hashvalue & (tablelength - 1u)); -} + indexFor(unsigned int tablelength, unsigned int hashvalue) + { + return (hashvalue & (tablelength - 1u)); + } */ /*****************************************************************************/ @@ -83,4 +83,14 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) * 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. -*/ + */ +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index aaf7b0ed47..e81ef5e90d 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -78,27 +78,27 @@ extern "C" { #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 -typedef double teletone_process_t; + typedef double teletone_process_t; -/*! \file libteletone.h - \brief Top level include file + /*! \file libteletone.h + \brief Top level include file - This file should be included by applications using the library -*/ + This file should be included by applications using the library + */ -/*! \brief An abstraction to store a tone mapping */ -typedef struct { - /*! An array of tone frequencies */ - teletone_process_t freqs[TELETONE_MAX_TONES]; -} teletone_tone_map_t; + /*! \brief An abstraction to store a tone mapping */ + typedef struct { + /*! An array of tone frequencies */ + teletone_process_t freqs[TELETONE_MAX_TONES]; + } teletone_tone_map_t; #if !defined(M_PI) -/* C99 systems may not define M_PI */ + /* C99 systems may not define M_PI */ #define M_PI 3.14159265358979323846264338327 #endif #ifdef _MSC_VER -typedef __int16 int16_t; + typedef __int16 int16_t; #endif #include diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index eda4e49514..15d5e9ddfb 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -98,11 +98,11 @@ extern "C" { #endif #include -/*! \file libteletone_detect.h - \brief Tone Detection Routines + /*! \file libteletone_detect.h + \brief Tone Detection Routines - This module is responsible for tone detection specifics -*/ + This module is responsible for tone detection specifics + */ #ifndef FALSE #define FALSE 0 @@ -111,17 +111,17 @@ extern "C" { #endif #endif -/* Basic DTMF specs: - * - * Minimum tone on = 40ms - * Minimum tone off = 50ms - * Maximum digit rate = 10 per second - * Normal twist <= 8dB accepted - * Reverse twist <= 4dB accepted - * S/N >= 15dB will detect OK - * Attenuation <= 26dB will detect OK - * Frequency tolerance +- 1.5% will detect, +-3.5% will reject - */ + /* Basic DTMF specs: + * + * Minimum tone on = 40ms + * Minimum tone off = 50ms + * Maximum digit rate = 10 per second + * Normal twist <= 8dB accepted + * Reverse twist <= 4dB accepted + * S/N >= 15dB will detect OK + * Attenuation <= 26dB will detect OK + * Frequency tolerance +- 1.5% will detect, +-3.5% will reject + */ #define DTMF_THRESHOLD 8.0e7 #define DTMF_NORMAL_TWIST 6.3 /* 8dB */ @@ -134,131 +134,131 @@ extern "C" { #define BLOCK_LEN 102 #define M_TWO_PI 2.0*M_PI -/*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ -typedef struct { - teletone_process_t v2; - teletone_process_t v3; - teletone_process_t fac; -} teletone_goertzel_state_t; + /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ + typedef struct { + teletone_process_t v2; + teletone_process_t v3; + teletone_process_t fac; + } teletone_goertzel_state_t; -/*! \brief A container for a DTMF detection state.*/ -typedef struct { - int hit1; - int hit2; - int hit3; - int hit4; - int mhit; + /*! \brief A container for a DTMF detection state.*/ + typedef struct { + int hit1; + int hit2; + int hit3; + int hit4; + int mhit; - teletone_goertzel_state_t row_out[GRID_FACTOR]; - teletone_goertzel_state_t col_out[GRID_FACTOR]; - teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; - teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; - teletone_process_t energy; + teletone_goertzel_state_t row_out[GRID_FACTOR]; + teletone_goertzel_state_t col_out[GRID_FACTOR]; + teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; + teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; + teletone_process_t energy; - int current_sample; - char digits[TELETONE_MAX_DTMF_DIGITS + 1]; - int current_digits; - int detected_digits; - int lost_digits; - int digit_hits[16]; -} teletone_dtmf_detect_state_t; + int current_sample; + char digits[TELETONE_MAX_DTMF_DIGITS + 1]; + int current_digits; + int detected_digits; + int lost_digits; + int digit_hits[16]; + } teletone_dtmf_detect_state_t; -/*! \brief An abstraction to store the coefficient of a tone frequency */ -typedef struct { - teletone_process_t fac; -} teletone_detection_descriptor_t; + /*! \brief An abstraction to store the coefficient of a tone frequency */ + typedef struct { + teletone_process_t fac; + } teletone_detection_descriptor_t; -/*! \brief A container for a single multi-tone detection -TELETONE_MAX_TONES dictates the maximum simultaneous tones that can be present -in a multi-tone representation. -*/ -typedef struct { - int sample_rate; + /*! \brief A container for a single multi-tone detection + TELETONE_MAX_TONES dictates the maximum simultaneous tones that can be present + in a multi-tone representation. + */ + typedef struct { + int sample_rate; - teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]; - teletone_goertzel_state_t gs[TELETONE_MAX_TONES]; - teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; - int tone_count; + teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs[TELETONE_MAX_TONES]; + teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; + int tone_count; - teletone_process_t energy; - int current_sample; + teletone_process_t energy; + int current_sample; - int min_samples; - int total_samples; + int min_samples; + int total_samples; - int positives; - int negatives; - int hits; + int positives; + int negatives; + int hits; - int positive_factor; - int negative_factor; - int hit_factor; + int positive_factor; + int negative_factor; + int hit_factor; -} teletone_multi_tone_t; + } teletone_multi_tone_t; -/*! - \brief Initilize a multi-frequency tone detector - \param mt the multi-frequency tone descriptor - \param map a representation of the multi-frequency tone -*/ -void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); + /*! + \brief Initilize a multi-frequency tone detector + \param mt the multi-frequency tone descriptor + \param map a representation of the multi-frequency tone + */ + void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); -/*! - \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt - \param mt the multi-frequency tone descriptor - \param sample_buffer an array aof 16 bit signed linear samples - \param samples the number of samples present in sample_buffer - \return true when the tone was detected or false when it is not -*/ -int teletone_multi_tone_detect (teletone_multi_tone_t *mt, - int16_t sample_buffer[], - int samples); + /*! + \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt + \param mt the multi-frequency tone descriptor + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when the tone was detected or false when it is not + */ + int teletone_multi_tone_detect (teletone_multi_tone_t *mt, + int16_t sample_buffer[], + int samples); -/*! - \brief Initilize a DTMF detection state object - \param dtmf_detect_state the DTMF detection state to initilize - \param sample_rate the desired sample rate -*/ -void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); + /*! + \brief Initilize a DTMF detection state object + \param dtmf_detect_state the DTMF detection state to initilize + \param sample_rate the desired sample rate + */ + void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); -/*! - \brief Check a sample buffer for the presence of DTMF digits - \param dtmf_detect_state the detection state object to check - \param sample_buffer an array aof 16 bit signed linear samples - \param samples the number of samples present in sample_buffer - \return true when DTMF was detected or false when it is not -*/ -int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, - int16_t sample_buffer[], - int samples); -/*! - \brief retrieve any collected digits into a string buffer - \param dtmf_detect_state the detection state object to check - \param buf the string buffer to write to - \param max the maximum length of buf - \return the number of characters written to buf -*/ -int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, - char *buf, - int max); - -/*! - \brief Step through the Goertzel Algorithm for each sample in a buffer - \param goertzel_state the goertzel state to step the samples through - \param sample_buffer an array aof 16 bit signed linear samples - \param samples the number of samples present in sample_buffer -*/ -void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + /*! + \brief Check a sample buffer for the presence of DTMF digits + \param dtmf_detect_state the detection state object to check + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + \return true when DTMF was detected or false when it is not + */ + int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples); + /*! + \brief retrieve any collected digits into a string buffer + \param dtmf_detect_state the detection state object to check + \param buf the string buffer to write to + \param max the maximum length of buf + \return the number of characters written to buf + */ + int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, + char *buf, + int max); -/*! - \brief Compute the result of the last applied step of the Goertzel Algorithm - \param goertzel_state the goertzel state to retrieve from - \return the computed value for consideration in furthur audio tests -*/ -teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); + /*! + \brief Step through the Goertzel Algorithm for each sample in a buffer + \param goertzel_state the goertzel state to step the samples through + \param sample_buffer an array aof 16 bit signed linear samples + \param samples the number of samples present in sample_buffer + */ + void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, + int16_t sample_buffer[], + int samples); + + /*! + \brief Compute the result of the last applied step of the Goertzel Algorithm + \param goertzel_state the goertzel state to retrieve from + \return the computed value for consideration in furthur audio tests + */ + teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 3d625e8f52..e37778d278 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -89,113 +89,113 @@ extern "C" { -/*! \file libteletone_generate.h - \brief Tone Generation Routines + /*! \file libteletone_generate.h + \brief Tone Generation Routines - This module is responsible for tone generation specifics -*/ + This module is responsible for tone generation specifics + */ -typedef int16_t teletone_audio_t; -struct teletone_generation_session; -typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); + typedef int16_t teletone_audio_t; + struct teletone_generation_session; + typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); -/*! \brief An abstraction to store a tone generation session */ -struct teletone_generation_session { - /*! An array of tone mappings to character mappings */ - teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; - /*! The number of channels the output audio should be in */ - int channels; - /*! The Rate in hz of the output audio */ - int rate; - /*! The duration (in samples) of the output audio */ - int duration; - /*! The duration of silence to append after the initial audio is generated */ - int wait; - /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ - int tmp_duration; - /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ - int tmp_wait; - /*! Number of loops to repeat a single instruction*/ - int loops; - /*! Number of loops to repeat the entire set of instructions*/ - int LOOPS; - /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - int decay_factor; - /*! Direction to perform volume increase/decrease 1/-1*/ - int decay_direction; - /*! Number of samples between increase/decrease of volume */ - int decay_step; - /*! Volume factor of the tone */ - int volume; - /*! Debug on/off */ - int debug; - /*! FILE stream to write debug data to */ - FILE *debug_stream; - /*! Extra user data to attach to the session*/ - void *user_data; - /*! Buffer for storing sample data (dynamic) */ - teletone_audio_t *buffer; - /*! Size of the buffer */ - int datalen; - /*! In-Use size of the buffer */ - int samples; - /*! Callback function called during generation */ - int dynamic; - tone_handler handler; -}; + /*! \brief An abstraction to store a tone generation session */ + struct teletone_generation_session { + /*! An array of tone mappings to character mappings */ + teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; + /*! The number of channels the output audio should be in */ + int channels; + /*! The Rate in hz of the output audio */ + int rate; + /*! The duration (in samples) of the output audio */ + int duration; + /*! The duration of silence to append after the initial audio is generated */ + int wait; + /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ + int tmp_duration; + /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ + int tmp_wait; + /*! Number of loops to repeat a single instruction*/ + int loops; + /*! Number of loops to repeat the entire set of instructions*/ + int LOOPS; + /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ + int decay_factor; + /*! Direction to perform volume increase/decrease 1/-1*/ + int decay_direction; + /*! Number of samples between increase/decrease of volume */ + int decay_step; + /*! Volume factor of the tone */ + int volume; + /*! Debug on/off */ + int debug; + /*! FILE stream to write debug data to */ + FILE *debug_stream; + /*! Extra user data to attach to the session*/ + void *user_data; + /*! Buffer for storing sample data (dynamic) */ + teletone_audio_t *buffer; + /*! Size of the buffer */ + int datalen; + /*! In-Use size of the buffer */ + int samples; + /*! Callback function called during generation */ + int dynamic; + tone_handler handler; + }; -typedef struct teletone_generation_session teletone_generation_session_t; + typedef struct teletone_generation_session teletone_generation_session_t; -/*! - \brief Assign a set of tones to a tone_session indexed by a paticular index/character - \param ts the tone generation session - \param index the index to map the tone to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 -*/ -int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); + /*! + \brief Assign a set of tones to a tone_session indexed by a paticular index/character + \param ts the tone generation session + \param index the index to map the tone to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 + */ + int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); -/*! - \brief Assign a set of tones to a single tone map - \param map the map to assign the tones to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 -*/ -int teletone_set_map(teletone_tone_map_t *map, ...); + /*! + \brief Assign a set of tones to a single tone map + \param map the map to assign the tones to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 + */ + int teletone_set_map(teletone_tone_map_t *map, ...); -/*! - \brief Initilize a tone generation session - \param ts the tone generation session to initilize - \param buflen the size of the buffer(in samples) to dynamically allocate - \param handler a callback function to execute when a tone generation instruction is complete - \param user_data optional user data to send - \return 0 -*/ -int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + /*! + \brief Initilize a tone generation session + \param ts the tone generation session to initilize + \param buflen the size of the buffer(in samples) to dynamically allocate + \param handler a callback function to execute when a tone generation instruction is complete + \param user_data optional user data to send + \return 0 + */ + int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); -/*! - \brief Free the buffer allocated by a tone generation session - \param ts the tone generation session to destroy - \return 0 -*/ -int teletone_destroy_session(teletone_generation_session_t *ts); + /*! + \brief Free the buffer allocated by a tone generation session + \param ts the tone generation session to destroy + \return 0 + */ + int teletone_destroy_session(teletone_generation_session_t *ts); -/*! - \brief Execute a single tone generation instruction - \param ts the tone generation session to consult for parameters - \param map the tone mapping to use for the frequencies - \return 0 -*/ -int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); + /*! + \brief Execute a single tone generation instruction + \param ts the tone generation session to consult for parameters + \param map the tone mapping to use for the frequencies + \return 0 + */ + int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); -/*! - \brief Execute a tone generation script and call callbacks after each instruction - \param ts the tone generation session to execute on - \param cmd the script to execute - \return 0 -*/ -int teletone_run(teletone_generation_session_t *ts, char *cmd); + /*! + \brief Execute a tone generation script and call callbacks after each instruction + \param ts the tone generation session to execute on + \param cmd the script to execute + \return 0 + */ + int teletone_run(teletone_generation_session_t *ts, char *cmd); #ifdef __cplusplus } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 1fdb372087..53d2106d99 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -189,8 +189,8 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); -#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex);\ - zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s));\ +#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); \ + zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ zap_channel_set_state(obj, s); @@ -235,6 +235,8 @@ struct zap_caller_data { struct zap_channel { uint32_t span_id; uint32_t chan_id; + uint32_t physical_span_id; + uint32_t physical_chan_id; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; @@ -263,11 +265,11 @@ struct zap_channel { char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; uint8_t needed_tones[ZAP_TONEMAP_INVALID]; uint8_t detected_tones[ZAP_TONEMAP_INVALID]; - zap_tonemap_t last_detected_tone; - + zap_tonemap_t last_detected_tone; uint32_t token_count; char chan_name[128]; char chan_number[32]; + zap_filehandle_t fds[2]; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -384,3 +386,14 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #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 expandtab: + */ diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index a9ef56add4..d4e673cc5e 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -43,10 +43,10 @@ struct iphdr { #if defined(__LITTLE_ENDIAN_BITFIELD) unsigned ihl:4, - version:4; + version:4; #elif defined (__BIG_ENDIAN_BITFIELD) unsigned version:4, - ihl:4; + ihl:4; #else # error "unknown byteorder!" #endif @@ -108,15 +108,15 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); if (DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ) == FALSE){ return 1; } @@ -176,15 +176,15 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) wan_udp.wan_udphdr_data_len = 0; DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ); + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ); if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ /* somone already has this channel, or somthing else is not right. */ @@ -230,21 +230,21 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) api_poll.timeout = timeout; if (!DeviceIoControl( - fd, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)&api_poll, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL)) { + 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; @@ -253,7 +253,7 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) default: return -1; - } + } if (api_poll.poll_events_bitmap == 0){ return -1; @@ -309,15 +309,15 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen } if (!DeviceIoControl( - fd, - IoctlReadCommand, - (LPVOID)NULL, - 0L, - (LPVOID)&rx_data, - sizeof(RX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - )){ + fd, + IoctlReadCommand, + (LPVOID)NULL, + 0L, + (LPVOID)&rx_data, + sizeof(RX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + )){ return -1; } @@ -327,18 +327,18 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen 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){ + { + 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; } - memcpy(databuf, rx_data.data, pri->data_length); - rx_len = pri->data_length; - break; - - default: - break; - } #else struct msghdr msg; @@ -386,15 +386,15 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle 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 - )){ + 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; } @@ -425,3 +425,15 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle } #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 expandtab: + */ + diff --git a/libs/freetdm/src/include/zap_analog.h b/libs/freetdm/src/include/zap_analog.h index 82badfcea9..5322463577 100644 --- a/libs/freetdm/src/include/zap_analog.h +++ b/libs/freetdm/src/include/zap_analog.h @@ -46,3 +46,14 @@ zap_status_t zap_analog_start(zap_span_t *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); #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 expandtab: + */ diff --git a/libs/freetdm/src/include/zap_isdn.h b/libs/freetdm/src/include/zap_isdn.h index 7117304a03..0aea34973d 100644 --- a/libs/freetdm/src/include/zap_isdn.h +++ b/libs/freetdm/src/include/zap_isdn.h @@ -47,3 +47,15 @@ zap_status_t zap_isdn_init(void); zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb); #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 expandtab: + */ + diff --git a/libs/freetdm/src/include/zap_skel.h b/libs/freetdm/src/include/zap_skel.h index 9fdaadf7b5..a8a245837f 100644 --- a/libs/freetdm/src/include/zap_skel.h +++ b/libs/freetdm/src/include/zap_skel.h @@ -39,3 +39,14 @@ zap_status_t skel_init(zap_software_interface_t **zint); zap_status_t skel_destroy(void); #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 expandtab: + */ diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index 557f23ea51..1a9061429e 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -37,3 +37,15 @@ zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); #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 expandtab: + */ + diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 3bd99d3b0d..607fa03366 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -41,10 +41,12 @@ typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef __int32 int32_t; typedef intptr_t zap_ssize_t; +typedef int zap_filehandle_t; #else #include typedef int zap_socket_t; typedef ssize_t zap_ssize_t; +typedef int zap_filehandle_t; #endif typedef size_t zap_size_t; @@ -167,8 +169,8 @@ typedef enum { ZAP_COMMAND_GET_CODEC, ZAP_COMMAND_SET_NATIVE_CODEC, ZAP_COMMAND_GET_NATIVE_CODEC, - ZAP_COMMAND_ENABLE_TONE_DETECT, - ZAP_COMMAND_DISABLE_TONE_DETECT, + 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, @@ -180,6 +182,8 @@ typedef enum { ZAP_COMMAND_ONHOOK, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, ZAP_COMMAND_DISABLE_PROGRESS_DETECT, + ZAP_COMMAND_TRACE_INPUT, + ZAP_COMMAND_TRACE_OUTPUT, ZAP_COMMAND_COUNT } zap_command_t; @@ -322,3 +326,15 @@ typedef struct hashtable_itr zap_hash_itr_t; typedef struct key zap_hash_key_t; typedef struct value zap_hash_val_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 expandtab: + */ + diff --git a/libs/freetdm/src/include/zap_wanpipe.h b/libs/freetdm/src/include/zap_wanpipe.h index fa78f41f74..0b2f4a9c48 100644 --- a/libs/freetdm/src/include/zap_wanpipe.h +++ b/libs/freetdm/src/include/zap_wanpipe.h @@ -39,3 +39,15 @@ zap_status_t wanpipe_init(zap_io_interface_t **zint); zap_status_t wanpipe_destroy(void); #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 expandtab: + */ + diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 1ad2e65c20..9f3287f6a4 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -229,3 +229,14 @@ zap_status_t zt_init(zap_io_interface_t **zint); zap_status_t zt_destroy(void); #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 expandtab: + */ diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 8df7d569a4..1af9b8fc43 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -208,8 +208,8 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } int teletone_multi_tone_detect (teletone_multi_tone_t *mt, - int16_t sample_buffer[], - int samples) + int16_t sample_buffer[], + int samples) { int sample, limit, j, x = 0; teletone_process_t v1, famp; @@ -295,8 +295,8 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, - int16_t sample_buffer[], - int samples) + int16_t sample_buffer[], + int samples) { teletone_process_t row_energy[GRID_FACTOR]; teletone_process_t col_energy[GRID_FACTOR]; @@ -426,8 +426,8 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, - char *buf, - int max) + char *buf, + int max) { if (max > dtmf_detect_state->current_digits) { max = dtmf_detect_state->current_digits; diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index 5612e19a15..9126a186af 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -137,11 +137,11 @@ static void launch_channel(struct sangoma_pri *spri, int channo) if (!lead && loops == 300) { #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, dtmf) != ZAP_SUCCESS) { - printf("Critical Error: Failed to send dtmf\n"); - zap_channel_close(&chan); - exit(-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 } @@ -314,3 +314,13 @@ int main(int argc, char *argv[]) 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 expandtab: + */ diff --git a/libs/freetdm/src/sangoma_pri.c b/libs/freetdm/src/sangoma_pri.c index b4692216d0..865fe4f476 100644 --- a/libs/freetdm/src/sangoma_pri.c +++ b/libs/freetdm/src/sangoma_pri.c @@ -23,39 +23,39 @@ 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; + 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(); + /** + ** 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; + Sec = Ticks/1000; + Usec = (Ticks - (Sec*1000))*1000; + tp->tv_sec = Sec; + tp->tv_usec = Usec; #endif /* WITHOUT_MM_LIB */ - (void)nothing; - return 0; + (void)nothing; + return 0; } #endif /* WIN32 */ #endif /* HAVE_GETTIMEOFDAY */ @@ -166,7 +166,7 @@ int sangoma_one_loop(struct sangoma_pri *spri) FD_ZERO(&efds); #ifdef _MSC_VER -//Windows macro for FD_SET includes a warning C4127: conditional expression is constant + //Windows macro for FD_SET includes a warning C4127: conditional expression is constant #pragma warning(push) #pragma warning(disable:4127) #endif @@ -238,3 +238,14 @@ int sangoma_run_pri(struct sangoma_pri *spri) } +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index e1f17d23fd..cd480e2ba5 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -100,3 +100,15 @@ int main(int argc, char *argv[]) zap_global_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 expandtab: + */ + diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 12b22b30b3..4f00ca600b 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -72,3 +72,14 @@ int main(int argc, char *argv[]) zap_global_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 expandtab: + */ diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index d268436eb5..93af26f752 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -41,3 +41,14 @@ int main(int argc, char *argv[]) zap_global_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 expandtab: + */ diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index ada2ca804e..e8944f2db6 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -135,7 +135,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) goto done; } - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); goto done; } @@ -483,6 +483,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + /*zap_channel_command(event->channel, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");*/ sig.event_id = ZAP_SIGEVENT_START; zap_set_string(event->channel->caller_data.dnis, event->channel->chan_number); data->sig_cb(&sig); @@ -585,3 +586,13 @@ zap_status_t zap_analog_start(zap_span_t *span) return zap_thread_create_detached(zap_analog_run, 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 expandtab: + */ diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index d4edbe6e29..1db918665d 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -197,11 +197,11 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d freespace = buffer->datalen - buffer->used; /* - if (buffer->data != buffer->head) { - memmove(buffer->data, buffer->head, buffer->used); - buffer->head = buffer->data; - } - */ + 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; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3877d5213d..bec1c5a1e8 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -332,6 +332,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; + new_chan->fds[0] = -1; + new_chan->fds[1] = -1; zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -689,12 +691,18 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) zap_status_t zap_channel_done(zap_channel_t *zchan) { + int i; assert(zchan != NULL); memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); - + for (i = 0; i < 2; i++) { + if (zchan->fds[i] > -1) { + close(zchan->fds[i]); + zchan->fds[i] = -1; + } + } return ZAP_SUCCESS; } @@ -780,6 +788,36 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_mutex_lock(zchan->mutex); switch(command) { + case ZAP_COMMAND_TRACE_INPUT: + { + char *path = (char *) obj; + if (zchan->fds[0] > 0) { + close(zchan->fds[0]); + zchan->fds[0] = -1; + } + if ((zchan->fds[0] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + GOTO_STATUS(done, ZAP_SUCCESS); + } + + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, ZAP_FAIL); + } + break; + case ZAP_COMMAND_TRACE_OUTPUT: + { + char *path = (char *) obj; + if (zchan->fds[1] > 0) { + close(zchan->fds[0]); + zchan->fds[1] = -1; + } + if ((zchan->fds[1] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + GOTO_STATUS(done, ZAP_SUCCESS); + } + + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, ZAP_FAIL); + } + break; case ZAP_COMMAND_SET_INTERVAL: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { @@ -863,7 +901,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo GOTO_STATUS(done, ZAP_SUCCESS); } break; - case ZAP_COMMAND_ENABLE_TONE_DETECT: + case ZAP_COMMAND_ENABLE_DTMF_DETECT: { /* if they don't have thier own, use ours */ if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { @@ -880,7 +918,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } } break; - case ZAP_COMMAND_DISABLE_TONE_DETECT: + case ZAP_COMMAND_DISABLE_DTMF_DETECT: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; @@ -1216,6 +1254,9 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } status = zchan->zio->read(zchan, data, datalen); + if (zchan->fds[0]) { + write(zchan->fds[0], data, *datalen); + } if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { @@ -1391,6 +1432,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } + if (zchan->fds[1]) { + write(zchan->fds[1], data, *datalen); + } + status = zchan->zio->write(zchan, data, datalen); return status; @@ -1731,3 +1776,13 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) } +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index a8e7281460..76ad83ca25 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -250,3 +250,14 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index 4341309649..c5e9a0e85d 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -108,3 +108,15 @@ zap_status_t skel_destroy(void) { return ZAP_FAIL; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 34e23bec5c..e82d6a3937 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -119,15 +119,15 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat status = ZAP_SUCCESS; goto done; -failpthread: + failpthread: pthread_attr_destroy(&thread->attribute); #endif -fail: + fail: if (thread) { free(thread); } -done: + done: return status; } @@ -157,16 +157,16 @@ zap_status_t zap_mutex_create(zap_mutex_t **mutex) goto success; -fail: - pthread_mutexattr_destroy(&attr); - goto done; + fail: + pthread_mutexattr_destroy(&attr); + goto done; -success: + success: #endif *mutex = check; status = ZAP_SUCCESS; -done: + done: return status; } @@ -217,3 +217,14 @@ zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) #endif return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index de3da19d59..3e9e7501de 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -72,6 +72,8 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + chan->physical_span_id = spanno; + chan->physical_chan_id = x; if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; @@ -532,3 +534,14 @@ zap_status_t wanpipe_destroy(void) memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index bafc191117..49d9edea60 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -90,6 +90,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + chan->physical_span_id = ztp.span_no; + chan->physical_chan_id = ztp.chan_no; + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { if (ztp.g711_type == ZT_G711_ALAW) { chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; @@ -559,3 +562,14 @@ zap_status_t zt_destroy(void) memset(&zt_interface, 0, sizeof(zt_interface)); return ZAP_SUCCESS; } + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ From 3503096dfc4a176bc6cdc0337a3c35c5fb87ed07 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 4 Jun 2007 15:26:10 +0000 Subject: [PATCH 0411/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@206 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/fsk.c | 2 +- libs/openzap/src/dsp/uart.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/dsp/fsk.c b/libs/openzap/src/dsp/fsk.c index e2d0360b77..8f4dfcad05 100644 --- a/libs/openzap/src/dsp/fsk.c +++ b/libs/openzap/src/dsp/fsk.c @@ -39,7 +39,7 @@ #include #include -#include "bell202.h" +#include "fsk.h" #include "uart.h" #ifndef M_PI diff --git a/libs/openzap/src/dsp/uart.h b/libs/openzap/src/dsp/uart.h index 91b2bd0880..368eb7aafa 100644 --- a/libs/openzap/src/dsp/uart.h +++ b/libs/openzap/src/dsp/uart.h @@ -35,7 +35,7 @@ #ifndef __UART_H__ #define __UART_H__ -typedef void (*bytehandler_func_t) (void *, int); +#include typedef struct dsp_uart_attr_s { From 0ce109b93771bbf1ea7c5efa0913ec2171ccaeb6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 4 Jun 2007 15:26:10 +0000 Subject: [PATCH 0412/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@206 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/fsk.c | 2 +- libs/freetdm/src/dsp/uart.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/dsp/fsk.c b/libs/freetdm/src/dsp/fsk.c index e2d0360b77..8f4dfcad05 100644 --- a/libs/freetdm/src/dsp/fsk.c +++ b/libs/freetdm/src/dsp/fsk.c @@ -39,7 +39,7 @@ #include #include -#include "bell202.h" +#include "fsk.h" #include "uart.h" #ifndef M_PI diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h index 91b2bd0880..368eb7aafa 100644 --- a/libs/freetdm/src/dsp/uart.h +++ b/libs/freetdm/src/dsp/uart.h @@ -35,7 +35,7 @@ #ifndef __UART_H__ #define __UART_H__ -typedef void (*bytehandler_func_t) (void *, int); +#include typedef struct dsp_uart_attr_s { From de0a5c3b07ae1b9564fdb8fd85a451293348bc7c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 4 Jun 2007 15:28:23 +0000 Subject: [PATCH 0413/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@207 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/fsk.h | 10 ++++------ libs/openzap/src/dsp/uart.h | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/dsp/fsk.h index dfb6af369c..a2615b1fed 100644 --- a/libs/openzap/src/dsp/fsk.h +++ b/libs/openzap/src/dsp/fsk.h @@ -32,11 +32,9 @@ * 2005 03 20 R. Krten created */ -#ifndef __BELL202_H__ -#define __BELL202_H__ - -typedef void (*bytehandler_func_t) (void *, int); -typedef void (*bithandler_func_t) (void *, int); +#ifndef __FSK_H__ +#define __FSK_H__ +#include "uart.h" typedef struct dsp_fsk_attr_s { @@ -86,5 +84,5 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle); void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); -#endif // __BELL202_H__ +#endif // __FSK_H__ diff --git a/libs/openzap/src/dsp/uart.h b/libs/openzap/src/dsp/uart.h index 368eb7aafa..bfad94ef38 100644 --- a/libs/openzap/src/dsp/uart.h +++ b/libs/openzap/src/dsp/uart.h @@ -35,7 +35,9 @@ #ifndef __UART_H__ #define __UART_H__ -#include +typedef void (*bytehandler_func_t) (void *, int); +typedef void (*bithandler_func_t) (void *, int); + typedef struct dsp_uart_attr_s { From 5e63fdee8b590c7f50ba758b5897eaf00eef5fcb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 4 Jun 2007 15:28:23 +0000 Subject: [PATCH 0414/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@207 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/fsk.h | 10 ++++------ libs/freetdm/src/dsp/uart.h | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/dsp/fsk.h index dfb6af369c..a2615b1fed 100644 --- a/libs/freetdm/src/dsp/fsk.h +++ b/libs/freetdm/src/dsp/fsk.h @@ -32,11 +32,9 @@ * 2005 03 20 R. Krten created */ -#ifndef __BELL202_H__ -#define __BELL202_H__ - -typedef void (*bytehandler_func_t) (void *, int); -typedef void (*bithandler_func_t) (void *, int); +#ifndef __FSK_H__ +#define __FSK_H__ +#include "uart.h" typedef struct dsp_fsk_attr_s { @@ -86,5 +84,5 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle); void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); -#endif // __BELL202_H__ +#endif // __FSK_H__ diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h index 368eb7aafa..bfad94ef38 100644 --- a/libs/freetdm/src/dsp/uart.h +++ b/libs/freetdm/src/dsp/uart.h @@ -35,7 +35,9 @@ #ifndef __UART_H__ #define __UART_H__ -#include +typedef void (*bytehandler_func_t) (void *, int); +typedef void (*bithandler_func_t) (void *, int); + typedef struct dsp_uart_attr_s { From 4ec6fab273197e2a55fdb0d051f825ce9f0e97b0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Jun 2007 23:44:18 +0000 Subject: [PATCH 0415/1766] build fix on windows. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@208 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index bec1c5a1e8..96089c5322 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -34,6 +34,9 @@ #include "openzap.h" #include "zap_isdn.h" #include +#ifdef WIN32 +#include +#endif #ifdef ZAP_WANPIPE_SUPPORT #include "zap_wanpipe.h" #endif @@ -1255,7 +1258,8 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data status = zchan->zio->read(zchan, data, datalen); if (zchan->fds[0]) { - write(zchan->fds[0], data, *datalen); + unsigned int dlen = (unsigned int) *datalen; + write(zchan->fds[0], data, dlen); } if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { @@ -1433,7 +1437,8 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } if (zchan->fds[1]) { - write(zchan->fds[1], data, *datalen); + unsigned int dlen = (unsigned int) *datalen; + write(zchan->fds[1], data, dlen); } status = zchan->zio->write(zchan, data, datalen); From fef19827ee1d6bc23f8bf18e2b0a96d6ecee7380 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Jun 2007 23:44:18 +0000 Subject: [PATCH 0416/1766] build fix on windows. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@208 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index bec1c5a1e8..96089c5322 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -34,6 +34,9 @@ #include "openzap.h" #include "zap_isdn.h" #include +#ifdef WIN32 +#include +#endif #ifdef ZAP_WANPIPE_SUPPORT #include "zap_wanpipe.h" #endif @@ -1255,7 +1258,8 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data status = zchan->zio->read(zchan, data, datalen); if (zchan->fds[0]) { - write(zchan->fds[0], data, *datalen); + unsigned int dlen = (unsigned int) *datalen; + write(zchan->fds[0], data, dlen); } if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { @@ -1433,7 +1437,8 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } if (zchan->fds[1]) { - write(zchan->fds[1], data, *datalen); + unsigned int dlen = (unsigned int) *datalen; + write(zchan->fds[1], data, dlen); } status = zchan->zio->write(zchan, data, datalen); From 9923827d1e69333437d172e529f2d8eb4269df0d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 00:57:02 +0000 Subject: [PATCH 0417/1766] add 1/2 of caller id code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@209 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 10 ++++++++-- libs/openzap/src/dsp/fsk.h | 3 +-- libs/openzap/src/dsp/uart.h | 3 +-- libs/openzap/src/include/openzap.h | 5 +++++ libs/openzap/src/include/zap_types.h | 29 +++++++++++++++++++++++++++- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 628702c594..5c259c578b 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -37,6 +37,9 @@ $(SRC)/zap_io.o \ $(SRC)/zap_isdn.o \ $(SRC)/zap_analog.o \ $(SRC)/zap_config.o \ +$(SRC)/zap_callerid.o \ +$(SRC)/dsp/fsk.o \ +$(SRC)/dsp/uart.o \ $(SRC)/g711.o \ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ @@ -61,7 +64,7 @@ HEADERS=$(SRC)/isdn/include/Q931.h \ $(SRC)/include/openzap.h PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include +INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -I$(PWD)/src/dsp CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a LIBPRIA=libpri.a @@ -79,6 +82,9 @@ $(MYLIB): $(OBJS) $(HEADERS) testapp: $(SRC)/testapp.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread +testcid: $(SRC)/testcid.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread @@ -124,6 +130,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/dsp/fsk.h index a2615b1fed..e9cf0c0c1c 100644 --- a/libs/openzap/src/dsp/fsk.h +++ b/libs/openzap/src/dsp/fsk.h @@ -1,4 +1,3 @@ - /* * bell202.h * @@ -84,5 +83,5 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle); void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); -#endif // __FSK_H__ +#endif diff --git a/libs/openzap/src/dsp/uart.h b/libs/openzap/src/dsp/uart.h index bfad94ef38..89c3a13abc 100644 --- a/libs/openzap/src/dsp/uart.h +++ b/libs/openzap/src/dsp/uart.h @@ -1,4 +1,3 @@ - /* * uart.h * @@ -73,5 +72,5 @@ void dsp_uart_destroy(dsp_uart_handle_t **handle); void dsp_uart_bit_handler(void *handle, int bit); -#endif // __UART_H__ +#endif diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 53d2106d99..dcbbf41ef9 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -342,6 +342,11 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, zap_size_t *len, char *data, size_t datalen); +zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); +zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); +int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); + zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 607fa03366..6e4c8c1e0e 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -33,6 +33,7 @@ #ifndef ZAP_TYPES_H #define ZAP_TYPES_H +#include "fsk.h" #ifdef WIN32 #include @@ -57,6 +58,32 @@ struct zap_io_interface; typedef uint64_t zap_time_t; +typedef enum { + MDMF_DATETIME = 1, + MDMF_PHONE_NUM = 2, + MDMF_NO_NUM = 4, + MDMF_NAME = 7, + MDMF_NO_NAME = 8 +} zap_mdmf_type_t; + + +struct zap_fsk_data_state { + dsp_fsk_handle_t *fsk1200_handle; + uint8_t init; + uint8_t *buf; + size_t bufsize; + int blen; + int bpos; + int dlen; + int ppos; + uint8_t checksum; +}; +typedef struct zap_fsk_data_state zap_fsk_data_state_t; + +typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state); + + + #define ZAP_TONEMAP_LEN 128 typedef enum { ZAP_TONEMAP_NONE, @@ -139,7 +166,7 @@ typedef enum { ZAP_MEMERR, ZAP_TIMEOUT, ZAP_NOTIMPL, - + ZAP_CHECKSUM_ERROR, ZAP_STATUS_COUNT } zap_status_t; From 4ee9084576323b2607d2204fd11a336af55b21ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 00:57:02 +0000 Subject: [PATCH 0418/1766] add 1/2 of caller id code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@209 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 10 ++++++++-- libs/freetdm/src/dsp/fsk.h | 3 +-- libs/freetdm/src/dsp/uart.h | 3 +-- libs/freetdm/src/include/openzap.h | 5 +++++ libs/freetdm/src/include/zap_types.h | 29 +++++++++++++++++++++++++++- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 628702c594..5c259c578b 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -37,6 +37,9 @@ $(SRC)/zap_io.o \ $(SRC)/zap_isdn.o \ $(SRC)/zap_analog.o \ $(SRC)/zap_config.o \ +$(SRC)/zap_callerid.o \ +$(SRC)/dsp/fsk.o \ +$(SRC)/dsp/uart.o \ $(SRC)/g711.o \ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ @@ -61,7 +64,7 @@ HEADERS=$(SRC)/isdn/include/Q931.h \ $(SRC)/include/openzap.h PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include +INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -I$(PWD)/src/dsp CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a LIBPRIA=libpri.a @@ -79,6 +82,9 @@ $(MYLIB): $(OBJS) $(HEADERS) testapp: $(SRC)/testapp.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread +testcid: $(SRC)/testcid.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread @@ -124,6 +130,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/dsp/fsk.h index a2615b1fed..e9cf0c0c1c 100644 --- a/libs/freetdm/src/dsp/fsk.h +++ b/libs/freetdm/src/dsp/fsk.h @@ -1,4 +1,3 @@ - /* * bell202.h * @@ -84,5 +83,5 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle); void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); -#endif // __FSK_H__ +#endif diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h index bfad94ef38..89c3a13abc 100644 --- a/libs/freetdm/src/dsp/uart.h +++ b/libs/freetdm/src/dsp/uart.h @@ -1,4 +1,3 @@ - /* * uart.h * @@ -73,5 +72,5 @@ void dsp_uart_destroy(dsp_uart_handle_t **handle); void dsp_uart_bit_handler(void *handle, int bit); -#endif // __UART_H__ +#endif diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 53d2106d99..dcbbf41ef9 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -342,6 +342,11 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, zap_size_t *len, char *data, size_t datalen); +zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); +zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); +int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); + zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 607fa03366..6e4c8c1e0e 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -33,6 +33,7 @@ #ifndef ZAP_TYPES_H #define ZAP_TYPES_H +#include "fsk.h" #ifdef WIN32 #include @@ -57,6 +58,32 @@ struct zap_io_interface; typedef uint64_t zap_time_t; +typedef enum { + MDMF_DATETIME = 1, + MDMF_PHONE_NUM = 2, + MDMF_NO_NUM = 4, + MDMF_NAME = 7, + MDMF_NO_NAME = 8 +} zap_mdmf_type_t; + + +struct zap_fsk_data_state { + dsp_fsk_handle_t *fsk1200_handle; + uint8_t init; + uint8_t *buf; + size_t bufsize; + int blen; + int bpos; + int dlen; + int ppos; + uint8_t checksum; +}; +typedef struct zap_fsk_data_state zap_fsk_data_state_t; + +typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state); + + + #define ZAP_TONEMAP_LEN 128 typedef enum { ZAP_TONEMAP_NONE, @@ -139,7 +166,7 @@ typedef enum { ZAP_MEMERR, ZAP_TIMEOUT, ZAP_NOTIMPL, - + ZAP_CHECKSUM_ERROR, ZAP_STATUS_COUNT } zap_status_t; From 42c70840d8f753ef7f7fb385b5b606ca73fd1180 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 01:31:25 +0000 Subject: [PATCH 0419/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@210 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/fsk.c | 34 +++++++++++++++++++++++++++++++++- libs/openzap/src/dsp/fsk.h | 11 ++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/dsp/fsk.c b/libs/openzap/src/dsp/fsk.c index 8f4dfcad05..a53fa81e7b 100644 --- a/libs/openzap/src/dsp/fsk.c +++ b/libs/openzap/src/dsp/fsk.c @@ -306,7 +306,39 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) if (handle->cellpos > 1.0) { handle->cellpos -= 1.0; - (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + + + switch (handle->state) { + case FSK_STATE_DATA: + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + break; + case FSK_STATE_CHANSEIZE: + if (handle->last_bit != handle->current_bit) { + + + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_CARRIERSIG; + handle->conscutive_state_bits = 0; + } + break; + case FSK_STATE_CARRIERSIG: + if (handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_DATA; + handle->conscutive_state_bits = 0; + } + break; + } + + handle->last_bit = handle->current_bit; } } diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/dsp/fsk.h index e9cf0c0c1c..b494593ebf 100644 --- a/libs/openzap/src/dsp/fsk.h +++ b/libs/openzap/src/dsp/fsk.h @@ -35,6 +35,12 @@ #define __FSK_H__ #include "uart.h" +typedef enum { + FSK_STATE_CHANSEIZE = 0, + FSK_STATE_CARRIERSIG, + FSK_STATE_DATA +} fsk_state_t; + typedef struct dsp_fsk_attr_s { int sample_rate; /* sample rate in HZ */ @@ -46,7 +52,8 @@ typedef struct dsp_fsk_attr_s typedef struct { - dsp_fsk_attr_t attr; /* attributes structure */ + fsk_state_t state; + dsp_fsk_attr_t attr; /* attributes structure */ double *correlates[4]; /* one for each of sin/cos for mark/space */ int corrsize; /* correlate size (also number of samples in ring buffer) */ double *buffer; /* sample ring buffer */ @@ -55,8 +62,10 @@ typedef struct double celladj; /* bit cell adjustment for each sample */ int previous_bit; /* previous bit (for detecting a transition to sync-up cell position) */ int current_bit; /* current bit */ + int last_bit; int downsampling_count; /* number of samples to skip */ int current_downsample; /* current skip count */ + int conscutive_state_bits; /* number of bits in a row that matches the pattern for the current state */ } dsp_fsk_handle_t; /* From 7fd17121c856efc56d41619f40bfdf304872e7fb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 01:31:25 +0000 Subject: [PATCH 0420/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@210 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/fsk.c | 34 +++++++++++++++++++++++++++++++++- libs/freetdm/src/dsp/fsk.h | 11 ++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/dsp/fsk.c b/libs/freetdm/src/dsp/fsk.c index 8f4dfcad05..a53fa81e7b 100644 --- a/libs/freetdm/src/dsp/fsk.c +++ b/libs/freetdm/src/dsp/fsk.c @@ -306,7 +306,39 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) if (handle->cellpos > 1.0) { handle->cellpos -= 1.0; - (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + + + switch (handle->state) { + case FSK_STATE_DATA: + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + break; + case FSK_STATE_CHANSEIZE: + if (handle->last_bit != handle->current_bit) { + + + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_CARRIERSIG; + handle->conscutive_state_bits = 0; + } + break; + case FSK_STATE_CARRIERSIG: + if (handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_DATA; + handle->conscutive_state_bits = 0; + } + break; + } + + handle->last_bit = handle->current_bit; } } diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/dsp/fsk.h index e9cf0c0c1c..b494593ebf 100644 --- a/libs/freetdm/src/dsp/fsk.h +++ b/libs/freetdm/src/dsp/fsk.h @@ -35,6 +35,12 @@ #define __FSK_H__ #include "uart.h" +typedef enum { + FSK_STATE_CHANSEIZE = 0, + FSK_STATE_CARRIERSIG, + FSK_STATE_DATA +} fsk_state_t; + typedef struct dsp_fsk_attr_s { int sample_rate; /* sample rate in HZ */ @@ -46,7 +52,8 @@ typedef struct dsp_fsk_attr_s typedef struct { - dsp_fsk_attr_t attr; /* attributes structure */ + fsk_state_t state; + dsp_fsk_attr_t attr; /* attributes structure */ double *correlates[4]; /* one for each of sin/cos for mark/space */ int corrsize; /* correlate size (also number of samples in ring buffer) */ double *buffer; /* sample ring buffer */ @@ -55,8 +62,10 @@ typedef struct double celladj; /* bit cell adjustment for each sample */ int previous_bit; /* previous bit (for detecting a transition to sync-up cell position) */ int current_bit; /* current bit */ + int last_bit; int downsampling_count; /* number of samples to skip */ int current_downsample; /* current skip count */ + int conscutive_state_bits; /* number of bits in a row that matches the pattern for the current state */ } dsp_fsk_handle_t; /* From e68ece0f1c4d37de9358228aa784287dfa3a64ed Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 02:48:50 +0000 Subject: [PATCH 0421/1766] fix windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@211 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 4 ++-- libs/openzap/src/include/zap_types.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 84fe2d134b..f677bc216b 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -41,7 +41,7 @@ Date: Tue, 5 Jun 2007 02:48:50 +0000 Subject: [PATCH 0422/1766] fix windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@211 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 4 ++-- libs/freetdm/src/include/zap_types.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 84fe2d134b..f677bc216b 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -41,7 +41,7 @@ Date: Tue, 5 Jun 2007 03:04:35 +0000 Subject: [PATCH 0423/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@212 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/testcid.c | 35 ++++++++++++++++++++++++++++++ libs/openzap/src/zap_io.c | 6 ++--- libs/openzap/src/zap_wanpipe.c | 5 ++++- libs/openzap/src/zap_zt.c | 1 + 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 libs/openzap/src/testcid.c diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index dcbbf41ef9..f7a020d4c8 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -237,6 +237,7 @@ struct zap_channel { uint32_t chan_id; uint32_t physical_span_id; uint32_t physical_chan_id; + uint32_t rate; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c new file mode 100644 index 0000000000..f91ee59d96 --- /dev/null +++ b/libs/openzap/src/testcid.c @@ -0,0 +1,35 @@ +#include "openzap.h" + +int main(int argc, char *argv[]) +{ + zap_fsk_data_state_t state = {0}; + int fd; + int16_t buf[160] = {0}; + ssize_t len = 0; + int type, mlen; + char str[128]; + char fbuf[256]; + + if (argc < 2 || zap_fsk_demod_init(&state, 8000, 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(&state, buf, len / 2) != ZAP_SUCCESS) { + break; + } + } + + while(zap_fsk_data_parse(&state, &type, &mlen, str, sizeof(str)) == ZAP_SUCCESS) { + printf("TYPE %d LEN %d VAL [%s]\n", type, mlen, str); + } + + + close(fd); +} diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 96089c5322..a792ab6b0f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -770,7 +770,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); teletone_init_session(&zchan->tone_session, 0, NULL, NULL); - zchan->tone_session.rate = 8000; + zchan->tone_session.rate = zchan->rate; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); /* @@ -910,7 +910,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); GOTO_STATUS(done, ZAP_SUCCESS); @@ -926,7 +926,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); GOTO_STATUS(done, ZAP_SUCCESS); diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 3e9e7501de..c5883bdd86 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -36,7 +36,8 @@ #include "openzap.h" #include "zap_wanpipe.h" -#include +/*#include */ +#include static struct { uint32_t codec_ms; @@ -74,6 +75,8 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); chan->physical_span_id = spanno; chan->physical_chan_id = x; + chan->rate = 8000; + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 49d9edea60..db940d5c54 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -90,6 +90,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + chan->rate = 8000; chan->physical_span_id = ztp.span_no; chan->physical_chan_id = ztp.chan_no; From 9d1b4458841be8ec8a7bb41443b442bcbc476aa7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 03:04:35 +0000 Subject: [PATCH 0424/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@212 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/testcid.c | 35 ++++++++++++++++++++++++++++++ libs/freetdm/src/zap_io.c | 6 ++--- libs/freetdm/src/zap_wanpipe.c | 5 ++++- libs/freetdm/src/zap_zt.c | 1 + 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 libs/freetdm/src/testcid.c diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index dcbbf41ef9..f7a020d4c8 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -237,6 +237,7 @@ struct zap_channel { uint32_t chan_id; uint32_t physical_span_id; uint32_t physical_chan_id; + uint32_t rate; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c new file mode 100644 index 0000000000..f91ee59d96 --- /dev/null +++ b/libs/freetdm/src/testcid.c @@ -0,0 +1,35 @@ +#include "openzap.h" + +int main(int argc, char *argv[]) +{ + zap_fsk_data_state_t state = {0}; + int fd; + int16_t buf[160] = {0}; + ssize_t len = 0; + int type, mlen; + char str[128]; + char fbuf[256]; + + if (argc < 2 || zap_fsk_demod_init(&state, 8000, 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(&state, buf, len / 2) != ZAP_SUCCESS) { + break; + } + } + + while(zap_fsk_data_parse(&state, &type, &mlen, str, sizeof(str)) == ZAP_SUCCESS) { + printf("TYPE %d LEN %d VAL [%s]\n", type, mlen, str); + } + + + close(fd); +} diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 96089c5322..a792ab6b0f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -770,7 +770,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); teletone_init_session(&zchan->tone_session, 0, NULL, NULL); - zchan->tone_session.rate = 8000; + zchan->tone_session.rate = zchan->rate; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); /* @@ -910,7 +910,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); GOTO_STATUS(done, ZAP_SUCCESS); @@ -926,7 +926,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, 8000); + teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); GOTO_STATUS(done, ZAP_SUCCESS); diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 3e9e7501de..c5883bdd86 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -36,7 +36,8 @@ #include "openzap.h" #include "zap_wanpipe.h" -#include +/*#include */ +#include static struct { uint32_t codec_ms; @@ -74,6 +75,8 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); chan->physical_span_id = spanno; chan->physical_chan_id = x; + chan->rate = 8000; + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 49d9edea60..db940d5c54 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -90,6 +90,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + chan->rate = 8000; chan->physical_span_id = ztp.span_no; chan->physical_chan_id = ztp.chan_no; From 204d5e452d646ec0525aa5e977b2cc7abdb5c283 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 03:56:59 +0000 Subject: [PATCH 0425/1766] add v.23 modem definitions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@213 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/fsk.c | 8 ++++++++ libs/openzap/src/dsp/fsk.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libs/openzap/src/dsp/fsk.c b/libs/openzap/src/dsp/fsk.c index a53fa81e7b..d2beee6484 100644 --- a/libs/openzap/src/dsp/fsk.c +++ b/libs/openzap/src/dsp/fsk.c @@ -55,6 +55,14 @@ #define V23_SPACE 2100 #define V23_BAUD 1200 +static fsk_modem_definition_t fsk_modem_definitions[] = +{ + { /* FSK_V23_FORWARD_MODE1 */ 1700, 1300, 600 }, + { /* FSK_V23_FORWARD_MODE2 */ 2100, 1300, 1200 }, + { /* FSK_V23_BACKWARD */ 450, 390, 75 }, + { /* FSK_BELL202 */ 2200, 1200, 1200 }, +}; + /* * dsp_fsk_attr_init * diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/dsp/fsk.h index b494593ebf..0f800bdc12 100644 --- a/libs/openzap/src/dsp/fsk.h +++ b/libs/openzap/src/dsp/fsk.h @@ -35,6 +35,20 @@ #define __FSK_H__ #include "uart.h" +typedef struct { + int freq_space; /* Frequency of the 0 bit */ + int freq_mark; /* Frequency of the 1 bit */ + int baud_rate; /* baud rate for the modem */ +} fsk_modem_definition_t; + +/* Must be kept in sync with fsk_modem_definitions array in fsk.c */ +typedef enum { + FSK_V23_FORWARD_MODE1 = 0, /* Maximum 600 bps for long haul */ + FSK_V23_FORWARD_MODE2, /* Standard 1200 bps V.23 */ + FSK_V23_BACKWARD, /* 75 bps return path for V.23 */ + FSK_BELL202 /* Bell 202 half-duplex 1200 bps */ +} fsk_modem_types_t; + typedef enum { FSK_STATE_CHANSEIZE = 0, FSK_STATE_CARRIERSIG, From 0b030c865e8ee9330e724e29d08225636af696a4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 03:56:59 +0000 Subject: [PATCH 0426/1766] add v.23 modem definitions. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@213 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/fsk.c | 8 ++++++++ libs/freetdm/src/dsp/fsk.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libs/freetdm/src/dsp/fsk.c b/libs/freetdm/src/dsp/fsk.c index a53fa81e7b..d2beee6484 100644 --- a/libs/freetdm/src/dsp/fsk.c +++ b/libs/freetdm/src/dsp/fsk.c @@ -55,6 +55,14 @@ #define V23_SPACE 2100 #define V23_BAUD 1200 +static fsk_modem_definition_t fsk_modem_definitions[] = +{ + { /* FSK_V23_FORWARD_MODE1 */ 1700, 1300, 600 }, + { /* FSK_V23_FORWARD_MODE2 */ 2100, 1300, 1200 }, + { /* FSK_V23_BACKWARD */ 450, 390, 75 }, + { /* FSK_BELL202 */ 2200, 1200, 1200 }, +}; + /* * dsp_fsk_attr_init * diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/dsp/fsk.h index b494593ebf..0f800bdc12 100644 --- a/libs/freetdm/src/dsp/fsk.h +++ b/libs/freetdm/src/dsp/fsk.h @@ -35,6 +35,20 @@ #define __FSK_H__ #include "uart.h" +typedef struct { + int freq_space; /* Frequency of the 0 bit */ + int freq_mark; /* Frequency of the 1 bit */ + int baud_rate; /* baud rate for the modem */ +} fsk_modem_definition_t; + +/* Must be kept in sync with fsk_modem_definitions array in fsk.c */ +typedef enum { + FSK_V23_FORWARD_MODE1 = 0, /* Maximum 600 bps for long haul */ + FSK_V23_FORWARD_MODE2, /* Standard 1200 bps V.23 */ + FSK_V23_BACKWARD, /* 75 bps return path for V.23 */ + FSK_BELL202 /* Bell 202 half-duplex 1200 bps */ +} fsk_modem_types_t; + typedef enum { FSK_STATE_CHANSEIZE = 0, FSK_STATE_CARRIERSIG, From 215287813acef3267b00d5da4c5de9487f561a49 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 03:59:28 +0000 Subject: [PATCH 0427/1766] add reference url. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@214 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/fsk.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/dsp/fsk.h index 0f800bdc12..e6ca995d57 100644 --- a/libs/openzap/src/dsp/fsk.h +++ b/libs/openzap/src/dsp/fsk.h @@ -42,6 +42,7 @@ typedef struct { } fsk_modem_definition_t; /* Must be kept in sync with fsk_modem_definitions array in fsk.c */ +/* V.23 definitions: http://www.itu.int/rec/recommendation.asp?type=folders&lang=e&parent=T-REC-V.23 */ typedef enum { FSK_V23_FORWARD_MODE1 = 0, /* Maximum 600 bps for long haul */ FSK_V23_FORWARD_MODE2, /* Standard 1200 bps V.23 */ From 7e410bb608bbb5ddde2993017f94aadd1b376925 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 03:59:28 +0000 Subject: [PATCH 0428/1766] add reference url. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@214 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/fsk.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/dsp/fsk.h index 0f800bdc12..e6ca995d57 100644 --- a/libs/freetdm/src/dsp/fsk.h +++ b/libs/freetdm/src/dsp/fsk.h @@ -42,6 +42,7 @@ typedef struct { } fsk_modem_definition_t; /* Must be kept in sync with fsk_modem_definitions array in fsk.c */ +/* V.23 definitions: http://www.itu.int/rec/recommendation.asp?type=folders&lang=e&parent=T-REC-V.23 */ typedef enum { FSK_V23_FORWARD_MODE1 = 0, /* Maximum 600 bps for long haul */ FSK_V23_FORWARD_MODE2, /* Standard 1200 bps V.23 */ From 6bf627a3d43d570fa5fca4e4466e5ec4cbed0187 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 04:23:58 +0000 Subject: [PATCH 0429/1766] use the fsk_modem_definitions array git-svn-id: http://svn.openzap.org/svn/openzap/trunk@215 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/dsp/fsk.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libs/openzap/src/dsp/fsk.c b/libs/openzap/src/dsp/fsk.c index d2beee6484..69b2edfc88 100644 --- a/libs/openzap/src/dsp/fsk.c +++ b/libs/openzap/src/dsp/fsk.c @@ -46,15 +46,6 @@ #define M_PI 3.14159265358979323846 #endif -/* local constants */ -#define BELL202_MARK 1200 -#define BELL202_SPACE 2200 -#define BELL202_BAUD 1200 - -#define V23_MARK 1300 -#define V23_SPACE 2100 -#define V23_BAUD 1200 - static fsk_modem_definition_t fsk_modem_definitions[] = { { /* FSK_V23_FORWARD_MODE1 */ 1700, 1300, 600 }, @@ -154,15 +145,15 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) memcpy(&handle->attr, attr, sizeof(*attr)); /* see if we can do downsampling. We only really need 6 samples to "match" */ - if (attr->sample_rate / BELL202_MARK > 6) { - handle->downsampling_count = attr->sample_rate / BELL202_MARK / 6; + if (attr->sample_rate / fsk_modem_definitions[FSK_BELL202].freq_mark > 6) { + handle->downsampling_count = attr->sample_rate / fsk_modem_definitions[FSK_BELL202].freq_mark / 6; } else { handle->downsampling_count = 1; } handle->current_downsample = 1; /* calculate the correlate size (number of samples required for slowest wave) */ - handle->corrsize = attr->sample_rate / handle->downsampling_count / BELL202_MARK; + handle->corrsize = attr->sample_rate / handle->downsampling_count / fsk_modem_definitions[FSK_BELL202].freq_mark; /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { @@ -175,8 +166,8 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) } /* now initialize them */ - phi_mark = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_MARK); - phi_space = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_SPACE); + phi_mark = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) fsk_modem_definitions[FSK_BELL202].freq_mark); + phi_space = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) fsk_modem_definitions[FSK_BELL202].freq_space); for (i = 0; i < handle->corrsize; i++) { handle->correlates[0][i] = sin(phi_mark * (double) i); @@ -196,7 +187,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) /* initalize intra-cell position */ handle->cellpos = 0; - handle->celladj = BELL202_BAUD / (double) attr->sample_rate * (double) handle->downsampling_count; + handle->celladj = fsk_modem_definitions[FSK_BELL202].baud_rate / (double) attr->sample_rate * (double) handle->downsampling_count; /* if they have provided a byte handler, add a UART to the processing chain */ if (handle->attr.bytehandler) { From 9db8af8e8fdcf658fef422780928b52685138117 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 04:23:58 +0000 Subject: [PATCH 0430/1766] use the fsk_modem_definitions array git-svn-id: http://svn.openzap.org/svn/openzap/trunk@215 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/fsk.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libs/freetdm/src/dsp/fsk.c b/libs/freetdm/src/dsp/fsk.c index d2beee6484..69b2edfc88 100644 --- a/libs/freetdm/src/dsp/fsk.c +++ b/libs/freetdm/src/dsp/fsk.c @@ -46,15 +46,6 @@ #define M_PI 3.14159265358979323846 #endif -/* local constants */ -#define BELL202_MARK 1200 -#define BELL202_SPACE 2200 -#define BELL202_BAUD 1200 - -#define V23_MARK 1300 -#define V23_SPACE 2100 -#define V23_BAUD 1200 - static fsk_modem_definition_t fsk_modem_definitions[] = { { /* FSK_V23_FORWARD_MODE1 */ 1700, 1300, 600 }, @@ -154,15 +145,15 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) memcpy(&handle->attr, attr, sizeof(*attr)); /* see if we can do downsampling. We only really need 6 samples to "match" */ - if (attr->sample_rate / BELL202_MARK > 6) { - handle->downsampling_count = attr->sample_rate / BELL202_MARK / 6; + if (attr->sample_rate / fsk_modem_definitions[FSK_BELL202].freq_mark > 6) { + handle->downsampling_count = attr->sample_rate / fsk_modem_definitions[FSK_BELL202].freq_mark / 6; } else { handle->downsampling_count = 1; } handle->current_downsample = 1; /* calculate the correlate size (number of samples required for slowest wave) */ - handle->corrsize = attr->sample_rate / handle->downsampling_count / BELL202_MARK; + handle->corrsize = attr->sample_rate / handle->downsampling_count / fsk_modem_definitions[FSK_BELL202].freq_mark; /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { @@ -175,8 +166,8 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) } /* now initialize them */ - phi_mark = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_MARK); - phi_space = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) BELL202_SPACE); + phi_mark = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) fsk_modem_definitions[FSK_BELL202].freq_mark); + phi_space = 2. * M_PI / ((double) attr->sample_rate / (double) handle->downsampling_count / (double) fsk_modem_definitions[FSK_BELL202].freq_space); for (i = 0; i < handle->corrsize; i++) { handle->correlates[0][i] = sin(phi_mark * (double) i); @@ -196,7 +187,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) /* initalize intra-cell position */ handle->cellpos = 0; - handle->celladj = BELL202_BAUD / (double) attr->sample_rate * (double) handle->downsampling_count; + handle->celladj = fsk_modem_definitions[FSK_BELL202].baud_rate / (double) attr->sample_rate * (double) handle->downsampling_count; /* if they have provided a byte handler, add a UART to the processing chain */ if (handle->attr.bytehandler) { From b23a8ae4d628db6e3df068fda7c8ca9348798854 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 04:37:50 +0000 Subject: [PATCH 0431/1766] update1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@216 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 19 +- libs/openzap/src/dsp/readme.txt | 50 --- libs/openzap/src/{dsp => }/fsk.c | 0 libs/openzap/src/{dsp => }/fsk.h | 0 libs/openzap/src/include/sangoma_tdm_api.h | 118 ------- .../src/include/wanpipe_tdm_api_iface.h | 314 +++++++++++++++++ libs/openzap/src/{dsp => }/uart.c | 0 libs/openzap/src/{dsp => }/uart.h | 0 libs/openzap/src/zap_io.c | 2 + libs/openzap/src/zap_wanpipe.c | 317 +++++++++++++++++- libs/openzap/src/zap_zt.c | 12 +- libs/openzap/wanpipe | 10 - libs/openzap/zt | 2 - 13 files changed, 631 insertions(+), 213 deletions(-) delete mode 100644 libs/openzap/src/dsp/readme.txt rename libs/openzap/src/{dsp => }/fsk.c (100%) rename libs/openzap/src/{dsp => }/fsk.h (100%) create mode 100644 libs/openzap/src/include/wanpipe_tdm_api_iface.h rename libs/openzap/src/{dsp => }/uart.c (100%) rename libs/openzap/src/{dsp => }/uart.h (100%) delete mode 100644 libs/openzap/wanpipe delete mode 100644 libs/openzap/zt diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 5c259c578b..64d1910a94 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -38,8 +38,8 @@ $(SRC)/zap_isdn.o \ $(SRC)/zap_analog.o \ $(SRC)/zap_config.o \ $(SRC)/zap_callerid.o \ -$(SRC)/dsp/fsk.o \ -$(SRC)/dsp/uart.o \ +$(SRC)/fsk.o \ +$(SRC)/uart.o \ $(SRC)/g711.o \ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ @@ -58,20 +58,23 @@ $(SRC)/isdn/Q931StateTE.o \ $(SRC)/isdn/nationalmes.o \ $(SRC)/isdn/nationalStateNT.o \ $(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/Q932mes.o +$(SRC)/isdn/Q932mes.o \ +$(SRC)/zap_zt.o \ +$(SRC)/zap_wanpipe.o + HEADERS=$(SRC)/isdn/include/Q931.h \ $(SRC)/include/openzap.h PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -I$(PWD)/src/dsp +INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w -include general.makefile $(ZAP_MODS) +include general.makefile all: $(MYLIB) @@ -106,12 +109,6 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -$(SRC)/zap_wanpipe.o: $(SRC)/zap_wanpipe.c - $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ - -$(SRC)/zap_zt.o: $(SRC)/zap_zt.c - $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@ - %.o: %.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/openzap/src/dsp/readme.txt b/libs/openzap/src/dsp/readme.txt deleted file mode 100644 index 6a71f9bf10..0000000000 --- a/libs/openzap/src/dsp/readme.txt +++ /dev/null @@ -1,50 +0,0 @@ -I have only tested the library with samples at 8kHz. It *should* work with arbitrary sample rates; the "optr" variable in the code samples below is the sampling rate in Hz. - -The first thing you need to do is initialize a context structure: - - dsp_fsk_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem - dsp_fsk_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem - - // initialize: - dsp_fsk_attr_init (&fsk1200_attr); // clear attributes structure - dsp_fsk_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate - dsp_fsk_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler - - // create context: - fsk1200_handle = dsp_fsk_create (&fsk1200_attr); - - // error check: - if (fsk1200_handle == NULL) { - fprintf (stderr, "%s: can't dsp_fsk_create, errno %d (%s)\n", progname, errno, strerror (errno)); - exit (EXIT_FAILURE); - } - -If you are decoding multiple channels, you will need multiple context structures; one per channel. -The attributes ("dsp_fsk_attr_t") do not have to be persistent, but the handle does. -There's even a "dsp_fsk_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. - -Then, you need to feed samples into the software modem: - dsp_fsk_sample (fsk1200_handle, (double) sample / 32767.); - -It assumes the samples are between -1 and 1 as a double. - -It will outcall to your provided "clid_byte_handler()" function, which needs to have a prototype as follows: - - void clid_byte_handler (void *x, int data); - -The "x" is a context "void *" that you can associate in the fsk1200_handle (great for multiple channels). - -This will dribble bytes out to you at 1200 baud. - -From there, you are on your own. Canadian caller ID streams are different format than US caller ID streams IIRC. Both are trivial to figure out, as they have lots of ASCII data. I can supply some more code later on the Canadian one if you need it. - -Here's a sample of a Canadian caller ID stream from when you called: - -00000000: 55 55 55 55 55 55 55 55-55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU -00000010: 55 55 D5 80 1D 01 08 30-36 30 31 31 36 31 36 08 UU.....06011616. -00000020: 01 4F 03 0B 31 32 34 38-35 35 35 31 32 31 32 06 .O..12485551212. -00000030: 01 4C D1 85 00 02 54 00-02 C5 60 28 10 0A 80 30 .L....T...`(...0 - -The "UUUUU" is an alternating series of ones and zeros (which, when combined with the start and stop bits, creates the 0x55 character "U") used to train analog modems. -06011616 is the date and time (JUN 01 16:16), the "O" at 0x21 is an "Out of area" -qualifier for why your name didn't appear, and "1248..." is your DN. The "L" at 0x31 is a long distance qualifier. diff --git a/libs/openzap/src/dsp/fsk.c b/libs/openzap/src/fsk.c similarity index 100% rename from libs/openzap/src/dsp/fsk.c rename to libs/openzap/src/fsk.c diff --git a/libs/openzap/src/dsp/fsk.h b/libs/openzap/src/fsk.h similarity index 100% rename from libs/openzap/src/dsp/fsk.h rename to libs/openzap/src/fsk.h diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index d4e673cc5e..08ae5cf00d 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -87,124 +87,6 @@ struct iphdr { #define FNAME_LEN 50 -/* what should the returns from this function be?? */ -/* I dont think they are currently consistant between windows and *nix */ -#ifdef __WINDOWS__ -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) -{ - /* can we make the structure passed for this on nix and windows the same */ - /* so we don't have to do the extra 2 memcpy's on windows for this ? */ - wan_udp_hdr_t wan_udp; - DWORD ln; - unsigned char id = 0; - - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; - wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); - - memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); - - if (DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - } - - if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - return 2; - } - - memcpy( (void*)tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t)); - return 0; -} - -#else -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) -{ - return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); -} -#endif - -void __inline__ tdmv_api_close_socket(sng_fd_t *sp) -{ - if ( *sp != WP_INVALID_SOCKET){ -#if defined(__WINDOWS__) - CloseHandle(*sp); -#else - close(*sp); -#endif - *sp = WP_INVALID_SOCKET; - } -} - -static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) -{ - char fname[FNAME_LEN]; - sng_fd_t fd = WP_INVALID_SOCKET; -#if defined(__WINDOWS__) - DWORD ln; - wan_udp_hdr_t wan_udp; - - /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ - /* Subtract 1 from 'chan'. */ - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - fd = CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); - - /* make sure that we are the only ones who have this chan open */ - /* is this a threadsafe way to make sure that we are ok and will */ - /* never return a valid handle to more than one thread for the same channel? */ - - wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; - wan_udp.wan_udphdr_data_len = 0; - - DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ); - - if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ - /* somone already has this channel, or somthing else is not right. */ - tdmv_api_close_socket(&fd); - } - -#else - /* Does this fail if another thread already has this chan open? */ - /* if not, we need to add some code to make sure it does */ - snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - -#endif - return fd; -} #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 */ diff --git a/libs/openzap/src/include/wanpipe_tdm_api_iface.h b/libs/openzap/src/include/wanpipe_tdm_api_iface.h new file mode 100644 index 0000000000..f7406841f5 --- /dev/null +++ b/libs/openzap/src/include/wanpipe_tdm_api_iface.h @@ -0,0 +1,314 @@ +/***************************************************************************** +* wanpipe_tdm_api.h +* +* WANPIPE(tm) AFT TE1 Hardware Support +* +* Authors: Nenad Corbic +* +* Copyright (c) 2007, 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 + +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, + + SIOC_WP_TDM_SET_RX_GAINS, + SIOC_WP_TDM_SET_TX_GAINS, + SIOC_WP_TDM_CLEAR_RX_GAINS, + SIOC_WP_TDM_CLEAR_TX_GAINS, + + SIOC_WP_TDM_GET_FE_ALARMS, + + SIOC_WP_TDM_ENABLE_HWEC, + SIOC_WP_TDM_DISABLE_HWEC, + + SIOC_WP_TDM_NOTSUPP /* */ + + +}; + +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 +}; + +#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)" + +#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 + + +typedef struct { + + u_int8_t type; + u_int8_t mode; + u_int32_t time_stamp; + u_int16_t channel; + u_int32_t chan_map; + 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; + } 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 +} 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 */ + wp_tdm_api_event_t event; /* TDM Event */ + unsigned int data_len; + void *data; +}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); +}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/dsp/uart.c b/libs/openzap/src/uart.c similarity index 100% rename from libs/openzap/src/dsp/uart.c rename to libs/openzap/src/uart.c diff --git a/libs/openzap/src/dsp/uart.h b/libs/openzap/src/uart.h similarity index 100% rename from libs/openzap/src/dsp/uart.h rename to libs/openzap/src/uart.h diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a792ab6b0f..6f6bdb6940 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -31,6 +31,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define ZAP_ZT_SUPPORT +#define ZAP_WANPIPE_SUPPORT #include "openzap.h" #include "zap_isdn.h" #include diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index c5883bdd86..bdbde9526f 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -31,13 +31,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define WANPIPE_TDM_API 1 - #include "openzap.h" #include "zap_wanpipe.h" +#include +#include +#include -/*#include */ -#include +#define WP_INVALID_SOCKET -1 + +#include static struct { uint32_t codec_ms; @@ -45,14 +47,288 @@ static struct { uint32_t flash_ms; } wp_globals; +#define SIOC_WANPIPE_TDM_API 1 + +/* 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 */ + uint32_t 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; +} + +/* 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 +} + +#define FNAME_LEN 128 +static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) +{ + char fname[FNAME_LEN]; + sng_fd_t fd = WP_INVALID_SOCKET; +#if defined(__WINDOWS__) + DWORD ln; + wan_udp_hdr_t wan_udp; + + /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ + /* Subtract 1 from 'chan'. */ + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + fd = CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); + + /* make sure that we are the only ones who have this chan open */ + /* is this a threadsafe way to make sure that we are ok and will */ + /* never return a valid handle to more than one thread for the same channel? */ + + wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; + wan_udp.wan_udphdr_data_len = 0; + + DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ); + + if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ + /* somone already has this channel, or somthing else is not right. */ + tdmv_api_close_socket(&fd); + } + +#else + /* Does this fail if another thread already has this chan open? */ + /* if not, we need to add some code to make sure it does */ + snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); + + fd = open(fname, O_RDWR); + + if (fd < 0) { + fd = WP_INVALID_SOCKET; + } + +#endif + return fd; +} + + + static zap_io_interface_t wanpipe_interface; static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) { int err; - err = tdmv_api_ioctl(zchan->sockfd, tdm_api); - + /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ + err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; @@ -80,11 +356,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - + if (type == ZAP_CHAN_TYPE_FXS) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RING_DETECT_EVENTS; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); } @@ -219,7 +498,7 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = WP_NONE; + tdm_api.wp_tdm_cmd.tdm_codec = 0; wp_tdm_cmd_exec(zchan, &tdm_api); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; @@ -366,7 +645,8 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; - int i, j = 0, k = 0, l = 0, r; + uint32_t i, j = 0, k = 0, l = 0; + int r; for(i = 1; i <= span->chan_count; i++) { memset(&pfds[j], 0, sizeof(pfds[j])); @@ -442,9 +722,9 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { - case WP_TDM_EVENT_RXHOOK: + case WP_TDMAPI_EVENT_RXHOOK: { - event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rxhook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? ZAP_OOB_OFFHOOK : ZAP_OOB_ONHOOK; + 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)) { @@ -468,11 +748,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) continue; } break; - case WP_TDM_EVENT_RING_DETECT: + 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; - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RING_DETECT_EVENTS; - wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + } break; default: @@ -499,8 +778,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) static ZIO_DESTROY_CHANNEL_FUNCTION(wanpipe_destroy_channel) { - tdmv_api_close_socket(&zchan->sockfd); - zchan->sockfd = WP_INVALID_SOCKET; + if (zchan->sockfd > -1) { + close(zchan->sockfd); + zchan->sockfd = WP_INVALID_SOCKET; + } return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index db940d5c54..26ac640f79 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -49,7 +49,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za { unsigned configured = 0, x; char path[128] = ""; - zt_params_t ztp = {0}; + zt_params_t ztp; + + memset(&ztp, 0, sizeof(ztp)); for(x = start; x < end; x++) { zap_channel_t *chan; @@ -236,9 +238,11 @@ static ZIO_CLOSE_FUNCTION(zt_close) static ZIO_COMMAND_FUNCTION(zt_command) { - zt_params_t ztp = {0}; + zt_params_t ztp; int err = 0; + memset(&ztp, 0, sizeof(ztp)); + switch(command) { case ZAP_COMMAND_OFFHOOK: { @@ -385,7 +389,8 @@ static ZIO_WAIT_FUNCTION(zt_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; - int i, j = 0, k = 0, r, e; + uint32_t i, j = 0, k = 0; + int r; for(i = 1; i <= span->chan_count; i++) { memset(&pfds[j], 0, sizeof(pfds[j])); @@ -474,7 +479,6 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; } - event: span->channels[i].last_event_time = 0; span->event_header.e_type = ZAP_EVENT_OOB; span->event_header.enum_id = event_id; diff --git a/libs/openzap/wanpipe b/libs/openzap/wanpipe deleted file mode 100644 index 4165283537..0000000000 --- a/libs/openzap/wanpipe +++ /dev/null @@ -1,10 +0,0 @@ -MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT -OBJS += $(SRC)/zap_wanpipe.o -WANPIPE_INCLUDE=/usr/include/wanpipe - -WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include -WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API - - - - diff --git a/libs/openzap/zt b/libs/openzap/zt deleted file mode 100644 index 28934f3b56..0000000000 --- a/libs/openzap/zt +++ /dev/null @@ -1,2 +0,0 @@ -MOD_CFLAGS +=-DZAP_ZT_SUPPORT -OBJS += $(SRC)/zap_zt.o From 82c58d1030000284881b136c38ec2b6ec0414f41 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 04:37:50 +0000 Subject: [PATCH 0432/1766] update1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@216 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 19 +- libs/freetdm/src/dsp/readme.txt | 50 --- libs/freetdm/src/{dsp => }/fsk.c | 0 libs/freetdm/src/{dsp => }/fsk.h | 0 libs/freetdm/src/include/sangoma_tdm_api.h | 118 ------- .../src/include/wanpipe_tdm_api_iface.h | 314 +++++++++++++++++ libs/freetdm/src/{dsp => }/uart.c | 0 libs/freetdm/src/{dsp => }/uart.h | 0 libs/freetdm/src/zap_io.c | 2 + libs/freetdm/src/zap_wanpipe.c | 317 +++++++++++++++++- libs/freetdm/src/zap_zt.c | 12 +- libs/freetdm/wanpipe | 10 - libs/freetdm/zt | 2 - 13 files changed, 631 insertions(+), 213 deletions(-) delete mode 100644 libs/freetdm/src/dsp/readme.txt rename libs/freetdm/src/{dsp => }/fsk.c (100%) rename libs/freetdm/src/{dsp => }/fsk.h (100%) create mode 100644 libs/freetdm/src/include/wanpipe_tdm_api_iface.h rename libs/freetdm/src/{dsp => }/uart.c (100%) rename libs/freetdm/src/{dsp => }/uart.h (100%) delete mode 100644 libs/freetdm/wanpipe delete mode 100644 libs/freetdm/zt diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 5c259c578b..64d1910a94 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -38,8 +38,8 @@ $(SRC)/zap_isdn.o \ $(SRC)/zap_analog.o \ $(SRC)/zap_config.o \ $(SRC)/zap_callerid.o \ -$(SRC)/dsp/fsk.o \ -$(SRC)/dsp/uart.o \ +$(SRC)/fsk.o \ +$(SRC)/uart.o \ $(SRC)/g711.o \ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ @@ -58,20 +58,23 @@ $(SRC)/isdn/Q931StateTE.o \ $(SRC)/isdn/nationalmes.o \ $(SRC)/isdn/nationalStateNT.o \ $(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/Q932mes.o +$(SRC)/isdn/Q932mes.o \ +$(SRC)/zap_zt.o \ +$(SRC)/zap_wanpipe.o + HEADERS=$(SRC)/isdn/include/Q931.h \ $(SRC)/include/openzap.h PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -I$(PWD)/src/dsp +INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include CFLAGS=$(ZAP_CFLAGS) $(INCS) MYLIB=libopenzap.a LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w -include general.makefile $(ZAP_MODS) +include general.makefile all: $(MYLIB) @@ -106,12 +109,6 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -$(SRC)/zap_wanpipe.o: $(SRC)/zap_wanpipe.c - $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@ - -$(SRC)/zap_zt.o: $(SRC)/zap_zt.c - $(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@ - %.o: %.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ diff --git a/libs/freetdm/src/dsp/readme.txt b/libs/freetdm/src/dsp/readme.txt deleted file mode 100644 index 6a71f9bf10..0000000000 --- a/libs/freetdm/src/dsp/readme.txt +++ /dev/null @@ -1,50 +0,0 @@ -I have only tested the library with samples at 8kHz. It *should* work with arbitrary sample rates; the "optr" variable in the code samples below is the sampling rate in Hz. - -The first thing you need to do is initialize a context structure: - - dsp_fsk_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem - dsp_fsk_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem - - // initialize: - dsp_fsk_attr_init (&fsk1200_attr); // clear attributes structure - dsp_fsk_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate - dsp_fsk_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler - - // create context: - fsk1200_handle = dsp_fsk_create (&fsk1200_attr); - - // error check: - if (fsk1200_handle == NULL) { - fprintf (stderr, "%s: can't dsp_fsk_create, errno %d (%s)\n", progname, errno, strerror (errno)); - exit (EXIT_FAILURE); - } - -If you are decoding multiple channels, you will need multiple context structures; one per channel. -The attributes ("dsp_fsk_attr_t") do not have to be persistent, but the handle does. -There's even a "dsp_fsk_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever. - -Then, you need to feed samples into the software modem: - dsp_fsk_sample (fsk1200_handle, (double) sample / 32767.); - -It assumes the samples are between -1 and 1 as a double. - -It will outcall to your provided "clid_byte_handler()" function, which needs to have a prototype as follows: - - void clid_byte_handler (void *x, int data); - -The "x" is a context "void *" that you can associate in the fsk1200_handle (great for multiple channels). - -This will dribble bytes out to you at 1200 baud. - -From there, you are on your own. Canadian caller ID streams are different format than US caller ID streams IIRC. Both are trivial to figure out, as they have lots of ASCII data. I can supply some more code later on the Canadian one if you need it. - -Here's a sample of a Canadian caller ID stream from when you called: - -00000000: 55 55 55 55 55 55 55 55-55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU -00000010: 55 55 D5 80 1D 01 08 30-36 30 31 31 36 31 36 08 UU.....06011616. -00000020: 01 4F 03 0B 31 32 34 38-35 35 35 31 32 31 32 06 .O..12485551212. -00000030: 01 4C D1 85 00 02 54 00-02 C5 60 28 10 0A 80 30 .L....T...`(...0 - -The "UUUUU" is an alternating series of ones and zeros (which, when combined with the start and stop bits, creates the 0x55 character "U") used to train analog modems. -06011616 is the date and time (JUN 01 16:16), the "O" at 0x21 is an "Out of area" -qualifier for why your name didn't appear, and "1248..." is your DN. The "L" at 0x31 is a long distance qualifier. diff --git a/libs/freetdm/src/dsp/fsk.c b/libs/freetdm/src/fsk.c similarity index 100% rename from libs/freetdm/src/dsp/fsk.c rename to libs/freetdm/src/fsk.c diff --git a/libs/freetdm/src/dsp/fsk.h b/libs/freetdm/src/fsk.h similarity index 100% rename from libs/freetdm/src/dsp/fsk.h rename to libs/freetdm/src/fsk.h diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index d4e673cc5e..08ae5cf00d 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -87,124 +87,6 @@ struct iphdr { #define FNAME_LEN 50 -/* what should the returns from this function be?? */ -/* I dont think they are currently consistant between windows and *nix */ -#ifdef __WINDOWS__ -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) -{ - /* can we make the structure passed for this on nix and windows the same */ - /* so we don't have to do the extra 2 memcpy's on windows for this ? */ - wan_udp_hdr_t wan_udp; - DWORD ln; - unsigned char id = 0; - - wan_udp.wan_udphdr_request_reply = 0x01; - wan_udp.wan_udphdr_id = id; - wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD; - - wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL; - wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t); - - memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t)); - - if (DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ) == FALSE){ - return 1; - } - - if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK){ - return 2; - } - - memcpy( (void*)tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t)); - return 0; -} - -#else -static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd) -{ - return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); -} -#endif - -void __inline__ tdmv_api_close_socket(sng_fd_t *sp) -{ - if ( *sp != WP_INVALID_SOCKET){ -#if defined(__WINDOWS__) - CloseHandle(*sp); -#else - close(*sp); -#endif - *sp = WP_INVALID_SOCKET; - } -} - -static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) -{ - char fname[FNAME_LEN]; - sng_fd_t fd = WP_INVALID_SOCKET; -#if defined(__WINDOWS__) - DWORD ln; - wan_udp_hdr_t wan_udp; - - /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ - /* Subtract 1 from 'chan'. */ - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - fd = CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); - - /* make sure that we are the only ones who have this chan open */ - /* is this a threadsafe way to make sure that we are ok and will */ - /* never return a valid handle to more than one thread for the same channel? */ - - wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; - wan_udp.wan_udphdr_data_len = 0; - - DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ); - - if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ - /* somone already has this channel, or somthing else is not right. */ - tdmv_api_close_socket(&fd); - } - -#else - /* Does this fail if another thread already has this chan open? */ - /* if not, we need to add some code to make sure it does */ - snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - -#endif - return fd; -} #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 */ diff --git a/libs/freetdm/src/include/wanpipe_tdm_api_iface.h b/libs/freetdm/src/include/wanpipe_tdm_api_iface.h new file mode 100644 index 0000000000..f7406841f5 --- /dev/null +++ b/libs/freetdm/src/include/wanpipe_tdm_api_iface.h @@ -0,0 +1,314 @@ +/***************************************************************************** +* wanpipe_tdm_api.h +* +* WANPIPE(tm) AFT TE1 Hardware Support +* +* Authors: Nenad Corbic +* +* Copyright (c) 2007, 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 + +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, + + SIOC_WP_TDM_SET_RX_GAINS, + SIOC_WP_TDM_SET_TX_GAINS, + SIOC_WP_TDM_CLEAR_RX_GAINS, + SIOC_WP_TDM_CLEAR_TX_GAINS, + + SIOC_WP_TDM_GET_FE_ALARMS, + + SIOC_WP_TDM_ENABLE_HWEC, + SIOC_WP_TDM_DISABLE_HWEC, + + SIOC_WP_TDM_NOTSUPP /* */ + + +}; + +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 +}; + +#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)" + +#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 + + +typedef struct { + + u_int8_t type; + u_int8_t mode; + u_int32_t time_stamp; + u_int16_t channel; + u_int32_t chan_map; + 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; + } 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 +} 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 */ + wp_tdm_api_event_t event; /* TDM Event */ + unsigned int data_len; + void *data; +}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); +}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/freetdm/src/dsp/uart.c b/libs/freetdm/src/uart.c similarity index 100% rename from libs/freetdm/src/dsp/uart.c rename to libs/freetdm/src/uart.c diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/uart.h similarity index 100% rename from libs/freetdm/src/dsp/uart.h rename to libs/freetdm/src/uart.h diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a792ab6b0f..6f6bdb6940 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -31,6 +31,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define ZAP_ZT_SUPPORT +#define ZAP_WANPIPE_SUPPORT #include "openzap.h" #include "zap_isdn.h" #include diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index c5883bdd86..bdbde9526f 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -31,13 +31,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define WANPIPE_TDM_API 1 - #include "openzap.h" #include "zap_wanpipe.h" +#include +#include +#include -/*#include */ -#include +#define WP_INVALID_SOCKET -1 + +#include static struct { uint32_t codec_ms; @@ -45,14 +47,288 @@ static struct { uint32_t flash_ms; } wp_globals; +#define SIOC_WANPIPE_TDM_API 1 + +/* 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 */ + uint32_t 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; +} + +/* 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 +} + +#define FNAME_LEN 128 +static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) +{ + char fname[FNAME_LEN]; + sng_fd_t fd = WP_INVALID_SOCKET; +#if defined(__WINDOWS__) + DWORD ln; + wan_udp_hdr_t wan_udp; + + /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ + /* Subtract 1 from 'chan'. */ + _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); + + fd = CreateFile( fname, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, + (HANDLE)NULL + ); + + /* make sure that we are the only ones who have this chan open */ + /* is this a threadsafe way to make sure that we are ok and will */ + /* never return a valid handle to more than one thread for the same channel? */ + + wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; + wan_udp.wan_udphdr_data_len = 0; + + DeviceIoControl( + fd, + IoctlManagementCommand, + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPVOID)&wan_udp, + sizeof(wan_udp_hdr_t), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + ); + + if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ + /* somone already has this channel, or somthing else is not right. */ + tdmv_api_close_socket(&fd); + } + +#else + /* Does this fail if another thread already has this chan open? */ + /* if not, we need to add some code to make sure it does */ + snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); + + fd = open(fname, O_RDWR); + + if (fd < 0) { + fd = WP_INVALID_SOCKET; + } + +#endif + return fd; +} + + + static zap_io_interface_t wanpipe_interface; static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) { int err; - err = tdmv_api_ioctl(zchan->sockfd, tdm_api); - + /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ + err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; @@ -80,11 +356,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - + if (type == ZAP_CHAN_TYPE_FXS) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RING_DETECT_EVENTS; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); } @@ -219,7 +498,7 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = WP_NONE; + tdm_api.wp_tdm_cmd.tdm_codec = 0; wp_tdm_cmd_exec(zchan, &tdm_api); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; @@ -366,7 +645,8 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; - int i, j = 0, k = 0, l = 0, r; + uint32_t i, j = 0, k = 0, l = 0; + int r; for(i = 1; i <= span->chan_count; i++) { memset(&pfds[j], 0, sizeof(pfds[j])); @@ -442,9 +722,9 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { - case WP_TDM_EVENT_RXHOOK: + case WP_TDMAPI_EVENT_RXHOOK: { - event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rxhook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? ZAP_OOB_OFFHOOK : ZAP_OOB_ONHOOK; + 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)) { @@ -468,11 +748,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) continue; } break; - case WP_TDM_EVENT_RING_DETECT: + 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; - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RING_DETECT_EVENTS; - wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + } break; default: @@ -499,8 +778,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) static ZIO_DESTROY_CHANNEL_FUNCTION(wanpipe_destroy_channel) { - tdmv_api_close_socket(&zchan->sockfd); - zchan->sockfd = WP_INVALID_SOCKET; + if (zchan->sockfd > -1) { + close(zchan->sockfd); + zchan->sockfd = WP_INVALID_SOCKET; + } return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index db940d5c54..26ac640f79 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -49,7 +49,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za { unsigned configured = 0, x; char path[128] = ""; - zt_params_t ztp = {0}; + zt_params_t ztp; + + memset(&ztp, 0, sizeof(ztp)); for(x = start; x < end; x++) { zap_channel_t *chan; @@ -236,9 +238,11 @@ static ZIO_CLOSE_FUNCTION(zt_close) static ZIO_COMMAND_FUNCTION(zt_command) { - zt_params_t ztp = {0}; + zt_params_t ztp; int err = 0; + memset(&ztp, 0, sizeof(ztp)); + switch(command) { case ZAP_COMMAND_OFFHOOK: { @@ -385,7 +389,8 @@ static ZIO_WAIT_FUNCTION(zt_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) { struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; - int i, j = 0, k = 0, r, e; + uint32_t i, j = 0, k = 0; + int r; for(i = 1; i <= span->chan_count; i++) { memset(&pfds[j], 0, sizeof(pfds[j])); @@ -474,7 +479,6 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; } - event: span->channels[i].last_event_time = 0; span->event_header.e_type = ZAP_EVENT_OOB; span->event_header.enum_id = event_id; diff --git a/libs/freetdm/wanpipe b/libs/freetdm/wanpipe deleted file mode 100644 index 4165283537..0000000000 --- a/libs/freetdm/wanpipe +++ /dev/null @@ -1,10 +0,0 @@ -MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT -OBJS += $(SRC)/zap_wanpipe.o -WANPIPE_INCLUDE=/usr/include/wanpipe - -WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include -WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API - - - - diff --git a/libs/freetdm/zt b/libs/freetdm/zt deleted file mode 100644 index 28934f3b56..0000000000 --- a/libs/freetdm/zt +++ /dev/null @@ -1,2 +0,0 @@ -MOD_CFLAGS +=-DZAP_ZT_SUPPORT -OBJS += $(SRC)/zap_zt.o From 34d0951d0955b947deb87920a695b7d506cd4b54 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 04:38:05 +0000 Subject: [PATCH 0433/1766] update2 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@217 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/{ => include}/fsk.h | 0 libs/openzap/src/{ => include}/uart.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/src/{ => include}/fsk.h (100%) rename libs/openzap/src/{ => include}/uart.h (100%) diff --git a/libs/openzap/src/fsk.h b/libs/openzap/src/include/fsk.h similarity index 100% rename from libs/openzap/src/fsk.h rename to libs/openzap/src/include/fsk.h diff --git a/libs/openzap/src/uart.h b/libs/openzap/src/include/uart.h similarity index 100% rename from libs/openzap/src/uart.h rename to libs/openzap/src/include/uart.h From 0b973f0309f317d4e56cef9bfb6bb69f4fef0597 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 04:38:05 +0000 Subject: [PATCH 0434/1766] update2 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@217 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/{ => include}/fsk.h | 0 libs/freetdm/src/{ => include}/uart.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/src/{ => include}/fsk.h (100%) rename libs/freetdm/src/{ => include}/uart.h (100%) diff --git a/libs/freetdm/src/fsk.h b/libs/freetdm/src/include/fsk.h similarity index 100% rename from libs/freetdm/src/fsk.h rename to libs/freetdm/src/include/fsk.h diff --git a/libs/freetdm/src/uart.h b/libs/freetdm/src/include/uart.h similarity index 100% rename from libs/freetdm/src/uart.h rename to libs/freetdm/src/include/uart.h From cb8a120519f11a3d3ad520fd410451ba4a71be32 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 04:40:18 +0000 Subject: [PATCH 0435/1766] update3 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@218 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index bdbde9526f..4edce625cd 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -36,9 +36,6 @@ #include #include #include - -#define WP_INVALID_SOCKET -1 - #include static struct { @@ -47,8 +44,9 @@ static struct { uint32_t flash_ms; } wp_globals; -#define SIOC_WANPIPE_TDM_API 1 +/* a bunch of this stuff should go into the wanpipe_tdm_api_iface.h */ +#define WP_INVALID_SOCKET -1 /* 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 */ From 881d202fccb46a3f5b9285a0d9c41a8195df00b3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 04:40:18 +0000 Subject: [PATCH 0436/1766] update3 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@218 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index bdbde9526f..4edce625cd 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -36,9 +36,6 @@ #include #include #include - -#define WP_INVALID_SOCKET -1 - #include static struct { @@ -47,8 +44,9 @@ static struct { uint32_t flash_ms; } wp_globals; -#define SIOC_WANPIPE_TDM_API 1 +/* a bunch of this stuff should go into the wanpipe_tdm_api_iface.h */ +#define WP_INVALID_SOCKET -1 /* 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 */ From 56946b78aa746261de759669626d04c52ed4eb0a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 04:47:13 +0000 Subject: [PATCH 0437/1766] update windows build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@219 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 54 ++++++++++++-------------------- libs/openzap/openzap.sln | 2 -- libs/openzap/src/zap_io.c | 2 ++ 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index f677bc216b..33776e109c 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -41,7 +41,7 @@ + + @@ -389,6 +395,10 @@ RelativePath="..\src\libteletone_generate.c" > + + @@ -411,6 +421,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -443,6 +457,10 @@ RelativePath="..\src\include\openzap.h" > + + @@ -461,38 +479,6 @@ - - - - - - - - - - - - - - - - diff --git a/libs/openzap/openzap.sln b/libs/openzap/openzap.sln index ab53115d35..2e05fb4136 100644 --- a/libs/openzap/openzap.sln +++ b/libs/openzap/openzap.sln @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unix Makefiles", "Unix Make ProjectSection(SolutionItems) = preProject general.makefile = general.makefile Makefile = Makefile - wanpipe = wanpipe - zt = zt EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6f6bdb6940..9c251c9c42 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -31,7 +31,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef WIN32 #define ZAP_ZT_SUPPORT +#endif #define ZAP_WANPIPE_SUPPORT #include "openzap.h" #include "zap_isdn.h" From 690b929ea62e6f94d4e69c2ea472d28f76348016 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Jun 2007 04:47:13 +0000 Subject: [PATCH 0438/1766] update windows build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@219 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 54 ++++++++++++-------------------- libs/freetdm/openzap.sln | 2 -- libs/freetdm/src/zap_io.c | 2 ++ 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index f677bc216b..33776e109c 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -41,7 +41,7 @@ + + @@ -389,6 +395,10 @@ RelativePath="..\src\libteletone_generate.c" > + + @@ -411,6 +421,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -443,6 +457,10 @@ RelativePath="..\src\include\openzap.h" > + + @@ -461,38 +479,6 @@ - - - - - - - - - - - - - - - - diff --git a/libs/freetdm/openzap.sln b/libs/freetdm/openzap.sln index ab53115d35..2e05fb4136 100644 --- a/libs/freetdm/openzap.sln +++ b/libs/freetdm/openzap.sln @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unix Makefiles", "Unix Make ProjectSection(SolutionItems) = preProject general.makefile = general.makefile Makefile = Makefile - wanpipe = wanpipe - zt = zt EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6f6bdb6940..9c251c9c42 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -31,7 +31,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef WIN32 #define ZAP_ZT_SUPPORT +#endif #define ZAP_WANPIPE_SUPPORT #include "openzap.h" #include "zap_isdn.h" From b9b5cfcd87a193ff063cd0d6bbaa3a9b4dfe206e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 16:57:32 +0000 Subject: [PATCH 0439/1766] add fsk callerid stuff to analog fxo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@220 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 27 ++++++--- libs/openzap/src/include/openzap.h | 19 +++++- libs/openzap/src/include/zap_types.h | 26 +++++++-- libs/openzap/src/testcid.c | 11 +++- libs/openzap/src/zap_analog.c | 52 +++++++++++------ libs/openzap/src/zap_io.c | 81 +++++++++++++++++++++++++- libs/openzap/src/zap_wanpipe.c | 3 +- 7 files changed, 182 insertions(+), 37 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 2a0e13c37e..822459a1be 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -699,7 +699,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t private_t *tech_pvt = NULL; switch_channel_t *channel = NULL; char name[128]; - + *sp = NULL; if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { @@ -716,16 +716,29 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_core_session_destroy(&session); return ZAP_FAIL; } - + + + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_name)) { + switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); + } + + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num)) { + if (!switch_strlen_zero(sigmsg->channel->caller_data.ani)) { + switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->caller_data.ani); + } else { + switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->chan_number); + } + } + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), "OpenZAP", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, - sigmsg->channel->chan_name, - sigmsg->channel->chan_number, - NULL, - sigmsg->channel->chan_number, - NULL, + sigmsg->channel->caller_data.cid_name, + sigmsg->channel->caller_data.cid_num, NULL, + sigmsg->channel->caller_data.ani, + sigmsg->channel->caller_data.aniII, + sigmsg->channel->caller_data.rdnis, (char *) modname, SPAN_CONFIG[sigmsg->channel->span_id].context, sigmsg->channel->caller_data.dnis); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index f7a020d4c8..dfa4837845 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -223,13 +223,28 @@ struct zap_event { #define ZAP_TOKEN_STRLEN 128 #define ZAP_MAX_TOKENS 10 +static __inline__ char *zap_clean_string(char *s) +{ + char *p; + for (p = s; p && *p; p++) { + uint8_t x = (uint8_t) *p; + if (x < 32 || x > 127) { + *p = ' '; + } + } + + return s; +} struct zap_caller_data { char cid_name[80]; + char cid_num[80]; + char cid_date[8]; char ani[25]; char aniII[25]; char dnis[25]; + char rdnis[25]; }; struct zap_channel { @@ -271,6 +286,8 @@ struct zap_channel { char chan_name[128]; char chan_number[32]; zap_filehandle_t fds[2]; + zap_fsk_data_state_t fsk; + uint8_t fsk_buf[80]; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -343,7 +360,7 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; -zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, zap_size_t *len, char *data, size_t datalen); +zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index d77f56cf98..ef0269fb67 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -63,14 +63,22 @@ struct zap_io_interface; typedef uint64_t zap_time_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_NAME = 7, - MDMF_NO_NAME = 8 + MDMF_PHONE_NAME = 7, + MDMF_NO_NAME = 8, + MDMF_INVALID = 9 } zap_mdmf_type_t; - +#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t) struct zap_fsk_data_state { dsp_fsk_handle_t *fsk1200_handle; @@ -216,6 +224,8 @@ typedef enum { ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_TRACE_INPUT, ZAP_COMMAND_TRACE_OUTPUT, + ZAP_COMMAND_ENABLE_CALLERID_DETECT, + ZAP_COMMAND_DISABLE_CALLERID_DETECT, ZAP_COMMAND_COUNT } zap_command_t; @@ -236,7 +246,8 @@ typedef enum { typedef enum { ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), - ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) + ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2), + ZAP_CHANNEL_FEATURE_CALLERID = (1 << 3) } zap_channel_feature_t; typedef enum { @@ -252,9 +263,11 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_DIALING, + ZAP_CHANNEL_STATE_GET_CALLERID, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ + "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -274,7 +287,8 @@ typedef enum { ZAP_CHANNEL_INUSE = (1 << 13), ZAP_CHANNEL_OFFHOOK = (1 << 14), ZAP_CHANNEL_RINGING = (1 << 15), - ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16) + ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), + ZAP_CHANNEL_CALLERID_DETECT = (1 << 17) } zap_channel_flag_t; diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index f91ee59d96..545794689c 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -7,7 +7,8 @@ int main(int argc, char *argv[]) int16_t buf[160] = {0}; ssize_t len = 0; int type, mlen; - char str[128]; + char *sp; + char str[128] = ""; char fbuf[256]; if (argc < 2 || zap_fsk_demod_init(&state, 8000, fbuf, sizeof(fbuf))) { @@ -26,10 +27,14 @@ int main(int argc, char *argv[]) } } - while(zap_fsk_data_parse(&state, &type, &mlen, str, sizeof(str)) == ZAP_SUCCESS) { - printf("TYPE %d LEN %d VAL [%s]\n", type, mlen, str); + while(zap_fsk_data_parse(&state, &type, &sp, &mlen) == ZAP_SUCCESS) { + zap_copy_string(str, sp, mlen+1); + *(str+mlen) = '\0'; + zap_clean_string(str); + printf("TYPE %d (%s) LEN %d VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); } + zap_fsk_demod_destroy(&state); close(fd); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index e8944f2db6..7290d38d88 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -164,6 +164,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { + case ZAP_CHANNEL_STATE_GET_CALLERID: + { + if (state_counter > 5000 || !zap_test_flag(chan, ZAP_CHANNEL_CALLERID_DETECT)) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + } + } + break; case ZAP_CHANNEL_STATE_DIALING: { if (state_counter > dial_timeout) { @@ -199,14 +206,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } break; + case ZAP_CHANNEL_STATE_ATTN: + { + if (state_counter > 20000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 2000) { - if (chan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); - } else { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); - } + if (state_counter > 1000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } } break; @@ -230,6 +240,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); indicate = 0; state_counter = 0; + zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(chan->state)); switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { @@ -264,7 +275,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_use(chan); sig.event_id = ZAP_SIGEVENT_START; - zap_copy_string(chan->caller_data.dnis, dtmf, sizeof(chan->caller_data.dnis)); + + if (chan->type == ZAP_CHAN_TYPE_FXO) { + zap_set_string(chan->caller_data.dnis, chan->chan_number); + } else { + zap_set_string(chan->caller_data.dnis, dtmf); + } + data->sig_cb(&sig); continue; } @@ -292,12 +309,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; - case ZAP_CHANNEL_STATE_RING: + case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); + zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + } + break; + case ZAP_CHANNEL_STATE_RING: + { zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); indicate = 1; + } break; case ZAP_CHANNEL_STATE_BUSY: @@ -317,7 +340,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } break; default: - zap_channel_done(chan); break; } } @@ -393,8 +415,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_write(chan, frame, sizeof(frame), &rlen); continue; } - - + if (!indicate) { continue; } @@ -408,7 +429,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (chan->effective_codec != ZAP_CODEC_SLIN) { zio_codec_t codec_func = NULL; @@ -431,7 +451,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } done: - + zap_channel_done(chan); if (chan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(chan, ZAP_COMMAND_ONHOOK, NULL); } @@ -484,11 +504,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { /*zap_channel_command(event->channel, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");*/ - sig.event_id = ZAP_SIGEVENT_START; - zap_set_string(event->channel->caller_data.dnis, event->channel->chan_number); - data->sig_cb(&sig); - zap_channel_command(event->channel, ZAP_COMMAND_OFFHOOK, NULL); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RING); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); zap_thread_create_detached(zap_analog_channel_run, event->channel); } } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 9c251c9c42..d0da23752f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -101,6 +101,9 @@ ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, ZAP_ENUM_NAMES(CHANNEL_STATE_NAMES, CHANNEL_STATE_STRINGS) ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t, CHANNEL_STATE_NAMES, ZAP_CHANNEL_STATE_INVALID) +ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) +ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) + static char *cut_path(char *in) { char *p, *ret = in; @@ -795,6 +798,26 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_mutex_lock(zchan->mutex); switch(command) { + + case ZAP_COMMAND_ENABLE_CALLERID_DETECT: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CALLERID)) { + if (zap_fsk_demod_init(&zchan->fsk, zchan->rate, zchan->fsk_buf, sizeof(zchan->fsk_buf)) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, ZAP_FAIL); + } + zap_set_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); + } + } + break; + case ZAP_COMMAND_DISABLE_CALLERID_DETECT: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CALLERID)) { + zap_fsk_demod_destroy(&zchan->fsk); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); + } + } + break; case ZAP_COMMAND_TRACE_INPUT: { char *path = (char *) obj; @@ -1285,7 +1308,8 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) || + zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { uint8_t sln_buf[1024] = {0}; int16_t *sln; zap_size_t slen = 0; @@ -1319,6 +1343,61 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data slen = len; } + if (zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { + if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { + uint32_t type, mlen; + char str[128], *sp; + + + while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { + *(str+mlen) = '\0'; + zap_copy_string(str, sp, ++mlen); + zap_clean_string(str); + zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + + switch(type) { + case MDMF_DDN: + case MDMF_PHONE_NUM: + { + if (mlen > sizeof(zchan->caller_data.ani)) { + mlen = sizeof(zchan->caller_data.ani); + } + zap_set_string(zchan->caller_data.ani, str); + zap_set_string(zchan->caller_data.cid_num, zchan->caller_data.ani); + } + break; + case MDMF_NO_NUM: + { + zap_set_string(zchan->caller_data.ani, *str == 'P' ? "private" : "unknown"); + zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani); + } + break; + case MDMF_PHONE_NAME: + { + if (mlen > sizeof(zchan->caller_data.cid_name)) { + mlen = sizeof(zchan->caller_data.cid_name); + } + zap_set_string(zchan->caller_data.cid_name, str); + } + break; + case MDMF_NO_NAME: + { + zap_set_string(zchan->caller_data.cid_name, *str == 'P' ? "private" : "unknown"); + } + case MDMF_DATETIME: + { + if (mlen > sizeof(zchan->caller_data.cid_date)) { + mlen = sizeof(zchan->caller_data.cid_date); + } + zap_set_string(zchan->caller_data.cid_date, str); + } + break; + } + } + zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL); + } + } + if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint32_t i; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 4edce625cd..b9acfc2b0c 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -358,12 +358,13 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - +#if 0 if (type == ZAP_CHAN_TYPE_FXS) { tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); } +#endif tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); From fa760fe233af5cd1a8affe4fc6ba43238254ba44 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 16:57:32 +0000 Subject: [PATCH 0440/1766] add fsk callerid stuff to analog fxo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@220 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 27 ++++++--- libs/freetdm/src/include/openzap.h | 19 +++++- libs/freetdm/src/include/zap_types.h | 26 +++++++-- libs/freetdm/src/testcid.c | 11 +++- libs/freetdm/src/zap_analog.c | 52 +++++++++++------ libs/freetdm/src/zap_io.c | 81 +++++++++++++++++++++++++- libs/freetdm/src/zap_wanpipe.c | 3 +- 7 files changed, 182 insertions(+), 37 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 2a0e13c37e..822459a1be 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -699,7 +699,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t private_t *tech_pvt = NULL; switch_channel_t *channel = NULL; char name[128]; - + *sp = NULL; if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { @@ -716,16 +716,29 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_core_session_destroy(&session); return ZAP_FAIL; } - + + + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_name)) { + switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); + } + + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num)) { + if (!switch_strlen_zero(sigmsg->channel->caller_data.ani)) { + switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->caller_data.ani); + } else { + switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->chan_number); + } + } + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), "OpenZAP", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, - sigmsg->channel->chan_name, - sigmsg->channel->chan_number, - NULL, - sigmsg->channel->chan_number, - NULL, + sigmsg->channel->caller_data.cid_name, + sigmsg->channel->caller_data.cid_num, NULL, + sigmsg->channel->caller_data.ani, + sigmsg->channel->caller_data.aniII, + sigmsg->channel->caller_data.rdnis, (char *) modname, SPAN_CONFIG[sigmsg->channel->span_id].context, sigmsg->channel->caller_data.dnis); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index f7a020d4c8..dfa4837845 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -223,13 +223,28 @@ struct zap_event { #define ZAP_TOKEN_STRLEN 128 #define ZAP_MAX_TOKENS 10 +static __inline__ char *zap_clean_string(char *s) +{ + char *p; + for (p = s; p && *p; p++) { + uint8_t x = (uint8_t) *p; + if (x < 32 || x > 127) { + *p = ' '; + } + } + + return s; +} struct zap_caller_data { char cid_name[80]; + char cid_num[80]; + char cid_date[8]; char ani[25]; char aniII[25]; char dnis[25]; + char rdnis[25]; }; struct zap_channel { @@ -271,6 +286,8 @@ struct zap_channel { char chan_name[128]; char chan_number[32]; zap_filehandle_t fds[2]; + zap_fsk_data_state_t fsk; + uint8_t fsk_buf[80]; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -343,7 +360,7 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; -zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, zap_size_t *len, char *data, size_t datalen); +zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index d77f56cf98..ef0269fb67 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -63,14 +63,22 @@ struct zap_io_interface; typedef uint64_t zap_time_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_NAME = 7, - MDMF_NO_NAME = 8 + MDMF_PHONE_NAME = 7, + MDMF_NO_NAME = 8, + MDMF_INVALID = 9 } zap_mdmf_type_t; - +#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t) struct zap_fsk_data_state { dsp_fsk_handle_t *fsk1200_handle; @@ -216,6 +224,8 @@ typedef enum { ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_TRACE_INPUT, ZAP_COMMAND_TRACE_OUTPUT, + ZAP_COMMAND_ENABLE_CALLERID_DETECT, + ZAP_COMMAND_DISABLE_CALLERID_DETECT, ZAP_COMMAND_COUNT } zap_command_t; @@ -236,7 +246,8 @@ typedef enum { typedef enum { ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), - ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) + ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2), + ZAP_CHANNEL_FEATURE_CALLERID = (1 << 3) } zap_channel_feature_t; typedef enum { @@ -252,9 +263,11 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_DIALING, + ZAP_CHANNEL_STATE_GET_CALLERID, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ + "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -274,7 +287,8 @@ typedef enum { ZAP_CHANNEL_INUSE = (1 << 13), ZAP_CHANNEL_OFFHOOK = (1 << 14), ZAP_CHANNEL_RINGING = (1 << 15), - ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16) + ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), + ZAP_CHANNEL_CALLERID_DETECT = (1 << 17) } zap_channel_flag_t; diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index f91ee59d96..545794689c 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -7,7 +7,8 @@ int main(int argc, char *argv[]) int16_t buf[160] = {0}; ssize_t len = 0; int type, mlen; - char str[128]; + char *sp; + char str[128] = ""; char fbuf[256]; if (argc < 2 || zap_fsk_demod_init(&state, 8000, fbuf, sizeof(fbuf))) { @@ -26,10 +27,14 @@ int main(int argc, char *argv[]) } } - while(zap_fsk_data_parse(&state, &type, &mlen, str, sizeof(str)) == ZAP_SUCCESS) { - printf("TYPE %d LEN %d VAL [%s]\n", type, mlen, str); + while(zap_fsk_data_parse(&state, &type, &sp, &mlen) == ZAP_SUCCESS) { + zap_copy_string(str, sp, mlen+1); + *(str+mlen) = '\0'; + zap_clean_string(str); + printf("TYPE %d (%s) LEN %d VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); } + zap_fsk_demod_destroy(&state); close(fd); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index e8944f2db6..7290d38d88 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -164,6 +164,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { switch(chan->state) { + case ZAP_CHANNEL_STATE_GET_CALLERID: + { + if (state_counter > 5000 || !zap_test_flag(chan, ZAP_CHANNEL_CALLERID_DETECT)) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + } + } + break; case ZAP_CHANNEL_STATE_DIALING: { if (state_counter > dial_timeout) { @@ -199,14 +206,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } break; + case ZAP_CHANNEL_STATE_ATTN: + { + if (state_counter > 20000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 2000) { - if (chan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); - } else { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); - } + if (state_counter > 1000) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } } break; @@ -230,6 +240,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); indicate = 0; state_counter = 0; + zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(chan->state)); switch(chan->state) { case ZAP_CHANNEL_STATE_UP: { @@ -264,7 +275,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_use(chan); sig.event_id = ZAP_SIGEVENT_START; - zap_copy_string(chan->caller_data.dnis, dtmf, sizeof(chan->caller_data.dnis)); + + if (chan->type == ZAP_CHAN_TYPE_FXO) { + zap_set_string(chan->caller_data.dnis, chan->chan_number); + } else { + zap_set_string(chan->caller_data.dnis, dtmf); + } + data->sig_cb(&sig); continue; } @@ -292,12 +309,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; - case ZAP_CHANNEL_STATE_RING: + case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); + zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + } + break; + case ZAP_CHANNEL_STATE_RING: + { zap_buffer_zero(dt_buffer); teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_RING]); indicate = 1; + } break; case ZAP_CHANNEL_STATE_BUSY: @@ -317,7 +340,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } break; default: - zap_channel_done(chan); break; } } @@ -393,8 +415,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_write(chan, frame, sizeof(frame), &rlen); continue; } - - + if (!indicate) { continue; } @@ -408,7 +429,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (chan->effective_codec != ZAP_CODEC_SLIN) { zio_codec_t codec_func = NULL; @@ -431,7 +451,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } done: - + zap_channel_done(chan); if (chan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(chan, ZAP_COMMAND_ONHOOK, NULL); } @@ -484,11 +504,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { /*zap_channel_command(event->channel, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");*/ - sig.event_id = ZAP_SIGEVENT_START; - zap_set_string(event->channel->caller_data.dnis, event->channel->chan_number); - data->sig_cb(&sig); - zap_channel_command(event->channel, ZAP_COMMAND_OFFHOOK, NULL); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RING); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); zap_thread_create_detached(zap_analog_channel_run, event->channel); } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 9c251c9c42..d0da23752f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -101,6 +101,9 @@ ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, ZAP_ENUM_NAMES(CHANNEL_STATE_NAMES, CHANNEL_STATE_STRINGS) ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t, CHANNEL_STATE_NAMES, ZAP_CHANNEL_STATE_INVALID) +ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) +ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) + static char *cut_path(char *in) { char *p, *ret = in; @@ -795,6 +798,26 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_mutex_lock(zchan->mutex); switch(command) { + + case ZAP_COMMAND_ENABLE_CALLERID_DETECT: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CALLERID)) { + if (zap_fsk_demod_init(&zchan->fsk, zchan->rate, zchan->fsk_buf, sizeof(zchan->fsk_buf)) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, ZAP_FAIL); + } + zap_set_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); + } + } + break; + case ZAP_COMMAND_DISABLE_CALLERID_DETECT: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CALLERID)) { + zap_fsk_demod_destroy(&zchan->fsk); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); + } + } + break; case ZAP_COMMAND_TRACE_INPUT: { char *path = (char *) obj; @@ -1285,7 +1308,8 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) || + zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { uint8_t sln_buf[1024] = {0}; int16_t *sln; zap_size_t slen = 0; @@ -1319,6 +1343,61 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data slen = len; } + if (zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { + if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { + uint32_t type, mlen; + char str[128], *sp; + + + while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { + *(str+mlen) = '\0'; + zap_copy_string(str, sp, ++mlen); + zap_clean_string(str); + zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + + switch(type) { + case MDMF_DDN: + case MDMF_PHONE_NUM: + { + if (mlen > sizeof(zchan->caller_data.ani)) { + mlen = sizeof(zchan->caller_data.ani); + } + zap_set_string(zchan->caller_data.ani, str); + zap_set_string(zchan->caller_data.cid_num, zchan->caller_data.ani); + } + break; + case MDMF_NO_NUM: + { + zap_set_string(zchan->caller_data.ani, *str == 'P' ? "private" : "unknown"); + zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani); + } + break; + case MDMF_PHONE_NAME: + { + if (mlen > sizeof(zchan->caller_data.cid_name)) { + mlen = sizeof(zchan->caller_data.cid_name); + } + zap_set_string(zchan->caller_data.cid_name, str); + } + break; + case MDMF_NO_NAME: + { + zap_set_string(zchan->caller_data.cid_name, *str == 'P' ? "private" : "unknown"); + } + case MDMF_DATETIME: + { + if (mlen > sizeof(zchan->caller_data.cid_date)) { + mlen = sizeof(zchan->caller_data.cid_date); + } + zap_set_string(zchan->caller_data.cid_date, str); + } + break; + } + } + zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL); + } + } + if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint32_t i; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 4edce625cd..b9acfc2b0c 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -358,12 +358,13 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - +#if 0 if (type == ZAP_CHAN_TYPE_FXS) { tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); } +#endif tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); From 0cd7288eadf29d8ed67c4e9da9c77a78878fc744 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 18:27:51 +0000 Subject: [PATCH 0441/1766] add file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@221 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_callerid.c | 141 ++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 libs/openzap/src/zap_callerid.c diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c new file mode 100644 index 0000000000..f94ec59076 --- /dev/null +++ b/libs/openzap/src/zap_callerid.c @@ -0,0 +1,141 @@ +#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 = 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; + } +} + +zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) +{ + + int i, 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; +} + +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; +} + +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; +} + +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); + } + + 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; +} + + From edbf7bb713fd83cd8ced33f95dc2cddd3cb4f613 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 5 Jun 2007 18:27:51 +0000 Subject: [PATCH 0442/1766] add file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@221 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_callerid.c | 141 ++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 libs/freetdm/src/zap_callerid.c diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c new file mode 100644 index 0000000000..f94ec59076 --- /dev/null +++ b/libs/freetdm/src/zap_callerid.c @@ -0,0 +1,141 @@ +#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 = 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; + } +} + +zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) +{ + + int i, 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; +} + +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; +} + +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; +} + +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); + } + + 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; +} + + From f23950ffdd06cbe5fb7b9373b7987cae7f5ecb53 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 6 Jun 2007 15:59:38 +0000 Subject: [PATCH 0443/1766] windows build add zap_callerid.c and tweak types. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@222 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 4 ++++ libs/openzap/src/include/zap_types.h | 10 +++++----- libs/openzap/src/zap_callerid.c | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 33776e109c..67565dbb90 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -403,6 +403,10 @@ RelativePath="..\src\zap_buffer.c" > + + diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index ef0269fb67..84f74ee556 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -85,11 +85,11 @@ struct zap_fsk_data_state { uint8_t init; uint8_t *buf; size_t bufsize; - int blen; - int bpos; - int dlen; - int ppos; - uint8_t checksum; + zap_size_t blen; + zap_size_t bpos; + zap_size_t dlen; + zap_size_t ppos; + int checksum; }; typedef struct zap_fsk_data_state zap_fsk_data_state_t; diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index f94ec59076..f3a685f55a 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -6,7 +6,7 @@ static void fsk_byte_handler (void *x, int data) { zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x; - uint8_t byte = data; + uint8_t byte = (uint8_t)data; top: @@ -39,7 +39,8 @@ static void fsk_byte_handler (void *x, int data) zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) { - int i, sum = 0; + zap_size_t i; + int sum = 0; top: From 886482c168a0cd6737d0b5df2b88fa8359b33192 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 6 Jun 2007 15:59:38 +0000 Subject: [PATCH 0444/1766] windows build add zap_callerid.c and tweak types. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@222 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 4 ++++ libs/freetdm/src/include/zap_types.h | 10 +++++----- libs/freetdm/src/zap_callerid.c | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 33776e109c..67565dbb90 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -403,6 +403,10 @@ RelativePath="..\src\zap_buffer.c" > + + diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index ef0269fb67..84f74ee556 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -85,11 +85,11 @@ struct zap_fsk_data_state { uint8_t init; uint8_t *buf; size_t bufsize; - int blen; - int bpos; - int dlen; - int ppos; - uint8_t checksum; + zap_size_t blen; + zap_size_t bpos; + zap_size_t dlen; + zap_size_t ppos; + int checksum; }; typedef struct zap_fsk_data_state zap_fsk_data_state_t; diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index f94ec59076..f3a685f55a 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -6,7 +6,7 @@ static void fsk_byte_handler (void *x, int data) { zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x; - uint8_t byte = data; + uint8_t byte = (uint8_t)data; top: @@ -39,7 +39,8 @@ static void fsk_byte_handler (void *x, int data) zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) { - int i, sum = 0; + zap_size_t i; + int sum = 0; top: From ffbba3d3218a95cc55517b50efa5413ee8735b9e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 6 Jun 2007 22:58:13 +0000 Subject: [PATCH 0445/1766] add dds to teletone git-svn-id: http://svn.openzap.org/svn/openzap/trunk@223 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 41 ++- libs/openzap/general.makefile | 4 +- libs/openzap/src/include/libteletone.h | 29 +- .../src/include/libteletone_generate.h | 276 +++++++++++------- libs/openzap/src/include/openzap.h | 3 +- libs/openzap/src/libteletone_detect.c | 5 +- libs/openzap/src/libteletone_generate.c | 87 ++++-- 7 files changed, 294 insertions(+), 151 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 64d1910a94..819e96c0f5 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -63,8 +63,34 @@ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o -HEADERS=$(SRC)/isdn/include/Q931.h \ - $(SRC)/include/openzap.h +HEADERS= $(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/wanpipe_tdm_api_iface.h \ +$(SRC)/include/zap_analog.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_isdn.h \ +$(SRC)/include/zap_skel.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_zt.h \ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include @@ -76,10 +102,12 @@ TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w include general.makefile +$(OBJS): $(HEADERS) + all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) - ar rcs $(MYLIB) $(OBJS) + ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) testapp: $(SRC)/testapp.c $(MYLIB) @@ -88,6 +116,9 @@ testapp: $(SRC)/testapp.c $(MYLIB) testcid: $(SRC)/testcid.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread +testtones: $(SRC)/testtones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread + testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread @@ -109,7 +140,7 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -%.o: %.c +%.o: %.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ dox: @@ -127,6 +158,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/general.makefile b/libs/openzap/general.makefile index e642a7d88e..5b2fcb9821 100644 --- a/libs/openzap/general.makefile +++ b/libs/openzap/general.makefile @@ -1,3 +1,3 @@ -CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi -Wno-unused-parameter +CC=gcc +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index e81ef5e90d..351afa1413 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -73,32 +73,37 @@ #ifdef __cplusplus extern "C" { +#ifdef _doh +} #endif +#endif + #define TELETONE_MAX_DTMF_DIGITS 128 #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 - typedef double teletone_process_t; +typedef double teletone_process_t; - /*! \file libteletone.h - \brief Top level include file +/*! \file libteletone.h + \brief Top level include file - This file should be included by applications using the library - */ + This file should be included by applications using the library +*/ + +/*! \brief An abstraction to store a tone mapping */ +typedef struct { + /*! An array of tone frequencies */ + teletone_process_t freqs[TELETONE_MAX_TONES]; +} teletone_tone_map_t; - /*! \brief An abstraction to store a tone mapping */ - typedef struct { - /*! An array of tone frequencies */ - teletone_process_t freqs[TELETONE_MAX_TONES]; - } teletone_tone_map_t; #if !defined(M_PI) - /* C99 systems may not define M_PI */ +/* C99 systems may not define M_PI */ #define M_PI 3.14159265358979323846264338327 #endif #ifdef _MSC_VER - typedef __int16 int16_t; +typedef __int16 int16_t; #endif #include diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index e37778d278..0ed8930539 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -72,13 +72,30 @@ #define LIBTELETONE_GENERATE_H #ifdef __cplusplus extern "C" { +#ifdef _doh +} #endif +#endif + +#include +#include +#include +#include +#include +#include +#include +#if !defined(powf) +extern float powf (float, float); +#endif +#include +#include + #include #include #include -#include #ifndef _MSC_VER #include +#include #endif #include #include @@ -87,115 +104,174 @@ extern "C" { #include #include +#define TELETONE_VOL_DB_MAX 0 +#define TELETONE_VOL_DB_MIN -63 + +struct teletone_dds_state { + uint32_t phase_rate; + uint32_t scale_factor; + uint32_t phase_accumulator; + int16_t sample; + int32_t tx_level; +}; +typedef struct teletone_dds_state teletone_dds_state_t; + +#define SINE_TABLE_MAX 128 +#define SINE_TABLE_LEN (SINE_TABLE_MAX - 1) +#define MAX_PHASE_ACCUMULATOR 0x10000 * 0x10000 +/* 3.14 == the max power on ulaw (alaw is 3.17) */ +/* 3.02 represents twice the power */ +#define DBM0_MAX_POWER (3.14f + 3.02f) + +const int16_t TELETONE_SINES[SINE_TABLE_MAX]; + +static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) +{ + int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; + int16_t sample; + + if (bitmask & SINE_TABLE_MAX) { + sine_index = SINE_TABLE_LEN - sine_index; + } + + sample = TELETONE_SINES[sine_index]; + + if (bitmask & (SINE_TABLE_MAX * 2)) { + sample *= -1; + } + + dds->phase_accumulator += dds->phase_rate; + + return (int16_t) (sample * dds->scale_factor >> 15); +} + +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) +{ + dds->phase_accumulator = 0; + dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); - /*! \file libteletone_generate.h - \brief Tone Generation Routines + if (dds->tx_level != tx_level || !dds->scale_factor) { + dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); + } + + dds->tx_level = tx_level; +} - This module is responsible for tone generation specifics - */ - - typedef int16_t teletone_audio_t; - struct teletone_generation_session; - typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); - - /*! \brief An abstraction to store a tone generation session */ - struct teletone_generation_session { - /*! An array of tone mappings to character mappings */ - teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; - /*! The number of channels the output audio should be in */ - int channels; - /*! The Rate in hz of the output audio */ - int rate; - /*! The duration (in samples) of the output audio */ - int duration; - /*! The duration of silence to append after the initial audio is generated */ - int wait; - /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ - int tmp_duration; - /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ - int tmp_wait; - /*! Number of loops to repeat a single instruction*/ - int loops; - /*! Number of loops to repeat the entire set of instructions*/ - int LOOPS; - /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - int decay_factor; - /*! Direction to perform volume increase/decrease 1/-1*/ - int decay_direction; - /*! Number of samples between increase/decrease of volume */ - int decay_step; - /*! Volume factor of the tone */ - int volume; - /*! Debug on/off */ - int debug; - /*! FILE stream to write debug data to */ - FILE *debug_stream; - /*! Extra user data to attach to the session*/ - void *user_data; - /*! Buffer for storing sample data (dynamic) */ - teletone_audio_t *buffer; - /*! Size of the buffer */ - int datalen; - /*! In-Use size of the buffer */ - int samples; - /*! Callback function called during generation */ - int dynamic; - tone_handler handler; - }; - - typedef struct teletone_generation_session teletone_generation_session_t; +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) +{ + dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); +} - /*! - \brief Assign a set of tones to a tone_session indexed by a paticular index/character - \param ts the tone generation session - \param index the index to map the tone to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 - */ - int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); - /*! - \brief Assign a set of tones to a single tone map - \param map the map to assign the tones to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 - */ - int teletone_set_map(teletone_tone_map_t *map, ...); +/*! \file libteletone_generate.h + \brief Tone Generation Routines - /*! - \brief Initilize a tone generation session - \param ts the tone generation session to initilize - \param buflen the size of the buffer(in samples) to dynamically allocate - \param handler a callback function to execute when a tone generation instruction is complete - \param user_data optional user data to send - \return 0 - */ - int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + This module is responsible for tone generation specifics +*/ - /*! - \brief Free the buffer allocated by a tone generation session - \param ts the tone generation session to destroy - \return 0 - */ - int teletone_destroy_session(teletone_generation_session_t *ts); +typedef int16_t teletone_audio_t; +struct teletone_generation_session; +typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); - /*! - \brief Execute a single tone generation instruction - \param ts the tone generation session to consult for parameters - \param map the tone mapping to use for the frequencies - \return 0 - */ - int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); +/*! \brief An abstraction to store a tone generation session */ +struct teletone_generation_session { + /*! An array of tone mappings to character mappings */ + teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; + /*! The number of channels the output audio should be in */ + int channels; + /*! The Rate in hz of the output audio */ + int rate; + /*! The duration (in samples) of the output audio */ + int duration; + /*! The duration of silence to append after the initial audio is generated */ + int wait; + /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ + int tmp_duration; + /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ + int tmp_wait; + /*! Number of loops to repeat a single instruction*/ + int loops; + /*! Number of loops to repeat the entire set of instructions*/ + int LOOPS; + /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ + float decay_factor; + /*! Direction to perform volume increase/decrease 1/-1*/ + int decay_direction; + /*! Number of samples between increase/decrease of volume */ + int decay_step; + /*! Volume factor of the tone */ + float volume; + /*! Debug on/off */ + int debug; + /*! FILE stream to write debug data to */ + FILE *debug_stream; + /*! Extra user data to attach to the session*/ + void *user_data; + /*! Buffer for storing sample data (dynamic) */ + teletone_audio_t *buffer; + /*! Size of the buffer */ + int datalen; + /*! In-Use size of the buffer */ + int samples; + /*! Callback function called during generation */ + int dynamic; + tone_handler handler; +}; - /*! - \brief Execute a tone generation script and call callbacks after each instruction - \param ts the tone generation session to execute on - \param cmd the script to execute - \return 0 - */ - int teletone_run(teletone_generation_session_t *ts, char *cmd); +typedef struct teletone_generation_session teletone_generation_session_t; + + +/*! + \brief Assign a set of tones to a tone_session indexed by a paticular index/character + \param ts the tone generation session + \param index the index to map the tone to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); + +/*! + \brief Assign a set of tones to a single tone map + \param map the map to assign the tones to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_map(teletone_tone_map_t *map, ...); + +/*! + \brief Initilize a tone generation session + \param ts the tone generation session to initilize + \param buflen the size of the buffer(in samples) to dynamically allocate + \param handler a callback function to execute when a tone generation instruction is complete + \param user_data optional user data to send + \return 0 +*/ +int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + +/*! + \brief Free the buffer allocated by a tone generation session + \param ts the tone generation session to destroy + \return 0 +*/ +int teletone_destroy_session(teletone_generation_session_t *ts); + +/*! + \brief Execute a single tone generation instruction + \param ts the tone generation session to consult for parameters + \param map the tone mapping to use for the frequencies + \return 0 +*/ +int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); + +/*! + \brief Execute a tone generation script and call callbacks after each instruction + \param ts the tone generation session to execute on + \param cmd the script to execute + \return 0 +*/ +int teletone_run(teletone_generation_session_t *ts, char *cmd); #ifdef __cplusplus } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index dfa4837845..01eb7e75ba 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -34,8 +34,9 @@ #ifndef OPENZAP_H #define OPENZAP_H + #ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #endif #ifndef HAVE_STRINGS_H diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 1af9b8fc43..a089f8fc48 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -90,7 +90,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include + #ifndef _MSC_VER #include #endif @@ -98,7 +99,7 @@ #include #include #include -#include + static teletone_detection_descriptor_t dtmf_detect_row[GRID_FACTOR]; static teletone_detection_descriptor_t dtmf_detect_col[GRID_FACTOR]; diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 4e388c8d3b..9a36e6280c 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -70,6 +70,7 @@ */ #include + #define SMAX 32767 #define SMIN -32768 #define normalize_to_16bit(n) if (n > SMAX) n = SMAX; else if (n < SMIN) n = SMIN; @@ -78,6 +79,25 @@ #pragma warning(disable:4706) #endif +const 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 +}; + int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) { @@ -122,8 +142,9 @@ int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_ha ts->tmp_wait = -1; ts->handler = handler; ts->user_data = user_data; - ts->volume = 1500; + 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; @@ -181,34 +202,24 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need) int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map) { - teletone_process_t period = (1.0 / ts->rate) / ts->channels; + /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/ int i, c; int freqlen = 0; - teletone_process_t tones[TELETONE_MAX_TONES]; - int decay = 0; + teletone_dds_state_t tones[TELETONE_MAX_TONES]; + //int decay = 0; int duration; int wait = 0; - teletone_process_t sample; - + 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) { - if (ts->decay_step) { - if (ts->decay_factor) { - decay = (duration - (duration / ts->decay_factor)); - } else { - decay = 0; - } - } - if (ts->volume < 0) { - ts->volume = 0; - } - for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { - tones[freqlen] = (teletone_process_t) map->freqs[freqlen] * (2 * M_PI); + teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, vol); } if (ts->channels > 1) { @@ -220,17 +231,28 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m return -1; } } + for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) { - if (ts->decay_step && !(ts->samples % ts->decay_step) && ts->volume > 0 && ts->samples > decay) { - ts->volume += ts->decay_direction; + 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; map->freqs[j] && j < TELETONE_MAX_TONES; j++) { + teletone_dds_state_set_tx_level(&tones[j], vol); + } + dc = 0; + } } - sample = (teletone_process_t) 128; + sample = 128; for (i = 0; i < freqlen; i++) { - sample += ((teletone_process_t) 2 * (ts->volume > 0 ? ts->volume : 1) * cos(tones[i] * ts->samples * period)); + int32_t s = teletone_dds_modulate_sample(&tones[i]); + sample += s; } - normalize_to_16bit(sample); + sample /= freqlen; ts->buffer[ts->samples] = (teletone_audio_t)sample; for (c = 1; c < ts->channels; c++) { @@ -261,7 +283,8 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m fprintf(ts->debug_stream, "%s%0.2f", i == 0 ? "" : "+",map->freqs[i]); } - fprintf(ts->debug_stream, ") [volume %d; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %d; decay_step %d; wrote %d bytes]\n", + fprintf(ts->debug_stream, + ") [volume %0.2fDb; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %0.2f; decay_step %d(%dms); wrote %d bytes]\n", ts->volume, duration, duration / (ts->rate / 1000), @@ -271,6 +294,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m wait / (ts->rate / 1000), ts->decay_factor, ts->decay_step, + ts->decay_step / (ts->rate / 1000), ts->samples * 2); } } @@ -330,18 +354,23 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->duration = atoi(cur + 2) * (ts->rate / 1000); break; case 'v': - ts->volume = atoi(cur + 2); + { + float vol = atof(cur + 2); + if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { + ts->volume = vol; + } + } break; case '>': - ts->decay_factor = atoi(cur + 2); + ts->decay_step = atoi(cur + 2) * (ts->rate / 1000); ts->decay_direction = -1; break; case '<': - ts->decay_factor = atoi(cur + 2); + ts->decay_step = atoi(cur + 2) * (ts->rate / 1000); ts->decay_direction = 1; break; case '+': - ts->decay_step = atoi(cur + 2); + ts->decay_factor = atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); From 83d74318e10815a5bc0f21b6d741e24c74bec607 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 6 Jun 2007 22:58:13 +0000 Subject: [PATCH 0446/1766] add dds to teletone git-svn-id: http://svn.openzap.org/svn/openzap/trunk@223 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 41 ++- libs/freetdm/general.makefile | 4 +- libs/freetdm/src/include/libteletone.h | 29 +- .../src/include/libteletone_generate.h | 276 +++++++++++------- libs/freetdm/src/include/openzap.h | 3 +- libs/freetdm/src/libteletone_detect.c | 5 +- libs/freetdm/src/libteletone_generate.c | 87 ++++-- 7 files changed, 294 insertions(+), 151 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 64d1910a94..819e96c0f5 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -63,8 +63,34 @@ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o -HEADERS=$(SRC)/isdn/include/Q931.h \ - $(SRC)/include/openzap.h +HEADERS= $(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/wanpipe_tdm_api_iface.h \ +$(SRC)/include/zap_analog.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_isdn.h \ +$(SRC)/include/zap_skel.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_zt.h \ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include @@ -76,10 +102,12 @@ TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w include general.makefile +$(OBJS): $(HEADERS) + all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) - ar rcs $(MYLIB) $(OBJS) + ar rcs $(MYLIB) $(OBJS) ranlib $(MYLIB) testapp: $(SRC)/testapp.c $(MYLIB) @@ -88,6 +116,9 @@ testapp: $(SRC)/testapp.c $(MYLIB) testcid: $(SRC)/testcid.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread +testtones: $(SRC)/testtones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread + testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread @@ -109,7 +140,7 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -%.o: %.c +%.o: %.c $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ dox: @@ -127,6 +158,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/general.makefile b/libs/freetdm/general.makefile index e642a7d88e..5b2fcb9821 100644 --- a/libs/freetdm/general.makefile +++ b/libs/freetdm/general.makefile @@ -1,3 +1,3 @@ -CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -ansi -Wno-unused-parameter +CC=gcc +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index e81ef5e90d..351afa1413 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -73,32 +73,37 @@ #ifdef __cplusplus extern "C" { +#ifdef _doh +} #endif +#endif + #define TELETONE_MAX_DTMF_DIGITS 128 #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 - typedef double teletone_process_t; +typedef double teletone_process_t; - /*! \file libteletone.h - \brief Top level include file +/*! \file libteletone.h + \brief Top level include file - This file should be included by applications using the library - */ + This file should be included by applications using the library +*/ + +/*! \brief An abstraction to store a tone mapping */ +typedef struct { + /*! An array of tone frequencies */ + teletone_process_t freqs[TELETONE_MAX_TONES]; +} teletone_tone_map_t; - /*! \brief An abstraction to store a tone mapping */ - typedef struct { - /*! An array of tone frequencies */ - teletone_process_t freqs[TELETONE_MAX_TONES]; - } teletone_tone_map_t; #if !defined(M_PI) - /* C99 systems may not define M_PI */ +/* C99 systems may not define M_PI */ #define M_PI 3.14159265358979323846264338327 #endif #ifdef _MSC_VER - typedef __int16 int16_t; +typedef __int16 int16_t; #endif #include diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index e37778d278..0ed8930539 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -72,13 +72,30 @@ #define LIBTELETONE_GENERATE_H #ifdef __cplusplus extern "C" { +#ifdef _doh +} #endif +#endif + +#include +#include +#include +#include +#include +#include +#include +#if !defined(powf) +extern float powf (float, float); +#endif +#include +#include + #include #include #include -#include #ifndef _MSC_VER #include +#include #endif #include #include @@ -87,115 +104,174 @@ extern "C" { #include #include +#define TELETONE_VOL_DB_MAX 0 +#define TELETONE_VOL_DB_MIN -63 + +struct teletone_dds_state { + uint32_t phase_rate; + uint32_t scale_factor; + uint32_t phase_accumulator; + int16_t sample; + int32_t tx_level; +}; +typedef struct teletone_dds_state teletone_dds_state_t; + +#define SINE_TABLE_MAX 128 +#define SINE_TABLE_LEN (SINE_TABLE_MAX - 1) +#define MAX_PHASE_ACCUMULATOR 0x10000 * 0x10000 +/* 3.14 == the max power on ulaw (alaw is 3.17) */ +/* 3.02 represents twice the power */ +#define DBM0_MAX_POWER (3.14f + 3.02f) + +const int16_t TELETONE_SINES[SINE_TABLE_MAX]; + +static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) +{ + int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; + int16_t sample; + + if (bitmask & SINE_TABLE_MAX) { + sine_index = SINE_TABLE_LEN - sine_index; + } + + sample = TELETONE_SINES[sine_index]; + + if (bitmask & (SINE_TABLE_MAX * 2)) { + sample *= -1; + } + + dds->phase_accumulator += dds->phase_rate; + + return (int16_t) (sample * dds->scale_factor >> 15); +} + +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) +{ + dds->phase_accumulator = 0; + dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); - /*! \file libteletone_generate.h - \brief Tone Generation Routines + if (dds->tx_level != tx_level || !dds->scale_factor) { + dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); + } + + dds->tx_level = tx_level; +} - This module is responsible for tone generation specifics - */ - - typedef int16_t teletone_audio_t; - struct teletone_generation_session; - typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); - - /*! \brief An abstraction to store a tone generation session */ - struct teletone_generation_session { - /*! An array of tone mappings to character mappings */ - teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; - /*! The number of channels the output audio should be in */ - int channels; - /*! The Rate in hz of the output audio */ - int rate; - /*! The duration (in samples) of the output audio */ - int duration; - /*! The duration of silence to append after the initial audio is generated */ - int wait; - /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ - int tmp_duration; - /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ - int tmp_wait; - /*! Number of loops to repeat a single instruction*/ - int loops; - /*! Number of loops to repeat the entire set of instructions*/ - int LOOPS; - /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - int decay_factor; - /*! Direction to perform volume increase/decrease 1/-1*/ - int decay_direction; - /*! Number of samples between increase/decrease of volume */ - int decay_step; - /*! Volume factor of the tone */ - int volume; - /*! Debug on/off */ - int debug; - /*! FILE stream to write debug data to */ - FILE *debug_stream; - /*! Extra user data to attach to the session*/ - void *user_data; - /*! Buffer for storing sample data (dynamic) */ - teletone_audio_t *buffer; - /*! Size of the buffer */ - int datalen; - /*! In-Use size of the buffer */ - int samples; - /*! Callback function called during generation */ - int dynamic; - tone_handler handler; - }; - - typedef struct teletone_generation_session teletone_generation_session_t; +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) +{ + dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); +} - /*! - \brief Assign a set of tones to a tone_session indexed by a paticular index/character - \param ts the tone generation session - \param index the index to map the tone to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 - */ - int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); - /*! - \brief Assign a set of tones to a single tone map - \param map the map to assign the tones to - \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 - \return 0 - */ - int teletone_set_map(teletone_tone_map_t *map, ...); +/*! \file libteletone_generate.h + \brief Tone Generation Routines - /*! - \brief Initilize a tone generation session - \param ts the tone generation session to initilize - \param buflen the size of the buffer(in samples) to dynamically allocate - \param handler a callback function to execute when a tone generation instruction is complete - \param user_data optional user data to send - \return 0 - */ - int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + This module is responsible for tone generation specifics +*/ - /*! - \brief Free the buffer allocated by a tone generation session - \param ts the tone generation session to destroy - \return 0 - */ - int teletone_destroy_session(teletone_generation_session_t *ts); +typedef int16_t teletone_audio_t; +struct teletone_generation_session; +typedef int (*tone_handler)(struct teletone_generation_session *ts, teletone_tone_map_t *map); - /*! - \brief Execute a single tone generation instruction - \param ts the tone generation session to consult for parameters - \param map the tone mapping to use for the frequencies - \return 0 - */ - int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); +/*! \brief An abstraction to store a tone generation session */ +struct teletone_generation_session { + /*! An array of tone mappings to character mappings */ + teletone_tone_map_t TONES[TELETONE_TONE_RANGE]; + /*! The number of channels the output audio should be in */ + int channels; + /*! The Rate in hz of the output audio */ + int rate; + /*! The duration (in samples) of the output audio */ + int duration; + /*! The duration of silence to append after the initial audio is generated */ + int wait; + /*! The duration (in samples) of the output audio (takes prescedence over actual duration value) */ + int tmp_duration; + /*! The duration of silence to append after the initial audio is generated (takes prescedence over actual wait value)*/ + int tmp_wait; + /*! Number of loops to repeat a single instruction*/ + int loops; + /*! Number of loops to repeat the entire set of instructions*/ + int LOOPS; + /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ + float decay_factor; + /*! Direction to perform volume increase/decrease 1/-1*/ + int decay_direction; + /*! Number of samples between increase/decrease of volume */ + int decay_step; + /*! Volume factor of the tone */ + float volume; + /*! Debug on/off */ + int debug; + /*! FILE stream to write debug data to */ + FILE *debug_stream; + /*! Extra user data to attach to the session*/ + void *user_data; + /*! Buffer for storing sample data (dynamic) */ + teletone_audio_t *buffer; + /*! Size of the buffer */ + int datalen; + /*! In-Use size of the buffer */ + int samples; + /*! Callback function called during generation */ + int dynamic; + tone_handler handler; +}; - /*! - \brief Execute a tone generation script and call callbacks after each instruction - \param ts the tone generation session to execute on - \param cmd the script to execute - \return 0 - */ - int teletone_run(teletone_generation_session_t *ts, char *cmd); +typedef struct teletone_generation_session teletone_generation_session_t; + + +/*! + \brief Assign a set of tones to a tone_session indexed by a paticular index/character + \param ts the tone generation session + \param index the index to map the tone to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); + +/*! + \brief Assign a set of tones to a single tone map + \param map the map to assign the tones to + \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 + \return 0 +*/ +int teletone_set_map(teletone_tone_map_t *map, ...); + +/*! + \brief Initilize a tone generation session + \param ts the tone generation session to initilize + \param buflen the size of the buffer(in samples) to dynamically allocate + \param handler a callback function to execute when a tone generation instruction is complete + \param user_data optional user data to send + \return 0 +*/ +int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); + +/*! + \brief Free the buffer allocated by a tone generation session + \param ts the tone generation session to destroy + \return 0 +*/ +int teletone_destroy_session(teletone_generation_session_t *ts); + +/*! + \brief Execute a single tone generation instruction + \param ts the tone generation session to consult for parameters + \param map the tone mapping to use for the frequencies + \return 0 +*/ +int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); + +/*! + \brief Execute a tone generation script and call callbacks after each instruction + \param ts the tone generation session to execute on + \param cmd the script to execute + \return 0 +*/ +int teletone_run(teletone_generation_session_t *ts, char *cmd); #ifdef __cplusplus } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index dfa4837845..01eb7e75ba 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -34,8 +34,9 @@ #ifndef OPENZAP_H #define OPENZAP_H + #ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #endif #ifndef HAVE_STRINGS_H diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 1af9b8fc43..a089f8fc48 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -90,7 +90,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include + #ifndef _MSC_VER #include #endif @@ -98,7 +99,7 @@ #include #include #include -#include + static teletone_detection_descriptor_t dtmf_detect_row[GRID_FACTOR]; static teletone_detection_descriptor_t dtmf_detect_col[GRID_FACTOR]; diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 4e388c8d3b..9a36e6280c 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -70,6 +70,7 @@ */ #include + #define SMAX 32767 #define SMIN -32768 #define normalize_to_16bit(n) if (n > SMAX) n = SMAX; else if (n < SMIN) n = SMIN; @@ -78,6 +79,25 @@ #pragma warning(disable:4706) #endif +const 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 +}; + int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) { @@ -122,8 +142,9 @@ int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_ha ts->tmp_wait = -1; ts->handler = handler; ts->user_data = user_data; - ts->volume = 1500; + 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; @@ -181,34 +202,24 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need) int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map) { - teletone_process_t period = (1.0 / ts->rate) / ts->channels; + /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/ int i, c; int freqlen = 0; - teletone_process_t tones[TELETONE_MAX_TONES]; - int decay = 0; + teletone_dds_state_t tones[TELETONE_MAX_TONES]; + //int decay = 0; int duration; int wait = 0; - teletone_process_t sample; - + 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) { - if (ts->decay_step) { - if (ts->decay_factor) { - decay = (duration - (duration / ts->decay_factor)); - } else { - decay = 0; - } - } - if (ts->volume < 0) { - ts->volume = 0; - } - for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { - tones[freqlen] = (teletone_process_t) map->freqs[freqlen] * (2 * M_PI); + teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, vol); } if (ts->channels > 1) { @@ -220,17 +231,28 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m return -1; } } + for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) { - if (ts->decay_step && !(ts->samples % ts->decay_step) && ts->volume > 0 && ts->samples > decay) { - ts->volume += ts->decay_direction; + 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; map->freqs[j] && j < TELETONE_MAX_TONES; j++) { + teletone_dds_state_set_tx_level(&tones[j], vol); + } + dc = 0; + } } - sample = (teletone_process_t) 128; + sample = 128; for (i = 0; i < freqlen; i++) { - sample += ((teletone_process_t) 2 * (ts->volume > 0 ? ts->volume : 1) * cos(tones[i] * ts->samples * period)); + int32_t s = teletone_dds_modulate_sample(&tones[i]); + sample += s; } - normalize_to_16bit(sample); + sample /= freqlen; ts->buffer[ts->samples] = (teletone_audio_t)sample; for (c = 1; c < ts->channels; c++) { @@ -261,7 +283,8 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m fprintf(ts->debug_stream, "%s%0.2f", i == 0 ? "" : "+",map->freqs[i]); } - fprintf(ts->debug_stream, ") [volume %d; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %d; decay_step %d; wrote %d bytes]\n", + fprintf(ts->debug_stream, + ") [volume %0.2fDb; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %0.2f; decay_step %d(%dms); wrote %d bytes]\n", ts->volume, duration, duration / (ts->rate / 1000), @@ -271,6 +294,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m wait / (ts->rate / 1000), ts->decay_factor, ts->decay_step, + ts->decay_step / (ts->rate / 1000), ts->samples * 2); } } @@ -330,18 +354,23 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->duration = atoi(cur + 2) * (ts->rate / 1000); break; case 'v': - ts->volume = atoi(cur + 2); + { + float vol = atof(cur + 2); + if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { + ts->volume = vol; + } + } break; case '>': - ts->decay_factor = atoi(cur + 2); + ts->decay_step = atoi(cur + 2) * (ts->rate / 1000); ts->decay_direction = -1; break; case '<': - ts->decay_factor = atoi(cur + 2); + ts->decay_step = atoi(cur + 2) * (ts->rate / 1000); ts->decay_direction = 1; break; case '+': - ts->decay_step = atoi(cur + 2); + ts->decay_factor = atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); From c620d60f45532d6532e77a2b6916700cc7011d59 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 6 Jun 2007 23:05:36 +0000 Subject: [PATCH 0447/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@224 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 819e96c0f5..a8296a3334 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -62,6 +62,7 @@ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o +#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") HEADERS= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ @@ -102,8 +103,6 @@ TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w include general.makefile -$(OBJS): $(HEADERS) - all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) @@ -140,7 +139,7 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -%.o: %.c +%.o: %.c $(HEADERS) $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ dox: From 97013ae77a8d3af3067991cc4051be1eae75ca24 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 6 Jun 2007 23:05:36 +0000 Subject: [PATCH 0448/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@224 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 819e96c0f5..a8296a3334 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -62,6 +62,7 @@ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o +#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") HEADERS= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ @@ -102,8 +103,6 @@ TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w include general.makefile -$(OBJS): $(HEADERS) - all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) @@ -140,7 +139,7 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ -%.o: %.c +%.o: %.c $(HEADERS) $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ dox: From 9a0e8c6a1f0703e80f1ff869f5910e61506118f2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 6 Jun 2007 23:27:21 +0000 Subject: [PATCH 0449/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@225 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone.h | 9 ++------- libs/openzap/src/include/libteletone_generate.h | 4 ++-- libs/openzap/src/libteletone_generate.c | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index 351afa1413..aaf7b0ed47 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -73,11 +73,7 @@ #ifdef __cplusplus extern "C" { -#ifdef _doh -} #endif -#endif - #define TELETONE_MAX_DTMF_DIGITS 128 #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 @@ -85,9 +81,9 @@ extern "C" { typedef double teletone_process_t; /*! \file libteletone.h - \brief Top level include file + \brief Top level include file - This file should be included by applications using the library + This file should be included by applications using the library */ /*! \brief An abstraction to store a tone mapping */ @@ -96,7 +92,6 @@ typedef struct { teletone_process_t freqs[TELETONE_MAX_TONES]; } teletone_tone_map_t; - #if !defined(M_PI) /* C99 systems may not define M_PI */ #define M_PI 3.14159265358979323846264338327 diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 0ed8930539..be791555bd 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -112,7 +112,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - int32_t tx_level; + float tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -123,7 +123,7 @@ typedef struct teletone_dds_state teletone_dds_state_t; /* 3.02 represents twice the power */ #define DBM0_MAX_POWER (3.14f + 3.02f) -const int16_t TELETONE_SINES[SINE_TABLE_MAX]; +extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) { diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 9a36e6280c..edd573c7a1 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -79,7 +79,7 @@ #pragma warning(disable:4706) #endif -const int16_t TELETONE_SINES[SINE_TABLE_MAX] = { +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, From 101617d1740994d7922bf5bbb65fb85ef3cd271d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 6 Jun 2007 23:27:21 +0000 Subject: [PATCH 0450/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@225 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone.h | 9 ++------- libs/freetdm/src/include/libteletone_generate.h | 4 ++-- libs/freetdm/src/libteletone_generate.c | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index 351afa1413..aaf7b0ed47 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -73,11 +73,7 @@ #ifdef __cplusplus extern "C" { -#ifdef _doh -} #endif -#endif - #define TELETONE_MAX_DTMF_DIGITS 128 #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 @@ -85,9 +81,9 @@ extern "C" { typedef double teletone_process_t; /*! \file libteletone.h - \brief Top level include file + \brief Top level include file - This file should be included by applications using the library + This file should be included by applications using the library */ /*! \brief An abstraction to store a tone mapping */ @@ -96,7 +92,6 @@ typedef struct { teletone_process_t freqs[TELETONE_MAX_TONES]; } teletone_tone_map_t; - #if !defined(M_PI) /* C99 systems may not define M_PI */ #define M_PI 3.14159265358979323846264338327 diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 0ed8930539..be791555bd 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -112,7 +112,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - int32_t tx_level; + float tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -123,7 +123,7 @@ typedef struct teletone_dds_state teletone_dds_state_t; /* 3.02 represents twice the power */ #define DBM0_MAX_POWER (3.14f + 3.02f) -const int16_t TELETONE_SINES[SINE_TABLE_MAX]; +extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) { diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 9a36e6280c..edd573c7a1 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -79,7 +79,7 @@ #pragma warning(disable:4706) #endif -const int16_t TELETONE_SINES[SINE_TABLE_MAX] = { +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, From 42cd11f708aba23638d0136758983a2208a67c47 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 00:20:41 +0000 Subject: [PATCH 0451/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@226 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index edd573c7a1..5c46b1afd1 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -284,7 +284,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m } fprintf(ts->debug_stream, - ") [volume %0.2fDb; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %0.2f; decay_step %d(%dms); wrote %d bytes]\n", + ") [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), From 4524bd46031873f5365f666b6cc6785c8b30c753 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 00:20:41 +0000 Subject: [PATCH 0452/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@226 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index edd573c7a1..5c46b1afd1 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -284,7 +284,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m } fprintf(ts->debug_stream, - ") [volume %0.2fDb; samples %d(%dms) x %d channel%s; wait %d(%dms); decay_factor %0.2f; decay_step %d(%dms); wrote %d bytes]\n", + ") [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), From ffb5e9557a568cac166d338c56a36b8ee6e2ca9b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 7 Jun 2007 00:33:31 +0000 Subject: [PATCH 0453/1766] use float instead of double for teletone. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@227 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone.h | 4 +-- libs/openzap/src/include/libteletone_detect.h | 2 +- .../src/include/libteletone_generate.h | 34 ++++++++++++------- libs/openzap/src/include/openzap.h | 3 ++ libs/openzap/src/libteletone_detect.c | 14 ++++---- libs/openzap/src/libteletone_generate.c | 10 +++--- libs/openzap/src/zap_io.c | 2 +- 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index aaf7b0ed47..5c9616cb2a 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -78,7 +78,7 @@ extern "C" { #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 -typedef double teletone_process_t; +typedef float teletone_process_t; /*! \file libteletone.h \brief Top level include file @@ -94,7 +94,7 @@ typedef struct { #if !defined(M_PI) /* C99 systems may not define M_PI */ -#define M_PI 3.14159265358979323846264338327 +#define M_PI 3.14159265358979323846264338327f #endif #ifdef _MSC_VER diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index 15d5e9ddfb..10fece6cc7 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -132,7 +132,7 @@ extern "C" { #define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define GRID_FACTOR 4 #define BLOCK_LEN 102 -#define M_TWO_PI 2.0*M_PI +#define M_TWO_PI 2.0f*M_PI /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ typedef struct { diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index be791555bd..fb2d06b0d7 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -79,7 +79,23 @@ extern "C" { #include #include +#ifdef WIN32 +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +#endif +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; +#else #include +#endif #include #include #include @@ -89,17 +105,9 @@ extern float powf (float, float); #endif #include #include - -#include -#include -#include #ifndef _MSC_VER #include -#include #endif -#include -#include -#include #include #include #include @@ -112,7 +120,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - float tx_level; + teletone_process_t tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -145,7 +153,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); @@ -158,7 +166,7 @@ static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, fl dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); } @@ -196,13 +204,13 @@ struct teletone_generation_session { /*! Number of loops to repeat the entire set of instructions*/ int LOOPS; /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - float decay_factor; + teletone_process_t decay_factor; /*! Direction to perform volume increase/decrease 1/-1*/ int decay_direction; /*! Number of samples between increase/decrease of volume */ int decay_step; /*! Volume factor of the tone */ - float volume; + teletone_process_t volume; /*! Debug on/off */ int debug; /*! FILE stream to write debug data to */ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 01eb7e75ba..e1dc74c649 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -53,6 +53,9 @@ #endif #ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif #if (_MSC_VER >= 1400) /* VC8+ */ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index a089f8fc48..4148751172 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -145,16 +145,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, for (i = 0; i < GRID_FACTOR; i++) { theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); - dtmf_detect_row[i].fac = 2.0*cos(theta); + dtmf_detect_row[i].fac = (teletone_process_t)(2.0f*cos(theta)); theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); - dtmf_detect_col[i].fac = 2.0*cos(theta); + dtmf_detect_col[i].fac = (teletone_process_t)(2.0f*cos(theta)); - theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); - dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); + theta = M_TWO_PI*(dtmf_row[i]*2.0f/(teletone_process_t)sample_rate); + dtmf_detect_row_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta)); - theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); - dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); + theta = M_TWO_PI*(dtmf_col[i]*2.0f/(teletone_process_t)sample_rate); + dtmf_detect_col_2nd[i].fac = (teletone_process_t)(2.0f*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]); @@ -201,7 +201,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } mt->tone_count++; theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); - mt->tdd[x].fac = 2.0 * cos(theta); + mt->tdd[x].fac = (teletone_process_t)(2.0f * cos(theta)); goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]); } diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 5c46b1afd1..131f795c1e 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -211,7 +211,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m int wait = 0; int32_t sample; int32_t dc = 0; - float vol = ts->volume; + teletone_process_t 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; @@ -234,7 +234,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m 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; + teletone_process_t nvol = vol + ts->decay_direction * ts->decay_factor; int j; if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) { @@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) break; case 'v': { - float vol = atof(cur + 2); + teletone_process_t vol = (teletone_process_t)atof(cur + 2); if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { ts->volume = vol; } @@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->decay_direction = 1; break; case '+': - ts->decay_factor = atof(cur + 2); + ts->decay_factor = (teletone_process_t)atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); @@ -419,7 +419,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->tmp_wait = atoi(p) * (ts->rate / 1000); i++; } else { - mymap.freqs[i++ - 2] = atof(p); + mymap.freqs[i++ - 2] = (teletone_process_t)atof(p); } p = next; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index d0da23752f..d4df53f3ce 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -306,7 +306,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) do { teletone_process_t this; next = strchr(p, ','); - this = atof(p); + this = (teletone_process_t)atof(p); span->tone_detect_map[index].freqs[i++] = this; if (next) { p = next + 1; From 437e7e9eb31de01c0fe8de87e21692860544e4bb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 7 Jun 2007 00:33:31 +0000 Subject: [PATCH 0454/1766] use float instead of double for teletone. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@227 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone.h | 4 +-- libs/freetdm/src/include/libteletone_detect.h | 2 +- .../src/include/libteletone_generate.h | 34 ++++++++++++------- libs/freetdm/src/include/openzap.h | 3 ++ libs/freetdm/src/libteletone_detect.c | 14 ++++---- libs/freetdm/src/libteletone_generate.c | 10 +++--- libs/freetdm/src/zap_io.c | 2 +- 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index aaf7b0ed47..5c9616cb2a 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -78,7 +78,7 @@ extern "C" { #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 -typedef double teletone_process_t; +typedef float teletone_process_t; /*! \file libteletone.h \brief Top level include file @@ -94,7 +94,7 @@ typedef struct { #if !defined(M_PI) /* C99 systems may not define M_PI */ -#define M_PI 3.14159265358979323846264338327 +#define M_PI 3.14159265358979323846264338327f #endif #ifdef _MSC_VER diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 15d5e9ddfb..10fece6cc7 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -132,7 +132,7 @@ extern "C" { #define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define GRID_FACTOR 4 #define BLOCK_LEN 102 -#define M_TWO_PI 2.0*M_PI +#define M_TWO_PI 2.0f*M_PI /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ typedef struct { diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index be791555bd..fb2d06b0d7 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -79,7 +79,23 @@ extern "C" { #include #include +#ifdef WIN32 +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +#endif +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; +#else #include +#endif #include #include #include @@ -89,17 +105,9 @@ extern float powf (float, float); #endif #include #include - -#include -#include -#include #ifndef _MSC_VER #include -#include #endif -#include -#include -#include #include #include #include @@ -112,7 +120,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - float tx_level; + teletone_process_t tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -145,7 +153,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); @@ -158,7 +166,7 @@ static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, fl dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); } @@ -196,13 +204,13 @@ struct teletone_generation_session { /*! Number of loops to repeat the entire set of instructions*/ int LOOPS; /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - float decay_factor; + teletone_process_t decay_factor; /*! Direction to perform volume increase/decrease 1/-1*/ int decay_direction; /*! Number of samples between increase/decrease of volume */ int decay_step; /*! Volume factor of the tone */ - float volume; + teletone_process_t volume; /*! Debug on/off */ int debug; /*! FILE stream to write debug data to */ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 01eb7e75ba..e1dc74c649 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -53,6 +53,9 @@ #endif #ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif #if (_MSC_VER >= 1400) /* VC8+ */ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index a089f8fc48..4148751172 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -145,16 +145,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, for (i = 0; i < GRID_FACTOR; i++) { theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); - dtmf_detect_row[i].fac = 2.0*cos(theta); + dtmf_detect_row[i].fac = (teletone_process_t)(2.0f*cos(theta)); theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); - dtmf_detect_col[i].fac = 2.0*cos(theta); + dtmf_detect_col[i].fac = (teletone_process_t)(2.0f*cos(theta)); - theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); - dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); + theta = M_TWO_PI*(dtmf_row[i]*2.0f/(teletone_process_t)sample_rate); + dtmf_detect_row_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta)); - theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); - dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); + theta = M_TWO_PI*(dtmf_col[i]*2.0f/(teletone_process_t)sample_rate); + dtmf_detect_col_2nd[i].fac = (teletone_process_t)(2.0f*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]); @@ -201,7 +201,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } mt->tone_count++; theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); - mt->tdd[x].fac = 2.0 * cos(theta); + mt->tdd[x].fac = (teletone_process_t)(2.0f * cos(theta)); goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]); } diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 5c46b1afd1..131f795c1e 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -211,7 +211,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m int wait = 0; int32_t sample; int32_t dc = 0; - float vol = ts->volume; + teletone_process_t 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; @@ -234,7 +234,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m 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; + teletone_process_t nvol = vol + ts->decay_direction * ts->decay_factor; int j; if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) { @@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) break; case 'v': { - float vol = atof(cur + 2); + teletone_process_t vol = (teletone_process_t)atof(cur + 2); if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { ts->volume = vol; } @@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->decay_direction = 1; break; case '+': - ts->decay_factor = atof(cur + 2); + ts->decay_factor = (teletone_process_t)atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); @@ -419,7 +419,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->tmp_wait = atoi(p) * (ts->rate / 1000); i++; } else { - mymap.freqs[i++ - 2] = atof(p); + mymap.freqs[i++ - 2] = (teletone_process_t)atof(p); } p = next; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index d0da23752f..d4df53f3ce 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -306,7 +306,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) do { teletone_process_t this; next = strchr(p, ','); - this = atof(p); + this = (teletone_process_t)atof(p); span->tone_detect_map[index].freqs[i++] = this; if (next) { p = next + 1; From cd21bbc273daa80bfc471db5b7a83c91d3b89a95 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 01:37:09 +0000 Subject: [PATCH 0455/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@228 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index 5c9616cb2a..5bb38b5c37 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -78,7 +78,7 @@ extern "C" { #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 -typedef float teletone_process_t; +typedef double teletone_process_t; /*! \file libteletone.h \brief Top level include file From 23f5980fd77450bcdce317cbabdb9583d033f0b5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 01:37:09 +0000 Subject: [PATCH 0456/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@228 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index 5c9616cb2a..5bb38b5c37 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -78,7 +78,7 @@ extern "C" { #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 -typedef float teletone_process_t; +typedef double teletone_process_t; /*! \file libteletone.h \brief Top level include file From f77dd4ad7682daee5c93de4a48a84fabc21f90c9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 01:45:32 +0000 Subject: [PATCH 0457/1766] revert changes that totally break everything (try it on unix too) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@229 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone.h | 2 +- libs/openzap/src/include/libteletone_detect.h | 2 +- .../src/include/libteletone_generate.h | 34 +++++++------------ libs/openzap/src/libteletone_detect.c | 14 ++++---- libs/openzap/src/libteletone_generate.c | 10 +++--- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index 5bb38b5c37..aaf7b0ed47 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -94,7 +94,7 @@ typedef struct { #if !defined(M_PI) /* C99 systems may not define M_PI */ -#define M_PI 3.14159265358979323846264338327f +#define M_PI 3.14159265358979323846264338327 #endif #ifdef _MSC_VER diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index 10fece6cc7..15d5e9ddfb 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -132,7 +132,7 @@ extern "C" { #define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define GRID_FACTOR 4 #define BLOCK_LEN 102 -#define M_TWO_PI 2.0f*M_PI +#define M_TWO_PI 2.0*M_PI /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ typedef struct { diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index fb2d06b0d7..be791555bd 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -79,23 +79,7 @@ extern "C" { #include #include -#ifdef WIN32 -#ifdef _MSC_VER -#ifndef __inline__ -#define __inline__ __inline -#endif -#endif -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; -#else #include -#endif #include #include #include @@ -105,9 +89,17 @@ extern float powf (float, float); #endif #include #include + +#include +#include +#include #ifndef _MSC_VER #include +#include #endif +#include +#include +#include #include #include #include @@ -120,7 +112,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - teletone_process_t tx_level; + float tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -153,7 +145,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); @@ -166,7 +158,7 @@ static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, te dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); } @@ -204,13 +196,13 @@ struct teletone_generation_session { /*! Number of loops to repeat the entire set of instructions*/ int LOOPS; /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - teletone_process_t decay_factor; + float decay_factor; /*! Direction to perform volume increase/decrease 1/-1*/ int decay_direction; /*! Number of samples between increase/decrease of volume */ int decay_step; /*! Volume factor of the tone */ - teletone_process_t volume; + float volume; /*! Debug on/off */ int debug; /*! FILE stream to write debug data to */ diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 4148751172..a089f8fc48 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -145,16 +145,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, for (i = 0; i < GRID_FACTOR; i++) { theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); - dtmf_detect_row[i].fac = (teletone_process_t)(2.0f*cos(theta)); + dtmf_detect_row[i].fac = 2.0*cos(theta); theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); - dtmf_detect_col[i].fac = (teletone_process_t)(2.0f*cos(theta)); + dtmf_detect_col[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_row[i]*2.0f/(teletone_process_t)sample_rate); - dtmf_detect_row_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta)); + theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]*2.0f/(teletone_process_t)sample_rate); - dtmf_detect_col_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta)); + theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_col_2nd[i].fac = 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]); @@ -201,7 +201,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } mt->tone_count++; theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); - mt->tdd[x].fac = (teletone_process_t)(2.0f * cos(theta)); + mt->tdd[x].fac = 2.0 * cos(theta); goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]); } diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 131f795c1e..5c46b1afd1 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -211,7 +211,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m int wait = 0; int32_t sample; int32_t dc = 0; - teletone_process_t vol = ts->volume; + 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; @@ -234,7 +234,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) { if (ts->decay_direction && ++dc >= ts->decay_step) { - teletone_process_t nvol = vol + ts->decay_direction * ts->decay_factor; + float nvol = vol + ts->decay_direction * ts->decay_factor; int j; if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) { @@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) break; case 'v': { - teletone_process_t vol = (teletone_process_t)atof(cur + 2); + float vol = atof(cur + 2); if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { ts->volume = vol; } @@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->decay_direction = 1; break; case '+': - ts->decay_factor = (teletone_process_t)atof(cur + 2); + ts->decay_factor = atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); @@ -419,7 +419,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->tmp_wait = atoi(p) * (ts->rate / 1000); i++; } else { - mymap.freqs[i++ - 2] = (teletone_process_t)atof(p); + mymap.freqs[i++ - 2] = atof(p); } p = next; From 8e96687bb321484857b63712b45c8322560f9b6e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 01:45:32 +0000 Subject: [PATCH 0458/1766] revert changes that totally break everything (try it on unix too) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@229 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone.h | 2 +- libs/freetdm/src/include/libteletone_detect.h | 2 +- .../src/include/libteletone_generate.h | 34 +++++++------------ libs/freetdm/src/libteletone_detect.c | 14 ++++---- libs/freetdm/src/libteletone_generate.c | 10 +++--- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index 5bb38b5c37..aaf7b0ed47 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -94,7 +94,7 @@ typedef struct { #if !defined(M_PI) /* C99 systems may not define M_PI */ -#define M_PI 3.14159265358979323846264338327f +#define M_PI 3.14159265358979323846264338327 #endif #ifdef _MSC_VER diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 10fece6cc7..15d5e9ddfb 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -132,7 +132,7 @@ extern "C" { #define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define GRID_FACTOR 4 #define BLOCK_LEN 102 -#define M_TWO_PI 2.0f*M_PI +#define M_TWO_PI 2.0*M_PI /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ typedef struct { diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index fb2d06b0d7..be791555bd 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -79,23 +79,7 @@ extern "C" { #include #include -#ifdef WIN32 -#ifdef _MSC_VER -#ifndef __inline__ -#define __inline__ __inline -#endif -#endif -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; -#else #include -#endif #include #include #include @@ -105,9 +89,17 @@ extern float powf (float, float); #endif #include #include + +#include +#include +#include #ifndef _MSC_VER #include +#include #endif +#include +#include +#include #include #include #include @@ -120,7 +112,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - teletone_process_t tx_level; + float tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -153,7 +145,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); @@ -166,7 +158,7 @@ static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, te dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); } @@ -204,13 +196,13 @@ struct teletone_generation_session { /*! Number of loops to repeat the entire set of instructions*/ int LOOPS; /*! Number to mutiply total samples by to determine when to begin ascent or decent e.g. 0=beginning 4=(last 25%) */ - teletone_process_t decay_factor; + float decay_factor; /*! Direction to perform volume increase/decrease 1/-1*/ int decay_direction; /*! Number of samples between increase/decrease of volume */ int decay_step; /*! Volume factor of the tone */ - teletone_process_t volume; + float volume; /*! Debug on/off */ int debug; /*! FILE stream to write debug data to */ diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 4148751172..a089f8fc48 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -145,16 +145,16 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, for (i = 0; i < GRID_FACTOR; i++) { theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); - dtmf_detect_row[i].fac = (teletone_process_t)(2.0f*cos(theta)); + dtmf_detect_row[i].fac = 2.0*cos(theta); theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); - dtmf_detect_col[i].fac = (teletone_process_t)(2.0f*cos(theta)); + dtmf_detect_col[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_row[i]*2.0f/(teletone_process_t)sample_rate); - dtmf_detect_row_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta)); + theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]*2.0f/(teletone_process_t)sample_rate); - dtmf_detect_col_2nd[i].fac = (teletone_process_t)(2.0f*cos(theta)); + theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); + dtmf_detect_col_2nd[i].fac = 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]); @@ -201,7 +201,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } mt->tone_count++; theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); - mt->tdd[x].fac = (teletone_process_t)(2.0f * cos(theta)); + mt->tdd[x].fac = 2.0 * cos(theta); goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]); } diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 131f795c1e..5c46b1afd1 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -211,7 +211,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m int wait = 0; int32_t sample; int32_t dc = 0; - teletone_process_t vol = ts->volume; + 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; @@ -234,7 +234,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) { if (ts->decay_direction && ++dc >= ts->decay_step) { - teletone_process_t nvol = vol + ts->decay_direction * ts->decay_factor; + float nvol = vol + ts->decay_direction * ts->decay_factor; int j; if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) { @@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) break; case 'v': { - teletone_process_t vol = (teletone_process_t)atof(cur + 2); + float vol = atof(cur + 2); if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { ts->volume = vol; } @@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->decay_direction = 1; break; case '+': - ts->decay_factor = (teletone_process_t)atof(cur + 2); + ts->decay_factor = atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); @@ -419,7 +419,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->tmp_wait = atoi(p) * (ts->rate / 1000); i++; } else { - mymap.freqs[i++ - 2] = (teletone_process_t)atof(p); + mymap.freqs[i++ - 2] = atof(p); } p = next; From d699160e0cfa75327de09e108e8b5d1a434979e8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 01:45:59 +0000 Subject: [PATCH 0459/1766] add file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@230 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testtones.c | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 libs/openzap/src/testtones.c diff --git a/libs/openzap/src/testtones.c b/libs/openzap/src/testtones.c new file mode 100644 index 0000000000..b041095b76 --- /dev/null +++ b/libs/openzap/src/testtones.c @@ -0,0 +1,71 @@ +#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; + + wrote = teletone_mux_tones(ts, map); + write(tmp->fd, ts->buffer, wrote * 2); + return 0; +} + +#if 1 +int main(int argc, char *argv[]) +{ + teletone_generation_session_t ts; + struct ttmp tmp; + + if (argc < 2) { + 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!\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); +} +#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; + + 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; i++) { + sample = teletone_dds_modulate_sample(&dds) * 20; + write(fd, &sample, sizeof(sample)); + } + + } + + close(fd); +} +#endif From ad8984f4cf11ea52014cec5929e0a4eb198ccc6a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 01:45:59 +0000 Subject: [PATCH 0460/1766] add file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@230 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testtones.c | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 libs/freetdm/src/testtones.c diff --git a/libs/freetdm/src/testtones.c b/libs/freetdm/src/testtones.c new file mode 100644 index 0000000000..b041095b76 --- /dev/null +++ b/libs/freetdm/src/testtones.c @@ -0,0 +1,71 @@ +#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; + + wrote = teletone_mux_tones(ts, map); + write(tmp->fd, ts->buffer, wrote * 2); + return 0; +} + +#if 1 +int main(int argc, char *argv[]) +{ + teletone_generation_session_t ts; + struct ttmp tmp; + + if (argc < 2) { + 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!\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); +} +#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; + + 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; i++) { + sample = teletone_dds_modulate_sample(&dds) * 20; + write(fd, &sample, sizeof(sample)); + } + + } + + close(fd); +} +#endif From 8472ec1850208ddb484229544eb4c5a67d9c223e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 03:28:07 +0000 Subject: [PATCH 0461/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@231 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/include/libteletone_generate.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index be791555bd..1101212708 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -112,7 +112,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - float tx_level; + teletone_process_t tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -145,24 +145,24 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) +{ + dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); +} + +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); - + if (dds->tx_level != tx_level || !dds->scale_factor) { - dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); + teletone_dds_state_set_tx_level(dds, tx_level); } dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) -{ - dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); -} - /*! \file libteletone_generate.h From d5ccb35af00a9d2578f423cdd3b56580a9f8c74e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 03:28:07 +0000 Subject: [PATCH 0462/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@231 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/include/libteletone_generate.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index be791555bd..1101212708 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -112,7 +112,7 @@ struct teletone_dds_state { uint32_t scale_factor; uint32_t phase_accumulator; int16_t sample; - float tx_level; + teletone_process_t tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -145,24 +145,24 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, float tone, uint32_t rate, float tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) +{ + dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); +} + +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); - + if (dds->tx_level != tx_level || !dds->scale_factor) { - dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); + teletone_dds_state_set_tx_level(dds, tx_level); } dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) -{ - dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); -} - /*! \file libteletone_generate.h From 0faa06ab1a1fda5dd11ac5e1df578e4987d15915 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 7 Jun 2007 03:29:48 +0000 Subject: [PATCH 0463/1766] int types and inline for windows build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@232 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/include/libteletone_generate.h | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 1101212708..8a324216d0 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -79,7 +79,21 @@ extern "C" { #include #include +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +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; +#else #include +#endif #include #include #include @@ -89,17 +103,9 @@ extern float powf (float, float); #endif #include #include - -#include -#include -#include #ifndef _MSC_VER #include -#include #endif -#include -#include -#include #include #include #include From d2b30a2c710338b027ce5376d152c3e23da4b6ee Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 7 Jun 2007 03:29:48 +0000 Subject: [PATCH 0464/1766] int types and inline for windows build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@232 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/include/libteletone_generate.h | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 1101212708..8a324216d0 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -79,7 +79,21 @@ extern "C" { #include #include +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +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; +#else #include +#endif #include #include #include @@ -89,17 +103,9 @@ extern float powf (float, float); #endif #include #include - -#include -#include -#include #ifndef _MSC_VER #include -#include #endif -#include -#include -#include #include #include #include From cc17fa213d7f9ae0c3ea234977160095d7b83dc9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 7 Jun 2007 03:36:03 +0000 Subject: [PATCH 0465/1766] atof returns double not float? git-svn-id: http://svn.openzap.org/svn/openzap/trunk@233 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 5c46b1afd1..bb904b2d68 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) break; case 'v': { - float vol = atof(cur + 2); + float vol = (float)atof(cur + 2); if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { ts->volume = vol; } @@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->decay_direction = 1; break; case '+': - ts->decay_factor = atof(cur + 2); + ts->decay_factor = (float)atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); From ea4fb5c3b1bc0ae9f0cc00b8c76a68eac0ac2135 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 7 Jun 2007 03:36:03 +0000 Subject: [PATCH 0466/1766] atof returns double not float? git-svn-id: http://svn.openzap.org/svn/openzap/trunk@233 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 5c46b1afd1..bb904b2d68 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -355,7 +355,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) break; case 'v': { - float vol = atof(cur + 2); + float vol = (float)atof(cur + 2); if (vol <= TELETONE_VOL_DB_MAX && vol >= TELETONE_VOL_DB_MIN) { ts->volume = vol; } @@ -370,7 +370,7 @@ int teletone_run(teletone_generation_session_t *ts, char *cmd) ts->decay_direction = 1; break; case '+': - ts->decay_factor = atof(cur + 2); + ts->decay_factor = (float)atof(cur + 2); break; case 'w': ts->wait = atoi(cur + 2) * (ts->rate / 1000); From b7461ff9c42c500ff6fba3bc9349cda767f90ed5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 03:48:07 +0000 Subject: [PATCH 0467/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@234 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone_generate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 8a324216d0..5340f767cc 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -151,12 +151,12 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, float tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); From d852547058156ebf55952d5a028773b2730bdef3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 03:48:07 +0000 Subject: [PATCH 0468/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@234 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone_generate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 8a324216d0..5340f767cc 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -151,12 +151,12 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds return (int16_t) (sample * dds->scale_factor >> 15); } -static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, teletone_process_t tx_level) +static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, float tx_level) { dds->phase_accumulator = 0; dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); From 144f92600476870007e3592c8dd4c04a52155238 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 05:13:39 +0000 Subject: [PATCH 0469/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@235 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/tones.conf | 8 ++--- libs/openzap/general.makefile | 2 +- .../src/include/libteletone_generate.h | 32 +++++++++++++------ libs/openzap/src/libteletone_generate.c | 5 +-- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index e24ccccfcd..d0f27acd93 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -1,14 +1,14 @@ [us] -generate-dial => %(1000,0,350,440) +generate-dial => v=-7;%(1000,0,350,440) detect-dial => 350,440 -generate-ring => %(2000,4000,440,480) +generate-ring => v=-7;%(2000,4000,440,480) detect-ring => 440,480 -generate-busy => %(500,500,480,620) +generate-busy => v=-7;%(500,500,480,620) detect-busy => 480,620 -generate-attn => %(100,100,1400,2060,2450,2600) +generate-attn => v=0;%(100,100,1400,2060,2450,2600) detect-attn => 1400,2060,2450,2600 detect-fail1 => 913.8 diff --git a/libs/openzap/general.makefile b/libs/openzap/general.makefile index 5b2fcb9821..b6d3777436 100644 --- a/libs/openzap/general.makefile +++ b/libs/openzap/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 5340f767cc..177c893966 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -112,12 +112,12 @@ extern float powf (float, float); #define TELETONE_VOL_DB_MAX 0 #define TELETONE_VOL_DB_MIN -63 +#define MAX_PHASE_TONES 4 struct teletone_dds_state { - uint32_t phase_rate; + uint32_t phase_rate[MAX_PHASE_TONES]; uint32_t scale_factor; uint32_t phase_accumulator; - int16_t sample; teletone_process_t tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -131,11 +131,20 @@ typedef struct teletone_dds_state teletone_dds_state_t; extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; -static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) +static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint32_t rate) +{ + return (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); +} + +static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex) { int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; int16_t sample; + if (pindex >= MAX_PHASE_TONES) { + pindex = 0; + } + if (bitmask & SINE_TABLE_MAX) { sine_index = SINE_TABLE_LEN - sine_index; } @@ -146,7 +155,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds sample *= -1; } - dds->phase_accumulator += dds->phase_rate; + dds->phase_accumulator += dds->phase_rate[pindex]; return (int16_t) (sample * dds->scale_factor >> 15); } @@ -154,19 +163,22 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); + dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, float tx_level) +static __inline__ void teletone_dds_state_reset_accum(teletone_dds_state_t *dds) { dds->phase_accumulator = 0; - dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); - +} - if (dds->tx_level != tx_level || !dds->scale_factor) { - teletone_dds_state_set_tx_level(dds, tx_level); +static __inline__ int teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, uint32_t pindex) +{ + if (pindex < MAX_PHASE_TONES) { + dds->phase_rate[pindex] = teletone_dds_phase_rate(tone, rate); + return 0; } - dds->tx_level = tx_level; + return -1; } diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index bb904b2d68..2804f0a920 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -219,7 +219,8 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m if (map->freqs[0] > 0) { for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { - teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, vol); + 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) { @@ -249,7 +250,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m sample = 128; for (i = 0; i < freqlen; i++) { - int32_t s = teletone_dds_modulate_sample(&tones[i]); + int32_t s = teletone_dds_state_modulate_sample(&tones[i], 0); sample += s; } sample /= freqlen; From 19bf0794a7cc4778f730f1d098fcb1db71823f5d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 05:13:39 +0000 Subject: [PATCH 0470/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@235 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/tones.conf | 8 ++--- libs/freetdm/general.makefile | 2 +- .../src/include/libteletone_generate.h | 32 +++++++++++++------ libs/freetdm/src/libteletone_generate.c | 5 +-- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index e24ccccfcd..d0f27acd93 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -1,14 +1,14 @@ [us] -generate-dial => %(1000,0,350,440) +generate-dial => v=-7;%(1000,0,350,440) detect-dial => 350,440 -generate-ring => %(2000,4000,440,480) +generate-ring => v=-7;%(2000,4000,440,480) detect-ring => 440,480 -generate-busy => %(500,500,480,620) +generate-busy => v=-7;%(500,500,480,620) detect-busy => 480,620 -generate-attn => %(100,100,1400,2060,2450,2600) +generate-attn => v=0;%(100,100,1400,2060,2450,2600) detect-attn => 1400,2060,2450,2600 detect-fail1 => 913.8 diff --git a/libs/freetdm/general.makefile b/libs/freetdm/general.makefile index 5b2fcb9821..b6d3777436 100644 --- a/libs/freetdm/general.makefile +++ b/libs/freetdm/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter +CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 5340f767cc..177c893966 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -112,12 +112,12 @@ extern float powf (float, float); #define TELETONE_VOL_DB_MAX 0 #define TELETONE_VOL_DB_MIN -63 +#define MAX_PHASE_TONES 4 struct teletone_dds_state { - uint32_t phase_rate; + uint32_t phase_rate[MAX_PHASE_TONES]; uint32_t scale_factor; uint32_t phase_accumulator; - int16_t sample; teletone_process_t tx_level; }; typedef struct teletone_dds_state teletone_dds_state_t; @@ -131,11 +131,20 @@ typedef struct teletone_dds_state teletone_dds_state_t; extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; -static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds) +static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint32_t rate) +{ + return (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); +} + +static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex) { int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; int16_t sample; + if (pindex >= MAX_PHASE_TONES) { + pindex = 0; + } + if (bitmask & SINE_TABLE_MAX) { sine_index = SINE_TABLE_LEN - sine_index; } @@ -146,7 +155,7 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds sample *= -1; } - dds->phase_accumulator += dds->phase_rate; + dds->phase_accumulator += dds->phase_rate[pindex]; return (int16_t) (sample * dds->scale_factor >> 15); } @@ -154,19 +163,22 @@ static __inline__ int16_t teletone_dds_modulate_sample(teletone_dds_state_t *dds static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) { dds->scale_factor = (int) (powf(10.0f, (tx_level - DBM0_MAX_POWER) / 20.0f) * (32767.0f * 1.414214f)); + dds->tx_level = tx_level; } -static __inline__ void teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, float tx_level) +static __inline__ void teletone_dds_state_reset_accum(teletone_dds_state_t *dds) { dds->phase_accumulator = 0; - dds->phase_rate = (int32_t) ((tone * MAX_PHASE_ACCUMULATOR) / rate); - +} - if (dds->tx_level != tx_level || !dds->scale_factor) { - teletone_dds_state_set_tx_level(dds, tx_level); +static __inline__ int teletone_dds_state_set_tone(teletone_dds_state_t *dds, teletone_process_t tone, uint32_t rate, uint32_t pindex) +{ + if (pindex < MAX_PHASE_TONES) { + dds->phase_rate[pindex] = teletone_dds_phase_rate(tone, rate); + return 0; } - dds->tx_level = tx_level; + return -1; } diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index bb904b2d68..2804f0a920 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -219,7 +219,8 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m if (map->freqs[0] > 0) { for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { - teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, vol); + 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) { @@ -249,7 +250,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m sample = 128; for (i = 0; i < freqlen; i++) { - int32_t s = teletone_dds_modulate_sample(&tones[i]); + int32_t s = teletone_dds_state_modulate_sample(&tones[i], 0); sample += s; } sample /= freqlen; From 43432933a83d019129793977b11a230d882c38bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 05:30:09 +0000 Subject: [PATCH 0471/1766] make comments that are not on the beginning of the line require a double char ;; <-- like this git-svn-id: http://svn.openzap.org/svn/openzap/trunk@236 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 5 ++++- libs/openzap/src/zap_config.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 7290d38d88..eb4337b156 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -143,7 +143,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_flag_locked(chan, 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(chan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index e4d4116244..5974574805 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -157,7 +157,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } - if ((end = strchr(*var, '#')) != 0 || (end = strchr(*var, ';')) != 0) { + if (((end = strchr(*var, '#')) || (end = strchr(*var, ';'))) && *(end+1) == *end) { *end = '\0'; end--; } else if ((end = strchr(*var, '\n')) != 0) { From 5b5efe5567e68babb6924421a0feb6ca8d4e90da Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 7 Jun 2007 05:30:09 +0000 Subject: [PATCH 0472/1766] make comments that are not on the beginning of the line require a double char ;; <-- like this git-svn-id: http://svn.openzap.org/svn/openzap/trunk@236 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 5 ++++- libs/freetdm/src/zap_config.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 7290d38d88..eb4337b156 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -143,7 +143,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_flag_locked(chan, 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(chan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index e4d4116244..5974574805 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -157,7 +157,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } - if ((end = strchr(*var, '#')) != 0 || (end = strchr(*var, ';')) != 0) { + if (((end = strchr(*var, '#')) || (end = strchr(*var, ';'))) && *(end+1) == *end) { *end = '\0'; end--; } else if ((end = strchr(*var, '\n')) != 0) { From a2e2b5bd4a37f0fa05b70ead5216dfad3d172c58 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Jun 2007 23:42:28 +0000 Subject: [PATCH 0473/1766] add the Illudium Q-36 Explosive FSK Modulator git-svn-id: http://svn.openzap.org/svn/openzap/trunk@237 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 2 +- libs/openzap/src/fsk.c | 2 +- libs/openzap/src/include/fsk.h | 2 + .../src/include/libteletone_generate.h | 1 - libs/openzap/src/include/openzap.h | 64 +++++++- libs/openzap/src/include/zap_types.h | 35 ++-- libs/openzap/src/testcid.c | 68 +++++++- libs/openzap/src/zap_callerid.c | 155 ++++++++++++++++++ libs/openzap/src/zap_io.c | 109 +++++++++--- libs/openzap/src/zap_isdn.c | 4 +- 10 files changed, 385 insertions(+), 57 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index a8296a3334..17661180d7 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -113,7 +113,7 @@ testapp: $(SRC)/testapp.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread testtones: $(SRC)/testtones.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread diff --git a/libs/openzap/src/fsk.c b/libs/openzap/src/fsk.c index 69b2edfc88..d933166227 100644 --- a/libs/openzap/src/fsk.c +++ b/libs/openzap/src/fsk.c @@ -46,7 +46,7 @@ #define M_PI 3.14159265358979323846 #endif -static fsk_modem_definition_t fsk_modem_definitions[] = +fsk_modem_definition_t fsk_modem_definitions[] = { { /* FSK_V23_FORWARD_MODE1 */ 1700, 1300, 600 }, { /* FSK_V23_FORWARD_MODE2 */ 2100, 1300, 1200 }, diff --git a/libs/openzap/src/include/fsk.h b/libs/openzap/src/include/fsk.h index e6ca995d57..b098444d03 100644 --- a/libs/openzap/src/include/fsk.h +++ b/libs/openzap/src/include/fsk.h @@ -107,5 +107,7 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle); void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); +extern fsk_modem_definition_t fsk_modem_definitions[]; + #endif diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 177c893966..de6697bb29 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -156,7 +156,6 @@ static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_ } dds->phase_accumulator += dds->phase_rate[pindex]; - return (int16_t) (sample * dds->scale_factor >> 15); } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index e1dc74c649..0e7887bd20 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -241,6 +241,46 @@ static __inline__ char *zap_clean_string(char *s) return s; } +struct zap_bitstream { + uint8_t *data; + uint32_t datalen; + uint32_t byte_index; + uint8_t bit_index; + int8_t endian; + uint8_t top; + uint8_t bot; + uint8_t ss; + uint8_t ssv; +}; + +struct zap_fsk_data_state { + dsp_fsk_handle_t *fsk1200_handle; + uint8_t init; + uint8_t *buf; + size_t bufsize; + zap_size_t blen; + zap_size_t bpos; + zap_size_t dlen; + zap_size_t ppos; + int checksum; +}; + +struct zap_fsk_modulator { + teletone_dds_state_t dds; + zap_bitstream_t bs; + uint32_t carrier_bits_start; + uint32_t carrier_bits_stop; + uint32_t chan_sieze_bits; + uint32_t bit_factor; + uint32_t bit_accum; + uint32_t sample_counter; + fsk_modem_types_t modem_type; + zap_fsk_data_state_t *fsk_data; + zap_fsk_write_sample_t write_sample_callback; + void *user_data; + int16_t sample_buffer[64]; +}; + struct zap_caller_data { char cid_name[80]; char cid_num[80]; @@ -364,11 +404,31 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +#define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ + zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ + zap_fsk_modulator_send_data(_it); \ + zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) + +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); +int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp); +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss); zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); - +zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen); +zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); +zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number); zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); @@ -403,7 +463,7 @@ zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e); +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, int ss); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 84f74ee556..2ae6e7b05d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -60,9 +60,15 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +#define ZAP_FSK_MOD_FACTOR 0x10000 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 @@ -75,28 +81,12 @@ typedef enum { MDMF_NO_NUM = 4, MDMF_PHONE_NAME = 7, MDMF_NO_NAME = 8, - MDMF_INVALID = 9 + 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", "INVALID" +#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) -struct zap_fsk_data_state { - dsp_fsk_handle_t *fsk1200_handle; - uint8_t init; - uint8_t *buf; - size_t bufsize; - zap_size_t blen; - zap_size_t bpos; - zap_size_t dlen; - zap_size_t ppos; - int checksum; -}; -typedef struct zap_fsk_data_state zap_fsk_data_state_t; - -typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state); - - - #define ZAP_TONEMAP_LEN 128 typedef enum { ZAP_TONEMAP_NONE, @@ -364,13 +354,18 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; #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)(char *file, const char *func, int line, int level, char *fmt, ...); typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; typedef struct hashtable_itr zap_hash_itr_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; + #endif /* For Emacs: diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index 545794689c..a75dee81de 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -1,17 +1,73 @@ #include "openzap.h" +struct helper { + int fd; +}; + +zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) +{ + int x ; + + struct helper *foo = (struct helper *) user_data; + for (x = 0; x < buflen; x++) { + printf("%x ", buf[x]); + } + printf("\n"); + write(foo->fd, buf, buflen * 2); +} + int main(int argc, char *argv[]) { - zap_fsk_data_state_t state = {0}; - int fd; + 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; int type, mlen; char *sp; char str[128] = ""; char fbuf[256]; + uint8_t databuf[1024] = ""; + struct helper foo; + + + + if (argc < 2) { + int x; + char *url = "sip:cool@rad.com"; - if (argc < 2 || zap_fsk_demod_init(&state, 8000, fbuf, sizeof(fbuf))) { + if ((fd = open("tone.raw", O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { + fprintf(stderr, "File Error!\n", strerror(errno)); + exit(-1); + } + + + zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); +#if 1 + zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06061234", 8); + zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, "5551212", 7); + zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); + //zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, 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)); + + if (fd > -1) { + close (fd); + } + + return 0; + } + + if (zap_fsk_demod_init(&fsk_data, 8000, fbuf, sizeof(fbuf))) { printf("wtf\n"); return 0; } @@ -22,19 +78,19 @@ int main(int argc, char *argv[]) } while((len = read(fd, buf, sizeof(buf))) > 0) { - if (zap_fsk_demod_feed(&state, buf, len / 2) != ZAP_SUCCESS) { + if (zap_fsk_demod_feed(&fsk_data, buf, len / 2) != ZAP_SUCCESS) { break; } } - while(zap_fsk_data_parse(&state, &type, &sp, &mlen) == ZAP_SUCCESS) { + 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 %d (%s) LEN %d VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); } - zap_fsk_demod_destroy(&state); + zap_fsk_demod_destroy(&fsk_data); close(fd); } diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index f3a685f55a..7b41117670 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -3,6 +3,7 @@ #include "uart.h" + static void fsk_byte_handler (void *x, int data) { zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x; @@ -36,6 +37,62 @@ static void fsk_byte_handler (void *x, int data) } } +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; +} + +zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, 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; +} + +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen) +{ + state->buf[0] = ZAP_CID_TYPE_MDMF; + state->buf[state->bpos++] = type; + state->buf[state->bpos++] = datalen; + memcpy(&state->buf[state->bpos], data, datalen); + state->bpos += datalen; + return ZAP_SUCCESS; +} + + +zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) +{ + uint32_t i; + uint8_t check = 0; + + state->buf[1] = state->bpos - 2; + + for (i = 0; i < state->bpos; i++) { + check += state->buf[i]; + } + + state->checksum = state->buf[state->bpos] = 256 - check; + state->bpos++; + + state->dlen = state->bpos; + state->blen = state->buf[1]; + + return ZAP_SUCCESS; +} + + zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) { @@ -54,6 +111,7 @@ zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, c } 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; } @@ -139,4 +197,101 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ return ZAP_SUCCESS; } +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; +} + + +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; + int 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))) { + fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + } else { + break; + } + } + + return i; +} + + +void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) +{ + uint32_t i = 0; + zap_size_t r = 0; + int 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))) { + fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + } else { + break; + } + bit = !bit; + } + + +} + + +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))) { + fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + } else { + break; + } + } +} + + +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 = (fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate; + 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, 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_io.c b/libs/openzap/src/zap_io.c index d4df53f3ce..597979c231 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1832,34 +1832,95 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss) { - int i,j = 0, k, l = 0; + memset(bsp, 0, sizeof(*bsp)); + bsp->data = data; + bsp->datalen = datalen; + bsp->endian = endian; + bsp->ss = ss; + + if (endian < 0) { + bsp->top = bsp->bit_index = 7; + bsp->bot = 0; + } else { + bsp->top = bsp->bit_index = 0; + bsp->bot = 7; + } + +} + +int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) +{ + int8_t bit = -1; + + + if (bsp->byte_index >= bsp->datalen) { + goto done; + } + + if (bsp->ss) { + if (!bsp->ssv) { + bsp->ssv = 1; + return 0; + } else if (bsp->ssv == 2) { + bsp->byte_index++; + bsp->ssv = 0; + return 1; + } + } + + + + + bit = (bsp->data[bsp->byte_index] >> (bsp->bit_index)) & 1; + + if (bsp->bit_index == bsp->bot) { + bsp->bit_index = bsp->top; + if (bsp->ss) { + bsp->ssv = 2; + goto done; + } + + if (++bsp->byte_index > bsp->datalen) { + bit = -1; + goto done; + } + + } else { + bsp->bit_index += bsp->endian; + } + + + done: + return bit; +} + + +void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, int ss) +{ + zap_bitstream_t bs; + int j = 0, c = 0; + int8_t bit; + uint32_t last; if (blen < (bl * 10) + 2) { - return; - } - - for (k = 0 ; k < bl; k++) { - buf[j++] = '['; - if (e) { - for(i = 7; i >= 0; i--) { - buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); - } - } else { - for(i = 0; i < 8; i++) { - buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); - } - } - buf[j++] = ']'; - buf[j++] = ' '; - if (++l == 6) { - buf[j++] = '\n'; - l = 0; - } - } + return; + } - buf[j++] = '\0'; + zap_bitstream_init(&bs, b, bl, e, ss); + last = bs.byte_index; + while((bit = zap_bitstream_get_bit(&bs)) > -1) { + buf[j++] = bit ? '1' : '0'; + if (bs.byte_index != last) { + buf[j++] = ' '; + last = bs.byte_index; + if (++c == 8) { + buf[j++] = '\n'; + c = 0; + } + } + } } diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 76ad83ca25..f9577e4798 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -89,7 +89,7 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) zap_size_t len = (zap_size_t) mlen; #ifdef IODEBUG char bb[4096] = ""; - print_bits(msg, (int)len, bb, sizeof(bb), 1); + print_bits(msg, (int)len, bb, sizeof(bb), 1, 0); zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif @@ -140,7 +140,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG char bb[4096] = ""; - print_bits(buf, (int)len, bb, sizeof(bb), 1); + print_bits(buf, (int)len, bb, sizeof(bb), 1, 0); zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif From 77c4ec357d9d52505fca6e9c9acd9df6ca4b8c28 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Jun 2007 23:42:28 +0000 Subject: [PATCH 0474/1766] add the Illudium Q-36 Explosive FSK Modulator git-svn-id: http://svn.openzap.org/svn/openzap/trunk@237 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 2 +- libs/freetdm/src/fsk.c | 2 +- libs/freetdm/src/include/fsk.h | 2 + .../src/include/libteletone_generate.h | 1 - libs/freetdm/src/include/openzap.h | 64 +++++++- libs/freetdm/src/include/zap_types.h | 35 ++-- libs/freetdm/src/testcid.c | 68 +++++++- libs/freetdm/src/zap_callerid.c | 155 ++++++++++++++++++ libs/freetdm/src/zap_io.c | 109 +++++++++--- libs/freetdm/src/zap_isdn.c | 4 +- 10 files changed, 385 insertions(+), 57 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index a8296a3334..17661180d7 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -113,7 +113,7 @@ testapp: $(SRC)/testapp.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread testtones: $(SRC)/testtones.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index 69b2edfc88..d933166227 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -46,7 +46,7 @@ #define M_PI 3.14159265358979323846 #endif -static fsk_modem_definition_t fsk_modem_definitions[] = +fsk_modem_definition_t fsk_modem_definitions[] = { { /* FSK_V23_FORWARD_MODE1 */ 1700, 1300, 600 }, { /* FSK_V23_FORWARD_MODE2 */ 2100, 1300, 1200 }, diff --git a/libs/freetdm/src/include/fsk.h b/libs/freetdm/src/include/fsk.h index e6ca995d57..b098444d03 100644 --- a/libs/freetdm/src/include/fsk.h +++ b/libs/freetdm/src/include/fsk.h @@ -107,5 +107,7 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle); void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); +extern fsk_modem_definition_t fsk_modem_definitions[]; + #endif diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 177c893966..de6697bb29 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -156,7 +156,6 @@ static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_ } dds->phase_accumulator += dds->phase_rate[pindex]; - return (int16_t) (sample * dds->scale_factor >> 15); } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index e1dc74c649..0e7887bd20 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -241,6 +241,46 @@ static __inline__ char *zap_clean_string(char *s) return s; } +struct zap_bitstream { + uint8_t *data; + uint32_t datalen; + uint32_t byte_index; + uint8_t bit_index; + int8_t endian; + uint8_t top; + uint8_t bot; + uint8_t ss; + uint8_t ssv; +}; + +struct zap_fsk_data_state { + dsp_fsk_handle_t *fsk1200_handle; + uint8_t init; + uint8_t *buf; + size_t bufsize; + zap_size_t blen; + zap_size_t bpos; + zap_size_t dlen; + zap_size_t ppos; + int checksum; +}; + +struct zap_fsk_modulator { + teletone_dds_state_t dds; + zap_bitstream_t bs; + uint32_t carrier_bits_start; + uint32_t carrier_bits_stop; + uint32_t chan_sieze_bits; + uint32_t bit_factor; + uint32_t bit_accum; + uint32_t sample_counter; + fsk_modem_types_t modem_type; + zap_fsk_data_state_t *fsk_data; + zap_fsk_write_sample_t write_sample_callback; + void *user_data; + int16_t sample_buffer[64]; +}; + struct zap_caller_data { char cid_name[80]; char cid_num[80]; @@ -364,11 +404,31 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +#define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ + zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ + zap_fsk_modulator_send_data(_it); \ + zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) + +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); +int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp); +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss); zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); - +zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen); +zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); +zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number); zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); @@ -403,7 +463,7 @@ zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e); +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, int ss); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 84f74ee556..2ae6e7b05d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -60,9 +60,15 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +#define ZAP_FSK_MOD_FACTOR 0x10000 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 @@ -75,28 +81,12 @@ typedef enum { MDMF_NO_NUM = 4, MDMF_PHONE_NAME = 7, MDMF_NO_NAME = 8, - MDMF_INVALID = 9 + 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", "INVALID" +#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) -struct zap_fsk_data_state { - dsp_fsk_handle_t *fsk1200_handle; - uint8_t init; - uint8_t *buf; - size_t bufsize; - zap_size_t blen; - zap_size_t bpos; - zap_size_t dlen; - zap_size_t ppos; - int checksum; -}; -typedef struct zap_fsk_data_state zap_fsk_data_state_t; - -typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state); - - - #define ZAP_TONEMAP_LEN 128 typedef enum { ZAP_TONEMAP_NONE, @@ -364,13 +354,18 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; #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)(char *file, const char *func, int line, int level, char *fmt, ...); typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; typedef struct hashtable_itr zap_hash_itr_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; + #endif /* For Emacs: diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index 545794689c..a75dee81de 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -1,17 +1,73 @@ #include "openzap.h" +struct helper { + int fd; +}; + +zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) +{ + int x ; + + struct helper *foo = (struct helper *) user_data; + for (x = 0; x < buflen; x++) { + printf("%x ", buf[x]); + } + printf("\n"); + write(foo->fd, buf, buflen * 2); +} + int main(int argc, char *argv[]) { - zap_fsk_data_state_t state = {0}; - int fd; + 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; int type, mlen; char *sp; char str[128] = ""; char fbuf[256]; + uint8_t databuf[1024] = ""; + struct helper foo; + + + + if (argc < 2) { + int x; + char *url = "sip:cool@rad.com"; - if (argc < 2 || zap_fsk_demod_init(&state, 8000, fbuf, sizeof(fbuf))) { + if ((fd = open("tone.raw", O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { + fprintf(stderr, "File Error!\n", strerror(errno)); + exit(-1); + } + + + zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); +#if 1 + zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06061234", 8); + zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, "5551212", 7); + zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); + //zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, 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)); + + if (fd > -1) { + close (fd); + } + + return 0; + } + + if (zap_fsk_demod_init(&fsk_data, 8000, fbuf, sizeof(fbuf))) { printf("wtf\n"); return 0; } @@ -22,19 +78,19 @@ int main(int argc, char *argv[]) } while((len = read(fd, buf, sizeof(buf))) > 0) { - if (zap_fsk_demod_feed(&state, buf, len / 2) != ZAP_SUCCESS) { + if (zap_fsk_demod_feed(&fsk_data, buf, len / 2) != ZAP_SUCCESS) { break; } } - while(zap_fsk_data_parse(&state, &type, &sp, &mlen) == ZAP_SUCCESS) { + 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 %d (%s) LEN %d VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); } - zap_fsk_demod_destroy(&state); + zap_fsk_demod_destroy(&fsk_data); close(fd); } diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index f3a685f55a..7b41117670 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -3,6 +3,7 @@ #include "uart.h" + static void fsk_byte_handler (void *x, int data) { zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x; @@ -36,6 +37,62 @@ static void fsk_byte_handler (void *x, int data) } } +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; +} + +zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, 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; +} + +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen) +{ + state->buf[0] = ZAP_CID_TYPE_MDMF; + state->buf[state->bpos++] = type; + state->buf[state->bpos++] = datalen; + memcpy(&state->buf[state->bpos], data, datalen); + state->bpos += datalen; + return ZAP_SUCCESS; +} + + +zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) +{ + uint32_t i; + uint8_t check = 0; + + state->buf[1] = state->bpos - 2; + + for (i = 0; i < state->bpos; i++) { + check += state->buf[i]; + } + + state->checksum = state->buf[state->bpos] = 256 - check; + state->bpos++; + + state->dlen = state->bpos; + state->blen = state->buf[1]; + + return ZAP_SUCCESS; +} + + zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) { @@ -54,6 +111,7 @@ zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, c } 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; } @@ -139,4 +197,101 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ return ZAP_SUCCESS; } +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; +} + + +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; + int 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))) { + fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + } else { + break; + } + } + + return i; +} + + +void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) +{ + uint32_t i = 0; + zap_size_t r = 0; + int 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))) { + fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + } else { + break; + } + bit = !bit; + } + + +} + + +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))) { + fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + } else { + break; + } + } +} + + +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 = (fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate; + 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, 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/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index d4df53f3ce..597979c231 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1832,34 +1832,95 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e) +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss) { - int i,j = 0, k, l = 0; + memset(bsp, 0, sizeof(*bsp)); + bsp->data = data; + bsp->datalen = datalen; + bsp->endian = endian; + bsp->ss = ss; + + if (endian < 0) { + bsp->top = bsp->bit_index = 7; + bsp->bot = 0; + } else { + bsp->top = bsp->bit_index = 0; + bsp->bot = 7; + } + +} + +int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) +{ + int8_t bit = -1; + + + if (bsp->byte_index >= bsp->datalen) { + goto done; + } + + if (bsp->ss) { + if (!bsp->ssv) { + bsp->ssv = 1; + return 0; + } else if (bsp->ssv == 2) { + bsp->byte_index++; + bsp->ssv = 0; + return 1; + } + } + + + + + bit = (bsp->data[bsp->byte_index] >> (bsp->bit_index)) & 1; + + if (bsp->bit_index == bsp->bot) { + bsp->bit_index = bsp->top; + if (bsp->ss) { + bsp->ssv = 2; + goto done; + } + + if (++bsp->byte_index > bsp->datalen) { + bit = -1; + goto done; + } + + } else { + bsp->bit_index += bsp->endian; + } + + + done: + return bit; +} + + +void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, int ss) +{ + zap_bitstream_t bs; + int j = 0, c = 0; + int8_t bit; + uint32_t last; if (blen < (bl * 10) + 2) { - return; - } - - for (k = 0 ; k < bl; k++) { - buf[j++] = '['; - if (e) { - for(i = 7; i >= 0; i--) { - buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); - } - } else { - for(i = 0; i < 8; i++) { - buf[j++] = ((b[k] & (1 << i)) ? '1' : '0'); - } - } - buf[j++] = ']'; - buf[j++] = ' '; - if (++l == 6) { - buf[j++] = '\n'; - l = 0; - } - } + return; + } - buf[j++] = '\0'; + zap_bitstream_init(&bs, b, bl, e, ss); + last = bs.byte_index; + while((bit = zap_bitstream_get_bit(&bs)) > -1) { + buf[j++] = bit ? '1' : '0'; + if (bs.byte_index != last) { + buf[j++] = ' '; + last = bs.byte_index; + if (++c == 8) { + buf[j++] = '\n'; + c = 0; + } + } + } } diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 76ad83ca25..f9577e4798 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -89,7 +89,7 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) zap_size_t len = (zap_size_t) mlen; #ifdef IODEBUG char bb[4096] = ""; - print_bits(msg, (int)len, bb, sizeof(bb), 1); + print_bits(msg, (int)len, bb, sizeof(bb), 1, 0); zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif @@ -140,7 +140,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG char bb[4096] = ""; - print_bits(buf, (int)len, bb, sizeof(bb), 1); + print_bits(buf, (int)len, bb, sizeof(bb), 1, 0); zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif From 715b0d9c4b3d3890e415670a372b39b2c1ed9b64 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Jun 2007 23:43:32 +0000 Subject: [PATCH 0475/1766] add the Illudium Q-36 Explosive FSK Modulator git-svn-id: http://svn.openzap.org/svn/openzap/trunk@238 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testcid.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index a75dee81de..ec9efd169a 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -9,10 +9,6 @@ zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) int x ; struct helper *foo = (struct helper *) user_data; - for (x = 0; x < buflen; x++) { - printf("%x ", buf[x]); - } - printf("\n"); write(foo->fd, buf, buflen * 2); } From a40eb444f389c1808a6befc8965bae6293b3b8b0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Jun 2007 23:43:32 +0000 Subject: [PATCH 0476/1766] add the Illudium Q-36 Explosive FSK Modulator git-svn-id: http://svn.openzap.org/svn/openzap/trunk@238 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testcid.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index a75dee81de..ec9efd169a 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -9,10 +9,6 @@ zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) int x ; struct helper *foo = (struct helper *) user_data; - for (x = 0; x < buflen; x++) { - printf("%x ", buf[x]); - } - printf("\n"); write(foo->fd, buf, buflen * 2); } From a2d983628e2f4b07c6ec6d6f297a4f391d3eaea2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 9 Jun 2007 00:56:53 +0000 Subject: [PATCH 0477/1766] more callerid code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@239 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 10 +++++++- libs/openzap/src/testcid.c | 12 ++++++--- libs/openzap/src/zap_callerid.c | 14 ++++++++--- libs/openzap/src/zap_io.c | 40 ++++++++++++++++++++++++++---- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 0e7887bd20..13683aaa3b 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -274,6 +274,8 @@ struct zap_fsk_modulator { uint32_t bit_factor; uint32_t bit_accum; uint32_t sample_counter; + int32_t samples_per_bit; + int32_t est_bytes; fsk_modem_types_t modem_type; zap_fsk_data_state_t *fsk_data; zap_fsk_write_sample_t write_sample_callback; @@ -310,7 +312,7 @@ struct zap_channel { zap_channel_state_t last_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; - uint32_t dtmf_delay; + uint32_t buffer_delay; zap_event_t event_header; char last_error[256]; zio_event_cb_t event_callback; @@ -318,6 +320,7 @@ struct zap_channel { uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; zap_buffer_t *digit_buffer; + zap_buffer_t *fsk_buffer; uint32_t dtmf_on; uint32_t dtmf_off; teletone_generation_session_t tone_session; @@ -404,6 +407,10 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); +int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); +void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); +void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); #define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ zap_fsk_modulator_send_data(_it); \ @@ -433,6 +440,7 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); void zap_channel_clear_needed_tones(zap_channel_t *zchan); +zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index ec9efd169a..eca951d252 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -2,6 +2,7 @@ struct helper { int fd; + int wrote; }; zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) @@ -10,6 +11,8 @@ zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) struct helper *foo = (struct helper *) user_data; write(foo->fd, buf, buflen * 2); + foo->wrote += buflen * 2; + return ZAP_SUCCESS; } int main(int argc, char *argv[]) @@ -24,8 +27,8 @@ int main(int argc, char *argv[]) char str[128] = ""; char fbuf[256]; uint8_t databuf[1024] = ""; - struct helper foo; - + struct helper foo = {0}; + int x, bytes, start_bits = 180, stop_bits = 5, sbits = 300; if (argc < 2) { @@ -43,7 +46,8 @@ int main(int argc, char *argv[]) zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06061234", 8); zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, "5551212", 7); zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); - //zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, url, strlen(url)); + for(x = 0; x < 0; x++) + zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, url, strlen(url)); #else zap_fsk_data_add_sdmf(&fsk_data, "06061234", "0"); //zap_fsk_data_add_sdmf(&state, "06061234", "5551212"); @@ -56,6 +60,8 @@ int main(int argc, char *argv[]) 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("%d %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); + if (fd > -1) { close (fd); } diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 7b41117670..8c44e11e60 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -223,7 +223,9 @@ int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, 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))) { - fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + break; + } } else { break; } @@ -241,7 +243,9 @@ void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) 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))) { - fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + break; + } } else { break; } @@ -259,7 +263,9 @@ void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) 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))) { - fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + break; + } } else { break; } @@ -283,6 +289,8 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, 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 = (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 = ((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); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 597979c231..cb9a38bafc 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -411,6 +411,27 @@ zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) return ZAP_NOTIMPL; } +static zap_status_t zchan_fsk_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) +{ + zap_channel_t *zchan = (zap_channel_t *) user_data; + zap_buffer_write(zchan->fsk_buffer, buf, buflen * 2); + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) +{ + struct zap_fsk_modulator fsk_trans; + + if (!zchan->fsk_buffer) { + zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); + } + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, -14, 180, 5, 180, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_send_all((&fsk_trans)); + zchan->buffer_delay = 2000 / zchan->effective_interval; + return ZAP_SUCCESS; +} + + zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->mutex); @@ -1454,8 +1475,9 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t dtmf_blen, max = datasize; - + zap_size_t blen, max = datasize; + zap_buffer_t *buffer = NULL; + assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1488,7 +1510,15 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } } - if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer)) && (!zchan->dtmf_delay || --zchan->dtmf_delay == 0)) { + if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { + if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { + buffer = zchan->fsk_buffer; + } else if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + buffer = zchan->dtmf_buffer; + } + } + + if (buffer) { zap_size_t dlen = *datalen; uint8_t auxbuf[1024]; zap_size_t len, br; @@ -1497,9 +1527,9 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data dlen *= 2; } - len = dtmf_blen > dlen ? dlen : dtmf_blen; + len = blen > dlen ? dlen : blen; - br = zap_buffer_read(zchan->dtmf_buffer, auxbuf, len); + br = zap_buffer_read(buffer, auxbuf, len); if (br < dlen) { memset(auxbuf + br, 0, dlen - br); From 56904825c12b7918ee62cd66b509c068c9d14355 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 9 Jun 2007 00:56:53 +0000 Subject: [PATCH 0478/1766] more callerid code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@239 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 10 +++++++- libs/freetdm/src/testcid.c | 12 ++++++--- libs/freetdm/src/zap_callerid.c | 14 ++++++++--- libs/freetdm/src/zap_io.c | 40 ++++++++++++++++++++++++++---- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 0e7887bd20..13683aaa3b 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -274,6 +274,8 @@ struct zap_fsk_modulator { uint32_t bit_factor; uint32_t bit_accum; uint32_t sample_counter; + int32_t samples_per_bit; + int32_t est_bytes; fsk_modem_types_t modem_type; zap_fsk_data_state_t *fsk_data; zap_fsk_write_sample_t write_sample_callback; @@ -310,7 +312,7 @@ struct zap_channel { zap_channel_state_t last_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; - uint32_t dtmf_delay; + uint32_t buffer_delay; zap_event_t event_header; char last_error[256]; zio_event_cb_t event_callback; @@ -318,6 +320,7 @@ struct zap_channel { uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; zap_buffer_t *digit_buffer; + zap_buffer_t *fsk_buffer; uint32_t dtmf_on; uint32_t dtmf_off; teletone_generation_session_t tone_session; @@ -404,6 +407,10 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; +zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); +int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); +void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); +void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); #define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ zap_fsk_modulator_send_data(_it); \ @@ -433,6 +440,7 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); void zap_channel_clear_needed_tones(zap_channel_t *zchan); +zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index ec9efd169a..eca951d252 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -2,6 +2,7 @@ struct helper { int fd; + int wrote; }; zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) @@ -10,6 +11,8 @@ zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) struct helper *foo = (struct helper *) user_data; write(foo->fd, buf, buflen * 2); + foo->wrote += buflen * 2; + return ZAP_SUCCESS; } int main(int argc, char *argv[]) @@ -24,8 +27,8 @@ int main(int argc, char *argv[]) char str[128] = ""; char fbuf[256]; uint8_t databuf[1024] = ""; - struct helper foo; - + struct helper foo = {0}; + int x, bytes, start_bits = 180, stop_bits = 5, sbits = 300; if (argc < 2) { @@ -43,7 +46,8 @@ int main(int argc, char *argv[]) zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06061234", 8); zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, "5551212", 7); zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); - //zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, url, strlen(url)); + for(x = 0; x < 0; x++) + zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, url, strlen(url)); #else zap_fsk_data_add_sdmf(&fsk_data, "06061234", "0"); //zap_fsk_data_add_sdmf(&state, "06061234", "5551212"); @@ -56,6 +60,8 @@ int main(int argc, char *argv[]) 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("%d %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); + if (fd > -1) { close (fd); } diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 7b41117670..8c44e11e60 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -223,7 +223,9 @@ int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, 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))) { - fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + break; + } } else { break; } @@ -241,7 +243,9 @@ void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) 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))) { - fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + break; + } } else { break; } @@ -259,7 +263,9 @@ void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) 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))) { - fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data); + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + break; + } } else { break; } @@ -283,6 +289,8 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, 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 = (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 = ((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); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 597979c231..cb9a38bafc 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -411,6 +411,27 @@ zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) return ZAP_NOTIMPL; } +static zap_status_t zchan_fsk_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) +{ + zap_channel_t *zchan = (zap_channel_t *) user_data; + zap_buffer_write(zchan->fsk_buffer, buf, buflen * 2); + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) +{ + struct zap_fsk_modulator fsk_trans; + + if (!zchan->fsk_buffer) { + zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); + } + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, -14, 180, 5, 180, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_send_all((&fsk_trans)); + zchan->buffer_delay = 2000 / zchan->effective_interval; + return ZAP_SUCCESS; +} + + zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->mutex); @@ -1454,8 +1475,9 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t dtmf_blen, max = datasize; - + zap_size_t blen, max = datasize; + zap_buffer_t *buffer = NULL; + assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1488,7 +1510,15 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } } - if (zchan->dtmf_buffer && (dtmf_blen = zap_buffer_inuse(zchan->dtmf_buffer)) && (!zchan->dtmf_delay || --zchan->dtmf_delay == 0)) { + if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { + if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { + buffer = zchan->fsk_buffer; + } else if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + buffer = zchan->dtmf_buffer; + } + } + + if (buffer) { zap_size_t dlen = *datalen; uint8_t auxbuf[1024]; zap_size_t len, br; @@ -1497,9 +1527,9 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data dlen *= 2; } - len = dtmf_blen > dlen ? dlen : dtmf_blen; + len = blen > dlen ? dlen : blen; - br = zap_buffer_read(zchan->dtmf_buffer, auxbuf, len); + br = zap_buffer_read(buffer, auxbuf, len); if (br < dlen) { memset(auxbuf + br, 0, dlen - br); From c2f9afc1063210f39b54e7c3df975f721ad83091 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 9 Jun 2007 14:23:02 +0000 Subject: [PATCH 0479/1766] caller id works both ways w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@240 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/general.makefile | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 11 +++-- libs/openzap/src/include/openzap.h | 16 ++++--- libs/openzap/src/testcid.c | 14 ++++-- libs/openzap/src/zap_analog.c | 61 +++++++++++++++++++++++--- libs/openzap/src/zap_callerid.c | 2 +- libs/openzap/src/zap_io.c | 33 +++++++++----- libs/openzap/src/zap_wanpipe.c | 2 + libs/openzap/src/zap_zt.c | 1 + 9 files changed, 110 insertions(+), 32 deletions(-) diff --git a/libs/openzap/general.makefile b/libs/openzap/general.makefile index b6d3777436..9a060c86c7 100644 --- a/libs/openzap/general.makefile +++ b/libs/openzap/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter +CC_CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter #-std=c99 -pedantic -Wno-unused-parameter diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 822459a1be..21f63022d9 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -620,12 +620,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((p = strchr(outbound_profile->destination_number, '/'))) { dest = p + 1; span_id = atoi(outbound_profile->destination_number); - if ((p = strchr(dest, '/'))) { - chan_id = atoi(dest); - dest = p + 1; - } + chan_id = atoi(dest); } + dest = outbound_profile->destination_number; + if (!dest) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -643,6 +642,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } + if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -667,6 +667,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi snprintf(name, sizeof(name), "OPENZAP/%s", dest); switch_channel_set_name(channel, name); zap_set_string(zchan->caller_data.ani, dest); + zap_set_string(zchan->caller_data.cid_name, outbound_profile->caller_id_name); + zap_set_string(zchan->caller_data.cid_num, outbound_profile->caller_id_number); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -681,6 +683,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } zap_channel_outgoing_call(zchan); + return SWITCH_CAUSE_SUCCESS; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 13683aaa3b..d38cf87938 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -178,7 +178,6 @@ \command flag the or'd list of flags to set */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) - #define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ zap_mutex_lock(obj->mutex); \ (obj)->flags |= (flag); \ @@ -193,9 +192,14 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); -#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); \ - zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ - zap_channel_set_state(obj, s); +#define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + } else { \ + int st = obj->state; \ + zap_channel_set_state(obj, s); \ + if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ + else zap_log(ZAP_LOG_WARNING, "VETO Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ + } #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -433,7 +437,7 @@ zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen); +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen); zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number); zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); @@ -452,7 +456,7 @@ zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); zap_status_t zap_span_find(uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); -zap_status_t zap_span_close_all(zap_io_interface_t *zio); +zap_status_t zap_span_close_all(void); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index eca951d252..d374a34081 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -29,7 +29,9 @@ int main(int argc, char *argv[]) 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; @@ -41,10 +43,16 @@ int main(int argc, char *argv[]) } + 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, "06061234", 8); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, "5551212", 7); + + zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, 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, "14149361212", 7); zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); for(x = 0; x < 0; x++) zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, url, strlen(url)); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index eb4337b156..421c17b73c 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -127,16 +127,19 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.buffer = NULL; if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n"); goto done; } if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { snprintf(chan->last_error, sizeof(chan->last_error), "memory error!"); + zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); goto done; } if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); goto done; } @@ -189,7 +192,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 60000) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); - } else { + } else if (!chan->fsk_buffer || !zap_buffer_inuse(chan->fsk_buffer)) { zap_sleep(interval); continue; } @@ -218,8 +221,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 1000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + + if (state_counter > 500) { + if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } else { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } } } break; @@ -254,6 +262,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); } + if (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer)) { + zap_log(ZAP_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n"); + zap_buffer_zero(chan->fsk_buffer); + } + + if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); } @@ -309,6 +323,43 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_GENRING: { + 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); + localtime_r(&now, &tm); + 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(chan->caller_data.cid_num)) { + mt = MDMF_NO_NUM; + zap_set_string(chan->caller_data.cid_num, "O"); + } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { + mt = MDMF_NO_NUM; + } else { + mt = MDMF_PHONE_NUM; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, strlen(chan->caller_data.cid_num)); + + if (zap_strlen_zero(chan->caller_data.cid_name)) { + mt = MDMF_NO_NAME; + zap_set_string(chan->caller_data.cid_name, "O"); + } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { + mt = MDMF_NO_NAME; + } else { + mt = MDMF_PHONE_NAME; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, strlen(chan->caller_data.cid_name)); + + zap_fsk_data_add_checksum(&fsk_data); + zap_channel_send_fsk_data(chan, &fsk_data, -14); + //zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; @@ -374,6 +425,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "READ ERROR\n"); goto done; } @@ -412,7 +464,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_clear_detected_tones(chan); } - if (chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) { + if ((chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) || (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer))) { rlen = len; memset(frame, 0, len); zap_channel_write(chan, frame, sizeof(frame), &rlen); @@ -506,7 +558,6 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - /*zap_channel_command(event->channel, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");*/ zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); zap_thread_create_detached(zap_analog_channel_run, event->channel); } diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 8c44e11e60..25229befbe 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -61,7 +61,7 @@ zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen) +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen) { state->buf[0] = ZAP_CID_TYPE_MDMF; state->buf[state->bpos++] = type; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index cb9a38bafc..eb5b342721 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -235,7 +235,7 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) return status; } -zap_status_t zap_span_close_all(zap_io_interface_t *zio) +zap_status_t zap_span_close_all(void) { zap_span_t *span; uint32_t i, j; @@ -425,9 +425,9 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ if (!zchan->fsk_buffer) { zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, -14, 180, 5, 180, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 180, zchan_fsk_write_sample, zchan); zap_fsk_modulator_send_all((&fsk_trans)); - zchan->buffer_delay = 2000 / zchan->effective_interval; + zchan->buffer_delay = 3500 / zchan->effective_interval; return ZAP_SUCCESS; } @@ -497,8 +497,8 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) { int ok = 1; - - zap_mutex_unlock(zchan->mutex); + + zap_mutex_lock(zchan->mutex); if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { @@ -511,6 +511,17 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } } + if (zchan->state == ZAP_CHANNEL_STATE_BUSY) { + + switch(state) { + case ZAP_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + if (state == zchan->state) { ok = 0; } @@ -660,7 +671,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } - if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && !zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); @@ -701,7 +712,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_mutex_unlock(check->mutex); } - done: + done: zap_mutex_unlock(globals.mutex); @@ -1526,11 +1537,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data if (zchan->native_codec != ZAP_CODEC_SLIN) { dlen *= 2; } - + len = blen > dlen ? dlen : blen; br = zap_buffer_read(buffer, auxbuf, len); - if (br < dlen) { memset(auxbuf + br, 0, dlen - br); } @@ -1548,7 +1558,6 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } } - if (zchan->fds[1]) { unsigned int dlen = (unsigned int) *datalen; write(zchan->fds[1], data, dlen); @@ -1792,14 +1801,14 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_ZT_SUPPORT + zap_span_close_all(); + if (interfaces.zt_interface) { - zap_span_close_all(interfaces.zt_interface); zt_destroy(); } #endif #ifdef ZAP_WANPIPE_SUPPORT if (interfaces.wanpipe_interface) { - zap_span_close_all(interfaces.wanpipe_interface); wanpipe_destroy(); } #endif diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index b9acfc2b0c..1ac08b40f6 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -696,6 +696,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; } @@ -705,6 +706,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; goto event; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 26ac640f79..90f310fc92 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -465,6 +465,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) case ZT_EVENT_RINGOFFHOOK: { if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { + 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; From 54192327ba7e077cc5c660e15ab601a888ac94c6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 9 Jun 2007 14:23:02 +0000 Subject: [PATCH 0480/1766] caller id works both ways w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@240 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/general.makefile | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 11 +++-- libs/freetdm/src/include/openzap.h | 16 ++++--- libs/freetdm/src/testcid.c | 14 ++++-- libs/freetdm/src/zap_analog.c | 61 +++++++++++++++++++++++--- libs/freetdm/src/zap_callerid.c | 2 +- libs/freetdm/src/zap_io.c | 33 +++++++++----- libs/freetdm/src/zap_wanpipe.c | 2 + libs/freetdm/src/zap_zt.c | 1 + 9 files changed, 110 insertions(+), 32 deletions(-) diff --git a/libs/freetdm/general.makefile b/libs/freetdm/general.makefile index b6d3777436..9a060c86c7 100644 --- a/libs/freetdm/general.makefile +++ b/libs/freetdm/general.makefile @@ -1,3 +1,3 @@ CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -std=c99 -pedantic -Wno-unused-parameter +CC_CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter #-std=c99 -pedantic -Wno-unused-parameter diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 822459a1be..21f63022d9 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -620,12 +620,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((p = strchr(outbound_profile->destination_number, '/'))) { dest = p + 1; span_id = atoi(outbound_profile->destination_number); - if ((p = strchr(dest, '/'))) { - chan_id = atoi(dest); - dest = p + 1; - } + chan_id = atoi(dest); } + dest = outbound_profile->destination_number; + if (!dest) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -643,6 +642,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } + if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -667,6 +667,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi snprintf(name, sizeof(name), "OPENZAP/%s", dest); switch_channel_set_name(channel, name); zap_set_string(zchan->caller_data.ani, dest); + zap_set_string(zchan->caller_data.cid_name, outbound_profile->caller_id_name); + zap_set_string(zchan->caller_data.cid_num, outbound_profile->caller_id_number); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -681,6 +683,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } zap_channel_outgoing_call(zchan); + return SWITCH_CAUSE_SUCCESS; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 13683aaa3b..d38cf87938 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -178,7 +178,6 @@ \command flag the or'd list of flags to set */ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) - #define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ zap_mutex_lock(obj->mutex); \ (obj)->flags |= (flag); \ @@ -193,9 +192,14 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); -#define zap_set_state_locked(obj, s) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); \ - zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ - zap_channel_set_state(obj, s); +#define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + } else { \ + int st = obj->state; \ + zap_channel_set_state(obj, s); \ + if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ + else zap_log(ZAP_LOG_WARNING, "VETO Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ + } #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -433,7 +437,7 @@ zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen); +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen); zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number); zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); @@ -452,7 +456,7 @@ zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); zap_status_t zap_span_find(uint32_t id, zap_span_t **span); zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); -zap_status_t zap_span_close_all(zap_io_interface_t *zio); +zap_status_t zap_span_close_all(void); zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index eca951d252..d374a34081 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -29,7 +29,9 @@ int main(int argc, char *argv[]) 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; @@ -41,10 +43,16 @@ int main(int argc, char *argv[]) } + 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, "06061234", 8); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, "5551212", 7); + + zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, 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, "14149361212", 7); zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); for(x = 0; x < 0; x++) zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, url, strlen(url)); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index eb4337b156..421c17b73c 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -127,16 +127,19 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.buffer = NULL; if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n"); goto done; } if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { snprintf(chan->last_error, sizeof(chan->last_error), "memory error!"); + zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); goto done; } if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); goto done; } @@ -189,7 +192,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 60000) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); - } else { + } else if (!chan->fsk_buffer || !zap_buffer_inuse(chan->fsk_buffer)) { zap_sleep(interval); continue; } @@ -218,8 +221,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 1000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + + if (state_counter > 500) { + if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + } else { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + } } } break; @@ -254,6 +262,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); } + if (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer)) { + zap_log(ZAP_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n"); + zap_buffer_zero(chan->fsk_buffer); + } + + if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); } @@ -309,6 +323,43 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_GENRING: { + 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); + localtime_r(&now, &tm); + 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(chan->caller_data.cid_num)) { + mt = MDMF_NO_NUM; + zap_set_string(chan->caller_data.cid_num, "O"); + } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { + mt = MDMF_NO_NUM; + } else { + mt = MDMF_PHONE_NUM; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, strlen(chan->caller_data.cid_num)); + + if (zap_strlen_zero(chan->caller_data.cid_name)) { + mt = MDMF_NO_NAME; + zap_set_string(chan->caller_data.cid_name, "O"); + } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { + mt = MDMF_NO_NAME; + } else { + mt = MDMF_PHONE_NAME; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, strlen(chan->caller_data.cid_name)); + + zap_fsk_data_add_checksum(&fsk_data); + zap_channel_send_fsk_data(chan, &fsk_data, -14); + //zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; @@ -374,6 +425,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "READ ERROR\n"); goto done; } @@ -412,7 +464,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_clear_detected_tones(chan); } - if (chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) { + if ((chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) || (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer))) { rlen = len; memset(frame, 0, len); zap_channel_write(chan, frame, sizeof(frame), &rlen); @@ -506,7 +558,6 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) { if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - /*zap_channel_command(event->channel, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");*/ zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); zap_thread_create_detached(zap_analog_channel_run, event->channel); } diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 8c44e11e60..25229befbe 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -61,7 +61,7 @@ zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, int8_t *data, uint32_t datalen) +zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen) { state->buf[0] = ZAP_CID_TYPE_MDMF; state->buf[state->bpos++] = type; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index cb9a38bafc..eb5b342721 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -235,7 +235,7 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) return status; } -zap_status_t zap_span_close_all(zap_io_interface_t *zio) +zap_status_t zap_span_close_all(void) { zap_span_t *span; uint32_t i, j; @@ -425,9 +425,9 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ if (!zchan->fsk_buffer) { zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, -14, 180, 5, 180, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 180, zchan_fsk_write_sample, zchan); zap_fsk_modulator_send_all((&fsk_trans)); - zchan->buffer_delay = 2000 / zchan->effective_interval; + zchan->buffer_delay = 3500 / zchan->effective_interval; return ZAP_SUCCESS; } @@ -497,8 +497,8 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) { int ok = 1; - - zap_mutex_unlock(zchan->mutex); + + zap_mutex_lock(zchan->mutex); if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { @@ -511,6 +511,17 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } } + if (zchan->state == ZAP_CHANNEL_STATE_BUSY) { + + switch(state) { + case ZAP_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + if (state == zchan->state) { ok = 0; } @@ -660,7 +671,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } - if (zap_test_flag(zchan, ZAP_CHANNEL_READY) && !zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); @@ -701,7 +712,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_mutex_unlock(check->mutex); } - done: + done: zap_mutex_unlock(globals.mutex); @@ -1526,11 +1537,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data if (zchan->native_codec != ZAP_CODEC_SLIN) { dlen *= 2; } - + len = blen > dlen ? dlen : blen; br = zap_buffer_read(buffer, auxbuf, len); - if (br < dlen) { memset(auxbuf + br, 0, dlen - br); } @@ -1548,7 +1558,6 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } } - if (zchan->fds[1]) { unsigned int dlen = (unsigned int) *datalen; write(zchan->fds[1], data, dlen); @@ -1792,14 +1801,14 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_ZT_SUPPORT + zap_span_close_all(); + if (interfaces.zt_interface) { - zap_span_close_all(interfaces.zt_interface); zt_destroy(); } #endif #ifdef ZAP_WANPIPE_SUPPORT if (interfaces.wanpipe_interface) { - zap_span_close_all(interfaces.wanpipe_interface); wanpipe_destroy(); } #endif diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index b9acfc2b0c..1ac08b40f6 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -696,6 +696,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; } @@ -705,6 +706,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; goto event; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 26ac640f79..90f310fc92 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -465,6 +465,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) case ZT_EVENT_RINGOFFHOOK: { if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { + 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; From 8f2661329eb3ead2816d73be7543e775cb9250ee Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 9 Jun 2007 16:25:39 +0000 Subject: [PATCH 0481/1766] data types. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@241 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 7 ++++--- libs/openzap/src/zap_analog.c | 9 +++++++-- libs/openzap/src/zap_callerid.c | 16 ++++++++-------- libs/openzap/src/zap_io.c | 8 ++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d38cf87938..30013ab67f 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -114,8 +114,9 @@ !strcasecmp(expr, "active") || \ atoi(expr))) ? 1 : 0 -#ifndef WIN32 + #include +#ifndef WIN32 #include #endif @@ -431,7 +432,7 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, zap_fsk_write_sample_t write_sample_callback, void *user_data); int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp); -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss); +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); @@ -475,7 +476,7 @@ zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, int ss); +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 421c17b73c..9463d4fa65 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -331,7 +331,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)); @@ -345,7 +350,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } else { mt = MDMF_PHONE_NUM; } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, strlen(chan->caller_data.cid_num)); + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); if (zap_strlen_zero(chan->caller_data.cid_name)) { mt = MDMF_NO_NAME; @@ -355,7 +360,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } else { mt = MDMF_PHONE_NAME; } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, strlen(chan->caller_data.cid_name)); + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_name)); zap_fsk_data_add_checksum(&fsk_data); zap_channel_send_fsk_data(chan, &fsk_data, -14); diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 25229befbe..3e8a790053 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -65,7 +65,7 @@ zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t { state->buf[0] = ZAP_CID_TYPE_MDMF; state->buf[state->bpos++] = type; - state->buf[state->bpos++] = datalen; + state->buf[state->bpos++] = (uint8_t)datalen; memcpy(&state->buf[state->bpos], data, datalen); state->bpos += datalen; return ZAP_SUCCESS; @@ -77,10 +77,10 @@ zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) uint32_t i; uint8_t check = 0; - state->buf[1] = state->bpos - 2; + state->buf[1] = (uint8_t)(state->bpos - 2); for (i = 0; i < state->bpos; i++) { - check += state->buf[i]; + check = check + state->buf[i]; } state->checksum = state->buf[state->bpos] = 256 - check; @@ -219,7 +219,7 @@ int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, { uint32_t i = 0; zap_size_t r = 0; - int bit = 1; + 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))) { @@ -239,7 +239,7 @@ void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) { uint32_t i = 0; zap_size_t r = 0; - int bit = 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))) { @@ -288,13 +288,13 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *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 = (fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate; + fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * 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 = ((fsk_data->dlen * 10) + carrier_bits_start + carrier_bits_stop + chan_sieze_bits) * ((fsk_trans->samples_per_bit + 1) * 2); + 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, fsk_trans->fsk_data->dlen, ZAP_ENDIAN_BIG, 1); + 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; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index eb5b342721..8721bdc82d 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1486,7 +1486,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t blen, max = datasize; + zap_size_t blen = 0, max = datasize; zap_buffer_t *buffer = NULL; assert(zchan != NULL); @@ -1871,7 +1871,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss) +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) { memset(bsp, 0, sizeof(*bsp)); bsp->data = data; @@ -1927,7 +1927,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) } } else { - bsp->bit_index += bsp->endian; + bsp->bit_index = bsp->bit_index + bsp->endian; } @@ -1936,7 +1936,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) } -void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, int ss) +void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) { zap_bitstream_t bs; int j = 0, c = 0; From 23abca3b3c056a34db123e140123f3904533343e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 9 Jun 2007 16:25:39 +0000 Subject: [PATCH 0482/1766] data types. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@241 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 7 ++++--- libs/freetdm/src/zap_analog.c | 9 +++++++-- libs/freetdm/src/zap_callerid.c | 16 ++++++++-------- libs/freetdm/src/zap_io.c | 8 ++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index d38cf87938..30013ab67f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -114,8 +114,9 @@ !strcasecmp(expr, "active") || \ atoi(expr))) ? 1 : 0 -#ifndef WIN32 + #include +#ifndef WIN32 #include #endif @@ -431,7 +432,7 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, zap_fsk_write_sample_t write_sample_callback, void *user_data); int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp); -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss); +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); @@ -475,7 +476,7 @@ zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, int ss); +void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 421c17b73c..9463d4fa65 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -331,7 +331,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)); @@ -345,7 +350,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } else { mt = MDMF_PHONE_NUM; } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, strlen(chan->caller_data.cid_num)); + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); if (zap_strlen_zero(chan->caller_data.cid_name)) { mt = MDMF_NO_NAME; @@ -355,7 +360,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } else { mt = MDMF_PHONE_NAME; } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, strlen(chan->caller_data.cid_name)); + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_name)); zap_fsk_data_add_checksum(&fsk_data); zap_channel_send_fsk_data(chan, &fsk_data, -14); diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 25229befbe..3e8a790053 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -65,7 +65,7 @@ zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t { state->buf[0] = ZAP_CID_TYPE_MDMF; state->buf[state->bpos++] = type; - state->buf[state->bpos++] = datalen; + state->buf[state->bpos++] = (uint8_t)datalen; memcpy(&state->buf[state->bpos], data, datalen); state->bpos += datalen; return ZAP_SUCCESS; @@ -77,10 +77,10 @@ zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) uint32_t i; uint8_t check = 0; - state->buf[1] = state->bpos - 2; + state->buf[1] = (uint8_t)(state->bpos - 2); for (i = 0; i < state->bpos; i++) { - check += state->buf[i]; + check = check + state->buf[i]; } state->checksum = state->buf[state->bpos] = 256 - check; @@ -219,7 +219,7 @@ int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, { uint32_t i = 0; zap_size_t r = 0; - int bit = 1; + 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))) { @@ -239,7 +239,7 @@ void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) { uint32_t i = 0; zap_size_t r = 0; - int bit = 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))) { @@ -288,13 +288,13 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *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 = (fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate; + fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * 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 = ((fsk_data->dlen * 10) + carrier_bits_start + carrier_bits_stop + chan_sieze_bits) * ((fsk_trans->samples_per_bit + 1) * 2); + 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, fsk_trans->fsk_data->dlen, ZAP_ENDIAN_BIG, 1); + 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; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index eb5b342721..8721bdc82d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1486,7 +1486,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t blen, max = datasize; + zap_size_t blen = 0, max = datasize; zap_buffer_t *buffer = NULL; assert(zchan != NULL); @@ -1871,7 +1871,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, int ss) +void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) { memset(bsp, 0, sizeof(*bsp)); bsp->data = data; @@ -1927,7 +1927,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) } } else { - bsp->bit_index += bsp->endian; + bsp->bit_index = bsp->bit_index + bsp->endian; } @@ -1936,7 +1936,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) } -void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, int ss) +void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) { zap_bitstream_t bs; int j = 0, c = 0; From 6f5e521686830696dd7460d90a3ac6d1dd5eba07 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 10 Jun 2007 05:43:50 +0000 Subject: [PATCH 0483/1766] add dest git-svn-id: http://svn.openzap.org/svn/openzap/trunk@242 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8721bdc82d..720bd9da24 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -249,6 +249,7 @@ zap_status_t zap_span_close_all(void) zap_mutex_destroy(&span->channels[j].mutex); zap_buffer_destroy(&span->channels[j].digit_buffer); zap_buffer_destroy(&span->channels[j].dtmf_buffer); + zap_buffer_destroy(&span->channels[j].fsk_buffer); } } From 6254fe5140cdab415536348bd078f135dda79ec0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 10 Jun 2007 05:43:50 +0000 Subject: [PATCH 0484/1766] add dest git-svn-id: http://svn.openzap.org/svn/openzap/trunk@242 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8721bdc82d..720bd9da24 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -249,6 +249,7 @@ zap_status_t zap_span_close_all(void) zap_mutex_destroy(&span->channels[j].mutex); zap_buffer_destroy(&span->channels[j].digit_buffer); zap_buffer_destroy(&span->channels[j].dtmf_buffer); + zap_buffer_destroy(&span->channels[j].fsk_buffer); } } From 17616625242f960440b0a404495338628ebbfac1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Jun 2007 18:15:09 +0000 Subject: [PATCH 0485/1766] add call waiting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@243 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 117 ++++++++++++------- libs/openzap/src/include/openzap.h | 4 +- libs/openzap/src/include/zap_types.h | 8 +- libs/openzap/src/zap_analog.c | 148 +++++++++++++++++-------- libs/openzap/src/zap_io.c | 93 +++++++++------- 5 files changed, 243 insertions(+), 127 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 21f63022d9..070ea50e5d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -86,7 +86,6 @@ struct private_object { switch_mutex_t *mutex; switch_mutex_t *flag_mutex; zap_channel_t *zchan; - int32_t token_id; uint32_t wr_error; }; @@ -106,6 +105,54 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); +static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) +{ + switch_core_session_t *session = NULL; + + if (id > ZAP_MAX_TOKENS) { + return NULL; + } + + if (!switch_strlen_zero(channel->tokens[id])) { + session = switch_core_session_locate(channel->tokens[id]); + } + + return session; +} + + +static void cycle_foreground(zap_channel_t *zchan, int flash) { + uint32_t i = 0; + switch_core_session_t *session; + switch_channel_t *channel; + private_t *tech_pvt; + + for (i = 0; i < zchan->token_count; i++) { + if ((session = zap_channel_get_session(zchan, i))) { + tech_pvt = switch_core_session_get_private(session); + channel = switch_core_session_get_channel(session); + if (zchan->token_count == 1 && flash) { + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } + } else if (i) { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + if (!switch_channel_test_flag(channel, CF_ANSWERED)) { + switch_channel_mark_answered(channel); + } + } + switch_core_session_rwunlock(session); + } + } +} + + + + static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) { char *dname = NULL; @@ -247,7 +294,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_channel_clear_token(tech_pvt->zchan, tech_pvt->token_id); + + zap_channel_clear_token(tech_pvt->zchan, switch_core_session_get_uuid(session)); switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: @@ -260,7 +308,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_FXS: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + if (tech_pvt->zchan->token_count) { + cycle_foreground(tech_pvt->zchan, 0); + } else { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } } } break; @@ -639,15 +691,15 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi status = zap_channel_open(span_id, chan_id, &zchan); } else { status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); - } - - + if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + + if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; @@ -676,13 +728,27 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); - if ((tech_pvt->token_id = zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session))) < 0) { + if (zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session), zchan->token_count) != ZAP_SUCCESS) { switch_core_session_destroy(new_session); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; goto fail; } - zap_channel_outgoing_call(zchan); + + if (zap_channel_outgoing_call(zchan) != ZAP_SUCCESS) { + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + switch_core_session_destroy(new_session); + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; + + } + return SWITCH_CAUSE_SUCCESS; } @@ -758,7 +824,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_FAIL; } - if ((tech_pvt->token_id = zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session))) < 0) { + if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS) { switch_core_session_destroy(&session); return ZAP_FAIL; } @@ -767,20 +833,6 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_SUCCESS; } -static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) -{ - switch_core_session_t *session = NULL; - - if (id > ZAP_MAX_TOKENS) { - return NULL; - } - - if (!switch_strlen_zero(channel->tokens[id])) { - session = switch_core_session_locate(channel->tokens[id]); - } - - return session; -} static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { @@ -853,24 +905,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_FLASH: { - uint32_t i = 0; - for (i = 0; i < sigmsg->channel->token_count; i++) { - if ((session = zap_channel_get_session(sigmsg->channel, i))) { - tech_pvt = switch_core_session_get_private(session); - if (sigmsg->channel->token_count == 1) { - if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { - switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); - } else { - switch_set_flag_locked(tech_pvt, TFLAG_HOLD); - } - } else if (i) { - switch_set_flag_locked(tech_pvt, TFLAG_HOLD); - } else { - switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); - } - switch_core_session_rwunlock(session); - } - } + cycle_foreground(sigmsg->channel, 1); } break; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 30013ab67f..774f3bcd4f 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -446,8 +446,8 @@ void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); void zap_channel_clear_needed_tones(zap_channel_t *zchan); zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 2ae6e7b05d..c6ae837986 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -97,9 +97,12 @@ typedef enum { 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", "INVALID" +#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 { @@ -254,10 +257,11 @@ typedef enum { ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, + ZAP_CHANNEL_STATE_CALLWAITING, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "INVALID" + "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 9463d4fa65..7bca77d10a 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -46,13 +46,16 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) zap_thread_create_detached(zap_analog_channel_run, zchan); return ZAP_SUCCESS; } + return ZAP_FAIL; } static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) { - if (!zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + 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); } @@ -106,6 +109,51 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map return 0; } +static void send_caller_id(zap_channel_t *chan) +{ + 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(chan->caller_data.cid_num)) { + mt = MDMF_NO_NUM; + zap_set_string(chan->caller_data.cid_num, "O"); + } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { + mt = MDMF_NO_NUM; + } else { + mt = MDMF_PHONE_NUM; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); + + if (zap_strlen_zero(chan->caller_data.cid_name)) { + mt = MDMF_NO_NAME; + zap_set_string(chan->caller_data.cid_name, "O"); + } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { + mt = MDMF_NO_NAME; + } else { + mt = MDMF_PHONE_NAME; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_name)); + + zap_fsk_data_add_checksum(&fsk_data); + zap_channel_send_fsk_data(chan, &fsk_data, -14); +} + static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_t *chan = (zap_channel_t *) obj; @@ -231,6 +279,37 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } break; + case ZAP_CHANNEL_STATE_CALLWAITING: + { + int done = 0; + + if (chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) { + send_caller_id(chan); + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; + } else if (state_counter > 600 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { + send_caller_id(chan); + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; + } else if (state_counter > 1000 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { + done = 1; + } else if (state_counter > 10000) { + if (chan->fsk_buffer) { + zap_buffer_zero(chan->fsk_buffer); + } else { + zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + } + + ts.user_data = chan->fsk_buffer; + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); + ts.user_data = dt_buffer; + done = 1; + } + + if (done) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + } + } case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { @@ -267,7 +346,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_zero(chan->fsk_buffer); } - if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); } @@ -321,49 +399,24 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; + case ZAP_CHANNEL_STATE_CALLWAITING: + { + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + if (chan->fsk_buffer) { + zap_buffer_zero(chan->fsk_buffer); + } else { + zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + } + + ts.user_data = chan->fsk_buffer; + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]); + ts.user_data = dt_buffer; + } + break; case ZAP_CHANNEL_STATE_GENRING: { - 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(chan->caller_data.cid_num)) { - mt = MDMF_NO_NUM; - zap_set_string(chan->caller_data.cid_num, "O"); - } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { - mt = MDMF_NO_NUM; - } else { - mt = MDMF_PHONE_NUM; - } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); - - if (zap_strlen_zero(chan->caller_data.cid_name)) { - mt = MDMF_NO_NAME; - zap_set_string(chan->caller_data.cid_name, "O"); - } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { - mt = MDMF_NO_NAME; - } else { - mt = MDMF_PHONE_NAME; - } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_name)); - - zap_fsk_data_add_checksum(&fsk_data); - zap_channel_send_fsk_data(chan, &fsk_data, -14); + send_caller_id(chan); //zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } @@ -575,13 +628,18 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) 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); + event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + } - sig.event_id = ZAP_SIGEVENT_FLASH; zap_channel_rotate_tokens(event->channel); - + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { + sig.event_id = ZAP_SIGEVENT_FLASH; data->sig_cb(&sig); if (event->channel->token_count == 1) { zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 720bd9da24..009fafef40 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -426,9 +426,14 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ if (!zchan->fsk_buffer) { zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 180, zchan_fsk_write_sample, zchan); - zap_fsk_modulator_send_all((&fsk_trans)); - zchan->buffer_delay = 3500 / zchan->effective_interval; + if (zchan->token_count > 1) { + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 80, 5, 0, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_send_all((&fsk_trans)); + } else { + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 300, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_send_all((&fsk_trans)); + zchan->buffer_delay = 3500 / zchan->effective_interval; + } return ZAP_SUCCESS; } @@ -441,15 +446,15 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token) { zap_status_t status = ZAP_FAIL; zap_mutex_lock(zchan->mutex); - if (token_id == -1) { + if (token == NULL) { memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; - } else if (*zchan->tokens[token_id] != '\0') { + } else if (*token != '\0') { char tokens[ZAP_MAX_TOKENS][ZAP_TOKEN_STRLEN]; int32_t i, count = zchan->token_count; memcpy(tokens, zchan->tokens, sizeof(tokens)); @@ -457,7 +462,7 @@ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) zchan->token_count = 0; for (i = 0; i < count; i++) { - if (i != token_id) { + if (strcmp(tokens[i], token)) { zap_copy_string(zchan->tokens[zchan->token_count], tokens[i], sizeof(zchan->tokens[zchan->token_count])); zchan->token_count++; } @@ -479,15 +484,20 @@ void zap_channel_rotate_tokens(zap_channel_t *zchan) } } -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) { zap_status_t status = ZAP_FAIL; zap_mutex_lock(zchan->mutex); if (zchan->token_count < ZAP_MAX_TOKENS) { - memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); - zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); - zchan->token_count++; + if (end) { + zap_copy_string(zchan->tokens[zchan->token_count++], token, ZAP_TOKEN_STRLEN); + } else { + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); + zchan->token_count++; + } + status = ZAP_SUCCESS; } zap_mutex_unlock(zchan->mutex); @@ -672,6 +682,9 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } + + status = ZAP_FAIL; + if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { @@ -698,7 +711,10 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t goto done; } - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + status = ZAP_FAIL; + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || + (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->open(check); if (status == ZAP_SUCCESS) { @@ -714,7 +730,6 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t } done: - zap_mutex_unlock(globals.mutex); return status; @@ -824,7 +839,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { zap_status_t status = ZAP_FAIL; - + assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1453,29 +1468,33 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if(*digit_str) { zio_event_cb_t event_callback = NULL; - zap_channel_queue_dtmf(zchan, digit_str); + if (zchan->state == ZAP_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) { + zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; + } else { + zap_channel_queue_dtmf(zchan, digit_str); - if (zchan->span->event_callback) { - event_callback = zchan->span->event_callback; - } else if (zchan->event_callback) { - event_callback = zchan->event_callback; - } + if (zchan->span->event_callback) { + event_callback = zchan->span->event_callback; + } else if (zchan->event_callback) { + event_callback = zchan->event_callback; + } - if (event_callback) { - zchan->event_header.channel = zchan; - zchan->event_header.e_type = ZAP_EVENT_DTMF; - zchan->event_header.data = digit_str; - event_callback(zchan, &zchan->event_header); - zchan->event_header.e_type = ZAP_EVENT_NONE; - zchan->event_header.data = NULL; + if (event_callback) { + zchan->event_header.channel = zchan; + zchan->event_header.e_type = ZAP_EVENT_DTMF; + zchan->event_header.data = digit_str; + event_callback(zchan, &zchan->event_header); + zchan->event_header.e_type = ZAP_EVENT_NONE; + zchan->event_header.data = NULL; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { + zchan->skip_read_frames = 20; + } + if (zchan->skip_read_frames > 0) { + memset(data, 0, *datalen); + zchan->skip_read_frames--; + } } - if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { - zchan->skip_read_frames = 20; - } - if (zchan->skip_read_frames > 0) { - memset(data, 0, *datalen); - zchan->skip_read_frames--; - } } } } @@ -1523,10 +1542,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { - if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { - buffer = zchan->fsk_buffer; - } else if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { buffer = zchan->dtmf_buffer; + } else if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { + buffer = zchan->fsk_buffer; } } From 9fd25b3bce1caed3fd5e02b1d40046b1128c5352 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Jun 2007 18:15:09 +0000 Subject: [PATCH 0486/1766] add call waiting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@243 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 117 ++++++++++++------- libs/freetdm/src/include/openzap.h | 4 +- libs/freetdm/src/include/zap_types.h | 8 +- libs/freetdm/src/zap_analog.c | 148 +++++++++++++++++-------- libs/freetdm/src/zap_io.c | 93 +++++++++------- 5 files changed, 243 insertions(+), 127 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 21f63022d9..070ea50e5d 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -86,7 +86,6 @@ struct private_object { switch_mutex_t *mutex; switch_mutex_t *flag_mutex; zap_channel_t *zchan; - int32_t token_id; uint32_t wr_error; }; @@ -106,6 +105,54 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); +static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) +{ + switch_core_session_t *session = NULL; + + if (id > ZAP_MAX_TOKENS) { + return NULL; + } + + if (!switch_strlen_zero(channel->tokens[id])) { + session = switch_core_session_locate(channel->tokens[id]); + } + + return session; +} + + +static void cycle_foreground(zap_channel_t *zchan, int flash) { + uint32_t i = 0; + switch_core_session_t *session; + switch_channel_t *channel; + private_t *tech_pvt; + + for (i = 0; i < zchan->token_count; i++) { + if ((session = zap_channel_get_session(zchan, i))) { + tech_pvt = switch_core_session_get_private(session); + channel = switch_core_session_get_channel(session); + if (zchan->token_count == 1 && flash) { + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } + } else if (i) { + switch_set_flag_locked(tech_pvt, TFLAG_HOLD); + } else { + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + if (!switch_channel_test_flag(channel, CF_ANSWERED)) { + switch_channel_mark_answered(channel); + } + } + switch_core_session_rwunlock(session); + } + } +} + + + + static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) { char *dname = NULL; @@ -247,7 +294,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_channel_clear_token(tech_pvt->zchan, tech_pvt->token_id); + + zap_channel_clear_token(tech_pvt->zchan, switch_core_session_get_uuid(session)); switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: @@ -260,7 +308,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_FXS: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + if (tech_pvt->zchan->token_count) { + cycle_foreground(tech_pvt->zchan, 0); + } else { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } } } break; @@ -639,15 +691,15 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi status = zap_channel_open(span_id, chan_id, &zchan); } else { status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); - } - - + if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + + if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; @@ -676,13 +728,27 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); - if ((tech_pvt->token_id = zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session))) < 0) { + if (zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session), zchan->token_count) != ZAP_SUCCESS) { switch_core_session_destroy(new_session); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; goto fail; } - zap_channel_outgoing_call(zchan); + + if (zap_channel_outgoing_call(zchan) != ZAP_SUCCESS) { + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + switch_core_session_destroy(new_session); + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; + + } + return SWITCH_CAUSE_SUCCESS; } @@ -758,7 +824,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_FAIL; } - if ((tech_pvt->token_id = zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session))) < 0) { + if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS) { switch_core_session_destroy(&session); return ZAP_FAIL; } @@ -767,20 +833,6 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_SUCCESS; } -static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) -{ - switch_core_session_t *session = NULL; - - if (id > ZAP_MAX_TOKENS) { - return NULL; - } - - if (!switch_strlen_zero(channel->tokens[id])) { - session = switch_core_session_locate(channel->tokens[id]); - } - - return session; -} static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { @@ -853,24 +905,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_FLASH: { - uint32_t i = 0; - for (i = 0; i < sigmsg->channel->token_count; i++) { - if ((session = zap_channel_get_session(sigmsg->channel, i))) { - tech_pvt = switch_core_session_get_private(session); - if (sigmsg->channel->token_count == 1) { - if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { - switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); - } else { - switch_set_flag_locked(tech_pvt, TFLAG_HOLD); - } - } else if (i) { - switch_set_flag_locked(tech_pvt, TFLAG_HOLD); - } else { - switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); - } - switch_core_session_rwunlock(session); - } - } + cycle_foreground(sigmsg->channel, 1); } break; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 30013ab67f..774f3bcd4f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -446,8 +446,8 @@ void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); void zap_channel_clear_needed_tones(zap_channel_t *zchan); zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id); -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token); +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 2ae6e7b05d..c6ae837986 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -97,9 +97,12 @@ typedef enum { 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", "INVALID" +#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 { @@ -254,10 +257,11 @@ typedef enum { ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, + ZAP_CHANNEL_STATE_CALLWAITING, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "INVALID" + "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 9463d4fa65..7bca77d10a 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -46,13 +46,16 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) zap_thread_create_detached(zap_analog_channel_run, zchan); return ZAP_SUCCESS; } + return ZAP_FAIL; } static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) { - if (!zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + 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); } @@ -106,6 +109,51 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map return 0; } +static void send_caller_id(zap_channel_t *chan) +{ + 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(chan->caller_data.cid_num)) { + mt = MDMF_NO_NUM; + zap_set_string(chan->caller_data.cid_num, "O"); + } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { + mt = MDMF_NO_NUM; + } else { + mt = MDMF_PHONE_NUM; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); + + if (zap_strlen_zero(chan->caller_data.cid_name)) { + mt = MDMF_NO_NAME; + zap_set_string(chan->caller_data.cid_name, "O"); + } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { + mt = MDMF_NO_NAME; + } else { + mt = MDMF_PHONE_NAME; + } + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_name)); + + zap_fsk_data_add_checksum(&fsk_data); + zap_channel_send_fsk_data(chan, &fsk_data, -14); +} + static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_t *chan = (zap_channel_t *) obj; @@ -231,6 +279,37 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } break; + case ZAP_CHANNEL_STATE_CALLWAITING: + { + int done = 0; + + if (chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) { + send_caller_id(chan); + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; + } else if (state_counter > 600 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { + send_caller_id(chan); + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; + } else if (state_counter > 1000 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { + done = 1; + } else if (state_counter > 10000) { + if (chan->fsk_buffer) { + zap_buffer_zero(chan->fsk_buffer); + } else { + zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + } + + ts.user_data = chan->fsk_buffer; + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); + ts.user_data = dt_buffer; + done = 1; + } + + if (done) { + zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + } + } case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_IDLE: { @@ -267,7 +346,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_zero(chan->fsk_buffer); } - if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); } @@ -321,49 +399,24 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) indicate = 1; } break; + case ZAP_CHANNEL_STATE_CALLWAITING: + { + chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + if (chan->fsk_buffer) { + zap_buffer_zero(chan->fsk_buffer); + } else { + zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + } + + ts.user_data = chan->fsk_buffer; + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); + teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]); + ts.user_data = dt_buffer; + } + break; case ZAP_CHANNEL_STATE_GENRING: { - 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(chan->caller_data.cid_num)) { - mt = MDMF_NO_NUM; - zap_set_string(chan->caller_data.cid_num, "O"); - } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { - mt = MDMF_NO_NUM; - } else { - mt = MDMF_PHONE_NUM; - } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); - - if (zap_strlen_zero(chan->caller_data.cid_name)) { - mt = MDMF_NO_NAME; - zap_set_string(chan->caller_data.cid_name, "O"); - } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { - mt = MDMF_NO_NAME; - } else { - mt = MDMF_PHONE_NAME; - } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_name)); - - zap_fsk_data_add_checksum(&fsk_data); - zap_channel_send_fsk_data(chan, &fsk_data, -14); + send_caller_id(chan); //zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } @@ -575,13 +628,18 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) 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); + event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + } - sig.event_id = ZAP_SIGEVENT_FLASH; zap_channel_rotate_tokens(event->channel); - + if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { + sig.event_id = ZAP_SIGEVENT_FLASH; data->sig_cb(&sig); if (event->channel->token_count == 1) { zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 720bd9da24..009fafef40 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -426,9 +426,14 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ if (!zchan->fsk_buffer) { zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 180, zchan_fsk_write_sample, zchan); - zap_fsk_modulator_send_all((&fsk_trans)); - zchan->buffer_delay = 3500 / zchan->effective_interval; + if (zchan->token_count > 1) { + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 80, 5, 0, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_send_all((&fsk_trans)); + } else { + zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 300, zchan_fsk_write_sample, zchan); + zap_fsk_modulator_send_all((&fsk_trans)); + zchan->buffer_delay = 3500 / zchan->effective_interval; + } return ZAP_SUCCESS; } @@ -441,15 +446,15 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) +zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token) { zap_status_t status = ZAP_FAIL; zap_mutex_lock(zchan->mutex); - if (token_id == -1) { + if (token == NULL) { memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; - } else if (*zchan->tokens[token_id] != '\0') { + } else if (*token != '\0') { char tokens[ZAP_MAX_TOKENS][ZAP_TOKEN_STRLEN]; int32_t i, count = zchan->token_count; memcpy(tokens, zchan->tokens, sizeof(tokens)); @@ -457,7 +462,7 @@ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, int32_t token_id) zchan->token_count = 0; for (i = 0; i < count; i++) { - if (i != token_id) { + if (strcmp(tokens[i], token)) { zap_copy_string(zchan->tokens[zchan->token_count], tokens[i], sizeof(zchan->tokens[zchan->token_count])); zchan->token_count++; } @@ -479,15 +484,20 @@ void zap_channel_rotate_tokens(zap_channel_t *zchan) } } -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token) +zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) { zap_status_t status = ZAP_FAIL; zap_mutex_lock(zchan->mutex); if (zchan->token_count < ZAP_MAX_TOKENS) { - memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); - zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); - zchan->token_count++; + if (end) { + zap_copy_string(zchan->tokens[zchan->token_count++], token, ZAP_TOKEN_STRLEN); + } else { + memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); + zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); + zchan->token_count++; + } + status = ZAP_SUCCESS; } zap_mutex_unlock(zchan->mutex); @@ -672,6 +682,9 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } + + status = ZAP_FAIL; + if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { @@ -698,7 +711,10 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t goto done; } - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + status = ZAP_FAIL; + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || + (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->open(check); if (status == ZAP_SUCCESS) { @@ -714,7 +730,6 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t } done: - zap_mutex_unlock(globals.mutex); return status; @@ -824,7 +839,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { zap_status_t status = ZAP_FAIL; - + assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1453,29 +1468,33 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if(*digit_str) { zio_event_cb_t event_callback = NULL; - zap_channel_queue_dtmf(zchan, digit_str); + if (zchan->state == ZAP_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) { + zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; + } else { + zap_channel_queue_dtmf(zchan, digit_str); - if (zchan->span->event_callback) { - event_callback = zchan->span->event_callback; - } else if (zchan->event_callback) { - event_callback = zchan->event_callback; - } + if (zchan->span->event_callback) { + event_callback = zchan->span->event_callback; + } else if (zchan->event_callback) { + event_callback = zchan->event_callback; + } - if (event_callback) { - zchan->event_header.channel = zchan; - zchan->event_header.e_type = ZAP_EVENT_DTMF; - zchan->event_header.data = digit_str; - event_callback(zchan, &zchan->event_header); - zchan->event_header.e_type = ZAP_EVENT_NONE; - zchan->event_header.data = NULL; + if (event_callback) { + zchan->event_header.channel = zchan; + zchan->event_header.e_type = ZAP_EVENT_DTMF; + zchan->event_header.data = digit_str; + event_callback(zchan, &zchan->event_header); + zchan->event_header.e_type = ZAP_EVENT_NONE; + zchan->event_header.data = NULL; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { + zchan->skip_read_frames = 20; + } + if (zchan->skip_read_frames > 0) { + memset(data, 0, *datalen); + zchan->skip_read_frames--; + } } - if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { - zchan->skip_read_frames = 20; - } - if (zchan->skip_read_frames > 0) { - memset(data, 0, *datalen); - zchan->skip_read_frames--; - } } } } @@ -1523,10 +1542,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { - if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { - buffer = zchan->fsk_buffer; - } else if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { + if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { buffer = zchan->dtmf_buffer; + } else if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { + buffer = zchan->fsk_buffer; } } From 7c3fc6ee7e1ed214e4eb84b282cf5b0d62ad0b08 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Jun 2007 21:07:36 +0000 Subject: [PATCH 0487/1766] add config git-svn-id: http://svn.openzap.org/svn/openzap/trunk@244 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/tones.conf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index d0f27acd93..8046578c68 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -11,8 +11,15 @@ detect-busy => 480,620 generate-attn => v=0;%(100,100,1400,2060,2450,2600) detect-attn => 1400,2060,2450,2600 +generate-callwaiting-sas => v=0;%(300,0,440) +detect-callwaiting-sas => 440 + +generate-callwaiting-cas => v=0;%(80,0,2750,2130) +detect-callwaiting-cas => 2750,2130 + detect-fail1 => 913.8 detect-fail2 => 1370.6 detect-fail3 => 776.7 + From 84da547692487e9a513081ca15e97d197831be16 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Jun 2007 21:07:36 +0000 Subject: [PATCH 0488/1766] add config git-svn-id: http://svn.openzap.org/svn/openzap/trunk@244 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/tones.conf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index d0f27acd93..8046578c68 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -11,8 +11,15 @@ detect-busy => 480,620 generate-attn => v=0;%(100,100,1400,2060,2450,2600) detect-attn => 1400,2060,2450,2600 +generate-callwaiting-sas => v=0;%(300,0,440) +detect-callwaiting-sas => 440 + +generate-callwaiting-cas => v=0;%(80,0,2750,2130) +detect-callwaiting-cas => 2750,2130 + detect-fail1 => 913.8 detect-fail2 => 1370.6 detect-fail3 => 776.7 + From 505539d65cf0dc2cea61cd0fec4158f3fb9601fc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 11 Jun 2007 22:11:58 +0000 Subject: [PATCH 0489/1766] add enum helpers git-svn-id: http://svn.openzap.org/svn/openzap/trunk@245 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 3 +++ libs/openzap/src/isdn/include/Q931.h | 37 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 7930fa53db..641f34a7ce 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -556,3 +556,6 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) return RetCode; } + +Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS) +Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 10a2e6e5dd..b230c96e35 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -114,7 +114,42 @@ #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 char * _NAME [] = { _STRINGS , NULL }; +#define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#define Q931_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ + _TYPE _FUNC1 (char *name) \ + { \ + int i; \ + _TYPE t = _MAX ; \ + \ + for (i = 0; i < _MAX ; i++) { \ + if (!strcasecmp(name, _STRINGS[i])) { \ + t = (_TYPE) i; \ + break; \ + } \ + } \ + \ + return t; \ + } \ + char * _FUNC2 (_TYPE type) \ + { \ + if (type > _MAX) { \ + type = _MAX; \ + } \ + return _STRINGS[(int)type]; \ + } \ /***************************************************************************** @@ -454,6 +489,8 @@ typedef enum /* Dialect enum */ Q931_Dialect_Count } Q931Dialect_t; +#define DIALECT_STRINGS "q931", "", "national" +Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t) typedef enum /* Trunk Line Type. */ { From c0d9b613bd9b4d988c5a7effd40e71f554212f38 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 11 Jun 2007 22:11:58 +0000 Subject: [PATCH 0490/1766] add enum helpers git-svn-id: http://svn.openzap.org/svn/openzap/trunk@245 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 3 +++ libs/freetdm/src/isdn/include/Q931.h | 37 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 7930fa53db..641f34a7ce 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -556,3 +556,6 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) return RetCode; } + +Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS) +Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 10a2e6e5dd..b230c96e35 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -114,7 +114,42 @@ #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 char * _NAME [] = { _STRINGS , NULL }; +#define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#define Q931_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ + _TYPE _FUNC1 (char *name) \ + { \ + int i; \ + _TYPE t = _MAX ; \ + \ + for (i = 0; i < _MAX ; i++) { \ + if (!strcasecmp(name, _STRINGS[i])) { \ + t = (_TYPE) i; \ + break; \ + } \ + } \ + \ + return t; \ + } \ + char * _FUNC2 (_TYPE type) \ + { \ + if (type > _MAX) { \ + type = _MAX; \ + } \ + return _STRINGS[(int)type]; \ + } \ /***************************************************************************** @@ -454,6 +489,8 @@ typedef enum /* Dialect enum */ Q931_Dialect_Count } Q931Dialect_t; +#define DIALECT_STRINGS "q931", "", "national" +Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t) typedef enum /* Trunk Line Type. */ { From 02186c731d09878a314173940c12959f6b563aa5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 12 Jun 2007 01:38:45 +0000 Subject: [PATCH 0491/1766] add auto acks. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@246 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 10 +++++- libs/openzap/src/isdn/Q931api.c | 49 +++++++++++++++------------- libs/openzap/src/isdn/include/Q931.h | 2 ++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 6d92423ec7..2b81d2dcf7 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -298,6 +298,10 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); + if (pTrunk->autoConnectAck) { + Q931AckConnect(pTrunk, buf); + } + } return ret; } @@ -419,8 +423,12 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* Send setup indication to user */ ret = Q931Tx34(pTrunk,(L3UCHAR*)pMes,pMes->Size); - if(ret != Q931E_NO_ERROR) + 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 */ diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 641f34a7ce..e13d4791d7 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -214,33 +214,12 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) return crv++; } -L3INT Q931InitMesSetup(Q931mes_Generic *pMes) +L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) { + memset(pMes, 0, sizeof(*pMes)); pMes->ProtDisc = 0x80; - pMes->CRV = 0; /* CRV to be allocated, might be receive*/ - pMes->MesType = Q931mes_SETUP; - pMes->Size = Q931GetMesSize(pMes); - pMes->SendComplete =0; /* Sending Complete */ - pMes->RepeatInd =0; /* Repeat Indicator */ - pMes->BearerCap =0; /* Bearer Capability */ - pMes->ChanID =0; /* Channel ID */ - pMes->ProgInd =0; /* Progress Indicator */ - pMes->NetFac =0; /* Network-specific facilities */ - pMes->Display =0; /* Display */ - pMes->DateTime =0; /* Date/Time */ - pMes->KeypadFac =0; /* Keypad Facility */ - pMes->Signal =0; /* Signal */ - pMes->CallingNum =0; /* Calling party number */ - pMes->CallingSub =0; /* Calling party sub address */ - pMes->CalledNum =0; /* Called party number */ - pMes->CalledSub =0; /* Called party sub address */ - pMes->TransNetSel =0; /* Transit network selection */ - pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ - pMes->LLComp =0; /* Low layer compatibility */ - pMes->HLComp =0; /* High layer compatibility */ - return 0; } @@ -557,5 +536,29 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) 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; +} + Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS) Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index b230c96e35..b0bb3f4275 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -938,6 +938,8 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo); 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 Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, From 6d857dc80814feb3ffde439894d8f812e0c93910 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 12 Jun 2007 01:38:45 +0000 Subject: [PATCH 0492/1766] add auto acks. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@246 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 10 +++++- libs/freetdm/src/isdn/Q931api.c | 49 +++++++++++++++------------- libs/freetdm/src/isdn/include/Q931.h | 2 ++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 6d92423ec7..2b81d2dcf7 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -298,6 +298,10 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); + if (pTrunk->autoConnectAck) { + Q931AckConnect(pTrunk, buf); + } + } return ret; } @@ -419,8 +423,12 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* Send setup indication to user */ ret = Q931Tx34(pTrunk,(L3UCHAR*)pMes,pMes->Size); - if(ret != Q931E_NO_ERROR) + 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 */ diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 641f34a7ce..e13d4791d7 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -214,33 +214,12 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) return crv++; } -L3INT Q931InitMesSetup(Q931mes_Generic *pMes) +L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) { + memset(pMes, 0, sizeof(*pMes)); pMes->ProtDisc = 0x80; - pMes->CRV = 0; /* CRV to be allocated, might be receive*/ - pMes->MesType = Q931mes_SETUP; - pMes->Size = Q931GetMesSize(pMes); - pMes->SendComplete =0; /* Sending Complete */ - pMes->RepeatInd =0; /* Repeat Indicator */ - pMes->BearerCap =0; /* Bearer Capability */ - pMes->ChanID =0; /* Channel ID */ - pMes->ProgInd =0; /* Progress Indicator */ - pMes->NetFac =0; /* Network-specific facilities */ - pMes->Display =0; /* Display */ - pMes->DateTime =0; /* Date/Time */ - pMes->KeypadFac =0; /* Keypad Facility */ - pMes->Signal =0; /* Signal */ - pMes->CallingNum =0; /* Calling party number */ - pMes->CallingSub =0; /* Calling party sub address */ - pMes->CalledNum =0; /* Called party number */ - pMes->CalledSub =0; /* Called party sub address */ - pMes->TransNetSel =0; /* Transit network selection */ - pMes->LLRepeatInd =0; /* Repeat Indicator 2 LLComp */ - pMes->LLComp =0; /* Low layer compatibility */ - pMes->HLComp =0; /* High layer compatibility */ - return 0; } @@ -557,5 +536,29 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) 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; +} + Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS) Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index b230c96e35..b0bb3f4275 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -938,6 +938,8 @@ L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE); L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause); L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo); 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 Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, From 63cdfc06e5e24253eba1cf3ecb8df8d9fd8e1068 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 00:01:40 +0000 Subject: [PATCH 0493/1766] off by one. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@247 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 85 +++++++++++++++++----------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 5c3ea473fc..1258144139 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1029,6 +1029,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I /* Octet 4 */ pie->Value = IBuf[Octet+Off] & 0x7f; + Octet++; Q931IESizeTest(Q931E_CAUSE); @@ -2976,27 +2977,27 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L 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; +/***************************************************************************** + + 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; @@ -3055,24 +3056,24 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U 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: 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; +} From 1919aa3e36a0569c72a647ba105790e7d07cd381 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 00:01:40 +0000 Subject: [PATCH 0494/1766] off by one. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@247 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 85 +++++++++++++++++----------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 5c3ea473fc..1258144139 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1029,6 +1029,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I /* Octet 4 */ pie->Value = IBuf[Octet+Off] & 0x7f; + Octet++; Q931IESizeTest(Q931E_CAUSE); @@ -2976,27 +2977,27 @@ L3INT Q931Pie_UserUser(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L 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; +/***************************************************************************** + + 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; @@ -3055,24 +3056,24 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U 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: 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; +} From e7a9f6a7246aa16da3610ae2ffbe0cc543d784d1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 Jun 2007 01:39:29 +0000 Subject: [PATCH 0495/1766] revert previous incorrect commit git-svn-id: http://svn.openzap.org/svn/openzap/trunk@248 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 1258144139..f3041b2b0e 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1029,7 +1029,6 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I /* Octet 4 */ pie->Value = IBuf[Octet+Off] & 0x7f; - Octet++; Q931IESizeTest(Q931E_CAUSE); From 306a9476ba643b9bb5e22fbbe50e0591ec100aa5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 Jun 2007 01:39:29 +0000 Subject: [PATCH 0496/1766] revert previous incorrect commit git-svn-id: http://svn.openzap.org/svn/openzap/trunk@248 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 1258144139..f3041b2b0e 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1029,7 +1029,6 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I /* Octet 4 */ pie->Value = IBuf[Octet+Off] & 0x7f; - Octet++; Q931IESizeTest(Q931E_CAUSE); From a97e199a313604e8504e79fab2e95ca912240c6e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 01:52:19 +0000 Subject: [PATCH 0497/1766] handle the crv flag git-svn-id: http://svn.openzap.org/svn/openzap/trunk@249 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 1 + libs/openzap/src/isdn/Q931ie.c | 4 +-- libs/openzap/src/isdn/Q931mes.c | 44 ++++++++++++++-------------- libs/openzap/src/isdn/include/Q931.h | 2 ++ libs/openzap/src/isdn/nationalmes.c | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 6c0b65613c..e1606b0809 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -329,6 +329,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->ProtDisc = Mes[IOff++]; /* CRV */ + m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); /* Message Type */ diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index f3041b2b0e..ca3bb9640b 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1307,12 +1307,12 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I if(l == 1) /* One octet CRV */ { - CRV = IBuf[Octet]; + CRV = IBuf[Octet] & 0x7F; Octet++; } else if(l==2) /* two octet CRV */ { - CRV = IBuf[Octet] << 8; + CRV = (IBuf[Octet] << 8) & 0x7F; CRV = CRV + IBuf[Octet+1]; Octet += 2; } diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index bc2facd7cb..d4229fe958 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -92,7 +92,7 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -180,7 +180,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -299,7 +299,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -395,7 +395,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -460,7 +460,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -535,7 +535,7 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -610,7 +610,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -678,7 +678,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -756,7 +756,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -823,7 +823,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -890,7 +890,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -957,7 +957,7 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1022,7 +1022,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1081,7 +1081,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1143,7 +1143,7 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I /* Q931 Message Header */ OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1258,7 +1258,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1406,7 +1406,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1481,7 +1481,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1546,7 +1546,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1603,7 +1603,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1661,7 +1661,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1719,7 +1719,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index b0bb3f4275..1243c5a114 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -390,6 +390,7 @@ 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; @@ -406,6 +407,7 @@ 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 */ ie Shift; diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 41de1531c6..7dc73989e4 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -158,7 +158,7 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ From 0b24196b4b8ba71b4aeeaf8ae225c30b6ff5f219 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 01:52:19 +0000 Subject: [PATCH 0498/1766] handle the crv flag git-svn-id: http://svn.openzap.org/svn/openzap/trunk@249 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 1 + libs/freetdm/src/isdn/Q931ie.c | 4 +-- libs/freetdm/src/isdn/Q931mes.c | 44 ++++++++++++++-------------- libs/freetdm/src/isdn/include/Q931.h | 2 ++ libs/freetdm/src/isdn/nationalmes.c | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 6c0b65613c..e1606b0809 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -329,6 +329,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->ProtDisc = Mes[IOff++]; /* CRV */ + m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); /* Message Type */ diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index f3041b2b0e..ca3bb9640b 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1307,12 +1307,12 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I if(l == 1) /* One octet CRV */ { - CRV = IBuf[Octet]; + CRV = IBuf[Octet] & 0x7F; Octet++; } else if(l==2) /* two octet CRV */ { - CRV = IBuf[Octet] << 8; + CRV = (IBuf[Octet] << 8) & 0x7F; CRV = CRV + IBuf[Octet+1]; Octet += 2; } diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index bc2facd7cb..d4229fe958 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -92,7 +92,7 @@ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -180,7 +180,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -299,7 +299,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -395,7 +395,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -460,7 +460,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -535,7 +535,7 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -610,7 +610,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -678,7 +678,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -756,7 +756,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -823,7 +823,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -890,7 +890,7 @@ L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -957,7 +957,7 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1022,7 +1022,7 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1081,7 +1081,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1143,7 +1143,7 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I /* Q931 Message Header */ OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1258,7 +1258,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1406,7 +1406,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1481,7 +1481,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1546,7 +1546,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1603,7 +1603,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1661,7 +1661,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ @@ -1719,7 +1719,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index b0bb3f4275..1243c5a114 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -390,6 +390,7 @@ 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; @@ -406,6 +407,7 @@ 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 */ ie Shift; diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 41de1531c6..7dc73989e4 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -158,7 +158,7 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ From ecdc2671126acd750c814faebcd23b200e1f5df3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 02:46:39 +0000 Subject: [PATCH 0499/1766] fix CRV parser right this time git-svn-id: http://svn.openzap.org/svn/openzap/trunk@250 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index ca3bb9640b..9e2f687206 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1312,7 +1312,7 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } else if(l==2) /* two octet CRV */ { - CRV = (IBuf[Octet] << 8) & 0x7F; + CRV = (IBuf[Octet] & 0x7f) << 8; CRV = CRV + IBuf[Octet+1]; Octet += 2; } From 8474098118016dc920980d96bc961fc97ca5745f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 02:46:39 +0000 Subject: [PATCH 0500/1766] fix CRV parser right this time git-svn-id: http://svn.openzap.org/svn/openzap/trunk@250 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index ca3bb9640b..9e2f687206 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1312,7 +1312,7 @@ L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I } else if(l==2) /* two octet CRV */ { - CRV = (IBuf[Octet] << 8) & 0x7F; + CRV = (IBuf[Octet] & 0x7f) << 8; CRV = CRV + IBuf[Octet+1]; Octet += 2; } From 18ac09fb0d48f246fc3e75bf75c36f7d0a7c5957 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 Jun 2007 03:37:55 +0000 Subject: [PATCH 0501/1766] WIP git-svn-id: http://svn.openzap.org/svn/openzap/trunk@251 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 131 ++++++++++++++++++++++++- libs/openzap/src/include/openzap.h | 3 + libs/openzap/src/priserver.c | 9 +- libs/openzap/src/sangoma_pri.c | 12 +-- libs/openzap/src/testisdn.c | 2 +- libs/openzap/src/zap_io.c | 7 +- libs/openzap/src/zap_isdn.c | 102 ++++++++++++++++++- 7 files changed, 245 insertions(+), 21 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 070ea50e5d..e4793fe807 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -316,6 +316,13 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) } } break; + case ZAP_CHAN_TYPE_B: + { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; default: { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); @@ -536,7 +543,27 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) { - return SWITCH_STATUS_FALSE; + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_ANSWER: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_receive_message_fxo(switch_core_session_t *session, switch_core_session_message_t *msg) @@ -913,7 +940,46 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_zap_signal) +static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) +{ + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + zap_status_t status; + + zap_log(ZAP_LOG_DEBUG, "got ISDN sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + { + return zap_channel_from_event(sigmsg, &session); + } + break; + case ZAP_SIGEVENT_STOP: + { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_channel_clear_token(sigmsg->channel, 0); + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; + } + + return ZAP_SUCCESS; +} + + +static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: @@ -1027,7 +1093,7 @@ static switch_status_t load_config(void) continue; } - if (zap_analog_configure_span(span, tonegroup, to, max, on_zap_signal) != ZAP_SUCCESS) { + if (zap_analog_configure_span(span, tonegroup, to, max, on_analog_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } @@ -1041,6 +1107,65 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "pri_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *context = "default"; + char *dialplan = "XML"; + Q921NetUser_t mode = Q931_TE; + Q931Dialect_t dialect = Q931_Dialect_National; + uint32_t span_id = 0; + zap_span_t *span = NULL; + char *tonegroup = NULL; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "mode")) { + mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT; + } else if (!strcasecmp(var, "dialect")) { + dialect = q931_str2Q931Diaelct_type(val); + if (dialect == Q931_Dialect_Count) { + dialect = Q931_Dialect_National; + } + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (zap_isdn_configure_span(span, mode, dialect, on_isdn_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + + zap_isdn_start(span); + } + } + switch_xml_free(xml); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 774f3bcd4f..a13ae80814 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -296,6 +296,9 @@ struct zap_caller_data { char aniII[25]; char dnis[25]; char rdnis[25]; + int CRV; + uint8_t raw_data[1024]; + uint32_t raw_data_len; }; struct zap_channel { diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c index 9126a186af..57c29146c2 100644 --- a/libs/openzap/src/priserver.c +++ b/libs/openzap/src/priserver.c @@ -88,7 +88,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) memset(inframe, 0, MAX_BYTES); memset(outframe, 0, MAX_BYTES); - if (zap_channel_open("wanpipe", spri->span, channo, &chan) != ZAP_SUCCESS) { + if (zap_channel_open(spri->span, channo, &chan) != ZAP_SUCCESS) { printf("DEBUG cant open fd!\n"); } @@ -103,7 +103,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) #endif #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + 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); @@ -167,7 +167,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) if (lead) { continue; } - zap_channel_write(chan, outframe, &len); + zap_channel_write(chan, outframe, sizeof(outframe), &len); } else { printf("BREAK"); break; @@ -289,7 +289,8 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - + debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; + if (sangoma_init_pri(&spri, 1, // span 24, // dchan diff --git a/libs/openzap/src/sangoma_pri.c b/libs/openzap/src/sangoma_pri.c index 865fe4f476..bf213699b6 100644 --- a/libs/openzap/src/sangoma_pri.c +++ b/libs/openzap/src/sangoma_pri.c @@ -105,8 +105,8 @@ static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen) memset(&((unsigned char*)buf)[res],0,2); res+=2; - print_bits(buf, res-2, bb, sizeof(bb), 1); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb); + //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; } @@ -118,13 +118,13 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen) zap_size_t len = buflen -2; char bb[4096] = ""; - if (zap_channel_write(spri->zdchan, buf, &len) != ZAP_SUCCESS) { + 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); - zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb); + //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; } @@ -136,7 +136,7 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, memset(spri, 0, sizeof(struct sangoma_pri)); - if (zap_channel_open("wanpipe", span, dchan, &spri->zdchan) != ZAP_SUCCESS) { + 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))){ diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 93af26f752..231215a4b1 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + if (zap_span_find(1, &span) != ZAP_SUCCESS) { fprintf(stderr, "Error finding OpenZAP span\n"); goto done; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 009fafef40..82d6706134 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -781,9 +781,12 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(zchan != NULL); check = *zchan; - assert(check != NULL); *zchan = NULL; + if (!check) { + return ZAP_FAIL; + } + zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); @@ -1966,7 +1969,7 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t if (blen < (bl * 10) + 2) { return; } - + zap_bitstream_init(&bs, b, bl, e, ss); last = bs.byte_index; while((bit = zap_bitstream_get_bit(&bs)) > -1) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index f9577e4798..36628a6309 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -71,6 +71,55 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) assert(data != NULL); zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); + switch(gen->MesType) { + case Q931mes_SETUP: + { + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); + Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); + int chan_id = chanid->ChanSlot; + zap_channel_t *zchan; + zap_status_t status; + zap_sigmsg_t sig; + zap_isdn_data_t *data; + int fail = 1; + uint32_t cplen = mlen; + + if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + sig.event_id = ZAP_SIGEVENT_START; + data = zchan->span->isdn_data; + + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + + zap_copy_string(zchan->caller_data.cid_num, callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.cid_name, callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.ani, callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.dnis, callednum->Digit, callednum->Size - 3); + + zchan->caller_data.CRV = gen->CRV; + if (cplen > sizeof(zchan->caller_data.raw_data)) { + cplen = sizeof(zchan->caller_data.raw_data); + } + memcpy(zchan->caller_data.raw_data, msg, cplen); + zchan->caller_data.raw_data_len = cplen; + if ((status = data->sig_cb(&sig) == ZAP_SUCCESS)) { + fail = 0; + } + } + + if (fail) { + // add me + } + + } + break; + default: + break; + } return 0; } @@ -89,7 +138,7 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) zap_size_t len = (zap_size_t) mlen; #ifdef IODEBUG char bb[4096] = ""; - print_bits(msg, (int)len, bb, sizeof(bb), 1, 0); + 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 @@ -98,12 +147,49 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } +static void state_advance(zap_channel_t *zchan) +{ + Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data; + zap_isdn_data_t *data = zchan->span->isdn_data; + + zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n", + zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); + + + switch (zchan->state) { + case ZAP_CHANNEL_STATE_UP: + { + printf("XXXXXXXXXXXXXXXX answer %d\n", zchan->caller_data.raw_data_len); + gen->MesType = Q931mes_CONNECT; + gen->BearerCap = 0; + gen->CRVFlag = 1;//!(gen->CRVFlag); + Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + } + break; + default: + break; + } +} + +static void check_state(zap_span_t *span) +{ + uint32_t j; + + for(j = 1; j <= span->chan_count; j++) { + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + state_advance(&span->channels[j]); + zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + } + } +} + static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; zap_isdn_data_t *data = span->isdn_data; unsigned char buf[1024]; zap_size_t len = sizeof(buf); + int errs = 0; #ifdef WIN32 timeBeginPeriod(1); @@ -118,29 +204,34 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); Q921TimerTick(&data->q921); - + check_state(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!"); - goto done; + if (++errs == 10) { + goto done; + } } break; case ZAP_TIMEOUT: { /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ /*Q931TimeTick(data->q931, L3ULONG ms);*/ + errs = 0; } break; default: { + errs = 0; if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG char bb[4096] = ""; - print_bits(buf, (int)len, bb, sizeof(bb), 1, 0); + print_bits(buf, (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 @@ -191,7 +282,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D zap_channel_t *dchans[2] = {0}; if (span->signal_type) { - snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; } @@ -246,6 +337,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->isdn_data->q931.autoRestartAck = 1; + span->signal_type = ZAP_SIGTYPE_ISDN; return ZAP_SUCCESS; From cb5ed64400ad34a21aa847441eb4832868c10b45 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 Jun 2007 03:37:55 +0000 Subject: [PATCH 0502/1766] WIP git-svn-id: http://svn.openzap.org/svn/openzap/trunk@251 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 131 ++++++++++++++++++++++++- libs/freetdm/src/include/openzap.h | 3 + libs/freetdm/src/priserver.c | 9 +- libs/freetdm/src/sangoma_pri.c | 12 +-- libs/freetdm/src/testisdn.c | 2 +- libs/freetdm/src/zap_io.c | 7 +- libs/freetdm/src/zap_isdn.c | 102 ++++++++++++++++++- 7 files changed, 245 insertions(+), 21 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 070ea50e5d..e4793fe807 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -316,6 +316,13 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) } } break; + case ZAP_CHAN_TYPE_B: + { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; default: { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); @@ -536,7 +543,27 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) { - return SWITCH_STATUS_FALSE; + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_ANSWER: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_receive_message_fxo(switch_core_session_t *session, switch_core_session_message_t *msg) @@ -913,7 +940,46 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_zap_signal) +static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) +{ + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + zap_status_t status; + + zap_log(ZAP_LOG_DEBUG, "got ISDN sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + + switch(sigmsg->event_id) { + case ZAP_SIGEVENT_START: + { + return zap_channel_from_event(sigmsg, &session); + } + break; + case ZAP_SIGEVENT_STOP: + { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_channel_clear_token(sigmsg->channel, 0); + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; + } + + return ZAP_SUCCESS; +} + + +static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: @@ -1027,7 +1093,7 @@ static switch_status_t load_config(void) continue; } - if (zap_analog_configure_span(span, tonegroup, to, max, on_zap_signal) != ZAP_SUCCESS) { + if (zap_analog_configure_span(span, tonegroup, to, max, on_analog_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } @@ -1041,6 +1107,65 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "pri_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *context = "default"; + char *dialplan = "XML"; + Q921NetUser_t mode = Q931_TE; + Q931Dialect_t dialect = Q931_Dialect_National; + uint32_t span_id = 0; + zap_span_t *span = NULL; + char *tonegroup = NULL; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "mode")) { + mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT; + } else if (!strcasecmp(var, "dialect")) { + dialect = q931_str2Q931Diaelct_type(val); + if (dialect == Q931_Dialect_Count) { + dialect = Q931_Dialect_National; + } + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (zap_isdn_configure_span(span, mode, dialect, on_isdn_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + + zap_isdn_start(span); + } + } + switch_xml_free(xml); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 774f3bcd4f..a13ae80814 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -296,6 +296,9 @@ struct zap_caller_data { char aniII[25]; char dnis[25]; char rdnis[25]; + int CRV; + uint8_t raw_data[1024]; + uint32_t raw_data_len; }; struct zap_channel { diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index 9126a186af..57c29146c2 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -88,7 +88,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) memset(inframe, 0, MAX_BYTES); memset(outframe, 0, MAX_BYTES); - if (zap_channel_open("wanpipe", spri->span, channo, &chan) != ZAP_SUCCESS) { + if (zap_channel_open(spri->span, channo, &chan) != ZAP_SUCCESS) { printf("DEBUG cant open fd!\n"); } @@ -103,7 +103,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) #endif #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { + 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); @@ -167,7 +167,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) if (lead) { continue; } - zap_channel_write(chan, outframe, &len); + zap_channel_write(chan, outframe, sizeof(outframe), &len); } else { printf("BREAK"); break; @@ -289,7 +289,8 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - + debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; + if (sangoma_init_pri(&spri, 1, // span 24, // dchan diff --git a/libs/freetdm/src/sangoma_pri.c b/libs/freetdm/src/sangoma_pri.c index 865fe4f476..bf213699b6 100644 --- a/libs/freetdm/src/sangoma_pri.c +++ b/libs/freetdm/src/sangoma_pri.c @@ -105,8 +105,8 @@ static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen) memset(&((unsigned char*)buf)[res],0,2); res+=2; - print_bits(buf, res-2, bb, sizeof(bb), 1); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb); + //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; } @@ -118,13 +118,13 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen) zap_size_t len = buflen -2; char bb[4096] = ""; - if (zap_channel_write(spri->zdchan, buf, &len) != ZAP_SUCCESS) { + 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); - zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb); + //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; } @@ -136,7 +136,7 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, memset(spri, 0, sizeof(struct sangoma_pri)); - if (zap_channel_open("wanpipe", span, dchan, &spri->zdchan) != ZAP_SUCCESS) { + 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))){ diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 93af26f752..231215a4b1 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_span_find("wanpipe", 1, &span) != ZAP_SUCCESS) { + if (zap_span_find(1, &span) != ZAP_SUCCESS) { fprintf(stderr, "Error finding OpenZAP span\n"); goto done; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 009fafef40..82d6706134 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -781,9 +781,12 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) assert(zchan != NULL); check = *zchan; - assert(check != NULL); *zchan = NULL; + if (!check) { + return ZAP_FAIL; + } + zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); @@ -1966,7 +1969,7 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t if (blen < (bl * 10) + 2) { return; } - + zap_bitstream_init(&bs, b, bl, e, ss); last = bs.byte_index; while((bit = zap_bitstream_get_bit(&bs)) > -1) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index f9577e4798..36628a6309 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -71,6 +71,55 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) assert(data != NULL); zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); + switch(gen->MesType) { + case Q931mes_SETUP: + { + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); + Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); + int chan_id = chanid->ChanSlot; + zap_channel_t *zchan; + zap_status_t status; + zap_sigmsg_t sig; + zap_isdn_data_t *data; + int fail = 1; + uint32_t cplen = mlen; + + if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + sig.event_id = ZAP_SIGEVENT_START; + data = zchan->span->isdn_data; + + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + + zap_copy_string(zchan->caller_data.cid_num, callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.cid_name, callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.ani, callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.dnis, callednum->Digit, callednum->Size - 3); + + zchan->caller_data.CRV = gen->CRV; + if (cplen > sizeof(zchan->caller_data.raw_data)) { + cplen = sizeof(zchan->caller_data.raw_data); + } + memcpy(zchan->caller_data.raw_data, msg, cplen); + zchan->caller_data.raw_data_len = cplen; + if ((status = data->sig_cb(&sig) == ZAP_SUCCESS)) { + fail = 0; + } + } + + if (fail) { + // add me + } + + } + break; + default: + break; + } return 0; } @@ -89,7 +138,7 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) zap_size_t len = (zap_size_t) mlen; #ifdef IODEBUG char bb[4096] = ""; - print_bits(msg, (int)len, bb, sizeof(bb), 1, 0); + 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 @@ -98,12 +147,49 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } +static void state_advance(zap_channel_t *zchan) +{ + Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data; + zap_isdn_data_t *data = zchan->span->isdn_data; + + zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n", + zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); + + + switch (zchan->state) { + case ZAP_CHANNEL_STATE_UP: + { + printf("XXXXXXXXXXXXXXXX answer %d\n", zchan->caller_data.raw_data_len); + gen->MesType = Q931mes_CONNECT; + gen->BearerCap = 0; + gen->CRVFlag = 1;//!(gen->CRVFlag); + Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + } + break; + default: + break; + } +} + +static void check_state(zap_span_t *span) +{ + uint32_t j; + + for(j = 1; j <= span->chan_count; j++) { + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + state_advance(&span->channels[j]); + zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + } + } +} + static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; zap_isdn_data_t *data = span->isdn_data; unsigned char buf[1024]; zap_size_t len = sizeof(buf); + int errs = 0; #ifdef WIN32 timeBeginPeriod(1); @@ -118,29 +204,34 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); Q921TimerTick(&data->q921); - + check_state(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!"); - goto done; + if (++errs == 10) { + goto done; + } } break; case ZAP_TIMEOUT: { /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ /*Q931TimeTick(data->q931, L3ULONG ms);*/ + errs = 0; } break; default: { + errs = 0; if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG char bb[4096] = ""; - print_bits(buf, (int)len, bb, sizeof(bb), 1, 0); + print_bits(buf, (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 @@ -191,7 +282,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D zap_channel_t *dchans[2] = {0}; if (span->signal_type) { - snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; } @@ -246,6 +337,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->isdn_data->q931.autoRestartAck = 1; + span->signal_type = ZAP_SIGTYPE_ISDN; return ZAP_SUCCESS; From 4c283d46522c0c3f8b5fbfbcd694ad7d1877749f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 03:44:09 +0000 Subject: [PATCH 0503/1766] cast to char * from unsigned char * git-svn-id: http://svn.openzap.org/svn/openzap/trunk@252 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 36628a6309..35b828c387 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -95,10 +95,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_copy_string(zchan->caller_data.cid_num, callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.cid_name, callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.ani, callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.dnis, callednum->Digit, callednum->Size - 3); + zap_copy_string(zchan->caller_data.cid_num, (char *)callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.cid_name, (char *)callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.ani, (char *)callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.dnis, (char *)callednum->Digit, callednum->Size - 3); zchan->caller_data.CRV = gen->CRV; if (cplen > sizeof(zchan->caller_data.raw_data)) { From deba84fe3b4fbfcbfd0f1b0b7fa3f454cdcdcdf1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 13 Jun 2007 03:44:09 +0000 Subject: [PATCH 0504/1766] cast to char * from unsigned char * git-svn-id: http://svn.openzap.org/svn/openzap/trunk@252 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 36628a6309..35b828c387 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -95,10 +95,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_copy_string(zchan->caller_data.cid_num, callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.cid_name, callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.ani, callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.dnis, callednum->Digit, callednum->Size - 3); + zap_copy_string(zchan->caller_data.cid_num, (char *)callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.cid_name, (char *)callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.ani, (char *)callingnum->Digit, callingnum->Size - 3); + zap_copy_string(zchan->caller_data.dnis, (char *)callednum->Digit, callednum->Size - 3); zchan->caller_data.CRV = gen->CRV; if (cplen > sizeof(zchan->caller_data.raw_data)) { From bd517afa82821329abdfb21fb17c33cca7d4fdfc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jun 2007 01:54:51 +0000 Subject: [PATCH 0505/1766] tweak the state stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@253 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 2b81d2dcf7..55ba103eb5 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -761,7 +761,12 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if(state == Q931_U0 && iFrom == 2) { ret = Q931ReleaseComplete(pTrunk, iFrom); } @@ -785,7 +790,8 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i L3INT ret = Q931E_NO_ERROR; if(state == Q931_U0 && iFrom == 2) { - /* no action */ + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); } return ret; } From d26289fc9223b8f935aa2f7a850e7aa4ca1213a1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jun 2007 01:54:51 +0000 Subject: [PATCH 0506/1766] tweak the state stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@253 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 2b81d2dcf7..55ba103eb5 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -761,7 +761,12 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if(state == Q931_U0 && iFrom == 2) { ret = Q931ReleaseComplete(pTrunk, iFrom); } @@ -785,7 +790,8 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i L3INT ret = Q931E_NO_ERROR; if(state == Q931_U0 && iFrom == 2) { - /* no action */ + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); } return ret; } From 2f4d9e8c3bb48a6e9d573f88b82462edbcace737 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Jun 2007 02:02:56 +0000 Subject: [PATCH 0507/1766] properly send release complete git-svn-id: http://svn.openzap.org/svn/openzap/trunk@254 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 17 ++++++----------- libs/openzap/src/isdn/Q931api.c | 11 +++++------ libs/openzap/src/isdn/include/Q931.h | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 55ba103eb5..9f68c970b0 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -761,17 +761,12 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if(state == Q931_U0 && iFrom == 2) - { - ret = Q931ReleaseComplete(pTrunk, iFrom); - } - else - { + if(iFrom == 4) { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } else if(state == Q931_U0 && iFrom == 2) { + ret = Q931ReleaseComplete(pTrunk, buf); + } else { ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); } diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index e13d4791d7..1ac2a56b96 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -515,13 +515,12 @@ L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCau return 0; } -L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo) +L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) { - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)iTo; + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; - return 0; + return Q931Tx32(pTrunk,buf,ptr->Size); } L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) @@ -529,7 +528,7 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) L3INT RetCode; Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; + ptr->MesType = Q931mes_RELEASE_COMPLETE; RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 1243c5a114..8c63d143f8 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -938,7 +938,7 @@ 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, L3INT iTo); +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); From 06c9547078a0afffe1a96d8eae1abd2ae25e0afd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Jun 2007 02:02:56 +0000 Subject: [PATCH 0508/1766] properly send release complete git-svn-id: http://svn.openzap.org/svn/openzap/trunk@254 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 17 ++++++----------- libs/freetdm/src/isdn/Q931api.c | 11 +++++------ libs/freetdm/src/isdn/include/Q931.h | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 55ba103eb5..9f68c970b0 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -761,17 +761,12 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if(state == Q931_U0 && iFrom == 2) - { - ret = Q931ReleaseComplete(pTrunk, iFrom); - } - else - { + if(iFrom == 4) { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } else if(state == Q931_U0 && iFrom == 2) { + ret = Q931ReleaseComplete(pTrunk, buf); + } else { ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); } diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index e13d4791d7..1ac2a56b96 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -515,13 +515,12 @@ L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCau return 0; } -L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3INT iTo) +L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) { - /* TODO: Unhandled paramaters */ - (void)pTrunk; - (void)iTo; + Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; + ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; - return 0; + return Q931Tx32(pTrunk,buf,ptr->Size); } L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) @@ -529,7 +528,7 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) L3INT RetCode; Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; + ptr->MesType = Q931mes_RELEASE_COMPLETE; RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 1243c5a114..8c63d143f8 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -938,7 +938,7 @@ 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, L3INT iTo); +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); From f981ebef9f79acf7487e788e1650a7f3d0e096c7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jun 2007 03:54:02 +0000 Subject: [PATCH 0509/1766] inbound calls milestone git-svn-id: http://svn.openzap.org/svn/openzap/trunk@255 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 9 +- libs/openzap/src/include/openzap.h | 3 +- libs/openzap/src/include/zap_types.h | 9 +- libs/openzap/src/isdn/Q931api.c | 9 +- libs/openzap/src/isdn/Q931ie.c | 23 +++-- libs/openzap/src/priserver.c | 2 +- libs/openzap/src/zap_analog.c | 3 + libs/openzap/src/zap_io.c | 44 +++++--- libs/openzap/src/zap_isdn.c | 137 ++++++++++++++++++------- 9 files changed, 164 insertions(+), 75 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index e4793fe807..639fc18f6f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -319,6 +319,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_B: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -638,7 +639,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } -static const switch_state_handler_table_t channel_event_handlers = { +static switch_state_handler_table_t channel_event_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, /*.on_execute */ channel_on_execute, @@ -647,7 +648,7 @@ static const switch_state_handler_table_t channel_event_handlers = { /*.on_transmit */ channel_on_transmit }; -static const switch_io_routines_t channel_io_routines = { +static switch_io_routines_t channel_io_routines = { /*.outgoing_channel */ channel_outgoing_channel, /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, @@ -658,7 +659,7 @@ static const switch_io_routines_t channel_io_routines = { /*.receive_message*/ channel_receive_message }; -static const switch_endpoint_interface_t channel_endpoint_interface = { +static switch_endpoint_interface_t channel_endpoint_interface = { /*.interface_name */ "openzap", /*.io_routines */ &channel_io_routines, /*.event_handlers */ &channel_event_handlers, @@ -666,7 +667,7 @@ static const switch_endpoint_interface_t channel_endpoint_interface = { /*.next */ NULL }; -static const switch_loadable_module_interface_t channel_module_interface = { +static switch_loadable_module_interface_t channel_module_interface = { /*.module_name */ modname, /*.endpoint_interface */ &channel_endpoint_interface, /*.timer_interface */ NULL, diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index a13ae80814..316b4d3af4 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -195,7 +195,7 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ - } else { \ + } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ @@ -297,6 +297,7 @@ struct zap_caller_data { char dnis[25]; char rdnis[25]; int CRV; + int hangup_cause; uint8_t raw_data[1024]; uint32_t raw_data_len; }; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index c6ae837986..b81f5338c1 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -224,7 +224,8 @@ typedef enum { typedef enum { ZAP_SPAN_CONFIGURED = (1 << 0), - ZAP_SPAN_READY = (1 << 1) + ZAP_SPAN_READY = (1 << 1), + ZAP_SPAN_STATE_CHANGE = (1 << 2) } zap_span_flag_t; typedef enum { @@ -258,10 +259,13 @@ typedef enum { ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, ZAP_CHANNEL_STATE_CALLWAITING, + ZAP_CHANNEL_STATE_TERMINATING, + ZAP_CHANNEL_STATE_RESTART, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", "INVALID" + "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ + "TERMINATING", "RESTART", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -285,7 +289,6 @@ typedef enum { ZAP_CHANNEL_CALLERID_DETECT = (1 << 17) } zap_channel_flag_t; - typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 1ac2a56b96..2e4e0063a6 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -518,8 +518,8 @@ L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCau L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) { Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; - + ptr->MesType = Q931mes_RELEASE_COMPLETE; + ptr->CRVFlag = !(ptr->CRVFlag); return Q931Tx32(pTrunk,buf,ptr->Size); } @@ -528,7 +528,10 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) L3INT RetCode; Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - ptr->MesType = Q931mes_RELEASE_COMPLETE; + ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; + if (ptr->CRV) { + ptr->CRVFlag = !(ptr->CRVFlag); + } RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 9e2f687206..0ea4251dbf 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -715,19 +715,22 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; pie->NumPlanID = IBuf[Octet+Off] & 0x0f; Octet ++; - + /* Octet 4*/ - for (x = 0; x < IESize - 1; x++) - { + 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 - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x); return Q931E_NO_ERROR; } @@ -824,15 +827,17 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); + } while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); + + pie->Digit[x] = '\0'; Q931IESizeTest(Q931E_CALLINGNUM); Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x); return Q931E_NO_ERROR; } diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c index 57c29146c2..6bb5e02965 100644 --- a/libs/openzap/src/priserver.c +++ b/libs/openzap/src/priserver.c @@ -180,7 +180,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) 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); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 7bca77d10a..0ad28c92bd 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -307,6 +307,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (done) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; } } @@ -328,6 +329,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } else { zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); indicate = 0; state_counter = 0; zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(chan->state)); @@ -631,6 +633,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) 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; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 82d6706134..8f5e0d08f6 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -511,26 +511,35 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta zap_mutex_lock(zchan->mutex); - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - - switch(state) { - case ZAP_CHANNEL_STATE_BUSY: - ok = 0; - break; - default: - break; - } + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { + return ZAP_FAIL; } - if (zchan->state == ZAP_CHANNEL_STATE_BUSY) { - - switch(state) { - case ZAP_CHANNEL_STATE_UP: - ok = 0; - break; - default: - break; + switch(zchan->state) { + case ZAP_CHANNEL_STATE_DOWN: + { + switch(state) { + case ZAP_CHANNEL_STATE_BUSY: + case ZAP_CHANNEL_STATE_HANGUP: + case ZAP_CHANNEL_STATE_TERMINATING: + ok = 0; + break; + default: + break; + } } + case ZAP_CHANNEL_STATE_BUSY: + { + switch(state) { + case ZAP_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + default: + break; } if (state == zchan->state) { @@ -539,6 +548,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (ok) { zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; zchan->state = state; } diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 35b828c387..d114be55d0 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -66,52 +66,74 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_span_t *span = (zap_span_t *) pvt; zap_isdn_data_t *data = span->isdn_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; - + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + int chan_id = chanid->ChanSlot; + zap_channel_t *zchan = NULL; + assert(span != NULL); assert(data != NULL); + + if (chan_id) { + zchan = &span->channels[chan_id]; + } - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); switch(gen->MesType) { + case Q931mes_RESTART: + { + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + } else { + uint32_t i; + for (i = 0; i < span->chan_count; i++) { + zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); + } + } + } + break; + case Q931mes_RELEASE_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + break; + case Q931mes_DISCONNECT: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } + break; case Q931mes_SETUP: { - Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); - int chan_id = chanid->ChanSlot; - zap_channel_t *zchan; zap_status_t status; - zap_sigmsg_t sig; - zap_isdn_data_t *data; int fail = 1; uint32_t cplen = mlen; + if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - sig.event_id = ZAP_SIGEVENT_START; - data = zchan->span->isdn_data; - - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_copy_string(zchan->caller_data.cid_num, (char *)callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.cid_name, (char *)callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.ani, (char *)callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.dnis, (char *)callednum->Digit, callednum->Size - 3); + zap_set_string(zchan->caller_data.cid_num, callingnum->Digit); + zap_set_string(zchan->caller_data.cid_name, callingnum->Digit); + zap_set_string(zchan->caller_data.ani, callingnum->Digit); + zap_set_string(zchan->caller_data.dnis, callednum->Digit); - zchan->caller_data.CRV = gen->CRV; - if (cplen > sizeof(zchan->caller_data.raw_data)) { - cplen = sizeof(zchan->caller_data.raw_data); - } - memcpy(zchan->caller_data.raw_data, msg, cplen); - zchan->caller_data.raw_data_len = cplen; - if ((status = data->sig_cb(&sig) == ZAP_SUCCESS)) { + 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; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; - } + } } if (fail) { + zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); // add me } @@ -147,39 +169,80 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } -static void state_advance(zap_channel_t *zchan) +static __inline__ void state_advance(zap_channel_t *zchan) { Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data; zap_isdn_data_t *data = zchan->span->isdn_data; + zap_sigmsg_t sig; + zap_status_t status; zap_log(ZAP_LOG_ERROR, "%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_RING: + { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + + } + break; + case ZAP_CHANNEL_STATE_RESTART: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_channel_close(&zchan); + } + break; case ZAP_CHANNEL_STATE_UP: { - printf("XXXXXXXXXXXXXXXX answer %d\n", zchan->caller_data.raw_data_len); gen->MesType = Q931mes_CONNECT; gen->BearerCap = 0; - gen->CRVFlag = 1;//!(gen->CRVFlag); Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); } break; + case ZAP_CHANNEL_STATE_HANGUP: + { + 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; + cause.Value = zchan->caller_data.hangup_cause; + *cause.Diag = '\0'; + gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); + Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); + } + break; + case ZAP_CHANNEL_STATE_TERMINATING: + { + gen->MesType = Q931mes_RELEASE; + Q931Rx43(&data->q931, (void *)gen, gen->Size); + } default: break; } } -static void check_state(zap_span_t *span) +static __inline__ void check_state(zap_span_t *span) { - uint32_t j; - - for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - state_advance(&span->channels[j]); - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + state_advance(&span->channels[j]); + zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + } } + zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); } } From 2ac9929c055b095afc86b8372be3797d46a170dd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jun 2007 03:54:02 +0000 Subject: [PATCH 0510/1766] inbound calls milestone git-svn-id: http://svn.openzap.org/svn/openzap/trunk@255 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 9 +- libs/freetdm/src/include/openzap.h | 3 +- libs/freetdm/src/include/zap_types.h | 9 +- libs/freetdm/src/isdn/Q931api.c | 9 +- libs/freetdm/src/isdn/Q931ie.c | 23 +++-- libs/freetdm/src/priserver.c | 2 +- libs/freetdm/src/zap_analog.c | 3 + libs/freetdm/src/zap_io.c | 44 +++++--- libs/freetdm/src/zap_isdn.c | 137 ++++++++++++++++++------- 9 files changed, 164 insertions(+), 75 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index e4793fe807..639fc18f6f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -319,6 +319,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_B: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -638,7 +639,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } -static const switch_state_handler_table_t channel_event_handlers = { +static switch_state_handler_table_t channel_event_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, /*.on_execute */ channel_on_execute, @@ -647,7 +648,7 @@ static const switch_state_handler_table_t channel_event_handlers = { /*.on_transmit */ channel_on_transmit }; -static const switch_io_routines_t channel_io_routines = { +static switch_io_routines_t channel_io_routines = { /*.outgoing_channel */ channel_outgoing_channel, /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, @@ -658,7 +659,7 @@ static const switch_io_routines_t channel_io_routines = { /*.receive_message*/ channel_receive_message }; -static const switch_endpoint_interface_t channel_endpoint_interface = { +static switch_endpoint_interface_t channel_endpoint_interface = { /*.interface_name */ "openzap", /*.io_routines */ &channel_io_routines, /*.event_handlers */ &channel_event_handlers, @@ -666,7 +667,7 @@ static const switch_endpoint_interface_t channel_endpoint_interface = { /*.next */ NULL }; -static const switch_loadable_module_interface_t channel_module_interface = { +static switch_loadable_module_interface_t channel_module_interface = { /*.module_name */ modname, /*.endpoint_interface */ &channel_endpoint_interface, /*.timer_interface */ NULL, diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index a13ae80814..316b4d3af4 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -195,7 +195,7 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ - } else { \ + } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ @@ -297,6 +297,7 @@ struct zap_caller_data { char dnis[25]; char rdnis[25]; int CRV; + int hangup_cause; uint8_t raw_data[1024]; uint32_t raw_data_len; }; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index c6ae837986..b81f5338c1 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -224,7 +224,8 @@ typedef enum { typedef enum { ZAP_SPAN_CONFIGURED = (1 << 0), - ZAP_SPAN_READY = (1 << 1) + ZAP_SPAN_READY = (1 << 1), + ZAP_SPAN_STATE_CHANGE = (1 << 2) } zap_span_flag_t; typedef enum { @@ -258,10 +259,13 @@ typedef enum { ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, ZAP_CHANNEL_STATE_CALLWAITING, + ZAP_CHANNEL_STATE_TERMINATING, + ZAP_CHANNEL_STATE_RESTART, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", "INVALID" + "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ + "TERMINATING", "RESTART", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -285,7 +289,6 @@ typedef enum { ZAP_CHANNEL_CALLERID_DETECT = (1 << 17) } zap_channel_flag_t; - typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 1ac2a56b96..2e4e0063a6 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -518,8 +518,8 @@ L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCau L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) { Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; - + ptr->MesType = Q931mes_RELEASE_COMPLETE; + ptr->CRVFlag = !(ptr->CRVFlag); return Q931Tx32(pTrunk,buf,ptr->Size); } @@ -528,7 +528,10 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) L3INT RetCode; Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; - ptr->MesType = Q931mes_RELEASE_COMPLETE; + ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; + if (ptr->CRV) { + ptr->CRVFlag = !(ptr->CRVFlag); + } RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 9e2f687206..0ea4251dbf 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -715,19 +715,22 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; pie->NumPlanID = IBuf[Octet+Off] & 0x0f; Octet ++; - + /* Octet 4*/ - for (x = 0; x < IESize - 1; x++) - { + 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 - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x - 1); + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x); return Q931E_NO_ERROR; } @@ -824,15 +827,17 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA pie->Digit[x] = IBuf[Octet+Off] & 0x7f; Off++; x++; - }while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); + } while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); + + pie->Digit[x] = '\0'; Q931IESizeTest(Q931E_CALLINGNUM); Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x - 1); + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x); return Q931E_NO_ERROR; } diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index 57c29146c2..6bb5e02965 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -180,7 +180,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) 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); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 7bca77d10a..0ad28c92bd 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -307,6 +307,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (done) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; } } @@ -328,6 +329,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } else { zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); indicate = 0; state_counter = 0; zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(chan->state)); @@ -631,6 +633,7 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) 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; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 82d6706134..8f5e0d08f6 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -511,26 +511,35 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta zap_mutex_lock(zchan->mutex); - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - - switch(state) { - case ZAP_CHANNEL_STATE_BUSY: - ok = 0; - break; - default: - break; - } + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { + return ZAP_FAIL; } - if (zchan->state == ZAP_CHANNEL_STATE_BUSY) { - - switch(state) { - case ZAP_CHANNEL_STATE_UP: - ok = 0; - break; - default: - break; + switch(zchan->state) { + case ZAP_CHANNEL_STATE_DOWN: + { + switch(state) { + case ZAP_CHANNEL_STATE_BUSY: + case ZAP_CHANNEL_STATE_HANGUP: + case ZAP_CHANNEL_STATE_TERMINATING: + ok = 0; + break; + default: + break; + } } + case ZAP_CHANNEL_STATE_BUSY: + { + switch(state) { + case ZAP_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + default: + break; } if (state == zchan->state) { @@ -539,6 +548,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (ok) { zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; zchan->state = state; } diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 35b828c387..d114be55d0 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -66,52 +66,74 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_span_t *span = (zap_span_t *) pvt; zap_isdn_data_t *data = span->isdn_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; - + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + int chan_id = chanid->ChanSlot; + zap_channel_t *zchan = NULL; + assert(span != NULL); assert(data != NULL); + + if (chan_id) { + zchan = &span->channels[chan_id]; + } - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%d] Size:[%d]\n", gen->MesType, gen->Size); + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); switch(gen->MesType) { + case Q931mes_RESTART: + { + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + } else { + uint32_t i; + for (i = 0; i < span->chan_count; i++) { + zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); + } + } + } + break; + case Q931mes_RELEASE_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + break; + case Q931mes_DISCONNECT: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } + break; case Q931mes_SETUP: { - Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); - int chan_id = chanid->ChanSlot; - zap_channel_t *zchan; zap_status_t status; - zap_sigmsg_t sig; - zap_isdn_data_t *data; int fail = 1; uint32_t cplen = mlen; + if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - sig.event_id = ZAP_SIGEVENT_START; - data = zchan->span->isdn_data; - - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_copy_string(zchan->caller_data.cid_num, (char *)callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.cid_name, (char *)callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.ani, (char *)callingnum->Digit, callingnum->Size - 3); - zap_copy_string(zchan->caller_data.dnis, (char *)callednum->Digit, callednum->Size - 3); + zap_set_string(zchan->caller_data.cid_num, callingnum->Digit); + zap_set_string(zchan->caller_data.cid_name, callingnum->Digit); + zap_set_string(zchan->caller_data.ani, callingnum->Digit); + zap_set_string(zchan->caller_data.dnis, callednum->Digit); - zchan->caller_data.CRV = gen->CRV; - if (cplen > sizeof(zchan->caller_data.raw_data)) { - cplen = sizeof(zchan->caller_data.raw_data); - } - memcpy(zchan->caller_data.raw_data, msg, cplen); - zchan->caller_data.raw_data_len = cplen; - if ((status = data->sig_cb(&sig) == ZAP_SUCCESS)) { + 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; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; - } + } } if (fail) { + zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); // add me } @@ -147,39 +169,80 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } -static void state_advance(zap_channel_t *zchan) +static __inline__ void state_advance(zap_channel_t *zchan) { Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data; zap_isdn_data_t *data = zchan->span->isdn_data; + zap_sigmsg_t sig; + zap_status_t status; zap_log(ZAP_LOG_ERROR, "%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_RING: + { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + + } + break; + case ZAP_CHANNEL_STATE_RESTART: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_channel_close(&zchan); + } + break; case ZAP_CHANNEL_STATE_UP: { - printf("XXXXXXXXXXXXXXXX answer %d\n", zchan->caller_data.raw_data_len); gen->MesType = Q931mes_CONNECT; gen->BearerCap = 0; - gen->CRVFlag = 1;//!(gen->CRVFlag); Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); } break; + case ZAP_CHANNEL_STATE_HANGUP: + { + 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; + cause.Value = zchan->caller_data.hangup_cause; + *cause.Diag = '\0'; + gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); + Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); + } + break; + case ZAP_CHANNEL_STATE_TERMINATING: + { + gen->MesType = Q931mes_RELEASE; + Q931Rx43(&data->q931, (void *)gen, gen->Size); + } default: break; } } -static void check_state(zap_span_t *span) +static __inline__ void check_state(zap_span_t *span) { - uint32_t j; - - for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - state_advance(&span->channels[j]); - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + state_advance(&span->channels[j]); + zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + } } + zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); } } From 765857444a7b9df8a6669e28b5cff10581557504 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jun 2007 04:44:44 +0000 Subject: [PATCH 0511/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@256 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 5 ++-- libs/openzap/src/zap_isdn.c | 36 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 639fc18f6f..8f1abc3ecf 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -774,18 +774,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_destroy(new_session); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; goto fail; - } - return SWITCH_CAUSE_SUCCESS; } - fail: + if (zchan) { zap_channel_done(zchan); } + return cause; } diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index d114be55d0..0ae26472ab 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -55,6 +55,13 @@ static L2ULONG zap_time_now() #endif } +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) +{ + zap_status_t status = ZAP_SUCCESS; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + return status; +} + 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); @@ -207,6 +214,32 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); } break; + case ZAP_CHANNEL_STATE_DIALING: + { + Q931ie_BearerCap BearerCap; + Q931ie_ChanID ChanID; + Q931ie_CallingNum CallingNum; + Q931ie_CalledNum CalledNum; + + Q931InitIEBearerCap(&BearerCap); + Q931InitIEChanID(&ChanID); + Q931InitIECallingNum(&CallingNum); + Q931InitIECalledNum(&CalledNum); + + ChanID.ChanSlot = zchan->chan_id; + + //CallingNum.Digits + + + //Q931InitMesGeneric(gen); + gen->MesType = Q931mes_SETUP; + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); + gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); + gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); + + } + break; case ZAP_CHANNEL_STATE_HANGUP: { Q931ie_Cause cause; @@ -399,9 +432,8 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span); span->isdn_data->q931.autoRestartAck = 1; - - span->signal_type = ZAP_SIGTYPE_ISDN; + span->outgoing_call = isdn_outgoing_call; return ZAP_SUCCESS; } From f4e72b8b833afdc80c5249a86713851b91bbccd3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Jun 2007 04:44:44 +0000 Subject: [PATCH 0512/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@256 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 ++-- libs/freetdm/src/zap_isdn.c | 36 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 639fc18f6f..8f1abc3ecf 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -774,18 +774,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_destroy(new_session); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; goto fail; - } - return SWITCH_CAUSE_SUCCESS; } - fail: + if (zchan) { zap_channel_done(zchan); } + return cause; } diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index d114be55d0..0ae26472ab 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -55,6 +55,13 @@ static L2ULONG zap_time_now() #endif } +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) +{ + zap_status_t status = ZAP_SUCCESS; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + return status; +} + 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); @@ -207,6 +214,32 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); } break; + case ZAP_CHANNEL_STATE_DIALING: + { + Q931ie_BearerCap BearerCap; + Q931ie_ChanID ChanID; + Q931ie_CallingNum CallingNum; + Q931ie_CalledNum CalledNum; + + Q931InitIEBearerCap(&BearerCap); + Q931InitIEChanID(&ChanID); + Q931InitIECallingNum(&CallingNum); + Q931InitIECalledNum(&CalledNum); + + ChanID.ChanSlot = zchan->chan_id; + + //CallingNum.Digits + + + //Q931InitMesGeneric(gen); + gen->MesType = Q931mes_SETUP; + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); + gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); + gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); + + } + break; case ZAP_CHANNEL_STATE_HANGUP: { Q931ie_Cause cause; @@ -399,9 +432,8 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span); span->isdn_data->q931.autoRestartAck = 1; - - span->signal_type = ZAP_SIGTYPE_ISDN; + span->outgoing_call = isdn_outgoing_call; return ZAP_SUCCESS; } From 7a2c12fb178a55ccc64e4e360db5e5ae696d44a7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Jun 2007 04:50:47 +0000 Subject: [PATCH 0513/1766] warnings git-svn-id: http://svn.openzap.org/svn/openzap/trunk@257 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 0ae26472ab..7e24d8d650 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -122,10 +122,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_set_string(zchan->caller_data.cid_num, callingnum->Digit); - zap_set_string(zchan->caller_data.cid_name, callingnum->Digit); - zap_set_string(zchan->caller_data.ani, callingnum->Digit); - zap_set_string(zchan->caller_data.dnis, callednum->Digit); + zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.ani, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); zchan->caller_data.CRV = gen->CRV; if (cplen > sizeof(zchan->caller_data.raw_data)) { @@ -226,7 +226,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931InitIECallingNum(&CallingNum); Q931InitIECalledNum(&CalledNum); - ChanID.ChanSlot = zchan->chan_id; + //is cast right here? + ChanID.ChanSlot = (unsigned char)zchan->chan_id; //CallingNum.Digits @@ -249,7 +250,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) cause.CodStand = 0; cause.Location = 1; cause.Recom = 1; - cause.Value = zchan->caller_data.hangup_cause; + //should we be casting here.. or do we need to translate value? + cause.Value = (unsigned char) zchan->caller_data.hangup_cause; *cause.Diag = '\0'; gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); From fc1289adaa7f44f75af180ed50360ac8a7253164 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Jun 2007 04:50:47 +0000 Subject: [PATCH 0514/1766] warnings git-svn-id: http://svn.openzap.org/svn/openzap/trunk@257 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 0ae26472ab..7e24d8d650 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -122,10 +122,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_set_string(zchan->caller_data.cid_num, callingnum->Digit); - zap_set_string(zchan->caller_data.cid_name, callingnum->Digit); - zap_set_string(zchan->caller_data.ani, callingnum->Digit); - zap_set_string(zchan->caller_data.dnis, callednum->Digit); + zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.ani, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); zchan->caller_data.CRV = gen->CRV; if (cplen > sizeof(zchan->caller_data.raw_data)) { @@ -226,7 +226,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931InitIECallingNum(&CallingNum); Q931InitIECalledNum(&CalledNum); - ChanID.ChanSlot = zchan->chan_id; + //is cast right here? + ChanID.ChanSlot = (unsigned char)zchan->chan_id; //CallingNum.Digits @@ -249,7 +250,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) cause.CodStand = 0; cause.Location = 1; cause.Recom = 1; - cause.Value = zchan->caller_data.hangup_cause; + //should we be casting here.. or do we need to translate value? + cause.Value = (unsigned char) zchan->caller_data.hangup_cause; *cause.Diag = '\0'; gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); From 9a94699be8c285bb9405140b023d7b4a67b7839e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Jun 2007 04:52:21 +0000 Subject: [PATCH 0515/1766] add prototype. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@258 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 1 + libs/openzap/src/zap_isdn.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 8c63d143f8..ce74a4e0fc 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -900,6 +900,7 @@ void Q931Initialize(); 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 Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 7e24d8d650..058c76c9e1 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -232,7 +232,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) //CallingNum.Digits - //Q931InitMesGeneric(gen); + Q931InitMesGeneric(gen); gen->MesType = Q931mes_SETUP; gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); From ca93ff3fccefe03929155f5c8f28f276935bbb34 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Jun 2007 04:52:21 +0000 Subject: [PATCH 0516/1766] add prototype. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@258 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 1 + libs/freetdm/src/zap_isdn.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 8c63d143f8..ce74a4e0fc 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -900,6 +900,7 @@ void Q931Initialize(); 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 Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 7e24d8d650..058c76c9e1 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -232,7 +232,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) //CallingNum.Digits - //Q931InitMesGeneric(gen); + Q931InitMesGeneric(gen); gen->MesType = Q931mes_SETUP; gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); From 3234f987d6bb58a8424399eea7271e7098e3b372 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 04:20:45 +0000 Subject: [PATCH 0517/1766] wtf git-svn-id: http://svn.openzap.org/svn/openzap/trunk@259 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 64 +++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 1ac08b40f6..01a3f469d9 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -355,17 +355,15 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, wanpipe_tdm_api_t tdm_api; tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(chan, &tdm_api); +#if 0 + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_KEWL; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); -#if 0 - if (type == ZAP_CHAN_TYPE_FXS) { - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); - } #endif - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -526,10 +524,58 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) memset(&tdm_api, 0, sizeof(tdm_api)); switch(command) { + case ZAP_COMMAND_OFFHOOK: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_DISABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - + if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; } From 8d50ec5b9c5d089d17d9e61b61d5a94fdcf83812 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 04:20:45 +0000 Subject: [PATCH 0518/1766] wtf git-svn-id: http://svn.openzap.org/svn/openzap/trunk@259 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 64 +++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 1ac08b40f6..01a3f469d9 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -355,17 +355,15 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, wanpipe_tdm_api_t tdm_api; tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(chan, &tdm_api); +#if 0 + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_KEWL; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); -#if 0 - if (type == ZAP_CHAN_TYPE_FXS) { - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); - } #endif - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -526,10 +524,58 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) memset(&tdm_api, 0, sizeof(tdm_api)); switch(command) { + case ZAP_COMMAND_OFFHOOK: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_DISABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: + { + tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - + if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; } From 5df3ff7678aec3a2fffd87e606710047443f6631 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 08:16:38 +0000 Subject: [PATCH 0519/1766] evil ass bug git-svn-id: http://svn.openzap.org/svn/openzap/trunk@260 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/fsk.c | 44 +++++++++++++++++------------- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/uart.c | 4 +-- libs/openzap/src/zap_analog.c | 5 ++++ libs/openzap/src/zap_callerid.c | 2 ++ libs/openzap/src/zap_io.c | 5 ++-- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/libs/openzap/src/fsk.c b/libs/openzap/src/fsk.c index d933166227..df3c834787 100644 --- a/libs/openzap/src/fsk.c +++ b/libs/openzap/src/fsk.c @@ -309,30 +309,36 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) switch (handle->state) { case FSK_STATE_DATA: - (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + { + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + } break; case FSK_STATE_CHANSEIZE: - if (handle->last_bit != handle->current_bit) { - - - handle->conscutive_state_bits++; - } else { - handle->conscutive_state_bits = 0; - } - if (handle->conscutive_state_bits > 15) { - handle->state = FSK_STATE_CARRIERSIG; - handle->conscutive_state_bits = 0; + { + if (handle->last_bit != handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_CARRIERSIG; + handle->conscutive_state_bits = 0; + } } break; case FSK_STATE_CARRIERSIG: - if (handle->current_bit) { - handle->conscutive_state_bits++; - } else { - handle->conscutive_state_bits = 0; - } - if (handle->conscutive_state_bits > 15) { - handle->state = FSK_STATE_DATA; - handle->conscutive_state_bits = 0; + { + if (handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_DATA; + handle->conscutive_state_bits = 0; + } } break; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 316b4d3af4..b68596770b 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -344,6 +344,7 @@ struct zap_channel { zap_filehandle_t fds[2]; zap_fsk_data_state_t fsk; uint8_t fsk_buf[80]; + uint32_t ring_count; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; diff --git a/libs/openzap/src/uart.c b/libs/openzap/src/uart.c index 05a80753ec..5e0dd85350 100644 --- a/libs/openzap/src/uart.c +++ b/libs/openzap/src/uart.c @@ -78,7 +78,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) handle = malloc(sizeof (*handle)); if (handle) { - memset(handle, 0, sizeof (handle)); + memset(handle, 0, sizeof (*handle)); /* fill the attributes member */ memcpy(&handle->attr, attr, sizeof (*attr)); @@ -111,8 +111,8 @@ void dsp_uart_bit_handler(void *x, int bit) 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; diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 0ad28c92bd..adaa0ad2a0 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -426,7 +426,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); + zap_channel_command(chan, ZAP_COMMAND_TRACE_INPUT, "/tmp/wtf.ul"); zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + continue; } break; case ZAP_CHANNEL_STATE_RING: @@ -619,7 +621,10 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); + event->channel->ring_count = 1; zap_thread_create_detached(zap_analog_channel_run, event->channel); + } else { + event->channel->ring_count++; } } break; diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 3e8a790053..8940569ec0 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -182,6 +182,8 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ dsp_fsk_destroy(&state->fsk1200_handle); } + memset(state, 0, sizeof(*state)); + memset(buf, 0, bufsize); state->buf = buf; state->bufsize = bufsize; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8f5e0d08f6..b997a0156c 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1408,13 +1408,12 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { uint32_t type, mlen; char str[128], *sp; - - + while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { *(str+mlen) = '\0'; zap_copy_string(str, sp, ++mlen); zap_clean_string(str); - zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + zap_log(ZAP_LOG_ERROR, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); switch(type) { case MDMF_DDN: From f4b07092fc2fc6024acaf3d0a40c5be707320542 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 08:16:38 +0000 Subject: [PATCH 0520/1766] evil ass bug git-svn-id: http://svn.openzap.org/svn/openzap/trunk@260 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/fsk.c | 44 +++++++++++++++++------------- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/uart.c | 4 +-- libs/freetdm/src/zap_analog.c | 5 ++++ libs/freetdm/src/zap_callerid.c | 2 ++ libs/freetdm/src/zap_io.c | 5 ++-- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index d933166227..df3c834787 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -309,30 +309,36 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) switch (handle->state) { case FSK_STATE_DATA: - (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + { + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); + } break; case FSK_STATE_CHANSEIZE: - if (handle->last_bit != handle->current_bit) { - - - handle->conscutive_state_bits++; - } else { - handle->conscutive_state_bits = 0; - } - if (handle->conscutive_state_bits > 15) { - handle->state = FSK_STATE_CARRIERSIG; - handle->conscutive_state_bits = 0; + { + if (handle->last_bit != handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_CARRIERSIG; + handle->conscutive_state_bits = 0; + } } break; case FSK_STATE_CARRIERSIG: - if (handle->current_bit) { - handle->conscutive_state_bits++; - } else { - handle->conscutive_state_bits = 0; - } - if (handle->conscutive_state_bits > 15) { - handle->state = FSK_STATE_DATA; - handle->conscutive_state_bits = 0; + { + if (handle->current_bit) { + handle->conscutive_state_bits++; + } else { + handle->conscutive_state_bits = 0; + } + + if (handle->conscutive_state_bits > 15) { + handle->state = FSK_STATE_DATA; + handle->conscutive_state_bits = 0; + } } break; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 316b4d3af4..b68596770b 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -344,6 +344,7 @@ struct zap_channel { zap_filehandle_t fds[2]; zap_fsk_data_state_t fsk; uint8_t fsk_buf[80]; + uint32_t ring_count; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; diff --git a/libs/freetdm/src/uart.c b/libs/freetdm/src/uart.c index 05a80753ec..5e0dd85350 100644 --- a/libs/freetdm/src/uart.c +++ b/libs/freetdm/src/uart.c @@ -78,7 +78,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) handle = malloc(sizeof (*handle)); if (handle) { - memset(handle, 0, sizeof (handle)); + memset(handle, 0, sizeof (*handle)); /* fill the attributes member */ memcpy(&handle->attr, attr, sizeof (*attr)); @@ -111,8 +111,8 @@ void dsp_uart_bit_handler(void *x, int bit) 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; diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 0ad28c92bd..adaa0ad2a0 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -426,7 +426,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); + zap_channel_command(chan, ZAP_COMMAND_TRACE_INPUT, "/tmp/wtf.ul"); zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + continue; } break; case ZAP_CHANNEL_STATE_RING: @@ -619,7 +621,10 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); + event->channel->ring_count = 1; zap_thread_create_detached(zap_analog_channel_run, event->channel); + } else { + event->channel->ring_count++; } } break; diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 3e8a790053..8940569ec0 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -182,6 +182,8 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ dsp_fsk_destroy(&state->fsk1200_handle); } + memset(state, 0, sizeof(*state)); + memset(buf, 0, bufsize); state->buf = buf; state->bufsize = bufsize; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8f5e0d08f6..b997a0156c 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1408,13 +1408,12 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { uint32_t type, mlen; char str[128], *sp; - - + while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { *(str+mlen) = '\0'; zap_copy_string(str, sp, ++mlen); zap_clean_string(str); - zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + zap_log(ZAP_LOG_ERROR, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); switch(type) { case MDMF_DDN: From facd5a6245b481a6d41b8ce8a4318dcc63988e91 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 20:58:46 +0000 Subject: [PATCH 0521/1766] fux type git-svn-id: http://svn.openzap.org/svn/openzap/trunk@261 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index b997a0156c..416562c087 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1406,7 +1406,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { - uint32_t type, mlen; + zap_size_t type, mlen; char str[128], *sp; while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { From 00c90fa27b0d57ed931f42b55351016da23dfdc1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 20:58:46 +0000 Subject: [PATCH 0522/1766] fux type git-svn-id: http://svn.openzap.org/svn/openzap/trunk@261 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index b997a0156c..416562c087 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1406,7 +1406,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { - uint32_t type, mlen; + zap_size_t type, mlen; char str[128], *sp; while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { From e06ddca9e7b05a1f70d03d967700bfce3791913d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 22:07:53 +0000 Subject: [PATCH 0523/1766] build tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@262 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 2 ++ libs/openzap/src/zap_analog.c | 5 +++++ libs/openzap/src/zap_wanpipe.c | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index b81f5338c1..7eb9bbff0d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -50,6 +50,8 @@ typedef intptr_t zap_ssize_t; typedef int zap_filehandle_t; #else #include +#include +#include typedef int zap_socket_t; typedef ssize_t zap_ssize_t; typedef int zap_filehandle_t; diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index adaa0ad2a0..91f982a2f4 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -34,6 +34,11 @@ #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); static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 01a3f469d9..6ea3a98b3e 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -33,7 +33,6 @@ #include "openzap.h" #include "zap_wanpipe.h" -#include #include #include #include From ffbf2620d87dda609cf469021e91b6f93d642a29 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Jun 2007 22:07:53 +0000 Subject: [PATCH 0524/1766] build tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@262 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 2 ++ libs/freetdm/src/zap_analog.c | 5 +++++ libs/freetdm/src/zap_wanpipe.c | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b81f5338c1..7eb9bbff0d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -50,6 +50,8 @@ typedef intptr_t zap_ssize_t; typedef int zap_filehandle_t; #else #include +#include +#include typedef int zap_socket_t; typedef ssize_t zap_ssize_t; typedef int zap_filehandle_t; diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index adaa0ad2a0..91f982a2f4 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -34,6 +34,11 @@ #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); static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 01a3f469d9..6ea3a98b3e 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -33,7 +33,6 @@ #include "openzap.h" #include "zap_wanpipe.h" -#include #include #include #include From ba4244b28badd8c7023df123ba023b3ac00266bc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 00:18:56 +0000 Subject: [PATCH 0525/1766] fix tones stuff on 64bit git-svn-id: http://svn.openzap.org/svn/openzap/trunk@263 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone_detect.h | 19 +++------- libs/openzap/src/libteletone_detect.c | 38 +++++++++---------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index 15d5e9ddfb..9c18d4b5a1 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -136,9 +136,9 @@ extern "C" { /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ typedef struct { - teletone_process_t v2; - teletone_process_t v3; - teletone_process_t fac; + float v2; + float v3; + double fac; } teletone_goertzel_state_t; /*! \brief A container for a DTMF detection state.*/ @@ -153,7 +153,7 @@ extern "C" { teletone_goertzel_state_t col_out[GRID_FACTOR]; teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; - teletone_process_t energy; + float energy; int current_sample; char digits[TELETONE_MAX_DTMF_DIGITS + 1]; @@ -165,7 +165,7 @@ extern "C" { /*! \brief An abstraction to store the coefficient of a tone frequency */ typedef struct { - teletone_process_t fac; + float fac; } teletone_detection_descriptor_t; /*! \brief A container for a single multi-tone detection @@ -180,7 +180,7 @@ extern "C" { teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; int tone_count; - teletone_process_t energy; + float energy; int current_sample; int min_samples; @@ -253,13 +253,6 @@ extern "C" { int16_t sample_buffer[], int samples); - /*! - \brief Compute the result of the last applied step of the Goertzel Algorithm - \param goertzel_state the goertzel state to retrieve from - \return the computed value for consideration in furthur audio tests - */ - teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); - #ifdef __cplusplus diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index a089f8fc48..a1d95abcd4 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -106,9 +106,8 @@ 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 teletone_process_t dtmf_row[] = {697.0, 770.0, 852.0, 941.0}; -static teletone_process_t dtmf_col[] = {1209.0, 1336.0, 1477.0, 1633.0}; - +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"; @@ -122,7 +121,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int samples) { int i; - teletone_process_t v1; + float v1; for (i = 0; i < samples; i++) { v1 = goertzel_state->v2; @@ -131,29 +130,26 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, } } -teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state) -{ - return goertzel_state->v3 * goertzel_state->v3 + goertzel_state->v2 * goertzel_state->v2 - goertzel_state->v2 * goertzel_state->v3 * goertzel_state->fac; -} +#define teletone_goertzel_result(gs) ((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { int i; - teletone_process_t theta; + float theta; dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; for (i = 0; i < GRID_FACTOR; i++) { - theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); dtmf_detect_row[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); dtmf_detect_col[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]); @@ -172,7 +168,7 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) { - teletone_process_t theta = 0; + float theta = 0; int x = 0; if(!mt->min_samples) { @@ -200,7 +196,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma break; } mt->tone_count++; - theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); + theta = M_TWO_PI*(map->freqs[x]/(float)mt->sample_rate); mt->tdd[x].fac = 2.0 * cos(theta); goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]); @@ -213,8 +209,8 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, int samples) { int sample, limit, j, x = 0; - teletone_process_t v1, famp; - teletone_process_t eng_sum = 0, eng_all[TELETONE_MAX_TONES]; + float v1, famp; + float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; for (sample = 0; sample < samples; sample = limit) { @@ -299,10 +295,10 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples) { - teletone_process_t row_energy[GRID_FACTOR]; - teletone_process_t col_energy[GRID_FACTOR]; - teletone_process_t famp; - teletone_process_t v1; + float row_energy[GRID_FACTOR]; + float col_energy[GRID_FACTOR]; + float famp; + float v1; int i; int j; int sample; From 64741d84a2cc0eb00f478e268cb8a80604c527ad Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 00:18:56 +0000 Subject: [PATCH 0526/1766] fix tones stuff on 64bit git-svn-id: http://svn.openzap.org/svn/openzap/trunk@263 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone_detect.h | 19 +++------- libs/freetdm/src/libteletone_detect.c | 38 +++++++++---------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 15d5e9ddfb..9c18d4b5a1 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -136,9 +136,9 @@ extern "C" { /*! \brief A continer for the elements of a Goertzel Algorithm (The names are from his formula) */ typedef struct { - teletone_process_t v2; - teletone_process_t v3; - teletone_process_t fac; + float v2; + float v3; + double fac; } teletone_goertzel_state_t; /*! \brief A container for a DTMF detection state.*/ @@ -153,7 +153,7 @@ extern "C" { teletone_goertzel_state_t col_out[GRID_FACTOR]; teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; - teletone_process_t energy; + float energy; int current_sample; char digits[TELETONE_MAX_DTMF_DIGITS + 1]; @@ -165,7 +165,7 @@ extern "C" { /*! \brief An abstraction to store the coefficient of a tone frequency */ typedef struct { - teletone_process_t fac; + float fac; } teletone_detection_descriptor_t; /*! \brief A container for a single multi-tone detection @@ -180,7 +180,7 @@ extern "C" { teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]; int tone_count; - teletone_process_t energy; + float energy; int current_sample; int min_samples; @@ -253,13 +253,6 @@ extern "C" { int16_t sample_buffer[], int samples); - /*! - \brief Compute the result of the last applied step of the Goertzel Algorithm - \param goertzel_state the goertzel state to retrieve from - \return the computed value for consideration in furthur audio tests - */ - teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state); - #ifdef __cplusplus diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index a089f8fc48..a1d95abcd4 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -106,9 +106,8 @@ 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 teletone_process_t dtmf_row[] = {697.0, 770.0, 852.0, 941.0}; -static teletone_process_t dtmf_col[] = {1209.0, 1336.0, 1477.0, 1633.0}; - +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"; @@ -122,7 +121,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int samples) { int i; - teletone_process_t v1; + float v1; for (i = 0; i < samples; i++) { v1 = goertzel_state->v2; @@ -131,29 +130,26 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, } } -teletone_process_t teletone_goertzel_result (teletone_goertzel_state_t *goertzel_state) -{ - return goertzel_state->v3 * goertzel_state->v3 + goertzel_state->v2 * goertzel_state->v2 - goertzel_state->v2 * goertzel_state->v3 * goertzel_state->fac; -} +#define teletone_goertzel_result(gs) ((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { int i; - teletone_process_t theta; + float theta; dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; for (i = 0; i < GRID_FACTOR; i++) { - theta = M_TWO_PI*(dtmf_row[i]/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); dtmf_detect_row[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); dtmf_detect_col[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_row[i]*2.0/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]*2.0/(teletone_process_t)sample_rate); + theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); goertzel_init (&dtmf_detect_state->row_out[i], &dtmf_detect_row[i]); @@ -172,7 +168,7 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) { - teletone_process_t theta = 0; + float theta = 0; int x = 0; if(!mt->min_samples) { @@ -200,7 +196,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma break; } mt->tone_count++; - theta = M_TWO_PI*(map->freqs[x]/(teletone_process_t)mt->sample_rate); + theta = M_TWO_PI*(map->freqs[x]/(float)mt->sample_rate); mt->tdd[x].fac = 2.0 * cos(theta); goertzel_init (&mt->gs[x], &mt->tdd[x]); goertzel_init (&mt->gs2[x], &mt->tdd[x]); @@ -213,8 +209,8 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, int samples) { int sample, limit, j, x = 0; - teletone_process_t v1, famp; - teletone_process_t eng_sum = 0, eng_all[TELETONE_MAX_TONES]; + float v1, famp; + float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; for (sample = 0; sample < samples; sample = limit) { @@ -299,10 +295,10 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples) { - teletone_process_t row_energy[GRID_FACTOR]; - teletone_process_t col_energy[GRID_FACTOR]; - teletone_process_t famp; - teletone_process_t v1; + float row_energy[GRID_FACTOR]; + float col_energy[GRID_FACTOR]; + float famp; + float v1; int i; int j; int sample; From bed2275bc8945f4f4ba6852b7c19bf01ecb61c59 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 04:39:15 +0000 Subject: [PATCH 0527/1766] outbound isdn w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@264 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 31 ++++- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_types.h | 7 +- libs/openzap/src/isdn/Q931api.c | 6 +- libs/openzap/src/isdn/Q931ie.c | 19 +-- libs/openzap/src/priserver.c | 1 + libs/openzap/src/zap_io.c | 32 ++++- libs/openzap/src/zap_isdn.c | 168 +++++++++++++++++++++---- 8 files changed, 222 insertions(+), 43 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 8f1abc3ecf..ef755a4772 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -554,7 +554,14 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, assert(tech_pvt != NULL); switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_RINGING: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } case SWITCH_MESSAGE_INDICATE_PROGRESS: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + } case SWITCH_MESSAGE_INDICATE_ANSWER: if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); @@ -697,14 +704,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + dest = outbound_profile->destination_number; + if ((p = strchr(outbound_profile->destination_number, '/'))) { dest = p + 1; span_id = atoi(outbound_profile->destination_number); chan_id = atoi(dest); + if ((p = strchr(dest, '/'))) { + dest = p + 1; + } } - dest = outbound_profile->destination_number; - if (!dest) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -972,6 +982,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) switch_core_session_rwunlock(session); } } + case ZAP_SIGEVENT_PROGRESS_MEDIA: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_pre_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_PROGRESS: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_ring_ready(channel); + switch_core_session_rwunlock(session); + } + } break; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index b68596770b..c95849df43 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -482,6 +482,7 @@ void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); +void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 7eb9bbff0d..900c29c9b5 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -263,11 +263,13 @@ typedef enum { ZAP_CHANNEL_STATE_CALLWAITING, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_RESTART, + ZAP_CHANNEL_STATE_EARLY_MEDIA, + ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "INVALID" + "TERMINATING", "RESTART", "EARLY_MEDIA", "PROGRESS", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -288,7 +290,8 @@ typedef enum { ZAP_CHANNEL_OFFHOOK = (1 << 14), ZAP_CHANNEL_RINGING = (1 << 15), ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), - ZAP_CHANNEL_CALLERID_DETECT = (1 << 17) + ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), + ZAP_CHANNEL_OUTBOUND = (1 << 18) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 2e4e0063a6..541b28d428 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -217,7 +217,7 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) { memset(pMes, 0, sizeof(*pMes)); - pMes->ProtDisc = 0x80; + pMes->ProtDisc = 0x08; pMes->Size = Q931GetMesSize(pMes); return 0; @@ -225,7 +225,7 @@ L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) L3INT Q931InitMesResume(Q931mes_Generic * pMes) { - pMes->ProtDisc = 0x80; + pMes->ProtDisc = 0x08; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESUME; @@ -236,7 +236,7 @@ L3INT Q931InitMesResume(Q931mes_Generic * pMes) L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes) { - pMes->ProtDisc = 0x80; + pMes->ProtDisc = 0x08; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE; diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 0ea4251dbf..9ed580568b 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -322,17 +322,12 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, li=(*Octet)++; /* remember length position */ /* Octet 3 - Coding standard / Information transfer capability */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITC & 0x1f); /* Octet 4 - Transfer mode / Information transfer rate */ + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); if(pIE->ITR == 0x18) { - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - } - else - { - OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - /* Octet 4.1 - Rate Multiplier */ OBuf[(*Octet)++] = 0x80 | pIE->RateMul; } @@ -382,7 +377,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, } else { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); + OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x1F); } } @@ -748,11 +743,11 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *****************************************************************************/ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf; + Q931ie_CalledNum * pIE = (Q931ie_CalledNum*)IBuf; L3INT rc=0; L3INT Beg=*Octet; L3INT li; - L3INT sN = pIE->Size - sizeof(Q931ie_CalledSub) + 1; + L3INT sN = pIE->Size - sizeof(Q931ie_CalledNum); L3INT x; /* Octet 1 */ @@ -760,7 +755,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, li=(*Octet)++; /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3); + OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->NumPlanID); /* Octet 4 */ for(x=0;xDigit[x]; } - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c index 6bb5e02965..377ded7325 100644 --- a/libs/openzap/src/priserver.c +++ b/libs/openzap/src/priserver.c @@ -290,6 +290,7 @@ int main(int argc, char *argv[]) debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; + printf("WTF %d\n", debug); if (sangoma_init_pri(&spri, 1, // span diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 416562c087..d5b525bcdd 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -658,6 +658,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); zap_channel_done(zchan); zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); + memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; @@ -747,9 +748,15 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) { + zap_status_t status; + assert(zchan != NULL); + if (zchan->span->outgoing_call) { - return zchan->span->outgoing_call(zchan); + if ((status = zchan->span->outgoing_call(zchan)) == ZAP_SUCCESS) { + zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + } + return status; } else { zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n"); } @@ -765,6 +772,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); for (i = 0; i < 2; i++) { if (zchan->fds[i] > -1) { close(zchan->fds[i]); @@ -1967,6 +1975,28 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) return bit; } +void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen) +{ + char *bp = buf; + uint8_t *byte = data; + uint32_t i, j = 0; + + if (blen < (dlen * 3) + 2) { + return; + } + + *bp++ = '['; + j++; + + for(i = 0; i < dlen; i++) { + snprintf(bp, blen-j, "%02x ", *byte++); + bp += 3; + j += 3; + } + + *--bp = ']'; + +} void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 058c76c9e1..ec42c2e43f 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -108,6 +108,21 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } break; + case Q931mes_ALERTING: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + } + break; + case Q931mes_PROGRESS: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + break; + case Q931mes_CONNECT: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + break; case Q931mes_SETUP: { @@ -155,7 +170,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { - int ret = Q931Rx23(pvt, msg, mlen); + int ret; + char bb[4096] = ""; + print_hex_bytes(msg, mlen, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen, LINE, bb); + + ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); return ((ret >= 0) ? 1 : 0); @@ -166,9 +186,10 @@ 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; #ifdef IODEBUG - char bb[4096] = ""; - 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); + //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 @@ -192,11 +213,31 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.channel = zchan; switch (zchan->state) { + case ZAP_CHANNEL_STATE_DOWN: + { + 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 = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + gen->MesType = Q931mes_PROGRESS; + Q931Rx43(&data->q931, (void *)gen, gen->Size); + } + } + break; case ZAP_CHANNEL_STATE_RING: { - sig.event_id = ZAP_SIGEVENT_START; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } } } @@ -207,11 +248,31 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_channel_close(&zchan); } break; + case ZAP_CHANNEL_STATE_EARLY_MEDIA: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + gen->MesType = Q931mes_ALERTING; + Q931Rx43(&data->q931, (void *)gen, gen->Size); + } + } + break; case ZAP_CHANNEL_STATE_UP: { - gen->MesType = Q931mes_CONNECT; - gen->BearerCap = 0; - Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_UP; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + gen->MesType = Q931mes_CONNECT; + gen->BearerCap = 0; + Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + } } break; case ZAP_CHANNEL_STATE_DIALING: @@ -220,25 +281,75 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_ChanID ChanID; Q931ie_CallingNum CallingNum; Q931ie_CalledNum CalledNum; + Q931ie_CalledNum *ptrCalledNum; Q931InitIEBearerCap(&BearerCap); Q931InitIEChanID(&ChanID); Q931InitIECallingNum(&CallingNum); Q931InitIECalledNum(&CalledNum); - - //is cast right here? - ChanID.ChanSlot = (unsigned char)zchan->chan_id; - - //CallingNum.Digits - Q931InitMesGeneric(gen); gen->MesType = Q931mes_SETUP; + + BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ + BearerCap.ITC = 0; /* Speech */ + BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ + BearerCap.ITR = 16; /* 64k */ + BearerCap.Layer1Ident = 1; + BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ +#if 0 + BearerCap.SyncAsync = ; + BearerCap.Negot = ; + BearerCap.UserRate = ; + BearerCap.InterRate = ; + BearerCap.NIConTx = ; + BearerCap.FlowCtlTx = ; + BearerCap.HDR = ; + BearerCap.MultiFrame = ; + BearerCap.Mode = ; + BearerCap.LLInegot = ; + BearerCap.Assignor = ; + BearerCap.InBandNeg = ; + BearerCap.NumStopBits = ; + BearerCap.NumDataBits = ; + BearerCap.Parity = ; + BearerCap.DuplexMode = ; + BearerCap.ModemType = ; + BearerCap.Layer2Ident = ; + BearerCap.UIL2Prot = ; + BearerCap.Layer3Ident = ; + BearerCap.UIL3Prot = ; + BearerCap.AL3Info1 = ; + BearerCap.AL3Info2 = ; +#endif + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + + //is cast right here? + ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ + ChanID.InfoChanSel = 1; + ChanID.ChanMapType = 3; /* B-Chan */ + ChanID.ChanSlot = (unsigned char)zchan->chan_id; gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); - gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); +#if 0 + CallingNum.Size += strlen(zchan->caller_data.cid_num); + gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); + zap_set_string((char *)CallingNum.Digit, zchan->caller_data.cid_num); + gen->Size += strlen(zchan->caller_data.cid_num); + + //zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); + +#endif + CalledNum.TypNum = 2; + CalledNum.NumPlanID = 1; + printf("WTF: [%s]\n", zchan->caller_data.ani); + CalledNum.Size += strlen(zchan->caller_data.ani); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); - + ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); + zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); + + //gen->Size += strlen(zchan->caller_data.ani); + Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -328,9 +439,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG - char bb[4096] = ""; - print_bits(buf, (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); + //char bb[4096] = ""; + //print_hex_bytes(buf, len, bb, sizeof(bb)); + + //print_bits(buf, (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(&data->q921, buf, (int)len); @@ -374,6 +487,16 @@ zap_status_t zap_isdn_start(zap_span_t *span) return zap_thread_create_detached(zap_isdn_run, span); } +static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen) +{ + int ret; + char bb[4096] = ""; + ret = Q921Rx32(pvt, msg, mlen); + print_hex_bytes(msg, mlen, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen, LINE, bb); + return ret; +} + zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) { uint32_t i, x = 0; @@ -428,12 +551,13 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D mode, span->trunk_type, zap_isdn_931_34, - (Q931TxCB_t)Q921Rx32, + (Q931TxCB_t)q931_rx_32, zap_isdn_931_err, &span->isdn_data->q921, span); span->isdn_data->q931.autoRestartAck = 1; + span->isdn_data->q931.autoConnectAck = 1; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; From c1dfe0c0ae4f1251613f6fd5487c38b5e1c70733 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 04:39:15 +0000 Subject: [PATCH 0528/1766] outbound isdn w00t git-svn-id: http://svn.openzap.org/svn/openzap/trunk@264 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 31 ++++- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 7 +- libs/freetdm/src/isdn/Q931api.c | 6 +- libs/freetdm/src/isdn/Q931ie.c | 19 +-- libs/freetdm/src/priserver.c | 1 + libs/freetdm/src/zap_io.c | 32 ++++- libs/freetdm/src/zap_isdn.c | 168 +++++++++++++++++++++---- 8 files changed, 222 insertions(+), 43 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 8f1abc3ecf..ef755a4772 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -554,7 +554,14 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, assert(tech_pvt != NULL); switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_RINGING: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } case SWITCH_MESSAGE_INDICATE_PROGRESS: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + } case SWITCH_MESSAGE_INDICATE_ANSWER: if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); @@ -697,14 +704,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + dest = outbound_profile->destination_number; + if ((p = strchr(outbound_profile->destination_number, '/'))) { dest = p + 1; span_id = atoi(outbound_profile->destination_number); chan_id = atoi(dest); + if ((p = strchr(dest, '/'))) { + dest = p + 1; + } } - dest = outbound_profile->destination_number; - if (!dest) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -972,6 +982,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) switch_core_session_rwunlock(session); } } + case ZAP_SIGEVENT_PROGRESS_MEDIA: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_pre_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_PROGRESS: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_ring_ready(channel); + switch_core_session_rwunlock(session); + } + } break; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index b68596770b..c95849df43 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -482,6 +482,7 @@ void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); +void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 7eb9bbff0d..900c29c9b5 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -263,11 +263,13 @@ typedef enum { ZAP_CHANNEL_STATE_CALLWAITING, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_RESTART, + ZAP_CHANNEL_STATE_EARLY_MEDIA, + ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "INVALID" + "TERMINATING", "RESTART", "EARLY_MEDIA", "PROGRESS", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { @@ -288,7 +290,8 @@ typedef enum { ZAP_CHANNEL_OFFHOOK = (1 << 14), ZAP_CHANNEL_RINGING = (1 << 15), ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), - ZAP_CHANNEL_CALLERID_DETECT = (1 << 17) + ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), + ZAP_CHANNEL_OUTBOUND = (1 << 18) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 2e4e0063a6..541b28d428 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -217,7 +217,7 @@ L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) { memset(pMes, 0, sizeof(*pMes)); - pMes->ProtDisc = 0x80; + pMes->ProtDisc = 0x08; pMes->Size = Q931GetMesSize(pMes); return 0; @@ -225,7 +225,7 @@ L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) L3INT Q931InitMesResume(Q931mes_Generic * pMes) { - pMes->ProtDisc = 0x80; + pMes->ProtDisc = 0x08; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESUME; @@ -236,7 +236,7 @@ L3INT Q931InitMesResume(Q931mes_Generic * pMes) L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes) { - pMes->ProtDisc = 0x80; + pMes->ProtDisc = 0x08; pMes->CRV = 0; /* CRV to be allocated, might be receive*/ pMes->MesType = Q931mes_RESTART_ACKNOWLEDGE; diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 0ea4251dbf..9ed580568b 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -322,17 +322,12 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, li=(*Octet)++; /* remember length position */ /* Octet 3 - Coding standard / Information transfer capability */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITR & 0x1f); + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITC & 0x1f); /* Octet 4 - Transfer mode / Information transfer rate */ + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); if(pIE->ITR == 0x18) { - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - } - else - { - OBuf[(*Octet)++] = 0x00 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); - /* Octet 4.1 - Rate Multiplier */ OBuf[(*Octet)++] = 0x80 | pIE->RateMul; } @@ -382,7 +377,7 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, } else { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15); + OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x1F); } } @@ -748,11 +743,11 @@ L3INT Q931Uie_CalledNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *****************************************************************************/ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - Q931ie_CalledSub * pIE = (Q931ie_CalledSub*)IBuf; + Q931ie_CalledNum * pIE = (Q931ie_CalledNum*)IBuf; L3INT rc=0; L3INT Beg=*Octet; L3INT li; - L3INT sN = pIE->Size - sizeof(Q931ie_CalledSub) + 1; + L3INT sN = pIE->Size - sizeof(Q931ie_CalledNum); L3INT x; /* Octet 1 */ @@ -760,7 +755,7 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, li=(*Octet)++; /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3); + OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->NumPlanID); /* Octet 4 */ for(x=0;xDigit[x]; } - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index 6bb5e02965..377ded7325 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -290,6 +290,7 @@ int main(int argc, char *argv[]) debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; + printf("WTF %d\n", debug); if (sangoma_init_pri(&spri, 1, // span diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 416562c087..d5b525bcdd 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -658,6 +658,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); zap_channel_done(zchan); zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); + memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; @@ -747,9 +748,15 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) { + zap_status_t status; + assert(zchan != NULL); + if (zchan->span->outgoing_call) { - return zchan->span->outgoing_call(zchan); + if ((status = zchan->span->outgoing_call(zchan)) == ZAP_SUCCESS) { + zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + } + return status; } else { zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n"); } @@ -765,6 +772,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); for (i = 0; i < 2; i++) { if (zchan->fds[i] > -1) { close(zchan->fds[i]); @@ -1967,6 +1975,28 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) return bit; } +void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen) +{ + char *bp = buf; + uint8_t *byte = data; + uint32_t i, j = 0; + + if (blen < (dlen * 3) + 2) { + return; + } + + *bp++ = '['; + j++; + + for(i = 0; i < dlen; i++) { + snprintf(bp, blen-j, "%02x ", *byte++); + bp += 3; + j += 3; + } + + *--bp = ']'; + +} void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 058c76c9e1..ec42c2e43f 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -108,6 +108,21 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } break; + case Q931mes_ALERTING: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + } + break; + case Q931mes_PROGRESS: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + break; + case Q931mes_CONNECT: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + break; case Q931mes_SETUP: { @@ -155,7 +170,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { - int ret = Q931Rx23(pvt, msg, mlen); + int ret; + char bb[4096] = ""; + print_hex_bytes(msg, mlen, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen, LINE, bb); + + ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); return ((ret >= 0) ? 1 : 0); @@ -166,9 +186,10 @@ 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; #ifdef IODEBUG - char bb[4096] = ""; - 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); + //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 @@ -192,11 +213,31 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.channel = zchan; switch (zchan->state) { + case ZAP_CHANNEL_STATE_DOWN: + { + 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 = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + gen->MesType = Q931mes_PROGRESS; + Q931Rx43(&data->q931, (void *)gen, gen->Size); + } + } + break; case ZAP_CHANNEL_STATE_RING: { - sig.event_id = ZAP_SIGEVENT_START; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } } } @@ -207,11 +248,31 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_channel_close(&zchan); } break; + case ZAP_CHANNEL_STATE_EARLY_MEDIA: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + gen->MesType = Q931mes_ALERTING; + Q931Rx43(&data->q931, (void *)gen, gen->Size); + } + } + break; case ZAP_CHANNEL_STATE_UP: { - gen->MesType = Q931mes_CONNECT; - gen->BearerCap = 0; - Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_UP; + if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + gen->MesType = Q931mes_CONNECT; + gen->BearerCap = 0; + Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + } } break; case ZAP_CHANNEL_STATE_DIALING: @@ -220,25 +281,75 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_ChanID ChanID; Q931ie_CallingNum CallingNum; Q931ie_CalledNum CalledNum; + Q931ie_CalledNum *ptrCalledNum; Q931InitIEBearerCap(&BearerCap); Q931InitIEChanID(&ChanID); Q931InitIECallingNum(&CallingNum); Q931InitIECalledNum(&CalledNum); - - //is cast right here? - ChanID.ChanSlot = (unsigned char)zchan->chan_id; - - //CallingNum.Digits - Q931InitMesGeneric(gen); gen->MesType = Q931mes_SETUP; + + BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ + BearerCap.ITC = 0; /* Speech */ + BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ + BearerCap.ITR = 16; /* 64k */ + BearerCap.Layer1Ident = 1; + BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ +#if 0 + BearerCap.SyncAsync = ; + BearerCap.Negot = ; + BearerCap.UserRate = ; + BearerCap.InterRate = ; + BearerCap.NIConTx = ; + BearerCap.FlowCtlTx = ; + BearerCap.HDR = ; + BearerCap.MultiFrame = ; + BearerCap.Mode = ; + BearerCap.LLInegot = ; + BearerCap.Assignor = ; + BearerCap.InBandNeg = ; + BearerCap.NumStopBits = ; + BearerCap.NumDataBits = ; + BearerCap.Parity = ; + BearerCap.DuplexMode = ; + BearerCap.ModemType = ; + BearerCap.Layer2Ident = ; + BearerCap.UIL2Prot = ; + BearerCap.Layer3Ident = ; + BearerCap.UIL3Prot = ; + BearerCap.AL3Info1 = ; + BearerCap.AL3Info2 = ; +#endif + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + + //is cast right here? + ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ + ChanID.InfoChanSel = 1; + ChanID.ChanMapType = 3; /* B-Chan */ + ChanID.ChanSlot = (unsigned char)zchan->chan_id; gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); - gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); +#if 0 + CallingNum.Size += strlen(zchan->caller_data.cid_num); + gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); + zap_set_string((char *)CallingNum.Digit, zchan->caller_data.cid_num); + gen->Size += strlen(zchan->caller_data.cid_num); + + //zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); + +#endif + CalledNum.TypNum = 2; + CalledNum.NumPlanID = 1; + printf("WTF: [%s]\n", zchan->caller_data.ani); + CalledNum.Size += strlen(zchan->caller_data.ani); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); - + ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); + zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); + + //gen->Size += strlen(zchan->caller_data.ani); + Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -328,9 +439,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG - char bb[4096] = ""; - print_bits(buf, (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); + //char bb[4096] = ""; + //print_hex_bytes(buf, len, bb, sizeof(bb)); + + //print_bits(buf, (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(&data->q921, buf, (int)len); @@ -374,6 +487,16 @@ zap_status_t zap_isdn_start(zap_span_t *span) return zap_thread_create_detached(zap_isdn_run, span); } +static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen) +{ + int ret; + char bb[4096] = ""; + ret = Q921Rx32(pvt, msg, mlen); + print_hex_bytes(msg, mlen, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen, LINE, bb); + return ret; +} + zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) { uint32_t i, x = 0; @@ -428,12 +551,13 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D mode, span->trunk_type, zap_isdn_931_34, - (Q931TxCB_t)Q921Rx32, + (Q931TxCB_t)q931_rx_32, zap_isdn_931_err, &span->isdn_data->q921, span); span->isdn_data->q931.autoRestartAck = 1; + span->isdn_data->q931.autoConnectAck = 1; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; From a91ce4a518210ba2bc620d5dad7f23ed4e553781 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 13:46:32 +0000 Subject: [PATCH 0529/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@265 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 24 ++++++++++++++++-------- libs/openzap/src/include/zap_types.h | 4 ++-- libs/openzap/src/zap_io.c | 16 ++++++++++++++++ libs/openzap/src/zap_isdn.c | 4 ++-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ef755a4772..0b07afbe2c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -555,16 +555,24 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } } + break; case SWITCH_MESSAGE_INDICATE_PROGRESS: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } } + break; case SWITCH_MESSAGE_INDICATE_ANSWER: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } } break; default: @@ -877,7 +885,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) switch_channel_t *channel = NULL; zap_status_t status; - zap_log(ZAP_LOG_DEBUG, "got fxo sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got FXO sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_UP: @@ -909,7 +917,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) private_t *tech_pvt = NULL; zap_status_t status = ZAP_SUCCESS; - zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got FXS sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_UP: diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 900c29c9b5..613e1f6e98 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -263,13 +263,13 @@ typedef enum { ZAP_CHANNEL_STATE_CALLWAITING, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_RESTART, - ZAP_CHANNEL_STATE_EARLY_MEDIA, + ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "EARLY_MEDIA", "PROGRESS", "INVALID" + "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index d5b525bcdd..2ba9f8e2fc 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -516,6 +516,18 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + { + switch(state) { + case ZAP_CHANNEL_STATE_PROGRESS: + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + ok = 0; + break; + default: + break; + } + } + break; case ZAP_CHANNEL_STATE_DOWN: { switch(state) { @@ -528,6 +540,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; } } + break; case ZAP_CHANNEL_STATE_BUSY: { switch(state) { @@ -538,6 +551,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; } } + break; default: break; } @@ -771,8 +785,10 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) assert(zchan != NULL); memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); + for (i = 0; i < 2; i++) { if (zchan->fds[i] > -1) { close(zchan->fds[i]); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index ec42c2e43f..dd870087d1 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -110,7 +110,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_ALERTING: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } break; case Q931mes_PROGRESS: @@ -248,7 +248,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_channel_close(&zchan); } break; - case ZAP_CHANNEL_STATE_EARLY_MEDIA: + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; From 058739eed9596266a1589c4daacaf275d4272c4a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 13:46:32 +0000 Subject: [PATCH 0530/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@265 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 24 ++++++++++++++++-------- libs/freetdm/src/include/zap_types.h | 4 ++-- libs/freetdm/src/zap_io.c | 16 ++++++++++++++++ libs/freetdm/src/zap_isdn.c | 4 ++-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ef755a4772..0b07afbe2c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -555,16 +555,24 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } } + break; case SWITCH_MESSAGE_INDICATE_PROGRESS: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } } + break; case SWITCH_MESSAGE_INDICATE_ANSWER: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } } break; default: @@ -877,7 +885,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) switch_channel_t *channel = NULL; zap_status_t status; - zap_log(ZAP_LOG_DEBUG, "got fxo sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got FXO sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_UP: @@ -909,7 +917,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) private_t *tech_pvt = NULL; zap_status_t status = ZAP_SUCCESS; - zap_log(ZAP_LOG_DEBUG, "got fxs sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got FXS sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_UP: diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 900c29c9b5..613e1f6e98 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -263,13 +263,13 @@ typedef enum { ZAP_CHANNEL_STATE_CALLWAITING, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_RESTART, - ZAP_CHANNEL_STATE_EARLY_MEDIA, + ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "EARLY_MEDIA", "PROGRESS", "INVALID" + "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index d5b525bcdd..2ba9f8e2fc 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -516,6 +516,18 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + { + switch(state) { + case ZAP_CHANNEL_STATE_PROGRESS: + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + ok = 0; + break; + default: + break; + } + } + break; case ZAP_CHANNEL_STATE_DOWN: { switch(state) { @@ -528,6 +540,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; } } + break; case ZAP_CHANNEL_STATE_BUSY: { switch(state) { @@ -538,6 +551,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; } } + break; default: break; } @@ -771,8 +785,10 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) assert(zchan != NULL); memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); + for (i = 0; i < 2; i++) { if (zchan->fds[i] > -1) { close(zchan->fds[i]); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index ec42c2e43f..dd870087d1 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -110,7 +110,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_ALERTING: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_EARLY_MEDIA); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } break; case Q931mes_PROGRESS: @@ -248,7 +248,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_channel_close(&zchan); } break; - case ZAP_CHANNEL_STATE_EARLY_MEDIA: + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; From cae2014e7634fb67f5df43ac1cf1a8fe94305306 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 15:52:49 +0000 Subject: [PATCH 0531/1766] pretty damn close to being operational git-svn-id: http://svn.openzap.org/svn/openzap/trunk@266 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- libs/openzap/src/isdn/Q931ie.c | 3 ++- libs/openzap/src/zap_io.c | 13 +++++++++++++ libs/openzap/src/zap_isdn.c | 9 ++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 0b07afbe2c..76436f8fb7 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -318,7 +318,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; case ZAP_CHAN_TYPE_B: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } @@ -977,7 +977,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) while((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); switch_core_session_rwunlock(session); } } diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 9ed580568b..70a7e228e4 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1018,7 +1018,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I pie->Location = IBuf[Octet+Off] & 0x0f; /* Octet 3a */ - if((IBuf[Octet+Off] & 0x80) != 0) + if((IBuf[Octet+Off] & 0x80) == 0) { Off++; pie->Recom = IBuf[Octet+Off] & 0x7f; @@ -1027,6 +1027,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I /* Octet 4 */ pie->Value = IBuf[Octet+Off] & 0x7f; + Octet++; Q931IESizeTest(Q931E_CAUSE); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2ba9f8e2fc..22bd482a9b 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -516,6 +516,19 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } switch(zchan->state) { + case ZAP_CHANNEL_STATE_HANGUP: + case ZAP_CHANNEL_STATE_TERMINATING: + { + ok = 0; + switch(state) { + case ZAP_CHANNEL_STATE_DOWN: + ok = 1; + break; + default: + break; + } + } + break; case ZAP_CHANNEL_STATE_UP: { switch(state) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index dd870087d1..b6f2d27b20 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -105,6 +105,8 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_DISCONNECT: { + Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); + zchan->caller_data.hangup_cause = cause->Value; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } break; @@ -172,8 +174,8 @@ static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret; char bb[4096] = ""; - print_hex_bytes(msg, mlen, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen, LINE, bb); + print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) @@ -342,7 +344,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) #endif CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; - printf("WTF: [%s]\n", zchan->caller_data.ani); CalledNum.Size += strlen(zchan->caller_data.ani); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); @@ -370,6 +371,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_TERMINATING: { + sig.event_id = ZAP_SIGEVENT_STOP; + status = data->sig_cb(&sig); gen->MesType = Q931mes_RELEASE; Q931Rx43(&data->q931, (void *)gen, gen->Size); } From aa53cf7997bb23ba5b238ef3a9c74709a3889f9c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 15:52:49 +0000 Subject: [PATCH 0532/1766] pretty damn close to being operational git-svn-id: http://svn.openzap.org/svn/openzap/trunk@266 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- libs/freetdm/src/isdn/Q931ie.c | 3 ++- libs/freetdm/src/zap_io.c | 13 +++++++++++++ libs/freetdm/src/zap_isdn.c | 9 ++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 0b07afbe2c..76436f8fb7 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -318,7 +318,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; case ZAP_CHAN_TYPE_B: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } @@ -977,7 +977,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) while((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); switch_core_session_rwunlock(session); } } diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 9ed580568b..70a7e228e4 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1018,7 +1018,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I pie->Location = IBuf[Octet+Off] & 0x0f; /* Octet 3a */ - if((IBuf[Octet+Off] & 0x80) != 0) + if((IBuf[Octet+Off] & 0x80) == 0) { Off++; pie->Recom = IBuf[Octet+Off] & 0x7f; @@ -1027,6 +1027,7 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I /* Octet 4 */ pie->Value = IBuf[Octet+Off] & 0x7f; + Octet++; Q931IESizeTest(Q931E_CAUSE); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2ba9f8e2fc..22bd482a9b 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -516,6 +516,19 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } switch(zchan->state) { + case ZAP_CHANNEL_STATE_HANGUP: + case ZAP_CHANNEL_STATE_TERMINATING: + { + ok = 0; + switch(state) { + case ZAP_CHANNEL_STATE_DOWN: + ok = 1; + break; + default: + break; + } + } + break; case ZAP_CHANNEL_STATE_UP: { switch(state) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index dd870087d1..b6f2d27b20 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -105,6 +105,8 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_DISCONNECT: { + Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); + zchan->caller_data.hangup_cause = cause->Value; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } break; @@ -172,8 +174,8 @@ static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret; char bb[4096] = ""; - print_hex_bytes(msg, mlen, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen, LINE, bb); + print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) @@ -342,7 +344,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) #endif CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; - printf("WTF: [%s]\n", zchan->caller_data.ani); CalledNum.Size += strlen(zchan->caller_data.ani); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); @@ -370,6 +371,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_TERMINATING: { + sig.event_id = ZAP_SIGEVENT_STOP; + status = data->sig_cb(&sig); gen->MesType = Q931mes_RELEASE; Q931Rx43(&data->q931, (void *)gen, gen->Size); } From c80c4e3385a6617fd160036ee8d1ca45e151d177 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 16:38:40 +0000 Subject: [PATCH 0533/1766] format git-svn-id: http://svn.openzap.org/svn/openzap/trunk@267 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone_detect.h | 24 +- .../src/include/libteletone_generate.h | 18 +- libs/openzap/src/libteletone_detect.c | 268 +++++++++--------- libs/openzap/src/libteletone_generate.c | 4 +- 4 files changed, 157 insertions(+), 157 deletions(-) diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index 9c18d4b5a1..414bbf2b35 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -54,7 +54,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -80,7 +80,7 @@ * 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 + * 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 @@ -105,9 +105,9 @@ extern "C" { */ #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #ifndef TRUE -#define TRUE (!FALSE) +#define TRUE (!FALSE) #endif #endif @@ -123,13 +123,13 @@ extern "C" { * Frequency tolerance +- 1.5% will detect, +-3.5% will reject */ -#define DTMF_THRESHOLD 8.0e7 -#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ -#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ -#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ -#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ -#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ -#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ +#define DTMF_THRESHOLD 8.0e7 +#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ +#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ +#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ +#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ +#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ +#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define GRID_FACTOR 4 #define BLOCK_LEN 102 #define M_TWO_PI 2.0*M_PI @@ -154,7 +154,7 @@ extern "C" { teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; float energy; - + int current_sample; char digits[TELETONE_MAX_DTMF_DIGITS + 1]; int current_digits; diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index de6697bb29..f303d82004 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -33,7 +33,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -59,7 +59,7 @@ * 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 + * 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 @@ -138,25 +138,25 @@ static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint3 static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex) { - int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; + int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; int16_t sample; - if (pindex >= MAX_PHASE_TONES) { + if (pindex >= MAX_PHASE_TONES) { pindex = 0; } - if (bitmask & SINE_TABLE_MAX) { - sine_index = SINE_TABLE_LEN - sine_index; + if (bitmask & SINE_TABLE_MAX) { + sine_index = SINE_TABLE_LEN - sine_index; } - sample = TELETONE_SINES[sine_index]; + sample = TELETONE_SINES[sine_index]; - if (bitmask & (SINE_TABLE_MAX * 2)) { + if (bitmask & (SINE_TABLE_MAX * 2)) { sample *= -1; } dds->phase_accumulator += dds->phase_rate[pindex]; - return (int16_t) (sample * dds->scale_factor >> 15); + return (int16_t) (sample * dds->scale_factor >> 15); } static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index a1d95abcd4..b5ba7e361d 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -54,7 +54,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -80,7 +80,7 @@ * 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 + * 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 @@ -106,64 +106,64 @@ 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_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; + goertzel_state->v2 = goertzel_state->v3 = 0.0; + goertzel_state->fac = tdesc->fac; } 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 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; - } + int i; + float v1; + + for (i = 0; i < samples; i++) { + v1 = goertzel_state->v2; + goertzel_state->v2 = goertzel_state->v3; + goertzel_state->v3 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; + } } #define teletone_goertzel_result(gs) ((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { - int i; - float theta; + int i; + float theta; - dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; + dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; - for (i = 0; i < GRID_FACTOR; i++) { - theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); - dtmf_detect_row[i].fac = 2.0*cos(theta); + for (i = 0; i < GRID_FACTOR; i++) { + theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); + dtmf_detect_row[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); - dtmf_detect_col[i].fac = 2.0*cos(theta); - - theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); - dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); + theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); + dtmf_detect_col[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); + dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); - dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); - + theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); + dtmf_detect_col_2nd[i].fac = 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]); + 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; + } + 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; } void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) @@ -213,17 +213,17 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; - for (sample = 0; sample < samples; sample = limit) { + for (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); + if ((samples - sample) >= (mt->min_samples - mt->current_sample)) { + limit = sample + (mt->min_samples - mt->current_sample); } else { - limit = samples; + limit = samples; } - for (j = sample; j < limit; j++) { - famp = sample_buffer[j]; + for (j = sample; j < limit; j++) { + famp = sample_buffer[j]; mt->energy += famp*famp; @@ -231,16 +231,16 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, v1 = mt->gs[x].v2; mt->gs[x].v2 = mt->gs[x].v3; mt->gs[x].v3 = 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 = mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp; } } - mt->current_sample += (limit - sample); - if (mt->current_sample < mt->min_samples) { - continue; + mt->current_sample += (limit - sample); + if (mt->current_sample < mt->min_samples) { + continue; } eng_sum = 0; @@ -277,15 +277,15 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } } - /* Reinitialise the detector for the next block */ + /* Reinitialise the detector for the next block */ for(x = 0; 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; - } + mt->current_sample = 0; + } return see_hit; } @@ -295,30 +295,30 @@ 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; + 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); + 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; + limit = samples; } - for (j = sample; j < limit; j++) { + for (j = sample; j < limit; j++) { int x = 0; - famp = sample_buffer[j]; + famp = sample_buffer[j]; dtmf_detect_state->energy += famp*famp; @@ -326,7 +326,7 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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 = 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 = dtmf_detect_state->col_out[x].fac*dtmf_detect_state->col_out[x].v2 - v1 + famp; @@ -334,59 +334,59 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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 = 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 = 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; + 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; + 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 && + } + 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 + 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) { + 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++; @@ -399,26 +399,26 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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->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->current_sample = 0; + } + if ((!dtmf_detect_state->mhit) || (dtmf_detect_state->mhit != hit)) { dtmf_detect_state->mhit = 0; return(0); - } - return (hit); + } + return (hit); } @@ -426,16 +426,16 @@ int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, int max) { - if (max > dtmf_detect_state->current_digits) { - max = dtmf_detect_state->current_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; + 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: diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 2804f0a920..a9060a8149 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -33,7 +33,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -59,7 +59,7 @@ * 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 + * 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 From 759cb3e2d7723cc621a36a82df60305c8bccef88 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 16 Jun 2007 16:38:40 +0000 Subject: [PATCH 0534/1766] format git-svn-id: http://svn.openzap.org/svn/openzap/trunk@267 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone_detect.h | 24 +- .../src/include/libteletone_generate.h | 18 +- libs/freetdm/src/libteletone_detect.c | 268 +++++++++--------- libs/freetdm/src/libteletone_generate.c | 4 +- 4 files changed, 157 insertions(+), 157 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 9c18d4b5a1..414bbf2b35 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -54,7 +54,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -80,7 +80,7 @@ * 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 + * 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 @@ -105,9 +105,9 @@ extern "C" { */ #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #ifndef TRUE -#define TRUE (!FALSE) +#define TRUE (!FALSE) #endif #endif @@ -123,13 +123,13 @@ extern "C" { * Frequency tolerance +- 1.5% will detect, +-3.5% will reject */ -#define DTMF_THRESHOLD 8.0e7 -#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ -#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ -#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ -#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ -#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ -#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ +#define DTMF_THRESHOLD 8.0e7 +#define DTMF_NORMAL_TWIST 6.3 /* 8dB */ +#define DTMF_REVERSE_TWIST 2.5 /* 4dB */ +#define DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ +#define DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ +#define DTMF_2ND_HARMONIC_ROW 2.5 /* 4dB */ +#define DTMF_2ND_HARMONIC_COL 63.1 /* 18dB */ #define GRID_FACTOR 4 #define BLOCK_LEN 102 #define M_TWO_PI 2.0*M_PI @@ -154,7 +154,7 @@ extern "C" { teletone_goertzel_state_t row_out2nd[GRID_FACTOR]; teletone_goertzel_state_t col_out2nd[GRID_FACTOR]; float energy; - + int current_sample; char digits[TELETONE_MAX_DTMF_DIGITS + 1]; int current_digits; diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index de6697bb29..f303d82004 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -33,7 +33,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -59,7 +59,7 @@ * 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 + * 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 @@ -138,25 +138,25 @@ static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint3 static __inline__ int16_t teletone_dds_state_modulate_sample(teletone_dds_state_t *dds, uint32_t pindex) { - int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; + int32_t bitmask = dds->phase_accumulator, sine_index = (bitmask >>= 23) & SINE_TABLE_LEN; int16_t sample; - if (pindex >= MAX_PHASE_TONES) { + if (pindex >= MAX_PHASE_TONES) { pindex = 0; } - if (bitmask & SINE_TABLE_MAX) { - sine_index = SINE_TABLE_LEN - sine_index; + if (bitmask & SINE_TABLE_MAX) { + sine_index = SINE_TABLE_LEN - sine_index; } - sample = TELETONE_SINES[sine_index]; + sample = TELETONE_SINES[sine_index]; - if (bitmask & (SINE_TABLE_MAX * 2)) { + if (bitmask & (SINE_TABLE_MAX * 2)) { sample *= -1; } dds->phase_accumulator += dds->phase_rate[pindex]; - return (int16_t) (sample * dds->scale_factor >> 15); + return (int16_t) (sample * dds->scale_factor >> 15); } static __inline__ void teletone_dds_state_set_tx_level(teletone_dds_state_t *dds, float tx_level) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index a1d95abcd4..b5ba7e361d 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -54,7 +54,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -80,7 +80,7 @@ * 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 + * 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 @@ -106,64 +106,64 @@ 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_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; + goertzel_state->v2 = goertzel_state->v3 = 0.0; + goertzel_state->fac = tdesc->fac; } 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 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; - } + int i; + float v1; + + for (i = 0; i < samples; i++) { + v1 = goertzel_state->v2; + goertzel_state->v2 = goertzel_state->v3; + goertzel_state->v3 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; + } } #define teletone_goertzel_result(gs) ((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { - int i; - float theta; + int i; + float theta; - dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; + dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; - for (i = 0; i < GRID_FACTOR; i++) { - theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); - dtmf_detect_row[i].fac = 2.0*cos(theta); + for (i = 0; i < GRID_FACTOR; i++) { + theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); + dtmf_detect_row[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); - dtmf_detect_col[i].fac = 2.0*cos(theta); - - theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); - dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); + theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); + dtmf_detect_col[i].fac = 2.0*cos(theta); + + theta = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); + dtmf_detect_row_2nd[i].fac = 2.0*cos(theta); - theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); - dtmf_detect_col_2nd[i].fac = 2.0*cos(theta); - + theta = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); + dtmf_detect_col_2nd[i].fac = 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]); + 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; + } + 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; } void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) @@ -213,17 +213,17 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; - for (sample = 0; sample < samples; sample = limit) { + for (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); + if ((samples - sample) >= (mt->min_samples - mt->current_sample)) { + limit = sample + (mt->min_samples - mt->current_sample); } else { - limit = samples; + limit = samples; } - for (j = sample; j < limit; j++) { - famp = sample_buffer[j]; + for (j = sample; j < limit; j++) { + famp = sample_buffer[j]; mt->energy += famp*famp; @@ -231,16 +231,16 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, v1 = mt->gs[x].v2; mt->gs[x].v2 = mt->gs[x].v3; mt->gs[x].v3 = 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 = mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp; } } - mt->current_sample += (limit - sample); - if (mt->current_sample < mt->min_samples) { - continue; + mt->current_sample += (limit - sample); + if (mt->current_sample < mt->min_samples) { + continue; } eng_sum = 0; @@ -277,15 +277,15 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } } - /* Reinitialise the detector for the next block */ + /* Reinitialise the detector for the next block */ for(x = 0; 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; - } + mt->current_sample = 0; + } return see_hit; } @@ -295,30 +295,30 @@ 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; + 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); + 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; + limit = samples; } - for (j = sample; j < limit; j++) { + for (j = sample; j < limit; j++) { int x = 0; - famp = sample_buffer[j]; + famp = sample_buffer[j]; dtmf_detect_state->energy += famp*famp; @@ -326,7 +326,7 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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 = 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 = dtmf_detect_state->col_out[x].fac*dtmf_detect_state->col_out[x].v2 - v1 + famp; @@ -334,59 +334,59 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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 = 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 = 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; + 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; + 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 && + } + 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 + 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) { + 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++; @@ -399,26 +399,26 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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->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->current_sample = 0; + } + if ((!dtmf_detect_state->mhit) || (dtmf_detect_state->mhit != hit)) { dtmf_detect_state->mhit = 0; return(0); - } - return (hit); + } + return (hit); } @@ -426,16 +426,16 @@ int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, int max) { - if (max > dtmf_detect_state->current_digits) { - max = dtmf_detect_state->current_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; + 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: diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 2804f0a920..a9060a8149 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -33,7 +33,7 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this + * as part of the openzap library. Any use or distribution of this * source code outside the scope of the openzap library will nullify the * following license and reinact the MPL 1.1 as stated above. * @@ -59,7 +59,7 @@ * 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 + * 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 From c687dabf772819037219c6de74c605d9ab4595bd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 17 Jun 2007 01:50:33 +0000 Subject: [PATCH 0535/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@268 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_wanpipe.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 6ea3a98b3e..ea34579d78 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -357,12 +357,17 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); -#if 0 - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_KEWL; + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); -#endif + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(chan, &tdm_api); + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -798,6 +803,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { 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; + 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; default: From 9bbdde527bdcb5335d4651873e26eec7f18aafab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 17 Jun 2007 01:50:33 +0000 Subject: [PATCH 0536/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@268 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_wanpipe.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 6ea3a98b3e..ea34579d78 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -357,12 +357,17 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); -#if 0 - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_KEWL; + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); -#endif + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(chan, &tdm_api); + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -798,6 +803,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { 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; + 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; default: From d874cf6cf9bc5758b1233066a72aa717fa89e552 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 17 Jun 2007 05:31:28 +0000 Subject: [PATCH 0537/1766] cleanup testing analog git-svn-id: http://svn.openzap.org/svn/openzap/trunk@269 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 22bd482a9b..019592ad99 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -522,6 +522,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta ok = 0; switch(state) { case ZAP_CHANNEL_STATE_DOWN: + case ZAP_CHANNEL_STATE_BUSY: ok = 1; break; default: @@ -716,8 +717,10 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; - - if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { + + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } @@ -745,7 +748,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t check = &globals.spans[span_id].channels[chan_id]; - if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + if (!zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { goto done; } From 18d09620fe1b24fc83632aaaa4258b79fc7dcb4d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 17 Jun 2007 05:31:28 +0000 Subject: [PATCH 0538/1766] cleanup testing analog git-svn-id: http://svn.openzap.org/svn/openzap/trunk@269 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 22bd482a9b..019592ad99 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -522,6 +522,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta ok = 0; switch(state) { case ZAP_CHANNEL_STATE_DOWN: + case ZAP_CHANNEL_STATE_BUSY: ok = 1; break; default: @@ -716,8 +717,10 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; - - if ((status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { + + assert(zchan != NULL); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } @@ -745,7 +748,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t check = &globals.spans[span_id].channels[chan_id]; - if ((status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + if (!zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { goto done; } From eb6c0351e4cdcfc488bc390c90a07d7915385e6a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 17 Jun 2007 19:40:35 +0000 Subject: [PATCH 0539/1766] windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@270 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 +- libs/openzap/src/libteletone_detect.c | 38 +++++++++++++-------------- libs/openzap/src/zap_io.c | 2 +- libs/openzap/src/zap_isdn.c | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index c95849df43..afbf11fbc9 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -482,7 +482,7 @@ void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); -void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen); +void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index b5ba7e361d..7a3bf0d406 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -126,11 +126,11 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, for (i = 0; i < samples; i++) { v1 = goertzel_state->v2; goertzel_state->v2 = goertzel_state->v3; - goertzel_state->v3 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; + goertzel_state->v3 = (float)(goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]); } } -#define teletone_goertzel_result(gs) ((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac) +#define teletone_goertzel_result(gs) (float)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { @@ -140,17 +140,17 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; for (i = 0; i < GRID_FACTOR; i++) { - theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); - dtmf_detect_row[i].fac = 2.0*cos(theta); + theta = (float)(M_TWO_PI*(dtmf_row[i]/(float)sample_rate)); + dtmf_detect_row[i].fac = (float)(2.0*cos(theta)); - theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); - dtmf_detect_col[i].fac = 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 = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); - dtmf_detect_row_2nd[i].fac = 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 = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); - dtmf_detect_col_2nd[i].fac = 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]); @@ -196,8 +196,8 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma break; } mt->tone_count++; - theta = M_TWO_PI*(map->freqs[x]/(float)mt->sample_rate); - mt->tdd[x].fac = 2.0 * cos(theta); + 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]); } @@ -230,11 +230,11 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, for(x = 0; x < mt->tone_count; x++) { v1 = mt->gs[x].v2; mt->gs[x].v2 = mt->gs[x].v3; - mt->gs[x].v3 = mt->gs[x].fac * mt->gs[x].v2 - v1 + famp; + 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 = mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp; + mt->gs2[x].v3 = (float)(mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp); } } @@ -245,7 +245,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, eng_sum = 0; for(x = 0; x < mt->tone_count; x++) { - eng_all[x] = teletone_goertzel_result (&mt->gs[x]); + eng_all[x] = (float)(teletone_goertzel_result (&mt->gs[x])); eng_sum += eng_all[x]; } @@ -325,19 +325,19 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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 = dtmf_detect_state->row_out[x].fac*dtmf_detect_state->row_out[x].v2 - v1 + famp; + 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 = dtmf_detect_state->col_out[x].fac*dtmf_detect_state->col_out[x].v2 - v1 + famp; + 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 = dtmf_detect_state->col_out2nd[x].fac*dtmf_detect_state->col_out2nd[x].v2 - v1 + famp; + 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 = dtmf_detect_state->row_out2nd[x].fac*dtmf_detect_state->row_out2nd[x].v2 - v1 + famp; + dtmf_detect_state->row_out2nd[x].v3 = (float)(dtmf_detect_state->row_out2nd[x].fac*dtmf_detect_state->row_out2nd[x].v2 - v1 + famp); } } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 019592ad99..2545e70724 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2007,7 +2007,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) return bit; } -void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen) +void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) { char *bp = buf; uint8_t *byte = data; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index b6f2d27b20..2424314b1c 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -344,7 +344,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) #endif CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; - CalledNum.Size += strlen(zchan->caller_data.ani); + CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); From 1795451255fc3d3ac683a4da43fd2ed3cc4fd461 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 17 Jun 2007 19:40:35 +0000 Subject: [PATCH 0540/1766] windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@270 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 +- libs/freetdm/src/libteletone_detect.c | 38 +++++++++++++-------------- libs/freetdm/src/zap_io.c | 2 +- libs/freetdm/src/zap_isdn.c | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index c95849df43..afbf11fbc9 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -482,7 +482,7 @@ void zap_global_set_logger(zap_logger_t logger); void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); -void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen); +void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index b5ba7e361d..7a3bf0d406 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -126,11 +126,11 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, for (i = 0; i < samples; i++) { v1 = goertzel_state->v2; goertzel_state->v2 = goertzel_state->v3; - goertzel_state->v3 = goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]; + goertzel_state->v3 = (float)(goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]); } } -#define teletone_goertzel_result(gs) ((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac) +#define teletone_goertzel_result(gs) (float)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { @@ -140,17 +140,17 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, dtmf_detect_state->hit1 = dtmf_detect_state->hit2 = 0; for (i = 0; i < GRID_FACTOR; i++) { - theta = M_TWO_PI*(dtmf_row[i]/(float)sample_rate); - dtmf_detect_row[i].fac = 2.0*cos(theta); + theta = (float)(M_TWO_PI*(dtmf_row[i]/(float)sample_rate)); + dtmf_detect_row[i].fac = (float)(2.0*cos(theta)); - theta = M_TWO_PI*(dtmf_col[i]/(float)sample_rate); - dtmf_detect_col[i].fac = 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 = M_TWO_PI*(dtmf_row[i]*2.0/(float)sample_rate); - dtmf_detect_row_2nd[i].fac = 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 = M_TWO_PI*(dtmf_col[i]*2.0/(float)sample_rate); - dtmf_detect_col_2nd[i].fac = 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]); @@ -196,8 +196,8 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma break; } mt->tone_count++; - theta = M_TWO_PI*(map->freqs[x]/(float)mt->sample_rate); - mt->tdd[x].fac = 2.0 * cos(theta); + 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]); } @@ -230,11 +230,11 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, for(x = 0; x < mt->tone_count; x++) { v1 = mt->gs[x].v2; mt->gs[x].v2 = mt->gs[x].v3; - mt->gs[x].v3 = mt->gs[x].fac * mt->gs[x].v2 - v1 + famp; + 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 = mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp; + mt->gs2[x].v3 = (float)(mt->gs2[x].fac*mt->gs2[x].v2 - v1 + famp); } } @@ -245,7 +245,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, eng_sum = 0; for(x = 0; x < mt->tone_count; x++) { - eng_all[x] = teletone_goertzel_result (&mt->gs[x]); + eng_all[x] = (float)(teletone_goertzel_result (&mt->gs[x])); eng_sum += eng_all[x]; } @@ -325,19 +325,19 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, 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 = dtmf_detect_state->row_out[x].fac*dtmf_detect_state->row_out[x].v2 - v1 + famp; + 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 = dtmf_detect_state->col_out[x].fac*dtmf_detect_state->col_out[x].v2 - v1 + famp; + 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 = dtmf_detect_state->col_out2nd[x].fac*dtmf_detect_state->col_out2nd[x].v2 - v1 + famp; + 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 = dtmf_detect_state->row_out2nd[x].fac*dtmf_detect_state->row_out2nd[x].v2 - v1 + famp; + dtmf_detect_state->row_out2nd[x].v3 = (float)(dtmf_detect_state->row_out2nd[x].fac*dtmf_detect_state->row_out2nd[x].v2 - v1 + famp); } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 019592ad99..2545e70724 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2007,7 +2007,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) return bit; } -void print_hex_bytes(uint8_t *data, zap_size_t dlen, uint8_t *buf, zap_size_t blen) +void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) { char *bp = buf; uint8_t *byte = data; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index b6f2d27b20..2424314b1c 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -344,7 +344,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) #endif CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; - CalledNum.Size += strlen(zchan->caller_data.ani); + CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); From 4ccb5098a00274328d2c2a6e71f4ef41f7c9e20d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Jun 2007 20:37:07 +0000 Subject: [PATCH 0541/1766] add a couple missing structs for config. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@271 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 9f3287f6a4..1920364e74 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -110,6 +110,26 @@ 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 */ +} /* Enumerations */ From 846175f898f818953bc4b59dde25f1905dfd6188 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Jun 2007 20:37:07 +0000 Subject: [PATCH 0542/1766] add a couple missing structs for config. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@271 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 9f3287f6a4..1920364e74 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -110,6 +110,26 @@ 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 */ +} /* Enumerations */ From 4943cb46637168895a57a35d31e816edd7531c06 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Jun 2007 21:15:17 +0000 Subject: [PATCH 0543/1766] add signaling types. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@272 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 1920364e74..d26a9813b8 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -197,6 +197,19 @@ typedef enum { 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_sigtype_t; + /* Defines */ From 93b8880e1eb57ceeb5596a935f62bdcb8f5d2583 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Jun 2007 21:15:17 +0000 Subject: [PATCH 0544/1766] add signaling types. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@272 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 1920364e74..d26a9813b8 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -197,6 +197,19 @@ typedef enum { 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_sigtype_t; + /* Defines */ From 7321b86adf4166343bcc2cf04c5d2c56dc5e4b58 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Jun 2007 21:32:56 +0000 Subject: [PATCH 0545/1766] update analog git-svn-id: http://svn.openzap.org/svn/openzap/trunk@273 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_types.h | 9 ++++ libs/openzap/src/include/zap_zt.h | 43 +++++++++---------- libs/openzap/src/zap_analog.c | 2 +- libs/openzap/src/zap_io.c | 39 ++++++++++++++--- libs/openzap/src/zap_wanpipe.c | 2 + libs/openzap/src/zap_zt.c | 62 ++++++++++++++++++++++++++++ 7 files changed, 131 insertions(+), 27 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index afbf11fbc9..4bf1979e46 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -386,6 +386,7 @@ struct zap_span { zio_event_cb_t event_callback; zap_mutex_t *mutex; zap_trunk_type_t trunk_type; + zap_analog_start_type_t start_type; zap_signal_type_t signal_type; struct zap_isdn_data *isdn_data; struct zap_analog_data *analog_data; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 613e1f6e98..1e27cf9a80 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -119,6 +119,15 @@ typedef enum { #define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "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_INVALID +} zap_analog_start_type_t; +#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "INVALID" +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, diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index d26a9813b8..35d9cd8d23 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -110,26 +110,26 @@ 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_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 */ +}; /* Enumerations */ @@ -238,7 +238,8 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #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_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 */ diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 91f982a2f4..672885ecee 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -44,6 +44,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); 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; @@ -424,7 +425,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GENRING: { send_caller_id(chan); - //zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2545e70724..8009cf536d 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -95,6 +95,9 @@ ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAME ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) +ZAP_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS) +ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_INVALID) + ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) @@ -1719,10 +1722,23 @@ static zap_status_t load_config(void) } else { zap_copy_string(number, val, sizeof(number)); } - } else if (!strcasecmp(var, "fxo-channel")) { + } else if (!strncasecmp(var, "fxo-channel", 11)) { if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXO; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + char *stype = var + 11; + zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; + + span->trunk_type = ZAP_TRUNK_FXO; + if (stype) { + while(*stype == '-') stype++; + if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { + start_type = tmp; + } + + } + + span->start_type = start_type; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(start_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); @@ -1731,8 +1747,21 @@ static zap_status_t load_config(void) } } else if (!strcasecmp(var, "fxs-channel")) { if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXS; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + char *stype = var + 11; + zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; + + span->trunk_type = ZAP_TRUNK_FXS; + if (stype) { + while(*stype == '-') stype++; + if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { + start_type = tmp; + } + + } + + span->start_type = start_type; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(start_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index ea34579d78..229cd600f0 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -801,12 +801,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) break; case WP_TDMAPI_EVENT_RING_DETECT: { + printf("you fucking suck: ring\n"); 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; case WP_TDMAPI_EVENT_RING_TRIP_DETECT: { + printf("you fucking suck: trip\n"); 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; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 90f310fc92..3461721440 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -48,8 +48,16 @@ static struct { static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) { unsigned configured = 0, x; + const char ctlpath[] = "/dev/zap/ctl"; char path[128] = ""; zt_params_t ztp; + zap_socket_t ctlfd = ZT_INVALID_SOCKET; + + + if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { + zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); + return 0; + } memset(&ztp, 0, sizeof(ztp)); @@ -62,6 +70,56 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + 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(ctlfd, ZT_CHANCONFIG, &cc)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", + path, x, ctlfd, strerror(errno)); + close(sockfd); + break; + } + } + len = zt_globals.eclevel; if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", @@ -92,6 +150,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + + chan->rate = 8000; chan->physical_span_id = ztp.span_no; chan->physical_chan_id = ztp.chan_no; @@ -125,6 +185,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } + close(ctlfd); + return configured; } From 441b487329920a0c5d964afdcd8120d74da3061e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Jun 2007 21:32:56 +0000 Subject: [PATCH 0546/1766] update analog git-svn-id: http://svn.openzap.org/svn/openzap/trunk@273 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 9 ++++ libs/freetdm/src/include/zap_zt.h | 43 +++++++++---------- libs/freetdm/src/zap_analog.c | 2 +- libs/freetdm/src/zap_io.c | 39 ++++++++++++++--- libs/freetdm/src/zap_wanpipe.c | 2 + libs/freetdm/src/zap_zt.c | 62 ++++++++++++++++++++++++++++ 7 files changed, 131 insertions(+), 27 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index afbf11fbc9..4bf1979e46 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -386,6 +386,7 @@ struct zap_span { zio_event_cb_t event_callback; zap_mutex_t *mutex; zap_trunk_type_t trunk_type; + zap_analog_start_type_t start_type; zap_signal_type_t signal_type; struct zap_isdn_data *isdn_data; struct zap_analog_data *analog_data; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 613e1f6e98..1e27cf9a80 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -119,6 +119,15 @@ typedef enum { #define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "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_INVALID +} zap_analog_start_type_t; +#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "INVALID" +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, diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index d26a9813b8..35d9cd8d23 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -110,26 +110,26 @@ 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_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 */ +}; /* Enumerations */ @@ -238,7 +238,8 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #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_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 */ diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 91f982a2f4..672885ecee 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -44,6 +44,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); 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; @@ -424,7 +425,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GENRING: { send_caller_id(chan); - //zap_channel_command(chan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2545e70724..8009cf536d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -95,6 +95,9 @@ ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAME ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) +ZAP_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS) +ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_INVALID) + ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) @@ -1719,10 +1722,23 @@ static zap_status_t load_config(void) } else { zap_copy_string(number, val, sizeof(number)); } - } else if (!strcasecmp(var, "fxo-channel")) { + } else if (!strncasecmp(var, "fxo-channel", 11)) { if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXO; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + char *stype = var + 11; + zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; + + span->trunk_type = ZAP_TRUNK_FXO; + if (stype) { + while(*stype == '-') stype++; + if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { + start_type = tmp; + } + + } + + span->start_type = start_type; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(start_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); @@ -1731,8 +1747,21 @@ static zap_status_t load_config(void) } } else if (!strcasecmp(var, "fxs-channel")) { if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXS; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); + char *stype = var + 11; + zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; + + span->trunk_type = ZAP_TRUNK_FXS; + if (stype) { + while(*stype == '-') stype++; + if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { + start_type = tmp; + } + + } + + span->start_type = start_type; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(start_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index ea34579d78..229cd600f0 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -801,12 +801,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) break; case WP_TDMAPI_EVENT_RING_DETECT: { + printf("you fucking suck: ring\n"); 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; case WP_TDMAPI_EVENT_RING_TRIP_DETECT: { + printf("you fucking suck: trip\n"); 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; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 90f310fc92..3461721440 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -48,8 +48,16 @@ static struct { static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) { unsigned configured = 0, x; + const char ctlpath[] = "/dev/zap/ctl"; char path[128] = ""; zt_params_t ztp; + zap_socket_t ctlfd = ZT_INVALID_SOCKET; + + + if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { + zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); + return 0; + } memset(&ztp, 0, sizeof(ztp)); @@ -62,6 +70,56 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + 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(ctlfd, ZT_CHANCONFIG, &cc)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", + path, x, ctlfd, strerror(errno)); + close(sockfd); + break; + } + } + len = zt_globals.eclevel; if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", @@ -92,6 +150,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + + chan->rate = 8000; chan->physical_span_id = ztp.span_no; chan->physical_chan_id = ztp.chan_no; @@ -125,6 +185,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } + close(ctlfd); + return configured; } From b4d6035c852d4f990a1daa8aa164c389c586a85b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 02:54:29 +0000 Subject: [PATCH 0547/1766] sangoma api probably working git-svn-id: http://svn.openzap.org/svn/openzap/trunk@274 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 14 +++ libs/openzap/src/include/zap_types.h | 17 +-- libs/openzap/src/zap_analog.c | 26 +++-- libs/openzap/src/zap_io.c | 50 +++------ libs/openzap/src/zap_wanpipe.c | 159 ++++++++++++++++++++------- 5 files changed, 180 insertions(+), 86 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4bf1979e46..cd3c3f920c 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -172,6 +172,7 @@ \return true value if the object has the flags defined */ #define zap_test_flag(obj, flag) ((obj)->flags & flag) +#define zap_test_pflag(obj, flag) ((obj)->pflags & flag) /*! \brief Set a flag on an arbitrary object @@ -184,6 +185,12 @@ (obj)->flags |= (flag); \ zap_mutex_unlock(obj->mutex); +#define zap_set_pflag(obj, flag) (obj)->pflags |= (flag) +#define zap_set_pflag_locked(obj, flag) assert(obj->mutex != NULL); \ + zap_mutex_lock(obj->mutex); \ + (obj)->pflags |= (flag); \ + zap_mutex_unlock(obj->mutex); + /*! \brief Clear a flag on an arbitrary object while locked \command obj the object to test @@ -193,6 +200,11 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); +#define zap_clear_pflag(obj, flag) (obj)->pflags &= ~(flag) + +#define zap_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); zap_mutex_unlock(obj->mutex); + + #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ @@ -311,6 +323,7 @@ struct zap_channel { zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; + uint32_t pflags; zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; @@ -334,6 +347,7 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; + zap_time_t ring_time; char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; uint8_t needed_tones[ZAP_TONEMAP_INVALID]; uint8_t detected_tones[ZAP_TONEMAP_INVALID]; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1e27cf9a80..b517aeacd8 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -123,9 +123,9 @@ typedef enum { ZAP_ANALOG_START_KEWL, ZAP_ANALOG_START_LOOP, ZAP_ANALOG_START_GROUND, - ZAP_ANALOG_START_INVALID + ZAP_ANALOG_START_NA } zap_analog_start_type_t; -#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "INVALID" +#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "NA" ZAP_STR2ENUM_P(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t) typedef enum { @@ -136,9 +136,10 @@ typedef enum { ZAP_OOB_FLASH, ZAP_OOB_RING_START, ZAP_OOB_RING_STOP, + ZAP_OOB_NOOP, ZAP_OOB_INVALID } zap_oob_event_t; -#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "INVALID" +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "NOOP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t) typedef enum { @@ -257,7 +258,6 @@ typedef enum { typedef enum { ZAP_CHANNEL_STATE_DOWN, - ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HOLD, ZAP_CHANNEL_STATE_DIALTONE, @@ -265,7 +265,6 @@ typedef enum { ZAP_CHANNEL_STATE_RING, ZAP_CHANNEL_STATE_BUSY, ZAP_CHANNEL_STATE_ATTN, - ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, @@ -274,11 +273,13 @@ typedef enum { ZAP_CHANNEL_STATE_RESTART, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, + ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ + "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ + "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "IDLE", "UP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 672885ecee..fb38b6c27a 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -277,7 +277,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 500) { - if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK) && chan->state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } else { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); @@ -663,14 +663,23 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) break; case ZAP_OOB_OFFHOOK: { - if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - if (event->channel->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) { - zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + 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 { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + zap_thread_create_detached(zap_analog_channel_run, event->channel); } - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - zap_thread_create_detached(zap_analog_channel_run, event->channel); + 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); } } } @@ -697,6 +706,9 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) { zap_event_t *event; while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { + if (event->e_type == ZAP_OOB_NOOP) { + continue; + } if (process_event(span, event) != ZAP_SUCCESS) { goto end; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8009cf536d..083ded5d96 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -96,7 +96,7 @@ ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) ZAP_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS) -ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_INVALID) +ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_NA) ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) @@ -1660,6 +1660,7 @@ static zap_status_t load_config(void) char name[80] = ""; char number[25] = ""; zap_io_interface_t *zio = NULL; + zap_analog_start_type_t tmp; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; @@ -1722,23 +1723,20 @@ static zap_status_t load_config(void) } else { zap_copy_string(number, val, sizeof(number)); } - } else if (!strncasecmp(var, "fxo-channel", 11)) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - char *stype = var + 11; - zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; - - span->trunk_type = ZAP_TRUNK_FXO; - if (stype) { - while(*stype == '-') stype++; - if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { - start_type = tmp; - } - + } else if (!strcasecmp(var, "analog-start-type")) { + if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO) { + if ((tmp = zap_str2zap_analog_start_type(val)) != ZAP_ANALOG_START_NA) { + span->start_type = tmp; + zap_log(ZAP_LOG_DEBUG, "changing start type to '%s'\n", zap_analog_start_type2str(span->start_type)); } - - span->start_type = start_type; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(start_type)); + } else { + zap_log(ZAP_LOG_ERROR, "This option is only valid on analog trunks!\n"); + } + } else if (!strcasecmp(var, "fxo-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXO; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); @@ -1747,21 +1745,9 @@ static zap_status_t load_config(void) } } else if (!strcasecmp(var, "fxs-channel")) { if (span->trunk_type == ZAP_TRUNK_NONE) { - char *stype = var + 11; - zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; - - span->trunk_type = ZAP_TRUNK_FXS; - if (stype) { - while(*stype == '-') stype++; - if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { - start_type = tmp; - } - - } - - span->start_type = start_type; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(start_type)); + span->trunk_type = ZAP_TRUNK_FXS; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 229cd600f0..3e52568fb1 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -37,10 +37,16 @@ #include #include +typedef enum { + WP_RINGING = (1 << 0) +} wp_flag_t; + 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 */ @@ -353,21 +359,32 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; +#if 1 + if (type == ZAP_CHAN_TYPE_FXO) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(chan, &tdm_api); + } +#endif + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - +#if 1 tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - +#endif tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -530,8 +547,9 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) switch(command) { case ZAP_COMMAND_OFFHOOK: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = zchan->span->start_type == ZAP_ANALOG_START_KEWL ? + WP_TDMAPI_EVENT_TXSIG_START : WP_TDMAPI_EVENT_TXSIG_KEWL; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); @@ -542,9 +560,9 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_ONHOOK: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_DISABLE; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); return ZAP_FAIL; @@ -554,7 +572,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GENERATE_RING_ON: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { @@ -562,13 +580,15 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_ENABLE; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); return ZAP_FAIL; @@ -698,17 +718,53 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) int r; for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = &span->channels[i]; memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i].sockfd; pfds[j].events = POLLPRI; - if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_WINK) || zap_test_flag((&span->channels[i]), ZAP_CHANNEL_FLASH)) { - l++; + + /* 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)) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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 { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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 = 5; + ms = l; } r = poll(pfds, j, ms); @@ -721,13 +777,17 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = &span->channels[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(); + zap_set_flag(zchan, ZAP_CHANNEL_EVENT); + zchan->last_event_time = zap_current_time_in_ms(); k++; } } + + return k ? ZAP_SUCCESS : ZAP_FAIL; } @@ -758,12 +818,22 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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) { + wanpipe_tdm_api_t tdm_api; + memset(&tdm_api, 0, sizeof(tdm_api)); + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + } goto event; } } } if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { wanpipe_tdm_api_t tdm_api; + memset(&tdm_api, 0, sizeof(tdm_api)); zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; @@ -775,42 +845,50 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { case WP_TDMAPI_EVENT_RXHOOK: { - 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; + 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 { - zap_set_flag_locked((&span->channels[i]), ZAP_CHANNEL_WINK); - } + 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 { - 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); + int err; + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(&span->channels[i], &tdm_api))) { + 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; } - continue; } break; case WP_TDMAPI_EVENT_RING_DETECT: { - printf("you fucking suck: ring\n"); - 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; - + 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; case WP_TDMAPI_EVENT_RING_TRIP_DETECT: { - printf("you fucking suck: trip\n"); - 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; - + 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; default: @@ -822,6 +900,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } event: + span->channels[i].last_event_time = 0; span->event_header.e_type = ZAP_EVENT_OOB; span->event_header.enum_id = event_id; @@ -853,6 +932,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) 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; From 5b432cdb8a53cac4c1e85daec0d9b7bacaa38237 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 02:54:29 +0000 Subject: [PATCH 0548/1766] sangoma api probably working git-svn-id: http://svn.openzap.org/svn/openzap/trunk@274 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 14 +++ libs/freetdm/src/include/zap_types.h | 17 +-- libs/freetdm/src/zap_analog.c | 26 +++-- libs/freetdm/src/zap_io.c | 50 +++------ libs/freetdm/src/zap_wanpipe.c | 159 ++++++++++++++++++++------- 5 files changed, 180 insertions(+), 86 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4bf1979e46..cd3c3f920c 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -172,6 +172,7 @@ \return true value if the object has the flags defined */ #define zap_test_flag(obj, flag) ((obj)->flags & flag) +#define zap_test_pflag(obj, flag) ((obj)->pflags & flag) /*! \brief Set a flag on an arbitrary object @@ -184,6 +185,12 @@ (obj)->flags |= (flag); \ zap_mutex_unlock(obj->mutex); +#define zap_set_pflag(obj, flag) (obj)->pflags |= (flag) +#define zap_set_pflag_locked(obj, flag) assert(obj->mutex != NULL); \ + zap_mutex_lock(obj->mutex); \ + (obj)->pflags |= (flag); \ + zap_mutex_unlock(obj->mutex); + /*! \brief Clear a flag on an arbitrary object while locked \command obj the object to test @@ -193,6 +200,11 @@ #define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); +#define zap_clear_pflag(obj, flag) (obj)->pflags &= ~(flag) + +#define zap_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); zap_mutex_unlock(obj->mutex); + + #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ @@ -311,6 +323,7 @@ struct zap_channel { zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; + uint32_t pflags; zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; @@ -334,6 +347,7 @@ struct zap_channel { uint32_t dtmf_off; teletone_generation_session_t tone_session; zap_time_t last_event_time; + zap_time_t ring_time; char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; uint8_t needed_tones[ZAP_TONEMAP_INVALID]; uint8_t detected_tones[ZAP_TONEMAP_INVALID]; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 1e27cf9a80..b517aeacd8 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -123,9 +123,9 @@ typedef enum { ZAP_ANALOG_START_KEWL, ZAP_ANALOG_START_LOOP, ZAP_ANALOG_START_GROUND, - ZAP_ANALOG_START_INVALID + ZAP_ANALOG_START_NA } zap_analog_start_type_t; -#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "INVALID" +#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "NA" ZAP_STR2ENUM_P(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t) typedef enum { @@ -136,9 +136,10 @@ typedef enum { ZAP_OOB_FLASH, ZAP_OOB_RING_START, ZAP_OOB_RING_STOP, + ZAP_OOB_NOOP, ZAP_OOB_INVALID } zap_oob_event_t; -#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "INVALID" +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "NOOP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t) typedef enum { @@ -257,7 +258,6 @@ typedef enum { typedef enum { ZAP_CHANNEL_STATE_DOWN, - ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HOLD, ZAP_CHANNEL_STATE_DIALTONE, @@ -265,7 +265,6 @@ typedef enum { ZAP_CHANNEL_STATE_RING, ZAP_CHANNEL_STATE_BUSY, ZAP_CHANNEL_STATE_ATTN, - ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_GENRING, ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, @@ -274,11 +273,13 @@ typedef enum { ZAP_CHANNEL_STATE_RESTART, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, + ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "UP", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "IDLE", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "INVALID" +#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ + "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ + "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "IDLE", "UP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 672885ecee..fb38b6c27a 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -277,7 +277,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 500) { - if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { + if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK) && chan->state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); } else { zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); @@ -663,14 +663,23 @@ static zap_status_t process_event(zap_span_t *span, zap_event_t *event) break; case ZAP_OOB_OFFHOOK: { - if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - if (event->channel->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) { - zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + 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 { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + zap_thread_create_detached(zap_analog_channel_run, event->channel); } - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - zap_thread_create_detached(zap_analog_channel_run, event->channel); + 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); } } } @@ -697,6 +706,9 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) { zap_event_t *event; while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { + if (event->e_type == ZAP_OOB_NOOP) { + continue; + } if (process_event(span, event) != ZAP_SUCCESS) { goto end; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8009cf536d..083ded5d96 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -96,7 +96,7 @@ ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) ZAP_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS) -ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_INVALID) +ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_NA) ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) @@ -1660,6 +1660,7 @@ static zap_status_t load_config(void) char name[80] = ""; char number[25] = ""; zap_io_interface_t *zio = NULL; + zap_analog_start_type_t tmp; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; @@ -1722,23 +1723,20 @@ static zap_status_t load_config(void) } else { zap_copy_string(number, val, sizeof(number)); } - } else if (!strncasecmp(var, "fxo-channel", 11)) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - char *stype = var + 11; - zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; - - span->trunk_type = ZAP_TRUNK_FXO; - if (stype) { - while(*stype == '-') stype++; - if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { - start_type = tmp; - } - + } else if (!strcasecmp(var, "analog-start-type")) { + if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO) { + if ((tmp = zap_str2zap_analog_start_type(val)) != ZAP_ANALOG_START_NA) { + span->start_type = tmp; + zap_log(ZAP_LOG_DEBUG, "changing start type to '%s'\n", zap_analog_start_type2str(span->start_type)); } - - span->start_type = start_type; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(start_type)); + } else { + zap_log(ZAP_LOG_ERROR, "This option is only valid on analog trunks!\n"); + } + } else if (!strcasecmp(var, "fxo-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_FXO; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); @@ -1747,21 +1745,9 @@ static zap_status_t load_config(void) } } else if (!strcasecmp(var, "fxs-channel")) { if (span->trunk_type == ZAP_TRUNK_NONE) { - char *stype = var + 11; - zap_analog_start_type_t tmp, start_type = ZAP_ANALOG_START_KEWL; - - span->trunk_type = ZAP_TRUNK_FXS; - if (stype) { - while(*stype == '-') stype++; - if ((tmp = zap_str2zap_analog_start_type(stype)) != ZAP_ANALOG_START_INVALID) { - start_type = tmp; - } - - } - - span->start_type = start_type; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' (%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(start_type)); + span->trunk_type = ZAP_TRUNK_FXS; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 229cd600f0..3e52568fb1 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -37,10 +37,16 @@ #include #include +typedef enum { + WP_RINGING = (1 << 0) +} wp_flag_t; + 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 */ @@ -353,21 +359,32 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; +#if 1 + if (type == ZAP_CHAN_TYPE_FXO) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(chan, &tdm_api); + } +#endif + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - +#if 1 tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); - +#endif tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -530,8 +547,9 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) switch(command) { case ZAP_COMMAND_OFFHOOK: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = zchan->span->start_type == ZAP_ANALOG_START_KEWL ? + WP_TDMAPI_EVENT_TXSIG_START : WP_TDMAPI_EVENT_TXSIG_KEWL; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); @@ -542,9 +560,9 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_ONHOOK: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_DISABLE; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); return ZAP_FAIL; @@ -554,7 +572,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GENERATE_RING_ON: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { @@ -562,13 +580,15 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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: { - tdm_api.wp_tdm_cmd.cmd=SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode=WP_TDMAPI_EVENT_ENABLE; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); return ZAP_FAIL; @@ -698,17 +718,53 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) int r; for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = &span->channels[i]; memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i].sockfd; pfds[j].events = POLLPRI; - if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_WINK) || zap_test_flag((&span->channels[i]), ZAP_CHANNEL_FLASH)) { - l++; + + /* 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)) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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 { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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 = 5; + ms = l; } r = poll(pfds, j, ms); @@ -721,13 +777,17 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = &span->channels[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(); + zap_set_flag(zchan, ZAP_CHANNEL_EVENT); + zchan->last_event_time = zap_current_time_in_ms(); k++; } } + + return k ? ZAP_SUCCESS : ZAP_FAIL; } @@ -758,12 +818,22 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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) { + wanpipe_tdm_api_t tdm_api; + memset(&tdm_api, 0, sizeof(tdm_api)); + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + } goto event; } } } if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { wanpipe_tdm_api_t tdm_api; + memset(&tdm_api, 0, sizeof(tdm_api)); zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; @@ -775,42 +845,50 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { case WP_TDMAPI_EVENT_RXHOOK: { - 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; + 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 { - zap_set_flag_locked((&span->channels[i]), ZAP_CHANNEL_WINK); - } + 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 { - 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); + int err; + + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + if ((err = wp_tdm_cmd_exec(&span->channels[i], &tdm_api))) { + 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; } - continue; } break; case WP_TDMAPI_EVENT_RING_DETECT: { - printf("you fucking suck: ring\n"); - 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; - + 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; case WP_TDMAPI_EVENT_RING_TRIP_DETECT: { - printf("you fucking suck: trip\n"); - 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; - + 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; default: @@ -822,6 +900,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } event: + span->channels[i].last_event_time = 0; span->event_header.e_type = ZAP_EVENT_OOB; span->event_header.enum_id = event_id; @@ -853,6 +932,8 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) 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; From 25861c506eddc35e93dadcb5dc5c8039497285bc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 20 Jun 2007 09:27:28 +0000 Subject: [PATCH 0549/1766] fix build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@275 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 +--- libs/openzap/src/include/zap_zt.h | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 76436f8fb7..91d807120a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -914,7 +914,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; zap_status_t status = ZAP_SUCCESS; zap_log(ZAP_LOG_DEBUG, "got FXS sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -962,7 +961,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_status_t status; zap_log(ZAP_LOG_DEBUG, "got ISDN sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -1046,7 +1044,7 @@ static void zap_logger(char *file, const char *func, int line, int level, char * va_start(ap, fmt); if (switch_vasprintf(&data, fmt, ap) != -1) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, data); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, data); free(data); } diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 35d9cd8d23..031a80d059 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -198,18 +198,18 @@ typedef enum { } 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 */ +/* 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_sigtype_t; - + /* Defines */ From 99b76622ba402de5f9dbbcadc2ad6569c66224db Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 20 Jun 2007 09:27:28 +0000 Subject: [PATCH 0550/1766] fix build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@275 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 +--- libs/freetdm/src/include/zap_zt.h | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 76436f8fb7..91d807120a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -914,7 +914,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; zap_status_t status = ZAP_SUCCESS; zap_log(ZAP_LOG_DEBUG, "got FXS sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -962,7 +961,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_status_t status; zap_log(ZAP_LOG_DEBUG, "got ISDN sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); @@ -1046,7 +1044,7 @@ static void zap_logger(char *file, const char *func, int line, int level, char * va_start(ap, fmt); if (switch_vasprintf(&data, fmt, ap) != -1) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level, data); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, data); free(data); } diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 35d9cd8d23..031a80d059 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -198,18 +198,18 @@ typedef enum { } 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 */ +/* 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_sigtype_t; - + /* Defines */ From d71231f075e98a609e25feb621615e7733a224d3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 20 Jun 2007 17:20:56 +0000 Subject: [PATCH 0551/1766] add bufinfo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@276 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 031a80d059..897e92e0c5 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -131,6 +131,16 @@ struct zt_chanconfig { 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 */ @@ -238,8 +248,10 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #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_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 */ From 576766cbffff1dc219f762d9d0f7fa220cf3779f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 20 Jun 2007 17:20:56 +0000 Subject: [PATCH 0552/1766] add bufinfo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@276 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 031a80d059..897e92e0c5 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -131,6 +131,16 @@ struct zt_chanconfig { 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 */ @@ -238,8 +248,10 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #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_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 */ From c406e3eadc5d07c5441462a58efc211c0be4337c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 17:53:09 +0000 Subject: [PATCH 0553/1766] tmp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@277 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 18 ++++---- libs/openzap/src/zap_io.c | 1 + libs/openzap/src/zap_isdn.c | 12 ++--- libs/openzap/src/zap_zt.c | 76 ++++++++++++++++++++++--------- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 897e92e0c5..b972e4ff1d 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -131,13 +131,13 @@ struct zt_chanconfig { 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) */ +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) */ }; @@ -250,8 +250,8 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #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_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 */ diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 083ded5d96..771d74c8f1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1695,6 +1695,7 @@ static zap_status_t load_config(void) if (zap_span_create(zio, &span) == ZAP_SUCCESS) { zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); + d = 0; } else { zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); span = NULL; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 2424314b1c..ea0f7690e4 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -441,13 +441,13 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { -#ifdef IODEBUG - //char bb[4096] = ""; - //print_hex_bytes(buf, len, bb, sizeof(bb)); + //#ifdef IODEBUG + char bb[4096] = ""; + print_hex_bytes(buf, len, bb, sizeof(bb)); - //print_bits(buf, (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 + print_bits(buf, (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(&data->q921, buf, (int)len); Q921Rx12(&data->q921); diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 3461721440..4e8679a06f 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -49,7 +49,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za { unsigned configured = 0, x; const char ctlpath[] = "/dev/zap/ctl"; - char path[128] = ""; + char path[] = "/dev/zap/channel"; zt_params_t ztp; zap_socket_t ctlfd = ZT_INVALID_SOCKET; @@ -66,10 +66,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - snprintf(path, sizeof(path), "/dev/zap/%d", x); + //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + ioctl(sockfd, ZT_SPECIFY, &x); + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; memset(&cc, 0, sizeof(cc)); @@ -118,29 +120,31 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); break; } + + len = zt_globals.eclevel; + if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } } - len = zt_globals.eclevel; - if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } - - len = zt_globals.codec_ms * 8; - if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } + if (chan->type != ZAP_CHAN_TYPE_DQ921 && chan->type != ZAP_CHAN_TYPE_DQ931) { + len = zt_globals.codec_ms * 8; + if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; + } } if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { @@ -164,6 +168,20 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } + if (chan->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, ZT_SET_BUFINFO, &binfo)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + } + ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; @@ -290,6 +308,22 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) static ZIO_OPEN_FUNCTION(zt_open) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; + } else { + int ms = zt_globals.codec_ms; + int err; + if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &ms))) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } else { + zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); + zchan->effective_interval = zchan->native_interval = ms; + zchan->packet_len = zchan->native_interval * 8; + zchan->native_codec = zchan->effective_codec; + } + + } return ZAP_SUCCESS; } From 97121441c02c7f4800dc79842117064805ff7d60 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 17:53:09 +0000 Subject: [PATCH 0554/1766] tmp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@277 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 18 ++++---- libs/freetdm/src/zap_io.c | 1 + libs/freetdm/src/zap_isdn.c | 12 ++--- libs/freetdm/src/zap_zt.c | 76 ++++++++++++++++++++++--------- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 897e92e0c5..b972e4ff1d 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -131,13 +131,13 @@ struct zt_chanconfig { 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) */ +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) */ }; @@ -250,8 +250,8 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #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_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 */ diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 083ded5d96..771d74c8f1 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1695,6 +1695,7 @@ static zap_status_t load_config(void) if (zap_span_create(zio, &span) == ZAP_SUCCESS) { zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); + d = 0; } else { zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); span = NULL; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 2424314b1c..ea0f7690e4 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -441,13 +441,13 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { -#ifdef IODEBUG - //char bb[4096] = ""; - //print_hex_bytes(buf, len, bb, sizeof(bb)); + //#ifdef IODEBUG + char bb[4096] = ""; + print_hex_bytes(buf, len, bb, sizeof(bb)); - //print_bits(buf, (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 + print_bits(buf, (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(&data->q921, buf, (int)len); Q921Rx12(&data->q921); diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 3461721440..4e8679a06f 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -49,7 +49,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za { unsigned configured = 0, x; const char ctlpath[] = "/dev/zap/ctl"; - char path[128] = ""; + char path[] = "/dev/zap/channel"; zt_params_t ztp; zap_socket_t ctlfd = ZT_INVALID_SOCKET; @@ -66,10 +66,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - snprintf(path, sizeof(path), "/dev/zap/%d", x); + //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + ioctl(sockfd, ZT_SPECIFY, &x); + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; memset(&cc, 0, sizeof(cc)); @@ -118,29 +120,31 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); break; } + + len = zt_globals.eclevel; + if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } } - len = zt_globals.eclevel; - if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } - - len = zt_globals.codec_ms * 8; - if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } + if (chan->type != ZAP_CHAN_TYPE_DQ921 && chan->type != ZAP_CHAN_TYPE_DQ931) { + len = zt_globals.codec_ms * 8; + if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; + } } if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { @@ -164,6 +168,20 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } + if (chan->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, ZT_SET_BUFINFO, &binfo)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + } + ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; @@ -290,6 +308,22 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) static ZIO_OPEN_FUNCTION(zt_open) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; + } else { + int ms = zt_globals.codec_ms; + int err; + if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &ms))) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } else { + zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); + zchan->effective_interval = zchan->native_interval = ms; + zchan->packet_len = zchan->native_interval * 8; + zchan->native_codec = zchan->effective_codec; + } + + } return ZAP_SUCCESS; } From 599829cedbcc8138caaff71f965ed140c41e37ee Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 20:30:10 +0000 Subject: [PATCH 0555/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@278 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 5 +- libs/openzap/src/zap_isdn.c | 20 ++++---- libs/openzap/src/zap_zt.c | 77 ++++++++++++++++++++----------- 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index b972e4ff1d..eb707671e9 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -217,7 +217,10 @@ 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_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_sigtype_t; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index ea0f7690e4..22d737aa83 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -173,9 +173,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret; - char bb[4096] = ""; - print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); + //char bb[4096] = ""; + //print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); + //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) @@ -441,14 +441,14 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { - //#ifdef IODEBUG - char bb[4096] = ""; - print_hex_bytes(buf, len, bb, sizeof(bb)); - - print_bits(buf, (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 +#ifdef IODEBUG + //char bb[4096] = ""; + //print_hex_bytes(buf, len, bb, sizeof(bb)); + //print_bits(buf, (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(&data->q921, buf, (int)len); Q921Rx12(&data->q921); } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 4e8679a06f..7a280f91ad 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -53,7 +53,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zt_params_t ztp; zap_socket_t ctlfd = ZT_INVALID_SOCKET; - if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); return 0; @@ -68,9 +67,31 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); - if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - ioctl(sockfd, ZT_SPECIFY, &x); + +#if 1 + if (ioctl(sockfd, ZT_SPECIFY, &x)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); + close(sockfd); + continue; + } +#endif + +#if 1 + if (chan->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, ZT_SET_BUFINFO, &binfo)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + } +#endif if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; @@ -152,10 +173,17 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); continue; } + + if (chan->type == ZAP_CHAN_TYPE_DQ921) { + if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + } + zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); - - chan->rate = 8000; chan->physical_span_id = ztp.span_no; chan->physical_chan_id = ztp.chan_no; @@ -168,19 +196,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - if (chan->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, ZT_SET_BUFINFO, &binfo)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); - close(sockfd); - continue; - } - } ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; @@ -190,7 +205,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); continue; } - + + if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); } @@ -311,15 +327,15 @@ static ZIO_OPEN_FUNCTION(zt_open) if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { - int ms = zt_globals.codec_ms; + int blocksize = zt_globals.codec_ms * (zchan->rate / 1000); int err; - if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &ms))) { + if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &blocksize))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } else { zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); - zchan->effective_interval = zchan->native_interval = ms; - zchan->packet_len = zchan->native_interval * 8; + zchan->effective_interval = zchan->native_interval; + zchan->packet_len = blocksize; zchan->native_codec = zchan->effective_codec; } @@ -593,12 +609,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) static ZIO_READ_FUNCTION(zt_read) { zap_ssize_t r = 0; + //*datalen = zchan->packet_len; - *datalen = zchan->packet_len; r = read(zchan->sockfd, data, *datalen); - + if (r >= 0) { *datalen = r; + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + *datalen -= 2; + } return ZAP_SUCCESS; } @@ -608,9 +627,15 @@ static ZIO_READ_FUNCTION(zt_read) static ZIO_WRITE_FUNCTION(zt_write) { zap_ssize_t w = 0; + zap_size_t bytes = *datalen; - w = write(zchan->sockfd, data, *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; From 0943e49fbe0093e953590b15e7fee7bd73aef26d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 20:30:10 +0000 Subject: [PATCH 0556/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@278 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 5 +- libs/freetdm/src/zap_isdn.c | 20 ++++---- libs/freetdm/src/zap_zt.c | 77 ++++++++++++++++++++----------- 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index b972e4ff1d..eb707671e9 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -217,7 +217,10 @@ 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_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_sigtype_t; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index ea0f7690e4..22d737aa83 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -173,9 +173,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret; - char bb[4096] = ""; - print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); + //char bb[4096] = ""; + //print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); + //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) @@ -441,14 +441,14 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { - //#ifdef IODEBUG - char bb[4096] = ""; - print_hex_bytes(buf, len, bb, sizeof(bb)); - - print_bits(buf, (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 +#ifdef IODEBUG + //char bb[4096] = ""; + //print_hex_bytes(buf, len, bb, sizeof(bb)); + //print_bits(buf, (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(&data->q921, buf, (int)len); Q921Rx12(&data->q921); } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 4e8679a06f..7a280f91ad 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -53,7 +53,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zt_params_t ztp; zap_socket_t ctlfd = ZT_INVALID_SOCKET; - if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); return 0; @@ -68,9 +67,31 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); - if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - ioctl(sockfd, ZT_SPECIFY, &x); + +#if 1 + if (ioctl(sockfd, ZT_SPECIFY, &x)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); + close(sockfd); + continue; + } +#endif + +#if 1 + if (chan->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, ZT_SET_BUFINFO, &binfo)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + } +#endif if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; @@ -152,10 +173,17 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); continue; } + + if (chan->type == ZAP_CHAN_TYPE_DQ921) { + if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + close(sockfd); + continue; + } + } + zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); - - chan->rate = 8000; chan->physical_span_id = ztp.span_no; chan->physical_chan_id = ztp.chan_no; @@ -168,19 +196,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - if (chan->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, ZT_SET_BUFINFO, &binfo)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); - close(sockfd); - continue; - } - } ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; @@ -190,7 +205,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); continue; } - + + if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); } @@ -311,15 +327,15 @@ static ZIO_OPEN_FUNCTION(zt_open) if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { - int ms = zt_globals.codec_ms; + int blocksize = zt_globals.codec_ms * (zchan->rate / 1000); int err; - if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &ms))) { + if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &blocksize))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } else { zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); - zchan->effective_interval = zchan->native_interval = ms; - zchan->packet_len = zchan->native_interval * 8; + zchan->effective_interval = zchan->native_interval; + zchan->packet_len = blocksize; zchan->native_codec = zchan->effective_codec; } @@ -593,12 +609,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) static ZIO_READ_FUNCTION(zt_read) { zap_ssize_t r = 0; + //*datalen = zchan->packet_len; - *datalen = zchan->packet_len; r = read(zchan->sockfd, data, *datalen); - + if (r >= 0) { *datalen = r; + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + *datalen -= 2; + } return ZAP_SUCCESS; } @@ -608,9 +627,15 @@ static ZIO_READ_FUNCTION(zt_read) static ZIO_WRITE_FUNCTION(zt_write) { zap_ssize_t w = 0; + zap_size_t bytes = *datalen; - w = write(zchan->sockfd, data, *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; From b22f935b402b6ccc78bbdbe8d537bcd12c9d5415 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 00:00:10 +0000 Subject: [PATCH 0557/1766] sangoma might fully work now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@279 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/include/zap_types.h | 2 + libs/openzap/src/zap_analog.c | 4 +- libs/openzap/src/zap_io.c | 115 +++++++++++++++---------- 4 files changed, 74 insertions(+), 49 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 91d807120a..a78facb658 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1044,7 +1044,7 @@ static void zap_logger(char *file, const char *func, int line, int level, char * va_start(ap, fmt); if (switch_vasprintf(&data, fmt, ap) != -1) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, data); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, (char *)func, line, NULL, level, data); free(data); } diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index b517aeacd8..1caa08823d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -63,6 +63,8 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj #define ZAP_FSK_MOD_FACTOR 0x10000 +#define ZAP_DEFAULT_DTMF_ON 250 +#define ZAP_DEFAULT_DTMF_OFF 50 typedef uint64_t zap_time_t; diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index fb38b6c27a..79c02cb931 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -45,6 +45,9 @@ 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + 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; @@ -431,7 +434,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); - zap_channel_command(chan, ZAP_COMMAND_TRACE_INPUT, "/tmp/wtf.ul"); zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); continue; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 771d74c8f1..3c05830d2f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -210,6 +210,35 @@ static uint32_t hashfromstring(void *ky) return hash; } + +static zap_status_t zap_destroy_channel(zap_channel_t *zchan) +{ + + if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + zap_mutex_destroy(&zchan->mutex); + zap_buffer_destroy(&zchan->digit_buffer); + zap_buffer_destroy(&zchan->dtmf_buffer); + zap_buffer_destroy(&zchan->fsk_buffer); + + if (zchan->tone_session.buffer) { + teletone_destroy_session(&zchan->tone_session); + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + } + + + if (zchan->span->zio->destroy_channel) { + zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); + if (zchan->span->zio->destroy_channel(zchan) == ZAP_SUCCESS) { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); + } else { + zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); + } + } + } + + return ZAP_SUCCESS; +} + zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; @@ -248,12 +277,7 @@ zap_status_t zap_span_close_all(void) span = &globals.spans[i]; for(j = 0; j < span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_CONFIGURED)) { - zap_mutex_destroy(&span->channels[j].mutex); - zap_buffer_destroy(&span->channels[j].digit_buffer); - zap_buffer_destroy(&span->channels[j].dtmf_buffer); - zap_buffer_destroy(&span->channels[j].fsk_buffer); - } + zap_destroy_channel(&span->channels[i]); } if (span->mutex) { @@ -348,6 +372,13 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span = span; new_chan->fds[0] = -1; new_chan->fds[1] = -1; + if (!new_chan->dtmf_on) { + new_chan->dtmf_on = ZAP_DEFAULT_DTMF_ON; + } + + if (!new_chan->dtmf_off) { + new_chan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; + } zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -693,11 +724,6 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; - if (zchan->tone_session.buffer) { - teletone_destroy_session(&zchan->tone_session); - memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - } - if (zchan->dtmf_buffer) { zap_buffer_zero(zchan->dtmf_buffer); } @@ -706,8 +732,14 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_buffer_zero(zchan->digit_buffer); } - zchan->dtmf_on = zchan->dtmf_off = 0; + if (!zchan->dtmf_on) { + zchan->dtmf_on = ZAP_DEFAULT_DTMF_ON; + } + if (!zchan->dtmf_off) { + zchan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { zchan->effective_codec = zchan->native_codec; zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); @@ -858,29 +890,21 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) { - if (zchan->dtmf_buffer) { - return ZAP_SUCCESS; + if (!zchan->dtmf_buffer) { + if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); + return ZAP_FAIL; + } else { + zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); + } + } + + if (!zchan->tone_session.buffer) { + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + teletone_init_session(&zchan->tone_session, 0, NULL, NULL); } - if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); - snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); - return ZAP_FAIL; - } else { - zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); - } - - if (!zchan->dtmf_on) { - zchan->dtmf_on = 250; - } - - if (!zchan->dtmf_off) { - zchan->dtmf_off = 50; - } - - memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - teletone_init_session(&zchan->tone_session, 0, NULL, NULL); - zchan->tone_session.rate = zchan->rate; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); @@ -1118,11 +1142,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo char *digits = ZAP_COMMAND_OBJ_CHAR_P; int x = 0; - if (!zchan->dtmf_buffer) { - if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { - GOTO_STATUS(done, status); - } + if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { + GOTO_STATUS(done, status); } + zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); for (cur = digits; *cur; cur++) { @@ -1130,6 +1153,9 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); x++; + } else { + zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); + GOTO_STATUS(done, ZAP_FAIL); } } @@ -1860,11 +1886,15 @@ zap_status_t zap_global_init(void) return ZAP_FAIL; } + + zap_status_t zap_global_destroy(void) { unsigned int i,j; time_end(); + zap_span_close_all(); + for(i = 1; i <= globals.span_index; i++) { zap_span_t *cur_span = &globals.spans[i]; @@ -1873,14 +1903,7 @@ zap_status_t zap_global_destroy(void) for(j = 1; j <= cur_span->chan_count; j++) { zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - if (cur_span->zio->destroy_channel) { - zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - if (cur_span->zio->destroy_channel(cur_chan) == ZAP_SUCCESS) { - zap_clear_flag_locked(cur_chan, ZAP_CHANNEL_CONFIGURED); - } else { - zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - } - } + zap_destroy_channel(cur_chan); } } zap_mutex_unlock(cur_span->mutex); @@ -1889,8 +1912,6 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_ZT_SUPPORT - zap_span_close_all(); - if (interfaces.zt_interface) { zt_destroy(); } From 7d57b68604aa38bb8c3383fbbfbb20c6a72ae9db Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 00:00:10 +0000 Subject: [PATCH 0558/1766] sangoma might fully work now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@279 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/include/zap_types.h | 2 + libs/freetdm/src/zap_analog.c | 4 +- libs/freetdm/src/zap_io.c | 115 +++++++++++++++---------- 4 files changed, 74 insertions(+), 49 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 91d807120a..a78facb658 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1044,7 +1044,7 @@ static void zap_logger(char *file, const char *func, int line, int level, char * va_start(ap, fmt); if (switch_vasprintf(&data, fmt, ap) != -1) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, data); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, (char *)func, line, NULL, level, data); free(data); } diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b517aeacd8..1caa08823d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -63,6 +63,8 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj #define ZAP_FSK_MOD_FACTOR 0x10000 +#define ZAP_DEFAULT_DTMF_ON 250 +#define ZAP_DEFAULT_DTMF_OFF 50 typedef uint64_t zap_time_t; diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index fb38b6c27a..79c02cb931 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -45,6 +45,9 @@ 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + 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; @@ -431,7 +434,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GET_CALLERID: { zap_channel_done(chan); - zap_channel_command(chan, ZAP_COMMAND_TRACE_INPUT, "/tmp/wtf.ul"); zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); continue; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 771d74c8f1..3c05830d2f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -210,6 +210,35 @@ static uint32_t hashfromstring(void *ky) return hash; } + +static zap_status_t zap_destroy_channel(zap_channel_t *zchan) +{ + + if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + zap_mutex_destroy(&zchan->mutex); + zap_buffer_destroy(&zchan->digit_buffer); + zap_buffer_destroy(&zchan->dtmf_buffer); + zap_buffer_destroy(&zchan->fsk_buffer); + + if (zchan->tone_session.buffer) { + teletone_destroy_session(&zchan->tone_session); + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + } + + + if (zchan->span->zio->destroy_channel) { + zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); + if (zchan->span->zio->destroy_channel(zchan) == ZAP_SUCCESS) { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); + } else { + zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); + } + } + } + + return ZAP_SUCCESS; +} + zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; @@ -248,12 +277,7 @@ zap_status_t zap_span_close_all(void) span = &globals.spans[i]; for(j = 0; j < span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_CONFIGURED)) { - zap_mutex_destroy(&span->channels[j].mutex); - zap_buffer_destroy(&span->channels[j].digit_buffer); - zap_buffer_destroy(&span->channels[j].dtmf_buffer); - zap_buffer_destroy(&span->channels[j].fsk_buffer); - } + zap_destroy_channel(&span->channels[i]); } if (span->mutex) { @@ -348,6 +372,13 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span = span; new_chan->fds[0] = -1; new_chan->fds[1] = -1; + if (!new_chan->dtmf_on) { + new_chan->dtmf_on = ZAP_DEFAULT_DTMF_ON; + } + + if (!new_chan->dtmf_off) { + new_chan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; + } zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -693,11 +724,6 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) memset(zchan->tokens, 0, sizeof(zchan->tokens)); zchan->token_count = 0; - if (zchan->tone_session.buffer) { - teletone_destroy_session(&zchan->tone_session); - memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - } - if (zchan->dtmf_buffer) { zap_buffer_zero(zchan->dtmf_buffer); } @@ -706,8 +732,14 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_buffer_zero(zchan->digit_buffer); } - zchan->dtmf_on = zchan->dtmf_off = 0; + if (!zchan->dtmf_on) { + zchan->dtmf_on = ZAP_DEFAULT_DTMF_ON; + } + if (!zchan->dtmf_off) { + zchan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; + } + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { zchan->effective_codec = zchan->native_codec; zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); @@ -858,29 +890,21 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) { - if (zchan->dtmf_buffer) { - return ZAP_SUCCESS; + if (!zchan->dtmf_buffer) { + if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); + return ZAP_FAIL; + } else { + zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); + } + } + + if (!zchan->tone_session.buffer) { + memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); + teletone_init_session(&zchan->tone_session, 0, NULL, NULL); } - if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); - snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); - return ZAP_FAIL; - } else { - zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); - } - - if (!zchan->dtmf_on) { - zchan->dtmf_on = 250; - } - - if (!zchan->dtmf_off) { - zchan->dtmf_off = 50; - } - - memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - teletone_init_session(&zchan->tone_session, 0, NULL, NULL); - zchan->tone_session.rate = zchan->rate; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); @@ -1118,11 +1142,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo char *digits = ZAP_COMMAND_OBJ_CHAR_P; int x = 0; - if (!zchan->dtmf_buffer) { - if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { - GOTO_STATUS(done, status); - } + if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { + GOTO_STATUS(done, status); } + zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); for (cur = digits; *cur; cur++) { @@ -1130,6 +1153,9 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); x++; + } else { + zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); + GOTO_STATUS(done, ZAP_FAIL); } } @@ -1860,11 +1886,15 @@ zap_status_t zap_global_init(void) return ZAP_FAIL; } + + zap_status_t zap_global_destroy(void) { unsigned int i,j; time_end(); + zap_span_close_all(); + for(i = 1; i <= globals.span_index; i++) { zap_span_t *cur_span = &globals.spans[i]; @@ -1873,14 +1903,7 @@ zap_status_t zap_global_destroy(void) for(j = 1; j <= cur_span->chan_count; j++) { zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - if (cur_span->zio->destroy_channel) { - zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - if (cur_span->zio->destroy_channel(cur_chan) == ZAP_SUCCESS) { - zap_clear_flag_locked(cur_chan, ZAP_CHANNEL_CONFIGURED); - } else { - zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", cur_chan->span_id, cur_chan->chan_id, cur_chan->sockfd); - } - } + zap_destroy_channel(cur_chan); } } zap_mutex_unlock(cur_span->mutex); @@ -1889,8 +1912,6 @@ zap_status_t zap_global_destroy(void) #ifdef ZAP_ZT_SUPPORT - zap_span_close_all(); - if (interfaces.zt_interface) { zt_destroy(); } From d8760c423c81b2504ef9ff27e6b84aef7201cbda Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 02:13:41 +0000 Subject: [PATCH 0559/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@280 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 270 +++++++++++++++++----------------- libs/openzap/src/zap_zt.c | 88 ++++++----- 2 files changed, 185 insertions(+), 173 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 79c02cb931..db0584cde8 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -118,7 +118,7 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map return 0; } -static void send_caller_id(zap_channel_t *chan) +static void send_caller_id(zap_channel_t *zchan) { zap_fsk_data_state_t fsk_data; uint8_t databuf[1024] = ""; @@ -139,33 +139,33 @@ static void send_caller_id(zap_channel_t *chan) 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(chan->caller_data.cid_num)) { + if (zap_strlen_zero(zchan->caller_data.cid_num)) { mt = MDMF_NO_NUM; - zap_set_string(chan->caller_data.cid_num, "O"); - } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { + zap_set_string(zchan->caller_data.cid_num, "O"); + } else if (!strcasecmp(zchan->caller_data.cid_num, "P") || !strcasecmp(zchan->caller_data.cid_num, "O")) { mt = MDMF_NO_NUM; } else { mt = MDMF_PHONE_NUM; } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_num, (uint8_t)strlen(zchan->caller_data.cid_num)); - if (zap_strlen_zero(chan->caller_data.cid_name)) { + if (zap_strlen_zero(zchan->caller_data.cid_name)) { mt = MDMF_NO_NAME; - zap_set_string(chan->caller_data.cid_name, "O"); - } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { + 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 *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_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(chan, &fsk_data, -14); + zap_channel_send_fsk_data(zchan, &fsk_data, -14); } static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { - zap_channel_t *chan = (zap_channel_t *) obj; + zap_channel_t *zchan = (zap_channel_t *) obj; zap_buffer_t *dt_buffer = NULL; teletone_generation_session_t ts; uint8_t frame[1024]; @@ -173,7 +173,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128] = ""; zap_size_t dtmf_offset = 0; - zap_analog_data_t *data = chan->span->analog_data; + zap_analog_data_t *data = zchan->span->analog_data; zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; zap_sigmsg_t sig; @@ -183,40 +183,40 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.buffer = NULL; - if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n"); goto done; } if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - snprintf(chan->last_error, sizeof(chan->last_error), "memory error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!"); zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); goto done; } - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); + 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(chan, ZAP_CHANNEL_INTHREAD); + 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(chan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); memset(&sig, 0, sizeof(sig)); - sig.chan_id = chan->chan_id; - sig.span_id = chan->span_id; - sig.channel = chan; + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; - while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { + while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; zap_size_t dlen = 0; @@ -225,22 +225,22 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) elapsed += interval; state_counter += interval; - if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { - switch(chan->state) { + 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(chan, ZAP_CHANNEL_CALLERID_DETECT)) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + if (state_counter > 5000 || !zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); } } break; case ZAP_CHANNEL_STATE_DIALING: { if (state_counter > dial_timeout) { - if (chan->needed_tones[ZAP_TONEMAP_DIAL]) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (zchan->needed_tones[ZAP_TONEMAP_DIAL]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } } } @@ -248,8 +248,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GENRING: { if (state_counter > 60000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); - } else if (!chan->fsk_buffer || !zap_buffer_inuse(chan->fsk_buffer)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else if (!zchan->fsk_buffer || !zap_buffer_inuse(zchan->fsk_buffer)) { zap_sleep(interval); continue; } @@ -258,21 +258,21 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_DIALTONE: { if (state_counter > 10000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } } break; case ZAP_CHANNEL_STATE_BUSY: { if (state_counter > 20000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_ATTN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN); } } break; case ZAP_CHANNEL_STATE_ATTN: { if (state_counter > 20000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } break; @@ -280,10 +280,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 500) { - if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK) && chan->state >= ZAP_CHANNEL_STATE_IDLE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->state >= ZAP_CHANNEL_STATE_IDLE) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } } @@ -292,32 +292,32 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { int done = 0; - if (chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) { - send_caller_id(chan); - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else if (state_counter > 600 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { - send_caller_id(chan); - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else if (state_counter > 1000 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { + 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 (chan->fsk_buffer) { - zap_buffer_zero(chan->fsk_buffer); + if (zchan->fsk_buffer) { + zap_buffer_zero(zchan->fsk_buffer); } else { - zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - ts.user_data = chan->fsk_buffer; - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); + 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(chan, ZAP_CHANNEL_STATE_UP); - zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + 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: @@ -329,7 +329,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(chan); + zap_channel_done(zchan); goto done; } break; @@ -337,32 +337,32 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; } } else { - zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); indicate = 0; state_counter = 0; - zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(chan->state)); - switch(chan->state) { + zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(zchan->state)); + switch(zchan->state) { case ZAP_CHANNEL_STATE_UP: { - zap_channel_use(chan); - zap_channel_clear_needed_tones(chan); + zap_channel_use(zchan); + zap_channel_clear_needed_tones(zchan); - if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); } - if (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer)) { + 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(chan->fsk_buffer); + zap_buffer_zero(zchan->fsk_buffer); } - if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, 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); } - if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { - zap_clear_flag(chan, ZAP_CHANNEL_HOLD); + if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) { + zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); sig.event_id = ZAP_SIGEVENT_FLASH; } else { sig.event_id = ZAP_SIGEVENT_UP; @@ -374,18 +374,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALING: { - zap_channel_use(chan); + zap_channel_use(zchan); } break; case ZAP_CHANNEL_STATE_IDLE: { - zap_channel_use(chan); + zap_channel_use(zchan); sig.event_id = ZAP_SIGEVENT_START; - if (chan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_string(chan->caller_data.dnis, chan->chan_number); + if (zchan->type == ZAP_CHAN_TYPE_FXO) { + zap_set_string(zchan->caller_data.dnis, zchan->chan_number); } else { - zap_set_string(chan->caller_data.dnis, dtmf); + zap_set_string(zchan->caller_data.dnis, dtmf); } data->sig_cb(&sig); @@ -394,7 +394,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(chan); + zap_channel_done(zchan); sig.event_id = ZAP_SIGEVENT_STOP; data->sig_cb(&sig); goto done; @@ -402,63 +402,63 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { - zap_channel_done(chan); + zap_channel_done(zchan); *dtmf = '\0'; dtmf_offset = 0; zap_buffer_zero(dt_buffer); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_DIAL]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); indicate = 1; } break; case ZAP_CHANNEL_STATE_CALLWAITING: { - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; - if (chan->fsk_buffer) { - zap_buffer_zero(chan->fsk_buffer); + zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + if (zchan->fsk_buffer) { + zap_buffer_zero(zchan->fsk_buffer); } else { - zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - ts.user_data = chan->fsk_buffer; - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]); + 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: { - send_caller_id(chan); - zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); + send_caller_id(zchan); + zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; case ZAP_CHANNEL_STATE_GET_CALLERID: { - zap_channel_done(chan); - zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + zap_channel_done(zchan); + 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, chan->span->tone_map[ZAP_TONEMAP_RING]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]); indicate = 1; } break; case ZAP_CHANNEL_STATE_BUSY: { - zap_channel_done(chan); + zap_channel_done(zchan); zap_buffer_zero(dt_buffer); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); indicate = 1; } break; case ZAP_CHANNEL_STATE_ATTN: { - zap_channel_done(chan); + zap_channel_done(zchan); zap_buffer_zero(dt_buffer); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); indicate = 1; } break; @@ -467,11 +467,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->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 || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); } dtmf_offset = strlen(dtmf); last_digit = elapsed; @@ -481,11 +481,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); last_digit = 0; } - if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) { continue; } @@ -493,50 +493,50 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } - if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "READ ERROR\n"); goto done; } - if (chan->type == ZAP_CHAN_TYPE_FXO && chan->detected_tones[0]) { + 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 = chan->chan_id; - sig.span_id = chan->span_id; - sig.channel = chan; + 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 (chan->detected_tones[i]) { - zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tones[i])); + if (zchan->detected_tones[i]) { + zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(zchan->detected_tones[i])); sig.raw_data = &i; data->sig_cb(&sig); } } - if (chan->detected_tones[ZAP_TONEMAP_DIAL]) { - zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); + if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) { + zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani); state_counter = 0; - chan->needed_tones[ZAP_TONEMAP_RING] = 1; - chan->needed_tones[ZAP_TONEMAP_BUSY] = 1; - chan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; - chan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; - chan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; - dial_timeout = (chan->dtmf_on + chan->dtmf_off) * strlen(chan->caller_data.ani) + 50; - } else if (chan->detected_tones[ZAP_TONEMAP_RING]) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); - } else if (chan->detected_tones[ZAP_TONEMAP_BUSY]) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + 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) + 50; + } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } else if (zchan->detected_tones[ZAP_TONEMAP_BUSY]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } - zap_channel_clear_detected_tones(chan); + zap_channel_clear_detected_tones(zchan); } - if ((chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) || (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer))) { + 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(chan, frame, sizeof(frame), &rlen); + zap_channel_write(zchan, frame, sizeof(frame), &rlen); continue; } @@ -544,49 +544,49 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } - if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); } - if (chan->effective_codec != ZAP_CODEC_SLIN) { + if (zchan->effective_codec != ZAP_CODEC_SLIN) { len *= 2; } rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (chan->effective_codec != ZAP_CODEC_SLIN) { + if (zchan->effective_codec != ZAP_CODEC_SLIN) { zio_codec_t codec_func = NULL; - if (chan->native_codec == ZAP_CODEC_ULAW) { + if (zchan->native_codec == ZAP_CODEC_ULAW) { codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { codec_func = zio_slin2alaw; } if (codec_func) { status = codec_func(frame, sizeof(frame), &rlen); } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); goto done; } } - zap_channel_write(chan, frame, sizeof(frame), &rlen); + zap_channel_write(zchan, frame, sizeof(frame), &rlen); } done: - zap_channel_done(chan); - if (chan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(chan, ZAP_COMMAND_ONHOOK, NULL); + zap_channel_done(zchan); + if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); } - if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, 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 = chan; - zap_channel_close(&chan); + closed_chan = zchan; + zap_channel_close(&zchan); zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 7a280f91ad..47a995019b 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -41,6 +41,7 @@ static struct { uint32_t wink_ms; uint32_t flash_ms; uint32_t eclevel; + uint32_t etlevel; } zt_globals; #define ZT_INVALID_SOCKET -1 @@ -61,24 +62,21 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za memset(&ztp, 0, sizeof(ztp)); for(x = start; x < end; x++) { - zap_channel_t *chan; + zap_channel_t *zchan; zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); - if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { -#if 1 if (ioctl(sockfd, ZT_SPECIFY, &x)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); close(sockfd); continue; } -#endif -#if 1 - if (chan->type == ZAP_CHAN_TYPE_DQ921) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { struct zt_bufferinfo binfo; memset(&binfo, 0, sizeof(binfo)); binfo.txbufpolicy = 0; @@ -86,12 +84,11 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za binfo.numbufs = 32; binfo.bufsize = 1024; if (ioctl(sockfd, ZT_SET_BUFINFO, &binfo)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } } -#endif if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; @@ -136,63 +133,55 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za break; } if (ioctl(ctlfd, ZT_CHANCONFIG, &cc)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", + zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); close(sockfd); break; } - - len = zt_globals.eclevel; - if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } } - if (chan->type != ZAP_CHAN_TYPE_DQ921 && chan->type != ZAP_CHAN_TYPE_DQ931) { + if (zchan->type != ZAP_CHAN_TYPE_DQ921 && zchan->type != ZAP_CHAN_TYPE_DQ931) { len = zt_globals.codec_ms * 8; - if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + if (ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; + zchan->packet_len = len; + zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8; - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; + if (zchan->effective_codec == ZAP_CODEC_SLIN) { + zchan->packet_len *= 2; } } if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } - if (chan->type == ZAP_CHAN_TYPE_DQ921) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } } - zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); - chan->rate = 8000; - chan->physical_span_id = ztp.span_no; - chan->physical_chan_id = ztp.chan_no; + 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) { if (ztp.g711_type == ZT_G711_ALAW) { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; } else { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; } } @@ -201,17 +190,17 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za ztp.flash_time = zt_globals.flash_ms; if (ioctl(sockfd, ZT_SET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } if (!zap_strlen_zero(name)) { - zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); + zap_copy_string(zchan->chan_name, name, sizeof(zchan->chan_name)); } if (!zap_strlen_zero(number)) { - zap_copy_string(chan->chan_number, number, sizeof(chan->chan_number)); + zap_copy_string(zchan->chan_number, number, sizeof(zchan->chan_number)); } configured++; } else { @@ -339,6 +328,28 @@ static ZIO_OPEN_FUNCTION(zt_open) zchan->native_codec = zchan->effective_codec; } + if (zchan->type == ZAP_CHAN_TYPE_B) { + int one = 1; + if (ioctl(zchan->sockfd, ZT_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; + } + } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { + int len = zt_globals.eclevel; + if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + return ZAP_FAIL; + } + + len = zt_globals.etlevel; + if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + return ZAP_FAIL; + } + } } return ZAP_SUCCESS; } @@ -664,6 +675,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; zt_globals.eclevel = 64; + zt_globals.etlevel = 0; zt_interface.name = "zt"; zt_interface.configure = zt_configure; From 3417af8959de36087912450148ac5076fdfb7d47 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 02:13:41 +0000 Subject: [PATCH 0560/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@280 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 270 +++++++++++++++++----------------- libs/freetdm/src/zap_zt.c | 88 ++++++----- 2 files changed, 185 insertions(+), 173 deletions(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 79c02cb931..db0584cde8 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -118,7 +118,7 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map return 0; } -static void send_caller_id(zap_channel_t *chan) +static void send_caller_id(zap_channel_t *zchan) { zap_fsk_data_state_t fsk_data; uint8_t databuf[1024] = ""; @@ -139,33 +139,33 @@ static void send_caller_id(zap_channel_t *chan) 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(chan->caller_data.cid_num)) { + if (zap_strlen_zero(zchan->caller_data.cid_num)) { mt = MDMF_NO_NUM; - zap_set_string(chan->caller_data.cid_num, "O"); - } else if (!strcasecmp(chan->caller_data.cid_num, "P") || !strcasecmp(chan->caller_data.cid_num, "O")) { + zap_set_string(zchan->caller_data.cid_num, "O"); + } else if (!strcasecmp(zchan->caller_data.cid_num, "P") || !strcasecmp(zchan->caller_data.cid_num, "O")) { mt = MDMF_NO_NUM; } else { mt = MDMF_PHONE_NUM; } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) chan->caller_data.cid_num, (uint8_t)strlen(chan->caller_data.cid_num)); + zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_num, (uint8_t)strlen(zchan->caller_data.cid_num)); - if (zap_strlen_zero(chan->caller_data.cid_name)) { + if (zap_strlen_zero(zchan->caller_data.cid_name)) { mt = MDMF_NO_NAME; - zap_set_string(chan->caller_data.cid_name, "O"); - } else if (!strcasecmp(chan->caller_data.cid_name, "P") || !strcasecmp(chan->caller_data.cid_name, "O")) { + 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 *) chan->caller_data.cid_name, (uint8_t)strlen(chan->caller_data.cid_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(chan, &fsk_data, -14); + zap_channel_send_fsk_data(zchan, &fsk_data, -14); } static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { - zap_channel_t *chan = (zap_channel_t *) obj; + zap_channel_t *zchan = (zap_channel_t *) obj; zap_buffer_t *dt_buffer = NULL; teletone_generation_session_t ts; uint8_t frame[1024]; @@ -173,7 +173,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128] = ""; zap_size_t dtmf_offset = 0; - zap_analog_data_t *data = chan->span->analog_data; + zap_analog_data_t *data = zchan->span->analog_data; zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; zap_sigmsg_t sig; @@ -183,40 +183,40 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.buffer = NULL; - if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n"); goto done; } if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - snprintf(chan->last_error, sizeof(chan->last_error), "memory error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!"); zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); goto done; } - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!"); + 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(chan, ZAP_CHANNEL_INTHREAD); + 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(chan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); zap_buffer_set_loops(dt_buffer, -1); memset(&sig, 0, sizeof(sig)); - sig.chan_id = chan->chan_id; - sig.span_id = chan->span_id; - sig.channel = chan; + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; - while (zap_test_flag(chan, ZAP_CHANNEL_INTHREAD)) { + while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; zap_size_t dlen = 0; @@ -225,22 +225,22 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) elapsed += interval; state_counter += interval; - if (!zap_test_flag(chan, ZAP_CHANNEL_STATE_CHANGE)) { - switch(chan->state) { + 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(chan, ZAP_CHANNEL_CALLERID_DETECT)) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + if (state_counter > 5000 || !zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); } } break; case ZAP_CHANNEL_STATE_DIALING: { if (state_counter > dial_timeout) { - if (chan->needed_tones[ZAP_TONEMAP_DIAL]) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (zchan->needed_tones[ZAP_TONEMAP_DIAL]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } } } @@ -248,8 +248,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_GENRING: { if (state_counter > 60000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); - } else if (!chan->fsk_buffer || !zap_buffer_inuse(chan->fsk_buffer)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else if (!zchan->fsk_buffer || !zap_buffer_inuse(zchan->fsk_buffer)) { zap_sleep(interval); continue; } @@ -258,21 +258,21 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_DIALTONE: { if (state_counter > 10000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } } break; case ZAP_CHANNEL_STATE_BUSY: { if (state_counter > 20000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_ATTN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN); } } break; case ZAP_CHANNEL_STATE_ATTN: { if (state_counter > 20000) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } break; @@ -280,10 +280,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 500) { - if (zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK) && chan->state >= ZAP_CHANNEL_STATE_IDLE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->state >= ZAP_CHANNEL_STATE_IDLE) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } } @@ -292,32 +292,32 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { int done = 0; - if (chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) { - send_caller_id(chan); - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else if (state_counter > 600 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { - send_caller_id(chan); - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else if (state_counter > 1000 && !chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { + 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 (chan->fsk_buffer) { - zap_buffer_zero(chan->fsk_buffer); + if (zchan->fsk_buffer) { + zap_buffer_zero(zchan->fsk_buffer); } else { - zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - ts.user_data = chan->fsk_buffer; - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); + 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(chan, ZAP_CHANNEL_STATE_UP); - zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + 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: @@ -329,7 +329,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(chan); + zap_channel_done(zchan); goto done; } break; @@ -337,32 +337,32 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; } } else { - zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(chan->span, ZAP_SPAN_STATE_CHANGE); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); indicate = 0; state_counter = 0; - zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(chan->state)); - switch(chan->state) { + zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(zchan->state)); + switch(zchan->state) { case ZAP_CHANNEL_STATE_UP: { - zap_channel_use(chan); - zap_channel_clear_needed_tones(chan); + zap_channel_use(zchan); + zap_channel_clear_needed_tones(zchan); - if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); } - if (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer)) { + 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(chan->fsk_buffer); + zap_buffer_zero(zchan->fsk_buffer); } - if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, 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); } - if (zap_test_flag(chan, ZAP_CHANNEL_HOLD)) { - zap_clear_flag(chan, ZAP_CHANNEL_HOLD); + if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) { + zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); sig.event_id = ZAP_SIGEVENT_FLASH; } else { sig.event_id = ZAP_SIGEVENT_UP; @@ -374,18 +374,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALING: { - zap_channel_use(chan); + zap_channel_use(zchan); } break; case ZAP_CHANNEL_STATE_IDLE: { - zap_channel_use(chan); + zap_channel_use(zchan); sig.event_id = ZAP_SIGEVENT_START; - if (chan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_string(chan->caller_data.dnis, chan->chan_number); + if (zchan->type == ZAP_CHAN_TYPE_FXO) { + zap_set_string(zchan->caller_data.dnis, zchan->chan_number); } else { - zap_set_string(chan->caller_data.dnis, dtmf); + zap_set_string(zchan->caller_data.dnis, dtmf); } data->sig_cb(&sig); @@ -394,7 +394,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(chan); + zap_channel_done(zchan); sig.event_id = ZAP_SIGEVENT_STOP; data->sig_cb(&sig); goto done; @@ -402,63 +402,63 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { - zap_channel_done(chan); + zap_channel_done(zchan); *dtmf = '\0'; dtmf_offset = 0; zap_buffer_zero(dt_buffer); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_DIAL]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); indicate = 1; } break; case ZAP_CHANNEL_STATE_CALLWAITING: { - chan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; - if (chan->fsk_buffer) { - zap_buffer_zero(chan->fsk_buffer); + zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; + if (zchan->fsk_buffer) { + zap_buffer_zero(zchan->fsk_buffer); } else { - zap_buffer_create(&chan->fsk_buffer, 128, 128, 0); + zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); } - ts.user_data = chan->fsk_buffer; - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]); + 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: { - send_caller_id(chan); - zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_ON, NULL); + send_caller_id(zchan); + zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL); } break; case ZAP_CHANNEL_STATE_GET_CALLERID: { - zap_channel_done(chan); - zap_channel_command(chan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); + zap_channel_done(zchan); + 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, chan->span->tone_map[ZAP_TONEMAP_RING]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]); indicate = 1; } break; case ZAP_CHANNEL_STATE_BUSY: { - zap_channel_done(chan); + zap_channel_done(zchan); zap_buffer_zero(dt_buffer); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_BUSY]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); indicate = 1; } break; case ZAP_CHANNEL_STATE_ATTN: { - zap_channel_done(chan); + zap_channel_done(zchan); zap_buffer_zero(dt_buffer); - teletone_run(&ts, chan->span->tone_map[ZAP_TONEMAP_ATTN]); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); indicate = 1; } break; @@ -467,11 +467,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->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 || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); - if (chan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_COLLECT); + if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); } dtmf_offset = strlen(dtmf); last_digit = elapsed; @@ -481,11 +481,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_IDLE); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); last_digit = 0; } - if (zap_channel_wait(chan, &flags, interval * 2) != ZAP_SUCCESS) { + if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) { continue; } @@ -493,50 +493,50 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } - if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) { + if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "READ ERROR\n"); goto done; } - if (chan->type == ZAP_CHAN_TYPE_FXO && chan->detected_tones[0]) { + 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 = chan->chan_id; - sig.span_id = chan->span_id; - sig.channel = chan; + 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 (chan->detected_tones[i]) { - zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(chan->detected_tones[i])); + if (zchan->detected_tones[i]) { + zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(zchan->detected_tones[i])); sig.raw_data = &i; data->sig_cb(&sig); } } - if (chan->detected_tones[ZAP_TONEMAP_DIAL]) { - zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, chan->caller_data.ani); + if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) { + zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani); state_counter = 0; - chan->needed_tones[ZAP_TONEMAP_RING] = 1; - chan->needed_tones[ZAP_TONEMAP_BUSY] = 1; - chan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; - chan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; - chan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; - dial_timeout = (chan->dtmf_on + chan->dtmf_off) * strlen(chan->caller_data.ani) + 50; - } else if (chan->detected_tones[ZAP_TONEMAP_RING]) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); - } else if (chan->detected_tones[ZAP_TONEMAP_BUSY]) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + 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) + 50; + } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } else if (zchan->detected_tones[ZAP_TONEMAP_BUSY]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } - zap_channel_clear_detected_tones(chan); + zap_channel_clear_detected_tones(zchan); } - if ((chan->dtmf_buffer && zap_buffer_inuse(chan->dtmf_buffer)) || (chan->fsk_buffer && zap_buffer_inuse(chan->fsk_buffer))) { + 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(chan, frame, sizeof(frame), &rlen); + zap_channel_write(zchan, frame, sizeof(frame), &rlen); continue; } @@ -544,49 +544,49 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) continue; } - if (chan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(chan, ZAP_COMMAND_OFFHOOK, NULL); + if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); } - if (chan->effective_codec != ZAP_CODEC_SLIN) { + if (zchan->effective_codec != ZAP_CODEC_SLIN) { len *= 2; } rlen = zap_buffer_read_loop(dt_buffer, frame, len); - if (chan->effective_codec != ZAP_CODEC_SLIN) { + if (zchan->effective_codec != ZAP_CODEC_SLIN) { zio_codec_t codec_func = NULL; - if (chan->native_codec == ZAP_CODEC_ULAW) { + if (zchan->native_codec == ZAP_CODEC_ULAW) { codec_func = zio_slin2ulaw; - } else if (chan->native_codec == ZAP_CODEC_ALAW) { + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { codec_func = zio_slin2alaw; } if (codec_func) { status = codec_func(frame, sizeof(frame), &rlen); } else { - snprintf(chan->last_error, sizeof(chan->last_error), "codec error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); goto done; } } - zap_channel_write(chan, frame, sizeof(frame), &rlen); + zap_channel_write(zchan, frame, sizeof(frame), &rlen); } done: - zap_channel_done(chan); - if (chan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(chan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(chan, ZAP_COMMAND_ONHOOK, NULL); + zap_channel_done(zchan); + if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); } - if (chan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(chan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(chan, ZAP_COMMAND_GENERATE_RING_OFF, 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 = chan; - zap_channel_close(&chan); + closed_chan = zchan; + zap_channel_close(&zchan); zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 7a280f91ad..47a995019b 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -41,6 +41,7 @@ static struct { uint32_t wink_ms; uint32_t flash_ms; uint32_t eclevel; + uint32_t etlevel; } zt_globals; #define ZT_INVALID_SOCKET -1 @@ -61,24 +62,21 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za memset(&ztp, 0, sizeof(ztp)); for(x = start; x < end; x++) { - zap_channel_t *chan; + zap_channel_t *zchan; zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); - if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { -#if 1 if (ioctl(sockfd, ZT_SPECIFY, &x)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); close(sockfd); continue; } -#endif -#if 1 - if (chan->type == ZAP_CHAN_TYPE_DQ921) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { struct zt_bufferinfo binfo; memset(&binfo, 0, sizeof(binfo)); binfo.txbufpolicy = 0; @@ -86,12 +84,11 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za binfo.numbufs = 32; binfo.bufsize = 1024; if (ioctl(sockfd, ZT_SET_BUFINFO, &binfo)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } } -#endif if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; @@ -136,63 +133,55 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za break; } if (ioctl(ctlfd, ZT_CHANCONFIG, &cc)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", + zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); close(sockfd); break; } - - len = zt_globals.eclevel; - if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } } - if (chan->type != ZAP_CHAN_TYPE_DQ921 && chan->type != ZAP_CHAN_TYPE_DQ931) { + if (zchan->type != ZAP_CHAN_TYPE_DQ921 && zchan->type != ZAP_CHAN_TYPE_DQ931) { len = zt_globals.codec_ms * 8; - if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + if (ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; + zchan->packet_len = len; + zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8; - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; + if (zchan->effective_codec == ZAP_CODEC_SLIN) { + zchan->packet_len *= 2; } } if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } - if (chan->type == ZAP_CHAN_TYPE_DQ921) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } } - zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); - chan->rate = 8000; - chan->physical_span_id = ztp.span_no; - chan->physical_chan_id = ztp.chan_no; + 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) { if (ztp.g711_type == ZT_G711_ALAW) { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; } else { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; } } @@ -201,17 +190,17 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za ztp.flash_time = zt_globals.flash_ms; if (ioctl(sockfd, ZT_SET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); close(sockfd); continue; } if (!zap_strlen_zero(name)) { - zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); + zap_copy_string(zchan->chan_name, name, sizeof(zchan->chan_name)); } if (!zap_strlen_zero(number)) { - zap_copy_string(chan->chan_number, number, sizeof(chan->chan_number)); + zap_copy_string(zchan->chan_number, number, sizeof(zchan->chan_number)); } configured++; } else { @@ -339,6 +328,28 @@ static ZIO_OPEN_FUNCTION(zt_open) zchan->native_codec = zchan->effective_codec; } + if (zchan->type == ZAP_CHAN_TYPE_B) { + int one = 1; + if (ioctl(zchan->sockfd, ZT_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; + } + } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { + int len = zt_globals.eclevel; + if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + return ZAP_FAIL; + } + + len = zt_globals.etlevel; + if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + return ZAP_FAIL; + } + } } return ZAP_SUCCESS; } @@ -664,6 +675,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; zt_globals.eclevel = 64; + zt_globals.etlevel = 0; zt_interface.name = "zt"; zt_interface.configure = zt_configure; From 6da2de755fe024e6d5aa272f1ba475437428259c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 03:31:07 +0000 Subject: [PATCH 0561/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@281 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index db0584cde8..063fe6a5fa 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -280,7 +280,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 500) { - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->state >= ZAP_CHANNEL_STATE_IDLE) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); From 111d35e5a9e35e0e6358492bc8a50b26fb48a9bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 03:31:07 +0000 Subject: [PATCH 0562/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@281 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index db0584cde8..063fe6a5fa 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -280,7 +280,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { if (state_counter > 500) { - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->state >= ZAP_CHANNEL_STATE_IDLE) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); From 3f3d9401555425020eb16d1d4cb527edbcbf8251 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 03:56:28 +0000 Subject: [PATCH 0563/1766] dms uses proto disc other than 8 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@282 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index e1606b0809..232b2122c3 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -335,10 +335,6 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Message Type */ m->MesType = Mes[IOff++]; - if (m->ProtDisc != 8) { - return Q931E_UNKNOWN_MESSAGE; - } - /* Call table proc to unpack codec message */ RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); From 072df3d4b8e1b258892bf636c985b8d8a9b78659 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 03:56:28 +0000 Subject: [PATCH 0564/1766] dms uses proto disc other than 8 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@282 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index e1606b0809..232b2122c3 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -335,10 +335,6 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Message Type */ m->MesType = Mes[IOff++]; - if (m->ProtDisc != 8) { - return Q931E_UNKNOWN_MESSAGE; - } - /* Call table proc to unpack codec message */ RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); From 29411355a43b6279fa6830a6985f61deb6ede3b6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 04:05:37 +0000 Subject: [PATCH 0565/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@283 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1caa08823d..68712f0596 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -303,7 +303,8 @@ typedef enum { ZAP_CHANNEL_RINGING = (1 << 15), ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), - ZAP_CHANNEL_OUTBOUND = (1 << 18) + ZAP_CHANNEL_OUTBOUND = (1 << 18), + ZAP_CHANNEL_SUSPENDED = (1 << 19) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; From c1344ffdda5662028bc9dd858fa93b41768e385f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 21 Jun 2007 04:05:37 +0000 Subject: [PATCH 0566/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@283 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 1caa08823d..68712f0596 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -303,7 +303,8 @@ typedef enum { ZAP_CHANNEL_RINGING = (1 << 15), ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), - ZAP_CHANNEL_OUTBOUND = (1 << 18) + ZAP_CHANNEL_OUTBOUND = (1 << 18), + ZAP_CHANNEL_SUSPENDED = (1 << 19) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; From b041edc6053e1cbd458bd40cb75d35dade86b056 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 04:28:28 +0000 Subject: [PATCH 0567/1766] hack in DMS service message support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@284 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 1 + libs/openzap/src/isdn/include/Q931ie.h | 2 ++ libs/openzap/src/isdn/include/national.h | 2 ++ libs/openzap/src/isdn/nationalStateTE.c | 2 +- libs/openzap/src/isdn/nationalmes.c | 39 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 70a7e228e4..8d1efe8b77 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -2533,6 +2533,7 @@ L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA /* Octet 3 */ pie->Class = IBuf[Octet+Off] & 0x07; + pie->Spare = IBuf[Octet+Off] & 0x78; Off = Q931ReadExt(&IBuf[Octet], Off); Octet++; diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index f6f2870db0..dbca5b3990 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -63,6 +63,7 @@ typedef enum { /* 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 */ @@ -1060,6 +1061,7 @@ typedef struct { L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ + L3UCHAR Spare; /* Spare */ L3UCHAR Class; /* Class */ /* 000 Indicate channels */ /* 110 Single interface */ diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h index f6c79ed4c9..983a6de1dc 100644 --- a/libs/openzap/src/isdn/include/national.h +++ b/libs/openzap/src/isdn/include/national.h @@ -72,6 +72,8 @@ *****************************************************************************/ 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); +L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size); + /***************************************************************************** diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index fb2e7139c2..955453111f 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -67,7 +67,7 @@ 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,Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect); - Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE, Q931Umes_ConnectAck, Q931Pmes_ConnectAck); + Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); 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); diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 7dc73989e4..2f8b04394e 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -259,3 +259,42 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT return rc; } + + +/***************************************************************************** + + Function: DMSUmes_0x0f + +*****************************************************************************/ +L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) +//L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + L3INT rc=Q931E_NO_ERROR; + + if (mes->ProtDisc == 8) { + Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); + } + + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](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; +} From 2f9a50556fce44a69f209df14be3900f8072f0a0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 04:28:28 +0000 Subject: [PATCH 0568/1766] hack in DMS service message support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@284 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 1 + libs/freetdm/src/isdn/include/Q931ie.h | 2 ++ libs/freetdm/src/isdn/include/national.h | 2 ++ libs/freetdm/src/isdn/nationalStateTE.c | 2 +- libs/freetdm/src/isdn/nationalmes.c | 39 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 70a7e228e4..8d1efe8b77 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -2533,6 +2533,7 @@ L3INT Q931Uie_RestartInd(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA /* Octet 3 */ pie->Class = IBuf[Octet+Off] & 0x07; + pie->Spare = IBuf[Octet+Off] & 0x78; Off = Q931ReadExt(&IBuf[Octet], Off); Octet++; diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index f6f2870db0..dbca5b3990 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -63,6 +63,7 @@ typedef enum { /* 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 */ @@ -1060,6 +1061,7 @@ typedef struct { L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ + L3UCHAR Spare; /* Spare */ L3UCHAR Class; /* Class */ /* 000 Indicate channels */ /* 110 Single interface */ diff --git a/libs/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h index f6c79ed4c9..983a6de1dc 100644 --- a/libs/freetdm/src/isdn/include/national.h +++ b/libs/freetdm/src/isdn/include/national.h @@ -72,6 +72,8 @@ *****************************************************************************/ 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); +L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size); + /***************************************************************************** diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index fb2e7139c2..955453111f 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -67,7 +67,7 @@ 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,Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect); - Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE, Q931Umes_ConnectAck, Q931Pmes_ConnectAck); + Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); 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); diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 7dc73989e4..2f8b04394e 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -259,3 +259,42 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT return rc; } + + +/***************************************************************************** + + Function: DMSUmes_0x0f + +*****************************************************************************/ +L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) +//L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) +{ + L3INT OOff=0; + L3INT rc=Q931E_NO_ERROR; + + if (mes->ProtDisc == 8) { + Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); + } + + while(IOff < Size) + { + switch(IBuf[IOff]) + { + case Q931ie_CHANNEL_IDENTIFICATION: + rc = Q931Uie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](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; +} From b9634b84a0f0e4ff202f6162c45e4b0b5c910076 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 14:22:05 +0000 Subject: [PATCH 0569/1766] tweak dms service message handling. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@285 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/nationalmes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 2f8b04394e..75e313d90d 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -273,7 +273,7 @@ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes L3INT rc=Q931E_NO_ERROR; if (mes->ProtDisc == 8) { - Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); + return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); } while(IOff < Size) @@ -281,12 +281,12 @@ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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); + rc = Q931Uie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; From fb9d36c8a75f17cd1729a233c367679d804fec50 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 14:22:05 +0000 Subject: [PATCH 0570/1766] tweak dms service message handling. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@285 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/nationalmes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 2f8b04394e..75e313d90d 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -273,7 +273,7 @@ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes L3INT rc=Q931E_NO_ERROR; if (mes->ProtDisc == 8) { - Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); + return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); } while(IOff < Size) @@ -281,12 +281,12 @@ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes switch(IBuf[IOff]) { case Q931ie_CHANNEL_IDENTIFICATION: - rc = Q931Uie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); + 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); + rc = Q931Uie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); if(rc != Q931E_NO_ERROR) return rc; break; From 936459a5c0a9165c25ef077c8fea25afa405381c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 15:14:46 +0000 Subject: [PATCH 0571/1766] fix dms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@286 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 8d1efe8b77..2f4fa60b07 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1205,7 +1205,10 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * /* Octet 3.3 */ /* Temp fix. Assume B channel. H channels not supported */ pie->ChanSlot = IBuf[Octet+Off] & 0x7f; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); + /* 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++; } } From 0b76c793714eb3c92393c98763162977e5c30eb2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 15:14:46 +0000 Subject: [PATCH 0572/1766] fix dms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@286 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 8d1efe8b77..2f4fa60b07 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1205,7 +1205,10 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * /* Octet 3.3 */ /* Temp fix. Assume B channel. H channels not supported */ pie->ChanSlot = IBuf[Octet+Off] & 0x7f; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); + /* 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++; } } From dbc918f44bed9fddb35da9ba914abd40c728117c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 15:20:15 +0000 Subject: [PATCH 0573/1766] fix service message processing. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@287 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/nationalStateTE.c | 41 ++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index 955453111f..289e9c9de9 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -52,6 +52,8 @@ *****************************************************************************/ #include "national.h" +extern L3INT Q931L4HeaderSpace; +L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom); /***************************************************************************** Function: nationalCreateTE @@ -67,7 +69,7 @@ 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,Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect); - Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); + Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,DMSProc0x0fTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); 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); @@ -208,3 +210,40 @@ void nationalCreateTE(L3UCHAR i) Q931AddStateEntry(i,Q931_U25, */ } + +/***************************************************************************** + + Function: Q931ProcConnectAckTE + +*****************************************************************************/ +L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; + +} From 85274f5c73ad2deece928cc5dca3d733c5d74d13 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jun 2007 15:20:15 +0000 Subject: [PATCH 0574/1766] fix service message processing. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@287 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/nationalStateTE.c | 41 ++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index 955453111f..289e9c9de9 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -52,6 +52,8 @@ *****************************************************************************/ #include "national.h" +extern L3INT Q931L4HeaderSpace; +L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom); /***************************************************************************** Function: nationalCreateTE @@ -67,7 +69,7 @@ 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,Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect); - Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); + Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,DMSProc0x0fTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); 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); @@ -208,3 +210,40 @@ void nationalCreateTE(L3UCHAR i) Q931AddStateEntry(i,Q931_U25, */ } + +/***************************************************************************** + + Function: Q931ProcConnectAckTE + +*****************************************************************************/ +L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; + +} From e1dc87d54189bc5711ea52c102f123800230f4f5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 23 Jun 2007 18:51:10 +0000 Subject: [PATCH 0575/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@288 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 2 +- libs/openzap/docs/Doxygen.conf | 2 +- libs/openzap/src/include/openzap.h | 10 +++- libs/openzap/src/include/zap_types.h | 28 +++++++-- libs/openzap/src/testisdn.c | 9 ++- libs/openzap/src/zap_analog.c | 4 +- libs/openzap/src/zap_io.c | 46 ++++++++++++-- libs/openzap/src/zap_isdn.c | 90 ++++++++++++++++++++++++---- libs/openzap/src/zap_wanpipe.c | 4 +- libs/openzap/src/zap_zt.c | 62 +++++++++++++------ 10 files changed, 210 insertions(+), 47 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 17661180d7..03e8eacefc 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -119,7 +119,7 @@ testtones: $(SRC)/testtones.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread testanalog: $(SRC)/testanalog.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread diff --git a/libs/openzap/docs/Doxygen.conf b/libs/openzap/docs/Doxygen.conf index 03800ac6ff..2e0590e548 100644 --- a/libs/openzap/docs/Doxygen.conf +++ b/libs/openzap/docs/Doxygen.conf @@ -83,7 +83,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = .. ../include ../isdn ../isdn/include +INPUT = ../src ../src/include ../src/isdn ../src/isdn/include FILE_PATTERNS = *.c \ *.cc \ *.cxx \ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index cd3c3f920c..156e022300 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -174,6 +174,11 @@ #define zap_test_flag(obj, flag) ((obj)->flags & flag) #define zap_test_pflag(obj, flag) ((obj)->pflags & flag) + +#define zap_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag) +#define zap_clear_alarm_flag(obj, flag) (obj)->alarm_flags &= ~(flag) +#define zap_test_alarm_flag(obj, flag) ((obj)->alarm_flags & flag) + /*! \brief Set a flag on an arbitrary object \command obj the object to set the flags on @@ -324,6 +329,7 @@ struct zap_channel { zap_socket_t sockfd; zap_channel_flag_t flags; uint32_t pflags; + zap_alarm_flag_t alarm_flags; zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; @@ -423,7 +429,8 @@ struct zap_io_interface { zio_configure_t configure; zio_open_t open; zio_close_t close; - zio_destroy_channel_t destroy_channel; + zio_channel_destroy_t channel_destroy; + zio_get_alarms_t get_alarms; zio_command_t command; zio_wait_t wait; zio_read_t read; @@ -465,6 +472,7 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); void zap_channel_clear_needed_tones(zap_channel_t *zchan); +zap_status_t zap_channel_get_alarms(zap_channel_t *zchan); zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 68712f0596..818fed2af8 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -138,12 +138,24 @@ typedef enum { ZAP_OOB_FLASH, ZAP_OOB_RING_START, ZAP_OOB_RING_STOP, + ZAP_OOB_ALARM_TRAP, + ZAP_OOB_ALARM_CLEAR, ZAP_OOB_NOOP, ZAP_OOB_INVALID } zap_oob_event_t; -#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "NOOP", "INVALID" +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "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_flag_t; + typedef enum { ZAP_SIGTYPE_NONE, ZAP_SIGTYPE_ISDN, @@ -162,10 +174,13 @@ typedef enum { ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, ZAP_SIGEVENT_TONE_DETECTED, + ZAP_SIGEVENT_ALARM_TRAP, + ZAP_SIGEVENT_ALARM_CLEAR, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \ + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -322,9 +337,10 @@ typedef struct zap_span zap_span_t; #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_DESTROY_CHANNEL_ARGS (zap_channel_t *zchan) +#define ZIO_CHANNEL_DESTROY_ARGS (zap_channel_t *zchan) #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) @@ -338,7 +354,8 @@ 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_destroy_channel_t) ZIO_DESTROY_CHANNEL_ARGS ; +typedef zap_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_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 ; @@ -354,7 +371,8 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_DESTROY_CHANNEL_FUNCTION(name) zap_status_t name ZIO_DESTROY_CHANNEL_ARGS +#define ZIO_CHANNEL_DESTROY_FUNCTION(name) zap_status_t name ZIO_CHANNEL_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 diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 231215a4b1..bdfe66a522 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -9,9 +9,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) 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); @@ -19,7 +24,7 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_span_find(1, &span) != ZAP_SUCCESS) { + if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { fprintf(stderr, "Error finding OpenZAP span\n"); goto done; } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 063fe6a5fa..ba87ad1663 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -605,7 +605,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) return NULL; } -static zap_status_t process_event(zap_span_t *span, zap_event_t *event) +static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; zap_analog_data_t *data = event->channel->span->analog_data; @@ -708,7 +708,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) { zap_event_t *event; while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { - if (event->e_type == ZAP_OOB_NOOP) { + if (event->enum_id == ZAP_OOB_NOOP) { continue; } if (process_event(span, event) != ZAP_SUCCESS) { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3c05830d2f..3b1583d0eb 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -211,7 +211,7 @@ static uint32_t hashfromstring(void *ky) } -static zap_status_t zap_destroy_channel(zap_channel_t *zchan) +static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { @@ -226,9 +226,9 @@ static zap_status_t zap_destroy_channel(zap_channel_t *zchan) } - if (zchan->span->zio->destroy_channel) { + if (zchan->span->zio->channel_destroy) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); - if (zchan->span->zio->destroy_channel(zchan) == ZAP_SUCCESS) { + if (zchan->span->zio->channel_destroy(zchan) == ZAP_SUCCESS) { zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); } else { zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); @@ -239,6 +239,42 @@ static zap_status_t zap_destroy_channel(zap_channel_t *zchan) return ZAP_SUCCESS; } + + +zap_status_t zap_channel_get_alarms(zap_channel_t *zchan) +{ + zap_status_t status = ZAP_FAIL; + + if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + if (zchan->span->zio->get_alarms) { + if ((status = zchan->span->zio->get_alarms(zchan)) == ZAP_SUCCESS) { + *zchan->last_error = '\0'; + if (zap_test_alarm_flag(zchan, ZAP_ALARM_RED)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "RED/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_YELLOW)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "YELLOW/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_BLUE)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "BLUE/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_LOOPBACK)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "LOOP/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_RECOVER)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "RECOVER/"); + } + *(zchan->last_error + strlen(zchan->last_error) - 1) = '\0'; + + } + } else { + status = ZAP_NOTIMPL; + } + } + + return status; +} + zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; @@ -277,7 +313,7 @@ zap_status_t zap_span_close_all(void) span = &globals.spans[i]; for(j = 0; j < span->chan_count; j++) { - zap_destroy_channel(&span->channels[i]); + zap_channel_destroy(&span->channels[i]); } if (span->mutex) { @@ -1903,7 +1939,7 @@ zap_status_t zap_global_destroy(void) for(j = 1; j <= cur_span->chan_count; j++) { zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_destroy_channel(cur_chan); + zap_channel_destroy(cur_chan); } } zap_mutex_unlock(cur_span->mutex); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 22d737aa83..2d1a58c334 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -46,13 +46,7 @@ static L2ULONG zap_time_now() { -#ifdef WIN32 - return timeGetTime(); -#else - struct timeval tv; - gettimeofday(&tv, NULL); - return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); -#endif + return zap_current_time_in_ms(); } static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) @@ -173,9 +167,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret; - //char bb[4096] = ""; - //print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); - //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); + char bb[4096] = ""; + print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) @@ -395,6 +389,79 @@ static __inline__ void check_state(zap_span_t *span) } } +static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_sigmsg_t sig; + zap_isdn_data_t *data = span->isdn_data; + + 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)); + + switch(event->enum_id) { + case ZAP_OOB_ALARM_TRAP: + { + sig.event_id = ZAP_OOB_ALARM_TRAP; + if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_TERMINATING); + } + zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + zap_channel_get_alarms(event->channel); + data->sig_cb(&sig); + 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: + { + sig.event_id = ZAP_OOB_ALARM_CLEAR; + zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + zap_channel_get_alarms(event->channel); + data->sig_cb(&sig); + } + break; + } + + return ZAP_SUCCESS; +} + + +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!\n"); + } + break; + default: + break; + } +} + static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; @@ -417,7 +484,8 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) Q921TimerTick(&data->q921); check_state(span); - + check_events(span); + switch(status) { case ZAP_FAIL: { diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 3e52568fb1..7a7536f914 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -914,7 +914,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } -static ZIO_DESTROY_CHANNEL_FUNCTION(wanpipe_destroy_channel) +static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { if (zchan->sockfd > -1) { close(zchan->sockfd); @@ -947,7 +947,7 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wanpipe_interface.poll_event = wanpipe_poll_event; #endif wanpipe_interface.next_event = wanpipe_next_event; - wanpipe_interface.destroy_channel = wanpipe_destroy_channel; + wanpipe_interface.channel_destroy = wanpipe_channel_destroy; *zio = &wanpipe_interface; return ZAP_SUCCESS; diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 47a995019b..5f2a60b052 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -45,19 +45,14 @@ static struct { } zt_globals; #define ZT_INVALID_SOCKET -1 +static const char ctlpath[] = "/dev/zap/ctl"; +static zap_socket_t CONTROL_FD = ZT_INVALID_SOCKET; static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) { unsigned configured = 0, x; - const char ctlpath[] = "/dev/zap/ctl"; char path[] = "/dev/zap/channel"; zt_params_t ztp; - zap_socket_t ctlfd = ZT_INVALID_SOCKET; - - if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { - zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); - return 0; - } memset(&ztp, 0, sizeof(ztp)); @@ -71,7 +66,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { if (ioctl(sockfd, ZT_SPECIFY, &x)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, sockfd, strerror(errno)); close(sockfd); continue; } @@ -132,9 +127,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za default: break; } - if (ioctl(ctlfd, ZT_CHANCONFIG, &cc)) { + if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) { zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", - path, x, ctlfd, strerror(errno)); + path, x, CONTROL_FD, strerror(errno)); close(sockfd); break; } @@ -208,7 +203,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - close(ctlfd); + return configured; } @@ -448,6 +443,25 @@ static ZIO_COMMAND_FUNCTION(zt_command) return ZAP_SUCCESS; } +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, ZT_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; +} + + static ZIO_WAIT_FUNCTION(zt_wait) { int32_t inflags = 0; @@ -478,10 +492,9 @@ static ZIO_WAIT_FUNCTION(zt_wait) } if (result > 0) { - *flags = pfds[0].revents; + inflags = pfds[0].revents; } - *flags = ZAP_NO_FLAGS; if (result < 0){ @@ -595,6 +608,16 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) } } break; + case ZT_EVENT_ALARM: + { + event_id = ZAP_OOB_ALARM_TRAP; + } + break; + case ZT_EVENT_NOALARM: + { + event_id = ZAP_OOB_ALARM_CLEAR; + } + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); @@ -655,7 +678,7 @@ static ZIO_WRITE_FUNCTION(zt_write) return ZAP_FAIL; } -static ZIO_DESTROY_CHANNEL_FUNCTION(zt_destroy_channel) +static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) { close(zchan->sockfd); zchan->sockfd = ZT_INVALID_SOCKET; @@ -671,6 +694,11 @@ zap_status_t zt_init(zap_io_interface_t **zio) memset(&zt_interface, 0, sizeof(zt_interface)); memset(&zt_globals, 0, sizeof(zt_globals)); + if ((CONTROL_FD = open(ctlpath, O_RDWR)) < 0) { + zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); + return 0; + } + zt_globals.codec_ms = 20; zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; @@ -688,8 +716,8 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_interface.write = zt_write; zt_interface.poll_event = zt_poll_event; zt_interface.next_event = zt_next_event; - zt_interface.destroy_channel = zt_destroy_channel; - + zt_interface.channel_destroy = zt_channel_destroy; + zt_interface.get_alarms = zt_get_alarms; *zio = &zt_interface; return ZAP_SUCCESS; @@ -697,7 +725,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zap_status_t zt_destroy(void) { - + close(CONTROL_FD); memset(&zt_interface, 0, sizeof(zt_interface)); return ZAP_SUCCESS; } From dffaad2ab7ca60ad05bdfd9a6daed643cb1d44ed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 23 Jun 2007 18:51:10 +0000 Subject: [PATCH 0576/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@288 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 2 +- libs/freetdm/docs/Doxygen.conf | 2 +- libs/freetdm/src/include/openzap.h | 10 +++- libs/freetdm/src/include/zap_types.h | 28 +++++++-- libs/freetdm/src/testisdn.c | 9 ++- libs/freetdm/src/zap_analog.c | 4 +- libs/freetdm/src/zap_io.c | 46 ++++++++++++-- libs/freetdm/src/zap_isdn.c | 90 ++++++++++++++++++++++++---- libs/freetdm/src/zap_wanpipe.c | 4 +- libs/freetdm/src/zap_zt.c | 62 +++++++++++++------ 10 files changed, 210 insertions(+), 47 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 17661180d7..03e8eacefc 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -119,7 +119,7 @@ testtones: $(SRC)/testtones.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread testanalog: $(SRC)/testanalog.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread diff --git a/libs/freetdm/docs/Doxygen.conf b/libs/freetdm/docs/Doxygen.conf index 03800ac6ff..2e0590e548 100644 --- a/libs/freetdm/docs/Doxygen.conf +++ b/libs/freetdm/docs/Doxygen.conf @@ -83,7 +83,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = .. ../include ../isdn ../isdn/include +INPUT = ../src ../src/include ../src/isdn ../src/isdn/include FILE_PATTERNS = *.c \ *.cc \ *.cxx \ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index cd3c3f920c..156e022300 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -174,6 +174,11 @@ #define zap_test_flag(obj, flag) ((obj)->flags & flag) #define zap_test_pflag(obj, flag) ((obj)->pflags & flag) + +#define zap_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag) +#define zap_clear_alarm_flag(obj, flag) (obj)->alarm_flags &= ~(flag) +#define zap_test_alarm_flag(obj, flag) ((obj)->alarm_flags & flag) + /*! \brief Set a flag on an arbitrary object \command obj the object to set the flags on @@ -324,6 +329,7 @@ struct zap_channel { zap_socket_t sockfd; zap_channel_flag_t flags; uint32_t pflags; + zap_alarm_flag_t alarm_flags; zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; @@ -423,7 +429,8 @@ struct zap_io_interface { zio_configure_t configure; zio_open_t open; zio_close_t close; - zio_destroy_channel_t destroy_channel; + zio_channel_destroy_t channel_destroy; + zio_get_alarms_t get_alarms; zio_command_t command; zio_wait_t wait; zio_read_t read; @@ -465,6 +472,7 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); void zap_channel_clear_needed_tones(zap_channel_t *zchan); +zap_status_t zap_channel_get_alarms(zap_channel_t *zchan); zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 68712f0596..818fed2af8 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -138,12 +138,24 @@ typedef enum { ZAP_OOB_FLASH, ZAP_OOB_RING_START, ZAP_OOB_RING_STOP, + ZAP_OOB_ALARM_TRAP, + ZAP_OOB_ALARM_CLEAR, ZAP_OOB_NOOP, ZAP_OOB_INVALID } zap_oob_event_t; -#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "NOOP", "INVALID" +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "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_flag_t; + typedef enum { ZAP_SIGTYPE_NONE, ZAP_SIGTYPE_ISDN, @@ -162,10 +174,13 @@ typedef enum { ZAP_SIGEVENT_PROGRESS_MEDIA, ZAP_SIGEVENT_NOTIFY, ZAP_SIGEVENT_TONE_DETECTED, + ZAP_SIGEVENT_ALARM_TRAP, + ZAP_SIGEVENT_ALARM_CLEAR, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_INVALID } zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "MISC", "INVALID" +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \ + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -322,9 +337,10 @@ typedef struct zap_span zap_span_t; #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_DESTROY_CHANNEL_ARGS (zap_channel_t *zchan) +#define ZIO_CHANNEL_DESTROY_ARGS (zap_channel_t *zchan) #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) @@ -338,7 +354,8 @@ 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_destroy_channel_t) ZIO_DESTROY_CHANNEL_ARGS ; +typedef zap_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_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 ; @@ -354,7 +371,8 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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_DESTROY_CHANNEL_FUNCTION(name) zap_status_t name ZIO_DESTROY_CHANNEL_ARGS +#define ZIO_CHANNEL_DESTROY_FUNCTION(name) zap_status_t name ZIO_CHANNEL_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 diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 231215a4b1..bdfe66a522 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -9,9 +9,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) 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); @@ -19,7 +24,7 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_span_find(1, &span) != ZAP_SUCCESS) { + if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { fprintf(stderr, "Error finding OpenZAP span\n"); goto done; } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 063fe6a5fa..ba87ad1663 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -605,7 +605,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) return NULL; } -static zap_status_t process_event(zap_span_t *span, zap_event_t *event) +static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; zap_analog_data_t *data = event->channel->span->analog_data; @@ -708,7 +708,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) { zap_event_t *event; while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { - if (event->e_type == ZAP_OOB_NOOP) { + if (event->enum_id == ZAP_OOB_NOOP) { continue; } if (process_event(span, event) != ZAP_SUCCESS) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3c05830d2f..3b1583d0eb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -211,7 +211,7 @@ static uint32_t hashfromstring(void *ky) } -static zap_status_t zap_destroy_channel(zap_channel_t *zchan) +static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { @@ -226,9 +226,9 @@ static zap_status_t zap_destroy_channel(zap_channel_t *zchan) } - if (zchan->span->zio->destroy_channel) { + if (zchan->span->zio->channel_destroy) { zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); - if (zchan->span->zio->destroy_channel(zchan) == ZAP_SUCCESS) { + if (zchan->span->zio->channel_destroy(zchan) == ZAP_SUCCESS) { zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); } else { zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); @@ -239,6 +239,42 @@ static zap_status_t zap_destroy_channel(zap_channel_t *zchan) return ZAP_SUCCESS; } + + +zap_status_t zap_channel_get_alarms(zap_channel_t *zchan) +{ + zap_status_t status = ZAP_FAIL; + + if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + if (zchan->span->zio->get_alarms) { + if ((status = zchan->span->zio->get_alarms(zchan)) == ZAP_SUCCESS) { + *zchan->last_error = '\0'; + if (zap_test_alarm_flag(zchan, ZAP_ALARM_RED)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "RED/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_YELLOW)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "YELLOW/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_BLUE)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "BLUE/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_LOOPBACK)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "LOOP/"); + } + if (zap_test_alarm_flag(zchan, ZAP_ALARM_RECOVER)) { + snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "RECOVER/"); + } + *(zchan->last_error + strlen(zchan->last_error) - 1) = '\0'; + + } + } else { + status = ZAP_NOTIMPL; + } + } + + return status; +} + zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; @@ -277,7 +313,7 @@ zap_status_t zap_span_close_all(void) span = &globals.spans[i]; for(j = 0; j < span->chan_count; j++) { - zap_destroy_channel(&span->channels[i]); + zap_channel_destroy(&span->channels[i]); } if (span->mutex) { @@ -1903,7 +1939,7 @@ zap_status_t zap_global_destroy(void) for(j = 1; j <= cur_span->chan_count; j++) { zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_destroy_channel(cur_chan); + zap_channel_destroy(cur_chan); } } zap_mutex_unlock(cur_span->mutex); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 22d737aa83..2d1a58c334 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -46,13 +46,7 @@ static L2ULONG zap_time_now() { -#ifdef WIN32 - return timeGetTime(); -#else - struct timeval tv; - gettimeofday(&tv, NULL); - return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); -#endif + return zap_current_time_in_ms(); } static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) @@ -173,9 +167,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) { int ret; - //char bb[4096] = ""; - //print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); - //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); + char bb[4096] = ""; + print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); ret = Q931Rx23(pvt, msg, mlen); if (ret != 0) @@ -395,6 +389,79 @@ static __inline__ void check_state(zap_span_t *span) } } +static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_sigmsg_t sig; + zap_isdn_data_t *data = span->isdn_data; + + 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)); + + switch(event->enum_id) { + case ZAP_OOB_ALARM_TRAP: + { + sig.event_id = ZAP_OOB_ALARM_TRAP; + if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_TERMINATING); + } + zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + zap_channel_get_alarms(event->channel); + data->sig_cb(&sig); + 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: + { + sig.event_id = ZAP_OOB_ALARM_CLEAR; + zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + zap_channel_get_alarms(event->channel); + data->sig_cb(&sig); + } + break; + } + + return ZAP_SUCCESS; +} + + +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!\n"); + } + break; + default: + break; + } +} + static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; @@ -417,7 +484,8 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) Q921TimerTick(&data->q921); check_state(span); - + check_events(span); + switch(status) { case ZAP_FAIL: { diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 3e52568fb1..7a7536f914 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -914,7 +914,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } -static ZIO_DESTROY_CHANNEL_FUNCTION(wanpipe_destroy_channel) +static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { if (zchan->sockfd > -1) { close(zchan->sockfd); @@ -947,7 +947,7 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) wanpipe_interface.poll_event = wanpipe_poll_event; #endif wanpipe_interface.next_event = wanpipe_next_event; - wanpipe_interface.destroy_channel = wanpipe_destroy_channel; + wanpipe_interface.channel_destroy = wanpipe_channel_destroy; *zio = &wanpipe_interface; return ZAP_SUCCESS; diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 47a995019b..5f2a60b052 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -45,19 +45,14 @@ static struct { } zt_globals; #define ZT_INVALID_SOCKET -1 +static const char ctlpath[] = "/dev/zap/ctl"; +static zap_socket_t CONTROL_FD = ZT_INVALID_SOCKET; static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) { unsigned configured = 0, x; - const char ctlpath[] = "/dev/zap/ctl"; char path[] = "/dev/zap/channel"; zt_params_t ztp; - zap_socket_t ctlfd = ZT_INVALID_SOCKET; - - if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { - zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); - return 0; - } memset(&ztp, 0, sizeof(ztp)); @@ -71,7 +66,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { if (ioctl(sockfd, ZT_SPECIFY, &x)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno)); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, sockfd, strerror(errno)); close(sockfd); continue; } @@ -132,9 +127,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za default: break; } - if (ioctl(ctlfd, ZT_CHANCONFIG, &cc)) { + if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) { zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", - path, x, ctlfd, strerror(errno)); + path, x, CONTROL_FD, strerror(errno)); close(sockfd); break; } @@ -208,7 +203,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - close(ctlfd); + return configured; } @@ -448,6 +443,25 @@ static ZIO_COMMAND_FUNCTION(zt_command) return ZAP_SUCCESS; } +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, ZT_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; +} + + static ZIO_WAIT_FUNCTION(zt_wait) { int32_t inflags = 0; @@ -478,10 +492,9 @@ static ZIO_WAIT_FUNCTION(zt_wait) } if (result > 0) { - *flags = pfds[0].revents; + inflags = pfds[0].revents; } - *flags = ZAP_NO_FLAGS; if (result < 0){ @@ -595,6 +608,16 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) } } break; + case ZT_EVENT_ALARM: + { + event_id = ZAP_OOB_ALARM_TRAP; + } + break; + case ZT_EVENT_NOALARM: + { + event_id = ZAP_OOB_ALARM_CLEAR; + } + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); @@ -655,7 +678,7 @@ static ZIO_WRITE_FUNCTION(zt_write) return ZAP_FAIL; } -static ZIO_DESTROY_CHANNEL_FUNCTION(zt_destroy_channel) +static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) { close(zchan->sockfd); zchan->sockfd = ZT_INVALID_SOCKET; @@ -671,6 +694,11 @@ zap_status_t zt_init(zap_io_interface_t **zio) memset(&zt_interface, 0, sizeof(zt_interface)); memset(&zt_globals, 0, sizeof(zt_globals)); + if ((CONTROL_FD = open(ctlpath, O_RDWR)) < 0) { + zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); + return 0; + } + zt_globals.codec_ms = 20; zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; @@ -688,8 +716,8 @@ zap_status_t zt_init(zap_io_interface_t **zio) zt_interface.write = zt_write; zt_interface.poll_event = zt_poll_event; zt_interface.next_event = zt_next_event; - zt_interface.destroy_channel = zt_destroy_channel; - + zt_interface.channel_destroy = zt_channel_destroy; + zt_interface.get_alarms = zt_get_alarms; *zio = &zt_interface; return ZAP_SUCCESS; @@ -697,7 +725,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) zap_status_t zt_destroy(void) { - + close(CONTROL_FD); memset(&zt_interface, 0, sizeof(zt_interface)); return ZAP_SUCCESS; } From 84e8ad398e73ed00e9daabd3e9aededd1b088fab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 25 Jun 2007 05:26:37 +0000 Subject: [PATCH 0577/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@289 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 3 +- libs/openzap/src/testanalog.c | 4 +- libs/openzap/src/testisdn.c | 6 +- libs/openzap/src/zap_analog.c | 40 +++++++------ libs/openzap/src/zap_io.c | 8 +-- libs/openzap/src/zap_isdn.c | 94 ++++++++++++++++-------------- 6 files changed, 80 insertions(+), 75 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 156e022300..12bc936a75 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -408,8 +408,7 @@ struct zap_span { zap_trunk_type_t trunk_type; zap_analog_start_type_t start_type; zap_signal_type_t signal_type; - struct zap_isdn_data *isdn_data; - struct zap_analog_data *analog_data; + void *signal_data; zap_event_t event_header; char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index cd480e2ba5..dc90861834 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -62,6 +62,7 @@ int main(int argc, char *argv[]) { zap_span_t *span; int span_id; + zap_analog_data_t *analog_data; if (argc < 2) { printf("usage %s \n", argv[0]); @@ -88,9 +89,10 @@ int main(int argc, char *argv[]) zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); goto done; } + analog_data = span->signal_data; zap_analog_start(span); - while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { + while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { zap_sleep(1 * 1000); } diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index bdfe66a522..79771489f1 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -9,7 +9,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) int main(int argc, char *argv[]) { zap_span_t *span; - + zap_isdn_data_t *data; + zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); if (argc < 2) { @@ -31,13 +32,14 @@ int main(int argc, char *argv[]) if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, on_signal) == ZAP_SUCCESS) { + data = span->signal_data; zap_isdn_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } - while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { + while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { zap_sleep(1 * 1000); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index ba87ad1663..23b1ec1a55 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -74,7 +74,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) 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; assert(sig_cb != NULL); if (span->signal_type) { @@ -90,14 +90,15 @@ zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t max_dialstr = 11; } - span->analog_data = malloc(sizeof(*span->analog_data)); - memset(span->analog_data, 0, sizeof(*span->analog_data)); - assert(span->analog_data != NULL); + analog_data = malloc(sizeof(*analog_data)); + memset(analog_data, 0, sizeof(*analog_data)); + assert(analog_data != NULL); - span->analog_data->digit_timeout = digit_timeout; - span->analog_data->max_dialstr = max_dialstr; - span->analog_data->sig_cb = sig_cb; + analog_data->digit_timeout = digit_timeout; + analog_data->max_dialstr = max_dialstr; + analog_data->sig_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; + span->signal_data = analog_data; span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call; zap_span_load_tones(span, tonemap); @@ -173,7 +174,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128] = ""; zap_size_t dtmf_offset = 0; - zap_analog_data_t *data = zchan->span->analog_data; + zap_analog_data_t *analog_data = zchan->span->signal_data; zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; zap_sigmsg_t sig; @@ -368,7 +369,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_UP; } - data->sig_cb(&sig); + analog_data->sig_cb(&sig); continue; } break; @@ -388,7 +389,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_string(zchan->caller_data.dnis, dtmf); } - data->sig_cb(&sig); + analog_data->sig_cb(&sig); continue; } break; @@ -396,7 +397,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_done(zchan); sig.event_id = ZAP_SIGEVENT_STOP; - data->sig_cb(&sig); + analog_data->sig_cb(&sig); goto done; } break; @@ -479,7 +480,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } - if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + if (last_digit && ((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; @@ -511,7 +512,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zchan->detected_tones[i]) { zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(zchan->detected_tones[i])); sig.raw_data = &i; - data->sig_cb(&sig); + analog_data->sig_cb(&sig); } } @@ -608,7 +609,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; - zap_analog_data_t *data = event->channel->span->analog_data; + zap_analog_data_t *analog_data = event->channel->span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -655,7 +656,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { sig.event_id = ZAP_SIGEVENT_FLASH; - data->sig_cb(&sig); + analog_data->sig_cb(&sig); if (event->channel->token_count == 1) { zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); @@ -693,11 +694,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even static void *zap_analog_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_analog_data_t *data = span->analog_data; + zap_analog_data_t *analog_data = span->signal_data; zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); - while(zap_test_flag(data, ZAP_ANALOG_RUNNING)) { + while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { int waitms = 10; zap_status_t status; @@ -731,7 +732,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) end: - zap_clear_flag(data, ZAP_ANALOG_RUNNING); + zap_clear_flag(analog_data, ZAP_ANALOG_RUNNING); zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n"); @@ -742,7 +743,8 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) zap_status_t zap_analog_start(zap_span_t *span) { - zap_set_flag(span->analog_data, ZAP_ANALOG_RUNNING); + 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); } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3b1583d0eb..77bd0ecc17 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -319,12 +319,8 @@ zap_status_t zap_span_close_all(void) if (span->mutex) { zap_mutex_destroy(&span->mutex); } - if (span->isdn_data) { - free(span->isdn_data); - } - if (span->analog_data) { - free(span->isdn_data); - } + + zap_safe_free(span->signal_data); } zap_mutex_unlock(globals.mutex); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 2d1a58c334..db5ffdfadb 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -65,14 +65,14 @@ static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { zap_span_t *span = (zap_span_t *) pvt; - zap_isdn_data_t *data = span->isdn_data; + zap_isdn_data_t *isdn_data = span->signal_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); int chan_id = chanid->ChanSlot; zap_channel_t *zchan = NULL; assert(span != NULL); - assert(data != NULL); + assert(isdn_data != NULL); if (chan_id) { zchan = &span->channels[chan_id]; @@ -181,6 +181,8 @@ 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)); @@ -190,13 +192,13 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) #endif assert(span != NULL); - return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; + return zap_channel_write(isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } static __inline__ void state_advance(zap_channel_t *zchan) { Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data; - zap_isdn_data_t *data = zchan->span->isdn_data; + zap_isdn_data_t *isdn_data = zchan->span->signal_data; zap_sigmsg_t sig; zap_status_t status; @@ -218,12 +220,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_PROGRESS; - Q931Rx43(&data->q931, (void *)gen, gen->Size); + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } break; @@ -231,7 +233,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_START; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -248,12 +250,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_ALERTING; - Q931Rx43(&data->q931, (void *)gen, gen->Size); + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } break; @@ -261,13 +263,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_CONNECT; gen->BearerCap = 0; - Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + Q931Rx43(&isdn_data->q931, (void *)gen, zchan->caller_data.raw_data_len); } } break; @@ -344,7 +346,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); //gen->Size += strlen(zchan->caller_data.ani); - Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); + Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -360,15 +362,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) cause.Value = (unsigned char) zchan->caller_data.hangup_cause; *cause.Diag = '\0'; gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); - Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); + Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); } break; case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; - status = data->sig_cb(&sig); + status = isdn_data->sig_cb(&sig); gen->MesType = Q931mes_RELEASE; - Q931Rx43(&data->q931, (void *)gen, gen->Size); + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } default: break; @@ -392,7 +394,7 @@ static __inline__ void check_state(zap_span_t *span) static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; - zap_isdn_data_t *data = span->isdn_data; + zap_isdn_data_t *isdn_data = span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -411,7 +413,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - data->sig_cb(&sig); + isdn_data->sig_cb(&sig); 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, @@ -423,7 +425,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - data->sig_cb(&sig); + isdn_data->sig_cb(&sig); } break; } @@ -465,7 +467,7 @@ static __inline__ void check_events(zap_span_t *span) static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_isdn_data_t *data = span->isdn_data; + zap_isdn_data_t *isdn_data = span->signal_data; unsigned char buf[1024]; zap_size_t len = sizeof(buf); int errs = 0; @@ -476,13 +478,13 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n"); - Q921Start(&data->q921); + Q921Start(&isdn_data->q921); - while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { + while(zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; - zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); + zap_status_t status = zap_channel_wait(isdn_data->dchan, &flags, 100); - Q921TimerTick(&data->q921); + Q921TimerTick(&isdn_data->q921); check_state(span); check_events(span); @@ -499,7 +501,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) case ZAP_TIMEOUT: { /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ - /*Q931TimeTick(data->q931, L3ULONG ms);*/ + /*Q931TimeTick(isdn_data->q931, L3ULONG ms);*/ errs = 0; } break; @@ -508,7 +510,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) errs = 0; if (flags & ZAP_READ) { len = sizeof(buf); - if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { + if (zap_channel_read(isdn_data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG //char bb[4096] = ""; //print_hex_bytes(buf, len, bb, sizeof(bb)); @@ -517,8 +519,8 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif - Q921QueueHDLCFrame(&data->q921, buf, (int)len); - Q921Rx12(&data->q921); + Q921QueueHDLCFrame(&isdn_data->q921, buf, (int)len); + Q921Rx12(&isdn_data->q921); } } else { zap_log(ZAP_LOG_DEBUG, "No Read FLAG!\n"); @@ -531,9 +533,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) done: - zap_channel_close(&data->dchans[0]); - zap_channel_close(&data->dchans[1]); - zap_clear_flag(span->isdn_data, ZAP_ISDN_RUNNING); + 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); @@ -554,7 +556,8 @@ zap_status_t zap_isdn_init(void) zap_status_t zap_isdn_start(zap_span_t *span) { - zap_set_flag(span->isdn_data, ZAP_ISDN_RUNNING); + zap_isdn_data_t *isdn_data = span->signal_data; + zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); return zap_thread_create_detached(zap_isdn_run, span); } @@ -572,7 +575,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D { uint32_t i, x = 0; zap_channel_t *dchans[2] = {0}; - + zap_isdn_data_t *isdn_data; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; @@ -598,16 +601,16 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D } - span->isdn_data = malloc(sizeof(*span->isdn_data)); - assert(span->isdn_data != NULL); - memset(span->isdn_data, 0, sizeof(*span->isdn_data)); + isdn_data = malloc(sizeof(*isdn_data)); + assert(isdn_data != NULL); + memset(isdn_data, 0, sizeof(*isdn_data)); - span->isdn_data->sig_cb = sig_cb; - span->isdn_data->dchans[0] = dchans[0]; - span->isdn_data->dchans[1] = dchans[1]; - span->isdn_data->dchan = span->isdn_data->dchans[0]; + isdn_data->sig_cb = sig_cb; + isdn_data->dchans[0] = dchans[0]; + isdn_data->dchans[1] = dchans[1]; + isdn_data->dchan = isdn_data->dchans[0]; - Q921_InitTrunk(&span->isdn_data->q921, + Q921_InitTrunk(&isdn_data->q921, 0, 0, mode, @@ -615,20 +618,21 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D zap_isdn_921_21, (Q921TxCB_t)zap_isdn_921_23, span, - &span->isdn_data->q931); + &isdn_data->q931); - Q931Api_InitTrunk(&span->isdn_data->q931, + Q931Api_InitTrunk(&isdn_data->q931, dialect, mode, span->trunk_type, zap_isdn_931_34, (Q931TxCB_t)q931_rx_32, zap_isdn_931_err, - &span->isdn_data->q921, + &isdn_data->q921, span); - span->isdn_data->q931.autoRestartAck = 1; - span->isdn_data->q931.autoConnectAck = 1; + isdn_data->q931.autoRestartAck = 1; + isdn_data->q931.autoConnectAck = 1; + span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; From 94e92fe25c0712c82fe5767be32edc43198b0e2d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 25 Jun 2007 05:26:37 +0000 Subject: [PATCH 0578/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@289 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 3 +- libs/freetdm/src/testanalog.c | 4 +- libs/freetdm/src/testisdn.c | 6 +- libs/freetdm/src/zap_analog.c | 40 +++++++------ libs/freetdm/src/zap_io.c | 8 +-- libs/freetdm/src/zap_isdn.c | 94 ++++++++++++++++-------------- 6 files changed, 80 insertions(+), 75 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 156e022300..12bc936a75 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -408,8 +408,7 @@ struct zap_span { zap_trunk_type_t trunk_type; zap_analog_start_type_t start_type; zap_signal_type_t signal_type; - struct zap_isdn_data *isdn_data; - struct zap_analog_data *analog_data; + void *signal_data; zap_event_t event_header; char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index cd480e2ba5..dc90861834 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -62,6 +62,7 @@ int main(int argc, char *argv[]) { zap_span_t *span; int span_id; + zap_analog_data_t *analog_data; if (argc < 2) { printf("usage %s \n", argv[0]); @@ -88,9 +89,10 @@ int main(int argc, char *argv[]) zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); goto done; } + analog_data = span->signal_data; zap_analog_start(span); - while(zap_test_flag(span->analog_data, ZAP_ANALOG_RUNNING)) { + while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { zap_sleep(1 * 1000); } diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index bdfe66a522..79771489f1 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -9,7 +9,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) int main(int argc, char *argv[]) { zap_span_t *span; - + zap_isdn_data_t *data; + zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); if (argc < 2) { @@ -31,13 +32,14 @@ int main(int argc, char *argv[]) if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, on_signal) == ZAP_SUCCESS) { + data = span->signal_data; zap_isdn_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } - while(zap_test_flag(span->isdn_data, ZAP_ISDN_RUNNING)) { + while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { zap_sleep(1 * 1000); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index ba87ad1663..23b1ec1a55 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -74,7 +74,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) 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; assert(sig_cb != NULL); if (span->signal_type) { @@ -90,14 +90,15 @@ zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t max_dialstr = 11; } - span->analog_data = malloc(sizeof(*span->analog_data)); - memset(span->analog_data, 0, sizeof(*span->analog_data)); - assert(span->analog_data != NULL); + analog_data = malloc(sizeof(*analog_data)); + memset(analog_data, 0, sizeof(*analog_data)); + assert(analog_data != NULL); - span->analog_data->digit_timeout = digit_timeout; - span->analog_data->max_dialstr = max_dialstr; - span->analog_data->sig_cb = sig_cb; + analog_data->digit_timeout = digit_timeout; + analog_data->max_dialstr = max_dialstr; + analog_data->sig_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; + span->signal_data = analog_data; span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call; zap_span_load_tones(span, tonemap); @@ -173,7 +174,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_tone_type_t tt = ZAP_TONE_DTMF; char dtmf[128] = ""; zap_size_t dtmf_offset = 0; - zap_analog_data_t *data = zchan->span->analog_data; + zap_analog_data_t *analog_data = zchan->span->signal_data; zap_channel_t *closed_chan; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; zap_sigmsg_t sig; @@ -368,7 +369,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_UP; } - data->sig_cb(&sig); + analog_data->sig_cb(&sig); continue; } break; @@ -388,7 +389,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_string(zchan->caller_data.dnis, dtmf); } - data->sig_cb(&sig); + analog_data->sig_cb(&sig); continue; } break; @@ -396,7 +397,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { zap_channel_done(zchan); sig.event_id = ZAP_SIGEVENT_STOP; - data->sig_cb(&sig); + analog_data->sig_cb(&sig); goto done; } break; @@ -479,7 +480,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } - if (last_digit && ((elapsed - last_digit > data->digit_timeout) || strlen(dtmf) > data->max_dialstr)) { + if (last_digit && ((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; @@ -511,7 +512,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zchan->detected_tones[i]) { zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(zchan->detected_tones[i])); sig.raw_data = &i; - data->sig_cb(&sig); + analog_data->sig_cb(&sig); } } @@ -608,7 +609,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; - zap_analog_data_t *data = event->channel->span->analog_data; + zap_analog_data_t *analog_data = event->channel->span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -655,7 +656,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { sig.event_id = ZAP_SIGEVENT_FLASH; - data->sig_cb(&sig); + analog_data->sig_cb(&sig); if (event->channel->token_count == 1) { zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); @@ -693,11 +694,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even static void *zap_analog_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_analog_data_t *data = span->analog_data; + zap_analog_data_t *analog_data = span->signal_data; zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); - while(zap_test_flag(data, ZAP_ANALOG_RUNNING)) { + while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { int waitms = 10; zap_status_t status; @@ -731,7 +732,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) end: - zap_clear_flag(data, ZAP_ANALOG_RUNNING); + zap_clear_flag(analog_data, ZAP_ANALOG_RUNNING); zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n"); @@ -742,7 +743,8 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) zap_status_t zap_analog_start(zap_span_t *span) { - zap_set_flag(span->analog_data, ZAP_ANALOG_RUNNING); + 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); } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3b1583d0eb..77bd0ecc17 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -319,12 +319,8 @@ zap_status_t zap_span_close_all(void) if (span->mutex) { zap_mutex_destroy(&span->mutex); } - if (span->isdn_data) { - free(span->isdn_data); - } - if (span->analog_data) { - free(span->isdn_data); - } + + zap_safe_free(span->signal_data); } zap_mutex_unlock(globals.mutex); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 2d1a58c334..db5ffdfadb 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -65,14 +65,14 @@ static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { zap_span_t *span = (zap_span_t *) pvt; - zap_isdn_data_t *data = span->isdn_data; + zap_isdn_data_t *isdn_data = span->signal_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); int chan_id = chanid->ChanSlot; zap_channel_t *zchan = NULL; assert(span != NULL); - assert(data != NULL); + assert(isdn_data != NULL); if (chan_id) { zchan = &span->channels[chan_id]; @@ -181,6 +181,8 @@ 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)); @@ -190,13 +192,13 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) #endif assert(span != NULL); - return zap_channel_write(span->isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; + return zap_channel_write(isdn_data->dchan, msg, len, &len) == ZAP_SUCCESS ? 0 : -1; } static __inline__ void state_advance(zap_channel_t *zchan) { Q931mes_Generic *gen = (Q931mes_Generic *) zchan->caller_data.raw_data; - zap_isdn_data_t *data = zchan->span->isdn_data; + zap_isdn_data_t *isdn_data = zchan->span->signal_data; zap_sigmsg_t sig; zap_status_t status; @@ -218,12 +220,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_PROGRESS; - Q931Rx43(&data->q931, (void *)gen, gen->Size); + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } break; @@ -231,7 +233,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_START; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -248,12 +250,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_ALERTING; - Q931Rx43(&data->q931, (void *)gen, gen->Size); + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } break; @@ -261,13 +263,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_CONNECT; gen->BearerCap = 0; - Q931Rx43(&data->q931, (void *)gen, zchan->caller_data.raw_data_len); + Q931Rx43(&isdn_data->q931, (void *)gen, zchan->caller_data.raw_data_len); } } break; @@ -344,7 +346,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); //gen->Size += strlen(zchan->caller_data.ani); - Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); + Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -360,15 +362,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) cause.Value = (unsigned char) zchan->caller_data.hangup_cause; *cause.Diag = '\0'; gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); - Q931Rx43(&data->q931, (L3UCHAR *) gen, gen->Size); + Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); } break; case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; - status = data->sig_cb(&sig); + status = isdn_data->sig_cb(&sig); gen->MesType = Q931mes_RELEASE; - Q931Rx43(&data->q931, (void *)gen, gen->Size); + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } default: break; @@ -392,7 +394,7 @@ static __inline__ void check_state(zap_span_t *span) static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; - zap_isdn_data_t *data = span->isdn_data; + zap_isdn_data_t *isdn_data = span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -411,7 +413,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - data->sig_cb(&sig); + isdn_data->sig_cb(&sig); 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, @@ -423,7 +425,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - data->sig_cb(&sig); + isdn_data->sig_cb(&sig); } break; } @@ -465,7 +467,7 @@ static __inline__ void check_events(zap_span_t *span) static void *zap_isdn_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_isdn_data_t *data = span->isdn_data; + zap_isdn_data_t *isdn_data = span->signal_data; unsigned char buf[1024]; zap_size_t len = sizeof(buf); int errs = 0; @@ -476,13 +478,13 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n"); - Q921Start(&data->q921); + Q921Start(&isdn_data->q921); - while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { + while(zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; - zap_status_t status = zap_channel_wait(data->dchan, &flags, 100); + zap_status_t status = zap_channel_wait(isdn_data->dchan, &flags, 100); - Q921TimerTick(&data->q921); + Q921TimerTick(&isdn_data->q921); check_state(span); check_events(span); @@ -499,7 +501,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) case ZAP_TIMEOUT: { /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ - /*Q931TimeTick(data->q931, L3ULONG ms);*/ + /*Q931TimeTick(isdn_data->q931, L3ULONG ms);*/ errs = 0; } break; @@ -508,7 +510,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) errs = 0; if (flags & ZAP_READ) { len = sizeof(buf); - if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { + if (zap_channel_read(isdn_data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG //char bb[4096] = ""; //print_hex_bytes(buf, len, bb, sizeof(bb)); @@ -517,8 +519,8 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb); #endif - Q921QueueHDLCFrame(&data->q921, buf, (int)len); - Q921Rx12(&data->q921); + Q921QueueHDLCFrame(&isdn_data->q921, buf, (int)len); + Q921Rx12(&isdn_data->q921); } } else { zap_log(ZAP_LOG_DEBUG, "No Read FLAG!\n"); @@ -531,9 +533,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) done: - zap_channel_close(&data->dchans[0]); - zap_channel_close(&data->dchans[1]); - zap_clear_flag(span->isdn_data, ZAP_ISDN_RUNNING); + 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); @@ -554,7 +556,8 @@ zap_status_t zap_isdn_init(void) zap_status_t zap_isdn_start(zap_span_t *span) { - zap_set_flag(span->isdn_data, ZAP_ISDN_RUNNING); + zap_isdn_data_t *isdn_data = span->signal_data; + zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); return zap_thread_create_detached(zap_isdn_run, span); } @@ -572,7 +575,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D { uint32_t i, x = 0; zap_channel_t *dchans[2] = {0}; - + zap_isdn_data_t *isdn_data; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; @@ -598,16 +601,16 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D } - span->isdn_data = malloc(sizeof(*span->isdn_data)); - assert(span->isdn_data != NULL); - memset(span->isdn_data, 0, sizeof(*span->isdn_data)); + isdn_data = malloc(sizeof(*isdn_data)); + assert(isdn_data != NULL); + memset(isdn_data, 0, sizeof(*isdn_data)); - span->isdn_data->sig_cb = sig_cb; - span->isdn_data->dchans[0] = dchans[0]; - span->isdn_data->dchans[1] = dchans[1]; - span->isdn_data->dchan = span->isdn_data->dchans[0]; + isdn_data->sig_cb = sig_cb; + isdn_data->dchans[0] = dchans[0]; + isdn_data->dchans[1] = dchans[1]; + isdn_data->dchan = isdn_data->dchans[0]; - Q921_InitTrunk(&span->isdn_data->q921, + Q921_InitTrunk(&isdn_data->q921, 0, 0, mode, @@ -615,20 +618,21 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D zap_isdn_921_21, (Q921TxCB_t)zap_isdn_921_23, span, - &span->isdn_data->q931); + &isdn_data->q931); - Q931Api_InitTrunk(&span->isdn_data->q931, + Q931Api_InitTrunk(&isdn_data->q931, dialect, mode, span->trunk_type, zap_isdn_931_34, (Q931TxCB_t)q931_rx_32, zap_isdn_931_err, - &span->isdn_data->q921, + &isdn_data->q921, span); - span->isdn_data->q931.autoRestartAck = 1; - span->isdn_data->q931.autoConnectAck = 1; + isdn_data->q931.autoRestartAck = 1; + isdn_data->q931.autoConnectAck = 1; + span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; From ce36f85c1d19af657b975b90d298111db856e4f6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 25 Jun 2007 16:00:24 +0000 Subject: [PATCH 0579/1766] cleanup of service message handling, add separate dialects for dms and national. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@290 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 16 ++ libs/openzap/src/isdn/DMSStateNT.c | 126 +++++++++ libs/openzap/src/isdn/DMSStateTE.c | 291 +++++++++++++++++++ libs/openzap/src/isdn/DMSmes.c | 338 +++++++++++++++++++++++ libs/openzap/src/isdn/Q931.c | 7 + libs/openzap/src/isdn/Q931api.c | 15 + libs/openzap/src/isdn/Q931ie.c | 77 ++++++ libs/openzap/src/isdn/Q931mes.c | 131 +++++++++ libs/openzap/src/isdn/include/DMS.h | 95 +++++++ libs/openzap/src/isdn/include/Q931.h | 21 +- libs/openzap/src/isdn/include/Q931ie.h | 15 +- libs/openzap/src/isdn/include/national.h | 3 +- libs/openzap/src/isdn/nationalStateTE.c | 42 +-- libs/openzap/src/isdn/nationalmes.c | 37 --- libs/openzap/src/zap_isdn.c | 194 ++++++++----- 15 files changed, 1252 insertions(+), 156 deletions(-) create mode 100644 libs/openzap/src/isdn/DMSStateNT.c create mode 100644 libs/openzap/src/isdn/DMSStateTE.c create mode 100644 libs/openzap/src/isdn/DMSmes.c create mode 100644 libs/openzap/src/isdn/include/DMS.h diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 67565dbb90..c8d612a40f 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -162,6 +162,10 @@ + + @@ -190,6 +194,18 @@ + + + + + + diff --git a/libs/openzap/src/isdn/DMSStateNT.c b/libs/openzap/src/isdn/DMSStateNT.c new file mode 100644 index 0000000000..6c75029665 --- /dev/null +++ b/libs/openzap/src/isdn/DMSStateNT.c @@ -0,0 +1,126 @@ +/***************************************************************************** + + 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 new file mode 100644 index 0000000000..e508e1ce53 --- /dev/null +++ b/libs/openzap/src/isdn/DMSStateTE.c @@ -0,0 +1,291 @@ +/***************************************************************************** + + 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 "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) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 new file mode 100644 index 0000000000..57aeddfb0d --- /dev/null +++ b/libs/openzap/src/isdn/DMSmes.c @@ -0,0 +1,338 @@ +/***************************************************************************** + + 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 */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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/Q931.c b/libs/openzap/src/isdn/Q931.c index 232b2122c3..098c1a44b3 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -38,6 +38,7 @@ #include "Q931.h" #include "national.h" +#include "DMS.h" /***************************************************************************** @@ -261,6 +262,12 @@ void Q931Initialize() 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); + /* The last step we do is to call the callbacks to create the dialects */ for(x=0; x< Q931MAXDLCT; x++) { diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 541b28d428..0a6d3a6733 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -562,5 +562,20 @@ L3INT Q931AckConnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) 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_str2Q931Diaelct_type, q931_Q931Diaelct_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 index 2f4fa60b07..1973d20c41 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -3079,3 +3079,80 @@ L3INT Q931Pie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OB 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 ++; + + /* 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; +} diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index d4229fe958..497e6c1a94 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1770,3 +1770,134 @@ L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, 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) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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; +} diff --git a/libs/openzap/src/isdn/include/DMS.h b/libs/openzap/src/isdn/include/DMS.h new file mode 100644 index 0000000000..35d10d7b5b --- /dev/null +++ b/libs/openzap/src/isdn/include/DMS.h @@ -0,0 +1,95 @@ +/****************************************************************************** + + 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/Q931.h b/libs/openzap/src/isdn/include/Q931.h index ce74a4e0fc..ee92e48b26 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -283,7 +283,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 4 /* Max dialects included in this */ +#define Q931MAXDLCT 6 /* Max dialects included in this */ /* compile. User and Network count as */ /* one dialect each. */ @@ -377,6 +377,9 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #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 */ + /***************************************************************************** @@ -422,6 +425,7 @@ typedef struct 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 */ @@ -488,10 +492,11 @@ typedef enum /* Dialect enum */ { Q931_Dialect_Q931 = 0, Q931_Dialect_National = 2, + Q931_Dialect_DMS = 4, Q931_Dialect_Count } Q931Dialect_t; -#define DIALECT_STRINGS "q931", "", "national" +#define DIALECT_STRINGS "q931", "", "national", "", "dms" Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t) typedef enum /* Trunk Line Type. */ @@ -557,7 +562,10 @@ struct Q931_TrunkInfo L3BOOL autoRestartAck; /* Indicate if the stack should send */ /* RESTART ACK or not. 0=No, 1=Yes. */ - /* channel array holding info per channel. Usually defined to 32 */ + 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 { @@ -786,6 +794,9 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi 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); @@ -812,6 +823,9 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * 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); + /***************************************************************************** @@ -943,6 +957,7 @@ 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, diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index dbca5b3990..5b0e7314a5 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -1068,6 +1068,18 @@ typedef struct /* 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 @@ -1090,7 +1102,7 @@ typedef struct 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; @@ -1121,6 +1133,7 @@ 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; diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h index 983a6de1dc..c47daf4ed9 100644 --- a/libs/openzap/src/isdn/include/national.h +++ b/libs/openzap/src/isdn/include/national.h @@ -72,7 +72,8 @@ *****************************************************************************/ 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); -L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size); + +#include "DMS.h" /***************************************************************************** diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index 289e9c9de9..efd1d81ea2 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -53,7 +53,6 @@ #include "national.h" extern L3INT Q931L4HeaderSpace; -L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom); /***************************************************************************** Function: nationalCreateTE @@ -68,8 +67,8 @@ 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,Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect); - Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,DMSProc0x0fTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); + 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); @@ -107,6 +106,7 @@ void nationalCreateTE(L3UCHAR i) 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); @@ -211,39 +211,3 @@ void nationalCreateTE(L3UCHAR i) */ } -/***************************************************************************** - - Function: Q931ProcConnectAckTE - -*****************************************************************************/ -L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - 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, 303); - } - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,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/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 75e313d90d..81361bd70d 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -261,40 +261,3 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT } -/***************************************************************************** - - Function: DMSUmes_0x0f - -*****************************************************************************/ -L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) -//L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) -{ - L3INT OOff=0; - L3INT rc=Q931E_NO_ERROR; - - if (mes->ProtDisc == 8) { - return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); - } - - 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][Q931ie_RESTART_INDICATOR](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; -} diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index db5ffdfadb..e898a7927b 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -46,7 +46,7 @@ static L2ULONG zap_time_now() { - return zap_current_time_in_ms(); + return (L2ULONG)zap_current_time_in_ms(); } static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) @@ -79,86 +79,129 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); - switch(gen->MesType) { - case Q931mes_RESTART: - { - if (zchan) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); - } else { - uint32_t i; - for (i = 0; i < span->chan_count; i++) { - zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); + +#if 0 + 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; + +#endif + if (gen->ProtDisc == 3) { + switch(gen->MesType) { + case Q931mes_SERVICE: + { + Q931ie_ChangeStatus *changestatus = Q931GetIEPtr(gen->ChangeStatus, gen->buf); + /* TODO: Handle this properly */ + if (zchan) { + switch (changestatus->NewStatus) { + case 0: /* change status to "in service" */ + //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + break; + case 1: /* change status to "maintenance" */ + //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + break; + case 2: /* change status to "out of service" */ + //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + break; + default: /* unknown */ + break; + } } } + break; + default: + break; } - break; - case Q931mes_RELEASE_COMPLETE: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - break; - case Q931mes_DISCONNECT: - { - Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); - zchan->caller_data.hangup_cause = cause->Value; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - } - break; - case Q931mes_ALERTING: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); - } - break; - case Q931mes_PROGRESS: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS); - } - break; - case Q931mes_CONNECT: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } - break; - case Q931mes_SETUP: - { - - Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); - Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); - zap_status_t status; - int fail = 1; - uint32_t cplen = mlen; - - - if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - - zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.ani, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); - - zchan->caller_data.CRV = gen->CRV; - if (cplen > sizeof(zchan->caller_data.raw_data)) { - cplen = sizeof(zchan->caller_data.raw_data); + } else { + switch(gen->MesType) { + case Q931mes_RESTART: + { + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + } else { + uint32_t i; + for (i = 0; i < span->chan_count; i++) { + zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); } - gen->CRVFlag = !(gen->CRVFlag); - memcpy(zchan->caller_data.raw_data, msg, cplen); - zchan->caller_data.raw_data_len = cplen; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); - fail = 0; - } - } - - if (fail) { - zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); - // add me + } } - + break; + case Q931mes_RELEASE_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + break; + case Q931mes_DISCONNECT: + { + Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); + zchan->caller_data.hangup_cause = cause->Value; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } + break; + case Q931mes_ALERTING: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } + break; + case Q931mes_PROGRESS: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + break; + case Q931mes_CONNECT: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + break; + case Q931mes_SETUP: + { + + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); + Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); + zap_status_t status; + int fail = 1; + uint32_t cplen = mlen; + + + if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + + zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.ani, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.dnis, (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; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + fail = 0; + } + } + + if (fail) { + zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); + // add me + } + + } + break; + default: + break; } - break; - default: - break; } return 0; @@ -632,6 +675,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D isdn_data->q931.autoRestartAck = 1; isdn_data->q931.autoConnectAck = 1; + isdn_data->q931.autoServiceAck = 1; span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; From c1f9897ff56dec00d0296d009ae30cc593fba88e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 25 Jun 2007 16:00:24 +0000 Subject: [PATCH 0580/1766] cleanup of service message handling, add separate dialects for dms and national. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@290 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 16 ++ libs/freetdm/src/isdn/DMSStateNT.c | 126 +++++++++ libs/freetdm/src/isdn/DMSStateTE.c | 291 +++++++++++++++++++ libs/freetdm/src/isdn/DMSmes.c | 338 +++++++++++++++++++++++ libs/freetdm/src/isdn/Q931.c | 7 + libs/freetdm/src/isdn/Q931api.c | 15 + libs/freetdm/src/isdn/Q931ie.c | 77 ++++++ libs/freetdm/src/isdn/Q931mes.c | 131 +++++++++ libs/freetdm/src/isdn/include/DMS.h | 95 +++++++ libs/freetdm/src/isdn/include/Q931.h | 21 +- libs/freetdm/src/isdn/include/Q931ie.h | 15 +- libs/freetdm/src/isdn/include/national.h | 3 +- libs/freetdm/src/isdn/nationalStateTE.c | 42 +-- libs/freetdm/src/isdn/nationalmes.c | 37 --- libs/freetdm/src/zap_isdn.c | 194 ++++++++----- 15 files changed, 1252 insertions(+), 156 deletions(-) create mode 100644 libs/freetdm/src/isdn/DMSStateNT.c create mode 100644 libs/freetdm/src/isdn/DMSStateTE.c create mode 100644 libs/freetdm/src/isdn/DMSmes.c create mode 100644 libs/freetdm/src/isdn/include/DMS.h diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 67565dbb90..c8d612a40f 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -162,6 +162,10 @@ + + @@ -190,6 +194,18 @@ + + + + + + diff --git a/libs/freetdm/src/isdn/DMSStateNT.c b/libs/freetdm/src/isdn/DMSStateNT.c new file mode 100644 index 0000000000..6c75029665 --- /dev/null +++ b/libs/freetdm/src/isdn/DMSStateNT.c @@ -0,0 +1,126 @@ +/***************************************************************************** + + 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/freetdm/src/isdn/DMSStateTE.c b/libs/freetdm/src/isdn/DMSStateTE.c new file mode 100644 index 0000000000..e508e1ce53 --- /dev/null +++ b/libs/freetdm/src/isdn/DMSStateTE.c @@ -0,0 +1,291 @@ +/***************************************************************************** + + 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 "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) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; + +} diff --git a/libs/freetdm/src/isdn/DMSmes.c b/libs/freetdm/src/isdn/DMSmes.c new file mode 100644 index 0000000000..57aeddfb0d --- /dev/null +++ b/libs/freetdm/src/isdn/DMSmes.c @@ -0,0 +1,338 @@ +/***************************************************************************** + + 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 */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 232b2122c3..098c1a44b3 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -38,6 +38,7 @@ #include "Q931.h" #include "national.h" +#include "DMS.h" /***************************************************************************** @@ -261,6 +262,12 @@ void Q931Initialize() 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); + /* The last step we do is to call the callbacks to create the dialects */ for(x=0; x< Q931MAXDLCT; x++) { diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 541b28d428..0a6d3a6733 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -562,5 +562,20 @@ L3INT Q931AckConnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) 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_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 2f4fa60b07..1973d20c41 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -3079,3 +3079,80 @@ L3INT Q931Pie_GenericDigits(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OB 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 ++; + + /* 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; +} diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index d4229fe958..497e6c1a94 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1770,3 +1770,134 @@ L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, 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) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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) +{ + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; + + /* Q931 Message Header */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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; +} diff --git a/libs/freetdm/src/isdn/include/DMS.h b/libs/freetdm/src/isdn/include/DMS.h new file mode 100644 index 0000000000..35d10d7b5b --- /dev/null +++ b/libs/freetdm/src/isdn/include/DMS.h @@ -0,0 +1,95 @@ +/****************************************************************************** + + 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/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index ce74a4e0fc..ee92e48b26 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -283,7 +283,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 4 /* Max dialects included in this */ +#define Q931MAXDLCT 6 /* Max dialects included in this */ /* compile. User and Network count as */ /* one dialect each. */ @@ -377,6 +377,9 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #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 */ + /***************************************************************************** @@ -422,6 +425,7 @@ typedef struct 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 */ @@ -488,10 +492,11 @@ typedef enum /* Dialect enum */ { Q931_Dialect_Q931 = 0, Q931_Dialect_National = 2, + Q931_Dialect_DMS = 4, Q931_Dialect_Count } Q931Dialect_t; -#define DIALECT_STRINGS "q931", "", "national" +#define DIALECT_STRINGS "q931", "", "national", "", "dms" Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t) typedef enum /* Trunk Line Type. */ @@ -557,7 +562,10 @@ struct Q931_TrunkInfo L3BOOL autoRestartAck; /* Indicate if the stack should send */ /* RESTART ACK or not. 0=No, 1=Yes. */ - /* channel array holding info per channel. Usually defined to 32 */ + 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 { @@ -786,6 +794,9 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi 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); @@ -812,6 +823,9 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * 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); + /***************************************************************************** @@ -943,6 +957,7 @@ 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, diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index dbca5b3990..5b0e7314a5 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -1068,6 +1068,18 @@ typedef struct /* 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 @@ -1090,7 +1102,7 @@ typedef struct 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; @@ -1121,6 +1133,7 @@ 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; diff --git a/libs/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h index 983a6de1dc..c47daf4ed9 100644 --- a/libs/freetdm/src/isdn/include/national.h +++ b/libs/freetdm/src/isdn/include/national.h @@ -72,7 +72,8 @@ *****************************************************************************/ 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); -L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size); + +#include "DMS.h" /***************************************************************************** diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index 289e9c9de9..efd1d81ea2 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -53,7 +53,6 @@ #include "national.h" extern L3INT Q931L4HeaderSpace; -L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom); /***************************************************************************** Function: nationalCreateTE @@ -68,8 +67,8 @@ 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,Q931ProcConnectTE, Q931Umes_Connect, Q931Pmes_Connect); - Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,DMSProc0x0fTE, DMSUmes_0x0f, Q931Pmes_ConnectAck); + 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); @@ -107,6 +106,7 @@ void nationalCreateTE(L3UCHAR i) 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); @@ -211,39 +211,3 @@ void nationalCreateTE(L3UCHAR i) */ } -/***************************************************************************** - - Function: Q931ProcConnectAckTE - -*****************************************************************************/ -L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) -{ - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; - Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; - - 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, 303); - } - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); - } - else if (iFrom ==2) - { - /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); - } - return ret; - -} diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 75e313d90d..81361bd70d 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -261,40 +261,3 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT } -/***************************************************************************** - - Function: DMSUmes_0x0f - -*****************************************************************************/ -L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) -//L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) -{ - L3INT OOff=0; - L3INT rc=Q931E_NO_ERROR; - - if (mes->ProtDisc == 8) { - return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); - } - - 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][Q931ie_RESTART_INDICATOR](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; -} diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index db5ffdfadb..e898a7927b 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -46,7 +46,7 @@ static L2ULONG zap_time_now() { - return zap_current_time_in_ms(); + return (L2ULONG)zap_current_time_in_ms(); } static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) @@ -79,86 +79,129 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); - switch(gen->MesType) { - case Q931mes_RESTART: - { - if (zchan) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); - } else { - uint32_t i; - for (i = 0; i < span->chan_count; i++) { - zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); + +#if 0 + 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; + +#endif + if (gen->ProtDisc == 3) { + switch(gen->MesType) { + case Q931mes_SERVICE: + { + Q931ie_ChangeStatus *changestatus = Q931GetIEPtr(gen->ChangeStatus, gen->buf); + /* TODO: Handle this properly */ + if (zchan) { + switch (changestatus->NewStatus) { + case 0: /* change status to "in service" */ + //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + break; + case 1: /* change status to "maintenance" */ + //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + break; + case 2: /* change status to "out of service" */ + //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + break; + default: /* unknown */ + break; + } } } + break; + default: + break; } - break; - case Q931mes_RELEASE_COMPLETE: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - break; - case Q931mes_DISCONNECT: - { - Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); - zchan->caller_data.hangup_cause = cause->Value; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - } - break; - case Q931mes_ALERTING: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); - } - break; - case Q931mes_PROGRESS: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS); - } - break; - case Q931mes_CONNECT: - { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } - break; - case Q931mes_SETUP: - { - - Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); - Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); - zap_status_t status; - int fail = 1; - uint32_t cplen = mlen; - - - if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - - zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.ani, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); - - zchan->caller_data.CRV = gen->CRV; - if (cplen > sizeof(zchan->caller_data.raw_data)) { - cplen = sizeof(zchan->caller_data.raw_data); + } else { + switch(gen->MesType) { + case Q931mes_RESTART: + { + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + } else { + uint32_t i; + for (i = 0; i < span->chan_count; i++) { + zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); } - gen->CRVFlag = !(gen->CRVFlag); - memcpy(zchan->caller_data.raw_data, msg, cplen); - zchan->caller_data.raw_data_len = cplen; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); - fail = 0; - } - } - - if (fail) { - zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); - // add me + } } - + break; + case Q931mes_RELEASE_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + break; + case Q931mes_DISCONNECT: + { + Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); + zchan->caller_data.hangup_cause = cause->Value; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } + break; + case Q931mes_ALERTING: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } + break; + case Q931mes_PROGRESS: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + break; + case Q931mes_CONNECT: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + break; + case Q931mes_SETUP: + { + + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); + Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); + zap_status_t status; + int fail = 1; + uint32_t cplen = mlen; + + + if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + + zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.cid_name, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.ani, (char *)callingnum->Digit); + zap_set_string(zchan->caller_data.dnis, (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; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + fail = 0; + } + } + + if (fail) { + zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); + // add me + } + + } + break; + default: + break; } - break; - default: - break; } return 0; @@ -632,6 +675,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D isdn_data->q931.autoRestartAck = 1; isdn_data->q931.autoConnectAck = 1; + isdn_data->q931.autoServiceAck = 1; span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; From fc7ce954e1cb8c80634f914288844e6810edd853 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 25 Jun 2007 16:01:46 +0000 Subject: [PATCH 0581/1766] add new DMS files to the Makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@291 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 03e8eacefc..1eb5054414 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -58,6 +58,9 @@ $(SRC)/isdn/Q931StateTE.o \ $(SRC)/isdn/nationalmes.o \ $(SRC)/isdn/nationalStateNT.o \ $(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o From a746fe30a2588d7ecdadcb4a1e8856dc78d062e8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 25 Jun 2007 16:01:46 +0000 Subject: [PATCH 0582/1766] add new DMS files to the Makefile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@291 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 03e8eacefc..1eb5054414 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -58,6 +58,9 @@ $(SRC)/isdn/Q931StateTE.o \ $(SRC)/isdn/nationalmes.o \ $(SRC)/isdn/nationalStateNT.o \ $(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o From 917b2dfd21acad5423c314f3c97340c72f862eb2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 25 Jun 2007 16:04:24 +0000 Subject: [PATCH 0583/1766] whoops, leftover garbage git-svn-id: http://svn.openzap.org/svn/openzap/trunk@292 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index e898a7927b..8a3a14dd3d 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -80,20 +80,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); -#if 0 - 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; - -#endif if (gen->ProtDisc == 3) { switch(gen->MesType) { case Q931mes_SERVICE: From b4ec7b6ba22d9d27d0fbd6ee868e230edae5fad6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 25 Jun 2007 16:04:24 +0000 Subject: [PATCH 0584/1766] whoops, leftover garbage git-svn-id: http://svn.openzap.org/svn/openzap/trunk@292 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index e898a7927b..8a3a14dd3d 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -80,20 +80,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); -#if 0 - 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; - -#endif if (gen->ProtDisc == 3) { switch(gen->MesType) { case Q931mes_SERVICE: From 9e0303d4ab4148914a0b798a1e3f11abcfed29ed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Jun 2007 00:47:05 +0000 Subject: [PATCH 0585/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@293 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 ++- libs/openzap/src/zap_io.c | 9 +++++++-- libs/openzap/src/zap_isdn.c | 22 +++++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 818fed2af8..4055b0c931 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -277,6 +277,7 @@ typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HOLD, + ZAP_CHANNEL_STATE_SUSPENDED, ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_COLLECT, ZAP_CHANNEL_STATE_RING, @@ -294,7 +295,7 @@ typedef enum { ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ +#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "IDLE", "UP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 77bd0ecc17..477bc8f04f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -710,7 +710,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED)) { status = check->zio->open(check); @@ -787,6 +787,10 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) assert(zchan != NULL); + if (zap_test_flag(zchan, ZAP_CHANNEL_SUSPENDED)) { + return ZAP_FAIL; + } + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } @@ -815,7 +819,8 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t check = &globals.spans[span_id].channels[chan_id]; - if (!zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || + !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { goto done; } diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 8a3a14dd3d..af4f89d41f 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -85,17 +85,29 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_SERVICE: { Q931ie_ChangeStatus *changestatus = Q931GetIEPtr(gen->ChangeStatus, gen->buf); - /* TODO: Handle this properly */ if (zchan) { switch (changestatus->NewStatus) { case 0: /* change status to "in service" */ - //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); - break; + 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); + switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + break; + case ZAP_CHANNEL_STATE_DOWN: + break; + default: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + break; + } case 1: /* change status to "maintenance" */ - //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + 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_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag_locked(zchan, ZAP_CHANNEL_SUSPENDED); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_SUSPENDED); break; default: /* unknown */ break; From f90f684bc09fc1ae811809ea7cf6ae306557a5b5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Jun 2007 00:47:05 +0000 Subject: [PATCH 0586/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@293 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 3 ++- libs/freetdm/src/zap_io.c | 9 +++++++-- libs/freetdm/src/zap_isdn.c | 22 +++++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 818fed2af8..4055b0c931 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -277,6 +277,7 @@ typedef enum { ZAP_CHANNEL_STATE_DOWN, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HOLD, + ZAP_CHANNEL_STATE_SUSPENDED, ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_COLLECT, ZAP_CHANNEL_STATE_RING, @@ -294,7 +295,7 @@ typedef enum { ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "DIALTONE", "COLLECT", \ +#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "IDLE", "UP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 77bd0ecc17..477bc8f04f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -710,7 +710,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED)) { status = check->zio->open(check); @@ -787,6 +787,10 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) assert(zchan != NULL); + if (zap_test_flag(zchan, ZAP_CHANNEL_SUSPENDED)) { + return ZAP_FAIL; + } + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { return status; } @@ -815,7 +819,8 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t check = &globals.spans[span_id].channels[chan_id]; - if (!zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || + !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { goto done; } diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 8a3a14dd3d..af4f89d41f 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -85,17 +85,29 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_SERVICE: { Q931ie_ChangeStatus *changestatus = Q931GetIEPtr(gen->ChangeStatus, gen->buf); - /* TODO: Handle this properly */ if (zchan) { switch (changestatus->NewStatus) { case 0: /* change status to "in service" */ - //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); - break; + 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); + switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + break; + case ZAP_CHANNEL_STATE_DOWN: + break; + default: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + break; + } case 1: /* change status to "maintenance" */ - //zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + 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_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag_locked(zchan, ZAP_CHANNEL_SUSPENDED); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_SUSPENDED); break; default: /* unknown */ break; From 4fc410d8b827858f0b3bb5be29b6c08acccbac16 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Jun 2007 01:02:36 +0000 Subject: [PATCH 0587/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@294 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 47 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index af4f89d41f..800627d6a2 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -88,29 +88,38 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: - case ZAP_CHANNEL_STATE_IDLE: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - break; - case ZAP_CHANNEL_STATE_DOWN: - break; - default: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - break; + { + 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); + switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + break; + case ZAP_CHANNEL_STATE_DOWN: + break; + default: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + 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); + 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; + } } } } From 49b5b251baf3863501bb94f8d72f118c12097899 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Jun 2007 01:02:36 +0000 Subject: [PATCH 0588/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@294 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 47 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index af4f89d41f..800627d6a2 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -88,29 +88,38 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: - case ZAP_CHANNEL_STATE_IDLE: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - break; - case ZAP_CHANNEL_STATE_DOWN: - break; - default: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - break; + { + 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); + switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + break; + case ZAP_CHANNEL_STATE_DOWN: + break; + default: + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + 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); + 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; + } } } } From d8fb3b338f3a02627c616b67931801ffd84b7c13 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 26 Jun 2007 14:54:11 +0000 Subject: [PATCH 0589/1766] make chan id parsing more flezible, seems to follow the spec still correctly. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@295 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 1973d20c41..84677988f4 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1157,7 +1157,7 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * L3INT Off = 0; L3INT Octet = 0; L3INT IESize; - +//18 04 e1 80 83 01 *pIE=0; /* Octet 1 */ @@ -1190,8 +1190,8 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off = Q931ReadExt(&IBuf[Octet+Off], Off); Off++; } - else - { + + if (Octet + Off -2 != IESize) { /* Octet 3.2 */ if(pie->IntType == 1) /* PRI etc */ { From f1652c8997ae1806f5ac72c431bd1dcc9f7488a7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 26 Jun 2007 14:54:11 +0000 Subject: [PATCH 0590/1766] make chan id parsing more flezible, seems to follow the spec still correctly. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@295 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 1973d20c41..84677988f4 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1157,7 +1157,7 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * L3INT Off = 0; L3INT Octet = 0; L3INT IESize; - +//18 04 e1 80 83 01 *pIE=0; /* Octet 1 */ @@ -1190,8 +1190,8 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off = Q931ReadExt(&IBuf[Octet+Off], Off); Off++; } - else - { + + if (Octet + Off -2 != IESize) { /* Octet 3.2 */ if(pie->IntType == 1) /* PRI etc */ { From 93a1903a3cc880803ceab99887a072e0f3665d0a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 26 Jun 2007 15:23:27 +0000 Subject: [PATCH 0591/1766] handle sending complete in setup (kindof) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@296 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 497e6c1a94..d1e2a85112 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1194,6 +1194,8 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: + IOff++; + break; case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: From e89f94f0877198d5f4eabe6e76a06bef84c0640e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 26 Jun 2007 15:23:27 +0000 Subject: [PATCH 0592/1766] handle sending complete in setup (kindof) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@296 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 497e6c1a94..d1e2a85112 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1194,6 +1194,8 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m switch(IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: + IOff++; + break; case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: From fa0e2fa9195fc7711daf137229ba086a1682f800 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Jun 2007 14:59:05 +0000 Subject: [PATCH 0593/1766] fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@297 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 477bc8f04f..4ebaaa6bc8 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -215,7 +215,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { - zap_mutex_destroy(&zchan->mutex); + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -234,6 +234,8 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); } } + + zap_mutex_destroy(&zchan->mutex); } return ZAP_SUCCESS; From a554535050cba74ecab93bce88450c753f3327ec Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Jun 2007 14:59:05 +0000 Subject: [PATCH 0594/1766] fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@297 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 477bc8f04f..4ebaaa6bc8 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -215,7 +215,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { - zap_mutex_destroy(&zchan->mutex); + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -234,6 +234,8 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); } } + + zap_mutex_destroy(&zchan->mutex); } return ZAP_SUCCESS; From a4942a13d6c38f61d2d6492b8292e555b016fca8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Jun 2007 19:18:13 +0000 Subject: [PATCH 0595/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@298 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 3 ++- libs/openzap/src/zap_analog.c | 13 +++++++++++-- libs/openzap/src/zap_io.c | 7 ++++--- libs/openzap/src/zap_wanpipe.c | 3 ++- libs/openzap/src/zap_zt.c | 8 ++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index eb707671e9..46aab35eb6 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -233,7 +233,8 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #define ZT_CODE 'J' -#define ZT_GET_BLOCKSIZE _IOW (ZT_CODE, 1, int) /* Get Transfer Block Size. */ + +#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 */ diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 23b1ec1a55..23a9054dd0 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -215,7 +215,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.chan_id = zchan->chan_id; sig.span_id = zchan->span_id; sig.channel = zchan; - + + assert(interval != 0); while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -279,11 +280,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 500) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { + if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } @@ -577,6 +581,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) done: zap_channel_done(zchan); + + if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); } @@ -638,6 +644,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); + } zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } break; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 4ebaaa6bc8..c15ac3c1ab 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -577,12 +577,11 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta { int ok = 1; - zap_mutex_lock(zchan->mutex); - if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; } + zap_mutex_lock(zchan->mutex); switch(zchan->state) { case ZAP_CHANNEL_STATE_HANGUP: case ZAP_CHANNEL_STATE_TERMINATING: @@ -641,7 +640,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (state == zchan->state) { ok = 0; } - + if (ok) { zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); @@ -1209,11 +1208,13 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); + zap_log(ZAP_LOG_ERROR, "no commnand functon!\n"); GOTO_STATUS(done, ZAP_FAIL); } status = zchan->zio->command(zchan, command, obj); + done: zap_mutex_unlock(zchan->mutex); return status; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 7a7536f914..4537e547ff 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -543,7 +543,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) int err = 0; memset(&tdm_api, 0, sizeof(tdm_api)); - + switch(command) { case ZAP_COMMAND_OFFHOOK: { @@ -593,6 +593,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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; diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 5f2a60b052..be33a7c536 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -61,7 +61,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { @@ -308,6 +307,8 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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 { @@ -317,7 +318,6 @@ static ZIO_OPEN_FUNCTION(zt_open) snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } else { - zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); zchan->effective_interval = zchan->native_interval; zchan->packet_len = blocksize; zchan->native_codec = zchan->effective_codec; @@ -404,14 +404,14 @@ static ZIO_COMMAND_FUNCTION(zt_command) break; case ZAP_COMMAND_GET_INTERVAL: { + if (!(err = ioctl(zchan->sockfd, ZT_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: From a20ed892cf2099eda3eb0394ce44a6cd939d6963 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Jun 2007 19:18:13 +0000 Subject: [PATCH 0596/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@298 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_zt.h | 3 ++- libs/freetdm/src/zap_analog.c | 13 +++++++++++-- libs/freetdm/src/zap_io.c | 7 ++++--- libs/freetdm/src/zap_wanpipe.c | 3 ++- libs/freetdm/src/zap_zt.c | 8 ++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index eb707671e9..46aab35eb6 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -233,7 +233,8 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #define ZT_CODE 'J' -#define ZT_GET_BLOCKSIZE _IOW (ZT_CODE, 1, int) /* Get Transfer Block Size. */ + +#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 */ diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 23b1ec1a55..23a9054dd0 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -215,7 +215,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.chan_id = zchan->chan_id; sig.span_id = zchan->span_id; sig.channel = zchan; - + + assert(interval != 0); while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -279,11 +280,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 500) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { + if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } @@ -577,6 +581,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) done: zap_channel_done(zchan); + + if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); } @@ -638,6 +644,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); + } zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } break; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 4ebaaa6bc8..c15ac3c1ab 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -577,12 +577,11 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta { int ok = 1; - zap_mutex_lock(zchan->mutex); - if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; } + zap_mutex_lock(zchan->mutex); switch(zchan->state) { case ZAP_CHANNEL_STATE_HANGUP: case ZAP_CHANNEL_STATE_TERMINATING: @@ -641,7 +640,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (state == zchan->state) { ok = 0; } - + if (ok) { zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); @@ -1209,11 +1208,13 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); + zap_log(ZAP_LOG_ERROR, "no commnand functon!\n"); GOTO_STATUS(done, ZAP_FAIL); } status = zchan->zio->command(zchan, command, obj); + done: zap_mutex_unlock(zchan->mutex); return status; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 7a7536f914..4537e547ff 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -543,7 +543,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) int err = 0; memset(&tdm_api, 0, sizeof(tdm_api)); - + switch(command) { case ZAP_COMMAND_OFFHOOK: { @@ -593,6 +593,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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; diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 5f2a60b052..be33a7c536 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -61,7 +61,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { @@ -308,6 +307,8 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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 { @@ -317,7 +318,6 @@ static ZIO_OPEN_FUNCTION(zt_open) snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } else { - zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); zchan->effective_interval = zchan->native_interval; zchan->packet_len = blocksize; zchan->native_codec = zchan->effective_codec; @@ -404,14 +404,14 @@ static ZIO_COMMAND_FUNCTION(zt_command) break; case ZAP_COMMAND_GET_INTERVAL: { + if (!(err = ioctl(zchan->sockfd, ZT_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: From f30fa1b95ec879063d3d2febd9b1ffada945c543 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Jul 2007 14:15:43 +0000 Subject: [PATCH 0597/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@299 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 3 ++- libs/openzap/src/zap_zt.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 800627d6a2..e9647319c4 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -196,11 +196,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->caller_data.raw_data_len = cplen; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; + zap_log(ZAP_LOG_CRIT, "hi %s\n", zchan->caller_data.cid_num); } } if (fail) { - zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); + zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); // add me } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index be33a7c536..47d5d3cc6b 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -171,11 +171,22 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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) { + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { if (ztp.g711_type == ZT_G711_ALAW) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; - } else { + } 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; + } } From f6f320821c8f5cba33434f46a6c2490308d457aa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Jul 2007 14:15:43 +0000 Subject: [PATCH 0598/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@299 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 3 ++- libs/freetdm/src/zap_zt.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 800627d6a2..e9647319c4 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -196,11 +196,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->caller_data.raw_data_len = cplen; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; + zap_log(ZAP_LOG_CRIT, "hi %s\n", zchan->caller_data.cid_num); } } if (fail) { - zap_log(ZAP_LOG_CRIT, "FIX ME!\n"); + zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); // add me } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index be33a7c536..47d5d3cc6b 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -171,11 +171,22 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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) { + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { if (ztp.g711_type == ZT_G711_ALAW) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; - } else { + } 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; + } } From 916bd148ff6ce6552aa79e7c2c3540ec88ad3037 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 2 Jul 2007 22:31:20 +0000 Subject: [PATCH 0599/1766] use "isQ931ext" in LLComp ie parser. Be more flexible to missing octect 7 in LLComp ie. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@300 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 84677988f4..23e4f010ed 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1780,7 +1780,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 3a*/ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->NegotInd = (IBuf[Octet+Off] >> 6) & 0x01; Off++; @@ -1808,7 +1808,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 5a */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->SyncAsync = (IBuf[Octet+Off] >> 6) & 0x01; pie->Negot = (IBuf[Octet+Off] >> 5) & 0x01; @@ -1816,7 +1816,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off++; /* Octet 5b - 2 options */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { if(pie->UIL1Prot == 0x01) /* V.110, I.460 and X.30*/ { @@ -1849,7 +1849,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * } /* Octet 5c */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; @@ -1857,7 +1857,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off++; /* Octet 5d */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->DuplexMode = (IBuf[Octet+Off] >> 6) & 0x01; pie->ModemType = IBuf[Octet+Off] & 0x3f; @@ -1877,7 +1877,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 6a */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { if(pie->UIL2Prot == 0x10) /* 2nd 6a */ { @@ -1891,7 +1891,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off++; } /* Octet 6b*/ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->WindowSize = IBuf[Octet+Off] & 0x7f; Off++; @@ -1907,7 +1907,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 7a */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { if(pie->UIL3Prot == 0x0b) @@ -1931,13 +1931,13 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * } /* Octet 7b*/ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->DefPackSize = IBuf[Octet+Off] & 0x0f; Off++; /* Octet 7c */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->PackWinSize= IBuf[Octet+Off] & 0x7f; } @@ -1945,11 +1945,6 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * } } } - else - { - Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); - return Q931E_LLCOMP; - } Q931IESizeTest(Q931E_LLCOMP); From f783a69fbbe9250c5b14348792a1b2613bbab20b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 2 Jul 2007 22:31:20 +0000 Subject: [PATCH 0600/1766] use "isQ931ext" in LLComp ie parser. Be more flexible to missing octect 7 in LLComp ie. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@300 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 84677988f4..23e4f010ed 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1780,7 +1780,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 3a*/ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->NegotInd = (IBuf[Octet+Off] >> 6) & 0x01; Off++; @@ -1808,7 +1808,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 5a */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->SyncAsync = (IBuf[Octet+Off] >> 6) & 0x01; pie->Negot = (IBuf[Octet+Off] >> 5) & 0x01; @@ -1816,7 +1816,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off++; /* Octet 5b - 2 options */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { if(pie->UIL1Prot == 0x01) /* V.110, I.460 and X.30*/ { @@ -1849,7 +1849,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * } /* Octet 5c */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->NumStopBits=(IBuf[Octet+Off] >> 5) & 0x03; pie->NumDataBits=(IBuf[Octet+Off] >> 3) & 0x03; @@ -1857,7 +1857,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off++; /* Octet 5d */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->DuplexMode = (IBuf[Octet+Off] >> 6) & 0x01; pie->ModemType = IBuf[Octet+Off] & 0x3f; @@ -1877,7 +1877,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 6a */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { if(pie->UIL2Prot == 0x10) /* 2nd 6a */ { @@ -1891,7 +1891,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off++; } /* Octet 6b*/ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->WindowSize = IBuf[Octet+Off] & 0x7f; Off++; @@ -1907,7 +1907,7 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Octet++; /* Octet 7a */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { if(pie->UIL3Prot == 0x0b) @@ -1931,13 +1931,13 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * } /* Octet 7b*/ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->DefPackSize = IBuf[Octet+Off] & 0x0f; Off++; /* Octet 7c */ - if((IBuf[Octet+Off-1] & 0x80) != 0) + if(IsQ931Ext(IBuf[Octet+Off-1])) { pie->PackWinSize= IBuf[Octet+Off] & 0x7f; } @@ -1945,11 +1945,6 @@ L3INT Q931Uie_LLComp(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * } } } - else - { - Q931SetError(pTrunk,Q931E_LLCOMP, 7,0); - return Q931E_LLCOMP; - } Q931IESizeTest(Q931E_LLCOMP); From 97ef2be9344ae1404f5a11616d9efefb175aff1a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Jul 2007 20:38:43 +0000 Subject: [PATCH 0601/1766] update to use new module loader api git-svn-id: http://svn.openzap.org/svn/openzap/trunk@301 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 40 +++++++++----------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a78facb658..b70b5cfaee 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -34,7 +34,10 @@ #include "zap_analog.h" #include "zap_isdn.h" -static const char modname[] = "mod_openzap"; +SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); +SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, NULL, NULL); + +static switch_endpoint_interface_t *channel_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; static int running = 1; @@ -654,7 +657,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } -static switch_state_handler_table_t channel_event_handlers = { +static switch_state_handler_table_t channel_state_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, /*.on_execute */ channel_on_execute, @@ -674,24 +677,6 @@ static switch_io_routines_t channel_io_routines = { /*.receive_message*/ channel_receive_message }; -static switch_endpoint_interface_t channel_endpoint_interface = { - /*.interface_name */ "openzap", - /*.io_routines */ &channel_io_routines, - /*.event_handlers */ &channel_event_handlers, - /*.private */ NULL, - /*.next */ NULL -}; - -static switch_loadable_module_interface_t channel_module_interface = { - /*.module_name */ modname, - /*.endpoint_interface */ &channel_endpoint_interface, - /*.timer_interface */ NULL, - /*.dialplan_interface */ NULL, - /*.codec_interface */ NULL, - /*.application_interface */ NULL -}; - - /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ @@ -1205,13 +1190,10 @@ static switch_status_t load_config(void) return SWITCH_STATUS_SUCCESS; } -SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename) +SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { - if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n"); - return SWITCH_STATUS_TERM; - } + module_pool = pool; zap_global_set_logger(zap_logger); @@ -1225,8 +1207,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod return SWITCH_STATUS_TERM; } - /* connect my internal structure to the blank pointer passed to me */ - *module_interface = &channel_module_interface; + *module_interface = switch_loadable_module_create_module_interface(pool, modname); + channel_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); + channel_endpoint_interface->interface_name = "openzap"; + channel_endpoint_interface->io_routines = &channel_io_routines; + channel_endpoint_interface->state_handler = &channel_state_handlers; + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; From 50bf3e45b5e9d9e2f7d3245f52d0f9c34b21a002 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Jul 2007 20:38:43 +0000 Subject: [PATCH 0602/1766] update to use new module loader api git-svn-id: http://svn.openzap.org/svn/openzap/trunk@301 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 40 +++++++++----------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a78facb658..b70b5cfaee 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -34,7 +34,10 @@ #include "zap_analog.h" #include "zap_isdn.h" -static const char modname[] = "mod_openzap"; +SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); +SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, NULL, NULL); + +static switch_endpoint_interface_t *channel_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; static int running = 1; @@ -654,7 +657,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } -static switch_state_handler_table_t channel_event_handlers = { +static switch_state_handler_table_t channel_state_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, /*.on_execute */ channel_on_execute, @@ -674,24 +677,6 @@ static switch_io_routines_t channel_io_routines = { /*.receive_message*/ channel_receive_message }; -static switch_endpoint_interface_t channel_endpoint_interface = { - /*.interface_name */ "openzap", - /*.io_routines */ &channel_io_routines, - /*.event_handlers */ &channel_event_handlers, - /*.private */ NULL, - /*.next */ NULL -}; - -static switch_loadable_module_interface_t channel_module_interface = { - /*.module_name */ modname, - /*.endpoint_interface */ &channel_endpoint_interface, - /*.timer_interface */ NULL, - /*.dialplan_interface */ NULL, - /*.codec_interface */ NULL, - /*.application_interface */ NULL -}; - - /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ @@ -1205,13 +1190,10 @@ static switch_status_t load_config(void) return SWITCH_STATUS_SUCCESS; } -SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename) +SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { - if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n"); - return SWITCH_STATUS_TERM; - } + module_pool = pool; zap_global_set_logger(zap_logger); @@ -1225,8 +1207,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod return SWITCH_STATUS_TERM; } - /* connect my internal structure to the blank pointer passed to me */ - *module_interface = &channel_module_interface; + *module_interface = switch_loadable_module_create_module_interface(pool, modname); + channel_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); + channel_endpoint_interface->interface_name = "openzap"; + channel_endpoint_interface->io_routines = &channel_io_routines; + channel_endpoint_interface->state_handler = &channel_state_handlers; + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; From c70233502ab91d0d8ab3d89c1d5eba15e466e062 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 2 Aug 2007 21:24:09 +0000 Subject: [PATCH 0603/1766] fix for euroisdn, watch if this one breaks dms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@306 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 0a6d3a6733..d1ec028a04 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -529,9 +529,9 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; - if (ptr->CRV) { + //if (ptr->CRV) { ptr->CRVFlag = !(ptr->CRVFlag); - } + //} RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); From d2c6e56addb792e2fad81749816de43fd5592dbc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 2 Aug 2007 21:24:09 +0000 Subject: [PATCH 0604/1766] fix for euroisdn, watch if this one breaks dms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@306 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 0a6d3a6733..d1ec028a04 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -529,9 +529,9 @@ L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE; - if (ptr->CRV) { + //if (ptr->CRV) { ptr->CRVFlag = !(ptr->CRVFlag); - } + //} RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); From 02a9010ba744d63d0a53ccf72b1a8751f9f01169 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 2 Aug 2007 21:26:09 +0000 Subject: [PATCH 0605/1766] tweak log message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@307 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_zt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 47d5d3cc6b..3313216f6c 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -165,7 +165,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + zap_log(ZAP_LOG_INFO, "configuring device %s channel %d as OpenZAP device %d:%d fd:%d\n", path, x, zchan->span_id, zchan->chan_id, sockfd); zchan->rate = 8000; zchan->physical_span_id = ztp.span_no; From 4472dfacf8b0c7669e353d8a9399f2e835ec77cb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 2 Aug 2007 21:26:09 +0000 Subject: [PATCH 0606/1766] tweak log message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@307 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_zt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 47d5d3cc6b..3313216f6c 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -165,7 +165,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + zap_log(ZAP_LOG_INFO, "configuring device %s channel %d as OpenZAP device %d:%d fd:%d\n", path, x, zchan->span_id, zchan->chan_id, sockfd); zchan->rate = 8000; zchan->physical_span_id = ztp.span_no; From 93d309d4c14b54243e602a7b6626575197f0f9f8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 15 Aug 2007 15:54:00 +0000 Subject: [PATCH 0607/1766] fix sloppy commit when updated to new module interface git-svn-id: http://svn.openzap.org/svn/openzap/trunk@308 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b70b5cfaee..bbb7403a04 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -731,7 +731,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi - if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { + if ((*new_session = switch_core_session_request(channel_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; switch_caller_profile_t *caller_profile; @@ -801,7 +801,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + if (!(session = switch_core_session_request(channel_endpoint_interface, NULL))) { return ZAP_FAIL; } From 37dd6427ea50cf76c952322ed31714341066f17a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 15 Aug 2007 15:54:00 +0000 Subject: [PATCH 0608/1766] fix sloppy commit when updated to new module interface git-svn-id: http://svn.openzap.org/svn/openzap/trunk@308 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index b70b5cfaee..bbb7403a04 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -731,7 +731,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi - if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { + if ((*new_session = switch_core_session_request(channel_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; switch_caller_profile_t *caller_profile; @@ -801,7 +801,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(&channel_endpoint_interface, NULL))) { + if (!(session = switch_core_session_request(channel_endpoint_interface, NULL))) { return ZAP_FAIL; } From 26d00bd45601f10c866a63052c5f96e8e52f9905 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 19 Aug 2007 20:19:01 +0000 Subject: [PATCH 0609/1766] use relative path git-svn-id: http://svn.openzap.org/svn/openzap/trunk@309 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index 7edd420cdf..fcee33c9d8 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -1,4 +1,4 @@ -BASE=/usr/src/freeswitch.trunk +BASE=../../.. OZ_DIR=.. VERBOSE=1 OZA=$(OZ_DIR)/libopenzap.a From 4bc4bbc7525e45014e5f949d6f10577b31727ad9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 19 Aug 2007 20:19:01 +0000 Subject: [PATCH 0610/1766] use relative path git-svn-id: http://svn.openzap.org/svn/openzap/trunk@309 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index 7edd420cdf..fcee33c9d8 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -1,4 +1,4 @@ -BASE=/usr/src/freeswitch.trunk +BASE=../../.. OZ_DIR=.. VERBOSE=1 OZA=$(OZ_DIR)/libopenzap.a From 6583971b31a9cbeab58203b63ab9a0237f8f87c2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Oct 2007 18:10:25 +0000 Subject: [PATCH 0611/1766] fix scope of endpoint module structures git-svn-id: http://svn.openzap.org/svn/openzap/trunk@312 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index bbb7403a04..2dd3c76662 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -37,7 +37,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, NULL, NULL); -static switch_endpoint_interface_t *channel_endpoint_interface; +switch_endpoint_interface_t *openzap_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; static int running = 1; @@ -657,7 +657,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } -static switch_state_handler_table_t channel_state_handlers = { +switch_state_handler_table_t openzap_state_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, /*.on_execute */ channel_on_execute, @@ -666,7 +666,7 @@ static switch_state_handler_table_t channel_state_handlers = { /*.on_transmit */ channel_on_transmit }; -static switch_io_routines_t channel_io_routines = { +switch_io_routines_t openzap_io_routines = { /*.outgoing_channel */ channel_outgoing_channel, /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, @@ -731,7 +731,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi - if ((*new_session = switch_core_session_request(channel_endpoint_interface, pool)) != 0) { + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; switch_caller_profile_t *caller_profile; @@ -801,7 +801,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(channel_endpoint_interface, NULL))) { + if (!(session = switch_core_session_request(openzap_endpoint_interface, NULL))) { return ZAP_FAIL; } @@ -1208,10 +1208,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) } *module_interface = switch_loadable_module_create_module_interface(pool, modname); - channel_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); - channel_endpoint_interface->interface_name = "openzap"; - channel_endpoint_interface->io_routines = &channel_io_routines; - channel_endpoint_interface->state_handler = &channel_state_handlers; + openzap_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); + openzap_endpoint_interface->interface_name = "openzap"; + openzap_endpoint_interface->io_routines = &openzap_io_routines; + openzap_endpoint_interface->state_handler = &openzap_state_handlers; /* indicate that the module should continue to be loaded */ From dd7ff6f29b18988f3bd9cf42d8b35d497f47b893 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Oct 2007 18:10:25 +0000 Subject: [PATCH 0612/1766] fix scope of endpoint module structures git-svn-id: http://svn.openzap.org/svn/openzap/trunk@312 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index bbb7403a04..2dd3c76662 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -37,7 +37,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, NULL, NULL); -static switch_endpoint_interface_t *channel_endpoint_interface; +switch_endpoint_interface_t *openzap_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; static int running = 1; @@ -657,7 +657,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } -static switch_state_handler_table_t channel_state_handlers = { +switch_state_handler_table_t openzap_state_handlers = { /*.on_init */ channel_on_init, /*.on_ring */ channel_on_ring, /*.on_execute */ channel_on_execute, @@ -666,7 +666,7 @@ static switch_state_handler_table_t channel_state_handlers = { /*.on_transmit */ channel_on_transmit }; -static switch_io_routines_t channel_io_routines = { +switch_io_routines_t openzap_io_routines = { /*.outgoing_channel */ channel_outgoing_channel, /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, @@ -731,7 +731,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi - if ((*new_session = switch_core_session_request(channel_endpoint_interface, pool)) != 0) { + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; switch_caller_profile_t *caller_profile; @@ -801,7 +801,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(channel_endpoint_interface, NULL))) { + if (!(session = switch_core_session_request(openzap_endpoint_interface, NULL))) { return ZAP_FAIL; } @@ -1208,10 +1208,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) } *module_interface = switch_loadable_module_create_module_interface(pool, modname); - channel_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); - channel_endpoint_interface->interface_name = "openzap"; - channel_endpoint_interface->io_routines = &channel_io_routines; - channel_endpoint_interface->state_handler = &channel_state_handlers; + openzap_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); + openzap_endpoint_interface->interface_name = "openzap"; + openzap_endpoint_interface->io_routines = &openzap_io_routines; + openzap_endpoint_interface->state_handler = &openzap_state_handlers; /* indicate that the module should continue to be loaded */ From fb0c65a493db69a0516d8566206a621b83e96bed Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Oct 2007 21:59:26 +0000 Subject: [PATCH 0613/1766] handle mutex creation failure before marking the span configured. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@313 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index c15ac3c1ab..951f7424d7 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -288,10 +288,13 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { new_span = &globals.spans[++globals.span_index]; memset(new_span, 0, sizeof(*new_span)); + status = zap_mutex_create(&new_span->mutex); + if (status != ZAP_SUCCESS) { + goto done; + } zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); new_span->span_id = globals.span_index; new_span->zio = zio; - zap_mutex_create(&new_span->mutex); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); @@ -302,6 +305,8 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) } zap_mutex_unlock(globals.mutex); +done: + return status; } From 27145e4245d7116aa8685f03b069c249d4613e0c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Oct 2007 21:59:26 +0000 Subject: [PATCH 0614/1766] handle mutex creation failure before marking the span configured. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@313 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index c15ac3c1ab..951f7424d7 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -288,10 +288,13 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { new_span = &globals.spans[++globals.span_index]; memset(new_span, 0, sizeof(*new_span)); + status = zap_mutex_create(&new_span->mutex); + if (status != ZAP_SUCCESS) { + goto done; + } zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); new_span->span_id = globals.span_index; new_span->zio = zio; - zap_mutex_create(&new_span->mutex); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); @@ -302,6 +305,8 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) } zap_mutex_unlock(globals.mutex); +done: + return status; } From 19d8a3e3ac680606fd4fc3b09513b5c9869db92c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Oct 2007 22:15:42 +0000 Subject: [PATCH 0615/1766] don't destroy a mutex we are still using git-svn-id: http://svn.openzap.org/svn/openzap/trunk@314 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 951f7424d7..fe0c0a6d07 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -323,10 +323,6 @@ zap_status_t zap_span_close_all(void) zap_channel_destroy(&span->channels[i]); } - if (span->mutex) { - zap_mutex_destroy(&span->mutex); - } - zap_safe_free(span->signal_data); } zap_mutex_unlock(globals.mutex); @@ -1945,6 +1941,7 @@ zap_status_t zap_global_destroy(void) if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { zap_mutex_lock(cur_span->mutex); + zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); for(j = 1; j <= cur_span->chan_count; j++) { zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { @@ -1952,6 +1949,10 @@ zap_status_t zap_global_destroy(void) } } zap_mutex_unlock(cur_span->mutex); + + if (cur_span->mutex) { + zap_mutex_destroy(&cur_span->mutex); + } } } From d0465d4cd2ad2adf42292f7682e790632bde4cd9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 29 Oct 2007 22:15:42 +0000 Subject: [PATCH 0616/1766] don't destroy a mutex we are still using git-svn-id: http://svn.openzap.org/svn/openzap/trunk@314 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 951f7424d7..fe0c0a6d07 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -323,10 +323,6 @@ zap_status_t zap_span_close_all(void) zap_channel_destroy(&span->channels[i]); } - if (span->mutex) { - zap_mutex_destroy(&span->mutex); - } - zap_safe_free(span->signal_data); } zap_mutex_unlock(globals.mutex); @@ -1945,6 +1941,7 @@ zap_status_t zap_global_destroy(void) if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { zap_mutex_lock(cur_span->mutex); + zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); for(j = 1; j <= cur_span->chan_count; j++) { zap_channel_t *cur_chan = &cur_span->channels[j]; if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { @@ -1952,6 +1949,10 @@ zap_status_t zap_global_destroy(void) } } zap_mutex_unlock(cur_span->mutex); + + if (cur_span->mutex) { + zap_mutex_destroy(&cur_span->mutex); + } } } From 6ea45cbd2b587fce5ae36fded97690bb28f29087 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:10:14 +0000 Subject: [PATCH 0617/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@315 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_skel.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index c5e9a0e85d..b7e6f08555 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -83,6 +83,26 @@ static ZINT_WRITE_FUNCTION(skel_write) 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_GET_ALARMS_FUNCTION(skel_get_alarms) +{ + return zap_fail; +} + static zap_software_interface_t skel_interface; zap_status_t skel_init(zap_software_interface_t **zint) @@ -99,6 +119,10 @@ zap_status_t skel_init(zap_software_interface_t **zint) skel_interface.wait = skel_wait; skel_interface.read = skel_read; skel_interface.write = skel_write; + skel_interface.poll_event = skel_poll_event; + skel_interface.next_event = skel_next_event; + skel_interface.channel_destroy = skel_channel_destroy; + skel_interface.get_alarms = skel_get_alarms; *zint = &skel_interface; return ZAP_FAIL; From d5cd1adac016ea341b364ab07843d73d70eb9a8c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:10:14 +0000 Subject: [PATCH 0618/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@315 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_skel.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index c5e9a0e85d..b7e6f08555 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -83,6 +83,26 @@ static ZINT_WRITE_FUNCTION(skel_write) 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_GET_ALARMS_FUNCTION(skel_get_alarms) +{ + return zap_fail; +} + static zap_software_interface_t skel_interface; zap_status_t skel_init(zap_software_interface_t **zint) @@ -99,6 +119,10 @@ zap_status_t skel_init(zap_software_interface_t **zint) skel_interface.wait = skel_wait; skel_interface.read = skel_read; skel_interface.write = skel_write; + skel_interface.poll_event = skel_poll_event; + skel_interface.next_event = skel_next_event; + skel_interface.channel_destroy = skel_channel_destroy; + skel_interface.get_alarms = skel_get_alarms; *zint = &skel_interface; return ZAP_FAIL; From f24f9dcad8a058308112edd5d6dcf8fca47910d6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:35:34 +0000 Subject: [PATCH 0619/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@316 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_skel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index b7e6f08555..c1be4e9e99 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -103,9 +103,9 @@ static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) return zap_fail; } -static zap_software_interface_t skel_interface; +static zap_io_interface_t skel_interface; -zap_status_t skel_init(zap_software_interface_t **zint) +zap_status_t skel_init(zap_io_interface_t **zint) { assert(zint != NULL); memset(&skel_interface, 0, sizeof(skel_interface)); From b79063747c1982e109f029ccf7169d73c4de5acb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:35:34 +0000 Subject: [PATCH 0620/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@316 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_skel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index b7e6f08555..c1be4e9e99 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -103,9 +103,9 @@ static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) return zap_fail; } -static zap_software_interface_t skel_interface; +static zap_io_interface_t skel_interface; -zap_status_t skel_init(zap_software_interface_t **zint) +zap_status_t skel_init(zap_io_interface_t **zint) { assert(zint != NULL); memset(&skel_interface, 0, sizeof(skel_interface)); From a5af122aedecd6223b56d3b5dbd61b1f21da9a39 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:39:10 +0000 Subject: [PATCH 0621/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@317 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_skel.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index c1be4e9e99..5f31ea2166 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -35,51 +35,51 @@ #include "openzap.h" #include "zap_skel.h" -static ZINT_CONFIGURE_FUNCTION(skel_configure) +static ZIO_CONFIGURE_FUNCTION(skel_configure) { - ZINT_CONFIGURE_MUZZLE; + ZIO_CONFIGURE_MUZZLE; return ZAP_FAIL; } -static ZINT_OPEN_FUNCTION(skel_open) +static ZIO_OPEN_FUNCTION(skel_open) { - ZINT_OPEN_MUZZLE; + ZIO_OPEN_MUZZLE; return ZAP_FAIL; } -static ZINT_CLOSE_FUNCTION(skel_close) +static ZIO_CLOSE_FUNCTION(skel_close) { - ZINT_CLOSE_MUZZLE; + ZIO_CLOSE_MUZZLE; return ZAP_FAIL; } -static ZINT_SET_CODEC_FUNCTION(skel_set_codec) +static ZIO_SET_CODEC_FUNCTION(skel_set_codec) { - ZINT_SET_CODEC_MUZZLE; + ZIO_SET_CODEC_MUZZLE; return ZAP_FAIL; } -static ZINT_SET_INTERVAL_FUNCTION(skel_set_interval) +static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval) { - ZINT_SET_INTERVAL_MUZZLE; + ZIO_SET_INTERVAL_MUZZLE; return ZAP_FAIL; } -static ZINT_WAIT_FUNCTION(skel_wait) +static ZIO_WAIT_FUNCTION(skel_wait) { - ZINT_WAIT_MUZZLE; + ZIO_WAIT_MUZZLE; return ZAP_FAIL; } -static ZINT_READ_FUNCTION(skel_read) +static ZIO_READ_FUNCTION(skel_read) { - ZINT_READ_MUZZLE; + ZIO_READ_MUZZLE; return ZAP_FAIL; } -static ZINT_WRITE_FUNCTION(skel_write) +static ZIO_WRITE_FUNCTION(skel_write) { - ZINT_WRITE_MUZZLE; + ZIO_WRITE_MUZZLE; return ZAP_FAIL; } From d30d52bab456f90f758af18ab914db0246d37be7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:39:10 +0000 Subject: [PATCH 0622/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@317 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_skel.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index c1be4e9e99..5f31ea2166 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -35,51 +35,51 @@ #include "openzap.h" #include "zap_skel.h" -static ZINT_CONFIGURE_FUNCTION(skel_configure) +static ZIO_CONFIGURE_FUNCTION(skel_configure) { - ZINT_CONFIGURE_MUZZLE; + ZIO_CONFIGURE_MUZZLE; return ZAP_FAIL; } -static ZINT_OPEN_FUNCTION(skel_open) +static ZIO_OPEN_FUNCTION(skel_open) { - ZINT_OPEN_MUZZLE; + ZIO_OPEN_MUZZLE; return ZAP_FAIL; } -static ZINT_CLOSE_FUNCTION(skel_close) +static ZIO_CLOSE_FUNCTION(skel_close) { - ZINT_CLOSE_MUZZLE; + ZIO_CLOSE_MUZZLE; return ZAP_FAIL; } -static ZINT_SET_CODEC_FUNCTION(skel_set_codec) +static ZIO_SET_CODEC_FUNCTION(skel_set_codec) { - ZINT_SET_CODEC_MUZZLE; + ZIO_SET_CODEC_MUZZLE; return ZAP_FAIL; } -static ZINT_SET_INTERVAL_FUNCTION(skel_set_interval) +static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval) { - ZINT_SET_INTERVAL_MUZZLE; + ZIO_SET_INTERVAL_MUZZLE; return ZAP_FAIL; } -static ZINT_WAIT_FUNCTION(skel_wait) +static ZIO_WAIT_FUNCTION(skel_wait) { - ZINT_WAIT_MUZZLE; + ZIO_WAIT_MUZZLE; return ZAP_FAIL; } -static ZINT_READ_FUNCTION(skel_read) +static ZIO_READ_FUNCTION(skel_read) { - ZINT_READ_MUZZLE; + ZIO_READ_MUZZLE; return ZAP_FAIL; } -static ZINT_WRITE_FUNCTION(skel_write) +static ZIO_WRITE_FUNCTION(skel_write) { - ZINT_WRITE_MUZZLE; + ZIO_WRITE_MUZZLE; return ZAP_FAIL; } From e6a9f5f9cad97dbb9a24a6cfcf7305d5ef42b0ab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:41:29 +0000 Subject: [PATCH 0623/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@318 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_skel.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index 5f31ea2166..34a840c9da 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -53,12 +53,6 @@ static ZIO_CLOSE_FUNCTION(skel_close) return ZAP_FAIL; } -static ZIO_SET_CODEC_FUNCTION(skel_set_codec) -{ - ZIO_SET_CODEC_MUZZLE; - return ZAP_FAIL; -} - static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval) { ZIO_SET_INTERVAL_MUZZLE; @@ -114,8 +108,6 @@ zap_status_t skel_init(zap_io_interface_t **zint) skel_interface.configure = skel_configure; skel_interface.open = skel_open; skel_interface.close = skel_close; - skel_interface.set_codec = skel_set_codec; - skel_interface.set_interval = skel_set_interval; skel_interface.wait = skel_wait; skel_interface.read = skel_read; skel_interface.write = skel_write; From a490ea53a5565ac942974eea821169d857a363f8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 15:41:29 +0000 Subject: [PATCH 0624/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@318 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_skel.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index 5f31ea2166..34a840c9da 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -53,12 +53,6 @@ static ZIO_CLOSE_FUNCTION(skel_close) return ZAP_FAIL; } -static ZIO_SET_CODEC_FUNCTION(skel_set_codec) -{ - ZIO_SET_CODEC_MUZZLE; - return ZAP_FAIL; -} - static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval) { ZIO_SET_INTERVAL_MUZZLE; @@ -114,8 +108,6 @@ zap_status_t skel_init(zap_io_interface_t **zint) skel_interface.configure = skel_configure; skel_interface.open = skel_open; skel_interface.close = skel_close; - skel_interface.set_codec = skel_set_codec; - skel_interface.set_interval = skel_set_interval; skel_interface.wait = skel_wait; skel_interface.read = skel_read; skel_interface.write = skel_write; From e569e45f967b889673d77f1b511a43fac57a7780 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 16:49:29 +0000 Subject: [PATCH 0625/1766] fix ret val git-svn-id: http://svn.openzap.org/svn/openzap/trunk@319 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_zt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 3313216f6c..b2ee4c95b8 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -707,7 +707,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) if ((CONTROL_FD = open(ctlpath, O_RDWR)) < 0) { zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); - return 0; + return ZAP_FAIL; } zt_globals.codec_ms = 20; From 1aa7718594cc1eb15115bcd304b79f568135259e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 16:49:29 +0000 Subject: [PATCH 0626/1766] fix ret val git-svn-id: http://svn.openzap.org/svn/openzap/trunk@319 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_zt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 3313216f6c..b2ee4c95b8 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -707,7 +707,7 @@ zap_status_t zt_init(zap_io_interface_t **zio) if ((CONTROL_FD = open(ctlpath, O_RDWR)) < 0) { zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); - return 0; + return ZAP_FAIL; } zt_globals.codec_ms = 20; From 07f6b885102e22e852768fcc493e63d1e393d7ac Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 16:55:29 +0000 Subject: [PATCH 0627/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@320 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_skel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index 34a840c9da..992ca264e1 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -41,6 +41,11 @@ static ZIO_CONFIGURE_FUNCTION(skel_configure) return ZAP_FAIL; } +static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) +{ + +} + static ZIO_OPEN_FUNCTION(skel_open) { ZIO_OPEN_MUZZLE; @@ -106,6 +111,7 @@ zap_status_t skel_init(zap_io_interface_t **zint) 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; From 1d3dc55f6bb9e83081bea2966298db9e14d54dc4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 6 Nov 2007 16:55:29 +0000 Subject: [PATCH 0628/1766] update sample git-svn-id: http://svn.openzap.org/svn/openzap/trunk@320 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_skel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index 34a840c9da..992ca264e1 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -41,6 +41,11 @@ static ZIO_CONFIGURE_FUNCTION(skel_configure) return ZAP_FAIL; } +static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) +{ + +} + static ZIO_OPEN_FUNCTION(skel_open) { ZIO_OPEN_MUZZLE; @@ -106,6 +111,7 @@ zap_status_t skel_init(zap_io_interface_t **zint) 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; From 10dbcfd16eaca3c547522c425b221a3fbb5a2986 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 7 Nov 2007 17:17:06 +0000 Subject: [PATCH 0629/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@321 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index fcee33c9d8..aa763e48d8 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -9,6 +9,6 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) $(OZA): - cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb" + cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb $(ALL_CXXFLAGS)" From 8dfb3e42f98ea13ad617bad36d5dcd7b983d1e79 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 7 Nov 2007 17:17:06 +0000 Subject: [PATCH 0630/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@321 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index fcee33c9d8..aa763e48d8 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -9,6 +9,6 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) $(OZA): - cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb" + cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb $(ALL_CXXFLAGS)" From 78d0742c27f217aed4c1cd0798655db364e08db1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 7 Nov 2007 21:15:30 +0000 Subject: [PATCH 0631/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@322 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone_generate.h | 2 +- libs/openzap/src/libteletone_generate.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index f303d82004..83fd3f00ef 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -288,7 +288,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m \param cmd the script to execute \return 0 */ -int teletone_run(teletone_generation_session_t *ts, char *cmd); +int teletone_run(teletone_generation_session_t *ts, const char *cmd); #ifdef __cplusplus } diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index a9060a8149..6b262252bb 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -315,7 +315,7 @@ static char *my_strdup (const char *s) return (char *) memcpy (new, s, len); } -int teletone_run(teletone_generation_session_t *ts, char *cmd) +int teletone_run(teletone_generation_session_t *ts, const char *cmd) { char *data = NULL, *cur = NULL, *end = NULL; int var = 0, LOOPING = 0; From 6d8797a0180aa1bf49ad647d677d27f904c6c218 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 7 Nov 2007 21:15:30 +0000 Subject: [PATCH 0632/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@322 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone_generate.h | 2 +- libs/freetdm/src/libteletone_generate.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index f303d82004..83fd3f00ef 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -288,7 +288,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m \param cmd the script to execute \return 0 */ -int teletone_run(teletone_generation_session_t *ts, char *cmd); +int teletone_run(teletone_generation_session_t *ts, const char *cmd); #ifdef __cplusplus } diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index a9060a8149..6b262252bb 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -315,7 +315,7 @@ static char *my_strdup (const char *s) return (char *) memcpy (new, s, len); } -int teletone_run(teletone_generation_session_t *ts, char *cmd) +int teletone_run(teletone_generation_session_t *ts, const char *cmd) { char *data = NULL, *cur = NULL, *end = NULL; int var = 0, LOOPING = 0; From 74e84739715bf571fba00a3b32458ff97dc04f4c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 00:50:28 +0000 Subject: [PATCH 0633/1766] avoiding segfault git-svn-id: http://svn.openzap.org/svn/openzap/trunk@323 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 2dd3c76662..5be169488e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -167,6 +167,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); tech_pvt->cng_frame.data = tech_pvt->cng_databuf; tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); + tech_pvt->cng_frame.flags = SFF_CNG; memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.buflen); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); From 3d76eaab99374046d5aea7b79a705039de24795f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 00:50:28 +0000 Subject: [PATCH 0634/1766] avoiding segfault git-svn-id: http://svn.openzap.org/svn/openzap/trunk@323 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 2dd3c76662..5be169488e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -167,6 +167,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); tech_pvt->cng_frame.data = tech_pvt->cng_databuf; tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); + tech_pvt->cng_frame.flags = SFF_CNG; memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.buflen); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); From 003bdd30f2c15af65af9b08160052acb259b79fa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 01:22:58 +0000 Subject: [PATCH 0635/1766] avoiding initial deadlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@324 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index fe0c0a6d07..09d4727dc6 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -303,10 +303,9 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) *span = new_span; status = ZAP_SUCCESS; } - zap_mutex_unlock(globals.mutex); done: - + zap_mutex_unlock(globals.mutex); return status; } From 2c15f1087c6ad9ecc9e6ebc4ecca6fa0a355e1cb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 01:22:58 +0000 Subject: [PATCH 0636/1766] avoiding initial deadlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@324 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index fe0c0a6d07..09d4727dc6 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -303,10 +303,9 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) *span = new_span; status = ZAP_SUCCESS; } - zap_mutex_unlock(globals.mutex); done: - + zap_mutex_unlock(globals.mutex); return status; } From df84e318eb4d20c8794d05f29b6daf6a39917b35 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 01:40:45 +0000 Subject: [PATCH 0637/1766] avoiding secondary deadlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@325 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 09d4727dc6..2030e5ecc5 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -719,7 +719,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_channel_open_chan(check); *zchan = check; - return status; + goto done; } } @@ -740,6 +740,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } + done: zap_mutex_unlock(globals.mutex); return status; From bfb4be9ad9b80706cd2697117a70d592af311072 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 01:40:45 +0000 Subject: [PATCH 0638/1766] avoiding secondary deadlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@325 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 09d4727dc6..2030e5ecc5 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -719,7 +719,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_channel_open_chan(check); *zchan = check; - return status; + goto done; } } @@ -740,6 +740,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } + done: zap_mutex_unlock(globals.mutex); return status; From 02070dc6b229b38cc309eb14e1cc3df847b9018f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 01:42:21 +0000 Subject: [PATCH 0639/1766] bottoms up! git-svn-id: http://svn.openzap.org/svn/openzap/trunk@326 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5be169488e..fc63935a6c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -720,7 +720,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (chan_id) { - status = zap_channel_open(span_id, chan_id, &zchan); + if (chan_id > 0) { + status = zap_channel_open(span_id, chan_id, &zchan); + } else { + status = zap_channel_open_any(span_id, ZAP_BOTTOM_UP, &zchan); + } } else { status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); } From 9aa7a3f9fdeedab1c3961d636ebfb21ea4c8b872 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 Nov 2007 01:42:21 +0000 Subject: [PATCH 0640/1766] bottoms up! git-svn-id: http://svn.openzap.org/svn/openzap/trunk@326 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5be169488e..fc63935a6c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -720,7 +720,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (chan_id) { - status = zap_channel_open(span_id, chan_id, &zchan); + if (chan_id > 0) { + status = zap_channel_open(span_id, chan_id, &zchan); + } else { + status = zap_channel_open_any(span_id, ZAP_BOTTOM_UP, &zchan); + } } else { status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); } From 194fad282d24ebf1eedd5b49cc2b213473e11d1a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 13 Nov 2007 20:06:07 +0000 Subject: [PATCH 0641/1766] fix sun studio build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@327 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone_generate.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index 83fd3f00ef..addd1ebea9 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -79,10 +79,18 @@ extern "C" { #include #include + +#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) +#ifndef __inline__ +#define __inline__ inline +#endif +#endif + #ifdef _MSC_VER #ifndef __inline__ #define __inline__ __inline #endif + typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef unsigned __int16 uint16_t; From df25daeaae80edb96986d6454bfdedd4018f0067 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 13 Nov 2007 20:06:07 +0000 Subject: [PATCH 0642/1766] fix sun studio build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@327 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone_generate.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index 83fd3f00ef..addd1ebea9 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -79,10 +79,18 @@ extern "C" { #include #include + +#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) +#ifndef __inline__ +#define __inline__ inline +#endif +#endif + #ifdef _MSC_VER #ifndef __inline__ #define __inline__ __inline #endif + typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef unsigned __int16 uint16_t; From 4c6a22bf8e11c3138546c36517872d9b76157bdb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Nov 2007 22:05:41 +0000 Subject: [PATCH 0643/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@328 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 24 +++++++++++++++++++----- libs/openzap/src/detect_tones.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 libs/openzap/src/detect_tones.c diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 1eb5054414..32b70f0cc4 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -98,18 +98,29 @@ $(SRC)/isdn/include/Q932.h PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -CFLAGS=$(ZAP_CFLAGS) $(INCS) +CFLAGS= $(INCS) $(ZAP_CFLAGS) MYLIB=libopenzap.a LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +PIKA_DIR=$(shell ls -d /usr/include/pika) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so) + +ifneq ($(PIKA_DIR),) +ifneq ($(PIKA_LIB),) +OBJS += $(SRC)/zap_pika.o +CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +ADD_OBJS = $(PIKA_LIB) +endif +endif + include general.makefile all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) - ar rcs $(MYLIB) $(OBJS) + ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) ranlib $(MYLIB) testapp: $(SRC)/testapp.c $(MYLIB) @@ -119,13 +130,16 @@ testcid: $(SRC)/testcid.c $(MYLIB) $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + +detect_tones: $(SRC)/detect_tones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread $(SRC)/priserver.o: $(SRC)/priserver.c $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o @@ -160,6 +174,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/src/detect_tones.c b/libs/openzap/src/detect_tones.c new file mode 100644 index 0000000000..52ccbcd506 --- /dev/null +++ b/libs/openzap/src/detect_tones.c @@ -0,0 +1,31 @@ +//#include "openzap.h" +#include "libteletone_detect.h" + +int main(int argc, char *argv[]) +{ + teletone_generation_session_t ts; + teletone_multi_tone_t mt = {0}; + teletone_tone_map_t map = {350.0, 440.0, 0.0}; + + int fd, b; + short sln[512] = {0}; + + if (argc < 2) { + fprintf(stderr, "Arg Error!\n"); + exit(-1); + } + + teletone_multi_tone_init(&mt, &map); + + + if ((fd = open(argv[1], O_RDONLY)) < 0) { + fprintf(stderr, "File Error!\n", strerror(errno)); + exit(-1); + } + + while((b = read(fd, sln, 320)) > 0) { + printf("TEST %d %d\n", b, teletone_multi_tone_detect(&mt, sln, b / 2)); + } + close(fd); +} + From 86fc8ff116d4de940c3be3934bacbc02ee594b3a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Nov 2007 22:05:41 +0000 Subject: [PATCH 0644/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@328 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 24 +++++++++++++++++++----- libs/freetdm/src/detect_tones.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 libs/freetdm/src/detect_tones.c diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 1eb5054414..32b70f0cc4 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -98,18 +98,29 @@ $(SRC)/isdn/include/Q932.h PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -CFLAGS=$(ZAP_CFLAGS) $(INCS) +CFLAGS= $(INCS) $(ZAP_CFLAGS) MYLIB=libopenzap.a LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +PIKA_DIR=$(shell ls -d /usr/include/pika) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so) + +ifneq ($(PIKA_DIR),) +ifneq ($(PIKA_LIB),) +OBJS += $(SRC)/zap_pika.o +CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +ADD_OBJS = $(PIKA_LIB) +endif +endif + include general.makefile all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) - ar rcs $(MYLIB) $(OBJS) + ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) ranlib $(MYLIB) testapp: $(SRC)/testapp.c $(MYLIB) @@ -119,13 +130,16 @@ testcid: $(SRC)/testcid.c $(MYLIB) $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + +detect_tones: $(SRC)/detect_tones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread $(SRC)/priserver.o: $(SRC)/priserver.c $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o @@ -160,6 +174,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/src/detect_tones.c b/libs/freetdm/src/detect_tones.c new file mode 100644 index 0000000000..52ccbcd506 --- /dev/null +++ b/libs/freetdm/src/detect_tones.c @@ -0,0 +1,31 @@ +//#include "openzap.h" +#include "libteletone_detect.h" + +int main(int argc, char *argv[]) +{ + teletone_generation_session_t ts; + teletone_multi_tone_t mt = {0}; + teletone_tone_map_t map = {350.0, 440.0, 0.0}; + + int fd, b; + short sln[512] = {0}; + + if (argc < 2) { + fprintf(stderr, "Arg Error!\n"); + exit(-1); + } + + teletone_multi_tone_init(&mt, &map); + + + if ((fd = open(argv[1], O_RDONLY)) < 0) { + fprintf(stderr, "File Error!\n", strerror(errno)); + exit(-1); + } + + while((b = read(fd, sln, 320)) > 0) { + printf("TEST %d %d\n", b, teletone_multi_tone_detect(&mt, sln, b / 2)); + } + close(fd); +} + From 481561c3965d4923b69ef10dd394c1ab3de9525e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Nov 2007 22:22:21 +0000 Subject: [PATCH 0645/1766] double trouble git-svn-id: http://svn.openzap.org/svn/openzap/trunk@329 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 7a3bf0d406..ec30cd106d 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -130,7 +130,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, } } -#define teletone_goertzel_result(gs) (float)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) +#define teletone_goertzel_result(gs) (double)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { From fb6a913060f6e2404823043bd1ee7be6afb55322 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Nov 2007 22:22:21 +0000 Subject: [PATCH 0646/1766] double trouble git-svn-id: http://svn.openzap.org/svn/openzap/trunk@329 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 7a3bf0d406..ec30cd106d 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -130,7 +130,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, } } -#define teletone_goertzel_result(gs) (float)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) +#define teletone_goertzel_result(gs) (double)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { From 023015040685ecf827c9e49011309e88b57c7c3b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 16 Nov 2007 20:17:43 +0000 Subject: [PATCH 0647/1766] silence warning git-svn-id: http://svn.openzap.org/svn/openzap/trunk@330 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index ec30cd106d..c695d7e7b2 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -130,6 +130,10 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, } } +#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)) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) From b25d204d2bd3a4204028626a59c7f4d549c67b74 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 16 Nov 2007 20:17:43 +0000 Subject: [PATCH 0648/1766] silence warning git-svn-id: http://svn.openzap.org/svn/openzap/trunk@330 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index ec30cd106d..c695d7e7b2 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -130,6 +130,10 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, } } +#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)) void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) From e791b35e75c525b738e66851749b9f97e8c59a72 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 01:39:28 +0000 Subject: [PATCH 0649/1766] pika-choo i choose you git-svn-id: http://svn.openzap.org/svn/openzap/trunk@331 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 5 +- libs/openzap/conf/pika.conf | 33 + libs/openzap/mod_openzap/mod_openzap.c | 60 +- libs/openzap/src/detect_dtmf.c | 32 + libs/openzap/src/detect_tones.c | 5 +- libs/openzap/src/include/openzap.h | 14 +- libs/openzap/src/include/zap_pika.h | 53 ++ libs/openzap/src/include/zap_types.h | 75 +- libs/openzap/src/testanalog.c | 3 +- libs/openzap/src/testtones.c | 4 +- libs/openzap/src/zap_analog.c | 92 ++- libs/openzap/src/zap_io.c | 99 ++- libs/openzap/src/zap_pika.c | 1012 ++++++++++++++++++++++++ libs/openzap/src/zap_skel.c | 12 + 14 files changed, 1419 insertions(+), 80 deletions(-) create mode 100644 libs/openzap/conf/pika.conf create mode 100644 libs/openzap/src/detect_dtmf.c create mode 100644 libs/openzap/src/include/zap_pika.h create mode 100644 libs/openzap/src/zap_pika.c diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 32b70f0cc4..94883699c5 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -135,6 +135,9 @@ testtones: $(SRC)/testtones.c $(MYLIB) detect_tones: $(SRC)/detect_tones.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm +detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread @@ -174,6 +177,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf new file mode 100644 index 0000000000..1cba63b2ef --- /dev/null +++ b/libs/openzap/conf/pika.conf @@ -0,0 +1,33 @@ +; each category is a config profile +; to apply the profile append it to a channel def in +; openzap.conf with @ +; e.g. +; [span pika] +; name => pika +; number => pika +; fxs-channel => 1:0:1-12@default + +[default] +rx-gain => 0 +rx-agc-enabled => 0 +rx-agc-targetPower => 0 +rx-agc-minGain => 0 +rx-agc-maxGain => 0 +rx-agc-attackRate => 0 +rx-agc-decayRate => 0 +rx-agc-speechThreshold => 0 +rx-vad-enabled => 0 +rx-vad-activationThreshold => 0 +rx-vad-activationDebounceTime => 0 +rx-vad-deactivationThreshold => 0 +rx-vad-deactivationDebounceTime => 0 +rx-vad-preSpeechBufferSize => 0 +tx-gain => 0 +tx-agc-enabled => 0 +tx-agc-targetPower => 0 +tx-agc-minGain => 0 +tx-agc-maxGain => 0 +tx-agc-attackRate => 0 +tx-agc-decayRate => 0 +tx-agc-speechThreshold => 0 + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index fc63935a6c..a712b500f3 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -304,14 +304,14 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); - } + + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } break; case ZAP_CHAN_TYPE_FXS: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_BUSY && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { if (tech_pvt->zchan->token_count) { cycle_foreground(tech_pvt->zchan, 0); } else { @@ -466,20 +466,21 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (!switch_test_flag(tech_pvt, TFLAG_IO)) { - return SWITCH_STATUS_FALSE; + goto fail; } + wflags = ZAP_READ; status = zap_channel_wait(tech_pvt->zchan, &wflags, chunk); - + if (status == ZAP_FAIL) { - return SWITCH_STATUS_GENERR; + goto fail; } if (status == ZAP_TIMEOUT) { if (timeout > 0 && !switch_test_flag(tech_pvt, TFLAG_HOLD)) { total_to -= chunk; if (total_to <= 0) { - return SWITCH_STATUS_BREAK; + goto fail; } } @@ -487,12 +488,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (!(wflags & ZAP_READ)) { - return SWITCH_STATUS_GENERR; + goto fail; } len = tech_pvt->read_frame.buflen; if (zap_channel_read(tech_pvt->zchan, tech_pvt->read_frame.data, &len) != ZAP_SUCCESS) { - return SWITCH_STATUS_GENERR; + goto fail; } *frame = &tech_pvt->read_frame; @@ -509,6 +510,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_SUCCESS; + fail: + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + return SWITCH_STATUS_GENERR; + + } static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) @@ -530,13 +537,13 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } if (!switch_test_flag(tech_pvt, TFLAG_IO)) { - return SWITCH_STATUS_FALSE; + goto fail; } len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { - return SWITCH_STATUS_GENERR; + goto fail; } } else { tech_pvt->wr_error = 0; @@ -544,6 +551,11 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc return SWITCH_STATUS_SUCCESS; + fail: + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + return SWITCH_STATUS_GENERR; + } static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) @@ -833,7 +845,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->chan_number); } } - + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), "OpenZAP", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, @@ -875,9 +887,29 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) switch_channel_t *channel = NULL; zap_status_t status; - zap_log(ZAP_LOG_DEBUG, "got FXO sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got FXO 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_PROGRESS_MEDIA: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_pre_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_STOP: + { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_channel_clear_token(sigmsg->channel, 0); + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { diff --git a/libs/openzap/src/detect_dtmf.c b/libs/openzap/src/detect_dtmf.c new file mode 100644 index 0000000000..941237b464 --- /dev/null +++ b/libs/openzap/src/detect_dtmf.c @@ -0,0 +1,32 @@ +//#include "openzap.h" +#include "libteletone_detect.h" + +int main(int argc, char *argv[]) +{ + int fd, b; + short sln[512] = {0}; + teletone_dtmf_detect_state_t dtmf_detect = {0}; + char digit_str[128] = ""; + + if (argc < 2) { + fprintf(stderr, "Arg Error!\n"); + exit(-1); + } + + teletone_dtmf_detect_init (&dtmf_detect, 8000); + + if ((fd = open(argv[1], O_RDONLY)) < 0) { + fprintf(stderr, "File Error!\n", strerror(errno)); + exit(-1); + } + + while((b = read(fd, sln, 320)) > 0) { + teletone_dtmf_detect(&dtmf_detect, sln, b / 2); + teletone_dtmf_get(&dtmf_detect, digit_str, sizeof(digit_str)); + if (*digit_str) { + printf("digit: %s\n", digit_str); + } + } + close(fd); +} + diff --git a/libs/openzap/src/detect_tones.c b/libs/openzap/src/detect_tones.c index 52ccbcd506..c5d475edc3 100644 --- a/libs/openzap/src/detect_tones.c +++ b/libs/openzap/src/detect_tones.c @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) { teletone_generation_session_t ts; teletone_multi_tone_t mt = {0}; - teletone_tone_map_t map = {350.0, 440.0, 0.0}; + teletone_tone_map_t map = {0}; int fd, b; short sln[512] = {0}; @@ -15,6 +15,9 @@ int main(int argc, char *argv[]) exit(-1); } + + map.freqs[0] = atof("350"); + map.freqs[1] = atof("440"); teletone_multi_tone_init(&mt, &map); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 12bc936a75..c57ef1c5f3 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -211,12 +211,12 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%dfrom %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s); \ - if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ - else zap_log(ZAP_LOG_WARNING, "VETO Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ + if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ + else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } @@ -344,7 +344,6 @@ struct zap_channel { zap_event_t event_header; char last_error[256]; zio_event_cb_t event_callback; - void *mod_data; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; zap_buffer_t *digit_buffer; @@ -365,6 +364,7 @@ struct zap_channel { zap_fsk_data_state_t fsk; uint8_t fsk_buf[80]; uint32_t ring_count; + void *mod_data; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -416,7 +416,8 @@ struct zap_span { teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; zio_channel_outgoing_call_t outgoing_call; - void *app_data; + void *mod_data; + char *type; }; @@ -429,6 +430,7 @@ struct zap_io_interface { zio_open_t open; zio_close_t close; zio_channel_destroy_t channel_destroy; + zio_span_destroy_t span_destroy; zio_get_alarms_t get_alarms; zio_command_t command; zio_wait_t wait; @@ -505,6 +507,8 @@ void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); +int zap_hash_equalkeys(void *k1, void *k2); +uint32_t zap_hash_hashfromstring(void *ky); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/include/zap_pika.h b/libs/openzap/src/include/zap_pika.h new file mode 100644 index 0000000000..6d1c68f5f6 --- /dev/null +++ b/libs/openzap/src/include/zap_pika.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_PIKA_H +#define ZAP_PIKA_H +#include "openzap.h" +#include "pikahmpapi.h" +/* Openzap PIKA hardware interface functions */ +zap_status_t pika_init(zap_io_interface_t **zint); +zap_status_t pika_destroy(void); + +#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 expandtab: + */ diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 4055b0c931..e05f219f25 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -267,10 +267,11 @@ typedef enum { } zap_chan_type_t; typedef enum { - ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), - ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), - ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2), - ZAP_CHANNEL_FEATURE_CALLERID = (1 << 3) + 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_t; typedef enum { @@ -339,6 +340,7 @@ typedef struct zap_span zap_span_t; #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) @@ -356,6 +358,7 @@ 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 ; @@ -373,6 +376,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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 @@ -410,6 +414,69 @@ typedef struct value zap_hash_val_t; typedef struct zap_bitstream zap_bitstream_t; typedef struct zap_fsk_modulator zap_fsk_modulator_t; +typedef enum { + ZAP_CAUSE_UNALLOCATED = 0, + ZAP_CAUSE_SUCCESS = 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_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: diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index dc90861834..1ad530db89 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -14,7 +14,8 @@ static void *test_call(zap_thread_t *me, void *obj) 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, "5551212"); + while (chan->state == ZAP_CHANNEL_STATE_UP) { zap_wait_flag_t flags = ZAP_READ; diff --git a/libs/openzap/src/testtones.c b/libs/openzap/src/testtones.c index b041095b76..d6b3a68552 100644 --- a/libs/openzap/src/testtones.c +++ b/libs/openzap/src/testtones.c @@ -20,8 +20,8 @@ int main(int argc, char *argv[]) teletone_generation_session_t ts; struct ttmp tmp; - if (argc < 2) { - fprintf(stderr, "Arg Error!\n"); + if (argc < 3) { + fprintf(stderr, "Arg Error! \n"); exit(-1); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 23a9054dd0..bc02794acd 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -44,7 +44,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + zap_channel_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_clear_needed_tones(zchan); zap_channel_clear_detected_tones(zchan); @@ -281,13 +282,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { - if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } @@ -346,7 +348,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); indicate = 0; state_counter = 0; - zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(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)); switch(zchan->state) { case ZAP_CHANNEL_STATE_UP: { @@ -399,9 +403,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(zchan); sig.event_id = ZAP_SIGEVENT_STOP; analog_data->sig_cb(&sig); + zap_channel_done(zchan); goto done; } break; @@ -453,18 +457,27 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_BUSY: { - zap_channel_done(zchan); - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); - indicate = 1; + 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_channel_done(zchan); + 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: { - zap_channel_done(zchan); - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); - indicate = 1; + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_channel_done(zchan); + 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: @@ -514,25 +527,42 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { if (zchan->detected_tones[i]) { - zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(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; - analog_data->sig_cb(&sig); + if (analog_data->sig_cb) { + analog_data->sig_cb(&sig); + } } } - if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) { - zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani); - 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) + 50; + 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)) { + 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) != 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)) + 3000; + } + } } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } else if (zchan->detected_tones[ZAP_TONEMAP_BUSY]) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } zap_channel_clear_detected_tones(zchan); @@ -580,6 +610,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } done: + zap_channel_done(zchan); @@ -647,7 +678,10 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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_DOWN); + + if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); + } } break; case ZAP_OOB_FLASH: diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2030e5ecc5..30a9771beb 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -47,6 +47,9 @@ #ifdef ZAP_ZT_SUPPORT #include "zap_zt.h" #endif +#ifdef ZAP_PIKA_SUPPORT +#include "zap_pika.h" +#endif static int time_is_init = 0; @@ -192,12 +195,12 @@ void zap_global_set_default_logger(int level) zap_log_level = level; } -static int equalkeys(void *k1, void *k2) +int zap_hash_equalkeys(void *k1, void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static uint32_t hashfromstring(void *ky) +uint32_t zap_hash_hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; uint32_t hash = 0; @@ -211,6 +214,19 @@ static uint32_t hashfromstring(void *ky) } +static zap_status_t zap_span_destroy(zap_span_t *span) +{ + zap_status_t status = ZAP_FAIL; + + if (zap_test_flag(span, ZAP_SPAN_CONFIGURED) && span->zio && span->zio->span_destroy) { + zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); + status = span->zio->span_destroy(span); + zap_safe_free(span->type); + } + + return status; +} + static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { @@ -227,7 +243,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) if (zchan->span->zio->channel_destroy) { - zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); + zap_log(ZAP_LOG_INFO, "Closing channel %s:%u:%u fd:%d\n", zchan->span->type, zchan->span_id, zchan->chan_id, zchan->sockfd); if (zchan->span->zio->channel_destroy(zchan) == ZAP_SUCCESS) { zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); } else { @@ -315,14 +331,13 @@ zap_status_t zap_span_close_all(void) uint32_t i, j; zap_mutex_lock(globals.mutex); - for(i = 0; i < globals.span_index; i++) { + for(i = 1; i <= globals.span_index; i++) { span = &globals.spans[i]; - - for(j = 0; j < span->chan_count; j++) { - zap_channel_destroy(&span->channels[i]); - } - - zap_safe_free(span->signal_data); + if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + for(j = 0; j < span->chan_count; j++) { + zap_channel_destroy(&span->channels[i]); + } + } } zap_mutex_unlock(globals.mutex); @@ -938,6 +953,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); } } + if (!zchan->tone_session.buffer) { memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); @@ -947,6 +963,8 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zchan->tone_session.rate = zchan->rate; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); + zchan->tone_session.volume = -7; + /* zchan->tone_session.debug = 1; zchan->tone_session.debug_stream = stdout; @@ -1083,6 +1101,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: { /* if they don't have thier own, use ours */ + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); @@ -1101,7 +1121,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_ENABLE_DTMF_DETECT: { /* if they don't have thier own, use ours */ - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); @@ -1117,7 +1137,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_DISABLE_DTMF_DETECT: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); @@ -1132,7 +1152,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } case ZAP_COMMAND_GET_DTMF_ON_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1140,7 +1160,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_GET_DTMF_OFF_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1148,7 +1168,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_SET_DTMF_ON_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_on = val; @@ -1162,7 +1182,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_SET_DTMF_OFF_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_off = val; @@ -1176,7 +1196,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_SEND_DTMF: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; int x = 0; @@ -1523,7 +1543,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data *(str+mlen) = '\0'; zap_copy_string(str, sp, ++mlen); zap_clean_string(str); - zap_log(ZAP_LOG_ERROR, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); switch(type) { case MDMF_DDN: @@ -1570,13 +1590,14 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint32_t i; - + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { if (zchan->span->tone_finder[i].tone_count) { if (zchan->needed_tones[i] && teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen)) { - zchan->detected_tones[i] = 1; - zchan->needed_tones[i] = 0; - zchan->detected_tones[0]++; + if (++zchan->detected_tones[i]) { + zchan->needed_tones[i] = 0; + zchan->detected_tones[0]++; + } } } } @@ -1713,6 +1734,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data static struct { zap_io_interface_t *wanpipe_interface; zap_io_interface_t *zt_interface; + zap_io_interface_t *pika_interface; } interfaces; @@ -1760,7 +1782,14 @@ static zap_status_t load_config(void) continue; } + if (!zio->configure_span) { + zap_log(ZAP_LOG_CRIT, "failure creating span, no configure_span method for '%s'\n", type); + span = NULL; + continue; + } + if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + span->type = strdup(type); zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); d = 0; } else { @@ -1886,7 +1915,7 @@ zap_status_t zap_global_init(void) zap_isdn_init(); memset(&interfaces, 0, sizeof(interfaces)); - globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); + globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); @@ -1914,6 +1943,19 @@ zap_status_t zap_global_init(void) } #endif +#ifdef ZAP_PIKA_SUPPORT + if (pika_init(&interfaces.pika_interface) == ZAP_SUCCESS) { + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interfaces.pika_interface->name, interfaces.pika_interface); + process_module_config(interfaces.pika_interface); + zap_mutex_unlock(globals.mutex); + modcount++; + } else { + zap_log(ZAP_LOG_ERROR, "Error initilizing pika.\n"); + } +#endif + + if (!modcount) { zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); return ZAP_FAIL; @@ -1953,6 +1995,10 @@ zap_status_t zap_global_destroy(void) if (cur_span->mutex) { zap_mutex_destroy(&cur_span->mutex); } + + zap_safe_free(cur_span->signal_data); + zap_span_destroy(cur_span); + } } @@ -1962,6 +2008,13 @@ zap_status_t zap_global_destroy(void) zt_destroy(); } #endif + +#ifdef ZAP_PIKA_SUPPORT + if (interfaces.pika_interface) { + pika_destroy(); + } +#endif + #ifdef ZAP_WANPIPE_SUPPORT if (interfaces.wanpipe_interface) { wanpipe_destroy(); diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c new file mode 100644 index 0000000000..48be6f7a3f --- /dev/null +++ b/libs/openzap/src/zap_pika.c @@ -0,0 +1,1012 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_pika.h" +#define MAX_NUMBER_OF_TRUNKS 64 +#define PIKA_BLOCK_SIZE 160 +#define PIKA_BLOCK_LEN 20 + +struct pika_channel_profile { + char name[80]; + PKH_TRecordConfig record_config; + PKH_TPlayConfig play_config; +}; +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; + zap_hash_t *profile_hash; +} globals; + + +struct pika_span_data { + TPikaHandle event_queue; + PKH_TPikaEvent last_oob_event; + uint32_t boardno; +}; +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; + zap_buffer_t *digit_buffer; + zap_mutex_t *digit_mutex; + int dtmf_len; +}; +typedef struct pika_chan_data pika_chan_data_t; + +static 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"; +} + +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); + hashtable_insert(globals.profile_hash, (void *)profile->name, profile); + zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); + } + + if (!strcasecmp(var, "rx-gain")) { + profile->record_config.gain = 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 = atof(val); + } else if (!strcasecmp(var, "rx-agc-minGain")) { + profile->record_config.AGC.minGain = atof(val); + } else if (!strcasecmp(var, "rx-agc-maxGain")) { + profile->record_config.AGC.maxGain = 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 = 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 = 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 = 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 = 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 = atof(val); + } else if (!strcasecmp(var, "tx-agc-minGain")) { + profile->play_config.AGC.minGain = atof(val); + } else if (!strcasecmp(var, "tx-agc-maxGain")) { + profile->play_config.AGC.maxGain = 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 = atof(val); + } 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; +} + +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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + //PKH_EVENT_GetText(event->id, g_EventText, sizeof(g_EventText)); + //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + + 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; + } + +} + + +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 = 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; + } + 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)); + + if (type == ZAP_CHAN_TYPE_FXO) { + PKH_TTrunkConfig trunkConfig; + + if((status = PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_Seize(chan_data->handle) != PK_SUCCESS)) { + goto fail_fxo; + } + + if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { + goto fail_fxo; + } + + trunkConfig.internationalControl = PKH_TRUNK_NA; + trunkConfig.audioFormat = PKH_AUDIO_MULAW; + + if ((status = PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_Start(chan_data->handle)) != PK_SUCCESS) { + goto fail_fxo; + } + + goto ok; + + fail_fxo: + zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + zap_log(ZAP_LOG_ERROR, "Error: PKH_TRUNK_Open %u failed(%s)!\n", x, + PKH_ERROR_GetText(status, error_text, sizeof(error_text))); + if (chan_data->handle) { + PKH_TRUNK_Close(chan_data->handle); + } + PKH_QUEUE_Destroy(chan_data->media_in_queue); + + free(chan_data); + continue; + + } else if (type == ZAP_CHAN_TYPE_FXS) { + if((status = PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_PHONE_Seize(chan_data->handle) != PK_SUCCESS)) { + goto fail_fxs; + } + + if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_PHONE_Start(chan_data->handle)) != PK_SUCCESS) { + goto fail_fxs; + } + + goto ok; + + + fail_fxs: + zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + zap_log(ZAP_LOG_ERROR, "Error: PKH_PHONE_Open %u failed(%s)!\n", x, + PKH_ERROR_GetText(status, error_text, sizeof(error_text))); + if (chan_data->handle) { + PKH_PHONE_Close(chan_data->handle); + } + PKH_QUEUE_Destroy(chan_data->media_in_queue); + free(chan_data); + + + } + + ok: + + 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 = chan_data->record_config.bufferSize; + 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.enabled = profile->record_config.AGC.enabled; + chan_data->record_config.AGC.targetPower = profile->record_config.AGC.targetPower; + chan_data->record_config.AGC.minGain = profile->record_config.AGC.minGain; + chan_data->record_config.AGC.maxGain = profile->record_config.AGC.maxGain; + chan_data->record_config.AGC.attackRate = profile->record_config.AGC.attackRate; + chan_data->record_config.AGC.decayRate = profile->record_config.AGC.decayRate; + chan_data->record_config.AGC.speechThreshold = profile->record_config.AGC.speechThreshold; + chan_data->record_config.VAD.enabled = profile->record_config.VAD.enabled; + chan_data->record_config.VAD.activationThreshold = profile->record_config.VAD.activationThreshold; + chan_data->record_config.VAD.activationDebounceTime = profile->record_config.VAD.activationDebounceTime; + chan_data->record_config.VAD.deactivationThreshold = profile->record_config.VAD.deactivationThreshold; + chan_data->record_config.VAD.deactivationDebounceTime = profile->record_config.VAD.deactivationDebounceTime; + chan_data->record_config.VAD.preSpeechBufferSize = profile->record_config.VAD.preSpeechBufferSize; + chan_data->play_config.gain = profile->play_config.gain; + chan_data->play_config.AGC.enabled = profile->play_config.AGC.enabled; + chan_data->play_config.AGC.targetPower = profile->play_config.AGC.targetPower; + chan_data->play_config.AGC.minGain = profile->play_config.AGC.minGain; + chan_data->play_config.AGC.maxGain = profile->play_config.AGC.maxGain; + chan_data->play_config.AGC.attackRate = profile->play_config.AGC.attackRate; + chan_data->play_config.AGC.decayRate = profile->play_config.AGC.decayRate; + chan_data->play_config.AGC.speechThreshold = profile->play_config.AGC.speechThreshold; + } + + 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->mod_data = chan_data; + chan->physical_span_id = spanno; + chan->physical_chan_id = x; + + chan->rate = 8000; + chan->packet_len = 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); + + 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; +} + +static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) +{ + int items, i; + char *mydata, *item_list[10]; + char *bd, *sp, *ch, *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; +} + +static ZIO_OPEN_FUNCTION(pika_open) +{ + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + PKH_QUEUE_Flush(chan_data->media_in_queue); + PKH_PLAY_Start(chan_data->media_out); + return ZAP_SUCCESS; +} + +static ZIO_CLOSE_FUNCTION(pika_close) +{ + return ZAP_SUCCESS; +} + +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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + *flags = ZAP_NO_FLAGS; + + if (myflags & ZAP_READ) { + 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, g_EventText, sizeof(g_EventText)); + zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + } + + return ZAP_SUCCESS; +} + +static ZIO_READ_FUNCTION(pika_read) +{ + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + PK_STATUS status; + PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + if (zchan->packet_len < *datalen) { + *datalen = zchan->packet_len; + } + + if ((status = PKH_RECORD_GetData(chan_data->media_in, data, *datalen)) == PK_SUCCESS) { + return ZAP_SUCCESS; + } + + + PKH_ERROR_GetText(status, g_EventText, sizeof(g_EventText)); + zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", g_EventText); + return ZAP_FAIL; +} + +static ZIO_WRITE_FUNCTION(pika_write) +{ + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + + if (PKH_PLAY_AddData(chan_data->media_out, 0, data, *datalen) == PK_SUCCESS) { + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +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 = chan_data->record_config.bufferSize; + zchan->packet_len = 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; +} + +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; + + status = PKH_QUEUE_WaitOnEvent(span_data->event_queue, ms, &span_data->last_oob_event); + + if (status == PK_SUCCESS) { + zap_channel_t *zchan = span_data->last_oob_event.userData; + //PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + if (span_data->last_oob_event.id == PKH_EVENT_QUEUE_TIMEOUT) { + return ZAP_TIMEOUT; + } + + //PKH_EVENT_GetText(span_data->last_oob_event.id, g_EventText, sizeof(g_EventText)); + //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + + if (zchan) { + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + 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; +} + +static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) +{ + uint32_t i, event_id; + + 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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); + + PKH_EVENT_GetText(chan_data->last_oob_event.id, g_EventText, sizeof(g_EventText)); + zap_log(ZAP_LOG_DEBUG, "Event %d on channel %d:%d [%s]\n", + chan_data->last_oob_event.id, + span->channels[i].span_id, + span->channels[i].chan_id, + g_EventText); + + switch(chan_data->last_oob_event.id) { + 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_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, g_EventText); + 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; +} + +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; +} + +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 (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { + PKH_QUEUE_Detach(span_data->event_queue, chan_data->handle); + PKH_TRUNK_Close(chan_data->handle); + } + + 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); + zap_mutex_destroy(&chan_data->digit_mutex); + zap_buffer_destroy(&chan_data->digit_buffer); + zap_safe_free(chan_data); + + return ZAP_SUCCESS; +} + +static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) +{ + return ZAP_FAIL; +} + +static zap_io_interface_t pika_interface; + +zap_status_t pika_init(zap_io_interface_t **zint) +{ + + PK_STATUS status; + PK_CHAR error_text[PKH_ERROR_MAX_NAME_LENGTH]; + uint32_t i; + int ok = 0; + PKH_TLogMasks m; + + + assert(zint != NULL); + memset(&pika_interface, 0, sizeof(pika_interface)); + memset(&globals, 0, sizeof(globals)); + + 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 = 8; + PKH_SYSTEM_SetConfig(globals.system_handle, &globals.system_config); + + 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); + + 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; + *zint = &pika_interface; + + + + + memset(&m, 0, sizeof(m)); + //m.apiMask = 0xffffffff; + //PKH_LOG_SetMasks(&m); + + return ZAP_SUCCESS; +} + +zap_status_t pika_destroy(void) +{ + 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))); + } + + hashtable_destroy(globals.profile_hash, 0, 1); + + return ZAP_SUCCESS; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/zap_skel.c index 992ca264e1..575550979a 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/zap_skel.c @@ -82,6 +82,11 @@ 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; @@ -97,6 +102,11 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) return ZAP_FAIL; } +static ZIO_CHANNEL_DESTROY_FUNCTION(skel_span_destroy) +{ + return ZAP_FAIL; +} + static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) { return zap_fail; @@ -117,9 +127,11 @@ zap_status_t skel_init(zap_io_interface_t **zint) 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; *zint = &skel_interface; From 6b88eec7bfc09dba6a7a6f43b9355f4fd066d4c1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 01:39:28 +0000 Subject: [PATCH 0650/1766] pika-choo i choose you git-svn-id: http://svn.openzap.org/svn/openzap/trunk@331 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 5 +- libs/freetdm/conf/pika.conf | 33 + libs/freetdm/mod_openzap/mod_openzap.c | 60 +- libs/freetdm/src/detect_dtmf.c | 32 + libs/freetdm/src/detect_tones.c | 5 +- libs/freetdm/src/include/openzap.h | 14 +- libs/freetdm/src/include/zap_pika.h | 53 ++ libs/freetdm/src/include/zap_types.h | 75 +- libs/freetdm/src/testanalog.c | 3 +- libs/freetdm/src/testtones.c | 4 +- libs/freetdm/src/zap_analog.c | 92 ++- libs/freetdm/src/zap_io.c | 99 ++- libs/freetdm/src/zap_pika.c | 1012 ++++++++++++++++++++++++ libs/freetdm/src/zap_skel.c | 12 + 14 files changed, 1419 insertions(+), 80 deletions(-) create mode 100644 libs/freetdm/conf/pika.conf create mode 100644 libs/freetdm/src/detect_dtmf.c create mode 100644 libs/freetdm/src/include/zap_pika.h create mode 100644 libs/freetdm/src/zap_pika.c diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 32b70f0cc4..94883699c5 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -135,6 +135,9 @@ testtones: $(SRC)/testtones.c $(MYLIB) detect_tones: $(SRC)/detect_tones.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm +detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread @@ -174,6 +177,6 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf new file mode 100644 index 0000000000..1cba63b2ef --- /dev/null +++ b/libs/freetdm/conf/pika.conf @@ -0,0 +1,33 @@ +; each category is a config profile +; to apply the profile append it to a channel def in +; openzap.conf with @ +; e.g. +; [span pika] +; name => pika +; number => pika +; fxs-channel => 1:0:1-12@default + +[default] +rx-gain => 0 +rx-agc-enabled => 0 +rx-agc-targetPower => 0 +rx-agc-minGain => 0 +rx-agc-maxGain => 0 +rx-agc-attackRate => 0 +rx-agc-decayRate => 0 +rx-agc-speechThreshold => 0 +rx-vad-enabled => 0 +rx-vad-activationThreshold => 0 +rx-vad-activationDebounceTime => 0 +rx-vad-deactivationThreshold => 0 +rx-vad-deactivationDebounceTime => 0 +rx-vad-preSpeechBufferSize => 0 +tx-gain => 0 +tx-agc-enabled => 0 +tx-agc-targetPower => 0 +tx-agc-minGain => 0 +tx-agc-maxGain => 0 +tx-agc-attackRate => 0 +tx-agc-decayRate => 0 +tx-agc-speechThreshold => 0 + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index fc63935a6c..a712b500f3 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -304,14 +304,14 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); - } + + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + } break; case ZAP_CHAN_TYPE_FXS: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_BUSY && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { if (tech_pvt->zchan->token_count) { cycle_foreground(tech_pvt->zchan, 0); } else { @@ -466,20 +466,21 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (!switch_test_flag(tech_pvt, TFLAG_IO)) { - return SWITCH_STATUS_FALSE; + goto fail; } + wflags = ZAP_READ; status = zap_channel_wait(tech_pvt->zchan, &wflags, chunk); - + if (status == ZAP_FAIL) { - return SWITCH_STATUS_GENERR; + goto fail; } if (status == ZAP_TIMEOUT) { if (timeout > 0 && !switch_test_flag(tech_pvt, TFLAG_HOLD)) { total_to -= chunk; if (total_to <= 0) { - return SWITCH_STATUS_BREAK; + goto fail; } } @@ -487,12 +488,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (!(wflags & ZAP_READ)) { - return SWITCH_STATUS_GENERR; + goto fail; } len = tech_pvt->read_frame.buflen; if (zap_channel_read(tech_pvt->zchan, tech_pvt->read_frame.data, &len) != ZAP_SUCCESS) { - return SWITCH_STATUS_GENERR; + goto fail; } *frame = &tech_pvt->read_frame; @@ -509,6 +510,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_SUCCESS; + fail: + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + return SWITCH_STATUS_GENERR; + + } static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) @@ -530,13 +537,13 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } if (!switch_test_flag(tech_pvt, TFLAG_IO)) { - return SWITCH_STATUS_FALSE; + goto fail; } len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { - return SWITCH_STATUS_GENERR; + goto fail; } } else { tech_pvt->wr_error = 0; @@ -544,6 +551,11 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc return SWITCH_STATUS_SUCCESS; + fail: + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + return SWITCH_STATUS_GENERR; + } static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) @@ -833,7 +845,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->chan_number); } } - + tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), "OpenZAP", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, @@ -875,9 +887,29 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) switch_channel_t *channel = NULL; zap_status_t status; - zap_log(ZAP_LOG_DEBUG, "got FXO sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got FXO 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_PROGRESS_MEDIA: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_pre_answered(channel); + switch_core_session_rwunlock(session); + } + } + break; + case ZAP_SIGEVENT_STOP: + { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_channel_clear_token(sigmsg->channel, 0); + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { diff --git a/libs/freetdm/src/detect_dtmf.c b/libs/freetdm/src/detect_dtmf.c new file mode 100644 index 0000000000..941237b464 --- /dev/null +++ b/libs/freetdm/src/detect_dtmf.c @@ -0,0 +1,32 @@ +//#include "openzap.h" +#include "libteletone_detect.h" + +int main(int argc, char *argv[]) +{ + int fd, b; + short sln[512] = {0}; + teletone_dtmf_detect_state_t dtmf_detect = {0}; + char digit_str[128] = ""; + + if (argc < 2) { + fprintf(stderr, "Arg Error!\n"); + exit(-1); + } + + teletone_dtmf_detect_init (&dtmf_detect, 8000); + + if ((fd = open(argv[1], O_RDONLY)) < 0) { + fprintf(stderr, "File Error!\n", strerror(errno)); + exit(-1); + } + + while((b = read(fd, sln, 320)) > 0) { + teletone_dtmf_detect(&dtmf_detect, sln, b / 2); + teletone_dtmf_get(&dtmf_detect, digit_str, sizeof(digit_str)); + if (*digit_str) { + printf("digit: %s\n", digit_str); + } + } + close(fd); +} + diff --git a/libs/freetdm/src/detect_tones.c b/libs/freetdm/src/detect_tones.c index 52ccbcd506..c5d475edc3 100644 --- a/libs/freetdm/src/detect_tones.c +++ b/libs/freetdm/src/detect_tones.c @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) { teletone_generation_session_t ts; teletone_multi_tone_t mt = {0}; - teletone_tone_map_t map = {350.0, 440.0, 0.0}; + teletone_tone_map_t map = {0}; int fd, b; short sln[512] = {0}; @@ -15,6 +15,9 @@ int main(int argc, char *argv[]) exit(-1); } + + map.freqs[0] = atof("350"); + map.freqs[1] = atof("440"); teletone_multi_tone_init(&mt, &map); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 12bc936a75..c57ef1c5f3 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -211,12 +211,12 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state from %s to %s\n", zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%dfrom %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s); \ - if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ - else zap_log(ZAP_LOG_WARNING, "VETO Changing state from %s to %s\n", zap_channel_state2str(st), zap_channel_state2str(s)); \ + if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ + else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } @@ -344,7 +344,6 @@ struct zap_channel { zap_event_t event_header; char last_error[256]; zio_event_cb_t event_callback; - void *mod_data; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; zap_buffer_t *digit_buffer; @@ -365,6 +364,7 @@ struct zap_channel { zap_fsk_data_state_t fsk; uint8_t fsk_buf[80]; uint32_t ring_count; + void *mod_data; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -416,7 +416,8 @@ struct zap_span { teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; zio_channel_outgoing_call_t outgoing_call; - void *app_data; + void *mod_data; + char *type; }; @@ -429,6 +430,7 @@ struct zap_io_interface { zio_open_t open; zio_close_t close; zio_channel_destroy_t channel_destroy; + zio_span_destroy_t span_destroy; zio_get_alarms_t get_alarms; zio_command_t command; zio_wait_t wait; @@ -505,6 +507,8 @@ void zap_global_set_default_logger(int level); uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); +int zap_hash_equalkeys(void *k1, void *k2); +uint32_t zap_hash_hashfromstring(void *ky); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/include/zap_pika.h b/libs/freetdm/src/include/zap_pika.h new file mode 100644 index 0000000000..6d1c68f5f6 --- /dev/null +++ b/libs/freetdm/src/include/zap_pika.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_PIKA_H +#define ZAP_PIKA_H +#include "openzap.h" +#include "pikahmpapi.h" +/* Openzap PIKA hardware interface functions */ +zap_status_t pika_init(zap_io_interface_t **zint); +zap_status_t pika_destroy(void); + +#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 expandtab: + */ diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 4055b0c931..e05f219f25 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -267,10 +267,11 @@ typedef enum { } zap_chan_type_t; typedef enum { - ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), - ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), - ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2), - ZAP_CHANNEL_FEATURE_CALLERID = (1 << 3) + 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_t; typedef enum { @@ -339,6 +340,7 @@ typedef struct zap_span zap_span_t; #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) @@ -356,6 +358,7 @@ 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 ; @@ -373,6 +376,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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 @@ -410,6 +414,69 @@ typedef struct value zap_hash_val_t; typedef struct zap_bitstream zap_bitstream_t; typedef struct zap_fsk_modulator zap_fsk_modulator_t; +typedef enum { + ZAP_CAUSE_UNALLOCATED = 0, + ZAP_CAUSE_SUCCESS = 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_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: diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index dc90861834..1ad530db89 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -14,7 +14,8 @@ static void *test_call(zap_thread_t *me, void *obj) 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, "5551212"); + while (chan->state == ZAP_CHANNEL_STATE_UP) { zap_wait_flag_t flags = ZAP_READ; diff --git a/libs/freetdm/src/testtones.c b/libs/freetdm/src/testtones.c index b041095b76..d6b3a68552 100644 --- a/libs/freetdm/src/testtones.c +++ b/libs/freetdm/src/testtones.c @@ -20,8 +20,8 @@ int main(int argc, char *argv[]) teletone_generation_session_t ts; struct ttmp tmp; - if (argc < 2) { - fprintf(stderr, "Arg Error!\n"); + if (argc < 3) { + fprintf(stderr, "Arg Error! \n"); exit(-1); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 23a9054dd0..bc02794acd 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -44,7 +44,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + zap_channel_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_clear_needed_tones(zchan); zap_channel_clear_detected_tones(zchan); @@ -281,13 +282,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { - if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } @@ -346,7 +348,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); indicate = 0; state_counter = 0; - zap_log(ZAP_LOG_DEBUG, "Executing state handler for %s\n", zap_channel_state2str(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)); switch(zchan->state) { case ZAP_CHANNEL_STATE_UP: { @@ -399,9 +403,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(zchan); sig.event_id = ZAP_SIGEVENT_STOP; analog_data->sig_cb(&sig); + zap_channel_done(zchan); goto done; } break; @@ -453,18 +457,27 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_BUSY: { - zap_channel_done(zchan); - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); - indicate = 1; + 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_channel_done(zchan); + 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: { - zap_channel_done(zchan); - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); - indicate = 1; + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_channel_done(zchan); + 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: @@ -514,25 +527,42 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { if (zchan->detected_tones[i]) { - zap_log(ZAP_LOG_DEBUG, "Detected tone %s\n", zap_tonemap2str(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; - analog_data->sig_cb(&sig); + if (analog_data->sig_cb) { + analog_data->sig_cb(&sig); + } } } - if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) { - zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani); - 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) + 50; + 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)) { + 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) != 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)) + 3000; + } + } } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } else if (zchan->detected_tones[ZAP_TONEMAP_BUSY]) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } zap_channel_clear_detected_tones(zchan); @@ -580,6 +610,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } done: + zap_channel_done(zchan); @@ -647,7 +678,10 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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_DOWN); + + if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); + } } break; case ZAP_OOB_FLASH: diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2030e5ecc5..30a9771beb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -47,6 +47,9 @@ #ifdef ZAP_ZT_SUPPORT #include "zap_zt.h" #endif +#ifdef ZAP_PIKA_SUPPORT +#include "zap_pika.h" +#endif static int time_is_init = 0; @@ -192,12 +195,12 @@ void zap_global_set_default_logger(int level) zap_log_level = level; } -static int equalkeys(void *k1, void *k2) +int zap_hash_equalkeys(void *k1, void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -static uint32_t hashfromstring(void *ky) +uint32_t zap_hash_hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; uint32_t hash = 0; @@ -211,6 +214,19 @@ static uint32_t hashfromstring(void *ky) } +static zap_status_t zap_span_destroy(zap_span_t *span) +{ + zap_status_t status = ZAP_FAIL; + + if (zap_test_flag(span, ZAP_SPAN_CONFIGURED) && span->zio && span->zio->span_destroy) { + zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); + status = span->zio->span_destroy(span); + zap_safe_free(span->type); + } + + return status; +} + static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { @@ -227,7 +243,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) if (zchan->span->zio->channel_destroy) { - zap_log(ZAP_LOG_INFO, "Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); + zap_log(ZAP_LOG_INFO, "Closing channel %s:%u:%u fd:%d\n", zchan->span->type, zchan->span_id, zchan->chan_id, zchan->sockfd); if (zchan->span->zio->channel_destroy(zchan) == ZAP_SUCCESS) { zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); } else { @@ -315,14 +331,13 @@ zap_status_t zap_span_close_all(void) uint32_t i, j; zap_mutex_lock(globals.mutex); - for(i = 0; i < globals.span_index; i++) { + for(i = 1; i <= globals.span_index; i++) { span = &globals.spans[i]; - - for(j = 0; j < span->chan_count; j++) { - zap_channel_destroy(&span->channels[i]); - } - - zap_safe_free(span->signal_data); + if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + for(j = 0; j < span->chan_count; j++) { + zap_channel_destroy(&span->channels[i]); + } + } } zap_mutex_unlock(globals.mutex); @@ -938,6 +953,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); } } + if (!zchan->tone_session.buffer) { memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); @@ -947,6 +963,8 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) zchan->tone_session.rate = zchan->rate; zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); + zchan->tone_session.volume = -7; + /* zchan->tone_session.debug = 1; zchan->tone_session.debug_stream = stdout; @@ -1083,6 +1101,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: { /* if they don't have thier own, use ours */ + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); @@ -1101,7 +1121,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_ENABLE_DTMF_DETECT: { /* if they don't have thier own, use ours */ - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); @@ -1117,7 +1137,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_DISABLE_DTMF_DETECT: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; if (tt == ZAP_TONE_DTMF) { teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); @@ -1132,7 +1152,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } case ZAP_COMMAND_GET_DTMF_ON_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1140,7 +1160,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_GET_DTMF_OFF_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1148,7 +1168,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_SET_DTMF_ON_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_on = val; @@ -1162,7 +1182,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_SET_DTMF_OFF_PERIOD: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { int val = ZAP_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { zchan->dtmf_off = val; @@ -1176,7 +1196,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_SEND_DTMF: { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF)) { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; int x = 0; @@ -1523,7 +1543,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data *(str+mlen) = '\0'; zap_copy_string(str, sp, ++mlen); zap_clean_string(str); - zap_log(ZAP_LOG_ERROR, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); + zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); switch(type) { case MDMF_DDN: @@ -1570,13 +1590,14 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { uint32_t i; - + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { if (zchan->span->tone_finder[i].tone_count) { if (zchan->needed_tones[i] && teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen)) { - zchan->detected_tones[i] = 1; - zchan->needed_tones[i] = 0; - zchan->detected_tones[0]++; + if (++zchan->detected_tones[i]) { + zchan->needed_tones[i] = 0; + zchan->detected_tones[0]++; + } } } } @@ -1713,6 +1734,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data static struct { zap_io_interface_t *wanpipe_interface; zap_io_interface_t *zt_interface; + zap_io_interface_t *pika_interface; } interfaces; @@ -1760,7 +1782,14 @@ static zap_status_t load_config(void) continue; } + if (!zio->configure_span) { + zap_log(ZAP_LOG_CRIT, "failure creating span, no configure_span method for '%s'\n", type); + span = NULL; + continue; + } + if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + span->type = strdup(type); zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); d = 0; } else { @@ -1886,7 +1915,7 @@ zap_status_t zap_global_init(void) zap_isdn_init(); memset(&interfaces, 0, sizeof(interfaces)); - globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys); + globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); @@ -1914,6 +1943,19 @@ zap_status_t zap_global_init(void) } #endif +#ifdef ZAP_PIKA_SUPPORT + if (pika_init(&interfaces.pika_interface) == ZAP_SUCCESS) { + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interfaces.pika_interface->name, interfaces.pika_interface); + process_module_config(interfaces.pika_interface); + zap_mutex_unlock(globals.mutex); + modcount++; + } else { + zap_log(ZAP_LOG_ERROR, "Error initilizing pika.\n"); + } +#endif + + if (!modcount) { zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); return ZAP_FAIL; @@ -1953,6 +1995,10 @@ zap_status_t zap_global_destroy(void) if (cur_span->mutex) { zap_mutex_destroy(&cur_span->mutex); } + + zap_safe_free(cur_span->signal_data); + zap_span_destroy(cur_span); + } } @@ -1962,6 +2008,13 @@ zap_status_t zap_global_destroy(void) zt_destroy(); } #endif + +#ifdef ZAP_PIKA_SUPPORT + if (interfaces.pika_interface) { + pika_destroy(); + } +#endif + #ifdef ZAP_WANPIPE_SUPPORT if (interfaces.wanpipe_interface) { wanpipe_destroy(); diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c new file mode 100644 index 0000000000..48be6f7a3f --- /dev/null +++ b/libs/freetdm/src/zap_pika.c @@ -0,0 +1,1012 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "openzap.h" +#include "zap_pika.h" +#define MAX_NUMBER_OF_TRUNKS 64 +#define PIKA_BLOCK_SIZE 160 +#define PIKA_BLOCK_LEN 20 + +struct pika_channel_profile { + char name[80]; + PKH_TRecordConfig record_config; + PKH_TPlayConfig play_config; +}; +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; + zap_hash_t *profile_hash; +} globals; + + +struct pika_span_data { + TPikaHandle event_queue; + PKH_TPikaEvent last_oob_event; + uint32_t boardno; +}; +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; + zap_buffer_t *digit_buffer; + zap_mutex_t *digit_mutex; + int dtmf_len; +}; +typedef struct pika_chan_data pika_chan_data_t; + +static 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"; +} + +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); + hashtable_insert(globals.profile_hash, (void *)profile->name, profile); + zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); + } + + if (!strcasecmp(var, "rx-gain")) { + profile->record_config.gain = 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 = atof(val); + } else if (!strcasecmp(var, "rx-agc-minGain")) { + profile->record_config.AGC.minGain = atof(val); + } else if (!strcasecmp(var, "rx-agc-maxGain")) { + profile->record_config.AGC.maxGain = 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 = 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 = 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 = 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 = 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 = atof(val); + } else if (!strcasecmp(var, "tx-agc-minGain")) { + profile->play_config.AGC.minGain = atof(val); + } else if (!strcasecmp(var, "tx-agc-maxGain")) { + profile->play_config.AGC.maxGain = 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 = atof(val); + } 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; +} + +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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + //PKH_EVENT_GetText(event->id, g_EventText, sizeof(g_EventText)); + //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + + 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; + } + +} + + +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 = 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; + } + 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)); + + if (type == ZAP_CHAN_TYPE_FXO) { + PKH_TTrunkConfig trunkConfig; + + if((status = PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_Seize(chan_data->handle) != PK_SUCCESS)) { + goto fail_fxo; + } + + if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { + goto fail_fxo; + } + + trunkConfig.internationalControl = PKH_TRUNK_NA; + trunkConfig.audioFormat = PKH_AUDIO_MULAW; + + if ((status = PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxo; + } + + if ((status = PKH_TRUNK_Start(chan_data->handle)) != PK_SUCCESS) { + goto fail_fxo; + } + + goto ok; + + fail_fxo: + zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + zap_log(ZAP_LOG_ERROR, "Error: PKH_TRUNK_Open %u failed(%s)!\n", x, + PKH_ERROR_GetText(status, error_text, sizeof(error_text))); + if (chan_data->handle) { + PKH_TRUNK_Close(chan_data->handle); + } + PKH_QUEUE_Destroy(chan_data->media_in_queue); + + free(chan_data); + continue; + + } else if (type == ZAP_CHAN_TYPE_FXS) { + if((status = PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_PHONE_Seize(chan_data->handle) != PK_SUCCESS)) { + goto fail_fxs; + } + + if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { + goto fail_fxs; + } + + if ((status = PKH_PHONE_Start(chan_data->handle)) != PK_SUCCESS) { + goto fail_fxs; + } + + goto ok; + + + fail_fxs: + zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + zap_log(ZAP_LOG_ERROR, "Error: PKH_PHONE_Open %u failed(%s)!\n", x, + PKH_ERROR_GetText(status, error_text, sizeof(error_text))); + if (chan_data->handle) { + PKH_PHONE_Close(chan_data->handle); + } + PKH_QUEUE_Destroy(chan_data->media_in_queue); + free(chan_data); + + + } + + ok: + + 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 = chan_data->record_config.bufferSize; + 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.enabled = profile->record_config.AGC.enabled; + chan_data->record_config.AGC.targetPower = profile->record_config.AGC.targetPower; + chan_data->record_config.AGC.minGain = profile->record_config.AGC.minGain; + chan_data->record_config.AGC.maxGain = profile->record_config.AGC.maxGain; + chan_data->record_config.AGC.attackRate = profile->record_config.AGC.attackRate; + chan_data->record_config.AGC.decayRate = profile->record_config.AGC.decayRate; + chan_data->record_config.AGC.speechThreshold = profile->record_config.AGC.speechThreshold; + chan_data->record_config.VAD.enabled = profile->record_config.VAD.enabled; + chan_data->record_config.VAD.activationThreshold = profile->record_config.VAD.activationThreshold; + chan_data->record_config.VAD.activationDebounceTime = profile->record_config.VAD.activationDebounceTime; + chan_data->record_config.VAD.deactivationThreshold = profile->record_config.VAD.deactivationThreshold; + chan_data->record_config.VAD.deactivationDebounceTime = profile->record_config.VAD.deactivationDebounceTime; + chan_data->record_config.VAD.preSpeechBufferSize = profile->record_config.VAD.preSpeechBufferSize; + chan_data->play_config.gain = profile->play_config.gain; + chan_data->play_config.AGC.enabled = profile->play_config.AGC.enabled; + chan_data->play_config.AGC.targetPower = profile->play_config.AGC.targetPower; + chan_data->play_config.AGC.minGain = profile->play_config.AGC.minGain; + chan_data->play_config.AGC.maxGain = profile->play_config.AGC.maxGain; + chan_data->play_config.AGC.attackRate = profile->play_config.AGC.attackRate; + chan_data->play_config.AGC.decayRate = profile->play_config.AGC.decayRate; + chan_data->play_config.AGC.speechThreshold = profile->play_config.AGC.speechThreshold; + } + + 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->mod_data = chan_data; + chan->physical_span_id = spanno; + chan->physical_chan_id = x; + + chan->rate = 8000; + chan->packet_len = 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); + + 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; +} + +static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) +{ + int items, i; + char *mydata, *item_list[10]; + char *bd, *sp, *ch, *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; +} + +static ZIO_OPEN_FUNCTION(pika_open) +{ + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + PKH_QUEUE_Flush(chan_data->media_in_queue); + PKH_PLAY_Start(chan_data->media_out); + return ZAP_SUCCESS; +} + +static ZIO_CLOSE_FUNCTION(pika_close) +{ + return ZAP_SUCCESS; +} + +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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + *flags = ZAP_NO_FLAGS; + + if (myflags & ZAP_READ) { + 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, g_EventText, sizeof(g_EventText)); + zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + } + + return ZAP_SUCCESS; +} + +static ZIO_READ_FUNCTION(pika_read) +{ + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + PK_STATUS status; + PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + if (zchan->packet_len < *datalen) { + *datalen = zchan->packet_len; + } + + if ((status = PKH_RECORD_GetData(chan_data->media_in, data, *datalen)) == PK_SUCCESS) { + return ZAP_SUCCESS; + } + + + PKH_ERROR_GetText(status, g_EventText, sizeof(g_EventText)); + zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", g_EventText); + return ZAP_FAIL; +} + +static ZIO_WRITE_FUNCTION(pika_write) +{ + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + + if (PKH_PLAY_AddData(chan_data->media_out, 0, data, *datalen) == PK_SUCCESS) { + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +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 = chan_data->record_config.bufferSize; + zchan->packet_len = 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; +} + +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; + + status = PKH_QUEUE_WaitOnEvent(span_data->event_queue, ms, &span_data->last_oob_event); + + if (status == PK_SUCCESS) { + zap_channel_t *zchan = span_data->last_oob_event.userData; + //PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + if (span_data->last_oob_event.id == PKH_EVENT_QUEUE_TIMEOUT) { + return ZAP_TIMEOUT; + } + + //PKH_EVENT_GetText(span_data->last_oob_event.id, g_EventText, sizeof(g_EventText)); + //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + + if (zchan) { + pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + 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; +} + +static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) +{ + uint32_t i, event_id; + + 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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + + zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); + + PKH_EVENT_GetText(chan_data->last_oob_event.id, g_EventText, sizeof(g_EventText)); + zap_log(ZAP_LOG_DEBUG, "Event %d on channel %d:%d [%s]\n", + chan_data->last_oob_event.id, + span->channels[i].span_id, + span->channels[i].chan_id, + g_EventText); + + switch(chan_data->last_oob_event.id) { + 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_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, g_EventText); + 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; +} + +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; +} + +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 (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { + PKH_QUEUE_Detach(span_data->event_queue, chan_data->handle); + PKH_TRUNK_Close(chan_data->handle); + } + + 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); + zap_mutex_destroy(&chan_data->digit_mutex); + zap_buffer_destroy(&chan_data->digit_buffer); + zap_safe_free(chan_data); + + return ZAP_SUCCESS; +} + +static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) +{ + return ZAP_FAIL; +} + +static zap_io_interface_t pika_interface; + +zap_status_t pika_init(zap_io_interface_t **zint) +{ + + PK_STATUS status; + PK_CHAR error_text[PKH_ERROR_MAX_NAME_LENGTH]; + uint32_t i; + int ok = 0; + PKH_TLogMasks m; + + + assert(zint != NULL); + memset(&pika_interface, 0, sizeof(pika_interface)); + memset(&globals, 0, sizeof(globals)); + + 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 = 8; + PKH_SYSTEM_SetConfig(globals.system_handle, &globals.system_config); + + 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); + + 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; + *zint = &pika_interface; + + + + + memset(&m, 0, sizeof(m)); + //m.apiMask = 0xffffffff; + //PKH_LOG_SetMasks(&m); + + return ZAP_SUCCESS; +} + +zap_status_t pika_destroy(void) +{ + 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))); + } + + hashtable_destroy(globals.profile_hash, 0, 1); + + return ZAP_SUCCESS; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/zap_skel.c index 992ca264e1..575550979a 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/zap_skel.c @@ -82,6 +82,11 @@ 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; @@ -97,6 +102,11 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) return ZAP_FAIL; } +static ZIO_CHANNEL_DESTROY_FUNCTION(skel_span_destroy) +{ + return ZAP_FAIL; +} + static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) { return zap_fail; @@ -117,9 +127,11 @@ zap_status_t skel_init(zap_io_interface_t **zint) 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; *zint = &skel_interface; From ffe8247552965762ac075e29bd2897bec90dbc86 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 01:42:45 +0000 Subject: [PATCH 0651/1766] merge in sep str changes from big brother git-svn-id: http://svn.openzap.org/svn/openzap/trunk@332 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 30a9771beb..64b415adfb 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2034,8 +2034,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) int argc; char *ptr; int quot = 0; - char qc = '"'; - char *e; + char qc = '\''; int x; if (!buf || !array || !arraylen) { @@ -2066,13 +2065,21 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) array[argc++] = ptr; } - /* strip quotes */ + /* strip quotes and leading / trailing spaces */ for (x = 0; x < argc; x++) { - if (*(array[x]) == qc) { + char *p; + + while(*(array[x]) == ' ') { (array[x])++; - if ((e = strchr(array[x], qc))) { - *e = '\0'; - } + } + p = array[x]; + while((p = strchr(array[x], qc))) { + memmove(p, p+1, strlen(p)); + p++; + } + p = array[x] + (strlen(array[x]) - 1); + while(*p == ' ') { + *p-- = '\0'; } } From 60191d9c84d453acef38d6c6d170c96907ffadf0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 01:42:45 +0000 Subject: [PATCH 0652/1766] merge in sep str changes from big brother git-svn-id: http://svn.openzap.org/svn/openzap/trunk@332 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 30a9771beb..64b415adfb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2034,8 +2034,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) int argc; char *ptr; int quot = 0; - char qc = '"'; - char *e; + char qc = '\''; int x; if (!buf || !array || !arraylen) { @@ -2066,13 +2065,21 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) array[argc++] = ptr; } - /* strip quotes */ + /* strip quotes and leading / trailing spaces */ for (x = 0; x < argc; x++) { - if (*(array[x]) == qc) { + char *p; + + while(*(array[x]) == ' ') { (array[x])++; - if ((e = strchr(array[x], qc))) { - *e = '\0'; - } + } + p = array[x]; + while((p = strchr(array[x], qc))) { + memmove(p, p+1, strlen(p)); + p++; + } + p = array[x] + (strlen(array[x]) - 1); + while(*p == ' ') { + *p-- = '\0'; } } From df1b623c5ee3fcd5e364a816b036bfbd8e723cf0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 17 Nov 2007 03:45:54 +0000 Subject: [PATCH 0653/1766] windows build initial attempts. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@333 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 28 ++++++++++++++++++++++++++++ libs/openzap/src/zap_pika.c | 26 +++++++++++++------------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index c8d612a40f..a4cf1d6ea4 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -299,6 +299,10 @@ RelativePath="..\src\include\sangoma_tdm_api.h" > + + @@ -315,6 +319,30 @@ + + + + + + + + diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 48be6f7a3f..d2984d6cdd 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -73,7 +73,7 @@ struct pika_chan_data { PKH_TPlayConfig play_config; zap_buffer_t *digit_buffer; zap_mutex_t *digit_mutex; - int dtmf_len; + zap_size_t dtmf_len; }; typedef struct pika_chan_data pika_chan_data_t; @@ -104,49 +104,49 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } if (!strcasecmp(var, "rx-gain")) { - profile->record_config.gain = atof(val); + profile->record_config.gain = (PK_FLOAT)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 = atof(val); + profile->record_config.AGC.targetPower = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "rx-agc-minGain")) { - profile->record_config.AGC.minGain = atof(val); + profile->record_config.AGC.minGain = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "rx-agc-maxGain")) { - profile->record_config.AGC.maxGain = atof(val); + profile->record_config.AGC.maxGain = (PK_FLOAT)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 = atof(val); + profile->record_config.AGC.speechThreshold = (PK_FLOAT)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 = atof(val); + profile->record_config.VAD.activationThreshold = (PK_FLOAT)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 = atof(val); + profile->record_config.VAD.deactivationThreshold = (PK_FLOAT)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 = atof(val); + profile->play_config.gain = (PK_FLOAT)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 = atof(val); + profile->play_config.AGC.targetPower = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "tx-agc-minGain")) { - profile->play_config.AGC.minGain = atof(val); + profile->play_config.AGC.minGain = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "tx-agc-maxGain")) { - profile->play_config.AGC.maxGain = atof(val); + profile->play_config.AGC.maxGain = (PK_FLOAT)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 = atof(val); + profile->play_config.AGC.speechThreshold = (PK_FLOAT)atof(val); } else { ok = 0; } From 233ecfc43b9ede314294161e4aecf21560312809 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 17 Nov 2007 03:45:54 +0000 Subject: [PATCH 0654/1766] windows build initial attempts. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@333 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 28 ++++++++++++++++++++++++++++ libs/freetdm/src/zap_pika.c | 26 +++++++++++++------------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index c8d612a40f..a4cf1d6ea4 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -299,6 +299,10 @@ RelativePath="..\src\include\sangoma_tdm_api.h" > + + @@ -315,6 +319,30 @@ + + + + + + + + diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 48be6f7a3f..d2984d6cdd 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -73,7 +73,7 @@ struct pika_chan_data { PKH_TPlayConfig play_config; zap_buffer_t *digit_buffer; zap_mutex_t *digit_mutex; - int dtmf_len; + zap_size_t dtmf_len; }; typedef struct pika_chan_data pika_chan_data_t; @@ -104,49 +104,49 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } if (!strcasecmp(var, "rx-gain")) { - profile->record_config.gain = atof(val); + profile->record_config.gain = (PK_FLOAT)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 = atof(val); + profile->record_config.AGC.targetPower = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "rx-agc-minGain")) { - profile->record_config.AGC.minGain = atof(val); + profile->record_config.AGC.minGain = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "rx-agc-maxGain")) { - profile->record_config.AGC.maxGain = atof(val); + profile->record_config.AGC.maxGain = (PK_FLOAT)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 = atof(val); + profile->record_config.AGC.speechThreshold = (PK_FLOAT)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 = atof(val); + profile->record_config.VAD.activationThreshold = (PK_FLOAT)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 = atof(val); + profile->record_config.VAD.deactivationThreshold = (PK_FLOAT)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 = atof(val); + profile->play_config.gain = (PK_FLOAT)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 = atof(val); + profile->play_config.AGC.targetPower = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "tx-agc-minGain")) { - profile->play_config.AGC.minGain = atof(val); + profile->play_config.AGC.minGain = (PK_FLOAT)atof(val); } else if (!strcasecmp(var, "tx-agc-maxGain")) { - profile->play_config.AGC.maxGain = atof(val); + profile->play_config.AGC.maxGain = (PK_FLOAT)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 = atof(val); + profile->play_config.AGC.speechThreshold = (PK_FLOAT)atof(val); } else { ok = 0; } From 2e874998b47d9a97d79541d3af0b6da53752129d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 19:33:34 +0000 Subject: [PATCH 0655/1766] add ec params git-svn-id: http://svn.openzap.org/svn/openzap/trunk@334 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/pika.conf | 8 ++++++- libs/openzap/src/zap_pika.c | 48 ++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf index 1cba63b2ef..86b0897361 100644 --- a/libs/openzap/conf/pika.conf +++ b/libs/openzap/conf/pika.conf @@ -30,4 +30,10 @@ tx-agc-maxGain => 0 tx-agc-attackRate => 0 tx-agc-decayRate => 0 tx-agc-speechThreshold => 0 - +ec-enabled => 0 +ec-doubleTalkerThreshold => 0 +ec-speechPresentThreshold => 0 +ec-echoSuppressionThreshold => 0 +ec-echoSuppressionEnabled => 0 +ec-comfortNoiseEnabled => 0 +ec-adaptationModeEnabled => 0 diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index d2984d6cdd..72d6b2f47d 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -42,6 +42,8 @@ struct pika_channel_profile { char name[80]; PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; + int ec_enabled; + PKH_TECConfig ec_config; }; typedef struct pika_channel_profile pika_channel_profile_t; @@ -71,6 +73,8 @@ struct pika_chan_data { PKH_TPikaEvent last_oob_event; PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; + int ec_enabled; + PKH_TECConfig ec_config; zap_buffer_t *digit_buffer; zap_mutex_t *digit_mutex; zap_size_t dtmf_len; @@ -147,6 +151,20 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) profile->play_config.AGC.decayRate = atoi(val); } else if (!strcasecmp(var, "tx-agc-speechThreshold")) { profile->play_config.AGC.speechThreshold = (PK_FLOAT)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_FLOAT)atof(val); + } else if (!strcasecmp(var, "ec-speechPresentThreshold")) { + profile->ec_config.speechPresentThreshold = (PK_FLOAT)atof(val); + } else if (!strcasecmp(var, "ec-echoSuppressionThreshold")) { + profile->ec_config.echoSuppressionThreshold = (PK_FLOAT)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 { ok = 0; } @@ -415,27 +433,12 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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.enabled = profile->record_config.AGC.enabled; - chan_data->record_config.AGC.targetPower = profile->record_config.AGC.targetPower; - chan_data->record_config.AGC.minGain = profile->record_config.AGC.minGain; - chan_data->record_config.AGC.maxGain = profile->record_config.AGC.maxGain; - chan_data->record_config.AGC.attackRate = profile->record_config.AGC.attackRate; - chan_data->record_config.AGC.decayRate = profile->record_config.AGC.decayRate; - chan_data->record_config.AGC.speechThreshold = profile->record_config.AGC.speechThreshold; - chan_data->record_config.VAD.enabled = profile->record_config.VAD.enabled; - chan_data->record_config.VAD.activationThreshold = profile->record_config.VAD.activationThreshold; - chan_data->record_config.VAD.activationDebounceTime = profile->record_config.VAD.activationDebounceTime; - chan_data->record_config.VAD.deactivationThreshold = profile->record_config.VAD.deactivationThreshold; - chan_data->record_config.VAD.deactivationDebounceTime = profile->record_config.VAD.deactivationDebounceTime; - chan_data->record_config.VAD.preSpeechBufferSize = profile->record_config.VAD.preSpeechBufferSize; + 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.enabled = profile->play_config.AGC.enabled; - chan_data->play_config.AGC.targetPower = profile->play_config.AGC.targetPower; - chan_data->play_config.AGC.minGain = profile->play_config.AGC.minGain; - chan_data->play_config.AGC.maxGain = profile->play_config.AGC.maxGain; - chan_data->play_config.AGC.attackRate = profile->play_config.AGC.attackRate; - chan_data->play_config.AGC.decayRate = profile->play_config.AGC.decayRate; - chan_data->play_config.AGC.speechThreshold = profile->play_config.AGC.speechThreshold; + chan_data->play_config.AGC = profile->play_config.AGC; + chan_data->ec_enabled = profile->ec_enabled; + chan_data->ec_config = profile->ec_config; } status = PKH_RECORD_SetConfig(chan_data->media_in, &chan_data->record_config); @@ -452,8 +455,9 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa PKH_RECORD_Start(chan_data->media_in); PKH_PLAY_Start(chan_data->media_out); - - PKH_EC_Start(chan_data->media_in, chan_data->media_in, chan_data->media_out); + if (chan_data->ec_enabled) { + 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)); From 185c25a5b5d67e19f53b52183bb3966fc9ed5b69 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 19:33:34 +0000 Subject: [PATCH 0656/1766] add ec params git-svn-id: http://svn.openzap.org/svn/openzap/trunk@334 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/pika.conf | 8 ++++++- libs/freetdm/src/zap_pika.c | 48 ++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index 1cba63b2ef..86b0897361 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -30,4 +30,10 @@ tx-agc-maxGain => 0 tx-agc-attackRate => 0 tx-agc-decayRate => 0 tx-agc-speechThreshold => 0 - +ec-enabled => 0 +ec-doubleTalkerThreshold => 0 +ec-speechPresentThreshold => 0 +ec-echoSuppressionThreshold => 0 +ec-echoSuppressionEnabled => 0 +ec-comfortNoiseEnabled => 0 +ec-adaptationModeEnabled => 0 diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index d2984d6cdd..72d6b2f47d 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -42,6 +42,8 @@ struct pika_channel_profile { char name[80]; PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; + int ec_enabled; + PKH_TECConfig ec_config; }; typedef struct pika_channel_profile pika_channel_profile_t; @@ -71,6 +73,8 @@ struct pika_chan_data { PKH_TPikaEvent last_oob_event; PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; + int ec_enabled; + PKH_TECConfig ec_config; zap_buffer_t *digit_buffer; zap_mutex_t *digit_mutex; zap_size_t dtmf_len; @@ -147,6 +151,20 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) profile->play_config.AGC.decayRate = atoi(val); } else if (!strcasecmp(var, "tx-agc-speechThreshold")) { profile->play_config.AGC.speechThreshold = (PK_FLOAT)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_FLOAT)atof(val); + } else if (!strcasecmp(var, "ec-speechPresentThreshold")) { + profile->ec_config.speechPresentThreshold = (PK_FLOAT)atof(val); + } else if (!strcasecmp(var, "ec-echoSuppressionThreshold")) { + profile->ec_config.echoSuppressionThreshold = (PK_FLOAT)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 { ok = 0; } @@ -415,27 +433,12 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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.enabled = profile->record_config.AGC.enabled; - chan_data->record_config.AGC.targetPower = profile->record_config.AGC.targetPower; - chan_data->record_config.AGC.minGain = profile->record_config.AGC.minGain; - chan_data->record_config.AGC.maxGain = profile->record_config.AGC.maxGain; - chan_data->record_config.AGC.attackRate = profile->record_config.AGC.attackRate; - chan_data->record_config.AGC.decayRate = profile->record_config.AGC.decayRate; - chan_data->record_config.AGC.speechThreshold = profile->record_config.AGC.speechThreshold; - chan_data->record_config.VAD.enabled = profile->record_config.VAD.enabled; - chan_data->record_config.VAD.activationThreshold = profile->record_config.VAD.activationThreshold; - chan_data->record_config.VAD.activationDebounceTime = profile->record_config.VAD.activationDebounceTime; - chan_data->record_config.VAD.deactivationThreshold = profile->record_config.VAD.deactivationThreshold; - chan_data->record_config.VAD.deactivationDebounceTime = profile->record_config.VAD.deactivationDebounceTime; - chan_data->record_config.VAD.preSpeechBufferSize = profile->record_config.VAD.preSpeechBufferSize; + 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.enabled = profile->play_config.AGC.enabled; - chan_data->play_config.AGC.targetPower = profile->play_config.AGC.targetPower; - chan_data->play_config.AGC.minGain = profile->play_config.AGC.minGain; - chan_data->play_config.AGC.maxGain = profile->play_config.AGC.maxGain; - chan_data->play_config.AGC.attackRate = profile->play_config.AGC.attackRate; - chan_data->play_config.AGC.decayRate = profile->play_config.AGC.decayRate; - chan_data->play_config.AGC.speechThreshold = profile->play_config.AGC.speechThreshold; + chan_data->play_config.AGC = profile->play_config.AGC; + chan_data->ec_enabled = profile->ec_enabled; + chan_data->ec_config = profile->ec_config; } status = PKH_RECORD_SetConfig(chan_data->media_in, &chan_data->record_config); @@ -452,8 +455,9 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa PKH_RECORD_Start(chan_data->media_in); PKH_PLAY_Start(chan_data->media_out); - - PKH_EC_Start(chan_data->media_in, chan_data->media_in, chan_data->media_out); + if (chan_data->ec_enabled) { + 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)); From bdc8ab6dddf12baefb09a9898460cbf863ae9cf2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 17 Nov 2007 21:31:22 +0000 Subject: [PATCH 0657/1766] fix windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@335 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_pika.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 72d6b2f47d..ec059b1467 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -417,7 +417,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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 = chan_data->record_config.bufferSize; + chan_data->record_config.numberOfBuffers = (PK_UINT)chan_data->record_config.bufferSize; chan_data->record_config.VAD.enabled = PK_FALSE; //chan_data->record_config.speechSegmentEventsEnabled = PK_FALSE; //chan_data->record_config.gain = rxgain; @@ -450,7 +450,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan->physical_chan_id = x; chan->rate = 8000; - chan->packet_len = chan_data->record_config.bufferSize; + 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); @@ -694,8 +694,8 @@ static ZIO_COMMAND_FUNCTION(pika_command) int interval = ZAP_COMMAND_OBJ_INT; int len = interval * 8; chan_data->record_config.bufferSize = len; - chan_data->record_config.numberOfBuffers = chan_data->record_config.bufferSize; - zchan->packet_len = chan_data->record_config.bufferSize; + 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); From 9af0aef7ab0105eba40ac84036b118930d9343b1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 17 Nov 2007 21:31:22 +0000 Subject: [PATCH 0658/1766] fix windows build. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@335 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_pika.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 72d6b2f47d..ec059b1467 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -417,7 +417,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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 = chan_data->record_config.bufferSize; + chan_data->record_config.numberOfBuffers = (PK_UINT)chan_data->record_config.bufferSize; chan_data->record_config.VAD.enabled = PK_FALSE; //chan_data->record_config.speechSegmentEventsEnabled = PK_FALSE; //chan_data->record_config.gain = rxgain; @@ -450,7 +450,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan->physical_chan_id = x; chan->rate = 8000; - chan->packet_len = chan_data->record_config.bufferSize; + 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); @@ -694,8 +694,8 @@ static ZIO_COMMAND_FUNCTION(pika_command) int interval = ZAP_COMMAND_OBJ_INT; int len = interval * 8; chan_data->record_config.bufferSize = len; - chan_data->record_config.numberOfBuffers = chan_data->record_config.bufferSize; - zchan->packet_len = chan_data->record_config.bufferSize; + 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); From bbc4d36b167e9b2b852dcbb7449e478df55fdc2c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 22:41:30 +0000 Subject: [PATCH 0659/1766] setup default config and some cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@336 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/pika.conf | 58 ++++++------ libs/openzap/src/zap_pika.c | 171 ++++++++++++------------------------ 2 files changed, 86 insertions(+), 143 deletions(-) diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf index 86b0897361..5073305da1 100644 --- a/libs/openzap/conf/pika.conf +++ b/libs/openzap/conf/pika.conf @@ -8,32 +8,32 @@ ; fxs-channel => 1:0:1-12@default [default] -rx-gain => 0 -rx-agc-enabled => 0 -rx-agc-targetPower => 0 -rx-agc-minGain => 0 -rx-agc-maxGain => 0 -rx-agc-attackRate => 0 -rx-agc-decayRate => 0 -rx-agc-speechThreshold => 0 -rx-vad-enabled => 0 -rx-vad-activationThreshold => 0 -rx-vad-activationDebounceTime => 0 -rx-vad-deactivationThreshold => 0 -rx-vad-deactivationDebounceTime => 0 -rx-vad-preSpeechBufferSize => 0 -tx-gain => 0 -tx-agc-enabled => 0 -tx-agc-targetPower => 0 -tx-agc-minGain => 0 -tx-agc-maxGain => 0 -tx-agc-attackRate => 0 -tx-agc-decayRate => 0 -tx-agc-speechThreshold => 0 -ec-enabled => 0 -ec-doubleTalkerThreshold => 0 -ec-speechPresentThreshold => 0 -ec-echoSuppressionThreshold => 0 -ec-echoSuppressionEnabled => 0 -ec-comfortNoiseEnabled => 0 -ec-adaptationModeEnabled => 0 +;rx-gain => 0 +;rx-agc-enabled => 0 +;rx-agc-targetPower => 0 +;rx-agc-minGain => 0 +;rx-agc-maxGain => 0 +;rx-agc-attackRate => 0 +;rx-agc-decayRate => 0 +;rx-agc-speechThreshold => 0 +;rx-vad-enabled => 0 +;rx-vad-activationThreshold => 0 +;rx-vad-activationDebounceTime => 0 +;rx-vad-deactivationThreshold => 0 +;rx-vad-deactivationDebounceTime => 0 +;rx-vad-preSpeechBufferSize => 0 +;tx-gain => 0 +;tx-agc-enabled => 0 +;tx-agc-targetPower => 0 +;tx-agc-minGain => 0 +;tx-agc-maxGain => 0 +;tx-agc-attackRate => 0 +;tx-agc-decayRate => 0 +;tx-agc-speechThreshold => 0 +;ec-enabled => 0 +;ec-doubleTalkerThreshold => 0 +;ec-speechPresentThreshold => 0 +;ec-echoSuppressionThreshold => 0 +;ec-echoSuppressionEnabled => 0 +;ec-comfortNoiseEnabled => 0 +;ec-adaptationModeEnabled => 0 diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index ec059b1467..aa6109c36e 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -34,9 +34,12 @@ #include "openzap.h" #include "zap_pika.h" + #define MAX_NUMBER_OF_TRUNKS 64 #define PIKA_BLOCK_SIZE 160 #define PIKA_BLOCK_LEN 20 +#define TRY_OR_DIE(__code, __status, __label) if ((status = __code ) != __status) goto __label +#define pk_atof(__a) (PK_FLOAT) atof(__a) struct pika_channel_profile { char name[80]; @@ -52,6 +55,9 @@ static struct { 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; zap_hash_t *profile_hash; } globals; @@ -103,62 +109,65 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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); zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } if (!strcasecmp(var, "rx-gain")) { - profile->record_config.gain = (PK_FLOAT)atof(val); + 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_FLOAT)atof(val); + profile->record_config.AGC.targetPower = pk_atof(val); } else if (!strcasecmp(var, "rx-agc-minGain")) { - profile->record_config.AGC.minGain = (PK_FLOAT)atof(val); + profile->record_config.AGC.minGain = pk_atof(val); } else if (!strcasecmp(var, "rx-agc-maxGain")) { - profile->record_config.AGC.maxGain = (PK_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + profile->play_config.AGC.targetPower = pk_atof(val); } else if (!strcasecmp(var, "tx-agc-minGain")) { - profile->play_config.AGC.minGain = (PK_FLOAT)atof(val); + profile->play_config.AGC.minGain = pk_atof(val); } else if (!strcasecmp(var, "tx-agc-maxGain")) { - profile->play_config.AGC.maxGain = (PK_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + profile->ec_config.doubleTalkerThreshold = pk_atof(val); } else if (!strcasecmp(var, "ec-speechPresentThreshold")) { - profile->ec_config.speechPresentThreshold = (PK_FLOAT)atof(val); + profile->ec_config.speechPresentThreshold = pk_atof(val); } else if (!strcasecmp(var, "ec-echoSuppressionThreshold")) { - profile->ec_config.echoSuppressionThreshold = (PK_FLOAT)atof(val); + 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")) { @@ -277,65 +286,29 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data = malloc(sizeof *chan_data); assert(chan_data); memset(chan_data, 0, sizeof(*chan_data)); - + + if (type == ZAP_CHAN_TYPE_FXO) { PKH_TTrunkConfig trunkConfig; - if((status = PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_Seize(chan_data->handle) != PK_SUCCESS)) { - goto fail_fxo; - } + TRY_OR_DIE(PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_Seize(chan_data->handle), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); - if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { - goto fail_fxo; - } - trunkConfig.internationalControl = PKH_TRUNK_NA; trunkConfig.audioFormat = PKH_AUDIO_MULAW; - if ((status = PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { - goto fail_fxo; - } + TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_Start(chan_data->handle), PK_SUCCESS, fail_fxo); - if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_Start(chan_data->handle)) != PK_SUCCESS) { - goto fail_fxo; - } - goto ok; fail_fxo: @@ -351,50 +324,18 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa continue; } else if (type == ZAP_CHAN_TYPE_FXS) { - if((status = PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { - goto fail_fxs; - } + TRY_OR_DIE(PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_PHONE_Seize(chan_data->handle), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_PHONE_Start(chan_data->handle), PK_SUCCESS, fail_fxs); - if ((status = PKH_PHONE_Seize(chan_data->handle) != PK_SUCCESS)) { - goto fail_fxs; - } - - if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_PHONE_Start(chan_data->handle)) != PK_SUCCESS) { - goto fail_fxs; - } - goto ok; @@ -407,8 +348,6 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } PKH_QUEUE_Destroy(chan_data->media_in_queue); free(chan_data); - - } ok: @@ -422,8 +361,6 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa //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; @@ -909,7 +846,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) uint32_t i; int ok = 0; PKH_TLogMasks m; - + TPikaHandle tmpHandle; assert(zint != NULL); memset(&pika_interface, 0, sizeof(pika_interface)); @@ -939,6 +876,12 @@ zap_status_t pika_init(zap_io_interface_t **zint) globals.system_config.recordNumberOfBuffers = 8; 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", From 1d06bed6227d85f2ac8cbcfb9d39226134260bf1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 22:41:30 +0000 Subject: [PATCH 0660/1766] setup default config and some cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@336 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/pika.conf | 58 ++++++------ libs/freetdm/src/zap_pika.c | 171 ++++++++++++------------------------ 2 files changed, 86 insertions(+), 143 deletions(-) diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index 86b0897361..5073305da1 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -8,32 +8,32 @@ ; fxs-channel => 1:0:1-12@default [default] -rx-gain => 0 -rx-agc-enabled => 0 -rx-agc-targetPower => 0 -rx-agc-minGain => 0 -rx-agc-maxGain => 0 -rx-agc-attackRate => 0 -rx-agc-decayRate => 0 -rx-agc-speechThreshold => 0 -rx-vad-enabled => 0 -rx-vad-activationThreshold => 0 -rx-vad-activationDebounceTime => 0 -rx-vad-deactivationThreshold => 0 -rx-vad-deactivationDebounceTime => 0 -rx-vad-preSpeechBufferSize => 0 -tx-gain => 0 -tx-agc-enabled => 0 -tx-agc-targetPower => 0 -tx-agc-minGain => 0 -tx-agc-maxGain => 0 -tx-agc-attackRate => 0 -tx-agc-decayRate => 0 -tx-agc-speechThreshold => 0 -ec-enabled => 0 -ec-doubleTalkerThreshold => 0 -ec-speechPresentThreshold => 0 -ec-echoSuppressionThreshold => 0 -ec-echoSuppressionEnabled => 0 -ec-comfortNoiseEnabled => 0 -ec-adaptationModeEnabled => 0 +;rx-gain => 0 +;rx-agc-enabled => 0 +;rx-agc-targetPower => 0 +;rx-agc-minGain => 0 +;rx-agc-maxGain => 0 +;rx-agc-attackRate => 0 +;rx-agc-decayRate => 0 +;rx-agc-speechThreshold => 0 +;rx-vad-enabled => 0 +;rx-vad-activationThreshold => 0 +;rx-vad-activationDebounceTime => 0 +;rx-vad-deactivationThreshold => 0 +;rx-vad-deactivationDebounceTime => 0 +;rx-vad-preSpeechBufferSize => 0 +;tx-gain => 0 +;tx-agc-enabled => 0 +;tx-agc-targetPower => 0 +;tx-agc-minGain => 0 +;tx-agc-maxGain => 0 +;tx-agc-attackRate => 0 +;tx-agc-decayRate => 0 +;tx-agc-speechThreshold => 0 +;ec-enabled => 0 +;ec-doubleTalkerThreshold => 0 +;ec-speechPresentThreshold => 0 +;ec-echoSuppressionThreshold => 0 +;ec-echoSuppressionEnabled => 0 +;ec-comfortNoiseEnabled => 0 +;ec-adaptationModeEnabled => 0 diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index ec059b1467..aa6109c36e 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -34,9 +34,12 @@ #include "openzap.h" #include "zap_pika.h" + #define MAX_NUMBER_OF_TRUNKS 64 #define PIKA_BLOCK_SIZE 160 #define PIKA_BLOCK_LEN 20 +#define TRY_OR_DIE(__code, __status, __label) if ((status = __code ) != __status) goto __label +#define pk_atof(__a) (PK_FLOAT) atof(__a) struct pika_channel_profile { char name[80]; @@ -52,6 +55,9 @@ static struct { 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; zap_hash_t *profile_hash; } globals; @@ -103,62 +109,65 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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); zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } if (!strcasecmp(var, "rx-gain")) { - profile->record_config.gain = (PK_FLOAT)atof(val); + 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_FLOAT)atof(val); + profile->record_config.AGC.targetPower = pk_atof(val); } else if (!strcasecmp(var, "rx-agc-minGain")) { - profile->record_config.AGC.minGain = (PK_FLOAT)atof(val); + profile->record_config.AGC.minGain = pk_atof(val); } else if (!strcasecmp(var, "rx-agc-maxGain")) { - profile->record_config.AGC.maxGain = (PK_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + profile->play_config.AGC.targetPower = pk_atof(val); } else if (!strcasecmp(var, "tx-agc-minGain")) { - profile->play_config.AGC.minGain = (PK_FLOAT)atof(val); + profile->play_config.AGC.minGain = pk_atof(val); } else if (!strcasecmp(var, "tx-agc-maxGain")) { - profile->play_config.AGC.maxGain = (PK_FLOAT)atof(val); + 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_FLOAT)atof(val); + 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_FLOAT)atof(val); + profile->ec_config.doubleTalkerThreshold = pk_atof(val); } else if (!strcasecmp(var, "ec-speechPresentThreshold")) { - profile->ec_config.speechPresentThreshold = (PK_FLOAT)atof(val); + profile->ec_config.speechPresentThreshold = pk_atof(val); } else if (!strcasecmp(var, "ec-echoSuppressionThreshold")) { - profile->ec_config.echoSuppressionThreshold = (PK_FLOAT)atof(val); + 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")) { @@ -277,65 +286,29 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data = malloc(sizeof *chan_data); assert(chan_data); memset(chan_data, 0, sizeof(*chan_data)); - + + if (type == ZAP_CHAN_TYPE_FXO) { PKH_TTrunkConfig trunkConfig; - if((status = PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_Seize(chan_data->handle) != PK_SUCCESS)) { - goto fail_fxo; - } + TRY_OR_DIE(PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_Seize(chan_data->handle), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); - if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { - goto fail_fxo; - } - trunkConfig.internationalControl = PKH_TRUNK_NA; trunkConfig.audioFormat = PKH_AUDIO_MULAW; - if ((status = PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig) != PK_SUCCESS)) { - goto fail_fxo; - } + TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); + TRY_OR_DIE(PKH_TRUNK_Start(chan_data->handle), PK_SUCCESS, fail_fxo); - if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxo; - } - - if ((status = PKH_TRUNK_Start(chan_data->handle)) != PK_SUCCESS) { - goto fail_fxo; - } - goto ok; fail_fxo: @@ -351,50 +324,18 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa continue; } else if (type == ZAP_CHAN_TYPE_FXS) { - if((status = PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle)) != PK_SUCCESS) { - goto fail_fxs; - } + TRY_OR_DIE(PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_PHONE_Seize(chan_data->handle), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); + TRY_OR_DIE(PKH_PHONE_Start(chan_data->handle), PK_SUCCESS, fail_fxs); - if ((status = PKH_PHONE_Seize(chan_data->handle) != PK_SUCCESS)) { - goto fail_fxs; - } - - if (zap_span_add_channel(span, 0, type, &chan) != ZAP_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out)) != ZAP_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan)) != PK_SUCCESS) { - goto fail_fxs; - } - - if ((status = PKH_PHONE_Start(chan_data->handle)) != PK_SUCCESS) { - goto fail_fxs; - } - goto ok; @@ -407,8 +348,6 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } PKH_QUEUE_Destroy(chan_data->media_in_queue); free(chan_data); - - } ok: @@ -422,8 +361,6 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa //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; @@ -909,7 +846,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) uint32_t i; int ok = 0; PKH_TLogMasks m; - + TPikaHandle tmpHandle; assert(zint != NULL); memset(&pika_interface, 0, sizeof(pika_interface)); @@ -939,6 +876,12 @@ zap_status_t pika_init(zap_io_interface_t **zint) globals.system_config.recordNumberOfBuffers = 8; 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", From 7ba733429eb2c6ef2e68af71c6d37f8a8b870e30 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 23:23:14 +0000 Subject: [PATCH 0661/1766] set actual default git-svn-id: http://svn.openzap.org/svn/openzap/trunk@337 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/pika.conf | 57 ++++++++++++++++++------------------- libs/openzap/src/zap_pika.c | 32 ++++++++++++++++++++- 2 files changed, 59 insertions(+), 30 deletions(-) diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf index 5073305da1..b44cedabbf 100644 --- a/libs/openzap/conf/pika.conf +++ b/libs/openzap/conf/pika.conf @@ -8,32 +8,31 @@ ; fxs-channel => 1:0:1-12@default [default] -;rx-gain => 0 -;rx-agc-enabled => 0 -;rx-agc-targetPower => 0 -;rx-agc-minGain => 0 -;rx-agc-maxGain => 0 -;rx-agc-attackRate => 0 -;rx-agc-decayRate => 0 -;rx-agc-speechThreshold => 0 -;rx-vad-enabled => 0 -;rx-vad-activationThreshold => 0 -;rx-vad-activationDebounceTime => 0 -;rx-vad-deactivationThreshold => 0 -;rx-vad-deactivationDebounceTime => 0 -;rx-vad-preSpeechBufferSize => 0 -;tx-gain => 0 -;tx-agc-enabled => 0 -;tx-agc-targetPower => 0 -;tx-agc-minGain => 0 -;tx-agc-maxGain => 0 -;tx-agc-attackRate => 0 -;tx-agc-decayRate => 0 -;tx-agc-speechThreshold => 0 -;ec-enabled => 0 -;ec-doubleTalkerThreshold => 0 -;ec-speechPresentThreshold => 0 -;ec-echoSuppressionThreshold => 0 -;ec-echoSuppressionEnabled => 0 -;ec-comfortNoiseEnabled => 0 -;ec-adaptationModeEnabled => 0 +;rx-gain => 0.00 +;rx-agc-enabled => false +;rx-agc-targetPower => -15.00 +;rx-agc-minGain => -6.00 +;rx-agc-maxGain => 18.00 +;rx-agc-attackRate => 170 +;rx-agc-decayRate => 750 +;rx-agc-speechThreshold => -36.00 +;rx-vad-enabled => false +;rx-vad-activationThreshold => -40.00 +;rx-vad-activationDebounceTime => 72 +;rx-vad-deactivationThreshold => -40.00 +;rx-vad-deactivationDebounceTime => 984 +;rx-vad-preSpeechBufferSize => 240 +;tx-gain => 0.00 +;tx-agc-enabled => true +;tx-agc-targetPower => -15.00 +;tx-agc-minGain => -6.00 +;tx-agc-maxGain => 18.00 +;tx-agc-attackRate => 170 +;tx-agc-decayRate => 750 +;tx-agc-speechThreshold => -36.00 +;ec-doubleTalkerThreshold => -6.00 +;ec-speechPresentThreshold => -40.00 +;ec-echoSuppressionThreshold => -18.00 +;ec-echoSuppressionEnabled => true +;ec-comfortNoiseEnabled => true +;ec-adaptationModeEnabled => true diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index aa6109c36e..60cb333828 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -912,7 +912,37 @@ zap_status_t pika_init(zap_io_interface_t **zint) pika_interface.get_alarms = pika_get_alarms; *zint = &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)); From a6185618582db4c50df5ea6bb4f60f456059e756 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 23:23:14 +0000 Subject: [PATCH 0662/1766] set actual default git-svn-id: http://svn.openzap.org/svn/openzap/trunk@337 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/pika.conf | 57 ++++++++++++++++++------------------- libs/freetdm/src/zap_pika.c | 32 ++++++++++++++++++++- 2 files changed, 59 insertions(+), 30 deletions(-) diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index 5073305da1..b44cedabbf 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -8,32 +8,31 @@ ; fxs-channel => 1:0:1-12@default [default] -;rx-gain => 0 -;rx-agc-enabled => 0 -;rx-agc-targetPower => 0 -;rx-agc-minGain => 0 -;rx-agc-maxGain => 0 -;rx-agc-attackRate => 0 -;rx-agc-decayRate => 0 -;rx-agc-speechThreshold => 0 -;rx-vad-enabled => 0 -;rx-vad-activationThreshold => 0 -;rx-vad-activationDebounceTime => 0 -;rx-vad-deactivationThreshold => 0 -;rx-vad-deactivationDebounceTime => 0 -;rx-vad-preSpeechBufferSize => 0 -;tx-gain => 0 -;tx-agc-enabled => 0 -;tx-agc-targetPower => 0 -;tx-agc-minGain => 0 -;tx-agc-maxGain => 0 -;tx-agc-attackRate => 0 -;tx-agc-decayRate => 0 -;tx-agc-speechThreshold => 0 -;ec-enabled => 0 -;ec-doubleTalkerThreshold => 0 -;ec-speechPresentThreshold => 0 -;ec-echoSuppressionThreshold => 0 -;ec-echoSuppressionEnabled => 0 -;ec-comfortNoiseEnabled => 0 -;ec-adaptationModeEnabled => 0 +;rx-gain => 0.00 +;rx-agc-enabled => false +;rx-agc-targetPower => -15.00 +;rx-agc-minGain => -6.00 +;rx-agc-maxGain => 18.00 +;rx-agc-attackRate => 170 +;rx-agc-decayRate => 750 +;rx-agc-speechThreshold => -36.00 +;rx-vad-enabled => false +;rx-vad-activationThreshold => -40.00 +;rx-vad-activationDebounceTime => 72 +;rx-vad-deactivationThreshold => -40.00 +;rx-vad-deactivationDebounceTime => 984 +;rx-vad-preSpeechBufferSize => 240 +;tx-gain => 0.00 +;tx-agc-enabled => true +;tx-agc-targetPower => -15.00 +;tx-agc-minGain => -6.00 +;tx-agc-maxGain => 18.00 +;tx-agc-attackRate => 170 +;tx-agc-decayRate => 750 +;tx-agc-speechThreshold => -36.00 +;ec-doubleTalkerThreshold => -6.00 +;ec-speechPresentThreshold => -40.00 +;ec-echoSuppressionThreshold => -18.00 +;ec-echoSuppressionEnabled => true +;ec-comfortNoiseEnabled => true +;ec-adaptationModeEnabled => true diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index aa6109c36e..60cb333828 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -912,7 +912,37 @@ zap_status_t pika_init(zap_io_interface_t **zint) pika_interface.get_alarms = pika_get_alarms; *zint = &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)); From 6837a069c300979121217831dd16a7acf43baeed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 23:32:51 +0000 Subject: [PATCH 0663/1766] polish git-svn-id: http://svn.openzap.org/svn/openzap/trunk@338 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/pika.conf | 1 + libs/openzap/src/zap_pika.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf index b44cedabbf..cdb96b0bbc 100644 --- a/libs/openzap/conf/pika.conf +++ b/libs/openzap/conf/pika.conf @@ -30,6 +30,7 @@ ;tx-agc-attackRate => 170 ;tx-agc-decayRate => 750 ;tx-agc-speechThreshold => -36.00 +;ec->enabled => false ;ec-doubleTalkerThreshold => -6.00 ;ec-speechPresentThreshold => -40.00 ;ec-echoSuppressionThreshold => -18.00 diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 60cb333828..7add97eaa8 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -393,6 +393,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); } From bb911f2bfd8e963477276bfdd35f75d4a5701a6f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Nov 2007 23:32:51 +0000 Subject: [PATCH 0664/1766] polish git-svn-id: http://svn.openzap.org/svn/openzap/trunk@338 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/pika.conf | 1 + libs/freetdm/src/zap_pika.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index b44cedabbf..cdb96b0bbc 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -30,6 +30,7 @@ ;tx-agc-attackRate => 170 ;tx-agc-decayRate => 750 ;tx-agc-speechThreshold => -36.00 +;ec->enabled => false ;ec-doubleTalkerThreshold => -6.00 ;ec-speechPresentThreshold => -40.00 ;ec-echoSuppressionThreshold => -18.00 diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 60cb333828..7add97eaa8 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -393,6 +393,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); } From dbcdb7aac6d07b6d1772d83b94d0ce0c48ebfef2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 19 Nov 2007 14:52:59 +0000 Subject: [PATCH 0665/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@339 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_pika.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 7add97eaa8..00da64b2f7 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -38,6 +38,7 @@ #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) @@ -356,7 +357,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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 = (PK_UINT)chan_data->record_config.bufferSize; + 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; @@ -874,7 +875,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) 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 = 8; + globals.system_config.recordNumberOfBuffers = PIKA_NUM_BUFFERS; PKH_SYSTEM_SetConfig(globals.system_handle, &globals.system_config); status = PKH_MEDIA_STREAM_Create(&tmpHandle); From 621f1b6a05445e4c6b5088744c8ecc4da808fbfb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 19 Nov 2007 14:52:59 +0000 Subject: [PATCH 0666/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@339 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_pika.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 7add97eaa8..00da64b2f7 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -38,6 +38,7 @@ #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) @@ -356,7 +357,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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 = (PK_UINT)chan_data->record_config.bufferSize; + 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; @@ -874,7 +875,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) 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 = 8; + globals.system_config.recordNumberOfBuffers = PIKA_NUM_BUFFERS; PKH_SYSTEM_SetConfig(globals.system_handle, &globals.system_config); status = PKH_MEDIA_STREAM_Create(&tmpHandle); From a37aa538ed025c2e7d25645b2ba23c2649dc223e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 19 Nov 2007 16:10:19 +0000 Subject: [PATCH 0667/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@340 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/pika.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf index cdb96b0bbc..418be1d289 100644 --- a/libs/openzap/conf/pika.conf +++ b/libs/openzap/conf/pika.conf @@ -30,7 +30,7 @@ ;tx-agc-attackRate => 170 ;tx-agc-decayRate => 750 ;tx-agc-speechThreshold => -36.00 -;ec->enabled => false +;ec-enabled => false ;ec-doubleTalkerThreshold => -6.00 ;ec-speechPresentThreshold => -40.00 ;ec-echoSuppressionThreshold => -18.00 From b701f9c80205abad0803be73a6078826187d7314 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 19 Nov 2007 16:10:19 +0000 Subject: [PATCH 0668/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@340 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/pika.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index cdb96b0bbc..418be1d289 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -30,7 +30,7 @@ ;tx-agc-attackRate => 170 ;tx-agc-decayRate => 750 ;tx-agc-speechThreshold => -36.00 -;ec->enabled => false +;ec-enabled => false ;ec-doubleTalkerThreshold => -6.00 ;ec-speechPresentThreshold => -40.00 ;ec-echoSuppressionThreshold => -18.00 From 3faf9b70c3ad0f26d4f980fe12c2d4344f751c63 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 21:08:06 +0000 Subject: [PATCH 0669/1766] Send event to app when we get a release. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@341 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 9f68c970b0..48b7847ab7 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -765,6 +765,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO Add proc here*/ ret = Q931Tx32(pTrunk,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); From e0ddee14a33ddced58d0c49c699abb51c26aac93 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 21:08:06 +0000 Subject: [PATCH 0670/1766] Send event to app when we get a release. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@341 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 9f68c970b0..48b7847ab7 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -765,6 +765,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO Add proc here*/ ret = Q931Tx32(pTrunk,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); From e77c69f2836b33dde3862eeb0662e7cfc4aa0589 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 21:55:46 +0000 Subject: [PATCH 0671/1766] allways tell the app regardless of state. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@342 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 48b7847ab7..07e31bdcf0 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -784,7 +784,7 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) + if(iFrom == 2) { /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); From 8d234ad209b153643037388c7103a2b828864e11 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 21:55:46 +0000 Subject: [PATCH 0672/1766] allways tell the app regardless of state. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@342 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 48b7847ab7..07e31bdcf0 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -784,7 +784,7 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; - if(state == Q931_U0 && iFrom == 2) + if(iFrom == 2) { /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); From 8dfec4151f15cd7125b6d675fae5ccb95c986893 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 22:02:04 +0000 Subject: [PATCH 0673/1766] pull some state stuff out for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@343 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 07e31bdcf0..bdded13486 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -405,7 +405,8 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); - Q931SetState(pTrunk, callIndex, Q931_U1); + /* TODO: Add this back when we get the state stuff more filled out */ + //Q931SetState(pTrunk, callIndex, Q931_U1); } /* incoming call */ else From 8e8f641f3c401c0caab116db23271b6ef3b99767 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 22:02:04 +0000 Subject: [PATCH 0674/1766] pull some state stuff out for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@343 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 07e31bdcf0..bdded13486 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -405,7 +405,8 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); - Q931SetState(pTrunk, callIndex, Q931_U1); + /* TODO: Add this back when we get the state stuff more filled out */ + //Q931SetState(pTrunk, callIndex, Q931_U1); } /* incoming call */ else From d0a3cefa3ffc3fdf321bbb4a0df753c7424489f5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 22:08:37 +0000 Subject: [PATCH 0675/1766] unused var. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@344 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index bdded13486..a45aa06472 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -783,7 +783,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + //L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; if(iFrom == 2) { From e000d714253499df253b657b7b70a541266f2266 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 Nov 2007 22:08:37 +0000 Subject: [PATCH 0676/1766] unused var. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@344 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index bdded13486..a45aa06472 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -783,7 +783,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT state = Q931GetCallState(pTrunk, pMes->CRV); + //L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; if(iFrom == 2) { From 32e176c561490054bb5ae2889d12a9e9d3c88dbc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 21 Nov 2007 22:08:47 +0000 Subject: [PATCH 0677/1766] add pika isdn support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@345 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 17 +- libs/openzap/src/include/zap_pika.h | 60 ++++ libs/openzap/src/include/zap_types.h | 5 +- libs/openzap/src/zap_io.c | 3 + libs/openzap/src/zap_isdn.c | 21 +- libs/openzap/src/zap_pika.c | 466 ++++++++++++++++++++++----- 6 files changed, 468 insertions(+), 104 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index c57ef1c5f3..a9209ad8c2 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -81,10 +81,10 @@ #pragma comment(lib, "Winmm") #endif -#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; -#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; +#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); #define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ - _TYPE _FUNC1 (char *name) \ + _TYPE _FUNC1 (const char *name) \ { \ int i; \ _TYPE t = _MAX ; \ @@ -98,7 +98,7 @@ \ return t; \ } \ - char * _FUNC2 (_TYPE type) \ + const char * _FUNC2 (_TYPE type) \ { \ if (type > _MAX) { \ type = _MAX; \ @@ -319,7 +319,15 @@ struct zap_caller_data { uint32_t raw_data_len; }; +typedef enum { + ZAP_TYPE_NONE, + ZAP_TYPE_SPAN = 0xFF, + ZAP_TYPE_CHANNEL +} zap_data_type_t; + + struct zap_channel { + zap_data_type_t data_type; uint32_t span_id; uint32_t chan_id; uint32_t physical_span_id; @@ -399,6 +407,7 @@ struct zap_analog_data { }; struct zap_span { + zap_data_type_t data_type; uint32_t span_id; uint32_t chan_count; zap_span_flag_t flags; diff --git a/libs/openzap/src/include/zap_pika.h b/libs/openzap/src/include/zap_pika.h index 6d1c68f5f6..c30f98cbb3 100644 --- a/libs/openzap/src/include/zap_pika.h +++ b/libs/openzap/src/include/zap_pika.h @@ -35,6 +35,66 @@ #define ZAP_PIKA_H #include "openzap.h" #include "pikahmpapi.h" + + + + +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" +ZAP_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" +ZAP_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" +ZAP_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" +ZAP_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) + +typedef enum { + PIKA_SPAN_COMMAND_MODE_MU_LAW = 1, + PIKA_SPAN_COMMAND_MODE_A_LAW, + PIKA_SPAN_COMMAND_MODE_INVALID +} PIKA_TSpanCompandMode; +#define PIKA_SPAN_COMMAND_MODE_STRINGS "MU_LAW", "A_LAW" +ZAP_STR2ENUM_P(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode) + + /* Openzap PIKA hardware interface functions */ zap_status_t pika_init(zap_io_interface_t **zint); zap_status_t pika_destroy(void); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index e05f219f25..8be5007779 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -153,7 +153,10 @@ typedef enum { ZAP_ALARM_YELLOW = (1 << 3), ZAP_ALARM_RED = (1 << 4), ZAP_ALARM_BLUE = (1 << 5), - ZAP_ALARM_NOTOPEN = ( 1 << 6) + ZAP_ALARM_NOTOPEN = ( 1 << 6), + ZAP_ALARM_AIS = ( 1 << 7), + ZAP_ALARM_RAI = ( 1 << 8), + ZAP_ALARM_GENERAL = ( 1 << 31) } zap_alarm_flag_t; typedef enum { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 64b415adfb..d8aa4778ef 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -316,6 +316,7 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); new_span->trunk_type = ZAP_TRUNK_NONE; + new_span->data_type = ZAP_TYPE_SPAN; *span = new_span; status = ZAP_SUCCESS; } @@ -421,6 +422,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span = span; new_chan->fds[0] = -1; new_chan->fds[1] = -1; + new_chan->data_type = ZAP_TYPE_CHANNEL; if (!new_chan->dtmf_on) { new_chan->dtmf_on = ZAP_DEFAULT_DTMF_ON; } @@ -605,6 +607,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_DOWN: case ZAP_CHANNEL_STATE_BUSY: + case ZAP_CHANNEL_STATE_RESTART: ok = 1; break; default: diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index e9647319c4..c159230ad5 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -42,7 +42,7 @@ #endif #define LINE "--------------------------------------------------------------------------------" -#define IODEBUG +//#define IODEBUG static L2ULONG zap_time_now() { @@ -141,6 +141,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } break; + case Q931mes_RELEASE: case Q931mes_RELEASE_COMPLETE: { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -151,6 +152,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); zchan->caller_data.hangup_cause = cause->Value; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } break; case Q931mes_ALERTING: @@ -196,7 +198,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->caller_data.raw_data_len = cplen; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; - zap_log(ZAP_LOG_CRIT, "hi %s\n", zchan->caller_data.cid_num); } } @@ -235,10 +236,10 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT 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); + 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 @@ -563,11 +564,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) len = sizeof(buf); if (zap_channel_read(isdn_data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG - //char bb[4096] = ""; - //print_hex_bytes(buf, len, bb, sizeof(bb)); + char bb[4096] = ""; + print_hex_bytes(buf, len, bb, sizeof(bb)); - //print_bits(buf, (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); + print_bits(buf, (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, buf, (int)len); diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 00da64b2f7..8644b4acd5 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -42,12 +42,40 @@ #define TRY_OR_DIE(__code, __status, __label) if ((status = __code ) != __status) goto __label #define pk_atof(__a) (PK_FLOAT) atof(__a) +ZAP_ENUM_NAMES(PIKA_SPAN_NAMES, PIKA_SPAN_STRINGS) +ZAP_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID) + +ZAP_ENUM_NAMES(PIKA_SPAN_ENCODING_NAMES, PIKA_SPAN_ENCODING_STRINGS) +ZAP_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) +ZAP_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) +ZAP_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID) + +ZAP_ENUM_NAMES(PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_MODE_STRINGS) +ZAP_STR2ENUM(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_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; }; typedef struct pika_channel_profile pika_channel_profile_t; @@ -59,7 +87,9 @@ static struct { PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; PKH_TECConfig ec_config; + PKH_TSpanConfig span_config; zap_hash_t *profile_hash; + general_config_t general_config; } globals; @@ -67,6 +97,9 @@ 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; @@ -82,9 +115,12 @@ struct pika_chan_data { 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; @@ -111,6 +147,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); profile->ec_config = globals.ec_config; + profile->span_config = globals.span_config; profile->record_config = globals.record_config; profile->play_config = globals.play_config; hashtable_insert(globals.profile_hash, (void *)profile->name, profile); @@ -175,6 +212,20 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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); + } else if (!strcasecmp(var, "encoding")) { + profile->span_config.encoding = pika_str2span_encoding(val); + } else if (!strcasecmp(var, "loopLength")) { + profile->span_config.loopLength = pika_str2loop_length(val); + } else if (!strcasecmp(var, "buildOut")) { + profile->span_config.buildOut = pika_str2lbo(val); + } 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; } @@ -194,9 +245,9 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) zap_channel_t *zchan = event->userData; pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; - //PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; - //PKH_EVENT_GetText(event->id, g_EventText, sizeof(g_EventText)); - //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + //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: @@ -259,7 +310,9 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } - if (!span->mod_data) { + 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)); @@ -274,12 +327,16 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa return 0; } - PKH_QUEUE_Attach(span_data->event_queue, globals.open_boards[boardno], NULL); + //PKH_QUEUE_Attach(span_data->event_queue, globals.open_boards[boardno], NULL); span->mod_data = span_data; } - start--; - end--; + + 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; @@ -287,72 +344,99 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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_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); + TRY_OR_DIE(PKH_BOARD_GetConfig(globals.open_boards[boardno], &boardConfig), PK_SUCCESS, error); + + 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; + PKH_BOARD_SetConfig(globals.open_boards[boardno], &boardConfig); + zap_set_flag(span_data, PK_FLAG_LOCKED); + } + } 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, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_Seize(chan_data->handle), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); + 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); - trunkConfig.internationalControl = PKH_TRUNK_NA; - trunkConfig.audioFormat = PKH_AUDIO_MULAW; - - TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_Start(chan_data->handle), PK_SUCCESS, fail_fxo); - - goto ok; - - fail_fxo: - zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); - zap_log(ZAP_LOG_ERROR, "Error: PKH_TRUNK_Open %u failed(%s)!\n", x, - PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - if (chan_data->handle) { - PKH_TRUNK_Close(chan_data->handle); + 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; + TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, error); } - PKH_QUEUE_Destroy(chan_data->media_in_queue); - free(chan_data); - continue; + 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) { - TRY_OR_DIE(PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_PHONE_Seize(chan_data->handle), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_PHONE_Start(chan_data->handle), PK_SUCCESS, fail_fxs); - - goto ok; + PKH_TPhoneConfig phoneConfig; - - fail_fxs: - zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); - zap_log(ZAP_LOG_ERROR, "Error: PKH_PHONE_Open %u failed(%s)!\n", x, - PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - if (chan_data->handle) { - PKH_PHONE_Close(chan_data->handle); + 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; + TRY_OR_DIE(PKH_PHONE_SetConfig(chan_data->handle, &phoneConfig), PK_SUCCESS, error); } - PKH_QUEUE_Destroy(chan_data->media_in_queue); - free(chan_data); - } - ok: + 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); + 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; @@ -377,13 +461,16 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data->play_config.AGC = profile->play_config.AGC; chan_data->ec_enabled = profile->ec_enabled; chan_data->ec_config = profile->ec_config; + 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; } 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->mod_data = chan_data; chan->physical_span_id = spanno; chan->physical_chan_id = x; @@ -448,10 +535,9 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) bd = item_list[i]; if ((sp = strchr(bd, ':'))) { *sp++ = '\0'; - } - - if ((ch = strchr(sp, ':'))) { - *ch++ = '\0'; + if ((ch = strchr(sp, ':'))) { + *ch++ = '\0'; + } } if (!(bd && sp && ch)) { @@ -504,8 +590,18 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) static ZIO_OPEN_FUNCTION(pika_open) { pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; - PKH_QUEUE_Flush(chan_data->media_in_queue); - PKH_PLAY_Start(chan_data->media_out); + + 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; } @@ -519,11 +615,15 @@ 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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + 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) { @@ -535,8 +635,8 @@ static ZIO_WAIT_FUNCTION(pika_wait) return ZAP_SUCCESS; } - PKH_EVENT_GetText(chan_data->last_media_event.id, g_EventText, sizeof(g_EventText)); - zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + 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; @@ -546,7 +646,16 @@ static ZIO_READ_FUNCTION(pika_read) { pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; PK_STATUS status; - PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH]; + + 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 (zchan->packet_len < *datalen) { *datalen = zchan->packet_len; @@ -557,14 +666,22 @@ static ZIO_READ_FUNCTION(pika_read) } - PKH_ERROR_GetText(status, g_EventText, sizeof(g_EventText)); - zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", g_EventText); + PKH_ERROR_GetText(status, event_text, sizeof(event_text)); + zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", event_text); return ZAP_FAIL; } 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; @@ -706,22 +823,93 @@ 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 = span_data->last_oob_event.userData; - //PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + 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; } - - //PKH_EVENT_GetText(span_data->last_oob_event.id, g_EventText, sizeof(g_EventText)); - //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + 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; @@ -740,18 +928,16 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + 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, g_EventText, sizeof(g_EventText)); - zap_log(ZAP_LOG_DEBUG, "Event %d on channel %d:%d [%s]\n", - chan_data->last_oob_event.id, - span->channels[i].span_id, - span->channels[i].chan_id, - g_EventText); + 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; @@ -774,6 +960,79 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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 : @@ -783,7 +1042,7 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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, g_EventText); + 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; } @@ -816,16 +1075,34 @@ 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 (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { - PKH_QUEUE_Detach(span_data->event_queue, chan_data->handle); - PKH_TRUNK_Close(chan_data->handle); + + if (!chan_data) { + return ZAP_FAIL; } + 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); zap_safe_free(chan_data); @@ -853,6 +1130,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) assert(zint != 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); @@ -884,12 +1162,22 @@ zap_status_t pika_init(zap_io_interface_t **zint) 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 tmp, tmp2; + PKH_BOARD_Open(globals.board_list.board[i].id, NULL, &tmp); + PKH_SPAN_Open(tmp, 0, NULL, &tmp2); + PKH_SPAN_GetConfig(tmp2, &globals.span_config); + PKH_SPAN_Close(tmp2); + PKH_BOARD_Close(tmp); + } ok++; } From 027e0d1438e2b095a0020f6a4a66d53bceb08c24 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 21 Nov 2007 22:08:47 +0000 Subject: [PATCH 0678/1766] add pika isdn support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@345 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 17 +- libs/freetdm/src/include/zap_pika.h | 60 ++++ libs/freetdm/src/include/zap_types.h | 5 +- libs/freetdm/src/zap_io.c | 3 + libs/freetdm/src/zap_isdn.c | 21 +- libs/freetdm/src/zap_pika.c | 466 ++++++++++++++++++++++----- 6 files changed, 468 insertions(+), 104 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index c57ef1c5f3..a9209ad8c2 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -81,10 +81,10 @@ #pragma comment(lib, "Winmm") #endif -#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; -#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; +#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); #define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ - _TYPE _FUNC1 (char *name) \ + _TYPE _FUNC1 (const char *name) \ { \ int i; \ _TYPE t = _MAX ; \ @@ -98,7 +98,7 @@ \ return t; \ } \ - char * _FUNC2 (_TYPE type) \ + const char * _FUNC2 (_TYPE type) \ { \ if (type > _MAX) { \ type = _MAX; \ @@ -319,7 +319,15 @@ struct zap_caller_data { uint32_t raw_data_len; }; +typedef enum { + ZAP_TYPE_NONE, + ZAP_TYPE_SPAN = 0xFF, + ZAP_TYPE_CHANNEL +} zap_data_type_t; + + struct zap_channel { + zap_data_type_t data_type; uint32_t span_id; uint32_t chan_id; uint32_t physical_span_id; @@ -399,6 +407,7 @@ struct zap_analog_data { }; struct zap_span { + zap_data_type_t data_type; uint32_t span_id; uint32_t chan_count; zap_span_flag_t flags; diff --git a/libs/freetdm/src/include/zap_pika.h b/libs/freetdm/src/include/zap_pika.h index 6d1c68f5f6..c30f98cbb3 100644 --- a/libs/freetdm/src/include/zap_pika.h +++ b/libs/freetdm/src/include/zap_pika.h @@ -35,6 +35,66 @@ #define ZAP_PIKA_H #include "openzap.h" #include "pikahmpapi.h" + + + + +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" +ZAP_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" +ZAP_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" +ZAP_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" +ZAP_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) + +typedef enum { + PIKA_SPAN_COMMAND_MODE_MU_LAW = 1, + PIKA_SPAN_COMMAND_MODE_A_LAW, + PIKA_SPAN_COMMAND_MODE_INVALID +} PIKA_TSpanCompandMode; +#define PIKA_SPAN_COMMAND_MODE_STRINGS "MU_LAW", "A_LAW" +ZAP_STR2ENUM_P(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode) + + /* Openzap PIKA hardware interface functions */ zap_status_t pika_init(zap_io_interface_t **zint); zap_status_t pika_destroy(void); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index e05f219f25..8be5007779 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -153,7 +153,10 @@ typedef enum { ZAP_ALARM_YELLOW = (1 << 3), ZAP_ALARM_RED = (1 << 4), ZAP_ALARM_BLUE = (1 << 5), - ZAP_ALARM_NOTOPEN = ( 1 << 6) + ZAP_ALARM_NOTOPEN = ( 1 << 6), + ZAP_ALARM_AIS = ( 1 << 7), + ZAP_ALARM_RAI = ( 1 << 8), + ZAP_ALARM_GENERAL = ( 1 << 31) } zap_alarm_flag_t; typedef enum { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 64b415adfb..d8aa4778ef 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -316,6 +316,7 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); new_span->trunk_type = ZAP_TRUNK_NONE; + new_span->data_type = ZAP_TYPE_SPAN; *span = new_span; status = ZAP_SUCCESS; } @@ -421,6 +422,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha new_chan->span = span; new_chan->fds[0] = -1; new_chan->fds[1] = -1; + new_chan->data_type = ZAP_TYPE_CHANNEL; if (!new_chan->dtmf_on) { new_chan->dtmf_on = ZAP_DEFAULT_DTMF_ON; } @@ -605,6 +607,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_DOWN: case ZAP_CHANNEL_STATE_BUSY: + case ZAP_CHANNEL_STATE_RESTART: ok = 1; break; default: diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index e9647319c4..c159230ad5 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -42,7 +42,7 @@ #endif #define LINE "--------------------------------------------------------------------------------" -#define IODEBUG +//#define IODEBUG static L2ULONG zap_time_now() { @@ -141,6 +141,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } break; + case Q931mes_RELEASE: case Q931mes_RELEASE_COMPLETE: { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -151,6 +152,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); zchan->caller_data.hangup_cause = cause->Value; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } break; case Q931mes_ALERTING: @@ -196,7 +198,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->caller_data.raw_data_len = cplen; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; - zap_log(ZAP_LOG_CRIT, "hi %s\n", zchan->caller_data.cid_num); } } @@ -235,10 +236,10 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT 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); + 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 @@ -563,11 +564,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) len = sizeof(buf); if (zap_channel_read(isdn_data->dchan, buf, &len) == ZAP_SUCCESS) { #ifdef IODEBUG - //char bb[4096] = ""; - //print_hex_bytes(buf, len, bb, sizeof(bb)); + char bb[4096] = ""; + print_hex_bytes(buf, len, bb, sizeof(bb)); - //print_bits(buf, (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); + print_bits(buf, (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, buf, (int)len); diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 00da64b2f7..8644b4acd5 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -42,12 +42,40 @@ #define TRY_OR_DIE(__code, __status, __label) if ((status = __code ) != __status) goto __label #define pk_atof(__a) (PK_FLOAT) atof(__a) +ZAP_ENUM_NAMES(PIKA_SPAN_NAMES, PIKA_SPAN_STRINGS) +ZAP_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID) + +ZAP_ENUM_NAMES(PIKA_SPAN_ENCODING_NAMES, PIKA_SPAN_ENCODING_STRINGS) +ZAP_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) +ZAP_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) +ZAP_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID) + +ZAP_ENUM_NAMES(PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_MODE_STRINGS) +ZAP_STR2ENUM(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_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; }; typedef struct pika_channel_profile pika_channel_profile_t; @@ -59,7 +87,9 @@ static struct { PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; PKH_TECConfig ec_config; + PKH_TSpanConfig span_config; zap_hash_t *profile_hash; + general_config_t general_config; } globals; @@ -67,6 +97,9 @@ 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; @@ -82,9 +115,12 @@ struct pika_chan_data { 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; @@ -111,6 +147,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); profile->ec_config = globals.ec_config; + profile->span_config = globals.span_config; profile->record_config = globals.record_config; profile->play_config = globals.play_config; hashtable_insert(globals.profile_hash, (void *)profile->name, profile); @@ -175,6 +212,20 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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); + } else if (!strcasecmp(var, "encoding")) { + profile->span_config.encoding = pika_str2span_encoding(val); + } else if (!strcasecmp(var, "loopLength")) { + profile->span_config.loopLength = pika_str2loop_length(val); + } else if (!strcasecmp(var, "buildOut")) { + profile->span_config.buildOut = pika_str2lbo(val); + } 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; } @@ -194,9 +245,9 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) zap_channel_t *zchan = event->userData; pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; - //PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; - //PKH_EVENT_GetText(event->id, g_EventText, sizeof(g_EventText)); - //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + //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: @@ -259,7 +310,9 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } - if (!span->mod_data) { + 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)); @@ -274,12 +327,16 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa return 0; } - PKH_QUEUE_Attach(span_data->event_queue, globals.open_boards[boardno], NULL); + //PKH_QUEUE_Attach(span_data->event_queue, globals.open_boards[boardno], NULL); span->mod_data = span_data; } - start--; - end--; + + 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; @@ -287,72 +344,99 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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_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); + TRY_OR_DIE(PKH_BOARD_GetConfig(globals.open_boards[boardno], &boardConfig), PK_SUCCESS, error); + + 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; + PKH_BOARD_SetConfig(globals.open_boards[boardno], &boardConfig); + zap_set_flag(span_data, PK_FLAG_LOCKED); + } + } 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, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_Seize(chan_data->handle), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_GetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); + 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); - trunkConfig.internationalControl = PKH_TRUNK_NA; - trunkConfig.audioFormat = PKH_AUDIO_MULAW; - - TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxo); - TRY_OR_DIE(PKH_TRUNK_Start(chan_data->handle), PK_SUCCESS, fail_fxo); - - goto ok; - - fail_fxo: - zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); - zap_log(ZAP_LOG_ERROR, "Error: PKH_TRUNK_Open %u failed(%s)!\n", x, - PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - if (chan_data->handle) { - PKH_TRUNK_Close(chan_data->handle); + 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; + TRY_OR_DIE(PKH_TRUNK_SetConfig(chan_data->handle, &trunkConfig), PK_SUCCESS, error); } - PKH_QUEUE_Destroy(chan_data->media_in_queue); - free(chan_data); - continue; + 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) { - TRY_OR_DIE(PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_PHONE_Seize(chan_data->handle), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(zap_span_add_channel(span, 0, type, &chan), ZAP_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_PHONE_GetMediaStreams(chan_data->handle, &chan_data->media_in, &chan_data->media_out), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Attach(span_data->event_queue, chan_data->handle, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_NORMAL, &chan_data->media_in_queue), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_in_queue, chan_data->media_in, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Create(PKH_QUEUE_TYPE_CALLBACK, &chan_data->media_out_queue), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_SetEventHandler(chan_data->media_out_queue, media_out_callback), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_QUEUE_Attach(chan_data->media_out_queue, chan_data->media_out, (PK_VOID*) chan), PK_SUCCESS, fail_fxs); - TRY_OR_DIE(PKH_PHONE_Start(chan_data->handle), PK_SUCCESS, fail_fxs); - - goto ok; + PKH_TPhoneConfig phoneConfig; - - fail_fxs: - zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); - zap_log(ZAP_LOG_ERROR, "Error: PKH_PHONE_Open %u failed(%s)!\n", x, - PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - if (chan_data->handle) { - PKH_PHONE_Close(chan_data->handle); + 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; + TRY_OR_DIE(PKH_PHONE_SetConfig(chan_data->handle, &phoneConfig), PK_SUCCESS, error); } - PKH_QUEUE_Destroy(chan_data->media_in_queue); - free(chan_data); - } - ok: + 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); + 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; @@ -377,13 +461,16 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data->play_config.AGC = profile->play_config.AGC; chan_data->ec_enabled = profile->ec_enabled; chan_data->ec_config = profile->ec_config; + 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; } 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->mod_data = chan_data; chan->physical_span_id = spanno; chan->physical_chan_id = x; @@ -448,10 +535,9 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) bd = item_list[i]; if ((sp = strchr(bd, ':'))) { *sp++ = '\0'; - } - - if ((ch = strchr(sp, ':'))) { - *ch++ = '\0'; + if ((ch = strchr(sp, ':'))) { + *ch++ = '\0'; + } } if (!(bd && sp && ch)) { @@ -504,8 +590,18 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) static ZIO_OPEN_FUNCTION(pika_open) { pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; - PKH_QUEUE_Flush(chan_data->media_in_queue); - PKH_PLAY_Start(chan_data->media_out); + + 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; } @@ -519,11 +615,15 @@ 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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + 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) { @@ -535,8 +635,8 @@ static ZIO_WAIT_FUNCTION(pika_wait) return ZAP_SUCCESS; } - PKH_EVENT_GetText(chan_data->last_media_event.id, g_EventText, sizeof(g_EventText)); - zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + 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; @@ -546,7 +646,16 @@ static ZIO_READ_FUNCTION(pika_read) { pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; PK_STATUS status; - PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH]; + + 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 (zchan->packet_len < *datalen) { *datalen = zchan->packet_len; @@ -557,14 +666,22 @@ static ZIO_READ_FUNCTION(pika_read) } - PKH_ERROR_GetText(status, g_EventText, sizeof(g_EventText)); - zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", g_EventText); + PKH_ERROR_GetText(status, event_text, sizeof(event_text)); + zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", event_text); return ZAP_FAIL; } 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; @@ -706,22 +823,93 @@ 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 = span_data->last_oob_event.userData; - //PK_CHAR g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + 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; } - - //PKH_EVENT_GetText(span_data->last_oob_event.id, g_EventText, sizeof(g_EventText)); - //zap_log(ZAP_LOG_DEBUG, "Event: %s\n", g_EventText); + 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; @@ -740,18 +928,16 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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 g_EventText[PKH_EVENT_MAX_NAME_LENGTH]; + 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, g_EventText, sizeof(g_EventText)); - zap_log(ZAP_LOG_DEBUG, "Event %d on channel %d:%d [%s]\n", - chan_data->last_oob_event.id, - span->channels[i].span_id, - span->channels[i].chan_id, - g_EventText); + 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; @@ -774,6 +960,79 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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 : @@ -783,7 +1042,7 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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, g_EventText); + 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; } @@ -816,16 +1075,34 @@ 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 (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { - PKH_QUEUE_Detach(span_data->event_queue, chan_data->handle); - PKH_TRUNK_Close(chan_data->handle); + + if (!chan_data) { + return ZAP_FAIL; } + 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); zap_safe_free(chan_data); @@ -853,6 +1130,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) assert(zint != 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); @@ -884,12 +1162,22 @@ zap_status_t pika_init(zap_io_interface_t **zint) 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 tmp, tmp2; + PKH_BOARD_Open(globals.board_list.board[i].id, NULL, &tmp); + PKH_SPAN_Open(tmp, 0, NULL, &tmp2); + PKH_SPAN_GetConfig(tmp2, &globals.span_config); + PKH_SPAN_Close(tmp2); + PKH_BOARD_Close(tmp); + } ok++; } From e01c1022bbbc25ba49114c65865f88531a0dafc2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 22 Nov 2007 09:28:40 +0000 Subject: [PATCH 0679/1766] Add files for 5ess Dialect, numerous formatting and typo fixes. MODENDP-43 and MODENDP-44. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@346 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 6 + libs/openzap/msvc/openzap.vcproj | 16 + libs/openzap/src/isdn/5ESSStateNT.c | 129 ++++++++ libs/openzap/src/isdn/5ESSStateTE.c | 295 +++++++++++++++++ libs/openzap/src/isdn/5ESSmes.c | 341 ++++++++++++++++++++ libs/openzap/src/isdn/DMSStateTE.c | 4 +- libs/openzap/src/isdn/Q931.c | 457 ++++++++++++++------------- libs/openzap/src/isdn/Q931api.c | 2 +- libs/openzap/src/isdn/include/5ESS.h | 103 ++++++ libs/openzap/src/isdn/include/Q931.h | 157 ++++----- 10 files changed, 1206 insertions(+), 304 deletions(-) create mode 100644 libs/openzap/src/isdn/5ESSStateNT.c create mode 100644 libs/openzap/src/isdn/5ESSStateTE.c create mode 100644 libs/openzap/src/isdn/5ESSmes.c create mode 100644 libs/openzap/src/isdn/include/5ESS.h diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 94883699c5..e90992406f 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -61,6 +61,9 @@ $(SRC)/isdn/nationalStateTE.o \ $(SRC)/isdn/DMSmes.o \ $(SRC)/isdn/DMSStateNT.o \ $(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o @@ -90,6 +93,8 @@ $(SRC)/include/zap_wanpipe.h \ $(SRC)/include/zap_zt.h \ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ $(SRC)/isdn/include/Q921.h \ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ @@ -180,3 +185,4 @@ clean: mod_openzap-clean rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index a4cf1d6ea4..10c7e5a912 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -162,6 +162,10 @@ + + @@ -194,6 +198,18 @@ + + + + + + diff --git a/libs/openzap/src/isdn/5ESSStateNT.c b/libs/openzap/src/isdn/5ESSStateNT.c new file mode 100644 index 0000000000..5ba4ca8f79 --- /dev/null +++ b/libs/openzap/src/isdn/5ESSStateNT.c @@ -0,0 +1,129 @@ +/***************************************************************************** + + 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); + + /* 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 new file mode 100644 index 0000000000..05a11b0c5c --- /dev/null +++ b/libs/openzap/src/isdn/5ESSStateTE.c @@ -0,0 +1,295 @@ +/***************************************************************************** + + 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, 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_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: ATT5ESSProc0x0fTE + +*****************************************************************************/ +L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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 new file mode 100644 index 0000000000..6a6f4684d1 --- /dev/null +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -0,0 +1,341 @@ +/***************************************************************************** + + 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_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: 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 */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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/DMSStateTE.c b/libs/openzap/src/isdn/DMSStateTE.c index e508e1ce53..565841589e 100644 --- a/libs/openzap/src/isdn/DMSStateTE.c +++ b/libs/openzap/src/isdn/DMSStateTE.c @@ -1,8 +1,8 @@ /***************************************************************************** - FileName: nationalStateTE.c + FileName: DMSStateTE.c - Contents: National ISDN State Engine for TE (User Mode). + 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 diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 098c1a44b3..316390c492 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -3,7 +3,7 @@ FileName: Q931.c Contents: Implementation of Q.931 stack main interface functions. - See q931.h for description. + See q931.h for description. License/Copyright: @@ -15,13 +15,13 @@ met: * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 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. + 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. + 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 @@ -39,6 +39,8 @@ #include "Q931.h" #include "national.h" #include "DMS.h" +#include "5ESS.h" + /***************************************************************************** @@ -50,7 +52,7 @@ 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 dielects as it treats User + 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 @@ -68,8 +70,8 @@ q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE]; void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)= { - NULL, - NULL + NULL, + NULL }; Q931State Q931st[Q931MAXSTATE]; @@ -80,7 +82,7 @@ Q931State Q931st[Q931MAXSTATE]; *****************************************************************************/ -L3INT Q931L4HeaderSpace={0}; /* header space to be ignoder/inserted */ +L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */ /* at head of each message. */ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ @@ -92,7 +94,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ *****************************************************************************/ Q931ErrorCB_t Q931ErrorProc; - /* callback for error messages. */ + /* callback for error messages. */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ @@ -128,7 +130,7 @@ void Q931SetL2HeaderSpace(L3INT space) /***************************************************************************** - Function: Q931 + Function: Q931ProcDummy Description: Dummy function for message processing. @@ -140,7 +142,7 @@ L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) /***************************************************************************** - Function: Q931 + Function: Q931UmesDummy Description: Dummy function for message processing @@ -152,7 +154,7 @@ L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBu /***************************************************************************** - Function: Q931 + Function: Q931UieDummy Description: Dummy function for message processing @@ -164,7 +166,7 @@ L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IB /***************************************************************************** - Function: Q931 + Function: Q931PmesDummy Description: Dummy function for message processing @@ -207,7 +209,7 @@ L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n) *****************************************************************************/ L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) { - return 0; + return 0; } /***************************************************************************** @@ -218,7 +220,7 @@ L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) Will set up the trunk array, channel arrays and initialize Q931 function arrays before it finally - set up EuroISDN processing with User as diealect 0 and + set up EuroISDN processing with User as dialect 0 and Network as dialect 1. Note: Initialization of other stacks should be inserted after @@ -229,53 +231,59 @@ void Q931Initialize() { L3INT x,y; - /* Secure the callbacks to default procs */ + /* 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++) + /* 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 0 : Warning - see q931errors.h for details. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) { L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; + L3INT RetCode = Q931E_NO_ERROR; Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; L3INT ISize; @@ -336,42 +344,44 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->ProtDisc = Mes[IOff++]; /* CRV */ - m->CRVFlag = Mes[IOff + 1] & 0x80; + m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); /* Message Type */ m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); + /*debug */ + /* printf("\n\nQ931Rx23- Dialect: %d, MsgType: %d\n",pTrunk->Dialect,m->MesType); */ + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); - if(RetCode >= Q931E_NO_ERROR) - { - RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); - } + if(RetCode >= Q931E_NO_ERROR) + { + RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + } return RetCode; } /***************************************************************************** - Function: Q931Tx34 + Function: Q931Tx34 - Description: Called from the stac to send a message to layer 4. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { - if (pTrunk->Q931Tx34CBProc) { - return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); - } - return Q931E_MISSING_CB; + if (pTrunk->Q931Tx34CBProc) { + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); + } + return Q931E_MISSING_CB; } /***************************************************************************** @@ -385,52 +395,52 @@ L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) Size[IN] Message size in bytes. Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning - see q931errors.h for details. + 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; + L3INT RetCode = Q931E_NO_ERROR; - RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); return RetCode; } /***************************************************************************** - Function: Q931Tx32 + Function: Q931Tx32 - Description: Called from the stack to send a message to L2. The input is + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { L3INT OSize; Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; - L3INT RetCode = Q931E_NO_ERROR; + L3INT RetCode = Q931E_NO_ERROR; L3INT iDialect = pTrunk->Dialect; /* Call pack function through table. */ RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { - if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); - } else { - RetCode = Q931E_MISSING_CB; - } + if(RetCode >= Q931E_NO_ERROR) + { + if (pTrunk->Q931Tx32CBProc) { + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); + } else { + RetCode = Q931E_MISSING_CB; + } } return RetCode; @@ -439,23 +449,23 @@ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) /***************************************************************************** - Function: Q931SetError + Function: Q931SetError - Description: Called from the stack to indicate an error. + Description: Called from the stack to indicate an error. - Parameters: ErrID ID of ie or message causing error. - ErrPar1 Error parameter 1 + 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); - } + if (pTrunk->Q931ErrorCBProc) { + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } else { + Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } } void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) @@ -465,58 +475,58 @@ void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) /***************************************************************************** - Function: Q931CreateCRV + 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. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ -L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) { - L3INT CRV = Q931GetUniqueCRV(pTrunk); + L3INT CRV = Q931GetUniqueCRV(pTrunk); - return Q931AllocateCRV(pTrunk, CRV, callIndex); + return Q931AllocateCRV(pTrunk, CRV, callIndex); } /***************************************************************************** - Function: Q931AllocateCRV + Function: Q931AllocateCRV - Description: Allocate a call table entry and assigns the given CRV value - to it. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ -L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) +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 */ + 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; } @@ -527,19 +537,19 @@ L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) 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 + Parameters: pTrunk [IN] Trunk number. + iCRV [IN] CRV Return Value: Call State. *****************************************************************************/ -L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) +L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) { L3INT x; - for(x=0; x < Q931MAXCALLPERTRUNK; x++) - { - if(pTrunk->call[x].InUse) - { + for(x=0; x < Q931MAXCALLPERTRUNK; x++) + { + if(pTrunk->call[x].InUse) + { if(pTrunk->call[x].CRV == iCRV) { return pTrunk->call[x].State; @@ -589,9 +599,9 @@ L3ULONG Q931GetTime() tNow = Q931GetTimeProc(); if(tNow < tLast) /* wrapped */ { - /* TODO */ + /* TODO */ } - tLast = tNow; + tLast = tNow; } return tNow; } @@ -604,10 +614,10 @@ void Q931SetGetTimeCB(L3ULONG (*callback)()) L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex) { L3INT x; - for(x=0; x < Q931MAXCALLPERTRUNK; x++) - { - if(pTrunk->call[x].InUse) - { + for(x=0; x < Q931MAXCALLPERTRUNK; x++) + { + if(pTrunk->call[x].InUse) + { if(pTrunk->call[x].CRV == crv) { *callindex = x; @@ -621,101 +631,101 @@ L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex) void Q931AddDialect(L3UCHAR i, void (*callback)(L3UCHAR iD )) { - if(i < Q931MAXDLCT) - { - Q931CreateDialectCB[i] = callback; - } + if(i < Q931MAXDLCT) + { + Q931CreateDialectCB[i] = callback; + } } /***************************************************************************** - Function: Q931AddStateEntry + Function: Q931AddStateEntry - Description: Find an empty entry in the dialects state table and add this - entry. + Description: Find an empty entry in the dialects state table and add this + entry. *****************************************************************************/ -void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) +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; - } - } + 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 + Function: Q931IsEventLegal - Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + 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 - sequensial is ok for now. + 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; + 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() + Function: q931_error_to_name() - Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + 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 - sequensial is ok for now. + 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_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 */ + "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 */ }; @@ -723,13 +733,14 @@ static const char *q931_error_names[] = { 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]; + 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]; } + diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index d1ec028a04..9a3084c2c3 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -578,4 +578,4 @@ L3INT Q931AckService(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) } Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS) -Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) +Q931_STR2ENUM(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/openzap/src/isdn/include/5ESS.h b/libs/openzap/src/isdn/include/5ESS.h new file mode 100644 index 0000000000..dd364ed537 --- /dev/null +++ b/libs/openzap/src/isdn/include/5ESS.h @@ -0,0 +1,103 @@ +/****************************************************************************** + + 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/Q931.h b/libs/openzap/src/isdn/include/Q931.h index ee92e48b26..f8592ddc2d 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -3,75 +3,75 @@ FileName: Q931.h Contents: Header and definition for the ITU-T Q.931 stack. The - header contents the following parts: + header contents the following parts: - - Definition of codes + - Definition of codes - Definition of information elements (Q931ie_). - Definition of messages (Q931mes_). - Definitian of variables (var_). - - Function prototypes. + - 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. + 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: + 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. + - 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. + 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. + 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 + 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 + 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: + 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. + .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. + 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. + 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. + 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: @@ -123,7 +123,7 @@ /***************************************************************************** - Enum helper macros + Enum helper macros *****************************************************************************/ #define Q931_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; @@ -200,11 +200,11 @@ 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 have to do a lot of extra + 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 ressult in usage of some extra space, but speed up the stack. + will result in usage of some extra space, but will speed up the stack. - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + The stack has been designed to allow L3UCHAR etc. to be any size of 8 bit or larger. *****************************************************************************/ @@ -233,7 +233,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ /* value for single octet ) to the */ /* struct holding the ie. Offset = 0 */ /* is buf[1] etc. */ - /* ie == 0xffff indicate error */ + /* ie == 0xffff indicates error */ /***************************************************************************** @@ -268,8 +268,8 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ 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 schoose to use - the proc etc for standard Q.931 or insert a modified proc. + 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. @@ -283,7 +283,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 6 /* Max dialects included in this */ +#define Q931MAXDLCT 8 /* Max dialects included in this */ /* compile. User and Network count as */ /* one dialect each. */ @@ -294,9 +294,9 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #define Q931MAXUSEDIE 50 /* Maximum number of ie types per Dialect */ -#define Q931MAXCODESETS 7 /* Maximum number of codests (by spec, 0-7 */ +#define Q931MAXCODESETS 7 /* Maximum number of codests (by spec, 0-7) */ -#define Q931MAXSTATE 100 /* Size of state tables */ +#define Q931MAXSTATE 100 /* Size of state tables */ /***************************************************************************** @@ -336,14 +336,14 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #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) +#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) /***************************************************************************** @@ -469,12 +469,12 @@ typedef struct Struct: Q931_TrunkInfo Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated + information and state for E1/T1/J1 trunks and associated channels in the system. The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. + and needs to feed the interface functions with a pointer to + the TrunkInfo entry. *****************************************************************************/ typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; @@ -490,14 +490,15 @@ typedef enum /* Network/User Mode. */ typedef enum /* Dialect enum */ { - Q931_Dialect_Q931 = 0, + Q931_Dialect_Q931 = 0, Q931_Dialect_National = 2, - Q931_Dialect_DMS = 4, + 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" -Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, 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. */ { @@ -516,7 +517,7 @@ typedef enum /* Trunk State */ typedef enum { Q931_ChType_NotUsed=0, /* Unused Channel */ - Q931_ChType_B=1, /* B Channel (Voice) */ + Q931_ChType_B=1, /* B Channel (Voice) */ Q931_ChType_D=2, /* D Channel (Signalling) */ Q931_ChType_Sync=3 /* Sync Channel */ } Q931_ChanType_t; @@ -525,7 +526,7 @@ struct Q931_TrunkInfo { Q931NetUser_t NetUser; /* Network/User Mode. */ - Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ + Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ @@ -549,7 +550,7 @@ struct Q931_TrunkInfo 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 send by the stack in response to SETUP to buy */ + /* 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. */ @@ -618,8 +619,8 @@ struct Q931_TrunkInfo Description: Define a Q931 State, legal events and next state for each event. Used to simplify the state engine logic. Each state - engine define it's own state table and the logic only need - to call a helper function to check if the message is legal + 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. *****************************************************************************/ From 3f2097c49b3a43eadc2bbc71dc4d6aaf693c6ab7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 22 Nov 2007 09:28:40 +0000 Subject: [PATCH 0680/1766] Add files for 5ess Dialect, numerous formatting and typo fixes. MODENDP-43 and MODENDP-44. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@346 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 6 + libs/freetdm/msvc/openzap.vcproj | 16 + libs/freetdm/src/isdn/5ESSStateNT.c | 129 ++++++++ libs/freetdm/src/isdn/5ESSStateTE.c | 295 +++++++++++++++++ libs/freetdm/src/isdn/5ESSmes.c | 341 ++++++++++++++++++++ libs/freetdm/src/isdn/DMSStateTE.c | 4 +- libs/freetdm/src/isdn/Q931.c | 457 ++++++++++++++------------- libs/freetdm/src/isdn/Q931api.c | 2 +- libs/freetdm/src/isdn/include/5ESS.h | 103 ++++++ libs/freetdm/src/isdn/include/Q931.h | 157 ++++----- 10 files changed, 1206 insertions(+), 304 deletions(-) create mode 100644 libs/freetdm/src/isdn/5ESSStateNT.c create mode 100644 libs/freetdm/src/isdn/5ESSStateTE.c create mode 100644 libs/freetdm/src/isdn/5ESSmes.c create mode 100644 libs/freetdm/src/isdn/include/5ESS.h diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 94883699c5..e90992406f 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -61,6 +61,9 @@ $(SRC)/isdn/nationalStateTE.o \ $(SRC)/isdn/DMSmes.o \ $(SRC)/isdn/DMSStateNT.o \ $(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o @@ -90,6 +93,8 @@ $(SRC)/include/zap_wanpipe.h \ $(SRC)/include/zap_zt.h \ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ $(SRC)/isdn/include/Q921.h \ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ @@ -180,3 +185,4 @@ clean: mod_openzap-clean rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index a4cf1d6ea4..10c7e5a912 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -162,6 +162,10 @@ + + @@ -194,6 +198,18 @@ + + + + + + diff --git a/libs/freetdm/src/isdn/5ESSStateNT.c b/libs/freetdm/src/isdn/5ESSStateNT.c new file mode 100644 index 0000000000..5ba4ca8f79 --- /dev/null +++ b/libs/freetdm/src/isdn/5ESSStateNT.c @@ -0,0 +1,129 @@ +/***************************************************************************** + + 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); + + /* 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/freetdm/src/isdn/5ESSStateTE.c b/libs/freetdm/src/isdn/5ESSStateTE.c new file mode 100644 index 0000000000..05a11b0c5c --- /dev/null +++ b/libs/freetdm/src/isdn/5ESSStateTE.c @@ -0,0 +1,295 @@ +/***************************************************************************** + + 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, 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_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: ATT5ESSProc0x0fTE + +*****************************************************************************/ +L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,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) +{ + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + + 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, 303); + } + if(iFrom == 4) + { + /* TODO Add proc here*/ + ret = Q931Tx32(pTrunk,buf,pMes->Size); + } + else if (iFrom ==2) + { + /* TODO Add proc here*/ + ret = Q931Tx34(pTrunk,buf,pMes->Size); + } + return ret; + +} diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c new file mode 100644 index 0000000000..6a6f4684d1 --- /dev/null +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -0,0 +1,341 @@ +/***************************************************************************** + + 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_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: 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 */ + + OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ + OBuf[Octet++] = 2; /* length is 2 octets */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ + OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ + OBuf[Octet++] = pMes->MesType; /* message header */ + + /* 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/freetdm/src/isdn/DMSStateTE.c b/libs/freetdm/src/isdn/DMSStateTE.c index e508e1ce53..565841589e 100644 --- a/libs/freetdm/src/isdn/DMSStateTE.c +++ b/libs/freetdm/src/isdn/DMSStateTE.c @@ -1,8 +1,8 @@ /***************************************************************************** - FileName: nationalStateTE.c + FileName: DMSStateTE.c - Contents: National ISDN State Engine for TE (User Mode). + 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 diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 098c1a44b3..316390c492 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -3,7 +3,7 @@ FileName: Q931.c Contents: Implementation of Q.931 stack main interface functions. - See q931.h for description. + See q931.h for description. License/Copyright: @@ -15,13 +15,13 @@ met: * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 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. + 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. + 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 @@ -39,6 +39,8 @@ #include "Q931.h" #include "national.h" #include "DMS.h" +#include "5ESS.h" + /***************************************************************************** @@ -50,7 +52,7 @@ 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 dielects as it treats User + 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 @@ -68,8 +70,8 @@ q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE]; void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)= { - NULL, - NULL + NULL, + NULL }; Q931State Q931st[Q931MAXSTATE]; @@ -80,7 +82,7 @@ Q931State Q931st[Q931MAXSTATE]; *****************************************************************************/ -L3INT Q931L4HeaderSpace={0}; /* header space to be ignoder/inserted */ +L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */ /* at head of each message. */ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ @@ -92,7 +94,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ *****************************************************************************/ Q931ErrorCB_t Q931ErrorProc; - /* callback for error messages. */ + /* callback for error messages. */ L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ @@ -128,7 +130,7 @@ void Q931SetL2HeaderSpace(L3INT space) /***************************************************************************** - Function: Q931 + Function: Q931ProcDummy Description: Dummy function for message processing. @@ -140,7 +142,7 @@ L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) /***************************************************************************** - Function: Q931 + Function: Q931UmesDummy Description: Dummy function for message processing @@ -152,7 +154,7 @@ L3INT Q931UmesDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *OBu /***************************************************************************** - Function: Q931 + Function: Q931UieDummy Description: Dummy function for message processing @@ -164,7 +166,7 @@ L3INT Q931UieDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IB /***************************************************************************** - Function: Q931 + Function: Q931PmesDummy Description: Dummy function for message processing @@ -207,7 +209,7 @@ L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n) *****************************************************************************/ L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) { - return 0; + return 0; } /***************************************************************************** @@ -218,7 +220,7 @@ L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) Will set up the trunk array, channel arrays and initialize Q931 function arrays before it finally - set up EuroISDN processing with User as diealect 0 and + set up EuroISDN processing with User as dialect 0 and Network as dialect 1. Note: Initialization of other stacks should be inserted after @@ -229,53 +231,59 @@ void Q931Initialize() { L3INT x,y; - /* Secure the callbacks to default procs */ + /* 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++) + /* 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 0 : Warning - see q931errors.h for details. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) { L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; + L3INT RetCode = Q931E_NO_ERROR; Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; L3INT ISize; @@ -336,42 +344,44 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) m->ProtDisc = Mes[IOff++]; /* CRV */ - m->CRVFlag = Mes[IOff + 1] & 0x80; + m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); /* Message Type */ m->MesType = Mes[IOff++]; /* Call table proc to unpack codec message */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); + /*debug */ + /* printf("\n\nQ931Rx23- Dialect: %d, MsgType: %d\n",pTrunk->Dialect,m->MesType); */ + RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); - if(RetCode >= Q931E_NO_ERROR) - { - RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); - } + if(RetCode >= Q931E_NO_ERROR) + { + RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); + } return RetCode; } /***************************************************************************** - Function: Q931Tx34 + Function: Q931Tx34 - Description: Called from the stac to send a message to layer 4. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { - if (pTrunk->Q931Tx34CBProc) { - return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); - } - return Q931E_MISSING_CB; + if (pTrunk->Q931Tx34CBProc) { + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); + } + return Q931E_MISSING_CB; } /***************************************************************************** @@ -385,52 +395,52 @@ L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) Size[IN] Message size in bytes. Return Value: Error Code. 0 = No Error, < 0 :error, > 0 : Warning - see q931errors.h for details. + 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; + L3INT RetCode = Q931E_NO_ERROR; - RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); return RetCode; } /***************************************************************************** - Function: Q931Tx32 + Function: Q931Tx32 - Description: Called from the stack to send a message to L2. The input is + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) { L3INT OSize; Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; - L3INT RetCode = Q931E_NO_ERROR; + L3INT RetCode = Q931E_NO_ERROR; L3INT iDialect = pTrunk->Dialect; /* Call pack function through table. */ RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { - if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); - } else { - RetCode = Q931E_MISSING_CB; - } + if(RetCode >= Q931E_NO_ERROR) + { + if (pTrunk->Q931Tx32CBProc) { + RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); + } else { + RetCode = Q931E_MISSING_CB; + } } return RetCode; @@ -439,23 +449,23 @@ L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) /***************************************************************************** - Function: Q931SetError + Function: Q931SetError - Description: Called from the stack to indicate an error. + Description: Called from the stack to indicate an error. - Parameters: ErrID ID of ie or message causing error. - ErrPar1 Error parameter 1 + 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); - } + if (pTrunk->Q931ErrorCBProc) { + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } else { + Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } } void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) @@ -465,58 +475,58 @@ void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) /***************************************************************************** - Function: Q931CreateCRV + 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. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ -L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) { - L3INT CRV = Q931GetUniqueCRV(pTrunk); + L3INT CRV = Q931GetUniqueCRV(pTrunk); - return Q931AllocateCRV(pTrunk, CRV, callIndex); + return Q931AllocateCRV(pTrunk, CRV, callIndex); } /***************************************************************************** - Function: Q931AllocateCRV + Function: Q931AllocateCRV - Description: Allocate a call table entry and assigns the given CRV value - to it. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ -L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) +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 */ + 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; } @@ -527,19 +537,19 @@ L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) 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 + Parameters: pTrunk [IN] Trunk number. + iCRV [IN] CRV Return Value: Call State. *****************************************************************************/ -L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) +L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) { L3INT x; - for(x=0; x < Q931MAXCALLPERTRUNK; x++) - { - if(pTrunk->call[x].InUse) - { + for(x=0; x < Q931MAXCALLPERTRUNK; x++) + { + if(pTrunk->call[x].InUse) + { if(pTrunk->call[x].CRV == iCRV) { return pTrunk->call[x].State; @@ -589,9 +599,9 @@ L3ULONG Q931GetTime() tNow = Q931GetTimeProc(); if(tNow < tLast) /* wrapped */ { - /* TODO */ + /* TODO */ } - tLast = tNow; + tLast = tNow; } return tNow; } @@ -604,10 +614,10 @@ void Q931SetGetTimeCB(L3ULONG (*callback)()) L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex) { L3INT x; - for(x=0; x < Q931MAXCALLPERTRUNK; x++) - { - if(pTrunk->call[x].InUse) - { + for(x=0; x < Q931MAXCALLPERTRUNK; x++) + { + if(pTrunk->call[x].InUse) + { if(pTrunk->call[x].CRV == crv) { *callindex = x; @@ -621,101 +631,101 @@ L3INT Q931FindCRV(Q931_TrunkInfo_t *pTrunk, L3INT crv, L3INT *callindex) void Q931AddDialect(L3UCHAR i, void (*callback)(L3UCHAR iD )) { - if(i < Q931MAXDLCT) - { - Q931CreateDialectCB[i] = callback; - } + if(i < Q931MAXDLCT) + { + Q931CreateDialectCB[i] = callback; + } } /***************************************************************************** - Function: Q931AddStateEntry + Function: Q931AddStateEntry - Description: Find an empty entry in the dialects state table and add this - entry. + Description: Find an empty entry in the dialects state table and add this + entry. *****************************************************************************/ -void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir) +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; - } - } + 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 + Function: Q931IsEventLegal - Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + 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 - sequensial is ok for now. + 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; + 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() + Function: q931_error_to_name() - Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + 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 - sequensial is ok for now. + 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_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 */ + "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 */ }; @@ -723,13 +733,14 @@ static const char *q931_error_names[] = { 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]; + 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]; } + diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index d1ec028a04..9a3084c2c3 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -578,4 +578,4 @@ L3INT Q931AckService(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) } Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS) -Q931_STR2ENUM(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) +Q931_STR2ENUM(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t, DIALECT_TYPE_NAMES, Q931_Dialect_Count) diff --git a/libs/freetdm/src/isdn/include/5ESS.h b/libs/freetdm/src/isdn/include/5ESS.h new file mode 100644 index 0000000000..dd364ed537 --- /dev/null +++ b/libs/freetdm/src/isdn/include/5ESS.h @@ -0,0 +1,103 @@ +/****************************************************************************** + + 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/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index ee92e48b26..f8592ddc2d 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -3,75 +3,75 @@ FileName: Q931.h Contents: Header and definition for the ITU-T Q.931 stack. The - header contents the following parts: + header contents the following parts: - - Definition of codes + - Definition of codes - Definition of information elements (Q931ie_). - Definition of messages (Q931mes_). - Definitian of variables (var_). - - Function prototypes. + - 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. + 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: + 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. + - 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. + 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. + 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 + 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 + 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: + 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. + .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. + 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. + 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. + 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: @@ -123,7 +123,7 @@ /***************************************************************************** - Enum helper macros + Enum helper macros *****************************************************************************/ #define Q931_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; @@ -200,11 +200,11 @@ 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 have to do a lot of extra + 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 ressult in usage of some extra space, but speed up the stack. + will result in usage of some extra space, but will speed up the stack. - The stack have been designed to allow L3UCHAR etc. to be any size of 8 bit + The stack has been designed to allow L3UCHAR etc. to be any size of 8 bit or larger. *****************************************************************************/ @@ -233,7 +233,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ /* value for single octet ) to the */ /* struct holding the ie. Offset = 0 */ /* is buf[1] etc. */ - /* ie == 0xffff indicate error */ + /* ie == 0xffff indicates error */ /***************************************************************************** @@ -268,8 +268,8 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ 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 schoose to use - the proc etc for standard Q.931 or insert a modified proc. + 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. @@ -283,7 +283,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ /* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the */ /* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is */ /* not used. */ -#define Q931MAXDLCT 6 /* Max dialects included in this */ +#define Q931MAXDLCT 8 /* Max dialects included in this */ /* compile. User and Network count as */ /* one dialect each. */ @@ -294,9 +294,9 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #define Q931MAXUSEDIE 50 /* Maximum number of ie types per Dialect */ -#define Q931MAXCODESETS 7 /* Maximum number of codests (by spec, 0-7 */ +#define Q931MAXCODESETS 7 /* Maximum number of codests (by spec, 0-7) */ -#define Q931MAXSTATE 100 /* Size of state tables */ +#define Q931MAXSTATE 100 /* Size of state tables */ /***************************************************************************** @@ -336,14 +336,14 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #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) +#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) /***************************************************************************** @@ -469,12 +469,12 @@ typedef struct Struct: Q931_TrunkInfo Description: TrunkInfo is the struct entry used to store Q.931 related - information and state for E1/T1/J1 trunks and assosiated + information and state for E1/T1/J1 trunks and associated channels in the system. The user should store this information outside this stack - and need to feed the interface functions with a pointer to - the trunk Info entry. + and needs to feed the interface functions with a pointer to + the TrunkInfo entry. *****************************************************************************/ typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; @@ -490,14 +490,15 @@ typedef enum /* Network/User Mode. */ typedef enum /* Dialect enum */ { - Q931_Dialect_Q931 = 0, + Q931_Dialect_Q931 = 0, Q931_Dialect_National = 2, - Q931_Dialect_DMS = 4, + 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" -Q931_STR2ENUM_P(q931_str2Q931Diaelct_type, q931_Q931Diaelct_type2str, 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. */ { @@ -516,7 +517,7 @@ typedef enum /* Trunk State */ typedef enum { Q931_ChType_NotUsed=0, /* Unused Channel */ - Q931_ChType_B=1, /* B Channel (Voice) */ + Q931_ChType_B=1, /* B Channel (Voice) */ Q931_ChType_D=2, /* D Channel (Signalling) */ Q931_ChType_Sync=3 /* Sync Channel */ } Q931_ChanType_t; @@ -525,7 +526,7 @@ struct Q931_TrunkInfo { Q931NetUser_t NetUser; /* Network/User Mode. */ - Q931Dialect_t Dialect; /* Q.931 Based dielact index. */ + Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ @@ -549,7 +550,7 @@ struct Q931_TrunkInfo 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 send by the stack in response to SETUP to buy */ + /* 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. */ @@ -618,8 +619,8 @@ struct Q931_TrunkInfo Description: Define a Q931 State, legal events and next state for each event. Used to simplify the state engine logic. Each state - engine define it's own state table and the logic only need - to call a helper function to check if the message is legal + 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. *****************************************************************************/ From fcde65bbf25e0521f9dd73a67eabcadfa71425af Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 22 Nov 2007 15:59:31 +0000 Subject: [PATCH 0681/1766] MODENDP-47 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@347 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a712b500f3..292ac052e0 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1182,7 +1182,7 @@ static switch_status_t load_config(void) } else if (!strcasecmp(var, "mode")) { mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT; } else if (!strcasecmp(var, "dialect")) { - dialect = q931_str2Q931Diaelct_type(val); + dialect = q931_str2Q931Dialect_type(val); if (dialect == Q931_Dialect_Count) { dialect = Q931_Dialect_National; } From a78fc9115b78efe92d266a343e251268eb128dd6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 22 Nov 2007 15:59:31 +0000 Subject: [PATCH 0682/1766] MODENDP-47 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@347 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a712b500f3..292ac052e0 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1182,7 +1182,7 @@ static switch_status_t load_config(void) } else if (!strcasecmp(var, "mode")) { mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT; } else if (!strcasecmp(var, "dialect")) { - dialect = q931_str2Q931Diaelct_type(val); + dialect = q931_str2Q931Dialect_type(val); if (dialect == Q931_Dialect_Count) { dialect = Q931_Dialect_National; } From fc327a23082ae92562c4d1a2a3cbe8cdb102a894 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 16:08:05 +0000 Subject: [PATCH 0683/1766] tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@349 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_pika.h | 10 +++++----- libs/openzap/src/zap_pika.c | 31 ++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/include/zap_pika.h b/libs/openzap/src/include/zap_pika.h index c30f98cbb3..a98c08cbe6 100644 --- a/libs/openzap/src/include/zap_pika.h +++ b/libs/openzap/src/include/zap_pika.h @@ -87,12 +87,12 @@ typedef enum { ZAP_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) typedef enum { - PIKA_SPAN_COMMAND_MODE_MU_LAW = 1, - PIKA_SPAN_COMMAND_MODE_A_LAW, - PIKA_SPAN_COMMAND_MODE_INVALID + PIKA_SPAN_COMPAND_MODE_MU_LAW = 1, + PIKA_SPAN_COMPAND_MODE_A_LAW, + PIKA_SPAN_COMPAND_MODE_INVALID } PIKA_TSpanCompandMode; -#define PIKA_SPAN_COMMAND_MODE_STRINGS "MU_LAW", "A_LAW" -ZAP_STR2ENUM_P(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode) +#define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW" +ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) /* Openzap PIKA hardware interface functions */ diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 8644b4acd5..47afa9f6b3 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -54,8 +54,8 @@ ZAP_STR2ENUM(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength, P ZAP_ENUM_NAMES(PIKA_LBO_NAMES, PIKA_LBO_STRINGS) ZAP_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID) -ZAP_ENUM_NAMES(PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_MODE_STRINGS) -ZAP_STR2ENUM(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_MODE_INVALID) +ZAP_ENUM_NAMES(PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_STRINGS) +ZAP_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID) typedef enum { @@ -220,6 +220,8 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) profile->span_config.loopLength = pika_str2loop_length(val); } else if (!strcasecmp(var, "buildOut")) { profile->span_config.buildOut = pika_str2lbo(val); + } else if (!strcasecmp(var, "compandMode")) { + profile->span_config.compandMode = pika_str2compand_mode(val); } else if (!strcasecmp(var, "region")) { if (!strcasecmp(val, "eu")) { profile->general_config.region = PKH_TRUNK_EU; @@ -377,7 +379,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; } @@ -396,7 +401,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); @@ -465,12 +473,20 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; } + if (type == ZAP_CHAN_TYPE_B) { + if (span_data->span_config.compandMode == PKH_SPAN_COMPAND_MODE_MU_LAW) { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + } else { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + } + } + 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; @@ -647,6 +663,7 @@ 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) { @@ -657,8 +674,12 @@ static ZIO_READ_FUNCTION(pika_read) return ZAP_FAIL; } - if (zchan->packet_len < *datalen) { - *datalen = zchan->packet_len; + 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) { From 255071deb3c0c7b866450bacefbc8cf1891f21eb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 16:08:05 +0000 Subject: [PATCH 0684/1766] tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@349 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_pika.h | 10 +++++----- libs/freetdm/src/zap_pika.c | 31 ++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/include/zap_pika.h b/libs/freetdm/src/include/zap_pika.h index c30f98cbb3..a98c08cbe6 100644 --- a/libs/freetdm/src/include/zap_pika.h +++ b/libs/freetdm/src/include/zap_pika.h @@ -87,12 +87,12 @@ typedef enum { ZAP_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) typedef enum { - PIKA_SPAN_COMMAND_MODE_MU_LAW = 1, - PIKA_SPAN_COMMAND_MODE_A_LAW, - PIKA_SPAN_COMMAND_MODE_INVALID + PIKA_SPAN_COMPAND_MODE_MU_LAW = 1, + PIKA_SPAN_COMPAND_MODE_A_LAW, + PIKA_SPAN_COMPAND_MODE_INVALID } PIKA_TSpanCompandMode; -#define PIKA_SPAN_COMMAND_MODE_STRINGS "MU_LAW", "A_LAW" -ZAP_STR2ENUM_P(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode) +#define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW" +ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) /* Openzap PIKA hardware interface functions */ diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 8644b4acd5..47afa9f6b3 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -54,8 +54,8 @@ ZAP_STR2ENUM(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength, P ZAP_ENUM_NAMES(PIKA_LBO_NAMES, PIKA_LBO_STRINGS) ZAP_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID) -ZAP_ENUM_NAMES(PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_MODE_STRINGS) -ZAP_STR2ENUM(pika_str2command_mode, pika_command_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMMAND_MODE_NAMES, PIKA_SPAN_COMMAND_MODE_INVALID) +ZAP_ENUM_NAMES(PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_STRINGS) +ZAP_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID) typedef enum { @@ -220,6 +220,8 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) profile->span_config.loopLength = pika_str2loop_length(val); } else if (!strcasecmp(var, "buildOut")) { profile->span_config.buildOut = pika_str2lbo(val); + } else if (!strcasecmp(var, "compandMode")) { + profile->span_config.compandMode = pika_str2compand_mode(val); } else if (!strcasecmp(var, "region")) { if (!strcasecmp(val, "eu")) { profile->general_config.region = PKH_TRUNK_EU; @@ -377,7 +379,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; } @@ -396,7 +401,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); @@ -465,12 +473,20 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; } + if (type == ZAP_CHAN_TYPE_B) { + if (span_data->span_config.compandMode == PKH_SPAN_COMPAND_MODE_MU_LAW) { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + } else { + chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + } + } + 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; @@ -647,6 +663,7 @@ 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) { @@ -657,8 +674,12 @@ static ZIO_READ_FUNCTION(pika_read) return ZAP_FAIL; } - if (zchan->packet_len < *datalen) { - *datalen = zchan->packet_len; + 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) { From 06e51c310b2c087c4a0dbdd1814cf2b6bac8d5e5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 17:05:04 +0000 Subject: [PATCH 0685/1766] more tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@350 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/pika.conf | 2 + libs/openzap/src/zap_pika.c | 83 ++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/libs/openzap/conf/pika.conf b/libs/openzap/conf/pika.conf index 418be1d289..8cc8d9c11d 100644 --- a/libs/openzap/conf/pika.conf +++ b/libs/openzap/conf/pika.conf @@ -8,6 +8,8 @@ ; fxs-channel => 1:0:1-12@default [default] +; region is na or eu +;region => na ;rx-gain => 0.00 ;rx-agc-enabled => false ;rx-agc-targetPower => -15.00 diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 47afa9f6b3..9d79641dc0 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -76,6 +76,7 @@ struct pika_channel_profile { 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; @@ -87,7 +88,8 @@ static struct { PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; PKH_TECConfig ec_config; - PKH_TSpanConfig span_config; + PKH_TSpanConfig t1_span_config; + PKH_TSpanConfig e1_span_config; zap_hash_t *profile_hash; general_config_t general_config; } globals; @@ -147,7 +149,6 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); profile->ec_config = globals.ec_config; - profile->span_config = globals.span_config; profile->record_config = globals.record_config; profile->play_config = globals.play_config; hashtable_insert(globals.profile_hash, (void *)profile->name, profile); @@ -214,14 +215,19 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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; @@ -352,10 +358,13 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa if ((type == ZAP_CHAN_TYPE_B || type == ZAP_CHAN_TYPE_DQ921) && !span_data->handle) { PKH_TBoardConfig boardConfig; - 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); 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)) { @@ -363,9 +372,16 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } } else if (span->trunk_type == ZAP_TRUNK_E1) { boardConfig.specific.DigitalGateway.interfaceType = PKH_BOARD_INTERFACE_TYPE_E1; - PKH_BOARD_SetConfig(globals.open_boards[boardno], &boardConfig); + 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) { @@ -433,6 +449,29 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); } @@ -469,18 +508,13 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data->play_config.AGC = profile->play_config.AGC; chan_data->ec_enabled = profile->ec_enabled; chan_data->ec_config = profile->ec_config; - 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; } if (type == ZAP_CHAN_TYPE_B) { - if (span_data->span_config.compandMode == PKH_SPAN_COMPAND_MODE_MU_LAW) { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; - } else { + 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; } } @@ -1192,12 +1226,21 @@ zap_status_t pika_init(zap_io_interface_t **zint) globals.board_list.board[i].serialNumber); if (globals.board_list.board[i].type == PKH_BOARD_TYPE_DIGITAL_GATEWAY) { - TPikaHandle tmp, tmp2; - PKH_BOARD_Open(globals.board_list.board[i].id, NULL, &tmp); - PKH_SPAN_Open(tmp, 0, NULL, &tmp2); - PKH_SPAN_GetConfig(tmp2, &globals.span_config); - PKH_SPAN_Close(tmp2); - PKH_BOARD_Close(tmp); + 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++; From 5a3c1ad7521ce055f36206e724d5205a695678de Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 17:05:04 +0000 Subject: [PATCH 0686/1766] more tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@350 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/pika.conf | 2 + libs/freetdm/src/zap_pika.c | 83 ++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index 418be1d289..8cc8d9c11d 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -8,6 +8,8 @@ ; fxs-channel => 1:0:1-12@default [default] +; region is na or eu +;region => na ;rx-gain => 0.00 ;rx-agc-enabled => false ;rx-agc-targetPower => -15.00 diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 47afa9f6b3..9d79641dc0 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -76,6 +76,7 @@ struct pika_channel_profile { 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; @@ -87,7 +88,8 @@ static struct { PKH_TRecordConfig record_config; PKH_TPlayConfig play_config; PKH_TECConfig ec_config; - PKH_TSpanConfig span_config; + PKH_TSpanConfig t1_span_config; + PKH_TSpanConfig e1_span_config; zap_hash_t *profile_hash; general_config_t general_config; } globals; @@ -147,7 +149,6 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); profile->ec_config = globals.ec_config; - profile->span_config = globals.span_config; profile->record_config = globals.record_config; profile->play_config = globals.play_config; hashtable_insert(globals.profile_hash, (void *)profile->name, profile); @@ -214,14 +215,19 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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; @@ -352,10 +358,13 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa if ((type == ZAP_CHAN_TYPE_B || type == ZAP_CHAN_TYPE_DQ921) && !span_data->handle) { PKH_TBoardConfig boardConfig; - 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); 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)) { @@ -363,9 +372,16 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } } else if (span->trunk_type == ZAP_TRUNK_E1) { boardConfig.specific.DigitalGateway.interfaceType = PKH_BOARD_INTERFACE_TYPE_E1; - PKH_BOARD_SetConfig(globals.open_boards[boardno], &boardConfig); + 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) { @@ -433,6 +449,29 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); } @@ -469,18 +508,13 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data->play_config.AGC = profile->play_config.AGC; chan_data->ec_enabled = profile->ec_enabled; chan_data->ec_config = profile->ec_config; - 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; } if (type == ZAP_CHAN_TYPE_B) { - if (span_data->span_config.compandMode == PKH_SPAN_COMPAND_MODE_MU_LAW) { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; - } else { + 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; } } @@ -1192,12 +1226,21 @@ zap_status_t pika_init(zap_io_interface_t **zint) globals.board_list.board[i].serialNumber); if (globals.board_list.board[i].type == PKH_BOARD_TYPE_DIGITAL_GATEWAY) { - TPikaHandle tmp, tmp2; - PKH_BOARD_Open(globals.board_list.board[i].id, NULL, &tmp); - PKH_SPAN_Open(tmp, 0, NULL, &tmp2); - PKH_SPAN_GetConfig(tmp2, &globals.span_config); - PKH_SPAN_Close(tmp2); - PKH_BOARD_Close(tmp); + 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++; From e27ac53847eff6842c33eef6acc888e75b93b143 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 18:09:44 +0000 Subject: [PATCH 0687/1766] off by 1 err pointed out by trixter from irc git-svn-id: http://svn.openzap.org/svn/openzap/trunk@351 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 6b262252bb..fdf4dd14f7 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -106,7 +106,7 @@ int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) teletone_process_t x = 0; va_start(ap, index); - while (i <= TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { + while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { ts->TONES[index].freqs[i++] = x; } va_end(ap); @@ -122,7 +122,7 @@ int teletone_set_map(teletone_tone_map_t *map, ...) teletone_process_t x = 0; va_start(ap, map); - while (i <= TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { + while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { map->freqs[i++] = x; } va_end(ap); From 1a94caa44905776af6a7da1fa0df24be6e04edad Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Nov 2007 18:09:44 +0000 Subject: [PATCH 0688/1766] off by 1 err pointed out by trixter from irc git-svn-id: http://svn.openzap.org/svn/openzap/trunk@351 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 6b262252bb..fdf4dd14f7 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -106,7 +106,7 @@ int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) teletone_process_t x = 0; va_start(ap, index); - while (i <= TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { + while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { ts->TONES[index].freqs[i++] = x; } va_end(ap); @@ -122,7 +122,7 @@ int teletone_set_map(teletone_tone_map_t *map, ...) teletone_process_t x = 0; va_start(ap, map); - while (i <= TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { + while (i < TELETONE_MAX_TONES && (x = va_arg(ap, teletone_process_t))) { map->freqs[i++] = x; } va_end(ap); From e728218e2ff6540e3e46ea352a0b4c0d54b55f9c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 24 Nov 2007 18:04:14 +0000 Subject: [PATCH 0689/1766] add dial regexs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@352 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/openzap.conf.xml | 8 ++- libs/openzap/mod_openzap/mod_openzap.c | 79 ++++++++++++++++++++++---- libs/openzap/src/include/openzap.h | 2 + libs/openzap/src/include/zap_types.h | 6 +- libs/openzap/src/zap_analog.c | 13 ++++- libs/openzap/src/zap_io.c | 8 +++ libs/openzap/src/zap_isdn.c | 4 +- 7 files changed, 101 insertions(+), 19 deletions(-) diff --git a/libs/openzap/conf/openzap.conf.xml b/libs/openzap/conf/openzap.conf.xml index be802f9f5f..45780e9787 100644 --- a/libs/openzap/conf/openzap.conf.xml +++ b/libs/openzap/conf/openzap.conf.xml @@ -5,10 +5,14 @@ - - + + + + + + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 292ac052e0..3f322039a2 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -35,7 +35,8 @@ #include "zap_isdn.h" SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); -SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, NULL, NULL); +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); +SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); switch_endpoint_interface_t *openzap_endpoint_interface; @@ -46,6 +47,9 @@ struct span_config { zap_span_t *span; char dialplan[80]; char context[80]; + char dial_regex[256]; + char fail_dial_regex[256]; + }; static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; @@ -974,6 +978,42 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) cycle_foreground(sigmsg->channel, 1); } break; + + case ZAP_SIGEVENT_COLLECTED_DIGIT: + { + char *dtmf = sigmsg->raw_data; + char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; + char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; + + if (switch_strlen_zero(regex)) { + regex = NULL; + } + + if (switch_strlen_zero(fail_regex)) { + fail_regex = NULL; + } + + if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { + switch_regex_t *re = NULL; + int ovector[30]; + int match = 0; + + if (fail_regex) { + match = switch_regex_perform(dtmf, fail_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_SUCCESS : ZAP_BREAK; + switch_regex_safe_free(re); + } + + if (status == ZAP_SUCCESS && regex) { + match = switch_regex_perform(dtmf, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_BREAK : ZAP_SUCCESS; + } + + switch_regex_safe_free(re); + } + + } + break; } return status; @@ -1036,15 +1076,17 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { + switch_status_t status; + switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: { - on_fxo_signal(sigmsg); + status = on_fxo_signal(sigmsg); } break; case ZAP_CHAN_TYPE_FXS: { - on_fxs_signal(sigmsg); + status = on_fxs_signal(sigmsg); } break; default: @@ -1055,7 +1097,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) break; } - return ZAP_SUCCESS; + return status; } static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) @@ -1105,6 +1147,8 @@ static switch_status_t load_config(void) char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; + char *dial_regex = NULL; + char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; @@ -1114,13 +1158,17 @@ static switch_status_t load_config(void) if (!strcasecmp(var, "tonegroup")) { tonegroup = val; - } else if (!strcasecmp(var, "digit_timeout")) { + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { digit_timeout = val; } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; - } else if (!strcasecmp(var, "max_digits")) { + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { digit_timeout = val; } } @@ -1154,10 +1202,17 @@ static switch_status_t load_config(void) } SPAN_CONFIG[span->span_id].span = span; - switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); - switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_set_string(SPAN_CONFIG[span->span_id].context, context); + switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan); + + if (dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); + } + + if (fail_dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); + } - zap_analog_start(span); } } @@ -1255,7 +1310,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) return SWITCH_STATUS_SUCCESS; } - +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) +{ + zap_global_destroy(); + return SWITCH_STATUS_SUCCESS; +} /* For Emacs: * Local Variables: diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index a9209ad8c2..14b46b7167 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -518,6 +518,8 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); +uint32_t zap_running(void); + ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 8be5007779..aac07d19f4 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -180,10 +180,11 @@ typedef enum { ZAP_SIGEVENT_ALARM_TRAP, ZAP_SIGEVENT_ALARM_CLEAR, ZAP_SIGEVENT_MISC, + ZAP_SIGEVENT_COLLECTED_DIGIT, 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", "INVALID" + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -205,7 +206,8 @@ typedef enum { ZAP_TIMEOUT, ZAP_NOTIMPL, ZAP_CHECKSUM_ERROR, - ZAP_STATUS_COUNT + ZAP_STATUS_COUNT, + ZAP_BREAK } zap_status_t; typedef enum { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index bc02794acd..2cb06d0d91 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -177,7 +177,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; + 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; @@ -490,17 +490,24 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); + collecting = 1; } dtmf_offset = strlen(dtmf); last_digit = elapsed; + sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; + sig.raw_data = dtmf; + if (analog_data->sig_cb(&sig) == ZAP_BREAK) { + collecting = 0; + } } } - if (last_digit && ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr)) { + 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) { @@ -741,7 +748,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); - while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { + while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { int waitms = 10; zap_status_t status; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index d8aa4778ef..1255b1352e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -85,6 +85,7 @@ static struct { zap_mutex_t *mutex; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; uint32_t span_index; + uint32_t running; } globals; @@ -1965,6 +1966,7 @@ zap_status_t zap_global_init(void) } if (load_config() == ZAP_SUCCESS) { + globals.running = 1; return ZAP_SUCCESS; } @@ -1972,6 +1974,10 @@ zap_status_t zap_global_init(void) return ZAP_FAIL; } +uint32_t zap_running(void) +{ + return globals.running; +} zap_status_t zap_global_destroy(void) @@ -1980,6 +1986,8 @@ zap_status_t zap_global_destroy(void) time_end(); zap_span_close_all(); + globals.running = 0; + zap_sleep(200); for(i = 1; i <= globals.span_index; i++) { zap_span_t *cur_span = &globals.spans[i]; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index c159230ad5..5f92cfa4b6 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -508,7 +508,7 @@ static __inline__ void check_events(zap_span_t *span) break; case ZAP_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Event Failure!\n"); + zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); } break; default: @@ -532,7 +532,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) Q921Start(&isdn_data->q921); - while(zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { + while(zap_running() && zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; zap_status_t status = zap_channel_wait(isdn_data->dchan, &flags, 100); From 34ec86778d79ca26a0bcf9b4eb2442bd0282b0e3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 24 Nov 2007 18:04:14 +0000 Subject: [PATCH 0690/1766] add dial regexs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@352 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/openzap.conf.xml | 8 ++- libs/freetdm/mod_openzap/mod_openzap.c | 79 ++++++++++++++++++++++---- libs/freetdm/src/include/openzap.h | 2 + libs/freetdm/src/include/zap_types.h | 6 +- libs/freetdm/src/zap_analog.c | 13 ++++- libs/freetdm/src/zap_io.c | 8 +++ libs/freetdm/src/zap_isdn.c | 4 +- 7 files changed, 101 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/conf/openzap.conf.xml b/libs/freetdm/conf/openzap.conf.xml index be802f9f5f..45780e9787 100644 --- a/libs/freetdm/conf/openzap.conf.xml +++ b/libs/freetdm/conf/openzap.conf.xml @@ -5,10 +5,14 @@ - - + + + + + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 292ac052e0..3f322039a2 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -35,7 +35,8 @@ #include "zap_isdn.h" SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); -SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, NULL, NULL); +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); +SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); switch_endpoint_interface_t *openzap_endpoint_interface; @@ -46,6 +47,9 @@ struct span_config { zap_span_t *span; char dialplan[80]; char context[80]; + char dial_regex[256]; + char fail_dial_regex[256]; + }; static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; @@ -974,6 +978,42 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) cycle_foreground(sigmsg->channel, 1); } break; + + case ZAP_SIGEVENT_COLLECTED_DIGIT: + { + char *dtmf = sigmsg->raw_data; + char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; + char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; + + if (switch_strlen_zero(regex)) { + regex = NULL; + } + + if (switch_strlen_zero(fail_regex)) { + fail_regex = NULL; + } + + if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { + switch_regex_t *re = NULL; + int ovector[30]; + int match = 0; + + if (fail_regex) { + match = switch_regex_perform(dtmf, fail_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_SUCCESS : ZAP_BREAK; + switch_regex_safe_free(re); + } + + if (status == ZAP_SUCCESS && regex) { + match = switch_regex_perform(dtmf, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_BREAK : ZAP_SUCCESS; + } + + switch_regex_safe_free(re); + } + + } + break; } return status; @@ -1036,15 +1076,17 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { + switch_status_t status; + switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: { - on_fxo_signal(sigmsg); + status = on_fxo_signal(sigmsg); } break; case ZAP_CHAN_TYPE_FXS: { - on_fxs_signal(sigmsg); + status = on_fxs_signal(sigmsg); } break; default: @@ -1055,7 +1097,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) break; } - return ZAP_SUCCESS; + return status; } static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) @@ -1105,6 +1147,8 @@ static switch_status_t load_config(void) char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; + char *dial_regex = NULL; + char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; @@ -1114,13 +1158,17 @@ static switch_status_t load_config(void) if (!strcasecmp(var, "tonegroup")) { tonegroup = val; - } else if (!strcasecmp(var, "digit_timeout")) { + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { digit_timeout = val; } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; - } else if (!strcasecmp(var, "max_digits")) { + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { digit_timeout = val; } } @@ -1154,10 +1202,17 @@ static switch_status_t load_config(void) } SPAN_CONFIG[span->span_id].span = span; - switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); - switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_set_string(SPAN_CONFIG[span->span_id].context, context); + switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan); + + if (dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); + } + + if (fail_dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); + } - zap_analog_start(span); } } @@ -1255,7 +1310,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) return SWITCH_STATUS_SUCCESS; } - +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) +{ + zap_global_destroy(); + return SWITCH_STATUS_SUCCESS; +} /* For Emacs: * Local Variables: diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index a9209ad8c2..14b46b7167 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -518,6 +518,8 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); +uint32_t zap_running(void); + ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 8be5007779..aac07d19f4 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -180,10 +180,11 @@ typedef enum { ZAP_SIGEVENT_ALARM_TRAP, ZAP_SIGEVENT_ALARM_CLEAR, ZAP_SIGEVENT_MISC, + ZAP_SIGEVENT_COLLECTED_DIGIT, 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", "INVALID" + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -205,7 +206,8 @@ typedef enum { ZAP_TIMEOUT, ZAP_NOTIMPL, ZAP_CHECKSUM_ERROR, - ZAP_STATUS_COUNT + ZAP_STATUS_COUNT, + ZAP_BREAK } zap_status_t; typedef enum { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index bc02794acd..2cb06d0d91 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -177,7 +177,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; + 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; @@ -490,17 +490,24 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); + collecting = 1; } dtmf_offset = strlen(dtmf); last_digit = elapsed; + sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; + sig.raw_data = dtmf; + if (analog_data->sig_cb(&sig) == ZAP_BREAK) { + collecting = 0; + } } } - if (last_digit && ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr)) { + 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) { @@ -741,7 +748,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); - while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { + while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { int waitms = 10; zap_status_t status; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index d8aa4778ef..1255b1352e 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -85,6 +85,7 @@ static struct { zap_mutex_t *mutex; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; uint32_t span_index; + uint32_t running; } globals; @@ -1965,6 +1966,7 @@ zap_status_t zap_global_init(void) } if (load_config() == ZAP_SUCCESS) { + globals.running = 1; return ZAP_SUCCESS; } @@ -1972,6 +1974,10 @@ zap_status_t zap_global_init(void) return ZAP_FAIL; } +uint32_t zap_running(void) +{ + return globals.running; +} zap_status_t zap_global_destroy(void) @@ -1980,6 +1986,8 @@ zap_status_t zap_global_destroy(void) time_end(); zap_span_close_all(); + globals.running = 0; + zap_sleep(200); for(i = 1; i <= globals.span_index; i++) { zap_span_t *cur_span = &globals.spans[i]; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index c159230ad5..5f92cfa4b6 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -508,7 +508,7 @@ static __inline__ void check_events(zap_span_t *span) break; case ZAP_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Event Failure!\n"); + zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); } break; default: @@ -532,7 +532,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) Q921Start(&isdn_data->q921); - while(zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { + while(zap_running() && zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { zap_wait_flag_t flags = ZAP_READ; zap_status_t status = zap_channel_wait(isdn_data->dchan, &flags, 100); From 4e3bfaa971d8b7693291b1796bb04fdd827c7d7e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 30 Nov 2007 23:30:36 +0000 Subject: [PATCH 0691/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@353 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index c695d7e7b2..004aac3e58 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -231,7 +231,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, mt->energy += famp*famp; - for(x = 0; x < mt->tone_count; x++) { + 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); @@ -248,13 +248,13 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } eng_sum = 0; - for(x = 0; x < mt->tone_count; x++) { + 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 < mt->tone_count; x++) { + for(x = 0; x < TELETONE_MAX_TONES && x < mt->tone_count; x++) { gtest += teletone_goertzel_result (&mt->gs2[x]) < eng_all[x] ? 1 : 0; } @@ -282,7 +282,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } /* Reinitialise the detector for the next block */ - for(x = 0; x < mt->tone_count; x++) { + 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]); } From 06a88cb0e59b0d0c94248b827a93501558ff199b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 30 Nov 2007 23:30:36 +0000 Subject: [PATCH 0692/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@353 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index c695d7e7b2..004aac3e58 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -231,7 +231,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, mt->energy += famp*famp; - for(x = 0; x < mt->tone_count; x++) { + 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); @@ -248,13 +248,13 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } eng_sum = 0; - for(x = 0; x < mt->tone_count; x++) { + 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 < mt->tone_count; x++) { + for(x = 0; x < TELETONE_MAX_TONES && x < mt->tone_count; x++) { gtest += teletone_goertzel_result (&mt->gs2[x]) < eng_all[x] ? 1 : 0; } @@ -282,7 +282,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } /* Reinitialise the detector for the next block */ - for(x = 0; x < mt->tone_count; x++) { + 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]); } From 0ebf02ae82ce92d2d48a848ebb1abb6de397347a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 2 Dec 2007 16:05:19 +0000 Subject: [PATCH 0693/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@354 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_buffer.h | 1 + libs/openzap/src/zap_buffer.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_buffer.h b/libs/openzap/src/include/zap_buffer.h index cd16825787..eaa71524f9 100644 --- a/libs/openzap/src/include/zap_buffer.h +++ b/libs/openzap/src/include/zap_buffer.h @@ -124,6 +124,7 @@ void zap_buffer_destroy(zap_buffer_t **buffer); /** @} */ +zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen); #endif /* For Emacs: diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 1db918665d..9cfb354ad4 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -187,8 +187,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d } actual_freespace = buffer->datalen - buffer->actually_used; - - if (actual_freespace < datalen) { + if (actual_freespace < datalen && (!buffer->max_len || (buffer->datalen + datalen <= buffer->max_len))) { memmove(buffer->data, buffer->head, buffer->used); buffer->head = buffer->data; buffer->actually_used = buffer->used; @@ -246,6 +245,18 @@ void zap_buffer_zero(zap_buffer_t *buffer) buffer->head = buffer->data; } +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; +} + void zap_buffer_destroy(zap_buffer_t **buffer) { if (*buffer) { From 4a61a74272e48f4692e966d50fe0b917411d454c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 2 Dec 2007 16:05:19 +0000 Subject: [PATCH 0694/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@354 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_buffer.h | 1 + libs/freetdm/src/zap_buffer.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h index cd16825787..eaa71524f9 100644 --- a/libs/freetdm/src/include/zap_buffer.h +++ b/libs/freetdm/src/include/zap_buffer.h @@ -124,6 +124,7 @@ void zap_buffer_destroy(zap_buffer_t **buffer); /** @} */ +zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen); #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 1db918665d..9cfb354ad4 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -187,8 +187,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d } actual_freespace = buffer->datalen - buffer->actually_used; - - if (actual_freespace < datalen) { + if (actual_freespace < datalen && (!buffer->max_len || (buffer->datalen + datalen <= buffer->max_len))) { memmove(buffer->data, buffer->head, buffer->used); buffer->head = buffer->data; buffer->actually_used = buffer->used; @@ -246,6 +245,18 @@ void zap_buffer_zero(zap_buffer_t *buffer) buffer->head = buffer->data; } +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; +} + void zap_buffer_destroy(zap_buffer_t **buffer) { if (*buffer) { From 839f6e0d91a6eafc2c9434b33517ae0b93ef79b5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 4 Dec 2007 16:13:52 +0000 Subject: [PATCH 0695/1766] we don't have this support on windows yet. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@355 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 1255b1352e..8703db8994 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -33,8 +33,8 @@ #ifndef WIN32 #define ZAP_ZT_SUPPORT -#endif #define ZAP_WANPIPE_SUPPORT +#endif #include "openzap.h" #include "zap_isdn.h" #include From 28b9c10b52e230e7d49c0f9ff2b50712746aecd7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 4 Dec 2007 16:13:52 +0000 Subject: [PATCH 0696/1766] we don't have this support on windows yet. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@355 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1255b1352e..8703db8994 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -33,8 +33,8 @@ #ifndef WIN32 #define ZAP_ZT_SUPPORT -#endif #define ZAP_WANPIPE_SUPPORT +#endif #include "openzap.h" #include "zap_isdn.h" #include From eb2387f27d60a4ab8195fef93f331284eafe154f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 14 Dec 2007 23:11:52 +0000 Subject: [PATCH 0697/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@356 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 004aac3e58..c0e75e3bfd 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -217,7 +217,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; - for (sample = 0; sample < samples; sample = limit) { + for (sample = 0; sample <= 0 && sample < samples; sample = limit) { mt->total_samples++; if ((samples - sample) >= (mt->min_samples - mt->current_sample)) { From 1c32ee36f1b6c70e81a1a0db5e7fe28169c5a317 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 14 Dec 2007 23:11:52 +0000 Subject: [PATCH 0698/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@356 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 004aac3e58..c0e75e3bfd 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -217,7 +217,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; - for (sample = 0; sample < samples; sample = limit) { + for (sample = 0; sample <= 0 && sample < samples; sample = limit) { mt->total_samples++; if ((samples - sample) >= (mt->min_samples - mt->current_sample)) { From f56929a99f54273cab9221becb57b4c864ce9273 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 15 Dec 2007 15:32:47 +0000 Subject: [PATCH 0699/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@357 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index c0e75e3bfd..7bbdd697df 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -129,7 +129,6 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, goertzel_state->v3 = (float)(goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]); } } - #ifdef _MSC_VER #pragma warning(disable:4244) #endif @@ -212,12 +211,12 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples) { - int sample, limit, j, x = 0; + int sample, limit = 0, j, x = 0; float v1, famp; float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; - for (sample = 0; sample <= 0 && sample < samples; sample = limit) { + for (sample = 0; sample >= 0 && sample < samples; sample = limit) { mt->total_samples++; if ((samples - sample) >= (mt->min_samples - mt->current_sample)) { @@ -225,6 +224,9 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } else { limit = samples; } + if (limit < 0 || limit > samples) { + limit = samples; + } for (j = sample; j < limit; j++) { famp = sample_buffer[j]; From 67ba63c549dae2291d51fad6711a54d2332b52b9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 15 Dec 2007 15:32:47 +0000 Subject: [PATCH 0700/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@357 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index c0e75e3bfd..7bbdd697df 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -129,7 +129,6 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, goertzel_state->v3 = (float)(goertzel_state->fac*goertzel_state->v2 - v1 + sample_buffer[i]); } } - #ifdef _MSC_VER #pragma warning(disable:4244) #endif @@ -212,12 +211,12 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples) { - int sample, limit, j, x = 0; + int sample, limit = 0, j, x = 0; float v1, famp; float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; int gtest = 0, see_hit = 0; - for (sample = 0; sample <= 0 && sample < samples; sample = limit) { + for (sample = 0; sample >= 0 && sample < samples; sample = limit) { mt->total_samples++; if ((samples - sample) >= (mt->min_samples - mt->current_sample)) { @@ -225,6 +224,9 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } else { limit = samples; } + if (limit < 0 || limit > samples) { + limit = samples; + } for (j = sample; j < limit; j++) { famp = sample_buffer[j]; From 010b17484b3a47b50c94f2fbd47f176363440a14 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 22 Dec 2007 02:16:03 +0000 Subject: [PATCH 0701/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@358 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 3f322039a2..243135959a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -418,14 +418,16 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int } -static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf) +static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) { private_t *tech_pvt = NULL; + char tmp[2] = ""; tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, dtmf); + tmp[0] = dtmf->digit; + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, tmp); return SWITCH_STATUS_SUCCESS; } @@ -509,7 +511,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { - switch_channel_queue_dtmf(channel, dtmf); + switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; + switch_channel_queue_dtmf(channel, &_dtmf); } return SWITCH_STATUS_SUCCESS; From 5916d66a28bfa5f128814ead6e007abd48a0000d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 22 Dec 2007 02:16:03 +0000 Subject: [PATCH 0702/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@358 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 3f322039a2..243135959a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -418,14 +418,16 @@ static switch_status_t channel_waitfor_write(switch_core_session_t *session, int } -static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *dtmf) +static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) { private_t *tech_pvt = NULL; + char tmp[2] = ""; tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, dtmf); + tmp[0] = dtmf->digit; + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, tmp); return SWITCH_STATUS_SUCCESS; } @@ -509,7 +511,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { - switch_channel_queue_dtmf(channel, dtmf); + switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; + switch_channel_queue_dtmf(channel, &_dtmf); } return SWITCH_STATUS_SUCCESS; From f926e83c027bd385d81238fe48d0b839862f0d72 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Jan 2008 16:50:20 +0000 Subject: [PATCH 0703/1766] error checking on dial string. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@359 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 243135959a..b997997dd6 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -717,18 +717,25 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + if (switch_strlen_zero(outbound_profile->destination_number)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + dest = outbound_profile->destination_number; if ((p = strchr(outbound_profile->destination_number, '/'))) { dest = p + 1; span_id = atoi(outbound_profile->destination_number); - chan_id = atoi(dest); - if ((p = strchr(dest, '/'))) { - dest = p + 1; + if (!switch_strlen_zero(dest)) { + chan_id = atoi(dest); + if ((p = strchr(dest, '/'))) { + dest = p + 1; + } } } - if (!dest) { + if (!switch_strlen_zero(dest)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -753,8 +760,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - - if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; From f81b02f429b9c804bb7cce6aa05291bf8c8ed460 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Jan 2008 16:50:20 +0000 Subject: [PATCH 0704/1766] error checking on dial string. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@359 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 243135959a..b997997dd6 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -717,18 +717,25 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + if (switch_strlen_zero(outbound_profile->destination_number)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + dest = outbound_profile->destination_number; if ((p = strchr(outbound_profile->destination_number, '/'))) { dest = p + 1; span_id = atoi(outbound_profile->destination_number); - chan_id = atoi(dest); - if ((p = strchr(dest, '/'))) { - dest = p + 1; + if (!switch_strlen_zero(dest)) { + chan_id = atoi(dest); + if ((p = strchr(dest, '/'))) { + dest = p + 1; + } } } - if (!dest) { + if (!switch_strlen_zero(dest)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -753,8 +760,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - - if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; From 2fddaf746525e3ab2c872d0aacc7007e4b95e95b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 8 Jan 2008 23:33:07 +0000 Subject: [PATCH 0705/1766] remove -w from makefile and fix all the obvious mistakes it was hiding git-svn-id: http://svn.openzap.org/svn/openzap/trunk@360 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 42 +++++++++++++++++++++----- libs/openzap/src/zap_pika.c | 5 +++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index aa763e48d8..fcbf198180 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -2,7 +2,7 @@ BASE=../../.. OZ_DIR=.. VERBOSE=1 OZA=$(OZ_DIR)/libopenzap.a -LOCAL_CFLAGS=-w -I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include +LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include LOCAL_LIBADD=$(OZA) include $(BASE)/build/modmake.rules diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b997997dd6..5323715ab2 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -41,7 +41,6 @@ SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NU switch_endpoint_interface_t *openzap_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; -static int running = 1; struct span_config { zap_span_t *span; @@ -52,7 +51,7 @@ struct span_config { }; -static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; +static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; typedef enum { TFLAG_IO = (1 << 0), @@ -106,7 +105,9 @@ static switch_status_t channel_on_loopback(switch_core_session_t *session); static switch_status_t channel_on_transmit(switch_core_session_t *session); static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, - switch_core_session_t **new_session, switch_memory_pool_t **pool); + switch_core_session_t **new_session, + switch_memory_pool_t **pool, + switch_originate_flag_t flags); static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); @@ -197,6 +198,8 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses dname = "L16"; } break; + default: + abort(); } @@ -702,7 +705,8 @@ that allocate memory or you will have 1 channel with memory allocated from anoth */ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, - switch_core_session_t **new_session, switch_memory_pool_t **pool) + switch_core_session_t **new_session, switch_memory_pool_t **pool, + switch_originate_flag_t flags) { char *p, *dest = NULL; @@ -918,6 +922,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } @@ -939,6 +944,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) } } break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } return ZAP_SUCCESS; @@ -973,9 +986,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } @@ -1022,6 +1035,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } return status; @@ -1043,9 +1064,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } @@ -1076,6 +1097,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) } } break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; } return ZAP_SUCCESS; @@ -1084,7 +1112,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { - switch_status_t status; + switch_status_t status = SWITCH_STATUS_FALSE; switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 9d79641dc0..b78710054c 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -1135,6 +1135,9 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) 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); @@ -1160,6 +1163,8 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) zap_mutex_destroy(&chan_data->digit_mutex); zap_buffer_destroy(&chan_data->digit_buffer); + + end: zap_safe_free(chan_data); return ZAP_SUCCESS; From e203b777f2dcef710c1c5085227bc8a8b0eb3306 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 8 Jan 2008 23:33:07 +0000 Subject: [PATCH 0706/1766] remove -w from makefile and fix all the obvious mistakes it was hiding git-svn-id: http://svn.openzap.org/svn/openzap/trunk@360 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 42 +++++++++++++++++++++----- libs/freetdm/src/zap_pika.c | 5 +++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index aa763e48d8..fcbf198180 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -2,7 +2,7 @@ BASE=../../.. OZ_DIR=.. VERBOSE=1 OZA=$(OZ_DIR)/libopenzap.a -LOCAL_CFLAGS=-w -I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include +LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include LOCAL_LIBADD=$(OZA) include $(BASE)/build/modmake.rules diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index b997997dd6..5323715ab2 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -41,7 +41,6 @@ SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NU switch_endpoint_interface_t *openzap_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; -static int running = 1; struct span_config { zap_span_t *span; @@ -52,7 +51,7 @@ struct span_config { }; -static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {0}; +static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; typedef enum { TFLAG_IO = (1 << 0), @@ -106,7 +105,9 @@ static switch_status_t channel_on_loopback(switch_core_session_t *session); static switch_status_t channel_on_transmit(switch_core_session_t *session); static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, - switch_core_session_t **new_session, switch_memory_pool_t **pool); + switch_core_session_t **new_session, + switch_memory_pool_t **pool, + switch_originate_flag_t flags); static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); @@ -197,6 +198,8 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses dname = "L16"; } break; + default: + abort(); } @@ -702,7 +705,8 @@ that allocate memory or you will have 1 channel with memory allocated from anoth */ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, - switch_core_session_t **new_session, switch_memory_pool_t **pool) + switch_core_session_t **new_session, switch_memory_pool_t **pool, + switch_originate_flag_t flags) { char *p, *dest = NULL; @@ -918,6 +922,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } @@ -939,6 +944,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) } } break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } return ZAP_SUCCESS; @@ -973,9 +986,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } @@ -1022,6 +1035,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } return status; @@ -1043,9 +1064,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } @@ -1076,6 +1097,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) } } break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; } return ZAP_SUCCESS; @@ -1084,7 +1112,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { - switch_status_t status; + switch_status_t status = SWITCH_STATUS_FALSE; switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 9d79641dc0..b78710054c 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -1135,6 +1135,9 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) 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); @@ -1160,6 +1163,8 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) zap_mutex_destroy(&chan_data->digit_mutex); zap_buffer_destroy(&chan_data->digit_buffer); + + end: zap_safe_free(chan_data); return ZAP_SUCCESS; From 169c074bcf9749fb8307c69efd6e51cfa53f2a07 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jan 2008 00:47:04 +0000 Subject: [PATCH 0707/1766] add hold-music 3way blind and attended transfer to openzap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@361 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 179 +++++++++++++++++++++++-- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_types.h | 6 +- libs/openzap/src/zap_analog.c | 6 +- libs/openzap/src/zap_pika.c | 4 +- libs/openzap/src/zap_zt.c | 4 +- 6 files changed, 180 insertions(+), 20 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5323715ab2..b9de0281b5 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -48,7 +48,7 @@ struct span_config { char context[80]; char dial_regex[256]; char fail_dial_regex[256]; - + char hold_music[256]; }; static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; @@ -73,6 +73,7 @@ static struct { unsigned int flags; int fd; int calls; + char hold_music[256]; switch_mutex_t *mutex; } globals; @@ -122,32 +123,93 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in } if (!switch_strlen_zero(channel->tokens[id])) { - session = switch_core_session_locate(channel->tokens[id]); + if (!(session = switch_core_session_locate(channel->tokens[id]))) { + zap_channel_clear_token(channel, channel->tokens[id]); + } } return session; } -static void cycle_foreground(zap_channel_t *zchan, int flash) { +static void stop_hold(const char *uuid) +{ + switch_core_session_t *session; + switch_channel_t *channel; + + if (!uuid) { + return; + } + + if ((session = switch_core_session_locate(uuid))) { + channel = switch_core_session_get_channel(session); + switch_channel_stop_broadcast(channel); + switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + switch_core_session_rwunlock(session); + } +} + +static void start_hold(const char *uuid, const char *music) +{ + switch_core_session_t *session; + switch_channel_t *channel; + const char *stream = NULL; + + + if (!uuid) { + return; + } + + if ((session = switch_core_session_locate(uuid))) { + channel = switch_core_session_get_channel(session); + + if (!(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { + stream = music; + if (switch_strlen_zero(stream)) { + stream = globals.hold_music; + } + } + + if (!switch_strlen_zero(stream)) { + switch_ivr_broadcast(switch_core_session_get_uuid(session), stream, SMF_ECHO_ALEG | SMF_LOOP); + } + + switch_core_session_rwunlock(session); + } +} + + +static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) { uint32_t i = 0; switch_core_session_t *session; switch_channel_t *channel; private_t *tech_pvt; + if (!bcast) { + bcast = SPAN_CONFIG[zchan->span->span_id].hold_music; + } + for (i = 0; i < zchan->token_count; i++) { if ((session = zap_channel_get_session(zchan, i))) { + const char *buuid; tech_pvt = switch_core_session_get_private(session); channel = switch_core_session_get_channel(session); + buuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); + + if (zchan->token_count == 1 && flash) { if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + stop_hold(buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } else { + start_hold(buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } } else if (i) { + start_hold(buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { + stop_hold(buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); if (!switch_channel_test_flag(channel, CF_ANSWERED)) { switch_channel_mark_answered(channel); @@ -173,6 +235,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses tech_pvt->cng_frame.data = tech_pvt->cng_databuf; tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); tech_pvt->cng_frame.flags = SFF_CNG; + tech_pvt->cng_frame.codec = &tech_pvt->read_codec; memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.buflen); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); @@ -320,7 +383,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_BUSY && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { if (tech_pvt->zchan->token_count) { - cycle_foreground(tech_pvt->zchan, 0); + cycle_foreground(tech_pvt->zchan, 0, NULL); } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } @@ -739,7 +802,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } - if (!switch_strlen_zero(dest)) { + if (switch_strlen_zero(dest)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -849,7 +912,8 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_FAIL; } - + *sigmsg->channel->caller_data.collected = '\0'; + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_name)) { switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); } @@ -985,18 +1049,104 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_STOP: { + switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; + if (sigmsg->channel->token_count) { + switch_core_session_t *session_a, *session_b, *session_t = NULL; + switch_channel_t *channel_a = NULL, *channel_b = NULL; + int digits = !switch_strlen_zero(sigmsg->channel->caller_data.collected); + const char *br_a_uuid = NULL, *br_b_uuid = NULL; + private_t *tech_pvt = NULL; + + + if ((session_a = switch_core_session_locate(sigmsg->channel->tokens[0]))) { + channel_a = switch_core_session_get_channel(session_a); + br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); + + tech_pvt = switch_core_session_get_private(session_a); + stop_hold(switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE)); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } + + if ((session_b = switch_core_session_locate(sigmsg->channel->tokens[1]))) { + channel_b = switch_core_session_get_channel(session_b); + br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); + + tech_pvt = switch_core_session_get_private(session_b); + stop_hold(switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE)); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } + + if (channel_a && channel_b && !switch_channel_test_flag(channel_a, CF_OUTBOUND) && !switch_channel_test_flag(channel_b, CF_OUTBOUND)) { + cause = SWITCH_CAUSE_ATTENDED_TRANSFER; + if (br_a_uuid && br_b_uuid) { + switch_ivr_uuid_bridge(br_a_uuid, br_b_uuid); + } else if (br_a_uuid && digits) { + session_t = switch_core_session_locate(br_a_uuid); + } else if (br_b_uuid && digits) { + session_t = switch_core_session_locate(br_b_uuid); + } + } + + if (session_t) { + switch_ivr_session_transfer(session_t, sigmsg->channel->caller_data.collected, NULL, NULL); + switch_core_session_rwunlock(session_t); + } + + if (session_a) { + switch_core_session_rwunlock(session_a); + } + + if (session_b) { + switch_core_session_rwunlock(session_b); + } + + + } + while((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } + zap_channel_clear_token(sigmsg->channel, NULL); + } break; + case ZAP_SIGEVENT_ADD_CALL: + { + cycle_foreground(sigmsg->channel, 1, NULL); + } + break; case ZAP_SIGEVENT_FLASH: { - cycle_foreground(sigmsg->channel, 1); + + if (sigmsg->channel->token_count == 2) { + if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { + zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); + if ((session = zap_channel_get_session(sigmsg->channel, 1))) { + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_rwunlock(session); + } + cycle_foreground(sigmsg->channel, 1, NULL); + } else { + char *cmd; + cmd = switch_mprintf("three_way::%s", sigmsg->channel->tokens[0]); + zap_set_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); + cycle_foreground(sigmsg->channel, 1, cmd); + free(cmd); + } + } else { + cycle_foreground(sigmsg->channel, 1, NULL); + if (sigmsg->channel->token_count == 1) { + zap_set_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_DIALTONE); + } + } + } break; @@ -1013,7 +1163,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (switch_strlen_zero(fail_regex)) { fail_regex = NULL; } - + + switch_set_string(sigmsg->channel->caller_data.collected, dtmf); + if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { switch_regex_t *re = NULL; int ovector[30]; @@ -1171,6 +1323,8 @@ static switch_status_t load_config(void) if (!strcasecmp(var, "debug")) { globals.debug = atoi(val); + } else if (!strcasecmp(var, "hold-music")) { + switch_set_string(globals.hold_music, val); } } } @@ -1184,6 +1338,7 @@ static switch_status_t load_config(void) char *digit_timeout = NULL; char *max_digits = NULL; char *dial_regex = NULL; + char *hold_music = NULL; char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; @@ -1204,6 +1359,8 @@ static switch_status_t load_config(void) dial_regex = val; } else if (!strcasecmp(var, "fail-dial-regex")) { fail_dial_regex = val; + } else if (!strcasecmp(var, "hold-music")) { + hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { digit_timeout = val; } @@ -1249,6 +1406,10 @@ static switch_status_t load_config(void) switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); } + if (hold_music) { + switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); + } + zap_analog_start(span); } } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 14b46b7167..866c665251 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -313,6 +313,7 @@ struct zap_caller_data { char aniII[25]; char dnis[25]; char rdnis[25]; + char collected[25]; int CRV; int hangup_cause; uint8_t raw_data[1024]; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index aac07d19f4..dfcf339026 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -181,10 +181,11 @@ typedef enum { ZAP_SIGEVENT_ALARM_CLEAR, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_COLLECTED_DIGIT, + ZAP_SIGEVENT_ADD_CALL, 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", "INVALID" + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "ADD_CALL", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -326,7 +327,8 @@ typedef enum { ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), ZAP_CHANNEL_OUTBOUND = (1 << 18), - ZAP_CHANNEL_SUSPENDED = (1 << 19) + ZAP_CHANNEL_SUSPENDED = (1 << 19), + ZAP_CHANNEL_3WAY = (1 << 20) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 2cb06d0d91..ccbea0b32b 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -372,7 +372,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) { zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); - sig.event_id = ZAP_SIGEVENT_FLASH; + sig.event_id = ZAP_SIGEVENT_ADD_CALL; } else { sig.event_id = ZAP_SIGEVENT_UP; } @@ -707,10 +707,6 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } else { sig.event_id = ZAP_SIGEVENT_FLASH; analog_data->sig_cb(&sig); - if (event->channel->token_count == 1) { - zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - } } } break; diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index b78710054c..2081867255 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -558,7 +558,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) { int items, i; char *mydata, *item_list[10]; - char *bd, *sp, *ch, *mx; + char *bd, *sp, *ch = NULL, *mx; int boardno; int channo; int spanno; @@ -978,7 +978,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) { - uint32_t i, event_id; + uint32_t i, event_id = 0; for(i = 1; i <= span->chan_count; i++) { if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index b2ee4c95b8..0513333e91 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -568,8 +568,8 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) { - uint32_t i, event_id; - zap_oob_event_t zt_event_id; + uint32_t i, event_id = 0; + zap_oob_event_t zt_event_id = 0; for(i = 1; i <= span->chan_count; i++) { if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { From 9d760b645db2f48f2e83c07056725fd6764d417f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jan 2008 00:47:04 +0000 Subject: [PATCH 0708/1766] add hold-music 3way blind and attended transfer to openzap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@361 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 179 +++++++++++++++++++++++-- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 6 +- libs/freetdm/src/zap_analog.c | 6 +- libs/freetdm/src/zap_pika.c | 4 +- libs/freetdm/src/zap_zt.c | 4 +- 6 files changed, 180 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5323715ab2..b9de0281b5 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -48,7 +48,7 @@ struct span_config { char context[80]; char dial_regex[256]; char fail_dial_regex[256]; - + char hold_music[256]; }; static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; @@ -73,6 +73,7 @@ static struct { unsigned int flags; int fd; int calls; + char hold_music[256]; switch_mutex_t *mutex; } globals; @@ -122,32 +123,93 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in } if (!switch_strlen_zero(channel->tokens[id])) { - session = switch_core_session_locate(channel->tokens[id]); + if (!(session = switch_core_session_locate(channel->tokens[id]))) { + zap_channel_clear_token(channel, channel->tokens[id]); + } } return session; } -static void cycle_foreground(zap_channel_t *zchan, int flash) { +static void stop_hold(const char *uuid) +{ + switch_core_session_t *session; + switch_channel_t *channel; + + if (!uuid) { + return; + } + + if ((session = switch_core_session_locate(uuid))) { + channel = switch_core_session_get_channel(session); + switch_channel_stop_broadcast(channel); + switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + switch_core_session_rwunlock(session); + } +} + +static void start_hold(const char *uuid, const char *music) +{ + switch_core_session_t *session; + switch_channel_t *channel; + const char *stream = NULL; + + + if (!uuid) { + return; + } + + if ((session = switch_core_session_locate(uuid))) { + channel = switch_core_session_get_channel(session); + + if (!(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { + stream = music; + if (switch_strlen_zero(stream)) { + stream = globals.hold_music; + } + } + + if (!switch_strlen_zero(stream)) { + switch_ivr_broadcast(switch_core_session_get_uuid(session), stream, SMF_ECHO_ALEG | SMF_LOOP); + } + + switch_core_session_rwunlock(session); + } +} + + +static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) { uint32_t i = 0; switch_core_session_t *session; switch_channel_t *channel; private_t *tech_pvt; + if (!bcast) { + bcast = SPAN_CONFIG[zchan->span->span_id].hold_music; + } + for (i = 0; i < zchan->token_count; i++) { if ((session = zap_channel_get_session(zchan, i))) { + const char *buuid; tech_pvt = switch_core_session_get_private(session); channel = switch_core_session_get_channel(session); + buuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); + + if (zchan->token_count == 1 && flash) { if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { + stop_hold(buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } else { + start_hold(buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } } else if (i) { + start_hold(buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { + stop_hold(buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); if (!switch_channel_test_flag(channel, CF_ANSWERED)) { switch_channel_mark_answered(channel); @@ -173,6 +235,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses tech_pvt->cng_frame.data = tech_pvt->cng_databuf; tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); tech_pvt->cng_frame.flags = SFF_CNG; + tech_pvt->cng_frame.codec = &tech_pvt->read_codec; memset(tech_pvt->cng_frame.data, 255, tech_pvt->cng_frame.buflen); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); @@ -320,7 +383,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_BUSY && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { if (tech_pvt->zchan->token_count) { - cycle_foreground(tech_pvt->zchan, 0); + cycle_foreground(tech_pvt->zchan, 0, NULL); } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } @@ -739,7 +802,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } - if (!switch_strlen_zero(dest)) { + if (switch_strlen_zero(dest)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -849,7 +912,8 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_FAIL; } - + *sigmsg->channel->caller_data.collected = '\0'; + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_name)) { switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); } @@ -985,18 +1049,104 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_STOP: { + switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; + if (sigmsg->channel->token_count) { + switch_core_session_t *session_a, *session_b, *session_t = NULL; + switch_channel_t *channel_a = NULL, *channel_b = NULL; + int digits = !switch_strlen_zero(sigmsg->channel->caller_data.collected); + const char *br_a_uuid = NULL, *br_b_uuid = NULL; + private_t *tech_pvt = NULL; + + + if ((session_a = switch_core_session_locate(sigmsg->channel->tokens[0]))) { + channel_a = switch_core_session_get_channel(session_a); + br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); + + tech_pvt = switch_core_session_get_private(session_a); + stop_hold(switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE)); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } + + if ((session_b = switch_core_session_locate(sigmsg->channel->tokens[1]))) { + channel_b = switch_core_session_get_channel(session_b); + br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); + + tech_pvt = switch_core_session_get_private(session_b); + stop_hold(switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE)); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + } + + if (channel_a && channel_b && !switch_channel_test_flag(channel_a, CF_OUTBOUND) && !switch_channel_test_flag(channel_b, CF_OUTBOUND)) { + cause = SWITCH_CAUSE_ATTENDED_TRANSFER; + if (br_a_uuid && br_b_uuid) { + switch_ivr_uuid_bridge(br_a_uuid, br_b_uuid); + } else if (br_a_uuid && digits) { + session_t = switch_core_session_locate(br_a_uuid); + } else if (br_b_uuid && digits) { + session_t = switch_core_session_locate(br_b_uuid); + } + } + + if (session_t) { + switch_ivr_session_transfer(session_t, sigmsg->channel->caller_data.collected, NULL, NULL); + switch_core_session_rwunlock(session_t); + } + + if (session_a) { + switch_core_session_rwunlock(session_a); + } + + if (session_b) { + switch_core_session_rwunlock(session_b); + } + + + } + while((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } + zap_channel_clear_token(sigmsg->channel, NULL); + } break; + case ZAP_SIGEVENT_ADD_CALL: + { + cycle_foreground(sigmsg->channel, 1, NULL); + } + break; case ZAP_SIGEVENT_FLASH: { - cycle_foreground(sigmsg->channel, 1); + + if (sigmsg->channel->token_count == 2) { + if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { + zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); + if ((session = zap_channel_get_session(sigmsg->channel, 1))) { + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_rwunlock(session); + } + cycle_foreground(sigmsg->channel, 1, NULL); + } else { + char *cmd; + cmd = switch_mprintf("three_way::%s", sigmsg->channel->tokens[0]); + zap_set_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); + cycle_foreground(sigmsg->channel, 1, cmd); + free(cmd); + } + } else { + cycle_foreground(sigmsg->channel, 1, NULL); + if (sigmsg->channel->token_count == 1) { + zap_set_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_DIALTONE); + } + } + } break; @@ -1013,7 +1163,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (switch_strlen_zero(fail_regex)) { fail_regex = NULL; } - + + switch_set_string(sigmsg->channel->caller_data.collected, dtmf); + if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { switch_regex_t *re = NULL; int ovector[30]; @@ -1171,6 +1323,8 @@ static switch_status_t load_config(void) if (!strcasecmp(var, "debug")) { globals.debug = atoi(val); + } else if (!strcasecmp(var, "hold-music")) { + switch_set_string(globals.hold_music, val); } } } @@ -1184,6 +1338,7 @@ static switch_status_t load_config(void) char *digit_timeout = NULL; char *max_digits = NULL; char *dial_regex = NULL; + char *hold_music = NULL; char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; @@ -1204,6 +1359,8 @@ static switch_status_t load_config(void) dial_regex = val; } else if (!strcasecmp(var, "fail-dial-regex")) { fail_dial_regex = val; + } else if (!strcasecmp(var, "hold-music")) { + hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { digit_timeout = val; } @@ -1249,6 +1406,10 @@ static switch_status_t load_config(void) switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); } + if (hold_music) { + switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); + } + zap_analog_start(span); } } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 14b46b7167..866c665251 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -313,6 +313,7 @@ struct zap_caller_data { char aniII[25]; char dnis[25]; char rdnis[25]; + char collected[25]; int CRV; int hangup_cause; uint8_t raw_data[1024]; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index aac07d19f4..dfcf339026 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -181,10 +181,11 @@ typedef enum { ZAP_SIGEVENT_ALARM_CLEAR, ZAP_SIGEVENT_MISC, ZAP_SIGEVENT_COLLECTED_DIGIT, + ZAP_SIGEVENT_ADD_CALL, 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", "INVALID" + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "ADD_CALL", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -326,7 +327,8 @@ typedef enum { ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), ZAP_CHANNEL_OUTBOUND = (1 << 18), - ZAP_CHANNEL_SUSPENDED = (1 << 19) + ZAP_CHANNEL_SUSPENDED = (1 << 19), + ZAP_CHANNEL_3WAY = (1 << 20) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 2cb06d0d91..ccbea0b32b 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -372,7 +372,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) { zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); - sig.event_id = ZAP_SIGEVENT_FLASH; + sig.event_id = ZAP_SIGEVENT_ADD_CALL; } else { sig.event_id = ZAP_SIGEVENT_UP; } @@ -707,10 +707,6 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } else { sig.event_id = ZAP_SIGEVENT_FLASH; analog_data->sig_cb(&sig); - if (event->channel->token_count == 1) { - zap_set_flag_locked(event->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - } } } break; diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index b78710054c..2081867255 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -558,7 +558,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) { int items, i; char *mydata, *item_list[10]; - char *bd, *sp, *ch, *mx; + char *bd, *sp, *ch = NULL, *mx; int boardno; int channo; int spanno; @@ -978,7 +978,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) { - uint32_t i, event_id; + uint32_t i, event_id = 0; for(i = 1; i <= span->chan_count; i++) { if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index b2ee4c95b8..0513333e91 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -568,8 +568,8 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) { - uint32_t i, event_id; - zap_oob_event_t zt_event_id; + uint32_t i, event_id = 0; + zap_oob_event_t zt_event_id = 0; for(i = 1; i <= span->chan_count; i++) { if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { From 12fa624e801812eceb2db6f1bf4142f2508f13a2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jan 2008 01:15:04 +0000 Subject: [PATCH 0709/1766] build update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@362 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 1 + libs/openzap/Makefile | 44 ++++++++++++++++++++++++-- libs/openzap/mod_openzap/Makefile | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 libs/openzap/.update diff --git a/libs/openzap/.update b/libs/openzap/.update new file mode 100644 index 0000000000..9e957ffb88 --- /dev/null +++ b/libs/openzap/.update @@ -0,0 +1 @@ +Wed Jan 9 20:08:13 EST 2008 diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index e90992406f..1919a52555 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -30,6 +30,44 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SRC=src +SOURCES=\ +$(SRC)/hashtable.c \ +$(SRC)/hashtable_itr.c \ +$(SRC)/zap_io.c \ +$(SRC)/zap_isdn.c \ +$(SRC)/zap_analog.c \ +$(SRC)/zap_config.c \ +$(SRC)/zap_callerid.c \ +$(SRC)/fsk.c \ +$(SRC)/uart.c \ +$(SRC)/g711.c \ +$(SRC)/libteletone_detect.c \ +$(SRC)/libteletone_generate.c \ +$(SRC)/zap_buffer.c \ +$(SRC)/zap_threadmutex.c \ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c \ +$(SRC)/zap_zt.c \ +$(SRC)/zap_wanpipe.c + OBJS=\ $(SRC)/hashtable.o \ $(SRC)/hashtable_itr.o \ @@ -109,8 +147,8 @@ LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w -PIKA_DIR=$(shell ls -d /usr/include/pika) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so) +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) ifneq ($(PIKA_DIR),) ifneq ($(PIKA_LIB),) @@ -124,7 +162,7 @@ include general.makefile all: $(MYLIB) -$(MYLIB): $(OBJS) $(HEADERS) +$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) ranlib $(MYLIB) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index fcbf198180..2609dc75a5 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -8,7 +8,7 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) -$(OZA): +$(OZA): $(OZ_DIR)/.update cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb $(ALL_CXXFLAGS)" diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b9de0281b5..1797cfe555 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -502,7 +502,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - uint32_t len; + zap_size_t len; zap_wait_flag_t wflags = ZAP_READ; char dtmf[128] = ""; zap_status_t status; From 9bb73cc4dcf9992e579cdf63dda4f0b43d252ef7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jan 2008 01:15:04 +0000 Subject: [PATCH 0710/1766] build update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@362 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 1 + libs/freetdm/Makefile | 44 ++++++++++++++++++++++++-- libs/freetdm/mod_openzap/Makefile | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 libs/freetdm/.update diff --git a/libs/freetdm/.update b/libs/freetdm/.update new file mode 100644 index 0000000000..9e957ffb88 --- /dev/null +++ b/libs/freetdm/.update @@ -0,0 +1 @@ +Wed Jan 9 20:08:13 EST 2008 diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index e90992406f..1919a52555 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -30,6 +30,44 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SRC=src +SOURCES=\ +$(SRC)/hashtable.c \ +$(SRC)/hashtable_itr.c \ +$(SRC)/zap_io.c \ +$(SRC)/zap_isdn.c \ +$(SRC)/zap_analog.c \ +$(SRC)/zap_config.c \ +$(SRC)/zap_callerid.c \ +$(SRC)/fsk.c \ +$(SRC)/uart.c \ +$(SRC)/g711.c \ +$(SRC)/libteletone_detect.c \ +$(SRC)/libteletone_generate.c \ +$(SRC)/zap_buffer.c \ +$(SRC)/zap_threadmutex.c \ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c \ +$(SRC)/zap_zt.c \ +$(SRC)/zap_wanpipe.c + OBJS=\ $(SRC)/hashtable.o \ $(SRC)/hashtable_itr.o \ @@ -109,8 +147,8 @@ LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w -PIKA_DIR=$(shell ls -d /usr/include/pika) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so) +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) ifneq ($(PIKA_DIR),) ifneq ($(PIKA_LIB),) @@ -124,7 +162,7 @@ include general.makefile all: $(MYLIB) -$(MYLIB): $(OBJS) $(HEADERS) +$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) ranlib $(MYLIB) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index fcbf198180..2609dc75a5 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -8,7 +8,7 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) -$(OZA): +$(OZA): $(OZ_DIR)/.update cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb $(ALL_CXXFLAGS)" diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index b9de0281b5..1797cfe555 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -502,7 +502,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - uint32_t len; + zap_size_t len; zap_wait_flag_t wflags = ZAP_READ; char dtmf[128] = ""; zap_status_t status; From cb4a1605afcf970329d6152b11e908281df7d5d9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jan 2008 16:50:38 +0000 Subject: [PATCH 0711/1766] don't timeout dialtone for mid-call dialtone to support hold better git-svn-id: http://svn.openzap.org/svn/openzap/trunk@363 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index ccbea0b32b..c560eade9c 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -260,7 +260,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { - if (state_counter > 10000) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_HOLD) && state_counter > 10000) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } } From b54c19e125aabe3c2370e7d5de0b16d0b89cd61a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jan 2008 16:50:38 +0000 Subject: [PATCH 0712/1766] don't timeout dialtone for mid-call dialtone to support hold better git-svn-id: http://svn.openzap.org/svn/openzap/trunk@363 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index ccbea0b32b..c560eade9c 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -260,7 +260,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { - if (state_counter > 10000) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_HOLD) && state_counter > 10000) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } } From f60626ba88829214e290f6b480c622bbf972a7ac Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 11 Jan 2008 17:23:12 +0000 Subject: [PATCH 0713/1766] build fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@364 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/fsk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/fsk.c b/libs/openzap/src/fsk.c index df3c834787..bed3e12a64 100644 --- a/libs/openzap/src/fsk.c +++ b/libs/openzap/src/fsk.c @@ -237,7 +237,8 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle) } if ((*handle)->attr.bytehandler) { - dsp_uart_destroy((dsp_uart_handle_t**)&(*handle)->attr.bithandler_arg); + dsp_uart_handle_t** dhandle = (void *)(&(*handle)->attr.bithandler_arg); + dsp_uart_destroy(dhandle); } free(*handle); From d24f057e1553ddefef197a6c9a28af8d2cd34e0f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 11 Jan 2008 17:23:12 +0000 Subject: [PATCH 0714/1766] build fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@364 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/fsk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index df3c834787..bed3e12a64 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -237,7 +237,8 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle) } if ((*handle)->attr.bytehandler) { - dsp_uart_destroy((dsp_uart_handle_t**)&(*handle)->attr.bithandler_arg); + dsp_uart_handle_t** dhandle = (void *)(&(*handle)->attr.bithandler_arg); + dsp_uart_destroy(dhandle); } free(*handle); From 38c7ed615ecc84543b289d4bfd2cece542eb464d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 12 Jan 2008 06:11:48 +0000 Subject: [PATCH 0715/1766] adj git-svn-id: http://svn.openzap.org/svn/openzap/trunk@365 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 11 +++++++++-- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/zap_analog.c | 9 ++++----- libs/openzap/src/zap_io.c | 9 ++++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 1797cfe555..dcbf8b3294 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -578,7 +578,14 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; - switch_channel_queue_dtmf(channel, &_dtmf); + char *p; + for (p = dtmf; p && *p; p++) { + if (is_dtmf(*p)) { + _dtmf.digit = *p; + zap_log(ZAP_LOG_DEBUG, "queue DTMF [%c]\n", *p); + switch_channel_queue_dtmf(channel, &_dtmf); + } + } } return SWITCH_STATUS_SUCCESS; @@ -1214,7 +1221,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) } break; case ZAP_SIGEVENT_STOP: - { + { while((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 866c665251..d03ded222e 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -521,6 +521,7 @@ int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); + ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index c560eade9c..a53d5ab7e6 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -38,7 +38,6 @@ struct tm * localtime_r(const time_t *clock, struct tm *result); #endif - static void *zap_analog_channel_run(zap_thread_t *me, void *obj); static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) @@ -485,9 +484,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { - zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + + 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; @@ -786,7 +786,6 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) } - zap_status_t zap_analog_start(zap_span_t *span) { zap_analog_data_t *analog_data = span->signal_data; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8703db8994..4f18f971d7 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1412,7 +1412,11 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t assert(zchan != NULL); - if (zap_buffer_inuse(zchan->digit_buffer)) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { + return ZAP_FAIL; + } + + if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { zap_mutex_lock(zchan->mutex); if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { *(dtmf + bytes) = '\0'; @@ -1608,7 +1612,6 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { - teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); @@ -1987,7 +1990,7 @@ zap_status_t zap_global_destroy(void) zap_span_close_all(); globals.running = 0; - zap_sleep(200); + zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) { zap_span_t *cur_span = &globals.spans[i]; From 460af7233da9d212fdf46f0f13231e082d5cc864 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 12 Jan 2008 06:11:48 +0000 Subject: [PATCH 0716/1766] adj git-svn-id: http://svn.openzap.org/svn/openzap/trunk@365 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 11 +++++++++-- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_analog.c | 9 ++++----- libs/freetdm/src/zap_io.c | 9 ++++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 1797cfe555..dcbf8b3294 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -578,7 +578,14 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; - switch_channel_queue_dtmf(channel, &_dtmf); + char *p; + for (p = dtmf; p && *p; p++) { + if (is_dtmf(*p)) { + _dtmf.digit = *p; + zap_log(ZAP_LOG_DEBUG, "queue DTMF [%c]\n", *p); + switch_channel_queue_dtmf(channel, &_dtmf); + } + } } return SWITCH_STATUS_SUCCESS; @@ -1214,7 +1221,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) } break; case ZAP_SIGEVENT_STOP: - { + { while((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 866c665251..d03ded222e 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -521,6 +521,7 @@ int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); + ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index c560eade9c..a53d5ab7e6 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -38,7 +38,6 @@ struct tm * localtime_r(const time_t *clock, struct tm *result); #endif - static void *zap_analog_channel_run(zap_thread_t *me, void *obj); static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) @@ -485,9 +484,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } } - if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { - zap_log(ZAP_LOG_DEBUG, "DTMF %s\n", dtmf + dtmf_offset); + + 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; @@ -786,7 +786,6 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) } - zap_status_t zap_analog_start(zap_span_t *span) { zap_analog_data_t *analog_data = span->signal_data; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8703db8994..4f18f971d7 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1412,7 +1412,11 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t assert(zchan != NULL); - if (zap_buffer_inuse(zchan->digit_buffer)) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { + return ZAP_FAIL; + } + + if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { zap_mutex_lock(zchan->mutex); if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { *(dtmf + bytes) = '\0'; @@ -1608,7 +1612,6 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { - teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); @@ -1987,7 +1990,7 @@ zap_status_t zap_global_destroy(void) zap_span_close_all(); globals.running = 0; - zap_sleep(200); + zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) { zap_span_t *cur_span = &globals.spans[i]; From 8d3361d8a55a141c5e580cbff48fd3c6d0e40150 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 Jan 2008 19:10:12 +0000 Subject: [PATCH 0717/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@366 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 9cfb354ad4..525a3e2100 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -187,7 +187,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d } actual_freespace = buffer->datalen - buffer->actually_used; - if (actual_freespace < datalen && (!buffer->max_len || (buffer->datalen + datalen <= buffer->max_len))) { + 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; From 1992ccae6a33bbeba93152dc164749383a544e19 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 Jan 2008 19:10:12 +0000 Subject: [PATCH 0718/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@366 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 9cfb354ad4..525a3e2100 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -187,7 +187,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d } actual_freespace = buffer->datalen - buffer->actually_used; - if (actual_freespace < datalen && (!buffer->max_len || (buffer->datalen + datalen <= buffer->max_len))) { + 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; From d223f037985c635254033dbda2c33fa5105db3b8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 14 Jan 2008 19:45:32 +0000 Subject: [PATCH 0719/1766] get chan id correctly from dial string git-svn-id: http://svn.openzap.org/svn/openzap/trunk@367 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index dcbf8b3294..ae5ae2e5f8 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -802,8 +802,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi dest = p + 1; span_id = atoi(outbound_profile->destination_number); if (!switch_strlen_zero(dest)) { - chan_id = atoi(dest); if ((p = strchr(dest, '/'))) { + chan_id = atoi(dest); dest = p + 1; } } From 2b4fa5f22140d5a123b1244dd37079e15c539079 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 14 Jan 2008 19:45:32 +0000 Subject: [PATCH 0720/1766] get chan id correctly from dial string git-svn-id: http://svn.openzap.org/svn/openzap/trunk@367 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index dcbf8b3294..ae5ae2e5f8 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -802,8 +802,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi dest = p + 1; span_id = atoi(outbound_profile->destination_number); if (!switch_strlen_zero(dest)) { - chan_id = atoi(dest); if ((p = strchr(dest, '/'))) { + chan_id = atoi(dest); dest = p + 1; } } From 955ece3364f5a0b657490cdc518b04c4ded72914 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 15:05:37 +0000 Subject: [PATCH 0721/1766] fix outgoing channel selection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@369 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 48 ++++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ae5ae2e5f8..ce707eab4c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -785,7 +785,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; zap_status_t status; - + int direction = ZAP_TOP_DOWN; + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -796,37 +797,40 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - dest = outbound_profile->destination_number; - - if ((p = strchr(outbound_profile->destination_number, '/'))) { - dest = p + 1; - span_id = atoi(outbound_profile->destination_number); - if (!switch_strlen_zero(dest)) { - if ((p = strchr(dest, '/'))) { - chan_id = atoi(dest); - dest = p + 1; - } - } - } - - if (switch_strlen_zero(dest)) { + if (switch_strlen_zero(outbound_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + dest = outbound_profile->destination_number; + span_id = atoi(dest); + + if ((p = strchr(dest, '/'))) { + if (*p++) { + if (*p == 'A') { + direction = ZAP_BOTTOM_UP; + } else if (*p == 'a') { + direction = ZAP_TOP_DOWN; + } else { + chan_id = atoi(dest); + } + } + } + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - + + if (chan_id < 0) { + direction = ZAP_BOTTOM_UP; + chan_id = 0; + } + if (chan_id) { - if (chan_id > 0) { - status = zap_channel_open(span_id, chan_id, &zchan); - } else { - status = zap_channel_open_any(span_id, ZAP_BOTTOM_UP, &zchan); - } + status = zap_channel_open(span_id, chan_id, &zchan); } else { - status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); + status = zap_channel_open_any(span_id, direction, &zchan); } if (status != ZAP_SUCCESS) { From ac6d26f72cae21584650a354e7ee7e29f659c32b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 15:05:37 +0000 Subject: [PATCH 0722/1766] fix outgoing channel selection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@369 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 48 ++++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ae5ae2e5f8..ce707eab4c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -785,7 +785,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; zap_status_t status; - + int direction = ZAP_TOP_DOWN; + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -796,37 +797,40 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - dest = outbound_profile->destination_number; - - if ((p = strchr(outbound_profile->destination_number, '/'))) { - dest = p + 1; - span_id = atoi(outbound_profile->destination_number); - if (!switch_strlen_zero(dest)) { - if ((p = strchr(dest, '/'))) { - chan_id = atoi(dest); - dest = p + 1; - } - } - } - - if (switch_strlen_zero(dest)) { + if (switch_strlen_zero(outbound_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + dest = outbound_profile->destination_number; + span_id = atoi(dest); + + if ((p = strchr(dest, '/'))) { + if (*p++) { + if (*p == 'A') { + direction = ZAP_BOTTOM_UP; + } else if (*p == 'a') { + direction = ZAP_TOP_DOWN; + } else { + chan_id = atoi(dest); + } + } + } + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - + + if (chan_id < 0) { + direction = ZAP_BOTTOM_UP; + chan_id = 0; + } + if (chan_id) { - if (chan_id > 0) { - status = zap_channel_open(span_id, chan_id, &zchan); - } else { - status = zap_channel_open_any(span_id, ZAP_BOTTOM_UP, &zchan); - } + status = zap_channel_open(span_id, chan_id, &zchan); } else { - status = zap_channel_open_any(span_id, ZAP_TOP_DOWN, &zchan); + status = zap_channel_open_any(span_id, direction, &zchan); } if (status != ZAP_SUCCESS) { From ee217678fc4aab83156c81f72a07bcc7a32e0f4d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 15:20:14 +0000 Subject: [PATCH 0723/1766] fix build err git-svn-id: http://svn.openzap.org/svn/openzap/trunk@370 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 4f18f971d7..9013acb4de 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1484,8 +1484,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data status = zchan->zio->read(zchan, data, datalen); if (zchan->fds[0]) { - unsigned int dlen = (unsigned int) *datalen; - write(zchan->fds[0], data, dlen); + int dlen = (int) *datalen; + if (write(zchan->fds[0], data, dlen) != dlen) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + return ZAP_FAIL; + } } if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { @@ -1729,8 +1732,11 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } if (zchan->fds[1]) { - unsigned int dlen = (unsigned int) *datalen; - write(zchan->fds[1], data, dlen); + int dlen = (int) *datalen; + if ((write(zchan->fds[1], data, dlen)) != dlen) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + return ZAP_FAIL; + } } status = zchan->zio->write(zchan, data, datalen); From 1c8d45c9268aa99ae272c00ce13e5414461ecaf8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 15:20:14 +0000 Subject: [PATCH 0724/1766] fix build err git-svn-id: http://svn.openzap.org/svn/openzap/trunk@370 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 4f18f971d7..9013acb4de 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1484,8 +1484,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data status = zchan->zio->read(zchan, data, datalen); if (zchan->fds[0]) { - unsigned int dlen = (unsigned int) *datalen; - write(zchan->fds[0], data, dlen); + int dlen = (int) *datalen; + if (write(zchan->fds[0], data, dlen) != dlen) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + return ZAP_FAIL; + } } if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { @@ -1729,8 +1732,11 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } if (zchan->fds[1]) { - unsigned int dlen = (unsigned int) *datalen; - write(zchan->fds[1], data, dlen); + int dlen = (int) *datalen; + if ((write(zchan->fds[1], data, dlen)) != dlen) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + return ZAP_FAIL; + } } status = zchan->zio->write(zchan, data, datalen); From b14afebf3e3ade6249c9ce6108f8090a2c53bb1d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 15:52:02 +0000 Subject: [PATCH 0725/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@371 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 9013acb4de..a88f4f661e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1483,10 +1483,10 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } status = zchan->zio->read(zchan, data, datalen); - if (zchan->fds[0]) { + if (zchan->fds[0] > -1) { int dlen = (int) *datalen; if (write(zchan->fds[0], data, dlen) != dlen) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "file write error!"); return ZAP_FAIL; } } @@ -1731,10 +1731,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } } - if (zchan->fds[1]) { + if (zchan->fds[1] > -1) { int dlen = (int) *datalen; if ((write(zchan->fds[1], data, dlen)) != dlen) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "file write error!"); return ZAP_FAIL; } } From c973fadc4e1b01fa908db518ed1bf9066bd8555d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 15:52:02 +0000 Subject: [PATCH 0726/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@371 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 9013acb4de..a88f4f661e 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1483,10 +1483,10 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } status = zchan->zio->read(zchan, data, datalen); - if (zchan->fds[0]) { + if (zchan->fds[0] > -1) { int dlen = (int) *datalen; if (write(zchan->fds[0], data, dlen) != dlen) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "file write error!"); return ZAP_FAIL; } } @@ -1731,10 +1731,10 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } } - if (zchan->fds[1]) { + if (zchan->fds[1] > -1) { int dlen = (int) *datalen; if ((write(zchan->fds[1], data, dlen)) != dlen) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "write error!"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "file write error!"); return ZAP_FAIL; } } From dceef913730c7e824a696e41e7b109a92bcad6dd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 16:42:06 +0000 Subject: [PATCH 0727/1766] add some options git-svn-id: http://svn.openzap.org/svn/openzap/trunk@372 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/openzap.conf.xml | 7 +++++ libs/openzap/mod_openzap/mod_openzap.c | 39 +++++++++++++++++++++++--- libs/openzap/src/zap_analog.c | 6 +++- libs/openzap/src/zap_zt.c | 10 +++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/libs/openzap/conf/openzap.conf.xml b/libs/openzap/conf/openzap.conf.xml index 45780e9787..1ca75c0e21 100644 --- a/libs/openzap/conf/openzap.conf.xml +++ b/libs/openzap/conf/openzap.conf.xml @@ -1,9 +1,16 @@ + + + + + + + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ce707eab4c..ceabd3c547 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -42,6 +42,12 @@ switch_endpoint_interface_t *openzap_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; +typedef enum { + ANALOG_OPTION_NONE = 0, + ANALOG_OPTION_3WAY = (1 << 0), + ANALOG_OPTION_CALL_SWAP = (1 << 1) +} analog_option_t; + struct span_config { zap_span_t *span; char dialplan[80]; @@ -49,6 +55,7 @@ struct span_config { char dial_regex[256]; char fail_dial_regex[256]; char hold_music[256]; + analog_option_t analog_options; }; static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; @@ -75,6 +82,7 @@ static struct { int calls; char hold_music[256]; switch_mutex_t *mutex; + analog_option_t analog_options; } globals; struct private_object { @@ -511,6 +519,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch channel = switch_core_session_get_channel(session); assert(channel != NULL); + tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); @@ -1052,6 +1061,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_START: { + zap_clear_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); status = zap_channel_from_event(sigmsg, &session); if (status != ZAP_SUCCESS) { zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); @@ -1132,8 +1142,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_FLASH: { - - if (sigmsg->channel->token_count == 2) { + if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { @@ -1150,7 +1159,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) cycle_foreground(sigmsg->channel, 1, cmd); free(cmd); } - } else { + } else if ((SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_CALL_SWAP) + || (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY) + ) { cycle_foreground(sigmsg->channel, 1, NULL); if (sigmsg->channel->token_count == 1) { zap_set_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); @@ -1315,6 +1326,20 @@ static void zap_logger(char *file, const char *func, int line, int level, char * } +static uint32_t enable_analog_option(const char *str, uint32_t current_options) +{ + if (!strcasecmp(str, "3-way")) { + current_options |= ANALOG_OPTION_3WAY; + current_options &= ~ANALOG_OPTION_CALL_SWAP; + } else if (!strcasecmp(str, "call-swap")) { + current_options |= ANALOG_OPTION_CALL_SWAP; + current_options &= ~ANALOG_OPTION_3WAY; + } + + return current_options; + +} + static switch_status_t load_config(void) { char *cf = "openzap.conf"; @@ -1336,6 +1361,8 @@ static switch_status_t load_config(void) globals.debug = atoi(val); } else if (!strcasecmp(var, "hold-music")) { switch_set_string(globals.hold_music, val); + } else if (!strcasecmp(var, "enable-analog-option")) { + globals.analog_options = enable_analog_option(val, globals.analog_options); } } } @@ -1353,6 +1380,7 @@ static switch_status_t load_config(void) char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; + analog_option_t analog_options = ANALOG_OPTION_NONE; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1374,6 +1402,8 @@ static switch_status_t load_config(void) hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { digit_timeout = val; + } else if (!strcasecmp(var, "enable-analog-option")) { + analog_options = enable_analog_option(val, analog_options); } } @@ -1408,7 +1438,8 @@ static switch_status_t load_config(void) SPAN_CONFIG[span->span_id].span = span; switch_set_string(SPAN_CONFIG[span->span_id].context, context); switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan); - + SPAN_CONFIG[span->span_id].analog_options = analog_options | globals.analog_options; + if (dial_regex) { switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index a53d5ab7e6..ee16393eec 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -369,6 +369,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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; @@ -519,7 +523,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "READ ERROR\n"); + zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error); goto done; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 0513333e91..43d434036d 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -654,11 +654,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) static ZIO_READ_FUNCTION(zt_read) { zap_ssize_t r = 0; - //*datalen = zchan->packet_len; + int errs = 0; - r = read(zchan->sockfd, data, *datalen); + while (errs++ < 100) { + if ((r = read(zchan->sockfd, data, *datalen)) > 0) { + break; + } + } - if (r >= 0) { + if (r > 0) { *datalen = r; if (zchan->type == ZAP_CHAN_TYPE_DQ921) { *datalen -= 2; From 254c3ed2d838c6693dcf6a366b8e639e4e2bbe4c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 16:42:06 +0000 Subject: [PATCH 0728/1766] add some options git-svn-id: http://svn.openzap.org/svn/openzap/trunk@372 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/openzap.conf.xml | 7 +++++ libs/freetdm/mod_openzap/mod_openzap.c | 39 +++++++++++++++++++++++--- libs/freetdm/src/zap_analog.c | 6 +++- libs/freetdm/src/zap_zt.c | 10 +++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/conf/openzap.conf.xml b/libs/freetdm/conf/openzap.conf.xml index 45780e9787..1ca75c0e21 100644 --- a/libs/freetdm/conf/openzap.conf.xml +++ b/libs/freetdm/conf/openzap.conf.xml @@ -1,9 +1,16 @@ + + + + + + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ce707eab4c..ceabd3c547 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -42,6 +42,12 @@ switch_endpoint_interface_t *openzap_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; +typedef enum { + ANALOG_OPTION_NONE = 0, + ANALOG_OPTION_3WAY = (1 << 0), + ANALOG_OPTION_CALL_SWAP = (1 << 1) +} analog_option_t; + struct span_config { zap_span_t *span; char dialplan[80]; @@ -49,6 +55,7 @@ struct span_config { char dial_regex[256]; char fail_dial_regex[256]; char hold_music[256]; + analog_option_t analog_options; }; static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; @@ -75,6 +82,7 @@ static struct { int calls; char hold_music[256]; switch_mutex_t *mutex; + analog_option_t analog_options; } globals; struct private_object { @@ -511,6 +519,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch channel = switch_core_session_get_channel(session); assert(channel != NULL); + tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); @@ -1052,6 +1061,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_START: { + zap_clear_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); status = zap_channel_from_event(sigmsg, &session); if (status != ZAP_SUCCESS) { zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); @@ -1132,8 +1142,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_FLASH: { - - if (sigmsg->channel->token_count == 2) { + if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { @@ -1150,7 +1159,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) cycle_foreground(sigmsg->channel, 1, cmd); free(cmd); } - } else { + } else if ((SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_CALL_SWAP) + || (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY) + ) { cycle_foreground(sigmsg->channel, 1, NULL); if (sigmsg->channel->token_count == 1) { zap_set_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); @@ -1315,6 +1326,20 @@ static void zap_logger(char *file, const char *func, int line, int level, char * } +static uint32_t enable_analog_option(const char *str, uint32_t current_options) +{ + if (!strcasecmp(str, "3-way")) { + current_options |= ANALOG_OPTION_3WAY; + current_options &= ~ANALOG_OPTION_CALL_SWAP; + } else if (!strcasecmp(str, "call-swap")) { + current_options |= ANALOG_OPTION_CALL_SWAP; + current_options &= ~ANALOG_OPTION_3WAY; + } + + return current_options; + +} + static switch_status_t load_config(void) { char *cf = "openzap.conf"; @@ -1336,6 +1361,8 @@ static switch_status_t load_config(void) globals.debug = atoi(val); } else if (!strcasecmp(var, "hold-music")) { switch_set_string(globals.hold_music, val); + } else if (!strcasecmp(var, "enable-analog-option")) { + globals.analog_options = enable_analog_option(val, globals.analog_options); } } } @@ -1353,6 +1380,7 @@ static switch_status_t load_config(void) char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; + analog_option_t analog_options = ANALOG_OPTION_NONE; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1374,6 +1402,8 @@ static switch_status_t load_config(void) hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { digit_timeout = val; + } else if (!strcasecmp(var, "enable-analog-option")) { + analog_options = enable_analog_option(val, analog_options); } } @@ -1408,7 +1438,8 @@ static switch_status_t load_config(void) SPAN_CONFIG[span->span_id].span = span; switch_set_string(SPAN_CONFIG[span->span_id].context, context); switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan); - + SPAN_CONFIG[span->span_id].analog_options = analog_options | globals.analog_options; + if (dial_regex) { switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index a53d5ab7e6..ee16393eec 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -369,6 +369,10 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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; @@ -519,7 +523,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "READ ERROR\n"); + zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error); goto done; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 0513333e91..43d434036d 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -654,11 +654,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) static ZIO_READ_FUNCTION(zt_read) { zap_ssize_t r = 0; - //*datalen = zchan->packet_len; + int errs = 0; - r = read(zchan->sockfd, data, *datalen); + while (errs++ < 100) { + if ((r = read(zchan->sockfd, data, *datalen)) > 0) { + break; + } + } - if (r >= 0) { + if (r > 0) { *datalen = r; if (zchan->type == ZAP_CHAN_TYPE_DQ921) { *datalen -= 2; From 1766e2eb6dad08deb55b2c935755a80f141512b9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 23:54:26 +0000 Subject: [PATCH 0729/1766] i guess idsn calls want dtmf too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@373 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ceabd3c547..c595e086b1 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1248,6 +1248,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_tone_type_t tt = ZAP_TONE_DTMF; + + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + } + channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); switch_core_session_rwunlock(session); From f5d6a0f7f0966fe96a1f01e73cdadd4bcf612df4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 25 Jan 2008 23:54:26 +0000 Subject: [PATCH 0730/1766] i guess idsn calls want dtmf too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@373 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ceabd3c547..c595e086b1 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1248,6 +1248,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_tone_type_t tt = ZAP_TONE_DTMF; + + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + } + channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); switch_core_session_rwunlock(session); From eb593b7ab38a9e934247da879736092af61d759f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 Jan 2008 00:07:37 +0000 Subject: [PATCH 0731/1766] i guess idsn calls want dtmf too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@374 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 9e957ffb88..23063c4325 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Wed Jan 9 20:08:13 EST 2008 +Fri Jan 25 19:07:34 EST 2008 From adf8253a0ee1b6b80f3a03ce97a52e5c25a974fd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 26 Jan 2008 00:07:37 +0000 Subject: [PATCH 0732/1766] i guess idsn calls want dtmf too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@374 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 9e957ffb88..23063c4325 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Wed Jan 9 20:08:13 EST 2008 +Fri Jan 25 19:07:34 EST 2008 From 96af9f5fe701d6669d1d2a833e30c774c34c247a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 28 Jan 2008 21:45:48 +0000 Subject: [PATCH 0733/1766] doh wrong place git-svn-id: http://svn.openzap.org/svn/openzap/trunk@375 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c595e086b1..8f74c12902 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1232,6 +1232,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: { + zap_tone_type_t tt = ZAP_TONE_DTMF; + + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + } + return zap_channel_from_event(sigmsg, &session); } break; @@ -1248,12 +1254,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_tone_type_t tt = ZAP_TONE_DTMF; - - if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); - } - channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); switch_core_session_rwunlock(session); From 05645d13fb1a1f7990b6988a6e0c22e531f9d96f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 28 Jan 2008 21:45:48 +0000 Subject: [PATCH 0734/1766] doh wrong place git-svn-id: http://svn.openzap.org/svn/openzap/trunk@375 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c595e086b1..8f74c12902 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1232,6 +1232,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: { + zap_tone_type_t tt = ZAP_TONE_DTMF; + + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + } + return zap_channel_from_event(sigmsg, &session); } break; @@ -1248,12 +1254,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_tone_type_t tt = ZAP_TONE_DTMF; - - if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); - } - channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); switch_core_session_rwunlock(session); From c9ce523168b3a6a6f6ab6abe58b152a974a6e41d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 Jan 2008 22:17:34 +0000 Subject: [PATCH 0735/1766] more gracefully handle messagees with unexpected chan id that we don't have allocated. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@376 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 5f92cfa4b6..4d10f8c555 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -144,7 +144,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RELEASE: case Q931mes_RELEASE_COMPLETE: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); + } } break; case Q931mes_DISCONNECT: @@ -157,17 +161,29 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_ALERTING: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + 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: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_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: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } else { + zap_log(ZAP_LOG_CRIT, "Received Connect with no matching channel %d\n", chan_id); + } } break; case Q931mes_SETUP: From 9ed82fc71c8b637a6da157c2ac712445f8a56df5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 Jan 2008 22:17:34 +0000 Subject: [PATCH 0736/1766] more gracefully handle messagees with unexpected chan id that we don't have allocated. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@376 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 5f92cfa4b6..4d10f8c555 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -144,7 +144,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RELEASE: case Q931mes_RELEASE_COMPLETE: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); + } } break; case Q931mes_DISCONNECT: @@ -157,17 +161,29 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_ALERTING: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + 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: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_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: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + if (zchan) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } else { + zap_log(ZAP_LOG_CRIT, "Received Connect with no matching channel %d\n", chan_id); + } } break; case Q931mes_SETUP: From 08c099582e7eb719c90b2eff56c19a916dfc680b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jan 2008 00:15:08 +0000 Subject: [PATCH 0737/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@377 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 8f74c12902..51faebc011 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -821,11 +821,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } else if (*p == 'a') { direction = ZAP_TOP_DOWN; } else { - chan_id = atoi(dest); + chan_id = atoi(p); } } } - + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From 4f7223357e365dbc2244a9ecb89097ade1fb8d87 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jan 2008 00:15:08 +0000 Subject: [PATCH 0738/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@377 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 8f74c12902..51faebc011 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -821,11 +821,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } else if (*p == 'a') { direction = ZAP_TOP_DOWN; } else { - chan_id = atoi(dest); + chan_id = atoi(p); } } } - + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From d8e3b4b3fe197b507f9e3b592355e1dd0245457a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 01:44:05 +0000 Subject: [PATCH 0739/1766] first hack at crv lookup table for zchan git-svn-id: http://svn.openzap.org/svn/openzap/trunk@378 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 ++ libs/openzap/src/zap_isdn.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d03ded222e..57a0081ab1 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -425,6 +425,8 @@ struct zap_span { teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + zap_channel_t *channels_local_crv[32768]; + zap_channel_t *channels_remote_crv[32768]; zio_channel_outgoing_call_t outgoing_call; void *mod_data; char *type; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 4d10f8c555..9c22b96bda 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -67,10 +67,21 @@ 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; - Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); - int chan_id = chanid->ChanSlot; + int chan_id = 0; zap_channel_t *zchan = NULL; + if (Q931IsIEPresent(gen->ChanID)) { + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + chan_id = chanid->ChanSlot; + zchan = &span->channels[chan_id]; + } else { + if (gen->CRVFlag) { + zchan = span->channels_local_crv[gen->CRV]; + } else { + zchan = span->channels_remote_crv[gen->CRV]; + } + } + assert(span != NULL); assert(isdn_data != NULL); @@ -129,6 +140,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } else { switch(gen->MesType) { + case Q931mes_CALL_PROCEEDING: + { + if (zchan) { + zchan->span->channels_local_crv[gen->CRV] = zchan; + } else { + zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); + } + } + break; case Q931mes_RESTART: { if (zchan) { @@ -198,6 +218,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + zchan->span->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); From e4af9c444acc1fe8fc2afad2b435e8292d4de20b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 01:44:05 +0000 Subject: [PATCH 0740/1766] first hack at crv lookup table for zchan git-svn-id: http://svn.openzap.org/svn/openzap/trunk@378 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 ++ libs/freetdm/src/zap_isdn.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index d03ded222e..57a0081ab1 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -425,6 +425,8 @@ struct zap_span { teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + zap_channel_t *channels_local_crv[32768]; + zap_channel_t *channels_remote_crv[32768]; zio_channel_outgoing_call_t outgoing_call; void *mod_data; char *type; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 4d10f8c555..9c22b96bda 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -67,10 +67,21 @@ 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; - Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); - int chan_id = chanid->ChanSlot; + int chan_id = 0; zap_channel_t *zchan = NULL; + if (Q931IsIEPresent(gen->ChanID)) { + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + chan_id = chanid->ChanSlot; + zchan = &span->channels[chan_id]; + } else { + if (gen->CRVFlag) { + zchan = span->channels_local_crv[gen->CRV]; + } else { + zchan = span->channels_remote_crv[gen->CRV]; + } + } + assert(span != NULL); assert(isdn_data != NULL); @@ -129,6 +140,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } else { switch(gen->MesType) { + case Q931mes_CALL_PROCEEDING: + { + if (zchan) { + zchan->span->channels_local_crv[gen->CRV] = zchan; + } else { + zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); + } + } + break; case Q931mes_RESTART: { if (zchan) { @@ -198,6 +218,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + zchan->span->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); From 1d09e2c87049538405092ed2b741c479ef7f2bfa Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 01:44:48 +0000 Subject: [PATCH 0741/1766] remove incorrect debug statement git-svn-id: http://svn.openzap.org/svn/openzap/trunk@379 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 9c22b96bda..024cc002d2 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -144,8 +144,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { if (zchan) { zchan->span->channels_local_crv[gen->CRV] = zchan; - } else { - zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); } } break; From cb3679ac0c9028c774c0b685fd40ea37124c8e2d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 01:44:48 +0000 Subject: [PATCH 0742/1766] remove incorrect debug statement git-svn-id: http://svn.openzap.org/svn/openzap/trunk@379 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 9c22b96bda..024cc002d2 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -144,8 +144,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { if (zchan) { zchan->span->channels_local_crv[gen->CRV] = zchan; - } else { - zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); } } break; From 966763465c9312bd5e10b0d301d03414e1557446 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 15:23:36 +0000 Subject: [PATCH 0743/1766] set lookup on outbound call git-svn-id: http://svn.openzap.org/svn/openzap/trunk@380 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 024cc002d2..4b0d7a1f77 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -140,13 +140,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } else { switch(gen->MesType) { - case Q931mes_CALL_PROCEEDING: - { - if (zchan) { - zchan->span->channels_local_crv[gen->CRV] = zchan; - } - } - break; case Q931mes_RESTART: { if (zchan) { @@ -434,6 +427,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) //gen->Size += strlen(zchan->caller_data.ani); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); + zchan->span->channels_local_crv[gen->CRV] = zchan; } break; case ZAP_CHANNEL_STATE_HANGUP: From 88db54e8ccc680bf9e70b0515956fde2a8f7d1d8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 15:23:36 +0000 Subject: [PATCH 0744/1766] set lookup on outbound call git-svn-id: http://svn.openzap.org/svn/openzap/trunk@380 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 024cc002d2..4b0d7a1f77 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -140,13 +140,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } else { switch(gen->MesType) { - case Q931mes_CALL_PROCEEDING: - { - if (zchan) { - zchan->span->channels_local_crv[gen->CRV] = zchan; - } - } - break; case Q931mes_RESTART: { if (zchan) { @@ -434,6 +427,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) //gen->Size += strlen(zchan->caller_data.ani); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); + zchan->span->channels_local_crv[gen->CRV] = zchan; } break; case ZAP_CHANNEL_STATE_HANGUP: From 84d9aca9b901dd595c752266427cbc8ec0420388 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 15:29:20 +0000 Subject: [PATCH 0745/1766] use our new lookup table git-svn-id: http://svn.openzap.org/svn/openzap/trunk@381 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 4b0d7a1f77..da164328a6 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -70,17 +70,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) int chan_id = 0; zap_channel_t *zchan = NULL; - if (Q931IsIEPresent(gen->ChanID)) { - Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); - chan_id = chanid->ChanSlot; - zchan = &span->channels[chan_id]; + if (gen->CRVFlag) { + zchan = span->channels_local_crv[gen->CRV]; } else { - if (gen->CRVFlag) { - zchan = span->channels_local_crv[gen->CRV]; - } else { - zchan = span->channels_remote_crv[gen->CRV]; - } - } + zchan = span->channels_remote_crv[gen->CRV]; + } assert(span != NULL); assert(isdn_data != NULL); From 0f918716a9cfba510f6ae8caef1bf538def30a57 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 15:29:20 +0000 Subject: [PATCH 0746/1766] use our new lookup table git-svn-id: http://svn.openzap.org/svn/openzap/trunk@381 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 4b0d7a1f77..da164328a6 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -70,17 +70,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) int chan_id = 0; zap_channel_t *zchan = NULL; - if (Q931IsIEPresent(gen->ChanID)) { - Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); - chan_id = chanid->ChanSlot; - zchan = &span->channels[chan_id]; + if (gen->CRVFlag) { + zchan = span->channels_local_crv[gen->CRV]; } else { - if (gen->CRVFlag) { - zchan = span->channels_local_crv[gen->CRV]; - } else { - zchan = span->channels_remote_crv[gen->CRV]; - } - } + zchan = span->channels_remote_crv[gen->CRV]; + } assert(span != NULL); assert(isdn_data != NULL); From 59d403173548065746ae77be9568cfe62bb60ffb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 16:24:54 +0000 Subject: [PATCH 0747/1766] allow diag bytes on Cause IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@382 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 23e4f010ed..d3cea9936f 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1029,7 +1029,12 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I pie->Value = IBuf[Octet+Off] & 0x7f; Octet++; - Q931IESizeTest(Q931E_CAUSE); + /* Consume optional Diagnostic bytes */ + while (Q931MoreIE()) { + Off++; + }; + + Q931IESizeTest(Q931E_CAUSE); Q931SetIE(*pIE, *OOff); From 6a8f752cfe7389593789d40218b83d027971b7a0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 30 Jan 2008 16:24:54 +0000 Subject: [PATCH 0748/1766] allow diag bytes on Cause IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@382 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 23e4f010ed..d3cea9936f 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1029,7 +1029,12 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I pie->Value = IBuf[Octet+Off] & 0x7f; Octet++; - Q931IESizeTest(Q931E_CAUSE); + /* Consume optional Diagnostic bytes */ + while (Q931MoreIE()) { + Off++; + }; + + Q931IESizeTest(Q931E_CAUSE); Q931SetIE(*pIE, *OOff); From d400fb721114fac9c14f621620f520518c5947d5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 2 Feb 2008 16:48:20 +0000 Subject: [PATCH 0749/1766] fix dest git-svn-id: http://svn.openzap.org/svn/openzap/trunk@383 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 51faebc011..d28de8fb01 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -823,9 +823,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } else { chan_id = atoi(p); } + if ((p = strchr(p, '/')) && *++p) { + dest = p; + } } } - + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From 3ece98d91013f2673408137da2fb5d44ddb200c2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 2 Feb 2008 16:48:20 +0000 Subject: [PATCH 0750/1766] fix dest git-svn-id: http://svn.openzap.org/svn/openzap/trunk@383 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 51faebc011..d28de8fb01 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -823,9 +823,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } else { chan_id = atoi(p); } + if ((p = strchr(p, '/')) && *++p) { + dest = p; + } } } - + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From 2dd2b0134547db9460be29fa8d094e47c202b318 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 2 Feb 2008 16:54:21 +0000 Subject: [PATCH 0751/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@384 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d28de8fb01..84baeaa284 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -806,11 +806,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (switch_strlen_zero(outbound_profile->destination_number)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } - dest = outbound_profile->destination_number; span_id = atoi(dest); From 3a72affc9e4bec48a2a0a3000fffb2685259ee0f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 2 Feb 2008 16:54:21 +0000 Subject: [PATCH 0752/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@384 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d28de8fb01..84baeaa284 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -806,11 +806,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (switch_strlen_zero(outbound_profile->destination_number)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } - dest = outbound_profile->destination_number; span_id = atoi(dest); From 7df46e7aacdc4c68e83dc7273a6d792174f934ba Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Feb 2008 17:57:50 +0000 Subject: [PATCH 0753/1766] one / is enough git-svn-id: http://svn.openzap.org/svn/openzap/trunk@385 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 1919a52555..a569b23a24 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -140,7 +140,7 @@ $(SRC)/isdn/include/Q932.h PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include CFLAGS= $(INCS) $(ZAP_CFLAGS) MYLIB=libopenzap.a LIBPRIA=libpri.a From f133df8748b12279dbbb7113b09cf9384550a2f1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Feb 2008 17:57:50 +0000 Subject: [PATCH 0754/1766] one / is enough git-svn-id: http://svn.openzap.org/svn/openzap/trunk@385 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 1919a52555..a569b23a24 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -140,7 +140,7 @@ $(SRC)/isdn/include/Q932.h PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include CFLAGS= $(INCS) $(ZAP_CFLAGS) MYLIB=libopenzap.a LIBPRIA=libpri.a From f3e6e89761645589bc37bceb01d563daa80d04fd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Feb 2008 20:27:54 +0000 Subject: [PATCH 0755/1766] fix inbound git-svn-id: http://svn.openzap.org/svn/openzap/trunk@386 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index da164328a6..381afcd2fa 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -70,18 +70,26 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) int chan_id = 0; zap_channel_t *zchan = NULL; + if (Q931IsIEPresent(gen->ChanID)) { + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + chan_id = chanid->ChanSlot; + } + + assert(span != NULL); + assert(isdn_data != NULL); + +#if 0 + if (chan_id) { + zchan = &span->channels[chan_id]; + } +#endif + if (gen->CRVFlag) { zchan = span->channels_local_crv[gen->CRV]; } else { zchan = span->channels_remote_crv[gen->CRV]; } - assert(span != NULL); - assert(isdn_data != NULL); - - if (chan_id) { - zchan = &span->channels[chan_id]; - } zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); From e8051d6b78c652ff77e8a779d920e1db4dfa8e76 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Feb 2008 20:27:54 +0000 Subject: [PATCH 0756/1766] fix inbound git-svn-id: http://svn.openzap.org/svn/openzap/trunk@386 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index da164328a6..381afcd2fa 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -70,18 +70,26 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) int chan_id = 0; zap_channel_t *zchan = NULL; + if (Q931IsIEPresent(gen->ChanID)) { + Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); + chan_id = chanid->ChanSlot; + } + + assert(span != NULL); + assert(isdn_data != NULL); + +#if 0 + if (chan_id) { + zchan = &span->channels[chan_id]; + } +#endif + if (gen->CRVFlag) { zchan = span->channels_local_crv[gen->CRV]; } else { zchan = span->channels_remote_crv[gen->CRV]; } - assert(span != NULL); - assert(isdn_data != NULL); - - if (chan_id) { - zchan = &span->channels[chan_id]; - } zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); From 099dae4b9910864e29d3b3b21c6e84ceaa0dac58 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Feb 2008 20:40:23 +0000 Subject: [PATCH 0757/1766] mark answered. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@387 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 84baeaa284..db9cb1ee4e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1252,8 +1252,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_tone_type_t tt = ZAP_TONE_DTMF; channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + } switch_core_session_rwunlock(session); } } From 08115470e01aff6102036af470523033bdeb9e5a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 4 Feb 2008 20:40:23 +0000 Subject: [PATCH 0758/1766] mark answered. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@387 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 84baeaa284..db9cb1ee4e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1252,8 +1252,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_tone_type_t tt = ZAP_TONE_DTMF; channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + } switch_core_session_rwunlock(session); } } From fa839992e0a1e3d84c451be83e623a63c8590512 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Feb 2008 17:54:15 +0000 Subject: [PATCH 0759/1766] stop when we reach the end of our spans git-svn-id: http://svn.openzap.org/svn/openzap/trunk@388 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a88f4f661e..2987164c69 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -695,11 +695,6 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } for(;;) { - span = &globals.spans[j]; - if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - goto next_loop; - } - if (direction == ZAP_TOP_DOWN) { if (j > span_max) { break; @@ -709,6 +704,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z break; } } + + span = &globals.spans[j]; + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + goto next_loop; + } if (direction == ZAP_TOP_DOWN) { i = 1; From 9d8d013df452a3749a86a4b9bf5ca81afb8db663 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 5 Feb 2008 17:54:15 +0000 Subject: [PATCH 0760/1766] stop when we reach the end of our spans git-svn-id: http://svn.openzap.org/svn/openzap/trunk@388 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a88f4f661e..2987164c69 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -695,11 +695,6 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } for(;;) { - span = &globals.spans[j]; - if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - goto next_loop; - } - if (direction == ZAP_TOP_DOWN) { if (j > span_max) { break; @@ -709,6 +704,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z break; } } + + span = &globals.spans[j]; + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + goto next_loop; + } if (direction == ZAP_TOP_DOWN) { i = 1; From 33f70e63bcb4ed658d97541552c83267a7f7d7e7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 6 Feb 2008 18:10:27 +0000 Subject: [PATCH 0761/1766] try to release the call refs. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@389 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index a45aa06472..3cd45dab33 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -782,14 +782,24 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - //L3INT state = Q931GetCallState(pTrunk, pMes->CRV); - L3INT ret = Q931E_NO_ERROR; + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; + if(iFrom == 2) { /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); } + + 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; + } + return ret; } From 46ef513af8e7b1698ea22a6dc29158e2ee9c0b48 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 6 Feb 2008 18:10:27 +0000 Subject: [PATCH 0762/1766] try to release the call refs. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@389 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index a45aa06472..3cd45dab33 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -782,14 +782,24 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - //L3INT state = Q931GetCallState(pTrunk, pMes->CRV); - L3INT ret = Q931E_NO_ERROR; + L3INT callIndex; + L3INT ret=Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; + if(iFrom == 2) { /* TODO Add proc here*/ ret = Q931Tx34(pTrunk,buf,pMes->Size); } + + 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; + } + return ret; } From 860645b9759e38272b77ad4d1703211aaa25ff15 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Feb 2008 15:54:15 +0000 Subject: [PATCH 0763/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@390 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index ee16393eec..b4c1087462 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -43,8 +43,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); - zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); + //zap_channel_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + //zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_clear_needed_tones(zchan); zap_channel_clear_detected_tones(zchan); From 829dad8c23d59cd2d3010dcf4466bf8151caf6ea Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Feb 2008 15:54:15 +0000 Subject: [PATCH 0764/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@390 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index ee16393eec..b4c1087462 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -43,8 +43,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); - zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); + //zap_channel_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); + //zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_clear_needed_tones(zchan); zap_channel_clear_detected_tones(zchan); From 0b25d3af9fcc808be41a3516cb2f88639aa69493 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 12 Feb 2008 00:54:57 +0000 Subject: [PATCH 0765/1766] initial addition of ss7boost client code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@392 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 12 +- libs/openzap/src/include/sigboost.h | 104 +++++ libs/openzap/src/include/ss7_boost_client.h | 137 +++++++ libs/openzap/src/ss7_boost_client.c | 415 ++++++++++++++++++++ 4 files changed, 666 insertions(+), 2 deletions(-) create mode 100644 libs/openzap/src/include/sigboost.h create mode 100644 libs/openzap/src/include/ss7_boost_client.h create mode 100644 libs/openzap/src/ss7_boost_client.c diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index a569b23a24..848e5fe2e9 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -66,7 +66,8 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c +$(SRC)/zap_wanpipe.c\ +$(SRC)/ss7_boost_client.c OBJS=\ $(SRC)/hashtable.o \ @@ -104,7 +105,8 @@ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o +$(SRC)/zap_wanpipe.o\ +$(SRC)/ss7_boost_client.o #SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") @@ -129,6 +131,7 @@ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_types.h \ $(SRC)/include/zap_wanpipe.h \ $(SRC)/include/zap_zt.h \ +$(SRC)/include/ss7_boost_client.h \ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ $(SRC)/isdn/include/DMS.h \ @@ -147,6 +150,11 @@ LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +SCTP_H=$(shell ls /usr/include/netinet/sctp.h 2>/dev/null) +ifneq ($(SCTP_H),) +CFLAGS += -DSS7BC_USE_SCTP +endif + PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) diff --git a/libs/openzap/src/include/sigboost.h b/libs/openzap/src/include/sigboost.h new file mode 100644 index 0000000000..009e4b26c6 --- /dev/null +++ b/libs/openzap/src/include/sigboost.h @@ -0,0 +1,104 @@ +/**************************************************************************** + * sigboost.h $Revision: 1.3 $ + * + * Definitions for the sigboost interface. + * + * WARNING WARNING WARNING + * + * This file is used by sangoma_mgd and perhaps other programs. Any changes + * to this file must be coordinated with other user programs, + * + * Copyright (C) 2005 Xygnada Technology, Inc. + * +****************************************************************************/ +#ifndef _SIGBOOST_H_ +#define _SIGBOOST_H_ + +#include +#include + +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, +}; + +#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 + +#pragma pack(1) +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 */ + /* redir string format: + * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection + * */ +} t_sigboost; +#pragma pack() + +#endif diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h new file mode 100644 index 0000000000..33a9e39a62 --- /dev/null +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2007, 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 _SS7BC_H +#define _SS7BC_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + + +#define ss7bc_test_flag(p,flag) ({ \ + ((p)->flags & (flag)); \ + }) + +#define ss7bc_set_flag(p,flag) do { \ + ((p)->flags |= (flag)); \ + } while (0) + +#define ss7bc_clear_flag(p,flag) do { \ + ((p)->flags &= ~(flag)); \ + } while (0) + +#define ss7bc_copy_flags(dest,src,flagz) do { \ + (dest)->flags &= ~(flagz); \ + (dest)->flags |= ((src)->flags & (flagz)); \ + } while (0) + +typedef t_sigboost ss7bc_event_t; +typedef uint32_t ss7bc_event_id_t; + +typedef struct smg_ip_cfg +{ + char local_ip[25]; + int local_port; + char remote_ip[25]; + int remote_port; +}smg_ip_cfg_t; + +struct ss7bc_connection { + zap_socket_t socket; + struct sockaddr_in local_addr; + struct sockaddr_in remote_addr; + ss7bc_event_t event; + struct hostent remote_hp; + struct hostent local_hp; + unsigned int flags; + pthread_mutex_t lock; + FILE *log; + unsigned int txseq; + unsigned int rxseq; + unsigned int txwindow; + unsigned int rxseq_reset; + smg_ip_cfg_t cfg; +}; + +typedef enum { + MSU_FLAG_EVENT = (1 << 0) +} ss7bc_flag_t; + +typedef struct ss7bc_connection ss7bc_connection_t; + +/* disable nagle's algorythm */ +static inline void sctp_no_nagle(int socket) +{ + int flag = 1; + setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int)); +} + +int ss7bc_connection_close(ss7bc_connection_t *mcon); +int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); +ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); +ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); +int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event); +void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); +void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id); +char *ss7bc_event_id_name(uint32_t event_id); + +#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 expandtab: + */ diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c new file mode 100644 index 0000000000..058d52d306 --- /dev/null +++ b/libs/openzap/src/ss7_boost_client.c @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2007, 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. + */ +#include "openzap.h" +#include + +#ifndef gethostbyname_r +extern int gethostbyname_r (__const char *__restrict __name, + struct hostent *__restrict __result_buf, + char *__restrict __buf, size_t __buflen, + struct hostent **__restrict __result, + int *__restrict __h_errnop); +#endif + +struct ss7bc_map { + uint32_t event_id; + char *name; +}; + +static struct ss7bc_map ss7bc_table[] = { + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, + {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, + {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, + {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, + {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, + {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, + {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, + {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"} +}; + + + +static int create_conn_socket(ss7bc_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)); +#ifdef SS7BC_USE_SCTP + mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); +#else + mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); +#endif + + 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); + +#ifdef SS7BC_USE_SCTP + 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 SS7BC_USE_SCTP + rc=listen(mcon->socket,100); + if (rc) { + close(mcon->socket); + mcon->socket = -1; + } +#endif + } + } + } + + return mcon->socket; +} + +int ss7bc_connection_close(ss7bc_connection_t *mcon) +{ + close(mcon->socket); + mcon->socket = -1; + memset(mcon, 0, sizeof(*mcon)); + + return 0; +} + +int ss7bc_connection_open(ss7bc_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; +} + +ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) +{ + unsigned int fromlen = sizeof(struct sockaddr_in); +#if 0 + ss7bc_event_t *event = &mcon->event; +#endif + 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_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", + mcon->rxseq,mcon->event.fseqno); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + } + +#if 0 + /* Debugging only not to be used in production because span/chan can be invalid */ + if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: RX Cmd=%s Invalid Span=%i Chan=%i\n", + ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + + errno=EAGAIN; + return NULL; + } +#endif + + + + + return &mcon->event; + } else { + if (iteration == 0) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: Invalid Event lenght from boost rxlen=%i evsz=%i\n", + bytes, sizeof(mcon->event)); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + } + } + + return NULL; +} + +ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) +{ + unsigned int fromlen = sizeof(struct sockaddr_in); +#if 0 + ss7bc_event_t *event = &mcon->event; +#endif + 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 0 + /* Debugging only not to be used in production because span/chan can be invalid */ + if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: RXp Cmd=%s Invalid Span=%i Chan=%i\n", + ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + + errno=EAGAIN; + return NULL; + } +#endif + + return &mcon->event; + } else { + if (iteration == 0) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", + bytes, sizeof(mcon->event)); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + } + } + + return NULL; +} + + +int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + int err; + if (!event) { + zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); + return -EINVAL; + } + + if (event->span > 16 || event->chan > 31) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", + ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + + return -1; + } + + gettimeofday(&event->tv,NULL); + + pthread_mutex_lock(&mcon->lock); + event->fseqno=mcon->txseq++; + event->bseqno=mcon->rxseq; + err=sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, + (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + pthread_mutex_unlock(&mcon->lock); + + if (err != sizeof(ss7bc_event_t)) { + err = -1; + } + +#if 0 + zap_log(ZAP_LOG_DEBUG, "TX EVENT\n"); + zap_log(ZAP_LOG_DEBUG, "===================================\n"); + zap_log(ZAP_LOG_DEBUG, " tType: %s (%0x HEX)\n", + ss7bc_event_id_name(event->event_id),event->event_id); + zap_log(ZAP_LOG_DEBUG, " tSpan: [%d]\n",event->span+1); + zap_log(ZAP_LOG_DEBUG, " tChan: [%d]\n",event->chan+1); + zap_log(ZAP_LOG_DEBUG, " tCalledNum: %s\n", + (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A")); + zap_log(ZAP_LOG_DEBUG, " tCallingNum: %s\n", + (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A")); + zap_log(ZAP_LOG_DEBUG, " tCause: %d\n",event->release_cause); + zap_log(ZAP_LOG_DEBUG, " tInterface: [w%dg%d]\n",event->span+1,event->chan+1); + zap_log(ZAP_LOG_DEBUG, " tEvent ID: [%d]\n",event->event_id); + zap_log(ZAP_LOG_DEBUG, " tSetup ID: [%d]\n",event->call_setup_id); + zap_log(ZAP_LOG_DEBUG, " tSeq: [%d]\n",event->fseqno); + zap_log(ZAP_LOG_DEBUG, "===================================\n"); +#endif + +#if 1 + zap_log(ZAP_LOG_DEBUG, + "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ss7bc_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") + ); +#endif + + +#if 0 + + zap_log(ZAP_LOG_DEBUG, + "\nTX EVENT\n" + "===================================\n" + " tType: %s (%0x HEX)\n" + " tSpan: [%d]\n" + " tChan: [%d]\n" + " tCalledNum: %s\n" + " tCallingNum: %s\n" + " tCause: %d\n" + " tInterface: [w%dg%d]\n" + " tEvent ID: [%d]\n" + " tSetup ID: [%d]\n" + " tSeq: [%d]\n" + "===================================\n" + "\n", + ss7bc_event_id_name(event->event_id), + event->event_id, + event->span+1, + event->chan+1, + (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"), + (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"), + event->release_cause, + event->span+1, + event->chan+1, + event->event_id, + event->call_setup_id, + event->fseqno + ); +#endif + + + return err; +} + +void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id) +{ + memset(event, 0, sizeof(ss7bc_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 ss7bc_event_init(ss7bc_event_t *event, ss7bc_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; +} + +char *ss7bc_event_id_name(uint32_t event_id) +{ + unsigned int x; + char *ret = NULL; + + for (x = 0 ; x < sizeof(ss7bc_table)/sizeof(struct ss7bc_map); x++) { + if (ss7bc_table[x].event_id == event_id) { + ret = ss7bc_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 expandtab: + */ + From 7897701da9b90b530f4b3dd234fbfd054a96b5af Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 12 Feb 2008 00:54:57 +0000 Subject: [PATCH 0766/1766] initial addition of ss7boost client code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@392 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 12 +- libs/freetdm/src/include/sigboost.h | 104 +++++ libs/freetdm/src/include/ss7_boost_client.h | 137 +++++++ libs/freetdm/src/ss7_boost_client.c | 415 ++++++++++++++++++++ 4 files changed, 666 insertions(+), 2 deletions(-) create mode 100644 libs/freetdm/src/include/sigboost.h create mode 100644 libs/freetdm/src/include/ss7_boost_client.h create mode 100644 libs/freetdm/src/ss7_boost_client.c diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index a569b23a24..848e5fe2e9 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -66,7 +66,8 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c +$(SRC)/zap_wanpipe.c\ +$(SRC)/ss7_boost_client.c OBJS=\ $(SRC)/hashtable.o \ @@ -104,7 +105,8 @@ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o +$(SRC)/zap_wanpipe.o\ +$(SRC)/ss7_boost_client.o #SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") @@ -129,6 +131,7 @@ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_types.h \ $(SRC)/include/zap_wanpipe.h \ $(SRC)/include/zap_zt.h \ +$(SRC)/include/ss7_boost_client.h \ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ $(SRC)/isdn/include/DMS.h \ @@ -147,6 +150,11 @@ LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +SCTP_H=$(shell ls /usr/include/netinet/sctp.h 2>/dev/null) +ifneq ($(SCTP_H),) +CFLAGS += -DSS7BC_USE_SCTP +endif + PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) diff --git a/libs/freetdm/src/include/sigboost.h b/libs/freetdm/src/include/sigboost.h new file mode 100644 index 0000000000..009e4b26c6 --- /dev/null +++ b/libs/freetdm/src/include/sigboost.h @@ -0,0 +1,104 @@ +/**************************************************************************** + * sigboost.h $Revision: 1.3 $ + * + * Definitions for the sigboost interface. + * + * WARNING WARNING WARNING + * + * This file is used by sangoma_mgd and perhaps other programs. Any changes + * to this file must be coordinated with other user programs, + * + * Copyright (C) 2005 Xygnada Technology, Inc. + * +****************************************************************************/ +#ifndef _SIGBOOST_H_ +#define _SIGBOOST_H_ + +#include +#include + +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, +}; + +#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 + +#pragma pack(1) +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 */ + /* redir string format: + * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection + * */ +} t_sigboost; +#pragma pack() + +#endif diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h new file mode 100644 index 0000000000..33a9e39a62 --- /dev/null +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2007, 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 _SS7BC_H +#define _SS7BC_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + + +#define ss7bc_test_flag(p,flag) ({ \ + ((p)->flags & (flag)); \ + }) + +#define ss7bc_set_flag(p,flag) do { \ + ((p)->flags |= (flag)); \ + } while (0) + +#define ss7bc_clear_flag(p,flag) do { \ + ((p)->flags &= ~(flag)); \ + } while (0) + +#define ss7bc_copy_flags(dest,src,flagz) do { \ + (dest)->flags &= ~(flagz); \ + (dest)->flags |= ((src)->flags & (flagz)); \ + } while (0) + +typedef t_sigboost ss7bc_event_t; +typedef uint32_t ss7bc_event_id_t; + +typedef struct smg_ip_cfg +{ + char local_ip[25]; + int local_port; + char remote_ip[25]; + int remote_port; +}smg_ip_cfg_t; + +struct ss7bc_connection { + zap_socket_t socket; + struct sockaddr_in local_addr; + struct sockaddr_in remote_addr; + ss7bc_event_t event; + struct hostent remote_hp; + struct hostent local_hp; + unsigned int flags; + pthread_mutex_t lock; + FILE *log; + unsigned int txseq; + unsigned int rxseq; + unsigned int txwindow; + unsigned int rxseq_reset; + smg_ip_cfg_t cfg; +}; + +typedef enum { + MSU_FLAG_EVENT = (1 << 0) +} ss7bc_flag_t; + +typedef struct ss7bc_connection ss7bc_connection_t; + +/* disable nagle's algorythm */ +static inline void sctp_no_nagle(int socket) +{ + int flag = 1; + setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int)); +} + +int ss7bc_connection_close(ss7bc_connection_t *mcon); +int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); +ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); +ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); +int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event); +void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); +void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id); +char *ss7bc_event_id_name(uint32_t event_id); + +#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 expandtab: + */ diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c new file mode 100644 index 0000000000..058d52d306 --- /dev/null +++ b/libs/freetdm/src/ss7_boost_client.c @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2007, 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. + */ +#include "openzap.h" +#include + +#ifndef gethostbyname_r +extern int gethostbyname_r (__const char *__restrict __name, + struct hostent *__restrict __result_buf, + char *__restrict __buf, size_t __buflen, + struct hostent **__restrict __result, + int *__restrict __h_errnop); +#endif + +struct ss7bc_map { + uint32_t event_id; + char *name; +}; + +static struct ss7bc_map ss7bc_table[] = { + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, + {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, + {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, + {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, + {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, + {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, + {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, + {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"} +}; + + + +static int create_conn_socket(ss7bc_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)); +#ifdef SS7BC_USE_SCTP + mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); +#else + mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); +#endif + + 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); + +#ifdef SS7BC_USE_SCTP + 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 SS7BC_USE_SCTP + rc=listen(mcon->socket,100); + if (rc) { + close(mcon->socket); + mcon->socket = -1; + } +#endif + } + } + } + + return mcon->socket; +} + +int ss7bc_connection_close(ss7bc_connection_t *mcon) +{ + close(mcon->socket); + mcon->socket = -1; + memset(mcon, 0, sizeof(*mcon)); + + return 0; +} + +int ss7bc_connection_open(ss7bc_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; +} + +ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) +{ + unsigned int fromlen = sizeof(struct sockaddr_in); +#if 0 + ss7bc_event_t *event = &mcon->event; +#endif + 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_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", + mcon->rxseq,mcon->event.fseqno); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + } + +#if 0 + /* Debugging only not to be used in production because span/chan can be invalid */ + if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: RX Cmd=%s Invalid Span=%i Chan=%i\n", + ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + + errno=EAGAIN; + return NULL; + } +#endif + + + + + return &mcon->event; + } else { + if (iteration == 0) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: Invalid Event lenght from boost rxlen=%i evsz=%i\n", + bytes, sizeof(mcon->event)); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + } + } + + return NULL; +} + +ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) +{ + unsigned int fromlen = sizeof(struct sockaddr_in); +#if 0 + ss7bc_event_t *event = &mcon->event; +#endif + 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 0 + /* Debugging only not to be used in production because span/chan can be invalid */ + if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: RXp Cmd=%s Invalid Span=%i Chan=%i\n", + ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + + errno=EAGAIN; + return NULL; + } +#endif + + return &mcon->event; + } else { + if (iteration == 0) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", + bytes, sizeof(mcon->event)); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + } + } + + return NULL; +} + + +int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + int err; + if (!event) { + zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); + return -EINVAL; + } + + if (event->span > 16 || event->chan > 31) { + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + zap_log(ZAP_LOG_DEBUG, + "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", + ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(ZAP_LOG_DEBUG, + "------------------------------------------\n"); + + return -1; + } + + gettimeofday(&event->tv,NULL); + + pthread_mutex_lock(&mcon->lock); + event->fseqno=mcon->txseq++; + event->bseqno=mcon->rxseq; + err=sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, + (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + pthread_mutex_unlock(&mcon->lock); + + if (err != sizeof(ss7bc_event_t)) { + err = -1; + } + +#if 0 + zap_log(ZAP_LOG_DEBUG, "TX EVENT\n"); + zap_log(ZAP_LOG_DEBUG, "===================================\n"); + zap_log(ZAP_LOG_DEBUG, " tType: %s (%0x HEX)\n", + ss7bc_event_id_name(event->event_id),event->event_id); + zap_log(ZAP_LOG_DEBUG, " tSpan: [%d]\n",event->span+1); + zap_log(ZAP_LOG_DEBUG, " tChan: [%d]\n",event->chan+1); + zap_log(ZAP_LOG_DEBUG, " tCalledNum: %s\n", + (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A")); + zap_log(ZAP_LOG_DEBUG, " tCallingNum: %s\n", + (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A")); + zap_log(ZAP_LOG_DEBUG, " tCause: %d\n",event->release_cause); + zap_log(ZAP_LOG_DEBUG, " tInterface: [w%dg%d]\n",event->span+1,event->chan+1); + zap_log(ZAP_LOG_DEBUG, " tEvent ID: [%d]\n",event->event_id); + zap_log(ZAP_LOG_DEBUG, " tSetup ID: [%d]\n",event->call_setup_id); + zap_log(ZAP_LOG_DEBUG, " tSeq: [%d]\n",event->fseqno); + zap_log(ZAP_LOG_DEBUG, "===================================\n"); +#endif + +#if 1 + zap_log(ZAP_LOG_DEBUG, + "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ss7bc_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") + ); +#endif + + +#if 0 + + zap_log(ZAP_LOG_DEBUG, + "\nTX EVENT\n" + "===================================\n" + " tType: %s (%0x HEX)\n" + " tSpan: [%d]\n" + " tChan: [%d]\n" + " tCalledNum: %s\n" + " tCallingNum: %s\n" + " tCause: %d\n" + " tInterface: [w%dg%d]\n" + " tEvent ID: [%d]\n" + " tSetup ID: [%d]\n" + " tSeq: [%d]\n" + "===================================\n" + "\n", + ss7bc_event_id_name(event->event_id), + event->event_id, + event->span+1, + event->chan+1, + (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"), + (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"), + event->release_cause, + event->span+1, + event->chan+1, + event->event_id, + event->call_setup_id, + event->fseqno + ); +#endif + + + return err; +} + +void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id) +{ + memset(event, 0, sizeof(ss7bc_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 ss7bc_event_init(ss7bc_event_t *event, ss7bc_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; +} + +char *ss7bc_event_id_name(uint32_t event_id) +{ + unsigned int x; + char *ret = NULL; + + for (x = 0 ; x < sizeof(ss7bc_table)/sizeof(struct ss7bc_map); x++) { + if (ss7bc_table[x].event_id == event_id) { + ret = ss7bc_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 expandtab: + */ + From ee89a1eb55b26908e65a61f87a3fcab34d49fbe8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 12 Feb 2008 18:38:26 +0000 Subject: [PATCH 0767/1766] ifdef for sctp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@393 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/ss7_boost_client.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h index 33a9e39a62..079893c7de 100644 --- a/libs/openzap/src/include/ss7_boost_client.h +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -44,7 +44,9 @@ #include #include #include +#ifdef SS7BC_USE_SCTP #include +#endif #include #include #include @@ -109,8 +111,10 @@ typedef struct ss7bc_connection ss7bc_connection_t; /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) { +#ifdef SS7BC_USE_SCTP int flag = 1; setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int)); +#endif } int ss7bc_connection_close(ss7bc_connection_t *mcon); From 108bb09a126ad48d7e3da50493aa9845d3894c68 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 12 Feb 2008 18:38:26 +0000 Subject: [PATCH 0768/1766] ifdef for sctp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@393 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/ss7_boost_client.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h index 33a9e39a62..079893c7de 100644 --- a/libs/freetdm/src/include/ss7_boost_client.h +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -44,7 +44,9 @@ #include #include #include +#ifdef SS7BC_USE_SCTP #include +#endif #include #include #include @@ -109,8 +111,10 @@ typedef struct ss7bc_connection ss7bc_connection_t; /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) { +#ifdef SS7BC_USE_SCTP int flag = 1; setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int)); +#endif } int ss7bc_connection_close(ss7bc_connection_t *mcon); From 6a9cbad9af79a31269ad7e53007b0eaefd32441d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Feb 2008 18:17:02 +0000 Subject: [PATCH 0769/1766] sync w/ libteletone changes from main repo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@394 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone.h | 9 +++++++++ libs/openzap/src/libteletone_detect.c | 2 ++ libs/openzap/src/libteletone_generate.c | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index aaf7b0ed47..db6accb97e 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -74,6 +74,9 @@ #ifdef __cplusplus extern "C" { #endif + +#include + #define TELETONE_MAX_DTMF_DIGITS 128 #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 @@ -101,6 +104,12 @@ typedef struct { typedef __int16 int16_t; #endif +#if (_MSC_VER >= 1400) // VC8+ +#define teletone_assert(expr) assert(expr);__analysis_assume( expr ) +#else +#define teletone_assert(expr) assert(expr) +#endif + #include #include diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 7bbdd697df..55cfcf60cd 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -432,6 +432,8 @@ 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; } diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index fdf4dd14f7..7771188c46 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -191,10 +191,13 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need) need *= ts->channels; if (need > ts->datalen) { + teletone_audio_t *tmp; ts->datalen = need + ts->dynamic; - if (!(ts->buffer = realloc(ts->buffer, ts->datalen))) { + tmp = realloc(ts->buffer, ts->datalen); + if (!tmp) { return -1; } + ts->buffer = tmp; } return 0; From 509593fc49227220bbda3d2f18b137bdf467a75d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 14 Feb 2008 18:17:02 +0000 Subject: [PATCH 0770/1766] sync w/ libteletone changes from main repo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@394 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone.h | 9 +++++++++ libs/freetdm/src/libteletone_detect.c | 2 ++ libs/freetdm/src/libteletone_generate.c | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index aaf7b0ed47..db6accb97e 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -74,6 +74,9 @@ #ifdef __cplusplus extern "C" { #endif + +#include + #define TELETONE_MAX_DTMF_DIGITS 128 #define TELETONE_MAX_TONES 6 #define TELETONE_TONE_RANGE 127 @@ -101,6 +104,12 @@ typedef struct { typedef __int16 int16_t; #endif +#if (_MSC_VER >= 1400) // VC8+ +#define teletone_assert(expr) assert(expr);__analysis_assume( expr ) +#else +#define teletone_assert(expr) assert(expr) +#endif + #include #include diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 7bbdd697df..55cfcf60cd 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -432,6 +432,8 @@ 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; } diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index fdf4dd14f7..7771188c46 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -191,10 +191,13 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need) need *= ts->channels; if (need > ts->datalen) { + teletone_audio_t *tmp; ts->datalen = need + ts->dynamic; - if (!(ts->buffer = realloc(ts->buffer, ts->datalen))) { + tmp = realloc(ts->buffer, ts->datalen); + if (!tmp) { return -1; } + ts->buffer = tmp; } return 0; From 4cb323b5acdc2910a558bd8ef23868ce802b6a40 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Feb 2008 20:26:06 +0000 Subject: [PATCH 0771/1766] fix shutdown race git-svn-id: http://svn.openzap.org/svn/openzap/trunk@395 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_analog.c | 2 +- libs/openzap/src/zap_io.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index b4c1087462..ef9d696dc5 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -218,7 +218,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) assert(interval != 0); - while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; zap_size_t dlen = 0; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2987164c69..05a26beda2 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -233,6 +233,11 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + zap_log(ZAP_LOG_INFO, "Waiting for thread to exit on channel %u:%u\n", zchan->span_id, zchan->chan_id); + zap_sleep(500); + } + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -1993,9 +1998,9 @@ zap_status_t zap_global_destroy(void) { unsigned int i,j; time_end(); - + + globals.running = 0; zap_span_close_all(); - globals.running = 0; zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) { From 42233ec499578b0d0cde5b8477ee81dcec3ea119 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Feb 2008 20:26:06 +0000 Subject: [PATCH 0772/1766] fix shutdown race git-svn-id: http://svn.openzap.org/svn/openzap/trunk@395 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_analog.c | 2 +- libs/freetdm/src/zap_io.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index b4c1087462..ef9d696dc5 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -218,7 +218,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) assert(interval != 0); - while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; zap_size_t dlen = 0; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2987164c69..05a26beda2 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -233,6 +233,11 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { + while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + zap_log(ZAP_LOG_INFO, "Waiting for thread to exit on channel %u:%u\n", zchan->span_id, zchan->chan_id); + zap_sleep(500); + } + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -1993,9 +1998,9 @@ zap_status_t zap_global_destroy(void) { unsigned int i,j; time_end(); - + + globals.running = 0; zap_span_close_all(); - globals.running = 0; zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) { From 081d5f2e527dfde7f8cbd4cc84190fd37f5b3a3a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 17 Feb 2008 10:33:21 +0000 Subject: [PATCH 0773/1766] try to release call table entry a bit more. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@396 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 3cd45dab33..f001029ac6 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -759,6 +759,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { + L3INT callIndex; Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; @@ -771,6 +772,12 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else { ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); } + if (pMes->CRV) { + /* Find the call using CRV */ + if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR) + return ret; + pTrunk->call[callIndex].InUse = 0; + } return ret; } From 7235194cc4d1dcd99bee190dffee9ad8802aaa65 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 17 Feb 2008 10:33:21 +0000 Subject: [PATCH 0774/1766] try to release call table entry a bit more. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@396 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 3cd45dab33..f001029ac6 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -759,6 +759,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { + L3INT callIndex; Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; L3INT state = Q931GetCallState(pTrunk, pMes->CRV); L3INT ret = Q931E_NO_ERROR; @@ -771,6 +772,12 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else { ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); } + if (pMes->CRV) { + /* Find the call using CRV */ + if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR) + return ret; + pTrunk->call[callIndex].InUse = 0; + } return ret; } From 60e5cec7cc80b1afbf2c9d21eea4cc21a3a6ae54 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 17 Feb 2008 21:52:17 +0000 Subject: [PATCH 0775/1766] autoconf for openzap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@397 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 226 ++++++++++++++++++ libs/openzap/Makefile.in | 222 +++++++++++++++++ libs/openzap/configure.ac | 51 ++++ libs/openzap/general.makefile | 3 - .../src/include/wanpipe_tdm_api_iface.h | 33 ++- libs/openzap/src/include/zap_zt.h | 6 + libs/openzap/src/zap_wanpipe.c | 4 + 7 files changed, 525 insertions(+), 20 deletions(-) create mode 100644 libs/openzap/Makefile.in create mode 100644 libs/openzap/configure.ac diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 848e5fe2e9..592ce77a2e 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -29,6 +29,232 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SRC=src +SOURCES=\ +$(SRC)/hashtable.c \ +$(SRC)/hashtable_itr.c \ +$(SRC)/zap_io.c \ +$(SRC)/zap_isdn.c \ +$(SRC)/zap_analog.c \ +$(SRC)/zap_config.c \ +$(SRC)/zap_callerid.c \ +$(SRC)/fsk.c \ +$(SRC)/uart.c \ +$(SRC)/g711.c \ +$(SRC)/libteletone_detect.c \ +$(SRC)/libteletone_generate.c \ +$(SRC)/zap_buffer.c \ +$(SRC)/zap_threadmutex.c \ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c \ +$(SRC)/zap_zt.c \ +$(SRC)/zap_wanpipe.c + +OBJS=\ +$(SRC)/hashtable.o \ +$(SRC)/hashtable_itr.o \ +$(SRC)/zap_io.o \ +$(SRC)/zap_isdn.o \ +$(SRC)/zap_analog.o \ +$(SRC)/zap_config.o \ +$(SRC)/zap_callerid.o \ +$(SRC)/fsk.o \ +$(SRC)/uart.o \ +$(SRC)/g711.o \ +$(SRC)/libteletone_detect.o \ +$(SRC)/libteletone_generate.o \ +$(SRC)/zap_buffer.o \ +$(SRC)/zap_threadmutex.o \ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ +$(SRC)/isdn/Q932mes.o \ +$(SRC)/zap_zt.o \ +$(SRC)/zap_wanpipe.o + +#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") + +HEADERS= $(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/wanpipe_tdm_api_iface.h \ +$(SRC)/include/zap_analog.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_isdn.h \ +$(SRC)/include/zap_skel.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_zt.h \ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + + +PWD=$(shell pwd) +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include +CFLAGS= $(INCS) $(ZAP_CFLAGS) +MYLIB=libopenzap.a +LIBPRIA=libpri.a +LIBPRI=./libpri +TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w + +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) + +ifneq ($(PIKA_DIR),) +ifneq ($(PIKA_LIB),) +OBJS += $(SRC)/zap_pika.o +CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +ADD_OBJS = $(PIKA_LIB) +endif +endif + +include general.makefile + +all: $(MYLIB) + +$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) + ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) + ranlib $(MYLIB) + +testapp: $(SRC)/testapp.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread + +testcid: $(SRC)/testcid.c $(MYLIB) + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + +testtones: $(SRC)/testtones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + +detect_tones: $(SRC)/detect_tones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm + +detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + +testisdn: $(SRC)/testisdn.c $(MYLIB) + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + +testanalog: $(SRC)/testanalog.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + +$(SRC)/priserver.o: $(SRC)/priserver.c + $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o + +$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c + $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o + +$(LIBPRI)/$(LIBPRIA): + cd libpri && make + +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) + +$(SRC)/zap_io.o: $(SRC)/zap_io.c + $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +%.o: %.c $(HEADERS) + $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +dox: + cd docs && doxygen $(PWD)/docs/Doxygen.conf + +mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.so + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi + +clean: mod_openzap-clean + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog + @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + + +# Copyright (c) 2007, Anthony Minessale II +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the original author; nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + SRC=src SOURCES=\ $(SRC)/hashtable.c \ diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in new file mode 100644 index 0000000000..3a057d258e --- /dev/null +++ b/libs/openzap/Makefile.in @@ -0,0 +1,222 @@ +# Copyright (c) 2007, Anthony Minessale II +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the original author; nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +CFLAGS=@COMP_VENDOR_CFLAGS@ +SRC=src +SOURCES=\ +$(SRC)/hashtable.c \ +$(SRC)/hashtable_itr.c \ +$(SRC)/zap_io.c \ +$(SRC)/zap_isdn.c \ +$(SRC)/zap_analog.c \ +$(SRC)/zap_config.c \ +$(SRC)/zap_callerid.c \ +$(SRC)/fsk.c \ +$(SRC)/uart.c \ +$(SRC)/g711.c \ +$(SRC)/libteletone_detect.c \ +$(SRC)/libteletone_generate.c \ +$(SRC)/zap_buffer.c \ +$(SRC)/zap_threadmutex.c \ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c \ +$(SRC)/zap_zt.c \ +$(SRC)/zap_wanpipe.c + +OBJS=\ +$(SRC)/hashtable.o \ +$(SRC)/hashtable_itr.o \ +$(SRC)/zap_io.o \ +$(SRC)/zap_isdn.o \ +$(SRC)/zap_analog.o \ +$(SRC)/zap_config.o \ +$(SRC)/zap_callerid.o \ +$(SRC)/fsk.o \ +$(SRC)/uart.o \ +$(SRC)/g711.o \ +$(SRC)/libteletone_detect.o \ +$(SRC)/libteletone_generate.o \ +$(SRC)/zap_buffer.o \ +$(SRC)/zap_threadmutex.o \ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ +$(SRC)/isdn/Q932mes.o \ +$(SRC)/zap_zt.o \ +$(SRC)/zap_wanpipe.o + +#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") + +HEADERS= $(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/wanpipe_tdm_api_iface.h \ +$(SRC)/include/zap_analog.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_isdn.h \ +$(SRC)/include/zap_skel.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_zt.h \ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + +PWD=$(shell pwd) +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include +CFLAGS+= $(INCS) $(ZAP_CFLAGS) +MYLIB=libopenzap.a +LIBPRIA=libpri.a +LIBPRI=./libpri +TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w + +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) + +ifneq ($(PIKA_DIR),) +ifneq ($(PIKA_LIB),) +OBJS += $(SRC)/zap_pika.o +CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +ADD_OBJS = $(PIKA_LIB) +endif +endif + +all: $(MYLIB) + +$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) + ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) + ranlib $(MYLIB) + +testapp: $(SRC)/testapp.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread + +testcid: $(SRC)/testcid.c $(MYLIB) + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + +testtones: $(SRC)/testtones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + +detect_tones: $(SRC)/detect_tones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm + +detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + +testisdn: $(SRC)/testisdn.c $(MYLIB) + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + +testanalog: $(SRC)/testanalog.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + +$(SRC)/priserver.o: $(SRC)/priserver.c + $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o + +$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c + $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o + +$(LIBPRI)/$(LIBPRIA): + cd libpri && make + +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) + +$(SRC)/zap_io.o: $(SRC)/zap_io.c + $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +%.o: %.c $(HEADERS) + $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +dox: + cd docs && doxygen $(PWD)/docs/Doxygen.conf + +mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.so + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi + +clean: mod_openzap-clean + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog + @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac new file mode 100644 index 0000000000..fc339546c1 --- /dev/null +++ b/libs/openzap/configure.ac @@ -0,0 +1,51 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.61) +AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.prg]) +AC_CONFIG_SRCDIR([src/libteletone_detect.c]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_MAKE_SET +AC_PROG_RANLIB + +# Check for com;iler type +AC_DEFUN([AX_COMPILER_VENDOR], +[ +AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor, + [ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown + # note: don't check for GCC first, since some other compilers define __GNUC__ + for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do + vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[ +#if !($vencpp) + thisisanerror; +#endif +])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break]) + done + ]) +]) +AC_ARG_ENABLE(enable_64, [ --enable-64 Enable 64bit compilation]) + +AX_COMPILER_VENDOR + +case "${ax_cv_c_compiler_vendor}" in +gnu) + COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + ;; +sun) + COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" + if test "$enable_64" = "yes" ; then + COMP_VENDOR_CFLAGS="-m64 $COMP_VENDOR_CFLAGS" + fi + ;; +*) + COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + ;; +esac + +COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" +AC_SUBST(COMP_VENDOR_CFLAGS) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/libs/openzap/general.makefile b/libs/openzap/general.makefile index 9a060c86c7..e69de29bb2 100644 --- a/libs/openzap/general.makefile +++ b/libs/openzap/general.makefile @@ -1,3 +0,0 @@ -CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter #-std=c99 -pedantic -Wno-unused-parameter - diff --git a/libs/openzap/src/include/wanpipe_tdm_api_iface.h b/libs/openzap/src/include/wanpipe_tdm_api_iface.h index f7406841f5..409469c58f 100644 --- a/libs/openzap/src/include/wanpipe_tdm_api_iface.h +++ b/libs/openzap/src/include/wanpipe_tdm_api_iface.h @@ -156,39 +156,38 @@ enum wanpipe_tdm_api_events { #define WP_TDMAPI_EVENT_TONE_RING 0x03 #define WP_TDMAPI_EVENT_TONE_CONGESTION 0x04 - typedef struct { - u_int8_t type; - u_int8_t mode; - u_int32_t time_stamp; - u_int16_t channel; - u_int32_t chan_map; + uint8_t type; + uint8_t mode; + uint32_t time_stamp; + uint16_t channel; + uint32_t chan_map; union { struct { - u_int8_t alarm; + uint8_t alarm; } te1_alarm; struct { - u_int8_t rbs_bits; + uint8_t rbs_bits; } te1_rbs; struct { - u_int8_t state; - u_int8_t sig; + uint8_t state; + uint8_t sig; } rm_hook; struct { - u_int8_t state; + uint8_t state; } rm_ring; struct { - u_int8_t type; + uint8_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 */ + uint8_t digit; /* DTMF: digit */ + uint8_t port; /* DTMF: SOUT/ROUT */ + uint8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - u_int16_t polarity; - u_int16_t ohttimer; + uint16_t polarity; + uint16_t ohttimer; } rm_common; } wp_tdm_api_event_u; #define wp_tdm_api_event_type type diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 46aab35eb6..0e16d29398 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -37,6 +37,12 @@ #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 */ diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 4537e547ff..6dd4d5db08 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -31,6 +31,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __sun +#include +#include +#endif #include "openzap.h" #include "zap_wanpipe.h" #include From 96a357af008e11d2e96d840d2a073c698b3d0b2a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 17 Feb 2008 21:52:17 +0000 Subject: [PATCH 0776/1766] autoconf for openzap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@397 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 226 ++++++++++++++++++ libs/freetdm/Makefile.in | 222 +++++++++++++++++ libs/freetdm/configure.ac | 51 ++++ libs/freetdm/general.makefile | 3 - .../src/include/wanpipe_tdm_api_iface.h | 33 ++- libs/freetdm/src/include/zap_zt.h | 6 + libs/freetdm/src/zap_wanpipe.c | 4 + 7 files changed, 525 insertions(+), 20 deletions(-) create mode 100644 libs/freetdm/Makefile.in create mode 100644 libs/freetdm/configure.ac diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 848e5fe2e9..592ce77a2e 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -29,6 +29,232 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SRC=src +SOURCES=\ +$(SRC)/hashtable.c \ +$(SRC)/hashtable_itr.c \ +$(SRC)/zap_io.c \ +$(SRC)/zap_isdn.c \ +$(SRC)/zap_analog.c \ +$(SRC)/zap_config.c \ +$(SRC)/zap_callerid.c \ +$(SRC)/fsk.c \ +$(SRC)/uart.c \ +$(SRC)/g711.c \ +$(SRC)/libteletone_detect.c \ +$(SRC)/libteletone_generate.c \ +$(SRC)/zap_buffer.c \ +$(SRC)/zap_threadmutex.c \ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c \ +$(SRC)/zap_zt.c \ +$(SRC)/zap_wanpipe.c + +OBJS=\ +$(SRC)/hashtable.o \ +$(SRC)/hashtable_itr.o \ +$(SRC)/zap_io.o \ +$(SRC)/zap_isdn.o \ +$(SRC)/zap_analog.o \ +$(SRC)/zap_config.o \ +$(SRC)/zap_callerid.o \ +$(SRC)/fsk.o \ +$(SRC)/uart.o \ +$(SRC)/g711.o \ +$(SRC)/libteletone_detect.o \ +$(SRC)/libteletone_generate.o \ +$(SRC)/zap_buffer.o \ +$(SRC)/zap_threadmutex.o \ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ +$(SRC)/isdn/Q932mes.o \ +$(SRC)/zap_zt.o \ +$(SRC)/zap_wanpipe.o + +#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") + +HEADERS= $(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/wanpipe_tdm_api_iface.h \ +$(SRC)/include/zap_analog.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_isdn.h \ +$(SRC)/include/zap_skel.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_zt.h \ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + + +PWD=$(shell pwd) +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include +CFLAGS= $(INCS) $(ZAP_CFLAGS) +MYLIB=libopenzap.a +LIBPRIA=libpri.a +LIBPRI=./libpri +TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w + +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) + +ifneq ($(PIKA_DIR),) +ifneq ($(PIKA_LIB),) +OBJS += $(SRC)/zap_pika.o +CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +ADD_OBJS = $(PIKA_LIB) +endif +endif + +include general.makefile + +all: $(MYLIB) + +$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) + ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) + ranlib $(MYLIB) + +testapp: $(SRC)/testapp.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread + +testcid: $(SRC)/testcid.c $(MYLIB) + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + +testtones: $(SRC)/testtones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + +detect_tones: $(SRC)/detect_tones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm + +detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + +testisdn: $(SRC)/testisdn.c $(MYLIB) + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + +testanalog: $(SRC)/testanalog.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + +$(SRC)/priserver.o: $(SRC)/priserver.c + $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o + +$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c + $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o + +$(LIBPRI)/$(LIBPRIA): + cd libpri && make + +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) + +$(SRC)/zap_io.o: $(SRC)/zap_io.c + $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +%.o: %.c $(HEADERS) + $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +dox: + cd docs && doxygen $(PWD)/docs/Doxygen.conf + +mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.so + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi + +clean: mod_openzap-clean + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog + @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + + +# Copyright (c) 2007, Anthony Minessale II +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the original author; nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + SRC=src SOURCES=\ $(SRC)/hashtable.c \ diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in new file mode 100644 index 0000000000..3a057d258e --- /dev/null +++ b/libs/freetdm/Makefile.in @@ -0,0 +1,222 @@ +# Copyright (c) 2007, Anthony Minessale II +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the original author; nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +CFLAGS=@COMP_VENDOR_CFLAGS@ +SRC=src +SOURCES=\ +$(SRC)/hashtable.c \ +$(SRC)/hashtable_itr.c \ +$(SRC)/zap_io.c \ +$(SRC)/zap_isdn.c \ +$(SRC)/zap_analog.c \ +$(SRC)/zap_config.c \ +$(SRC)/zap_callerid.c \ +$(SRC)/fsk.c \ +$(SRC)/uart.c \ +$(SRC)/g711.c \ +$(SRC)/libteletone_detect.c \ +$(SRC)/libteletone_generate.c \ +$(SRC)/zap_buffer.c \ +$(SRC)/zap_threadmutex.c \ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c \ +$(SRC)/zap_zt.c \ +$(SRC)/zap_wanpipe.c + +OBJS=\ +$(SRC)/hashtable.o \ +$(SRC)/hashtable_itr.o \ +$(SRC)/zap_io.o \ +$(SRC)/zap_isdn.o \ +$(SRC)/zap_analog.o \ +$(SRC)/zap_config.o \ +$(SRC)/zap_callerid.o \ +$(SRC)/fsk.o \ +$(SRC)/uart.o \ +$(SRC)/g711.o \ +$(SRC)/libteletone_detect.o \ +$(SRC)/libteletone_generate.o \ +$(SRC)/zap_buffer.o \ +$(SRC)/zap_threadmutex.o \ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ +$(SRC)/isdn/Q932mes.o \ +$(SRC)/zap_zt.o \ +$(SRC)/zap_wanpipe.o + +#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") + +HEADERS= $(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/wanpipe_tdm_api_iface.h \ +$(SRC)/include/zap_analog.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_isdn.h \ +$(SRC)/include/zap_skel.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_zt.h \ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + +PWD=$(shell pwd) +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include +CFLAGS+= $(INCS) $(ZAP_CFLAGS) +MYLIB=libopenzap.a +LIBPRIA=libpri.a +LIBPRI=./libpri +TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w + +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) + +ifneq ($(PIKA_DIR),) +ifneq ($(PIKA_LIB),) +OBJS += $(SRC)/zap_pika.o +CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +ADD_OBJS = $(PIKA_LIB) +endif +endif + +all: $(MYLIB) + +$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) + ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) + ranlib $(MYLIB) + +testapp: $(SRC)/testapp.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread + +testcid: $(SRC)/testcid.c $(MYLIB) + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + +testtones: $(SRC)/testtones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + +detect_tones: $(SRC)/detect_tones.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm + +detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + +testisdn: $(SRC)/testisdn.c $(MYLIB) + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + +testanalog: $(SRC)/testanalog.c $(MYLIB) + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + +$(SRC)/priserver.o: $(SRC)/priserver.c + $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o + +$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c + $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o + +$(LIBPRI)/$(LIBPRIA): + cd libpri && make + +priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) + +$(SRC)/zap_io.o: $(SRC)/zap_io.c + $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +%.o: %.c $(HEADERS) + $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + +dox: + cd docs && doxygen $(PWD)/docs/Doxygen.conf + +mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.so + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi + +clean: mod_openzap-clean + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog + @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac new file mode 100644 index 0000000000..fc339546c1 --- /dev/null +++ b/libs/freetdm/configure.ac @@ -0,0 +1,51 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.61) +AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.prg]) +AC_CONFIG_SRCDIR([src/libteletone_detect.c]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_MAKE_SET +AC_PROG_RANLIB + +# Check for com;iler type +AC_DEFUN([AX_COMPILER_VENDOR], +[ +AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor, + [ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown + # note: don't check for GCC first, since some other compilers define __GNUC__ + for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do + vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[ +#if !($vencpp) + thisisanerror; +#endif +])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break]) + done + ]) +]) +AC_ARG_ENABLE(enable_64, [ --enable-64 Enable 64bit compilation]) + +AX_COMPILER_VENDOR + +case "${ax_cv_c_compiler_vendor}" in +gnu) + COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + ;; +sun) + COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" + if test "$enable_64" = "yes" ; then + COMP_VENDOR_CFLAGS="-m64 $COMP_VENDOR_CFLAGS" + fi + ;; +*) + COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + ;; +esac + +COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" +AC_SUBST(COMP_VENDOR_CFLAGS) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/libs/freetdm/general.makefile b/libs/freetdm/general.makefile index 9a060c86c7..e69de29bb2 100644 --- a/libs/freetdm/general.makefile +++ b/libs/freetdm/general.makefile @@ -1,3 +0,0 @@ -CC=gcc -CC_CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter #-std=c99 -pedantic -Wno-unused-parameter - diff --git a/libs/freetdm/src/include/wanpipe_tdm_api_iface.h b/libs/freetdm/src/include/wanpipe_tdm_api_iface.h index f7406841f5..409469c58f 100644 --- a/libs/freetdm/src/include/wanpipe_tdm_api_iface.h +++ b/libs/freetdm/src/include/wanpipe_tdm_api_iface.h @@ -156,39 +156,38 @@ enum wanpipe_tdm_api_events { #define WP_TDMAPI_EVENT_TONE_RING 0x03 #define WP_TDMAPI_EVENT_TONE_CONGESTION 0x04 - typedef struct { - u_int8_t type; - u_int8_t mode; - u_int32_t time_stamp; - u_int16_t channel; - u_int32_t chan_map; + uint8_t type; + uint8_t mode; + uint32_t time_stamp; + uint16_t channel; + uint32_t chan_map; union { struct { - u_int8_t alarm; + uint8_t alarm; } te1_alarm; struct { - u_int8_t rbs_bits; + uint8_t rbs_bits; } te1_rbs; struct { - u_int8_t state; - u_int8_t sig; + uint8_t state; + uint8_t sig; } rm_hook; struct { - u_int8_t state; + uint8_t state; } rm_ring; struct { - u_int8_t type; + uint8_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 */ + uint8_t digit; /* DTMF: digit */ + uint8_t port; /* DTMF: SOUT/ROUT */ + uint8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - u_int16_t polarity; - u_int16_t ohttimer; + uint16_t polarity; + uint16_t ohttimer; } rm_common; } wp_tdm_api_event_u; #define wp_tdm_api_event_type type diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/include/zap_zt.h index 46aab35eb6..0e16d29398 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/include/zap_zt.h @@ -37,6 +37,12 @@ #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 */ diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 4537e547ff..6dd4d5db08 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -31,6 +31,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __sun +#include +#include +#endif #include "openzap.h" #include "zap_wanpipe.h" #include From 65b7e38b209bbb20106395d49265c56d78006549 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Feb 2008 15:43:54 +0000 Subject: [PATCH 0777/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@398 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index db9cb1ee4e..b3d36bd6ef 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -34,6 +34,10 @@ #include "zap_analog.h" #include "zap_isdn.h" +#ifndef __FUNCTION__ +#define __FUNCTION__ __SWITCH_FUNC__ +#endif + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); From 673501ae057c09244ab857b349944d40839a7425 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Feb 2008 15:43:54 +0000 Subject: [PATCH 0778/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@398 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index db9cb1ee4e..b3d36bd6ef 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -34,6 +34,10 @@ #include "zap_analog.h" #include "zap_isdn.h" +#ifndef __FUNCTION__ +#define __FUNCTION__ __SWITCH_FUNC__ +#endif + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); From 0d55659a6cadb65f21ab12cb69bf898c22096d49 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 16:12:26 +0000 Subject: [PATCH 0779/1766] only require 2.59 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@399 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index fc339546c1..920ff6cacb 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.61) +AC_PREREQ(2.59) AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.prg]) AC_CONFIG_SRCDIR([src/libteletone_detect.c]) From 26997e2bbe31951f609412d1616f983542302b14 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 16:12:26 +0000 Subject: [PATCH 0780/1766] only require 2.59 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@399 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index fc339546c1..920ff6cacb 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.61) +AC_PREREQ(2.59) AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.prg]) AC_CONFIG_SRCDIR([src/libteletone_detect.c]) From e702576e1f9b571a337015000b8715fcb79b9aa0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 16:15:24 +0000 Subject: [PATCH 0781/1766] tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@400 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 242 +-------------------- libs/openzap/mod_openzap/mod_openzap.c | 3 +- libs/openzap/src/fsk.c | 7 +- libs/openzap/src/include/openzap.h | 10 + libs/openzap/src/include/zap_threadmutex.h | 6 +- libs/openzap/src/zap_analog.c | 30 ++- libs/openzap/src/zap_callerid.c | 2 +- libs/openzap/src/zap_io.c | 34 +-- libs/openzap/src/zap_threadmutex.c | 10 +- libs/openzap/src/zap_zt.c | 9 +- 10 files changed, 72 insertions(+), 281 deletions(-) diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile index 592ce77a2e..ece84e085a 100644 --- a/libs/openzap/Makefile +++ b/libs/openzap/Makefile @@ -29,6 +29,7 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +CFLAGS=-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes SRC=src SOURCES=\ $(SRC)/hashtable.c \ @@ -138,10 +139,9 @@ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h - PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS= $(INCS) $(ZAP_CFLAGS) +CFLAGS+= $(INCS) $(ZAP_CFLAGS) MYLIB=libopenzap.a LIBPRIA=libpri.a LIBPRI=./libpri @@ -158,8 +158,6 @@ ADD_OBJS = $(PIKA_LIB) endif endif -include general.makefile - all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) @@ -222,239 +220,3 @@ mod_openzap-clean: clean: mod_openzap-clean rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi - - -# Copyright (c) 2007, Anthony Minessale II -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of the original author; nor the names of any contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -SRC=src -SOURCES=\ -$(SRC)/hashtable.c \ -$(SRC)/hashtable_itr.c \ -$(SRC)/zap_io.c \ -$(SRC)/zap_isdn.c \ -$(SRC)/zap_analog.c \ -$(SRC)/zap_config.c \ -$(SRC)/zap_callerid.c \ -$(SRC)/fsk.c \ -$(SRC)/uart.c \ -$(SRC)/g711.c \ -$(SRC)/libteletone_detect.c \ -$(SRC)/libteletone_generate.c \ -$(SRC)/zap_buffer.c \ -$(SRC)/zap_threadmutex.c \ -$(SRC)/isdn/EuroISDNStateNT.c \ -$(SRC)/isdn/EuroISDNStateTE.c \ -$(SRC)/isdn/mfifo.c \ -$(SRC)/isdn/Q921.c \ -$(SRC)/isdn/Q931api.c \ -$(SRC)/isdn/Q931.c \ -$(SRC)/isdn/Q931ie.c \ -$(SRC)/isdn/Q931mes.c \ -$(SRC)/isdn/Q931StateNT.c \ -$(SRC)/isdn/Q931StateTE.c \ -$(SRC)/isdn/nationalmes.c \ -$(SRC)/isdn/nationalStateNT.c \ -$(SRC)/isdn/nationalStateTE.c \ -$(SRC)/isdn/DMSmes.c \ -$(SRC)/isdn/DMSStateNT.c \ -$(SRC)/isdn/DMSStateTE.c \ -$(SRC)/isdn/5ESSmes.c \ -$(SRC)/isdn/5ESSStateNT.c \ -$(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c \ -$(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c\ -$(SRC)/ss7_boost_client.c - -OBJS=\ -$(SRC)/hashtable.o \ -$(SRC)/hashtable_itr.o \ -$(SRC)/zap_io.o \ -$(SRC)/zap_isdn.o \ -$(SRC)/zap_analog.o \ -$(SRC)/zap_config.o \ -$(SRC)/zap_callerid.o \ -$(SRC)/fsk.o \ -$(SRC)/uart.o \ -$(SRC)/g711.o \ -$(SRC)/libteletone_detect.o \ -$(SRC)/libteletone_generate.o \ -$(SRC)/zap_buffer.o \ -$(SRC)/zap_threadmutex.o \ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o \ -$(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o\ -$(SRC)/ss7_boost_client.o - -#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") - -HEADERS= $(SRC)/include/fsk.h \ -$(SRC)/include/g711.h \ -$(SRC)/include/hashtable.h \ -$(SRC)/include/hashtable_itr.h \ -$(SRC)/include/hashtable_private.h \ -$(SRC)/include/libteletone_detect.h \ -$(SRC)/include/libteletone_generate.h \ -$(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ -$(SRC)/include/sangoma_tdm_api.h \ -$(SRC)/include/uart.h \ -$(SRC)/include/wanpipe_tdm_api_iface.h \ -$(SRC)/include/zap_analog.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_isdn.h \ -$(SRC)/include/zap_skel.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_types.h \ -$(SRC)/include/zap_wanpipe.h \ -$(SRC)/include/zap_zt.h \ -$(SRC)/include/ss7_boost_client.h \ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - - -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS= $(INCS) $(ZAP_CFLAGS) -MYLIB=libopenzap.a -LIBPRIA=libpri.a -LIBPRI=./libpri -TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w - -SCTP_H=$(shell ls /usr/include/netinet/sctp.h 2>/dev/null) -ifneq ($(SCTP_H),) -CFLAGS += -DSS7BC_USE_SCTP -endif - -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -ifneq ($(PIKA_DIR),) -ifneq ($(PIKA_LIB),) -OBJS += $(SRC)/zap_pika.o -CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -ADD_OBJS = $(PIKA_LIB) -endif -endif - -include general.makefile - -all: $(MYLIB) - -$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - ranlib $(MYLIB) - -testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread - -testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread - -testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm - -detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm - -detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm - -testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread - -testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread - -$(SRC)/priserver.o: $(SRC)/priserver.c - $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o - -$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c - $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o - -$(LIBPRI)/$(LIBPRIA): - cd libpri && make - -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) - -$(SRC)/zap_io.o: $(SRC)/zap_io.c - $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -%.o: %.c $(HEADERS) - $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -dox: - cd docs && doxygen $(PWD)/docs/Doxygen.conf - -mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make - -mod_openzap: mod_openzap/mod_openzap.so - -mod_openzap-install: mod_openzap - cd mod_openzap && make install - -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi - -clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog - @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi - - diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b3d36bd6ef..c495e11f9e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1187,7 +1187,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (switch_strlen_zero(fail_regex)) { fail_regex = NULL; } - + + zap_log(ZAP_LOG_DEBUG, "got DTMF sig [%s]\n", dtmf); switch_set_string(sigmsg->channel->caller_data.collected, dtmf); if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { diff --git a/libs/openzap/src/fsk.c b/libs/openzap/src/fsk.c index bed3e12a64..773b0deaae 100644 --- a/libs/openzap/src/fsk.c +++ b/libs/openzap/src/fsk.c @@ -307,21 +307,22 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) if (handle->cellpos > 1.0) { handle->cellpos -= 1.0; - switch (handle->state) { case FSK_STATE_DATA: - { + { + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); } break; case FSK_STATE_CHANSEIZE: { + if (handle->last_bit != handle->current_bit) { handle->conscutive_state_bits++; } else { handle->conscutive_state_bits = 0; } - + if (handle->conscutive_state_bits > 15) { handle->state = FSK_STATE_CARRIERSIG; handle->conscutive_state_bits = 0; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 57a0081ab1..705ac4bb5e 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -493,6 +493,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); +void zap_channel_flush_dtmf(zap_channel_t *zchan); zap_time_t zap_current_time_in_ms(void); zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); @@ -531,6 +532,15 @@ ZIO_CODEC_FUNCTION(zio_alaw2slin); ZIO_CODEC_FUNCTION(zio_ulaw2alaw); ZIO_CODEC_FUNCTION(zio_alaw2ulaw); +#ifdef DEBUG_LOCKS +#define zap_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_lock(_x) +#define zap_mutex_trylock(_x) printf("++++++try %s:%d\n", __FILE__, __LINE__) && _zap_mutex_trylock(_x) +#define zap_mutex_unlock(_x) printf("------unlock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_unlock(_x) +#else +#define zap_mutex_lock(_x) _zap_mutex_lock(_x) +#define zap_mutex_trylock(_x) _zap_mutex_trylock(_x) +#define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) +#endif #endif diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index 1a9061429e..f187bc516f 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -32,9 +32,9 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat void zap_thread_override_default_stacksize(zap_size_t size); zap_status_t zap_mutex_create(zap_mutex_t **mutex); zap_status_t zap_mutex_destroy(zap_mutex_t **mutex); -zap_status_t zap_mutex_lock(zap_mutex_t *mutex); -zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); -zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); +zap_status_t _zap_mutex_lock(zap_mutex_t *mutex); +zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex); +zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex); #endif diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index ef9d696dc5..ce01ffaa68 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -43,8 +43,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); - //zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_clear_needed_tones(zchan); zap_channel_clear_detected_tones(zchan); @@ -185,7 +183,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.buffer = NULL; if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n"); + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); goto done; } @@ -226,12 +224,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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); } } @@ -355,7 +354,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { 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); } @@ -569,7 +569,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)) + 3000; + dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani)) + 2000; } } } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { @@ -658,7 +658,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even { 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; @@ -669,15 +670,16 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); 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++; @@ -693,6 +695,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } + } break; case ZAP_OOB_FLASH: @@ -724,6 +727,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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_channel_run, event->channel); } } else { @@ -736,8 +741,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } } } - - zap_mutex_unlock(event->channel->mutex); + if (locked) { + zap_mutex_unlock(event->channel->mutex); + } return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 8940569ec0..e3cb6d9050 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -18,7 +18,7 @@ static void fsk_byte_handler (void *x, int data) if (state->dlen) { goto add_byte; } - + if (state->bpos == 1) { state->blen = byte; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 05a26beda2..581af7b6dc 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -436,8 +436,10 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha if (!new_chan->dtmf_off) { new_chan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; } + zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -814,10 +816,12 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) assert(zchan != NULL); if (zap_test_flag(zchan, ZAP_CHANNEL_SUSPENDED)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is suspended"); return ZAP_FAIL; } - + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Channel is not ready or is in use %d %d", zap_test_flag(zchan, ZAP_CHANNEL_READY), status); return status; } @@ -828,9 +832,11 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); } + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); } - zap_mutex_unlock(zchan->mutex); + zap_mutex_unlock(zchan->mutex); return status; } @@ -894,8 +900,6 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) zap_status_t zap_channel_done(zap_channel_t *zchan) { - int i; - assert(zchan != NULL); memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); @@ -903,12 +907,6 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); - for (i = 0; i < 2; i++) { - if (zchan->fds[i] > -1) { - close(zchan->fds[i]); - zchan->fds[i] = -1; - } - } return ZAP_SUCCESS; } @@ -1019,7 +1017,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo close(zchan->fds[0]); zchan->fds[0] = -1; } - if ((zchan->fds[0] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + if ((zchan->fds[0] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path); GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1031,10 +1030,11 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { char *path = (char *) obj; if (zchan->fds[1] > 0) { - close(zchan->fds[0]); + close(zchan->fds[1]); zchan->fds[1] = -1; } - if ((zchan->fds[1] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + if ((zchan->fds[1] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path); GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1432,6 +1432,14 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t return bytes; } +void zap_channel_flush_dtmf(zap_channel_t *zchan) +{ + if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { + zap_mutex_lock(zchan->mutex); + zap_buffer_zero(zchan->digit_buffer); + zap_mutex_unlock(zchan->mutex); + } +} zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) { diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index e82d6a3937..7534d3c965 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -184,7 +184,7 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) return ZAP_SUCCESS; } -zap_status_t zap_mutex_lock(zap_mutex_t *mutex) +zap_status_t _zap_mutex_lock(zap_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); @@ -195,7 +195,7 @@ zap_status_t zap_mutex_lock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t zap_mutex_trylock(zap_mutex_t *mutex) +zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) @@ -207,7 +207,7 @@ zap_status_t zap_mutex_trylock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) +zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); @@ -218,6 +218,10 @@ zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) return ZAP_SUCCESS; } + + + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 43d434036d..396aeaacca 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -88,6 +88,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za struct zt_chanconfig cc; memset(&cc, 0, sizeof(cc)); cc.chan = cc.master = x; + switch(type) { case ZAP_CHAN_TYPE_FXS: { @@ -126,11 +127,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za default: break; } + if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", - path, x, CONTROL_FD, strerror(errno)); - close(sockfd); - break; + 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", path, x, CONTROL_FD, strerror(errno)); } } @@ -319,7 +318,7 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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 { From 6ec135418a7b2be3f4c969fc5187ec428443c5d7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 16:15:24 +0000 Subject: [PATCH 0782/1766] tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@400 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 242 +-------------------- libs/freetdm/mod_openzap/mod_openzap.c | 3 +- libs/freetdm/src/fsk.c | 7 +- libs/freetdm/src/include/openzap.h | 10 + libs/freetdm/src/include/zap_threadmutex.h | 6 +- libs/freetdm/src/zap_analog.c | 30 ++- libs/freetdm/src/zap_callerid.c | 2 +- libs/freetdm/src/zap_io.c | 34 +-- libs/freetdm/src/zap_threadmutex.c | 10 +- libs/freetdm/src/zap_zt.c | 9 +- 10 files changed, 72 insertions(+), 281 deletions(-) diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile index 592ce77a2e..ece84e085a 100644 --- a/libs/freetdm/Makefile +++ b/libs/freetdm/Makefile @@ -29,6 +29,7 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +CFLAGS=-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes SRC=src SOURCES=\ $(SRC)/hashtable.c \ @@ -138,10 +139,9 @@ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h - PWD=$(shell pwd) INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS= $(INCS) $(ZAP_CFLAGS) +CFLAGS+= $(INCS) $(ZAP_CFLAGS) MYLIB=libopenzap.a LIBPRIA=libpri.a LIBPRI=./libpri @@ -158,8 +158,6 @@ ADD_OBJS = $(PIKA_LIB) endif endif -include general.makefile - all: $(MYLIB) $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) @@ -222,239 +220,3 @@ mod_openzap-clean: clean: mod_openzap-clean rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi - - -# Copyright (c) 2007, Anthony Minessale II -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of the original author; nor the names of any contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -SRC=src -SOURCES=\ -$(SRC)/hashtable.c \ -$(SRC)/hashtable_itr.c \ -$(SRC)/zap_io.c \ -$(SRC)/zap_isdn.c \ -$(SRC)/zap_analog.c \ -$(SRC)/zap_config.c \ -$(SRC)/zap_callerid.c \ -$(SRC)/fsk.c \ -$(SRC)/uart.c \ -$(SRC)/g711.c \ -$(SRC)/libteletone_detect.c \ -$(SRC)/libteletone_generate.c \ -$(SRC)/zap_buffer.c \ -$(SRC)/zap_threadmutex.c \ -$(SRC)/isdn/EuroISDNStateNT.c \ -$(SRC)/isdn/EuroISDNStateTE.c \ -$(SRC)/isdn/mfifo.c \ -$(SRC)/isdn/Q921.c \ -$(SRC)/isdn/Q931api.c \ -$(SRC)/isdn/Q931.c \ -$(SRC)/isdn/Q931ie.c \ -$(SRC)/isdn/Q931mes.c \ -$(SRC)/isdn/Q931StateNT.c \ -$(SRC)/isdn/Q931StateTE.c \ -$(SRC)/isdn/nationalmes.c \ -$(SRC)/isdn/nationalStateNT.c \ -$(SRC)/isdn/nationalStateTE.c \ -$(SRC)/isdn/DMSmes.c \ -$(SRC)/isdn/DMSStateNT.c \ -$(SRC)/isdn/DMSStateTE.c \ -$(SRC)/isdn/5ESSmes.c \ -$(SRC)/isdn/5ESSStateNT.c \ -$(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c \ -$(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c\ -$(SRC)/ss7_boost_client.c - -OBJS=\ -$(SRC)/hashtable.o \ -$(SRC)/hashtable_itr.o \ -$(SRC)/zap_io.o \ -$(SRC)/zap_isdn.o \ -$(SRC)/zap_analog.o \ -$(SRC)/zap_config.o \ -$(SRC)/zap_callerid.o \ -$(SRC)/fsk.o \ -$(SRC)/uart.o \ -$(SRC)/g711.o \ -$(SRC)/libteletone_detect.o \ -$(SRC)/libteletone_generate.o \ -$(SRC)/zap_buffer.o \ -$(SRC)/zap_threadmutex.o \ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o \ -$(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o\ -$(SRC)/ss7_boost_client.o - -#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") - -HEADERS= $(SRC)/include/fsk.h \ -$(SRC)/include/g711.h \ -$(SRC)/include/hashtable.h \ -$(SRC)/include/hashtable_itr.h \ -$(SRC)/include/hashtable_private.h \ -$(SRC)/include/libteletone_detect.h \ -$(SRC)/include/libteletone_generate.h \ -$(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ -$(SRC)/include/sangoma_tdm_api.h \ -$(SRC)/include/uart.h \ -$(SRC)/include/wanpipe_tdm_api_iface.h \ -$(SRC)/include/zap_analog.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_isdn.h \ -$(SRC)/include/zap_skel.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_types.h \ -$(SRC)/include/zap_wanpipe.h \ -$(SRC)/include/zap_zt.h \ -$(SRC)/include/ss7_boost_client.h \ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - - -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS= $(INCS) $(ZAP_CFLAGS) -MYLIB=libopenzap.a -LIBPRIA=libpri.a -LIBPRI=./libpri -TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w - -SCTP_H=$(shell ls /usr/include/netinet/sctp.h 2>/dev/null) -ifneq ($(SCTP_H),) -CFLAGS += -DSS7BC_USE_SCTP -endif - -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -ifneq ($(PIKA_DIR),) -ifneq ($(PIKA_LIB),) -OBJS += $(SRC)/zap_pika.o -CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -ADD_OBJS = $(PIKA_LIB) -endif -endif - -include general.makefile - -all: $(MYLIB) - -$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - ranlib $(MYLIB) - -testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread - -testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread - -testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm - -detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm - -detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm - -testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread - -testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread - -$(SRC)/priserver.o: $(SRC)/priserver.c - $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o - -$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c - $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o - -$(LIBPRI)/$(LIBPRIA): - cd libpri && make - -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) - -$(SRC)/zap_io.o: $(SRC)/zap_io.c - $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -%.o: %.c $(HEADERS) - $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -dox: - cd docs && doxygen $(PWD)/docs/Doxygen.conf - -mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make - -mod_openzap: mod_openzap/mod_openzap.so - -mod_openzap-install: mod_openzap - cd mod_openzap && make install - -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi - -clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog - @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi - - diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index b3d36bd6ef..c495e11f9e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1187,7 +1187,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (switch_strlen_zero(fail_regex)) { fail_regex = NULL; } - + + zap_log(ZAP_LOG_DEBUG, "got DTMF sig [%s]\n", dtmf); switch_set_string(sigmsg->channel->caller_data.collected, dtmf); if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index bed3e12a64..773b0deaae 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -307,21 +307,22 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample) if (handle->cellpos > 1.0) { handle->cellpos -= 1.0; - switch (handle->state) { case FSK_STATE_DATA: - { + { + (*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit); } break; case FSK_STATE_CHANSEIZE: { + if (handle->last_bit != handle->current_bit) { handle->conscutive_state_bits++; } else { handle->conscutive_state_bits = 0; } - + if (handle->conscutive_state_bits > 15) { handle->state = FSK_STATE_CARRIERSIG; handle->conscutive_state_bits = 0; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 57a0081ab1..705ac4bb5e 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -493,6 +493,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); +void zap_channel_flush_dtmf(zap_channel_t *zchan); zap_time_t zap_current_time_in_ms(void); zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); @@ -531,6 +532,15 @@ ZIO_CODEC_FUNCTION(zio_alaw2slin); ZIO_CODEC_FUNCTION(zio_ulaw2alaw); ZIO_CODEC_FUNCTION(zio_alaw2ulaw); +#ifdef DEBUG_LOCKS +#define zap_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_lock(_x) +#define zap_mutex_trylock(_x) printf("++++++try %s:%d\n", __FILE__, __LINE__) && _zap_mutex_trylock(_x) +#define zap_mutex_unlock(_x) printf("------unlock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_unlock(_x) +#else +#define zap_mutex_lock(_x) _zap_mutex_lock(_x) +#define zap_mutex_trylock(_x) _zap_mutex_trylock(_x) +#define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) +#endif #endif diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index 1a9061429e..f187bc516f 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -32,9 +32,9 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat void zap_thread_override_default_stacksize(zap_size_t size); zap_status_t zap_mutex_create(zap_mutex_t **mutex); zap_status_t zap_mutex_destroy(zap_mutex_t **mutex); -zap_status_t zap_mutex_lock(zap_mutex_t *mutex); -zap_status_t zap_mutex_trylock(zap_mutex_t *mutex); -zap_status_t zap_mutex_unlock(zap_mutex_t *mutex); +zap_status_t _zap_mutex_lock(zap_mutex_t *mutex); +zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex); +zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex); #endif diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index ef9d696dc5..ce01ffaa68 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -43,8 +43,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj); 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_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul"); - //zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul"); zap_channel_clear_needed_tones(zchan); zap_channel_clear_detected_tones(zchan); @@ -185,7 +183,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) ts.buffer = NULL; if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n"); + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); goto done; } @@ -226,12 +224,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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); } } @@ -355,7 +354,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { 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); } @@ -569,7 +569,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)) + 3000; + dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani)) + 2000; } } } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { @@ -658,7 +658,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even { 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; @@ -669,15 +670,16 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { + if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); 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++; @@ -693,6 +695,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } + } break; case ZAP_OOB_FLASH: @@ -724,6 +727,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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_channel_run, event->channel); } } else { @@ -736,8 +741,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } } } - - zap_mutex_unlock(event->channel->mutex); + if (locked) { + zap_mutex_unlock(event->channel->mutex); + } return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 8940569ec0..e3cb6d9050 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -18,7 +18,7 @@ static void fsk_byte_handler (void *x, int data) if (state->dlen) { goto add_byte; } - + if (state->bpos == 1) { state->blen = byte; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 05a26beda2..581af7b6dc 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -436,8 +436,10 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha if (!new_chan->dtmf_off) { new_chan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; } + zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -814,10 +816,12 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) assert(zchan != NULL); if (zap_test_flag(zchan, ZAP_CHANNEL_SUSPENDED)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is suspended"); return ZAP_FAIL; } - + if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Channel is not ready or is in use %d %d", zap_test_flag(zchan, ZAP_CHANNEL_READY), status); return status; } @@ -828,9 +832,11 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if (status == ZAP_SUCCESS) { zap_set_flag(zchan, ZAP_CHANNEL_OPEN); } + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); } - zap_mutex_unlock(zchan->mutex); + zap_mutex_unlock(zchan->mutex); return status; } @@ -894,8 +900,6 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) zap_status_t zap_channel_done(zap_channel_t *zchan) { - int i; - assert(zchan != NULL); memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); @@ -903,12 +907,6 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); - for (i = 0; i < 2; i++) { - if (zchan->fds[i] > -1) { - close(zchan->fds[i]); - zchan->fds[i] = -1; - } - } return ZAP_SUCCESS; } @@ -1019,7 +1017,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo close(zchan->fds[0]); zchan->fds[0] = -1; } - if ((zchan->fds[0] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + if ((zchan->fds[0] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path); GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1031,10 +1030,11 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo { char *path = (char *) obj; if (zchan->fds[1] > 0) { - close(zchan->fds[0]); + close(zchan->fds[1]); zchan->fds[1] = -1; } - if ((zchan->fds[1] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) { + if ((zchan->fds[1] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path); GOTO_STATUS(done, ZAP_SUCCESS); } @@ -1432,6 +1432,14 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t return bytes; } +void zap_channel_flush_dtmf(zap_channel_t *zchan) +{ + if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { + zap_mutex_lock(zchan->mutex); + zap_buffer_zero(zchan->digit_buffer); + zap_mutex_unlock(zchan->mutex); + } +} zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) { diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index e82d6a3937..7534d3c965 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -184,7 +184,7 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) return ZAP_SUCCESS; } -zap_status_t zap_mutex_lock(zap_mutex_t *mutex) +zap_status_t _zap_mutex_lock(zap_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); @@ -195,7 +195,7 @@ zap_status_t zap_mutex_lock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t zap_mutex_trylock(zap_mutex_t *mutex) +zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) @@ -207,7 +207,7 @@ zap_status_t zap_mutex_trylock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) +zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); @@ -218,6 +218,10 @@ zap_status_t zap_mutex_unlock(zap_mutex_t *mutex) return ZAP_SUCCESS; } + + + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 43d434036d..396aeaacca 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -88,6 +88,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za struct zt_chanconfig cc; memset(&cc, 0, sizeof(cc)); cc.chan = cc.master = x; + switch(type) { case ZAP_CHAN_TYPE_FXS: { @@ -126,11 +127,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za default: break; } + if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", - path, x, CONTROL_FD, strerror(errno)); - close(sockfd); - break; + 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", path, x, CONTROL_FD, strerror(errno)); } } @@ -319,7 +318,7 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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 { From 54fb9a3ca02c93ee6f0e45183811d81b030f3461 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 16:22:39 +0000 Subject: [PATCH 0783/1766] tweak cflags/cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@401 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile | 222 ---------------------------------- libs/openzap/configure.ac | 4 +- libs/openzap/general.makefile | 0 3 files changed, 2 insertions(+), 224 deletions(-) delete mode 100644 libs/openzap/Makefile delete mode 100644 libs/openzap/general.makefile diff --git a/libs/openzap/Makefile b/libs/openzap/Makefile deleted file mode 100644 index ece84e085a..0000000000 --- a/libs/openzap/Makefile +++ /dev/null @@ -1,222 +0,0 @@ -# Copyright (c) 2007, Anthony Minessale II -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of the original author; nor the names of any contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CFLAGS=-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -SRC=src -SOURCES=\ -$(SRC)/hashtable.c \ -$(SRC)/hashtable_itr.c \ -$(SRC)/zap_io.c \ -$(SRC)/zap_isdn.c \ -$(SRC)/zap_analog.c \ -$(SRC)/zap_config.c \ -$(SRC)/zap_callerid.c \ -$(SRC)/fsk.c \ -$(SRC)/uart.c \ -$(SRC)/g711.c \ -$(SRC)/libteletone_detect.c \ -$(SRC)/libteletone_generate.c \ -$(SRC)/zap_buffer.c \ -$(SRC)/zap_threadmutex.c \ -$(SRC)/isdn/EuroISDNStateNT.c \ -$(SRC)/isdn/EuroISDNStateTE.c \ -$(SRC)/isdn/mfifo.c \ -$(SRC)/isdn/Q921.c \ -$(SRC)/isdn/Q931api.c \ -$(SRC)/isdn/Q931.c \ -$(SRC)/isdn/Q931ie.c \ -$(SRC)/isdn/Q931mes.c \ -$(SRC)/isdn/Q931StateNT.c \ -$(SRC)/isdn/Q931StateTE.c \ -$(SRC)/isdn/nationalmes.c \ -$(SRC)/isdn/nationalStateNT.c \ -$(SRC)/isdn/nationalStateTE.c \ -$(SRC)/isdn/DMSmes.c \ -$(SRC)/isdn/DMSStateNT.c \ -$(SRC)/isdn/DMSStateTE.c \ -$(SRC)/isdn/5ESSmes.c \ -$(SRC)/isdn/5ESSStateNT.c \ -$(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c \ -$(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c - -OBJS=\ -$(SRC)/hashtable.o \ -$(SRC)/hashtable_itr.o \ -$(SRC)/zap_io.o \ -$(SRC)/zap_isdn.o \ -$(SRC)/zap_analog.o \ -$(SRC)/zap_config.o \ -$(SRC)/zap_callerid.o \ -$(SRC)/fsk.o \ -$(SRC)/uart.o \ -$(SRC)/g711.o \ -$(SRC)/libteletone_detect.o \ -$(SRC)/libteletone_generate.o \ -$(SRC)/zap_buffer.o \ -$(SRC)/zap_threadmutex.o \ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o \ -$(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o - -#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") - -HEADERS= $(SRC)/include/fsk.h \ -$(SRC)/include/g711.h \ -$(SRC)/include/hashtable.h \ -$(SRC)/include/hashtable_itr.h \ -$(SRC)/include/hashtable_private.h \ -$(SRC)/include/libteletone_detect.h \ -$(SRC)/include/libteletone_generate.h \ -$(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ -$(SRC)/include/sangoma_tdm_api.h \ -$(SRC)/include/uart.h \ -$(SRC)/include/wanpipe_tdm_api_iface.h \ -$(SRC)/include/zap_analog.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_isdn.h \ -$(SRC)/include/zap_skel.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_types.h \ -$(SRC)/include/zap_wanpipe.h \ -$(SRC)/include/zap_zt.h \ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -MYLIB=libopenzap.a -LIBPRIA=libpri.a -LIBPRI=./libpri -TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w - -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -ifneq ($(PIKA_DIR),) -ifneq ($(PIKA_LIB),) -OBJS += $(SRC)/zap_pika.o -CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -ADD_OBJS = $(PIKA_LIB) -endif -endif - -all: $(MYLIB) - -$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - ranlib $(MYLIB) - -testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread - -testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread - -testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm - -detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm - -detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm - -testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread - -testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread - -$(SRC)/priserver.o: $(SRC)/priserver.c - $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o - -$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c - $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o - -$(LIBPRI)/$(LIBPRIA): - cd libpri && make - -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) - -$(SRC)/zap_io.o: $(SRC)/zap_io.c - $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -%.o: %.c $(HEADERS) - $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -dox: - cd docs && doxygen $(PWD)/docs/Doxygen.conf - -mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make - -mod_openzap: mod_openzap/mod_openzap.so - -mod_openzap-install: mod_openzap - cd mod_openzap && make install - -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi - -clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog - @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 920ff6cacb..a3512e95a1 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -32,7 +32,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" @@ -41,7 +41,7 @@ sun) fi ;; *) - COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" ;; esac diff --git a/libs/openzap/general.makefile b/libs/openzap/general.makefile deleted file mode 100644 index e69de29bb2..0000000000 From 47ba69491dfdbf025e1a3cc3b729ac337b4f9382 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 16:22:39 +0000 Subject: [PATCH 0784/1766] tweak cflags/cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@401 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile | 222 ---------------------------------- libs/freetdm/configure.ac | 4 +- libs/freetdm/general.makefile | 0 3 files changed, 2 insertions(+), 224 deletions(-) delete mode 100644 libs/freetdm/Makefile delete mode 100644 libs/freetdm/general.makefile diff --git a/libs/freetdm/Makefile b/libs/freetdm/Makefile deleted file mode 100644 index ece84e085a..0000000000 --- a/libs/freetdm/Makefile +++ /dev/null @@ -1,222 +0,0 @@ -# Copyright (c) 2007, Anthony Minessale II -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of the original author; nor the names of any contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CFLAGS=-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -SRC=src -SOURCES=\ -$(SRC)/hashtable.c \ -$(SRC)/hashtable_itr.c \ -$(SRC)/zap_io.c \ -$(SRC)/zap_isdn.c \ -$(SRC)/zap_analog.c \ -$(SRC)/zap_config.c \ -$(SRC)/zap_callerid.c \ -$(SRC)/fsk.c \ -$(SRC)/uart.c \ -$(SRC)/g711.c \ -$(SRC)/libteletone_detect.c \ -$(SRC)/libteletone_generate.c \ -$(SRC)/zap_buffer.c \ -$(SRC)/zap_threadmutex.c \ -$(SRC)/isdn/EuroISDNStateNT.c \ -$(SRC)/isdn/EuroISDNStateTE.c \ -$(SRC)/isdn/mfifo.c \ -$(SRC)/isdn/Q921.c \ -$(SRC)/isdn/Q931api.c \ -$(SRC)/isdn/Q931.c \ -$(SRC)/isdn/Q931ie.c \ -$(SRC)/isdn/Q931mes.c \ -$(SRC)/isdn/Q931StateNT.c \ -$(SRC)/isdn/Q931StateTE.c \ -$(SRC)/isdn/nationalmes.c \ -$(SRC)/isdn/nationalStateNT.c \ -$(SRC)/isdn/nationalStateTE.c \ -$(SRC)/isdn/DMSmes.c \ -$(SRC)/isdn/DMSStateNT.c \ -$(SRC)/isdn/DMSStateTE.c \ -$(SRC)/isdn/5ESSmes.c \ -$(SRC)/isdn/5ESSStateNT.c \ -$(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c \ -$(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c - -OBJS=\ -$(SRC)/hashtable.o \ -$(SRC)/hashtable_itr.o \ -$(SRC)/zap_io.o \ -$(SRC)/zap_isdn.o \ -$(SRC)/zap_analog.o \ -$(SRC)/zap_config.o \ -$(SRC)/zap_callerid.o \ -$(SRC)/fsk.o \ -$(SRC)/uart.o \ -$(SRC)/g711.o \ -$(SRC)/libteletone_detect.o \ -$(SRC)/libteletone_generate.o \ -$(SRC)/zap_buffer.o \ -$(SRC)/zap_threadmutex.o \ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o \ -$(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o - -#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") - -HEADERS= $(SRC)/include/fsk.h \ -$(SRC)/include/g711.h \ -$(SRC)/include/hashtable.h \ -$(SRC)/include/hashtable_itr.h \ -$(SRC)/include/hashtable_private.h \ -$(SRC)/include/libteletone_detect.h \ -$(SRC)/include/libteletone_generate.h \ -$(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ -$(SRC)/include/sangoma_tdm_api.h \ -$(SRC)/include/uart.h \ -$(SRC)/include/wanpipe_tdm_api_iface.h \ -$(SRC)/include/zap_analog.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_isdn.h \ -$(SRC)/include/zap_skel.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_types.h \ -$(SRC)/include/zap_wanpipe.h \ -$(SRC)/include/zap_zt.h \ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -MYLIB=libopenzap.a -LIBPRIA=libpri.a -LIBPRI=./libpri -TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w - -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -ifneq ($(PIKA_DIR),) -ifneq ($(PIKA_LIB),) -OBJS += $(SRC)/zap_pika.o -CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -ADD_OBJS = $(PIKA_LIB) -endif -endif - -all: $(MYLIB) - -$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - ranlib $(MYLIB) - -testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread - -testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread - -testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm - -detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm - -detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm - -testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread - -testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread - -$(SRC)/priserver.o: $(SRC)/priserver.c - $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o - -$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c - $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o - -$(LIBPRI)/$(LIBPRIA): - cd libpri && make - -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) - -$(SRC)/zap_io.o: $(SRC)/zap_io.c - $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -%.o: %.c $(HEADERS) - $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ - -dox: - cd docs && doxygen $(PWD)/docs/Doxygen.conf - -mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make - -mod_openzap: mod_openzap/mod_openzap.so - -mod_openzap-install: mod_openzap - cd mod_openzap && make install - -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi - -clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog - @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 920ff6cacb..a3512e95a1 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -32,7 +32,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" @@ -41,7 +41,7 @@ sun) fi ;; *) - COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" ;; esac diff --git a/libs/freetdm/general.makefile b/libs/freetdm/general.makefile deleted file mode 100644 index e69de29bb2..0000000000 From d809d5111d3e013492f49a5fa45ba024cf712dee Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 17:17:38 +0000 Subject: [PATCH 0785/1766] build with all the strict flags on git-svn-id: http://svn.openzap.org/svn/openzap/trunk@402 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 4 +-- libs/openzap/src/include/hashtable_itr.h | 5 ++++ libs/openzap/src/include/zap_config.h | 4 +-- libs/openzap/src/include/zap_types.h | 2 +- libs/openzap/src/isdn/EuroISDNStateTE.c | 5 ++-- libs/openzap/src/isdn/Q921.c | 10 +++---- libs/openzap/src/isdn/Q931.c | 4 +-- libs/openzap/src/isdn/include/Q921.h | 24 ++++++++++++++++- libs/openzap/src/isdn/include/Q931.h | 33 ++++++++++++++++++------ libs/openzap/src/isdn/include/Q931ie.h | 8 ++++++ libs/openzap/src/zap_config.c | 8 +++--- libs/openzap/src/zap_io.c | 12 ++++----- libs/openzap/src/zap_isdn.c | 2 +- libs/openzap/src/zap_pika.c | 4 ++- libs/openzap/src/zap_wanpipe.c | 3 +++ libs/openzap/src/zap_zt.c | 3 +++ 16 files changed, 96 insertions(+), 35 deletions(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index a3512e95a1..3ff905cf26 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -32,7 +32,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" + COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" @@ -41,7 +41,7 @@ sun) fi ;; *) - COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" + COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; esac diff --git a/libs/openzap/src/include/hashtable_itr.h b/libs/openzap/src/include/hashtable_itr.h index 71c0d659ff..e14833ab57 100644 --- a/libs/openzap/src/include/hashtable_itr.h +++ b/libs/openzap/src/include/hashtable_itr.h @@ -27,6 +27,8 @@ hashtable_iterator(struct hashtable *h); /*****************************************************************************/ /* hashtable_iterator_key * - return the value of the (key,value) pair at the current position */ +extern __inline__ void * +hashtable_iterator_key(struct hashtable_itr *i); extern __inline__ void * hashtable_iterator_key(struct hashtable_itr *i) @@ -37,6 +39,9 @@ hashtable_iterator_key(struct hashtable_itr *i) /*****************************************************************************/ /* value - return the value of the (key,value) pair at the current position */ +extern __inline__ void * +hashtable_iterator_value(struct hashtable_itr *i); + extern __inline__ void * hashtable_iterator_value(struct hashtable_itr *i) { diff --git a/libs/openzap/src/include/zap_config.h b/libs/openzap/src/include/zap_config.h index 61aa93c177..f239fa933e 100644 --- a/libs/openzap/src/include/zap_config.h +++ b/libs/openzap/src/include/zap_config.h @@ -77,7 +77,7 @@ struct zap_config { /*! FILE stream buffer to the opened file */ FILE *file; /*! path to the file */ - char *path; + const char *path; /*! current category */ char category[256]; /*! current section */ @@ -100,7 +100,7 @@ struct zap_config { \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, char *file_path); +int zap_config_open_file(zap_config_t * cfg, const char *file_path); /*! \brief Close a previously opened configuration file diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index dfcf339026..7e49ce5f62 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -412,7 +412,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; 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)(char *file, const char *func, int line, int level, char *fmt, ...); +typedef void (*zap_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...); typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; typedef struct hashtable_itr zap_hash_itr_t; diff --git a/libs/openzap/src/isdn/EuroISDNStateTE.c b/libs/openzap/src/isdn/EuroISDNStateTE.c index 250d33ffd2..7b7433e567 100644 --- a/libs/openzap/src/isdn/EuroISDNStateTE.c +++ b/libs/openzap/src/isdn/EuroISDNStateTE.c @@ -50,8 +50,9 @@ however run smoothly under the generic space, so these functions are more for show */ - -void EuroISDNCreateTE(L3UCHAR i) +#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 index 10e90972fb..2dad5cf006 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -84,7 +84,7 @@ void Q921_InitTrunk(L2TRUNK trunk, trunk->T203Timeout = 10000; } -static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) +int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); } @@ -105,10 +105,10 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) Return Value: none *****************************************************************************/ -L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ -static L2ULONG tLast={0}; +L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ +L2ULONG tLast = {0}; -L2ULONG Q921GetTime() +L2ULONG Q921GetTime(void) { L2ULONG tNow = 0; if(Q921GetTimeProc != NULL) @@ -182,7 +182,7 @@ void Q921TimerTick(L2TRUNK trunk) } -void Q921SetGetTimeCB(L2ULONG (*callback)()) +void Q921SetGetTimeCB(L2ULONG (*callback)(void)) { Q921GetTimeProc = callback; } diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 316390c492..cb9c28ab20 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -96,7 +96,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */ -L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ +L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ /***************************************************************************** @@ -606,7 +606,7 @@ L3ULONG Q931GetTime() return tNow; } -void Q931SetGetTimeCB(L3ULONG (*callback)()) +void Q931SetGetTimeCB(L3ULONG (*callback)(void)) { Q931GetTimeProc = callback; } diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 97e9e5b867..01e7a1416a 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -131,7 +131,29 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Start(L2TRUNK trunk); -void Q921SetGetTimeCB(L2ULONG (*callback)()); +void Q921SetGetTimeCB(L2ULONG (*callback)(void)); void Q921TimerTick(L2TRUNK trunk); + +int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); +int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); +extern L2ULONG tLast; +L2ULONG Q921GetTime(void); +void Q921T200TimerStart(L2TRUNK trunk); +void Q921T200TimerStop(L2TRUNK trunk); +void Q921T200TimerReset(L2TRUNK trunk); +void Q921T203TimerStart(L2TRUNK trunk); +void Q921T203TimerStop(L2TRUNK trunk); +void Q921T203TimerReset(L2TRUNK trunk); +void Q921T200TimerExpire(L2TRUNK trunk); +void Q921T203TimerExpire(L2TRUNK trunk); +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size); +int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size); + #endif diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index f8592ddc2d..2da5ba5c01 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -126,10 +126,10 @@ Enum helper macros *****************************************************************************/ -#define Q931_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; -#define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#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 (char *name) \ + _TYPE _FUNC1 (const char *name) \ { \ int i; \ _TYPE t = _MAX ; \ @@ -143,7 +143,7 @@ \ return t; \ } \ - char * _FUNC2 (_TYPE type) \ + const char * _FUNC2 (_TYPE type) \ { \ if (type > _MAX) { \ type = _MAX; \ @@ -904,14 +904,14 @@ void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar); void Q931CreateTE(L3UCHAR i); void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); +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 Q931Initialize(); +void Q931Initialize(void); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); L3INT Q931InitMesSetup(Q931mes_Generic *p); L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes); @@ -924,8 +924,8 @@ 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 Q931SetGetTimeCB(L3ULONG (*callback)()); +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); @@ -970,4 +970,21 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, void *PrivateData32, void *PrivateData34); +L3INT Q931GetMesSize(Q931mes_Generic *pMes); +L3INT Q931InitMesResume(Q931mes_Generic * pMes); + + + +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); + + + #endif /* _Q931_NL */ diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index 5b0e7314a5..e64480dfb5 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -1161,4 +1161,12 @@ 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); + + #endif /* _Q931IE_NL */ diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index 5974574805..4c9aaa957d 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -34,10 +34,10 @@ #include "openzap.h" #include "zap_config.h" -int zap_config_open_file(zap_config_t *cfg, char *file_path) +int zap_config_open_file(zap_config_t *cfg, const char *file_path) { FILE *f; - char *path = NULL; + const char *path = NULL; char path_buf[1024]; if (file_path[0] == '/') { @@ -136,8 +136,8 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } cfg->catno = 0; cfg->lineno = 0; - *var = ""; - *val = ""; + *var = (char *) ""; + *val = (char *) ""; return 1; } else { zap_copy_string(cfg->category, *var, sizeof(cfg->category)); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 581af7b6dc..3f0cb2810b 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -111,9 +111,9 @@ ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) -static char *cut_path(char *in) +static const char *cut_path(const char *in) { - char *p, *ret = in; + const char *p, *ret = in; char delims[] = "/\\"; char *i; @@ -126,7 +126,7 @@ static char *cut_path(char *in) return ret; } -static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) +static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { if (file && func && line && level && fmt) { return; @@ -135,7 +135,7 @@ static void null_logger(char *file, const char *func, int line, int level, char } -static char *LEVEL_NAMES[] = { +static const char *LEVEL_NAMES[] = { "EMERG", "ALERT", "CRIT", @@ -149,9 +149,9 @@ static char *LEVEL_NAMES[] = { static int zap_log_level = 7; -static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) +static void default_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { - char *fp; + const char *fp; char data[1024]; va_list ap; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 381afcd2fa..32d2a34c43 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -44,7 +44,7 @@ #define LINE "--------------------------------------------------------------------------------" //#define IODEBUG -static L2ULONG zap_time_now() +static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); } diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 2081867255..310cf5b1c1 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -42,6 +42,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) ZAP_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID) @@ -126,7 +128,7 @@ struct pika_chan_data { }; typedef struct pika_chan_data pika_chan_data_t; -static char *pika_board_type_string(PK_UINT type) +static const char *pika_board_type_string(PK_UINT type) { if (type == PKH_BOARD_TYPE_DIGITAL_GATEWAY) { return "digital_gateway"; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 6dd4d5db08..b89b646a14 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -55,6 +55,9 @@ static struct { /* 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); + #define WP_INVALID_SOCKET -1 /* 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 */ diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 396aeaacca..6c0c6d3140 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -48,6 +48,9 @@ static struct { static const char ctlpath[] = "/dev/zap/ctl"; 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); + static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) { unsigned configured = 0, x; From 32d5cd1ab6acd20c5d1bfb02f212ee2a7ee59468 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 17:17:38 +0000 Subject: [PATCH 0786/1766] build with all the strict flags on git-svn-id: http://svn.openzap.org/svn/openzap/trunk@402 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 4 +-- libs/freetdm/src/include/hashtable_itr.h | 5 ++++ libs/freetdm/src/include/zap_config.h | 4 +-- libs/freetdm/src/include/zap_types.h | 2 +- libs/freetdm/src/isdn/EuroISDNStateTE.c | 5 ++-- libs/freetdm/src/isdn/Q921.c | 10 +++---- libs/freetdm/src/isdn/Q931.c | 4 +-- libs/freetdm/src/isdn/include/Q921.h | 24 ++++++++++++++++- libs/freetdm/src/isdn/include/Q931.h | 33 ++++++++++++++++++------ libs/freetdm/src/isdn/include/Q931ie.h | 8 ++++++ libs/freetdm/src/zap_config.c | 8 +++--- libs/freetdm/src/zap_io.c | 12 ++++----- libs/freetdm/src/zap_isdn.c | 2 +- libs/freetdm/src/zap_pika.c | 4 ++- libs/freetdm/src/zap_wanpipe.c | 3 +++ libs/freetdm/src/zap_zt.c | 3 +++ 16 files changed, 96 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index a3512e95a1..3ff905cf26 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -32,7 +32,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" + COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" @@ -41,7 +41,7 @@ sun) fi ;; *) - COMP_VENDOR_CFLAGS="-Wall -Werror -Wextra -Wno-unused-parameter" + COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; esac diff --git a/libs/freetdm/src/include/hashtable_itr.h b/libs/freetdm/src/include/hashtable_itr.h index 71c0d659ff..e14833ab57 100644 --- a/libs/freetdm/src/include/hashtable_itr.h +++ b/libs/freetdm/src/include/hashtable_itr.h @@ -27,6 +27,8 @@ hashtable_iterator(struct hashtable *h); /*****************************************************************************/ /* hashtable_iterator_key * - return the value of the (key,value) pair at the current position */ +extern __inline__ void * +hashtable_iterator_key(struct hashtable_itr *i); extern __inline__ void * hashtable_iterator_key(struct hashtable_itr *i) @@ -37,6 +39,9 @@ hashtable_iterator_key(struct hashtable_itr *i) /*****************************************************************************/ /* value - return the value of the (key,value) pair at the current position */ +extern __inline__ void * +hashtable_iterator_value(struct hashtable_itr *i); + extern __inline__ void * hashtable_iterator_value(struct hashtable_itr *i) { diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h index 61aa93c177..f239fa933e 100644 --- a/libs/freetdm/src/include/zap_config.h +++ b/libs/freetdm/src/include/zap_config.h @@ -77,7 +77,7 @@ struct zap_config { /*! FILE stream buffer to the opened file */ FILE *file; /*! path to the file */ - char *path; + const char *path; /*! current category */ char category[256]; /*! current section */ @@ -100,7 +100,7 @@ struct zap_config { \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, char *file_path); +int zap_config_open_file(zap_config_t * cfg, const char *file_path); /*! \brief Close a previously opened configuration file diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index dfcf339026..7e49ce5f62 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -412,7 +412,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; 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)(char *file, const char *func, int line, int level, char *fmt, ...); +typedef void (*zap_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...); typedef struct zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; typedef struct hashtable_itr zap_hash_itr_t; diff --git a/libs/freetdm/src/isdn/EuroISDNStateTE.c b/libs/freetdm/src/isdn/EuroISDNStateTE.c index 250d33ffd2..7b7433e567 100644 --- a/libs/freetdm/src/isdn/EuroISDNStateTE.c +++ b/libs/freetdm/src/isdn/EuroISDNStateTE.c @@ -50,8 +50,9 @@ however run smoothly under the generic space, so these functions are more for show */ - -void EuroISDNCreateTE(L3UCHAR i) +#if 0 +static void EuroISDNCreateTE(L3UCHAR i) { Q931CreateTE(i); } +#endif diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 10e90972fb..2dad5cf006 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -84,7 +84,7 @@ void Q921_InitTrunk(L2TRUNK trunk, trunk->T203Timeout = 10000; } -static int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) +int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) { return trunk->Q921Tx21Proc(trunk->PrivateData21, Msg, size); } @@ -105,10 +105,10 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) Return Value: none *****************************************************************************/ -L2ULONG (*Q921GetTimeProc) ()=NULL; /* callback for func reading time in ms */ -static L2ULONG tLast={0}; +L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ +L2ULONG tLast = {0}; -L2ULONG Q921GetTime() +L2ULONG Q921GetTime(void) { L2ULONG tNow = 0; if(Q921GetTimeProc != NULL) @@ -182,7 +182,7 @@ void Q921TimerTick(L2TRUNK trunk) } -void Q921SetGetTimeCB(L2ULONG (*callback)()) +void Q921SetGetTimeCB(L2ULONG (*callback)(void)) { Q921GetTimeProc = callback; } diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 316390c492..cb9c28ab20 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -96,7 +96,7 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */ -L3ULONG (*Q931GetTimeProc) ()=NULL; /* callback for func reading time in ms */ +L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ /***************************************************************************** @@ -606,7 +606,7 @@ L3ULONG Q931GetTime() return tNow; } -void Q931SetGetTimeCB(L3ULONG (*callback)()) +void Q931SetGetTimeCB(L3ULONG (*callback)(void)) { Q931GetTimeProc = callback; } diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 97e9e5b867..01e7a1416a 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -131,7 +131,29 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); int Q921Rx12(L2TRUNK trunk); int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); int Q921Start(L2TRUNK trunk); -void Q921SetGetTimeCB(L2ULONG (*callback)()); +void Q921SetGetTimeCB(L2ULONG (*callback)(void)); void Q921TimerTick(L2TRUNK trunk); + +int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); +int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); +extern L2ULONG tLast; +L2ULONG Q921GetTime(void); +void Q921T200TimerStart(L2TRUNK trunk); +void Q921T200TimerStop(L2TRUNK trunk); +void Q921T200TimerReset(L2TRUNK trunk); +void Q921T203TimerStart(L2TRUNK trunk); +void Q921T203TimerStop(L2TRUNK trunk); +void Q921T203TimerReset(L2TRUNK trunk); +void Q921T200TimerExpire(L2TRUNK trunk); +void Q921T203TimerExpire(L2TRUNK trunk); +int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size); +int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); +int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size); + #endif diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index f8592ddc2d..2da5ba5c01 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -126,10 +126,10 @@ Enum helper macros *****************************************************************************/ -#define Q931_ENUM_NAMES(_NAME, _STRINGS) static char * _NAME [] = { _STRINGS , NULL }; -#define Q931_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (char *name); char * _FUNC2 (_TYPE type); +#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 (char *name) \ + _TYPE _FUNC1 (const char *name) \ { \ int i; \ _TYPE t = _MAX ; \ @@ -143,7 +143,7 @@ \ return t; \ } \ - char * _FUNC2 (_TYPE type) \ + const char * _FUNC2 (_TYPE type) \ { \ if (type > _MAX) { \ type = _MAX; \ @@ -904,14 +904,14 @@ void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar); void Q931CreateTE(L3UCHAR i); void Q931CreateNT(L3UCHAR i); -void Q931SetMesCreateCB(L3INT (*callback)()); +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 Q931Initialize(); +void Q931Initialize(void); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); L3INT Q931InitMesSetup(Q931mes_Generic *p); L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes); @@ -924,8 +924,8 @@ 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 Q931SetGetTimeCB(L3ULONG (*callback)()); +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); @@ -970,4 +970,21 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, void *PrivateData32, void *PrivateData34); +L3INT Q931GetMesSize(Q931mes_Generic *pMes); +L3INT Q931InitMesResume(Q931mes_Generic * pMes); + + + +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); + + + #endif /* _Q931_NL */ diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index 5b0e7314a5..e64480dfb5 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -1161,4 +1161,12 @@ 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); + + #endif /* _Q931IE_NL */ diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index 5974574805..4c9aaa957d 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -34,10 +34,10 @@ #include "openzap.h" #include "zap_config.h" -int zap_config_open_file(zap_config_t *cfg, char *file_path) +int zap_config_open_file(zap_config_t *cfg, const char *file_path) { FILE *f; - char *path = NULL; + const char *path = NULL; char path_buf[1024]; if (file_path[0] == '/') { @@ -136,8 +136,8 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } cfg->catno = 0; cfg->lineno = 0; - *var = ""; - *val = ""; + *var = (char *) ""; + *val = (char *) ""; return 1; } else { zap_copy_string(cfg->category, *var, sizeof(cfg->category)); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 581af7b6dc..3f0cb2810b 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -111,9 +111,9 @@ ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) -static char *cut_path(char *in) +static const char *cut_path(const char *in) { - char *p, *ret = in; + const char *p, *ret = in; char delims[] = "/\\"; char *i; @@ -126,7 +126,7 @@ static char *cut_path(char *in) return ret; } -static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...) +static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { if (file && func && line && level && fmt) { return; @@ -135,7 +135,7 @@ static void null_logger(char *file, const char *func, int line, int level, char } -static char *LEVEL_NAMES[] = { +static const char *LEVEL_NAMES[] = { "EMERG", "ALERT", "CRIT", @@ -149,9 +149,9 @@ static char *LEVEL_NAMES[] = { static int zap_log_level = 7; -static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...) +static void default_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { - char *fp; + const char *fp; char data[1024]; va_list ap; diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 381afcd2fa..32d2a34c43 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -44,7 +44,7 @@ #define LINE "--------------------------------------------------------------------------------" //#define IODEBUG -static L2ULONG zap_time_now() +static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); } diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 2081867255..310cf5b1c1 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -42,6 +42,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) ZAP_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID) @@ -126,7 +128,7 @@ struct pika_chan_data { }; typedef struct pika_chan_data pika_chan_data_t; -static char *pika_board_type_string(PK_UINT type) +static const char *pika_board_type_string(PK_UINT type) { if (type == PKH_BOARD_TYPE_DIGITAL_GATEWAY) { return "digital_gateway"; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index 6dd4d5db08..b89b646a14 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -55,6 +55,9 @@ static struct { /* 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); + #define WP_INVALID_SOCKET -1 /* 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 */ diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 396aeaacca..6c0c6d3140 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -48,6 +48,9 @@ static struct { static const char ctlpath[] = "/dev/zap/ctl"; 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); + static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) { unsigned configured = 0, x; From 722d812aee7492d2b9e02af1a07537fa70d7f18b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 17:41:41 +0000 Subject: [PATCH 0787/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@403 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c495e11f9e..cf5518a05c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1323,7 +1323,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) return status; } -static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) +static void zap_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { char *data = NULL; va_list ap; @@ -1464,7 +1464,7 @@ static switch_status_t load_config(void) if (hold_music) { switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } - + zap_analog_start(span); } } From f6c2eca61532d891bdaf4950ef7b7affc929af2a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 17:41:41 +0000 Subject: [PATCH 0788/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@403 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c495e11f9e..cf5518a05c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1323,7 +1323,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) return status; } -static void zap_logger(char *file, const char *func, int line, int level, char *fmt, ...) +static void zap_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { char *data = NULL; va_list ap; @@ -1464,7 +1464,7 @@ static switch_status_t load_config(void) if (hold_music) { switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } - + zap_analog_start(span); } } From 77c2ce76bdc7818b9b336c5d4644677d500c99a3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Feb 2008 18:16:58 +0000 Subject: [PATCH 0789/1766] fix caller id (MODAPP-77) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@404 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 31 ++++++++---------- libs/openzap/src/zap_isdn.c | 59 +++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index d3cea9936f..09d2d1ce8a 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -752,6 +752,8 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* Octet 1 */ OBuf[(*Octet)++] = Q931ie_CALLED_PARTY_NUMBER; + + /* Octet 2 */ li=(*Octet)++; /* Octet 3 */ @@ -814,7 +816,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA } Octet++; - /* Octet 4a*/ + /* Octet 4*/ x=0; do{ pie->Digit[x] = IBuf[Octet+Off] & 0x7f; @@ -848,38 +850,31 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA *****************************************************************************/ L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - Q931ie_CallingSub * pIE = (Q931ie_CallingSub*)IBuf; + Q931ie_CallingNum * pIE = (Q931ie_CallingNum*)IBuf; L3INT rc=0; L3INT Beg=*Octet; L3INT li; - L3INT sN = pIE->Size - sizeof(Q931ie_CalledSub) + 1; + L3INT sN = pIE->Size - sizeof(Q931ie_CallingNum); L3INT x; /* Octet 1 */ - OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_SUBADDRESS; + OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_NUMBER; + + /* Octet 2 */ li=(*Octet)++; /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3); + OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID); - /* Octet 3a */ - /* - - Details about the use and how to detect if Octet 3a is used - are very weak. Temp left out. - - Octet 3 msb is set to 1 to indicate that this is not present - - */ - /* Octet 4 */ + OBuf[(*Octet)++] = 0x80; + + /* Octet 5 */ for(x=0;xDigit[x]; } - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1528,7 +1523,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = Q931ie_DISPLAY; li=(*Octet)++; - DSize = pIE->Size - sizeof(Q931ie_Display) + 1; + DSize = pIE->Size - sizeof(Q931ie_Display); for(x=0; x< DSize; x++) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 32d2a34c43..86647e051f 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -360,13 +360,16 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_BearerCap BearerCap; Q931ie_ChanID ChanID; Q931ie_CallingNum CallingNum; + Q931ie_CallingNum *ptrCallingNum; Q931ie_CalledNum CalledNum; Q931ie_CalledNum *ptrCalledNum; + Q931ie_Display Display, *ptrDisplay; Q931InitIEBearerCap(&BearerCap); Q931InitIEChanID(&ChanID); Q931InitIECallingNum(&CallingNum); Q931InitIECalledNum(&CalledNum); + Q931InitIEDisplay(&Display); Q931InitMesGeneric(gen); gen->MesType = Q931mes_SETUP; @@ -411,15 +414,56 @@ static __inline__ void state_advance(zap_channel_t *zchan) ChanID.ChanMapType = 3; /* B-Chan */ ChanID.ChanSlot = (unsigned char)zchan->chan_id; gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); -#if 0 - CallingNum.Size += strlen(zchan->caller_data.cid_num); + + 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); + + /* TypNum: Type of number */ + /* Bits 7 6 5 */ + /* 000 Unknown */ + /* 001 International number */ + /* 010 National number */ + /* 011 Network Specific number */ + /* 100 Subscriber mumber */ + /* 110 Abbreviated number */ + /* 111 Reserved for extension */ + /* All other values are reserved */ + CallingNum.TypNum = 2; + + /* NumPlanID */ + /* Bits 4 3 2 1 */ + /* 0000 Unknown */ + /* 0001 ISDN/telephony numbering plan (E.164) */ + /* 0011 Data numbering plan (X.121) */ + /* 0100 Telex numbering plan (F.69) */ + /* 1000 National standard numbering plan */ + /* 1001 Private numbering plan */ + /* 1111 Reserved for extension */ + /* All other valures are reserved */ + CallingNum.NumPlanID = 1; + + /* Presentation indicator */ + /* Bits 7 6 */ + /* 00 Presenation Allowed */ + /* 01 Presentation Restricted */ + /* 10 Number not available due to internetworking */ + /* 11 Reserved */ + CallingNum.PresInd = 0; + + /* Screening Indicator */ + /* Bits 2 1 */ + /* 00 User-provided, not screened */ + /* 01 User-provided, verified and passed */ + /* 10 User-provided, verified and failed */ + /* 11 Network provided */ + CallingNum.ScreenInd = 0; + CallingNum.Size = CallingNum.Size + (unsigned char)strlen(zchan->caller_data.cid_num); gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); - zap_set_string((char *)CallingNum.Digit, zchan->caller_data.cid_num); - gen->Size += strlen(zchan->caller_data.cid_num); + ptrCallingNum = Q931GetIEPtr(gen->CallingNum, gen->buf); + zap_copy_string((char *)ptrCallingNum->Digit, zchan->caller_data.cid_num, strlen(zchan->caller_data.cid_num)+1); - //zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); - -#endif CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani); @@ -427,7 +471,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); - //gen->Size += strlen(zchan->caller_data.ani); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); zchan->span->channels_local_crv[gen->CRV] = zchan; } From e0bdde62349593c5874ca0480513be3b3b24e4ab Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 18 Feb 2008 18:16:58 +0000 Subject: [PATCH 0790/1766] fix caller id (MODAPP-77) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@404 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 31 ++++++++---------- libs/freetdm/src/zap_isdn.c | 59 +++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index d3cea9936f..09d2d1ce8a 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -752,6 +752,8 @@ L3INT Q931Pie_CalledNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, /* Octet 1 */ OBuf[(*Octet)++] = Q931ie_CALLED_PARTY_NUMBER; + + /* Octet 2 */ li=(*Octet)++; /* Octet 3 */ @@ -814,7 +816,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA } Octet++; - /* Octet 4a*/ + /* Octet 4*/ x=0; do{ pie->Digit[x] = IBuf[Octet+Off] & 0x7f; @@ -848,38 +850,31 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA *****************************************************************************/ L3INT Q931Pie_CallingNum(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - Q931ie_CallingSub * pIE = (Q931ie_CallingSub*)IBuf; + Q931ie_CallingNum * pIE = (Q931ie_CallingNum*)IBuf; L3INT rc=0; L3INT Beg=*Octet; L3INT li; - L3INT sN = pIE->Size - sizeof(Q931ie_CalledSub) + 1; + L3INT sN = pIE->Size - sizeof(Q931ie_CallingNum); L3INT x; /* Octet 1 */ - OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_SUBADDRESS; + OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_NUMBER; + + /* Octet 2 */ li=(*Octet)++; /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->OddEvenInd << 3); + OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID); - /* Octet 3a */ - /* - - Details about the use and how to detect if Octet 3a is used - are very weak. Temp left out. - - Octet 3 msb is set to 1 to indicate that this is not present - - */ - /* Octet 4 */ + OBuf[(*Octet)++] = 0x80; + + /* Octet 5 */ for(x=0;xDigit[x]; } - OBuf[(*Octet)-1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; return rc; } @@ -1528,7 +1523,7 @@ L3INT Q931Pie_Display(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3 OBuf[(*Octet)++] = Q931ie_DISPLAY; li=(*Octet)++; - DSize = pIE->Size - sizeof(Q931ie_Display) + 1; + DSize = pIE->Size - sizeof(Q931ie_Display); for(x=0; x< DSize; x++) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 32d2a34c43..86647e051f 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -360,13 +360,16 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_BearerCap BearerCap; Q931ie_ChanID ChanID; Q931ie_CallingNum CallingNum; + Q931ie_CallingNum *ptrCallingNum; Q931ie_CalledNum CalledNum; Q931ie_CalledNum *ptrCalledNum; + Q931ie_Display Display, *ptrDisplay; Q931InitIEBearerCap(&BearerCap); Q931InitIEChanID(&ChanID); Q931InitIECallingNum(&CallingNum); Q931InitIECalledNum(&CalledNum); + Q931InitIEDisplay(&Display); Q931InitMesGeneric(gen); gen->MesType = Q931mes_SETUP; @@ -411,15 +414,56 @@ static __inline__ void state_advance(zap_channel_t *zchan) ChanID.ChanMapType = 3; /* B-Chan */ ChanID.ChanSlot = (unsigned char)zchan->chan_id; gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); -#if 0 - CallingNum.Size += strlen(zchan->caller_data.cid_num); + + 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); + + /* TypNum: Type of number */ + /* Bits 7 6 5 */ + /* 000 Unknown */ + /* 001 International number */ + /* 010 National number */ + /* 011 Network Specific number */ + /* 100 Subscriber mumber */ + /* 110 Abbreviated number */ + /* 111 Reserved for extension */ + /* All other values are reserved */ + CallingNum.TypNum = 2; + + /* NumPlanID */ + /* Bits 4 3 2 1 */ + /* 0000 Unknown */ + /* 0001 ISDN/telephony numbering plan (E.164) */ + /* 0011 Data numbering plan (X.121) */ + /* 0100 Telex numbering plan (F.69) */ + /* 1000 National standard numbering plan */ + /* 1001 Private numbering plan */ + /* 1111 Reserved for extension */ + /* All other valures are reserved */ + CallingNum.NumPlanID = 1; + + /* Presentation indicator */ + /* Bits 7 6 */ + /* 00 Presenation Allowed */ + /* 01 Presentation Restricted */ + /* 10 Number not available due to internetworking */ + /* 11 Reserved */ + CallingNum.PresInd = 0; + + /* Screening Indicator */ + /* Bits 2 1 */ + /* 00 User-provided, not screened */ + /* 01 User-provided, verified and passed */ + /* 10 User-provided, verified and failed */ + /* 11 Network provided */ + CallingNum.ScreenInd = 0; + CallingNum.Size = CallingNum.Size + (unsigned char)strlen(zchan->caller_data.cid_num); gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum); - zap_set_string((char *)CallingNum.Digit, zchan->caller_data.cid_num); - gen->Size += strlen(zchan->caller_data.cid_num); + ptrCallingNum = Q931GetIEPtr(gen->CallingNum, gen->buf); + zap_copy_string((char *)ptrCallingNum->Digit, zchan->caller_data.cid_num, strlen(zchan->caller_data.cid_num)+1); - //zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); - -#endif CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani); @@ -427,7 +471,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani, strlen(zchan->caller_data.ani)+1); - //gen->Size += strlen(zchan->caller_data.ani); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); zchan->span->channels_local_crv[gen->CRV] = zchan; } From 1bed5656bdaeb4e8e20789dec22a38740d2822a6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 21:06:02 +0000 Subject: [PATCH 0791/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@405 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 3ff905cf26..6234a100e9 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -32,7 +32,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" From 8867e2e985be0daac7d738bfb63ea5015510920c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Feb 2008 21:06:02 +0000 Subject: [PATCH 0792/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@405 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 3ff905cf26..6234a100e9 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -32,7 +32,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-std=gnu99 -ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" From 32fc3f50adee8498e20ad53410df5584532c2df4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 19 Feb 2008 00:37:00 +0000 Subject: [PATCH 0793/1766] some more alterations to prep for boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@406 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_types.h | 6 +++++- libs/openzap/src/zap_io.c | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 705ac4bb5e..4c48e2baab 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -428,6 +428,7 @@ struct zap_span { zap_channel_t *channels_local_crv[32768]; zap_channel_t *channels_remote_crv[32768]; zio_channel_outgoing_call_t outgoing_call; + zio_channel_request_t channel_request; void *mod_data; char *type; }; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 7e49ce5f62..3465eca470 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -163,7 +163,8 @@ typedef enum { ZAP_SIGTYPE_NONE, ZAP_SIGTYPE_ISDN, ZAP_SIGTYPE_RBS, - ZAP_SIGTYPE_ANALOG + ZAP_SIGTYPE_ANALOG, + ZAP_SIGTYPE_SS7BOOST } zap_signal_type_t; typedef enum { @@ -336,6 +337,7 @@ typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; +#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, 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) @@ -354,6 +356,7 @@ typedef struct zap_span zap_span_t; #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) +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 ; @@ -372,6 +375,7 @@ 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 ; +#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 diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3f0cb2810b..f128037ba3 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -689,6 +689,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z zap_mutex_lock(globals.mutex); + if (span_id && globals.spans[span_id].channel_request) { + status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, zchan); + goto done; + } + if (span_id) { span_max = span_id; j = span_id; @@ -846,6 +851,11 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_mutex_lock(globals.mutex); + if (span_id && globals.spans[span_id].channel_request) { + zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + goto done; + } + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; From dc7a83902d0c8a4950b9efce2bb5b6daf6d82069 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 19 Feb 2008 00:37:00 +0000 Subject: [PATCH 0794/1766] some more alterations to prep for boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@406 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 6 +++++- libs/freetdm/src/zap_io.c | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 705ac4bb5e..4c48e2baab 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -428,6 +428,7 @@ struct zap_span { zap_channel_t *channels_local_crv[32768]; zap_channel_t *channels_remote_crv[32768]; zio_channel_outgoing_call_t outgoing_call; + zio_channel_request_t channel_request; void *mod_data; char *type; }; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 7e49ce5f62..3465eca470 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -163,7 +163,8 @@ typedef enum { ZAP_SIGTYPE_NONE, ZAP_SIGTYPE_ISDN, ZAP_SIGTYPE_RBS, - ZAP_SIGTYPE_ANALOG + ZAP_SIGTYPE_ANALOG, + ZAP_SIGTYPE_SS7BOOST } zap_signal_type_t; typedef enum { @@ -336,6 +337,7 @@ typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; +#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, 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) @@ -354,6 +356,7 @@ typedef struct zap_span zap_span_t; #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) +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 ; @@ -372,6 +375,7 @@ 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 ; +#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 diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3f0cb2810b..f128037ba3 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -689,6 +689,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z zap_mutex_lock(globals.mutex); + if (span_id && globals.spans[span_id].channel_request) { + status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, zchan); + goto done; + } + if (span_id) { span_max = span_id; j = span_id; @@ -846,6 +851,11 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_mutex_lock(globals.mutex); + if (span_id && globals.spans[span_id].channel_request) { + zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + goto done; + } + if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; From 684c9ec05480c9317bc7deca65b16386463ebc26 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Feb 2008 16:55:54 +0000 Subject: [PATCH 0795/1766] add in switch_core_signal_lock/unlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@407 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 43 +++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index cf5518a05c..3de436c24f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -747,20 +747,28 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { private_t *tech_pvt; - + switch_status_t status; + tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + switch_mutex_lock(tech_pvt->flag_mutex); + switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: - return channel_receive_message_fxs(session, msg); + status = channel_receive_message_fxs(session, msg); case ZAP_CHAN_TYPE_FXO: - return channel_receive_message_fxo(session, msg); + status = channel_receive_message_fxo(session, msg); case ZAP_CHAN_TYPE_B: - return channel_receive_message_b(session, msg); + status = channel_receive_message_b(session, msg); default: - return SWITCH_STATUS_FALSE; + status = SWITCH_STATUS_FALSE; } + + switch_mutex_unlock(tech_pvt->flag_mutex); + + return status; + } switch_state_handler_table_t openzap_state_handlers = { @@ -996,8 +1004,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1005,10 +1015,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1055,8 +1067,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1082,6 +1096,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if ((session_a = switch_core_session_locate(sigmsg->channel->tokens[0]))) { + switch_core_session_signal_lock(session_a); channel_a = switch_core_session_get_channel(session_a); br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1091,6 +1106,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } if ((session_b = switch_core_session_locate(sigmsg->channel->tokens[1]))) { + switch_core_session_signal_lock(session_b); channel_b = switch_core_session_get_channel(session_b); br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1105,21 +1121,26 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) switch_ivr_uuid_bridge(br_a_uuid, br_b_uuid); } else if (br_a_uuid && digits) { session_t = switch_core_session_locate(br_a_uuid); + switch_core_session_signal_lock(session_t); } else if (br_b_uuid && digits) { session_t = switch_core_session_locate(br_b_uuid); + switch_core_session_signal_lock(session_t); } } if (session_t) { switch_ivr_session_transfer(session_t, sigmsg->channel->caller_data.collected, NULL, NULL); + switch_core_session_signal_unlock(session_t); switch_core_session_rwunlock(session_t); } if (session_a) { + switch_core_session_signal_unlock(session_a); switch_core_session_rwunlock(session_a); } if (session_b) { + switch_core_session_signal_unlock(session_b); switch_core_session_rwunlock(session_b); } @@ -1127,9 +1148,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } while((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } zap_channel_clear_token(sigmsg->channel, NULL); @@ -1148,9 +1171,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } cycle_foreground(sigmsg->channel, 1, NULL); @@ -1247,9 +1272,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1258,19 +1285,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_tone_type_t tt = ZAP_TONE_DTMF; + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1278,8 +1309,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } From a2dfc75587a96ac41214634ce1e5439c2e79109e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Feb 2008 16:55:54 +0000 Subject: [PATCH 0796/1766] add in switch_core_signal_lock/unlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@407 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 43 +++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index cf5518a05c..3de436c24f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -747,20 +747,28 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { private_t *tech_pvt; - + switch_status_t status; + tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + switch_mutex_lock(tech_pvt->flag_mutex); + switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: - return channel_receive_message_fxs(session, msg); + status = channel_receive_message_fxs(session, msg); case ZAP_CHAN_TYPE_FXO: - return channel_receive_message_fxo(session, msg); + status = channel_receive_message_fxo(session, msg); case ZAP_CHAN_TYPE_B: - return channel_receive_message_b(session, msg); + status = channel_receive_message_b(session, msg); default: - return SWITCH_STATUS_FALSE; + status = SWITCH_STATUS_FALSE; } + + switch_mutex_unlock(tech_pvt->flag_mutex); + + return status; + } switch_state_handler_table_t openzap_state_handlers = { @@ -996,8 +1004,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1005,10 +1015,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1055,8 +1067,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1082,6 +1096,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if ((session_a = switch_core_session_locate(sigmsg->channel->tokens[0]))) { + switch_core_session_signal_lock(session_a); channel_a = switch_core_session_get_channel(session_a); br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1091,6 +1106,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } if ((session_b = switch_core_session_locate(sigmsg->channel->tokens[1]))) { + switch_core_session_signal_lock(session_b); channel_b = switch_core_session_get_channel(session_b); br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1105,21 +1121,26 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) switch_ivr_uuid_bridge(br_a_uuid, br_b_uuid); } else if (br_a_uuid && digits) { session_t = switch_core_session_locate(br_a_uuid); + switch_core_session_signal_lock(session_t); } else if (br_b_uuid && digits) { session_t = switch_core_session_locate(br_b_uuid); + switch_core_session_signal_lock(session_t); } } if (session_t) { switch_ivr_session_transfer(session_t, sigmsg->channel->caller_data.collected, NULL, NULL); + switch_core_session_signal_unlock(session_t); switch_core_session_rwunlock(session_t); } if (session_a) { + switch_core_session_signal_unlock(session_a); switch_core_session_rwunlock(session_a); } if (session_b) { + switch_core_session_signal_unlock(session_b); switch_core_session_rwunlock(session_b); } @@ -1127,9 +1148,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } while((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } zap_channel_clear_token(sigmsg->channel, NULL); @@ -1148,9 +1171,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } cycle_foreground(sigmsg->channel, 1, NULL); @@ -1247,9 +1272,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1258,19 +1285,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_tone_type_t tt = ZAP_TONE_DTMF; + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1278,8 +1309,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); + switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } From ec0b259ecf35954027b8593e28d25b157911030a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Feb 2008 22:30:54 +0000 Subject: [PATCH 0797/1766] fix MODENDP-82 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@408 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 8 ++++---- libs/openzap/src/zap_analog.c | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 3de436c24f..437e3204c8 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -752,21 +752,21 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - switch_mutex_lock(tech_pvt->flag_mutex); - switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: status = channel_receive_message_fxs(session, msg); + break; case ZAP_CHAN_TYPE_FXO: status = channel_receive_message_fxo(session, msg); + break; case ZAP_CHAN_TYPE_B: status = channel_receive_message_b(session, msg); + break; default: status = SWITCH_STATUS_FALSE; + break; } - switch_mutex_unlock(tech_pvt->flag_mutex); - return status; } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index ce01ffaa68..63e360df10 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -284,7 +284,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); } - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && + (zchan->last_state == ZAP_CHANNEL_STATE_RING || 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; From 26d7b0013b4854178c4d14be95ed7fdb11d608d2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Feb 2008 22:30:54 +0000 Subject: [PATCH 0798/1766] fix MODENDP-82 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@408 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 8 ++++---- libs/freetdm/src/zap_analog.c | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 3de436c24f..437e3204c8 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -752,21 +752,21 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - switch_mutex_lock(tech_pvt->flag_mutex); - switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: status = channel_receive_message_fxs(session, msg); + break; case ZAP_CHAN_TYPE_FXO: status = channel_receive_message_fxo(session, msg); + break; case ZAP_CHAN_TYPE_B: status = channel_receive_message_b(session, msg); + break; default: status = SWITCH_STATUS_FALSE; + break; } - switch_mutex_unlock(tech_pvt->flag_mutex); - return status; } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index ce01ffaa68..63e360df10 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -284,7 +284,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); } - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && + (zchan->last_state == ZAP_CHANNEL_STATE_RING || 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; From 2602a26dadc3b1ebda09ad2ae517ec70cf6569f5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Feb 2008 00:05:52 +0000 Subject: [PATCH 0799/1766] incomplete framework for boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@409 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 12 ++- libs/openzap/src/include/zap_ss7_boost.h | 72 ++++++++++++++ libs/openzap/src/testboost.c | 61 ++++++++++++ libs/openzap/src/zap_ss7_boost.c | 114 +++++++++++++++++++++++ 4 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 libs/openzap/src/include/zap_ss7_boost.h create mode 100644 libs/openzap/src/testboost.c create mode 100644 libs/openzap/src/zap_ss7_boost.c diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 3a057d258e..c4a533bc24 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -67,7 +67,8 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c +$(SRC)/zap_wanpipe.c \ +$(SRC)/zap_ss7_boost.c OBJS=\ $(SRC)/hashtable.o \ @@ -105,7 +106,8 @@ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o +$(SRC)/zap_wanpipe.o \ +$(SRC)/zap_ss7_boost.o #SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") @@ -129,6 +131,7 @@ $(SRC)/include/zap_skel.h \ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_types.h \ $(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_ss7_boost.h \ $(SRC)/include/zap_zt.h \ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ @@ -182,6 +185,9 @@ detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread +testboost: $(SRC)/testboost.c $(MYLIB) + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap -lm -lpthread + testanalog: $(SRC)/testanalog.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread @@ -218,5 +224,5 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/openzap/src/include/zap_ss7_boost.h b/libs/openzap/src/include/zap_ss7_boost.h new file mode 100644 index 0000000000..9e0d19e655 --- /dev/null +++ b/libs/openzap/src/include/zap_ss7_boost.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_SS7_BOOST_H +#define ZAP_SS7_BOOST_H +#include "openzap.h" + +typedef enum { + ZAP_SS7_BOOST_RUNNING = (1 << 0) +} zap_isdn_flag_t; + +struct zap_ss7_boost_data { + const char *local_ip; + int local_port; + const char *remote_ip; + int remote_port; + zio_signal_cb_t signal_cb; + uint32_t flags; +}; +typedef struct zap_ss7_boost_data zap_ss7_boost_data_t; + +zap_status_t zap_ss7_boost_start(zap_span_t *span); +zap_status_t zap_ss7_boost_init(void); +zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, + const char *local_ip, int local_port, + const char *remote_ip, int remote_port, + zio_signal_cb_t sig_cb); + + +#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 expandtab: + */ + diff --git a/libs/openzap/src/testboost.c b/libs/openzap/src/testboost.c new file mode 100644 index 0000000000..4fb9ee12ba --- /dev/null +++ b/libs/openzap/src/testboost.c @@ -0,0 +1,61 @@ +#include "openzap.h" +#include "zap_ss7_boost.h" + +static ZIO_SIGNAL_CB_FUNCTION(on_signal) +{ + return ZAP_FAIL; +} + +int main(int argc, char *argv[]) +{ + zap_span_t *span; + zap_ss7_boost_data_t *data; + + 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_ss7_boost_configure_span(span, "127.0.0.65", 53000, "127.0.0.66", 53000, on_signal) == ZAP_SUCCESS) { + data = span->signal_data; + zap_ss7_boost_start(span); + } else { + fprintf(stderr, "Error starting SS7_BOOST\n"); + goto done; + } + + while(zap_test_flag(data, ZAP_SS7_BOOST_RUNNING)) { + zap_sleep(1 * 1000); + } + + done: + + zap_global_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 expandtab: + */ diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c new file mode 100644 index 0000000000..bf195e1c9d --- /dev/null +++ b/libs/openzap/src/zap_ss7_boost.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "ss7_boost_client.h" +#include "zap_ss7_boost.h" + + +static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) +{ + zap_status_t status = ZAP_SUCCESS; + return status; +} + + +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) +{ + zap_status_t status = ZAP_SUCCESS; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + return status; +} + +static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + + while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { + break; + } + + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "SS7_BOOST thread ended.\n"); + return NULL; +} + +zap_status_t zap_ss7_boost_init(void) +{ + return ZAP_SUCCESS; +} + +zap_status_t zap_ss7_boost_start(zap_span_t *span) +{ + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + return zap_thread_create_detached(zap_ss7_boost_run, span); +} + +zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, + const char *local_ip, int local_port, + const char *remote_ip, int remote_port, + zio_signal_cb_t sig_cb) +{ + zap_ss7_boost_data_t *ss7_boost_data = NULL; + + ss7_boost_data = malloc(sizeof(*ss7_boost_data)); + assert(ss7_boost_data); + memset(ss7_boost_data, 0, sizeof(*ss7_boost_data)); + + ss7_boost_data->local_ip = local_ip; + ss7_boost_data->local_port = local_port; + ss7_boost_data->remote_ip = remote_ip; + ss7_boost_data->remote_port = remote_port; + ss7_boost_data->signal_cb = sig_cb; + + span->signal_data = ss7_boost_data; + span->signal_type = ZAP_SIGTYPE_SS7BOOST; + span->outgoing_call = ss7_boost_outgoing_call; + span->channel_request = ss7_boost_channel_request; + + return ZAP_SUCCESS; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ From 8a122d84a4605a90db57c7ee84623438f635745e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Feb 2008 00:05:52 +0000 Subject: [PATCH 0800/1766] incomplete framework for boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@409 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 12 ++- libs/freetdm/src/include/zap_ss7_boost.h | 72 ++++++++++++++ libs/freetdm/src/testboost.c | 61 ++++++++++++ libs/freetdm/src/zap_ss7_boost.c | 114 +++++++++++++++++++++++ 4 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 libs/freetdm/src/include/zap_ss7_boost.h create mode 100644 libs/freetdm/src/testboost.c create mode 100644 libs/freetdm/src/zap_ss7_boost.c diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 3a057d258e..c4a533bc24 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -67,7 +67,8 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c +$(SRC)/zap_wanpipe.c \ +$(SRC)/zap_ss7_boost.c OBJS=\ $(SRC)/hashtable.o \ @@ -105,7 +106,8 @@ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o +$(SRC)/zap_wanpipe.o \ +$(SRC)/zap_ss7_boost.o #SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") @@ -129,6 +131,7 @@ $(SRC)/include/zap_skel.h \ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_types.h \ $(SRC)/include/zap_wanpipe.h \ +$(SRC)/include/zap_ss7_boost.h \ $(SRC)/include/zap_zt.h \ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ @@ -182,6 +185,9 @@ detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) testisdn: $(SRC)/testisdn.c $(MYLIB) $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread +testboost: $(SRC)/testboost.c $(MYLIB) + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap -lm -lpthread + testanalog: $(SRC)/testanalog.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread @@ -218,5 +224,5 @@ mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testanalog + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi diff --git a/libs/freetdm/src/include/zap_ss7_boost.h b/libs/freetdm/src/include/zap_ss7_boost.h new file mode 100644 index 0000000000..9e0d19e655 --- /dev/null +++ b/libs/freetdm/src/include/zap_ss7_boost.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ZAP_SS7_BOOST_H +#define ZAP_SS7_BOOST_H +#include "openzap.h" + +typedef enum { + ZAP_SS7_BOOST_RUNNING = (1 << 0) +} zap_isdn_flag_t; + +struct zap_ss7_boost_data { + const char *local_ip; + int local_port; + const char *remote_ip; + int remote_port; + zio_signal_cb_t signal_cb; + uint32_t flags; +}; +typedef struct zap_ss7_boost_data zap_ss7_boost_data_t; + +zap_status_t zap_ss7_boost_start(zap_span_t *span); +zap_status_t zap_ss7_boost_init(void); +zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, + const char *local_ip, int local_port, + const char *remote_ip, int remote_port, + zio_signal_cb_t sig_cb); + + +#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 expandtab: + */ + diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c new file mode 100644 index 0000000000..4fb9ee12ba --- /dev/null +++ b/libs/freetdm/src/testboost.c @@ -0,0 +1,61 @@ +#include "openzap.h" +#include "zap_ss7_boost.h" + +static ZIO_SIGNAL_CB_FUNCTION(on_signal) +{ + return ZAP_FAIL; +} + +int main(int argc, char *argv[]) +{ + zap_span_t *span; + zap_ss7_boost_data_t *data; + + 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_ss7_boost_configure_span(span, "127.0.0.65", 53000, "127.0.0.66", 53000, on_signal) == ZAP_SUCCESS) { + data = span->signal_data; + zap_ss7_boost_start(span); + } else { + fprintf(stderr, "Error starting SS7_BOOST\n"); + goto done; + } + + while(zap_test_flag(data, ZAP_SS7_BOOST_RUNNING)) { + zap_sleep(1 * 1000); + } + + done: + + zap_global_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 expandtab: + */ diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c new file mode 100644 index 0000000000..bf195e1c9d --- /dev/null +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "ss7_boost_client.h" +#include "zap_ss7_boost.h" + + +static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) +{ + zap_status_t status = ZAP_SUCCESS; + return status; +} + + +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) +{ + zap_status_t status = ZAP_SUCCESS; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + return status; +} + +static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + + while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { + break; + } + + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "SS7_BOOST thread ended.\n"); + return NULL; +} + +zap_status_t zap_ss7_boost_init(void) +{ + return ZAP_SUCCESS; +} + +zap_status_t zap_ss7_boost_start(zap_span_t *span) +{ + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + return zap_thread_create_detached(zap_ss7_boost_run, span); +} + +zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, + const char *local_ip, int local_port, + const char *remote_ip, int remote_port, + zio_signal_cb_t sig_cb) +{ + zap_ss7_boost_data_t *ss7_boost_data = NULL; + + ss7_boost_data = malloc(sizeof(*ss7_boost_data)); + assert(ss7_boost_data); + memset(ss7_boost_data, 0, sizeof(*ss7_boost_data)); + + ss7_boost_data->local_ip = local_ip; + ss7_boost_data->local_port = local_port; + ss7_boost_data->remote_ip = remote_ip; + ss7_boost_data->remote_port = remote_port; + ss7_boost_data->signal_cb = sig_cb; + + span->signal_data = ss7_boost_data; + span->signal_type = ZAP_SIGTYPE_SS7BOOST; + span->outgoing_call = ss7_boost_outgoing_call; + span->channel_request = ss7_boost_channel_request; + + return ZAP_SUCCESS; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ From 7ffa6362a7735af69f9787826a62175897ec83f0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Feb 2008 17:37:29 +0000 Subject: [PATCH 0801/1766] attempting fix for MODENDP-87 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@410 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 86647e051f..772c895842 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -144,6 +144,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 { From 58cf814aa29305697f38de2fc66553289e325d5d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Feb 2008 17:37:29 +0000 Subject: [PATCH 0802/1766] attempting fix for MODENDP-87 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@410 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 86647e051f..772c895842 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -144,6 +144,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 { From 64c49d88d787905875525beb215be1af70a6afc7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Feb 2008 23:30:49 +0000 Subject: [PATCH 0803/1766] properly tear down on a restart. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@411 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 772c895842..73bf924035 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -327,8 +327,9 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - zap_channel_close(&zchan); + if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: From 79f2bfc536aba238fe2290f0e95a556e2d9ba42b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Feb 2008 23:30:49 +0000 Subject: [PATCH 0804/1766] properly tear down on a restart. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@411 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 772c895842..73bf924035 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -327,8 +327,9 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - zap_channel_close(&zchan); + if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: From 504c7b70699c85893d0bef09e0b5efe6fccf17b8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Feb 2008 23:34:30 +0000 Subject: [PATCH 0805/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@412 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index c4a533bc24..50b22e5c05 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -109,8 +109,6 @@ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o \ $(SRC)/zap_ss7_boost.o -#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") - HEADERS= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ $(SRC)/include/hashtable.h \ From 68fba615a53f002fa5bdde27b084b4bd51e9b7c4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Feb 2008 23:34:30 +0000 Subject: [PATCH 0806/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@412 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index c4a533bc24..50b22e5c05 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -109,8 +109,6 @@ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o \ $(SRC)/zap_ss7_boost.o -#SRCS=$(shell echo $(OBJS) | sed "s/\.o/\.c/g") - HEADERS= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ $(SRC)/include/hashtable.h \ From 506a07ab07752815d33e843d549768629c690741 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Feb 2008 00:19:07 +0000 Subject: [PATCH 0807/1766] fix for MODENDP-88 (too many dchans on a span) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@413 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 73bf924035..31e17049d7 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -718,9 +718,14 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D 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, &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); - x++; + 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); + x++; + } } } } From b809ddb4ec67447934d1bca91f673b103e2125c9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Feb 2008 00:19:07 +0000 Subject: [PATCH 0808/1766] fix for MODENDP-88 (too many dchans on a span) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@413 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 73bf924035..31e17049d7 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -718,9 +718,14 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D 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, &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); - x++; + 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); + x++; + } } } } From 87a1ca9927d0ea52d6f4d4b0f015943dcee2c9da Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Feb 2008 15:58:22 +0000 Subject: [PATCH 0809/1766] add debug flogs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@414 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 6234a100e9..cd73f2ddba 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -44,6 +44,19 @@ sun) COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; esac +# Enable debugging +AC_ARG_ENABLE(debug, +[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"]) + +if test "${enable_debug}" = "yes"; then + AC_DEFINE([DEBUG],[],[Enable extra debugging.]) + + if test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS -g -ggdb" + fi +fi + + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) From 21ffaca607410a67ba2a8dc6319c6e4366ec16d7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Feb 2008 15:58:22 +0000 Subject: [PATCH 0810/1766] add debug flogs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@414 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 6234a100e9..cd73f2ddba 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -44,6 +44,19 @@ sun) COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; esac +# Enable debugging +AC_ARG_ENABLE(debug, +[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"]) + +if test "${enable_debug}" = "yes"; then + AC_DEFINE([DEBUG],[],[Enable extra debugging.]) + + if test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS -g -ggdb" + fi +fi + + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) From db534bd8f078e00e8bbdfd839c58cfb778864e2e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Feb 2008 17:23:10 +0000 Subject: [PATCH 0811/1766] handle invalid disconnect with no matching zchan git-svn-id: http://svn.openzap.org/svn/openzap/trunk@415 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 31e17049d7..39c904b329 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -169,10 +169,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_DISCONNECT: { - Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); - zchan->caller_data.hangup_cause = cause->Value; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - + 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 Diconnect with no matching channel %d\n", chan_id); + } } break; case Q931mes_ALERTING: From 5e56f09d924945f86a5035a642ef20aaeb89fce6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Feb 2008 17:23:10 +0000 Subject: [PATCH 0812/1766] handle invalid disconnect with no matching zchan git-svn-id: http://svn.openzap.org/svn/openzap/trunk@415 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 31e17049d7..39c904b329 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -169,10 +169,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_DISCONNECT: { - Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); - zchan->caller_data.hangup_cause = cause->Value; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - + 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 Diconnect with no matching channel %d\n", chan_id); + } } break; case Q931mes_ALERTING: From 61663af152dd7acdd834ec17ecfe8ed661186da4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Feb 2008 00:21:04 +0000 Subject: [PATCH 0813/1766] boost up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@416 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 4 +- libs/openzap/configure.ac | 3 + libs/openzap/mod_openzap/mod_openzap.c | 79 +++- libs/openzap/src/include/openzap.h | 6 +- libs/openzap/src/include/ss7_boost_client.h | 15 +- libs/openzap/src/include/zap_ss7_boost.h | 14 +- libs/openzap/src/include/zap_types.h | 3 +- libs/openzap/src/ss7_boost_client.c | 55 ++- libs/openzap/src/zap_io.c | 8 +- libs/openzap/src/zap_ss7_boost.c | 484 +++++++++++++++++++- libs/openzap/src/zap_wanpipe.c | 7 +- 11 files changed, 633 insertions(+), 45 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 50b22e5c05..03454e6677 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -29,7 +29,7 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CFLAGS=@COMP_VENDOR_CFLAGS@ +CFLAGS=@COMP_VENDOR_CFLAGS@ @DEFS@ SRC=src SOURCES=\ $(SRC)/hashtable.c \ @@ -68,6 +68,7 @@ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/zap_zt.c \ $(SRC)/zap_wanpipe.c \ +$(SRC)/ss7_boost_client.c \ $(SRC)/zap_ss7_boost.c OBJS=\ @@ -107,6 +108,7 @@ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o \ +$(SRC)/ss7_boost_client.o \ $(SRC)/zap_ss7_boost.o HEADERS= $(SRC)/include/fsk.h \ diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index cd73f2ddba..ffe599eb37 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -44,6 +44,9 @@ sun) COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; esac + +AC_CHECK_HEADERS([netinet/sctp.h]) + # Enable debugging AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"]) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 437e3204c8..fcd635434e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -33,6 +33,7 @@ #include "openzap.h" #include "zap_analog.h" #include "zap_isdn.h" +#include "zap_ss7_boost.h" #ifndef __FUNCTION__ #define __FUNCTION__ __SWITCH_FUNC__ @@ -807,7 +808,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char name[128]; zap_status_t status; int direction = ZAP_TOP_DOWN; - + zap_caller_data_t caller_data = {{ 0 }}; + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -846,10 +848,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi chan_id = 0; } + zap_set_string(caller_data.ani, dest); + zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); + zap_set_string(caller_data.cid_num, outbound_profile->caller_id_number); + if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); } else { - status = zap_channel_open_any(span_id, direction, &zchan); + status = zap_channel_open_any(span_id, direction, &caller_data, &zchan); } if (status != ZAP_SUCCESS) { @@ -875,9 +881,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi snprintf(name, sizeof(name), "OPENZAP/%s", dest); switch_channel_set_name(channel, name); - zap_set_string(zchan->caller_data.ani, dest); - zap_set_string(zchan->caller_data.cid_name, outbound_profile->caller_id_name); - zap_set_string(zchan->caller_data.cid_num, outbound_profile->caller_id_number); + zchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -1535,6 +1539,7 @@ static switch_status_t load_config(void) if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; } span_id = atoi(id); @@ -1561,6 +1566,70 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "boost_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *context = "default"; + char *dialplan = "XML"; + uint32_t span_id = 0; + zap_span_t *span = NULL; + char *tonegroup = NULL; + char *local_ip = NULL; + int local_port = 0; + char *remote_ip = NULL; + int remote_port = 0; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "local-ip")) { + local_ip = val; + } else if (!strcasecmp(var, "local-port")) { + local_port = atoi(val); + } else if (!strcasecmp(var, "remote-ip")) { + remote_ip = val; + } else if (!strcasecmp(var, "remote-port")) { + remote_port = atoi(val); + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } + } + + if (!(id && local_ip && local_port && remote_ip && remote_port) ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); + continue; + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_isdn_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + + zap_ss7_boost_start(span); + } + } + + switch_xml_free(xml); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4c48e2baab..67693b0c77 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -150,7 +150,9 @@ #define assert(_Expression) ((void)(_Expression)) #endif -#define ZAP_MAX_CHANNELS_SPAN 513 +#define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 +#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 16 +#define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN #define ZAP_MAX_SPANS_INTERFACE 33 #define GOTO_STATUS(label,st) status = st; goto label ; @@ -506,7 +508,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_done(zap_channel_t *zchan); zap_status_t zap_channel_use(zap_channel_t *zchan); diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h index 079893c7de..c7ad5493ee 100644 --- a/libs/openzap/src/include/ss7_boost_client.h +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -44,7 +44,7 @@ #include #include #include -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H #include #endif #include @@ -77,13 +77,13 @@ typedef t_sigboost ss7bc_event_t; typedef uint32_t ss7bc_event_id_t; -typedef struct smg_ip_cfg +typedef struct ss7bc_ip_cfg { char local_ip[25]; int local_port; char remote_ip[25]; int remote_port; -}smg_ip_cfg_t; +}ss7bc_ip_cfg_t; struct ss7bc_connection { zap_socket_t socket; @@ -99,7 +99,7 @@ struct ss7bc_connection { unsigned int rxseq; unsigned int txwindow; unsigned int rxseq_reset; - smg_ip_cfg_t cfg; + ss7bc_ip_cfg_t cfg; }; typedef enum { @@ -111,7 +111,7 @@ typedef struct ss7bc_connection ss7bc_connection_t; /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) { -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H int flag = 1; setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int)); #endif @@ -123,8 +123,9 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event); void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); -void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id); -char *ss7bc_event_id_name(uint32_t event_id); +void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); +const char *ss7bc_event_id_name(uint32_t event_id); +int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause); #endif diff --git a/libs/openzap/src/include/zap_ss7_boost.h b/libs/openzap/src/include/zap_ss7_boost.h index 9e0d19e655..e3c7901c45 100644 --- a/libs/openzap/src/include/zap_ss7_boost.h +++ b/libs/openzap/src/include/zap_ss7_boost.h @@ -33,21 +33,19 @@ #ifndef ZAP_SS7_BOOST_H #define ZAP_SS7_BOOST_H +#include "ss7_boost_client.h" #include "openzap.h" typedef enum { ZAP_SS7_BOOST_RUNNING = (1 << 0) -} zap_isdn_flag_t; +} zap_ss7_boost_flag_t; -struct zap_ss7_boost_data { - const char *local_ip; - int local_port; - const char *remote_ip; - int remote_port; +typedef struct zap_ss7_boost_data { + ss7bc_connection_t mcon; + ss7bc_connection_t pcon; zio_signal_cb_t signal_cb; uint32_t flags; -}; -typedef struct zap_ss7_boost_data zap_ss7_boost_data_t; +} zap_ss7_boost_data_t; zap_status_t zap_ss7_boost_start(zap_span_t *span); zap_status_t zap_ss7_boost_init(void); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 3465eca470..d1db4ed5e1 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -336,8 +336,9 @@ 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; -#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, zap_channel_t **zchan) +#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, const 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) diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index 058d52d306..254d10c3bf 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -43,7 +43,7 @@ extern int gethostbyname_r (__const char *__restrict __name, struct ss7bc_map { uint32_t event_id; - char *name; + const char *name; }; static struct ss7bc_map ss7bc_table[] = { @@ -72,7 +72,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp)); memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); #else mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); @@ -96,7 +96,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca 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 SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H setsockopt(mcon->socket, IPPROTO_SCTP, SCTP_NODELAY, (char *)&flag, sizeof(int)); #endif @@ -107,7 +107,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca close(mcon->socket); mcon->socket = -1; } else { -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H rc=listen(mcon->socket,100); if (rc) { close(mcon->socket); @@ -123,9 +123,11 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca int ss7bc_connection_close(ss7bc_connection_t *mcon) { - close(mcon->socket); - mcon->socket = -1; + if (mcon->socket > -1) { + close(mcon->socket); + } memset(mcon, 0, sizeof(*mcon)); + mcon->socket = -1; return 0; } @@ -136,6 +138,41 @@ int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_po return mcon->socket; } + +int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) +{ + ss7bc_event_t oevent; + int retry = 5; + + ss7bc_event_init(&oevent, cmd, chan, span); + oevent.release_cause = cause; + + if (id >= 0) { + oevent.call_setup_id = id; + } + isup_exec_cmd_retry: + if (ss7bc_connection_write(mcon, &oevent) <= 0){ + + --retry; + if (retry <= 0) { + zap_log(ZAP_LOG_WARNING, + "Critical System Error: Failed to tx on ISUP socket: %s\n", + strerror(errno)); + return -1; + } else { + zap_log(ZAP_LOG_WARNING, + "System Warning: Failed to tx on ISUP socket: %s :retry %i\n", + strerror(errno),retry); + } + + goto isup_exec_cmd_retry; + } + + return 0; +} + + + ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) { unsigned int fromlen = sizeof(struct sockaddr_in); @@ -360,7 +397,7 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) return err; } -void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id) +void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id) { memset(event, 0, sizeof(ss7bc_event_t)); event->event_id = SIGBOOST_EVENT_CALL_START; @@ -387,10 +424,10 @@ void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, event->span = span; } -char *ss7bc_event_id_name(uint32_t event_id) +const char *ss7bc_event_id_name(uint32_t event_id) { unsigned int x; - char *ret = NULL; + const char *ret = NULL; for (x = 0 ; x < sizeof(ss7bc_table)/sizeof(struct ss7bc_map); x++) { if (ss7bc_table[x].event_id == event_id) { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f128037ba3..0c9af51e67 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -37,6 +37,7 @@ #endif #include "openzap.h" #include "zap_isdn.h" +#include "zap_ss7_boost.h" #include #ifdef WIN32 #include @@ -342,7 +343,7 @@ zap_status_t zap_span_close_all(void) span = &globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { for(j = 0; j < span->chan_count; j++) { - zap_channel_destroy(&span->channels[i]); + zap_channel_destroy(&span->channels[j]); } } } @@ -679,7 +680,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -690,7 +691,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z zap_mutex_lock(globals.mutex); if (span_id && globals.spans[span_id].channel_request) { - status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, zchan); + status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); goto done; } @@ -1949,6 +1950,7 @@ zap_status_t zap_global_init(void) time_init(); zap_isdn_init(); + zap_ss7_boost_init(); memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index bf195e1c9d..1c51822afe 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -35,30 +35,493 @@ #include "ss7_boost_client.h" #include "zap_ss7_boost.h" +typedef uint16_t ss7_boost_request_id_t; + +typedef enum { + BST_FREE, + BST_WAITING, + BST_READY, + BST_FAIL +} ss7_boost_request_status_t; + +typedef struct { + ss7_boost_request_status_t status; + ss7bc_event_t event; + zap_span_t *span; + zap_channel_t *zchan; +} ss7_boost_request_t; + +static ss7_boost_request_id_t current_request = 0; + +static ss7_boost_request_t OUTBOUND_REQUESTS[ZAP_MAX_CHANNELS_SPAN] = {{ 0 }}; + +static zap_mutex_t *request_mutex = NULL; +static zap_mutex_t *signal_mutex = NULL; + +static ss7_boost_request_id_t next_request_id(void) +{ + ss7_boost_request_id_t r; + + zap_mutex_lock(request_mutex); + if (current_request == ZAP_MAX_CHANNELS_SPAN) { + current_request = 0; + } + r = current_request++; + zap_mutex_unlock(request_mutex); + + return r + 1; +} + +static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) +{ + int i; + zap_channel_t *zchan = NULL; + + for(i = 0; 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]; + break; + } + } + + return zchan; +} static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) { + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; zap_status_t status = ZAP_SUCCESS; + ss7_boost_request_id_t r = next_request_id(); + ss7bc_event_t event = {0}; + int sanity = 60000; + + ss7bc_call_init(&event, caller_data->cid_num, caller_data->ani, r); + OUTBOUND_REQUESTS[r].status = BST_WAITING; + OUTBOUND_REQUESTS[r].span = span; + + if (ss7bc_connection_write(&ss7_boost_data->mcon, &event) <= 0) { + zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]\n", strerror(errno)); + status = ZAP_FAIL; + goto done; + } + + while(OUTBOUND_REQUESTS[r].status == BST_WAITING) { + zap_sleep(1); + if (!--sanity) { + status = ZAP_FAIL; + goto done; + } + } + + if (OUTBOUND_REQUESTS[r].status == BST_READY) { + *zchan = OUTBOUND_REQUESTS[r].zchan; + } + + done: + + OUTBOUND_REQUESTS[r].status = BST_FREE; + return status; } - static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); return status; } +static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + + if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event))) { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + return; + } + } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + event->call_setup_id, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + +} + +static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + + ss7bc_exec_command(mcon, + event->span, + event->chan, + event->call_setup_id, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); +} + +static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event))) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } else { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + } +} + +static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event))) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } else { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + } +} + +static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event))) { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + } else { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } +} + + +static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + int err = ss7bc_connection_write(mcon, event); + + if (err <= 0) { + zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno)); + } + + return; +} + +static void handle_restart_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + mcon->rxseq_reset = 0; +} + +static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_mutex_lock(signal_mutex); + + zap_log(ZAP_LOG_DEBUG, + "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ss7bc_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") + ); + + + switch(event->event_id) { + + case SIGBOOST_EVENT_CALL_START: + handle_call_start(span, mcon, 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_START_NACK: + handle_call_start_nack(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_START_NACK_ACK: + //handle_call_start_nack_ack(event); + break; + case SIGBOOST_EVENT_CALL_STOPPED_ACK: + //handle_call_stop_ack(event); + break; + case SIGBOOST_EVENT_INSERT_CHECK_LOOP: + //handle_call_loop_start(event); + break; + case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: + //handle_call_stop(event); + break; + case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: + handle_restart_ack(mcon,event); + break; + case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE: + //handle_gap_abate(event); + break; + default: + zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", ss7bc_event_id_name(event->event_id)); + break; + } + + zap_mutex_unlock(signal_mutex); + + return 0; +} + +static __inline__ void state_advance(zap_channel_t *zchan) +{ + + zap_ss7_boost_data_t *ss7_boost_data = zchan->span->signal_data; + ss7bc_connection_t *mcon = &ss7_boost_data->mcon; + zap_sigmsg_t sig; + zap_status_t status; + + zap_log(ZAP_LOG_ERROR, "%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: + { + 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 = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + //send progress + } + } + break; + case ZAP_CHANNEL_STATE_RING: + { + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + + } + break; + case ZAP_CHANNEL_STATE_RESTART: + { + if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; + if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + // send alerting + } + } + break; + case ZAP_CHANNEL_STATE_UP: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_UP; + if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + // send connect + } + } + break; + case ZAP_CHANNEL_STATE_DIALING: + { + } + break; + case ZAP_CHANNEL_STATE_HANGUP: + { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + + } + break; + case ZAP_CHANNEL_STATE_TERMINATING: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = ss7_boost_data->signal_cb(&sig); + } + default: + break; + } +} + + +static __inline__ void check_state(zap_span_t *span) +{ + + + if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + zap_mutex_lock(signal_mutex); + state_advance(&span->channels[j]); + zap_mutex_unlock(signal_mutex); + zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + } + } + zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); + } +} + + static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + ss7bc_connection_t *mcon, *pcon; + + ss7_boost_data->pcon = ss7_boost_data->mcon; + + if (ss7bc_connection_open(&ss7_boost_data->mcon, + ss7_boost_data->mcon.cfg.local_ip, + ss7_boost_data->mcon.cfg.local_port, + ss7_boost_data->mcon.cfg.remote_ip, + ss7_boost_data->mcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", ss7_boost_data->mcon.socket, strerror(errno)); + goto end; + } + + if (ss7bc_connection_open(&ss7_boost_data->pcon, + ss7_boost_data->pcon.cfg.local_ip, + ++ss7_boost_data->pcon.cfg.local_port, + ss7_boost_data->pcon.cfg.remote_ip, + ss7_boost_data->pcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", ss7_boost_data->pcon.socket, strerror(errno)); + goto end; + } + + mcon = &ss7_boost_data->mcon; + pcon = &ss7_boost_data->pcon; + + mcon->rxseq_reset = 1; + + ss7bc_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { - break; + fd_set rfds, efds; + struct timeval tv = { 0, 100000 }; + int max, activity, i = 0; + ss7bc_event_t *event = NULL; + + 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; + + if ((activity = select(max, &rfds, NULL, &efds, &tv)) < 0) { + goto error; + } + + if (!activity) { + continue; + } + + if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) { + goto error; + } + + if (FD_ISSET(pcon->socket, &rfds)) { + if ((event = ss7bc_connection_readp(pcon, i))) { + parse_ss7_event(span, pcon, event); + } + } + + if (FD_ISSET(mcon->socket, &rfds)) { + if ((event = ss7bc_connection_read(mcon, i))) { + parse_ss7_event(span, mcon, event); + } + } + + check_state(span); + } + goto end; + + error: + zap_log(ZAP_LOG_CRIT, "Socket Error!\n"); + + end: + + ss7bc_connection_close(&ss7_boost_data->mcon); + ss7bc_connection_close(&ss7_boost_data->pcon); + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); zap_log(ZAP_LOG_DEBUG, "SS7_BOOST thread ended.\n"); @@ -67,6 +530,9 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_status_t zap_ss7_boost_init(void) { + zap_mutex_create(&request_mutex); + zap_mutex_create(&signal_mutex); + return ZAP_SUCCESS; } @@ -84,14 +550,18 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, { zap_ss7_boost_data_t *ss7_boost_data = NULL; + if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { + return ZAP_FAIL; + } + ss7_boost_data = malloc(sizeof(*ss7_boost_data)); assert(ss7_boost_data); memset(ss7_boost_data, 0, sizeof(*ss7_boost_data)); - ss7_boost_data->local_ip = local_ip; - ss7_boost_data->local_port = local_port; - ss7_boost_data->remote_ip = remote_ip; - ss7_boost_data->remote_port = remote_port; + zap_set_string(ss7_boost_data->mcon.cfg.local_ip, local_ip); + ss7_boost_data->mcon.cfg.local_port = local_port; + zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); + ss7_boost_data->mcon.cfg.remote_port = remote_port; ss7_boost_data->signal_cb = sig_cb; span->signal_data = ss7_boost_data; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index b89b646a14..bbeb191b4a 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -358,13 +358,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, sockfd = tdmv_api_open_span_chan(spanno, x); if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + wanpipe_tdm_api_t tdm_api; zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); chan->physical_span_id = spanno; chan->physical_chan_id = x; chan->rate = 8000; if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { - wanpipe_tdm_api_t tdm_api; + #if 1 if (type == ZAP_CHAN_TYPE_FXO) { @@ -390,8 +391,9 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); + } - + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -400,6 +402,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); } From 1d3f79cddc21f5d175f2e4eeeb9d9027eec50f0b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Feb 2008 00:21:04 +0000 Subject: [PATCH 0814/1766] boost up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@416 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 4 +- libs/freetdm/configure.ac | 3 + libs/freetdm/mod_openzap/mod_openzap.c | 79 +++- libs/freetdm/src/include/openzap.h | 6 +- libs/freetdm/src/include/ss7_boost_client.h | 15 +- libs/freetdm/src/include/zap_ss7_boost.h | 14 +- libs/freetdm/src/include/zap_types.h | 3 +- libs/freetdm/src/ss7_boost_client.c | 55 ++- libs/freetdm/src/zap_io.c | 8 +- libs/freetdm/src/zap_ss7_boost.c | 484 +++++++++++++++++++- libs/freetdm/src/zap_wanpipe.c | 7 +- 11 files changed, 633 insertions(+), 45 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 50b22e5c05..03454e6677 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -29,7 +29,7 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CFLAGS=@COMP_VENDOR_CFLAGS@ +CFLAGS=@COMP_VENDOR_CFLAGS@ @DEFS@ SRC=src SOURCES=\ $(SRC)/hashtable.c \ @@ -68,6 +68,7 @@ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/zap_zt.c \ $(SRC)/zap_wanpipe.c \ +$(SRC)/ss7_boost_client.c \ $(SRC)/zap_ss7_boost.c OBJS=\ @@ -107,6 +108,7 @@ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o \ $(SRC)/zap_zt.o \ $(SRC)/zap_wanpipe.o \ +$(SRC)/ss7_boost_client.o \ $(SRC)/zap_ss7_boost.o HEADERS= $(SRC)/include/fsk.h \ diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index cd73f2ddba..ffe599eb37 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -44,6 +44,9 @@ sun) COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" ;; esac + +AC_CHECK_HEADERS([netinet/sctp.h]) + # Enable debugging AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"]) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 437e3204c8..fcd635434e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -33,6 +33,7 @@ #include "openzap.h" #include "zap_analog.h" #include "zap_isdn.h" +#include "zap_ss7_boost.h" #ifndef __FUNCTION__ #define __FUNCTION__ __SWITCH_FUNC__ @@ -807,7 +808,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char name[128]; zap_status_t status; int direction = ZAP_TOP_DOWN; - + zap_caller_data_t caller_data = {{ 0 }}; + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -846,10 +848,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi chan_id = 0; } + zap_set_string(caller_data.ani, dest); + zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); + zap_set_string(caller_data.cid_num, outbound_profile->caller_id_number); + if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); } else { - status = zap_channel_open_any(span_id, direction, &zchan); + status = zap_channel_open_any(span_id, direction, &caller_data, &zchan); } if (status != ZAP_SUCCESS) { @@ -875,9 +881,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi snprintf(name, sizeof(name), "OPENZAP/%s", dest); switch_channel_set_name(channel, name); - zap_set_string(zchan->caller_data.ani, dest); - zap_set_string(zchan->caller_data.cid_name, outbound_profile->caller_id_name); - zap_set_string(zchan->caller_data.cid_num, outbound_profile->caller_id_number); + zchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -1535,6 +1539,7 @@ static switch_status_t load_config(void) if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; } span_id = atoi(id); @@ -1561,6 +1566,70 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "boost_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *context = "default"; + char *dialplan = "XML"; + uint32_t span_id = 0; + zap_span_t *span = NULL; + char *tonegroup = NULL; + char *local_ip = NULL; + int local_port = 0; + char *remote_ip = NULL; + int remote_port = 0; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "local-ip")) { + local_ip = val; + } else if (!strcasecmp(var, "local-port")) { + local_port = atoi(val); + } else if (!strcasecmp(var, "remote-ip")) { + remote_ip = val; + } else if (!strcasecmp(var, "remote-port")) { + remote_port = atoi(val); + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } + } + + if (!(id && local_ip && local_port && remote_ip && remote_port) ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); + continue; + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_isdn_signal) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + + zap_ss7_boost_start(span); + } + } + + switch_xml_free(xml); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4c48e2baab..67693b0c77 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -150,7 +150,9 @@ #define assert(_Expression) ((void)(_Expression)) #endif -#define ZAP_MAX_CHANNELS_SPAN 513 +#define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 +#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 16 +#define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN #define ZAP_MAX_SPANS_INTERFACE 33 #define GOTO_STATUS(label,st) status = st; goto label ; @@ -506,7 +508,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_done(zap_channel_t *zchan); zap_status_t zap_channel_use(zap_channel_t *zchan); diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h index 079893c7de..c7ad5493ee 100644 --- a/libs/freetdm/src/include/ss7_boost_client.h +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -44,7 +44,7 @@ #include #include #include -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H #include #endif #include @@ -77,13 +77,13 @@ typedef t_sigboost ss7bc_event_t; typedef uint32_t ss7bc_event_id_t; -typedef struct smg_ip_cfg +typedef struct ss7bc_ip_cfg { char local_ip[25]; int local_port; char remote_ip[25]; int remote_port; -}smg_ip_cfg_t; +}ss7bc_ip_cfg_t; struct ss7bc_connection { zap_socket_t socket; @@ -99,7 +99,7 @@ struct ss7bc_connection { unsigned int rxseq; unsigned int txwindow; unsigned int rxseq_reset; - smg_ip_cfg_t cfg; + ss7bc_ip_cfg_t cfg; }; typedef enum { @@ -111,7 +111,7 @@ typedef struct ss7bc_connection ss7bc_connection_t; /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) { -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H int flag = 1; setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int)); #endif @@ -123,8 +123,9 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event); void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); -void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id); -char *ss7bc_event_id_name(uint32_t event_id); +void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); +const char *ss7bc_event_id_name(uint32_t event_id); +int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause); #endif diff --git a/libs/freetdm/src/include/zap_ss7_boost.h b/libs/freetdm/src/include/zap_ss7_boost.h index 9e0d19e655..e3c7901c45 100644 --- a/libs/freetdm/src/include/zap_ss7_boost.h +++ b/libs/freetdm/src/include/zap_ss7_boost.h @@ -33,21 +33,19 @@ #ifndef ZAP_SS7_BOOST_H #define ZAP_SS7_BOOST_H +#include "ss7_boost_client.h" #include "openzap.h" typedef enum { ZAP_SS7_BOOST_RUNNING = (1 << 0) -} zap_isdn_flag_t; +} zap_ss7_boost_flag_t; -struct zap_ss7_boost_data { - const char *local_ip; - int local_port; - const char *remote_ip; - int remote_port; +typedef struct zap_ss7_boost_data { + ss7bc_connection_t mcon; + ss7bc_connection_t pcon; zio_signal_cb_t signal_cb; uint32_t flags; -}; -typedef struct zap_ss7_boost_data zap_ss7_boost_data_t; +} zap_ss7_boost_data_t; zap_status_t zap_ss7_boost_start(zap_span_t *span); zap_status_t zap_ss7_boost_init(void); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 3465eca470..d1db4ed5e1 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -336,8 +336,9 @@ 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; -#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, zap_channel_t **zchan) +#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, const 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) diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index 058d52d306..254d10c3bf 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -43,7 +43,7 @@ extern int gethostbyname_r (__const char *__restrict __name, struct ss7bc_map { uint32_t event_id; - char *name; + const char *name; }; static struct ss7bc_map ss7bc_table[] = { @@ -72,7 +72,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp)); memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); #else mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); @@ -96,7 +96,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca 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 SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H setsockopt(mcon->socket, IPPROTO_SCTP, SCTP_NODELAY, (char *)&flag, sizeof(int)); #endif @@ -107,7 +107,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca close(mcon->socket); mcon->socket = -1; } else { -#ifdef SS7BC_USE_SCTP +#ifdef HAVE_NETINET_SCTP_H rc=listen(mcon->socket,100); if (rc) { close(mcon->socket); @@ -123,9 +123,11 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca int ss7bc_connection_close(ss7bc_connection_t *mcon) { - close(mcon->socket); - mcon->socket = -1; + if (mcon->socket > -1) { + close(mcon->socket); + } memset(mcon, 0, sizeof(*mcon)); + mcon->socket = -1; return 0; } @@ -136,6 +138,41 @@ int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_po return mcon->socket; } + +int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) +{ + ss7bc_event_t oevent; + int retry = 5; + + ss7bc_event_init(&oevent, cmd, chan, span); + oevent.release_cause = cause; + + if (id >= 0) { + oevent.call_setup_id = id; + } + isup_exec_cmd_retry: + if (ss7bc_connection_write(mcon, &oevent) <= 0){ + + --retry; + if (retry <= 0) { + zap_log(ZAP_LOG_WARNING, + "Critical System Error: Failed to tx on ISUP socket: %s\n", + strerror(errno)); + return -1; + } else { + zap_log(ZAP_LOG_WARNING, + "System Warning: Failed to tx on ISUP socket: %s :retry %i\n", + strerror(errno),retry); + } + + goto isup_exec_cmd_retry; + } + + return 0; +} + + + ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) { unsigned int fromlen = sizeof(struct sockaddr_in); @@ -360,7 +397,7 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) return err; } -void ss7bc_call_init(ss7bc_event_t *event, char *calling, char *called, int setup_id) +void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id) { memset(event, 0, sizeof(ss7bc_event_t)); event->event_id = SIGBOOST_EVENT_CALL_START; @@ -387,10 +424,10 @@ void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, event->span = span; } -char *ss7bc_event_id_name(uint32_t event_id) +const char *ss7bc_event_id_name(uint32_t event_id) { unsigned int x; - char *ret = NULL; + const char *ret = NULL; for (x = 0 ; x < sizeof(ss7bc_table)/sizeof(struct ss7bc_map); x++) { if (ss7bc_table[x].event_id == event_id) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f128037ba3..0c9af51e67 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -37,6 +37,7 @@ #endif #include "openzap.h" #include "zap_isdn.h" +#include "zap_ss7_boost.h" #include #ifdef WIN32 #include @@ -342,7 +343,7 @@ zap_status_t zap_span_close_all(void) span = &globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { for(j = 0; j < span->chan_count; j++) { - zap_channel_destroy(&span->channels[i]); + zap_channel_destroy(&span->channels[j]); } } } @@ -679,7 +680,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -690,7 +691,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z zap_mutex_lock(globals.mutex); if (span_id && globals.spans[span_id].channel_request) { - status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, zchan); + status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); goto done; } @@ -1949,6 +1950,7 @@ zap_status_t zap_global_init(void) time_init(); zap_isdn_init(); + zap_ss7_boost_init(); memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index bf195e1c9d..1c51822afe 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -35,30 +35,493 @@ #include "ss7_boost_client.h" #include "zap_ss7_boost.h" +typedef uint16_t ss7_boost_request_id_t; + +typedef enum { + BST_FREE, + BST_WAITING, + BST_READY, + BST_FAIL +} ss7_boost_request_status_t; + +typedef struct { + ss7_boost_request_status_t status; + ss7bc_event_t event; + zap_span_t *span; + zap_channel_t *zchan; +} ss7_boost_request_t; + +static ss7_boost_request_id_t current_request = 0; + +static ss7_boost_request_t OUTBOUND_REQUESTS[ZAP_MAX_CHANNELS_SPAN] = {{ 0 }}; + +static zap_mutex_t *request_mutex = NULL; +static zap_mutex_t *signal_mutex = NULL; + +static ss7_boost_request_id_t next_request_id(void) +{ + ss7_boost_request_id_t r; + + zap_mutex_lock(request_mutex); + if (current_request == ZAP_MAX_CHANNELS_SPAN) { + current_request = 0; + } + r = current_request++; + zap_mutex_unlock(request_mutex); + + return r + 1; +} + +static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) +{ + int i; + zap_channel_t *zchan = NULL; + + for(i = 0; 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]; + break; + } + } + + return zchan; +} static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) { + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; zap_status_t status = ZAP_SUCCESS; + ss7_boost_request_id_t r = next_request_id(); + ss7bc_event_t event = {0}; + int sanity = 60000; + + ss7bc_call_init(&event, caller_data->cid_num, caller_data->ani, r); + OUTBOUND_REQUESTS[r].status = BST_WAITING; + OUTBOUND_REQUESTS[r].span = span; + + if (ss7bc_connection_write(&ss7_boost_data->mcon, &event) <= 0) { + zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]\n", strerror(errno)); + status = ZAP_FAIL; + goto done; + } + + while(OUTBOUND_REQUESTS[r].status == BST_WAITING) { + zap_sleep(1); + if (!--sanity) { + status = ZAP_FAIL; + goto done; + } + } + + if (OUTBOUND_REQUESTS[r].status == BST_READY) { + *zchan = OUTBOUND_REQUESTS[r].zchan; + } + + done: + + OUTBOUND_REQUESTS[r].status = BST_FREE; + return status; } - static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); return status; } +static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + + if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event))) { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + return; + } + } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + event->call_setup_id, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + +} + +static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + + ss7bc_exec_command(mcon, + event->span, + event->chan, + event->call_setup_id, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); +} + +static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event))) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } else { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + } +} + +static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event))) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } else { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + } +} + +static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event))) { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + } else { + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } +} + + +static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + int err = ss7bc_connection_write(mcon, event); + + if (err <= 0) { + zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno)); + } + + return; +} + +static void handle_restart_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + mcon->rxseq_reset = 0; +} + +static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_mutex_lock(signal_mutex); + + zap_log(ZAP_LOG_DEBUG, + "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ss7bc_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") + ); + + + switch(event->event_id) { + + case SIGBOOST_EVENT_CALL_START: + handle_call_start(span, mcon, 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_START_NACK: + handle_call_start_nack(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_START_NACK_ACK: + //handle_call_start_nack_ack(event); + break; + case SIGBOOST_EVENT_CALL_STOPPED_ACK: + //handle_call_stop_ack(event); + break; + case SIGBOOST_EVENT_INSERT_CHECK_LOOP: + //handle_call_loop_start(event); + break; + case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: + //handle_call_stop(event); + break; + case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: + handle_restart_ack(mcon,event); + break; + case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE: + //handle_gap_abate(event); + break; + default: + zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", ss7bc_event_id_name(event->event_id)); + break; + } + + zap_mutex_unlock(signal_mutex); + + return 0; +} + +static __inline__ void state_advance(zap_channel_t *zchan) +{ + + zap_ss7_boost_data_t *ss7_boost_data = zchan->span->signal_data; + ss7bc_connection_t *mcon = &ss7_boost_data->mcon; + zap_sigmsg_t sig; + zap_status_t status; + + zap_log(ZAP_LOG_ERROR, "%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: + { + 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 = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + //send progress + } + } + break; + case ZAP_CHANNEL_STATE_RING: + { + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + + } + break; + case ZAP_CHANNEL_STATE_RESTART: + { + if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + break; + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; + if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + // send alerting + } + } + break; + case ZAP_CHANNEL_STATE_UP: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_UP; + if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + // send connect + } + } + break; + case ZAP_CHANNEL_STATE_DIALING: + { + } + break; + case ZAP_CHANNEL_STATE_HANGUP: + { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + 0); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + + } + break; + case ZAP_CHANNEL_STATE_TERMINATING: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = ss7_boost_data->signal_cb(&sig); + } + default: + break; + } +} + + +static __inline__ void check_state(zap_span_t *span) +{ + + + if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + zap_mutex_lock(signal_mutex); + state_advance(&span->channels[j]); + zap_mutex_unlock(signal_mutex); + zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + } + } + zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); + } +} + + static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + ss7bc_connection_t *mcon, *pcon; + + ss7_boost_data->pcon = ss7_boost_data->mcon; + + if (ss7bc_connection_open(&ss7_boost_data->mcon, + ss7_boost_data->mcon.cfg.local_ip, + ss7_boost_data->mcon.cfg.local_port, + ss7_boost_data->mcon.cfg.remote_ip, + ss7_boost_data->mcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", ss7_boost_data->mcon.socket, strerror(errno)); + goto end; + } + + if (ss7bc_connection_open(&ss7_boost_data->pcon, + ss7_boost_data->pcon.cfg.local_ip, + ++ss7_boost_data->pcon.cfg.local_port, + ss7_boost_data->pcon.cfg.remote_ip, + ss7_boost_data->pcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", ss7_boost_data->pcon.socket, strerror(errno)); + goto end; + } + + mcon = &ss7_boost_data->mcon; + pcon = &ss7_boost_data->pcon; + + mcon->rxseq_reset = 1; + + ss7bc_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { - break; + fd_set rfds, efds; + struct timeval tv = { 0, 100000 }; + int max, activity, i = 0; + ss7bc_event_t *event = NULL; + + 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; + + if ((activity = select(max, &rfds, NULL, &efds, &tv)) < 0) { + goto error; + } + + if (!activity) { + continue; + } + + if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) { + goto error; + } + + if (FD_ISSET(pcon->socket, &rfds)) { + if ((event = ss7bc_connection_readp(pcon, i))) { + parse_ss7_event(span, pcon, event); + } + } + + if (FD_ISSET(mcon->socket, &rfds)) { + if ((event = ss7bc_connection_read(mcon, i))) { + parse_ss7_event(span, mcon, event); + } + } + + check_state(span); + } + goto end; + + error: + zap_log(ZAP_LOG_CRIT, "Socket Error!\n"); + + end: + + ss7bc_connection_close(&ss7_boost_data->mcon); + ss7bc_connection_close(&ss7_boost_data->pcon); + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); zap_log(ZAP_LOG_DEBUG, "SS7_BOOST thread ended.\n"); @@ -67,6 +530,9 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_status_t zap_ss7_boost_init(void) { + zap_mutex_create(&request_mutex); + zap_mutex_create(&signal_mutex); + return ZAP_SUCCESS; } @@ -84,14 +550,18 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, { zap_ss7_boost_data_t *ss7_boost_data = NULL; + if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { + return ZAP_FAIL; + } + ss7_boost_data = malloc(sizeof(*ss7_boost_data)); assert(ss7_boost_data); memset(ss7_boost_data, 0, sizeof(*ss7_boost_data)); - ss7_boost_data->local_ip = local_ip; - ss7_boost_data->local_port = local_port; - ss7_boost_data->remote_ip = remote_ip; - ss7_boost_data->remote_port = remote_port; + zap_set_string(ss7_boost_data->mcon.cfg.local_ip, local_ip); + ss7_boost_data->mcon.cfg.local_port = local_port; + zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); + ss7_boost_data->mcon.cfg.remote_port = remote_port; ss7_boost_data->signal_cb = sig_cb; span->signal_data = ss7_boost_data; diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/zap_wanpipe.c index b89b646a14..bbeb191b4a 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/zap_wanpipe.c @@ -358,13 +358,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, sockfd = tdmv_api_open_span_chan(spanno, x); if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + wanpipe_tdm_api_t tdm_api; zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); chan->physical_span_id = spanno; chan->physical_chan_id = x; chan->rate = 8000; if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { - wanpipe_tdm_api_t tdm_api; + #if 1 if (type == ZAP_CHAN_TYPE_FXO) { @@ -390,8 +391,9 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; wp_tdm_cmd_exec(chan, &tdm_api); + } - + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; wp_tdm_cmd_exec(chan, &tdm_api); if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { @@ -400,6 +402,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); } From 759e606ed2d34802ecebeec4e55891e17e58bfd9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 29 Feb 2008 01:05:23 +0000 Subject: [PATCH 0815/1766] state tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@417 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 39c904b329..5bfe471144 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -332,6 +332,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } break; From 7d476dd3032cce68397e0b23dbd5da0067f8a9ec Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 29 Feb 2008 01:05:23 +0000 Subject: [PATCH 0816/1766] state tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@417 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 39c904b329..5bfe471144 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -332,6 +332,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } break; From da7a79ce6131a4a2d086a5da3b35dabffe4866c9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 29 Feb 2008 17:55:29 +0000 Subject: [PATCH 0817/1766] handle failure on chan open on new setup msg git-svn-id: http://svn.openzap.org/svn/openzap/trunk@418 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 5bfe471144..34cef48467 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -238,8 +238,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (fail) { - zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); - // add me + if (zchan) { + zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } else { + zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); + } } } From e1f3a14ad8d0258756dc27d7a4792d7739cf7f2a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 29 Feb 2008 17:55:29 +0000 Subject: [PATCH 0818/1766] handle failure on chan open on new setup msg git-svn-id: http://svn.openzap.org/svn/openzap/trunk@418 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 5bfe471144..34cef48467 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -238,8 +238,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (fail) { - zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); - // add me + if (zchan) { + zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } else { + zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); + } } } From 7cd6d9f30ff1429d2f341998f879354e62dd9544 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 29 Feb 2008 22:04:15 +0000 Subject: [PATCH 0819/1766] we do these from the lib automatically now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@419 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index 2609dc75a5..1552a37c45 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -9,6 +9,6 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) $(OZA): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb $(ALL_CXXFLAGS)" + cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="$(ALL_CXXFLAGS)" From 051f68251642f25c2f0e34fadb55592c726cb375 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 29 Feb 2008 22:04:15 +0000 Subject: [PATCH 0820/1766] we do these from the lib automatically now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@419 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index 2609dc75a5..1552a37c45 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -9,6 +9,6 @@ include $(BASE)/build/modmake.rules local_depend: $(OZA) $(OZA): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="-g -ggdb $(ALL_CXXFLAGS)" + cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="$(ALL_CXXFLAGS)" From 532de2fb08b648324811e947422b6618bcbd2841 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 1 Mar 2008 00:48:36 +0000 Subject: [PATCH 0821/1766] some changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@420 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 56 +++-- libs/openzap/src/include/openzap.h | 41 +++- libs/openzap/src/include/ss7_boost_client.h | 8 +- libs/openzap/src/include/zap_types.h | 9 +- libs/openzap/src/ss7_boost_client.c | 185 +++------------- libs/openzap/src/zap_analog.c | 18 +- libs/openzap/src/zap_io.c | 31 ++- libs/openzap/src/zap_isdn.c | 14 +- libs/openzap/src/zap_ss7_boost.c | 220 ++++++++++++++------ 9 files changed, 316 insertions(+), 266 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index fcd635434e..4763a52b86 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -847,10 +847,27 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi direction = ZAP_BOTTOM_UP; chan_id = 0; } + + if (switch_test_flag(outbound_profile, SWITCH_CPF_SCREEN)) { + caller_data.screen = 1; + } + + if (switch_test_flag(outbound_profile, SWITCH_CPF_HIDE_NUMBER)) { + caller_data.pres = 1; + } + + if (!switch_strlen_zero(dest)) { + zap_set_string(caller_data.ani.digits, dest); + } + +#if 0 + if (!switch_strlen_zero(outbound_profile->rdnis)) { + zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); + } +#endif - zap_set_string(caller_data.ani, dest); zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); - zap_set_string(caller_data.cid_num, outbound_profile->caller_id_number); + zap_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); @@ -952,11 +969,11 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); } - if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num)) { - if (!switch_strlen_zero(sigmsg->channel->caller_data.ani)) { - switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->caller_data.ani); + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num.digits)) { + if (!switch_strlen_zero(sigmsg->channel->caller_data.ani.digits)) { + switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->caller_data.ani.digits); } else { - switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->chan_number); + switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->chan_number); } } @@ -964,16 +981,25 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t "OpenZAP", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, sigmsg->channel->caller_data.cid_name, - sigmsg->channel->caller_data.cid_num, + sigmsg->channel->caller_data.cid_num.digits, NULL, - sigmsg->channel->caller_data.ani, + sigmsg->channel->caller_data.ani.digits, sigmsg->channel->caller_data.aniII, - sigmsg->channel->caller_data.rdnis, + sigmsg->channel->caller_data.rdnis.digits, (char *) modname, SPAN_CONFIG[sigmsg->channel->span_id].context, - sigmsg->channel->caller_data.dnis); + sigmsg->channel->caller_data.dnis.digits); + assert(tech_pvt->caller_profile != NULL); - + + if (sigmsg->channel->caller_data.screen == 1 || sigmsg->channel->caller_data.screen == 3) { + switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_SCREEN); + } + + if (sigmsg->channel->caller_data.pres) { + switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); + } + snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); @@ -1254,12 +1280,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) +static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_log(ZAP_LOG_DEBUG, "got ISDN sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got clear channel sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: @@ -1553,7 +1579,7 @@ static switch_status_t load_config(void) continue; } - if (zap_isdn_configure_span(span, mode, dialect, on_isdn_signal) != ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, mode, dialect, on_clear_channel_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -1616,7 +1642,7 @@ static switch_status_t load_config(void) continue; } - if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_isdn_signal) != ZAP_SUCCESS) { + if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_clear_channel_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 67693b0c77..6261e2e57f 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -307,14 +307,22 @@ struct zap_fsk_modulator { int16_t sample_buffer[64]; }; +typedef struct { + char digits[25]; + uint8_t type; + uint8_t plan; +} zap_number_t; + struct zap_caller_data { - char cid_name[80]; - char cid_num[80]; char cid_date[8]; - char ani[25]; + char cid_name[80]; + zap_number_t cid_num; + zap_number_t ani; + zap_number_t dnis; + zap_number_t rdnis; char aniII[25]; - char dnis[25]; - char rdnis[25]; + uint8_t screen; + uint8_t pres; char collected[25]; int CRV; int hangup_cause; @@ -413,6 +421,7 @@ struct zap_span { zap_data_type_t data_type; uint32_t span_id; uint32_t chan_count; + uint32_t active_count; zap_span_flag_t flags; struct zap_io_interface *zio; zio_event_cb_t event_callback; @@ -455,6 +464,7 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; + zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); @@ -545,6 +555,27 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) #endif + +static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state) +{ + uint32_t j; + zap_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + zap_set_state_locked((&span->channels[j]), state); + } + zap_mutex_unlock(span->mutex); +} + +static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) +{ + uint32_t j; + zap_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + zap_set_flag_locked((&span->channels[j]), flag); + } + zap_mutex_unlock(span->mutex); +} + #endif /* For Emacs: diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h index c7ad5493ee..d2fee452bc 100644 --- a/libs/openzap/src/include/ss7_boost_client.h +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -51,12 +51,8 @@ #include #include #include -#include #include - - - #define ss7bc_test_flag(p,flag) ({ \ ((p)->flags & (flag)); \ }) @@ -93,13 +89,15 @@ struct ss7bc_connection { struct hostent remote_hp; struct hostent local_hp; unsigned int flags; - pthread_mutex_t lock; + zap_mutex_t *mutex; FILE *log; unsigned int txseq; unsigned int rxseq; unsigned int txwindow; unsigned int rxseq_reset; ss7bc_ip_cfg_t cfg; + uint32_t hb_elapsed; + int up; }; typedef enum { diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index d1db4ed5e1..84b0243eca 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -261,7 +261,8 @@ typedef enum { typedef enum { ZAP_SPAN_CONFIGURED = (1 << 0), ZAP_SPAN_READY = (1 << 1), - ZAP_SPAN_STATE_CHANGE = (1 << 2) + ZAP_SPAN_STATE_CHANGE = (1 << 2), + ZAP_SPAN_SUSPENDED = (1 << 3) } zap_span_flag_t; typedef enum { @@ -329,7 +330,10 @@ typedef enum { ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), ZAP_CHANNEL_OUTBOUND = (1 << 18), ZAP_CHANNEL_SUSPENDED = (1 << 19), - ZAP_CHANNEL_3WAY = (1 << 20) + ZAP_CHANNEL_3WAY = (1 << 20), + ZAP_CHANNEL_PROGRESS = (1 << 21), + ZAP_CHANNEL_MEDIA = (1 << 22), + ZAP_CHANNEL_ANSWERED = (1 << 23) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; @@ -489,6 +493,7 @@ typedef enum { ZAP_CAUSE_MEDIA_TIMEOUT = 604 } zap_call_cause_t; + #endif /* For Emacs: diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index 254d10c3bf..dc0151e2ab 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -118,6 +118,8 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca } } + zap_mutex_create(&mcon->mutex); + return mcon->socket; } @@ -126,6 +128,8 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) if (mcon->socket > -1) { close(mcon->socket); } + + zap_mutex_destroy(&mcon->mutex); memset(mcon, 0, sizeof(*mcon)); mcon->socket = -1; @@ -147,25 +151,25 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int ss7bc_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; } - isup_exec_cmd_retry: - if (ss7bc_connection_write(mcon, &oevent) <= 0){ - --retry; - if (retry <= 0) { - zap_log(ZAP_LOG_WARNING, - "Critical System Error: Failed to tx on ISUP socket: %s\n", - strerror(errno)); + while (ss7bc_connection_write(mcon, &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, - "System Warning: Failed to tx on ISUP socket: %s :retry %i\n", - strerror(errno),retry); + zap_log(ZAP_LOG_WARNING, "Failed to tx on ISUP socket: %s :retry %i\n", strerror(errno), retry); + zap_sleep(1); } - - goto isup_exec_cmd_retry; } return 0; @@ -176,21 +180,17 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) { unsigned int fromlen = sizeof(struct sockaddr_in); -#if 0 - ss7bc_event_t *event = &mcon->event; -#endif 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 (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; + mcon->rxseq = mcon->event.fseqno; return &mcon->event; } errno=EAGAIN; @@ -202,44 +202,15 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) mcon->rxseq++; if (mcon->rxseq != mcon->event.fseqno) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", - mcon->rxseq,mcon->event.fseqno); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - } - -#if 0 - /* Debugging only not to be used in production because span/chan can be invalid */ - if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: RX Cmd=%s Invalid Span=%i Chan=%i\n", - ss7bc_event_id_name(event->event_id), event->span,event->chan); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - - errno=EAGAIN; + 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_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: Invalid Event lenght from boost rxlen=%i evsz=%i\n", - bytes, sizeof(mcon->event)); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); + zap_log(ZAP_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + return NULL; } } @@ -249,43 +220,16 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) { unsigned int fromlen = sizeof(struct sockaddr_in); -#if 0 - ss7bc_event_t *event = &mcon->event; -#endif 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 0 - /* Debugging only not to be used in production because span/chan can be invalid */ - if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: RXp Cmd=%s Invalid Span=%i Chan=%i\n", - ss7bc_event_id_name(event->event_id), event->span,event->chan); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - - errno=EAGAIN; - return NULL; - } -#endif + 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_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", - bytes, sizeof(mcon->event)); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); + zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + return NULL; } } @@ -296,58 +240,30 @@ ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) { int err; + if (!event) { zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); return -EINVAL; } if (event->span > 16 || event->chan > 31) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", - ss7bc_event_id_name(event->event_id), event->span,event->chan); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - + zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); return -1; } gettimeofday(&event->tv,NULL); - pthread_mutex_lock(&mcon->lock); - event->fseqno=mcon->txseq++; - event->bseqno=mcon->rxseq; - err=sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, - (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); - pthread_mutex_unlock(&mcon->lock); + zap_mutex_lock(mcon->mutex); + event->fseqno = mcon->txseq++; + event->bseqno = mcon->rxseq; + err = sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + zap_mutex_unlock(mcon->mutex); if (err != sizeof(ss7bc_event_t)) { err = -1; } -#if 0 - zap_log(ZAP_LOG_DEBUG, "TX EVENT\n"); - zap_log(ZAP_LOG_DEBUG, "===================================\n"); - zap_log(ZAP_LOG_DEBUG, " tType: %s (%0x HEX)\n", - ss7bc_event_id_name(event->event_id),event->event_id); - zap_log(ZAP_LOG_DEBUG, " tSpan: [%d]\n",event->span+1); - zap_log(ZAP_LOG_DEBUG, " tChan: [%d]\n",event->chan+1); - zap_log(ZAP_LOG_DEBUG, " tCalledNum: %s\n", - (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A")); - zap_log(ZAP_LOG_DEBUG, " tCallingNum: %s\n", - (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A")); - zap_log(ZAP_LOG_DEBUG, " tCause: %d\n",event->release_cause); - zap_log(ZAP_LOG_DEBUG, " tInterface: [w%dg%d]\n",event->span+1,event->chan+1); - zap_log(ZAP_LOG_DEBUG, " tEvent ID: [%d]\n",event->event_id); - zap_log(ZAP_LOG_DEBUG, " tSetup ID: [%d]\n",event->call_setup_id); - zap_log(ZAP_LOG_DEBUG, " tSeq: [%d]\n",event->fseqno); - zap_log(ZAP_LOG_DEBUG, "===================================\n"); -#endif - -#if 1 - zap_log(ZAP_LOG_DEBUG, - "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", ss7bc_event_id_name(event->event_id), event->event_id, event->span+1, @@ -358,41 +274,6 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"), (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A") ); -#endif - - -#if 0 - - zap_log(ZAP_LOG_DEBUG, - "\nTX EVENT\n" - "===================================\n" - " tType: %s (%0x HEX)\n" - " tSpan: [%d]\n" - " tChan: [%d]\n" - " tCalledNum: %s\n" - " tCallingNum: %s\n" - " tCause: %d\n" - " tInterface: [w%dg%d]\n" - " tEvent ID: [%d]\n" - " tSetup ID: [%d]\n" - " tSeq: [%d]\n" - "===================================\n" - "\n", - ss7bc_event_id_name(event->event_id), - event->event_id, - event->span+1, - event->chan+1, - (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"), - (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"), - event->release_cause, - event->span+1, - event->chan+1, - event->event_id, - event->call_setup_id, - event->fseqno - ); -#endif - return err; } diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 63e360df10..7e6027e06b 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -138,15 +138,15 @@ static void send_caller_id(zap_channel_t *zchan) 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)) { + if (zap_strlen_zero(zchan->caller_data.cid_num.digits)) { mt = MDMF_NO_NUM; - zap_set_string(zchan->caller_data.cid_num, "O"); - } else if (!strcasecmp(zchan->caller_data.cid_num, "P") || !strcasecmp(zchan->caller_data.cid_num, "O")) { + 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, (uint8_t)strlen(zchan->caller_data.cid_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; @@ -396,9 +396,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_START; if (zchan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_string(zchan->caller_data.dnis, zchan->chan_number); + zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number); } else { - zap_set_string(zchan->caller_data.dnis, dtmf); + zap_set_string(zchan->caller_data.dnis.digits, dtmf); } analog_data->sig_cb(&sig); @@ -556,11 +556,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)) { + 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) != ZAP_SUCCESS) { + 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 { @@ -570,7 +570,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)) + 2000; + dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000; } } } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 0c9af51e67..6ba6fec39d 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -669,6 +669,23 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } if (ok) { + if (state == ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + } else if (state == ZAP_CHANNEL_STATE_UP) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); + } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + } + + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + zchan->span->active_count++; + } else if (state == ZAP_CHANNEL_STATE_DOWN) { + zchan->span->active_count--; + } + zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; @@ -690,6 +707,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c zap_mutex_lock(globals.mutex); + if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + goto done; + } + if (span_id && globals.spans[span_id].channel_request) { status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); goto done; @@ -1587,14 +1610,14 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (mlen > sizeof(zchan->caller_data.ani)) { mlen = sizeof(zchan->caller_data.ani); } - zap_set_string(zchan->caller_data.ani, str); - zap_set_string(zchan->caller_data.cid_num, zchan->caller_data.ani); + zap_set_string(zchan->caller_data.ani.digits, str); + zap_set_string(zchan->caller_data.cid_num.digits, zchan->caller_data.ani.digits); } break; case MDMF_NO_NUM: { - zap_set_string(zchan->caller_data.ani, *str == 'P' ? "private" : "unknown"); - zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani); + zap_set_string(zchan->caller_data.ani.digits, *str == 'P' ? "private" : "unknown"); + zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani.digits); } break; case MDMF_PHONE_NAME: diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 34cef48467..8af35ef12a 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -220,10 +220,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->span->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); + 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, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); + zap_set_string(zchan->caller_data.ani.digits, (char *)callingnum->Digit); + 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)) { @@ -472,17 +472,17 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* 10 User-provided, verified and failed */ /* 11 Network provided */ CallingNum.ScreenInd = 0; - CallingNum.Size = CallingNum.Size + (unsigned char)strlen(zchan->caller_data.cid_num); + 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, strlen(zchan->caller_data.cid_num)+1); + zap_copy_string((char *)ptrCallingNum->Digit, zchan->caller_data.cid_num.digits, strlen(zchan->caller_data.cid_num.digits)+1); CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; - CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani); + 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, strlen(zchan->caller_data.ani)+1); + zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani.digits, strlen(zchan->caller_data.ani.digits)+1); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); zchan->span->channels_local_crv[gen->CRV] = zchan; diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 1c51822afe..bd1507c9bd 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -53,7 +53,7 @@ typedef struct { static ss7_boost_request_id_t current_request = 0; -static ss7_boost_request_t OUTBOUND_REQUESTS[ZAP_MAX_CHANNELS_SPAN] = {{ 0 }}; +static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_PENDING_CALLS] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; @@ -63,7 +63,7 @@ static ss7_boost_request_id_t next_request_id(void) ss7_boost_request_id_t r; zap_mutex_lock(request_mutex); - if (current_request == ZAP_MAX_CHANNELS_SPAN) { + if (current_request == MAX_PENDING_CALLS) { current_request = 0; } r = current_request++; @@ -90,31 +90,51 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - zap_status_t status = ZAP_SUCCESS; - ss7_boost_request_id_t r = next_request_id(); + zap_status_t status = ZAP_FAIL; + ss7_boost_request_id_t r; ss7bc_event_t event = {0}; int sanity = 60000; - ss7bc_call_init(&event, caller_data->cid_num, caller_data->ani, r); + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { + zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + if (span->active_count >= span->chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + r = next_request_id(); + + ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + zap_set_string(event.redirection_string, caller_data->rdnis.digits); + + OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; if (ss7bc_connection_write(&ss7_boost_data->mcon, &event) <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]\n", strerror(errno)); status = ZAP_FAIL; + *zchan = NULL; goto done; } - while(OUTBOUND_REQUESTS[r].status == BST_WAITING) { + while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { zap_sleep(1); if (!--sanity) { status = ZAP_FAIL; + *zchan = NULL; goto done; } } if (OUTBOUND_REQUESTS[r].status == BST_READY) { *zchan = OUTBOUND_REQUESTS[r].zchan; + status = ZAP_SUCCESS; } done: @@ -141,7 +161,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; return; } @@ -152,7 +172,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_STOPPED, - 0); + ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; } @@ -175,14 +195,23 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e zap_channel_t *zchan; if ((zchan = find_zchan(span, event))) { + zchan->caller_data.hangup_cause = event->release_cause; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } else { ss7bc_exec_command(mcon, event->span, event->chan, 0, SIGBOOST_EVENT_CALL_STOPPED, - 0); + ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); } } @@ -198,7 +227,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc event->chan, 0, SIGBOOST_EVENT_CALL_STOPPED, - 0); + ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); } } @@ -206,46 +235,92 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ { zap_channel_t *zchan; - if ((zchan = find_zchan(span, event))) { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); - - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); - } else { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_NACK, - 0); + if (!(zchan = find_zchan(span, event))) { + goto error; } + + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + goto error; + } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + + zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); + zchan->caller_data.screen = event->calling_number_screening_ind; + zchan->caller_data.pres = event->calling_number_presentation; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + return; + + error: + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) { - int err = ss7bc_connection_write(mcon, event); + int err; + + err = ss7bc_connection_write(mcon, 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; } -static void handle_restart_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) { mcon->rxseq_reset = 0; + mcon->up = 1; + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); + mcon->hb_elapsed = 0; } static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { zap_mutex_lock(signal_mutex); + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { + + zap_log(ZAP_LOG_WARNING, + "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ss7bc_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") + ); + + goto end; + } + + zap_log(ZAP_LOG_DEBUG, "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", ss7bc_event_id_name(event->event_id), @@ -260,6 +335,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve ); + switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: @@ -293,7 +369,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve //handle_call_stop(event); break; case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: - handle_restart_ack(mcon,event); + handle_restart_ack(mcon, span, event); break; case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE: //handle_gap_abate(event); @@ -303,6 +379,8 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve break; } + end: + zap_mutex_unlock(signal_mutex); return 0; @@ -316,9 +394,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_sigmsg_t sig; zap_status_t status; - zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n", - zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); - + 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; @@ -330,15 +407,16 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_channel_done(zchan); } break; + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: case ZAP_CHANNEL_STATE_PROGRESS: { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS; + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - //send progress + } } break; @@ -357,18 +435,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } - } - break; - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } } else { - // send alerting + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } break; @@ -380,7 +448,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - // send connect + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_ANSWERED, + 0); } } break; @@ -395,7 +468,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED, - 0); + zchan->caller_data.hangup_cause); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } @@ -410,6 +483,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } +static __inline__ void init_outgoing_array(void) +{ + memset(&OUTBOUND_REQUESTS, 0, sizeof(OUTBOUND_REQUESTS)); +} static __inline__ void check_state(zap_span_t *span) { @@ -429,13 +506,13 @@ static __inline__ void check_state(zap_span_t *span) } } - static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - + uint32_t ms = 10, too_long = 60000; + ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -460,7 +537,9 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - mcon->rxseq_reset = 1; + top: + + init_outgoing_array(); ss7bc_exec_command(mcon, 0, @@ -471,7 +550,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { fd_set rfds, efds; - struct timeval tv = { 0, 100000 }; + struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; ss7bc_event_t *event = NULL; @@ -488,28 +567,34 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) goto error; } - if (!activity) { - continue; - } - - if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) { - goto error; - } - - if (FD_ISSET(pcon->socket, &rfds)) { - if ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, pcon, event); + if (activity) { + if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) { + goto error; } - } - if (FD_ISSET(mcon->socket, &rfds)) { - if ((event = ss7bc_connection_read(mcon, i))) { - parse_ss7_event(span, mcon, event); + if (FD_ISSET(pcon->socket, &rfds)) { + if ((event = ss7bc_connection_readp(pcon, i))) { + parse_ss7_event(span, pcon, event); + } else goto top; + } + + if (FD_ISSET(mcon->socket, &rfds)) { + if ((event = ss7bc_connection_read(mcon, i))) { + parse_ss7_event(span, mcon, event); + } else goto top; } } check_state(span); + mcon->hb_elapsed += ms; + if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + mcon->up = 0; + zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); + } + } goto end; @@ -568,7 +653,8 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, span->signal_type = ZAP_SIGTYPE_SS7BOOST; span->outgoing_call = ss7_boost_outgoing_call; span->channel_request = ss7_boost_channel_request; - + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + return ZAP_SUCCESS; } From 9c95febcdd95d654defe059b4d68a054153ea056 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 1 Mar 2008 00:48:36 +0000 Subject: [PATCH 0822/1766] some changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@420 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 56 +++-- libs/freetdm/src/include/openzap.h | 41 +++- libs/freetdm/src/include/ss7_boost_client.h | 8 +- libs/freetdm/src/include/zap_types.h | 9 +- libs/freetdm/src/ss7_boost_client.c | 185 +++------------- libs/freetdm/src/zap_analog.c | 18 +- libs/freetdm/src/zap_io.c | 31 ++- libs/freetdm/src/zap_isdn.c | 14 +- libs/freetdm/src/zap_ss7_boost.c | 220 ++++++++++++++------ 9 files changed, 316 insertions(+), 266 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index fcd635434e..4763a52b86 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -847,10 +847,27 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi direction = ZAP_BOTTOM_UP; chan_id = 0; } + + if (switch_test_flag(outbound_profile, SWITCH_CPF_SCREEN)) { + caller_data.screen = 1; + } + + if (switch_test_flag(outbound_profile, SWITCH_CPF_HIDE_NUMBER)) { + caller_data.pres = 1; + } + + if (!switch_strlen_zero(dest)) { + zap_set_string(caller_data.ani.digits, dest); + } + +#if 0 + if (!switch_strlen_zero(outbound_profile->rdnis)) { + zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); + } +#endif - zap_set_string(caller_data.ani, dest); zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); - zap_set_string(caller_data.cid_num, outbound_profile->caller_id_number); + zap_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); @@ -952,11 +969,11 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); } - if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num)) { - if (!switch_strlen_zero(sigmsg->channel->caller_data.ani)) { - switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->caller_data.ani); + if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num.digits)) { + if (!switch_strlen_zero(sigmsg->channel->caller_data.ani.digits)) { + switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->caller_data.ani.digits); } else { - switch_set_string(sigmsg->channel->caller_data.cid_num, sigmsg->channel->chan_number); + switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->chan_number); } } @@ -964,16 +981,25 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t "OpenZAP", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, sigmsg->channel->caller_data.cid_name, - sigmsg->channel->caller_data.cid_num, + sigmsg->channel->caller_data.cid_num.digits, NULL, - sigmsg->channel->caller_data.ani, + sigmsg->channel->caller_data.ani.digits, sigmsg->channel->caller_data.aniII, - sigmsg->channel->caller_data.rdnis, + sigmsg->channel->caller_data.rdnis.digits, (char *) modname, SPAN_CONFIG[sigmsg->channel->span_id].context, - sigmsg->channel->caller_data.dnis); + sigmsg->channel->caller_data.dnis.digits); + assert(tech_pvt->caller_profile != NULL); - + + if (sigmsg->channel->caller_data.screen == 1 || sigmsg->channel->caller_data.screen == 3) { + switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_SCREEN); + } + + if (sigmsg->channel->caller_data.pres) { + switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); + } + snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); @@ -1254,12 +1280,12 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_isdn_signal) +static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_log(ZAP_LOG_DEBUG, "got ISDN sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + zap_log(ZAP_LOG_DEBUG, "got clear channel sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: @@ -1553,7 +1579,7 @@ static switch_status_t load_config(void) continue; } - if (zap_isdn_configure_span(span, mode, dialect, on_isdn_signal) != ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, mode, dialect, on_clear_channel_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -1616,7 +1642,7 @@ static switch_status_t load_config(void) continue; } - if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_isdn_signal) != ZAP_SUCCESS) { + if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_clear_channel_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 67693b0c77..6261e2e57f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -307,14 +307,22 @@ struct zap_fsk_modulator { int16_t sample_buffer[64]; }; +typedef struct { + char digits[25]; + uint8_t type; + uint8_t plan; +} zap_number_t; + struct zap_caller_data { - char cid_name[80]; - char cid_num[80]; char cid_date[8]; - char ani[25]; + char cid_name[80]; + zap_number_t cid_num; + zap_number_t ani; + zap_number_t dnis; + zap_number_t rdnis; char aniII[25]; - char dnis[25]; - char rdnis[25]; + uint8_t screen; + uint8_t pres; char collected[25]; int CRV; int hangup_cause; @@ -413,6 +421,7 @@ struct zap_span { zap_data_type_t data_type; uint32_t span_id; uint32_t chan_count; + uint32_t active_count; zap_span_flag_t flags; struct zap_io_interface *zio; zio_event_cb_t event_callback; @@ -455,6 +464,7 @@ struct zap_io_interface { zio_span_next_event_t next_event; }; + zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); @@ -545,6 +555,27 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) #endif + +static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state) +{ + uint32_t j; + zap_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + zap_set_state_locked((&span->channels[j]), state); + } + zap_mutex_unlock(span->mutex); +} + +static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) +{ + uint32_t j; + zap_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + zap_set_flag_locked((&span->channels[j]), flag); + } + zap_mutex_unlock(span->mutex); +} + #endif /* For Emacs: diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h index c7ad5493ee..d2fee452bc 100644 --- a/libs/freetdm/src/include/ss7_boost_client.h +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -51,12 +51,8 @@ #include #include #include -#include #include - - - #define ss7bc_test_flag(p,flag) ({ \ ((p)->flags & (flag)); \ }) @@ -93,13 +89,15 @@ struct ss7bc_connection { struct hostent remote_hp; struct hostent local_hp; unsigned int flags; - pthread_mutex_t lock; + zap_mutex_t *mutex; FILE *log; unsigned int txseq; unsigned int rxseq; unsigned int txwindow; unsigned int rxseq_reset; ss7bc_ip_cfg_t cfg; + uint32_t hb_elapsed; + int up; }; typedef enum { diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index d1db4ed5e1..84b0243eca 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -261,7 +261,8 @@ typedef enum { typedef enum { ZAP_SPAN_CONFIGURED = (1 << 0), ZAP_SPAN_READY = (1 << 1), - ZAP_SPAN_STATE_CHANGE = (1 << 2) + ZAP_SPAN_STATE_CHANGE = (1 << 2), + ZAP_SPAN_SUSPENDED = (1 << 3) } zap_span_flag_t; typedef enum { @@ -329,7 +330,10 @@ typedef enum { ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), ZAP_CHANNEL_OUTBOUND = (1 << 18), ZAP_CHANNEL_SUSPENDED = (1 << 19), - ZAP_CHANNEL_3WAY = (1 << 20) + ZAP_CHANNEL_3WAY = (1 << 20), + ZAP_CHANNEL_PROGRESS = (1 << 21), + ZAP_CHANNEL_MEDIA = (1 << 22), + ZAP_CHANNEL_ANSWERED = (1 << 23) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; @@ -489,6 +493,7 @@ typedef enum { ZAP_CAUSE_MEDIA_TIMEOUT = 604 } zap_call_cause_t; + #endif /* For Emacs: diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index 254d10c3bf..dc0151e2ab 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -118,6 +118,8 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca } } + zap_mutex_create(&mcon->mutex); + return mcon->socket; } @@ -126,6 +128,8 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) if (mcon->socket > -1) { close(mcon->socket); } + + zap_mutex_destroy(&mcon->mutex); memset(mcon, 0, sizeof(*mcon)); mcon->socket = -1; @@ -147,25 +151,25 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int ss7bc_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; } - isup_exec_cmd_retry: - if (ss7bc_connection_write(mcon, &oevent) <= 0){ - --retry; - if (retry <= 0) { - zap_log(ZAP_LOG_WARNING, - "Critical System Error: Failed to tx on ISUP socket: %s\n", - strerror(errno)); + while (ss7bc_connection_write(mcon, &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, - "System Warning: Failed to tx on ISUP socket: %s :retry %i\n", - strerror(errno),retry); + zap_log(ZAP_LOG_WARNING, "Failed to tx on ISUP socket: %s :retry %i\n", strerror(errno), retry); + zap_sleep(1); } - - goto isup_exec_cmd_retry; } return 0; @@ -176,21 +180,17 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) { unsigned int fromlen = sizeof(struct sockaddr_in); -#if 0 - ss7bc_event_t *event = &mcon->event; -#endif 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 (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; + mcon->rxseq = mcon->event.fseqno; return &mcon->event; } errno=EAGAIN; @@ -202,44 +202,15 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) mcon->rxseq++; if (mcon->rxseq != mcon->event.fseqno) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", - mcon->rxseq,mcon->event.fseqno); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - } - -#if 0 - /* Debugging only not to be used in production because span/chan can be invalid */ - if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: RX Cmd=%s Invalid Span=%i Chan=%i\n", - ss7bc_event_id_name(event->event_id), event->span,event->chan); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - - errno=EAGAIN; + 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_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: Invalid Event lenght from boost rxlen=%i evsz=%i\n", - bytes, sizeof(mcon->event)); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); + zap_log(ZAP_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + return NULL; } } @@ -249,43 +220,16 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) { unsigned int fromlen = sizeof(struct sockaddr_in); -#if 0 - ss7bc_event_t *event = &mcon->event; -#endif 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 0 - /* Debugging only not to be used in production because span/chan can be invalid */ - if (mcon->event.span < 0 || mcon->event.chan < 0 || mcon->event.span > 16 || mcon->event.chan > 31) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: RXp Cmd=%s Invalid Span=%i Chan=%i\n", - ss7bc_event_id_name(event->event_id), event->span,event->chan); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - - errno=EAGAIN; - return NULL; - } -#endif + 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_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", - bytes, sizeof(mcon->event)); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); + zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + return NULL; } } @@ -296,58 +240,30 @@ ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) { int err; + if (!event) { zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); return -EINVAL; } if (event->span > 16 || event->chan > 31) { - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - zap_log(ZAP_LOG_DEBUG, - "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", - ss7bc_event_id_name(event->event_id), event->span,event->chan); - zap_log(ZAP_LOG_DEBUG, - "------------------------------------------\n"); - + zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); return -1; } gettimeofday(&event->tv,NULL); - pthread_mutex_lock(&mcon->lock); - event->fseqno=mcon->txseq++; - event->bseqno=mcon->rxseq; - err=sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, - (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); - pthread_mutex_unlock(&mcon->lock); + zap_mutex_lock(mcon->mutex); + event->fseqno = mcon->txseq++; + event->bseqno = mcon->rxseq; + err = sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + zap_mutex_unlock(mcon->mutex); if (err != sizeof(ss7bc_event_t)) { err = -1; } -#if 0 - zap_log(ZAP_LOG_DEBUG, "TX EVENT\n"); - zap_log(ZAP_LOG_DEBUG, "===================================\n"); - zap_log(ZAP_LOG_DEBUG, " tType: %s (%0x HEX)\n", - ss7bc_event_id_name(event->event_id),event->event_id); - zap_log(ZAP_LOG_DEBUG, " tSpan: [%d]\n",event->span+1); - zap_log(ZAP_LOG_DEBUG, " tChan: [%d]\n",event->chan+1); - zap_log(ZAP_LOG_DEBUG, " tCalledNum: %s\n", - (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A")); - zap_log(ZAP_LOG_DEBUG, " tCallingNum: %s\n", - (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A")); - zap_log(ZAP_LOG_DEBUG, " tCause: %d\n",event->release_cause); - zap_log(ZAP_LOG_DEBUG, " tInterface: [w%dg%d]\n",event->span+1,event->chan+1); - zap_log(ZAP_LOG_DEBUG, " tEvent ID: [%d]\n",event->event_id); - zap_log(ZAP_LOG_DEBUG, " tSetup ID: [%d]\n",event->call_setup_id); - zap_log(ZAP_LOG_DEBUG, " tSeq: [%d]\n",event->fseqno); - zap_log(ZAP_LOG_DEBUG, "===================================\n"); -#endif - -#if 1 - zap_log(ZAP_LOG_DEBUG, - "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", ss7bc_event_id_name(event->event_id), event->event_id, event->span+1, @@ -358,41 +274,6 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"), (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A") ); -#endif - - -#if 0 - - zap_log(ZAP_LOG_DEBUG, - "\nTX EVENT\n" - "===================================\n" - " tType: %s (%0x HEX)\n" - " tSpan: [%d]\n" - " tChan: [%d]\n" - " tCalledNum: %s\n" - " tCallingNum: %s\n" - " tCause: %d\n" - " tInterface: [w%dg%d]\n" - " tEvent ID: [%d]\n" - " tSetup ID: [%d]\n" - " tSeq: [%d]\n" - "===================================\n" - "\n", - ss7bc_event_id_name(event->event_id), - event->event_id, - event->span+1, - event->chan+1, - (event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"), - (event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"), - event->release_cause, - event->span+1, - event->chan+1, - event->event_id, - event->call_setup_id, - event->fseqno - ); -#endif - return err; } diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 63e360df10..7e6027e06b 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -138,15 +138,15 @@ static void send_caller_id(zap_channel_t *zchan) 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)) { + if (zap_strlen_zero(zchan->caller_data.cid_num.digits)) { mt = MDMF_NO_NUM; - zap_set_string(zchan->caller_data.cid_num, "O"); - } else if (!strcasecmp(zchan->caller_data.cid_num, "P") || !strcasecmp(zchan->caller_data.cid_num, "O")) { + 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, (uint8_t)strlen(zchan->caller_data.cid_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; @@ -396,9 +396,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_START; if (zchan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_string(zchan->caller_data.dnis, zchan->chan_number); + zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number); } else { - zap_set_string(zchan->caller_data.dnis, dtmf); + zap_set_string(zchan->caller_data.dnis.digits, dtmf); } analog_data->sig_cb(&sig); @@ -556,11 +556,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)) { + 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) != ZAP_SUCCESS) { + 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 { @@ -570,7 +570,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)) + 2000; + dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000; } } } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 0c9af51e67..6ba6fec39d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -669,6 +669,23 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } if (ok) { + if (state == ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + } else if (state == ZAP_CHANNEL_STATE_UP) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); + } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + } + + if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + zchan->span->active_count++; + } else if (state == ZAP_CHANNEL_STATE_DOWN) { + zchan->span->active_count--; + } + zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; @@ -690,6 +707,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c zap_mutex_lock(globals.mutex); + if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + goto done; + } + if (span_id && globals.spans[span_id].channel_request) { status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); goto done; @@ -1587,14 +1610,14 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data if (mlen > sizeof(zchan->caller_data.ani)) { mlen = sizeof(zchan->caller_data.ani); } - zap_set_string(zchan->caller_data.ani, str); - zap_set_string(zchan->caller_data.cid_num, zchan->caller_data.ani); + zap_set_string(zchan->caller_data.ani.digits, str); + zap_set_string(zchan->caller_data.cid_num.digits, zchan->caller_data.ani.digits); } break; case MDMF_NO_NUM: { - zap_set_string(zchan->caller_data.ani, *str == 'P' ? "private" : "unknown"); - zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani); + zap_set_string(zchan->caller_data.ani.digits, *str == 'P' ? "private" : "unknown"); + zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani.digits); } break; case MDMF_PHONE_NAME: diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 34cef48467..8af35ef12a 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -220,10 +220,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->span->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_set_string(zchan->caller_data.cid_num, (char *)callingnum->Digit); + 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, (char *)callingnum->Digit); - zap_set_string(zchan->caller_data.dnis, (char *)callednum->Digit); + zap_set_string(zchan->caller_data.ani.digits, (char *)callingnum->Digit); + 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)) { @@ -472,17 +472,17 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* 10 User-provided, verified and failed */ /* 11 Network provided */ CallingNum.ScreenInd = 0; - CallingNum.Size = CallingNum.Size + (unsigned char)strlen(zchan->caller_data.cid_num); + 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, strlen(zchan->caller_data.cid_num)+1); + zap_copy_string((char *)ptrCallingNum->Digit, zchan->caller_data.cid_num.digits, strlen(zchan->caller_data.cid_num.digits)+1); CalledNum.TypNum = 2; CalledNum.NumPlanID = 1; - CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani); + 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, strlen(zchan->caller_data.ani)+1); + zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani.digits, strlen(zchan->caller_data.ani.digits)+1); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); zchan->span->channels_local_crv[gen->CRV] = zchan; diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 1c51822afe..bd1507c9bd 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -53,7 +53,7 @@ typedef struct { static ss7_boost_request_id_t current_request = 0; -static ss7_boost_request_t OUTBOUND_REQUESTS[ZAP_MAX_CHANNELS_SPAN] = {{ 0 }}; +static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_PENDING_CALLS] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; @@ -63,7 +63,7 @@ static ss7_boost_request_id_t next_request_id(void) ss7_boost_request_id_t r; zap_mutex_lock(request_mutex); - if (current_request == ZAP_MAX_CHANNELS_SPAN) { + if (current_request == MAX_PENDING_CALLS) { current_request = 0; } r = current_request++; @@ -90,31 +90,51 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - zap_status_t status = ZAP_SUCCESS; - ss7_boost_request_id_t r = next_request_id(); + zap_status_t status = ZAP_FAIL; + ss7_boost_request_id_t r; ss7bc_event_t event = {0}; int sanity = 60000; - ss7bc_call_init(&event, caller_data->cid_num, caller_data->ani, r); + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { + zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + if (span->active_count >= span->chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + r = next_request_id(); + + ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + zap_set_string(event.redirection_string, caller_data->rdnis.digits); + + OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; if (ss7bc_connection_write(&ss7_boost_data->mcon, &event) <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]\n", strerror(errno)); status = ZAP_FAIL; + *zchan = NULL; goto done; } - while(OUTBOUND_REQUESTS[r].status == BST_WAITING) { + while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { zap_sleep(1); if (!--sanity) { status = ZAP_FAIL; + *zchan = NULL; goto done; } } if (OUTBOUND_REQUESTS[r].status == BST_READY) { *zchan = OUTBOUND_REQUESTS[r].zchan; + status = ZAP_SUCCESS; } done: @@ -141,7 +161,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; return; } @@ -152,7 +172,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_STOPPED, - 0); + ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; } @@ -175,14 +195,23 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e zap_channel_t *zchan; if ((zchan = find_zchan(span, event))) { + zchan->caller_data.hangup_cause = event->release_cause; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } else { ss7bc_exec_command(mcon, event->span, event->chan, 0, SIGBOOST_EVENT_CALL_STOPPED, - 0); + ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); } } @@ -198,7 +227,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc event->chan, 0, SIGBOOST_EVENT_CALL_STOPPED, - 0); + ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); } } @@ -206,46 +235,92 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ { zap_channel_t *zchan; - if ((zchan = find_zchan(span, event))) { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); - - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); - } else { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_NACK, - 0); + if (!(zchan = find_zchan(span, event))) { + goto error; } + + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + goto error; + } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + + zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); + zchan->caller_data.screen = event->calling_number_screening_ind; + zchan->caller_data.pres = event->calling_number_presentation; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + return; + + error: + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) { - int err = ss7bc_connection_write(mcon, event); + int err; + + err = ss7bc_connection_write(mcon, 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; } -static void handle_restart_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) { mcon->rxseq_reset = 0; + mcon->up = 1; + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); + mcon->hb_elapsed = 0; } static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { zap_mutex_lock(signal_mutex); + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { + + zap_log(ZAP_LOG_WARNING, + "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ss7bc_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") + ); + + goto end; + } + + zap_log(ZAP_LOG_DEBUG, "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", ss7bc_event_id_name(event->event_id), @@ -260,6 +335,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve ); + switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: @@ -293,7 +369,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve //handle_call_stop(event); break; case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: - handle_restart_ack(mcon,event); + handle_restart_ack(mcon, span, event); break; case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE: //handle_gap_abate(event); @@ -303,6 +379,8 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve break; } + end: + zap_mutex_unlock(signal_mutex); return 0; @@ -316,9 +394,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_sigmsg_t sig; zap_status_t status; - zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n", - zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); - + 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; @@ -330,15 +407,16 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_channel_done(zchan); } break; + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: case ZAP_CHANNEL_STATE_PROGRESS: { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS; + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - //send progress + } } break; @@ -357,18 +435,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } - } - break; - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } } else { - // send alerting + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } break; @@ -380,7 +448,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - // send connect + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_ANSWERED, + 0); } } break; @@ -395,7 +468,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED, - 0); + zchan->caller_data.hangup_cause); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } @@ -410,6 +483,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } +static __inline__ void init_outgoing_array(void) +{ + memset(&OUTBOUND_REQUESTS, 0, sizeof(OUTBOUND_REQUESTS)); +} static __inline__ void check_state(zap_span_t *span) { @@ -429,13 +506,13 @@ static __inline__ void check_state(zap_span_t *span) } } - static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - + uint32_t ms = 10, too_long = 60000; + ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -460,7 +537,9 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - mcon->rxseq_reset = 1; + top: + + init_outgoing_array(); ss7bc_exec_command(mcon, 0, @@ -471,7 +550,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { fd_set rfds, efds; - struct timeval tv = { 0, 100000 }; + struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; ss7bc_event_t *event = NULL; @@ -488,28 +567,34 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) goto error; } - if (!activity) { - continue; - } - - if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) { - goto error; - } - - if (FD_ISSET(pcon->socket, &rfds)) { - if ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, pcon, event); + if (activity) { + if (FD_ISSET(pcon->socket, &efds) || FD_ISSET(mcon->socket, &efds)) { + goto error; } - } - if (FD_ISSET(mcon->socket, &rfds)) { - if ((event = ss7bc_connection_read(mcon, i))) { - parse_ss7_event(span, mcon, event); + if (FD_ISSET(pcon->socket, &rfds)) { + if ((event = ss7bc_connection_readp(pcon, i))) { + parse_ss7_event(span, pcon, event); + } else goto top; + } + + if (FD_ISSET(mcon->socket, &rfds)) { + if ((event = ss7bc_connection_read(mcon, i))) { + parse_ss7_event(span, mcon, event); + } else goto top; } } check_state(span); + mcon->hb_elapsed += ms; + if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + mcon->up = 0; + zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); + } + } goto end; @@ -568,7 +653,8 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, span->signal_type = ZAP_SIGTYPE_SS7BOOST; span->outgoing_call = ss7_boost_outgoing_call; span->channel_request = ss7_boost_channel_request; - + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + return ZAP_SUCCESS; } From ae4020acacb15490d69567b86a857d91a27b1e85 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 16 Mar 2008 23:43:56 +0000 Subject: [PATCH 0823/1766] proper gethostebyname_r detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@421 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 3 ++- libs/openzap/src/ss7_boost_client.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index ffe599eb37..2931a4f262 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -45,7 +45,8 @@ sun) ;; esac -AC_CHECK_HEADERS([netinet/sctp.h]) +AC_CHECK_HEADERS([netinet/sctp.h netdb.h]) +AC_CHECK_FUNCS([gethostbyname_r]) # Enable debugging AC_ARG_ENABLE(debug, diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index dc0151e2ab..d2ec25d597 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -30,15 +30,21 @@ * 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 gethostbyname_r -extern int gethostbyname_r (__const char *__restrict __name, - struct hostent *__restrict __result_buf, - char *__restrict __buf, size_t __buflen, - struct hostent **__restrict __result, - int *__restrict __h_errnop); + +#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 ss7bc_map { From f09846d3e9e95af3c45865965f508bfd4d8edeca Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 16 Mar 2008 23:43:56 +0000 Subject: [PATCH 0824/1766] proper gethostebyname_r detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@421 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 3 ++- libs/freetdm/src/ss7_boost_client.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index ffe599eb37..2931a4f262 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -45,7 +45,8 @@ sun) ;; esac -AC_CHECK_HEADERS([netinet/sctp.h]) +AC_CHECK_HEADERS([netinet/sctp.h netdb.h]) +AC_CHECK_FUNCS([gethostbyname_r]) # Enable debugging AC_ARG_ENABLE(debug, diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index dc0151e2ab..d2ec25d597 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -30,15 +30,21 @@ * 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 gethostbyname_r -extern int gethostbyname_r (__const char *__restrict __name, - struct hostent *__restrict __result_buf, - char *__restrict __buf, size_t __buflen, - struct hostent **__restrict __result, - int *__restrict __h_errnop); + +#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 ss7bc_map { From 15408778941265a86af0579387c2b9c77653eeab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 18 Mar 2008 20:19:59 +0000 Subject: [PATCH 0825/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@423 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ss7_boost_client.c | 2 +- libs/openzap/src/zap_ss7_boost.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index d2ec25d597..53a8c8e726 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -247,7 +247,7 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) { int err; - if (!event) { + if (!event || mcon->socket < 0 || !mcon->mutex) { zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); return -EINVAL; } diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index bd1507c9bd..09b3c4d7a2 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -132,9 +132,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } } - if (OUTBOUND_REQUESTS[r].status == BST_READY) { + 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: @@ -162,6 +165,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; return; } @@ -477,6 +481,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } default: break; From b43a995bc0208f6abae1258cb616a146bc90dea6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 18 Mar 2008 20:19:59 +0000 Subject: [PATCH 0826/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@423 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ss7_boost_client.c | 2 +- libs/freetdm/src/zap_ss7_boost.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index d2ec25d597..53a8c8e726 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -247,7 +247,7 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) { int err; - if (!event) { + if (!event || mcon->socket < 0 || !mcon->mutex) { zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); return -EINVAL; } diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index bd1507c9bd..09b3c4d7a2 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -132,9 +132,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } } - if (OUTBOUND_REQUESTS[r].status == BST_READY) { + 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: @@ -162,6 +165,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; return; } @@ -477,6 +481,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } default: break; From 2ff832c9b94d03408b8cd5d8d096044ee7803886 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 00:26:27 +0000 Subject: [PATCH 0827/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@424 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 14 ++++++++++- libs/openzap/src/zap_ss7_boost.c | 37 +++++++++++------------------- libs/openzap/src/zap_threadmutex.c | 3 +++ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6ba6fec39d..f5b4bc1b67 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -342,7 +342,7 @@ zap_status_t zap_span_close_all(void) for(i = 1; i <= globals.span_index; i++) { span = &globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 0; j < span->chan_count; j++) { + for(j = 0; j <= span->chan_count; j++) { zap_channel_destroy(&span->channels[j]); } } @@ -940,6 +940,18 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_WINK); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_FLASH); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_3WAY); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 09b3c4d7a2..a6f6ff273e 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -77,7 +77,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) int i; zap_channel_t *zchan = NULL; - for(i = 0; i < span->chan_count; i++) { + for(i = 0; 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]; break; @@ -171,6 +171,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } } + zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); ss7bc_exec_command(mcon, event->span, event->chan, @@ -201,22 +202,17 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e if ((zchan = find_zchan(span, event))) { zchan->caller_data.hangup_cause = event->release_cause; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - } else { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); + zap_log(ZAP_LOG_CRIT, "STOP CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -226,12 +222,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc if ((zchan = find_zchan(span, event))) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } else { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); + zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } } @@ -542,7 +533,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - top: + top: init_outgoing_array(); @@ -579,7 +570,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, pcon, event); + parse_ss7_event(span, mcon, event); } else goto top; } diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 7534d3c965..abeaa1f9b5 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -174,6 +174,9 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) { zap_mutex_t *mp = *mutex; *mutex = NULL; + if (!mp) { + return ZAP_FAIL; + } #ifdef WIN32 DeleteCriticalSection(&mp->mutex); #else From 131b13b236d3cb63eaf3131b575d916320df11f0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 00:26:27 +0000 Subject: [PATCH 0828/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@424 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 14 ++++++++++- libs/freetdm/src/zap_ss7_boost.c | 37 +++++++++++------------------- libs/freetdm/src/zap_threadmutex.c | 3 +++ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6ba6fec39d..f5b4bc1b67 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -342,7 +342,7 @@ zap_status_t zap_span_close_all(void) for(i = 1; i <= globals.span_index; i++) { span = &globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 0; j < span->chan_count; j++) { + for(j = 0; j <= span->chan_count; j++) { zap_channel_destroy(&span->channels[j]); } } @@ -940,6 +940,18 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_WINK); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_FLASH); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_3WAY); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 09b3c4d7a2..a6f6ff273e 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -77,7 +77,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) int i; zap_channel_t *zchan = NULL; - for(i = 0; i < span->chan_count; i++) { + for(i = 0; 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]; break; @@ -171,6 +171,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } } + zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); ss7bc_exec_command(mcon, event->span, event->chan, @@ -201,22 +202,17 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e if ((zchan = find_zchan(span, event))) { zchan->caller_data.hangup_cause = event->release_cause; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - } else { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); + zap_log(ZAP_LOG_CRIT, "STOP CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -226,12 +222,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc if ((zchan = find_zchan(span, event))) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } else { - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); + zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } } @@ -542,7 +533,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - top: + top: init_outgoing_array(); @@ -579,7 +570,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, pcon, event); + parse_ss7_event(span, mcon, event); } else goto top; } diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 7534d3c965..abeaa1f9b5 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -174,6 +174,9 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) { zap_mutex_t *mp = *mutex; *mutex = NULL; + if (!mp) { + return ZAP_FAIL; + } #ifdef WIN32 DeleteCriticalSection(&mp->mutex); #else From 6ac134b1058facd36a9b3984972605dae330b54d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 00:51:13 +0000 Subject: [PATCH 0829/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@425 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_ss7_boost.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index a6f6ff273e..a44b8bb0ba 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -80,6 +80,15 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) for(i = 0; 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 (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + zchan = NULL; + zap_log(ZAP_LOG_WARNING, "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; } } @@ -257,6 +266,8 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ error: + zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + ss7bc_exec_command(mcon, event->span, event->chan, From 18ad7751940cb3fc6cb605084c1ee43734f4cb85 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 00:51:13 +0000 Subject: [PATCH 0830/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@425 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_ss7_boost.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index a6f6ff273e..a44b8bb0ba 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -80,6 +80,15 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) for(i = 0; 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 (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + zchan = NULL; + zap_log(ZAP_LOG_WARNING, "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; } } @@ -257,6 +266,8 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ error: + zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + ss7bc_exec_command(mcon, event->span, event->chan, From 6880c95573a3647782d75b848635274db60d74d9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 20:45:57 +0000 Subject: [PATCH 0831/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@426 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 25 ++++++++-- libs/openzap/src/include/zap_types.h | 12 ++--- libs/openzap/src/zap_io.c | 17 +++---- libs/openzap/src/zap_ss7_boost.c | 66 ++++++++++++++++++-------- 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 4763a52b86..64d19abdec 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -666,21 +666,28 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: { - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } } break; case SWITCH_MESSAGE_INDICATE_PROGRESS: { - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } break; case SWITCH_MESSAGE_INDICATE_ANSWER: { - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } @@ -706,7 +713,11 @@ static switch_status_t channel_receive_message_fxo(switch_core_session_t *sessio switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } break; @@ -731,7 +742,11 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } break; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 84b0243eca..c4f477e625 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -284,7 +284,6 @@ typedef enum { typedef enum { ZAP_CHANNEL_STATE_DOWN, - ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HOLD, ZAP_CHANNEL_STATE_SUSPENDED, ZAP_CHANNEL_STATE_DIALTONE, @@ -296,17 +295,18 @@ typedef enum { ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, ZAP_CHANNEL_STATE_CALLWAITING, - ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_RESTART, - ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, - ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_UP, + ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_TERMINATING, + ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ +#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "IDLE", "UP", "INVALID" + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f5b4bc1b67..13c68f0956 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -979,16 +979,17 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) return ZAP_FAIL; } - zap_mutex_lock(check->mutex); - if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->close(check); - if (status == ZAP_SUCCESS) { - zap_channel_reset(check); - *zchan = NULL; + if (zap_test_flag(check, ZAP_CHANNEL_CONFIGURED)) { + zap_mutex_lock(check->mutex); + if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zio->close(check); + if (status == ZAP_SUCCESS) { + zap_channel_reset(check); + *zchan = NULL; + } } + zap_mutex_unlock(check->mutex); } - - zap_mutex_unlock(check->mutex); return status; } diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index a44b8bb0ba..b131d6a1ba 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -77,21 +77,38 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) int i; zap_channel_t *zchan = NULL; + zap_mutex_lock(signal_mutex); for(i = 0; 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 (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - zchan = NULL; - zap_log(ZAP_LOG_WARNING, "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 - ); + 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"); + + zap_mutex_unlock(signal_mutex); + for (x = 0; x < 200; x++) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + break; + } + zap_sleep(5); + } + zap_mutex_lock(signal_mutex); + } + if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + zchan = NULL; + zap_log(ZAP_LOG_ERROR, "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; } } + zap_mutex_unlock(signal_mutex); return zchan; } @@ -247,13 +264,6 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ goto error; } - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); - zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); @@ -454,6 +464,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -469,12 +486,21 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - zchan->caller_data.hangup_cause); + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED)) { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + zchan->caller_data.hangup_cause); + } else { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + zchan->caller_data.hangup_cause); + } zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } From eba32dae0d3f8a10a527cc8e7c156723c3fa525e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 20:45:57 +0000 Subject: [PATCH 0832/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@426 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 25 ++++++++-- libs/freetdm/src/include/zap_types.h | 12 ++--- libs/freetdm/src/zap_io.c | 17 +++---- libs/freetdm/src/zap_ss7_boost.c | 66 ++++++++++++++++++-------- 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 4763a52b86..64d19abdec 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -666,21 +666,28 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: { - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } } break; case SWITCH_MESSAGE_INDICATE_PROGRESS: { - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } break; case SWITCH_MESSAGE_INDICATE_ANSWER: { - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } @@ -706,7 +713,11 @@ static switch_status_t channel_receive_message_fxo(switch_core_session_t *sessio switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } break; @@ -731,7 +742,11 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } break; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 84b0243eca..c4f477e625 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -284,7 +284,6 @@ typedef enum { typedef enum { ZAP_CHANNEL_STATE_DOWN, - ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HOLD, ZAP_CHANNEL_STATE_SUSPENDED, ZAP_CHANNEL_STATE_DIALTONE, @@ -296,17 +295,18 @@ typedef enum { ZAP_CHANNEL_STATE_DIALING, ZAP_CHANNEL_STATE_GET_CALLERID, ZAP_CHANNEL_STATE_CALLWAITING, - ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_RESTART, - ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, - ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_UP, + ZAP_CHANNEL_STATE_IDLE, + ZAP_CHANNEL_STATE_TERMINATING, + ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "HANGUP", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ +#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "TERMINATING", "RESTART", "PROGRESS_MEDIA", "PROGRESS", "IDLE", "UP", "INVALID" + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f5b4bc1b67..13c68f0956 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -979,16 +979,17 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) return ZAP_FAIL; } - zap_mutex_lock(check->mutex); - if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->close(check); - if (status == ZAP_SUCCESS) { - zap_channel_reset(check); - *zchan = NULL; + if (zap_test_flag(check, ZAP_CHANNEL_CONFIGURED)) { + zap_mutex_lock(check->mutex); + if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zio->close(check); + if (status == ZAP_SUCCESS) { + zap_channel_reset(check); + *zchan = NULL; + } } + zap_mutex_unlock(check->mutex); } - - zap_mutex_unlock(check->mutex); return status; } diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index a44b8bb0ba..b131d6a1ba 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -77,21 +77,38 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) int i; zap_channel_t *zchan = NULL; + zap_mutex_lock(signal_mutex); for(i = 0; 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 (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - zchan = NULL; - zap_log(ZAP_LOG_WARNING, "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 - ); + 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"); + + zap_mutex_unlock(signal_mutex); + for (x = 0; x < 200; x++) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + break; + } + zap_sleep(5); + } + zap_mutex_lock(signal_mutex); + } + if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + zchan = NULL; + zap_log(ZAP_LOG_ERROR, "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; } } + zap_mutex_unlock(signal_mutex); return zchan; } @@ -247,13 +264,6 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ goto error; } - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); - zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); @@ -454,6 +464,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -469,12 +486,21 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - zchan->caller_data.hangup_cause); + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED)) { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + zchan->caller_data.hangup_cause); + } else { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + zchan->caller_data.hangup_cause); + } zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } From d39e00d82c3aef93c3d7c724496aaab0e3568057 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 23:23:04 +0000 Subject: [PATCH 0833/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@427 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 +- libs/openzap/src/include/zap_types.h | 3 +- libs/openzap/src/zap_analog.c | 1 + libs/openzap/src/zap_io.c | 30 ++++++++----- libs/openzap/src/zap_isdn.c | 3 +- libs/openzap/src/zap_ss7_boost.c | 66 +++++++++++++++++++--------- 6 files changed, 71 insertions(+), 34 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 6261e2e57f..ee4b4a7ac7 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -536,7 +536,7 @@ void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); - +zap_status_t zap_channel_complete_state(zap_channel_t *zchan); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index c4f477e625..2336e7ded3 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -302,11 +302,12 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_HANGUP, + ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "INVALID" + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "HANGUP_COMPLETE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 7e6027e06b..3b1246961b 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -345,6 +345,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } 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", diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 13c68f0956..6ef687e7a1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -599,6 +599,25 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) } +zap_status_t zap_channel_complete_state(zap_channel_t *zchan) +{ + zap_channel_state_t state = zchan->state; + + if (state == ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + } else if (state == ZAP_CHANNEL_STATE_UP) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); + } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + } + + return ZAP_SUCCESS; +} + + zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) { int ok = 1; @@ -669,17 +688,6 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } if (ok) { - if (state == ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - } else if (state == ZAP_CHANNEL_STATE_UP) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); - zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); - } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); - } - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->active_count++; } else if (state == ZAP_CHANNEL_STATE_DOWN) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 8af35ef12a..f105174353 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -334,7 +334,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -523,6 +523,7 @@ static __inline__ void check_state(zap_span_t *span) for(j = 1; j <= span->chan_count; j++) { if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); } } diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index b131d6a1ba..685c13cc29 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -72,7 +72,7 @@ static ss7_boost_request_id_t next_request_id(void) return r + 1; } -static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) +static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) { int i; zap_channel_t *zchan = NULL; @@ -81,6 +81,9 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) for(i = 0; 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) { + break; + } if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state >= ZAP_CHANNEL_STATE_TERMINATING) { int x = 0; @@ -108,6 +111,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) break; } } + zap_mutex_unlock(signal_mutex); return zchan; @@ -185,7 +189,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event))) { + if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 1))) { OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); @@ -208,6 +212,18 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } +static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event, 1))) { + + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_log(ZAP_LOG_CRIT, "DONE CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + } +} + static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *event) { OUTBOUND_REQUESTS[event->call_setup_id].event = *event; @@ -225,7 +241,7 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e { zap_channel_t *zchan; - if ((zchan = find_zchan(span, event))) { + if ((zchan = find_zchan(span, event, 1))) { zchan->caller_data.hangup_cause = event->release_cause; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } else { @@ -245,7 +261,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc { zap_channel_t *zchan; - if ((zchan = find_zchan(span, event))) { + if ((zchan = find_zchan(span, event, 1))) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); @@ -256,7 +272,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ { zap_channel_t *zchan; - if (!(zchan = find_zchan(span, event))) { + if (!(zchan = find_zchan(span, event, 0))) { goto error; } @@ -372,11 +388,9 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve case SIGBOOST_EVENT_HEARTBEAT: handle_heartbeat(mcon, event); break; - case SIGBOOST_EVENT_CALL_START_NACK_ACK: - //handle_call_start_nack_ack(event); - break; case SIGBOOST_EVENT_CALL_STOPPED_ACK: - //handle_call_stop_ack(event); + case SIGBOOST_EVENT_CALL_START_NACK_ACK: + handle_call_done(span, mcon, event); break; case SIGBOOST_EVENT_INSERT_CHECK_LOOP: //handle_call_loop_start(event); @@ -432,7 +446,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); } } break; @@ -449,7 +468,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -464,12 +483,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); + + if (!(zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA))) { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + } ss7bc_exec_command(mcon, zchan->physical_span_id-1, @@ -484,6 +506,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) { } break; + case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + break; case ZAP_CHANNEL_STATE_HANGUP: { if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED)) { @@ -500,9 +527,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 0, SIGBOOST_EVENT_CALL_START_NACK, zchan->caller_data.hangup_cause); - } - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - + } } break; case ZAP_CHANNEL_STATE_TERMINATING: @@ -531,6 +556,7 @@ static __inline__ void check_state(zap_span_t *span) if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { zap_mutex_lock(signal_mutex); state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); zap_mutex_unlock(signal_mutex); zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); } From bb14afecc00a9c317154853bc0a73c6ad985ddb1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Mar 2008 23:23:04 +0000 Subject: [PATCH 0834/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@427 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 +- libs/freetdm/src/include/zap_types.h | 3 +- libs/freetdm/src/zap_analog.c | 1 + libs/freetdm/src/zap_io.c | 30 ++++++++----- libs/freetdm/src/zap_isdn.c | 3 +- libs/freetdm/src/zap_ss7_boost.c | 66 +++++++++++++++++++--------- 6 files changed, 71 insertions(+), 34 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 6261e2e57f..ee4b4a7ac7 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -536,7 +536,7 @@ void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); - +zap_status_t zap_channel_complete_state(zap_channel_t *zchan); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index c4f477e625..2336e7ded3 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -302,11 +302,12 @@ typedef enum { ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_HANGUP, + ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "INVALID" + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "HANGUP_COMPLETE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 7e6027e06b..3b1246961b 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -345,6 +345,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } 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", diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 13c68f0956..6ef687e7a1 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -599,6 +599,25 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) } +zap_status_t zap_channel_complete_state(zap_channel_t *zchan) +{ + zap_channel_state_t state = zchan->state; + + if (state == ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + } else if (state == ZAP_CHANNEL_STATE_UP) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); + } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); + } + + return ZAP_SUCCESS; +} + + zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) { int ok = 1; @@ -669,17 +688,6 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } if (ok) { - if (state == ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - } else if (state == ZAP_CHANNEL_STATE_UP) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); - zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); - } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); - } - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->active_count++; } else if (state == ZAP_CHANNEL_STATE_DOWN) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 8af35ef12a..f105174353 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -334,7 +334,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -523,6 +523,7 @@ static __inline__ void check_state(zap_span_t *span) for(j = 1; j <= span->chan_count; j++) { if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); } } diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index b131d6a1ba..685c13cc29 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -72,7 +72,7 @@ static ss7_boost_request_id_t next_request_id(void) return r + 1; } -static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) +static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) { int i; zap_channel_t *zchan = NULL; @@ -81,6 +81,9 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) for(i = 0; 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) { + break; + } if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state >= ZAP_CHANNEL_STATE_TERMINATING) { int x = 0; @@ -108,6 +111,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event) break; } } + zap_mutex_unlock(signal_mutex); return zchan; @@ -185,7 +189,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event))) { + if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 1))) { OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); @@ -208,6 +212,18 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } +static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +{ + zap_channel_t *zchan; + + if ((zchan = find_zchan(span, event, 1))) { + + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_log(ZAP_LOG_CRIT, "DONE CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + } +} + static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *event) { OUTBOUND_REQUESTS[event->call_setup_id].event = *event; @@ -225,7 +241,7 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e { zap_channel_t *zchan; - if ((zchan = find_zchan(span, event))) { + if ((zchan = find_zchan(span, event, 1))) { zchan->caller_data.hangup_cause = event->release_cause; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } else { @@ -245,7 +261,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc { zap_channel_t *zchan; - if ((zchan = find_zchan(span, event))) { + if ((zchan = find_zchan(span, event, 1))) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); @@ -256,7 +272,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ { zap_channel_t *zchan; - if (!(zchan = find_zchan(span, event))) { + if (!(zchan = find_zchan(span, event, 0))) { goto error; } @@ -372,11 +388,9 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve case SIGBOOST_EVENT_HEARTBEAT: handle_heartbeat(mcon, event); break; - case SIGBOOST_EVENT_CALL_START_NACK_ACK: - //handle_call_start_nack_ack(event); - break; case SIGBOOST_EVENT_CALL_STOPPED_ACK: - //handle_call_stop_ack(event); + case SIGBOOST_EVENT_CALL_START_NACK_ACK: + handle_call_done(span, mcon, event); break; case SIGBOOST_EVENT_INSERT_CHECK_LOOP: //handle_call_loop_start(event); @@ -432,7 +446,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); } } break; @@ -449,7 +468,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state > ZAP_CHANNEL_STATE_HANGUP) { + if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -464,12 +483,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); + + if (!(zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA))) { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + } ss7bc_exec_command(mcon, zchan->physical_span_id-1, @@ -484,6 +506,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) { } break; + case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + break; case ZAP_CHANNEL_STATE_HANGUP: { if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED)) { @@ -500,9 +527,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 0, SIGBOOST_EVENT_CALL_START_NACK, zchan->caller_data.hangup_cause); - } - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - + } } break; case ZAP_CHANNEL_STATE_TERMINATING: @@ -531,6 +556,7 @@ static __inline__ void check_state(zap_span_t *span) if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { zap_mutex_lock(signal_mutex); state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); zap_mutex_unlock(signal_mutex); zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); } From 8e2257ff8abb78398c4b7d603410014236f8e971 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 28 Mar 2008 23:22:21 +0000 Subject: [PATCH 0835/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@429 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/zap_io.c | 4 +- libs/openzap/src/zap_isdn.c | 23 ++++----- libs/openzap/src/zap_ss7_boost.c | 76 +++++++++++++++++++----------- 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index ee4b4a7ac7..2a02885da2 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -344,6 +344,7 @@ struct zap_channel { uint32_t physical_span_id; uint32_t physical_chan_id; uint32_t rate; + uint32_t extra_id; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6ef687e7a1..b54bacbb26 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -686,7 +686,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (state == zchan->state) { ok = 0; } - + if (ok) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->active_count++; @@ -695,7 +695,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); + zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; zchan->state = state; } diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index f105174353..e2fe1c241f 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -518,19 +518,20 @@ static __inline__ void state_advance(zap_channel_t *zchan) static __inline__ void check_state(zap_span_t *span) { - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { - uint32_t j; - for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - state_advance(&span->channels[j]); - zap_channel_complete_state(&span->channels[j]); - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); - } - } - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); - } + 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_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); + } + } + } } + static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 685c13cc29..4b0c33a488 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -51,25 +51,42 @@ typedef struct { zap_channel_t *zchan; } ss7_boost_request_t; -static ss7_boost_request_id_t current_request = 0; +#define MAX_REQ_ID MAX_PENDING_CALLS -static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_PENDING_CALLS] = {{ 0 }}; +static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; +static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; + +static void release_request_id(ss7_boost_request_id_t r) +{ + zap_mutex_lock(request_mutex); + req_map[r] = 0; + zap_mutex_unlock(request_mutex); +} + static ss7_boost_request_id_t next_request_id(void) { - ss7_boost_request_id_t r; - - zap_mutex_lock(request_mutex); - if (current_request == MAX_PENDING_CALLS) { - current_request = 0; - } - r = current_request++; - zap_mutex_unlock(request_mutex); + ss7_boost_request_id_t r = 0; + int ok = 0; - return r + 1; + while(!ok) { + zap_mutex_lock(request_mutex); + for (r = 1; r <= MAX_REQ_ID; r++) { + if (!req_map[r]) { + ok = 1; + req_map[r] = 1; + break; + } + } + zap_mutex_unlock(request_mutex); + if (!ok) { + zap_sleep(5); + } + } + return r; } static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) @@ -193,9 +210,11 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + release_request_id(event->call_setup_id); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + zchan->extra_id = event->call_setup_id; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; return; } @@ -228,7 +247,7 @@ static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *even { OUTBOUND_REQUESTS[event->call_setup_id].event = *event; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - + release_request_id(event->call_setup_id); ss7bc_exec_command(mcon, event->span, event->chan, @@ -434,7 +453,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) switch (zchan->state) { case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(zchan); + if (zchan->extra_id) { + release_request_id((ss7_boost_request_id_t)zchan->extra_id); + zchan->extra_id = 0; + } + zap_channel_done(zchan); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -548,23 +571,20 @@ static __inline__ void init_outgoing_array(void) static __inline__ void check_state(zap_span_t *span) { - - - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { - uint32_t j; - for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - zap_mutex_lock(signal_mutex); - state_advance(&span->channels[j]); - zap_channel_complete_state(&span->channels[j]); - zap_mutex_unlock(signal_mutex); - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); - } - } - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); - } + 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_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); + } + } + } } + static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; From 43d251490e53f6cb3356965d6271442ce26b6fcb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 28 Mar 2008 23:22:21 +0000 Subject: [PATCH 0836/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@429 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 4 +- libs/freetdm/src/zap_isdn.c | 23 ++++----- libs/freetdm/src/zap_ss7_boost.c | 76 +++++++++++++++++++----------- 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ee4b4a7ac7..2a02885da2 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -344,6 +344,7 @@ struct zap_channel { uint32_t physical_span_id; uint32_t physical_chan_id; uint32_t rate; + uint32_t extra_id; zap_chan_type_t type; zap_socket_t sockfd; zap_channel_flag_t flags; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6ef687e7a1..b54bacbb26 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -686,7 +686,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (state == zchan->state) { ok = 0; } - + if (ok) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->active_count++; @@ -695,7 +695,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); + zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; zchan->state = state; } diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index f105174353..e2fe1c241f 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -518,19 +518,20 @@ static __inline__ void state_advance(zap_channel_t *zchan) static __inline__ void check_state(zap_span_t *span) { - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { - uint32_t j; - for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - state_advance(&span->channels[j]); - zap_channel_complete_state(&span->channels[j]); - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); - } - } - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); - } + 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_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); + } + } + } } + static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 685c13cc29..4b0c33a488 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -51,25 +51,42 @@ typedef struct { zap_channel_t *zchan; } ss7_boost_request_t; -static ss7_boost_request_id_t current_request = 0; +#define MAX_REQ_ID MAX_PENDING_CALLS -static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_PENDING_CALLS] = {{ 0 }}; +static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; +static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; + +static void release_request_id(ss7_boost_request_id_t r) +{ + zap_mutex_lock(request_mutex); + req_map[r] = 0; + zap_mutex_unlock(request_mutex); +} + static ss7_boost_request_id_t next_request_id(void) { - ss7_boost_request_id_t r; - - zap_mutex_lock(request_mutex); - if (current_request == MAX_PENDING_CALLS) { - current_request = 0; - } - r = current_request++; - zap_mutex_unlock(request_mutex); + ss7_boost_request_id_t r = 0; + int ok = 0; - return r + 1; + while(!ok) { + zap_mutex_lock(request_mutex); + for (r = 1; r <= MAX_REQ_ID; r++) { + if (!req_map[r]) { + ok = 1; + req_map[r] = 1; + break; + } + } + zap_mutex_unlock(request_mutex); + if (!ok) { + zap_sleep(5); + } + } + return r; } static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) @@ -193,9 +210,11 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + release_request_id(event->call_setup_id); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + zchan->extra_id = event->call_setup_id; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; return; } @@ -228,7 +247,7 @@ static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *even { OUTBOUND_REQUESTS[event->call_setup_id].event = *event; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - + release_request_id(event->call_setup_id); ss7bc_exec_command(mcon, event->span, event->chan, @@ -434,7 +453,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) switch (zchan->state) { case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(zchan); + if (zchan->extra_id) { + release_request_id((ss7_boost_request_id_t)zchan->extra_id); + zchan->extra_id = 0; + } + zap_channel_done(zchan); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -548,23 +571,20 @@ static __inline__ void init_outgoing_array(void) static __inline__ void check_state(zap_span_t *span) { - - - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { - uint32_t j; - for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - zap_mutex_lock(signal_mutex); - state_advance(&span->channels[j]); - zap_channel_complete_state(&span->channels[j]); - zap_mutex_unlock(signal_mutex); - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); - } - } - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); - } + 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_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); + } + } + } } + static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; From 307b0ffad8b5d9804562a7bf2034b549ece17aa5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 00:38:40 +0000 Subject: [PATCH 0837/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@430 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 + libs/openzap/src/include/openzap.h | 2 + libs/openzap/src/ss7_boost_client.c | 2 + libs/openzap/src/zap_io.c | 13 +++++ libs/openzap/src/zap_ss7_boost.c | 66 +++++++++++++++++++------- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 64d19abdec..d0002ebd16 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -333,6 +333,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session) globals.calls++; switch_mutex_unlock(globals.mutex); + zap_channel_init(tech_pvt->zchan); + return SWITCH_STATUS_SUCCESS; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 2a02885da2..4cdd259fb8 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -358,6 +358,7 @@ struct zap_channel { uint32_t packet_len; zap_channel_state_t state; zap_channel_state_t last_state; + zap_channel_state_t init_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; uint32_t buffer_delay; @@ -538,6 +539,7 @@ int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); zap_status_t zap_channel_complete_state(zap_channel_t *zchan); +zap_status_t zap_channel_init(zap_channel_t *zchan); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index 53a8c8e726..21690506b1 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -135,6 +135,8 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) 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; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index b54bacbb26..7be39a47b6 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -722,6 +722,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } if (span_id && globals.spans[span_id].channel_request) { + zap_mutex_unlock(globals.mutex); status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); goto done; } @@ -846,6 +847,16 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) return ZAP_SUCCESS; } +zap_status_t zap_channel_init(zap_channel_t *zchan) +{ + if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(zchan, zchan->init_state); + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; + } + + return ZAP_SUCCESS; +} + zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -960,6 +971,8 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; + zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 4b0c33a488..fac6cf9840 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -101,7 +101,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int for if (force) { break; } - if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + 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"); @@ -182,6 +182,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { *zchan = OUTBOUND_REQUESTS[r].zchan; status = ZAP_SUCCESS; + (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; } else { status = ZAP_FAIL; *zchan = NULL; @@ -206,16 +207,16 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 1))) { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + 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); release_request_id(event->call_setup_id); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); zchan->extra_id = event->call_setup_id; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; return; } } @@ -243,17 +244,30 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e } } -static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - release_request_id(event->call_setup_id); - ss7bc_exec_command(mcon, - event->span, - event->chan, - event->call_setup_id, - SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); + + if (event->call_setup_id) { + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + + ss7bc_exec_command(mcon, + event->span, + event->chan, + event->call_setup_id, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + + release_request_id(event->call_setup_id); + } else { + zap_channel_t *zchan; + if ((zchan = find_zchan(span, event, 1))) { + assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); + zchan->caller_data.hangup_cause = event->release_cause; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } + } + } static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -281,6 +295,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { + assert(zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); @@ -351,6 +366,12 @@ static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { zap_mutex_lock(signal_mutex); + + if (!zap_running()) { + zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); + goto end; + } + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { @@ -399,7 +420,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve handle_call_start_ack(mcon, event); break; case SIGBOOST_EVENT_CALL_START_NACK: - handle_call_start_nack(mcon, event); + handle_call_start_nack(span, mcon, event); break; case SIGBOOST_EVENT_CALL_ANSWERED: handle_call_answer(span, mcon, event); @@ -506,7 +527,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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))) { ss7bc_exec_command(mcon, zchan->physical_span_id-1, @@ -536,7 +556,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -627,11 +647,21 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); - while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { + while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; ss7bc_event_t *event = NULL; + + if (!zap_running()) { + ss7bc_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + break; + } FD_ZERO(&rfds); FD_ZERO(&efds); From e0512294af669a05bc6f11c4eb7b70f00c516921 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 00:38:40 +0000 Subject: [PATCH 0838/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@430 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 + libs/freetdm/src/include/openzap.h | 2 + libs/freetdm/src/ss7_boost_client.c | 2 + libs/freetdm/src/zap_io.c | 13 +++++ libs/freetdm/src/zap_ss7_boost.c | 66 +++++++++++++++++++------- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 64d19abdec..d0002ebd16 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -333,6 +333,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session) globals.calls++; switch_mutex_unlock(globals.mutex); + zap_channel_init(tech_pvt->zchan); + return SWITCH_STATUS_SUCCESS; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 2a02885da2..4cdd259fb8 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -358,6 +358,7 @@ struct zap_channel { uint32_t packet_len; zap_channel_state_t state; zap_channel_state_t last_state; + zap_channel_state_t init_state; zap_mutex_t *mutex; teletone_dtmf_detect_state_t dtmf_detect; uint32_t buffer_delay; @@ -538,6 +539,7 @@ int zap_hash_equalkeys(void *k1, void *k2); uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); zap_status_t zap_channel_complete_state(zap_channel_t *zchan); +zap_status_t zap_channel_init(zap_channel_t *zchan); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index 53a8c8e726..21690506b1 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -135,6 +135,8 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) 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; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index b54bacbb26..7be39a47b6 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -722,6 +722,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } if (span_id && globals.spans[span_id].channel_request) { + zap_mutex_unlock(globals.mutex); status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); goto done; } @@ -846,6 +847,16 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) return ZAP_SUCCESS; } +zap_status_t zap_channel_init(zap_channel_t *zchan) +{ + if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(zchan, zchan->init_state); + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; + } + + return ZAP_SUCCESS; +} + zap_status_t zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -960,6 +971,8 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; + zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 4b0c33a488..fac6cf9840 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -101,7 +101,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int for if (force) { break; } - if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + 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"); @@ -182,6 +182,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { *zchan = OUTBOUND_REQUESTS[r].zchan; status = ZAP_SUCCESS; + (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; } else { status = ZAP_FAIL; *zchan = NULL; @@ -206,16 +207,16 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 1))) { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + 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); release_request_id(event->call_setup_id); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); zchan->extra_id = event->call_setup_id; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; return; } } @@ -243,17 +244,30 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e } } -static void handle_call_start_nack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - release_request_id(event->call_setup_id); - ss7bc_exec_command(mcon, - event->span, - event->chan, - event->call_setup_id, - SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); + + if (event->call_setup_id) { + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + + ss7bc_exec_command(mcon, + event->span, + event->chan, + event->call_setup_id, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + + release_request_id(event->call_setup_id); + } else { + zap_channel_t *zchan; + if ((zchan = find_zchan(span, event, 1))) { + assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); + zchan->caller_data.hangup_cause = event->release_cause; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + } + } + } static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -281,6 +295,7 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { + assert(zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); @@ -351,6 +366,12 @@ static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { zap_mutex_lock(signal_mutex); + + if (!zap_running()) { + zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); + goto end; + } + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { @@ -399,7 +420,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve handle_call_start_ack(mcon, event); break; case SIGBOOST_EVENT_CALL_START_NACK: - handle_call_start_nack(mcon, event); + handle_call_start_nack(span, mcon, event); break; case SIGBOOST_EVENT_CALL_ANSWERED: handle_call_answer(span, mcon, event); @@ -506,7 +527,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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))) { ss7bc_exec_command(mcon, zchan->physical_span_id-1, @@ -536,7 +556,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -627,11 +647,21 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); - while (zap_running() && zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { + while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; ss7bc_event_t *event = NULL; + + if (!zap_running()) { + ss7bc_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + break; + } FD_ZERO(&rfds); FD_ZERO(&efds); From 426d2a767f2bcf5c3ac4eb62602eb1868f01af7f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 17:29:57 +0000 Subject: [PATCH 0839/1766] add oz api command git-svn-id: http://svn.openzap.org/svn/openzap/trunk@432 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 139 ++++++++++++++++++++++++- libs/openzap/src/include/zap_types.h | 3 + libs/openzap/src/zap_io.c | 4 + 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d0002ebd16..953d3a4c03 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -60,6 +60,7 @@ struct span_config { char dial_regex[256]; char fail_dial_regex[256]; char hold_music[256]; + char type[256]; analog_option_t analog_options; }; @@ -1544,7 +1545,7 @@ static switch_status_t load_config(void) if (hold_music) { switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } - + switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type)); zap_analog_start(span); } } @@ -1604,6 +1605,7 @@ static switch_status_t load_config(void) SPAN_CONFIG[span->span_id].span = span; switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); zap_isdn_start(span); } @@ -1669,6 +1671,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); zap_ss7_boost_start(span); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); } } @@ -1679,9 +1682,140 @@ static switch_status_t load_config(void) return SWITCH_STATUS_SUCCESS; } + +void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) +{ + stream->write_function(stream, + "span_id: %u\n" + "chan_id: %u\n" + "physical_span_id: %u\n" + "physical_chan_id: %u\n" + "type: %s\n" + "state: %s\n" + "last_state: %s\n" + "cid_date: %s\n" + "cid_name: %s\n" + "cid_num: %s\n" + "ani: %s\n" + "aniII: %s\n" + "dnis: %s\n" + "rdnis: %s\n" + "cause: %s\n\n", + span->channels[chan_id].span_id, + span->channels[chan_id].chan_id, + span->channels[chan_id].physical_span_id, + span->channels[chan_id].physical_chan_id, + zap_chan_type2str(span->channels[chan_id].type), + zap_channel_state2str(span->channels[chan_id].state), + zap_channel_state2str(span->channels[chan_id].last_state), + span->channels[chan_id].caller_data.cid_date, + span->channels[chan_id].caller_data.cid_name, + span->channels[chan_id].caller_data.cid_num.digits, + span->channels[chan_id].caller_data.ani.digits, + span->channels[chan_id].caller_data.aniII, + span->channels[chan_id].caller_data.dnis.digits, + span->channels[chan_id].caller_data.rdnis.digits, + switch_channel_cause2str(span->channels[chan_id].caller_data.hangup_cause) + ); +} + +#define OZ_SYNTAX "list || dump []" +SWITCH_STANDARD_API(oz_function) +{ + char *mycmd = NULL, *argv[10] = { 0 }; + int argc = 0; + + if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) { + argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } + + if (!argc) { + stream->write_function(stream, "%s", OZ_SYNTAX); + goto end; + } + + if (!strcasecmp(argv[0], "dump")) { + if (argc < 2) { + stream->write_function(stream, "-ERR Usage: oz dump []\n"); + goto end; + } else { + int32_t span_id, chan_id = 0; + zap_span_t *span; + + span_id = atoi(argv[1]); + + if (argc > 2) { + chan_id = atoi(argv[2]); + } + + if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + stream->write_function(stream, "-ERR invalid span\n"); + } else { + if (chan_id) { + dump_chan(span, chan_id, stream); + } else { + int j; + + stream->write_function(stream, "+OK\n"); + for(j = 0; j <= span->chan_count; j++) { + dump_chan(span, j, stream); + } + + } + } + } + } else if (!strcasecmp(argv[0], "list")) { + int j; + for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { + if (SPAN_CONFIG[j].span) { + char *flags = "none"; + + if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { + flags = "3way"; + } else if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_CALL_SWAP) { + flags = "call swap"; + } + + stream->write_function(stream, + "+OK\n" + "span: %u\n" + "type: %s\n" + "chan_count: %u\n" + "dialplan: %s\n" + "context: %s\n" + "dial_regex: %s\n" + "fail_dial_regex: %s\n" + "hold_music: %s\n" + "analog_options %s\n", + j, + SPAN_CONFIG[j].type, + SPAN_CONFIG[j].span->chan_count, + SPAN_CONFIG[j].dialplan, + SPAN_CONFIG[j].context, + SPAN_CONFIG[j].dial_regex, + SPAN_CONFIG[j].fail_dial_regex, + SPAN_CONFIG[j].hold_music, + flags + ); + } + } + } else { + stream->write_function(stream, "-ERR Usage: oz list || dump []\n"); + } + + end: + + switch_safe_free(mycmd); + + return SWITCH_STATUS_SUCCESS; +} + + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { + switch_api_interface_t *commands_api_interface; + module_pool = pool; zap_global_set_logger(zap_logger); @@ -1701,7 +1835,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) openzap_endpoint_interface->interface_name = "openzap"; openzap_endpoint_interface->io_routines = &openzap_io_routines; openzap_endpoint_interface->state_handler = &openzap_state_handlers; - + + SWITCH_ADD_API(commands_api_interface, "oz", "OpenZAP commands", oz_function, OZ_SYNTAX); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 2336e7ded3..999b84effb 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -274,6 +274,9 @@ typedef enum { ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) + typedef enum { ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0), ZAP_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1), diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 7be39a47b6..26bf9cb58c 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -112,6 +112,10 @@ ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) +ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) +ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) + + static const char *cut_path(const char *in) { const char *p, *ret = in; From 3f9d36f5528353ffa150c36698e1cc80ef2e7130 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 17:29:57 +0000 Subject: [PATCH 0840/1766] add oz api command git-svn-id: http://svn.openzap.org/svn/openzap/trunk@432 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 139 ++++++++++++++++++++++++- libs/freetdm/src/include/zap_types.h | 3 + libs/freetdm/src/zap_io.c | 4 + 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d0002ebd16..953d3a4c03 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -60,6 +60,7 @@ struct span_config { char dial_regex[256]; char fail_dial_regex[256]; char hold_music[256]; + char type[256]; analog_option_t analog_options; }; @@ -1544,7 +1545,7 @@ static switch_status_t load_config(void) if (hold_music) { switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } - + switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type)); zap_analog_start(span); } } @@ -1604,6 +1605,7 @@ static switch_status_t load_config(void) SPAN_CONFIG[span->span_id].span = span; switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); zap_isdn_start(span); } @@ -1669,6 +1671,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); zap_ss7_boost_start(span); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); } } @@ -1679,9 +1682,140 @@ static switch_status_t load_config(void) return SWITCH_STATUS_SUCCESS; } + +void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) +{ + stream->write_function(stream, + "span_id: %u\n" + "chan_id: %u\n" + "physical_span_id: %u\n" + "physical_chan_id: %u\n" + "type: %s\n" + "state: %s\n" + "last_state: %s\n" + "cid_date: %s\n" + "cid_name: %s\n" + "cid_num: %s\n" + "ani: %s\n" + "aniII: %s\n" + "dnis: %s\n" + "rdnis: %s\n" + "cause: %s\n\n", + span->channels[chan_id].span_id, + span->channels[chan_id].chan_id, + span->channels[chan_id].physical_span_id, + span->channels[chan_id].physical_chan_id, + zap_chan_type2str(span->channels[chan_id].type), + zap_channel_state2str(span->channels[chan_id].state), + zap_channel_state2str(span->channels[chan_id].last_state), + span->channels[chan_id].caller_data.cid_date, + span->channels[chan_id].caller_data.cid_name, + span->channels[chan_id].caller_data.cid_num.digits, + span->channels[chan_id].caller_data.ani.digits, + span->channels[chan_id].caller_data.aniII, + span->channels[chan_id].caller_data.dnis.digits, + span->channels[chan_id].caller_data.rdnis.digits, + switch_channel_cause2str(span->channels[chan_id].caller_data.hangup_cause) + ); +} + +#define OZ_SYNTAX "list || dump []" +SWITCH_STANDARD_API(oz_function) +{ + char *mycmd = NULL, *argv[10] = { 0 }; + int argc = 0; + + if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) { + argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } + + if (!argc) { + stream->write_function(stream, "%s", OZ_SYNTAX); + goto end; + } + + if (!strcasecmp(argv[0], "dump")) { + if (argc < 2) { + stream->write_function(stream, "-ERR Usage: oz dump []\n"); + goto end; + } else { + int32_t span_id, chan_id = 0; + zap_span_t *span; + + span_id = atoi(argv[1]); + + if (argc > 2) { + chan_id = atoi(argv[2]); + } + + if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + stream->write_function(stream, "-ERR invalid span\n"); + } else { + if (chan_id) { + dump_chan(span, chan_id, stream); + } else { + int j; + + stream->write_function(stream, "+OK\n"); + for(j = 0; j <= span->chan_count; j++) { + dump_chan(span, j, stream); + } + + } + } + } + } else if (!strcasecmp(argv[0], "list")) { + int j; + for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { + if (SPAN_CONFIG[j].span) { + char *flags = "none"; + + if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { + flags = "3way"; + } else if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_CALL_SWAP) { + flags = "call swap"; + } + + stream->write_function(stream, + "+OK\n" + "span: %u\n" + "type: %s\n" + "chan_count: %u\n" + "dialplan: %s\n" + "context: %s\n" + "dial_regex: %s\n" + "fail_dial_regex: %s\n" + "hold_music: %s\n" + "analog_options %s\n", + j, + SPAN_CONFIG[j].type, + SPAN_CONFIG[j].span->chan_count, + SPAN_CONFIG[j].dialplan, + SPAN_CONFIG[j].context, + SPAN_CONFIG[j].dial_regex, + SPAN_CONFIG[j].fail_dial_regex, + SPAN_CONFIG[j].hold_music, + flags + ); + } + } + } else { + stream->write_function(stream, "-ERR Usage: oz list || dump []\n"); + } + + end: + + switch_safe_free(mycmd); + + return SWITCH_STATUS_SUCCESS; +} + + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { + switch_api_interface_t *commands_api_interface; + module_pool = pool; zap_global_set_logger(zap_logger); @@ -1701,7 +1835,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) openzap_endpoint_interface->interface_name = "openzap"; openzap_endpoint_interface->io_routines = &openzap_io_routines; openzap_endpoint_interface->state_handler = &openzap_state_handlers; - + + SWITCH_ADD_API(commands_api_interface, "oz", "OpenZAP commands", oz_function, OZ_SYNTAX); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 2336e7ded3..999b84effb 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -274,6 +274,9 @@ typedef enum { ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "INVALID" +ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) + typedef enum { ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0), ZAP_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1), diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 7be39a47b6..26bf9cb58c 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -112,6 +112,10 @@ ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) +ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) +ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) + + static const char *cut_path(const char *in) { const char *p, *ret = in; From 56aa60cb2041a609cf56a9b11e5a6ba588a4b06f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 18:53:25 +0000 Subject: [PATCH 0841/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@433 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 ++- libs/openzap/src/zap_isdn.c | 2 +- libs/openzap/src/zap_ss7_boost.c | 35 ++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 999b84effb..40fd649ad2 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -304,13 +304,14 @@ typedef enum { ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_TERMINATING, + ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "HANGUP_COMPLETE", "INVALID" + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index e2fe1c241f..e190960321 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -174,7 +174,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->caller_data.hangup_cause = cause->Value; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } else { - zap_log(ZAP_LOG_CRIT, "Received Diconnect with no matching channel %d\n", chan_id); + zap_log(ZAP_LOG_CRIT, "Received Disconnect with no matching channel %d\n", chan_id); } } break; diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index fac6cf9840..5d586e6d56 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -264,7 +264,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s if ((zchan = find_zchan(span, event, 1))) { assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); zchan->caller_data.hangup_cause = event->release_cause; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CANCEL); } } @@ -279,14 +279,15 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } else { zap_log(ZAP_LOG_CRIT, "STOP CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); } + - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); } @@ -573,12 +574,32 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; + case ZAP_CHANNEL_STATE_CANCEL: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = ss7_boost_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + } + break; case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); } + break; default: break; } From 3768aba8d638c06fa494710faab0741bd8a25f37 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 18:53:25 +0000 Subject: [PATCH 0842/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@433 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 3 ++- libs/freetdm/src/zap_isdn.c | 2 +- libs/freetdm/src/zap_ss7_boost.c | 35 ++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 999b84effb..40fd649ad2 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -304,13 +304,14 @@ typedef enum { ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_IDLE, ZAP_CHANNEL_STATE_TERMINATING, + ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "HANGUP", "HANGUP_COMPLETE", "INVALID" + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) typedef enum { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index e2fe1c241f..e190960321 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -174,7 +174,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan->caller_data.hangup_cause = cause->Value; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } else { - zap_log(ZAP_LOG_CRIT, "Received Diconnect with no matching channel %d\n", chan_id); + zap_log(ZAP_LOG_CRIT, "Received Disconnect with no matching channel %d\n", chan_id); } } break; diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index fac6cf9840..5d586e6d56 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -264,7 +264,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s if ((zchan = find_zchan(span, event, 1))) { assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); zchan->caller_data.hangup_cause = event->release_cause; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CANCEL); } } @@ -279,14 +279,15 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); } else { zap_log(ZAP_LOG_CRIT, "STOP CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); } + - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); } @@ -573,12 +574,32 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; + case ZAP_CHANNEL_STATE_CANCEL: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = ss7_boost_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + } + break; case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); } + break; default: break; } From 8b707829cc97cd8fae6a7af505b127ae780f1310 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 21:49:35 +0000 Subject: [PATCH 0843/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@434 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 8 ++-- libs/openzap/src/include/openzap.h | 2 +- libs/openzap/src/zap_isdn.c | 60 +++++++++++++++++++------- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 953d3a4c03..eade1be790 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -914,13 +914,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - snprintf(name, sizeof(name), "OPENZAP/%s", dest); + snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", zchan->span_id, zchan->chan_id, dest); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); zchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; - + switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); @@ -1018,7 +1019,8 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); } - snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); + snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4cdd259fb8..136fa3f8c4 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -213,7 +213,7 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%dfrom %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s); \ diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index e190960321..3cde7b5860 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -104,17 +104,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { 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); - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: - case ZAP_CHANNEL_STATE_IDLE: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - break; - case ZAP_CHANNEL_STATE_DOWN: - break; - default: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - break; - } + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } break; case 1: @@ -213,9 +203,36 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_status_t status; int fail = 1; uint32_t cplen = mlen; + + zchan = NULL; + if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { + zchan = &span->channels[chan_id]; + } + if (zchan && (status = zap_channel_open_chan(zchan) == ZAP_SUCCESS)) { + 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"); + + 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)) { + zchan = NULL; + 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 + ); + } + } - if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); @@ -238,12 +255,25 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (fail) { + 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 (zchan) { - zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + zap_log(ZAP_LOG_CRIT, "Channel is busy\n"); } else { zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); } + } } @@ -550,7 +580,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even { sig.event_id = ZAP_OOB_ALARM_TRAP; if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_TERMINATING); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); } zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); From 9ad363cffed24459c5827c811d75aa6b1b4c5e44 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Apr 2008 21:49:35 +0000 Subject: [PATCH 0844/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@434 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 8 ++-- libs/freetdm/src/include/openzap.h | 2 +- libs/freetdm/src/zap_isdn.c | 60 +++++++++++++++++++------- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 953d3a4c03..eade1be790 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -914,13 +914,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - snprintf(name, sizeof(name), "OPENZAP/%s", dest); + snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", zchan->span_id, zchan->chan_id, dest); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); zchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; - + switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); @@ -1018,7 +1019,8 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); } - snprintf(name, sizeof(name), "OpenZAP/%s", tech_pvt->caller_profile->destination_number); + snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4cdd259fb8..136fa3f8c4 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -213,7 +213,7 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%dfrom %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s); \ diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index e190960321..3cde7b5860 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -104,17 +104,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { 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); - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: - case ZAP_CHANNEL_STATE_IDLE: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - break; - case ZAP_CHANNEL_STATE_DOWN: - break; - default: - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - break; - } + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } break; case 1: @@ -213,9 +203,36 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_status_t status; int fail = 1; uint32_t cplen = mlen; + + zchan = NULL; + if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { + zchan = &span->channels[chan_id]; + } + if (zchan && (status = zap_channel_open_chan(zchan) == ZAP_SUCCESS)) { + 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"); + + 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)) { + zchan = NULL; + 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 + ); + } + } - if ((status = zap_channel_open(span->span_id, chan_id, &zchan) == ZAP_SUCCESS)) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); @@ -238,12 +255,25 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (fail) { + 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 (zchan) { - zap_log(ZAP_LOG_CRIT, "FIX ME! %s\n", zap_channel_state2str(zchan->state)); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + zap_log(ZAP_LOG_CRIT, "Channel is busy\n"); } else { zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); } + } } @@ -550,7 +580,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even { sig.event_id = ZAP_OOB_ALARM_TRAP; if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_TERMINATING); + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); } zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); From 83459e33f83367315d08815445d9ff5aa8a87dbd Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 2 Apr 2008 06:33:25 +0000 Subject: [PATCH 0845/1766] Test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@435 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ss7/README | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libs/openzap/src/ss7/README diff --git a/libs/openzap/src/ss7/README b/libs/openzap/src/ss7/README new file mode 100644 index 0000000000..f4f786855c --- /dev/null +++ b/libs/openzap/src/ss7/README @@ -0,0 +1,3 @@ +SS7 Coming soon + +Shane Burrell From d7310326ad9b0a4e796210a51cf5c1409ed99cb4 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 2 Apr 2008 06:33:25 +0000 Subject: [PATCH 0846/1766] Test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@435 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ss7/README | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libs/freetdm/src/ss7/README diff --git a/libs/freetdm/src/ss7/README b/libs/freetdm/src/ss7/README new file mode 100644 index 0000000000..f4f786855c --- /dev/null +++ b/libs/freetdm/src/ss7/README @@ -0,0 +1,3 @@ +SS7 Coming soon + +Shane Burrell From 7f8ee9981a0cd7c3f9f87bcfd481a75cc6d9721c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Apr 2008 17:49:18 +0000 Subject: [PATCH 0847/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@436 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 47 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 26bf9cb58c..fe83986f11 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -717,21 +717,17 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c zap_span_t *span; uint32_t span_max; - zap_mutex_lock(globals.mutex); - - if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); - *zchan = NULL; - goto done; - } - - if (span_id && globals.spans[span_id].channel_request) { - zap_mutex_unlock(globals.mutex); - status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); - goto done; - } - if (span_id) { + if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + if (globals.spans[span_id].channel_request) { + return globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); + } + span_max = span_id; j = span_id; } else { @@ -742,19 +738,21 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c j = span_max; } } - + for(;;) { if (direction == ZAP_TOP_DOWN) { if (j > span_max) { - break; + goto done; } } else { if (j == 0) { - break; + goto done; } } span = &globals.spans[j]; + zap_mutex_lock(span->mutex); + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } @@ -766,7 +764,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } for(;;) { - + if (direction == ZAP_TOP_DOWN) { if (i > span->chan_count) { break; @@ -779,7 +777,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED)) { + if (zap_test_flag(check, ZAP_CHANNEL_READY) && + !zap_test_flag(check, ZAP_CHANNEL_INUSE) && + !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && + check->state == ZAP_CHANNEL_STATE_DOWN + ) { status = check->zio->open(check); @@ -787,6 +789,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_channel_open_chan(check); *zchan = check; + zap_mutex_unlock(span->mutex); goto done; } } @@ -796,11 +799,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } else { i--; } - } next_loop: - + + zap_mutex_unlock(span->mutex); + if (direction == ZAP_TOP_DOWN) { j++; } else { @@ -809,7 +813,6 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } done: - zap_mutex_unlock(globals.mutex); return status; } From ca2bbe4bc21be4060b3efb52a0b32f6bf81bb69d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Apr 2008 17:49:18 +0000 Subject: [PATCH 0848/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@436 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 47 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 26bf9cb58c..fe83986f11 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -717,21 +717,17 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c zap_span_t *span; uint32_t span_max; - zap_mutex_lock(globals.mutex); - - if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); - *zchan = NULL; - goto done; - } - - if (span_id && globals.spans[span_id].channel_request) { - zap_mutex_unlock(globals.mutex); - status = globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); - goto done; - } - if (span_id) { + if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + if (globals.spans[span_id].channel_request) { + return globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); + } + span_max = span_id; j = span_id; } else { @@ -742,19 +738,21 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c j = span_max; } } - + for(;;) { if (direction == ZAP_TOP_DOWN) { if (j > span_max) { - break; + goto done; } } else { if (j == 0) { - break; + goto done; } } span = &globals.spans[j]; + zap_mutex_lock(span->mutex); + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } @@ -766,7 +764,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } for(;;) { - + if (direction == ZAP_TOP_DOWN) { if (i > span->chan_count) { break; @@ -779,7 +777,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c check = &span->channels[i]; - if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED)) { + if (zap_test_flag(check, ZAP_CHANNEL_READY) && + !zap_test_flag(check, ZAP_CHANNEL_INUSE) && + !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && + check->state == ZAP_CHANNEL_STATE_DOWN + ) { status = check->zio->open(check); @@ -787,6 +789,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_channel_open_chan(check); *zchan = check; + zap_mutex_unlock(span->mutex); goto done; } } @@ -796,11 +799,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } else { i--; } - } next_loop: - + + zap_mutex_unlock(span->mutex); + if (direction == ZAP_TOP_DOWN) { j++; } else { @@ -809,7 +813,6 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c } done: - zap_mutex_unlock(globals.mutex); return status; } From 5daf56acd5287daeed15ea23fe568294428e2e5a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Apr 2008 20:24:54 +0000 Subject: [PATCH 0849/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@437 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 4 ++-- libs/openzap/src/isdn/Q931.c | 13 +++++++++++++ libs/openzap/src/isdn/include/Q931.h | 1 + libs/openzap/src/zap_isdn.c | 17 ++++++++++++----- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 136fa3f8c4..3d973fd3a6 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -410,6 +410,8 @@ struct zap_isdn_data { struct zap_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; + zap_channel_t *channels_local_crv[32768]; + zap_channel_t *channels_remote_crv[32768]; }; struct zap_analog_data { @@ -438,8 +440,6 @@ struct zap_span { teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; - zap_channel_t *channels_local_crv[32768]; - zap_channel_t *channels_remote_crv[32768]; zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; void *mod_data; diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index cb9c28ab20..272d768766 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -495,6 +495,19 @@ L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) 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 diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 2da5ba5c01..8cea95e586 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -918,6 +918,7 @@ 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); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 3cde7b5860..63a8d4782a 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -85,9 +85,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) #endif if (gen->CRVFlag) { - zchan = span->channels_local_crv[gen->CRV]; + zchan = isdn_data->channels_local_crv[gen->CRV]; } else { - zchan = span->channels_remote_crv[gen->CRV]; + zchan = isdn_data->channels_remote_crv[gen->CRV]; } @@ -197,7 +197,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_SETUP: { - + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); zap_status_t status; @@ -234,7 +234,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - zchan->span->channels_remote_crv[gen->CRV] = zchan; + isdn_data->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_set_string(zchan->caller_data.cid_num.digits, (char *)callingnum->Digit); @@ -268,6 +268,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 { @@ -335,6 +339,9 @@ static __inline__ void state_advance(zap_channel_t *zchan) switch (zchan->state) { case ZAP_CHANNEL_STATE_DOWN: { + if (gen->CRV) { + Q931ReleaseCRV(&isdn_data->q931, gen->CRV); + } zap_channel_done(zchan); } break; @@ -515,7 +522,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani.digits, strlen(zchan->caller_data.ani.digits)+1); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); - zchan->span->channels_local_crv[gen->CRV] = zchan; + isdn_data->channels_local_crv[gen->CRV] = zchan; } break; case ZAP_CHANNEL_STATE_HANGUP: From d06ede0e44dbb1e0294c37777cc2d03055a1f1c0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Apr 2008 20:24:54 +0000 Subject: [PATCH 0850/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@437 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 4 ++-- libs/freetdm/src/isdn/Q931.c | 13 +++++++++++++ libs/freetdm/src/isdn/include/Q931.h | 1 + libs/freetdm/src/zap_isdn.c | 17 ++++++++++++----- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 136fa3f8c4..3d973fd3a6 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -410,6 +410,8 @@ struct zap_isdn_data { struct zap_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; + zap_channel_t *channels_local_crv[32768]; + zap_channel_t *channels_remote_crv[32768]; }; struct zap_analog_data { @@ -438,8 +440,6 @@ struct zap_span { teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; - zap_channel_t *channels_local_crv[32768]; - zap_channel_t *channels_remote_crv[32768]; zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; void *mod_data; diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index cb9c28ab20..272d768766 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -495,6 +495,19 @@ L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) 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 diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 2da5ba5c01..8cea95e586 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -918,6 +918,7 @@ 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); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 3cde7b5860..63a8d4782a 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -85,9 +85,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) #endif if (gen->CRVFlag) { - zchan = span->channels_local_crv[gen->CRV]; + zchan = isdn_data->channels_local_crv[gen->CRV]; } else { - zchan = span->channels_remote_crv[gen->CRV]; + zchan = isdn_data->channels_remote_crv[gen->CRV]; } @@ -197,7 +197,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_SETUP: { - + Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); zap_status_t status; @@ -234,7 +234,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - zchan->span->channels_remote_crv[gen->CRV] = zchan; + isdn_data->channels_remote_crv[gen->CRV] = zchan; memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_set_string(zchan->caller_data.cid_num.digits, (char *)callingnum->Digit); @@ -268,6 +268,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 { @@ -335,6 +339,9 @@ static __inline__ void state_advance(zap_channel_t *zchan) switch (zchan->state) { case ZAP_CHANNEL_STATE_DOWN: { + if (gen->CRV) { + Q931ReleaseCRV(&isdn_data->q931, gen->CRV); + } zap_channel_done(zchan); } break; @@ -515,7 +522,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani.digits, strlen(zchan->caller_data.ani.digits)+1); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); - zchan->span->channels_local_crv[gen->CRV] = zchan; + isdn_data->channels_local_crv[gen->CRV] = zchan; } break; case ZAP_CHANNEL_STATE_HANGUP: From b4f2e40748d277b768db8c78a5d5e4a6bb01387b Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Thu, 3 Apr 2008 03:19:52 +0000 Subject: [PATCH 0851/1766] Intial m3ua commit. Inital port of our m3ua. This should be enough to do ISUP git-svn-id: http://svn.openzap.org/svn/openzap/trunk@438 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua/mstm3ua.c | 58 +++++++++++++++++++++++++ libs/openzap/src/m3ua/mstm3ua.h | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 libs/openzap/src/m3ua/mstm3ua.c create mode 100644 libs/openzap/src/m3ua/mstm3ua.h diff --git a/libs/openzap/src/m3ua/mstm3ua.c b/libs/openzap/src/m3ua/mstm3ua.c new file mode 100644 index 0000000000..8c00bf1483 --- /dev/null +++ b/libs/openzap/src/m3ua/mstm3ua.c @@ -0,0 +1,58 @@ +/* WARNING WORK IN PROGRESS + * mstm3ua.c + * mstss7d port + * + * Created by Shane Burrell on 2/2/08. + * Copyright 2008 Shane Burrell. All rights reserved. + * + */ + +#include "mstm3ua.h" + + +int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len) +{ +//Routing Context + bytemsg[8] = 0x10; //Tag 0x210 Protocol Data + bytemsg[9] = 0x02; + + bytemsg[10] = len; //Len + bytemsg[11] = 0x00; + + + bytemsg[12] = opc[2]; //OPC Member + bytemsg[13] = opc[1]; //OPC Cluster + bytemsg[14] = opc[0]; //OPC Network + + bytemsg[15] = 0x00; + + bytemsg[16] = dpc[2];//DPC Member + bytemsg[17] = dpc[1];//DPC Cluster + bytemsg[18] = dpc[0];//DPC Network + + bytemsg[19] = 0x00; + return 0; +} + + + +int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg) + +{ + + bytemsg[0] = M_VERSION_REL1; // 1 Verison + //bytemsg[1] = 0x00; // 2 RESERVED + //bytemsg[2] = M_CLASS_XFER; // 3 Msg Class + //SS7 BOX Kludge + bytemsg[1] = 0x01; // 2 RESERVED + bytemsg[2] = 0x00; // 2 RESERVED + + bytemsg[3] = M_TYPE_DATA ; // 4 Msg Type + + bytemsg[4] = len; // 5 Msg LENGTH 81 32bit field + bytemsg[5] = 0x00; // 6 + bytemsg[6] = 0x00; // 7 + bytemsg[7] = 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 new file mode 100644 index 0000000000..dc4b9d61eb --- /dev/null +++ b/libs/openzap/src/m3ua/mstm3ua.h @@ -0,0 +1,75 @@ + +/* mstm3ua.h + * mstss7d + * + * Created by Shane Burrell on 3/2/08. + * Copyright 2008 Shane Burrell. All rights reserved. + * + */ + +#ifndef __SS7_M3UA_H__ +#define __SS7_M3UA_H__ + +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 + + + +#endif From 4dbaeebd554ce929f1e0b7f0f9177bdfafc1aff0 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Thu, 3 Apr 2008 03:19:52 +0000 Subject: [PATCH 0852/1766] Intial m3ua commit. Inital port of our m3ua. This should be enough to do ISUP git-svn-id: http://svn.openzap.org/svn/openzap/trunk@438 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua/mstm3ua.c | 58 +++++++++++++++++++++++++ libs/freetdm/src/m3ua/mstm3ua.h | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 libs/freetdm/src/m3ua/mstm3ua.c create mode 100644 libs/freetdm/src/m3ua/mstm3ua.h diff --git a/libs/freetdm/src/m3ua/mstm3ua.c b/libs/freetdm/src/m3ua/mstm3ua.c new file mode 100644 index 0000000000..8c00bf1483 --- /dev/null +++ b/libs/freetdm/src/m3ua/mstm3ua.c @@ -0,0 +1,58 @@ +/* WARNING WORK IN PROGRESS + * mstm3ua.c + * mstss7d port + * + * Created by Shane Burrell on 2/2/08. + * Copyright 2008 Shane Burrell. All rights reserved. + * + */ + +#include "mstm3ua.h" + + +int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len) +{ +//Routing Context + bytemsg[8] = 0x10; //Tag 0x210 Protocol Data + bytemsg[9] = 0x02; + + bytemsg[10] = len; //Len + bytemsg[11] = 0x00; + + + bytemsg[12] = opc[2]; //OPC Member + bytemsg[13] = opc[1]; //OPC Cluster + bytemsg[14] = opc[0]; //OPC Network + + bytemsg[15] = 0x00; + + bytemsg[16] = dpc[2];//DPC Member + bytemsg[17] = dpc[1];//DPC Cluster + bytemsg[18] = dpc[0];//DPC Network + + bytemsg[19] = 0x00; + return 0; +} + + + +int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg) + +{ + + bytemsg[0] = M_VERSION_REL1; // 1 Verison + //bytemsg[1] = 0x00; // 2 RESERVED + //bytemsg[2] = M_CLASS_XFER; // 3 Msg Class + //SS7 BOX Kludge + bytemsg[1] = 0x01; // 2 RESERVED + bytemsg[2] = 0x00; // 2 RESERVED + + bytemsg[3] = M_TYPE_DATA ; // 4 Msg Type + + bytemsg[4] = len; // 5 Msg LENGTH 81 32bit field + bytemsg[5] = 0x00; // 6 + bytemsg[6] = 0x00; // 7 + bytemsg[7] = 0x00; // 8 + return(0); + +}; \ No newline at end of file diff --git a/libs/freetdm/src/m3ua/mstm3ua.h b/libs/freetdm/src/m3ua/mstm3ua.h new file mode 100644 index 0000000000..dc4b9d61eb --- /dev/null +++ b/libs/freetdm/src/m3ua/mstm3ua.h @@ -0,0 +1,75 @@ + +/* mstm3ua.h + * mstss7d + * + * Created by Shane Burrell on 3/2/08. + * Copyright 2008 Shane Burrell. All rights reserved. + * + */ + +#ifndef __SS7_M3UA_H__ +#define __SS7_M3UA_H__ + +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 + + + +#endif From cb615fff36e57148e898b69d435063048c51fb41 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Thu, 3 Apr 2008 05:17:25 +0000 Subject: [PATCH 0853/1766] Added disclamer and license. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@439 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua/mstm3ua.c | 27 +++++++++++++++++++++++++++ libs/openzap/src/m3ua/mstm3ua.h | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libs/openzap/src/m3ua/mstm3ua.c b/libs/openzap/src/m3ua/mstm3ua.c index 8c00bf1483..d5a415b061 100644 --- a/libs/openzap/src/m3ua/mstm3ua.c +++ b/libs/openzap/src/m3ua/mstm3ua.c @@ -5,6 +5,33 @@ * 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" diff --git a/libs/openzap/src/m3ua/mstm3ua.h b/libs/openzap/src/m3ua/mstm3ua.h index dc4b9d61eb..9bec483bda 100644 --- a/libs/openzap/src/m3ua/mstm3ua.h +++ b/libs/openzap/src/m3ua/mstm3ua.h @@ -5,6 +5,33 @@ * 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. */ #ifndef __SS7_M3UA_H__ From 72dedf3b57d25708547945aa05a89056fdba7d55 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Thu, 3 Apr 2008 05:17:25 +0000 Subject: [PATCH 0854/1766] Added disclamer and license. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@439 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua/mstm3ua.c | 27 +++++++++++++++++++++++++++ libs/freetdm/src/m3ua/mstm3ua.h | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libs/freetdm/src/m3ua/mstm3ua.c b/libs/freetdm/src/m3ua/mstm3ua.c index 8c00bf1483..d5a415b061 100644 --- a/libs/freetdm/src/m3ua/mstm3ua.c +++ b/libs/freetdm/src/m3ua/mstm3ua.c @@ -5,6 +5,33 @@ * 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" diff --git a/libs/freetdm/src/m3ua/mstm3ua.h b/libs/freetdm/src/m3ua/mstm3ua.h index dc4b9d61eb..9bec483bda 100644 --- a/libs/freetdm/src/m3ua/mstm3ua.h +++ b/libs/freetdm/src/m3ua/mstm3ua.h @@ -5,6 +5,33 @@ * 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. */ #ifndef __SS7_M3UA_H__ From 737e47552cdcb3295f8cd44cd4e567ff6a2776ca Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Fri, 4 Apr 2008 19:05:01 +0000 Subject: [PATCH 0855/1766] Intial Checkin of M3UA ZAP IO git-svn-id: http://svn.openzap.org/svn/openzap/trunk@440 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_m3ua.c | 253 ++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 libs/openzap/src/zap_m3ua.c diff --git a/libs/openzap/src/zap_m3ua.c b/libs/openzap/src/zap_m3ua.c new file mode 100644 index 0000000000..dcd5aab584 --- /dev/null +++ b/libs/openzap/src/zap_m3ua.c @@ -0,0 +1,253 @@ +/* + * zap_m3ua.c + * openzap + * + * Created by Shane Burrell on 4/3/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 "openzap.h" +//#include "m3ua_client.h" +#include "zap_m3ua.h" + +struct general_config { + uint32_t region; +}; +typedef struct general_config general_config_t; + + +struct m3ua_channel_profile { + char name[80]; + int cust_span; +}; +typedef struct m3ua_channel_profile m3ua_channel_profile_t; + +static struct { + zap_hash_t *profile_hash; + general_config_t general_config; +} globals; + +struct m3ua_span_data { + uint32_t boardno; + uint32_t flags; +}; +typedef struct m3ua_span_data m3ua_span_data_t; + +struct m3ua_chan_data { + zap_buffer_t *digit_buffer; + zap_mutex_t *digit_mutex; + zap_size_t dtmf_len; + uint32_t flags; + uint32_t hdlc_bytes; +}; +typedef struct m3ua_chan_data m3ua_chan_data_t; + + + + + + +static ZIO_CONFIGURE_FUNCTION(m3ua_configure) +{ + m3ua_channel_profile_t *profile = NULL; + int ok = 1; + + if (!(profile = (m3ua_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->play_config = globals.play_config; + hashtable_insert(globals.profile_hash, (void *)profile->name, profile); + zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); + } + + + if (!strcasecmp(var, "local_ip")) { + //profile->span_config.framing = pika_str2span(val); + profile->cust_span++; + } + 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; +} + +static ZIO_CONFIGURE_SPAN_FUNCTION(m3ua_configure_span) +{ + + return ZAP_FAIL; +} + +static ZIO_OPEN_FUNCTION(m3ua_open) +{ + + return ZAP_FAIL; +} + +static ZIO_CLOSE_FUNCTION(m3ua_close) +{ + + return ZAP_FAIL; +} + +/*static ZIO_SET_INTERVAL_FUNCTION(m3ua_set_interval) +{ + + return 0; +}*/ + +static ZIO_WAIT_FUNCTION(m3ua_wait) +{ + + return ZAP_FAIL; +} + +static ZIO_READ_FUNCTION(m3ua_read) +{ + + return ZAP_FAIL; +} + +static ZIO_WRITE_FUNCTION(m3ua_write) +{ + + return ZAP_FAIL; +} + +static ZIO_COMMAND_FUNCTION(m3ua_command) +{ + return ZAP_FAIL; +} + +static ZIO_SPAN_POLL_EVENT_FUNCTION(m3ua_poll_event) +{ + return ZAP_FAIL; +} + +static ZIO_SPAN_NEXT_EVENT_FUNCTION(m3ua_next_event) +{ + return ZAP_FAIL; +} + + +static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) +{ + m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data; + + if (span_data) { + free(span_data); + } + + return ZAP_SUCCESS; +} +static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) +{ + m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) zchan->mod_data; + m3ua_span_data_t *span_data = (m3ua_span_data_t *) zchan->span->mod_data; + + if (!chan_data) { + return ZAP_FAIL; + } + + + + + + + zap_mutex_destroy(&chan_data->digit_mutex); + zap_buffer_destroy(&chan_data->digit_buffer); + + + zap_safe_free(chan_data); + + if (span_data) { + free(span_data); + } + + + return ZAP_SUCCESS; +} + + + +static ZIO_GET_ALARMS_FUNCTION(m3ua_get_alarms) +{ + return ZAP_FAIL; +} + +static zap_io_interface_t m3ua_interface; + +zap_status_t m3ua_init(zap_io_interface_t **zint) +{ + assert(zint != NULL); + memset(&m3ua_interface, 0, sizeof(m3ua_interface)); + + m3ua_interface.name = "m3ua"; + m3ua_interface.configure = m3ua_configure; + m3ua_interface.configure_span = m3ua_configure_span; + m3ua_interface.open = m3ua_open; + m3ua_interface.close = m3ua_close; + m3ua_interface.wait = m3ua_wait; + m3ua_interface.read = m3ua_read; + m3ua_interface.write = m3ua_write; + m3ua_interface.command = m3ua_command; + m3ua_interface.poll_event = m3ua_poll_event; + m3ua_interface.next_event = m3ua_next_event; + m3ua_interface.channel_destroy = m3ua_channel_destroy; + m3ua_interface.span_destroy = m3ua_span_destroy; + m3ua_interface.get_alarms = m3ua_get_alarms; + *zint = &m3ua_interface; + + return ZAP_FAIL; +} + +zap_status_t m3ua_destroy(void) +{ + return ZAP_FAIL; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: +*/ \ No newline at end of file From 00e40e69e506b700e6e351ff7c627d525aa97702 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Fri, 4 Apr 2008 19:05:01 +0000 Subject: [PATCH 0856/1766] Intial Checkin of M3UA ZAP IO git-svn-id: http://svn.openzap.org/svn/openzap/trunk@440 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_m3ua.c | 253 ++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 libs/freetdm/src/zap_m3ua.c diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c new file mode 100644 index 0000000000..dcd5aab584 --- /dev/null +++ b/libs/freetdm/src/zap_m3ua.c @@ -0,0 +1,253 @@ +/* + * zap_m3ua.c + * openzap + * + * Created by Shane Burrell on 4/3/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 "openzap.h" +//#include "m3ua_client.h" +#include "zap_m3ua.h" + +struct general_config { + uint32_t region; +}; +typedef struct general_config general_config_t; + + +struct m3ua_channel_profile { + char name[80]; + int cust_span; +}; +typedef struct m3ua_channel_profile m3ua_channel_profile_t; + +static struct { + zap_hash_t *profile_hash; + general_config_t general_config; +} globals; + +struct m3ua_span_data { + uint32_t boardno; + uint32_t flags; +}; +typedef struct m3ua_span_data m3ua_span_data_t; + +struct m3ua_chan_data { + zap_buffer_t *digit_buffer; + zap_mutex_t *digit_mutex; + zap_size_t dtmf_len; + uint32_t flags; + uint32_t hdlc_bytes; +}; +typedef struct m3ua_chan_data m3ua_chan_data_t; + + + + + + +static ZIO_CONFIGURE_FUNCTION(m3ua_configure) +{ + m3ua_channel_profile_t *profile = NULL; + int ok = 1; + + if (!(profile = (m3ua_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->play_config = globals.play_config; + hashtable_insert(globals.profile_hash, (void *)profile->name, profile); + zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); + } + + + if (!strcasecmp(var, "local_ip")) { + //profile->span_config.framing = pika_str2span(val); + profile->cust_span++; + } + 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; +} + +static ZIO_CONFIGURE_SPAN_FUNCTION(m3ua_configure_span) +{ + + return ZAP_FAIL; +} + +static ZIO_OPEN_FUNCTION(m3ua_open) +{ + + return ZAP_FAIL; +} + +static ZIO_CLOSE_FUNCTION(m3ua_close) +{ + + return ZAP_FAIL; +} + +/*static ZIO_SET_INTERVAL_FUNCTION(m3ua_set_interval) +{ + + return 0; +}*/ + +static ZIO_WAIT_FUNCTION(m3ua_wait) +{ + + return ZAP_FAIL; +} + +static ZIO_READ_FUNCTION(m3ua_read) +{ + + return ZAP_FAIL; +} + +static ZIO_WRITE_FUNCTION(m3ua_write) +{ + + return ZAP_FAIL; +} + +static ZIO_COMMAND_FUNCTION(m3ua_command) +{ + return ZAP_FAIL; +} + +static ZIO_SPAN_POLL_EVENT_FUNCTION(m3ua_poll_event) +{ + return ZAP_FAIL; +} + +static ZIO_SPAN_NEXT_EVENT_FUNCTION(m3ua_next_event) +{ + return ZAP_FAIL; +} + + +static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) +{ + m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data; + + if (span_data) { + free(span_data); + } + + return ZAP_SUCCESS; +} +static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) +{ + m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) zchan->mod_data; + m3ua_span_data_t *span_data = (m3ua_span_data_t *) zchan->span->mod_data; + + if (!chan_data) { + return ZAP_FAIL; + } + + + + + + + zap_mutex_destroy(&chan_data->digit_mutex); + zap_buffer_destroy(&chan_data->digit_buffer); + + + zap_safe_free(chan_data); + + if (span_data) { + free(span_data); + } + + + return ZAP_SUCCESS; +} + + + +static ZIO_GET_ALARMS_FUNCTION(m3ua_get_alarms) +{ + return ZAP_FAIL; +} + +static zap_io_interface_t m3ua_interface; + +zap_status_t m3ua_init(zap_io_interface_t **zint) +{ + assert(zint != NULL); + memset(&m3ua_interface, 0, sizeof(m3ua_interface)); + + m3ua_interface.name = "m3ua"; + m3ua_interface.configure = m3ua_configure; + m3ua_interface.configure_span = m3ua_configure_span; + m3ua_interface.open = m3ua_open; + m3ua_interface.close = m3ua_close; + m3ua_interface.wait = m3ua_wait; + m3ua_interface.read = m3ua_read; + m3ua_interface.write = m3ua_write; + m3ua_interface.command = m3ua_command; + m3ua_interface.poll_event = m3ua_poll_event; + m3ua_interface.next_event = m3ua_next_event; + m3ua_interface.channel_destroy = m3ua_channel_destroy; + m3ua_interface.span_destroy = m3ua_span_destroy; + m3ua_interface.get_alarms = m3ua_get_alarms; + *zint = &m3ua_interface; + + return ZAP_FAIL; +} + +zap_status_t m3ua_destroy(void) +{ + return ZAP_FAIL; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: +*/ \ No newline at end of file From 6223a95b0abaddfe6882b8fc108b1f485f0d911a Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Fri, 4 Apr 2008 19:05:29 +0000 Subject: [PATCH 0857/1766] Intial Checkin of M3UA ZAP IO git-svn-id: http://svn.openzap.org/svn/openzap/trunk@441 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_m3ua.h | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 libs/openzap/src/include/zap_m3ua.h diff --git a/libs/openzap/src/include/zap_m3ua.h b/libs/openzap/src/include/zap_m3ua.h new file mode 100644 index 0000000000..8819d37252 --- /dev/null +++ b/libs/openzap/src/include/zap_m3ua.h @@ -0,0 +1,82 @@ +/* + * zap_m3ua.h + * openzap + * + * Created by Shane Burrell on 4/3/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 "m3ua_client.h" +#include "openzap.h" + +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 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); + + + + + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + From 9397ee671c6acfbca198f2d2a637627fecbe2023 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Fri, 4 Apr 2008 19:05:29 +0000 Subject: [PATCH 0858/1766] Intial Checkin of M3UA ZAP IO git-svn-id: http://svn.openzap.org/svn/openzap/trunk@441 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_m3ua.h | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 libs/freetdm/src/include/zap_m3ua.h diff --git a/libs/freetdm/src/include/zap_m3ua.h b/libs/freetdm/src/include/zap_m3ua.h new file mode 100644 index 0000000000..8819d37252 --- /dev/null +++ b/libs/freetdm/src/include/zap_m3ua.h @@ -0,0 +1,82 @@ +/* + * zap_m3ua.h + * openzap + * + * Created by Shane Burrell on 4/3/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 "m3ua_client.h" +#include "openzap.h" + +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 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); + + + + + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ + From f1ced4783f4345287a674e755885f595a72b22bf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 4 Apr 2008 20:39:14 +0000 Subject: [PATCH 0859/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@442 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 9a3084c2c3..79f52a4a54 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -211,7 +211,9 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) { static L3INT crv={1}; - return crv++; + crv++; + if (crv > 32766) crv = 1; + return crv; } L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) From f8b58eae7c7b5d60aff8e69bbb52cf1d5394924a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 4 Apr 2008 20:39:14 +0000 Subject: [PATCH 0860/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@442 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 9a3084c2c3..79f52a4a54 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -211,7 +211,9 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) { static L3INT crv={1}; - return crv++; + crv++; + if (crv > 32766) crv = 1; + return crv; } L3INT Q931InitMesGeneric(Q931mes_Generic *pMes) From 5803a63bac06af3819298c0c8a293f806e5482aa Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 4 Apr 2008 20:43:48 +0000 Subject: [PATCH 0861/1766] clarify. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@443 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index 79f52a4a54..b0119ef68c 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -208,9 +208,10 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) /***************************************************************************** *****************************************************************************/ +static L3INT crv={1}; + L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) { - static L3INT crv={1}; crv++; if (crv > 32766) crv = 1; return crv; From e97f258474bdb6e30feec09267600515a4b73253 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 4 Apr 2008 20:43:48 +0000 Subject: [PATCH 0862/1766] clarify. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@443 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index 79f52a4a54..b0119ef68c 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -208,9 +208,10 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) /***************************************************************************** *****************************************************************************/ +static L3INT crv={1}; + L3INT Q931GetUniqueCRV(Q931_TrunkInfo_t *pTrunk) { - static L3INT crv={1}; crv++; if (crv > 32766) crv = 1; return crv; From c252ac86ffbe44da58a59bba91f125640715ba3a Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Sun, 6 Apr 2008 01:48:14 +0000 Subject: [PATCH 0863/1766] Inital m3ua config file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@444 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/m3ua.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 libs/openzap/conf/m3ua.conf diff --git a/libs/openzap/conf/m3ua.conf b/libs/openzap/conf/m3ua.conf new file mode 100644 index 0000000000..792d600548 --- /dev/null +++ b/libs/openzap/conf/m3ua.conf @@ -0,0 +1 @@ +# From dbb029d6f2bc6218b11368490e11199ab16c7c9c Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Sun, 6 Apr 2008 01:48:14 +0000 Subject: [PATCH 0864/1766] Inital m3ua config file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@444 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/m3ua.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 libs/freetdm/conf/m3ua.conf diff --git a/libs/freetdm/conf/m3ua.conf b/libs/freetdm/conf/m3ua.conf new file mode 100644 index 0000000000..792d600548 --- /dev/null +++ b/libs/freetdm/conf/m3ua.conf @@ -0,0 +1 @@ +# From 985de885ae00d5012c85f667f9f1f4ea928d745b Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 02:59:03 +0000 Subject: [PATCH 0865/1766] Intial work on m3ua agent git-svn-id: http://svn.openzap.org/svn/openzap/trunk@445 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua_client.c | 332 +++++++++++++++++++++++++++++++++ libs/openzap/src/m3ua_client.h | 120 ++++++++++++ 2 files changed, 452 insertions(+) create mode 100644 libs/openzap/src/m3ua_client.c create mode 100644 libs/openzap/src/m3ua_client.h diff --git a/libs/openzap/src/m3ua_client.c b/libs/openzap/src/m3ua_client.c new file mode 100644 index 0000000000..aaeb5ae9e0 --- /dev/null +++ b/libs/openzap/src/m3ua_client.c @@ -0,0 +1,332 @@ +/* + * m3ua_client.c + * openzap + * + * Created by Shane Burrell on 4/3/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. + */ + +#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[] = { + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, + {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, + {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, + {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, + {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, + {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, + {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, + {SIGBOOST_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 = 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 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 expandtab: + */ + + diff --git a/libs/openzap/src/m3ua_client.h b/libs/openzap/src/m3ua_client.h new file mode 100644 index 0000000000..e75a6dcee2 --- /dev/null +++ b/libs/openzap/src/m3ua_client.h @@ -0,0 +1,120 @@ +/* + * m3ua_client.h + * openzap + * + * Created by Shane Burrell on 4/3/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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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) +} ss7bc_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 *ss7bc_connection_read(m3uac_connection_t *mcon, int iteration); +m3uac_event_t *ss7bc_connection_readp(m3uac_connection_t *mcon, int iteration); +int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_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); + +#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 expandtab: + */ From 301723183b9a4a9931784df3078d66ace4b1c3ab Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 02:59:03 +0000 Subject: [PATCH 0866/1766] Intial work on m3ua agent git-svn-id: http://svn.openzap.org/svn/openzap/trunk@445 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua_client.c | 332 +++++++++++++++++++++++++++++++++ libs/freetdm/src/m3ua_client.h | 120 ++++++++++++ 2 files changed, 452 insertions(+) create mode 100644 libs/freetdm/src/m3ua_client.c create mode 100644 libs/freetdm/src/m3ua_client.h diff --git a/libs/freetdm/src/m3ua_client.c b/libs/freetdm/src/m3ua_client.c new file mode 100644 index 0000000000..aaeb5ae9e0 --- /dev/null +++ b/libs/freetdm/src/m3ua_client.c @@ -0,0 +1,332 @@ +/* + * m3ua_client.c + * openzap + * + * Created by Shane Burrell on 4/3/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. + */ + +#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[] = { + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, + {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, + {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, + {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, + {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, + {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, + {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, + {SIGBOOST_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 = 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 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 expandtab: + */ + + diff --git a/libs/freetdm/src/m3ua_client.h b/libs/freetdm/src/m3ua_client.h new file mode 100644 index 0000000000..e75a6dcee2 --- /dev/null +++ b/libs/freetdm/src/m3ua_client.h @@ -0,0 +1,120 @@ +/* + * m3ua_client.h + * openzap + * + * Created by Shane Burrell on 4/3/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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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) +} ss7bc_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 *ss7bc_connection_read(m3uac_connection_t *mcon, int iteration); +m3uac_event_t *ss7bc_connection_readp(m3uac_connection_t *mcon, int iteration); +int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_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); + +#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 expandtab: + */ From d2b316a91b6d298a84bf69723940e0af031b8237 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 03:01:26 +0000 Subject: [PATCH 0867/1766] Small change git-svn-id: http://svn.openzap.org/svn/openzap/trunk@446 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua/mstm3ua.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/m3ua/mstm3ua.h b/libs/openzap/src/m3ua/mstm3ua.h index 9bec483bda..0517661288 100644 --- a/libs/openzap/src/m3ua/mstm3ua.h +++ b/libs/openzap/src/m3ua/mstm3ua.h @@ -97,6 +97,6 @@ typedef unsigned long u32; #define M_CLASS_MASK 0xff00 #define M_TYPE_MASK 0x00ff - - +int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len); +int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg); #endif From df4fe26e6e10432fee69c468a5309b7a91bcb94f Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 03:01:26 +0000 Subject: [PATCH 0868/1766] Small change git-svn-id: http://svn.openzap.org/svn/openzap/trunk@446 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua/mstm3ua.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/m3ua/mstm3ua.h b/libs/freetdm/src/m3ua/mstm3ua.h index 9bec483bda..0517661288 100644 --- a/libs/freetdm/src/m3ua/mstm3ua.h +++ b/libs/freetdm/src/m3ua/mstm3ua.h @@ -97,6 +97,6 @@ typedef unsigned long u32; #define M_CLASS_MASK 0xff00 #define M_TYPE_MASK 0x00ff - - +int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len); +int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg); #endif From 6abea14ca686f15c0cebc40a0d9d1f20077efe5d Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 03:02:23 +0000 Subject: [PATCH 0869/1766] Added some m3ua params git-svn-id: http://svn.openzap.org/svn/openzap/trunk@447 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/m3ua.conf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/openzap/conf/m3ua.conf b/libs/openzap/conf/m3ua.conf index 792d600548..0444b49e0c 100644 --- a/libs/openzap/conf/m3ua.conf +++ b/libs/openzap/conf/m3ua.conf @@ -1 +1,9 @@ -# +;M3UA SS7 Links Config +; +;ss7box-m3ua_mode => true +;local_sctp_ip => localhost +;local sctp_port => 30000 +;remote_sctp_ip => localhost +;remote_sctp_port => 30001 +;opc => 0-0-0 +;dpc => 0-0-0 From 41d67eedab0b3b1af152c7a33e3e8b5587c14fc9 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 03:02:23 +0000 Subject: [PATCH 0870/1766] Added some m3ua params git-svn-id: http://svn.openzap.org/svn/openzap/trunk@447 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/m3ua.conf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/conf/m3ua.conf b/libs/freetdm/conf/m3ua.conf index 792d600548..0444b49e0c 100644 --- a/libs/freetdm/conf/m3ua.conf +++ b/libs/freetdm/conf/m3ua.conf @@ -1 +1,9 @@ -# +;M3UA SS7 Links Config +; +;ss7box-m3ua_mode => true +;local_sctp_ip => localhost +;local sctp_port => 30000 +;remote_sctp_ip => localhost +;remote_sctp_port => 30001 +;opc => 0-0-0 +;dpc => 0-0-0 From ffb15e0cbb7bcc6451618293d33fd913280ff213 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 05:03:10 +0000 Subject: [PATCH 0871/1766] sctplib changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@448 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 +- libs/openzap/src/m3ua_client.h | 60 +++++++++++++++++++++++----- libs/openzap/src/zap_m3ua.c | 2 +- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 40fd649ad2..b515a1f00d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -164,7 +164,8 @@ typedef enum { ZAP_SIGTYPE_ISDN, ZAP_SIGTYPE_RBS, ZAP_SIGTYPE_ANALOG, - ZAP_SIGTYPE_SS7BOOST + ZAP_SIGTYPE_SS7BOOST, + ZAP_SIGTYPE_M3UA } zap_signal_type_t; typedef enum { diff --git a/libs/openzap/src/m3ua_client.h b/libs/openzap/src/m3ua_client.h index e75a6dcee2..d7eb286029 100644 --- a/libs/openzap/src/m3ua_client.h +++ b/libs/openzap/src/m3ua_client.h @@ -46,16 +46,58 @@ #include #include #include -#include +#include +//#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]; @@ -85,27 +127,27 @@ struct m3uac_connection { typedef enum { MSU_FLAG_EVENT = (1 << 0) -} ss7bc_flag_t; +} 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 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 *ss7bc_connection_read(m3uac_connection_t *mcon, int iteration); -m3uac_event_t *ss7bc_connection_readp(m3uac_connection_t *mcon, int iteration); -int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event); +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); -#endif + /* For Emacs: diff --git a/libs/openzap/src/zap_m3ua.c b/libs/openzap/src/zap_m3ua.c index dcd5aab584..bd35703ff9 100644 --- a/libs/openzap/src/zap_m3ua.c +++ b/libs/openzap/src/zap_m3ua.c @@ -38,7 +38,7 @@ #include "openzap.h" -//#include "m3ua_client.h" +#include "m3ua_client.h" #include "zap_m3ua.h" struct general_config { From 7f3c466cc9f9f862f362a66f7ddfc9539bf61554 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 05:03:10 +0000 Subject: [PATCH 0872/1766] sctplib changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@448 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 3 +- libs/freetdm/src/m3ua_client.h | 60 +++++++++++++++++++++++----- libs/freetdm/src/zap_m3ua.c | 2 +- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 40fd649ad2..b515a1f00d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -164,7 +164,8 @@ typedef enum { ZAP_SIGTYPE_ISDN, ZAP_SIGTYPE_RBS, ZAP_SIGTYPE_ANALOG, - ZAP_SIGTYPE_SS7BOOST + ZAP_SIGTYPE_SS7BOOST, + ZAP_SIGTYPE_M3UA } zap_signal_type_t; typedef enum { diff --git a/libs/freetdm/src/m3ua_client.h b/libs/freetdm/src/m3ua_client.h index e75a6dcee2..d7eb286029 100644 --- a/libs/freetdm/src/m3ua_client.h +++ b/libs/freetdm/src/m3ua_client.h @@ -46,16 +46,58 @@ #include #include #include -#include +#include +//#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]; @@ -85,27 +127,27 @@ struct m3uac_connection { typedef enum { MSU_FLAG_EVENT = (1 << 0) -} ss7bc_flag_t; +} 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 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 *ss7bc_connection_read(m3uac_connection_t *mcon, int iteration); -m3uac_event_t *ss7bc_connection_readp(m3uac_connection_t *mcon, int iteration); -int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event); +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); -#endif + /* For Emacs: diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index dcd5aab584..bd35703ff9 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -38,7 +38,7 @@ #include "openzap.h" -//#include "m3ua_client.h" +#include "m3ua_client.h" #include "zap_m3ua.h" struct general_config { From 36f5e577276a9736dc8288bb408776c032e01cf2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Apr 2008 05:38:37 +0000 Subject: [PATCH 0873/1766] whoops (MODENDP-103) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@449 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 63a8d4782a..08ab6fe6f1 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -223,13 +223,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - zchan = NULL; 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; } } From f6a44786c72830cf057bd6cfb0c64d1f26058376 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Apr 2008 05:38:37 +0000 Subject: [PATCH 0874/1766] whoops (MODENDP-103) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@449 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 63a8d4782a..08ab6fe6f1 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -223,13 +223,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - zchan = NULL; 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; } } From 80832799034b822dbc8547039d8f222d97b45b02 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Apr 2008 06:01:27 +0000 Subject: [PATCH 0875/1766] whoops (MODENDP-103) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@450 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 08ab6fe6f1..a235638542 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -233,7 +233,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + 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)); From a016e07dbd9132dd59bb1082771097699900c5da Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Apr 2008 06:01:27 +0000 Subject: [PATCH 0876/1766] whoops (MODENDP-103) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@450 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 08ab6fe6f1..a235638542 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -233,7 +233,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { + 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)); From 62867815cdc6015d6a9ea5731d8d06e79731e46b Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 17:38:39 +0000 Subject: [PATCH 0877/1766] Put enough in conf file to do testing of m3ua git-svn-id: http://svn.openzap.org/svn/openzap/trunk@451 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/m3ua.conf | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/openzap/conf/m3ua.conf b/libs/openzap/conf/m3ua.conf index 0444b49e0c..e3eeed3a4a 100644 --- a/libs/openzap/conf/m3ua.conf +++ b/libs/openzap/conf/m3ua.conf @@ -7,3 +7,32 @@ ;remote_sctp_port => 30001 ;opc => 0-0-0 ;dpc => 0-0-0 + + +; AP Specific Stuff. This will likely move later. + +; CNAM Gateways +cnam1_dpc => 0-0-0 +cnam1_ssn => 253 +cnam2_dpc => 0-0-0 +cnam2_ssn => 253 +cnam3_dpc => 0-0-0 +cnam3_ssn => 253 + +;LNP Gateways +lnp1_dpc => 0-0-0 +lnp1_ssn => 253 +lnp2_dpc => 0-0-0 +lnp2_ssn => 253 +lnp3_dpc => 0-0-0 +lnp3_ssn => 253 + +;LNP Gateways +sms8001_dpc => 0-0-0 +sms8001_ssn => 253 +sms8002_dpc => 0-0-0 +sms8002_ssn => 253 +sms8003_dpc => 0-0-0 +sms8003_ssn => 253 + + From d0c1abd7f0e19550ed5fcd6541d8318265428c50 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Mon, 7 Apr 2008 17:38:39 +0000 Subject: [PATCH 0878/1766] Put enough in conf file to do testing of m3ua git-svn-id: http://svn.openzap.org/svn/openzap/trunk@451 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/m3ua.conf | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/freetdm/conf/m3ua.conf b/libs/freetdm/conf/m3ua.conf index 0444b49e0c..e3eeed3a4a 100644 --- a/libs/freetdm/conf/m3ua.conf +++ b/libs/freetdm/conf/m3ua.conf @@ -7,3 +7,32 @@ ;remote_sctp_port => 30001 ;opc => 0-0-0 ;dpc => 0-0-0 + + +; AP Specific Stuff. This will likely move later. + +; CNAM Gateways +cnam1_dpc => 0-0-0 +cnam1_ssn => 253 +cnam2_dpc => 0-0-0 +cnam2_ssn => 253 +cnam3_dpc => 0-0-0 +cnam3_ssn => 253 + +;LNP Gateways +lnp1_dpc => 0-0-0 +lnp1_ssn => 253 +lnp2_dpc => 0-0-0 +lnp2_ssn => 253 +lnp3_dpc => 0-0-0 +lnp3_ssn => 253 + +;LNP Gateways +sms8001_dpc => 0-0-0 +sms8001_ssn => 253 +sms8002_dpc => 0-0-0 +sms8002_ssn => 253 +sms8003_dpc => 0-0-0 +sms8003_ssn => 253 + + From 70b0c19b7af849d6f95a3c1d82779ddf6159aef2 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Tue, 8 Apr 2008 01:01:09 +0000 Subject: [PATCH 0879/1766] zap run additions. Almost ppl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@452 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_m3ua.c | 438 +++++++++++++++++++++++++++++++++++- 1 file changed, 437 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_m3ua.c b/libs/openzap/src/zap_m3ua.c index bd35703ff9..0e02a4ae7f 100644 --- a/libs/openzap/src/zap_m3ua.c +++ b/libs/openzap/src/zap_m3ua.c @@ -41,6 +41,24 @@ #include "m3ua_client.h" #include "zap_m3ua.h" +#define MAX_REQ_ID MAX_PENDING_CALLS +typedef uint16_t m3ua_request_id_t; + +typedef enum { + BST_FREE, + BST_WAITING, + BST_READY, + BST_FAIL +} m3ua_request_status_t; + +typedef struct { + m3ua_request_status_t status; + m3uac_event_t event; + zap_span_t *span; + zap_channel_t *zchan; +} m3ua_request_t; + + struct general_config { uint32_t region; }; @@ -50,6 +68,13 @@ typedef struct general_config general_config_t; struct m3ua_channel_profile { char name[80]; int cust_span; + unsigned char opc[3]; + unsigned char dpc[3]; + int local_ip[4]; + int local_port; + int remote_ip[4]; + int remote_port; + int m3ua_mode; }; typedef struct m3ua_channel_profile m3ua_channel_profile_t; @@ -73,10 +98,298 @@ struct m3ua_chan_data { }; typedef struct m3ua_chan_data m3ua_chan_data_t; +static zap_mutex_t *request_mutex = NULL; +static zap_mutex_t *signal_mutex = NULL; + +static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; + +static void release_request_id(m3ua_request_id_t r) +{ + zap_mutex_lock(request_mutex); + req_map[r] = 0; + zap_mutex_unlock(request_mutex); +} + +/*static m3ua_request_id_t next_request_id(void) +{ + m3ua_request_id_t r = 0; + int ok = 0; + + while(!ok) { + zap_mutex_lock(request_mutex); + for (r = 1; r <= MAX_REQ_ID; r++) { + if (!req_map[r]) { + ok = 1; + req_map[r] = 1; + break; + } + } + zap_mutex_unlock(request_mutex); + if (!ok) { + zap_sleep(5); + } + } + return r; +} +*/ + +static __inline__ void state_advance(zap_channel_t *zchan) +{ + + m3ua_data_t *m3ua_data = zchan->span->signal_data; + m3uac_connection_t *mcon = &m3ua_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->extra_id) { + release_request_id((m3ua_request_id_t)zchan->extra_id); + zchan->extra_id = 0; + } + zap_channel_done(zchan); + } + break; + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case ZAP_CHANNEL_STATE_PROGRESS: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; + if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + } + } + break; + case ZAP_CHANNEL_STATE_RING: + { + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + + } + break; + case ZAP_CHANNEL_STATE_RESTART: + { + if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } else { + 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 = m3ua_data->signal_cb(&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))) { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + } + + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_ANSWERED, + 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: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + zchan->caller_data.hangup_cause); + } else { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + zchan->caller_data.hangup_cause); + } + } + break; + case ZAP_CHANNEL_STATE_CANCEL: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = m3ua_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + } + break; + case ZAP_CHANNEL_STATE_TERMINATING: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = m3ua_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } + break; + default: + break; + } +} +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_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); + } + } + } +} +static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_event_t *event) +{ + zap_mutex_lock(signal_mutex); + + if (!zap_running()) { + zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); + goto end; + } + + + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { + + zap_log(ZAP_LOG_WARNING, + "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + m3uac_event_id_name(event->event_id), + event->event_id, + 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") + ); + + goto end; + } + + + zap_log(ZAP_LOG_DEBUG, + "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + m3uac_event_id_name(event->event_id), + event->event_id, + 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") + ); + + + + switch(event->event_id) { + + case SIGBOOST_EVENT_CALL_START: + //handle_call_start(span, mcon, 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_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: + case SIGBOOST_EVENT_CALL_START_NACK_ACK: + //handle_call_done(span, mcon, event); + break; + case SIGBOOST_EVENT_INSERT_CHECK_LOOP: + //handle_call_loop_start(event); + break; + case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: + //handle_call_stop(event); + break; + case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: + //handle_restart_ack(mcon, span, event); + break; + case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE: + //handle_gap_abate(event); + break; + default: + zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", m3uac_event_id_name(event->event_id)); + break; + } + + end: + + zap_mutex_unlock(signal_mutex); + + return 0; +} static ZIO_CONFIGURE_FUNCTION(m3ua_configure) { @@ -87,7 +400,6 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) profile = malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); - //profile->play_config = globals.play_config; hashtable_insert(globals.profile_hash, (void *)profile->name, profile); zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } @@ -243,6 +555,130 @@ zap_status_t m3ua_destroy(void) return ZAP_FAIL; } + +static void *m3ua_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + m3ua_data_t *m3ua_data = span->signal_data; + m3uac_connection_t *mcon, *pcon; + uint32_t ms = 10, too_long = 60000; + + + m3ua_data->pcon = m3ua_data->mcon; + + if (m3uac_connection_open(&m3ua_data->mcon, + m3ua_data->mcon.cfg.local_ip, + m3ua_data->mcon.cfg.local_port, + m3ua_data->mcon.cfg.remote_ip, + m3ua_data->mcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", m3ua_data->mcon.socket, strerror(errno)); + goto end; + } + + if (m3uac_connection_open(&m3ua_data->pcon, + m3ua_data->pcon.cfg.local_ip, + ++m3ua_data->pcon.cfg.local_port, + m3ua_data->pcon.cfg.remote_ip, + m3ua_data->pcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", m3ua_data->pcon.socket, strerror(errno)); + goto end; + } + + mcon = &m3ua_data->mcon; + pcon = &m3ua_data->pcon; + + top: + + //init_outgoing_array(); + + m3uac_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + + while (zap_test_flag(m3ua_data, ZAP_M3UA_RUNNING)) { + fd_set rfds, efds; + struct timeval tv = { 0, ms * 1000 }; + int max, activity, i = 0; + m3uac_event_t *event = NULL; + + if (!zap_running()) { + m3uac_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + 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; + + 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)) { + if ((event = m3uac_connection_readp(pcon, i))) { + parse_ss7_event(span, mcon, event); + } else goto top; + } + + if (FD_ISSET(mcon->socket, &rfds)) { + if ((event = m3uac_connection_read(mcon, i))) { + parse_ss7_event(span, mcon, event); + } else goto top; + } + } + + check_state(span); + mcon->hb_elapsed += ms; + + if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + mcon->up = 0; + zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); + } + + } + + goto end; + + error: + zap_log(ZAP_LOG_CRIT, "Socket Error!\n"); + + end: + + m3uac_connection_close(&m3ua_data->mcon); + m3uac_connection_close(&m3ua_data->pcon); + + zap_clear_flag(m3ua_data, ZAP_M3UA_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "M3UA thread ended.\n"); + return NULL; +} +zap_status_t m3ua_start(zap_span_t *span) +{ + m3ua_data_t *m3ua_data = span->signal_data; + zap_set_flag(m3ua_data, ZAP_M3UA_RUNNING); + return zap_thread_create_detached(m3ua_run, span); +} + /* For Emacs: * Local Variables: * mode:c From 570ff2b3c24f2672a353da59f07a19aaec953ba1 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Tue, 8 Apr 2008 01:01:09 +0000 Subject: [PATCH 0880/1766] zap run additions. Almost ppl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@452 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_m3ua.c | 438 +++++++++++++++++++++++++++++++++++- 1 file changed, 437 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index bd35703ff9..0e02a4ae7f 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -41,6 +41,24 @@ #include "m3ua_client.h" #include "zap_m3ua.h" +#define MAX_REQ_ID MAX_PENDING_CALLS +typedef uint16_t m3ua_request_id_t; + +typedef enum { + BST_FREE, + BST_WAITING, + BST_READY, + BST_FAIL +} m3ua_request_status_t; + +typedef struct { + m3ua_request_status_t status; + m3uac_event_t event; + zap_span_t *span; + zap_channel_t *zchan; +} m3ua_request_t; + + struct general_config { uint32_t region; }; @@ -50,6 +68,13 @@ typedef struct general_config general_config_t; struct m3ua_channel_profile { char name[80]; int cust_span; + unsigned char opc[3]; + unsigned char dpc[3]; + int local_ip[4]; + int local_port; + int remote_ip[4]; + int remote_port; + int m3ua_mode; }; typedef struct m3ua_channel_profile m3ua_channel_profile_t; @@ -73,10 +98,298 @@ struct m3ua_chan_data { }; typedef struct m3ua_chan_data m3ua_chan_data_t; +static zap_mutex_t *request_mutex = NULL; +static zap_mutex_t *signal_mutex = NULL; + +static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; + +static void release_request_id(m3ua_request_id_t r) +{ + zap_mutex_lock(request_mutex); + req_map[r] = 0; + zap_mutex_unlock(request_mutex); +} + +/*static m3ua_request_id_t next_request_id(void) +{ + m3ua_request_id_t r = 0; + int ok = 0; + + while(!ok) { + zap_mutex_lock(request_mutex); + for (r = 1; r <= MAX_REQ_ID; r++) { + if (!req_map[r]) { + ok = 1; + req_map[r] = 1; + break; + } + } + zap_mutex_unlock(request_mutex); + if (!ok) { + zap_sleep(5); + } + } + return r; +} +*/ + +static __inline__ void state_advance(zap_channel_t *zchan) +{ + + m3ua_data_t *m3ua_data = zchan->span->signal_data; + m3uac_connection_t *mcon = &m3ua_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->extra_id) { + release_request_id((m3ua_request_id_t)zchan->extra_id); + zchan->extra_id = 0; + } + zap_channel_done(zchan); + } + break; + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case ZAP_CHANNEL_STATE_PROGRESS: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; + if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } else { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + } + } + break; + case ZAP_CHANNEL_STATE_RING: + { + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + sig.event_id = ZAP_SIGEVENT_START; + if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } + } + + } + break; + case ZAP_CHANNEL_STATE_RESTART: + { + if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + } else { + 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 = m3ua_data->signal_cb(&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))) { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0); + } + + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_ANSWERED, + 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: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + zchan->caller_data.hangup_cause); + } else { + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + zchan->caller_data.hangup_cause); + } + } + break; + case ZAP_CHANNEL_STATE_CANCEL: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = m3ua_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + } + break; + case ZAP_CHANNEL_STATE_TERMINATING: + { + sig.event_id = ZAP_SIGEVENT_STOP; + status = m3ua_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + m3uac_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } + break; + default: + break; + } +} +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_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + state_advance(&span->channels[j]); + zap_channel_complete_state(&span->channels[j]); + } + } + } +} +static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_event_t *event) +{ + zap_mutex_lock(signal_mutex); + + if (!zap_running()) { + zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); + goto end; + } + + + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { + + zap_log(ZAP_LOG_WARNING, + "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + m3uac_event_id_name(event->event_id), + event->event_id, + 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") + ); + + goto end; + } + + + zap_log(ZAP_LOG_DEBUG, + "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + m3uac_event_id_name(event->event_id), + event->event_id, + 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") + ); + + + + switch(event->event_id) { + + case SIGBOOST_EVENT_CALL_START: + //handle_call_start(span, mcon, 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_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: + case SIGBOOST_EVENT_CALL_START_NACK_ACK: + //handle_call_done(span, mcon, event); + break; + case SIGBOOST_EVENT_INSERT_CHECK_LOOP: + //handle_call_loop_start(event); + break; + case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: + //handle_call_stop(event); + break; + case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: + //handle_restart_ack(mcon, span, event); + break; + case SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE: + //handle_gap_abate(event); + break; + default: + zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", m3uac_event_id_name(event->event_id)); + break; + } + + end: + + zap_mutex_unlock(signal_mutex); + + return 0; +} static ZIO_CONFIGURE_FUNCTION(m3ua_configure) { @@ -87,7 +400,6 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) profile = malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); - //profile->play_config = globals.play_config; hashtable_insert(globals.profile_hash, (void *)profile->name, profile); zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } @@ -243,6 +555,130 @@ zap_status_t m3ua_destroy(void) return ZAP_FAIL; } + +static void *m3ua_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + m3ua_data_t *m3ua_data = span->signal_data; + m3uac_connection_t *mcon, *pcon; + uint32_t ms = 10, too_long = 60000; + + + m3ua_data->pcon = m3ua_data->mcon; + + if (m3uac_connection_open(&m3ua_data->mcon, + m3ua_data->mcon.cfg.local_ip, + m3ua_data->mcon.cfg.local_port, + m3ua_data->mcon.cfg.remote_ip, + m3ua_data->mcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", m3ua_data->mcon.socket, strerror(errno)); + goto end; + } + + if (m3uac_connection_open(&m3ua_data->pcon, + m3ua_data->pcon.cfg.local_ip, + ++m3ua_data->pcon.cfg.local_port, + m3ua_data->pcon.cfg.remote_ip, + m3ua_data->pcon.cfg.remote_port) < 0) { + zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", m3ua_data->pcon.socket, strerror(errno)); + goto end; + } + + mcon = &m3ua_data->mcon; + pcon = &m3ua_data->pcon; + + top: + + //init_outgoing_array(); + + m3uac_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + + while (zap_test_flag(m3ua_data, ZAP_M3UA_RUNNING)) { + fd_set rfds, efds; + struct timeval tv = { 0, ms * 1000 }; + int max, activity, i = 0; + m3uac_event_t *event = NULL; + + if (!zap_running()) { + m3uac_exec_command(mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + 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; + + 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)) { + if ((event = m3uac_connection_readp(pcon, i))) { + parse_ss7_event(span, mcon, event); + } else goto top; + } + + if (FD_ISSET(mcon->socket, &rfds)) { + if ((event = m3uac_connection_read(mcon, i))) { + parse_ss7_event(span, mcon, event); + } else goto top; + } + } + + check_state(span); + mcon->hb_elapsed += ms; + + if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + mcon->up = 0; + zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); + } + + } + + goto end; + + error: + zap_log(ZAP_LOG_CRIT, "Socket Error!\n"); + + end: + + m3uac_connection_close(&m3ua_data->mcon); + m3uac_connection_close(&m3ua_data->pcon); + + zap_clear_flag(m3ua_data, ZAP_M3UA_RUNNING); + + zap_log(ZAP_LOG_DEBUG, "M3UA thread ended.\n"); + return NULL; +} +zap_status_t m3ua_start(zap_span_t *span) +{ + m3ua_data_t *m3ua_data = span->signal_data; + zap_set_flag(m3ua_data, ZAP_M3UA_RUNNING); + return zap_thread_create_detached(m3ua_run, span); +} + /* For Emacs: * Local Variables: * mode:c From 3050d2f9529cad3da14c894cd989c0edb9a9614f Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Tue, 8 Apr 2008 01:01:20 +0000 Subject: [PATCH 0881/1766] zap run additions. Almost ppl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@453 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua_client.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libs/openzap/src/m3ua_client.c b/libs/openzap/src/m3ua_client.c index aaeb5ae9e0..7a37bd0f93 100644 --- a/libs/openzap/src/m3ua_client.c +++ b/libs/openzap/src/m3ua_client.c @@ -57,18 +57,18 @@ struct m3uac_map { }; static struct m3uac_map m3uac_table[] = { - {SIGBOOST_EVENT_CALL_START, "CALL_START"}, - {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, - {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, - {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, - {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, - {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, - {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, - {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, - {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, - {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, - {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, - {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"} + {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"} }; @@ -279,7 +279,7 @@ int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event) 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 = SIGBOOST_EVENT_CALL_START; + event->event_id = M3UA_EVENT_CALL_START; if (calling) { strncpy((char*)event->calling_number_digits, calling, sizeof(event->calling_number_digits)-1); From 191ca19871f62380b65f04e80a0add90f5b405bf Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Tue, 8 Apr 2008 01:01:20 +0000 Subject: [PATCH 0882/1766] zap run additions. Almost ppl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@453 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua_client.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/src/m3ua_client.c b/libs/freetdm/src/m3ua_client.c index aaeb5ae9e0..7a37bd0f93 100644 --- a/libs/freetdm/src/m3ua_client.c +++ b/libs/freetdm/src/m3ua_client.c @@ -57,18 +57,18 @@ struct m3uac_map { }; static struct m3uac_map m3uac_table[] = { - {SIGBOOST_EVENT_CALL_START, "CALL_START"}, - {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, - {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, - {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, - {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, - {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, - {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, - {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, - {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, - {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, - {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, - {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"} + {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"} }; @@ -279,7 +279,7 @@ int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event) 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 = SIGBOOST_EVENT_CALL_START; + event->event_id = M3UA_EVENT_CALL_START; if (calling) { strncpy((char*)event->calling_number_digits, calling, sizeof(event->calling_number_digits)-1); From 3d88101812245f1d90e0d32a071dc6f559a4121c Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Tue, 8 Apr 2008 01:01:30 +0000 Subject: [PATCH 0883/1766] zap run additions. Almost ppl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@454 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_m3ua.h | 50 +++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_m3ua.h b/libs/openzap/src/include/zap_m3ua.h index 8819d37252..8dda119361 100644 --- a/libs/openzap/src/include/zap_m3ua.h +++ b/libs/openzap/src/include/zap_m3ua.h @@ -39,7 +39,46 @@ //#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, @@ -54,6 +93,14 @@ 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; @@ -64,8 +111,7 @@ typedef enum { 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); From fa2ef583f8beabe621483c41a204f2cf7ad341f9 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Tue, 8 Apr 2008 01:01:30 +0000 Subject: [PATCH 0884/1766] zap run additions. Almost ppl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@454 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_m3ua.h | 50 +++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_m3ua.h b/libs/freetdm/src/include/zap_m3ua.h index 8819d37252..8dda119361 100644 --- a/libs/freetdm/src/include/zap_m3ua.h +++ b/libs/freetdm/src/include/zap_m3ua.h @@ -39,7 +39,46 @@ //#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, @@ -54,6 +93,14 @@ 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; @@ -64,8 +111,7 @@ typedef enum { 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); From 0165695f5d98f86b5fe78353acb151ffc46a062b Mon Sep 17 00:00:00 2001 From: Ken Rice Date: Fri, 11 Apr 2008 17:11:44 +0000 Subject: [PATCH 0885/1766] Test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@456 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ss7/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ss7/README b/libs/openzap/src/ss7/README index f4f786855c..0efe94c94a 100644 --- a/libs/openzap/src/ss7/README +++ b/libs/openzap/src/ss7/README @@ -1,3 +1,3 @@ SS7 Coming soon -Shane Burrell +-Shane Burrell- From 99a1776aff226f983138a6cd1c9d7f326cf78afa Mon Sep 17 00:00:00 2001 From: Ken Rice Date: Fri, 11 Apr 2008 17:11:44 +0000 Subject: [PATCH 0886/1766] Test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@456 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ss7/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ss7/README b/libs/freetdm/src/ss7/README index f4f786855c..0efe94c94a 100644 --- a/libs/freetdm/src/ss7/README +++ b/libs/freetdm/src/ss7/README @@ -1,3 +1,3 @@ SS7 Coming soon -Shane Burrell +-Shane Burrell- From f28650f7a38e91bd651964aa108254065bacacc4 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:42:24 +0000 Subject: [PATCH 0887/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@457 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua/mstm3ua.c | 41 ++++++++------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/libs/openzap/src/m3ua/mstm3ua.c b/libs/openzap/src/m3ua/mstm3ua.c index d5a415b061..1d8179c58d 100644 --- a/libs/openzap/src/m3ua/mstm3ua.c +++ b/libs/openzap/src/m3ua/mstm3ua.c @@ -37,49 +37,26 @@ #include "mstm3ua.h" -int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len) -{ -//Routing Context - bytemsg[8] = 0x10; //Tag 0x210 Protocol Data - bytemsg[9] = 0x02; - - bytemsg[10] = len; //Len - bytemsg[11] = 0x00; - - - bytemsg[12] = opc[2]; //OPC Member - bytemsg[13] = opc[1]; //OPC Cluster - bytemsg[14] = opc[0]; //OPC Network - - bytemsg[15] = 0x00; - - bytemsg[16] = dpc[2];//DPC Member - bytemsg[17] = dpc[1];//DPC Cluster - bytemsg[18] = dpc[0];//DPC Network - - bytemsg[19] = 0x00; - return 0; -} int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg) { - - bytemsg[0] = M_VERSION_REL1; // 1 Verison + + *bytemsg++ = M_VERSION_REL1; // 1 Verison //bytemsg[1] = 0x00; // 2 RESERVED //bytemsg[2] = M_CLASS_XFER; // 3 Msg Class //SS7 BOX Kludge - bytemsg[1] = 0x01; // 2 RESERVED - bytemsg[2] = 0x00; // 2 RESERVED + *bytemsg++ = 0x01; // 2 RESERVED + *bytemsg++ = 0x00; // 2 RESERVED - bytemsg[3] = M_TYPE_DATA ; // 4 Msg Type + *bytemsg++ = M_TYPE_DATA ; // 4 Msg Type - bytemsg[4] = len; // 5 Msg LENGTH 81 32bit field - bytemsg[5] = 0x00; // 6 - bytemsg[6] = 0x00; // 7 - bytemsg[7] = 0x00; // 8 + *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 From 231b7d7a58b2803573ce633ac0b0866aa4db2892 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:42:24 +0000 Subject: [PATCH 0888/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@457 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua/mstm3ua.c | 41 ++++++++------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/libs/freetdm/src/m3ua/mstm3ua.c b/libs/freetdm/src/m3ua/mstm3ua.c index d5a415b061..1d8179c58d 100644 --- a/libs/freetdm/src/m3ua/mstm3ua.c +++ b/libs/freetdm/src/m3ua/mstm3ua.c @@ -37,49 +37,26 @@ #include "mstm3ua.h" -int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len) -{ -//Routing Context - bytemsg[8] = 0x10; //Tag 0x210 Protocol Data - bytemsg[9] = 0x02; - - bytemsg[10] = len; //Len - bytemsg[11] = 0x00; - - - bytemsg[12] = opc[2]; //OPC Member - bytemsg[13] = opc[1]; //OPC Cluster - bytemsg[14] = opc[0]; //OPC Network - - bytemsg[15] = 0x00; - - bytemsg[16] = dpc[2];//DPC Member - bytemsg[17] = dpc[1];//DPC Cluster - bytemsg[18] = dpc[0];//DPC Network - - bytemsg[19] = 0x00; - return 0; -} int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg) { - - bytemsg[0] = M_VERSION_REL1; // 1 Verison + + *bytemsg++ = M_VERSION_REL1; // 1 Verison //bytemsg[1] = 0x00; // 2 RESERVED //bytemsg[2] = M_CLASS_XFER; // 3 Msg Class //SS7 BOX Kludge - bytemsg[1] = 0x01; // 2 RESERVED - bytemsg[2] = 0x00; // 2 RESERVED + *bytemsg++ = 0x01; // 2 RESERVED + *bytemsg++ = 0x00; // 2 RESERVED - bytemsg[3] = M_TYPE_DATA ; // 4 Msg Type + *bytemsg++ = M_TYPE_DATA ; // 4 Msg Type - bytemsg[4] = len; // 5 Msg LENGTH 81 32bit field - bytemsg[5] = 0x00; // 6 - bytemsg[6] = 0x00; // 7 - bytemsg[7] = 0x00; // 8 + *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 From b8695c5f5ee2e5fa280c80a9e75159b288dc578e Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:42:31 +0000 Subject: [PATCH 0889/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@458 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua/mstm3ua.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/m3ua/mstm3ua.h b/libs/openzap/src/m3ua/mstm3ua.h index 0517661288..13527dac35 100644 --- a/libs/openzap/src/m3ua/mstm3ua.h +++ b/libs/openzap/src/m3ua/mstm3ua.h @@ -1,10 +1,11 @@ - -/* mstm3ua.h +/* + * 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: @@ -33,10 +34,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef __SS7_M3UA_H__ -#define __SS7_M3UA_H__ - typedef unsigned long m3ua_ulong; typedef unsigned short m3ua_ushort; typedef unsigned char m3ua_uchar; @@ -97,6 +94,3 @@ typedef unsigned long u32; #define M_CLASS_MASK 0xff00 #define M_TYPE_MASK 0x00ff -int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len); -int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg); -#endif From d1e67eb08ab8b82d403da0d25012c33d6624a3e2 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:42:31 +0000 Subject: [PATCH 0890/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@458 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua/mstm3ua.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/m3ua/mstm3ua.h b/libs/freetdm/src/m3ua/mstm3ua.h index 0517661288..13527dac35 100644 --- a/libs/freetdm/src/m3ua/mstm3ua.h +++ b/libs/freetdm/src/m3ua/mstm3ua.h @@ -1,10 +1,11 @@ - -/* mstm3ua.h +/* + * 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: @@ -33,10 +34,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef __SS7_M3UA_H__ -#define __SS7_M3UA_H__ - typedef unsigned long m3ua_ulong; typedef unsigned short m3ua_ushort; typedef unsigned char m3ua_uchar; @@ -97,6 +94,3 @@ typedef unsigned long u32; #define M_CLASS_MASK 0xff00 #define M_TYPE_MASK 0x00ff -int build_route_context(unsigned char *opc, unsigned char *dpc, unsigned char *bytemsg, unsigned char len); -int build_m3ua_hdr(unsigned char len,unsigned char *bytemsg); -#endif From 30d355b76536af9afbecbf5af70a4e32fac5cd58 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:12 +0000 Subject: [PATCH 0891/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@459 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua_client.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/m3ua_client.h b/libs/openzap/src/m3ua_client.h index d7eb286029..29620e0302 100644 --- a/libs/openzap/src/m3ua_client.h +++ b/libs/openzap/src/m3ua_client.h @@ -5,7 +5,7 @@ * 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 @@ -46,6 +46,8 @@ #include #include #include + +// Fix this for portability #include //#include #include From 00e1a4eb63ed8a96d23d3245e879096017718c5c Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:12 +0000 Subject: [PATCH 0892/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@459 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua_client.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/m3ua_client.h b/libs/freetdm/src/m3ua_client.h index d7eb286029..29620e0302 100644 --- a/libs/freetdm/src/m3ua_client.h +++ b/libs/freetdm/src/m3ua_client.h @@ -5,7 +5,7 @@ * 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 @@ -46,6 +46,8 @@ #include #include #include + +// Fix this for portability #include //#include #include From ae139f5fc6e7abb07691c7443c148b112787c6b6 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:21 +0000 Subject: [PATCH 0893/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@460 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/m3ua_client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/m3ua_client.c b/libs/openzap/src/m3ua_client.c index 7a37bd0f93..05dfc49523 100644 --- a/libs/openzap/src/m3ua_client.c +++ b/libs/openzap/src/m3ua_client.c @@ -6,6 +6,7 @@ * 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: From 80f3bacfd8e61941eeacc0687546ed77c4b09547 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:21 +0000 Subject: [PATCH 0894/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@460 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/m3ua_client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/m3ua_client.c b/libs/freetdm/src/m3ua_client.c index 7a37bd0f93..05dfc49523 100644 --- a/libs/freetdm/src/m3ua_client.c +++ b/libs/freetdm/src/m3ua_client.c @@ -6,6 +6,7 @@ * 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: From cf065230986e3d9ad2879dadd916f8cd6c9d761a Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:36 +0000 Subject: [PATCH 0895/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@461 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_m3ua.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/include/zap_m3ua.h b/libs/openzap/src/include/zap_m3ua.h index 8dda119361..12e6c45582 100644 --- a/libs/openzap/src/include/zap_m3ua.h +++ b/libs/openzap/src/include/zap_m3ua.h @@ -5,7 +5,7 @@ * 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 @@ -93,14 +93,14 @@ typedef enum { ZAP_M3UA_RUNNING = (1 << 0) } zap_m3uat_flag_t; -typedef struct m3ua_data { +/*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; From b65e7946cc0b8dd232ac08d871a8d0430948e0f0 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:36 +0000 Subject: [PATCH 0896/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@461 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_m3ua.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/include/zap_m3ua.h b/libs/freetdm/src/include/zap_m3ua.h index 8dda119361..12e6c45582 100644 --- a/libs/freetdm/src/include/zap_m3ua.h +++ b/libs/freetdm/src/include/zap_m3ua.h @@ -5,7 +5,7 @@ * 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 @@ -93,14 +93,14 @@ typedef enum { ZAP_M3UA_RUNNING = (1 << 0) } zap_m3uat_flag_t; -typedef struct m3ua_data { +/*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; From fc18e69a6c26b00d7f2d900c621d4c1ba8aaf78a Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:51 +0000 Subject: [PATCH 0897/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@462 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_m3ua.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/zap_m3ua.c b/libs/openzap/src/zap_m3ua.c index 0e02a4ae7f..c54e533eab 100644 --- a/libs/openzap/src/zap_m3ua.c +++ b/libs/openzap/src/zap_m3ua.c @@ -5,8 +5,9 @@ * 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: @@ -394,6 +395,7 @@ static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_eve static ZIO_CONFIGURE_FUNCTION(m3ua_configure) { m3ua_channel_profile_t *profile = NULL; + int ok = 1; if (!(profile = (m3ua_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { @@ -404,12 +406,13 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } - - if (!strcasecmp(var, "local_ip")) { - //profile->span_config.framing = pika_str2span(val); +// zap_set_string(m3ua_data->mcon. cfg.local_ip, local_ip); + if (!strcasecmp(var, "local_sctp_port")) { + profile->local_port = 30000 ; + profile->remote_port = 30000; profile->cust_span++; } - ok = 0; + ok = 1; if (ok) { From d57d8ffc2f5d71d62f9548c86b1e184929529ef9 Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:43:51 +0000 Subject: [PATCH 0898/1766] Formatting git-svn-id: http://svn.openzap.org/svn/openzap/trunk@462 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_m3ua.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index 0e02a4ae7f..c54e533eab 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -5,8 +5,9 @@ * 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: @@ -394,6 +395,7 @@ static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_eve static ZIO_CONFIGURE_FUNCTION(m3ua_configure) { m3ua_channel_profile_t *profile = NULL; + int ok = 1; if (!(profile = (m3ua_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { @@ -404,12 +406,13 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } - - if (!strcasecmp(var, "local_ip")) { - //profile->span_config.framing = pika_str2span(val); +// zap_set_string(m3ua_data->mcon. cfg.local_ip, local_ip); + if (!strcasecmp(var, "local_sctp_port")) { + profile->local_port = 30000 ; + profile->remote_port = 30000; profile->cust_span++; } - ok = 0; + ok = 1; if (ok) { From 95e3cc2210c6b0c830fb03cfb7d167c10f811bad Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:59:59 +0000 Subject: [PATCH 0899/1766] testm3ua prototype git-svn-id: http://svn.openzap.org/svn/openzap/trunk@463 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testm3ua.c | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 libs/openzap/src/testm3ua.c diff --git a/libs/openzap/src/testm3ua.c b/libs/openzap/src/testm3ua.c new file mode 100644 index 0000000000..16377cd067 --- /dev/null +++ b/libs/openzap/src/testm3ua.c @@ -0,0 +1,60 @@ +/* + * 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(); + +} From b794a13ded5ce39e55017226f63d6005b82dfe4b Mon Sep 17 00:00:00 2001 From: Shane Burrell Date: Wed, 16 Apr 2008 22:59:59 +0000 Subject: [PATCH 0900/1766] testm3ua prototype git-svn-id: http://svn.openzap.org/svn/openzap/trunk@463 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testm3ua.c | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 libs/freetdm/src/testm3ua.c diff --git a/libs/freetdm/src/testm3ua.c b/libs/freetdm/src/testm3ua.c new file mode 100644 index 0000000000..16377cd067 --- /dev/null +++ b/libs/freetdm/src/testm3ua.c @@ -0,0 +1,60 @@ +/* + * 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(); + +} From 5c815447bfd421c39576a18368e263bcd3e3b383 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 Apr 2008 15:57:19 +0000 Subject: [PATCH 0901/1766] deal with untimely pri messages that mess up the state machine git-svn-id: http://svn.openzap.org/svn/openzap/trunk@464 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 ++- libs/openzap/src/zap_isdn.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index b515a1f00d..c0334bffd9 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -184,10 +184,11 @@ typedef enum { 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", "INVALID" + "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 { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index a235638542..2b7de4a180 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -150,10 +150,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RELEASE: case Q931mes_RELEASE_COMPLETE: { + const char *what = gen->MesType == Q931mes_RELEASE ? "Release" : "Release Complete"; if (zchan) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + if (zchan->state == ZAP_CHANNEL_STATE_TERMINATING || zchan->state == ZAP_CHANNEL_STATE_HANGUP) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_log(ZAP_LOG_DEBUG, "Ignoring %s on channel %d\n", what, chan_id); + } } else { - zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); + zap_log(ZAP_LOG_CRIT, "Received %s with no matching channel %d\n", what, chan_id); } } break; @@ -374,6 +379,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } else { + sig.event_id = ZAP_SIGEVENT_RESTART; + status = isdn_data->sig_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } From b518f8573d8801f06465fd9492e38aae1cd14641 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 Apr 2008 15:57:19 +0000 Subject: [PATCH 0902/1766] deal with untimely pri messages that mess up the state machine git-svn-id: http://svn.openzap.org/svn/openzap/trunk@464 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 3 ++- libs/freetdm/src/zap_isdn.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b515a1f00d..c0334bffd9 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -184,10 +184,11 @@ typedef enum { 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", "INVALID" + "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 { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index a235638542..2b7de4a180 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -150,10 +150,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RELEASE: case Q931mes_RELEASE_COMPLETE: { + const char *what = gen->MesType == Q931mes_RELEASE ? "Release" : "Release Complete"; if (zchan) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + if (zchan->state == ZAP_CHANNEL_STATE_TERMINATING || zchan->state == ZAP_CHANNEL_STATE_HANGUP) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } else { + zap_log(ZAP_LOG_DEBUG, "Ignoring %s on channel %d\n", what, chan_id); + } } else { - zap_log(ZAP_LOG_CRIT, "Received Release Complete with no matching channel %d\n", chan_id); + zap_log(ZAP_LOG_CRIT, "Received %s with no matching channel %d\n", what, chan_id); } } break; @@ -374,6 +379,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } else { + sig.event_id = ZAP_SIGEVENT_RESTART; + status = isdn_data->sig_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } From cd737a7ba3ea943a37787efa93725548415f8a1a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Apr 2008 15:17:55 +0000 Subject: [PATCH 0903/1766] fix some analog issues brought about by too much concentration on digital git-svn-id: http://svn.openzap.org/svn/openzap/trunk@465 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 12 ++++-------- libs/openzap/src/zap_analog.c | 6 ++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 23063c4325..4ad7659099 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Fri Jan 25 19:07:34 EST 2008 +Wed Apr 30 10:51:26 EDT 2008 diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index eade1be790..c9469dbb96 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -159,16 +159,15 @@ static void stop_hold(const char *uuid) channel = switch_core_session_get_channel(session); switch_channel_stop_broadcast(channel); switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + switch_core_session_rwunlock(session); } } -static void start_hold(const char *uuid, const char *music) +static void start_hold(const char *uuid, const char *stream) { switch_core_session_t *session; switch_channel_t *channel; - const char *stream = NULL; - if (!uuid) { return; @@ -177,11 +176,8 @@ static void start_hold(const char *uuid, const char *music) if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); - if (!(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { - stream = music; - if (switch_strlen_zero(stream)) { - stream = globals.hold_music; - } + if (switch_strlen_zero(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { + stream = globals.hold_music; } if (!switch_strlen_zero(stream)) { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 3b1246961b..40fb6977ff 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -416,7 +416,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { - zap_channel_done(zchan); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); *dtmf = '\0'; dtmf_offset = 0; zap_buffer_zero(dt_buffer); @@ -447,7 +447,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_GET_CALLERID: { - zap_channel_done(zchan); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_channel_command(zchan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); continue; } @@ -464,7 +464,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { 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_channel_done(zchan); zap_buffer_zero(dt_buffer); teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); indicate = 1; @@ -476,7 +475,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_ATTN: { if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_channel_done(zchan); zap_buffer_zero(dt_buffer); teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); indicate = 1; From 14519d193cabf300428fff7c51e264de76ead09e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Apr 2008 15:17:55 +0000 Subject: [PATCH 0904/1766] fix some analog issues brought about by too much concentration on digital git-svn-id: http://svn.openzap.org/svn/openzap/trunk@465 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 12 ++++-------- libs/freetdm/src/zap_analog.c | 6 ++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 23063c4325..4ad7659099 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Fri Jan 25 19:07:34 EST 2008 +Wed Apr 30 10:51:26 EDT 2008 diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index eade1be790..c9469dbb96 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -159,16 +159,15 @@ static void stop_hold(const char *uuid) channel = switch_core_session_get_channel(session); switch_channel_stop_broadcast(channel); switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + switch_core_session_rwunlock(session); } } -static void start_hold(const char *uuid, const char *music) +static void start_hold(const char *uuid, const char *stream) { switch_core_session_t *session; switch_channel_t *channel; - const char *stream = NULL; - if (!uuid) { return; @@ -177,11 +176,8 @@ static void start_hold(const char *uuid, const char *music) if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); - if (!(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { - stream = music; - if (switch_strlen_zero(stream)) { - stream = globals.hold_music; - } + if (switch_strlen_zero(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { + stream = globals.hold_music; } if (!switch_strlen_zero(stream)) { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 3b1246961b..40fb6977ff 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -416,7 +416,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DIALTONE: { - zap_channel_done(zchan); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); *dtmf = '\0'; dtmf_offset = 0; zap_buffer_zero(dt_buffer); @@ -447,7 +447,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_GET_CALLERID: { - zap_channel_done(zchan); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_channel_command(zchan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); continue; } @@ -464,7 +464,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { 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_channel_done(zchan); zap_buffer_zero(dt_buffer); teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); indicate = 1; @@ -476,7 +475,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) case ZAP_CHANNEL_STATE_ATTN: { if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_channel_done(zchan); zap_buffer_zero(dt_buffer); teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); indicate = 1; From 0b5f27f66f0b7e0ed01715495662149ee8709802 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 1 May 2008 16:41:10 +0000 Subject: [PATCH 0905/1766] tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@466 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 85 ++++++++++++++++++++------ libs/openzap/src/zap_analog.c | 6 +- 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 4ad7659099..30f69ec1d6 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Wed Apr 30 10:51:26 EDT 2008 +Thu May 1 12:15:19 EDT 2008 diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c9469dbb96..7055f77a92 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -146,10 +146,11 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in } -static void stop_hold(const char *uuid) +static void stop_hold(switch_core_session_t *session_a, const char *uuid) { switch_core_session_t *session; - switch_channel_t *channel; + switch_channel_t *channel, *channel_a; + ; if (!uuid) { return; @@ -157,31 +158,68 @@ static void stop_hold(const char *uuid) if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); - switch_channel_stop_broadcast(channel); - switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + + if (switch_channel_test_flag(channel, CF_HOLD)) { + channel_a = switch_core_session_get_channel(session_a); + switch_ivr_unhold(session); + switch_channel_clear_flag(channel_a, CF_SUSPEND); + switch_channel_clear_flag(channel_a, CF_HOLD); + } else { + switch_channel_stop_broadcast(channel); + switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + } switch_core_session_rwunlock(session); } } -static void start_hold(const char *uuid, const char *stream) +static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, const char *uuid, const char *stream) { switch_core_session_t *session; - switch_channel_t *channel; + switch_channel_t *channel, *channel_a; if (!uuid) { return; } + if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); + if (switch_strlen_zero(stream)) { + if (!strcasecmp(globals.hold_music, "indicate_hold")) { + stream = "indicate_hold"; + } + if (!strcasecmp(SPAN_CONFIG[zchan->span->span_id].hold_music, "indicate_hold")) { + stream = "indicate_hold"; + } + } + + if (switch_strlen_zero(stream)) { + stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE); + } + + if (switch_strlen_zero(stream)) { + stream = SPAN_CONFIG[zchan->span->span_id].hold_music; + } + + if (switch_strlen_zero(stream)) { + stream = globals.hold_music; + } + if (switch_strlen_zero(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { stream = globals.hold_music; } if (!switch_strlen_zero(stream)) { - switch_ivr_broadcast(switch_core_session_get_uuid(session), stream, SMF_ECHO_ALEG | SMF_LOOP); + if (!strcasecmp(stream, "indicate_hold")) { + channel_a = switch_core_session_get_channel(session_a); + switch_ivr_hold_uuid(uuid, NULL, 0); + switch_channel_set_flag(channel_a, CF_SUSPEND); + switch_channel_set_flag(channel_a, CF_HOLD); + } else { + switch_ivr_broadcast(switch_core_session_get_uuid(session), stream, SMF_ECHO_ALEG | SMF_LOOP); + } } switch_core_session_rwunlock(session); @@ -195,9 +233,6 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) switch_channel_t *channel; private_t *tech_pvt; - if (!bcast) { - bcast = SPAN_CONFIG[zchan->span->span_id].hold_music; - } for (i = 0; i < zchan->token_count; i++) { if ((session = zap_channel_get_session(zchan, i))) { @@ -209,17 +244,17 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) if (zchan->token_count == 1 && flash) { if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { - stop_hold(buuid); + stop_hold(session, buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } else { - start_hold(buuid, bcast); + start_hold(zchan, session, buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } } else if (i) { - start_hold(buuid, bcast); + start_hold(zchan, session, buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { - stop_hold(buuid); + stop_hold(session, buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); if (!switch_channel_test_flag(channel, CF_ANSWERED)) { switch_channel_mark_answered(channel); @@ -1147,7 +1182,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); tech_pvt = switch_core_session_get_private(session_a); - stop_hold(switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE)); + stop_hold(session_a, switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE)); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } @@ -1157,7 +1192,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); tech_pvt = switch_core_session_get_private(session_b); - stop_hold(switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE)); + stop_hold(session_a, switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE)); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } @@ -1213,7 +1248,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_FLASH: { - if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { + + if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_HOLD) && sigmsg->channel->token_count == 1) { + switch_core_session_t *session; + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + const char *buuid; + switch_channel_t *channel; + private_t *tech_pvt; + + tech_pvt = switch_core_session_get_private(session); + channel = switch_core_session_get_channel(session); + buuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_UP); + stop_hold(session, buuid); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + switch_core_session_rwunlock(session); + } + } else if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 40fb6977ff..c6e6c62b26 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -285,7 +285,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && - (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) { + (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; @@ -348,6 +349,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)); @@ -709,7 +711,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_channel_rotate_tokens(event->channel); - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + 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; From 1d5bec97f1c91656df581299c04189de7edb74ab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 1 May 2008 16:41:10 +0000 Subject: [PATCH 0906/1766] tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@466 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 85 ++++++++++++++++++++------ libs/freetdm/src/zap_analog.c | 6 +- 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 4ad7659099..30f69ec1d6 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Wed Apr 30 10:51:26 EDT 2008 +Thu May 1 12:15:19 EDT 2008 diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c9469dbb96..7055f77a92 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -146,10 +146,11 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in } -static void stop_hold(const char *uuid) +static void stop_hold(switch_core_session_t *session_a, const char *uuid) { switch_core_session_t *session; - switch_channel_t *channel; + switch_channel_t *channel, *channel_a; + ; if (!uuid) { return; @@ -157,31 +158,68 @@ static void stop_hold(const char *uuid) if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); - switch_channel_stop_broadcast(channel); - switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + + if (switch_channel_test_flag(channel, CF_HOLD)) { + channel_a = switch_core_session_get_channel(session_a); + switch_ivr_unhold(session); + switch_channel_clear_flag(channel_a, CF_SUSPEND); + switch_channel_clear_flag(channel_a, CF_HOLD); + } else { + switch_channel_stop_broadcast(channel); + switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + } switch_core_session_rwunlock(session); } } -static void start_hold(const char *uuid, const char *stream) +static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, const char *uuid, const char *stream) { switch_core_session_t *session; - switch_channel_t *channel; + switch_channel_t *channel, *channel_a; if (!uuid) { return; } + if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); + if (switch_strlen_zero(stream)) { + if (!strcasecmp(globals.hold_music, "indicate_hold")) { + stream = "indicate_hold"; + } + if (!strcasecmp(SPAN_CONFIG[zchan->span->span_id].hold_music, "indicate_hold")) { + stream = "indicate_hold"; + } + } + + if (switch_strlen_zero(stream)) { + stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE); + } + + if (switch_strlen_zero(stream)) { + stream = SPAN_CONFIG[zchan->span->span_id].hold_music; + } + + if (switch_strlen_zero(stream)) { + stream = globals.hold_music; + } + if (switch_strlen_zero(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { stream = globals.hold_music; } if (!switch_strlen_zero(stream)) { - switch_ivr_broadcast(switch_core_session_get_uuid(session), stream, SMF_ECHO_ALEG | SMF_LOOP); + if (!strcasecmp(stream, "indicate_hold")) { + channel_a = switch_core_session_get_channel(session_a); + switch_ivr_hold_uuid(uuid, NULL, 0); + switch_channel_set_flag(channel_a, CF_SUSPEND); + switch_channel_set_flag(channel_a, CF_HOLD); + } else { + switch_ivr_broadcast(switch_core_session_get_uuid(session), stream, SMF_ECHO_ALEG | SMF_LOOP); + } } switch_core_session_rwunlock(session); @@ -195,9 +233,6 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) switch_channel_t *channel; private_t *tech_pvt; - if (!bcast) { - bcast = SPAN_CONFIG[zchan->span->span_id].hold_music; - } for (i = 0; i < zchan->token_count; i++) { if ((session = zap_channel_get_session(zchan, i))) { @@ -209,17 +244,17 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) if (zchan->token_count == 1 && flash) { if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { - stop_hold(buuid); + stop_hold(session, buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } else { - start_hold(buuid, bcast); + start_hold(zchan, session, buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } } else if (i) { - start_hold(buuid, bcast); + start_hold(zchan, session, buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { - stop_hold(buuid); + stop_hold(session, buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); if (!switch_channel_test_flag(channel, CF_ANSWERED)) { switch_channel_mark_answered(channel); @@ -1147,7 +1182,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); tech_pvt = switch_core_session_get_private(session_a); - stop_hold(switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE)); + stop_hold(session_a, switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE)); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } @@ -1157,7 +1192,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); tech_pvt = switch_core_session_get_private(session_b); - stop_hold(switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE)); + stop_hold(session_a, switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE)); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } @@ -1213,7 +1248,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_FLASH: { - if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { + + if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_HOLD) && sigmsg->channel->token_count == 1) { + switch_core_session_t *session; + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + const char *buuid; + switch_channel_t *channel; + private_t *tech_pvt; + + tech_pvt = switch_core_session_get_private(session); + channel = switch_core_session_get_channel(session); + buuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); + zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_UP); + stop_hold(session, buuid); + switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); + switch_core_session_rwunlock(session); + } + } else if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 40fb6977ff..c6e6c62b26 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -285,7 +285,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && - (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) { + (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; @@ -348,6 +349,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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)); @@ -709,7 +711,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_channel_rotate_tokens(event->channel); - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD)) { + 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; From bb92c3248ed8895b81010baedf823ab218c3e2b3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 2 May 2008 22:28:45 +0000 Subject: [PATCH 0907/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@467 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 2b7de4a180..1053e6de20 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -567,9 +567,11 @@ static __inline__ void check_state(zap_span_t *span) 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_clear_flag_locked((&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); } } } From 53887a7d15db3e8c49c75877bf5a21ab4033f027 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 2 May 2008 22:28:45 +0000 Subject: [PATCH 0908/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@467 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 2b7de4a180..1053e6de20 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -567,9 +567,11 @@ static __inline__ void check_state(zap_span_t *span) 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_clear_flag_locked((&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); } } } From a90ef152f953dd11836dd3aeb75b36dc799f197d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 2 May 2008 23:37:01 +0000 Subject: [PATCH 0909/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@468 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateTE.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index f001029ac6..da028b5867 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -772,7 +772,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else { ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); } - if (pMes->CRV) { + if (pMes->CRV && iFrom == 2) { /* Find the call using CRV */ if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR) return ret; @@ -797,16 +797,17 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i { /* 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; + } - 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; } - return ret; } From a0ab351bcfd21796287b356eb4f990e63321d664 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 2 May 2008 23:37:01 +0000 Subject: [PATCH 0910/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@468 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateTE.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index f001029ac6..da028b5867 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -772,7 +772,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) } else { ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom); } - if (pMes->CRV) { + if (pMes->CRV && iFrom == 2) { /* Find the call using CRV */ if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR) return ret; @@ -797,16 +797,17 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i { /* 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; + } - 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; } - return ret; } From 7917a9a472f8f59da9ad3d630e66b4fcad29a1fc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 5 May 2008 15:47:44 +0000 Subject: [PATCH 0911/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@470 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 26 +++++++++++++------------- libs/openzap/src/zap_isdn.c | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 7055f77a92..d916ecc7a1 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -115,9 +115,9 @@ typedef struct private_object private_t; static switch_status_t channel_on_init(switch_core_session_t *session); static switch_status_t channel_on_hangup(switch_core_session_t *session); -static switch_status_t channel_on_ring(switch_core_session_t *session); -static switch_status_t channel_on_loopback(switch_core_session_t *session); -static switch_status_t channel_on_transmit(switch_core_session_t *session); +static switch_status_t channel_on_routing(switch_core_session_t *session); +static switch_status_t channel_on_exchange_media(switch_core_session_t *session); +static switch_status_t channel_on_soft_execute(switch_core_session_t *session); static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, @@ -359,8 +359,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session) switch_set_flag_locked(tech_pvt, TFLAG_IO); - /* Move Channel's State Machine to RING */ - switch_channel_set_state(channel, CS_RING); + /* Move Channel's State Machine to ROUTING */ + switch_channel_set_state(channel, CS_ROUTING); switch_mutex_lock(globals.mutex); globals.calls++; switch_mutex_unlock(globals.mutex); @@ -370,7 +370,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_ring(switch_core_session_t *session) +static switch_status_t channel_on_routing(switch_core_session_t *session) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; @@ -498,15 +498,15 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_loopback(switch_core_session_t *session) +static switch_status_t channel_on_exchange_media(switch_core_session_t *session) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL EXCHANGE_MEDIA\n"); return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_transmit(switch_core_session_t *session) +static switch_status_t channel_on_soft_execute(switch_core_session_t *session) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL SOFT_EXECUTE\n"); return SWITCH_STATUS_SUCCESS; } @@ -823,11 +823,11 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch_state_handler_table_t openzap_state_handlers = { /*.on_init */ channel_on_init, - /*.on_ring */ channel_on_ring, + /*.on_routing */ channel_on_routing, /*.on_execute */ channel_on_execute, /*.on_hangup */ channel_on_hangup, - /*.on_loopback */ channel_on_loopback, - /*.on_transmit */ channel_on_transmit + /*.on_exchange_media */ channel_on_exchange_media, + /*.on_soft_execute */ channel_on_soft_execute }; switch_io_routines_t openzap_io_routines = { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 1053e6de20..528aafa04e 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -467,7 +467,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) //is cast right here? ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.InfoChanSel = 1; + ChanID.InfoChanSel = 1;//2 suggest 3 you tell me ChanID.ChanMapType = 3; /* B-Chan */ ChanID.ChanSlot = (unsigned char)zchan->chan_id; gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); From f99afcefde32a64e4428a5dd5751ccec64ec22e6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 5 May 2008 15:47:44 +0000 Subject: [PATCH 0912/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@470 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 26 +++++++++++++------------- libs/freetdm/src/zap_isdn.c | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 7055f77a92..d916ecc7a1 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -115,9 +115,9 @@ typedef struct private_object private_t; static switch_status_t channel_on_init(switch_core_session_t *session); static switch_status_t channel_on_hangup(switch_core_session_t *session); -static switch_status_t channel_on_ring(switch_core_session_t *session); -static switch_status_t channel_on_loopback(switch_core_session_t *session); -static switch_status_t channel_on_transmit(switch_core_session_t *session); +static switch_status_t channel_on_routing(switch_core_session_t *session); +static switch_status_t channel_on_exchange_media(switch_core_session_t *session); +static switch_status_t channel_on_soft_execute(switch_core_session_t *session); static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, @@ -359,8 +359,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session) switch_set_flag_locked(tech_pvt, TFLAG_IO); - /* Move Channel's State Machine to RING */ - switch_channel_set_state(channel, CS_RING); + /* Move Channel's State Machine to ROUTING */ + switch_channel_set_state(channel, CS_ROUTING); switch_mutex_lock(globals.mutex); globals.calls++; switch_mutex_unlock(globals.mutex); @@ -370,7 +370,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_ring(switch_core_session_t *session) +static switch_status_t channel_on_routing(switch_core_session_t *session) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; @@ -498,15 +498,15 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_loopback(switch_core_session_t *session) +static switch_status_t channel_on_exchange_media(switch_core_session_t *session) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL EXCHANGE_MEDIA\n"); return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_transmit(switch_core_session_t *session) +static switch_status_t channel_on_soft_execute(switch_core_session_t *session) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL SOFT_EXECUTE\n"); return SWITCH_STATUS_SUCCESS; } @@ -823,11 +823,11 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch_state_handler_table_t openzap_state_handlers = { /*.on_init */ channel_on_init, - /*.on_ring */ channel_on_ring, + /*.on_routing */ channel_on_routing, /*.on_execute */ channel_on_execute, /*.on_hangup */ channel_on_hangup, - /*.on_loopback */ channel_on_loopback, - /*.on_transmit */ channel_on_transmit + /*.on_exchange_media */ channel_on_exchange_media, + /*.on_soft_execute */ channel_on_soft_execute }; switch_io_routines_t openzap_io_routines = { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 1053e6de20..528aafa04e 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -467,7 +467,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) //is cast right here? ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.InfoChanSel = 1; + ChanID.InfoChanSel = 1;//2 suggest 3 you tell me ChanID.ChanMapType = 3; /* B-Chan */ ChanID.ChanSlot = (unsigned char)zchan->chan_id; gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); From 965e37759ac4a0e56755b246b02e5f1d98954b10 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 5 May 2008 22:54:40 +0000 Subject: [PATCH 0913/1766] change outbound req code for isdn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@471 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 13 +- libs/openzap/src/include/zap_types.h | 2 +- libs/openzap/src/zap_io.c | 14 +- libs/openzap/src/zap_isdn.c | 377 ++++++++++++++++++--------- 4 files changed, 278 insertions(+), 128 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3d973fd3a6..57c87fb549 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -313,6 +313,12 @@ typedef struct { uint8_t plan; } zap_number_t; +typedef enum { + ZAP_CALLER_STATE_DIALING, + ZAP_CALLER_STATE_SUCCESS, + ZAP_CALLER_STATE_FAIL +} zap_caller_state_t; + struct zap_caller_data { char cid_date[8]; char cid_name[80]; @@ -328,6 +334,9 @@ struct zap_caller_data { int hangup_cause; uint8_t raw_data[1024]; uint32_t raw_data_len; + uint32_t flags; + zap_caller_state_t call_state; + uint32_t chan_id; }; typedef enum { @@ -410,6 +419,7 @@ struct zap_isdn_data { struct zap_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; + zap_caller_data_t *outbound_crv[32768]; zap_channel_t *channels_local_crv[32768]; zap_channel_t *channels_remote_crv[32768]; }; @@ -444,6 +454,7 @@ struct zap_span { zio_channel_request_t channel_request; void *mod_data; char *type; + int suggest_chan_id; }; @@ -520,7 +531,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_done(zap_channel_t *zchan); zap_status_t zap_channel_use(zap_channel_t *zchan); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index c0334bffd9..5ee75505ab 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -349,7 +349,7 @@ typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; typedef struct zap_caller_data zap_caller_data_t; -#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan) +#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) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index fe83986f11..5bce48dc56 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -709,7 +709,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -723,9 +723,9 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c *zchan = NULL; return ZAP_FAIL; } - - if (globals.spans[span_id].channel_request) { - return globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); + + if (globals.spans[span_id].channel_request && !globals.spans[span_id].suggest_chan_id) { + return globals.spans[span_id].channel_request(&globals.spans[span_id], 0, direction, caller_data, zchan); } span_max = span_id; @@ -783,6 +783,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c check->state == ZAP_CHANNEL_STATE_DOWN ) { + if (globals.spans[span_id].channel_request) { + status = globals.spans[span_id].channel_request(&globals.spans[span_id], i, direction, caller_data, zchan); + zap_mutex_unlock(span->mutex); + goto done; + } + status = check->zio->open(check); if (status == ZAP_SUCCESS) { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 528aafa04e..28093cae5d 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -56,6 +56,232 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) return status; } +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; + zap_status_t status = ZAP_FAIL; + zap_isdn_data_t *isdn_data = span->signal_data; + int sanity = 60000; + + Q931InitIEBearerCap(&BearerCap); + Q931InitIEChanID(&ChanID); + Q931InitIECallingNum(&CallingNum); + Q931InitIECalledNum(&CalledNum); + Q931InitIEDisplay(&Display); + + Q931InitMesGeneric(gen); + gen->MesType = Q931mes_SETUP; + + BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ + BearerCap.ITC = 0; /* Speech */ + BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ + BearerCap.ITR = 16; /* 64k */ + BearerCap.Layer1Ident = 1; + BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ +#if 0 + BearerCap.SyncAsync = ; + BearerCap.Negot = ; + BearerCap.UserRate = ; + BearerCap.InterRate = ; + BearerCap.NIConTx = ; + BearerCap.FlowCtlTx = ; + BearerCap.HDR = ; + BearerCap.MultiFrame = ; + BearerCap.Mode = ; + BearerCap.LLInegot = ; + BearerCap.Assignor = ; + BearerCap.InBandNeg = ; + BearerCap.NumStopBits = ; + BearerCap.NumDataBits = ; + BearerCap.Parity = ; + BearerCap.DuplexMode = ; + BearerCap.ModemType = ; + BearerCap.Layer2Ident = ; + BearerCap.UIL2Prot = ; + BearerCap.Layer3Ident = ; + BearerCap.UIL3Prot = ; + BearerCap.AL3Info1 = ; + BearerCap.AL3Info2 = ; +#endif + + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + + //is cast right here? + ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ + ChanID.PrefExcl = 0; /* 0 = preferred, 1 exclusive */ + ChanID.InfoChanSel = 1; + ChanID.ChanMapType = 3; /* B-Chan */ + ChanID.ChanSlot = chan_id; + gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); + + 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); + + /* TypNum: Type of number */ + /* Bits 7 6 5 */ + /* 000 Unknown */ + /* 001 International number */ + /* 010 National number */ + /* 011 Network Specific number */ + /* 100 Subscriber mumber */ + /* 110 Abbreviated number */ + /* 111 Reserved for extension */ + /* All other values are reserved */ + CallingNum.TypNum = 2; + + /* NumPlanID */ + /* Bits 4 3 2 1 */ + /* 0000 Unknown */ + /* 0001 ISDN/telephony numbering plan (E.164) */ + /* 0011 Data numbering plan (X.121) */ + /* 0100 Telex numbering plan (F.69) */ + /* 1000 National standard numbering plan */ + /* 1001 Private numbering plan */ + /* 1111 Reserved for extension */ + /* All other valures are reserved */ + CallingNum.NumPlanID = 1; + + /* Presentation indicator */ + /* Bits 7 6 */ + /* 00 Presenation Allowed */ + /* 01 Presentation Restricted */ + /* 10 Number not available due to internetworking */ + /* 11 Reserved */ + CallingNum.PresInd = 0; + + /* Screening Indicator */ + /* Bits 2 1 */ + /* 00 User-provided, not screened */ + /* 01 User-provided, verified and passed */ + /* 10 User-provided, verified and failed */ + /* 11 Network provided */ + CallingNum.ScreenInd = 0; + 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); + + CalledNum.TypNum = 2; + CalledNum.NumPlanID = 1; + 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); + + + 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)); + + switch(gen->MesType) { + case Q931mes_ALERTING: + new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; + break; + 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; + +} + 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); @@ -69,7 +295,8 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931mes_Generic *gen = (Q931mes_Generic *) msg; int chan_id = 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); chan_id = chanid->ChanSlot; @@ -78,11 +305,31 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) assert(span != NULL); assert(isdn_data != NULL); -#if 0 - if (chan_id) { - zchan = &span->channels[chan_id]; + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); + + 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; } -#endif if (gen->CRVFlag) { zchan = isdn_data->channels_local_crv[gen->CRV]; @@ -91,7 +338,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); + if (gen->ProtDisc == 3) { switch(gen->MesType) { @@ -414,122 +661,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_DIALING: { - Q931ie_BearerCap BearerCap; - Q931ie_ChanID ChanID; - Q931ie_CallingNum CallingNum; - Q931ie_CallingNum *ptrCallingNum; - Q931ie_CalledNum CalledNum; - Q931ie_CalledNum *ptrCalledNum; - Q931ie_Display Display, *ptrDisplay; - - Q931InitIEBearerCap(&BearerCap); - Q931InitIEChanID(&ChanID); - Q931InitIECallingNum(&CallingNum); - Q931InitIECalledNum(&CalledNum); - Q931InitIEDisplay(&Display); - Q931InitMesGeneric(gen); - gen->MesType = Q931mes_SETUP; - - BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ - BearerCap.ITC = 0; /* Speech */ - BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ - BearerCap.ITR = 16; /* 64k */ - BearerCap.Layer1Ident = 1; - BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ -#if 0 - BearerCap.SyncAsync = ; - BearerCap.Negot = ; - BearerCap.UserRate = ; - BearerCap.InterRate = ; - BearerCap.NIConTx = ; - BearerCap.FlowCtlTx = ; - BearerCap.HDR = ; - BearerCap.MultiFrame = ; - BearerCap.Mode = ; - BearerCap.LLInegot = ; - BearerCap.Assignor = ; - BearerCap.InBandNeg = ; - BearerCap.NumStopBits = ; - BearerCap.NumDataBits = ; - BearerCap.Parity = ; - BearerCap.DuplexMode = ; - BearerCap.ModemType = ; - BearerCap.Layer2Ident = ; - BearerCap.UIL2Prot = ; - BearerCap.Layer3Ident = ; - BearerCap.UIL3Prot = ; - BearerCap.AL3Info1 = ; - BearerCap.AL3Info2 = ; -#endif - - gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); - - //is cast right here? - ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.InfoChanSel = 1;//2 suggest 3 you tell me - ChanID.ChanMapType = 3; /* B-Chan */ - ChanID.ChanSlot = (unsigned char)zchan->chan_id; - gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); - - 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); - - /* TypNum: Type of number */ - /* Bits 7 6 5 */ - /* 000 Unknown */ - /* 001 International number */ - /* 010 National number */ - /* 011 Network Specific number */ - /* 100 Subscriber mumber */ - /* 110 Abbreviated number */ - /* 111 Reserved for extension */ - /* All other values are reserved */ - CallingNum.TypNum = 2; - - /* NumPlanID */ - /* Bits 4 3 2 1 */ - /* 0000 Unknown */ - /* 0001 ISDN/telephony numbering plan (E.164) */ - /* 0011 Data numbering plan (X.121) */ - /* 0100 Telex numbering plan (F.69) */ - /* 1000 National standard numbering plan */ - /* 1001 Private numbering plan */ - /* 1111 Reserved for extension */ - /* All other valures are reserved */ - CallingNum.NumPlanID = 1; - - /* Presentation indicator */ - /* Bits 7 6 */ - /* 00 Presenation Allowed */ - /* 01 Presentation Restricted */ - /* 10 Number not available due to internetworking */ - /* 11 Reserved */ - CallingNum.PresInd = 0; - - /* Screening Indicator */ - /* Bits 2 1 */ - /* 00 User-provided, not screened */ - /* 01 User-provided, verified and passed */ - /* 10 User-provided, verified and failed */ - /* 11 Network provided */ - CallingNum.ScreenInd = 0; - 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.TypNum = 2; - CalledNum.NumPlanID = 1; - 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); - - Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); - isdn_data->channels_local_crv[gen->CRV] = zchan; } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -828,7 +960,8 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - + span->channel_request = isdn_channel_request; + span->suggest_chan_id = 1; return ZAP_SUCCESS; } From fb4a8b2a59ac2e3707ea7e195d56ecac4faa3588 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 5 May 2008 22:54:40 +0000 Subject: [PATCH 0914/1766] change outbound req code for isdn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@471 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 13 +- libs/freetdm/src/include/zap_types.h | 2 +- libs/freetdm/src/zap_io.c | 14 +- libs/freetdm/src/zap_isdn.c | 377 ++++++++++++++++++--------- 4 files changed, 278 insertions(+), 128 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 3d973fd3a6..57c87fb549 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -313,6 +313,12 @@ typedef struct { uint8_t plan; } zap_number_t; +typedef enum { + ZAP_CALLER_STATE_DIALING, + ZAP_CALLER_STATE_SUCCESS, + ZAP_CALLER_STATE_FAIL +} zap_caller_state_t; + struct zap_caller_data { char cid_date[8]; char cid_name[80]; @@ -328,6 +334,9 @@ struct zap_caller_data { int hangup_cause; uint8_t raw_data[1024]; uint32_t raw_data_len; + uint32_t flags; + zap_caller_state_t call_state; + uint32_t chan_id; }; typedef enum { @@ -410,6 +419,7 @@ struct zap_isdn_data { struct zap_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; + zap_caller_data_t *outbound_crv[32768]; zap_channel_t *channels_local_crv[32768]; zap_channel_t *channels_remote_crv[32768]; }; @@ -444,6 +454,7 @@ struct zap_span { zio_channel_request_t channel_request; void *mod_data; char *type; + int suggest_chan_id; }; @@ -520,7 +531,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan); +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); zap_status_t zap_channel_close(zap_channel_t **zchan); zap_status_t zap_channel_done(zap_channel_t *zchan); zap_status_t zap_channel_use(zap_channel_t *zchan); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index c0334bffd9..5ee75505ab 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -349,7 +349,7 @@ typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; typedef struct zap_caller_data zap_caller_data_t; -#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan) +#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) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index fe83986f11..5bce48dc56 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -709,7 +709,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, const zap_caller_data_t *caller_data, zap_channel_t **zchan) +zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -723,9 +723,9 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c *zchan = NULL; return ZAP_FAIL; } - - if (globals.spans[span_id].channel_request) { - return globals.spans[span_id].channel_request(&globals.spans[span_id], direction, caller_data, zchan); + + if (globals.spans[span_id].channel_request && !globals.spans[span_id].suggest_chan_id) { + return globals.spans[span_id].channel_request(&globals.spans[span_id], 0, direction, caller_data, zchan); } span_max = span_id; @@ -783,6 +783,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, c check->state == ZAP_CHANNEL_STATE_DOWN ) { + if (globals.spans[span_id].channel_request) { + status = globals.spans[span_id].channel_request(&globals.spans[span_id], i, direction, caller_data, zchan); + zap_mutex_unlock(span->mutex); + goto done; + } + status = check->zio->open(check); if (status == ZAP_SUCCESS) { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 528aafa04e..28093cae5d 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -56,6 +56,232 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) return status; } +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; + zap_status_t status = ZAP_FAIL; + zap_isdn_data_t *isdn_data = span->signal_data; + int sanity = 60000; + + Q931InitIEBearerCap(&BearerCap); + Q931InitIEChanID(&ChanID); + Q931InitIECallingNum(&CallingNum); + Q931InitIECalledNum(&CalledNum); + Q931InitIEDisplay(&Display); + + Q931InitMesGeneric(gen); + gen->MesType = Q931mes_SETUP; + + BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ + BearerCap.ITC = 0; /* Speech */ + BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ + BearerCap.ITR = 16; /* 64k */ + BearerCap.Layer1Ident = 1; + BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ +#if 0 + BearerCap.SyncAsync = ; + BearerCap.Negot = ; + BearerCap.UserRate = ; + BearerCap.InterRate = ; + BearerCap.NIConTx = ; + BearerCap.FlowCtlTx = ; + BearerCap.HDR = ; + BearerCap.MultiFrame = ; + BearerCap.Mode = ; + BearerCap.LLInegot = ; + BearerCap.Assignor = ; + BearerCap.InBandNeg = ; + BearerCap.NumStopBits = ; + BearerCap.NumDataBits = ; + BearerCap.Parity = ; + BearerCap.DuplexMode = ; + BearerCap.ModemType = ; + BearerCap.Layer2Ident = ; + BearerCap.UIL2Prot = ; + BearerCap.Layer3Ident = ; + BearerCap.UIL3Prot = ; + BearerCap.AL3Info1 = ; + BearerCap.AL3Info2 = ; +#endif + + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + + //is cast right here? + ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ + ChanID.PrefExcl = 0; /* 0 = preferred, 1 exclusive */ + ChanID.InfoChanSel = 1; + ChanID.ChanMapType = 3; /* B-Chan */ + ChanID.ChanSlot = chan_id; + gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); + + 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); + + /* TypNum: Type of number */ + /* Bits 7 6 5 */ + /* 000 Unknown */ + /* 001 International number */ + /* 010 National number */ + /* 011 Network Specific number */ + /* 100 Subscriber mumber */ + /* 110 Abbreviated number */ + /* 111 Reserved for extension */ + /* All other values are reserved */ + CallingNum.TypNum = 2; + + /* NumPlanID */ + /* Bits 4 3 2 1 */ + /* 0000 Unknown */ + /* 0001 ISDN/telephony numbering plan (E.164) */ + /* 0011 Data numbering plan (X.121) */ + /* 0100 Telex numbering plan (F.69) */ + /* 1000 National standard numbering plan */ + /* 1001 Private numbering plan */ + /* 1111 Reserved for extension */ + /* All other valures are reserved */ + CallingNum.NumPlanID = 1; + + /* Presentation indicator */ + /* Bits 7 6 */ + /* 00 Presenation Allowed */ + /* 01 Presentation Restricted */ + /* 10 Number not available due to internetworking */ + /* 11 Reserved */ + CallingNum.PresInd = 0; + + /* Screening Indicator */ + /* Bits 2 1 */ + /* 00 User-provided, not screened */ + /* 01 User-provided, verified and passed */ + /* 10 User-provided, verified and failed */ + /* 11 Network provided */ + CallingNum.ScreenInd = 0; + 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); + + CalledNum.TypNum = 2; + CalledNum.NumPlanID = 1; + 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); + + + 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)); + + switch(gen->MesType) { + case Q931mes_ALERTING: + new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; + break; + 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; + +} + 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); @@ -69,7 +295,8 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931mes_Generic *gen = (Q931mes_Generic *) msg; int chan_id = 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); chan_id = chanid->ChanSlot; @@ -78,11 +305,31 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) assert(span != NULL); assert(isdn_data != NULL); -#if 0 - if (chan_id) { - zchan = &span->channels[chan_id]; + zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); + + 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; } -#endif if (gen->CRVFlag) { zchan = isdn_data->channels_local_crv[gen->CRV]; @@ -91,7 +338,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); + if (gen->ProtDisc == 3) { switch(gen->MesType) { @@ -414,122 +661,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_DIALING: { - Q931ie_BearerCap BearerCap; - Q931ie_ChanID ChanID; - Q931ie_CallingNum CallingNum; - Q931ie_CallingNum *ptrCallingNum; - Q931ie_CalledNum CalledNum; - Q931ie_CalledNum *ptrCalledNum; - Q931ie_Display Display, *ptrDisplay; - - Q931InitIEBearerCap(&BearerCap); - Q931InitIEChanID(&ChanID); - Q931InitIECallingNum(&CallingNum); - Q931InitIECalledNum(&CalledNum); - Q931InitIEDisplay(&Display); - Q931InitMesGeneric(gen); - gen->MesType = Q931mes_SETUP; - - BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ - BearerCap.ITC = 0; /* Speech */ - BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ - BearerCap.ITR = 16; /* 64k */ - BearerCap.Layer1Ident = 1; - BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ -#if 0 - BearerCap.SyncAsync = ; - BearerCap.Negot = ; - BearerCap.UserRate = ; - BearerCap.InterRate = ; - BearerCap.NIConTx = ; - BearerCap.FlowCtlTx = ; - BearerCap.HDR = ; - BearerCap.MultiFrame = ; - BearerCap.Mode = ; - BearerCap.LLInegot = ; - BearerCap.Assignor = ; - BearerCap.InBandNeg = ; - BearerCap.NumStopBits = ; - BearerCap.NumDataBits = ; - BearerCap.Parity = ; - BearerCap.DuplexMode = ; - BearerCap.ModemType = ; - BearerCap.Layer2Ident = ; - BearerCap.UIL2Prot = ; - BearerCap.Layer3Ident = ; - BearerCap.UIL3Prot = ; - BearerCap.AL3Info1 = ; - BearerCap.AL3Info2 = ; -#endif - - gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); - - //is cast right here? - ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.InfoChanSel = 1;//2 suggest 3 you tell me - ChanID.ChanMapType = 3; /* B-Chan */ - ChanID.ChanSlot = (unsigned char)zchan->chan_id; - gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); - - 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); - - /* TypNum: Type of number */ - /* Bits 7 6 5 */ - /* 000 Unknown */ - /* 001 International number */ - /* 010 National number */ - /* 011 Network Specific number */ - /* 100 Subscriber mumber */ - /* 110 Abbreviated number */ - /* 111 Reserved for extension */ - /* All other values are reserved */ - CallingNum.TypNum = 2; - - /* NumPlanID */ - /* Bits 4 3 2 1 */ - /* 0000 Unknown */ - /* 0001 ISDN/telephony numbering plan (E.164) */ - /* 0011 Data numbering plan (X.121) */ - /* 0100 Telex numbering plan (F.69) */ - /* 1000 National standard numbering plan */ - /* 1001 Private numbering plan */ - /* 1111 Reserved for extension */ - /* All other valures are reserved */ - CallingNum.NumPlanID = 1; - - /* Presentation indicator */ - /* Bits 7 6 */ - /* 00 Presenation Allowed */ - /* 01 Presentation Restricted */ - /* 10 Number not available due to internetworking */ - /* 11 Reserved */ - CallingNum.PresInd = 0; - - /* Screening Indicator */ - /* Bits 2 1 */ - /* 00 User-provided, not screened */ - /* 01 User-provided, verified and passed */ - /* 10 User-provided, verified and failed */ - /* 11 Network provided */ - CallingNum.ScreenInd = 0; - 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.TypNum = 2; - CalledNum.NumPlanID = 1; - 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); - - Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); - isdn_data->channels_local_crv[gen->CRV] = zchan; } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -828,7 +960,8 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - + span->channel_request = isdn_channel_request; + span->suggest_chan_id = 1; return ZAP_SUCCESS; } From e1a86feba83c434ed9d2649e1248a257e1b56f16 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 May 2008 20:27:31 +0000 Subject: [PATCH 0915/1766] CtRiX is fast git-svn-id: http://svn.openzap.org/svn/openzap/trunk@472 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 42 ++++++++------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d916ecc7a1..b786752d9c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -123,8 +123,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags); -static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id); -static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); @@ -359,7 +359,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) switch_set_flag_locked(tech_pvt, TFLAG_IO); - /* Move Channel's State Machine to ROUTING */ + /* Move channel's state machine to ROUTING */ switch_channel_set_state(channel, CS_ROUTING); switch_mutex_lock(globals.mutex); globals.calls++; @@ -510,27 +510,6 @@ static switch_status_t channel_on_soft_execute(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id) -{ - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id) -{ - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); - - return SWITCH_STATUS_SUCCESS; - -} - static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) { private_t *tech_pvt = NULL; @@ -545,7 +524,7 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; @@ -553,7 +532,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch zap_wait_flag_t wflags = ZAP_READ; char dtmf[128] = ""; zap_status_t status; - int total_to = timeout; + int total_to; int chunk, do_break = 0; channel = switch_core_session_get_channel(session); @@ -566,9 +545,14 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); chunk = tech_pvt->zchan->effective_interval * 2; + total_to = chunk * 2; top: + if (switch_channel_test_flag(channel, CF_SUSPEND)) { + do_break = 1; + } + if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { switch_clear_flag_locked(tech_pvt, TFLAG_BREAK); do_break = 1; @@ -597,7 +581,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (status == ZAP_TIMEOUT) { - if (timeout > 0 && !switch_test_flag(tech_pvt, TFLAG_HOLD)) { + if (!switch_test_flag(tech_pvt, TFLAG_HOLD)) { total_to -= chunk; if (total_to <= 0) { goto fail; @@ -646,7 +630,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } -static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; @@ -835,8 +819,6 @@ switch_io_routines_t openzap_io_routines = { /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, /*.kill_channel */ channel_kill_channel, - /*.waitfor_read */ channel_waitfor_read, - /*.waitfor_write */ channel_waitfor_write, /*.send_dtmf */ channel_send_dtmf, /*.receive_message*/ channel_receive_message }; From 01b0022a50875e78677bae1a9a70e01006a1a59f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 May 2008 20:27:31 +0000 Subject: [PATCH 0916/1766] CtRiX is fast git-svn-id: http://svn.openzap.org/svn/openzap/trunk@472 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 42 ++++++++------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d916ecc7a1..b786752d9c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -123,8 +123,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags); -static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id); -static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); @@ -359,7 +359,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) switch_set_flag_locked(tech_pvt, TFLAG_IO); - /* Move Channel's State Machine to ROUTING */ + /* Move channel's state machine to ROUTING */ switch_channel_set_state(channel, CS_ROUTING); switch_mutex_lock(globals.mutex); globals.calls++; @@ -510,27 +510,6 @@ static switch_status_t channel_on_soft_execute(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id) -{ - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id) -{ - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); - - return SWITCH_STATUS_SUCCESS; - -} - static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) { private_t *tech_pvt = NULL; @@ -545,7 +524,7 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) +static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; @@ -553,7 +532,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch zap_wait_flag_t wflags = ZAP_READ; char dtmf[128] = ""; zap_status_t status; - int total_to = timeout; + int total_to; int chunk, do_break = 0; channel = switch_core_session_get_channel(session); @@ -566,9 +545,14 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); chunk = tech_pvt->zchan->effective_interval * 2; + total_to = chunk * 2; top: + if (switch_channel_test_flag(channel, CF_SUSPEND)) { + do_break = 1; + } + if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { switch_clear_flag_locked(tech_pvt, TFLAG_BREAK); do_break = 1; @@ -597,7 +581,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (status == ZAP_TIMEOUT) { - if (timeout > 0 && !switch_test_flag(tech_pvt, TFLAG_HOLD)) { + if (!switch_test_flag(tech_pvt, TFLAG_HOLD)) { total_to -= chunk; if (total_to <= 0) { goto fail; @@ -646,7 +630,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } -static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) +static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; @@ -835,8 +819,6 @@ switch_io_routines_t openzap_io_routines = { /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, /*.kill_channel */ channel_kill_channel, - /*.waitfor_read */ channel_waitfor_read, - /*.waitfor_write */ channel_waitfor_write, /*.send_dtmf */ channel_send_dtmf, /*.receive_message*/ channel_receive_message }; From cb617328208892c0086c0c39661a3d1391033442 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 9 May 2008 14:50:21 +0000 Subject: [PATCH 0917/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@473 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/src/zap_analog.c | 3 +-- libs/openzap/src/zap_zt.c | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 30f69ec1d6..dd1ee6e7b5 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Thu May 1 12:15:19 EDT 2008 +Fri May 9 10:23:02 EDT 2008 diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index c6e6c62b26..2b053cff9b 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -778,8 +778,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) break; case ZAP_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Failure!\n"); - goto end; + zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); } break; default: diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 6c0c6d3140..afcf3ca968 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -565,6 +565,10 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) } } + if (!k) { + snprintf(span->last_error, sizeof(span->last_error), "no matching descriptor"); + } + return k ? ZAP_SUCCESS : ZAP_FAIL; } From f43d61872570dd1718231b3c1e93413f5f8686ec Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 9 May 2008 14:50:21 +0000 Subject: [PATCH 0918/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@473 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/src/zap_analog.c | 3 +-- libs/freetdm/src/zap_zt.c | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 30f69ec1d6..dd1ee6e7b5 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Thu May 1 12:15:19 EDT 2008 +Fri May 9 10:23:02 EDT 2008 diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index c6e6c62b26..2b053cff9b 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -778,8 +778,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) break; case ZAP_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Failure!\n"); - goto end; + zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); } break; default: diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index 6c0c6d3140..afcf3ca968 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -565,6 +565,10 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) } } + if (!k) { + snprintf(span->last_error, sizeof(span->last_error), "no matching descriptor"); + } + return k ? ZAP_SUCCESS : ZAP_FAIL; } From 25ebc8420e4dcfb5cdbb962394208264c31c2933 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 May 2008 15:48:51 +0000 Subject: [PATCH 0919/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@475 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/src/zap_analog.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index dd1ee6e7b5..aee0582972 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Fri May 9 10:23:02 EDT 2008 +Wed May 14 11:20:37 EDT 2008 diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 2b053cff9b..64836c7436 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -336,7 +336,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(zchan); goto done; } break; @@ -412,7 +411,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { sig.event_id = ZAP_SIGEVENT_STOP; analog_data->sig_cb(&sig); - zap_channel_done(zchan); goto done; } break; @@ -624,8 +622,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) done: - zap_channel_done(zchan); - if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); From 7efa298023d417575379617d0bfe8f494bcbc3be Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 May 2008 15:48:51 +0000 Subject: [PATCH 0920/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@475 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/src/zap_analog.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index dd1ee6e7b5..aee0582972 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Fri May 9 10:23:02 EDT 2008 +Wed May 14 11:20:37 EDT 2008 diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/zap_analog.c index 2b053cff9b..64836c7436 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/zap_analog.c @@ -336,7 +336,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_DOWN: { - zap_channel_done(zchan); goto done; } break; @@ -412,7 +411,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) { sig.event_id = ZAP_SIGEVENT_STOP; analog_data->sig_cb(&sig); - zap_channel_done(zchan); goto done; } break; @@ -624,8 +622,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) done: - zap_channel_done(zchan); - if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); From 3e7f205d31b7893ed7cdebf5826b3f24ec810554 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 May 2008 15:53:02 +0000 Subject: [PATCH 0921/1766] make echo stuff failure nonfatal git-svn-id: http://svn.openzap.org/svn/openzap/trunk@476 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/src/zap_zt.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index aee0582972..b7c238bea5 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Wed May 14 11:20:37 EDT 2008 +Wed May 14 11:24:37 EDT 2008 diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index afcf3ca968..ec6872b782 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -346,16 +346,18 @@ static ZIO_OPEN_FUNCTION(zt_open) } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { int len = zt_globals.eclevel; if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); - return ZAP_FAIL; - } - - len = zt_globals.etlevel; - if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); - return ZAP_FAIL; + zap_log(ZAP_LOG_WARNING, "Echo cancel not available for %d:%d\n", zchan->span_id, zchan->chan_id); + //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + //return ZAP_FAIL; + } else { + len = zt_globals.etlevel; + if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { + zap_log(ZAP_LOG_WARNING, "Echo training not available for %d:%d\n", zchan->span_id, zchan->chan_id); + //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + //return ZAP_FAIL; + } } } } From 618bd1d079c4a04ee9418e3948cc53421f1c8467 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 May 2008 15:53:02 +0000 Subject: [PATCH 0922/1766] make echo stuff failure nonfatal git-svn-id: http://svn.openzap.org/svn/openzap/trunk@476 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/src/zap_zt.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index aee0582972..b7c238bea5 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Wed May 14 11:20:37 EDT 2008 +Wed May 14 11:24:37 EDT 2008 diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index afcf3ca968..ec6872b782 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -346,16 +346,18 @@ static ZIO_OPEN_FUNCTION(zt_open) } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { int len = zt_globals.eclevel; if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); - return ZAP_FAIL; - } - - len = zt_globals.etlevel; - if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); - return ZAP_FAIL; + zap_log(ZAP_LOG_WARNING, "Echo cancel not available for %d:%d\n", zchan->span_id, zchan->chan_id); + //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + //return ZAP_FAIL; + } else { + len = zt_globals.etlevel; + if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { + zap_log(ZAP_LOG_WARNING, "Echo training not available for %d:%d\n", zchan->span_id, zchan->chan_id); + //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); + //return ZAP_FAIL; + } } } } From b7b9bf763b01841ac126e945052cfdb1ada9c72d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 May 2008 19:43:58 +0000 Subject: [PATCH 0923/1766] add var_event down into the endpoints so chans with no parents can still pass options git-svn-id: http://svn.openzap.org/svn/openzap/trunk@477 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b786752d9c..e0e4b6ac43 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -118,7 +118,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session); static switch_status_t channel_on_routing(switch_core_session_t *session); static switch_status_t channel_on_exchange_media(switch_core_session_t *session); static switch_status_t channel_on_soft_execute(switch_core_session_t *session); -static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, @@ -826,7 +826,7 @@ switch_io_routines_t openzap_io_routines = { /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ -static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags) From 5ae7201c37fed1245746e258b052f8c76dff0c57 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 May 2008 19:43:58 +0000 Subject: [PATCH 0924/1766] add var_event down into the endpoints so chans with no parents can still pass options git-svn-id: http://svn.openzap.org/svn/openzap/trunk@477 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index b786752d9c..e0e4b6ac43 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -118,7 +118,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session); static switch_status_t channel_on_routing(switch_core_session_t *session); static switch_status_t channel_on_exchange_media(switch_core_session_t *session); static switch_status_t channel_on_soft_execute(switch_core_session_t *session); -static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, @@ -826,7 +826,7 @@ switch_io_routines_t openzap_io_routines = { /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines that allocate memory or you will have 1 channel with memory allocated from another channel's pool! */ -static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, +static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags) From 9053ab88e3e912f9f12c50ecc0545a275f2d3a19 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 May 2008 20:56:47 +0000 Subject: [PATCH 0925/1766] fix pointer thingy git-svn-id: http://svn.openzap.org/svn/openzap/trunk@478 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_config.h | 2 +- libs/openzap/src/zap_config.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/include/zap_config.h b/libs/openzap/src/include/zap_config.h index f239fa933e..0b37208666 100644 --- a/libs/openzap/src/include/zap_config.h +++ b/libs/openzap/src/include/zap_config.h @@ -77,7 +77,7 @@ struct zap_config { /*! FILE stream buffer to the opened file */ FILE *file; /*! path to the file */ - const char *path; + char path[512]; /*! current category */ char category[256]; /*! current section */ diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index 4c9aaa957d..f27fa04621 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -69,7 +69,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) } cfg->file = f; - cfg->path = path; + zap_set_string(cfg->path, path); while (zap_config_next_pair(cfg, &var, &val)) { if ((cfg->sectno != last) && !strcmp(cfg->section, file_path)) { @@ -86,7 +86,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) return 0; } else { cfg->file = f; - cfg->path = path; + zap_set_string(cfg->path, path); return 1; } } From a649b013acdecae22b451c0954d8732051026e6e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 May 2008 20:56:47 +0000 Subject: [PATCH 0926/1766] fix pointer thingy git-svn-id: http://svn.openzap.org/svn/openzap/trunk@478 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_config.h | 2 +- libs/freetdm/src/zap_config.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h index f239fa933e..0b37208666 100644 --- a/libs/freetdm/src/include/zap_config.h +++ b/libs/freetdm/src/include/zap_config.h @@ -77,7 +77,7 @@ struct zap_config { /*! FILE stream buffer to the opened file */ FILE *file; /*! path to the file */ - const char *path; + char path[512]; /*! current category */ char category[256]; /*! current section */ diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index 4c9aaa957d..f27fa04621 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -69,7 +69,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) } cfg->file = f; - cfg->path = path; + zap_set_string(cfg->path, path); while (zap_config_next_pair(cfg, &var, &val)) { if ((cfg->sectno != last) && !strcmp(cfg->section, file_path)) { @@ -86,7 +86,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) return 0; } else { cfg->file = f; - cfg->path = path; + zap_set_string(cfg->path, path); return 1; } } From 33b748e11477cb4f843594052b9adea72d5bf1d3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 May 2008 16:48:19 +0000 Subject: [PATCH 0927/1766] fix bounds check issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@480 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 16 +++++++++++----- libs/openzap/src/zap_isdn.c | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 5bce48dc56..5bdb83f3df 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -718,6 +718,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { + if (span_id >= ZAP_MAX_SPANS_INTERFACE) { + zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); + *zchan = NULL; + return ZAP_FAIL; + } + if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); *zchan = NULL; @@ -907,14 +913,14 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_mutex_lock(globals.mutex); - if (span_id && globals.spans[span_id].channel_request) { - zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); - goto done; - } - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; + if (globals.spans[span_id].channel_request) { + zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + goto done; + } + check = &globals.spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 28093cae5d..80a3c8475e 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -813,6 +813,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) 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; } } @@ -913,6 +914,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D } 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++; } } From c1d46e371cfd7a0744144bc64b3304b2163bbd1b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 May 2008 16:48:19 +0000 Subject: [PATCH 0928/1766] fix bounds check issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@480 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 16 +++++++++++----- libs/freetdm/src/zap_isdn.c | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5bce48dc56..5bdb83f3df 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -718,6 +718,12 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { + if (span_id >= ZAP_MAX_SPANS_INTERFACE) { + zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); + *zchan = NULL; + return ZAP_FAIL; + } + if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); *zchan = NULL; @@ -907,14 +913,14 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t zap_mutex_lock(globals.mutex); - if (span_id && globals.spans[span_id].channel_request) { - zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); - goto done; - } - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; + if (globals.spans[span_id].channel_request) { + zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + goto done; + } + check = &globals.spans[span_id].channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 28093cae5d..80a3c8475e 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -813,6 +813,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) 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; } } @@ -913,6 +914,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D } 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++; } } From fabc3df7d4dfe0663cd77e45aef2235841c9996b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 21 May 2008 16:49:22 +0000 Subject: [PATCH 0929/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@481 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 18 +- libs/openzap/src/include/openzap.h | 32 +- libs/openzap/src/include/ss7_boost_client.h | 3 +- libs/openzap/src/include/zap_types.h | 30 ++ libs/openzap/src/ss7_boost_client.c | 20 +- libs/openzap/src/zap_io.c | 92 ++++- libs/openzap/src/zap_ss7_boost.c | 410 ++++++++++++++++---- 7 files changed, 505 insertions(+), 100 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index e0e4b6ac43..79d4a7b55a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -981,6 +981,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; if (!(session = switch_core_session_request(openzap_endpoint_interface, NULL))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); return ZAP_FAIL; } @@ -1045,6 +1046,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t } if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding token\n"); switch_core_session_destroy(&session); return ZAP_FAIL; } @@ -1351,11 +1353,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1364,23 +1366,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_tone_type_t tt = ZAP_TONE_DTMF; - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1388,10 +1390,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 57c87fb549..0f8fba7ecc 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -175,6 +175,7 @@ */ #define zap_test_flag(obj, flag) ((obj)->flags & flag) #define zap_test_pflag(obj, flag) ((obj)->pflags & flag) +#define zap_test_sflag(obj, flag) ((obj)->sflags & flag) #define zap_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag) @@ -198,6 +199,12 @@ (obj)->pflags |= (flag); \ zap_mutex_unlock(obj->mutex); +#define zap_set_sflag(obj, flag) (obj)->sflags |= (flag) +#define zap_set_sflag_locked(obj, flag) assert(obj->mutex != NULL); \ + zap_mutex_lock(obj->mutex); \ + (obj)->sflags |= (flag); \ + zap_mutex_unlock(obj->mutex); + /*! \brief Clear a flag on an arbitrary object while locked \command obj the object to test @@ -211,16 +218,35 @@ #define zap_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); zap_mutex_unlock(obj->mutex); +#define zap_clear_sflag(obj, flag) (obj)->sflags &= ~(flag) + +#define zap_clear_sflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->sflags &= ~(flag); zap_mutex_unlock(obj->mutex); + #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ - zap_channel_set_state(obj, s); \ + zap_channel_set_state(obj, s, 1); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } +typedef enum { + ZAP_STATE_CHANGE_FAIL, + ZAP_STATE_CHANGE_SUCCESS, + ZAP_STATE_CHANGE_SAME, +} zap_state_change_result_t; + +#define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ + } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ + int st = obj->state; \ + r = (zap_channel_set_state(obj, s, l) == ZAP_SUCCESS) ? ZAP_STATE_CHANGE_SUCCESS : ZAP_STATE_CHANGE_FAIL; \ + if (obj->state == s) {zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s));} \ + else {zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); } \ + } + #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -358,6 +384,7 @@ struct zap_channel { zap_socket_t sockfd; zap_channel_flag_t flags; uint32_t pflags; + uint32_t sflags; zap_alarm_flag_t alarm_flags; zap_channel_feature_t features; zap_codec_t effective_codec; @@ -455,6 +482,7 @@ struct zap_span { void *mod_data; char *type; int suggest_chan_id; + zap_state_map_t *state_map; }; @@ -515,7 +543,7 @@ zap_status_t zap_channel_get_alarms(zap_channel_t *zchan); zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h index d2fee452bc..4184f5385e 100644 --- a/libs/openzap/src/include/ss7_boost_client.h +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -119,7 +119,8 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon); int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); -int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event); +int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); +#define ss7bc_connection_write(_m,_e) __ss7bc_connection_write(_m, _e, __FILE__, __func__, __LINE__) void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); const char *ss7bc_event_id_name(uint32_t event_id); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 5ee75505ab..8b25e9fc07 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -66,6 +66,9 @@ struct zap_io_interface; #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 { @@ -343,6 +346,33 @@ typedef enum { ZAP_CHANNEL_ANSWERED = (1 << 23) } 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; diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index 21690506b1..75d274cfaf 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -135,9 +135,11 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) close(mcon->socket); } - zap_mutex_lock(mcon->mutex); - zap_mutex_unlock(mcon->mutex); - zap_mutex_destroy(&mcon->mutex); + 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; @@ -245,17 +247,19 @@ ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) } -int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) +int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) { int err; if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); return -EINVAL; + abort(); } if (event->span > 16 || event->chan > 31) { - zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); + abort(); return -1; } @@ -269,9 +273,10 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) if (err != sizeof(ss7bc_event_t)) { err = -1; + abort(); } - zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", ss7bc_event_id_name(event->event_id), event->event_id, event->span+1, @@ -286,6 +291,7 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) return err; } + void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id) { memset(event, 0, sizeof(ss7bc_event_t)); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 5bdb83f3df..9fa317c0e4 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -621,16 +621,69 @@ zap_status_t zap_channel_complete_state(zap_channel_t *zchan) return ZAP_SUCCESS; } - -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) +static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, zap_state_map_t *state_map) { - int ok = 1; + int x = 0, ok = 0; + zap_state_direction_t direction = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? ZSD_OUTBOUND : ZSD_INBOUND; + + for(x = 0; x < ZAP_MAP_NODE_SIZE; x++) { + int i = 0, proceed = 0; + if (!state_map->nodes[x].type) { + break; + } + + if (state_map->nodes[x].direction != direction) { + continue; + } + + if (state_map->nodes[x].check_states[0] == ZAP_ANY_STATE) { + proceed = 1; + } else { + for(i = 0; i < ZAP_MAP_MAX; i++) { + if (state_map->nodes[x].check_states[i] == zchan->state) { + proceed = 1; + break; + } + } + } + + if (!proceed) { + continue; + } + + for(i = 0; i < ZAP_MAP_MAX; i++) { + ok = (state_map->nodes[x].type == ZSM_ACCEPTABLE); + if (state_map->nodes[x].states[i] == ZAP_END) { + break; + } + if (state_map->nodes[x].states[i] == state) { + ok = !ok; + goto end; + } + } + } + end: + + return ok; +} + +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) +{ + int ok = 0; if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; } - zap_mutex_lock(zchan->mutex); + if (lock) { + zap_mutex_lock(zchan->mutex); + } + + if (zchan->span->state_map) { + ok = zap_parse_state_map(zchan, state, zchan->span->state_map); + goto end; + } + switch(zchan->state) { case ZAP_CHANNEL_STATE_HANGUP: case ZAP_CHANNEL_STATE_TERMINATING: @@ -649,6 +702,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; case ZAP_CHANNEL_STATE_UP: { + ok = 0; switch(state) { case ZAP_CHANNEL_STATE_PROGRESS: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -661,11 +715,12 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; case ZAP_CHANNEL_STATE_DOWN: { + ok = 0; + switch(state) { - case ZAP_CHANNEL_STATE_BUSY: - case ZAP_CHANNEL_STATE_HANGUP: - case ZAP_CHANNEL_STATE_TERMINATING: - ok = 0; + case ZAP_CHANNEL_STATE_DIALTONE: + case ZAP_CHANNEL_STATE_RING: + ok = 1; break; default: break; @@ -683,14 +738,28 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } } break; + case ZAP_CHANNEL_STATE_RING: + { + switch(state) { + case ZAP_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + break; default: break; } + end: + if (state == zchan->state) { ok = 0; } - + + if (ok) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->active_count++; @@ -704,7 +773,9 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta zchan->state = state; } - zap_mutex_unlock(zchan->mutex); + if (lock) { + zap_mutex_unlock(zchan->mutex); + } return ok ? ZAP_SUCCESS : ZAP_FAIL; } @@ -868,6 +939,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_init(zap_channel_t *zchan) { + if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, zchan->init_state); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 5d586e6d56..885a75f296 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -35,6 +35,11 @@ #include "ss7_boost_client.h" #include "zap_ss7_boost.h" +typedef enum { + SFLAG_FREE_REQ_ID = (1 << 0), + SFLAG_SENT_FINAL_RESPONSE = (1 << 1) +} sflag_t; + typedef uint16_t ss7_boost_request_id_t; typedef enum { @@ -51,7 +56,11 @@ typedef struct { zap_channel_t *zchan; } ss7_boost_request_t; -#define MAX_REQ_ID MAX_PENDING_CALLS +#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN + + //#define MAX_REQ_ID 5 + +static uint16_t SETUP_GRID[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN+1][ZAP_MAX_CHANNELS_PHYSICAL_SPAN+1] = {{ 0 }}; static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; @@ -60,34 +69,66 @@ static zap_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; -static void release_request_id(ss7_boost_request_id_t r) +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])) { + 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__) + +static void __release_request_id(ss7_boost_request_id_t r, const char *func, int line) { 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 ss7_boost_request_id_t next_request_id(void) +static ss7_boost_request_id_t last_req = 0; + +static ss7_boost_request_id_t __next_request_id(const char *func, int line) { - ss7_boost_request_id_t r = 0; - int ok = 0; + ss7_boost_request_id_t r = 0, i = 0; + int found=0; - while(!ok) { - zap_mutex_lock(request_mutex); - for (r = 1; r <= MAX_REQ_ID; r++) { - if (!req_map[r]) { - ok = 1; - req_map[r] = 1; - break; - } + 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 = last_req = 1; } - zap_mutex_unlock(request_mutex); - if (!ok) { - zap_sleep(5); + + 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__) static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) { @@ -104,7 +145,11 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int for 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"); + zap_log(ZAP_LOG_WARNING, "Channel %d:%d ~ %d:%d is already in use waiting for it to become available.\n", + span->channels[i].span_id, + span->channels[i].chan_id, + span->channels[i].physical_span_id, + span->channels[i].physical_chan_id); zap_mutex_unlock(signal_mutex); for (x = 0; x < 200; x++) { @@ -140,7 +185,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) zap_status_t status = ZAP_FAIL; ss7_boost_request_id_t r; ss7bc_event_t event = {0}; - int sanity = 60000; + int sanity = 5000; + ss7_boost_request_status_t st; if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); @@ -155,6 +201,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } r = next_request_id(); + if (r == 0) { + zap_log(ZAP_LOG_CRIT, "All tanks ids are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); zap_set_string(event.redirection_string, caller_data->rdnis.digits); @@ -172,11 +223,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { zap_sleep(1); - if (!--sanity) { + if (--sanity <= 0) { status = ZAP_FAIL; *zchan = NULL; goto done; } + //printf("WTF %d\n", sanity); } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { @@ -190,7 +242,19 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) done: - OUTBOUND_REQUESTS[r].status = BST_FREE; + st = OUTBOUND_REQUESTS[r].status; + OUTBOUND_REQUESTS[r].status = BST_FREE; + + if (st == BST_FAIL) { + release_request_id(r); + } else if (st != BST_READY) { + ss7bc_exec_command(&ss7_boost_data->mcon, + 0, + 0, + r, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } return status; } @@ -206,20 +270,32 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event zap_channel_t *zchan; OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + zap_mutex_lock(request_mutex); + assert(SETUP_GRID[event->span][event->chan] == 0); + SETUP_GRID[event->span][event->chan] = event->call_setup_id; + zap_mutex_unlock(request_mutex); 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); - release_request_id(event->call_setup_id); + //release_request_id(event->call_setup_id); } else { 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 = 0; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; return; } } + + 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)); + } + zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); ss7bc_exec_command(mcon, @@ -235,39 +311,79 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_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) { + goto done; + } + + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } else { - zap_log(ZAP_LOG_CRIT, "DONE CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + if (r) { + zap_set_sflag(zchan, SFLAG_FREE_REQ_ID); + return; + } + } + + done: + + if (zchan) { + zap_mutex_unlock(zchan->mutex); } + + release_request_id_span_chan(event->span, event->chan); } static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { - - if (event->call_setup_id) { - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + zap_channel_t *zchan; + if (event->call_setup_id) { ss7bc_exec_command(mcon, - event->span, - event->chan, + 0, + 0, event->call_setup_id, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); - release_request_id(event->call_setup_id); + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + return; } else { - zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { + int r = 0; assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); - zchan->caller_data.hangup_cause = event->release_cause; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CANCEL); + + zap_mutex_lock(zchan->mutex); + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_CANCEL, 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_RESPONSE); + } + + + /* nobody else will do it so we have to do it ourselves */ + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + + + } static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -275,20 +391,38 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { - zchan->caller_data.hangup_cause = event->release_cause; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - } else { - zap_log(ZAP_LOG_CRIT, "STOP CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - } - + int r = 0; + 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; + } + + 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.... */ + + if (zchan) { + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + release_request_id_span_chan(event->span, event->chan); } static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -296,8 +430,21 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { - assert(zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + int r = 0; + + if (zchan->extra_id == event->call_setup_id && zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_mutex_lock(zchan->mutex); + if (zchan->state == ZAP_CHANNEL_STATE_DOWN && zchan->init_state != ZAP_CHANNEL_STATE_UP) { + zchan->init_state = ZAP_CHANNEL_STATE_UP; + r = 1; + } else { + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_UP, 0, r); + } + zap_mutex_unlock(zchan->mutex); + } + if (!r) { + printf("WTF BAD ANSWER %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)); + } } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } @@ -314,7 +461,8 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { goto error; } - + + zchan->sflags = 0; zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); @@ -476,9 +624,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DOWN: { if (zchan->extra_id) { - release_request_id((ss7_boost_request_id_t)zchan->extra_id); zchan->extra_id = 0; } + + if (zap_test_sflag(zchan, SFLAG_FREE_REQ_ID)) { + release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1); + } + + zchan->sflags = 0; zap_channel_done(zchan); } break; @@ -557,21 +710,27 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - zchan->caller_data.hangup_cause); + if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_RESPONSE)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } else { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_START_NACK, - zchan->caller_data.hangup_cause); - } + + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + zchan->caller_data.hangup_cause); + } else { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + zchan->caller_data.hangup_cause); + } + } } break; case ZAP_CHANNEL_STATE_CANCEL: @@ -579,6 +738,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -592,12 +752,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); + } break; default: @@ -617,9 +779,11 @@ static __inline__ void check_state(zap_span_t *span) 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_clear_flag_locked((&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); } } } @@ -631,7 +795,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10, too_long = 60000; + uint32_t ms = 10;//, too_long = 60000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -657,8 +821,9 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - top: - + //top: + + init_outgoing_array(); ss7bc_exec_command(mcon, @@ -705,25 +870,26 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { parse_ss7_event(span, mcon, event); - } else goto top; + } //else goto top; } if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { parse_ss7_event(span, mcon, event); - } else goto top; + } //else goto top; } } check_state(span); mcon->hb_elapsed += ms; - +#if 0 if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); mcon->up = 0; zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); } +#endif } @@ -758,6 +924,105 @@ zap_status_t zap_ss7_boost_start(zap_span_t *span) return zap_thread_create_detached(zap_ss7_boost_run, span); } +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_END} + }, + { + ZSD_OUTBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, 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_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_RING, ZAP_END} + }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_RING, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, 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_END}, + }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_CANCEL, 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_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}, + }, + + + } +}; + zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, const char *local_ip, int local_port, const char *remote_ip, int remote_port, @@ -778,11 +1043,12 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); ss7_boost_data->mcon.cfg.remote_port = remote_port; ss7_boost_data->signal_cb = sig_cb; - + span->signal_data = ss7_boost_data; span->signal_type = ZAP_SIGTYPE_SS7BOOST; span->outgoing_call = ss7_boost_outgoing_call; span->channel_request = ss7_boost_channel_request; + span->state_map = &boost_state_map; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); return ZAP_SUCCESS; From 219812a90f02b688b9542910f8fcbdb88a2f5f3b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 21 May 2008 16:49:22 +0000 Subject: [PATCH 0930/1766] sync git-svn-id: http://svn.openzap.org/svn/openzap/trunk@481 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 18 +- libs/freetdm/src/include/openzap.h | 32 +- libs/freetdm/src/include/ss7_boost_client.h | 3 +- libs/freetdm/src/include/zap_types.h | 30 ++ libs/freetdm/src/ss7_boost_client.c | 20 +- libs/freetdm/src/zap_io.c | 92 ++++- libs/freetdm/src/zap_ss7_boost.c | 410 ++++++++++++++++---- 7 files changed, 505 insertions(+), 100 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index e0e4b6ac43..79d4a7b55a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -981,6 +981,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; if (!(session = switch_core_session_request(openzap_endpoint_interface, NULL))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); return ZAP_FAIL; } @@ -1045,6 +1046,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t } if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding token\n"); switch_core_session_destroy(&session); return ZAP_FAIL; } @@ -1351,11 +1353,11 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1364,23 +1366,23 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_tone_type_t tt = ZAP_TONE_DTMF; - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1388,10 +1390,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); + //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); - switch_core_session_signal_unlock(session); + //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 57c87fb549..0f8fba7ecc 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -175,6 +175,7 @@ */ #define zap_test_flag(obj, flag) ((obj)->flags & flag) #define zap_test_pflag(obj, flag) ((obj)->pflags & flag) +#define zap_test_sflag(obj, flag) ((obj)->sflags & flag) #define zap_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag) @@ -198,6 +199,12 @@ (obj)->pflags |= (flag); \ zap_mutex_unlock(obj->mutex); +#define zap_set_sflag(obj, flag) (obj)->sflags |= (flag) +#define zap_set_sflag_locked(obj, flag) assert(obj->mutex != NULL); \ + zap_mutex_lock(obj->mutex); \ + (obj)->sflags |= (flag); \ + zap_mutex_unlock(obj->mutex); + /*! \brief Clear a flag on an arbitrary object while locked \command obj the object to test @@ -211,16 +218,35 @@ #define zap_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); zap_mutex_unlock(obj->mutex); +#define zap_clear_sflag(obj, flag) (obj)->sflags &= ~(flag) + +#define zap_clear_sflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->sflags &= ~(flag); zap_mutex_unlock(obj->mutex); + #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ - zap_channel_set_state(obj, s); \ + zap_channel_set_state(obj, s, 1); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } +typedef enum { + ZAP_STATE_CHANGE_FAIL, + ZAP_STATE_CHANGE_SUCCESS, + ZAP_STATE_CHANGE_SAME, +} zap_state_change_result_t; + +#define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ + zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ + } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ + int st = obj->state; \ + r = (zap_channel_set_state(obj, s, l) == ZAP_SUCCESS) ? ZAP_STATE_CHANGE_SUCCESS : ZAP_STATE_CHANGE_FAIL; \ + if (obj->state == s) {zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s));} \ + else {zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); } \ + } + #define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) @@ -358,6 +384,7 @@ struct zap_channel { zap_socket_t sockfd; zap_channel_flag_t flags; uint32_t pflags; + uint32_t sflags; zap_alarm_flag_t alarm_flags; zap_channel_feature_t features; zap_codec_t effective_codec; @@ -455,6 +482,7 @@ struct zap_span { void *mod_data; char *type; int suggest_chan_id; + zap_state_map_t *state_map; }; @@ -515,7 +543,7 @@ zap_status_t zap_channel_get_alarms(zap_channel_t *zchan); zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state); +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h index d2fee452bc..4184f5385e 100644 --- a/libs/freetdm/src/include/ss7_boost_client.h +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -119,7 +119,8 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon); int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); -int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event); +int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); +#define ss7bc_connection_write(_m,_e) __ss7bc_connection_write(_m, _e, __FILE__, __func__, __LINE__) void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); const char *ss7bc_event_id_name(uint32_t event_id); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 5ee75505ab..8b25e9fc07 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -66,6 +66,9 @@ struct zap_io_interface; #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 { @@ -343,6 +346,33 @@ typedef enum { ZAP_CHANNEL_ANSWERED = (1 << 23) } 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; diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index 21690506b1..75d274cfaf 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -135,9 +135,11 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) close(mcon->socket); } - zap_mutex_lock(mcon->mutex); - zap_mutex_unlock(mcon->mutex); - zap_mutex_destroy(&mcon->mutex); + 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; @@ -245,17 +247,19 @@ ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) } -int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) +int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) { int err; if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); return -EINVAL; + abort(); } if (event->span > 16 || event->chan > 31) { - zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); + abort(); return -1; } @@ -269,9 +273,10 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) if (err != sizeof(ss7bc_event_t)) { err = -1; + abort(); } - zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", ss7bc_event_id_name(event->event_id), event->event_id, event->span+1, @@ -286,6 +291,7 @@ int ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event) return err; } + void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id) { memset(event, 0, sizeof(ss7bc_event_t)); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5bdb83f3df..9fa317c0e4 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -621,16 +621,69 @@ zap_status_t zap_channel_complete_state(zap_channel_t *zchan) return ZAP_SUCCESS; } - -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state) +static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, zap_state_map_t *state_map) { - int ok = 1; + int x = 0, ok = 0; + zap_state_direction_t direction = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? ZSD_OUTBOUND : ZSD_INBOUND; + + for(x = 0; x < ZAP_MAP_NODE_SIZE; x++) { + int i = 0, proceed = 0; + if (!state_map->nodes[x].type) { + break; + } + + if (state_map->nodes[x].direction != direction) { + continue; + } + + if (state_map->nodes[x].check_states[0] == ZAP_ANY_STATE) { + proceed = 1; + } else { + for(i = 0; i < ZAP_MAP_MAX; i++) { + if (state_map->nodes[x].check_states[i] == zchan->state) { + proceed = 1; + break; + } + } + } + + if (!proceed) { + continue; + } + + for(i = 0; i < ZAP_MAP_MAX; i++) { + ok = (state_map->nodes[x].type == ZSM_ACCEPTABLE); + if (state_map->nodes[x].states[i] == ZAP_END) { + break; + } + if (state_map->nodes[x].states[i] == state) { + ok = !ok; + goto end; + } + } + } + end: + + return ok; +} + +zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) +{ + int ok = 0; if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; } - zap_mutex_lock(zchan->mutex); + if (lock) { + zap_mutex_lock(zchan->mutex); + } + + if (zchan->span->state_map) { + ok = zap_parse_state_map(zchan, state, zchan->span->state_map); + goto end; + } + switch(zchan->state) { case ZAP_CHANNEL_STATE_HANGUP: case ZAP_CHANNEL_STATE_TERMINATING: @@ -649,6 +702,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; case ZAP_CHANNEL_STATE_UP: { + ok = 0; switch(state) { case ZAP_CHANNEL_STATE_PROGRESS: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -661,11 +715,12 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; case ZAP_CHANNEL_STATE_DOWN: { + ok = 0; + switch(state) { - case ZAP_CHANNEL_STATE_BUSY: - case ZAP_CHANNEL_STATE_HANGUP: - case ZAP_CHANNEL_STATE_TERMINATING: - ok = 0; + case ZAP_CHANNEL_STATE_DIALTONE: + case ZAP_CHANNEL_STATE_RING: + ok = 1; break; default: break; @@ -683,14 +738,28 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta } } break; + case ZAP_CHANNEL_STATE_RING: + { + switch(state) { + case ZAP_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + break; default: break; } + end: + if (state == zchan->state) { ok = 0; } - + + if (ok) { if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { zchan->span->active_count++; @@ -704,7 +773,9 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta zchan->state = state; } - zap_mutex_unlock(zchan->mutex); + if (lock) { + zap_mutex_unlock(zchan->mutex); + } return ok ? ZAP_SUCCESS : ZAP_FAIL; } @@ -868,6 +939,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_status_t zap_channel_init(zap_channel_t *zchan) { + if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, zchan->init_state); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 5d586e6d56..885a75f296 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -35,6 +35,11 @@ #include "ss7_boost_client.h" #include "zap_ss7_boost.h" +typedef enum { + SFLAG_FREE_REQ_ID = (1 << 0), + SFLAG_SENT_FINAL_RESPONSE = (1 << 1) +} sflag_t; + typedef uint16_t ss7_boost_request_id_t; typedef enum { @@ -51,7 +56,11 @@ typedef struct { zap_channel_t *zchan; } ss7_boost_request_t; -#define MAX_REQ_ID MAX_PENDING_CALLS +#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN + + //#define MAX_REQ_ID 5 + +static uint16_t SETUP_GRID[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN+1][ZAP_MAX_CHANNELS_PHYSICAL_SPAN+1] = {{ 0 }}; static ss7_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; @@ -60,34 +69,66 @@ static zap_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; -static void release_request_id(ss7_boost_request_id_t r) +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])) { + 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__) + +static void __release_request_id(ss7_boost_request_id_t r, const char *func, int line) { 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 ss7_boost_request_id_t next_request_id(void) +static ss7_boost_request_id_t last_req = 0; + +static ss7_boost_request_id_t __next_request_id(const char *func, int line) { - ss7_boost_request_id_t r = 0; - int ok = 0; + ss7_boost_request_id_t r = 0, i = 0; + int found=0; - while(!ok) { - zap_mutex_lock(request_mutex); - for (r = 1; r <= MAX_REQ_ID; r++) { - if (!req_map[r]) { - ok = 1; - req_map[r] = 1; - break; - } + 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 = last_req = 1; } - zap_mutex_unlock(request_mutex); - if (!ok) { - zap_sleep(5); + + 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__) static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) { @@ -104,7 +145,11 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int for 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"); + zap_log(ZAP_LOG_WARNING, "Channel %d:%d ~ %d:%d is already in use waiting for it to become available.\n", + span->channels[i].span_id, + span->channels[i].chan_id, + span->channels[i].physical_span_id, + span->channels[i].physical_chan_id); zap_mutex_unlock(signal_mutex); for (x = 0; x < 200; x++) { @@ -140,7 +185,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) zap_status_t status = ZAP_FAIL; ss7_boost_request_id_t r; ss7bc_event_t event = {0}; - int sanity = 60000; + int sanity = 5000; + ss7_boost_request_status_t st; if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); @@ -155,6 +201,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } r = next_request_id(); + if (r == 0) { + zap_log(ZAP_LOG_CRIT, "All tanks ids are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); zap_set_string(event.redirection_string, caller_data->rdnis.digits); @@ -172,11 +223,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { zap_sleep(1); - if (!--sanity) { + if (--sanity <= 0) { status = ZAP_FAIL; *zchan = NULL; goto done; } + //printf("WTF %d\n", sanity); } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { @@ -190,7 +242,19 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) done: - OUTBOUND_REQUESTS[r].status = BST_FREE; + st = OUTBOUND_REQUESTS[r].status; + OUTBOUND_REQUESTS[r].status = BST_FREE; + + if (st == BST_FAIL) { + release_request_id(r); + } else if (st != BST_READY) { + ss7bc_exec_command(&ss7_boost_data->mcon, + 0, + 0, + r, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } return status; } @@ -206,20 +270,32 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event zap_channel_t *zchan; OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + zap_mutex_lock(request_mutex); + assert(SETUP_GRID[event->span][event->chan] == 0); + SETUP_GRID[event->span][event->chan] = event->call_setup_id; + zap_mutex_unlock(request_mutex); 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); - release_request_id(event->call_setup_id); + //release_request_id(event->call_setup_id); } else { 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 = 0; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; return; } } + + 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)); + } + zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); ss7bc_exec_command(mcon, @@ -235,39 +311,79 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_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) { + goto done; + } + + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } else { - zap_log(ZAP_LOG_CRIT, "DONE CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + if (r) { + zap_set_sflag(zchan, SFLAG_FREE_REQ_ID); + return; + } + } + + done: + + if (zchan) { + zap_mutex_unlock(zchan->mutex); } + + release_request_id_span_chan(event->span, event->chan); } static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { - - if (event->call_setup_id) { - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + zap_channel_t *zchan; + if (event->call_setup_id) { ss7bc_exec_command(mcon, - event->span, - event->chan, + 0, + 0, event->call_setup_id, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); - release_request_id(event->call_setup_id); + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + return; } else { - zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { + int r = 0; assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); - zchan->caller_data.hangup_cause = event->release_cause; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CANCEL); + + zap_mutex_lock(zchan->mutex); + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_CANCEL, 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_RESPONSE); + } + + + /* nobody else will do it so we have to do it ourselves */ + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0); + + + } static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -275,20 +391,38 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { - zchan->caller_data.hangup_cause = event->release_cause; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); - } else { - zap_log(ZAP_LOG_CRIT, "STOP CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - ss7bc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - } - + int r = 0; + 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; + } + + 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.... */ + + if (zchan) { + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + } + + ss7bc_exec_command(mcon, + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + release_request_id_span_chan(event->span, event->chan); } static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) @@ -296,8 +430,21 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { - assert(zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + int r = 0; + + if (zchan->extra_id == event->call_setup_id && zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_mutex_lock(zchan->mutex); + if (zchan->state == ZAP_CHANNEL_STATE_DOWN && zchan->init_state != ZAP_CHANNEL_STATE_UP) { + zchan->init_state = ZAP_CHANNEL_STATE_UP; + r = 1; + } else { + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_UP, 0, r); + } + zap_mutex_unlock(zchan->mutex); + } + if (!r) { + printf("WTF BAD ANSWER %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)); + } } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } @@ -314,7 +461,8 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { goto error; } - + + zchan->sflags = 0; zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); @@ -476,9 +624,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DOWN: { if (zchan->extra_id) { - release_request_id((ss7_boost_request_id_t)zchan->extra_id); zchan->extra_id = 0; } + + if (zap_test_sflag(zchan, SFLAG_FREE_REQ_ID)) { + release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1); + } + + zchan->sflags = 0; zap_channel_done(zchan); } break; @@ -557,21 +710,27 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_STOPPED, - zchan->caller_data.hangup_cause); + if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_RESPONSE)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } else { - ss7bc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_START_NACK, - zchan->caller_data.hangup_cause); - } + + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED, + zchan->caller_data.hangup_cause); + } else { + ss7bc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + zchan->caller_data.hangup_cause); + } + } } break; case ZAP_CHANNEL_STATE_CANCEL: @@ -579,6 +738,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -592,12 +752,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); ss7bc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); + } break; default: @@ -617,9 +779,11 @@ static __inline__ void check_state(zap_span_t *span) 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_clear_flag_locked((&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); } } } @@ -631,7 +795,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10, too_long = 60000; + uint32_t ms = 10;//, too_long = 60000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -657,8 +821,9 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - top: - + //top: + + init_outgoing_array(); ss7bc_exec_command(mcon, @@ -705,25 +870,26 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { parse_ss7_event(span, mcon, event); - } else goto top; + } //else goto top; } if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { parse_ss7_event(span, mcon, event); - } else goto top; + } //else goto top; } } check_state(span); mcon->hb_elapsed += ms; - +#if 0 if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); mcon->up = 0; zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); } +#endif } @@ -758,6 +924,105 @@ zap_status_t zap_ss7_boost_start(zap_span_t *span) return zap_thread_create_detached(zap_ss7_boost_run, span); } +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_END} + }, + { + ZSD_OUTBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, 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_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_RING, ZAP_END} + }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_RING, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, 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_END}, + }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_CANCEL, 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_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}, + }, + + + } +}; + zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, const char *local_ip, int local_port, const char *remote_ip, int remote_port, @@ -778,11 +1043,12 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); ss7_boost_data->mcon.cfg.remote_port = remote_port; ss7_boost_data->signal_cb = sig_cb; - + span->signal_data = ss7_boost_data; span->signal_type = ZAP_SIGTYPE_SS7BOOST; span->outgoing_call = ss7_boost_outgoing_call; span->channel_request = ss7_boost_channel_request; + span->state_map = &boost_state_map; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); return ZAP_SUCCESS; From 7813d6a46c2e9bfe915fb6d7f3a3c250dc926d44 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 May 2008 18:58:14 +0000 Subject: [PATCH 0931/1766] add strict state parsing and configurable suggest mode git-svn-id: http://svn.openzap.org/svn/openzap/trunk@482 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 7 +- libs/openzap/src/include/openzap.h | 13 -- libs/openzap/src/include/zap_isdn.h | 23 ++- libs/openzap/src/testisdn.c | 2 +- libs/openzap/src/zap_isdn.c | 248 +++++++++++++++++++++---- 5 files changed, 243 insertions(+), 50 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 79d4a7b55a..24d093f49e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1593,7 +1593,8 @@ static switch_status_t load_config(void) uint32_t span_id = 0; zap_span_t *span = NULL; char *tonegroup = NULL; - + zap_isdn_opts_t opts = ZAP_ISDN_OPT_NONE; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1609,6 +1610,8 @@ static switch_status_t load_config(void) } } else if (!strcasecmp(var, "context")) { context = val; + } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { + opts |= ZAP_ISDN_OPT_SUGGEST_CHANNEL; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } @@ -1630,7 +1633,7 @@ static switch_status_t load_config(void) continue; } - if (zap_isdn_configure_span(span, mode, dialect, on_clear_channel_signal) != ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, mode, dialect, opts, on_clear_channel_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 0f8fba7ecc..e8ee4fe890 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -438,19 +438,6 @@ struct zap_sigmsg { }; -struct zap_isdn_data { - Q921Data_t q921; - Q931_TrunkInfo_t q931; - zap_channel_t *dchan; - zap_channel_t *dchans[2]; - struct zap_sigmsg sigmsg; - zio_signal_cb_t sig_cb; - uint32_t flags; - zap_caller_data_t *outbound_crv[32768]; - zap_channel_t *channels_local_crv[32768]; - zap_channel_t *channels_remote_crv[32768]; -}; - struct zap_analog_data { uint32_t flags; uint32_t max_dialstr; diff --git a/libs/openzap/src/include/zap_isdn.h b/libs/openzap/src/include/zap_isdn.h index 0aea34973d..91f35b2a9b 100644 --- a/libs/openzap/src/include/zap_isdn.h +++ b/libs/openzap/src/include/zap_isdn.h @@ -35,16 +35,37 @@ #define ZAP_ISDN_H #include "openzap.h" +typedef enum { + ZAP_ISDN_OPT_NONE = 0, + ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0) +} zap_isdn_opts_t; + typedef enum { ZAP_ISDN_RUNNING = (1 << 0) } 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; + zio_signal_cb_t sig_cb; + uint32_t flags; + zap_caller_data_t *outbound_crv[32768]; + zap_channel_t *channels_local_crv[32768]; + zap_channel_t *channels_remote_crv[32768]; + zap_isdn_opts_t opts; +}; + + + typedef struct zap_isdn_data zap_isdn_data_t; zap_status_t zap_isdn_start(zap_span_t *span); zap_status_t zap_isdn_init(void); -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb); +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb); #endif diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 79771489f1..88cc113717 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) } - if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, on_signal) == ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) { data = span->signal_data; zap_isdn_start(span); } else { diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 80a3c8475e..f6f254627a 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -52,6 +52,7 @@ static L2ULONG zap_time_now(void) 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; } @@ -85,37 +86,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) BearerCap.ITR = 16; /* 64k */ BearerCap.Layer1Ident = 1; BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ -#if 0 - BearerCap.SyncAsync = ; - BearerCap.Negot = ; - BearerCap.UserRate = ; - BearerCap.InterRate = ; - BearerCap.NIConTx = ; - BearerCap.FlowCtlTx = ; - BearerCap.HDR = ; - BearerCap.MultiFrame = ; - BearerCap.Mode = ; - BearerCap.LLInegot = ; - BearerCap.Assignor = ; - BearerCap.InBandNeg = ; - BearerCap.NumStopBits = ; - BearerCap.NumDataBits = ; - BearerCap.Parity = ; - BearerCap.DuplexMode = ; - BearerCap.ModemType = ; - BearerCap.Layer2Ident = ; - BearerCap.UIL2Prot = ; - BearerCap.Layer3Ident = ; - BearerCap.UIL3Prot = ; - BearerCap.AL3Info1 = ; - BearerCap.AL3Info2 = ; -#endif gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); - //is cast right here? ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.PrefExcl = 0; /* 0 = preferred, 1 exclusive */ + ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */ ChanID.InfoChanSel = 1; ChanID.ChanMapType = 3; /* B-Chan */ ChanID.ChanSlot = chan_id; @@ -230,7 +205,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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; @@ -400,7 +376,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } else { zap_log(ZAP_LOG_DEBUG, "Ignoring %s on channel %d\n", what, chan_id); } @@ -660,8 +636,102 @@ static __inline__ void state_advance(zap_channel_t *zchan) } 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; + + Q931InitIEBearerCap(&BearerCap); + Q931InitIEChanID(&ChanID); + Q931InitIECallingNum(&CallingNum); + Q931InitIECalledNum(&CalledNum); + Q931InitIEDisplay(&Display); + Q931InitMesGeneric(gen); + gen->MesType = Q931mes_SETUP; + + BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ + BearerCap.ITC = 0; /* Speech */ + BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ + BearerCap.ITR = 16; /* 64k */ + BearerCap.Layer1Ident = 1; + BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + + //is cast right here? + ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ + ChanID.InfoChanSel = 1; + ChanID.ChanMapType = 3; /* B-Chan */ + ChanID.ChanSlot = (unsigned char)zchan->chan_id; + gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); + + 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); + + /* TypNum: Type of number*/ + /* Bits 7 6 5*/ + /* 000Unknown*/ + /* 001International number*/ + /* 010National number*/ + /* 011Network Specific number */ + /* 100Subscriber mumber*/ + /* 110Abbreviated number*/ + /* 111Reserved for extension*/ + /* All other values are reserved */ + CallingNum.TypNum = 2; + + /* NumPlanID*/ + /* Bits 4 3 2 1*/ + /* 0000Unknown*/ + /* 0001ISDN/telephony numbering plan (E.164)*/ + /* 0011Data numbering plan (X.121)*/ + /* 0100Telex numbering plan (F.69)*/ + /* 1000National standard numbering plan*/ + /* 1001Private numbering plan*/ + /* 1111Reserved for extension*/ + /* All other valures are reserved*/ + CallingNum.NumPlanID = 1; + + /* Presentation indicator*/ + /* Bits 7 6*/ + /* 00Presenation Allowed*/ + /* 01Presentation Restricted*/ + /* 10Number not available due to internetworking*/ + /* 11Reserved*/ + CallingNum.PresInd = 0; + + /* Screening Indicator*/ + /* Bits 2 1*/ + /* 00User-provided, not screened*/ + /* 01User-provided, verified and passed*/ + /* 10User-provided, verified and failed*/ + /* 11Network provided*/ + CallingNum.ScreenInd = 0; + 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.TypNum = 2; + CalledNum.NumPlanID = 1; + 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); + + Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); + isdn_data->channels_local_crv[gen->CRV] = zchan; + } + break; + case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -891,7 +961,113 @@ static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen) return ret; } -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) + +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_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_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_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_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_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}, + }, + + + } +}; + +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb) { uint32_t i, x = 0; zap_channel_t *dchans[2] = {0}; @@ -962,8 +1138,14 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - span->channel_request = isdn_channel_request; - span->suggest_chan_id = 1; + isdn_data->opts = opts; + + if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { + span->channel_request = isdn_channel_request; + span->suggest_chan_id = 1; + } + span->state_map = &isdn_state_map; + return ZAP_SUCCESS; } From b015d7b8d3cff72d9ba1b467f12a308633e2c081 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 21 May 2008 18:58:14 +0000 Subject: [PATCH 0932/1766] add strict state parsing and configurable suggest mode git-svn-id: http://svn.openzap.org/svn/openzap/trunk@482 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 7 +- libs/freetdm/src/include/openzap.h | 13 -- libs/freetdm/src/include/zap_isdn.h | 23 ++- libs/freetdm/src/testisdn.c | 2 +- libs/freetdm/src/zap_isdn.c | 248 +++++++++++++++++++++---- 5 files changed, 243 insertions(+), 50 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 79d4a7b55a..24d093f49e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1593,7 +1593,8 @@ static switch_status_t load_config(void) uint32_t span_id = 0; zap_span_t *span = NULL; char *tonegroup = NULL; - + zap_isdn_opts_t opts = ZAP_ISDN_OPT_NONE; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1609,6 +1610,8 @@ static switch_status_t load_config(void) } } else if (!strcasecmp(var, "context")) { context = val; + } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { + opts |= ZAP_ISDN_OPT_SUGGEST_CHANNEL; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } @@ -1630,7 +1633,7 @@ static switch_status_t load_config(void) continue; } - if (zap_isdn_configure_span(span, mode, dialect, on_clear_channel_signal) != ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, mode, dialect, opts, on_clear_channel_signal) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 0f8fba7ecc..e8ee4fe890 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -438,19 +438,6 @@ struct zap_sigmsg { }; -struct zap_isdn_data { - Q921Data_t q921; - Q931_TrunkInfo_t q931; - zap_channel_t *dchan; - zap_channel_t *dchans[2]; - struct zap_sigmsg sigmsg; - zio_signal_cb_t sig_cb; - uint32_t flags; - zap_caller_data_t *outbound_crv[32768]; - zap_channel_t *channels_local_crv[32768]; - zap_channel_t *channels_remote_crv[32768]; -}; - struct zap_analog_data { uint32_t flags; uint32_t max_dialstr; diff --git a/libs/freetdm/src/include/zap_isdn.h b/libs/freetdm/src/include/zap_isdn.h index 0aea34973d..91f35b2a9b 100644 --- a/libs/freetdm/src/include/zap_isdn.h +++ b/libs/freetdm/src/include/zap_isdn.h @@ -35,16 +35,37 @@ #define ZAP_ISDN_H #include "openzap.h" +typedef enum { + ZAP_ISDN_OPT_NONE = 0, + ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0) +} zap_isdn_opts_t; + typedef enum { ZAP_ISDN_RUNNING = (1 << 0) } 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; + zio_signal_cb_t sig_cb; + uint32_t flags; + zap_caller_data_t *outbound_crv[32768]; + zap_channel_t *channels_local_crv[32768]; + zap_channel_t *channels_remote_crv[32768]; + zap_isdn_opts_t opts; +}; + + + typedef struct zap_isdn_data zap_isdn_data_t; zap_status_t zap_isdn_start(zap_span_t *span); zap_status_t zap_isdn_init(void); -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb); +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb); #endif diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 79771489f1..88cc113717 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) } - if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, on_signal) == ZAP_SUCCESS) { + if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) { data = span->signal_data; zap_isdn_start(span); } else { diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 80a3c8475e..f6f254627a 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -52,6 +52,7 @@ static L2ULONG zap_time_now(void) 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; } @@ -85,37 +86,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) BearerCap.ITR = 16; /* 64k */ BearerCap.Layer1Ident = 1; BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ -#if 0 - BearerCap.SyncAsync = ; - BearerCap.Negot = ; - BearerCap.UserRate = ; - BearerCap.InterRate = ; - BearerCap.NIConTx = ; - BearerCap.FlowCtlTx = ; - BearerCap.HDR = ; - BearerCap.MultiFrame = ; - BearerCap.Mode = ; - BearerCap.LLInegot = ; - BearerCap.Assignor = ; - BearerCap.InBandNeg = ; - BearerCap.NumStopBits = ; - BearerCap.NumDataBits = ; - BearerCap.Parity = ; - BearerCap.DuplexMode = ; - BearerCap.ModemType = ; - BearerCap.Layer2Ident = ; - BearerCap.UIL2Prot = ; - BearerCap.Layer3Ident = ; - BearerCap.UIL3Prot = ; - BearerCap.AL3Info1 = ; - BearerCap.AL3Info2 = ; -#endif gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); - //is cast right here? ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.PrefExcl = 0; /* 0 = preferred, 1 exclusive */ + ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */ ChanID.InfoChanSel = 1; ChanID.ChanMapType = 3; /* B-Chan */ ChanID.ChanSlot = chan_id; @@ -230,7 +205,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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; @@ -400,7 +376,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } else { zap_log(ZAP_LOG_DEBUG, "Ignoring %s on channel %d\n", what, chan_id); } @@ -660,8 +636,102 @@ static __inline__ void state_advance(zap_channel_t *zchan) } 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; + + Q931InitIEBearerCap(&BearerCap); + Q931InitIEChanID(&ChanID); + Q931InitIECallingNum(&CallingNum); + Q931InitIECalledNum(&CalledNum); + Q931InitIEDisplay(&Display); + Q931InitMesGeneric(gen); + gen->MesType = Q931mes_SETUP; + + BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ + BearerCap.ITC = 0; /* Speech */ + BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ + BearerCap.ITR = 16; /* 64k */ + BearerCap.Layer1Ident = 1; + BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/ + gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); + + //is cast right here? + ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ + ChanID.InfoChanSel = 1; + ChanID.ChanMapType = 3; /* B-Chan */ + ChanID.ChanSlot = (unsigned char)zchan->chan_id; + gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); + + 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); + + /* TypNum: Type of number*/ + /* Bits 7 6 5*/ + /* 000Unknown*/ + /* 001International number*/ + /* 010National number*/ + /* 011Network Specific number */ + /* 100Subscriber mumber*/ + /* 110Abbreviated number*/ + /* 111Reserved for extension*/ + /* All other values are reserved */ + CallingNum.TypNum = 2; + + /* NumPlanID*/ + /* Bits 4 3 2 1*/ + /* 0000Unknown*/ + /* 0001ISDN/telephony numbering plan (E.164)*/ + /* 0011Data numbering plan (X.121)*/ + /* 0100Telex numbering plan (F.69)*/ + /* 1000National standard numbering plan*/ + /* 1001Private numbering plan*/ + /* 1111Reserved for extension*/ + /* All other valures are reserved*/ + CallingNum.NumPlanID = 1; + + /* Presentation indicator*/ + /* Bits 7 6*/ + /* 00Presenation Allowed*/ + /* 01Presentation Restricted*/ + /* 10Number not available due to internetworking*/ + /* 11Reserved*/ + CallingNum.PresInd = 0; + + /* Screening Indicator*/ + /* Bits 2 1*/ + /* 00User-provided, not screened*/ + /* 01User-provided, verified and passed*/ + /* 10User-provided, verified and failed*/ + /* 11Network provided*/ + CallingNum.ScreenInd = 0; + 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.TypNum = 2; + CalledNum.NumPlanID = 1; + 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); + + Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); + isdn_data->channels_local_crv[gen->CRV] = zchan; + } + break; + case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; case ZAP_CHANNEL_STATE_HANGUP: @@ -891,7 +961,113 @@ static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen) return ret; } -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zio_signal_cb_t sig_cb) + +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_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_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_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_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_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}, + }, + + + } +}; + +zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb) { uint32_t i, x = 0; zap_channel_t *dchans[2] = {0}; @@ -962,8 +1138,14 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - span->channel_request = isdn_channel_request; - span->suggest_chan_id = 1; + isdn_data->opts = opts; + + if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { + span->channel_request = isdn_channel_request; + span->suggest_chan_id = 1; + } + span->state_map = &isdn_state_map; + return ZAP_SUCCESS; } From dba966a948760af855fad5a90caf4c8510d21bed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 May 2008 21:50:07 +0000 Subject: [PATCH 0933/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@483 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_ss7_boost.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 885a75f296..30979daefb 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -68,6 +68,7 @@ static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; +static uint8_t nack_map[MAX_REQ_ID+1] = { 0 }; static void __release_request_id_span_chan(int span, int chan, const char *func, int line) { @@ -75,6 +76,7 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, 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; } @@ -84,6 +86,7 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, static void __release_request_id(ss7_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); @@ -248,6 +251,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) if (st == BST_FAIL) { release_request_id(r); } else if (st != BST_READY) { + assert(r <= MAX_REQ_ID); + nack_map[r] = 1; ss7bc_exec_command(&ss7_boost_data->mcon, 0, 0, @@ -269,16 +274,16 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event { zap_channel_t *zchan; + if (nack_map[event->call_setup_id]) { + return; + } + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - zap_mutex_lock(request_mutex); - assert(SETUP_GRID[event->span][event->chan] == 0); SETUP_GRID[event->span][event->chan] = event->call_setup_id; - zap_mutex_unlock(request_mutex); 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); - //release_request_id(event->call_setup_id); } else { zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); @@ -324,6 +329,7 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e if (r) { zap_set_sflag(zchan, SFLAG_FREE_REQ_ID); + zap_mutex_unlock(zchan->mutex); return; } } @@ -556,6 +562,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve ); + assert(event->call_setup_id <= MAX_REQ_ID); switch(event->event_id) { @@ -578,8 +585,11 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve 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(event); @@ -751,7 +761,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); ss7bc_exec_command(mcon, zchan->physical_span_id-1, @@ -1010,7 +1020,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_UP, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}, }, { ZSD_INBOUND, From 0fed9a582c2a3a43941afbd4540755fe54871cf3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 May 2008 21:50:07 +0000 Subject: [PATCH 0934/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@483 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_ss7_boost.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 885a75f296..30979daefb 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -68,6 +68,7 @@ static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; +static uint8_t nack_map[MAX_REQ_ID+1] = { 0 }; static void __release_request_id_span_chan(int span, int chan, const char *func, int line) { @@ -75,6 +76,7 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, 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; } @@ -84,6 +86,7 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, static void __release_request_id(ss7_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); @@ -248,6 +251,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) if (st == BST_FAIL) { release_request_id(r); } else if (st != BST_READY) { + assert(r <= MAX_REQ_ID); + nack_map[r] = 1; ss7bc_exec_command(&ss7_boost_data->mcon, 0, 0, @@ -269,16 +274,16 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event { zap_channel_t *zchan; + if (nack_map[event->call_setup_id]) { + return; + } + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - zap_mutex_lock(request_mutex); - assert(SETUP_GRID[event->span][event->chan] == 0); SETUP_GRID[event->span][event->chan] = event->call_setup_id; - zap_mutex_unlock(request_mutex); 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); - //release_request_id(event->call_setup_id); } else { zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); @@ -324,6 +329,7 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e if (r) { zap_set_sflag(zchan, SFLAG_FREE_REQ_ID); + zap_mutex_unlock(zchan->mutex); return; } } @@ -556,6 +562,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve ); + assert(event->call_setup_id <= MAX_REQ_ID); switch(event->event_id) { @@ -578,8 +585,11 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve 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(event); @@ -751,7 +761,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { sig.event_id = ZAP_SIGEVENT_STOP; status = ss7_boost_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); ss7bc_exec_command(mcon, zchan->physical_span_id-1, @@ -1010,7 +1020,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_UP, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}, }, { ZSD_INBOUND, From 4f7c97ef350737ced07337b116544363961a6661 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 26 May 2008 01:51:11 +0000 Subject: [PATCH 0935/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@484 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 1 + libs/openzap/src/zap_isdn.c | 11 ++++------- libs/openzap/src/zap_ss7_boost.c | 6 ++++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 24d093f49e..318ed6e4a9 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1351,6 +1351,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) } break; case ZAP_SIGEVENT_STOP: + case ZAP_SIGEVENT_RESTART: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { //switch_core_session_signal_lock(session); diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index f6f254627a..c0811fb9dd 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -599,13 +599,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } else { - sig.event_id = ZAP_SIGEVENT_RESTART; - status = isdn_data->sig_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED; + sig.event_id = ZAP_SIGEVENT_RESTART; + status = isdn_data->sig_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 30979daefb..17a2cd7ed7 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -296,9 +296,9 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } } - printf("WTF BAD ACK CSid=%d span=%d chan=%d\n", event->call_setup_id, event->span+1,event->chan+1); + //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)); + //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)); } @@ -448,9 +448,11 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc } zap_mutex_unlock(zchan->mutex); } +#if 0 if (!r) { printf("WTF BAD ANSWER %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)); } +#endif } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } From c0d5af780403cfb92a29087b3fae0bf22e424235 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 26 May 2008 01:51:11 +0000 Subject: [PATCH 0936/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@484 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 1 + libs/freetdm/src/zap_isdn.c | 11 ++++------- libs/freetdm/src/zap_ss7_boost.c | 6 ++++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 24d093f49e..318ed6e4a9 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1351,6 +1351,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) } break; case ZAP_SIGEVENT_STOP: + case ZAP_SIGEVENT_RESTART: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { //switch_core_session_signal_lock(session); diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index f6f254627a..c0811fb9dd 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -599,13 +599,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } else { - sig.event_id = ZAP_SIGEVENT_RESTART; - status = isdn_data->sig_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED; + sig.event_id = ZAP_SIGEVENT_RESTART; + status = isdn_data->sig_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 30979daefb..17a2cd7ed7 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -296,9 +296,9 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } } - printf("WTF BAD ACK CSid=%d span=%d chan=%d\n", event->call_setup_id, event->span+1,event->chan+1); + //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)); + //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)); } @@ -448,9 +448,11 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc } zap_mutex_unlock(zchan->mutex); } +#if 0 if (!r) { printf("WTF BAD ANSWER %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)); } +#endif } else { zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } From 8167c5b41cf2f70d30ab96274f4067e2426e894c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 26 May 2008 18:58:28 +0000 Subject: [PATCH 0937/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@485 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 9fa317c0e4..2f6d7afd5e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -669,7 +669,7 @@ static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) { - int ok = 0; + int ok = 1; if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; From 3eb33ba8de87695b015717fa737704a7074cdde9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 26 May 2008 18:58:28 +0000 Subject: [PATCH 0938/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@485 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 9fa317c0e4..2f6d7afd5e 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -669,7 +669,7 @@ static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) { - int ok = 0; + int ok = 1; if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; From c2419bc6a4644a815ddbbca8aa8b16ea49caec54 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 26 May 2008 23:53:19 +0000 Subject: [PATCH 0939/1766] fix for solaris openzap from stkn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@486 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 29 +++++++++++++++++++++++++---- libs/openzap/src/ss7_boost_client.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 2931a4f262..ec7e935dfb 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.prg]) +AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) AC_CONFIG_SRCDIR([src/libteletone_detect.c]) # Checks for programs. @@ -26,7 +26,7 @@ AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compile done ]) ]) -AC_ARG_ENABLE(enable_64, [ --enable-64 Enable 64bit compilation]) +AC_ARG_ENABLE([enable_64], [AS_HELP_STRING([--enable-64], [Enable 64bit compilation])], [enable_64="$enableval"], [enable_64="no"]) AX_COMPILER_VENDOR @@ -46,11 +46,32 @@ sun) esac AC_CHECK_HEADERS([netinet/sctp.h netdb.h]) -AC_CHECK_FUNCS([gethostbyname_r]) +AC_CHECK_FUNC([gethostbyname_r], + [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] +) +if test "$ac_cv_func_gethostbyname_r" = "yes" -o "$ac_cv_lib_nsl_gethostbyname_r" = "yes" ; then + +AC_MSG_CHECKING([whether gethostbyname_r requires five arguments]) + +ac_cv_func_gethostbyname_r_five_args="no" + +AC_TRY_COMPILE([#include ], + [char *name; + struct hostent *he, *res; + char buffer[2048]; + int buflen = 2048; + (void)gethostbyname_r(name, he, buffer, buflen, &res)], + [ac_cv_func_gethostbyname_r_five_args="yes" + AC_DEFINE([HAVE_GETHOSTBYNAME_R_FIVE], [1], [gethostbyname_r has five arguments])] +) + + AC_MSG_RESULT([$ac_cv_func_gethostbyname_r_five_args]) + AC_DEFINE([HAVE_GETHOSTBYNAME_R],[1],[threadsafe gethostbyname]) +fi # Enable debugging AC_ARG_ENABLE(debug, -[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"]) +[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enableval"],[enable_debug="yes"]) if test "${enable_debug}" = "yes"; then AC_DEFINE([DEBUG],[],[Enable extra debugging.]) diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index 75d274cfaf..f12f1018a8 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -74,7 +74,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca int rc; struct hostent *result, *local_result; char buf[512], local_buf[512]; - int err = 0; + int err = 0, local_err = 0; memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp)); memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); @@ -91,9 +91,15 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca 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, &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); From 714535c19087d50d6a794fc2f512b71fe9223af1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 26 May 2008 23:53:19 +0000 Subject: [PATCH 0940/1766] fix for solaris openzap from stkn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@486 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 29 +++++++++++++++++++++++++---- libs/freetdm/src/ss7_boost_client.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 2931a4f262..ec7e935dfb 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.prg]) +AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) AC_CONFIG_SRCDIR([src/libteletone_detect.c]) # Checks for programs. @@ -26,7 +26,7 @@ AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compile done ]) ]) -AC_ARG_ENABLE(enable_64, [ --enable-64 Enable 64bit compilation]) +AC_ARG_ENABLE([enable_64], [AS_HELP_STRING([--enable-64], [Enable 64bit compilation])], [enable_64="$enableval"], [enable_64="no"]) AX_COMPILER_VENDOR @@ -46,11 +46,32 @@ sun) esac AC_CHECK_HEADERS([netinet/sctp.h netdb.h]) -AC_CHECK_FUNCS([gethostbyname_r]) +AC_CHECK_FUNC([gethostbyname_r], + [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] +) +if test "$ac_cv_func_gethostbyname_r" = "yes" -o "$ac_cv_lib_nsl_gethostbyname_r" = "yes" ; then + +AC_MSG_CHECKING([whether gethostbyname_r requires five arguments]) + +ac_cv_func_gethostbyname_r_five_args="no" + +AC_TRY_COMPILE([#include ], + [char *name; + struct hostent *he, *res; + char buffer[2048]; + int buflen = 2048; + (void)gethostbyname_r(name, he, buffer, buflen, &res)], + [ac_cv_func_gethostbyname_r_five_args="yes" + AC_DEFINE([HAVE_GETHOSTBYNAME_R_FIVE], [1], [gethostbyname_r has five arguments])] +) + + AC_MSG_RESULT([$ac_cv_func_gethostbyname_r_five_args]) + AC_DEFINE([HAVE_GETHOSTBYNAME_R],[1],[threadsafe gethostbyname]) +fi # Enable debugging AC_ARG_ENABLE(debug, -[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"]) +[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enableval"],[enable_debug="yes"]) if test "${enable_debug}" = "yes"; then AC_DEFINE([DEBUG],[],[Enable extra debugging.]) diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index 75d274cfaf..f12f1018a8 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -74,7 +74,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca int rc; struct hostent *result, *local_result; char buf[512], local_buf[512]; - int err = 0; + int err = 0, local_err = 0; memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp)); memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); @@ -91,9 +91,15 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca 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, &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); From 7ccbbcaedf7b07ff924d0f07a31c3531c64fb336 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 27 May 2008 08:49:37 +0000 Subject: [PATCH 0941/1766] __FUNCTION__ is a gcc extension... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@488 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 8b25e9fc07..c187f1f8d4 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -436,6 +436,10 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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 +#ifndef __FUNCTION__ +#define __FUNCTION__ "" +#endif + #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ #define ZAP_LOG_LEVEL_DEBUG 7 #define ZAP_LOG_LEVEL_INFO 6 From ba43d4da36c6a7bf616d93261386b2559ec4b0b6 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 27 May 2008 08:49:37 +0000 Subject: [PATCH 0942/1766] __FUNCTION__ is a gcc extension... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@488 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 8b25e9fc07..c187f1f8d4 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -436,6 +436,10 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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 +#ifndef __FUNCTION__ +#define __FUNCTION__ "" +#endif + #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ #define ZAP_LOG_LEVEL_DEBUG 7 #define ZAP_LOG_LEVEL_INFO 6 From 2eb1569a42784e0488ed8aca7633a810673aa4af Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 27 May 2008 15:59:56 +0000 Subject: [PATCH 0943/1766] better fix for missing __FUNCTION__ git-svn-id: http://svn.openzap.org/svn/openzap/trunk@489 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index c187f1f8d4..dbe03d3cf7 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -437,7 +437,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; #define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS #ifndef __FUNCTION__ -#define __FUNCTION__ "" +#define __FUNCTION__ (const char *)__func__ #endif #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ From cb01ace9c9d1c08a0bfd4d34d53f67a1937f6237 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 27 May 2008 15:59:56 +0000 Subject: [PATCH 0944/1766] better fix for missing __FUNCTION__ git-svn-id: http://svn.openzap.org/svn/openzap/trunk@489 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index c187f1f8d4..dbe03d3cf7 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -437,7 +437,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; #define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS #ifndef __FUNCTION__ -#define __FUNCTION__ "" +#define __FUNCTION__ (const char *)__func__ #endif #define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ From 689b83170953c9de7b21c186a9c856e909cb9077 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 29 May 2008 19:58:35 +0000 Subject: [PATCH 0945/1766] messed up state rule git-svn-id: http://svn.openzap.org/svn/openzap/trunk@490 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/src/zap_io.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index b7c238bea5..c444c4e1e4 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Wed May 14 11:24:37 EDT 2008 +Thu May 29 15:57:49 EDT 2008 diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2f6d7afd5e..5538d7d58b 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -719,7 +719,10 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_DIALTONE: + case ZAP_CHANNEL_STATE_DIALING: case ZAP_CHANNEL_STATE_RING: + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case ZAP_CHANNEL_STATE_PROGRESS: ok = 1; break; default: From 72f39201a1c96318426f1ee9da42cbd511e1929e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 29 May 2008 19:58:35 +0000 Subject: [PATCH 0946/1766] messed up state rule git-svn-id: http://svn.openzap.org/svn/openzap/trunk@490 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/src/zap_io.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index b7c238bea5..c444c4e1e4 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Wed May 14 11:24:37 EDT 2008 +Thu May 29 15:57:49 EDT 2008 diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2f6d7afd5e..5538d7d58b 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -719,7 +719,10 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_DIALTONE: + case ZAP_CHANNEL_STATE_DIALING: case ZAP_CHANNEL_STATE_RING: + case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case ZAP_CHANNEL_STATE_PROGRESS: ok = 1; break; default: From f5008c1d373c37483756584036251c1abbfbad4c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 16:59:41 +0000 Subject: [PATCH 0947/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@491 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 5538d7d58b..19876afb5b 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -723,6 +723,8 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta case ZAP_CHANNEL_STATE_RING: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: case ZAP_CHANNEL_STATE_PROGRESS: + case ZAP_CHANNEL_STATE_GET_CALLERID: + case ZAP_CHANNEL_STATE_GENRING: ok = 1; break; default: From 23aaa233eca50062e90a1dc7f1b649be635ea9e6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 16:59:41 +0000 Subject: [PATCH 0948/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@491 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5538d7d58b..19876afb5b 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -723,6 +723,8 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta case ZAP_CHANNEL_STATE_RING: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: case ZAP_CHANNEL_STATE_PROGRESS: + case ZAP_CHANNEL_STATE_GET_CALLERID: + case ZAP_CHANNEL_STATE_GENRING: ok = 1; break; default: From 605d0625a19f011b4bf5eff4b608025cfdf12046 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 17:00:02 +0000 Subject: [PATCH 0949/1766] double doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@492 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index c444c4e1e4..105f52776b 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Thu May 29 15:57:49 EDT 2008 +Tue Jun 3 12:59:58 EDT 2008 From 3989919d66966d00267c996f9b03efd5e665d6d6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 17:00:02 +0000 Subject: [PATCH 0950/1766] double doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@492 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index c444c4e1e4..105f52776b 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Thu May 29 15:57:49 EDT 2008 +Tue Jun 3 12:59:58 EDT 2008 From 9ec816c6d9119b1fd65ba7ada8b751c9ccdaeff6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 19:31:07 +0000 Subject: [PATCH 0951/1766] sigh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@493 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/src/zap_io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 105f52776b..4ba9017948 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Tue Jun 3 12:59:58 EDT 2008 +Tue Jun 3 15:31:00 EDT 2008 diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 19876afb5b..d5cca22cb3 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -702,7 +702,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; case ZAP_CHANNEL_STATE_UP: { - ok = 0; + ok = 1; switch(state) { case ZAP_CHANNEL_STATE_PROGRESS: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: From b51ea4b1dc11997c74651e6e6c3ae50f373ab8cc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 19:31:07 +0000 Subject: [PATCH 0952/1766] sigh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@493 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/src/zap_io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 105f52776b..4ba9017948 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Tue Jun 3 12:59:58 EDT 2008 +Tue Jun 3 15:31:00 EDT 2008 diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 19876afb5b..d5cca22cb3 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -702,7 +702,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta break; case ZAP_CHANNEL_STATE_UP: { - ok = 0; + ok = 1; switch(state) { case ZAP_CHANNEL_STATE_PROGRESS: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: From 52ec1f9a285000681de85343a73e904333caf2c8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 21:10:30 +0000 Subject: [PATCH 0953/1766] surely the wrong week to quit sniffing glue and don't call me shirley git-svn-id: http://svn.openzap.org/svn/openzap/trunk@494 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/src/zap_io.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 4ba9017948..5009a80d3a 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Tue Jun 3 15:31:00 EDT 2008 +Tue Jun 3 17:09:07 EDT 2008 diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index d5cca22cb3..52211d8fb1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1105,6 +1105,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) *zchan = NULL; } } + check->ring_count = 0; zap_mutex_unlock(check->mutex); } From cf76457d4b897c8b45afd5ef318d90d2f5dbee5d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Jun 2008 21:10:30 +0000 Subject: [PATCH 0954/1766] surely the wrong week to quit sniffing glue and don't call me shirley git-svn-id: http://svn.openzap.org/svn/openzap/trunk@494 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/src/zap_io.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 4ba9017948..5009a80d3a 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Tue Jun 3 15:31:00 EDT 2008 +Tue Jun 3 17:09:07 EDT 2008 diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index d5cca22cb3..52211d8fb1 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1105,6 +1105,7 @@ zap_status_t zap_channel_close(zap_channel_t **zchan) *zchan = NULL; } } + check->ring_count = 0; zap_mutex_unlock(check->mutex); } From 7ea0f83baf4736600c1df601ea885cbd9e778249 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 5 Jun 2008 14:09:53 +0000 Subject: [PATCH 0955/1766] fix missed name change in debug line git-svn-id: http://svn.openzap.org/svn/openzap/trunk@495 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 318ed6e4a9..c27870e45c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -381,7 +381,7 @@ static switch_status_t channel_on_routing(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(channel)); return SWITCH_STATUS_SUCCESS; } From 114a0a8afbf52e1ec87c8a3b32ca0bea6369ea66 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 5 Jun 2008 14:09:53 +0000 Subject: [PATCH 0956/1766] fix missed name change in debug line git-svn-id: http://svn.openzap.org/svn/openzap/trunk@495 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 318ed6e4a9..c27870e45c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -381,7 +381,7 @@ static switch_status_t channel_on_routing(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(channel)); return SWITCH_STATUS_SUCCESS; } From 7d9be1f65ab4e6eb254da302d38af15b328ae2fd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 1 Jul 2008 22:34:59 +0000 Subject: [PATCH 0957/1766] re-set our decode buffer to get rid of the previous message. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@496 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 272d768766..0415f39512 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -340,10 +340,13 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) L3INT IOff = 0; - /* Protocol Discriminator */ + /* Reset our decode buffer */ + memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf)); + + /* Protocol Discriminator */ m->ProtDisc = Mes[IOff++]; - /* CRV */ + /* CRV */add m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); From 522baa05a71f385bcea82c9e77e943a1ad857aed Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 1 Jul 2008 22:34:59 +0000 Subject: [PATCH 0958/1766] re-set our decode buffer to get rid of the previous message. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@496 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 272d768766..0415f39512 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -340,10 +340,13 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) L3INT IOff = 0; - /* Protocol Discriminator */ + /* Reset our decode buffer */ + memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf)); + + /* Protocol Discriminator */ m->ProtDisc = Mes[IOff++]; - /* CRV */ + /* CRV */add m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); From 1b523a758fc45f0edabd4041c4cb299e77a9b593 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 1 Jul 2008 23:34:16 +0000 Subject: [PATCH 0959/1766] DOH git-svn-id: http://svn.openzap.org/svn/openzap/trunk@497 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 0415f39512..12ebde2660 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -346,7 +346,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Protocol Discriminator */ m->ProtDisc = Mes[IOff++]; - /* CRV */add + /* CRV */ m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); From b212c8cdf2b770da54be66dc13952da32ecce56b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 1 Jul 2008 23:34:16 +0000 Subject: [PATCH 0960/1766] DOH git-svn-id: http://svn.openzap.org/svn/openzap/trunk@497 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 0415f39512..12ebde2660 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -346,7 +346,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) /* Protocol Discriminator */ m->ProtDisc = Mes[IOff++]; - /* CRV */add + /* CRV */ m->CRVFlag = Mes[IOff + 1] & 0x80; m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); From 2dba8483c76948c77aa4025ead4feb5e6b51ec4e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 3 Jul 2008 22:51:18 +0000 Subject: [PATCH 0961/1766] fix causes causing trouble (do make current) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@498 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index dbe03d3cf7..483bddfb82 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -472,8 +472,8 @@ typedef struct zap_bitstream zap_bitstream_t; typedef struct zap_fsk_modulator zap_fsk_modulator_t; typedef enum { - ZAP_CAUSE_UNALLOCATED = 0, - ZAP_CAUSE_SUCCESS = 1, + 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, @@ -522,6 +522,7 @@ typedef enum { 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, From 1cdd22c2b4b7ff858ceb0c092a4d0c31316f94bc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 3 Jul 2008 22:51:18 +0000 Subject: [PATCH 0962/1766] fix causes causing trouble (do make current) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@498 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index dbe03d3cf7..483bddfb82 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -472,8 +472,8 @@ typedef struct zap_bitstream zap_bitstream_t; typedef struct zap_fsk_modulator zap_fsk_modulator_t; typedef enum { - ZAP_CAUSE_UNALLOCATED = 0, - ZAP_CAUSE_SUCCESS = 1, + 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, @@ -522,6 +522,7 @@ typedef enum { 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, From 58ac0987b02691e78779435c7313dd36989ed582 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 8 Jul 2008 02:22:48 +0000 Subject: [PATCH 0963/1766] fix bsd build (OPENZAP-1) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@499 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 2 +- libs/openzap/src/zap_ss7_boost.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index ec7e935dfb..480527be18 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -45,7 +45,7 @@ sun) ;; esac -AC_CHECK_HEADERS([netinet/sctp.h netdb.h]) +AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) AC_CHECK_FUNC([gethostbyname_r], [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] ) diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 17a2cd7ed7..08e1d65417 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -34,6 +34,9 @@ #include "openzap.h" #include "ss7_boost_client.h" #include "zap_ss7_boost.h" +#ifdef HAVE_SYS_SELECT_H +#include +#endif typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), From d15813f1f791a0fe2ea45c709028fd66aaf6da7d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 8 Jul 2008 02:22:48 +0000 Subject: [PATCH 0964/1766] fix bsd build (OPENZAP-1) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@499 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 2 +- libs/freetdm/src/zap_ss7_boost.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index ec7e935dfb..480527be18 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -45,7 +45,7 @@ sun) ;; esac -AC_CHECK_HEADERS([netinet/sctp.h netdb.h]) +AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) AC_CHECK_FUNC([gethostbyname_r], [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] ) diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 17a2cd7ed7..08e1d65417 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -34,6 +34,9 @@ #include "openzap.h" #include "ss7_boost_client.h" #include "zap_ss7_boost.h" +#ifdef HAVE_SYS_SELECT_H +#include +#endif typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), From 45d28e8fab8ce061b101c6e3d6c568bdf5b4bfaa Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 8 Jul 2008 14:44:11 +0000 Subject: [PATCH 0965/1766] [Q.931] Fix DateTime IE parsing git-svn-id: http://svn.openzap.org/svn/openzap/trunk@500 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 09d2d1ce8a..6c77d32a47 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1357,11 +1357,10 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *pIE=0; - pie->IEId = IBuf[Octet]; - IESize = IBuf[Octet ++]; + pie->IEId = IBuf[Octet++]; /* Octet 2 */ - IESize = IBuf[Octet ++]; + IESize = IBuf[Octet++]; /* Octet 3 - Year */ pie->Year = IBuf[Octet++]; @@ -1375,23 +1374,24 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR /******************************************************************* 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 >= 6) + if(IESize >= 4) { pie->Format = 1; pie->Hour = IBuf[Octet++]; /* Octet 7 - Minute (optional)*/ - if(IESize >= 7) + if(IESize >= 5) { pie->Format = 2; pie->Minute = IBuf[Octet++]; /* Octet 8 - Second (optional)*/ - if(IESize >= 8) + if(IESize >= 6) { pie->Format = 3; pie->Second = IBuf[Octet++]; From a32cd745f7790b99e6502aa6eb0678607d205160 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 8 Jul 2008 14:44:11 +0000 Subject: [PATCH 0966/1766] [Q.931] Fix DateTime IE parsing git-svn-id: http://svn.openzap.org/svn/openzap/trunk@500 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 09d2d1ce8a..6c77d32a47 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1357,11 +1357,10 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *pIE=0; - pie->IEId = IBuf[Octet]; - IESize = IBuf[Octet ++]; + pie->IEId = IBuf[Octet++]; /* Octet 2 */ - IESize = IBuf[Octet ++]; + IESize = IBuf[Octet++]; /* Octet 3 - Year */ pie->Year = IBuf[Octet++]; @@ -1375,23 +1374,24 @@ L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR /******************************************************************* 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 >= 6) + if(IESize >= 4) { pie->Format = 1; pie->Hour = IBuf[Octet++]; /* Octet 7 - Minute (optional)*/ - if(IESize >= 7) + if(IESize >= 5) { pie->Format = 2; pie->Minute = IBuf[Octet++]; /* Octet 8 - Second (optional)*/ - if(IESize >= 8) + if(IESize >= 6) { pie->Format = 3; pie->Second = IBuf[Octet++]; From d54afa61063e5ea2fd147db23f764a2359283639 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 8 Jul 2008 14:45:41 +0000 Subject: [PATCH 0967/1766] [Q.931] INFORMATION message is 0x7b not 0x7a git-svn-id: http://svn.openzap.org/svn/openzap/trunk@501 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 8cea95e586..70b84af070 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -371,7 +371,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #define Q931mes_RESTART 0x46 /* 0100 0110 */ #define Q931mes_RESTART_ACKNOWLEDGE 0x4e /* 0100 1110 */ #define Q931mes_CONGESTION_CONTROL 0x79 /* 0111 1001 */ -#define Q931mes_INFORMATION 0x7a /* 0111 1011 */ +#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 */ From af1bcca8e4bb9e0b823b16be3175c4064307a079 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 8 Jul 2008 14:45:41 +0000 Subject: [PATCH 0968/1766] [Q.931] INFORMATION message is 0x7b not 0x7a git-svn-id: http://svn.openzap.org/svn/openzap/trunk@501 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 8cea95e586..70b84af070 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -371,7 +371,7 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #define Q931mes_RESTART 0x46 /* 0100 0110 */ #define Q931mes_RESTART_ACKNOWLEDGE 0x4e /* 0100 1110 */ #define Q931mes_CONGESTION_CONTROL 0x79 /* 0111 1001 */ -#define Q931mes_INFORMATION 0x7a /* 0111 1011 */ +#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 */ From 0baedecdfdec58475e93616ffb238c621acd0b13 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 15 Jul 2008 17:34:17 +0000 Subject: [PATCH 0969/1766] change order. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@502 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index d1e2a85112..2131c20e48 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1890,14 +1890,14 @@ L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ - /* Display */ + 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; - 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; From 34c111830f55f56d0fb8ee1ab3aabca73f5a9935 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 15 Jul 2008 17:34:17 +0000 Subject: [PATCH 0970/1766] change order. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@502 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index d1e2a85112..2131c20e48 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1890,14 +1890,14 @@ L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ OBuf[Octet++] = pMes->MesType; /* message header */ - /* Display */ + 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; - 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; From 44e8be160ab7f0d88de79e7bbf3b23917b4b8756 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 Jul 2008 20:03:37 +0000 Subject: [PATCH 0971/1766] send call progress not proceeding. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@505 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index c0811fb9dd..4cd3cee8bd 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -581,7 +581,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - gen->MesType = Q931mes_PROGRESS; + gen->MesType = Q931mes_CALL_PROCEEDING; Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } From 8587eb9308a5f0c59897adbdb614d80bd1087522 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 24 Jul 2008 20:03:37 +0000 Subject: [PATCH 0972/1766] send call progress not proceeding. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@505 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index c0811fb9dd..4cd3cee8bd 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -581,7 +581,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - gen->MesType = Q931mes_PROGRESS; + gen->MesType = Q931mes_CALL_PROCEEDING; Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } From e2cb2de28e4f6c2eb47b984d8c80fb0b633cf5f8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 15:05:07 +0000 Subject: [PATCH 0973/1766] add disable_ec app git-svn-id: http://svn.openzap.org/svn/openzap/trunk@506 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 20 ++++++++++++++++++++ libs/openzap/src/include/zap_types.h | 4 ++++ libs/openzap/src/zap_buffer.c | 6 ++++-- libs/openzap/src/zap_zt.c | 26 ++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c27870e45c..10aa079f03 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1848,10 +1848,28 @@ SWITCH_STANDARD_API(oz_function) } +SWITCH_STANDARD_APP(disable_ec_function) +{ + private_t *tech_pvt; + int x = 0; + + if (!switch_core_session_check_interface(session, openzap_endpoint_interface)) { + zap_log(ZAP_LOG_ERROR, "This application is only for OpenZAP channels.\n"); + return; + } + + tech_pvt = switch_core_session_get_private(session); + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOCANCEL, &x); + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOTRAIN, &x); + zap_log(ZAP_LOG_ERROR, "Echo Canceller Disabled\n"); +} + + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { switch_api_interface_t *commands_api_interface; + switch_application_interface_t *app_interface; module_pool = pool; @@ -1875,6 +1893,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_ADD_API(commands_api_interface, "oz", "OpenZAP commands", oz_function, OZ_SYNTAX); + SWITCH_ADD_APP(app_interface, "disable_ec", "Disable Echo Canceller", "Disable Echo Canceller", disable_ec_function, "", SAF_NONE); + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 483bddfb82..be43d0d069 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -260,6 +260,10 @@ typedef enum { ZAP_COMMAND_TRACE_OUTPUT, ZAP_COMMAND_ENABLE_CALLERID_DETECT, ZAP_COMMAND_DISABLE_CALLERID_DETECT, + ZAP_COMMAND_ENABLE_ECHOCANCEL, + ZAP_COMMAND_DISABLE_ECHOCANCEL, + ZAP_COMMAND_ENABLE_ECHOTRAIN, + ZAP_COMMAND_DISABLE_ECHOTRAIN, ZAP_COMMAND_COUNT } zap_command_t; diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 525a3e2100..d5d7f1ef7d 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -204,6 +204,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d 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; @@ -212,10 +213,11 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d new_size = new_block_size; } buffer->head = buffer->data; - buffer->data = realloc(buffer->data, new_size); - if (!buffer->data) { + data = realloc(buffer->data, new_size); + if (!data) { return 0; } + buffer->data = data; buffer->head = buffer->data; buffer->datalen = new_size; } diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index ec6872b782..38c55ffae5 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -377,6 +377,32 @@ static ZIO_COMMAND_FUNCTION(zt_command) memset(&ztp, 0, sizeof(ztp)); switch(command) { + case ZAP_COMMAND_ENABLE_ECHOCANCEL: + { + int level = ZAP_COMMAND_OBJ_INT; + err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + ZAP_COMMAND_OBJ_INT = level; + } + case ZAP_COMMAND_DISABLE_ECHOCANCEL: + { + int level = 0; + err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + ZAP_COMMAND_OBJ_INT = level; + } + break; + case ZAP_COMMAND_ENABLE_ECHOTRAIN: + { + int level = ZAP_COMMAND_OBJ_INT; + err = ioctl(zchan->sockfd, ZT_ECHOTRAIN, &level); + ZAP_COMMAND_OBJ_INT = level; + } + case ZAP_COMMAND_DISABLE_ECHOTRAIN: + { + int level = 0; + err = ioctl(zchan->sockfd, ZT_ECHOTRAIN, &level); + ZAP_COMMAND_OBJ_INT = level; + } + break; case ZAP_COMMAND_OFFHOOK: { int command = ZT_OFFHOOK; From 15fe36a6d75d49bbfe0d51b231ba1c41f2b2e297 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 15:05:07 +0000 Subject: [PATCH 0974/1766] add disable_ec app git-svn-id: http://svn.openzap.org/svn/openzap/trunk@506 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 20 ++++++++++++++++++++ libs/freetdm/src/include/zap_types.h | 4 ++++ libs/freetdm/src/zap_buffer.c | 6 ++++-- libs/freetdm/src/zap_zt.c | 26 ++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c27870e45c..10aa079f03 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1848,10 +1848,28 @@ SWITCH_STANDARD_API(oz_function) } +SWITCH_STANDARD_APP(disable_ec_function) +{ + private_t *tech_pvt; + int x = 0; + + if (!switch_core_session_check_interface(session, openzap_endpoint_interface)) { + zap_log(ZAP_LOG_ERROR, "This application is only for OpenZAP channels.\n"); + return; + } + + tech_pvt = switch_core_session_get_private(session); + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOCANCEL, &x); + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOTRAIN, &x); + zap_log(ZAP_LOG_ERROR, "Echo Canceller Disabled\n"); +} + + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { switch_api_interface_t *commands_api_interface; + switch_application_interface_t *app_interface; module_pool = pool; @@ -1875,6 +1893,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_ADD_API(commands_api_interface, "oz", "OpenZAP commands", oz_function, OZ_SYNTAX); + SWITCH_ADD_APP(app_interface, "disable_ec", "Disable Echo Canceller", "Disable Echo Canceller", disable_ec_function, "", SAF_NONE); + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 483bddfb82..be43d0d069 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -260,6 +260,10 @@ typedef enum { ZAP_COMMAND_TRACE_OUTPUT, ZAP_COMMAND_ENABLE_CALLERID_DETECT, ZAP_COMMAND_DISABLE_CALLERID_DETECT, + ZAP_COMMAND_ENABLE_ECHOCANCEL, + ZAP_COMMAND_DISABLE_ECHOCANCEL, + ZAP_COMMAND_ENABLE_ECHOTRAIN, + ZAP_COMMAND_DISABLE_ECHOTRAIN, ZAP_COMMAND_COUNT } zap_command_t; diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 525a3e2100..d5d7f1ef7d 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -204,6 +204,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d 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; @@ -212,10 +213,11 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d new_size = new_block_size; } buffer->head = buffer->data; - buffer->data = realloc(buffer->data, new_size); - if (!buffer->data) { + data = realloc(buffer->data, new_size); + if (!data) { return 0; } + buffer->data = data; buffer->head = buffer->data; buffer->datalen = new_size; } diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/zap_zt.c index ec6872b782..38c55ffae5 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/zap_zt.c @@ -377,6 +377,32 @@ static ZIO_COMMAND_FUNCTION(zt_command) memset(&ztp, 0, sizeof(ztp)); switch(command) { + case ZAP_COMMAND_ENABLE_ECHOCANCEL: + { + int level = ZAP_COMMAND_OBJ_INT; + err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + ZAP_COMMAND_OBJ_INT = level; + } + case ZAP_COMMAND_DISABLE_ECHOCANCEL: + { + int level = 0; + err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + ZAP_COMMAND_OBJ_INT = level; + } + break; + case ZAP_COMMAND_ENABLE_ECHOTRAIN: + { + int level = ZAP_COMMAND_OBJ_INT; + err = ioctl(zchan->sockfd, ZT_ECHOTRAIN, &level); + ZAP_COMMAND_OBJ_INT = level; + } + case ZAP_COMMAND_DISABLE_ECHOTRAIN: + { + int level = 0; + err = ioctl(zchan->sockfd, ZT_ECHOTRAIN, &level); + ZAP_COMMAND_OBJ_INT = level; + } + break; case ZAP_COMMAND_OFFHOOK: { int command = ZT_OFFHOOK; From fe7744a96eb7f88f710d84e30499dd7c3fc19e09 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 22:15:28 +0000 Subject: [PATCH 0975/1766] update boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@507 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 12 ++ libs/openzap/src/include/sigboost.h | 53 ++++-- libs/openzap/src/include/ss7_boost_client.h | 14 +- libs/openzap/src/include/zap_ss7_boost.h | 3 +- libs/openzap/src/ss7_boost_client.c | 181 +++++++++++++++++--- libs/openzap/src/zap_ss7_boost.c | 162 +++++++++++------- 6 files changed, 321 insertions(+), 104 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index e8ee4fe890..4fb5c737ad 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -595,6 +595,18 @@ static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t s zap_mutex_unlock(span->mutex); } +static __inline__ int zap_check_state_all(zap_span_t *span, zap_channel_state_t state) +{ + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (span->channels[j].state != state || zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + return 0; + } + } + + return 1; +} + static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) { uint32_t j; diff --git a/libs/openzap/src/include/sigboost.h b/libs/openzap/src/include/sigboost.h index 009e4b26c6..a5a147cd11 100644 --- a/libs/openzap/src/include/sigboost.h +++ b/libs/openzap/src/include/sigboost.h @@ -1,5 +1,5 @@ /**************************************************************************** - * sigboost.h $Revision: 1.3 $ + * sigboost.h $Revision: 1.5 $ * * Definitions for the sigboost interface. * @@ -33,12 +33,12 @@ enum e_sigboost_event_id_values 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*/ }; 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 */ @@ -59,7 +59,6 @@ enum e_sigboost_call_setup_ack_nack_cause_values }; #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. @@ -68,37 +67,63 @@ enum e_sigboost_call_setup_ack_nack_cause_values #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 +#define SIZE_RDNIS 128 #pragma pack(1) typedef struct { uint32_t event_id; + /* delete sequence numbers - SCTP does not need them */ 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 span; + uint8_t chan; + struct timeval tv; 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 calling_name[MAX_DIALED_DIGITS + 1]; + uint16_t redirection_string_size; char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ /* redir string format: * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection * */ -} t_sigboost; +} t_sigboost_callstart; + +#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) + +typedef struct +{ + 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; + 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: + return 1; + default: + return 0; + } + + return 0; +} + #endif diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h index 4184f5385e..f28f1900f3 100644 --- a/libs/openzap/src/include/ss7_boost_client.h +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -70,7 +70,8 @@ (dest)->flags |= ((src)->flags & (flagz)); \ } while (0) -typedef t_sigboost ss7bc_event_t; +typedef t_sigboost_callstart ss7bc_event_t; +typedef t_sigboost_short ss7bc_short_event_t; typedef uint32_t ss7bc_event_id_t; typedef struct ss7bc_ip_cfg @@ -117,14 +118,19 @@ static inline void sctp_no_nagle(int socket) int ss7bc_connection_close(ss7bc_connection_t *mcon); int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); -ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); -ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); +ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); +ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); +int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); #define ss7bc_connection_write(_m,_e) __ss7bc_connection_write(_m, _e, __FILE__, __func__, __LINE__) -void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); +#define ss7bc_connection_writep(_m,_e) __ss7bc_connection_writep(_m, _e, __FILE__, __func__, __LINE__) +#define ss7bc_connection_read(_m,_e) __ss7bc_connection_read(_m, _e, __FILE__, __func__, __LINE__) +#define ss7bc_connection_readp(_m,_e) __ss7bc_connection_readp(_m, _e, __FILE__, __func__, __LINE__) +void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span); void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); const char *ss7bc_event_id_name(uint32_t event_id); int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause); +int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); #endif diff --git a/libs/openzap/src/include/zap_ss7_boost.h b/libs/openzap/src/include/zap_ss7_boost.h index e3c7901c45..c5496b8aed 100644 --- a/libs/openzap/src/include/zap_ss7_boost.h +++ b/libs/openzap/src/include/zap_ss7_boost.h @@ -37,7 +37,8 @@ #include "openzap.h" typedef enum { - ZAP_SS7_BOOST_RUNNING = (1 << 0) + ZAP_SS7_BOOST_RUNNING = (1 << 0), + ZAP_SS7_BOOST_RESTARTING = (1 << 1) } zap_ss7_boost_flag_t; typedef struct zap_ss7_boost_data { diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index f12f1018a8..5699455854 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -69,6 +69,41 @@ static struct ss7bc_map ss7bc_table[] = { +static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_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_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + dir ? "TX":"RX", + ss7bc_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") + ); + +} +static void ss7bc_print_event_short(ss7bc_connection_t *mcon,ss7bc_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_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + dir ? "TX":"RX", + priority ? "P":"N", + ss7bc_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(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) { int rc; @@ -161,13 +196,13 @@ int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_po int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) { - ss7bc_event_t oevent; + ss7bc_short_event_t oevent; int retry = 5; ss7bc_event_init(&oevent, cmd, chan, span); oevent.release_cause = cause; - if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART) { + if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->rxseq_reset = 1; mcon->txseq = 0; mcon->rxseq = 0; @@ -178,7 +213,33 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int oevent.call_setup_id = id; } - while (ss7bc_connection_write(mcon, &oevent) <= 0) { + while (ss7bc_connection_write(mcon, (ss7bc_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 ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause) +{ + ss7bc_short_event_t oevent; + int retry = 5; + + ss7bc_event_init(&oevent, cmd, chan, span); + oevent.release_cause = cause; + + if (id >= 0) { + oevent.call_setup_id = id; + } + + while (ss7bc_connection_writep(pcon, (ss7bc_event_t*)&oevent) <= 0) { if (--retry <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket: %s\n", strerror(errno)); return -1; @@ -193,16 +254,39 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int -ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) +ss7bc_event_t *__ss7bc_connection_read(ss7bc_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 == sizeof(mcon->event) || bytes == (sizeof(mcon->event)-sizeof(uint32_t))) { + /* 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(ss7bc_short_event_t)) { + msg_ok=1; + + } else { + msg_ok=0; + } + + if (msg_ok){ + + if (boost_full_event(mcon->event.event_id)) { + ss7bc_print_event_call(mcon,&mcon->event, 0, 0, file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_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"); @@ -213,6 +297,7 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n"); return NULL; } +#endif mcon->txwindow = mcon->txseq - mcon->event.bseqno; mcon->rxseq++; @@ -233,14 +318,21 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) return NULL; } -ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) +ss7bc_event_t *__ss7bc_connection_readp(ss7bc_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 == sizeof(mcon->event) || bytes == (sizeof(mcon->event)-sizeof(uint32_t))) { + if (bytes == sizeof(ss7bc_short_event_t)) { + + if (boost_full_event(mcon->event.event_id)) { + ss7bc_print_event_call(mcon,&mcon->event, 1, 0, file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)&mcon->event, 1, 0, file,func,line); + } + return &mcon->event; } else { if (iteration == 0) { @@ -256,6 +348,7 @@ ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) { int err; + int event_size=sizeof(ss7bc_event_t); if (!event || mcon->socket < 0 || !mcon->mutex) { zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); @@ -269,30 +362,71 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con return -1; } + if (!boost_full_event(event->event_id)) { + event_size=sizeof(ss7bc_short_event_t); + } + gettimeofday(&event->tv,NULL); zap_mutex_lock(mcon->mutex); - event->fseqno = mcon->txseq++; + 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; - err = sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + zap_mutex_unlock(mcon->mutex); - if (err != sizeof(ss7bc_event_t)) { + if (err != event_size) { err = -1; abort(); } + + if (boost_full_event(event->event_id)) { + ss7bc_print_event_call(mcon,event, 0, 1,file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 0, 1,file,func,line); + } + + return err; +} + + +int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) +{ + int err; + int event_size=sizeof(ss7bc_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(ss7bc_short_event_t); + } + + gettimeofday(&event->tv,NULL); - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", - ss7bc_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") - ); + zap_mutex_lock(mcon->mutex); + 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)) { + ss7bc_print_event_call(mcon,event, 1, 1,file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 1, 1,file,func,line); + } return err; } @@ -317,9 +451,9 @@ void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *call } -void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span) +void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span) { - memset(event, 0, sizeof(ss7bc_event_t)); + memset(event, 0, sizeof(ss7bc_short_event_t)); event->event_id = event_id; event->chan = chan; event->span = span; @@ -340,6 +474,7 @@ const char *ss7bc_event_id_name(uint32_t event_id) return ret; } + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 08e1d65417..0238a50437 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -54,7 +54,7 @@ typedef enum { typedef struct { ss7_boost_request_status_t status; - ss7bc_event_t event; + ss7bc_short_event_t event; zap_span_t *span; zap_channel_t *zchan; } ss7_boost_request_t; @@ -136,7 +136,7 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) } #define next_request_id() __next_request_id(__FUNCTION__, __LINE__) -static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) +static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, int force) { int i; zap_channel_t *zchan = NULL; @@ -273,7 +273,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) return status; } -static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -316,7 +316,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } -static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; int r = 0; @@ -346,7 +346,7 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e release_request_id_span_chan(event->span, event->chan); } -static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -395,7 +395,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s } -static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -434,7 +434,7 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e release_request_id_span_chan(event->span, event->chan); } -static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -465,7 +465,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ { zap_channel_t *zchan; - if (!(zchan = find_zchan(span, event, 0))) { + if (!(zchan = find_zchan(span, (ss7bc_short_event_t*)event, 0))) { goto error; } @@ -498,12 +498,11 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } -static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { int err; - - err = ss7bc_connection_write(mcon, event); + err = ss7bc_connection_writep(mcon, (ss7bc_event_t*)event); if (err <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno)); @@ -514,16 +513,64 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) return; } -static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) +static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { - mcon->rxseq_reset = 0; +#if 0 +/* NC: Clear suspended on RESTART ACK */ + mcon->rxseq_reset = 0; mcon->up = 1; zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); +#endif mcon->hb_elapsed = 0; } -static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) + +static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) +{ + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + + mcon->rxseq_reset = 0; + mcon->up = 1; + + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + + mcon->hb_elapsed = 0; +} + +static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) +{ + zap_channel_t *zchan = NULL; + char digits[MAX_DIALED_DIGITS + 2] = ""; + + if (!(zchan = find_zchan(span, (ss7bc_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; +} + + +static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -532,47 +579,19 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve goto end; } - if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && - event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { - - zap_log(ZAP_LOG_WARNING, - "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", - ss7bc_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") - ); - + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && + event->event_id != SIGBOOST_EVENT_HEARTBEAT && + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART) { goto end; } - - zap_log(ZAP_LOG_DEBUG, - "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", - ss7bc_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") - ); - - assert(event->call_setup_id <= MAX_REQ_ID); switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: - handle_call_start(span, mcon, event); + handle_call_start(span, mcon, (ss7bc_event_t*)event); break; case SIGBOOST_EVENT_CALL_STOPPED: handle_call_stop(span, mcon, event); @@ -605,9 +624,15 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve 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, (ss7bc_event_t*)event); + break; default: zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", ss7bc_event_id_name(event->event_id)); break; @@ -681,11 +706,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; case ZAP_CHANNEL_STATE_UP: @@ -789,6 +810,8 @@ static __inline__ void init_outgoing_array(void) static __inline__ void check_state(zap_span_t *span) { + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { uint32_t j; zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); @@ -802,6 +825,22 @@ static __inline__ void check_state(zap_span_t *span) } } } + + if (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING)) { + if (zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) { + ss7bc_exec_command(&ss7_boost_data->mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART_ACK, + 0); + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); + ss7_boost_data->mcon.hb_elapsed = 0; + } + } + + } @@ -810,7 +849,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10;//, too_long = 60000; + uint32_t ms = 10, too_long = 5000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -823,12 +862,12 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", ss7_boost_data->mcon.socket, strerror(errno)); goto end; } - + if (ss7bc_connection_open(&ss7_boost_data->pcon, ss7_boost_data->pcon.cfg.local_ip, ++ss7_boost_data->pcon.cfg.local_port, ss7_boost_data->pcon.cfg.remote_ip, - ss7_boost_data->pcon.cfg.remote_port) < 0) { + ++ss7_boost_data->pcon.cfg.remote_port) < 0) { zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", ss7_boost_data->pcon.socket, strerror(errno)); goto end; } @@ -841,7 +880,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) init_outgoing_array(); - ss7bc_exec_command(mcon, + ss7bc_exec_commandp(pcon, 0, 0, -1, @@ -855,7 +894,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) ss7bc_event_t *event = NULL; if (!zap_running()) { - ss7bc_exec_command(mcon, + ss7bc_exec_commandp(pcon, 0, 0, -1, @@ -884,27 +923,26 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, mcon, event); + parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); } //else goto top; } if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { - parse_ss7_event(span, mcon, event); + parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); } //else goto top; } } check_state(span); - mcon->hb_elapsed += ms; -#if 0 - if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { + pcon->hb_elapsed += ms; + + if (pcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); mcon->up = 0; zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); } -#endif } From 96ddc322d86a7f3603a8ed40b29e8997abb5e51a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 22:15:28 +0000 Subject: [PATCH 0976/1766] update boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@507 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 12 ++ libs/freetdm/src/include/sigboost.h | 53 ++++-- libs/freetdm/src/include/ss7_boost_client.h | 14 +- libs/freetdm/src/include/zap_ss7_boost.h | 3 +- libs/freetdm/src/ss7_boost_client.c | 181 +++++++++++++++++--- libs/freetdm/src/zap_ss7_boost.c | 162 +++++++++++------- 6 files changed, 321 insertions(+), 104 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index e8ee4fe890..4fb5c737ad 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -595,6 +595,18 @@ static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t s zap_mutex_unlock(span->mutex); } +static __inline__ int zap_check_state_all(zap_span_t *span, zap_channel_state_t state) +{ + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (span->channels[j].state != state || zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + return 0; + } + } + + return 1; +} + static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) { uint32_t j; diff --git a/libs/freetdm/src/include/sigboost.h b/libs/freetdm/src/include/sigboost.h index 009e4b26c6..a5a147cd11 100644 --- a/libs/freetdm/src/include/sigboost.h +++ b/libs/freetdm/src/include/sigboost.h @@ -1,5 +1,5 @@ /**************************************************************************** - * sigboost.h $Revision: 1.3 $ + * sigboost.h $Revision: 1.5 $ * * Definitions for the sigboost interface. * @@ -33,12 +33,12 @@ enum e_sigboost_event_id_values 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*/ }; 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 */ @@ -59,7 +59,6 @@ enum e_sigboost_call_setup_ack_nack_cause_values }; #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. @@ -68,37 +67,63 @@ enum e_sigboost_call_setup_ack_nack_cause_values #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 +#define SIZE_RDNIS 128 #pragma pack(1) typedef struct { uint32_t event_id; + /* delete sequence numbers - SCTP does not need them */ 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 span; + uint8_t chan; + struct timeval tv; 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 calling_name[MAX_DIALED_DIGITS + 1]; + uint16_t redirection_string_size; char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ /* redir string format: * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection * */ -} t_sigboost; +} t_sigboost_callstart; + +#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) + +typedef struct +{ + 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; + 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: + return 1; + default: + return 0; + } + + return 0; +} + #endif diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h index 4184f5385e..f28f1900f3 100644 --- a/libs/freetdm/src/include/ss7_boost_client.h +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -70,7 +70,8 @@ (dest)->flags |= ((src)->flags & (flagz)); \ } while (0) -typedef t_sigboost ss7bc_event_t; +typedef t_sigboost_callstart ss7bc_event_t; +typedef t_sigboost_short ss7bc_short_event_t; typedef uint32_t ss7bc_event_id_t; typedef struct ss7bc_ip_cfg @@ -117,14 +118,19 @@ static inline void sctp_no_nagle(int socket) int ss7bc_connection_close(ss7bc_connection_t *mcon); int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); -ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration); -ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration); +ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); +ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); +int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); #define ss7bc_connection_write(_m,_e) __ss7bc_connection_write(_m, _e, __FILE__, __func__, __LINE__) -void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span); +#define ss7bc_connection_writep(_m,_e) __ss7bc_connection_writep(_m, _e, __FILE__, __func__, __LINE__) +#define ss7bc_connection_read(_m,_e) __ss7bc_connection_read(_m, _e, __FILE__, __func__, __LINE__) +#define ss7bc_connection_readp(_m,_e) __ss7bc_connection_readp(_m, _e, __FILE__, __func__, __LINE__) +void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span); void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); const char *ss7bc_event_id_name(uint32_t event_id); int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause); +int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); #endif diff --git a/libs/freetdm/src/include/zap_ss7_boost.h b/libs/freetdm/src/include/zap_ss7_boost.h index e3c7901c45..c5496b8aed 100644 --- a/libs/freetdm/src/include/zap_ss7_boost.h +++ b/libs/freetdm/src/include/zap_ss7_boost.h @@ -37,7 +37,8 @@ #include "openzap.h" typedef enum { - ZAP_SS7_BOOST_RUNNING = (1 << 0) + ZAP_SS7_BOOST_RUNNING = (1 << 0), + ZAP_SS7_BOOST_RESTARTING = (1 << 1) } zap_ss7_boost_flag_t; typedef struct zap_ss7_boost_data { diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index f12f1018a8..5699455854 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -69,6 +69,41 @@ static struct ss7bc_map ss7bc_table[] = { +static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_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_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + dir ? "TX":"RX", + ss7bc_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") + ); + +} +static void ss7bc_print_event_short(ss7bc_connection_t *mcon,ss7bc_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_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + dir ? "TX":"RX", + priority ? "P":"N", + ss7bc_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(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) { int rc; @@ -161,13 +196,13 @@ int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_po int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) { - ss7bc_event_t oevent; + ss7bc_short_event_t oevent; int retry = 5; ss7bc_event_init(&oevent, cmd, chan, span); oevent.release_cause = cause; - if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART) { + if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->rxseq_reset = 1; mcon->txseq = 0; mcon->rxseq = 0; @@ -178,7 +213,33 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int oevent.call_setup_id = id; } - while (ss7bc_connection_write(mcon, &oevent) <= 0) { + while (ss7bc_connection_write(mcon, (ss7bc_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 ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause) +{ + ss7bc_short_event_t oevent; + int retry = 5; + + ss7bc_event_init(&oevent, cmd, chan, span); + oevent.release_cause = cause; + + if (id >= 0) { + oevent.call_setup_id = id; + } + + while (ss7bc_connection_writep(pcon, (ss7bc_event_t*)&oevent) <= 0) { if (--retry <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket: %s\n", strerror(errno)); return -1; @@ -193,16 +254,39 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int -ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) +ss7bc_event_t *__ss7bc_connection_read(ss7bc_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 == sizeof(mcon->event) || bytes == (sizeof(mcon->event)-sizeof(uint32_t))) { + /* 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(ss7bc_short_event_t)) { + msg_ok=1; + + } else { + msg_ok=0; + } + + if (msg_ok){ + + if (boost_full_event(mcon->event.event_id)) { + ss7bc_print_event_call(mcon,&mcon->event, 0, 0, file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_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"); @@ -213,6 +297,7 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n"); return NULL; } +#endif mcon->txwindow = mcon->txseq - mcon->event.bseqno; mcon->rxseq++; @@ -233,14 +318,21 @@ ss7bc_event_t *ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration) return NULL; } -ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) +ss7bc_event_t *__ss7bc_connection_readp(ss7bc_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 == sizeof(mcon->event) || bytes == (sizeof(mcon->event)-sizeof(uint32_t))) { + if (bytes == sizeof(ss7bc_short_event_t)) { + + if (boost_full_event(mcon->event.event_id)) { + ss7bc_print_event_call(mcon,&mcon->event, 1, 0, file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)&mcon->event, 1, 0, file,func,line); + } + return &mcon->event; } else { if (iteration == 0) { @@ -256,6 +348,7 @@ ss7bc_event_t *ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration) int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) { int err; + int event_size=sizeof(ss7bc_event_t); if (!event || mcon->socket < 0 || !mcon->mutex) { zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); @@ -269,30 +362,71 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con return -1; } + if (!boost_full_event(event->event_id)) { + event_size=sizeof(ss7bc_short_event_t); + } + gettimeofday(&event->tv,NULL); zap_mutex_lock(mcon->mutex); - event->fseqno = mcon->txseq++; + 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; - err = sendto(mcon->socket, event, sizeof(ss7bc_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + zap_mutex_unlock(mcon->mutex); - if (err != sizeof(ss7bc_event_t)) { + if (err != event_size) { err = -1; abort(); } + + if (boost_full_event(event->event_id)) { + ss7bc_print_event_call(mcon,event, 0, 1,file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 0, 1,file,func,line); + } + + return err; +} + + +int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) +{ + int err; + int event_size=sizeof(ss7bc_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(ss7bc_short_event_t); + } + + gettimeofday(&event->tv,NULL); - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", - ss7bc_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") - ); + zap_mutex_lock(mcon->mutex); + 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)) { + ss7bc_print_event_call(mcon,event, 1, 1,file,func,line); + } else { + ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 1, 1,file,func,line); + } return err; } @@ -317,9 +451,9 @@ void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *call } -void ss7bc_event_init(ss7bc_event_t *event, ss7bc_event_id_t event_id, int chan, int span) +void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span) { - memset(event, 0, sizeof(ss7bc_event_t)); + memset(event, 0, sizeof(ss7bc_short_event_t)); event->event_id = event_id; event->chan = chan; event->span = span; @@ -340,6 +474,7 @@ const char *ss7bc_event_id_name(uint32_t event_id) return ret; } + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 08e1d65417..0238a50437 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -54,7 +54,7 @@ typedef enum { typedef struct { ss7_boost_request_status_t status; - ss7bc_event_t event; + ss7bc_short_event_t event; zap_span_t *span; zap_channel_t *zchan; } ss7_boost_request_t; @@ -136,7 +136,7 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) } #define next_request_id() __next_request_id(__FUNCTION__, __LINE__) -static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_event_t *event, int force) +static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, int force) { int i; zap_channel_t *zchan = NULL; @@ -273,7 +273,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) return status; } -static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -316,7 +316,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_event_t *event } -static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; int r = 0; @@ -346,7 +346,7 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e release_request_id_span_chan(event->span, event->chan); } -static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -395,7 +395,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s } -static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -434,7 +434,7 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_e release_request_id_span_chan(event->span, event->chan); } -static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -465,7 +465,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ { zap_channel_t *zchan; - if (!(zchan = find_zchan(span, event, 0))) { + if (!(zchan = find_zchan(span, (ss7bc_short_event_t*)event, 0))) { goto error; } @@ -498,12 +498,11 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } -static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { int err; - - err = ss7bc_connection_write(mcon, event); + err = ss7bc_connection_writep(mcon, (ss7bc_event_t*)event); if (err <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno)); @@ -514,16 +513,64 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_event_t *event) return; } -static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) +static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { - mcon->rxseq_reset = 0; +#if 0 +/* NC: Clear suspended on RESTART ACK */ + mcon->rxseq_reset = 0; mcon->up = 1; zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); +#endif mcon->hb_elapsed = 0; } -static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) + +static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) +{ + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + + mcon->rxseq_reset = 0; + mcon->up = 1; + + zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + + mcon->hb_elapsed = 0; +} + +static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) +{ + zap_channel_t *zchan = NULL; + char digits[MAX_DIALED_DIGITS + 2] = ""; + + if (!(zchan = find_zchan(span, (ss7bc_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; +} + + +static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -532,47 +579,19 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve goto end; } - if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && - event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { - - zap_log(ZAP_LOG_WARNING, - "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", - ss7bc_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") - ); - + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && + event->event_id != SIGBOOST_EVENT_HEARTBEAT && + event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART) { goto end; } - - zap_log(ZAP_LOG_DEBUG, - "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", - ss7bc_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") - ); - - assert(event->call_setup_id <= MAX_REQ_ID); switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: - handle_call_start(span, mcon, event); + handle_call_start(span, mcon, (ss7bc_event_t*)event); break; case SIGBOOST_EVENT_CALL_STOPPED: handle_call_stop(span, mcon, event); @@ -605,9 +624,15 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_eve 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, (ss7bc_event_t*)event); + break; default: zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", ss7bc_event_id_name(event->event_id)); break; @@ -681,11 +706,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { - if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; case ZAP_CHANNEL_STATE_UP: @@ -789,6 +810,8 @@ static __inline__ void init_outgoing_array(void) static __inline__ void check_state(zap_span_t *span) { + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { uint32_t j; zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); @@ -802,6 +825,22 @@ static __inline__ void check_state(zap_span_t *span) } } } + + if (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING)) { + if (zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) { + ss7bc_exec_command(&ss7_boost_data->mcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART_ACK, + 0); + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); + ss7_boost_data->mcon.hb_elapsed = 0; + } + } + + } @@ -810,7 +849,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10;//, too_long = 60000; + uint32_t ms = 10, too_long = 5000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -823,12 +862,12 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", ss7_boost_data->mcon.socket, strerror(errno)); goto end; } - + if (ss7bc_connection_open(&ss7_boost_data->pcon, ss7_boost_data->pcon.cfg.local_ip, ++ss7_boost_data->pcon.cfg.local_port, ss7_boost_data->pcon.cfg.remote_ip, - ss7_boost_data->pcon.cfg.remote_port) < 0) { + ++ss7_boost_data->pcon.cfg.remote_port) < 0) { zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", ss7_boost_data->pcon.socket, strerror(errno)); goto end; } @@ -841,7 +880,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) init_outgoing_array(); - ss7bc_exec_command(mcon, + ss7bc_exec_commandp(pcon, 0, 0, -1, @@ -855,7 +894,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) ss7bc_event_t *event = NULL; if (!zap_running()) { - ss7bc_exec_command(mcon, + ss7bc_exec_commandp(pcon, 0, 0, -1, @@ -884,27 +923,26 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, mcon, event); + parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); } //else goto top; } if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { - parse_ss7_event(span, mcon, event); + parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); } //else goto top; } } check_state(span); - mcon->hb_elapsed += ms; -#if 0 - if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { + pcon->hb_elapsed += ms; + + if (pcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); mcon->up = 0; zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); } -#endif } From a0d04064f435f8dff1161a927cda86611b9331ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 22:37:55 +0000 Subject: [PATCH 0977/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@508 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_ss7_boost.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index 0238a50437..e030bb9d4b 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -214,8 +214,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + zap_set_string(event.calling_name, caller_data->cid_name); zap_set_string(event.redirection_string, caller_data->rdnis.digits); - OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; @@ -476,6 +476,9 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ zchan->sflags = 0; zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); + if (strlen(event->calling_name)) { + zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_name); + } zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); From 4bf8d37006c4df3499ba0c55ac5a2e2c16e478ed Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 22:37:55 +0000 Subject: [PATCH 0978/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@508 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_ss7_boost.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index 0238a50437..e030bb9d4b 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -214,8 +214,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + zap_set_string(event.calling_name, caller_data->cid_name); zap_set_string(event.redirection_string, caller_data->rdnis.digits); - OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; @@ -476,6 +476,9 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ zchan->sflags = 0; zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); + if (strlen(event->calling_name)) { + zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_name); + } zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); From 465329ea34d43d210231ba06bf5a291c0ba5f501 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Aug 2008 16:09:39 +0000 Subject: [PATCH 0979/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@509 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 10aa079f03..d28a754119 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -441,6 +441,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); + if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { + tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + } zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } } From 91b042092c243eb7fd1fdf9d361e4df95f0499c0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 11 Aug 2008 16:09:39 +0000 Subject: [PATCH 0980/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@509 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 10aa079f03..d28a754119 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -441,6 +441,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); + if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { + tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + } zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } } From 0fd7cd7b7b0e9f93935bcbcc4dfcba737095a4a1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Aug 2008 20:09:49 +0000 Subject: [PATCH 0981/1766] reinit properly git-svn-id: http://svn.openzap.org/svn/openzap/trunk@510 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 4 ++++ libs/openzap/src/zap_pika.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 52211d8fb1..c92083f914 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2102,6 +2102,8 @@ zap_status_t zap_global_init(void) { int modcount; + memset(&globals, 0, sizeof(globals)); + time_init(); zap_isdn_init(); zap_ss7_boost_init(); @@ -2224,6 +2226,8 @@ zap_status_t zap_global_destroy(void) hashtable_destroy(globals.interface_hash, 0, 0); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); + + memset(&globals, 0, sizeof(globals)); return ZAP_SUCCESS; } diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/zap_pika.c index 310cf5b1c1..ffe79e397c 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/zap_pika.c @@ -1330,6 +1330,8 @@ zap_status_t pika_destroy(void) 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, 0, 1); From 65b7c28ba03cd4dad92e05e2a5cf574ba411d145 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 14 Aug 2008 20:09:49 +0000 Subject: [PATCH 0982/1766] reinit properly git-svn-id: http://svn.openzap.org/svn/openzap/trunk@510 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 4 ++++ libs/freetdm/src/zap_pika.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 52211d8fb1..c92083f914 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2102,6 +2102,8 @@ zap_status_t zap_global_init(void) { int modcount; + memset(&globals, 0, sizeof(globals)); + time_init(); zap_isdn_init(); zap_ss7_boost_init(); @@ -2224,6 +2226,8 @@ zap_status_t zap_global_destroy(void) hashtable_destroy(globals.interface_hash, 0, 0); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); + + memset(&globals, 0, sizeof(globals)); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/zap_pika.c index 310cf5b1c1..ffe79e397c 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/zap_pika.c @@ -1330,6 +1330,8 @@ zap_status_t pika_destroy(void) 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, 0, 1); From a0d9ff1e562eb988fce9c2af67d52df7a5630954 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Aug 2008 20:45:05 +0000 Subject: [PATCH 0983/1766] merge in some boost changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@511 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/ss7_boost_client.h | 11 +- libs/openzap/src/ss7_boost_client.c | 144 +++++++++++--------- libs/openzap/src/zap_io.c | 6 + libs/openzap/src/zap_ss7_boost.c | 77 ++++++----- 4 files changed, 136 insertions(+), 102 deletions(-) diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/include/ss7_boost_client.h index f28f1900f3..292f8dc556 100644 --- a/libs/openzap/src/include/ss7_boost_client.h +++ b/libs/openzap/src/include/ss7_boost_client.h @@ -82,6 +82,12 @@ typedef struct ss7bc_ip_cfg int remote_port; }ss7bc_ip_cfg_t; +typedef enum { + MSU_FLAG_EVENT = (1 << 0), + MSU_FLAG_DOWN = (1 << 1) +} ss7bc_flag_t; + + struct ss7bc_connection { zap_socket_t socket; struct sockaddr_in local_addr; @@ -98,13 +104,8 @@ struct ss7bc_connection { unsigned int rxseq_reset; ss7bc_ip_cfg_t cfg; uint32_t hb_elapsed; - int up; }; -typedef enum { - MSU_FLAG_EVENT = (1 << 0) -} ss7bc_flag_t; - typedef struct ss7bc_connection ss7bc_connection_t; /* disable nagle's algorythm */ diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ss7_boost_client.c index 5699455854..20986b30f1 100644 --- a/libs/openzap/src/ss7_boost_client.c +++ b/libs/openzap/src/ss7_boost_client.c @@ -22,8 +22,8 @@ * "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, + * 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 @@ -40,10 +40,10 @@ #ifndef HAVE_GETHOSTBYNAME_R -extern int gethostbyname_r (const char *__name, - struct hostent *__result_buf, - char *__buf, size_t __buflen, - struct hostent **__result, +extern int gethostbyname_r (const char *__name, + struct hostent *__result_buf, + char *__buf, size_t __buflen, + struct hostent **__result, int *__h_errnop); #endif @@ -53,53 +53,53 @@ struct ss7bc_map { }; static struct ss7bc_map ss7bc_table[] = { - {SIGBOOST_EVENT_CALL_START, "CALL_START"}, - {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, - {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, - {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, - {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, - {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, - {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, - {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, - {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, - {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, - {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, + {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, + {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, + {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, + {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, + {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, + {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"} }; -static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *event, int priority, int dir,const char *file, const char *func, int line) +static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_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_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", - dir ? "TX":"RX", - ss7bc_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"), + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + dir ? "TX":"RX", + ss7bc_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") ); } -static void ss7bc_print_event_short(ss7bc_connection_t *mcon,ss7bc_short_event_t *event, int priority, int dir,const char *file, const char *func, int line) +static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_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_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", - dir ? "TX":"RX", - priority ? "P":"N", - ss7bc_event_id_name(event->event_id), - event->event_id, - event->span+1, - event->chan+1, - event->release_cause, - event->call_setup_id, + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + dir ? "TX":"RX", + priority ? "P":"N", + ss7bc_event_id_name(event->event_id), + event->event_id, + event->span+1, + event->chan+1, + event->release_cause, + event->call_setup_id, event->fseqno); } @@ -119,8 +119,8 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); #endif - zap_log(ZAP_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n", - local_ip,local_port,ip,port); + 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; @@ -149,13 +149,13 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca #endif if ((rc = bind(mcon->socket, - (struct sockaddr *) &mcon->local_addr, + (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); + rc=listen(mcon->socket, 100); if (rc) { close(mcon->socket); mcon->socket = -1; @@ -252,8 +252,6 @@ int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, in return 0; } - - ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line) { unsigned int fromlen = sizeof(struct sockaddr_in); @@ -279,20 +277,30 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, if (msg_ok){ - if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon,&mcon->event, 0, 0, file,func,line); - } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)&mcon->event, 0, 0, file,func,line); + if (ss7bc_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", + ss7bc_event_id_name(mcon->event.event_id)); + return NULL; + } } -#if 0 + if (boost_full_event(mcon->event.event_id)) { + ss7bc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); + } else { + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); + } + +#if 1 /* NC: NOT USED ANY MORE */ if (mcon->rxseq_reset) { - if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { + //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; @@ -328,9 +336,9 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, if (bytes == sizeof(ss7bc_short_event_t)) { if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon,&mcon->event, 1, 0, file,func,line); + ss7bc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line); } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)&mcon->event, 1, 0, file,func,line); + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 1, 0, file, func, line); } return &mcon->event; @@ -349,15 +357,15 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con { int err; int event_size=sizeof(ss7bc_event_t); - + if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); return -EINVAL; abort(); } if (event->span > 16 || event->chan > 31) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span, event->chan); abort(); return -1; } @@ -366,7 +374,17 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con event_size=sizeof(ss7bc_short_event_t); } - gettimeofday(&event->tv,NULL); + if (ss7bc_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", + ss7bc_event_id_name(event->event_id)); + return 0; + } + } + + gettimeofday(&event->tv, NULL); zap_mutex_lock(mcon->mutex); if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { @@ -387,9 +405,9 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon,event, 0, 1,file,func,line); + ss7bc_print_event_call(mcon, event, 0, 1, file, func, line); } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 0, 1,file,func,line); + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 0, 1, file, func, line); } return err; @@ -402,7 +420,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co int event_size=sizeof(ss7bc_event_t); if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); return -EINVAL; abort(); } @@ -411,7 +429,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co event_size=sizeof(ss7bc_short_event_t); } - gettimeofday(&event->tv,NULL); + gettimeofday(&event->tv, NULL); zap_mutex_lock(mcon->mutex); err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); @@ -423,9 +441,9 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon,event, 1, 1,file,func,line); + ss7bc_print_event_call(mcon, event, 1, 1, file, func, line); } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 1, 1,file,func,line); + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 1, 1, file, func, line); } return err; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index c92083f914..2c24cc5d85 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -675,6 +675,12 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ZAP_FAIL; } + if (zap_test_flag(zchan->span, ZAP_SPAN_SUSPENDED)) { + if (state != ZAP_CHANNEL_STATE_RESTART && state != ZAP_CHANNEL_STATE_DOWN) { + return ZAP_FAIL; + } + } + if (lock) { zap_mutex_lock(zchan->mutex); } diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/zap_ss7_boost.c index e030bb9d4b..4a26054029 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/zap_ss7_boost.c @@ -518,14 +518,7 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *even static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { -#if 0 -/* NC: Clear suspended on RESTART ACK */ - mcon->rxseq_reset = 0; - mcon->up = 1; - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); -#endif - mcon->hb_elapsed = 0; + zap_log(ZAP_LOG_DEBUG, "RECV RESTART ACK\n"); } @@ -534,10 +527,8 @@ static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_sho zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; mcon->rxseq_reset = 0; - mcon->up = 1; - + zap_set_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); mcon->hb_elapsed = 0; @@ -572,7 +563,6 @@ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss return; } - static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -582,13 +572,6 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho goto end; } - if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && - event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && - event->event_id != SIGBOOST_EVENT_HEARTBEAT && - event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART) { - goto end; - } - assert(event->call_setup_id <= MAX_REQ_ID); switch(event->event_id) { @@ -709,7 +692,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { + sig.event_id = ZAP_SIGEVENT_RESTART; + status = ss7_boost_data->signal_cb(&sig); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } break; case ZAP_CHANNEL_STATE_UP: @@ -814,14 +801,22 @@ static __inline__ void init_outgoing_array(void) static __inline__ void check_state(zap_span_t *span) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + int susp = zap_test_flag(span, ZAP_SPAN_SUSPENDED); - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + 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)) { + 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); @@ -839,7 +834,9 @@ static __inline__ void check_state(zap_span_t *span) 0); zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); + zap_clear_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); ss7_boost_data->mcon.hb_elapsed = 0; + init_outgoing_array(); } } @@ -852,7 +849,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10, too_long = 5000; + uint32_t ms = 10, too_long = 20000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -878,10 +875,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - //top: - - - init_outgoing_array(); + init_outgoing_array(); ss7bc_exec_commandp(pcon, 0, @@ -889,7 +883,8 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0); - + zap_set_flag(mcon, MSU_FLAG_DOWN); + while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; @@ -903,6 +898,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0); + zap_set_flag(mcon, MSU_FLAG_DOWN); break; } @@ -927,24 +923,37 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); - } //else goto top; + } } if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); - } //else goto top; + } } } - check_state(span); + pcon->hb_elapsed += ms; - if (pcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - mcon->up = 0; + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) || zap_test_flag(mcon, MSU_FLAG_DOWN)) { + pcon->hb_elapsed = 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); + ss7bc_exec_commandp(pcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + } + + if (zap_running()) { + check_state(span); } } From 9e4558ab13d2a6e96c134298d90b72f5073f50d1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 18 Aug 2008 20:45:05 +0000 Subject: [PATCH 0984/1766] merge in some boost changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@511 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/ss7_boost_client.h | 11 +- libs/freetdm/src/ss7_boost_client.c | 144 +++++++++++--------- libs/freetdm/src/zap_io.c | 6 + libs/freetdm/src/zap_ss7_boost.c | 77 ++++++----- 4 files changed, 136 insertions(+), 102 deletions(-) diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/include/ss7_boost_client.h index f28f1900f3..292f8dc556 100644 --- a/libs/freetdm/src/include/ss7_boost_client.h +++ b/libs/freetdm/src/include/ss7_boost_client.h @@ -82,6 +82,12 @@ typedef struct ss7bc_ip_cfg int remote_port; }ss7bc_ip_cfg_t; +typedef enum { + MSU_FLAG_EVENT = (1 << 0), + MSU_FLAG_DOWN = (1 << 1) +} ss7bc_flag_t; + + struct ss7bc_connection { zap_socket_t socket; struct sockaddr_in local_addr; @@ -98,13 +104,8 @@ struct ss7bc_connection { unsigned int rxseq_reset; ss7bc_ip_cfg_t cfg; uint32_t hb_elapsed; - int up; }; -typedef enum { - MSU_FLAG_EVENT = (1 << 0) -} ss7bc_flag_t; - typedef struct ss7bc_connection ss7bc_connection_t; /* disable nagle's algorythm */ diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ss7_boost_client.c index 5699455854..20986b30f1 100644 --- a/libs/freetdm/src/ss7_boost_client.c +++ b/libs/freetdm/src/ss7_boost_client.c @@ -22,8 +22,8 @@ * "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, + * 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 @@ -40,10 +40,10 @@ #ifndef HAVE_GETHOSTBYNAME_R -extern int gethostbyname_r (const char *__name, - struct hostent *__result_buf, - char *__buf, size_t __buflen, - struct hostent **__result, +extern int gethostbyname_r (const char *__name, + struct hostent *__result_buf, + char *__buf, size_t __buflen, + struct hostent **__result, int *__h_errnop); #endif @@ -53,53 +53,53 @@ struct ss7bc_map { }; static struct ss7bc_map ss7bc_table[] = { - {SIGBOOST_EVENT_CALL_START, "CALL_START"}, - {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, - {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, - {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, - {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, - {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, - {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, - {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, - {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, - {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, - {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK_ACK, "CALL_START_NACK_ACK"}, + {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, + {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, + {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, + {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, + {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, + {SIGBOOST_EVENT_INSERT_CHECK_LOOP, "LOOP START"}, {SIGBOOST_EVENT_REMOVE_CHECK_LOOP, "LOOP STOP"} }; -static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *event, int priority, int dir,const char *file, const char *func, int line) +static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_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_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", - dir ? "TX":"RX", - ss7bc_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"), + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + dir ? "TX":"RX", + ss7bc_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") ); } -static void ss7bc_print_event_short(ss7bc_connection_t *mcon,ss7bc_short_event_t *event, int priority, int dir,const char *file, const char *func, int line) +static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_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_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", - dir ? "TX":"RX", - priority ? "P":"N", - ss7bc_event_id_name(event->event_id), - event->event_id, - event->span+1, - event->chan+1, - event->release_cause, - event->call_setup_id, + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + dir ? "TX":"RX", + priority ? "P":"N", + ss7bc_event_id_name(event->event_id), + event->event_id, + event->span+1, + event->chan+1, + event->release_cause, + event->call_setup_id, event->fseqno); } @@ -119,8 +119,8 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); #endif - zap_log(ZAP_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n", - local_ip,local_port,ip,port); + 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; @@ -149,13 +149,13 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca #endif if ((rc = bind(mcon->socket, - (struct sockaddr *) &mcon->local_addr, + (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); + rc=listen(mcon->socket, 100); if (rc) { close(mcon->socket); mcon->socket = -1; @@ -252,8 +252,6 @@ int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, in return 0; } - - ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line) { unsigned int fromlen = sizeof(struct sockaddr_in); @@ -279,20 +277,30 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, if (msg_ok){ - if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon,&mcon->event, 0, 0, file,func,line); - } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)&mcon->event, 0, 0, file,func,line); + if (ss7bc_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", + ss7bc_event_id_name(mcon->event.event_id)); + return NULL; + } } -#if 0 + if (boost_full_event(mcon->event.event_id)) { + ss7bc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); + } else { + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); + } + +#if 1 /* NC: NOT USED ANY MORE */ if (mcon->rxseq_reset) { - if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { + //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; @@ -328,9 +336,9 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, if (bytes == sizeof(ss7bc_short_event_t)) { if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon,&mcon->event, 1, 0, file,func,line); + ss7bc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line); } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)&mcon->event, 1, 0, file,func,line); + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 1, 0, file, func, line); } return &mcon->event; @@ -349,15 +357,15 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con { int err; int event_size=sizeof(ss7bc_event_t); - + if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); return -EINVAL; abort(); } if (event->span > 16 || event->chan > 31) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span,event->chan); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", ss7bc_event_id_name(event->event_id), event->span, event->chan); abort(); return -1; } @@ -366,7 +374,17 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con event_size=sizeof(ss7bc_short_event_t); } - gettimeofday(&event->tv,NULL); + if (ss7bc_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", + ss7bc_event_id_name(event->event_id)); + return 0; + } + } + + gettimeofday(&event->tv, NULL); zap_mutex_lock(mcon->mutex); if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { @@ -387,9 +405,9 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon,event, 0, 1,file,func,line); + ss7bc_print_event_call(mcon, event, 0, 1, file, func, line); } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 0, 1,file,func,line); + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 0, 1, file, func, line); } return err; @@ -402,7 +420,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co int event_size=sizeof(ss7bc_event_t); if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); + zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: No Event Device\n"); return -EINVAL; abort(); } @@ -411,7 +429,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co event_size=sizeof(ss7bc_short_event_t); } - gettimeofday(&event->tv,NULL); + gettimeofday(&event->tv, NULL); zap_mutex_lock(mcon->mutex); err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); @@ -423,9 +441,9 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon,event, 1, 1,file,func,line); + ss7bc_print_event_call(mcon, event, 1, 1, file, func, line); } else { - ss7bc_print_event_short(mcon,(ss7bc_short_event_t*)event, 1, 1,file,func,line); + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 1, 1, file, func, line); } return err; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index c92083f914..2c24cc5d85 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -675,6 +675,12 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ZAP_FAIL; } + if (zap_test_flag(zchan->span, ZAP_SPAN_SUSPENDED)) { + if (state != ZAP_CHANNEL_STATE_RESTART && state != ZAP_CHANNEL_STATE_DOWN) { + return ZAP_FAIL; + } + } + if (lock) { zap_mutex_lock(zchan->mutex); } diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/zap_ss7_boost.c index e030bb9d4b..4a26054029 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/zap_ss7_boost.c @@ -518,14 +518,7 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *even static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { -#if 0 -/* NC: Clear suspended on RESTART ACK */ - mcon->rxseq_reset = 0; - mcon->up = 1; - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); -#endif - mcon->hb_elapsed = 0; + zap_log(ZAP_LOG_DEBUG, "RECV RESTART ACK\n"); } @@ -534,10 +527,8 @@ static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_sho zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; mcon->rxseq_reset = 0; - mcon->up = 1; - + zap_set_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); mcon->hb_elapsed = 0; @@ -572,7 +563,6 @@ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss return; } - static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -582,13 +572,6 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho goto end; } - if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && - event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && - event->event_id != SIGBOOST_EVENT_HEARTBEAT && - event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART) { - goto end; - } - assert(event->call_setup_id <= MAX_REQ_ID); switch(event->event_id) { @@ -709,7 +692,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_RESTART: { + sig.event_id = ZAP_SIGEVENT_RESTART; + status = ss7_boost_data->signal_cb(&sig); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } break; case ZAP_CHANNEL_STATE_UP: @@ -814,14 +801,22 @@ static __inline__ void init_outgoing_array(void) static __inline__ void check_state(zap_span_t *span) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + int susp = zap_test_flag(span, ZAP_SPAN_SUSPENDED); - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + 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)) { + 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); @@ -839,7 +834,9 @@ static __inline__ void check_state(zap_span_t *span) 0); zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); + zap_clear_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); ss7_boost_data->mcon.hb_elapsed = 0; + init_outgoing_array(); } } @@ -852,7 +849,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10, too_long = 5000; + uint32_t ms = 10, too_long = 20000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -878,10 +875,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) mcon = &ss7_boost_data->mcon; pcon = &ss7_boost_data->pcon; - //top: - - - init_outgoing_array(); + init_outgoing_array(); ss7bc_exec_commandp(pcon, 0, @@ -889,7 +883,8 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0); - + zap_set_flag(mcon, MSU_FLAG_DOWN); + while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; @@ -903,6 +898,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0); + zap_set_flag(mcon, MSU_FLAG_DOWN); break; } @@ -927,24 +923,37 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (FD_ISSET(pcon->socket, &rfds)) { if ((event = ss7bc_connection_readp(pcon, i))) { parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); - } //else goto top; + } } if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); - } //else goto top; + } } } - check_state(span); + pcon->hb_elapsed += ms; - if (pcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - mcon->up = 0; + if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) || zap_test_flag(mcon, MSU_FLAG_DOWN)) { + pcon->hb_elapsed = 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); + ss7bc_exec_commandp(pcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + } + + if (zap_running()) { + check_state(span); } } From 9bcabce6e8d2f5778dafa4b4101a508f9d1b2fcd Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 22 Aug 2008 16:55:01 +0000 Subject: [PATCH 0985/1766] Add initial Basic Rate Interface (BRI) support... Short summary of changes: (Massive) rework of the Q.921 layer Q.931 changes to get BRI PTMP working and cleanups (more to come...) Add Hi-Layer compat and Progress IE to outgoing SETUP messages Improve handling of call tear-down in zap_isdn.c Open ZAP I/O channels after processing the dialplan for incoming calls Bearer Capability and Channel ID IE handling improved for BRI/PRI and A-law/u-law ...and a lot of other small changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@512 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.gitignore | 12 + libs/openzap/mod_openzap/mod_openzap.c | 7 +- libs/openzap/src/include/openzap.h | 15 +- libs/openzap/src/include/zap_isdn.h | 3 +- libs/openzap/src/include/zap_types.h | 3 +- libs/openzap/src/isdn/5ESSStateTE.c | 4 +- libs/openzap/src/isdn/5ESSmes.c | 7 +- libs/openzap/src/isdn/DMSStateTE.c | 4 +- libs/openzap/src/isdn/DMSmes.c | 7 +- libs/openzap/src/isdn/Q921.c | 3399 ++++++++++++++++++++-- libs/openzap/src/isdn/Q931.c | 298 +- libs/openzap/src/isdn/Q931StateNT.c | 92 +- libs/openzap/src/isdn/Q931StateTE.c | 91 +- libs/openzap/src/isdn/Q931api.c | 22 +- libs/openzap/src/isdn/Q931ie.c | 295 +- libs/openzap/src/isdn/Q931mes.c | 301 +- libs/openzap/src/isdn/include/Q921.h | 169 +- libs/openzap/src/isdn/include/Q921priv.h | 298 ++ libs/openzap/src/isdn/include/Q931.h | 361 ++- libs/openzap/src/isdn/include/Q931ie.h | 7 +- libs/openzap/src/isdn/include/mfifo.h | 14 +- libs/openzap/src/isdn/mfifo.c | 208 +- libs/openzap/src/isdn/nationalStateTE.c | 3 + libs/openzap/src/isdn/nationalmes.c | 7 +- libs/openzap/src/zap_isdn.c | 580 +++- 25 files changed, 5148 insertions(+), 1059 deletions(-) create mode 100644 libs/openzap/.gitignore create mode 100644 libs/openzap/src/isdn/include/Q921priv.h diff --git a/libs/openzap/.gitignore b/libs/openzap/.gitignore new file mode 100644 index 0000000000..e767f23aa1 --- /dev/null +++ b/libs/openzap/.gitignore @@ -0,0 +1,12 @@ +*.o +*.lo +*.so +*.a +*.orig +*.rej +*.log + +Makefile +config.* +configure + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d28a754119..a40b49e1fd 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -673,6 +673,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } + static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) { switch_channel_t *channel; @@ -690,7 +691,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, if (switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } } break; @@ -700,7 +701,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } break; @@ -709,7 +710,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, if (switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } break; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4fb5c737ad..26b050181e 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -134,8 +134,8 @@ #include "libteletone.h" #include "zap_buffer.h" #include "zap_threadmutex.h" -#include "Q931.h" #include "Q921.h" +#include "Q931.h" #define XX if (0) @@ -232,6 +232,19 @@ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } +#define zap_set_state_locked_wait(obj, s) \ + do { \ + int __safety = 100; \ + zap_set_state_locked(obj, s); \ + while(__safety-- && zap_test_flag(obj, ZAP_CHANNEL_STATE_CHANGE)) { \ + zap_sleep(10); \ + } \ + if(!__safety) { \ + zap_log(ZAP_LOG_CRIT, "State change not completed\n"); \ + } \ + } while(0); + + typedef enum { ZAP_STATE_CHANGE_FAIL, ZAP_STATE_CHANGE_SUCCESS, diff --git a/libs/openzap/src/include/zap_isdn.h b/libs/openzap/src/include/zap_isdn.h index 91f35b2a9b..e18a51ab0a 100644 --- a/libs/openzap/src/include/zap_isdn.h +++ b/libs/openzap/src/include/zap_isdn.h @@ -53,10 +53,11 @@ struct zap_isdn_data { struct zap_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; + int32_t mode; + 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]; - zap_isdn_opts_t opts; }; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index be43d0d069..7c092e7f70 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -117,11 +117,12 @@ typedef enum { ZAP_TRUNK_T1, ZAP_TRUNK_J1, ZAP_TRUNK_BRI, + ZAP_TRUNK_BRI_PTMP, ZAP_TRUNK_FXO, ZAP_TRUNK_FXS, ZAP_TRUNK_NONE } zap_trunk_type_t; -#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE" +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "NONE" ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) typedef enum { diff --git a/libs/openzap/src/isdn/5ESSStateTE.c b/libs/openzap/src/isdn/5ESSStateTE.c index 05a11b0c5c..a9654ce723 100644 --- a/libs/openzap/src/isdn/5ESSStateTE.c +++ b/libs/openzap/src/isdn/5ESSStateTE.c @@ -240,7 +240,7 @@ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -283,7 +283,7 @@ L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c index 6a6f4684d1..da47f7ac5b 100644 --- a/libs/openzap/src/isdn/5ESSmes.c +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -158,12 +158,7 @@ L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) diff --git a/libs/openzap/src/isdn/DMSStateTE.c b/libs/openzap/src/isdn/DMSStateTE.c index 565841589e..8c435fa8c2 100644 --- a/libs/openzap/src/isdn/DMSStateTE.c +++ b/libs/openzap/src/isdn/DMSStateTE.c @@ -237,7 +237,7 @@ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -279,7 +279,7 @@ L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/openzap/src/isdn/DMSmes.c b/libs/openzap/src/isdn/DMSmes.c index 57aeddfb0d..b32664b767 100644 --- a/libs/openzap/src/isdn/DMSmes.c +++ b/libs/openzap/src/isdn/DMSmes.c @@ -155,12 +155,7 @@ L3INT DMSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 2dad5cf006..a682c2342e 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -37,12 +37,323 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "Q921.h" + +/**************************************************************************** + * 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" -int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); + +/****************************************************************************************************** + * 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; +} /***************************************************************************** @@ -52,47 +363,461 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); function MUST be called before you call any other functions. *****************************************************************************/ -void Q921_InitTrunk(L2TRUNK trunk, +int Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser, + Q921NetType_t NetType, L2INT hsize, - Q921TxCB_t cb21, - Q921TxCB_t cb23, + Q921Tx21CB_t cb21, + Q921Tx23CB_t cb23, void *priv21, void *priv23) { - if (trunk->initialized != INITIALIZED_MAGIC) { - MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); - trunk->initialized = INITIALIZED_MAGIC; - } - trunk->va = 0; - trunk->vs = 0; - trunk->vr = 0; - trunk->state = 0; + 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; - trunk->T200 = 0; - trunk->T203 = 0; - trunk->T200Timeout = 1000; - trunk->T203Timeout = 10000; + + 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; } -int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) + +/** + * 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); } -int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) -{ - return trunk->Q921Tx23Proc(trunk->PrivateData23, 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]; + L2INT len, left; + va_list ap; + + if(!trunk->Q921LogProc) + return 0; + + if(trunk->loglevel < level) + return 0; + + if(!mes) + return 0; + + + 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]; + L2INT pleft, poffset; + L2UCHAR sapi, tei, cr; + L2UCHAR *pmes = mes + trunk->Q921HeaderSpace; + struct Q921_Link *link; + + 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, 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, 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: + return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, strlen(buf)); } /***************************************************************************** @@ -105,82 +830,468 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) Return Value: none *****************************************************************************/ -L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ -L2ULONG tLast = {0}; +static L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ +static L2ULONG tLast = {0}; -L2ULONG Q921GetTime(void) +static L2ULONG Q921GetTime(void) { - L2ULONG tNow = 0; - if(Q921GetTimeProc != NULL) - { - tNow = Q921GetTimeProc(); - if(tNow < tLast) /* wrapped */ - { + L2ULONG tNow = 0; + + if(Q921GetTimeProc) + { + tNow = Q921GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { /* TODO */ - } + } tLast = tNow; - } - return tNow; + } + return tNow; } -void Q921T200TimerStart(L2TRUNK trunk) +/* + * T200 handling (per-TEI in PTMP NT mode, tei=0 otherwise) + */ +static void Q921T200TimerStart(L2TRUNK trunk, L2UCHAR tei) { - if (!trunk->T200) { - trunk->T200 = Q921GetTime() + trunk->T200Timeout; + 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); } } -void Q921T200TimerStop(L2TRUNK trunk) +static void Q921T200TimerStop(L2TRUNK trunk, L2UCHAR tei) { - trunk->T200 = 0; + struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei); + + link->T200 = 0; + + Q921Log(trunk, Q921_LOG_DEBUG, "T200 stopped for TEI %d\n", tei); } -void Q921T200TimerReset(L2TRUNK trunk) +static void Q921T200TimerReset(L2TRUNK trunk, L2UCHAR tei) { - Q921T200TimerStop(trunk); - Q921T200TimerStart(trunk); + 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); } -void Q921T203TimerStart(L2TRUNK trunk) +/* + * T203 handling (per-TEI in PTMP NT mode, tei=0 otherwise) + */ +static void Q921T203TimerStart(L2TRUNK trunk, L2UCHAR tei) { - if (!trunk->T203) { - trunk->T203 = Q921GetTime() + trunk->T203Timeout; + 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); } } -void Q921T203TimerStop(L2TRUNK trunk) +static void Q921T203TimerStop(L2TRUNK trunk, L2UCHAR tei) { - trunk->T203 = 0; + struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei); + + link->T203 = 0; + + Q921Log(trunk, Q921_LOG_DEBUG, "T203 stopped for TEI %d\n", tei); } -void Q921T203TimerReset(L2TRUNK trunk) +static void Q921T203TimerReset(L2TRUNK trunk, L2UCHAR tei) { - Q921T203TimerStop(trunk); - Q921T203TimerStart(trunk); + 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); } -void Q921T200TimerExpire(L2TRUNK trunk) +/* + * T202 handling (TEI message timeout, TE mode only) + */ +static void Q921T202TimerStart(L2TRUNK trunk) { - (void)trunk; + if (!trunk->T202) { + trunk->T202 = Q921GetTime() + trunk->T202Timeout; + + Q921Log(trunk, Q921_LOG_DEBUG, "T202 (timeout: %d msecs) started\n", trunk->T202Timeout); + } } -void Q921T203TimerExpire(L2TRUNK trunk) +static void Q921T202TimerStop(L2TRUNK trunk) { - Q921T203TimerReset(trunk); - Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); + 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(); - if (trunk->T200 && tNow > trunk->T200) { - Q921T200TimerExpire(trunk); - } - if (trunk->T203 && tNow > trunk->T203) { - Q921T203TimerExpire(trunk); - } -} + 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)) { @@ -211,45 +1322,292 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size) return MFIFOWriteMes(trunk->HDLCInQueue, b, size); } -/***************************************************************************** - - Function: Q921SendI - - Description: Compose and Send I Frame to layer. Will receive an I frame - with space for L2 header and fill out that header before - it call Q921Tx21Proc. - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - mes ptr to I frame message. - size size of message in bytes. - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT 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) { - mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; - mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); - trunk->vs++; + struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, Tei); - return Q921Tx21Proc(trunk, mes, size); + /* 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; } -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) +/** + * Q921SendQueuedIFrame + * \brief Try to transmit queued I frame (if available) + */ +static int Q921SendQueuedIFrame(L2TRUNK trunk, L2UCHAR tei) { - return Q921SendI(trunk, - trunk->sapi, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, - 0, - Mes, - Size); + 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; } /***************************************************************************** @@ -267,16 +1625,11 @@ int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) *****************************************************************************/ -int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); + return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x00, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -294,16 +1647,11 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); + return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x01, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -321,16 +1669,11 @@ int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); + return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x03, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -348,31 +1691,150 @@ int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + 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) { - return Q921SendSABME(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, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, + 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: Comose and Send DM (Disconnected Mode) + Description: Compose and Send DM (Disconnected Mode) Parameters: trunk trunk # Sapi Sapi @@ -383,15 +1845,11 @@ int Q921Start(L2TRUNK trunk) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x03, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -409,15 +1867,11 @@ int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x08, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -435,30 +1889,1000 @@ int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x0c, mes, trunk->Q921HeaderSpace+3); } -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) +static int Q921SendUN(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf, L2UCHAR *mes, L2INT size) { - /* TODO: Do we need these paramaters? */ - (void)mes; - (void)size; - - trunk->vr=0; - trunk->vs=0; - trunk->va=0; - - return 1; + 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 @@ -479,80 +2903,597 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) *****************************************************************************/ int Q921Rx12(L2TRUNK trunk) { - L2UCHAR *mes; - L2INT rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - L2UCHAR nr; + L2INT size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - if(smes != NULL) - { - rs = size - trunk->Q921HeaderSpace; - mes = &smes[trunk->Q921HeaderSpace]; + if(smes) + { + struct Q921_Link *link; + L2UCHAR sapi, tei; + L2UCHAR *mes; + L2INT rs; - if ((mes[2] & 3) != 3) { - /* we have an S or I frame */ - /* if nr is between va and vs, update our va counter */ - nr = (mes[3] >> 1); - if (nr >= trunk->va && nr <= trunk->vs) { - trunk->va = nr; - } + 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; } - /* check for I frame */ - if((mes[2] & 0x01) == 0) - { + 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 */ + } - /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ - trunk->vr++; - if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ - { - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - /* trunk->vr--; */ - /* for now, lets just respond for easier debugging on errors */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); - } - } +out: + MFIFOKillNext(trunk->HDLCInQueue); - /* check for RR */ - else if(mes[2] ==0x01) - { - if (((mes[0]>>1)&0x01) == (trunk->NetUser == Q921_TE ? 1 : 0)) { /* if this is a command */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[2]&0x01); - } + return 1; + } - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(trunk->HDLCInQueue); - - return 1; - } - return 0; + 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; + + 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; + + link->ri = (L2USHORT)(random() % 0xffff); + + /* 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 index 12ebde2660..6591613d71 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#include "Q921.h" #include "Q931.h" #include "national.h" #include "DMS.h" @@ -67,6 +68,8 @@ 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)= { @@ -250,6 +253,10 @@ void Q931Initialize() 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) @@ -286,28 +293,38 @@ void Q931Initialize() } } -/***************************************************************************** - - Function: Q931TimeTick - - Description: Called periodically from an external source to allow the - stack to process and maintain it's own timers. - - Parameters: ms[IN] Milliseconds since last call. - - Return Value: none - -*****************************************************************************/ -void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms) +/** + * Q931TimerTick + * \brief Periodically called to update and check for expired timers + * \param pTrunk Q.931 trunk + */ +void Q931TimerTick(Q931_TrunkInfo_t *pTrunk) { - (void)pTrunk; - ms=ms; /* avoid warning for now. */ + 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. - */ + /* 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); + } + } } /***************************************************************************** @@ -331,39 +348,65 @@ void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) +L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT Size) { - L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; - Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; - L3INT ISize; + L3UCHAR *Mes = NULL; + L3INT RetCode = Q931E_NO_ERROR; + Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; + L3INT ISize; + L3INT IOff = 0; + L3INT L2HSize = Q931L2HeaderSpace; - L3INT IOff = 0; + switch(ind) { + case Q921_DL_UNIT_DATA: /* DL-UNITDATA indication (UI frame, 3 byte header) */ + L2HSize = 3; - /* Reset our decode buffer */ - memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf)); + case Q921_DL_DATA: /* DL-DATA indication (I frame, 4 byte header) */ + /* Reset our decode buffer */ + memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf)); - /* Protocol Discriminator */ - m->ProtDisc = Mes[IOff++]; + /* L2 Header Offset */ + Mes = &buf[L2HSize]; - /* CRV */ - m->CRVFlag = Mes[IOff + 1] & 0x80; - m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); + /* Protocol Discriminator */ + m->ProtDisc = Mes[IOff++]; - /* Message Type */ - m->MesType = Mes[IOff++]; + /* CRV */ + m->CRVFlag = (Mes[IOff + 1] >> 7) & 0x01; + m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); - /* Call table proc to unpack codec message */ - /*debug */ - /* printf("\n\nQ931Rx23- Dialect: %d, MsgType: %d\n",pTrunk->Dialect,m->MesType); */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); + /* Message Type */ + m->MesType = Mes[IOff++]; - if(RetCode >= Q931E_NO_ERROR) - { - RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); - } + /* 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; - return RetCode; + /* 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, 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; } /***************************************************************************** @@ -381,6 +424,8 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) *****************************************************************************/ 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); } @@ -406,7 +451,11 @@ L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; - RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + 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; } @@ -428,25 +477,42 @@ L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) +L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size) { - L3INT OSize; - Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; - L3INT RetCode = Q931E_NO_ERROR; - L3INT iDialect = pTrunk->Dialect; + Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; + L3INT RetCode = Q931E_NO_ERROR; + L3INT iDialect = pTrunk->Dialect; + L3INT Offset = bcast ? (Q931L2HeaderSpace - 1) : Q931L2HeaderSpace; + L3INT OSize; - /* Call pack function through table. */ - RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { - if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); - } else { - RetCode = Q931E_MISSING_CB; - } - } + Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending message to Q.921 (size: %d)\n", Size); - return RetCode; + 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; } @@ -575,28 +641,40 @@ L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) return 0; /* assume state zero for non existing CRV's */ } -/***************************************************************************** - - Function: Q931StartTimer - - Description: Start a timer. - - Parameters: pTrunk Trunk number - callindex call index. - iTimer timer id -*****************************************************************************/ +/** + * 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) { - pTrunk->call[callIndex].Timer = Q931GetTime(); - pTrunk->call[callIndex].TimerID = iTimerID; - return 0; + L3ULONG duration = Q931Timer[pTrunk->Dialect][iTimerID]; + + if(duration) { + pTrunk->call[callIndex].Timer = Q931GetTime() + duration; + pTrunk->call[callIndex].TimerID = iTimerID; + } + + 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; + if(pTrunk->call[callindex].TimerID == iTimerID) + pTrunk->call[callindex].TimerID = 0; + + return 0; } L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) @@ -609,7 +687,8 @@ L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) L3ULONG Q931GetTime() { L3ULONG tNow = 0; - static L3ULONG tLast={0}; + static L3ULONG tLast = 0; + if(Q931GetTimeProc != NULL) { tNow = Q931GetTimeProc(); @@ -758,5 +837,68 @@ const char *q931_error_to_name(q931_error_t error) } 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) +{ + 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 index 3343170786..af74ef0e8b 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -116,11 +116,34 @@ void Q931CreateNT(L3UCHAR i) 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); + /* 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 */ } /***************************************************************************** @@ -143,7 +166,7 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -175,7 +198,7 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -208,7 +231,7 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -241,7 +264,7 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -274,7 +297,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -313,7 +336,10 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; pMes->CRV = pTrunk->call[callIndex].CRV; - ret = Q931Tx32(pTrunk,buf,pMes->Size); + /* + * 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; @@ -389,7 +415,7 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -422,7 +448,7 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -455,7 +481,7 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -488,7 +514,7 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -521,7 +547,7 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -554,7 +580,7 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -587,7 +613,7 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -620,7 +646,7 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -653,7 +679,7 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -686,7 +712,7 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -719,7 +745,7 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -752,7 +778,7 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -785,7 +811,7 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -818,7 +844,7 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -851,7 +877,7 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -884,7 +910,7 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -917,7 +943,7 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -950,7 +976,7 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -983,7 +1009,7 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1020,7 +1046,7 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1053,7 +1079,7 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1086,7 +1112,7 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1119,7 +1145,7 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1152,7 +1178,7 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1185,7 +1211,7 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1218,7 +1244,7 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1251,7 +1277,7 @@ L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index da028b5867..552b39ff27 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -123,6 +123,9 @@ void Q931CreateTE(L3UCHAR i) 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); + /* 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.*/ @@ -205,6 +208,24 @@ void Q931CreateTE(L3UCHAR i) 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 */ } /***************************************************************************** @@ -227,7 +248,7 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -259,7 +280,7 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -292,7 +313,7 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -329,7 +350,7 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -362,7 +383,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -399,7 +420,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; pMes->CRV = pTrunk->call[callIndex].CRV; - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); if(ret) return ret; @@ -475,7 +496,7 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -504,7 +525,7 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) pMes->CRV = pTrunk->call[callIndex].CRV; /* Send RESUME to network */ - ret=Q931Tx32(pTrunk,buf, pMes->Size); + ret=Q931Tx32Data(pTrunk,0,buf, pMes->Size); if(ret != Q931E_NO_ERROR) return ret; @@ -544,7 +565,7 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -577,7 +598,7 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -610,7 +631,7 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -643,7 +664,7 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -676,7 +697,7 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -709,7 +730,7 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -730,6 +751,9 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret=Q931E_NO_ERROR; Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + 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) @@ -742,7 +766,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -765,7 +789,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret = Q931E_NO_ERROR; if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if(state == Q931_U0 && iFrom == 2) { Q931Tx34(pTrunk,buf,pMes->Size); ret = Q931ReleaseComplete(pTrunk, buf); @@ -805,6 +829,9 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i 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); } } @@ -838,7 +865,7 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -877,7 +904,7 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -910,7 +937,7 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -943,7 +970,7 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -976,7 +1003,7 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1009,7 +1036,7 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1042,7 +1069,7 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1075,7 +1102,7 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1112,7 +1139,7 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1145,7 +1172,7 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1178,7 +1205,7 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1211,7 +1238,7 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1244,7 +1271,7 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1277,7 +1304,7 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1310,7 +1337,7 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1343,7 +1370,7 @@ L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index b0119ef68c..c7200d568d 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -74,8 +74,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, - Q931TxCB_t Q931Tx34CBProc, - Q931TxCB_t Q931Tx32CBProc, + Q931Tx34CB_t Q931Tx34CBProc, + Q931Tx32CB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, void *PrivateData32, void *PrivateData34) @@ -97,6 +97,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, break; case Q931_TrType_BRI: + case Q931_TrType_BRI_PTMP: dchannel = 3; maxchans = 3; break; @@ -166,6 +167,16 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q9 Q931Uie[dialect][iec] = Q931UieProc; } +void Q931SetTimeoutProc(L3UCHAR timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc) +{ + if(Q931Timeout != NULL) + Q931Timeout[dialect][timer] = Q931TimeoutProc; +} + +void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout) +{ + Q931Timer[dialect][timer] = timeout; +} L3INT Q931GetMesSize(Q931mes_Generic *pMes) { @@ -212,8 +223,11 @@ 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++; - if (crv > 32766) crv = 1; + crv = (crv <= max) ? crv : 1; + return crv; } @@ -523,7 +537,7 @@ 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 Q931Tx32(pTrunk,buf,ptr->Size); + return Q931Tx32Data(pTrunk,0,buf,ptr->Size); } L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 6c77d32a47..983e158aee 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -318,73 +318,74 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, 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) | (pIE->ITC & 0x1f); + OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | (pIE->ITC & 0x1f); /* Octet 4 - Transfer mode / Information transfer rate */ - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + OBuf[(*Octet)++] = 0x80 | ((pIE->TransMode << 5) & 0x60) | (pIE->ITR & 0x1f); + if(pIE->ITR == 0x18) { /* Octet 4.1 - Rate Multiplier */ - OBuf[(*Octet)++] = 0x80 | pIE->RateMul; + OBuf[(*Octet)++] = 0x80 | (pIE->RateMul & 0x7f); } - /* Octet 5 - Layer 1 Ident / User information layer 1 protocol*/ + /* 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))) + 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) | (pIE->UIL1Prot & 0x15); + OBuf[(*Octet)++] = 0x00 | ((pIE->Layer1Ident << 5) & 0x60) | (pIE->UIL1Prot & 0x15); /* Octet 5a - SyncAsync/Negot/UserRate */ - OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (pIE->UserRate&0x1f); + 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) - | (pIE->NIConTx << 4) - | (pIE->NIConRx << 3) - | (pIE->FlowCtlTx << 2) - | (pIE->FlowCtlRx << 1); + | ((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) - | (pIE->MultiFrame << 5) - | (pIE->Mode << 4) - | (pIE->LLInegot << 3) - | (pIE->Assignor << 2) - | (pIE->InBandNeg << 1); + | ((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 ) - | (pIE->NumDataBits << 3 ) - | (pIE->Parity); + | ((pIE->NumStopBits << 5) & 0x60) + | ((pIE->NumDataBits << 3) & 0x18) + | (pIE->Parity & 0x07); /* Octet 5d - Duplex Mode/Modem Type */ - OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); + OBuf[(*Octet)++] = 0x80 | ((pIE->DuplexMode << 6) & 0x40) | (pIE->ModemType & 0x3f); } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x1F); + 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) | (pIE->UIL2Prot); + if(pIE->Layer2Ident == 0x02) { + OBuf[(*Octet)++] = 0x80 | ((pIE->Layer2Ident << 5) & 0x60) | (pIE->UIL2Prot & 0x1f); } /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ @@ -392,17 +393,16 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, { if(pIE->UIL3Prot == 0x0c) { - OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + OBuf[(*Octet)++] = 0x00 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f); /* Octet 7a - Additional information layer 3 msb */ - OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); + OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1 & 0x0f); /* Octet 7b - Additional information layer 3 lsb */ - OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); + OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2 & 0x0f); } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + else { + OBuf[(*Octet)++] = 0x80 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f); } } @@ -1152,76 +1152,107 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, *****************************************************************************/ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { - Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; + Q931ie_ChanID *pie = (Q931ie_ChanID*)OBuf; ie *pIE = &pMsg->ChanID; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; //18 04 e1 80 83 01 - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + Q931Log(pTrunk, Q931_LOG_DEBUG, "Decoding ChanID IE\n"); - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 1 */ + pie->IEId = 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; + /* Octet 2 */ + IESize = IBuf[Octet++]; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); - 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; - /* Octet 3.1 */ + Off = Q931ReadExt(&IBuf[Octet++], Off); - if(pie->IntIDPresent) - { - pie->InterfaceID = IBuf[Octet+Off] & 0x7f; + /* 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++; - } + /* 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; + 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++; - Off ++; + /* Octet 3.3 */ + /* Temp fix. Assume B channel. H channels not supported */ + pie->ChanSlot = IBuf[Octet+Off] & 0x7f; - - /* 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) { + if((Octet + Off - 1) != IESize) { Off = Q931ReadExt(&IBuf[Octet+Off], Off); } - Off++; - } - } + Off++; + } + } - Q931IESizeTest(Q931E_CHANID); + Q931IESizeTest(Q931E_CHANID); - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ChanID); + pie->Size = sizeof(Q931ie_ChanID); - return Q931E_NO_ERROR; + 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; } /***************************************************************************** @@ -1238,24 +1269,24 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * 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 rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; /* remember current offset */ L3INT li; OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION; - li=(*Octet)++; /* remember length position */ + li = (*Octet)++; /* remember length position */ /* Octet 3 flags & BRI chan # */ OBuf[(*Octet)++] = 0x80 - | (pIE->IntIDPresent << 6) - | (pIE->IntType<<5) - | (pIE->PrefExcl<<3) - | pIE->InfoChanSel; + | ((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; + OBuf[(*Octet)++] = 0x80 | (pIE->InterfaceID & 0x7f); } else { @@ -1263,12 +1294,21 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I if(pIE->IntType == 1) { OBuf[(*Octet)++] = 0x80 - | (pIE->CodStand << 5) - | (pIE->NumMap << 4) - | pIE->ChanMapType; + | ((pIE->CodStand << 5) & 0x60) + | ((pIE->NumMap << 4) & 0x10) + | (pIE->ChanMapType & 0x0f); /* TODO: support all possible channel map types */ - /* Octet 3.2 Channel number/slot map */ - OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; + /* 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; + } } } @@ -1302,28 +1342,25 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I *****************************************************************************/ 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]; - L3USHORT CRV; - Octet++; /*Octet 2 is length indicator */ + L3INT l = IBuf[Octet++]; - if(l == 1) /* One octet CRV */ + if(l == 1) /* One octet CRV */ { - CRV = IBuf[Octet] & 0x7F; - Octet++; + CRV = IBuf[Octet++] & 0x7F; } - else if(l==2) /* two octet CRV */ + else if(l == 2) /* two octet CRV */ { - CRV = (IBuf[Octet] & 0x7f) << 8; - CRV = CRV + IBuf[Octet+1]; - Octet += 2; + 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; + /* Long CRV is not used, so we skip this */ + /* TODO: is it right to set to 0 here? */ + CRV = 0; + Octet += l; } *IOff = Octet; @@ -1634,7 +1671,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I li=(*Octet)++; /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | (pIE->Interpret << 2) | pIE->PresMeth; + OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | ((pIE->Interpret << 2) & 0x1c) | (pIE->PresMeth & 0x03); /* Octet 4 */ OBuf[(*Octet)++] = pIE->HLCharID; @@ -1642,11 +1679,11 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 4a */ if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) { - OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; + OBuf[(*Octet)++] = 0x80 | (pIE->EHLCharID & 0x7f); } else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) { - OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; + OBuf[(*Octet)++] = 0x80 | (pIE->EVideoTlfCharID & 0x7f); } else { @@ -3151,3 +3188,29 @@ L3INT Q931Pie_ChangeStatus(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu 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 index 2131c20e48..4a53516bdd 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -43,6 +43,34 @@ #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 @@ -84,17 +112,12 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *****************************************************************************/ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -177,12 +200,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -271,17 +289,23 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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 */ 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; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } /***************************************************************************** @@ -296,12 +320,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -392,12 +411,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->Display)) @@ -432,6 +446,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener case Q931ie_PROGRESS_INDICATOR: case Q931ie_DISPLAY: case Q931ie_SIGNAL: + 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; @@ -457,12 +472,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -516,8 +526,10 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gene break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } /***************************************************************************** @@ -532,13 +544,8 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN L3INT Octet = 0; /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); @@ -607,12 +614,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -675,12 +677,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -753,12 +750,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -820,12 +812,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -882,34 +869,29 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *****************************************************************************/ L3INT Q931Pmes_Restart(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; + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* 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; + /* 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; + return rc; } /***************************************************************************** @@ -953,13 +935,8 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1019,13 +996,8 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi L3INT Octet = 0; /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) @@ -1061,8 +1033,10 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } @@ -1073,17 +1047,12 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi *****************************************************************************/ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1096,7 +1065,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT *OSize = Octet; - return rc; + return rc; } /***************************************************************************** @@ -1124,8 +1093,10 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gen break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } @@ -1141,11 +1112,7 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I L3INT Octet = 0; /* Q931 Message Header */ - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -1159,23 +1126,23 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I *OSize = Octet; - return rc; + return rc; } L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT OOff) { - L3INT i = IOff; + L3INT i = IOff; - return IOff - i; + return IOff - i; } L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; *OSize = 0; - return RetCode; + return RetCode; } /***************************************************************************** @@ -1196,6 +1163,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m case Q931ie_SENDING_COMPLETE: IOff++; break; + case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: @@ -1215,6 +1183,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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); @@ -1223,13 +1192,16 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m return Q931E_ILLEGAL_IE; } break; + default: return Q931E_ILLEGAL_IE; break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } /***************************************************************************** @@ -1252,25 +1224,20 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m *****************************************************************************/ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Sending Complete */ + /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) - OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + OBuf[Octet++] = (L3UCHAR)Q931ie_SENDING_COMPLETE & 0xff; /* Repeat Indicator */ if(Q931IsIEPresent(pMes->RepeatInd)) - OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 0x00ff); + OBuf[Octet++] = (L3UCHAR)Q931ie_REPEAT_INDICATOR & 0xff; /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -1359,7 +1326,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz *OSize = Octet; - return rc; + return rc; } /***************************************************************************** @@ -1389,8 +1356,8 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** @@ -1405,12 +1372,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1480,12 +1442,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -1545,12 +1502,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->Display)) @@ -1602,12 +1554,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) @@ -1660,12 +1607,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->Display)) @@ -1718,12 +1660,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -1817,12 +1754,7 @@ L3INT Q931Pmes_Service(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1883,12 +1815,7 @@ L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* 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) diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index 01e7a1416a..f09fa7577c 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -31,7 +31,7 @@ NOTE: The following are not yet implemented OnQ921Error Function called every if an error is - deteceted. + detected. OnQ921Log Function called if logging is active. @@ -76,84 +76,149 @@ *****************************************************************************/ +/**************************************************************************** + * 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 L2INT int /* Min 16 bit signed */ -#define L2ULONG unsigned long /* Min 32 bit */ +#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 * -typedef enum /* Network/User Mode. */ +#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 */ + Q921_TE=0, /* 0 : User Mode */ + Q921_NT=1 /* 1 : Network Mode */ } Q921NetUser_t; -typedef struct Q921Data Q921Data_t; -typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); +typedef enum /* Type of connection */ +{ + Q921_PTP=0, /* 0 : Point-To-Point */ + Q921_PTMP=1 /* 1 : Point-To-Multipoint */ +} Q921NetType_t; -#define INITIALIZED_MAGIC 42 -struct Q921Data +typedef enum +{ + Q921_LOG_NONE = 0, + 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 { - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2INT initialized; - L2UCHAR va; - L2UCHAR vs; - L2UCHAR vr; - L2INT state; - L2UCHAR sapi; - L2UCHAR tei; + + L2UCHAR sapi; /*!< User assigned SAPI */ + L2UCHAR tei; /*!< User assigned TEI value */ + + L2INT Q921HeaderSpace; Q921NetUser_t NetUser; - L2ULONG T200; - L2ULONG T203; + 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; - Q921TxCB_t Q921Tx21Proc; - Q921TxCB_t Q921Tx23Proc; + + 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; - L2INT Q921HeaderSpace; -}; + /* logging */ + Q921LogLevel_t loglevel; /*!< trunk loglevel */ + Q921LogCB_t Q921LogProc; /*!< log callback procedure */ + void *PrivateDataLog; /*!< private data pointer for log proc */ -void Q921_InitTrunk(L2TRUNK trunk, + /* 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, - Q921TxCB_t cb21, - Q921TxCB_t cb23, + Q921Tx21CB_t cb21, + Q921Tx23CB_t cb23, void *priv21, void *priv23); -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); -int Q921Rx12(L2TRUNK trunk); -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); 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); -int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); -int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); -extern L2ULONG tLast; -L2ULONG Q921GetTime(void); -void Q921T200TimerStart(L2TRUNK trunk); -void Q921T200TimerStop(L2TRUNK trunk); -void Q921T200TimerReset(L2TRUNK trunk); -void Q921T203TimerStart(L2TRUNK trunk); -void Q921T203TimerStop(L2TRUNK trunk); -void Q921T203TimerReset(L2TRUNK trunk); -void Q921T200TimerExpire(L2TRUNK trunk); -void Q921T203TimerExpire(L2TRUNK trunk); -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size); -int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size); - #endif - diff --git a/libs/openzap/src/isdn/include/Q921priv.h b/libs/openzap/src/isdn/include/Q921priv.h new file mode 100644 index 0000000000..c355e9b20d --- /dev/null +++ b/libs/openzap/src/isdn/include/Q921priv.h @@ -0,0 +1,298 @@ +/***************************************************************************** + + 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_ + +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 index 70b84af070..2687930485 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -244,23 +244,35 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ *****************************************************************************/ -#define Q931L4BUF 1000 /* size of message buffer */ +#define Q931_LOGBUFSIZE 1024 /* size of logging buffer */ -#define Q931L2BUF 300 /* size of message buffer */ +#define Q931L4BUF 1000 /* size of message buffer */ -#define Q931MAXTRUNKS 4 /* Total number of trunks that will be */ - /* processed by this instance of the */ - /* stack */ +#define Q931L2BUF 300 /* size of message buffer */ -#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 Q931MAXTRUNKS 4 /* Total number of trunks that will be */ + /* processed by this instance of the */ + /* stack */ -#define Q931MAXCALLPERTRUNK (Q931MAXCHPERTRUNK * 2) - /* Number of max active CRV per trunk. */ - /* Q.931 can have more calls than there */ - /* are channels. */ +#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 /***************************************************************************** @@ -280,24 +292,19 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ *****************************************************************************/ -/* 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 */ +/* 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 */ /***************************************************************************** @@ -381,6 +388,155 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #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 @@ -479,33 +635,46 @@ typedef struct *****************************************************************************/ typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; -typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT); -typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT); - -typedef enum /* Network/User Mode. */ +typedef enum { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ + Q931_LOG_NONE = 0, + 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 */ +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_5ESS = 6, /* Coming soon to a PRI stack near you! */ Q931_Dialect_Count } Q931Dialect_t; -#define DIALECT_STRINGS "q931", "", "national", "", "dms","","5ess","" +#define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", "" Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t) -typedef enum /* Trunk Line Type. */ +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_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 */ @@ -522,19 +691,51 @@ typedef enum { 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. */ - - Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ - Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ + Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ - Q931TxCB_t Q931Tx34CBProc; - Q931TxCB_t Q931Tx32CBProc; + 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 */ @@ -580,37 +781,9 @@ struct Q931_TrunkInfo }ch[Q931MAXCHPERTRUNK]; - /* Active Call information indentified by CRV. See Q931AllocateCRV for */ - /* initialization of call table. */ - struct _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - + /* Active Call information indentified by CRV. See Q931AllocateCRV for */ + /* initialization of call table. */ + struct Q931_Call call[Q931MAXCALLPERTRUNK]; }; /***************************************************************************** @@ -646,6 +819,9 @@ typedef L3INT (q931pmes_func_t) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf 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]; @@ -654,6 +830,10 @@ 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 @@ -893,9 +1073,9 @@ L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFro Interface Function Prototypes. Implemented in Q931.c *****************************************************************************/ -void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size); +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); @@ -910,6 +1090,8 @@ 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 timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc); +void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout); void Q931Initialize(void); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); @@ -926,7 +1108,7 @@ 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 Q931SetGetTimeCB(L3ULONG (*callback)(void)); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); @@ -965,8 +1147,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, - Q931TxCB_t Q931Tx34CBProc, - Q931TxCB_t Q931Tx32CBProc, + Q931Tx34CB_t Q931Tx34CBProc, + Q931Tx32CB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, void *PrivateData32, void *PrivateData34); @@ -974,7 +1156,9 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, 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); @@ -985,7 +1169,8 @@ L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize 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 index e64480dfb5..2acb937702 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -57,7 +57,7 @@ typedef enum { /* Single octet information elements */ #define Q931ie_SHIFT 0x90 /* 1001 ---- */ #define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0001 */ #define Q931ie_CONGESTION_LEVEL 0xb0 /* 1011 ---- */ #define Q931ie_REPEAT_INDICATOR 0xd0 /* 1101 ---- */ @@ -101,6 +101,9 @@ typedef enum { #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 */ /***************************************************************************** @@ -1168,5 +1171,7 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, 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/mfifo.h b/libs/openzap/src/isdn/include/mfifo.h index 99faa1d1ba..477362466b 100644 --- a/libs/openzap/src/isdn/include/mfifo.h +++ b/libs/openzap/src/isdn/include/mfifo.h @@ -58,15 +58,15 @@ typedef struct _mindex queue. *****************************************************************************/ -typedef struct _mfifo +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; + unsigned char *buf; /* ptr to start of buffer */ + int ixsize; /* index size */ + MINDEX ix[1]; /* message index */ +} MFIFO; /***************************************************************************** Function prototypes. @@ -80,4 +80,8 @@ 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/mfifo.c b/libs/openzap/src/isdn/mfifo.c index a1e85dedf4..64dbcedfcc 100644 --- a/libs/openzap/src/isdn/mfifo.c +++ b/libs/openzap/src/isdn/mfifo.c @@ -84,17 +84,16 @@ *****************************************************************************/ int MFIFOCreate(unsigned char *buf, int size, int index) { - MFIFO * mf; - mf = (MFIFO*)buf; + MFIFO *mf = (MFIFO *)buf; mf->first = mf->last = 0; mf->ixsize = index; - mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; + mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * index)]; - if(mf->buf > & buf[size]) + if(mf->buf > &buf[size]) return 0; - mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index); return 1; } @@ -112,9 +111,9 @@ int MFIFOCreate(unsigned char *buf, int size, int index) *****************************************************************************/ void MFIFOClear(unsigned char * buf) { - MFIFO * mf; - mf = (MFIFO*)buf; - mf->first = mf->last = 0; + MFIFO *mf = (MFIFO *)buf; + + mf->first = mf->last = 0; } /***************************************************************************** @@ -130,8 +129,8 @@ void MFIFOClear(unsigned char * buf) *****************************************************************************/ int MFIFOGetLBOffset(unsigned char *buf) { - MFIFO * mf; - mf = (MFIFO*)buf; + MFIFO *mf = (MFIFO *)buf; + if(mf->last != mf->first) return mf->ix[mf->last].offset; @@ -153,15 +152,17 @@ int MFIFOGetLBOffset(unsigned char *buf) *****************************************************************************/ int MFIFOGetFBOffset(unsigned char *buf) { + MFIFO *mf = (MFIFO *)buf; int x; - MFIFO * mf; - mf = (MFIFO*)buf; + if(mf->last == mf->first) return 0; - x=mf->first; - x--; - if(x<0) - x=mf->ixsize; + + x = mf->first - 1; + + if(x < 0) + x = mf->ixsize - 1; + return mf->ix[x].offset + mf->ix[x].size; } @@ -184,16 +185,19 @@ int MFIFOGetFBOffset(unsigned char *buf) *****************************************************************************/ void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off) { + MFIFO *mf = (MFIFO *)buf; int x; - MFIFO * mf; - mf = (MFIFO*)buf; - 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; + + 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; } /***************************************************************************** @@ -209,13 +213,14 @@ void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int *****************************************************************************/ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { - int of,ol,x; - MFIFO * mf; - mf = (MFIFO*)buf; + MFIFO *mf = (MFIFO *)buf; + int of, ol, x; + + x = mf->first + 1; + + if(x >= mf->ixsize) + x = 0; - x = mf->first+1; - if(x > mf->ixsize) - x=0; if(x == mf->last) return 0; /* full queue */ @@ -224,6 +229,7 @@ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) if(mf->last == mf->first) /* empty queue */ { mf->first = mf->last = 0; /* optimize */ + MFIFOWriteIX(buf, mes, size, mf->first, 0); return 1; } @@ -231,18 +237,18 @@ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { if(mf->bsize - of >= size) { - MFIFOWriteIX(buf,mes,size,mf->first,of); + MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } else if(ol > size) { - MFIFOWriteIX(buf,mes,size,mf->first,ol); + MFIFOWriteIX(buf, mes, size, mf->first, ol); return 1; } } else if(ol - of > size) { - MFIFOWriteIX(buf,mes,size,mf->first,of); + MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } @@ -262,12 +268,14 @@ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) *****************************************************************************/ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) { - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->first==mf->last) - return NULL; - *size = mf->ix[mf->last].size; - return &mf->buf[mf->ix[mf->last].offset]; + 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]; } /***************************************************************************** @@ -283,14 +291,120 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) *****************************************************************************/ void MFIFOKillNext(unsigned char *buf) { + MFIFO *mf = (MFIFO *)buf; int x; - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->first!=mf->last) + + if(mf->first != mf->last) { - x = mf->last+1; - if(x > mf->ixsize) - x=0; - mf->last=x; + 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/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index efd1d81ea2..99dcec3b9a 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -127,6 +127,9 @@ void nationalCreateTE(L3UCHAR i) 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.*/ diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 81361bd70d..90f7a1b1a3 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -155,12 +155,7 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 4cd3cee8bd..912a14fb0d 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -44,6 +44,10 @@ #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) + static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); @@ -67,91 +71,117 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) Q931ie_CalledNum CalledNum; Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; + Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ + Q931ie_SendComplete SComplete; /* Sending Complete 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; - Q931InitIEBearerCap(&BearerCap); - Q931InitIEChanID(&ChanID); - Q931InitIECallingNum(&CallingNum); - Q931InitIECalledNum(&CalledNum); - Q931InitIEDisplay(&Display); + /* + * 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 */ - BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ - BearerCap.ITC = 0; /* Speech */ - BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ - BearerCap.ITR = 16; /* 64k */ + /* + * 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 = 2; /* U-law (a-law = 3)*/ - + 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); - ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */ - ChanID.InfoChanSel = 1; - ChanID.ChanMapType = 3; /* B-Chan */ - ChanID.ChanSlot = chan_id; + /* + * 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 + */ + 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); - /* TypNum: Type of number */ - /* Bits 7 6 5 */ - /* 000 Unknown */ - /* 001 International number */ - /* 010 National number */ - /* 011 Network Specific number */ - /* 100 Subscriber mumber */ - /* 110 Abbreviated number */ - /* 111 Reserved for extension */ - /* All other values are reserved */ - CallingNum.TypNum = 2; - - /* NumPlanID */ - /* Bits 4 3 2 1 */ - /* 0000 Unknown */ - /* 0001 ISDN/telephony numbering plan (E.164) */ - /* 0011 Data numbering plan (X.121) */ - /* 0100 Telex numbering plan (F.69) */ - /* 1000 National standard numbering plan */ - /* 1001 Private numbering plan */ - /* 1111 Reserved for extension */ - /* All other valures are reserved */ - CallingNum.NumPlanID = 1; - - /* Presentation indicator */ - /* Bits 7 6 */ - /* 00 Presenation Allowed */ - /* 01 Presentation Restricted */ - /* 10 Number not available due to internetworking */ - /* 11 Reserved */ - CallingNum.PresInd = 0; - - /* Screening Indicator */ - /* Bits 2 1 */ - /* 00 User-provided, not screened */ - /* 01 User-provided, verified and passed */ - /* 10 User-provided, verified and failed */ - /* 11 Network provided */ - CallingNum.ScreenInd = 0; + /* + * 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); - CalledNum.TypNum = 2; - CalledNum.NumPlanID = 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); + + /* + * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) + */ + SComplete.IEId = Q931ie_SENDING_COMPLETE; +// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); caller_data->call_state = ZAP_CALLER_STATE_DIALING; Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); @@ -211,7 +241,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) case Q931mes_ALERTING: new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; break; - break; case Q931mes_CONNECT: new_chan->init_state = ZAP_CHANNEL_STATE_UP; break; @@ -275,13 +304,17 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if (Q931IsIEPresent(gen->ChanID)) { Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); - chan_id = chanid->ChanSlot; + + if(chanid->IntType) + chan_id = chanid->ChanSlot; + else + chan_id = chanid->InfoChanSel; } assert(span != NULL); assert(isdn_data != NULL); - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); + 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) { @@ -313,7 +346,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan = isdn_data->channels_remote_crv[gen->CRV]; } - + zap_log(ZAP_LOG_DEBUG, "zchan %x source isdn_data->channels_%s_crv[%#hx]\n", zchan, gen->CRVFlag ? "local" : "remote", gen->CRV); if (gen->ProtDisc == 3) { @@ -376,8 +409,34 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); - } else { + 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 = isdn_data->sig_cb(&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 { @@ -418,6 +477,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { 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); } @@ -425,23 +488,35 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_SETUP: { - Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); - zap_status_t status; int fail = 1; 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; if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { zchan = &span->channels[chan_id]; } - if (zchan && (status = zap_channel_open_chan(zchan) == ZAP_SUCCESS)) { + 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"); + 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)) { @@ -485,9 +560,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 = 0; + cause.CodStand = Q931_CODING_ITU; cause.Location = 1; cause.Recom = 1; //should we be casting here.. or do we need to translate value? @@ -506,11 +582,35 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); } + } else { + 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 = 1; /* call is not end-to-end isdn = 1, in-band information available = 8 */ + gen->ProgInd = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &progress); } - } 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; + default: + zap_log(ZAP_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType); break; } } @@ -518,16 +618,23 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) return 0; } -static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) +static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg, L2INT mlen) { - int ret; + int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; - print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); - ret = Q931Rx23(pvt, msg, mlen); - if (ret != 0) - zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); + switch(ind) { + case Q921_DL_DATA: + case Q921_DL_UNIT_DATA: + print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\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); } @@ -568,6 +675,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DOWN: { if (gen->CRV) { + if(gen->CRVFlag) { + 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); @@ -582,6 +694,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } else { gen->MesType = Q931mes_CALL_PROCEEDING; + gen->CRVFlag = 1; /* inbound */ + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } @@ -594,7 +708,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } - } break; case ZAP_CHANNEL_STATE_RESTART: @@ -613,7 +726,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); } } @@ -626,8 +746,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); } } @@ -641,117 +768,193 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_CalledNum CalledNum; Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; - - Q931InitIEBearerCap(&BearerCap); - Q931InitIEChanID(&ChanID); - Q931InitIECallingNum(&CallingNum); - Q931InitIECalledNum(&CalledNum); - Q931InitIEDisplay(&Display); + Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ + Q931ie_SendComplete SComplete; /* Sending Complete 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(?) */ - BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ - BearerCap.ITC = 0; /* Speech */ - BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ - BearerCap.ITR = 16; /* 64k */ + /* + * 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 = 2; /* U-law (a-law = 3)*/ + BearerCap.UIL1Prot = (codec == ZAP_CODEC_ALAW) ? 3 : 2; /* U-law = 2, A-law = 3 */ gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); - //is cast right here? - ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.InfoChanSel = 1; - ChanID.ChanMapType = 3; /* B-Chan */ - ChanID.ChanSlot = (unsigned char)zchan->chan_id; + /* + * 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 + */ + 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); - /* TypNum: Type of number*/ - /* Bits 7 6 5*/ - /* 000Unknown*/ - /* 001International number*/ - /* 010National number*/ - /* 011Network Specific number */ - /* 100Subscriber mumber*/ - /* 110Abbreviated number*/ - /* 111Reserved for extension*/ - /* All other values are reserved */ - CallingNum.TypNum = 2; - - /* NumPlanID*/ - /* Bits 4 3 2 1*/ - /* 0000Unknown*/ - /* 0001ISDN/telephony numbering plan (E.164)*/ - /* 0011Data numbering plan (X.121)*/ - /* 0100Telex numbering plan (F.69)*/ - /* 1000National standard numbering plan*/ - /* 1001Private numbering plan*/ - /* 1111Reserved for extension*/ - /* All other valures are reserved*/ - CallingNum.NumPlanID = 1; - - /* Presentation indicator*/ - /* Bits 7 6*/ - /* 00Presenation Allowed*/ - /* 01Presentation Restricted*/ - /* 10Number not available due to internetworking*/ - /* 11Reserved*/ - CallingNum.PresInd = 0; - - /* Screening Indicator*/ - /* Bits 2 1*/ - /* 00User-provided, not screened*/ - /* 01User-provided, verified and passed*/ - /* 10User-provided, verified and failed*/ - /* 11Network provided*/ - CallingNum.ScreenInd = 0; + /* + * CallingNum 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(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.TypNum = 2; - CalledNum.NumPlanID = 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); + + /* + * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) + */ + SComplete.IEId = Q931ie_SENDING_COMPLETE; +// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); + 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; - gen->MesType = Q931mes_DISCONNECT; + + 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 = 0; - cause.Location = 1; - cause.Recom = 1; - //should we be casting here.. or do we need to translate value? - 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); + 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 = isdn_data->sig_cb(&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: @@ -871,6 +1074,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) 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); @@ -887,8 +1091,6 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) break; case ZAP_TIMEOUT: { - /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ - /*Q931TimeTick(isdn_data->q931, L3ULONG ms);*/ errs = 0; } break; @@ -937,7 +1139,8 @@ zap_status_t zap_isdn_init(void) Q931Initialize(); Q921SetGetTimeCB(zap_time_now); - + Q931SetGetTimeCB(zap_time_now); + return ZAP_SUCCESS; } @@ -948,16 +1151,66 @@ zap_status_t zap_isdn_start(zap_span_t *span) return zap_thread_create_detached(zap_isdn_run, span); } -static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen) +static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3INT mlen) { - int ret; + int offset = 4; char bb[4096] = ""; - ret = Q921Rx32(pvt, msg, mlen); - print_hex_bytes(msg, mlen, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen, LINE, bb); - return ret; + + switch(ind) { + case Q921_DL_UNIT_DATA: + offset = 3; + + case Q921_DL_DATA: + print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); + 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); } +static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) +{ + int loglevel = ZAP_LOG_LEVEL_DEBUG; + + switch(level) { + case Q921_LOG_DEBUG: + loglevel = ZAP_LOG_LEVEL_DEBUG; + break; + + case Q921_LOG_INFO: + loglevel = ZAP_LOG_LEVEL_INFO; + break; + + case Q921_LOG_NOTICE: + loglevel = ZAP_LOG_LEVEL_NOTICE; + break; + + case Q921_LOG_WARNING: + loglevel = ZAP_LOG_LEVEL_WARNING; + break; + + case Q921_LOG_ERROR: + loglevel = ZAP_LOG_LEVEL_ERROR; + break; + + default: + return 0; + } + + zap_log(__FILE__, "Q.921", __LINE__, loglevel, "%s", msg); + + return 0; +} + +static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size) +{ + zap_log(__FILE__, "Q.931", __LINE__, ZAP_LOG_LEVEL_DEBUG, "%s", msg); + return 0; +} static zap_state_map_t isdn_state_map = { { @@ -995,7 +1248,7 @@ static zap_state_map_t isdn_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END} }, { ZSD_OUTBOUND, @@ -1039,7 +1292,7 @@ static zap_state_map_t isdn_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END}, }, { ZSD_INBOUND, @@ -1108,29 +1361,38 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; + isdn_data->mode = mode; Q921_InitTrunk(&isdn_data->q921, 0, 0, mode, + span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP, 0, zap_isdn_921_21, - (Q921TxCB_t)zap_isdn_921_23, + (Q921Tx23CB_t)zap_isdn_921_23, span, &isdn_data->q931); + + Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); + Q921SetLogLevel(&isdn_data->q921, Q921_LOG_DEBUG); Q931Api_InitTrunk(&isdn_data->q931, dialect, mode, span->trunk_type, zap_isdn_931_34, - (Q931TxCB_t)q931_rx_32, + (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, Q931_LOG_DEBUG); + isdn_data->q931.autoRestartAck = 1; - isdn_data->q931.autoConnectAck = 1; +// isdn_data->q931.autoConnectAck = 1; + isdn_data->q931.autoConnectAck = 0; isdn_data->q931.autoServiceAck = 1; span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; From ff19726bd051dad9e2d77f86ec86bb090ac0977f Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 22 Aug 2008 16:55:01 +0000 Subject: [PATCH 0986/1766] Add initial Basic Rate Interface (BRI) support... Short summary of changes: (Massive) rework of the Q.921 layer Q.931 changes to get BRI PTMP working and cleanups (more to come...) Add Hi-Layer compat and Progress IE to outgoing SETUP messages Improve handling of call tear-down in zap_isdn.c Open ZAP I/O channels after processing the dialplan for incoming calls Bearer Capability and Channel ID IE handling improved for BRI/PRI and A-law/u-law ...and a lot of other small changes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@512 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.gitignore | 12 + libs/freetdm/mod_openzap/mod_openzap.c | 7 +- libs/freetdm/src/include/openzap.h | 15 +- libs/freetdm/src/include/zap_isdn.h | 3 +- libs/freetdm/src/include/zap_types.h | 3 +- libs/freetdm/src/isdn/5ESSStateTE.c | 4 +- libs/freetdm/src/isdn/5ESSmes.c | 7 +- libs/freetdm/src/isdn/DMSStateTE.c | 4 +- libs/freetdm/src/isdn/DMSmes.c | 7 +- libs/freetdm/src/isdn/Q921.c | 3399 ++++++++++++++++++++-- libs/freetdm/src/isdn/Q931.c | 298 +- libs/freetdm/src/isdn/Q931StateNT.c | 92 +- libs/freetdm/src/isdn/Q931StateTE.c | 91 +- libs/freetdm/src/isdn/Q931api.c | 22 +- libs/freetdm/src/isdn/Q931ie.c | 295 +- libs/freetdm/src/isdn/Q931mes.c | 301 +- libs/freetdm/src/isdn/include/Q921.h | 169 +- libs/freetdm/src/isdn/include/Q921priv.h | 298 ++ libs/freetdm/src/isdn/include/Q931.h | 361 ++- libs/freetdm/src/isdn/include/Q931ie.h | 7 +- libs/freetdm/src/isdn/include/mfifo.h | 14 +- libs/freetdm/src/isdn/mfifo.c | 208 +- libs/freetdm/src/isdn/nationalStateTE.c | 3 + libs/freetdm/src/isdn/nationalmes.c | 7 +- libs/freetdm/src/zap_isdn.c | 580 +++- 25 files changed, 5148 insertions(+), 1059 deletions(-) create mode 100644 libs/freetdm/.gitignore create mode 100644 libs/freetdm/src/isdn/include/Q921priv.h diff --git a/libs/freetdm/.gitignore b/libs/freetdm/.gitignore new file mode 100644 index 0000000000..e767f23aa1 --- /dev/null +++ b/libs/freetdm/.gitignore @@ -0,0 +1,12 @@ +*.o +*.lo +*.so +*.a +*.orig +*.rej +*.log + +Makefile +config.* +configure + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d28a754119..a40b49e1fd 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -673,6 +673,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } + static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) { switch_channel_t *channel; @@ -690,7 +691,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, if (switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } } break; @@ -700,7 +701,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } break; @@ -709,7 +710,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, if (switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } break; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4fb5c737ad..26b050181e 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -134,8 +134,8 @@ #include "libteletone.h" #include "zap_buffer.h" #include "zap_threadmutex.h" -#include "Q931.h" #include "Q921.h" +#include "Q931.h" #define XX if (0) @@ -232,6 +232,19 @@ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } +#define zap_set_state_locked_wait(obj, s) \ + do { \ + int __safety = 100; \ + zap_set_state_locked(obj, s); \ + while(__safety-- && zap_test_flag(obj, ZAP_CHANNEL_STATE_CHANGE)) { \ + zap_sleep(10); \ + } \ + if(!__safety) { \ + zap_log(ZAP_LOG_CRIT, "State change not completed\n"); \ + } \ + } while(0); + + typedef enum { ZAP_STATE_CHANGE_FAIL, ZAP_STATE_CHANGE_SUCCESS, diff --git a/libs/freetdm/src/include/zap_isdn.h b/libs/freetdm/src/include/zap_isdn.h index 91f35b2a9b..e18a51ab0a 100644 --- a/libs/freetdm/src/include/zap_isdn.h +++ b/libs/freetdm/src/include/zap_isdn.h @@ -53,10 +53,11 @@ struct zap_isdn_data { struct zap_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; + int32_t mode; + 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]; - zap_isdn_opts_t opts; }; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index be43d0d069..7c092e7f70 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -117,11 +117,12 @@ typedef enum { ZAP_TRUNK_T1, ZAP_TRUNK_J1, ZAP_TRUNK_BRI, + ZAP_TRUNK_BRI_PTMP, ZAP_TRUNK_FXO, ZAP_TRUNK_FXS, ZAP_TRUNK_NONE } zap_trunk_type_t; -#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE" +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "NONE" ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) typedef enum { diff --git a/libs/freetdm/src/isdn/5ESSStateTE.c b/libs/freetdm/src/isdn/5ESSStateTE.c index 05a11b0c5c..a9654ce723 100644 --- a/libs/freetdm/src/isdn/5ESSStateTE.c +++ b/libs/freetdm/src/isdn/5ESSStateTE.c @@ -240,7 +240,7 @@ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -283,7 +283,7 @@ L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c index 6a6f4684d1..da47f7ac5b 100644 --- a/libs/freetdm/src/isdn/5ESSmes.c +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -158,12 +158,7 @@ L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) diff --git a/libs/freetdm/src/isdn/DMSStateTE.c b/libs/freetdm/src/isdn/DMSStateTE.c index 565841589e..8c435fa8c2 100644 --- a/libs/freetdm/src/isdn/DMSStateTE.c +++ b/libs/freetdm/src/isdn/DMSStateTE.c @@ -237,7 +237,7 @@ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -279,7 +279,7 @@ L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/freetdm/src/isdn/DMSmes.c b/libs/freetdm/src/isdn/DMSmes.c index 57aeddfb0d..b32664b767 100644 --- a/libs/freetdm/src/isdn/DMSmes.c +++ b/libs/freetdm/src/isdn/DMSmes.c @@ -155,12 +155,7 @@ L3INT DMSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 2dad5cf006..a682c2342e 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -37,12 +37,323 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -#include "Q921.h" + +/**************************************************************************** + * 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" -int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); + +/****************************************************************************************************** + * 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; +} /***************************************************************************** @@ -52,47 +363,461 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); function MUST be called before you call any other functions. *****************************************************************************/ -void Q921_InitTrunk(L2TRUNK trunk, +int Q921_InitTrunk(L2TRUNK trunk, L2UCHAR sapi, L2UCHAR tei, Q921NetUser_t NetUser, + Q921NetType_t NetType, L2INT hsize, - Q921TxCB_t cb21, - Q921TxCB_t cb23, + Q921Tx21CB_t cb21, + Q921Tx23CB_t cb23, void *priv21, void *priv23) { - if (trunk->initialized != INITIALIZED_MAGIC) { - MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10); - trunk->initialized = INITIALIZED_MAGIC; - } - trunk->va = 0; - trunk->vs = 0; - trunk->vr = 0; - trunk->state = 0; + 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; - trunk->T200 = 0; - trunk->T203 = 0; - trunk->T200Timeout = 1000; - trunk->T203Timeout = 10000; + + 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; } -int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) + +/** + * 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); } -int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) -{ - return trunk->Q921Tx23Proc(trunk->PrivateData23, 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]; + L2INT len, left; + va_list ap; + + if(!trunk->Q921LogProc) + return 0; + + if(trunk->loglevel < level) + return 0; + + if(!mes) + return 0; + + + 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]; + L2INT pleft, poffset; + L2UCHAR sapi, tei, cr; + L2UCHAR *pmes = mes + trunk->Q921HeaderSpace; + struct Q921_Link *link; + + 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, 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, 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: + return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, strlen(buf)); } /***************************************************************************** @@ -105,82 +830,468 @@ int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size) Return Value: none *****************************************************************************/ -L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ -L2ULONG tLast = {0}; +static L2ULONG (*Q921GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ +static L2ULONG tLast = {0}; -L2ULONG Q921GetTime(void) +static L2ULONG Q921GetTime(void) { - L2ULONG tNow = 0; - if(Q921GetTimeProc != NULL) - { - tNow = Q921GetTimeProc(); - if(tNow < tLast) /* wrapped */ - { + L2ULONG tNow = 0; + + if(Q921GetTimeProc) + { + tNow = Q921GetTimeProc(); + if(tNow < tLast) /* wrapped */ + { /* TODO */ - } + } tLast = tNow; - } - return tNow; + } + return tNow; } -void Q921T200TimerStart(L2TRUNK trunk) +/* + * T200 handling (per-TEI in PTMP NT mode, tei=0 otherwise) + */ +static void Q921T200TimerStart(L2TRUNK trunk, L2UCHAR tei) { - if (!trunk->T200) { - trunk->T200 = Q921GetTime() + trunk->T200Timeout; + 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); } } -void Q921T200TimerStop(L2TRUNK trunk) +static void Q921T200TimerStop(L2TRUNK trunk, L2UCHAR tei) { - trunk->T200 = 0; + struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei); + + link->T200 = 0; + + Q921Log(trunk, Q921_LOG_DEBUG, "T200 stopped for TEI %d\n", tei); } -void Q921T200TimerReset(L2TRUNK trunk) +static void Q921T200TimerReset(L2TRUNK trunk, L2UCHAR tei) { - Q921T200TimerStop(trunk); - Q921T200TimerStart(trunk); + 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); } -void Q921T203TimerStart(L2TRUNK trunk) +/* + * T203 handling (per-TEI in PTMP NT mode, tei=0 otherwise) + */ +static void Q921T203TimerStart(L2TRUNK trunk, L2UCHAR tei) { - if (!trunk->T203) { - trunk->T203 = Q921GetTime() + trunk->T203Timeout; + 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); } } -void Q921T203TimerStop(L2TRUNK trunk) +static void Q921T203TimerStop(L2TRUNK trunk, L2UCHAR tei) { - trunk->T203 = 0; + struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, tei); + + link->T203 = 0; + + Q921Log(trunk, Q921_LOG_DEBUG, "T203 stopped for TEI %d\n", tei); } -void Q921T203TimerReset(L2TRUNK trunk) +static void Q921T203TimerReset(L2TRUNK trunk, L2UCHAR tei) { - Q921T203TimerStop(trunk); - Q921T203TimerStart(trunk); + 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); } -void Q921T200TimerExpire(L2TRUNK trunk) +/* + * T202 handling (TEI message timeout, TE mode only) + */ +static void Q921T202TimerStart(L2TRUNK trunk) { - (void)trunk; + if (!trunk->T202) { + trunk->T202 = Q921GetTime() + trunk->T202Timeout; + + Q921Log(trunk, Q921_LOG_DEBUG, "T202 (timeout: %d msecs) started\n", trunk->T202Timeout); + } } -void Q921T203TimerExpire(L2TRUNK trunk) +static void Q921T202TimerStop(L2TRUNK trunk) { - Q921T203TimerReset(trunk); - Q921SendRR(trunk, trunk->sapi, trunk->NetUser == Q921_TE ? 0 : 1, trunk->tei, 1); + 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(); - if (trunk->T200 && tNow > trunk->T200) { - Q921T200TimerExpire(trunk); - } - if (trunk->T203 && tNow > trunk->T203) { - Q921T203TimerExpire(trunk); - } -} + 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)) { @@ -211,45 +1322,292 @@ int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size) return MFIFOWriteMes(trunk->HDLCInQueue, b, size); } -/***************************************************************************** - - Function: Q921SendI - - Description: Compose and Send I Frame to layer. Will receive an I frame - with space for L2 header and fill out that header before - it call Q921Tx21Proc. - - Parameters: trunk trunk # - Sapi Sapi - cr C/R field. - Tei Tei. - pf P fiels octet 5 - mes ptr to I frame message. - size size of message in bytes. - - Return Value: 0 if failed, 1 if Send. - -*****************************************************************************/ -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT 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) { - mes[trunk->Q921HeaderSpace+0] = (Sapi&0xfc) | ((cr<<1)&0x02); - mes[trunk->Q921HeaderSpace+1] = (Tei<<1) | 0x01; - mes[trunk->Q921HeaderSpace+2] = trunk->vs<<1; - mes[trunk->Q921HeaderSpace+3] = (trunk->vr<<1) | (pf & 0x01); - trunk->vs++; + struct Q921_Link *link = Q921_LINK_CONTEXT(trunk, Tei); - return Q921Tx21Proc(trunk, mes, size); + /* 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; } -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) +/** + * Q921SendQueuedIFrame + * \brief Try to transmit queued I frame (if available) + */ +static int Q921SendQueuedIFrame(L2TRUNK trunk, L2UCHAR tei) { - return Q921SendI(trunk, - trunk->sapi, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, - 0, - Mes, - Size); + 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; } /***************************************************************************** @@ -267,16 +1625,11 @@ int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size) *****************************************************************************/ -int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x01; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); + return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x00, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -294,16 +1647,11 @@ int Q921SendRR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x05; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); + return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x01, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -321,16 +1669,11 @@ int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)0x09; - mes[trunk->Q921HeaderSpace+3] = (L2UCHAR)((trunk->vr<<1) | (pf & 0x01)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+4); + return Q921SendS(trunk, Sapi, cr, Tei, pf, 0x03, mes, trunk->Q921HeaderSpace+4); } /***************************************************************************** @@ -348,31 +1691,150 @@ int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x6f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + 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) { - return Q921SendSABME(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, - trunk->NetUser == Q921_TE ? 0 : 1, - trunk->tei, + 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: Comose and Send DM (Disconnected Mode) + Description: Compose and Send DM (Disconnected Mode) Parameters: trunk trunk # Sapi Sapi @@ -383,15 +1845,11 @@ int Q921Start(L2TRUNK trunk) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x0f | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x03, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -409,15 +1867,11 @@ int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x43 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x08, mes, trunk->Q921HeaderSpace+3); } /***************************************************************************** @@ -435,30 +1889,1000 @@ int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) Return Value: 0 if failed, 1 if Send. *****************************************************************************/ -int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) +static int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf) { - L2UCHAR mes[400]; + L2UCHAR mes[25]; - mes[trunk->Q921HeaderSpace+0] = (L2UCHAR)((Sapi&0xfc) | ((cr<<1)&0x02)); - mes[trunk->Q921HeaderSpace+1] = (L2UCHAR)((Tei<<1) | 0x01); - mes[trunk->Q921HeaderSpace+2] = (L2UCHAR)(0x63 | ((pf<<4)&0x10)); - - return Q921Tx21Proc(trunk, mes, trunk->Q921HeaderSpace+3); + return Q921SendU(trunk, Sapi, cr, Tei, pf, 0x0c, mes, trunk->Q921HeaderSpace+3); } -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) +static int Q921SendUN(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf, L2UCHAR *mes, L2INT size) { - /* TODO: Do we need these paramaters? */ - (void)mes; - (void)size; - - trunk->vr=0; - trunk->vs=0; - trunk->va=0; - - return 1; + 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 @@ -479,80 +2903,597 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size) *****************************************************************************/ int Q921Rx12(L2TRUNK trunk) { - L2UCHAR *mes; - L2INT rs,size; /* receive size & Q921 frame size*/ - L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - L2UCHAR nr; + L2INT size; /* receive size & Q921 frame size*/ + L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size); - if(smes != NULL) - { - rs = size - trunk->Q921HeaderSpace; - mes = &smes[trunk->Q921HeaderSpace]; + if(smes) + { + struct Q921_Link *link; + L2UCHAR sapi, tei; + L2UCHAR *mes; + L2INT rs; - if ((mes[2] & 3) != 3) { - /* we have an S or I frame */ - /* if nr is between va and vs, update our va counter */ - nr = (mes[3] >> 1); - if (nr >= trunk->va && nr <= trunk->vs) { - trunk->va = nr; - } + 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; } - /* check for I frame */ - if((mes[2] & 0x01) == 0) - { + 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 */ + } - /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */ - trunk->vr++; - if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */ - { - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); - } - else - { - /* todo: whatever*/ - /* trunk->vr--; */ - /* for now, lets just respond for easier debugging on errors */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[3]&0x01); - } - } +out: + MFIFOKillNext(trunk->HDLCInQueue); - /* check for RR */ - else if(mes[2] ==0x01) - { - if (((mes[0]>>1)&0x01) == (trunk->NetUser == Q921_TE ? 1 : 0)) { /* if this is a command */ - Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01, mes[1]>>1, mes[2]&0x01); - } + return 1; + } - } - - /* check for RNR */ - /* check for REJ */ - /* check for SABME */ - else if((mes[2] & 0xef) == 0x6f) - { - Q921ProcSABME(trunk, mes, rs); - Q921SendUA(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, (mes[2]&0x10)>>4); - } - - /* check for DM */ - /* check for UI */ - /* check for DISC */ - /* check for UA */ - /* check for FRMR */ - /* check for XID */ - - else - { - /* what the ? Issue an error */ - /* Q921ErrorProc(trunk, Q921_UNKNOWNFRAME, mes, rs); */ - /* todo: REJ or FRMR */ - } - - MFIFOKillNext(trunk->HDLCInQueue); - - return 1; - } - return 0; + 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; + + 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; + + link->ri = (L2USHORT)(random() % 0xffff); + + /* 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/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 12ebde2660..6591613d71 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#include "Q921.h" #include "Q931.h" #include "national.h" #include "DMS.h" @@ -67,6 +68,8 @@ 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)= { @@ -250,6 +253,10 @@ void Q931Initialize() 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) @@ -286,28 +293,38 @@ void Q931Initialize() } } -/***************************************************************************** - - Function: Q931TimeTick - - Description: Called periodically from an external source to allow the - stack to process and maintain it's own timers. - - Parameters: ms[IN] Milliseconds since last call. - - Return Value: none - -*****************************************************************************/ -void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms) +/** + * Q931TimerTick + * \brief Periodically called to update and check for expired timers + * \param pTrunk Q.931 trunk + */ +void Q931TimerTick(Q931_TrunkInfo_t *pTrunk) { - (void)pTrunk; - ms=ms; /* avoid warning for now. */ + 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. - */ + /* 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); + } + } } /***************************************************************************** @@ -331,39 +348,65 @@ void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) +L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT Size) { - L3UCHAR *Mes = &buf[Q931L2HeaderSpace]; - L3INT RetCode = Q931E_NO_ERROR; - Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; - L3INT ISize; + L3UCHAR *Mes = NULL; + L3INT RetCode = Q931E_NO_ERROR; + Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf; + L3INT ISize; + L3INT IOff = 0; + L3INT L2HSize = Q931L2HeaderSpace; - L3INT IOff = 0; + switch(ind) { + case Q921_DL_UNIT_DATA: /* DL-UNITDATA indication (UI frame, 3 byte header) */ + L2HSize = 3; - /* Reset our decode buffer */ - memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf)); + case Q921_DL_DATA: /* DL-DATA indication (I frame, 4 byte header) */ + /* Reset our decode buffer */ + memset(pTrunk->L3Buf, 0, sizeof(pTrunk->L3Buf)); - /* Protocol Discriminator */ - m->ProtDisc = Mes[IOff++]; + /* L2 Header Offset */ + Mes = &buf[L2HSize]; - /* CRV */ - m->CRVFlag = Mes[IOff + 1] & 0x80; - m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); + /* Protocol Discriminator */ + m->ProtDisc = Mes[IOff++]; - /* Message Type */ - m->MesType = Mes[IOff++]; + /* CRV */ + m->CRVFlag = (Mes[IOff + 1] >> 7) & 0x01; + m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize); - /* Call table proc to unpack codec message */ - /*debug */ - /* printf("\n\nQ931Rx23- Dialect: %d, MsgType: %d\n",pTrunk->Dialect,m->MesType); */ - RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1); + /* Message Type */ + m->MesType = Mes[IOff++]; - if(RetCode >= Q931E_NO_ERROR) - { - RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); - } + /* 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; - return RetCode; + /* 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, 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; } /***************************************************************************** @@ -381,6 +424,8 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size) *****************************************************************************/ 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); } @@ -406,7 +451,11 @@ L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace]; L3INT RetCode = Q931E_NO_ERROR; - RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4); + 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; } @@ -428,25 +477,42 @@ L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size) see q931errors.h for details. *****************************************************************************/ -L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size) +L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size) { - L3INT OSize; - Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; - L3INT RetCode = Q931E_NO_ERROR; - L3INT iDialect = pTrunk->Dialect; + Q931mes_Generic *ptr = (Q931mes_Generic*)Mes; + L3INT RetCode = Q931E_NO_ERROR; + L3INT iDialect = pTrunk->Dialect; + L3INT Offset = bcast ? (Q931L2HeaderSpace - 1) : Q931L2HeaderSpace; + L3INT OSize; - /* Call pack function through table. */ - RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { - if (pTrunk->Q931Tx32CBProc) { - RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace); - } else { - RetCode = Q931E_MISSING_CB; - } - } + Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending message to Q.921 (size: %d)\n", Size); - return RetCode; + 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; } @@ -575,28 +641,40 @@ L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) return 0; /* assume state zero for non existing CRV's */ } -/***************************************************************************** - - Function: Q931StartTimer - - Description: Start a timer. - - Parameters: pTrunk Trunk number - callindex call index. - iTimer timer id -*****************************************************************************/ +/** + * 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) { - pTrunk->call[callIndex].Timer = Q931GetTime(); - pTrunk->call[callIndex].TimerID = iTimerID; - return 0; + L3ULONG duration = Q931Timer[pTrunk->Dialect][iTimerID]; + + if(duration) { + pTrunk->call[callIndex].Timer = Q931GetTime() + duration; + pTrunk->call[callIndex].TimerID = iTimerID; + } + + 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; + if(pTrunk->call[callindex].TimerID == iTimerID) + pTrunk->call[callindex].TimerID = 0; + + return 0; } L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) @@ -609,7 +687,8 @@ L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) L3ULONG Q931GetTime() { L3ULONG tNow = 0; - static L3ULONG tLast={0}; + static L3ULONG tLast = 0; + if(Q931GetTimeProc != NULL) { tNow = Q931GetTimeProc(); @@ -758,5 +837,68 @@ const char *q931_error_to_name(q931_error_t error) } 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) +{ + 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/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 3343170786..af74ef0e8b 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -116,11 +116,34 @@ void Q931CreateNT(L3UCHAR i) 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); + /* 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 */ } /***************************************************************************** @@ -143,7 +166,7 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -175,7 +198,7 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -208,7 +231,7 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -241,7 +264,7 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -274,7 +297,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -313,7 +336,10 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; pMes->CRV = pTrunk->call[callIndex].CRV; - ret = Q931Tx32(pTrunk,buf,pMes->Size); + /* + * 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; @@ -389,7 +415,7 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -422,7 +448,7 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -455,7 +481,7 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -488,7 +514,7 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -521,7 +547,7 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -554,7 +580,7 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -587,7 +613,7 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -620,7 +646,7 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -653,7 +679,7 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -686,7 +712,7 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -719,7 +745,7 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -752,7 +778,7 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -785,7 +811,7 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -818,7 +844,7 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -851,7 +877,7 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -884,7 +910,7 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -917,7 +943,7 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -950,7 +976,7 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -983,7 +1009,7 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1020,7 +1046,7 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1053,7 +1079,7 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1086,7 +1112,7 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1119,7 +1145,7 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1152,7 +1178,7 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1185,7 +1211,7 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1218,7 +1244,7 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1251,7 +1277,7 @@ L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index da028b5867..552b39ff27 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -123,6 +123,9 @@ void Q931CreateTE(L3UCHAR i) 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); + /* 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.*/ @@ -205,6 +208,24 @@ void Q931CreateTE(L3UCHAR i) 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 */ } /***************************************************************************** @@ -227,7 +248,7 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -259,7 +280,7 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -292,7 +313,7 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -329,7 +350,7 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -362,7 +383,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -399,7 +420,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; pMes->CRV = pTrunk->call[callIndex].CRV; - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); if(ret) return ret; @@ -475,7 +496,7 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) Q931StartTimer(pTrunk, callIndex, 303); if(iFrom == 4) { - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -504,7 +525,7 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) pMes->CRV = pTrunk->call[callIndex].CRV; /* Send RESUME to network */ - ret=Q931Tx32(pTrunk,buf, pMes->Size); + ret=Q931Tx32Data(pTrunk,0,buf, pMes->Size); if(ret != Q931E_NO_ERROR) return ret; @@ -544,7 +565,7 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -577,7 +598,7 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -610,7 +631,7 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -643,7 +664,7 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -676,7 +697,7 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -709,7 +730,7 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -730,6 +751,9 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret=Q931E_NO_ERROR; Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace]; + 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) @@ -742,7 +766,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -765,7 +789,7 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) L3INT ret = Q931E_NO_ERROR; if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if(state == Q931_U0 && iFrom == 2) { Q931Tx34(pTrunk,buf,pMes->Size); ret = Q931ReleaseComplete(pTrunk, buf); @@ -805,6 +829,9 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i 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); } } @@ -838,7 +865,7 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -877,7 +904,7 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -910,7 +937,7 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -943,7 +970,7 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -976,7 +1003,7 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1009,7 +1036,7 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1042,7 +1069,7 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1075,7 +1102,7 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1112,7 +1139,7 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1145,7 +1172,7 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1178,7 +1205,7 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1211,7 +1238,7 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1244,7 +1271,7 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1277,7 +1304,7 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1310,7 +1337,7 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { @@ -1343,7 +1370,7 @@ L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF if(iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32(pTrunk,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); } else if (iFrom ==2) { diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index b0119ef68c..c7200d568d 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -74,8 +74,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, - Q931TxCB_t Q931Tx34CBProc, - Q931TxCB_t Q931Tx32CBProc, + Q931Tx34CB_t Q931Tx34CBProc, + Q931Tx32CB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, void *PrivateData32, void *PrivateData34) @@ -97,6 +97,7 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, break; case Q931_TrType_BRI: + case Q931_TrType_BRI_PTMP: dchannel = 3; maxchans = 3; break; @@ -166,6 +167,16 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q9 Q931Uie[dialect][iec] = Q931UieProc; } +void Q931SetTimeoutProc(L3UCHAR timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc) +{ + if(Q931Timeout != NULL) + Q931Timeout[dialect][timer] = Q931TimeoutProc; +} + +void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout) +{ + Q931Timer[dialect][timer] = timeout; +} L3INT Q931GetMesSize(Q931mes_Generic *pMes) { @@ -212,8 +223,11 @@ 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++; - if (crv > 32766) crv = 1; + crv = (crv <= max) ? crv : 1; + return crv; } @@ -523,7 +537,7 @@ 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 Q931Tx32(pTrunk,buf,ptr->Size); + return Q931Tx32Data(pTrunk,0,buf,ptr->Size); } L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 6c77d32a47..983e158aee 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -318,73 +318,74 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, 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) | (pIE->ITC & 0x1f); + OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | (pIE->ITC & 0x1f); /* Octet 4 - Transfer mode / Information transfer rate */ - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f); + OBuf[(*Octet)++] = 0x80 | ((pIE->TransMode << 5) & 0x60) | (pIE->ITR & 0x1f); + if(pIE->ITR == 0x18) { /* Octet 4.1 - Rate Multiplier */ - OBuf[(*Octet)++] = 0x80 | pIE->RateMul; + OBuf[(*Octet)++] = 0x80 | (pIE->RateMul & 0x7f); } - /* Octet 5 - Layer 1 Ident / User information layer 1 protocol*/ + /* 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))) + 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) | (pIE->UIL1Prot & 0x15); + OBuf[(*Octet)++] = 0x00 | ((pIE->Layer1Ident << 5) & 0x60) | (pIE->UIL1Prot & 0x15); /* Octet 5a - SyncAsync/Negot/UserRate */ - OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (pIE->UserRate&0x1f); + 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) - | (pIE->NIConTx << 4) - | (pIE->NIConRx << 3) - | (pIE->FlowCtlTx << 2) - | (pIE->FlowCtlRx << 1); + | ((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) - | (pIE->MultiFrame << 5) - | (pIE->Mode << 4) - | (pIE->LLInegot << 3) - | (pIE->Assignor << 2) - | (pIE->InBandNeg << 1); + | ((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 ) - | (pIE->NumDataBits << 3 ) - | (pIE->Parity); + | ((pIE->NumStopBits << 5) & 0x60) + | ((pIE->NumDataBits << 3) & 0x18) + | (pIE->Parity & 0x07); /* Octet 5d - Duplex Mode/Modem Type */ - OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType); + OBuf[(*Octet)++] = 0x80 | ((pIE->DuplexMode << 6) & 0x40) | (pIE->ModemType & 0x3f); } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x1F); + 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) | (pIE->UIL2Prot); + if(pIE->Layer2Ident == 0x02) { + OBuf[(*Octet)++] = 0x80 | ((pIE->Layer2Ident << 5) & 0x60) | (pIE->UIL2Prot & 0x1f); } /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */ @@ -392,17 +393,16 @@ L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, { if(pIE->UIL3Prot == 0x0c) { - OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + OBuf[(*Octet)++] = 0x00 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f); /* Octet 7a - Additional information layer 3 msb */ - OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1); + OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1 & 0x0f); /* Octet 7b - Additional information layer 3 lsb */ - OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2); + OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2 & 0x0f); } - else - { - OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot); + else { + OBuf[(*Octet)++] = 0x80 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f); } } @@ -1152,76 +1152,107 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, *****************************************************************************/ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) { - Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf; + Q931ie_ChanID *pie = (Q931ie_ChanID*)OBuf; ie *pIE = &pMsg->ChanID; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; //18 04 e1 80 83 01 - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + Q931Log(pTrunk, Q931_LOG_DEBUG, "Decoding ChanID IE\n"); - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 1 */ + pie->IEId = 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; + /* Octet 2 */ + IESize = IBuf[Octet++]; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); - 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; - /* Octet 3.1 */ + Off = Q931ReadExt(&IBuf[Octet++], Off); - if(pie->IntIDPresent) - { - pie->InterfaceID = IBuf[Octet+Off] & 0x7f; + /* 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++; - } + /* 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; + 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++; - Off ++; + /* Octet 3.3 */ + /* Temp fix. Assume B channel. H channels not supported */ + pie->ChanSlot = IBuf[Octet+Off] & 0x7f; - - /* 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) { + if((Octet + Off - 1) != IESize) { Off = Q931ReadExt(&IBuf[Octet+Off], Off); } - Off++; - } - } + Off++; + } + } - Q931IESizeTest(Q931E_CHANID); + Q931IESizeTest(Q931E_CHANID); - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ChanID); + pie->Size = sizeof(Q931ie_ChanID); - return Q931E_NO_ERROR; + 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; } /***************************************************************************** @@ -1238,24 +1269,24 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * 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 rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; /* remember current offset */ L3INT li; OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION; - li=(*Octet)++; /* remember length position */ + li = (*Octet)++; /* remember length position */ /* Octet 3 flags & BRI chan # */ OBuf[(*Octet)++] = 0x80 - | (pIE->IntIDPresent << 6) - | (pIE->IntType<<5) - | (pIE->PrefExcl<<3) - | pIE->InfoChanSel; + | ((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; + OBuf[(*Octet)++] = 0x80 | (pIE->InterfaceID & 0x7f); } else { @@ -1263,12 +1294,21 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I if(pIE->IntType == 1) { OBuf[(*Octet)++] = 0x80 - | (pIE->CodStand << 5) - | (pIE->NumMap << 4) - | pIE->ChanMapType; + | ((pIE->CodStand << 5) & 0x60) + | ((pIE->NumMap << 4) & 0x10) + | (pIE->ChanMapType & 0x0f); /* TODO: support all possible channel map types */ - /* Octet 3.2 Channel number/slot map */ - OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot; + /* 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; + } } } @@ -1302,28 +1342,25 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I *****************************************************************************/ 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]; - L3USHORT CRV; - Octet++; /*Octet 2 is length indicator */ + L3INT l = IBuf[Octet++]; - if(l == 1) /* One octet CRV */ + if(l == 1) /* One octet CRV */ { - CRV = IBuf[Octet] & 0x7F; - Octet++; + CRV = IBuf[Octet++] & 0x7F; } - else if(l==2) /* two octet CRV */ + else if(l == 2) /* two octet CRV */ { - CRV = (IBuf[Octet] & 0x7f) << 8; - CRV = CRV + IBuf[Octet+1]; - Octet += 2; + 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; + /* Long CRV is not used, so we skip this */ + /* TODO: is it right to set to 0 here? */ + CRV = 0; + Octet += l; } *IOff = Octet; @@ -1634,7 +1671,7 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I li=(*Octet)++; /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | (pIE->Interpret << 2) | pIE->PresMeth; + OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | ((pIE->Interpret << 2) & 0x1c) | (pIE->PresMeth & 0x03); /* Octet 4 */ OBuf[(*Octet)++] = pIE->HLCharID; @@ -1642,11 +1679,11 @@ L3INT Q931Pie_HLComp(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I /* Octet 4a */ if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f) { - OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID; + OBuf[(*Octet)++] = 0x80 | (pIE->EHLCharID & 0x7f); } else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf) { - OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID; + OBuf[(*Octet)++] = 0x80 | (pIE->EVideoTlfCharID & 0x7f); } else { @@ -3151,3 +3188,29 @@ L3INT Q931Pie_ChangeStatus(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBu 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/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 2131c20e48..4a53516bdd 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -43,6 +43,34 @@ #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 @@ -84,17 +112,12 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *****************************************************************************/ L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -177,12 +200,7 @@ L3INT Q931Pmes_CallProceeding(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -271,17 +289,23 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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 */ 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; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } /***************************************************************************** @@ -296,12 +320,7 @@ L3INT Q931Pmes_Connect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -392,12 +411,7 @@ L3INT Q931Pmes_ConnectAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->Display)) @@ -432,6 +446,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener case Q931ie_PROGRESS_INDICATOR: case Q931ie_DISPLAY: case Q931ie_SIGNAL: + 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; @@ -457,12 +472,7 @@ L3INT Q931Pmes_Disconnect(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -516,8 +526,10 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gene break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } /***************************************************************************** @@ -532,13 +544,8 @@ L3INT Q931Pmes_Information(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3IN L3INT Octet = 0; /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); @@ -607,12 +614,7 @@ L3INT Q931Pmes_Notify(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -675,12 +677,7 @@ L3INT Q931Pmes_Progress(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -753,12 +750,7 @@ L3INT Q931Pmes_Release(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -820,12 +812,7 @@ L3INT Q931Pmes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -882,34 +869,29 @@ L3INT Q931Umes_Restart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *****************************************************************************/ L3INT Q931Pmes_Restart(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; + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* 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; + /* 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; + return rc; } /***************************************************************************** @@ -953,13 +935,8 @@ L3INT Q931Pmes_RestartAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; - /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* ChanID */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1019,13 +996,8 @@ L3INT Q931Pmes_Resume(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi L3INT Octet = 0; /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0) @@ -1061,8 +1033,10 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } @@ -1073,17 +1047,12 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi *****************************************************************************/ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1096,7 +1065,7 @@ L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT *OSize = Octet; - return rc; + return rc; } /***************************************************************************** @@ -1124,8 +1093,10 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gen break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } @@ -1141,11 +1112,7 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I L3INT Octet = 0; /* Q931 Message Header */ - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -1159,23 +1126,23 @@ L3INT Q931Pmes_ResumeReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3I *OSize = Octet; - return rc; + return rc; } L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT OOff) { - L3INT i = IOff; + L3INT i = IOff; - return IOff - i; + return IOff - i; } L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; *OSize = 0; - return RetCode; + return RetCode; } /***************************************************************************** @@ -1196,6 +1163,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m case Q931ie_SENDING_COMPLETE: IOff++; break; + case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: @@ -1215,6 +1183,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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); @@ -1223,13 +1192,16 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m return Q931E_ILLEGAL_IE; } break; + default: return Q931E_ILLEGAL_IE; break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + + return Q931E_NO_ERROR; } /***************************************************************************** @@ -1252,25 +1224,20 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m *****************************************************************************/ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + L3INT rc = Q931E_NO_ERROR; Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; L3INT Octet = 0; /* Q931 Message Header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ - - /* Sending Complete */ + /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) - OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + OBuf[Octet++] = (L3UCHAR)Q931ie_SENDING_COMPLETE & 0xff; /* Repeat Indicator */ if(Q931IsIEPresent(pMes->RepeatInd)) - OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 0x00ff); + OBuf[Octet++] = (L3UCHAR)Q931ie_REPEAT_INDICATOR & 0xff; /* Bearer capability */ if(Q931IsIEPresent(pMes->BearerCap)) @@ -1359,7 +1326,7 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz *OSize = Octet; - return rc; + return rc; } /***************************************************************************** @@ -1389,8 +1356,8 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** @@ -1405,12 +1372,7 @@ L3INT Q931Pmes_SetupAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Channel Identification */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1480,12 +1442,7 @@ L3INT Q931Pmes_Status(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISi L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -1545,12 +1502,7 @@ L3INT Q931Pmes_StatusEnquiry(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->Display)) @@ -1602,12 +1554,7 @@ L3INT Q931Pmes_Suspend(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Call Identity */ if(Q931IsIEPresent(pMes->CallID)) @@ -1660,12 +1607,7 @@ L3INT Q931Pmes_SuspendAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->Display)) @@ -1718,12 +1660,7 @@ L3INT Q931Pmes_SuspendReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3 L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Cause */ if(Q931IsIEPresent(pMes->Cause)) @@ -1817,12 +1754,7 @@ L3INT Q931Pmes_Service(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Display */ if(Q931IsIEPresent(pMes->ChanID)) @@ -1883,12 +1815,7 @@ L3INT Q931Pmes_ServiceAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* 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) diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index 01e7a1416a..f09fa7577c 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -31,7 +31,7 @@ NOTE: The following are not yet implemented OnQ921Error Function called every if an error is - deteceted. + detected. OnQ921Log Function called if logging is active. @@ -76,84 +76,149 @@ *****************************************************************************/ +/**************************************************************************** + * 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 L2INT int /* Min 16 bit signed */ -#define L2ULONG unsigned long /* Min 32 bit */ +#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 * -typedef enum /* Network/User Mode. */ +#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 */ + Q921_TE=0, /* 0 : User Mode */ + Q921_NT=1 /* 1 : Network Mode */ } Q921NetUser_t; -typedef struct Q921Data Q921Data_t; -typedef int (*Q921TxCB_t) (void *, L2UCHAR *, L2INT); +typedef enum /* Type of connection */ +{ + Q921_PTP=0, /* 0 : Point-To-Point */ + Q921_PTMP=1 /* 1 : Point-To-Multipoint */ +} Q921NetType_t; -#define INITIALIZED_MAGIC 42 -struct Q921Data +typedef enum +{ + Q921_LOG_NONE = 0, + 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 { - L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE]; L2INT initialized; - L2UCHAR va; - L2UCHAR vs; - L2UCHAR vr; - L2INT state; - L2UCHAR sapi; - L2UCHAR tei; + + L2UCHAR sapi; /*!< User assigned SAPI */ + L2UCHAR tei; /*!< User assigned TEI value */ + + L2INT Q921HeaderSpace; Q921NetUser_t NetUser; - L2ULONG T200; - L2ULONG T203; + 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; - Q921TxCB_t Q921Tx21Proc; - Q921TxCB_t Q921Tx23Proc; + + 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; - L2INT Q921HeaderSpace; -}; + /* logging */ + Q921LogLevel_t loglevel; /*!< trunk loglevel */ + Q921LogCB_t Q921LogProc; /*!< log callback procedure */ + void *PrivateDataLog; /*!< private data pointer for log proc */ -void Q921_InitTrunk(L2TRUNK trunk, + /* 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, - Q921TxCB_t cb21, - Q921TxCB_t cb23, + Q921Tx21CB_t cb21, + Q921Tx23CB_t cb23, void *priv21, void *priv23); -int Q921QueueHDLCFrame(L2TRUNK trunk, L2UCHAR *b, L2INT size); -int Q921Rx12(L2TRUNK trunk); -int Q921Rx32(L2TRUNK trunk, L2UCHAR * Mes, L2INT Size); 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); -int Q921Tx21Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); -int Q921Tx23Proc(L2TRUNK trunk, L2UCHAR *Msg, L2INT size); -extern L2ULONG tLast; -L2ULONG Q921GetTime(void); -void Q921T200TimerStart(L2TRUNK trunk); -void Q921T200TimerStop(L2TRUNK trunk); -void Q921T200TimerReset(L2TRUNK trunk); -void Q921T203TimerStart(L2TRUNK trunk); -void Q921T203TimerStop(L2TRUNK trunk); -void Q921T203TimerReset(L2TRUNK trunk); -void Q921T200TimerExpire(L2TRUNK trunk); -void Q921T203TimerExpire(L2TRUNK trunk); -int Q921SendI(L2TRUNK trunk, L2UCHAR Sapi, char cr, L2UCHAR Tei, char pf, L2UCHAR *mes, L2INT size); -int Q921SendRNR(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendREJ(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendSABME(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendDM(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendDISC(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921SendUA(L2TRUNK trunk, int Sapi, int cr, int Tei, int pf); -int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size); - #endif - diff --git a/libs/freetdm/src/isdn/include/Q921priv.h b/libs/freetdm/src/isdn/include/Q921priv.h new file mode 100644 index 0000000000..c355e9b20d --- /dev/null +++ b/libs/freetdm/src/isdn/include/Q921priv.h @@ -0,0 +1,298 @@ +/***************************************************************************** + + 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_ + +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/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 70b84af070..2687930485 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -244,23 +244,35 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ *****************************************************************************/ -#define Q931L4BUF 1000 /* size of message buffer */ +#define Q931_LOGBUFSIZE 1024 /* size of logging buffer */ -#define Q931L2BUF 300 /* size of message buffer */ +#define Q931L4BUF 1000 /* size of message buffer */ -#define Q931MAXTRUNKS 4 /* Total number of trunks that will be */ - /* processed by this instance of the */ - /* stack */ +#define Q931L2BUF 300 /* size of message buffer */ -#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 Q931MAXTRUNKS 4 /* Total number of trunks that will be */ + /* processed by this instance of the */ + /* stack */ -#define Q931MAXCALLPERTRUNK (Q931MAXCHPERTRUNK * 2) - /* Number of max active CRV per trunk. */ - /* Q.931 can have more calls than there */ - /* are channels. */ +#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 /***************************************************************************** @@ -280,24 +292,19 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ *****************************************************************************/ -/* 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 */ +/* 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 */ /***************************************************************************** @@ -381,6 +388,155 @@ typedef L3USHORT ie; /* Special data type to hold a dynamic */ #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 @@ -479,33 +635,46 @@ typedef struct *****************************************************************************/ typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; -typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT); -typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT); - -typedef enum /* Network/User Mode. */ +typedef enum { - Q931_TE=0, /* 0 : User Mode */ - Q931_NT=1 /* 1 : Network Mode */ + Q931_LOG_NONE = 0, + 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 */ +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_5ESS = 6, /* Coming soon to a PRI stack near you! */ Q931_Dialect_Count } Q931Dialect_t; -#define DIALECT_STRINGS "q931", "", "national", "", "dms","","5ess","" +#define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", "" Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t) -typedef enum /* Trunk Line Type. */ +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_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 */ @@ -522,19 +691,51 @@ typedef enum { 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. */ - - Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ - Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ + Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ - Q931TxCB_t Q931Tx34CBProc; - Q931TxCB_t Q931Tx32CBProc; + 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 */ @@ -580,37 +781,9 @@ struct Q931_TrunkInfo }ch[Q931MAXCHPERTRUNK]; - /* Active Call information indentified by CRV. See Q931AllocateCRV for */ - /* initialization of call table. */ - struct _ccarray - { - L3UCHAR InUse; /* Indicate if entry is in use. */ - /* 0 = Not in Use */ - /* 1 = Active Call. */ - - 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 */ - - }call[Q931MAXCALLPERTRUNK]; - + /* Active Call information indentified by CRV. See Q931AllocateCRV for */ + /* initialization of call table. */ + struct Q931_Call call[Q931MAXCALLPERTRUNK]; }; /***************************************************************************** @@ -646,6 +819,9 @@ typedef L3INT (q931pmes_func_t) (Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf 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]; @@ -654,6 +830,10 @@ 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 @@ -893,9 +1073,9 @@ L3INT Q931ProcUnexpectedMessage(Q931_TrunkInfo_t *pTrunk,L3UCHAR * b, L3INT iFro Interface Function Prototypes. Implemented in Q931.c *****************************************************************************/ -void Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms); -L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size); -L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size); +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); @@ -910,6 +1090,8 @@ 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 timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc); +void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout); void Q931Initialize(void); void Q931AddDialect(L3UCHAR iDialect, void (*Q931CreateDialectCB)(L3UCHAR iDialect)); @@ -926,7 +1108,7 @@ 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 Q931SetGetTimeCB(L3ULONG (*callback)(void)); void Q931AddStateEntry(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); L3BOOL Q931IsEventLegal(L3UCHAR iD, L3INT iState, L3INT iMes, L3UCHAR cDir); @@ -965,8 +1147,8 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, Q931Dialect_t Dialect, Q931NetUser_t NetUser, Q931_TrunkType_t TrunkType, - Q931TxCB_t Q931Tx34CBProc, - Q931TxCB_t Q931Tx32CBProc, + Q931Tx34CB_t Q931Tx34CBProc, + Q931Tx32CB_t Q931Tx32CBProc, Q931ErrorCB_t Q931ErrorCBProc, void *PrivateData32, void *PrivateData34); @@ -974,7 +1156,9 @@ L3INT Q931Api_InitTrunk(Q931_TrunkInfo_t *pTrunk, 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); @@ -985,7 +1169,8 @@ L3INT Q931PmesDummy(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize 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/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index e64480dfb5..2acb937702 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -57,7 +57,7 @@ typedef enum { /* Single octet information elements */ #define Q931ie_SHIFT 0x90 /* 1001 ---- */ #define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ -#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0000 */ +#define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0001 */ #define Q931ie_CONGESTION_LEVEL 0xb0 /* 1011 ---- */ #define Q931ie_REPEAT_INDICATOR 0xd0 /* 1101 ---- */ @@ -101,6 +101,9 @@ typedef enum { #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 */ /***************************************************************************** @@ -1168,5 +1171,7 @@ L3INT Q931Pie_CongLevel(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, 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/freetdm/src/isdn/include/mfifo.h b/libs/freetdm/src/isdn/include/mfifo.h index 99faa1d1ba..477362466b 100644 --- a/libs/freetdm/src/isdn/include/mfifo.h +++ b/libs/freetdm/src/isdn/include/mfifo.h @@ -58,15 +58,15 @@ typedef struct _mindex queue. *****************************************************************************/ -typedef struct _mfifo +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; + unsigned char *buf; /* ptr to start of buffer */ + int ixsize; /* index size */ + MINDEX ix[1]; /* message index */ +} MFIFO; /***************************************************************************** Function prototypes. @@ -80,4 +80,8 @@ 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/freetdm/src/isdn/mfifo.c b/libs/freetdm/src/isdn/mfifo.c index a1e85dedf4..64dbcedfcc 100644 --- a/libs/freetdm/src/isdn/mfifo.c +++ b/libs/freetdm/src/isdn/mfifo.c @@ -84,17 +84,16 @@ *****************************************************************************/ int MFIFOCreate(unsigned char *buf, int size, int index) { - MFIFO * mf; - mf = (MFIFO*)buf; + MFIFO *mf = (MFIFO *)buf; mf->first = mf->last = 0; mf->ixsize = index; - mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * (index-1))]; + mf->buf = &buf[sizeof(MFIFO) + (sizeof(MINDEX) * index)]; - if(mf->buf > & buf[size]) + if(mf->buf > &buf[size]) return 0; - mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * (index-1)); + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index); return 1; } @@ -112,9 +111,9 @@ int MFIFOCreate(unsigned char *buf, int size, int index) *****************************************************************************/ void MFIFOClear(unsigned char * buf) { - MFIFO * mf; - mf = (MFIFO*)buf; - mf->first = mf->last = 0; + MFIFO *mf = (MFIFO *)buf; + + mf->first = mf->last = 0; } /***************************************************************************** @@ -130,8 +129,8 @@ void MFIFOClear(unsigned char * buf) *****************************************************************************/ int MFIFOGetLBOffset(unsigned char *buf) { - MFIFO * mf; - mf = (MFIFO*)buf; + MFIFO *mf = (MFIFO *)buf; + if(mf->last != mf->first) return mf->ix[mf->last].offset; @@ -153,15 +152,17 @@ int MFIFOGetLBOffset(unsigned char *buf) *****************************************************************************/ int MFIFOGetFBOffset(unsigned char *buf) { + MFIFO *mf = (MFIFO *)buf; int x; - MFIFO * mf; - mf = (MFIFO*)buf; + if(mf->last == mf->first) return 0; - x=mf->first; - x--; - if(x<0) - x=mf->ixsize; + + x = mf->first - 1; + + if(x < 0) + x = mf->ixsize - 1; + return mf->ix[x].offset + mf->ix[x].size; } @@ -184,16 +185,19 @@ int MFIFOGetFBOffset(unsigned char *buf) *****************************************************************************/ void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int off) { + MFIFO *mf = (MFIFO *)buf; int x; - MFIFO * mf; - mf = (MFIFO*)buf; - 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; + + 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; } /***************************************************************************** @@ -209,13 +213,14 @@ void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int *****************************************************************************/ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { - int of,ol,x; - MFIFO * mf; - mf = (MFIFO*)buf; + MFIFO *mf = (MFIFO *)buf; + int of, ol, x; + + x = mf->first + 1; + + if(x >= mf->ixsize) + x = 0; - x = mf->first+1; - if(x > mf->ixsize) - x=0; if(x == mf->last) return 0; /* full queue */ @@ -224,6 +229,7 @@ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) if(mf->last == mf->first) /* empty queue */ { mf->first = mf->last = 0; /* optimize */ + MFIFOWriteIX(buf, mes, size, mf->first, 0); return 1; } @@ -231,18 +237,18 @@ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { if(mf->bsize - of >= size) { - MFIFOWriteIX(buf,mes,size,mf->first,of); + MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } else if(ol > size) { - MFIFOWriteIX(buf,mes,size,mf->first,ol); + MFIFOWriteIX(buf, mes, size, mf->first, ol); return 1; } } else if(ol - of > size) { - MFIFOWriteIX(buf,mes,size,mf->first,of); + MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } @@ -262,12 +268,14 @@ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) *****************************************************************************/ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) { - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->first==mf->last) - return NULL; - *size = mf->ix[mf->last].size; - return &mf->buf[mf->ix[mf->last].offset]; + 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]; } /***************************************************************************** @@ -283,14 +291,120 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) *****************************************************************************/ void MFIFOKillNext(unsigned char *buf) { + MFIFO *mf = (MFIFO *)buf; int x; - MFIFO * mf; - mf = (MFIFO*)buf; - if(mf->first!=mf->last) + + if(mf->first != mf->last) { - x = mf->last+1; - if(x > mf->ixsize) - x=0; - mf->last=x; + 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/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index efd1d81ea2..99dcec3b9a 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -127,6 +127,9 @@ void nationalCreateTE(L3UCHAR i) 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.*/ diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 81361bd70d..90f7a1b1a3 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -155,12 +155,7 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT L3INT Octet = 0; /* Q931 Message Header */ - - OBuf[Octet++] = pMes->ProtDisc; /* Protocol discriminator */ - OBuf[Octet++] = 2; /* length is 2 octets */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7); /* msb */ - OBuf[Octet++] = (L3UCHAR)(pMes->CRV); /* lsb */ - OBuf[Octet++] = pMes->MesType; /* message header */ + Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ if(Q931IsIEPresent(pMes->SendComplete)) diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/zap_isdn.c index 4cd3cee8bd..912a14fb0d 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/zap_isdn.c @@ -44,6 +44,10 @@ #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) + static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); @@ -67,91 +71,117 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) Q931ie_CalledNum CalledNum; Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; + Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ + Q931ie_SendComplete SComplete; /* Sending Complete 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; - Q931InitIEBearerCap(&BearerCap); - Q931InitIEChanID(&ChanID); - Q931InitIECallingNum(&CallingNum); - Q931InitIECalledNum(&CalledNum); - Q931InitIEDisplay(&Display); + /* + * 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 */ - BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ - BearerCap.ITC = 0; /* Speech */ - BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ - BearerCap.ITR = 16; /* 64k */ + /* + * 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 = 2; /* U-law (a-law = 3)*/ - + 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); - ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */ - ChanID.InfoChanSel = 1; - ChanID.ChanMapType = 3; /* B-Chan */ - ChanID.ChanSlot = chan_id; + /* + * 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 + */ + 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); - /* TypNum: Type of number */ - /* Bits 7 6 5 */ - /* 000 Unknown */ - /* 001 International number */ - /* 010 National number */ - /* 011 Network Specific number */ - /* 100 Subscriber mumber */ - /* 110 Abbreviated number */ - /* 111 Reserved for extension */ - /* All other values are reserved */ - CallingNum.TypNum = 2; - - /* NumPlanID */ - /* Bits 4 3 2 1 */ - /* 0000 Unknown */ - /* 0001 ISDN/telephony numbering plan (E.164) */ - /* 0011 Data numbering plan (X.121) */ - /* 0100 Telex numbering plan (F.69) */ - /* 1000 National standard numbering plan */ - /* 1001 Private numbering plan */ - /* 1111 Reserved for extension */ - /* All other valures are reserved */ - CallingNum.NumPlanID = 1; - - /* Presentation indicator */ - /* Bits 7 6 */ - /* 00 Presenation Allowed */ - /* 01 Presentation Restricted */ - /* 10 Number not available due to internetworking */ - /* 11 Reserved */ - CallingNum.PresInd = 0; - - /* Screening Indicator */ - /* Bits 2 1 */ - /* 00 User-provided, not screened */ - /* 01 User-provided, verified and passed */ - /* 10 User-provided, verified and failed */ - /* 11 Network provided */ - CallingNum.ScreenInd = 0; + /* + * 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); - CalledNum.TypNum = 2; - CalledNum.NumPlanID = 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); + + /* + * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) + */ + SComplete.IEId = Q931ie_SENDING_COMPLETE; +// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); caller_data->call_state = ZAP_CALLER_STATE_DIALING; Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); @@ -211,7 +241,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) case Q931mes_ALERTING: new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; break; - break; case Q931mes_CONNECT: new_chan->init_state = ZAP_CHANNEL_STATE_UP; break; @@ -275,13 +304,17 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if (Q931IsIEPresent(gen->ChanID)) { Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); - chan_id = chanid->ChanSlot; + + if(chanid->IntType) + chan_id = chanid->ChanSlot; + else + chan_id = chanid->InfoChanSel; } assert(span != NULL); assert(isdn_data != NULL); - zap_log(ZAP_LOG_DEBUG, "Yay I got an event! Type:[%02x] Size:[%d]\n", gen->MesType, gen->Size); + 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) { @@ -313,7 +346,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan = isdn_data->channels_remote_crv[gen->CRV]; } - + zap_log(ZAP_LOG_DEBUG, "zchan %x source isdn_data->channels_%s_crv[%#hx]\n", zchan, gen->CRVFlag ? "local" : "remote", gen->CRV); if (gen->ProtDisc == 3) { @@ -376,8 +409,34 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); - } else { + 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 = isdn_data->sig_cb(&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 { @@ -418,6 +477,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) { 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); } @@ -425,23 +488,35 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; case Q931mes_SETUP: { - Q931ie_CallingNum *callingnum = Q931GetIEPtr(gen->CallingNum, gen->buf); Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); - zap_status_t status; int fail = 1; 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; if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { zchan = &span->channels[chan_id]; } - if (zchan && (status = zap_channel_open_chan(zchan) == ZAP_SUCCESS)) { + 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"); + 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)) { @@ -485,9 +560,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 = 0; + cause.CodStand = Q931_CODING_ITU; cause.Location = 1; cause.Recom = 1; //should we be casting here.. or do we need to translate value? @@ -506,11 +582,35 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); } + } else { + 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 = 1; /* call is not end-to-end isdn = 1, in-band information available = 8 */ + gen->ProgInd = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &progress); } - } 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; + default: + zap_log(ZAP_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType); break; } } @@ -518,16 +618,23 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) return 0; } -static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) +static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg, L2INT mlen) { - int ret; + int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; - print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); - ret = Q931Rx23(pvt, msg, mlen); - if (ret != 0) - zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); + switch(ind) { + case Q921_DL_DATA: + case Q921_DL_UNIT_DATA: + print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); + zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\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); } @@ -568,6 +675,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DOWN: { if (gen->CRV) { + if(gen->CRVFlag) { + 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); @@ -582,6 +694,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } else { gen->MesType = Q931mes_CALL_PROCEEDING; + gen->CRVFlag = 1; /* inbound */ + Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } } @@ -594,7 +708,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } - } break; case ZAP_CHANNEL_STATE_RESTART: @@ -613,7 +726,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); } } @@ -626,8 +746,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); } } @@ -641,117 +768,193 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_CalledNum CalledNum; Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; - - Q931InitIEBearerCap(&BearerCap); - Q931InitIEChanID(&ChanID); - Q931InitIECallingNum(&CallingNum); - Q931InitIECalledNum(&CalledNum); - Q931InitIEDisplay(&Display); + Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ + Q931ie_SendComplete SComplete; /* Sending Complete 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(?) */ - BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */ - BearerCap.ITC = 0; /* Speech */ - BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */ - BearerCap.ITR = 16; /* 64k */ + /* + * 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 = 2; /* U-law (a-law = 3)*/ + BearerCap.UIL1Prot = (codec == ZAP_CODEC_ALAW) ? 3 : 2; /* U-law = 2, A-law = 3 */ gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap); - //is cast right here? - ChanID.IntType = 1; /* PRI = 1, BRI = 0 */ - ChanID.InfoChanSel = 1; - ChanID.ChanMapType = 3; /* B-Chan */ - ChanID.ChanSlot = (unsigned char)zchan->chan_id; + /* + * 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 + */ + 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); - /* TypNum: Type of number*/ - /* Bits 7 6 5*/ - /* 000Unknown*/ - /* 001International number*/ - /* 010National number*/ - /* 011Network Specific number */ - /* 100Subscriber mumber*/ - /* 110Abbreviated number*/ - /* 111Reserved for extension*/ - /* All other values are reserved */ - CallingNum.TypNum = 2; - - /* NumPlanID*/ - /* Bits 4 3 2 1*/ - /* 0000Unknown*/ - /* 0001ISDN/telephony numbering plan (E.164)*/ - /* 0011Data numbering plan (X.121)*/ - /* 0100Telex numbering plan (F.69)*/ - /* 1000National standard numbering plan*/ - /* 1001Private numbering plan*/ - /* 1111Reserved for extension*/ - /* All other valures are reserved*/ - CallingNum.NumPlanID = 1; - - /* Presentation indicator*/ - /* Bits 7 6*/ - /* 00Presenation Allowed*/ - /* 01Presentation Restricted*/ - /* 10Number not available due to internetworking*/ - /* 11Reserved*/ - CallingNum.PresInd = 0; - - /* Screening Indicator*/ - /* Bits 2 1*/ - /* 00User-provided, not screened*/ - /* 01User-provided, verified and passed*/ - /* 10User-provided, verified and failed*/ - /* 11Network provided*/ - CallingNum.ScreenInd = 0; + /* + * CallingNum 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(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.TypNum = 2; - CalledNum.NumPlanID = 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); + + /* + * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) + */ + SComplete.IEId = Q931ie_SENDING_COMPLETE; +// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); + 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; - gen->MesType = Q931mes_DISCONNECT; + + 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 = 0; - cause.Location = 1; - cause.Recom = 1; - //should we be casting here.. or do we need to translate value? - 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); + 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 = isdn_data->sig_cb(&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: @@ -871,6 +1074,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) 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); @@ -887,8 +1091,6 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) break; case ZAP_TIMEOUT: { - /*zap_log(ZAP_LOG_DEBUG, "Timeout!\n");*/ - /*Q931TimeTick(isdn_data->q931, L3ULONG ms);*/ errs = 0; } break; @@ -937,7 +1139,8 @@ zap_status_t zap_isdn_init(void) Q931Initialize(); Q921SetGetTimeCB(zap_time_now); - + Q931SetGetTimeCB(zap_time_now); + return ZAP_SUCCESS; } @@ -948,16 +1151,66 @@ zap_status_t zap_isdn_start(zap_span_t *span) return zap_thread_create_detached(zap_isdn_run, span); } -static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen) +static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3INT mlen) { - int ret; + int offset = 4; char bb[4096] = ""; - ret = Q921Rx32(pvt, msg, mlen); - print_hex_bytes(msg, mlen, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen, LINE, bb); - return ret; + + switch(ind) { + case Q921_DL_UNIT_DATA: + offset = 3; + + case Q921_DL_DATA: + print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); + 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); } +static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) +{ + int loglevel = ZAP_LOG_LEVEL_DEBUG; + + switch(level) { + case Q921_LOG_DEBUG: + loglevel = ZAP_LOG_LEVEL_DEBUG; + break; + + case Q921_LOG_INFO: + loglevel = ZAP_LOG_LEVEL_INFO; + break; + + case Q921_LOG_NOTICE: + loglevel = ZAP_LOG_LEVEL_NOTICE; + break; + + case Q921_LOG_WARNING: + loglevel = ZAP_LOG_LEVEL_WARNING; + break; + + case Q921_LOG_ERROR: + loglevel = ZAP_LOG_LEVEL_ERROR; + break; + + default: + return 0; + } + + zap_log(__FILE__, "Q.921", __LINE__, loglevel, "%s", msg); + + return 0; +} + +static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size) +{ + zap_log(__FILE__, "Q.931", __LINE__, ZAP_LOG_LEVEL_DEBUG, "%s", msg); + return 0; +} static zap_state_map_t isdn_state_map = { { @@ -995,7 +1248,7 @@ static zap_state_map_t isdn_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END} }, { ZSD_OUTBOUND, @@ -1039,7 +1292,7 @@ static zap_state_map_t isdn_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_DOWN, ZAP_END}, }, { ZSD_INBOUND, @@ -1108,29 +1361,38 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; + isdn_data->mode = mode; Q921_InitTrunk(&isdn_data->q921, 0, 0, mode, + span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP, 0, zap_isdn_921_21, - (Q921TxCB_t)zap_isdn_921_23, + (Q921Tx23CB_t)zap_isdn_921_23, span, &isdn_data->q931); + + Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); + Q921SetLogLevel(&isdn_data->q921, Q921_LOG_DEBUG); Q931Api_InitTrunk(&isdn_data->q931, dialect, mode, span->trunk_type, zap_isdn_931_34, - (Q931TxCB_t)q931_rx_32, + (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, Q931_LOG_DEBUG); + isdn_data->q931.autoRestartAck = 1; - isdn_data->q931.autoConnectAck = 1; +// isdn_data->q931.autoConnectAck = 1; + isdn_data->q931.autoConnectAck = 0; isdn_data->q931.autoServiceAck = 1; span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; From 43c28c17dc7ffbbf84e85a8a622014133b189503 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 22 Aug 2008 17:56:09 +0000 Subject: [PATCH 0987/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@513 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a40b49e1fd..9c0af7659f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1906,7 +1906,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) { zap_global_destroy(); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_NOUNLOAD; } /* For Emacs: From d36e174cda5baba83d0c5d553f083a04e025ca6f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 22 Aug 2008 17:56:09 +0000 Subject: [PATCH 0988/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@513 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a40b49e1fd..9c0af7659f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1906,7 +1906,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) { zap_global_destroy(); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_NOUNLOAD; } /* For Emacs: From 2b8570e7497d6195686c4e6b1b461bd3b7ce75b7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Aug 2008 17:51:05 +0000 Subject: [PATCH 0989/1766] add start of zap_dso abstraction git-svn-id: http://svn.openzap.org/svn/openzap/trunk@514 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.vcproj | 12 +++++- libs/openzap/src/include/zap_dso.h | 44 ++++++++++++++++++++ libs/openzap/src/zap_dso.c | 66 ++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 libs/openzap/src/include/zap_dso.h create mode 100644 libs/openzap/src/zap_dso.c diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj index 10c7e5a912..c3af23614f 100644 --- a/libs/openzap/msvc/openzap.vcproj +++ b/libs/openzap/msvc/openzap.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../src/include;../src/isdn/include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -110,7 +110,7 @@ + + @@ -533,6 +537,10 @@ RelativePath="..\src\include\zap_config.h" > + + diff --git a/libs/openzap/src/include/zap_dso.h b/libs/openzap/src/include/zap_dso.h new file mode 100644 index 0000000000..e4337e64db --- /dev/null +++ b/libs/openzap/src/include/zap_dso.h @@ -0,0 +1,44 @@ +/* + * 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, const char **err); +zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const 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 + */ + diff --git a/libs/openzap/src/zap_dso.c b/libs/openzap/src/zap_dso.c new file mode 100644 index 0000000000..cbcc5914c8 --- /dev/null +++ b/libs/openzap/src/zap_dso.c @@ -0,0 +1,66 @@ +/* + * 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. + * + */ + + +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +void zap_dso_destroy(zap_dso_lib_t *lib) { + if (lib) { + dlclose(lib); + lib = NULL; + } +} + +zap_dso_lib_t zap_dso_open(const char *path, const char **err) { + void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); + if (lib == NULL) { + *err = strdup(dlerror()); + } + return lib; +} + +zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err) { + zap_dso_lib_t func = (zap_dso_lib_t)dlsym(lib, sym); + if (!func) { + *err = strdup(dlerror()); + } + return func; +} + +/* }====================================================== */ + +/* 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 + */ From b5a23ffa69a281627edf7e6960de70a8b810ea18 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Aug 2008 17:51:05 +0000 Subject: [PATCH 0990/1766] add start of zap_dso abstraction git-svn-id: http://svn.openzap.org/svn/openzap/trunk@514 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.vcproj | 12 +++++- libs/freetdm/src/include/zap_dso.h | 44 ++++++++++++++++++++ libs/freetdm/src/zap_dso.c | 66 ++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 libs/freetdm/src/include/zap_dso.h create mode 100644 libs/freetdm/src/zap_dso.c diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj index 10c7e5a912..c3af23614f 100644 --- a/libs/freetdm/msvc/openzap.vcproj +++ b/libs/freetdm/msvc/openzap.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../src/include;../src/isdn/include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -110,7 +110,7 @@ + + @@ -533,6 +537,10 @@ RelativePath="..\src\include\zap_config.h" > + + diff --git a/libs/freetdm/src/include/zap_dso.h b/libs/freetdm/src/include/zap_dso.h new file mode 100644 index 0000000000..e4337e64db --- /dev/null +++ b/libs/freetdm/src/include/zap_dso.h @@ -0,0 +1,44 @@ +/* + * 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, const char **err); +zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const 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 + */ + diff --git a/libs/freetdm/src/zap_dso.c b/libs/freetdm/src/zap_dso.c new file mode 100644 index 0000000000..cbcc5914c8 --- /dev/null +++ b/libs/freetdm/src/zap_dso.c @@ -0,0 +1,66 @@ +/* + * 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. + * + */ + + +/* +** {======================================================================== +** This is an implementation of loadlib based on the dlfcn interface. +** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, +** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least +** as an emulation layer on top of native functions. +** ========================================================================= +*/ + +#include + +void zap_dso_destroy(zap_dso_lib_t *lib) { + if (lib) { + dlclose(lib); + lib = NULL; + } +} + +zap_dso_lib_t zap_dso_open(const char *path, const char **err) { + void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); + if (lib == NULL) { + *err = strdup(dlerror()); + } + return lib; +} + +zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err) { + zap_dso_lib_t func = (zap_dso_lib_t)dlsym(lib, sym); + if (!func) { + *err = strdup(dlerror()); + } + return func; +} + +/* }====================================================== */ + +/* 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 + */ From be6eb554a71c54751e9bc532aca0823d79236afd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Aug 2008 17:57:44 +0000 Subject: [PATCH 0991/1766] add zap_dso abstraction git-svn-id: http://svn.openzap.org/svn/openzap/trunk@515 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 3 ++ libs/openzap/src/include/zap_dso.h | 70 +++++++++++++++--------------- libs/openzap/src/zap_dso.c | 62 +++++++++++++------------- 3 files changed, 71 insertions(+), 64 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 03454e6677..6c3bb534e5 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -46,6 +46,7 @@ $(SRC)/libteletone_detect.c \ $(SRC)/libteletone_generate.c \ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ +$(SRC)/zap_dso.c \ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -86,6 +87,7 @@ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ $(SRC)/zap_buffer.o \ $(SRC)/zap_threadmutex.o \ +$(SRC)/zap_dso.o \ $(SRC)/isdn/EuroISDNStateNT.o \ $(SRC)/isdn/EuroISDNStateTE.o \ $(SRC)/isdn/mfifo.o \ @@ -129,6 +131,7 @@ $(SRC)/include/zap_config.h \ $(SRC)/include/zap_isdn.h \ $(SRC)/include/zap_skel.h \ $(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_dso.h \ $(SRC)/include/zap_types.h \ $(SRC)/include/zap_wanpipe.h \ $(SRC)/include/zap_ss7_boost.h \ diff --git a/libs/openzap/src/include/zap_dso.h b/libs/openzap/src/include/zap_dso.h index e4337e64db..2c7be2b4be 100644 --- a/libs/openzap/src/include/zap_dso.h +++ b/libs/openzap/src/include/zap_dso.h @@ -1,25 +1,25 @@ -/* - * 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 +/* + * 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; @@ -29,16 +29,16 @@ zap_dso_lib_t zap_dso_open(const char *path, const char **err); zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const 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 - */ - +#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 + */ + diff --git a/libs/openzap/src/zap_dso.c b/libs/openzap/src/zap_dso.c index cbcc5914c8..aceaa5f5e5 100644 --- a/libs/openzap/src/zap_dso.c +++ b/libs/openzap/src/zap_dso.c @@ -1,22 +1,25 @@ -/* - * 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. - * - */ +/* + * 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. + * + */ +#include "zap_dso.h" +#include +#include /* ** {======================================================================== @@ -27,6 +30,7 @@ ** ========================================================================= */ + #include void zap_dso_destroy(zap_dso_lib_t *lib) { @@ -53,14 +57,14 @@ zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char * } /* }====================================================== */ - -/* 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 - */ + +/* 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 + */ From 8c4245dd54926aeb6306cda72525174c6c3f6c91 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Aug 2008 17:57:44 +0000 Subject: [PATCH 0992/1766] add zap_dso abstraction git-svn-id: http://svn.openzap.org/svn/openzap/trunk@515 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 3 ++ libs/freetdm/src/include/zap_dso.h | 70 +++++++++++++++--------------- libs/freetdm/src/zap_dso.c | 62 +++++++++++++------------- 3 files changed, 71 insertions(+), 64 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 03454e6677..6c3bb534e5 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -46,6 +46,7 @@ $(SRC)/libteletone_detect.c \ $(SRC)/libteletone_generate.c \ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ +$(SRC)/zap_dso.c \ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -86,6 +87,7 @@ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ $(SRC)/zap_buffer.o \ $(SRC)/zap_threadmutex.o \ +$(SRC)/zap_dso.o \ $(SRC)/isdn/EuroISDNStateNT.o \ $(SRC)/isdn/EuroISDNStateTE.o \ $(SRC)/isdn/mfifo.o \ @@ -129,6 +131,7 @@ $(SRC)/include/zap_config.h \ $(SRC)/include/zap_isdn.h \ $(SRC)/include/zap_skel.h \ $(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_dso.h \ $(SRC)/include/zap_types.h \ $(SRC)/include/zap_wanpipe.h \ $(SRC)/include/zap_ss7_boost.h \ diff --git a/libs/freetdm/src/include/zap_dso.h b/libs/freetdm/src/include/zap_dso.h index e4337e64db..2c7be2b4be 100644 --- a/libs/freetdm/src/include/zap_dso.h +++ b/libs/freetdm/src/include/zap_dso.h @@ -1,25 +1,25 @@ -/* - * 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 +/* + * 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; @@ -29,16 +29,16 @@ zap_dso_lib_t zap_dso_open(const char *path, const char **err); zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const 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 - */ - +#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 + */ + diff --git a/libs/freetdm/src/zap_dso.c b/libs/freetdm/src/zap_dso.c index cbcc5914c8..aceaa5f5e5 100644 --- a/libs/freetdm/src/zap_dso.c +++ b/libs/freetdm/src/zap_dso.c @@ -1,22 +1,25 @@ -/* - * 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. - * - */ +/* + * 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. + * + */ +#include "zap_dso.h" +#include +#include /* ** {======================================================================== @@ -27,6 +30,7 @@ ** ========================================================================= */ + #include void zap_dso_destroy(zap_dso_lib_t *lib) { @@ -53,14 +57,14 @@ zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char * } /* }====================================================== */ - -/* 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 - */ + +/* 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 + */ From 584880af5b1801b6c8da3fabfca7e2fe6345bf77 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 28 Aug 2008 15:50:26 +0000 Subject: [PATCH 0993/1766] Fix encoding of the Channel ID IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@516 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 36 ++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 983e158aee..d7716bc3da 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1288,28 +1288,26 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I { OBuf[(*Octet)++] = 0x80 | (pIE->InterfaceID & 0x7f); } - else + + /* Octet 3.2 & 3.3 - PRI */ + if(pIE->IntType) { - /* Octet 3.2 & 3.3 - PRI */ - if(pIE->IntType == 1) - { - OBuf[(*Octet)++] = 0x80 - | ((pIE->CodStand << 5) & 0x60) - | ((pIE->NumMap << 4) & 0x10) - | (pIE->ChanMapType & 0x0f); /* TODO: support all possible channel map types */ + 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; + /* 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; - } - } + 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; From 2973d68f37273446df6ea34f7363bab5f3f2992f Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 28 Aug 2008 15:50:26 +0000 Subject: [PATCH 0994/1766] Fix encoding of the Channel ID IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@516 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 36 ++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 983e158aee..d7716bc3da 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1288,28 +1288,26 @@ L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3I { OBuf[(*Octet)++] = 0x80 | (pIE->InterfaceID & 0x7f); } - else + + /* Octet 3.2 & 3.3 - PRI */ + if(pIE->IntType) { - /* Octet 3.2 & 3.3 - PRI */ - if(pIE->IntType == 1) - { - OBuf[(*Octet)++] = 0x80 - | ((pIE->CodStand << 5) & 0x60) - | ((pIE->NumMap << 4) & 0x10) - | (pIE->ChanMapType & 0x0f); /* TODO: support all possible channel map types */ + 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; + /* 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; - } - } + 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; From 92fbb583ab408cd3727e3c85bc2559099013b2bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 15:58:59 +0000 Subject: [PATCH 0995/1766] dyna won't you blow your horn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@517 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 128 ++++++--- libs/openzap/conf/modules.conf | 11 + libs/openzap/configure.ac | 3 + libs/openzap/mod_openzap/Makefile | 17 +- libs/openzap/mod_openzap/mod_openzap.c | 46 ++-- libs/openzap/src/hashtable.c | 62 +++++ libs/openzap/src/include/hashtable.h | 5 + libs/openzap/src/include/hashtable_private.h | 8 + libs/openzap/src/include/openzap.h | 5 + libs/openzap/src/include/zap_dso.h | 4 +- libs/openzap/src/include/zap_skel.h | 52 ---- libs/openzap/src/include/zap_types.h | 34 ++- libs/openzap/src/include/zap_wanpipe.h | 53 ---- .../ozmod_analog/ozmod_analog.c} | 54 +++- .../ozmod_analog}/zap_analog.h | 5 +- .../ozmod_isdn/ozmod_isdn.c} | 72 ++++-- .../{include => ozmod/ozmod_isdn}/zap_isdn.h | 4 - .../ozmod_pika/ozmod_pika.c} | 15 +- .../{include => ozmod/ozmod_pika}/zap_pika.h | 5 - .../ozmod_skel/ozmod_skel.c} | 40 ++- .../ozmod_ss7_boost/ozmod_ss7_boost.c} | 54 +++- .../ozmod_ss7_boost}/sigboost.h | 0 .../ozmod_ss7_boost}/ss7_boost_client.c | 0 .../ozmod_ss7_boost}/ss7_boost_client.h | 0 .../ozmod_ss7_boost}/zap_ss7_boost.h | 8 - .../ozmod_wanpipe/ozmod_wanpipe.c} | 14 +- .../ozmod_wanpipe}/wanpipe_tdm_api_iface.h | 0 .../{zap_zt.c => ozmod/ozmod_zt/ozmod_zt.c} | 13 +- .../zap_zt.h => ozmod/ozmod_zt/ozmod_zt.h} | 4 - libs/openzap/src/testanalog.c | 29 ++- libs/openzap/src/testboost.c | 26 +- libs/openzap/src/testisdn.c | 33 ++- libs/openzap/src/zap_dso.c | 12 +- libs/openzap/src/zap_io.c | 244 +++++++++++++----- 34 files changed, 706 insertions(+), 354 deletions(-) create mode 100644 libs/openzap/conf/modules.conf delete mode 100644 libs/openzap/src/include/zap_skel.h delete mode 100644 libs/openzap/src/include/zap_wanpipe.h rename libs/openzap/src/{zap_analog.c => ozmod/ozmod_analog/ozmod_analog.c} (95%) rename libs/openzap/src/{include => ozmod/ozmod_analog}/zap_analog.h (91%) rename libs/openzap/src/{zap_isdn.c => ozmod/ozmod_isdn/ozmod_isdn.c} (97%) rename libs/openzap/src/{include => ozmod/ozmod_isdn}/zap_isdn.h (91%) rename libs/openzap/src/{zap_pika.c => ozmod/ozmod_pika/ozmod_pika.c} (99%) rename libs/openzap/src/{include => ozmod/ozmod_pika}/zap_pika.h (96%) rename libs/openzap/src/{zap_skel.c => ozmod/ozmod_skel/ozmod_skel.c} (88%) rename libs/openzap/src/{zap_ss7_boost.c => ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c} (96%) rename libs/openzap/src/{include => ozmod/ozmod_ss7_boost}/sigboost.h (100%) rename libs/openzap/src/{ => ozmod/ozmod_ss7_boost}/ss7_boost_client.c (100%) rename libs/openzap/src/{include => ozmod/ozmod_ss7_boost}/ss7_boost_client.h (100%) rename libs/openzap/src/{include => ozmod/ozmod_ss7_boost}/zap_ss7_boost.h (88%) rename libs/openzap/src/{zap_wanpipe.c => ozmod/ozmod_wanpipe/ozmod_wanpipe.c} (99%) rename libs/openzap/src/{include => ozmod/ozmod_wanpipe}/wanpipe_tdm_api_iface.h (100%) rename libs/openzap/src/{zap_zt.c => ozmod/ozmod_zt/ozmod_zt.c} (99%) rename libs/openzap/src/{include/zap_zt.h => ozmod/ozmod_zt/ozmod_zt.h} (98%) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 6c3bb534e5..2ad180b430 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -35,8 +35,6 @@ SOURCES=\ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ -$(SRC)/zap_isdn.c \ -$(SRC)/zap_analog.c \ $(SRC)/zap_config.c \ $(SRC)/zap_callerid.c \ $(SRC)/fsk.c \ @@ -46,7 +44,14 @@ $(SRC)/libteletone_detect.c \ $(SRC)/libteletone_generate.c \ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ -$(SRC)/zap_dso.c \ +$(SRC)/zap_dso.c + +BOOST_SOURCES=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ +$(SRC)/ozmod/ozmod_ss7_boost/zap_ss7_boost.c + + +ISDN_SOURCES=\ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -66,18 +71,13 @@ $(SRC)/isdn/DMSStateTE.c \ $(SRC)/isdn/5ESSmes.c \ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c \ -$(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c \ -$(SRC)/ss7_boost_client.c \ -$(SRC)/zap_ss7_boost.c +$(SRC)/isdn/Q932mes.c + OBJS=\ $(SRC)/hashtable.o \ $(SRC)/hashtable_itr.o \ $(SRC)/zap_io.o \ -$(SRC)/zap_isdn.o \ -$(SRC)/zap_analog.o \ $(SRC)/zap_config.o \ $(SRC)/zap_callerid.o \ $(SRC)/fsk.o \ @@ -87,7 +87,13 @@ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ $(SRC)/zap_buffer.o \ $(SRC)/zap_threadmutex.o \ -$(SRC)/zap_dso.o \ +$(SRC)/zap_dso.o + +BOOST_OBJS=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o + + +ISDN_OBJS=\ $(SRC)/isdn/EuroISDNStateNT.o \ $(SRC)/isdn/EuroISDNStateTE.o \ $(SRC)/isdn/mfifo.o \ @@ -107,11 +113,8 @@ $(SRC)/isdn/DMSStateTE.o \ $(SRC)/isdn/5ESSmes.o \ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o \ -$(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o \ -$(SRC)/ss7_boost_client.o \ -$(SRC)/zap_ss7_boost.o +$(SRC)/isdn/Q932mes.o + HEADERS= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ @@ -124,18 +127,14 @@ $(SRC)/include/libteletone.h \ $(SRC)/include/openzap.h \ $(SRC)/include/sangoma_tdm_api.h \ $(SRC)/include/uart.h \ -$(SRC)/include/wanpipe_tdm_api_iface.h \ -$(SRC)/include/zap_analog.h \ $(SRC)/include/zap_buffer.h \ $(SRC)/include/zap_config.h \ -$(SRC)/include/zap_isdn.h \ -$(SRC)/include/zap_skel.h \ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_dso.h \ -$(SRC)/include/zap_types.h \ -$(SRC)/include/zap_wanpipe.h \ -$(SRC)/include/zap_ss7_boost.h \ -$(SRC)/include/zap_zt.h \ +$(SRC)/include/zap_types.h + + +ISDN_HEADERS=\ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ $(SRC)/isdn/include/DMS.h \ @@ -145,30 +144,33 @@ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h + PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -MYLIB=libopenzap.a +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost +CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" +MYLIB=libopenzap.so LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +PREFIX=@prefix@ PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) -ifneq ($(PIKA_DIR),) -ifneq ($(PIKA_LIB),) -OBJS += $(SRC)/zap_pika.o -CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -ADD_OBJS = $(PIKA_LIB) -endif -endif +#ifneq ($(PIKA_DIR),) +#ifneq ($(PIKA_LIB),) +#OBJS += $(SRC)/zap_pika.o +#CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +#ADD_OBJS = $(PIKA_LIB) +#endif +#endif -all: $(MYLIB) +all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - ranlib $(MYLIB) + #ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) + #ranlib $(MYLIB) + $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl testapp: $(SRC)/testapp.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread @@ -226,6 +228,54 @@ mod_openzap-install: mod_openzap mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi -clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog +clean: + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.so src/ozmod/*/*.dylib src/ozmod/*/*.dll @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + +install: all + @mkdir -p $(DESTDIR)$(PREFIX) + @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf) + @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) + @mkdir -p $(DESTDIR)$(PREFIX)/lib + @[ ! -f $(MYLIB) ] || cp -f $(MYLIB) $(DESTDIR)$(PREFIX)/lib + @mkdir -p $(DESTDIR)$(PREFIX)/mod + @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod + @cp -f src/ozmod/*/*.so $(DESTDIR)$(PREFIX)/mod + @echo OpenZAP Installed + +uninstall: + @rm -fr $(DESTDIR)$(PREFIX) + +$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib +skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so + + +$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so + +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so + +$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: + $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib + +pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so + +$(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c + +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so + +$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) + $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so + +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so + + diff --git a/libs/openzap/conf/modules.conf b/libs/openzap/conf/modules.conf new file mode 100644 index 0000000000..28d8d0b6eb --- /dev/null +++ b/libs/openzap/conf/modules.conf @@ -0,0 +1,11 @@ +[modules] +;load => ozmod_skel +load => ozmod_zt +load => ozmod_wanpipe +;load => ozmod_pika +load => ozmod_isdn +load => ozmod_analog +;load => ozmod_ss7_boost + + + diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 480527be18..76ee2c8df0 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -10,6 +10,9 @@ AC_PROG_CC AC_PROG_MAKE_SET AC_PROG_RANLIB + +AC_PREFIX_DEFAULT(/usr/local/openzap) + # Check for com;iler type AC_DEFUN([AX_COMPILER_VENDOR], [ diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index 1552a37c45..b380a8103a 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -1,14 +1,21 @@ BASE=../../.. OZ_DIR=.. VERBOSE=1 -OZA=$(OZ_DIR)/libopenzap.a +OZSO=$(OZ_DIR)/libopenzap.so LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include -LOCAL_LIBADD=$(OZA) +LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap include $(BASE)/build/modmake.rules -local_depend: $(OZA) +local_depend: $(OZSO) -$(OZA): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="$(ALL_CXXFLAGS)" +$(OZSO): $(OZ_DIR)/.update + cd $(OZ_DIR) && $(MAKE) ZAP_CFLAGS="$(ALL_CXXFLAGS)" + +local_install: + cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)" + [ ! -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs + +local_clean: + cd $(OZ_DIR) && $(MAKE) clean diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 9c0af7659f..ae9133bf1d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -31,9 +31,6 @@ */ #include #include "openzap.h" -#include "zap_analog.h" -#include "zap_isdn.h" -#include "zap_ss7_boost.h" #ifndef __FUNCTION__ #define __FUNCTION__ __SWITCH_FUNC__ @@ -1562,7 +1559,11 @@ static switch_status_t load_config(void) continue; } - if (zap_analog_configure_span(span, tonegroup, to, max, on_analog_signal) != ZAP_SUCCESS) { + if (zap_configure_span("analog", span, on_analog_signal, + "tonemap", tonegroup, + "digit_timeout", &to, + "max_dialstr", &max + ) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } @@ -1584,7 +1585,7 @@ static switch_status_t load_config(void) switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_analog_start(span); + zap_span_start(span); } } @@ -1593,12 +1594,14 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr_soft(myspan, "id"); char *context = "default"; char *dialplan = "XML"; - Q921NetUser_t mode = Q931_TE; - Q931Dialect_t dialect = Q931_Dialect_National; + //Q921NetUser_t mode = Q931_TE; + //Q931Dialect_t dialect = Q931_Dialect_National; + char *mode = NULL; + char *dialect = NULL; uint32_t span_id = 0; zap_span_t *span = NULL; char *tonegroup = NULL; - zap_isdn_opts_t opts = ZAP_ISDN_OPT_NONE; + uint32_t opts = 0; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1607,16 +1610,13 @@ static switch_status_t load_config(void) if (!strcasecmp(var, "tonegroup")) { tonegroup = val; } else if (!strcasecmp(var, "mode")) { - mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT; + mode = val; } else if (!strcasecmp(var, "dialect")) { - dialect = q931_str2Q931Dialect_type(val); - if (dialect == Q931_Dialect_Count) { - dialect = Q931_Dialect_National; - } + dialect = val; } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { - opts |= ZAP_ISDN_OPT_SUGGEST_CHANNEL; + opts |= 1; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } @@ -1637,8 +1637,11 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } - - if (zap_isdn_configure_span(span, mode, dialect, opts, on_clear_channel_signal) != ZAP_SUCCESS) { + + if (zap_configure_span("isdn", span, on_clear_channel_signal, + "mode", mode, + "dialect", dialect + ) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -1648,7 +1651,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_isdn_start(span); + zap_span_start(span); } } @@ -1702,7 +1705,12 @@ static switch_status_t load_config(void) continue; } - if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_clear_channel_signal) != ZAP_SUCCESS) { + if (zap_configure_span("ss7_boost", span, on_clear_channel_signal, + "local_ip", local_ip, + "local_port", &local_port, + "remote_ip", remote_ip, + "remote_port", &remote_port + ) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } @@ -1711,7 +1719,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); - zap_ss7_boost_start(span); + zap_span_start(span); switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); } } diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index 5cc2bb0c40..8e252339a2 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -230,6 +230,68 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values) free(h); } +struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) +{ + + if (i->e) { + if ((i->e = i->e->next)) { + return i; + } else { + i->pos++; + } + } + + while(i->pos < i->h->tablelength && !i->h->table[i->pos]) { + i->pos++; + } + + if (i->pos >= i->h->tablelength) { + return NULL; + } + + if ((i->e = i->h->table[i->pos])) { + return i; + } + + return NULL; +} + +struct hashtable_iterator *hashtable_first(struct hashtable *h) +{ + h->iterator.pos = 0; + h->iterator.e = NULL; + h->iterator.h = h; + return hashtable_next(&h->iterator); +} + + + +void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) +{ + if (i->e) { + if (key) { + *key = i->e->k; + } + if (klen) { + *klen = strlen(i->e->k); + } + if (val) { + *val = i->e->v; + } + } else { + if (key) { + *key = NULL; + } + if (klen) { + *klen = 0; + } + if (val) { + *val = NULL; + } + } +} + + /* * Copyright (c) 2002, Christopher Clark * All rights reserved. diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index 4c3c48f4bf..243441c1d4 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -9,6 +9,7 @@ #endif struct hashtable; +struct hashtable_iterator; /* Example of use: * @@ -168,6 +169,10 @@ hashtable_count(struct hashtable *h); void hashtable_destroy(struct hashtable *h, int free_keys, int free_values); +struct hashtable_iterator *hashtable_first(struct hashtable *h); +struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i); +void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); + #endif /* __HASHTABLE_CWC22_H__ */ /* diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index ede652c654..81197e6cb3 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -7,6 +7,7 @@ /*****************************************************************************/ + struct entry { void *k, *v; @@ -14,6 +15,12 @@ struct entry struct entry *next; }; +struct hashtable_iterator { + int pos; + struct entry *e; + struct hashtable *h; +}; + struct hashtable { unsigned int tablelength; struct entry **table; @@ -22,6 +29,7 @@ struct hashtable { unsigned int primeindex; unsigned int (*hashfn) (void *k); int (*eqfn) (void *k1, void *k2); + struct hashtable_iterator iterator; }; /*****************************************************************************/ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 26b050181e..ff13d47386 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -479,6 +479,7 @@ struct zap_span { zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; + zap_span_start_t start; void *mod_data; char *type; int suggest_chan_id; @@ -579,6 +580,10 @@ uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); zap_status_t zap_channel_complete_state(zap_channel_t *zchan); zap_status_t zap_channel_init(zap_channel_t *zchan); +int zap_load_modules(void); +zap_status_t zap_unload_modules(void); +zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); +zap_status_t zap_span_start(zap_span_t *span); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/include/zap_dso.h b/libs/openzap/src/include/zap_dso.h index 2c7be2b4be..bf51f92b18 100644 --- a/libs/openzap/src/include/zap_dso.h +++ b/libs/openzap/src/include/zap_dso.h @@ -25,8 +25,8 @@ 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, const char **err); -zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err); +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 diff --git a/libs/openzap/src/include/zap_skel.h b/libs/openzap/src/include/zap_skel.h deleted file mode 100644 index a8a245837f..0000000000 --- a/libs/openzap/src/include/zap_skel.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ZAP_SKEL_H -#define ZAP_SKEL_H -#include "openzap.h" - -zap_status_t skel_init(zap_software_interface_t **zint); -zap_status_t skel_destroy(void); - -#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 expandtab: - */ diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 7c092e7f70..9c14686f8c 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -52,6 +52,7 @@ typedef int zap_filehandle_t; #include #include #include +#include typedef int zap_socket_t; typedef ssize_t zap_ssize_t; typedef int zap_filehandle_t; @@ -383,6 +384,7 @@ 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; #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) @@ -402,6 +404,11 @@ typedef struct zap_caller_data zap_caller_data_t; #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) 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 ; @@ -421,6 +428,11 @@ 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 ; #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 @@ -440,6 +452,24 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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 + +#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__ @@ -468,13 +498,13 @@ 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 zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; -typedef struct hashtable_itr zap_hash_itr_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 enum { ZAP_CAUSE_NONE = 0, diff --git a/libs/openzap/src/include/zap_wanpipe.h b/libs/openzap/src/include/zap_wanpipe.h deleted file mode 100644 index 0b2f4a9c48..0000000000 --- a/libs/openzap/src/include/zap_wanpipe.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ZAP_WANPIPE_H -#define ZAP_WANPIPE_H -#include "openzap.h" - -zap_status_t wanpipe_init(zap_io_interface_t **zint); -zap_status_t wanpipe_destroy(void); - -#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 expandtab: - */ - diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c similarity index 95% rename from libs/openzap/src/zap_analog.c rename to libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 64836c7436..fe438c2244 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -70,9 +70,24 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) return ZAP_SUCCESS; } -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) + +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); +} + +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; + char *tonemap = "us"; + uint32_t digit_timeout = 10; + uint32_t max_dialstr = 11; + char *var, *val; + int *intval; + assert(sig_cb != NULL); if (span->signal_type) { @@ -92,6 +107,27 @@ zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); + + 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; + } + } + + span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; analog_data->sig_cb = sig_cb; @@ -793,13 +829,21 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) } -zap_status_t zap_analog_start(zap_span_t *span) +static ZIO_SIG_LOAD_FUNCTION(zap_analog_init) { - 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); + return ZAP_SUCCESS; } +zap_module_t zap_module = { + "analog", + NULL, + NULL, + zap_analog_init, + zap_analog_configure_span, + NULL +}; + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/include/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h similarity index 91% rename from libs/openzap/src/include/zap_analog.h rename to libs/openzap/src/ozmod/ozmod_analog/zap_analog.h index 5322463577..2d90910244 100644 --- a/libs/openzap/src/include/zap_analog.h +++ b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h @@ -39,12 +39,9 @@ typedef enum { ZAP_ANALOG_RUNNING = (1 << 0) } zap_analog_flag_t; - +static void *zap_analog_run(zap_thread_t *me, void *obj); typedef struct zap_analog_data zap_analog_data_t; -zap_status_t zap_analog_start(zap_span_t *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); - #endif /* For Emacs: diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c similarity index 97% rename from libs/openzap/src/zap_isdn.c rename to libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 912a14fb0d..78792ba72c 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -663,7 +663,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_sigmsg_t sig; zap_status_t status; - zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n", + 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)); @@ -1134,7 +1134,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) return NULL; } -zap_status_t zap_isdn_init(void) +static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) { Q931Initialize(); @@ -1144,13 +1144,6 @@ zap_status_t zap_isdn_init(void) return ZAP_SUCCESS; } -zap_status_t zap_isdn_start(zap_span_t *span) -{ - zap_isdn_data_t *isdn_data = span->signal_data; - zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); - return zap_thread_create_detached(zap_isdn_run, span); -} - static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3INT mlen) { int offset = 4; @@ -1317,11 +1310,24 @@ static zap_state_map_t isdn_state_map = { } }; -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb) +static zap_status_t zap_isdn_start(zap_span_t *span) +{ + zap_isdn_data_t *isdn_data = span->signal_data; + zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); + return zap_thread_create_detached(zap_isdn_run, span); +} + + + +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; + char *var, *val; + Q931Dialect_t dialect = Q931_Dialect_National; + uint32_t opts = 0; + if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; @@ -1352,21 +1358,46 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D 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) { + dialect = Q931_Dialect_National; + } + } else if (!strcasecmp(var, "opts")) { + int *optp; + if (!(optp = va_arg(ap, int *))) { + break; + } + opts = isdn_data->opts = *optp; + } + } + + span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; - isdn_data->mode = mode; Q921_InitTrunk(&isdn_data->q921, 0, 0, - mode, + isdn_data->mode, span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP, 0, zap_isdn_921_21, @@ -1379,7 +1410,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D Q931Api_InitTrunk(&isdn_data->q931, dialect, - mode, + isdn_data->mode, span->trunk_type, zap_isdn_931_34, (Q931Tx32CB_t)q931_rx_32, @@ -1397,7 +1428,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - isdn_data->opts = opts; + if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; @@ -1408,6 +1439,17 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "isdn", + NULL, + NULL, + zap_isdn_init, + zap_isdn_configure_span, + NULL +}; + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/include/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h similarity index 91% rename from libs/openzap/src/include/zap_isdn.h rename to libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index e18a51ab0a..86a3f40155 100644 --- a/libs/openzap/src/include/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -64,10 +64,6 @@ struct zap_isdn_data { typedef struct zap_isdn_data zap_isdn_data_t; -zap_status_t zap_isdn_start(zap_span_t *span); -zap_status_t zap_isdn_init(void); -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb); - #endif /* For Emacs: diff --git a/libs/openzap/src/zap_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c similarity index 99% rename from libs/openzap/src/zap_pika.c rename to libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c index ffe79e397c..e3121309ec 100644 --- a/libs/openzap/src/zap_pika.c +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c @@ -1179,7 +1179,7 @@ static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) static zap_io_interface_t pika_interface; -zap_status_t pika_init(zap_io_interface_t **zint) +static ZIO_IO_LOAD_FUNCTION(pika_init) { PK_STATUS status; @@ -1189,7 +1189,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) PKH_TLogMasks m; TPikaHandle tmpHandle; - assert(zint != NULL); + assert(zio != NULL); memset(&pika_interface, 0, sizeof(pika_interface)); memset(&globals, 0, sizeof(globals)); globals.general_config.region = PKH_TRUNK_NA; @@ -1271,7 +1271,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) pika_interface.channel_destroy = pika_channel_destroy; pika_interface.span_destroy = pika_span_destroy; pika_interface.get_alarms = pika_get_alarms; - *zint = &pika_interface; + *zio = &pika_interface; zap_log(ZAP_LOG_INFO, "Dumping Default configs:\n"); @@ -1313,7 +1313,8 @@ zap_status_t pika_init(zap_io_interface_t **zint) return ZAP_SUCCESS; } -zap_status_t pika_destroy(void) + +static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) { uint32_t x; PK_STATUS status; @@ -1339,6 +1340,12 @@ zap_status_t pika_destroy(void) return ZAP_SUCCESS; } +zap_module_t zap_module = { + "pika", + pika_init, + pika_destroy, +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/include/zap_pika.h b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h similarity index 96% rename from libs/openzap/src/include/zap_pika.h rename to libs/openzap/src/ozmod/ozmod_pika/zap_pika.h index a98c08cbe6..c8401c6aa1 100644 --- a/libs/openzap/src/include/zap_pika.h +++ b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h @@ -94,11 +94,6 @@ typedef enum { #define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW" ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) - -/* Openzap PIKA hardware interface functions */ -zap_status_t pika_init(zap_io_interface_t **zint); -zap_status_t pika_destroy(void); - #endif /* For Emacs: diff --git a/libs/openzap/src/zap_skel.c b/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c similarity index 88% rename from libs/openzap/src/zap_skel.c rename to libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c index 575550979a..aa468a356f 100644 --- a/libs/openzap/src/zap_skel.c +++ b/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c @@ -33,52 +33,40 @@ #include "openzap.h" -#include "zap_skel.h" +//#include "zap_skel.h" static ZIO_CONFIGURE_FUNCTION(skel_configure) { - ZIO_CONFIGURE_MUZZLE; return ZAP_FAIL; } static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) { - + return ZAP_FAIL; } static ZIO_OPEN_FUNCTION(skel_open) { - ZIO_OPEN_MUZZLE; return ZAP_FAIL; } static ZIO_CLOSE_FUNCTION(skel_close) { - ZIO_CLOSE_MUZZLE; - return ZAP_FAIL; -} - -static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval) -{ - ZIO_SET_INTERVAL_MUZZLE; return ZAP_FAIL; } static ZIO_WAIT_FUNCTION(skel_wait) { - ZIO_WAIT_MUZZLE; return ZAP_FAIL; } static ZIO_READ_FUNCTION(skel_read) { - ZIO_READ_MUZZLE; return ZAP_FAIL; } static ZIO_WRITE_FUNCTION(skel_write) { - ZIO_WRITE_MUZZLE; return ZAP_FAIL; } @@ -102,21 +90,21 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) return ZAP_FAIL; } -static ZIO_CHANNEL_DESTROY_FUNCTION(skel_span_destroy) +static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy) { return ZAP_FAIL; } static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) { - return zap_fail; + return ZAP_FAIL; } static zap_io_interface_t skel_interface; -zap_status_t skel_init(zap_io_interface_t **zint) +static ZIO_IO_LOAD_FUNCTION(skel_init) { - assert(zint != NULL); + assert(zio != NULL); memset(&skel_interface, 0, sizeof(skel_interface)); skel_interface.name = "skel"; @@ -133,16 +121,24 @@ zap_status_t skel_init(zap_io_interface_t **zint) skel_interface.channel_destroy = skel_channel_destroy; skel_interface.span_destroy = skel_span_destroy; skel_interface.get_alarms = skel_get_alarms; - *zint = &skel_interface; + *zio = &skel_interface; - return ZAP_FAIL; + return ZAP_SUCCESS; } -zap_status_t skel_destroy(void) +static ZIO_IO_UNLOAD_FUNCTION(skel_destroy) { - return ZAP_FAIL; + return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "skel", + skel_init, + skel_destroy, +}; + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/zap_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c similarity index 96% rename from libs/openzap/src/zap_ss7_boost.c rename to libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 4a26054029..64cad3c02d 100644 --- a/libs/openzap/src/zap_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -974,15 +974,15 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) return NULL; } -zap_status_t zap_ss7_boost_init(void) +static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) { zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); - + return ZAP_SUCCESS; } -zap_status_t zap_ss7_boost_start(zap_span_t *span) +static zap_status_t zap_ss7_boost_start(zap_span_t *span) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); @@ -1088,13 +1088,39 @@ static zap_state_map_t boost_state_map = { } }; -zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, - const char *local_ip, int local_port, - const char *remote_ip, int remote_port, - zio_signal_cb_t sig_cb) +static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; - + char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; + int local_port = 5300, remote_port = 5300; + 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; + } + } + + if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { return ZAP_FAIL; } @@ -1108,7 +1134,7 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); ss7_boost_data->mcon.cfg.remote_port = remote_port; ss7_boost_data->signal_cb = sig_cb; - + span->start = zap_ss7_boost_start; span->signal_data = ss7_boost_data; span->signal_type = ZAP_SIGTYPE_SS7BOOST; span->outgoing_call = ss7_boost_outgoing_call; @@ -1119,6 +1145,16 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "analog", + NULL, + NULL, + zap_ss7_boost_init, + zap_ss7_boost_configure_span, + NULL +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/include/sigboost.h b/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h similarity index 100% rename from libs/openzap/src/include/sigboost.h rename to libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h diff --git a/libs/openzap/src/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c similarity index 100% rename from libs/openzap/src/ss7_boost_client.c rename to libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c diff --git a/libs/openzap/src/include/ss7_boost_client.h b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h similarity index 100% rename from libs/openzap/src/include/ss7_boost_client.h rename to libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h diff --git a/libs/openzap/src/include/zap_ss7_boost.h b/libs/openzap/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h similarity index 88% rename from libs/openzap/src/include/zap_ss7_boost.h rename to libs/openzap/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h index c5496b8aed..b3f3e416bf 100644 --- a/libs/openzap/src/include/zap_ss7_boost.h +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h @@ -48,14 +48,6 @@ typedef struct zap_ss7_boost_data { uint32_t flags; } zap_ss7_boost_data_t; -zap_status_t zap_ss7_boost_start(zap_span_t *span); -zap_status_t zap_ss7_boost_init(void); -zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, - const char *local_ip, int local_port, - const char *remote_ip, int remote_port, - zio_signal_cb_t sig_cb); - - #endif /* For Emacs: diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c similarity index 99% rename from libs/openzap/src/zap_wanpipe.c rename to libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index bbeb191b4a..19d74cdb19 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -36,10 +36,9 @@ #include #endif #include "openzap.h" -#include "zap_wanpipe.h" #include #include -#include +#include "wanpipe_tdm_api_iface.h" typedef enum { WP_RINGING = (1 << 0) @@ -935,7 +934,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) return ZAP_SUCCESS; } -zap_status_t wanpipe_init(zap_io_interface_t **zio) +static ZIO_IO_LOAD_FUNCTION(wanpipe_init) { assert(zio != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); @@ -964,12 +963,19 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) return ZAP_SUCCESS; } -zap_status_t wanpipe_destroy(void) +static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) { memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "wanpipe", + wanpipe_init, + wanpipe_destroy, +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/include/wanpipe_tdm_api_iface.h b/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h similarity index 100% rename from libs/openzap/src/include/wanpipe_tdm_api_iface.h rename to libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c similarity index 99% rename from libs/openzap/src/zap_zt.c rename to libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 38c55ffae5..4b271ed6f5 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -33,7 +33,7 @@ #include "openzap.h" -#include "zap_zt.h" +#include "ozmod_zt.h" static struct { @@ -737,7 +737,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) static zap_io_interface_t zt_interface; -zap_status_t zt_init(zap_io_interface_t **zio) +static ZIO_IO_LOAD_FUNCTION(zt_init) { assert(zio != NULL); memset(&zt_interface, 0, sizeof(zt_interface)); @@ -772,13 +772,20 @@ zap_status_t zt_init(zap_io_interface_t **zio) return ZAP_SUCCESS; } -zap_status_t zt_destroy(void) +static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) { close(CONTROL_FD); memset(&zt_interface, 0, sizeof(zt_interface)); return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "zt", + zt_init, + zt_destroy, +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h similarity index 98% rename from libs/openzap/src/include/zap_zt.h rename to libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h index 0e16d29398..c3e2067585 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h @@ -280,10 +280,6 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #define ZT_ECHOTRAIN _IOW (ZT_CODE, 50, int) /* Control Echo Trainer */ -/* Openzap ZT hardware interface functions */ -zap_status_t zt_init(zap_io_interface_t **zint); -zap_status_t zt_destroy(void); - #endif /* For Emacs: diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 1ad530db89..813605decc 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -1,5 +1,4 @@ #include "openzap.h" -#include "zap_analog.h" static void *test_call(zap_thread_t *me, void *obj) @@ -59,11 +58,20 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) return ZAP_SUCCESS; } +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; int span_id; - zap_analog_data_t *analog_data; + int digit_timeout = 2000; + int max_dialstr = 11; if (argc < 2) { printf("usage %s \n", argv[0]); @@ -86,19 +94,22 @@ int main(int argc, char *argv[]) goto done; } - if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) { + + if (zap_configure_span("analog", span, on_signal, + "tonemap", "te", + "digit_timeout", &digit_timeout, + "max_dialstr", &max_dialstr + ) == ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); goto done; } - analog_data = span->signal_data; - zap_analog_start(span); - - while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { + zap_span_start(span); + + while(zap_running() && R) { zap_sleep(1 * 1000); } - - done: +done: zap_global_destroy(); diff --git a/libs/openzap/src/testboost.c b/libs/openzap/src/testboost.c index 4fb9ee12ba..c27636efab 100644 --- a/libs/openzap/src/testboost.c +++ b/libs/openzap/src/testboost.c @@ -1,15 +1,24 @@ #include "openzap.h" -#include "zap_ss7_boost.h" 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_ss7_boost_data_t *data; + int local_port, remote_port; + + local_port = remote_port = 53000; zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); @@ -30,16 +39,19 @@ int main(int argc, char *argv[]) goto done; } - - if (zap_ss7_boost_configure_span(span, "127.0.0.65", 53000, "127.0.0.66", 53000, on_signal) == ZAP_SUCCESS) { - data = span->signal_data; - zap_ss7_boost_start(span); + 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 + ) == ZAP_SUCCESS) { + zap_span_start(span); } else { fprintf(stderr, "Error starting SS7_BOOST\n"); goto done; } - while(zap_test_flag(data, ZAP_SS7_BOOST_RUNNING)) { + while(zap_running() && R) { zap_sleep(1 * 1000); } diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 88cc113717..29bf4c952b 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -1,16 +1,24 @@ #include "openzap.h" -#include "zap_isdn.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_isdn_data_t *data; - + zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); if (argc < 2) { @@ -31,15 +39,30 @@ int main(int argc, char *argv[]) } +#if 1 + + if (zap_configure_span("isdn", span, on_signal, + "mode", "te", + "dialect", "national" + ) == ZAP_SUCCESS) { + zap_span_start(span); + } else { + fprintf(stderr, "Error starting ISDN D-Channel\n"); + goto done; + } +#else if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) { - data = span->signal_data; zap_isdn_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } - while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { +#endif + + signal(SIGINT, handle_SIGINT); + R = 1; + while(R) { zap_sleep(1 * 1000); } diff --git a/libs/openzap/src/zap_dso.c b/libs/openzap/src/zap_dso.c index aceaa5f5e5..07c25f29fd 100644 --- a/libs/openzap/src/zap_dso.c +++ b/libs/openzap/src/zap_dso.c @@ -34,13 +34,13 @@ #include void zap_dso_destroy(zap_dso_lib_t *lib) { - if (lib) { - dlclose(lib); - lib = NULL; + if (lib && *lib) { + dlclose(*lib); + *lib = NULL; } } -zap_dso_lib_t zap_dso_open(const char *path, const char **err) { +zap_dso_lib_t zap_dso_open(const char *path, char **err) { void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (lib == NULL) { *err = strdup(dlerror()); @@ -48,8 +48,8 @@ zap_dso_lib_t zap_dso_open(const char *path, const char **err) { return lib; } -zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err) { - zap_dso_lib_t func = (zap_dso_lib_t)dlsym(lib, sym); +void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { + void *func = dlsym(lib, sym); if (!func) { *err = strdup(dlerror()); } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2c24cc5d85..7eb6bda296 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -32,22 +32,14 @@ */ #ifndef WIN32 -#define ZAP_ZT_SUPPORT -#define ZAP_WANPIPE_SUPPORT #endif #include "openzap.h" -#include "zap_isdn.h" -#include "zap_ss7_boost.h" +//#include "zap_isdn.h" +//#include "zap_ss7_boost.h" #include #ifdef WIN32 #include #endif -#ifdef ZAP_WANPIPE_SUPPORT -#include "zap_wanpipe.h" -#endif -#ifdef ZAP_ZT_SUPPORT -#include "zap_zt.h" -#endif #ifdef ZAP_PIKA_SUPPORT #include "zap_pika.h" #endif @@ -83,6 +75,7 @@ zap_time_t zap_current_time_in_ms(void) static struct { zap_hash_t *interface_hash; + zap_hash_t *module_hash; zap_mutex_t *mutex; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; uint32_t span_index; @@ -1929,8 +1922,6 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } static struct { - zap_io_interface_t *wanpipe_interface; - zap_io_interface_t *zt_interface; zap_io_interface_t *pika_interface; } interfaces; @@ -2104,6 +2095,173 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } +int zap_load_modules(void) +{ + char cfg_name[] = "modules.conf"; + char path[128] = ""; + zap_config_t cfg; + char *err; + char *var, *val; + zap_module_t *mod; + int count = 0; + +#ifdef WIN32 + const char *ext = ".dll"; + //const char *EXT = ".DLL"; +#elif defined (MACOSX) || defined (DARWIN) + const char *ext = ".dylib"; + //const char *EXT = ".DYLIB"; +#else + const char *ext = ".so"; + //const char *EXT = ".SO"; +#endif + + + if (!zap_config_open_file(&cfg, cfg_name)) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "modules")) { + if (!strcasecmp(var, "load")) { + zap_dso_lib_t lib; + int x = 0; + + if (*val == *ZAP_PATH_SEPARATOR) { + snprintf(path, sizeof(path), "%s%s", val, ext); + } else { + snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, val, ext); + } + + if (!(lib = zap_dso_open(path, &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + free(err); + continue; + } + + if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + free(err); + continue; + } + + if (mod->io_load) { + zap_io_interface_t *interface; + + if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + } else { + zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + process_module_config(interface); + zap_mutex_unlock(globals.mutex); + x++; + } + } + + if (mod->sig_load) { + if (mod->sig_load() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + } else { + zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); + x++; + } + } + + if (x) { + char *p; + mod->lib = lib; + zap_set_string(mod->path, path); + if (mod->name[0] == '\0') { + if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { + p = path; + } + zap_set_string(mod->name, p); + } + + hashtable_insert(globals.module_hash, (void *)mod->name, mod); + count++; + } else { + zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); + zap_dso_destroy(&lib); + } + } + } + } + + return count; +} + +zap_status_t zap_unload_modules(void) +{ + zap_hash_iterator_t *i; + zap_dso_lib_t lib; + + for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { + const void *key; + void *val; + + hashtable_this(i, &key, NULL, &val); + + if (key && val) { + zap_module_t *mod = (zap_module_t *) val; + + if (!mod) { + continue; + } + + if (mod->io_unload) { + if (mod->io_unload() == ZAP_SUCCESS) { + zap_log(ZAP_LOG_INFO, "Unloading IO %s\n", mod->name); + } else { + zap_log(ZAP_LOG_ERROR, "Error unloading IO %s\n", mod->name); + } + } + + if (mod->sig_unload) { + if (mod->sig_unload() == ZAP_SUCCESS) { + zap_log(ZAP_LOG_INFO, "Unloading SIG %s\n", mod->name); + } else { + zap_log(ZAP_LOG_ERROR, "Error unloading SIG %s\n", mod->name); + } + } + + + zap_log(ZAP_LOG_INFO, "Unloading %s\n", mod->path); + lib = mod->lib; + zap_dso_destroy(&lib); + + } + } + + return ZAP_SUCCESS; +} + +zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) +{ + zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); + zap_status_t status = ZAP_FAIL; + + if (mod && mod->sig_configure) { + va_list ap; + va_start(ap, sig_cb); + status = mod->sig_configure(span, sig_cb, ap); + va_end(ap); + } + return status; +} + +zap_status_t zap_span_start(zap_span_t *span) +{ + if (span->start) { + return span->start(span); + } + + return ZAP_FAIL; +} + + zap_status_t zap_global_init(void) { int modcount; @@ -2111,50 +2269,17 @@ zap_status_t zap_global_init(void) memset(&globals, 0, sizeof(globals)); time_init(); - zap_isdn_init(); - zap_ss7_boost_init(); + //zap_isdn_init(); + //zap_ss7_boost_init(); memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); -#ifdef ZAP_WANPIPE_SUPPORT - if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { - zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); - process_module_config(interfaces.wanpipe_interface); - zap_mutex_unlock(globals.mutex); - modcount++; - } else { - zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n"); - } -#endif - -#ifdef ZAP_ZT_SUPPORT - if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) { - zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface); - process_module_config(interfaces.zt_interface); - zap_mutex_unlock(globals.mutex); - modcount++; - } else { - zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n"); - } -#endif - -#ifdef ZAP_PIKA_SUPPORT - if (pika_init(&interfaces.pika_interface) == ZAP_SUCCESS) { - zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interfaces.pika_interface->name, interfaces.pika_interface); - process_module_config(interfaces.pika_interface); - zap_mutex_unlock(globals.mutex); - modcount++; - } else { - zap_log(ZAP_LOG_ERROR, "Error initilizing pika.\n"); - } -#endif + modcount = zap_load_modules(); if (!modcount) { zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); @@ -2209,27 +2334,11 @@ zap_status_t zap_global_destroy(void) } } - -#ifdef ZAP_ZT_SUPPORT - if (interfaces.zt_interface) { - zt_destroy(); - } -#endif - -#ifdef ZAP_PIKA_SUPPORT - if (interfaces.pika_interface) { - pika_destroy(); - } -#endif - -#ifdef ZAP_WANPIPE_SUPPORT - if (interfaces.wanpipe_interface) { - wanpipe_destroy(); - } -#endif + zap_unload_modules(); zap_mutex_lock(globals.mutex); hashtable_destroy(globals.interface_hash, 0, 0); + hashtable_destroy(globals.module_hash, 0, 0); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); @@ -2409,7 +2518,6 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t } - /* For Emacs: * Local Variables: * mode:c From bc1ccab19ca52e13eedb49a1ca761acb26ad91cb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 15:58:59 +0000 Subject: [PATCH 0996/1766] dyna won't you blow your horn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@517 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 128 ++++++--- libs/freetdm/conf/modules.conf | 11 + libs/freetdm/configure.ac | 3 + libs/freetdm/mod_openzap/Makefile | 17 +- libs/freetdm/mod_openzap/mod_openzap.c | 46 ++-- libs/freetdm/src/hashtable.c | 62 +++++ libs/freetdm/src/include/hashtable.h | 5 + libs/freetdm/src/include/hashtable_private.h | 8 + libs/freetdm/src/include/openzap.h | 5 + libs/freetdm/src/include/zap_dso.h | 4 +- libs/freetdm/src/include/zap_skel.h | 52 ---- libs/freetdm/src/include/zap_types.h | 34 ++- libs/freetdm/src/include/zap_wanpipe.h | 53 ---- .../ozmod_analog/ozmod_analog.c} | 54 +++- .../ozmod_analog}/zap_analog.h | 5 +- .../ozmod_isdn/ozmod_isdn.c} | 72 ++++-- .../{include => ozmod/ozmod_isdn}/zap_isdn.h | 4 - .../ozmod_pika/ozmod_pika.c} | 15 +- .../{include => ozmod/ozmod_pika}/zap_pika.h | 5 - .../ozmod_skel/ozmod_skel.c} | 40 ++- .../ozmod_ss7_boost/ozmod_ss7_boost.c} | 54 +++- .../ozmod_ss7_boost}/sigboost.h | 0 .../ozmod_ss7_boost}/ss7_boost_client.c | 0 .../ozmod_ss7_boost}/ss7_boost_client.h | 0 .../ozmod_ss7_boost}/zap_ss7_boost.h | 8 - .../ozmod_wanpipe/ozmod_wanpipe.c} | 14 +- .../ozmod_wanpipe}/wanpipe_tdm_api_iface.h | 0 .../{zap_zt.c => ozmod/ozmod_zt/ozmod_zt.c} | 13 +- .../zap_zt.h => ozmod/ozmod_zt/ozmod_zt.h} | 4 - libs/freetdm/src/testanalog.c | 29 ++- libs/freetdm/src/testboost.c | 26 +- libs/freetdm/src/testisdn.c | 33 ++- libs/freetdm/src/zap_dso.c | 12 +- libs/freetdm/src/zap_io.c | 244 +++++++++++++----- 34 files changed, 706 insertions(+), 354 deletions(-) create mode 100644 libs/freetdm/conf/modules.conf delete mode 100644 libs/freetdm/src/include/zap_skel.h delete mode 100644 libs/freetdm/src/include/zap_wanpipe.h rename libs/freetdm/src/{zap_analog.c => ozmod/ozmod_analog/ozmod_analog.c} (95%) rename libs/freetdm/src/{include => ozmod/ozmod_analog}/zap_analog.h (91%) rename libs/freetdm/src/{zap_isdn.c => ozmod/ozmod_isdn/ozmod_isdn.c} (97%) rename libs/freetdm/src/{include => ozmod/ozmod_isdn}/zap_isdn.h (91%) rename libs/freetdm/src/{zap_pika.c => ozmod/ozmod_pika/ozmod_pika.c} (99%) rename libs/freetdm/src/{include => ozmod/ozmod_pika}/zap_pika.h (96%) rename libs/freetdm/src/{zap_skel.c => ozmod/ozmod_skel/ozmod_skel.c} (88%) rename libs/freetdm/src/{zap_ss7_boost.c => ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c} (96%) rename libs/freetdm/src/{include => ozmod/ozmod_ss7_boost}/sigboost.h (100%) rename libs/freetdm/src/{ => ozmod/ozmod_ss7_boost}/ss7_boost_client.c (100%) rename libs/freetdm/src/{include => ozmod/ozmod_ss7_boost}/ss7_boost_client.h (100%) rename libs/freetdm/src/{include => ozmod/ozmod_ss7_boost}/zap_ss7_boost.h (88%) rename libs/freetdm/src/{zap_wanpipe.c => ozmod/ozmod_wanpipe/ozmod_wanpipe.c} (99%) rename libs/freetdm/src/{include => ozmod/ozmod_wanpipe}/wanpipe_tdm_api_iface.h (100%) rename libs/freetdm/src/{zap_zt.c => ozmod/ozmod_zt/ozmod_zt.c} (99%) rename libs/freetdm/src/{include/zap_zt.h => ozmod/ozmod_zt/ozmod_zt.h} (98%) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 6c3bb534e5..2ad180b430 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -35,8 +35,6 @@ SOURCES=\ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ -$(SRC)/zap_isdn.c \ -$(SRC)/zap_analog.c \ $(SRC)/zap_config.c \ $(SRC)/zap_callerid.c \ $(SRC)/fsk.c \ @@ -46,7 +44,14 @@ $(SRC)/libteletone_detect.c \ $(SRC)/libteletone_generate.c \ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ -$(SRC)/zap_dso.c \ +$(SRC)/zap_dso.c + +BOOST_SOURCES=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ +$(SRC)/ozmod/ozmod_ss7_boost/zap_ss7_boost.c + + +ISDN_SOURCES=\ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -66,18 +71,13 @@ $(SRC)/isdn/DMSStateTE.c \ $(SRC)/isdn/5ESSmes.c \ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c \ -$(SRC)/zap_zt.c \ -$(SRC)/zap_wanpipe.c \ -$(SRC)/ss7_boost_client.c \ -$(SRC)/zap_ss7_boost.c +$(SRC)/isdn/Q932mes.c + OBJS=\ $(SRC)/hashtable.o \ $(SRC)/hashtable_itr.o \ $(SRC)/zap_io.o \ -$(SRC)/zap_isdn.o \ -$(SRC)/zap_analog.o \ $(SRC)/zap_config.o \ $(SRC)/zap_callerid.o \ $(SRC)/fsk.o \ @@ -87,7 +87,13 @@ $(SRC)/libteletone_detect.o \ $(SRC)/libteletone_generate.o \ $(SRC)/zap_buffer.o \ $(SRC)/zap_threadmutex.o \ -$(SRC)/zap_dso.o \ +$(SRC)/zap_dso.o + +BOOST_OBJS=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o + + +ISDN_OBJS=\ $(SRC)/isdn/EuroISDNStateNT.o \ $(SRC)/isdn/EuroISDNStateTE.o \ $(SRC)/isdn/mfifo.o \ @@ -107,11 +113,8 @@ $(SRC)/isdn/DMSStateTE.o \ $(SRC)/isdn/5ESSmes.o \ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o \ -$(SRC)/zap_zt.o \ -$(SRC)/zap_wanpipe.o \ -$(SRC)/ss7_boost_client.o \ -$(SRC)/zap_ss7_boost.o +$(SRC)/isdn/Q932mes.o + HEADERS= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ @@ -124,18 +127,14 @@ $(SRC)/include/libteletone.h \ $(SRC)/include/openzap.h \ $(SRC)/include/sangoma_tdm_api.h \ $(SRC)/include/uart.h \ -$(SRC)/include/wanpipe_tdm_api_iface.h \ -$(SRC)/include/zap_analog.h \ $(SRC)/include/zap_buffer.h \ $(SRC)/include/zap_config.h \ -$(SRC)/include/zap_isdn.h \ -$(SRC)/include/zap_skel.h \ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_dso.h \ -$(SRC)/include/zap_types.h \ -$(SRC)/include/zap_wanpipe.h \ -$(SRC)/include/zap_ss7_boost.h \ -$(SRC)/include/zap_zt.h \ +$(SRC)/include/zap_types.h + + +ISDN_HEADERS=\ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ $(SRC)/isdn/include/DMS.h \ @@ -145,30 +144,33 @@ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h + PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -MYLIB=libopenzap.a +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost +CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" +MYLIB=libopenzap.so LIBPRIA=libpri.a LIBPRI=./libpri TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +PREFIX=@prefix@ PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) -ifneq ($(PIKA_DIR),) -ifneq ($(PIKA_LIB),) -OBJS += $(SRC)/zap_pika.o -CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -ADD_OBJS = $(PIKA_LIB) -endif -endif +#ifneq ($(PIKA_DIR),) +#ifneq ($(PIKA_LIB),) +#OBJS += $(SRC)/zap_pika.o +#CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) +#ADD_OBJS = $(PIKA_LIB) +#endif +#endif -all: $(MYLIB) +all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - ranlib $(MYLIB) + #ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) + #ranlib $(MYLIB) + $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl testapp: $(SRC)/testapp.c $(MYLIB) $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread @@ -226,6 +228,54 @@ mod_openzap-install: mod_openzap mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi -clean: mod_openzap-clean - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog +clean: + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.so src/ozmod/*/*.dylib src/ozmod/*/*.dll @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + +install: all + @mkdir -p $(DESTDIR)$(PREFIX) + @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf) + @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) + @mkdir -p $(DESTDIR)$(PREFIX)/lib + @[ ! -f $(MYLIB) ] || cp -f $(MYLIB) $(DESTDIR)$(PREFIX)/lib + @mkdir -p $(DESTDIR)$(PREFIX)/mod + @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod + @cp -f src/ozmod/*/*.so $(DESTDIR)$(PREFIX)/mod + @echo OpenZAP Installed + +uninstall: + @rm -fr $(DESTDIR)$(PREFIX) + +$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib +skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so + + +$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so + +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so + +$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: + $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib + +pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so + +$(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c + +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so + +$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) + $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so + +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so + + diff --git a/libs/freetdm/conf/modules.conf b/libs/freetdm/conf/modules.conf new file mode 100644 index 0000000000..28d8d0b6eb --- /dev/null +++ b/libs/freetdm/conf/modules.conf @@ -0,0 +1,11 @@ +[modules] +;load => ozmod_skel +load => ozmod_zt +load => ozmod_wanpipe +;load => ozmod_pika +load => ozmod_isdn +load => ozmod_analog +;load => ozmod_ss7_boost + + + diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 480527be18..76ee2c8df0 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -10,6 +10,9 @@ AC_PROG_CC AC_PROG_MAKE_SET AC_PROG_RANLIB + +AC_PREFIX_DEFAULT(/usr/local/openzap) + # Check for com;iler type AC_DEFUN([AX_COMPILER_VENDOR], [ diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index 1552a37c45..b380a8103a 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -1,14 +1,21 @@ BASE=../../.. OZ_DIR=.. VERBOSE=1 -OZA=$(OZ_DIR)/libopenzap.a +OZSO=$(OZ_DIR)/libopenzap.so LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include -LOCAL_LIBADD=$(OZA) +LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap include $(BASE)/build/modmake.rules -local_depend: $(OZA) +local_depend: $(OZSO) -$(OZA): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) ZAP_MODS="wanpipe zt" ZAP_CFLAGS="$(ALL_CXXFLAGS)" +$(OZSO): $(OZ_DIR)/.update + cd $(OZ_DIR) && $(MAKE) ZAP_CFLAGS="$(ALL_CXXFLAGS)" + +local_install: + cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)" + [ ! -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs + +local_clean: + cd $(OZ_DIR) && $(MAKE) clean diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9c0af7659f..ae9133bf1d 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -31,9 +31,6 @@ */ #include #include "openzap.h" -#include "zap_analog.h" -#include "zap_isdn.h" -#include "zap_ss7_boost.h" #ifndef __FUNCTION__ #define __FUNCTION__ __SWITCH_FUNC__ @@ -1562,7 +1559,11 @@ static switch_status_t load_config(void) continue; } - if (zap_analog_configure_span(span, tonegroup, to, max, on_analog_signal) != ZAP_SUCCESS) { + if (zap_configure_span("analog", span, on_analog_signal, + "tonemap", tonegroup, + "digit_timeout", &to, + "max_dialstr", &max + ) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } @@ -1584,7 +1585,7 @@ static switch_status_t load_config(void) switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_analog_start(span); + zap_span_start(span); } } @@ -1593,12 +1594,14 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr_soft(myspan, "id"); char *context = "default"; char *dialplan = "XML"; - Q921NetUser_t mode = Q931_TE; - Q931Dialect_t dialect = Q931_Dialect_National; + //Q921NetUser_t mode = Q931_TE; + //Q931Dialect_t dialect = Q931_Dialect_National; + char *mode = NULL; + char *dialect = NULL; uint32_t span_id = 0; zap_span_t *span = NULL; char *tonegroup = NULL; - zap_isdn_opts_t opts = ZAP_ISDN_OPT_NONE; + uint32_t opts = 0; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1607,16 +1610,13 @@ static switch_status_t load_config(void) if (!strcasecmp(var, "tonegroup")) { tonegroup = val; } else if (!strcasecmp(var, "mode")) { - mode = strcasecmp(val, "net") ? Q931_TE : Q931_NT; + mode = val; } else if (!strcasecmp(var, "dialect")) { - dialect = q931_str2Q931Dialect_type(val); - if (dialect == Q931_Dialect_Count) { - dialect = Q931_Dialect_National; - } + dialect = val; } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { - opts |= ZAP_ISDN_OPT_SUGGEST_CHANNEL; + opts |= 1; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } @@ -1637,8 +1637,11 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } - - if (zap_isdn_configure_span(span, mode, dialect, opts, on_clear_channel_signal) != ZAP_SUCCESS) { + + if (zap_configure_span("isdn", span, on_clear_channel_signal, + "mode", mode, + "dialect", dialect + ) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -1648,7 +1651,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_isdn_start(span); + zap_span_start(span); } } @@ -1702,7 +1705,12 @@ static switch_status_t load_config(void) continue; } - if (zap_ss7_boost_configure_span(span, local_ip, local_port, remote_ip, remote_port, on_clear_channel_signal) != ZAP_SUCCESS) { + if (zap_configure_span("ss7_boost", span, on_clear_channel_signal, + "local_ip", local_ip, + "local_port", &local_port, + "remote_ip", remote_ip, + "remote_port", &remote_port + ) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } @@ -1711,7 +1719,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); - zap_ss7_boost_start(span); + zap_span_start(span); switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); } } diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 5cc2bb0c40..8e252339a2 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -230,6 +230,68 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values) free(h); } +struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) +{ + + if (i->e) { + if ((i->e = i->e->next)) { + return i; + } else { + i->pos++; + } + } + + while(i->pos < i->h->tablelength && !i->h->table[i->pos]) { + i->pos++; + } + + if (i->pos >= i->h->tablelength) { + return NULL; + } + + if ((i->e = i->h->table[i->pos])) { + return i; + } + + return NULL; +} + +struct hashtable_iterator *hashtable_first(struct hashtable *h) +{ + h->iterator.pos = 0; + h->iterator.e = NULL; + h->iterator.h = h; + return hashtable_next(&h->iterator); +} + + + +void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) +{ + if (i->e) { + if (key) { + *key = i->e->k; + } + if (klen) { + *klen = strlen(i->e->k); + } + if (val) { + *val = i->e->v; + } + } else { + if (key) { + *key = NULL; + } + if (klen) { + *klen = 0; + } + if (val) { + *val = NULL; + } + } +} + + /* * Copyright (c) 2002, Christopher Clark * All rights reserved. diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 4c3c48f4bf..243441c1d4 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -9,6 +9,7 @@ #endif struct hashtable; +struct hashtable_iterator; /* Example of use: * @@ -168,6 +169,10 @@ hashtable_count(struct hashtable *h); void hashtable_destroy(struct hashtable *h, int free_keys, int free_values); +struct hashtable_iterator *hashtable_first(struct hashtable *h); +struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i); +void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); + #endif /* __HASHTABLE_CWC22_H__ */ /* diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index ede652c654..81197e6cb3 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -7,6 +7,7 @@ /*****************************************************************************/ + struct entry { void *k, *v; @@ -14,6 +15,12 @@ struct entry struct entry *next; }; +struct hashtable_iterator { + int pos; + struct entry *e; + struct hashtable *h; +}; + struct hashtable { unsigned int tablelength; struct entry **table; @@ -22,6 +29,7 @@ struct hashtable { unsigned int primeindex; unsigned int (*hashfn) (void *k); int (*eqfn) (void *k1, void *k2); + struct hashtable_iterator iterator; }; /*****************************************************************************/ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 26b050181e..ff13d47386 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -479,6 +479,7 @@ struct zap_span { zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; + zap_span_start_t start; void *mod_data; char *type; int suggest_chan_id; @@ -579,6 +580,10 @@ uint32_t zap_hash_hashfromstring(void *ky); uint32_t zap_running(void); zap_status_t zap_channel_complete_state(zap_channel_t *zchan); zap_status_t zap_channel_init(zap_channel_t *zchan); +int zap_load_modules(void); +zap_status_t zap_unload_modules(void); +zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); +zap_status_t zap_span_start(zap_span_t *span); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/include/zap_dso.h b/libs/freetdm/src/include/zap_dso.h index 2c7be2b4be..bf51f92b18 100644 --- a/libs/freetdm/src/include/zap_dso.h +++ b/libs/freetdm/src/include/zap_dso.h @@ -25,8 +25,8 @@ 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, const char **err); -zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err); +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 diff --git a/libs/freetdm/src/include/zap_skel.h b/libs/freetdm/src/include/zap_skel.h deleted file mode 100644 index a8a245837f..0000000000 --- a/libs/freetdm/src/include/zap_skel.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ZAP_SKEL_H -#define ZAP_SKEL_H -#include "openzap.h" - -zap_status_t skel_init(zap_software_interface_t **zint); -zap_status_t skel_destroy(void); - -#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 expandtab: - */ diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 7c092e7f70..9c14686f8c 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -52,6 +52,7 @@ typedef int zap_filehandle_t; #include #include #include +#include typedef int zap_socket_t; typedef ssize_t zap_ssize_t; typedef int zap_filehandle_t; @@ -383,6 +384,7 @@ 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; #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) @@ -402,6 +404,11 @@ typedef struct zap_caller_data zap_caller_data_t; #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) 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 ; @@ -421,6 +428,11 @@ 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 ; #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 @@ -440,6 +452,24 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_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 + +#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__ @@ -468,13 +498,13 @@ 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 zap_io_interface zap_io_interface_t; typedef struct hashtable zap_hash_t; -typedef struct hashtable_itr zap_hash_itr_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 enum { ZAP_CAUSE_NONE = 0, diff --git a/libs/freetdm/src/include/zap_wanpipe.h b/libs/freetdm/src/include/zap_wanpipe.h deleted file mode 100644 index 0b2f4a9c48..0000000000 --- a/libs/freetdm/src/include/zap_wanpipe.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ZAP_WANPIPE_H -#define ZAP_WANPIPE_H -#include "openzap.h" - -zap_status_t wanpipe_init(zap_io_interface_t **zint); -zap_status_t wanpipe_destroy(void); - -#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 expandtab: - */ - diff --git a/libs/freetdm/src/zap_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c similarity index 95% rename from libs/freetdm/src/zap_analog.c rename to libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 64836c7436..fe438c2244 100644 --- a/libs/freetdm/src/zap_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -70,9 +70,24 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) return ZAP_SUCCESS; } -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) + +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); +} + +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; + char *tonemap = "us"; + uint32_t digit_timeout = 10; + uint32_t max_dialstr = 11; + char *var, *val; + int *intval; + assert(sig_cb != NULL); if (span->signal_type) { @@ -92,6 +107,27 @@ zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); + + 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; + } + } + + span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; analog_data->sig_cb = sig_cb; @@ -793,13 +829,21 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) } -zap_status_t zap_analog_start(zap_span_t *span) +static ZIO_SIG_LOAD_FUNCTION(zap_analog_init) { - 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); + return ZAP_SUCCESS; } +zap_module_t zap_module = { + "analog", + NULL, + NULL, + zap_analog_init, + zap_analog_configure_span, + NULL +}; + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/include/zap_analog.h b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h similarity index 91% rename from libs/freetdm/src/include/zap_analog.h rename to libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h index 5322463577..2d90910244 100644 --- a/libs/freetdm/src/include/zap_analog.h +++ b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h @@ -39,12 +39,9 @@ typedef enum { ZAP_ANALOG_RUNNING = (1 << 0) } zap_analog_flag_t; - +static void *zap_analog_run(zap_thread_t *me, void *obj); typedef struct zap_analog_data zap_analog_data_t; -zap_status_t zap_analog_start(zap_span_t *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); - #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c similarity index 97% rename from libs/freetdm/src/zap_isdn.c rename to libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 912a14fb0d..78792ba72c 100644 --- a/libs/freetdm/src/zap_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -663,7 +663,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_sigmsg_t sig; zap_status_t status; - zap_log(ZAP_LOG_ERROR, "%d:%d STATE [%s]\n", + 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)); @@ -1134,7 +1134,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) return NULL; } -zap_status_t zap_isdn_init(void) +static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) { Q931Initialize(); @@ -1144,13 +1144,6 @@ zap_status_t zap_isdn_init(void) return ZAP_SUCCESS; } -zap_status_t zap_isdn_start(zap_span_t *span) -{ - zap_isdn_data_t *isdn_data = span->signal_data; - zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); - return zap_thread_create_detached(zap_isdn_run, span); -} - static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3INT mlen) { int offset = 4; @@ -1317,11 +1310,24 @@ static zap_state_map_t isdn_state_map = { } }; -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb) +static zap_status_t zap_isdn_start(zap_span_t *span) +{ + zap_isdn_data_t *isdn_data = span->signal_data; + zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); + return zap_thread_create_detached(zap_isdn_run, span); +} + + + +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; + char *var, *val; + Q931Dialect_t dialect = Q931_Dialect_National; + uint32_t opts = 0; + if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; @@ -1352,21 +1358,46 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D 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) { + dialect = Q931_Dialect_National; + } + } else if (!strcasecmp(var, "opts")) { + int *optp; + if (!(optp = va_arg(ap, int *))) { + break; + } + opts = isdn_data->opts = *optp; + } + } + + span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; - isdn_data->mode = mode; Q921_InitTrunk(&isdn_data->q921, 0, 0, - mode, + isdn_data->mode, span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP, 0, zap_isdn_921_21, @@ -1379,7 +1410,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D Q931Api_InitTrunk(&isdn_data->q931, dialect, - mode, + isdn_data->mode, span->trunk_type, zap_isdn_931_34, (Q931Tx32CB_t)q931_rx_32, @@ -1397,7 +1428,7 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - isdn_data->opts = opts; + if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; @@ -1408,6 +1439,17 @@ zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931D return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "isdn", + NULL, + NULL, + zap_isdn_init, + zap_isdn_configure_span, + NULL +}; + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/include/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h similarity index 91% rename from libs/freetdm/src/include/zap_isdn.h rename to libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index e18a51ab0a..86a3f40155 100644 --- a/libs/freetdm/src/include/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -64,10 +64,6 @@ struct zap_isdn_data { typedef struct zap_isdn_data zap_isdn_data_t; -zap_status_t zap_isdn_start(zap_span_t *span); -zap_status_t zap_isdn_init(void); -zap_status_t zap_isdn_configure_span(zap_span_t *span, Q921NetUser_t mode, Q931Dialect_t dialect, zap_isdn_opts_t opts, zio_signal_cb_t sig_cb); - #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c similarity index 99% rename from libs/freetdm/src/zap_pika.c rename to libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index ffe79e397c..e3121309ec 100644 --- a/libs/freetdm/src/zap_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -1179,7 +1179,7 @@ static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) static zap_io_interface_t pika_interface; -zap_status_t pika_init(zap_io_interface_t **zint) +static ZIO_IO_LOAD_FUNCTION(pika_init) { PK_STATUS status; @@ -1189,7 +1189,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) PKH_TLogMasks m; TPikaHandle tmpHandle; - assert(zint != NULL); + assert(zio != NULL); memset(&pika_interface, 0, sizeof(pika_interface)); memset(&globals, 0, sizeof(globals)); globals.general_config.region = PKH_TRUNK_NA; @@ -1271,7 +1271,7 @@ zap_status_t pika_init(zap_io_interface_t **zint) pika_interface.channel_destroy = pika_channel_destroy; pika_interface.span_destroy = pika_span_destroy; pika_interface.get_alarms = pika_get_alarms; - *zint = &pika_interface; + *zio = &pika_interface; zap_log(ZAP_LOG_INFO, "Dumping Default configs:\n"); @@ -1313,7 +1313,8 @@ zap_status_t pika_init(zap_io_interface_t **zint) return ZAP_SUCCESS; } -zap_status_t pika_destroy(void) + +static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) { uint32_t x; PK_STATUS status; @@ -1339,6 +1340,12 @@ zap_status_t pika_destroy(void) return ZAP_SUCCESS; } +zap_module_t zap_module = { + "pika", + pika_init, + pika_destroy, +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/include/zap_pika.h b/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h similarity index 96% rename from libs/freetdm/src/include/zap_pika.h rename to libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h index a98c08cbe6..c8401c6aa1 100644 --- a/libs/freetdm/src/include/zap_pika.h +++ b/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h @@ -94,11 +94,6 @@ typedef enum { #define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW" ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) - -/* Openzap PIKA hardware interface functions */ -zap_status_t pika_init(zap_io_interface_t **zint); -zap_status_t pika_destroy(void); - #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_skel.c b/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c similarity index 88% rename from libs/freetdm/src/zap_skel.c rename to libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c index 575550979a..aa468a356f 100644 --- a/libs/freetdm/src/zap_skel.c +++ b/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c @@ -33,52 +33,40 @@ #include "openzap.h" -#include "zap_skel.h" +//#include "zap_skel.h" static ZIO_CONFIGURE_FUNCTION(skel_configure) { - ZIO_CONFIGURE_MUZZLE; return ZAP_FAIL; } static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) { - + return ZAP_FAIL; } static ZIO_OPEN_FUNCTION(skel_open) { - ZIO_OPEN_MUZZLE; return ZAP_FAIL; } static ZIO_CLOSE_FUNCTION(skel_close) { - ZIO_CLOSE_MUZZLE; - return ZAP_FAIL; -} - -static ZIO_SET_INTERVAL_FUNCTION(skel_set_interval) -{ - ZIO_SET_INTERVAL_MUZZLE; return ZAP_FAIL; } static ZIO_WAIT_FUNCTION(skel_wait) { - ZIO_WAIT_MUZZLE; return ZAP_FAIL; } static ZIO_READ_FUNCTION(skel_read) { - ZIO_READ_MUZZLE; return ZAP_FAIL; } static ZIO_WRITE_FUNCTION(skel_write) { - ZIO_WRITE_MUZZLE; return ZAP_FAIL; } @@ -102,21 +90,21 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) return ZAP_FAIL; } -static ZIO_CHANNEL_DESTROY_FUNCTION(skel_span_destroy) +static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy) { return ZAP_FAIL; } static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) { - return zap_fail; + return ZAP_FAIL; } static zap_io_interface_t skel_interface; -zap_status_t skel_init(zap_io_interface_t **zint) +static ZIO_IO_LOAD_FUNCTION(skel_init) { - assert(zint != NULL); + assert(zio != NULL); memset(&skel_interface, 0, sizeof(skel_interface)); skel_interface.name = "skel"; @@ -133,16 +121,24 @@ zap_status_t skel_init(zap_io_interface_t **zint) skel_interface.channel_destroy = skel_channel_destroy; skel_interface.span_destroy = skel_span_destroy; skel_interface.get_alarms = skel_get_alarms; - *zint = &skel_interface; + *zio = &skel_interface; - return ZAP_FAIL; + return ZAP_SUCCESS; } -zap_status_t skel_destroy(void) +static ZIO_IO_UNLOAD_FUNCTION(skel_destroy) { - return ZAP_FAIL; + return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "skel", + skel_init, + skel_destroy, +}; + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/zap_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c similarity index 96% rename from libs/freetdm/src/zap_ss7_boost.c rename to libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 4a26054029..64cad3c02d 100644 --- a/libs/freetdm/src/zap_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -974,15 +974,15 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) return NULL; } -zap_status_t zap_ss7_boost_init(void) +static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) { zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); - + return ZAP_SUCCESS; } -zap_status_t zap_ss7_boost_start(zap_span_t *span) +static zap_status_t zap_ss7_boost_start(zap_span_t *span) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); @@ -1088,13 +1088,39 @@ static zap_state_map_t boost_state_map = { } }; -zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, - const char *local_ip, int local_port, - const char *remote_ip, int remote_port, - zio_signal_cb_t sig_cb) +static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; - + char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; + int local_port = 5300, remote_port = 5300; + 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; + } + } + + if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { return ZAP_FAIL; } @@ -1108,7 +1134,7 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); ss7_boost_data->mcon.cfg.remote_port = remote_port; ss7_boost_data->signal_cb = sig_cb; - + span->start = zap_ss7_boost_start; span->signal_data = ss7_boost_data; span->signal_type = ZAP_SIGTYPE_SS7BOOST; span->outgoing_call = ss7_boost_outgoing_call; @@ -1119,6 +1145,16 @@ zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "analog", + NULL, + NULL, + zap_ss7_boost_init, + zap_ss7_boost_configure_span, + NULL +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/include/sigboost.h b/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h similarity index 100% rename from libs/freetdm/src/include/sigboost.h rename to libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h diff --git a/libs/freetdm/src/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c similarity index 100% rename from libs/freetdm/src/ss7_boost_client.c rename to libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c diff --git a/libs/freetdm/src/include/ss7_boost_client.h b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h similarity index 100% rename from libs/freetdm/src/include/ss7_boost_client.h rename to libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h diff --git a/libs/freetdm/src/include/zap_ss7_boost.h b/libs/freetdm/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h similarity index 88% rename from libs/freetdm/src/include/zap_ss7_boost.h rename to libs/freetdm/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h index c5496b8aed..b3f3e416bf 100644 --- a/libs/freetdm/src/include/zap_ss7_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h @@ -48,14 +48,6 @@ typedef struct zap_ss7_boost_data { uint32_t flags; } zap_ss7_boost_data_t; -zap_status_t zap_ss7_boost_start(zap_span_t *span); -zap_status_t zap_ss7_boost_init(void); -zap_status_t zap_ss7_boost_configure_span(zap_span_t *span, - const char *local_ip, int local_port, - const char *remote_ip, int remote_port, - zio_signal_cb_t sig_cb); - - #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c similarity index 99% rename from libs/freetdm/src/zap_wanpipe.c rename to libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index bbeb191b4a..19d74cdb19 100644 --- a/libs/freetdm/src/zap_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -36,10 +36,9 @@ #include #endif #include "openzap.h" -#include "zap_wanpipe.h" #include #include -#include +#include "wanpipe_tdm_api_iface.h" typedef enum { WP_RINGING = (1 << 0) @@ -935,7 +934,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) return ZAP_SUCCESS; } -zap_status_t wanpipe_init(zap_io_interface_t **zio) +static ZIO_IO_LOAD_FUNCTION(wanpipe_init) { assert(zio != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); @@ -964,12 +963,19 @@ zap_status_t wanpipe_init(zap_io_interface_t **zio) return ZAP_SUCCESS; } -zap_status_t wanpipe_destroy(void) +static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) { memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "wanpipe", + wanpipe_init, + wanpipe_destroy, +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/include/wanpipe_tdm_api_iface.h b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h similarity index 100% rename from libs/freetdm/src/include/wanpipe_tdm_api_iface.h rename to libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h diff --git a/libs/freetdm/src/zap_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c similarity index 99% rename from libs/freetdm/src/zap_zt.c rename to libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 38c55ffae5..4b271ed6f5 100644 --- a/libs/freetdm/src/zap_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -33,7 +33,7 @@ #include "openzap.h" -#include "zap_zt.h" +#include "ozmod_zt.h" static struct { @@ -737,7 +737,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) static zap_io_interface_t zt_interface; -zap_status_t zt_init(zap_io_interface_t **zio) +static ZIO_IO_LOAD_FUNCTION(zt_init) { assert(zio != NULL); memset(&zt_interface, 0, sizeof(zt_interface)); @@ -772,13 +772,20 @@ zap_status_t zt_init(zap_io_interface_t **zio) return ZAP_SUCCESS; } -zap_status_t zt_destroy(void) +static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) { close(CONTROL_FD); memset(&zt_interface, 0, sizeof(zt_interface)); return ZAP_SUCCESS; } + +zap_module_t zap_module = { + "zt", + zt_init, + zt_destroy, +}; + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/include/zap_zt.h b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h similarity index 98% rename from libs/freetdm/src/include/zap_zt.h rename to libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h index 0e16d29398..c3e2067585 100644 --- a/libs/freetdm/src/include/zap_zt.h +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h @@ -280,10 +280,6 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #define ZT_ECHOTRAIN _IOW (ZT_CODE, 50, int) /* Control Echo Trainer */ -/* Openzap ZT hardware interface functions */ -zap_status_t zt_init(zap_io_interface_t **zint); -zap_status_t zt_destroy(void); - #endif /* For Emacs: diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 1ad530db89..813605decc 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -1,5 +1,4 @@ #include "openzap.h" -#include "zap_analog.h" static void *test_call(zap_thread_t *me, void *obj) @@ -59,11 +58,20 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) return ZAP_SUCCESS; } +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; int span_id; - zap_analog_data_t *analog_data; + int digit_timeout = 2000; + int max_dialstr = 11; if (argc < 2) { printf("usage %s \n", argv[0]); @@ -86,19 +94,22 @@ int main(int argc, char *argv[]) goto done; } - if (zap_analog_configure_span(span, "us", 2000, 11, on_signal) != ZAP_SUCCESS) { + + if (zap_configure_span("analog", span, on_signal, + "tonemap", "te", + "digit_timeout", &digit_timeout, + "max_dialstr", &max_dialstr + ) == ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); goto done; } - analog_data = span->signal_data; - zap_analog_start(span); - - while(zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { + zap_span_start(span); + + while(zap_running() && R) { zap_sleep(1 * 1000); } - - done: +done: zap_global_destroy(); diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index 4fb9ee12ba..c27636efab 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -1,15 +1,24 @@ #include "openzap.h" -#include "zap_ss7_boost.h" 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_ss7_boost_data_t *data; + int local_port, remote_port; + + local_port = remote_port = 53000; zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); @@ -30,16 +39,19 @@ int main(int argc, char *argv[]) goto done; } - - if (zap_ss7_boost_configure_span(span, "127.0.0.65", 53000, "127.0.0.66", 53000, on_signal) == ZAP_SUCCESS) { - data = span->signal_data; - zap_ss7_boost_start(span); + 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 + ) == ZAP_SUCCESS) { + zap_span_start(span); } else { fprintf(stderr, "Error starting SS7_BOOST\n"); goto done; } - while(zap_test_flag(data, ZAP_SS7_BOOST_RUNNING)) { + while(zap_running() && R) { zap_sleep(1 * 1000); } diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 88cc113717..29bf4c952b 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -1,16 +1,24 @@ #include "openzap.h" -#include "zap_isdn.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_isdn_data_t *data; - + zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); if (argc < 2) { @@ -31,15 +39,30 @@ int main(int argc, char *argv[]) } +#if 1 + + if (zap_configure_span("isdn", span, on_signal, + "mode", "te", + "dialect", "national" + ) == ZAP_SUCCESS) { + zap_span_start(span); + } else { + fprintf(stderr, "Error starting ISDN D-Channel\n"); + goto done; + } +#else if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) { - data = span->signal_data; zap_isdn_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } - while(zap_test_flag(data, ZAP_ISDN_RUNNING)) { +#endif + + signal(SIGINT, handle_SIGINT); + R = 1; + while(R) { zap_sleep(1 * 1000); } diff --git a/libs/freetdm/src/zap_dso.c b/libs/freetdm/src/zap_dso.c index aceaa5f5e5..07c25f29fd 100644 --- a/libs/freetdm/src/zap_dso.c +++ b/libs/freetdm/src/zap_dso.c @@ -34,13 +34,13 @@ #include void zap_dso_destroy(zap_dso_lib_t *lib) { - if (lib) { - dlclose(lib); - lib = NULL; + if (lib && *lib) { + dlclose(*lib); + *lib = NULL; } } -zap_dso_lib_t zap_dso_open(const char *path, const char **err) { +zap_dso_lib_t zap_dso_open(const char *path, char **err) { void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (lib == NULL) { *err = strdup(dlerror()); @@ -48,8 +48,8 @@ zap_dso_lib_t zap_dso_open(const char *path, const char **err) { return lib; } -zap_func_ptr_t zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, const char **err) { - zap_dso_lib_t func = (zap_dso_lib_t)dlsym(lib, sym); +void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { + void *func = dlsym(lib, sym); if (!func) { *err = strdup(dlerror()); } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2c24cc5d85..7eb6bda296 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -32,22 +32,14 @@ */ #ifndef WIN32 -#define ZAP_ZT_SUPPORT -#define ZAP_WANPIPE_SUPPORT #endif #include "openzap.h" -#include "zap_isdn.h" -#include "zap_ss7_boost.h" +//#include "zap_isdn.h" +//#include "zap_ss7_boost.h" #include #ifdef WIN32 #include #endif -#ifdef ZAP_WANPIPE_SUPPORT -#include "zap_wanpipe.h" -#endif -#ifdef ZAP_ZT_SUPPORT -#include "zap_zt.h" -#endif #ifdef ZAP_PIKA_SUPPORT #include "zap_pika.h" #endif @@ -83,6 +75,7 @@ zap_time_t zap_current_time_in_ms(void) static struct { zap_hash_t *interface_hash; + zap_hash_t *module_hash; zap_mutex_t *mutex; struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; uint32_t span_index; @@ -1929,8 +1922,6 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data } static struct { - zap_io_interface_t *wanpipe_interface; - zap_io_interface_t *zt_interface; zap_io_interface_t *pika_interface; } interfaces; @@ -2104,6 +2095,173 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } +int zap_load_modules(void) +{ + char cfg_name[] = "modules.conf"; + char path[128] = ""; + zap_config_t cfg; + char *err; + char *var, *val; + zap_module_t *mod; + int count = 0; + +#ifdef WIN32 + const char *ext = ".dll"; + //const char *EXT = ".DLL"; +#elif defined (MACOSX) || defined (DARWIN) + const char *ext = ".dylib"; + //const char *EXT = ".DYLIB"; +#else + const char *ext = ".so"; + //const char *EXT = ".SO"; +#endif + + + if (!zap_config_open_file(&cfg, cfg_name)) { + return ZAP_FAIL; + } + + while (zap_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "modules")) { + if (!strcasecmp(var, "load")) { + zap_dso_lib_t lib; + int x = 0; + + if (*val == *ZAP_PATH_SEPARATOR) { + snprintf(path, sizeof(path), "%s%s", val, ext); + } else { + snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, val, ext); + } + + if (!(lib = zap_dso_open(path, &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + free(err); + continue; + } + + if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + free(err); + continue; + } + + if (mod->io_load) { + zap_io_interface_t *interface; + + if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + } else { + zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); + zap_mutex_lock(globals.mutex); + hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + process_module_config(interface); + zap_mutex_unlock(globals.mutex); + x++; + } + } + + if (mod->sig_load) { + if (mod->sig_load() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + } else { + zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); + x++; + } + } + + if (x) { + char *p; + mod->lib = lib; + zap_set_string(mod->path, path); + if (mod->name[0] == '\0') { + if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { + p = path; + } + zap_set_string(mod->name, p); + } + + hashtable_insert(globals.module_hash, (void *)mod->name, mod); + count++; + } else { + zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); + zap_dso_destroy(&lib); + } + } + } + } + + return count; +} + +zap_status_t zap_unload_modules(void) +{ + zap_hash_iterator_t *i; + zap_dso_lib_t lib; + + for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { + const void *key; + void *val; + + hashtable_this(i, &key, NULL, &val); + + if (key && val) { + zap_module_t *mod = (zap_module_t *) val; + + if (!mod) { + continue; + } + + if (mod->io_unload) { + if (mod->io_unload() == ZAP_SUCCESS) { + zap_log(ZAP_LOG_INFO, "Unloading IO %s\n", mod->name); + } else { + zap_log(ZAP_LOG_ERROR, "Error unloading IO %s\n", mod->name); + } + } + + if (mod->sig_unload) { + if (mod->sig_unload() == ZAP_SUCCESS) { + zap_log(ZAP_LOG_INFO, "Unloading SIG %s\n", mod->name); + } else { + zap_log(ZAP_LOG_ERROR, "Error unloading SIG %s\n", mod->name); + } + } + + + zap_log(ZAP_LOG_INFO, "Unloading %s\n", mod->path); + lib = mod->lib; + zap_dso_destroy(&lib); + + } + } + + return ZAP_SUCCESS; +} + +zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) +{ + zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); + zap_status_t status = ZAP_FAIL; + + if (mod && mod->sig_configure) { + va_list ap; + va_start(ap, sig_cb); + status = mod->sig_configure(span, sig_cb, ap); + va_end(ap); + } + return status; +} + +zap_status_t zap_span_start(zap_span_t *span) +{ + if (span->start) { + return span->start(span); + } + + return ZAP_FAIL; +} + + zap_status_t zap_global_init(void) { int modcount; @@ -2111,50 +2269,17 @@ zap_status_t zap_global_init(void) memset(&globals, 0, sizeof(globals)); time_init(); - zap_isdn_init(); - zap_ss7_boost_init(); + //zap_isdn_init(); + //zap_ss7_boost_init(); memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); -#ifdef ZAP_WANPIPE_SUPPORT - if (wanpipe_init(&interfaces.wanpipe_interface) == ZAP_SUCCESS) { - zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interfaces.wanpipe_interface->name, interfaces.wanpipe_interface); - process_module_config(interfaces.wanpipe_interface); - zap_mutex_unlock(globals.mutex); - modcount++; - } else { - zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n"); - } -#endif - -#ifdef ZAP_ZT_SUPPORT - if (zt_init(&interfaces.zt_interface) == ZAP_SUCCESS) { - zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interfaces.zt_interface->name, interfaces.zt_interface); - process_module_config(interfaces.zt_interface); - zap_mutex_unlock(globals.mutex); - modcount++; - } else { - zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n"); - } -#endif - -#ifdef ZAP_PIKA_SUPPORT - if (pika_init(&interfaces.pika_interface) == ZAP_SUCCESS) { - zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interfaces.pika_interface->name, interfaces.pika_interface); - process_module_config(interfaces.pika_interface); - zap_mutex_unlock(globals.mutex); - modcount++; - } else { - zap_log(ZAP_LOG_ERROR, "Error initilizing pika.\n"); - } -#endif + modcount = zap_load_modules(); if (!modcount) { zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); @@ -2209,27 +2334,11 @@ zap_status_t zap_global_destroy(void) } } - -#ifdef ZAP_ZT_SUPPORT - if (interfaces.zt_interface) { - zt_destroy(); - } -#endif - -#ifdef ZAP_PIKA_SUPPORT - if (interfaces.pika_interface) { - pika_destroy(); - } -#endif - -#ifdef ZAP_WANPIPE_SUPPORT - if (interfaces.wanpipe_interface) { - wanpipe_destroy(); - } -#endif + zap_unload_modules(); zap_mutex_lock(globals.mutex); hashtable_destroy(globals.interface_hash, 0, 0); + hashtable_destroy(globals.module_hash, 0, 0); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); @@ -2409,7 +2518,6 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t } - /* For Emacs: * Local Variables: * mode:c From d165e41e9c8982a70e4dbfc81454dd2e36859ea8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:20:07 +0000 Subject: [PATCH 0997/1766] patch from Michael Collins, 5ess does not use display IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@518 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/5ESSStateTE.c | 2 +- libs/openzap/src/isdn/5ESSmes.c | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/openzap/src/isdn/5ESSStateTE.c b/libs/openzap/src/isdn/5ESSStateTE.c index a9654ce723..13a080cadc 100644 --- a/libs/openzap/src/isdn/5ESSStateTE.c +++ b/libs/openzap/src/isdn/5ESSStateTE.c @@ -73,7 +73,7 @@ void ATT5ESSCreateTE(L3UCHAR i) 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, Q931Umes_Setup, Q931Pmes_Setup); + 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); diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c index da47f7ac5b..fc8d4b9fbb 100644 --- a/libs/openzap/src/isdn/5ESSmes.c +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -85,7 +85,6 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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: @@ -194,11 +193,6 @@ L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I 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) From ec4e39ef9842726fc2109356824c045d138203c3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:20:07 +0000 Subject: [PATCH 0998/1766] patch from Michael Collins, 5ess does not use display IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@518 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/5ESSStateTE.c | 2 +- libs/freetdm/src/isdn/5ESSmes.c | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/freetdm/src/isdn/5ESSStateTE.c b/libs/freetdm/src/isdn/5ESSStateTE.c index a9654ce723..13a080cadc 100644 --- a/libs/freetdm/src/isdn/5ESSStateTE.c +++ b/libs/freetdm/src/isdn/5ESSStateTE.c @@ -73,7 +73,7 @@ void ATT5ESSCreateTE(L3UCHAR i) 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, Q931Umes_Setup, Q931Pmes_Setup); + 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); diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c index da47f7ac5b..fc8d4b9fbb 100644 --- a/libs/freetdm/src/isdn/5ESSmes.c +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -85,7 +85,6 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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: @@ -194,11 +193,6 @@ L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I 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) From 345c7e741adbb28958b2bc61965881ca5f31a1dd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:24:54 +0000 Subject: [PATCH 0999/1766] merge patches from stkn openzap-facility-Umes.patch openzap-53ess-facility.patch openzap-5ess-facility-Umes.patch to fix some 5ess dialect issues when talking to an actual lucent 5ess git-svn-id: http://svn.openzap.org/svn/openzap/trunk@519 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/5ESSStateNT.c | 3 +++ libs/openzap/src/isdn/5ESSStateTE.c | 3 +++ libs/openzap/src/isdn/5ESSmes.c | 1 + libs/openzap/src/isdn/Q931mes.c | 1 + 4 files changed, 8 insertions(+) diff --git a/libs/openzap/src/isdn/5ESSStateNT.c b/libs/openzap/src/isdn/5ESSStateNT.c index 5ba4ca8f79..d2a5540c32 100644 --- a/libs/openzap/src/isdn/5ESSStateNT.c +++ b/libs/openzap/src/isdn/5ESSStateNT.c @@ -121,6 +121,9 @@ void ATT5ESSCreateNT(L3UCHAR i) 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.*/ diff --git a/libs/openzap/src/isdn/5ESSStateTE.c b/libs/openzap/src/isdn/5ESSStateTE.c index 13a080cadc..62594212e3 100644 --- a/libs/openzap/src/isdn/5ESSStateTE.c +++ b/libs/openzap/src/isdn/5ESSStateTE.c @@ -130,6 +130,9 @@ void ATT5ESSCreateTE(L3UCHAR i) 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.*/ diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c index fc8d4b9fbb..10508baf9a 100644 --- a/libs/openzap/src/isdn/5ESSmes.c +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -95,6 +95,7 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 4a53516bdd..43a5098f62 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1179,6 +1179,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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; From 092200f022cbeb45d90943d6bb870724315caa2b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:24:54 +0000 Subject: [PATCH 1000/1766] merge patches from stkn openzap-facility-Umes.patch openzap-53ess-facility.patch openzap-5ess-facility-Umes.patch to fix some 5ess dialect issues when talking to an actual lucent 5ess git-svn-id: http://svn.openzap.org/svn/openzap/trunk@519 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/5ESSStateNT.c | 3 +++ libs/freetdm/src/isdn/5ESSStateTE.c | 3 +++ libs/freetdm/src/isdn/5ESSmes.c | 1 + libs/freetdm/src/isdn/Q931mes.c | 1 + 4 files changed, 8 insertions(+) diff --git a/libs/freetdm/src/isdn/5ESSStateNT.c b/libs/freetdm/src/isdn/5ESSStateNT.c index 5ba4ca8f79..d2a5540c32 100644 --- a/libs/freetdm/src/isdn/5ESSStateNT.c +++ b/libs/freetdm/src/isdn/5ESSStateNT.c @@ -121,6 +121,9 @@ void ATT5ESSCreateNT(L3UCHAR i) 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.*/ diff --git a/libs/freetdm/src/isdn/5ESSStateTE.c b/libs/freetdm/src/isdn/5ESSStateTE.c index 13a080cadc..62594212e3 100644 --- a/libs/freetdm/src/isdn/5ESSStateTE.c +++ b/libs/freetdm/src/isdn/5ESSStateTE.c @@ -130,6 +130,9 @@ void ATT5ESSCreateTE(L3UCHAR i) 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.*/ diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c index fc8d4b9fbb..10508baf9a 100644 --- a/libs/freetdm/src/isdn/5ESSmes.c +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -95,6 +95,7 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 4a53516bdd..43a5098f62 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1179,6 +1179,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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; From f9612fdb72135a2bc2b9bfd1ea86d9fa8b78e96e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:37:45 +0000 Subject: [PATCH 1001/1766] better dep tracking git-svn-id: http://svn.openzap.org/svn/openzap/trunk@520 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 2ad180b430..a595b9355e 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -246,20 +246,20 @@ install: all uninstall: @rm -fr $(DESTDIR)$(PREFIX) -$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: +$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: +$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: +$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so @@ -270,11 +270,11 @@ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) +$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so From c7106ffa5de72b38e59adbf80256c6d95f96bf78 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:37:45 +0000 Subject: [PATCH 1002/1766] better dep tracking git-svn-id: http://svn.openzap.org/svn/openzap/trunk@520 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 2ad180b430..a595b9355e 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -246,20 +246,20 @@ install: all uninstall: @rm -fr $(DESTDIR)$(PREFIX) -$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: +$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: +$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: +$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so @@ -270,11 +270,11 @@ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) +$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so From 59e2f1894e9f3545fb3bdca291b013b4ad183567 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:50:42 +0000 Subject: [PATCH 1003/1766] only install if the file is NOT there git-svn-id: http://svn.openzap.org/svn/openzap/trunk@521 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile index b380a8103a..025e0df927 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile @@ -13,7 +13,7 @@ $(OZSO): $(OZ_DIR)/.update local_install: cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)" - [ ! -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs + [ -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs local_clean: cd $(OZ_DIR) && $(MAKE) clean From c18c881bd43f7db1d49461f03b7889fda8c4e637 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 18:50:42 +0000 Subject: [PATCH 1004/1766] only install if the file is NOT there git-svn-id: http://svn.openzap.org/svn/openzap/trunk@521 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile index b380a8103a..025e0df927 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile @@ -13,7 +13,7 @@ $(OZSO): $(OZ_DIR)/.update local_install: cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)" - [ ! -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs + [ -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs local_clean: cd $(OZ_DIR) && $(MAKE) clean From 81a44b3fdc3ee1b3eeaf7c7c8fef433bd9ed1e1f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 20:41:17 +0000 Subject: [PATCH 1005/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@522 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 15 +++++----- libs/openzap/src/include/zap_types.h | 2 ++ .../src/ozmod/ozmod_analog/ozmod_analog.c | 1 - .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +- libs/openzap/src/testanalog.c | 3 +- libs/openzap/src/testboost.c | 4 +-- libs/openzap/src/testisdn.c | 16 ++-------- libs/openzap/src/zap_io.c | 29 +++++++++++++------ 8 files changed, 38 insertions(+), 35 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ae9133bf1d..b93a5abc55 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1538,6 +1538,7 @@ static switch_status_t load_config(void) if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; } span_id = atoi(id); @@ -1562,8 +1563,8 @@ static switch_status_t load_config(void) if (zap_configure_span("analog", span, on_analog_signal, "tonemap", tonegroup, "digit_timeout", &to, - "max_dialstr", &max - ) != ZAP_SUCCESS) { + "max_dialstr", &max, + TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } @@ -1640,8 +1641,8 @@ static switch_status_t load_config(void) if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, - "dialect", dialect - ) != ZAP_SUCCESS) { + "dialect", dialect, + TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -1689,7 +1690,7 @@ static switch_status_t load_config(void) } } - if (!(id && local_ip && local_port && remote_ip && remote_port) ) { + if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); continue; } @@ -1709,8 +1710,8 @@ static switch_status_t load_config(void) "local_ip", local_ip, "local_port", &local_port, "remote_ip", remote_ip, - "remote_port", &remote_port - ) != ZAP_SUCCESS) { + "remote_port", &remote_port, + TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 9c14686f8c..3c04b8db8d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -58,6 +58,8 @@ 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; diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index fe438c2244..3d04425880 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -107,7 +107,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); - while(var = va_arg(ap, char *)) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 64cad3c02d..14086a5154 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1122,6 +1122,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { + zap_set_string(span->last_error, "missing params"); return ZAP_FAIL; } @@ -1147,7 +1148,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) zap_module_t zap_module = { - "analog", + "ss7_boost", NULL, NULL, zap_ss7_boost_init, diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 813605decc..dd91c639d9 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -98,7 +98,8 @@ int main(int argc, char *argv[]) if (zap_configure_span("analog", span, on_signal, "tonemap", "te", "digit_timeout", &digit_timeout, - "max_dialstr", &max_dialstr + "max_dialstr", &max_dialstr, + TAG_END ) == ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); goto done; diff --git a/libs/openzap/src/testboost.c b/libs/openzap/src/testboost.c index c27636efab..e585fcbb1d 100644 --- a/libs/openzap/src/testboost.c +++ b/libs/openzap/src/testboost.c @@ -43,8 +43,8 @@ int main(int argc, char *argv[]) "local_ip", "127.0.0.65", "local_port", &local_port, "remote_ip", "127.0.0.66", - "remote_port", &remote_port - ) == ZAP_SUCCESS) { + "remote_port", &remote_port, + TAG_END) == ZAP_SUCCESS) { zap_span_start(span); } else { fprintf(stderr, "Error starting SS7_BOOST\n"); diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 29bf4c952b..7606d4bb74 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -38,27 +38,15 @@ int main(int argc, char *argv[]) goto done; } - -#if 1 - if (zap_configure_span("isdn", span, on_signal, "mode", "te", - "dialect", "national" - ) == ZAP_SUCCESS) { + "dialect", "national", + TAG_END) == ZAP_SUCCESS) { zap_span_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } -#else - if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) { - zap_isdn_start(span); - } else { - fprintf(stderr, "Error starting ISDN D-Channel\n"); - goto done; - } - -#endif signal(SIGINT, handle_SIGINT); R = 1; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 7eb6bda296..1619493294 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2135,13 +2135,13 @@ int zap_load_modules(void) if (!(lib = zap_dso_open(path, &err))) { zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - free(err); + zap_safe_free(err); continue; } if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - free(err); + zap_safe_free(err); continue; } @@ -2149,20 +2149,24 @@ int zap_load_modules(void) zap_io_interface_t *interface; if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interface->name, interface); - process_module_config(interface); + if (hashtable_search(globals.interface_hash, (void *)interface->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); + } else { + hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + process_module_config(interface); + x++; + } zap_mutex_unlock(globals.mutex); - x++; } } if (mod->sig_load) { if (mod->sig_load() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); x++; @@ -2180,8 +2184,15 @@ int zap_load_modules(void) zap_set_string(mod->name, p); } - hashtable_insert(globals.module_hash, (void *)mod->name, mod); - count++; + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.module_hash, (void *)mod->name)) { + zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); + zap_dso_destroy(&lib); + } else { + hashtable_insert(globals.module_hash, (void *)mod->name, mod); + count++; + } + zap_mutex_unlock(globals.mutex); } else { zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); zap_dso_destroy(&lib); From 2070e9d05b74c8c413fccdd033516609d4174930 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 20:41:17 +0000 Subject: [PATCH 1006/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@522 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 15 +++++----- libs/freetdm/src/include/zap_types.h | 2 ++ .../src/ozmod/ozmod_analog/ozmod_analog.c | 1 - .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +- libs/freetdm/src/testanalog.c | 3 +- libs/freetdm/src/testboost.c | 4 +-- libs/freetdm/src/testisdn.c | 16 ++-------- libs/freetdm/src/zap_io.c | 29 +++++++++++++------ 8 files changed, 38 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ae9133bf1d..b93a5abc55 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1538,6 +1538,7 @@ static switch_status_t load_config(void) if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; } span_id = atoi(id); @@ -1562,8 +1563,8 @@ static switch_status_t load_config(void) if (zap_configure_span("analog", span, on_analog_signal, "tonemap", tonegroup, "digit_timeout", &to, - "max_dialstr", &max - ) != ZAP_SUCCESS) { + "max_dialstr", &max, + TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } @@ -1640,8 +1641,8 @@ static switch_status_t load_config(void) if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, - "dialect", dialect - ) != ZAP_SUCCESS) { + "dialect", dialect, + TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -1689,7 +1690,7 @@ static switch_status_t load_config(void) } } - if (!(id && local_ip && local_port && remote_ip && remote_port) ) { + if (!id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); continue; } @@ -1709,8 +1710,8 @@ static switch_status_t load_config(void) "local_ip", local_ip, "local_port", &local_port, "remote_ip", remote_ip, - "remote_port", &remote_port - ) != ZAP_SUCCESS) { + "remote_port", &remote_port, + TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 9c14686f8c..3c04b8db8d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -58,6 +58,8 @@ 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; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index fe438c2244..3d04425880 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -107,7 +107,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); - while(var = va_arg(ap, char *)) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 64cad3c02d..14086a5154 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1122,6 +1122,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { + zap_set_string(span->last_error, "missing params"); return ZAP_FAIL; } @@ -1147,7 +1148,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) zap_module_t zap_module = { - "analog", + "ss7_boost", NULL, NULL, zap_ss7_boost_init, diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 813605decc..dd91c639d9 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -98,7 +98,8 @@ int main(int argc, char *argv[]) if (zap_configure_span("analog", span, on_signal, "tonemap", "te", "digit_timeout", &digit_timeout, - "max_dialstr", &max_dialstr + "max_dialstr", &max_dialstr, + TAG_END ) == ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); goto done; diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index c27636efab..e585fcbb1d 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -43,8 +43,8 @@ int main(int argc, char *argv[]) "local_ip", "127.0.0.65", "local_port", &local_port, "remote_ip", "127.0.0.66", - "remote_port", &remote_port - ) == ZAP_SUCCESS) { + "remote_port", &remote_port, + TAG_END) == ZAP_SUCCESS) { zap_span_start(span); } else { fprintf(stderr, "Error starting SS7_BOOST\n"); diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 29bf4c952b..7606d4bb74 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -38,27 +38,15 @@ int main(int argc, char *argv[]) goto done; } - -#if 1 - if (zap_configure_span("isdn", span, on_signal, "mode", "te", - "dialect", "national" - ) == ZAP_SUCCESS) { + "dialect", "national", + TAG_END) == ZAP_SUCCESS) { zap_span_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } -#else - if (zap_isdn_configure_span(span, Q931_TE, Q931_Dialect_National, 0, on_signal) == ZAP_SUCCESS) { - zap_isdn_start(span); - } else { - fprintf(stderr, "Error starting ISDN D-Channel\n"); - goto done; - } - -#endif signal(SIGINT, handle_SIGINT); R = 1; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 7eb6bda296..1619493294 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2135,13 +2135,13 @@ int zap_load_modules(void) if (!(lib = zap_dso_open(path, &err))) { zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - free(err); + zap_safe_free(err); continue; } if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - free(err); + zap_safe_free(err); continue; } @@ -2149,20 +2149,24 @@ int zap_load_modules(void) zap_io_interface_t *interface; if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); zap_mutex_lock(globals.mutex); - hashtable_insert(globals.interface_hash, (void *)interface->name, interface); - process_module_config(interface); + if (hashtable_search(globals.interface_hash, (void *)interface->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); + } else { + hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + process_module_config(interface); + x++; + } zap_mutex_unlock(globals.mutex); - x++; } } if (mod->sig_load) { if (mod->sig_load() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); x++; @@ -2180,8 +2184,15 @@ int zap_load_modules(void) zap_set_string(mod->name, p); } - hashtable_insert(globals.module_hash, (void *)mod->name, mod); - count++; + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.module_hash, (void *)mod->name)) { + zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); + zap_dso_destroy(&lib); + } else { + hashtable_insert(globals.module_hash, (void *)mod->name, mod); + count++; + } + zap_mutex_unlock(globals.mutex); } else { zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); zap_dso_destroy(&lib); From 7d014bc91cd132495e12cc232ceac6c3e3d2a74a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 21:26:59 +0000 Subject: [PATCH 1007/1766] auto-load modules on demand git-svn-id: http://svn.openzap.org/svn/openzap/trunk@523 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 + libs/openzap/src/zap_io.c | 199 ++++++++++++++++------------- 2 files changed, 112 insertions(+), 89 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index ff13d47386..d29bd26db6 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -584,6 +584,8 @@ int zap_load_modules(void); zap_status_t zap_unload_modules(void); zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); zap_status_t zap_span_start(zap_span_t *span); +int zap_load_module(const char *name); +int zap_load_module_assume(const char *name); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 1619493294..8ab35179f4 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1959,9 +1959,14 @@ static zap_status_t load_config(void) span = NULL; continue; } - + zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type); + if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + zap_load_module_assume(type); + if ((zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } zap_mutex_unlock(globals.mutex); if (!zio) { @@ -2095,15 +2100,13 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } -int zap_load_modules(void) +int zap_load_module(const char *name) { - char cfg_name[] = "modules.conf"; + zap_dso_lib_t lib; + int count = 0, x = 0; char path[128] = ""; - zap_config_t cfg; char *err; - char *var, *val; zap_module_t *mod; - int count = 0; #ifdef WIN32 const char *ext = ".dll"; @@ -2115,8 +2118,96 @@ int zap_load_modules(void) const char *ext = ".so"; //const char *EXT = ".SO"; #endif - + if (*name == *ZAP_PATH_SEPARATOR) { + snprintf(path, sizeof(path), "%s%s", name, ext); + } else { + snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, name, ext); + } + + if (!(lib = zap_dso_open(path, &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_safe_free(err); + return 0; + } + + if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_safe_free(err); + return 0; + } + + if (mod->io_load) { + zap_io_interface_t *interface; + + if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); + } else { + zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.interface_hash, (void *)interface->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); + } else { + hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + process_module_config(interface); + x++; + } + zap_mutex_unlock(globals.mutex); + } + } + + if (mod->sig_load) { + if (mod->sig_load() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); + } else { + zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); + x++; + } + } + + if (x) { + char *p; + mod->lib = lib; + zap_set_string(mod->path, path); + if (mod->name[0] == '\0') { + if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { + p = path; + } + zap_set_string(mod->name, p); + } + + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.module_hash, (void *)mod->name)) { + zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); + zap_dso_destroy(&lib); + } else { + hashtable_insert(globals.module_hash, (void *)mod->name, mod); + count++; + } + zap_mutex_unlock(globals.mutex); + } else { + zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); + zap_dso_destroy(&lib); + } + + return count; +} + +int zap_load_module_assume(const char *name) +{ + char buf[256] = ""; + + snprintf(buf, sizeof(buf), "ozmod_%s", name); + return zap_load_module(buf); +} + +int zap_load_modules(void) +{ + char cfg_name[] = "modules.conf"; + zap_config_t cfg; + char *var, *val; + int count = 0; + if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; } @@ -2124,79 +2215,7 @@ int zap_load_modules(void) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "modules")) { if (!strcasecmp(var, "load")) { - zap_dso_lib_t lib; - int x = 0; - - if (*val == *ZAP_PATH_SEPARATOR) { - snprintf(path, sizeof(path), "%s%s", val, ext); - } else { - snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, val, ext); - } - - if (!(lib = zap_dso_open(path, &err))) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - zap_safe_free(err); - continue; - } - - if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - zap_safe_free(err); - continue; - } - - if (mod->io_load) { - zap_io_interface_t *interface; - - if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { - zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); - } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.interface_hash, (void *)interface->name)) { - zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); - } else { - hashtable_insert(globals.interface_hash, (void *)interface->name, interface); - process_module_config(interface); - x++; - } - zap_mutex_unlock(globals.mutex); - } - } - - if (mod->sig_load) { - if (mod->sig_load() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); - } else { - zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); - x++; - } - } - - if (x) { - char *p; - mod->lib = lib; - zap_set_string(mod->path, path); - if (mod->name[0] == '\0') { - if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { - p = path; - } - zap_set_string(mod->name, p); - } - - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.module_hash, (void *)mod->name)) { - zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); - zap_dso_destroy(&lib); - } else { - hashtable_insert(globals.module_hash, (void *)mod->name, mod); - count++; - } - zap_mutex_unlock(globals.mutex); - } else { - zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); - zap_dso_destroy(&lib); - } + count += zap_load_module(val); } } } @@ -2254,12 +2273,22 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_status_t status = ZAP_FAIL; + if (!mod) { + zap_load_module_assume(type); + if ((mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + if (mod && mod->sig_configure) { va_list ap; va_start(ap, sig_cb); status = mod->sig_configure(span, sig_cb, ap); va_end(ap); + } else { + zap_log(ZAP_LOG_ERROR, "can't find '%s'\n", type); } + return status; } @@ -2280,8 +2309,6 @@ zap_status_t zap_global_init(void) memset(&globals, 0, sizeof(globals)); time_init(); - //zap_isdn_init(); - //zap_ss7_boost_init(); memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); @@ -2289,14 +2316,8 @@ zap_status_t zap_global_init(void) modcount = 0; zap_mutex_create(&globals.mutex); - modcount = zap_load_modules(); - if (!modcount) { - zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); - return ZAP_FAIL; - } - if (load_config() == ZAP_SUCCESS) { globals.running = 1; return ZAP_SUCCESS; From f655ef522025f4cda7d5d9bea6c3c766f2871780 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 21:26:59 +0000 Subject: [PATCH 1008/1766] auto-load modules on demand git-svn-id: http://svn.openzap.org/svn/openzap/trunk@523 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 + libs/freetdm/src/zap_io.c | 199 ++++++++++++++++------------- 2 files changed, 112 insertions(+), 89 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ff13d47386..d29bd26db6 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -584,6 +584,8 @@ int zap_load_modules(void); zap_status_t zap_unload_modules(void); zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); zap_status_t zap_span_start(zap_span_t *span); +int zap_load_module(const char *name); +int zap_load_module_assume(const char *name); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1619493294..8ab35179f4 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1959,9 +1959,14 @@ static zap_status_t load_config(void) span = NULL; continue; } - + zap_mutex_lock(globals.mutex); - zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type); + if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + zap_load_module_assume(type); + if ((zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } zap_mutex_unlock(globals.mutex); if (!zio) { @@ -2095,15 +2100,13 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } -int zap_load_modules(void) +int zap_load_module(const char *name) { - char cfg_name[] = "modules.conf"; + zap_dso_lib_t lib; + int count = 0, x = 0; char path[128] = ""; - zap_config_t cfg; char *err; - char *var, *val; zap_module_t *mod; - int count = 0; #ifdef WIN32 const char *ext = ".dll"; @@ -2115,8 +2118,96 @@ int zap_load_modules(void) const char *ext = ".so"; //const char *EXT = ".SO"; #endif - + if (*name == *ZAP_PATH_SEPARATOR) { + snprintf(path, sizeof(path), "%s%s", name, ext); + } else { + snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, name, ext); + } + + if (!(lib = zap_dso_open(path, &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_safe_free(err); + return 0; + } + + if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { + zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); + zap_safe_free(err); + return 0; + } + + if (mod->io_load) { + zap_io_interface_t *interface; + + if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); + } else { + zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.interface_hash, (void *)interface->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); + } else { + hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + process_module_config(interface); + x++; + } + zap_mutex_unlock(globals.mutex); + } + } + + if (mod->sig_load) { + if (mod->sig_load() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); + } else { + zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); + x++; + } + } + + if (x) { + char *p; + mod->lib = lib; + zap_set_string(mod->path, path); + if (mod->name[0] == '\0') { + if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { + p = path; + } + zap_set_string(mod->name, p); + } + + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.module_hash, (void *)mod->name)) { + zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); + zap_dso_destroy(&lib); + } else { + hashtable_insert(globals.module_hash, (void *)mod->name, mod); + count++; + } + zap_mutex_unlock(globals.mutex); + } else { + zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); + zap_dso_destroy(&lib); + } + + return count; +} + +int zap_load_module_assume(const char *name) +{ + char buf[256] = ""; + + snprintf(buf, sizeof(buf), "ozmod_%s", name); + return zap_load_module(buf); +} + +int zap_load_modules(void) +{ + char cfg_name[] = "modules.conf"; + zap_config_t cfg; + char *var, *val; + int count = 0; + if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; } @@ -2124,79 +2215,7 @@ int zap_load_modules(void) while (zap_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "modules")) { if (!strcasecmp(var, "load")) { - zap_dso_lib_t lib; - int x = 0; - - if (*val == *ZAP_PATH_SEPARATOR) { - snprintf(path, sizeof(path), "%s%s", val, ext); - } else { - snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, val, ext); - } - - if (!(lib = zap_dso_open(path, &err))) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - zap_safe_free(err); - continue; - } - - if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - zap_safe_free(err); - continue; - } - - if (mod->io_load) { - zap_io_interface_t *interface; - - if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { - zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); - } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.interface_hash, (void *)interface->name)) { - zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); - } else { - hashtable_insert(globals.interface_hash, (void *)interface->name, interface); - process_module_config(interface); - x++; - } - zap_mutex_unlock(globals.mutex); - } - } - - if (mod->sig_load) { - if (mod->sig_load() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); - } else { - zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); - x++; - } - } - - if (x) { - char *p; - mod->lib = lib; - zap_set_string(mod->path, path); - if (mod->name[0] == '\0') { - if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { - p = path; - } - zap_set_string(mod->name, p); - } - - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.module_hash, (void *)mod->name)) { - zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); - zap_dso_destroy(&lib); - } else { - hashtable_insert(globals.module_hash, (void *)mod->name, mod); - count++; - } - zap_mutex_unlock(globals.mutex); - } else { - zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); - zap_dso_destroy(&lib); - } + count += zap_load_module(val); } } } @@ -2254,12 +2273,22 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_status_t status = ZAP_FAIL; + if (!mod) { + zap_load_module_assume(type); + if ((mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + if (mod && mod->sig_configure) { va_list ap; va_start(ap, sig_cb); status = mod->sig_configure(span, sig_cb, ap); va_end(ap); + } else { + zap_log(ZAP_LOG_ERROR, "can't find '%s'\n", type); } + return status; } @@ -2280,8 +2309,6 @@ zap_status_t zap_global_init(void) memset(&globals, 0, sizeof(globals)); time_init(); - //zap_isdn_init(); - //zap_ss7_boost_init(); memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); @@ -2289,14 +2316,8 @@ zap_status_t zap_global_init(void) modcount = 0; zap_mutex_create(&globals.mutex); - modcount = zap_load_modules(); - if (!modcount) { - zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n"); - return ZAP_FAIL; - } - if (load_config() == ZAP_SUCCESS) { globals.running = 1; return ZAP_SUCCESS; From 368899cf5161b1766169760babbe0d229b60d642 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 21:29:58 +0000 Subject: [PATCH 1009/1766] auto-load modules on demand git-svn-id: http://svn.openzap.org/svn/openzap/trunk@524 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/modules.conf | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 libs/openzap/conf/modules.conf diff --git a/libs/openzap/conf/modules.conf b/libs/openzap/conf/modules.conf deleted file mode 100644 index 28d8d0b6eb..0000000000 --- a/libs/openzap/conf/modules.conf +++ /dev/null @@ -1,11 +0,0 @@ -[modules] -;load => ozmod_skel -load => ozmod_zt -load => ozmod_wanpipe -;load => ozmod_pika -load => ozmod_isdn -load => ozmod_analog -;load => ozmod_ss7_boost - - - From 07c3d642668bbc2e7016d1f522375860b0fb9ac0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Aug 2008 21:29:58 +0000 Subject: [PATCH 1010/1766] auto-load modules on demand git-svn-id: http://svn.openzap.org/svn/openzap/trunk@524 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/modules.conf | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 libs/freetdm/conf/modules.conf diff --git a/libs/freetdm/conf/modules.conf b/libs/freetdm/conf/modules.conf deleted file mode 100644 index 28d8d0b6eb..0000000000 --- a/libs/freetdm/conf/modules.conf +++ /dev/null @@ -1,11 +0,0 @@ -[modules] -;load => ozmod_skel -load => ozmod_zt -load => ozmod_wanpipe -;load => ozmod_pika -load => ozmod_isdn -load => ozmod_analog -;load => ozmod_ss7_boost - - - From dd1bc3d4548393d0c1949ff1b137aa6b118a9d19 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 1 Sep 2008 17:25:40 +0000 Subject: [PATCH 1011/1766] [Q.921] Null terminate string buffer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@525 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index a682c2342e..2c7c740251 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -817,6 +817,8 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 } out: + buf[sizeof(buf) - 1] = '\0'; + return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, strlen(buf)); } From 31edae1ab53b6027abb6aaafe5e744c0bf43acc9 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 1 Sep 2008 17:25:40 +0000 Subject: [PATCH 1012/1766] [Q.921] Null terminate string buffer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@525 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index a682c2342e..2c7c740251 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -817,6 +817,8 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 } out: + buf[sizeof(buf) - 1] = '\0'; + return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, strlen(buf)); } From 7da014da8bb633ba3453f48a23b12ead8837e202 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 1 Sep 2008 17:32:30 +0000 Subject: [PATCH 1013/1766] [Q.921] Init buffers with zeroes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@526 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q921.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 2c7c740251..d2ed969ba9 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -576,6 +576,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 if(!mes) return 0; + memset(buf, 0, sizeof(buf)); left = sizeof(buf) - 1; @@ -598,6 +599,8 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 L2UCHAR *pmes = mes + trunk->Q921HeaderSpace; struct Q921_Link *link; + memset(pbuf, 0, sizeof(pbuf)); + pleft = sizeof(pbuf); poffset = 0; From 010987ebfce5e1d0eaf6a17c49fac67736720a75 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 1 Sep 2008 17:32:30 +0000 Subject: [PATCH 1014/1766] [Q.921] Init buffers with zeroes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@526 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q921.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 2c7c740251..d2ed969ba9 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -576,6 +576,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 if(!mes) return 0; + memset(buf, 0, sizeof(buf)); left = sizeof(buf) - 1; @@ -598,6 +599,8 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 L2UCHAR *pmes = mes + trunk->Q921HeaderSpace; struct Q921_Link *link; + memset(pbuf, 0, sizeof(pbuf)); + pleft = sizeof(pbuf); poffset = 0; From 6d86d55b224068484c7835eb9a823f55e6ff7085 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 3 Sep 2008 18:46:56 +0000 Subject: [PATCH 1015/1766] tweak for cross compile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@527 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index a595b9355e..3a1f4eb2d9 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -29,7 +29,15 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CFLAGS=@COMP_VENDOR_CFLAGS@ @DEFS@ +CC = @CC@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXFLAGS = @CXXFLAGS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ SRC=src SOURCES=\ $(SRC)/hashtable.c \ From 032368da124cb200c38420eef33fdddf87e31a47 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 3 Sep 2008 18:46:56 +0000 Subject: [PATCH 1016/1766] tweak for cross compile git-svn-id: http://svn.openzap.org/svn/openzap/trunk@527 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index a595b9355e..3a1f4eb2d9 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -29,7 +29,15 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CFLAGS=@COMP_VENDOR_CFLAGS@ @DEFS@ +CC = @CC@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXFLAGS = @CXXFLAGS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ SRC=src SOURCES=\ $(SRC)/hashtable.c \ From fca0ee9959e15f726c324cb30360906fd49f2049 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 4 Sep 2008 04:58:00 +0000 Subject: [PATCH 1017/1766] turn down the logs for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@528 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 78792ba72c..df6e116dad 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1406,7 +1406,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) &isdn_data->q931); Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); - Q921SetLogLevel(&isdn_data->q921, Q921_LOG_DEBUG); + Q921SetLogLevel(&isdn_data->q921, Q921_LOG_NONE); Q931Api_InitTrunk(&isdn_data->q931, dialect, From 29132c7207c5efcac68b9403055763a806ea514b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 4 Sep 2008 04:58:00 +0000 Subject: [PATCH 1018/1766] turn down the logs for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@528 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 78792ba72c..df6e116dad 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1406,7 +1406,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) &isdn_data->q931); Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); - Q921SetLogLevel(&isdn_data->q921, Q921_LOG_DEBUG); + Q921SetLogLevel(&isdn_data->q921, Q921_LOG_NONE); Q931Api_InitTrunk(&isdn_data->q931, dialect, From 16e3f8b8526bee29dcacdd423d05b3ceedcf9dc3 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 4 Sep 2008 20:30:16 +0000 Subject: [PATCH 1019/1766] Re-add Display IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@529 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/5ESSmes.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c index 10508baf9a..3e4b316d98 100644 --- a/libs/openzap/src/isdn/5ESSmes.c +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -85,6 +85,7 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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: @@ -194,6 +195,11 @@ L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I 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) From 83144a4093dca3a500a47905154afebfa8bdf2d4 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 4 Sep 2008 20:30:16 +0000 Subject: [PATCH 1020/1766] Re-add Display IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@529 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/5ESSmes.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c index 10508baf9a..3e4b316d98 100644 --- a/libs/freetdm/src/isdn/5ESSmes.c +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -85,6 +85,7 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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: @@ -194,6 +195,11 @@ L3INT ATT5ESSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT I 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) From e8fd83456de83076304f6433f95ab8170574abd7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Sep 2008 03:53:32 +0000 Subject: [PATCH 1021/1766] (OPENZAP-11) use all the cflags from configure so we can build ss7 boost on freebsd and fix other code issues noted by more warnings from those cflags git-svn-id: http://svn.openzap.org/svn/openzap/trunk@530 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 16 +++++++--------- libs/openzap/src/include/openzap.h | 2 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 6 +++--- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 4 ++-- libs/openzap/src/zap_io.c | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 3a1f4eb2d9..68eef4694f 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -176,8 +176,6 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - #ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - #ranlib $(MYLIB) $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl testapp: $(SRC)/testapp.c $(MYLIB) @@ -255,35 +253,35 @@ uninstall: @rm -fr $(DESTDIR)$(PREFIX) $(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so $(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so $(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so $(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d29bd26db6..d65b9ef68e 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -545,7 +545,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); -zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); +zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); void zap_channel_flush_dtmf(zap_channel_t *zchan); diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 3d04425880..6bf8b86977 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -82,10 +82,10 @@ 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; - char *tonemap = "us"; + const char *tonemap = "us"; uint32_t digit_timeout = 10; uint32_t max_dialstr = 11; - char *var, *val; + const char *var, *val; int *intval; assert(sig_cb != NULL); @@ -107,7 +107,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); - while(var = va_arg(ap, char *)) { + while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index df6e116dad..5e86199d89 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1365,7 +1365,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) isdn_data->mode = Q931_TE; dialect = Q931_Dialect_National; - while(var = va_arg(ap, char *)) { + while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "mode")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 14086a5154..7a3e08d2ce 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1091,12 +1091,12 @@ static zap_state_map_t boost_state_map = { static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; - char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; + const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; int local_port = 5300, remote_port = 5300; char *var, *val; int *intval; - while(var = va_arg(ap, char *)) { + while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8ab35179f4..67a9ae690f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -349,7 +349,7 @@ zap_status_t zap_span_close_all(void) return i ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) +zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) { zap_config_t cfg; char *var, *val; From 4317cbe2e808aa586d2277bbd354e730f12bbbc5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Sep 2008 03:53:32 +0000 Subject: [PATCH 1022/1766] (OPENZAP-11) use all the cflags from configure so we can build ss7 boost on freebsd and fix other code issues noted by more warnings from those cflags git-svn-id: http://svn.openzap.org/svn/openzap/trunk@530 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 16 +++++++--------- libs/freetdm/src/include/openzap.h | 2 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 6 +++--- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 4 ++-- libs/freetdm/src/zap_io.c | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 3a1f4eb2d9..68eef4694f 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -176,8 +176,6 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - #ar rcs $(MYLIB) $(OBJS) $(ADD_OBJS) - #ranlib $(MYLIB) $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl testapp: $(SRC)/testapp.c $(MYLIB) @@ -255,35 +253,35 @@ uninstall: @rm -fr $(DESTDIR)$(PREFIX) $(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so $(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so $(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(ZAP_CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so $(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(ZAP_CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index d29bd26db6..d65b9ef68e 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -545,7 +545,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); -zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname); +zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname); zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); void zap_channel_flush_dtmf(zap_channel_t *zchan); diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 3d04425880..6bf8b86977 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -82,10 +82,10 @@ 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; - char *tonemap = "us"; + const char *tonemap = "us"; uint32_t digit_timeout = 10; uint32_t max_dialstr = 11; - char *var, *val; + const char *var, *val; int *intval; assert(sig_cb != NULL); @@ -107,7 +107,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); - while(var = va_arg(ap, char *)) { + while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index df6e116dad..5e86199d89 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1365,7 +1365,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) isdn_data->mode = Q931_TE; dialect = Q931_Dialect_National; - while(var = va_arg(ap, char *)) { + while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "mode")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 14086a5154..7a3e08d2ce 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1091,12 +1091,12 @@ static zap_state_map_t boost_state_map = { static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; - char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; + const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; int local_port = 5300, remote_port = 5300; char *var, *val; int *intval; - while(var = va_arg(ap, char *)) { + while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8ab35179f4..67a9ae690f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -349,7 +349,7 @@ zap_status_t zap_span_close_all(void) return i ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname) +zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) { zap_config_t cfg; char *var, *val; From b3cea0f20dc8cb01c01d8a578708725b2c605512 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Sep 2008 19:12:20 +0000 Subject: [PATCH 1023/1766] (OPENZAP-12) fix param passing in ZIO_SIG_CONFIGURE_FUNCTION on some platforms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@531 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 2 +- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 5 ++++- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 +++ libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 3c04b8db8d..ace40c8698 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -409,7 +409,7 @@ typedef struct zap_io_interface zap_io_interface_t; #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_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, ...) #define ZIO_SIG_UNLOAD_ARGS (void) typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 6bf8b86977..c149f0cf7a 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -87,6 +87,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) uint32_t max_dialstr = 11; const char *var, *val; int *intval; + va_list ap; assert(sig_cb != NULL); @@ -104,9 +105,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } analog_data = malloc(sizeof(*analog_data)); - memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); + memset(analog_data, 0, sizeof(*analog_data)); + va_start(ap, sig_cb); while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { @@ -125,6 +127,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) max_dialstr = *intval; } } + va_end(ap); span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 5e86199d89..73ef91f38f 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1327,6 +1327,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; + va_list ap; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1365,6 +1366,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) isdn_data->mode = Q931_TE; dialect = Q931_Dialect_National; + va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "mode")) { if (!(val = va_arg(ap, char *))) { @@ -1387,6 +1389,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) opts = isdn_data->opts = *optp; } } + va_end(ap); span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 7a3e08d2ce..a58781adc5 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1095,7 +1095,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) int local_port = 5300, remote_port = 5300; char *var, *val; int *intval; + va_list ap; + va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { @@ -1119,6 +1121,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) remote_port = *intval; } } + va_end(ap); if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { From cd8a4e513987133bc3d3ae85f91301204b40a855 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Sep 2008 19:12:20 +0000 Subject: [PATCH 1024/1766] (OPENZAP-12) fix param passing in ZIO_SIG_CONFIGURE_FUNCTION on some platforms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@531 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 2 +- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 5 ++++- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 +++ libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 3c04b8db8d..ace40c8698 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -409,7 +409,7 @@ typedef struct zap_io_interface zap_io_interface_t; #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_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, ...) #define ZIO_SIG_UNLOAD_ARGS (void) typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 6bf8b86977..c149f0cf7a 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -87,6 +87,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) uint32_t max_dialstr = 11; const char *var, *val; int *intval; + va_list ap; assert(sig_cb != NULL); @@ -104,9 +105,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } analog_data = malloc(sizeof(*analog_data)); - memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); + memset(analog_data, 0, sizeof(*analog_data)); + va_start(ap, sig_cb); while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { @@ -125,6 +127,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) max_dialstr = *intval; } } + va_end(ap); span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 5e86199d89..73ef91f38f 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1327,6 +1327,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; + va_list ap; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1365,6 +1366,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) isdn_data->mode = Q931_TE; dialect = Q931_Dialect_National; + va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "mode")) { if (!(val = va_arg(ap, char *))) { @@ -1387,6 +1389,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) opts = isdn_data->opts = *optp; } } + va_end(ap); span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 7a3e08d2ce..a58781adc5 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1095,7 +1095,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) int local_port = 5300, remote_port = 5300; char *var, *val; int *intval; + va_list ap; + va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { @@ -1119,6 +1121,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) remote_port = *intval; } } + va_end(ap); if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { From 9ea45b7b7e153219177315626447f9d024adb7f0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Sep 2008 20:27:55 +0000 Subject: [PATCH 1025/1766] (OPENZAP-10) detect required libs using configure to fix freebsd build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@532 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 35 ++++++++++++++++++----------------- libs/openzap/configure.ac | 4 ++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 68eef4694f..808a2b2af6 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -38,6 +38,7 @@ CXXFLAGS = @CXXFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ +LIBS = @LIBS@ SRC=src SOURCES=\ $(SRC)/hashtable.c \ @@ -176,31 +177,31 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl + $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap $(LIBS) testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap $(LIBS) testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap $(LIBS) testboost: $(SRC)/testboost.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap -lm -lpthread + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap $(LIBS) testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap $(LIBS) $(SRC)/priserver.o: $(SRC)/priserver.c $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o @@ -212,7 +213,7 @@ $(LIBPRI)/$(LIBPRIA): cd libpri && make priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap $(LIBS) $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ @@ -253,35 +254,35 @@ uninstall: @rm -fr $(DESTDIR)$(PREFIX) $(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so $(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so $(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so $(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 76ee2c8df0..e04cbe7200 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -48,6 +48,10 @@ sun) ;; esac +AC_CHECK_LIB([dl], [dlopen]) +AC_CHECK_LIB([pthread], [pthread_create]) +AC_CHECK_LIB([m], [cos]) + AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) AC_CHECK_FUNC([gethostbyname_r], [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] From c880efb4c64cb1c81e15b16133b92c5c22e0b177 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Sep 2008 20:27:55 +0000 Subject: [PATCH 1026/1766] (OPENZAP-10) detect required libs using configure to fix freebsd build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@532 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 35 ++++++++++++++++++----------------- libs/freetdm/configure.ac | 4 ++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 68eef4694f..808a2b2af6 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -38,6 +38,7 @@ CXXFLAGS = @CXXFLAGS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ +LIBS = @LIBS@ SRC=src SOURCES=\ $(SRC)/hashtable.c \ @@ -176,31 +177,31 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) -ldl + $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap $(LIBS) testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap -lm -lpthread + $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap $(LIBS) testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap -lm + $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap -lm + $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap -lm + $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap -lm -lpthread + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap $(LIBS) testboost: $(SRC)/testboost.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap -lm -lpthread + $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap $(LIBS) testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap -lm -lpthread + $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap $(LIBS) $(SRC)/priserver.o: $(SRC)/priserver.c $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o @@ -212,7 +213,7 @@ $(LIBPRI)/$(LIBPRIA): cd libpri && make priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap -lm -lpthread $(LIBPRI)/$(LIBPRIA) + $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap $(LIBS) $(LIBPRI)/$(LIBPRIA) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ @@ -253,35 +254,35 @@ uninstall: @rm -fr $(DESTDIR)$(PREFIX) $(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x -lm -lpthread -ldl -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so $(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so $(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so $(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x -lm -lpthread -ldl $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 76ee2c8df0..e04cbe7200 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -48,6 +48,10 @@ sun) ;; esac +AC_CHECK_LIB([dl], [dlopen]) +AC_CHECK_LIB([pthread], [pthread_create]) +AC_CHECK_LIB([m], [cos]) + AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) AC_CHECK_FUNC([gethostbyname_r], [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] From 9060a74517da093077d9430b2e761422093e4af2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 04:15:49 +0000 Subject: [PATCH 1027/1766] revert patch from OPENZAP-12 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@533 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 2 +- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 5 +---- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 --- libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 --- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index ace40c8698..3c04b8db8d 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -409,7 +409,7 @@ typedef struct zap_io_interface zap_io_interface_t; #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, ...) +#define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap) #define ZIO_SIG_UNLOAD_ARGS (void) typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index c149f0cf7a..6bf8b86977 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -87,7 +87,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) uint32_t max_dialstr = 11; const char *var, *val; int *intval; - va_list ap; assert(sig_cb != NULL); @@ -105,10 +104,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } analog_data = malloc(sizeof(*analog_data)); - assert(analog_data != NULL); memset(analog_data, 0, sizeof(*analog_data)); + assert(analog_data != NULL); - va_start(ap, sig_cb); while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { @@ -127,7 +125,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) max_dialstr = *intval; } } - va_end(ap); span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 73ef91f38f..5e86199d89 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1327,7 +1327,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; - va_list ap; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1366,7 +1365,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) isdn_data->mode = Q931_TE; dialect = Q931_Dialect_National; - va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "mode")) { if (!(val = va_arg(ap, char *))) { @@ -1389,7 +1387,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) opts = isdn_data->opts = *optp; } } - va_end(ap); span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index a58781adc5..7a3e08d2ce 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1095,9 +1095,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) int local_port = 5300, remote_port = 5300; char *var, *val; int *intval; - va_list ap; - va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { @@ -1121,7 +1119,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) remote_port = *intval; } } - va_end(ap); if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { From 9b5b73c6285dd44e76f2c54869090fc9848a34e8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 04:15:49 +0000 Subject: [PATCH 1028/1766] revert patch from OPENZAP-12 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@533 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 2 +- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 5 +---- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 --- libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 --- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index ace40c8698..3c04b8db8d 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -409,7 +409,7 @@ typedef struct zap_io_interface zap_io_interface_t; #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, ...) +#define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap) #define ZIO_SIG_UNLOAD_ARGS (void) typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index c149f0cf7a..6bf8b86977 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -87,7 +87,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) uint32_t max_dialstr = 11; const char *var, *val; int *intval; - va_list ap; assert(sig_cb != NULL); @@ -105,10 +104,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } analog_data = malloc(sizeof(*analog_data)); - assert(analog_data != NULL); memset(analog_data, 0, sizeof(*analog_data)); + assert(analog_data != NULL); - va_start(ap, sig_cb); while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { @@ -127,7 +125,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) max_dialstr = *intval; } } - va_end(ap); span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 73ef91f38f..5e86199d89 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1327,7 +1327,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; - va_list ap; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1366,7 +1365,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) isdn_data->mode = Q931_TE; dialect = Q931_Dialect_National; - va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "mode")) { if (!(val = va_arg(ap, char *))) { @@ -1389,7 +1387,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) opts = isdn_data->opts = *optp; } } - va_end(ap); span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index a58781adc5..7a3e08d2ce 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1095,9 +1095,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) int local_port = 5300, remote_port = 5300; char *var, *val; int *intval; - va_list ap; - va_start(ap, sig_cb); while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { @@ -1121,7 +1119,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) remote_port = *intval; } } - va_end(ap); if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { From cb92fcdf43d41fc0d65b606b9674d084d9b3fb94 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 05:46:14 +0000 Subject: [PATCH 1029/1766] add some libtool usage in openzap build. This will require re-bootstrap and configure git-svn-id: http://svn.openzap.org/svn/openzap/trunk@534 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 133 +- libs/openzap/build/config.guess | 1516 ++++++ libs/openzap/build/config.sub | 1626 +++++++ libs/openzap/build/install-sh | 322 ++ libs/openzap/build/ltmain.sh | 6930 ++++++++++++++++++++++++++++ libs/openzap/build/missing | 360 ++ libs/openzap/configure.ac | 47 +- libs/openzap/src/detect_dtmf.c | 3 +- libs/openzap/src/detect_tones.c | 8 +- libs/openzap/src/include/openzap.h | 4 +- libs/openzap/src/testanalog.c | 12 +- libs/openzap/src/testapp.c | 4 +- libs/openzap/src/testboost.c | 4 +- libs/openzap/src/testcid.c | 10 +- libs/openzap/src/testisdn.c | 2 + libs/openzap/src/testtones.c | 6 +- libs/openzap/src/zap_callerid.c | 4 +- 17 files changed, 10892 insertions(+), 99 deletions(-) create mode 100755 libs/openzap/build/config.guess create mode 100755 libs/openzap/build/config.sub create mode 100755 libs/openzap/build/install-sh create mode 100644 libs/openzap/build/ltmain.sh create mode 100755 libs/openzap/build/missing diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 808a2b2af6..66fac93825 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -32,14 +32,26 @@ CC = @CC@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXFLAGS = @CXXFLAGS@ DEFS = @DEFS@ -DEPDIR = @DEPDIR@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ LIBS = @LIBS@ +DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ +SOLINK = @SOLINK@ SRC=src +top_builddir=@top_builddir@ +INSTALL=@INSTALL@ +LIBTOOL=@LIBTOOL@ +LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) +LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f +CCLD = $(CC) +PWD=$(shell pwd) +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost +CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" + +COMPILE = $(CC) $(CFLAGS) $(DEFS) $(INCS) +LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) +LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ + SOURCES=\ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ @@ -154,13 +166,7 @@ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" -MYLIB=libopenzap.so -LIBPRIA=libpri.a -LIBPRI=./libpri -TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +MYLIB=libopenzap.$(DYNAMIC_LIB_EXTEN) PREFIX=@prefix@ PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) @@ -177,112 +183,99 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) + $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) -testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap $(LIBS) +testapp: $(SRC)/testapp.o $(MYLIB) + $(LINK) $(SRC)/testapp.o ./$(MYLIB) $(LIBS) -testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap $(LIBS) +testcid: $(SRC)/testcid.o $(MYLIB) + $(LINK) $(SRC)/testcid.o ./$(MYLIB) $(LIBS) -testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap +testtones: $(SRC)/testtones.o $(MYLIB) + $(LINK) $(SRC)/testtones.o ./$(MYLIB) $(LIBS) -detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap +detect_tones: $(SRC)/detect_tones.o $(MYLIB) + $(LINK) $(SRC)/detect_tones.o ./$(MYLIB) $(LIBS) -detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap +detect_dtmf: $(SRC)/detect_dtmf.o $(MYLIB) + $(LINK) $(SRC)/detect_dtmf.o ./$(MYLIB) $(LIBS) -testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap $(LIBS) +testisdn: $(SRC)/testisdn.o $(MYLIB) + $(LINK) $(SRC)/testisdn.o ./$(MYLIB) $(LIBS) -testboost: $(SRC)/testboost.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap $(LIBS) +testboost: $(SRC)/testboost.o $(MYLIB) + $(LINK) $(SRC)/testboost.o ./$(MYLIB) $(LIBS) -testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap $(LIBS) - -$(SRC)/priserver.o: $(SRC)/priserver.c - $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o - -$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c - $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o - -$(LIBPRI)/$(LIBPRIA): - cd libpri && make - -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap $(LIBS) $(LIBPRI)/$(LIBPRIA) +testanalog: $(SRC)/testanalog.o $(MYLIB) + $(LINK) $(SRC)/testanalog.o ./$(MYLIB) $(LIBS) $(SRC)/zap_io.o: $(SRC)/zap_io.c - $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + $(COMPILE) $(MOD_CFLAGS) -c $< -o $@ %.o: %.c $(HEADERS) - $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + $(COMPILE) -c $< -o $@ dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf -mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c +mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c cd mod_openzap && make -mod_openzap: mod_openzap/mod_openzap.so +mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) mod_openzap-install: mod_openzap cd mod_openzap && make install mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi + @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi clean: - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.so src/ozmod/*/*.dylib src/ozmod/*/*.dll - @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) install: all @mkdir -p $(DESTDIR)$(PREFIX) @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf) @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @mkdir -p $(DESTDIR)$(PREFIX)/lib - @[ ! -f $(MYLIB) ] || cp -f $(MYLIB) $(DESTDIR)$(PREFIX)/lib + @$(LTINSTALL) $(MYLIB) $(DESTDIR)$(PREFIX)/lib/ @mkdir -p $(DESTDIR)$(PREFIX)/mod @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod - @cp -f src/ozmod/*/*.so $(DESTDIR)$(PREFIX)/mod + @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed uninstall: @rm -fr $(DESTDIR)$(PREFIX) -$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib -skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so +$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib +skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so +$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.c + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.c + $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib -pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so +pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so +$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c + $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) diff --git a/libs/openzap/build/config.guess b/libs/openzap/build/config.guess new file mode 100755 index 0000000000..951383e355 --- /dev/null +++ b/libs/openzap/build/config.guess @@ -0,0 +1,1516 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2007-05-17' + +# This file 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. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:* | ix86xen:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa:Linux:*:*) + echo xtensa-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/libs/openzap/build/config.sub b/libs/openzap/build/config.sub new file mode 100755 index 0000000000..c060f44833 --- /dev/null +++ b/libs/openzap/build/config.sub @@ -0,0 +1,1626 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2007-04-29' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fido | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16c) + basic_machine=cr16c-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/libs/openzap/build/install-sh b/libs/openzap/build/install-sh new file mode 100755 index 0000000000..b777f1244c --- /dev/null +++ b/libs/openzap/build/install-sh @@ -0,0 +1,322 @@ +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2004-07-05.00 + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +chmodcmd="$chmodprog 0755" +chowncmd= +chgrpcmd= +stripcmd= +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src= +dst= +dir_arg= +dstarg= +no_target_directory= + +usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: +-c (ignored) +-d create directories instead of installing files. +-g GROUP $chgrpprog installed files to GROUP. +-m MODE $chmodprog installed files to MODE. +-o USER $chownprog installed files to USER. +-s $stripprog installed files. +-t DIRECTORY install into DIRECTORY. +-T report an error if DSTFILE is a directory. +--help display this help and exit. +--version display version info and exit. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG +" + +while test -n "$1"; do + case $1 in + -c) shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + --help) echo "$usage"; exit 0;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t) dstarg=$2 + shift + shift + continue;; + + -T) no_target_directory=true + shift + continue;; + + --version) echo "$0 $scriptversion"; exit 0;; + + *) # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + test -n "$dir_arg$dstarg" && break + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dstarg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dstarg" + shift # fnord + fi + shift # arg + dstarg=$arg + done + break;; + esac +done + +if test -z "$1"; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src ;; + esac + + if test -n "$dir_arg"; then + dst=$src + src= + + if test -d "$dst"; then + mkdircmd=: + chmodcmd= + else + mkdircmd=$mkdirprog + fi + else + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dstarg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dstarg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst ;; + esac + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dstarg: Is a directory" >&2 + exit 1 + fi + dst=$dst/`basename "$src"` + fi + fi + + # This sed command emulates the dirname command. + dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + + # Make sure that the destination directory exists. + + # Skip lots of stat calls in the usual case. + if test ! -d "$dstdir"; then + defaultIFS=' + ' + IFS="${IFS-$defaultIFS}" + + oIFS=$IFS + # Some sh's can't handle IFS=/ for some reason. + IFS='%' + set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + IFS=$oIFS + + pathcomp= + + while test $# -ne 0 ; do + pathcomp=$pathcomp$1 + shift + if test ! -d "$pathcomp"; then + $mkdirprog "$pathcomp" + # mkdir can fail with a `File exist' error in case several + # install-sh are creating the directory concurrently. This + # is OK. + test -d "$pathcomp" || exit + fi + pathcomp=$pathcomp/ + done + fi + + if test -n "$dir_arg"; then + $doit $mkdircmd "$dst" \ + && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } + + else + dstfile=`basename "$dst"` + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap '(exit $?); exit' 1 2 13 15 + + # Copy the file name to the temp name. + $doit $cpprog "$src" "$dsttmp" && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && + + # Now rename the file to the real destination. + { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ + || { + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + if test -f "$dstdir/$dstfile"; then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ + || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ + || { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + } + } + fi || { (exit 1); exit; } +done + +# The final little trick to "correctly" pass the exit status to the exit trap. +{ + (exit 0); exit +} + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/libs/openzap/build/ltmain.sh b/libs/openzap/build/ltmain.sh new file mode 100644 index 0000000000..4598ec61cc --- /dev/null +++ b/libs/openzap/build/ltmain.sh @@ -0,0 +1,6930 @@ +# ltmain.sh - Provide generalized library-building support services. +# NOTE: Changing this file will not affect anything until you rerun configure. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, +# 2007 Free Software Foundation, Inc. +# Originally by Gordon Matzigkeit , 1996 +# +# 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. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +basename="s,^.*/,,g" + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath="$0" + +# The name of this program: +progname=`echo "$progpath" | $SED $basename` +modename="$progname" + +# Global variables: +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +PROGRAM=ltmain.sh +PACKAGE=libtool +VERSION=1.5.24 +TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" + +# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# Check that we have a working $echo. +if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X$1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then + # Yippee, $echo works! + : +else + # Restart under the correct shell, and then maybe $echo will work. + exec $SHELL "$progpath" --no-reexec ${1+"$@"} +fi + +if test "X$1" = X--fallback-echo; then + # used as fallback echo + shift + cat <&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE +fi + +# Global variables. +mode=$default_mode +nonopt= +prev= +prevopt= +run= +show="$echo" +show_help= +execute_dlfiles= +duplicate_deps=no +preserve_args= +lo2o="s/\\.lo\$/.${objext}/" +o2lo="s/\\.${objext}\$/.lo/" +extracted_archives= +extracted_serial=0 + +##################################### +# Shell function definitions: +# This seems to be the best place for them + +# func_mktempdir [string] +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, STRING is the basename for that directory. +func_mktempdir () +{ + my_template="${TMPDIR-/tmp}/${1-$progname}" + + if test "$run" = ":"; then + # Return a directory name, but don't create it in dry-run mode + my_tmpdir="${my_template}-$$" + else + + # If mktemp works, use that first and foremost + my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` + + if test ! -d "$my_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + my_tmpdir="${my_template}-${RANDOM-0}$$" + + save_mktempdir_umask=`umask` + umask 0077 + $mkdir "$my_tmpdir" + umask $save_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$my_tmpdir" || { + $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2 + exit $EXIT_FAILURE + } + fi + + $echo "X$my_tmpdir" | $Xsed +} + + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +func_win32_libid () +{ + win32_libid_type="unknown" + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ + $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then + win32_nmres=`eval $NM -f posix -A $1 | \ + $SED -n -e '1,100{ + / I /{ + s,.*,import, + p + q + } + }'` + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $echo $win32_libid_type +} + + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + CC_quoted="$CC_quoted $arg" + done + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + CC_quoted="$CC_quoted $arg" + done + case "$@ " in + " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + $echo "$modename: unable to infer tagged configuration" + $echo "$modename: specify a tag with \`--tag'" 1>&2 + exit $EXIT_FAILURE +# else +# $echo "$modename: using $tagname tagged configuration" + fi + ;; + esac + fi +} + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + f_ex_an_ar_dir="$1"; shift + f_ex_an_ar_oldlib="$1" + + $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)" + $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $? + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2 + exit $EXIT_FAILURE + fi +} + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + my_gentop="$1"; shift + my_oldlibs=${1+"$@"} + my_oldobjs="" + my_xlib="" + my_xabs="" + my_xdir="" + my_status="" + + $show "${rm}r $my_gentop" + $run ${rm}r "$my_gentop" + $show "$mkdir $my_gentop" + $run $mkdir "$my_gentop" + my_status=$? + if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then + exit $my_status + fi + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'` + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir="$my_gentop/$my_xlib_u" + + $show "${rm}r $my_xdir" + $run ${rm}r "$my_xdir" + $show "$mkdir $my_xdir" + $run $mkdir "$my_xdir" + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then + exit $exit_status + fi + case $host in + *-darwin*) + $show "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + if test -z "$run"; then + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'` + darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null` + if test -n "$darwin_arches"; then + darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + $show "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches ; do + mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}" + lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" + cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" + func_extract_an_archive "`pwd`" "${darwin_base_archive}" + cd "$darwin_curdir" + $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" + done # $darwin_arches + ## Okay now we have a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` + lipo -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + ${rm}r unfat-$$ + cd "$darwin_orig_dir" + else + cd "$darwin_orig_dir" + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + fi # $run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` + done + func_extract_archives_result="$my_oldobjs" +} +# End of Shell function definitions +##################################### + +# Darwin sucks +eval std_shrext=\"$shrext_cmds\" + +disable_libs=no + +# Parse our command line options once, thoroughly. +while test "$#" -gt 0 +do + arg="$1" + shift + + case $arg in + -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + execute_dlfiles) + execute_dlfiles="$execute_dlfiles $arg" + ;; + tag) + tagname="$arg" + preserve_args="${preserve_args}=$arg" + + # Check whether tagname contains only valid characters + case $tagname in + *[!-_A-Za-z0-9,/]*) + $echo "$progname: invalid tag name: $tagname" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $tagname in + CC) + # Don't test for the "default" C tag, as we know, it's there, but + # not specially marked. + ;; + *) + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then + taglist="$taglist $tagname" + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`" + else + $echo "$progname: ignoring unknown tag $tagname" 1>&2 + fi + ;; + esac + ;; + *) + eval "$prev=\$arg" + ;; + esac + + prev= + prevopt= + continue + fi + + # Have we seen a non-optional argument yet? + case $arg in + --help) + show_help=yes + ;; + + --version) + echo "\ +$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP + +Copyright (C) 2007 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + exit $? + ;; + + --config) + ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath + # Now print the configurations for the tags. + for tagname in $taglist; do + ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath" + done + exit $? + ;; + + --debug) + $echo "$progname: enabling shell trace mode" + set -x + preserve_args="$preserve_args $arg" + ;; + + --dry-run | -n) + run=: + ;; + + --features) + $echo "host: $host" + if test "$build_libtool_libs" = yes; then + $echo "enable shared libraries" + else + $echo "disable shared libraries" + fi + if test "$build_old_libs" = yes; then + $echo "enable static libraries" + else + $echo "disable static libraries" + fi + exit $? + ;; + + --finish) mode="finish" ;; + + --mode) prevopt="--mode" prev=mode ;; + --mode=*) mode="$optarg" ;; + + --preserve-dup-deps) duplicate_deps="yes" ;; + + --quiet | --silent) + show=: + preserve_args="$preserve_args $arg" + ;; + + --tag) + prevopt="--tag" + prev=tag + preserve_args="$preserve_args --tag" + ;; + --tag=*) + set tag "$optarg" ${1+"$@"} + shift + prev=tag + preserve_args="$preserve_args --tag" + ;; + + -dlopen) + prevopt="-dlopen" + prev=execute_dlfiles + ;; + + -*) + $echo "$modename: unrecognized option \`$arg'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + + *) + nonopt="$arg" + break + ;; + esac +done + +if test -n "$prevopt"; then + $echo "$modename: option \`$prevopt' requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE +fi + +case $disable_libs in +no) + ;; +shared) + build_libtool_libs=no + build_old_libs=yes + ;; +static) + build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` + ;; +esac + +# If this variable is set in any of the actions, the command in it +# will be execed at the end. This prevents here-documents from being +# left over by shells. +exec_cmd= + +if test -z "$show_help"; then + + # Infer the operation mode. + if test -z "$mode"; then + $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2 + $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2 + case $nonopt in + *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*) + mode=link + for arg + do + case $arg in + -c) + mode=compile + break + ;; + esac + done + ;; + *db | *dbx | *strace | *truss) + mode=execute + ;; + *install*|cp|mv) + mode=install + ;; + *rm) + mode=uninstall + ;; + *) + # If we have no mode, but dlfiles were specified, then do execute mode. + test -n "$execute_dlfiles" && mode=execute + + # Just use the default operation mode. + if test -z "$mode"; then + if test -n "$nonopt"; then + $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2 + else + $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2 + fi + fi + ;; + esac + fi + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$execute_dlfiles" && test "$mode" != execute; then + $echo "$modename: unrecognized option \`-dlopen'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help="$help" + help="Try \`$modename --help --mode=$mode' for more information." + + # These modes are in order of execution frequency so that they run quickly. + case $mode in + # libtool compile mode + compile) + modename="$modename: compile" + # Get the compilation command and the source file. + base_compile= + srcfile="$nonopt" # always keep a non-empty value in "srcfile" + suppress_opt=yes + suppress_output= + arg_mode=normal + libobj= + later= + + for arg + do + case $arg_mode in + arg ) + # do not "continue". Instead, add this to base_compile + lastarg="$arg" + arg_mode=normal + ;; + + target ) + libobj="$arg" + arg_mode=normal + continue + ;; + + normal ) + # Accept any command-line options. + case $arg in + -o) + if test -n "$libobj" ; then + $echo "$modename: you cannot specify \`-o' more than once" 1>&2 + exit $EXIT_FAILURE + fi + arg_mode=target + continue + ;; + + -static | -prefer-pic | -prefer-non-pic) + later="$later $arg" + continue + ;; + + -no-suppress) + suppress_opt=no + continue + ;; + + -Xcompiler) + arg_mode=arg # the next one goes into the "base_compile" arg list + continue # The current "srcfile" will either be retained or + ;; # replaced later. I would guess that would be a bug. + + -Wc,*) + args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"` + lastarg= + save_ifs="$IFS"; IFS=',' + for arg in $args; do + IFS="$save_ifs" + + # Double-quote args containing other shell metacharacters. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + lastarg="$lastarg $arg" + done + IFS="$save_ifs" + lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"` + + # Add the arguments to base_compile. + base_compile="$base_compile $lastarg" + continue + ;; + + * ) + # Accept the current argument as the source file. + # The previous "srcfile" becomes the current argument. + # + lastarg="$srcfile" + srcfile="$arg" + ;; + esac # case $arg + ;; + esac # case $arg_mode + + # Aesthetically quote the previous argument. + lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"` + + case $lastarg in + # Double-quote args containing other shell metacharacters. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, and some SunOS ksh mistreat backslash-escaping + # in scan sets (worked around with variable expansion), + # and furthermore cannot handle '|' '&' '(' ')' in scan sets + # at all, so we specify them separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + lastarg="\"$lastarg\"" + ;; + esac + + base_compile="$base_compile $lastarg" + done # for arg + + case $arg_mode in + arg) + $echo "$modename: you must specify an argument for -Xcompile" + exit $EXIT_FAILURE + ;; + target) + $echo "$modename: you must specify a target with \`-o'" 1>&2 + exit $EXIT_FAILURE + ;; + *) + # Get the name of the library object. + [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'` + ;; + esac + + # Recognize several different file suffixes. + # If the user specifies -o file.o, it is replaced with file.lo + xform='[cCFSifmso]' + case $libobj in + *.ada) xform=ada ;; + *.adb) xform=adb ;; + *.ads) xform=ads ;; + *.asm) xform=asm ;; + *.c++) xform=c++ ;; + *.cc) xform=cc ;; + *.ii) xform=ii ;; + *.class) xform=class ;; + *.cpp) xform=cpp ;; + *.cxx) xform=cxx ;; + *.[fF][09]?) xform=[fF][09]. ;; + *.for) xform=for ;; + *.java) xform=java ;; + *.obj) xform=obj ;; + esac + + libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` + + case $libobj in + *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;; + *) + $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + func_infer_tag $base_compile + + for arg in $later; do + case $arg in + -static) + build_old_libs=yes + continue + ;; + + -prefer-pic) + pic_mode=yes + continue + ;; + + -prefer-non-pic) + pic_mode=no + continue + ;; + esac + done + + qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"` + case $qlibobj in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qlibobj="\"$qlibobj\"" ;; + esac + test "X$libobj" != "X$qlibobj" \ + && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \ + && $echo "$modename: libobj name \`$libobj' may not contain shell special characters." + objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` + xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$obj"; then + xdir= + else + xdir=$xdir/ + fi + lobj=${xdir}$objdir/$objname + + if test -z "$base_compile"; then + $echo "$modename: you must specify a compilation command" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Delete any leftover library objects. + if test "$build_old_libs" = yes; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + $run $rm $removelist + trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2*) + pic_mode=default + ;; + esac + if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test "$compiler_c_o" = no; then + output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} + lockfile="$output_obj.lock" + removelist="$removelist $output_obj $lockfile" + trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test "$need_locks" = yes; then + until $run ln "$progpath" "$lockfile" 2>/dev/null; do + $show "Waiting for $lockfile to be removed" + sleep 2 + done + elif test "$need_locks" = warn; then + if test -f "$lockfile"; then + $echo "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + $echo "$srcfile" > "$lockfile" + fi + + if test -n "$fix_srcfile_path"; then + eval srcfile=\"$fix_srcfile_path\" + fi + qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"` + case $qsrcfile in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qsrcfile="\"$qsrcfile\"" ;; + esac + + $run $rm "$libobj" "${libobj}T" + + # Create a libtool object file (analogous to a ".la" file), + # but don't create it if we're doing a dry run. + test -z "$run" && cat > ${libobj}T </dev/null`" != "X$srcfile"; then + $echo "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + $show "$mv $output_obj $lobj" + if $run $mv $output_obj $lobj; then : + else + error=$? + $run $rm $removelist + exit $error + fi + fi + + # Append the name of the PIC object to the libtool object file. + test -z "$run" && cat >> ${libobj}T <> ${libobj}T </dev/null`" != "X$srcfile"; then + $echo "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + $show "$mv $output_obj $obj" + if $run $mv $output_obj $obj; then : + else + error=$? + $run $rm $removelist + exit $error + fi + fi + + # Append the name of the non-PIC object the libtool object file. + # Only append if the libtool object file exists. + test -z "$run" && cat >> ${libobj}T <> ${libobj}T <&2 + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg="$1" + shift + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test + ;; + *) qarg=$arg ;; + esac + libtool_args="$libtool_args $qarg" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + compile_command="$compile_command @OUTPUT@" + finalize_command="$finalize_command @OUTPUT@" + ;; + esac + + case $prev in + dlfiles|dlprefiles) + if test "$preload" = no; then + # Add the symbol object into the linking commands. + compile_command="$compile_command @SYMFILE@" + finalize_command="$finalize_command @SYMFILE@" + preload=yes + fi + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test "$dlself" = no; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test "$prev" = dlprefiles; then + dlself=yes + elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test "$prev" = dlfiles; then + dlfiles="$dlfiles $arg" + else + dlprefiles="$dlprefiles $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols="$arg" + if test ! -f "$arg"; then + $echo "$modename: symbol file \`$arg' does not exist" + exit $EXIT_FAILURE + fi + prev= + continue + ;; + expsyms_regex) + export_symbols_regex="$arg" + prev= + continue + ;; + inst_prefix) + inst_prefix_dir="$arg" + prev= + continue + ;; + precious_regex) + precious_files_regex="$arg" + prev= + continue + ;; + release) + release="-$arg" + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat $save_arg` + do +# moreargs="$moreargs $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + pic_object= + non_pic_object= + + # Read the .lo file + # If there is no directory component, then add one. + case $arg in + */* | *\\*) . $arg ;; + *) . ./$arg ;; + esac + + if test -z "$pic_object" || \ + test -z "$non_pic_object" || + test "$pic_object" = none && \ + test "$non_pic_object" = none; then + $echo "$modename: cannot find name of object for \`$arg'" 1>&2 + exit $EXIT_FAILURE + fi + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + libobjs="$libobjs $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + non_pic_objects="$non_pic_objects $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if test -z "$run"; then + $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 + exit $EXIT_FAILURE + else + # Dry-run case. + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` + non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` + libobjs="$libobjs $pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + fi + done + else + $echo "$modename: link input file \`$save_arg' does not exist" + exit $EXIT_FAILURE + fi + arg=$save_arg + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + $echo "$modename: only absolute run-paths are allowed" 1>&2 + exit $EXIT_FAILURE + ;; + esac + if test "$prev" = rpath; then + case "$rpath " in + *" $arg "*) ;; + *) rpath="$rpath $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) xrpath="$xrpath $arg" ;; + esac + fi + prev= + continue + ;; + xcompiler) + compiler_flags="$compiler_flags $qarg" + prev= + compile_command="$compile_command $qarg" + finalize_command="$finalize_command $qarg" + continue + ;; + xlinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $wl$qarg" + prev= + compile_command="$compile_command $wl$qarg" + finalize_command="$finalize_command $wl$qarg" + continue + ;; + xcclinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $qarg" + prev= + compile_command="$compile_command $qarg" + finalize_command="$finalize_command $qarg" + continue + ;; + shrext) + shrext_cmds="$arg" + prev= + continue + ;; + darwin_framework|darwin_framework_skip) + test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + prev= + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg="$arg" + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + compile_command="$compile_command $link_static_flag" + finalize_command="$finalize_command $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2 + continue + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + $echo "$modename: more than one -exported-symbols argument is not allowed" + exit $EXIT_FAILURE + fi + if test "X$arg" = "X-export-symbols"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework|-arch|-isysroot) + case " $CC " in + *" ${arg} ${1} "* | *" ${arg} ${1} "*) + prev=darwin_framework_skip ;; + *) compiler_flags="$compiler_flags $arg" + prev=darwin_framework ;; + esac + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + ;; + esac + continue + ;; + + -L*) + dir=`$echo "X$arg" | $Xsed -e 's/^-L//'` + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2 + absdir="$dir" + notinst_path="$notinst_path $dir" + fi + dir="$absdir" + ;; + esac + case "$deplibs " in + *" -L$dir "*) ;; + *) + deplibs="$deplibs -L$dir" + lib_search_path="$lib_search_path $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + *) dllsearchpath="$dllsearchpath:$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test "X$arg" = "X-lc" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + test "X$arg" = "X-lc" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + deplibs="$deplibs -framework System" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test "X$arg" = "X-lc" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test "X$arg" = "X-lc" && continue + ;; + esac + elif test "X$arg" = "X-lc_r"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + deplibs="$deplibs $arg" + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + -model) + compile_command="$compile_command $arg" + compiler_flags="$compiler_flags $arg" + finalize_command="$finalize_command $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + compiler_flags="$compiler_flags $arg" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + continue + ;; + + -module) + module=yes + continue + ;; + + # -64, -mips[0-9] enable 64-bit mode on the SGI compiler + # -r[0-9][0-9]* specifies the processor on the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler + # +DA*, +DD* enable 64-bit mode on the HP compiler + # -q* pass through compiler args for the IBM compiler + # -m* pass through architecture-specific compiler args for GCC + # -m*, -t[45]*, -txscale* pass through architecture-specific + # compiler args for GCC + # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC + # -F/path gives path to uninstalled frameworks, gcc on darwin + # @file GCC response files + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) + + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + compiler_flags="$compiler_flags $arg" + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) + # The PATH hackery in wrapper scripts is required on Windows + # and Darwin in order for the loader to find any dlls it needs. + $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 + $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + dir=`$echo "X$arg" | $Xsed -e 's/^-R//'` + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + $echo "$modename: only absolute run-paths are allowed" 1>&2 + exit $EXIT_FAILURE + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -Wc,*) + args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'` + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + case $flag in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + flag="\"$flag\"" + ;; + esac + arg="$arg $wl$flag" + compiler_flags="$compiler_flags $flag" + done + IFS="$save_ifs" + arg=`$echo "X$arg" | $Xsed -e "s/^ //"` + ;; + + -Wl,*) + args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'` + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + case $flag in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + flag="\"$flag\"" + ;; + esac + arg="$arg $wl$flag" + compiler_flags="$compiler_flags $wl$flag" + linker_flags="$linker_flags $flag" + done + IFS="$save_ifs" + arg=`$echo "X$arg" | $Xsed -e "s/^ //"` + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # Some other compiler flag. + -* | +*) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + ;; + + *.$objext) + # A standard object. + objs="$objs $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + pic_object= + non_pic_object= + + # Read the .lo file + # If there is no directory component, then add one. + case $arg in + */* | *\\*) . $arg ;; + *) . ./$arg ;; + esac + + if test -z "$pic_object" || \ + test -z "$non_pic_object" || + test "$pic_object" = none && \ + test "$non_pic_object" = none; then + $echo "$modename: cannot find name of object for \`$arg'" 1>&2 + exit $EXIT_FAILURE + fi + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + libobjs="$libobjs $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + non_pic_objects="$non_pic_objects $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if test -z "$run"; then + $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 + exit $EXIT_FAILURE + else + # Dry-run case. + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` + non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` + libobjs="$libobjs $pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + fi + ;; + + *.$libext) + # An archive. + deplibs="$deplibs $arg" + old_deplibs="$old_deplibs $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + if test "$prev" = dlfiles; then + # This library was specified with -dlopen. + dlfiles="$dlfiles $arg" + prev= + elif test "$prev" = dlprefiles; then + # The library was specified with -dlpreopen. + dlprefiles="$dlprefiles $arg" + prev= + else + deplibs="$deplibs $arg" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + fi + done # argument parsing loop + + if test -n "$prev"; then + $echo "$modename: the \`$prevarg' option requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'` + libobjs_save="$libobjs" + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'` + if test "X$output_objdir" = "X$output"; then + output_objdir="$objdir" + else + output_objdir="$output_objdir/$objdir" + fi + # Create the object directory. + if test ! -d "$output_objdir"; then + $show "$mkdir $output_objdir" + $run $mkdir $output_objdir + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then + exit $exit_status + fi + fi + + # Determine the type of output + case $output in + "") + $echo "$modename: you must specify an output file" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + case $host in + *cygwin* | *mingw* | *pw32*) + # don't eliminate duplications in $postdeps and $predeps + duplicate_compiler_generated_deps=yes + ;; + *) + duplicate_compiler_generated_deps=$duplicate_deps + ;; + esac + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if test "X$duplicate_deps" = "Xyes" ; then + case "$libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + libs="$libs $deplib" + done + + if test "$linkmode" = lib; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; + esac + pre_post_deps="$pre_post_deps $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + case $linkmode in + lib) + passes="conv link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2 + exit $EXIT_FAILURE + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=no + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + for pass in $passes; do + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan"; then + libs="$deplibs" + deplibs= + fi + if test "$linkmode" = prog; then + case $pass in + dlopen) libs="$dlfiles" ;; + dlpreopen) libs="$dlprefiles" ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + esac + fi + if test "$pass" = dlopen; then + # Collect dlpreopened libraries + save_deplibs="$deplibs" + deplibs= + fi + for deplib in $libs; do + lib= + found=no + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + compiler_flags="$compiler_flags $deplib" + fi + continue + ;; + -l*) + if test "$linkmode" != lib && test "$linkmode" != prog; then + $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2 + continue + fi + name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` + for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib="$searchdir/lib${name}${search_ext}" + if test -f "$lib"; then + if test "$search_ext" = ".la"; then + found=yes + else + found=no + fi + break 2 + fi + done + done + if test "$found" != yes; then + # deplib doesn't seem to be a libtool library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + else # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $deplib "*) + if (${SED} -e '2q' $lib | + grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + library_names= + old_library= + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + for l in $old_library $library_names; do + ll="$l" + done + if test "X$ll" = "X$old_library" ; then # only static version available + found=no + ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` + test "X$ladir" = "X$lib" && ladir="." + lib=$ladir/$old_library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + fi + ;; # -l + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test "$pass" = conv && continue + newdependency_libs="$deplib $newdependency_libs" + newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` + ;; + prog) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + if test "$pass" = scan; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` + ;; + *) + $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2 + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test "$pass" = link; then + dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'` + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) lib="$deplib" ;; + *.$libext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + valid_a_lib=no + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method + match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` + if eval $echo \"$deplib\" 2>/dev/null \ + | $SED 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=yes + fi + ;; + pass_all) + valid_a_lib=yes + ;; + esac + if test "$valid_a_lib" != yes; then + $echo + $echo "*** Warning: Trying to link with static lib archive $deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because the file extensions .$libext of this argument makes me believe" + $echo "*** that it is just a static archive that I should not used here." + else + $echo + $echo "*** Warning: Linking the shared library $output against the" + $echo "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + fi + continue + ;; + prog) + if test "$pass" != link; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + elif test "$linkmode" = prog; then + if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + newdlprefiles="$newdlprefiles $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + newdlfiles="$newdlfiles $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=yes + continue + ;; + esac # case $deplib + if test "$found" = yes || test -f "$lib"; then : + else + $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2 + exit $EXIT_FAILURE + fi + + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + + ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` + test "X$ladir" = "X$lib" && ladir="." + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan" || + { test "$linkmode" != prog && test "$linkmode" != lib; }; then + test -n "$dlopen" && dlfiles="$dlfiles $dlopen" + test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" + fi + + if test "$pass" = conv; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + # It is a libtool convenience library, so add in its objects. + convenience="$convenience $ladir/$objdir/$old_library" + old_convenience="$old_convenience $ladir/$objdir/$old_library" + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + elif test "$linkmode" != prog && test "$linkmode" != lib; then + $echo "$modename: \`$lib' is not a convenience library" 1>&2 + exit $EXIT_FAILURE + fi + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + for l in $old_library $library_names; do + linklib="$l" + done + if test -z "$linklib"; then + $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + + # This library was specified with -dlopen. + if test "$pass" = dlopen; then + if test -z "$libdir"; then + $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + if test -z "$dlname" || + test "$dlopen_support" != yes || + test "$build_libtool_libs" = no; then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + dlprefiles="$dlprefiles $lib $dependency_libs" + else + newdlfiles="$newdlfiles $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2 + $echo "$modename: passing it literally to the linker, although it might fail" 1>&2 + abs_ladir="$ladir" + fi + ;; + esac + laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + + # Find the relevant object directory and library name. + if test "X$installed" = Xyes; then + if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + $echo "$modename: warning: library \`$lib' was moved." 1>&2 + dir="$ladir" + absdir="$abs_ladir" + libdir="$abs_ladir" + else + dir="$libdir" + absdir="$libdir" + fi + test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir="$ladir" + absdir="$abs_ladir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + else + dir="$ladir/$objdir" + absdir="$abs_ladir/$objdir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + fi + fi # $installed = yes + name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` + + # This library was specified with -dlpreopen. + if test "$pass" = dlpreopen; then + if test -z "$libdir"; then + $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + newdlprefiles="$newdlprefiles $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + newdlprefiles="$newdlprefiles $dir/$dlname" + else + newdlprefiles="$newdlprefiles $dir/$linklib" + fi + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test "$linkmode" = lib; then + deplibs="$dir/$old_library $deplibs" + elif test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test "$linkmode" = prog && test "$pass" != link; then + newlib_search_path="$newlib_search_path $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=no + if test "$link_all_deplibs" != no || test -z "$library_names" || + test "$build_libtool_libs" = no; then + linkalldeplibs=yes + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test + esac + # Need to link against all dependency_libs? + if test "$linkalldeplibs" = yes; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test "$linkmode,$pass" = "prog,link"; then + if test -n "$library_names" && + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then + # Make sure the rpath contains only unique directories. + case "$temp_rpath " in + *" $dir "*) ;; + *" $absdir "*) ;; + *) temp_rpath="$temp_rpath $absdir" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if test "$alldeplibs" = yes && + { test "$deplibs_check_method" = pass_all || + { test "$build_libtool_libs" = yes && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test "$use_static_libs" = built && test "$installed" = yes ; then + use_static_libs=no + fi + if test -n "$library_names" && + { test "$use_static_libs" = no || test -z "$old_library"; }; then + if test "$installed" = no; then + notinst_deplibs="$notinst_deplibs $lib" + need_relink=yes + fi + # This is a shared library + + # Warn about portability, can't link against -module's on + # some systems (darwin) + if test "$shouldnotlink" = yes && test "$pass" = link ; then + $echo + if test "$linkmode" = prog; then + $echo "*** Warning: Linking the executable $output against the loadable module" + else + $echo "*** Warning: Linking the shared library $output against the loadable module" + fi + $echo "*** $linklib is not portable!" + fi + if test "$linkmode" = lib && + test "$hardcode_into_libs" = yes; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + realname="$2" + shift; shift + libname=`eval \\$echo \"$libname_spec\"` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname="$dlname" + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw*) + major=`expr $current - $age` + versuffix="-$major" + ;; + esac + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot="$soname" + soname=`$echo $soroot | ${SED} -e 's/^.*\///'` + newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a" + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + $show "extracting exported symbol list from \`$soname'" + save_ifs="$IFS"; IFS='~' + cmds=$extract_expsyms_cmds + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + $show "generating import library for \`$soname'" + save_ifs="$IFS"; IFS='~' + cmds=$old_archive_from_expsyms_cmds + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test "$linkmode" = prog || test "$mode" != relink; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test "$hardcode_direct" = no; then + add="$dir/$linklib" + case $host in + *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; + *-*-sysv4*uw2*) add_dir="-L$dir" ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir="-L$dir" ;; + *-*-darwin* ) + # if the lib is a module then we can not link against + # it, someone is ignoring the new warnings I added + if /usr/bin/file -L $add 2> /dev/null | + $EGREP ": [^:]* bundle" >/dev/null ; then + $echo "** Warning, lib $linklib is a module, not a shared library" + if test -z "$old_library" ; then + $echo + $echo "** And there doesn't seem to be a static archive available" + $echo "** The link will probably fail, sorry" + else + add="$dir/$old_library" + fi + fi + esac + elif test "$hardcode_minus_L" = no; then + case $host in + *-*-sunos*) add_shlibpath="$dir" ;; + esac + add_dir="-L$dir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = no; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + relink) + if test "$hardcode_direct" = yes; then + add="$dir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$dir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test "$lib_linked" != yes; then + $echo "$modename: configuration error: unsupported hardcode properties" + exit $EXIT_FAILURE + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; + esac + fi + if test "$linkmode" = prog; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test "$hardcode_direct" != yes && \ + test "$hardcode_minus_L" != yes && \ + test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + fi + fi + fi + + if test "$linkmode" = prog || test "$mode" = relink; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test "$hardcode_direct" = yes; then + add="$libdir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$libdir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + add="-l$name" + elif test "$hardcode_automatic" = yes; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib" ; then + add="$inst_prefix_dir$libdir/$linklib" + else + add="$libdir/$linklib" + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir="-L$libdir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + fi + + if test "$linkmode" = prog; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test "$linkmode" = prog; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test "$hardcode_direct" != unsupported; then + test -n "$old_library" && linklib="$old_library" + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test "$build_libtool_libs" = yes; then + # Not a shared library + if test "$deplibs_check_method" != pass_all; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + $echo + $echo "*** Warning: This system can not link to static lib archive $lib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have." + if test "$module" = yes; then + $echo "*** But as you try to build a module library, libtool will still create " + $echo "*** a static module, that should work as long as the dlopening application" + $echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + $echo + $echo "*** However, this would only work if libtool was able to extract symbol" + $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" + $echo "*** not find such a program. So, this module is probably useless." + $echo "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test "$linkmode" = lib; then + if test -n "$dependency_libs" && + { test "$hardcode_into_libs" != yes || + test "$build_old_libs" = yes || + test "$link_static" = yes; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'` + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) xrpath="$xrpath $temp_xrpath";; + esac;; + *) temp_deplibs="$temp_deplibs $libdir";; + esac + done + dependency_libs="$temp_deplibs" + fi + + newlib_search_path="$newlib_search_path $absdir" + # Link against this library + test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + + if test "$link_all_deplibs" != no; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + case $deplib in + -L*) path="$deplib" ;; + *.la) + dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$deplib" && dir="." + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2 + absdir="$dir" + fi + ;; + esac + if grep "^installed=no" $deplib > /dev/null; then + path="$absdir/$objdir" + else + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + if test -z "$libdir"; then + $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + if test "$absdir" != "$libdir"; then + $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2 + fi + path="$absdir" + fi + depdepl= + case $host in + *-*-darwin*) + # we do not want to link against static libs, + # but need to link against shared + eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names" ; then + for tmp in $deplibrary_names ; do + depdepl=$tmp + done + if test -f "$path/$depdepl" ; then + depdepl="$path/$depdepl" + fi + # do not add paths which are already there + case " $newlib_search_path " in + *" $path "*) ;; + *) newlib_search_path="$newlib_search_path $path";; + esac + fi + path="" + ;; + *) + path="-L$path" + ;; + esac + ;; + -l*) + case $host in + *-*-darwin*) + # Again, we only want to link against shared libraries + eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"` + for tmp in $newlib_search_path ; do + if test -f "$tmp/lib$tmp_libs.dylib" ; then + eval depdepl="$tmp/lib$tmp_libs.dylib" + break + fi + done + path="" + ;; + *) continue ;; + esac + ;; + *) continue ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + case " $deplibs " in + *" $depdepl "*) ;; + *) deplibs="$depdepl $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + dependency_libs="$newdependency_libs" + if test "$pass" = dlpreopen; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test "$pass" != dlopen; then + if test "$pass" != conv; then + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) lib_search_path="$lib_search_path $dir" ;; + esac + done + newlib_search_path= + fi + + if test "$linkmode,$pass" != "prog,link"; then + vars="deplibs" + else + vars="compile_deplibs finalize_deplibs" + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs ; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i="" + ;; + esac + if test -n "$i" ; then + tmp_libs="$tmp_libs $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test "$linkmode" = prog; then + dlfiles="$newdlfiles" + dlprefiles="$newdlprefiles" + fi + + case $linkmode in + oldlib) + if test -n "$deplibs"; then + $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 + fi + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 + fi + + if test -n "$rpath"; then + $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2 + fi + + if test -n "$xrpath"; then + $echo "$modename: warning: \`-R' is ignored for archives" 1>&2 + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for archives" 1>&2 + fi + + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2 + fi + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs="$output" + objs="$objs$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form `libNAME.la'. + case $outputname in + lib*) + name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + if test "$module" = no; then + $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + if test "$need_lib_prefix" != no; then + # Add the "lib" prefix for modules if required + name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` + fi + ;; + esac + + if test -n "$objs"; then + if test "$deplibs_check_method" != pass_all; then + $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1 + exit $EXIT_FAILURE + else + $echo + $echo "*** Warning: Linking the shared library $output against the non-libtool" + $echo "*** objects $objs is not portable!" + libobjs="$libobjs $objs" + fi + fi + + if test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2 + fi + + set dummy $rpath + if test "$#" -gt 2; then + $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2 + fi + install_libdir="$2" + + oldlibs= + if test -z "$rpath"; then + if test "$build_libtool_libs" = yes; then + # Building a libtool convenience library. + # Some compilers have problems with a `.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2 + fi + else + + # Parse the version information argument. + save_ifs="$IFS"; IFS=':' + set dummy $vinfo 0 0 0 + IFS="$save_ifs" + + if test -n "$8"; then + $echo "$modename: too many parameters to \`-version-info'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major="$2" + number_minor="$3" + number_revision="$4" + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # which has an extra 1 added just for fun + # + case $version_type in + darwin|linux|osf|windows|none) + current=`expr $number_major + $number_minor` + age="$number_minor" + revision="$number_revision" + ;; + freebsd-aout|freebsd-elf|sunos) + current="$number_major" + revision="$number_minor" + age="0" + ;; + irix|nonstopux) + current=`expr $number_major + $number_minor` + age="$number_minor" + revision="$number_minor" + lt_irix_increment=no + ;; + esac + ;; + no) + current="$2" + revision="$3" + age="$4" + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + if test "$age" -gt "$current"; then + $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + major=.`expr $current - $age` + versuffix="$major.$age.$revision" + # Darwin ld doesn't like 0 for these options... + minor_current=`expr $current + 1` + xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + ;; + + freebsd-aout) + major=".$current" + versuffix=".$current.$revision"; + ;; + + freebsd-elf) + major=".$current" + versuffix=".$current"; + ;; + + irix | nonstopux) + if test "X$lt_irix_increment" = "Xno"; then + major=`expr $current - $age` + else + major=`expr $current - $age + 1` + fi + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring="$verstring_prefix$major.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test "$loop" -ne 0; do + iface=`expr $revision - $loop` + loop=`expr $loop - 1` + verstring="$verstring_prefix$major.$iface:$verstring" + done + + # Before this point, $major must not contain `.'. + major=.$major + versuffix="$major.$revision" + ;; + + linux) + major=.`expr $current - $age` + versuffix="$major.$age.$revision" + ;; + + osf) + major=.`expr $current - $age` + versuffix=".$current.$age.$revision" + verstring="$current.$age.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$age + while test "$loop" -ne 0; do + iface=`expr $current - $loop` + loop=`expr $loop - 1` + verstring="$verstring:${iface}.0" + done + + # Make executables depend on our current version. + verstring="$verstring:${current}.0" + ;; + + sunos) + major=".$current" + versuffix=".$current.$revision" + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 filesystems. + major=`expr $current - $age` + versuffix="-$major" + ;; + + *) + $echo "$modename: unknown library version type \`$version_type'" 1>&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring="0.0" + ;; + esac + if test "$need_version" = no; then + versuffix= + else + versuffix=".0.0" + fi + fi + + # Remove version info from name if versioning should be avoided + if test "$avoid_version" = yes && test "$need_version" = no; then + major= + versuffix= + verstring="" + fi + + # Check to see if the archive will have undefined symbols. + if test "$allow_undefined" = yes; then + if test "$allow_undefined_flag" = unsupported; then + $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2 + build_libtool_libs=no + build_old_libs=yes + fi + else + # Don't allow undefined symbols. + allow_undefined_flag="$no_undefined_flag" + fi + fi + + if test "$mode" != relink; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$echo "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) + if test "X$precious_files_regex" != "X"; then + if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + removelist="$removelist $p" + ;; + *) ;; + esac + done + if test -n "$removelist"; then + $show "${rm}r $removelist" + $run ${rm}r $removelist + fi + fi + + # Now set the variables for building old libraries. + if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then + oldlibs="$oldlibs $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. + #for path in $notinst_path; do + # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` + # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` + # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` + #done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + temp_xrpath="$temp_xrpath -R$libdir" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles="$dlfiles" + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) dlfiles="$dlfiles $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles="$dlprefiles" + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) dlprefiles="$dlprefiles $lib" ;; + esac + done + + if test "$build_libtool_libs" = yes; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + deplibs="$deplibs -framework System" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test "$build_libtool_need_lc" = "yes"; then + deplibs="$deplibs -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release="" + versuffix="" + major="" + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $rm conftest.c + cat > conftest.c </dev/null` + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null \ + | grep " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib="$potent_lib" + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; + *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \ + | ${SED} 10q \ + | $EGREP "$file_magic_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $echo + $echo "*** Warning: linker path does not have real file for library $a_deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $echo "*** with $libname but no candidates were found. (...for file magic test)" + else + $echo "*** with $libname and none of the candidates passed a file format test" + $echo "*** using a file magic. Last file checked: $potlib" + fi + fi + else + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + fi + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method + match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` + for a_deplib in $deplibs; do + name=`expr $a_deplib : '-l\(.*\)'` + # If $name is empty we are operating on a -L argument. + if test -n "$name" && test "$name" != "0"; then + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $a_deplib "*) + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + ;; + esac + fi + if test -n "$a_deplib" ; then + libname=`eval \\$echo \"$libname_spec\"` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib="$potent_lib" # see symlink-check above in file_magic test + if eval $echo \"$potent_lib\" 2>/dev/null \ + | ${SED} 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $echo + $echo "*** Warning: linker path does not have real file for library $a_deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $echo "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $echo "*** with $libname and none of the candidates passed a file format test" + $echo "*** using a regex pattern. Last file checked: $potlib" + fi + fi + else + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + fi + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs="" + tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \ + -e 's/ -[LR][^ ]*//g'` + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + for i in $predeps $postdeps ; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"` + done + fi + if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \ + | grep . >/dev/null; then + $echo + if test "X$deplibs_check_method" = "Xnone"; then + $echo "*** Warning: inter-library dependencies are not supported in this platform." + else + $echo "*** Warning: inter-library dependencies are not known to be supported." + fi + $echo "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + fi + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'` + ;; + esac + + if test "$droppeddeps" = yes; then + if test "$module" = yes; then + $echo + $echo "*** Warning: libtool could not satisfy all declared inter-library" + $echo "*** dependencies of module $libname. Therefore, libtool will create" + $echo "*** a static module, that should work as long as the dlopening" + $echo "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + $echo + $echo "*** However, this would only work if libtool was able to extract symbol" + $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" + $echo "*** not find such a program. So, this module is probably useless." + $echo "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + $echo "*** The inter-library dependencies that have been dropped here will be" + $echo "*** automatically added whenever a program is linked with this library" + $echo "*** or is declared to -dlopen it." + + if test "$allow_undefined" = no; then + $echo + $echo "*** Since this library must not contain undefined symbols," + $echo "*** because either the platform does not support them or" + $echo "*** it was explicitly requested with -no-undefined," + $echo "*** libtool will only create a static version of it." + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + deplibs="$new_libs" + + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test "$build_libtool_libs" = yes; then + if test "$hardcode_into_libs" = yes; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath="$finalize_rpath" + test "$mode" != relink && rpath="$compile_rpath$rpath" + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + dep_rpath="$dep_rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + if test -n "$hardcode_libdir_flag_spec_ld"; then + case $archive_cmds in + *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; + *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; + esac + else + eval dep_rpath=\"$hardcode_libdir_flag_spec\" + fi + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath="$finalize_shlibpath" + test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + realname="$2" + shift; shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib="$output_objdir/$realname" + linknames= + for link + do + linknames="$linknames $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then + $show "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $run $rm $export_symbols + cmds=$export_symbols_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + if len=`expr "X$cmd" : ".*"` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + $show "$cmd" + $run eval "$cmd" || exit $? + skipped_export=false + else + # The command line is too long to execute in one step. + $show "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS="$save_ifs" + if test -n "$export_symbols_regex"; then + $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"" + $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + $show "$mv \"${export_symbols}T\" \"$export_symbols\"" + $run eval '$mv "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"' + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + tmp_deplibs="$tmp_deplibs $test_deplib" + ;; + esac + done + deplibs="$tmp_deplibs" + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + else + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + libobjs="$libobjs $func_extract_archives_result" + fi + fi + + if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + linker_flags="$linker_flags $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test "X$skipped_export" != "X:" && + len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise. + $echo "creating reloadable object files..." + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + output_la=`$echo "X$output" | $Xsed -e "$basename"` + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + delfiles= + last_robj= + k=1 + output=$output_objdir/$output_la-${k}.$objext + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + eval test_cmds=\"$reload_cmds $objlist $last_robj\" + if test "X$objlist" = X || + { len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len"; }; then + objlist="$objlist $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test "$k" -eq 1 ; then + # The first file doesn't have a previous command to add. + eval concat_cmds=\"$reload_cmds $objlist $last_robj\" + else + # All subsequent reloadable object files will link in + # the last one created. + eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\" + fi + last_robj=$output_objdir/$output_la-${k}.$objext + k=`expr $k + 1` + output=$output_objdir/$output_la-${k}.$objext + objlist=$obj + len=1 + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" + + if ${skipped_export-false}; then + $show "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $run $rm $export_symbols + libobjs=$output + # Append the command to create the export file. + eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\" + fi + + # Set up a command to remove the reloadable object files + # after they are used. + i=0 + while test "$i" -lt "$k" + do + i=`expr $i + 1` + delfiles="$delfiles $output_objdir/$output_la-${i}.$objext" + done + + $echo "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs="$IFS"; IFS='~' + for cmd in $concat_cmds; do + IFS="$save_ifs" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + + # Append the command to remove the reloadable object files + # to the just-reset $cmds. + eval cmds=\"\$cmds~\$rm $delfiles\" + fi + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + $show "${rm}r $gentop" + $run ${rm}r "$gentop" + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)" + $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $? + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test "$module" = yes || test "$export_dynamic" = yes; then + # On all known operating systems, these are identical. + dlname="$soname" + fi + fi + ;; + + obj) + if test -n "$deplibs"; then + $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 + fi + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 + fi + + if test -n "$rpath"; then + $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2 + fi + + if test -n "$xrpath"; then + $echo "$modename: warning: \`-R' is ignored for objects" 1>&2 + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for objects" 1>&2 + fi + + case $output in + *.lo) + if test -n "$objs$old_deplibs"; then + $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2 + exit $EXIT_FAILURE + fi + libobj="$output" + obj=`$echo "X$output" | $Xsed -e "$lo2o"` + ;; + *) + libobj= + obj="$output" + ;; + esac + + # Delete the old objects. + $run $rm $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # reload_cmds runs $LD directly, so let us get rid of + # -Wl from whole_archive_flag_spec and hope we can get by with + # turning comma into space.. + wl= + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + else + gentop="$output_objdir/${obj}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # Create the old-style object. + reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test + + output="$obj" + cmds=$reload_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + exit $EXIT_SUCCESS + fi + + if test "$build_libtool_libs" != yes; then + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $run eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + fi + + if test -n "$pic_flag" || test "$pic_mode" != default; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output="$libobj" + cmds=$reload_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;; + esac + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for programs" 1>&2 + fi + + if test "$preload" = yes; then + if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown && + test "$dlopen_self_static" = unknown; then + $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support." + fi + fi + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'` + finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'` + ;; + esac + + case $host in + *darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + if test "$tagname" = CXX ; then + compile_command="$compile_command ${wl}-bind_at_load" + finalize_command="$finalize_command ${wl}-bind_at_load" + fi + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + compile_deplibs="$new_libs" + + + compile_command="$compile_command $compile_deplibs" + finalize_command="$finalize_command $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + *) dllsearchpath="$dllsearchpath:$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath="$rpath" + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath="$rpath" + + if test -n "$libobjs" && test "$build_old_libs" = yes; then + # Transform all the library objects into standard objects. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + fi + + dlsyms= + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + dlsyms="${outputname}S.c" + else + $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 + fi + fi + + if test -n "$dlsyms"; then + case $dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist="$output_objdir/${outputname}.nm" + + $show "$rm $nlist ${nlist}S ${nlist}T" + $run $rm "$nlist" "${nlist}S" "${nlist}T" + + # Parse the name list into a source file. + $show "creating $output_objdir/$dlsyms" + + test -z "$run" && $echo > "$output_objdir/$dlsyms" "\ +/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */ +/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +/* Prevent the only kind of declaration conflicts we can make. */ +#define lt_preloaded_symbols some_other_symbol + +/* External symbol declarations for the compiler. */\ +" + + if test "$dlself" = yes; then + $show "generating symbol list for \`$output'" + + test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + for arg in $progfiles; do + $show "extracting global C symbols from \`$arg'" + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + $run eval '$mv "$nlist"T "$nlist"' + fi + + if test -n "$export_symbols_regex"; then + $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + $run eval '$mv "$nlist"T "$nlist"' + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols="$output_objdir/$outputname.exp" + $run $rm $export_symbols + $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* ) + $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + $run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + else + $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + $run eval 'mv "$nlist"T "$nlist"' + case $host in + *cygwin* | *mingw* ) + $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + $run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + fi + fi + + for arg in $dlprefiles; do + $show "extracting global C symbols from \`$arg'" + name=`$echo "$arg" | ${SED} -e 's%^.*/%%'` + $run eval '$echo ": $name " >> "$nlist"' + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + + if test -z "$run"; then + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $mv "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if grep -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + grep -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"' + else + $echo '/* NONE */' >> "$output_objdir/$dlsyms" + fi + + $echo >> "$output_objdir/$dlsyms" "\ + +#undef lt_preloaded_symbols + +#if defined (__STDC__) && __STDC__ +# define lt_ptr void * +#else +# define lt_ptr char * +# define const +#endif + +/* The mapping between symbol names and symbols. */ +" + + case $host in + *cygwin* | *mingw* ) + $echo >> "$output_objdir/$dlsyms" "\ +/* DATA imports from DLLs on WIN32 can't be const, because + runtime relocations are performed -- see ld's documentation + on pseudo-relocs */ +struct { +" + ;; + * ) + $echo >> "$output_objdir/$dlsyms" "\ +const struct { +" + ;; + esac + + + $echo >> "$output_objdir/$dlsyms" "\ + const char *name; + lt_ptr address; +} +lt_preloaded_symbols[] = +{\ +" + + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms" + + $echo >> "$output_objdir/$dlsyms" "\ + {0, (lt_ptr) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + fi + + pic_flag_for_symtable= + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + case "$compile_command " in + *" -static "*) ;; + *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";; + esac;; + *-*-hpux*) + case "$compile_command " in + *" -static "*) ;; + *) pic_flag_for_symtable=" $pic_flag";; + esac + esac + + # Now compile the dynamic symbol file. + $show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")" + $run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $? + + # Clean up the generated files. + $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T" + $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T" + + # Transform the symbol file into the correct name. + case $host in + *cygwin* | *mingw* ) + if test -f "$output_objdir/${outputname}.def" ; then + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` + else + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + fi + ;; + * ) + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + ;; + esac + ;; + *) + $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 + exit $EXIT_FAILURE + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` + fi + + if test "$need_relink" = no || test "$build_libtool_libs" != yes; then + # Replace the output file specification. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$output"'%g' | $NL2SP` + link_command="$compile_command$compile_rpath" + + # We have no uninstalled library dependencies, so finalize right now. + $show "$link_command" + $run eval "$link_command" + exit_status=$? + + # Delete the generated files. + if test -n "$dlsyms"; then + $show "$rm $output_objdir/${outputname}S.${objext}" + $run $rm "$output_objdir/${outputname}S.${objext}" + fi + + exit $exit_status + fi + + if test -n "$shlibpath_var"; then + # We should set the shlibpath_var + rpath= + for dir in $temp_rpath; do + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) + # Absolute path. + rpath="$rpath$dir:" + ;; + *) + # Relative path: add a thisdir entry. + rpath="$rpath\$thisdir/$dir:" + ;; + esac + done + temp_rpath="$rpath" + fi + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + rpath="$rpath$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test "$no_install" = yes; then + # We don't need to create a wrapper script. + link_command="$compile_var$compile_command$compile_rpath" + # Replace the output file specification. + link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $run $rm $output + # Link the executable and exit + $show "$link_command" + $run eval "$link_command" || exit $? + exit $EXIT_SUCCESS + fi + + if test "$hardcode_action" = relink; then + # Fast installation is not supported + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + + $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2 + $echo "$modename: \`$output' will be relinked during installation" 1>&2 + else + if test "$fast_install" != no; then + link_command="$finalize_var$compile_command$finalize_rpath" + if test "$fast_install" = yes; then + relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $SP2NL | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g' | $NL2SP` + else + # fast_install is set to needless + relink_command= + fi + else + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + fi + fi + + # Replace the output file specification. + link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname + + $show "$link_command" + $run eval "$link_command" || exit $? + + # Now create the wrapper script. + $show "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` + relink_command="$var=\"$var_value\"; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` + fi + + # Quote $echo for shipping. + if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then + case $progpath in + [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; + *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; + esac + qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"` + else + qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"` + fi + + # Only actually do things if our run command is non-null. + if test -z "$run"; then + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + output_name=`basename $output` + output_path=`dirname $output` + cwrappersource="$output_path/$objdir/lt-$output_name.c" + cwrapper="$output_path/$output_name.exe" + $rm $cwrappersource $cwrapper + trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + cat > $cwrappersource <> $cwrappersource<<"EOF" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(PATH_MAX) +# define LT_PATHMAX PATH_MAX +#elif defined(MAXPATHLEN) +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ + defined (__OS2__) +# define HAVE_DOS_BASED_FILE_SYSTEM +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free ((void *) stale); stale = 0; } \ +} while (0) + +/* -DDEBUG is fairly common in CFLAGS. */ +#undef DEBUG +#if defined DEBUGWRAPPER +# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__) +#else +# define DEBUG(format, ...) +#endif + +const char *program_name = NULL; + +void * xmalloc (size_t num); +char * xstrdup (const char *string); +const char * base_name (const char *name); +char * find_executable(const char *wrapper); +int check_executable(const char *path); +char * strendzap(char *str, const char *pat); +void lt_fatal (const char *message, ...); + +int +main (int argc, char *argv[]) +{ + char **newargz; + int i; + + program_name = (char *) xstrdup (base_name (argv[0])); + DEBUG("(main) argv[0] : %s\n",argv[0]); + DEBUG("(main) program_name : %s\n",program_name); + newargz = XMALLOC(char *, argc+2); +EOF + + cat >> $cwrappersource <> $cwrappersource <<"EOF" + newargz[1] = find_executable(argv[0]); + if (newargz[1] == NULL) + lt_fatal("Couldn't find %s", argv[0]); + DEBUG("(main) found exe at : %s\n",newargz[1]); + /* we know the script has the same name, without the .exe */ + /* so make sure newargz[1] doesn't end in .exe */ + strendzap(newargz[1],".exe"); + for (i = 1; i < argc; i++) + newargz[i+1] = xstrdup(argv[i]); + newargz[argc+1] = NULL; + + for (i=0; i> $cwrappersource <> $cwrappersource <> $cwrappersource <<"EOF" + return 127; +} + +void * +xmalloc (size_t num) +{ + void * p = (void *) malloc (num); + if (!p) + lt_fatal ("Memory exhausted"); + + return p; +} + +char * +xstrdup (const char *string) +{ + return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL +; +} + +const char * +base_name (const char *name) +{ + const char *base; + +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + /* Skip over the disk name in MSDOS pathnames. */ + if (isalpha ((unsigned char)name[0]) && name[1] == ':') + name += 2; +#endif + + for (base = name; *name; name++) + if (IS_DIR_SEPARATOR (*name)) + base = name + 1; + return base; +} + +int +check_executable(const char * path) +{ + struct stat st; + + DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!"); + if ((!path) || (!*path)) + return 0; + + if ((stat (path, &st) >= 0) && + ( + /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */ +#if defined (S_IXOTH) + ((st.st_mode & S_IXOTH) == S_IXOTH) || +#endif +#if defined (S_IXGRP) + ((st.st_mode & S_IXGRP) == S_IXGRP) || +#endif + ((st.st_mode & S_IXUSR) == S_IXUSR)) + ) + return 1; + else + return 0; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise */ +char * +find_executable (const char* wrapper) +{ + int has_slash = 0; + const char* p; + const char* p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + int tmp_len; + char* concat_name; + + DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char* path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char* q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR(*q)) + break; + p_len = q - p; + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen(tmp); + concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen(tmp); + concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + return NULL; +} + +char * +strendzap(char *str, const char *pat) +{ + size_t len, patlen; + + assert(str != NULL); + assert(pat != NULL); + + len = strlen(str); + patlen = strlen(pat); + + if (patlen <= len) + { + str += len - patlen; + if (strcmp(str, pat) == 0) + *str = '\0'; + } + return str; +} + +static void +lt_error_core (int exit_status, const char * mode, + const char * message, va_list ap) +{ + fprintf (stderr, "%s: %s: ", program_name, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, "FATAL", message, ap); + va_end (ap); +} +EOF + # we should really use a build-platform specific compiler + # here, but OTOH, the wrappers (shell script and this C one) + # are only useful if you want to execute the "real" binary. + # Since the "real" binary is built for $host, then this + # wrapper might as well be built for $host, too. + $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource + ;; + esac + $rm $output + trap "$rm $output; exit $EXIT_FAILURE" 1 2 15 + + $echo > $output "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='${SED} -e 1s/^X//' +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variable: + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$echo are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + echo=\"$qecho\" + file=\"\$0\" + # Make sure echo works. + if test \"X\$1\" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then + # Yippee, \$echo works! + : + else + # Restart under the correct shell, and then maybe \$echo will work. + exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} + fi + fi\ +" + $echo >> $output "\ + + # Find the directory that this script lives in. + thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` + done + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test "$fast_install" = yes; then + $echo >> $output "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || \\ + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $mkdir \"\$progdir\" + else + $rm \"\$progdir/\$file\" + fi" + + $echo >> $output "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + $echo \"\$relink_command_output\" >&2 + $rm \"\$progdir/\$file\" + exit $EXIT_FAILURE + fi + fi + + $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $rm \"\$progdir/\$program\"; + $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $rm \"\$progdir/\$file\" + fi" + else + $echo >> $output "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $echo >> $output "\ + + if test -f \"\$progdir/\$program\"; then" + + # Export our shlibpath_var if we have one. + if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $echo >> $output "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` + + export $shlibpath_var +" + fi + + # fixup the dll searchpath if we need to. + if test -n "$dllsearchpath"; then + $echo >> $output "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + $echo >> $output "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2*) + $echo >> $output "\ + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $echo >> $output "\ + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $echo >> $output "\ + \$echo \"\$0: cannot exec \$program \$*\" + exit $EXIT_FAILURE + fi + else + # The program doesn't exist. + \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 + \$echo \"This script is just a wrapper for \$program.\" 1>&2 + $echo \"See the $PACKAGE documentation for more information.\" 1>&2 + exit $EXIT_FAILURE + fi +fi\ +" + chmod +x $output + fi + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + if test "$build_libtool_libs" = convenience; then + oldobjs="$libobjs_save" + addlibs="$convenience" + build_libtool_libs=no + else + if test "$build_libtool_libs" = module; then + oldobjs="$libobjs_save" + build_libtool_libs=no + else + oldobjs="$old_deplibs $non_pic_objects" + fi + addlibs="$old_convenience" + fi + + if test -n "$addlibs"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $addlibs + oldobjs="$oldobjs $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then + cmds=$old_archive_from_new_cmds + else + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + $echo "X$obj" | $Xsed -e 's%^.*/%%' + done | sort | sort -uc >/dev/null 2>&1); then + : + else + $echo "copying selected object files to avoid basename conflicts..." + + if test -z "$gentop"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + $show "${rm}r $gentop" + $run ${rm}r "$gentop" + $show "$mkdir $gentop" + $run $mkdir "$gentop" + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$gentop"; then + exit $exit_status + fi + fi + + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + counter=`expr $counter + 1` + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + $run ln "$obj" "$gentop/$newobj" || + $run cp "$obj" "$gentop/$newobj" + oldobjs="$oldobjs $gentop/$newobj" + ;; + *) oldobjs="$oldobjs $obj" ;; + esac + done + fi + + eval cmds=\"$old_archive_cmds\" + + if len=`expr "X$cmds" : ".*"` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + $echo "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + for obj in $save_oldobjs + do + oldobjs="$objlist $obj" + objlist="$objlist $obj" + eval test_cmds=\"$old_archive_cmds\" + if len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj" ; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" + objlist= + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test "X$oldobjs" = "X" ; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + eval cmd=\"$cmd\" + IFS="$save_ifs" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + done + + if test -n "$generated"; then + $show "${rm}r$generated" + $run ${rm}r$generated + fi + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test "$build_old_libs" = yes && old_library="$libname.$libext" + $show "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` + relink_command="$var=\"$var_value\"; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` + if test "$hardcode_automatic" = yes ; then + relink_command= + fi + + + # Only create the output if not a dry run. + if test -z "$run"; then + for installed in no yes; do + if test "$installed" = yes; then + if test -z "$install_libdir"; then + break + fi + output="$output_objdir/$outputname"i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + if test -z "$libdir"; then + $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdependency_libs="$newdependency_libs $libdir/$name" + ;; + *) newdependency_libs="$newdependency_libs $deplib" ;; + esac + done + dependency_libs="$newdependency_libs" + newdlfiles= + for lib in $dlfiles; do + name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + if test -z "$libdir"; then + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdlfiles="$newdlfiles $libdir/$name" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + if test -z "$libdir"; then + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdlprefiles="$newdlprefiles $libdir/$name" + done + dlprefiles="$newdlprefiles" + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlfiles="$newdlfiles $abs" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlprefiles="$newdlprefiles $abs" + done + dlprefiles="$newdlprefiles" + fi + $rm $output + # place dlname in correct position for cygwin + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; + esac + $echo > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test "$installed" = no && test "$need_relink" = yes; then + $echo >> $output "\ +relink_command=\"$relink_command\"" + fi + done + fi + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)" + $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $? + ;; + esac + exit $EXIT_SUCCESS + ;; + + # libtool install mode + install) + modename="$modename: install" + + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || + # Allow the use of GNU shtool's install command. + $echo "X$nonopt" | grep shtool > /dev/null; then + # Aesthetically quote it. + arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$arg " + arg="$1" + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$install_prog$arg" + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=no + stripme= + for arg + do + if test -n "$dest"; then + files="$files $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=yes ;; + -f) + case " $install_prog " in + *[\\\ /]cp\ *) ;; + *) prev=$arg ;; + esac + ;; + -g | -m | -o) prev=$arg ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$install_prog $arg" + done + + if test -z "$install_prog"; then + $echo "$modename: you must specify an install program" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test -n "$prev"; then + $echo "$modename: the \`$prev' option requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test -z "$files"; then + if test -z "$dest"; then + $echo "$modename: no file or destination specified" 1>&2 + else + $echo "$modename: you must specify a destination" 1>&2 + fi + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Strip any trailing slash from the destination. + dest=`$echo "X$dest" | $Xsed -e 's%/$%%'` + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=yes + if test "$isdir" = yes; then + destdir="$dest" + destname= + else + destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'` + test "X$destdir" = "X$dest" && destdir=. + destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'` + + # Not a directory, so check to see that there is only one file specified. + set dummy $files + if test "$#" -gt 2; then + $echo "$modename: \`$dest' is not a directory" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + staticlibs="$staticlibs $file" + ;; + + *.la) + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$file' is not a valid libtool archive" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + library_names= + old_library= + relink_command= + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) current_libdirs="$current_libdirs $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) future_libdirs="$future_libdirs $libdir" ;; + esac + fi + + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/ + test "X$dir" = "X$file/" && dir= + dir="$dir$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + if test "$inst_prefix_dir" = "$destdir"; then + $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 + exit $EXIT_FAILURE + fi + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%" | $NL2SP` + else + relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%%" | $NL2SP` + fi + + $echo "$modename: warning: relinking \`$file'" 1>&2 + $show "$relink_command" + if $run eval "$relink_command"; then : + else + $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 + exit $EXIT_FAILURE + fi + fi + + # See the names of the shared library. + set dummy $library_names + if test -n "$2"; then + realname="$2" + shift + shift + + srcname="$realname" + test -n "$relink_command" && srcname="$realname"T + + # Install the shared library and build the symlinks. + $show "$install_prog $dir/$srcname $destdir/$realname" + $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $? + if test -n "$stripme" && test -n "$striplib"; then + $show "$striplib $destdir/$realname" + $run eval "$striplib $destdir/$realname" || exit $? + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try `ln -sf' first, because the `ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + if test "$linkname" != "$realname"; then + $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" + $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" + fi + done + fi + + # Do each command in the postinstall commands. + lib="$destdir/$realname" + cmds=$postinstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + fi + + # Install the pseudo-library for information purposes. + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + instname="$dir/$name"i + $show "$install_prog $instname $destdir/$name" + $run eval "$install_prog $instname $destdir/$name" || exit $? + + # Maybe install the static library, too. + test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + destfile="$destdir/$destfile" + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"` + ;; + *.$objext) + staticdest="$destfile" + destfile= + ;; + *) + $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + # Install the libtool object if requested. + if test -n "$destfile"; then + $show "$install_prog $file $destfile" + $run eval "$install_prog $file $destfile" || exit $? + fi + + # Install the old object if enabled. + if test "$build_old_libs" = yes; then + # Deduce the name of the old-style object file. + staticobj=`$echo "X$file" | $Xsed -e "$lo2o"` + + $show "$install_prog $staticobj $staticdest" + $run eval "$install_prog \$staticobj \$staticdest" || exit $? + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + destfile="$destdir/$destfile" + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext="" + case $file in + *.exe) + if test ! -f "$file"; then + file=`$echo $file|${SED} 's,.exe$,,'` + stripped_ext=".exe" + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin*|*mingw*) + wrapper=`$echo $file | ${SED} -e 's,.exe$,,'` + ;; + *) + wrapper=$file + ;; + esac + if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then + notinst_deplibs= + relink_command= + + # Note that it is not necessary on cygwin/mingw to append a dot to + # foo even if both foo and FILE.exe exist: automatic-append-.exe + # behavior happens only for exec(3), not for open(2)! Also, sourcing + # `FILE.' does not work on cygwin managed mounts. + # + # If there is no directory component, then add one. + case $wrapper in + */* | *\\*) . ${wrapper} ;; + *) . ./${wrapper} ;; + esac + + # Check the variables that should have been set. + if test -z "$notinst_deplibs"; then + $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2 + exit $EXIT_FAILURE + fi + + finalize=yes + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + # If there is no directory component, then add one. + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + fi + libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test + if test -n "$libdir" && test ! -f "$libfile"; then + $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2 + finalize=no + fi + done + + relink_command= + # Note that it is not necessary on cygwin/mingw to append a dot to + # foo even if both foo and FILE.exe exist: automatic-append-.exe + # behavior happens only for exec(3), not for open(2)! Also, sourcing + # `FILE.' does not work on cygwin managed mounts. + # + # If there is no directory component, then add one. + case $wrapper in + */* | *\\*) . ${wrapper} ;; + *) . ./${wrapper} ;; + esac + + outputname= + if test "$fast_install" = no && test -n "$relink_command"; then + if test "$finalize" = yes && test -z "$run"; then + tmpdir=`func_mktempdir` + file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` + outputname="$tmpdir/$file" + # Replace the output file specification. + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g' | $NL2SP` + + $show "$relink_command" + if $run eval "$relink_command"; then : + else + $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 + ${rm}r "$tmpdir" + continue + fi + file="$outputname" + else + $echo "$modename: warning: cannot relink \`$file'" 1>&2 + fi + else + # Install the binary that we compiled earlier. + file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'` + ;; + esac + ;; + esac + $show "$install_prog$stripme $file $destfile" + $run eval "$install_prog\$stripme \$file \$destfile" || exit $? + test -n "$outputname" && ${rm}r "$tmpdir" + ;; + esac + done + + for file in $staticlibs; do + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + + # Set up the ranlib parameters. + oldlib="$destdir/$name" + + $show "$install_prog $file $oldlib" + $run eval "$install_prog \$file \$oldlib" || exit $? + + if test -n "$stripme" && test -n "$old_striplib"; then + $show "$old_striplib $oldlib" + $run eval "$old_striplib $oldlib" || exit $? + fi + + # Do each command in the postinstall commands. + cmds=$old_postinstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + done + + if test -n "$future_libdirs"; then + $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2 + fi + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + test -n "$run" && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi + ;; + + # libtool finish mode + finish) + modename="$modename: finish" + libdirs="$nonopt" + admincmds= + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for dir + do + libdirs="$libdirs $dir" + done + + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + cmds=$finish_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || admincmds="$admincmds + $cmd" + done + IFS="$save_ifs" + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $run eval "$cmds" || admincmds="$admincmds + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + test "$show" = : && exit $EXIT_SUCCESS + + $echo "X----------------------------------------------------------------------" | $Xsed + $echo "Libraries have been installed in:" + for libdir in $libdirs; do + $echo " $libdir" + done + $echo + $echo "If you ever happen to want to link against installed libraries" + $echo "in a given directory, LIBDIR, you must either use libtool, and" + $echo "specify the full pathname of the library, or use the \`-LLIBDIR'" + $echo "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + $echo " - add LIBDIR to the \`$shlibpath_var' environment variable" + $echo " during execution" + fi + if test -n "$runpath_var"; then + $echo " - add LIBDIR to the \`$runpath_var' environment variable" + $echo " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $echo " - use the \`$flag' linker flag" + fi + if test -n "$admincmds"; then + $echo " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" + fi + $echo + $echo "See any operating system documentation about shared libraries for" + $echo "more information, such as the ld(1) and ld.so(8) manual pages." + $echo "X----------------------------------------------------------------------" | $Xsed + exit $EXIT_SUCCESS + ;; + + # libtool execute mode + execute) + modename="$modename: execute" + + # The first argument is the command name. + cmd="$nonopt" + if test -z "$cmd"; then + $echo "$modename: you must specify a COMMAND" 1>&2 + $echo "$help" + exit $EXIT_FAILURE + fi + + # Handle -dlopen flags immediately. + for file in $execute_dlfiles; do + if test ! -f "$file"; then + $echo "$modename: \`$file' is not a file" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + dir= + case $file in + *.la) + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Read the libtool library. + dlname= + library_names= + + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'" + continue + fi + + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$file" && dir=. + + if test -f "$dir/$objdir/$dlname"; then + dir="$dir/$objdir" + else + if test ! -f "$dir/$dlname"; then + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE + fi + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$file" && dir=. + ;; + + *) + $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2 + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir="$absdir" + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic="$magic" + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -*) ;; + *) + # Do a test to see if this is really a libtool program. + if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Transform arg to wrapped name. + file="$progdir/$program" + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"` + args="$args \"$file\"" + done + + if test -z "$run"; then + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + fi" + done + + # Now prepare to actually exec the command. + exec_cmd="\$cmd$args" + else + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\"" + $echo "export $shlibpath_var" + fi + $echo "$cmd$args" + exit $EXIT_SUCCESS + fi + ;; + + # libtool clean and uninstall mode + clean | uninstall) + modename="$modename: $mode" + rm="$nonopt" + files= + rmforce= + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + for arg + do + case $arg in + -f) rm="$rm $arg"; rmforce=yes ;; + -*) rm="$rm $arg" ;; + *) files="$files $arg" ;; + esac + done + + if test -z "$rm"; then + $echo "$modename: you must specify an RM program" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + rmdirs= + + origobjdir="$objdir" + for file in $files; do + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + if test "X$dir" = "X$file"; then + dir=. + objdir="$origobjdir" + else + objdir="$dir/$origobjdir" + fi + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + test "$mode" = uninstall && objdir="$dir" + + # Remember objdir for removal later, being careful to avoid duplicates + if test "$mode" = clean; then + case " $rmdirs " in + *" $objdir "*) ;; + *) rmdirs="$rmdirs $objdir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if (test -L "$file") >/dev/null 2>&1 \ + || (test -h "$file") >/dev/null 2>&1 \ + || test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif test "$rmforce" = yes; then + continue + fi + + rmfiles="$file" + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + . $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + rmfiles="$rmfiles $objdir/$n" + done + test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" + + case "$mode" in + clean) + case " $library_names " in + # " " in the beginning catches empty $dlname + *" $dlname "*) ;; + *) rmfiles="$rmfiles $objdir/$dlname" ;; + esac + test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + cmds=$postuninstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" + if test "$?" -ne 0 && test "$rmforce" != yes; then + exit_status=1 + fi + done + IFS="$save_ifs" + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + cmds=$old_postuninstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" + if test "$?" -ne 0 && test "$rmforce" != yes; then + exit_status=1 + fi + done + IFS="$save_ifs" + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + + # Read the .lo file + . $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" \ + && test "$pic_object" != none; then + rmfiles="$rmfiles $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" \ + && test "$non_pic_object" != none; then + rmfiles="$rmfiles $dir/$non_pic_object" + fi + fi + ;; + + *) + if test "$mode" = clean ; then + noexename=$name + case $file in + *.exe) + file=`$echo $file|${SED} 's,.exe$,,'` + noexename=`$echo $name|${SED} 's,.exe$,,'` + # $file with .exe has already been added to rmfiles, + # add $file without .exe + rmfiles="$rmfiles $file" + ;; + esac + # Do a test to see if this is a libtool program. + if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + relink_command= + . $dir/$noexename + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" + if test "$fast_install" = yes && test -n "$relink_command"; then + rmfiles="$rmfiles $objdir/lt-$name" + fi + if test "X$noexename" != "X$name" ; then + rmfiles="$rmfiles $objdir/lt-${noexename}.c" + fi + fi + fi + ;; + esac + $show "$rm $rmfiles" + $run $rm $rmfiles || exit_status=1 + done + objdir="$origobjdir" + + # Try to remove the ${objdir}s in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + $show "rmdir $dir" + $run rmdir $dir >/dev/null 2>&1 + fi + done + + exit $exit_status + ;; + + "") + $echo "$modename: you must specify a MODE" 1>&2 + $echo "$generic_help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + if test -z "$exec_cmd"; then + $echo "$modename: invalid operation mode \`$mode'" 1>&2 + $echo "$generic_help" 1>&2 + exit $EXIT_FAILURE + fi +fi # test -z "$show_help" + +if test -n "$exec_cmd"; then + eval exec $exec_cmd + exit $EXIT_FAILURE +fi + +# We need to display help for each of the modes. +case $mode in +"") $echo \ +"Usage: $modename [OPTION]... [MODE-ARG]... + +Provide generalized library-building support services. + + --config show all configuration variables + --debug enable verbose shell tracing +-n, --dry-run display commands without modifying any files + --features display basic configuration information and exit + --finish same as \`--mode=finish' + --help display this help message and exit + --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS] + --quiet same as \`--silent' + --silent don't print informational messages + --tag=TAG use configuration variables from tag TAG + --version print version information + +MODE must be one of the following: + + clean remove files from the build directory + compile compile a source file into a libtool object + execute automatically set library path, then run a program + finish complete the installation of libtool libraries + install install libraries or executables + link create a library or an executable + uninstall remove libraries from an installed directory + +MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for +a more detailed description of MODE. + +Report bugs to ." + exit $EXIT_SUCCESS + ;; + +clean) + $echo \ +"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + +compile) + $echo \ +"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -prefer-pic try to building PIC objects only + -prefer-non-pic try to building non-PIC objects only + -static always build a \`.o' file suitable for static linking + +COMPILE-COMMAND is a command to be used in creating a \`standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix \`.c' with the +library object suffix, \`.lo'." + ;; + +execute) + $echo \ +"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to \`-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + +finish) + $echo \ +"Usage: $modename [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the \`--dry-run' option if you just want to see what would be executed." + ;; + +install) + $echo \ +"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the \`install' or \`cp' program. + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + +link) + $echo \ +"Usage: $modename [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE Use a list of object files found in FILE to specify objects + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + +All other options (arguments beginning with \`-') are ignored. + +Every other argument is treated as a filename. Files ending in \`.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in \`.la', then a libtool library is created, +only library objects (\`.lo' files) may be specified, and \`-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created +using \`ar' and \`ranlib', or on Windows using \`lib'. + +If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file +is created, otherwise an executable program is created." + ;; + +uninstall) + $echo \ +"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + +*) + $echo "$modename: invalid operation mode \`$mode'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; +esac + +$echo +$echo "Try \`$modename --help' for more information about other modes." + +exit $? + +# The TAGs below are defined such that we never get into a situation +# in which we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +disable_libs=shared +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +disable_libs=static +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff --git a/libs/openzap/build/missing b/libs/openzap/build/missing new file mode 100755 index 0000000000..e7ef83a1c2 --- /dev/null +++ b/libs/openzap/build/missing @@ -0,0 +1,360 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. + +scriptversion=2003-09-02.23 + +# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 +# Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# 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, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +msg="missing on your system" + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + # Exit code 63 means version mismatch. This often happens + # when the user try to use an ancient version of a tool on + # a file that requires a minimum version. In this case we + # we should proceed has if the program had been absent, or + # if --run hadn't been passed. + if test $? = 63; then + run=: + msg="probably too old" + fi + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch] + +Send bug reports to ." + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing $scriptversion (GNU Automake)" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, but is $msg. + You might have modified some files without having the + proper tools for further handling them. + You can get \`$1' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' $msg. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and is $msg. + You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequisites for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index e04cbe7200..aff46c9a36 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -5,14 +5,23 @@ AC_PREREQ(2.59) AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) AC_CONFIG_SRCDIR([src/libteletone_detect.c]) +AC_CONFIG_AUX_DIR(build) +#AM_INIT_AUTOMAKE(libopenzap,0.1) + # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET -AC_PROG_RANLIB - AC_PREFIX_DEFAULT(/usr/local/openzap) +#override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) +m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) +m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) +m4_defun([_LT_AC_LANG_RC_CONFIG], [:]) +#AM_PROG_CC_C_O +AC_PROG_LIBTOOL +AC_PROG_INSTALL + # Check for com;iler type AC_DEFUN([AX_COMPILER_VENDOR], [ @@ -48,6 +57,40 @@ sun) ;; esac + +#set SOLINK variable based on compiler and host +if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then + SOLINK="-Bdynamic -dy -G" +elif test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then + case "$host" in + *darwin*) + SOLINK="-dynamic -bundle -force-flat-namespace" + ;; + *-solaris2*) + SOLINK="-shared -Xlinker" + ;; + *) + SOLINK="-shared -Xlinker -x" + ;; + esac +else + AC_ERROR([Please update configure.in with SOLINK values for your compiler]) +fi + +# set DYNAMIC_LIB_EXTEN +# we should really be using libtool so we don't need to do this +case "$host" in + *cygwin* | *mingw*) + DYNAMIC_LIB_EXTEN="dll" + ;; + *) + DYNAMIC_LIB_EXTEN="so" + ;; +esac + +AC_SUBST(SOLINK) +AC_SUBST(DYNAMIC_LIB_EXTEN) + AC_CHECK_LIB([dl], [dlopen]) AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([m], [cos]) diff --git a/libs/openzap/src/detect_dtmf.c b/libs/openzap/src/detect_dtmf.c index 941237b464..f73586adcb 100644 --- a/libs/openzap/src/detect_dtmf.c +++ b/libs/openzap/src/detect_dtmf.c @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) teletone_dtmf_detect_init (&dtmf_detect, 8000); if ((fd = open(argv[1], O_RDONLY)) < 0) { - fprintf(stderr, "File Error!\n", strerror(errno)); + fprintf(stderr, "File Error! [%s]\n", strerror(errno)); exit(-1); } @@ -28,5 +28,6 @@ int main(int argc, char *argv[]) } } close(fd); + return 0; } diff --git a/libs/openzap/src/detect_tones.c b/libs/openzap/src/detect_tones.c index c5d475edc3..580f6a9d17 100644 --- a/libs/openzap/src/detect_tones.c +++ b/libs/openzap/src/detect_tones.c @@ -3,9 +3,8 @@ int main(int argc, char *argv[]) { - teletone_generation_session_t ts; teletone_multi_tone_t mt = {0}; - teletone_tone_map_t map = {0}; + teletone_tone_map_t map = {{0}}; int fd, b; short sln[512] = {0}; @@ -15,14 +14,12 @@ int main(int argc, char *argv[]) exit(-1); } - map.freqs[0] = atof("350"); map.freqs[1] = atof("440"); teletone_multi_tone_init(&mt, &map); - if ((fd = open(argv[1], O_RDONLY)) < 0) { - fprintf(stderr, "File Error!\n", strerror(errno)); + fprintf(stderr, "File Error! [%s]\n", strerror(errno)); exit(-1); } @@ -30,5 +27,6 @@ int main(int argc, char *argv[]) printf("TEST %d %d\n", b, teletone_multi_tone_detect(&mt, sln, b / 2)); } close(fd); + return 0; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d65b9ef68e..03f58b6da0 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -533,9 +533,9 @@ zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen); +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); zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number); +zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index dd91c639d9..d816edb3be 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -6,14 +6,14 @@ 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, "5551212"); + zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, number); while (chan->state == ZAP_CHANNEL_STATE_UP) { zap_wait_flag_t flags = ZAP_READ; @@ -37,8 +37,8 @@ static void *test_call(zap_thread_t *me, void *obj) } zap_log(ZAP_LOG_DEBUG, "call over\n"); - - return 0; + free(number); + return NULL; } static ZIO_SIGNAL_CB_FUNCTION(on_signal) @@ -59,12 +59,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) } static int R = 0; +#if 0 static void handle_SIGINT(int sig) { if (sig); R = 0; return; } +#endif int main(int argc, char *argv[]) { @@ -113,7 +115,7 @@ int main(int argc, char *argv[]) done: zap_global_destroy(); - + return 0; } /* For Emacs: diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 4f00ca600b..3a706edc95 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -67,10 +67,8 @@ int main(int argc, char *argv[]) goto top; } - end: - zap_global_destroy(); - + return 0; } /* For Emacs: diff --git a/libs/openzap/src/testboost.c b/libs/openzap/src/testboost.c index e585fcbb1d..4838f54def 100644 --- a/libs/openzap/src/testboost.c +++ b/libs/openzap/src/testboost.c @@ -6,13 +6,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) } 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; @@ -59,6 +60,7 @@ int main(int argc, char *argv[]) zap_global_destroy(); + return 0; } /* For Emacs: diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index d374a34081..0dd923393e 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -1,4 +1,5 @@ #include "openzap.h" +zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data); struct helper { int fd; @@ -7,8 +8,6 @@ struct helper { zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) { - int x ; - struct helper *foo = (struct helper *) user_data; write(foo->fd, buf, buflen * 2); foo->wrote += buflen * 2; @@ -28,17 +27,17 @@ int main(int argc, char *argv[]) char fbuf[256]; uint8_t databuf[1024] = ""; struct helper foo = {0}; - int x, bytes, start_bits = 180, stop_bits = 5, sbits = 300; + // 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; - char *url = "sip:cool@rad.com"; + 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!\n", strerror(errno)); + fprintf(stderr, "File Error! [%s]\n", strerror(errno)); exit(-1); } @@ -103,4 +102,5 @@ int main(int argc, char *argv[]) zap_fsk_demod_destroy(&fsk_data); close(fd); + return 0; } diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 7606d4bb74..252f0bcec8 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -58,6 +58,8 @@ int main(int argc, char *argv[]) zap_global_destroy(); + return 1; + } /* For Emacs: diff --git a/libs/openzap/src/testtones.c b/libs/openzap/src/testtones.c index d6b3a68552..2097f26df5 100644 --- a/libs/openzap/src/testtones.c +++ b/libs/openzap/src/testtones.c @@ -26,18 +26,18 @@ int main(int argc, char *argv[]) } if ((tmp.fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { - fprintf(stderr, "File Error!\n", strerror(errno)); + 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[]) diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index e3cb6d9050..97c0f87223 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -47,7 +47,7 @@ zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint3 return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number) +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); @@ -61,7 +61,7 @@ zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen) +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; From ba95f425f7e77f2375469811a2ccb06362860ae5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 05:46:14 +0000 Subject: [PATCH 1030/1766] add some libtool usage in openzap build. This will require re-bootstrap and configure git-svn-id: http://svn.openzap.org/svn/openzap/trunk@534 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 133 +- libs/freetdm/build/config.guess | 1516 ++++++ libs/freetdm/build/config.sub | 1626 +++++++ libs/freetdm/build/install-sh | 322 ++ libs/freetdm/build/ltmain.sh | 6930 ++++++++++++++++++++++++++++ libs/freetdm/build/missing | 360 ++ libs/freetdm/configure.ac | 47 +- libs/freetdm/src/detect_dtmf.c | 3 +- libs/freetdm/src/detect_tones.c | 8 +- libs/freetdm/src/include/openzap.h | 4 +- libs/freetdm/src/testanalog.c | 12 +- libs/freetdm/src/testapp.c | 4 +- libs/freetdm/src/testboost.c | 4 +- libs/freetdm/src/testcid.c | 10 +- libs/freetdm/src/testisdn.c | 2 + libs/freetdm/src/testtones.c | 6 +- libs/freetdm/src/zap_callerid.c | 4 +- 17 files changed, 10892 insertions(+), 99 deletions(-) create mode 100755 libs/freetdm/build/config.guess create mode 100755 libs/freetdm/build/config.sub create mode 100755 libs/freetdm/build/install-sh create mode 100644 libs/freetdm/build/ltmain.sh create mode 100755 libs/freetdm/build/missing diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 808a2b2af6..66fac93825 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -32,14 +32,26 @@ CC = @CC@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXFLAGS = @CXXFLAGS@ DEFS = @DEFS@ -DEPDIR = @DEPDIR@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ LIBS = @LIBS@ +DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ +SOLINK = @SOLINK@ SRC=src +top_builddir=@top_builddir@ +INSTALL=@INSTALL@ +LIBTOOL=@LIBTOOL@ +LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) +LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f +CCLD = $(CC) +PWD=$(shell pwd) +INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost +CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" + +COMPILE = $(CC) $(CFLAGS) $(DEFS) $(INCS) +LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) +LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ + SOURCES=\ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ @@ -154,13 +166,7 @@ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" -MYLIB=libopenzap.so -LIBPRIA=libpri.a -LIBPRI=./libpri -TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w +MYLIB=libopenzap.$(DYNAMIC_LIB_EXTEN) PREFIX=@prefix@ PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) @@ -177,112 +183,99 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) - $(CC) -shared -Wl,-x -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) + $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) -testapp: $(SRC)/testapp.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testapp.c -o testapp -lopenzap $(LIBS) +testapp: $(SRC)/testapp.o $(MYLIB) + $(LINK) $(SRC)/testapp.o ./$(MYLIB) $(LIBS) -testcid: $(SRC)/testcid.c $(MYLIB) - $(CC) $(INCS) -L. -g -ggdb $(SRC)/testcid.c -o testcid -lopenzap $(LIBS) +testcid: $(SRC)/testcid.o $(MYLIB) + $(LINK) $(SRC)/testcid.o ./$(MYLIB) $(LIBS) -testtones: $(SRC)/testtones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testtones.c -o testtones -lopenzap +testtones: $(SRC)/testtones.o $(MYLIB) + $(LINK) $(SRC)/testtones.o ./$(MYLIB) $(LIBS) -detect_tones: $(SRC)/detect_tones.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_tones.c -o detect_tones -lopenzap +detect_tones: $(SRC)/detect_tones.o $(MYLIB) + $(LINK) $(SRC)/detect_tones.o ./$(MYLIB) $(LIBS) -detect_dtmf: $(SRC)/detect_dtmf.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/detect_dtmf.c -o detect_dtmf -lopenzap +detect_dtmf: $(SRC)/detect_dtmf.o $(MYLIB) + $(LINK) $(SRC)/detect_dtmf.o ./$(MYLIB) $(LIBS) -testisdn: $(SRC)/testisdn.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testisdn.c -o testisdn -lopenzap $(LIBS) +testisdn: $(SRC)/testisdn.o $(MYLIB) + $(LINK) $(SRC)/testisdn.o ./$(MYLIB) $(LIBS) -testboost: $(SRC)/testboost.c $(MYLIB) - $(CC) $(INCS) $(ZAP_CFLAGS) -L. $(SRC)/testboost.c -o testboost -lopenzap $(LIBS) +testboost: $(SRC)/testboost.o $(MYLIB) + $(LINK) $(SRC)/testboost.o ./$(MYLIB) $(LIBS) -testanalog: $(SRC)/testanalog.c $(MYLIB) - $(CC) $(INCS) -L. $(SRC)/testanalog.c -o testanalog -lopenzap $(LIBS) - -$(SRC)/priserver.o: $(SRC)/priserver.c - $(CC) $(INCS) $(TMP) -c $(SRC)/priserver.c -o $(SRC)/priserver.o - -$(SRC)/sangoma_pri.o: $(SRC)/sangoma_pri.c - $(CC) $(INCS) $(TMP) -c $(SRC)/sangoma_pri.c -o $(SRC)/sangoma_pri.o - -$(LIBPRI)/$(LIBPRIA): - cd libpri && make - -priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA) - $(CC) $(SRC)/sangoma_pri.o $(SRC)/priserver.o -L. -o priserver -lopenzap $(LIBS) $(LIBPRI)/$(LIBPRIA) +testanalog: $(SRC)/testanalog.o $(MYLIB) + $(LINK) $(SRC)/testanalog.o ./$(MYLIB) $(LIBS) $(SRC)/zap_io.o: $(SRC)/zap_io.c - $(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + $(COMPILE) $(MOD_CFLAGS) -c $< -o $@ %.o: %.c $(HEADERS) - $(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@ + $(COMPILE) -c $< -o $@ dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf -mod_openzap/mod_openzap.so: $(MYLIB) mod_openzap/mod_openzap.c +mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c cd mod_openzap && make -mod_openzap: mod_openzap/mod_openzap.so +mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) mod_openzap-install: mod_openzap cd mod_openzap && make install mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.so ] ; then cd mod_openzap && make clean ; fi + @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi clean: - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf priserver testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.so src/ozmod/*/*.dylib src/ozmod/*/*.dll - @if [ -f $(LIBPRI)/$(LIBPRIA) ] ; then cd $(LIBPRI) && make clean ; fi + rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) install: all @mkdir -p $(DESTDIR)$(PREFIX) @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf) @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @mkdir -p $(DESTDIR)$(PREFIX)/lib - @[ ! -f $(MYLIB) ] || cp -f $(MYLIB) $(DESTDIR)$(PREFIX)/lib + @$(LTINSTALL) $(MYLIB) $(DESTDIR)$(PREFIX)/lib/ @mkdir -p $(DESTDIR)$(PREFIX)/mod @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod - @cp -f src/ozmod/*/*.so $(DESTDIR)$(PREFIX)/mod + @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed uninstall: @rm -fr $(DESTDIR)$(PREFIX) -$(SRC)/ozmod/ozmod_skel/ozmod_skel.so: $(SRC)/ozmod/ozmod_skel/ozmod_skel.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.so -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib -skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.so +$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib +skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_zt/ozmod_zt.so: $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.so +$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.c + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.so +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c + $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_pika/ozmod_pika.so: $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.so -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.c + $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib -pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.so +pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so: $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.so +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) + $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_analog/ozmod_analog.so: $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.so +$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c + $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so: $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib -boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.so +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c + $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) diff --git a/libs/freetdm/build/config.guess b/libs/freetdm/build/config.guess new file mode 100755 index 0000000000..951383e355 --- /dev/null +++ b/libs/freetdm/build/config.guess @@ -0,0 +1,1516 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2007-05-17' + +# This file 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. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:* | ix86xen:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa:Linux:*:*) + echo xtensa-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/libs/freetdm/build/config.sub b/libs/freetdm/build/config.sub new file mode 100755 index 0000000000..c060f44833 --- /dev/null +++ b/libs/freetdm/build/config.sub @@ -0,0 +1,1626 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. + +timestamp='2007-04-29' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fido | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16c) + basic_machine=cr16c-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/libs/freetdm/build/install-sh b/libs/freetdm/build/install-sh new file mode 100755 index 0000000000..b777f1244c --- /dev/null +++ b/libs/freetdm/build/install-sh @@ -0,0 +1,322 @@ +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2004-07-05.00 + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +chmodcmd="$chmodprog 0755" +chowncmd= +chgrpcmd= +stripcmd= +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src= +dst= +dir_arg= +dstarg= +no_target_directory= + +usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: +-c (ignored) +-d create directories instead of installing files. +-g GROUP $chgrpprog installed files to GROUP. +-m MODE $chmodprog installed files to MODE. +-o USER $chownprog installed files to USER. +-s $stripprog installed files. +-t DIRECTORY install into DIRECTORY. +-T report an error if DSTFILE is a directory. +--help display this help and exit. +--version display version info and exit. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG +" + +while test -n "$1"; do + case $1 in + -c) shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + --help) echo "$usage"; exit 0;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t) dstarg=$2 + shift + shift + continue;; + + -T) no_target_directory=true + shift + continue;; + + --version) echo "$0 $scriptversion"; exit 0;; + + *) # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + test -n "$dir_arg$dstarg" && break + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dstarg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dstarg" + shift # fnord + fi + shift # arg + dstarg=$arg + done + break;; + esac +done + +if test -z "$1"; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src ;; + esac + + if test -n "$dir_arg"; then + dst=$src + src= + + if test -d "$dst"; then + mkdircmd=: + chmodcmd= + else + mkdircmd=$mkdirprog + fi + else + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dstarg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dstarg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst ;; + esac + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dstarg: Is a directory" >&2 + exit 1 + fi + dst=$dst/`basename "$src"` + fi + fi + + # This sed command emulates the dirname command. + dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + + # Make sure that the destination directory exists. + + # Skip lots of stat calls in the usual case. + if test ! -d "$dstdir"; then + defaultIFS=' + ' + IFS="${IFS-$defaultIFS}" + + oIFS=$IFS + # Some sh's can't handle IFS=/ for some reason. + IFS='%' + set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + IFS=$oIFS + + pathcomp= + + while test $# -ne 0 ; do + pathcomp=$pathcomp$1 + shift + if test ! -d "$pathcomp"; then + $mkdirprog "$pathcomp" + # mkdir can fail with a `File exist' error in case several + # install-sh are creating the directory concurrently. This + # is OK. + test -d "$pathcomp" || exit + fi + pathcomp=$pathcomp/ + done + fi + + if test -n "$dir_arg"; then + $doit $mkdircmd "$dst" \ + && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } + + else + dstfile=`basename "$dst"` + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 + trap '(exit $?); exit' 1 2 13 15 + + # Copy the file name to the temp name. + $doit $cpprog "$src" "$dsttmp" && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && + + # Now rename the file to the real destination. + { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ + || { + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + if test -f "$dstdir/$dstfile"; then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ + || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ + || { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + } + } + fi || { (exit 1); exit; } +done + +# The final little trick to "correctly" pass the exit status to the exit trap. +{ + (exit 0); exit +} + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/libs/freetdm/build/ltmain.sh b/libs/freetdm/build/ltmain.sh new file mode 100644 index 0000000000..4598ec61cc --- /dev/null +++ b/libs/freetdm/build/ltmain.sh @@ -0,0 +1,6930 @@ +# ltmain.sh - Provide generalized library-building support services. +# NOTE: Changing this file will not affect anything until you rerun configure. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, +# 2007 Free Software Foundation, Inc. +# Originally by Gordon Matzigkeit , 1996 +# +# 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. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +basename="s,^.*/,,g" + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath="$0" + +# The name of this program: +progname=`echo "$progpath" | $SED $basename` +modename="$progname" + +# Global variables: +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +PROGRAM=ltmain.sh +PACKAGE=libtool +VERSION=1.5.24 +TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" + +# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# Check that we have a working $echo. +if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X$1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then + # Yippee, $echo works! + : +else + # Restart under the correct shell, and then maybe $echo will work. + exec $SHELL "$progpath" --no-reexec ${1+"$@"} +fi + +if test "X$1" = X--fallback-echo; then + # used as fallback echo + shift + cat <&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE +fi + +# Global variables. +mode=$default_mode +nonopt= +prev= +prevopt= +run= +show="$echo" +show_help= +execute_dlfiles= +duplicate_deps=no +preserve_args= +lo2o="s/\\.lo\$/.${objext}/" +o2lo="s/\\.${objext}\$/.lo/" +extracted_archives= +extracted_serial=0 + +##################################### +# Shell function definitions: +# This seems to be the best place for them + +# func_mktempdir [string] +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, STRING is the basename for that directory. +func_mktempdir () +{ + my_template="${TMPDIR-/tmp}/${1-$progname}" + + if test "$run" = ":"; then + # Return a directory name, but don't create it in dry-run mode + my_tmpdir="${my_template}-$$" + else + + # If mktemp works, use that first and foremost + my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` + + if test ! -d "$my_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + my_tmpdir="${my_template}-${RANDOM-0}$$" + + save_mktempdir_umask=`umask` + umask 0077 + $mkdir "$my_tmpdir" + umask $save_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$my_tmpdir" || { + $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2 + exit $EXIT_FAILURE + } + fi + + $echo "X$my_tmpdir" | $Xsed +} + + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +func_win32_libid () +{ + win32_libid_type="unknown" + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ + $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then + win32_nmres=`eval $NM -f posix -A $1 | \ + $SED -n -e '1,100{ + / I /{ + s,.*,import, + p + q + } + }'` + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $echo $win32_libid_type +} + + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + CC_quoted="$CC_quoted $arg" + done + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + CC_quoted="$CC_quoted $arg" + done + case "$@ " in + " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + $echo "$modename: unable to infer tagged configuration" + $echo "$modename: specify a tag with \`--tag'" 1>&2 + exit $EXIT_FAILURE +# else +# $echo "$modename: using $tagname tagged configuration" + fi + ;; + esac + fi +} + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + f_ex_an_ar_dir="$1"; shift + f_ex_an_ar_oldlib="$1" + + $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)" + $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $? + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2 + exit $EXIT_FAILURE + fi +} + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + my_gentop="$1"; shift + my_oldlibs=${1+"$@"} + my_oldobjs="" + my_xlib="" + my_xabs="" + my_xdir="" + my_status="" + + $show "${rm}r $my_gentop" + $run ${rm}r "$my_gentop" + $show "$mkdir $my_gentop" + $run $mkdir "$my_gentop" + my_status=$? + if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then + exit $my_status + fi + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'` + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir="$my_gentop/$my_xlib_u" + + $show "${rm}r $my_xdir" + $run ${rm}r "$my_xdir" + $show "$mkdir $my_xdir" + $run $mkdir "$my_xdir" + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then + exit $exit_status + fi + case $host in + *-darwin*) + $show "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + if test -z "$run"; then + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'` + darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null` + if test -n "$darwin_arches"; then + darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + $show "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches ; do + mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}" + lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" + cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" + func_extract_an_archive "`pwd`" "${darwin_base_archive}" + cd "$darwin_curdir" + $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" + done # $darwin_arches + ## Okay now we have a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` + lipo -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + ${rm}r unfat-$$ + cd "$darwin_orig_dir" + else + cd "$darwin_orig_dir" + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + fi # $run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` + done + func_extract_archives_result="$my_oldobjs" +} +# End of Shell function definitions +##################################### + +# Darwin sucks +eval std_shrext=\"$shrext_cmds\" + +disable_libs=no + +# Parse our command line options once, thoroughly. +while test "$#" -gt 0 +do + arg="$1" + shift + + case $arg in + -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + execute_dlfiles) + execute_dlfiles="$execute_dlfiles $arg" + ;; + tag) + tagname="$arg" + preserve_args="${preserve_args}=$arg" + + # Check whether tagname contains only valid characters + case $tagname in + *[!-_A-Za-z0-9,/]*) + $echo "$progname: invalid tag name: $tagname" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $tagname in + CC) + # Don't test for the "default" C tag, as we know, it's there, but + # not specially marked. + ;; + *) + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then + taglist="$taglist $tagname" + # Evaluate the configuration. + eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`" + else + $echo "$progname: ignoring unknown tag $tagname" 1>&2 + fi + ;; + esac + ;; + *) + eval "$prev=\$arg" + ;; + esac + + prev= + prevopt= + continue + fi + + # Have we seen a non-optional argument yet? + case $arg in + --help) + show_help=yes + ;; + + --version) + echo "\ +$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP + +Copyright (C) 2007 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + exit $? + ;; + + --config) + ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath + # Now print the configurations for the tags. + for tagname in $taglist; do + ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath" + done + exit $? + ;; + + --debug) + $echo "$progname: enabling shell trace mode" + set -x + preserve_args="$preserve_args $arg" + ;; + + --dry-run | -n) + run=: + ;; + + --features) + $echo "host: $host" + if test "$build_libtool_libs" = yes; then + $echo "enable shared libraries" + else + $echo "disable shared libraries" + fi + if test "$build_old_libs" = yes; then + $echo "enable static libraries" + else + $echo "disable static libraries" + fi + exit $? + ;; + + --finish) mode="finish" ;; + + --mode) prevopt="--mode" prev=mode ;; + --mode=*) mode="$optarg" ;; + + --preserve-dup-deps) duplicate_deps="yes" ;; + + --quiet | --silent) + show=: + preserve_args="$preserve_args $arg" + ;; + + --tag) + prevopt="--tag" + prev=tag + preserve_args="$preserve_args --tag" + ;; + --tag=*) + set tag "$optarg" ${1+"$@"} + shift + prev=tag + preserve_args="$preserve_args --tag" + ;; + + -dlopen) + prevopt="-dlopen" + prev=execute_dlfiles + ;; + + -*) + $echo "$modename: unrecognized option \`$arg'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + + *) + nonopt="$arg" + break + ;; + esac +done + +if test -n "$prevopt"; then + $echo "$modename: option \`$prevopt' requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE +fi + +case $disable_libs in +no) + ;; +shared) + build_libtool_libs=no + build_old_libs=yes + ;; +static) + build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` + ;; +esac + +# If this variable is set in any of the actions, the command in it +# will be execed at the end. This prevents here-documents from being +# left over by shells. +exec_cmd= + +if test -z "$show_help"; then + + # Infer the operation mode. + if test -z "$mode"; then + $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2 + $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2 + case $nonopt in + *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*) + mode=link + for arg + do + case $arg in + -c) + mode=compile + break + ;; + esac + done + ;; + *db | *dbx | *strace | *truss) + mode=execute + ;; + *install*|cp|mv) + mode=install + ;; + *rm) + mode=uninstall + ;; + *) + # If we have no mode, but dlfiles were specified, then do execute mode. + test -n "$execute_dlfiles" && mode=execute + + # Just use the default operation mode. + if test -z "$mode"; then + if test -n "$nonopt"; then + $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2 + else + $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2 + fi + fi + ;; + esac + fi + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$execute_dlfiles" && test "$mode" != execute; then + $echo "$modename: unrecognized option \`-dlopen'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help="$help" + help="Try \`$modename --help --mode=$mode' for more information." + + # These modes are in order of execution frequency so that they run quickly. + case $mode in + # libtool compile mode + compile) + modename="$modename: compile" + # Get the compilation command and the source file. + base_compile= + srcfile="$nonopt" # always keep a non-empty value in "srcfile" + suppress_opt=yes + suppress_output= + arg_mode=normal + libobj= + later= + + for arg + do + case $arg_mode in + arg ) + # do not "continue". Instead, add this to base_compile + lastarg="$arg" + arg_mode=normal + ;; + + target ) + libobj="$arg" + arg_mode=normal + continue + ;; + + normal ) + # Accept any command-line options. + case $arg in + -o) + if test -n "$libobj" ; then + $echo "$modename: you cannot specify \`-o' more than once" 1>&2 + exit $EXIT_FAILURE + fi + arg_mode=target + continue + ;; + + -static | -prefer-pic | -prefer-non-pic) + later="$later $arg" + continue + ;; + + -no-suppress) + suppress_opt=no + continue + ;; + + -Xcompiler) + arg_mode=arg # the next one goes into the "base_compile" arg list + continue # The current "srcfile" will either be retained or + ;; # replaced later. I would guess that would be a bug. + + -Wc,*) + args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"` + lastarg= + save_ifs="$IFS"; IFS=',' + for arg in $args; do + IFS="$save_ifs" + + # Double-quote args containing other shell metacharacters. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + lastarg="$lastarg $arg" + done + IFS="$save_ifs" + lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"` + + # Add the arguments to base_compile. + base_compile="$base_compile $lastarg" + continue + ;; + + * ) + # Accept the current argument as the source file. + # The previous "srcfile" becomes the current argument. + # + lastarg="$srcfile" + srcfile="$arg" + ;; + esac # case $arg + ;; + esac # case $arg_mode + + # Aesthetically quote the previous argument. + lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"` + + case $lastarg in + # Double-quote args containing other shell metacharacters. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, and some SunOS ksh mistreat backslash-escaping + # in scan sets (worked around with variable expansion), + # and furthermore cannot handle '|' '&' '(' ')' in scan sets + # at all, so we specify them separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + lastarg="\"$lastarg\"" + ;; + esac + + base_compile="$base_compile $lastarg" + done # for arg + + case $arg_mode in + arg) + $echo "$modename: you must specify an argument for -Xcompile" + exit $EXIT_FAILURE + ;; + target) + $echo "$modename: you must specify a target with \`-o'" 1>&2 + exit $EXIT_FAILURE + ;; + *) + # Get the name of the library object. + [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'` + ;; + esac + + # Recognize several different file suffixes. + # If the user specifies -o file.o, it is replaced with file.lo + xform='[cCFSifmso]' + case $libobj in + *.ada) xform=ada ;; + *.adb) xform=adb ;; + *.ads) xform=ads ;; + *.asm) xform=asm ;; + *.c++) xform=c++ ;; + *.cc) xform=cc ;; + *.ii) xform=ii ;; + *.class) xform=class ;; + *.cpp) xform=cpp ;; + *.cxx) xform=cxx ;; + *.[fF][09]?) xform=[fF][09]. ;; + *.for) xform=for ;; + *.java) xform=java ;; + *.obj) xform=obj ;; + esac + + libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` + + case $libobj in + *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;; + *) + $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + func_infer_tag $base_compile + + for arg in $later; do + case $arg in + -static) + build_old_libs=yes + continue + ;; + + -prefer-pic) + pic_mode=yes + continue + ;; + + -prefer-non-pic) + pic_mode=no + continue + ;; + esac + done + + qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"` + case $qlibobj in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qlibobj="\"$qlibobj\"" ;; + esac + test "X$libobj" != "X$qlibobj" \ + && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \ + && $echo "$modename: libobj name \`$libobj' may not contain shell special characters." + objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` + xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$obj"; then + xdir= + else + xdir=$xdir/ + fi + lobj=${xdir}$objdir/$objname + + if test -z "$base_compile"; then + $echo "$modename: you must specify a compilation command" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Delete any leftover library objects. + if test "$build_old_libs" = yes; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + $run $rm $removelist + trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2*) + pic_mode=default + ;; + esac + if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test "$compiler_c_o" = no; then + output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} + lockfile="$output_obj.lock" + removelist="$removelist $output_obj $lockfile" + trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test "$need_locks" = yes; then + until $run ln "$progpath" "$lockfile" 2>/dev/null; do + $show "Waiting for $lockfile to be removed" + sleep 2 + done + elif test "$need_locks" = warn; then + if test -f "$lockfile"; then + $echo "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + $echo "$srcfile" > "$lockfile" + fi + + if test -n "$fix_srcfile_path"; then + eval srcfile=\"$fix_srcfile_path\" + fi + qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"` + case $qsrcfile in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qsrcfile="\"$qsrcfile\"" ;; + esac + + $run $rm "$libobj" "${libobj}T" + + # Create a libtool object file (analogous to a ".la" file), + # but don't create it if we're doing a dry run. + test -z "$run" && cat > ${libobj}T </dev/null`" != "X$srcfile"; then + $echo "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + $show "$mv $output_obj $lobj" + if $run $mv $output_obj $lobj; then : + else + error=$? + $run $rm $removelist + exit $error + fi + fi + + # Append the name of the PIC object to the libtool object file. + test -z "$run" && cat >> ${libobj}T <> ${libobj}T </dev/null`" != "X$srcfile"; then + $echo "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support \`-c' and \`-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $run $rm $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + $show "$mv $output_obj $obj" + if $run $mv $output_obj $obj; then : + else + error=$? + $run $rm $removelist + exit $error + fi + fi + + # Append the name of the non-PIC object the libtool object file. + # Only append if the libtool object file exists. + test -z "$run" && cat >> ${libobj}T <> ${libobj}T <&2 + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg="$1" + shift + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test + ;; + *) qarg=$arg ;; + esac + libtool_args="$libtool_args $qarg" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + compile_command="$compile_command @OUTPUT@" + finalize_command="$finalize_command @OUTPUT@" + ;; + esac + + case $prev in + dlfiles|dlprefiles) + if test "$preload" = no; then + # Add the symbol object into the linking commands. + compile_command="$compile_command @SYMFILE@" + finalize_command="$finalize_command @SYMFILE@" + preload=yes + fi + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test "$dlself" = no; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test "$prev" = dlprefiles; then + dlself=yes + elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test "$prev" = dlfiles; then + dlfiles="$dlfiles $arg" + else + dlprefiles="$dlprefiles $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols="$arg" + if test ! -f "$arg"; then + $echo "$modename: symbol file \`$arg' does not exist" + exit $EXIT_FAILURE + fi + prev= + continue + ;; + expsyms_regex) + export_symbols_regex="$arg" + prev= + continue + ;; + inst_prefix) + inst_prefix_dir="$arg" + prev= + continue + ;; + precious_regex) + precious_files_regex="$arg" + prev= + continue + ;; + release) + release="-$arg" + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat $save_arg` + do +# moreargs="$moreargs $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + pic_object= + non_pic_object= + + # Read the .lo file + # If there is no directory component, then add one. + case $arg in + */* | *\\*) . $arg ;; + *) . ./$arg ;; + esac + + if test -z "$pic_object" || \ + test -z "$non_pic_object" || + test "$pic_object" = none && \ + test "$non_pic_object" = none; then + $echo "$modename: cannot find name of object for \`$arg'" 1>&2 + exit $EXIT_FAILURE + fi + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + libobjs="$libobjs $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + non_pic_objects="$non_pic_objects $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if test -z "$run"; then + $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 + exit $EXIT_FAILURE + else + # Dry-run case. + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` + non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` + libobjs="$libobjs $pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + fi + done + else + $echo "$modename: link input file \`$save_arg' does not exist" + exit $EXIT_FAILURE + fi + arg=$save_arg + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + $echo "$modename: only absolute run-paths are allowed" 1>&2 + exit $EXIT_FAILURE + ;; + esac + if test "$prev" = rpath; then + case "$rpath " in + *" $arg "*) ;; + *) rpath="$rpath $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) xrpath="$xrpath $arg" ;; + esac + fi + prev= + continue + ;; + xcompiler) + compiler_flags="$compiler_flags $qarg" + prev= + compile_command="$compile_command $qarg" + finalize_command="$finalize_command $qarg" + continue + ;; + xlinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $wl$qarg" + prev= + compile_command="$compile_command $wl$qarg" + finalize_command="$finalize_command $wl$qarg" + continue + ;; + xcclinker) + linker_flags="$linker_flags $qarg" + compiler_flags="$compiler_flags $qarg" + prev= + compile_command="$compile_command $qarg" + finalize_command="$finalize_command $qarg" + continue + ;; + shrext) + shrext_cmds="$arg" + prev= + continue + ;; + darwin_framework|darwin_framework_skip) + test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + prev= + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg="$arg" + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + compile_command="$compile_command $link_static_flag" + finalize_command="$finalize_command $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2 + continue + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + $echo "$modename: more than one -exported-symbols argument is not allowed" + exit $EXIT_FAILURE + fi + if test "X$arg" = "X-export-symbols"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework|-arch|-isysroot) + case " $CC " in + *" ${arg} ${1} "* | *" ${arg} ${1} "*) + prev=darwin_framework_skip ;; + *) compiler_flags="$compiler_flags $arg" + prev=darwin_framework ;; + esac + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + ;; + esac + continue + ;; + + -L*) + dir=`$echo "X$arg" | $Xsed -e 's/^-L//'` + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2 + absdir="$dir" + notinst_path="$notinst_path $dir" + fi + dir="$absdir" + ;; + esac + case "$deplibs " in + *" -L$dir "*) ;; + *) + deplibs="$deplibs -L$dir" + lib_search_path="$lib_search_path $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + *) dllsearchpath="$dllsearchpath:$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test "X$arg" = "X-lc" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + test "X$arg" = "X-lc" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + deplibs="$deplibs -framework System" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test "X$arg" = "X-lc" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test "X$arg" = "X-lc" && continue + ;; + esac + elif test "X$arg" = "X-lc_r"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + deplibs="$deplibs $arg" + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + -model) + compile_command="$compile_command $arg" + compiler_flags="$compiler_flags $arg" + finalize_command="$finalize_command $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + compiler_flags="$compiler_flags $arg" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + continue + ;; + + -module) + module=yes + continue + ;; + + # -64, -mips[0-9] enable 64-bit mode on the SGI compiler + # -r[0-9][0-9]* specifies the processor on the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler + # +DA*, +DD* enable 64-bit mode on the HP compiler + # -q* pass through compiler args for the IBM compiler + # -m* pass through architecture-specific compiler args for GCC + # -m*, -t[45]*, -txscale* pass through architecture-specific + # compiler args for GCC + # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC + # -F/path gives path to uninstalled frameworks, gcc on darwin + # @file GCC response files + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) + + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + compiler_flags="$compiler_flags $arg" + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) + # The PATH hackery in wrapper scripts is required on Windows + # and Darwin in order for the loader to find any dlls it needs. + $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 + $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + dir=`$echo "X$arg" | $Xsed -e 's/^-R//'` + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + $echo "$modename: only absolute run-paths are allowed" 1>&2 + exit $EXIT_FAILURE + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -Wc,*) + args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'` + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + case $flag in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + flag="\"$flag\"" + ;; + esac + arg="$arg $wl$flag" + compiler_flags="$compiler_flags $flag" + done + IFS="$save_ifs" + arg=`$echo "X$arg" | $Xsed -e "s/^ //"` + ;; + + -Wl,*) + args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'` + arg= + save_ifs="$IFS"; IFS=',' + for flag in $args; do + IFS="$save_ifs" + case $flag in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + flag="\"$flag\"" + ;; + esac + arg="$arg $wl$flag" + compiler_flags="$compiler_flags $wl$flag" + linker_flags="$linker_flags $flag" + done + IFS="$save_ifs" + arg=`$echo "X$arg" | $Xsed -e "s/^ //"` + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # Some other compiler flag. + -* | +*) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + ;; + + *.$objext) + # A standard object. + objs="$objs $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + pic_object= + non_pic_object= + + # Read the .lo file + # If there is no directory component, then add one. + case $arg in + */* | *\\*) . $arg ;; + *) . ./$arg ;; + esac + + if test -z "$pic_object" || \ + test -z "$non_pic_object" || + test "$pic_object" = none && \ + test "$non_pic_object" = none; then + $echo "$modename: cannot find name of object for \`$arg'" 1>&2 + exit $EXIT_FAILURE + fi + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + if test "$pic_object" != none; then + # Prepend the subdirectory the object is found in. + pic_object="$xdir$pic_object" + + if test "$prev" = dlfiles; then + if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then + dlfiles="$dlfiles $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test "$prev" = dlprefiles; then + # Preload the old-style object. + dlprefiles="$dlprefiles $pic_object" + prev= + fi + + # A PIC object. + libobjs="$libobjs $pic_object" + arg="$pic_object" + fi + + # Non-PIC object. + if test "$non_pic_object" != none; then + # Prepend the subdirectory the object is found in. + non_pic_object="$xdir$non_pic_object" + + # A standard non-PIC object + non_pic_objects="$non_pic_objects $non_pic_object" + if test -z "$pic_object" || test "$pic_object" = none ; then + arg="$non_pic_object" + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object="$pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if test -z "$run"; then + $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 + exit $EXIT_FAILURE + else + # Dry-run case. + + # Extract subdirectory from the argument. + xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$xdir" = "X$arg"; then + xdir= + else + xdir="$xdir/" + fi + + pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` + non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` + libobjs="$libobjs $pic_object" + non_pic_objects="$non_pic_objects $non_pic_object" + fi + fi + ;; + + *.$libext) + # An archive. + deplibs="$deplibs $arg" + old_deplibs="$old_deplibs $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + if test "$prev" = dlfiles; then + # This library was specified with -dlopen. + dlfiles="$dlfiles $arg" + prev= + elif test "$prev" = dlprefiles; then + # The library was specified with -dlpreopen. + dlprefiles="$dlprefiles $arg" + prev= + else + deplibs="$deplibs $arg" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + fi + done # argument parsing loop + + if test -n "$prev"; then + $echo "$modename: the \`$prevarg' option requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + compile_command="$compile_command $arg" + finalize_command="$finalize_command $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'` + libobjs_save="$libobjs" + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'` + if test "X$output_objdir" = "X$output"; then + output_objdir="$objdir" + else + output_objdir="$output_objdir/$objdir" + fi + # Create the object directory. + if test ! -d "$output_objdir"; then + $show "$mkdir $output_objdir" + $run $mkdir $output_objdir + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then + exit $exit_status + fi + fi + + # Determine the type of output + case $output in + "") + $echo "$modename: you must specify an output file" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + case $host in + *cygwin* | *mingw* | *pw32*) + # don't eliminate duplications in $postdeps and $predeps + duplicate_compiler_generated_deps=yes + ;; + *) + duplicate_compiler_generated_deps=$duplicate_deps + ;; + esac + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if test "X$duplicate_deps" = "Xyes" ; then + case "$libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + libs="$libs $deplib" + done + + if test "$linkmode" = lib; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; + esac + pre_post_deps="$pre_post_deps $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + case $linkmode in + lib) + passes="conv link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2 + exit $EXIT_FAILURE + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=no + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + for pass in $passes; do + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan"; then + libs="$deplibs" + deplibs= + fi + if test "$linkmode" = prog; then + case $pass in + dlopen) libs="$dlfiles" ;; + dlpreopen) libs="$dlprefiles" ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + esac + fi + if test "$pass" = dlopen; then + # Collect dlpreopened libraries + save_deplibs="$deplibs" + deplibs= + fi + for deplib in $libs; do + lib= + found=no + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + compiler_flags="$compiler_flags $deplib" + fi + continue + ;; + -l*) + if test "$linkmode" != lib && test "$linkmode" != prog; then + $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2 + continue + fi + name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` + for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib="$searchdir/lib${name}${search_ext}" + if test -f "$lib"; then + if test "$search_ext" = ".la"; then + found=yes + else + found=no + fi + break 2 + fi + done + done + if test "$found" != yes; then + # deplib doesn't seem to be a libtool library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + else # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $deplib "*) + if (${SED} -e '2q' $lib | + grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + library_names= + old_library= + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + for l in $old_library $library_names; do + ll="$l" + done + if test "X$ll" = "X$old_library" ; then # only static version available + found=no + ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` + test "X$ladir" = "X$lib" && ladir="." + lib=$ladir/$old_library + if test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + fi + ;; # -l + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test "$pass" = conv && continue + newdependency_libs="$deplib $newdependency_libs" + newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` + ;; + prog) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + if test "$pass" = scan; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` + ;; + *) + $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2 + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test "$pass" = link; then + dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'` + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) xrpath="$xrpath $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) lib="$deplib" ;; + *.$libext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + valid_a_lib=no + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method + match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` + if eval $echo \"$deplib\" 2>/dev/null \ + | $SED 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=yes + fi + ;; + pass_all) + valid_a_lib=yes + ;; + esac + if test "$valid_a_lib" != yes; then + $echo + $echo "*** Warning: Trying to link with static lib archive $deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because the file extensions .$libext of this argument makes me believe" + $echo "*** that it is just a static archive that I should not used here." + else + $echo + $echo "*** Warning: Linking the shared library $output against the" + $echo "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + fi + continue + ;; + prog) + if test "$pass" != link; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + elif test "$linkmode" = prog; then + if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + newdlprefiles="$newdlprefiles $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + newdlfiles="$newdlfiles $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=yes + continue + ;; + esac # case $deplib + if test "$found" = yes || test -f "$lib"; then : + else + $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2 + exit $EXIT_FAILURE + fi + + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + + ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` + test "X$ladir" = "X$lib" && ladir="." + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + + if test "$linkmode,$pass" = "lib,link" || + test "$linkmode,$pass" = "prog,scan" || + { test "$linkmode" != prog && test "$linkmode" != lib; }; then + test -n "$dlopen" && dlfiles="$dlfiles $dlopen" + test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" + fi + + if test "$pass" = conv; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + # It is a libtool convenience library, so add in its objects. + convenience="$convenience $ladir/$objdir/$old_library" + old_convenience="$old_convenience $ladir/$objdir/$old_library" + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + elif test "$linkmode" != prog && test "$linkmode" != lib; then + $echo "$modename: \`$lib' is not a convenience library" 1>&2 + exit $EXIT_FAILURE + fi + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + for l in $old_library $library_names; do + linklib="$l" + done + if test -z "$linklib"; then + $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + + # This library was specified with -dlopen. + if test "$pass" = dlopen; then + if test -z "$libdir"; then + $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + if test -z "$dlname" || + test "$dlopen_support" != yes || + test "$build_libtool_libs" = no; then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + dlprefiles="$dlprefiles $lib $dependency_libs" + else + newdlfiles="$newdlfiles $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2 + $echo "$modename: passing it literally to the linker, although it might fail" 1>&2 + abs_ladir="$ladir" + fi + ;; + esac + laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + + # Find the relevant object directory and library name. + if test "X$installed" = Xyes; then + if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + $echo "$modename: warning: library \`$lib' was moved." 1>&2 + dir="$ladir" + absdir="$abs_ladir" + libdir="$abs_ladir" + else + dir="$libdir" + absdir="$libdir" + fi + test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir="$ladir" + absdir="$abs_ladir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + else + dir="$ladir/$objdir" + absdir="$abs_ladir/$objdir" + # Remove this search path later + notinst_path="$notinst_path $abs_ladir" + fi + fi # $installed = yes + name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` + + # This library was specified with -dlpreopen. + if test "$pass" = dlpreopen; then + if test -z "$libdir"; then + $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2 + exit $EXIT_FAILURE + fi + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + newdlprefiles="$newdlprefiles $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + newdlprefiles="$newdlprefiles $dir/$dlname" + else + newdlprefiles="$newdlprefiles $dir/$linklib" + fi + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test "$linkmode" = lib; then + deplibs="$dir/$old_library $deplibs" + elif test "$linkmode,$pass" = "prog,link"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test "$linkmode" = prog && test "$pass" != link; then + newlib_search_path="$newlib_search_path $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=no + if test "$link_all_deplibs" != no || test -z "$library_names" || + test "$build_libtool_libs" = no; then + linkalldeplibs=yes + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test + esac + # Need to link against all dependency_libs? + if test "$linkalldeplibs" = yes; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test "$linkmode,$pass" = "prog,link"; then + if test -n "$library_names" && + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then + # Make sure the rpath contains only unique directories. + case "$temp_rpath " in + *" $dir "*) ;; + *" $absdir "*) ;; + *) temp_rpath="$temp_rpath $absdir" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if test "$alldeplibs" = yes && + { test "$deplibs_check_method" = pass_all || + { test "$build_libtool_libs" = yes && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test "$use_static_libs" = built && test "$installed" = yes ; then + use_static_libs=no + fi + if test -n "$library_names" && + { test "$use_static_libs" = no || test -z "$old_library"; }; then + if test "$installed" = no; then + notinst_deplibs="$notinst_deplibs $lib" + need_relink=yes + fi + # This is a shared library + + # Warn about portability, can't link against -module's on + # some systems (darwin) + if test "$shouldnotlink" = yes && test "$pass" = link ; then + $echo + if test "$linkmode" = prog; then + $echo "*** Warning: Linking the executable $output against the loadable module" + else + $echo "*** Warning: Linking the shared library $output against the loadable module" + fi + $echo "*** $linklib is not portable!" + fi + if test "$linkmode" = lib && + test "$hardcode_into_libs" = yes; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) compile_rpath="$compile_rpath $absdir" + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + realname="$2" + shift; shift + libname=`eval \\$echo \"$libname_spec\"` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname="$dlname" + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw*) + major=`expr $current - $age` + versuffix="-$major" + ;; + esac + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot="$soname" + soname=`$echo $soroot | ${SED} -e 's/^.*\///'` + newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a" + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + $show "extracting exported symbol list from \`$soname'" + save_ifs="$IFS"; IFS='~' + cmds=$extract_expsyms_cmds + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + $show "generating import library for \`$soname'" + save_ifs="$IFS"; IFS='~' + cmds=$old_archive_from_expsyms_cmds + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test "$linkmode" = prog || test "$mode" != relink; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test "$hardcode_direct" = no; then + add="$dir/$linklib" + case $host in + *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; + *-*-sysv4*uw2*) add_dir="-L$dir" ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir="-L$dir" ;; + *-*-darwin* ) + # if the lib is a module then we can not link against + # it, someone is ignoring the new warnings I added + if /usr/bin/file -L $add 2> /dev/null | + $EGREP ": [^:]* bundle" >/dev/null ; then + $echo "** Warning, lib $linklib is a module, not a shared library" + if test -z "$old_library" ; then + $echo + $echo "** And there doesn't seem to be a static archive available" + $echo "** The link will probably fail, sorry" + else + add="$dir/$old_library" + fi + fi + esac + elif test "$hardcode_minus_L" = no; then + case $host in + *-*-sunos*) add_shlibpath="$dir" ;; + esac + add_dir="-L$dir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = no; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + relink) + if test "$hardcode_direct" = yes; then + add="$dir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$dir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + add_shlibpath="$dir" + add="-l$name" + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test "$lib_linked" != yes; then + $echo "$modename: configuration error: unsupported hardcode properties" + exit $EXIT_FAILURE + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; + esac + fi + if test "$linkmode" = prog; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test "$hardcode_direct" != yes && \ + test "$hardcode_minus_L" != yes && \ + test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + fi + fi + fi + + if test "$linkmode" = prog || test "$mode" = relink; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test "$hardcode_direct" = yes; then + add="$libdir/$linklib" + elif test "$hardcode_minus_L" = yes; then + add_dir="-L$libdir" + add="-l$name" + elif test "$hardcode_shlibpath_var" = yes; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; + esac + add="-l$name" + elif test "$hardcode_automatic" = yes; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib" ; then + add="$inst_prefix_dir$libdir/$linklib" + else + add="$libdir/$linklib" + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir="-L$libdir" + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + add_dir="$add_dir -L$inst_prefix_dir$libdir" + ;; + esac + fi + add="-l$name" + fi + + if test "$linkmode" = prog; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test "$linkmode" = prog; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test "$hardcode_direct" != unsupported; then + test -n "$old_library" && linklib="$old_library" + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test "$build_libtool_libs" = yes; then + # Not a shared library + if test "$deplibs_check_method" != pass_all; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + $echo + $echo "*** Warning: This system can not link to static lib archive $lib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have." + if test "$module" = yes; then + $echo "*** But as you try to build a module library, libtool will still create " + $echo "*** a static module, that should work as long as the dlopening application" + $echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + $echo + $echo "*** However, this would only work if libtool was able to extract symbol" + $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" + $echo "*** not find such a program. So, this module is probably useless." + $echo "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test "$linkmode" = lib; then + if test -n "$dependency_libs" && + { test "$hardcode_into_libs" != yes || + test "$build_old_libs" = yes || + test "$link_static" = yes; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'` + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) xrpath="$xrpath $temp_xrpath";; + esac;; + *) temp_deplibs="$temp_deplibs $libdir";; + esac + done + dependency_libs="$temp_deplibs" + fi + + newlib_search_path="$newlib_search_path $absdir" + # Link against this library + test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + if test "X$duplicate_deps" = "Xyes" ; then + case "$tmp_libs " in + *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; + esac + fi + tmp_libs="$tmp_libs $deplib" + done + + if test "$link_all_deplibs" != no; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + case $deplib in + -L*) path="$deplib" ;; + *.la) + dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$deplib" && dir="." + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2 + absdir="$dir" + fi + ;; + esac + if grep "^installed=no" $deplib > /dev/null; then + path="$absdir/$objdir" + else + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + if test -z "$libdir"; then + $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + if test "$absdir" != "$libdir"; then + $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2 + fi + path="$absdir" + fi + depdepl= + case $host in + *-*-darwin*) + # we do not want to link against static libs, + # but need to link against shared + eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names" ; then + for tmp in $deplibrary_names ; do + depdepl=$tmp + done + if test -f "$path/$depdepl" ; then + depdepl="$path/$depdepl" + fi + # do not add paths which are already there + case " $newlib_search_path " in + *" $path "*) ;; + *) newlib_search_path="$newlib_search_path $path";; + esac + fi + path="" + ;; + *) + path="-L$path" + ;; + esac + ;; + -l*) + case $host in + *-*-darwin*) + # Again, we only want to link against shared libraries + eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"` + for tmp in $newlib_search_path ; do + if test -f "$tmp/lib$tmp_libs.dylib" ; then + eval depdepl="$tmp/lib$tmp_libs.dylib" + break + fi + done + path="" + ;; + *) continue ;; + esac + ;; + *) continue ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + case " $deplibs " in + *" $depdepl "*) ;; + *) deplibs="$depdepl $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + dependency_libs="$newdependency_libs" + if test "$pass" = dlpreopen; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test "$pass" != dlopen; then + if test "$pass" != conv; then + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) lib_search_path="$lib_search_path $dir" ;; + esac + done + newlib_search_path= + fi + + if test "$linkmode,$pass" != "prog,link"; then + vars="deplibs" + else + vars="compile_deplibs finalize_deplibs" + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + ;; + *) tmp_libs="$tmp_libs $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs ; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i="" + ;; + esac + if test -n "$i" ; then + tmp_libs="$tmp_libs $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test "$linkmode" = prog; then + dlfiles="$newdlfiles" + dlprefiles="$newdlprefiles" + fi + + case $linkmode in + oldlib) + if test -n "$deplibs"; then + $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 + fi + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 + fi + + if test -n "$rpath"; then + $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2 + fi + + if test -n "$xrpath"; then + $echo "$modename: warning: \`-R' is ignored for archives" 1>&2 + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for archives" 1>&2 + fi + + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2 + fi + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs="$output" + objs="$objs$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form `libNAME.la'. + case $outputname in + lib*) + name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + if test "$module" = no; then + $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + if test "$need_lib_prefix" != no; then + # Add the "lib" prefix for modules if required + name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` + fi + ;; + esac + + if test -n "$objs"; then + if test "$deplibs_check_method" != pass_all; then + $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1 + exit $EXIT_FAILURE + else + $echo + $echo "*** Warning: Linking the shared library $output against the non-libtool" + $echo "*** objects $objs is not portable!" + libobjs="$libobjs $objs" + fi + fi + + if test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2 + fi + + set dummy $rpath + if test "$#" -gt 2; then + $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2 + fi + install_libdir="$2" + + oldlibs= + if test -z "$rpath"; then + if test "$build_libtool_libs" = yes; then + # Building a libtool convenience library. + # Some compilers have problems with a `.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2 + fi + else + + # Parse the version information argument. + save_ifs="$IFS"; IFS=':' + set dummy $vinfo 0 0 0 + IFS="$save_ifs" + + if test -n "$8"; then + $echo "$modename: too many parameters to \`-version-info'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major="$2" + number_minor="$3" + number_revision="$4" + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # which has an extra 1 added just for fun + # + case $version_type in + darwin|linux|osf|windows|none) + current=`expr $number_major + $number_minor` + age="$number_minor" + revision="$number_revision" + ;; + freebsd-aout|freebsd-elf|sunos) + current="$number_major" + revision="$number_minor" + age="0" + ;; + irix|nonstopux) + current=`expr $number_major + $number_minor` + age="$number_minor" + revision="$number_minor" + lt_irix_increment=no + ;; + esac + ;; + no) + current="$2" + revision="$3" + age="$4" + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + if test "$age" -gt "$current"; then + $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2 + $echo "$modename: \`$vinfo' is not valid version information" 1>&2 + exit $EXIT_FAILURE + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + major=.`expr $current - $age` + versuffix="$major.$age.$revision" + # Darwin ld doesn't like 0 for these options... + minor_current=`expr $current + 1` + xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + ;; + + freebsd-aout) + major=".$current" + versuffix=".$current.$revision"; + ;; + + freebsd-elf) + major=".$current" + versuffix=".$current"; + ;; + + irix | nonstopux) + if test "X$lt_irix_increment" = "Xno"; then + major=`expr $current - $age` + else + major=`expr $current - $age + 1` + fi + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring="$verstring_prefix$major.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test "$loop" -ne 0; do + iface=`expr $revision - $loop` + loop=`expr $loop - 1` + verstring="$verstring_prefix$major.$iface:$verstring" + done + + # Before this point, $major must not contain `.'. + major=.$major + versuffix="$major.$revision" + ;; + + linux) + major=.`expr $current - $age` + versuffix="$major.$age.$revision" + ;; + + osf) + major=.`expr $current - $age` + versuffix=".$current.$age.$revision" + verstring="$current.$age.$revision" + + # Add in all the interfaces that we are compatible with. + loop=$age + while test "$loop" -ne 0; do + iface=`expr $current - $loop` + loop=`expr $loop - 1` + verstring="$verstring:${iface}.0" + done + + # Make executables depend on our current version. + verstring="$verstring:${current}.0" + ;; + + sunos) + major=".$current" + versuffix=".$current.$revision" + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 filesystems. + major=`expr $current - $age` + versuffix="-$major" + ;; + + *) + $echo "$modename: unknown library version type \`$version_type'" 1>&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring="0.0" + ;; + esac + if test "$need_version" = no; then + versuffix= + else + versuffix=".0.0" + fi + fi + + # Remove version info from name if versioning should be avoided + if test "$avoid_version" = yes && test "$need_version" = no; then + major= + versuffix= + verstring="" + fi + + # Check to see if the archive will have undefined symbols. + if test "$allow_undefined" = yes; then + if test "$allow_undefined_flag" = unsupported; then + $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2 + build_libtool_libs=no + build_old_libs=yes + fi + else + # Don't allow undefined symbols. + allow_undefined_flag="$no_undefined_flag" + fi + fi + + if test "$mode" != relink; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$echo "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) + if test "X$precious_files_regex" != "X"; then + if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + removelist="$removelist $p" + ;; + *) ;; + esac + done + if test -n "$removelist"; then + $show "${rm}r $removelist" + $run ${rm}r $removelist + fi + fi + + # Now set the variables for building old libraries. + if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then + oldlibs="$oldlibs $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. + #for path in $notinst_path; do + # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` + # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` + # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` + #done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + temp_xrpath="$temp_xrpath -R$libdir" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles="$dlfiles" + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) dlfiles="$dlfiles $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles="$dlprefiles" + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) dlprefiles="$dlprefiles $lib" ;; + esac + done + + if test "$build_libtool_libs" = yes; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + deplibs="$deplibs -framework System" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test "$build_libtool_need_lc" = "yes"; then + deplibs="$deplibs -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release="" + versuffix="" + major="" + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $rm conftest.c + cat > conftest.c </dev/null` + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null \ + | grep " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib="$potent_lib" + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; + *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \ + | ${SED} 10q \ + | $EGREP "$file_magic_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $echo + $echo "*** Warning: linker path does not have real file for library $a_deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $echo "*** with $libname but no candidates were found. (...for file magic test)" + else + $echo "*** with $libname and none of the candidates passed a file format test" + $echo "*** using a file magic. Last file checked: $potlib" + fi + fi + else + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + fi + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method + match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` + for a_deplib in $deplibs; do + name=`expr $a_deplib : '-l\(.*\)'` + # If $name is empty we are operating on a -L argument. + if test -n "$name" && test "$name" != "0"; then + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + case " $predeps $postdeps " in + *" $a_deplib "*) + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + ;; + esac + fi + if test -n "$a_deplib" ; then + libname=`eval \\$echo \"$libname_spec\"` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib="$potent_lib" # see symlink-check above in file_magic test + if eval $echo \"$potent_lib\" 2>/dev/null \ + | ${SED} 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + newdeplibs="$newdeplibs $a_deplib" + a_deplib="" + break 2 + fi + done + done + fi + if test -n "$a_deplib" ; then + droppeddeps=yes + $echo + $echo "*** Warning: linker path does not have real file for library $a_deplib." + $echo "*** I have the capability to make that library automatically link in when" + $echo "*** you link to this library. But I can only do this if you have a" + $echo "*** shared version of the library, which you do not appear to have" + $echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib" ; then + $echo "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $echo "*** with $libname and none of the candidates passed a file format test" + $echo "*** using a regex pattern. Last file checked: $potlib" + fi + fi + else + # Add a -L argument. + newdeplibs="$newdeplibs $a_deplib" + fi + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs="" + tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \ + -e 's/ -[LR][^ ]*//g'` + if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then + for i in $predeps $postdeps ; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"` + done + fi + if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \ + | grep . >/dev/null; then + $echo + if test "X$deplibs_check_method" = "Xnone"; then + $echo "*** Warning: inter-library dependencies are not supported in this platform." + else + $echo "*** Warning: inter-library dependencies are not known to be supported." + fi + $echo "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + fi + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'` + ;; + esac + + if test "$droppeddeps" = yes; then + if test "$module" = yes; then + $echo + $echo "*** Warning: libtool could not satisfy all declared inter-library" + $echo "*** dependencies of module $libname. Therefore, libtool will create" + $echo "*** a static module, that should work as long as the dlopening" + $echo "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + $echo + $echo "*** However, this would only work if libtool was able to extract symbol" + $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" + $echo "*** not find such a program. So, this module is probably useless." + $echo "*** \`nm' from GNU binutils and a full rebuild may help." + fi + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + $echo "*** The inter-library dependencies that have been dropped here will be" + $echo "*** automatically added whenever a program is linked with this library" + $echo "*** or is declared to -dlopen it." + + if test "$allow_undefined" = no; then + $echo + $echo "*** Since this library must not contain undefined symbols," + $echo "*** because either the platform does not support them or" + $echo "*** it was explicitly requested with -no-undefined," + $echo "*** libtool will only create a static version of it." + if test "$build_old_libs" = no; then + oldlibs="$output_objdir/$libname.$libext" + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + deplibs="$new_libs" + + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test "$build_libtool_libs" = yes; then + if test "$hardcode_into_libs" = yes; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath="$finalize_rpath" + test "$mode" != relink && rpath="$compile_rpath$rpath" + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + dep_rpath="$dep_rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + if test -n "$hardcode_libdir_flag_spec_ld"; then + case $archive_cmds in + *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; + *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; + esac + else + eval dep_rpath=\"$hardcode_libdir_flag_spec\" + fi + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath="$finalize_shlibpath" + test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + realname="$2" + shift; shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname="$realname" + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib="$output_objdir/$realname" + linknames= + for link + do + linknames="$linknames $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then + $show "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $run $rm $export_symbols + cmds=$export_symbols_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + if len=`expr "X$cmd" : ".*"` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + $show "$cmd" + $run eval "$cmd" || exit $? + skipped_export=false + else + # The command line is too long to execute in one step. + $show "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS="$save_ifs" + if test -n "$export_symbols_regex"; then + $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"" + $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + $show "$mv \"${export_symbols}T\" \"$export_symbols\"" + $run eval '$mv "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"' + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + tmp_deplibs="$tmp_deplibs $test_deplib" + ;; + esac + done + deplibs="$tmp_deplibs" + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + else + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + libobjs="$libobjs $func_extract_archives_result" + fi + fi + + if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + linker_flags="$linker_flags $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test "X$skipped_export" != "X:" && + len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise. + $echo "creating reloadable object files..." + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + output_la=`$echo "X$output" | $Xsed -e "$basename"` + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + delfiles= + last_robj= + k=1 + output=$output_objdir/$output_la-${k}.$objext + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + eval test_cmds=\"$reload_cmds $objlist $last_robj\" + if test "X$objlist" = X || + { len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len"; }; then + objlist="$objlist $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test "$k" -eq 1 ; then + # The first file doesn't have a previous command to add. + eval concat_cmds=\"$reload_cmds $objlist $last_robj\" + else + # All subsequent reloadable object files will link in + # the last one created. + eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\" + fi + last_robj=$output_objdir/$output_la-${k}.$objext + k=`expr $k + 1` + output=$output_objdir/$output_la-${k}.$objext + objlist=$obj + len=1 + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" + + if ${skipped_export-false}; then + $show "generating symbol list for \`$libname.la'" + export_symbols="$output_objdir/$libname.exp" + $run $rm $export_symbols + libobjs=$output + # Append the command to create the export file. + eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\" + fi + + # Set up a command to remove the reloadable object files + # after they are used. + i=0 + while test "$i" -lt "$k" + do + i=`expr $i + 1` + delfiles="$delfiles $output_objdir/$output_la-${i}.$objext" + done + + $echo "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs="$IFS"; IFS='~' + for cmd in $concat_cmds; do + IFS="$save_ifs" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test "$module" = yes && test -n "$module_cmds" ; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + + # Append the command to remove the reloadable object files + # to the just-reset $cmds. + eval cmds=\"\$cmds~\$rm $delfiles\" + fi + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + $show "${rm}r $gentop" + $run ${rm}r "$gentop" + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)" + $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $? + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test "$module" = yes || test "$export_dynamic" = yes; then + # On all known operating systems, these are identical. + dlname="$soname" + fi + fi + ;; + + obj) + if test -n "$deplibs"; then + $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 + fi + + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 + fi + + if test -n "$rpath"; then + $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2 + fi + + if test -n "$xrpath"; then + $echo "$modename: warning: \`-R' is ignored for objects" 1>&2 + fi + + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for objects" 1>&2 + fi + + case $output in + *.lo) + if test -n "$objs$old_deplibs"; then + $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2 + exit $EXIT_FAILURE + fi + libobj="$output" + obj=`$echo "X$output" | $Xsed -e "$lo2o"` + ;; + *) + libobj= + obj="$output" + ;; + esac + + # Delete the old objects. + $run $rm $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # reload_cmds runs $LD directly, so let us get rid of + # -Wl from whole_archive_flag_spec and hope we can get by with + # turning comma into space.. + wl= + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + else + gentop="$output_objdir/${obj}x" + generated="$generated $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # Create the old-style object. + reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test + + output="$obj" + cmds=$reload_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + exit $EXIT_SUCCESS + fi + + if test "$build_libtool_libs" != yes; then + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $run eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + fi + + if test -n "$pic_flag" || test "$pic_mode" != default; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output="$libobj" + cmds=$reload_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + fi + + if test -n "$gentop"; then + $show "${rm}r $gentop" + $run ${rm}r $gentop + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;; + esac + if test -n "$vinfo"; then + $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2 + fi + + if test -n "$release"; then + $echo "$modename: warning: \`-release' is ignored for programs" 1>&2 + fi + + if test "$preload" = yes; then + if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown && + test "$dlopen_self_static" = unknown; then + $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support." + fi + fi + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'` + finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'` + ;; + esac + + case $host in + *darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + if test "$tagname" = CXX ; then + compile_command="$compile_command ${wl}-bind_at_load" + finalize_command="$finalize_command ${wl}-bind_at_load" + fi + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + new_libs="$new_libs -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$new_libs $deplib" ;; + esac + ;; + *) new_libs="$new_libs $deplib" ;; + esac + done + compile_deplibs="$new_libs" + + + compile_command="$compile_command $compile_deplibs" + finalize_command="$finalize_command $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) finalize_rpath="$finalize_rpath $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) perm_rpath="$perm_rpath $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + *) dllsearchpath="$dllsearchpath:$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + *) dllsearchpath="$dllsearchpath:$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath="$rpath" + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs="$libdir" + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + rpath="$rpath $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir="$hardcode_libdirs" + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath="$rpath" + + if test -n "$libobjs" && test "$build_old_libs" = yes; then + # Transform all the library objects into standard objects. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + fi + + dlsyms= + if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + dlsyms="${outputname}S.c" + else + $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 + fi + fi + + if test -n "$dlsyms"; then + case $dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist="$output_objdir/${outputname}.nm" + + $show "$rm $nlist ${nlist}S ${nlist}T" + $run $rm "$nlist" "${nlist}S" "${nlist}T" + + # Parse the name list into a source file. + $show "creating $output_objdir/$dlsyms" + + test -z "$run" && $echo > "$output_objdir/$dlsyms" "\ +/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */ +/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +/* Prevent the only kind of declaration conflicts we can make. */ +#define lt_preloaded_symbols some_other_symbol + +/* External symbol declarations for the compiler. */\ +" + + if test "$dlself" = yes; then + $show "generating symbol list for \`$output'" + + test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` + for arg in $progfiles; do + $show "extracting global C symbols from \`$arg'" + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + $run eval '$mv "$nlist"T "$nlist"' + fi + + if test -n "$export_symbols_regex"; then + $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + $run eval '$mv "$nlist"T "$nlist"' + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols="$output_objdir/$outputname.exp" + $run $rm $export_symbols + $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* ) + $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + $run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + else + $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + $run eval 'mv "$nlist"T "$nlist"' + case $host in + *cygwin* | *mingw* ) + $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + $run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + fi + fi + + for arg in $dlprefiles; do + $show "extracting global C symbols from \`$arg'" + name=`$echo "$arg" | ${SED} -e 's%^.*/%%'` + $run eval '$echo ": $name " >> "$nlist"' + $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" + done + + if test -z "$run"; then + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $mv "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if grep -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + grep -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"' + else + $echo '/* NONE */' >> "$output_objdir/$dlsyms" + fi + + $echo >> "$output_objdir/$dlsyms" "\ + +#undef lt_preloaded_symbols + +#if defined (__STDC__) && __STDC__ +# define lt_ptr void * +#else +# define lt_ptr char * +# define const +#endif + +/* The mapping between symbol names and symbols. */ +" + + case $host in + *cygwin* | *mingw* ) + $echo >> "$output_objdir/$dlsyms" "\ +/* DATA imports from DLLs on WIN32 can't be const, because + runtime relocations are performed -- see ld's documentation + on pseudo-relocs */ +struct { +" + ;; + * ) + $echo >> "$output_objdir/$dlsyms" "\ +const struct { +" + ;; + esac + + + $echo >> "$output_objdir/$dlsyms" "\ + const char *name; + lt_ptr address; +} +lt_preloaded_symbols[] = +{\ +" + + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms" + + $echo >> "$output_objdir/$dlsyms" "\ + {0, (lt_ptr) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + fi + + pic_flag_for_symtable= + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + case "$compile_command " in + *" -static "*) ;; + *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";; + esac;; + *-*-hpux*) + case "$compile_command " in + *" -static "*) ;; + *) pic_flag_for_symtable=" $pic_flag";; + esac + esac + + # Now compile the dynamic symbol file. + $show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")" + $run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $? + + # Clean up the generated files. + $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T" + $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T" + + # Transform the symbol file into the correct name. + case $host in + *cygwin* | *mingw* ) + if test -f "$output_objdir/${outputname}.def" ; then + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` + else + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + fi + ;; + * ) + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` + ;; + esac + ;; + *) + $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 + exit $EXIT_FAILURE + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` + finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` + fi + + if test "$need_relink" = no || test "$build_libtool_libs" != yes; then + # Replace the output file specification. + compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$output"'%g' | $NL2SP` + link_command="$compile_command$compile_rpath" + + # We have no uninstalled library dependencies, so finalize right now. + $show "$link_command" + $run eval "$link_command" + exit_status=$? + + # Delete the generated files. + if test -n "$dlsyms"; then + $show "$rm $output_objdir/${outputname}S.${objext}" + $run $rm "$output_objdir/${outputname}S.${objext}" + fi + + exit $exit_status + fi + + if test -n "$shlibpath_var"; then + # We should set the shlibpath_var + rpath= + for dir in $temp_rpath; do + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) + # Absolute path. + rpath="$rpath$dir:" + ;; + *) + # Relative path: add a thisdir entry. + rpath="$rpath\$thisdir/$dir:" + ;; + esac + done + temp_rpath="$rpath" + fi + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + rpath="$rpath$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + rpath="$rpath$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test "$no_install" = yes; then + # We don't need to create a wrapper script. + link_command="$compile_var$compile_command$compile_rpath" + # Replace the output file specification. + link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $run $rm $output + # Link the executable and exit + $show "$link_command" + $run eval "$link_command" || exit $? + exit $EXIT_SUCCESS + fi + + if test "$hardcode_action" = relink; then + # Fast installation is not supported + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + + $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2 + $echo "$modename: \`$output' will be relinked during installation" 1>&2 + else + if test "$fast_install" != no; then + link_command="$finalize_var$compile_command$finalize_rpath" + if test "$fast_install" = yes; then + relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $SP2NL | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g' | $NL2SP` + else + # fast_install is set to needless + relink_command= + fi + else + link_command="$compile_var$compile_command$compile_rpath" + relink_command="$finalize_var$finalize_command$finalize_rpath" + fi + fi + + # Replace the output file specification. + link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname + + $show "$link_command" + $run eval "$link_command" || exit $? + + # Now create the wrapper script. + $show "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` + relink_command="$var=\"$var_value\"; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` + fi + + # Quote $echo for shipping. + if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then + case $progpath in + [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; + *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; + esac + qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"` + else + qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"` + fi + + # Only actually do things if our run command is non-null. + if test -z "$run"; then + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + output_name=`basename $output` + output_path=`dirname $output` + cwrappersource="$output_path/$objdir/lt-$output_name.c" + cwrapper="$output_path/$output_name.exe" + $rm $cwrappersource $cwrapper + trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + cat > $cwrappersource <> $cwrappersource<<"EOF" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(PATH_MAX) +# define LT_PATHMAX PATH_MAX +#elif defined(MAXPATHLEN) +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ + defined (__OS2__) +# define HAVE_DOS_BASED_FILE_SYSTEM +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free ((void *) stale); stale = 0; } \ +} while (0) + +/* -DDEBUG is fairly common in CFLAGS. */ +#undef DEBUG +#if defined DEBUGWRAPPER +# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__) +#else +# define DEBUG(format, ...) +#endif + +const char *program_name = NULL; + +void * xmalloc (size_t num); +char * xstrdup (const char *string); +const char * base_name (const char *name); +char * find_executable(const char *wrapper); +int check_executable(const char *path); +char * strendzap(char *str, const char *pat); +void lt_fatal (const char *message, ...); + +int +main (int argc, char *argv[]) +{ + char **newargz; + int i; + + program_name = (char *) xstrdup (base_name (argv[0])); + DEBUG("(main) argv[0] : %s\n",argv[0]); + DEBUG("(main) program_name : %s\n",program_name); + newargz = XMALLOC(char *, argc+2); +EOF + + cat >> $cwrappersource <> $cwrappersource <<"EOF" + newargz[1] = find_executable(argv[0]); + if (newargz[1] == NULL) + lt_fatal("Couldn't find %s", argv[0]); + DEBUG("(main) found exe at : %s\n",newargz[1]); + /* we know the script has the same name, without the .exe */ + /* so make sure newargz[1] doesn't end in .exe */ + strendzap(newargz[1],".exe"); + for (i = 1; i < argc; i++) + newargz[i+1] = xstrdup(argv[i]); + newargz[argc+1] = NULL; + + for (i=0; i> $cwrappersource <> $cwrappersource <> $cwrappersource <<"EOF" + return 127; +} + +void * +xmalloc (size_t num) +{ + void * p = (void *) malloc (num); + if (!p) + lt_fatal ("Memory exhausted"); + + return p; +} + +char * +xstrdup (const char *string) +{ + return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL +; +} + +const char * +base_name (const char *name) +{ + const char *base; + +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + /* Skip over the disk name in MSDOS pathnames. */ + if (isalpha ((unsigned char)name[0]) && name[1] == ':') + name += 2; +#endif + + for (base = name; *name; name++) + if (IS_DIR_SEPARATOR (*name)) + base = name + 1; + return base; +} + +int +check_executable(const char * path) +{ + struct stat st; + + DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!"); + if ((!path) || (!*path)) + return 0; + + if ((stat (path, &st) >= 0) && + ( + /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */ +#if defined (S_IXOTH) + ((st.st_mode & S_IXOTH) == S_IXOTH) || +#endif +#if defined (S_IXGRP) + ((st.st_mode & S_IXGRP) == S_IXGRP) || +#endif + ((st.st_mode & S_IXUSR) == S_IXUSR)) + ) + return 1; + else + return 0; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise */ +char * +find_executable (const char* wrapper) +{ + int has_slash = 0; + const char* p; + const char* p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + int tmp_len; + char* concat_name; + + DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char* path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char* q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR(*q)) + break; + p_len = q - p; + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen(tmp); + concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal ("getcwd failed"); + tmp_len = strlen(tmp); + concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable(concat_name)) + return concat_name; + XFREE(concat_name); + return NULL; +} + +char * +strendzap(char *str, const char *pat) +{ + size_t len, patlen; + + assert(str != NULL); + assert(pat != NULL); + + len = strlen(str); + patlen = strlen(pat); + + if (patlen <= len) + { + str += len - patlen; + if (strcmp(str, pat) == 0) + *str = '\0'; + } + return str; +} + +static void +lt_error_core (int exit_status, const char * mode, + const char * message, va_list ap) +{ + fprintf (stderr, "%s: %s: ", program_name, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, "FATAL", message, ap); + va_end (ap); +} +EOF + # we should really use a build-platform specific compiler + # here, but OTOH, the wrappers (shell script and this C one) + # are only useful if you want to execute the "real" binary. + # Since the "real" binary is built for $host, then this + # wrapper might as well be built for $host, too. + $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource + ;; + esac + $rm $output + trap "$rm $output; exit $EXIT_FAILURE" 1 2 15 + + $echo > $output "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='${SED} -e 1s/^X//' +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variable: + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$echo are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + echo=\"$qecho\" + file=\"\$0\" + # Make sure echo works. + if test \"X\$1\" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then + # Yippee, \$echo works! + : + else + # Restart under the correct shell, and then maybe \$echo will work. + exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} + fi + fi\ +" + $echo >> $output "\ + + # Find the directory that this script lives in. + thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` + done + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test "$fast_install" = yes; then + $echo >> $output "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || \\ + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $mkdir \"\$progdir\" + else + $rm \"\$progdir/\$file\" + fi" + + $echo >> $output "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + $echo \"\$relink_command_output\" >&2 + $rm \"\$progdir/\$file\" + exit $EXIT_FAILURE + fi + fi + + $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $rm \"\$progdir/\$program\"; + $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $rm \"\$progdir/\$file\" + fi" + else + $echo >> $output "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $echo >> $output "\ + + if test -f \"\$progdir/\$program\"; then" + + # Export our shlibpath_var if we have one. + if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $echo >> $output "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` + + export $shlibpath_var +" + fi + + # fixup the dll searchpath if we need to. + if test -n "$dllsearchpath"; then + $echo >> $output "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + $echo >> $output "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2*) + $echo >> $output "\ + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $echo >> $output "\ + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $echo >> $output "\ + \$echo \"\$0: cannot exec \$program \$*\" + exit $EXIT_FAILURE + fi + else + # The program doesn't exist. + \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 + \$echo \"This script is just a wrapper for \$program.\" 1>&2 + $echo \"See the $PACKAGE documentation for more information.\" 1>&2 + exit $EXIT_FAILURE + fi +fi\ +" + chmod +x $output + fi + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + if test "$build_libtool_libs" = convenience; then + oldobjs="$libobjs_save" + addlibs="$convenience" + build_libtool_libs=no + else + if test "$build_libtool_libs" = module; then + oldobjs="$libobjs_save" + build_libtool_libs=no + else + oldobjs="$old_deplibs $non_pic_objects" + fi + addlibs="$old_convenience" + fi + + if test -n "$addlibs"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + func_extract_archives $gentop $addlibs + oldobjs="$oldobjs $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then + cmds=$old_archive_from_new_cmds + else + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + $echo "X$obj" | $Xsed -e 's%^.*/%%' + done | sort | sort -uc >/dev/null 2>&1); then + : + else + $echo "copying selected object files to avoid basename conflicts..." + + if test -z "$gentop"; then + gentop="$output_objdir/${outputname}x" + generated="$generated $gentop" + + $show "${rm}r $gentop" + $run ${rm}r "$gentop" + $show "$mkdir $gentop" + $run $mkdir "$gentop" + exit_status=$? + if test "$exit_status" -ne 0 && test ! -d "$gentop"; then + exit $exit_status + fi + fi + + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + counter=`expr $counter + 1` + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + $run ln "$obj" "$gentop/$newobj" || + $run cp "$obj" "$gentop/$newobj" + oldobjs="$oldobjs $gentop/$newobj" + ;; + *) oldobjs="$oldobjs $obj" ;; + esac + done + fi + + eval cmds=\"$old_archive_cmds\" + + if len=`expr "X$cmds" : ".*"` && + test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + $echo "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + for obj in $save_oldobjs + do + oldobjs="$objlist $obj" + objlist="$objlist $obj" + eval test_cmds=\"$old_archive_cmds\" + if len=`expr "X$test_cmds" : ".*" 2>/dev/null` && + test "$len" -le "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj" ; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" + objlist= + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test "X$oldobjs" = "X" ; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + eval cmd=\"$cmd\" + IFS="$save_ifs" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + done + + if test -n "$generated"; then + $show "${rm}r$generated" + $run ${rm}r$generated + fi + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test "$build_old_libs" = yes && old_library="$libname.$libext" + $show "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` + relink_command="$var=\"$var_value\"; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` + if test "$hardcode_automatic" = yes ; then + relink_command= + fi + + + # Only create the output if not a dry run. + if test -z "$run"; then + for installed in no yes; do + if test "$installed" = yes; then + if test -z "$install_libdir"; then + break + fi + output="$output_objdir/$outputname"i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + if test -z "$libdir"; then + $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdependency_libs="$newdependency_libs $libdir/$name" + ;; + *) newdependency_libs="$newdependency_libs $deplib" ;; + esac + done + dependency_libs="$newdependency_libs" + newdlfiles= + for lib in $dlfiles; do + name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + if test -z "$libdir"; then + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdlfiles="$newdlfiles $libdir/$name" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` + eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + if test -z "$libdir"; then + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + exit $EXIT_FAILURE + fi + newdlprefiles="$newdlprefiles $libdir/$name" + done + dlprefiles="$newdlprefiles" + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlfiles="$newdlfiles $abs" + done + dlfiles="$newdlfiles" + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; + *) abs=`pwd`"/$lib" ;; + esac + newdlprefiles="$newdlprefiles $abs" + done + dlprefiles="$newdlprefiles" + fi + $rm $output + # place dlname in correct position for cygwin + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; + esac + $echo > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test "$installed" = no && test "$need_relink" = yes; then + $echo >> $output "\ +relink_command=\"$relink_command\"" + fi + done + fi + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)" + $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $? + ;; + esac + exit $EXIT_SUCCESS + ;; + + # libtool install mode + install) + modename="$modename: install" + + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || + # Allow the use of GNU shtool's install command. + $echo "X$nonopt" | grep shtool > /dev/null; then + # Aesthetically quote it. + arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$arg " + arg="$1" + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$install_prog$arg" + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=no + stripme= + for arg + do + if test -n "$dest"; then + files="$files $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=yes ;; + -f) + case " $install_prog " in + *[\\\ /]cp\ *) ;; + *) prev=$arg ;; + esac + ;; + -g | -m | -o) prev=$arg ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` + case $arg in + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + arg="\"$arg\"" + ;; + esac + install_prog="$install_prog $arg" + done + + if test -z "$install_prog"; then + $echo "$modename: you must specify an install program" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test -n "$prev"; then + $echo "$modename: the \`$prev' option requires an argument" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + if test -z "$files"; then + if test -z "$dest"; then + $echo "$modename: no file or destination specified" 1>&2 + else + $echo "$modename: you must specify a destination" 1>&2 + fi + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Strip any trailing slash from the destination. + dest=`$echo "X$dest" | $Xsed -e 's%/$%%'` + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=yes + if test "$isdir" = yes; then + destdir="$dest" + destname= + else + destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'` + test "X$destdir" = "X$dest" && destdir=. + destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'` + + # Not a directory, so check to see that there is only one file specified. + set dummy $files + if test "$#" -gt 2; then + $echo "$modename: \`$dest' is not a directory" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + staticlibs="$staticlibs $file" + ;; + + *.la) + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$file' is not a valid libtool archive" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + library_names= + old_library= + relink_command= + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) current_libdirs="$current_libdirs $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) future_libdirs="$future_libdirs $libdir" ;; + esac + fi + + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/ + test "X$dir" = "X$file/" && dir= + dir="$dir$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + if test "$inst_prefix_dir" = "$destdir"; then + $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 + exit $EXIT_FAILURE + fi + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%" | $NL2SP` + else + relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%%" | $NL2SP` + fi + + $echo "$modename: warning: relinking \`$file'" 1>&2 + $show "$relink_command" + if $run eval "$relink_command"; then : + else + $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 + exit $EXIT_FAILURE + fi + fi + + # See the names of the shared library. + set dummy $library_names + if test -n "$2"; then + realname="$2" + shift + shift + + srcname="$realname" + test -n "$relink_command" && srcname="$realname"T + + # Install the shared library and build the symlinks. + $show "$install_prog $dir/$srcname $destdir/$realname" + $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $? + if test -n "$stripme" && test -n "$striplib"; then + $show "$striplib $destdir/$realname" + $run eval "$striplib $destdir/$realname" || exit $? + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try `ln -sf' first, because the `ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + if test "$linkname" != "$realname"; then + $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" + $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" + fi + done + fi + + # Do each command in the postinstall commands. + lib="$destdir/$realname" + cmds=$postinstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test "$mode" = relink; then + $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' + fi + + exit $lt_exit + } + done + IFS="$save_ifs" + fi + + # Install the pseudo-library for information purposes. + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + instname="$dir/$name"i + $show "$install_prog $instname $destdir/$name" + $run eval "$install_prog $instname $destdir/$name" || exit $? + + # Maybe install the static library, too. + test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + destfile="$destdir/$destfile" + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"` + ;; + *.$objext) + staticdest="$destfile" + destfile= + ;; + *) + $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + # Install the libtool object if requested. + if test -n "$destfile"; then + $show "$install_prog $file $destfile" + $run eval "$install_prog $file $destfile" || exit $? + fi + + # Install the old object if enabled. + if test "$build_old_libs" = yes; then + # Deduce the name of the old-style object file. + staticobj=`$echo "X$file" | $Xsed -e "$lo2o"` + + $show "$install_prog $staticobj $staticdest" + $run eval "$install_prog \$staticobj \$staticdest" || exit $? + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile="$destdir/$destname" + else + destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + destfile="$destdir/$destfile" + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext="" + case $file in + *.exe) + if test ! -f "$file"; then + file=`$echo $file|${SED} 's,.exe$,,'` + stripped_ext=".exe" + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin*|*mingw*) + wrapper=`$echo $file | ${SED} -e 's,.exe$,,'` + ;; + *) + wrapper=$file + ;; + esac + if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then + notinst_deplibs= + relink_command= + + # Note that it is not necessary on cygwin/mingw to append a dot to + # foo even if both foo and FILE.exe exist: automatic-append-.exe + # behavior happens only for exec(3), not for open(2)! Also, sourcing + # `FILE.' does not work on cygwin managed mounts. + # + # If there is no directory component, then add one. + case $wrapper in + */* | *\\*) . ${wrapper} ;; + *) . ./${wrapper} ;; + esac + + # Check the variables that should have been set. + if test -z "$notinst_deplibs"; then + $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2 + exit $EXIT_FAILURE + fi + + finalize=yes + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + # If there is no directory component, then add one. + case $lib in + */* | *\\*) . $lib ;; + *) . ./$lib ;; + esac + fi + libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test + if test -n "$libdir" && test ! -f "$libfile"; then + $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2 + finalize=no + fi + done + + relink_command= + # Note that it is not necessary on cygwin/mingw to append a dot to + # foo even if both foo and FILE.exe exist: automatic-append-.exe + # behavior happens only for exec(3), not for open(2)! Also, sourcing + # `FILE.' does not work on cygwin managed mounts. + # + # If there is no directory component, then add one. + case $wrapper in + */* | *\\*) . ${wrapper} ;; + *) . ./${wrapper} ;; + esac + + outputname= + if test "$fast_install" = no && test -n "$relink_command"; then + if test "$finalize" = yes && test -z "$run"; then + tmpdir=`func_mktempdir` + file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` + outputname="$tmpdir/$file" + # Replace the output file specification. + relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g' | $NL2SP` + + $show "$relink_command" + if $run eval "$relink_command"; then : + else + $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 + ${rm}r "$tmpdir" + continue + fi + file="$outputname" + else + $echo "$modename: warning: cannot relink \`$file'" 1>&2 + fi + else + # Install the binary that we compiled earlier. + file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'` + ;; + esac + ;; + esac + $show "$install_prog$stripme $file $destfile" + $run eval "$install_prog\$stripme \$file \$destfile" || exit $? + test -n "$outputname" && ${rm}r "$tmpdir" + ;; + esac + done + + for file in $staticlibs; do + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + + # Set up the ranlib parameters. + oldlib="$destdir/$name" + + $show "$install_prog $file $oldlib" + $run eval "$install_prog \$file \$oldlib" || exit $? + + if test -n "$stripme" && test -n "$old_striplib"; then + $show "$old_striplib $oldlib" + $run eval "$old_striplib $oldlib" || exit $? + fi + + # Do each command in the postinstall commands. + cmds=$old_postinstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || exit $? + done + IFS="$save_ifs" + done + + if test -n "$future_libdirs"; then + $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2 + fi + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + test -n "$run" && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi + ;; + + # libtool finish mode + finish) + modename="$modename: finish" + libdirs="$nonopt" + admincmds= + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for dir + do + libdirs="$libdirs $dir" + done + + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + cmds=$finish_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" || admincmds="$admincmds + $cmd" + done + IFS="$save_ifs" + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $run eval "$cmds" || admincmds="$admincmds + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + test "$show" = : && exit $EXIT_SUCCESS + + $echo "X----------------------------------------------------------------------" | $Xsed + $echo "Libraries have been installed in:" + for libdir in $libdirs; do + $echo " $libdir" + done + $echo + $echo "If you ever happen to want to link against installed libraries" + $echo "in a given directory, LIBDIR, you must either use libtool, and" + $echo "specify the full pathname of the library, or use the \`-LLIBDIR'" + $echo "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + $echo " - add LIBDIR to the \`$shlibpath_var' environment variable" + $echo " during execution" + fi + if test -n "$runpath_var"; then + $echo " - add LIBDIR to the \`$runpath_var' environment variable" + $echo " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $echo " - use the \`$flag' linker flag" + fi + if test -n "$admincmds"; then + $echo " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" + fi + $echo + $echo "See any operating system documentation about shared libraries for" + $echo "more information, such as the ld(1) and ld.so(8) manual pages." + $echo "X----------------------------------------------------------------------" | $Xsed + exit $EXIT_SUCCESS + ;; + + # libtool execute mode + execute) + modename="$modename: execute" + + # The first argument is the command name. + cmd="$nonopt" + if test -z "$cmd"; then + $echo "$modename: you must specify a COMMAND" 1>&2 + $echo "$help" + exit $EXIT_FAILURE + fi + + # Handle -dlopen flags immediately. + for file in $execute_dlfiles; do + if test ! -f "$file"; then + $echo "$modename: \`$file' is not a file" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + dir= + case $file in + *.la) + # Check to see that this really is a libtool archive. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : + else + $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Read the libtool library. + dlname= + library_names= + + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'" + continue + fi + + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$file" && dir=. + + if test -f "$dir/$objdir/$dlname"; then + dir="$dir/$objdir" + else + if test ! -f "$dir/$dlname"; then + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE + fi + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "X$dir" = "X$file" && dir=. + ;; + + *) + $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2 + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir="$absdir" + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic="$magic" + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -*) ;; + *) + # Do a test to see if this is really a libtool program. + if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + # If there is no directory component, then add one. + case $file in + */* | *\\*) . $file ;; + *) . ./$file ;; + esac + + # Transform arg to wrapped name. + file="$progdir/$program" + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"` + args="$args \"$file\"" + done + + if test -z "$run"; then + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + fi" + done + + # Now prepare to actually exec the command. + exec_cmd="\$cmd$args" + else + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\"" + $echo "export $shlibpath_var" + fi + $echo "$cmd$args" + exit $EXIT_SUCCESS + fi + ;; + + # libtool clean and uninstall mode + clean | uninstall) + modename="$modename: $mode" + rm="$nonopt" + files= + rmforce= + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic="$magic" + + for arg + do + case $arg in + -f) rm="$rm $arg"; rmforce=yes ;; + -*) rm="$rm $arg" ;; + *) files="$files $arg" ;; + esac + done + + if test -z "$rm"; then + $echo "$modename: you must specify an RM program" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + fi + + rmdirs= + + origobjdir="$objdir" + for file in $files; do + dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` + if test "X$dir" = "X$file"; then + dir=. + objdir="$origobjdir" + else + objdir="$dir/$origobjdir" + fi + name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` + test "$mode" = uninstall && objdir="$dir" + + # Remember objdir for removal later, being careful to avoid duplicates + if test "$mode" = clean; then + case " $rmdirs " in + *" $objdir "*) ;; + *) rmdirs="$rmdirs $objdir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if (test -L "$file") >/dev/null 2>&1 \ + || (test -h "$file") >/dev/null 2>&1 \ + || test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif test "$rmforce" = yes; then + continue + fi + + rmfiles="$file" + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + . $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + rmfiles="$rmfiles $objdir/$n" + done + test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" + + case "$mode" in + clean) + case " $library_names " in + # " " in the beginning catches empty $dlname + *" $dlname "*) ;; + *) rmfiles="$rmfiles $objdir/$dlname" ;; + esac + test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + cmds=$postuninstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" + if test "$?" -ne 0 && test "$rmforce" != yes; then + exit_status=1 + fi + done + IFS="$save_ifs" + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + cmds=$old_postuninstall_cmds + save_ifs="$IFS"; IFS='~' + for cmd in $cmds; do + IFS="$save_ifs" + eval cmd=\"$cmd\" + $show "$cmd" + $run eval "$cmd" + if test "$?" -ne 0 && test "$rmforce" != yes; then + exit_status=1 + fi + done + IFS="$save_ifs" + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + + # Read the .lo file + . $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" \ + && test "$pic_object" != none; then + rmfiles="$rmfiles $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" \ + && test "$non_pic_object" != none; then + rmfiles="$rmfiles $dir/$non_pic_object" + fi + fi + ;; + + *) + if test "$mode" = clean ; then + noexename=$name + case $file in + *.exe) + file=`$echo $file|${SED} 's,.exe$,,'` + noexename=`$echo $name|${SED} 's,.exe$,,'` + # $file with .exe has already been added to rmfiles, + # add $file without .exe + rmfiles="$rmfiles $file" + ;; + esac + # Do a test to see if this is a libtool program. + if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then + relink_command= + . $dir/$noexename + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" + if test "$fast_install" = yes && test -n "$relink_command"; then + rmfiles="$rmfiles $objdir/lt-$name" + fi + if test "X$noexename" != "X$name" ; then + rmfiles="$rmfiles $objdir/lt-${noexename}.c" + fi + fi + fi + ;; + esac + $show "$rm $rmfiles" + $run $rm $rmfiles || exit_status=1 + done + objdir="$origobjdir" + + # Try to remove the ${objdir}s in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + $show "rmdir $dir" + $run rmdir $dir >/dev/null 2>&1 + fi + done + + exit $exit_status + ;; + + "") + $echo "$modename: you must specify a MODE" 1>&2 + $echo "$generic_help" 1>&2 + exit $EXIT_FAILURE + ;; + esac + + if test -z "$exec_cmd"; then + $echo "$modename: invalid operation mode \`$mode'" 1>&2 + $echo "$generic_help" 1>&2 + exit $EXIT_FAILURE + fi +fi # test -z "$show_help" + +if test -n "$exec_cmd"; then + eval exec $exec_cmd + exit $EXIT_FAILURE +fi + +# We need to display help for each of the modes. +case $mode in +"") $echo \ +"Usage: $modename [OPTION]... [MODE-ARG]... + +Provide generalized library-building support services. + + --config show all configuration variables + --debug enable verbose shell tracing +-n, --dry-run display commands without modifying any files + --features display basic configuration information and exit + --finish same as \`--mode=finish' + --help display this help message and exit + --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS] + --quiet same as \`--silent' + --silent don't print informational messages + --tag=TAG use configuration variables from tag TAG + --version print version information + +MODE must be one of the following: + + clean remove files from the build directory + compile compile a source file into a libtool object + execute automatically set library path, then run a program + finish complete the installation of libtool libraries + install install libraries or executables + link create a library or an executable + uninstall remove libraries from an installed directory + +MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for +a more detailed description of MODE. + +Report bugs to ." + exit $EXIT_SUCCESS + ;; + +clean) + $echo \ +"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + +compile) + $echo \ +"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -prefer-pic try to building PIC objects only + -prefer-non-pic try to building non-PIC objects only + -static always build a \`.o' file suitable for static linking + +COMPILE-COMMAND is a command to be used in creating a \`standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix \`.c' with the +library object suffix, \`.lo'." + ;; + +execute) + $echo \ +"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to \`-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + +finish) + $echo \ +"Usage: $modename [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the \`--dry-run' option if you just want to see what would be executed." + ;; + +install) + $echo \ +"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the \`install' or \`cp' program. + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + +link) + $echo \ +"Usage: $modename [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE Use a list of object files found in FILE to specify objects + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + +All other options (arguments beginning with \`-') are ignored. + +Every other argument is treated as a filename. Files ending in \`.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in \`.la', then a libtool library is created, +only library objects (\`.lo' files) may be specified, and \`-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created +using \`ar' and \`ranlib', or on Windows using \`lib'. + +If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file +is created, otherwise an executable program is created." + ;; + +uninstall) + $echo \ +"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + +*) + $echo "$modename: invalid operation mode \`$mode'" 1>&2 + $echo "$help" 1>&2 + exit $EXIT_FAILURE + ;; +esac + +$echo +$echo "Try \`$modename --help' for more information about other modes." + +exit $? + +# The TAGs below are defined such that we never get into a situation +# in which we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +disable_libs=shared +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +disable_libs=static +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff --git a/libs/freetdm/build/missing b/libs/freetdm/build/missing new file mode 100755 index 0000000000..e7ef83a1c2 --- /dev/null +++ b/libs/freetdm/build/missing @@ -0,0 +1,360 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. + +scriptversion=2003-09-02.23 + +# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 +# Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# 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, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +msg="missing on your system" + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + # Exit code 63 means version mismatch. This often happens + # when the user try to use an ancient version of a tool on + # a file that requires a minimum version. In this case we + # we should proceed has if the program had been absent, or + # if --run hadn't been passed. + if test $? = 63; then + run=: + msg="probably too old" + fi + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch] + +Send bug reports to ." + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing $scriptversion (GNU Automake)" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, but is $msg. + You might have modified some files without having the + proper tools for further handling them. + You can get \`$1' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' $msg. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is $msg. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and is $msg. + You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequisites for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index e04cbe7200..aff46c9a36 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -5,14 +5,23 @@ AC_PREREQ(2.59) AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) AC_CONFIG_SRCDIR([src/libteletone_detect.c]) +AC_CONFIG_AUX_DIR(build) +#AM_INIT_AUTOMAKE(libopenzap,0.1) + # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET -AC_PROG_RANLIB - AC_PREFIX_DEFAULT(/usr/local/openzap) +#override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) +m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) +m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) +m4_defun([_LT_AC_LANG_RC_CONFIG], [:]) +#AM_PROG_CC_C_O +AC_PROG_LIBTOOL +AC_PROG_INSTALL + # Check for com;iler type AC_DEFUN([AX_COMPILER_VENDOR], [ @@ -48,6 +57,40 @@ sun) ;; esac + +#set SOLINK variable based on compiler and host +if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then + SOLINK="-Bdynamic -dy -G" +elif test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then + case "$host" in + *darwin*) + SOLINK="-dynamic -bundle -force-flat-namespace" + ;; + *-solaris2*) + SOLINK="-shared -Xlinker" + ;; + *) + SOLINK="-shared -Xlinker -x" + ;; + esac +else + AC_ERROR([Please update configure.in with SOLINK values for your compiler]) +fi + +# set DYNAMIC_LIB_EXTEN +# we should really be using libtool so we don't need to do this +case "$host" in + *cygwin* | *mingw*) + DYNAMIC_LIB_EXTEN="dll" + ;; + *) + DYNAMIC_LIB_EXTEN="so" + ;; +esac + +AC_SUBST(SOLINK) +AC_SUBST(DYNAMIC_LIB_EXTEN) + AC_CHECK_LIB([dl], [dlopen]) AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([m], [cos]) diff --git a/libs/freetdm/src/detect_dtmf.c b/libs/freetdm/src/detect_dtmf.c index 941237b464..f73586adcb 100644 --- a/libs/freetdm/src/detect_dtmf.c +++ b/libs/freetdm/src/detect_dtmf.c @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) teletone_dtmf_detect_init (&dtmf_detect, 8000); if ((fd = open(argv[1], O_RDONLY)) < 0) { - fprintf(stderr, "File Error!\n", strerror(errno)); + fprintf(stderr, "File Error! [%s]\n", strerror(errno)); exit(-1); } @@ -28,5 +28,6 @@ int main(int argc, char *argv[]) } } close(fd); + return 0; } diff --git a/libs/freetdm/src/detect_tones.c b/libs/freetdm/src/detect_tones.c index c5d475edc3..580f6a9d17 100644 --- a/libs/freetdm/src/detect_tones.c +++ b/libs/freetdm/src/detect_tones.c @@ -3,9 +3,8 @@ int main(int argc, char *argv[]) { - teletone_generation_session_t ts; teletone_multi_tone_t mt = {0}; - teletone_tone_map_t map = {0}; + teletone_tone_map_t map = {{0}}; int fd, b; short sln[512] = {0}; @@ -15,14 +14,12 @@ int main(int argc, char *argv[]) exit(-1); } - map.freqs[0] = atof("350"); map.freqs[1] = atof("440"); teletone_multi_tone_init(&mt, &map); - if ((fd = open(argv[1], O_RDONLY)) < 0) { - fprintf(stderr, "File Error!\n", strerror(errno)); + fprintf(stderr, "File Error! [%s]\n", strerror(errno)); exit(-1); } @@ -30,5 +27,6 @@ int main(int argc, char *argv[]) printf("TEST %d %d\n", b, teletone_multi_tone_detect(&mt, sln, b / 2)); } close(fd); + return 0; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index d65b9ef68e..03f58b6da0 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -533,9 +533,9 @@ zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen); +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); zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number); +zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); void zap_channel_rotate_tokens(zap_channel_t *zchan); void zap_channel_clear_detected_tones(zap_channel_t *zchan); diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index dd91c639d9..d816edb3be 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -6,14 +6,14 @@ 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, "5551212"); + zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, number); while (chan->state == ZAP_CHANNEL_STATE_UP) { zap_wait_flag_t flags = ZAP_READ; @@ -37,8 +37,8 @@ static void *test_call(zap_thread_t *me, void *obj) } zap_log(ZAP_LOG_DEBUG, "call over\n"); - - return 0; + free(number); + return NULL; } static ZIO_SIGNAL_CB_FUNCTION(on_signal) @@ -59,12 +59,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) } static int R = 0; +#if 0 static void handle_SIGINT(int sig) { if (sig); R = 0; return; } +#endif int main(int argc, char *argv[]) { @@ -113,7 +115,7 @@ int main(int argc, char *argv[]) done: zap_global_destroy(); - + return 0; } /* For Emacs: diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 4f00ca600b..3a706edc95 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -67,10 +67,8 @@ int main(int argc, char *argv[]) goto top; } - end: - zap_global_destroy(); - + return 0; } /* For Emacs: diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index e585fcbb1d..4838f54def 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -6,13 +6,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) } 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; @@ -59,6 +60,7 @@ int main(int argc, char *argv[]) zap_global_destroy(); + return 0; } /* For Emacs: diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index d374a34081..0dd923393e 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -1,4 +1,5 @@ #include "openzap.h" +zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data); struct helper { int fd; @@ -7,8 +8,6 @@ struct helper { zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) { - int x ; - struct helper *foo = (struct helper *) user_data; write(foo->fd, buf, buflen * 2); foo->wrote += buflen * 2; @@ -28,17 +27,17 @@ int main(int argc, char *argv[]) char fbuf[256]; uint8_t databuf[1024] = ""; struct helper foo = {0}; - int x, bytes, start_bits = 180, stop_bits = 5, sbits = 300; + // 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; - char *url = "sip:cool@rad.com"; + 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!\n", strerror(errno)); + fprintf(stderr, "File Error! [%s]\n", strerror(errno)); exit(-1); } @@ -103,4 +102,5 @@ int main(int argc, char *argv[]) zap_fsk_demod_destroy(&fsk_data); close(fd); + return 0; } diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 7606d4bb74..252f0bcec8 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -58,6 +58,8 @@ int main(int argc, char *argv[]) zap_global_destroy(); + return 1; + } /* For Emacs: diff --git a/libs/freetdm/src/testtones.c b/libs/freetdm/src/testtones.c index d6b3a68552..2097f26df5 100644 --- a/libs/freetdm/src/testtones.c +++ b/libs/freetdm/src/testtones.c @@ -26,18 +26,18 @@ int main(int argc, char *argv[]) } if ((tmp.fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { - fprintf(stderr, "File Error!\n", strerror(errno)); + 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[]) diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index e3cb6d9050..97c0f87223 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -47,7 +47,7 @@ zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint3 return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char *number) +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); @@ -61,7 +61,7 @@ zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, char *date, char return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, uint8_t *data, uint32_t datalen) +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; From b2623fb871888a1194a32c4f065d3767dc258473 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 19:40:40 +0000 Subject: [PATCH 1031/1766] Codingstyle cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@535 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/5ESSStateNT.c | 154 +- libs/openzap/src/isdn/5ESSStateTE.c | 329 +- libs/openzap/src/isdn/5ESSmes.c | 441 +-- libs/openzap/src/isdn/DMSStateNT.c | 120 +- libs/openzap/src/isdn/DMSStateTE.c | 279 +- libs/openzap/src/isdn/DMSmes.c | 153 +- libs/openzap/src/isdn/EuroISDNStateNT.c | 18 +- libs/openzap/src/isdn/EuroISDNStateTE.c | 16 +- libs/openzap/src/isdn/Q931.c | 624 ++-- libs/openzap/src/isdn/Q931StateNT.c | 933 +++--- libs/openzap/src/isdn/Q931StateTE.c | 1107 +++---- libs/openzap/src/isdn/Q931ie.c | 3704 +++++++++++----------- libs/openzap/src/isdn/Q931mes.c | 1603 +++++----- libs/openzap/src/isdn/Q932mes.c | 150 +- libs/openzap/src/isdn/include/DMS.h | 16 +- libs/openzap/src/isdn/include/Q931.h | 134 +- libs/openzap/src/isdn/include/Q931ie.h | 248 +- libs/openzap/src/isdn/include/Q932.h | 2 +- libs/openzap/src/isdn/include/mfifo.h | 8 +- libs/openzap/src/isdn/include/national.h | 20 +- libs/openzap/src/isdn/mfifo.c | 275 +- libs/openzap/src/isdn/nationalStateNT.c | 130 +- libs/openzap/src/isdn/nationalStateTE.c | 252 +- libs/openzap/src/isdn/nationalmes.c | 147 +- 24 files changed, 5286 insertions(+), 5577 deletions(-) diff --git a/libs/openzap/src/isdn/5ESSStateNT.c b/libs/openzap/src/isdn/5ESSStateNT.c index d2a5540c32..1eb9415422 100644 --- a/libs/openzap/src/isdn/5ESSStateNT.c +++ b/libs/openzap/src/isdn/5ESSStateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -25,14 +25,14 @@ 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. + * 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 @@ -53,80 +53,80 @@ 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. + 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(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); + 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); + /* 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.*/ + /* 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 */ + /* TODO define state table here */ } diff --git a/libs/openzap/src/isdn/5ESSStateTE.c b/libs/openzap/src/isdn/5ESSStateTE.c index 62594212e3..ce2425e0e0 100644 --- a/libs/openzap/src/isdn/5ESSStateTE.c +++ b/libs/openzap/src/isdn/5ESSStateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -32,14 +32,14 @@ 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. + * 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 @@ -61,159 +61,159 @@ 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. + 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(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); + 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); + /* 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.*/ + /* 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 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 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 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 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 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 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 7 Call Received */ + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); - /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE,4); + /* 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 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 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 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 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); + /* 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ } @@ -224,37 +224,33 @@ void ATT5ESSCreateTE(L3UCHAR i) *****************************************************************************/ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom ==2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) { - printf("autoServiceAck is on, responding to Service Req from network...\n"); + printf("autoServiceAck is on, responding to Service Req from network...\n"); Q931AckService(pTrunk, buf); } - } return ret; @@ -267,31 +263,28 @@ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom == 2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c index 3e4b316d98..17f7ec8c77 100644 --- a/libs/openzap/src/isdn/5ESSmes.c +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: 5ESSmes.c + 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. + 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. + See 5ESS.h for description. License/Copyright: @@ -24,14 +24,14 @@ 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. + * 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 @@ -51,287 +51,300 @@ /***************************************************************************** - Function: ATT5ESSUmes_Setup + 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_lock = 1; + 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; - } + 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 ((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: - 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; - } + 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 { - return Q931E_ILLEGAL_IE; - } - } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + } else { + return Q931E_ILLEGAL_IE; + } + } + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: ATT5ESSPmes_Setup + 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. + 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. + 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 + 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; + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; - /* Q931 Message Header */ + /* Q931 Message Header */ Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - - /* Sending Complete */ - if(Q931IsIEPresent(pMes->SendComplete)) - OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + + /* Sending Complete */ + if (Q931IsIEPresent(pMes->SendComplete)) { + OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + } - /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) - OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 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; - } + /* 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; + /* 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; + /* 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; + /* 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; + /* 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; + /* 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; + /* 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; + /* 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 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; + /* 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 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; + /* 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; + /* 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 */ + /* 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; + /* 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; + /* 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; + *OSize = Octet; + return rc; } /***************************************************************************** - Function: ATT5ESSUmes_0x0f + 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 == 8) { + return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); + } - if (mes->ProtDisc == 3) { - return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size); - } + if (mes->ProtDisc == 3) { + return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: ATT5ESSPmes_0x0f + 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; + Q931mes_Generic *mes = (Q931mes_Generic *)IBuf; - if (mes->ProtDisc == 8) { - return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 8) { + return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize); + } - if (mes->ProtDisc == 3) { - return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 3) { + return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: ATT5ESSUmes_0x07 + 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 == 8) { + return Q931Umes_Connect(pTrunk, IBuf, mes, IOff, Size); + } - if (mes->ProtDisc == 3) { - return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size); - } + if (mes->ProtDisc == 3) { + return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: ATT5ESSPmes_0x07 + 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; + Q931mes_Generic *mes = (Q931mes_Generic *)IBuf; - if (mes->ProtDisc == 8) { - return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 8) { + return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize); + } - if (mes->ProtDisc == 3) { - return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 3) { + return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } diff --git a/libs/openzap/src/isdn/DMSStateNT.c b/libs/openzap/src/isdn/DMSStateNT.c index 6c75029665..e8814ba8ef 100644 --- a/libs/openzap/src/isdn/DMSStateNT.c +++ b/libs/openzap/src/isdn/DMSStateNT.c @@ -22,12 +22,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -57,66 +57,66 @@ *****************************************************************************/ 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(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); + 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_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 */ diff --git a/libs/openzap/src/isdn/DMSStateTE.c b/libs/openzap/src/isdn/DMSStateTE.c index 8c435fa8c2..5de657d7d9 100644 --- a/libs/openzap/src/isdn/DMSStateTE.c +++ b/libs/openzap/src/isdn/DMSStateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -29,12 +29,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -65,149 +65,149 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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); + 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); + 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); + 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); + 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); + 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); + 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); + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4); + 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); + 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); + 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); + 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); + 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); + 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ } @@ -218,36 +218,32 @@ void DMSCreateTE(L3UCHAR i) *****************************************************************************/ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom == 2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) { Q931AckService(pTrunk, buf); } - } return ret; @@ -260,31 +256,28 @@ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom == 2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; diff --git a/libs/openzap/src/isdn/DMSmes.c b/libs/openzap/src/isdn/DMSmes.c index b32664b767..3ce82f2ded 100644 --- a/libs/openzap/src/isdn/DMSmes.c +++ b/libs/openzap/src/isdn/DMSmes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: DMSmes.c + 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. + 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. + See national.h for description. License/Copyright: @@ -21,12 +21,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -48,19 +48,18 @@ /***************************************************************************** - Function: DMSUmes_Setup + 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; + L3INT ir = 0; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; L3UCHAR last_codeset = 0, codeset = 0; L3UCHAR shift_lock = 1; - while(IOff < Size) - { + while (IOff < Size) { if (!shift_lock) { codeset = last_codeset; } @@ -75,8 +74,7 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me } if (codeset == 0) { - switch(IBuf[IOff]) - { + switch (IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: @@ -94,11 +92,11 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + if (ir < 2) { rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else { @@ -110,11 +108,10 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me break; } } else if (codeset == 6) { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -126,13 +123,13 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me return Q931E_ILLEGAL_IE; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: DMSPmes_Setup + 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 @@ -150,115 +147,129 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me *****************************************************************************/ L3INT DMSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + 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)) + /* Sending Complete */ + if (Q931IsIEPresent(pMes->SendComplete)) { OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + } /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) + 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) + 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; + } 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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)) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: DMSUmes_0x0f + Function: DMSUmes_0x0f *****************************************************************************/ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) @@ -276,7 +287,7 @@ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes /***************************************************************************** - Function: DMSPmes_0x0f + Function: DMSPmes_0x0f *****************************************************************************/ L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) @@ -296,7 +307,7 @@ L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, /***************************************************************************** - Function: DMSUmes_0x07 + Function: DMSUmes_0x07 *****************************************************************************/ L3INT DMSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) @@ -314,7 +325,7 @@ L3INT DMSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes /***************************************************************************** - Function: DMSPmes_0x07 + Function: DMSPmes_0x07 *****************************************************************************/ L3INT DMSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) diff --git a/libs/openzap/src/isdn/EuroISDNStateNT.c b/libs/openzap/src/isdn/EuroISDNStateNT.c index ccfaba0d16..6b26c91e04 100644 --- a/libs/openzap/src/isdn/EuroISDNStateNT.c +++ b/libs/openzap/src/isdn/EuroISDNStateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -19,12 +19,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -42,5 +42,3 @@ *****************************************************************************/ #include "Q931.h" - - diff --git a/libs/openzap/src/isdn/EuroISDNStateTE.c b/libs/openzap/src/isdn/EuroISDNStateTE.c index 7b7433e567..ef6b39e8e5 100644 --- a/libs/openzap/src/isdn/EuroISDNStateTE.c +++ b/libs/openzap/src/isdn/EuroISDNStateTE.c @@ -4,11 +4,11 @@ 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. + 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: @@ -19,12 +19,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 6591613d71..9b9b6331bd 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -1,9 +1,9 @@ /***************************************************************************** - FileName: Q931.c + FileName: Q931.c - Contents: Implementation of Q.931 stack main interface functions. - See q931.h for description. + Contents: Implementation of Q.931 stack main interface functions. + See q931.h for description. License/Copyright: @@ -14,14 +14,14 @@ 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. + * 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 @@ -71,11 +71,7 @@ q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE]; q931timeout_func_t *Q931Timeout[Q931MAXDLCT][Q931MAXTIMER]; q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; -void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)= -{ - NULL, - NULL -}; +void (*Q931CreateDialectCB[Q931MAXDLCT])(L3UCHAR iDialect) = { NULL, NULL }; Q931State Q931st[Q931MAXSTATE]; @@ -85,10 +81,10 @@ Q931State Q931st[Q931MAXSTATE]; *****************************************************************************/ -L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */ - /* at head of each message. */ +L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */ + /* at head of each message. */ -L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ +L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ /***************************************************************************** @@ -96,201 +92,195 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ *****************************************************************************/ -Q931ErrorCB_t Q931ErrorProc; - /* callback for error messages. */ - -L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ +Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */ +L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ /***************************************************************************** - Function: Q931SetL4HeaderSpace + 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. + 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; + Q931L4HeaderSpace = space; } /***************************************************************************** - Function: Q931SetL2HeaderSpace + 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. + 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; + Q931L2HeaderSpace = space; } /***************************************************************************** - Function: Q931ProcDummy + Function: Q931ProcDummy Description: Dummy function for message processing. *****************************************************************************/ L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) { - return Q931E_INTERNAL; + return Q931E_INTERNAL; } /***************************************************************************** - Function: Q931UmesDummy + 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; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: Q931UieDummy + 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; + return Q931E_UNKNOWN_IE; } /***************************************************************************** - Function: Q931PmesDummy + 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; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: Q931PieDummy + Function: Q931PieDummy Description: Dummy function for message processing *****************************************************************************/ L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - return Q931E_UNKNOWN_IE; + return Q931E_UNKNOWN_IE; } /***************************************************************************** - Function: Q931TxDummy + Function: Q931TxDummy Description: Dummy function for message processing *****************************************************************************/ L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n) { - return Q931E_MISSING_CB; + return Q931E_MISSING_CB; } /***************************************************************************** - Function: Q931ErrorDummy + Function: Q931ErrorDummy Description: Dummy function for error processing *****************************************************************************/ L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) { - return 0; + return 0; } /***************************************************************************** - Function: Q931Initialize + 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. + 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. + Note: Initialization of other stacks should be inserted after + the initialization of EuroISDN. *****************************************************************************/ void Q931Initialize() { - L3INT x,y; + L3INT x,y; - /* Secure the callbacks to default procs */ - Q931ErrorProc = Q931ErrorDummy; + /* 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; + /* 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_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_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_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_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_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_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_TE] == NULL) + Q931AddDialect(Q931_Dialect_5ESS + Q931_TE, ATT5ESSCreateTE); - if(Q931CreateDialectCB[Q931_Dialect_5ESS + Q931_NT] == NULL) - Q931AddDialect(Q931_Dialect_5ESS + Q931_NT, ATT5ESSCreateNT); + 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); - } - } + /* 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); + } + } } /** @@ -304,20 +294,20 @@ void Q931TimerTick(Q931_TrunkInfo_t *pTrunk) 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. + /* 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++) { + for (x = 0; x < Q931MAXCALLPERTRUNK; x++) { call = &pTrunk->call[x]; - if(!call->InUse || !call->Timer || !call->TimerID) + if (!call->InUse || !call->Timer || !call->TimerID) continue; - if(call->Timer <= now) { + if (call->Timer <= now) { /* Stop Timer */ Q931StopTimer(pTrunk, x, call->TimerID); @@ -329,23 +319,23 @@ void Q931TimerTick(Q931_TrunkInfo_t *pTrunk) /***************************************************************************** - Function: Q931Rx23 + 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. + 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. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT Size) @@ -357,7 +347,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT IOff = 0; L3INT L2HSize = Q931L2HeaderSpace; - switch(ind) { + switch (ind) { case Q921_DL_UNIT_DATA: /* DL-UNITDATA indication (UI frame, 3 byte header) */ L2HSize = 3; @@ -382,12 +372,12 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, * a) doing Q.921 work in the lower levels (extracting the TEI ourselves) * b) adding a tei parameter to _all_ Proc functions */ - if(tei) { + 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) { + if (RetCode == Q931E_NO_ERROR && !pTrunk->call[callIndex].Tei) { pTrunk->call[callIndex].Tei = tei; } } @@ -396,8 +386,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, 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) - { + if (RetCode >= Q931E_NO_ERROR) { RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); } break; @@ -411,70 +400,70 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, /***************************************************************************** - Function: Q931Tx34 + 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. + 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. + 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; + if (pTrunk->Q931Tx34CBProc) { + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); + } + return Q931E_MISSING_CB; } /***************************************************************************** - Function: Q931Rx43 + Function: Q931Rx43 Description: Receive message from Layer 4 (application). Parameters: pTrunk[IN] Trunk #. - buf[IN] Message Pointer. - Size[IN] Message size in bytes. + 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. + 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; + 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); + RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); Q931Log(pTrunk, Q931_LOG_DEBUG, "Q931Rx43 return code: %d\n", RetCode); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Tx32 + 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. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size) @@ -491,15 +480,14 @@ L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT /* Call pack function through table. */ RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Offset], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { + if (RetCode >= Q931E_NO_ERROR) { L3INT callIndex; L3UCHAR tei = 0; - if(ptr->CRV) { + if (ptr->CRV) { /* Find the call using CRV */ RetCode = Q931FindCRV(pTrunk, ptr->CRV, &callIndex); - if(RetCode != Q931E_NO_ERROR) + if (RetCode != Q931E_NO_ERROR) return RetCode; tei = pTrunk->call[callIndex].Tei; @@ -518,54 +506,53 @@ L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT /***************************************************************************** - Function: Q931SetError + 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. + 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); - } + if (pTrunk->Q931ErrorCBProc) { + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } else { + Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } } void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) { - Q931ErrorProc = Q931ErrorPar; + Q931ErrorProc = Q931ErrorPar; } /***************************************************************************** - Function: Q931CreateCRV + 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. + 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. + 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) + see q931errors.h for details. +****************************************************************************/ +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) { - L3INT CRV = Q931GetUniqueCRV(pTrunk); + L3INT CRV = Q931GetUniqueCRV(pTrunk); - return Q931AllocateCRV(pTrunk, CRV, callIndex); + return Q931AllocateCRV(pTrunk, CRV, callIndex); } -L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV) +L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV) { int callIndex; @@ -579,66 +566,61 @@ L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV) /***************************************************************************** - Function: Q931AllocateCRV + Function: Q931AllocateCRV Description: Allocate a call table entry and assigns the given CRV value - to it. + to it. - Parameters: pTrunk [IN] Trunk number - iCRV [IN] Call Reference Value. - callindex [OUT] return call table index. + 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. + see q931errors.h for details. *****************************************************************************/ -L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) +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; + 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 + Function: Q931GetCallState Description: Look up CRV and return current call state. A non existing - CRV is the same as state zero (0). + CRV is the same as state zero (0). - Parameters: pTrunk [IN] Trunk number. - iCRV [IN] CRV + Parameters: pTrunk [IN] Trunk number. + iCRV [IN] CRV Return Value: Call State. *****************************************************************************/ -L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) +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 */ + 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 */ } /** @@ -653,11 +635,10 @@ L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerI { L3ULONG duration = Q931Timer[pTrunk->Dialect][iTimerID]; - if(duration) { + if (duration) { pTrunk->call[callIndex].Timer = Q931GetTime() + duration; pTrunk->call[callIndex].TimerID = iTimerID; } - return 0; } @@ -671,7 +652,7 @@ L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerI */ L3INT Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimerID) { - if(pTrunk->call[callindex].TimerID == iTimerID) + if (pTrunk->call[callindex].TimerID == iTimerID) pTrunk->call[callindex].TimerID = 0; return 0; @@ -679,148 +660,137 @@ L3INT Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimerID L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) { - pTrunk->call[callIndex].State = iState; + pTrunk->call[callIndex].State = iState; - return 0; + return 0; } L3ULONG Q931GetTime() { - L3ULONG tNow = 0; - static L3ULONG tLast = 0; + L3ULONG tNow = 0; + static L3ULONG tLast = 0; - if(Q931GetTimeProc != NULL) - { - tNow = Q931GetTimeProc(); - if(tNow < tLast) /* wrapped */ - { - /* TODO */ - } - tLast = tNow; - } - return tNow; + if (Q931GetTimeProc != NULL) { + tNow = Q931GetTimeProc(); + if (tNow < tLast) { /* wrapped */ + /* TODO */ + } + tLast = tNow; + } + return tNow; } void Q931SetGetTimeCB(L3ULONG (*callback)(void)) { - Q931GetTimeProc = callback; + 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; + 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; - } + if (i < Q931MAXDLCT) { + Q931CreateDialectCB[i] = callback; + } } /***************************************************************************** - Function: Q931AddStateEntry + Function: Q931AddStateEntry Description: Find an empty entry in the dialects state table and add this - entry. + 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; - } - } + 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 + Function: Q931IsEventLegal Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + Message is legal in this state or not. - Note: Someone write a bsearch or invent something smart here - please - sequential is ok for now. + 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; + 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() + Function: q931_error_to_name() Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + Message is legal in this state or not. - Note: Someone write a bsearch or invent something smart here - please - sequential is ok for now. + 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_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 */ + "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 */ }; @@ -828,14 +798,14 @@ static const char *q931_error_names[] = { 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]; + 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 @@ -844,24 +814,24 @@ const char *q931_error_to_name(q931_error_t error) L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...) { - char buf[Q931_LOGBUFSIZE]; + char buf[Q931_LOGBUFSIZE]; L3INT len; va_list ap; - if(!trunk->Q931LogCBProc) + if (!trunk->Q931LogCBProc) return 0; - if(trunk->loglevel < level) + if (trunk->loglevel < level) return 0; va_start(ap, fmt); len = vsnprintf(buf, sizeof(buf)-1, fmt, ap); - if(len <= 0) { + if (len <= 0) { /* TODO: error handling */ return -1; } - if(len >= sizeof(buf)) + if (len >= sizeof(buf)) len = sizeof(buf) - 1; buf[len] = '\0'; @@ -877,7 +847,7 @@ L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, .. */ void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv) { - trunk->Q931LogCBProc = func; + trunk->Q931LogCBProc = func; trunk->PrivateDataLog = priv; } diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index af74ef0e8b..5b8b0860b4 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -19,12 +19,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -56,76 +56,76 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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); - /* 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.*/ + /* 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 */ @@ -153,24 +153,22 @@ void Q931CreateNT(L3UCHAR i) *****************************************************************************/ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + if (iFrom == 4) { + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); + else if (iFrom == 2) { + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -182,28 +180,26 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -215,28 +211,26 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF *****************************************************************************/ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -248,28 +242,26 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -281,28 +273,26 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -316,71 +306,61 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT rc=0; Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; + 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; - } + /* 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; + if (iFrom == 4) { + ret = Q931CreateCRV(pTrunk, &callIndex); + if (ret) + return ret; - /* - * 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; + pMes->CRV = pTrunk->call[callIndex].CRV; - Q931StartTimer(pTrunk, callIndex, 303); + /* + * 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; - Q931SetState(pTrunk, callIndex, Q931_U1); - } + Q931StartTimer(pTrunk, callIndex, 303); + 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) - 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; + 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) { + 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, 303); + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); + Q931StartTimer(pTrunk, callIndex, 303); #endif - } return rc; @@ -399,28 +379,26 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -432,28 +410,26 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -465,28 +441,26 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -498,28 +472,26 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -531,28 +503,26 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro *****************************************************************************/ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -564,28 +534,26 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -597,28 +565,26 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -630,28 +596,26 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -663,28 +627,26 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -696,28 +658,26 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -729,28 +689,26 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -762,28 +720,26 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -795,28 +751,26 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -828,28 +782,26 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -861,28 +813,26 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT *****************************************************************************/ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -894,28 +844,26 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -927,28 +875,26 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -960,28 +906,26 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -993,28 +937,26 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1030,28 +972,26 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1063,28 +1003,26 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1096,28 +1034,26 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1129,28 +1065,26 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1162,28 +1096,26 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1195,28 +1127,26 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1228,28 +1158,26 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1261,29 +1189,26 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + 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 index 552b39ff27..0d79daf656 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -26,12 +26,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -63,150 +63,151 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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); - /* 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.*/ + /* 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); + 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); + 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); + 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); + 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); + 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); + 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); + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4); + 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); + 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); + 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); + 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); + 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); + 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ /* Timer default values */ @@ -235,24 +236,22 @@ void Q931CreateTE(L3UCHAR i) *****************************************************************************/ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + if (iFrom == 4) { + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); + else if (iFrom == 2) { + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -264,28 +263,26 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -297,32 +294,29 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF *****************************************************************************/ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pTrunk->autoConnectAck) { Q931AckConnect(pTrunk, buf); } - } return ret; } @@ -334,28 +328,26 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -367,28 +359,26 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -400,73 +390,64 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT rc=0; Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; + 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; - } + /* 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; + 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; + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); + if (ret) + return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, 303); /* TODO: Add this back when we get the state stuff more filled out */ - //Q931SetState(pTrunk, callIndex, Q931_U1); - } + /*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 */ + 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; + } - 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) { + /* 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 - { + 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; + Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81); + return ret; } #if 0 /* TODO: Unreachable code??? */ - /* Set state U6 */ - Q931SetState(pTrunk, callIndex, Q931_U6); + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, 303); #endif - } - + } return rc; } @@ -485,22 +466,20 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + if (iFrom ==4) { + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { - Q931StartTimer(pTrunk, callIndex, 303); + else if (iFrom == 2) { + Q931StartTimer(pTrunk, callIndex, 303); } return ret; } @@ -512,34 +491,31 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT callIndex; - L3INT ret = Q931E_NO_ERROR; + 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; + 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; + /* Send RESUME to network */ + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); + if (ret != Q931E_NO_ERROR) + return ret; - /* Start timer T318 */ - Q931StartTimer(pTrunk, callIndex, 318); + /* Start timer T318 */ + Q931StartTimer(pTrunk, callIndex, 318); - /*set state U17 */ - Q931SetState(pTrunk, callIndex, Q931_U17); - } - else - { - return Q931E_ILLEGAL_MESSAGE; - } - return ret; + /* set state U17 */ + Q931SetState(pTrunk, callIndex, Q931_U17); + } else { + return Q931E_ILLEGAL_MESSAGE; + } + return ret; } /***************************************************************************** @@ -549,28 +525,26 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -582,28 +556,26 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -615,28 +587,26 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro *****************************************************************************/ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -648,28 +618,26 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -681,28 +649,26 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -714,28 +680,26 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -747,31 +711,29 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -783,19 +745,21 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - 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); - } + 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) @@ -813,27 +777,24 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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 (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) + 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); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - } return ret; } @@ -845,32 +806,29 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* TODO - Set correct timer here */ Q931StartTimer(pTrunk, callIndex, 303); } - /* TODO chack against state table for illegal or unexpected message here*/ + /* 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); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pTrunk->autoRestartAck) { Q931AckRestart(pTrunk, buf); @@ -886,30 +844,28 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* TODO - Set correct timer here */ Q931StartTimer(pTrunk, callIndex, 303); } - /* TODO chack against state table for illegal or unexpected message here*/ + /* 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); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -921,28 +877,26 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -954,28 +908,26 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT *****************************************************************************/ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -987,28 +939,26 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1020,28 +970,26 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1053,28 +1001,26 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1086,28 +1032,26 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1123,28 +1067,26 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1156,28 +1098,26 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1189,28 +1129,26 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1222,28 +1160,26 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1255,28 +1191,26 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1288,28 +1222,26 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1321,28 +1253,26 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1354,29 +1284,26 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } - diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index d7716bc3da..095e8cd577 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -1,28 +1,28 @@ /***************************************************************************** - FileName: Q931ie.c + FileName: Q931ie.c - Contents: Information Element Pack/Unpack functions. + 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. + 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. + 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: + 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). + 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. + used in QSIG, NI2, Q.932 etc are located in separate files. - See q931.h for description. + See q931.h for description. License/Copyright: @@ -33,12 +33,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -59,40 +59,39 @@ /***************************************************************************** - Macro: Q931MoreIE + 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. + 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 Q931MoreIE() (Octet + Off - 2 < IESize) -#define Q931IESizeTest(x) {\ - if(Octet+Off-2 != IESize)\ - {\ - Q931SetError(pTrunk,x, Octet, Off);\ - return x;\ - }\ - } +#define Q931IESizeTest(x) {\ + if (Octet + Off - 2 != IESize) {\ + Q931SetError(pTrunk, x, Octet, Off);\ + return x;\ + }\ +} /***************************************************************************** - Function: Q931ReadExt + 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. + 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. + 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 + Parameters: IBuf ptr to octet array. + Off Starting offset counter Return Value: New offset value. @@ -100,27 +99,27 @@ L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off) { - L3INT c =0; - while((IBuf[c] & 0x80) == 0) - c++; - - return Off + c; + L3INT c = 0; + while ((IBuf[c] & 0x80) == 0) { + c++; + } + return Off + c; } /***************************************************************************** - Function: Q931Uie_BearerCap + 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 + 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. + 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 @@ -128,900 +127,852 @@ L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off) L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { - Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; + Q931ie_BearerCap *pie = (Q931ie_BearerCap*)OBuf; ie *pIE = &pMsg->BearerCap; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - *pIE=0; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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 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 */ + 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 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 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. */ + /* 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; - } + 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 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 5c */ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { + /* Octet 5d */ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->DuplexMode = ieGetOctet((IBuf[Octet + Off] & 0x40) >> 6); + pie->ModemType = ieGetOctet(IBuf[Octet + Off] & 0x3f); + Off ++; + } + } + } + } + } - 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 6 */ + if ((IBuf[Octet + Off] & 0x60) == 0x40 && Q931MoreIE()) { + pie->Layer2Ident = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5); + pie->UIL2Prot = ieGetOctet(IBuf[Octet + Off] & 0x1f); - /* Octet 5d */ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { + Off = Q931ReadExt(&IBuf[Octet + Off], Off); + Octet ++; + } - pie->DuplexMode = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6); - pie->ModemType = ieGetOctet(IBuf[Octet+Off] & 0x3f); - Off ++; - } - } - } - } - } + /* 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 6 */ - if((IBuf[Octet+Off] & 0x60) == 0x40 && Q931MoreIE()) - { - pie->Layer2Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5); - pie->UIL2Prot = ieGetOctet(IBuf[Octet+Off] & 0x1f); + /* Octet 7a */ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + if (pie->UIL3Prot == 0x0c) { + pie->AL3Info1 = ieGetOctet(IBuf[Octet + Off] & 0x0f); + Off++; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); - Octet ++; - } + /* 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; - /* 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); + Q931IESizeTest(Q931E_BEARERCAP); + Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_BearerCap + 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. + 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. + 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 + 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; + 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 */ + OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; + li = (*Octet)++; /* remember length position */ - /* Octet 3 - Coding standard / Information transfer capability */ + /* Octet 3 - Coding standard / Information transfer capability */ OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | (pIE->ITC & 0x1f); - /* Octet 4 - Transfer mode / Information transfer rate */ + /* 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 */ + 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))) - { + 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 */ + + /* 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 + /* 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 + } + 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 + /* 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 */ + /* 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) { + /* 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) - { + /* 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 */ + /* Octet 7a - Additional information layer 3 msb */ OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1 & 0x0f); - /* Octet 7b - Additional information layer 3 lsb */ + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallID + 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 + 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. + 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; + Q931ie_CallID *pie = (Q931ie_CallID*)OBuf; ie *pIE = &pMsg->CallID; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - do{ - pie->CallId[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while(Q931MoreIE()); + /* Octet 3 */ + do { + pie->CallId[x] = IBuf[Octet + Off] & 0x7f; + Off++; + x++; + } while (Q931MoreIE()); - Q931IESizeTest(Q931E_CALLID); - - Q931SetIE(*pIE, *OOff); + 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); + *OOff = (*OOff) + sizeof(Q931ie_CallID) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallID + Function: Q931Pie_CallID - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 */ + OBuf[(*Octet)++] = Q931ie_CALL_IDENTITY ; + li = (*Octet)++; /* remember length position */ - for(x=0;x < sCI; x++) - { - OBuf[(*Octet)++] = pIE->CallId[x]; - } + for (x = 0; x < sCI; x++) { + OBuf[(*Octet)++] = pIE->CallId[x]; + } - OBuf[(*Octet)-1] |= 0x80; /* set complete flag at last octet*/ + OBuf[(*Octet) - 1] |= 0x80; /* set complete flag at last octet*/ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallState + 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 + 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. + 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; + Q931ie_CallState *pie = (Q931ie_CallState*)OBuf; ie *pIE = &pMsg->CallState; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; + /* Octet 3 */ + pie->CodStand = (IBuf[Octet + Off] >> 6) & 0x03; + pie->CallState = IBuf[Octet + Off] & 0x3f; + Octet++; - /* Octet 3 */ - pie->CodStand = (IBuf[Octet+Off] >> 6) & 0x03; - pie->CallState= IBuf[Octet+Off] & 0x3f; - - Octet++; - - Q931IESizeTest(Q931E_CALLSTATE); - - Q931SetIE(*pIE, *OOff); + Q931IESizeTest(Q931E_CALLSTATE); + Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallState); - pie->Size = sizeof(Q931ie_CallState); + *OOff = (*OOff) + sizeof(Q931ie_CallState); + pie->Size = sizeof(Q931ie_CallState); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallState + Function: Q931Pie_CallState - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; + 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)++] = Q931ie_CALL_STATE; + li = (*Octet)++; /* remember length position */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CalledSub + 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 + 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. + 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; + Q931ie_CalledSub *pie = (Q931ie_CalledSub*)OBuf; ie *pIE = &pMsg->CalledSub; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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); + /* 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); + 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); + *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CalledSub + Function: Q931Pie_CalledSub - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 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]; - } + /* 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[(*Octet) - 1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CalledNum + 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 + 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. + 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; + Q931ie_CalledNum *pie = (Q931ie_CalledNum*)OBuf; ie *pIE = &pMsg->CalledNum; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; /* # digits in this case */ + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; /* # digits in this case */ - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet++]; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; - pie->NumPlanID = IBuf[Octet+Off] & 0x0f; - 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()); + /* 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); + Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x); + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CalledNum + Function: Q931Pie_CalledNum - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 1 */ + OBuf[(*Octet)++] = Q931ie_CALLED_PARTY_NUMBER; + /* Octet 2 */ - li=(*Octet)++; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->NumPlanID); - - /* Octet 4 */ - for(x=0;xDigit[x]; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallingNum + 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 + 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. + 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; + Q931ie_CallingNum *pie = (Q931ie_CallingNum*)OBuf; ie *pIE = &pMsg->CallingNum; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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 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; - do{ - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - } while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); + /* 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'; - Q931IESizeTest(Q931E_CALLINGNUM); + Q931IESizeTest(Q931E_CALLINGNUM); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallingNum + Function: Q931Pie_CallingNum - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 1 */ + OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_NUMBER; /* Octet 2 */ - li=(*Octet)++; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID); - - /* Octet 4 */ - OBuf[(*Octet)++] = 0x80; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID); + + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80; - /* Octet 5 */ - for(x=0;xDigit[x]; - } + /* Octet 5 */ + for (x = 0; xDigit[x]; + } - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallingSub + 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 + 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. + 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; + Q931ie_CallingSub *pie = (Q931ie_CallingSub*)OBuf; ie *pIE = &pMsg->CallingSub; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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); + /* 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); + Q931IESizeTest(Q931E_CALLINGSUB); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallingSub + Function: Q931Pie_CallingSub - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 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]; - } + /* 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[(*Octet) - 1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_Cause + 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 + 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. + 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; + Q931ie_Cause *pie = (Q931ie_Cause*)OBuf; ie *pIE = &pMsg->Cause; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2*/ + IESize = IBuf[Octet++]; - /* Octet 3*/ - pie->CodStand = (IBuf[Octet+Off]>>5) & 0x03; - pie->Location = IBuf[Octet+Off] & 0x0f; + /* 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 3a */ + if ((IBuf[Octet + Off] & 0x80) == 0) { + Off++; + pie->Recom = IBuf[Octet + Off] & 0x7f; + } + Octet++; - /* Octet 4 */ - pie->Value = IBuf[Octet+Off] & 0x7f; + /* Octet 4 */ + pie->Value = IBuf[Octet + Off] & 0x7f; Octet++; /* Consume optional Diagnostic bytes */ @@ -1030,124 +981,123 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I }; Q931IESizeTest(Q931E_CAUSE); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Cause); + pie->Size = sizeof(Q931ie_Cause); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Cause); - pie->Size = sizeof(Q931ie_Cause); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Cause + Function: Q931Pie_Cause - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Cause *pIE = (Q931ie_Cause*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_CAUSE; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_CAUSE; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | pIE->Location; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | pIE->Location; - /* Octet 3a - currently not supported in send */ + /* Octet 3a - currently not supported in send */ - /* Octet 4 */ - OBuf[(*Octet)++] = 0x80 | pIE->Value; + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80 | pIE->Value; - /* Octet 5 - diagnostics not supported in send */ + /* Octet 5 - diagnostics not supported in send */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CongLevel + 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 + 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. + 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; + Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; ie *pIE = &pMsg->CongestionLevel; - L3INT Off = 0; - L3INT Octet = 0; + L3INT Off = 0; + L3INT Octet = 0; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet] & 0xf0; - pie->CongLevel = IBuf[Octet] & 0x0f; - Octet ++; + pie->IEId = IBuf[Octet] & 0xf0; + pie->CongLevel = IBuf[Octet] & 0x0f; + Octet ++; - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CongLevel); - pie->Size = sizeof(Q931ie_CongLevel); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CongLevel); + pie->Size = sizeof(Q931ie_CongLevel); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CongLevel + Function: Q931Pie_CongLevel - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; */ + Q931ie_CongLevel *pIE = (Q931ie_CongLevel*)IBuf; + L3INT rc = 0; + /* L3INT Beg = *Octet; */ - OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel; - - return rc; + OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel; + + return rc; } /***************************************************************************** - Function: Q931Uie_ChanID + 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 + 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. + 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 + Return Value: Error code, 0 = OK *****************************************************************************/ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) @@ -1178,22 +1128,20 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off = Q931ReadExt(&IBuf[Octet++], Off); /* Octet 3.1 */ - if(pie->IntIDPresent) - { - pie->InterfaceID = IBuf[Octet+Off] & 0x7f; + 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 = Q931ReadExt(&IBuf[Octet + Off], Off); Off++; } if ((Octet + Off - 2) != IESize) { /* Octet 3.2 */ - if(pie->IntType == 1) /* PRI etc */ - { + 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; @@ -1201,31 +1149,29 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * /* Octet 3.3 */ /* Temp fix. Assume B channel. H channels not supported */ - pie->ChanSlot = IBuf[Octet+Off] & 0x7f; + 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); + 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) - { + if (pTrunk->loglevel == Q931_LOG_DEBUG) { const char *iface; char tmp[100] = ""; - if(!pie->IntType) { - switch(pie->InfoChanSel) { + if (!pie->IntType) { + switch (pie->InfoChanSel) { case 0x0: iface = "None"; break; @@ -1251,1818 +1197,1714 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * ((pie->IntType) ? "PRI/Other" : "BRI"), tmp); } - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ChanID + Function: Q931Pie_ChanID - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_ChanID *pIE = (Q931ie_ChanID*)IBuf; L3INT rc = Q931E_NO_ERROR; L3INT Beg = *Octet; /* remember current offset */ - L3INT li; + L3INT li; - OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION; - li = (*Octet)++; /* remember length position */ + OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION; + li = (*Octet)++; /* remember length position */ - /* Octet 3 flags & BRI chan # */ - OBuf[(*Octet)++] = 0x80 + /* 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) - { + /* 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 + /* 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; + /* 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; + 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CRV + 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. + 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 + 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. + 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++]; + 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; - } + 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; + *IOff = Octet; + return CRV; } /***************************************************************************** - Function: Q931Uie_DateTime + 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 [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. + 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; + Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; ie *pIE = &pMsg->DateTime; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize=0; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize = 0; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet++]; - - /* Octet 2 */ - IESize = IBuf[Octet++]; + pie->IEId = IBuf[Octet++]; + + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 - Year */ - pie->Year = IBuf[Octet++]; + /* Octet 3 - Year */ + pie->Year = IBuf[Octet++]; - /* Octet 4 - Month */ - pie->Month = IBuf[Octet++]; + /* Octet 4 - Month */ + pie->Month = IBuf[Octet++]; - /* Octet 5 - Day */ - pie->Day = 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; + /******************************************************************* + 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 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 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++]; - } - } - } + /* Octet 8 - Second (optional)*/ + if (IESize >= 6) { + pie->Format = 3; + pie->Second = IBuf[Octet++]; + } + } + } - Q931IESizeTest(Q931E_DATETIME); + Q931IESizeTest(Q931E_DATETIME); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_DateTime); + pie->Size = sizeof(Q931ie_DateTime); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_DateTime); - pie->Size = sizeof(Q931ie_DateTime); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_DateTime + Function: Q931Pie_DateTime - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_DateTime *pIE = (Q931ie_DateTime*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_DATETIME; - li=(*Octet)++; + 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[(*Octet)++] = pIE->Year; + OBuf[(*Octet)++] = pIE->Month; + OBuf[(*Octet)++] = pIE->Day; + if (pIE->Format >= 1) { + OBuf[(*Octet)++] = pIE->Hour; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + 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 + 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 + 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. + 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; + Q931ie_Display *pie = (Q931ie_Display*)OBuf; ie *pIE = &pMsg->Display; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; + IESize = IBuf[Octet++]; - IESize = IBuf[Octet ++]; + for (x = 0; xDisplay[x] = IBuf[Octet + Off] & 0x7f; + Off++; + } - for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } + Q931IESizeTest(Q931E_DISPLAY); + Q931SetIE(*pIE, *OOff); - Q931IESizeTest(Q931E_DISPLAY); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); - 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; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Display + Function: Q931Pie_Display - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Display *pIE = (Q931ie_Display*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; + L3INT DSize; + L3INT x; - OBuf[(*Octet)++] = Q931ie_DISPLAY; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_DISPLAY; + li = (*Octet)++; - DSize = pIE->Size - sizeof(Q931ie_Display); + DSize = pIE->Size - sizeof(Q931ie_Display); - for(x=0; x< DSize; x++) - { - - OBuf[(*Octet)++] = pIE->Display[x]; - } + for (x = 0; x< DSize; x++) { + + OBuf[(*Octet)++] = pIE->Display[x]; + } - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_HLComp + 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 + 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. + 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; + Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; ie *pIE = &pMsg->HLComp; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet */ - IESize = 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 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); - } + /* 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); + Q931IESizeTest(Q931E_HLCOMP); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_HLComp); + pie->Size = sizeof(Q931ie_HLComp); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_HLComp); - pie->Size = sizeof(Q931ie_HLComp); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_HLComp + Function: Q931Pie_HLComp - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_HLComp *pIE = (Q931ie_HLComp*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_HIGH_LAYER_COMPATIBILITY; - li=(*Octet)++; + 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 3 */ + OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | ((pIE->Interpret << 2) & 0x1c) | (pIE->PresMeth & 0x03); - /* Octet 4 */ - OBuf[(*Octet)++] = pIE->HLCharID; + /* 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; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_KeypadFac + 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 + 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. + 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; + Q931ie_KeypadFac *pie = (Q931ie_KeypadFac*)OBuf; ie *pIE = &pMsg->KeypadFac; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; + IESize = IBuf[Octet++]; - IESize = IBuf[Octet ++]; + for (x = 0; xKeypadFac[x] = IBuf[Octet + Off] & 0x7f; + Off++; + } - for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } + Q931IESizeTest(Q931E_KEYPADFAC); + Q931SetIE(*pIE, *OOff); - Q931IESizeTest(Q931E_KEYPADFAC); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); - 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; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_KeypadFac + Function: Q931Pie_KeypadFac - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_KEYPAD_FACILITY; + li = (*Octet)++; - DSize = pIE->Size - sizeof(Q931ie_KeypadFac) + 1; + DSize = pIE->Size - sizeof(Q931ie_KeypadFac) + 1; - for(x=0; x< DSize; x++) - { - OBuf[(*Octet)++] = pIE->KeypadFac[x]; - } + for (x = 0; x< DSize; x++) { + OBuf[(*Octet)++] = pIE->KeypadFac[x]; + } - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_LLComp + 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 + 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. + 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; + Q931ie_LLComp *pie = (Q931ie_LLComp*)OBuf; ie *pIE = &pMsg->LLComp; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3*/ + /* Octet 3 */ + pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03; + pie->ITransCap = IBuf[Octet + Off] & 0x1f; + Octet++; - pie->CodStand = (IBuf[Octet+Off] >> 5) & 0x03; - pie->ITransCap= IBuf[Octet+Off] & 0x1f; + /* Octet 3a*/ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->NegotInd = (IBuf[Octet + Off] >> 6) & 0x01; + Off++; + } - Octet++; + /* Octet 4 */ + pie->TransMode = (IBuf[Octet + Off] >> 5) & 0x03; + pie->InfoRate = IBuf[Octet + Off] & 0x1f; - /* Octet 3a*/ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { - pie->NegotInd = (IBuf[Octet+Off] >> 6) & 0x01; - Off++; - } + Octet++; - /* Octet 4 */ - pie->TransMode = (IBuf[Octet+Off] >> 5) & 0x03; - pie->InfoRate = IBuf[Octet+Off] & 0x1f; + /* Octet 4.1 */ + if (pie->InfoRate == 0x14) { /* Mutirate */ + pie->RateMul = IBuf[Octet + Off] & 0x7f; + Off++; + } - Octet++; + /* 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 4.1 */ - if(pie->InfoRate == 0x14 ) /* Mutirate */ - { - pie->RateMul = IBuf[Octet+Off] & 0x7f; - Off++; - } + /* 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 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 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++; + /* 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 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 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 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 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 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 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 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 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 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 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 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 7b*/ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->DefPackSize = IBuf[Octet + Off] & 0x0f; + 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 7c */ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->PackWinSize= IBuf[Octet + Off] & 0x7f; + } + } + } + } + } - /* 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++; - } + Q931IESizeTest(Q931E_LLCOMP); + Q931SetIE(*pIE, *OOff); - /* Octet 7b*/ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { - pie->DefPackSize = IBuf[Octet+Off] & 0x0f; - Off++; + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_LLComp); + pie->Size = sizeof(Q931ie_LLComp); - /* 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; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_LLComp + Function: Q931Pie_LLComp - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; + Q931ie_LLComp *pIE = (Q931ie_LLComp*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_LOW_LAYER_COMPATIBILITY; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_LOW_LAYER_COMPATIBILITY; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = (pIE->CodStand << 6) | pIE->ITransCap; + /* Octet 3 */ + OBuf[(*Octet)++] = (pIE->CodStand << 6) | pIE->ITransCap; - /* Octet 3a*/ - OBuf[(*Octet)++] = 0x80 | (pIE->NegotInd << 6); + /* Octet 3a */ + OBuf[(*Octet)++] = 0x80 | (pIE->NegotInd << 6); - /* Octet 4 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode << 5) | pIE->InfoRate; + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode << 5) | pIE->InfoRate; - /* Octet 4.1*/ - if(pIE->InfoRate == 0x18) - { - OBuf[(*Octet)++] = 0x80 | pIE->RateMul; - } + /* 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; - } + /* 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 ; + /* 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 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 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 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 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 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 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 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; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_NetFac + 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 + 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. + 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; + Q931ie_NetFac *pie = (Q931ie_NetFac*)OBuf; ie *pIE = &pMsg->NetFac; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - pie->LenNetID = IBuf[Octet+Off]; /* full octet is used */ - 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++; + 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 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++; + /* Octet 4*/ + pie->NetFac = IBuf[Octet + Off]; /* Full Octet is used */ + Octet++; - Q931IESizeTest(Q931E_NETFAC); + Q931IESizeTest(Q931E_NETFAC); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_NetFac + Function: Q931Pie_NetFac - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_NETWORK_SPECIFIC_FACILITIES; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = pIE->LenNetID; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->LenNetID; - if(pIE->LenNetID > 0) - { - /* Octet 3.1 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypeNetID << 4) | pIE->NetIDPlan; + 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 3.2 */ + for (x = 0; x LenNetID; x++) { + OBuf[(*Octet)++] = pIE->NetID[x]; + } + } - /* Octet 4*/ - OBuf[(*Octet)++] = pIE->NetFac; + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->NetFac; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_NotifInd + 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 + 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. + 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; + Q931ie_NotifInd *pie = (Q931ie_NotifInd*)OBuf; ie *pIE = &pMsg->NotifInd; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2*/ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Notification = IBuf[Octet+Off] & 0x7f; + /* Octet 3 */ + pie->Notification = IBuf[Octet + Off] & 0x7f; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - Q931IESizeTest(Q931E_NOTIFIND); + Q931IESizeTest(Q931E_NOTIFIND); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NotifInd); + pie->Size = sizeof(Q931ie_NotifInd); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NotifInd); - pie->Size = sizeof(Q931ie_NotifInd); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_NotifInd + Function: Q931Pie_NotifInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_NotifInd *pIE = (Q931ie_NotifInd*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_NOTIFICATION_INDICATOR; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_NOTIFICATION_INDICATOR; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = pIE->Notification; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->Notification; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_ProgInd + 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 + 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. + 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; + Q931ie_ProgInd *pie = (Q931ie_ProgInd*)OBuf; ie *pIE = &pMsg->ProgInd; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3*/ - pie->CodStand = (IBuf[Octet+Off] >> 5) & 0x03; - pie->Location = IBuf[Octet+Off] & 0x0f; + /* Octet 3 */ + pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03; + pie->Location = IBuf[Octet + Off] & 0x0f; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - /* Octet 4*/ - pie->ProgDesc = IBuf[Octet+Off] & 0x7f; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + /* Octet 4 */ + pie->ProgDesc = IBuf[Octet + Off] & 0x7f; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - Q931IESizeTest(Q931E_PROGIND); + Q931IESizeTest(Q931E_PROGIND); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ProgInd); + pie->Size = sizeof(Q931ie_ProgInd); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_ProgInd); - pie->Size = sizeof(Q931ie_ProgInd); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ProgInd + Function: Q931Pie_ProgInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset L3INTo OBuf. + 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; + Q931ie_ProgInd *pIE = (Q931ie_ProgInd*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_PROGRESS_INDICATOR; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_PROGRESS_INDICATOR; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | pIE->Location; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | pIE->Location; - /* Octet 4*/ - OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_RepeatInd + 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 + 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. + 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; + Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; ie *pIE = &pMsg->RepeatInd; - L3INT Off = 0; - L3INT Octet = 0; + L3INT Off = 0; + L3INT Octet = 0; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet] & 0xf0; - pie->RepeatInd = IBuf[Octet] & 0x0f; - Octet ++; + pie->IEId = IBuf[Octet] & 0xf0; + pie->RepeatInd = IBuf[Octet] & 0x0f; + Octet ++; - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); - pie->Size = sizeof(Q931ie_RepeatInd); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); + pie->Size = sizeof(Q931ie_RepeatInd); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_RepeatInd + Function: Q931Pie_RepeatInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; */ + Q931ie_RepeatInd *pIE = (Q931ie_RepeatInd*)IBuf; + L3INT rc = 0; + /* L3INT Beg = *Octet; */ - OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd; - - return rc; + OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd; + + return rc; } /***************************************************************************** - Function: Q931Uie_RevChargeInd + 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 + 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. + 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 iE; /* ie *pIE = &pMsg->RevChargeInd; */ - Q931SetIE(iE, *OOff); + Q931SetIE(iE, *OOff); - return iE; + return iE; } /***************************************************************************** - Function: Q931Pie_RevChargeInd + Function: Q931Pie_RevChargeInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + Return Value: Error code, 0 = OK *****************************************************************************/ L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Uie_RestartInd + 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 + 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. + 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; + Q931ie_RestartInd *pie = (Q931ie_RestartInd*)OBuf; ie *pIE = &pMsg->RestartInd; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Class = IBuf[Octet+Off] & 0x07; - pie->Spare = IBuf[Octet+Off] & 0x78; + /* Octet 3 */ + pie->Class = IBuf[Octet + Off] & 0x07; + pie->Spare = IBuf[Octet + Off] & 0x78; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - Q931IESizeTest(Q931E_RESTARTIND); + Q931IESizeTest(Q931E_RESTARTIND); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RestartInd); - pie->Size = sizeof(Q931ie_RestartInd); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RestartInd); + pie->Size = sizeof(Q931ie_RestartInd); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_RestartInd + Function: Q931Pie_RestartInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_RestartInd *pIE = (Q931ie_RestartInd*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_RESTART_INDICATOR; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_RESTART_INDICATOR; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = 0x80 | pIE->Class ; + /* Octet 3*/ + OBuf[(*Octet)++] = 0x80 | pIE->Class ; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_Segment + 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 + 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. + 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; + Q931ie_Segment *pie = (Q931ie_Segment*)OBuf; ie *pIE = &pMsg->Segment; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; + Octet++; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2*/ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->FSI = (IBuf[Octet+Off] & 0x80) >> 7; - pie->NumSegRem = IBuf[Octet+Off] & 0x7f; - 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); + /* Octet 4 */ + pie->SegType = IBuf[Octet + Off] & 0x7f; + Octet++; + + Q931IESizeTest(Q931E_SEGMENT); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Segment); + pie->Size = sizeof(Q931ie_Segment); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Segment); - pie->Size = sizeof(Q931ie_Segment); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Segment + Function: Q931Pie_Segment - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Segment *pIE = (Q931ie_Segment*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_SEGMENTED_MESSAGE; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_SEGMENTED_MESSAGE; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = (pIE->FSI<<7) | pIE->NumSegRem; + /* Octet 3 */ + OBuf[(*Octet)++] = (pIE->FSI << 7) | pIE->NumSegRem; - /* Octet 4 */ - OBuf[(*Octet)++] = pIE->SegType; + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->SegType; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_SendComplete + 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 + 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. + 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; + Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; ie *pIE = &pMsg->SendComplete; - L3INT Off = 0; - L3INT Octet = 0; + L3INT Off = 0; + L3INT Octet = 0; - *pIE=0; + *pIE = 0; + Octet++; - Octet ++; + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_SendComplete); + pie->Size = sizeof(Q931ie_SendComplete); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_SendComplete); - pie->Size = sizeof(Q931ie_SendComplete); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ProgInd + Function: Q931Pie_ProgInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; */ + /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */ + L3INT rc = Q931E_NO_ERROR; + /* L3INT Beg = *Octet; */ - OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; + OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; - return rc; + return rc; } /***************************************************************************** - Function: Q931Uie_Signal + 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 + 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. + 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; + Q931ie_Signal *pie = (Q931ie_Signal*)OBuf; ie *pIE = &pMsg->Signal; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Signal = IBuf[Octet+Off]; - Octet++; + /* Octet 3 */ + pie->Signal = IBuf[Octet + Off]; + Octet++; - Q931IESizeTest(Q931E_SIGNAL); + Q931IESizeTest(Q931E_SIGNAL); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Signal); + pie->Size = sizeof(Q931ie_Signal); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Signal); - pie->Size = sizeof(Q931ie_Signal); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Signal + Function: Q931Pie_Signal - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Signal *pIE = (Q931ie_Signal*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_SIGNAL; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_SIGNAL; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = pIE->Signal; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->Signal; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_TransNetSel + 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 + 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. + 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; + Q931ie_TransNetSel *pie = (Q931ie_TransNetSel*)OBuf; ie *pIE = &pMsg->TransNetSel; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT l; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; + /* Octet 2 */ + l = IBuf[Octet++] - 3; - /* Octet 3*/ - pie->Type = (IBuf[Octet+Off] >> 4) & 0x07; + /* Octet 3 */ + pie->Type = (IBuf[Octet + Off] >> 4) & 0x07; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - for(x=0; x < l; x++) - { - pie->NetID[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } + for (x = 0; x < l; x++) { + pie->NetID[x] = IBuf[Octet + Off] & 0x7f; + Off++; + } - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_TransNetSel + Function: Q931Pie_TransNetSel - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_TRANSIT_NETWORK_SELECTION; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->Type<<4) | pIE->NetIDPlan; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | (pIE->Type << 4) | pIE->NetIDPlan; - /* Octet 4 */ - l = pIE->Size - sizeof(Q931ie_TransNetSel) + 1; - for(x=0;xNetID[x]; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_UserUser + 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 + 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. + 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; + Q931ie_UserUser *pie = (Q931ie_UserUser*)OBuf; ie *pIE = &pMsg->UserUser; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT l; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; + /* Octet 2 */ + l = IBuf[Octet++] - 3; - /* Octet 3*/ - pie->ProtDisc = IBuf[Octet+Off]; - Octet++; + /* Octet 3 */ + pie->ProtDisc = IBuf[Octet + Off]; + Octet++; - for(x=0; x < l; x++) - { - pie->User[x] = IBuf[Octet+Off]; - Off++; - } + for (x = 0; x < l; x++) { + pie->User[x] = IBuf[Octet + Off]; + Off++; + } - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_UserUser + Function: Q931Pie_UserUser - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_USER_USER; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = pIE->ProtDisc; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->ProtDisc; - /* Octet 4 */ - l = pIE->Size - sizeof(Q931ie_UserUser) + 1; - for(x=0;xUser[x]; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_GenericDigits + 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 + 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. + 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; + Q931ie_GenericDigits *pie = (Q931ie_GenericDigits*)OBuf; ie *pIE = &pMsg->GenericDigits; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Type = (IBuf[Octet]) & 0x1F; - pie->Encoding = (IBuf[Octet] >> 5) & 0x07; - Octet ++; - - /* Octet 4*/ + /* 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; + 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; + pie->Digit[x++] = IBuf[Octet + Off] & 0x0f; if (Q931MoreIE()) { - pie->Digit[x] = (IBuf[Octet+Off] >> 4) & 0x0f; + pie->Digit[x] = (IBuf[Octet + Off] >> 4) & 0x0f; } x++; Off++; @@ -3070,7 +2912,7 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U } else if (pie->Encoding == 2) { /* IA5 */ x = 0; do { - pie->Digit[x++] = IBuf[Octet+Off] & 0x7f; + pie->Digit[x++] = IBuf[Octet + Off] & 0x7f; Off++; } while (Q931MoreIE()); } else { @@ -3079,112 +2921,108 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U return Q931E_GENERIC_DIGITS; } - Q931IESizeTest(Q931E_GENERIC_DIGITS); + Q931IESizeTest(Q931E_GENERIC_DIGITS); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x - 1); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_GenericDigits + Function: Q931Pie_GenericDigits - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + OBuf[(*Octet)++] = 0; - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Uie_ChangeStatus + 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 + 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. + 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; + Q931ie_ChangeStatus *pie = (Q931ie_ChangeStatus*)OBuf; ie *pIE = &pMsg->ChangeStatus; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = 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 3 */ + pie->Preference = (IBuf[Octet + Off] >> 6) & 0x01; + pie->Spare = IBuf[Octet + Off] & 0x38; + pie->NewStatus = IBuf[Octet + Off] & 0x07; + Octet++; - Octet++; + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ChangeStatus); + pie->Size = sizeof(Q931ie_ChangeStatus); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_ChangeStatus); - pie->Size = sizeof(Q931ie_ChangeStatus); - - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ChangeStatus + Function: Q931Pie_ChangeStatus - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_ChangeStatus *pIE = (Q931ie_ChangeStatus*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_CHANGE_STATUS; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_CHANGE_STATUS; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = 0x80 | pIE->NewStatus | ((pIE->Preference & 0x01) << 6); + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | pIE->NewStatus | ((pIE->Preference & 0x01) << 6); - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 43a5098f62..f77f3837f1 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: Q931mes.c + 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. + 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. + See q931.h for description. License/Copyright: @@ -18,12 +18,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -54,38 +54,35 @@ L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OB 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 */ + 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++] = 1; /* length is 1 octet */ + OBuf[Octet++] = (L3UCHAR) (mes->CRV & 0x7f) | ((mes->CRVFlag << 7) & 0x80); /* CRV & flag */ } - OBuf[Octet++] = mes->MesType; /* message header */ + OBuf[Octet++] = mes->MesType; /* message header */ *IOff = Octet; - return 0; } /***************************************************************************** - Function: Q931Umes_Alerting + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: @@ -93,7 +90,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic case Q931ie_SIGNAL: 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -101,82 +98,84 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Alerting + Function: Q931Pmes_Alerting *****************************************************************************/ L3INT Q931Pmes_Alerting(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 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) + 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_CallProceeding + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -184,103 +183,103 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_G break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_CallProceeding + Function: Q931Pmes_CallProceeding *****************************************************************************/ L3INT Q931Pmes_CallProceeding(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 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_CongestionControl + Function: Q931Umes_CongestionControl *****************************************************************************/ L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(mes); - NoWarning(IBuf); + NoWarning(mes); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Pmes_CongestionControl + Function: Q931Pmes_CongestionControl *****************************************************************************/ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); *OSize = 0; - - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Umes_Connect + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: @@ -291,7 +290,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic case Q931ie_HIGH_LAYER_COMPATIBILITY: case Q931ie_CONNECTED_NUMBER: /* not actually used, seen while testing BRI PTMP TE */ rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) + if (rc != Q931E_NO_ERROR) return rc; break; @@ -304,89 +303,91 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Connect + Function: Q931Pmes_Connect *****************************************************************************/ L3INT Q931Pmes_Connect(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 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ConnectAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -394,131 +395,61 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ConnectAck + Function: Q931Pmes_ConnectAck *****************************************************************************/ L3INT Q931Pmes_ConnectAck(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Disconnect + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_CAUSE: case Q931ie_PROGRESS_INDICATOR: case Q931ie_DISPLAY: case Q931ie_SIGNAL: 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; - 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -528,132 +459,203 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gene } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Information + 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) { - L3INT rc = Q931E_NO_ERROR; 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)) + /* 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Notify + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Notify + Function: Q931Pmes_Notify *****************************************************************************/ L3INT Q931Pmes_Notify(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Progress + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -661,72 +663,76 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Progress + Function: Q931Pmes_Progress *****************************************************************************/ L3INT Q931Pmes_Progress(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 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Release + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_CAUSE: 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -734,61 +740,64 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Release + Function: Q931Pmes_Release *****************************************************************************/ L3INT Q931Pmes_Release(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 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ReleaseComplete + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_CAUSE: 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -796,183 +805,130 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_ break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ReleaseComplete + Function: Q931Pmes_ReleaseComplete *****************************************************************************/ L3INT Q931Pmes_ReleaseComplete(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 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Restart + 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; + 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; + 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 + Function: Q931Pmes_Restart *****************************************************************************/ L3INT Q931Pmes_Restart(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 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) + 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) + 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) + 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 + Function: Q931Umes_RestartAck *****************************************************************************/ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { - L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; - 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; -} + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(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); - - /* 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: + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -980,52 +936,114 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Resume + 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) { - L3INT rc = Q931E_NO_ERROR; 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ResumeAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1035,57 +1053,56 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ResumeAck + Function: Q931Pmes_ResumeAck *****************************************************************************/ L3INT Q931Pmes_ResumeAck(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 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) + 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) + 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 + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1095,37 +1112,37 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gen } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ResumeReject + Function: Q931Pmes_ResumeReject *****************************************************************************/ L3INT Q931Pmes_ResumeReject(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 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) + /* 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) + /* 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; } @@ -1141,25 +1158,22 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3BOOL RetCode = L3FALSE; *OSize = 0; - return RetCode; } /***************************************************************************** - Function: Q931Umes_Setup + 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; + L3INT ir = 0; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: IOff++; break; @@ -1181,12 +1195,12 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + if (ir < 2) { rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else { @@ -1201,13 +1215,12 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Setup + 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 @@ -1225,105 +1238,308 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m *****************************************************************************/ L3INT Q931Pmes_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 rc = Q931E_NO_ERROR; L3INT Octet = 0; /* Q931 Message Header */ Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ - if(Q931IsIEPresent(pMes->SendComplete)) + if (Q931IsIEPresent(pMes->SendComplete)) { OBuf[Octet++] = (L3UCHAR)Q931ie_SENDING_COMPLETE & 0xff; + } /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) + 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) + 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; + } 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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)) + 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) + 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) + 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; @@ -1332,24 +1548,19 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz /***************************************************************************** - Function: Q931Umes_SetupAck + Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; - L3INT rc=Q931E_NO_ERROR; + 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: + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1357,234 +1568,50 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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 + Function: Q931Pmes_Suspend *****************************************************************************/ L3INT Q931Pmes_Suspend(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 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_SuspendAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1592,52 +1619,51 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_SuspendAck + Function: Q931Pmes_SuspendAck *****************************************************************************/ L3INT Q931Pmes_SuspendAck(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 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_SuspendReject + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1645,93 +1671,93 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Ge break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_SuspendReject + Function: Q931Pmes_SuspendReject *****************************************************************************/ L3INT Q931Pmes_SuspendReject(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_UserInformation + Function: Q931Umes_UserInformation *****************************************************************************/ L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT I, L3INT O) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(mes); - NoWarning(IBuf); + NoWarning(mes); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Pmes_UserInformation + Function: Q931Pmes_UserInformation *****************************************************************************/ L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); *OSize = 0; - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Umes_Service + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1739,60 +1765,60 @@ L3INT Q931Umes_Service(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Service + Function: Q931Pmes_Service *****************************************************************************/ L3INT Q931Pmes_Service(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ServiceAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1800,34 +1826,35 @@ L3INT Q931Umes_ServiceAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ServiceAck + Function: Q931Pmes_ServiceAck *****************************************************************************/ L3INT Q931Pmes_ServiceAck(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 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) + 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) + 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; + return rc; } diff --git a/libs/openzap/src/isdn/Q932mes.c b/libs/openzap/src/isdn/Q932mes.c index 8e011deb31..574499a241 100644 --- a/libs/openzap/src/isdn/Q932mes.c +++ b/libs/openzap/src/isdn/Q932mes.c @@ -13,12 +13,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -39,248 +39,248 @@ /***************************************************************************** - Function: Q932Umes_Facility + Function: Q932Umes_Facility *****************************************************************************/ L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Facility + Function: Q931Pmes_Facility *****************************************************************************/ L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_Hold + Function: Q932Umes_Hold *****************************************************************************/ L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Hold + Function: Q931Pmes_Hold *****************************************************************************/ L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_HoldAck + Function: Q932Umes_HoldAck *****************************************************************************/ L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_HoldAck + Function: Q931Pmes_HoldAck *****************************************************************************/ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_HoldReject + Function: Q932Umes_HoldReject *****************************************************************************/ L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_HoldReject + Function: Q931Pmes_HoldReject *****************************************************************************/ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_Register + Function: Q932Umes_Register *****************************************************************************/ L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Register + Function: Q931Pmes_Register *****************************************************************************/ L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_Retrieve + Function: Q932Umes_Retrieve *****************************************************************************/ L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Retrieve + Function: Q931Pmes_Retrieve *****************************************************************************/ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_RetrieveAck + Function: Q932Umes_RetrieveAck *****************************************************************************/ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_RetrieveAck + Function: Q931Pmes_RetrieveAck *****************************************************************************/ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_RetrieveReject + Function: Q932Umes_RetrieveReject *****************************************************************************/ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_RetrieveReject + Function: Q931Pmes_RetrieveReject *****************************************************************************/ L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } diff --git a/libs/openzap/src/isdn/include/DMS.h b/libs/openzap/src/isdn/include/DMS.h index 35d10d7b5b..605a61aa6e 100644 --- a/libs/openzap/src/isdn/include/DMS.h +++ b/libs/openzap/src/isdn/include/DMS.h @@ -4,18 +4,17 @@ Contents: Header and definition for the National ISDN dialect. The header contents the following parts: - - - Definition of codes + - Definition of codes - Definition of information elements (nationalie_). - Definition of messages (nationalmes_). - - Function prototypes. + - 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 + 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: @@ -77,8 +76,6 @@ L3INT DMSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, 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 @@ -88,7 +85,6 @@ L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, 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); diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 2687930485..8673b71fe8 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -157,7 +157,6 @@ *****************************************************************************/ typedef enum { - Q931E_NO_ERROR = 0, Q931E_UNKNOWN_MESSAGE = -3001, @@ -190,7 +189,6 @@ typedef enum { 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 */ @@ -563,61 +561,61 @@ typedef struct *****************************************************************************/ 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 */ + 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 */ - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; + 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; + 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 */ + L3UCHAR buf[1]; /* Buffer for IE's */ -}Q931mes_Generic; +} Q931mes_Generic; /***************************************************************************** @@ -723,19 +721,19 @@ struct Q931_Call struct Q931_TrunkInfo { - Q931NetUser_t NetUser; /* Network/User Mode. */ + Q931NetUser_t NetUser; /* Network/User Mode. */ Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ - Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ + Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ - Q931Tx34CB_t Q931Tx34CBProc; - Q931Tx32CB_t Q931Tx32CBProc; - Q931ErrorCB_t Q931ErrorCBProc; - Q931LogCB_t Q931LogCBProc; + Q931Tx34CB_t Q931Tx34CBProc; + Q931Tx32CB_t Q931Tx32CBProc; + Q931ErrorCB_t Q931ErrorCBProc; + Q931LogCB_t Q931LogCBProc; void *PrivateData32; void *PrivateData34; void *PrivateDataLog; - Q931LogLevel_t loglevel; + Q931LogLevel_t loglevel; L3UCHAR Enabled; /* Enabled/Disabled */ /* 0 = Disabled */ @@ -779,7 +777,7 @@ struct Q931_TrunkInfo L3INT CRV; /* Associated CRV */ - }ch[Q931MAXCHPERTRUNK]; + } ch[Q931MAXCHPERTRUNK]; /* Active Call information indentified by CRV. See Q931AllocateCRV for */ /* initialization of call table. */ @@ -802,7 +800,7 @@ typedef struct L3INT State; L3INT Message; L3UCHAR Direction; -}Q931State; +} Q931State; /***************************************************************************** @@ -844,7 +842,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; size of 'header'. *****************************************************************************/ -#define Q931GetIETotSize(ie) (((ie.InfoID & 0x80) !=0) ? 1:ie.LenIE)+2) +#define Q931GetIETotSize(ie) (((ie.InfoID & 0x80) != 0) ? 1 : ie.LenIE) + 2) /***************************************************************************** @@ -855,7 +853,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; Description: Return TRUE if the Information Element is included. *****************************************************************************/ -#define Q931IsIEPresent(x) ((x & 0x8000) != 0) +#define Q931IsIEPresent(x) ((x & 0x8000) != 0) /***************************************************************************** @@ -872,7 +870,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; *****************************************************************************/ #define Q931GetIEOffset(x) (x & 0x7fff) -#define Q931GetIEValue(x) (x & 0x7fff) +#define Q931GetIEValue(x) (x & 0x7fff) /***************************************************************************** @@ -894,7 +892,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; Description: Set an information element. *****************************************************************************/ -#define Q931SetIE(x,o) {x = (ie)(o) | 0x8000;} +#define Q931SetIE(x,o) { x = (ie)(o) | 0x8000; } /***************************************************************************** @@ -906,7 +904,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; that the octet is extended. *****************************************************************************/ -#define IsQ931Ext(x) ((x&0x80)==0) +#define IsQ931Ext(x) ((x & 0x80) == 0) /***************************************************************************** @@ -933,7 +931,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; warning for the initial empty functions. *****************************************************************************/ -#define NoWarning(x) (x=x) +#define NoWarning(x) (x = x) /***************************************************************************** diff --git a/libs/openzap/src/isdn/include/Q931ie.h b/libs/openzap/src/isdn/include/Q931ie.h index 2acb937702..65dba4e261 100644 --- a/libs/openzap/src/isdn/include/Q931ie.h +++ b/libs/openzap/src/isdn/include/Q931ie.h @@ -54,7 +54,7 @@ typedef enum { } q931_codeset_t; -/* Single octet information elements */ +/* Single octet information elements */ #define Q931ie_SHIFT 0x90 /* 1001 ---- */ #define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ #define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0001 */ @@ -98,12 +98,11 @@ typedef enum { #define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */ /* Variable Length Codeset 6 Information Elements */ - -#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ +#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 */ +#define Q931ie_CONNECTED_NUMBER 0x4c /* 0100 1101 */ +#define Q931ie_FACILITY 0x1c /* 0001 1101 */ /***************************************************************************** @@ -114,10 +113,9 @@ typedef enum { *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00000100 for Bearer Capability */ - L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding Standard. */ @@ -286,7 +284,8 @@ typedef struct L3UCHAR AL3Info1; /* additional layer 3 info 1 */ L3UCHAR AL3Info2; /* additional layer 3 info 2 */ -}Q931ie_BearerCap; + +} Q931ie_BearerCap; /***************************************************************************** @@ -295,12 +294,13 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00010000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CallId[1]; /* Call identity */ -}Q931ie_CallID; + +} Q931ie_CallID; /***************************************************************************** @@ -309,13 +309,14 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00010100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding Standard */ L3UCHAR CallState; /* Call State Value */ -}Q931ie_CallState; + +} Q931ie_CallState; /***************************************************************************** @@ -324,8 +325,8 @@ typedef struct Description: Cause IE as described in Q.850 *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00010100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding Standard */ @@ -333,21 +334,23 @@ typedef struct L3UCHAR Recom; /* Recommendation */ L3UCHAR Value; /* Cause Value */ L3UCHAR Diag[1]; /* Optional Diagnostics Field */ -}Q931ie_Cause; + +} Q931ie_Cause; /***************************************************************************** Struct: Q931ie_CalledNum *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_CalledNum; /***************************************************************************** @@ -357,14 +360,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_CalledSub; /***************************************************************************** @@ -374,8 +378,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01101100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR TypNum; /* Type of number */ @@ -383,7 +387,8 @@ typedef struct L3UCHAR PresInd; /* Presentation indicator */ L3UCHAR ScreenInd; /* Screening indicator */ L3UCHAR Digit[1]; /* Number digits (IA5) */ -}Q931ie_CallingNum; + +} Q931ie_CallingNum; /***************************************************************************** @@ -393,14 +398,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_CallingSub; /***************************************************************************** @@ -418,8 +424,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00011000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR IntIDPresent; /* Int. id. present */ @@ -460,7 +466,8 @@ typedef struct /* 1001 : H12 channel units */ L3UCHAR ChanSlot; /* Channel number */ -}Q931ie_ChanID; + +} Q931ie_ChanID; /***************************************************************************** @@ -470,8 +477,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00101001 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Year; /* Year */ @@ -485,7 +492,7 @@ typedef struct /* 1 : Hour present */ /* 2 : Hour and Minute present */ /* 3 : Hour, Minute and Second present */ -}Q931ie_DateTime; +} Q931ie_DateTime; /***************************************************************************** @@ -495,12 +502,13 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00101000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Display[1]; /* Display information (IA5) */ -}Q931ie_Display; + +} Q931ie_Display; /***************************************************************************** @@ -510,8 +518,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01111101 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding standard */ @@ -520,7 +528,8 @@ typedef struct L3UCHAR HLCharID; /* High layer characteristics id. */ L3UCHAR EHLCharID; /* Extended high layer character. id. */ L3UCHAR EVideoTlfCharID; /* Ext. videotelephony char. id. */ -}Q931ie_HLComp; + +} Q931ie_HLComp; /***************************************************************************** @@ -530,12 +539,12 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { L3UCHAR IEId; /* 00101100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR KeypadFac[1]; /* dynamic buffer */ -}Q931ie_KeypadFac; + +} Q931ie_KeypadFac; /***************************************************************************** @@ -545,8 +554,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01111100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding standard */ @@ -750,7 +759,8 @@ typedef struct L3UCHAR PackWinSize; /* Packet window size */ L3UCHAR AddL3Info; /* Additional Layer 3 protocol info */ -}Q931ie_LLComp; + +} Q931ie_LLComp; /***************************************************************************** @@ -760,8 +770,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00100000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR LenNetID; /* Length of network facilities id. */ @@ -769,7 +779,8 @@ typedef struct L3UCHAR NetIDPlan; /* Network identification plan. */ L3UCHAR NetFac; /* Network specific facility spec. */ L3UCHAR NetID[1]; /* Network id. (IA5) */ -}Q931ie_NetFac; + +} Q931ie_NetFac; /***************************************************************************** @@ -779,12 +790,13 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00100000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Notification; /* Notification descriptor */ -}Q931ie_NotifInd; + +} Q931ie_NotifInd; /***************************************************************************** @@ -794,14 +806,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00011110 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding standard */ L3UCHAR Location; /* Location */ L3UCHAR ProgDesc; /* Progress description */ -}Q931ie_ProgInd; + +} Q931ie_ProgInd; /***************************************************************************** @@ -811,20 +824,23 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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 -{ +} Q931ie_Segment; + + +typedef struct { + L3UCHAR IEId; /* 00000000 */ L3UCHAR Size; /* Length of Information Element */ -}Q931ie_SendComplete; + +} Q931ie_SendComplete; /***************************************************************************** @@ -834,8 +850,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00000000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Signal; /* Signal value */ @@ -859,7 +875,7 @@ typedef struct /* 01000110 Alerting on - pattern 6 */ /* 01000111 Alerting on - pattern 7 */ /* 01001111 Alerting off */ -}Q931ie_Signal; +} Q931ie_Signal; /***************************************************************************** @@ -869,12 +885,13 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00000000 */ L3UCHAR Size; /* Length of Information Element */ L3ULONG TxDSIValue; /* Trans. delay sel. & ind. value */ -}Q931ie_TransDelSelInd; + +} Q931ie_TransDelSelInd; #endif /***************************************************************************** @@ -885,14 +902,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_TransNetSel; /***************************************************************************** @@ -902,13 +920,14 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01111110 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR ProtDisc; /* Protocol discriminator */ L3UCHAR User[1]; /* User information */ -}Q931ie_UserUser; + +} Q931ie_UserUser; /***************************************************************************** @@ -918,13 +937,14 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000111 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CUGInd; /* CUG indication */ L3UCHAR CUG[1]; /* CUG index code (IA5) */ -}Q931ie_ClosedUserGrp; + +} Q931ie_ClosedUserGrp; #endif /***************************************************************************** @@ -934,12 +954,13 @@ typedef struct Description: Congestion Level *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000111 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CongLevel; /* Conguestion Level */ -}Q931ie_CongLevel; + +} Q931ie_CongLevel; /***************************************************************************** @@ -949,14 +970,15 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +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; + +} Q931ie_EndEndTxDelay; #endif /***************************************************************************** @@ -967,15 +989,16 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +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; + +} Q931ie_InfoRate; #endif /***************************************************************************** @@ -986,15 +1009,16 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +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; + +} Q931ie_PackParam; #endif /***************************************************************************** @@ -1005,13 +1029,14 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000101 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR ForwardValue; /* Forward value */ L3UCHAR BackwardValue; /* Backward value */ -}Q931ie_PackWinSize; + +} Q931ie_PackWinSize; #endif /***************************************************************************** @@ -1022,13 +1047,14 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000110 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR ForwardValue; /* Forward value */ L3UCHAR BackwardValue; /* Backward value */ -}Q931ie_PackSize; + +} Q931ie_PackSize; #endif /***************************************************************************** @@ -1039,8 +1065,8 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR TypeNum; /* Type of number */ @@ -1049,19 +1075,20 @@ typedef struct L3UCHAR ScreenInd; /* Screening indicator */ L3UCHAR Reason; /* Reason for redirection */ L3UCHAR Digit[1]; /* Number digits (IA5) */ -}Q931ie_RedirNum; + +} Q931ie_RedirNum; #endif -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR RepeatInd; /* 0010 Prioritized list for selecting */ /* one possible. */ -}Q931ie_RepeatInd; +} Q931ie_RepeatInd; + +typedef struct { -typedef struct -{ L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Spare; /* Spare */ @@ -1069,10 +1096,10 @@ typedef struct /* 000 Indicate channels */ /* 110 Single interface */ /* 111 All interfaces */ -}Q931ie_RestartInd; +} Q931ie_RestartInd; + +typedef struct { -typedef struct -{ L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Preference; /* Preference 0 = reserved, 1 = channel */ @@ -1081,7 +1108,7 @@ typedef struct /* 000 In service */ /* 001 Maintenance */ /* 010 Out of service */ -}Q931ie_ChangeStatus; +} Q931ie_ChangeStatus; /***************************************************************************** @@ -1090,13 +1117,14 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; diff --git a/libs/openzap/src/isdn/include/Q932.h b/libs/openzap/src/isdn/include/Q932.h index 34ba9ffa4b..9b69a34a02 100644 --- a/libs/openzap/src/isdn/include/Q932.h +++ b/libs/openzap/src/isdn/include/Q932.h @@ -53,7 +53,7 @@ /***************************************************************************** Q.932 Additional EI Codes *****************************************************************************/ -#define Q932ie_FACILITY 0x1c /* 0001 1100 */ +#define Q932ie_FACILITY 0x1c /* 0001 1100 */ /***************************************************************************** Function Prototypes. diff --git a/libs/openzap/src/isdn/include/mfifo.h b/libs/openzap/src/isdn/include/mfifo.h index 477362466b..4c1d850d81 100644 --- a/libs/openzap/src/isdn/include/mfifo.h +++ b/libs/openzap/src/isdn/include/mfifo.h @@ -44,11 +44,10 @@ Description: Message Index used to index a dynamic size Message FIFO. *****************************************************************************/ -typedef struct _mindex -{ +typedef struct _mindex { int offset; /* offset to message in buf */ int size; /* size of message in bytes */ -}MINDEX; +} MINDEX; /***************************************************************************** @@ -58,8 +57,7 @@ typedef struct _mindex queue. *****************************************************************************/ -typedef struct -{ +typedef struct { int first; /* first out */ int last; /* last in + 1 */ int bsize; /* buffer size */ diff --git a/libs/openzap/src/isdn/include/national.h b/libs/openzap/src/isdn/include/national.h index c47daf4ed9..cff26aa4a4 100644 --- a/libs/openzap/src/isdn/include/national.h +++ b/libs/openzap/src/isdn/include/national.h @@ -3,19 +3,18 @@ FileName: national.h Contents: Header and definition for the National ISDN dialect. The - header contents the following parts: - - - Definition of codes + header contents the following parts: + - Definition of codes - Definition of information elements (nationalie_). - Definition of messages (nationalmes_). - - Function prototypes. + - Function prototypes. - Description: The National ISDN dialect here covers ???? + 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 + 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: @@ -75,15 +74,12 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT #include "DMS.h" - /***************************************************************************** Q.931 Process Function Prototyping. Implemented in nationalStateTE.c *****************************************************************************/ - - void nationalCreateTE(L3UCHAR i); void nationalCreateNT(L3UCHAR i); diff --git a/libs/openzap/src/isdn/mfifo.c b/libs/openzap/src/isdn/mfifo.c index 64dbcedfcc..28528f9b64 100644 --- a/libs/openzap/src/isdn/mfifo.c +++ b/libs/openzap/src/isdn/mfifo.c @@ -1,38 +1,38 @@ /***************************************************************************** - Filename: mfifo.c + Filename: mfifo.c Description: mfifo is a message orriented fifo system with support of - both message and byte per byte retriaval of messages. + both message and byte per byte retriaval of messages. - The fifo has been designed with two usages in mind: + 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. + - 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. + - 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. + 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. + 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. + * 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. + 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. + This is required to allow direct ptr access to messages + stored in the queue. License/Copyright: @@ -43,12 +43,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -71,40 +71,40 @@ /***************************************************************************** - Function: MFIFOCreate + 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). + 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)]; + 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; + if (mf->buf > &buf[size]) + return 0; - mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index); + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index); - return 1; + return 1; } /***************************************************************************** - Function: MFIFOClear + Function: MFIFOClear Description: Clear the FIFO - Paremeters: buf ptr to fifo + Paremeters: buf ptr to fifo Return Value: none @@ -118,91 +118,91 @@ void MFIFOClear(unsigned char * buf) /***************************************************************************** - Function: MFIFOGetLBOffset + Function: MFIFOGetLBOffset Description: Helper function caclulating offset to the 'first out' byte. - Paremeters: buf ptr to fifo + Paremeters: buf ptr to fifo Return Value: offset. *****************************************************************************/ int MFIFOGetLBOffset(unsigned char *buf) { - MFIFO *mf = (MFIFO *)buf; + MFIFO *mf = (MFIFO *)buf; - if(mf->last != mf->first) - return mf->ix[mf->last].offset; - - return 0; + if (mf->last != mf->first) + return mf->ix[mf->last].offset; + + return 0; } /***************************************************************************** - Function: MFIFOGetFBOffset + 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. + byte in the buffer. This is the position the next byte + entering the fifo will occupy. - Paremeters: buf ptr to fifo + Paremeters: buf ptr to fifo Return Value: offset *****************************************************************************/ int MFIFOGetFBOffset(unsigned char *buf) { - MFIFO *mf = (MFIFO *)buf; - int x; + MFIFO *mf = (MFIFO *)buf; + int x; - if(mf->last == mf->first) - return 0; + if (mf->last == mf->first) + return 0; - x = mf->first - 1; + x = mf->first - 1; - if(x < 0) - x = mf->ixsize - 1; + if (x < 0) + x = mf->ixsize - 1; - return mf->ix[x].offset + mf->ix[x].size; + return mf->ix[x].offset + mf->ix[x].size; } /***************************************************************************** - Function: MFIFOWriteIX + 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. + 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 + 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; + MFIFO *mf = (MFIFO *)buf; + int x; - memcpy(&mf->buf[off], mes, size); - mf->ix[ix].offset = off; - mf->ix[ix].size = size; + memcpy(&mf->buf[off], mes, size); + mf->ix[ix].offset = off; + mf->ix[ix].size = size; - x = mf->first + 1; + x = mf->first + 1; - if(x >= mf->ixsize) - x = 0; + if (x >= mf->ixsize) + x = 0; - mf->first = x; + mf->first = x; } /***************************************************************************** - Function: MFIFOWriteMes + Function: MFIFOWriteMes Description: @@ -213,51 +213,46 @@ void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int *****************************************************************************/ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { - MFIFO *mf = (MFIFO *)buf; - int of, ol, x; + MFIFO *mf = (MFIFO *)buf; + int of, ol, x; - x = mf->first + 1; + x = mf->first + 1; - if(x >= mf->ixsize) - x = 0; + if (x >= mf->ixsize) + x = 0; - if(x == mf->last) - return 0; /* full queue */ + 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 */ + 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; - } + 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; + return 0; } /***************************************************************************** - Function: MFIFOGetMesPtr + Function: MFIFOGetMesPtr Description: @@ -270,7 +265,7 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) { MFIFO *mf = (MFIFO *)buf; - if(mf->first == mf->last) { + if (mf->first == mf->last) { return NULL; } @@ -280,7 +275,7 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) /***************************************************************************** - Function: MFIFOKillNext + Function: MFIFOKillNext Description: @@ -291,18 +286,17 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) *****************************************************************************/ void MFIFOKillNext(unsigned char *buf) { - MFIFO *mf = (MFIFO *)buf; - int x; + MFIFO *mf = (MFIFO *)buf; + int x; - if(mf->first != mf->last) - { - x = mf->last + 1; - if(x >= mf->ixsize) { - x = 0; + if (mf->first != mf->last) { + x = mf->last + 1; + if (x >= mf->ixsize) { + x = 0; + } + + mf->last = x; } - - mf->last = x; - } } @@ -319,16 +313,16 @@ unsigned char * MFIFOGetMesPtrOffset(unsigned char *buf, int *size, const int po MFIFO *mf = (MFIFO *)buf; int x; - if(mf->first == mf->last) { + if (mf->first == mf->last) { return NULL; } - if(pos < 0 || pos >= mf->ixsize) { + if (pos < 0 || pos >= mf->ixsize) { return NULL; } x = pos - mf->last; - if(x < 0) { + if (x < 0) { x += (mf->ixsize - 1); } @@ -345,10 +339,10 @@ int MFIFOGetMesCount(unsigned char *buf) { MFIFO *mf = (MFIFO *)buf; - if(mf->first == mf->last) { + if (mf->first == mf->last) { return 0; } - else if(mf->first > mf->last) { + else if (mf->first > mf->last) { return mf->first - mf->last; } else { @@ -367,42 +361,37 @@ int MFIFOWriteMesOverwrite(unsigned char *buf, unsigned char *mes, int size) x = mf->first + 1; - if(x >= mf->ixsize) + if (x >= mf->ixsize) x = 0; - if(x == mf->last) { + if (x == mf->last) { /* advance last pointer */ mf->last++; - if(mf->last >= mf->ixsize) + if (mf->last >= mf->ixsize) mf->last = 0; } of = MFIFOGetFBOffset(buf); ol = MFIFOGetLBOffset(buf); - if(mf->last == mf->first) /* empty queue */ - { + 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) - { + else if (of > ol) { + if (mf->bsize - of >= size) { MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } - else if(ol > size) - { + else if (ol > size) { MFIFOWriteIX(buf, mes, size, mf->first, ol); return 1; } } - else if(ol - of > size) - { + else if (ol - of > size) { MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c index 29f766e073..48d649f2df 100644 --- a/libs/openzap/src/isdn/nationalStateNT.c +++ b/libs/openzap/src/isdn/nationalStateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -22,12 +22,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -57,66 +57,66 @@ *****************************************************************************/ 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(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); + 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_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 */ diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index 99dcec3b9a..a50ae3debd 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -29,12 +29,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -65,152 +65,152 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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.*/ + /* 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); + 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); + 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); + 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); + 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); + 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); + 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); + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4); + 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); + 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); + 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); + 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); + 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); + 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, + 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 index 90f7a1b1a3..5ef69014b5 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: nationalmes.c + 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. + 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. + See national.h for description. License/Copyright: @@ -21,12 +21,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -48,19 +48,18 @@ /***************************************************************************** - Function: nationalUmes_Setup + 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; + L3INT ir = 0; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; L3UCHAR last_codeset = 0, codeset = 0; L3UCHAR shift_lock = 1; - while(IOff < Size) - { + while (IOff < Size) { if (!shift_lock) { codeset = last_codeset; } @@ -75,8 +74,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi } if (codeset == 0) { - switch(IBuf[IOff]) - { + switch (IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: @@ -94,11 +92,11 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + if (ir < 2) { rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else { @@ -110,11 +108,10 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi break; } } else if (codeset == 6) { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -126,13 +123,13 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi return Q931E_ILLEGAL_IE; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: nationalPmes_Setup + 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 @@ -150,109 +147,121 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi *****************************************************************************/ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + 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)) + + /* Sending Complete */ + if (Q931IsIEPresent(pMes->SendComplete)) { OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + } /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) + 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) + 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; + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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)) + 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) + 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) + 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; + return rc; } - - From 6c4e94774f36d2eecf86c6044f3741dedfb14ae6 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 19:40:40 +0000 Subject: [PATCH 1032/1766] Codingstyle cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@535 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/5ESSStateNT.c | 154 +- libs/freetdm/src/isdn/5ESSStateTE.c | 329 +- libs/freetdm/src/isdn/5ESSmes.c | 441 +-- libs/freetdm/src/isdn/DMSStateNT.c | 120 +- libs/freetdm/src/isdn/DMSStateTE.c | 279 +- libs/freetdm/src/isdn/DMSmes.c | 153 +- libs/freetdm/src/isdn/EuroISDNStateNT.c | 18 +- libs/freetdm/src/isdn/EuroISDNStateTE.c | 16 +- libs/freetdm/src/isdn/Q931.c | 624 ++-- libs/freetdm/src/isdn/Q931StateNT.c | 933 +++--- libs/freetdm/src/isdn/Q931StateTE.c | 1107 +++---- libs/freetdm/src/isdn/Q931ie.c | 3704 +++++++++++----------- libs/freetdm/src/isdn/Q931mes.c | 1603 +++++----- libs/freetdm/src/isdn/Q932mes.c | 150 +- libs/freetdm/src/isdn/include/DMS.h | 16 +- libs/freetdm/src/isdn/include/Q931.h | 134 +- libs/freetdm/src/isdn/include/Q931ie.h | 248 +- libs/freetdm/src/isdn/include/Q932.h | 2 +- libs/freetdm/src/isdn/include/mfifo.h | 8 +- libs/freetdm/src/isdn/include/national.h | 20 +- libs/freetdm/src/isdn/mfifo.c | 275 +- libs/freetdm/src/isdn/nationalStateNT.c | 130 +- libs/freetdm/src/isdn/nationalStateTE.c | 252 +- libs/freetdm/src/isdn/nationalmes.c | 147 +- 24 files changed, 5286 insertions(+), 5577 deletions(-) diff --git a/libs/freetdm/src/isdn/5ESSStateNT.c b/libs/freetdm/src/isdn/5ESSStateNT.c index d2a5540c32..1eb9415422 100644 --- a/libs/freetdm/src/isdn/5ESSStateNT.c +++ b/libs/freetdm/src/isdn/5ESSStateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -25,14 +25,14 @@ 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. + * 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 @@ -53,80 +53,80 @@ 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. + 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(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); + 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); + /* 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.*/ + /* 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 */ + /* TODO define state table here */ } diff --git a/libs/freetdm/src/isdn/5ESSStateTE.c b/libs/freetdm/src/isdn/5ESSStateTE.c index 62594212e3..ce2425e0e0 100644 --- a/libs/freetdm/src/isdn/5ESSStateTE.c +++ b/libs/freetdm/src/isdn/5ESSStateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -32,14 +32,14 @@ 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. + * 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 @@ -61,159 +61,159 @@ 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. + 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(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); + 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); + /* 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.*/ + /* 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 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 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 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 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 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 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 7 Call Received */ + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); - /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE,4); + /* 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 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 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 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 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); + /* 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ } @@ -224,37 +224,33 @@ void ATT5ESSCreateTE(L3UCHAR i) *****************************************************************************/ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom ==2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) { - printf("autoServiceAck is on, responding to Service Req from network...\n"); + printf("autoServiceAck is on, responding to Service Req from network...\n"); Q931AckService(pTrunk, buf); } - } return ret; @@ -267,31 +263,28 @@ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom == 2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c index 3e4b316d98..17f7ec8c77 100644 --- a/libs/freetdm/src/isdn/5ESSmes.c +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: 5ESSmes.c + 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. + 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. + See 5ESS.h for description. License/Copyright: @@ -24,14 +24,14 @@ 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. + * 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 @@ -51,287 +51,300 @@ /***************************************************************************** - Function: ATT5ESSUmes_Setup + 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_lock = 1; + 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; - } + 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 ((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: - 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; - } + 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 { - return Q931E_ILLEGAL_IE; - } - } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + } else { + return Q931E_ILLEGAL_IE; + } + } + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: ATT5ESSPmes_Setup + 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. + 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. + 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 + 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; + L3INT rc = Q931E_NO_ERROR; + Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; + L3INT Octet = 0; - /* Q931 Message Header */ + /* Q931 Message Header */ Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); - - /* Sending Complete */ - if(Q931IsIEPresent(pMes->SendComplete)) - OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + + /* Sending Complete */ + if (Q931IsIEPresent(pMes->SendComplete)) { + OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + } - /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) - OBuf[Octet++] = (L3UCHAR)(pMes->RepeatInd & 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; - } + /* 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; + /* 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; + /* 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; + /* 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; + /* 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; + /* 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; + /* 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; + /* 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 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; + /* 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 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; + /* 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; + /* 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 */ + /* 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; + /* 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; + /* 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; + *OSize = Octet; + return rc; } /***************************************************************************** - Function: ATT5ESSUmes_0x0f + 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 == 8) { + return Q931Umes_ConnectAck(pTrunk, IBuf, mes, IOff, Size); + } - if (mes->ProtDisc == 3) { - return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size); - } + if (mes->ProtDisc == 3) { + return Q931Umes_Service(pTrunk, IBuf, mes, IOff, Size); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: ATT5ESSPmes_0x0f + 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; + Q931mes_Generic *mes = (Q931mes_Generic *)IBuf; - if (mes->ProtDisc == 8) { - return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 8) { + return Q931Pmes_ConnectAck(pTrunk, IBuf, ISize, OBuf, OSize); + } - if (mes->ProtDisc == 3) { - return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 3) { + return Q931Pmes_Service(pTrunk, IBuf, ISize, OBuf, OSize); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: ATT5ESSUmes_0x07 + 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 == 8) { + return Q931Umes_Connect(pTrunk, IBuf, mes, IOff, Size); + } - if (mes->ProtDisc == 3) { - return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size); - } + if (mes->ProtDisc == 3) { + return Q931Umes_ServiceAck(pTrunk, IBuf, mes, IOff, Size); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: ATT5ESSPmes_0x07 + 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; + Q931mes_Generic *mes = (Q931mes_Generic *)IBuf; - if (mes->ProtDisc == 8) { - return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 8) { + return Q931Pmes_Connect(pTrunk, IBuf, ISize, OBuf, OSize); + } - if (mes->ProtDisc == 3) { - return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize); - } + if (mes->ProtDisc == 3) { + return Q931Pmes_ServiceAck(pTrunk, IBuf, ISize, OBuf, OSize); + } - return Q931E_UNKNOWN_MESSAGE; + return Q931E_UNKNOWN_MESSAGE; } diff --git a/libs/freetdm/src/isdn/DMSStateNT.c b/libs/freetdm/src/isdn/DMSStateNT.c index 6c75029665..e8814ba8ef 100644 --- a/libs/freetdm/src/isdn/DMSStateNT.c +++ b/libs/freetdm/src/isdn/DMSStateNT.c @@ -22,12 +22,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -57,66 +57,66 @@ *****************************************************************************/ 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(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); + 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_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 */ diff --git a/libs/freetdm/src/isdn/DMSStateTE.c b/libs/freetdm/src/isdn/DMSStateTE.c index 8c435fa8c2..5de657d7d9 100644 --- a/libs/freetdm/src/isdn/DMSStateTE.c +++ b/libs/freetdm/src/isdn/DMSStateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -29,12 +29,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -65,149 +65,149 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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); + 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); + 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); + 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); + 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); + 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); + 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); + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4); + 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); + 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); + 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); + 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); + 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); + 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ } @@ -218,36 +218,32 @@ void DMSCreateTE(L3UCHAR i) *****************************************************************************/ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom == 2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pMes->ProtDisc == 3 && pTrunk->autoServiceAck) { Q931AckService(pTrunk, buf); } - } return ret; @@ -260,31 +256,28 @@ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); } - if(iFrom == 4) - { + if (iFrom == 4) { /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { + else if (iFrom == 2) { /* TODO Add proc here*/ - ret = Q931Tx34(pTrunk,buf,pMes->Size); + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; diff --git a/libs/freetdm/src/isdn/DMSmes.c b/libs/freetdm/src/isdn/DMSmes.c index b32664b767..3ce82f2ded 100644 --- a/libs/freetdm/src/isdn/DMSmes.c +++ b/libs/freetdm/src/isdn/DMSmes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: DMSmes.c + 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. + 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. + See national.h for description. License/Copyright: @@ -21,12 +21,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -48,19 +48,18 @@ /***************************************************************************** - Function: DMSUmes_Setup + 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; + L3INT ir = 0; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; L3UCHAR last_codeset = 0, codeset = 0; L3UCHAR shift_lock = 1; - while(IOff < Size) - { + while (IOff < Size) { if (!shift_lock) { codeset = last_codeset; } @@ -75,8 +74,7 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me } if (codeset == 0) { - switch(IBuf[IOff]) - { + switch (IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: @@ -94,11 +92,11 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + if (ir < 2) { rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else { @@ -110,11 +108,10 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me break; } } else if (codeset == 6) { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -126,13 +123,13 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me return Q931E_ILLEGAL_IE; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: DMSPmes_Setup + 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 @@ -150,115 +147,129 @@ L3INT DMSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *me *****************************************************************************/ L3INT DMSPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + 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)) + /* Sending Complete */ + if (Q931IsIEPresent(pMes->SendComplete)) { OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + } /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) + 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) + 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; + } 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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)) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: DMSUmes_0x0f + Function: DMSUmes_0x0f *****************************************************************************/ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) @@ -276,7 +287,7 @@ L3INT DMSUmes_0x0f(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes /***************************************************************************** - Function: DMSPmes_0x0f + Function: DMSPmes_0x0f *****************************************************************************/ L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) @@ -296,7 +307,7 @@ L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, /***************************************************************************** - Function: DMSUmes_0x07 + Function: DMSUmes_0x07 *****************************************************************************/ L3INT DMSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) @@ -314,7 +325,7 @@ L3INT DMSUmes_0x07(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes /***************************************************************************** - Function: DMSPmes_0x07 + Function: DMSPmes_0x07 *****************************************************************************/ L3INT DMSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) diff --git a/libs/freetdm/src/isdn/EuroISDNStateNT.c b/libs/freetdm/src/isdn/EuroISDNStateNT.c index ccfaba0d16..6b26c91e04 100644 --- a/libs/freetdm/src/isdn/EuroISDNStateNT.c +++ b/libs/freetdm/src/isdn/EuroISDNStateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -19,12 +19,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -42,5 +42,3 @@ *****************************************************************************/ #include "Q931.h" - - diff --git a/libs/freetdm/src/isdn/EuroISDNStateTE.c b/libs/freetdm/src/isdn/EuroISDNStateTE.c index 7b7433e567..ef6b39e8e5 100644 --- a/libs/freetdm/src/isdn/EuroISDNStateTE.c +++ b/libs/freetdm/src/isdn/EuroISDNStateTE.c @@ -4,11 +4,11 @@ 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. + 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: @@ -19,12 +19,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 6591613d71..9b9b6331bd 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -1,9 +1,9 @@ /***************************************************************************** - FileName: Q931.c + FileName: Q931.c - Contents: Implementation of Q.931 stack main interface functions. - See q931.h for description. + Contents: Implementation of Q.931 stack main interface functions. + See q931.h for description. License/Copyright: @@ -14,14 +14,14 @@ 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. + * 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 @@ -71,11 +71,7 @@ q931pie_func_t *Q931Pie[Q931MAXDLCT][Q931MAXIE]; q931timeout_func_t *Q931Timeout[Q931MAXDLCT][Q931MAXTIMER]; q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; -void (*Q931CreateDialectCB[Q931MAXDLCT]) (L3UCHAR iDialect)= -{ - NULL, - NULL -}; +void (*Q931CreateDialectCB[Q931MAXDLCT])(L3UCHAR iDialect) = { NULL, NULL }; Q931State Q931st[Q931MAXSTATE]; @@ -85,10 +81,10 @@ Q931State Q931st[Q931MAXSTATE]; *****************************************************************************/ -L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */ - /* at head of each message. */ +L3INT Q931L4HeaderSpace = {0}; /* header space to be ignoder/inserted */ + /* at head of each message. */ -L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ +L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ /***************************************************************************** @@ -96,201 +92,195 @@ L3INT Q931L2HeaderSpace = {4}; /* Q921 header space, sapi, tei etc */ *****************************************************************************/ -Q931ErrorCB_t Q931ErrorProc; - /* callback for error messages. */ - -L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ +Q931ErrorCB_t Q931ErrorProc; /* callback for error messages. */ +L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */ /***************************************************************************** - Function: Q931SetL4HeaderSpace + 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. + 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; + Q931L4HeaderSpace = space; } /***************************************************************************** - Function: Q931SetL2HeaderSpace + 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. + 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; + Q931L2HeaderSpace = space; } /***************************************************************************** - Function: Q931ProcDummy + Function: Q931ProcDummy Description: Dummy function for message processing. *****************************************************************************/ L3INT Q931ProcDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b,L3INT c) { - return Q931E_INTERNAL; + return Q931E_INTERNAL; } /***************************************************************************** - Function: Q931UmesDummy + 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; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: Q931UieDummy + 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; + return Q931E_UNKNOWN_IE; } /***************************************************************************** - Function: Q931PmesDummy + 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; + return Q931E_UNKNOWN_MESSAGE; } /***************************************************************************** - Function: Q931PieDummy + Function: Q931PieDummy Description: Dummy function for message processing *****************************************************************************/ L3INT Q931PieDummy(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - return Q931E_UNKNOWN_IE; + return Q931E_UNKNOWN_IE; } /***************************************************************************** - Function: Q931TxDummy + Function: Q931TxDummy Description: Dummy function for message processing *****************************************************************************/ L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n) { - return Q931E_MISSING_CB; + return Q931E_MISSING_CB; } /***************************************************************************** - Function: Q931ErrorDummy + Function: Q931ErrorDummy Description: Dummy function for error processing *****************************************************************************/ L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c) { - return 0; + return 0; } /***************************************************************************** - Function: Q931Initialize + 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. + 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. + Note: Initialization of other stacks should be inserted after + the initialization of EuroISDN. *****************************************************************************/ void Q931Initialize() { - L3INT x,y; + L3INT x,y; - /* Secure the callbacks to default procs */ - Q931ErrorProc = Q931ErrorDummy; + /* 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; + /* 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_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_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_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_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_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_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_TE] == NULL) + Q931AddDialect(Q931_Dialect_5ESS + Q931_TE, ATT5ESSCreateTE); - if(Q931CreateDialectCB[Q931_Dialect_5ESS + Q931_NT] == NULL) - Q931AddDialect(Q931_Dialect_5ESS + Q931_NT, ATT5ESSCreateNT); + 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); - } - } + /* 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); + } + } } /** @@ -304,20 +294,20 @@ void Q931TimerTick(Q931_TrunkInfo_t *pTrunk) 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. + /* 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++) { + for (x = 0; x < Q931MAXCALLPERTRUNK; x++) { call = &pTrunk->call[x]; - if(!call->InUse || !call->Timer || !call->TimerID) + if (!call->InUse || !call->Timer || !call->TimerID) continue; - if(call->Timer <= now) { + if (call->Timer <= now) { /* Stop Timer */ Q931StopTimer(pTrunk, x, call->TimerID); @@ -329,23 +319,23 @@ void Q931TimerTick(Q931_TrunkInfo_t *pTrunk) /***************************************************************************** - Function: Q931Rx23 + 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. + 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. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT Size) @@ -357,7 +347,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, L3INT IOff = 0; L3INT L2HSize = Q931L2HeaderSpace; - switch(ind) { + switch (ind) { case Q921_DL_UNIT_DATA: /* DL-UNITDATA indication (UI frame, 3 byte header) */ L2HSize = 3; @@ -382,12 +372,12 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, * a) doing Q.921 work in the lower levels (extracting the TEI ourselves) * b) adding a tei parameter to _all_ Proc functions */ - if(tei) { + 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) { + if (RetCode == Q931E_NO_ERROR && !pTrunk->call[callIndex].Tei) { pTrunk->call[callIndex].Tei = tei; } } @@ -396,8 +386,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, 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) - { + if (RetCode >= Q931E_NO_ERROR) { RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2); } break; @@ -411,70 +400,70 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, /***************************************************************************** - Function: Q931Tx34 + 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. + 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. + 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; + if (pTrunk->Q931Tx34CBProc) { + return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size); + } + return Q931E_MISSING_CB; } /***************************************************************************** - Function: Q931Rx43 + Function: Q931Rx43 Description: Receive message from Layer 4 (application). Parameters: pTrunk[IN] Trunk #. - buf[IN] Message Pointer. - Size[IN] Message size in bytes. + 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. + 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; + 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); + RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4); Q931Log(pTrunk, Q931_LOG_DEBUG, "Q931Rx43 return code: %d\n", RetCode); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Tx32 + 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. + 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. + 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. + see q931errors.h for details. *****************************************************************************/ L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT Size) @@ -491,15 +480,14 @@ L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT /* Call pack function through table. */ RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Offset], &OSize); - if(RetCode >= Q931E_NO_ERROR) - { + if (RetCode >= Q931E_NO_ERROR) { L3INT callIndex; L3UCHAR tei = 0; - if(ptr->CRV) { + if (ptr->CRV) { /* Find the call using CRV */ RetCode = Q931FindCRV(pTrunk, ptr->CRV, &callIndex); - if(RetCode != Q931E_NO_ERROR) + if (RetCode != Q931E_NO_ERROR) return RetCode; tei = pTrunk->call[callIndex].Tei; @@ -518,54 +506,53 @@ L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR bcast, L3UCHAR * Mes, L3INT /***************************************************************************** - Function: Q931SetError + 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. + 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); - } + if (pTrunk->Q931ErrorCBProc) { + pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } else { + Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2); + } } void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar) { - Q931ErrorProc = Q931ErrorPar; + Q931ErrorProc = Q931ErrorPar; } /***************************************************************************** - Function: Q931CreateCRV + 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. + 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. + 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) + see q931errors.h for details. +****************************************************************************/ +L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex) { - L3INT CRV = Q931GetUniqueCRV(pTrunk); + L3INT CRV = Q931GetUniqueCRV(pTrunk); - return Q931AllocateCRV(pTrunk, CRV, callIndex); + return Q931AllocateCRV(pTrunk, CRV, callIndex); } -L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV) +L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV) { int callIndex; @@ -579,66 +566,61 @@ L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV) /***************************************************************************** - Function: Q931AllocateCRV + Function: Q931AllocateCRV Description: Allocate a call table entry and assigns the given CRV value - to it. + to it. - Parameters: pTrunk [IN] Trunk number - iCRV [IN] Call Reference Value. - callindex [OUT] return call table index. + 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. + see q931errors.h for details. *****************************************************************************/ -L3INT Q931AllocateCRV(Q931_TrunkInfo_t *pTrunk, L3INT iCRV, L3INT * callIndex) +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; + 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 + Function: Q931GetCallState Description: Look up CRV and return current call state. A non existing - CRV is the same as state zero (0). + CRV is the same as state zero (0). - Parameters: pTrunk [IN] Trunk number. - iCRV [IN] CRV + Parameters: pTrunk [IN] Trunk number. + iCRV [IN] CRV Return Value: Call State. *****************************************************************************/ -L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) +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 */ + 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 */ } /** @@ -653,11 +635,10 @@ L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerI { L3ULONG duration = Q931Timer[pTrunk->Dialect][iTimerID]; - if(duration) { + if (duration) { pTrunk->call[callIndex].Timer = Q931GetTime() + duration; pTrunk->call[callIndex].TimerID = iTimerID; } - return 0; } @@ -671,7 +652,7 @@ L3INT Q931StartTimer(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3USHORT iTimerI */ L3INT Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimerID) { - if(pTrunk->call[callindex].TimerID == iTimerID) + if (pTrunk->call[callindex].TimerID == iTimerID) pTrunk->call[callindex].TimerID = 0; return 0; @@ -679,148 +660,137 @@ L3INT Q931StopTimer(Q931_TrunkInfo_t *pTrunk, L3INT callindex, L3USHORT iTimerID L3INT Q931SetState(Q931_TrunkInfo_t *pTrunk, L3INT callIndex, L3INT iState) { - pTrunk->call[callIndex].State = iState; + pTrunk->call[callIndex].State = iState; - return 0; + return 0; } L3ULONG Q931GetTime() { - L3ULONG tNow = 0; - static L3ULONG tLast = 0; + L3ULONG tNow = 0; + static L3ULONG tLast = 0; - if(Q931GetTimeProc != NULL) - { - tNow = Q931GetTimeProc(); - if(tNow < tLast) /* wrapped */ - { - /* TODO */ - } - tLast = tNow; - } - return tNow; + if (Q931GetTimeProc != NULL) { + tNow = Q931GetTimeProc(); + if (tNow < tLast) { /* wrapped */ + /* TODO */ + } + tLast = tNow; + } + return tNow; } void Q931SetGetTimeCB(L3ULONG (*callback)(void)) { - Q931GetTimeProc = callback; + 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; + 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; - } + if (i < Q931MAXDLCT) { + Q931CreateDialectCB[i] = callback; + } } /***************************************************************************** - Function: Q931AddStateEntry + Function: Q931AddStateEntry Description: Find an empty entry in the dialects state table and add this - entry. + 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; - } - } + 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 + Function: Q931IsEventLegal Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + Message is legal in this state or not. - Note: Someone write a bsearch or invent something smart here - please - sequential is ok for now. + 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; + 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() + Function: q931_error_to_name() Description: Check state table for matching criteria to indicate if this - Message is legal in this state or not. + Message is legal in this state or not. - Note: Someone write a bsearch or invent something smart here - please - sequential is ok for now. + 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_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 */ + "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 */ }; @@ -828,14 +798,14 @@ static const char *q931_error_names[] = { 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]; + 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 @@ -844,24 +814,24 @@ const char *q931_error_to_name(q931_error_t error) L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...) { - char buf[Q931_LOGBUFSIZE]; + char buf[Q931_LOGBUFSIZE]; L3INT len; va_list ap; - if(!trunk->Q931LogCBProc) + if (!trunk->Q931LogCBProc) return 0; - if(trunk->loglevel < level) + if (trunk->loglevel < level) return 0; va_start(ap, fmt); len = vsnprintf(buf, sizeof(buf)-1, fmt, ap); - if(len <= 0) { + if (len <= 0) { /* TODO: error handling */ return -1; } - if(len >= sizeof(buf)) + if (len >= sizeof(buf)) len = sizeof(buf) - 1; buf[len] = '\0'; @@ -877,7 +847,7 @@ L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, .. */ void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv) { - trunk->Q931LogCBProc = func; + trunk->Q931LogCBProc = func; trunk->PrivateDataLog = priv; } diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index af74ef0e8b..5b8b0860b4 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -19,12 +19,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -56,76 +56,76 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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); - /* 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.*/ + /* 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 */ @@ -153,24 +153,22 @@ void Q931CreateNT(L3UCHAR i) *****************************************************************************/ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + if (iFrom == 4) { + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); + else if (iFrom == 2) { + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -182,28 +180,26 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -215,28 +211,26 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF *****************************************************************************/ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -248,28 +242,26 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -281,28 +273,26 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -316,71 +306,61 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT rc=0; Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; + 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; - } + /* 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; + if (iFrom == 4) { + ret = Q931CreateCRV(pTrunk, &callIndex); + if (ret) + return ret; - /* - * 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; + pMes->CRV = pTrunk->call[callIndex].CRV; - Q931StartTimer(pTrunk, callIndex, 303); + /* + * 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; - Q931SetState(pTrunk, callIndex, Q931_U1); - } + Q931StartTimer(pTrunk, callIndex, 303); + 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) - 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; + 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) { + 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, 303); + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); + Q931StartTimer(pTrunk, callIndex, 303); #endif - } return rc; @@ -399,28 +379,26 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -432,28 +410,26 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -465,28 +441,26 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -498,28 +472,26 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -531,28 +503,26 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro *****************************************************************************/ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -564,28 +534,26 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -597,28 +565,26 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -630,28 +596,26 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -663,28 +627,26 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -696,28 +658,26 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -729,28 +689,26 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -762,28 +720,26 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -795,28 +751,26 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -828,28 +782,26 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -861,28 +813,26 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT *****************************************************************************/ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -894,28 +844,26 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -927,28 +875,26 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -960,28 +906,26 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -993,28 +937,26 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1030,28 +972,26 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1063,28 +1003,26 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1096,28 +1034,26 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1129,28 +1065,26 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1162,28 +1096,26 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1195,28 +1127,26 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1228,28 +1158,26 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1261,29 +1189,26 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + 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, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } - diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 552b39ff27..0d79daf656 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -26,12 +26,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -63,150 +63,151 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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); - /* 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.*/ + /* 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); + 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); + 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); + 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); + 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); + 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); + 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); + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4); + 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); + 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); + 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); + 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); + 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); + 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ /* Timer default values */ @@ -235,24 +236,22 @@ void Q931CreateTE(L3UCHAR i) *****************************************************************************/ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + if (iFrom == 4) { + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { - ret = Q931Tx34(pTrunk,buf,pMes->Size); + else if (iFrom == 2) { + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -264,28 +263,26 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -297,32 +294,29 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF *****************************************************************************/ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pTrunk->autoConnectAck) { Q931AckConnect(pTrunk, buf); } - } return ret; } @@ -334,28 +328,26 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -367,28 +359,26 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -400,73 +390,64 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT rc=0; Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; + 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; - } + /* 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; + 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; + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); + if (ret) + return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, 303); /* TODO: Add this back when we get the state stuff more filled out */ - //Q931SetState(pTrunk, callIndex, Q931_U1); - } + /*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 */ + 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; + } - 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) { + /* 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 - { + 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; + Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81); + return ret; } #if 0 /* TODO: Unreachable code??? */ - /* Set state U6 */ - Q931SetState(pTrunk, callIndex, Q931_U6); + /* Set state U6 */ + Q931SetState(pTrunk, callIndex, Q931_U6); - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, 303); #endif - } - + } return rc; } @@ -485,22 +466,20 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + if (iFrom ==4) { + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - else if (iFrom ==2) - { - Q931StartTimer(pTrunk, callIndex, 303); + else if (iFrom == 2) { + Q931StartTimer(pTrunk, callIndex, 303); } return ret; } @@ -512,34 +491,31 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - L3INT callIndex; - L3INT ret = Q931E_NO_ERROR; + 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; + 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; + /* Send RESUME to network */ + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); + if (ret != Q931E_NO_ERROR) + return ret; - /* Start timer T318 */ - Q931StartTimer(pTrunk, callIndex, 318); + /* Start timer T318 */ + Q931StartTimer(pTrunk, callIndex, 318); - /*set state U17 */ - Q931SetState(pTrunk, callIndex, Q931_U17); - } - else - { - return Q931E_ILLEGAL_MESSAGE; - } - return ret; + /* set state U17 */ + Q931SetState(pTrunk, callIndex, Q931_U17); + } else { + return Q931E_ILLEGAL_MESSAGE; + } + return ret; } /***************************************************************************** @@ -549,28 +525,26 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -582,28 +556,26 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -615,28 +587,26 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro *****************************************************************************/ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -648,28 +618,26 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -681,28 +649,26 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -714,28 +680,26 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -747,31 +711,29 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -783,19 +745,21 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace]; - 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); - } + 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) @@ -813,27 +777,24 @@ L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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 (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) + 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); + ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } - } return ret; } @@ -845,32 +806,29 @@ L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i *****************************************************************************/ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* TODO - Set correct timer here */ Q931StartTimer(pTrunk, callIndex, 303); } - /* TODO chack against state table for illegal or unexpected message here*/ + /* 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); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); if (pTrunk->autoRestartAck) { Q931AckRestart(pTrunk, buf); @@ -886,30 +844,28 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; /* TODO - Set correct timer here */ Q931StartTimer(pTrunk, callIndex, 303); } - /* TODO chack against state table for illegal or unexpected message here*/ + /* 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); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -921,28 +877,26 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -954,28 +908,26 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT *****************************************************************************/ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -987,28 +939,26 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1020,28 +970,26 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1053,28 +1001,26 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1086,28 +1032,26 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr *****************************************************************************/ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1123,28 +1067,26 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1156,28 +1098,26 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1189,28 +1129,26 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1222,28 +1160,26 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1255,28 +1191,26 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1288,28 +1222,26 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1321,28 +1253,26 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) *****************************************************************************/ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } @@ -1354,29 +1284,26 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom *****************************************************************************/ L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) { - L3INT callIndex; - L3INT ret=Q931E_NO_ERROR; 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) + if (ret != Q931E_NO_ERROR) return ret; - /* TODO chack against state table for illegal or unexpected message here*/ + /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); - if(iFrom == 4) - { - /* TODO Add proc here*/ - ret = Q931Tx32Data(pTrunk,0,buf,pMes->Size); + Q931StartTimer(pTrunk, callIndex, 303); + 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); + else if (iFrom == 2) { + /* TODO Add proc here */ + ret = Q931Tx34(pTrunk, buf, pMes->Size); } return ret; } - diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index d7716bc3da..095e8cd577 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -1,28 +1,28 @@ /***************************************************************************** - FileName: Q931ie.c + FileName: Q931ie.c - Contents: Information Element Pack/Unpack functions. + 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. + 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. + 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: + 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). + 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. + used in QSIG, NI2, Q.932 etc are located in separate files. - See q931.h for description. + See q931.h for description. License/Copyright: @@ -33,12 +33,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -59,40 +59,39 @@ /***************************************************************************** - Macro: Q931MoreIE + 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. + 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 Q931MoreIE() (Octet + Off - 2 < IESize) -#define Q931IESizeTest(x) {\ - if(Octet+Off-2 != IESize)\ - {\ - Q931SetError(pTrunk,x, Octet, Off);\ - return x;\ - }\ - } +#define Q931IESizeTest(x) {\ + if (Octet + Off - 2 != IESize) {\ + Q931SetError(pTrunk, x, Octet, Off);\ + return x;\ + }\ +} /***************************************************************************** - Function: Q931ReadExt + 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. + 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. + 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 + Parameters: IBuf ptr to octet array. + Off Starting offset counter Return Value: New offset value. @@ -100,27 +99,27 @@ L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off) { - L3INT c =0; - while((IBuf[c] & 0x80) == 0) - c++; - - return Off + c; + L3INT c = 0; + while ((IBuf[c] & 0x80) == 0) { + c++; + } + return Off + c; } /***************************************************************************** - Function: Q931Uie_BearerCap + 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 + 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. + 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 @@ -128,900 +127,852 @@ L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off) L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) { - Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf; + Q931ie_BearerCap *pie = (Q931ie_BearerCap*)OBuf; ie *pIE = &pMsg->BearerCap; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - *pIE=0; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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 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 */ + 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 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 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. */ + /* 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; - } + 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 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 5c */ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { + /* Octet 5d */ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->DuplexMode = ieGetOctet((IBuf[Octet + Off] & 0x40) >> 6); + pie->ModemType = ieGetOctet(IBuf[Octet + Off] & 0x3f); + Off ++; + } + } + } + } + } - 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 6 */ + if ((IBuf[Octet + Off] & 0x60) == 0x40 && Q931MoreIE()) { + pie->Layer2Ident = ieGetOctet((IBuf[Octet + Off] & 0x60) >> 5); + pie->UIL2Prot = ieGetOctet(IBuf[Octet + Off] & 0x1f); - /* Octet 5d */ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { + Off = Q931ReadExt(&IBuf[Octet + Off], Off); + Octet ++; + } - pie->DuplexMode = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6); - pie->ModemType = ieGetOctet(IBuf[Octet+Off] & 0x3f); - Off ++; - } - } - } - } - } + /* 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 6 */ - if((IBuf[Octet+Off] & 0x60) == 0x40 && Q931MoreIE()) - { - pie->Layer2Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5); - pie->UIL2Prot = ieGetOctet(IBuf[Octet+Off] & 0x1f); + /* Octet 7a */ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + if (pie->UIL3Prot == 0x0c) { + pie->AL3Info1 = ieGetOctet(IBuf[Octet + Off] & 0x0f); + Off++; - Off = Q931ReadExt(&IBuf[Octet+Off], Off); - Octet ++; - } + /* 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; - /* 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); + Q931IESizeTest(Q931E_BEARERCAP); + Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_BearerCap); - pie->Size = sizeof(Q931ie_BearerCap); + *OOff = (*OOff) + sizeof(Q931ie_BearerCap); + pie->Size = sizeof(Q931ie_BearerCap); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_BearerCap + 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. + 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. + 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 + 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; + 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 */ + OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ; + li = (*Octet)++; /* remember length position */ - /* Octet 3 - Coding standard / Information transfer capability */ + /* Octet 3 - Coding standard / Information transfer capability */ OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | (pIE->ITC & 0x1f); - /* Octet 4 - Transfer mode / Information transfer rate */ + /* 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 */ + 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))) - { + 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 */ + + /* 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 + /* 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 + } + 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 + /* 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 */ + /* 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) { + /* 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) - { + /* 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 */ + /* Octet 7a - Additional information layer 3 msb */ OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1 & 0x0f); - /* Octet 7b - Additional information layer 3 lsb */ + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallID + 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 + 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. + 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; + Q931ie_CallID *pie = (Q931ie_CallID*)OBuf; ie *pIE = &pMsg->CallID; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - do{ - pie->CallId[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - }while(Q931MoreIE()); + /* Octet 3 */ + do { + pie->CallId[x] = IBuf[Octet + Off] & 0x7f; + Off++; + x++; + } while (Q931MoreIE()); - Q931IESizeTest(Q931E_CALLID); - - Q931SetIE(*pIE, *OOff); + 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); + *OOff = (*OOff) + sizeof(Q931ie_CallID) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallID) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallID + Function: Q931Pie_CallID - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 */ + OBuf[(*Octet)++] = Q931ie_CALL_IDENTITY ; + li = (*Octet)++; /* remember length position */ - for(x=0;x < sCI; x++) - { - OBuf[(*Octet)++] = pIE->CallId[x]; - } + for (x = 0; x < sCI; x++) { + OBuf[(*Octet)++] = pIE->CallId[x]; + } - OBuf[(*Octet)-1] |= 0x80; /* set complete flag at last octet*/ + OBuf[(*Octet) - 1] |= 0x80; /* set complete flag at last octet*/ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallState + 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 + 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. + 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; + Q931ie_CallState *pie = (Q931ie_CallState*)OBuf; ie *pIE = &pMsg->CallState; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; + /* Octet 3 */ + pie->CodStand = (IBuf[Octet + Off] >> 6) & 0x03; + pie->CallState = IBuf[Octet + Off] & 0x3f; + Octet++; - /* Octet 3 */ - pie->CodStand = (IBuf[Octet+Off] >> 6) & 0x03; - pie->CallState= IBuf[Octet+Off] & 0x3f; - - Octet++; - - Q931IESizeTest(Q931E_CALLSTATE); - - Q931SetIE(*pIE, *OOff); + Q931IESizeTest(Q931E_CALLSTATE); + Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallState); - pie->Size = sizeof(Q931ie_CallState); + *OOff = (*OOff) + sizeof(Q931ie_CallState); + pie->Size = sizeof(Q931ie_CallState); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallState + Function: Q931Pie_CallState - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; + 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)++] = Q931ie_CALL_STATE; + li = (*Octet)++; /* remember length position */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CalledSub + 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 + 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. + 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; + Q931ie_CalledSub *pie = (Q931ie_CalledSub*)OBuf; ie *pIE = &pMsg->CalledSub; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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); + /* 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); + 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); + *OOff = (*OOff) + sizeof(Q931ie_CalledSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledSub) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CalledSub + Function: Q931Pie_CalledSub - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 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]; - } + /* 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[(*Octet) - 1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CalledNum + 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 + 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. + 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; + Q931ie_CalledNum *pie = (Q931ie_CalledNum*)OBuf; ie *pIE = &pMsg->CalledNum; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; /* # digits in this case */ + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; /* # digits in this case */ - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet++]; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->TypNum = (IBuf[Octet+Off] >> 4) & 0x07; - pie->NumPlanID = IBuf[Octet+Off] & 0x0f; - 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()); + /* 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); + Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x); + *OOff = (*OOff) + sizeof(Q931ie_CalledNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CalledNum) + x); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CalledNum + Function: Q931Pie_CalledNum - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 1 */ + OBuf[(*Octet)++] = Q931ie_CALLED_PARTY_NUMBER; + /* Octet 2 */ - li=(*Octet)++; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypNum << 4) | (pIE->NumPlanID); - - /* Octet 4 */ - for(x=0;xDigit[x]; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallingNum + 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 + 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. + 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; + Q931ie_CallingNum *pie = (Q931ie_CallingNum*)OBuf; ie *pIE = &pMsg->CallingNum; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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 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; - do{ - pie->Digit[x] = IBuf[Octet+Off] & 0x7f; - Off++; - x++; - } while((IBuf[Octet+Off]&0x80) == 0 && Q931MoreIE()); + /* 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'; - Q931IESizeTest(Q931E_CALLINGNUM); + Q931IESizeTest(Q931E_CALLINGNUM); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingNum) + x; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingNum) + x); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallingNum + Function: Q931Pie_CallingNum - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 1 */ + OBuf[(*Octet)++] = Q931ie_CALLING_PARTY_NUMBER; /* Octet 2 */ - li=(*Octet)++; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID); - - /* Octet 4 */ - OBuf[(*Octet)++] = 0x80; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x00 | (pIE->TypNum << 4) | (pIE->NumPlanID); + + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80; - /* Octet 5 */ - for(x=0;xDigit[x]; - } + /* Octet 5 */ + for (x = 0; xDigit[x]; + } - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CallingSub + 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 + 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. + 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; + Q931ie_CallingSub *pie = (Q931ie_CallingSub*)OBuf; ie *pIE = &pMsg->CallingSub; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = 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); + /* 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); + Q931IESizeTest(Q931E_CALLINGSUB); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CallingSub + Function: Q931Pie_CallingSub - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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 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]; - } + /* 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[(*Octet) - 1] |= 0x80; /* Terminate bit */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_Cause + 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 + 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. + 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; + Q931ie_Cause *pie = (Q931ie_Cause*)OBuf; ie *pIE = &pMsg->Cause; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2*/ + IESize = IBuf[Octet++]; - /* Octet 3*/ - pie->CodStand = (IBuf[Octet+Off]>>5) & 0x03; - pie->Location = IBuf[Octet+Off] & 0x0f; + /* 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 3a */ + if ((IBuf[Octet + Off] & 0x80) == 0) { + Off++; + pie->Recom = IBuf[Octet + Off] & 0x7f; + } + Octet++; - /* Octet 4 */ - pie->Value = IBuf[Octet+Off] & 0x7f; + /* Octet 4 */ + pie->Value = IBuf[Octet + Off] & 0x7f; Octet++; /* Consume optional Diagnostic bytes */ @@ -1030,124 +981,123 @@ L3INT Q931Uie_Cause(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * I }; Q931IESizeTest(Q931E_CAUSE); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Cause); + pie->Size = sizeof(Q931ie_Cause); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Cause); - pie->Size = sizeof(Q931ie_Cause); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Cause + Function: Q931Pie_Cause - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Cause *pIE = (Q931ie_Cause*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_CAUSE; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_CAUSE; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | pIE->Location; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | pIE->Location; - /* Octet 3a - currently not supported in send */ + /* Octet 3a - currently not supported in send */ - /* Octet 4 */ - OBuf[(*Octet)++] = 0x80 | pIE->Value; + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80 | pIE->Value; - /* Octet 5 - diagnostics not supported in send */ + /* Octet 5 - diagnostics not supported in send */ - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CongLevel + 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 + 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. + 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; + Q931ie_CongLevel *pie = (Q931ie_CongLevel*)OBuf; ie *pIE = &pMsg->CongestionLevel; - L3INT Off = 0; - L3INT Octet = 0; + L3INT Off = 0; + L3INT Octet = 0; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet] & 0xf0; - pie->CongLevel = IBuf[Octet] & 0x0f; - Octet ++; + pie->IEId = IBuf[Octet] & 0xf0; + pie->CongLevel = IBuf[Octet] & 0x0f; + Octet ++; - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CongLevel); - pie->Size = sizeof(Q931ie_CongLevel); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CongLevel); + pie->Size = sizeof(Q931ie_CongLevel); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_CongLevel + Function: Q931Pie_CongLevel - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; */ + Q931ie_CongLevel *pIE = (Q931ie_CongLevel*)IBuf; + L3INT rc = 0; + /* L3INT Beg = *Octet; */ - OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel; - - return rc; + OBuf[(*Octet)++] = Q931ie_CONGESTION_LEVEL | pIE->CongLevel; + + return rc; } /***************************************************************************** - Function: Q931Uie_ChanID + 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 + 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. + 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 + Return Value: Error code, 0 = OK *****************************************************************************/ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff) @@ -1178,22 +1128,20 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * Off = Q931ReadExt(&IBuf[Octet++], Off); /* Octet 3.1 */ - if(pie->IntIDPresent) - { - pie->InterfaceID = IBuf[Octet+Off] & 0x7f; + 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 = Q931ReadExt(&IBuf[Octet + Off], Off); Off++; } if ((Octet + Off - 2) != IESize) { /* Octet 3.2 */ - if(pie->IntType == 1) /* PRI etc */ - { + 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; @@ -1201,31 +1149,29 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * /* Octet 3.3 */ /* Temp fix. Assume B channel. H channels not supported */ - pie->ChanSlot = IBuf[Octet+Off] & 0x7f; + 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); + 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) - { + if (pTrunk->loglevel == Q931_LOG_DEBUG) { const char *iface; char tmp[100] = ""; - if(!pie->IntType) { - switch(pie->InfoChanSel) { + if (!pie->IntType) { + switch (pie->InfoChanSel) { case 0x0: iface = "None"; break; @@ -1251,1818 +1197,1714 @@ L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * ((pie->IntType) ? "PRI/Other" : "BRI"), tmp); } - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ChanID + Function: Q931Pie_ChanID - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_ChanID *pIE = (Q931ie_ChanID*)IBuf; L3INT rc = Q931E_NO_ERROR; L3INT Beg = *Octet; /* remember current offset */ - L3INT li; + L3INT li; - OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION; - li = (*Octet)++; /* remember length position */ + OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION; + li = (*Octet)++; /* remember length position */ - /* Octet 3 flags & BRI chan # */ - OBuf[(*Octet)++] = 0x80 + /* 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) - { + /* 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 + /* 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; + /* 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; + 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_CRV + 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. + 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 + 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. + 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++]; + 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; - } + 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; + *IOff = Octet; + return CRV; } /***************************************************************************** - Function: Q931Uie_DateTime + 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 [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. + 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; + Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf; ie *pIE = &pMsg->DateTime; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize=0; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize = 0; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet++]; - - /* Octet 2 */ - IESize = IBuf[Octet++]; + pie->IEId = IBuf[Octet++]; + + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 - Year */ - pie->Year = IBuf[Octet++]; + /* Octet 3 - Year */ + pie->Year = IBuf[Octet++]; - /* Octet 4 - Month */ - pie->Month = IBuf[Octet++]; + /* Octet 4 - Month */ + pie->Month = IBuf[Octet++]; - /* Octet 5 - Day */ - pie->Day = 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; + /******************************************************************* + 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 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 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++]; - } - } - } + /* Octet 8 - Second (optional)*/ + if (IESize >= 6) { + pie->Format = 3; + pie->Second = IBuf[Octet++]; + } + } + } - Q931IESizeTest(Q931E_DATETIME); + Q931IESizeTest(Q931E_DATETIME); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_DateTime); + pie->Size = sizeof(Q931ie_DateTime); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_DateTime); - pie->Size = sizeof(Q931ie_DateTime); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_DateTime + Function: Q931Pie_DateTime - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_DateTime *pIE = (Q931ie_DateTime*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_DATETIME; - li=(*Octet)++; + 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[(*Octet)++] = pIE->Year; + OBuf[(*Octet)++] = pIE->Month; + OBuf[(*Octet)++] = pIE->Day; + if (pIE->Format >= 1) { + OBuf[(*Octet)++] = pIE->Hour; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + 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 + 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 + 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. + 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; + Q931ie_Display *pie = (Q931ie_Display*)OBuf; ie *pIE = &pMsg->Display; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; + IESize = IBuf[Octet++]; - IESize = IBuf[Octet ++]; + for (x = 0; xDisplay[x] = IBuf[Octet + Off] & 0x7f; + Off++; + } - for(x=0; xDisplay[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } + Q931IESizeTest(Q931E_DISPLAY); + Q931SetIE(*pIE, *OOff); - Q931IESizeTest(Q931E_DISPLAY); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1); - 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; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Display + Function: Q931Pie_Display - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Display *pIE = (Q931ie_Display*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; + L3INT DSize; + L3INT x; - OBuf[(*Octet)++] = Q931ie_DISPLAY; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_DISPLAY; + li = (*Octet)++; - DSize = pIE->Size - sizeof(Q931ie_Display); + DSize = pIE->Size - sizeof(Q931ie_Display); - for(x=0; x< DSize; x++) - { - - OBuf[(*Octet)++] = pIE->Display[x]; - } + for (x = 0; x< DSize; x++) { + + OBuf[(*Octet)++] = pIE->Display[x]; + } - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_HLComp + 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 + 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. + 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; + Q931ie_HLComp * pie = (Q931ie_HLComp*)OBuf; ie *pIE = &pMsg->HLComp; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet */ - IESize = 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 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); - } + /* 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); + Q931IESizeTest(Q931E_HLCOMP); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_HLComp); + pie->Size = sizeof(Q931ie_HLComp); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_HLComp); - pie->Size = sizeof(Q931ie_HLComp); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_HLComp + Function: Q931Pie_HLComp - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_HLComp *pIE = (Q931ie_HLComp*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_HIGH_LAYER_COMPATIBILITY; - li=(*Octet)++; + 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 3 */ + OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | ((pIE->Interpret << 2) & 0x1c) | (pIE->PresMeth & 0x03); - /* Octet 4 */ - OBuf[(*Octet)++] = pIE->HLCharID; + /* 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; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_KeypadFac + 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 + 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. + 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; + Q931ie_KeypadFac *pie = (Q931ie_KeypadFac*)OBuf; ie *pIE = &pMsg->KeypadFac; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; - L3INT x; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; + L3INT x; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; + IESize = IBuf[Octet++]; - IESize = IBuf[Octet ++]; + for (x = 0; xKeypadFac[x] = IBuf[Octet + Off] & 0x7f; + Off++; + } - for(x=0; xKeypadFac[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } + Q931IESizeTest(Q931E_KEYPADFAC); + Q931SetIE(*pIE, *OOff); - Q931IESizeTest(Q931E_KEYPADFAC); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_KeypadFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_KeypadFac) + x - 1); - 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; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_KeypadFac + Function: Q931Pie_KeypadFac - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_KEYPAD_FACILITY; + li = (*Octet)++; - DSize = pIE->Size - sizeof(Q931ie_KeypadFac) + 1; + DSize = pIE->Size - sizeof(Q931ie_KeypadFac) + 1; - for(x=0; x< DSize; x++) - { - OBuf[(*Octet)++] = pIE->KeypadFac[x]; - } + for (x = 0; x< DSize; x++) { + OBuf[(*Octet)++] = pIE->KeypadFac[x]; + } - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_LLComp + 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 + 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. + 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; + Q931ie_LLComp *pie = (Q931ie_LLComp*)OBuf; ie *pIE = &pMsg->LLComp; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3*/ + /* Octet 3 */ + pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03; + pie->ITransCap = IBuf[Octet + Off] & 0x1f; + Octet++; - pie->CodStand = (IBuf[Octet+Off] >> 5) & 0x03; - pie->ITransCap= IBuf[Octet+Off] & 0x1f; + /* Octet 3a*/ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->NegotInd = (IBuf[Octet + Off] >> 6) & 0x01; + Off++; + } - Octet++; + /* Octet 4 */ + pie->TransMode = (IBuf[Octet + Off] >> 5) & 0x03; + pie->InfoRate = IBuf[Octet + Off] & 0x1f; - /* Octet 3a*/ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { - pie->NegotInd = (IBuf[Octet+Off] >> 6) & 0x01; - Off++; - } + Octet++; - /* Octet 4 */ - pie->TransMode = (IBuf[Octet+Off] >> 5) & 0x03; - pie->InfoRate = IBuf[Octet+Off] & 0x1f; + /* Octet 4.1 */ + if (pie->InfoRate == 0x14) { /* Mutirate */ + pie->RateMul = IBuf[Octet + Off] & 0x7f; + Off++; + } - Octet++; + /* 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 4.1 */ - if(pie->InfoRate == 0x14 ) /* Mutirate */ - { - pie->RateMul = IBuf[Octet+Off] & 0x7f; - Off++; - } + /* 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 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 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++; + /* 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 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 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 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 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 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 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 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 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 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 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 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 7b*/ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->DefPackSize = IBuf[Octet + Off] & 0x0f; + 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 7c */ + if (IsQ931Ext(IBuf[Octet + Off - 1])) { + pie->PackWinSize= IBuf[Octet + Off] & 0x7f; + } + } + } + } + } - /* 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++; - } + Q931IESizeTest(Q931E_LLCOMP); + Q931SetIE(*pIE, *OOff); - /* Octet 7b*/ - if(IsQ931Ext(IBuf[Octet+Off-1])) - { - pie->DefPackSize = IBuf[Octet+Off] & 0x0f; - Off++; + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_LLComp); + pie->Size = sizeof(Q931ie_LLComp); - /* 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; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_LLComp + Function: Q931Pie_LLComp - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; + Q931ie_LLComp *pIE = (Q931ie_LLComp*)IBuf; + L3INT rc = 0; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_LOW_LAYER_COMPATIBILITY; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_LOW_LAYER_COMPATIBILITY; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = (pIE->CodStand << 6) | pIE->ITransCap; + /* Octet 3 */ + OBuf[(*Octet)++] = (pIE->CodStand << 6) | pIE->ITransCap; - /* Octet 3a*/ - OBuf[(*Octet)++] = 0x80 | (pIE->NegotInd << 6); + /* Octet 3a */ + OBuf[(*Octet)++] = 0x80 | (pIE->NegotInd << 6); - /* Octet 4 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TransMode << 5) | pIE->InfoRate; + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80 | (pIE->TransMode << 5) | pIE->InfoRate; - /* Octet 4.1*/ - if(pIE->InfoRate == 0x18) - { - OBuf[(*Octet)++] = 0x80 | pIE->RateMul; - } + /* 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; - } + /* 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 ; + /* 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 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 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 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 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 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 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 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; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_NetFac + 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 + 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. + 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; + Q931ie_NetFac *pie = (Q931ie_NetFac*)OBuf; ie *pIE = &pMsg->NetFac; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - pie->LenNetID = IBuf[Octet+Off]; /* full octet is used */ - 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++; + 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 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++; + /* Octet 4*/ + pie->NetFac = IBuf[Octet + Off]; /* Full Octet is used */ + Octet++; - Q931IESizeTest(Q931E_NETFAC); + Q931IESizeTest(Q931E_NETFAC); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NetFac) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_NetFac) + x - 1); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_NetFac + Function: Q931Pie_NetFac - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_NETWORK_SPECIFIC_FACILITIES; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = pIE->LenNetID; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->LenNetID; - if(pIE->LenNetID > 0) - { - /* Octet 3.1 */ - OBuf[(*Octet)++] = 0x80 | (pIE->TypeNetID << 4) | pIE->NetIDPlan; + 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 3.2 */ + for (x = 0; x LenNetID; x++) { + OBuf[(*Octet)++] = pIE->NetID[x]; + } + } - /* Octet 4*/ - OBuf[(*Octet)++] = pIE->NetFac; + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->NetFac; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_NotifInd + 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 + 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. + 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; + Q931ie_NotifInd *pie = (Q931ie_NotifInd*)OBuf; ie *pIE = &pMsg->NotifInd; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2*/ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Notification = IBuf[Octet+Off] & 0x7f; + /* Octet 3 */ + pie->Notification = IBuf[Octet + Off] & 0x7f; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - Q931IESizeTest(Q931E_NOTIFIND); + Q931IESizeTest(Q931E_NOTIFIND); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_NotifInd); + pie->Size = sizeof(Q931ie_NotifInd); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_NotifInd); - pie->Size = sizeof(Q931ie_NotifInd); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_NotifInd + Function: Q931Pie_NotifInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_NotifInd *pIE = (Q931ie_NotifInd*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_NOTIFICATION_INDICATOR; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_NOTIFICATION_INDICATOR; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = pIE->Notification; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->Notification; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_ProgInd + 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 + 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. + 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; + Q931ie_ProgInd *pie = (Q931ie_ProgInd*)OBuf; ie *pIE = &pMsg->ProgInd; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3*/ - pie->CodStand = (IBuf[Octet+Off] >> 5) & 0x03; - pie->Location = IBuf[Octet+Off] & 0x0f; + /* Octet 3 */ + pie->CodStand = (IBuf[Octet + Off] >> 5) & 0x03; + pie->Location = IBuf[Octet + Off] & 0x0f; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - /* Octet 4*/ - pie->ProgDesc = IBuf[Octet+Off] & 0x7f; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + /* Octet 4 */ + pie->ProgDesc = IBuf[Octet + Off] & 0x7f; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - Q931IESizeTest(Q931E_PROGIND); + Q931IESizeTest(Q931E_PROGIND); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ProgInd); + pie->Size = sizeof(Q931ie_ProgInd); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_ProgInd); - pie->Size = sizeof(Q931ie_ProgInd); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ProgInd + Function: Q931Pie_ProgInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset L3INTo OBuf. + 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; + Q931ie_ProgInd *pIE = (Q931ie_ProgInd*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_PROGRESS_INDICATOR; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_PROGRESS_INDICATOR; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | pIE->Location; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | pIE->Location; - /* Octet 4*/ - OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; + /* Octet 4 */ + OBuf[(*Octet)++] = 0x80 | pIE->ProgDesc; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_RepeatInd + 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 + 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. + 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; + Q931ie_RepeatInd *pie = (Q931ie_RepeatInd*)OBuf; ie *pIE = &pMsg->RepeatInd; - L3INT Off = 0; - L3INT Octet = 0; + L3INT Off = 0; + L3INT Octet = 0; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet] & 0xf0; - pie->RepeatInd = IBuf[Octet] & 0x0f; - Octet ++; + pie->IEId = IBuf[Octet] & 0xf0; + pie->RepeatInd = IBuf[Octet] & 0x0f; + Octet ++; - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); - pie->Size = sizeof(Q931ie_RepeatInd); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RepeatInd); + pie->Size = sizeof(Q931ie_RepeatInd); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_RepeatInd + Function: Q931Pie_RepeatInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; */ + Q931ie_RepeatInd *pIE = (Q931ie_RepeatInd*)IBuf; + L3INT rc = 0; + /* L3INT Beg = *Octet; */ - OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd; - - return rc; + OBuf[(*Octet)++] = Q931ie_REPEAT_INDICATOR | pIE->RepeatInd; + + return rc; } /***************************************************************************** - Function: Q931Uie_RevChargeInd + 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 + 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. + 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 iE; /* ie *pIE = &pMsg->RevChargeInd; */ - Q931SetIE(iE, *OOff); + Q931SetIE(iE, *OOff); - return iE; + return iE; } /***************************************************************************** - Function: Q931Pie_RevChargeInd + Function: Q931Pie_RevChargeInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + Return Value: Error code, 0 = OK *****************************************************************************/ L3INT Q931Pie_RevChargeInd(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Uie_RestartInd + 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 + 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. + 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; + Q931ie_RestartInd *pie = (Q931ie_RestartInd*)OBuf; ie *pIE = &pMsg->RestartInd; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Class = IBuf[Octet+Off] & 0x07; - pie->Spare = IBuf[Octet+Off] & 0x78; + /* Octet 3 */ + pie->Class = IBuf[Octet + Off] & 0x07; + pie->Spare = IBuf[Octet + Off] & 0x78; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - Q931IESizeTest(Q931E_RESTARTIND); + Q931IESizeTest(Q931E_RESTARTIND); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); - - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_RestartInd); - pie->Size = sizeof(Q931ie_RestartInd); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_RestartInd); + pie->Size = sizeof(Q931ie_RestartInd); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_RestartInd + Function: Q931Pie_RestartInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_RestartInd *pIE = (Q931ie_RestartInd*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_RESTART_INDICATOR; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_RESTART_INDICATOR; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = 0x80 | pIE->Class ; + /* Octet 3*/ + OBuf[(*Octet)++] = 0x80 | pIE->Class ; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_Segment + 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 + 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. + 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; + Q931ie_Segment *pie = (Q931ie_Segment*)OBuf; ie *pIE = &pMsg->Segment; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; + Octet++; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2*/ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->FSI = (IBuf[Octet+Off] & 0x80) >> 7; - pie->NumSegRem = IBuf[Octet+Off] & 0x7f; - 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); + /* Octet 4 */ + pie->SegType = IBuf[Octet + Off] & 0x7f; + Octet++; + + Q931IESizeTest(Q931E_SEGMENT); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Segment); + pie->Size = sizeof(Q931ie_Segment); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Segment); - pie->Size = sizeof(Q931ie_Segment); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Segment + Function: Q931Pie_Segment - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Segment *pIE = (Q931ie_Segment*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_SEGMENTED_MESSAGE; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_SEGMENTED_MESSAGE; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = (pIE->FSI<<7) | pIE->NumSegRem; + /* Octet 3 */ + OBuf[(*Octet)++] = (pIE->FSI << 7) | pIE->NumSegRem; - /* Octet 4 */ - OBuf[(*Octet)++] = pIE->SegType; + /* Octet 4 */ + OBuf[(*Octet)++] = pIE->SegType; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_SendComplete + 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 + 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. + 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; + Q931ie_SendComplete *pie = (Q931ie_SendComplete*)OBuf; ie *pIE = &pMsg->SendComplete; - L3INT Off = 0; - L3INT Octet = 0; + L3INT Off = 0; + L3INT Octet = 0; - *pIE=0; + *pIE = 0; + Octet++; - Octet ++; + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_SendComplete); + pie->Size = sizeof(Q931ie_SendComplete); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_SendComplete); - pie->Size = sizeof(Q931ie_SendComplete); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ProgInd + Function: Q931Pie_ProgInd - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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; */ + /* Q931ie_SendComplete * pIE = (Q931ie_SendComplete*)IBuf; */ + L3INT rc = Q931E_NO_ERROR; + /* L3INT Beg = *Octet; */ - OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; + OBuf[(*Octet)++] = 0x80 | (L3UCHAR)Q931ie_SENDING_COMPLETE; - return rc; + return rc; } /***************************************************************************** - Function: Q931Uie_Signal + 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 + 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. + 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; + Q931ie_Signal *pie = (Q931ie_Signal*)OBuf; ie *pIE = &pMsg->Signal; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Signal = IBuf[Octet+Off]; - Octet++; + /* Octet 3 */ + pie->Signal = IBuf[Octet + Off]; + Octet++; - Q931IESizeTest(Q931E_SIGNAL); + Q931IESizeTest(Q931E_SIGNAL); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_Signal); + pie->Size = sizeof(Q931ie_Signal); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_Signal); - pie->Size = sizeof(Q931ie_Signal); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_Signal + Function: Q931Pie_Signal - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_Signal *pIE = (Q931ie_Signal*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_SIGNAL; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_SIGNAL; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = pIE->Signal; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->Signal; - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_TransNetSel + 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 + 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. + 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; + Q931ie_TransNetSel *pie = (Q931ie_TransNetSel*)OBuf; ie *pIE = &pMsg->TransNetSel; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT l; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; + /* Octet 2 */ + l = IBuf[Octet++] - 3; - /* Octet 3*/ - pie->Type = (IBuf[Octet+Off] >> 4) & 0x07; + /* Octet 3 */ + pie->Type = (IBuf[Octet + Off] >> 4) & 0x07; - Off = Q931ReadExt(&IBuf[Octet], Off); - Octet++; + Off = Q931ReadExt(&IBuf[Octet], Off); + Octet++; - for(x=0; x < l; x++) - { - pie->NetID[x] = IBuf[Octet+Off] & 0x7f; - Off++; - } + for (x = 0; x < l; x++) { + pie->NetID[x] = IBuf[Octet + Off] & 0x7f; + Off++; + } - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_TransNetSel) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_TransNetSel) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_TransNetSel + Function: Q931Pie_TransNetSel - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_TRANSIT_NETWORK_SELECTION; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = 0x80 | (pIE->Type<<4) | pIE->NetIDPlan; + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | (pIE->Type << 4) | pIE->NetIDPlan; - /* Octet 4 */ - l = pIE->Size - sizeof(Q931ie_TransNetSel) + 1; - for(x=0;xNetID[x]; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_UserUser + 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 + 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. + 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; + Q931ie_UserUser *pie = (Q931ie_UserUser*)OBuf; ie *pIE = &pMsg->UserUser; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x=0; - L3INT l; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x = 0; + L3INT l; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - l = IBuf[Octet] - 3; - Octet++; + /* Octet 2 */ + l = IBuf[Octet++] - 3; - /* Octet 3*/ - pie->ProtDisc = IBuf[Octet+Off]; - Octet++; + /* Octet 3 */ + pie->ProtDisc = IBuf[Octet + Off]; + Octet++; - for(x=0; x < l; x++) - { - pie->User[x] = IBuf[Octet+Off]; - Off++; - } + for (x = 0; x < l; x++) { + pie->User[x] = IBuf[Octet + Off]; + Off++; + } - Q931SetIE(*pIE, *OOff); + Q931SetIE(*pIE, *OOff); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_UserUser + Function: Q931Pie_UserUser - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + 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)++; + OBuf[(*Octet)++] = Q931ie_USER_USER; + li = (*Octet)++; - /* Octet 3 */ - OBuf[(*Octet)++] = pIE->ProtDisc; + /* Octet 3 */ + OBuf[(*Octet)++] = pIE->ProtDisc; - /* Octet 4 */ - l = pIE->Size - sizeof(Q931ie_UserUser) + 1; - for(x=0;xUser[x]; - } + /* 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; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } /***************************************************************************** - Function: Q931Uie_GenericDigits + 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 + 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. + 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; + Q931ie_GenericDigits *pie = (Q931ie_GenericDigits*)OBuf; ie *pIE = &pMsg->GenericDigits; - L3INT Off = 0; - L3INT Octet = 0; - L3INT x; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT x; + L3INT IESize; - *pIE=0; + *pIE = 0; - /* Octet 1 */ - pie->IEId = IBuf[Octet]; - Octet ++; + /* Octet 1 */ + pie->IEId = IBuf[Octet++]; - /* Octet 2 */ - IESize = IBuf[Octet ++]; + /* Octet 2 */ + IESize = IBuf[Octet++]; - /* Octet 3 */ - pie->Type = (IBuf[Octet]) & 0x1F; - pie->Encoding = (IBuf[Octet] >> 5) & 0x07; - Octet ++; - - /* Octet 4*/ + /* 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; + 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; + pie->Digit[x++] = IBuf[Octet + Off] & 0x0f; if (Q931MoreIE()) { - pie->Digit[x] = (IBuf[Octet+Off] >> 4) & 0x0f; + pie->Digit[x] = (IBuf[Octet + Off] >> 4) & 0x0f; } x++; Off++; @@ -3070,7 +2912,7 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U } else if (pie->Encoding == 2) { /* IA5 */ x = 0; do { - pie->Digit[x++] = IBuf[Octet+Off] & 0x7f; + pie->Digit[x++] = IBuf[Octet + Off] & 0x7f; Off++; } while (Q931MoreIE()); } else { @@ -3079,112 +2921,108 @@ L3INT Q931Uie_GenericDigits(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3U return Q931E_GENERIC_DIGITS; } - Q931IESizeTest(Q931E_GENERIC_DIGITS); + Q931IESizeTest(Q931E_GENERIC_DIGITS); + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x - 1); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_CallingSub) + x -1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_CallingSub) + x -1); - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_GenericDigits + Function: Q931Pie_GenericDigits - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + OBuf[(*Octet)++] = 0; - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Uie_ChangeStatus + 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 + 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. + 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; + Q931ie_ChangeStatus *pie = (Q931ie_ChangeStatus*)OBuf; ie *pIE = &pMsg->ChangeStatus; - L3INT Off = 0; - L3INT Octet = 0; - L3INT IESize; + L3INT Off = 0; + L3INT Octet = 0; + L3INT IESize; - *pIE=0; + *pIE = 0; - pie->IEId = IBuf[Octet]; - Octet ++; + pie->IEId = IBuf[Octet++]; - /* Octet 2*/ - IESize = 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 3 */ + pie->Preference = (IBuf[Octet + Off] >> 6) & 0x01; + pie->Spare = IBuf[Octet + Off] & 0x38; + pie->NewStatus = IBuf[Octet + Off] & 0x07; + Octet++; - Octet++; + Q931SetIE(*pIE, *OOff); - Q931SetIE(*pIE, *OOff); + *IOff = (*IOff) + Octet + Off; + *OOff = (*OOff) + sizeof(Q931ie_ChangeStatus); + pie->Size = sizeof(Q931ie_ChangeStatus); - *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_ChangeStatus); - pie->Size = sizeof(Q931ie_ChangeStatus); - - - return Q931E_NO_ERROR; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pie_ChangeStatus + Function: Q931Pie_ChangeStatus - Parameters: IBuf[IN] Ptr to struct. - OBuf[OUT] Ptr tp packed output buffer. - Octet[IN/OUT] Offset into OBuf. + 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 + 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; + Q931ie_ChangeStatus *pIE = (Q931ie_ChangeStatus*)IBuf; + L3INT rc = Q931E_NO_ERROR; + L3INT Beg = *Octet; + L3INT li; - OBuf[(*Octet)++] = Q931ie_CHANGE_STATUS; - li=(*Octet)++; + OBuf[(*Octet)++] = Q931ie_CHANGE_STATUS; + li = (*Octet)++; - /* Octet 3*/ - OBuf[(*Octet)++] = 0x80 | pIE->NewStatus | ((pIE->Preference & 0x01) << 6); + /* Octet 3 */ + OBuf[(*Octet)++] = 0x80 | pIE->NewStatus | ((pIE->Preference & 0x01) << 6); - OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2; - return rc; + OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; + return rc; } diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 43a5098f62..f77f3837f1 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: Q931mes.c + 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. + 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. + See q931.h for description. License/Copyright: @@ -18,12 +18,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -54,38 +54,35 @@ L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OB 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 */ + 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++] = 1; /* length is 1 octet */ + OBuf[Octet++] = (L3UCHAR) (mes->CRV & 0x7f) | ((mes->CRVFlag << 7) & 0x80); /* CRV & flag */ } - OBuf[Octet++] = mes->MesType; /* message header */ + OBuf[Octet++] = mes->MesType; /* message header */ *IOff = Octet; - return 0; } /***************************************************************************** - Function: Q931Umes_Alerting + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: @@ -93,7 +90,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic case Q931ie_SIGNAL: 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -101,82 +98,84 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Alerting + Function: Q931Pmes_Alerting *****************************************************************************/ L3INT Q931Pmes_Alerting(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 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) + 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_CallProceeding + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -184,103 +183,103 @@ L3INT Q931Umes_CallProceeding(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_G break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_CallProceeding + Function: Q931Pmes_CallProceeding *****************************************************************************/ L3INT Q931Pmes_CallProceeding(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 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_CongestionControl + Function: Q931Umes_CongestionControl *****************************************************************************/ L3INT Q931Umes_CongestionControl(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(mes); - NoWarning(IBuf); + NoWarning(mes); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Pmes_CongestionControl + Function: Q931Pmes_CongestionControl *****************************************************************************/ L3INT Q931Pmes_CongestionControl(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); *OSize = 0; - - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Umes_Connect + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: case Q931ie_PROGRESS_INDICATOR: @@ -291,7 +290,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic case Q931ie_HIGH_LAYER_COMPATIBILITY: case Q931ie_CONNECTED_NUMBER: /* not actually used, seen while testing BRI PTMP TE */ rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); - if(rc != Q931E_NO_ERROR) + if (rc != Q931E_NO_ERROR) return rc; break; @@ -304,89 +303,91 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Connect + Function: Q931Pmes_Connect *****************************************************************************/ L3INT Q931Pmes_Connect(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 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ConnectAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -394,131 +395,61 @@ L3INT Q931Umes_ConnectAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ConnectAck + Function: Q931Pmes_ConnectAck *****************************************************************************/ L3INT Q931Pmes_ConnectAck(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Disconnect + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_CAUSE: case Q931ie_PROGRESS_INDICATOR: case Q931ie_DISPLAY: case Q931ie_SIGNAL: 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; - 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -528,132 +459,203 @@ L3INT Q931Umes_Information(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gene } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Information + 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) { - L3INT rc = Q931E_NO_ERROR; 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)) + /* 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Notify + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Notify + Function: Q931Pmes_Notify *****************************************************************************/ L3INT Q931Pmes_Notify(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Progress + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -661,72 +663,76 @@ L3INT Q931Umes_Progress(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Progress + Function: Q931Pmes_Progress *****************************************************************************/ L3INT Q931Pmes_Progress(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 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) + 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) + 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Release + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_CAUSE: 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -734,61 +740,64 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Release + Function: Q931Pmes_Release *****************************************************************************/ L3INT Q931Pmes_Release(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 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ReleaseComplete + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_CAUSE: 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -796,183 +805,130 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_ break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ReleaseComplete + Function: Q931Pmes_ReleaseComplete *****************************************************************************/ L3INT Q931Pmes_ReleaseComplete(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 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) + 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_Restart + 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; + 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; + 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 + Function: Q931Pmes_Restart *****************************************************************************/ L3INT Q931Pmes_Restart(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 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) + 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) + 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) + 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 + Function: Q931Umes_RestartAck *****************************************************************************/ L3INT Q931Umes_RestartAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *OBuf, L3INT IOff, L3INT Size) { - L3INT OOff=0; - Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; - 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; -} + Q931mes_Generic *mes = (Q931mes_Generic*)OBuf; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; -/***************************************************************************** - - Function: Q931Pmes_RestartAck - -*****************************************************************************/ -L3INT Q931Pmes_RestartAck(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); - - /* 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: + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -980,52 +936,114 @@ L3INT Q931Umes_Resume(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Resume + 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) { - L3INT rc = Q931E_NO_ERROR; 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ResumeAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1035,57 +1053,56 @@ L3INT Q931Umes_ResumeAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ResumeAck + Function: Q931Pmes_ResumeAck *****************************************************************************/ L3INT Q931Pmes_ResumeAck(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 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) + 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) + 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 + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1095,37 +1112,37 @@ L3INT Q931Umes_ResumeReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gen } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ResumeReject + Function: Q931Pmes_ResumeReject *****************************************************************************/ L3INT Q931Pmes_ResumeReject(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 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) + /* 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) + /* 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; } @@ -1141,25 +1158,22 @@ L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT IS L3BOOL RetCode = L3FALSE; *OSize = 0; - return RetCode; } /***************************************************************************** - Function: Q931Umes_Setup + 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; + L3INT ir = 0; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + while (IOff < Size) { + switch (IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: IOff++; break; @@ -1181,12 +1195,12 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + if (ir < 2) { rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else { @@ -1201,13 +1215,12 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m } mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Setup + 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 @@ -1225,105 +1238,308 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m *****************************************************************************/ L3INT Q931Pmes_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 rc = Q931E_NO_ERROR; L3INT Octet = 0; /* Q931 Message Header */ Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet); /* Sending Complete */ - if(Q931IsIEPresent(pMes->SendComplete)) + if (Q931IsIEPresent(pMes->SendComplete)) { OBuf[Octet++] = (L3UCHAR)Q931ie_SENDING_COMPLETE & 0xff; + } /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) + 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) + 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; + } 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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)) + 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) + 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) + 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; @@ -1332,24 +1548,19 @@ L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISiz /***************************************************************************** - Function: Q931Umes_SetupAck + Function: Q931Umes_Suspend *****************************************************************************/ -L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) +L3INT Q931Umes_Suspend(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; - L3INT rc=Q931E_NO_ERROR; + 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: + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1357,234 +1568,50 @@ L3INT Q931Umes_SetupAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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) -{ - L3INT rc = Q931E_NO_ERROR; - Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf; - 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 + Function: Q931Pmes_Suspend *****************************************************************************/ L3INT Q931Pmes_Suspend(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 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_SuspendAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1592,52 +1619,51 @@ L3INT Q931Umes_SuspendAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_SuspendAck + Function: Q931Pmes_SuspendAck *****************************************************************************/ L3INT Q931Pmes_SuspendAck(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 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_SuspendReject + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1645,93 +1671,93 @@ L3INT Q931Umes_SuspendReject(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Ge break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_SuspendReject + Function: Q931Pmes_SuspendReject *****************************************************************************/ L3INT Q931Pmes_SuspendReject(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_UserInformation + Function: Q931Umes_UserInformation *****************************************************************************/ L3INT Q931Umes_UserInformation(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT I, L3INT O) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(mes); - NoWarning(IBuf); + NoWarning(mes); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Pmes_UserInformation + Function: Q931Pmes_UserInformation *****************************************************************************/ L3INT Q931Pmes_UserInformation(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); *OSize = 0; - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q931Umes_Service + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1739,60 +1765,60 @@ L3INT Q931Umes_Service(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Service + Function: Q931Pmes_Service *****************************************************************************/ L3INT Q931Pmes_Service(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 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) + 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) + 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; + return rc; } /***************************************************************************** - Function: Q931Umes_ServiceAck + 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; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; - while(IOff < Size) - { - switch(IBuf[IOff]) - { + 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) + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -1800,34 +1826,35 @@ L3INT Q931Umes_ServiceAck(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener break; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_ServiceAck + Function: Q931Pmes_ServiceAck *****************************************************************************/ L3INT Q931Pmes_ServiceAck(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 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) + 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) + 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; + return rc; } diff --git a/libs/freetdm/src/isdn/Q932mes.c b/libs/freetdm/src/isdn/Q932mes.c index 8e011deb31..574499a241 100644 --- a/libs/freetdm/src/isdn/Q932mes.c +++ b/libs/freetdm/src/isdn/Q932mes.c @@ -13,12 +13,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -39,248 +39,248 @@ /***************************************************************************** - Function: Q932Umes_Facility + Function: Q932Umes_Facility *****************************************************************************/ L3INT Q932Umes_Facility(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Facility + Function: Q931Pmes_Facility *****************************************************************************/ L3INT Q932Pmes_Facility(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_Hold + Function: Q932Umes_Hold *****************************************************************************/ L3INT Q932Umes_Hold(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Hold + Function: Q931Pmes_Hold *****************************************************************************/ L3INT Q932Pmes_Hold(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_HoldAck + Function: Q932Umes_HoldAck *****************************************************************************/ L3INT Q932Umes_HoldAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_HoldAck + Function: Q931Pmes_HoldAck *****************************************************************************/ L3INT Q932Pmes_HoldAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_HoldReject + Function: Q932Umes_HoldReject *****************************************************************************/ L3INT Q932Umes_HoldReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_HoldReject + Function: Q931Pmes_HoldReject *****************************************************************************/ L3INT Q932Pmes_HoldReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_Register + Function: Q932Umes_Register *****************************************************************************/ L3INT Q932Umes_Register(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Register + Function: Q931Pmes_Register *****************************************************************************/ L3INT Q932Pmes_Register(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_Retrieve + Function: Q932Umes_Retrieve *****************************************************************************/ L3INT Q932Umes_Retrieve(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_Retrieve + Function: Q931Pmes_Retrieve *****************************************************************************/ L3INT Q932Pmes_Retrieve(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_RetrieveAck + Function: Q932Umes_RetrieveAck *****************************************************************************/ L3INT Q932Umes_RetrieveAck(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_RetrieveAck + Function: Q931Pmes_RetrieveAck *****************************************************************************/ L3INT Q932Pmes_RetrieveAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } /***************************************************************************** - Function: Q932Umes_RetrieveReject + Function: Q932Umes_RetrieveReject *****************************************************************************/ L3INT Q932Umes_RetrieveReject(Q931_TrunkInfo_t *pTrunk,L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT Size) { - L3INT OOff=0; + L3INT OOff = 0; /* TODO */ - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: Q931Pmes_RetrieveReject + Function: Q931Pmes_RetrieveReject *****************************************************************************/ L3INT Q932Pmes_RetrieveReject(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3BOOL RetCode = L3FALSE; + L3BOOL RetCode = L3FALSE; - NoWarning(OBuf); - NoWarning(IBuf); + NoWarning(OBuf); + NoWarning(IBuf); - return RetCode; + return RetCode; } diff --git a/libs/freetdm/src/isdn/include/DMS.h b/libs/freetdm/src/isdn/include/DMS.h index 35d10d7b5b..605a61aa6e 100644 --- a/libs/freetdm/src/isdn/include/DMS.h +++ b/libs/freetdm/src/isdn/include/DMS.h @@ -4,18 +4,17 @@ Contents: Header and definition for the National ISDN dialect. The header contents the following parts: - - - Definition of codes + - Definition of codes - Definition of information elements (nationalie_). - Definition of messages (nationalmes_). - - Function prototypes. + - 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 + 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: @@ -77,8 +76,6 @@ L3INT DMSPmes_0x07(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, 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 @@ -88,7 +85,6 @@ L3INT DMSPmes_0x0f(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, 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); diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 2687930485..8673b71fe8 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -157,7 +157,6 @@ *****************************************************************************/ typedef enum { - Q931E_NO_ERROR = 0, Q931E_UNKNOWN_MESSAGE = -3001, @@ -190,7 +189,6 @@ typedef enum { 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 */ @@ -563,61 +561,61 @@ typedef struct *****************************************************************************/ 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 */ + 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 */ - ie Shift; - ie MoreData; - ie SendComplete; - ie CongestionLevel; - ie RepeatInd; + 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; + 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 */ + L3UCHAR buf[1]; /* Buffer for IE's */ -}Q931mes_Generic; +} Q931mes_Generic; /***************************************************************************** @@ -723,19 +721,19 @@ struct Q931_Call struct Q931_TrunkInfo { - Q931NetUser_t NetUser; /* Network/User Mode. */ + Q931NetUser_t NetUser; /* Network/User Mode. */ Q931_TrunkType_t TrunkType; /* Trunk Line Type. */ - Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ + Q931Dialect_t Dialect; /* Q.931 Based dialect index. */ - Q931Tx34CB_t Q931Tx34CBProc; - Q931Tx32CB_t Q931Tx32CBProc; - Q931ErrorCB_t Q931ErrorCBProc; - Q931LogCB_t Q931LogCBProc; + Q931Tx34CB_t Q931Tx34CBProc; + Q931Tx32CB_t Q931Tx32CBProc; + Q931ErrorCB_t Q931ErrorCBProc; + Q931LogCB_t Q931LogCBProc; void *PrivateData32; void *PrivateData34; void *PrivateDataLog; - Q931LogLevel_t loglevel; + Q931LogLevel_t loglevel; L3UCHAR Enabled; /* Enabled/Disabled */ /* 0 = Disabled */ @@ -779,7 +777,7 @@ struct Q931_TrunkInfo L3INT CRV; /* Associated CRV */ - }ch[Q931MAXCHPERTRUNK]; + } ch[Q931MAXCHPERTRUNK]; /* Active Call information indentified by CRV. See Q931AllocateCRV for */ /* initialization of call table. */ @@ -802,7 +800,7 @@ typedef struct L3INT State; L3INT Message; L3UCHAR Direction; -}Q931State; +} Q931State; /***************************************************************************** @@ -844,7 +842,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; size of 'header'. *****************************************************************************/ -#define Q931GetIETotSize(ie) (((ie.InfoID & 0x80) !=0) ? 1:ie.LenIE)+2) +#define Q931GetIETotSize(ie) (((ie.InfoID & 0x80) != 0) ? 1 : ie.LenIE) + 2) /***************************************************************************** @@ -855,7 +853,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; Description: Return TRUE if the Information Element is included. *****************************************************************************/ -#define Q931IsIEPresent(x) ((x & 0x8000) != 0) +#define Q931IsIEPresent(x) ((x & 0x8000) != 0) /***************************************************************************** @@ -872,7 +870,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; *****************************************************************************/ #define Q931GetIEOffset(x) (x & 0x7fff) -#define Q931GetIEValue(x) (x & 0x7fff) +#define Q931GetIEValue(x) (x & 0x7fff) /***************************************************************************** @@ -894,7 +892,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; Description: Set an information element. *****************************************************************************/ -#define Q931SetIE(x,o) {x = (ie)(o) | 0x8000;} +#define Q931SetIE(x,o) { x = (ie)(o) | 0x8000; } /***************************************************************************** @@ -906,7 +904,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; that the octet is extended. *****************************************************************************/ -#define IsQ931Ext(x) ((x&0x80)==0) +#define IsQ931Ext(x) ((x & 0x80) == 0) /***************************************************************************** @@ -933,7 +931,7 @@ extern q931timer_t Q931Timer[Q931MAXDLCT][Q931MAXTIMER]; warning for the initial empty functions. *****************************************************************************/ -#define NoWarning(x) (x=x) +#define NoWarning(x) (x = x) /***************************************************************************** diff --git a/libs/freetdm/src/isdn/include/Q931ie.h b/libs/freetdm/src/isdn/include/Q931ie.h index 2acb937702..65dba4e261 100644 --- a/libs/freetdm/src/isdn/include/Q931ie.h +++ b/libs/freetdm/src/isdn/include/Q931ie.h @@ -54,7 +54,7 @@ typedef enum { } q931_codeset_t; -/* Single octet information elements */ +/* Single octet information elements */ #define Q931ie_SHIFT 0x90 /* 1001 ---- */ #define Q931ie_MORE_DATA 0xa0 /* 1010 ---- */ #define Q931ie_SENDING_COMPLETE 0xa1 /* 1010 0001 */ @@ -98,12 +98,11 @@ typedef enum { #define Q931ie_ESCAPE_FOR_EX 0x7f /* 0111 1111 */ /* Variable Length Codeset 6 Information Elements */ - -#define Q931ie_GENERIC_DIGITS 0x37 /* 0011 0111 */ +#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 */ +#define Q931ie_CONNECTED_NUMBER 0x4c /* 0100 1101 */ +#define Q931ie_FACILITY 0x1c /* 0001 1101 */ /***************************************************************************** @@ -114,10 +113,9 @@ typedef enum { *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00000100 for Bearer Capability */ - L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding Standard. */ @@ -286,7 +284,8 @@ typedef struct L3UCHAR AL3Info1; /* additional layer 3 info 1 */ L3UCHAR AL3Info2; /* additional layer 3 info 2 */ -}Q931ie_BearerCap; + +} Q931ie_BearerCap; /***************************************************************************** @@ -295,12 +294,13 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00010000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CallId[1]; /* Call identity */ -}Q931ie_CallID; + +} Q931ie_CallID; /***************************************************************************** @@ -309,13 +309,14 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00010100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding Standard */ L3UCHAR CallState; /* Call State Value */ -}Q931ie_CallState; + +} Q931ie_CallState; /***************************************************************************** @@ -324,8 +325,8 @@ typedef struct Description: Cause IE as described in Q.850 *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00010100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding Standard */ @@ -333,21 +334,23 @@ typedef struct L3UCHAR Recom; /* Recommendation */ L3UCHAR Value; /* Cause Value */ L3UCHAR Diag[1]; /* Optional Diagnostics Field */ -}Q931ie_Cause; + +} Q931ie_Cause; /***************************************************************************** Struct: Q931ie_CalledNum *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_CalledNum; /***************************************************************************** @@ -357,14 +360,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_CalledSub; /***************************************************************************** @@ -374,8 +378,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01101100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR TypNum; /* Type of number */ @@ -383,7 +387,8 @@ typedef struct L3UCHAR PresInd; /* Presentation indicator */ L3UCHAR ScreenInd; /* Screening indicator */ L3UCHAR Digit[1]; /* Number digits (IA5) */ -}Q931ie_CallingNum; + +} Q931ie_CallingNum; /***************************************************************************** @@ -393,14 +398,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_CallingSub; /***************************************************************************** @@ -418,8 +424,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00011000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR IntIDPresent; /* Int. id. present */ @@ -460,7 +466,8 @@ typedef struct /* 1001 : H12 channel units */ L3UCHAR ChanSlot; /* Channel number */ -}Q931ie_ChanID; + +} Q931ie_ChanID; /***************************************************************************** @@ -470,8 +477,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00101001 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Year; /* Year */ @@ -485,7 +492,7 @@ typedef struct /* 1 : Hour present */ /* 2 : Hour and Minute present */ /* 3 : Hour, Minute and Second present */ -}Q931ie_DateTime; +} Q931ie_DateTime; /***************************************************************************** @@ -495,12 +502,13 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00101000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Display[1]; /* Display information (IA5) */ -}Q931ie_Display; + +} Q931ie_Display; /***************************************************************************** @@ -510,8 +518,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01111101 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding standard */ @@ -520,7 +528,8 @@ typedef struct L3UCHAR HLCharID; /* High layer characteristics id. */ L3UCHAR EHLCharID; /* Extended high layer character. id. */ L3UCHAR EVideoTlfCharID; /* Ext. videotelephony char. id. */ -}Q931ie_HLComp; + +} Q931ie_HLComp; /***************************************************************************** @@ -530,12 +539,12 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { L3UCHAR IEId; /* 00101100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR KeypadFac[1]; /* dynamic buffer */ -}Q931ie_KeypadFac; + +} Q931ie_KeypadFac; /***************************************************************************** @@ -545,8 +554,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01111100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding standard */ @@ -750,7 +759,8 @@ typedef struct L3UCHAR PackWinSize; /* Packet window size */ L3UCHAR AddL3Info; /* Additional Layer 3 protocol info */ -}Q931ie_LLComp; + +} Q931ie_LLComp; /***************************************************************************** @@ -760,8 +770,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00100000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR LenNetID; /* Length of network facilities id. */ @@ -769,7 +779,8 @@ typedef struct L3UCHAR NetIDPlan; /* Network identification plan. */ L3UCHAR NetFac; /* Network specific facility spec. */ L3UCHAR NetID[1]; /* Network id. (IA5) */ -}Q931ie_NetFac; + +} Q931ie_NetFac; /***************************************************************************** @@ -779,12 +790,13 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00100000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Notification; /* Notification descriptor */ -}Q931ie_NotifInd; + +} Q931ie_NotifInd; /***************************************************************************** @@ -794,14 +806,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00011110 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CodStand; /* Coding standard */ L3UCHAR Location; /* Location */ L3UCHAR ProgDesc; /* Progress description */ -}Q931ie_ProgInd; + +} Q931ie_ProgInd; /***************************************************************************** @@ -811,20 +824,23 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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 -{ +} Q931ie_Segment; + + +typedef struct { + L3UCHAR IEId; /* 00000000 */ L3UCHAR Size; /* Length of Information Element */ -}Q931ie_SendComplete; + +} Q931ie_SendComplete; /***************************************************************************** @@ -834,8 +850,8 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00000000 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Signal; /* Signal value */ @@ -859,7 +875,7 @@ typedef struct /* 01000110 Alerting on - pattern 6 */ /* 01000111 Alerting on - pattern 7 */ /* 01001111 Alerting off */ -}Q931ie_Signal; +} Q931ie_Signal; /***************************************************************************** @@ -869,12 +885,13 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 00000000 */ L3UCHAR Size; /* Length of Information Element */ L3ULONG TxDSIValue; /* Trans. delay sel. & ind. value */ -}Q931ie_TransDelSelInd; + +} Q931ie_TransDelSelInd; #endif /***************************************************************************** @@ -885,14 +902,15 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; + +} Q931ie_TransNetSel; /***************************************************************************** @@ -902,13 +920,14 @@ typedef struct *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01111110 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR ProtDisc; /* Protocol discriminator */ L3UCHAR User[1]; /* User information */ -}Q931ie_UserUser; + +} Q931ie_UserUser; /***************************************************************************** @@ -918,13 +937,14 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000111 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CUGInd; /* CUG indication */ L3UCHAR CUG[1]; /* CUG index code (IA5) */ -}Q931ie_ClosedUserGrp; + +} Q931ie_ClosedUserGrp; #endif /***************************************************************************** @@ -934,12 +954,13 @@ typedef struct Description: Congestion Level *****************************************************************************/ -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000111 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR CongLevel; /* Conguestion Level */ -}Q931ie_CongLevel; + +} Q931ie_CongLevel; /***************************************************************************** @@ -949,14 +970,15 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +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; + +} Q931ie_EndEndTxDelay; #endif /***************************************************************************** @@ -967,15 +989,16 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +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; + +} Q931ie_InfoRate; #endif /***************************************************************************** @@ -986,15 +1009,16 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +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; + +} Q931ie_PackParam; #endif /***************************************************************************** @@ -1005,13 +1029,14 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000101 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR ForwardValue; /* Forward value */ L3UCHAR BackwardValue; /* Backward value */ -}Q931ie_PackWinSize; + +} Q931ie_PackWinSize; #endif /***************************************************************************** @@ -1022,13 +1047,14 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01000110 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR ForwardValue; /* Forward value */ L3UCHAR BackwardValue; /* Backward value */ -}Q931ie_PackSize; + +} Q931ie_PackSize; #endif /***************************************************************************** @@ -1039,8 +1065,8 @@ typedef struct *****************************************************************************/ #ifdef Q931_X25_SUPPORT -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR TypeNum; /* Type of number */ @@ -1049,19 +1075,20 @@ typedef struct L3UCHAR ScreenInd; /* Screening indicator */ L3UCHAR Reason; /* Reason for redirection */ L3UCHAR Digit[1]; /* Number digits (IA5) */ -}Q931ie_RedirNum; + +} Q931ie_RedirNum; #endif -typedef struct -{ +typedef struct { + L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR RepeatInd; /* 0010 Prioritized list for selecting */ /* one possible. */ -}Q931ie_RepeatInd; +} Q931ie_RepeatInd; + +typedef struct { -typedef struct -{ L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Spare; /* Spare */ @@ -1069,10 +1096,10 @@ typedef struct /* 000 Indicate channels */ /* 110 Single interface */ /* 111 All interfaces */ -}Q931ie_RestartInd; +} Q931ie_RestartInd; + +typedef struct { -typedef struct -{ L3UCHAR IEId; /* 01110100 */ L3UCHAR Size; /* Length of Information Element */ L3UCHAR Preference; /* Preference 0 = reserved, 1 = channel */ @@ -1081,7 +1108,7 @@ typedef struct /* 000 In service */ /* 001 Maintenance */ /* 010 Out of service */ -}Q931ie_ChangeStatus; +} Q931ie_ChangeStatus; /***************************************************************************** @@ -1090,13 +1117,14 @@ typedef struct *****************************************************************************/ -typedef struct -{ +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; diff --git a/libs/freetdm/src/isdn/include/Q932.h b/libs/freetdm/src/isdn/include/Q932.h index 34ba9ffa4b..9b69a34a02 100644 --- a/libs/freetdm/src/isdn/include/Q932.h +++ b/libs/freetdm/src/isdn/include/Q932.h @@ -53,7 +53,7 @@ /***************************************************************************** Q.932 Additional EI Codes *****************************************************************************/ -#define Q932ie_FACILITY 0x1c /* 0001 1100 */ +#define Q932ie_FACILITY 0x1c /* 0001 1100 */ /***************************************************************************** Function Prototypes. diff --git a/libs/freetdm/src/isdn/include/mfifo.h b/libs/freetdm/src/isdn/include/mfifo.h index 477362466b..4c1d850d81 100644 --- a/libs/freetdm/src/isdn/include/mfifo.h +++ b/libs/freetdm/src/isdn/include/mfifo.h @@ -44,11 +44,10 @@ Description: Message Index used to index a dynamic size Message FIFO. *****************************************************************************/ -typedef struct _mindex -{ +typedef struct _mindex { int offset; /* offset to message in buf */ int size; /* size of message in bytes */ -}MINDEX; +} MINDEX; /***************************************************************************** @@ -58,8 +57,7 @@ typedef struct _mindex queue. *****************************************************************************/ -typedef struct -{ +typedef struct { int first; /* first out */ int last; /* last in + 1 */ int bsize; /* buffer size */ diff --git a/libs/freetdm/src/isdn/include/national.h b/libs/freetdm/src/isdn/include/national.h index c47daf4ed9..cff26aa4a4 100644 --- a/libs/freetdm/src/isdn/include/national.h +++ b/libs/freetdm/src/isdn/include/national.h @@ -3,19 +3,18 @@ FileName: national.h Contents: Header and definition for the National ISDN dialect. The - header contents the following parts: - - - Definition of codes + header contents the following parts: + - Definition of codes - Definition of information elements (nationalie_). - Definition of messages (nationalmes_). - - Function prototypes. + - Function prototypes. - Description: The National ISDN dialect here covers ???? + 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 + 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: @@ -75,15 +74,12 @@ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT #include "DMS.h" - /***************************************************************************** Q.931 Process Function Prototyping. Implemented in nationalStateTE.c *****************************************************************************/ - - void nationalCreateTE(L3UCHAR i); void nationalCreateNT(L3UCHAR i); diff --git a/libs/freetdm/src/isdn/mfifo.c b/libs/freetdm/src/isdn/mfifo.c index 64dbcedfcc..28528f9b64 100644 --- a/libs/freetdm/src/isdn/mfifo.c +++ b/libs/freetdm/src/isdn/mfifo.c @@ -1,38 +1,38 @@ /***************************************************************************** - Filename: mfifo.c + Filename: mfifo.c Description: mfifo is a message orriented fifo system with support of - both message and byte per byte retriaval of messages. + both message and byte per byte retriaval of messages. - The fifo has been designed with two usages in mind: + 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. + - 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. + - 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. + 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. + 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. + * 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. + 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. + This is required to allow direct ptr access to messages + stored in the queue. License/Copyright: @@ -43,12 +43,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -71,40 +71,40 @@ /***************************************************************************** - Function: MFIFOCreate + 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). + 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)]; + 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; + if (mf->buf > &buf[size]) + return 0; - mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index); + mf->bsize = size - sizeof(MFIFO) - (sizeof(MINDEX) * index); - return 1; + return 1; } /***************************************************************************** - Function: MFIFOClear + Function: MFIFOClear Description: Clear the FIFO - Paremeters: buf ptr to fifo + Paremeters: buf ptr to fifo Return Value: none @@ -118,91 +118,91 @@ void MFIFOClear(unsigned char * buf) /***************************************************************************** - Function: MFIFOGetLBOffset + Function: MFIFOGetLBOffset Description: Helper function caclulating offset to the 'first out' byte. - Paremeters: buf ptr to fifo + Paremeters: buf ptr to fifo Return Value: offset. *****************************************************************************/ int MFIFOGetLBOffset(unsigned char *buf) { - MFIFO *mf = (MFIFO *)buf; + MFIFO *mf = (MFIFO *)buf; - if(mf->last != mf->first) - return mf->ix[mf->last].offset; - - return 0; + if (mf->last != mf->first) + return mf->ix[mf->last].offset; + + return 0; } /***************************************************************************** - Function: MFIFOGetFBOffset + 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. + byte in the buffer. This is the position the next byte + entering the fifo will occupy. - Paremeters: buf ptr to fifo + Paremeters: buf ptr to fifo Return Value: offset *****************************************************************************/ int MFIFOGetFBOffset(unsigned char *buf) { - MFIFO *mf = (MFIFO *)buf; - int x; + MFIFO *mf = (MFIFO *)buf; + int x; - if(mf->last == mf->first) - return 0; + if (mf->last == mf->first) + return 0; - x = mf->first - 1; + x = mf->first - 1; - if(x < 0) - x = mf->ixsize - 1; + if (x < 0) + x = mf->ixsize - 1; - return mf->ix[x].offset + mf->ix[x].size; + return mf->ix[x].offset + mf->ix[x].size; } /***************************************************************************** - Function: MFIFOWriteIX + 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. + 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 + 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; + MFIFO *mf = (MFIFO *)buf; + int x; - memcpy(&mf->buf[off], mes, size); - mf->ix[ix].offset = off; - mf->ix[ix].size = size; + memcpy(&mf->buf[off], mes, size); + mf->ix[ix].offset = off; + mf->ix[ix].size = size; - x = mf->first + 1; + x = mf->first + 1; - if(x >= mf->ixsize) - x = 0; + if (x >= mf->ixsize) + x = 0; - mf->first = x; + mf->first = x; } /***************************************************************************** - Function: MFIFOWriteMes + Function: MFIFOWriteMes Description: @@ -213,51 +213,46 @@ void MFIFOWriteIX(unsigned char *buf, unsigned char *mes, int size, int ix, int *****************************************************************************/ int MFIFOWriteMes(unsigned char *buf, unsigned char *mes, int size) { - MFIFO *mf = (MFIFO *)buf; - int of, ol, x; + MFIFO *mf = (MFIFO *)buf; + int of, ol, x; - x = mf->first + 1; + x = mf->first + 1; - if(x >= mf->ixsize) - x = 0; + if (x >= mf->ixsize) + x = 0; - if(x == mf->last) - return 0; /* full queue */ + 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 */ + 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; - } + 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; + return 0; } /***************************************************************************** - Function: MFIFOGetMesPtr + Function: MFIFOGetMesPtr Description: @@ -270,7 +265,7 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) { MFIFO *mf = (MFIFO *)buf; - if(mf->first == mf->last) { + if (mf->first == mf->last) { return NULL; } @@ -280,7 +275,7 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) /***************************************************************************** - Function: MFIFOKillNext + Function: MFIFOKillNext Description: @@ -291,18 +286,17 @@ unsigned char * MFIFOGetMesPtr(unsigned char *buf, int *size) *****************************************************************************/ void MFIFOKillNext(unsigned char *buf) { - MFIFO *mf = (MFIFO *)buf; - int x; + MFIFO *mf = (MFIFO *)buf; + int x; - if(mf->first != mf->last) - { - x = mf->last + 1; - if(x >= mf->ixsize) { - x = 0; + if (mf->first != mf->last) { + x = mf->last + 1; + if (x >= mf->ixsize) { + x = 0; + } + + mf->last = x; } - - mf->last = x; - } } @@ -319,16 +313,16 @@ unsigned char * MFIFOGetMesPtrOffset(unsigned char *buf, int *size, const int po MFIFO *mf = (MFIFO *)buf; int x; - if(mf->first == mf->last) { + if (mf->first == mf->last) { return NULL; } - if(pos < 0 || pos >= mf->ixsize) { + if (pos < 0 || pos >= mf->ixsize) { return NULL; } x = pos - mf->last; - if(x < 0) { + if (x < 0) { x += (mf->ixsize - 1); } @@ -345,10 +339,10 @@ int MFIFOGetMesCount(unsigned char *buf) { MFIFO *mf = (MFIFO *)buf; - if(mf->first == mf->last) { + if (mf->first == mf->last) { return 0; } - else if(mf->first > mf->last) { + else if (mf->first > mf->last) { return mf->first - mf->last; } else { @@ -367,42 +361,37 @@ int MFIFOWriteMesOverwrite(unsigned char *buf, unsigned char *mes, int size) x = mf->first + 1; - if(x >= mf->ixsize) + if (x >= mf->ixsize) x = 0; - if(x == mf->last) { + if (x == mf->last) { /* advance last pointer */ mf->last++; - if(mf->last >= mf->ixsize) + if (mf->last >= mf->ixsize) mf->last = 0; } of = MFIFOGetFBOffset(buf); ol = MFIFOGetLBOffset(buf); - if(mf->last == mf->first) /* empty queue */ - { + 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) - { + else if (of > ol) { + if (mf->bsize - of >= size) { MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } - else if(ol > size) - { + else if (ol > size) { MFIFOWriteIX(buf, mes, size, mf->first, ol); return 1; } } - else if(ol - of > size) - { + else if (ol - of > size) { MFIFOWriteIX(buf, mes, size, mf->first, of); return 1; } diff --git a/libs/freetdm/src/isdn/nationalStateNT.c b/libs/freetdm/src/isdn/nationalStateNT.c index 29f766e073..48d649f2df 100644 --- a/libs/freetdm/src/isdn/nationalStateNT.c +++ b/libs/freetdm/src/isdn/nationalStateNT.c @@ -4,11 +4,11 @@ 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. + 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: @@ -22,12 +22,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -57,66 +57,66 @@ *****************************************************************************/ 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(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); + 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_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 */ diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index 99dcec3b9a..a50ae3debd 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -4,18 +4,18 @@ 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. + 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. + 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: @@ -29,12 +29,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -65,152 +65,152 @@ extern L3INT Q931L4HeaderSpace; *****************************************************************************/ 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(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); + 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_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.*/ + /* 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); + 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); + 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); + 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); + 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); + 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); + 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); + Q931AddStateEntry(i, Q931_U7, Q931mes_CONNECT, 2); /* State 8 Connect request */ - Q931AddStateEntry(i,Q931_U8, Q931mes_CONNECT_ACKNOWLEDGE, 4); + 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); + 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); + 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); + 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); + 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); + 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, + Q931AddStateEntry(i, Q931_U17, + Q931AddStateEntry(i, Q931_U19, + Q931AddStateEntry(i, Q931_U25, */ } - diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 90f7a1b1a3..5ef69014b5 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -1,13 +1,13 @@ /***************************************************************************** - FileName: nationalmes.c + 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. + 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. + See national.h for description. License/Copyright: @@ -21,12 +21,12 @@ modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, + * 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, + * 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 + * 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. @@ -48,19 +48,18 @@ /***************************************************************************** - Function: nationalUmes_Setup + 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; + L3INT ir = 0; + L3INT OOff = 0; + L3INT rc = Q931E_NO_ERROR; L3UCHAR last_codeset = 0, codeset = 0; L3UCHAR shift_lock = 1; - while(IOff < Size) - { + while (IOff < Size) { if (!shift_lock) { codeset = last_codeset; } @@ -75,8 +74,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi } if (codeset == 0) { - switch(IBuf[IOff]) - { + switch (IBuf[IOff]) { case Q931ie_SENDING_COMPLETE: case Q931ie_BEARER_CAPABILITY: case Q931ie_CHANNEL_IDENTIFICATION: @@ -94,11 +92,11 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: - if(ir < 2) { + if (ir < 2) { rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff); ir++; } else { @@ -110,11 +108,10 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi break; } } else if (codeset == 6) { - switch(IBuf[IOff]) - { + 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) + if (rc != Q931E_NO_ERROR) return rc; break; default: @@ -126,13 +123,13 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi return Q931E_ILLEGAL_IE; } } - mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; - return Q931E_NO_ERROR; + mes->Size = sizeof(Q931mes_Generic) - 1 + OOff; + return Q931E_NO_ERROR; } /***************************************************************************** - Function: nationalPmes_Setup + 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 @@ -150,109 +147,121 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi *****************************************************************************/ L3INT nationalPmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize) { - L3INT rc = Q931E_NO_ERROR; + 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)) + + /* Sending Complete */ + if (Q931IsIEPresent(pMes->SendComplete)) { OBuf[Octet++] = (L3UCHAR)(pMes->SendComplete & 0x00ff); + } /* Repeat Indicator */ - if(Q931IsIEPresent(pMes->RepeatInd)) + 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) + 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; + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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)) + 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) + 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) + 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; + return rc; } - - From c62692e85d719db1b7b215f0907fef7ddce0c34a Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:14:07 +0000 Subject: [PATCH 1033/1766] [ozmod_isdn] Remove sending complete IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@536 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 5e86199d89..250dc4cae6 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -72,7 +72,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ - Q931ie_SendComplete SComplete; /* Sending Complete IE */ Q931ie_ProgInd Progress; /* Progress Indicator IE */ zap_status_t status = ZAP_FAIL; zap_isdn_data_t *isdn_data = span->signal_data; @@ -177,12 +176,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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); - /* - * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) - */ - SComplete.IEId = Q931ie_SENDING_COMPLETE; -// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); - caller_data->call_state = ZAP_CALLER_STATE_DIALING; Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); @@ -769,7 +762,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ - Q931ie_SendComplete SComplete; /* Sending Complete IE */ Q931ie_ProgInd Progress; /* Progress Indicator IE */ int codec = 0; @@ -864,12 +856,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); - /* - * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) - */ - SComplete.IEId = Q931ie_SENDING_COMPLETE; -// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); - Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); isdn_data->channels_local_crv[gen->CRV] = zchan; } From 00215f734949ecb3ddb11c30fc93bdc410ae1166 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:14:07 +0000 Subject: [PATCH 1034/1766] [ozmod_isdn] Remove sending complete IE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@536 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 5e86199d89..250dc4cae6 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -72,7 +72,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ - Q931ie_SendComplete SComplete; /* Sending Complete IE */ Q931ie_ProgInd Progress; /* Progress Indicator IE */ zap_status_t status = ZAP_FAIL; zap_isdn_data_t *isdn_data = span->signal_data; @@ -177,12 +176,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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); - /* - * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) - */ - SComplete.IEId = Q931ie_SENDING_COMPLETE; -// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); - caller_data->call_state = ZAP_CALLER_STATE_DIALING; Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); @@ -769,7 +762,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931ie_CalledNum *ptrCalledNum; Q931ie_Display Display, *ptrDisplay; Q931ie_HLComp HLComp; /* High-Layer Compatibility IE */ - Q931ie_SendComplete SComplete; /* Sending Complete IE */ Q931ie_ProgInd Progress; /* Progress Indicator IE */ int codec = 0; @@ -864,12 +856,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); - /* - * Sending complete IE (or some NT stuff waits forever in Q.931 overlap dial state...) - */ - SComplete.IEId = Q931ie_SENDING_COMPLETE; -// gen->SendComplete = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &SComplete); - Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); isdn_data->channels_local_crv[gen->CRV] = zchan; } From 416f8e58b2c3ee430736d8f1d23b3a6081b1dab5 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:23:26 +0000 Subject: [PATCH 1035/1766] [Q.931] Codingstyle cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@537 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 43 ++++++++++++---------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 8673b71fe8..110682d4d3 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -542,14 +542,14 @@ enum { 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; +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; /***************************************************************************** @@ -633,8 +633,7 @@ typedef struct *****************************************************************************/ typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; -typedef enum -{ +typedef enum { Q931_LOG_NONE = 0, Q931_LOG_ERROR, Q931_LOG_WARNING, @@ -648,14 +647,12 @@ 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. */ -{ +typedef enum { /* Network/User Mode. */ Q931_TE=0, /* 0 : User Mode */ Q931_NT=1 /* 1 : Network Mode */ } Q931NetUser_t; -typedef enum /* Dialect enum */ -{ +typedef enum { /* Dialect enum */ Q931_Dialect_Q931 = 0, Q931_Dialect_National = 2, Q931_Dialect_DMS = 4, @@ -666,8 +663,7 @@ typedef enum /* Dialect enum */ #define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", "" Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t) -typedef enum /* Trunk Line Type. */ -{ +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 */ @@ -675,18 +671,17 @@ typedef enum /* Trunk Line Type. */ 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 */ +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_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 From 66eace59c4d3f9bee0f8a13f8d1a7a6420950693 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:23:26 +0000 Subject: [PATCH 1036/1766] [Q.931] Codingstyle cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@537 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 43 ++++++++++++---------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 8673b71fe8..110682d4d3 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -542,14 +542,14 @@ enum { 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; +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; /***************************************************************************** @@ -633,8 +633,7 @@ typedef struct *****************************************************************************/ typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; -typedef enum -{ +typedef enum { Q931_LOG_NONE = 0, Q931_LOG_ERROR, Q931_LOG_WARNING, @@ -648,14 +647,12 @@ 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. */ -{ +typedef enum { /* Network/User Mode. */ Q931_TE=0, /* 0 : User Mode */ Q931_NT=1 /* 1 : Network Mode */ } Q931NetUser_t; -typedef enum /* Dialect enum */ -{ +typedef enum { /* Dialect enum */ Q931_Dialect_Q931 = 0, Q931_Dialect_National = 2, Q931_Dialect_DMS = 4, @@ -666,8 +663,7 @@ typedef enum /* Dialect enum */ #define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", "" Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t) -typedef enum /* Trunk Line Type. */ -{ +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 */ @@ -675,18 +671,17 @@ typedef enum /* Trunk Line Type. */ 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 */ +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_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 From 8e25e1ef36f5a8275b2ed896c36731550c75f943 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:28:50 +0000 Subject: [PATCH 1037/1766] [Q.931] Save TEI from incoming SETUP message in call struct + make the TEI available in all incoming messages git-svn-id: http://svn.openzap.org/svn/openzap/trunk@538 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 5 ++++- libs/openzap/src/isdn/Q931StateNT.c | 3 +++ libs/openzap/src/isdn/include/Q931.h | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index 9b9b6331bd..b29bcf97dd 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -368,6 +368,9 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, /* 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 @@ -382,7 +385,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, } } - 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, tei, Size, + 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); diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 5b8b0860b4..71f2e6e836 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -345,6 +345,9 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) 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) { diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 110682d4d3..e05c7e9dce 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -559,11 +559,11 @@ typedef struct { provided in case a proprietary variant needs it. *****************************************************************************/ -typedef struct -{ +typedef struct { L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ + L3UCHAR Tei; /* TEI */ L3UCHAR CRVFlag; /* Call reference value flag */ L3INT CRV; /* Call reference value */ From 82318fc434793ca0fd31cfc186e6cabe8b0a89bd Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:28:50 +0000 Subject: [PATCH 1038/1766] [Q.931] Save TEI from incoming SETUP message in call struct + make the TEI available in all incoming messages git-svn-id: http://svn.openzap.org/svn/openzap/trunk@538 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 5 ++++- libs/freetdm/src/isdn/Q931StateNT.c | 3 +++ libs/freetdm/src/isdn/include/Q931.h | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index 9b9b6331bd..b29bcf97dd 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -368,6 +368,9 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, /* 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 @@ -382,7 +385,7 @@ L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR tei, L3UCHAR * buf, } } - 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, tei, Size, + 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); diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 5b8b0860b4..71f2e6e836 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -345,6 +345,9 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) 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) { diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 110682d4d3..e05c7e9dce 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -559,11 +559,11 @@ typedef struct { provided in case a proprietary variant needs it. *****************************************************************************/ -typedef struct -{ +typedef struct { L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ + L3UCHAR Tei; /* TEI */ L3UCHAR CRVFlag; /* Call reference value flag */ L3INT CRV; /* Call reference value */ From 048d021f4030210d2b7174d79bbc05921f4c6770 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:41:50 +0000 Subject: [PATCH 1039/1766] Change zap_buffer_read_loop() to always try to read the full amount of bytes we wanted to get; add zap_buffer_seek() to skip n bytes from the beginning of the buffer (zap_buffer_toss works relative to the current position only) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@539 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_buffer.h | 7 +++++++ libs/openzap/src/zap_buffer.c | 27 ++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/include/zap_buffer.h b/libs/openzap/src/include/zap_buffer.h index eaa71524f9..958d2fc8e7 100644 --- a/libs/openzap/src/include/zap_buffer.h +++ b/libs/openzap/src/include/zap_buffer.h @@ -122,6 +122,13 @@ void zap_buffer_zero(zap_buffer_t *buffer); */ 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 + */ +zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); + /** @} */ zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen); diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index d5d7f1ef7d..1051f716cc 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -108,6 +108,27 @@ zap_size_t zap_buffer_inuse(zap_buffer_t *buffer) return buffer->used; } +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; +} + zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) { zap_size_t reading = 0; @@ -137,13 +158,13 @@ void zap_buffer_set_loops(zap_buffer_t *buffer, int loops) 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)) == 0) { + if ((len = zap_buffer_read(buffer, data, datalen)) < datalen) { if (buffer->loops == 0) { - return 0; + return len; } buffer->head = buffer->data; buffer->used = buffer->actually_used; - len = zap_buffer_read(buffer, data, datalen); + len = zap_buffer_read(buffer, data + len, datalen - len); buffer->loops--; } return len; From 081cc2e75b93cebc3073e5ed94c52dca091243db Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sat, 6 Sep 2008 20:41:50 +0000 Subject: [PATCH 1040/1766] Change zap_buffer_read_loop() to always try to read the full amount of bytes we wanted to get; add zap_buffer_seek() to skip n bytes from the beginning of the buffer (zap_buffer_toss works relative to the current position only) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@539 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_buffer.h | 7 +++++++ libs/freetdm/src/zap_buffer.c | 27 ++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h index eaa71524f9..958d2fc8e7 100644 --- a/libs/freetdm/src/include/zap_buffer.h +++ b/libs/freetdm/src/include/zap_buffer.h @@ -122,6 +122,13 @@ void zap_buffer_zero(zap_buffer_t *buffer); */ 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 + */ +zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); + /** @} */ zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen); diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index d5d7f1ef7d..1051f716cc 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -108,6 +108,27 @@ zap_size_t zap_buffer_inuse(zap_buffer_t *buffer) return buffer->used; } +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; +} + zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) { zap_size_t reading = 0; @@ -137,13 +158,13 @@ void zap_buffer_set_loops(zap_buffer_t *buffer, int loops) 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)) == 0) { + if ((len = zap_buffer_read(buffer, data, datalen)) < datalen) { if (buffer->loops == 0) { - return 0; + return len; } buffer->head = buffer->data; buffer->used = buffer->actually_used; - len = zap_buffer_read(buffer, data, datalen); + len = zap_buffer_read(buffer, data + len, datalen - len); buffer->loops--; } return len; From 1244c453788b23cd732281eebc6f036cd41f51f8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 22:10:15 +0000 Subject: [PATCH 1041/1766] use libtool for compile too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@540 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 66fac93825..3ee8af7863 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -210,10 +210,10 @@ testanalog: $(SRC)/testanalog.o $(MYLIB) $(LINK) $(SRC)/testanalog.o ./$(MYLIB) $(LIBS) $(SRC)/zap_io.o: $(SRC)/zap_io.c - $(COMPILE) $(MOD_CFLAGS) -c $< -o $@ + $(LTCOMPILE) $(MOD_CFLAGS) -c $< -o $@ %.o: %.c $(HEADERS) - $(COMPILE) -c $< -o $@ + $(LTCOMPILE) -c $< -o $@ dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf From b7b5e9daf623e1afda025fe6479143be7c82d997 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 22:10:15 +0000 Subject: [PATCH 1042/1766] use libtool for compile too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@540 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 66fac93825..3ee8af7863 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -210,10 +210,10 @@ testanalog: $(SRC)/testanalog.o $(MYLIB) $(LINK) $(SRC)/testanalog.o ./$(MYLIB) $(LIBS) $(SRC)/zap_io.o: $(SRC)/zap_io.c - $(COMPILE) $(MOD_CFLAGS) -c $< -o $@ + $(LTCOMPILE) $(MOD_CFLAGS) -c $< -o $@ %.o: %.c $(HEADERS) - $(COMPILE) -c $< -o $@ + $(LTCOMPILE) -c $< -o $@ dox: cd docs && doxygen $(PWD)/docs/Doxygen.conf From 7071a943a081f5b798ae9854e9691c971a69b9d8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 22:12:33 +0000 Subject: [PATCH 1043/1766] add configure.gnu to force pic git-svn-id: http://svn.openzap.org/svn/openzap/trunk@541 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.gnu | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libs/openzap/configure.gnu diff --git a/libs/openzap/configure.gnu b/libs/openzap/configure.gnu new file mode 100644 index 0000000000..5785ffc0e7 --- /dev/null +++ b/libs/openzap/configure.gnu @@ -0,0 +1,3 @@ +#! /bin/sh +./configure "$@" --with-pic + From 7841265d043a0d666cb1f7e347a2a341e2618133 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 22:12:33 +0000 Subject: [PATCH 1044/1766] add configure.gnu to force pic git-svn-id: http://svn.openzap.org/svn/openzap/trunk@541 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.gnu | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 libs/freetdm/configure.gnu diff --git a/libs/freetdm/configure.gnu b/libs/freetdm/configure.gnu new file mode 100644 index 0000000000..5785ffc0e7 --- /dev/null +++ b/libs/freetdm/configure.gnu @@ -0,0 +1,3 @@ +#! /bin/sh +./configure "$@" --with-pic + From 35e83cc2d3b3ca449cae2e8be25fb0e16760654e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 23:11:45 +0000 Subject: [PATCH 1045/1766] don't overflow int type git-svn-id: http://svn.openzap.org/svn/openzap/trunk@542 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 3c04b8db8d..f3b75bac98 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -163,7 +163,7 @@ typedef enum { ZAP_ALARM_NOTOPEN = ( 1 << 6), ZAP_ALARM_AIS = ( 1 << 7), ZAP_ALARM_RAI = ( 1 << 8), - ZAP_ALARM_GENERAL = ( 1 << 31) + ZAP_ALARM_GENERAL = ( 1 << 30) } zap_alarm_flag_t; typedef enum { @@ -232,7 +232,7 @@ typedef enum { ZAP_CODEC_ULAW = 0, ZAP_CODEC_ALAW = 8, ZAP_CODEC_SLIN = 10, - ZAP_CODEC_NONE = (1 << 31) + ZAP_CODEC_NONE = (1 << 30) } zap_codec_t; typedef enum { From 16c61e57a491719d8148b0d07748ea568af37c75 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 6 Sep 2008 23:11:45 +0000 Subject: [PATCH 1046/1766] don't overflow int type git-svn-id: http://svn.openzap.org/svn/openzap/trunk@542 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 3c04b8db8d..f3b75bac98 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -163,7 +163,7 @@ typedef enum { ZAP_ALARM_NOTOPEN = ( 1 << 6), ZAP_ALARM_AIS = ( 1 << 7), ZAP_ALARM_RAI = ( 1 << 8), - ZAP_ALARM_GENERAL = ( 1 << 31) + ZAP_ALARM_GENERAL = ( 1 << 30) } zap_alarm_flag_t; typedef enum { @@ -232,7 +232,7 @@ typedef enum { ZAP_CODEC_ULAW = 0, ZAP_CODEC_ALAW = 8, ZAP_CODEC_SLIN = 10, - ZAP_CODEC_NONE = (1 << 31) + ZAP_CODEC_NONE = (1 << 30) } zap_codec_t; typedef enum { From ef3d96dd9c3546c5deda52e510fa7b5faed2518b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 7 Sep 2008 00:08:01 +0000 Subject: [PATCH 1047/1766] don't use shell, that is a gmakeism, instead detect from configure git-svn-id: http://svn.openzap.org/svn/openzap/trunk@543 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 9 +++++---- libs/openzap/configure.ac | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 3ee8af7863..63c1a4d6e3 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -37,6 +37,8 @@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ LIBS = @LIBS@ DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ SOLINK = @SOLINK@ +OZ_SRCDIR=@oz_srcdir@ +oz_builddir=@oz_builddir@ SRC=src top_builddir=@top_builddir@ INSTALL=@INSTALL@ @@ -44,11 +46,10 @@ LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost +INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" -COMPILE = $(CC) $(CFLAGS) $(DEFS) $(INCS) +COMPILE = $(CC) $(CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ @@ -216,7 +217,7 @@ $(SRC)/zap_io.o: $(SRC)/zap_io.c $(LTCOMPILE) -c $< -o $@ dox: - cd docs && doxygen $(PWD)/docs/Doxygen.conf + cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c cd mod_openzap && make diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index aff46c9a36..ae71dcba1a 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ(2.59) AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) -AC_CONFIG_SRCDIR([src/libteletone_detect.c]) +AC_CONFIG_SRCDIR([src/zap_io.c]) AC_CONFIG_AUX_DIR(build) #AM_INIT_AUTOMAKE(libopenzap,0.1) @@ -14,6 +14,13 @@ AC_PROG_MAKE_SET AC_PREFIX_DEFAULT(/usr/local/openzap) + +# Absolute source/build directory +oz_srcdir=`(cd $srcdir && pwd)` +oz_builddir=`pwd` +AC_SUBST(oz_srcdir) +AC_SUBST(oz_builddir) + #override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) From d09e16f2457ad8b97ceba51216e02157283ca910 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 7 Sep 2008 00:08:01 +0000 Subject: [PATCH 1048/1766] don't use shell, that is a gmakeism, instead detect from configure git-svn-id: http://svn.openzap.org/svn/openzap/trunk@543 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 9 +++++---- libs/freetdm/configure.ac | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 3ee8af7863..63c1a4d6e3 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -37,6 +37,8 @@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ LIBS = @LIBS@ DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ SOLINK = @SOLINK@ +OZ_SRCDIR=@oz_srcdir@ +oz_builddir=@oz_builddir@ SRC=src top_builddir=@top_builddir@ INSTALL=@INSTALL@ @@ -44,11 +46,10 @@ LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) -PWD=$(shell pwd) -INCS=-I$(PWD)/$(SRC)/include -I$(PWD)/$(SRC)/isdn/include -I$(PWD)/$(SRC)/ozmod/ozmod_ss7_boost +INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" -COMPILE = $(CC) $(CFLAGS) $(DEFS) $(INCS) +COMPILE = $(CC) $(CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ @@ -216,7 +217,7 @@ $(SRC)/zap_io.o: $(SRC)/zap_io.c $(LTCOMPILE) -c $< -o $@ dox: - cd docs && doxygen $(PWD)/docs/Doxygen.conf + cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c cd mod_openzap && make diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index aff46c9a36..ae71dcba1a 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ(2.59) AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) -AC_CONFIG_SRCDIR([src/libteletone_detect.c]) +AC_CONFIG_SRCDIR([src/zap_io.c]) AC_CONFIG_AUX_DIR(build) #AM_INIT_AUTOMAKE(libopenzap,0.1) @@ -14,6 +14,13 @@ AC_PROG_MAKE_SET AC_PREFIX_DEFAULT(/usr/local/openzap) + +# Absolute source/build directory +oz_srcdir=`(cd $srcdir && pwd)` +oz_builddir=`pwd` +AC_SUBST(oz_srcdir) +AC_SUBST(oz_builddir) + #override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) From df1b9dca950dea7e56c984b898a3a329fbf002fe Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 7 Sep 2008 17:39:36 +0000 Subject: [PATCH 1049/1766] NT mode improvements: Add channel hunting in case the TE side specifies "any" channel in the Channel ID IE of an incoming SETUP message (or if there is no Channel ID IE at all). Support overlap dial in NT mode, (needed for BRI phones), triggered by a missing Called Party IE in the SETUP message. Tones... picking up a phone and not hearing a dialtone is no fun... Dialtone (works) and Ring (untested) are implemented, tones are generated by a secondary thread (only started for spans in NT mode). I tried to do the tone generating in the main thread first, but it is easier to handle like this. The loop uses the first channel that needs tones as a timing reference and the tone buffer is reused if multiple succeeding channels share the same state to save some cpu cycles (yes, not perfect... alternative is to allocate a buffer for every indication and precalculate the values... => 16KB for each indication). Coming up next: Q.931 Timers git-svn-id: http://svn.openzap.org/svn/openzap/trunk@544 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 + .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 429 ++++++++++++++++-- 2 files changed, 420 insertions(+), 26 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b93a5abc55..94dd0f9f23 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -698,6 +698,13 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); } else { + /* Don't skip messages in the ISDN call setup + * TODO: make the isdn stack smart enough to handle that itself + * until then, this is here for safety... + */ + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } @@ -707,6 +714,16 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, if (switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); } else { + /* Don't skip messages in the ISDN call setup + * TODO: make the isdn stack smart enough to handle that itself + * until then, this is here for safety... + */ + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 250dc4cae6..2136ee36cf 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -292,6 +292,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_isdn_data_t *isdn_data = span->signal_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; int chan_id = 0; + int chan_hunt = 0; zap_channel_t *zchan = NULL; zap_caller_data_t *caller_data = NULL; @@ -302,6 +303,14 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); @@ -339,7 +348,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan = isdn_data->channels_remote_crv[gen->CRV]; } - zap_log(ZAP_LOG_DEBUG, "zchan %x source isdn_data->channels_%s_crv[%#hx]\n", zchan, gen->CRVFlag ? "local" : "remote", 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) { @@ -484,6 +493,8 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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]) { @@ -497,8 +508,60 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } zchan = NULL; - if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { - zchan = &span->channels[chan_id]; + /* + * Channel selection for incoming calls: + */ + if (ZAP_SPAN_IS_NT(span) && chan_hunt) { + int 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) { @@ -545,7 +608,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) gen->CRVFlag = !(gen->CRVFlag); memcpy(zchan->caller_data.raw_data, msg, cplen); zchan->caller_data.raw_data_len = cplen; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; } } @@ -560,7 +622,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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.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); @@ -576,17 +638,50 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } else { - Q931ie_ProgInd progress; + Q931ie_ChanID ChanID; /* - * Setup Progress indicator + * Update Channel ID IE */ - 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 = 1; /* call is not end-to-end isdn = 1, in-band information available = 8 */ - gen->ProgInd = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &progress); + 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; @@ -602,6 +697,48 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } 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)) { + 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 = strlen(zchan->caller_data.cid_num.digits); + strcat(&zchan->caller_data.cid_num.digits[pos], (char *)callednum->Digit); + strcat(&zchan->caller_data.cid_name[pos], (char *)callednum->Digit); + strcat(&zchan->caller_data.ani.digits[pos], (char *)callednum->Digit); + strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); + + zap_log(ZAP_LOG_DEBUG, "Received new overlap digit (%s), destination number: %s\n", callednum->Digit, zchan->caller_data.cid_num.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; + default: zap_log(ZAP_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType); break; @@ -689,10 +826,44 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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: + { +/* + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + 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; + } + } + } +*/ + } + break; case ZAP_CHANNEL_STATE_RING: { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { @@ -1039,12 +1210,194 @@ static __inline__ void check_events(zap_span_t *span) } } + +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; +} + +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; + unsigned char frame[1024]; + int x, interval; + int offset = 0; + + zap_log(ZAP_LOG_DEBUG, "ISDN tones thread starting.\n"); + + 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; + } + } + zap_log(ZAP_LOG_NOTICE, "Tone generating interval %d\n", interval); + + assert(interval != 0); + + /* 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_RUNNING)) { + zap_wait_flag_t flags; + zap_status_t status; + int last_chan_state = 0; + int gated = 0; + + /* + * 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: + { + 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"); + return NULL; +} + 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 buf[1024]; - zap_size_t len = sizeof(buf); + unsigned char frame[1024]; + zap_size_t len = sizeof(frame); int errs = 0; #ifdef WIN32 @@ -1064,6 +1417,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) check_state(span); check_events(span); + /* + * + */ switch(status) { case ZAP_FAIL: { @@ -1084,17 +1440,17 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) { errs = 0; if (flags & ZAP_READ) { - len = sizeof(buf); - if (zap_channel_read(isdn_data->dchan, buf, &len) == ZAP_SUCCESS) { + len = sizeof(frame); + if (zap_channel_read(isdn_data->dchan, frame, &len) == ZAP_SUCCESS) { #ifdef IODEBUG char bb[4096] = ""; - print_hex_bytes(buf, len, bb, sizeof(bb)); + print_hex_bytes(frame, len, bb, sizeof(bb)); - print_bits(buf, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0); + 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, buf, (int)len); + Q921QueueHDLCFrame(&isdn_data->q921, frame, (int)len); Q921Rx12(&isdn_data->q921); } } else { @@ -1103,11 +1459,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) } break; } - } done: - zap_channel_close(&isdn_data->dchans[0]); zap_channel_close(&isdn_data->dchans[1]); zap_clear_flag(isdn_data, ZAP_ISDN_RUNNING); @@ -1259,7 +1613,13 @@ static zap_state_map_t isdn_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_RING, 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, @@ -1298,9 +1658,20 @@ static zap_state_map_t isdn_state_map = { static zap_status_t zap_isdn_start(zap_span_t *span) { + zap_status_t ret; + zap_isdn_data_t *isdn_data = span->signal_data; zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); - return zap_thread_create_detached(zap_isdn_run, span); + + ret = zap_thread_create_detached(zap_isdn_run, span); + if (ret != ZAP_SUCCESS) { + return ret; + } + + if(ZAP_SPAN_IS_NT(span)) { + ret = zap_thread_create_detached(zap_isdn_tones_run, span); + } + return ret; } @@ -1310,6 +1681,7 @@ 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; uint32_t opts = 0; @@ -1371,6 +1743,11 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) break; } opts = isdn_data->opts = *optp; + } else if (!strcasecmp(var, "tonemap")) { + if (!(val = va_arg(ap, char *))) { + break; + } + tonemap = (const char *)val; } } @@ -1408,20 +1785,20 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) Q931SetLogLevel(&isdn_data->q931, Q931_LOG_DEBUG); isdn_data->q931.autoRestartAck = 1; -// isdn_data->q931.autoConnectAck = 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 ((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; } From a8d9742c8e744433a626464a553aae8854dc66d5 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 7 Sep 2008 17:39:36 +0000 Subject: [PATCH 1050/1766] NT mode improvements: Add channel hunting in case the TE side specifies "any" channel in the Channel ID IE of an incoming SETUP message (or if there is no Channel ID IE at all). Support overlap dial in NT mode, (needed for BRI phones), triggered by a missing Called Party IE in the SETUP message. Tones... picking up a phone and not hearing a dialtone is no fun... Dialtone (works) and Ring (untested) are implemented, tones are generated by a secondary thread (only started for spans in NT mode). I tried to do the tone generating in the main thread first, but it is easier to handle like this. The loop uses the first channel that needs tones as a timing reference and the tone buffer is reused if multiple succeeding channels share the same state to save some cpu cycles (yes, not perfect... alternative is to allocate a buffer for every indication and precalculate the values... => 16KB for each indication). Coming up next: Q.931 Timers git-svn-id: http://svn.openzap.org/svn/openzap/trunk@544 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 17 + .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 429 ++++++++++++++++-- 2 files changed, 420 insertions(+), 26 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index b93a5abc55..94dd0f9f23 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -698,6 +698,13 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); } else { + /* Don't skip messages in the ISDN call setup + * TODO: make the isdn stack smart enough to handle that itself + * until then, this is here for safety... + */ + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } @@ -707,6 +714,16 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, if (switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); } else { + /* Don't skip messages in the ISDN call setup + * TODO: make the isdn stack smart enough to handle that itself + * until then, this is here for safety... + */ + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 250dc4cae6..2136ee36cf 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -292,6 +292,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_isdn_data_t *isdn_data = span->signal_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; int chan_id = 0; + int chan_hunt = 0; zap_channel_t *zchan = NULL; zap_caller_data_t *caller_data = NULL; @@ -302,6 +303,14 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); @@ -339,7 +348,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zchan = isdn_data->channels_remote_crv[gen->CRV]; } - zap_log(ZAP_LOG_DEBUG, "zchan %x source isdn_data->channels_%s_crv[%#hx]\n", zchan, gen->CRVFlag ? "local" : "remote", 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) { @@ -484,6 +493,8 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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]) { @@ -497,8 +508,60 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } zchan = NULL; - if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { - zchan = &span->channels[chan_id]; + /* + * Channel selection for incoming calls: + */ + if (ZAP_SPAN_IS_NT(span) && chan_hunt) { + int 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) { @@ -545,7 +608,6 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) gen->CRVFlag = !(gen->CRVFlag); memcpy(zchan->caller_data.raw_data, msg, cplen); zchan->caller_data.raw_data_len = cplen; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); fail = 0; } } @@ -560,7 +622,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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.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); @@ -576,17 +638,50 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } else { - Q931ie_ProgInd progress; + Q931ie_ChanID ChanID; /* - * Setup Progress indicator + * Update Channel ID IE */ - 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 = 1; /* call is not end-to-end isdn = 1, in-band information available = 8 */ - gen->ProgInd = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &progress); + 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; @@ -602,6 +697,48 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } 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)) { + 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 = strlen(zchan->caller_data.cid_num.digits); + strcat(&zchan->caller_data.cid_num.digits[pos], (char *)callednum->Digit); + strcat(&zchan->caller_data.cid_name[pos], (char *)callednum->Digit); + strcat(&zchan->caller_data.ani.digits[pos], (char *)callednum->Digit); + strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); + + zap_log(ZAP_LOG_DEBUG, "Received new overlap digit (%s), destination number: %s\n", callednum->Digit, zchan->caller_data.cid_num.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; + default: zap_log(ZAP_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType); break; @@ -689,10 +826,44 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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: + { +/* + if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + 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; + } + } + } +*/ + } + break; case ZAP_CHANNEL_STATE_RING: { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { @@ -1039,12 +1210,194 @@ static __inline__ void check_events(zap_span_t *span) } } + +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; +} + +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; + unsigned char frame[1024]; + int x, interval; + int offset = 0; + + zap_log(ZAP_LOG_DEBUG, "ISDN tones thread starting.\n"); + + 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; + } + } + zap_log(ZAP_LOG_NOTICE, "Tone generating interval %d\n", interval); + + assert(interval != 0); + + /* 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_RUNNING)) { + zap_wait_flag_t flags; + zap_status_t status; + int last_chan_state = 0; + int gated = 0; + + /* + * 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: + { + 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"); + return NULL; +} + 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 buf[1024]; - zap_size_t len = sizeof(buf); + unsigned char frame[1024]; + zap_size_t len = sizeof(frame); int errs = 0; #ifdef WIN32 @@ -1064,6 +1417,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) check_state(span); check_events(span); + /* + * + */ switch(status) { case ZAP_FAIL: { @@ -1084,17 +1440,17 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) { errs = 0; if (flags & ZAP_READ) { - len = sizeof(buf); - if (zap_channel_read(isdn_data->dchan, buf, &len) == ZAP_SUCCESS) { + len = sizeof(frame); + if (zap_channel_read(isdn_data->dchan, frame, &len) == ZAP_SUCCESS) { #ifdef IODEBUG char bb[4096] = ""; - print_hex_bytes(buf, len, bb, sizeof(bb)); + print_hex_bytes(frame, len, bb, sizeof(bb)); - print_bits(buf, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0); + 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, buf, (int)len); + Q921QueueHDLCFrame(&isdn_data->q921, frame, (int)len); Q921Rx12(&isdn_data->q921); } } else { @@ -1103,11 +1459,9 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) } break; } - } done: - zap_channel_close(&isdn_data->dchans[0]); zap_channel_close(&isdn_data->dchans[1]); zap_clear_flag(isdn_data, ZAP_ISDN_RUNNING); @@ -1259,7 +1613,13 @@ static zap_state_map_t isdn_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_RING, 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, @@ -1298,9 +1658,20 @@ static zap_state_map_t isdn_state_map = { static zap_status_t zap_isdn_start(zap_span_t *span) { + zap_status_t ret; + zap_isdn_data_t *isdn_data = span->signal_data; zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); - return zap_thread_create_detached(zap_isdn_run, span); + + ret = zap_thread_create_detached(zap_isdn_run, span); + if (ret != ZAP_SUCCESS) { + return ret; + } + + if(ZAP_SPAN_IS_NT(span)) { + ret = zap_thread_create_detached(zap_isdn_tones_run, span); + } + return ret; } @@ -1310,6 +1681,7 @@ 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; uint32_t opts = 0; @@ -1371,6 +1743,11 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) break; } opts = isdn_data->opts = *optp; + } else if (!strcasecmp(var, "tonemap")) { + if (!(val = va_arg(ap, char *))) { + break; + } + tonemap = (const char *)val; } } @@ -1408,20 +1785,20 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) Q931SetLogLevel(&isdn_data->q931, Q931_LOG_DEBUG); isdn_data->q931.autoRestartAck = 1; -// isdn_data->q931.autoConnectAck = 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 ((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; } From 0811daff59c84ad83508665df98974b9995b429a Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 7 Sep 2008 21:41:23 +0000 Subject: [PATCH 1051/1766] Fix building of ozmod_ss7_boost on FreeBSD(7) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@545 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 03f58b6da0..48cffda0be 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -35,7 +35,7 @@ #define OPENZAP_H -#ifndef _XOPEN_SOURCE +#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) #define _XOPEN_SOURCE 600 #endif From f5d6cecb48cbf4f5c5c677553563b95a37624ed8 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 7 Sep 2008 21:41:23 +0000 Subject: [PATCH 1052/1766] Fix building of ozmod_ss7_boost on FreeBSD(7) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@545 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 03f58b6da0..48cffda0be 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -35,7 +35,7 @@ #define OPENZAP_H -#ifndef _XOPEN_SOURCE +#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) #define _XOPEN_SOURCE 600 #endif From 00b24ab8d0e0ba2b12527bd49c37b8eea5b46bb6 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 8 Sep 2008 21:34:08 +0000 Subject: [PATCH 1053/1766] Add Facility IE handling on incoming SETUP messages to national too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@546 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/nationalStateNT.c | 3 +++ libs/openzap/src/isdn/nationalmes.c | 1 + 2 files changed, 4 insertions(+) diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c index 48d649f2df..6b6aa305d6 100644 --- a/libs/openzap/src/isdn/nationalStateNT.c +++ b/libs/openzap/src/isdn/nationalStateNT.c @@ -118,6 +118,9 @@ void nationalCreateNT(L3UCHAR i) 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.*/ diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 5ef69014b5..8d75760c8e 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -91,6 +91,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi 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; From 2178f9b87d3c992df16ea4db00391a589e6c751f Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 8 Sep 2008 21:34:08 +0000 Subject: [PATCH 1054/1766] Add Facility IE handling on incoming SETUP messages to national too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@546 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/nationalStateNT.c | 3 +++ libs/freetdm/src/isdn/nationalmes.c | 1 + 2 files changed, 4 insertions(+) diff --git a/libs/freetdm/src/isdn/nationalStateNT.c b/libs/freetdm/src/isdn/nationalStateNT.c index 48d649f2df..6b6aa305d6 100644 --- a/libs/freetdm/src/isdn/nationalStateNT.c +++ b/libs/freetdm/src/isdn/nationalStateNT.c @@ -118,6 +118,9 @@ void nationalCreateNT(L3UCHAR i) 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.*/ diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 5ef69014b5..8d75760c8e 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -91,6 +91,7 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi 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; From 8202ffd5784e8f7bf43300f5a49e2758dd3e8523 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 8 Sep 2008 23:01:44 +0000 Subject: [PATCH 1055/1766] fix config parser and build on some systems git-svn-id: http://svn.openzap.org/svn/openzap/trunk@547 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 2 +- libs/openzap/mod_openzap/mod_openzap.c | 2 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 63c1a4d6e3..a9263de5cf 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -40,7 +40,7 @@ SOLINK = @SOLINK@ OZ_SRCDIR=@oz_srcdir@ oz_builddir=@oz_builddir@ SRC=src -top_builddir=@top_builddir@ +top_builddir=@oz_builddir@ INSTALL=@INSTALL@ LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 94dd0f9f23..86a16f72d3 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1547,7 +1547,7 @@ static switch_status_t load_config(void) } else if (!strcasecmp(var, "hold-music")) { hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { - digit_timeout = val; + max_digits = val; } else if (!strcasecmp(var, "enable-analog-option")) { analog_options = enable_analog_option(val, analog_options); } diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 6bf8b86977..167c230220 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -95,14 +95,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) return ZAP_FAIL; } - if (digit_timeout < 2000 || digit_timeout > 10000) { - digit_timeout = 2000; - } - - if (max_dialstr < 2 || max_dialstr > 20) { - max_dialstr = 11; - } - analog_data = malloc(sizeof(*analog_data)); memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); @@ -126,6 +118,15 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } } + + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > 20) { + max_dialstr = 11; + } + span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; From 38f509239ee927066ceba1ace1f464bd6931ec0c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 8 Sep 2008 23:01:44 +0000 Subject: [PATCH 1056/1766] fix config parser and build on some systems git-svn-id: http://svn.openzap.org/svn/openzap/trunk@547 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 63c1a4d6e3..a9263de5cf 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -40,7 +40,7 @@ SOLINK = @SOLINK@ OZ_SRCDIR=@oz_srcdir@ oz_builddir=@oz_builddir@ SRC=src -top_builddir=@top_builddir@ +top_builddir=@oz_builddir@ INSTALL=@INSTALL@ LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 94dd0f9f23..86a16f72d3 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1547,7 +1547,7 @@ static switch_status_t load_config(void) } else if (!strcasecmp(var, "hold-music")) { hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { - digit_timeout = val; + max_digits = val; } else if (!strcasecmp(var, "enable-analog-option")) { analog_options = enable_analog_option(val, analog_options); } diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 6bf8b86977..167c230220 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -95,14 +95,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) return ZAP_FAIL; } - if (digit_timeout < 2000 || digit_timeout > 10000) { - digit_timeout = 2000; - } - - if (max_dialstr < 2 || max_dialstr > 20) { - max_dialstr = 11; - } - analog_data = malloc(sizeof(*analog_data)); memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); @@ -126,6 +118,15 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } } + + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > 20) { + max_dialstr = 11; + } + span->start = zap_analog_start; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; From d995bca407884856973f1737d07757755c48691e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 9 Sep 2008 18:10:04 +0000 Subject: [PATCH 1057/1766] fix leading space on calling number git-svn-id: http://svn.openzap.org/svn/openzap/trunk@548 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 095e8cd577..b936c20fe9 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -767,7 +767,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA pie->NumPlanID = IBuf[Octet + Off] & 0x0f; /* Octet 3a */ - if ((IBuf[Octet + Off] & 0x80) != 0) { + if ((IBuf[Octet + Off] & 0x80) == 0) { Off++; pie->PresInd = (IBuf[Octet + Off] >> 5) & 0x03; pie->ScreenInd = IBuf[Octet + Off] & 0x03; From efa6ec9c8f2dafa03b164deb7e1f356c0d1d8e09 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 9 Sep 2008 18:10:04 +0000 Subject: [PATCH 1058/1766] fix leading space on calling number git-svn-id: http://svn.openzap.org/svn/openzap/trunk@548 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 095e8cd577..b936c20fe9 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -767,7 +767,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA pie->NumPlanID = IBuf[Octet + Off] & 0x0f; /* Octet 3a */ - if ((IBuf[Octet + Off] & 0x80) != 0) { + if ((IBuf[Octet + Off] & 0x80) == 0) { Off++; pie->PresInd = (IBuf[Octet + Off] >> 5) & 0x03; pie->ScreenInd = IBuf[Octet + Off] & 0x03; From 675f163f9072bf7408680931d348a9751120a60f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 9 Sep 2008 19:17:38 +0000 Subject: [PATCH 1059/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@549 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 86a16f72d3..a74d3a26f6 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -163,7 +163,7 @@ static void stop_hold(switch_core_session_t *session_a, const char *uuid) switch_channel_clear_flag(channel_a, CF_HOLD); } else { switch_channel_stop_broadcast(channel); - switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000, NULL); } switch_core_session_rwunlock(session); From b23ecdd82e9ea878f494dbfcfedc37fd846d4733 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 9 Sep 2008 19:17:38 +0000 Subject: [PATCH 1060/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@549 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 86a16f72d3..a74d3a26f6 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -163,7 +163,7 @@ static void stop_hold(switch_core_session_t *session_a, const char *uuid) switch_channel_clear_flag(channel_a, CF_HOLD); } else { switch_channel_stop_broadcast(channel); - switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000); + switch_channel_wait_for_flag(channel, CF_BROADCAST, SWITCH_FALSE, 2000, NULL); } switch_core_session_rwunlock(session); From b715312d8f740134082b7a4acad1913f1322e362 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 9 Sep 2008 20:19:03 +0000 Subject: [PATCH 1061/1766] Extend 5ESS Setup message parser to handle Display IE in codeset 7 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@550 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/5ESSmes.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/isdn/5ESSmes.c b/libs/openzap/src/isdn/5ESSmes.c index 17f7ec8c77..7cdd21e7cc 100644 --- a/libs/openzap/src/isdn/5ESSmes.c +++ b/libs/openzap/src/isdn/5ESSmes.c @@ -60,17 +60,17 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic L3INT OOff = 0; L3INT rc = Q931E_NO_ERROR; L3UCHAR last_codeset = 0, codeset = 0; - L3UCHAR shift_lock = 1; + L3UCHAR shift_nolock = 1; - while (IOff < Size) - { - if (!shift_lock) { + while (IOff < Size) { + + if (shift_nolock) { codeset = last_codeset; } - if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) { - shift_lock = (IBuf[IOff] & 0x08); - if (shift_lock) { + if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT) { + shift_nolock = (IBuf[IOff] & 0x08); + if (shift_nolock) { last_codeset = codeset; } codeset = ((IBuf[IOff] & 0x07)); @@ -125,7 +125,18 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; } From 3e7e87f7999f69b97826805bd11f41581858ae29 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 9 Sep 2008 20:19:03 +0000 Subject: [PATCH 1062/1766] Extend 5ESS Setup message parser to handle Display IE in codeset 7 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@550 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/5ESSmes.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/isdn/5ESSmes.c b/libs/freetdm/src/isdn/5ESSmes.c index 17f7ec8c77..7cdd21e7cc 100644 --- a/libs/freetdm/src/isdn/5ESSmes.c +++ b/libs/freetdm/src/isdn/5ESSmes.c @@ -60,17 +60,17 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic L3INT OOff = 0; L3INT rc = Q931E_NO_ERROR; L3UCHAR last_codeset = 0, codeset = 0; - L3UCHAR shift_lock = 1; + L3UCHAR shift_nolock = 1; - while (IOff < Size) - { - if (!shift_lock) { + while (IOff < Size) { + + if (shift_nolock) { codeset = last_codeset; } - if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT ) { - shift_lock = (IBuf[IOff] & 0x08); - if (shift_lock) { + if ((IBuf[IOff] & 0xF0) == Q931ie_SHIFT) { + shift_nolock = (IBuf[IOff] & 0x08); + if (shift_nolock) { last_codeset = codeset; } codeset = ((IBuf[IOff] & 0x07)); @@ -125,7 +125,18 @@ L3INT ATT5ESSUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; } From 11e185ee8e2ee3d21d50ce2d850e4bca620ddbc2 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 9 Sep 2008 21:10:18 +0000 Subject: [PATCH 1063/1766] Fix CallingNum IE decoding to allow zero-length "numbers" git-svn-id: http://svn.openzap.org/svn/openzap/trunk@551 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index b936c20fe9..c93313e973 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -765,7 +765,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA /* Octet 3 */ pie->TypNum = (IBuf[Octet + Off] >> 4) & 0x07; pie->NumPlanID = IBuf[Octet + Off] & 0x0f; - + /* Octet 3a */ if ((IBuf[Octet + Off] & 0x80) == 0) { Off++; @@ -774,14 +774,16 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA } Octet++; - /* Octet 4*/ + /* Octet 4 */ x = 0; - do { - pie->Digit[x] = IBuf[Octet + Off] & 0x7f; - Off++; - x++; - } while ((IBuf[Octet + Off]&0x80) == 0 && Q931MoreIE()); + while (Q931MoreIE()) { + pie->Digit[x++] = IBuf[Octet + Off] & 0x7f; + if ((IBuf[Octet + Off] & 0x80) != 0) { + break; + } + Off++; + } pie->Digit[x] = '\0'; Q931IESizeTest(Q931E_CALLINGNUM); From 395f54b32f1d898f310388c371459fd94783f4b1 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 9 Sep 2008 21:10:18 +0000 Subject: [PATCH 1064/1766] Fix CallingNum IE decoding to allow zero-length "numbers" git-svn-id: http://svn.openzap.org/svn/openzap/trunk@551 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index b936c20fe9..c93313e973 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -765,7 +765,7 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA /* Octet 3 */ pie->TypNum = (IBuf[Octet + Off] >> 4) & 0x07; pie->NumPlanID = IBuf[Octet + Off] & 0x0f; - + /* Octet 3a */ if ((IBuf[Octet + Off] & 0x80) == 0) { Off++; @@ -774,14 +774,16 @@ L3INT Q931Uie_CallingNum(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHA } Octet++; - /* Octet 4*/ + /* Octet 4 */ x = 0; - do { - pie->Digit[x] = IBuf[Octet + Off] & 0x7f; - Off++; - x++; - } while ((IBuf[Octet + Off]&0x80) == 0 && Q931MoreIE()); + while (Q931MoreIE()) { + pie->Digit[x++] = IBuf[Octet + Off] & 0x7f; + if ((IBuf[Octet + Off] & 0x80) != 0) { + break; + } + Off++; + } pie->Digit[x] = '\0'; Q931IESizeTest(Q931E_CALLINGNUM); From fa8457c019d5ad68bd6b3ffae9f453af8373d502 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 10 Sep 2008 15:25:02 +0000 Subject: [PATCH 1065/1766] change core of openzap to use dynamic allocation of spans and channels to reduce memory usage git-svn-id: http://svn.openzap.org/svn/openzap/trunk@552 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 30 +++--- libs/openzap/src/include/openzap.h | 10 +- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 35 +++---- .../openzap/src/ozmod/ozmod_pika/ozmod_pika.c | 58 ++++++------ .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 36 +++---- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 64 ++++++------- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 24 ++--- libs/openzap/src/testanalog.c | 6 +- libs/openzap/src/zap_io.c | 94 ++++++++++++------- libs/openzap/src/zap_m3ua.c | 2 +- 10 files changed, 192 insertions(+), 167 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a74d3a26f6..0027451179 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1768,21 +1768,21 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea "dnis: %s\n" "rdnis: %s\n" "cause: %s\n\n", - span->channels[chan_id].span_id, - span->channels[chan_id].chan_id, - span->channels[chan_id].physical_span_id, - span->channels[chan_id].physical_chan_id, - zap_chan_type2str(span->channels[chan_id].type), - zap_channel_state2str(span->channels[chan_id].state), - zap_channel_state2str(span->channels[chan_id].last_state), - span->channels[chan_id].caller_data.cid_date, - span->channels[chan_id].caller_data.cid_name, - span->channels[chan_id].caller_data.cid_num.digits, - span->channels[chan_id].caller_data.ani.digits, - span->channels[chan_id].caller_data.aniII, - span->channels[chan_id].caller_data.dnis.digits, - span->channels[chan_id].caller_data.rdnis.digits, - switch_channel_cause2str(span->channels[chan_id].caller_data.hangup_cause) + span->channels[chan_id]->span_id, + span->channels[chan_id]->chan_id, + span->channels[chan_id]->physical_span_id, + span->channels[chan_id]->physical_chan_id, + zap_chan_type2str(span->channels[chan_id]->type), + zap_channel_state2str(span->channels[chan_id]->state), + zap_channel_state2str(span->channels[chan_id]->last_state), + span->channels[chan_id]->caller_data.cid_date, + span->channels[chan_id]->caller_data.cid_name, + span->channels[chan_id]->caller_data.cid_num.digits, + span->channels[chan_id]->caller_data.ani.digits, + span->channels[chan_id]->caller_data.aniII, + span->channels[chan_id]->caller_data.dnis.digits, + span->channels[chan_id]->caller_data.rdnis.digits, + switch_channel_cause2str(span->channels[chan_id]->caller_data.hangup_cause) ); } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 48cffda0be..11381854aa 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -153,7 +153,7 @@ #define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 #define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 16 #define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN -#define ZAP_MAX_SPANS_INTERFACE 33 +#define ZAP_MAX_SPANS_INTERFACE 128 #define GOTO_STATUS(label,st) status = st; goto label ; @@ -476,7 +476,7 @@ struct zap_span { char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; - zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + zap_channel_t *channels[ZAP_MAX_CHANNELS_SPAN+1]; zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; zap_span_start_t start; @@ -610,7 +610,7 @@ static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t s uint32_t j; zap_mutex_lock(span->mutex); for(j = 1; j <= span->chan_count; j++) { - zap_set_state_locked((&span->channels[j]), state); + zap_set_state_locked((span->channels[j]), state); } zap_mutex_unlock(span->mutex); } @@ -619,7 +619,7 @@ static __inline__ int zap_check_state_all(zap_span_t *span, zap_channel_state_t { uint32_t j; for(j = 1; j <= span->chan_count; j++) { - if (span->channels[j].state != state || zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + if (span->channels[j]->state != state || zap_test_flag(span->channels[j], ZAP_CHANNEL_STATE_CHANGE)) { return 0; } } @@ -632,7 +632,7 @@ static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) uint32_t j; zap_mutex_lock(span->mutex); for(j = 1; j <= span->chan_count; j++) { - zap_set_flag_locked((&span->channels[j]), flag); + zap_set_flag_locked((span->channels[j]), flag); } zap_mutex_unlock(span->mutex); } diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 2136ee36cf..ea39bf4285 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -81,7 +81,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) /* * get codec type */ - zap_channel_command(&span->channels[chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); /* * Q.931 Setup Message @@ -198,7 +198,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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]; + new_chan = span->channels[caller_data->chan_id]; } if (new_chan && (status = zap_channel_open_chan(new_chan) == ZAP_SUCCESS)) { @@ -393,14 +393,14 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RESTART: { if (chan_id) { - zchan = &span->channels[chan_id]; + zchan = span->channels[chan_id]; } if (zchan) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } else { uint32_t i; for (i = 0; i < span->chan_count; i++) { - zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); + zap_set_state_locked((span->channels[i]), ZAP_CHANNEL_STATE_RESTART); } } } @@ -519,7 +519,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * try to find a free channel */ for (x = 1; x <= span->chan_count; x++) { - zap_channel_t *zc = &span->channels[x]; + zap_channel_t *zc = span->channels[x]; if (!zap_test_flag(zc, ZAP_CHANNEL_INUSE) && zc->state == ZAP_CHANNEL_STATE_DOWN) { zchan = zc; @@ -543,7 +543,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * 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]; + zchan = span->channels[chan_id]; } else { /* invalid channel id */ @@ -939,7 +939,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* * get codec type */ - zap_channel_command(&zchan->span->channels[zchan->chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); + zap_channel_command(zchan->span->channels[zchan->chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); /* * Q.931 Setup Message @@ -1125,12 +1125,12 @@ static __inline__ void check_state(zap_span_t *span) 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); + 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); } } } @@ -1245,8 +1245,8 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) /* 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); + if (span->channels[x]->type != ZAP_CHAN_TYPE_DQ921) { + zap_channel_command(span->channels[x], ZAP_COMMAND_GET_INTERVAL, &interval); break; } } @@ -1270,7 +1270,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) * 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_channel_t *zchan = span->channels[x]; zap_size_t len = sizeof(frame), rlen; if (zchan->type == ZAP_CHAN_TYPE_DQ921) { @@ -1389,6 +1389,7 @@ done: } zap_log(ZAP_LOG_DEBUG, "ISDN tone thread ended.\n"); + return NULL; } @@ -1697,7 +1698,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } for(i = 1; i <= span->chan_count; i++) { - if (span->channels[i].type == ZAP_CHAN_TYPE_DQ921) { + 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; diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c index e3121309ec..c409f9535e 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c @@ -945,7 +945,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) zap_channel_t *zchan; pika_chan_data_t *chan_data; for(x = 1; x <= span->chan_count; x++) { - zchan = &span->channels[x]; + zchan = span->channels[x]; assert(zchan != NULL); chan_data = (pika_chan_data_t *) zchan->mod_data; assert(chan_data != NULL); @@ -983,11 +983,11 @@ 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; + 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); + zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT); PKH_EVENT_GetText(chan_data->last_oob_event.id, event_text, sizeof(event_text)); @@ -1006,47 +1006,47 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) break; case PKH_EVENT_PHONE_OFFHOOK: - zap_set_flag_locked((&span->channels[i]), ZAP_CHANNEL_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); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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: @@ -1057,22 +1057,22 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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"); + 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); + 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); + 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); + 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); + 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); + 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); + 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: @@ -1080,7 +1080,7 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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); + zap_clear_alarm_flag(span->channels[i], ZAP_ALARM_GENERAL); event_id = ZAP_OOB_ALARM_CLEAR; break; case PKH_EVENT_SPAN_MESSAGE: @@ -1104,10 +1104,10 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) break; } - span->channels[i].last_event_time = 0; + 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]; + span->event_header.channel = span->channels[i]; *event = &span->event_header; return ZAP_SUCCESS; } diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 7a3e08d2ce..c93f254783 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -143,8 +143,8 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i zap_mutex_lock(signal_mutex); for(i = 0; 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 (span->channels[i]->physical_span_id == event->span+1 && span->channels[i]->physical_chan_id == event->chan+1) { + zchan = span->channels[i]; if (force) { break; } @@ -152,10 +152,10 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i 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", - span->channels[i].span_id, - span->channels[i].chan_id, - span->channels[i].physical_span_id, - span->channels[i].physical_chan_id); + span->channels[i]->span_id, + span->channels[i]->chan_id, + span->channels[i]->physical_span_id, + span->channels[i]->physical_chan_id); zap_mutex_unlock(signal_mutex); for (x = 0; x < 200; x++) { @@ -169,10 +169,10 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { zchan = NULL; zap_log(ZAP_LOG_ERROR, "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 + span->channels[i]->span_id, + span->channels[i]->chan_id, + span->channels[i]->physical_span_id, + span->channels[i]->physical_chan_id ); } } @@ -811,15 +811,15 @@ static __inline__ void check_state(zap_span_t *span) 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); + 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); + state_advance(span->channels[j]); + zap_channel_complete_state(span->channels[j]); + zap_mutex_unlock(span->channels[j]->mutex); } } } diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 19d74cdb19..e4f2023786 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -728,9 +728,9 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) int r; for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = &span->channels[i]; + zap_channel_t *zchan = span->channels[i]; memset(&pfds[j], 0, sizeof(pfds[j])); - pfds[j].fd = span->channels[i].sockfd; + pfds[j].fd = span->channels[i]->sockfd; pfds[j].events = POLLPRI; /* The driver probably should be able to do this wink/flash/ringing by itself this is sort of a hack to make it work! */ @@ -787,7 +787,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = &span->channels[i]; + zap_channel_t *zchan = span->channels[i]; if (pfds[i-1].revents & POLLPRI) { zap_set_flag(zchan, ZAP_CHANNEL_EVENT); @@ -809,45 +809,45 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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 (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); + 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 (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); + 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) { + if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + wp_tdm_cmd_exec(span->channels[i], &tdm_api); } goto event; } } } - if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { + if (zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) { wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); - zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); + zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; - if (wp_tdm_cmd_exec(&span->channels[i], &tdm_api) != ZAP_SUCCESS) { + if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -855,25 +855,25 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { case WP_TDMAPI_EVENT_RXHOOK: { - if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { + 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); + 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); + 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); + 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); + zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH); } } continue; @@ -883,8 +883,8 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(&span->channels[i], &tdm_api))) { - snprintf(span->channels[i].last_error, sizeof(span->channels[i].last_error), "ONHOOK Failed"); + if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { + 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; @@ -911,10 +911,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event: - span->channels[i].last_event_time = 0; + 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]; + span->event_header.channel = span->channels[i]; *event = &span->event_header; return ZAP_SUCCESS; } diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 4b271ed6f5..a739300d1b 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -571,7 +571,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) for(i = 1; i <= span->chan_count; i++) { memset(&pfds[j], 0, sizeof(pfds[j])); - pfds[j].fd = span->channels[i].sockfd; + pfds[j].fd = span->channels[i]->sockfd; pfds[j].events = POLLPRI; j++; } @@ -587,8 +587,8 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) 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(); + zap_set_flag(span->channels[i], ZAP_CHANNEL_EVENT); + span->channels[i]->last_event_time = zap_current_time_in_ms(); k++; } } @@ -606,9 +606,9 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) zap_oob_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, ZT_GETEVENT, &zt_event_id) == -1) { + 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, ZT_GETEVENT, &zt_event_id) == -1) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -636,7 +636,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_WINKFLASH: { - if (span->channels[i].state == ZAP_CHANNEL_STATE_DOWN) { + if (span->channels[i]->state == ZAP_CHANNEL_STATE_DOWN) { event_id = ZAP_OOB_WINK; } else { event_id = ZAP_OOB_FLASH; @@ -645,10 +645,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_RINGOFFHOOK: { - if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { - zap_set_flag_locked((&span->channels[i]), ZAP_CHANNEL_OFFHOOK); + if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { + 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) { + } else if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) { event_id = ZAP_OOB_RING_START; } } @@ -671,10 +671,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; } - span->channels[i].last_event_time = 0; + 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]; + span->event_header.channel = span->channels[i]; *event = &span->event_header; return ZAP_SUCCESS; } diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index d816edb3be..274228dea0 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -98,16 +98,18 @@ int main(int argc, char *argv[]) if (zap_configure_span("analog", span, on_signal, - "tonemap", "te", + "tonemap", "us", "digit_timeout", &digit_timeout, "max_dialstr", &max_dialstr, TAG_END - ) == ZAP_SUCCESS) { + ) != 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); } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 67a9ae690f..69b920c3f1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -77,7 +77,7 @@ static struct { zap_hash_t *interface_hash; zap_hash_t *module_hash; zap_mutex_t *mutex; - struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; + struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1]; uint32_t span_index; uint32_t running; } globals; @@ -306,7 +306,13 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_mutex_lock(globals.mutex); if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = &globals.spans[++globals.span_index]; + new_span = globals.spans[++globals.span_index]; + if (!new_span) { + if (!(new_span = malloc(sizeof(*new_span)))) { + goto done; + } + globals.spans[globals.span_index] = new_span; + } memset(new_span, 0, sizeof(*new_span)); status = zap_mutex_create(&new_span->mutex); if (status != ZAP_SUCCESS) { @@ -337,10 +343,10 @@ zap_status_t zap_span_close_all(void) zap_mutex_lock(globals.mutex); for(i = 1; i <= globals.span_index; i++) { - span = &globals.spans[i]; + span = globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 0; j <= span->chan_count; j++) { - zap_channel_destroy(&span->channels[j]); + for(j = 0; j <= span->chan_count && span->channels[j]; j++) { + zap_channel_destroy(span->channels[j]); } } } @@ -416,8 +422,15 @@ zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { - zap_channel_t *new_chan; - new_chan = &span->channels[++span->chan_count]; + zap_channel_t *new_chan = span->channels[++span->chan_count]; + + if (!new_chan) { + if (!(new_chan = malloc(sizeof(*new_chan)))) { + return ZAP_FAIL; + } + span->channels[span->chan_count] = new_chan; + } + new_chan->type = type; new_chan->sockfd = sockfd; new_chan->zio = span->zio; @@ -455,10 +468,10 @@ zap_status_t zap_span_find(uint32_t id, zap_span_t **span) } zap_mutex_lock(globals.mutex); - fspan = &globals.spans[id]; + fspan = globals.spans[id]; zap_mutex_unlock(globals.mutex); - if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { + if (!fspan || !zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; } @@ -799,14 +812,14 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z return ZAP_FAIL; } - if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { + if (globals.spans[span_id]->active_count >= globals.spans[span_id]->chan_count) { zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); *zchan = NULL; return ZAP_FAIL; } - if (globals.spans[span_id].channel_request && !globals.spans[span_id].suggest_chan_id) { - return globals.spans[span_id].channel_request(&globals.spans[span_id], 0, direction, caller_data, zchan); + if (globals.spans[span_id]->channel_request && !globals.spans[span_id]->suggest_chan_id) { + return globals.spans[span_id]->channel_request(globals.spans[span_id], 0, direction, caller_data, zchan); } span_max = span_id; @@ -831,7 +844,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } - span = &globals.spans[j]; + span = globals.spans[j]; zap_mutex_lock(span->mutex); if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { @@ -856,7 +869,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } - check = &span->channels[i]; + check = span->channels[i]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && @@ -864,8 +877,8 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z check->state == ZAP_CHANNEL_STATE_DOWN ) { - if (globals.spans[span_id].channel_request) { - status = globals.spans[span_id].channel_request(&globals.spans[span_id], i, direction, caller_data, zchan); + if (globals.spans[span_id]->channel_request) { + status = globals.spans[span_id]->channel_request(globals.spans[span_id], i, direction, caller_data, zchan); zap_mutex_unlock(span->mutex); goto done; } @@ -992,12 +1005,12 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; - if (globals.spans[span_id].channel_request) { + if (globals.spans[span_id]->channel_request) { zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); goto done; } - check = &globals.spans[span_id].channels[chan_id]; + check = globals.spans[span_id]->channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { @@ -2343,29 +2356,38 @@ zap_status_t zap_global_destroy(void) zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) { - zap_span_t *cur_span = &globals.spans[i]; + zap_span_t *cur_span = globals.spans[i]; - if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { - zap_mutex_lock(cur_span->mutex); - zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); - for(j = 1; j <= cur_span->chan_count; j++) { - zap_channel_t *cur_chan = &cur_span->channels[j]; - if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_channel_destroy(cur_chan); + if (cur_span) { + if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { + zap_mutex_lock(cur_span->mutex); + zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); + for(j = 1; j <= cur_span->chan_count && cur_span->channels[j]; j++) { + zap_channel_t *cur_chan = cur_span->channels[j]; + if (cur_chan) { + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + zap_channel_destroy(cur_chan); + } + free(cur_chan); + cur_chan = NULL; + } } + zap_mutex_unlock(cur_span->mutex); + + if (cur_span->mutex) { + zap_mutex_destroy(&cur_span->mutex); + } + + zap_safe_free(cur_span->signal_data); + zap_span_destroy(cur_span); } - zap_mutex_unlock(cur_span->mutex); - - if (cur_span->mutex) { - zap_mutex_destroy(&cur_span->mutex); - } - - zap_safe_free(cur_span->signal_data); - zap_span_destroy(cur_span); - + zap_safe_free(cur_span->type); + free(cur_span); + cur_span = NULL; } } - + globals.span_index = 0; + zap_unload_modules(); zap_mutex_lock(globals.mutex); diff --git a/libs/openzap/src/zap_m3ua.c b/libs/openzap/src/zap_m3ua.c index c54e533eab..50736b75e4 100644 --- a/libs/openzap/src/zap_m3ua.c +++ b/libs/openzap/src/zap_m3ua.c @@ -689,4 +689,4 @@ zap_status_t m3ua_start(zap_span_t *span) * tab-width:4 * c-basic-offset:4 * End: -*/ \ No newline at end of file +*/ From 3c4453955d86f72611d4698f87b1ff44b34fb17f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 10 Sep 2008 15:25:02 +0000 Subject: [PATCH 1066/1766] change core of openzap to use dynamic allocation of spans and channels to reduce memory usage git-svn-id: http://svn.openzap.org/svn/openzap/trunk@552 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 30 +++--- libs/freetdm/src/include/openzap.h | 10 +- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 35 +++---- .../freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 58 ++++++------ .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 36 +++---- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 64 ++++++------- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 24 ++--- libs/freetdm/src/testanalog.c | 6 +- libs/freetdm/src/zap_io.c | 94 ++++++++++++------- libs/freetdm/src/zap_m3ua.c | 2 +- 10 files changed, 192 insertions(+), 167 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a74d3a26f6..0027451179 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1768,21 +1768,21 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea "dnis: %s\n" "rdnis: %s\n" "cause: %s\n\n", - span->channels[chan_id].span_id, - span->channels[chan_id].chan_id, - span->channels[chan_id].physical_span_id, - span->channels[chan_id].physical_chan_id, - zap_chan_type2str(span->channels[chan_id].type), - zap_channel_state2str(span->channels[chan_id].state), - zap_channel_state2str(span->channels[chan_id].last_state), - span->channels[chan_id].caller_data.cid_date, - span->channels[chan_id].caller_data.cid_name, - span->channels[chan_id].caller_data.cid_num.digits, - span->channels[chan_id].caller_data.ani.digits, - span->channels[chan_id].caller_data.aniII, - span->channels[chan_id].caller_data.dnis.digits, - span->channels[chan_id].caller_data.rdnis.digits, - switch_channel_cause2str(span->channels[chan_id].caller_data.hangup_cause) + span->channels[chan_id]->span_id, + span->channels[chan_id]->chan_id, + span->channels[chan_id]->physical_span_id, + span->channels[chan_id]->physical_chan_id, + zap_chan_type2str(span->channels[chan_id]->type), + zap_channel_state2str(span->channels[chan_id]->state), + zap_channel_state2str(span->channels[chan_id]->last_state), + span->channels[chan_id]->caller_data.cid_date, + span->channels[chan_id]->caller_data.cid_name, + span->channels[chan_id]->caller_data.cid_num.digits, + span->channels[chan_id]->caller_data.ani.digits, + span->channels[chan_id]->caller_data.aniII, + span->channels[chan_id]->caller_data.dnis.digits, + span->channels[chan_id]->caller_data.rdnis.digits, + switch_channel_cause2str(span->channels[chan_id]->caller_data.hangup_cause) ); } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 48cffda0be..11381854aa 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -153,7 +153,7 @@ #define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 #define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 16 #define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN -#define ZAP_MAX_SPANS_INTERFACE 33 +#define ZAP_MAX_SPANS_INTERFACE 128 #define GOTO_STATUS(label,st) status = st; goto label ; @@ -476,7 +476,7 @@ struct zap_span { char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; - zap_channel_t channels[ZAP_MAX_CHANNELS_SPAN]; + zap_channel_t *channels[ZAP_MAX_CHANNELS_SPAN+1]; zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; zap_span_start_t start; @@ -610,7 +610,7 @@ static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t s uint32_t j; zap_mutex_lock(span->mutex); for(j = 1; j <= span->chan_count; j++) { - zap_set_state_locked((&span->channels[j]), state); + zap_set_state_locked((span->channels[j]), state); } zap_mutex_unlock(span->mutex); } @@ -619,7 +619,7 @@ static __inline__ int zap_check_state_all(zap_span_t *span, zap_channel_state_t { uint32_t j; for(j = 1; j <= span->chan_count; j++) { - if (span->channels[j].state != state || zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { + if (span->channels[j]->state != state || zap_test_flag(span->channels[j], ZAP_CHANNEL_STATE_CHANGE)) { return 0; } } @@ -632,7 +632,7 @@ static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) uint32_t j; zap_mutex_lock(span->mutex); for(j = 1; j <= span->chan_count; j++) { - zap_set_flag_locked((&span->channels[j]), flag); + zap_set_flag_locked((span->channels[j]), flag); } zap_mutex_unlock(span->mutex); } diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 2136ee36cf..ea39bf4285 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -81,7 +81,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) /* * get codec type */ - zap_channel_command(&span->channels[chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); /* * Q.931 Setup Message @@ -198,7 +198,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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]; + new_chan = span->channels[caller_data->chan_id]; } if (new_chan && (status = zap_channel_open_chan(new_chan) == ZAP_SUCCESS)) { @@ -393,14 +393,14 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RESTART: { if (chan_id) { - zchan = &span->channels[chan_id]; + zchan = span->channels[chan_id]; } if (zchan) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } else { uint32_t i; for (i = 0; i < span->chan_count; i++) { - zap_set_state_locked((&span->channels[i]), ZAP_CHANNEL_STATE_RESTART); + zap_set_state_locked((span->channels[i]), ZAP_CHANNEL_STATE_RESTART); } } } @@ -519,7 +519,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * try to find a free channel */ for (x = 1; x <= span->chan_count; x++) { - zap_channel_t *zc = &span->channels[x]; + zap_channel_t *zc = span->channels[x]; if (!zap_test_flag(zc, ZAP_CHANNEL_INUSE) && zc->state == ZAP_CHANNEL_STATE_DOWN) { zchan = zc; @@ -543,7 +543,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * 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]; + zchan = span->channels[chan_id]; } else { /* invalid channel id */ @@ -939,7 +939,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* * get codec type */ - zap_channel_command(&zchan->span->channels[zchan->chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); + zap_channel_command(zchan->span->channels[zchan->chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); /* * Q.931 Setup Message @@ -1125,12 +1125,12 @@ static __inline__ void check_state(zap_span_t *span) 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); + 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); } } } @@ -1245,8 +1245,8 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) /* 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); + if (span->channels[x]->type != ZAP_CHAN_TYPE_DQ921) { + zap_channel_command(span->channels[x], ZAP_COMMAND_GET_INTERVAL, &interval); break; } } @@ -1270,7 +1270,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) * 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_channel_t *zchan = span->channels[x]; zap_size_t len = sizeof(frame), rlen; if (zchan->type == ZAP_CHAN_TYPE_DQ921) { @@ -1389,6 +1389,7 @@ done: } zap_log(ZAP_LOG_DEBUG, "ISDN tone thread ended.\n"); + return NULL; } @@ -1697,7 +1698,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } for(i = 1; i <= span->chan_count; i++) { - if (span->channels[i].type == ZAP_CHAN_TYPE_DQ921) { + 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; diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index e3121309ec..c409f9535e 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -945,7 +945,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) zap_channel_t *zchan; pika_chan_data_t *chan_data; for(x = 1; x <= span->chan_count; x++) { - zchan = &span->channels[x]; + zchan = span->channels[x]; assert(zchan != NULL); chan_data = (pika_chan_data_t *) zchan->mod_data; assert(chan_data != NULL); @@ -983,11 +983,11 @@ 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; + 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); + zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT); PKH_EVENT_GetText(chan_data->last_oob_event.id, event_text, sizeof(event_text)); @@ -1006,47 +1006,47 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) break; case PKH_EVENT_PHONE_OFFHOOK: - zap_set_flag_locked((&span->channels[i]), ZAP_CHANNEL_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); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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: @@ -1057,22 +1057,22 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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"); + 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); + 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); + 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); + 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); + 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); + 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); + 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: @@ -1080,7 +1080,7 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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); + zap_clear_alarm_flag(span->channels[i], ZAP_ALARM_GENERAL); event_id = ZAP_OOB_ALARM_CLEAR; break; case PKH_EVENT_SPAN_MESSAGE: @@ -1104,10 +1104,10 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) break; } - span->channels[i].last_event_time = 0; + 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]; + span->event_header.channel = span->channels[i]; *event = &span->event_header; return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 7a3e08d2ce..c93f254783 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -143,8 +143,8 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i zap_mutex_lock(signal_mutex); for(i = 0; 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 (span->channels[i]->physical_span_id == event->span+1 && span->channels[i]->physical_chan_id == event->chan+1) { + zchan = span->channels[i]; if (force) { break; } @@ -152,10 +152,10 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i 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", - span->channels[i].span_id, - span->channels[i].chan_id, - span->channels[i].physical_span_id, - span->channels[i].physical_chan_id); + span->channels[i]->span_id, + span->channels[i]->chan_id, + span->channels[i]->physical_span_id, + span->channels[i]->physical_chan_id); zap_mutex_unlock(signal_mutex); for (x = 0; x < 200; x++) { @@ -169,10 +169,10 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { zchan = NULL; zap_log(ZAP_LOG_ERROR, "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 + span->channels[i]->span_id, + span->channels[i]->chan_id, + span->channels[i]->physical_span_id, + span->channels[i]->physical_chan_id ); } } @@ -811,15 +811,15 @@ static __inline__ void check_state(zap_span_t *span) 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); + 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); + state_advance(span->channels[j]); + zap_channel_complete_state(span->channels[j]); + zap_mutex_unlock(span->channels[j]->mutex); } } } diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 19d74cdb19..e4f2023786 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -728,9 +728,9 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) int r; for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = &span->channels[i]; + zap_channel_t *zchan = span->channels[i]; memset(&pfds[j], 0, sizeof(pfds[j])); - pfds[j].fd = span->channels[i].sockfd; + pfds[j].fd = span->channels[i]->sockfd; pfds[j].events = POLLPRI; /* The driver probably should be able to do this wink/flash/ringing by itself this is sort of a hack to make it work! */ @@ -787,7 +787,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = &span->channels[i]; + zap_channel_t *zchan = span->channels[i]; if (pfds[i-1].revents & POLLPRI) { zap_set_flag(zchan, ZAP_CHANNEL_EVENT); @@ -809,45 +809,45 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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 (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); + 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 (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); + 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) { + if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) { wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(&span->channels[i], &tdm_api); + wp_tdm_cmd_exec(span->channels[i], &tdm_api); } goto event; } } } - if (zap_test_flag((&span->channels[i]), ZAP_CHANNEL_EVENT)) { + if (zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) { wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); - zap_clear_flag((&span->channels[i]), ZAP_CHANNEL_EVENT); + zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; - if (wp_tdm_cmd_exec(&span->channels[i], &tdm_api) != ZAP_SUCCESS) { + if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -855,25 +855,25 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { case WP_TDMAPI_EVENT_RXHOOK: { - if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { + 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); + 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); + 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); + 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); + zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH); } } continue; @@ -883,8 +883,8 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(&span->channels[i], &tdm_api))) { - snprintf(span->channels[i].last_error, sizeof(span->channels[i].last_error), "ONHOOK Failed"); + if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { + 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; @@ -911,10 +911,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event: - span->channels[i].last_event_time = 0; + 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]; + span->event_header.channel = span->channels[i]; *event = &span->event_header; return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 4b271ed6f5..a739300d1b 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -571,7 +571,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) for(i = 1; i <= span->chan_count; i++) { memset(&pfds[j], 0, sizeof(pfds[j])); - pfds[j].fd = span->channels[i].sockfd; + pfds[j].fd = span->channels[i]->sockfd; pfds[j].events = POLLPRI; j++; } @@ -587,8 +587,8 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) 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(); + zap_set_flag(span->channels[i], ZAP_CHANNEL_EVENT); + span->channels[i]->last_event_time = zap_current_time_in_ms(); k++; } } @@ -606,9 +606,9 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) zap_oob_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, ZT_GETEVENT, &zt_event_id) == -1) { + 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, ZT_GETEVENT, &zt_event_id) == -1) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); return ZAP_FAIL; } @@ -636,7 +636,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_WINKFLASH: { - if (span->channels[i].state == ZAP_CHANNEL_STATE_DOWN) { + if (span->channels[i]->state == ZAP_CHANNEL_STATE_DOWN) { event_id = ZAP_OOB_WINK; } else { event_id = ZAP_OOB_FLASH; @@ -645,10 +645,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_RINGOFFHOOK: { - if (span->channels[i].type == ZAP_CHAN_TYPE_FXS) { - zap_set_flag_locked((&span->channels[i]), ZAP_CHANNEL_OFFHOOK); + if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { + 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) { + } else if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) { event_id = ZAP_OOB_RING_START; } } @@ -671,10 +671,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; } - span->channels[i].last_event_time = 0; + 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]; + span->event_header.channel = span->channels[i]; *event = &span->event_header; return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index d816edb3be..274228dea0 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -98,16 +98,18 @@ int main(int argc, char *argv[]) if (zap_configure_span("analog", span, on_signal, - "tonemap", "te", + "tonemap", "us", "digit_timeout", &digit_timeout, "max_dialstr", &max_dialstr, TAG_END - ) == ZAP_SUCCESS) { + ) != 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); } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 67a9ae690f..69b920c3f1 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -77,7 +77,7 @@ static struct { zap_hash_t *interface_hash; zap_hash_t *module_hash; zap_mutex_t *mutex; - struct zap_span spans[ZAP_MAX_SPANS_INTERFACE]; + struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1]; uint32_t span_index; uint32_t running; } globals; @@ -306,7 +306,13 @@ zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) zap_mutex_lock(globals.mutex); if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = &globals.spans[++globals.span_index]; + new_span = globals.spans[++globals.span_index]; + if (!new_span) { + if (!(new_span = malloc(sizeof(*new_span)))) { + goto done; + } + globals.spans[globals.span_index] = new_span; + } memset(new_span, 0, sizeof(*new_span)); status = zap_mutex_create(&new_span->mutex); if (status != ZAP_SUCCESS) { @@ -337,10 +343,10 @@ zap_status_t zap_span_close_all(void) zap_mutex_lock(globals.mutex); for(i = 1; i <= globals.span_index; i++) { - span = &globals.spans[i]; + span = globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 0; j <= span->chan_count; j++) { - zap_channel_destroy(&span->channels[j]); + for(j = 0; j <= span->chan_count && span->channels[j]; j++) { + zap_channel_destroy(span->channels[j]); } } } @@ -416,8 +422,15 @@ zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { - zap_channel_t *new_chan; - new_chan = &span->channels[++span->chan_count]; + zap_channel_t *new_chan = span->channels[++span->chan_count]; + + if (!new_chan) { + if (!(new_chan = malloc(sizeof(*new_chan)))) { + return ZAP_FAIL; + } + span->channels[span->chan_count] = new_chan; + } + new_chan->type = type; new_chan->sockfd = sockfd; new_chan->zio = span->zio; @@ -455,10 +468,10 @@ zap_status_t zap_span_find(uint32_t id, zap_span_t **span) } zap_mutex_lock(globals.mutex); - fspan = &globals.spans[id]; + fspan = globals.spans[id]; zap_mutex_unlock(globals.mutex); - if (!zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { + if (!fspan || !zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; } @@ -799,14 +812,14 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z return ZAP_FAIL; } - if (globals.spans[span_id].active_count >= globals.spans[span_id].chan_count) { + if (globals.spans[span_id]->active_count >= globals.spans[span_id]->chan_count) { zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); *zchan = NULL; return ZAP_FAIL; } - if (globals.spans[span_id].channel_request && !globals.spans[span_id].suggest_chan_id) { - return globals.spans[span_id].channel_request(&globals.spans[span_id], 0, direction, caller_data, zchan); + if (globals.spans[span_id]->channel_request && !globals.spans[span_id]->suggest_chan_id) { + return globals.spans[span_id]->channel_request(globals.spans[span_id], 0, direction, caller_data, zchan); } span_max = span_id; @@ -831,7 +844,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } - span = &globals.spans[j]; + span = globals.spans[j]; zap_mutex_lock(span->mutex); if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { @@ -856,7 +869,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } - check = &span->channels[i]; + check = span->channels[i]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && @@ -864,8 +877,8 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z check->state == ZAP_CHANNEL_STATE_DOWN ) { - if (globals.spans[span_id].channel_request) { - status = globals.spans[span_id].channel_request(&globals.spans[span_id], i, direction, caller_data, zchan); + if (globals.spans[span_id]->channel_request) { + status = globals.spans[span_id]->channel_request(globals.spans[span_id], i, direction, caller_data, zchan); zap_mutex_unlock(span->mutex); goto done; } @@ -992,12 +1005,12 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; - if (globals.spans[span_id].channel_request) { + if (globals.spans[span_id]->channel_request) { zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); goto done; } - check = &globals.spans[span_id].channels[chan_id]; + check = globals.spans[span_id]->channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { @@ -2343,29 +2356,38 @@ zap_status_t zap_global_destroy(void) zap_sleep(1000); for(i = 1; i <= globals.span_index; i++) { - zap_span_t *cur_span = &globals.spans[i]; + zap_span_t *cur_span = globals.spans[i]; - if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { - zap_mutex_lock(cur_span->mutex); - zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); - for(j = 1; j <= cur_span->chan_count; j++) { - zap_channel_t *cur_chan = &cur_span->channels[j]; - if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_channel_destroy(cur_chan); + if (cur_span) { + if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { + zap_mutex_lock(cur_span->mutex); + zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); + for(j = 1; j <= cur_span->chan_count && cur_span->channels[j]; j++) { + zap_channel_t *cur_chan = cur_span->channels[j]; + if (cur_chan) { + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + zap_channel_destroy(cur_chan); + } + free(cur_chan); + cur_chan = NULL; + } } + zap_mutex_unlock(cur_span->mutex); + + if (cur_span->mutex) { + zap_mutex_destroy(&cur_span->mutex); + } + + zap_safe_free(cur_span->signal_data); + zap_span_destroy(cur_span); } - zap_mutex_unlock(cur_span->mutex); - - if (cur_span->mutex) { - zap_mutex_destroy(&cur_span->mutex); - } - - zap_safe_free(cur_span->signal_data); - zap_span_destroy(cur_span); - + zap_safe_free(cur_span->type); + free(cur_span); + cur_span = NULL; } } - + globals.span_index = 0; + zap_unload_modules(); zap_mutex_lock(globals.mutex); diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index c54e533eab..50736b75e4 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -689,4 +689,4 @@ zap_status_t m3ua_start(zap_span_t *span) * tab-width:4 * c-basic-offset:4 * End: -*/ \ No newline at end of file +*/ From 6d024dc60e167672426d1b9568e8d24c7b021892 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 10 Sep 2008 19:27:17 +0000 Subject: [PATCH 1067/1766] fix OPENZAP-14 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@553 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/zap_io.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 0027451179..9a1ac3423f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1824,7 +1824,7 @@ SWITCH_STANDARD_API(oz_function) int j; stream->write_function(stream, "+OK\n"); - for(j = 0; j <= span->chan_count; j++) { + for(j = 1; j <= span->chan_count; j++) { dump_chan(span, j, stream); } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 69b920c3f1..864b19ffd1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -345,7 +345,7 @@ zap_status_t zap_span_close_all(void) for(i = 1; i <= globals.span_index; i++) { span = globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 0; j <= span->chan_count && span->channels[j]; j++) { + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { zap_channel_destroy(span->channels[j]); } } @@ -429,6 +429,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } span->channels[span->chan_count] = new_chan; + memset(new_chan, 0, sizeof(*new_chan)); } new_chan->type = type; @@ -869,7 +870,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } - check = span->channels[i]; + if (!(check = span->channels[i])) { + status = ZAP_FAIL; + zap_mutex_unlock(span->mutex); + goto done; + } if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && From 97958e56e0d69f55a168fc22ac77de04a4805602 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 10 Sep 2008 19:27:17 +0000 Subject: [PATCH 1068/1766] fix OPENZAP-14 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@553 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/zap_io.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 0027451179..9a1ac3423f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1824,7 +1824,7 @@ SWITCH_STANDARD_API(oz_function) int j; stream->write_function(stream, "+OK\n"); - for(j = 0; j <= span->chan_count; j++) { + for(j = 1; j <= span->chan_count; j++) { dump_chan(span, j, stream); } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 69b920c3f1..864b19ffd1 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -345,7 +345,7 @@ zap_status_t zap_span_close_all(void) for(i = 1; i <= globals.span_index; i++) { span = globals.spans[i]; if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 0; j <= span->chan_count && span->channels[j]; j++) { + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { zap_channel_destroy(span->channels[j]); } } @@ -429,6 +429,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } span->channels[span->chan_count] = new_chan; + memset(new_chan, 0, sizeof(*new_chan)); } new_chan->type = type; @@ -869,7 +870,11 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z } } - check = span->channels[i]; + if (!(check = span->channels[i])) { + status = ZAP_FAIL; + zap_mutex_unlock(span->mutex); + goto done; + } if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && From 1b6e79d89bc225f067e0e3ee3e6dd53207d351b2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 10 Sep 2008 19:43:55 +0000 Subject: [PATCH 1069/1766] fix off by one index git-svn-id: http://svn.openzap.org/svn/openzap/trunk@554 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index ea39bf4285..8aeecae8d3 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -399,7 +399,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } else { uint32_t i; - for (i = 0; i < span->chan_count; i++) { + for (i = 1; i < span->chan_count; i++) { zap_set_state_locked((span->channels[i]), ZAP_CHANNEL_STATE_RESTART); } } diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index c93f254783..ced303ca4c 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -142,7 +142,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i zap_channel_t *zchan = NULL; zap_mutex_lock(signal_mutex); - for(i = 0; i <= span->chan_count; i++) { + 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) { From b645cacc11da6b4a640ec53f5e818a05e04f1db9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 10 Sep 2008 19:43:55 +0000 Subject: [PATCH 1070/1766] fix off by one index git-svn-id: http://svn.openzap.org/svn/openzap/trunk@554 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index ea39bf4285..8aeecae8d3 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -399,7 +399,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } else { uint32_t i; - for (i = 0; i < span->chan_count; i++) { + for (i = 1; i < span->chan_count; i++) { zap_set_state_locked((span->channels[i]), ZAP_CHANNEL_STATE_RESTART); } } diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index c93f254783..ced303ca4c 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -142,7 +142,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i zap_channel_t *zchan = NULL; zap_mutex_lock(signal_mutex); - for(i = 0; i <= span->chan_count; i++) { + 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) { From 02ea4b4d34a193d9522e7ff7533430c070474081 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 11 Sep 2008 17:55:27 +0000 Subject: [PATCH 1071/1766] push progress event up to mod_openzap on analog ring git-svn-id: http://svn.openzap.org/svn/openzap/trunk@555 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 9 +++++++++ libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 9a1ac3423f..ea57d85688 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1158,6 +1158,15 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } } break; + case ZAP_SIGEVENT_PROGRESS: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_ring_ready(channel); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_START: { zap_clear_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 167c230220..a17d70e85c 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -477,8 +477,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_GENRING: { + zap_sigmsg_t sig; + send_caller_id(zchan); zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + sig.event_id = ZAP_SIGEVENT_PROGRESS; + analog_data->sig_cb(&sig); + } break; case ZAP_CHANNEL_STATE_GET_CALLERID: From 7d86ac571499df24c1def83c1fcb04a7a91e59f6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 11 Sep 2008 17:55:27 +0000 Subject: [PATCH 1072/1766] push progress event up to mod_openzap on analog ring git-svn-id: http://svn.openzap.org/svn/openzap/trunk@555 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 9 +++++++++ libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9a1ac3423f..ea57d85688 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1158,6 +1158,15 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } } break; + case ZAP_SIGEVENT_PROGRESS: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_ring_ready(channel); + switch_core_session_rwunlock(session); + } + } + break; case ZAP_SIGEVENT_START: { zap_clear_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 167c230220..a17d70e85c 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -477,8 +477,18 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_GENRING: { + zap_sigmsg_t sig; + send_caller_id(zchan); zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + sig.event_id = ZAP_SIGEVENT_PROGRESS; + analog_data->sig_cb(&sig); + } break; case ZAP_CHANNEL_STATE_GET_CALLERID: From fffbcd503e987e4a9c33a62b70b5b13914cfba72 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 Sep 2008 18:39:30 +0000 Subject: [PATCH 1073/1766] protect the innocent git-svn-id: http://svn.openzap.org/svn/openzap/trunk@556 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index a17d70e85c..f6b0c75df7 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -719,6 +719,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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))) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); event->channel->ring_count = 1; @@ -785,6 +790,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } } } + + end: + if (locked) { zap_mutex_unlock(event->channel->mutex); } From 77278ca92e3cbae8bf9c33994b3be6abe93c8f62 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 Sep 2008 18:39:30 +0000 Subject: [PATCH 1074/1766] protect the innocent git-svn-id: http://svn.openzap.org/svn/openzap/trunk@556 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index a17d70e85c..f6b0c75df7 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -719,6 +719,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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))) { zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); event->channel->ring_count = 1; @@ -785,6 +790,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } } } + + end: + if (locked) { zap_mutex_unlock(event->channel->mutex); } From afe7a948bbdb396821775aef18bae987895a84fe Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 14 Sep 2008 23:31:23 +0000 Subject: [PATCH 1075/1766] blah git-svn-id: http://svn.openzap.org/svn/openzap/trunk@557 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 864b19ffd1..ddbf269b22 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -760,7 +760,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta { switch(state) { case ZAP_CHANNEL_STATE_UP: - ok = 0; + ok = 1; break; default: break; From 75943674cb3e74d2a33e6c80114250c14e620033 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 14 Sep 2008 23:31:23 +0000 Subject: [PATCH 1076/1766] blah git-svn-id: http://svn.openzap.org/svn/openzap/trunk@557 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 864b19ffd1..ddbf269b22 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -760,7 +760,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta { switch(state) { case ZAP_CHANNEL_STATE_UP: - ok = 0; + ok = 1; break; default: break; From 1ccfd032ce98242d7e628a7513dd5703732bbe00 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 16 Sep 2008 17:28:15 +0000 Subject: [PATCH 1077/1766] (OPENZAP-6) misplaced assert git-svn-id: http://svn.openzap.org/svn/openzap/trunk@558 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index f6b0c75df7..d1a6e31543 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -96,8 +96,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } analog_data = malloc(sizeof(*analog_data)); - memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); + memset(analog_data, 0, sizeof(*analog_data)); while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { From 967ff7d06f5f8bd8480562cc41ba3d6c66d2f0ae Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 16 Sep 2008 17:28:15 +0000 Subject: [PATCH 1078/1766] (OPENZAP-6) misplaced assert git-svn-id: http://svn.openzap.org/svn/openzap/trunk@558 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index f6b0c75df7..d1a6e31543 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -96,8 +96,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } analog_data = malloc(sizeof(*analog_data)); - memset(analog_data, 0, sizeof(*analog_data)); assert(analog_data != NULL); + memset(analog_data, 0, sizeof(*analog_data)); while ((var = va_arg(ap, char *))) { if (!strcasecmp(var, "tonemap")) { From a38983374b6e28d8eadf644e804ddf4572806888 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 16 Sep 2008 18:22:00 +0000 Subject: [PATCH 1079/1766] Improve logging for setups with more than one span git-svn-id: http://svn.openzap.org/svn/openzap/trunk@559 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 8aeecae8d3..3a99aae361 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1450,7 +1450,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) 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); } @@ -1508,6 +1508,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) { + zap_span_t *span = (zap_span_t *) pvt; int loglevel = ZAP_LOG_LEVEL_DEBUG; switch(level) { @@ -1535,14 +1536,15 @@ static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT s return 0; } - zap_log(__FILE__, "Q.921", __LINE__, loglevel, "%s", msg); - + zap_log("Span", "Q.921", span->span_id, loglevel, "%s", msg); return 0; } static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size) { - zap_log(__FILE__, "Q.931", __LINE__, ZAP_LOG_LEVEL_DEBUG, "%s", msg); + zap_span_t *span = (zap_span_t *) pvt; + + zap_log("Span", "Q.931", span->span_id, ZAP_LOG_LEVEL_DEBUG, "%s", msg); return 0; } From 7b99c4f95d6f686a279cc2de1636df959d682d71 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 16 Sep 2008 18:22:00 +0000 Subject: [PATCH 1080/1766] Improve logging for setups with more than one span git-svn-id: http://svn.openzap.org/svn/openzap/trunk@559 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 8aeecae8d3..3a99aae361 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1450,7 +1450,7 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) 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); } @@ -1508,6 +1508,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) { + zap_span_t *span = (zap_span_t *) pvt; int loglevel = ZAP_LOG_LEVEL_DEBUG; switch(level) { @@ -1535,14 +1536,15 @@ static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT s return 0; } - zap_log(__FILE__, "Q.921", __LINE__, loglevel, "%s", msg); - + zap_log("Span", "Q.921", span->span_id, loglevel, "%s", msg); return 0; } static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size) { - zap_log(__FILE__, "Q.931", __LINE__, ZAP_LOG_LEVEL_DEBUG, "%s", msg); + zap_span_t *span = (zap_span_t *) pvt; + + zap_log("Span", "Q.931", span->span_id, ZAP_LOG_LEVEL_DEBUG, "%s", msg); return 0; } From f0b27688c1ed385a07b01d2d9c45d2506430253c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 17 Sep 2008 01:22:24 +0000 Subject: [PATCH 1081/1766] libtool the openzap modules git-svn-id: http://svn.openzap.org/svn/openzap/trunk@560 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index a9263de5cf..73481bf8c0 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -46,12 +46,13 @@ LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) -INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost +INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" COMPILE = $(CC) $(CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ +libdir = $(PREFIX)/lib/ SOURCES=\ $(SRC)/hashtable.c \ @@ -70,8 +71,7 @@ $(SRC)/zap_dso.c BOOST_SOURCES=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ -$(SRC)/ozmod/ozmod_ss7_boost/zap_ss7_boost.c - +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c ISDN_SOURCES=\ $(SRC)/isdn/EuroISDNStateNT.c \ @@ -112,8 +112,8 @@ $(SRC)/zap_threadmutex.o \ $(SRC)/zap_dso.o BOOST_OBJS=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o - +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o ISDN_OBJS=\ $(SRC)/isdn/EuroISDNStateNT.o \ @@ -247,36 +247,35 @@ install: all uninstall: @rm -fr $(DESTDIR)$(PREFIX) -$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) -rpath $(libdir) skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) -rpath $(libdir) ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) -rpath $(libdir) wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib - +$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o + $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) + $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) From b46ce732b286882931f072f65ecec114ae247ecc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 17 Sep 2008 01:22:24 +0000 Subject: [PATCH 1082/1766] libtool the openzap modules git-svn-id: http://svn.openzap.org/svn/openzap/trunk@560 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index a9263de5cf..73481bf8c0 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -46,12 +46,13 @@ LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) -INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost +INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" COMPILE = $(CC) $(CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ +libdir = $(PREFIX)/lib/ SOURCES=\ $(SRC)/hashtable.c \ @@ -70,8 +71,7 @@ $(SRC)/zap_dso.c BOOST_SOURCES=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ -$(SRC)/ozmod/ozmod_ss7_boost/zap_ss7_boost.c - +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c ISDN_SOURCES=\ $(SRC)/isdn/EuroISDNStateNT.c \ @@ -112,8 +112,8 @@ $(SRC)/zap_threadmutex.o \ $(SRC)/zap_dso.o BOOST_OBJS=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o - +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o ISDN_OBJS=\ $(SRC)/isdn/EuroISDNStateNT.o \ @@ -247,36 +247,35 @@ install: all uninstall: @rm -fr $(DESTDIR)$(PREFIX) -$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -o $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) -rpath $(libdir) skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -o $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) -rpath $(libdir) ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c - $(CC) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -o $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) -rpath $(libdir) wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.c - $(CC) -I$(PIKA_DIR) $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_pika/ozmod_pika.c -o $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) $(PIKA_LIB) -Wl,--rpath -Wl,$(PREFIX)/lib - +$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) $(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) - $(CC) -I$(SRC)/isdn/include/ $(INCS) $(CFLAGS) -L. $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -o $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o + $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_OBJS) $(SRC)/ozmod/ozmod_analog/ozmod_analog.c - $(CC) -I$(SRC)/analog/include/ $(INCS) $(CFLAGS) -L. $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -o $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - $(CC) -I/ozmod/ozmod_ss7_boost $(INCS) $(CFLAGS) -L. $(BOOST_OBJS) $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -o $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) -shared -Wl,-x $(LIBS) $(MYLIB) -Wl,--rpath -Wl,$(PREFIX)/lib +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) + $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) From 3f4bf6f6470122bbfe9bba3f81415f01d1fb7922 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 17 Sep 2008 02:21:28 +0000 Subject: [PATCH 1083/1766] (OPENZAP-7) inital checkin of E&M support from John Wehle git-svn-id: http://svn.openzap.org/svn/openzap/trunk@561 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 6 +- libs/openzap/mod_openzap/mod_openzap.c | 97 +++ libs/openzap/src/include/zap_types.h | 9 +- .../ozmod/ozmod_analog_em/ozmod_analog_em.c | 663 ++++++++++++++++++ .../src/ozmod/ozmod_analog_em/zap_analog_em.h | 61 ++ libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 8 +- libs/openzap/src/zap_io.c | 13 +- 7 files changed, 848 insertions(+), 9 deletions(-) create mode 100644 libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c create mode 100644 libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 73481bf8c0..8c69bafe12 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -181,7 +181,7 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) #endif #endif -all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod +all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) @@ -274,6 +274,10 @@ $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozm $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) +$(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_EM_OBJS) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o $(MYLIB) -rpath $(libdir) +analog_emmod: $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN) + $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ea57d85688..8d3c39c4f3 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -417,6 +417,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: + case ZAP_CHAN_TYPE_EM: { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); @@ -806,6 +807,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: + case ZAP_CHAN_TYPE_EM: status = channel_receive_message_fxs(session, msg); break; case ZAP_CHAN_TYPE_FXO: @@ -1445,6 +1447,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: + case ZAP_CHAN_TYPE_EM: { status = on_fxo_signal(sigmsg); } @@ -1616,6 +1619,100 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "analog_em_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *context = "default"; + char *dialplan = "XML"; + char *tonegroup = NULL; + char *digit_timeout = NULL; + char *max_digits = NULL; + char *dial_regex = NULL; + char *hold_music = NULL; + char *fail_dial_regex = NULL; + uint32_t span_id = 0, to = 0, max = 0; + zap_span_t *span = NULL; + analog_option_t analog_options = ANALOG_OPTION_NONE; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { + digit_timeout = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } else if (!strcasecmp(var, "hold-music")) { + hold_music = val; + } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { + max_digits = val; + } else if (!strcasecmp(var, "enable-analog-option")) { + analog_options = enable_analog_option(val, analog_options); + } + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (digit_timeout) { + to = atoi(digit_timeout); + } + + if (max_digits) { + max = atoi(max_digits); + } + + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (zap_configure_span("analog_em", span, on_analog_signal, + "tonemap", tonegroup, + "digit_timeout", &to, + "max_dialstr", &max, + TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_set_string(SPAN_CONFIG[span->span_id].context, context); + switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan); + SPAN_CONFIG[span->span_id].analog_options = analog_options | globals.analog_options; + + if (dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); + } + + if (fail_dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); + } + + if (hold_music) { + switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); + } + switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog_em", sizeof(SPAN_CONFIG[span->span_id].type)); + zap_span_start(span); + } + } + if ((spans = switch_xml_child(cfg, "pri_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr_soft(myspan, "id"); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index f3b75bac98..dc34e3f40b 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -123,18 +123,20 @@ typedef enum { 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", "NONE" +#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", "NA" +#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 { @@ -284,10 +286,11 @@ typedef enum { ZAP_CHAN_TYPE_DQ931, ZAP_CHAN_TYPE_FXS, ZAP_CHAN_TYPE_FXO, + ZAP_CHAN_TYPE_EM, ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; -#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "INVALID" +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) typedef enum { 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 new file mode 100644 index 0000000000..a428d1f6f7 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -0,0 +1,663 @@ +/* + * Copyright (c) 2008, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributor(s): + * + * John Wehle (john@feith.com) + * + */ + +#include "openzap.h" +#include "zap_analog_em.h" + +#ifndef localtime_r +struct tm * localtime_r(const time_t *clock, struct tm *result); +#endif + +static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj); + +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; +} + + +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); +} + +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; + } + } + + + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > 20) { + max_dialstr = 11; + } + + span->start = zap_analog_em_start; + analog_data->digit_timeout = digit_timeout; + analog_data->max_dialstr = max_dialstr; + analog_data->sig_cb = sig_cb; + span->signal_type = ZAP_SIGTYPE_ANALOG; + span->signal_data = analog_data; + span->outgoing_call = analog_em_outgoing_call; + zap_span_load_tones(span, tonemap); + + return ZAP_SUCCESS; + +} + +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; +} + +static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) +{ + zap_channel_t *zchan = (zap_channel_t *) obj; + zap_buffer_t *dt_buffer = NULL; + teletone_generation_session_t ts; + uint8_t frame[1024]; + zap_size_t len, rlen; + zap_tone_type_t tt = ZAP_TONE_DTMF; + char dtmf[128] = ""; + zap_size_t dtmf_offset = 0; + zap_analog_em_data_t *analog_data = zchan->span->signal_data; + zap_channel_t *closed_chan; + uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; + zap_sigmsg_t sig; + zap_status_t status; + + zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n"); + + ts.buffer = NULL; + + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + goto done; + } + + if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!"); + zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); + goto done; + } + + if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!"); + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + goto done; + } + + zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD); + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); + ts.rate = 8000; +#if 0 + ts.debug = 1; + ts.debug_stream = stdout; +#endif + zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_buffer_set_loops(dt_buffer, -1); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + + assert(interval != 0); + + while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + zap_wait_flag_t flags = ZAP_READ; + zap_size_t dlen = 0; + + len = sizeof(frame); + + elapsed += interval; + state_counter += interval; + + if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) { + switch(zchan->state) { + case ZAP_CHANNEL_STATE_DIALING: + { + if (! zchan->needed_tones[ZAP_TONEMAP_RING] + && zap_test_flag(zchan, ZAP_CHANNEL_WINK)) { + if (zap_strlen_zero(zchan->caller_data.ani.digits)) { + zap_log(ZAP_LOG_ERROR, "No Digits to send!\n"); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + state_counter = 0; + zchan->needed_tones[ZAP_TONEMAP_RING] = 1; + zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1; + zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; + zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; + zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; + dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000; + } + } + break; + } + if (state_counter > dial_timeout) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_WINK)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + } + } + break; + case ZAP_CHANNEL_STATE_DIALTONE: + { + if (state_counter > 10000) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } + } + break; + case ZAP_CHANNEL_STATE_BUSY: + { + if (state_counter > 20000) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN); + } + } + break; + case ZAP_CHANNEL_STATE_ATTN: + { + if (state_counter > 20000) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + case ZAP_CHANNEL_STATE_HANGUP: + { + if (state_counter > 500) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && + (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE + || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + } + break; + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + { + zap_sleep(interval); + continue; + } + break; + case ZAP_CHANNEL_STATE_DOWN: + { + goto done; + } + break; + default: + break; + } + } else { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); + zap_channel_complete_state(zchan); + indicate = 0; + state_counter = 0; + + zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", + zchan->span_id, zchan->chan_id, + zap_channel_state2str(zchan->state)); + switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + { + zap_channel_use(zchan); + zap_channel_clear_needed_tones(zchan); + zap_channel_flush_dtmf(zchan); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); + } + + sig.event_id = ZAP_SIGEVENT_UP; + + analog_data->sig_cb(&sig); + continue; + } + break; + case ZAP_CHANNEL_STATE_DIALING: + { + zap_channel_use(zchan); + } + break; + case ZAP_CHANNEL_STATE_IDLE: + { + zap_channel_use(zchan); + + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number); + } else { + zap_set_string(zchan->caller_data.dnis.digits, dtmf); + } + + sig.event_id = ZAP_SIGEVENT_START; + + analog_data->sig_cb(&sig); + continue; + } + break; + case ZAP_CHANNEL_STATE_DOWN: + { + sig.event_id = ZAP_SIGEVENT_STOP; + analog_data->sig_cb(&sig); + goto done; + } + break; + case ZAP_CHANNEL_STATE_DIALTONE: + { + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + *dtmf = '\0'; + dtmf_offset = 0; + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); + indicate = 1; + + zap_sleep(25); + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); + zap_sleep(200); + zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); + zap_sleep(50); + } + break; + case ZAP_CHANNEL_STATE_RING: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]); + indicate = 1; + } + break; + case ZAP_CHANNEL_STATE_BUSY: + { + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION; + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); + indicate = 1; + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + case ZAP_CHANNEL_STATE_ATTN: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); + indicate = 1; + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + default: + break; + } + } + + + if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { + if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + + if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); + collecting = 1; + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; + sig.raw_data = dtmf; + if (analog_data->sig_cb(&sig) == ZAP_BREAK) { + collecting = 0; + } + } + } + + + if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; + collecting = 0; + } + + if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; + } + + if (!(flags & ZAP_READ)) { + continue; + } + + if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error); + goto done; + } + + if (zchan->detected_tones[0]) { + zap_sigmsg_t sig; + int i; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; + + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { + if (zchan->detected_tones[i]) { + zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id); + sig.raw_data = &i; + if (analog_data->sig_cb) { + analog_data->sig_cb(&sig); + } + } + } + + if (zchan->detected_tones[ZAP_TONEMAP_BUSY] || + zchan->detected_tones[ZAP_TONEMAP_FAIL1] || + zchan->detected_tones[ZAP_TONEMAP_FAIL2] || + zchan->detected_tones[ZAP_TONEMAP_FAIL3] || + zchan->detected_tones[ZAP_TONEMAP_ATTN] + ) { + zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n"); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + + zap_channel_clear_detected_tones(zchan); + } + + if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer))) { + rlen = len; + memset(frame, 0, len); + zap_channel_write(zchan, frame, sizeof(frame), &rlen); + continue; + } + + if (!indicate) { + continue; + } + + if (zchan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } + + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + + if (zchan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (zchan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + goto done; + } + } + + zap_channel_write(zchan, frame, sizeof(frame), &rlen); + } + + done: + + zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); + + closed_chan = zchan; + zap_channel_close(&zchan); + + zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); + + if (ts.buffer) { + teletone_destroy_session(&ts); + } + + if (dt_buffer) { + zap_buffer_destroy(&dt_buffer); + } + + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + + zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n"); + + return NULL; +} + +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; +} + +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; +} + + +static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init) +{ + return ZAP_SUCCESS; +} + +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 expandtab: + */ 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 new file mode 100644 index 0000000000..e20875d54c --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2008, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributor(s): + * + * John Wehle (john@feith.com) + * + */ + +#ifndef ZAP_ANALOG_EM_H +#define ZAP_ANALOG_EM_H +#include "openzap.h" + +typedef enum { + ZAP_ANALOG_EM_RUNNING = (1 << 0) +} zap_analog_em_flag_t; + +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 expandtab: + */ diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index a739300d1b..43a662d9fd 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -173,7 +173,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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_B) { + 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) { @@ -343,7 +343,7 @@ static ZIO_OPEN_FUNCTION(zt_open) zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); return ZAP_FAIL; } - } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { + } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_EM) { int len = zt_globals.eclevel; if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { zap_log(ZAP_LOG_WARNING, "Echo cancel not available for %d:%d\n", zchan->span_id, zchan->chan_id); @@ -636,7 +636,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_WINKFLASH: { - if (span->channels[i]->state == ZAP_CHANNEL_STATE_DOWN) { + 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; @@ -645,7 +645,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_RINGOFFHOOK: { - if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { + 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) { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index ddbf269b22..acef551eb8 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2032,7 +2032,7 @@ static zap_status_t load_config(void) zap_copy_string(number, val, sizeof(number)); } } else if (!strcasecmp(var, "analog-start-type")) { - if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO) { + if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO || span->trunk_type == ZAP_TRUNK_EM) { if ((tmp = zap_str2zap_analog_start_type(val)) != ZAP_ANALOG_START_NA) { span->start_type = tmp; zap_log(ZAP_LOG_DEBUG, "changing start type to '%s'\n", zap_analog_start_type2str(span->start_type)); @@ -2062,6 +2062,17 @@ static zap_status_t load_config(void) } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } + } else if (!strcasecmp(var, "em-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_EM; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(span->start_type)); + } + if (span->trunk_type == ZAP_TRUNK_EM) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_EM, name, number); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); + } } else if (!strcasecmp(var, "b-channel")) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); } else if (!strcasecmp(var, "d-channel")) { From 3479ce917e108c9639e06294fdaec9f99941a428 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 17 Sep 2008 02:21:28 +0000 Subject: [PATCH 1084/1766] (OPENZAP-7) inital checkin of E&M support from John Wehle git-svn-id: http://svn.openzap.org/svn/openzap/trunk@561 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 6 +- libs/freetdm/mod_openzap/mod_openzap.c | 97 +++ libs/freetdm/src/include/zap_types.h | 9 +- .../ozmod/ozmod_analog_em/ozmod_analog_em.c | 663 ++++++++++++++++++ .../src/ozmod/ozmod_analog_em/zap_analog_em.h | 61 ++ libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 8 +- libs/freetdm/src/zap_io.c | 13 +- 7 files changed, 848 insertions(+), 9 deletions(-) create mode 100644 libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c create mode 100644 libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 73481bf8c0..8c69bafe12 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -181,7 +181,7 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) #endif #endif -all: $(MYLIB) analogmod isdnmod boostmod ztmod wpmod +all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod $(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) @@ -274,6 +274,10 @@ $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozm $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) +$(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_EM_OBJS) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o + $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o $(MYLIB) -rpath $(libdir) +analog_emmod: $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN) + $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ea57d85688..8d3c39c4f3 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -417,6 +417,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: + case ZAP_CHAN_TYPE_EM: { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); @@ -806,6 +807,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: + case ZAP_CHAN_TYPE_EM: status = channel_receive_message_fxs(session, msg); break; case ZAP_CHAN_TYPE_FXO: @@ -1445,6 +1447,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: + case ZAP_CHAN_TYPE_EM: { status = on_fxo_signal(sigmsg); } @@ -1616,6 +1619,100 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "analog_em_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *context = "default"; + char *dialplan = "XML"; + char *tonegroup = NULL; + char *digit_timeout = NULL; + char *max_digits = NULL; + char *dial_regex = NULL; + char *hold_music = NULL; + char *fail_dial_regex = NULL; + uint32_t span_id = 0, to = 0, max = 0; + zap_span_t *span = NULL; + analog_option_t analog_options = ANALOG_OPTION_NONE; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { + digit_timeout = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } else if (!strcasecmp(var, "hold-music")) { + hold_music = val; + } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { + max_digits = val; + } else if (!strcasecmp(var, "enable-analog-option")) { + analog_options = enable_analog_option(val, analog_options); + } + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; + } + + span_id = atoi(id); + + if (!tonegroup) { + tonegroup = "us"; + } + + if (digit_timeout) { + to = atoi(digit_timeout); + } + + if (max_digits) { + max = atoi(max_digits); + } + + if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (zap_configure_span("analog_em", span, on_analog_signal, + "tonemap", tonegroup, + "digit_timeout", &to, + "max_dialstr", &max, + TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_set_string(SPAN_CONFIG[span->span_id].context, context); + switch_set_string(SPAN_CONFIG[span->span_id].dialplan, dialplan); + SPAN_CONFIG[span->span_id].analog_options = analog_options | globals.analog_options; + + if (dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); + } + + if (fail_dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); + } + + if (hold_music) { + switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); + } + switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog_em", sizeof(SPAN_CONFIG[span->span_id].type)); + zap_span_start(span); + } + } + if ((spans = switch_xml_child(cfg, "pri_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr_soft(myspan, "id"); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index f3b75bac98..dc34e3f40b 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -123,18 +123,20 @@ typedef enum { 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", "NONE" +#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", "NA" +#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 { @@ -284,10 +286,11 @@ typedef enum { ZAP_CHAN_TYPE_DQ931, ZAP_CHAN_TYPE_FXS, ZAP_CHAN_TYPE_FXO, + ZAP_CHAN_TYPE_EM, ZAP_CHAN_TYPE_COUNT } zap_chan_type_t; -#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "INVALID" +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) typedef enum { diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c new file mode 100644 index 0000000000..a428d1f6f7 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -0,0 +1,663 @@ +/* + * Copyright (c) 2008, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributor(s): + * + * John Wehle (john@feith.com) + * + */ + +#include "openzap.h" +#include "zap_analog_em.h" + +#ifndef localtime_r +struct tm * localtime_r(const time_t *clock, struct tm *result); +#endif + +static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj); + +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; +} + + +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); +} + +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; + } + } + + + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > 20) { + max_dialstr = 11; + } + + span->start = zap_analog_em_start; + analog_data->digit_timeout = digit_timeout; + analog_data->max_dialstr = max_dialstr; + analog_data->sig_cb = sig_cb; + span->signal_type = ZAP_SIGTYPE_ANALOG; + span->signal_data = analog_data; + span->outgoing_call = analog_em_outgoing_call; + zap_span_load_tones(span, tonemap); + + return ZAP_SUCCESS; + +} + +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; +} + +static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) +{ + zap_channel_t *zchan = (zap_channel_t *) obj; + zap_buffer_t *dt_buffer = NULL; + teletone_generation_session_t ts; + uint8_t frame[1024]; + zap_size_t len, rlen; + zap_tone_type_t tt = ZAP_TONE_DTMF; + char dtmf[128] = ""; + zap_size_t dtmf_offset = 0; + zap_analog_em_data_t *analog_data = zchan->span->signal_data; + zap_channel_t *closed_chan; + uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; + zap_sigmsg_t sig; + zap_status_t status; + + zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n"); + + ts.buffer = NULL; + + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + goto done; + } + + if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!"); + zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); + goto done; + } + + if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!"); + zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + goto done; + } + + zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD); + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); + ts.rate = 8000; +#if 0 + ts.debug = 1; + ts.debug_stream = stdout; +#endif + zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); + zap_buffer_set_loops(dt_buffer, -1); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + + assert(interval != 0); + + while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { + zap_wait_flag_t flags = ZAP_READ; + zap_size_t dlen = 0; + + len = sizeof(frame); + + elapsed += interval; + state_counter += interval; + + if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) { + switch(zchan->state) { + case ZAP_CHANNEL_STATE_DIALING: + { + if (! zchan->needed_tones[ZAP_TONEMAP_RING] + && zap_test_flag(zchan, ZAP_CHANNEL_WINK)) { + if (zap_strlen_zero(zchan->caller_data.ani.digits)) { + zap_log(ZAP_LOG_ERROR, "No Digits to send!\n"); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + state_counter = 0; + zchan->needed_tones[ZAP_TONEMAP_RING] = 1; + zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1; + zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; + zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; + zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; + dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000; + } + } + break; + } + if (state_counter > dial_timeout) { + if (!zap_test_flag(zchan, ZAP_CHANNEL_WINK)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + } + } + break; + case ZAP_CHANNEL_STATE_DIALTONE: + { + if (state_counter > 10000) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } + } + break; + case ZAP_CHANNEL_STATE_BUSY: + { + if (state_counter > 20000) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN); + } + } + break; + case ZAP_CHANNEL_STATE_ATTN: + { + if (state_counter > 20000) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + case ZAP_CHANNEL_STATE_HANGUP: + { + if (state_counter > 500) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && + (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE + || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else { + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + } + break; + case ZAP_CHANNEL_STATE_UP: + case ZAP_CHANNEL_STATE_IDLE: + { + zap_sleep(interval); + continue; + } + break; + case ZAP_CHANNEL_STATE_DOWN: + { + goto done; + } + break; + default: + break; + } + } else { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); + zap_channel_complete_state(zchan); + indicate = 0; + state_counter = 0; + + zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", + zchan->span_id, zchan->chan_id, + zap_channel_state2str(zchan->state)); + switch(zchan->state) { + case ZAP_CHANNEL_STATE_UP: + { + zap_channel_use(zchan); + zap_channel_clear_needed_tones(zchan); + zap_channel_flush_dtmf(zchan); + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); + } + + sig.event_id = ZAP_SIGEVENT_UP; + + analog_data->sig_cb(&sig); + continue; + } + break; + case ZAP_CHANNEL_STATE_DIALING: + { + zap_channel_use(zchan); + } + break; + case ZAP_CHANNEL_STATE_IDLE: + { + zap_channel_use(zchan); + + if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number); + } else { + zap_set_string(zchan->caller_data.dnis.digits, dtmf); + } + + sig.event_id = ZAP_SIGEVENT_START; + + analog_data->sig_cb(&sig); + continue; + } + break; + case ZAP_CHANNEL_STATE_DOWN: + { + sig.event_id = ZAP_SIGEVENT_STOP; + analog_data->sig_cb(&sig); + goto done; + } + break; + case ZAP_CHANNEL_STATE_DIALTONE: + { + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); + *dtmf = '\0'; + dtmf_offset = 0; + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); + indicate = 1; + + zap_sleep(25); + zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); + zap_sleep(200); + zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); + zap_sleep(50); + } + break; + case ZAP_CHANNEL_STATE_RING: + { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]); + indicate = 1; + } + break; + case ZAP_CHANNEL_STATE_BUSY: + { + zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION; + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); + indicate = 1; + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + case ZAP_CHANNEL_STATE_ATTN: + { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + zap_buffer_zero(dt_buffer); + teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); + indicate = 1; + } else { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } + } + break; + default: + break; + } + } + + + if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { + if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + + if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); + collecting = 1; + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; + sig.raw_data = dtmf; + if (analog_data->sig_cb(&sig) == ZAP_BREAK) { + collecting = 0; + } + } + } + + + if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) { + zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); + last_digit = 0; + collecting = 0; + } + + if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) { + continue; + } + + if (!(flags & ZAP_READ)) { + continue; + } + + if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error); + goto done; + } + + if (zchan->detected_tones[0]) { + zap_sigmsg_t sig; + int i; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = zchan->chan_id; + sig.span_id = zchan->span_id; + sig.channel = zchan; + sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; + + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { + if (zchan->detected_tones[i]) { + zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id); + sig.raw_data = &i; + if (analog_data->sig_cb) { + analog_data->sig_cb(&sig); + } + } + } + + if (zchan->detected_tones[ZAP_TONEMAP_BUSY] || + zchan->detected_tones[ZAP_TONEMAP_FAIL1] || + zchan->detected_tones[ZAP_TONEMAP_FAIL2] || + zchan->detected_tones[ZAP_TONEMAP_FAIL3] || + zchan->detected_tones[ZAP_TONEMAP_ATTN] + ) { + zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n"); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); + } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); + } + + zap_channel_clear_detected_tones(zchan); + } + + if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer))) { + rlen = len; + memset(frame, 0, len); + zap_channel_write(zchan, frame, sizeof(frame), &rlen); + continue; + } + + if (!indicate) { + continue; + } + + if (zchan->effective_codec != ZAP_CODEC_SLIN) { + len *= 2; + } + + rlen = zap_buffer_read_loop(dt_buffer, frame, len); + + if (zchan->effective_codec != ZAP_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (zchan->native_codec == ZAP_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); + goto done; + } + } + + zap_channel_write(zchan, frame, sizeof(frame), &rlen); + } + + done: + + zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); + + closed_chan = zchan; + zap_channel_close(&zchan); + + zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); + + if (ts.buffer) { + teletone_destroy_session(&ts); + } + + if (dt_buffer) { + zap_buffer_destroy(&dt_buffer); + } + + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + + zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n"); + + return NULL; +} + +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; +} + +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; +} + + +static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init) +{ + return ZAP_SUCCESS; +} + +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 expandtab: + */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h new file mode 100644 index 0000000000..e20875d54c --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2008, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributor(s): + * + * John Wehle (john@feith.com) + * + */ + +#ifndef ZAP_ANALOG_EM_H +#define ZAP_ANALOG_EM_H +#include "openzap.h" + +typedef enum { + ZAP_ANALOG_EM_RUNNING = (1 << 0) +} zap_analog_em_flag_t; + +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 expandtab: + */ diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index a739300d1b..43a662d9fd 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -173,7 +173,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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_B) { + 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) { @@ -343,7 +343,7 @@ static ZIO_OPEN_FUNCTION(zt_open) zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); return ZAP_FAIL; } - } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO) { + } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_EM) { int len = zt_globals.eclevel; if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { zap_log(ZAP_LOG_WARNING, "Echo cancel not available for %d:%d\n", zchan->span_id, zchan->chan_id); @@ -636,7 +636,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_WINKFLASH: { - if (span->channels[i]->state == ZAP_CHANNEL_STATE_DOWN) { + 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; @@ -645,7 +645,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_RINGOFFHOOK: { - if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { + 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) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index ddbf269b22..acef551eb8 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2032,7 +2032,7 @@ static zap_status_t load_config(void) zap_copy_string(number, val, sizeof(number)); } } else if (!strcasecmp(var, "analog-start-type")) { - if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO) { + if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO || span->trunk_type == ZAP_TRUNK_EM) { if ((tmp = zap_str2zap_analog_start_type(val)) != ZAP_ANALOG_START_NA) { span->start_type = tmp; zap_log(ZAP_LOG_DEBUG, "changing start type to '%s'\n", zap_analog_start_type2str(span->start_type)); @@ -2062,6 +2062,17 @@ static zap_status_t load_config(void) } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } + } else if (!strcasecmp(var, "em-channel")) { + if (span->trunk_type == ZAP_TRUNK_NONE) { + span->trunk_type = ZAP_TRUNK_EM; + zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), + zap_analog_start_type2str(span->start_type)); + } + if (span->trunk_type == ZAP_TRUNK_EM) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_EM, name, number); + } else { + zap_log(ZAP_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); + } } else if (!strcasecmp(var, "b-channel")) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); } else if (!strcasecmp(var, "d-channel")) { From f79ea715d7ca267b1c38882c2fbfa0d9f46d0377 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 23 Sep 2008 15:58:44 +0000 Subject: [PATCH 1085/1766] (OPENZAP-17) make # not a special char in config files now. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@562 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index f27fa04621..cce3507f25 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -157,7 +157,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } - if (((end = strchr(*var, '#')) || (end = strchr(*var, ';'))) && *(end+1) == *end) { + if ((end = strchr(*var, ';')) && *(end+1) == *end) { *end = '\0'; end--; } else if ((end = strchr(*var, '\n')) != 0) { From 35fbef437398e1c5c9e3930a334b6c5fffacb793 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 23 Sep 2008 15:58:44 +0000 Subject: [PATCH 1086/1766] (OPENZAP-17) make # not a special char in config files now. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@562 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index f27fa04621..cce3507f25 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -157,7 +157,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } - if (((end = strchr(*var, '#')) || (end = strchr(*var, ';'))) && *(end+1) == *end) { + if ((end = strchr(*var, ';')) && *(end+1) == *end) { *end = '\0'; end--; } else if ((end = strchr(*var, '\n')) != 0) { From 5eafd8d74964c319793caaa809ebdb0f373e84cf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 23 Sep 2008 16:00:26 +0000 Subject: [PATCH 1087/1766] build tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@563 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 6 ++++++ libs/openzap/src/isdn/Q921.c | 4 ++-- libs/openzap/src/isdn/Q931ie.c | 23 +++++++++++++++++++++++ libs/openzap/src/isdn/include/Q921priv.h | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 11381854aa..c0b739fc04 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -73,6 +73,12 @@ #ifndef snprintf #define snprintf _snprintf #endif +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif #undef HAVE_STRINGS_H #undef HAVE_SYS_SOCKET_H /* disable warning for zero length array in a struct */ diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index d2ed969ba9..a3e5ec3783 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -564,7 +564,7 @@ static int print_hex(char *buf, int bsize, const unsigned char *in, const int le static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2UCHAR *mes, L2INT size, const char *fmt, ...) { char buf[Q921_LOGBUFSIZE]; - L2INT len, left; + size_t len, left; va_list ap; if(!trunk->Q921LogProc) @@ -594,7 +594,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 if(trunk->loglevel == Q921_LOG_DEBUG) { char pbuf[1024]; - L2INT pleft, poffset; + size_t pleft, poffset; L2UCHAR sapi, tei, cr; L2UCHAR *pmes = mes + trunk->Q921HeaderSpace; struct Q921_Link *link; diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index c93313e973..61ffc3dcc1 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -57,6 +57,29 @@ #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 diff --git a/libs/openzap/src/isdn/include/Q921priv.h b/libs/openzap/src/isdn/include/Q921priv.h index c355e9b20d..d2d838c399 100644 --- a/libs/openzap/src/isdn/include/Q921priv.h +++ b/libs/openzap/src/isdn/include/Q921priv.h @@ -43,6 +43,29 @@ #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 */ From b36e1af380c1e91eca0d1b9acae1cc1d8d1a2efd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 23 Sep 2008 16:00:26 +0000 Subject: [PATCH 1088/1766] build tweaks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@563 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 6 ++++++ libs/freetdm/src/isdn/Q921.c | 4 ++-- libs/freetdm/src/isdn/Q931ie.c | 23 +++++++++++++++++++++++ libs/freetdm/src/isdn/include/Q921priv.h | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 11381854aa..c0b739fc04 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -73,6 +73,12 @@ #ifndef snprintf #define snprintf _snprintf #endif +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif #undef HAVE_STRINGS_H #undef HAVE_SYS_SOCKET_H /* disable warning for zero length array in a struct */ diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index d2ed969ba9..a3e5ec3783 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -564,7 +564,7 @@ static int print_hex(char *buf, int bsize, const unsigned char *in, const int le static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2UCHAR *mes, L2INT size, const char *fmt, ...) { char buf[Q921_LOGBUFSIZE]; - L2INT len, left; + size_t len, left; va_list ap; if(!trunk->Q921LogProc) @@ -594,7 +594,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 if(trunk->loglevel == Q921_LOG_DEBUG) { char pbuf[1024]; - L2INT pleft, poffset; + size_t pleft, poffset; L2UCHAR sapi, tei, cr; L2UCHAR *pmes = mes + trunk->Q921HeaderSpace; struct Q921_Link *link; diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index c93313e973..61ffc3dcc1 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -57,6 +57,29 @@ #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 diff --git a/libs/freetdm/src/isdn/include/Q921priv.h b/libs/freetdm/src/isdn/include/Q921priv.h index c355e9b20d..d2d838c399 100644 --- a/libs/freetdm/src/isdn/include/Q921priv.h +++ b/libs/freetdm/src/isdn/include/Q921priv.h @@ -43,6 +43,29 @@ #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 */ From 056a3ec2eef5a06be687b655666e8ff257e86b61 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 24 Sep 2008 21:26:44 +0000 Subject: [PATCH 1089/1766] only get real q850 cause codes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@564 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 8d3c39c4f3..25b54dc22f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -438,7 +438,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_B: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { - tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); + tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; } From 7c004d59ffe80ee0f957bbb6e106a4b7722e5a2c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 24 Sep 2008 21:26:44 +0000 Subject: [PATCH 1090/1766] only get real q850 cause codes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@564 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 8d3c39c4f3..25b54dc22f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -438,7 +438,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_B: { if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { - tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause(channel); + tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; } From cf7125c1184ef141a7cc62b323a0f1d110284357 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 15:36:34 +0000 Subject: [PATCH 1091/1766] add name to spans git-svn-id: http://svn.openzap.org/svn/openzap/trunk@565 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 25 ++++++++++++-- libs/openzap/src/include/openzap.h | 2 ++ libs/openzap/src/zap_io.c | 47 ++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 25b54dc22f..9d9b97d848 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1528,6 +1528,7 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -1539,7 +1540,8 @@ static switch_status_t load_config(void) uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; - + zap_status_t zstatus = ZAP_FAIL; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1570,7 +1572,7 @@ static switch_status_t load_config(void) continue; } - span_id = atoi(id); + if (!tonegroup) { tonegroup = "us"; @@ -1584,10 +1586,27 @@ static switch_status_t load_config(void) max = atoi(max_digits); } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } + + if (!span_id) { + span_id = span->span_id; + } if (zap_configure_span("analog", span, on_analog_signal, "tonemap", tonegroup, diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index c0b739fc04..efe0de3ecf 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -466,6 +466,7 @@ struct zap_analog_data { struct zap_span { zap_data_type_t data_type; + char *name; uint32_t span_id; uint32_t chan_count; uint32_t active_count; @@ -592,6 +593,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c zap_status_t zap_span_start(zap_span_t *span); int zap_load_module(const char *name); int zap_load_module_assume(const char *name); +zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index acef551eb8..ae21e578ec 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -76,6 +76,7 @@ zap_time_t zap_current_time_in_ms(void) static struct { zap_hash_t *interface_hash; zap_hash_t *module_hash; + zap_hash_t *span_hash; zap_mutex_t *mutex; struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1]; uint32_t span_index; @@ -460,6 +461,19 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } +zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span) +{ + zap_status_t status = ZAP_FAIL; + + zap_mutex_lock(globals.mutex); + if (!zap_strlen_zero(name) && (*span = hashtable_search(globals.span_hash, (void *)name))) { + status = ZAP_SUCCESS; + } + zap_mutex_unlock(globals.mutex); + + return status; +} + zap_status_t zap_span_find(uint32_t id, zap_span_t **span) { zap_span_t *fspan; @@ -1965,10 +1979,12 @@ static zap_status_t load_config(void) if (!strncasecmp(cfg.category, "span", 4)) { if (cfg.catno != catno) { char *type = cfg.category + 4; + char *name; + if (*type == ' ') { type++; } - + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; @@ -1977,7 +1993,9 @@ static zap_status_t load_config(void) span = NULL; continue; } - + + name = strchr(type, ' '); + zap_mutex_lock(globals.mutex); if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { zap_load_module_assume(type); @@ -2001,8 +2019,25 @@ static zap_status_t load_config(void) if (zap_span_create(zio, &span) == ZAP_SUCCESS) { span->type = strdup(type); - zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); d = 0; + + zap_mutex_lock(globals.mutex); + if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { + zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", span->span_id); + name = NULL; + } + + if (!name) { + char buf[128] = ""; + snprintf(buf, sizeof(buf), "span%d", span->span_id); + name = buf; + } + span->name = strdup(name); + hashtable_insert(globals.span_hash, (void *)span->name, span); + zap_mutex_unlock(globals.mutex); + + zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); + } else { zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); span = NULL; @@ -2342,6 +2377,7 @@ zap_status_t zap_global_init(void) memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); @@ -2397,7 +2433,11 @@ zap_status_t zap_global_destroy(void) zap_safe_free(cur_span->signal_data); zap_span_destroy(cur_span); } + zap_mutex_lock(globals.mutex); + hashtable_remove(globals.span_hash, (void *)cur_span->name); + zap_mutex_unlock(globals.mutex); zap_safe_free(cur_span->type); + zap_safe_free(cur_span->name); free(cur_span); cur_span = NULL; } @@ -2409,6 +2449,7 @@ zap_status_t zap_global_destroy(void) zap_mutex_lock(globals.mutex); hashtable_destroy(globals.interface_hash, 0, 0); hashtable_destroy(globals.module_hash, 0, 0); + hashtable_destroy(globals.span_hash, 0, 0); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); From a3922ed7c8d0659a4b110bb4ebcfc02900a10377 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 15:36:34 +0000 Subject: [PATCH 1092/1766] add name to spans git-svn-id: http://svn.openzap.org/svn/openzap/trunk@565 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 25 ++++++++++++-- libs/freetdm/src/include/openzap.h | 2 ++ libs/freetdm/src/zap_io.c | 47 ++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 25b54dc22f..9d9b97d848 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1528,6 +1528,7 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -1539,7 +1540,8 @@ static switch_status_t load_config(void) uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; - + zap_status_t zstatus = ZAP_FAIL; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1570,7 +1572,7 @@ static switch_status_t load_config(void) continue; } - span_id = atoi(id); + if (!tonegroup) { tonegroup = "us"; @@ -1584,10 +1586,27 @@ static switch_status_t load_config(void) max = atoi(max_digits); } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } + + if (!span_id) { + span_id = span->span_id; + } if (zap_configure_span("analog", span, on_analog_signal, "tonemap", tonegroup, diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index c0b739fc04..efe0de3ecf 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -466,6 +466,7 @@ struct zap_analog_data { struct zap_span { zap_data_type_t data_type; + char *name; uint32_t span_id; uint32_t chan_count; uint32_t active_count; @@ -592,6 +593,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c zap_status_t zap_span_start(zap_span_t *span); int zap_load_module(const char *name); int zap_load_module_assume(const char *name); +zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index acef551eb8..ae21e578ec 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -76,6 +76,7 @@ zap_time_t zap_current_time_in_ms(void) static struct { zap_hash_t *interface_hash; zap_hash_t *module_hash; + zap_hash_t *span_hash; zap_mutex_t *mutex; struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1]; uint32_t span_index; @@ -460,6 +461,19 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } +zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span) +{ + zap_status_t status = ZAP_FAIL; + + zap_mutex_lock(globals.mutex); + if (!zap_strlen_zero(name) && (*span = hashtable_search(globals.span_hash, (void *)name))) { + status = ZAP_SUCCESS; + } + zap_mutex_unlock(globals.mutex); + + return status; +} + zap_status_t zap_span_find(uint32_t id, zap_span_t **span) { zap_span_t *fspan; @@ -1965,10 +1979,12 @@ static zap_status_t load_config(void) if (!strncasecmp(cfg.category, "span", 4)) { if (cfg.catno != catno) { char *type = cfg.category + 4; + char *name; + if (*type == ' ') { type++; } - + zap_log(ZAP_LOG_DEBUG, "found config for span\n"); catno = cfg.catno; @@ -1977,7 +1993,9 @@ static zap_status_t load_config(void) span = NULL; continue; } - + + name = strchr(type, ' '); + zap_mutex_lock(globals.mutex); if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { zap_load_module_assume(type); @@ -2001,8 +2019,25 @@ static zap_status_t load_config(void) if (zap_span_create(zio, &span) == ZAP_SUCCESS) { span->type = strdup(type); - zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); d = 0; + + zap_mutex_lock(globals.mutex); + if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { + zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", span->span_id); + name = NULL; + } + + if (!name) { + char buf[128] = ""; + snprintf(buf, sizeof(buf), "span%d", span->span_id); + name = buf; + } + span->name = strdup(name); + hashtable_insert(globals.span_hash, (void *)span->name, span); + zap_mutex_unlock(globals.mutex); + + zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); + } else { zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); span = NULL; @@ -2342,6 +2377,7 @@ zap_status_t zap_global_init(void) memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); @@ -2397,7 +2433,11 @@ zap_status_t zap_global_destroy(void) zap_safe_free(cur_span->signal_data); zap_span_destroy(cur_span); } + zap_mutex_lock(globals.mutex); + hashtable_remove(globals.span_hash, (void *)cur_span->name); + zap_mutex_unlock(globals.mutex); zap_safe_free(cur_span->type); + zap_safe_free(cur_span->name); free(cur_span); cur_span = NULL; } @@ -2409,6 +2449,7 @@ zap_status_t zap_global_destroy(void) zap_mutex_lock(globals.mutex); hashtable_destroy(globals.interface_hash, 0, 0); hashtable_destroy(globals.module_hash, 0, 0); + hashtable_destroy(globals.span_hash, 0, 0); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); From dfc4c3533ead6836d3b952fee86316abec1e1760 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 16:39:46 +0000 Subject: [PATCH 1093/1766] change hash to use flags per entry for free on keys and values git-svn-id: http://svn.openzap.org/svn/openzap/trunk@566 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/hashtable.c | 11 +++++++---- libs/openzap/src/include/hashtable.h | 11 +++++++++-- libs/openzap/src/include/hashtable_private.h | 1 + libs/openzap/src/zap_io.c | 12 ++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index 8e252339a2..bc5d76475b 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -134,7 +134,7 @@ hashtable_count(struct hashtable *h) /*****************************************************************************/ int -hashtable_insert(struct hashtable *h, void *k, void *v) +hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) { /* This method allows duplicate keys - but they shouldn't be used */ unsigned int index; @@ -153,6 +153,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) index = indexFor(h->tablelength,e->h); e->k = k; e->v = v; + e->flags = flags; e->next = h->table[index]; h->table[index] = e; return -1; @@ -200,7 +201,9 @@ hashtable_remove(struct hashtable *h, void *k) *pE = e->next; h->entrycount--; v = e->v; - freekey(e->k); + if (e->flags & HASHTABLE_FLAG_FREE_KEY) { + freekey(e->k); + } free(e); return v; } @@ -213,7 +216,7 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ void -hashtable_destroy(struct hashtable *h, int free_keys, int free_values) +hashtable_destroy(struct hashtable *h) { unsigned int i; struct entry *e, *f; @@ -223,7 +226,7 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values) { e = table[i]; while (NULL != e) - { f = e; e = e->next; if (free_keys) freekey(f->k); if (free_values) free(f->v); free(f); } + { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) free(f->v); free(f); } } free(h->table); diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index 243441c1d4..137e9460e6 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -101,8 +101,15 @@ create_hashtable(unsigned int minsize, * If in doubt, remove before insert. */ + +typedef enum { + HASHTABLE_FLAG_NONE = 0, + HASHTABLE_FLAG_FREE_KEY = (1 << 0), + HASHTABLE_FLAG_FREE_VALUE = (1 << 1) +} hashtable_flag_t; + int -hashtable_insert(struct hashtable *h, void *k, void *v); +hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); #define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ int fnname (struct hashtable *h, keytype *k, valuetype *v) \ @@ -167,7 +174,7 @@ hashtable_count(struct hashtable *h); */ void -hashtable_destroy(struct hashtable *h, int free_keys, int free_values); +hashtable_destroy(struct hashtable *h); struct hashtable_iterator *hashtable_first(struct hashtable *h); struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i); diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index 81197e6cb3..0a20c214fd 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -12,6 +12,7 @@ struct entry { void *k, *v; unsigned int h; + hashtable_flag_t flags; struct entry *next; }; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index ae21e578ec..9b69349925 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2033,7 +2033,7 @@ static zap_status_t load_config(void) name = buf; } span->name = strdup(name); - hashtable_insert(globals.span_hash, (void *)span->name, span); + hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); zap_mutex_unlock(globals.mutex); zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); @@ -2212,7 +2212,7 @@ int zap_load_module(const char *name) if (hashtable_search(globals.interface_hash, (void *)interface->name)) { zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); } else { - hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + hashtable_insert(globals.interface_hash, (void *)interface->name, interface, HASHTABLE_FLAG_NONE); process_module_config(interface); x++; } @@ -2245,7 +2245,7 @@ int zap_load_module(const char *name) zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); zap_dso_destroy(&lib); } else { - hashtable_insert(globals.module_hash, (void *)mod->name, mod); + hashtable_insert(globals.module_hash, (void *)mod->name, mod, HASHTABLE_FLAG_NONE); count++; } zap_mutex_unlock(globals.mutex); @@ -2447,9 +2447,9 @@ zap_status_t zap_global_destroy(void) zap_unload_modules(); zap_mutex_lock(globals.mutex); - hashtable_destroy(globals.interface_hash, 0, 0); - hashtable_destroy(globals.module_hash, 0, 0); - hashtable_destroy(globals.span_hash, 0, 0); + hashtable_destroy(globals.interface_hash); + hashtable_destroy(globals.module_hash); + hashtable_destroy(globals.span_hash); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); From 8811a8d02e4af1931fdf2ff2f918babbfc217211 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 16:39:46 +0000 Subject: [PATCH 1094/1766] change hash to use flags per entry for free on keys and values git-svn-id: http://svn.openzap.org/svn/openzap/trunk@566 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/hashtable.c | 11 +++++++---- libs/freetdm/src/include/hashtable.h | 11 +++++++++-- libs/freetdm/src/include/hashtable_private.h | 1 + libs/freetdm/src/zap_io.c | 12 ++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 8e252339a2..bc5d76475b 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -134,7 +134,7 @@ hashtable_count(struct hashtable *h) /*****************************************************************************/ int -hashtable_insert(struct hashtable *h, void *k, void *v) +hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) { /* This method allows duplicate keys - but they shouldn't be used */ unsigned int index; @@ -153,6 +153,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) index = indexFor(h->tablelength,e->h); e->k = k; e->v = v; + e->flags = flags; e->next = h->table[index]; h->table[index] = e; return -1; @@ -200,7 +201,9 @@ hashtable_remove(struct hashtable *h, void *k) *pE = e->next; h->entrycount--; v = e->v; - freekey(e->k); + if (e->flags & HASHTABLE_FLAG_FREE_KEY) { + freekey(e->k); + } free(e); return v; } @@ -213,7 +216,7 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ void -hashtable_destroy(struct hashtable *h, int free_keys, int free_values) +hashtable_destroy(struct hashtable *h) { unsigned int i; struct entry *e, *f; @@ -223,7 +226,7 @@ hashtable_destroy(struct hashtable *h, int free_keys, int free_values) { e = table[i]; while (NULL != e) - { f = e; e = e->next; if (free_keys) freekey(f->k); if (free_values) free(f->v); free(f); } + { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) free(f->v); free(f); } } free(h->table); diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 243441c1d4..137e9460e6 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -101,8 +101,15 @@ create_hashtable(unsigned int minsize, * If in doubt, remove before insert. */ + +typedef enum { + HASHTABLE_FLAG_NONE = 0, + HASHTABLE_FLAG_FREE_KEY = (1 << 0), + HASHTABLE_FLAG_FREE_VALUE = (1 << 1) +} hashtable_flag_t; + int -hashtable_insert(struct hashtable *h, void *k, void *v); +hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); #define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ int fnname (struct hashtable *h, keytype *k, valuetype *v) \ @@ -167,7 +174,7 @@ hashtable_count(struct hashtable *h); */ void -hashtable_destroy(struct hashtable *h, int free_keys, int free_values); +hashtable_destroy(struct hashtable *h); struct hashtable_iterator *hashtable_first(struct hashtable *h); struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i); diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index 81197e6cb3..0a20c214fd 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -12,6 +12,7 @@ struct entry { void *k, *v; unsigned int h; + hashtable_flag_t flags; struct entry *next; }; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index ae21e578ec..9b69349925 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2033,7 +2033,7 @@ static zap_status_t load_config(void) name = buf; } span->name = strdup(name); - hashtable_insert(globals.span_hash, (void *)span->name, span); + hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); zap_mutex_unlock(globals.mutex); zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); @@ -2212,7 +2212,7 @@ int zap_load_module(const char *name) if (hashtable_search(globals.interface_hash, (void *)interface->name)) { zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); } else { - hashtable_insert(globals.interface_hash, (void *)interface->name, interface); + hashtable_insert(globals.interface_hash, (void *)interface->name, interface, HASHTABLE_FLAG_NONE); process_module_config(interface); x++; } @@ -2245,7 +2245,7 @@ int zap_load_module(const char *name) zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); zap_dso_destroy(&lib); } else { - hashtable_insert(globals.module_hash, (void *)mod->name, mod); + hashtable_insert(globals.module_hash, (void *)mod->name, mod, HASHTABLE_FLAG_NONE); count++; } zap_mutex_unlock(globals.mutex); @@ -2447,9 +2447,9 @@ zap_status_t zap_global_destroy(void) zap_unload_modules(); zap_mutex_lock(globals.mutex); - hashtable_destroy(globals.interface_hash, 0, 0); - hashtable_destroy(globals.module_hash, 0, 0); - hashtable_destroy(globals.span_hash, 0, 0); + hashtable_destroy(globals.interface_hash); + hashtable_destroy(globals.module_hash); + hashtable_destroy(globals.span_hash); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); From d79352b29cba2ab342ce95bc4c54162b690feda6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 16:59:13 +0000 Subject: [PATCH 1095/1766] doh blame normB git-svn-id: http://svn.openzap.org/svn/openzap/trunk@567 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 9b69349925..0cbef9f8ab 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1994,7 +1994,9 @@ static zap_status_t load_config(void) continue; } - name = strchr(type, ' '); + if ((name = strchr(type, ' '))) { + *name++ = '\0'; + } zap_mutex_lock(globals.mutex); if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { From 3c2e49bd7102dca3fa3ab07d726f527a8c2d8598 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 16:59:13 +0000 Subject: [PATCH 1096/1766] doh blame normB git-svn-id: http://svn.openzap.org/svn/openzap/trunk@567 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 9b69349925..0cbef9f8ab 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1994,7 +1994,9 @@ static zap_status_t load_config(void) continue; } - name = strchr(type, ' '); + if ((name = strchr(type, ' '))) { + *name++ = '\0'; + } zap_mutex_lock(globals.mutex); if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { From 18abfac3173c339842ceeacca1ec7fae68ef5be5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 17:09:10 +0000 Subject: [PATCH 1097/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@568 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 101 ++++++++++++++++++++----- 1 file changed, 80 insertions(+), 21 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 9d9b97d848..e434b01933 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -788,7 +788,11 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio } break; case SWITCH_MESSAGE_INDICATE_RINGING: - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + if (!(switch_channel_test_flag(channel, CF_OUTBOUND) || + switch_channel_test_flag(channel, CF_ANSWERED) || + switch_channel_test_flag(channel, CF_EARLY_MEDIA))) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + } break; default: break; @@ -1527,8 +1531,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -1540,7 +1545,6 @@ static switch_status_t load_config(void) uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; - zap_status_t zstatus = ZAP_FAIL; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1567,7 +1571,7 @@ static switch_status_t load_config(void) } } - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } @@ -1640,7 +1644,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_em_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -1678,12 +1684,11 @@ static switch_status_t load_config(void) } } - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } - span_id = atoi(id); if (!tonegroup) { tonegroup = "us"; @@ -1697,10 +1702,29 @@ static switch_status_t load_config(void) max = atoi(max_digits); } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } + + if (!span_id) { + span_id = span->span_id; + } + if (zap_configure_span("analog_em", span, on_analog_signal, "tonemap", tonegroup, @@ -1734,7 +1758,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "pri_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; //Q921NetUser_t mode = Q931_TE; @@ -1764,23 +1790,39 @@ static switch_status_t load_config(void) dialplan = val; } } + - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } - span_id = atoi(id); + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (!span_id) { + span_id = span->span_id; + } if (!tonegroup) { tonegroup = "us"; } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); - continue; - } - if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, @@ -1800,7 +1842,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "boost_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; uint32_t span_id = 0; @@ -1832,21 +1876,36 @@ static switch_status_t load_config(void) } } - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); continue; } - span_id = atoi(id); - if (!tonegroup) { tonegroup = "us"; } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } + + if (!span_id) { + span_id = span->span_id; + } if (zap_configure_span("ss7_boost", span, on_clear_channel_signal, "local_ip", local_ip, From e403a7952f0556af7be38ff3dd035f3aec654c92 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 17:09:10 +0000 Subject: [PATCH 1098/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@568 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 101 ++++++++++++++++++++----- 1 file changed, 80 insertions(+), 21 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9d9b97d848..e434b01933 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -788,7 +788,11 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio } break; case SWITCH_MESSAGE_INDICATE_RINGING: - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + if (!(switch_channel_test_flag(channel, CF_OUTBOUND) || + switch_channel_test_flag(channel, CF_ANSWERED) || + switch_channel_test_flag(channel, CF_EARLY_MEDIA))) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + } break; default: break; @@ -1527,8 +1531,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -1540,7 +1545,6 @@ static switch_status_t load_config(void) uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; - zap_status_t zstatus = ZAP_FAIL; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1567,7 +1571,7 @@ static switch_status_t load_config(void) } } - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } @@ -1640,7 +1644,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "analog_em_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; char *tonegroup = NULL; @@ -1678,12 +1684,11 @@ static switch_status_t load_config(void) } } - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } - span_id = atoi(id); if (!tonegroup) { tonegroup = "us"; @@ -1697,10 +1702,29 @@ static switch_status_t load_config(void) max = atoi(max_digits); } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } + + if (!span_id) { + span_id = span->span_id; + } + if (zap_configure_span("analog_em", span, on_analog_signal, "tonemap", tonegroup, @@ -1734,7 +1758,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "pri_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; //Q921NetUser_t mode = Q931_TE; @@ -1764,23 +1790,39 @@ static switch_status_t load_config(void) dialplan = val; } } + - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } - span_id = atoi(id); + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + continue; + } + + if (!span_id) { + span_id = span->span_id; + } if (!tonegroup) { tonegroup = "us"; } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); - continue; - } - if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, @@ -1800,7 +1842,9 @@ static switch_status_t load_config(void) if ((spans = switch_xml_child(cfg, "boost_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr_soft(myspan, "id"); + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; char *context = "default"; char *dialplan = "XML"; uint32_t span_id = 0; @@ -1832,21 +1876,36 @@ static switch_status_t load_config(void) } } - if (!id) { + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); continue; } - span_id = atoi(id); - if (!tonegroup) { tonegroup = "us"; } - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; } + + if (!span_id) { + span_id = span->span_id; + } if (zap_configure_span("ss7_boost", span, on_clear_channel_signal, "local_ip", local_ip, From 2dd27f27381abe5edd6503ddeb3bbb3aedab9054 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 17:29:48 +0000 Subject: [PATCH 1099/1766] fix analog fxs state machine issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@569 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 +++++++++++------ libs/openzap/src/zap_io.c | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index e434b01933..2aaa3296cf 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -779,19 +779,24 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); - } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + switch_channel_mark_answered(channel); } break; case SWITCH_MESSAGE_INDICATE_RINGING: - if (!(switch_channel_test_flag(channel, CF_OUTBOUND) || - switch_channel_test_flag(channel, CF_ANSWERED) || - switch_channel_test_flag(channel, CF_EARLY_MEDIA))) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + + if (!switch_channel_test_flag(channel, CF_ANSWERED) && + !switch_channel_test_flag(channel, CF_EARLY_MEDIA) && + !switch_channel_test_flag(channel, CF_RING_READY) + ) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + switch_channel_mark_ring_ready(channel); + } } break; default: diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 0cbef9f8ab..6a8045c02a 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -733,6 +733,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_PROGRESS: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case ZAP_CHANNEL_STATE_RING: ok = 0; break; default: From 36abcdd03d7adc9c3d9a97414fa2990af4910656 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 26 Sep 2008 17:29:48 +0000 Subject: [PATCH 1100/1766] fix analog fxs state machine issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@569 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 17 +++++++++++------ libs/freetdm/src/zap_io.c | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index e434b01933..2aaa3296cf 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -779,19 +779,24 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: - if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); - } else { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + switch_channel_mark_answered(channel); } break; case SWITCH_MESSAGE_INDICATE_RINGING: - if (!(switch_channel_test_flag(channel, CF_OUTBOUND) || - switch_channel_test_flag(channel, CF_ANSWERED) || - switch_channel_test_flag(channel, CF_EARLY_MEDIA))) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + + if (!switch_channel_test_flag(channel, CF_ANSWERED) && + !switch_channel_test_flag(channel, CF_EARLY_MEDIA) && + !switch_channel_test_flag(channel, CF_RING_READY) + ) { + zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + switch_channel_mark_ring_ready(channel); + } } break; default: diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 0cbef9f8ab..6a8045c02a 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -733,6 +733,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_PROGRESS: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case ZAP_CHANNEL_STATE_RING: ok = 0; break; default: From 0fefb95b07183c989210c0cb257a3a27e24c04b0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 26 Sep 2008 18:28:28 +0000 Subject: [PATCH 1101/1766] OPENZAP-19 add handler for connect ack git-svn-id: http://svn.openzap.org/svn/openzap/trunk@570 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 3a99aae361..a9170d0d2b 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -696,6 +696,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } 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: { From c7cbbc6f4e9d146d82ebe5427c6f54c888377bac Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 26 Sep 2008 18:28:28 +0000 Subject: [PATCH 1102/1766] OPENZAP-19 add handler for connect ack git-svn-id: http://svn.openzap.org/svn/openzap/trunk@570 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 3a99aae361..a9170d0d2b 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -696,6 +696,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } } 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: { From b89f93c049bf765c524292eb5faebb30805428bf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 26 Sep 2008 20:04:22 +0000 Subject: [PATCH 1103/1766] add dtmf based hangup (OPENZAP-3) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@571 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 3 +++ libs/openzap/src/zap_io.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index efe0de3ecf..0cdb98f834 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -426,6 +426,7 @@ struct zap_channel { zap_buffer_t *fsk_buffer; uint32_t dtmf_on; uint32_t dtmf_off; + char *dtmf_hangup_buf; teletone_generation_session_t tone_session; zap_time_t last_event_time; zap_time_t ring_time; @@ -489,6 +490,8 @@ struct zap_span { zap_span_start_t start; void *mod_data; char *type; + char *dtmf_hangup; + size_t dtmf_hangup_len; int suggest_chan_id; zap_state_map_t *state_map; }; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6a8045c02a..ebbd7a6e89 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -222,6 +222,7 @@ static zap_status_t zap_span_destroy(zap_span_t *span) zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); status = span->zio->span_destroy(span); zap_safe_free(span->type); + zap_safe_free(span->dtmf_hangup); } return status; @@ -241,6 +242,8 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + zap_safe_free(zchan->dtmf_hangup_buf); + if (zchan->tone_session.buffer) { teletone_destroy_session(&zchan->tone_session); memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); @@ -453,6 +456,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -965,6 +970,8 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; } + memset(zchan->dtmf_hangup_buf, '\0', zchan->span->dtmf_hangup_len); + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { zchan->effective_codec = zchan->native_codec; zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); @@ -1656,6 +1663,18 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) zap_buffer_toss(zchan->digit_buffer, strlen(dtmf)); } + if (zchan->span->dtmf_hangup_len) { + for (p = dtmf; zap_is_dtmf(*p); p++) { + memmove (zchan->dtmf_hangup_buf, zchan->dtmf_hangup_buf + 1, zchan->span->dtmf_hangup_len - 1); + zchan->dtmf_hangup_buf[zchan->span->dtmf_hangup_len - 1] = *p; + if (!strcmp(zchan->dtmf_hangup_buf, zchan->span->dtmf_hangup)) { + zap_log(ZAP_LOG_DEBUG, "DTMF hangup detected.\n"); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + break; + } + } + } + p = dtmf; while (wr < len && p) { if (zap_is_dtmf(*p)) { @@ -2127,6 +2146,9 @@ static zap_status_t load_config(void) configured += zio->configure_span(span, val, qtype, name, number); d++; } + } else if (!strcasecmp(var, "dtmf_hangup")) { + span->dtmf_hangup = strdup(val); + span->dtmf_hangup_len = strlen(val); } } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); From 21d796b63e267365c9fa1bb8e7f455fcc9f40b9d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 26 Sep 2008 20:04:22 +0000 Subject: [PATCH 1104/1766] add dtmf based hangup (OPENZAP-3) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@571 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 3 +++ libs/freetdm/src/zap_io.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index efe0de3ecf..0cdb98f834 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -426,6 +426,7 @@ struct zap_channel { zap_buffer_t *fsk_buffer; uint32_t dtmf_on; uint32_t dtmf_off; + char *dtmf_hangup_buf; teletone_generation_session_t tone_session; zap_time_t last_event_time; zap_time_t ring_time; @@ -489,6 +490,8 @@ struct zap_span { zap_span_start_t start; void *mod_data; char *type; + char *dtmf_hangup; + size_t dtmf_hangup_len; int suggest_chan_id; zap_state_map_t *state_map; }; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6a8045c02a..ebbd7a6e89 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -222,6 +222,7 @@ static zap_status_t zap_span_destroy(zap_span_t *span) zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); status = span->zio->span_destroy(span); zap_safe_free(span->type); + zap_safe_free(span->dtmf_hangup); } return status; @@ -241,6 +242,8 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + zap_safe_free(zchan->dtmf_hangup_buf); + if (zchan->tone_session.buffer) { teletone_destroy_session(&zchan->tone_session); memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); @@ -453,6 +456,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -965,6 +970,8 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zchan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; } + memset(zchan->dtmf_hangup_buf, '\0', zchan->span->dtmf_hangup_len); + if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { zchan->effective_codec = zchan->native_codec; zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); @@ -1656,6 +1663,18 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) zap_buffer_toss(zchan->digit_buffer, strlen(dtmf)); } + if (zchan->span->dtmf_hangup_len) { + for (p = dtmf; zap_is_dtmf(*p); p++) { + memmove (zchan->dtmf_hangup_buf, zchan->dtmf_hangup_buf + 1, zchan->span->dtmf_hangup_len - 1); + zchan->dtmf_hangup_buf[zchan->span->dtmf_hangup_len - 1] = *p; + if (!strcmp(zchan->dtmf_hangup_buf, zchan->span->dtmf_hangup)) { + zap_log(ZAP_LOG_DEBUG, "DTMF hangup detected.\n"); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + break; + } + } + } + p = dtmf; while (wr < len && p) { if (zap_is_dtmf(*p)) { @@ -2127,6 +2146,9 @@ static zap_status_t load_config(void) configured += zio->configure_span(span, val, qtype, name, number); d++; } + } else if (!strcasecmp(var, "dtmf_hangup")) { + span->dtmf_hangup = strdup(val); + span->dtmf_hangup_len = strlen(val); } } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); From 7b3195511a69ed88b85e645834b6a5532677d0ce Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 27 Sep 2008 18:46:22 +0000 Subject: [PATCH 1105/1766] (OPENZAP-21) E&M shouldn't have delay after sending wink git-svn-id: http://svn.openzap.org/svn/openzap/trunk@572 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 1 - 1 file changed, 1 deletion(-) 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 index a428d1f6f7..ed7f04b903 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -361,7 +361,6 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); zap_sleep(200); zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); - zap_sleep(50); } break; case ZAP_CHANNEL_STATE_RING: From bff3651b2dc9c2d3ddfd83f425ea071c41302a79 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 27 Sep 2008 18:46:22 +0000 Subject: [PATCH 1106/1766] (OPENZAP-21) E&M shouldn't have delay after sending wink git-svn-id: http://svn.openzap.org/svn/openzap/trunk@572 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index a428d1f6f7..ed7f04b903 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -361,7 +361,6 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); zap_sleep(200); zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); - zap_sleep(50); } break; case ZAP_CHANNEL_STATE_RING: From f91b93dc43d9e5d0ea2d490cca951969c7af0267 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 29 Sep 2008 15:51:00 +0000 Subject: [PATCH 1107/1766] fix unclean reset from i/o error and add new span wide option to disable callerid detect git-svn-id: http://svn.openzap.org/svn/openzap/trunk@573 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/openzap.conf.xml | 1 + libs/openzap/mod_openzap/mod_openzap.c | 5 ++++ libs/openzap/src/include/openzap.h | 7 ------ .../src/ozmod/ozmod_analog/ozmod_analog.c | 25 ++++++++++++++++--- .../src/ozmod/ozmod_analog/zap_analog.h | 13 +++++++++- .../src/ozmod/ozmod_analog_em/zap_analog_em.h | 8 ++++++ 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/libs/openzap/conf/openzap.conf.xml b/libs/openzap/conf/openzap.conf.xml index 1ca75c0e21..8326505177 100644 --- a/libs/openzap/conf/openzap.conf.xml +++ b/libs/openzap/conf/openzap.conf.xml @@ -16,6 +16,7 @@ + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 2aaa3296cf..18064e6486 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1547,6 +1547,8 @@ static switch_status_t load_config(void) char *dial_regex = NULL; char *hold_music = NULL; char *fail_dial_regex = NULL; + char *enable_callerid = "true"; + uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; @@ -1565,6 +1567,8 @@ static switch_status_t load_config(void) dialplan = val; } else if (!strcasecmp(var, "dial-regex")) { dial_regex = val; + } else if (!strcasecmp(var, "enable-callerid")) { + enable_callerid = val; } else if (!strcasecmp(var, "fail-dial-regex")) { fail_dial_regex = val; } else if (!strcasecmp(var, "hold-music")) { @@ -1621,6 +1625,7 @@ static switch_status_t load_config(void) "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, + "enable_callerid", enable_callerid, TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 0cdb98f834..4b705b0b74 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -458,13 +458,6 @@ struct zap_sigmsg { }; -struct zap_analog_data { - uint32_t flags; - uint32_t max_dialstr; - uint32_t digit_timeout; - zio_signal_cb_t sig_cb; -}; - struct zap_span { zap_data_type_t data_type; char *name; diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index d1a6e31543..d6e2f5bb35 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -87,6 +87,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) uint32_t max_dialstr = 11; const char *var, *val; int *intval; + uint32_t flags = ZAP_ANALOG_CALLERID; assert(sig_cb != NULL); @@ -110,6 +111,16 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) 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; @@ -128,6 +139,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } span->start = zap_analog_start; + analog_data->flags = flags; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; analog_data->sig_cb = sig_cb; @@ -691,9 +703,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_destroy(&dt_buffer); } - zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + if (zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", zchan->span_id, zchan->chan_id); + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); return NULL; } @@ -725,7 +740,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even goto end; } if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); + 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; diff --git a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h index 2d90910244..16b7d4f09a 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h @@ -36,9 +36,20 @@ #include "openzap.h" typedef enum { - ZAP_ANALOG_RUNNING = (1 << 0) + ZAP_ANALOG_RUNNING = (1 << 0), + ZAP_ANALOG_CALLERID = (1 << 1) } zap_analog_flag_t; + +struct zap_analog_data { + uint32_t flags; + uint32_t max_dialstr; + uint32_t digit_timeout; + zio_signal_cb_t sig_cb; +}; + + + static void *zap_analog_run(zap_thread_t *me, void *obj); typedef struct zap_analog_data zap_analog_data_t; 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 index e20875d54c..9411844c44 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -44,6 +44,14 @@ 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; + zio_signal_cb_t sig_cb; +}; + static void *zap_analog_em_run(zap_thread_t *me, void *obj); typedef struct zap_analog_data zap_analog_em_data_t; From 26b368810e11615cd353b0113a9679fb21181e02 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 29 Sep 2008 15:51:00 +0000 Subject: [PATCH 1108/1766] fix unclean reset from i/o error and add new span wide option to disable callerid detect git-svn-id: http://svn.openzap.org/svn/openzap/trunk@573 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/openzap.conf.xml | 1 + libs/freetdm/mod_openzap/mod_openzap.c | 5 ++++ libs/freetdm/src/include/openzap.h | 7 ------ .../src/ozmod/ozmod_analog/ozmod_analog.c | 25 ++++++++++++++++--- .../src/ozmod/ozmod_analog/zap_analog.h | 13 +++++++++- .../src/ozmod/ozmod_analog_em/zap_analog_em.h | 8 ++++++ 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/conf/openzap.conf.xml b/libs/freetdm/conf/openzap.conf.xml index 1ca75c0e21..8326505177 100644 --- a/libs/freetdm/conf/openzap.conf.xml +++ b/libs/freetdm/conf/openzap.conf.xml @@ -16,6 +16,7 @@ + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 2aaa3296cf..18064e6486 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1547,6 +1547,8 @@ static switch_status_t load_config(void) char *dial_regex = NULL; char *hold_music = NULL; char *fail_dial_regex = NULL; + char *enable_callerid = "true"; + uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; @@ -1565,6 +1567,8 @@ static switch_status_t load_config(void) dialplan = val; } else if (!strcasecmp(var, "dial-regex")) { dial_regex = val; + } else if (!strcasecmp(var, "enable-callerid")) { + enable_callerid = val; } else if (!strcasecmp(var, "fail-dial-regex")) { fail_dial_regex = val; } else if (!strcasecmp(var, "hold-music")) { @@ -1621,6 +1625,7 @@ static switch_status_t load_config(void) "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, + "enable_callerid", enable_callerid, TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 0cdb98f834..4b705b0b74 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -458,13 +458,6 @@ struct zap_sigmsg { }; -struct zap_analog_data { - uint32_t flags; - uint32_t max_dialstr; - uint32_t digit_timeout; - zio_signal_cb_t sig_cb; -}; - struct zap_span { zap_data_type_t data_type; char *name; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index d1a6e31543..d6e2f5bb35 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -87,6 +87,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) uint32_t max_dialstr = 11; const char *var, *val; int *intval; + uint32_t flags = ZAP_ANALOG_CALLERID; assert(sig_cb != NULL); @@ -110,6 +111,16 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) 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; @@ -128,6 +139,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } span->start = zap_analog_start; + analog_data->flags = flags; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; analog_data->sig_cb = sig_cb; @@ -691,9 +703,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_destroy(&dt_buffer); } - zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); + if (zchan->state != ZAP_CHANNEL_STATE_DOWN) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + } - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); + zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", zchan->span_id, zchan->chan_id); + zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); return NULL; } @@ -725,7 +740,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even goto end; } if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); + 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; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h index 2d90910244..16b7d4f09a 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h @@ -36,9 +36,20 @@ #include "openzap.h" typedef enum { - ZAP_ANALOG_RUNNING = (1 << 0) + ZAP_ANALOG_RUNNING = (1 << 0), + ZAP_ANALOG_CALLERID = (1 << 1) } zap_analog_flag_t; + +struct zap_analog_data { + uint32_t flags; + uint32_t max_dialstr; + uint32_t digit_timeout; + zio_signal_cb_t sig_cb; +}; + + + static void *zap_analog_run(zap_thread_t *me, void *obj); typedef struct zap_analog_data zap_analog_data_t; diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h index e20875d54c..9411844c44 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -44,6 +44,14 @@ 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; + zio_signal_cb_t sig_cb; +}; + static void *zap_analog_em_run(zap_thread_t *me, void *obj); typedef struct zap_analog_data zap_analog_em_data_t; From dd8e70164d5c3ec472267e8f5e5a31a14cd371e5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 29 Sep 2008 17:55:22 +0000 Subject: [PATCH 1109/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@574 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index d6e2f5bb35..df82fda5f2 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -703,11 +703,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_destroy(&dt_buffer); } - if (zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + 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", zchan->span_id, zchan->chan_id); + 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; From 88f09d5973e28628cb63e727b07384ba0dddff40 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 29 Sep 2008 17:55:22 +0000 Subject: [PATCH 1110/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@574 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index d6e2f5bb35..df82fda5f2 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -703,11 +703,11 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_buffer_destroy(&dt_buffer); } - if (zchan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + 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", zchan->span_id, zchan->chan_id); + 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; From 35db2eaec8806efe363924963d221408637955e3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 1 Oct 2008 21:51:10 +0000 Subject: [PATCH 1111/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@575 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 ++- .../ozmod_wanpipe/wanpipe_tdm_api_iface.h | 98 +++++++++++++------ 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e4f2023786..933373f47d 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -525,7 +525,16 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = 0; + + if (zchan->native_codec == ZAP_CODEC_ULAW) { + tdm_api.wp_tdm_cmd.tdm_codec = 0; + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + tdm_api.wp_tdm_cmd.tdm_codec = 1; + } else { + tdm_api.wp_tdm_cmd.tdm_codec = 2; + } + zchan->effective_codec = zchan->native_codec; + wp_tdm_cmd_exec(zchan, &tdm_api); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; @@ -534,8 +543,6 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) 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; - zchan->native_codec = zchan->effective_codec; - } return ZAP_SUCCESS; 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 index 409469c58f..3801ff9c8c 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h @@ -1,11 +1,11 @@ /***************************************************************************** -* wanpipe_tdm_api.h +* wanpipe_tdm_api_iface.h * * WANPIPE(tm) AFT TE1 Hardware Support * * Authors: Nenad Corbic * -* Copyright (c) 2007, Sangoma Technologies +* Copyright (c) 2007 - 08, Sangoma Technologies * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,12 @@ typedef HANDLE sng_fd_t; 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 */ @@ -82,23 +88,29 @@ enum wanpipe_tdm_api_cmds { SIOC_WP_TDM_READ_EVENT, /* 0x15 */ - SIOC_WP_TDM_SET_EVENT, + SIOC_WP_TDM_SET_EVENT, /* 0x16 */ - SIOC_WP_TDM_SET_RX_GAINS, - SIOC_WP_TDM_SET_TX_GAINS, - SIOC_WP_TDM_CLEAR_RX_GAINS, - SIOC_WP_TDM_CLEAR_TX_GAINS, + 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, + SIOC_WP_TDM_GET_FE_ALARMS, /* 0x1B */ - SIOC_WP_TDM_ENABLE_HWEC, - SIOC_WP_TDM_DISABLE_HWEC, + 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, @@ -115,9 +127,14 @@ enum wanpipe_tdm_api_events { WP_TDMAPI_EVENT_TXSIG_OFFHOOK, WP_TDMAPI_EVENT_TXSIG_ONHOOK, WP_TDMAPI_EVENT_ONHOOKTRANSFER, - WP_TDMAPI_EVENT_SETPOLARITY + 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) \ @@ -150,45 +167,61 @@ enum wanpipe_tdm_api_events { ((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 { - uint8_t type; - uint8_t mode; - uint32_t time_stamp; - uint16_t channel; - uint32_t chan_map; + 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 { - uint8_t alarm; + u_int8_t alarm; } te1_alarm; struct { - uint8_t rbs_bits; + u_int8_t rbs_bits; } te1_rbs; struct { - uint8_t state; - uint8_t sig; + u_int8_t state; + u_int8_t sig; } rm_hook; struct { - uint8_t state; + u_int8_t state; } rm_ring; struct { - uint8_t type; + u_int8_t type; } rm_tone; struct { - uint8_t digit; /* DTMF: digit */ - uint8_t port; /* DTMF: SOUT/ROUT */ - uint8_t type; /* DTMF: PRESET/STOP */ + u_int8_t digit; /* DTMF: digit */ + u_int8_t port; /* DTMF: SOUT/ROUT */ + u_int8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - uint16_t polarity; - uint16_t ohttimer; + 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 @@ -204,6 +237,7 @@ typedef struct { #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 { @@ -286,13 +320,16 @@ typedef struct wanpipe_tdm_api_cmd{ 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 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{ @@ -302,6 +339,7 @@ typedef struct wanpipe_tdm_api_event{ 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{ From 404136331016eaca971ca56f3571297591a7cd60 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 1 Oct 2008 21:51:10 +0000 Subject: [PATCH 1112/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@575 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 ++- .../ozmod_wanpipe/wanpipe_tdm_api_iface.h | 98 +++++++++++++------ 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e4f2023786..933373f47d 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -525,7 +525,16 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = 0; + + if (zchan->native_codec == ZAP_CODEC_ULAW) { + tdm_api.wp_tdm_cmd.tdm_codec = 0; + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + tdm_api.wp_tdm_cmd.tdm_codec = 1; + } else { + tdm_api.wp_tdm_cmd.tdm_codec = 2; + } + zchan->effective_codec = zchan->native_codec; + wp_tdm_cmd_exec(zchan, &tdm_api); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; @@ -534,8 +543,6 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) 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; - zchan->native_codec = zchan->effective_codec; - } return ZAP_SUCCESS; diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h index 409469c58f..3801ff9c8c 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h @@ -1,11 +1,11 @@ /***************************************************************************** -* wanpipe_tdm_api.h +* wanpipe_tdm_api_iface.h * * WANPIPE(tm) AFT TE1 Hardware Support * * Authors: Nenad Corbic * -* Copyright (c) 2007, Sangoma Technologies +* Copyright (c) 2007 - 08, Sangoma Technologies * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,12 @@ typedef HANDLE sng_fd_t; 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 */ @@ -82,23 +88,29 @@ enum wanpipe_tdm_api_cmds { SIOC_WP_TDM_READ_EVENT, /* 0x15 */ - SIOC_WP_TDM_SET_EVENT, + SIOC_WP_TDM_SET_EVENT, /* 0x16 */ - SIOC_WP_TDM_SET_RX_GAINS, - SIOC_WP_TDM_SET_TX_GAINS, - SIOC_WP_TDM_CLEAR_RX_GAINS, - SIOC_WP_TDM_CLEAR_TX_GAINS, + 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, + SIOC_WP_TDM_GET_FE_ALARMS, /* 0x1B */ - SIOC_WP_TDM_ENABLE_HWEC, - SIOC_WP_TDM_DISABLE_HWEC, + 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, @@ -115,9 +127,14 @@ enum wanpipe_tdm_api_events { WP_TDMAPI_EVENT_TXSIG_OFFHOOK, WP_TDMAPI_EVENT_TXSIG_ONHOOK, WP_TDMAPI_EVENT_ONHOOKTRANSFER, - WP_TDMAPI_EVENT_SETPOLARITY + 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) \ @@ -150,45 +167,61 @@ enum wanpipe_tdm_api_events { ((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 { - uint8_t type; - uint8_t mode; - uint32_t time_stamp; - uint16_t channel; - uint32_t chan_map; + 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 { - uint8_t alarm; + u_int8_t alarm; } te1_alarm; struct { - uint8_t rbs_bits; + u_int8_t rbs_bits; } te1_rbs; struct { - uint8_t state; - uint8_t sig; + u_int8_t state; + u_int8_t sig; } rm_hook; struct { - uint8_t state; + u_int8_t state; } rm_ring; struct { - uint8_t type; + u_int8_t type; } rm_tone; struct { - uint8_t digit; /* DTMF: digit */ - uint8_t port; /* DTMF: SOUT/ROUT */ - uint8_t type; /* DTMF: PRESET/STOP */ + u_int8_t digit; /* DTMF: digit */ + u_int8_t port; /* DTMF: SOUT/ROUT */ + u_int8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - uint16_t polarity; - uint16_t ohttimer; + 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 @@ -204,6 +237,7 @@ typedef struct { #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 { @@ -286,13 +320,16 @@ typedef struct wanpipe_tdm_api_cmd{ 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 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{ @@ -302,6 +339,7 @@ typedef struct wanpipe_tdm_api_event{ 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{ From 1d8f1d05b4790d5fb9565b4e8cf3d05a3a03c94b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 18:15:04 +0000 Subject: [PATCH 1113/1766] write cng frames during sleep git-svn-id: http://svn.openzap.org/svn/openzap/trunk@576 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 18064e6486..94c2ac7834 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -364,6 +364,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session) zap_channel_init(tech_pvt->zchan); + switch_channel_set_flag(channel, CF_ACCEPT_CNG); + return SWITCH_STATUS_SUCCESS; } @@ -636,7 +638,8 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; zap_size_t len; - + unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -653,6 +656,16 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc goto fail; } + if (switch_test_flag(frame, SFF_CNG)) { + frame->data = data; + frame->buflen = sizeof(data); + if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_frame) > frame->buflen) { + goto fail; + } + memset(data, 255, frame->datalen); + } + + len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { From 06368f611968e5f5134b60140886b92aedfbd000 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 18:15:04 +0000 Subject: [PATCH 1114/1766] write cng frames during sleep git-svn-id: http://svn.openzap.org/svn/openzap/trunk@576 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 18064e6486..94c2ac7834 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -364,6 +364,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session) zap_channel_init(tech_pvt->zchan); + switch_channel_set_flag(channel, CF_ACCEPT_CNG); + return SWITCH_STATUS_SUCCESS; } @@ -636,7 +638,8 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; zap_size_t len; - + unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -653,6 +656,16 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc goto fail; } + if (switch_test_flag(frame, SFF_CNG)) { + frame->data = data; + frame->buflen = sizeof(data); + if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_frame) > frame->buflen) { + goto fail; + } + memset(data, 255, frame->datalen); + } + + len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { From 4c45863d5a321c79cd14859249974c9b7f18797e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:03:21 +0000 Subject: [PATCH 1115/1766] move dtmf gen to read git-svn-id: http://svn.openzap.org/svn/openzap/trunk@577 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/zap_io.c | 156 ++++++++++++++++--------- 3 files changed, 102 insertions(+), 57 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 94c2ac7834..5ea4e7728d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -364,7 +364,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) zap_channel_init(tech_pvt->zchan); - switch_channel_set_flag(channel, CF_ACCEPT_CNG); + //switch_channel_set_flag(channel, CF_ACCEPT_CNG); return SWITCH_STATUS_SUCCESS; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4b705b0b74..7e670f14c2 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -422,6 +422,7 @@ struct zap_channel { zio_event_cb_t event_callback; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; + zap_buffer_t *gen_dtmf_buffer; zap_buffer_t *digit_buffer; zap_buffer_t *fsk_buffer; uint32_t dtmf_on; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index ebbd7a6e89..f0e66bea10 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -239,6 +239,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) } zap_buffer_destroy(&zchan->digit_buffer); + zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -455,7 +456,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); - + zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -958,6 +960,10 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_buffer_zero(zchan->dtmf_buffer); } + if (zchan->gen_dtmf_buffer) { + zap_buffer_zero(zchan->gen_dtmf_buffer); + } + if (zchan->digit_buffer) { zap_buffer_zero(zchan->digit_buffer); } @@ -1410,28 +1416,16 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_SEND_DTMF: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; - int x = 0; + if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { GOTO_STATUS(done, status); } zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); + zap_buffer_write(zchan->gen_dtmf_buffer, digits, strlen(digits)); - for (cur = digits; *cur; cur++) { - int wrote = 0; - if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { - zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); - x++; - } else { - zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); - GOTO_STATUS(done, ZAP_FAIL); - } - } - - zchan->skip_read_frames = 200 * x; GOTO_STATUS(done, ZAP_SUCCESS); } } @@ -1691,6 +1685,81 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) return status; } + +static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) +{ + zap_buffer_t *buffer = NULL; + zap_size_t dblen; + + if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { + char digits[128] = ""; + char *cur; + int x = 0; + + if (dblen > sizeof(digits) - 1) { + dblen = sizeof(digits) - 1; + } + + if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero(digits)) { + zap_log(ZAP_LOG_DEBUG, "GENERATE DTMF [%s]\n", digits); + + for (cur = digits; *cur; cur++) { + int wrote = 0; + if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { + zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); + x++; + } else { + zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); + return ZAP_FAIL; + } + } + + zchan->skip_read_frames = 200 * x; + } + } + + + if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { + if (zchan->dtmf_buffer && (dblen = zap_buffer_inuse(zchan->dtmf_buffer))) { + buffer = zchan->dtmf_buffer; + } else if (zchan->fsk_buffer && (dblen = zap_buffer_inuse(zchan->fsk_buffer))) { + buffer = zchan->fsk_buffer; + } + } + + if (buffer) { + zap_size_t dlen = datalen; + uint8_t auxbuf[1024]; + zap_size_t len, br, max = sizeof(auxbuf); + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + dlen *= 2; + } + + len = dblen > dlen ? dlen : dblen; + + br = zap_buffer_read(buffer, auxbuf, len); + if (br < dlen) { + memset(auxbuf + br, 0, dlen - br); + } + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + if (zchan->native_codec == ZAP_CODEC_ULAW) { + zio_slin2ulaw(auxbuf, max, &dlen); + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + zio_slin2alaw(auxbuf, max, &dlen); + } + } + + return zchan->zio->write(zchan, auxbuf, &dlen); + } + + return ZAP_SUCCESS; + +} + + + zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; @@ -1720,6 +1789,10 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } + if (status == ZAP_SUCCESS) { + handle_dtmf(zchan, *datalen); + } + if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { codec_func = zio_ulaw2slin; @@ -1880,6 +1953,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } } + return status; } @@ -1888,12 +1962,19 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t blen = 0, max = datasize; - zap_buffer_t *buffer = NULL; + zap_size_t max = datasize; assert(zchan != NULL); assert(zchan->zio != NULL); + if (!zchan->buffer_delay && + ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer)) || + (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer)))) { + /* read size writing DTMF ATM */ + return ZAP_SUCCESS; + } + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; @@ -1921,45 +2002,8 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); status = ZAP_FAIL; } - } - - if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { - if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { - buffer = zchan->dtmf_buffer; - } else if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { - buffer = zchan->fsk_buffer; - } - } - - if (buffer) { - zap_size_t dlen = *datalen; - uint8_t auxbuf[1024]; - zap_size_t len, br; - - if (zchan->native_codec != ZAP_CODEC_SLIN) { - dlen *= 2; - } - - len = blen > dlen ? dlen : blen; - - br = zap_buffer_read(buffer, auxbuf, len); - if (br < dlen) { - memset(auxbuf + br, 0, dlen - br); - } - - memcpy(data, auxbuf, dlen); - - if (zchan->native_codec != ZAP_CODEC_SLIN) { - if (zchan->native_codec == ZAP_CODEC_ULAW) { - *datalen = dlen; - zio_slin2ulaw(data, max, datalen); - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - *datalen = dlen; - zio_slin2alaw(data, max, datalen); - } - } - - } + } + if (zchan->fds[1] > -1) { int dlen = (int) *datalen; if ((write(zchan->fds[1], data, dlen)) != dlen) { From a120d4bd7a9cf43546feb67f5311c6850ea7f2fe Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:03:21 +0000 Subject: [PATCH 1116/1766] move dtmf gen to read git-svn-id: http://svn.openzap.org/svn/openzap/trunk@577 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 156 ++++++++++++++++--------- 3 files changed, 102 insertions(+), 57 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 94c2ac7834..5ea4e7728d 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -364,7 +364,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) zap_channel_init(tech_pvt->zchan); - switch_channel_set_flag(channel, CF_ACCEPT_CNG); + //switch_channel_set_flag(channel, CF_ACCEPT_CNG); return SWITCH_STATUS_SUCCESS; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4b705b0b74..7e670f14c2 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -422,6 +422,7 @@ struct zap_channel { zio_event_cb_t event_callback; uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; + zap_buffer_t *gen_dtmf_buffer; zap_buffer_t *digit_buffer; zap_buffer_t *fsk_buffer; uint32_t dtmf_on; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index ebbd7a6e89..f0e66bea10 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -239,6 +239,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) } zap_buffer_destroy(&zchan->digit_buffer); + zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); @@ -455,7 +456,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); - + zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -958,6 +960,10 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) zap_buffer_zero(zchan->dtmf_buffer); } + if (zchan->gen_dtmf_buffer) { + zap_buffer_zero(zchan->gen_dtmf_buffer); + } + if (zchan->digit_buffer) { zap_buffer_zero(zchan->digit_buffer); } @@ -1410,28 +1416,16 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo case ZAP_COMMAND_SEND_DTMF: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - char *cur; char *digits = ZAP_COMMAND_OBJ_CHAR_P; - int x = 0; + if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { GOTO_STATUS(done, status); } zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); + zap_buffer_write(zchan->gen_dtmf_buffer, digits, strlen(digits)); - for (cur = digits; *cur; cur++) { - int wrote = 0; - if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { - zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); - x++; - } else { - zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); - GOTO_STATUS(done, ZAP_FAIL); - } - } - - zchan->skip_read_frames = 200 * x; GOTO_STATUS(done, ZAP_SUCCESS); } } @@ -1691,6 +1685,81 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) return status; } + +static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) +{ + zap_buffer_t *buffer = NULL; + zap_size_t dblen; + + if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { + char digits[128] = ""; + char *cur; + int x = 0; + + if (dblen > sizeof(digits) - 1) { + dblen = sizeof(digits) - 1; + } + + if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero(digits)) { + zap_log(ZAP_LOG_DEBUG, "GENERATE DTMF [%s]\n", digits); + + for (cur = digits; *cur; cur++) { + int wrote = 0; + if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { + zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); + x++; + } else { + zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); + return ZAP_FAIL; + } + } + + zchan->skip_read_frames = 200 * x; + } + } + + + if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { + if (zchan->dtmf_buffer && (dblen = zap_buffer_inuse(zchan->dtmf_buffer))) { + buffer = zchan->dtmf_buffer; + } else if (zchan->fsk_buffer && (dblen = zap_buffer_inuse(zchan->fsk_buffer))) { + buffer = zchan->fsk_buffer; + } + } + + if (buffer) { + zap_size_t dlen = datalen; + uint8_t auxbuf[1024]; + zap_size_t len, br, max = sizeof(auxbuf); + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + dlen *= 2; + } + + len = dblen > dlen ? dlen : dblen; + + br = zap_buffer_read(buffer, auxbuf, len); + if (br < dlen) { + memset(auxbuf + br, 0, dlen - br); + } + + if (zchan->native_codec != ZAP_CODEC_SLIN) { + if (zchan->native_codec == ZAP_CODEC_ULAW) { + zio_slin2ulaw(auxbuf, max, &dlen); + } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + zio_slin2alaw(auxbuf, max, &dlen); + } + } + + return zchan->zio->write(zchan, auxbuf, &dlen); + } + + return ZAP_SUCCESS; + +} + + + zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; @@ -1720,6 +1789,10 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } + if (status == ZAP_SUCCESS) { + handle_dtmf(zchan, *datalen); + } + if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { codec_func = zio_ulaw2slin; @@ -1880,6 +1953,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } } + return status; } @@ -1888,12 +1962,19 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; - zap_size_t blen = 0, max = datasize; - zap_buffer_t *buffer = NULL; + zap_size_t max = datasize; assert(zchan != NULL); assert(zchan->zio != NULL); + if (!zchan->buffer_delay && + ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer)) || + (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer)))) { + /* read size writing DTMF ATM */ + return ZAP_SUCCESS; + } + + if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); return ZAP_FAIL; @@ -1921,45 +2002,8 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); status = ZAP_FAIL; } - } - - if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { - if (zchan->dtmf_buffer && (blen = zap_buffer_inuse(zchan->dtmf_buffer))) { - buffer = zchan->dtmf_buffer; - } else if (zchan->fsk_buffer && (blen = zap_buffer_inuse(zchan->fsk_buffer))) { - buffer = zchan->fsk_buffer; - } - } - - if (buffer) { - zap_size_t dlen = *datalen; - uint8_t auxbuf[1024]; - zap_size_t len, br; - - if (zchan->native_codec != ZAP_CODEC_SLIN) { - dlen *= 2; - } - - len = blen > dlen ? dlen : blen; - - br = zap_buffer_read(buffer, auxbuf, len); - if (br < dlen) { - memset(auxbuf + br, 0, dlen - br); - } - - memcpy(data, auxbuf, dlen); - - if (zchan->native_codec != ZAP_CODEC_SLIN) { - if (zchan->native_codec == ZAP_CODEC_ULAW) { - *datalen = dlen; - zio_slin2ulaw(data, max, datalen); - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - *datalen = dlen; - zio_slin2alaw(data, max, datalen); - } - } - - } + } + if (zchan->fds[1] > -1) { int dlen = (int) *datalen; if ((write(zchan->fds[1], data, dlen)) != dlen) { From 8a2abc06c32b9bab540ebc2d8acafd3ded341b48 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:14:46 +0000 Subject: [PATCH 1117/1766] OPENZAP-25 Setting screening and presentation indicator for outgoing calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@578 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index ced303ca4c..9fe9b08292 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -216,6 +216,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); zap_set_string(event.calling_name, caller_data->cid_name); zap_set_string(event.redirection_string, caller_data->rdnis.digits); + event.calling_number_screening_ind = caller_data->screen; + event.calling_number_presentation = caller_data->pres; OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; From ded0b0e605bb043bd942450c99084120efd6062c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:14:46 +0000 Subject: [PATCH 1118/1766] OPENZAP-25 Setting screening and presentation indicator for outgoing calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@578 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index ced303ca4c..9fe9b08292 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -216,6 +216,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); zap_set_string(event.calling_name, caller_data->cid_name); zap_set_string(event.redirection_string, caller_data->rdnis.digits); + event.calling_number_screening_ind = caller_data->screen; + event.calling_number_presentation = caller_data->pres; OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; From 086decc2d6c7f93d83e3f416dbc9c8b3aa40cd74 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:15:45 +0000 Subject: [PATCH 1119/1766] clean up log git-svn-id: http://svn.openzap.org/svn/openzap/trunk@579 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f0e66bea10..1f07f3af98 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1418,12 +1418,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { char *digits = ZAP_COMMAND_OBJ_CHAR_P; - if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { GOTO_STATUS(done, status); } - zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); zap_buffer_write(zchan->gen_dtmf_buffer, digits, strlen(digits)); GOTO_STATUS(done, ZAP_SUCCESS); @@ -1701,7 +1699,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero(digits)) { - zap_log(ZAP_LOG_DEBUG, "GENERATE DTMF [%s]\n", digits); + zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); for (cur = digits; *cur; cur++) { int wrote = 0; @@ -1709,7 +1707,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); x++; } else { - zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); + zap_log(ZAP_LOG_ERROR, "%d:%d Problem Adding DTMF SEQ [%s]\n", zchan->span_id, zchan->chan_id, digits); return ZAP_FAIL; } } From f5f9de357b34cd5d1155fddb68b1b431cf1c5061 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:15:45 +0000 Subject: [PATCH 1120/1766] clean up log git-svn-id: http://svn.openzap.org/svn/openzap/trunk@579 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f0e66bea10..1f07f3af98 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1418,12 +1418,10 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { char *digits = ZAP_COMMAND_OBJ_CHAR_P; - if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { GOTO_STATUS(done, status); } - zap_log(ZAP_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); zap_buffer_write(zchan->gen_dtmf_buffer, digits, strlen(digits)); GOTO_STATUS(done, ZAP_SUCCESS); @@ -1701,7 +1699,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero(digits)) { - zap_log(ZAP_LOG_DEBUG, "GENERATE DTMF [%s]\n", digits); + zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); for (cur = digits; *cur; cur++) { int wrote = 0; @@ -1709,7 +1707,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); x++; } else { - zap_log(ZAP_LOG_ERROR, "Problem Adding DTMF SEQ [%s]\n", digits); + zap_log(ZAP_LOG_ERROR, "%d:%d Problem Adding DTMF SEQ [%s]\n", zchan->span_id, zchan->chan_id, digits); return ZAP_FAIL; } } From 41184317d00e30c8312860b7958cb8013fb1e9bc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:57:57 +0000 Subject: [PATCH 1121/1766] OPENZAP-22 add configuration settable debug levels for isdn trunks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@580 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.update | 2 +- libs/openzap/conf/openzap.conf.xml | 19 +++++++ libs/openzap/mod_openzap/mod_openzap.c | 17 ++++-- libs/openzap/src/isdn/Q921.c | 6 +++ libs/openzap/src/isdn/Q931.c | 9 ++++ libs/openzap/src/isdn/include/Q921.h | 5 +- libs/openzap/src/isdn/include/Q931.h | 15 +++--- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 52 ++++++++----------- 8 files changed, 83 insertions(+), 42 deletions(-) diff --git a/libs/openzap/.update b/libs/openzap/.update index 5009a80d3a..e9475b68ed 100644 --- a/libs/openzap/.update +++ b/libs/openzap/.update @@ -1 +1 @@ -Tue Jun 3 17:09:07 EDT 2008 +Fri Oct 3 17:54:41 EDT 2008 diff --git a/libs/openzap/conf/openzap.conf.xml b/libs/openzap/conf/openzap.conf.xml index 8326505177..bfa2bc0391 100644 --- a/libs/openzap/conf/openzap.conf.xml +++ b/libs/openzap/conf/openzap.conf.xml @@ -5,6 +5,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5ea4e7728d..1fa56ea393 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1794,7 +1794,9 @@ static switch_status_t load_config(void) zap_span_t *span = NULL; char *tonegroup = NULL; uint32_t opts = 0; - + int q921loglevel = -1; + int q931loglevel = -1; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1805,6 +1807,14 @@ static switch_status_t load_config(void) mode = val; } else if (!strcasecmp(var, "dialect")) { dialect = val; + } else if (!strcasecmp(var, "q921loglevel")) { + if ((q921loglevel = switch_log_str2level(val)) == SWITCH_LOG_INVALID) { + q921loglevel = -1; + } + } else if (!strcasecmp(var, "q931loglevel")) { + if ((q931loglevel = switch_log_str2level(val)) == SWITCH_LOG_INVALID) { + q931loglevel = -1; + } } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { @@ -1813,8 +1823,7 @@ static switch_status_t load_config(void) dialplan = val; } } - - + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; @@ -1849,6 +1858,8 @@ static switch_status_t load_config(void) if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, + "q921loglevel", q921loglevel, + "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index a3e5ec3783..7667203227 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -2993,6 +2993,12 @@ 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; } diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index b29bcf97dd..a235253c3a 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -860,6 +860,15 @@ void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv) */ 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; } diff --git a/libs/openzap/src/isdn/include/Q921.h b/libs/openzap/src/isdn/include/Q921.h index f09fa7577c..cb21a157ea 100644 --- a/libs/openzap/src/isdn/include/Q921.h +++ b/libs/openzap/src/isdn/include/Q921.h @@ -119,7 +119,10 @@ typedef enum /* Type of connection */ typedef enum { - Q921_LOG_NONE = 0, + Q921_LOG_NONE = -1, + Q921_LOG_EMERG = 0, + Q921_LOG_ALERT, + Q921_LOG_CRIT, Q921_LOG_ERROR, Q921_LOG_WARNING, Q921_LOG_NOTICE, diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index e05c7e9dce..9877912f79 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -634,12 +634,15 @@ typedef struct { typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; typedef enum { - Q931_LOG_NONE = 0, - Q931_LOG_ERROR, - Q931_LOG_WARNING, - Q931_LOG_NOTICE, - Q931_LOG_INFO, - Q931_LOG_DEBUG + 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); diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index a9170d0d2b..87d0cf595f 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1518,34 +1518,8 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) { zap_span_t *span = (zap_span_t *) pvt; - int loglevel = ZAP_LOG_LEVEL_DEBUG; - switch(level) { - case Q921_LOG_DEBUG: - loglevel = ZAP_LOG_LEVEL_DEBUG; - break; - - case Q921_LOG_INFO: - loglevel = ZAP_LOG_LEVEL_INFO; - break; - - case Q921_LOG_NOTICE: - loglevel = ZAP_LOG_LEVEL_NOTICE; - break; - - case Q921_LOG_WARNING: - loglevel = ZAP_LOG_LEVEL_WARNING; - break; - - case Q921_LOG_ERROR: - loglevel = ZAP_LOG_LEVEL_ERROR; - break; - - default: - return 0; - } - - zap_log("Span", "Q.921", span->span_id, loglevel, "%s", msg); + zap_log("Span", "Q.921", span->span_id, (int)level, "%s", msg); return 0; } @@ -1553,7 +1527,7 @@ static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT { zap_span_t *span = (zap_span_t *) pvt; - zap_log("Span", "Q.931", span->span_id, ZAP_LOG_LEVEL_DEBUG, "%s", msg); + zap_log("Span", "Q.931", span->span_id, (int)level, "%s", msg); return 0; } @@ -1697,6 +1671,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; + int q921loglevel = 0; + int q931loglevel = 0; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1760,9 +1736,23 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) break; } tonemap = (const char *)val; + } 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; + } } } - + span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; @@ -1781,7 +1771,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) &isdn_data->q931); Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); - Q921SetLogLevel(&isdn_data->q921, Q921_LOG_NONE); + Q921SetLogLevel(&isdn_data->q921, (Q921LogLevel_t)q921loglevel); Q931Api_InitTrunk(&isdn_data->q931, dialect, @@ -1794,7 +1784,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) span); Q931SetLogCB(&isdn_data->q931, &zap_isdn_q931_log, isdn_data); - Q931SetLogLevel(&isdn_data->q931, Q931_LOG_DEBUG); + Q931SetLogLevel(&isdn_data->q931, (Q931LogLevel_t)q931loglevel); isdn_data->q931.autoRestartAck = 1; isdn_data->q931.autoConnectAck = 0; From 5b2982a442c5a7ee953ef0aa43c8208c08bdba07 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 21:57:57 +0000 Subject: [PATCH 1122/1766] OPENZAP-22 add configuration settable debug levels for isdn trunks git-svn-id: http://svn.openzap.org/svn/openzap/trunk@580 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.update | 2 +- libs/freetdm/conf/openzap.conf.xml | 19 +++++++ libs/freetdm/mod_openzap/mod_openzap.c | 17 ++++-- libs/freetdm/src/isdn/Q921.c | 6 +++ libs/freetdm/src/isdn/Q931.c | 9 ++++ libs/freetdm/src/isdn/include/Q921.h | 5 +- libs/freetdm/src/isdn/include/Q931.h | 15 +++--- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 52 ++++++++----------- 8 files changed, 83 insertions(+), 42 deletions(-) diff --git a/libs/freetdm/.update b/libs/freetdm/.update index 5009a80d3a..e9475b68ed 100644 --- a/libs/freetdm/.update +++ b/libs/freetdm/.update @@ -1 +1 @@ -Tue Jun 3 17:09:07 EDT 2008 +Fri Oct 3 17:54:41 EDT 2008 diff --git a/libs/freetdm/conf/openzap.conf.xml b/libs/freetdm/conf/openzap.conf.xml index 8326505177..bfa2bc0391 100644 --- a/libs/freetdm/conf/openzap.conf.xml +++ b/libs/freetdm/conf/openzap.conf.xml @@ -5,6 +5,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5ea4e7728d..1fa56ea393 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1794,7 +1794,9 @@ static switch_status_t load_config(void) zap_span_t *span = NULL; char *tonegroup = NULL; uint32_t opts = 0; - + int q921loglevel = -1; + int q931loglevel = -1; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1805,6 +1807,14 @@ static switch_status_t load_config(void) mode = val; } else if (!strcasecmp(var, "dialect")) { dialect = val; + } else if (!strcasecmp(var, "q921loglevel")) { + if ((q921loglevel = switch_log_str2level(val)) == SWITCH_LOG_INVALID) { + q921loglevel = -1; + } + } else if (!strcasecmp(var, "q931loglevel")) { + if ((q931loglevel = switch_log_str2level(val)) == SWITCH_LOG_INVALID) { + q931loglevel = -1; + } } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { @@ -1813,8 +1823,7 @@ static switch_status_t load_config(void) dialplan = val; } } - - + if (!id && !name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; @@ -1849,6 +1858,8 @@ static switch_status_t load_config(void) if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, + "q921loglevel", q921loglevel, + "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); continue; diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index a3e5ec3783..7667203227 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -2993,6 +2993,12 @@ 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; } diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index b29bcf97dd..a235253c3a 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -860,6 +860,15 @@ void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv) */ 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; } diff --git a/libs/freetdm/src/isdn/include/Q921.h b/libs/freetdm/src/isdn/include/Q921.h index f09fa7577c..cb21a157ea 100644 --- a/libs/freetdm/src/isdn/include/Q921.h +++ b/libs/freetdm/src/isdn/include/Q921.h @@ -119,7 +119,10 @@ typedef enum /* Type of connection */ typedef enum { - Q921_LOG_NONE = 0, + Q921_LOG_NONE = -1, + Q921_LOG_EMERG = 0, + Q921_LOG_ALERT, + Q921_LOG_CRIT, Q921_LOG_ERROR, Q921_LOG_WARNING, Q921_LOG_NOTICE, diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index e05c7e9dce..9877912f79 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -634,12 +634,15 @@ typedef struct { typedef struct Q931_TrunkInfo Q931_TrunkInfo_t; typedef enum { - Q931_LOG_NONE = 0, - Q931_LOG_ERROR, - Q931_LOG_WARNING, - Q931_LOG_NOTICE, - Q931_LOG_INFO, - Q931_LOG_DEBUG + 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); diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index a9170d0d2b..87d0cf595f 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1518,34 +1518,8 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) { zap_span_t *span = (zap_span_t *) pvt; - int loglevel = ZAP_LOG_LEVEL_DEBUG; - switch(level) { - case Q921_LOG_DEBUG: - loglevel = ZAP_LOG_LEVEL_DEBUG; - break; - - case Q921_LOG_INFO: - loglevel = ZAP_LOG_LEVEL_INFO; - break; - - case Q921_LOG_NOTICE: - loglevel = ZAP_LOG_LEVEL_NOTICE; - break; - - case Q921_LOG_WARNING: - loglevel = ZAP_LOG_LEVEL_WARNING; - break; - - case Q921_LOG_ERROR: - loglevel = ZAP_LOG_LEVEL_ERROR; - break; - - default: - return 0; - } - - zap_log("Span", "Q.921", span->span_id, loglevel, "%s", msg); + zap_log("Span", "Q.921", span->span_id, (int)level, "%s", msg); return 0; } @@ -1553,7 +1527,7 @@ static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT { zap_span_t *span = (zap_span_t *) pvt; - zap_log("Span", "Q.931", span->span_id, ZAP_LOG_LEVEL_DEBUG, "%s", msg); + zap_log("Span", "Q.931", span->span_id, (int)level, "%s", msg); return 0; } @@ -1697,6 +1671,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; + int q921loglevel = 0; + int q931loglevel = 0; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1760,9 +1736,23 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) break; } tonemap = (const char *)val; + } 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; + } } } - + span->start = zap_isdn_start; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; @@ -1781,7 +1771,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) &isdn_data->q931); Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); - Q921SetLogLevel(&isdn_data->q921, Q921_LOG_NONE); + Q921SetLogLevel(&isdn_data->q921, (Q921LogLevel_t)q921loglevel); Q931Api_InitTrunk(&isdn_data->q931, dialect, @@ -1794,7 +1784,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) span); Q931SetLogCB(&isdn_data->q931, &zap_isdn_q931_log, isdn_data); - Q931SetLogLevel(&isdn_data->q931, Q931_LOG_DEBUG); + Q931SetLogLevel(&isdn_data->q931, (Q931LogLevel_t)q931loglevel); isdn_data->q931.autoRestartAck = 1; isdn_data->q931.autoConnectAck = 0; From 7479fdeb122bd627d364c18068f3fa8adb9b3990 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 22:19:40 +0000 Subject: [PATCH 1123/1766] OPENZAP-24 audio problem on alaw wanpipe git-svn-id: http://svn.openzap.org/svn/openzap/trunk@581 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 933373f47d..acf9ab28c0 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -524,19 +524,10 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - - if (zchan->native_codec == ZAP_CODEC_ULAW) { - tdm_api.wp_tdm_cmd.tdm_codec = 0; - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - tdm_api.wp_tdm_cmd.tdm_codec = 1; - } else { - tdm_api.wp_tdm_cmd.tdm_codec = 2; - } zchan->effective_codec = zchan->native_codec; - - wp_tdm_cmd_exec(zchan, &tdm_api); - + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; + tdm_api.wp_tdm_cmd.tdm_codec = 0; + wp_tdm_cmd_exec(zchan, &tdm_api); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; wp_tdm_cmd_exec(zchan, &tdm_api); From cd8e473df19d8fcd60df6629b70aa7be552f9f3b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Oct 2008 22:19:40 +0000 Subject: [PATCH 1124/1766] OPENZAP-24 audio problem on alaw wanpipe git-svn-id: http://svn.openzap.org/svn/openzap/trunk@581 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 933373f47d..acf9ab28c0 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -524,19 +524,10 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - - if (zchan->native_codec == ZAP_CODEC_ULAW) { - tdm_api.wp_tdm_cmd.tdm_codec = 0; - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - tdm_api.wp_tdm_cmd.tdm_codec = 1; - } else { - tdm_api.wp_tdm_cmd.tdm_codec = 2; - } zchan->effective_codec = zchan->native_codec; - - wp_tdm_cmd_exec(zchan, &tdm_api); - + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; + tdm_api.wp_tdm_cmd.tdm_codec = 0; + wp_tdm_cmd_exec(zchan, &tdm_api); tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; wp_tdm_cmd_exec(zchan, &tdm_api); From 75b1f063ce7e560ab7b581f1c3443b2a770bfd5a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 4 Oct 2008 19:00:13 +0000 Subject: [PATCH 1125/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@582 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/zap_io.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 7e670f14c2..567a0e53eb 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -166,6 +166,7 @@ #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) #define zap_set_string(x,y) strncpy(x, y, sizeof(x)-1) #define zap_strlen_zero(s) (!s || *s == '\0') +#define zap_strlen_zero_buf(s) (*s == '\0') #define zap_channel_test_feature(obj, flag) ((obj)->features & flag) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 1f07f3af98..8d74f9faf6 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1698,7 +1698,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) dblen = sizeof(digits) - 1; } - if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero(digits)) { + if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero_buf(digits)) { zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); for (cur = digits; *cur; cur++) { From bbca5aba493140c35f14c4304dc05f41ebf29594 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 4 Oct 2008 19:00:13 +0000 Subject: [PATCH 1126/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@582 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 7e670f14c2..567a0e53eb 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -166,6 +166,7 @@ #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) #define zap_set_string(x,y) strncpy(x, y, sizeof(x)-1) #define zap_strlen_zero(s) (!s || *s == '\0') +#define zap_strlen_zero_buf(s) (*s == '\0') #define zap_channel_test_feature(obj, flag) ((obj)->features & flag) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1f07f3af98..8d74f9faf6 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1698,7 +1698,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) dblen = sizeof(digits) - 1; } - if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero(digits)) { + if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero_buf(digits)) { zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); for (cur = digits; *cur; cur++) { From 11ee8f645b99b9312e85e1f87764978be7e18cc5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 15:53:23 +0000 Subject: [PATCH 1127/1766] initialize to no isdn logging if param not set in config git-svn-id: http://svn.openzap.org/svn/openzap/trunk@583 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 87d0cf595f..04e6eecdf3 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1671,8 +1671,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; - int q921loglevel = 0; - int q931loglevel = 0; + int q921loglevel = -1; + int q931loglevel = -1; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); From d0ef88c299a98e0507e4ed72ba1c321034afc362 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 15:53:23 +0000 Subject: [PATCH 1128/1766] initialize to no isdn logging if param not set in config git-svn-id: http://svn.openzap.org/svn/openzap/trunk@583 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 87d0cf595f..04e6eecdf3 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1671,8 +1671,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; - int q921loglevel = 0; - int q931loglevel = 0; + int q921loglevel = -1; + int q931loglevel = -1; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); From 7f960f6edbd120fa2bf593e9a69f2e83da322b3a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 15:57:11 +0000 Subject: [PATCH 1129/1766] allow span name in dial string instead of span number openzap//A| git-svn-id: http://svn.openzap.org/svn/openzap/trunk@584 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 1fa56ea393..77f9a79ee0 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -882,6 +882,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_status_t status; int direction = ZAP_TOP_DOWN; zap_caller_data_t caller_data = {{ 0 }}; + char *span_name = NULL; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -894,8 +895,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } dest = outbound_profile->destination_number; - span_id = atoi(dest); + if (switch_is_number(dest)) { + span_id = atoi(dest); + } else { + span_name = dest; + } + + if ((p = strchr(dest, '/'))) { if (*p++) { if (*p == 'A') { @@ -911,6 +918,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } + if (!span_id && !switch_strlen_zero(span_name)) { + zap_span_t *span; + zap_status_t zstatus = zap_span_find_by_name(span_name, &span); + if (zstatus == ZAP_SUCCESS && span) { + span_id = span->span_id; + } + } + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From e4797e4de61a07a60c2bfea4c5d4f37cdb5ef73a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 15:57:11 +0000 Subject: [PATCH 1130/1766] allow span name in dial string instead of span number openzap//A| git-svn-id: http://svn.openzap.org/svn/openzap/trunk@584 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 1fa56ea393..77f9a79ee0 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -882,6 +882,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_status_t status; int direction = ZAP_TOP_DOWN; zap_caller_data_t caller_data = {{ 0 }}; + char *span_name = NULL; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -894,8 +895,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } dest = outbound_profile->destination_number; - span_id = atoi(dest); + if (switch_is_number(dest)) { + span_id = atoi(dest); + } else { + span_name = dest; + } + + if ((p = strchr(dest, '/'))) { if (*p++) { if (*p == 'A') { @@ -911,6 +918,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } + if (!span_id && !switch_strlen_zero(span_name)) { + zap_span_t *span; + zap_status_t zstatus = zap_span_find_by_name(span_name, &span); + if (zstatus == ZAP_SUCCESS && span) { + span_id = span->span_id; + } + } + if (!span_id) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From 539bd22cab9409c1ec416ec874843ae982b93ca1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 19:13:32 +0000 Subject: [PATCH 1131/1766] add patch OPENZAP-26 with minor mods git-svn-id: http://svn.openzap.org/svn/openzap/trunk@585 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 14 ++++++++ libs/openzap/src/include/openzap.h | 4 +++ libs/openzap/src/zap_io.c | 44 +++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 77f9a79ee0..9539cb7bfb 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -36,6 +36,9 @@ #define __FUNCTION__ __SWITCH_FUNC__ #endif +#define OPENZAP_VAR_PREFIX "openzap_" +#define OPENZAP_VAR_PREFIX_LEN 8 + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); @@ -883,6 +886,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi int direction = ZAP_TOP_DOWN; zap_caller_data_t caller_data = {{ 0 }}; char *span_name = NULL; + switch_event_header_t *h; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -968,6 +972,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + zap_channel_clear_vars(zchan); + for (h = var_event->headers; h; h = h->next) { + if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { + char *v = h->name + OPENZAP_VAR_PREFIX_LEN; + if (!switch_strlen_zero(v)) { + zap_channel_add_var(zchan, v, h->value); + } + } + } + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 567a0e53eb..ae95e34021 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -447,6 +447,7 @@ struct zap_channel { struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; + zap_hash_t *variable_hash; }; @@ -573,6 +574,9 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); +zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); +const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name); +zap_status_t zap_channel_clear_vars(zap_channel_t *zchan); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8d74f9faf6..1472d2e697 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -242,6 +242,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + hashtable_destroy(zchan->variable_hash); zap_safe_free(zchan->dtmf_hangup_buf); @@ -457,7 +458,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); - + new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -2015,6 +2017,46 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data return status; } +zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) +{ + if(zchan->variable_hash) { + hashtable_destroy(zchan->variable_hash); + } + zchan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + + if(!zchan->variable_hash) + return ZAP_FAIL; + + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) +{ + char *t_name = 0, *t_val = 0; + + if(!zchan->variable_hash || !var_name || !value) + { + return ZAP_FAIL; + } + + t_name = strdup(var_name); + t_val = strdup(value); + + if(hashtable_insert(zchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) { + return ZAP_SUCCESS; + } + return ZAP_FAIL; +} + +const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name) +{ + if(!zchan->variable_hash || !var_name) + { + return NULL; + } + return (const char *) hashtable_search(zchan->variable_hash, (void *)var_name); +} + static struct { zap_io_interface_t *pika_interface; } interfaces; From 1ded02179637877ac15d9604f7c305e3bc7f0e00 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 19:13:32 +0000 Subject: [PATCH 1132/1766] add patch OPENZAP-26 with minor mods git-svn-id: http://svn.openzap.org/svn/openzap/trunk@585 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 14 ++++++++ libs/freetdm/src/include/openzap.h | 4 +++ libs/freetdm/src/zap_io.c | 44 +++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 77f9a79ee0..9539cb7bfb 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -36,6 +36,9 @@ #define __FUNCTION__ __SWITCH_FUNC__ #endif +#define OPENZAP_VAR_PREFIX "openzap_" +#define OPENZAP_VAR_PREFIX_LEN 8 + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); @@ -883,6 +886,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi int direction = ZAP_TOP_DOWN; zap_caller_data_t caller_data = {{ 0 }}; char *span_name = NULL; + switch_event_header_t *h; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -968,6 +972,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + zap_channel_clear_vars(zchan); + for (h = var_event->headers; h; h = h->next) { + if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { + char *v = h->name + OPENZAP_VAR_PREFIX_LEN; + if (!switch_strlen_zero(v)) { + zap_channel_add_var(zchan, v, h->value); + } + } + } + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 567a0e53eb..ae95e34021 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -447,6 +447,7 @@ struct zap_channel { struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; + zap_hash_t *variable_hash; }; @@ -573,6 +574,9 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); +zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); +const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name); +zap_status_t zap_channel_clear_vars(zap_channel_t *zchan); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8d74f9faf6..1472d2e697 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -242,6 +242,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + hashtable_destroy(zchan->variable_hash); zap_safe_free(zchan->dtmf_hangup_buf); @@ -457,7 +458,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); - + new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -2015,6 +2017,46 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data return status; } +zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) +{ + if(zchan->variable_hash) { + hashtable_destroy(zchan->variable_hash); + } + zchan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + + if(!zchan->variable_hash) + return ZAP_FAIL; + + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) +{ + char *t_name = 0, *t_val = 0; + + if(!zchan->variable_hash || !var_name || !value) + { + return ZAP_FAIL; + } + + t_name = strdup(var_name); + t_val = strdup(value); + + if(hashtable_insert(zchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) { + return ZAP_SUCCESS; + } + return ZAP_FAIL; +} + +const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name) +{ + if(!zchan->variable_hash || !var_name) + { + return NULL; + } + return (const char *) hashtable_search(zchan->variable_hash, (void *)var_name); +} + static struct { zap_io_interface_t *pika_interface; } interfaces; From e5f6013b5895ce0d8bed17bcc28513146c2bbf61 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 19:21:27 +0000 Subject: [PATCH 1133/1766] add patch OPENZAP-15 with minor mods git-svn-id: http://svn.openzap.org/svn/openzap/trunk@586 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++ libs/openzap/src/include/zap_types.h | 3 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 56 +++++++++++++++++-- .../src/ozmod/ozmod_analog/zap_analog.h | 2 + libs/openzap/src/zap_io.c | 37 +++++++----- 5 files changed, 82 insertions(+), 20 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 9539cb7bfb..e3dbc247f7 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1586,6 +1586,7 @@ static switch_status_t load_config(void) char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; + char *hotline = NULL; char *dial_regex = NULL; char *hold_music = NULL; char *fail_dial_regex = NULL; @@ -1617,6 +1618,8 @@ static switch_status_t load_config(void) hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { max_digits = val; + } else if (!strcasecmp(var, "hotline")) { + hotline = val; } else if (!strcasecmp(var, "enable-analog-option")) { analog_options = enable_analog_option(val, analog_options); } @@ -1667,6 +1670,7 @@ static switch_status_t load_config(void) "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, + "hotline", hotline, "enable_callerid", enable_callerid, TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index dc34e3f40b..f8ec1ff698 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -298,7 +298,8 @@ typedef enum { 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_CALLERID = (1 << 4), + ZAP_CHANNEL_FEATURE_PROGRESS = (1 << 5) } zap_channel_feature_t; typedef enum { diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index df82fda5f2..62d5f11a2b 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -83,6 +83,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) { zap_analog_data_t *analog_data; const char *tonemap = "us"; + const char *hotline = ""; uint32_t digit_timeout = 10; uint32_t max_dialstr = 11; const char *var, *val; @@ -126,7 +127,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) break; } max_dialstr = *intval; - } + } else if (!strcasecmp(var, "hotline")) { + if (!(val = va_arg(ap, char *))) { + break; + } + hotline = val; + } } @@ -134,7 +140,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) digit_timeout = 2000; } - if (max_dialstr < 2 || max_dialstr > 20) { + if ((max_dialstr < 2 && !strlen(hotline)) || max_dialstr > 20) { max_dialstr = 11; } @@ -143,6 +149,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; analog_data->sig_cb = sig_cb; + strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline)); span->signal_type = ZAP_SIGTYPE_ANALOG; span->signal_data = analog_data; span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call; @@ -562,10 +569,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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))) { + 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; @@ -794,7 +807,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + 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); @@ -808,6 +825,35 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); + } + } } end: @@ -826,7 +872,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { - int waitms = 10; + int waitms = 1000; zap_status_t status; status = zap_span_poll_event(span, waitms); diff --git a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h index 16b7d4f09a..6fde39e9ca 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h @@ -40,11 +40,13 @@ typedef enum { ZAP_ANALOG_CALLERID = (1 << 1) } zap_analog_flag_t; +#define ZAP_MAX_HOTLINE_STR 20 struct zap_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; + char hotline[ZAP_MAX_HOTLINE_STR]; zio_signal_cb_t sig_cb; }; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 1472d2e697..a835a78b62 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -553,7 +553,10 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ if (!zchan->fsk_buffer) { zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); + } else { + zap_buffer_zero(zchan->fsk_buffer); } + if (zchan->token_count > 1) { zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 80, 5, 0, zchan_fsk_write_sample, zchan); zap_fsk_modulator_send_all((&fsk_trans)); @@ -562,6 +565,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ zap_fsk_modulator_send_all((&fsk_trans)); zchan->buffer_delay = 3500 / zchan->effective_interval; } + return ZAP_SUCCESS; } @@ -756,6 +760,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_DIALTONE: + case ZAP_CHANNEL_STATE_COLLECT: case ZAP_CHANNEL_STATE_DIALING: case ZAP_CHANNEL_STATE_RING: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -1321,22 +1326,26 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: { - /* if they don't have thier own, use ours */ - zap_channel_clear_detected_tones(zchan); - zap_channel_clear_needed_tones(zchan); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - GOTO_STATUS(done, ZAP_SUCCESS); + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { + /* if they don't have thier own, use ours */ + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, ZAP_SUCCESS); + } } break; case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - zap_channel_clear_detected_tones(zchan); - zap_channel_clear_needed_tones(zchan); - GOTO_STATUS(done, ZAP_SUCCESS); + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); + GOTO_STATUS(done, ZAP_SUCCESS); + } } break; case ZAP_COMMAND_ENABLE_DTMF_DETECT: @@ -1901,7 +1910,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { uint32_t i; for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { @@ -1916,7 +1925,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); From 8cdc323ca5af03eec5a2457c88aec62a76f2ca98 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 19:21:27 +0000 Subject: [PATCH 1134/1766] add patch OPENZAP-15 with minor mods git-svn-id: http://svn.openzap.org/svn/openzap/trunk@586 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++ libs/freetdm/src/include/zap_types.h | 3 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 56 +++++++++++++++++-- .../src/ozmod/ozmod_analog/zap_analog.h | 2 + libs/freetdm/src/zap_io.c | 37 +++++++----- 5 files changed, 82 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9539cb7bfb..e3dbc247f7 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1586,6 +1586,7 @@ static switch_status_t load_config(void) char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; + char *hotline = NULL; char *dial_regex = NULL; char *hold_music = NULL; char *fail_dial_regex = NULL; @@ -1617,6 +1618,8 @@ static switch_status_t load_config(void) hold_music = val; } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { max_digits = val; + } else if (!strcasecmp(var, "hotline")) { + hotline = val; } else if (!strcasecmp(var, "enable-analog-option")) { analog_options = enable_analog_option(val, analog_options); } @@ -1667,6 +1670,7 @@ static switch_status_t load_config(void) "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, + "hotline", hotline, "enable_callerid", enable_callerid, TAG_END) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index dc34e3f40b..f8ec1ff698 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -298,7 +298,8 @@ typedef enum { 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_CALLERID = (1 << 4), + ZAP_CHANNEL_FEATURE_PROGRESS = (1 << 5) } zap_channel_feature_t; typedef enum { diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index df82fda5f2..62d5f11a2b 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -83,6 +83,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) { zap_analog_data_t *analog_data; const char *tonemap = "us"; + const char *hotline = ""; uint32_t digit_timeout = 10; uint32_t max_dialstr = 11; const char *var, *val; @@ -126,7 +127,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) break; } max_dialstr = *intval; - } + } else if (!strcasecmp(var, "hotline")) { + if (!(val = va_arg(ap, char *))) { + break; + } + hotline = val; + } } @@ -134,7 +140,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) digit_timeout = 2000; } - if (max_dialstr < 2 || max_dialstr > 20) { + if ((max_dialstr < 2 && !strlen(hotline)) || max_dialstr > 20) { max_dialstr = 11; } @@ -143,6 +149,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; analog_data->sig_cb = sig_cb; + strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline)); span->signal_type = ZAP_SIGTYPE_ANALOG; span->signal_data = analog_data; span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call; @@ -562,10 +569,16 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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))) { + 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; @@ -794,7 +807,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even } zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); + 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); @@ -808,6 +825,35 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); + } + } } end: @@ -826,7 +872,7 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { - int waitms = 10; + int waitms = 1000; zap_status_t status; status = zap_span_poll_event(span, waitms); diff --git a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h index 16b7d4f09a..6fde39e9ca 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h @@ -40,11 +40,13 @@ typedef enum { ZAP_ANALOG_CALLERID = (1 << 1) } zap_analog_flag_t; +#define ZAP_MAX_HOTLINE_STR 20 struct zap_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; + char hotline[ZAP_MAX_HOTLINE_STR]; zio_signal_cb_t sig_cb; }; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1472d2e697..a835a78b62 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -553,7 +553,10 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ if (!zchan->fsk_buffer) { zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); + } else { + zap_buffer_zero(zchan->fsk_buffer); } + if (zchan->token_count > 1) { zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 80, 5, 0, zchan_fsk_write_sample, zchan); zap_fsk_modulator_send_all((&fsk_trans)); @@ -562,6 +565,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ zap_fsk_modulator_send_all((&fsk_trans)); zchan->buffer_delay = 3500 / zchan->effective_interval; } + return ZAP_SUCCESS; } @@ -756,6 +760,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta switch(state) { case ZAP_CHANNEL_STATE_DIALTONE: + case ZAP_CHANNEL_STATE_COLLECT: case ZAP_CHANNEL_STATE_DIALING: case ZAP_CHANNEL_STATE_RING: case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -1321,22 +1326,26 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo break; case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: { - /* if they don't have thier own, use ours */ - zap_channel_clear_detected_tones(zchan); - zap_channel_clear_needed_tones(zchan); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - GOTO_STATUS(done, ZAP_SUCCESS); + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { + /* if they don't have thier own, use ours */ + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); + teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); + zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, ZAP_SUCCESS); + } } break; case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - zap_channel_clear_detected_tones(zchan); - zap_channel_clear_needed_tones(zchan); - GOTO_STATUS(done, ZAP_SUCCESS); + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { + zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_channel_clear_detected_tones(zchan); + zap_channel_clear_needed_tones(zchan); + GOTO_STATUS(done, ZAP_SUCCESS); + } } break; case ZAP_COMMAND_ENABLE_DTMF_DETECT: @@ -1901,7 +1910,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { uint32_t i; for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { @@ -1916,7 +1925,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } } - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); From da93edd6adda3d8beaae3465fd828c0b83a17d3c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 20:02:55 +0000 Subject: [PATCH 1135/1766] fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@587 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index e3dbc247f7..7e8173702f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -877,7 +877,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_originate_flag_t flags) { - char *p, *dest = NULL; + char *dest = NULL, *data = NULL; int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -887,6 +887,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_caller_data_t caller_data = {{ 0 }}; char *span_name = NULL; switch_event_header_t *h; + char *argv[3]; + int argc = 0; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -898,30 +900,30 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - dest = outbound_profile->destination_number; - if (switch_is_number(dest)) { - span_id = atoi(dest); - } else { - span_name = dest; + data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); + + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - - if ((p = strchr(dest, '/'))) { - if (*p++) { - if (*p == 'A') { - direction = ZAP_BOTTOM_UP; - } else if (*p == 'a') { - direction = ZAP_TOP_DOWN; - } else { - chan_id = atoi(p); - } - if ((p = strchr(p, '/')) && *++p) { - dest = p; - } - } + if (switch_is_number(argv[0])) { + span_id = atoi(argv[0]); + } else { + span_name = argv[0]; + } + + if (*argv[1] == 'A') { + direction = ZAP_BOTTOM_UP; + } else if (*argv[1] == 'a') { + direction = ZAP_TOP_DOWN; + } else { + chan_id = atoi(argv[1]); } + dest = argv[2]; + if (!span_id && !switch_strlen_zero(span_name)) { zap_span_t *span; zap_status_t zstatus = zap_span_find_by_name(span_name, &span); From d90030872c1753a6c186f48fe48ef606b03a42be Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 6 Oct 2008 20:02:55 +0000 Subject: [PATCH 1136/1766] fix git-svn-id: http://svn.openzap.org/svn/openzap/trunk@587 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index e3dbc247f7..7e8173702f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -877,7 +877,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_originate_flag_t flags) { - char *p, *dest = NULL; + char *dest = NULL, *data = NULL; int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -887,6 +887,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_caller_data_t caller_data = {{ 0 }}; char *span_name = NULL; switch_event_header_t *h; + char *argv[3]; + int argc = 0; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -898,30 +900,30 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - dest = outbound_profile->destination_number; - if (switch_is_number(dest)) { - span_id = atoi(dest); - } else { - span_name = dest; + data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); + + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - - if ((p = strchr(dest, '/'))) { - if (*p++) { - if (*p == 'A') { - direction = ZAP_BOTTOM_UP; - } else if (*p == 'a') { - direction = ZAP_TOP_DOWN; - } else { - chan_id = atoi(p); - } - if ((p = strchr(p, '/')) && *++p) { - dest = p; - } - } + if (switch_is_number(argv[0])) { + span_id = atoi(argv[0]); + } else { + span_name = argv[0]; + } + + if (*argv[1] == 'A') { + direction = ZAP_BOTTOM_UP; + } else if (*argv[1] == 'a') { + direction = ZAP_TOP_DOWN; + } else { + chan_id = atoi(argv[1]); } + dest = argv[2]; + if (!span_id && !switch_strlen_zero(span_name)) { zap_span_t *span; zap_status_t zstatus = zap_span_find_by_name(span_name, &span); From 540ac847102d78f280948c6acd1c6c8b934a1f78 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 7 Oct 2008 00:00:15 +0000 Subject: [PATCH 1137/1766] bail on bad args git-svn-id: http://svn.openzap.org/svn/openzap/trunk@588 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 3 +++ libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 3 +++ libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 +++ libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +++ 4 files changed, 12 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 62d5f11a2b..ad6bd60b48 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -132,6 +132,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) break; } hotline = val; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; } } 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 index ed7f04b903..1d951ec65e 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -108,6 +108,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) break; } max_dialstr = *intval; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; } } diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 04e6eecdf3..c226d72aec 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1750,6 +1750,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } 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; } } diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 9fe9b08292..656b09a9a5 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1119,6 +1119,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) break; } remote_port = *intval; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; } } From a422a4f672176b5314cc8bc78e26ea644bfb1707 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 7 Oct 2008 00:00:15 +0000 Subject: [PATCH 1138/1766] bail on bad args git-svn-id: http://svn.openzap.org/svn/openzap/trunk@588 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 3 +++ libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 3 +++ libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 +++ libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +++ 4 files changed, 12 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 62d5f11a2b..ad6bd60b48 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -132,6 +132,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) break; } hotline = val; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; } } diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index ed7f04b903..1d951ec65e 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -108,6 +108,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) break; } max_dialstr = *intval; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; } } diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 04e6eecdf3..c226d72aec 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1750,6 +1750,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } 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; } } diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 9fe9b08292..656b09a9a5 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1119,6 +1119,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) break; } remote_port = *intval; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; } } From f1e9611fd11661ef52b100e5e91644956630c5e0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 7 Oct 2008 15:27:51 +0000 Subject: [PATCH 1139/1766] OPENZAP-28 pass opts from mod_openzap to ozmod_isdn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@589 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 1 + libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 10 +++++----- libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 7e8173702f..e915c2d368 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1893,6 +1893,7 @@ static switch_status_t load_config(void) if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, + "opts", opts, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index c226d72aec..ca6a7fdd65 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1726,11 +1726,11 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) dialect = Q931_Dialect_National; } } else if (!strcasecmp(var, "opts")) { - int *optp; - if (!(optp = va_arg(ap, int *))) { - break; - } - opts = isdn_data->opts = *optp; + opts = va_arg(ap, uint32_t); + if (opts >= ZAP_ISDN_OPT_MAX) { + return ZAP_FAIL; + } + isdn_data->opts = opts; } else if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index 86a3f40155..cf45908364 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -37,7 +37,9 @@ typedef enum { ZAP_ISDN_OPT_NONE = 0, - ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0) + ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0), + + ZAP_ISDN_OPT_MAX = (2 << 0) } zap_isdn_opts_t; typedef enum { From 564329faee37ed3b42dd7ac13b74eb96b661384c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 7 Oct 2008 15:27:51 +0000 Subject: [PATCH 1140/1766] OPENZAP-28 pass opts from mod_openzap to ozmod_isdn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@589 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 1 + libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 10 +++++----- libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 7e8173702f..e915c2d368 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1893,6 +1893,7 @@ static switch_status_t load_config(void) if (zap_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, + "opts", opts, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index c226d72aec..ca6a7fdd65 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1726,11 +1726,11 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) dialect = Q931_Dialect_National; } } else if (!strcasecmp(var, "opts")) { - int *optp; - if (!(optp = va_arg(ap, int *))) { - break; - } - opts = isdn_data->opts = *optp; + opts = va_arg(ap, uint32_t); + if (opts >= ZAP_ISDN_OPT_MAX) { + return ZAP_FAIL; + } + isdn_data->opts = opts; } else if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { break; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index 86a3f40155..cf45908364 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -37,7 +37,9 @@ typedef enum { ZAP_ISDN_OPT_NONE = 0, - ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0) + ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0), + + ZAP_ISDN_OPT_MAX = (2 << 0) } zap_isdn_opts_t; typedef enum { From 8bc032c6bb429c7e7eee6225d5b249f6b20ecd3a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Oct 2008 01:18:40 +0000 Subject: [PATCH 1141/1766] allow blank dest for calling fxs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@590 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index e915c2d368..fd308a0d5e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -903,7 +903,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); - if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) { + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -922,7 +922,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi chan_id = atoi(argv[1]); } - dest = argv[2]; + if (!(dest = argv[2])) { + dest = ""; + } if (!span_id && !switch_strlen_zero(span_name)) { zap_span_t *span; From 145b9618156a5f30fd5df66cd06768275ea72da2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Oct 2008 01:18:40 +0000 Subject: [PATCH 1142/1766] allow blank dest for calling fxs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@590 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index e915c2d368..fd308a0d5e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -903,7 +903,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); - if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) { + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -922,7 +922,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi chan_id = atoi(argv[1]); } - dest = argv[2]; + if (!(dest = argv[2])) { + dest = ""; + } if (!span_id && !switch_strlen_zero(span_name)) { zap_span_t *span; From d95b0b044213903ec63a6e702753193a00ae6dfd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 9 Oct 2008 19:24:39 +0000 Subject: [PATCH 1143/1766] attempt to fix solaris openzap build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@591 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_wanpipe/wanpipe_tdm_api_iface.h | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) 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 index 3801ff9c8c..cfb4c151ac 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h @@ -187,40 +187,40 @@ enum wanpipe_tdm_api_events { 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; + uint8_t type; + uint8_t mode; + uint32_t time_stamp; + uint8_t channel; + uint32_t chan_map; + uint8_t span; union { struct { - u_int8_t alarm; + uint8_t alarm; } te1_alarm; struct { - u_int8_t rbs_bits; + uint8_t rbs_bits; } te1_rbs; struct { - u_int8_t state; - u_int8_t sig; + uint8_t state; + uint8_t sig; } rm_hook; struct { - u_int8_t state; + uint8_t state; } rm_ring; struct { - u_int8_t type; + uint8_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 */ + uint8_t digit; /* DTMF: digit */ + uint8_t port; /* DTMF: SOUT/ROUT */ + uint8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - u_int16_t polarity; - u_int16_t ohttimer; + uint16_t polarity; + uint16_t ohttimer; } rm_common; struct{ - u_int16_t status; + uint16_t status; } linkstatus; } wp_tdm_api_event_u; #define wp_tdm_api_event_type type From e5124abc4b2ca5bd8d7c66b3027938e706974db4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 9 Oct 2008 19:24:39 +0000 Subject: [PATCH 1144/1766] attempt to fix solaris openzap build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@591 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_wanpipe/wanpipe_tdm_api_iface.h | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h index 3801ff9c8c..cfb4c151ac 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h @@ -187,40 +187,40 @@ enum wanpipe_tdm_api_events { 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; + uint8_t type; + uint8_t mode; + uint32_t time_stamp; + uint8_t channel; + uint32_t chan_map; + uint8_t span; union { struct { - u_int8_t alarm; + uint8_t alarm; } te1_alarm; struct { - u_int8_t rbs_bits; + uint8_t rbs_bits; } te1_rbs; struct { - u_int8_t state; - u_int8_t sig; + uint8_t state; + uint8_t sig; } rm_hook; struct { - u_int8_t state; + uint8_t state; } rm_ring; struct { - u_int8_t type; + uint8_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 */ + uint8_t digit; /* DTMF: digit */ + uint8_t port; /* DTMF: SOUT/ROUT */ + uint8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - u_int16_t polarity; - u_int16_t ohttimer; + uint16_t polarity; + uint16_t ohttimer; } rm_common; struct{ - u_int16_t status; + uint16_t status; } linkstatus; } wp_tdm_api_event_u; #define wp_tdm_api_event_type type From 5910cd957bd85ad9b087504f818a9f57a19ccc5a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 10 Oct 2008 16:02:09 +0000 Subject: [PATCH 1145/1766] OPENZAP-27 add inital CAS support to wanpipe and zt git-svn-id: http://svn.openzap.org/svn/openzap/trunk@592 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_config.h | 7 +++ libs/openzap/src/include/zap_types.h | 8 ++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 60 +++++++++++++++++-- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 51 ++++++++++++++-- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h | 13 +++- libs/openzap/src/zap_config.c | 32 +++++++++- libs/openzap/src/zap_io.c | 5 ++ 8 files changed, 165 insertions(+), 12 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index ae95e34021..e0974326ca 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -448,6 +448,7 @@ struct zap_channel { struct zap_span *span; struct zap_io_interface *zio; zap_hash_t *variable_hash; + unsigned char cas_bits; }; diff --git a/libs/openzap/src/include/zap_config.h b/libs/openzap/src/include/zap_config.h index 0b37208666..f550029388 100644 --- a/libs/openzap/src/include/zap_config.h +++ b/libs/openzap/src/include/zap_config.h @@ -116,6 +116,13 @@ void zap_config_close_file(zap_config_t * cfg); */ 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 +*/ +int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); + /** @} */ #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index f8ec1ff698..1998465bbb 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -150,9 +150,10 @@ typedef enum { 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", "INVALID" +#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 { @@ -270,6 +271,8 @@ typedef enum { ZAP_COMMAND_DISABLE_ECHOCANCEL, ZAP_COMMAND_ENABLE_ECHOTRAIN, ZAP_COMMAND_DISABLE_ECHOTRAIN, + ZAP_COMMAND_SET_CAS_BITS, + ZAP_COMMAND_GET_CAS_BITS, ZAP_COMMAND_COUNT } zap_command_t; @@ -287,10 +290,11 @@ typedef enum { 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", "INVALID" +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) typedef enum { diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index acf9ab28c0..3be93f2e01 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -346,10 +346,31 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm return ZAP_SUCCESS; } -static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) +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; +} + +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; + 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 *chan; zap_socket_t sockfd = WP_INVALID_SOCKET; @@ -401,6 +422,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + + if (type == ZAP_CHAN_TYPE_CAS) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; + tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); + wp_tdm_cmd_exec(chan, &tdm_api); + } if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); @@ -452,8 +479,9 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) { int items, i; - char *mydata, *item_list[10]; + char *mydata, *item_list[10]; char *sp, *ch, *mx; + unsigned char cas_bits = 0; int channo; int spanno; int top = 0; @@ -506,8 +534,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); continue; } - - configured += wp_open_range(span, spanno, channo, top, type, name, number); + 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); } @@ -622,6 +653,19 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); } break; + case ZAP_COMMAND_SET_CAS_BITS: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; + tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); + err = wp_tdm_cmd_exec(zchan, &tdm_api); + } + break; + case ZAP_COMMAND_GET_CAS_BITS: + { + /* wanpipe does not has a command to get the CAS bits so we emulate it */ + ZAP_COMMAND_OBJ_INT = zchan->cas_bits; + } + break; default: break; }; @@ -899,6 +943,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; + /* save the CAS bits, user should retrieve it with ZAP_COMMAND_GET_CAS_BITS + is there a best play to store this? instead of adding cas_bits member to zap_chan? */ + span->channels[i]->cas_bits = wanpipe_swap_bits(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rbs_bits); + } + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 43a662d9fd..4d5c7c7c01 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -51,7 +51,7 @@ 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); -static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) +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; char path[] = "/dev/zap/channel"; @@ -59,6 +59,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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; @@ -136,6 +139,19 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } + 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, ZT_CHANCONFIG, &cc)) { + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s", path, 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, ZT_SET_BLOCKSIZE, &len)) { @@ -224,8 +240,9 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { int items, i; - char *mydata, *item_list[10]; + char *mydata, *item_list[10]; char *ch, *mx; + unsigned char cas_bits = 0; int channo; int top = 0; unsigned configured = 0; @@ -266,8 +283,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); continue; } - - configured += zt_open_range(span, channo, top, type, name, number); + 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); } @@ -471,6 +491,18 @@ static ZIO_COMMAND_FUNCTION(zt_command) } } break; + case ZAP_COMMAND_SET_CAS_BITS: + { + int bits = ZAP_COMMAND_OBJ_INT; + err = ioctl(zchan->sockfd, ZT_SETTXBITS, &bits); + } + break; + case ZAP_COMMAND_GET_CAS_BITS: + { + /* probably we should call ZT_GETRXBITS instead? */ + ZAP_COMMAND_OBJ_INT = zchan->cas_bits; + } + break; default: break; }; @@ -663,6 +695,17 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) event_id = ZAP_OOB_ALARM_CLEAR; } break; + case ZT_EVENT_BITSCHANGED: + { + event_id = ZAP_OOB_CAS_BITS_CHANGE; + int bits = 0; + int err = ioctl(span->channels[i]->sockfd, ZT_GETRXBITS, &bits); + if (err) { + return ZAP_FAIL; + } + span->channels[i]->cas_bits = bits; + } + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h index c3e2067585..d965de4b93 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h @@ -226,9 +226,16 @@ 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_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW), +ZT_SIG_CAS = (1 << 15) } zt_sigtype_t; +typedef enum { +ZT_DBIT = 1, +ZT_CBIT = 2, +ZT_BBIT = 4, +ZT_ABIT = 8 +} zt_cas_bit_t; /* Defines */ @@ -279,6 +286,10 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #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) + #endif diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index cce3507f25..b1f6bd90c4 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -53,7 +53,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) memset(cfg, 0, sizeof(*cfg)); cfg->lockto = -1; - + zap_log(ZAP_LOG_DEBUG, "Configuration file is %s.\n", path); f = fopen(path, "r"); if (!f) { @@ -209,6 +209,36 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } +int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) +{ + char cas_bits[5]; + unsigned char bit = 0x8; + 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", double_colon); + 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); + int x = 0; + 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 diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a835a78b62..444f3b85fb 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2239,9 +2239,13 @@ static zap_status_t load_config(void) configured += zio->configure_span(span, val, qtype, name, number); d++; } + } else if (!strcasecmp(var, "cas-channel")) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_CAS, name, number); } else if (!strcasecmp(var, "dtmf_hangup")) { span->dtmf_hangup = strdup(val); span->dtmf_hangup_len = strlen(val); + } else { + zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); @@ -2500,6 +2504,7 @@ zap_status_t zap_global_init(void) zap_mutex_create(&globals.mutex); modcount = zap_load_modules(); + zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); if (load_config() == ZAP_SUCCESS) { globals.running = 1; From 18baa59c02947b3b52b363d4e78b40f8d756c160 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 10 Oct 2008 16:02:09 +0000 Subject: [PATCH 1146/1766] OPENZAP-27 add inital CAS support to wanpipe and zt git-svn-id: http://svn.openzap.org/svn/openzap/trunk@592 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_config.h | 7 +++ libs/freetdm/src/include/zap_types.h | 8 ++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 60 +++++++++++++++++-- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 51 ++++++++++++++-- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h | 13 +++- libs/freetdm/src/zap_config.c | 32 +++++++++- libs/freetdm/src/zap_io.c | 5 ++ 8 files changed, 165 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ae95e34021..e0974326ca 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -448,6 +448,7 @@ struct zap_channel { struct zap_span *span; struct zap_io_interface *zio; zap_hash_t *variable_hash; + unsigned char cas_bits; }; diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h index 0b37208666..f550029388 100644 --- a/libs/freetdm/src/include/zap_config.h +++ b/libs/freetdm/src/include/zap_config.h @@ -116,6 +116,13 @@ void zap_config_close_file(zap_config_t * cfg); */ 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 +*/ +int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); + /** @} */ #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index f8ec1ff698..1998465bbb 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -150,9 +150,10 @@ typedef enum { 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", "INVALID" +#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 { @@ -270,6 +271,8 @@ typedef enum { ZAP_COMMAND_DISABLE_ECHOCANCEL, ZAP_COMMAND_ENABLE_ECHOTRAIN, ZAP_COMMAND_DISABLE_ECHOTRAIN, + ZAP_COMMAND_SET_CAS_BITS, + ZAP_COMMAND_GET_CAS_BITS, ZAP_COMMAND_COUNT } zap_command_t; @@ -287,10 +290,11 @@ typedef enum { 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", "INVALID" +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) typedef enum { diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index acf9ab28c0..3be93f2e01 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -346,10 +346,31 @@ static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm return ZAP_SUCCESS; } -static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) +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; +} + +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; + 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 *chan; zap_socket_t sockfd = WP_INVALID_SOCKET; @@ -401,6 +422,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } } + + if (type == ZAP_CHAN_TYPE_CAS) { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; + tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); + wp_tdm_cmd_exec(chan, &tdm_api); + } if (!zap_strlen_zero(name)) { zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); @@ -452,8 +479,9 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) { int items, i; - char *mydata, *item_list[10]; + char *mydata, *item_list[10]; char *sp, *ch, *mx; + unsigned char cas_bits = 0; int channo; int spanno; int top = 0; @@ -506,8 +534,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); continue; } - - configured += wp_open_range(span, spanno, channo, top, type, name, number); + 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); } @@ -622,6 +653,19 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); } break; + case ZAP_COMMAND_SET_CAS_BITS: + { + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; + tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); + err = wp_tdm_cmd_exec(zchan, &tdm_api); + } + break; + case ZAP_COMMAND_GET_CAS_BITS: + { + /* wanpipe does not has a command to get the CAS bits so we emulate it */ + ZAP_COMMAND_OBJ_INT = zchan->cas_bits; + } + break; default: break; }; @@ -899,6 +943,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; + /* save the CAS bits, user should retrieve it with ZAP_COMMAND_GET_CAS_BITS + is there a best play to store this? instead of adding cas_bits member to zap_chan? */ + span->channels[i]->cas_bits = wanpipe_swap_bits(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rbs_bits); + } + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 43a662d9fd..4d5c7c7c01 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -51,7 +51,7 @@ 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); -static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number) +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; char path[] = "/dev/zap/channel"; @@ -59,6 +59,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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; @@ -136,6 +139,19 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } + 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, ZT_CHANCONFIG, &cc)) { + zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s", path, 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, ZT_SET_BLOCKSIZE, &len)) { @@ -224,8 +240,9 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { int items, i; - char *mydata, *item_list[10]; + char *mydata, *item_list[10]; char *ch, *mx; + unsigned char cas_bits = 0; int channo; int top = 0; unsigned configured = 0; @@ -266,8 +283,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); continue; } - - configured += zt_open_range(span, channo, top, type, name, number); + 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); } @@ -471,6 +491,18 @@ static ZIO_COMMAND_FUNCTION(zt_command) } } break; + case ZAP_COMMAND_SET_CAS_BITS: + { + int bits = ZAP_COMMAND_OBJ_INT; + err = ioctl(zchan->sockfd, ZT_SETTXBITS, &bits); + } + break; + case ZAP_COMMAND_GET_CAS_BITS: + { + /* probably we should call ZT_GETRXBITS instead? */ + ZAP_COMMAND_OBJ_INT = zchan->cas_bits; + } + break; default: break; }; @@ -663,6 +695,17 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) event_id = ZAP_OOB_ALARM_CLEAR; } break; + case ZT_EVENT_BITSCHANGED: + { + event_id = ZAP_OOB_CAS_BITS_CHANGE; + int bits = 0; + int err = ioctl(span->channels[i]->sockfd, ZT_GETRXBITS, &bits); + if (err) { + return ZAP_FAIL; + } + span->channels[i]->cas_bits = bits; + } + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h index c3e2067585..d965de4b93 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h @@ -226,9 +226,16 @@ 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_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW), +ZT_SIG_CAS = (1 << 15) } zt_sigtype_t; +typedef enum { +ZT_DBIT = 1, +ZT_CBIT = 2, +ZT_BBIT = 4, +ZT_ABIT = 8 +} zt_cas_bit_t; /* Defines */ @@ -279,6 +286,10 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #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) + #endif diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index cce3507f25..b1f6bd90c4 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -53,7 +53,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) memset(cfg, 0, sizeof(*cfg)); cfg->lockto = -1; - + zap_log(ZAP_LOG_DEBUG, "Configuration file is %s.\n", path); f = fopen(path, "r"); if (!f) { @@ -209,6 +209,36 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } +int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) +{ + char cas_bits[5]; + unsigned char bit = 0x8; + 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", double_colon); + 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); + int x = 0; + 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 diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a835a78b62..444f3b85fb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2239,9 +2239,13 @@ static zap_status_t load_config(void) configured += zio->configure_span(span, val, qtype, name, number); d++; } + } else if (!strcasecmp(var, "cas-channel")) { + configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_CAS, name, number); } else if (!strcasecmp(var, "dtmf_hangup")) { span->dtmf_hangup = strdup(val); span->dtmf_hangup_len = strlen(val); + } else { + zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); @@ -2500,6 +2504,7 @@ zap_status_t zap_global_init(void) zap_mutex_create(&globals.mutex); modcount = zap_load_modules(); + zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); if (load_config() == ZAP_SUCCESS) { globals.running = 1; From 35ee397cd1f7162aed583121e2aa1039745e2777 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 12 Oct 2008 22:07:45 +0000 Subject: [PATCH 1147/1766] Add NT-mode overlap dial timeout and fix CID in overlap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@593 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/.gitignore | 3 +- libs/openzap/mod_openzap/mod_openzap.c | 13 +- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 115 +++++++++++++----- libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 16 ++- 4 files changed, 112 insertions(+), 35 deletions(-) diff --git a/libs/openzap/.gitignore b/libs/openzap/.gitignore index e767f23aa1..d90d79d08d 100644 --- a/libs/openzap/.gitignore +++ b/libs/openzap/.gitignore @@ -9,4 +9,5 @@ Makefile config.* configure - +libtool +aclocal.m4 diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index fd308a0d5e..86108913b0 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1830,6 +1830,8 @@ static switch_status_t load_config(void) uint32_t span_id = 0; zap_span_t *span = NULL; char *tonegroup = NULL; + char *digit_timeout = NULL; + uint32_t to = 0; uint32_t opts = 0; int q921loglevel = -1; int q931loglevel = -1; @@ -1858,7 +1860,9 @@ static switch_status_t load_config(void) opts |= 1; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; - } + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { + digit_timeout = val; + } } if (!id && !name) { @@ -1879,6 +1883,10 @@ static switch_status_t load_config(void) } } + if (digit_timeout) { + to = atoi(digit_timeout); + } + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; @@ -1893,8 +1901,9 @@ static switch_status_t load_config(void) } if (zap_configure_span("isdn", span, on_clear_channel_signal, - "mode", mode, + "mode", mode, "dialect", dialect, + "digit_timeout", &to, "opts", opts, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index ca6a7fdd65..ee97409504 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -48,6 +48,7 @@ #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) + static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); @@ -596,10 +597,16 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); - zap_set_string(zchan->caller_data.dnis.digits, (char *)callednum->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)) { @@ -718,6 +725,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * 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; @@ -727,13 +735,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } /* TODO: make this more safe with strncat() */ - pos = strlen(zchan->caller_data.cid_num.digits); - strcat(&zchan->caller_data.cid_num.digits[pos], (char *)callednum->Digit); - strcat(&zchan->caller_data.cid_name[pos], (char *)callednum->Digit); - strcat(&zchan->caller_data.ani.digits[pos], (char *)callednum->Digit); + pos = strlen(zchan->caller_data.dnis.digits); strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); - zap_log(ZAP_LOG_DEBUG, "Received new overlap digit (%s), destination number: %s\n", callednum->Digit, zchan->caller_data.cid_num.digits); + /* 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 == '#') { @@ -861,16 +869,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_DIALTONE: { -/* - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - 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; - } - } + 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: @@ -1274,6 +1277,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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 @@ -1294,6 +1298,23 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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]); @@ -1671,8 +1692,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; - int q921loglevel = -1; - int q931loglevel = -1; + int32_t digit_timeout = 0; + int q921loglevel = -1; + int q931loglevel = -1; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1727,40 +1749,73 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } } else if (!strcasecmp(var, "opts")) { opts = va_arg(ap, uint32_t); - if (opts >= ZAP_ISDN_OPT_MAX) { - return ZAP_FAIL; - } + if (opts >= ZAP_ISDN_OPT_MAX) { + return ZAP_FAIL; + } isdn_data->opts = opts; } 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; - } + 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; - } + 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; isdn_data->sig_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, diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index cf45908364..14b2731db5 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -35,6 +35,9 @@ #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), @@ -56,16 +59,25 @@ struct zap_isdn_data { zio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; + int32_t digit_timeout; zap_isdn_opts_t opts; zap_caller_data_t *outbound_crv[32768]; zap_channel_t *channels_local_crv[32768]; zap_channel_t *channels_remote_crv[32768]; }; - - typedef struct zap_isdn_data zap_isdn_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: From 4c4047d5cf4ac1b85789149203d2dca1e9d8e006 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 12 Oct 2008 22:07:45 +0000 Subject: [PATCH 1148/1766] Add NT-mode overlap dial timeout and fix CID in overlap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@593 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/.gitignore | 3 +- libs/freetdm/mod_openzap/mod_openzap.c | 13 +- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 115 +++++++++++++----- libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h | 16 ++- 4 files changed, 112 insertions(+), 35 deletions(-) diff --git a/libs/freetdm/.gitignore b/libs/freetdm/.gitignore index e767f23aa1..d90d79d08d 100644 --- a/libs/freetdm/.gitignore +++ b/libs/freetdm/.gitignore @@ -9,4 +9,5 @@ Makefile config.* configure - +libtool +aclocal.m4 diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index fd308a0d5e..86108913b0 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1830,6 +1830,8 @@ static switch_status_t load_config(void) uint32_t span_id = 0; zap_span_t *span = NULL; char *tonegroup = NULL; + char *digit_timeout = NULL; + uint32_t to = 0; uint32_t opts = 0; int q921loglevel = -1; int q931loglevel = -1; @@ -1858,7 +1860,9 @@ static switch_status_t load_config(void) opts |= 1; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; - } + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { + digit_timeout = val; + } } if (!id && !name) { @@ -1879,6 +1883,10 @@ static switch_status_t load_config(void) } } + if (digit_timeout) { + to = atoi(digit_timeout); + } + if (zstatus != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); continue; @@ -1893,8 +1901,9 @@ static switch_status_t load_config(void) } if (zap_configure_span("isdn", span, on_clear_channel_signal, - "mode", mode, + "mode", mode, "dialect", dialect, + "digit_timeout", &to, "opts", opts, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index ca6a7fdd65..ee97409504 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -48,6 +48,7 @@ #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) + static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); @@ -596,10 +597,16 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); - zap_set_string(zchan->caller_data.dnis.digits, (char *)callednum->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)) { @@ -718,6 +725,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * 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; @@ -727,13 +735,13 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } /* TODO: make this more safe with strncat() */ - pos = strlen(zchan->caller_data.cid_num.digits); - strcat(&zchan->caller_data.cid_num.digits[pos], (char *)callednum->Digit); - strcat(&zchan->caller_data.cid_name[pos], (char *)callednum->Digit); - strcat(&zchan->caller_data.ani.digits[pos], (char *)callednum->Digit); + pos = strlen(zchan->caller_data.dnis.digits); strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); - zap_log(ZAP_LOG_DEBUG, "Received new overlap digit (%s), destination number: %s\n", callednum->Digit, zchan->caller_data.cid_num.digits); + /* 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 == '#') { @@ -861,16 +869,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_DIALTONE: { -/* - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - 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; - } - } + 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: @@ -1274,6 +1277,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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 @@ -1294,6 +1298,23 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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]); @@ -1671,8 +1692,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; uint32_t opts = 0; - int q921loglevel = -1; - int q931loglevel = -1; + int32_t digit_timeout = 0; + int q921loglevel = -1; + int q931loglevel = -1; if (span->signal_type) { snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); @@ -1727,40 +1749,73 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } } else if (!strcasecmp(var, "opts")) { opts = va_arg(ap, uint32_t); - if (opts >= ZAP_ISDN_OPT_MAX) { - return ZAP_FAIL; - } + if (opts >= ZAP_ISDN_OPT_MAX) { + return ZAP_FAIL; + } isdn_data->opts = opts; } 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; - } + 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; - } + 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; isdn_data->sig_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, diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index cf45908364..14b2731db5 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -35,6 +35,9 @@ #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), @@ -56,16 +59,25 @@ struct zap_isdn_data { zio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; + int32_t digit_timeout; zap_isdn_opts_t opts; zap_caller_data_t *outbound_crv[32768]; zap_channel_t *channels_local_crv[32768]; zap_channel_t *channels_remote_crv[32768]; }; - - typedef struct zap_isdn_data zap_isdn_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: From f87ff68d0e7a98369f1c22f7cd3734013f7b332a Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 13 Oct 2008 05:44:15 +0000 Subject: [PATCH 1149/1766] oops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@594 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index ee97409504..ffee6f7b20 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1764,7 +1764,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) break; } digit_timeout = *optp; - } } else if (!strcasecmp(var, "q921loglevel")) { q921loglevel = va_arg(ap, int); if (q921loglevel < Q921_LOG_NONE) { From 71e753165553788c214e76a4bc50a81988886247 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 13 Oct 2008 05:44:15 +0000 Subject: [PATCH 1150/1766] oops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@594 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index ee97409504..ffee6f7b20 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1764,7 +1764,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) break; } digit_timeout = *optp; - } } else if (!strcasecmp(var, "q921loglevel")) { q921loglevel = va_arg(ap, int); if (q921loglevel < Q921_LOG_NONE) { From d556d15e7c96194542c0a007eb2e4091a2777e49 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 17 Oct 2008 23:00:47 +0000 Subject: [PATCH 1151/1766] fix FSCORE-206 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@595 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 86108913b0..c602588fbf 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -71,7 +71,8 @@ typedef enum { TFLAG_DTMF = (1 << 1), TFLAG_CODEC = (1 << 2), TFLAG_BREAK = (1 << 3), - TFLAG_HOLD = (1 << 4) + TFLAG_HOLD = (1 << 4), + TFLAG_DEAD = (1 << 5) } TFLAGS; static struct { @@ -341,7 +342,8 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); switch_set_flag_locked(tech_pvt, TFLAG_CODEC); tech_pvt->read_frame.codec = &tech_pvt->read_codec; - + switch_set_flag_locked(tech_pvt, TFLAG_IO); + return SWITCH_STATUS_SUCCESS; } @@ -357,7 +359,6 @@ static switch_status_t channel_on_init(switch_core_session_t *session) channel = switch_core_session_get_channel(session); assert(channel != NULL); - switch_set_flag_locked(tech_pvt, TFLAG_IO); /* Move channel's state machine to ROUTING */ switch_channel_set_state(channel, CS_ROUTING); @@ -493,6 +494,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int switch (sig) { case SWITCH_SIG_KILL: switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); break; case SWITCH_SIG_BREAK: switch_set_flag_locked(tech_pvt, TFLAG_BREAK); @@ -553,6 +555,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch chunk = tech_pvt->zchan->effective_interval * 2; total_to = chunk * 2; + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + return SWITCH_STATUS_FALSE; + } + top: if (switch_channel_test_flag(channel, CF_SUSPEND)) { @@ -566,9 +572,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch if (switch_test_flag(tech_pvt, TFLAG_HOLD) || do_break) { switch_yield(tech_pvt->zchan->effective_interval * 1000); - *frame = &tech_pvt->cng_frame; tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; tech_pvt->cng_frame.samples = tech_pvt->cng_frame.datalen; + tech_pvt->cng_frame.flags = SFF_CNG; + *frame = &tech_pvt->cng_frame; if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { tech_pvt->cng_frame.samples /= 2; } @@ -651,6 +658,10 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc assert(tech_pvt->zchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + return SWITCH_STATUS_FALSE; + } + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { return SWITCH_STATUS_SUCCESS; } From 4277fe8eed4d3a48a22a7bda96e56aaf090b8d96 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 17 Oct 2008 23:00:47 +0000 Subject: [PATCH 1152/1766] fix FSCORE-206 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@595 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 86108913b0..c602588fbf 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -71,7 +71,8 @@ typedef enum { TFLAG_DTMF = (1 << 1), TFLAG_CODEC = (1 << 2), TFLAG_BREAK = (1 << 3), - TFLAG_HOLD = (1 << 4) + TFLAG_HOLD = (1 << 4), + TFLAG_DEAD = (1 << 5) } TFLAGS; static struct { @@ -341,7 +342,8 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); switch_set_flag_locked(tech_pvt, TFLAG_CODEC); tech_pvt->read_frame.codec = &tech_pvt->read_codec; - + switch_set_flag_locked(tech_pvt, TFLAG_IO); + return SWITCH_STATUS_SUCCESS; } @@ -357,7 +359,6 @@ static switch_status_t channel_on_init(switch_core_session_t *session) channel = switch_core_session_get_channel(session); assert(channel != NULL); - switch_set_flag_locked(tech_pvt, TFLAG_IO); /* Move channel's state machine to ROUTING */ switch_channel_set_state(channel, CS_ROUTING); @@ -493,6 +494,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int switch (sig) { case SWITCH_SIG_KILL: switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); break; case SWITCH_SIG_BREAK: switch_set_flag_locked(tech_pvt, TFLAG_BREAK); @@ -553,6 +555,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch chunk = tech_pvt->zchan->effective_interval * 2; total_to = chunk * 2; + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + return SWITCH_STATUS_FALSE; + } + top: if (switch_channel_test_flag(channel, CF_SUSPEND)) { @@ -566,9 +572,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch if (switch_test_flag(tech_pvt, TFLAG_HOLD) || do_break) { switch_yield(tech_pvt->zchan->effective_interval * 1000); - *frame = &tech_pvt->cng_frame; tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; tech_pvt->cng_frame.samples = tech_pvt->cng_frame.datalen; + tech_pvt->cng_frame.flags = SFF_CNG; + *frame = &tech_pvt->cng_frame; if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { tech_pvt->cng_frame.samples /= 2; } @@ -651,6 +658,10 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc assert(tech_pvt->zchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + return SWITCH_STATUS_FALSE; + } + if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { return SWITCH_STATUS_SUCCESS; } From 3ee051544b75c92f4150d99b213aa0811e764b87 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 20 Oct 2008 18:10:37 +0000 Subject: [PATCH 1153/1766] change to reflect new code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@596 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c602588fbf..d49775cd71 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -673,7 +673,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (switch_test_flag(frame, SFF_CNG)) { frame->data = data; frame->buflen = sizeof(data); - if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_frame) > frame->buflen) { + if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_packet) > frame->buflen) { goto fail; } memset(data, 255, frame->datalen); From 843a36f74de7f91f91d1e6c3417a9de46b1c32fe Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 20 Oct 2008 18:10:37 +0000 Subject: [PATCH 1154/1766] change to reflect new code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@596 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c602588fbf..d49775cd71 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -673,7 +673,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc if (switch_test_flag(frame, SFF_CNG)) { frame->data = data; frame->buflen = sizeof(data); - if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_frame) > frame->buflen) { + if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_packet) > frame->buflen) { goto fail; } memset(data, 255, frame->datalen); From 38668daa86c1d365d033c913910ed41a37c080a1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 19:40:45 +0000 Subject: [PATCH 1155/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@597 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 444f3b85fb..fb6abf3931 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2138,7 +2138,7 @@ static zap_status_t load_config(void) zap_mutex_lock(globals.mutex); if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { - zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", span->span_id); + zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, span->span_id); name = NULL; } From 4072689a67358a110d005bb36963d3fee87d1bbd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 19:40:45 +0000 Subject: [PATCH 1156/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@597 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 444f3b85fb..fb6abf3931 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2138,7 +2138,7 @@ static zap_status_t load_config(void) zap_mutex_lock(globals.mutex); if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { - zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", span->span_id); + zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, span->span_id); name = NULL; } From e1ad4f2785d8dbf26f9e65e10f5755b70fe262f7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 19:53:56 +0000 Subject: [PATCH 1157/1766] add name to oz list git-svn-id: http://svn.openzap.org/svn/openzap/trunk@598 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d49775cd71..4c685361b3 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2121,7 +2121,7 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "+OK\n" - "span: %u\n" + "span: %u (%s)\n" "type: %s\n" "chan_count: %u\n" "dialplan: %s\n" @@ -2131,6 +2131,7 @@ SWITCH_STANDARD_API(oz_function) "hold_music: %s\n" "analog_options %s\n", j, + SPAN_CONFIG[j].span->name, SPAN_CONFIG[j].type, SPAN_CONFIG[j].span->chan_count, SPAN_CONFIG[j].dialplan, From 8f8d75cc2bae0302f91c4901609d931a639c4e46 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 19:53:56 +0000 Subject: [PATCH 1158/1766] add name to oz list git-svn-id: http://svn.openzap.org/svn/openzap/trunk@598 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d49775cd71..4c685361b3 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2121,7 +2121,7 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "+OK\n" - "span: %u\n" + "span: %u (%s)\n" "type: %s\n" "chan_count: %u\n" "dialplan: %s\n" @@ -2131,6 +2131,7 @@ SWITCH_STANDARD_API(oz_function) "hold_music: %s\n" "analog_options %s\n", j, + SPAN_CONFIG[j].span->name, SPAN_CONFIG[j].type, SPAN_CONFIG[j].span->chan_count, SPAN_CONFIG[j].dialplan, From be418cf51427405eff7de1b1c5bbb41368843d95 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 20:41:52 +0000 Subject: [PATCH 1159/1766] change log message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@599 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 4c685361b3..f532274b50 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1880,7 +1880,7 @@ static switch_status_t load_config(void) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } - + if (name) { zstatus = zap_span_find_by_name(name, &span); } else { @@ -1899,7 +1899,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s\n", id); continue; } From 06f51244b65f58b55b17b09ec300a880b2973845 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 20:41:52 +0000 Subject: [PATCH 1160/1766] change log message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@599 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 4c685361b3..f532274b50 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1880,7 +1880,7 @@ static switch_status_t load_config(void) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); continue; } - + if (name) { zstatus = zap_span_find_by_name(name, &span); } else { @@ -1899,7 +1899,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s\n", id); continue; } From 7c5876912240ea9b5efe779b154a03d69865cbfa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 20:44:37 +0000 Subject: [PATCH 1161/1766] change log message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@600 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index f532274b50..d20d382e3d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1899,7 +1899,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s\n", id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s %s\n", switch_str_nil(id), switch_str_nil(name)); continue; } From 3906f66859939eb45f1e5546b239f98a777871b5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 20:44:37 +0000 Subject: [PATCH 1162/1766] change log message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@600 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index f532274b50..d20d382e3d 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1899,7 +1899,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s\n", id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s %s\n", switch_str_nil(id), switch_str_nil(name)); continue; } From ea63035f3a3e05f7023b0bfb242257e72be73929 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 20:52:45 +0000 Subject: [PATCH 1163/1766] fix log git-svn-id: http://svn.openzap.org/svn/openzap/trunk@601 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d20d382e3d..6def11afe8 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1673,7 +1673,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1788,7 +1788,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1899,7 +1899,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s %s\n", switch_str_nil(id), switch_str_nil(name)); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1991,7 +1991,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } From 9637d0195415f337ab28e961ad0a6a565085a0f3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Oct 2008 20:52:45 +0000 Subject: [PATCH 1164/1766] fix log git-svn-id: http://svn.openzap.org/svn/openzap/trunk@601 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d20d382e3d..6def11afe8 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1673,7 +1673,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1788,7 +1788,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1899,7 +1899,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %s %s\n", switch_str_nil(id), switch_str_nil(name)); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1991,7 +1991,7 @@ static switch_status_t load_config(void) } if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span %d\n", span_id); + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } From 1b51c77f6f2de941d5c8686a40992937b720842d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 15:58:58 +0000 Subject: [PATCH 1165/1766] move copyright headers to the top git-svn-id: http://svn.openzap.org/svn/openzap/trunk@602 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/hashtable.c | 66 ++++++++++++++++---------------- libs/openzap/src/hashtable_itr.c | 66 ++++++++++++++++---------------- 2 files changed, 64 insertions(+), 68 deletions(-) diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index bc5d76475b..d9e0a30a9f 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -1,4 +1,35 @@ -/* Copyright (C) 2004 Christopher Clark */ +/* + * Copyright (c) 2002, Christopher Clark + * 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 "hashtable.h" #include "hashtable_private.h" @@ -295,39 +326,6 @@ void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, v } -/* - * Copyright (c) 2002, Christopher Clark - * 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. - */ - /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c index a60965e911..8519ab3c77 100644 --- a/libs/openzap/src/hashtable_itr.c +++ b/libs/openzap/src/hashtable_itr.c @@ -1,4 +1,35 @@ -/* Copyright (C) 2002, 2004 Christopher Clark */ +/* + * Copyright (c) 2002, 2004, Christopher Clark + * 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 "hashtable.h" #include "hashtable_private.h" @@ -142,39 +173,6 @@ hashtable_iterator_search(struct hashtable_itr *itr, } -/* - * Copyright (c) 2002, 2004, Christopher Clark - * 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. - */ - /* For Emacs: * Local Variables: * mode:c From 97d9169d856591fbfcb1a24f2cd0fab46e121804 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 15:58:58 +0000 Subject: [PATCH 1166/1766] move copyright headers to the top git-svn-id: http://svn.openzap.org/svn/openzap/trunk@602 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/hashtable.c | 66 ++++++++++++++++---------------- libs/freetdm/src/hashtable_itr.c | 66 ++++++++++++++++---------------- 2 files changed, 64 insertions(+), 68 deletions(-) diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index bc5d76475b..d9e0a30a9f 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -1,4 +1,35 @@ -/* Copyright (C) 2004 Christopher Clark */ +/* + * Copyright (c) 2002, Christopher Clark + * 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 "hashtable.h" #include "hashtable_private.h" @@ -295,39 +326,6 @@ void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, v } -/* - * Copyright (c) 2002, Christopher Clark - * 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. - */ - /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index a60965e911..8519ab3c77 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -1,4 +1,35 @@ -/* Copyright (C) 2002, 2004 Christopher Clark */ +/* + * Copyright (c) 2002, 2004, Christopher Clark + * 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 "hashtable.h" #include "hashtable_private.h" @@ -142,39 +173,6 @@ hashtable_iterator_search(struct hashtable_itr *itr, } -/* - * Copyright (c) 2002, 2004, Christopher Clark - * 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. - */ - /* For Emacs: * Local Variables: * mode:c From 735165130a9b03c44b4f8370602793336341e498 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 16:08:45 +0000 Subject: [PATCH 1167/1766] just make this version of teletone bsd too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@603 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone_detect.h | 61 +++++------------- .../src/include/libteletone_generate.h | 35 ----------- libs/openzap/src/libteletone_detect.c | 63 +++++-------------- libs/openzap/src/libteletone_generate.c | 38 +---------- 4 files changed, 30 insertions(+), 167 deletions(-) diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index 414bbf2b35..3c44d480ee 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -2,55 +2,8 @@ * libteletone * Copyright (C) 2005/2006, Anthony Minessale II * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. - * - * - * The Initial Developer of the Original Code is - * Stephen Underwood - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * The the original interface designed by Steve Underwood was preserved to retain - *the optimizations when considering DTMF tones though the names were changed in the interest - * of namespace. - * - * 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 * - * - ********************************************************************************* - * - * Derived from tone_detect.h - 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. - * - * * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed @@ -88,6 +41,20 @@ * 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.h - 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. + * + * */ #ifndef LIBTELETONE_DETECT_H diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index addd1ebea9..d538fdc90a 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -2,41 +2,6 @@ * libteletone * Copyright (C) 2005/2006, Anthony Minessale II * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is libteletone - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * - * - * libteletone.h -- Tone Generator - * - * - * - * Exception: - * The author hereby grants the use of this source code under the - * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the - * following license and reinact the MPL 1.1 as stated above. - * * Copyright (c) 2007, Anthony Minessale II * All rights reserved. * diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 55cfcf60cd..c85ac59161 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -2,62 +2,14 @@ * libteletone * Copyright (C) 2005/2006, Anthony Minessale II * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. - * - * - * The Initial Developer of the Original Code is - * Stephen Underwood - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * The the original interface designed by Steve Underwood was preserved to retain - *the optimizations when considering DTMF tones though the names were changed in the interest - * of namespace. - * * 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 * - * - ********************************************************************************* - * - * 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. - * - * - * Exception: - * The author hereby grants the use of this source code under the - * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the - * following license and reinact the MPL 1.1 as stated above. - * * Copyright (c) 2007, Anthony Minessale II * All rights reserved. * @@ -88,6 +40,21 @@ * 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 diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 7771188c46..4a723fec6f 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -1,41 +1,5 @@ /* - * libteletone - * Copyright (C) 2005/2006, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is libteletone - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * - * - * libteletone.c -- Tone Generator - * - * - * - * Exception: - * The author hereby grants the use of this source code under the - * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the - * following license and reinact the MPL 1.1 as stated above. + * libteletone_generate.c -- Tone Generator * * Copyright (c) 2007, Anthony Minessale II * All rights reserved. From 338c9ebd602e6c6223ca10125aa8cf61eee788c8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 16:08:45 +0000 Subject: [PATCH 1168/1766] just make this version of teletone bsd too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@603 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone_detect.h | 61 +++++------------- .../src/include/libteletone_generate.h | 35 ----------- libs/freetdm/src/libteletone_detect.c | 63 +++++-------------- libs/freetdm/src/libteletone_generate.c | 38 +---------- 4 files changed, 30 insertions(+), 167 deletions(-) diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 414bbf2b35..3c44d480ee 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -2,55 +2,8 @@ * libteletone * Copyright (C) 2005/2006, Anthony Minessale II * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. - * - * - * The Initial Developer of the Original Code is - * Stephen Underwood - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * The the original interface designed by Steve Underwood was preserved to retain - *the optimizations when considering DTMF tones though the names were changed in the interest - * of namespace. - * - * 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 * - * - ********************************************************************************* - * - * Derived from tone_detect.h - 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. - * - * * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed @@ -88,6 +41,20 @@ * 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.h - 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. + * + * */ #ifndef LIBTELETONE_DETECT_H diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index addd1ebea9..d538fdc90a 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -2,41 +2,6 @@ * libteletone * Copyright (C) 2005/2006, Anthony Minessale II * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is libteletone - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * - * - * libteletone.h -- Tone Generator - * - * - * - * Exception: - * The author hereby grants the use of this source code under the - * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the - * following license and reinact the MPL 1.1 as stated above. - * * Copyright (c) 2007, Anthony Minessale II * All rights reserved. * diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 55cfcf60cd..c85ac59161 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -2,62 +2,14 @@ * libteletone * Copyright (C) 2005/2006, Anthony Minessale II * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is tone_detect.c - General telephony tone detection, and specific detection of DTMF. - * - * - * The Initial Developer of the Original Code is - * Stephen Underwood - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * The the original interface designed by Steve Underwood was preserved to retain - *the optimizations when considering DTMF tones though the names were changed in the interest - * of namespace. - * * 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 * - * - ********************************************************************************* - * - * 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. - * - * - * Exception: - * The author hereby grants the use of this source code under the - * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the - * following license and reinact the MPL 1.1 as stated above. - * * Copyright (c) 2007, Anthony Minessale II * All rights reserved. * @@ -88,6 +40,21 @@ * 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 diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 7771188c46..4a723fec6f 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -1,41 +1,5 @@ /* - * libteletone - * Copyright (C) 2005/2006, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is libteletone - * - * The Initial Developer of the Original Code is - * Anthony Minessale II - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Anthony Minessale II - * - * - * libteletone.c -- Tone Generator - * - * - * - * Exception: - * The author hereby grants the use of this source code under the - * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the - * following license and reinact the MPL 1.1 as stated above. + * libteletone_generate.c -- Tone Generator * * Copyright (c) 2007, Anthony Minessale II * All rights reserved. From b2022b8d72ed3624d654310cf8fc675eed10bea8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 22:40:57 +0000 Subject: [PATCH 1169/1766] redo some stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@604 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 6def11afe8..2fcb44f171 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1155,23 +1155,18 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); - switch_core_session_signal_unlock(session); - switch_core_session_rwunlock(session); } } break; case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1218,10 +1213,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1256,7 +1249,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if ((session_a = switch_core_session_locate(sigmsg->channel->tokens[0]))) { - switch_core_session_signal_lock(session_a); channel_a = switch_core_session_get_channel(session_a); br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1266,7 +1258,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } if ((session_b = switch_core_session_locate(sigmsg->channel->tokens[1]))) { - switch_core_session_signal_lock(session_b); channel_b = switch_core_session_get_channel(session_b); br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1281,26 +1272,21 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) switch_ivr_uuid_bridge(br_a_uuid, br_b_uuid); } else if (br_a_uuid && digits) { session_t = switch_core_session_locate(br_a_uuid); - switch_core_session_signal_lock(session_t); } else if (br_b_uuid && digits) { session_t = switch_core_session_locate(br_b_uuid); - switch_core_session_signal_lock(session_t); } } if (session_t) { switch_ivr_session_transfer(session_t, sigmsg->channel->caller_data.collected, NULL, NULL); - switch_core_session_signal_unlock(session_t); switch_core_session_rwunlock(session_t); } if (session_a) { - switch_core_session_signal_unlock(session_a); switch_core_session_rwunlock(session_a); } if (session_b) { - switch_core_session_signal_unlock(session_b); switch_core_session_rwunlock(session_b); } @@ -1308,11 +1294,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } while((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } zap_channel_clear_token(sigmsg->channel, NULL); @@ -1347,11 +1331,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } cycle_foreground(sigmsg->channel, 1, NULL); @@ -1449,11 +1431,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_RESTART: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1462,23 +1442,19 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_tone_type_t tt = ZAP_TONE_DTMF; - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1486,10 +1462,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } From 885d726da8d40f7c45fbeb4aa37166f8010a0f3e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 22:40:57 +0000 Subject: [PATCH 1170/1766] redo some stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@604 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 6def11afe8..2fcb44f171 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1155,23 +1155,18 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); - switch_core_session_signal_unlock(session); - switch_core_session_rwunlock(session); } } break; case ZAP_SIGEVENT_STOP: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1218,10 +1213,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) case ZAP_SIGEVENT_UP: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1256,7 +1249,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if ((session_a = switch_core_session_locate(sigmsg->channel->tokens[0]))) { - switch_core_session_signal_lock(session_a); channel_a = switch_core_session_get_channel(session_a); br_a_uuid = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1266,7 +1258,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } if ((session_b = switch_core_session_locate(sigmsg->channel->tokens[1]))) { - switch_core_session_signal_lock(session_b); channel_b = switch_core_session_get_channel(session_b); br_b_uuid = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE); @@ -1281,26 +1272,21 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) switch_ivr_uuid_bridge(br_a_uuid, br_b_uuid); } else if (br_a_uuid && digits) { session_t = switch_core_session_locate(br_a_uuid); - switch_core_session_signal_lock(session_t); } else if (br_b_uuid && digits) { session_t = switch_core_session_locate(br_b_uuid); - switch_core_session_signal_lock(session_t); } } if (session_t) { switch_ivr_session_transfer(session_t, sigmsg->channel->caller_data.collected, NULL, NULL); - switch_core_session_signal_unlock(session_t); switch_core_session_rwunlock(session_t); } if (session_a) { - switch_core_session_signal_unlock(session_a); switch_core_session_rwunlock(session_a); } if (session_b) { - switch_core_session_signal_unlock(session_b); switch_core_session_rwunlock(session_b); } @@ -1308,11 +1294,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } while((session = zap_channel_get_session(sigmsg->channel, 0))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } zap_channel_clear_token(sigmsg->channel, NULL); @@ -1347,11 +1331,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); if ((session = zap_channel_get_session(sigmsg->channel, 1))) { - switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } cycle_foreground(sigmsg->channel, 1, NULL); @@ -1449,11 +1431,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_RESTART: { while((session = zap_channel_get_session(sigmsg->channel, 0))) { - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1462,23 +1442,19 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { zap_tone_type_t tt = ZAP_TONE_DTMF; - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } @@ -1486,10 +1462,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - //switch_core_session_signal_lock(session); channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); - //switch_core_session_signal_unlock(session); switch_core_session_rwunlock(session); } } From 9d7405d76842b5f4d503167faac0123f598b7f11 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 31 Oct 2008 14:30:45 +0000 Subject: [PATCH 1171/1766] set init state sooner on outbound calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@605 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 2fcb44f171..0eeb9d2115 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1044,6 +1044,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } + zap_channel_init(zchan); + return SWITCH_CAUSE_SUCCESS; } From c528de01af2aff6fe1fbc36636eb02a02bfc6731 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 31 Oct 2008 14:30:45 +0000 Subject: [PATCH 1172/1766] set init state sooner on outbound calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@605 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 2fcb44f171..0eeb9d2115 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1044,6 +1044,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } + zap_channel_init(zchan); + return SWITCH_CAUSE_SUCCESS; } From 50beaaf2ea5d7154a395df94b59599903f5bb288 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 3 Nov 2008 20:46:43 +0000 Subject: [PATCH 1173/1766] (OPENZAP-33) format not a string literal and no format arguments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@606 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 0eeb9d2115..89678af149 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1518,7 +1518,7 @@ static void zap_logger(const char *file, const char *func, int line, int level, va_start(ap, fmt); if (switch_vasprintf(&data, fmt, ap) != -1) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, (char *)func, line, NULL, level, data); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, (char *)func, line, NULL, level, "%s", data); free(data); } From 4d736eb3515e4d911a0fc5f924ca23b74e08dc89 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 3 Nov 2008 20:46:43 +0000 Subject: [PATCH 1174/1766] (OPENZAP-33) format not a string literal and no format arguments git-svn-id: http://svn.openzap.org/svn/openzap/trunk@606 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 0eeb9d2115..89678af149 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1518,7 +1518,7 @@ static void zap_logger(const char *file, const char *func, int line, int level, va_start(ap, fmt); if (switch_vasprintf(&data, fmt, ap) != -1) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, (char *)func, line, NULL, level, data); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, (char *)func, line, NULL, level, "%s", data); free(data); } From b53c31d3f3b7087f90a7e293ccf309846c7943ab Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 3 Nov 2008 20:55:26 +0000 Subject: [PATCH 1175/1766] Fix OPENZAP-32 (and possibly others), thanks to Lukasz Kutkowski for spotting this... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@607 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/include/Q931.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index 9877912f79..b9c1cd3d94 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -563,10 +563,13 @@ typedef struct { L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3UCHAR Tei; /* TEI */ 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; From b3dab16f13dea7f66dc081ab3f817908d452f057 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 3 Nov 2008 20:55:26 +0000 Subject: [PATCH 1176/1766] Fix OPENZAP-32 (and possibly others), thanks to Lukasz Kutkowski for spotting this... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@607 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/include/Q931.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index 9877912f79..b9c1cd3d94 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -563,10 +563,13 @@ typedef struct { L3UINT Size; /* Size of message in bytes */ L3UCHAR ProtDisc; /* Protocol Discriminator */ L3UCHAR MesType; /* Message type */ - L3UCHAR Tei; /* TEI */ 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; From 479b109acadc5b81e6553682a509e59dd30968d9 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 14 Nov 2008 20:31:08 +0000 Subject: [PATCH 1177/1766] Fix OpenZAP-34 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@609 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/5ESSStateTE.c | 4 +- libs/openzap/src/isdn/DMSStateTE.c | 4 +- libs/openzap/src/isdn/Q931StateNT.c | 68 ++++++++++++++-------------- libs/openzap/src/isdn/Q931StateTE.c | 66 +++++++++++++-------------- libs/openzap/src/isdn/Q931api.c | 4 +- libs/openzap/src/isdn/include/Q931.h | 4 +- 6 files changed, 75 insertions(+), 75 deletions(-) diff --git a/libs/openzap/src/isdn/5ESSStateTE.c b/libs/openzap/src/isdn/5ESSStateTE.c index ce2425e0e0..e2ededd9ac 100644 --- a/libs/openzap/src/isdn/5ESSStateTE.c +++ b/libs/openzap/src/isdn/5ESSStateTE.c @@ -237,7 +237,7 @@ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ @@ -276,7 +276,7 @@ L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ diff --git a/libs/openzap/src/isdn/DMSStateTE.c b/libs/openzap/src/isdn/DMSStateTE.c index 5de657d7d9..cb740d3c2f 100644 --- a/libs/openzap/src/isdn/DMSStateTE.c +++ b/libs/openzap/src/isdn/DMSStateTE.c @@ -231,7 +231,7 @@ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ @@ -269,7 +269,7 @@ L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 71f2e6e836..6a4a37b0e7 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -163,7 +163,7 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } @@ -192,7 +192,7 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -223,7 +223,7 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -254,7 +254,7 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -285,7 +285,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -332,7 +332,7 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret) return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); Q931SetState(pTrunk, callIndex, Q931_U1); } /* incoming call */ @@ -362,7 +362,7 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO: Unreachable code??? */ /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); #endif } @@ -394,7 +394,7 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -425,7 +425,7 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -456,7 +456,7 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -487,7 +487,7 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -518,7 +518,7 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -549,7 +549,7 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -580,7 +580,7 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -611,7 +611,7 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -642,7 +642,7 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -673,7 +673,7 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -704,7 +704,7 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -735,7 +735,7 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -766,7 +766,7 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -797,7 +797,7 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -828,7 +828,7 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -859,7 +859,7 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -890,7 +890,7 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -921,7 +921,7 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -952,7 +952,7 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -987,7 +987,7 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1018,7 +1018,7 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1049,7 +1049,7 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1080,7 +1080,7 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1111,7 +1111,7 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1142,7 +1142,7 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1173,7 +1173,7 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1204,7 +1204,7 @@ L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index 0d79daf656..b5486b37c0 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -246,7 +246,7 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } @@ -275,7 +275,7 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -306,7 +306,7 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -340,7 +340,7 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -371,7 +371,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -412,7 +412,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret) return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); /* TODO: Add this back when we get the state stuff more filled out */ /*Q931SetState(pTrunk, callIndex, Q931_U1);*/ @@ -445,7 +445,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); #endif } return rc; @@ -474,12 +474,12 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret != Q931E_NO_ERROR) return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } else if (iFrom == 2) { - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } return ret; } @@ -508,7 +508,7 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* Start timer T318 */ - Q931StartTimer(pTrunk, callIndex, 318); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T318); /* set state U17 */ Q931SetState(pTrunk, callIndex, Q931_U17); @@ -537,7 +537,7 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -568,7 +568,7 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -599,7 +599,7 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -630,7 +630,7 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -661,7 +661,7 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -692,7 +692,7 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -726,7 +726,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -817,7 +817,7 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } /* TODO chack against state table for illegal or unexpected message here */ @@ -854,7 +854,7 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret != Q931E_NO_ERROR) return ret; /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } /* TODO chack against state table for illegal or unexpected message here */ @@ -889,7 +889,7 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -920,7 +920,7 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -951,7 +951,7 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -982,7 +982,7 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1013,7 +1013,7 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1044,7 +1044,7 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1079,7 +1079,7 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1110,7 +1110,7 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1141,7 +1141,7 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1172,7 +1172,7 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1203,7 +1203,7 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1234,7 +1234,7 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1265,7 +1265,7 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1296,7 +1296,7 @@ L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index c7200d568d..e59247a26a 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -167,13 +167,13 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q9 Q931Uie[dialect][iec] = Q931UieProc; } -void Q931SetTimeoutProc(L3UCHAR timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc) +void Q931SetTimeoutProc(L3UCHAR dialect, L3UCHAR timer, q931timeout_func_t *Q931TimeoutProc) { if(Q931Timeout != NULL) Q931Timeout[dialect][timer] = Q931TimeoutProc; } -void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout) +void Q931SetTimerDefault(L3UCHAR dialect, L3UCHAR timer, q931timer_t timeout) { Q931Timer[dialect][timer] = timeout; } diff --git a/libs/openzap/src/isdn/include/Q931.h b/libs/openzap/src/isdn/include/Q931.h index b9c1cd3d94..0dbafd9f11 100644 --- a/libs/openzap/src/isdn/include/Q931.h +++ b/libs/openzap/src/isdn/include/Q931.h @@ -1089,8 +1089,8 @@ 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 timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc); -void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout); +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)); From 98d63a74fe66c9d5cc3bd901c2b50f3a8c262c95 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 14 Nov 2008 20:31:08 +0000 Subject: [PATCH 1178/1766] Fix OpenZAP-34 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@609 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/5ESSStateTE.c | 4 +- libs/freetdm/src/isdn/DMSStateTE.c | 4 +- libs/freetdm/src/isdn/Q931StateNT.c | 68 ++++++++++++++-------------- libs/freetdm/src/isdn/Q931StateTE.c | 66 +++++++++++++-------------- libs/freetdm/src/isdn/Q931api.c | 4 +- libs/freetdm/src/isdn/include/Q931.h | 4 +- 6 files changed, 75 insertions(+), 75 deletions(-) diff --git a/libs/freetdm/src/isdn/5ESSStateTE.c b/libs/freetdm/src/isdn/5ESSStateTE.c index ce2425e0e0..e2ededd9ac 100644 --- a/libs/freetdm/src/isdn/5ESSStateTE.c +++ b/libs/freetdm/src/isdn/5ESSStateTE.c @@ -237,7 +237,7 @@ L3INT ATT5ESSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ @@ -276,7 +276,7 @@ L3INT ATT5ESSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ diff --git a/libs/freetdm/src/isdn/DMSStateTE.c b/libs/freetdm/src/isdn/DMSStateTE.c index 5de657d7d9..cb740d3c2f 100644 --- a/libs/freetdm/src/isdn/DMSStateTE.c +++ b/libs/freetdm/src/isdn/DMSStateTE.c @@ -231,7 +231,7 @@ L3INT DMSProc0x0fTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ @@ -269,7 +269,7 @@ L3INT DMSProc0x07TE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } if (iFrom == 4) { /* TODO Add proc here*/ diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 71f2e6e836..6a4a37b0e7 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -163,7 +163,7 @@ L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } @@ -192,7 +192,7 @@ L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -223,7 +223,7 @@ L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -254,7 +254,7 @@ L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -285,7 +285,7 @@ L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -332,7 +332,7 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret) return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); Q931SetState(pTrunk, callIndex, Q931_U1); } /* incoming call */ @@ -362,7 +362,7 @@ L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO: Unreachable code??? */ /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); #endif } @@ -394,7 +394,7 @@ L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -425,7 +425,7 @@ L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -456,7 +456,7 @@ L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -487,7 +487,7 @@ L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -518,7 +518,7 @@ L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -549,7 +549,7 @@ L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -580,7 +580,7 @@ L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -611,7 +611,7 @@ L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -642,7 +642,7 @@ L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -673,7 +673,7 @@ L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -704,7 +704,7 @@ L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -735,7 +735,7 @@ L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -766,7 +766,7 @@ L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -797,7 +797,7 @@ L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -828,7 +828,7 @@ L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -859,7 +859,7 @@ L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -890,7 +890,7 @@ L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -921,7 +921,7 @@ L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -952,7 +952,7 @@ L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -987,7 +987,7 @@ L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1018,7 +1018,7 @@ L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1049,7 +1049,7 @@ L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1080,7 +1080,7 @@ L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1111,7 +1111,7 @@ L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1142,7 +1142,7 @@ L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1173,7 +1173,7 @@ L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1204,7 +1204,7 @@ L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here*/ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index 0d79daf656..b5486b37c0 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -246,7 +246,7 @@ L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* Reset 4 sec timer. */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } @@ -275,7 +275,7 @@ L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom == 4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -306,7 +306,7 @@ L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -340,7 +340,7 @@ L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -371,7 +371,7 @@ L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -412,7 +412,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret) return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); /* TODO: Add this back when we get the state stuff more filled out */ /*Q931SetState(pTrunk, callIndex, Q931_U1);*/ @@ -445,7 +445,7 @@ L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* Set state U6 */ Q931SetState(pTrunk, callIndex, Q931_U6); - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); #endif } return rc; @@ -474,12 +474,12 @@ L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret != Q931E_NO_ERROR) return ret; - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); } else if (iFrom == 2) { - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } return ret; } @@ -508,7 +508,7 @@ L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* Start timer T318 */ - Q931StartTimer(pTrunk, callIndex, 318); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T318); /* set state U17 */ Q931SetState(pTrunk, callIndex, Q931_U17); @@ -537,7 +537,7 @@ L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -568,7 +568,7 @@ L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFro /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -599,7 +599,7 @@ L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -630,7 +630,7 @@ L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -661,7 +661,7 @@ L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -692,7 +692,7 @@ L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT i /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -726,7 +726,7 @@ L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -817,7 +817,7 @@ L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) return ret; /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } /* TODO chack against state table for illegal or unexpected message here */ @@ -854,7 +854,7 @@ L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) if (ret != Q931E_NO_ERROR) return ret; /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); } /* TODO chack against state table for illegal or unexpected message here */ @@ -889,7 +889,7 @@ L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -920,7 +920,7 @@ L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -951,7 +951,7 @@ L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -982,7 +982,7 @@ L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1013,7 +1013,7 @@ L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFr /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1044,7 +1044,7 @@ L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1079,7 +1079,7 @@ L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1110,7 +1110,7 @@ L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1141,7 +1141,7 @@ L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1172,7 +1172,7 @@ L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1203,7 +1203,7 @@ L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1234,7 +1234,7 @@ L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom) /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1265,7 +1265,7 @@ L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); @@ -1296,7 +1296,7 @@ L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iF /* TODO chack against state table for illegal or unexpected message here */ /* TODO - Set correct timer here */ - Q931StartTimer(pTrunk, callIndex, 303); + Q931StartTimer(pTrunk, callIndex, Q931_TIMER_T303); if (iFrom ==4) { /* TODO Add proc here */ ret = Q931Tx32Data(pTrunk, 0, buf, pMes->Size); diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index c7200d568d..e59247a26a 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -167,13 +167,13 @@ void Q931SetIEProc(L3UCHAR iec, L3UCHAR dialect, q931pie_func_t *Q931PieProc, q9 Q931Uie[dialect][iec] = Q931UieProc; } -void Q931SetTimeoutProc(L3UCHAR timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc) +void Q931SetTimeoutProc(L3UCHAR dialect, L3UCHAR timer, q931timeout_func_t *Q931TimeoutProc) { if(Q931Timeout != NULL) Q931Timeout[dialect][timer] = Q931TimeoutProc; } -void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout) +void Q931SetTimerDefault(L3UCHAR dialect, L3UCHAR timer, q931timer_t timeout) { Q931Timer[dialect][timer] = timeout; } diff --git a/libs/freetdm/src/isdn/include/Q931.h b/libs/freetdm/src/isdn/include/Q931.h index b9c1cd3d94..0dbafd9f11 100644 --- a/libs/freetdm/src/isdn/include/Q931.h +++ b/libs/freetdm/src/isdn/include/Q931.h @@ -1089,8 +1089,8 @@ 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 timer, L3UCHAR dialect, q931timeout_func_t *Q931TimeoutProc); -void Q931SetTimerDefault(L3UCHAR timer, L3UCHAR dialect, q931timer_t timeout); +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)); From 7ee2f82e818d3f589d27a5d22cb1d5dae96e496d Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 14 Nov 2008 20:47:29 +0000 Subject: [PATCH 1179/1766] Disable the non-working timer stuff for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@610 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/isdn/Q931.c b/libs/openzap/src/isdn/Q931.c index a235253c3a..b245c144d8 100644 --- a/libs/openzap/src/isdn/Q931.c +++ b/libs/openzap/src/isdn/Q931.c @@ -636,12 +636,14 @@ L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) */ 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; } From cb64fb902d896eac593afeb7557442bf5ee19765 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 14 Nov 2008 20:47:29 +0000 Subject: [PATCH 1180/1766] Disable the non-working timer stuff for now git-svn-id: http://svn.openzap.org/svn/openzap/trunk@610 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931.c b/libs/freetdm/src/isdn/Q931.c index a235253c3a..b245c144d8 100644 --- a/libs/freetdm/src/isdn/Q931.c +++ b/libs/freetdm/src/isdn/Q931.c @@ -636,12 +636,14 @@ L3INT Q931GetCallState(Q931_TrunkInfo_t *pTrunk, L3INT iCRV) */ 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; } From 7d75e8df8934ee18a1050536e58c7e20ee04e16b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Nov 2008 17:34:32 +0000 Subject: [PATCH 1181/1766] close OPENZAP-31 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@611 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 8 ++++---- libs/openzap/src/ozmod/ozmod_analog/zap_analog.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index ad6bd60b48..15cd842027 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -85,7 +85,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) const char *tonemap = "us"; const char *hotline = ""; uint32_t digit_timeout = 10; - uint32_t max_dialstr = 11; + uint32_t max_dialstr = MAX_DTMF; const char *var, *val; int *intval; uint32_t flags = ZAP_ANALOG_CALLERID; @@ -143,8 +143,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) digit_timeout = 2000; } - if ((max_dialstr < 2 && !strlen(hotline)) || max_dialstr > 20) { - max_dialstr = 11; + if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) { + max_dialstr = MAX_DTMF; } span->start = zap_analog_start; @@ -228,7 +228,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_tone_type_t tt = ZAP_TONE_DTMF; - char dtmf[128] = ""; + 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; diff --git a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h index 6fde39e9ca..b48b168e69 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h @@ -41,6 +41,7 @@ typedef enum { } zap_analog_flag_t; #define ZAP_MAX_HOTLINE_STR 20 +#define MAX_DTMF 256 struct zap_analog_data { uint32_t flags; From b83ab7a8d3e5f8f6cd601f0a566b17c6fa977beb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Nov 2008 17:34:32 +0000 Subject: [PATCH 1182/1766] close OPENZAP-31 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@611 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 8 ++++---- libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index ad6bd60b48..15cd842027 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -85,7 +85,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) const char *tonemap = "us"; const char *hotline = ""; uint32_t digit_timeout = 10; - uint32_t max_dialstr = 11; + uint32_t max_dialstr = MAX_DTMF; const char *var, *val; int *intval; uint32_t flags = ZAP_ANALOG_CALLERID; @@ -143,8 +143,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) digit_timeout = 2000; } - if ((max_dialstr < 2 && !strlen(hotline)) || max_dialstr > 20) { - max_dialstr = 11; + if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) { + max_dialstr = MAX_DTMF; } span->start = zap_analog_start; @@ -228,7 +228,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) uint8_t frame[1024]; zap_size_t len, rlen; zap_tone_type_t tt = ZAP_TONE_DTMF; - char dtmf[128] = ""; + 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; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h index 6fde39e9ca..b48b168e69 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h @@ -41,6 +41,7 @@ typedef enum { } zap_analog_flag_t; #define ZAP_MAX_HOTLINE_STR 20 +#define MAX_DTMF 256 struct zap_analog_data { uint32_t flags; From f8b23330bc9885278b6689e4314a36432645ce4d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 20 Nov 2008 23:46:15 +0000 Subject: [PATCH 1183/1766] OPENZAP-30 add support for flash hook as part of the dial string using 'F' git-svn-id: http://svn.openzap.org/svn/openzap/trunk@612 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 1 + libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 9 +++++++++ libs/openzap/src/zap_io.c | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1998465bbb..57013ff3a1 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -261,6 +261,7 @@ typedef enum { ZAP_COMMAND_GENERATE_RING_OFF, ZAP_COMMAND_OFFHOOK, ZAP_COMMAND_ONHOOK, + ZAP_COMMAND_FLASH, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_TRACE_INPUT, diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 4d5c7c7c01..9ab48c4b94 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -443,6 +443,15 @@ static ZIO_COMMAND_FUNCTION(zt_command) zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); } break; + case ZAP_COMMAND_FLASH: + { + int command = ZT_FLASH; + if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "FLASH Failed"); + return ZAP_FAIL; + } + } + break; case ZAP_COMMAND_GENERATE_RING_ON: { int command = ZT_RING; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index fb6abf3931..3535049064 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1712,7 +1712,14 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero_buf(digits)) { zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); - for (cur = digits; *cur; cur++) { + cur = digits; + + if (*cur == 'F') { + zap_channel_command(zchan, ZAP_COMMAND_FLASH, NULL); + cur++; + } + + for (; *cur; cur++) { int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); From 751cbfb6d19863f4813f7f483cef4ce78f3fb597 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 20 Nov 2008 23:46:15 +0000 Subject: [PATCH 1184/1766] OPENZAP-30 add support for flash hook as part of the dial string using 'F' git-svn-id: http://svn.openzap.org/svn/openzap/trunk@612 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 1 + libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 9 +++++++++ libs/freetdm/src/zap_io.c | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 1998465bbb..57013ff3a1 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -261,6 +261,7 @@ typedef enum { ZAP_COMMAND_GENERATE_RING_OFF, ZAP_COMMAND_OFFHOOK, ZAP_COMMAND_ONHOOK, + ZAP_COMMAND_FLASH, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, ZAP_COMMAND_DISABLE_PROGRESS_DETECT, ZAP_COMMAND_TRACE_INPUT, diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 4d5c7c7c01..9ab48c4b94 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -443,6 +443,15 @@ static ZIO_COMMAND_FUNCTION(zt_command) zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); } break; + case ZAP_COMMAND_FLASH: + { + int command = ZT_FLASH; + if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "FLASH Failed"); + return ZAP_FAIL; + } + } + break; case ZAP_COMMAND_GENERATE_RING_ON: { int command = ZT_RING; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index fb6abf3931..3535049064 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1712,7 +1712,14 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero_buf(digits)) { zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); - for (cur = digits; *cur; cur++) { + cur = digits; + + if (*cur == 'F') { + zap_channel_command(zchan, ZAP_COMMAND_FLASH, NULL); + cur++; + } + + for (; *cur; cur++) { int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); From 4291661dab28adb3770cffccfa6a5c2b4d366076 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 1 Dec 2008 21:01:07 +0000 Subject: [PATCH 1185/1766] allow state change from progress_media to terminating in isdn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@613 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index ffee6f7b20..a46e81a4a1 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1650,7 +1650,8 @@ static zap_state_map_t isdn_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_UP, 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, From b3a8afd9963d4c6763f4923a7724bd22d9da995a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 1 Dec 2008 21:01:07 +0000 Subject: [PATCH 1186/1766] allow state change from progress_media to terminating in isdn git-svn-id: http://svn.openzap.org/svn/openzap/trunk@613 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index ffee6f7b20..a46e81a4a1 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1650,7 +1650,8 @@ static zap_state_map_t isdn_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_UP, 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, From 774372dcea8ec56dec47ce2bfca0b74e85f130a9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 3 Dec 2008 16:02:17 +0000 Subject: [PATCH 1187/1766] add wink command patch (still needs more code) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@614 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 1 + libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 5 +---- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 9 +++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 57013ff3a1..28fd127fbf 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -262,6 +262,7 @@ typedef enum { 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, 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 index 1d951ec65e..5e8649bf4c 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -360,10 +360,7 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); indicate = 1; - zap_sleep(25); - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - zap_sleep(200); - zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); + zap_channel_command(zchan, ZAP_COMMAND_WINK, NULL); } break; case ZAP_CHANNEL_STATE_RING: diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 9ab48c4b94..a4802463e3 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -452,6 +452,15 @@ static ZIO_COMMAND_FUNCTION(zt_command) } } break; + case ZAP_COMMAND_WINK: + { + int command = ZT_WINK; + if (ioctl(zchan->sockfd, ZT_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; From 07a8ebe5e07310de31d604bd062e75b11ab8764a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 3 Dec 2008 16:02:17 +0000 Subject: [PATCH 1188/1766] add wink command patch (still needs more code) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@614 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 1 + libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 5 +---- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 9 +++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 57013ff3a1..28fd127fbf 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -262,6 +262,7 @@ typedef enum { 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, diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index 1d951ec65e..5e8649bf4c 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -360,10 +360,7 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); indicate = 1; - zap_sleep(25); - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - zap_sleep(200); - zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); + zap_channel_command(zchan, ZAP_COMMAND_WINK, NULL); } break; case ZAP_CHANNEL_STATE_RING: diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 9ab48c4b94..a4802463e3 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -452,6 +452,15 @@ static ZIO_COMMAND_FUNCTION(zt_command) } } break; + case ZAP_COMMAND_WINK: + { + int command = ZT_WINK; + if (ioctl(zchan->sockfd, ZT_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; From 26deb420a8515f9c5fe9698610ac0cf9b1a3bcd4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 Dec 2008 15:10:22 +0000 Subject: [PATCH 1189/1766] fix compiler warning git-svn-id: http://svn.openzap.org/svn/openzap/trunk@615 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/build/config.guess | 687 ++++++++++-------------- libs/openzap/build/config.sub | 244 ++------- libs/openzap/build/ltmain.sh | 139 +++-- libs/openzap/src/libteletone_generate.c | 2 +- 4 files changed, 411 insertions(+), 661 deletions(-) diff --git a/libs/openzap/build/config.guess b/libs/openzap/build/config.guess index 951383e355..2fc3acce2e 100755 --- a/libs/openzap/build/config.guess +++ b/libs/openzap/build/config.guess @@ -1,10 +1,9 @@ #! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2007-05-17' +timestamp='2003-06-17' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -18,15 +17,13 @@ timestamp='2007-05-17' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. - # Originally written by Per Bothner . # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. @@ -56,7 +53,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -69,11 +66,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; + echo "$timestamp" ; exit 0 ;; --version | -v ) - echo "$version" ; exit ;; + echo "$version" ; exit 0 ;; --help | --h* | -h ) - echo "$usage"; exit ;; + echo "$usage"; exit 0 ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -107,7 +104,7 @@ set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; @@ -126,7 +123,7 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' +esac ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) @@ -139,6 +136,13 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown +## for Red Hat Linux +if test -f /etc/redhat-release ; then + VENDOR=redhat ; +else + VENDOR= ; +fi + # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in @@ -161,7 +165,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched @@ -200,32 +203,50 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" - exit ;; + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + macppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvmeppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mipseb-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; + echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) + if test $UNAME_RELEASE = "V4.0"; then UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac + fi # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU @@ -263,49 +284,42 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac - # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha*:OpenVMS:*:*) + echo alpha-hp-vms + exit 0 ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix - exit ;; + exit 0 ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 - exit ;; + exit 0 ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 - exit ;; + exit 0;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; + exit 0 ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos - exit ;; + exit 0 ;; *:OS/390:*:*) echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; + exit 0 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; + exit 0;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp - exit ;; + exit 0;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then @@ -313,32 +327,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in else echo pyramid-pyramid-bsd fi - exit ;; + exit 0 ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 - exit ;; + exit 0 ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + exit 0 ;; + DRS?6000:UNIX_SV:4.2*:7*) case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; + sparc) echo sparc-icl-nx7 && exit 0 ;; esac ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:* | ix86xen:SunOS:5.*:*) + exit 0 ;; + i86pc:SunOS:5.*:*) echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) @@ -347,10 +361,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; + exit 0 ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; + exit 0 ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 @@ -362,10 +376,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo sparc-sun-sunos${UNAME_RELEASE} ;; esac - exit ;; + exit 0 ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; + exit 0 ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor @@ -376,40 +390,37 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; + exit 0 ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; + exit 0 ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 - exit ;; + exit 0 ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; + exit 0 ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; + exit 0 ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; + exit 0 ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -433,33 +444,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit (-1); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } + $CC_FOR_BUILD -o $dummy $dummy.c \ + && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && exit 0 echo mips-mips-riscos${UNAME_RELEASE} - exit ;; + exit 0 ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax - exit ;; + exit 0 ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax - exit ;; + exit 0 ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax - exit ;; + exit 0 ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix - exit ;; + exit 0 ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 - exit ;; + exit 0 ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 - exit ;; + exit 0 ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 - exit ;; + exit 0 ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` @@ -475,29 +485,29 @@ EOF else echo i586-dg-dgux${UNAME_RELEASE} fi - exit ;; + exit 0 ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 - exit ;; + exit 0 ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 - exit ;; + exit 0 ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 - exit ;; + exit 0 ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd - exit ;; + exit 0 ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; + exit 0 ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix - exit ;; + exit 0 ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` @@ -505,7 +515,7 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; + exit 0 ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build @@ -520,18 +530,14 @@ EOF exit(0); } EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 + echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi - exit ;; + exit 0 ;; *:AIX:*:[45]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then @@ -545,28 +551,28 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; + exit 0 ;; *:AIX:*:*) echo rs6000-ibm-aix - exit ;; + exit 0 ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 - exit ;; + exit 0 ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 + exit 0 ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx - exit ;; + exit 0 ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 - exit ;; + exit 0 ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd - exit ;; + exit 0 ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 - exit ;; + exit 0 ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in @@ -628,19 +634,9 @@ EOF esac if [ ${HP_ARCH} = "hppa2.0w" ] then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null + # avoid double evaluation of $set_cc_for_build + test -n "$CC_FOR_BUILD" || eval $set_cc_for_build + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null then HP_ARCH="hppa2.0w" else @@ -648,11 +644,11 @@ EOF fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; + exit 0 ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} - exit ;; + exit 0 ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -680,182 +676,150 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 echo unknown-hitachi-hiuxwe2 - exit ;; + exit 0 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd - exit ;; + exit 0 ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd - exit ;; + exit 0 ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix - exit ;; + exit 0 ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf - exit ;; + exit 0 ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf - exit ;; + exit 0 ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi - exit ;; + exit 0 ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites - exit ;; + exit 0 ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd - exit ;; + exit 0 ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit ;; + exit 0 ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd - exit ;; + exit 0 ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd - exit ;; + exit 0 ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd - exit ;; + exit 0 ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + exit 0 ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; + exit 0 ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; + exit 0 ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; + exit 0 ;; + *:FreeBSD:*:*|*:GNU/FreeBSD:*:*) + # Determine whether the default compiler uses glibc. + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #if __GLIBC__ >= 2 + LIBC=gnu + #else + LIBC= + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} + exit 0 ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW*:*) + exit 0 ;; + i*:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; + exit 0 ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - EM64T | authenticamd) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; + exit 0 ;; + x86:Interix*:[34]*) + echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' + exit 0 ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks - exit ;; + exit 0 ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix - exit ;; + exit 0 ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; + exit 0 ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin - exit ;; + exit 0 ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; *:GNU:*:*) - # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; + exit 0 ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix - exit ;; + exit 0 ;; arm*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; cris:Linux:*:*) echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; + exit 0 ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + echo ${UNAME_MACHINE}-${VENDOR:-unknown}-linux-gnu + exit 0 ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; mips:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -872,12 +836,8 @@ EOF #endif #endif EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; mips64:Linux:*:*) eval $set_cc_for_build @@ -895,22 +855,15 @@ EOF #endif #endif EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; + echo powerpc-${VENDOR:-unknown}-linux-gnu + exit 0 ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; + echo powerpc64-${VENDOR:-unknown}-linux-gnu + exit 0 ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -924,7 +877,7 @@ EOF objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; + exit 0 ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in @@ -932,31 +885,25 @@ EOF PA8*) echo hppa2.0-unknown-linux-gnu ;; *) echo hppa-unknown-linux-gnu ;; esac - exit ;; + exit 0 ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-gnu - exit ;; + exit 0 ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; + echo ${UNAME_MACHINE}-${VENDOR:-ibm}-linux-gnu + exit 0 ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; + exit 0 ;; x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - xtensa:Linux:*:*) - echo xtensa-unknown-linux-gnu - exit ;; + echo x86_64-${VENDOR:-unknown}-linux-gnu + exit 0 ;; i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so # first see if it will tell us. cd to the root directory to prevent @@ -974,15 +921,15 @@ EOF ;; a.out-i386-linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; + exit 0 ;; coff-i386) echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit ;; + exit 0 ;; "") # Either a pre-BFD a.out linker (linux-gnuoldld) or # one that does not give us useful --help. echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; + exit 0 ;; esac # Determine whether the default compiler is a.out or elf eval $set_cc_for_build @@ -999,33 +946,23 @@ EOF LIBC=gnulibc1 # endif #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + #ifdef __INTEL_COMPILER LIBC=gnu #else LIBC=gnuaout #endif #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-${VENDOR:-pc}-linux-${LIBC}" && exit 0 + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 - exit ;; + exit 0 ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... @@ -1033,27 +970,24 @@ EOF # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; + exit 0 ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; + exit 0 ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop - exit ;; + exit 0 ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; + exit 0 ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; + exit 0 ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then @@ -1061,16 +995,15 @@ EOF else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. + exit 0 ;; + i*86:*:5:[78]*) case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; + exit 0 ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi - exit ;; + exit 0 ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv - exit ;; + exit 0 ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv - exit ;; + exit 0 ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + exit 0 ;; + M68*:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + && echo i486-ncr-sysv4.3${OS_REL} && exit 0 /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; + && echo i486-ncr-sysv4 && exit 0 ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 - exit ;; + exit 0 ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} - exit ;; + exit 0 ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 - exit ;; + exit 0 ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 - exit ;; + exit 0 ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` @@ -1162,81 +1095,68 @@ EOF else echo ns32k-sni-sysv fi - exit ;; + exit 0 ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 - exit ;; + exit 0 ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 - exit ;; + exit 0 ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; + exit 0 ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos - exit ;; + exit 0 ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} - exit ;; + exit 0 ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 - exit ;; + exit 0 ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi - exit ;; + exit 0 ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos - exit ;; + exit 0 ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos - exit ;; + exit 0 ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos - exit ;; + exit 0 ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} - exit ;; + exit 0 ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} - exit ;; + exit 0 ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; + exit 0 ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; + exit 0 ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; + exit 0 ;; *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; + case `uname -p` in + *86) UNAME_PROCESSOR=i686 ;; + powerpc) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; + exit 0 ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then @@ -1244,25 +1164,22 @@ EOF UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; + exit 0 ;; *:QNX:*:4*) echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) + exit 0 ;; + NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; + exit 0 ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux - exit ;; + exit 0 ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv - exit ;; + exit 0 ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; + exit 0 ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 @@ -1273,47 +1190,28 @@ EOF UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; + exit 0 ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 - exit ;; + exit 0 ;; *:TENEX:*:*) echo pdp10-unknown-tenex - exit ;; + exit 0 ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 - exit ;; + exit 0 ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 - exit ;; + exit 0 ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 - exit ;; + exit 0 ;; *:ITS:*:*) echo pdp10-unknown-its - exit ;; + exit 0 ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; + exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 @@ -1345,7 +1243,7 @@ main () #endif #if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); + printf ("arm-acorn-riscix"); exit (0); #endif #if defined (hp300) && !defined (hpux) @@ -1434,12 +1332,11 @@ main () } EOF -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0 # Apollos put the system type in the environment. -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } # Convex versions that predate uname can use getsysinfo(1) @@ -1448,22 +1345,22 @@ then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd - exit ;; + exit 0 ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit ;; + exit 0 ;; c34*) echo c34-convex-bsd - exit ;; + exit 0 ;; c38*) echo c38-convex-bsd - exit ;; + exit 0 ;; c4*) echo c4-convex-bsd - exit ;; + exit 0 ;; esac fi @@ -1474,9 +1371,7 @@ This script, last modified $timestamp, has failed to recognize the operating system you are using. It is advised that you download the most up to date version of the config scripts from - http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess -and - http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub + ftp://ftp.gnu.org/pub/gnu/config/ If the version you run ($0) is already up to date, please send the following data and any information you think might be diff --git a/libs/openzap/build/config.sub b/libs/openzap/build/config.sub index c060f44833..6b2ff9f6a7 100755 --- a/libs/openzap/build/config.sub +++ b/libs/openzap/build/config.sub @@ -1,10 +1,9 @@ #! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2007-04-29' +timestamp='2003-06-18' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -22,15 +21,14 @@ timestamp='2007-04-29' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# +# Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. - # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. # @@ -72,7 +70,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -85,11 +83,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; + echo "$timestamp" ; exit 0 ;; --version | -v ) - echo "$version" ; exit ;; + echo "$version" ; exit 0 ;; --help | --h* | -h ) - echo "$usage"; exit ;; + echo "$usage"; exit 0 ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -101,7 +99,7 @@ while test $# -gt 0 ; do *local*) # First pass through any local machine types. echo $1 - exit ;; + exit 0;; * ) break ;; @@ -120,9 +118,7 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ - uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -148,7 +144,7 @@ case $os in -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) + -apple | -axis) os= basic_machine=$1 ;; @@ -173,10 +169,6 @@ case $os in -hiux*) os=-hiuxwe2 ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -193,10 +185,6 @@ case $os in # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -240,17 +228,14 @@ case $basic_machine in | a29k \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | bfin \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ - | fido | fr30 | frv \ + | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep \ + | ip2k \ + | m32r | m68000 | m68k | m88k | mcore \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -259,33 +244,28 @@ case $basic_machine in | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ - | mt \ | msp430 \ - | nios | nios2 \ | ns16k | ns32k \ - | or32 \ + | openrisc | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ - | score \ - | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | s390 | s390x \ + | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu | strongarm \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \ + | strongarm \ | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ | we32k \ - | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | x86 | xscale | xstormy16 | xtensa \ | z8k) basic_machine=$basic_machine-unknown ;; @@ -296,9 +276,6 @@ case $basic_machine in ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; - ms1) - basic_machine=mt-unknown - ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and @@ -318,20 +295,20 @@ case $basic_machine in | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | bfin-* | bs2000-* \ + | avr-* \ + | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ + | clipper-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | m32c-* | m32r-* | m32rle-* \ + | ip2k-* \ + | m32r-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* \ + | m88110-* | m88k-* | mcore-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ @@ -340,36 +317,31 @@ case $basic_machine in | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ | msp430-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ + | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | s390-* | s390x-* \ + | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ | v850-* | v850e-* | vax-* \ | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa-* \ + | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ + | xtensa-* \ | ymp-* \ | z8k-*) ;; @@ -389,9 +361,6 @@ case $basic_machine in basic_machine=a29k-amd os=-udi ;; - abacus) - basic_machine=abacus-unknown - ;; adobe68k) basic_machine=m68010-adobe os=-scout @@ -409,9 +378,6 @@ case $basic_machine in amd64) basic_machine=x86_64-pc ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; amdahl) basic_machine=580-amdahl os=-sysv @@ -471,27 +437,12 @@ case $basic_machine in basic_machine=j90-cray os=-unicos ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16c) - basic_machine=cr16c-unknown - os=-elf - ;; crds | unos) basic_machine=m68k-crds ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; da30 | da30-*) basic_machine=m68k-da30 ;; @@ -514,10 +465,6 @@ case $basic_machine in basic_machine=m88k-motorola os=-sysv3 ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx @@ -683,10 +630,6 @@ case $basic_machine in basic_machine=i386-pc os=-mingw32 ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; miniframe) basic_machine=m68000-convergent ;; @@ -700,6 +643,10 @@ case $basic_machine in mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; monitor) basic_machine=m68k-rom68k os=-coff @@ -712,9 +659,6 @@ case $basic_machine in basic_machine=i386-pc os=-msdos ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; mvs) basic_machine=i370-ibm os=-mvs @@ -783,6 +727,10 @@ case $basic_machine in np1) basic_machine=np1-gould ;; + nv1) + basic_machine=nv1-cray + os=-unicosmp + ;; nsr-tandem) basic_machine=nsr-tandem ;; @@ -790,12 +738,9 @@ case $basic_machine in basic_machine=hppa1.1-oki os=-proelf ;; - openrisc | openrisc-*) + or32 | or32-*) basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 + os=-coff ;; OSE68000 | ose68000) basic_machine=m68000-ericsson @@ -822,12 +767,6 @@ case $basic_machine in pc532 | pc532-*) basic_machine=ns32k-pc532 ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; @@ -884,10 +823,6 @@ case $basic_machine in basic_machine=i586-unknown os=-pw32 ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; rom68k) basic_machine=m68k-rom68k os=-coff @@ -898,12 +833,6 @@ case $basic_machine in rtpc | rtpc-*) basic_machine=romp-ibm ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; sa29200) basic_machine=a29k-amd os=-udi @@ -914,10 +843,6 @@ case $basic_machine in sb1el) basic_machine=mipsisa64sb1el-unknown ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; sei) basic_machine=mips-sei os=-seiux @@ -929,9 +854,6 @@ case $basic_machine in basic_machine=sh-hitachi os=-hms ;; - sh5el) - basic_machine=sh5le-unknown - ;; sh64) basic_machine=sh64-unknown ;; @@ -1034,10 +956,6 @@ case $basic_machine in tower | tower-32) basic_machine=m68k-ncr ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; udi29k) basic_machine=a29k-amd os=-udi @@ -1081,10 +999,6 @@ case $basic_machine in basic_machine=hppa1.1-winbond os=-proelf ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; xps | xps100) basic_machine=xps100-honeywell ;; @@ -1115,9 +1029,6 @@ case $basic_machine in romp) basic_machine=romp-ibm ;; - mmix) - basic_machine=mmix-knuth - ;; rs6000) basic_machine=rs6000-ibm ;; @@ -1134,10 +1045,13 @@ case $basic_machine in we32k) basic_machine=we32k-att ;; - sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + sh64) + basic_machine=sh64-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; cydra) @@ -1210,23 +1124,19 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + | -powermax* | -dnix* | -nx6 | -nx7 | -sei*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1244,15 +1154,12 @@ case $os in os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; @@ -1265,9 +1172,6 @@ case $os in -opened*) os=-openedition ;; - -os400*) - os=-os400 - ;; -wince*) os=-wince ;; @@ -1289,9 +1193,6 @@ case $os in -atheos*) os=-atheos ;; - -syllable*) - os=-syllable - ;; -386bsd) os=-bsd ;; @@ -1314,9 +1215,6 @@ case $os in -sinix*) os=-sysv4 ;; - -tpf*) - os=-tpf - ;; -triton*) os=-sysv3 ;; @@ -1353,9 +1251,6 @@ case $os in -kaos*) os=-kaos ;; - -zvmoe) - os=-zvmoe - ;; -none) ;; *) @@ -1378,12 +1273,6 @@ else # system, and we'll never get to this point. case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; *-acorn) os=-riscix1.2 ;; @@ -1393,8 +1282,8 @@ case $basic_machine in arm*-semi) os=-aout ;; - c4x-* | tic4x-*) - os=-coff + c4x-* | tic4x-*) + os=-coff ;; # This must come before the *-dec entry. pdp10-*) @@ -1421,9 +1310,6 @@ case $basic_machine in m68*-cisco) os=-aout ;; - mep-*) - os=-elf - ;; mips*-cisco) os=-elf ;; @@ -1442,15 +1328,9 @@ case $basic_machine in *-be) os=-beos ;; - *-haiku) - os=-haiku - ;; *-ibm) os=-aix ;; - *-knuth) - os=-mmixware - ;; *-wec) os=-proelf ;; @@ -1583,15 +1463,9 @@ case $basic_machine in -mvs* | -opened*) vendor=ibm ;; - -os400*) - vendor=ibm - ;; -ptx*) vendor=sequent ;; - -tpf*) - vendor=ibm - ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; @@ -1616,7 +1490,7 @@ case $basic_machine in esac echo $basic_machine$os -exit +exit 0 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) diff --git a/libs/openzap/build/ltmain.sh b/libs/openzap/build/ltmain.sh index 4598ec61cc..0223495a02 100644 --- a/libs/openzap/build/ltmain.sh +++ b/libs/openzap/build/ltmain.sh @@ -1,8 +1,8 @@ # ltmain.sh - Provide generalized library-building support services. # NOTE: Changing this file will not affect anything until you rerun configure. # -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007 Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 +# Free Software Foundation, Inc. # Originally by Gordon Matzigkeit , 1996 # # This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ EXIT_FAILURE=1 PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.5.24 -TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" +VERSION=1.5.22 +TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)" # Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -57,8 +57,6 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then else case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh # Check that we have a working $echo. if test "X$1" = X--no-reexec; then @@ -116,10 +114,10 @@ esac for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then - save_$lt_var=\$$lt_var - $lt_var=C - export $lt_var - fi" + save_$lt_var=\$$lt_var + $lt_var=C + export $lt_var + fi" done # Make sure IFS has a sensible default @@ -208,13 +206,7 @@ func_win32_libid () if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then win32_nmres=`eval $NM -f posix -A $1 | \ - $SED -n -e '1,100{ - / I /{ - s,.*,import, - p - q - } - }'` + $SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'` case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; @@ -348,11 +340,11 @@ func_extract_archives () my_xlib_u=$my_xlib while :; do case " $extracted_archives " in - *" $my_xlib_u "*) - extracted_serial=`expr $extracted_serial + 1` - my_xlib_u=lt$extracted_serial-$my_xlib ;; - *) break ;; - esac + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir="$my_gentop/$my_xlib_u" @@ -482,12 +474,11 @@ do ;; --version) - echo "\ -$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP - -Copyright (C) 2007 Free Software Foundation, Inc. -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP" + $echo + $echo "Copyright (C) 2005 Free Software Foundation, Inc." + $echo "This is free software; see the source for copying conditions. There is NO" + $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." exit $? ;; @@ -784,7 +775,7 @@ if test -z "$show_help"; then *.class) xform=class ;; *.cpp) xform=cpp ;; *.cxx) xform=cxx ;; - *.[fF][09]?) xform=[fF][09]. ;; + *.f90) xform=f90 ;; *.for) xform=for ;; *.java) xform=java ;; *.obj) xform=obj ;; @@ -1169,8 +1160,8 @@ EOF do case $arg in -all-static | -static | -static-libtool-libs) - case $arg in - -all-static) + case $arg in + -all-static) if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2 fi @@ -1179,19 +1170,19 @@ EOF fi prefer_static_libs=yes ;; - -static) + -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; - -static-libtool-libs) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - esac + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac build_libtool_libs=no build_old_libs=yes break @@ -1639,7 +1630,7 @@ EOF continue ;; - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) compiler_flags="$compiler_flags $arg" compile_command="$compile_command $arg" finalize_command="$finalize_command $arg" @@ -1659,11 +1650,10 @@ EOF # -m* pass through architecture-specific compiler args for GCC # -m*, -t[45]*, -txscale* pass through architecture-specific # compiler args for GCC - # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC - # -F/path gives path to uninstalled frameworks, gcc on darwin + # -pg pass through profiling flag for GCC # @file GCC response files - -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ - -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \ + -t[45]*|-txscale*|@*) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. @@ -1691,9 +1681,9 @@ EOF -no-install) case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) # The PATH hackery in wrapper scripts is required on Windows - # and Darwin in order for the loader to find any dlls it needs. + # in order for the loader to find any dlls it needs. $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 fast_install=no @@ -2134,7 +2124,7 @@ EOF lib= found=no case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" @@ -2530,9 +2520,9 @@ EOF if test "$linkmode,$pass" = "prog,link"; then if test -n "$library_names" && - { { test "$prefer_static_libs" = no || - test "$prefer_static_libs,$installed" = "built,yes"; } || - test -z "$old_library"; }; then + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then # We need to hardcode the library path if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then # Make sure the rpath contains only unique directories. @@ -3239,10 +3229,9 @@ EOF age="0" ;; irix|nonstopux) - current=`expr $number_major + $number_minor` + current=`expr $number_major + $number_minor - 1` age="$number_minor" revision="$number_minor" - lt_irix_increment=no ;; esac ;; @@ -3301,8 +3290,7 @@ EOF versuffix="$major.$age.$revision" # Darwin ld doesn't like 0 for these options... minor_current=`expr $current + 1` - xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" - verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" ;; freebsd-aout) @@ -3316,11 +3304,8 @@ EOF ;; irix | nonstopux) - if test "X$lt_irix_increment" = "Xno"; then - major=`expr $current - $age` - else - major=`expr $current - $age + 1` - fi + major=`expr $current - $age + 1` + case $version_type in nonstopux) verstring_prefix=nonstopux ;; *) verstring_prefix=sgi ;; @@ -3457,11 +3442,11 @@ EOF fi # Eliminate all temporary directories. - #for path in $notinst_path; do - # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` - # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` - # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` - #done +# for path in $notinst_path; do +# lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` +# deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` +# dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` +# done if test -n "$xrpath"; then # If the user specified any rpath flags, then add them. @@ -3562,7 +3547,7 @@ EOF int main() { return 0; } EOF $rm conftest - if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then + if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then ldd_output=`ldd conftest` for i in $deplibs; do name=`expr $i : '-l\(.*\)'` @@ -3924,10 +3909,7 @@ EOF test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" if test -n "$hardcode_libdir_flag_spec_ld"; then - case $archive_cmds in - *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; - *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; - esac + eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" else eval dep_rpath=\"$hardcode_libdir_flag_spec\" fi @@ -4293,7 +4275,7 @@ EOF if test -n "$convenience"; then if test -n "$whole_archive_flag_spec"; then eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" - reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` else gentop="$output_objdir/${obj}x" generated="$generated $gentop" @@ -5313,8 +5295,6 @@ if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. @@ -6411,10 +6391,8 @@ relink_command=\"$relink_command\"" if test -f "$dir/$objdir/$dlname"; then dir="$dir/$objdir" else - if test ! -f "$dir/$dlname"; then - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit $EXIT_FAILURE - fi + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE fi ;; @@ -6480,11 +6458,14 @@ relink_command=\"$relink_command\"" # Restore saved environment variables for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do - eval "if test \"\${save_$lt_var+set}\" = set; then - $lt_var=\$save_$lt_var; export $lt_var - fi" + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + else + $lt_unset $lt_var + fi" done + # Now prepare to actually exec the command. exec_cmd="\$cmd$args" else diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 4a723fec6f..84de06853c 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -172,7 +172,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/ int i, c; int freqlen = 0; - teletone_dds_state_t tones[TELETONE_MAX_TONES]; + teletone_dds_state_t tones[TELETONE_MAX_TONES+1]; //int decay = 0; int duration; int wait = 0; From dd658a138c8c8da88f031b953e128c9e0ef9451a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 Dec 2008 15:10:22 +0000 Subject: [PATCH 1190/1766] fix compiler warning git-svn-id: http://svn.openzap.org/svn/openzap/trunk@615 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/build/config.guess | 687 ++++++++++-------------- libs/freetdm/build/config.sub | 244 ++------- libs/freetdm/build/ltmain.sh | 139 +++-- libs/freetdm/src/libteletone_generate.c | 2 +- 4 files changed, 411 insertions(+), 661 deletions(-) diff --git a/libs/freetdm/build/config.guess b/libs/freetdm/build/config.guess index 951383e355..2fc3acce2e 100755 --- a/libs/freetdm/build/config.guess +++ b/libs/freetdm/build/config.guess @@ -1,10 +1,9 @@ #! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2007-05-17' +timestamp='2003-06-17' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -18,15 +17,13 @@ timestamp='2007-05-17' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. - # Originally written by Per Bothner . # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. @@ -56,7 +53,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -69,11 +66,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; + echo "$timestamp" ; exit 0 ;; --version | -v ) - echo "$version" ; exit ;; + echo "$version" ; exit 0 ;; --help | --h* | -h ) - echo "$usage"; exit ;; + echo "$usage"; exit 0 ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -107,7 +104,7 @@ set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; @@ -126,7 +123,7 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' +esac ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) @@ -139,6 +136,13 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown +## for Red Hat Linux +if test -f /etc/redhat-release ; then + VENDOR=redhat ; +else + VENDOR= ; +fi + # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in @@ -161,7 +165,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched @@ -200,32 +203,50 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" - exit ;; + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + macppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvmeppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mipseb-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; + echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) + if test $UNAME_RELEASE = "V4.0"; then UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac + fi # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU @@ -263,49 +284,42 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac - # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha*:OpenVMS:*:*) + echo alpha-hp-vms + exit 0 ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix - exit ;; + exit 0 ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 - exit ;; + exit 0 ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 - exit ;; + exit 0;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; + exit 0 ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos - exit ;; + exit 0 ;; *:OS/390:*:*) echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; + exit 0 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; + exit 0;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp - exit ;; + exit 0;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then @@ -313,32 +327,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in else echo pyramid-pyramid-bsd fi - exit ;; + exit 0 ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 - exit ;; + exit 0 ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + exit 0 ;; + DRS?6000:UNIX_SV:4.2*:7*) case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; + sparc) echo sparc-icl-nx7 && exit 0 ;; esac ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:* | ix86xen:SunOS:5.*:*) + exit 0 ;; + i86pc:SunOS:5.*:*) echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) @@ -347,10 +361,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; + exit 0 ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; + exit 0 ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 @@ -362,10 +376,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo sparc-sun-sunos${UNAME_RELEASE} ;; esac - exit ;; + exit 0 ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; + exit 0 ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor @@ -376,40 +390,37 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} - exit ;; + exit 0 ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; + exit 0 ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; + exit 0 ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 - exit ;; + exit 0 ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; + exit 0 ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; + exit 0 ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; + exit 0 ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -433,33 +444,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit (-1); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } + $CC_FOR_BUILD -o $dummy $dummy.c \ + && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && exit 0 echo mips-mips-riscos${UNAME_RELEASE} - exit ;; + exit 0 ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax - exit ;; + exit 0 ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax - exit ;; + exit 0 ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax - exit ;; + exit 0 ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix - exit ;; + exit 0 ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 - exit ;; + exit 0 ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 - exit ;; + exit 0 ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 - exit ;; + exit 0 ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` @@ -475,29 +485,29 @@ EOF else echo i586-dg-dgux${UNAME_RELEASE} fi - exit ;; + exit 0 ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 - exit ;; + exit 0 ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 - exit ;; + exit 0 ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 - exit ;; + exit 0 ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd - exit ;; + exit 0 ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; + exit 0 ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix - exit ;; + exit 0 ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` @@ -505,7 +515,7 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; + exit 0 ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build @@ -520,18 +530,14 @@ EOF exit(0); } EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 + echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi - exit ;; + exit 0 ;; *:AIX:*:[45]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then @@ -545,28 +551,28 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; + exit 0 ;; *:AIX:*:*) echo rs6000-ibm-aix - exit ;; + exit 0 ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 - exit ;; + exit 0 ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 + exit 0 ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx - exit ;; + exit 0 ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 - exit ;; + exit 0 ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd - exit ;; + exit 0 ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 - exit ;; + exit 0 ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in @@ -628,19 +634,9 @@ EOF esac if [ ${HP_ARCH} = "hppa2.0w" ] then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null + # avoid double evaluation of $set_cc_for_build + test -n "$CC_FOR_BUILD" || eval $set_cc_for_build + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null then HP_ARCH="hppa2.0w" else @@ -648,11 +644,11 @@ EOF fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; + exit 0 ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} - exit ;; + exit 0 ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -680,182 +676,150 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 echo unknown-hitachi-hiuxwe2 - exit ;; + exit 0 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd - exit ;; + exit 0 ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd - exit ;; + exit 0 ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix - exit ;; + exit 0 ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf - exit ;; + exit 0 ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf - exit ;; + exit 0 ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi - exit ;; + exit 0 ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites - exit ;; + exit 0 ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd - exit ;; + exit 0 ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit ;; + exit 0 ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd - exit ;; + exit 0 ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd - exit ;; + exit 0 ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd - exit ;; + exit 0 ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + exit 0 ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + exit 0 ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; + exit 0 ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; + exit 0 ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; + exit 0 ;; + *:FreeBSD:*:*|*:GNU/FreeBSD:*:*) + # Determine whether the default compiler uses glibc. + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #if __GLIBC__ >= 2 + LIBC=gnu + #else + LIBC= + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} + exit 0 ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW*:*) + exit 0 ;; + i*:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; + exit 0 ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - EM64T | authenticamd) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; + exit 0 ;; + x86:Interix*:[34]*) + echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' + exit 0 ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks - exit ;; + exit 0 ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix - exit ;; + exit 0 ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; + exit 0 ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin - exit ;; + exit 0 ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + exit 0 ;; *:GNU:*:*) - # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; + exit 0 ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix - exit ;; + exit 0 ;; arm*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; cris:Linux:*:*) echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; + exit 0 ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + echo ${UNAME_MACHINE}-${VENDOR:-unknown}-linux-gnu + exit 0 ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; mips:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -872,12 +836,8 @@ EOF #endif #endif EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; mips64:Linux:*:*) eval $set_cc_for_build @@ -895,22 +855,15 @@ EOF #endif #endif EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; + echo powerpc-${VENDOR:-unknown}-linux-gnu + exit 0 ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; + echo powerpc64-${VENDOR:-unknown}-linux-gnu + exit 0 ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -924,7 +877,7 @@ EOF objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; + exit 0 ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in @@ -932,31 +885,25 @@ EOF PA8*) echo hppa2.0-unknown-linux-gnu ;; *) echo hppa-unknown-linux-gnu ;; esac - exit ;; + exit 0 ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-gnu - exit ;; + exit 0 ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; + echo ${UNAME_MACHINE}-${VENDOR:-ibm}-linux-gnu + exit 0 ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; + exit 0 ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; + exit 0 ;; x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - xtensa:Linux:*:*) - echo xtensa-unknown-linux-gnu - exit ;; + echo x86_64-${VENDOR:-unknown}-linux-gnu + exit 0 ;; i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so # first see if it will tell us. cd to the root directory to prevent @@ -974,15 +921,15 @@ EOF ;; a.out-i386-linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; + exit 0 ;; coff-i386) echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit ;; + exit 0 ;; "") # Either a pre-BFD a.out linker (linux-gnuoldld) or # one that does not give us useful --help. echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; + exit 0 ;; esac # Determine whether the default compiler is a.out or elf eval $set_cc_for_build @@ -999,33 +946,23 @@ EOF LIBC=gnulibc1 # endif #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + #ifdef __INTEL_COMPILER LIBC=gnu #else LIBC=gnuaout #endif #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-${VENDOR:-pc}-linux-${LIBC}" && exit 0 + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 - exit ;; + exit 0 ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... @@ -1033,27 +970,24 @@ EOF # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; + exit 0 ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; + exit 0 ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop - exit ;; + exit 0 ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; + exit 0 ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; + exit 0 ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then @@ -1061,16 +995,15 @@ EOF else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. + exit 0 ;; + i*86:*:5:[78]*) case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; + exit 0 ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi - exit ;; + exit 0 ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv - exit ;; + exit 0 ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv - exit ;; + exit 0 ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + exit 0 ;; + M68*:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + && echo i486-ncr-sysv4.3${OS_REL} && exit 0 /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; + && echo i486-ncr-sysv4 && exit 0 ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 - exit ;; + exit 0 ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; + exit 0 ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} - exit ;; + exit 0 ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 - exit ;; + exit 0 ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 - exit ;; + exit 0 ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` @@ -1162,81 +1095,68 @@ EOF else echo ns32k-sni-sysv fi - exit ;; + exit 0 ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 - exit ;; + exit 0 ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 - exit ;; + exit 0 ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; + exit 0 ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos - exit ;; + exit 0 ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} - exit ;; + exit 0 ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 - exit ;; + exit 0 ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi - exit ;; + exit 0 ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos - exit ;; + exit 0 ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos - exit ;; + exit 0 ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos - exit ;; + exit 0 ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} - exit ;; + exit 0 ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} - exit ;; + exit 0 ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; + exit 0 ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; + exit 0 ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; + exit 0 ;; *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; + case `uname -p` in + *86) UNAME_PROCESSOR=i686 ;; + powerpc) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; + exit 0 ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then @@ -1244,25 +1164,22 @@ EOF UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; + exit 0 ;; *:QNX:*:4*) echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) + exit 0 ;; + NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; + exit 0 ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux - exit ;; + exit 0 ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv - exit ;; + exit 0 ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; + exit 0 ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 @@ -1273,47 +1190,28 @@ EOF UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; + exit 0 ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 - exit ;; + exit 0 ;; *:TENEX:*:*) echo pdp10-unknown-tenex - exit ;; + exit 0 ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 - exit ;; + exit 0 ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 - exit ;; + exit 0 ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 - exit ;; + exit 0 ;; *:ITS:*:*) echo pdp10-unknown-its - exit ;; + exit 0 ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; + exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 @@ -1345,7 +1243,7 @@ main () #endif #if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); + printf ("arm-acorn-riscix"); exit (0); #endif #if defined (hp300) && !defined (hpux) @@ -1434,12 +1332,11 @@ main () } EOF -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0 # Apollos put the system type in the environment. -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } # Convex versions that predate uname can use getsysinfo(1) @@ -1448,22 +1345,22 @@ then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd - exit ;; + exit 0 ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit ;; + exit 0 ;; c34*) echo c34-convex-bsd - exit ;; + exit 0 ;; c38*) echo c38-convex-bsd - exit ;; + exit 0 ;; c4*) echo c4-convex-bsd - exit ;; + exit 0 ;; esac fi @@ -1474,9 +1371,7 @@ This script, last modified $timestamp, has failed to recognize the operating system you are using. It is advised that you download the most up to date version of the config scripts from - http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess -and - http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub + ftp://ftp.gnu.org/pub/gnu/config/ If the version you run ($0) is already up to date, please send the following data and any information you think might be diff --git a/libs/freetdm/build/config.sub b/libs/freetdm/build/config.sub index c060f44833..6b2ff9f6a7 100755 --- a/libs/freetdm/build/config.sub +++ b/libs/freetdm/build/config.sub @@ -1,10 +1,9 @@ #! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2007-04-29' +timestamp='2003-06-18' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -22,15 +21,14 @@ timestamp='2007-04-29' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# +# Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. - # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. # @@ -72,7 +70,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -85,11 +83,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; + echo "$timestamp" ; exit 0 ;; --version | -v ) - echo "$version" ; exit ;; + echo "$version" ; exit 0 ;; --help | --h* | -h ) - echo "$usage"; exit ;; + echo "$usage"; exit 0 ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -101,7 +99,7 @@ while test $# -gt 0 ; do *local*) # First pass through any local machine types. echo $1 - exit ;; + exit 0;; * ) break ;; @@ -120,9 +118,7 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ - uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -148,7 +144,7 @@ case $os in -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) + -apple | -axis) os= basic_machine=$1 ;; @@ -173,10 +169,6 @@ case $os in -hiux*) os=-hiuxwe2 ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -193,10 +185,6 @@ case $os in # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -240,17 +228,14 @@ case $basic_machine in | a29k \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | bfin \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ - | fido | fr30 | frv \ + | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep \ + | ip2k \ + | m32r | m68000 | m68k | m88k | mcore \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -259,33 +244,28 @@ case $basic_machine in | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ - | mt \ | msp430 \ - | nios | nios2 \ | ns16k | ns32k \ - | or32 \ + | openrisc | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ - | score \ - | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | s390 | s390x \ + | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu | strongarm \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \ + | strongarm \ | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ | we32k \ - | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | x86 | xscale | xstormy16 | xtensa \ | z8k) basic_machine=$basic_machine-unknown ;; @@ -296,9 +276,6 @@ case $basic_machine in ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; - ms1) - basic_machine=mt-unknown - ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and @@ -318,20 +295,20 @@ case $basic_machine in | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | bfin-* | bs2000-* \ + | avr-* \ + | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ + | clipper-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | m32c-* | m32r-* | m32rle-* \ + | ip2k-* \ + | m32r-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* \ + | m88110-* | m88k-* | mcore-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ @@ -340,36 +317,31 @@ case $basic_machine in | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ | msp430-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ + | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | s390-* | s390x-* \ + | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ | v850-* | v850e-* | vax-* \ | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa-* \ + | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ + | xtensa-* \ | ymp-* \ | z8k-*) ;; @@ -389,9 +361,6 @@ case $basic_machine in basic_machine=a29k-amd os=-udi ;; - abacus) - basic_machine=abacus-unknown - ;; adobe68k) basic_machine=m68010-adobe os=-scout @@ -409,9 +378,6 @@ case $basic_machine in amd64) basic_machine=x86_64-pc ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; amdahl) basic_machine=580-amdahl os=-sysv @@ -471,27 +437,12 @@ case $basic_machine in basic_machine=j90-cray os=-unicos ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16c) - basic_machine=cr16c-unknown - os=-elf - ;; crds | unos) basic_machine=m68k-crds ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; da30 | da30-*) basic_machine=m68k-da30 ;; @@ -514,10 +465,6 @@ case $basic_machine in basic_machine=m88k-motorola os=-sysv3 ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx @@ -683,10 +630,6 @@ case $basic_machine in basic_machine=i386-pc os=-mingw32 ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; miniframe) basic_machine=m68000-convergent ;; @@ -700,6 +643,10 @@ case $basic_machine in mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; monitor) basic_machine=m68k-rom68k os=-coff @@ -712,9 +659,6 @@ case $basic_machine in basic_machine=i386-pc os=-msdos ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; mvs) basic_machine=i370-ibm os=-mvs @@ -783,6 +727,10 @@ case $basic_machine in np1) basic_machine=np1-gould ;; + nv1) + basic_machine=nv1-cray + os=-unicosmp + ;; nsr-tandem) basic_machine=nsr-tandem ;; @@ -790,12 +738,9 @@ case $basic_machine in basic_machine=hppa1.1-oki os=-proelf ;; - openrisc | openrisc-*) + or32 | or32-*) basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 + os=-coff ;; OSE68000 | ose68000) basic_machine=m68000-ericsson @@ -822,12 +767,6 @@ case $basic_machine in pc532 | pc532-*) basic_machine=ns32k-pc532 ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; @@ -884,10 +823,6 @@ case $basic_machine in basic_machine=i586-unknown os=-pw32 ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; rom68k) basic_machine=m68k-rom68k os=-coff @@ -898,12 +833,6 @@ case $basic_machine in rtpc | rtpc-*) basic_machine=romp-ibm ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; sa29200) basic_machine=a29k-amd os=-udi @@ -914,10 +843,6 @@ case $basic_machine in sb1el) basic_machine=mipsisa64sb1el-unknown ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; sei) basic_machine=mips-sei os=-seiux @@ -929,9 +854,6 @@ case $basic_machine in basic_machine=sh-hitachi os=-hms ;; - sh5el) - basic_machine=sh5le-unknown - ;; sh64) basic_machine=sh64-unknown ;; @@ -1034,10 +956,6 @@ case $basic_machine in tower | tower-32) basic_machine=m68k-ncr ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; udi29k) basic_machine=a29k-amd os=-udi @@ -1081,10 +999,6 @@ case $basic_machine in basic_machine=hppa1.1-winbond os=-proelf ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; xps | xps100) basic_machine=xps100-honeywell ;; @@ -1115,9 +1029,6 @@ case $basic_machine in romp) basic_machine=romp-ibm ;; - mmix) - basic_machine=mmix-knuth - ;; rs6000) basic_machine=rs6000-ibm ;; @@ -1134,10 +1045,13 @@ case $basic_machine in we32k) basic_machine=we32k-att ;; - sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + sh64) + basic_machine=sh64-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; cydra) @@ -1210,23 +1124,19 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + | -powermax* | -dnix* | -nx6 | -nx7 | -sei*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1244,15 +1154,12 @@ case $os in os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; @@ -1265,9 +1172,6 @@ case $os in -opened*) os=-openedition ;; - -os400*) - os=-os400 - ;; -wince*) os=-wince ;; @@ -1289,9 +1193,6 @@ case $os in -atheos*) os=-atheos ;; - -syllable*) - os=-syllable - ;; -386bsd) os=-bsd ;; @@ -1314,9 +1215,6 @@ case $os in -sinix*) os=-sysv4 ;; - -tpf*) - os=-tpf - ;; -triton*) os=-sysv3 ;; @@ -1353,9 +1251,6 @@ case $os in -kaos*) os=-kaos ;; - -zvmoe) - os=-zvmoe - ;; -none) ;; *) @@ -1378,12 +1273,6 @@ else # system, and we'll never get to this point. case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; *-acorn) os=-riscix1.2 ;; @@ -1393,8 +1282,8 @@ case $basic_machine in arm*-semi) os=-aout ;; - c4x-* | tic4x-*) - os=-coff + c4x-* | tic4x-*) + os=-coff ;; # This must come before the *-dec entry. pdp10-*) @@ -1421,9 +1310,6 @@ case $basic_machine in m68*-cisco) os=-aout ;; - mep-*) - os=-elf - ;; mips*-cisco) os=-elf ;; @@ -1442,15 +1328,9 @@ case $basic_machine in *-be) os=-beos ;; - *-haiku) - os=-haiku - ;; *-ibm) os=-aix ;; - *-knuth) - os=-mmixware - ;; *-wec) os=-proelf ;; @@ -1583,15 +1463,9 @@ case $basic_machine in -mvs* | -opened*) vendor=ibm ;; - -os400*) - vendor=ibm - ;; -ptx*) vendor=sequent ;; - -tpf*) - vendor=ibm - ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; @@ -1616,7 +1490,7 @@ case $basic_machine in esac echo $basic_machine$os -exit +exit 0 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) diff --git a/libs/freetdm/build/ltmain.sh b/libs/freetdm/build/ltmain.sh index 4598ec61cc..0223495a02 100644 --- a/libs/freetdm/build/ltmain.sh +++ b/libs/freetdm/build/ltmain.sh @@ -1,8 +1,8 @@ # ltmain.sh - Provide generalized library-building support services. # NOTE: Changing this file will not affect anything until you rerun configure. # -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007 Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 +# Free Software Foundation, Inc. # Originally by Gordon Matzigkeit , 1996 # # This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ EXIT_FAILURE=1 PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.5.24 -TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" +VERSION=1.5.22 +TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)" # Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -57,8 +57,6 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then else case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh # Check that we have a working $echo. if test "X$1" = X--no-reexec; then @@ -116,10 +114,10 @@ esac for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then - save_$lt_var=\$$lt_var - $lt_var=C - export $lt_var - fi" + save_$lt_var=\$$lt_var + $lt_var=C + export $lt_var + fi" done # Make sure IFS has a sensible default @@ -208,13 +206,7 @@ func_win32_libid () if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then win32_nmres=`eval $NM -f posix -A $1 | \ - $SED -n -e '1,100{ - / I /{ - s,.*,import, - p - q - } - }'` + $SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'` case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; @@ -348,11 +340,11 @@ func_extract_archives () my_xlib_u=$my_xlib while :; do case " $extracted_archives " in - *" $my_xlib_u "*) - extracted_serial=`expr $extracted_serial + 1` - my_xlib_u=lt$extracted_serial-$my_xlib ;; - *) break ;; - esac + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir="$my_gentop/$my_xlib_u" @@ -482,12 +474,11 @@ do ;; --version) - echo "\ -$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP - -Copyright (C) 2007 Free Software Foundation, Inc. -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP" + $echo + $echo "Copyright (C) 2005 Free Software Foundation, Inc." + $echo "This is free software; see the source for copying conditions. There is NO" + $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." exit $? ;; @@ -784,7 +775,7 @@ if test -z "$show_help"; then *.class) xform=class ;; *.cpp) xform=cpp ;; *.cxx) xform=cxx ;; - *.[fF][09]?) xform=[fF][09]. ;; + *.f90) xform=f90 ;; *.for) xform=for ;; *.java) xform=java ;; *.obj) xform=obj ;; @@ -1169,8 +1160,8 @@ EOF do case $arg in -all-static | -static | -static-libtool-libs) - case $arg in - -all-static) + case $arg in + -all-static) if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2 fi @@ -1179,19 +1170,19 @@ EOF fi prefer_static_libs=yes ;; - -static) + -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; - -static-libtool-libs) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - esac + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac build_libtool_libs=no build_old_libs=yes break @@ -1639,7 +1630,7 @@ EOF continue ;; - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) compiler_flags="$compiler_flags $arg" compile_command="$compile_command $arg" finalize_command="$finalize_command $arg" @@ -1659,11 +1650,10 @@ EOF # -m* pass through architecture-specific compiler args for GCC # -m*, -t[45]*, -txscale* pass through architecture-specific # compiler args for GCC - # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC - # -F/path gives path to uninstalled frameworks, gcc on darwin + # -pg pass through profiling flag for GCC # @file GCC response files - -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ - -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \ + -t[45]*|-txscale*|@*) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. @@ -1691,9 +1681,9 @@ EOF -no-install) case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) # The PATH hackery in wrapper scripts is required on Windows - # and Darwin in order for the loader to find any dlls it needs. + # in order for the loader to find any dlls it needs. $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 fast_install=no @@ -2134,7 +2124,7 @@ EOF lib= found=no case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" @@ -2530,9 +2520,9 @@ EOF if test "$linkmode,$pass" = "prog,link"; then if test -n "$library_names" && - { { test "$prefer_static_libs" = no || - test "$prefer_static_libs,$installed" = "built,yes"; } || - test -z "$old_library"; }; then + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then # We need to hardcode the library path if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then # Make sure the rpath contains only unique directories. @@ -3239,10 +3229,9 @@ EOF age="0" ;; irix|nonstopux) - current=`expr $number_major + $number_minor` + current=`expr $number_major + $number_minor - 1` age="$number_minor" revision="$number_minor" - lt_irix_increment=no ;; esac ;; @@ -3301,8 +3290,7 @@ EOF versuffix="$major.$age.$revision" # Darwin ld doesn't like 0 for these options... minor_current=`expr $current + 1` - xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" - verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" ;; freebsd-aout) @@ -3316,11 +3304,8 @@ EOF ;; irix | nonstopux) - if test "X$lt_irix_increment" = "Xno"; then - major=`expr $current - $age` - else - major=`expr $current - $age + 1` - fi + major=`expr $current - $age + 1` + case $version_type in nonstopux) verstring_prefix=nonstopux ;; *) verstring_prefix=sgi ;; @@ -3457,11 +3442,11 @@ EOF fi # Eliminate all temporary directories. - #for path in $notinst_path; do - # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` - # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` - # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` - #done +# for path in $notinst_path; do +# lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` +# deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` +# dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` +# done if test -n "$xrpath"; then # If the user specified any rpath flags, then add them. @@ -3562,7 +3547,7 @@ EOF int main() { return 0; } EOF $rm conftest - if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then + if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then ldd_output=`ldd conftest` for i in $deplibs; do name=`expr $i : '-l\(.*\)'` @@ -3924,10 +3909,7 @@ EOF test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" if test -n "$hardcode_libdir_flag_spec_ld"; then - case $archive_cmds in - *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; - *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; - esac + eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" else eval dep_rpath=\"$hardcode_libdir_flag_spec\" fi @@ -4293,7 +4275,7 @@ EOF if test -n "$convenience"; then if test -n "$whole_archive_flag_spec"; then eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" - reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` else gentop="$output_objdir/${obj}x" generated="$generated $gentop" @@ -5313,8 +5295,6 @@ if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. @@ -6411,10 +6391,8 @@ relink_command=\"$relink_command\"" if test -f "$dir/$objdir/$dlname"; then dir="$dir/$objdir" else - if test ! -f "$dir/$dlname"; then - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit $EXIT_FAILURE - fi + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE fi ;; @@ -6480,11 +6458,14 @@ relink_command=\"$relink_command\"" # Restore saved environment variables for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do - eval "if test \"\${save_$lt_var+set}\" = set; then - $lt_var=\$save_$lt_var; export $lt_var - fi" + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + else + $lt_unset $lt_var + fi" done + # Now prepare to actually exec the command. exec_cmd="\$cmd$args" else diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 4a723fec6f..84de06853c 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -172,7 +172,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/ int i, c; int freqlen = 0; - teletone_dds_state_t tones[TELETONE_MAX_TONES]; + teletone_dds_state_t tones[TELETONE_MAX_TONES+1]; //int decay = 0; int duration; int wait = 0; From a4c03480a5091dc85518b4489d09ca9b6a23378a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 15 Dec 2008 20:20:09 +0000 Subject: [PATCH 1191/1766] OPENZAP-37 (fail if invalid dialect is defined. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@616 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index a46e81a4a1..23f5acd8d8 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1746,7 +1746,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } dialect = q931_str2Q931Dialect_type(val); if (dialect == Q931_Dialect_Count) { - dialect = Q931_Dialect_National; + return ZAP_FAIL; } } else if (!strcasecmp(var, "opts")) { opts = va_arg(ap, uint32_t); From ff4858ec6b7f0a8dd9d3a5fc31e3bdeda2ac3b3f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 15 Dec 2008 20:20:09 +0000 Subject: [PATCH 1192/1766] OPENZAP-37 (fail if invalid dialect is defined. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@616 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index a46e81a4a1..23f5acd8d8 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1746,7 +1746,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } dialect = q931_str2Q931Dialect_type(val); if (dialect == Q931_Dialect_Count) { - dialect = Q931_Dialect_National; + return ZAP_FAIL; } } else if (!strcasecmp(var, "opts")) { opts = va_arg(ap, uint32_t); From 654cd7fa70fdd970bba13a3cf8749f89f0d022cc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 20 Dec 2008 05:23:56 +0000 Subject: [PATCH 1193/1766] fix filehandle leak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@617 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3535049064..dcc0f0a3aa 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -415,6 +415,8 @@ zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) } } } + + zap_config_close_file(&cfg); if (!x) { snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); From 5d12ff02008f1d9cfa717dce499e856895ff5aa3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 20 Dec 2008 05:23:56 +0000 Subject: [PATCH 1194/1766] fix filehandle leak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@617 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3535049064..dcc0f0a3aa 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -415,6 +415,8 @@ zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) } } } + + zap_config_close_file(&cfg); if (!x) { snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); From bb86de4a2b08e58cb827fd44ed3f5ef844f29f16 Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Fri, 2 Jan 2009 18:45:21 +0000 Subject: [PATCH 1195/1766] Update Doxygen.conf for the new OpenZAP dir stucture; allow static and local members to be built in docs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@619 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/docs/Doxygen.conf | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/openzap/docs/Doxygen.conf b/libs/openzap/docs/Doxygen.conf index 2e0590e548..c4e47076fa 100644 --- a/libs/openzap/docs/Doxygen.conf +++ b/libs/openzap/docs/Doxygen.conf @@ -45,10 +45,10 @@ IGNORE_PREFIX = zap_ ZAP_ Q921 Q931 # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = YES -EXTRACT_PRIVATE = NO -EXTRACT_STATIC = NO +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO +EXTRACT_LOCAL_METHODS = YES HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES HIDE_FRIEND_COMPOUNDS = NO @@ -83,7 +83,19 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = ../src ../src/include ../src/isdn ../src/isdn/include +INPUT = ../src ../src/include \ + ../src/isdn ../src/isdn/include \ + ../mod_openzap ../ \ + ../src/ozmod \ + ../src/ozmod/ozmod_analog \ + ../src/ozmod/ozmod_analog_em \ + ../src/ozmod/ozmod_isdn \ + ../src/ozmod/ozmod_pika \ + ../src/ozmod/ozmod_skel \ + ../src/ozmod/ozmod_ss7_boost \ + ../src/ozmod/ozmod_wanpipe \ + ../src/ozmod/ozmod_zt + FILE_PATTERNS = *.c \ *.cc \ *.cxx \ From 249d0676bc446e2e1426d4151d8e90b80d31090d Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Fri, 2 Jan 2009 18:45:21 +0000 Subject: [PATCH 1196/1766] Update Doxygen.conf for the new OpenZAP dir stucture; allow static and local members to be built in docs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@619 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/docs/Doxygen.conf | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/docs/Doxygen.conf b/libs/freetdm/docs/Doxygen.conf index 2e0590e548..c4e47076fa 100644 --- a/libs/freetdm/docs/Doxygen.conf +++ b/libs/freetdm/docs/Doxygen.conf @@ -45,10 +45,10 @@ IGNORE_PREFIX = zap_ ZAP_ Q921 Q931 # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = YES -EXTRACT_PRIVATE = NO -EXTRACT_STATIC = NO +EXTRACT_PRIVATE = YES +EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO +EXTRACT_LOCAL_METHODS = YES HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES HIDE_FRIEND_COMPOUNDS = NO @@ -83,7 +83,19 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = ../src ../src/include ../src/isdn ../src/isdn/include +INPUT = ../src ../src/include \ + ../src/isdn ../src/isdn/include \ + ../mod_openzap ../ \ + ../src/ozmod \ + ../src/ozmod/ozmod_analog \ + ../src/ozmod/ozmod_analog_em \ + ../src/ozmod/ozmod_isdn \ + ../src/ozmod/ozmod_pika \ + ../src/ozmod/ozmod_skel \ + ../src/ozmod/ozmod_ss7_boost \ + ../src/ozmod/ozmod_wanpipe \ + ../src/ozmod/ozmod_zt + FILE_PATTERNS = *.c \ *.cc \ *.cxx \ From 755b203096722ed570fb3dab2c81bf09b0d5509e Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Tue, 6 Jan 2009 01:07:09 +0000 Subject: [PATCH 1197/1766] Add stub for oz bounce command git-svn-id: http://svn.openzap.org/svn/openzap/trunk@620 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 89678af149..c562808ac9 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1822,6 +1822,8 @@ static switch_status_t load_config(void) uint32_t opts = 0; int q921loglevel = -1; int q931loglevel = -1; + // quick debug + // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -2119,6 +2121,39 @@ SWITCH_STANDARD_API(oz_function) ); } } + } else if (!strcasecmp(argv[0], "bounce")) { + /* MSC testing "oz bounce" command */ + if (argc < 2) { + stream->write_function(stream, "-ERR Usage: oz dump []\n"); + goto end; + } else { + int32_t span_id, chan_id = 0; + zap_span_t *span; + + span_id = atoi(argv[1]); + + if (argc > 2) { + chan_id = atoi(argv[2]); + } + + if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + stream->write_function(stream, "-ERR invalid span\n"); + } else { + if (chan_id) { + //dump_chan(span, chan_id, stream); + zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); + } else { + int j; + + stream->write_function(stream, "+OK\n"); + for(j = 1; j <= span->chan_count; j++) { + //dump_chan(span, j, stream); + zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, j); + } + + } + } + } } else { stream->write_function(stream, "-ERR Usage: oz list || dump []\n"); } From 8d3b22aee59f9fb18c79c98f829a1ffd752e3ade Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Tue, 6 Jan 2009 01:07:09 +0000 Subject: [PATCH 1198/1766] Add stub for oz bounce command git-svn-id: http://svn.openzap.org/svn/openzap/trunk@620 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 89678af149..c562808ac9 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1822,6 +1822,8 @@ static switch_status_t load_config(void) uint32_t opts = 0; int q921loglevel = -1; int q931loglevel = -1; + // quick debug + // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -2119,6 +2121,39 @@ SWITCH_STANDARD_API(oz_function) ); } } + } else if (!strcasecmp(argv[0], "bounce")) { + /* MSC testing "oz bounce" command */ + if (argc < 2) { + stream->write_function(stream, "-ERR Usage: oz dump []\n"); + goto end; + } else { + int32_t span_id, chan_id = 0; + zap_span_t *span; + + span_id = atoi(argv[1]); + + if (argc > 2) { + chan_id = atoi(argv[2]); + } + + if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + stream->write_function(stream, "-ERR invalid span\n"); + } else { + if (chan_id) { + //dump_chan(span, chan_id, stream); + zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); + } else { + int j; + + stream->write_function(stream, "+OK\n"); + for(j = 1; j <= span->chan_count; j++) { + //dump_chan(span, j, stream); + zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, j); + } + + } + } + } } else { stream->write_function(stream, "-ERR Usage: oz list || dump []\n"); } From ac845fb58fcfdb10acd79872fdb2189e5d209b0f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 9 Jan 2009 22:11:04 +0000 Subject: [PATCH 1199/1766] make error more clear about missing trunk_type param in openzap.conf (and auto tolerate the err) and fix printf metas git-svn-id: http://svn.openzap.org/svn/openzap/trunk@621 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 5 +++-- libs/openzap/src/zap_io.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c562808ac9..935f367c61 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1897,7 +1897,7 @@ static switch_status_t load_config(void) "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %s dialect: %s error: %s\n", span_id, mode, dialect, span->last_error); continue; } diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 23f5acd8d8..c374eeded4 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1703,8 +1703,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } if (span->trunk_type >= ZAP_TRUNK_NONE) { - snprintf(span->last_error, sizeof(span->last_error), "Unknown trunk type!"); - return ZAP_FAIL; + 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++) { @@ -1785,6 +1785,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } } + if (!digit_timeout) { digit_timeout = DEFAULT_DIGIT_TIMEOUT; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index dcc0f0a3aa..714160ca8e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2482,6 +2482,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c va_end(ap); } else { zap_log(ZAP_LOG_ERROR, "can't find '%s'\n", type); + status = ZAP_FAIL; } return status; From 0fa7d1b68e6009c71d1e79bbf18b77fa47bf0217 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 9 Jan 2009 22:11:04 +0000 Subject: [PATCH 1200/1766] make error more clear about missing trunk_type param in openzap.conf (and auto tolerate the err) and fix printf metas git-svn-id: http://svn.openzap.org/svn/openzap/trunk@621 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 5 +++-- libs/freetdm/src/zap_io.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c562808ac9..935f367c61 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1897,7 +1897,7 @@ static switch_status_t load_config(void) "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %d dialect: %d error: %s\n", span_id, mode, dialect, span->last_error); + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %s dialect: %s error: %s\n", span_id, mode, dialect, span->last_error); continue; } diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 23f5acd8d8..c374eeded4 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1703,8 +1703,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } if (span->trunk_type >= ZAP_TRUNK_NONE) { - snprintf(span->last_error, sizeof(span->last_error), "Unknown trunk type!"); - return ZAP_FAIL; + 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++) { @@ -1785,6 +1785,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } } + if (!digit_timeout) { digit_timeout = DEFAULT_DIGIT_TIMEOUT; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index dcc0f0a3aa..714160ca8e 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2482,6 +2482,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c va_end(ap); } else { zap_log(ZAP_LOG_ERROR, "can't find '%s'\n", type); + status = ZAP_FAIL; } return status; From 2a8e9751a0bc280207c57a0b80b4ae764e41e489 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jan 2009 17:46:30 +0000 Subject: [PATCH 1201/1766] add type of num var for pri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@622 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 12 ++++++++++++ libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 935f367c61..ef1bd3e520 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -900,6 +900,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_event_header_t *h; char *argv[3]; int argc = 0; + const char *var; + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -966,6 +968,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (!switch_strlen_zero(dest)) { zap_set_string(caller_data.ani.digits, dest); } + + if ((var = switch_event_get_header(var_event, "openzap_outbound_ton"))) { + if (!strcasecmp(var, "national")) { + caller_data.ani.type = Q931_TON_NATIONAL; + } + } else { + caller_data.ani.type = outbound_profile->destination_number_ton; + } + + caller_data.ani.plan = outbound_profile->destination_number_numplan; #if 0 if (!switch_strlen_zero(outbound_profile->rdnis)) { diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index c374eeded4..096086d437 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1009,7 +1009,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) * CallingNum IE */ Q931InitIECallingNum(&CallingNum); - CallingNum.TypNum = Q931_TON_UNKNOWN; + CallingNum.TypNum = zchan->caller_data.ani.type; CallingNum.NumPlanID = Q931_NUMPLAN_E164; CallingNum.PresInd = Q931_PRES_ALLOWED; CallingNum.ScreenInd = Q931_SCREEN_USER_NOT_SCREENED; From bdc9c28d9cdc0d5a8360783bb7cb488262da2d21 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jan 2009 17:46:30 +0000 Subject: [PATCH 1202/1766] add type of num var for pri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@622 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 12 ++++++++++++ libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 935f367c61..ef1bd3e520 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -900,6 +900,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_event_header_t *h; char *argv[3]; int argc = 0; + const char *var; + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -966,6 +968,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (!switch_strlen_zero(dest)) { zap_set_string(caller_data.ani.digits, dest); } + + if ((var = switch_event_get_header(var_event, "openzap_outbound_ton"))) { + if (!strcasecmp(var, "national")) { + caller_data.ani.type = Q931_TON_NATIONAL; + } + } else { + caller_data.ani.type = outbound_profile->destination_number_ton; + } + + caller_data.ani.plan = outbound_profile->destination_number_numplan; #if 0 if (!switch_strlen_zero(outbound_profile->rdnis)) { diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index c374eeded4..096086d437 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1009,7 +1009,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) * CallingNum IE */ Q931InitIECallingNum(&CallingNum); - CallingNum.TypNum = Q931_TON_UNKNOWN; + CallingNum.TypNum = zchan->caller_data.ani.type; CallingNum.NumPlanID = Q931_NUMPLAN_E164; CallingNum.PresInd = Q931_PRES_ALLOWED; CallingNum.ScreenInd = Q931_SCREEN_USER_NOT_SCREENED; From 7dd156caad41c8cda989cd712eaf19b2f3088b77 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jan 2009 17:50:26 +0000 Subject: [PATCH 1203/1766] add type of num var for pri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@623 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ef1bd3e520..ce0d5042d7 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -901,7 +901,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char *argv[3]; int argc = 0; const char *var; - + switch_channel_t *channel = NULL; + + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -969,7 +971,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_set_string(caller_data.ani.digits, dest); } - if ((var = switch_event_get_header(var_event, "openzap_outbound_ton"))) { + channel = switch_core_session_get_channel(*new_session); + + if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_channel_get_variable(channel, "openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { caller_data.ani.type = Q931_TON_NATIONAL; } @@ -1011,12 +1015,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; - switch_channel_t *channel; switch_caller_profile_t *caller_profile; switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { - channel = switch_core_session_get_channel(*new_session); tech_init(tech_pvt, *new_session, zchan); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); From c909649b85f8236e527b1437d054585c62dc548c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jan 2009 17:50:26 +0000 Subject: [PATCH 1204/1766] add type of num var for pri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@623 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ef1bd3e520..ce0d5042d7 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -901,7 +901,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char *argv[3]; int argc = 0; const char *var; - + switch_channel_t *channel = NULL; + + if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -969,7 +971,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_set_string(caller_data.ani.digits, dest); } - if ((var = switch_event_get_header(var_event, "openzap_outbound_ton"))) { + channel = switch_core_session_get_channel(*new_session); + + if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_channel_get_variable(channel, "openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { caller_data.ani.type = Q931_TON_NATIONAL; } @@ -1011,12 +1015,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; - switch_channel_t *channel; switch_caller_profile_t *caller_profile; switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { - channel = switch_core_session_get_channel(*new_session); tech_init(tech_pvt, *new_session, zchan); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); From 45f3e3472dd14164dee2d0803d80029ea7bb843e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jan 2009 18:05:22 +0000 Subject: [PATCH 1205/1766] add type of num var for pri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@624 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ce0d5042d7..5639cf8b82 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -901,8 +901,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char *argv[3]; int argc = 0; const char *var; - switch_channel_t *channel = NULL; - if (!outbound_profile) { @@ -971,18 +969,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_set_string(caller_data.ani.digits, dest); } - channel = switch_core_session_get_channel(*new_session); - - if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_channel_get_variable(channel, "openzap_outbound_ton"))) { + if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { caller_data.ani.type = Q931_TON_NATIONAL; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; } - + caller_data.ani.plan = outbound_profile->destination_number_numplan; + #if 0 if (!switch_strlen_zero(outbound_profile->rdnis)) { zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); @@ -1016,7 +1013,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_caller_profile_t *caller_profile; - + switch_channel_t *channel = switch_core_session_get_channel(*new_session); + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { tech_init(tech_pvt, *new_session, zchan); From 80c5d2b727144803ff9951b70e01f791092e0707 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jan 2009 18:05:22 +0000 Subject: [PATCH 1206/1766] add type of num var for pri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@624 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ce0d5042d7..5639cf8b82 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -901,8 +901,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char *argv[3]; int argc = 0; const char *var; - switch_channel_t *channel = NULL; - if (!outbound_profile) { @@ -971,18 +969,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_set_string(caller_data.ani.digits, dest); } - channel = switch_core_session_get_channel(*new_session); - - if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_channel_get_variable(channel, "openzap_outbound_ton"))) { + if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { caller_data.ani.type = Q931_TON_NATIONAL; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; } - + caller_data.ani.plan = outbound_profile->destination_number_numplan; + #if 0 if (!switch_strlen_zero(outbound_profile->rdnis)) { zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); @@ -1016,7 +1013,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_caller_profile_t *caller_profile; - + switch_channel_t *channel = switch_core_session_get_channel(*new_session); + switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { tech_init(tech_pvt, *new_session, zchan); From 10060435039edc2e6277238bb6f272af16abc493 Mon Sep 17 00:00:00 2001 From: Raymond Chandler Date: Tue, 13 Jan 2009 17:26:36 +0000 Subject: [PATCH 1207/1766] OPENZAP-42 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@625 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/build/config.guess | 26 ++- libs/openzap/build/config.sub | 28 +-- libs/openzap/build/ltmain.sh | 197 ++++++++++++++------- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 2 +- 4 files changed, 164 insertions(+), 89 deletions(-) diff --git a/libs/openzap/build/config.guess b/libs/openzap/build/config.guess index 2fc3acce2e..0e30d56e94 100755 --- a/libs/openzap/build/config.guess +++ b/libs/openzap/build/config.guess @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2003-06-17' +timestamp='2003-07-02' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -136,13 +136,6 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -## for Red Hat Linux -if test -f /etc/redhat-release ; then - VENDOR=redhat ; -else - VENDOR= ; -fi - # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in @@ -770,7 +763,10 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} + # GNU/FreeBSD systems have a "k" prefix to indicate we are using + # FreeBSD's kernel, but not the complete OS. + case ${LIBC} in gnu) kernel_only='k' ;; esac + echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} exit 0 ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin @@ -815,7 +811,7 @@ EOF echo cris-axis-linux-gnu exit 0 ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR:-unknown}-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu @@ -859,10 +855,10 @@ EOF test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; ppc:Linux:*:*) - echo powerpc-${VENDOR:-unknown}-linux-gnu + echo powerpc-unknown-linux-gnu exit 0 ;; ppc64:Linux:*:*) - echo powerpc64-${VENDOR:-unknown}-linux-gnu + echo powerpc64-unknown-linux-gnu exit 0 ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in @@ -890,7 +886,7 @@ EOF echo hppa64-unknown-linux-gnu exit 0 ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR:-ibm}-linux-gnu + echo ${UNAME_MACHINE}-ibm-linux exit 0 ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu @@ -902,7 +898,7 @@ EOF echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; x86_64:Linux:*:*) - echo x86_64-${VENDOR:-unknown}-linux-gnu + echo x86_64-unknown-linux-gnu exit 0 ;; i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so @@ -954,7 +950,7 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - test x"${LIBC}" != x && echo "${UNAME_MACHINE}-${VENDOR:-pc}-linux-${LIBC}" && exit 0 + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ;; i*86:DYNIX/ptx:4*:*) diff --git a/libs/openzap/build/config.sub b/libs/openzap/build/config.sub index 6b2ff9f6a7..9d7f733905 100755 --- a/libs/openzap/build/config.sub +++ b/libs/openzap/build/config.sub @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2003-06-18' +timestamp='2003-07-04' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -118,7 +118,7 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -257,10 +257,9 @@ case $basic_machine in | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ - | s390 | s390x \ | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ - | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ | strongarm \ | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ @@ -293,7 +292,7 @@ case $basic_machine in | a29k-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* \ | bs2000-* \ @@ -330,11 +329,10 @@ case $basic_machine in | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ - | s390-* | s390x-* \ | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ + | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ @@ -833,6 +831,12 @@ case $basic_machine in rtpc | rtpc-*) basic_machine=romp-ibm ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; sa29200) basic_machine=a29k-amd os=-udi @@ -1051,7 +1055,7 @@ case $basic_machine in sh64) basic_machine=sh64-unknown ;; - sparc | sparcv8 | sparcv9 | sparcv9b) + sparc | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; cydra) @@ -1124,7 +1128,7 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ @@ -1282,9 +1286,9 @@ case $basic_machine in arm*-semi) os=-aout ;; - c4x-* | tic4x-*) - os=-coff - ;; + c4x-* | tic4x-*) + os=-coff + ;; # This must come before the *-dec entry. pdp10-*) os=-tops20 diff --git a/libs/openzap/build/ltmain.sh b/libs/openzap/build/ltmain.sh index 0223495a02..c9698e72c3 100644 --- a/libs/openzap/build/ltmain.sh +++ b/libs/openzap/build/ltmain.sh @@ -1,8 +1,8 @@ # ltmain.sh - Provide generalized library-building support services. # NOTE: Changing this file will not affect anything until you rerun configure. # -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 -# Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, +# 2007 Free Software Foundation, Inc. # Originally by Gordon Matzigkeit , 1996 # # This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ EXIT_FAILURE=1 PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.5.22 -TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)" +VERSION=1.5.24 +TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" # Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -57,6 +57,8 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then else case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh # Check that we have a working $echo. if test "X$1" = X--no-reexec; then @@ -114,10 +116,10 @@ esac for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then - save_$lt_var=\$$lt_var - $lt_var=C - export $lt_var - fi" + save_$lt_var=\$$lt_var + $lt_var=C + export $lt_var + fi" done # Make sure IFS has a sensible default @@ -206,7 +208,13 @@ func_win32_libid () if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then win32_nmres=`eval $NM -f posix -A $1 | \ - $SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'` + $SED -n -e '1,100{ + / I /{ + s,.*,import, + p + q + } + }'` case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; @@ -236,6 +244,20 @@ func_win32_libid () # arg is usually of the form 'gcc ...' func_infer_tag () { + # FreeBSD-specific: where we install compilers with non-standard names + tag_compilers_CC="*cc cc* *gcc gcc*" + tag_compilers_CXX="*c++ c++* *g++ g++*" + base_compiler=`set -- "$@"; echo $1` + + # If $tagname isn't set, then try to infer if the default "CC" tag applies + if test -z "$tagname"; then + for zp in $tag_compilers_CC; do + case $base_compiler in + $zp) tagname="CC"; break;; + esac + done + fi + if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do @@ -276,7 +298,22 @@ func_infer_tag () break ;; esac - fi + + # FreeBSD-specific: try compilers based on inferred tag + if test -z "$tagname"; then + eval "tag_compilers=\$tag_compilers_${z}" + if test -n "$tag_compilers"; then + for zp in $tag_compilers; do + case $base_compiler in + $zp) tagname=$z; break;; + esac + done + if test -n "$tagname"; then + break + fi + fi + fi + fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command @@ -340,11 +377,11 @@ func_extract_archives () my_xlib_u=$my_xlib while :; do case " $extracted_archives " in - *" $my_xlib_u "*) - extracted_serial=`expr $extracted_serial + 1` - my_xlib_u=lt$extracted_serial-$my_xlib ;; - *) break ;; - esac + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir="$my_gentop/$my_xlib_u" @@ -474,11 +511,12 @@ do ;; --version) - $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP" - $echo - $echo "Copyright (C) 2005 Free Software Foundation, Inc." - $echo "This is free software; see the source for copying conditions. There is NO" - $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + echo "\ +$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP + +Copyright (C) 2007 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." exit $? ;; @@ -775,7 +813,7 @@ if test -z "$show_help"; then *.class) xform=class ;; *.cpp) xform=cpp ;; *.cxx) xform=cxx ;; - *.f90) xform=f90 ;; + *.[fF][09]?) xform=[fF][09]. ;; *.for) xform=for ;; *.java) xform=java ;; *.obj) xform=obj ;; @@ -1160,8 +1198,8 @@ EOF do case $arg in -all-static | -static | -static-libtool-libs) - case $arg in - -all-static) + case $arg in + -all-static) if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2 fi @@ -1170,19 +1208,19 @@ EOF fi prefer_static_libs=yes ;; - -static) + -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; - -static-libtool-libs) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - esac + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac build_libtool_libs=no build_old_libs=yes break @@ -1630,10 +1668,11 @@ EOF continue ;; - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) compiler_flags="$compiler_flags $arg" compile_command="$compile_command $arg" finalize_command="$finalize_command $arg" + deplibs="$deplibs $arg" continue ;; @@ -1650,10 +1689,11 @@ EOF # -m* pass through architecture-specific compiler args for GCC # -m*, -t[45]*, -txscale* pass through architecture-specific # compiler args for GCC - # -pg pass through profiling flag for GCC + # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC + # -F/path gives path to uninstalled frameworks, gcc on darwin # @file GCC response files - -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \ - -t[45]*|-txscale*|@*) + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. @@ -1681,9 +1721,9 @@ EOF -no-install) case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) # The PATH hackery in wrapper scripts is required on Windows - # in order for the loader to find any dlls it needs. + # and Darwin in order for the loader to find any dlls it needs. $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 fast_install=no @@ -2124,13 +2164,36 @@ EOF lib= found=no case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else compiler_flags="$compiler_flags $deplib" fi + + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test "$pass" = conv && continue + newdependency_libs="$deplib $newdependency_libs" + ;; + prog) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + if test "$pass" = scan; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + ;; + *) + ;; + esac # linkmode + continue ;; -l*) @@ -2520,9 +2583,9 @@ EOF if test "$linkmode,$pass" = "prog,link"; then if test -n "$library_names" && - { { test "$prefer_static_libs" = no || - test "$prefer_static_libs,$installed" = "built,yes"; } || - test -z "$old_library"; }; then + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then # We need to hardcode the library path if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then # Make sure the rpath contains only unique directories. @@ -3229,9 +3292,10 @@ EOF age="0" ;; irix|nonstopux) - current=`expr $number_major + $number_minor - 1` + current=`expr $number_major + $number_minor` age="$number_minor" revision="$number_minor" + lt_irix_increment=no ;; esac ;; @@ -3290,7 +3354,8 @@ EOF versuffix="$major.$age.$revision" # Darwin ld doesn't like 0 for these options... minor_current=`expr $current + 1` - verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" ;; freebsd-aout) @@ -3304,8 +3369,11 @@ EOF ;; irix | nonstopux) - major=`expr $current - $age + 1` - + if test "X$lt_irix_increment" = "Xno"; then + major=`expr $current - $age` + else + major=`expr $current - $age + 1` + fi case $version_type in nonstopux) verstring_prefix=nonstopux ;; *) verstring_prefix=sgi ;; @@ -3442,11 +3510,11 @@ EOF fi # Eliminate all temporary directories. -# for path in $notinst_path; do -# lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` -# deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` -# dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` -# done + #for path in $notinst_path; do + # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` + # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` + # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` + #done if test -n "$xrpath"; then # If the user specified any rpath flags, then add them. @@ -3547,7 +3615,7 @@ EOF int main() { return 0; } EOF $rm conftest - if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then + if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then ldd_output=`ldd conftest` for i in $deplibs; do name=`expr $i : '-l\(.*\)'` @@ -3909,7 +3977,10 @@ EOF test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" if test -n "$hardcode_libdir_flag_spec_ld"; then - eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" + case $archive_cmds in + *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; + *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; + esac else eval dep_rpath=\"$hardcode_libdir_flag_spec\" fi @@ -4275,7 +4346,7 @@ EOF if test -n "$convenience"; then if test -n "$whole_archive_flag_spec"; then eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" - reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` else gentop="$output_objdir/${obj}x" generated="$generated $gentop" @@ -4736,6 +4807,9 @@ static const void *lt_preloaded_setup() { ;; esac ;; + *-*-freebsd*) + # FreeBSD doesn't need this... + ;; *) $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 exit $EXIT_FAILURE @@ -5295,6 +5369,8 @@ if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. @@ -6391,8 +6467,10 @@ relink_command=\"$relink_command\"" if test -f "$dir/$objdir/$dlname"; then dir="$dir/$objdir" else - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit $EXIT_FAILURE + if test ! -f "$dir/$dlname"; then + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE + fi fi ;; @@ -6458,14 +6536,11 @@ relink_command=\"$relink_command\"" # Restore saved environment variables for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do - eval "if test \"\${save_$lt_var+set}\" = set; then - $lt_var=\$save_$lt_var; export $lt_var - else - $lt_unset $lt_var - fi" + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + fi" done - # Now prepare to actually exec the command. exec_cmd="\$cmd$args" else diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index a4802463e3..0648ab28b8 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -726,7 +726,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; default: { - zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); + 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; From 442754e7d11f1fd15ecbe52880a4909777dcffdb Mon Sep 17 00:00:00 2001 From: Raymond Chandler Date: Tue, 13 Jan 2009 17:26:36 +0000 Subject: [PATCH 1208/1766] OPENZAP-42 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@625 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/build/config.guess | 26 ++- libs/freetdm/build/config.sub | 28 +-- libs/freetdm/build/ltmain.sh | 197 ++++++++++++++------- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 2 +- 4 files changed, 164 insertions(+), 89 deletions(-) diff --git a/libs/freetdm/build/config.guess b/libs/freetdm/build/config.guess index 2fc3acce2e..0e30d56e94 100755 --- a/libs/freetdm/build/config.guess +++ b/libs/freetdm/build/config.guess @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2003-06-17' +timestamp='2003-07-02' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -136,13 +136,6 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -## for Red Hat Linux -if test -f /etc/redhat-release ; then - VENDOR=redhat ; -else - VENDOR= ; -fi - # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in @@ -770,7 +763,10 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} + # GNU/FreeBSD systems have a "k" prefix to indicate we are using + # FreeBSD's kernel, but not the complete OS. + case ${LIBC} in gnu) kernel_only='k' ;; esac + echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} exit 0 ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin @@ -815,7 +811,7 @@ EOF echo cris-axis-linux-gnu exit 0 ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR:-unknown}-linux-gnu + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu @@ -859,10 +855,10 @@ EOF test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; ppc:Linux:*:*) - echo powerpc-${VENDOR:-unknown}-linux-gnu + echo powerpc-unknown-linux-gnu exit 0 ;; ppc64:Linux:*:*) - echo powerpc64-${VENDOR:-unknown}-linux-gnu + echo powerpc64-unknown-linux-gnu exit 0 ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in @@ -890,7 +886,7 @@ EOF echo hppa64-unknown-linux-gnu exit 0 ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR:-ibm}-linux-gnu + echo ${UNAME_MACHINE}-ibm-linux exit 0 ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu @@ -902,7 +898,7 @@ EOF echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; x86_64:Linux:*:*) - echo x86_64-${VENDOR:-unknown}-linux-gnu + echo x86_64-unknown-linux-gnu exit 0 ;; i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so @@ -954,7 +950,7 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - test x"${LIBC}" != x && echo "${UNAME_MACHINE}-${VENDOR:-pc}-linux-${LIBC}" && exit 0 + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ;; i*86:DYNIX/ptx:4*:*) diff --git a/libs/freetdm/build/config.sub b/libs/freetdm/build/config.sub index 6b2ff9f6a7..9d7f733905 100755 --- a/libs/freetdm/build/config.sub +++ b/libs/freetdm/build/config.sub @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2003-06-18' +timestamp='2003-07-04' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -118,7 +118,7 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | freebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -257,10 +257,9 @@ case $basic_machine in | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ - | s390 | s390x \ | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ - | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ | strongarm \ | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ @@ -293,7 +292,7 @@ case $basic_machine in | a29k-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* \ | bs2000-* \ @@ -330,11 +329,10 @@ case $basic_machine in | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ - | s390-* | s390x-* \ | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ + | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ @@ -833,6 +831,12 @@ case $basic_machine in rtpc | rtpc-*) basic_machine=romp-ibm ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; sa29200) basic_machine=a29k-amd os=-udi @@ -1051,7 +1055,7 @@ case $basic_machine in sh64) basic_machine=sh64-unknown ;; - sparc | sparcv8 | sparcv9 | sparcv9b) + sparc | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; cydra) @@ -1124,7 +1128,7 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ @@ -1282,9 +1286,9 @@ case $basic_machine in arm*-semi) os=-aout ;; - c4x-* | tic4x-*) - os=-coff - ;; + c4x-* | tic4x-*) + os=-coff + ;; # This must come before the *-dec entry. pdp10-*) os=-tops20 diff --git a/libs/freetdm/build/ltmain.sh b/libs/freetdm/build/ltmain.sh index 0223495a02..c9698e72c3 100644 --- a/libs/freetdm/build/ltmain.sh +++ b/libs/freetdm/build/ltmain.sh @@ -1,8 +1,8 @@ # ltmain.sh - Provide generalized library-building support services. # NOTE: Changing this file will not affect anything until you rerun configure. # -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 -# Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, +# 2007 Free Software Foundation, Inc. # Originally by Gordon Matzigkeit , 1996 # # This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ EXIT_FAILURE=1 PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.5.22 -TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)" +VERSION=1.5.24 +TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" # Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -57,6 +57,8 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then else case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh # Check that we have a working $echo. if test "X$1" = X--no-reexec; then @@ -114,10 +116,10 @@ esac for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then - save_$lt_var=\$$lt_var - $lt_var=C - export $lt_var - fi" + save_$lt_var=\$$lt_var + $lt_var=C + export $lt_var + fi" done # Make sure IFS has a sensible default @@ -206,7 +208,13 @@ func_win32_libid () if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then win32_nmres=`eval $NM -f posix -A $1 | \ - $SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'` + $SED -n -e '1,100{ + / I /{ + s,.*,import, + p + q + } + }'` case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; @@ -236,6 +244,20 @@ func_win32_libid () # arg is usually of the form 'gcc ...' func_infer_tag () { + # FreeBSD-specific: where we install compilers with non-standard names + tag_compilers_CC="*cc cc* *gcc gcc*" + tag_compilers_CXX="*c++ c++* *g++ g++*" + base_compiler=`set -- "$@"; echo $1` + + # If $tagname isn't set, then try to infer if the default "CC" tag applies + if test -z "$tagname"; then + for zp in $tag_compilers_CC; do + case $base_compiler in + $zp) tagname="CC"; break;; + esac + done + fi + if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do @@ -276,7 +298,22 @@ func_infer_tag () break ;; esac - fi + + # FreeBSD-specific: try compilers based on inferred tag + if test -z "$tagname"; then + eval "tag_compilers=\$tag_compilers_${z}" + if test -n "$tag_compilers"; then + for zp in $tag_compilers; do + case $base_compiler in + $zp) tagname=$z; break;; + esac + done + if test -n "$tagname"; then + break + fi + fi + fi + fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command @@ -340,11 +377,11 @@ func_extract_archives () my_xlib_u=$my_xlib while :; do case " $extracted_archives " in - *" $my_xlib_u "*) - extracted_serial=`expr $extracted_serial + 1` - my_xlib_u=lt$extracted_serial-$my_xlib ;; - *) break ;; - esac + *" $my_xlib_u "*) + extracted_serial=`expr $extracted_serial + 1` + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir="$my_gentop/$my_xlib_u" @@ -474,11 +511,12 @@ do ;; --version) - $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP" - $echo - $echo "Copyright (C) 2005 Free Software Foundation, Inc." - $echo "This is free software; see the source for copying conditions. There is NO" - $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + echo "\ +$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP + +Copyright (C) 2007 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." exit $? ;; @@ -775,7 +813,7 @@ if test -z "$show_help"; then *.class) xform=class ;; *.cpp) xform=cpp ;; *.cxx) xform=cxx ;; - *.f90) xform=f90 ;; + *.[fF][09]?) xform=[fF][09]. ;; *.for) xform=for ;; *.java) xform=java ;; *.obj) xform=obj ;; @@ -1160,8 +1198,8 @@ EOF do case $arg in -all-static | -static | -static-libtool-libs) - case $arg in - -all-static) + case $arg in + -all-static) if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2 fi @@ -1170,19 +1208,19 @@ EOF fi prefer_static_libs=yes ;; - -static) + -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; - -static-libtool-libs) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - esac + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac build_libtool_libs=no build_old_libs=yes break @@ -1630,10 +1668,11 @@ EOF continue ;; - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) compiler_flags="$compiler_flags $arg" compile_command="$compile_command $arg" finalize_command="$finalize_command $arg" + deplibs="$deplibs $arg" continue ;; @@ -1650,10 +1689,11 @@ EOF # -m* pass through architecture-specific compiler args for GCC # -m*, -t[45]*, -txscale* pass through architecture-specific # compiler args for GCC - # -pg pass through profiling flag for GCC + # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC + # -F/path gives path to uninstalled frameworks, gcc on darwin # @file GCC response files - -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \ - -t[45]*|-txscale*|@*) + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. @@ -1681,9 +1721,9 @@ EOF -no-install) case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) # The PATH hackery in wrapper scripts is required on Windows - # in order for the loader to find any dlls it needs. + # and Darwin in order for the loader to find any dlls it needs. $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 fast_install=no @@ -2124,13 +2164,36 @@ EOF lib= found=no case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe) + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else compiler_flags="$compiler_flags $deplib" fi + + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test "$pass" = conv && continue + newdependency_libs="$deplib $newdependency_libs" + ;; + prog) + if test "$pass" = conv; then + deplibs="$deplib $deplibs" + continue + fi + if test "$pass" = scan; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + ;; + *) + ;; + esac # linkmode + continue ;; -l*) @@ -2520,9 +2583,9 @@ EOF if test "$linkmode,$pass" = "prog,link"; then if test -n "$library_names" && - { { test "$prefer_static_libs" = no || - test "$prefer_static_libs,$installed" = "built,yes"; } || - test -z "$old_library"; }; then + { { test "$prefer_static_libs" = no || + test "$prefer_static_libs,$installed" = "built,yes"; } || + test -z "$old_library"; }; then # We need to hardcode the library path if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then # Make sure the rpath contains only unique directories. @@ -3229,9 +3292,10 @@ EOF age="0" ;; irix|nonstopux) - current=`expr $number_major + $number_minor - 1` + current=`expr $number_major + $number_minor` age="$number_minor" revision="$number_minor" + lt_irix_increment=no ;; esac ;; @@ -3290,7 +3354,8 @@ EOF versuffix="$major.$age.$revision" # Darwin ld doesn't like 0 for these options... minor_current=`expr $current + 1` - verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" ;; freebsd-aout) @@ -3304,8 +3369,11 @@ EOF ;; irix | nonstopux) - major=`expr $current - $age + 1` - + if test "X$lt_irix_increment" = "Xno"; then + major=`expr $current - $age` + else + major=`expr $current - $age + 1` + fi case $version_type in nonstopux) verstring_prefix=nonstopux ;; *) verstring_prefix=sgi ;; @@ -3442,11 +3510,11 @@ EOF fi # Eliminate all temporary directories. -# for path in $notinst_path; do -# lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` -# deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` -# dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` -# done + #for path in $notinst_path; do + # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` + # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` + # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` + #done if test -n "$xrpath"; then # If the user specified any rpath flags, then add them. @@ -3547,7 +3615,7 @@ EOF int main() { return 0; } EOF $rm conftest - if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then + if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then ldd_output=`ldd conftest` for i in $deplibs; do name=`expr $i : '-l\(.*\)'` @@ -3909,7 +3977,10 @@ EOF test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" if test -n "$hardcode_libdir_flag_spec_ld"; then - eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" + case $archive_cmds in + *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; + *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; + esac else eval dep_rpath=\"$hardcode_libdir_flag_spec\" fi @@ -4275,7 +4346,7 @@ EOF if test -n "$convenience"; then if test -n "$whole_archive_flag_spec"; then eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" - reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` + reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` else gentop="$output_objdir/${obj}x" generated="$generated $gentop" @@ -4736,6 +4807,9 @@ static const void *lt_preloaded_setup() { ;; esac ;; + *-*-freebsd*) + # FreeBSD doesn't need this... + ;; *) $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 exit $EXIT_FAILURE @@ -5295,6 +5369,8 @@ if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. @@ -6391,8 +6467,10 @@ relink_command=\"$relink_command\"" if test -f "$dir/$objdir/$dlname"; then dir="$dir/$objdir" else - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit $EXIT_FAILURE + if test ! -f "$dir/$dlname"; then + $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 + exit $EXIT_FAILURE + fi fi ;; @@ -6458,14 +6536,11 @@ relink_command=\"$relink_command\"" # Restore saved environment variables for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do - eval "if test \"\${save_$lt_var+set}\" = set; then - $lt_var=\$save_$lt_var; export $lt_var - else - $lt_unset $lt_var - fi" + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + fi" done - # Now prepare to actually exec the command. exec_cmd="\$cmd$args" else diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index a4802463e3..0648ab28b8 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -726,7 +726,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; default: { - zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", zt_event_id); + 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; From 355ff93aa4d9ee4126bbffdcf10abc32f047991d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 13 Jan 2009 22:45:09 +0000 Subject: [PATCH 1209/1766] fix strange openzap build issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@626 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 3 +- .../mod_openzap/{Makefile => Makefile.in} | 8 ++-- libs/openzap/mod_openzap/mod_openzap.c | 37 ++++++++++--------- 3 files changed, 27 insertions(+), 21 deletions(-) rename libs/openzap/mod_openzap/{Makefile => Makefile.in} (79%) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index ae71dcba1a..7451ecc647 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -142,5 +142,6 @@ fi COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile + mod_openzap/Makefile]) AC_OUTPUT diff --git a/libs/openzap/mod_openzap/Makefile b/libs/openzap/mod_openzap/Makefile.in similarity index 79% rename from libs/openzap/mod_openzap/Makefile rename to libs/openzap/mod_openzap/Makefile.in index 025e0df927..e4271e38a4 100644 --- a/libs/openzap/mod_openzap/Makefile +++ b/libs/openzap/mod_openzap/Makefile.in @@ -1,18 +1,20 @@ +OZ_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ + BASE=../../.. OZ_DIR=.. VERBOSE=1 OZSO=$(OZ_DIR)/libopenzap.so -LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include +LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include $(OZ_CFLAGS) LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap include $(BASE)/build/modmake.rules local_depend: $(OZSO) $(OZSO): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) ZAP_CFLAGS="$(ALL_CXXFLAGS)" + cd $(OZ_DIR) && $(MAKE) local_install: - cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)" + cd $(OZ_DIR) && $(MAKE) install [ -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs local_clean: diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5639cf8b82..de551ce1ec 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -127,6 +127,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); +zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp); +void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) @@ -271,7 +273,7 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) { - char *dname = NULL; + const char *dname = NULL; uint32_t interval = 0, srate = 8000; zap_codec_t codec; @@ -888,7 +890,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_originate_flag_t flags) { - char *dest = NULL, *data = NULL; + const char *dest = NULL; + char *data = NULL; int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -1554,7 +1557,7 @@ static uint32_t enable_analog_option(const char *str, uint32_t current_options) static switch_status_t load_config(void) { - char *cf = "openzap.conf"; + const char *cf = "openzap.conf"; switch_xml_t cfg, xml, settings, param, spans, myspan; memset(&globals, 0, sizeof(globals)); @@ -1584,16 +1587,16 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; - char *tonegroup = NULL; + const char *context = "default"; + const char *dialplan = "XML"; + const char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; char *hotline = NULL; char *dial_regex = NULL; char *hold_music = NULL; char *fail_dial_regex = NULL; - char *enable_callerid = "true"; + const char *enable_callerid = "true"; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; @@ -1706,9 +1709,9 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; - char *tonegroup = NULL; + const char *context = "default"; + const char *dialplan = "XML"; + const char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; char *dial_regex = NULL; @@ -1820,15 +1823,15 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; + const char *context = "default"; + const char *dialplan = "XML"; //Q921NetUser_t mode = Q931_TE; //Q931Dialect_t dialect = Q931_Dialect_National; char *mode = NULL; char *dialect = NULL; uint32_t span_id = 0; zap_span_t *span = NULL; - char *tonegroup = NULL; + const char *tonegroup = NULL; char *digit_timeout = NULL; uint32_t to = 0; uint32_t opts = 0; @@ -1927,11 +1930,11 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; + const char *context = "default"; + const char *dialplan = "XML"; uint32_t span_id = 0; zap_span_t *span = NULL; - char *tonegroup = NULL; + const char *tonegroup = NULL; char *local_ip = NULL; int local_port = 0; char *remote_ip = NULL; @@ -2101,7 +2104,7 @@ SWITCH_STANDARD_API(oz_function) int j; for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { if (SPAN_CONFIG[j].span) { - char *flags = "none"; + const char *flags = "none"; if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { flags = "3way"; From d5f2bf456d08bcd263a519d2d74121c6a3414f25 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 13 Jan 2009 22:45:09 +0000 Subject: [PATCH 1210/1766] fix strange openzap build issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@626 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 3 +- .../mod_openzap/{Makefile => Makefile.in} | 8 ++-- libs/freetdm/mod_openzap/mod_openzap.c | 37 ++++++++++--------- 3 files changed, 27 insertions(+), 21 deletions(-) rename libs/freetdm/mod_openzap/{Makefile => Makefile.in} (79%) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index ae71dcba1a..7451ecc647 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -142,5 +142,6 @@ fi COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile + mod_openzap/Makefile]) AC_OUTPUT diff --git a/libs/freetdm/mod_openzap/Makefile b/libs/freetdm/mod_openzap/Makefile.in similarity index 79% rename from libs/freetdm/mod_openzap/Makefile rename to libs/freetdm/mod_openzap/Makefile.in index 025e0df927..e4271e38a4 100644 --- a/libs/freetdm/mod_openzap/Makefile +++ b/libs/freetdm/mod_openzap/Makefile.in @@ -1,18 +1,20 @@ +OZ_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ + BASE=../../.. OZ_DIR=.. VERBOSE=1 OZSO=$(OZ_DIR)/libopenzap.so -LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include +LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include $(OZ_CFLAGS) LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap include $(BASE)/build/modmake.rules local_depend: $(OZSO) $(OZSO): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) ZAP_CFLAGS="$(ALL_CXXFLAGS)" + cd $(OZ_DIR) && $(MAKE) local_install: - cd $(OZ_DIR) && $(MAKE) install ZAP_CFLAGS="$(ALL_CXXFLAGS)" + cd $(OZ_DIR) && $(MAKE) install [ -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs local_clean: diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5639cf8b82..de551ce1ec 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -127,6 +127,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); +zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp); +void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) @@ -271,7 +273,7 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) { - char *dname = NULL; + const char *dname = NULL; uint32_t interval = 0, srate = 8000; zap_codec_t codec; @@ -888,7 +890,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_originate_flag_t flags) { - char *dest = NULL, *data = NULL; + const char *dest = NULL; + char *data = NULL; int span_id = 0, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -1554,7 +1557,7 @@ static uint32_t enable_analog_option(const char *str, uint32_t current_options) static switch_status_t load_config(void) { - char *cf = "openzap.conf"; + const char *cf = "openzap.conf"; switch_xml_t cfg, xml, settings, param, spans, myspan; memset(&globals, 0, sizeof(globals)); @@ -1584,16 +1587,16 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; - char *tonegroup = NULL; + const char *context = "default"; + const char *dialplan = "XML"; + const char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; char *hotline = NULL; char *dial_regex = NULL; char *hold_music = NULL; char *fail_dial_regex = NULL; - char *enable_callerid = "true"; + const char *enable_callerid = "true"; uint32_t span_id = 0, to = 0, max = 0; zap_span_t *span = NULL; @@ -1706,9 +1709,9 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; - char *tonegroup = NULL; + const char *context = "default"; + const char *dialplan = "XML"; + const char *tonegroup = NULL; char *digit_timeout = NULL; char *max_digits = NULL; char *dial_regex = NULL; @@ -1820,15 +1823,15 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; + const char *context = "default"; + const char *dialplan = "XML"; //Q921NetUser_t mode = Q931_TE; //Q931Dialect_t dialect = Q931_Dialect_National; char *mode = NULL; char *dialect = NULL; uint32_t span_id = 0; zap_span_t *span = NULL; - char *tonegroup = NULL; + const char *tonegroup = NULL; char *digit_timeout = NULL; uint32_t to = 0; uint32_t opts = 0; @@ -1927,11 +1930,11 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); zap_status_t zstatus = ZAP_FAIL; - char *context = "default"; - char *dialplan = "XML"; + const char *context = "default"; + const char *dialplan = "XML"; uint32_t span_id = 0; zap_span_t *span = NULL; - char *tonegroup = NULL; + const char *tonegroup = NULL; char *local_ip = NULL; int local_port = 0; char *remote_ip = NULL; @@ -2101,7 +2104,7 @@ SWITCH_STANDARD_API(oz_function) int j; for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { if (SPAN_CONFIG[j].span) { - char *flags = "none"; + const char *flags = "none"; if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { flags = "3way"; From ac172da18b0013387c2e607a5500ca29e5f45213 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 29 Jan 2009 18:56:16 +0000 Subject: [PATCH 1211/1766] fix crazy build issue with broken gcc optimizer on bleeding edge ubuntu git-svn-id: http://svn.openzap.org/svn/openzap/trunk@627 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.ac | 2 +- .../ozmod_wanpipe/wanpipe_tdm_api_iface.h | 36 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 7451ecc647..cb613a79d5 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -51,7 +51,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -O0" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" 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 index cfb4c151ac..3801ff9c8c 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h @@ -187,40 +187,40 @@ enum wanpipe_tdm_api_events { typedef struct { - uint8_t type; - uint8_t mode; - uint32_t time_stamp; - uint8_t channel; - uint32_t chan_map; - uint8_t span; + 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 { - uint8_t alarm; + u_int8_t alarm; } te1_alarm; struct { - uint8_t rbs_bits; + u_int8_t rbs_bits; } te1_rbs; struct { - uint8_t state; - uint8_t sig; + u_int8_t state; + u_int8_t sig; } rm_hook; struct { - uint8_t state; + u_int8_t state; } rm_ring; struct { - uint8_t type; + u_int8_t type; } rm_tone; struct { - uint8_t digit; /* DTMF: digit */ - uint8_t port; /* DTMF: SOUT/ROUT */ - uint8_t type; /* DTMF: PRESET/STOP */ + u_int8_t digit; /* DTMF: digit */ + u_int8_t port; /* DTMF: SOUT/ROUT */ + u_int8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - uint16_t polarity; - uint16_t ohttimer; + u_int16_t polarity; + u_int16_t ohttimer; } rm_common; struct{ - uint16_t status; + u_int16_t status; } linkstatus; } wp_tdm_api_event_u; #define wp_tdm_api_event_type type From e29ec54993de9adaf636d9ef736eb0560fe6c8b8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 29 Jan 2009 18:56:16 +0000 Subject: [PATCH 1212/1766] fix crazy build issue with broken gcc optimizer on bleeding edge ubuntu git-svn-id: http://svn.openzap.org/svn/openzap/trunk@627 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/configure.ac | 2 +- .../ozmod_wanpipe/wanpipe_tdm_api_iface.h | 36 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 7451ecc647..cb613a79d5 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -51,7 +51,7 @@ AX_COMPILER_VENDOR case "${ax_cv_c_compiler_vendor}" in gnu) - COMP_VENDOR_CFLAGS="-ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" + COMP_VENDOR_CFLAGS="-ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -O0" ;; sun) COMP_VENDOR_CFLAGS="-xc99=all -mt -xCC -D__FUNCTION__=__func__ -xvpara" diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h index cfb4c151ac..3801ff9c8c 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h @@ -187,40 +187,40 @@ enum wanpipe_tdm_api_events { typedef struct { - uint8_t type; - uint8_t mode; - uint32_t time_stamp; - uint8_t channel; - uint32_t chan_map; - uint8_t span; + 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 { - uint8_t alarm; + u_int8_t alarm; } te1_alarm; struct { - uint8_t rbs_bits; + u_int8_t rbs_bits; } te1_rbs; struct { - uint8_t state; - uint8_t sig; + u_int8_t state; + u_int8_t sig; } rm_hook; struct { - uint8_t state; + u_int8_t state; } rm_ring; struct { - uint8_t type; + u_int8_t type; } rm_tone; struct { - uint8_t digit; /* DTMF: digit */ - uint8_t port; /* DTMF: SOUT/ROUT */ - uint8_t type; /* DTMF: PRESET/STOP */ + u_int8_t digit; /* DTMF: digit */ + u_int8_t port; /* DTMF: SOUT/ROUT */ + u_int8_t type; /* DTMF: PRESET/STOP */ } dtmf; struct { - uint16_t polarity; - uint16_t ohttimer; + u_int16_t polarity; + u_int16_t ohttimer; } rm_common; struct{ - uint16_t status; + u_int16_t status; } linkstatus; } wp_tdm_api_event_u; #define wp_tdm_api_event_type type From 8333afcb593d39cb52c7e458c2f77dff637dd494 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Fri, 30 Jan 2009 11:37:11 +0000 Subject: [PATCH 1213/1766] Q931ToPcap patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@628 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 7 + libs/openzap/build/config.guess | 671 +++++++++++------- libs/openzap/build/config.sub | 240 +++++-- libs/openzap/build/ltmain.sh | 59 +- libs/openzap/mod_openzap/mod_openzap.c | 69 +- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 253 ++++++- 6 files changed, 977 insertions(+), 322 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 8c69bafe12..9094c1b8ce 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -34,6 +34,11 @@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ + +###For libpcap +CFLAGS+=-D_GNU_SOURCE +#### + LIBS = @LIBS@ DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ SOLINK = @SOLINK@ @@ -270,6 +275,8 @@ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $ $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) +$(ISDN_OBJS2): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c + $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) diff --git a/libs/openzap/build/config.guess b/libs/openzap/build/config.guess index 0e30d56e94..2b73846398 100755 --- a/libs/openzap/build/config.guess +++ b/libs/openzap/build/config.guess @@ -1,7 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. timestamp='2003-07-02' @@ -17,13 +18,15 @@ timestamp='2003-07-02' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. + # Originally written by Per Bothner . # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. @@ -53,7 +56,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -66,11 +69,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit 0 ;; + echo "$timestamp" ; exit ;; --version | -v ) - echo "$version" ; exit 0 ;; + echo "$version" ; exit ;; --help | --h* | -h ) - echo "$usage"; exit 0 ;; + echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -104,7 +107,7 @@ set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; @@ -123,7 +126,7 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ;' +esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) @@ -158,6 +161,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched @@ -196,50 +200,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" - exit 0 ;; - amiga:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - arc:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - hp300:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mac68k:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - macppc:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvme68k:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvme88k:OpenBSD:*:*) - echo m88k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvmeppc:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - pmax:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - sgi:OpenBSD:*:*) - echo mipseb-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - sun3:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - wgrisc:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; + exit ;; *:OpenBSD:*:*) - echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; alpha:OSF1:*:*) - if test $UNAME_RELEASE = "V4.0"; then + case $UNAME_RELEASE in + *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - fi + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU @@ -277,42 +263,49 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac + # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit 0 ;; - Alpha*:OpenVMS:*:*) - echo alpha-hp-vms - exit 0 ;; + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix - exit 0 ;; + exit ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 - exit 0 ;; + exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 - exit 0;; + exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos - exit 0 ;; + exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos - exit 0 ;; + exit ;; *:OS/390:*:*) echo i370-ibm-openedition - exit 0 ;; + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} - exit 0;; + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp - exit 0;; + exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then @@ -320,32 +313,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in else echo pyramid-pyramid-bsd fi - exit 0 ;; + exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 - exit 0 ;; + exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 - exit 0 ;; - DRS?6000:UNIX_SV:4.2*:7*) + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7 && exit 0 ;; + sparc) echo sparc-icl-nx7; exit ;; esac ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - i86pc:SunOS:5.*:*) + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) @@ -354,10 +347,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit 0 ;; + exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} - exit 0 ;; + exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 @@ -369,10 +362,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo sparc-sun-sunos${UNAME_RELEASE} ;; esac - exit 0 ;; + exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} - exit 0 ;; + exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor @@ -383,37 +376,40 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} - exit 0 ;; + exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 - exit 0 ;; + exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} - exit 0 ;; + exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} - exit 0 ;; + exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} - exit 0 ;; + exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -437,32 +433,33 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit (-1); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c \ - && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ - && exit 0 + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos${UNAME_RELEASE} - exit 0 ;; + exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax - exit 0 ;; + exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax - exit 0 ;; + exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax - exit 0 ;; + exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix - exit 0 ;; + exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 - exit 0 ;; + exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 - exit 0 ;; + exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 - exit 0 ;; + exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` @@ -478,29 +475,29 @@ EOF else echo i586-dg-dgux${UNAME_RELEASE} fi - exit 0 ;; + exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 - exit 0 ;; + exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 - exit 0 ;; + exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 - exit 0 ;; + exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd - exit 0 ;; + exit ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit 0 ;; + exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix - exit 0 ;; + exit ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` @@ -508,7 +505,7 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit 0 ;; + exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build @@ -523,14 +520,18 @@ EOF exit(0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 - echo rs6000-ibm-aix3.2.5 + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi - exit 0 ;; + exit ;; *:AIX:*:[45]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then @@ -544,28 +545,28 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit 0 ;; + exit ;; *:AIX:*:*) echo rs6000-ibm-aix - exit 0 ;; + exit ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 - exit 0 ;; + exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit 0 ;; # report: romp-ibm BSD 4.3 + exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx - exit 0 ;; + exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 - exit 0 ;; + exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd - exit 0 ;; + exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 - exit 0 ;; + exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in @@ -627,9 +628,19 @@ EOF esac if [ ${HP_ARCH} = "hppa2.0w" ] then - # avoid double evaluation of $set_cc_for_build - test -n "$CC_FOR_BUILD" || eval $set_cc_for_build - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null then HP_ARCH="hppa2.0w" else @@ -637,11 +648,11 @@ EOF fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit 0 ;; + exit ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} - exit 0 ;; + exit ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -669,87 +680,106 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 - exit 0 ;; + exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd - exit 0 ;; + exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd - exit 0 ;; + exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix - exit 0 ;; + exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf - exit 0 ;; + exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf - exit 0 ;; + exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi - exit 0 ;; + exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites - exit 0 ;; + exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd - exit 0 ;; + exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit 0 ;; + exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd - exit 0 ;; + exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd - exit 0 ;; + exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd - exit 0 ;; + exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; *:UNICOS/mp:*:*) - echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit 0 ;; + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit 0 ;; + exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} - exit 0 ;; + exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} +<<<<<<< .mine + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; +======= exit 0 ;; *:FreeBSD:*:*|*:GNU/FreeBSD:*:*) # Determine whether the default compiler uses glibc. @@ -768,54 +798,90 @@ EOF case ${LIBC} in gnu) kernel_only='k' ;; esac echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} exit 0 ;; +>>>>>>> .r627 i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin - exit 0 ;; - i*:MINGW*:*) + exit ;; + *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 - exit 0 ;; + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 - exit 0 ;; - x86:Interix*:[34]*) - echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' - exit 0 ;; + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks - exit 0 ;; + exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix - exit 0 ;; + exit ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin - exit 0 ;; + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin - exit 0 ;; + exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; *:GNU:*:*) + # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit 0 ;; + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix - exit 0 ;; + exit ;; arm*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; cris:Linux:*:*) echo cris-axis-linux-gnu - exit 0 ;; + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; ia64:Linux:*:*) +<<<<<<< .mine + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; +======= echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; mips:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -832,8 +898,12 @@ EOF #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; mips64:Linux:*:*) eval $set_cc_for_build @@ -851,15 +921,32 @@ EOF #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; ppc:Linux:*:*) +<<<<<<< .mine + echo powerpc-unknown-linux-gnu + exit ;; +======= echo powerpc-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 ppc64:Linux:*:*) +<<<<<<< .mine + echo powerpc64-unknown-linux-gnu + exit ;; +======= echo powerpc64-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -873,7 +960,7 @@ EOF objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit 0 ;; + exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in @@ -881,25 +968,41 @@ EOF PA8*) echo hppa2.0-unknown-linux-gnu ;; *) echo hppa-unknown-linux-gnu ;; esac - exit 0 ;; + exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-gnu - exit 0 ;; + exit ;; s390:Linux:*:* | s390x:Linux:*:*) +<<<<<<< .mine + echo ${UNAME_MACHINE}-ibm-linux + exit ;; +======= echo ${UNAME_MACHINE}-ibm-linux exit 0 ;; +>>>>>>> .r627 sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; x86_64:Linux:*:*) +<<<<<<< .mine + echo x86_64-unknown-linux-gnu + exit ;; + xtensa:Linux:*:*) + echo xtensa-unknown-linux-gnu + exit ;; +======= echo x86_64-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so # first see if it will tell us. cd to the root directory to prevent @@ -917,15 +1020,15 @@ EOF ;; a.out-i386-linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit 0 ;; + exit ;; coff-i386) echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit 0 ;; + exit ;; "") # Either a pre-BFD a.out linker (linux-gnuoldld) or # one that does not give us useful --help. echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit 0 ;; + exit ;; esac # Determine whether the default compiler is a.out or elf eval $set_cc_for_build @@ -942,23 +1045,39 @@ EOF LIBC=gnulibc1 # endif #else - #ifdef __INTEL_COMPILER + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) LIBC=gnu #else LIBC=gnuaout #endif #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif EOF +<<<<<<< .mine + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } +======= eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 +>>>>>>> .r627 ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 - exit 0 ;; + exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... @@ -966,24 +1085,27 @@ EOF # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit 0 ;; + exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx - exit 0 ;; + exit ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop - exit 0 ;; + exit ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos - exit 0 ;; + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) echo i386-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit 0 ;; + exit ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then @@ -991,15 +1113,16 @@ EOF else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi - exit 0 ;; - i*86:*:5:[78]*) + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit 0 ;; + exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi - exit 0 ;; + exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv - exit 0 ;; + exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv - exit 0 ;; + exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix - exit 0 ;; - M68*:*:R3V[567]*:*) - test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; - 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && echo i486-ncr-sysv4.3${OS_REL} && exit 0 + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && echo i486-ncr-sysv4 && exit 0 ;; + && { echo i486-ncr-sysv4; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 - exit 0 ;; + exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} - exit 0 ;; + exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 - exit 0 ;; + exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 - exit 0 ;; + exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` @@ -1091,68 +1214,81 @@ EOF else echo ns32k-sni-sysv fi - exit 0 ;; + exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 - exit 0 ;; + exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 - exit 0 ;; + exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 - exit 0 ;; + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos - exit 0 ;; + exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} - exit 0 ;; + exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 - exit 0 ;; + exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi - exit 0 ;; + exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos - exit 0 ;; + exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos - exit 0 ;; + exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos - exit 0 ;; + exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} - exit 0 ;; + exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} - exit 0 ;; + exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} - exit 0 ;; + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; + exit ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; + exit ;; *:Darwin:*:*) - case `uname -p` in - *86) UNAME_PROCESSOR=i686 ;; - powerpc) UNAME_PROCESSOR=powerpc ;; + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit 0 ;; + exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then @@ -1160,22 +1296,25 @@ EOF UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit 0 ;; + exit ;; *:QNX:*:4*) echo i386-pc-qnx - exit 0 ;; - NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} - exit 0 ;; + exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux - exit 0 ;; + exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv - exit 0 ;; + exit ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit 0 ;; + exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 @@ -1186,28 +1325,47 @@ EOF UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 - exit 0 ;; + exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 - exit 0 ;; + exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex - exit 0 ;; + exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 - exit 0 ;; + exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 - exit 0 ;; + exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 - exit 0 ;; + exit ;; *:ITS:*:*) echo pdp10-unknown-its - exit 0 ;; + exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} - exit 0 ;; + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 @@ -1239,7 +1397,7 @@ main () #endif #if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix"); exit (0); + printf ("arm-acorn-riscix\n"); exit (0); #endif #if defined (hp300) && !defined (hpux) @@ -1328,11 +1486,12 @@ main () } EOF -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0 +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } # Convex versions that predate uname can use getsysinfo(1) @@ -1341,22 +1500,22 @@ then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd - exit 0 ;; + exit ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit 0 ;; + exit ;; c34*) echo c34-convex-bsd - exit 0 ;; + exit ;; c38*) echo c38-convex-bsd - exit 0 ;; + exit ;; c4*) echo c4-convex-bsd - exit 0 ;; + exit ;; esac fi @@ -1367,7 +1526,9 @@ This script, last modified $timestamp, has failed to recognize the operating system you are using. It is advised that you download the most up to date version of the config scripts from - ftp://ftp.gnu.org/pub/gnu/config/ + http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess +and + http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub If the version you run ($0) is already up to date, please send the following data and any information you think might be diff --git a/libs/openzap/build/config.sub b/libs/openzap/build/config.sub index 9d7f733905..91ca9d054c 100755 --- a/libs/openzap/build/config.sub +++ b/libs/openzap/build/config.sub @@ -1,9 +1,10 @@ #! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. -timestamp='2003-07-04' +timestamp='2007-06-28' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -21,14 +22,15 @@ timestamp='2003-07-04' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. + # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. # @@ -70,7 +72,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -83,11 +85,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit 0 ;; + echo "$timestamp" ; exit ;; --version | -v ) - echo "$version" ; exit 0 ;; + echo "$version" ; exit ;; --help | --h* | -h ) - echo "$usage"; exit 0 ;; + echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -99,7 +101,7 @@ while test $# -gt 0 ; do *local*) # First pass through any local machine types. echo $1 - exit 0;; + exit ;; * ) break ;; @@ -144,7 +146,7 @@ case $os in -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis) + -apple | -axis | -knuth | -cray) os= basic_machine=$1 ;; @@ -169,6 +171,10 @@ case $os in -hiux*) os=-hiuxwe2 ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -185,6 +191,10 @@ case $os in # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -228,14 +238,17 @@ case $basic_machine in | a29k \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ - | fr30 | frv \ + | fido | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ - | ip2k \ - | m32r | m68000 | m68k | m88k | mcore \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -244,27 +257,42 @@ case $basic_machine in | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ + | mt \ | msp430 \ + | nios | nios2 \ | ns16k | ns32k \ - | openrisc | or32 \ + | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ +<<<<<<< .mine + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ +======= | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ +>>>>>>> .r627 | sh64 | sh64le \ +<<<<<<< .mine + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ +======= | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ | strongarm \ +>>>>>>> .r627 | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ | we32k \ - | x86 | xscale | xstormy16 | xtensa \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ | z8k) basic_machine=$basic_machine-unknown ;; @@ -275,6 +303,9 @@ case $basic_machine in ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; + ms1) + basic_machine=mt-unknown + ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and @@ -294,20 +325,20 @@ case $basic_machine in | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* \ - | bs2000-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | cydra-* \ + | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ - | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* \ - | m32r-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | mcore-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ @@ -316,30 +347,45 @@ case $basic_machine in | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ | msp430-* \ - | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ +<<<<<<< .mine + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ +======= | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ +>>>>>>> .r627 | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ +<<<<<<< .mine + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ +======= | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ +>>>>>>> .r627 | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ | v850-* | v850e-* | vax-* \ | we32k-* \ - | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ - | xtensa-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa-* \ | ymp-* \ | z8k-*) ;; @@ -359,6 +405,9 @@ case $basic_machine in basic_machine=a29k-amd os=-udi ;; + abacus) + basic_machine=abacus-unknown + ;; adobe68k) basic_machine=m68010-adobe os=-scout @@ -376,6 +425,9 @@ case $basic_machine in amd64) basic_machine=x86_64-pc ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; amdahl) basic_machine=580-amdahl os=-sysv @@ -435,12 +487,27 @@ case $basic_machine in basic_machine=j90-cray os=-unicos ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16) + basic_machine=cr16-unknown + os=-elf + ;; crds | unos) basic_machine=m68k-crds ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; da30 | da30-*) basic_machine=m68k-da30 ;; @@ -463,6 +530,10 @@ case $basic_machine in basic_machine=m88k-motorola os=-sysv3 ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx @@ -628,6 +699,10 @@ case $basic_machine in basic_machine=i386-pc os=-mingw32 ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; miniframe) basic_machine=m68000-convergent ;; @@ -641,10 +716,6 @@ case $basic_machine in mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; - mmix*) - basic_machine=mmix-knuth - os=-mmixware - ;; monitor) basic_machine=m68k-rom68k os=-coff @@ -657,6 +728,9 @@ case $basic_machine in basic_machine=i386-pc os=-msdos ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; mvs) basic_machine=i370-ibm os=-mvs @@ -725,10 +799,6 @@ case $basic_machine in np1) basic_machine=np1-gould ;; - nv1) - basic_machine=nv1-cray - os=-unicosmp - ;; nsr-tandem) basic_machine=nsr-tandem ;; @@ -736,9 +806,12 @@ case $basic_machine in basic_machine=hppa1.1-oki os=-proelf ;; - or32 | or32-*) + openrisc | openrisc-*) basic_machine=or32-unknown - os=-coff + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson @@ -765,6 +838,12 @@ case $basic_machine in pc532 | pc532-*) basic_machine=ns32k-pc532 ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; @@ -821,6 +900,10 @@ case $basic_machine in basic_machine=i586-unknown os=-pw32 ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; rom68k) basic_machine=m68k-rom68k os=-coff @@ -847,6 +930,10 @@ case $basic_machine in sb1el) basic_machine=mipsisa64sb1el-unknown ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; sei) basic_machine=mips-sei os=-seiux @@ -858,6 +945,9 @@ case $basic_machine in basic_machine=sh-hitachi os=-hms ;; + sh5el) + basic_machine=sh5le-unknown + ;; sh64) basic_machine=sh64-unknown ;; @@ -960,6 +1050,10 @@ case $basic_machine in tower | tower-32) basic_machine=m68k-ncr ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; udi29k) basic_machine=a29k-amd os=-udi @@ -1003,6 +1097,10 @@ case $basic_machine in basic_machine=hppa1.1-winbond os=-proelf ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; xps | xps100) basic_machine=xps100-honeywell ;; @@ -1033,6 +1131,9 @@ case $basic_machine in romp) basic_machine=romp-ibm ;; + mmix) + basic_machine=mmix-knuth + ;; rs6000) basic_machine=rs6000-ibm ;; @@ -1049,13 +1150,17 @@ case $basic_machine in we32k) basic_machine=we32k-att ;; - sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; +<<<<<<< .mine + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) +======= sh64) basic_machine=sh64-unknown ;; sparc | sparcv9 | sparcv9b) +>>>>>>> .r627 basic_machine=sparc-sun ;; cydra) @@ -1128,19 +1233,28 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ +<<<<<<< .mine + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ +======= | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ +>>>>>>> .r627 | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei*) + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1158,12 +1272,15 @@ case $os in os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; @@ -1176,6 +1293,9 @@ case $os in -opened*) os=-openedition ;; + -os400*) + os=-os400 + ;; -wince*) os=-wince ;; @@ -1197,6 +1317,9 @@ case $os in -atheos*) os=-atheos ;; + -syllable*) + os=-syllable + ;; -386bsd) os=-bsd ;; @@ -1219,6 +1342,9 @@ case $os in -sinix*) os=-sysv4 ;; + -tpf*) + os=-tpf + ;; -triton*) os=-sysv3 ;; @@ -1255,6 +1381,9 @@ case $os in -kaos*) os=-kaos ;; + -zvmoe) + os=-zvmoe + ;; -none) ;; *) @@ -1277,6 +1406,12 @@ else # system, and we'll never get to this point. case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; *-acorn) os=-riscix1.2 ;; @@ -1286,9 +1421,15 @@ case $basic_machine in arm*-semi) os=-aout ;; +<<<<<<< .mine + c4x-* | tic4x-*) + os=-coff + ;; +======= c4x-* | tic4x-*) os=-coff ;; +>>>>>>> .r627 # This must come before the *-dec entry. pdp10-*) os=-tops20 @@ -1314,6 +1455,9 @@ case $basic_machine in m68*-cisco) os=-aout ;; + mep-*) + os=-elf + ;; mips*-cisco) os=-elf ;; @@ -1332,9 +1476,15 @@ case $basic_machine in *-be) os=-beos ;; + *-haiku) + os=-haiku + ;; *-ibm) os=-aix ;; + *-knuth) + os=-mmixware + ;; *-wec) os=-proelf ;; @@ -1467,9 +1617,15 @@ case $basic_machine in -mvs* | -opened*) vendor=ibm ;; + -os400*) + vendor=ibm + ;; -ptx*) vendor=sequent ;; + -tpf*) + vendor=ibm + ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; @@ -1494,7 +1650,7 @@ case $basic_machine in esac echo $basic_machine$os -exit 0 +exit # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) diff --git a/libs/openzap/build/ltmain.sh b/libs/openzap/build/ltmain.sh index c9698e72c3..aa4e393407 100644 --- a/libs/openzap/build/ltmain.sh +++ b/libs/openzap/build/ltmain.sh @@ -113,7 +113,8 @@ esac # These must not be set unconditionally because not all systems understand # e.g. LANG=C (notably SCO). # We save the old values to restore during execute mode. -for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES +lt_env= +for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then save_$lt_var=\$$lt_var @@ -122,6 +123,10 @@ do fi" done +if test -n "$lt_env"; then + lt_env="env $lt_env" +fi + # Make sure IFS has a sensible default lt_nl=' ' @@ -817,6 +822,7 @@ if test -z "$show_help"; then *.for) xform=for ;; *.java) xform=java ;; *.obj) xform=obj ;; + *.sx) xform=sx ;; esac libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` @@ -985,7 +991,7 @@ EOF $run $rm "$lobj" "$output_obj" $show "$command" - if $run eval "$command"; then : + if $run eval $lt_env "$command"; then : else test -n "$output_obj" && $run $rm $removelist exit $EXIT_FAILURE @@ -1057,7 +1063,7 @@ EOF command="$command$suppress_output" $run $rm "$obj" "$output_obj" $show "$command" - if $run eval "$command"; then : + if $run eval $lt_env "$command"; then : else $run $rm $removelist exit $EXIT_FAILURE @@ -1190,6 +1196,7 @@ EOF thread_safe=no vinfo= vinfo_number=no + single_module="${wl}-single_module" func_infer_tag $base_compile @@ -1676,6 +1683,11 @@ EOF continue ;; + -multi_module) + single_module="${wl}-multi_module" + continue + ;; + -module) module=yes continue @@ -2152,7 +2164,10 @@ EOF case $pass in dlopen) libs="$dlfiles" ;; dlpreopen) libs="$dlprefiles" ;; - link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + link) + libs="$deplibs %DEPLIBS%" + test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" + ;; esac fi if test "$pass" = dlopen; then @@ -2202,7 +2217,12 @@ EOF continue fi name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` - for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do + if test "$linkmode" = lib; then + searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" + else + searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" + fi + for searchdir in $searchdirs; do for search_ext in .la $std_shrext .so .a; do # Search the libtool library lib="$searchdir/lib${name}${search_ext}" @@ -2998,12 +3018,18 @@ EOF # we do not want to link against static libs, # but need to link against shared eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + eval deplibdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` if test -n "$deplibrary_names" ; then for tmp in $deplibrary_names ; do depdepl=$tmp done - if test -f "$path/$depdepl" ; then + if test -f "$deplibdir/$depdepl" ; then + depdepl="$deplibdir/$depdepl" + elif test -f "$path/$depdepl" ; then depdepl="$path/$depdepl" + else + # Can't find it, oh well... + depdepl= fi # do not add paths which are already there case " $newlib_search_path " in @@ -3151,9 +3177,10 @@ EOF case $linkmode in oldlib) - if test -n "$deplibs"; then - $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 - fi + case " $deplibs" in + *\ -l* | *\ -L*) + $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 ;; + esac if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 @@ -3297,6 +3324,11 @@ EOF revision="$number_minor" lt_irix_increment=no ;; + *) + $echo "$modename: unknown library version type \`$version_type'" 1>&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE + ;; esac ;; no) @@ -4290,9 +4322,10 @@ EOF ;; obj) - if test -n "$deplibs"; then - $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 - fi + case " $deplibs" in + *\ -l* | *\ -L*) + $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 ;; + esac if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 @@ -6534,7 +6567,7 @@ relink_command=\"$relink_command\"" fi # Restore saved environment variables - for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${save_$lt_var+set}\" = set; then $lt_var=\$save_$lt_var; export $lt_var diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index de551ce1ec..d76beba46d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1682,6 +1682,7 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } + zap_log(ZAP_LOG_ERROR, "SPANID = %i\n", span->span_id); SPAN_CONFIG[span->span_id].span = span; switch_set_string(SPAN_CONFIG[span->span_id].context, context); @@ -1838,7 +1839,7 @@ static switch_status_t load_config(void) int q921loglevel = -1; int q931loglevel = -1; // quick debug - // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1895,11 +1896,11 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } - - if (!span_id) { - span_id = span->span_id; - } - + + if (!span_id) { + span_id = span->span_id; + } + if (!tonegroup) { tonegroup = "us"; } @@ -2055,7 +2056,7 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } -#define OZ_SYNTAX "list || dump []" +#define OZ_SYNTAX "list || dump [] || bounce [] || q931_pcap on|off [pcapfilename without suffix]" SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; @@ -2139,7 +2140,7 @@ SWITCH_STANDARD_API(oz_function) } else if (!strcasecmp(argv[0], "bounce")) { /* MSC testing "oz bounce" command */ if (argc < 2) { - stream->write_function(stream, "-ERR Usage: oz dump []\n"); + stream->write_function(stream, "-ERR Usage: oz bounce []\n"); goto end; } else { int32_t span_id, chan_id = 0; @@ -2169,9 +2170,59 @@ SWITCH_STANDARD_API(oz_function) } } } + /*Q931ToPcap enhancement*/ + } else if (!strcasecmp(argv[0], "q931_pcap")) { + int32_t span_id = 0; + zap_span_t *span; + char *pcapfn = NULL; + char *tmp_path = NULL; + + if (argc < 3) { + stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + goto end; + } + span_id = atoi(argv[1]); + if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + + /*Look for a given file name or use default file name*/ + if (argc > 3) { + if(argv[3]){ + pcapfn=argv[3]; + } + } + else { + pcapfn="q931"; + } + + /*Add log directory path to file name*/ + tmp_path=switch_mprintf("%s%s%s.pcap", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pcapfn); + + if(!strcasecmp(argv[2], "on")) { + if (zap_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 1, "pcapfilename", tmp_path, TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_WARNING, "Error couldn't (re-)enable Q931-To-Pcap!\n"); + goto end; + } else { + stream->write_function(stream, "+OK\n"); + } + } else if(!strcasecmp(argv[2], "off")) { + if (zap_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 0, TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error couldn't enable Q931-To-Pcap!\n"); + goto end; + } else { + stream->write_function(stream, "+OK\n"); + } + } else { + stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + goto end; + } + } else { - stream->write_function(stream, "-ERR Usage: oz list || dump []\n"); + stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); } + /*Q931ToPcap enhancement done*/ end: diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 096086d437..8586c9d81b 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -49,6 +49,207 @@ #define ZAP_SPAN_IS_NT(x) (((zap_isdn_data_t *)(x)->signal_data)->mode == Q921_NT) +/*-------------------------------------------------------------------------*/ +/*Q931ToPcap functions*/ +#include +#include +#include +#include +#include + +#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 + +/*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; + + + +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; +} + +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; +} + +static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) +{ + L3UCHAR *frame = NULL; + u_char spanid = (u_char)span_id; + unsigned long *tcp_next_seq_no = NULL; + + spanid=span_id; + + /*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 + }; + /*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)! Limitting it to %u! Q931 packet will be corrupt.\n", q931size, MAX_Q931_SIZE); + q931size=MAX_Q931_SIZE; + } + + /*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; + pcap_dump((u_char*)pcapfile, &pcaphdr, frame); + pcap_dump_flush(pcapfile); + + /*Increase microsecond timestamp by 1*/ + pcaphdr.ts.tv_usec++; + if(pcaphdr.ts.tv_usec==1000000) + { + pcaphdr.ts.tv_sec++; + pcaphdr.ts.tv_usec=0; + } + + /*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; +} + +static ZIO_IO_UNLOAD_FUNCTION(close_pcap) +{ + return closePcapFile(); +} + +/*Q931ToPcap functions DONE*/ +/*-------------------------------------------------------------------------*/ + + static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); @@ -769,12 +970,20 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg { int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; + zap_span_t *span = (zap_span_t *) pvt; /*To get access to spanid for Q931ToPcap*/ switch(ind) { case Q921_DL_DATA: case Q921_DL_UNIT_DATA: print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); + /*Q931ToPcap*/ + if(do_q931ToPcap==1){ + 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*/ + 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) @@ -1519,6 +1728,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I { int offset = 4; char bb[4096] = ""; + zap_span_t *span = (zap_span_t *) pvt; /*To get access to span_id for Q931ToPcap*/ switch(ind) { case Q921_DL_UNIT_DATA: @@ -1526,6 +1736,13 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I case Q921_DL_DATA: print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); + /*Q931ToPcap*/ + if(do_q931ToPcap==1){ + 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*/ zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); break; @@ -1696,8 +1913,38 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) int32_t digit_timeout = 0; int q921loglevel = -1; int q931loglevel = -1; + int q931topcap = -1; /*Q931ToPcap*/ + int openPcap = 0; /*Flag: open Pcap file please*/ if (span->signal_type) { + /*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*/ + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; } @@ -1863,17 +2110,17 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_SUCCESS; } - zap_module_t zap_module = { "isdn", NULL, - NULL, + close_pcap, zap_isdn_init, zap_isdn_configure_span, NULL }; + /* For Emacs: * Local Variables: * mode:c From eb24f46932e6952e26362351294fc747431e66cc Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Fri, 30 Jan 2009 11:37:11 +0000 Subject: [PATCH 1214/1766] Q931ToPcap patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@628 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 7 + libs/freetdm/build/config.guess | 671 +++++++++++------- libs/freetdm/build/config.sub | 240 +++++-- libs/freetdm/build/ltmain.sh | 59 +- libs/freetdm/mod_openzap/mod_openzap.c | 69 +- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 253 ++++++- 6 files changed, 977 insertions(+), 322 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 8c69bafe12..9094c1b8ce 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -34,6 +34,11 @@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ + +###For libpcap +CFLAGS+=-D_GNU_SOURCE +#### + LIBS = @LIBS@ DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ SOLINK = @SOLINK@ @@ -270,6 +275,8 @@ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $ $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) +$(ISDN_OBJS2): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c + $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) diff --git a/libs/freetdm/build/config.guess b/libs/freetdm/build/config.guess index 0e30d56e94..2b73846398 100755 --- a/libs/freetdm/build/config.guess +++ b/libs/freetdm/build/config.guess @@ -1,7 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. timestamp='2003-07-02' @@ -17,13 +18,15 @@ timestamp='2003-07-02' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. + # Originally written by Per Bothner . # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. @@ -53,7 +56,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -66,11 +69,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit 0 ;; + echo "$timestamp" ; exit ;; --version | -v ) - echo "$version" ; exit 0 ;; + echo "$version" ; exit ;; --help | --h* | -h ) - echo "$usage"; exit 0 ;; + echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -104,7 +107,7 @@ set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; @@ -123,7 +126,7 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ;' +esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) @@ -158,6 +161,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched @@ -196,50 +200,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" - exit 0 ;; - amiga:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - arc:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - hp300:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mac68k:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - macppc:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvme68k:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvme88k:OpenBSD:*:*) - echo m88k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvmeppc:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - pmax:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - sgi:OpenBSD:*:*) - echo mipseb-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - sun3:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - wgrisc:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; + exit ;; *:OpenBSD:*:*) - echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; alpha:OSF1:*:*) - if test $UNAME_RELEASE = "V4.0"; then + case $UNAME_RELEASE in + *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - fi + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU @@ -277,42 +263,49 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac + # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit 0 ;; - Alpha*:OpenVMS:*:*) - echo alpha-hp-vms - exit 0 ;; + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix - exit 0 ;; + exit ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 - exit 0 ;; + exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 - exit 0;; + exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos - exit 0 ;; + exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos - exit 0 ;; + exit ;; *:OS/390:*:*) echo i370-ibm-openedition - exit 0 ;; + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} - exit 0;; + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp - exit 0;; + exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then @@ -320,32 +313,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in else echo pyramid-pyramid-bsd fi - exit 0 ;; + exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 - exit 0 ;; + exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 - exit 0 ;; - DRS?6000:UNIX_SV:4.2*:7*) + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7 && exit 0 ;; + sparc) echo sparc-icl-nx7; exit ;; esac ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - i86pc:SunOS:5.*:*) + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) @@ -354,10 +347,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit 0 ;; + exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} - exit 0 ;; + exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 @@ -369,10 +362,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo sparc-sun-sunos${UNAME_RELEASE} ;; esac - exit 0 ;; + exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} - exit 0 ;; + exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor @@ -383,37 +376,40 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} - exit 0 ;; + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} - exit 0 ;; + exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 - exit 0 ;; + exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} - exit 0 ;; + exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} - exit 0 ;; + exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} - exit 0 ;; + exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -437,32 +433,33 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit (-1); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c \ - && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ - && exit 0 + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos${UNAME_RELEASE} - exit 0 ;; + exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax - exit 0 ;; + exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax - exit 0 ;; + exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax - exit 0 ;; + exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix - exit 0 ;; + exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 - exit 0 ;; + exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 - exit 0 ;; + exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 - exit 0 ;; + exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` @@ -478,29 +475,29 @@ EOF else echo i586-dg-dgux${UNAME_RELEASE} fi - exit 0 ;; + exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 - exit 0 ;; + exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 - exit 0 ;; + exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 - exit 0 ;; + exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd - exit 0 ;; + exit ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit 0 ;; + exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix - exit 0 ;; + exit ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` @@ -508,7 +505,7 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit 0 ;; + exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build @@ -523,14 +520,18 @@ EOF exit(0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 - echo rs6000-ibm-aix3.2.5 + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi - exit 0 ;; + exit ;; *:AIX:*:[45]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then @@ -544,28 +545,28 @@ EOF IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit 0 ;; + exit ;; *:AIX:*:*) echo rs6000-ibm-aix - exit 0 ;; + exit ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 - exit 0 ;; + exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit 0 ;; # report: romp-ibm BSD 4.3 + exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx - exit 0 ;; + exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 - exit 0 ;; + exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd - exit 0 ;; + exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 - exit 0 ;; + exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in @@ -627,9 +628,19 @@ EOF esac if [ ${HP_ARCH} = "hppa2.0w" ] then - # avoid double evaluation of $set_cc_for_build - test -n "$CC_FOR_BUILD" || eval $set_cc_for_build - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null then HP_ARCH="hppa2.0w" else @@ -637,11 +648,11 @@ EOF fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit 0 ;; + exit ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} - exit 0 ;; + exit ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -669,87 +680,106 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 - exit 0 ;; + exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd - exit 0 ;; + exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd - exit 0 ;; + exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix - exit 0 ;; + exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf - exit 0 ;; + exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf - exit 0 ;; + exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi - exit 0 ;; + exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites - exit 0 ;; + exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd - exit 0 ;; + exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit 0 ;; + exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd - exit 0 ;; + exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd - exit 0 ;; + exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd - exit 0 ;; + exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + exit ;; *:UNICOS/mp:*:*) - echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit 0 ;; + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit 0 ;; + exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} - exit 0 ;; + exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} +<<<<<<< .mine + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; +======= exit 0 ;; *:FreeBSD:*:*|*:GNU/FreeBSD:*:*) # Determine whether the default compiler uses glibc. @@ -768,54 +798,90 @@ EOF case ${LIBC} in gnu) kernel_only='k' ;; esac echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} exit 0 ;; +>>>>>>> .r627 i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin - exit 0 ;; - i*:MINGW*:*) + exit ;; + *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 - exit 0 ;; + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 - exit 0 ;; - x86:Interix*:[34]*) - echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' - exit 0 ;; + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks - exit 0 ;; + exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix - exit 0 ;; + exit ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin - exit 0 ;; + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin - exit 0 ;; + exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; + exit ;; *:GNU:*:*) + # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit 0 ;; + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix - exit 0 ;; + exit ;; arm*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; cris:Linux:*:*) echo cris-axis-linux-gnu - exit 0 ;; + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; ia64:Linux:*:*) +<<<<<<< .mine + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; +======= echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; mips:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c @@ -832,8 +898,12 @@ EOF #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; mips64:Linux:*:*) eval $set_cc_for_build @@ -851,15 +921,32 @@ EOF #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; ppc:Linux:*:*) +<<<<<<< .mine + echo powerpc-unknown-linux-gnu + exit ;; +======= echo powerpc-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 ppc64:Linux:*:*) +<<<<<<< .mine + echo powerpc64-unknown-linux-gnu + exit ;; +======= echo powerpc64-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -873,7 +960,7 @@ EOF objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit 0 ;; + exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in @@ -881,25 +968,41 @@ EOF PA8*) echo hppa2.0-unknown-linux-gnu ;; *) echo hppa-unknown-linux-gnu ;; esac - exit 0 ;; + exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-gnu - exit 0 ;; + exit ;; s390:Linux:*:* | s390x:Linux:*:*) +<<<<<<< .mine + echo ${UNAME_MACHINE}-ibm-linux + exit ;; +======= echo ${UNAME_MACHINE}-ibm-linux exit 0 ;; +>>>>>>> .r627 sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; x86_64:Linux:*:*) +<<<<<<< .mine + echo x86_64-unknown-linux-gnu + exit ;; + xtensa:Linux:*:*) + echo xtensa-unknown-linux-gnu + exit ;; +======= echo x86_64-unknown-linux-gnu exit 0 ;; +>>>>>>> .r627 i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so # first see if it will tell us. cd to the root directory to prevent @@ -917,15 +1020,15 @@ EOF ;; a.out-i386-linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit 0 ;; + exit ;; coff-i386) echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit 0 ;; + exit ;; "") # Either a pre-BFD a.out linker (linux-gnuoldld) or # one that does not give us useful --help. echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit 0 ;; + exit ;; esac # Determine whether the default compiler is a.out or elf eval $set_cc_for_build @@ -942,23 +1045,39 @@ EOF LIBC=gnulibc1 # endif #else - #ifdef __INTEL_COMPILER + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) LIBC=gnu #else LIBC=gnuaout #endif #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif EOF +<<<<<<< .mine + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } +======= eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 +>>>>>>> .r627 ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 - exit 0 ;; + exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... @@ -966,24 +1085,27 @@ EOF # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit 0 ;; + exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx - exit 0 ;; + exit ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop - exit 0 ;; + exit ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos - exit 0 ;; + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) echo i386-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit 0 ;; + exit ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then @@ -991,15 +1113,16 @@ EOF else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi - exit 0 ;; - i*86:*:5:[78]*) + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit 0 ;; + exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi - exit 0 ;; + exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv - exit 0 ;; + exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv - exit 0 ;; + exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix - exit 0 ;; - M68*:*:R3V[567]*:*) - test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; - 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && echo i486-ncr-sysv4.3${OS_REL} && exit 0 + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && echo i486-ncr-sysv4 && exit 0 ;; + && { echo i486-ncr-sysv4; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 - exit 0 ;; + exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; + exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} - exit 0 ;; + exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 - exit 0 ;; + exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 - exit 0 ;; + exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` @@ -1091,68 +1214,81 @@ EOF else echo ns32k-sni-sysv fi - exit 0 ;; + exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 - exit 0 ;; + exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 - exit 0 ;; + exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 - exit 0 ;; + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos - exit 0 ;; + exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} - exit 0 ;; + exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 - exit 0 ;; + exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi - exit 0 ;; + exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos - exit 0 ;; + exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos - exit 0 ;; + exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos - exit 0 ;; + exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} - exit 0 ;; + exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} - exit 0 ;; + exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} - exit 0 ;; + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; + exit ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; + exit ;; *:Darwin:*:*) - case `uname -p` in - *86) UNAME_PROCESSOR=i686 ;; - powerpc) UNAME_PROCESSOR=powerpc ;; + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit 0 ;; + exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then @@ -1160,22 +1296,25 @@ EOF UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit 0 ;; + exit ;; *:QNX:*:4*) echo i386-pc-qnx - exit 0 ;; - NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} - exit 0 ;; + exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux - exit 0 ;; + exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv - exit 0 ;; + exit ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit 0 ;; + exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 @@ -1186,28 +1325,47 @@ EOF UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 - exit 0 ;; + exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 - exit 0 ;; + exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex - exit 0 ;; + exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 - exit 0 ;; + exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 - exit 0 ;; + exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 - exit 0 ;; + exit ;; *:ITS:*:*) echo pdp10-unknown-its - exit 0 ;; + exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} - exit 0 ;; + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 @@ -1239,7 +1397,7 @@ main () #endif #if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix"); exit (0); + printf ("arm-acorn-riscix\n"); exit (0); #endif #if defined (hp300) && !defined (hpux) @@ -1328,11 +1486,12 @@ main () } EOF -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0 +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } # Convex versions that predate uname can use getsysinfo(1) @@ -1341,22 +1500,22 @@ then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd - exit 0 ;; + exit ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit 0 ;; + exit ;; c34*) echo c34-convex-bsd - exit 0 ;; + exit ;; c38*) echo c38-convex-bsd - exit 0 ;; + exit ;; c4*) echo c4-convex-bsd - exit 0 ;; + exit ;; esac fi @@ -1367,7 +1526,9 @@ This script, last modified $timestamp, has failed to recognize the operating system you are using. It is advised that you download the most up to date version of the config scripts from - ftp://ftp.gnu.org/pub/gnu/config/ + http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess +and + http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub If the version you run ($0) is already up to date, please send the following data and any information you think might be diff --git a/libs/freetdm/build/config.sub b/libs/freetdm/build/config.sub index 9d7f733905..91ca9d054c 100755 --- a/libs/freetdm/build/config.sub +++ b/libs/freetdm/build/config.sub @@ -1,9 +1,10 @@ #! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, +# Inc. -timestamp='2003-07-04' +timestamp='2007-06-28' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -21,14 +22,15 @@ timestamp='2003-07-04' # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. + # Please send patches to . Submit a context # diff and a properly formatted ChangeLog entry. # @@ -70,7 +72,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -83,11 +85,11 @@ Try \`$me --help' for more information." while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) - echo "$timestamp" ; exit 0 ;; + echo "$timestamp" ; exit ;; --version | -v ) - echo "$version" ; exit 0 ;; + echo "$version" ; exit ;; --help | --h* | -h ) - echo "$usage"; exit 0 ;; + echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. @@ -99,7 +101,7 @@ while test $# -gt 0 ; do *local*) # First pass through any local machine types. echo $1 - exit 0;; + exit ;; * ) break ;; @@ -144,7 +146,7 @@ case $os in -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis) + -apple | -axis | -knuth | -cray) os= basic_machine=$1 ;; @@ -169,6 +171,10 @@ case $os in -hiux*) os=-hiuxwe2 ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -185,6 +191,10 @@ case $os in # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -228,14 +238,17 @@ case $basic_machine in | a29k \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ - | fr30 | frv \ + | fido | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ - | ip2k \ - | m32r | m68000 | m68k | m88k | mcore \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -244,27 +257,42 @@ case $basic_machine in | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ + | mt \ | msp430 \ + | nios | nios2 \ | ns16k | ns32k \ - | openrisc | or32 \ + | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ +<<<<<<< .mine + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ +======= | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ +>>>>>>> .r627 | sh64 | sh64le \ +<<<<<<< .mine + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ +======= | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ | strongarm \ +>>>>>>> .r627 | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ | we32k \ - | x86 | xscale | xstormy16 | xtensa \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ | z8k) basic_machine=$basic_machine-unknown ;; @@ -275,6 +303,9 @@ case $basic_machine in ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; + ms1) + basic_machine=mt-unknown + ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and @@ -294,20 +325,20 @@ case $basic_machine in | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* \ - | bs2000-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | cydra-* \ + | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ - | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* \ - | m32r-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | mcore-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ @@ -316,30 +347,45 @@ case $basic_machine in | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ | msp430-* \ - | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ +<<<<<<< .mine + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ +======= | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ +>>>>>>> .r627 | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ +<<<<<<< .mine + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ +======= | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ +>>>>>>> .r627 | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ | v850-* | v850e-* | vax-* \ | we32k-* \ - | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ - | xtensa-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa-* \ | ymp-* \ | z8k-*) ;; @@ -359,6 +405,9 @@ case $basic_machine in basic_machine=a29k-amd os=-udi ;; + abacus) + basic_machine=abacus-unknown + ;; adobe68k) basic_machine=m68010-adobe os=-scout @@ -376,6 +425,9 @@ case $basic_machine in amd64) basic_machine=x86_64-pc ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; amdahl) basic_machine=580-amdahl os=-sysv @@ -435,12 +487,27 @@ case $basic_machine in basic_machine=j90-cray os=-unicos ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16) + basic_machine=cr16-unknown + os=-elf + ;; crds | unos) basic_machine=m68k-crds ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; da30 | da30-*) basic_machine=m68k-da30 ;; @@ -463,6 +530,10 @@ case $basic_machine in basic_machine=m88k-motorola os=-sysv3 ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx @@ -628,6 +699,10 @@ case $basic_machine in basic_machine=i386-pc os=-mingw32 ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; miniframe) basic_machine=m68000-convergent ;; @@ -641,10 +716,6 @@ case $basic_machine in mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; - mmix*) - basic_machine=mmix-knuth - os=-mmixware - ;; monitor) basic_machine=m68k-rom68k os=-coff @@ -657,6 +728,9 @@ case $basic_machine in basic_machine=i386-pc os=-msdos ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; mvs) basic_machine=i370-ibm os=-mvs @@ -725,10 +799,6 @@ case $basic_machine in np1) basic_machine=np1-gould ;; - nv1) - basic_machine=nv1-cray - os=-unicosmp - ;; nsr-tandem) basic_machine=nsr-tandem ;; @@ -736,9 +806,12 @@ case $basic_machine in basic_machine=hppa1.1-oki os=-proelf ;; - or32 | or32-*) + openrisc | openrisc-*) basic_machine=or32-unknown - os=-coff + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson @@ -765,6 +838,12 @@ case $basic_machine in pc532 | pc532-*) basic_machine=ns32k-pc532 ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; @@ -821,6 +900,10 @@ case $basic_machine in basic_machine=i586-unknown os=-pw32 ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; rom68k) basic_machine=m68k-rom68k os=-coff @@ -847,6 +930,10 @@ case $basic_machine in sb1el) basic_machine=mipsisa64sb1el-unknown ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; sei) basic_machine=mips-sei os=-seiux @@ -858,6 +945,9 @@ case $basic_machine in basic_machine=sh-hitachi os=-hms ;; + sh5el) + basic_machine=sh5le-unknown + ;; sh64) basic_machine=sh64-unknown ;; @@ -960,6 +1050,10 @@ case $basic_machine in tower | tower-32) basic_machine=m68k-ncr ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; udi29k) basic_machine=a29k-amd os=-udi @@ -1003,6 +1097,10 @@ case $basic_machine in basic_machine=hppa1.1-winbond os=-proelf ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; xps | xps100) basic_machine=xps100-honeywell ;; @@ -1033,6 +1131,9 @@ case $basic_machine in romp) basic_machine=romp-ibm ;; + mmix) + basic_machine=mmix-knuth + ;; rs6000) basic_machine=rs6000-ibm ;; @@ -1049,13 +1150,17 @@ case $basic_machine in we32k) basic_machine=we32k-att ;; - sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; +<<<<<<< .mine + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) +======= sh64) basic_machine=sh64-unknown ;; sparc | sparcv9 | sparcv9b) +>>>>>>> .r627 basic_machine=sparc-sun ;; cydra) @@ -1128,19 +1233,28 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ +<<<<<<< .mine + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ +======= | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ +>>>>>>> .r627 | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei*) + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1158,12 +1272,15 @@ case $os in os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; @@ -1176,6 +1293,9 @@ case $os in -opened*) os=-openedition ;; + -os400*) + os=-os400 + ;; -wince*) os=-wince ;; @@ -1197,6 +1317,9 @@ case $os in -atheos*) os=-atheos ;; + -syllable*) + os=-syllable + ;; -386bsd) os=-bsd ;; @@ -1219,6 +1342,9 @@ case $os in -sinix*) os=-sysv4 ;; + -tpf*) + os=-tpf + ;; -triton*) os=-sysv3 ;; @@ -1255,6 +1381,9 @@ case $os in -kaos*) os=-kaos ;; + -zvmoe) + os=-zvmoe + ;; -none) ;; *) @@ -1277,6 +1406,12 @@ else # system, and we'll never get to this point. case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; *-acorn) os=-riscix1.2 ;; @@ -1286,9 +1421,15 @@ case $basic_machine in arm*-semi) os=-aout ;; +<<<<<<< .mine + c4x-* | tic4x-*) + os=-coff + ;; +======= c4x-* | tic4x-*) os=-coff ;; +>>>>>>> .r627 # This must come before the *-dec entry. pdp10-*) os=-tops20 @@ -1314,6 +1455,9 @@ case $basic_machine in m68*-cisco) os=-aout ;; + mep-*) + os=-elf + ;; mips*-cisco) os=-elf ;; @@ -1332,9 +1476,15 @@ case $basic_machine in *-be) os=-beos ;; + *-haiku) + os=-haiku + ;; *-ibm) os=-aix ;; + *-knuth) + os=-mmixware + ;; *-wec) os=-proelf ;; @@ -1467,9 +1617,15 @@ case $basic_machine in -mvs* | -opened*) vendor=ibm ;; + -os400*) + vendor=ibm + ;; -ptx*) vendor=sequent ;; + -tpf*) + vendor=ibm + ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; @@ -1494,7 +1650,7 @@ case $basic_machine in esac echo $basic_machine$os -exit 0 +exit # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) diff --git a/libs/freetdm/build/ltmain.sh b/libs/freetdm/build/ltmain.sh index c9698e72c3..aa4e393407 100644 --- a/libs/freetdm/build/ltmain.sh +++ b/libs/freetdm/build/ltmain.sh @@ -113,7 +113,8 @@ esac # These must not be set unconditionally because not all systems understand # e.g. LANG=C (notably SCO). # We save the old values to restore during execute mode. -for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES +lt_env= +for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then save_$lt_var=\$$lt_var @@ -122,6 +123,10 @@ do fi" done +if test -n "$lt_env"; then + lt_env="env $lt_env" +fi + # Make sure IFS has a sensible default lt_nl=' ' @@ -817,6 +822,7 @@ if test -z "$show_help"; then *.for) xform=for ;; *.java) xform=java ;; *.obj) xform=obj ;; + *.sx) xform=sx ;; esac libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` @@ -985,7 +991,7 @@ EOF $run $rm "$lobj" "$output_obj" $show "$command" - if $run eval "$command"; then : + if $run eval $lt_env "$command"; then : else test -n "$output_obj" && $run $rm $removelist exit $EXIT_FAILURE @@ -1057,7 +1063,7 @@ EOF command="$command$suppress_output" $run $rm "$obj" "$output_obj" $show "$command" - if $run eval "$command"; then : + if $run eval $lt_env "$command"; then : else $run $rm $removelist exit $EXIT_FAILURE @@ -1190,6 +1196,7 @@ EOF thread_safe=no vinfo= vinfo_number=no + single_module="${wl}-single_module" func_infer_tag $base_compile @@ -1676,6 +1683,11 @@ EOF continue ;; + -multi_module) + single_module="${wl}-multi_module" + continue + ;; + -module) module=yes continue @@ -2152,7 +2164,10 @@ EOF case $pass in dlopen) libs="$dlfiles" ;; dlpreopen) libs="$dlprefiles" ;; - link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + link) + libs="$deplibs %DEPLIBS%" + test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" + ;; esac fi if test "$pass" = dlopen; then @@ -2202,7 +2217,12 @@ EOF continue fi name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` - for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do + if test "$linkmode" = lib; then + searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" + else + searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" + fi + for searchdir in $searchdirs; do for search_ext in .la $std_shrext .so .a; do # Search the libtool library lib="$searchdir/lib${name}${search_ext}" @@ -2998,12 +3018,18 @@ EOF # we do not want to link against static libs, # but need to link against shared eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + eval deplibdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` if test -n "$deplibrary_names" ; then for tmp in $deplibrary_names ; do depdepl=$tmp done - if test -f "$path/$depdepl" ; then + if test -f "$deplibdir/$depdepl" ; then + depdepl="$deplibdir/$depdepl" + elif test -f "$path/$depdepl" ; then depdepl="$path/$depdepl" + else + # Can't find it, oh well... + depdepl= fi # do not add paths which are already there case " $newlib_search_path " in @@ -3151,9 +3177,10 @@ EOF case $linkmode in oldlib) - if test -n "$deplibs"; then - $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 - fi + case " $deplibs" in + *\ -l* | *\ -L*) + $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 ;; + esac if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 @@ -3297,6 +3324,11 @@ EOF revision="$number_minor" lt_irix_increment=no ;; + *) + $echo "$modename: unknown library version type \`$version_type'" 1>&2 + $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 + exit $EXIT_FAILURE + ;; esac ;; no) @@ -4290,9 +4322,10 @@ EOF ;; obj) - if test -n "$deplibs"; then - $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 - fi + case " $deplibs" in + *\ -l* | *\ -L*) + $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 ;; + esac if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 @@ -6534,7 +6567,7 @@ relink_command=\"$relink_command\"" fi # Restore saved environment variables - for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${save_$lt_var+set}\" = set; then $lt_var=\$save_$lt_var; export $lt_var diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index de551ce1ec..d76beba46d 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1682,6 +1682,7 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } + zap_log(ZAP_LOG_ERROR, "SPANID = %i\n", span->span_id); SPAN_CONFIG[span->span_id].span = span; switch_set_string(SPAN_CONFIG[span->span_id].context, context); @@ -1838,7 +1839,7 @@ static switch_status_t load_config(void) int q921loglevel = -1; int q931loglevel = -1; // quick debug - // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1895,11 +1896,11 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } - - if (!span_id) { - span_id = span->span_id; - } - + + if (!span_id) { + span_id = span->span_id; + } + if (!tonegroup) { tonegroup = "us"; } @@ -2055,7 +2056,7 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } -#define OZ_SYNTAX "list || dump []" +#define OZ_SYNTAX "list || dump [] || bounce [] || q931_pcap on|off [pcapfilename without suffix]" SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; @@ -2139,7 +2140,7 @@ SWITCH_STANDARD_API(oz_function) } else if (!strcasecmp(argv[0], "bounce")) { /* MSC testing "oz bounce" command */ if (argc < 2) { - stream->write_function(stream, "-ERR Usage: oz dump []\n"); + stream->write_function(stream, "-ERR Usage: oz bounce []\n"); goto end; } else { int32_t span_id, chan_id = 0; @@ -2169,9 +2170,59 @@ SWITCH_STANDARD_API(oz_function) } } } + /*Q931ToPcap enhancement*/ + } else if (!strcasecmp(argv[0], "q931_pcap")) { + int32_t span_id = 0; + zap_span_t *span; + char *pcapfn = NULL; + char *tmp_path = NULL; + + if (argc < 3) { + stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + goto end; + } + span_id = atoi(argv[1]); + if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + + /*Look for a given file name or use default file name*/ + if (argc > 3) { + if(argv[3]){ + pcapfn=argv[3]; + } + } + else { + pcapfn="q931"; + } + + /*Add log directory path to file name*/ + tmp_path=switch_mprintf("%s%s%s.pcap", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pcapfn); + + if(!strcasecmp(argv[2], "on")) { + if (zap_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 1, "pcapfilename", tmp_path, TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_WARNING, "Error couldn't (re-)enable Q931-To-Pcap!\n"); + goto end; + } else { + stream->write_function(stream, "+OK\n"); + } + } else if(!strcasecmp(argv[2], "off")) { + if (zap_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 0, TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error couldn't enable Q931-To-Pcap!\n"); + goto end; + } else { + stream->write_function(stream, "+OK\n"); + } + } else { + stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + goto end; + } + } else { - stream->write_function(stream, "-ERR Usage: oz list || dump []\n"); + stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); } + /*Q931ToPcap enhancement done*/ end: diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 096086d437..8586c9d81b 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -49,6 +49,207 @@ #define ZAP_SPAN_IS_NT(x) (((zap_isdn_data_t *)(x)->signal_data)->mode == Q921_NT) +/*-------------------------------------------------------------------------*/ +/*Q931ToPcap functions*/ +#include +#include +#include +#include +#include + +#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 + +/*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; + + + +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; +} + +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; +} + +static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) +{ + L3UCHAR *frame = NULL; + u_char spanid = (u_char)span_id; + unsigned long *tcp_next_seq_no = NULL; + + spanid=span_id; + + /*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 + }; + /*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)! Limitting it to %u! Q931 packet will be corrupt.\n", q931size, MAX_Q931_SIZE); + q931size=MAX_Q931_SIZE; + } + + /*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; + pcap_dump((u_char*)pcapfile, &pcaphdr, frame); + pcap_dump_flush(pcapfile); + + /*Increase microsecond timestamp by 1*/ + pcaphdr.ts.tv_usec++; + if(pcaphdr.ts.tv_usec==1000000) + { + pcaphdr.ts.tv_sec++; + pcaphdr.ts.tv_usec=0; + } + + /*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; +} + +static ZIO_IO_UNLOAD_FUNCTION(close_pcap) +{ + return closePcapFile(); +} + +/*Q931ToPcap functions DONE*/ +/*-------------------------------------------------------------------------*/ + + static L2ULONG zap_time_now(void) { return (L2ULONG)zap_current_time_in_ms(); @@ -769,12 +970,20 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg { int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; + zap_span_t *span = (zap_span_t *) pvt; /*To get access to spanid for Q931ToPcap*/ switch(ind) { case Q921_DL_DATA: case Q921_DL_UNIT_DATA: print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); + /*Q931ToPcap*/ + if(do_q931ToPcap==1){ + 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*/ + 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) @@ -1519,6 +1728,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I { int offset = 4; char bb[4096] = ""; + zap_span_t *span = (zap_span_t *) pvt; /*To get access to span_id for Q931ToPcap*/ switch(ind) { case Q921_DL_UNIT_DATA: @@ -1526,6 +1736,13 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I case Q921_DL_DATA: print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); + /*Q931ToPcap*/ + if(do_q931ToPcap==1){ + 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*/ zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); break; @@ -1696,8 +1913,38 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) int32_t digit_timeout = 0; int q921loglevel = -1; int q931loglevel = -1; + int q931topcap = -1; /*Q931ToPcap*/ + int openPcap = 0; /*Flag: open Pcap file please*/ if (span->signal_type) { + /*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*/ + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling [%d].", span->signal_type); return ZAP_FAIL; } @@ -1863,17 +2110,17 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_SUCCESS; } - zap_module_t zap_module = { "isdn", NULL, - NULL, + close_pcap, zap_isdn_init, zap_isdn_configure_span, NULL }; + /* For Emacs: * Local Variables: * mode:c From c4001047ef112a02b4576b4e16f4861068954638 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Fri, 30 Jan 2009 11:44:03 +0000 Subject: [PATCH 1215/1766] Deleted some unneeded includes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@629 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 8586c9d81b..8d512f5394 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -52,10 +52,6 @@ /*-------------------------------------------------------------------------*/ /*Q931ToPcap functions*/ #include -#include -#include -#include -#include #define SNAPLEN 1522 #define MAX_ETHER_PAYLOAD_SIZE 1500 From 25d82076eef1b92a32dbd5fe62d2e5ab468fac17 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Fri, 30 Jan 2009 11:44:03 +0000 Subject: [PATCH 1216/1766] Deleted some unneeded includes git-svn-id: http://svn.openzap.org/svn/openzap/trunk@629 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 8586c9d81b..8d512f5394 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -52,10 +52,6 @@ /*-------------------------------------------------------------------------*/ /*Q931ToPcap functions*/ #include -#include -#include -#include -#include #define SNAPLEN 1522 #define MAX_ETHER_PAYLOAD_SIZE 1500 From 241b9d8184dca9f095cb8718262ad7b9e0f1035b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 30 Jan 2009 22:27:23 +0000 Subject: [PATCH 1217/1766] build tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@630 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index d76beba46d..58bfedf047 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2174,7 +2174,7 @@ SWITCH_STANDARD_API(oz_function) } else if (!strcasecmp(argv[0], "q931_pcap")) { int32_t span_id = 0; zap_span_t *span; - char *pcapfn = NULL; + const char *pcapfn = NULL; char *tmp_path = NULL; if (argc < 3) { From e2658cb9d983743d8f617c2a88c8ac97393ab0cd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 30 Jan 2009 22:27:23 +0000 Subject: [PATCH 1218/1766] build tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@630 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d76beba46d..58bfedf047 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2174,7 +2174,7 @@ SWITCH_STANDARD_API(oz_function) } else if (!strcasecmp(argv[0], "q931_pcap")) { int32_t span_id = 0; zap_span_t *span; - char *pcapfn = NULL; + const char *pcapfn = NULL; char *tmp_path = NULL; if (argc < 3) { From 3f340f4335dd3e69ae9d82aa786fe9b8616e70dc Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Sat, 31 Jan 2009 10:23:23 +0000 Subject: [PATCH 1219/1766] Q931ToPcap: Changed predefined ethernet frames in writeQ931... function from local to global variables. This should speed things up a bit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@631 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 8d512f5394..be3d86313f 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -78,7 +78,29 @@ 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 + }; static zap_status_t openPcapFile(void) { @@ -144,29 +166,6 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L spanid=span_id; - /*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 - }; /*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 :)*/ From 5da3ac8de63e770b2594491b5f7475ff9bd0be70 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Sat, 31 Jan 2009 10:23:23 +0000 Subject: [PATCH 1220/1766] Q931ToPcap: Changed predefined ethernet frames in writeQ931... function from local to global variables. This should speed things up a bit. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@631 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 8d512f5394..be3d86313f 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -78,7 +78,29 @@ 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 + }; static zap_status_t openPcapFile(void) { @@ -144,29 +166,6 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L spanid=span_id; - /*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 - }; /*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 :)*/ From cb580b94368a7acdcb80d53175af44221591afb5 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Mon, 2 Feb 2009 16:47:44 +0000 Subject: [PATCH 1221/1766] Makefile.in: Added libpcap to LIBS git-svn-id: http://svn.openzap.org/svn/openzap/trunk@632 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.in | 7 +++- libs/openzap/build/config.guess | 54 +------------------------- libs/openzap/build/config.sub | 42 ++------------------- libs/openzap/build/ltmain.sh | 67 +++------------------------------ 4 files changed, 17 insertions(+), 153 deletions(-) diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.in index 9094c1b8ce..3055c23121 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.in @@ -36,10 +36,15 @@ DEFS = @DEFS@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ ###For libpcap -CFLAGS+=-D_GNU_SOURCE +CFLAGS+= -D_GNU_SOURCE #### LIBS = @LIBS@ + +###For libpcap +LIBS+= -lpcap +#### + DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ SOLINK = @SOLINK@ OZ_SRCDIR=@oz_srcdir@ diff --git a/libs/openzap/build/config.guess b/libs/openzap/build/config.guess index 2b73846398..278f9e9e07 100755 --- a/libs/openzap/build/config.guess +++ b/libs/openzap/build/config.guess @@ -4,7 +4,7 @@ # 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, # Inc. -timestamp='2003-07-02' +timestamp='2007-07-22' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -767,7 +767,6 @@ EOF exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} -<<<<<<< .mine exit ;; *:FreeBSD:*:*) case ${UNAME_MACHINE} in @@ -779,26 +778,6 @@ EOF echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; -======= - exit 0 ;; - *:FreeBSD:*:*|*:GNU/FreeBSD:*:*) - # Determine whether the default compiler uses glibc. - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #if __GLIBC__ >= 2 - LIBC=gnu - #else - LIBC= - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - # GNU/FreeBSD systems have a "k" prefix to indicate we are using - # FreeBSD's kernel, but not the complete OS. - case ${LIBC} in gnu) kernel_only='k' ;; esac - echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} - exit 0 ;; ->>>>>>> .r627 i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; @@ -869,16 +848,11 @@ EOF echo frv-unknown-linux-gnu exit ;; ia64:Linux:*:*) -<<<<<<< .mine echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; -======= - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; @@ -932,21 +906,11 @@ EOF echo or32-unknown-linux-gnu exit ;; ppc:Linux:*:*) -<<<<<<< .mine echo powerpc-unknown-linux-gnu exit ;; -======= - echo powerpc-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 ppc64:Linux:*:*) -<<<<<<< .mine echo powerpc64-unknown-linux-gnu exit ;; -======= - echo powerpc64-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -973,13 +937,8 @@ EOF echo hppa64-unknown-linux-gnu exit ;; s390:Linux:*:* | s390x:Linux:*:*) -<<<<<<< .mine echo ${UNAME_MACHINE}-ibm-linux exit ;; -======= - echo ${UNAME_MACHINE}-ibm-linux - exit 0 ;; ->>>>>>> .r627 sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; @@ -993,16 +952,11 @@ EOF echo ${UNAME_MACHINE}-dec-linux-gnu exit ;; x86_64:Linux:*:*) -<<<<<<< .mine echo x86_64-unknown-linux-gnu exit ;; xtensa:Linux:*:*) echo xtensa-unknown-linux-gnu exit ;; -======= - echo x86_64-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so # first see if it will tell us. cd to the root directory to prevent @@ -1055,7 +1009,6 @@ EOF LIBC=dietlibc #endif EOF -<<<<<<< .mine eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' /^LIBC/{ s: ::g @@ -1066,11 +1019,6 @@ EOF exit } test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } -======= - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 - test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ->>>>>>> .r627 ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. diff --git a/libs/openzap/build/config.sub b/libs/openzap/build/config.sub index 91ca9d054c..1761d8bdf6 100755 --- a/libs/openzap/build/config.sub +++ b/libs/openzap/build/config.sub @@ -120,7 +120,9 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -274,21 +276,12 @@ case $basic_machine in | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ -<<<<<<< .mine | score \ | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ -======= - | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ ->>>>>>> .r627 | sh64 | sh64le \ -<<<<<<< .mine | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | spu | strongarm \ -======= - | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ - | strongarm \ ->>>>>>> .r627 | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ | we32k \ @@ -323,7 +316,7 @@ case $basic_machine in | a29k-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | bfin-* | bs2000-* \ @@ -365,20 +358,11 @@ case $basic_machine in | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ -<<<<<<< .mine | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ -======= - | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ ->>>>>>> .r627 | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ -<<<<<<< .mine | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ -======= - | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ - | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ ->>>>>>> .r627 | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ @@ -1153,14 +1137,7 @@ case $basic_machine in sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; -<<<<<<< .mine sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) -======= - sh64) - basic_machine=sh64-unknown - ;; - sparc | sparcv9 | sparcv9b) ->>>>>>> .r627 basic_machine=sparc-sun ;; cydra) @@ -1233,15 +1210,10 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ -<<<<<<< .mine | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -openbsd* | -solidbsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ -======= - | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ - | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ ->>>>>>> .r627 | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ @@ -1421,15 +1393,9 @@ case $basic_machine in arm*-semi) os=-aout ;; -<<<<<<< .mine c4x-* | tic4x-*) os=-coff ;; -======= - c4x-* | tic4x-*) - os=-coff - ;; ->>>>>>> .r627 # This must come before the *-dec entry. pdp10-*) os=-tops20 diff --git a/libs/openzap/build/ltmain.sh b/libs/openzap/build/ltmain.sh index aa4e393407..e420facf55 100644 --- a/libs/openzap/build/ltmain.sh +++ b/libs/openzap/build/ltmain.sh @@ -2,7 +2,7 @@ # NOTE: Changing this file will not affect anything until you rerun configure. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007 Free Software Foundation, Inc. +# 2007, 2008 Free Software Foundation, Inc. # Originally by Gordon Matzigkeit , 1996 # # This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ EXIT_FAILURE=1 PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.5.24 -TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" +VERSION="1.5.26 Debian 1.5.26-1ubuntu1" +TIMESTAMP=" (1.1220.2.493 2008/02/01 16:58:18)" # Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -118,6 +118,7 @@ for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then save_$lt_var=\$$lt_var + lt_env=\"$lt_var=\$$lt_var \$lt_env\" $lt_var=C export $lt_var fi" @@ -249,20 +250,6 @@ func_win32_libid () # arg is usually of the form 'gcc ...' func_infer_tag () { - # FreeBSD-specific: where we install compilers with non-standard names - tag_compilers_CC="*cc cc* *gcc gcc*" - tag_compilers_CXX="*c++ c++* *g++ g++*" - base_compiler=`set -- "$@"; echo $1` - - # If $tagname isn't set, then try to infer if the default "CC" tag applies - if test -z "$tagname"; then - for zp in $tag_compilers_CC; do - case $base_compiler in - $zp) tagname="CC"; break;; - esac - done - fi - if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do @@ -303,22 +290,7 @@ func_infer_tag () break ;; esac - - # FreeBSD-specific: try compilers based on inferred tag - if test -z "$tagname"; then - eval "tag_compilers=\$tag_compilers_${z}" - if test -n "$tag_compilers"; then - for zp in $tag_compilers; do - case $base_compiler in - $zp) tagname=$z; break;; - esac - done - if test -n "$tagname"; then - break - fi - fi - fi - fi + fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command @@ -519,7 +491,7 @@ do echo "\ $PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP -Copyright (C) 2007 Free Software Foundation, Inc. +Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." exit $? @@ -1679,7 +1651,6 @@ EOF compiler_flags="$compiler_flags $arg" compile_command="$compile_command $arg" finalize_command="$finalize_command $arg" - deplibs="$deplibs $arg" continue ;; @@ -2186,29 +2157,6 @@ EOF else compiler_flags="$compiler_flags $deplib" fi - - case $linkmode in - lib) - deplibs="$deplib $deplibs" - test "$pass" = conv && continue - newdependency_libs="$deplib $newdependency_libs" - ;; - prog) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - if test "$pass" = scan; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - ;; - *) - ;; - esac # linkmode - continue ;; -l*) @@ -4840,9 +4788,6 @@ static const void *lt_preloaded_setup() { ;; esac ;; - *-*-freebsd*) - # FreeBSD doesn't need this... - ;; *) $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 exit $EXIT_FAILURE From 2ac127566cf38dd5666b9ed92bec163b3171af37 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Mon, 2 Feb 2009 16:47:44 +0000 Subject: [PATCH 1222/1766] Makefile.in: Added libpcap to LIBS git-svn-id: http://svn.openzap.org/svn/openzap/trunk@632 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.in | 7 +++- libs/freetdm/build/config.guess | 54 +------------------------- libs/freetdm/build/config.sub | 42 ++------------------- libs/freetdm/build/ltmain.sh | 67 +++------------------------------ 4 files changed, 17 insertions(+), 153 deletions(-) diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.in index 9094c1b8ce..3055c23121 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.in @@ -36,10 +36,15 @@ DEFS = @DEFS@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ ###For libpcap -CFLAGS+=-D_GNU_SOURCE +CFLAGS+= -D_GNU_SOURCE #### LIBS = @LIBS@ + +###For libpcap +LIBS+= -lpcap +#### + DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ SOLINK = @SOLINK@ OZ_SRCDIR=@oz_srcdir@ diff --git a/libs/freetdm/build/config.guess b/libs/freetdm/build/config.guess index 2b73846398..278f9e9e07 100755 --- a/libs/freetdm/build/config.guess +++ b/libs/freetdm/build/config.guess @@ -4,7 +4,7 @@ # 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, # Inc. -timestamp='2003-07-02' +timestamp='2007-07-22' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -767,7 +767,6 @@ EOF exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} -<<<<<<< .mine exit ;; *:FreeBSD:*:*) case ${UNAME_MACHINE} in @@ -779,26 +778,6 @@ EOF echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; -======= - exit 0 ;; - *:FreeBSD:*:*|*:GNU/FreeBSD:*:*) - # Determine whether the default compiler uses glibc. - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #if __GLIBC__ >= 2 - LIBC=gnu - #else - LIBC= - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - # GNU/FreeBSD systems have a "k" prefix to indicate we are using - # FreeBSD's kernel, but not the complete OS. - case ${LIBC} in gnu) kernel_only='k' ;; esac - echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} - exit 0 ;; ->>>>>>> .r627 i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; @@ -869,16 +848,11 @@ EOF echo frv-unknown-linux-gnu exit ;; ia64:Linux:*:*) -<<<<<<< .mine echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; -======= - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; @@ -932,21 +906,11 @@ EOF echo or32-unknown-linux-gnu exit ;; ppc:Linux:*:*) -<<<<<<< .mine echo powerpc-unknown-linux-gnu exit ;; -======= - echo powerpc-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 ppc64:Linux:*:*) -<<<<<<< .mine echo powerpc64-unknown-linux-gnu exit ;; -======= - echo powerpc64-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; @@ -973,13 +937,8 @@ EOF echo hppa64-unknown-linux-gnu exit ;; s390:Linux:*:* | s390x:Linux:*:*) -<<<<<<< .mine echo ${UNAME_MACHINE}-ibm-linux exit ;; -======= - echo ${UNAME_MACHINE}-ibm-linux - exit 0 ;; ->>>>>>> .r627 sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; @@ -993,16 +952,11 @@ EOF echo ${UNAME_MACHINE}-dec-linux-gnu exit ;; x86_64:Linux:*:*) -<<<<<<< .mine echo x86_64-unknown-linux-gnu exit ;; xtensa:Linux:*:*) echo xtensa-unknown-linux-gnu exit ;; -======= - echo x86_64-unknown-linux-gnu - exit 0 ;; ->>>>>>> .r627 i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so # first see if it will tell us. cd to the root directory to prevent @@ -1055,7 +1009,6 @@ EOF LIBC=dietlibc #endif EOF -<<<<<<< .mine eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' /^LIBC/{ s: ::g @@ -1066,11 +1019,6 @@ EOF exit } test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } -======= - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 - test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ->>>>>>> .r627 ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. diff --git a/libs/freetdm/build/config.sub b/libs/freetdm/build/config.sub index 91ca9d054c..1761d8bdf6 100755 --- a/libs/freetdm/build/config.sub +++ b/libs/freetdm/build/config.sub @@ -120,7 +120,9 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -274,21 +276,12 @@ case $basic_machine in | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ -<<<<<<< .mine | score \ | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ -======= - | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ ->>>>>>> .r627 | sh64 | sh64le \ -<<<<<<< .mine | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | spu | strongarm \ -======= - | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ - | strongarm \ ->>>>>>> .r627 | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ | we32k \ @@ -323,7 +316,7 @@ case $basic_machine in | a29k-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | bfin-* | bs2000-* \ @@ -365,20 +358,11 @@ case $basic_machine in | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* \ -<<<<<<< .mine | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ -======= - | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ ->>>>>>> .r627 | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ -<<<<<<< .mine | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ -======= - | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ - | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ ->>>>>>> .r627 | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ @@ -1153,14 +1137,7 @@ case $basic_machine in sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; -<<<<<<< .mine sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) -======= - sh64) - basic_machine=sh64-unknown - ;; - sparc | sparcv9 | sparcv9b) ->>>>>>> .r627 basic_machine=sparc-sun ;; cydra) @@ -1233,15 +1210,10 @@ case $os in | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ -<<<<<<< .mine | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -openbsd* | -solidbsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ -======= - | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ - | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ ->>>>>>> .r627 | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ @@ -1421,15 +1393,9 @@ case $basic_machine in arm*-semi) os=-aout ;; -<<<<<<< .mine c4x-* | tic4x-*) os=-coff ;; -======= - c4x-* | tic4x-*) - os=-coff - ;; ->>>>>>> .r627 # This must come before the *-dec entry. pdp10-*) os=-tops20 diff --git a/libs/freetdm/build/ltmain.sh b/libs/freetdm/build/ltmain.sh index aa4e393407..e420facf55 100644 --- a/libs/freetdm/build/ltmain.sh +++ b/libs/freetdm/build/ltmain.sh @@ -2,7 +2,7 @@ # NOTE: Changing this file will not affect anything until you rerun configure. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007 Free Software Foundation, Inc. +# 2007, 2008 Free Software Foundation, Inc. # Originally by Gordon Matzigkeit , 1996 # # This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ EXIT_FAILURE=1 PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.5.24 -TIMESTAMP=" (1.1220.2.455 2007/06/24 02:13:29)" +VERSION="1.5.26 Debian 1.5.26-1ubuntu1" +TIMESTAMP=" (1.1220.2.493 2008/02/01 16:58:18)" # Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then @@ -118,6 +118,7 @@ for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then save_$lt_var=\$$lt_var + lt_env=\"$lt_var=\$$lt_var \$lt_env\" $lt_var=C export $lt_var fi" @@ -249,20 +250,6 @@ func_win32_libid () # arg is usually of the form 'gcc ...' func_infer_tag () { - # FreeBSD-specific: where we install compilers with non-standard names - tag_compilers_CC="*cc cc* *gcc gcc*" - tag_compilers_CXX="*c++ c++* *g++ g++*" - base_compiler=`set -- "$@"; echo $1` - - # If $tagname isn't set, then try to infer if the default "CC" tag applies - if test -z "$tagname"; then - for zp in $tag_compilers_CC; do - case $base_compiler in - $zp) tagname="CC"; break;; - esac - done - fi - if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do @@ -303,22 +290,7 @@ func_infer_tag () break ;; esac - - # FreeBSD-specific: try compilers based on inferred tag - if test -z "$tagname"; then - eval "tag_compilers=\$tag_compilers_${z}" - if test -n "$tag_compilers"; then - for zp in $tag_compilers; do - case $base_compiler in - $zp) tagname=$z; break;; - esac - done - if test -n "$tagname"; then - break - fi - fi - fi - fi + fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command @@ -519,7 +491,7 @@ do echo "\ $PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP -Copyright (C) 2007 Free Software Foundation, Inc. +Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." exit $? @@ -1679,7 +1651,6 @@ EOF compiler_flags="$compiler_flags $arg" compile_command="$compile_command $arg" finalize_command="$finalize_command $arg" - deplibs="$deplibs $arg" continue ;; @@ -2186,29 +2157,6 @@ EOF else compiler_flags="$compiler_flags $deplib" fi - - case $linkmode in - lib) - deplibs="$deplib $deplibs" - test "$pass" = conv && continue - newdependency_libs="$deplib $newdependency_libs" - ;; - prog) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - if test "$pass" = scan; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - ;; - *) - ;; - esac # linkmode - continue ;; -l*) @@ -4840,9 +4788,6 @@ static const void *lt_preloaded_setup() { ;; esac ;; - *-*-freebsd*) - # FreeBSD doesn't need this... - ;; *) $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 exit $EXIT_FAILURE From f76dbc8aa9fe8d9ab9cab17fe9bbb17097a9269f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 2 Feb 2009 22:31:03 +0000 Subject: [PATCH 1223/1766] initial bits of libpcap detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@633 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/build/libpcap.m4 | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 libs/openzap/build/libpcap.m4 diff --git a/libs/openzap/build/libpcap.m4 b/libs/openzap/build/libpcap.m4 new file mode 100644 index 0000000000..77fce6a2f0 --- /dev/null +++ b/libs/openzap/build/libpcap.m4 @@ -0,0 +1,109 @@ +dnl libpcap.m4--PCAP libraries and includes +dnl Derrick Brashear +dnl from KTH krb and Arla +dnl $Id: libpcap.m4,v 1.4 2006/01/20 20:21:09 snsimon Exp $ + +AC_DEFUN([PCAP_INC_WHERE1], [ +ac_cv_found_pcap_inc=no +if test -f "$1/pcap.h" ; then + ac_cv_found_pcap_inc=yes +fi +]) + +AC_DEFUN([PCAP_INC_WHERE], [ + for i in $1; do + AC_MSG_CHECKING(for pcap header in $i) + PCAP_INC_WHERE1($i) + if test "$ac_cv_found_pcap_inc" = "yes"; then + ac_cv_pcap_where_inc=$i + AC_MSG_RESULT(found) + break + else + AC_MSG_RESULT(no found) + fi + done +]) + +AC_DEFUN([PCAP_LIB_WHERE1], [ +saved_LIBS=$LIBS +LIBS="$saved_LIBS -L$1 -lpcap" +AC_TRY_LINK(, +[pcap_lookupdev("");], +[ac_cv_found_pcap_lib=yes], +ac_cv_found_pcap_lib=no) +LIBS=$saved_LIBS +]) + +AC_DEFUN([PCAP_LIB_WHERE], [ + for i in $1; do + AC_MSG_CHECKING(for pcap library in $i) + PCAP_LIB_WHERE1($i) + TEST_LIBPATH($i, pcap) + if test "$ac_cv_found_pcap_lib" = "yes" ; then + ac_cv_pcap_where_lib=$i + AC_MSG_RESULT(found) + break + else + AC_MSG_RESULT(no found) + fi + done +]) + +AC_DEFUN([PCAP], [ +AC_REQUIRE([FIND_LIB_SUBDIR]) +AC_ARG_WITH(pcap, + [ --with-pcap=PREFIX Compile with PCAP support], + [if test "X$with_pcap" = "X"; then + with_pcap=yes + fi]) +AC_ARG_WITH(pcap-lib, + [ --with-pcap-lib=dir use pcap libraries in dir], + [if test "$withval" = "yes" -o "$withval" = "no"; then + AC_MSG_ERROR([No argument for --with-pcap-lib]) + fi]) +AC_ARG_WITH(pcap-include, + [ --with-pcap-include=dir use pcap headers in dir], + [if test "$withval" = "yes" -o "$withval" = "no"; then + AC_MSG_ERROR([No argument for --with-pcap-include]) + fi]) + + if test "X$with_pcap" != "X"; then + if test "$with_pcap" != "yes"; then + ac_cv_pcap_where_lib=$with_pcap + ac_cv_pcap_where_inc=$with_pcap/include + fi + fi + + if test "X$with_pcap_lib" != "X"; then + ac_cv_pcap_where_lib=$with_pcap_lib + fi + if test "X$ac_cv_pcap_where_lib" = "X"; then + PCAP_LIB_WHERE(/usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) + fi + + if test "X$with_pcap_include" != "X"; then + ac_cv_pcap_where_inc=$with_pcap_include + fi + if test "X$ac_cv_pcap_where_inc" = "X"; then + PCAP_INC_WHERE(/usr/ng/include /usr/include /usr/local/include) + fi + + AC_MSG_CHECKING(whether to include pcap) + if test "X$ac_cv_pcap_where_lib" = "X" -a "X$ac_cv_pcap_where_inc" = "X"; then + ac_cv_found_pcap=no + AC_MSG_RESULT(no) + else + ac_cv_found_pcap=yes + AC_MSG_RESULT(yes) + PCAP_INC_DIR=$ac_cv_pcap_where_inc + PCAP_LIB_DIR=$ac_cv_pcap_where_lib + PCAP_INC_FLAGS="-I${PCAP_INC_DIR}" + PCAP_LIB_FLAGS="-L${PCAP_LIB_DIR} -lpcap" + AC_SUBST(PCAP_INC_DIR) + AC_SUBST(PCAP_LIB_DIR) + AC_SUBST(PCAP_INC_FLAGS) + AC_SUBST(PCAP_LIB_FLAGS) + AC_DEFINE([HAVE_LIBPCAP],[1],[libpcap]) + fi + ]) + From f618a792012768e7b648fdc45831cce7b8f37ba4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 2 Feb 2009 22:31:03 +0000 Subject: [PATCH 1224/1766] initial bits of libpcap detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@633 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/build/libpcap.m4 | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 libs/freetdm/build/libpcap.m4 diff --git a/libs/freetdm/build/libpcap.m4 b/libs/freetdm/build/libpcap.m4 new file mode 100644 index 0000000000..77fce6a2f0 --- /dev/null +++ b/libs/freetdm/build/libpcap.m4 @@ -0,0 +1,109 @@ +dnl libpcap.m4--PCAP libraries and includes +dnl Derrick Brashear +dnl from KTH krb and Arla +dnl $Id: libpcap.m4,v 1.4 2006/01/20 20:21:09 snsimon Exp $ + +AC_DEFUN([PCAP_INC_WHERE1], [ +ac_cv_found_pcap_inc=no +if test -f "$1/pcap.h" ; then + ac_cv_found_pcap_inc=yes +fi +]) + +AC_DEFUN([PCAP_INC_WHERE], [ + for i in $1; do + AC_MSG_CHECKING(for pcap header in $i) + PCAP_INC_WHERE1($i) + if test "$ac_cv_found_pcap_inc" = "yes"; then + ac_cv_pcap_where_inc=$i + AC_MSG_RESULT(found) + break + else + AC_MSG_RESULT(no found) + fi + done +]) + +AC_DEFUN([PCAP_LIB_WHERE1], [ +saved_LIBS=$LIBS +LIBS="$saved_LIBS -L$1 -lpcap" +AC_TRY_LINK(, +[pcap_lookupdev("");], +[ac_cv_found_pcap_lib=yes], +ac_cv_found_pcap_lib=no) +LIBS=$saved_LIBS +]) + +AC_DEFUN([PCAP_LIB_WHERE], [ + for i in $1; do + AC_MSG_CHECKING(for pcap library in $i) + PCAP_LIB_WHERE1($i) + TEST_LIBPATH($i, pcap) + if test "$ac_cv_found_pcap_lib" = "yes" ; then + ac_cv_pcap_where_lib=$i + AC_MSG_RESULT(found) + break + else + AC_MSG_RESULT(no found) + fi + done +]) + +AC_DEFUN([PCAP], [ +AC_REQUIRE([FIND_LIB_SUBDIR]) +AC_ARG_WITH(pcap, + [ --with-pcap=PREFIX Compile with PCAP support], + [if test "X$with_pcap" = "X"; then + with_pcap=yes + fi]) +AC_ARG_WITH(pcap-lib, + [ --with-pcap-lib=dir use pcap libraries in dir], + [if test "$withval" = "yes" -o "$withval" = "no"; then + AC_MSG_ERROR([No argument for --with-pcap-lib]) + fi]) +AC_ARG_WITH(pcap-include, + [ --with-pcap-include=dir use pcap headers in dir], + [if test "$withval" = "yes" -o "$withval" = "no"; then + AC_MSG_ERROR([No argument for --with-pcap-include]) + fi]) + + if test "X$with_pcap" != "X"; then + if test "$with_pcap" != "yes"; then + ac_cv_pcap_where_lib=$with_pcap + ac_cv_pcap_where_inc=$with_pcap/include + fi + fi + + if test "X$with_pcap_lib" != "X"; then + ac_cv_pcap_where_lib=$with_pcap_lib + fi + if test "X$ac_cv_pcap_where_lib" = "X"; then + PCAP_LIB_WHERE(/usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) + fi + + if test "X$with_pcap_include" != "X"; then + ac_cv_pcap_where_inc=$with_pcap_include + fi + if test "X$ac_cv_pcap_where_inc" = "X"; then + PCAP_INC_WHERE(/usr/ng/include /usr/include /usr/local/include) + fi + + AC_MSG_CHECKING(whether to include pcap) + if test "X$ac_cv_pcap_where_lib" = "X" -a "X$ac_cv_pcap_where_inc" = "X"; then + ac_cv_found_pcap=no + AC_MSG_RESULT(no) + else + ac_cv_found_pcap=yes + AC_MSG_RESULT(yes) + PCAP_INC_DIR=$ac_cv_pcap_where_inc + PCAP_LIB_DIR=$ac_cv_pcap_where_lib + PCAP_INC_FLAGS="-I${PCAP_INC_DIR}" + PCAP_LIB_FLAGS="-L${PCAP_LIB_DIR} -lpcap" + AC_SUBST(PCAP_INC_DIR) + AC_SUBST(PCAP_LIB_DIR) + AC_SUBST(PCAP_INC_FLAGS) + AC_SUBST(PCAP_LIB_FLAGS) + AC_DEFINE([HAVE_LIBPCAP],[1],[libpcap]) + fi + ]) + From fc7ed1c8c307f29b862e5f5b7faf6857ec6c1a54 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 04:51:53 +0000 Subject: [PATCH 1225/1766] convert to automake (still not really using automake in a useful way) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@634 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/AUTHORS | 0 libs/openzap/ChangeLog | 0 libs/openzap/{Makefile.in => Makefile.am} | 16 +- libs/openzap/NEWS | 0 libs/openzap/build/config.guess | 1516 ----- libs/openzap/build/config.sub | 1626 ----- libs/openzap/build/install-sh | 322 - libs/openzap/build/ltmain.sh | 6964 --------------------- libs/openzap/build/missing | 360 -- libs/openzap/configure.ac | 2 +- 10 files changed, 9 insertions(+), 10797 deletions(-) create mode 100644 libs/openzap/AUTHORS create mode 100644 libs/openzap/ChangeLog rename libs/openzap/{Makefile.in => Makefile.am} (96%) create mode 100644 libs/openzap/NEWS delete mode 100755 libs/openzap/build/config.guess delete mode 100755 libs/openzap/build/config.sub delete mode 100755 libs/openzap/build/install-sh delete mode 100644 libs/openzap/build/ltmain.sh delete mode 100755 libs/openzap/build/missing diff --git a/libs/openzap/AUTHORS b/libs/openzap/AUTHORS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/openzap/ChangeLog b/libs/openzap/ChangeLog new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/openzap/Makefile.in b/libs/openzap/Makefile.am similarity index 96% rename from libs/openzap/Makefile.in rename to libs/openzap/Makefile.am index 3055c23121..673f03936b 100644 --- a/libs/openzap/Makefile.in +++ b/libs/openzap/Makefile.am @@ -79,11 +79,11 @@ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ $(SRC)/zap_dso.c -BOOST_SOURCES=\ +BOOST_SOURCE=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -ISDN_SOURCES=\ +ISDN_SOURCE=\ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -148,7 +148,7 @@ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o -HEADERS= $(SRC)/include/fsk.h \ +HEADER= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ $(SRC)/include/hashtable.h \ $(SRC)/include/hashtable_itr.h \ @@ -166,7 +166,7 @@ $(SRC)/include/zap_dso.h \ $(SRC)/include/zap_types.h -ISDN_HEADERS=\ +ISDN_HEADER=\ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ $(SRC)/isdn/include/DMS.h \ @@ -193,7 +193,7 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod -$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) +$(MYLIB): $(OBJS) $(HEADER) $(SOURCES) $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) testapp: $(SRC)/testapp.o $(MYLIB) @@ -223,7 +223,7 @@ testanalog: $(SRC)/testanalog.o $(MYLIB) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(LTCOMPILE) $(MOD_CFLAGS) -c $< -o $@ -%.o: %.c $(HEADERS) +%.o: %.c $(HEADER) $(LTCOMPILE) -c $< -o $@ dox: @@ -274,13 +274,13 @@ $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -$(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +$(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -$(ISDN_OBJS2): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c +$(ISDN_OBJS2): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) diff --git a/libs/openzap/NEWS b/libs/openzap/NEWS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/openzap/build/config.guess b/libs/openzap/build/config.guess deleted file mode 100755 index 278f9e9e07..0000000000 --- a/libs/openzap/build/config.guess +++ /dev/null @@ -1,1516 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. - -timestamp='2007-07-22' - -# This file 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. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner . -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in - Debian*) - release='-gnu' - ;; - *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in - "EV4 (21064)") - UNAME_MACHINE="alpha" ;; - "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; - "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; - "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; - "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; - "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; - "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; - "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; - "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; - "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; - "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; - "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; - DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit ;; - *:AIX:*:[45]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if [ ${HP_ARCH} = "hppa2.0w" ] - then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null - then - HP_ARCH="hppa2.0w" - else - HP_ARCH="hppa64" - fi - fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - EM64T | authenticamd) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - *:GNU:*:*) - # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - arm*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - cris:Linux:*:*) - echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips64 - #undef mips64el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mips64el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips64 - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; - sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; - x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - xtensa:Linux:*:*) - echo xtensa-unknown-linux-gnu - exit ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; - coff-i386) - echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i386. - echo i386-pc-msdosdjgpp - exit ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; - M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; - esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit ;; - SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; -esac - -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 - -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - -cat >&2 < in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/libs/openzap/build/config.sub b/libs/openzap/build/config.sub deleted file mode 100755 index 1761d8bdf6..0000000000 --- a/libs/openzap/build/config.sub +++ /dev/null @@ -1,1626 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. - -timestamp='2007-06-28' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file 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. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit ;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ - uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) - os= - basic_machine=$1 - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | bfin \ - | c4x | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | fido | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64vr | mips64vrel \ - | mips64orion | mips64orionel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | mt \ - | msp430 \ - | nios | nios2 \ - | ns16k | ns32k \ - | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ - | pyramid \ - | score \ - | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu | strongarm \ - | tahoe | thumb | tic4x | tic80 | tron \ - | v850 | v850e \ - | we32k \ - | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ - | z8k) - basic_machine=$basic_machine-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12) - # Motorola 68HC11/12. - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - ms1) - basic_machine=mt-unknown - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | m32c-* | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ - | msp430-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ - | pyramid-* \ - | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ - | tahoe-* | thumb-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ - | tron-* \ - | v850-* | v850e-* | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa-* \ - | ymp-* \ - | z8k-*) - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16) - basic_machine=cr16-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; -# I'm not sure what "Sysv32" means. Should this be sysv3.2? - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc - ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc) basic_machine=powerpc-unknown - ;; - ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; - sei) - basic_machine=mips-sei - os=-seiux - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sh5el) - basic_machine=sh5le-unknown - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tic54x | c54x*) - basic_machine=tic54x-unknown - os=-coff - ;; - tic55x | c55x*) - basic_machine=tic55x-unknown - os=-coff - ;; - tic6x | c6x*) - basic_machine=tic6x-unknown - os=-coff - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - mmix) - basic_machine=mmix-knuth - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) - basic_machine=sh-unknown - ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto-qnx*) - ;; - -nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -os400*) - os=-os400 - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -syllable*) - os=-syllable - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -tpf*) - os=-tpf - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -aros*) - os=-aros - ;; - -kaos*) - os=-kaos - ;; - -zvmoe) - os=-zvmoe - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - c4x-* | tic4x-*) - os=-coff - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - # This also exists in the configure program, but was not the - # default. - # os=-sunos4 - ;; - m68*-cisco) - os=-aout - ;; - mep-*) - os=-elf - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-haiku) - os=-haiku - ;; - *-ibm) - os=-aix - ;; - *-knuth) - os=-mmixware - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -os400*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -tpf*) - vendor=ibm - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/libs/openzap/build/install-sh b/libs/openzap/build/install-sh deleted file mode 100755 index b777f1244c..0000000000 --- a/libs/openzap/build/install-sh +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh -# install - install a program, script, or datafile - -scriptversion=2004-07-05.00 - -# This originates from X11R5 (mit/util/scripts/install.sh), which was -# later released in X11R6 (xc/config/util/install.sh) with the -# following copyright and license. -# -# Copyright (C) 1994 X Consortium -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- -# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# Except as contained in this notice, the name of the X Consortium shall not -# be used in advertising or otherwise to promote the sale, use or other deal- -# ings in this Software without prior written authorization from the X Consor- -# tium. -# -# -# FSF changes to this file are in the public domain. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -chmodcmd="$chmodprog 0755" -chowncmd= -chgrpcmd= -stripcmd= -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src= -dst= -dir_arg= -dstarg= -no_target_directory= - -usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE - or: $0 [OPTION]... SRCFILES... DIRECTORY - or: $0 [OPTION]... -t DIRECTORY SRCFILES... - or: $0 [OPTION]... -d DIRECTORIES... - -In the 1st form, copy SRCFILE to DSTFILE. -In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. -In the 4th, create DIRECTORIES. - -Options: --c (ignored) --d create directories instead of installing files. --g GROUP $chgrpprog installed files to GROUP. --m MODE $chmodprog installed files to MODE. --o USER $chownprog installed files to USER. --s $stripprog installed files. --t DIRECTORY install into DIRECTORY. --T report an error if DSTFILE is a directory. ---help display this help and exit. ---version display version info and exit. - -Environment variables override the default commands: - CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG -" - -while test -n "$1"; do - case $1 in - -c) shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - --help) echo "$usage"; exit 0;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -s) stripcmd=$stripprog - shift - continue;; - - -t) dstarg=$2 - shift - shift - continue;; - - -T) no_target_directory=true - shift - continue;; - - --version) echo "$0 $scriptversion"; exit 0;; - - *) # When -d is used, all remaining arguments are directories to create. - # When -t is used, the destination is already specified. - test -n "$dir_arg$dstarg" && break - # Otherwise, the last argument is the destination. Remove it from $@. - for arg - do - if test -n "$dstarg"; then - # $@ is not empty: it contains at least $arg. - set fnord "$@" "$dstarg" - shift # fnord - fi - shift # arg - dstarg=$arg - done - break;; - esac -done - -if test -z "$1"; then - if test -z "$dir_arg"; then - echo "$0: no input file specified." >&2 - exit 1 - fi - # It's OK to call `install-sh -d' without argument. - # This can happen when creating conditional directories. - exit 0 -fi - -for src -do - # Protect names starting with `-'. - case $src in - -*) src=./$src ;; - esac - - if test -n "$dir_arg"; then - dst=$src - src= - - if test -d "$dst"; then - mkdircmd=: - chmodcmd= - else - mkdircmd=$mkdirprog - fi - else - # Waiting for this to be detected by the "$cpprog $src $dsttmp" command - # might cause directories to be created, which would be especially bad - # if $src (and thus $dsttmp) contains '*'. - if test ! -f "$src" && test ! -d "$src"; then - echo "$0: $src does not exist." >&2 - exit 1 - fi - - if test -z "$dstarg"; then - echo "$0: no destination specified." >&2 - exit 1 - fi - - dst=$dstarg - # Protect names starting with `-'. - case $dst in - -*) dst=./$dst ;; - esac - - # If destination is a directory, append the input filename; won't work - # if double slashes aren't ignored. - if test -d "$dst"; then - if test -n "$no_target_directory"; then - echo "$0: $dstarg: Is a directory" >&2 - exit 1 - fi - dst=$dst/`basename "$src"` - fi - fi - - # This sed command emulates the dirname command. - dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - - # Make sure that the destination directory exists. - - # Skip lots of stat calls in the usual case. - if test ! -d "$dstdir"; then - defaultIFS=' - ' - IFS="${IFS-$defaultIFS}" - - oIFS=$IFS - # Some sh's can't handle IFS=/ for some reason. - IFS='%' - set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` - IFS=$oIFS - - pathcomp= - - while test $# -ne 0 ; do - pathcomp=$pathcomp$1 - shift - if test ! -d "$pathcomp"; then - $mkdirprog "$pathcomp" - # mkdir can fail with a `File exist' error in case several - # install-sh are creating the directory concurrently. This - # is OK. - test -d "$pathcomp" || exit - fi - pathcomp=$pathcomp/ - done - fi - - if test -n "$dir_arg"; then - $doit $mkdircmd "$dst" \ - && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ - && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ - && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ - && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } - - else - dstfile=`basename "$dst"` - - # Make a couple of temp file names in the proper directory. - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ - - # Trap to clean up those temp files at exit. - trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 - trap '(exit $?); exit' 1 2 13 15 - - # Copy the file name to the temp name. - $doit $cpprog "$src" "$dsttmp" && - - # and set any options; do chmod last to preserve setuid bits. - # - # If any of these fail, we abort the whole thing. If we want to - # ignore errors from any of these, just make sure not to ignore - # errors from the above "$doit $cpprog $src $dsttmp" command. - # - { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ - && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ - && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ - && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && - - # Now rename the file to the real destination. - { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ - || { - # The rename failed, perhaps because mv can't rename something else - # to itself, or perhaps because mv is so ancient that it does not - # support -f. - - # Now remove or move aside any old file at destination location. - # We try this two ways since rm can't unlink itself on some - # systems and the destination file might be busy for other - # reasons. In this case, the final cleanup might fail but the new - # file should still install successfully. - { - if test -f "$dstdir/$dstfile"; then - $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ - || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ - || { - echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit - } - else - : - fi - } && - - # Now rename the file to the real destination. - $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" - } - } - fi || { (exit 1); exit; } -done - -# The final little trick to "correctly" pass the exit status to the exit trap. -{ - (exit 0); exit -} - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" -# End: diff --git a/libs/openzap/build/ltmain.sh b/libs/openzap/build/ltmain.sh deleted file mode 100644 index e420facf55..0000000000 --- a/libs/openzap/build/ltmain.sh +++ /dev/null @@ -1,6964 +0,0 @@ -# ltmain.sh - Provide generalized library-building support services. -# NOTE: Changing this file will not affect anything until you rerun configure. -# -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007, 2008 Free Software Foundation, Inc. -# Originally by Gordon Matzigkeit , 1996 -# -# 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. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -basename="s,^.*/,,g" - -# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh -# is ksh but when the shell is invoked as "sh" and the current value of -# the _XPG environment variable is not equal to 1 (one), the special -# positional parameter $0, within a function call, is the name of the -# function. -progpath="$0" - -# The name of this program: -progname=`echo "$progpath" | $SED $basename` -modename="$progname" - -# Global variables: -EXIT_SUCCESS=0 -EXIT_FAILURE=1 - -PROGRAM=ltmain.sh -PACKAGE=libtool -VERSION="1.5.26 Debian 1.5.26-1ubuntu1" -TIMESTAMP=" (1.1220.2.493 2008/02/01 16:58:18)" - -# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# Check that we have a working $echo. -if test "X$1" = X--no-reexec; then - # Discard the --no-reexec flag, and continue. - shift -elif test "X$1" = X--fallback-echo; then - # Avoid inline document here, it may be left over - : -elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then - # Yippee, $echo works! - : -else - # Restart under the correct shell, and then maybe $echo will work. - exec $SHELL "$progpath" --no-reexec ${1+"$@"} -fi - -if test "X$1" = X--fallback-echo; then - # used as fallback echo - shift - cat <&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit $EXIT_FAILURE -fi - -# Global variables. -mode=$default_mode -nonopt= -prev= -prevopt= -run= -show="$echo" -show_help= -execute_dlfiles= -duplicate_deps=no -preserve_args= -lo2o="s/\\.lo\$/.${objext}/" -o2lo="s/\\.${objext}\$/.lo/" -extracted_archives= -extracted_serial=0 - -##################################### -# Shell function definitions: -# This seems to be the best place for them - -# func_mktempdir [string] -# Make a temporary directory that won't clash with other running -# libtool processes, and avoids race conditions if possible. If -# given, STRING is the basename for that directory. -func_mktempdir () -{ - my_template="${TMPDIR-/tmp}/${1-$progname}" - - if test "$run" = ":"; then - # Return a directory name, but don't create it in dry-run mode - my_tmpdir="${my_template}-$$" - else - - # If mktemp works, use that first and foremost - my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` - - if test ! -d "$my_tmpdir"; then - # Failing that, at least try and use $RANDOM to avoid a race - my_tmpdir="${my_template}-${RANDOM-0}$$" - - save_mktempdir_umask=`umask` - umask 0077 - $mkdir "$my_tmpdir" - umask $save_mktempdir_umask - fi - - # If we're not in dry-run mode, bomb out on failure - test -d "$my_tmpdir" || { - $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2 - exit $EXIT_FAILURE - } - fi - - $echo "X$my_tmpdir" | $Xsed -} - - -# func_win32_libid arg -# return the library type of file 'arg' -# -# Need a lot of goo to handle *both* DLLs and import libs -# Has to be a shell function in order to 'eat' the argument -# that is supplied when $file_magic_command is called. -func_win32_libid () -{ - win32_libid_type="unknown" - win32_fileres=`file -L $1 2>/dev/null` - case $win32_fileres in - *ar\ archive\ import\ library*) # definitely import - win32_libid_type="x86 archive import" - ;; - *ar\ archive*) # could be an import, or static - if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ - $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then - win32_nmres=`eval $NM -f posix -A $1 | \ - $SED -n -e '1,100{ - / I /{ - s,.*,import, - p - q - } - }'` - case $win32_nmres in - import*) win32_libid_type="x86 archive import";; - *) win32_libid_type="x86 archive static";; - esac - fi - ;; - *DLL*) - win32_libid_type="x86 DLL" - ;; - *executable*) # but shell scripts are "executable" too... - case $win32_fileres in - *MS\ Windows\ PE\ Intel*) - win32_libid_type="x86 DLL" - ;; - esac - ;; - esac - $echo $win32_libid_type -} - - -# func_infer_tag arg -# Infer tagged configuration to use if any are available and -# if one wasn't chosen via the "--tag" command line option. -# Only attempt this if the compiler in the base compile -# command doesn't match the default compiler. -# arg is usually of the form 'gcc ...' -func_infer_tag () -{ - if test -n "$available_tags" && test -z "$tagname"; then - CC_quoted= - for arg in $CC; do - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - CC_quoted="$CC_quoted $arg" - done - case $@ in - # Blanks in the command may have been stripped by the calling shell, - # but not from the CC environment variable when configure was run. - " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;; - # Blanks at the start of $base_compile will cause this to fail - # if we don't check for them as well. - *) - for z in $available_tags; do - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" - CC_quoted= - for arg in $CC; do - # Double-quote args containing other shell metacharacters. - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - CC_quoted="$CC_quoted $arg" - done - case "$@ " in - " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) - # The compiler in the base compile command matches - # the one in the tagged configuration. - # Assume this is the tagged configuration we want. - tagname=$z - break - ;; - esac - fi - done - # If $tagname still isn't set, then no tagged configuration - # was found and let the user know that the "--tag" command - # line option must be used. - if test -z "$tagname"; then - $echo "$modename: unable to infer tagged configuration" - $echo "$modename: specify a tag with \`--tag'" 1>&2 - exit $EXIT_FAILURE -# else -# $echo "$modename: using $tagname tagged configuration" - fi - ;; - esac - fi -} - - -# func_extract_an_archive dir oldlib -func_extract_an_archive () -{ - f_ex_an_ar_dir="$1"; shift - f_ex_an_ar_oldlib="$1" - - $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)" - $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $? - if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2 - exit $EXIT_FAILURE - fi -} - -# func_extract_archives gentop oldlib ... -func_extract_archives () -{ - my_gentop="$1"; shift - my_oldlibs=${1+"$@"} - my_oldobjs="" - my_xlib="" - my_xabs="" - my_xdir="" - my_status="" - - $show "${rm}r $my_gentop" - $run ${rm}r "$my_gentop" - $show "$mkdir $my_gentop" - $run $mkdir "$my_gentop" - my_status=$? - if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then - exit $my_status - fi - - for my_xlib in $my_oldlibs; do - # Extract the objects. - case $my_xlib in - [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; - *) my_xabs=`pwd`"/$my_xlib" ;; - esac - my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'` - my_xlib_u=$my_xlib - while :; do - case " $extracted_archives " in - *" $my_xlib_u "*) - extracted_serial=`expr $extracted_serial + 1` - my_xlib_u=lt$extracted_serial-$my_xlib ;; - *) break ;; - esac - done - extracted_archives="$extracted_archives $my_xlib_u" - my_xdir="$my_gentop/$my_xlib_u" - - $show "${rm}r $my_xdir" - $run ${rm}r "$my_xdir" - $show "$mkdir $my_xdir" - $run $mkdir "$my_xdir" - exit_status=$? - if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then - exit $exit_status - fi - case $host in - *-darwin*) - $show "Extracting $my_xabs" - # Do not bother doing anything if just a dry run - if test -z "$run"; then - darwin_orig_dir=`pwd` - cd $my_xdir || exit $? - darwin_archive=$my_xabs - darwin_curdir=`pwd` - darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'` - darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null` - if test -n "$darwin_arches"; then - darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'` - darwin_arch= - $show "$darwin_base_archive has multiple architectures $darwin_arches" - for darwin_arch in $darwin_arches ; do - mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}" - lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" - cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" - func_extract_an_archive "`pwd`" "${darwin_base_archive}" - cd "$darwin_curdir" - $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" - done # $darwin_arches - ## Okay now we have a bunch of thin objects, gotta fatten them up :) - darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP` - darwin_file= - darwin_files= - for darwin_file in $darwin_filelist; do - darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` - lipo -create -output "$darwin_file" $darwin_files - done # $darwin_filelist - ${rm}r unfat-$$ - cd "$darwin_orig_dir" - else - cd "$darwin_orig_dir" - func_extract_an_archive "$my_xdir" "$my_xabs" - fi # $darwin_arches - fi # $run - ;; - *) - func_extract_an_archive "$my_xdir" "$my_xabs" - ;; - esac - my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` - done - func_extract_archives_result="$my_oldobjs" -} -# End of Shell function definitions -##################################### - -# Darwin sucks -eval std_shrext=\"$shrext_cmds\" - -disable_libs=no - -# Parse our command line options once, thoroughly. -while test "$#" -gt 0 -do - arg="$1" - shift - - case $arg in - -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;; - *) optarg= ;; - esac - - # If the previous option needs an argument, assign it. - if test -n "$prev"; then - case $prev in - execute_dlfiles) - execute_dlfiles="$execute_dlfiles $arg" - ;; - tag) - tagname="$arg" - preserve_args="${preserve_args}=$arg" - - # Check whether tagname contains only valid characters - case $tagname in - *[!-_A-Za-z0-9,/]*) - $echo "$progname: invalid tag name: $tagname" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - case $tagname in - CC) - # Don't test for the "default" C tag, as we know, it's there, but - # not specially marked. - ;; - *) - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then - taglist="$taglist $tagname" - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`" - else - $echo "$progname: ignoring unknown tag $tagname" 1>&2 - fi - ;; - esac - ;; - *) - eval "$prev=\$arg" - ;; - esac - - prev= - prevopt= - continue - fi - - # Have we seen a non-optional argument yet? - case $arg in - --help) - show_help=yes - ;; - - --version) - echo "\ -$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP - -Copyright (C) 2008 Free Software Foundation, Inc. -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - exit $? - ;; - - --config) - ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath - # Now print the configurations for the tags. - for tagname in $taglist; do - ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath" - done - exit $? - ;; - - --debug) - $echo "$progname: enabling shell trace mode" - set -x - preserve_args="$preserve_args $arg" - ;; - - --dry-run | -n) - run=: - ;; - - --features) - $echo "host: $host" - if test "$build_libtool_libs" = yes; then - $echo "enable shared libraries" - else - $echo "disable shared libraries" - fi - if test "$build_old_libs" = yes; then - $echo "enable static libraries" - else - $echo "disable static libraries" - fi - exit $? - ;; - - --finish) mode="finish" ;; - - --mode) prevopt="--mode" prev=mode ;; - --mode=*) mode="$optarg" ;; - - --preserve-dup-deps) duplicate_deps="yes" ;; - - --quiet | --silent) - show=: - preserve_args="$preserve_args $arg" - ;; - - --tag) - prevopt="--tag" - prev=tag - preserve_args="$preserve_args --tag" - ;; - --tag=*) - set tag "$optarg" ${1+"$@"} - shift - prev=tag - preserve_args="$preserve_args --tag" - ;; - - -dlopen) - prevopt="-dlopen" - prev=execute_dlfiles - ;; - - -*) - $echo "$modename: unrecognized option \`$arg'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - - *) - nonopt="$arg" - break - ;; - esac -done - -if test -n "$prevopt"; then - $echo "$modename: option \`$prevopt' requires an argument" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE -fi - -case $disable_libs in -no) - ;; -shared) - build_libtool_libs=no - build_old_libs=yes - ;; -static) - build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` - ;; -esac - -# If this variable is set in any of the actions, the command in it -# will be execed at the end. This prevents here-documents from being -# left over by shells. -exec_cmd= - -if test -z "$show_help"; then - - # Infer the operation mode. - if test -z "$mode"; then - $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2 - $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2 - case $nonopt in - *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*) - mode=link - for arg - do - case $arg in - -c) - mode=compile - break - ;; - esac - done - ;; - *db | *dbx | *strace | *truss) - mode=execute - ;; - *install*|cp|mv) - mode=install - ;; - *rm) - mode=uninstall - ;; - *) - # If we have no mode, but dlfiles were specified, then do execute mode. - test -n "$execute_dlfiles" && mode=execute - - # Just use the default operation mode. - if test -z "$mode"; then - if test -n "$nonopt"; then - $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2 - else - $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2 - fi - fi - ;; - esac - fi - - # Only execute mode is allowed to have -dlopen flags. - if test -n "$execute_dlfiles" && test "$mode" != execute; then - $echo "$modename: unrecognized option \`-dlopen'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Change the help message to a mode-specific one. - generic_help="$help" - help="Try \`$modename --help --mode=$mode' for more information." - - # These modes are in order of execution frequency so that they run quickly. - case $mode in - # libtool compile mode - compile) - modename="$modename: compile" - # Get the compilation command and the source file. - base_compile= - srcfile="$nonopt" # always keep a non-empty value in "srcfile" - suppress_opt=yes - suppress_output= - arg_mode=normal - libobj= - later= - - for arg - do - case $arg_mode in - arg ) - # do not "continue". Instead, add this to base_compile - lastarg="$arg" - arg_mode=normal - ;; - - target ) - libobj="$arg" - arg_mode=normal - continue - ;; - - normal ) - # Accept any command-line options. - case $arg in - -o) - if test -n "$libobj" ; then - $echo "$modename: you cannot specify \`-o' more than once" 1>&2 - exit $EXIT_FAILURE - fi - arg_mode=target - continue - ;; - - -static | -prefer-pic | -prefer-non-pic) - later="$later $arg" - continue - ;; - - -no-suppress) - suppress_opt=no - continue - ;; - - -Xcompiler) - arg_mode=arg # the next one goes into the "base_compile" arg list - continue # The current "srcfile" will either be retained or - ;; # replaced later. I would guess that would be a bug. - - -Wc,*) - args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"` - lastarg= - save_ifs="$IFS"; IFS=',' - for arg in $args; do - IFS="$save_ifs" - - # Double-quote args containing other shell metacharacters. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - lastarg="$lastarg $arg" - done - IFS="$save_ifs" - lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"` - - # Add the arguments to base_compile. - base_compile="$base_compile $lastarg" - continue - ;; - - * ) - # Accept the current argument as the source file. - # The previous "srcfile" becomes the current argument. - # - lastarg="$srcfile" - srcfile="$arg" - ;; - esac # case $arg - ;; - esac # case $arg_mode - - # Aesthetically quote the previous argument. - lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"` - - case $lastarg in - # Double-quote args containing other shell metacharacters. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, and some SunOS ksh mistreat backslash-escaping - # in scan sets (worked around with variable expansion), - # and furthermore cannot handle '|' '&' '(' ')' in scan sets - # at all, so we specify them separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - lastarg="\"$lastarg\"" - ;; - esac - - base_compile="$base_compile $lastarg" - done # for arg - - case $arg_mode in - arg) - $echo "$modename: you must specify an argument for -Xcompile" - exit $EXIT_FAILURE - ;; - target) - $echo "$modename: you must specify a target with \`-o'" 1>&2 - exit $EXIT_FAILURE - ;; - *) - # Get the name of the library object. - [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'` - ;; - esac - - # Recognize several different file suffixes. - # If the user specifies -o file.o, it is replaced with file.lo - xform='[cCFSifmso]' - case $libobj in - *.ada) xform=ada ;; - *.adb) xform=adb ;; - *.ads) xform=ads ;; - *.asm) xform=asm ;; - *.c++) xform=c++ ;; - *.cc) xform=cc ;; - *.ii) xform=ii ;; - *.class) xform=class ;; - *.cpp) xform=cpp ;; - *.cxx) xform=cxx ;; - *.[fF][09]?) xform=[fF][09]. ;; - *.for) xform=for ;; - *.java) xform=java ;; - *.obj) xform=obj ;; - *.sx) xform=sx ;; - esac - - libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` - - case $libobj in - *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;; - *) - $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - func_infer_tag $base_compile - - for arg in $later; do - case $arg in - -static) - build_old_libs=yes - continue - ;; - - -prefer-pic) - pic_mode=yes - continue - ;; - - -prefer-non-pic) - pic_mode=no - continue - ;; - esac - done - - qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"` - case $qlibobj in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qlibobj="\"$qlibobj\"" ;; - esac - test "X$libobj" != "X$qlibobj" \ - && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \ - && $echo "$modename: libobj name \`$libobj' may not contain shell special characters." - objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` - xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$obj"; then - xdir= - else - xdir=$xdir/ - fi - lobj=${xdir}$objdir/$objname - - if test -z "$base_compile"; then - $echo "$modename: you must specify a compilation command" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Delete any leftover library objects. - if test "$build_old_libs" = yes; then - removelist="$obj $lobj $libobj ${libobj}T" - else - removelist="$lobj $libobj ${libobj}T" - fi - - $run $rm $removelist - trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 - - # On Cygwin there's no "real" PIC flag so we must build both object types - case $host_os in - cygwin* | mingw* | pw32* | os2*) - pic_mode=default - ;; - esac - if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then - # non-PIC code in shared libraries is not supported - pic_mode=default - fi - - # Calculate the filename of the output object if compiler does - # not support -o with -c - if test "$compiler_c_o" = no; then - output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} - lockfile="$output_obj.lock" - removelist="$removelist $output_obj $lockfile" - trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 - else - output_obj= - need_locks=no - lockfile= - fi - - # Lock this critical section if it is needed - # We use this script file to make the link, it avoids creating a new file - if test "$need_locks" = yes; then - until $run ln "$progpath" "$lockfile" 2>/dev/null; do - $show "Waiting for $lockfile to be removed" - sleep 2 - done - elif test "$need_locks" = warn; then - if test -f "$lockfile"; then - $echo "\ -*** ERROR, $lockfile exists and contains: -`cat $lockfile 2>/dev/null` - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit $EXIT_FAILURE - fi - $echo "$srcfile" > "$lockfile" - fi - - if test -n "$fix_srcfile_path"; then - eval srcfile=\"$fix_srcfile_path\" - fi - qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"` - case $qsrcfile in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qsrcfile="\"$qsrcfile\"" ;; - esac - - $run $rm "$libobj" "${libobj}T" - - # Create a libtool object file (analogous to a ".la" file), - # but don't create it if we're doing a dry run. - test -z "$run" && cat > ${libobj}T </dev/null`" != "X$srcfile"; then - $echo "\ -*** ERROR, $lockfile contains: -`cat $lockfile 2>/dev/null` - -but it should contain: -$srcfile - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit $EXIT_FAILURE - fi - - # Just move the object if needed, then go on to compile the next one - if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then - $show "$mv $output_obj $lobj" - if $run $mv $output_obj $lobj; then : - else - error=$? - $run $rm $removelist - exit $error - fi - fi - - # Append the name of the PIC object to the libtool object file. - test -z "$run" && cat >> ${libobj}T <> ${libobj}T </dev/null`" != "X$srcfile"; then - $echo "\ -*** ERROR, $lockfile contains: -`cat $lockfile 2>/dev/null` - -but it should contain: -$srcfile - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit $EXIT_FAILURE - fi - - # Just move the object if needed - if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then - $show "$mv $output_obj $obj" - if $run $mv $output_obj $obj; then : - else - error=$? - $run $rm $removelist - exit $error - fi - fi - - # Append the name of the non-PIC object the libtool object file. - # Only append if the libtool object file exists. - test -z "$run" && cat >> ${libobj}T <> ${libobj}T <&2 - fi - if test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - -static) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=built - ;; - -static-libtool-libs) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - esac - build_libtool_libs=no - build_old_libs=yes - break - ;; - esac - done - - # See if our shared archives depend on static archives. - test -n "$old_archive_from_new_cmds" && build_old_libs=yes - - # Go through the arguments, transforming them on the way. - while test "$#" -gt 0; do - arg="$1" - shift - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test - ;; - *) qarg=$arg ;; - esac - libtool_args="$libtool_args $qarg" - - # If the previous option needs an argument, assign it. - if test -n "$prev"; then - case $prev in - output) - compile_command="$compile_command @OUTPUT@" - finalize_command="$finalize_command @OUTPUT@" - ;; - esac - - case $prev in - dlfiles|dlprefiles) - if test "$preload" = no; then - # Add the symbol object into the linking commands. - compile_command="$compile_command @SYMFILE@" - finalize_command="$finalize_command @SYMFILE@" - preload=yes - fi - case $arg in - *.la | *.lo) ;; # We handle these cases below. - force) - if test "$dlself" = no; then - dlself=needless - export_dynamic=yes - fi - prev= - continue - ;; - self) - if test "$prev" = dlprefiles; then - dlself=yes - elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then - dlself=yes - else - dlself=needless - export_dynamic=yes - fi - prev= - continue - ;; - *) - if test "$prev" = dlfiles; then - dlfiles="$dlfiles $arg" - else - dlprefiles="$dlprefiles $arg" - fi - prev= - continue - ;; - esac - ;; - expsyms) - export_symbols="$arg" - if test ! -f "$arg"; then - $echo "$modename: symbol file \`$arg' does not exist" - exit $EXIT_FAILURE - fi - prev= - continue - ;; - expsyms_regex) - export_symbols_regex="$arg" - prev= - continue - ;; - inst_prefix) - inst_prefix_dir="$arg" - prev= - continue - ;; - precious_regex) - precious_files_regex="$arg" - prev= - continue - ;; - release) - release="-$arg" - prev= - continue - ;; - objectlist) - if test -f "$arg"; then - save_arg=$arg - moreargs= - for fil in `cat $save_arg` - do -# moreargs="$moreargs $fil" - arg=$fil - # A libtool-controlled object. - - # Check to see that this really is a libtool object. - if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - pic_object= - non_pic_object= - - # Read the .lo file - # If there is no directory component, then add one. - case $arg in - */* | *\\*) . $arg ;; - *) . ./$arg ;; - esac - - if test -z "$pic_object" || \ - test -z "$non_pic_object" || - test "$pic_object" = none && \ - test "$non_pic_object" = none; then - $echo "$modename: cannot find name of object for \`$arg'" 1>&2 - exit $EXIT_FAILURE - fi - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - if test "$pic_object" != none; then - # Prepend the subdirectory the object is found in. - pic_object="$xdir$pic_object" - - if test "$prev" = dlfiles; then - if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then - dlfiles="$dlfiles $pic_object" - prev= - continue - else - # If libtool objects are unsupported, then we need to preload. - prev=dlprefiles - fi - fi - - # CHECK ME: I think I busted this. -Ossama - if test "$prev" = dlprefiles; then - # Preload the old-style object. - dlprefiles="$dlprefiles $pic_object" - prev= - fi - - # A PIC object. - libobjs="$libobjs $pic_object" - arg="$pic_object" - fi - - # Non-PIC object. - if test "$non_pic_object" != none; then - # Prepend the subdirectory the object is found in. - non_pic_object="$xdir$non_pic_object" - - # A standard non-PIC object - non_pic_objects="$non_pic_objects $non_pic_object" - if test -z "$pic_object" || test "$pic_object" = none ; then - arg="$non_pic_object" - fi - else - # If the PIC object exists, use it instead. - # $xdir was prepended to $pic_object above. - non_pic_object="$pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - else - # Only an error if not doing a dry-run. - if test -z "$run"; then - $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 - exit $EXIT_FAILURE - else - # Dry-run case. - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` - non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` - libobjs="$libobjs $pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - fi - done - else - $echo "$modename: link input file \`$save_arg' does not exist" - exit $EXIT_FAILURE - fi - arg=$save_arg - prev= - continue - ;; - rpath | xrpath) - # We need an absolute path. - case $arg in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - $echo "$modename: only absolute run-paths are allowed" 1>&2 - exit $EXIT_FAILURE - ;; - esac - if test "$prev" = rpath; then - case "$rpath " in - *" $arg "*) ;; - *) rpath="$rpath $arg" ;; - esac - else - case "$xrpath " in - *" $arg "*) ;; - *) xrpath="$xrpath $arg" ;; - esac - fi - prev= - continue - ;; - xcompiler) - compiler_flags="$compiler_flags $qarg" - prev= - compile_command="$compile_command $qarg" - finalize_command="$finalize_command $qarg" - continue - ;; - xlinker) - linker_flags="$linker_flags $qarg" - compiler_flags="$compiler_flags $wl$qarg" - prev= - compile_command="$compile_command $wl$qarg" - finalize_command="$finalize_command $wl$qarg" - continue - ;; - xcclinker) - linker_flags="$linker_flags $qarg" - compiler_flags="$compiler_flags $qarg" - prev= - compile_command="$compile_command $qarg" - finalize_command="$finalize_command $qarg" - continue - ;; - shrext) - shrext_cmds="$arg" - prev= - continue - ;; - darwin_framework|darwin_framework_skip) - test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - prev= - continue - ;; - *) - eval "$prev=\"\$arg\"" - prev= - continue - ;; - esac - fi # test -n "$prev" - - prevarg="$arg" - - case $arg in - -all-static) - if test -n "$link_static_flag"; then - compile_command="$compile_command $link_static_flag" - finalize_command="$finalize_command $link_static_flag" - fi - continue - ;; - - -allow-undefined) - # FIXME: remove this flag sometime in the future. - $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2 - continue - ;; - - -avoid-version) - avoid_version=yes - continue - ;; - - -dlopen) - prev=dlfiles - continue - ;; - - -dlpreopen) - prev=dlprefiles - continue - ;; - - -export-dynamic) - export_dynamic=yes - continue - ;; - - -export-symbols | -export-symbols-regex) - if test -n "$export_symbols" || test -n "$export_symbols_regex"; then - $echo "$modename: more than one -exported-symbols argument is not allowed" - exit $EXIT_FAILURE - fi - if test "X$arg" = "X-export-symbols"; then - prev=expsyms - else - prev=expsyms_regex - fi - continue - ;; - - -framework|-arch|-isysroot) - case " $CC " in - *" ${arg} ${1} "* | *" ${arg} ${1} "*) - prev=darwin_framework_skip ;; - *) compiler_flags="$compiler_flags $arg" - prev=darwin_framework ;; - esac - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - continue - ;; - - -inst-prefix-dir) - prev=inst_prefix - continue - ;; - - # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* - # so, if we see these flags be careful not to treat them like -L - -L[A-Z][A-Z]*:*) - case $with_gcc/$host in - no/*-*-irix* | /*-*-irix*) - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - ;; - esac - continue - ;; - - -L*) - dir=`$echo "X$arg" | $Xsed -e 's/^-L//'` - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - absdir=`cd "$dir" && pwd` - if test -z "$absdir"; then - $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2 - absdir="$dir" - notinst_path="$notinst_path $dir" - fi - dir="$absdir" - ;; - esac - case "$deplibs " in - *" -L$dir "*) ;; - *) - deplibs="$deplibs -L$dir" - lib_search_path="$lib_search_path $dir" - ;; - esac - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'` - case :$dllsearchpath: in - *":$dir:"*) ;; - *) dllsearchpath="$dllsearchpath:$dir";; - esac - case :$dllsearchpath: in - *":$testbindir:"*) ;; - *) dllsearchpath="$dllsearchpath:$testbindir";; - esac - ;; - esac - continue - ;; - - -l*) - if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*) - # These systems don't actually have a C or math library (as such) - continue - ;; - *-*-os2*) - # These systems don't actually have a C library (as such) - test "X$arg" = "X-lc" && continue - ;; - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) - # Do not include libc due to us having libc/libc_r. - test "X$arg" = "X-lc" && continue - ;; - *-*-rhapsody* | *-*-darwin1.[012]) - # Rhapsody C and math libraries are in the System framework - deplibs="$deplibs -framework System" - continue - ;; - *-*-sco3.2v5* | *-*-sco5v6*) - # Causes problems with __ctype - test "X$arg" = "X-lc" && continue - ;; - *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) - # Compiler inserts libc in the correct place for threads to work - test "X$arg" = "X-lc" && continue - ;; - esac - elif test "X$arg" = "X-lc_r"; then - case $host in - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) - # Do not include libc_r directly, use -pthread flag. - continue - ;; - esac - fi - deplibs="$deplibs $arg" - continue - ;; - - # Tru64 UNIX uses -model [arg] to determine the layout of C++ - # classes, name mangling, and exception handling. - -model) - compile_command="$compile_command $arg" - compiler_flags="$compiler_flags $arg" - finalize_command="$finalize_command $arg" - prev=xcompiler - continue - ;; - - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) - compiler_flags="$compiler_flags $arg" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - continue - ;; - - -multi_module) - single_module="${wl}-multi_module" - continue - ;; - - -module) - module=yes - continue - ;; - - # -64, -mips[0-9] enable 64-bit mode on the SGI compiler - # -r[0-9][0-9]* specifies the processor on the SGI compiler - # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler - # +DA*, +DD* enable 64-bit mode on the HP compiler - # -q* pass through compiler args for the IBM compiler - # -m* pass through architecture-specific compiler args for GCC - # -m*, -t[45]*, -txscale* pass through architecture-specific - # compiler args for GCC - # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC - # -F/path gives path to uninstalled frameworks, gcc on darwin - # @file GCC response files - -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ - -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) - - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - compiler_flags="$compiler_flags $arg" - continue - ;; - - -shrext) - prev=shrext - continue - ;; - - -no-fast-install) - fast_install=no - continue - ;; - - -no-install) - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) - # The PATH hackery in wrapper scripts is required on Windows - # and Darwin in order for the loader to find any dlls it needs. - $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 - $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 - fast_install=no - ;; - *) no_install=yes ;; - esac - continue - ;; - - -no-undefined) - allow_undefined=no - continue - ;; - - -objectlist) - prev=objectlist - continue - ;; - - -o) prev=output ;; - - -precious-files-regex) - prev=precious_regex - continue - ;; - - -release) - prev=release - continue - ;; - - -rpath) - prev=rpath - continue - ;; - - -R) - prev=xrpath - continue - ;; - - -R*) - dir=`$echo "X$arg" | $Xsed -e 's/^-R//'` - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - $echo "$modename: only absolute run-paths are allowed" 1>&2 - exit $EXIT_FAILURE - ;; - esac - case "$xrpath " in - *" $dir "*) ;; - *) xrpath="$xrpath $dir" ;; - esac - continue - ;; - - -static | -static-libtool-libs) - # The effects of -static are defined in a previous loop. - # We used to do the same as -all-static on platforms that - # didn't have a PIC flag, but the assumption that the effects - # would be equivalent was wrong. It would break on at least - # Digital Unix and AIX. - continue - ;; - - -thread-safe) - thread_safe=yes - continue - ;; - - -version-info) - prev=vinfo - continue - ;; - -version-number) - prev=vinfo - vinfo_number=yes - continue - ;; - - -Wc,*) - args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'` - arg= - save_ifs="$IFS"; IFS=',' - for flag in $args; do - IFS="$save_ifs" - case $flag in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - flag="\"$flag\"" - ;; - esac - arg="$arg $wl$flag" - compiler_flags="$compiler_flags $flag" - done - IFS="$save_ifs" - arg=`$echo "X$arg" | $Xsed -e "s/^ //"` - ;; - - -Wl,*) - args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'` - arg= - save_ifs="$IFS"; IFS=',' - for flag in $args; do - IFS="$save_ifs" - case $flag in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - flag="\"$flag\"" - ;; - esac - arg="$arg $wl$flag" - compiler_flags="$compiler_flags $wl$flag" - linker_flags="$linker_flags $flag" - done - IFS="$save_ifs" - arg=`$echo "X$arg" | $Xsed -e "s/^ //"` - ;; - - -Xcompiler) - prev=xcompiler - continue - ;; - - -Xlinker) - prev=xlinker - continue - ;; - - -XCClinker) - prev=xcclinker - continue - ;; - - # Some other compiler flag. - -* | +*) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - ;; - - *.$objext) - # A standard object. - objs="$objs $arg" - ;; - - *.lo) - # A libtool-controlled object. - - # Check to see that this really is a libtool object. - if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - pic_object= - non_pic_object= - - # Read the .lo file - # If there is no directory component, then add one. - case $arg in - */* | *\\*) . $arg ;; - *) . ./$arg ;; - esac - - if test -z "$pic_object" || \ - test -z "$non_pic_object" || - test "$pic_object" = none && \ - test "$non_pic_object" = none; then - $echo "$modename: cannot find name of object for \`$arg'" 1>&2 - exit $EXIT_FAILURE - fi - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - if test "$pic_object" != none; then - # Prepend the subdirectory the object is found in. - pic_object="$xdir$pic_object" - - if test "$prev" = dlfiles; then - if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then - dlfiles="$dlfiles $pic_object" - prev= - continue - else - # If libtool objects are unsupported, then we need to preload. - prev=dlprefiles - fi - fi - - # CHECK ME: I think I busted this. -Ossama - if test "$prev" = dlprefiles; then - # Preload the old-style object. - dlprefiles="$dlprefiles $pic_object" - prev= - fi - - # A PIC object. - libobjs="$libobjs $pic_object" - arg="$pic_object" - fi - - # Non-PIC object. - if test "$non_pic_object" != none; then - # Prepend the subdirectory the object is found in. - non_pic_object="$xdir$non_pic_object" - - # A standard non-PIC object - non_pic_objects="$non_pic_objects $non_pic_object" - if test -z "$pic_object" || test "$pic_object" = none ; then - arg="$non_pic_object" - fi - else - # If the PIC object exists, use it instead. - # $xdir was prepended to $pic_object above. - non_pic_object="$pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - else - # Only an error if not doing a dry-run. - if test -z "$run"; then - $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 - exit $EXIT_FAILURE - else - # Dry-run case. - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` - non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` - libobjs="$libobjs $pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - fi - ;; - - *.$libext) - # An archive. - deplibs="$deplibs $arg" - old_deplibs="$old_deplibs $arg" - continue - ;; - - *.la) - # A libtool-controlled library. - - if test "$prev" = dlfiles; then - # This library was specified with -dlopen. - dlfiles="$dlfiles $arg" - prev= - elif test "$prev" = dlprefiles; then - # The library was specified with -dlpreopen. - dlprefiles="$dlprefiles $arg" - prev= - else - deplibs="$deplibs $arg" - fi - continue - ;; - - # Some other compiler argument. - *) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - ;; - esac # arg - - # Now actually substitute the argument into the commands. - if test -n "$arg"; then - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - fi - done # argument parsing loop - - if test -n "$prev"; then - $echo "$modename: the \`$prevarg' option requires an argument" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then - eval arg=\"$export_dynamic_flag_spec\" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - fi - - oldlibs= - # calculate the name of the file, without its directory - outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'` - libobjs_save="$libobjs" - - if test -n "$shlibpath_var"; then - # get the directories listed in $shlibpath_var - eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` - else - shlib_search_path= - fi - eval sys_lib_search_path=\"$sys_lib_search_path_spec\" - eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" - - output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'` - if test "X$output_objdir" = "X$output"; then - output_objdir="$objdir" - else - output_objdir="$output_objdir/$objdir" - fi - # Create the object directory. - if test ! -d "$output_objdir"; then - $show "$mkdir $output_objdir" - $run $mkdir $output_objdir - exit_status=$? - if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then - exit $exit_status - fi - fi - - # Determine the type of output - case $output in - "") - $echo "$modename: you must specify an output file" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - *.$libext) linkmode=oldlib ;; - *.lo | *.$objext) linkmode=obj ;; - *.la) linkmode=lib ;; - *) linkmode=prog ;; # Anything else should be a program. - esac - - case $host in - *cygwin* | *mingw* | *pw32*) - # don't eliminate duplications in $postdeps and $predeps - duplicate_compiler_generated_deps=yes - ;; - *) - duplicate_compiler_generated_deps=$duplicate_deps - ;; - esac - specialdeplibs= - - libs= - # Find all interdependent deplibs by searching for libraries - # that are linked more than once (e.g. -la -lb -la) - for deplib in $deplibs; do - if test "X$duplicate_deps" = "Xyes" ; then - case "$libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - libs="$libs $deplib" - done - - if test "$linkmode" = lib; then - libs="$predeps $libs $compiler_lib_search_path $postdeps" - - # Compute libraries that are listed more than once in $predeps - # $postdeps and mark them as special (i.e., whose duplicates are - # not to be eliminated). - pre_post_deps= - if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then - for pre_post_dep in $predeps $postdeps; do - case "$pre_post_deps " in - *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; - esac - pre_post_deps="$pre_post_deps $pre_post_dep" - done - fi - pre_post_deps= - fi - - deplibs= - newdependency_libs= - newlib_search_path= - need_relink=no # whether we're linking any uninstalled libtool libraries - notinst_deplibs= # not-installed libtool libraries - case $linkmode in - lib) - passes="conv link" - for file in $dlfiles $dlprefiles; do - case $file in - *.la) ;; - *) - $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2 - exit $EXIT_FAILURE - ;; - esac - done - ;; - prog) - compile_deplibs= - finalize_deplibs= - alldeplibs=no - newdlfiles= - newdlprefiles= - passes="conv scan dlopen dlpreopen link" - ;; - *) passes="conv" - ;; - esac - for pass in $passes; do - if test "$linkmode,$pass" = "lib,link" || - test "$linkmode,$pass" = "prog,scan"; then - libs="$deplibs" - deplibs= - fi - if test "$linkmode" = prog; then - case $pass in - dlopen) libs="$dlfiles" ;; - dlpreopen) libs="$dlprefiles" ;; - link) - libs="$deplibs %DEPLIBS%" - test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" - ;; - esac - fi - if test "$pass" = dlopen; then - # Collect dlpreopened libraries - save_deplibs="$deplibs" - deplibs= - fi - for deplib in $libs; do - lib= - found=no - case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - compiler_flags="$compiler_flags $deplib" - fi - continue - ;; - -l*) - if test "$linkmode" != lib && test "$linkmode" != prog; then - $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2 - continue - fi - name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` - if test "$linkmode" = lib; then - searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" - else - searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" - fi - for searchdir in $searchdirs; do - for search_ext in .la $std_shrext .so .a; do - # Search the libtool library - lib="$searchdir/lib${name}${search_ext}" - if test -f "$lib"; then - if test "$search_ext" = ".la"; then - found=yes - else - found=no - fi - break 2 - fi - done - done - if test "$found" != yes; then - # deplib doesn't seem to be a libtool library - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - deplibs="$deplib $deplibs" - test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" - fi - continue - else # deplib is a libtool library - # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, - # We need to do some special things here, and not later. - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - case " $predeps $postdeps " in - *" $deplib "*) - if (${SED} -e '2q' $lib | - grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - library_names= - old_library= - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - for l in $old_library $library_names; do - ll="$l" - done - if test "X$ll" = "X$old_library" ; then # only static version available - found=no - ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` - test "X$ladir" = "X$lib" && ladir="." - lib=$ladir/$old_library - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - deplibs="$deplib $deplibs" - test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" - fi - continue - fi - fi - ;; - *) ;; - esac - fi - fi - ;; # -l - -L*) - case $linkmode in - lib) - deplibs="$deplib $deplibs" - test "$pass" = conv && continue - newdependency_libs="$deplib $newdependency_libs" - newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` - ;; - prog) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - if test "$pass" = scan; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` - ;; - *) - $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2 - ;; - esac # linkmode - continue - ;; # -L - -R*) - if test "$pass" = link; then - dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'` - # Make sure the xrpath contains only unique directories. - case "$xrpath " in - *" $dir "*) ;; - *) xrpath="$xrpath $dir" ;; - esac - fi - deplibs="$deplib $deplibs" - continue - ;; - *.la) lib="$deplib" ;; - *.$libext) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - case $linkmode in - lib) - valid_a_lib=no - case $deplibs_check_method in - match_pattern*) - set dummy $deplibs_check_method - match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` - if eval $echo \"$deplib\" 2>/dev/null \ - | $SED 10q \ - | $EGREP "$match_pattern_regex" > /dev/null; then - valid_a_lib=yes - fi - ;; - pass_all) - valid_a_lib=yes - ;; - esac - if test "$valid_a_lib" != yes; then - $echo - $echo "*** Warning: Trying to link with static lib archive $deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because the file extensions .$libext of this argument makes me believe" - $echo "*** that it is just a static archive that I should not used here." - else - $echo - $echo "*** Warning: Linking the shared library $output against the" - $echo "*** static library $deplib is not portable!" - deplibs="$deplib $deplibs" - fi - continue - ;; - prog) - if test "$pass" != link; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - continue - ;; - esac # linkmode - ;; # *.$libext - *.lo | *.$objext) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - elif test "$linkmode" = prog; then - if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then - # If there is no dlopen support or we're linking statically, - # we need to preload. - newdlprefiles="$newdlprefiles $deplib" - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - newdlfiles="$newdlfiles $deplib" - fi - fi - continue - ;; - %DEPLIBS%) - alldeplibs=yes - continue - ;; - esac # case $deplib - if test "$found" = yes || test -f "$lib"; then : - else - $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2 - exit $EXIT_FAILURE - fi - - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - - ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` - test "X$ladir" = "X$lib" && ladir="." - - dlname= - dlopen= - dlpreopen= - libdir= - library_names= - old_library= - # If the library was installed with an old release of libtool, - # it will not redefine variables installed, or shouldnotlink - installed=yes - shouldnotlink=no - avoidtemprpath= - - - # Read the .la file - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - - if test "$linkmode,$pass" = "lib,link" || - test "$linkmode,$pass" = "prog,scan" || - { test "$linkmode" != prog && test "$linkmode" != lib; }; then - test -n "$dlopen" && dlfiles="$dlfiles $dlopen" - test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" - fi - - if test "$pass" = conv; then - # Only check for convenience libraries - deplibs="$lib $deplibs" - if test -z "$libdir"; then - if test -z "$old_library"; then - $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - # It is a libtool convenience library, so add in its objects. - convenience="$convenience $ladir/$objdir/$old_library" - old_convenience="$old_convenience $ladir/$objdir/$old_library" - tmp_libs= - for deplib in $dependency_libs; do - deplibs="$deplib $deplibs" - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done - elif test "$linkmode" != prog && test "$linkmode" != lib; then - $echo "$modename: \`$lib' is not a convenience library" 1>&2 - exit $EXIT_FAILURE - fi - continue - fi # $pass = conv - - - # Get the name of the library we link against. - linklib= - for l in $old_library $library_names; do - linklib="$l" - done - if test -z "$linklib"; then - $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - - # This library was specified with -dlopen. - if test "$pass" = dlopen; then - if test -z "$libdir"; then - $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - if test -z "$dlname" || - test "$dlopen_support" != yes || - test "$build_libtool_libs" = no; then - # If there is no dlname, no dlopen support or we're linking - # statically, we need to preload. We also need to preload any - # dependent libraries so libltdl's deplib preloader doesn't - # bomb out in the load deplibs phase. - dlprefiles="$dlprefiles $lib $dependency_libs" - else - newdlfiles="$newdlfiles $lib" - fi - continue - fi # $pass = dlopen - - # We need an absolute path. - case $ladir in - [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; - *) - abs_ladir=`cd "$ladir" && pwd` - if test -z "$abs_ladir"; then - $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2 - $echo "$modename: passing it literally to the linker, although it might fail" 1>&2 - abs_ladir="$ladir" - fi - ;; - esac - laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - - # Find the relevant object directory and library name. - if test "X$installed" = Xyes; then - if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then - $echo "$modename: warning: library \`$lib' was moved." 1>&2 - dir="$ladir" - absdir="$abs_ladir" - libdir="$abs_ladir" - else - dir="$libdir" - absdir="$libdir" - fi - test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes - else - if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then - dir="$ladir" - absdir="$abs_ladir" - # Remove this search path later - notinst_path="$notinst_path $abs_ladir" - else - dir="$ladir/$objdir" - absdir="$abs_ladir/$objdir" - # Remove this search path later - notinst_path="$notinst_path $abs_ladir" - fi - fi # $installed = yes - name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - - # This library was specified with -dlpreopen. - if test "$pass" = dlpreopen; then - if test -z "$libdir"; then - $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - # Prefer using a static library (so that no silly _DYNAMIC symbols - # are required to link). - if test -n "$old_library"; then - newdlprefiles="$newdlprefiles $dir/$old_library" - # Otherwise, use the dlname, so that lt_dlopen finds it. - elif test -n "$dlname"; then - newdlprefiles="$newdlprefiles $dir/$dlname" - else - newdlprefiles="$newdlprefiles $dir/$linklib" - fi - fi # $pass = dlpreopen - - if test -z "$libdir"; then - # Link the convenience library - if test "$linkmode" = lib; then - deplibs="$dir/$old_library $deplibs" - elif test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$dir/$old_library $compile_deplibs" - finalize_deplibs="$dir/$old_library $finalize_deplibs" - else - deplibs="$lib $deplibs" # used for prog,scan pass - fi - continue - fi - - - if test "$linkmode" = prog && test "$pass" != link; then - newlib_search_path="$newlib_search_path $ladir" - deplibs="$lib $deplibs" - - linkalldeplibs=no - if test "$link_all_deplibs" != no || test -z "$library_names" || - test "$build_libtool_libs" = no; then - linkalldeplibs=yes - fi - - tmp_libs= - for deplib in $dependency_libs; do - case $deplib in - -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test - esac - # Need to link against all dependency_libs? - if test "$linkalldeplibs" = yes; then - deplibs="$deplib $deplibs" - else - # Need to hardcode shared library paths - # or/and link against static libraries - newdependency_libs="$deplib $newdependency_libs" - fi - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done # for deplib - continue - fi # $linkmode = prog... - - if test "$linkmode,$pass" = "prog,link"; then - if test -n "$library_names" && - { { test "$prefer_static_libs" = no || - test "$prefer_static_libs,$installed" = "built,yes"; } || - test -z "$old_library"; }; then - # We need to hardcode the library path - if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then - # Make sure the rpath contains only unique directories. - case "$temp_rpath " in - *" $dir "*) ;; - *" $absdir "*) ;; - *) temp_rpath="$temp_rpath $absdir" ;; - esac - fi - - # Hardcode the library path. - # Skip directories that are in the system default run-time - # search path. - case " $sys_lib_dlsearch_path " in - *" $absdir "*) ;; - *) - case "$compile_rpath " in - *" $absdir "*) ;; - *) compile_rpath="$compile_rpath $absdir" - esac - ;; - esac - case " $sys_lib_dlsearch_path " in - *" $libdir "*) ;; - *) - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" - esac - ;; - esac - fi # $linkmode,$pass = prog,link... - - if test "$alldeplibs" = yes && - { test "$deplibs_check_method" = pass_all || - { test "$build_libtool_libs" = yes && - test -n "$library_names"; }; }; then - # We only need to search for static libraries - continue - fi - fi - - link_static=no # Whether the deplib will be linked statically - use_static_libs=$prefer_static_libs - if test "$use_static_libs" = built && test "$installed" = yes ; then - use_static_libs=no - fi - if test -n "$library_names" && - { test "$use_static_libs" = no || test -z "$old_library"; }; then - if test "$installed" = no; then - notinst_deplibs="$notinst_deplibs $lib" - need_relink=yes - fi - # This is a shared library - - # Warn about portability, can't link against -module's on - # some systems (darwin) - if test "$shouldnotlink" = yes && test "$pass" = link ; then - $echo - if test "$linkmode" = prog; then - $echo "*** Warning: Linking the executable $output against the loadable module" - else - $echo "*** Warning: Linking the shared library $output against the loadable module" - fi - $echo "*** $linklib is not portable!" - fi - if test "$linkmode" = lib && - test "$hardcode_into_libs" = yes; then - # Hardcode the library path. - # Skip directories that are in the system default run-time - # search path. - case " $sys_lib_dlsearch_path " in - *" $absdir "*) ;; - *) - case "$compile_rpath " in - *" $absdir "*) ;; - *) compile_rpath="$compile_rpath $absdir" - esac - ;; - esac - case " $sys_lib_dlsearch_path " in - *" $libdir "*) ;; - *) - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" - esac - ;; - esac - fi - - if test -n "$old_archive_from_expsyms_cmds"; then - # figure out the soname - set dummy $library_names - realname="$2" - shift; shift - libname=`eval \\$echo \"$libname_spec\"` - # use dlname if we got it. it's perfectly good, no? - if test -n "$dlname"; then - soname="$dlname" - elif test -n "$soname_spec"; then - # bleh windows - case $host in - *cygwin* | mingw*) - major=`expr $current - $age` - versuffix="-$major" - ;; - esac - eval soname=\"$soname_spec\" - else - soname="$realname" - fi - - # Make a new name for the extract_expsyms_cmds to use - soroot="$soname" - soname=`$echo $soroot | ${SED} -e 's/^.*\///'` - newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a" - - # If the library has no export list, then create one now - if test -f "$output_objdir/$soname-def"; then : - else - $show "extracting exported symbol list from \`$soname'" - save_ifs="$IFS"; IFS='~' - cmds=$extract_expsyms_cmds - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - # Create $newlib - if test -f "$output_objdir/$newlib"; then :; else - $show "generating import library for \`$soname'" - save_ifs="$IFS"; IFS='~' - cmds=$old_archive_from_expsyms_cmds - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - # make sure the library variables are pointing to the new library - dir=$output_objdir - linklib=$newlib - fi # test -n "$old_archive_from_expsyms_cmds" - - if test "$linkmode" = prog || test "$mode" != relink; then - add_shlibpath= - add_dir= - add= - lib_linked=yes - case $hardcode_action in - immediate | unsupported) - if test "$hardcode_direct" = no; then - add="$dir/$linklib" - case $host in - *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; - *-*-sysv4*uw2*) add_dir="-L$dir" ;; - *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ - *-*-unixware7*) add_dir="-L$dir" ;; - *-*-darwin* ) - # if the lib is a module then we can not link against - # it, someone is ignoring the new warnings I added - if /usr/bin/file -L $add 2> /dev/null | - $EGREP ": [^:]* bundle" >/dev/null ; then - $echo "** Warning, lib $linklib is a module, not a shared library" - if test -z "$old_library" ; then - $echo - $echo "** And there doesn't seem to be a static archive available" - $echo "** The link will probably fail, sorry" - else - add="$dir/$old_library" - fi - fi - esac - elif test "$hardcode_minus_L" = no; then - case $host in - *-*-sunos*) add_shlibpath="$dir" ;; - esac - add_dir="-L$dir" - add="-l$name" - elif test "$hardcode_shlibpath_var" = no; then - add_shlibpath="$dir" - add="-l$name" - else - lib_linked=no - fi - ;; - relink) - if test "$hardcode_direct" = yes; then - add="$dir/$linklib" - elif test "$hardcode_minus_L" = yes; then - add_dir="-L$dir" - # Try looking first in the location we're being installed to. - if test -n "$inst_prefix_dir"; then - case $libdir in - [\\/]*) - add_dir="$add_dir -L$inst_prefix_dir$libdir" - ;; - esac - fi - add="-l$name" - elif test "$hardcode_shlibpath_var" = yes; then - add_shlibpath="$dir" - add="-l$name" - else - lib_linked=no - fi - ;; - *) lib_linked=no ;; - esac - - if test "$lib_linked" != yes; then - $echo "$modename: configuration error: unsupported hardcode properties" - exit $EXIT_FAILURE - fi - - if test -n "$add_shlibpath"; then - case :$compile_shlibpath: in - *":$add_shlibpath:"*) ;; - *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; - esac - fi - if test "$linkmode" = prog; then - test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" - test -n "$add" && compile_deplibs="$add $compile_deplibs" - else - test -n "$add_dir" && deplibs="$add_dir $deplibs" - test -n "$add" && deplibs="$add $deplibs" - if test "$hardcode_direct" != yes && \ - test "$hardcode_minus_L" != yes && \ - test "$hardcode_shlibpath_var" = yes; then - case :$finalize_shlibpath: in - *":$libdir:"*) ;; - *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; - esac - fi - fi - fi - - if test "$linkmode" = prog || test "$mode" = relink; then - add_shlibpath= - add_dir= - add= - # Finalize command for both is simple: just hardcode it. - if test "$hardcode_direct" = yes; then - add="$libdir/$linklib" - elif test "$hardcode_minus_L" = yes; then - add_dir="-L$libdir" - add="-l$name" - elif test "$hardcode_shlibpath_var" = yes; then - case :$finalize_shlibpath: in - *":$libdir:"*) ;; - *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; - esac - add="-l$name" - elif test "$hardcode_automatic" = yes; then - if test -n "$inst_prefix_dir" && - test -f "$inst_prefix_dir$libdir/$linklib" ; then - add="$inst_prefix_dir$libdir/$linklib" - else - add="$libdir/$linklib" - fi - else - # We cannot seem to hardcode it, guess we'll fake it. - add_dir="-L$libdir" - # Try looking first in the location we're being installed to. - if test -n "$inst_prefix_dir"; then - case $libdir in - [\\/]*) - add_dir="$add_dir -L$inst_prefix_dir$libdir" - ;; - esac - fi - add="-l$name" - fi - - if test "$linkmode" = prog; then - test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" - test -n "$add" && finalize_deplibs="$add $finalize_deplibs" - else - test -n "$add_dir" && deplibs="$add_dir $deplibs" - test -n "$add" && deplibs="$add $deplibs" - fi - fi - elif test "$linkmode" = prog; then - # Here we assume that one of hardcode_direct or hardcode_minus_L - # is not unsupported. This is valid on all known static and - # shared platforms. - if test "$hardcode_direct" != unsupported; then - test -n "$old_library" && linklib="$old_library" - compile_deplibs="$dir/$linklib $compile_deplibs" - finalize_deplibs="$dir/$linklib $finalize_deplibs" - else - compile_deplibs="-l$name -L$dir $compile_deplibs" - finalize_deplibs="-l$name -L$dir $finalize_deplibs" - fi - elif test "$build_libtool_libs" = yes; then - # Not a shared library - if test "$deplibs_check_method" != pass_all; then - # We're trying link a shared library against a static one - # but the system doesn't support it. - - # Just print a warning and add the library to dependency_libs so - # that the program can be linked against the static library. - $echo - $echo "*** Warning: This system can not link to static lib archive $lib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have." - if test "$module" = yes; then - $echo "*** But as you try to build a module library, libtool will still create " - $echo "*** a static module, that should work as long as the dlopening application" - $echo "*** is linked with the -dlopen flag to resolve symbols at runtime." - if test -z "$global_symbol_pipe"; then - $echo - $echo "*** However, this would only work if libtool was able to extract symbol" - $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" - $echo "*** not find such a program. So, this module is probably useless." - $echo "*** \`nm' from GNU binutils and a full rebuild may help." - fi - if test "$build_old_libs" = no; then - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - fi - else - deplibs="$dir/$old_library $deplibs" - link_static=yes - fi - fi # link shared/static library? - - if test "$linkmode" = lib; then - if test -n "$dependency_libs" && - { test "$hardcode_into_libs" != yes || - test "$build_old_libs" = yes || - test "$link_static" = yes; }; then - # Extract -R from dependency_libs - temp_deplibs= - for libdir in $dependency_libs; do - case $libdir in - -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'` - case " $xrpath " in - *" $temp_xrpath "*) ;; - *) xrpath="$xrpath $temp_xrpath";; - esac;; - *) temp_deplibs="$temp_deplibs $libdir";; - esac - done - dependency_libs="$temp_deplibs" - fi - - newlib_search_path="$newlib_search_path $absdir" - # Link against this library - test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" - # ... and its dependency_libs - tmp_libs= - for deplib in $dependency_libs; do - newdependency_libs="$deplib $newdependency_libs" - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done - - if test "$link_all_deplibs" != no; then - # Add the search paths of all dependency libraries - for deplib in $dependency_libs; do - case $deplib in - -L*) path="$deplib" ;; - *.la) - dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$deplib" && dir="." - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; - *) - absdir=`cd "$dir" && pwd` - if test -z "$absdir"; then - $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2 - absdir="$dir" - fi - ;; - esac - if grep "^installed=no" $deplib > /dev/null; then - path="$absdir/$objdir" - else - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -z "$libdir"; then - $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - if test "$absdir" != "$libdir"; then - $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2 - fi - path="$absdir" - fi - depdepl= - case $host in - *-*-darwin*) - # we do not want to link against static libs, - # but need to link against shared - eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` - eval deplibdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -n "$deplibrary_names" ; then - for tmp in $deplibrary_names ; do - depdepl=$tmp - done - if test -f "$deplibdir/$depdepl" ; then - depdepl="$deplibdir/$depdepl" - elif test -f "$path/$depdepl" ; then - depdepl="$path/$depdepl" - else - # Can't find it, oh well... - depdepl= - fi - # do not add paths which are already there - case " $newlib_search_path " in - *" $path "*) ;; - *) newlib_search_path="$newlib_search_path $path";; - esac - fi - path="" - ;; - *) - path="-L$path" - ;; - esac - ;; - -l*) - case $host in - *-*-darwin*) - # Again, we only want to link against shared libraries - eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"` - for tmp in $newlib_search_path ; do - if test -f "$tmp/lib$tmp_libs.dylib" ; then - eval depdepl="$tmp/lib$tmp_libs.dylib" - break - fi - done - path="" - ;; - *) continue ;; - esac - ;; - *) continue ;; - esac - case " $deplibs " in - *" $path "*) ;; - *) deplibs="$path $deplibs" ;; - esac - case " $deplibs " in - *" $depdepl "*) ;; - *) deplibs="$depdepl $deplibs" ;; - esac - done - fi # link_all_deplibs != no - fi # linkmode = lib - done # for deplib in $libs - dependency_libs="$newdependency_libs" - if test "$pass" = dlpreopen; then - # Link the dlpreopened libraries before other libraries - for deplib in $save_deplibs; do - deplibs="$deplib $deplibs" - done - fi - if test "$pass" != dlopen; then - if test "$pass" != conv; then - # Make sure lib_search_path contains only unique directories. - lib_search_path= - for dir in $newlib_search_path; do - case "$lib_search_path " in - *" $dir "*) ;; - *) lib_search_path="$lib_search_path $dir" ;; - esac - done - newlib_search_path= - fi - - if test "$linkmode,$pass" != "prog,link"; then - vars="deplibs" - else - vars="compile_deplibs finalize_deplibs" - fi - for var in $vars dependency_libs; do - # Add libraries to $var in reverse order - eval tmp_libs=\"\$$var\" - new_libs= - for deplib in $tmp_libs; do - # FIXME: Pedantically, this is the right thing to do, so - # that some nasty dependency loop isn't accidentally - # broken: - #new_libs="$deplib $new_libs" - # Pragmatically, this seems to cause very few problems in - # practice: - case $deplib in - -L*) new_libs="$deplib $new_libs" ;; - -R*) ;; - *) - # And here is the reason: when a library appears more - # than once as an explicit dependence of a library, or - # is implicitly linked in more than once by the - # compiler, it is considered special, and multiple - # occurrences thereof are not removed. Compare this - # with having the same library being listed as a - # dependency of multiple other libraries: in this case, - # we know (pedantically, we assume) the library does not - # need to be listed more than once, so we keep only the - # last copy. This is not always right, but it is rare - # enough that we require users that really mean to play - # such unportable linking tricks to link the library - # using -Wl,-lname, so that libtool does not consider it - # for duplicate removal. - case " $specialdeplibs " in - *" $deplib "*) new_libs="$deplib $new_libs" ;; - *) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$deplib $new_libs" ;; - esac - ;; - esac - ;; - esac - done - tmp_libs= - for deplib in $new_libs; do - case $deplib in - -L*) - case " $tmp_libs " in - *" $deplib "*) ;; - *) tmp_libs="$tmp_libs $deplib" ;; - esac - ;; - *) tmp_libs="$tmp_libs $deplib" ;; - esac - done - eval $var=\"$tmp_libs\" - done # for var - fi - # Last step: remove runtime libs from dependency_libs - # (they stay in deplibs) - tmp_libs= - for i in $dependency_libs ; do - case " $predeps $postdeps $compiler_lib_search_path " in - *" $i "*) - i="" - ;; - esac - if test -n "$i" ; then - tmp_libs="$tmp_libs $i" - fi - done - dependency_libs=$tmp_libs - done # for pass - if test "$linkmode" = prog; then - dlfiles="$newdlfiles" - dlprefiles="$newdlprefiles" - fi - - case $linkmode in - oldlib) - case " $deplibs" in - *\ -l* | *\ -L*) - $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 ;; - esac - - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 - fi - - if test -n "$rpath"; then - $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2 - fi - - if test -n "$xrpath"; then - $echo "$modename: warning: \`-R' is ignored for archives" 1>&2 - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for archives" 1>&2 - fi - - if test -n "$export_symbols" || test -n "$export_symbols_regex"; then - $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2 - fi - - # Now set the variables for building old libraries. - build_libtool_libs=no - oldlibs="$output" - objs="$objs$old_deplibs" - ;; - - lib) - # Make sure we only generate libraries of the form `libNAME.la'. - case $outputname in - lib*) - name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - eval shared_ext=\"$shrext_cmds\" - eval libname=\"$libname_spec\" - ;; - *) - if test "$module" = no; then - $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - if test "$need_lib_prefix" != no; then - # Add the "lib" prefix for modules if required - name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` - eval shared_ext=\"$shrext_cmds\" - eval libname=\"$libname_spec\" - else - libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` - fi - ;; - esac - - if test -n "$objs"; then - if test "$deplibs_check_method" != pass_all; then - $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1 - exit $EXIT_FAILURE - else - $echo - $echo "*** Warning: Linking the shared library $output against the non-libtool" - $echo "*** objects $objs is not portable!" - libobjs="$libobjs $objs" - fi - fi - - if test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2 - fi - - set dummy $rpath - if test "$#" -gt 2; then - $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2 - fi - install_libdir="$2" - - oldlibs= - if test -z "$rpath"; then - if test "$build_libtool_libs" = yes; then - # Building a libtool convenience library. - # Some compilers have problems with a `.al' extension so - # convenience libraries should have the same extension an - # archive normally would. - oldlibs="$output_objdir/$libname.$libext $oldlibs" - build_libtool_libs=convenience - build_old_libs=yes - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2 - fi - else - - # Parse the version information argument. - save_ifs="$IFS"; IFS=':' - set dummy $vinfo 0 0 0 - IFS="$save_ifs" - - if test -n "$8"; then - $echo "$modename: too many parameters to \`-version-info'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # convert absolute version numbers to libtool ages - # this retains compatibility with .la files and attempts - # to make the code below a bit more comprehensible - - case $vinfo_number in - yes) - number_major="$2" - number_minor="$3" - number_revision="$4" - # - # There are really only two kinds -- those that - # use the current revision as the major version - # and those that subtract age and use age as - # a minor version. But, then there is irix - # which has an extra 1 added just for fun - # - case $version_type in - darwin|linux|osf|windows|none) - current=`expr $number_major + $number_minor` - age="$number_minor" - revision="$number_revision" - ;; - freebsd-aout|freebsd-elf|sunos) - current="$number_major" - revision="$number_minor" - age="0" - ;; - irix|nonstopux) - current=`expr $number_major + $number_minor` - age="$number_minor" - revision="$number_minor" - lt_irix_increment=no - ;; - *) - $echo "$modename: unknown library version type \`$version_type'" 1>&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit $EXIT_FAILURE - ;; - esac - ;; - no) - current="$2" - revision="$3" - age="$4" - ;; - esac - - # Check that each of the things are valid numbers. - case $current in - 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; - *) - $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - case $revision in - 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; - *) - $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - case $age in - 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; - *) - $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - if test "$age" -gt "$current"; then - $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - fi - - # Calculate the version variables. - major= - versuffix= - verstring= - case $version_type in - none) ;; - - darwin) - # Like Linux, but with the current version available in - # verstring for coding it into the library header - major=.`expr $current - $age` - versuffix="$major.$age.$revision" - # Darwin ld doesn't like 0 for these options... - minor_current=`expr $current + 1` - xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" - verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" - ;; - - freebsd-aout) - major=".$current" - versuffix=".$current.$revision"; - ;; - - freebsd-elf) - major=".$current" - versuffix=".$current"; - ;; - - irix | nonstopux) - if test "X$lt_irix_increment" = "Xno"; then - major=`expr $current - $age` - else - major=`expr $current - $age + 1` - fi - case $version_type in - nonstopux) verstring_prefix=nonstopux ;; - *) verstring_prefix=sgi ;; - esac - verstring="$verstring_prefix$major.$revision" - - # Add in all the interfaces that we are compatible with. - loop=$revision - while test "$loop" -ne 0; do - iface=`expr $revision - $loop` - loop=`expr $loop - 1` - verstring="$verstring_prefix$major.$iface:$verstring" - done - - # Before this point, $major must not contain `.'. - major=.$major - versuffix="$major.$revision" - ;; - - linux) - major=.`expr $current - $age` - versuffix="$major.$age.$revision" - ;; - - osf) - major=.`expr $current - $age` - versuffix=".$current.$age.$revision" - verstring="$current.$age.$revision" - - # Add in all the interfaces that we are compatible with. - loop=$age - while test "$loop" -ne 0; do - iface=`expr $current - $loop` - loop=`expr $loop - 1` - verstring="$verstring:${iface}.0" - done - - # Make executables depend on our current version. - verstring="$verstring:${current}.0" - ;; - - sunos) - major=".$current" - versuffix=".$current.$revision" - ;; - - windows) - # Use '-' rather than '.', since we only want one - # extension on DOS 8.3 filesystems. - major=`expr $current - $age` - versuffix="-$major" - ;; - - *) - $echo "$modename: unknown library version type \`$version_type'" 1>&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit $EXIT_FAILURE - ;; - esac - - # Clear the version info if we defaulted, and they specified a release. - if test -z "$vinfo" && test -n "$release"; then - major= - case $version_type in - darwin) - # we can't check for "0.0" in archive_cmds due to quoting - # problems, so we reset it completely - verstring= - ;; - *) - verstring="0.0" - ;; - esac - if test "$need_version" = no; then - versuffix= - else - versuffix=".0.0" - fi - fi - - # Remove version info from name if versioning should be avoided - if test "$avoid_version" = yes && test "$need_version" = no; then - major= - versuffix= - verstring="" - fi - - # Check to see if the archive will have undefined symbols. - if test "$allow_undefined" = yes; then - if test "$allow_undefined_flag" = unsupported; then - $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2 - build_libtool_libs=no - build_old_libs=yes - fi - else - # Don't allow undefined symbols. - allow_undefined_flag="$no_undefined_flag" - fi - fi - - if test "$mode" != relink; then - # Remove our outputs, but don't remove object files since they - # may have been created when compiling PIC objects. - removelist= - tempremovelist=`$echo "$output_objdir/*"` - for p in $tempremovelist; do - case $p in - *.$objext) - ;; - $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) - if test "X$precious_files_regex" != "X"; then - if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 - then - continue - fi - fi - removelist="$removelist $p" - ;; - *) ;; - esac - done - if test -n "$removelist"; then - $show "${rm}r $removelist" - $run ${rm}r $removelist - fi - fi - - # Now set the variables for building old libraries. - if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then - oldlibs="$oldlibs $output_objdir/$libname.$libext" - - # Transform .lo files to .o files. - oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` - fi - - # Eliminate all temporary directories. - #for path in $notinst_path; do - # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` - # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` - # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` - #done - - if test -n "$xrpath"; then - # If the user specified any rpath flags, then add them. - temp_xrpath= - for libdir in $xrpath; do - temp_xrpath="$temp_xrpath -R$libdir" - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" ;; - esac - done - if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then - dependency_libs="$temp_xrpath $dependency_libs" - fi - fi - - # Make sure dlfiles contains only unique files that won't be dlpreopened - old_dlfiles="$dlfiles" - dlfiles= - for lib in $old_dlfiles; do - case " $dlprefiles $dlfiles " in - *" $lib "*) ;; - *) dlfiles="$dlfiles $lib" ;; - esac - done - - # Make sure dlprefiles contains only unique files - old_dlprefiles="$dlprefiles" - dlprefiles= - for lib in $old_dlprefiles; do - case "$dlprefiles " in - *" $lib "*) ;; - *) dlprefiles="$dlprefiles $lib" ;; - esac - done - - if test "$build_libtool_libs" = yes; then - if test -n "$rpath"; then - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*) - # these systems don't actually have a c library (as such)! - ;; - *-*-rhapsody* | *-*-darwin1.[012]) - # Rhapsody C library is in the System framework - deplibs="$deplibs -framework System" - ;; - *-*-netbsd*) - # Don't link with libc until the a.out ld.so is fixed. - ;; - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) - # Do not include libc due to us having libc/libc_r. - ;; - *-*-sco3.2v5* | *-*-sco5v6*) - # Causes problems with __ctype - ;; - *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) - # Compiler inserts libc in the correct place for threads to work - ;; - *) - # Add libc to deplibs on all other systems if necessary. - if test "$build_libtool_need_lc" = "yes"; then - deplibs="$deplibs -lc" - fi - ;; - esac - fi - - # Transform deplibs into only deplibs that can be linked in shared. - name_save=$name - libname_save=$libname - release_save=$release - versuffix_save=$versuffix - major_save=$major - # I'm not sure if I'm treating the release correctly. I think - # release should show up in the -l (ie -lgmp5) so we don't want to - # add it in twice. Is that correct? - release="" - versuffix="" - major="" - newdeplibs= - droppeddeps=no - case $deplibs_check_method in - pass_all) - # Don't check for shared/static. Everything works. - # This might be a little naive. We might want to check - # whether the library exists or not. But this is on - # osf3 & osf4 and I'm not really sure... Just - # implementing what was already the behavior. - newdeplibs=$deplibs - ;; - test_compile) - # This code stresses the "libraries are programs" paradigm to its - # limits. Maybe even breaks it. We compile a program, linking it - # against the deplibs as a proxy for the library. Then we can check - # whether they linked in statically or dynamically with ldd. - $rm conftest.c - cat > conftest.c </dev/null` - for potent_lib in $potential_libs; do - # Follow soft links. - if ls -lLd "$potent_lib" 2>/dev/null \ - | grep " -> " >/dev/null; then - continue - fi - # The statement above tries to avoid entering an - # endless loop below, in case of cyclic links. - # We might still enter an endless loop, since a link - # loop can be closed while we follow links, - # but so what? - potlib="$potent_lib" - while test -h "$potlib" 2>/dev/null; do - potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` - case $potliblink in - [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; - *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; - esac - done - if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \ - | ${SED} 10q \ - | $EGREP "$file_magic_regex" > /dev/null; then - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - break 2 - fi - done - done - fi - if test -n "$a_deplib" ; then - droppeddeps=yes - $echo - $echo "*** Warning: linker path does not have real file for library $a_deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because I did check the linker path looking for a file starting" - if test -z "$potlib" ; then - $echo "*** with $libname but no candidates were found. (...for file magic test)" - else - $echo "*** with $libname and none of the candidates passed a file format test" - $echo "*** using a file magic. Last file checked: $potlib" - fi - fi - else - # Add a -L argument. - newdeplibs="$newdeplibs $a_deplib" - fi - done # Gone through all deplibs. - ;; - match_pattern*) - set dummy $deplibs_check_method - match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` - for a_deplib in $deplibs; do - name=`expr $a_deplib : '-l\(.*\)'` - # If $name is empty we are operating on a -L argument. - if test -n "$name" && test "$name" != "0"; then - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - case " $predeps $postdeps " in - *" $a_deplib "*) - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - ;; - esac - fi - if test -n "$a_deplib" ; then - libname=`eval \\$echo \"$libname_spec\"` - for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do - potential_libs=`ls $i/$libname[.-]* 2>/dev/null` - for potent_lib in $potential_libs; do - potlib="$potent_lib" # see symlink-check above in file_magic test - if eval $echo \"$potent_lib\" 2>/dev/null \ - | ${SED} 10q \ - | $EGREP "$match_pattern_regex" > /dev/null; then - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - break 2 - fi - done - done - fi - if test -n "$a_deplib" ; then - droppeddeps=yes - $echo - $echo "*** Warning: linker path does not have real file for library $a_deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because I did check the linker path looking for a file starting" - if test -z "$potlib" ; then - $echo "*** with $libname but no candidates were found. (...for regex pattern test)" - else - $echo "*** with $libname and none of the candidates passed a file format test" - $echo "*** using a regex pattern. Last file checked: $potlib" - fi - fi - else - # Add a -L argument. - newdeplibs="$newdeplibs $a_deplib" - fi - done # Gone through all deplibs. - ;; - none | unknown | *) - newdeplibs="" - tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \ - -e 's/ -[LR][^ ]*//g'` - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - for i in $predeps $postdeps ; do - # can't use Xsed below, because $i might contain '/' - tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"` - done - fi - if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \ - | grep . >/dev/null; then - $echo - if test "X$deplibs_check_method" = "Xnone"; then - $echo "*** Warning: inter-library dependencies are not supported in this platform." - else - $echo "*** Warning: inter-library dependencies are not known to be supported." - fi - $echo "*** All declared inter-library dependencies are being dropped." - droppeddeps=yes - fi - ;; - esac - versuffix=$versuffix_save - major=$major_save - release=$release_save - libname=$libname_save - name=$name_save - - case $host in - *-*-rhapsody* | *-*-darwin1.[012]) - # On Rhapsody replace the C library is the System framework - newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'` - ;; - esac - - if test "$droppeddeps" = yes; then - if test "$module" = yes; then - $echo - $echo "*** Warning: libtool could not satisfy all declared inter-library" - $echo "*** dependencies of module $libname. Therefore, libtool will create" - $echo "*** a static module, that should work as long as the dlopening" - $echo "*** application is linked with the -dlopen flag." - if test -z "$global_symbol_pipe"; then - $echo - $echo "*** However, this would only work if libtool was able to extract symbol" - $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" - $echo "*** not find such a program. So, this module is probably useless." - $echo "*** \`nm' from GNU binutils and a full rebuild may help." - fi - if test "$build_old_libs" = no; then - oldlibs="$output_objdir/$libname.$libext" - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - else - $echo "*** The inter-library dependencies that have been dropped here will be" - $echo "*** automatically added whenever a program is linked with this library" - $echo "*** or is declared to -dlopen it." - - if test "$allow_undefined" = no; then - $echo - $echo "*** Since this library must not contain undefined symbols," - $echo "*** because either the platform does not support them or" - $echo "*** it was explicitly requested with -no-undefined," - $echo "*** libtool will only create a static version of it." - if test "$build_old_libs" = no; then - oldlibs="$output_objdir/$libname.$libext" - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - fi - fi - fi - # Done checking deplibs! - deplibs=$newdeplibs - fi - - - # move library search paths that coincide with paths to not yet - # installed libraries to the beginning of the library search list - new_libs= - for path in $notinst_path; do - case " $new_libs " in - *" -L$path/$objdir "*) ;; - *) - case " $deplibs " in - *" -L$path/$objdir "*) - new_libs="$new_libs -L$path/$objdir" ;; - esac - ;; - esac - done - for deplib in $deplibs; do - case $deplib in - -L*) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$new_libs $deplib" ;; - esac - ;; - *) new_libs="$new_libs $deplib" ;; - esac - done - deplibs="$new_libs" - - - # All the library-specific variables (install_libdir is set above). - library_names= - old_library= - dlname= - - # Test again, we may have decided not to build it any more - if test "$build_libtool_libs" = yes; then - if test "$hardcode_into_libs" = yes; then - # Hardcode the library paths - hardcode_libdirs= - dep_rpath= - rpath="$finalize_rpath" - test "$mode" != relink && rpath="$compile_rpath$rpath" - for libdir in $rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - dep_rpath="$dep_rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$perm_rpath " in - *" $libdir "*) ;; - *) perm_rpath="$perm_rpath $libdir" ;; - esac - fi - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - if test -n "$hardcode_libdir_flag_spec_ld"; then - case $archive_cmds in - *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; - *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; - esac - else - eval dep_rpath=\"$hardcode_libdir_flag_spec\" - fi - fi - if test -n "$runpath_var" && test -n "$perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $perm_rpath; do - rpath="$rpath$dir:" - done - eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" - fi - test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" - fi - - shlibpath="$finalize_shlibpath" - test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" - if test -n "$shlibpath"; then - eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" - fi - - # Get the real and link names of the library. - eval shared_ext=\"$shrext_cmds\" - eval library_names=\"$library_names_spec\" - set dummy $library_names - realname="$2" - shift; shift - - if test -n "$soname_spec"; then - eval soname=\"$soname_spec\" - else - soname="$realname" - fi - if test -z "$dlname"; then - dlname=$soname - fi - - lib="$output_objdir/$realname" - linknames= - for link - do - linknames="$linknames $link" - done - - # Use standard objects if they are pic - test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - - # Prepare the list of exported symbols - if test -z "$export_symbols"; then - if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then - $show "generating symbol list for \`$libname.la'" - export_symbols="$output_objdir/$libname.exp" - $run $rm $export_symbols - cmds=$export_symbols_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - if len=`expr "X$cmd" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - $show "$cmd" - $run eval "$cmd" || exit $? - skipped_export=false - else - # The command line is too long to execute in one step. - $show "using reloadable object file for export list..." - skipped_export=: - # Break out early, otherwise skipped_export may be - # set to false by a later but shorter cmd. - break - fi - done - IFS="$save_ifs" - if test -n "$export_symbols_regex"; then - $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"" - $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' - $show "$mv \"${export_symbols}T\" \"$export_symbols\"" - $run eval '$mv "${export_symbols}T" "$export_symbols"' - fi - fi - fi - - if test -n "$export_symbols" && test -n "$include_expsyms"; then - $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"' - fi - - tmp_deplibs= - for test_deplib in $deplibs; do - case " $convenience " in - *" $test_deplib "*) ;; - *) - tmp_deplibs="$tmp_deplibs $test_deplib" - ;; - esac - done - deplibs="$tmp_deplibs" - - if test -n "$convenience"; then - if test -n "$whole_archive_flag_spec"; then - save_libobjs=$libobjs - eval libobjs=\"\$libobjs $whole_archive_flag_spec\" - else - gentop="$output_objdir/${outputname}x" - generated="$generated $gentop" - - func_extract_archives $gentop $convenience - libobjs="$libobjs $func_extract_archives_result" - fi - fi - - if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then - eval flag=\"$thread_safe_flag_spec\" - linker_flags="$linker_flags $flag" - fi - - # Make a backup of the uninstalled library when relinking - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $? - fi - - # Do each of the archive commands. - if test "$module" = yes && test -n "$module_cmds" ; then - if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then - eval test_cmds=\"$module_expsym_cmds\" - cmds=$module_expsym_cmds - else - eval test_cmds=\"$module_cmds\" - cmds=$module_cmds - fi - else - if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then - eval test_cmds=\"$archive_expsym_cmds\" - cmds=$archive_expsym_cmds - else - eval test_cmds=\"$archive_cmds\" - cmds=$archive_cmds - fi - fi - - if test "X$skipped_export" != "X:" && - len=`expr "X$test_cmds" : ".*" 2>/dev/null` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - : - else - # The command line is too long to link in one step, link piecewise. - $echo "creating reloadable object files..." - - # Save the value of $output and $libobjs because we want to - # use them later. If we have whole_archive_flag_spec, we - # want to use save_libobjs as it was before - # whole_archive_flag_spec was expanded, because we can't - # assume the linker understands whole_archive_flag_spec. - # This may have to be revisited, in case too many - # convenience libraries get linked in and end up exceeding - # the spec. - if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then - save_libobjs=$libobjs - fi - save_output=$output - output_la=`$echo "X$output" | $Xsed -e "$basename"` - - # Clear the reloadable object creation command queue and - # initialize k to one. - test_cmds= - concat_cmds= - objlist= - delfiles= - last_robj= - k=1 - output=$output_objdir/$output_la-${k}.$objext - # Loop over the list of objects to be linked. - for obj in $save_libobjs - do - eval test_cmds=\"$reload_cmds $objlist $last_robj\" - if test "X$objlist" = X || - { len=`expr "X$test_cmds" : ".*" 2>/dev/null` && - test "$len" -le "$max_cmd_len"; }; then - objlist="$objlist $obj" - else - # The command $test_cmds is almost too long, add a - # command to the queue. - if test "$k" -eq 1 ; then - # The first file doesn't have a previous command to add. - eval concat_cmds=\"$reload_cmds $objlist $last_robj\" - else - # All subsequent reloadable object files will link in - # the last one created. - eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\" - fi - last_robj=$output_objdir/$output_la-${k}.$objext - k=`expr $k + 1` - output=$output_objdir/$output_la-${k}.$objext - objlist=$obj - len=1 - fi - done - # Handle the remaining objects by creating one last - # reloadable object file. All subsequent reloadable object - # files will link in the last one created. - test -z "$concat_cmds" || concat_cmds=$concat_cmds~ - eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" - - if ${skipped_export-false}; then - $show "generating symbol list for \`$libname.la'" - export_symbols="$output_objdir/$libname.exp" - $run $rm $export_symbols - libobjs=$output - # Append the command to create the export file. - eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\" - fi - - # Set up a command to remove the reloadable object files - # after they are used. - i=0 - while test "$i" -lt "$k" - do - i=`expr $i + 1` - delfiles="$delfiles $output_objdir/$output_la-${i}.$objext" - done - - $echo "creating a temporary reloadable object file: $output" - - # Loop through the commands generated above and execute them. - save_ifs="$IFS"; IFS='~' - for cmd in $concat_cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - libobjs=$output - # Restore the value of output. - output=$save_output - - if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then - eval libobjs=\"\$libobjs $whole_archive_flag_spec\" - fi - # Expand the library linking commands again to reset the - # value of $libobjs for piecewise linking. - - # Do each of the archive commands. - if test "$module" = yes && test -n "$module_cmds" ; then - if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then - cmds=$module_expsym_cmds - else - cmds=$module_cmds - fi - else - if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then - cmds=$archive_expsym_cmds - else - cmds=$archive_cmds - fi - fi - - # Append the command to remove the reloadable object files - # to the just-reset $cmds. - eval cmds=\"\$cmds~\$rm $delfiles\" - fi - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || { - lt_exit=$? - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' - fi - - exit $lt_exit - } - done - IFS="$save_ifs" - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $? - - if test -n "$convenience"; then - if test -z "$whole_archive_flag_spec"; then - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - fi - fi - - exit $EXIT_SUCCESS - fi - - # Create links to the real library. - for linkname in $linknames; do - if test "$realname" != "$linkname"; then - $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)" - $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $? - fi - done - - # If -module or -export-dynamic was specified, set the dlname. - if test "$module" = yes || test "$export_dynamic" = yes; then - # On all known operating systems, these are identical. - dlname="$soname" - fi - fi - ;; - - obj) - case " $deplibs" in - *\ -l* | *\ -L*) - $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 ;; - esac - - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 - fi - - if test -n "$rpath"; then - $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2 - fi - - if test -n "$xrpath"; then - $echo "$modename: warning: \`-R' is ignored for objects" 1>&2 - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for objects" 1>&2 - fi - - case $output in - *.lo) - if test -n "$objs$old_deplibs"; then - $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2 - exit $EXIT_FAILURE - fi - libobj="$output" - obj=`$echo "X$output" | $Xsed -e "$lo2o"` - ;; - *) - libobj= - obj="$output" - ;; - esac - - # Delete the old objects. - $run $rm $obj $libobj - - # Objects from convenience libraries. This assumes - # single-version convenience libraries. Whenever we create - # different ones for PIC/non-PIC, this we'll have to duplicate - # the extraction. - reload_conv_objs= - gentop= - # reload_cmds runs $LD directly, so let us get rid of - # -Wl from whole_archive_flag_spec and hope we can get by with - # turning comma into space.. - wl= - - if test -n "$convenience"; then - if test -n "$whole_archive_flag_spec"; then - eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" - reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` - else - gentop="$output_objdir/${obj}x" - generated="$generated $gentop" - - func_extract_archives $gentop $convenience - reload_conv_objs="$reload_objs $func_extract_archives_result" - fi - fi - - # Create the old-style object. - reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test - - output="$obj" - cmds=$reload_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - # Exit if we aren't doing a library object file. - if test -z "$libobj"; then - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - exit $EXIT_SUCCESS - fi - - if test "$build_libtool_libs" != yes; then - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - # Create an invalid libtool object if no PIC, so that we don't - # accidentally link it into a program. - # $show "echo timestamp > $libobj" - # $run eval "echo timestamp > $libobj" || exit $? - exit $EXIT_SUCCESS - fi - - if test -n "$pic_flag" || test "$pic_mode" != default; then - # Only do commands if we really have different PIC objects. - reload_objs="$libobjs $reload_conv_objs" - output="$libobj" - cmds=$reload_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - exit $EXIT_SUCCESS - ;; - - prog) - case $host in - *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;; - esac - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for programs" 1>&2 - fi - - if test "$preload" = yes; then - if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown && - test "$dlopen_self_static" = unknown; then - $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support." - fi - fi - - case $host in - *-*-rhapsody* | *-*-darwin1.[012]) - # On Rhapsody replace the C library is the System framework - compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'` - finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'` - ;; - esac - - case $host in - *darwin*) - # Don't allow lazy linking, it breaks C++ global constructors - if test "$tagname" = CXX ; then - compile_command="$compile_command ${wl}-bind_at_load" - finalize_command="$finalize_command ${wl}-bind_at_load" - fi - ;; - esac - - - # move library search paths that coincide with paths to not yet - # installed libraries to the beginning of the library search list - new_libs= - for path in $notinst_path; do - case " $new_libs " in - *" -L$path/$objdir "*) ;; - *) - case " $compile_deplibs " in - *" -L$path/$objdir "*) - new_libs="$new_libs -L$path/$objdir" ;; - esac - ;; - esac - done - for deplib in $compile_deplibs; do - case $deplib in - -L*) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$new_libs $deplib" ;; - esac - ;; - *) new_libs="$new_libs $deplib" ;; - esac - done - compile_deplibs="$new_libs" - - - compile_command="$compile_command $compile_deplibs" - finalize_command="$finalize_command $finalize_deplibs" - - if test -n "$rpath$xrpath"; then - # If the user specified any rpath flags, then add them. - for libdir in $rpath $xrpath; do - # This is the magic to use -rpath. - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" ;; - esac - done - fi - - # Now hardcode the library paths - rpath= - hardcode_libdirs= - for libdir in $compile_rpath $finalize_rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - rpath="$rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$perm_rpath " in - *" $libdir "*) ;; - *) perm_rpath="$perm_rpath $libdir" ;; - esac - fi - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'` - case :$dllsearchpath: in - *":$libdir:"*) ;; - *) dllsearchpath="$dllsearchpath:$libdir";; - esac - case :$dllsearchpath: in - *":$testbindir:"*) ;; - *) dllsearchpath="$dllsearchpath:$testbindir";; - esac - ;; - esac - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - eval rpath=\" $hardcode_libdir_flag_spec\" - fi - compile_rpath="$rpath" - - rpath= - hardcode_libdirs= - for libdir in $finalize_rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - rpath="$rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$finalize_perm_rpath " in - *" $libdir "*) ;; - *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; - esac - fi - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - eval rpath=\" $hardcode_libdir_flag_spec\" - fi - finalize_rpath="$rpath" - - if test -n "$libobjs" && test "$build_old_libs" = yes; then - # Transform all the library objects into standard objects. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - fi - - dlsyms= - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - if test -n "$NM" && test -n "$global_symbol_pipe"; then - dlsyms="${outputname}S.c" - else - $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 - fi - fi - - if test -n "$dlsyms"; then - case $dlsyms in - "") ;; - *.c) - # Discover the nlist of each of the dlfiles. - nlist="$output_objdir/${outputname}.nm" - - $show "$rm $nlist ${nlist}S ${nlist}T" - $run $rm "$nlist" "${nlist}S" "${nlist}T" - - # Parse the name list into a source file. - $show "creating $output_objdir/$dlsyms" - - test -z "$run" && $echo > "$output_objdir/$dlsyms" "\ -/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */ -/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */ - -#ifdef __cplusplus -extern \"C\" { -#endif - -/* Prevent the only kind of declaration conflicts we can make. */ -#define lt_preloaded_symbols some_other_symbol - -/* External symbol declarations for the compiler. */\ -" - - if test "$dlself" = yes; then - $show "generating symbol list for \`$output'" - - test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist" - - # Add our own program objects to the symbol list. - progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - for arg in $progfiles; do - $show "extracting global C symbols from \`$arg'" - $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" - done - - if test -n "$exclude_expsyms"; then - $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' - $run eval '$mv "$nlist"T "$nlist"' - fi - - if test -n "$export_symbols_regex"; then - $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' - $run eval '$mv "$nlist"T "$nlist"' - fi - - # Prepare the list of exported symbols - if test -z "$export_symbols"; then - export_symbols="$output_objdir/$outputname.exp" - $run $rm $export_symbols - $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' - case $host in - *cygwin* | *mingw* ) - $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' - $run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' - ;; - esac - else - $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' - $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' - $run eval 'mv "$nlist"T "$nlist"' - case $host in - *cygwin* | *mingw* ) - $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' - $run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' - ;; - esac - fi - fi - - for arg in $dlprefiles; do - $show "extracting global C symbols from \`$arg'" - name=`$echo "$arg" | ${SED} -e 's%^.*/%%'` - $run eval '$echo ": $name " >> "$nlist"' - $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" - done - - if test -z "$run"; then - # Make sure we have at least an empty file. - test -f "$nlist" || : > "$nlist" - - if test -n "$exclude_expsyms"; then - $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T - $mv "$nlist"T "$nlist" - fi - - # Try sorting and uniquifying the output. - if grep -v "^: " < "$nlist" | - if sort -k 3 /dev/null 2>&1; then - sort -k 3 - else - sort +2 - fi | - uniq > "$nlist"S; then - : - else - grep -v "^: " < "$nlist" > "$nlist"S - fi - - if test -f "$nlist"S; then - eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"' - else - $echo '/* NONE */' >> "$output_objdir/$dlsyms" - fi - - $echo >> "$output_objdir/$dlsyms" "\ - -#undef lt_preloaded_symbols - -#if defined (__STDC__) && __STDC__ -# define lt_ptr void * -#else -# define lt_ptr char * -# define const -#endif - -/* The mapping between symbol names and symbols. */ -" - - case $host in - *cygwin* | *mingw* ) - $echo >> "$output_objdir/$dlsyms" "\ -/* DATA imports from DLLs on WIN32 can't be const, because - runtime relocations are performed -- see ld's documentation - on pseudo-relocs */ -struct { -" - ;; - * ) - $echo >> "$output_objdir/$dlsyms" "\ -const struct { -" - ;; - esac - - - $echo >> "$output_objdir/$dlsyms" "\ - const char *name; - lt_ptr address; -} -lt_preloaded_symbols[] = -{\ -" - - eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms" - - $echo >> "$output_objdir/$dlsyms" "\ - {0, (lt_ptr) 0} -}; - -/* This works around a problem in FreeBSD linker */ -#ifdef FREEBSD_WORKAROUND -static const void *lt_preloaded_setup() { - return lt_preloaded_symbols; -} -#endif - -#ifdef __cplusplus -} -#endif\ -" - fi - - pic_flag_for_symtable= - case $host in - # compiling the symbol table file with pic_flag works around - # a FreeBSD bug that causes programs to crash when -lm is - # linked before any other PIC object. But we must not use - # pic_flag when linking with -static. The problem exists in - # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. - *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) - case "$compile_command " in - *" -static "*) ;; - *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";; - esac;; - *-*-hpux*) - case "$compile_command " in - *" -static "*) ;; - *) pic_flag_for_symtable=" $pic_flag";; - esac - esac - - # Now compile the dynamic symbol file. - $show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")" - $run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $? - - # Clean up the generated files. - $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T" - $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T" - - # Transform the symbol file into the correct name. - case $host in - *cygwin* | *mingw* ) - if test -f "$output_objdir/${outputname}.def" ; then - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` - else - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - fi - ;; - * ) - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - ;; - esac - ;; - *) - $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 - exit $EXIT_FAILURE - ;; - esac - else - # We keep going just in case the user didn't refer to - # lt_preloaded_symbols. The linker will fail if global_symbol_pipe - # really was required. - - # Nullify the symbol file. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` - fi - - if test "$need_relink" = no || test "$build_libtool_libs" != yes; then - # Replace the output file specification. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$output"'%g' | $NL2SP` - link_command="$compile_command$compile_rpath" - - # We have no uninstalled library dependencies, so finalize right now. - $show "$link_command" - $run eval "$link_command" - exit_status=$? - - # Delete the generated files. - if test -n "$dlsyms"; then - $show "$rm $output_objdir/${outputname}S.${objext}" - $run $rm "$output_objdir/${outputname}S.${objext}" - fi - - exit $exit_status - fi - - if test -n "$shlibpath_var"; then - # We should set the shlibpath_var - rpath= - for dir in $temp_rpath; do - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) - # Absolute path. - rpath="$rpath$dir:" - ;; - *) - # Relative path: add a thisdir entry. - rpath="$rpath\$thisdir/$dir:" - ;; - esac - done - temp_rpath="$rpath" - fi - - if test -n "$compile_shlibpath$finalize_shlibpath"; then - compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" - fi - if test -n "$finalize_shlibpath"; then - finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" - fi - - compile_var= - finalize_var= - if test -n "$runpath_var"; then - if test -n "$perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $perm_rpath; do - rpath="$rpath$dir:" - done - compile_var="$runpath_var=\"$rpath\$$runpath_var\" " - fi - if test -n "$finalize_perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $finalize_perm_rpath; do - rpath="$rpath$dir:" - done - finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " - fi - fi - - if test "$no_install" = yes; then - # We don't need to create a wrapper script. - link_command="$compile_var$compile_command$compile_rpath" - # Replace the output file specification. - link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` - # Delete the old output file. - $run $rm $output - # Link the executable and exit - $show "$link_command" - $run eval "$link_command" || exit $? - exit $EXIT_SUCCESS - fi - - if test "$hardcode_action" = relink; then - # Fast installation is not supported - link_command="$compile_var$compile_command$compile_rpath" - relink_command="$finalize_var$finalize_command$finalize_rpath" - - $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2 - $echo "$modename: \`$output' will be relinked during installation" 1>&2 - else - if test "$fast_install" != no; then - link_command="$finalize_var$compile_command$finalize_rpath" - if test "$fast_install" = yes; then - relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $SP2NL | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g' | $NL2SP` - else - # fast_install is set to needless - relink_command= - fi - else - link_command="$compile_var$compile_command$compile_rpath" - relink_command="$finalize_var$finalize_command$finalize_rpath" - fi - fi - - # Replace the output file specification. - link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` - - # Delete the old output files. - $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname - - $show "$link_command" - $run eval "$link_command" || exit $? - - # Now create the wrapper script. - $show "creating $output" - - # Quote the relink command for shipping. - if test -n "$relink_command"; then - # Preserve any variables that may affect compiler behavior - for var in $variables_saved_for_relink; do - if eval test -z \"\${$var+set}\"; then - relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" - elif eval var_value=\$$var; test -z "$var_value"; then - relink_command="$var=; export $var; $relink_command" - else - var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` - relink_command="$var=\"$var_value\"; export $var; $relink_command" - fi - done - relink_command="(cd `pwd`; $relink_command)" - relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` - fi - - # Quote $echo for shipping. - if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then - case $progpath in - [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; - *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; - esac - qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"` - else - qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"` - fi - - # Only actually do things if our run command is non-null. - if test -z "$run"; then - # win32 will think the script is a binary if it has - # a .exe suffix, so we strip it off here. - case $output in - *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;; - esac - # test for cygwin because mv fails w/o .exe extensions - case $host in - *cygwin*) - exeext=.exe - outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;; - *) exeext= ;; - esac - case $host in - *cygwin* | *mingw* ) - output_name=`basename $output` - output_path=`dirname $output` - cwrappersource="$output_path/$objdir/lt-$output_name.c" - cwrapper="$output_path/$output_name.exe" - $rm $cwrappersource $cwrapper - trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 - - cat > $cwrappersource <> $cwrappersource<<"EOF" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(PATH_MAX) -# define LT_PATHMAX PATH_MAX -#elif defined(MAXPATHLEN) -# define LT_PATHMAX MAXPATHLEN -#else -# define LT_PATHMAX 1024 -#endif - -#ifndef DIR_SEPARATOR -# define DIR_SEPARATOR '/' -# define PATH_SEPARATOR ':' -#endif - -#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ - defined (__OS2__) -# define HAVE_DOS_BASED_FILE_SYSTEM -# ifndef DIR_SEPARATOR_2 -# define DIR_SEPARATOR_2 '\\' -# endif -# ifndef PATH_SEPARATOR_2 -# define PATH_SEPARATOR_2 ';' -# endif -#endif - -#ifndef DIR_SEPARATOR_2 -# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) -#else /* DIR_SEPARATOR_2 */ -# define IS_DIR_SEPARATOR(ch) \ - (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) -#endif /* DIR_SEPARATOR_2 */ - -#ifndef PATH_SEPARATOR_2 -# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) -#else /* PATH_SEPARATOR_2 */ -# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) -#endif /* PATH_SEPARATOR_2 */ - -#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) -#define XFREE(stale) do { \ - if (stale) { free ((void *) stale); stale = 0; } \ -} while (0) - -/* -DDEBUG is fairly common in CFLAGS. */ -#undef DEBUG -#if defined DEBUGWRAPPER -# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__) -#else -# define DEBUG(format, ...) -#endif - -const char *program_name = NULL; - -void * xmalloc (size_t num); -char * xstrdup (const char *string); -const char * base_name (const char *name); -char * find_executable(const char *wrapper); -int check_executable(const char *path); -char * strendzap(char *str, const char *pat); -void lt_fatal (const char *message, ...); - -int -main (int argc, char *argv[]) -{ - char **newargz; - int i; - - program_name = (char *) xstrdup (base_name (argv[0])); - DEBUG("(main) argv[0] : %s\n",argv[0]); - DEBUG("(main) program_name : %s\n",program_name); - newargz = XMALLOC(char *, argc+2); -EOF - - cat >> $cwrappersource <> $cwrappersource <<"EOF" - newargz[1] = find_executable(argv[0]); - if (newargz[1] == NULL) - lt_fatal("Couldn't find %s", argv[0]); - DEBUG("(main) found exe at : %s\n",newargz[1]); - /* we know the script has the same name, without the .exe */ - /* so make sure newargz[1] doesn't end in .exe */ - strendzap(newargz[1],".exe"); - for (i = 1; i < argc; i++) - newargz[i+1] = xstrdup(argv[i]); - newargz[argc+1] = NULL; - - for (i=0; i> $cwrappersource <> $cwrappersource <> $cwrappersource <<"EOF" - return 127; -} - -void * -xmalloc (size_t num) -{ - void * p = (void *) malloc (num); - if (!p) - lt_fatal ("Memory exhausted"); - - return p; -} - -char * -xstrdup (const char *string) -{ - return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL -; -} - -const char * -base_name (const char *name) -{ - const char *base; - -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - /* Skip over the disk name in MSDOS pathnames. */ - if (isalpha ((unsigned char)name[0]) && name[1] == ':') - name += 2; -#endif - - for (base = name; *name; name++) - if (IS_DIR_SEPARATOR (*name)) - base = name + 1; - return base; -} - -int -check_executable(const char * path) -{ - struct stat st; - - DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!"); - if ((!path) || (!*path)) - return 0; - - if ((stat (path, &st) >= 0) && - ( - /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */ -#if defined (S_IXOTH) - ((st.st_mode & S_IXOTH) == S_IXOTH) || -#endif -#if defined (S_IXGRP) - ((st.st_mode & S_IXGRP) == S_IXGRP) || -#endif - ((st.st_mode & S_IXUSR) == S_IXUSR)) - ) - return 1; - else - return 0; -} - -/* Searches for the full path of the wrapper. Returns - newly allocated full path name if found, NULL otherwise */ -char * -find_executable (const char* wrapper) -{ - int has_slash = 0; - const char* p; - const char* p_next; - /* static buffer for getcwd */ - char tmp[LT_PATHMAX + 1]; - int tmp_len; - char* concat_name; - - DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"); - - if ((wrapper == NULL) || (*wrapper == '\0')) - return NULL; - - /* Absolute path? */ -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':') - { - concat_name = xstrdup (wrapper); - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - } - else - { -#endif - if (IS_DIR_SEPARATOR (wrapper[0])) - { - concat_name = xstrdup (wrapper); - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - } -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - } -#endif - - for (p = wrapper; *p; p++) - if (*p == '/') - { - has_slash = 1; - break; - } - if (!has_slash) - { - /* no slashes; search PATH */ - const char* path = getenv ("PATH"); - if (path != NULL) - { - for (p = path; *p; p = p_next) - { - const char* q; - size_t p_len; - for (q = p; *q; q++) - if (IS_PATH_SEPARATOR(*q)) - break; - p_len = q - p; - p_next = (*q == '\0' ? q : q + 1); - if (p_len == 0) - { - /* empty path: current directory */ - if (getcwd (tmp, LT_PATHMAX) == NULL) - lt_fatal ("getcwd failed"); - tmp_len = strlen(tmp); - concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); - memcpy (concat_name, tmp, tmp_len); - concat_name[tmp_len] = '/'; - strcpy (concat_name + tmp_len + 1, wrapper); - } - else - { - concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1); - memcpy (concat_name, p, p_len); - concat_name[p_len] = '/'; - strcpy (concat_name + p_len + 1, wrapper); - } - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - } - } - /* not found in PATH; assume curdir */ - } - /* Relative path | not found in path: prepend cwd */ - if (getcwd (tmp, LT_PATHMAX) == NULL) - lt_fatal ("getcwd failed"); - tmp_len = strlen(tmp); - concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); - memcpy (concat_name, tmp, tmp_len); - concat_name[tmp_len] = '/'; - strcpy (concat_name + tmp_len + 1, wrapper); - - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - return NULL; -} - -char * -strendzap(char *str, const char *pat) -{ - size_t len, patlen; - - assert(str != NULL); - assert(pat != NULL); - - len = strlen(str); - patlen = strlen(pat); - - if (patlen <= len) - { - str += len - patlen; - if (strcmp(str, pat) == 0) - *str = '\0'; - } - return str; -} - -static void -lt_error_core (int exit_status, const char * mode, - const char * message, va_list ap) -{ - fprintf (stderr, "%s: %s: ", program_name, mode); - vfprintf (stderr, message, ap); - fprintf (stderr, ".\n"); - - if (exit_status >= 0) - exit (exit_status); -} - -void -lt_fatal (const char *message, ...) -{ - va_list ap; - va_start (ap, message); - lt_error_core (EXIT_FAILURE, "FATAL", message, ap); - va_end (ap); -} -EOF - # we should really use a build-platform specific compiler - # here, but OTOH, the wrappers (shell script and this C one) - # are only useful if you want to execute the "real" binary. - # Since the "real" binary is built for $host, then this - # wrapper might as well be built for $host, too. - $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource - ;; - esac - $rm $output - trap "$rm $output; exit $EXIT_FAILURE" 1 2 15 - - $echo > $output "\ -#! $SHELL - -# $output - temporary wrapper script for $objdir/$outputname -# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP -# -# The $output program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -Xsed='${SED} -e 1s/^X//' -sed_quote_subst='$sed_quote_subst' - -# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). -if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which - # is contrary to our usage. Disable this feature. - alias -g '\${1+\"\$@\"}'='\"\$@\"' - setopt NO_GLOB_SUBST -else - case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command=\"$relink_command\" - -# This environment variable determines our operation mode. -if test \"\$libtool_install_magic\" = \"$magic\"; then - # install mode needs the following variable: - notinst_deplibs='$notinst_deplibs' -else - # When we are sourced in execute mode, \$file and \$echo are already set. - if test \"\$libtool_execute_magic\" != \"$magic\"; then - echo=\"$qecho\" - file=\"\$0\" - # Make sure echo works. - if test \"X\$1\" = X--no-reexec; then - # Discard the --no-reexec flag, and continue. - shift - elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then - # Yippee, \$echo works! - : - else - # Restart under the correct shell, and then maybe \$echo will work. - exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} - fi - fi\ -" - $echo >> $output "\ - - # Find the directory that this script lives in. - thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` - test \"x\$thisdir\" = \"x\$file\" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` - while test -n \"\$file\"; do - destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` - - # If there was a directory component, then change thisdir. - if test \"x\$destdir\" != \"x\$file\"; then - case \"\$destdir\" in - [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; - *) thisdir=\"\$thisdir/\$destdir\" ;; - esac - fi - - file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\` - file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` - done - - # Try to get the absolute directory name. - absdir=\`cd \"\$thisdir\" && pwd\` - test -n \"\$absdir\" && thisdir=\"\$absdir\" -" - - if test "$fast_install" = yes; then - $echo >> $output "\ - program=lt-'$outputname'$exeext - progdir=\"\$thisdir/$objdir\" - - if test ! -f \"\$progdir/\$program\" || \\ - { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ - test \"X\$file\" != \"X\$progdir/\$program\"; }; then - - file=\"\$\$-\$program\" - - if test ! -d \"\$progdir\"; then - $mkdir \"\$progdir\" - else - $rm \"\$progdir/\$file\" - fi" - - $echo >> $output "\ - - # relink executable if necessary - if test -n \"\$relink_command\"; then - if relink_command_output=\`eval \$relink_command 2>&1\`; then : - else - $echo \"\$relink_command_output\" >&2 - $rm \"\$progdir/\$file\" - exit $EXIT_FAILURE - fi - fi - - $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || - { $rm \"\$progdir/\$program\"; - $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; } - $rm \"\$progdir/\$file\" - fi" - else - $echo >> $output "\ - program='$outputname' - progdir=\"\$thisdir/$objdir\" -" - fi - - $echo >> $output "\ - - if test -f \"\$progdir/\$program\"; then" - - # Export our shlibpath_var if we have one. - if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then - $echo >> $output "\ - # Add our own library path to $shlibpath_var - $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" - - # Some systems cannot cope with colon-terminated $shlibpath_var - # The second colon is a workaround for a bug in BeOS R4 sed - $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` - - export $shlibpath_var -" - fi - - # fixup the dll searchpath if we need to. - if test -n "$dllsearchpath"; then - $echo >> $output "\ - # Add the dll search path components to the executable PATH - PATH=$dllsearchpath:\$PATH -" - fi - - $echo >> $output "\ - if test \"\$libtool_execute_magic\" != \"$magic\"; then - # Run the actual program with our arguments. -" - case $host in - # Backslashes separate directories on plain windows - *-*-mingw | *-*-os2*) - $echo >> $output "\ - exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} -" - ;; - - *) - $echo >> $output "\ - exec \"\$progdir/\$program\" \${1+\"\$@\"} -" - ;; - esac - $echo >> $output "\ - \$echo \"\$0: cannot exec \$program \$*\" - exit $EXIT_FAILURE - fi - else - # The program doesn't exist. - \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 - \$echo \"This script is just a wrapper for \$program.\" 1>&2 - $echo \"See the $PACKAGE documentation for more information.\" 1>&2 - exit $EXIT_FAILURE - fi -fi\ -" - chmod +x $output - fi - exit $EXIT_SUCCESS - ;; - esac - - # See if we need to build an old-fashioned archive. - for oldlib in $oldlibs; do - - if test "$build_libtool_libs" = convenience; then - oldobjs="$libobjs_save" - addlibs="$convenience" - build_libtool_libs=no - else - if test "$build_libtool_libs" = module; then - oldobjs="$libobjs_save" - build_libtool_libs=no - else - oldobjs="$old_deplibs $non_pic_objects" - fi - addlibs="$old_convenience" - fi - - if test -n "$addlibs"; then - gentop="$output_objdir/${outputname}x" - generated="$generated $gentop" - - func_extract_archives $gentop $addlibs - oldobjs="$oldobjs $func_extract_archives_result" - fi - - # Do each command in the archive commands. - if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then - cmds=$old_archive_from_new_cmds - else - # POSIX demands no paths to be encoded in archives. We have - # to avoid creating archives with duplicate basenames if we - # might have to extract them afterwards, e.g., when creating a - # static archive out of a convenience library, or when linking - # the entirety of a libtool archive into another (currently - # not supported by libtool). - if (for obj in $oldobjs - do - $echo "X$obj" | $Xsed -e 's%^.*/%%' - done | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "copying selected object files to avoid basename conflicts..." - - if test -z "$gentop"; then - gentop="$output_objdir/${outputname}x" - generated="$generated $gentop" - - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - $show "$mkdir $gentop" - $run $mkdir "$gentop" - exit_status=$? - if test "$exit_status" -ne 0 && test ! -d "$gentop"; then - exit $exit_status - fi - fi - - save_oldobjs=$oldobjs - oldobjs= - counter=1 - for obj in $save_oldobjs - do - objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` - case " $oldobjs " in - " ") oldobjs=$obj ;; - *[\ /]"$objbase "*) - while :; do - # Make sure we don't pick an alternate name that also - # overlaps. - newobj=lt$counter-$objbase - counter=`expr $counter + 1` - case " $oldobjs " in - *[\ /]"$newobj "*) ;; - *) if test ! -f "$gentop/$newobj"; then break; fi ;; - esac - done - $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" - $run ln "$obj" "$gentop/$newobj" || - $run cp "$obj" "$gentop/$newobj" - oldobjs="$oldobjs $gentop/$newobj" - ;; - *) oldobjs="$oldobjs $obj" ;; - esac - done - fi - - eval cmds=\"$old_archive_cmds\" - - if len=`expr "X$cmds" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - cmds=$old_archive_cmds - else - # the command line is too long to link in one step, link in parts - $echo "using piecewise archive linking..." - save_RANLIB=$RANLIB - RANLIB=: - objlist= - concat_cmds= - save_oldobjs=$oldobjs - - # Is there a better way of finding the last object in the list? - for obj in $save_oldobjs - do - last_oldobj=$obj - done - for obj in $save_oldobjs - do - oldobjs="$objlist $obj" - objlist="$objlist $obj" - eval test_cmds=\"$old_archive_cmds\" - if len=`expr "X$test_cmds" : ".*" 2>/dev/null` && - test "$len" -le "$max_cmd_len"; then - : - else - # the above command should be used before it gets too long - oldobjs=$objlist - if test "$obj" = "$last_oldobj" ; then - RANLIB=$save_RANLIB - fi - test -z "$concat_cmds" || concat_cmds=$concat_cmds~ - eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" - objlist= - fi - done - RANLIB=$save_RANLIB - oldobjs=$objlist - if test "X$oldobjs" = "X" ; then - eval cmds=\"\$concat_cmds\" - else - eval cmds=\"\$concat_cmds~\$old_archive_cmds\" - fi - fi - fi - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - eval cmd=\"$cmd\" - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - done - - if test -n "$generated"; then - $show "${rm}r$generated" - $run ${rm}r$generated - fi - - # Now create the libtool archive. - case $output in - *.la) - old_library= - test "$build_old_libs" = yes && old_library="$libname.$libext" - $show "creating $output" - - # Preserve any variables that may affect compiler behavior - for var in $variables_saved_for_relink; do - if eval test -z \"\${$var+set}\"; then - relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" - elif eval var_value=\$$var; test -z "$var_value"; then - relink_command="$var=; export $var; $relink_command" - else - var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` - relink_command="$var=\"$var_value\"; export $var; $relink_command" - fi - done - # Quote the link command for shipping. - relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" - relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` - if test "$hardcode_automatic" = yes ; then - relink_command= - fi - - - # Only create the output if not a dry run. - if test -z "$run"; then - for installed in no yes; do - if test "$installed" = yes; then - if test -z "$install_libdir"; then - break - fi - output="$output_objdir/$outputname"i - # Replace all uninstalled libtool libraries with the installed ones - newdependency_libs= - for deplib in $dependency_libs; do - case $deplib in - *.la) - name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -z "$libdir"; then - $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - newdependency_libs="$newdependency_libs $libdir/$name" - ;; - *) newdependency_libs="$newdependency_libs $deplib" ;; - esac - done - dependency_libs="$newdependency_libs" - newdlfiles= - for lib in $dlfiles; do - name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` - if test -z "$libdir"; then - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - newdlfiles="$newdlfiles $libdir/$name" - done - dlfiles="$newdlfiles" - newdlprefiles= - for lib in $dlprefiles; do - name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` - if test -z "$libdir"; then - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - newdlprefiles="$newdlprefiles $libdir/$name" - done - dlprefiles="$newdlprefiles" - else - newdlfiles= - for lib in $dlfiles; do - case $lib in - [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; - *) abs=`pwd`"/$lib" ;; - esac - newdlfiles="$newdlfiles $abs" - done - dlfiles="$newdlfiles" - newdlprefiles= - for lib in $dlprefiles; do - case $lib in - [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; - *) abs=`pwd`"/$lib" ;; - esac - newdlprefiles="$newdlprefiles $abs" - done - dlprefiles="$newdlprefiles" - fi - $rm $output - # place dlname in correct position for cygwin - tdlname=$dlname - case $host,$output,$installed,$module,$dlname in - *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; - esac - $echo > $output "\ -# $outputname - a libtool library file -# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='$tdlname' - -# Names of this library. -library_names='$library_names' - -# The name of the static archive. -old_library='$old_library' - -# Libraries that this one depends upon. -dependency_libs='$dependency_libs' - -# Version information for $libname. -current=$current -age=$age -revision=$revision - -# Is this an already installed library? -installed=$installed - -# Should we warn about portability when linking against -modules? -shouldnotlink=$module - -# Files to dlopen/dlpreopen -dlopen='$dlfiles' -dlpreopen='$dlprefiles' - -# Directory that this library needs to be installed in: -libdir='$install_libdir'" - if test "$installed" = no && test "$need_relink" = yes; then - $echo >> $output "\ -relink_command=\"$relink_command\"" - fi - done - fi - - # Do a symbolic link so that the libtool archive can be found in - # LD_LIBRARY_PATH before the program is installed. - $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)" - $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $? - ;; - esac - exit $EXIT_SUCCESS - ;; - - # libtool install mode - install) - modename="$modename: install" - - # There may be an optional sh(1) argument at the beginning of - # install_prog (especially on Windows NT). - if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || - # Allow the use of GNU shtool's install command. - $echo "X$nonopt" | grep shtool > /dev/null; then - # Aesthetically quote it. - arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - install_prog="$arg " - arg="$1" - shift - else - install_prog= - arg=$nonopt - fi - - # The real first argument should be the name of the installation program. - # Aesthetically quote it. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - install_prog="$install_prog$arg" - - # We need to accept at least all the BSD install flags. - dest= - files= - opts= - prev= - install_type= - isdir=no - stripme= - for arg - do - if test -n "$dest"; then - files="$files $dest" - dest=$arg - continue - fi - - case $arg in - -d) isdir=yes ;; - -f) - case " $install_prog " in - *[\\\ /]cp\ *) ;; - *) prev=$arg ;; - esac - ;; - -g | -m | -o) prev=$arg ;; - -s) - stripme=" -s" - continue - ;; - -*) - ;; - *) - # If the previous option needed an argument, then skip it. - if test -n "$prev"; then - prev= - else - dest=$arg - continue - fi - ;; - esac - - # Aesthetically quote the argument. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - install_prog="$install_prog $arg" - done - - if test -z "$install_prog"; then - $echo "$modename: you must specify an install program" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - if test -n "$prev"; then - $echo "$modename: the \`$prev' option requires an argument" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - if test -z "$files"; then - if test -z "$dest"; then - $echo "$modename: no file or destination specified" 1>&2 - else - $echo "$modename: you must specify a destination" 1>&2 - fi - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Strip any trailing slash from the destination. - dest=`$echo "X$dest" | $Xsed -e 's%/$%%'` - - # Check to see that the destination is a directory. - test -d "$dest" && isdir=yes - if test "$isdir" = yes; then - destdir="$dest" - destname= - else - destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'` - test "X$destdir" = "X$dest" && destdir=. - destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'` - - # Not a directory, so check to see that there is only one file specified. - set dummy $files - if test "$#" -gt 2; then - $echo "$modename: \`$dest' is not a directory" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - fi - case $destdir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - for file in $files; do - case $file in - *.lo) ;; - *) - $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - esac - done - ;; - esac - - # This variable tells wrapper scripts just to set variables rather - # than running their programs. - libtool_install_magic="$magic" - - staticlibs= - future_libdirs= - current_libdirs= - for file in $files; do - - # Do each installation. - case $file in - *.$libext) - # Do the static libraries later. - staticlibs="$staticlibs $file" - ;; - - *.la) - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$file' is not a valid libtool archive" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - library_names= - old_library= - relink_command= - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Add the libdir to current_libdirs if it is the destination. - if test "X$destdir" = "X$libdir"; then - case "$current_libdirs " in - *" $libdir "*) ;; - *) current_libdirs="$current_libdirs $libdir" ;; - esac - else - # Note the libdir as a future libdir. - case "$future_libdirs " in - *" $libdir "*) ;; - *) future_libdirs="$future_libdirs $libdir" ;; - esac - fi - - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/ - test "X$dir" = "X$file/" && dir= - dir="$dir$objdir" - - if test -n "$relink_command"; then - # Determine the prefix the user has applied to our future dir. - inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"` - - # Don't allow the user to place us outside of our expected - # location b/c this prevents finding dependent libraries that - # are installed to the same prefix. - # At present, this check doesn't affect windows .dll's that - # are installed into $libdir/../bin (currently, that works fine) - # but it's something to keep an eye on. - if test "$inst_prefix_dir" = "$destdir"; then - $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 - exit $EXIT_FAILURE - fi - - if test -n "$inst_prefix_dir"; then - # Stick the inst_prefix_dir data into the link command. - relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%" | $NL2SP` - else - relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%%" | $NL2SP` - fi - - $echo "$modename: warning: relinking \`$file'" 1>&2 - $show "$relink_command" - if $run eval "$relink_command"; then : - else - $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 - exit $EXIT_FAILURE - fi - fi - - # See the names of the shared library. - set dummy $library_names - if test -n "$2"; then - realname="$2" - shift - shift - - srcname="$realname" - test -n "$relink_command" && srcname="$realname"T - - # Install the shared library and build the symlinks. - $show "$install_prog $dir/$srcname $destdir/$realname" - $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $? - if test -n "$stripme" && test -n "$striplib"; then - $show "$striplib $destdir/$realname" - $run eval "$striplib $destdir/$realname" || exit $? - fi - - if test "$#" -gt 0; then - # Delete the old symlinks, and create new ones. - # Try `ln -sf' first, because the `ln' binary might depend on - # the symlink we replace! Solaris /bin/ln does not understand -f, - # so we also need to try rm && ln -s. - for linkname - do - if test "$linkname" != "$realname"; then - $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" - $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" - fi - done - fi - - # Do each command in the postinstall commands. - lib="$destdir/$realname" - cmds=$postinstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || { - lt_exit=$? - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' - fi - - exit $lt_exit - } - done - IFS="$save_ifs" - fi - - # Install the pseudo-library for information purposes. - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - instname="$dir/$name"i - $show "$install_prog $instname $destdir/$name" - $run eval "$install_prog $instname $destdir/$name" || exit $? - - # Maybe install the static library, too. - test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" - ;; - - *.lo) - # Install (i.e. copy) a libtool object. - - # Figure out destination file name, if it wasn't already specified. - if test -n "$destname"; then - destfile="$destdir/$destname" - else - destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - destfile="$destdir/$destfile" - fi - - # Deduce the name of the destination old-style object file. - case $destfile in - *.lo) - staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"` - ;; - *.$objext) - staticdest="$destfile" - destfile= - ;; - *) - $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - # Install the libtool object if requested. - if test -n "$destfile"; then - $show "$install_prog $file $destfile" - $run eval "$install_prog $file $destfile" || exit $? - fi - - # Install the old object if enabled. - if test "$build_old_libs" = yes; then - # Deduce the name of the old-style object file. - staticobj=`$echo "X$file" | $Xsed -e "$lo2o"` - - $show "$install_prog $staticobj $staticdest" - $run eval "$install_prog \$staticobj \$staticdest" || exit $? - fi - exit $EXIT_SUCCESS - ;; - - *) - # Figure out destination file name, if it wasn't already specified. - if test -n "$destname"; then - destfile="$destdir/$destname" - else - destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - destfile="$destdir/$destfile" - fi - - # If the file is missing, and there is a .exe on the end, strip it - # because it is most likely a libtool script we actually want to - # install - stripped_ext="" - case $file in - *.exe) - if test ! -f "$file"; then - file=`$echo $file|${SED} 's,.exe$,,'` - stripped_ext=".exe" - fi - ;; - esac - - # Do a test to see if this is really a libtool program. - case $host in - *cygwin*|*mingw*) - wrapper=`$echo $file | ${SED} -e 's,.exe$,,'` - ;; - *) - wrapper=$file - ;; - esac - if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then - notinst_deplibs= - relink_command= - - # Note that it is not necessary on cygwin/mingw to append a dot to - # foo even if both foo and FILE.exe exist: automatic-append-.exe - # behavior happens only for exec(3), not for open(2)! Also, sourcing - # `FILE.' does not work on cygwin managed mounts. - # - # If there is no directory component, then add one. - case $wrapper in - */* | *\\*) . ${wrapper} ;; - *) . ./${wrapper} ;; - esac - - # Check the variables that should have been set. - if test -z "$notinst_deplibs"; then - $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2 - exit $EXIT_FAILURE - fi - - finalize=yes - for lib in $notinst_deplibs; do - # Check to see that each library is installed. - libdir= - if test -f "$lib"; then - # If there is no directory component, then add one. - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - fi - libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test - if test -n "$libdir" && test ! -f "$libfile"; then - $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2 - finalize=no - fi - done - - relink_command= - # Note that it is not necessary on cygwin/mingw to append a dot to - # foo even if both foo and FILE.exe exist: automatic-append-.exe - # behavior happens only for exec(3), not for open(2)! Also, sourcing - # `FILE.' does not work on cygwin managed mounts. - # - # If there is no directory component, then add one. - case $wrapper in - */* | *\\*) . ${wrapper} ;; - *) . ./${wrapper} ;; - esac - - outputname= - if test "$fast_install" = no && test -n "$relink_command"; then - if test "$finalize" = yes && test -z "$run"; then - tmpdir=`func_mktempdir` - file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` - outputname="$tmpdir/$file" - # Replace the output file specification. - relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g' | $NL2SP` - - $show "$relink_command" - if $run eval "$relink_command"; then : - else - $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 - ${rm}r "$tmpdir" - continue - fi - file="$outputname" - else - $echo "$modename: warning: cannot relink \`$file'" 1>&2 - fi - else - # Install the binary that we compiled earlier. - file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` - fi - fi - - # remove .exe since cygwin /usr/bin/install will append another - # one anyway - case $install_prog,$host in - */usr/bin/install*,*cygwin*) - case $file:$destfile in - *.exe:*.exe) - # this is ok - ;; - *.exe:*) - destfile=$destfile.exe - ;; - *:*.exe) - destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'` - ;; - esac - ;; - esac - $show "$install_prog$stripme $file $destfile" - $run eval "$install_prog\$stripme \$file \$destfile" || exit $? - test -n "$outputname" && ${rm}r "$tmpdir" - ;; - esac - done - - for file in $staticlibs; do - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - - # Set up the ranlib parameters. - oldlib="$destdir/$name" - - $show "$install_prog $file $oldlib" - $run eval "$install_prog \$file \$oldlib" || exit $? - - if test -n "$stripme" && test -n "$old_striplib"; then - $show "$old_striplib $oldlib" - $run eval "$old_striplib $oldlib" || exit $? - fi - - # Do each command in the postinstall commands. - cmds=$old_postinstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - done - - if test -n "$future_libdirs"; then - $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2 - fi - - if test -n "$current_libdirs"; then - # Maybe just do a dry run. - test -n "$run" && current_libdirs=" -n$current_libdirs" - exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' - else - exit $EXIT_SUCCESS - fi - ;; - - # libtool finish mode - finish) - modename="$modename: finish" - libdirs="$nonopt" - admincmds= - - if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then - for dir - do - libdirs="$libdirs $dir" - done - - for libdir in $libdirs; do - if test -n "$finish_cmds"; then - # Do each command in the finish commands. - cmds=$finish_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || admincmds="$admincmds - $cmd" - done - IFS="$save_ifs" - fi - if test -n "$finish_eval"; then - # Do the single finish_eval. - eval cmds=\"$finish_eval\" - $run eval "$cmds" || admincmds="$admincmds - $cmds" - fi - done - fi - - # Exit here if they wanted silent mode. - test "$show" = : && exit $EXIT_SUCCESS - - $echo "X----------------------------------------------------------------------" | $Xsed - $echo "Libraries have been installed in:" - for libdir in $libdirs; do - $echo " $libdir" - done - $echo - $echo "If you ever happen to want to link against installed libraries" - $echo "in a given directory, LIBDIR, you must either use libtool, and" - $echo "specify the full pathname of the library, or use the \`-LLIBDIR'" - $echo "flag during linking and do at least one of the following:" - if test -n "$shlibpath_var"; then - $echo " - add LIBDIR to the \`$shlibpath_var' environment variable" - $echo " during execution" - fi - if test -n "$runpath_var"; then - $echo " - add LIBDIR to the \`$runpath_var' environment variable" - $echo " during linking" - fi - if test -n "$hardcode_libdir_flag_spec"; then - libdir=LIBDIR - eval flag=\"$hardcode_libdir_flag_spec\" - - $echo " - use the \`$flag' linker flag" - fi - if test -n "$admincmds"; then - $echo " - have your system administrator run these commands:$admincmds" - fi - if test -f /etc/ld.so.conf; then - $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" - fi - $echo - $echo "See any operating system documentation about shared libraries for" - $echo "more information, such as the ld(1) and ld.so(8) manual pages." - $echo "X----------------------------------------------------------------------" | $Xsed - exit $EXIT_SUCCESS - ;; - - # libtool execute mode - execute) - modename="$modename: execute" - - # The first argument is the command name. - cmd="$nonopt" - if test -z "$cmd"; then - $echo "$modename: you must specify a COMMAND" 1>&2 - $echo "$help" - exit $EXIT_FAILURE - fi - - # Handle -dlopen flags immediately. - for file in $execute_dlfiles; do - if test ! -f "$file"; then - $echo "$modename: \`$file' is not a file" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - dir= - case $file in - *.la) - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Read the libtool library. - dlname= - library_names= - - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Skip this library if it cannot be dlopened. - if test -z "$dlname"; then - # Warn if it was a shared library. - test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'" - continue - fi - - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$file" && dir=. - - if test -f "$dir/$objdir/$dlname"; then - dir="$dir/$objdir" - else - if test ! -f "$dir/$dlname"; then - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit $EXIT_FAILURE - fi - fi - ;; - - *.lo) - # Just add the directory containing the .lo file. - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$file" && dir=. - ;; - - *) - $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2 - continue - ;; - esac - - # Get the absolute pathname. - absdir=`cd "$dir" && pwd` - test -n "$absdir" && dir="$absdir" - - # Now add the directory to shlibpath_var. - if eval "test -z \"\$$shlibpath_var\""; then - eval "$shlibpath_var=\"\$dir\"" - else - eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" - fi - done - - # This variable tells wrapper scripts just to set shlibpath_var - # rather than running their programs. - libtool_execute_magic="$magic" - - # Check if any of the arguments is a wrapper script. - args= - for file - do - case $file in - -*) ;; - *) - # Do a test to see if this is really a libtool program. - if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Transform arg to wrapped name. - file="$progdir/$program" - fi - ;; - esac - # Quote arguments (to preserve shell metacharacters). - file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"` - args="$args \"$file\"" - done - - if test -z "$run"; then - if test -n "$shlibpath_var"; then - # Export the shlibpath_var. - eval "export $shlibpath_var" - fi - - # Restore saved environment variables - for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES - do - eval "if test \"\${save_$lt_var+set}\" = set; then - $lt_var=\$save_$lt_var; export $lt_var - fi" - done - - # Now prepare to actually exec the command. - exec_cmd="\$cmd$args" - else - # Display what would be done. - if test -n "$shlibpath_var"; then - eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\"" - $echo "export $shlibpath_var" - fi - $echo "$cmd$args" - exit $EXIT_SUCCESS - fi - ;; - - # libtool clean and uninstall mode - clean | uninstall) - modename="$modename: $mode" - rm="$nonopt" - files= - rmforce= - exit_status=0 - - # This variable tells wrapper scripts just to set variables rather - # than running their programs. - libtool_install_magic="$magic" - - for arg - do - case $arg in - -f) rm="$rm $arg"; rmforce=yes ;; - -*) rm="$rm $arg" ;; - *) files="$files $arg" ;; - esac - done - - if test -z "$rm"; then - $echo "$modename: you must specify an RM program" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - rmdirs= - - origobjdir="$objdir" - for file in $files; do - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - if test "X$dir" = "X$file"; then - dir=. - objdir="$origobjdir" - else - objdir="$dir/$origobjdir" - fi - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - test "$mode" = uninstall && objdir="$dir" - - # Remember objdir for removal later, being careful to avoid duplicates - if test "$mode" = clean; then - case " $rmdirs " in - *" $objdir "*) ;; - *) rmdirs="$rmdirs $objdir" ;; - esac - fi - - # Don't error if the file doesn't exist and rm -f was used. - if (test -L "$file") >/dev/null 2>&1 \ - || (test -h "$file") >/dev/null 2>&1 \ - || test -f "$file"; then - : - elif test -d "$file"; then - exit_status=1 - continue - elif test "$rmforce" = yes; then - continue - fi - - rmfiles="$file" - - case $name in - *.la) - # Possibly a libtool archive, so verify it. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - . $dir/$name - - # Delete the libtool libraries and symlinks. - for n in $library_names; do - rmfiles="$rmfiles $objdir/$n" - done - test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" - - case "$mode" in - clean) - case " $library_names " in - # " " in the beginning catches empty $dlname - *" $dlname "*) ;; - *) rmfiles="$rmfiles $objdir/$dlname" ;; - esac - test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" - ;; - uninstall) - if test -n "$library_names"; then - # Do each command in the postuninstall commands. - cmds=$postuninstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" - if test "$?" -ne 0 && test "$rmforce" != yes; then - exit_status=1 - fi - done - IFS="$save_ifs" - fi - - if test -n "$old_library"; then - # Do each command in the old_postuninstall commands. - cmds=$old_postuninstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" - if test "$?" -ne 0 && test "$rmforce" != yes; then - exit_status=1 - fi - done - IFS="$save_ifs" - fi - # FIXME: should reinstall the best remaining shared library. - ;; - esac - fi - ;; - - *.lo) - # Possibly a libtool object, so verify it. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - - # Read the .lo file - . $dir/$name - - # Add PIC object to the list of files to remove. - if test -n "$pic_object" \ - && test "$pic_object" != none; then - rmfiles="$rmfiles $dir/$pic_object" - fi - - # Add non-PIC object to the list of files to remove. - if test -n "$non_pic_object" \ - && test "$non_pic_object" != none; then - rmfiles="$rmfiles $dir/$non_pic_object" - fi - fi - ;; - - *) - if test "$mode" = clean ; then - noexename=$name - case $file in - *.exe) - file=`$echo $file|${SED} 's,.exe$,,'` - noexename=`$echo $name|${SED} 's,.exe$,,'` - # $file with .exe has already been added to rmfiles, - # add $file without .exe - rmfiles="$rmfiles $file" - ;; - esac - # Do a test to see if this is a libtool program. - if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - relink_command= - . $dir/$noexename - - # note $name still contains .exe if it was in $file originally - # as does the version of $file that was added into $rmfiles - rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" - if test "$fast_install" = yes && test -n "$relink_command"; then - rmfiles="$rmfiles $objdir/lt-$name" - fi - if test "X$noexename" != "X$name" ; then - rmfiles="$rmfiles $objdir/lt-${noexename}.c" - fi - fi - fi - ;; - esac - $show "$rm $rmfiles" - $run $rm $rmfiles || exit_status=1 - done - objdir="$origobjdir" - - # Try to remove the ${objdir}s in the directories where we deleted files - for dir in $rmdirs; do - if test -d "$dir"; then - $show "rmdir $dir" - $run rmdir $dir >/dev/null 2>&1 - fi - done - - exit $exit_status - ;; - - "") - $echo "$modename: you must specify a MODE" 1>&2 - $echo "$generic_help" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - if test -z "$exec_cmd"; then - $echo "$modename: invalid operation mode \`$mode'" 1>&2 - $echo "$generic_help" 1>&2 - exit $EXIT_FAILURE - fi -fi # test -z "$show_help" - -if test -n "$exec_cmd"; then - eval exec $exec_cmd - exit $EXIT_FAILURE -fi - -# We need to display help for each of the modes. -case $mode in -"") $echo \ -"Usage: $modename [OPTION]... [MODE-ARG]... - -Provide generalized library-building support services. - - --config show all configuration variables - --debug enable verbose shell tracing --n, --dry-run display commands without modifying any files - --features display basic configuration information and exit - --finish same as \`--mode=finish' - --help display this help message and exit - --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS] - --quiet same as \`--silent' - --silent don't print informational messages - --tag=TAG use configuration variables from tag TAG - --version print version information - -MODE must be one of the following: - - clean remove files from the build directory - compile compile a source file into a libtool object - execute automatically set library path, then run a program - finish complete the installation of libtool libraries - install install libraries or executables - link create a library or an executable - uninstall remove libraries from an installed directory - -MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for -a more detailed description of MODE. - -Report bugs to ." - exit $EXIT_SUCCESS - ;; - -clean) - $echo \ -"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE... - -Remove files from the build directory. - -RM is the name of the program to use to delete files associated with each FILE -(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed -to RM. - -If FILE is a libtool library, object or program, all the files associated -with it are deleted. Otherwise, only FILE itself is deleted using RM." - ;; - -compile) - $echo \ -"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE - -Compile a source file into a libtool library object. - -This mode accepts the following additional options: - - -o OUTPUT-FILE set the output file name to OUTPUT-FILE - -prefer-pic try to building PIC objects only - -prefer-non-pic try to building non-PIC objects only - -static always build a \`.o' file suitable for static linking - -COMPILE-COMMAND is a command to be used in creating a \`standard' object file -from the given SOURCEFILE. - -The output file name is determined by removing the directory component from -SOURCEFILE, then substituting the C source code suffix \`.c' with the -library object suffix, \`.lo'." - ;; - -execute) - $echo \ -"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]... - -Automatically set library path, then run a program. - -This mode accepts the following additional options: - - -dlopen FILE add the directory containing FILE to the library path - -This mode sets the library path environment variable according to \`-dlopen' -flags. - -If any of the ARGS are libtool executable wrappers, then they are translated -into their corresponding uninstalled binary, and any of their required library -directories are added to the library path. - -Then, COMMAND is executed, with ARGS as arguments." - ;; - -finish) - $echo \ -"Usage: $modename [OPTION]... --mode=finish [LIBDIR]... - -Complete the installation of libtool libraries. - -Each LIBDIR is a directory that contains libtool libraries. - -The commands that this mode executes may require superuser privileges. Use -the \`--dry-run' option if you just want to see what would be executed." - ;; - -install) - $echo \ -"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND... - -Install executables or libraries. - -INSTALL-COMMAND is the installation command. The first component should be -either the \`install' or \`cp' program. - -The rest of the components are interpreted as arguments to that command (only -BSD-compatible install options are recognized)." - ;; - -link) - $echo \ -"Usage: $modename [OPTION]... --mode=link LINK-COMMAND... - -Link object files or libraries together to form another library, or to -create an executable program. - -LINK-COMMAND is a command using the C compiler that you would use to create -a program from several object files. - -The following components of LINK-COMMAND are treated specially: - - -all-static do not do any dynamic linking at all - -avoid-version do not add a version suffix if possible - -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime - -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols - -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) - -export-symbols SYMFILE - try to export only the symbols listed in SYMFILE - -export-symbols-regex REGEX - try to export only the symbols matching REGEX - -LLIBDIR search LIBDIR for required installed libraries - -lNAME OUTPUT-FILE requires the installed library libNAME - -module build a library that can dlopened - -no-fast-install disable the fast-install mode - -no-install link a not-installable executable - -no-undefined declare that a library does not refer to external symbols - -o OUTPUT-FILE create OUTPUT-FILE from the specified objects - -objectlist FILE Use a list of object files found in FILE to specify objects - -precious-files-regex REGEX - don't remove output files matching REGEX - -release RELEASE specify package release information - -rpath LIBDIR the created library will eventually be installed in LIBDIR - -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries - -static do not do any dynamic linking of uninstalled libtool libraries - -static-libtool-libs - do not do any dynamic linking of libtool libraries - -version-info CURRENT[:REVISION[:AGE]] - specify library version info [each variable defaults to 0] - -All other options (arguments beginning with \`-') are ignored. - -Every other argument is treated as a filename. Files ending in \`.la' are -treated as uninstalled libtool libraries, other files are standard or library -object files. - -If the OUTPUT-FILE ends in \`.la', then a libtool library is created, -only library objects (\`.lo' files) may be specified, and \`-rpath' is -required, except when creating a convenience library. - -If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created -using \`ar' and \`ranlib', or on Windows using \`lib'. - -If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file -is created, otherwise an executable program is created." - ;; - -uninstall) - $echo \ -"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... - -Remove libraries from an installation directory. - -RM is the name of the program to use to delete files associated with each FILE -(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed -to RM. - -If FILE is a libtool library, all the files associated with it are deleted. -Otherwise, only FILE itself is deleted using RM." - ;; - -*) - $echo "$modename: invalid operation mode \`$mode'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; -esac - -$echo -$echo "Try \`$modename --help' for more information about other modes." - -exit $? - -# The TAGs below are defined such that we never get into a situation -# in which we disable both kinds of libraries. Given conflicting -# choices, we go for a static library, that is the most portable, -# since we can't tell whether shared libraries were disabled because -# the user asked for that or because the platform doesn't support -# them. This is particularly important on AIX, because we don't -# support having both static and shared libraries enabled at the same -# time on that platform, so we default to a shared-only configuration. -# If a disable-shared tag is given, we'll fallback to a static-only -# configuration. But we'll never go from static-only to shared-only. - -# ### BEGIN LIBTOOL TAG CONFIG: disable-shared -disable_libs=shared -# ### END LIBTOOL TAG CONFIG: disable-shared - -# ### BEGIN LIBTOOL TAG CONFIG: disable-static -disable_libs=static -# ### END LIBTOOL TAG CONFIG: disable-static - -# Local Variables: -# mode:shell-script -# sh-indentation:2 -# End: diff --git a/libs/openzap/build/missing b/libs/openzap/build/missing deleted file mode 100755 index e7ef83a1c2..0000000000 --- a/libs/openzap/build/missing +++ /dev/null @@ -1,360 +0,0 @@ -#! /bin/sh -# Common stub for a few missing GNU programs while installing. - -scriptversion=2003-09-02.23 - -# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 -# Free Software Foundation, Inc. -# Originally by Fran,cois Pinard , 1996. - -# 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, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -if test $# -eq 0; then - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 -fi - -run=: - -# In the cases where this matters, `missing' is being run in the -# srcdir already. -if test -f configure.ac; then - configure_ac=configure.ac -else - configure_ac=configure.in -fi - -msg="missing on your system" - -case "$1" in ---run) - # Try to run requested program, and just exit if it succeeds. - run= - shift - "$@" && exit 0 - # Exit code 63 means version mismatch. This often happens - # when the user try to use an ancient version of a tool on - # a file that requires a minimum version. In this case we - # we should proceed has if the program had been absent, or - # if --run hadn't been passed. - if test $? = 63; then - run=: - msg="probably too old" - fi - ;; -esac - -# If it does not exist, or fails to run (possibly an outdated version), -# try to emulate it. -case "$1" in - - -h|--h|--he|--hel|--help) - echo "\ -$0 [OPTION]... PROGRAM [ARGUMENT]... - -Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an -error status if there is no known handling for PROGRAM. - -Options: - -h, --help display this help and exit - -v, --version output version information and exit - --run try to run the given command, and emulate it if it fails - -Supported PROGRAM values: - aclocal touch file \`aclocal.m4' - autoconf touch file \`configure' - autoheader touch file \`config.h.in' - automake touch all \`Makefile.in' files - bison create \`y.tab.[ch]', if possible, from existing .[ch] - flex create \`lex.yy.c', if possible, from existing .c - help2man touch the output file - lex create \`lex.yy.c', if possible, from existing .c - makeinfo touch the output file - tar try tar, gnutar, gtar, then tar without non-portable flags - yacc create \`y.tab.[ch]', if possible, from existing .[ch] - -Send bug reports to ." - ;; - - -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing $scriptversion (GNU Automake)" - ;; - - -*) - echo 1>&2 "$0: Unknown \`$1' option" - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 - ;; - - aclocal*) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`acinclude.m4' or \`${configure_ac}'. You might want - to install the \`Automake' and \`Perl' packages. Grab them from - any GNU archive site." - touch aclocal.m4 - ;; - - autoconf) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`${configure_ac}'. You might want to install the - \`Autoconf' and \`GNU m4' packages. Grab them from any GNU - archive site." - touch configure - ;; - - autoheader) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`acconfig.h' or \`${configure_ac}'. You might want - to install the \`Autoconf' and \`GNU m4' packages. Grab them - from any GNU archive site." - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` - test -z "$files" && files="config.h" - touch_files= - for f in $files; do - case "$f" in - *:*) touch_files="$touch_files "`echo "$f" | - sed -e 's/^[^:]*://' -e 's/:.*//'`;; - *) touch_files="$touch_files $f.in";; - esac - done - touch $touch_files - ;; - - automake*) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. - You might want to install the \`Automake' and \`Perl' packages. - Grab them from any GNU archive site." - find . -type f -name Makefile.am -print | - sed 's/\.am$/.in/' | - while read f; do touch "$f"; done - ;; - - autom4te) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is needed, but is $msg. - You might have modified some files without having the - proper tools for further handling them. - You can get \`$1' as part of \`Autoconf' from any GNU - archive site." - - file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` - test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` - if test -f "$file"; then - touch $file - else - test -z "$file" || exec >$file - echo "#! /bin/sh" - echo "# Created by GNU Automake missing as a replacement of" - echo "# $ $@" - echo "exit 0" - chmod +x $file - exit 1 - fi - ;; - - bison|yacc) - echo 1>&2 "\ -WARNING: \`$1' $msg. You should only need it if - you modified a \`.y' file. You may need the \`Bison' package - in order for those modifications to take effect. You can get - \`Bison' from any GNU archive site." - rm -f y.tab.c y.tab.h - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.y) - SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.c - fi - SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.h - fi - ;; - esac - fi - if [ ! -f y.tab.h ]; then - echo >y.tab.h - fi - if [ ! -f y.tab.c ]; then - echo 'main() { return 0; }' >y.tab.c - fi - ;; - - lex|flex) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a \`.l' file. You may need the \`Flex' package - in order for those modifications to take effect. You can get - \`Flex' from any GNU archive site." - rm -f lex.yy.c - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.l) - SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" lex.yy.c - fi - ;; - esac - fi - if [ ! -f lex.yy.c ]; then - echo 'main() { return 0; }' >lex.yy.c - fi - ;; - - help2man) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a dependency of a manual page. You may need the - \`Help2man' package in order for those modifications to take - effect. You can get \`Help2man' from any GNU archive site." - - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` - fi - if [ -f "$file" ]; then - touch $file - else - test -z "$file" || exec >$file - echo ".ab help2man is required to generate this page" - exit 1 - fi - ;; - - makeinfo) - if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then - # We have makeinfo, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a \`.texi' or \`.texinfo' file, or any other file - indirectly affecting the aspect of the manual. The spurious - call might also be the consequence of using a buggy \`make' (AIX, - DU, IRIX). You might want to install the \`Texinfo' package or - the \`GNU make' package. Grab either from any GNU archive site." - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` - file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` - fi - touch $file - ;; - - tar) - shift - if test -n "$run"; then - echo 1>&2 "ERROR: \`tar' requires --run" - exit 1 - fi - - # We have already tried tar in the generic part. - # Look for gnutar/gtar before invocation to avoid ugly error - # messages. - if (gnutar --version > /dev/null 2>&1); then - gnutar "$@" && exit 0 - fi - if (gtar --version > /dev/null 2>&1); then - gtar "$@" && exit 0 - fi - firstarg="$1" - if shift; then - case "$firstarg" in - *o*) - firstarg=`echo "$firstarg" | sed s/o//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - case "$firstarg" in - *h*) - firstarg=`echo "$firstarg" | sed s/h//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - fi - - echo 1>&2 "\ -WARNING: I can't seem to be able to run \`tar' with the given arguments. - You may want to install GNU tar or Free paxutils, or check the - command line arguments." - exit 1 - ;; - - *) - echo 1>&2 "\ -WARNING: \`$1' is needed, and is $msg. - You might have modified some files without having the - proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequisites for installing - this package. You may also peek at any GNU archive site, in case - some other package would contain this missing \`$1' program." - exit 1 - ;; -esac - -exit 0 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" -# End: diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index cb613a79d5..653bd01d2d 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -6,7 +6,7 @@ AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) AC_CONFIG_SRCDIR([src/zap_io.c]) AC_CONFIG_AUX_DIR(build) -#AM_INIT_AUTOMAKE(libopenzap,0.1) +AM_INIT_AUTOMAKE(libopenzap,0.1) # Checks for programs. AC_PROG_CC From d8f4cfa40a51bd0a9e09fadd03bd9b84902454d7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 04:51:53 +0000 Subject: [PATCH 1226/1766] convert to automake (still not really using automake in a useful way) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@634 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/AUTHORS | 0 libs/freetdm/ChangeLog | 0 libs/freetdm/{Makefile.in => Makefile.am} | 16 +- libs/freetdm/NEWS | 0 libs/freetdm/build/config.guess | 1516 ----- libs/freetdm/build/config.sub | 1626 ----- libs/freetdm/build/install-sh | 322 - libs/freetdm/build/ltmain.sh | 6964 --------------------- libs/freetdm/build/missing | 360 -- libs/freetdm/configure.ac | 2 +- 10 files changed, 9 insertions(+), 10797 deletions(-) create mode 100644 libs/freetdm/AUTHORS create mode 100644 libs/freetdm/ChangeLog rename libs/freetdm/{Makefile.in => Makefile.am} (96%) create mode 100644 libs/freetdm/NEWS delete mode 100755 libs/freetdm/build/config.guess delete mode 100755 libs/freetdm/build/config.sub delete mode 100755 libs/freetdm/build/install-sh delete mode 100644 libs/freetdm/build/ltmain.sh delete mode 100755 libs/freetdm/build/missing diff --git a/libs/freetdm/AUTHORS b/libs/freetdm/AUTHORS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/freetdm/ChangeLog b/libs/freetdm/ChangeLog new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/freetdm/Makefile.in b/libs/freetdm/Makefile.am similarity index 96% rename from libs/freetdm/Makefile.in rename to libs/freetdm/Makefile.am index 3055c23121..673f03936b 100644 --- a/libs/freetdm/Makefile.in +++ b/libs/freetdm/Makefile.am @@ -79,11 +79,11 @@ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ $(SRC)/zap_dso.c -BOOST_SOURCES=\ +BOOST_SOURCE=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -ISDN_SOURCES=\ +ISDN_SOURCE=\ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -148,7 +148,7 @@ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o -HEADERS= $(SRC)/include/fsk.h \ +HEADER= $(SRC)/include/fsk.h \ $(SRC)/include/g711.h \ $(SRC)/include/hashtable.h \ $(SRC)/include/hashtable_itr.h \ @@ -166,7 +166,7 @@ $(SRC)/include/zap_dso.h \ $(SRC)/include/zap_types.h -ISDN_HEADERS=\ +ISDN_HEADER=\ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ $(SRC)/isdn/include/DMS.h \ @@ -193,7 +193,7 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod -$(MYLIB): $(OBJS) $(HEADERS) $(SOURCES) +$(MYLIB): $(OBJS) $(HEADER) $(SOURCES) $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) testapp: $(SRC)/testapp.o $(MYLIB) @@ -223,7 +223,7 @@ testanalog: $(SRC)/testanalog.o $(MYLIB) $(SRC)/zap_io.o: $(SRC)/zap_io.c $(LTCOMPILE) $(MOD_CFLAGS) -c $< -o $@ -%.o: %.c $(HEADERS) +%.o: %.c $(HEADER) $(LTCOMPILE) -c $< -o $@ dox: @@ -274,13 +274,13 @@ $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -$(ISDN_OBJS): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +$(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) -$(ISDN_OBJS2): $(ISDN_HEADERS) $(ISDN_SOURCES) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c +$(ISDN_OBJS2): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) diff --git a/libs/freetdm/NEWS b/libs/freetdm/NEWS new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/freetdm/build/config.guess b/libs/freetdm/build/config.guess deleted file mode 100755 index 278f9e9e07..0000000000 --- a/libs/freetdm/build/config.guess +++ /dev/null @@ -1,1516 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. - -timestamp='2007-07-22' - -# This file 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. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner . -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in - Debian*) - release='-gnu' - ;; - *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in - "EV4 (21064)") - UNAME_MACHINE="alpha" ;; - "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; - "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; - "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; - "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; - "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; - "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; - "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; - "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; - "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; - "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; - "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; - DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit ;; - *:AIX:*:[45]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if [ ${HP_ARCH} = "hppa2.0w" ] - then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null - then - HP_ARCH="hppa2.0w" - else - HP_ARCH="hppa64" - fi - fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - EM64T | authenticamd) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - *:GNU:*:*) - # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - arm*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - cris:Linux:*:*) - echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips64 - #undef mips64el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mips64el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips64 - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; - sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; - x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - xtensa:Linux:*:*) - echo xtensa-unknown-linux-gnu - exit ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; - coff-i386) - echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i386. - echo i386-pc-msdosdjgpp - exit ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; - M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; - esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit ;; - SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; -esac - -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 - -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - -cat >&2 < in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/libs/freetdm/build/config.sub b/libs/freetdm/build/config.sub deleted file mode 100755 index 1761d8bdf6..0000000000 --- a/libs/freetdm/build/config.sub +++ /dev/null @@ -1,1626 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. - -timestamp='2007-06-28' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file 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. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit ;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ - uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) - os= - basic_machine=$1 - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | bfin \ - | c4x | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | fido | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64vr | mips64vrel \ - | mips64orion | mips64orionel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | mt \ - | msp430 \ - | nios | nios2 \ - | ns16k | ns32k \ - | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ - | pyramid \ - | score \ - | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu | strongarm \ - | tahoe | thumb | tic4x | tic80 | tron \ - | v850 | v850e \ - | we32k \ - | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ - | z8k) - basic_machine=$basic_machine-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12) - # Motorola 68HC11/12. - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - ms1) - basic_machine=mt-unknown - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | m32c-* | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ - | msp430-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ - | pyramid-* \ - | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ - | tahoe-* | thumb-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ - | tron-* \ - | v850-* | v850e-* | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa-* \ - | ymp-* \ - | z8k-*) - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16) - basic_machine=cr16-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; -# I'm not sure what "Sysv32" means. Should this be sysv3.2? - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc - ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc) basic_machine=powerpc-unknown - ;; - ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; - sei) - basic_machine=mips-sei - os=-seiux - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sh5el) - basic_machine=sh5le-unknown - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tic54x | c54x*) - basic_machine=tic54x-unknown - os=-coff - ;; - tic55x | c55x*) - basic_machine=tic55x-unknown - os=-coff - ;; - tic6x | c6x*) - basic_machine=tic6x-unknown - os=-coff - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - mmix) - basic_machine=mmix-knuth - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) - basic_machine=sh-unknown - ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto-qnx*) - ;; - -nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -os400*) - os=-os400 - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -syllable*) - os=-syllable - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -tpf*) - os=-tpf - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -aros*) - os=-aros - ;; - -kaos*) - os=-kaos - ;; - -zvmoe) - os=-zvmoe - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - c4x-* | tic4x-*) - os=-coff - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - # This also exists in the configure program, but was not the - # default. - # os=-sunos4 - ;; - m68*-cisco) - os=-aout - ;; - mep-*) - os=-elf - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-haiku) - os=-haiku - ;; - *-ibm) - os=-aix - ;; - *-knuth) - os=-mmixware - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -os400*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -tpf*) - vendor=ibm - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/libs/freetdm/build/install-sh b/libs/freetdm/build/install-sh deleted file mode 100755 index b777f1244c..0000000000 --- a/libs/freetdm/build/install-sh +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh -# install - install a program, script, or datafile - -scriptversion=2004-07-05.00 - -# This originates from X11R5 (mit/util/scripts/install.sh), which was -# later released in X11R6 (xc/config/util/install.sh) with the -# following copyright and license. -# -# Copyright (C) 1994 X Consortium -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- -# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# Except as contained in this notice, the name of the X Consortium shall not -# be used in advertising or otherwise to promote the sale, use or other deal- -# ings in this Software without prior written authorization from the X Consor- -# tium. -# -# -# FSF changes to this file are in the public domain. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -chmodcmd="$chmodprog 0755" -chowncmd= -chgrpcmd= -stripcmd= -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src= -dst= -dir_arg= -dstarg= -no_target_directory= - -usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE - or: $0 [OPTION]... SRCFILES... DIRECTORY - or: $0 [OPTION]... -t DIRECTORY SRCFILES... - or: $0 [OPTION]... -d DIRECTORIES... - -In the 1st form, copy SRCFILE to DSTFILE. -In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. -In the 4th, create DIRECTORIES. - -Options: --c (ignored) --d create directories instead of installing files. --g GROUP $chgrpprog installed files to GROUP. --m MODE $chmodprog installed files to MODE. --o USER $chownprog installed files to USER. --s $stripprog installed files. --t DIRECTORY install into DIRECTORY. --T report an error if DSTFILE is a directory. ---help display this help and exit. ---version display version info and exit. - -Environment variables override the default commands: - CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG -" - -while test -n "$1"; do - case $1 in - -c) shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - --help) echo "$usage"; exit 0;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -s) stripcmd=$stripprog - shift - continue;; - - -t) dstarg=$2 - shift - shift - continue;; - - -T) no_target_directory=true - shift - continue;; - - --version) echo "$0 $scriptversion"; exit 0;; - - *) # When -d is used, all remaining arguments are directories to create. - # When -t is used, the destination is already specified. - test -n "$dir_arg$dstarg" && break - # Otherwise, the last argument is the destination. Remove it from $@. - for arg - do - if test -n "$dstarg"; then - # $@ is not empty: it contains at least $arg. - set fnord "$@" "$dstarg" - shift # fnord - fi - shift # arg - dstarg=$arg - done - break;; - esac -done - -if test -z "$1"; then - if test -z "$dir_arg"; then - echo "$0: no input file specified." >&2 - exit 1 - fi - # It's OK to call `install-sh -d' without argument. - # This can happen when creating conditional directories. - exit 0 -fi - -for src -do - # Protect names starting with `-'. - case $src in - -*) src=./$src ;; - esac - - if test -n "$dir_arg"; then - dst=$src - src= - - if test -d "$dst"; then - mkdircmd=: - chmodcmd= - else - mkdircmd=$mkdirprog - fi - else - # Waiting for this to be detected by the "$cpprog $src $dsttmp" command - # might cause directories to be created, which would be especially bad - # if $src (and thus $dsttmp) contains '*'. - if test ! -f "$src" && test ! -d "$src"; then - echo "$0: $src does not exist." >&2 - exit 1 - fi - - if test -z "$dstarg"; then - echo "$0: no destination specified." >&2 - exit 1 - fi - - dst=$dstarg - # Protect names starting with `-'. - case $dst in - -*) dst=./$dst ;; - esac - - # If destination is a directory, append the input filename; won't work - # if double slashes aren't ignored. - if test -d "$dst"; then - if test -n "$no_target_directory"; then - echo "$0: $dstarg: Is a directory" >&2 - exit 1 - fi - dst=$dst/`basename "$src"` - fi - fi - - # This sed command emulates the dirname command. - dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - - # Make sure that the destination directory exists. - - # Skip lots of stat calls in the usual case. - if test ! -d "$dstdir"; then - defaultIFS=' - ' - IFS="${IFS-$defaultIFS}" - - oIFS=$IFS - # Some sh's can't handle IFS=/ for some reason. - IFS='%' - set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` - IFS=$oIFS - - pathcomp= - - while test $# -ne 0 ; do - pathcomp=$pathcomp$1 - shift - if test ! -d "$pathcomp"; then - $mkdirprog "$pathcomp" - # mkdir can fail with a `File exist' error in case several - # install-sh are creating the directory concurrently. This - # is OK. - test -d "$pathcomp" || exit - fi - pathcomp=$pathcomp/ - done - fi - - if test -n "$dir_arg"; then - $doit $mkdircmd "$dst" \ - && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ - && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ - && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ - && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } - - else - dstfile=`basename "$dst"` - - # Make a couple of temp file names in the proper directory. - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ - - # Trap to clean up those temp files at exit. - trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 - trap '(exit $?); exit' 1 2 13 15 - - # Copy the file name to the temp name. - $doit $cpprog "$src" "$dsttmp" && - - # and set any options; do chmod last to preserve setuid bits. - # - # If any of these fail, we abort the whole thing. If we want to - # ignore errors from any of these, just make sure not to ignore - # errors from the above "$doit $cpprog $src $dsttmp" command. - # - { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ - && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ - && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ - && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && - - # Now rename the file to the real destination. - { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ - || { - # The rename failed, perhaps because mv can't rename something else - # to itself, or perhaps because mv is so ancient that it does not - # support -f. - - # Now remove or move aside any old file at destination location. - # We try this two ways since rm can't unlink itself on some - # systems and the destination file might be busy for other - # reasons. In this case, the final cleanup might fail but the new - # file should still install successfully. - { - if test -f "$dstdir/$dstfile"; then - $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ - || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ - || { - echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit - } - else - : - fi - } && - - # Now rename the file to the real destination. - $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" - } - } - fi || { (exit 1); exit; } -done - -# The final little trick to "correctly" pass the exit status to the exit trap. -{ - (exit 0); exit -} - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" -# End: diff --git a/libs/freetdm/build/ltmain.sh b/libs/freetdm/build/ltmain.sh deleted file mode 100644 index e420facf55..0000000000 --- a/libs/freetdm/build/ltmain.sh +++ /dev/null @@ -1,6964 +0,0 @@ -# ltmain.sh - Provide generalized library-building support services. -# NOTE: Changing this file will not affect anything until you rerun configure. -# -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, -# 2007, 2008 Free Software Foundation, Inc. -# Originally by Gordon Matzigkeit , 1996 -# -# 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. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -basename="s,^.*/,,g" - -# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh -# is ksh but when the shell is invoked as "sh" and the current value of -# the _XPG environment variable is not equal to 1 (one), the special -# positional parameter $0, within a function call, is the name of the -# function. -progpath="$0" - -# The name of this program: -progname=`echo "$progpath" | $SED $basename` -modename="$progname" - -# Global variables: -EXIT_SUCCESS=0 -EXIT_FAILURE=1 - -PROGRAM=ltmain.sh -PACKAGE=libtool -VERSION="1.5.26 Debian 1.5.26-1ubuntu1" -TIMESTAMP=" (1.1220.2.493 2008/02/01 16:58:18)" - -# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# Check that we have a working $echo. -if test "X$1" = X--no-reexec; then - # Discard the --no-reexec flag, and continue. - shift -elif test "X$1" = X--fallback-echo; then - # Avoid inline document here, it may be left over - : -elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then - # Yippee, $echo works! - : -else - # Restart under the correct shell, and then maybe $echo will work. - exec $SHELL "$progpath" --no-reexec ${1+"$@"} -fi - -if test "X$1" = X--fallback-echo; then - # used as fallback echo - shift - cat <&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit $EXIT_FAILURE -fi - -# Global variables. -mode=$default_mode -nonopt= -prev= -prevopt= -run= -show="$echo" -show_help= -execute_dlfiles= -duplicate_deps=no -preserve_args= -lo2o="s/\\.lo\$/.${objext}/" -o2lo="s/\\.${objext}\$/.lo/" -extracted_archives= -extracted_serial=0 - -##################################### -# Shell function definitions: -# This seems to be the best place for them - -# func_mktempdir [string] -# Make a temporary directory that won't clash with other running -# libtool processes, and avoids race conditions if possible. If -# given, STRING is the basename for that directory. -func_mktempdir () -{ - my_template="${TMPDIR-/tmp}/${1-$progname}" - - if test "$run" = ":"; then - # Return a directory name, but don't create it in dry-run mode - my_tmpdir="${my_template}-$$" - else - - # If mktemp works, use that first and foremost - my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` - - if test ! -d "$my_tmpdir"; then - # Failing that, at least try and use $RANDOM to avoid a race - my_tmpdir="${my_template}-${RANDOM-0}$$" - - save_mktempdir_umask=`umask` - umask 0077 - $mkdir "$my_tmpdir" - umask $save_mktempdir_umask - fi - - # If we're not in dry-run mode, bomb out on failure - test -d "$my_tmpdir" || { - $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2 - exit $EXIT_FAILURE - } - fi - - $echo "X$my_tmpdir" | $Xsed -} - - -# func_win32_libid arg -# return the library type of file 'arg' -# -# Need a lot of goo to handle *both* DLLs and import libs -# Has to be a shell function in order to 'eat' the argument -# that is supplied when $file_magic_command is called. -func_win32_libid () -{ - win32_libid_type="unknown" - win32_fileres=`file -L $1 2>/dev/null` - case $win32_fileres in - *ar\ archive\ import\ library*) # definitely import - win32_libid_type="x86 archive import" - ;; - *ar\ archive*) # could be an import, or static - if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ - $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then - win32_nmres=`eval $NM -f posix -A $1 | \ - $SED -n -e '1,100{ - / I /{ - s,.*,import, - p - q - } - }'` - case $win32_nmres in - import*) win32_libid_type="x86 archive import";; - *) win32_libid_type="x86 archive static";; - esac - fi - ;; - *DLL*) - win32_libid_type="x86 DLL" - ;; - *executable*) # but shell scripts are "executable" too... - case $win32_fileres in - *MS\ Windows\ PE\ Intel*) - win32_libid_type="x86 DLL" - ;; - esac - ;; - esac - $echo $win32_libid_type -} - - -# func_infer_tag arg -# Infer tagged configuration to use if any are available and -# if one wasn't chosen via the "--tag" command line option. -# Only attempt this if the compiler in the base compile -# command doesn't match the default compiler. -# arg is usually of the form 'gcc ...' -func_infer_tag () -{ - if test -n "$available_tags" && test -z "$tagname"; then - CC_quoted= - for arg in $CC; do - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - CC_quoted="$CC_quoted $arg" - done - case $@ in - # Blanks in the command may have been stripped by the calling shell, - # but not from the CC environment variable when configure was run. - " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;; - # Blanks at the start of $base_compile will cause this to fail - # if we don't check for them as well. - *) - for z in $available_tags; do - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" - CC_quoted= - for arg in $CC; do - # Double-quote args containing other shell metacharacters. - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - CC_quoted="$CC_quoted $arg" - done - case "$@ " in - " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) - # The compiler in the base compile command matches - # the one in the tagged configuration. - # Assume this is the tagged configuration we want. - tagname=$z - break - ;; - esac - fi - done - # If $tagname still isn't set, then no tagged configuration - # was found and let the user know that the "--tag" command - # line option must be used. - if test -z "$tagname"; then - $echo "$modename: unable to infer tagged configuration" - $echo "$modename: specify a tag with \`--tag'" 1>&2 - exit $EXIT_FAILURE -# else -# $echo "$modename: using $tagname tagged configuration" - fi - ;; - esac - fi -} - - -# func_extract_an_archive dir oldlib -func_extract_an_archive () -{ - f_ex_an_ar_dir="$1"; shift - f_ex_an_ar_oldlib="$1" - - $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)" - $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $? - if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2 - exit $EXIT_FAILURE - fi -} - -# func_extract_archives gentop oldlib ... -func_extract_archives () -{ - my_gentop="$1"; shift - my_oldlibs=${1+"$@"} - my_oldobjs="" - my_xlib="" - my_xabs="" - my_xdir="" - my_status="" - - $show "${rm}r $my_gentop" - $run ${rm}r "$my_gentop" - $show "$mkdir $my_gentop" - $run $mkdir "$my_gentop" - my_status=$? - if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then - exit $my_status - fi - - for my_xlib in $my_oldlibs; do - # Extract the objects. - case $my_xlib in - [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; - *) my_xabs=`pwd`"/$my_xlib" ;; - esac - my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'` - my_xlib_u=$my_xlib - while :; do - case " $extracted_archives " in - *" $my_xlib_u "*) - extracted_serial=`expr $extracted_serial + 1` - my_xlib_u=lt$extracted_serial-$my_xlib ;; - *) break ;; - esac - done - extracted_archives="$extracted_archives $my_xlib_u" - my_xdir="$my_gentop/$my_xlib_u" - - $show "${rm}r $my_xdir" - $run ${rm}r "$my_xdir" - $show "$mkdir $my_xdir" - $run $mkdir "$my_xdir" - exit_status=$? - if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then - exit $exit_status - fi - case $host in - *-darwin*) - $show "Extracting $my_xabs" - # Do not bother doing anything if just a dry run - if test -z "$run"; then - darwin_orig_dir=`pwd` - cd $my_xdir || exit $? - darwin_archive=$my_xabs - darwin_curdir=`pwd` - darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'` - darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null` - if test -n "$darwin_arches"; then - darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'` - darwin_arch= - $show "$darwin_base_archive has multiple architectures $darwin_arches" - for darwin_arch in $darwin_arches ; do - mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}" - lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" - cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" - func_extract_an_archive "`pwd`" "${darwin_base_archive}" - cd "$darwin_curdir" - $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" - done # $darwin_arches - ## Okay now we have a bunch of thin objects, gotta fatten them up :) - darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP` - darwin_file= - darwin_files= - for darwin_file in $darwin_filelist; do - darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` - lipo -create -output "$darwin_file" $darwin_files - done # $darwin_filelist - ${rm}r unfat-$$ - cd "$darwin_orig_dir" - else - cd "$darwin_orig_dir" - func_extract_an_archive "$my_xdir" "$my_xabs" - fi # $darwin_arches - fi # $run - ;; - *) - func_extract_an_archive "$my_xdir" "$my_xabs" - ;; - esac - my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` - done - func_extract_archives_result="$my_oldobjs" -} -# End of Shell function definitions -##################################### - -# Darwin sucks -eval std_shrext=\"$shrext_cmds\" - -disable_libs=no - -# Parse our command line options once, thoroughly. -while test "$#" -gt 0 -do - arg="$1" - shift - - case $arg in - -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;; - *) optarg= ;; - esac - - # If the previous option needs an argument, assign it. - if test -n "$prev"; then - case $prev in - execute_dlfiles) - execute_dlfiles="$execute_dlfiles $arg" - ;; - tag) - tagname="$arg" - preserve_args="${preserve_args}=$arg" - - # Check whether tagname contains only valid characters - case $tagname in - *[!-_A-Za-z0-9,/]*) - $echo "$progname: invalid tag name: $tagname" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - case $tagname in - CC) - # Don't test for the "default" C tag, as we know, it's there, but - # not specially marked. - ;; - *) - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then - taglist="$taglist $tagname" - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`" - else - $echo "$progname: ignoring unknown tag $tagname" 1>&2 - fi - ;; - esac - ;; - *) - eval "$prev=\$arg" - ;; - esac - - prev= - prevopt= - continue - fi - - # Have we seen a non-optional argument yet? - case $arg in - --help) - show_help=yes - ;; - - --version) - echo "\ -$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP - -Copyright (C) 2008 Free Software Foundation, Inc. -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - exit $? - ;; - - --config) - ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath - # Now print the configurations for the tags. - for tagname in $taglist; do - ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath" - done - exit $? - ;; - - --debug) - $echo "$progname: enabling shell trace mode" - set -x - preserve_args="$preserve_args $arg" - ;; - - --dry-run | -n) - run=: - ;; - - --features) - $echo "host: $host" - if test "$build_libtool_libs" = yes; then - $echo "enable shared libraries" - else - $echo "disable shared libraries" - fi - if test "$build_old_libs" = yes; then - $echo "enable static libraries" - else - $echo "disable static libraries" - fi - exit $? - ;; - - --finish) mode="finish" ;; - - --mode) prevopt="--mode" prev=mode ;; - --mode=*) mode="$optarg" ;; - - --preserve-dup-deps) duplicate_deps="yes" ;; - - --quiet | --silent) - show=: - preserve_args="$preserve_args $arg" - ;; - - --tag) - prevopt="--tag" - prev=tag - preserve_args="$preserve_args --tag" - ;; - --tag=*) - set tag "$optarg" ${1+"$@"} - shift - prev=tag - preserve_args="$preserve_args --tag" - ;; - - -dlopen) - prevopt="-dlopen" - prev=execute_dlfiles - ;; - - -*) - $echo "$modename: unrecognized option \`$arg'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - - *) - nonopt="$arg" - break - ;; - esac -done - -if test -n "$prevopt"; then - $echo "$modename: option \`$prevopt' requires an argument" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE -fi - -case $disable_libs in -no) - ;; -shared) - build_libtool_libs=no - build_old_libs=yes - ;; -static) - build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` - ;; -esac - -# If this variable is set in any of the actions, the command in it -# will be execed at the end. This prevents here-documents from being -# left over by shells. -exec_cmd= - -if test -z "$show_help"; then - - # Infer the operation mode. - if test -z "$mode"; then - $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2 - $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2 - case $nonopt in - *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*) - mode=link - for arg - do - case $arg in - -c) - mode=compile - break - ;; - esac - done - ;; - *db | *dbx | *strace | *truss) - mode=execute - ;; - *install*|cp|mv) - mode=install - ;; - *rm) - mode=uninstall - ;; - *) - # If we have no mode, but dlfiles were specified, then do execute mode. - test -n "$execute_dlfiles" && mode=execute - - # Just use the default operation mode. - if test -z "$mode"; then - if test -n "$nonopt"; then - $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2 - else - $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2 - fi - fi - ;; - esac - fi - - # Only execute mode is allowed to have -dlopen flags. - if test -n "$execute_dlfiles" && test "$mode" != execute; then - $echo "$modename: unrecognized option \`-dlopen'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Change the help message to a mode-specific one. - generic_help="$help" - help="Try \`$modename --help --mode=$mode' for more information." - - # These modes are in order of execution frequency so that they run quickly. - case $mode in - # libtool compile mode - compile) - modename="$modename: compile" - # Get the compilation command and the source file. - base_compile= - srcfile="$nonopt" # always keep a non-empty value in "srcfile" - suppress_opt=yes - suppress_output= - arg_mode=normal - libobj= - later= - - for arg - do - case $arg_mode in - arg ) - # do not "continue". Instead, add this to base_compile - lastarg="$arg" - arg_mode=normal - ;; - - target ) - libobj="$arg" - arg_mode=normal - continue - ;; - - normal ) - # Accept any command-line options. - case $arg in - -o) - if test -n "$libobj" ; then - $echo "$modename: you cannot specify \`-o' more than once" 1>&2 - exit $EXIT_FAILURE - fi - arg_mode=target - continue - ;; - - -static | -prefer-pic | -prefer-non-pic) - later="$later $arg" - continue - ;; - - -no-suppress) - suppress_opt=no - continue - ;; - - -Xcompiler) - arg_mode=arg # the next one goes into the "base_compile" arg list - continue # The current "srcfile" will either be retained or - ;; # replaced later. I would guess that would be a bug. - - -Wc,*) - args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"` - lastarg= - save_ifs="$IFS"; IFS=',' - for arg in $args; do - IFS="$save_ifs" - - # Double-quote args containing other shell metacharacters. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - lastarg="$lastarg $arg" - done - IFS="$save_ifs" - lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"` - - # Add the arguments to base_compile. - base_compile="$base_compile $lastarg" - continue - ;; - - * ) - # Accept the current argument as the source file. - # The previous "srcfile" becomes the current argument. - # - lastarg="$srcfile" - srcfile="$arg" - ;; - esac # case $arg - ;; - esac # case $arg_mode - - # Aesthetically quote the previous argument. - lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"` - - case $lastarg in - # Double-quote args containing other shell metacharacters. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, and some SunOS ksh mistreat backslash-escaping - # in scan sets (worked around with variable expansion), - # and furthermore cannot handle '|' '&' '(' ')' in scan sets - # at all, so we specify them separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - lastarg="\"$lastarg\"" - ;; - esac - - base_compile="$base_compile $lastarg" - done # for arg - - case $arg_mode in - arg) - $echo "$modename: you must specify an argument for -Xcompile" - exit $EXIT_FAILURE - ;; - target) - $echo "$modename: you must specify a target with \`-o'" 1>&2 - exit $EXIT_FAILURE - ;; - *) - # Get the name of the library object. - [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'` - ;; - esac - - # Recognize several different file suffixes. - # If the user specifies -o file.o, it is replaced with file.lo - xform='[cCFSifmso]' - case $libobj in - *.ada) xform=ada ;; - *.adb) xform=adb ;; - *.ads) xform=ads ;; - *.asm) xform=asm ;; - *.c++) xform=c++ ;; - *.cc) xform=cc ;; - *.ii) xform=ii ;; - *.class) xform=class ;; - *.cpp) xform=cpp ;; - *.cxx) xform=cxx ;; - *.[fF][09]?) xform=[fF][09]. ;; - *.for) xform=for ;; - *.java) xform=java ;; - *.obj) xform=obj ;; - *.sx) xform=sx ;; - esac - - libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` - - case $libobj in - *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;; - *) - $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - func_infer_tag $base_compile - - for arg in $later; do - case $arg in - -static) - build_old_libs=yes - continue - ;; - - -prefer-pic) - pic_mode=yes - continue - ;; - - -prefer-non-pic) - pic_mode=no - continue - ;; - esac - done - - qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"` - case $qlibobj in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qlibobj="\"$qlibobj\"" ;; - esac - test "X$libobj" != "X$qlibobj" \ - && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \ - && $echo "$modename: libobj name \`$libobj' may not contain shell special characters." - objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` - xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$obj"; then - xdir= - else - xdir=$xdir/ - fi - lobj=${xdir}$objdir/$objname - - if test -z "$base_compile"; then - $echo "$modename: you must specify a compilation command" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Delete any leftover library objects. - if test "$build_old_libs" = yes; then - removelist="$obj $lobj $libobj ${libobj}T" - else - removelist="$lobj $libobj ${libobj}T" - fi - - $run $rm $removelist - trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 - - # On Cygwin there's no "real" PIC flag so we must build both object types - case $host_os in - cygwin* | mingw* | pw32* | os2*) - pic_mode=default - ;; - esac - if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then - # non-PIC code in shared libraries is not supported - pic_mode=default - fi - - # Calculate the filename of the output object if compiler does - # not support -o with -c - if test "$compiler_c_o" = no; then - output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} - lockfile="$output_obj.lock" - removelist="$removelist $output_obj $lockfile" - trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15 - else - output_obj= - need_locks=no - lockfile= - fi - - # Lock this critical section if it is needed - # We use this script file to make the link, it avoids creating a new file - if test "$need_locks" = yes; then - until $run ln "$progpath" "$lockfile" 2>/dev/null; do - $show "Waiting for $lockfile to be removed" - sleep 2 - done - elif test "$need_locks" = warn; then - if test -f "$lockfile"; then - $echo "\ -*** ERROR, $lockfile exists and contains: -`cat $lockfile 2>/dev/null` - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit $EXIT_FAILURE - fi - $echo "$srcfile" > "$lockfile" - fi - - if test -n "$fix_srcfile_path"; then - eval srcfile=\"$fix_srcfile_path\" - fi - qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"` - case $qsrcfile in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qsrcfile="\"$qsrcfile\"" ;; - esac - - $run $rm "$libobj" "${libobj}T" - - # Create a libtool object file (analogous to a ".la" file), - # but don't create it if we're doing a dry run. - test -z "$run" && cat > ${libobj}T </dev/null`" != "X$srcfile"; then - $echo "\ -*** ERROR, $lockfile contains: -`cat $lockfile 2>/dev/null` - -but it should contain: -$srcfile - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit $EXIT_FAILURE - fi - - # Just move the object if needed, then go on to compile the next one - if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then - $show "$mv $output_obj $lobj" - if $run $mv $output_obj $lobj; then : - else - error=$? - $run $rm $removelist - exit $error - fi - fi - - # Append the name of the PIC object to the libtool object file. - test -z "$run" && cat >> ${libobj}T <> ${libobj}T </dev/null`" != "X$srcfile"; then - $echo "\ -*** ERROR, $lockfile contains: -`cat $lockfile 2>/dev/null` - -but it should contain: -$srcfile - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit $EXIT_FAILURE - fi - - # Just move the object if needed - if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then - $show "$mv $output_obj $obj" - if $run $mv $output_obj $obj; then : - else - error=$? - $run $rm $removelist - exit $error - fi - fi - - # Append the name of the non-PIC object the libtool object file. - # Only append if the libtool object file exists. - test -z "$run" && cat >> ${libobj}T <> ${libobj}T <&2 - fi - if test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - -static) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=built - ;; - -static-libtool-libs) - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - prefer_static_libs=yes - ;; - esac - build_libtool_libs=no - build_old_libs=yes - break - ;; - esac - done - - # See if our shared archives depend on static archives. - test -n "$old_archive_from_new_cmds" && build_old_libs=yes - - # Go through the arguments, transforming them on the way. - while test "$#" -gt 0; do - arg="$1" - shift - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test - ;; - *) qarg=$arg ;; - esac - libtool_args="$libtool_args $qarg" - - # If the previous option needs an argument, assign it. - if test -n "$prev"; then - case $prev in - output) - compile_command="$compile_command @OUTPUT@" - finalize_command="$finalize_command @OUTPUT@" - ;; - esac - - case $prev in - dlfiles|dlprefiles) - if test "$preload" = no; then - # Add the symbol object into the linking commands. - compile_command="$compile_command @SYMFILE@" - finalize_command="$finalize_command @SYMFILE@" - preload=yes - fi - case $arg in - *.la | *.lo) ;; # We handle these cases below. - force) - if test "$dlself" = no; then - dlself=needless - export_dynamic=yes - fi - prev= - continue - ;; - self) - if test "$prev" = dlprefiles; then - dlself=yes - elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then - dlself=yes - else - dlself=needless - export_dynamic=yes - fi - prev= - continue - ;; - *) - if test "$prev" = dlfiles; then - dlfiles="$dlfiles $arg" - else - dlprefiles="$dlprefiles $arg" - fi - prev= - continue - ;; - esac - ;; - expsyms) - export_symbols="$arg" - if test ! -f "$arg"; then - $echo "$modename: symbol file \`$arg' does not exist" - exit $EXIT_FAILURE - fi - prev= - continue - ;; - expsyms_regex) - export_symbols_regex="$arg" - prev= - continue - ;; - inst_prefix) - inst_prefix_dir="$arg" - prev= - continue - ;; - precious_regex) - precious_files_regex="$arg" - prev= - continue - ;; - release) - release="-$arg" - prev= - continue - ;; - objectlist) - if test -f "$arg"; then - save_arg=$arg - moreargs= - for fil in `cat $save_arg` - do -# moreargs="$moreargs $fil" - arg=$fil - # A libtool-controlled object. - - # Check to see that this really is a libtool object. - if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - pic_object= - non_pic_object= - - # Read the .lo file - # If there is no directory component, then add one. - case $arg in - */* | *\\*) . $arg ;; - *) . ./$arg ;; - esac - - if test -z "$pic_object" || \ - test -z "$non_pic_object" || - test "$pic_object" = none && \ - test "$non_pic_object" = none; then - $echo "$modename: cannot find name of object for \`$arg'" 1>&2 - exit $EXIT_FAILURE - fi - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - if test "$pic_object" != none; then - # Prepend the subdirectory the object is found in. - pic_object="$xdir$pic_object" - - if test "$prev" = dlfiles; then - if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then - dlfiles="$dlfiles $pic_object" - prev= - continue - else - # If libtool objects are unsupported, then we need to preload. - prev=dlprefiles - fi - fi - - # CHECK ME: I think I busted this. -Ossama - if test "$prev" = dlprefiles; then - # Preload the old-style object. - dlprefiles="$dlprefiles $pic_object" - prev= - fi - - # A PIC object. - libobjs="$libobjs $pic_object" - arg="$pic_object" - fi - - # Non-PIC object. - if test "$non_pic_object" != none; then - # Prepend the subdirectory the object is found in. - non_pic_object="$xdir$non_pic_object" - - # A standard non-PIC object - non_pic_objects="$non_pic_objects $non_pic_object" - if test -z "$pic_object" || test "$pic_object" = none ; then - arg="$non_pic_object" - fi - else - # If the PIC object exists, use it instead. - # $xdir was prepended to $pic_object above. - non_pic_object="$pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - else - # Only an error if not doing a dry-run. - if test -z "$run"; then - $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 - exit $EXIT_FAILURE - else - # Dry-run case. - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` - non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` - libobjs="$libobjs $pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - fi - done - else - $echo "$modename: link input file \`$save_arg' does not exist" - exit $EXIT_FAILURE - fi - arg=$save_arg - prev= - continue - ;; - rpath | xrpath) - # We need an absolute path. - case $arg in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - $echo "$modename: only absolute run-paths are allowed" 1>&2 - exit $EXIT_FAILURE - ;; - esac - if test "$prev" = rpath; then - case "$rpath " in - *" $arg "*) ;; - *) rpath="$rpath $arg" ;; - esac - else - case "$xrpath " in - *" $arg "*) ;; - *) xrpath="$xrpath $arg" ;; - esac - fi - prev= - continue - ;; - xcompiler) - compiler_flags="$compiler_flags $qarg" - prev= - compile_command="$compile_command $qarg" - finalize_command="$finalize_command $qarg" - continue - ;; - xlinker) - linker_flags="$linker_flags $qarg" - compiler_flags="$compiler_flags $wl$qarg" - prev= - compile_command="$compile_command $wl$qarg" - finalize_command="$finalize_command $wl$qarg" - continue - ;; - xcclinker) - linker_flags="$linker_flags $qarg" - compiler_flags="$compiler_flags $qarg" - prev= - compile_command="$compile_command $qarg" - finalize_command="$finalize_command $qarg" - continue - ;; - shrext) - shrext_cmds="$arg" - prev= - continue - ;; - darwin_framework|darwin_framework_skip) - test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - prev= - continue - ;; - *) - eval "$prev=\"\$arg\"" - prev= - continue - ;; - esac - fi # test -n "$prev" - - prevarg="$arg" - - case $arg in - -all-static) - if test -n "$link_static_flag"; then - compile_command="$compile_command $link_static_flag" - finalize_command="$finalize_command $link_static_flag" - fi - continue - ;; - - -allow-undefined) - # FIXME: remove this flag sometime in the future. - $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2 - continue - ;; - - -avoid-version) - avoid_version=yes - continue - ;; - - -dlopen) - prev=dlfiles - continue - ;; - - -dlpreopen) - prev=dlprefiles - continue - ;; - - -export-dynamic) - export_dynamic=yes - continue - ;; - - -export-symbols | -export-symbols-regex) - if test -n "$export_symbols" || test -n "$export_symbols_regex"; then - $echo "$modename: more than one -exported-symbols argument is not allowed" - exit $EXIT_FAILURE - fi - if test "X$arg" = "X-export-symbols"; then - prev=expsyms - else - prev=expsyms_regex - fi - continue - ;; - - -framework|-arch|-isysroot) - case " $CC " in - *" ${arg} ${1} "* | *" ${arg} ${1} "*) - prev=darwin_framework_skip ;; - *) compiler_flags="$compiler_flags $arg" - prev=darwin_framework ;; - esac - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - continue - ;; - - -inst-prefix-dir) - prev=inst_prefix - continue - ;; - - # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* - # so, if we see these flags be careful not to treat them like -L - -L[A-Z][A-Z]*:*) - case $with_gcc/$host in - no/*-*-irix* | /*-*-irix*) - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - ;; - esac - continue - ;; - - -L*) - dir=`$echo "X$arg" | $Xsed -e 's/^-L//'` - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - absdir=`cd "$dir" && pwd` - if test -z "$absdir"; then - $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2 - absdir="$dir" - notinst_path="$notinst_path $dir" - fi - dir="$absdir" - ;; - esac - case "$deplibs " in - *" -L$dir "*) ;; - *) - deplibs="$deplibs -L$dir" - lib_search_path="$lib_search_path $dir" - ;; - esac - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'` - case :$dllsearchpath: in - *":$dir:"*) ;; - *) dllsearchpath="$dllsearchpath:$dir";; - esac - case :$dllsearchpath: in - *":$testbindir:"*) ;; - *) dllsearchpath="$dllsearchpath:$testbindir";; - esac - ;; - esac - continue - ;; - - -l*) - if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*) - # These systems don't actually have a C or math library (as such) - continue - ;; - *-*-os2*) - # These systems don't actually have a C library (as such) - test "X$arg" = "X-lc" && continue - ;; - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) - # Do not include libc due to us having libc/libc_r. - test "X$arg" = "X-lc" && continue - ;; - *-*-rhapsody* | *-*-darwin1.[012]) - # Rhapsody C and math libraries are in the System framework - deplibs="$deplibs -framework System" - continue - ;; - *-*-sco3.2v5* | *-*-sco5v6*) - # Causes problems with __ctype - test "X$arg" = "X-lc" && continue - ;; - *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) - # Compiler inserts libc in the correct place for threads to work - test "X$arg" = "X-lc" && continue - ;; - esac - elif test "X$arg" = "X-lc_r"; then - case $host in - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) - # Do not include libc_r directly, use -pthread flag. - continue - ;; - esac - fi - deplibs="$deplibs $arg" - continue - ;; - - # Tru64 UNIX uses -model [arg] to determine the layout of C++ - # classes, name mangling, and exception handling. - -model) - compile_command="$compile_command $arg" - compiler_flags="$compiler_flags $arg" - finalize_command="$finalize_command $arg" - prev=xcompiler - continue - ;; - - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) - compiler_flags="$compiler_flags $arg" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - continue - ;; - - -multi_module) - single_module="${wl}-multi_module" - continue - ;; - - -module) - module=yes - continue - ;; - - # -64, -mips[0-9] enable 64-bit mode on the SGI compiler - # -r[0-9][0-9]* specifies the processor on the SGI compiler - # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler - # +DA*, +DD* enable 64-bit mode on the HP compiler - # -q* pass through compiler args for the IBM compiler - # -m* pass through architecture-specific compiler args for GCC - # -m*, -t[45]*, -txscale* pass through architecture-specific - # compiler args for GCC - # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC - # -F/path gives path to uninstalled frameworks, gcc on darwin - # @file GCC response files - -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ - -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) - - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - compiler_flags="$compiler_flags $arg" - continue - ;; - - -shrext) - prev=shrext - continue - ;; - - -no-fast-install) - fast_install=no - continue - ;; - - -no-install) - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin*) - # The PATH hackery in wrapper scripts is required on Windows - # and Darwin in order for the loader to find any dlls it needs. - $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 - $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 - fast_install=no - ;; - *) no_install=yes ;; - esac - continue - ;; - - -no-undefined) - allow_undefined=no - continue - ;; - - -objectlist) - prev=objectlist - continue - ;; - - -o) prev=output ;; - - -precious-files-regex) - prev=precious_regex - continue - ;; - - -release) - prev=release - continue - ;; - - -rpath) - prev=rpath - continue - ;; - - -R) - prev=xrpath - continue - ;; - - -R*) - dir=`$echo "X$arg" | $Xsed -e 's/^-R//'` - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - $echo "$modename: only absolute run-paths are allowed" 1>&2 - exit $EXIT_FAILURE - ;; - esac - case "$xrpath " in - *" $dir "*) ;; - *) xrpath="$xrpath $dir" ;; - esac - continue - ;; - - -static | -static-libtool-libs) - # The effects of -static are defined in a previous loop. - # We used to do the same as -all-static on platforms that - # didn't have a PIC flag, but the assumption that the effects - # would be equivalent was wrong. It would break on at least - # Digital Unix and AIX. - continue - ;; - - -thread-safe) - thread_safe=yes - continue - ;; - - -version-info) - prev=vinfo - continue - ;; - -version-number) - prev=vinfo - vinfo_number=yes - continue - ;; - - -Wc,*) - args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'` - arg= - save_ifs="$IFS"; IFS=',' - for flag in $args; do - IFS="$save_ifs" - case $flag in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - flag="\"$flag\"" - ;; - esac - arg="$arg $wl$flag" - compiler_flags="$compiler_flags $flag" - done - IFS="$save_ifs" - arg=`$echo "X$arg" | $Xsed -e "s/^ //"` - ;; - - -Wl,*) - args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'` - arg= - save_ifs="$IFS"; IFS=',' - for flag in $args; do - IFS="$save_ifs" - case $flag in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - flag="\"$flag\"" - ;; - esac - arg="$arg $wl$flag" - compiler_flags="$compiler_flags $wl$flag" - linker_flags="$linker_flags $flag" - done - IFS="$save_ifs" - arg=`$echo "X$arg" | $Xsed -e "s/^ //"` - ;; - - -Xcompiler) - prev=xcompiler - continue - ;; - - -Xlinker) - prev=xlinker - continue - ;; - - -XCClinker) - prev=xcclinker - continue - ;; - - # Some other compiler flag. - -* | +*) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - ;; - - *.$objext) - # A standard object. - objs="$objs $arg" - ;; - - *.lo) - # A libtool-controlled object. - - # Check to see that this really is a libtool object. - if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - pic_object= - non_pic_object= - - # Read the .lo file - # If there is no directory component, then add one. - case $arg in - */* | *\\*) . $arg ;; - *) . ./$arg ;; - esac - - if test -z "$pic_object" || \ - test -z "$non_pic_object" || - test "$pic_object" = none && \ - test "$non_pic_object" = none; then - $echo "$modename: cannot find name of object for \`$arg'" 1>&2 - exit $EXIT_FAILURE - fi - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - if test "$pic_object" != none; then - # Prepend the subdirectory the object is found in. - pic_object="$xdir$pic_object" - - if test "$prev" = dlfiles; then - if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then - dlfiles="$dlfiles $pic_object" - prev= - continue - else - # If libtool objects are unsupported, then we need to preload. - prev=dlprefiles - fi - fi - - # CHECK ME: I think I busted this. -Ossama - if test "$prev" = dlprefiles; then - # Preload the old-style object. - dlprefiles="$dlprefiles $pic_object" - prev= - fi - - # A PIC object. - libobjs="$libobjs $pic_object" - arg="$pic_object" - fi - - # Non-PIC object. - if test "$non_pic_object" != none; then - # Prepend the subdirectory the object is found in. - non_pic_object="$xdir$non_pic_object" - - # A standard non-PIC object - non_pic_objects="$non_pic_objects $non_pic_object" - if test -z "$pic_object" || test "$pic_object" = none ; then - arg="$non_pic_object" - fi - else - # If the PIC object exists, use it instead. - # $xdir was prepended to $pic_object above. - non_pic_object="$pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - else - # Only an error if not doing a dry-run. - if test -z "$run"; then - $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 - exit $EXIT_FAILURE - else - # Dry-run case. - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` - non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` - libobjs="$libobjs $pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - fi - ;; - - *.$libext) - # An archive. - deplibs="$deplibs $arg" - old_deplibs="$old_deplibs $arg" - continue - ;; - - *.la) - # A libtool-controlled library. - - if test "$prev" = dlfiles; then - # This library was specified with -dlopen. - dlfiles="$dlfiles $arg" - prev= - elif test "$prev" = dlprefiles; then - # The library was specified with -dlpreopen. - dlprefiles="$dlprefiles $arg" - prev= - else - deplibs="$deplibs $arg" - fi - continue - ;; - - # Some other compiler argument. - *) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - ;; - esac # arg - - # Now actually substitute the argument into the commands. - if test -n "$arg"; then - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - fi - done # argument parsing loop - - if test -n "$prev"; then - $echo "$modename: the \`$prevarg' option requires an argument" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then - eval arg=\"$export_dynamic_flag_spec\" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - fi - - oldlibs= - # calculate the name of the file, without its directory - outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'` - libobjs_save="$libobjs" - - if test -n "$shlibpath_var"; then - # get the directories listed in $shlibpath_var - eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` - else - shlib_search_path= - fi - eval sys_lib_search_path=\"$sys_lib_search_path_spec\" - eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" - - output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'` - if test "X$output_objdir" = "X$output"; then - output_objdir="$objdir" - else - output_objdir="$output_objdir/$objdir" - fi - # Create the object directory. - if test ! -d "$output_objdir"; then - $show "$mkdir $output_objdir" - $run $mkdir $output_objdir - exit_status=$? - if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then - exit $exit_status - fi - fi - - # Determine the type of output - case $output in - "") - $echo "$modename: you must specify an output file" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - *.$libext) linkmode=oldlib ;; - *.lo | *.$objext) linkmode=obj ;; - *.la) linkmode=lib ;; - *) linkmode=prog ;; # Anything else should be a program. - esac - - case $host in - *cygwin* | *mingw* | *pw32*) - # don't eliminate duplications in $postdeps and $predeps - duplicate_compiler_generated_deps=yes - ;; - *) - duplicate_compiler_generated_deps=$duplicate_deps - ;; - esac - specialdeplibs= - - libs= - # Find all interdependent deplibs by searching for libraries - # that are linked more than once (e.g. -la -lb -la) - for deplib in $deplibs; do - if test "X$duplicate_deps" = "Xyes" ; then - case "$libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - libs="$libs $deplib" - done - - if test "$linkmode" = lib; then - libs="$predeps $libs $compiler_lib_search_path $postdeps" - - # Compute libraries that are listed more than once in $predeps - # $postdeps and mark them as special (i.e., whose duplicates are - # not to be eliminated). - pre_post_deps= - if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then - for pre_post_dep in $predeps $postdeps; do - case "$pre_post_deps " in - *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; - esac - pre_post_deps="$pre_post_deps $pre_post_dep" - done - fi - pre_post_deps= - fi - - deplibs= - newdependency_libs= - newlib_search_path= - need_relink=no # whether we're linking any uninstalled libtool libraries - notinst_deplibs= # not-installed libtool libraries - case $linkmode in - lib) - passes="conv link" - for file in $dlfiles $dlprefiles; do - case $file in - *.la) ;; - *) - $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2 - exit $EXIT_FAILURE - ;; - esac - done - ;; - prog) - compile_deplibs= - finalize_deplibs= - alldeplibs=no - newdlfiles= - newdlprefiles= - passes="conv scan dlopen dlpreopen link" - ;; - *) passes="conv" - ;; - esac - for pass in $passes; do - if test "$linkmode,$pass" = "lib,link" || - test "$linkmode,$pass" = "prog,scan"; then - libs="$deplibs" - deplibs= - fi - if test "$linkmode" = prog; then - case $pass in - dlopen) libs="$dlfiles" ;; - dlpreopen) libs="$dlprefiles" ;; - link) - libs="$deplibs %DEPLIBS%" - test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" - ;; - esac - fi - if test "$pass" = dlopen; then - # Collect dlpreopened libraries - save_deplibs="$deplibs" - deplibs= - fi - for deplib in $libs; do - lib= - found=no - case $deplib in - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - compiler_flags="$compiler_flags $deplib" - fi - continue - ;; - -l*) - if test "$linkmode" != lib && test "$linkmode" != prog; then - $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2 - continue - fi - name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` - if test "$linkmode" = lib; then - searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" - else - searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" - fi - for searchdir in $searchdirs; do - for search_ext in .la $std_shrext .so .a; do - # Search the libtool library - lib="$searchdir/lib${name}${search_ext}" - if test -f "$lib"; then - if test "$search_ext" = ".la"; then - found=yes - else - found=no - fi - break 2 - fi - done - done - if test "$found" != yes; then - # deplib doesn't seem to be a libtool library - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - deplibs="$deplib $deplibs" - test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" - fi - continue - else # deplib is a libtool library - # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, - # We need to do some special things here, and not later. - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - case " $predeps $postdeps " in - *" $deplib "*) - if (${SED} -e '2q' $lib | - grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - library_names= - old_library= - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - for l in $old_library $library_names; do - ll="$l" - done - if test "X$ll" = "X$old_library" ; then # only static version available - found=no - ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` - test "X$ladir" = "X$lib" && ladir="." - lib=$ladir/$old_library - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - deplibs="$deplib $deplibs" - test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" - fi - continue - fi - fi - ;; - *) ;; - esac - fi - fi - ;; # -l - -L*) - case $linkmode in - lib) - deplibs="$deplib $deplibs" - test "$pass" = conv && continue - newdependency_libs="$deplib $newdependency_libs" - newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` - ;; - prog) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - if test "$pass" = scan; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` - ;; - *) - $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2 - ;; - esac # linkmode - continue - ;; # -L - -R*) - if test "$pass" = link; then - dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'` - # Make sure the xrpath contains only unique directories. - case "$xrpath " in - *" $dir "*) ;; - *) xrpath="$xrpath $dir" ;; - esac - fi - deplibs="$deplib $deplibs" - continue - ;; - *.la) lib="$deplib" ;; - *.$libext) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - case $linkmode in - lib) - valid_a_lib=no - case $deplibs_check_method in - match_pattern*) - set dummy $deplibs_check_method - match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` - if eval $echo \"$deplib\" 2>/dev/null \ - | $SED 10q \ - | $EGREP "$match_pattern_regex" > /dev/null; then - valid_a_lib=yes - fi - ;; - pass_all) - valid_a_lib=yes - ;; - esac - if test "$valid_a_lib" != yes; then - $echo - $echo "*** Warning: Trying to link with static lib archive $deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because the file extensions .$libext of this argument makes me believe" - $echo "*** that it is just a static archive that I should not used here." - else - $echo - $echo "*** Warning: Linking the shared library $output against the" - $echo "*** static library $deplib is not portable!" - deplibs="$deplib $deplibs" - fi - continue - ;; - prog) - if test "$pass" != link; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - continue - ;; - esac # linkmode - ;; # *.$libext - *.lo | *.$objext) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - elif test "$linkmode" = prog; then - if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then - # If there is no dlopen support or we're linking statically, - # we need to preload. - newdlprefiles="$newdlprefiles $deplib" - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - newdlfiles="$newdlfiles $deplib" - fi - fi - continue - ;; - %DEPLIBS%) - alldeplibs=yes - continue - ;; - esac # case $deplib - if test "$found" = yes || test -f "$lib"; then : - else - $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2 - exit $EXIT_FAILURE - fi - - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - - ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` - test "X$ladir" = "X$lib" && ladir="." - - dlname= - dlopen= - dlpreopen= - libdir= - library_names= - old_library= - # If the library was installed with an old release of libtool, - # it will not redefine variables installed, or shouldnotlink - installed=yes - shouldnotlink=no - avoidtemprpath= - - - # Read the .la file - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - - if test "$linkmode,$pass" = "lib,link" || - test "$linkmode,$pass" = "prog,scan" || - { test "$linkmode" != prog && test "$linkmode" != lib; }; then - test -n "$dlopen" && dlfiles="$dlfiles $dlopen" - test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" - fi - - if test "$pass" = conv; then - # Only check for convenience libraries - deplibs="$lib $deplibs" - if test -z "$libdir"; then - if test -z "$old_library"; then - $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - # It is a libtool convenience library, so add in its objects. - convenience="$convenience $ladir/$objdir/$old_library" - old_convenience="$old_convenience $ladir/$objdir/$old_library" - tmp_libs= - for deplib in $dependency_libs; do - deplibs="$deplib $deplibs" - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done - elif test "$linkmode" != prog && test "$linkmode" != lib; then - $echo "$modename: \`$lib' is not a convenience library" 1>&2 - exit $EXIT_FAILURE - fi - continue - fi # $pass = conv - - - # Get the name of the library we link against. - linklib= - for l in $old_library $library_names; do - linklib="$l" - done - if test -z "$linklib"; then - $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - - # This library was specified with -dlopen. - if test "$pass" = dlopen; then - if test -z "$libdir"; then - $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - if test -z "$dlname" || - test "$dlopen_support" != yes || - test "$build_libtool_libs" = no; then - # If there is no dlname, no dlopen support or we're linking - # statically, we need to preload. We also need to preload any - # dependent libraries so libltdl's deplib preloader doesn't - # bomb out in the load deplibs phase. - dlprefiles="$dlprefiles $lib $dependency_libs" - else - newdlfiles="$newdlfiles $lib" - fi - continue - fi # $pass = dlopen - - # We need an absolute path. - case $ladir in - [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; - *) - abs_ladir=`cd "$ladir" && pwd` - if test -z "$abs_ladir"; then - $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2 - $echo "$modename: passing it literally to the linker, although it might fail" 1>&2 - abs_ladir="$ladir" - fi - ;; - esac - laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - - # Find the relevant object directory and library name. - if test "X$installed" = Xyes; then - if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then - $echo "$modename: warning: library \`$lib' was moved." 1>&2 - dir="$ladir" - absdir="$abs_ladir" - libdir="$abs_ladir" - else - dir="$libdir" - absdir="$libdir" - fi - test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes - else - if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then - dir="$ladir" - absdir="$abs_ladir" - # Remove this search path later - notinst_path="$notinst_path $abs_ladir" - else - dir="$ladir/$objdir" - absdir="$abs_ladir/$objdir" - # Remove this search path later - notinst_path="$notinst_path $abs_ladir" - fi - fi # $installed = yes - name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - - # This library was specified with -dlpreopen. - if test "$pass" = dlpreopen; then - if test -z "$libdir"; then - $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2 - exit $EXIT_FAILURE - fi - # Prefer using a static library (so that no silly _DYNAMIC symbols - # are required to link). - if test -n "$old_library"; then - newdlprefiles="$newdlprefiles $dir/$old_library" - # Otherwise, use the dlname, so that lt_dlopen finds it. - elif test -n "$dlname"; then - newdlprefiles="$newdlprefiles $dir/$dlname" - else - newdlprefiles="$newdlprefiles $dir/$linklib" - fi - fi # $pass = dlpreopen - - if test -z "$libdir"; then - # Link the convenience library - if test "$linkmode" = lib; then - deplibs="$dir/$old_library $deplibs" - elif test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$dir/$old_library $compile_deplibs" - finalize_deplibs="$dir/$old_library $finalize_deplibs" - else - deplibs="$lib $deplibs" # used for prog,scan pass - fi - continue - fi - - - if test "$linkmode" = prog && test "$pass" != link; then - newlib_search_path="$newlib_search_path $ladir" - deplibs="$lib $deplibs" - - linkalldeplibs=no - if test "$link_all_deplibs" != no || test -z "$library_names" || - test "$build_libtool_libs" = no; then - linkalldeplibs=yes - fi - - tmp_libs= - for deplib in $dependency_libs; do - case $deplib in - -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test - esac - # Need to link against all dependency_libs? - if test "$linkalldeplibs" = yes; then - deplibs="$deplib $deplibs" - else - # Need to hardcode shared library paths - # or/and link against static libraries - newdependency_libs="$deplib $newdependency_libs" - fi - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done # for deplib - continue - fi # $linkmode = prog... - - if test "$linkmode,$pass" = "prog,link"; then - if test -n "$library_names" && - { { test "$prefer_static_libs" = no || - test "$prefer_static_libs,$installed" = "built,yes"; } || - test -z "$old_library"; }; then - # We need to hardcode the library path - if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then - # Make sure the rpath contains only unique directories. - case "$temp_rpath " in - *" $dir "*) ;; - *" $absdir "*) ;; - *) temp_rpath="$temp_rpath $absdir" ;; - esac - fi - - # Hardcode the library path. - # Skip directories that are in the system default run-time - # search path. - case " $sys_lib_dlsearch_path " in - *" $absdir "*) ;; - *) - case "$compile_rpath " in - *" $absdir "*) ;; - *) compile_rpath="$compile_rpath $absdir" - esac - ;; - esac - case " $sys_lib_dlsearch_path " in - *" $libdir "*) ;; - *) - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" - esac - ;; - esac - fi # $linkmode,$pass = prog,link... - - if test "$alldeplibs" = yes && - { test "$deplibs_check_method" = pass_all || - { test "$build_libtool_libs" = yes && - test -n "$library_names"; }; }; then - # We only need to search for static libraries - continue - fi - fi - - link_static=no # Whether the deplib will be linked statically - use_static_libs=$prefer_static_libs - if test "$use_static_libs" = built && test "$installed" = yes ; then - use_static_libs=no - fi - if test -n "$library_names" && - { test "$use_static_libs" = no || test -z "$old_library"; }; then - if test "$installed" = no; then - notinst_deplibs="$notinst_deplibs $lib" - need_relink=yes - fi - # This is a shared library - - # Warn about portability, can't link against -module's on - # some systems (darwin) - if test "$shouldnotlink" = yes && test "$pass" = link ; then - $echo - if test "$linkmode" = prog; then - $echo "*** Warning: Linking the executable $output against the loadable module" - else - $echo "*** Warning: Linking the shared library $output against the loadable module" - fi - $echo "*** $linklib is not portable!" - fi - if test "$linkmode" = lib && - test "$hardcode_into_libs" = yes; then - # Hardcode the library path. - # Skip directories that are in the system default run-time - # search path. - case " $sys_lib_dlsearch_path " in - *" $absdir "*) ;; - *) - case "$compile_rpath " in - *" $absdir "*) ;; - *) compile_rpath="$compile_rpath $absdir" - esac - ;; - esac - case " $sys_lib_dlsearch_path " in - *" $libdir "*) ;; - *) - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" - esac - ;; - esac - fi - - if test -n "$old_archive_from_expsyms_cmds"; then - # figure out the soname - set dummy $library_names - realname="$2" - shift; shift - libname=`eval \\$echo \"$libname_spec\"` - # use dlname if we got it. it's perfectly good, no? - if test -n "$dlname"; then - soname="$dlname" - elif test -n "$soname_spec"; then - # bleh windows - case $host in - *cygwin* | mingw*) - major=`expr $current - $age` - versuffix="-$major" - ;; - esac - eval soname=\"$soname_spec\" - else - soname="$realname" - fi - - # Make a new name for the extract_expsyms_cmds to use - soroot="$soname" - soname=`$echo $soroot | ${SED} -e 's/^.*\///'` - newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a" - - # If the library has no export list, then create one now - if test -f "$output_objdir/$soname-def"; then : - else - $show "extracting exported symbol list from \`$soname'" - save_ifs="$IFS"; IFS='~' - cmds=$extract_expsyms_cmds - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - # Create $newlib - if test -f "$output_objdir/$newlib"; then :; else - $show "generating import library for \`$soname'" - save_ifs="$IFS"; IFS='~' - cmds=$old_archive_from_expsyms_cmds - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - # make sure the library variables are pointing to the new library - dir=$output_objdir - linklib=$newlib - fi # test -n "$old_archive_from_expsyms_cmds" - - if test "$linkmode" = prog || test "$mode" != relink; then - add_shlibpath= - add_dir= - add= - lib_linked=yes - case $hardcode_action in - immediate | unsupported) - if test "$hardcode_direct" = no; then - add="$dir/$linklib" - case $host in - *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; - *-*-sysv4*uw2*) add_dir="-L$dir" ;; - *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ - *-*-unixware7*) add_dir="-L$dir" ;; - *-*-darwin* ) - # if the lib is a module then we can not link against - # it, someone is ignoring the new warnings I added - if /usr/bin/file -L $add 2> /dev/null | - $EGREP ": [^:]* bundle" >/dev/null ; then - $echo "** Warning, lib $linklib is a module, not a shared library" - if test -z "$old_library" ; then - $echo - $echo "** And there doesn't seem to be a static archive available" - $echo "** The link will probably fail, sorry" - else - add="$dir/$old_library" - fi - fi - esac - elif test "$hardcode_minus_L" = no; then - case $host in - *-*-sunos*) add_shlibpath="$dir" ;; - esac - add_dir="-L$dir" - add="-l$name" - elif test "$hardcode_shlibpath_var" = no; then - add_shlibpath="$dir" - add="-l$name" - else - lib_linked=no - fi - ;; - relink) - if test "$hardcode_direct" = yes; then - add="$dir/$linklib" - elif test "$hardcode_minus_L" = yes; then - add_dir="-L$dir" - # Try looking first in the location we're being installed to. - if test -n "$inst_prefix_dir"; then - case $libdir in - [\\/]*) - add_dir="$add_dir -L$inst_prefix_dir$libdir" - ;; - esac - fi - add="-l$name" - elif test "$hardcode_shlibpath_var" = yes; then - add_shlibpath="$dir" - add="-l$name" - else - lib_linked=no - fi - ;; - *) lib_linked=no ;; - esac - - if test "$lib_linked" != yes; then - $echo "$modename: configuration error: unsupported hardcode properties" - exit $EXIT_FAILURE - fi - - if test -n "$add_shlibpath"; then - case :$compile_shlibpath: in - *":$add_shlibpath:"*) ;; - *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; - esac - fi - if test "$linkmode" = prog; then - test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" - test -n "$add" && compile_deplibs="$add $compile_deplibs" - else - test -n "$add_dir" && deplibs="$add_dir $deplibs" - test -n "$add" && deplibs="$add $deplibs" - if test "$hardcode_direct" != yes && \ - test "$hardcode_minus_L" != yes && \ - test "$hardcode_shlibpath_var" = yes; then - case :$finalize_shlibpath: in - *":$libdir:"*) ;; - *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; - esac - fi - fi - fi - - if test "$linkmode" = prog || test "$mode" = relink; then - add_shlibpath= - add_dir= - add= - # Finalize command for both is simple: just hardcode it. - if test "$hardcode_direct" = yes; then - add="$libdir/$linklib" - elif test "$hardcode_minus_L" = yes; then - add_dir="-L$libdir" - add="-l$name" - elif test "$hardcode_shlibpath_var" = yes; then - case :$finalize_shlibpath: in - *":$libdir:"*) ;; - *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; - esac - add="-l$name" - elif test "$hardcode_automatic" = yes; then - if test -n "$inst_prefix_dir" && - test -f "$inst_prefix_dir$libdir/$linklib" ; then - add="$inst_prefix_dir$libdir/$linklib" - else - add="$libdir/$linklib" - fi - else - # We cannot seem to hardcode it, guess we'll fake it. - add_dir="-L$libdir" - # Try looking first in the location we're being installed to. - if test -n "$inst_prefix_dir"; then - case $libdir in - [\\/]*) - add_dir="$add_dir -L$inst_prefix_dir$libdir" - ;; - esac - fi - add="-l$name" - fi - - if test "$linkmode" = prog; then - test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" - test -n "$add" && finalize_deplibs="$add $finalize_deplibs" - else - test -n "$add_dir" && deplibs="$add_dir $deplibs" - test -n "$add" && deplibs="$add $deplibs" - fi - fi - elif test "$linkmode" = prog; then - # Here we assume that one of hardcode_direct or hardcode_minus_L - # is not unsupported. This is valid on all known static and - # shared platforms. - if test "$hardcode_direct" != unsupported; then - test -n "$old_library" && linklib="$old_library" - compile_deplibs="$dir/$linklib $compile_deplibs" - finalize_deplibs="$dir/$linklib $finalize_deplibs" - else - compile_deplibs="-l$name -L$dir $compile_deplibs" - finalize_deplibs="-l$name -L$dir $finalize_deplibs" - fi - elif test "$build_libtool_libs" = yes; then - # Not a shared library - if test "$deplibs_check_method" != pass_all; then - # We're trying link a shared library against a static one - # but the system doesn't support it. - - # Just print a warning and add the library to dependency_libs so - # that the program can be linked against the static library. - $echo - $echo "*** Warning: This system can not link to static lib archive $lib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have." - if test "$module" = yes; then - $echo "*** But as you try to build a module library, libtool will still create " - $echo "*** a static module, that should work as long as the dlopening application" - $echo "*** is linked with the -dlopen flag to resolve symbols at runtime." - if test -z "$global_symbol_pipe"; then - $echo - $echo "*** However, this would only work if libtool was able to extract symbol" - $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" - $echo "*** not find such a program. So, this module is probably useless." - $echo "*** \`nm' from GNU binutils and a full rebuild may help." - fi - if test "$build_old_libs" = no; then - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - fi - else - deplibs="$dir/$old_library $deplibs" - link_static=yes - fi - fi # link shared/static library? - - if test "$linkmode" = lib; then - if test -n "$dependency_libs" && - { test "$hardcode_into_libs" != yes || - test "$build_old_libs" = yes || - test "$link_static" = yes; }; then - # Extract -R from dependency_libs - temp_deplibs= - for libdir in $dependency_libs; do - case $libdir in - -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'` - case " $xrpath " in - *" $temp_xrpath "*) ;; - *) xrpath="$xrpath $temp_xrpath";; - esac;; - *) temp_deplibs="$temp_deplibs $libdir";; - esac - done - dependency_libs="$temp_deplibs" - fi - - newlib_search_path="$newlib_search_path $absdir" - # Link against this library - test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" - # ... and its dependency_libs - tmp_libs= - for deplib in $dependency_libs; do - newdependency_libs="$deplib $newdependency_libs" - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done - - if test "$link_all_deplibs" != no; then - # Add the search paths of all dependency libraries - for deplib in $dependency_libs; do - case $deplib in - -L*) path="$deplib" ;; - *.la) - dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$deplib" && dir="." - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; - *) - absdir=`cd "$dir" && pwd` - if test -z "$absdir"; then - $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2 - absdir="$dir" - fi - ;; - esac - if grep "^installed=no" $deplib > /dev/null; then - path="$absdir/$objdir" - else - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -z "$libdir"; then - $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - if test "$absdir" != "$libdir"; then - $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2 - fi - path="$absdir" - fi - depdepl= - case $host in - *-*-darwin*) - # we do not want to link against static libs, - # but need to link against shared - eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` - eval deplibdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -n "$deplibrary_names" ; then - for tmp in $deplibrary_names ; do - depdepl=$tmp - done - if test -f "$deplibdir/$depdepl" ; then - depdepl="$deplibdir/$depdepl" - elif test -f "$path/$depdepl" ; then - depdepl="$path/$depdepl" - else - # Can't find it, oh well... - depdepl= - fi - # do not add paths which are already there - case " $newlib_search_path " in - *" $path "*) ;; - *) newlib_search_path="$newlib_search_path $path";; - esac - fi - path="" - ;; - *) - path="-L$path" - ;; - esac - ;; - -l*) - case $host in - *-*-darwin*) - # Again, we only want to link against shared libraries - eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"` - for tmp in $newlib_search_path ; do - if test -f "$tmp/lib$tmp_libs.dylib" ; then - eval depdepl="$tmp/lib$tmp_libs.dylib" - break - fi - done - path="" - ;; - *) continue ;; - esac - ;; - *) continue ;; - esac - case " $deplibs " in - *" $path "*) ;; - *) deplibs="$path $deplibs" ;; - esac - case " $deplibs " in - *" $depdepl "*) ;; - *) deplibs="$depdepl $deplibs" ;; - esac - done - fi # link_all_deplibs != no - fi # linkmode = lib - done # for deplib in $libs - dependency_libs="$newdependency_libs" - if test "$pass" = dlpreopen; then - # Link the dlpreopened libraries before other libraries - for deplib in $save_deplibs; do - deplibs="$deplib $deplibs" - done - fi - if test "$pass" != dlopen; then - if test "$pass" != conv; then - # Make sure lib_search_path contains only unique directories. - lib_search_path= - for dir in $newlib_search_path; do - case "$lib_search_path " in - *" $dir "*) ;; - *) lib_search_path="$lib_search_path $dir" ;; - esac - done - newlib_search_path= - fi - - if test "$linkmode,$pass" != "prog,link"; then - vars="deplibs" - else - vars="compile_deplibs finalize_deplibs" - fi - for var in $vars dependency_libs; do - # Add libraries to $var in reverse order - eval tmp_libs=\"\$$var\" - new_libs= - for deplib in $tmp_libs; do - # FIXME: Pedantically, this is the right thing to do, so - # that some nasty dependency loop isn't accidentally - # broken: - #new_libs="$deplib $new_libs" - # Pragmatically, this seems to cause very few problems in - # practice: - case $deplib in - -L*) new_libs="$deplib $new_libs" ;; - -R*) ;; - *) - # And here is the reason: when a library appears more - # than once as an explicit dependence of a library, or - # is implicitly linked in more than once by the - # compiler, it is considered special, and multiple - # occurrences thereof are not removed. Compare this - # with having the same library being listed as a - # dependency of multiple other libraries: in this case, - # we know (pedantically, we assume) the library does not - # need to be listed more than once, so we keep only the - # last copy. This is not always right, but it is rare - # enough that we require users that really mean to play - # such unportable linking tricks to link the library - # using -Wl,-lname, so that libtool does not consider it - # for duplicate removal. - case " $specialdeplibs " in - *" $deplib "*) new_libs="$deplib $new_libs" ;; - *) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$deplib $new_libs" ;; - esac - ;; - esac - ;; - esac - done - tmp_libs= - for deplib in $new_libs; do - case $deplib in - -L*) - case " $tmp_libs " in - *" $deplib "*) ;; - *) tmp_libs="$tmp_libs $deplib" ;; - esac - ;; - *) tmp_libs="$tmp_libs $deplib" ;; - esac - done - eval $var=\"$tmp_libs\" - done # for var - fi - # Last step: remove runtime libs from dependency_libs - # (they stay in deplibs) - tmp_libs= - for i in $dependency_libs ; do - case " $predeps $postdeps $compiler_lib_search_path " in - *" $i "*) - i="" - ;; - esac - if test -n "$i" ; then - tmp_libs="$tmp_libs $i" - fi - done - dependency_libs=$tmp_libs - done # for pass - if test "$linkmode" = prog; then - dlfiles="$newdlfiles" - dlprefiles="$newdlprefiles" - fi - - case $linkmode in - oldlib) - case " $deplibs" in - *\ -l* | *\ -L*) - $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 ;; - esac - - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 - fi - - if test -n "$rpath"; then - $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2 - fi - - if test -n "$xrpath"; then - $echo "$modename: warning: \`-R' is ignored for archives" 1>&2 - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for archives" 1>&2 - fi - - if test -n "$export_symbols" || test -n "$export_symbols_regex"; then - $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2 - fi - - # Now set the variables for building old libraries. - build_libtool_libs=no - oldlibs="$output" - objs="$objs$old_deplibs" - ;; - - lib) - # Make sure we only generate libraries of the form `libNAME.la'. - case $outputname in - lib*) - name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - eval shared_ext=\"$shrext_cmds\" - eval libname=\"$libname_spec\" - ;; - *) - if test "$module" = no; then - $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - if test "$need_lib_prefix" != no; then - # Add the "lib" prefix for modules if required - name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` - eval shared_ext=\"$shrext_cmds\" - eval libname=\"$libname_spec\" - else - libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` - fi - ;; - esac - - if test -n "$objs"; then - if test "$deplibs_check_method" != pass_all; then - $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1 - exit $EXIT_FAILURE - else - $echo - $echo "*** Warning: Linking the shared library $output against the non-libtool" - $echo "*** objects $objs is not portable!" - libobjs="$libobjs $objs" - fi - fi - - if test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2 - fi - - set dummy $rpath - if test "$#" -gt 2; then - $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2 - fi - install_libdir="$2" - - oldlibs= - if test -z "$rpath"; then - if test "$build_libtool_libs" = yes; then - # Building a libtool convenience library. - # Some compilers have problems with a `.al' extension so - # convenience libraries should have the same extension an - # archive normally would. - oldlibs="$output_objdir/$libname.$libext $oldlibs" - build_libtool_libs=convenience - build_old_libs=yes - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2 - fi - else - - # Parse the version information argument. - save_ifs="$IFS"; IFS=':' - set dummy $vinfo 0 0 0 - IFS="$save_ifs" - - if test -n "$8"; then - $echo "$modename: too many parameters to \`-version-info'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # convert absolute version numbers to libtool ages - # this retains compatibility with .la files and attempts - # to make the code below a bit more comprehensible - - case $vinfo_number in - yes) - number_major="$2" - number_minor="$3" - number_revision="$4" - # - # There are really only two kinds -- those that - # use the current revision as the major version - # and those that subtract age and use age as - # a minor version. But, then there is irix - # which has an extra 1 added just for fun - # - case $version_type in - darwin|linux|osf|windows|none) - current=`expr $number_major + $number_minor` - age="$number_minor" - revision="$number_revision" - ;; - freebsd-aout|freebsd-elf|sunos) - current="$number_major" - revision="$number_minor" - age="0" - ;; - irix|nonstopux) - current=`expr $number_major + $number_minor` - age="$number_minor" - revision="$number_minor" - lt_irix_increment=no - ;; - *) - $echo "$modename: unknown library version type \`$version_type'" 1>&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit $EXIT_FAILURE - ;; - esac - ;; - no) - current="$2" - revision="$3" - age="$4" - ;; - esac - - # Check that each of the things are valid numbers. - case $current in - 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; - *) - $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - case $revision in - 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; - *) - $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - case $age in - 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; - *) - $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - if test "$age" -gt "$current"; then - $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit $EXIT_FAILURE - fi - - # Calculate the version variables. - major= - versuffix= - verstring= - case $version_type in - none) ;; - - darwin) - # Like Linux, but with the current version available in - # verstring for coding it into the library header - major=.`expr $current - $age` - versuffix="$major.$age.$revision" - # Darwin ld doesn't like 0 for these options... - minor_current=`expr $current + 1` - xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" - verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" - ;; - - freebsd-aout) - major=".$current" - versuffix=".$current.$revision"; - ;; - - freebsd-elf) - major=".$current" - versuffix=".$current"; - ;; - - irix | nonstopux) - if test "X$lt_irix_increment" = "Xno"; then - major=`expr $current - $age` - else - major=`expr $current - $age + 1` - fi - case $version_type in - nonstopux) verstring_prefix=nonstopux ;; - *) verstring_prefix=sgi ;; - esac - verstring="$verstring_prefix$major.$revision" - - # Add in all the interfaces that we are compatible with. - loop=$revision - while test "$loop" -ne 0; do - iface=`expr $revision - $loop` - loop=`expr $loop - 1` - verstring="$verstring_prefix$major.$iface:$verstring" - done - - # Before this point, $major must not contain `.'. - major=.$major - versuffix="$major.$revision" - ;; - - linux) - major=.`expr $current - $age` - versuffix="$major.$age.$revision" - ;; - - osf) - major=.`expr $current - $age` - versuffix=".$current.$age.$revision" - verstring="$current.$age.$revision" - - # Add in all the interfaces that we are compatible with. - loop=$age - while test "$loop" -ne 0; do - iface=`expr $current - $loop` - loop=`expr $loop - 1` - verstring="$verstring:${iface}.0" - done - - # Make executables depend on our current version. - verstring="$verstring:${current}.0" - ;; - - sunos) - major=".$current" - versuffix=".$current.$revision" - ;; - - windows) - # Use '-' rather than '.', since we only want one - # extension on DOS 8.3 filesystems. - major=`expr $current - $age` - versuffix="-$major" - ;; - - *) - $echo "$modename: unknown library version type \`$version_type'" 1>&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit $EXIT_FAILURE - ;; - esac - - # Clear the version info if we defaulted, and they specified a release. - if test -z "$vinfo" && test -n "$release"; then - major= - case $version_type in - darwin) - # we can't check for "0.0" in archive_cmds due to quoting - # problems, so we reset it completely - verstring= - ;; - *) - verstring="0.0" - ;; - esac - if test "$need_version" = no; then - versuffix= - else - versuffix=".0.0" - fi - fi - - # Remove version info from name if versioning should be avoided - if test "$avoid_version" = yes && test "$need_version" = no; then - major= - versuffix= - verstring="" - fi - - # Check to see if the archive will have undefined symbols. - if test "$allow_undefined" = yes; then - if test "$allow_undefined_flag" = unsupported; then - $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2 - build_libtool_libs=no - build_old_libs=yes - fi - else - # Don't allow undefined symbols. - allow_undefined_flag="$no_undefined_flag" - fi - fi - - if test "$mode" != relink; then - # Remove our outputs, but don't remove object files since they - # may have been created when compiling PIC objects. - removelist= - tempremovelist=`$echo "$output_objdir/*"` - for p in $tempremovelist; do - case $p in - *.$objext) - ;; - $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) - if test "X$precious_files_regex" != "X"; then - if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 - then - continue - fi - fi - removelist="$removelist $p" - ;; - *) ;; - esac - done - if test -n "$removelist"; then - $show "${rm}r $removelist" - $run ${rm}r $removelist - fi - fi - - # Now set the variables for building old libraries. - if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then - oldlibs="$oldlibs $output_objdir/$libname.$libext" - - # Transform .lo files to .o files. - oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` - fi - - # Eliminate all temporary directories. - #for path in $notinst_path; do - # lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"` - # deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"` - # dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"` - #done - - if test -n "$xrpath"; then - # If the user specified any rpath flags, then add them. - temp_xrpath= - for libdir in $xrpath; do - temp_xrpath="$temp_xrpath -R$libdir" - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" ;; - esac - done - if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then - dependency_libs="$temp_xrpath $dependency_libs" - fi - fi - - # Make sure dlfiles contains only unique files that won't be dlpreopened - old_dlfiles="$dlfiles" - dlfiles= - for lib in $old_dlfiles; do - case " $dlprefiles $dlfiles " in - *" $lib "*) ;; - *) dlfiles="$dlfiles $lib" ;; - esac - done - - # Make sure dlprefiles contains only unique files - old_dlprefiles="$dlprefiles" - dlprefiles= - for lib in $old_dlprefiles; do - case "$dlprefiles " in - *" $lib "*) ;; - *) dlprefiles="$dlprefiles $lib" ;; - esac - done - - if test "$build_libtool_libs" = yes; then - if test -n "$rpath"; then - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*) - # these systems don't actually have a c library (as such)! - ;; - *-*-rhapsody* | *-*-darwin1.[012]) - # Rhapsody C library is in the System framework - deplibs="$deplibs -framework System" - ;; - *-*-netbsd*) - # Don't link with libc until the a.out ld.so is fixed. - ;; - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) - # Do not include libc due to us having libc/libc_r. - ;; - *-*-sco3.2v5* | *-*-sco5v6*) - # Causes problems with __ctype - ;; - *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) - # Compiler inserts libc in the correct place for threads to work - ;; - *) - # Add libc to deplibs on all other systems if necessary. - if test "$build_libtool_need_lc" = "yes"; then - deplibs="$deplibs -lc" - fi - ;; - esac - fi - - # Transform deplibs into only deplibs that can be linked in shared. - name_save=$name - libname_save=$libname - release_save=$release - versuffix_save=$versuffix - major_save=$major - # I'm not sure if I'm treating the release correctly. I think - # release should show up in the -l (ie -lgmp5) so we don't want to - # add it in twice. Is that correct? - release="" - versuffix="" - major="" - newdeplibs= - droppeddeps=no - case $deplibs_check_method in - pass_all) - # Don't check for shared/static. Everything works. - # This might be a little naive. We might want to check - # whether the library exists or not. But this is on - # osf3 & osf4 and I'm not really sure... Just - # implementing what was already the behavior. - newdeplibs=$deplibs - ;; - test_compile) - # This code stresses the "libraries are programs" paradigm to its - # limits. Maybe even breaks it. We compile a program, linking it - # against the deplibs as a proxy for the library. Then we can check - # whether they linked in statically or dynamically with ldd. - $rm conftest.c - cat > conftest.c </dev/null` - for potent_lib in $potential_libs; do - # Follow soft links. - if ls -lLd "$potent_lib" 2>/dev/null \ - | grep " -> " >/dev/null; then - continue - fi - # The statement above tries to avoid entering an - # endless loop below, in case of cyclic links. - # We might still enter an endless loop, since a link - # loop can be closed while we follow links, - # but so what? - potlib="$potent_lib" - while test -h "$potlib" 2>/dev/null; do - potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` - case $potliblink in - [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; - *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; - esac - done - if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \ - | ${SED} 10q \ - | $EGREP "$file_magic_regex" > /dev/null; then - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - break 2 - fi - done - done - fi - if test -n "$a_deplib" ; then - droppeddeps=yes - $echo - $echo "*** Warning: linker path does not have real file for library $a_deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because I did check the linker path looking for a file starting" - if test -z "$potlib" ; then - $echo "*** with $libname but no candidates were found. (...for file magic test)" - else - $echo "*** with $libname and none of the candidates passed a file format test" - $echo "*** using a file magic. Last file checked: $potlib" - fi - fi - else - # Add a -L argument. - newdeplibs="$newdeplibs $a_deplib" - fi - done # Gone through all deplibs. - ;; - match_pattern*) - set dummy $deplibs_check_method - match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` - for a_deplib in $deplibs; do - name=`expr $a_deplib : '-l\(.*\)'` - # If $name is empty we are operating on a -L argument. - if test -n "$name" && test "$name" != "0"; then - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - case " $predeps $postdeps " in - *" $a_deplib "*) - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - ;; - esac - fi - if test -n "$a_deplib" ; then - libname=`eval \\$echo \"$libname_spec\"` - for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do - potential_libs=`ls $i/$libname[.-]* 2>/dev/null` - for potent_lib in $potential_libs; do - potlib="$potent_lib" # see symlink-check above in file_magic test - if eval $echo \"$potent_lib\" 2>/dev/null \ - | ${SED} 10q \ - | $EGREP "$match_pattern_regex" > /dev/null; then - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - break 2 - fi - done - done - fi - if test -n "$a_deplib" ; then - droppeddeps=yes - $echo - $echo "*** Warning: linker path does not have real file for library $a_deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because I did check the linker path looking for a file starting" - if test -z "$potlib" ; then - $echo "*** with $libname but no candidates were found. (...for regex pattern test)" - else - $echo "*** with $libname and none of the candidates passed a file format test" - $echo "*** using a regex pattern. Last file checked: $potlib" - fi - fi - else - # Add a -L argument. - newdeplibs="$newdeplibs $a_deplib" - fi - done # Gone through all deplibs. - ;; - none | unknown | *) - newdeplibs="" - tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \ - -e 's/ -[LR][^ ]*//g'` - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - for i in $predeps $postdeps ; do - # can't use Xsed below, because $i might contain '/' - tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"` - done - fi - if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \ - | grep . >/dev/null; then - $echo - if test "X$deplibs_check_method" = "Xnone"; then - $echo "*** Warning: inter-library dependencies are not supported in this platform." - else - $echo "*** Warning: inter-library dependencies are not known to be supported." - fi - $echo "*** All declared inter-library dependencies are being dropped." - droppeddeps=yes - fi - ;; - esac - versuffix=$versuffix_save - major=$major_save - release=$release_save - libname=$libname_save - name=$name_save - - case $host in - *-*-rhapsody* | *-*-darwin1.[012]) - # On Rhapsody replace the C library is the System framework - newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'` - ;; - esac - - if test "$droppeddeps" = yes; then - if test "$module" = yes; then - $echo - $echo "*** Warning: libtool could not satisfy all declared inter-library" - $echo "*** dependencies of module $libname. Therefore, libtool will create" - $echo "*** a static module, that should work as long as the dlopening" - $echo "*** application is linked with the -dlopen flag." - if test -z "$global_symbol_pipe"; then - $echo - $echo "*** However, this would only work if libtool was able to extract symbol" - $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" - $echo "*** not find such a program. So, this module is probably useless." - $echo "*** \`nm' from GNU binutils and a full rebuild may help." - fi - if test "$build_old_libs" = no; then - oldlibs="$output_objdir/$libname.$libext" - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - else - $echo "*** The inter-library dependencies that have been dropped here will be" - $echo "*** automatically added whenever a program is linked with this library" - $echo "*** or is declared to -dlopen it." - - if test "$allow_undefined" = no; then - $echo - $echo "*** Since this library must not contain undefined symbols," - $echo "*** because either the platform does not support them or" - $echo "*** it was explicitly requested with -no-undefined," - $echo "*** libtool will only create a static version of it." - if test "$build_old_libs" = no; then - oldlibs="$output_objdir/$libname.$libext" - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - fi - fi - fi - # Done checking deplibs! - deplibs=$newdeplibs - fi - - - # move library search paths that coincide with paths to not yet - # installed libraries to the beginning of the library search list - new_libs= - for path in $notinst_path; do - case " $new_libs " in - *" -L$path/$objdir "*) ;; - *) - case " $deplibs " in - *" -L$path/$objdir "*) - new_libs="$new_libs -L$path/$objdir" ;; - esac - ;; - esac - done - for deplib in $deplibs; do - case $deplib in - -L*) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$new_libs $deplib" ;; - esac - ;; - *) new_libs="$new_libs $deplib" ;; - esac - done - deplibs="$new_libs" - - - # All the library-specific variables (install_libdir is set above). - library_names= - old_library= - dlname= - - # Test again, we may have decided not to build it any more - if test "$build_libtool_libs" = yes; then - if test "$hardcode_into_libs" = yes; then - # Hardcode the library paths - hardcode_libdirs= - dep_rpath= - rpath="$finalize_rpath" - test "$mode" != relink && rpath="$compile_rpath$rpath" - for libdir in $rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - dep_rpath="$dep_rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$perm_rpath " in - *" $libdir "*) ;; - *) perm_rpath="$perm_rpath $libdir" ;; - esac - fi - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - if test -n "$hardcode_libdir_flag_spec_ld"; then - case $archive_cmds in - *\$LD*) eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" ;; - *) eval dep_rpath=\"$hardcode_libdir_flag_spec\" ;; - esac - else - eval dep_rpath=\"$hardcode_libdir_flag_spec\" - fi - fi - if test -n "$runpath_var" && test -n "$perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $perm_rpath; do - rpath="$rpath$dir:" - done - eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" - fi - test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" - fi - - shlibpath="$finalize_shlibpath" - test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" - if test -n "$shlibpath"; then - eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" - fi - - # Get the real and link names of the library. - eval shared_ext=\"$shrext_cmds\" - eval library_names=\"$library_names_spec\" - set dummy $library_names - realname="$2" - shift; shift - - if test -n "$soname_spec"; then - eval soname=\"$soname_spec\" - else - soname="$realname" - fi - if test -z "$dlname"; then - dlname=$soname - fi - - lib="$output_objdir/$realname" - linknames= - for link - do - linknames="$linknames $link" - done - - # Use standard objects if they are pic - test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - - # Prepare the list of exported symbols - if test -z "$export_symbols"; then - if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then - $show "generating symbol list for \`$libname.la'" - export_symbols="$output_objdir/$libname.exp" - $run $rm $export_symbols - cmds=$export_symbols_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - if len=`expr "X$cmd" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - $show "$cmd" - $run eval "$cmd" || exit $? - skipped_export=false - else - # The command line is too long to execute in one step. - $show "using reloadable object file for export list..." - skipped_export=: - # Break out early, otherwise skipped_export may be - # set to false by a later but shorter cmd. - break - fi - done - IFS="$save_ifs" - if test -n "$export_symbols_regex"; then - $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"" - $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' - $show "$mv \"${export_symbols}T\" \"$export_symbols\"" - $run eval '$mv "${export_symbols}T" "$export_symbols"' - fi - fi - fi - - if test -n "$export_symbols" && test -n "$include_expsyms"; then - $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"' - fi - - tmp_deplibs= - for test_deplib in $deplibs; do - case " $convenience " in - *" $test_deplib "*) ;; - *) - tmp_deplibs="$tmp_deplibs $test_deplib" - ;; - esac - done - deplibs="$tmp_deplibs" - - if test -n "$convenience"; then - if test -n "$whole_archive_flag_spec"; then - save_libobjs=$libobjs - eval libobjs=\"\$libobjs $whole_archive_flag_spec\" - else - gentop="$output_objdir/${outputname}x" - generated="$generated $gentop" - - func_extract_archives $gentop $convenience - libobjs="$libobjs $func_extract_archives_result" - fi - fi - - if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then - eval flag=\"$thread_safe_flag_spec\" - linker_flags="$linker_flags $flag" - fi - - # Make a backup of the uninstalled library when relinking - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $? - fi - - # Do each of the archive commands. - if test "$module" = yes && test -n "$module_cmds" ; then - if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then - eval test_cmds=\"$module_expsym_cmds\" - cmds=$module_expsym_cmds - else - eval test_cmds=\"$module_cmds\" - cmds=$module_cmds - fi - else - if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then - eval test_cmds=\"$archive_expsym_cmds\" - cmds=$archive_expsym_cmds - else - eval test_cmds=\"$archive_cmds\" - cmds=$archive_cmds - fi - fi - - if test "X$skipped_export" != "X:" && - len=`expr "X$test_cmds" : ".*" 2>/dev/null` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - : - else - # The command line is too long to link in one step, link piecewise. - $echo "creating reloadable object files..." - - # Save the value of $output and $libobjs because we want to - # use them later. If we have whole_archive_flag_spec, we - # want to use save_libobjs as it was before - # whole_archive_flag_spec was expanded, because we can't - # assume the linker understands whole_archive_flag_spec. - # This may have to be revisited, in case too many - # convenience libraries get linked in and end up exceeding - # the spec. - if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then - save_libobjs=$libobjs - fi - save_output=$output - output_la=`$echo "X$output" | $Xsed -e "$basename"` - - # Clear the reloadable object creation command queue and - # initialize k to one. - test_cmds= - concat_cmds= - objlist= - delfiles= - last_robj= - k=1 - output=$output_objdir/$output_la-${k}.$objext - # Loop over the list of objects to be linked. - for obj in $save_libobjs - do - eval test_cmds=\"$reload_cmds $objlist $last_robj\" - if test "X$objlist" = X || - { len=`expr "X$test_cmds" : ".*" 2>/dev/null` && - test "$len" -le "$max_cmd_len"; }; then - objlist="$objlist $obj" - else - # The command $test_cmds is almost too long, add a - # command to the queue. - if test "$k" -eq 1 ; then - # The first file doesn't have a previous command to add. - eval concat_cmds=\"$reload_cmds $objlist $last_robj\" - else - # All subsequent reloadable object files will link in - # the last one created. - eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\" - fi - last_robj=$output_objdir/$output_la-${k}.$objext - k=`expr $k + 1` - output=$output_objdir/$output_la-${k}.$objext - objlist=$obj - len=1 - fi - done - # Handle the remaining objects by creating one last - # reloadable object file. All subsequent reloadable object - # files will link in the last one created. - test -z "$concat_cmds" || concat_cmds=$concat_cmds~ - eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" - - if ${skipped_export-false}; then - $show "generating symbol list for \`$libname.la'" - export_symbols="$output_objdir/$libname.exp" - $run $rm $export_symbols - libobjs=$output - # Append the command to create the export file. - eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\" - fi - - # Set up a command to remove the reloadable object files - # after they are used. - i=0 - while test "$i" -lt "$k" - do - i=`expr $i + 1` - delfiles="$delfiles $output_objdir/$output_la-${i}.$objext" - done - - $echo "creating a temporary reloadable object file: $output" - - # Loop through the commands generated above and execute them. - save_ifs="$IFS"; IFS='~' - for cmd in $concat_cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - libobjs=$output - # Restore the value of output. - output=$save_output - - if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then - eval libobjs=\"\$libobjs $whole_archive_flag_spec\" - fi - # Expand the library linking commands again to reset the - # value of $libobjs for piecewise linking. - - # Do each of the archive commands. - if test "$module" = yes && test -n "$module_cmds" ; then - if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then - cmds=$module_expsym_cmds - else - cmds=$module_cmds - fi - else - if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then - cmds=$archive_expsym_cmds - else - cmds=$archive_cmds - fi - fi - - # Append the command to remove the reloadable object files - # to the just-reset $cmds. - eval cmds=\"\$cmds~\$rm $delfiles\" - fi - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || { - lt_exit=$? - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' - fi - - exit $lt_exit - } - done - IFS="$save_ifs" - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $? - - if test -n "$convenience"; then - if test -z "$whole_archive_flag_spec"; then - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - fi - fi - - exit $EXIT_SUCCESS - fi - - # Create links to the real library. - for linkname in $linknames; do - if test "$realname" != "$linkname"; then - $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)" - $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $? - fi - done - - # If -module or -export-dynamic was specified, set the dlname. - if test "$module" = yes || test "$export_dynamic" = yes; then - # On all known operating systems, these are identical. - dlname="$soname" - fi - fi - ;; - - obj) - case " $deplibs" in - *\ -l* | *\ -L*) - $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 ;; - esac - - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 - fi - - if test -n "$rpath"; then - $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2 - fi - - if test -n "$xrpath"; then - $echo "$modename: warning: \`-R' is ignored for objects" 1>&2 - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for objects" 1>&2 - fi - - case $output in - *.lo) - if test -n "$objs$old_deplibs"; then - $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2 - exit $EXIT_FAILURE - fi - libobj="$output" - obj=`$echo "X$output" | $Xsed -e "$lo2o"` - ;; - *) - libobj= - obj="$output" - ;; - esac - - # Delete the old objects. - $run $rm $obj $libobj - - # Objects from convenience libraries. This assumes - # single-version convenience libraries. Whenever we create - # different ones for PIC/non-PIC, this we'll have to duplicate - # the extraction. - reload_conv_objs= - gentop= - # reload_cmds runs $LD directly, so let us get rid of - # -Wl from whole_archive_flag_spec and hope we can get by with - # turning comma into space.. - wl= - - if test -n "$convenience"; then - if test -n "$whole_archive_flag_spec"; then - eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" - reload_conv_objs=$reload_objs\ `$echo "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` - else - gentop="$output_objdir/${obj}x" - generated="$generated $gentop" - - func_extract_archives $gentop $convenience - reload_conv_objs="$reload_objs $func_extract_archives_result" - fi - fi - - # Create the old-style object. - reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test - - output="$obj" - cmds=$reload_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - # Exit if we aren't doing a library object file. - if test -z "$libobj"; then - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - exit $EXIT_SUCCESS - fi - - if test "$build_libtool_libs" != yes; then - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - # Create an invalid libtool object if no PIC, so that we don't - # accidentally link it into a program. - # $show "echo timestamp > $libobj" - # $run eval "echo timestamp > $libobj" || exit $? - exit $EXIT_SUCCESS - fi - - if test -n "$pic_flag" || test "$pic_mode" != default; then - # Only do commands if we really have different PIC objects. - reload_objs="$libobjs $reload_conv_objs" - output="$libobj" - cmds=$reload_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - exit $EXIT_SUCCESS - ;; - - prog) - case $host in - *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;; - esac - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for programs" 1>&2 - fi - - if test "$preload" = yes; then - if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown && - test "$dlopen_self_static" = unknown; then - $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support." - fi - fi - - case $host in - *-*-rhapsody* | *-*-darwin1.[012]) - # On Rhapsody replace the C library is the System framework - compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'` - finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'` - ;; - esac - - case $host in - *darwin*) - # Don't allow lazy linking, it breaks C++ global constructors - if test "$tagname" = CXX ; then - compile_command="$compile_command ${wl}-bind_at_load" - finalize_command="$finalize_command ${wl}-bind_at_load" - fi - ;; - esac - - - # move library search paths that coincide with paths to not yet - # installed libraries to the beginning of the library search list - new_libs= - for path in $notinst_path; do - case " $new_libs " in - *" -L$path/$objdir "*) ;; - *) - case " $compile_deplibs " in - *" -L$path/$objdir "*) - new_libs="$new_libs -L$path/$objdir" ;; - esac - ;; - esac - done - for deplib in $compile_deplibs; do - case $deplib in - -L*) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$new_libs $deplib" ;; - esac - ;; - *) new_libs="$new_libs $deplib" ;; - esac - done - compile_deplibs="$new_libs" - - - compile_command="$compile_command $compile_deplibs" - finalize_command="$finalize_command $finalize_deplibs" - - if test -n "$rpath$xrpath"; then - # If the user specified any rpath flags, then add them. - for libdir in $rpath $xrpath; do - # This is the magic to use -rpath. - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" ;; - esac - done - fi - - # Now hardcode the library paths - rpath= - hardcode_libdirs= - for libdir in $compile_rpath $finalize_rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - rpath="$rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$perm_rpath " in - *" $libdir "*) ;; - *) perm_rpath="$perm_rpath $libdir" ;; - esac - fi - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'` - case :$dllsearchpath: in - *":$libdir:"*) ;; - *) dllsearchpath="$dllsearchpath:$libdir";; - esac - case :$dllsearchpath: in - *":$testbindir:"*) ;; - *) dllsearchpath="$dllsearchpath:$testbindir";; - esac - ;; - esac - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - eval rpath=\" $hardcode_libdir_flag_spec\" - fi - compile_rpath="$rpath" - - rpath= - hardcode_libdirs= - for libdir in $finalize_rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - rpath="$rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$finalize_perm_rpath " in - *" $libdir "*) ;; - *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; - esac - fi - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - eval rpath=\" $hardcode_libdir_flag_spec\" - fi - finalize_rpath="$rpath" - - if test -n "$libobjs" && test "$build_old_libs" = yes; then - # Transform all the library objects into standard objects. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - fi - - dlsyms= - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - if test -n "$NM" && test -n "$global_symbol_pipe"; then - dlsyms="${outputname}S.c" - else - $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 - fi - fi - - if test -n "$dlsyms"; then - case $dlsyms in - "") ;; - *.c) - # Discover the nlist of each of the dlfiles. - nlist="$output_objdir/${outputname}.nm" - - $show "$rm $nlist ${nlist}S ${nlist}T" - $run $rm "$nlist" "${nlist}S" "${nlist}T" - - # Parse the name list into a source file. - $show "creating $output_objdir/$dlsyms" - - test -z "$run" && $echo > "$output_objdir/$dlsyms" "\ -/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */ -/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */ - -#ifdef __cplusplus -extern \"C\" { -#endif - -/* Prevent the only kind of declaration conflicts we can make. */ -#define lt_preloaded_symbols some_other_symbol - -/* External symbol declarations for the compiler. */\ -" - - if test "$dlself" = yes; then - $show "generating symbol list for \`$output'" - - test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist" - - # Add our own program objects to the symbol list. - progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - for arg in $progfiles; do - $show "extracting global C symbols from \`$arg'" - $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" - done - - if test -n "$exclude_expsyms"; then - $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' - $run eval '$mv "$nlist"T "$nlist"' - fi - - if test -n "$export_symbols_regex"; then - $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' - $run eval '$mv "$nlist"T "$nlist"' - fi - - # Prepare the list of exported symbols - if test -z "$export_symbols"; then - export_symbols="$output_objdir/$outputname.exp" - $run $rm $export_symbols - $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' - case $host in - *cygwin* | *mingw* ) - $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' - $run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' - ;; - esac - else - $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' - $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' - $run eval 'mv "$nlist"T "$nlist"' - case $host in - *cygwin* | *mingw* ) - $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' - $run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' - ;; - esac - fi - fi - - for arg in $dlprefiles; do - $show "extracting global C symbols from \`$arg'" - name=`$echo "$arg" | ${SED} -e 's%^.*/%%'` - $run eval '$echo ": $name " >> "$nlist"' - $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" - done - - if test -z "$run"; then - # Make sure we have at least an empty file. - test -f "$nlist" || : > "$nlist" - - if test -n "$exclude_expsyms"; then - $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T - $mv "$nlist"T "$nlist" - fi - - # Try sorting and uniquifying the output. - if grep -v "^: " < "$nlist" | - if sort -k 3 /dev/null 2>&1; then - sort -k 3 - else - sort +2 - fi | - uniq > "$nlist"S; then - : - else - grep -v "^: " < "$nlist" > "$nlist"S - fi - - if test -f "$nlist"S; then - eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"' - else - $echo '/* NONE */' >> "$output_objdir/$dlsyms" - fi - - $echo >> "$output_objdir/$dlsyms" "\ - -#undef lt_preloaded_symbols - -#if defined (__STDC__) && __STDC__ -# define lt_ptr void * -#else -# define lt_ptr char * -# define const -#endif - -/* The mapping between symbol names and symbols. */ -" - - case $host in - *cygwin* | *mingw* ) - $echo >> "$output_objdir/$dlsyms" "\ -/* DATA imports from DLLs on WIN32 can't be const, because - runtime relocations are performed -- see ld's documentation - on pseudo-relocs */ -struct { -" - ;; - * ) - $echo >> "$output_objdir/$dlsyms" "\ -const struct { -" - ;; - esac - - - $echo >> "$output_objdir/$dlsyms" "\ - const char *name; - lt_ptr address; -} -lt_preloaded_symbols[] = -{\ -" - - eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms" - - $echo >> "$output_objdir/$dlsyms" "\ - {0, (lt_ptr) 0} -}; - -/* This works around a problem in FreeBSD linker */ -#ifdef FREEBSD_WORKAROUND -static const void *lt_preloaded_setup() { - return lt_preloaded_symbols; -} -#endif - -#ifdef __cplusplus -} -#endif\ -" - fi - - pic_flag_for_symtable= - case $host in - # compiling the symbol table file with pic_flag works around - # a FreeBSD bug that causes programs to crash when -lm is - # linked before any other PIC object. But we must not use - # pic_flag when linking with -static. The problem exists in - # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. - *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) - case "$compile_command " in - *" -static "*) ;; - *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";; - esac;; - *-*-hpux*) - case "$compile_command " in - *" -static "*) ;; - *) pic_flag_for_symtable=" $pic_flag";; - esac - esac - - # Now compile the dynamic symbol file. - $show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")" - $run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $? - - # Clean up the generated files. - $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T" - $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T" - - # Transform the symbol file into the correct name. - case $host in - *cygwin* | *mingw* ) - if test -f "$output_objdir/${outputname}.def" ; then - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%" | $NL2SP` - else - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - fi - ;; - * ) - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%" | $NL2SP` - ;; - esac - ;; - *) - $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 - exit $EXIT_FAILURE - ;; - esac - else - # We keep going just in case the user didn't refer to - # lt_preloaded_symbols. The linker will fail if global_symbol_pipe - # really was required. - - # Nullify the symbol file. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "s% @SYMFILE@%%" | $NL2SP` - fi - - if test "$need_relink" = no || test "$build_libtool_libs" != yes; then - # Replace the output file specification. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$output"'%g' | $NL2SP` - link_command="$compile_command$compile_rpath" - - # We have no uninstalled library dependencies, so finalize right now. - $show "$link_command" - $run eval "$link_command" - exit_status=$? - - # Delete the generated files. - if test -n "$dlsyms"; then - $show "$rm $output_objdir/${outputname}S.${objext}" - $run $rm "$output_objdir/${outputname}S.${objext}" - fi - - exit $exit_status - fi - - if test -n "$shlibpath_var"; then - # We should set the shlibpath_var - rpath= - for dir in $temp_rpath; do - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) - # Absolute path. - rpath="$rpath$dir:" - ;; - *) - # Relative path: add a thisdir entry. - rpath="$rpath\$thisdir/$dir:" - ;; - esac - done - temp_rpath="$rpath" - fi - - if test -n "$compile_shlibpath$finalize_shlibpath"; then - compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" - fi - if test -n "$finalize_shlibpath"; then - finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" - fi - - compile_var= - finalize_var= - if test -n "$runpath_var"; then - if test -n "$perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $perm_rpath; do - rpath="$rpath$dir:" - done - compile_var="$runpath_var=\"$rpath\$$runpath_var\" " - fi - if test -n "$finalize_perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $finalize_perm_rpath; do - rpath="$rpath$dir:" - done - finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " - fi - fi - - if test "$no_install" = yes; then - # We don't need to create a wrapper script. - link_command="$compile_var$compile_command$compile_rpath" - # Replace the output file specification. - link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` - # Delete the old output file. - $run $rm $output - # Link the executable and exit - $show "$link_command" - $run eval "$link_command" || exit $? - exit $EXIT_SUCCESS - fi - - if test "$hardcode_action" = relink; then - # Fast installation is not supported - link_command="$compile_var$compile_command$compile_rpath" - relink_command="$finalize_var$finalize_command$finalize_rpath" - - $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2 - $echo "$modename: \`$output' will be relinked during installation" 1>&2 - else - if test "$fast_install" != no; then - link_command="$finalize_var$compile_command$finalize_rpath" - if test "$fast_install" = yes; then - relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $SP2NL | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g' | $NL2SP` - else - # fast_install is set to needless - relink_command= - fi - else - link_command="$compile_var$compile_command$compile_rpath" - relink_command="$finalize_var$finalize_command$finalize_rpath" - fi - fi - - # Replace the output file specification. - link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` - - # Delete the old output files. - $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname - - $show "$link_command" - $run eval "$link_command" || exit $? - - # Now create the wrapper script. - $show "creating $output" - - # Quote the relink command for shipping. - if test -n "$relink_command"; then - # Preserve any variables that may affect compiler behavior - for var in $variables_saved_for_relink; do - if eval test -z \"\${$var+set}\"; then - relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" - elif eval var_value=\$$var; test -z "$var_value"; then - relink_command="$var=; export $var; $relink_command" - else - var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` - relink_command="$var=\"$var_value\"; export $var; $relink_command" - fi - done - relink_command="(cd `pwd`; $relink_command)" - relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` - fi - - # Quote $echo for shipping. - if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then - case $progpath in - [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; - *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; - esac - qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"` - else - qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"` - fi - - # Only actually do things if our run command is non-null. - if test -z "$run"; then - # win32 will think the script is a binary if it has - # a .exe suffix, so we strip it off here. - case $output in - *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;; - esac - # test for cygwin because mv fails w/o .exe extensions - case $host in - *cygwin*) - exeext=.exe - outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;; - *) exeext= ;; - esac - case $host in - *cygwin* | *mingw* ) - output_name=`basename $output` - output_path=`dirname $output` - cwrappersource="$output_path/$objdir/lt-$output_name.c" - cwrapper="$output_path/$output_name.exe" - $rm $cwrappersource $cwrapper - trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 - - cat > $cwrappersource <> $cwrappersource<<"EOF" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(PATH_MAX) -# define LT_PATHMAX PATH_MAX -#elif defined(MAXPATHLEN) -# define LT_PATHMAX MAXPATHLEN -#else -# define LT_PATHMAX 1024 -#endif - -#ifndef DIR_SEPARATOR -# define DIR_SEPARATOR '/' -# define PATH_SEPARATOR ':' -#endif - -#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ - defined (__OS2__) -# define HAVE_DOS_BASED_FILE_SYSTEM -# ifndef DIR_SEPARATOR_2 -# define DIR_SEPARATOR_2 '\\' -# endif -# ifndef PATH_SEPARATOR_2 -# define PATH_SEPARATOR_2 ';' -# endif -#endif - -#ifndef DIR_SEPARATOR_2 -# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) -#else /* DIR_SEPARATOR_2 */ -# define IS_DIR_SEPARATOR(ch) \ - (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) -#endif /* DIR_SEPARATOR_2 */ - -#ifndef PATH_SEPARATOR_2 -# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) -#else /* PATH_SEPARATOR_2 */ -# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) -#endif /* PATH_SEPARATOR_2 */ - -#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) -#define XFREE(stale) do { \ - if (stale) { free ((void *) stale); stale = 0; } \ -} while (0) - -/* -DDEBUG is fairly common in CFLAGS. */ -#undef DEBUG -#if defined DEBUGWRAPPER -# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__) -#else -# define DEBUG(format, ...) -#endif - -const char *program_name = NULL; - -void * xmalloc (size_t num); -char * xstrdup (const char *string); -const char * base_name (const char *name); -char * find_executable(const char *wrapper); -int check_executable(const char *path); -char * strendzap(char *str, const char *pat); -void lt_fatal (const char *message, ...); - -int -main (int argc, char *argv[]) -{ - char **newargz; - int i; - - program_name = (char *) xstrdup (base_name (argv[0])); - DEBUG("(main) argv[0] : %s\n",argv[0]); - DEBUG("(main) program_name : %s\n",program_name); - newargz = XMALLOC(char *, argc+2); -EOF - - cat >> $cwrappersource <> $cwrappersource <<"EOF" - newargz[1] = find_executable(argv[0]); - if (newargz[1] == NULL) - lt_fatal("Couldn't find %s", argv[0]); - DEBUG("(main) found exe at : %s\n",newargz[1]); - /* we know the script has the same name, without the .exe */ - /* so make sure newargz[1] doesn't end in .exe */ - strendzap(newargz[1],".exe"); - for (i = 1; i < argc; i++) - newargz[i+1] = xstrdup(argv[i]); - newargz[argc+1] = NULL; - - for (i=0; i> $cwrappersource <> $cwrappersource <> $cwrappersource <<"EOF" - return 127; -} - -void * -xmalloc (size_t num) -{ - void * p = (void *) malloc (num); - if (!p) - lt_fatal ("Memory exhausted"); - - return p; -} - -char * -xstrdup (const char *string) -{ - return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL -; -} - -const char * -base_name (const char *name) -{ - const char *base; - -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - /* Skip over the disk name in MSDOS pathnames. */ - if (isalpha ((unsigned char)name[0]) && name[1] == ':') - name += 2; -#endif - - for (base = name; *name; name++) - if (IS_DIR_SEPARATOR (*name)) - base = name + 1; - return base; -} - -int -check_executable(const char * path) -{ - struct stat st; - - DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!"); - if ((!path) || (!*path)) - return 0; - - if ((stat (path, &st) >= 0) && - ( - /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */ -#if defined (S_IXOTH) - ((st.st_mode & S_IXOTH) == S_IXOTH) || -#endif -#if defined (S_IXGRP) - ((st.st_mode & S_IXGRP) == S_IXGRP) || -#endif - ((st.st_mode & S_IXUSR) == S_IXUSR)) - ) - return 1; - else - return 0; -} - -/* Searches for the full path of the wrapper. Returns - newly allocated full path name if found, NULL otherwise */ -char * -find_executable (const char* wrapper) -{ - int has_slash = 0; - const char* p; - const char* p_next; - /* static buffer for getcwd */ - char tmp[LT_PATHMAX + 1]; - int tmp_len; - char* concat_name; - - DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"); - - if ((wrapper == NULL) || (*wrapper == '\0')) - return NULL; - - /* Absolute path? */ -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':') - { - concat_name = xstrdup (wrapper); - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - } - else - { -#endif - if (IS_DIR_SEPARATOR (wrapper[0])) - { - concat_name = xstrdup (wrapper); - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - } -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - } -#endif - - for (p = wrapper; *p; p++) - if (*p == '/') - { - has_slash = 1; - break; - } - if (!has_slash) - { - /* no slashes; search PATH */ - const char* path = getenv ("PATH"); - if (path != NULL) - { - for (p = path; *p; p = p_next) - { - const char* q; - size_t p_len; - for (q = p; *q; q++) - if (IS_PATH_SEPARATOR(*q)) - break; - p_len = q - p; - p_next = (*q == '\0' ? q : q + 1); - if (p_len == 0) - { - /* empty path: current directory */ - if (getcwd (tmp, LT_PATHMAX) == NULL) - lt_fatal ("getcwd failed"); - tmp_len = strlen(tmp); - concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); - memcpy (concat_name, tmp, tmp_len); - concat_name[tmp_len] = '/'; - strcpy (concat_name + tmp_len + 1, wrapper); - } - else - { - concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1); - memcpy (concat_name, p, p_len); - concat_name[p_len] = '/'; - strcpy (concat_name + p_len + 1, wrapper); - } - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - } - } - /* not found in PATH; assume curdir */ - } - /* Relative path | not found in path: prepend cwd */ - if (getcwd (tmp, LT_PATHMAX) == NULL) - lt_fatal ("getcwd failed"); - tmp_len = strlen(tmp); - concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1); - memcpy (concat_name, tmp, tmp_len); - concat_name[tmp_len] = '/'; - strcpy (concat_name + tmp_len + 1, wrapper); - - if (check_executable(concat_name)) - return concat_name; - XFREE(concat_name); - return NULL; -} - -char * -strendzap(char *str, const char *pat) -{ - size_t len, patlen; - - assert(str != NULL); - assert(pat != NULL); - - len = strlen(str); - patlen = strlen(pat); - - if (patlen <= len) - { - str += len - patlen; - if (strcmp(str, pat) == 0) - *str = '\0'; - } - return str; -} - -static void -lt_error_core (int exit_status, const char * mode, - const char * message, va_list ap) -{ - fprintf (stderr, "%s: %s: ", program_name, mode); - vfprintf (stderr, message, ap); - fprintf (stderr, ".\n"); - - if (exit_status >= 0) - exit (exit_status); -} - -void -lt_fatal (const char *message, ...) -{ - va_list ap; - va_start (ap, message); - lt_error_core (EXIT_FAILURE, "FATAL", message, ap); - va_end (ap); -} -EOF - # we should really use a build-platform specific compiler - # here, but OTOH, the wrappers (shell script and this C one) - # are only useful if you want to execute the "real" binary. - # Since the "real" binary is built for $host, then this - # wrapper might as well be built for $host, too. - $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource - ;; - esac - $rm $output - trap "$rm $output; exit $EXIT_FAILURE" 1 2 15 - - $echo > $output "\ -#! $SHELL - -# $output - temporary wrapper script for $objdir/$outputname -# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP -# -# The $output program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -Xsed='${SED} -e 1s/^X//' -sed_quote_subst='$sed_quote_subst' - -# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE). -if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which - # is contrary to our usage. Disable this feature. - alias -g '\${1+\"\$@\"}'='\"\$@\"' - setopt NO_GLOB_SUBST -else - case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac -fi -BIN_SH=xpg4; export BIN_SH # for Tru64 -DUALCASE=1; export DUALCASE # for MKS sh - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -relink_command=\"$relink_command\" - -# This environment variable determines our operation mode. -if test \"\$libtool_install_magic\" = \"$magic\"; then - # install mode needs the following variable: - notinst_deplibs='$notinst_deplibs' -else - # When we are sourced in execute mode, \$file and \$echo are already set. - if test \"\$libtool_execute_magic\" != \"$magic\"; then - echo=\"$qecho\" - file=\"\$0\" - # Make sure echo works. - if test \"X\$1\" = X--no-reexec; then - # Discard the --no-reexec flag, and continue. - shift - elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then - # Yippee, \$echo works! - : - else - # Restart under the correct shell, and then maybe \$echo will work. - exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} - fi - fi\ -" - $echo >> $output "\ - - # Find the directory that this script lives in. - thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` - test \"x\$thisdir\" = \"x\$file\" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` - while test -n \"\$file\"; do - destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` - - # If there was a directory component, then change thisdir. - if test \"x\$destdir\" != \"x\$file\"; then - case \"\$destdir\" in - [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; - *) thisdir=\"\$thisdir/\$destdir\" ;; - esac - fi - - file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\` - file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` - done - - # Try to get the absolute directory name. - absdir=\`cd \"\$thisdir\" && pwd\` - test -n \"\$absdir\" && thisdir=\"\$absdir\" -" - - if test "$fast_install" = yes; then - $echo >> $output "\ - program=lt-'$outputname'$exeext - progdir=\"\$thisdir/$objdir\" - - if test ! -f \"\$progdir/\$program\" || \\ - { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ - test \"X\$file\" != \"X\$progdir/\$program\"; }; then - - file=\"\$\$-\$program\" - - if test ! -d \"\$progdir\"; then - $mkdir \"\$progdir\" - else - $rm \"\$progdir/\$file\" - fi" - - $echo >> $output "\ - - # relink executable if necessary - if test -n \"\$relink_command\"; then - if relink_command_output=\`eval \$relink_command 2>&1\`; then : - else - $echo \"\$relink_command_output\" >&2 - $rm \"\$progdir/\$file\" - exit $EXIT_FAILURE - fi - fi - - $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || - { $rm \"\$progdir/\$program\"; - $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; } - $rm \"\$progdir/\$file\" - fi" - else - $echo >> $output "\ - program='$outputname' - progdir=\"\$thisdir/$objdir\" -" - fi - - $echo >> $output "\ - - if test -f \"\$progdir/\$program\"; then" - - # Export our shlibpath_var if we have one. - if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then - $echo >> $output "\ - # Add our own library path to $shlibpath_var - $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" - - # Some systems cannot cope with colon-terminated $shlibpath_var - # The second colon is a workaround for a bug in BeOS R4 sed - $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` - - export $shlibpath_var -" - fi - - # fixup the dll searchpath if we need to. - if test -n "$dllsearchpath"; then - $echo >> $output "\ - # Add the dll search path components to the executable PATH - PATH=$dllsearchpath:\$PATH -" - fi - - $echo >> $output "\ - if test \"\$libtool_execute_magic\" != \"$magic\"; then - # Run the actual program with our arguments. -" - case $host in - # Backslashes separate directories on plain windows - *-*-mingw | *-*-os2*) - $echo >> $output "\ - exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} -" - ;; - - *) - $echo >> $output "\ - exec \"\$progdir/\$program\" \${1+\"\$@\"} -" - ;; - esac - $echo >> $output "\ - \$echo \"\$0: cannot exec \$program \$*\" - exit $EXIT_FAILURE - fi - else - # The program doesn't exist. - \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 - \$echo \"This script is just a wrapper for \$program.\" 1>&2 - $echo \"See the $PACKAGE documentation for more information.\" 1>&2 - exit $EXIT_FAILURE - fi -fi\ -" - chmod +x $output - fi - exit $EXIT_SUCCESS - ;; - esac - - # See if we need to build an old-fashioned archive. - for oldlib in $oldlibs; do - - if test "$build_libtool_libs" = convenience; then - oldobjs="$libobjs_save" - addlibs="$convenience" - build_libtool_libs=no - else - if test "$build_libtool_libs" = module; then - oldobjs="$libobjs_save" - build_libtool_libs=no - else - oldobjs="$old_deplibs $non_pic_objects" - fi - addlibs="$old_convenience" - fi - - if test -n "$addlibs"; then - gentop="$output_objdir/${outputname}x" - generated="$generated $gentop" - - func_extract_archives $gentop $addlibs - oldobjs="$oldobjs $func_extract_archives_result" - fi - - # Do each command in the archive commands. - if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then - cmds=$old_archive_from_new_cmds - else - # POSIX demands no paths to be encoded in archives. We have - # to avoid creating archives with duplicate basenames if we - # might have to extract them afterwards, e.g., when creating a - # static archive out of a convenience library, or when linking - # the entirety of a libtool archive into another (currently - # not supported by libtool). - if (for obj in $oldobjs - do - $echo "X$obj" | $Xsed -e 's%^.*/%%' - done | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "copying selected object files to avoid basename conflicts..." - - if test -z "$gentop"; then - gentop="$output_objdir/${outputname}x" - generated="$generated $gentop" - - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - $show "$mkdir $gentop" - $run $mkdir "$gentop" - exit_status=$? - if test "$exit_status" -ne 0 && test ! -d "$gentop"; then - exit $exit_status - fi - fi - - save_oldobjs=$oldobjs - oldobjs= - counter=1 - for obj in $save_oldobjs - do - objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` - case " $oldobjs " in - " ") oldobjs=$obj ;; - *[\ /]"$objbase "*) - while :; do - # Make sure we don't pick an alternate name that also - # overlaps. - newobj=lt$counter-$objbase - counter=`expr $counter + 1` - case " $oldobjs " in - *[\ /]"$newobj "*) ;; - *) if test ! -f "$gentop/$newobj"; then break; fi ;; - esac - done - $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" - $run ln "$obj" "$gentop/$newobj" || - $run cp "$obj" "$gentop/$newobj" - oldobjs="$oldobjs $gentop/$newobj" - ;; - *) oldobjs="$oldobjs $obj" ;; - esac - done - fi - - eval cmds=\"$old_archive_cmds\" - - if len=`expr "X$cmds" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - cmds=$old_archive_cmds - else - # the command line is too long to link in one step, link in parts - $echo "using piecewise archive linking..." - save_RANLIB=$RANLIB - RANLIB=: - objlist= - concat_cmds= - save_oldobjs=$oldobjs - - # Is there a better way of finding the last object in the list? - for obj in $save_oldobjs - do - last_oldobj=$obj - done - for obj in $save_oldobjs - do - oldobjs="$objlist $obj" - objlist="$objlist $obj" - eval test_cmds=\"$old_archive_cmds\" - if len=`expr "X$test_cmds" : ".*" 2>/dev/null` && - test "$len" -le "$max_cmd_len"; then - : - else - # the above command should be used before it gets too long - oldobjs=$objlist - if test "$obj" = "$last_oldobj" ; then - RANLIB=$save_RANLIB - fi - test -z "$concat_cmds" || concat_cmds=$concat_cmds~ - eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" - objlist= - fi - done - RANLIB=$save_RANLIB - oldobjs=$objlist - if test "X$oldobjs" = "X" ; then - eval cmds=\"\$concat_cmds\" - else - eval cmds=\"\$concat_cmds~\$old_archive_cmds\" - fi - fi - fi - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - eval cmd=\"$cmd\" - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - done - - if test -n "$generated"; then - $show "${rm}r$generated" - $run ${rm}r$generated - fi - - # Now create the libtool archive. - case $output in - *.la) - old_library= - test "$build_old_libs" = yes && old_library="$libname.$libext" - $show "creating $output" - - # Preserve any variables that may affect compiler behavior - for var in $variables_saved_for_relink; do - if eval test -z \"\${$var+set}\"; then - relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" - elif eval var_value=\$$var; test -z "$var_value"; then - relink_command="$var=; export $var; $relink_command" - else - var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` - relink_command="$var=\"$var_value\"; export $var; $relink_command" - fi - done - # Quote the link command for shipping. - relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" - relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e "$sed_quote_subst" | $NL2SP` - if test "$hardcode_automatic" = yes ; then - relink_command= - fi - - - # Only create the output if not a dry run. - if test -z "$run"; then - for installed in no yes; do - if test "$installed" = yes; then - if test -z "$install_libdir"; then - break - fi - output="$output_objdir/$outputname"i - # Replace all uninstalled libtool libraries with the installed ones - newdependency_libs= - for deplib in $dependency_libs; do - case $deplib in - *.la) - name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -z "$libdir"; then - $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - newdependency_libs="$newdependency_libs $libdir/$name" - ;; - *) newdependency_libs="$newdependency_libs $deplib" ;; - esac - done - dependency_libs="$newdependency_libs" - newdlfiles= - for lib in $dlfiles; do - name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` - if test -z "$libdir"; then - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - newdlfiles="$newdlfiles $libdir/$name" - done - dlfiles="$newdlfiles" - newdlprefiles= - for lib in $dlprefiles; do - name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` - if test -z "$libdir"; then - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit $EXIT_FAILURE - fi - newdlprefiles="$newdlprefiles $libdir/$name" - done - dlprefiles="$newdlprefiles" - else - newdlfiles= - for lib in $dlfiles; do - case $lib in - [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; - *) abs=`pwd`"/$lib" ;; - esac - newdlfiles="$newdlfiles $abs" - done - dlfiles="$newdlfiles" - newdlprefiles= - for lib in $dlprefiles; do - case $lib in - [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; - *) abs=`pwd`"/$lib" ;; - esac - newdlprefiles="$newdlprefiles $abs" - done - dlprefiles="$newdlprefiles" - fi - $rm $output - # place dlname in correct position for cygwin - tdlname=$dlname - case $host,$output,$installed,$module,$dlname in - *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; - esac - $echo > $output "\ -# $outputname - a libtool library file -# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='$tdlname' - -# Names of this library. -library_names='$library_names' - -# The name of the static archive. -old_library='$old_library' - -# Libraries that this one depends upon. -dependency_libs='$dependency_libs' - -# Version information for $libname. -current=$current -age=$age -revision=$revision - -# Is this an already installed library? -installed=$installed - -# Should we warn about portability when linking against -modules? -shouldnotlink=$module - -# Files to dlopen/dlpreopen -dlopen='$dlfiles' -dlpreopen='$dlprefiles' - -# Directory that this library needs to be installed in: -libdir='$install_libdir'" - if test "$installed" = no && test "$need_relink" = yes; then - $echo >> $output "\ -relink_command=\"$relink_command\"" - fi - done - fi - - # Do a symbolic link so that the libtool archive can be found in - # LD_LIBRARY_PATH before the program is installed. - $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)" - $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $? - ;; - esac - exit $EXIT_SUCCESS - ;; - - # libtool install mode - install) - modename="$modename: install" - - # There may be an optional sh(1) argument at the beginning of - # install_prog (especially on Windows NT). - if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || - # Allow the use of GNU shtool's install command. - $echo "X$nonopt" | grep shtool > /dev/null; then - # Aesthetically quote it. - arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - install_prog="$arg " - arg="$1" - shift - else - install_prog= - arg=$nonopt - fi - - # The real first argument should be the name of the installation program. - # Aesthetically quote it. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - install_prog="$install_prog$arg" - - # We need to accept at least all the BSD install flags. - dest= - files= - opts= - prev= - install_type= - isdir=no - stripme= - for arg - do - if test -n "$dest"; then - files="$files $dest" - dest=$arg - continue - fi - - case $arg in - -d) isdir=yes ;; - -f) - case " $install_prog " in - *[\\\ /]cp\ *) ;; - *) prev=$arg ;; - esac - ;; - -g | -m | -o) prev=$arg ;; - -s) - stripme=" -s" - continue - ;; - -*) - ;; - *) - # If the previous option needed an argument, then skip it. - if test -n "$prev"; then - prev= - else - dest=$arg - continue - fi - ;; - esac - - # Aesthetically quote the argument. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - install_prog="$install_prog $arg" - done - - if test -z "$install_prog"; then - $echo "$modename: you must specify an install program" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - if test -n "$prev"; then - $echo "$modename: the \`$prev' option requires an argument" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - if test -z "$files"; then - if test -z "$dest"; then - $echo "$modename: no file or destination specified" 1>&2 - else - $echo "$modename: you must specify a destination" 1>&2 - fi - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Strip any trailing slash from the destination. - dest=`$echo "X$dest" | $Xsed -e 's%/$%%'` - - # Check to see that the destination is a directory. - test -d "$dest" && isdir=yes - if test "$isdir" = yes; then - destdir="$dest" - destname= - else - destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'` - test "X$destdir" = "X$dest" && destdir=. - destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'` - - # Not a directory, so check to see that there is only one file specified. - set dummy $files - if test "$#" -gt 2; then - $echo "$modename: \`$dest' is not a directory" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - fi - case $destdir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - for file in $files; do - case $file in - *.lo) ;; - *) - $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - esac - done - ;; - esac - - # This variable tells wrapper scripts just to set variables rather - # than running their programs. - libtool_install_magic="$magic" - - staticlibs= - future_libdirs= - current_libdirs= - for file in $files; do - - # Do each installation. - case $file in - *.$libext) - # Do the static libraries later. - staticlibs="$staticlibs $file" - ;; - - *.la) - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$file' is not a valid libtool archive" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - library_names= - old_library= - relink_command= - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Add the libdir to current_libdirs if it is the destination. - if test "X$destdir" = "X$libdir"; then - case "$current_libdirs " in - *" $libdir "*) ;; - *) current_libdirs="$current_libdirs $libdir" ;; - esac - else - # Note the libdir as a future libdir. - case "$future_libdirs " in - *" $libdir "*) ;; - *) future_libdirs="$future_libdirs $libdir" ;; - esac - fi - - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/ - test "X$dir" = "X$file/" && dir= - dir="$dir$objdir" - - if test -n "$relink_command"; then - # Determine the prefix the user has applied to our future dir. - inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"` - - # Don't allow the user to place us outside of our expected - # location b/c this prevents finding dependent libraries that - # are installed to the same prefix. - # At present, this check doesn't affect windows .dll's that - # are installed into $libdir/../bin (currently, that works fine) - # but it's something to keep an eye on. - if test "$inst_prefix_dir" = "$destdir"; then - $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 - exit $EXIT_FAILURE - fi - - if test -n "$inst_prefix_dir"; then - # Stick the inst_prefix_dir data into the link command. - relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%" | $NL2SP` - else - relink_command=`$echo "$relink_command" | $SP2NL | $SED "s%@inst_prefix_dir@%%" | $NL2SP` - fi - - $echo "$modename: warning: relinking \`$file'" 1>&2 - $show "$relink_command" - if $run eval "$relink_command"; then : - else - $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 - exit $EXIT_FAILURE - fi - fi - - # See the names of the shared library. - set dummy $library_names - if test -n "$2"; then - realname="$2" - shift - shift - - srcname="$realname" - test -n "$relink_command" && srcname="$realname"T - - # Install the shared library and build the symlinks. - $show "$install_prog $dir/$srcname $destdir/$realname" - $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $? - if test -n "$stripme" && test -n "$striplib"; then - $show "$striplib $destdir/$realname" - $run eval "$striplib $destdir/$realname" || exit $? - fi - - if test "$#" -gt 0; then - # Delete the old symlinks, and create new ones. - # Try `ln -sf' first, because the `ln' binary might depend on - # the symlink we replace! Solaris /bin/ln does not understand -f, - # so we also need to try rm && ln -s. - for linkname - do - if test "$linkname" != "$realname"; then - $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" - $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })" - fi - done - fi - - # Do each command in the postinstall commands. - lib="$destdir/$realname" - cmds=$postinstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || { - lt_exit=$? - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)' - fi - - exit $lt_exit - } - done - IFS="$save_ifs" - fi - - # Install the pseudo-library for information purposes. - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - instname="$dir/$name"i - $show "$install_prog $instname $destdir/$name" - $run eval "$install_prog $instname $destdir/$name" || exit $? - - # Maybe install the static library, too. - test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" - ;; - - *.lo) - # Install (i.e. copy) a libtool object. - - # Figure out destination file name, if it wasn't already specified. - if test -n "$destname"; then - destfile="$destdir/$destname" - else - destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - destfile="$destdir/$destfile" - fi - - # Deduce the name of the destination old-style object file. - case $destfile in - *.lo) - staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"` - ;; - *.$objext) - staticdest="$destfile" - destfile= - ;; - *) - $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - # Install the libtool object if requested. - if test -n "$destfile"; then - $show "$install_prog $file $destfile" - $run eval "$install_prog $file $destfile" || exit $? - fi - - # Install the old object if enabled. - if test "$build_old_libs" = yes; then - # Deduce the name of the old-style object file. - staticobj=`$echo "X$file" | $Xsed -e "$lo2o"` - - $show "$install_prog $staticobj $staticdest" - $run eval "$install_prog \$staticobj \$staticdest" || exit $? - fi - exit $EXIT_SUCCESS - ;; - - *) - # Figure out destination file name, if it wasn't already specified. - if test -n "$destname"; then - destfile="$destdir/$destname" - else - destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - destfile="$destdir/$destfile" - fi - - # If the file is missing, and there is a .exe on the end, strip it - # because it is most likely a libtool script we actually want to - # install - stripped_ext="" - case $file in - *.exe) - if test ! -f "$file"; then - file=`$echo $file|${SED} 's,.exe$,,'` - stripped_ext=".exe" - fi - ;; - esac - - # Do a test to see if this is really a libtool program. - case $host in - *cygwin*|*mingw*) - wrapper=`$echo $file | ${SED} -e 's,.exe$,,'` - ;; - *) - wrapper=$file - ;; - esac - if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then - notinst_deplibs= - relink_command= - - # Note that it is not necessary on cygwin/mingw to append a dot to - # foo even if both foo and FILE.exe exist: automatic-append-.exe - # behavior happens only for exec(3), not for open(2)! Also, sourcing - # `FILE.' does not work on cygwin managed mounts. - # - # If there is no directory component, then add one. - case $wrapper in - */* | *\\*) . ${wrapper} ;; - *) . ./${wrapper} ;; - esac - - # Check the variables that should have been set. - if test -z "$notinst_deplibs"; then - $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2 - exit $EXIT_FAILURE - fi - - finalize=yes - for lib in $notinst_deplibs; do - # Check to see that each library is installed. - libdir= - if test -f "$lib"; then - # If there is no directory component, then add one. - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - fi - libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test - if test -n "$libdir" && test ! -f "$libfile"; then - $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2 - finalize=no - fi - done - - relink_command= - # Note that it is not necessary on cygwin/mingw to append a dot to - # foo even if both foo and FILE.exe exist: automatic-append-.exe - # behavior happens only for exec(3), not for open(2)! Also, sourcing - # `FILE.' does not work on cygwin managed mounts. - # - # If there is no directory component, then add one. - case $wrapper in - */* | *\\*) . ${wrapper} ;; - *) . ./${wrapper} ;; - esac - - outputname= - if test "$fast_install" = no && test -n "$relink_command"; then - if test "$finalize" = yes && test -z "$run"; then - tmpdir=`func_mktempdir` - file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` - outputname="$tmpdir/$file" - # Replace the output file specification. - relink_command=`$echo "X$relink_command" | $SP2NL | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g' | $NL2SP` - - $show "$relink_command" - if $run eval "$relink_command"; then : - else - $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 - ${rm}r "$tmpdir" - continue - fi - file="$outputname" - else - $echo "$modename: warning: cannot relink \`$file'" 1>&2 - fi - else - # Install the binary that we compiled earlier. - file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` - fi - fi - - # remove .exe since cygwin /usr/bin/install will append another - # one anyway - case $install_prog,$host in - */usr/bin/install*,*cygwin*) - case $file:$destfile in - *.exe:*.exe) - # this is ok - ;; - *.exe:*) - destfile=$destfile.exe - ;; - *:*.exe) - destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'` - ;; - esac - ;; - esac - $show "$install_prog$stripme $file $destfile" - $run eval "$install_prog\$stripme \$file \$destfile" || exit $? - test -n "$outputname" && ${rm}r "$tmpdir" - ;; - esac - done - - for file in $staticlibs; do - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - - # Set up the ranlib parameters. - oldlib="$destdir/$name" - - $show "$install_prog $file $oldlib" - $run eval "$install_prog \$file \$oldlib" || exit $? - - if test -n "$stripme" && test -n "$old_striplib"; then - $show "$old_striplib $oldlib" - $run eval "$old_striplib $oldlib" || exit $? - fi - - # Do each command in the postinstall commands. - cmds=$old_postinstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - done - - if test -n "$future_libdirs"; then - $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2 - fi - - if test -n "$current_libdirs"; then - # Maybe just do a dry run. - test -n "$run" && current_libdirs=" -n$current_libdirs" - exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' - else - exit $EXIT_SUCCESS - fi - ;; - - # libtool finish mode - finish) - modename="$modename: finish" - libdirs="$nonopt" - admincmds= - - if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then - for dir - do - libdirs="$libdirs $dir" - done - - for libdir in $libdirs; do - if test -n "$finish_cmds"; then - # Do each command in the finish commands. - cmds=$finish_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" || admincmds="$admincmds - $cmd" - done - IFS="$save_ifs" - fi - if test -n "$finish_eval"; then - # Do the single finish_eval. - eval cmds=\"$finish_eval\" - $run eval "$cmds" || admincmds="$admincmds - $cmds" - fi - done - fi - - # Exit here if they wanted silent mode. - test "$show" = : && exit $EXIT_SUCCESS - - $echo "X----------------------------------------------------------------------" | $Xsed - $echo "Libraries have been installed in:" - for libdir in $libdirs; do - $echo " $libdir" - done - $echo - $echo "If you ever happen to want to link against installed libraries" - $echo "in a given directory, LIBDIR, you must either use libtool, and" - $echo "specify the full pathname of the library, or use the \`-LLIBDIR'" - $echo "flag during linking and do at least one of the following:" - if test -n "$shlibpath_var"; then - $echo " - add LIBDIR to the \`$shlibpath_var' environment variable" - $echo " during execution" - fi - if test -n "$runpath_var"; then - $echo " - add LIBDIR to the \`$runpath_var' environment variable" - $echo " during linking" - fi - if test -n "$hardcode_libdir_flag_spec"; then - libdir=LIBDIR - eval flag=\"$hardcode_libdir_flag_spec\" - - $echo " - use the \`$flag' linker flag" - fi - if test -n "$admincmds"; then - $echo " - have your system administrator run these commands:$admincmds" - fi - if test -f /etc/ld.so.conf; then - $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" - fi - $echo - $echo "See any operating system documentation about shared libraries for" - $echo "more information, such as the ld(1) and ld.so(8) manual pages." - $echo "X----------------------------------------------------------------------" | $Xsed - exit $EXIT_SUCCESS - ;; - - # libtool execute mode - execute) - modename="$modename: execute" - - # The first argument is the command name. - cmd="$nonopt" - if test -z "$cmd"; then - $echo "$modename: you must specify a COMMAND" 1>&2 - $echo "$help" - exit $EXIT_FAILURE - fi - - # Handle -dlopen flags immediately. - for file in $execute_dlfiles; do - if test ! -f "$file"; then - $echo "$modename: \`$file' is not a file" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - dir= - case $file in - *.la) - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - # Read the libtool library. - dlname= - library_names= - - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Skip this library if it cannot be dlopened. - if test -z "$dlname"; then - # Warn if it was a shared library. - test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'" - continue - fi - - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$file" && dir=. - - if test -f "$dir/$objdir/$dlname"; then - dir="$dir/$objdir" - else - if test ! -f "$dir/$dlname"; then - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit $EXIT_FAILURE - fi - fi - ;; - - *.lo) - # Just add the directory containing the .lo file. - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$file" && dir=. - ;; - - *) - $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2 - continue - ;; - esac - - # Get the absolute pathname. - absdir=`cd "$dir" && pwd` - test -n "$absdir" && dir="$absdir" - - # Now add the directory to shlibpath_var. - if eval "test -z \"\$$shlibpath_var\""; then - eval "$shlibpath_var=\"\$dir\"" - else - eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" - fi - done - - # This variable tells wrapper scripts just to set shlibpath_var - # rather than running their programs. - libtool_execute_magic="$magic" - - # Check if any of the arguments is a wrapper script. - args= - for file - do - case $file in - -*) ;; - *) - # Do a test to see if this is really a libtool program. - if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Transform arg to wrapped name. - file="$progdir/$program" - fi - ;; - esac - # Quote arguments (to preserve shell metacharacters). - file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"` - args="$args \"$file\"" - done - - if test -z "$run"; then - if test -n "$shlibpath_var"; then - # Export the shlibpath_var. - eval "export $shlibpath_var" - fi - - # Restore saved environment variables - for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES - do - eval "if test \"\${save_$lt_var+set}\" = set; then - $lt_var=\$save_$lt_var; export $lt_var - fi" - done - - # Now prepare to actually exec the command. - exec_cmd="\$cmd$args" - else - # Display what would be done. - if test -n "$shlibpath_var"; then - eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\"" - $echo "export $shlibpath_var" - fi - $echo "$cmd$args" - exit $EXIT_SUCCESS - fi - ;; - - # libtool clean and uninstall mode - clean | uninstall) - modename="$modename: $mode" - rm="$nonopt" - files= - rmforce= - exit_status=0 - - # This variable tells wrapper scripts just to set variables rather - # than running their programs. - libtool_install_magic="$magic" - - for arg - do - case $arg in - -f) rm="$rm $arg"; rmforce=yes ;; - -*) rm="$rm $arg" ;; - *) files="$files $arg" ;; - esac - done - - if test -z "$rm"; then - $echo "$modename: you must specify an RM program" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - fi - - rmdirs= - - origobjdir="$objdir" - for file in $files; do - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - if test "X$dir" = "X$file"; then - dir=. - objdir="$origobjdir" - else - objdir="$dir/$origobjdir" - fi - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - test "$mode" = uninstall && objdir="$dir" - - # Remember objdir for removal later, being careful to avoid duplicates - if test "$mode" = clean; then - case " $rmdirs " in - *" $objdir "*) ;; - *) rmdirs="$rmdirs $objdir" ;; - esac - fi - - # Don't error if the file doesn't exist and rm -f was used. - if (test -L "$file") >/dev/null 2>&1 \ - || (test -h "$file") >/dev/null 2>&1 \ - || test -f "$file"; then - : - elif test -d "$file"; then - exit_status=1 - continue - elif test "$rmforce" = yes; then - continue - fi - - rmfiles="$file" - - case $name in - *.la) - # Possibly a libtool archive, so verify it. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - . $dir/$name - - # Delete the libtool libraries and symlinks. - for n in $library_names; do - rmfiles="$rmfiles $objdir/$n" - done - test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" - - case "$mode" in - clean) - case " $library_names " in - # " " in the beginning catches empty $dlname - *" $dlname "*) ;; - *) rmfiles="$rmfiles $objdir/$dlname" ;; - esac - test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" - ;; - uninstall) - if test -n "$library_names"; then - # Do each command in the postuninstall commands. - cmds=$postuninstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" - if test "$?" -ne 0 && test "$rmforce" != yes; then - exit_status=1 - fi - done - IFS="$save_ifs" - fi - - if test -n "$old_library"; then - # Do each command in the old_postuninstall commands. - cmds=$old_postuninstall_cmds - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - eval cmd=\"$cmd\" - $show "$cmd" - $run eval "$cmd" - if test "$?" -ne 0 && test "$rmforce" != yes; then - exit_status=1 - fi - done - IFS="$save_ifs" - fi - # FIXME: should reinstall the best remaining shared library. - ;; - esac - fi - ;; - - *.lo) - # Possibly a libtool object, so verify it. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - - # Read the .lo file - . $dir/$name - - # Add PIC object to the list of files to remove. - if test -n "$pic_object" \ - && test "$pic_object" != none; then - rmfiles="$rmfiles $dir/$pic_object" - fi - - # Add non-PIC object to the list of files to remove. - if test -n "$non_pic_object" \ - && test "$non_pic_object" != none; then - rmfiles="$rmfiles $dir/$non_pic_object" - fi - fi - ;; - - *) - if test "$mode" = clean ; then - noexename=$name - case $file in - *.exe) - file=`$echo $file|${SED} 's,.exe$,,'` - noexename=`$echo $name|${SED} 's,.exe$,,'` - # $file with .exe has already been added to rmfiles, - # add $file without .exe - rmfiles="$rmfiles $file" - ;; - esac - # Do a test to see if this is a libtool program. - if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - relink_command= - . $dir/$noexename - - # note $name still contains .exe if it was in $file originally - # as does the version of $file that was added into $rmfiles - rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" - if test "$fast_install" = yes && test -n "$relink_command"; then - rmfiles="$rmfiles $objdir/lt-$name" - fi - if test "X$noexename" != "X$name" ; then - rmfiles="$rmfiles $objdir/lt-${noexename}.c" - fi - fi - fi - ;; - esac - $show "$rm $rmfiles" - $run $rm $rmfiles || exit_status=1 - done - objdir="$origobjdir" - - # Try to remove the ${objdir}s in the directories where we deleted files - for dir in $rmdirs; do - if test -d "$dir"; then - $show "rmdir $dir" - $run rmdir $dir >/dev/null 2>&1 - fi - done - - exit $exit_status - ;; - - "") - $echo "$modename: you must specify a MODE" 1>&2 - $echo "$generic_help" 1>&2 - exit $EXIT_FAILURE - ;; - esac - - if test -z "$exec_cmd"; then - $echo "$modename: invalid operation mode \`$mode'" 1>&2 - $echo "$generic_help" 1>&2 - exit $EXIT_FAILURE - fi -fi # test -z "$show_help" - -if test -n "$exec_cmd"; then - eval exec $exec_cmd - exit $EXIT_FAILURE -fi - -# We need to display help for each of the modes. -case $mode in -"") $echo \ -"Usage: $modename [OPTION]... [MODE-ARG]... - -Provide generalized library-building support services. - - --config show all configuration variables - --debug enable verbose shell tracing --n, --dry-run display commands without modifying any files - --features display basic configuration information and exit - --finish same as \`--mode=finish' - --help display this help message and exit - --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS] - --quiet same as \`--silent' - --silent don't print informational messages - --tag=TAG use configuration variables from tag TAG - --version print version information - -MODE must be one of the following: - - clean remove files from the build directory - compile compile a source file into a libtool object - execute automatically set library path, then run a program - finish complete the installation of libtool libraries - install install libraries or executables - link create a library or an executable - uninstall remove libraries from an installed directory - -MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for -a more detailed description of MODE. - -Report bugs to ." - exit $EXIT_SUCCESS - ;; - -clean) - $echo \ -"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE... - -Remove files from the build directory. - -RM is the name of the program to use to delete files associated with each FILE -(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed -to RM. - -If FILE is a libtool library, object or program, all the files associated -with it are deleted. Otherwise, only FILE itself is deleted using RM." - ;; - -compile) - $echo \ -"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE - -Compile a source file into a libtool library object. - -This mode accepts the following additional options: - - -o OUTPUT-FILE set the output file name to OUTPUT-FILE - -prefer-pic try to building PIC objects only - -prefer-non-pic try to building non-PIC objects only - -static always build a \`.o' file suitable for static linking - -COMPILE-COMMAND is a command to be used in creating a \`standard' object file -from the given SOURCEFILE. - -The output file name is determined by removing the directory component from -SOURCEFILE, then substituting the C source code suffix \`.c' with the -library object suffix, \`.lo'." - ;; - -execute) - $echo \ -"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]... - -Automatically set library path, then run a program. - -This mode accepts the following additional options: - - -dlopen FILE add the directory containing FILE to the library path - -This mode sets the library path environment variable according to \`-dlopen' -flags. - -If any of the ARGS are libtool executable wrappers, then they are translated -into their corresponding uninstalled binary, and any of their required library -directories are added to the library path. - -Then, COMMAND is executed, with ARGS as arguments." - ;; - -finish) - $echo \ -"Usage: $modename [OPTION]... --mode=finish [LIBDIR]... - -Complete the installation of libtool libraries. - -Each LIBDIR is a directory that contains libtool libraries. - -The commands that this mode executes may require superuser privileges. Use -the \`--dry-run' option if you just want to see what would be executed." - ;; - -install) - $echo \ -"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND... - -Install executables or libraries. - -INSTALL-COMMAND is the installation command. The first component should be -either the \`install' or \`cp' program. - -The rest of the components are interpreted as arguments to that command (only -BSD-compatible install options are recognized)." - ;; - -link) - $echo \ -"Usage: $modename [OPTION]... --mode=link LINK-COMMAND... - -Link object files or libraries together to form another library, or to -create an executable program. - -LINK-COMMAND is a command using the C compiler that you would use to create -a program from several object files. - -The following components of LINK-COMMAND are treated specially: - - -all-static do not do any dynamic linking at all - -avoid-version do not add a version suffix if possible - -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime - -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols - -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) - -export-symbols SYMFILE - try to export only the symbols listed in SYMFILE - -export-symbols-regex REGEX - try to export only the symbols matching REGEX - -LLIBDIR search LIBDIR for required installed libraries - -lNAME OUTPUT-FILE requires the installed library libNAME - -module build a library that can dlopened - -no-fast-install disable the fast-install mode - -no-install link a not-installable executable - -no-undefined declare that a library does not refer to external symbols - -o OUTPUT-FILE create OUTPUT-FILE from the specified objects - -objectlist FILE Use a list of object files found in FILE to specify objects - -precious-files-regex REGEX - don't remove output files matching REGEX - -release RELEASE specify package release information - -rpath LIBDIR the created library will eventually be installed in LIBDIR - -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries - -static do not do any dynamic linking of uninstalled libtool libraries - -static-libtool-libs - do not do any dynamic linking of libtool libraries - -version-info CURRENT[:REVISION[:AGE]] - specify library version info [each variable defaults to 0] - -All other options (arguments beginning with \`-') are ignored. - -Every other argument is treated as a filename. Files ending in \`.la' are -treated as uninstalled libtool libraries, other files are standard or library -object files. - -If the OUTPUT-FILE ends in \`.la', then a libtool library is created, -only library objects (\`.lo' files) may be specified, and \`-rpath' is -required, except when creating a convenience library. - -If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created -using \`ar' and \`ranlib', or on Windows using \`lib'. - -If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file -is created, otherwise an executable program is created." - ;; - -uninstall) - $echo \ -"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... - -Remove libraries from an installation directory. - -RM is the name of the program to use to delete files associated with each FILE -(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed -to RM. - -If FILE is a libtool library, all the files associated with it are deleted. -Otherwise, only FILE itself is deleted using RM." - ;; - -*) - $echo "$modename: invalid operation mode \`$mode'" 1>&2 - $echo "$help" 1>&2 - exit $EXIT_FAILURE - ;; -esac - -$echo -$echo "Try \`$modename --help' for more information about other modes." - -exit $? - -# The TAGs below are defined such that we never get into a situation -# in which we disable both kinds of libraries. Given conflicting -# choices, we go for a static library, that is the most portable, -# since we can't tell whether shared libraries were disabled because -# the user asked for that or because the platform doesn't support -# them. This is particularly important on AIX, because we don't -# support having both static and shared libraries enabled at the same -# time on that platform, so we default to a shared-only configuration. -# If a disable-shared tag is given, we'll fallback to a static-only -# configuration. But we'll never go from static-only to shared-only. - -# ### BEGIN LIBTOOL TAG CONFIG: disable-shared -disable_libs=shared -# ### END LIBTOOL TAG CONFIG: disable-shared - -# ### BEGIN LIBTOOL TAG CONFIG: disable-static -disable_libs=static -# ### END LIBTOOL TAG CONFIG: disable-static - -# Local Variables: -# mode:shell-script -# sh-indentation:2 -# End: diff --git a/libs/freetdm/build/missing b/libs/freetdm/build/missing deleted file mode 100755 index e7ef83a1c2..0000000000 --- a/libs/freetdm/build/missing +++ /dev/null @@ -1,360 +0,0 @@ -#! /bin/sh -# Common stub for a few missing GNU programs while installing. - -scriptversion=2003-09-02.23 - -# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 -# Free Software Foundation, Inc. -# Originally by Fran,cois Pinard , 1996. - -# 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, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -if test $# -eq 0; then - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 -fi - -run=: - -# In the cases where this matters, `missing' is being run in the -# srcdir already. -if test -f configure.ac; then - configure_ac=configure.ac -else - configure_ac=configure.in -fi - -msg="missing on your system" - -case "$1" in ---run) - # Try to run requested program, and just exit if it succeeds. - run= - shift - "$@" && exit 0 - # Exit code 63 means version mismatch. This often happens - # when the user try to use an ancient version of a tool on - # a file that requires a minimum version. In this case we - # we should proceed has if the program had been absent, or - # if --run hadn't been passed. - if test $? = 63; then - run=: - msg="probably too old" - fi - ;; -esac - -# If it does not exist, or fails to run (possibly an outdated version), -# try to emulate it. -case "$1" in - - -h|--h|--he|--hel|--help) - echo "\ -$0 [OPTION]... PROGRAM [ARGUMENT]... - -Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an -error status if there is no known handling for PROGRAM. - -Options: - -h, --help display this help and exit - -v, --version output version information and exit - --run try to run the given command, and emulate it if it fails - -Supported PROGRAM values: - aclocal touch file \`aclocal.m4' - autoconf touch file \`configure' - autoheader touch file \`config.h.in' - automake touch all \`Makefile.in' files - bison create \`y.tab.[ch]', if possible, from existing .[ch] - flex create \`lex.yy.c', if possible, from existing .c - help2man touch the output file - lex create \`lex.yy.c', if possible, from existing .c - makeinfo touch the output file - tar try tar, gnutar, gtar, then tar without non-portable flags - yacc create \`y.tab.[ch]', if possible, from existing .[ch] - -Send bug reports to ." - ;; - - -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing $scriptversion (GNU Automake)" - ;; - - -*) - echo 1>&2 "$0: Unknown \`$1' option" - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 - ;; - - aclocal*) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`acinclude.m4' or \`${configure_ac}'. You might want - to install the \`Automake' and \`Perl' packages. Grab them from - any GNU archive site." - touch aclocal.m4 - ;; - - autoconf) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`${configure_ac}'. You might want to install the - \`Autoconf' and \`GNU m4' packages. Grab them from any GNU - archive site." - touch configure - ;; - - autoheader) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`acconfig.h' or \`${configure_ac}'. You might want - to install the \`Autoconf' and \`GNU m4' packages. Grab them - from any GNU archive site." - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` - test -z "$files" && files="config.h" - touch_files= - for f in $files; do - case "$f" in - *:*) touch_files="$touch_files "`echo "$f" | - sed -e 's/^[^:]*://' -e 's/:.*//'`;; - *) touch_files="$touch_files $f.in";; - esac - done - touch $touch_files - ;; - - automake*) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. - You might want to install the \`Automake' and \`Perl' packages. - Grab them from any GNU archive site." - find . -type f -name Makefile.am -print | - sed 's/\.am$/.in/' | - while read f; do touch "$f"; done - ;; - - autom4te) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is needed, but is $msg. - You might have modified some files without having the - proper tools for further handling them. - You can get \`$1' as part of \`Autoconf' from any GNU - archive site." - - file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` - test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` - if test -f "$file"; then - touch $file - else - test -z "$file" || exec >$file - echo "#! /bin/sh" - echo "# Created by GNU Automake missing as a replacement of" - echo "# $ $@" - echo "exit 0" - chmod +x $file - exit 1 - fi - ;; - - bison|yacc) - echo 1>&2 "\ -WARNING: \`$1' $msg. You should only need it if - you modified a \`.y' file. You may need the \`Bison' package - in order for those modifications to take effect. You can get - \`Bison' from any GNU archive site." - rm -f y.tab.c y.tab.h - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.y) - SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.c - fi - SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.h - fi - ;; - esac - fi - if [ ! -f y.tab.h ]; then - echo >y.tab.h - fi - if [ ! -f y.tab.c ]; then - echo 'main() { return 0; }' >y.tab.c - fi - ;; - - lex|flex) - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a \`.l' file. You may need the \`Flex' package - in order for those modifications to take effect. You can get - \`Flex' from any GNU archive site." - rm -f lex.yy.c - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.l) - SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" lex.yy.c - fi - ;; - esac - fi - if [ ! -f lex.yy.c ]; then - echo 'main() { return 0; }' >lex.yy.c - fi - ;; - - help2man) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a dependency of a manual page. You may need the - \`Help2man' package in order for those modifications to take - effect. You can get \`Help2man' from any GNU archive site." - - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` - fi - if [ -f "$file" ]; then - touch $file - else - test -z "$file" || exec >$file - echo ".ab help2man is required to generate this page" - exit 1 - fi - ;; - - makeinfo) - if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then - # We have makeinfo, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is $msg. You should only need it if - you modified a \`.texi' or \`.texinfo' file, or any other file - indirectly affecting the aspect of the manual. The spurious - call might also be the consequence of using a buggy \`make' (AIX, - DU, IRIX). You might want to install the \`Texinfo' package or - the \`GNU make' package. Grab either from any GNU archive site." - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` - file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` - fi - touch $file - ;; - - tar) - shift - if test -n "$run"; then - echo 1>&2 "ERROR: \`tar' requires --run" - exit 1 - fi - - # We have already tried tar in the generic part. - # Look for gnutar/gtar before invocation to avoid ugly error - # messages. - if (gnutar --version > /dev/null 2>&1); then - gnutar "$@" && exit 0 - fi - if (gtar --version > /dev/null 2>&1); then - gtar "$@" && exit 0 - fi - firstarg="$1" - if shift; then - case "$firstarg" in - *o*) - firstarg=`echo "$firstarg" | sed s/o//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - case "$firstarg" in - *h*) - firstarg=`echo "$firstarg" | sed s/h//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - fi - - echo 1>&2 "\ -WARNING: I can't seem to be able to run \`tar' with the given arguments. - You may want to install GNU tar or Free paxutils, or check the - command line arguments." - exit 1 - ;; - - *) - echo 1>&2 "\ -WARNING: \`$1' is needed, and is $msg. - You might have modified some files without having the - proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequisites for installing - this package. You may also peek at any GNU archive site, in case - some other package would contain this missing \`$1' program." - exit 1 - ;; -esac - -exit 0 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" -# End: diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index cb613a79d5..653bd01d2d 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -6,7 +6,7 @@ AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) AC_CONFIG_SRCDIR([src/zap_io.c]) AC_CONFIG_AUX_DIR(build) -#AM_INIT_AUTOMAKE(libopenzap,0.1) +AM_INIT_AUTOMAKE(libopenzap,0.1) # Checks for programs. AC_PROG_CC From 638ec7972d8e272538572bc5853a1a2e81645de1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 05:01:04 +0000 Subject: [PATCH 1227/1766] remove redundant defines git-svn-id: http://svn.openzap.org/svn/openzap/trunk@635 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 12 ------------ libs/openzap/configure.ac | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 673f03936b..dd0fb0cb88 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -29,30 +29,18 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CC = @CC@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -DEFS = @DEFS@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ ###For libpcap CFLAGS+= -D_GNU_SOURCE #### -LIBS = @LIBS@ - ###For libpcap LIBS+= -lpcap #### -DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ -SOLINK = @SOLINK@ -OZ_SRCDIR=@oz_srcdir@ -oz_builddir=@oz_builddir@ SRC=src top_builddir=@oz_builddir@ -INSTALL=@INSTALL@ -LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 653bd01d2d..471030debf 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -16,9 +16,9 @@ AC_PREFIX_DEFAULT(/usr/local/openzap) # Absolute source/build directory -oz_srcdir=`(cd $srcdir && pwd)` +OZ_SRCDIR=`(cd $srcdir && pwd)` oz_builddir=`pwd` -AC_SUBST(oz_srcdir) +AC_SUBST(OZ_SRCDIR) AC_SUBST(oz_builddir) #override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) From 02e0f005e1cc53ec476f7c45d5e47f076d298b50 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 05:01:04 +0000 Subject: [PATCH 1228/1766] remove redundant defines git-svn-id: http://svn.openzap.org/svn/openzap/trunk@635 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 12 ------------ libs/freetdm/configure.ac | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 673f03936b..dd0fb0cb88 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -29,30 +29,18 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CC = @CC@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -DEFS = @DEFS@ CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ ###For libpcap CFLAGS+= -D_GNU_SOURCE #### -LIBS = @LIBS@ - ###For libpcap LIBS+= -lpcap #### -DYNAMIC_LIB_EXTEN = @DYNAMIC_LIB_EXTEN@ -SOLINK = @SOLINK@ -OZ_SRCDIR=@oz_srcdir@ -oz_builddir=@oz_builddir@ SRC=src top_builddir=@oz_builddir@ -INSTALL=@INSTALL@ -LIBTOOL=@LIBTOOL@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 653bd01d2d..471030debf 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -16,9 +16,9 @@ AC_PREFIX_DEFAULT(/usr/local/openzap) # Absolute source/build directory -oz_srcdir=`(cd $srcdir && pwd)` +OZ_SRCDIR=`(cd $srcdir && pwd)` oz_builddir=`pwd` -AC_SUBST(oz_srcdir) +AC_SUBST(OZ_SRCDIR) AC_SUBST(oz_builddir) #override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) From 07081b72451d30f97a01312c2df4681101a7f05f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 05:41:40 +0000 Subject: [PATCH 1229/1766] automake build of libopenzap and install git-svn-id: http://svn.openzap.org/svn/openzap/trunk@636 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 117 ++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 68 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index dd0fb0cb88..b621f34ead 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -29,15 +29,7 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ - -###For libpcap -CFLAGS+= -D_GNU_SOURCE -#### - -###For libpcap -LIBS+= -lpcap -#### +PREFIX=$(prefix) SRC=src top_builddir=@oz_builddir@ @@ -45,14 +37,16 @@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" @COMP_VENDOR_CFLAGS@ @DEFS@ -COMPILE = $(CC) $(CFLAGS) $(INCS) +COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) -LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ +LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(MY_CFLAGS) $(LDFLAGS) -o $@ libdir = $(PREFIX)/lib/ -SOURCES=\ +library_includedir = $(PREFIX)/include + +libopenzap_la_SOURCES = \ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ @@ -67,6 +61,24 @@ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ $(SRC)/zap_dso.c +library_include_HEADERS = \ +$(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_dso.h \ +$(SRC)/include/zap_types.h + BOOST_SOURCE=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -93,22 +105,6 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c - -OBJS=\ -$(SRC)/hashtable.o \ -$(SRC)/hashtable_itr.o \ -$(SRC)/zap_io.o \ -$(SRC)/zap_config.o \ -$(SRC)/zap_callerid.o \ -$(SRC)/fsk.o \ -$(SRC)/uart.o \ -$(SRC)/g711.o \ -$(SRC)/libteletone_detect.o \ -$(SRC)/libteletone_generate.o \ -$(SRC)/zap_buffer.o \ -$(SRC)/zap_threadmutex.o \ -$(SRC)/zap_dso.o - BOOST_OBJS=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o @@ -135,25 +131,6 @@ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o - -HEADER= $(SRC)/include/fsk.h \ -$(SRC)/include/g711.h \ -$(SRC)/include/hashtable.h \ -$(SRC)/include/hashtable_itr.h \ -$(SRC)/include/hashtable_private.h \ -$(SRC)/include/libteletone_detect.h \ -$(SRC)/include/libteletone_generate.h \ -$(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ -$(SRC)/include/sangoma_tdm_api.h \ -$(SRC)/include/uart.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_dso.h \ -$(SRC)/include/zap_types.h - - ISDN_HEADER=\ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ @@ -164,25 +141,18 @@ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h +lib_LTLIBRARIES = libopenzap.la +libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) +libopenzap_la_LIBADD = $(LIBS) -MYLIB=libopenzap.$(DYNAMIC_LIB_EXTEN) -PREFIX=@prefix@ +MYLIB=libopenzap.la PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) -#ifneq ($(PIKA_DIR),) -#ifneq ($(PIKA_LIB),) -#OBJS += $(SRC)/zap_pika.o -#CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -#ADD_OBJS = $(PIKA_LIB) -#endif -#endif - all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod -$(MYLIB): $(OBJS) $(HEADER) $(SOURCES) - $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) testapp: $(SRC)/testapp.o $(MYLIB) $(LINK) $(SRC)/testapp.o ./$(MYLIB) $(LIBS) @@ -231,18 +201,19 @@ mod_openzap-clean: clean: rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) -install: all - @mkdir -p $(DESTDIR)$(PREFIX) - @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf) +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(PREFIX) + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) - @mkdir -p $(DESTDIR)$(PREFIX)/lib - @$(LTINSTALL) $(MYLIB) $(DESTDIR)$(PREFIX)/lib/ - @mkdir -p $(DESTDIR)$(PREFIX)/mod + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/lib + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/mod @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed -uninstall: +uninstall: oz-uninstall + +oz-uninstall: @rm -fr $(DESTDIR)$(PREFIX) $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) @@ -262,10 +233,20 @@ $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) +###For libpcap +ISDN_CFLAGS = -D_GNU_SOURCE +#### + +###For libpcap +ISDN_LIBS = -lpcap +#### + $(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c + $(LTCOMPILE) -c $< -o $@ $(ISDN_CFLAGS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o - $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) + $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) $(ISDN_LIBS) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) $(ISDN_OBJS2): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c From f954fa90015e0df186cb2ce558bd3850e5bd9d7b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 05:41:40 +0000 Subject: [PATCH 1230/1766] automake build of libopenzap and install git-svn-id: http://svn.openzap.org/svn/openzap/trunk@636 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 117 ++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 68 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index dd0fb0cb88..b621f34ead 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -29,15 +29,7 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ - -###For libpcap -CFLAGS+= -D_GNU_SOURCE -#### - -###For libpcap -LIBS+= -lpcap -#### +PREFIX=$(prefix) SRC=src top_builddir=@oz_builddir@ @@ -45,14 +37,16 @@ LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f CCLD = $(CC) INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -CFLAGS+= $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" @COMP_VENDOR_CFLAGS@ @DEFS@ -COMPILE = $(CC) $(CFLAGS) $(INCS) +COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) -LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ +LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(MY_CFLAGS) $(LDFLAGS) -o $@ libdir = $(PREFIX)/lib/ -SOURCES=\ +library_includedir = $(PREFIX)/include + +libopenzap_la_SOURCES = \ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ @@ -67,6 +61,24 @@ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ $(SRC)/zap_dso.c +library_include_HEADERS = \ +$(SRC)/include/fsk.h \ +$(SRC)/include/g711.h \ +$(SRC)/include/hashtable.h \ +$(SRC)/include/hashtable_itr.h \ +$(SRC)/include/hashtable_private.h \ +$(SRC)/include/libteletone_detect.h \ +$(SRC)/include/libteletone_generate.h \ +$(SRC)/include/libteletone.h \ +$(SRC)/include/openzap.h \ +$(SRC)/include/sangoma_tdm_api.h \ +$(SRC)/include/uart.h \ +$(SRC)/include/zap_buffer.h \ +$(SRC)/include/zap_config.h \ +$(SRC)/include/zap_threadmutex.h \ +$(SRC)/include/zap_dso.h \ +$(SRC)/include/zap_types.h + BOOST_SOURCE=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -93,22 +105,6 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c - -OBJS=\ -$(SRC)/hashtable.o \ -$(SRC)/hashtable_itr.o \ -$(SRC)/zap_io.o \ -$(SRC)/zap_config.o \ -$(SRC)/zap_callerid.o \ -$(SRC)/fsk.o \ -$(SRC)/uart.o \ -$(SRC)/g711.o \ -$(SRC)/libteletone_detect.o \ -$(SRC)/libteletone_generate.o \ -$(SRC)/zap_buffer.o \ -$(SRC)/zap_threadmutex.o \ -$(SRC)/zap_dso.o - BOOST_OBJS=\ $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o @@ -135,25 +131,6 @@ $(SRC)/isdn/5ESSStateNT.o \ $(SRC)/isdn/5ESSStateTE.o \ $(SRC)/isdn/Q932mes.o - -HEADER= $(SRC)/include/fsk.h \ -$(SRC)/include/g711.h \ -$(SRC)/include/hashtable.h \ -$(SRC)/include/hashtable_itr.h \ -$(SRC)/include/hashtable_private.h \ -$(SRC)/include/libteletone_detect.h \ -$(SRC)/include/libteletone_generate.h \ -$(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ -$(SRC)/include/sangoma_tdm_api.h \ -$(SRC)/include/uart.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_dso.h \ -$(SRC)/include/zap_types.h - - ISDN_HEADER=\ $(SRC)/isdn/include/mfifo.h \ $(SRC)/isdn/include/national.h \ @@ -164,25 +141,18 @@ $(SRC)/isdn/include/Q931.h \ $(SRC)/isdn/include/Q931ie.h \ $(SRC)/isdn/include/Q932.h +lib_LTLIBRARIES = libopenzap.la +libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) +libopenzap_la_LIBADD = $(LIBS) -MYLIB=libopenzap.$(DYNAMIC_LIB_EXTEN) -PREFIX=@prefix@ +MYLIB=libopenzap.la PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) -#ifneq ($(PIKA_DIR),) -#ifneq ($(PIKA_LIB),) -#OBJS += $(SRC)/zap_pika.o -#CFLAGS += -DZAP_PIKA_SUPPORT -I$(PIKA_DIR) -#ADD_OBJS = $(PIKA_LIB) -#endif -#endif - all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod -$(MYLIB): $(OBJS) $(HEADER) $(SOURCES) - $(LINK) $(SOLINK) -o $(MYLIB) $(OBJS) $(ADD_OBJS) $(LIBS) testapp: $(SRC)/testapp.o $(MYLIB) $(LINK) $(SRC)/testapp.o ./$(MYLIB) $(LIBS) @@ -231,18 +201,19 @@ mod_openzap-clean: clean: rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) -install: all - @mkdir -p $(DESTDIR)$(PREFIX) - @[ -d "$(DESTDIR)$(PREFIX)/conf" ] || ( mkdir -p $(DESTDIR)$(PREFIX)/conf) +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(PREFIX) + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) - @mkdir -p $(DESTDIR)$(PREFIX)/lib - @$(LTINSTALL) $(MYLIB) $(DESTDIR)$(PREFIX)/lib/ - @mkdir -p $(DESTDIR)$(PREFIX)/mod + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/lib + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/mod @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed -uninstall: +uninstall: oz-uninstall + +oz-uninstall: @rm -fr $(DESTDIR)$(PREFIX) $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) @@ -262,10 +233,20 @@ $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) +###For libpcap +ISDN_CFLAGS = -D_GNU_SOURCE +#### + +###For libpcap +ISDN_LIBS = -lpcap +#### + $(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c + $(LTCOMPILE) -c $< -o $@ $(ISDN_CFLAGS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o - $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) -rpath $(libdir) + $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) $(ISDN_LIBS) -rpath $(libdir) isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) $(ISDN_OBJS2): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c From a88518e0f9451c241d701be9fb8127a850967758 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 06:06:43 +0000 Subject: [PATCH 1231/1766] more automake build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@637 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index b621f34ead..3d9310e039 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -153,33 +153,32 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog #testapp testcid +#testapp_SOURCES = $(SRC)/testapp.c +#testapp_LDADD = libopenzap.la +#testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +#testcid_SOURCES = $(SRC)/testcid.c +#testcid_LDADD = libopenzap.la +#testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testtones_SOURCES = $(SRC)/testtones.c +testtones_LDADD = libopenzap.la +testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_tones_SOURCES = $(SRC)/detect_tones.c +detect_tones_LDADD = libopenzap.la +detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_dtmf_SOURCES = $(SRC)/detect_dtmf.c +detect_dtmf_LDADD = libopenzap.la +detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testisdn_SOURCES = $(SRC)/testisdn.c +testisdn_LDADD = libopenzap.la +testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testboost_SOURCES = $(SRC)/testboost.c +testboost_LDADD = libopenzap.la +testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testanalog_SOURCES = $(SRC)/testanalog.c +testanalog_LDADD = libopenzap.la +testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -testapp: $(SRC)/testapp.o $(MYLIB) - $(LINK) $(SRC)/testapp.o ./$(MYLIB) $(LIBS) - -testcid: $(SRC)/testcid.o $(MYLIB) - $(LINK) $(SRC)/testcid.o ./$(MYLIB) $(LIBS) - -testtones: $(SRC)/testtones.o $(MYLIB) - $(LINK) $(SRC)/testtones.o ./$(MYLIB) $(LIBS) - -detect_tones: $(SRC)/detect_tones.o $(MYLIB) - $(LINK) $(SRC)/detect_tones.o ./$(MYLIB) $(LIBS) - -detect_dtmf: $(SRC)/detect_dtmf.o $(MYLIB) - $(LINK) $(SRC)/detect_dtmf.o ./$(MYLIB) $(LIBS) - -testisdn: $(SRC)/testisdn.o $(MYLIB) - $(LINK) $(SRC)/testisdn.o ./$(MYLIB) $(LIBS) - -testboost: $(SRC)/testboost.o $(MYLIB) - $(LINK) $(SRC)/testboost.o ./$(MYLIB) $(LIBS) - -testanalog: $(SRC)/testanalog.o $(MYLIB) - $(LINK) $(SRC)/testanalog.o ./$(MYLIB) $(LIBS) - -$(SRC)/zap_io.o: $(SRC)/zap_io.c - $(LTCOMPILE) $(MOD_CFLAGS) -c $< -o $@ %.o: %.c $(HEADER) $(LTCOMPILE) -c $< -o $@ From f36e39bc772d024a3c56ce5a0399b8b808a5f3ef Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 06:06:43 +0000 Subject: [PATCH 1232/1766] more automake build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@637 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index b621f34ead..3d9310e039 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -153,33 +153,32 @@ PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog #testapp testcid +#testapp_SOURCES = $(SRC)/testapp.c +#testapp_LDADD = libopenzap.la +#testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +#testcid_SOURCES = $(SRC)/testcid.c +#testcid_LDADD = libopenzap.la +#testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testtones_SOURCES = $(SRC)/testtones.c +testtones_LDADD = libopenzap.la +testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_tones_SOURCES = $(SRC)/detect_tones.c +detect_tones_LDADD = libopenzap.la +detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_dtmf_SOURCES = $(SRC)/detect_dtmf.c +detect_dtmf_LDADD = libopenzap.la +detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testisdn_SOURCES = $(SRC)/testisdn.c +testisdn_LDADD = libopenzap.la +testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testboost_SOURCES = $(SRC)/testboost.c +testboost_LDADD = libopenzap.la +testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testanalog_SOURCES = $(SRC)/testanalog.c +testanalog_LDADD = libopenzap.la +testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -testapp: $(SRC)/testapp.o $(MYLIB) - $(LINK) $(SRC)/testapp.o ./$(MYLIB) $(LIBS) - -testcid: $(SRC)/testcid.o $(MYLIB) - $(LINK) $(SRC)/testcid.o ./$(MYLIB) $(LIBS) - -testtones: $(SRC)/testtones.o $(MYLIB) - $(LINK) $(SRC)/testtones.o ./$(MYLIB) $(LIBS) - -detect_tones: $(SRC)/detect_tones.o $(MYLIB) - $(LINK) $(SRC)/detect_tones.o ./$(MYLIB) $(LIBS) - -detect_dtmf: $(SRC)/detect_dtmf.o $(MYLIB) - $(LINK) $(SRC)/detect_dtmf.o ./$(MYLIB) $(LIBS) - -testisdn: $(SRC)/testisdn.o $(MYLIB) - $(LINK) $(SRC)/testisdn.o ./$(MYLIB) $(LIBS) - -testboost: $(SRC)/testboost.o $(MYLIB) - $(LINK) $(SRC)/testboost.o ./$(MYLIB) $(LIBS) - -testanalog: $(SRC)/testanalog.o $(MYLIB) - $(LINK) $(SRC)/testanalog.o ./$(MYLIB) $(LIBS) - -$(SRC)/zap_io.o: $(SRC)/zap_io.c - $(LTCOMPILE) $(MOD_CFLAGS) -c $< -o $@ %.o: %.c $(HEADER) $(LTCOMPILE) -c $< -o $@ From e56774994b98603b26fde7e9e456c616a67bdcae Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 06:16:53 +0000 Subject: [PATCH 1233/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@638 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 145 ++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 77 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 3d9310e039..055f6f0baf 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -32,18 +32,14 @@ PREFIX=$(prefix) SRC=src -top_builddir=@oz_builddir@ -LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) -LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f -CCLD = $(CC) + INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" @COMP_VENDOR_CFLAGS@ @DEFS@ - COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) -LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(MY_CFLAGS) $(LDFLAGS) -o $@ -libdir = $(PREFIX)/lib/ +LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ +libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include libopenzap_la_SOURCES = \ @@ -79,68 +75,6 @@ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_dso.h \ $(SRC)/include/zap_types.h -BOOST_SOURCE=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - -ISDN_SOURCE=\ -$(SRC)/isdn/EuroISDNStateNT.c \ -$(SRC)/isdn/EuroISDNStateTE.c \ -$(SRC)/isdn/mfifo.c \ -$(SRC)/isdn/Q921.c \ -$(SRC)/isdn/Q931api.c \ -$(SRC)/isdn/Q931.c \ -$(SRC)/isdn/Q931ie.c \ -$(SRC)/isdn/Q931mes.c \ -$(SRC)/isdn/Q931StateNT.c \ -$(SRC)/isdn/Q931StateTE.c \ -$(SRC)/isdn/nationalmes.c \ -$(SRC)/isdn/nationalStateNT.c \ -$(SRC)/isdn/nationalStateTE.c \ -$(SRC)/isdn/DMSmes.c \ -$(SRC)/isdn/DMSStateNT.c \ -$(SRC)/isdn/DMSStateTE.c \ -$(SRC)/isdn/5ESSmes.c \ -$(SRC)/isdn/5ESSStateNT.c \ -$(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c - -BOOST_OBJS=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o - -ISDN_OBJS=\ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o - -ISDN_HEADER=\ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - lib_LTLIBRARIES = libopenzap.la libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) @@ -148,9 +82,6 @@ libopenzap_la_LIBADD = $(LIBS) MYLIB=libopenzap.la -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog #testapp testcid @@ -210,11 +141,6 @@ install-data-local: @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed -uninstall: oz-uninstall - -oz-uninstall: - @rm -fr $(DESTDIR)$(PREFIX) - $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) -rpath $(libdir) skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) @@ -228,6 +154,9 @@ $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmo $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) -rpath $(libdir) wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) + $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) @@ -240,6 +169,60 @@ ISDN_CFLAGS = -D_GNU_SOURCE ISDN_LIBS = -lpcap #### +ISDN_SOURCE=\ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c + +ISDN_OBJS=\ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ +$(SRC)/isdn/Q932mes.o + +ISDN_HEADER=\ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + $(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(LTCOMPILE) -c $< -o $@ $(ISDN_CFLAGS) @@ -258,6 +241,14 @@ $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(AN $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o $(MYLIB) -rpath $(libdir) analog_emmod: $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN) +BOOST_OBJS=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o + +BOOST_SOURCE=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c + $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) From cea5e321efc0ab460534430c065a8260304a3ed5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 06:16:53 +0000 Subject: [PATCH 1234/1766] cleanup git-svn-id: http://svn.openzap.org/svn/openzap/trunk@638 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 145 ++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 77 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 3d9310e039..055f6f0baf 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -32,18 +32,14 @@ PREFIX=$(prefix) SRC=src -top_builddir=@oz_builddir@ -LTINSTALL=$(LIBTOOL) --mode=install $(INSTALL) -LTUNINSTALL=$(LIBTOOL) --mode=uninstall rm -f -CCLD = $(CC) + INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" @COMP_VENDOR_CFLAGS@ @DEFS@ - COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) -LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(MY_CFLAGS) $(LDFLAGS) -o $@ -libdir = $(PREFIX)/lib/ +LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ +libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include libopenzap_la_SOURCES = \ @@ -79,68 +75,6 @@ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_dso.h \ $(SRC)/include/zap_types.h -BOOST_SOURCE=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - -ISDN_SOURCE=\ -$(SRC)/isdn/EuroISDNStateNT.c \ -$(SRC)/isdn/EuroISDNStateTE.c \ -$(SRC)/isdn/mfifo.c \ -$(SRC)/isdn/Q921.c \ -$(SRC)/isdn/Q931api.c \ -$(SRC)/isdn/Q931.c \ -$(SRC)/isdn/Q931ie.c \ -$(SRC)/isdn/Q931mes.c \ -$(SRC)/isdn/Q931StateNT.c \ -$(SRC)/isdn/Q931StateTE.c \ -$(SRC)/isdn/nationalmes.c \ -$(SRC)/isdn/nationalStateNT.c \ -$(SRC)/isdn/nationalStateTE.c \ -$(SRC)/isdn/DMSmes.c \ -$(SRC)/isdn/DMSStateNT.c \ -$(SRC)/isdn/DMSStateTE.c \ -$(SRC)/isdn/5ESSmes.c \ -$(SRC)/isdn/5ESSStateNT.c \ -$(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c - -BOOST_OBJS=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o - -ISDN_OBJS=\ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o - -ISDN_HEADER=\ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - lib_LTLIBRARIES = libopenzap.la libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) @@ -148,9 +82,6 @@ libopenzap_la_LIBADD = $(LIBS) MYLIB=libopenzap.la -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog #testapp testcid @@ -210,11 +141,6 @@ install-data-local: @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed -uninstall: oz-uninstall - -oz-uninstall: - @rm -fr $(DESTDIR)$(PREFIX) - $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) -rpath $(libdir) skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) @@ -228,6 +154,9 @@ $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmo $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) -rpath $(libdir) wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) +PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) + $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) @@ -240,6 +169,60 @@ ISDN_CFLAGS = -D_GNU_SOURCE ISDN_LIBS = -lpcap #### +ISDN_SOURCE=\ +$(SRC)/isdn/EuroISDNStateNT.c \ +$(SRC)/isdn/EuroISDNStateTE.c \ +$(SRC)/isdn/mfifo.c \ +$(SRC)/isdn/Q921.c \ +$(SRC)/isdn/Q931api.c \ +$(SRC)/isdn/Q931.c \ +$(SRC)/isdn/Q931ie.c \ +$(SRC)/isdn/Q931mes.c \ +$(SRC)/isdn/Q931StateNT.c \ +$(SRC)/isdn/Q931StateTE.c \ +$(SRC)/isdn/nationalmes.c \ +$(SRC)/isdn/nationalStateNT.c \ +$(SRC)/isdn/nationalStateTE.c \ +$(SRC)/isdn/DMSmes.c \ +$(SRC)/isdn/DMSStateNT.c \ +$(SRC)/isdn/DMSStateTE.c \ +$(SRC)/isdn/5ESSmes.c \ +$(SRC)/isdn/5ESSStateNT.c \ +$(SRC)/isdn/5ESSStateTE.c \ +$(SRC)/isdn/Q932mes.c + +ISDN_OBJS=\ +$(SRC)/isdn/EuroISDNStateNT.o \ +$(SRC)/isdn/EuroISDNStateTE.o \ +$(SRC)/isdn/mfifo.o \ +$(SRC)/isdn/Q921.o \ +$(SRC)/isdn/Q931api.o \ +$(SRC)/isdn/Q931.o \ +$(SRC)/isdn/Q931ie.o \ +$(SRC)/isdn/Q931mes.o \ +$(SRC)/isdn/Q931StateNT.o \ +$(SRC)/isdn/Q931StateTE.o \ +$(SRC)/isdn/nationalmes.o \ +$(SRC)/isdn/nationalStateNT.o \ +$(SRC)/isdn/nationalStateTE.o \ +$(SRC)/isdn/DMSmes.o \ +$(SRC)/isdn/DMSStateNT.o \ +$(SRC)/isdn/DMSStateTE.o \ +$(SRC)/isdn/5ESSmes.o \ +$(SRC)/isdn/5ESSStateNT.o \ +$(SRC)/isdn/5ESSStateTE.o \ +$(SRC)/isdn/Q932mes.o + +ISDN_HEADER=\ +$(SRC)/isdn/include/mfifo.h \ +$(SRC)/isdn/include/national.h \ +$(SRC)/isdn/include/DMS.h \ +$(SRC)/isdn/include/5ESS.h \ +$(SRC)/isdn/include/Q921.h \ +$(SRC)/isdn/include/Q931.h \ +$(SRC)/isdn/include/Q931ie.h \ +$(SRC)/isdn/include/Q932.h + $(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c $(LTCOMPILE) -c $< -o $@ $(ISDN_CFLAGS) @@ -258,6 +241,14 @@ $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(AN $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o $(MYLIB) -rpath $(libdir) analog_emmod: $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN) +BOOST_OBJS=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o + +BOOST_SOURCE=\ +$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ +$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c + $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) From f0e51dee8cdf9a86e7163436fe86cd6b2233ae7c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 16:41:48 +0000 Subject: [PATCH 1235/1766] add libpcap detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@639 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/acinclude.m4 | 1 + libs/openzap/build/libpcap.m4 | 38 +++++++++++++++++++++++++++++++++-- libs/openzap/configure.ac | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 libs/openzap/acinclude.m4 diff --git a/libs/openzap/acinclude.m4 b/libs/openzap/acinclude.m4 new file mode 100644 index 0000000000..908ddba855 --- /dev/null +++ b/libs/openzap/acinclude.m4 @@ -0,0 +1 @@ +m4_include([build/libpcap.m4]) diff --git a/libs/openzap/build/libpcap.m4 b/libs/openzap/build/libpcap.m4 index 77fce6a2f0..fd3bbe1da0 100644 --- a/libs/openzap/build/libpcap.m4 +++ b/libs/openzap/build/libpcap.m4 @@ -34,6 +34,18 @@ ac_cv_found_pcap_lib=no) LIBS=$saved_LIBS ]) +AC_DEFUN([TEST_LIBPATH], [ +changequote(<<, >>) +define(<>, translit(ac_cv_found_$2_lib, <<- *>>, <<__p>>)) +changequote([, ]) +if test "$AC_CV_FOUND" = "yes"; then + if test \! -r "$1/lib$2.a" -a \! -r "$1/lib$2.so" -a \! -r "$1/lib$2.sl" -a \! -r "$1/lib$2.dylib"; then + AC_CV_FOUND=no + fi +fi +]) + + AC_DEFUN([PCAP_LIB_WHERE], [ for i in $1; do AC_MSG_CHECKING(for pcap library in $i) @@ -49,7 +61,29 @@ AC_DEFUN([PCAP_LIB_WHERE], [ done ]) -AC_DEFUN([PCAP], [ +AC_DEFUN([FIND_LIB_SUBDIR], +[dnl +AC_ARG_WITH([lib-subdir], AC_HELP_STRING([--with-lib-subdir=DIR],[Find libraries in DIR instead of lib])) +AC_CHECK_SIZEOF(long) +AC_CACHE_CHECK([what directory libraries are found in], [ac_cv_cmu_lib_subdir], +[test "X$with_lib_subdir" = "Xyes" && with_lib_subdir= +test "X$with_lib_subdir" = "Xno" && with_lib_subdir= + if test "X$with_lib_subdir" = "X" ; then + ac_cv_cmu_lib_subdir=lib + if test $ac_cv_sizeof_long -eq 4 ; then + test -d /usr/lib32 && ac_cv_cmu_lib_subdir=lib32 + fi + if test $ac_cv_sizeof_long -eq 8 ; then + test -d /usr/lib64 && ac_cv_cmu_lib_subdir=lib64 + fi + else + ac_cv_cmu_lib_subdir=$with_lib_subdir + fi]) + AC_SUBST(LIB_SUBDIR, $ac_cv_cmu_lib_subdir) + ]) + + +AC_DEFUN([AX_LIB_PCAP], [ AC_REQUIRE([FIND_LIB_SUBDIR]) AC_ARG_WITH(pcap, [ --with-pcap=PREFIX Compile with PCAP support], @@ -78,7 +112,7 @@ AC_ARG_WITH(pcap-include, ac_cv_pcap_where_lib=$with_pcap_lib fi if test "X$ac_cv_pcap_where_lib" = "X"; then - PCAP_LIB_WHERE(/usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) + PCAP_LIB_WHERE(/usr/$LIB_SUBDIR /usr/local/$LIB_SUBDIR) fi if test "X$with_pcap_include" != "X"; then diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 471030debf..3aedc1a354 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -101,6 +101,7 @@ AC_SUBST(DYNAMIC_LIB_EXTEN) AC_CHECK_LIB([dl], [dlopen]) AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([m], [cos]) +AX_LIB_PCAP AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) AC_CHECK_FUNC([gethostbyname_r], From 2e4c38f171b9bda127e95d26c0f6793c3dd0a8fd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 16:41:48 +0000 Subject: [PATCH 1236/1766] add libpcap detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@639 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/acinclude.m4 | 1 + libs/freetdm/build/libpcap.m4 | 38 +++++++++++++++++++++++++++++++++-- libs/freetdm/configure.ac | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 libs/freetdm/acinclude.m4 diff --git a/libs/freetdm/acinclude.m4 b/libs/freetdm/acinclude.m4 new file mode 100644 index 0000000000..908ddba855 --- /dev/null +++ b/libs/freetdm/acinclude.m4 @@ -0,0 +1 @@ +m4_include([build/libpcap.m4]) diff --git a/libs/freetdm/build/libpcap.m4 b/libs/freetdm/build/libpcap.m4 index 77fce6a2f0..fd3bbe1da0 100644 --- a/libs/freetdm/build/libpcap.m4 +++ b/libs/freetdm/build/libpcap.m4 @@ -34,6 +34,18 @@ ac_cv_found_pcap_lib=no) LIBS=$saved_LIBS ]) +AC_DEFUN([TEST_LIBPATH], [ +changequote(<<, >>) +define(<>, translit(ac_cv_found_$2_lib, <<- *>>, <<__p>>)) +changequote([, ]) +if test "$AC_CV_FOUND" = "yes"; then + if test \! -r "$1/lib$2.a" -a \! -r "$1/lib$2.so" -a \! -r "$1/lib$2.sl" -a \! -r "$1/lib$2.dylib"; then + AC_CV_FOUND=no + fi +fi +]) + + AC_DEFUN([PCAP_LIB_WHERE], [ for i in $1; do AC_MSG_CHECKING(for pcap library in $i) @@ -49,7 +61,29 @@ AC_DEFUN([PCAP_LIB_WHERE], [ done ]) -AC_DEFUN([PCAP], [ +AC_DEFUN([FIND_LIB_SUBDIR], +[dnl +AC_ARG_WITH([lib-subdir], AC_HELP_STRING([--with-lib-subdir=DIR],[Find libraries in DIR instead of lib])) +AC_CHECK_SIZEOF(long) +AC_CACHE_CHECK([what directory libraries are found in], [ac_cv_cmu_lib_subdir], +[test "X$with_lib_subdir" = "Xyes" && with_lib_subdir= +test "X$with_lib_subdir" = "Xno" && with_lib_subdir= + if test "X$with_lib_subdir" = "X" ; then + ac_cv_cmu_lib_subdir=lib + if test $ac_cv_sizeof_long -eq 4 ; then + test -d /usr/lib32 && ac_cv_cmu_lib_subdir=lib32 + fi + if test $ac_cv_sizeof_long -eq 8 ; then + test -d /usr/lib64 && ac_cv_cmu_lib_subdir=lib64 + fi + else + ac_cv_cmu_lib_subdir=$with_lib_subdir + fi]) + AC_SUBST(LIB_SUBDIR, $ac_cv_cmu_lib_subdir) + ]) + + +AC_DEFUN([AX_LIB_PCAP], [ AC_REQUIRE([FIND_LIB_SUBDIR]) AC_ARG_WITH(pcap, [ --with-pcap=PREFIX Compile with PCAP support], @@ -78,7 +112,7 @@ AC_ARG_WITH(pcap-include, ac_cv_pcap_where_lib=$with_pcap_lib fi if test "X$ac_cv_pcap_where_lib" = "X"; then - PCAP_LIB_WHERE(/usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) + PCAP_LIB_WHERE(/usr/$LIB_SUBDIR /usr/local/$LIB_SUBDIR) fi if test "X$with_pcap_include" != "X"; then diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 471030debf..3aedc1a354 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -101,6 +101,7 @@ AC_SUBST(DYNAMIC_LIB_EXTEN) AC_CHECK_LIB([dl], [dlopen]) AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([m], [cos]) +AX_LIB_PCAP AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) AC_CHECK_FUNC([gethostbyname_r], From 8f2779616764b413960431c248f1f65e4bb51d88 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 17:00:13 +0000 Subject: [PATCH 1237/1766] working libpcap detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@640 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 2 +- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 52 +++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 055f6f0baf..12422eb372 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -166,7 +166,7 @@ ISDN_CFLAGS = -D_GNU_SOURCE #### ###For libpcap -ISDN_LIBS = -lpcap +ISDN_LIBS = $(PCAP_LIB_FLAGS) #### ISDN_SOURCE=\ diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index be3d86313f..5f4c1ce4d6 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -49,9 +49,11 @@ #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 @@ -68,6 +70,7 @@ #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; @@ -139,14 +142,14 @@ static zap_status_t openPcapFile(void) static zap_status_t closePcapFile(void) { - if(pcapfile){ + if (pcapfile) { pcap_dump_close(pcapfile); - if(pcaphandle) pcap_close(pcaphandle); + 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; + pcaphdr.ts.tv_sec = 0; + pcaphdr.ts.tv_usec = 0; pcapfile = NULL; pcaphandle = NULL; pcapfilesize = 0; @@ -155,7 +158,7 @@ static zap_status_t closePcapFile(void) } /*We have allways success with this? I think so*/ - return ZAP_SUCCESS; + return ZAP_SUCCESS; } static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) @@ -236,9 +239,14 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L return ZAP_SUCCESS; } +#endif static ZIO_IO_UNLOAD_FUNCTION(close_pcap) { +#ifdef HAVE_LIBPCAP return closePcapFile(); +#else + return ZAP_SUCCESS; +#endif } /*Q931ToPcap functions DONE*/ @@ -965,12 +973,15 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg { int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; +#ifdef HAVE_LIBPCAP zap_span_t *span = (zap_span_t *) pvt; /*To get access to spanid for Q931ToPcap*/ +#endif 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){ if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 1) != ZAP_SUCCESS){ @@ -978,6 +989,7 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg } } /*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); @@ -1723,7 +1735,9 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I { int offset = 4; char bb[4096] = ""; +#ifdef HAVE_LIBPCAP zap_span_t *span = (zap_span_t *) pvt; /*To get access to span_id for Q931ToPcap*/ +#endif switch(ind) { case Q921_DL_UNIT_DATA: @@ -1731,6 +1745,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I case Q921_DL_DATA: print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); +#ifdef HAVE_LIBPCAP /*Q931ToPcap*/ if(do_q931ToPcap==1){ if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 0) != ZAP_SUCCESS){ @@ -1738,6 +1753,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I } } /*Q931ToPcap done*/ +#endif zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); break; @@ -1908,29 +1924,31 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) 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*/; + 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; + } 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*); - } + 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){ @@ -1939,7 +1957,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) 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; } From f8a3e20f29ab458a54b0871cc93dcdb3f77e9528 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 17:00:13 +0000 Subject: [PATCH 1238/1766] working libpcap detection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@640 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 2 +- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 52 +++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 055f6f0baf..12422eb372 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -166,7 +166,7 @@ ISDN_CFLAGS = -D_GNU_SOURCE #### ###For libpcap -ISDN_LIBS = -lpcap +ISDN_LIBS = $(PCAP_LIB_FLAGS) #### ISDN_SOURCE=\ diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index be3d86313f..5f4c1ce4d6 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -49,9 +49,11 @@ #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 @@ -68,6 +70,7 @@ #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; @@ -139,14 +142,14 @@ static zap_status_t openPcapFile(void) static zap_status_t closePcapFile(void) { - if(pcapfile){ + if (pcapfile) { pcap_dump_close(pcapfile); - if(pcaphandle) pcap_close(pcaphandle); + 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; + pcaphdr.ts.tv_sec = 0; + pcaphdr.ts.tv_usec = 0; pcapfile = NULL; pcaphandle = NULL; pcapfilesize = 0; @@ -155,7 +158,7 @@ static zap_status_t closePcapFile(void) } /*We have allways success with this? I think so*/ - return ZAP_SUCCESS; + return ZAP_SUCCESS; } static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) @@ -236,9 +239,14 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L return ZAP_SUCCESS; } +#endif static ZIO_IO_UNLOAD_FUNCTION(close_pcap) { +#ifdef HAVE_LIBPCAP return closePcapFile(); +#else + return ZAP_SUCCESS; +#endif } /*Q931ToPcap functions DONE*/ @@ -965,12 +973,15 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg { int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; +#ifdef HAVE_LIBPCAP zap_span_t *span = (zap_span_t *) pvt; /*To get access to spanid for Q931ToPcap*/ +#endif 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){ if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 1) != ZAP_SUCCESS){ @@ -978,6 +989,7 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg } } /*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); @@ -1723,7 +1735,9 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I { int offset = 4; char bb[4096] = ""; +#ifdef HAVE_LIBPCAP zap_span_t *span = (zap_span_t *) pvt; /*To get access to span_id for Q931ToPcap*/ +#endif switch(ind) { case Q921_DL_UNIT_DATA: @@ -1731,6 +1745,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I case Q921_DL_DATA: print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb)); +#ifdef HAVE_LIBPCAP /*Q931ToPcap*/ if(do_q931ToPcap==1){ if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 0) != ZAP_SUCCESS){ @@ -1738,6 +1753,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I } } /*Q931ToPcap done*/ +#endif zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); break; @@ -1908,29 +1924,31 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) 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*/; + 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; + } 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*); - } + 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){ @@ -1939,7 +1957,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) 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; } From 093bdd67dfb6836a5bd43098619d286678db84e9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 19:48:04 +0000 Subject: [PATCH 1239/1766] fix test programs build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@641 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 14 +++++++------- libs/openzap/src/testapp.c | 6 +++--- libs/openzap/src/testcid.c | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 12422eb372..fdd183bfc7 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -84,13 +84,13 @@ MYLIB=libopenzap.la all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog #testapp testcid -#testapp_SOURCES = $(SRC)/testapp.c -#testapp_LDADD = libopenzap.la -#testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -#testcid_SOURCES = $(SRC)/testcid.c -#testcid_LDADD = libopenzap.la -#testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid +testapp_SOURCES = $(SRC)/testapp.c +testapp_LDADD = libopenzap.la +testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testcid_SOURCES = $(SRC)/testcid.c +testcid_LDADD = libopenzap.la +testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testtones_SOURCES = $(SRC)/testtones.c testtones_LDADD = libopenzap.la testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 3a706edc95..3450f88762 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -45,13 +45,13 @@ int main(int argc, char *argv[]) zap_wait_flag_t flags = ZAP_READ; if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { - printf("wait FAIL! %d [%s]\n", len, chan->last_error); + printf("wait FAIL! %lu [%s]\n", len, chan->last_error); } if (flags & ZAP_READ) { if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { - printf("READ: %d\n", len); + printf("READ: %lu\n", len); } else { - printf("READ FAIL! %d [%s]\n", len, chan->last_error); + printf("READ FAIL! %lu [%s]\n", len, chan->last_error); break; } } else { diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index 0dd923393e..4b3e63ecdc 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) int fd = -1; int16_t buf[160] = {0}; ssize_t len = 0; - int type, mlen; + size_t type, mlen; char *sp; char str[128] = ""; char fbuf[256]; @@ -49,12 +49,12 @@ int main(int argc, char *argv[]) zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); #if 1 - zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, time_str, strlen(time_str)); + 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, "14149361212", 7); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); + 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, url, strlen(url)); + 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"); @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) 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("%d %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); + printf("%lu %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); if (fd > -1) { close (fd); @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) return 0; } - if (zap_fsk_demod_init(&fsk_data, 8000, fbuf, sizeof(fbuf))) { + if (zap_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) { printf("wtf\n"); return 0; } @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) zap_copy_string(str, sp, mlen+1); *(str+mlen) = '\0'; zap_clean_string(str); - printf("TYPE %d (%s) LEN %d VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); + printf("TYPE %lu (%s) LEN %lu VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); } zap_fsk_demod_destroy(&fsk_data); From cb40089f371c2e6e108f09f11e75a795b4288dde Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 19:48:04 +0000 Subject: [PATCH 1240/1766] fix test programs build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@641 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 14 +++++++------- libs/freetdm/src/testapp.c | 6 +++--- libs/freetdm/src/testcid.c | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 12422eb372..fdd183bfc7 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -84,13 +84,13 @@ MYLIB=libopenzap.la all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog #testapp testcid -#testapp_SOURCES = $(SRC)/testapp.c -#testapp_LDADD = libopenzap.la -#testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -#testcid_SOURCES = $(SRC)/testcid.c -#testcid_LDADD = libopenzap.la -#testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid +testapp_SOURCES = $(SRC)/testapp.c +testapp_LDADD = libopenzap.la +testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testcid_SOURCES = $(SRC)/testcid.c +testcid_LDADD = libopenzap.la +testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testtones_SOURCES = $(SRC)/testtones.c testtones_LDADD = libopenzap.la testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 3a706edc95..3450f88762 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -45,13 +45,13 @@ int main(int argc, char *argv[]) zap_wait_flag_t flags = ZAP_READ; if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { - printf("wait FAIL! %d [%s]\n", len, chan->last_error); + printf("wait FAIL! %lu [%s]\n", len, chan->last_error); } if (flags & ZAP_READ) { if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { - printf("READ: %d\n", len); + printf("READ: %lu\n", len); } else { - printf("READ FAIL! %d [%s]\n", len, chan->last_error); + printf("READ FAIL! %lu [%s]\n", len, chan->last_error); break; } } else { diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index 0dd923393e..4b3e63ecdc 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) int fd = -1; int16_t buf[160] = {0}; ssize_t len = 0; - int type, mlen; + size_t type, mlen; char *sp; char str[128] = ""; char fbuf[256]; @@ -49,12 +49,12 @@ int main(int argc, char *argv[]) zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); #if 1 - zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, time_str, strlen(time_str)); + 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, "14149361212", 7); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, "Fred Smith", 10); + 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, url, strlen(url)); + 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"); @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) 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("%d %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); + printf("%lu %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); if (fd > -1) { close (fd); @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) return 0; } - if (zap_fsk_demod_init(&fsk_data, 8000, fbuf, sizeof(fbuf))) { + if (zap_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) { printf("wtf\n"); return 0; } @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) zap_copy_string(str, sp, mlen+1); *(str+mlen) = '\0'; zap_clean_string(str); - printf("TYPE %d (%s) LEN %d VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); + printf("TYPE %lu (%s) LEN %lu VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, str); } zap_fsk_demod_destroy(&fsk_data); From a950bcc30dfc708612e3db7884f52752f370c678 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 20:58:30 +0000 Subject: [PATCH 1241/1766] fix endless loop git-svn-id: http://svn.openzap.org/svn/openzap/trunk@642 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931mes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index f77f3837f1..b89cf6fbba 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -600,6 +600,9 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * if (rc != Q931E_NO_ERROR) return rc; break; + default: + return Q931E_ILLEGAL_IE; + break; } } From e92c5f8c40d20cc85795137c7d43136ebf32c327 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 3 Feb 2009 20:58:30 +0000 Subject: [PATCH 1242/1766] fix endless loop git-svn-id: http://svn.openzap.org/svn/openzap/trunk@642 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931mes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index f77f3837f1..b89cf6fbba 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -600,6 +600,9 @@ L3INT Q931Umes_Notify(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic * if (rc != Q931E_NO_ERROR) return rc; break; + default: + return Q931E_ILLEGAL_IE; + break; } } From 7241056f7039308cccd2520f8321796b5747e481 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 4 Feb 2009 16:34:38 +0000 Subject: [PATCH 1243/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@643 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testapp.c | 6 +++--- libs/openzap/src/testcid.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index 3450f88762..ea83419a99 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -45,13 +45,13 @@ int main(int argc, char *argv[]) zap_wait_flag_t flags = ZAP_READ; if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { - printf("wait FAIL! %lu [%s]\n", len, chan->last_error); + 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: %lu\n", len); + printf("READ: %u\n", (unsigned)len); } else { - printf("READ FAIL! %lu [%s]\n", len, chan->last_error); + printf("READ FAIL! %u [%s]\n", (unsigned)len, chan->last_error); break; } } else { diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index 4b3e63ecdc..0b10570a27 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) zap_copy_string(str, sp, mlen+1); *(str+mlen) = '\0'; zap_clean_string(str); - printf("TYPE %lu (%s) LEN %lu VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, 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); From 0d8dbb1b6de5891e2fe1521dca8b3351d1d3a4a6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 4 Feb 2009 16:34:38 +0000 Subject: [PATCH 1244/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@643 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testapp.c | 6 +++--- libs/freetdm/src/testcid.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index 3450f88762..ea83419a99 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -45,13 +45,13 @@ int main(int argc, char *argv[]) zap_wait_flag_t flags = ZAP_READ; if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { - printf("wait FAIL! %lu [%s]\n", len, chan->last_error); + 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: %lu\n", len); + printf("READ: %u\n", (unsigned)len); } else { - printf("READ FAIL! %lu [%s]\n", len, chan->last_error); + printf("READ FAIL! %u [%s]\n", (unsigned)len, chan->last_error); break; } } else { diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index 4b3e63ecdc..0b10570a27 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) zap_copy_string(str, sp, mlen+1); *(str+mlen) = '\0'; zap_clean_string(str); - printf("TYPE %lu (%s) LEN %lu VAL [%s]\n", type, zap_mdmf_type2str(type), mlen, 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); From c334ae77450c565135a055dd8812e99977158f5a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 4 Feb 2009 21:34:02 +0000 Subject: [PATCH 1245/1766] allow commented categories git-svn-id: http://svn.openzap.org/svn/openzap/trunk@644 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 6 +++--- libs/openzap/src/zap_io.c | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 15cd842027..2677085aa8 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -654,9 +654,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } 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); + //rlen = len; + //memset(frame, 0, len); + //zap_channel_write(zchan, frame, sizeof(frame), &rlen); continue; } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 714160ca8e..9dbfa9efd9 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2098,7 +2098,12 @@ static zap_status_t load_config(void) } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strncasecmp(cfg.category, "span", 4)) { + if (*cfg.category == '#') { + if (cfg.catno != catno) { + zap_log(ZAP_LOG_DEBUG, "Skipping %s\n", cfg.category); + catno = cfg.catno; + } + } else if (!strncasecmp(cfg.category, "span", 4)) { if (cfg.catno != catno) { char *type = cfg.category + 4; char *name; From 99c4419ae94dce215c1f4d190d391dc615860499 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 4 Feb 2009 21:34:02 +0000 Subject: [PATCH 1246/1766] allow commented categories git-svn-id: http://svn.openzap.org/svn/openzap/trunk@644 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 6 +++--- libs/freetdm/src/zap_io.c | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 15cd842027..2677085aa8 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -654,9 +654,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) } 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); + //rlen = len; + //memset(frame, 0, len); + //zap_channel_write(zchan, frame, sizeof(frame), &rlen); continue; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 714160ca8e..9dbfa9efd9 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2098,7 +2098,12 @@ static zap_status_t load_config(void) } while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strncasecmp(cfg.category, "span", 4)) { + if (*cfg.category == '#') { + if (cfg.catno != catno) { + zap_log(ZAP_LOG_DEBUG, "Skipping %s\n", cfg.category); + catno = cfg.catno; + } + } else if (!strncasecmp(cfg.category, "span", 4)) { if (cfg.catno != catno) { char *type = cfg.category + 4; char *name; From cfc1495bc6acde4bf3cff064ca84078a14117e6b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 4 Feb 2009 23:11:41 +0000 Subject: [PATCH 1247/1766] don't dump non-existant channels (OPENZAP-47) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@645 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 58bfedf047..a2e9c148f9 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2022,6 +2022,11 @@ static switch_status_t load_config(void) void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) { + if (chan_id > span->chan_count) { + stream->write_function(stream, "ERROR\n"); + return; + } + stream->write_function(stream, "span_id: %u\n" "chan_id: %u\n" From 59342977f62988207da85ec0535bf362d1456890 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 4 Feb 2009 23:11:41 +0000 Subject: [PATCH 1248/1766] don't dump non-existant channels (OPENZAP-47) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@645 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 58bfedf047..a2e9c148f9 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2022,6 +2022,11 @@ static switch_status_t load_config(void) void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) { + if (chan_id > span->chan_count) { + stream->write_function(stream, "ERROR\n"); + return; + } + stream->write_function(stream, "span_id: %u\n" "chan_id: %u\n" From e9c2bc56e199b04ea786e625364b8348057dcef8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 02:37:04 +0000 Subject: [PATCH 1249/1766] don't dump non-existant channels (OPENZAP-47) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@646 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a2e9c148f9..5ecaa98143 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2023,7 +2023,6 @@ static switch_status_t load_config(void) void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) { if (chan_id > span->chan_count) { - stream->write_function(stream, "ERROR\n"); return; } @@ -2094,12 +2093,16 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR invalid span\n"); } else { if (chan_id) { - dump_chan(span, chan_id, stream); + if(chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid channel\n"); + } else { + dump_chan(span, chan_id, stream); + } } else { int j; stream->write_function(stream, "+OK\n"); - for(j = 1; j <= span->chan_count; j++) { + for (j = 1; j <= span->chan_count; j++) { dump_chan(span, j, stream); } @@ -2161,14 +2164,12 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR invalid span\n"); } else { if (chan_id) { - //dump_chan(span, chan_id, stream); zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); } else { int j; stream->write_function(stream, "+OK\n"); - for(j = 1; j <= span->chan_count; j++) { - //dump_chan(span, j, stream); + for (j = 1; j <= span->chan_count; j++) { zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, j); } From 0e583b43fdf1c307c731b41299c98d99c9322992 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 02:37:04 +0000 Subject: [PATCH 1250/1766] don't dump non-existant channels (OPENZAP-47) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@646 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a2e9c148f9..5ecaa98143 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2023,7 +2023,6 @@ static switch_status_t load_config(void) void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) { if (chan_id > span->chan_count) { - stream->write_function(stream, "ERROR\n"); return; } @@ -2094,12 +2093,16 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR invalid span\n"); } else { if (chan_id) { - dump_chan(span, chan_id, stream); + if(chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid channel\n"); + } else { + dump_chan(span, chan_id, stream); + } } else { int j; stream->write_function(stream, "+OK\n"); - for(j = 1; j <= span->chan_count; j++) { + for (j = 1; j <= span->chan_count; j++) { dump_chan(span, j, stream); } @@ -2161,14 +2164,12 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR invalid span\n"); } else { if (chan_id) { - //dump_chan(span, chan_id, stream); zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); } else { int j; stream->write_function(stream, "+OK\n"); - for(j = 1; j <= span->chan_count; j++) { - //dump_chan(span, j, stream); + for (j = 1; j <= span->chan_count; j++) { zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, j); } From 6b2067ffdfd7b6b5411249693bd532c49fcad79a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 03:25:57 +0000 Subject: [PATCH 1251/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@647 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testcid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index 0b10570a27..815ae2a0d2 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) 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("%lu %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); + printf("%u %d %d\n", (unsigned) fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); if (fd > -1) { close (fd); From 6e7331069acdb6d799d37dc0ea8616bd15ffac71 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 03:25:57 +0000 Subject: [PATCH 1252/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@647 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testcid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index 0b10570a27..815ae2a0d2 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) 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("%lu %d %d\n", fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); + printf("%u %d %d\n", (unsigned) fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); if (fd > -1) { close (fd); From e9e0302d2f6eca42c32b6097ad4b12b52fec8ecc Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 5 Feb 2009 15:54:16 +0000 Subject: [PATCH 1253/1766] Fix installation of openzap modules git-svn-id: http://svn.openzap.org/svn/openzap/trunk@648 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index fdd183bfc7..62603f02c7 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -138,7 +138,7 @@ install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX)/lib $(mkinstalldirs) $(DESTDIR)$(PREFIX)/mod @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod - @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod + @cp -f src/ozmod/*/.libs/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) From b6e03b6b6a6f15c14914dcd1d19c4aaeda3f93cc Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 5 Feb 2009 15:54:16 +0000 Subject: [PATCH 1254/1766] Fix installation of openzap modules git-svn-id: http://svn.openzap.org/svn/openzap/trunk@648 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index fdd183bfc7..62603f02c7 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -138,7 +138,7 @@ install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX)/lib $(mkinstalldirs) $(DESTDIR)$(PREFIX)/mod @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod - @cp -f src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod + @cp -f src/ozmod/*/.libs/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) From 6db05ad5f315d72e2e6570c6bc559e602f0c1ef9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 18:21:51 +0000 Subject: [PATCH 1255/1766] more automake git-svn-id: http://svn.openzap.org/svn/openzap/trunk@649 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 141 +++++++++++--------------------------- libs/openzap/configure.ac | 10 ++- 2 files changed, 48 insertions(+), 103 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 62603f02c7..35beef1053 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -33,8 +33,10 @@ PREFIX=$(prefix) SRC=src +moddir=@modinstdir@ + INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" @COMP_VENDOR_CFLAGS@ @DEFS@ +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ @@ -82,8 +84,6 @@ libopenzap_la_LIBADD = $(LIBS) MYLIB=libopenzap.la -all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod - noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -110,10 +110,6 @@ testanalog_SOURCES = $(SRC)/testanalog.c testanalog_LDADD = libopenzap.la testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) - -%.o: %.c $(HEADER) - $(LTCOMPILE) -c $< -o $@ - dox: cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf @@ -128,48 +124,34 @@ mod_openzap-install: mod_openzap mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi -clean: - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) - install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX) $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/lib - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/mod - @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod - @cp -f src/ozmod/*/.libs/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed -$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) -rpath $(libdir) -skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c +ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_zt_la_LDFLAGS = -module +ozmod_zt_la_LIBADD = $(MYLIB) +ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c +ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_skel_la_LDFLAGS = -module +ozmod_skel_la_LIBADD = $(MYLIB) +ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_wanpipe_la_LDFLAGS = -module +ozmod_wanpipe_la_LIBADD = $(MYLIB) +#PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +#PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) -$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) -rpath $(libdir) -ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) +#$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) +# $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) +#pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) -rpath $(libdir) -wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) - -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) -pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) - -###For libpcap -ISDN_CFLAGS = -D_GNU_SOURCE -#### - -###For libpcap -ISDN_LIBS = $(PCAP_LIB_FLAGS) -#### - -ISDN_SOURCE=\ +ozmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -189,68 +171,23 @@ $(SRC)/isdn/DMSStateTE.c \ $(SRC)/isdn/5ESSmes.c \ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c +$(SRC)/isdn/Q932mes.c \ +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE +ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module +ozmod_isdn_la_LIBADD = $(MYLIB) -ISDN_OBJS=\ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o - -ISDN_HEADER=\ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - -$(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c - $(LTCOMPILE) -c $< -o $@ $(ISDN_CFLAGS) - -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o - $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) $(ISDN_LIBS) -rpath $(libdir) -isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) - -$(ISDN_OBJS2): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c - -$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) -analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) - -$(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_EM_OBJS) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o $(MYLIB) -rpath $(libdir) -analog_emmod: $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN) - -BOOST_OBJS=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o - -BOOST_SOURCE=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) - $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) -boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) +ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c +ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_la_LDFLAGS = -module +ozmod_analog_la_LIBADD = $(MYLIB) +ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c +ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_em_la_LDFLAGS = -module +ozmod_analog_em_la_LIBADD = $(MYLIB) +ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_ss7_boost_la_LDFLAGS = -module +ozmod_ss7_boost_la_LIBADD = $(MYLIB) diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 3aedc1a354..501896a239 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -11,9 +11,13 @@ AM_INIT_AUTOMAKE(libopenzap,0.1) # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET +AM_PROG_CC_C_O AC_PREFIX_DEFAULT(/usr/local/openzap) - +# AC_PREFIX_DEFAULT does not get expanded until too late so we need to do this to use prefix in this script +if test "x$prefix" = "xNONE" ; then + prefix='/usr/local/openzap' +fi # Absolute source/build directory OZ_SRCDIR=`(cd $srcdir && pwd)` @@ -139,7 +143,11 @@ if test "${enable_debug}" = "yes"; then fi fi +# Where to install the modules +AC_ARG_WITH([modinstdir], + [AS_HELP_STRING([--with-modinstdir=DIR], [Install modules into this location (default: $prefix/mod)])], [modinstdir="$withval"], [modinstdir="${prefix}/mod"]) +AC_SUBST(modinstdir) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) From 99020477b54d61db13b18138def811750e137e52 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 18:21:51 +0000 Subject: [PATCH 1256/1766] more automake git-svn-id: http://svn.openzap.org/svn/openzap/trunk@649 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 141 +++++++++++--------------------------- libs/freetdm/configure.ac | 10 ++- 2 files changed, 48 insertions(+), 103 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 62603f02c7..35beef1053 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -33,8 +33,10 @@ PREFIX=$(prefix) SRC=src +moddir=@modinstdir@ + INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"@prefix@/mod\" @COMP_VENDOR_CFLAGS@ @DEFS@ +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ @@ -82,8 +84,6 @@ libopenzap_la_LIBADD = $(LIBS) MYLIB=libopenzap.la -all: $(MYLIB) analogmod analog_emmod isdnmod boostmod ztmod wpmod - noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -110,10 +110,6 @@ testanalog_SOURCES = $(SRC)/testanalog.c testanalog_LDADD = libopenzap.la testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) - -%.o: %.c $(HEADER) - $(LTCOMPILE) -c $< -o $@ - dox: cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf @@ -128,48 +124,34 @@ mod_openzap-install: mod_openzap mod_openzap-clean: @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi -clean: - rm -f $(SRC)/*.o $(SRC)/isdn/*.o $(MYLIB) *~ \#* testapp testcid testtones detect_tones detect_dtmf testisdn testboost testanalog src/ozmod/*/*.o src/ozmod/*/*.$(DYNAMIC_LIB_EXTEN) - install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX) $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/lib - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/mod - @[ ! -f ozmod_* ] || cp -f ozmod_* $(DESTDIR)$(PREFIX)/mod - @cp -f src/ozmod/*/.libs/*.$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/mod @echo OpenZAP Installed -$(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_skel/ozmod_skel.o $(MYLIB) -rpath $(libdir) -skelmod: $(SRC)/ozmod/ozmod_skel/ozmod_skel.$(DYNAMIC_LIB_EXTEN) +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c +ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_zt_la_LDFLAGS = -module +ozmod_zt_la_LIBADD = $(MYLIB) +ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c +ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_skel_la_LDFLAGS = -module +ozmod_skel_la_LIBADD = $(MYLIB) +ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_wanpipe_la_LDFLAGS = -module +ozmod_wanpipe_la_LIBADD = $(MYLIB) +#PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) +#PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) -$(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_zt/ozmod_zt.o $(MYLIB) -rpath $(libdir) -ztmod: $(SRC)/ozmod/ozmod_zt/ozmod_zt.$(DYNAMIC_LIB_EXTEN) +#$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) +# $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) +#pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) -$(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.o $(MYLIB) -rpath $(libdir) -wpmod: $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.$(DYNAMIC_LIB_EXTEN) - -PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) -pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) - -###For libpcap -ISDN_CFLAGS = -D_GNU_SOURCE -#### - -###For libpcap -ISDN_LIBS = $(PCAP_LIB_FLAGS) -#### - -ISDN_SOURCE=\ +ozmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -189,68 +171,23 @@ $(SRC)/isdn/DMSStateTE.c \ $(SRC)/isdn/5ESSmes.c \ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ -$(SRC)/isdn/Q932mes.c +$(SRC)/isdn/Q932mes.c \ +$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE +ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module +ozmod_isdn_la_LIBADD = $(MYLIB) -ISDN_OBJS=\ -$(SRC)/isdn/EuroISDNStateNT.o \ -$(SRC)/isdn/EuroISDNStateTE.o \ -$(SRC)/isdn/mfifo.o \ -$(SRC)/isdn/Q921.o \ -$(SRC)/isdn/Q931api.o \ -$(SRC)/isdn/Q931.o \ -$(SRC)/isdn/Q931ie.o \ -$(SRC)/isdn/Q931mes.o \ -$(SRC)/isdn/Q931StateNT.o \ -$(SRC)/isdn/Q931StateTE.o \ -$(SRC)/isdn/nationalmes.o \ -$(SRC)/isdn/nationalStateNT.o \ -$(SRC)/isdn/nationalStateTE.o \ -$(SRC)/isdn/DMSmes.o \ -$(SRC)/isdn/DMSStateNT.o \ -$(SRC)/isdn/DMSStateTE.o \ -$(SRC)/isdn/5ESSmes.o \ -$(SRC)/isdn/5ESSStateNT.o \ -$(SRC)/isdn/5ESSStateTE.o \ -$(SRC)/isdn/Q932mes.o - -ISDN_HEADER=\ -$(SRC)/isdn/include/mfifo.h \ -$(SRC)/isdn/include/national.h \ -$(SRC)/isdn/include/DMS.h \ -$(SRC)/isdn/include/5ESS.h \ -$(SRC)/isdn/include/Q921.h \ -$(SRC)/isdn/include/Q931.h \ -$(SRC)/isdn/include/Q931ie.h \ -$(SRC)/isdn/include/Q932.h - -$(ISDN_OBJS): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c - $(LTCOMPILE) -c $< -o $@ $(ISDN_CFLAGS) - -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o - $(LINK) $(SOLINK) $(ISDN_OBJS) $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.o $(MYLIB) $(ISDN_LIBS) -rpath $(libdir) -isdnmod: $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.$(DYNAMIC_LIB_EXTEN) - -$(ISDN_OBJS2): $(ISDN_HEADER) $(ISDN_SOURCE) $(SRC)/ozmod/ozmod_isdn_libpcap/ozmod_isdn.c - -$(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog/ozmod_analog.o $(MYLIB) -rpath $(libdir) -analogmod: $(SRC)/ozmod/ozmod_analog/ozmod_analog.$(DYNAMIC_LIB_EXTEN) - -$(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(ANALOG_EM_OBJS) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o - $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.o $(MYLIB) -rpath $(libdir) -analog_emmod: $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.$(DYNAMIC_LIB_EXTEN) - -BOOST_OBJS=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.o \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.o - -BOOST_SOURCE=\ -$(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c \ -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c - -$(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN): $(MYLIB) $(BOOST_OBJS) - $(LINK) $(SOLINK) $(BOOST_OBJS) $(MYLIB) -rpath $(libdir) -boostmod: $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.$(DYNAMIC_LIB_EXTEN) +ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c +ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_la_LDFLAGS = -module +ozmod_analog_la_LIBADD = $(MYLIB) +ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c +ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_em_la_LDFLAGS = -module +ozmod_analog_em_la_LIBADD = $(MYLIB) +ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_ss7_boost_la_LDFLAGS = -module +ozmod_ss7_boost_la_LIBADD = $(MYLIB) diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 3aedc1a354..501896a239 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -11,9 +11,13 @@ AM_INIT_AUTOMAKE(libopenzap,0.1) # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET +AM_PROG_CC_C_O AC_PREFIX_DEFAULT(/usr/local/openzap) - +# AC_PREFIX_DEFAULT does not get expanded until too late so we need to do this to use prefix in this script +if test "x$prefix" = "xNONE" ; then + prefix='/usr/local/openzap' +fi # Absolute source/build directory OZ_SRCDIR=`(cd $srcdir && pwd)` @@ -139,7 +143,11 @@ if test "${enable_debug}" = "yes"; then fi fi +# Where to install the modules +AC_ARG_WITH([modinstdir], + [AS_HELP_STRING([--with-modinstdir=DIR], [Install modules into this location (default: $prefix/mod)])], [modinstdir="$withval"], [modinstdir="${prefix}/mod"]) +AC_SUBST(modinstdir) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) From 456386aac0d1a45a0b82b61e7ce9644aff930c20 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 20:44:13 +0000 Subject: [PATCH 1257/1766] add libpri mod configure stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@650 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 9 ++++++++- libs/openzap/configure.ac | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 35beef1053..dba1a1e187 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -130,7 +130,7 @@ install-data-local: @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @echo OpenZAP Installed -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la #ozmod_libpri.la ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module @@ -191,3 +191,10 @@ ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(S ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_ss7_boost_la_LDFLAGS = -module ozmod_ss7_boost_la_LIBADD = $(MYLIB) + +if LIBPRI +#ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c +#ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +#ozmod_libpri_la_LDFLAGS = -module -lpri +#ozmod_libpri_la_LIBADD = $(MYLIB) +endif diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 501896a239..222a1d309d 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -149,6 +149,14 @@ AC_ARG_WITH([modinstdir], AC_SUBST(modinstdir) + +# libpri? +AC_ARG_WITH([libpri], + [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) +AC_SUBST(enable_libpri) + +AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile From 1578712f5d3866b0e2fd4254608dd23258dc71e3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 5 Feb 2009 20:44:13 +0000 Subject: [PATCH 1258/1766] add libpri mod configure stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@650 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 9 ++++++++- libs/freetdm/configure.ac | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 35beef1053..dba1a1e187 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -130,7 +130,7 @@ install-data-local: @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @echo OpenZAP Installed -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la #ozmod_libpri.la ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module @@ -191,3 +191,10 @@ ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(S ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_ss7_boost_la_LDFLAGS = -module ozmod_ss7_boost_la_LIBADD = $(MYLIB) + +if LIBPRI +#ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c +#ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +#ozmod_libpri_la_LDFLAGS = -module -lpri +#ozmod_libpri_la_LIBADD = $(MYLIB) +endif diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 501896a239..222a1d309d 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -149,6 +149,14 @@ AC_ARG_WITH([modinstdir], AC_SUBST(modinstdir) + +# libpri? +AC_ARG_WITH([libpri], + [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) +AC_SUBST(enable_libpri) + +AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile From a1f6e0ddfa7f5d6c6d6597929fe664a8ac31c0e4 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Feb 2009 19:01:31 +0000 Subject: [PATCH 1259/1766] fix gcc 4.3.2 rpm build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@651 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testtones.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/testtones.c b/libs/openzap/src/testtones.c index 2097f26df5..273b793acf 100644 --- a/libs/openzap/src/testtones.c +++ b/libs/openzap/src/testtones.c @@ -8,9 +8,13 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map { struct ttmp *tmp = ts->user_data; int wrote; + size_t len; wrote = teletone_mux_tones(ts, map); - write(tmp->fd, ts->buffer, wrote * 2); + len = write(tmp->fd, ts->buffer, wrote * 2); + + if (!len) return -1; + return 0; } @@ -49,6 +53,7 @@ int32_t main(int argc, char *argv[]) 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)); @@ -59,9 +64,9 @@ int32_t main(int argc, char *argv[]) teletone_dds_state_set_tone(&dds, tones[j], rate, -50); - for(i = 0; i < durations[j] * rate / 1000; i++) { + for(i = 0; (i < durations[j] * rate / 1000) && len != 0; i++) { sample = teletone_dds_modulate_sample(&dds) * 20; - write(fd, &sample, sizeof(sample)); + len = write(fd, &sample, sizeof(sample)); } } From eed38bc7912ff831e08ac1e5dad58cd36bd05f9a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Feb 2009 19:01:31 +0000 Subject: [PATCH 1260/1766] fix gcc 4.3.2 rpm build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@651 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testtones.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/testtones.c b/libs/freetdm/src/testtones.c index 2097f26df5..273b793acf 100644 --- a/libs/freetdm/src/testtones.c +++ b/libs/freetdm/src/testtones.c @@ -8,9 +8,13 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map { struct ttmp *tmp = ts->user_data; int wrote; + size_t len; wrote = teletone_mux_tones(ts, map); - write(tmp->fd, ts->buffer, wrote * 2); + len = write(tmp->fd, ts->buffer, wrote * 2); + + if (!len) return -1; + return 0; } @@ -49,6 +53,7 @@ int32_t main(int argc, char *argv[]) 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)); @@ -59,9 +64,9 @@ int32_t main(int argc, char *argv[]) teletone_dds_state_set_tone(&dds, tones[j], rate, -50); - for(i = 0; i < durations[j] * rate / 1000; i++) { + for(i = 0; (i < durations[j] * rate / 1000) && len != 0; i++) { sample = teletone_dds_modulate_sample(&dds) * 20; - write(fd, &sample, sizeof(sample)); + len = write(fd, &sample, sizeof(sample)); } } From 2d183463cf08f9b5e6db55a2042cf6ecedb021a9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Feb 2009 19:09:42 +0000 Subject: [PATCH 1261/1766] build tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@652 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/mod_openzap/Makefile.in b/libs/openzap/mod_openzap/Makefile.in index e4271e38a4..27eb4f3e8b 100644 --- a/libs/openzap/mod_openzap/Makefile.in +++ b/libs/openzap/mod_openzap/Makefile.in @@ -3,14 +3,14 @@ OZ_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ BASE=../../.. OZ_DIR=.. VERBOSE=1 -OZSO=$(OZ_DIR)/libopenzap.so +OZLA=$(OZ_DIR)/libopenzap.la LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include $(OZ_CFLAGS) LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap include $(BASE)/build/modmake.rules -local_depend: $(OZSO) +local_depend: $(OZLA) -$(OZSO): $(OZ_DIR)/.update +$(OZLA): $(OZ_DIR)/.update cd $(OZ_DIR) && $(MAKE) local_install: From 316bf74434e0a074605d4f86c252bcee3e3250ae Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Feb 2009 19:09:42 +0000 Subject: [PATCH 1262/1766] build tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@652 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/Makefile.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/mod_openzap/Makefile.in b/libs/freetdm/mod_openzap/Makefile.in index e4271e38a4..27eb4f3e8b 100644 --- a/libs/freetdm/mod_openzap/Makefile.in +++ b/libs/freetdm/mod_openzap/Makefile.in @@ -3,14 +3,14 @@ OZ_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ BASE=../../.. OZ_DIR=.. VERBOSE=1 -OZSO=$(OZ_DIR)/libopenzap.so +OZLA=$(OZ_DIR)/libopenzap.la LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include $(OZ_CFLAGS) LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap include $(BASE)/build/modmake.rules -local_depend: $(OZSO) +local_depend: $(OZLA) -$(OZSO): $(OZ_DIR)/.update +$(OZLA): $(OZ_DIR)/.update cd $(OZ_DIR) && $(MAKE) local_install: From 3e55a4767bbf822e444a52a8446e891b30a7bda7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 7 Feb 2009 23:14:25 +0000 Subject: [PATCH 1263/1766] add ozmod_libpri and framework for per module api commands like FS has, mikej probably needs to fix vasprintf..... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@653 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 10 +- libs/openzap/mod_openzap/mod_openzap.c | 103 ++- libs/openzap/src/include/openzap.h | 27 + libs/openzap/src/include/zap_types.h | 10 + .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 259 ++++++ .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 120 +++ .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 805 ++++++++++++++++++ .../src/ozmod/ozmod_libpri/ozmod_libpri.h | 96 +++ libs/openzap/src/zap_io.c | 82 ++ 9 files changed, 1504 insertions(+), 8 deletions(-) create mode 100644 libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c create mode 100644 libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h create mode 100644 libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c create mode 100644 libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index dba1a1e187..5a4d4774d8 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -130,7 +130,7 @@ install-data-local: @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @echo OpenZAP Installed -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la #ozmod_libpri.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la ozmod_libpri.la ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module @@ -193,8 +193,8 @@ ozmod_ss7_boost_la_LDFLAGS = -module ozmod_ss7_boost_la_LIBADD = $(MYLIB) if LIBPRI -#ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c -#ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -#ozmod_libpri_la_LDFLAGS = -module -lpri -#ozmod_libpri_la_LIBADD = $(MYLIB) +ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c +ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_libpri_la_LDFLAGS = -module -lpri +ozmod_libpri_la_LIBADD = $(MYLIB) endif diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5ecaa98143..6b941616ed 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -545,6 +545,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch int total_to; int chunk, do_break = 0; + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -634,11 +635,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } } } - return SWITCH_STATUS_SUCCESS; fail: - switch_clear_flag_locked(tech_pvt, TFLAG_IO); return SWITCH_STATUS_GENERR; @@ -1926,6 +1925,101 @@ static switch_status_t load_config(void) } } + + + if ((spans = switch_xml_child(cfg, "libpri_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; + const char *context = "default"; + const char *dialplan = "XML"; + + const char *o_node = "cpe"; + const char *o_switch = "dms100"; + const char *o_dp = "unknown"; + const char *o_l1 = "ulaw"; + const char *o_debug = NULL; + + + uint32_t span_id = 0; + zap_span_t *span = NULL; + uint32_t opts = 0; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "node")) { + o_node = val; + } else if (!strcasecmp(var, "switch")) { + o_switch = val; + } else if (!strcasecmp(var, "dp")) { + o_dp = val; + } else if (!strcasecmp(var, "l1")) { + o_l1 = val; + } else if (!strcasecmp(var, "debug")) { + o_debug = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { + opts |= 1; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } + } + + if (!id && !name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; + } + + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + continue; + } + + if (!span_id) { + span_id = span->span_id; + } + + + if (zap_configure_span("libpri", span, on_clear_channel_signal, + "node", o_node, + "switch", o_switch, + "dp", o_dp, + "l1", o_l1, + "debug", o_debug, + "opts", opts, + TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d node: %s switch: %s dp: %s l1: %s debug: %s error: %s\n", + span_id, switch_str_nil(o_node), switch_str_nil(o_switch), switch_str_nil(o_dp), switch_str_nil(o_l1), switch_str_nil(o_debug), + span->last_error); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); + + zap_span_start(span); + } + } + if ((spans = switch_xml_child(cfg, "boost_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); @@ -2292,7 +2386,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) { zap_global_destroy(); - return SWITCH_STATUS_NOUNLOAD; + + // this breaks pika but they are MIA so *shrug* + //return SWITCH_STATUS_NOUNLOAD; + return SWITCH_STATUS_SUCCESS; } /* For Emacs: diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index e0974326ca..2b078e603e 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -287,6 +287,31 @@ typedef enum { #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} +struct zap_stream_handle { + zap_stream_handle_write_function_t write_function; + zap_stream_handle_raw_write_function_t raw_write_function; + void *data; + void *end; + zap_size_t data_size; + zap_size_t data_len; + zap_size_t alloc_len; + zap_size_t alloc_chunk; +}; + +zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); +zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); + +#define ZAP_CMD_CHUNK_LEN 1024 +#define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ + switch_assert(s.data); \ + memset(s.data, 0, SWITCH_CMD_CHUNK_LEN); \ + s.end = s.data; \ + s.data_size = ZAP_CMD_CHUNK_LEN; \ + s.write_function = zap_console_stream_write; \ + s.raw_write_function = zap_console_stream_raw_write; \ + s.alloc_len = ZAP_CMD_CHUNK_LEN; \ + s.alloc_chunk = ZAP_CMD_CHUNK_LEN + struct zap_event { zap_event_type_t e_type; uint32_t enum_id; @@ -444,6 +469,7 @@ struct zap_channel { uint8_t fsk_buf[80]; uint32_t ring_count; void *mod_data; + void *call_data; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -511,6 +537,7 @@ struct zap_io_interface { zio_write_t write; zio_span_poll_event_t poll_event; zio_span_next_event_t next_event; + zio_api_t api; }; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 28fd127fbf..0aca999080 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -397,6 +397,10 @@ 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; +typedef struct zap_stream_handle zap_stream_handle_t; + +typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); +typedef zap_status_t (*zap_stream_handle_raw_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) @@ -421,6 +425,7 @@ typedef struct zap_io_interface zap_io_interface_t; #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 ; @@ -445,6 +450,8 @@ 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 @@ -469,9 +476,12 @@ typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_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 ZIP_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; diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c new file mode 100644 index 0000000000..3b227c3c9b --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2009, 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 "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"} +}; + +#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; + + 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_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->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 lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug) +{ + int ret = -1; + + memset(spri, 0, sizeof(struct lpwrap_pri)); + + spri->zdchan = dchan; + + if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){ + spri->span = span; + pri_set_debug(spri->pri, debug); + ret = 0; + } 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; + 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(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) { + 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 { + zap_log(ZAP_LOG_CRIT, "No event handler found for event %d.\n", event->e); + } + } + + return sel; +} + +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 + printf("Error = %i\n",ret); + perror("Lpwrap 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 expandtab: + */ + diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h new file mode 100644 index 0000000000..9333e3a049 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2009, 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_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 +} 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 *); +#define MAX_EVENT 18 + +struct lpwrap_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; +}; + +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, int 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 new file mode 100644 index 0000000000..d80960daf3 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -0,0 +1,805 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "ozmod_libpri.h" + +static ZIO_IO_UNLOAD_FUNCTION(zap_libpri_unload) +{ + return ZAP_SUCCESS; +} + +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; +} + +static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) +{ + return ZAP_FAIL; + +} + +#ifdef WIN32 +static void s_pri_error(char *s) +#else +static void s_pri_error(struct pri *pri, char *s) +#endif +{ + + zap_log(ZAP_LOG_ERROR, "%s", s); + +} + +#ifdef WIN32 +static void s_pri_message(char *s) +{ + zap_log(ZAP_LOG_DEBUG, "%s", s); +} +#else +static void s_pri_message(struct pri *pri, char *s) +{ + zap_log(ZAP_LOG_DEBUG, "%s", s); +} +#endif + +static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) +{ + pri_set_error(s_pri_error); + pri_set_message(s_pri_message); + + return ZAP_SUCCESS; +} + + +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}, + }, + + + } +}; + + + + + +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 (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) && !call) { + zap_log(ZAP_LOG_WARNING, "NO CALL!!!!\n"); + } + + + 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 = isdn_data->sig_cb(&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, 0); + } 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 = isdn_data->sig_cb(&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, 0); + } 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 = isdn_data->sig_cb(&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 = isdn_data->sig_cb(&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 = isdn_data->sig_cb(&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; + + if (!(call = pri_new_call(isdn_data->spri.pri))) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + return; + } + + 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, isdn_data->dp, 1); + pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, zchan->caller_data.cid_name, isdn_data->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, isdn_data->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 && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + 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 = isdn_data->sig_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + + } + default: + break; + } + + + + return; +} + +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); + } + } + } +} + + + +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; +} + +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, pevent->hangup.channel); + zchan->caller_data.hangup_cause = pevent->hangup.cause; + 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, + pevent->hangup.channel, zchan->chan_id); + } + + 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, 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, pevent->answer.channel, zchan->chan_id); + + } + + 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, 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, + pevent->proceeding.channel, zchan->chan_id); + } + + 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, pevent->ringing.channel); + 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, + pevent->ringing.channel, zchan->chan_id); + } + + return 0; +} + + +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, 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, pevent->ring.channel); + ret = 0; + goto done; + } + + + zap_log(ZAP_LOG_NOTICE, "-- Ring on channel %d:%d (from %s to %s)\n", spri->span, 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); + 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; +} + +static int check_flags(lpwrap_pri_t *spri) +{ + zap_span_t *span = spri->private_info; + + check_state(span); + + 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, 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; +} + +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); + zap_set_flag(spri, LPWRAP_PRI_READY); + } + + 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); + zap_clear_flag(spri, LPWRAP_PRI_READY); + } + + 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, event_type, lpwrap_pri_event_str(event_type)); + return 0; +} + + + +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; + + 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); + + isdn_data->spri.on_loop = check_flags; + isdn_data->spri.private_info = span; + + lpwrap_run_pri(&isdn_data->spri); + + + return NULL; +} + +static zap_status_t zap_libpri_start(zap_span_t *span) +{ + zap_status_t ret; + + zap_libpri_data_t *isdn_data = span->signal_data; + 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; +} + + + +static int str2node(char *node) +{ + if (!strcasecmp(node, "cpe")) + return PRI_CPE; + if (!strcasecmp(node, "network")) + return PRI_NETWORK; + return PRI_CPE; +} + +static int str2switch(char *swtype) +{ + if (!strcasecmp(swtype, "ni1")) + return PRI_SWITCH_NI1; + if (!strcasecmp(swtype, "ni2")) + return PRI_SWITCH_NI2; + if (!strcasecmp(swtype, "dms100")) + return PRI_SWITCH_DMS100; + if (!strcasecmp(swtype, "lucent5e")) + return PRI_SWITCH_LUCENT5E; + if (!strcasecmp(swtype, "att4ess")) + return PRI_SWITCH_ATT4ESS; + if (!strcasecmp(swtype, "euroisdn")) + return PRI_SWITCH_EUROISDN_E1; + if (!strcasecmp(swtype, "gr303eoc")) + return PRI_SWITCH_GR303_EOC; + if (!strcasecmp(swtype, "gr303tmc")) + return PRI_SWITCH_GR303_TMC; + return PRI_SWITCH_DMS100; +} + + +static int str2l1(char *l1) +{ + if (!strcasecmp(l1, "alaw")) + return PRI_LAYER_1_ALAW; + + return PRI_LAYER_1_ULAW; +} + +static int str2dp(char *dp) +{ + if (!strcasecmp(dp, "international")) + return PRI_INTERNATIONAL_ISDN; + if (!strcasecmp(dp, "national")) + return PRI_NATIONAL_ISDN; + if (!strcasecmp(dp, "local")) + return PRI_LOCAL_ISDN; + if (!strcasecmp(dp, "private")) + return PRI_PRIVATE; + if (!strcasecmp(dp, "unknown")) + return PRI_UNKNOWN; + + return PRI_UNKNOWN; +} + + + +static 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; + int32_t opts = 0; + + 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)); + + while((var = va_arg(ap, char *))) { + if (!strcasecmp(var, "node")) { + if (!(val = va_arg(ap, char *))) { + break; + } + isdn_data->node = str2node(val); + } else if (!strcasecmp(var, "switch")) { + if (!(val = va_arg(ap, char *))) { + break; + } + isdn_data->pswitch = str2switch(val); + } else if (!strcasecmp(var, "opts")) { + opts = va_arg(ap, uint32_t); + if (opts >= OZMOD_LIBPRI_OPT_MAX) { + return ZAP_FAIL; + } + isdn_data->opts = opts; + } 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; + } + isdn_data->debug = atoi(val); + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; + } + } + + + span->start = zap_libpri_start; + isdn_data->sig_cb = sig_cb; + isdn_data->dchans[0] = dchans[0]; + isdn_data->dchans[1] = dchans[1]; + isdn_data->dchan = isdn_data->dchans[0]; + + + // force debug rm me later + isdn_data->debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; + + + if (lpwrap_init_pri(&isdn_data->spri, + span->span_id, // 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!"); + return ZAP_FAIL; + } + + span->signal_data = isdn_data; + span->signal_type = ZAP_SIGTYPE_ISDN; + span->outgoing_call = isdn_outgoing_call; + + if ((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; +} + +zap_module_t zap_module = { + "libpri", + NULL, + 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 expandtab: + */ diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h new file mode 100644 index 0000000000..64a0c05ae3 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2009, 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_MAX = (2 << 0) +} 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; + zio_signal_cb_t sig_cb; + 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 expandtab: + */ + diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 9dbfa9efd9..50198709d5 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -31,6 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE #ifndef WIN32 #endif #include "openzap.h" @@ -2767,6 +2768,87 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t } + + +zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) +{ + zap_size_t need = handle->data_len + datalen; + + if (need >= handle->data_size) { + void *new_data; + need += handle->alloc_chunk; + + if (!(new_data = realloc(handle->data, need))) { + return ZAP_MEMERR; + } + + handle->data = new_data; + handle->data_size = need; + } + + memcpy((uint8_t *) (handle->data) + handle->data_len, data, datalen); + handle->data_len += datalen; + handle->end = (uint8_t *) (handle->data) + handle->data_len; + *(uint8_t *)handle->end = '\0'; + + return ZAP_SUCCESS; +} + +zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) +{ + va_list ap; + char *buf = handle->data; + char *end = handle->end; + int ret = 0; + char *data = NULL; + + if (handle->data_len >= handle->data_size) { + return ZAP_FAIL; + } + + va_start(ap, fmt); + ret = vasprintf(&data, fmt, ap); + va_end(ap); + + if (data) { + zap_size_t remaining = handle->data_size - handle->data_len; + zap_size_t need = strlen(data) + 1; + + if ((remaining < need) && handle->alloc_len) { + zap_size_t new_len; + void *new_data; + + new_len = handle->data_size + need + handle->alloc_chunk; + if ((new_data = realloc(handle->data, new_len))) { + handle->data_size = handle->alloc_len = new_len; + handle->data = new_data; + buf = handle->data; + remaining = handle->data_size - handle->data_len; + handle->end = (uint8_t *) (handle->data) + handle->data_len; + end = handle->end; + } else { + zap_log(ZAP_LOG_CRIT, "Memory Error!\n"); + free(data); + return ZAP_FAIL; + } + } + + if (remaining < need) { + ret = -1; + } else { + ret = 0; + snprintf(end, remaining, "%s", data); + handle->data_len = strlen(buf); + handle->end = (uint8_t *) (handle->data) + handle->data_len; + } + free(data); + } + + return ret ? ZAP_FAIL : ZAP_SUCCESS; +} + + + /* For Emacs: * Local Variables: * mode:c From 0f8ba38ca2cadf9f212c0f7e726429979f5bcd85 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 7 Feb 2009 23:14:25 +0000 Subject: [PATCH 1264/1766] add ozmod_libpri and framework for per module api commands like FS has, mikej probably needs to fix vasprintf..... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@653 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 10 +- libs/freetdm/mod_openzap/mod_openzap.c | 103 ++- libs/freetdm/src/include/openzap.h | 27 + libs/freetdm/src/include/zap_types.h | 10 + .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 259 ++++++ .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 120 +++ .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 805 ++++++++++++++++++ .../src/ozmod/ozmod_libpri/ozmod_libpri.h | 96 +++ libs/freetdm/src/zap_io.c | 82 ++ 9 files changed, 1504 insertions(+), 8 deletions(-) create mode 100644 libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c create mode 100644 libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h create mode 100644 libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c create mode 100644 libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index dba1a1e187..5a4d4774d8 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -130,7 +130,7 @@ install-data-local: @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @echo OpenZAP Installed -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la #ozmod_libpri.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la ozmod_libpri.la ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module @@ -193,8 +193,8 @@ ozmod_ss7_boost_la_LDFLAGS = -module ozmod_ss7_boost_la_LIBADD = $(MYLIB) if LIBPRI -#ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c -#ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -#ozmod_libpri_la_LDFLAGS = -module -lpri -#ozmod_libpri_la_LIBADD = $(MYLIB) +ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c +ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_libpri_la_LDFLAGS = -module -lpri +ozmod_libpri_la_LIBADD = $(MYLIB) endif diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5ecaa98143..6b941616ed 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -545,6 +545,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch int total_to; int chunk, do_break = 0; + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -634,11 +635,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } } } - return SWITCH_STATUS_SUCCESS; fail: - switch_clear_flag_locked(tech_pvt, TFLAG_IO); return SWITCH_STATUS_GENERR; @@ -1926,6 +1925,101 @@ static switch_status_t load_config(void) } } + + + if ((spans = switch_xml_child(cfg, "libpri_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; + const char *context = "default"; + const char *dialplan = "XML"; + + const char *o_node = "cpe"; + const char *o_switch = "dms100"; + const char *o_dp = "unknown"; + const char *o_l1 = "ulaw"; + const char *o_debug = NULL; + + + uint32_t span_id = 0; + zap_span_t *span = NULL; + uint32_t opts = 0; + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "node")) { + o_node = val; + } else if (!strcasecmp(var, "switch")) { + o_switch = val; + } else if (!strcasecmp(var, "dp")) { + o_dp = val; + } else if (!strcasecmp(var, "l1")) { + o_l1 = val; + } else if (!strcasecmp(var, "debug")) { + o_debug = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { + opts |= 1; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } + } + + if (!id && !name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; + } + + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + continue; + } + + if (!span_id) { + span_id = span->span_id; + } + + + if (zap_configure_span("libpri", span, on_clear_channel_signal, + "node", o_node, + "switch", o_switch, + "dp", o_dp, + "l1", o_l1, + "debug", o_debug, + "opts", opts, + TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d node: %s switch: %s dp: %s l1: %s debug: %s error: %s\n", + span_id, switch_str_nil(o_node), switch_str_nil(o_switch), switch_str_nil(o_dp), switch_str_nil(o_l1), switch_str_nil(o_debug), + span->last_error); + continue; + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); + + zap_span_start(span); + } + } + if ((spans = switch_xml_child(cfg, "boost_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); @@ -2292,7 +2386,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) { zap_global_destroy(); - return SWITCH_STATUS_NOUNLOAD; + + // this breaks pika but they are MIA so *shrug* + //return SWITCH_STATUS_NOUNLOAD; + return SWITCH_STATUS_SUCCESS; } /* For Emacs: diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index e0974326ca..2b078e603e 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -287,6 +287,31 @@ typedef enum { #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} +struct zap_stream_handle { + zap_stream_handle_write_function_t write_function; + zap_stream_handle_raw_write_function_t raw_write_function; + void *data; + void *end; + zap_size_t data_size; + zap_size_t data_len; + zap_size_t alloc_len; + zap_size_t alloc_chunk; +}; + +zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); +zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); + +#define ZAP_CMD_CHUNK_LEN 1024 +#define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ + switch_assert(s.data); \ + memset(s.data, 0, SWITCH_CMD_CHUNK_LEN); \ + s.end = s.data; \ + s.data_size = ZAP_CMD_CHUNK_LEN; \ + s.write_function = zap_console_stream_write; \ + s.raw_write_function = zap_console_stream_raw_write; \ + s.alloc_len = ZAP_CMD_CHUNK_LEN; \ + s.alloc_chunk = ZAP_CMD_CHUNK_LEN + struct zap_event { zap_event_type_t e_type; uint32_t enum_id; @@ -444,6 +469,7 @@ struct zap_channel { uint8_t fsk_buf[80]; uint32_t ring_count; void *mod_data; + void *call_data; struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; @@ -511,6 +537,7 @@ struct zap_io_interface { zio_write_t write; zio_span_poll_event_t poll_event; zio_span_next_event_t next_event; + zio_api_t api; }; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 28fd127fbf..0aca999080 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -397,6 +397,10 @@ 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; +typedef struct zap_stream_handle zap_stream_handle_t; + +typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); +typedef zap_status_t (*zap_stream_handle_raw_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) @@ -421,6 +425,7 @@ typedef struct zap_io_interface zap_io_interface_t; #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 ; @@ -445,6 +450,8 @@ 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 @@ -469,9 +476,12 @@ typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_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 ZIP_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; diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c new file mode 100644 index 0000000000..3b227c3c9b --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2009, 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 "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"} +}; + +#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; + + 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_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->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 lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug) +{ + int ret = -1; + + memset(spri, 0, sizeof(struct lpwrap_pri)); + + spri->zdchan = dchan; + + if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){ + spri->span = span; + pri_set_debug(spri->pri, debug); + ret = 0; + } 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; + 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(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) { + 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 { + zap_log(ZAP_LOG_CRIT, "No event handler found for event %d.\n", event->e); + } + } + + return sel; +} + +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 + printf("Error = %i\n",ret); + perror("Lpwrap 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 expandtab: + */ + diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h new file mode 100644 index 0000000000..9333e3a049 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2009, 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_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 +} 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 *); +#define MAX_EVENT 18 + +struct lpwrap_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; +}; + +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, int span, zap_channel_t *dchan, int swtype, int node, int debug); +int lpwrap_run_pri(struct lpwrap_pri *spri); + +#endif diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c new file mode 100644 index 0000000000..d80960daf3 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -0,0 +1,805 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "openzap.h" +#include "ozmod_libpri.h" + +static ZIO_IO_UNLOAD_FUNCTION(zap_libpri_unload) +{ + return ZAP_SUCCESS; +} + +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; +} + +static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) +{ + return ZAP_FAIL; + +} + +#ifdef WIN32 +static void s_pri_error(char *s) +#else +static void s_pri_error(struct pri *pri, char *s) +#endif +{ + + zap_log(ZAP_LOG_ERROR, "%s", s); + +} + +#ifdef WIN32 +static void s_pri_message(char *s) +{ + zap_log(ZAP_LOG_DEBUG, "%s", s); +} +#else +static void s_pri_message(struct pri *pri, char *s) +{ + zap_log(ZAP_LOG_DEBUG, "%s", s); +} +#endif + +static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) +{ + pri_set_error(s_pri_error); + pri_set_message(s_pri_message); + + return ZAP_SUCCESS; +} + + +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}, + }, + + + } +}; + + + + + +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 (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) && !call) { + zap_log(ZAP_LOG_WARNING, "NO CALL!!!!\n"); + } + + + 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 = isdn_data->sig_cb(&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, 0); + } 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 = isdn_data->sig_cb(&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, 0); + } 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 = isdn_data->sig_cb(&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 = isdn_data->sig_cb(&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 = isdn_data->sig_cb(&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; + + if (!(call = pri_new_call(isdn_data->spri.pri))) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + return; + } + + 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, isdn_data->dp, 1); + pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, zchan->caller_data.cid_name, isdn_data->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, isdn_data->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 && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + 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 = isdn_data->sig_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + + } + default: + break; + } + + + + return; +} + +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); + } + } + } +} + + + +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; +} + +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, pevent->hangup.channel); + zchan->caller_data.hangup_cause = pevent->hangup.cause; + 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, + pevent->hangup.channel, zchan->chan_id); + } + + 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, 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, pevent->answer.channel, zchan->chan_id); + + } + + 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, 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, + pevent->proceeding.channel, zchan->chan_id); + } + + 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, pevent->ringing.channel); + 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, + pevent->ringing.channel, zchan->chan_id); + } + + return 0; +} + + +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, 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, pevent->ring.channel); + ret = 0; + goto done; + } + + + zap_log(ZAP_LOG_NOTICE, "-- Ring on channel %d:%d (from %s to %s)\n", spri->span, 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); + 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; +} + +static int check_flags(lpwrap_pri_t *spri) +{ + zap_span_t *span = spri->private_info; + + check_state(span); + + 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, 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; +} + +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); + zap_set_flag(spri, LPWRAP_PRI_READY); + } + + 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); + zap_clear_flag(spri, LPWRAP_PRI_READY); + } + + 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, event_type, lpwrap_pri_event_str(event_type)); + return 0; +} + + + +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; + + 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); + + isdn_data->spri.on_loop = check_flags; + isdn_data->spri.private_info = span; + + lpwrap_run_pri(&isdn_data->spri); + + + return NULL; +} + +static zap_status_t zap_libpri_start(zap_span_t *span) +{ + zap_status_t ret; + + zap_libpri_data_t *isdn_data = span->signal_data; + 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; +} + + + +static int str2node(char *node) +{ + if (!strcasecmp(node, "cpe")) + return PRI_CPE; + if (!strcasecmp(node, "network")) + return PRI_NETWORK; + return PRI_CPE; +} + +static int str2switch(char *swtype) +{ + if (!strcasecmp(swtype, "ni1")) + return PRI_SWITCH_NI1; + if (!strcasecmp(swtype, "ni2")) + return PRI_SWITCH_NI2; + if (!strcasecmp(swtype, "dms100")) + return PRI_SWITCH_DMS100; + if (!strcasecmp(swtype, "lucent5e")) + return PRI_SWITCH_LUCENT5E; + if (!strcasecmp(swtype, "att4ess")) + return PRI_SWITCH_ATT4ESS; + if (!strcasecmp(swtype, "euroisdn")) + return PRI_SWITCH_EUROISDN_E1; + if (!strcasecmp(swtype, "gr303eoc")) + return PRI_SWITCH_GR303_EOC; + if (!strcasecmp(swtype, "gr303tmc")) + return PRI_SWITCH_GR303_TMC; + return PRI_SWITCH_DMS100; +} + + +static int str2l1(char *l1) +{ + if (!strcasecmp(l1, "alaw")) + return PRI_LAYER_1_ALAW; + + return PRI_LAYER_1_ULAW; +} + +static int str2dp(char *dp) +{ + if (!strcasecmp(dp, "international")) + return PRI_INTERNATIONAL_ISDN; + if (!strcasecmp(dp, "national")) + return PRI_NATIONAL_ISDN; + if (!strcasecmp(dp, "local")) + return PRI_LOCAL_ISDN; + if (!strcasecmp(dp, "private")) + return PRI_PRIVATE; + if (!strcasecmp(dp, "unknown")) + return PRI_UNKNOWN; + + return PRI_UNKNOWN; +} + + + +static 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; + int32_t opts = 0; + + 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)); + + while((var = va_arg(ap, char *))) { + if (!strcasecmp(var, "node")) { + if (!(val = va_arg(ap, char *))) { + break; + } + isdn_data->node = str2node(val); + } else if (!strcasecmp(var, "switch")) { + if (!(val = va_arg(ap, char *))) { + break; + } + isdn_data->pswitch = str2switch(val); + } else if (!strcasecmp(var, "opts")) { + opts = va_arg(ap, uint32_t); + if (opts >= OZMOD_LIBPRI_OPT_MAX) { + return ZAP_FAIL; + } + isdn_data->opts = opts; + } 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; + } + isdn_data->debug = atoi(val); + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return ZAP_FAIL; + } + } + + + span->start = zap_libpri_start; + isdn_data->sig_cb = sig_cb; + isdn_data->dchans[0] = dchans[0]; + isdn_data->dchans[1] = dchans[1]; + isdn_data->dchan = isdn_data->dchans[0]; + + + // force debug rm me later + isdn_data->debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; + + + if (lpwrap_init_pri(&isdn_data->spri, + span->span_id, // 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!"); + return ZAP_FAIL; + } + + span->signal_data = isdn_data; + span->signal_type = ZAP_SIGTYPE_ISDN; + span->outgoing_call = isdn_outgoing_call; + + if ((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; +} + +zap_module_t zap_module = { + "libpri", + NULL, + 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 expandtab: + */ diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h new file mode 100644 index 0000000000..64a0c05ae3 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2009, 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_MAX = (2 << 0) +} 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; + zio_signal_cb_t sig_cb; + 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 expandtab: + */ + diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 9dbfa9efd9..50198709d5 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -31,6 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE #ifndef WIN32 #endif #include "openzap.h" @@ -2767,6 +2768,87 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t } + + +zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) +{ + zap_size_t need = handle->data_len + datalen; + + if (need >= handle->data_size) { + void *new_data; + need += handle->alloc_chunk; + + if (!(new_data = realloc(handle->data, need))) { + return ZAP_MEMERR; + } + + handle->data = new_data; + handle->data_size = need; + } + + memcpy((uint8_t *) (handle->data) + handle->data_len, data, datalen); + handle->data_len += datalen; + handle->end = (uint8_t *) (handle->data) + handle->data_len; + *(uint8_t *)handle->end = '\0'; + + return ZAP_SUCCESS; +} + +zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) +{ + va_list ap; + char *buf = handle->data; + char *end = handle->end; + int ret = 0; + char *data = NULL; + + if (handle->data_len >= handle->data_size) { + return ZAP_FAIL; + } + + va_start(ap, fmt); + ret = vasprintf(&data, fmt, ap); + va_end(ap); + + if (data) { + zap_size_t remaining = handle->data_size - handle->data_len; + zap_size_t need = strlen(data) + 1; + + if ((remaining < need) && handle->alloc_len) { + zap_size_t new_len; + void *new_data; + + new_len = handle->data_size + need + handle->alloc_chunk; + if ((new_data = realloc(handle->data, new_len))) { + handle->data_size = handle->alloc_len = new_len; + handle->data = new_data; + buf = handle->data; + remaining = handle->data_size - handle->data_len; + handle->end = (uint8_t *) (handle->data) + handle->data_len; + end = handle->end; + } else { + zap_log(ZAP_LOG_CRIT, "Memory Error!\n"); + free(data); + return ZAP_FAIL; + } + } + + if (remaining < need) { + ret = -1; + } else { + ret = 0; + snprintf(end, remaining, "%s", data); + handle->data_len = strlen(buf); + handle->end = (uint8_t *) (handle->data) + handle->data_len; + } + free(data); + } + + return ret ? ZAP_FAIL : ZAP_SUCCESS; +} + + + /* For Emacs: * Local Variables: * mode:c From f0354992d2507998cb17a10554f66d2748a732fd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 7 Feb 2009 23:17:03 +0000 Subject: [PATCH 1265/1766] comment verbose message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@654 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index d80960daf3..2a1682d02e 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -214,9 +214,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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)); From b20d103bcab99647cfd984993cd1fafd9aa3b3f8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 7 Feb 2009 23:17:03 +0000 Subject: [PATCH 1266/1766] comment verbose message git-svn-id: http://svn.openzap.org/svn/openzap/trunk@654 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index d80960daf3..2a1682d02e 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -214,9 +214,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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)); From 38b7aa6caa3bea684818ee421e332a82e11e242b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Feb 2009 17:17:47 +0000 Subject: [PATCH 1267/1766] whoops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@655 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 5a4d4774d8..9bf1dada2a 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -130,7 +130,10 @@ install-data-local: @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @echo OpenZAP Installed -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la ozmod_libpri.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +if LIBPRI +mod_LTLIBRARIES += ozmod_libpri.la +endif ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module From 02f037f050fef81883d2af90e39f772c0afe7fae Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Feb 2009 17:17:47 +0000 Subject: [PATCH 1268/1766] whoops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@655 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 5a4d4774d8..9bf1dada2a 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -130,7 +130,10 @@ install-data-local: @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) @echo OpenZAP Installed -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la ozmod_libpri.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +if LIBPRI +mod_LTLIBRARIES += ozmod_libpri.la +endif ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module From 20049ab859005fb5acb31628e73ab5e8b197053f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Feb 2009 19:13:02 +0000 Subject: [PATCH 1269/1766] add api interface to oz and use it in ozmod_libpri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@656 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 3 + libs/openzap/mod_openzap/mod_openzap.c | 9 +- libs/openzap/src/include/openzap.h | 6 +- libs/openzap/src/include/zap_types.h | 8 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 131 ++++++++++++++++-- libs/openzap/src/zap_io.c | 52 ++++++- 6 files changed, 190 insertions(+), 19 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 9bf1dada2a..44df5bcd81 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -84,6 +84,9 @@ libopenzap_la_LIBADD = $(LIBS) MYLIB=libopenzap.la +core: libopenzap.la +core-install: install-libLTLIBRARIES + noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 6b941616ed..9bb5e5a902 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2320,7 +2320,14 @@ SWITCH_STANDARD_API(oz_function) } } else { - stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); + char *rply = zap_api_execute(cmd, NULL); + + if (rply) { + stream->write_function(stream, "%s", rply); + free(rply); + } else { + stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); + } } /*Q931ToPcap enhancement done*/ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 2b078e603e..e35daf1543 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -298,13 +298,14 @@ struct zap_stream_handle { zap_size_t alloc_chunk; }; + zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); #define ZAP_CMD_CHUNK_LEN 1024 #define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ - switch_assert(s.data); \ - memset(s.data, 0, SWITCH_CMD_CHUNK_LEN); \ + assert(s.data); \ + memset(s.data, 0, ZAP_CMD_CHUNK_LEN); \ s.end = s.data; \ s.data_size = ZAP_CMD_CHUNK_LEN; \ s.write_function = zap_console_stream_write; \ @@ -624,6 +625,7 @@ zap_status_t zap_span_start(zap_span_t *span); int zap_load_module(const char *name); int zap_load_module_assume(const char *name); zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); +char *zap_api_execute(const char *type, const char *cmd); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 0aca999080..fee42a14c0 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -397,10 +397,12 @@ 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_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); -typedef zap_status_t (*zap_stream_handle_raw_write_function_t) (zap_stream_handle_t *handle, const char *fmt, ...); +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) @@ -476,7 +478,7 @@ typedef zap_status_t (*zio_api_t) ZIO_API_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 ZIP_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS +#define ZIO_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS #include "zap_dso.h" diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 2a1682d02e..853dd97572 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -76,6 +76,121 @@ static void s_pri_message(struct pri *pri, char *s) } #endif + +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, "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 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], "debug")) { + 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; + 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; +} + + +static zap_io_interface_t zap_libpri_interface; + +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; +} + static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) { pri_set_error(s_pri_error); @@ -671,8 +786,6 @@ static int str2dp(char *dp) return PRI_UNKNOWN; } - - static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) { uint32_t i, x = 0; @@ -680,6 +793,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) zap_libpri_data_t *isdn_data; char *var, *val; int32_t opts = 0; + 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)); @@ -741,7 +855,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) if (!(val = va_arg(ap, char *))) { break; } - isdn_data->debug = atoi(val); + debug = val; } else { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); return ZAP_FAIL; @@ -755,11 +869,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; - - // force debug rm me later - isdn_data->debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; - - + isdn_data->debug = parse_debug(debug); + if (lpwrap_init_pri(&isdn_data->spri, span->span_id, // span isdn_data->dchan, // dchan @@ -786,7 +897,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) zap_module_t zap_module = { "libpri", - NULL, + zap_libpri_io_init, zap_libpri_unload, zap_libpri_init, zap_libpri_configure_span, @@ -795,6 +906,8 @@ zap_module_t zap_module = { + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 50198709d5..1e55a768c7 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2081,6 +2081,50 @@ static struct { } interfaces; +char *zap_api_execute(const char *type, const char *cmd) +{ + zap_io_interface_t *zio = NULL; + char *dup = NULL, *p; + char *rval = NULL; + + if (type && !cmd) { + dup = strdup(type); + if ((p = strchr(dup, ' '))) { + *p++ = '\0'; + cmd = p; + } + + type = dup; + } + + zap_mutex_lock(globals.mutex); + if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + zap_load_module_assume(type); + if ((zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + zap_mutex_unlock(globals.mutex); + + if (zio && zio->api) { + zap_stream_handle_t stream = { 0 }; + zap_status_t status; + ZAP_STANDARD_STREAM(stream); + status = zio->api(&stream, cmd); + + if (status != ZAP_SUCCESS) { + zap_safe_free(stream.data); + } else { + rval = (char *) stream.data; + } + } + + zap_safe_free(dup); + + return rval; +} + + static zap_status_t load_config(void) { char cfg_name[] = "openzap.conf"; @@ -2283,7 +2327,7 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) snprintf(filename, sizeof(filename), "%s.conf", zio->name); if (!zio->configure) { - zap_log(ZAP_LOG_ERROR, "Module %s does not support configuration.\n", zio->name); + zap_log(ZAP_LOG_DEBUG, "Module %s does not support configuration.\n", zio->name); return ZAP_FAIL; } @@ -2339,12 +2383,12 @@ int zap_load_module(const char *name) } if (mod->io_load) { - zap_io_interface_t *interface; + zap_io_interface_t *interface = NULL; - if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { + if (mod->io_load(&interface) != ZAP_SUCCESS || !interface || !interface->name) { zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); + zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface->name); zap_mutex_lock(globals.mutex); if (hashtable_search(globals.interface_hash, (void *)interface->name)) { zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); From 71d62fd995bbd61044131af0aeb445a4092ac075 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Feb 2009 19:13:02 +0000 Subject: [PATCH 1270/1766] add api interface to oz and use it in ozmod_libpri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@656 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 3 + libs/freetdm/mod_openzap/mod_openzap.c | 9 +- libs/freetdm/src/include/openzap.h | 6 +- libs/freetdm/src/include/zap_types.h | 8 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 131 ++++++++++++++++-- libs/freetdm/src/zap_io.c | 52 ++++++- 6 files changed, 190 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 9bf1dada2a..44df5bcd81 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -84,6 +84,9 @@ libopenzap_la_LIBADD = $(LIBS) MYLIB=libopenzap.la +core: libopenzap.la +core-install: install-libLTLIBRARIES + noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 6b941616ed..9bb5e5a902 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2320,7 +2320,14 @@ SWITCH_STANDARD_API(oz_function) } } else { - stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); + char *rply = zap_api_execute(cmd, NULL); + + if (rply) { + stream->write_function(stream, "%s", rply); + free(rply); + } else { + stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); + } } /*Q931ToPcap enhancement done*/ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 2b078e603e..e35daf1543 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -298,13 +298,14 @@ struct zap_stream_handle { zap_size_t alloc_chunk; }; + zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); #define ZAP_CMD_CHUNK_LEN 1024 #define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ - switch_assert(s.data); \ - memset(s.data, 0, SWITCH_CMD_CHUNK_LEN); \ + assert(s.data); \ + memset(s.data, 0, ZAP_CMD_CHUNK_LEN); \ s.end = s.data; \ s.data_size = ZAP_CMD_CHUNK_LEN; \ s.write_function = zap_console_stream_write; \ @@ -624,6 +625,7 @@ zap_status_t zap_span_start(zap_span_t *span); int zap_load_module(const char *name); int zap_load_module_assume(const char *name); zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); +char *zap_api_execute(const char *type, const char *cmd); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 0aca999080..fee42a14c0 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -397,10 +397,12 @@ 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_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); -typedef zap_status_t (*zap_stream_handle_raw_write_function_t) (zap_stream_handle_t *handle, const char *fmt, ...); +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) @@ -476,7 +478,7 @@ typedef zap_status_t (*zio_api_t) ZIO_API_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 ZIP_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS +#define ZIO_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS #include "zap_dso.h" diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 2a1682d02e..853dd97572 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -76,6 +76,121 @@ static void s_pri_message(struct pri *pri, char *s) } #endif + +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, "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 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], "debug")) { + 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; + 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; +} + + +static zap_io_interface_t zap_libpri_interface; + +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; +} + static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) { pri_set_error(s_pri_error); @@ -671,8 +786,6 @@ static int str2dp(char *dp) return PRI_UNKNOWN; } - - static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) { uint32_t i, x = 0; @@ -680,6 +793,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) zap_libpri_data_t *isdn_data; char *var, *val; int32_t opts = 0; + 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)); @@ -741,7 +855,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) if (!(val = va_arg(ap, char *))) { break; } - isdn_data->debug = atoi(val); + debug = val; } else { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); return ZAP_FAIL; @@ -755,11 +869,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; - - // force debug rm me later - isdn_data->debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; - - + isdn_data->debug = parse_debug(debug); + if (lpwrap_init_pri(&isdn_data->spri, span->span_id, // span isdn_data->dchan, // dchan @@ -786,7 +897,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) zap_module_t zap_module = { "libpri", - NULL, + zap_libpri_io_init, zap_libpri_unload, zap_libpri_init, zap_libpri_configure_span, @@ -795,6 +906,8 @@ zap_module_t zap_module = { + + /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 50198709d5..1e55a768c7 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2081,6 +2081,50 @@ static struct { } interfaces; +char *zap_api_execute(const char *type, const char *cmd) +{ + zap_io_interface_t *zio = NULL; + char *dup = NULL, *p; + char *rval = NULL; + + if (type && !cmd) { + dup = strdup(type); + if ((p = strchr(dup, ' '))) { + *p++ = '\0'; + cmd = p; + } + + type = dup; + } + + zap_mutex_lock(globals.mutex); + if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + zap_load_module_assume(type); + if ((zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + zap_mutex_unlock(globals.mutex); + + if (zio && zio->api) { + zap_stream_handle_t stream = { 0 }; + zap_status_t status; + ZAP_STANDARD_STREAM(stream); + status = zio->api(&stream, cmd); + + if (status != ZAP_SUCCESS) { + zap_safe_free(stream.data); + } else { + rval = (char *) stream.data; + } + } + + zap_safe_free(dup); + + return rval; +} + + static zap_status_t load_config(void) { char cfg_name[] = "openzap.conf"; @@ -2283,7 +2327,7 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) snprintf(filename, sizeof(filename), "%s.conf", zio->name); if (!zio->configure) { - zap_log(ZAP_LOG_ERROR, "Module %s does not support configuration.\n", zio->name); + zap_log(ZAP_LOG_DEBUG, "Module %s does not support configuration.\n", zio->name); return ZAP_FAIL; } @@ -2339,12 +2383,12 @@ int zap_load_module(const char *name) } if (mod->io_load) { - zap_io_interface_t *interface; + zap_io_interface_t *interface = NULL; - if (mod->io_load(&interface) != ZAP_SUCCESS || !interface) { + if (mod->io_load(&interface) != ZAP_SUCCESS || !interface || !interface->name) { zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s\n", path); + zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface->name); zap_mutex_lock(globals.mutex); if (hashtable_search(globals.interface_hash, (void *)interface->name)) { zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); From c588a513dbfb27a7bd32b2a5b1b3b9ccb6c5d111 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Feb 2009 16:41:03 +0000 Subject: [PATCH 1271/1766] fix hangup issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@657 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 853dd97572..7bb7b7678b 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -443,7 +443,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (call && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + 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); From acce4cccd01b8f0124cd3a7733faa97d785c6822 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Feb 2009 16:41:03 +0000 Subject: [PATCH 1272/1766] fix hangup issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@657 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 853dd97572..7bb7b7678b 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -443,7 +443,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (call && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + 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); From 8e2c4ebc19d967d27e68c2910ef5ed821fecbdf0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Feb 2009 16:43:16 +0000 Subject: [PATCH 1273/1766] fix sangoma caller-id issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@658 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 3be93f2e01..4efdf6dc76 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -586,8 +586,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_OFFHOOK: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = zchan->span->start_type == ZAP_ANALOG_START_KEWL ? - WP_TDMAPI_EVENT_TXSIG_START : WP_TDMAPI_EVENT_TXSIG_KEWL; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); @@ -611,8 +610,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_GENERATE_RING_ON: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; @@ -625,8 +623,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_GENERATE_RING_OFF: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); return ZAP_FAIL; @@ -793,7 +790,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) memset(&tdm_api, 0, sizeof(tdm_api)); if (zap_test_pflag(zchan, WP_RINGING)) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); @@ -803,7 +800,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_off_ms; } else { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); From 2e24552fa51b4eb501e8b7875c422d0d7c98baab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Feb 2009 16:43:16 +0000 Subject: [PATCH 1274/1766] fix sangoma caller-id issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@658 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 3be93f2e01..4efdf6dc76 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -586,8 +586,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_OFFHOOK: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = zchan->span->start_type == ZAP_ANALOG_START_KEWL ? - WP_TDMAPI_EVENT_TXSIG_START : WP_TDMAPI_EVENT_TXSIG_KEWL; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); @@ -611,8 +610,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_GENERATE_RING_ON: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; @@ -625,8 +623,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_GENERATE_RING_OFF: { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); return ZAP_FAIL; @@ -793,7 +790,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) memset(&tdm_api, 0, sizeof(tdm_api)); if (zap_test_pflag(zchan, WP_RINGING)) { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); @@ -803,7 +800,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_off_ms; } else { tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING; + tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); From 2550fc4f43b637770d883db2bc2e85d0fa3db21c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Feb 2009 20:31:47 +0000 Subject: [PATCH 1275/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@659 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/testcid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/testcid.c b/libs/openzap/src/testcid.c index 815ae2a0d2..0018bb9a5d 100644 --- a/libs/openzap/src/testcid.c +++ b/libs/openzap/src/testcid.c @@ -9,7 +9,9 @@ struct helper { zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) { struct helper *foo = (struct helper *) user_data; - write(foo->fd, buf, buflen * 2); + size_t len; + len = write(foo->fd, buf, buflen * 2); + if (!len) return ZAP_FAIL; foo->wrote += buflen * 2; return ZAP_SUCCESS; } From d424569f34ec85857c09aa2643209960f91550bf Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Feb 2009 20:31:47 +0000 Subject: [PATCH 1276/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@659 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testcid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index 815ae2a0d2..0018bb9a5d 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -9,7 +9,9 @@ struct helper { zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) { struct helper *foo = (struct helper *) user_data; - write(foo->fd, buf, buflen * 2); + size_t len; + len = write(foo->fd, buf, buflen * 2); + if (!len) return ZAP_FAIL; foo->wrote += buflen * 2; return ZAP_SUCCESS; } From 05d80e3930584ff2cc613dd7b00120060bfa9a5a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Feb 2009 23:44:51 +0000 Subject: [PATCH 1277/1766] fix hangup issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@660 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 7bb7b7678b..3dc0c88ad4 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -511,6 +511,7 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even call = (q931_call *) zchan->call_data; zap_log(ZAP_LOG_DEBUG, "-- Hangup on channel %d:%d\n", spri->span, 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 { From 9b02e629030b051d7624758c49d996cf42a54001 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Feb 2009 23:44:51 +0000 Subject: [PATCH 1278/1766] fix hangup issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@660 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 7bb7b7678b..3dc0c88ad4 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -511,6 +511,7 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even call = (q931_call *) zchan->call_data; zap_log(ZAP_LOG_DEBUG, "-- Hangup on channel %d:%d\n", spri->span, 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 { From da81f09ada2b95a03b36c1fcc6f46b2919a3d6a3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 11 Feb 2009 00:17:17 +0000 Subject: [PATCH 1279/1766] clean up tone_detect git-svn-id: http://svn.openzap.org/svn/openzap/trunk@661 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index c85ac59161..79875a0ade 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -141,10 +141,16 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma 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; } @@ -157,10 +163,6 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma mt->hit_factor = 2; } - if (!mt->sample_rate) { - mt->sample_rate = 8000; - } - for(x = 0; x < TELETONE_MAX_TONES; x++) { if ((int) map->freqs[x] == 0) { break; From a846877a47bc67c6159ddf656dc7b4971accb4a2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 11 Feb 2009 00:17:17 +0000 Subject: [PATCH 1280/1766] clean up tone_detect git-svn-id: http://svn.openzap.org/svn/openzap/trunk@661 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index c85ac59161..79875a0ade 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -141,10 +141,16 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma 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; } @@ -157,10 +163,6 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma mt->hit_factor = 2; } - if (!mt->sample_rate) { - mt->sample_rate = 8000; - } - for(x = 0; x < TELETONE_MAX_TONES; x++) { if ((int) map->freqs[x] == 0) { break; From f931915e8af6b15470df061b3ef0f3df90811e2b Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 11 Feb 2009 16:04:30 +0000 Subject: [PATCH 1281/1766] [ozmod_isdn] Backport fix from rework branch: use channel flag rather than CRVFlag to properly release channels in ZAP_CHANNEL_STATE_DOWN transition git-svn-id: http://svn.openzap.org/svn/openzap/trunk@662 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 5f4c1ce4d6..24822f107a 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1038,7 +1038,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DOWN: { if (gen->CRV) { - if(gen->CRVFlag) { + 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; From 2505bfd29f3921c8efaf5b1fb191efc15a78bf3b Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 11 Feb 2009 16:04:30 +0000 Subject: [PATCH 1282/1766] [ozmod_isdn] Backport fix from rework branch: use channel flag rather than CRVFlag to properly release channels in ZAP_CHANNEL_STATE_DOWN transition git-svn-id: http://svn.openzap.org/svn/openzap/trunk@662 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 5f4c1ce4d6..24822f107a 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1038,7 +1038,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DOWN: { if (gen->CRV) { - if(gen->CRVFlag) { + 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; From decaf14be36027e77364b7fa90222322e5e5c493 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 11 Feb 2009 22:47:44 +0000 Subject: [PATCH 1283/1766] name first then number if it's blank git-svn-id: http://svn.openzap.org/svn/openzap/trunk@663 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 3dc0c88ad4..317e0d8ad1 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -607,7 +607,11 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_set_string(zchan->caller_data.cid_num.digits, (char *)pevent->ring.callingnum); - zap_set_string(zchan->caller_data.cid_name, (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); From 9eacbc411a8077aa8f9a8486ae28326ba2b7775a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 11 Feb 2009 22:47:44 +0000 Subject: [PATCH 1284/1766] name first then number if it's blank git-svn-id: http://svn.openzap.org/svn/openzap/trunk@663 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 3dc0c88ad4..317e0d8ad1 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -607,7 +607,11 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); zap_set_string(zchan->caller_data.cid_num.digits, (char *)pevent->ring.callingnum); - zap_set_string(zchan->caller_data.cid_name, (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); From b18d9875ed121541b6d36c0c5c86abd35be21744 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 21 Feb 2009 00:44:52 +0000 Subject: [PATCH 1285/1766] fix bounds check git-svn-id: http://svn.openzap.org/svn/openzap/trunk@665 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 1e55a768c7..4647fbef04 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -839,7 +839,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { - if (span_id >= ZAP_MAX_SPANS_INTERFACE) { + if (span_id >= globals.span_index) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; From 282934f8a589c19b14e37b0c08174d25f8501169 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 21 Feb 2009 00:44:52 +0000 Subject: [PATCH 1286/1766] fix bounds check git-svn-id: http://svn.openzap.org/svn/openzap/trunk@665 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1e55a768c7..4647fbef04 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -839,7 +839,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { - if (span_id >= ZAP_MAX_SPANS_INTERFACE) { + if (span_id >= globals.span_index) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; From dad062dcda06971c9fe85fd72bb42893acba00cb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 24 Feb 2009 05:05:25 +0000 Subject: [PATCH 1287/1766] OPENZAP-53/OPENZAP-52 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@666 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 9bb5e5a902..49009a1109 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1012,7 +1012,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } - if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) { private_t *tech_pvt; switch_caller_profile_t *caller_profile; switch_channel_t *channel = switch_core_session_get_channel(*new_session); @@ -1082,7 +1082,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(openzap_endpoint_interface, NULL))) { + if (!(session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); return ZAP_FAIL; } From 908ed389150a4f86d94d1baed3de7d7ad453cfa5 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 24 Feb 2009 05:05:25 +0000 Subject: [PATCH 1288/1766] OPENZAP-53/OPENZAP-52 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@666 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9bb5e5a902..49009a1109 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1012,7 +1012,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } - if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) { private_t *tech_pvt; switch_caller_profile_t *caller_profile; switch_channel_t *channel = switch_core_session_get_channel(*new_session); @@ -1082,7 +1082,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(openzap_endpoint_interface, NULL))) { + if (!(session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); return ZAP_FAIL; } From 29da776fd06d5c7c6c8611145bd183779fb36498 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Tue, 24 Feb 2009 08:26:52 +0000 Subject: [PATCH 1289/1766] Setting InUse channel flag in function "zap_channel_open_chan" of zap_io.c Without this, inbound calls never were marked as InUse. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@667 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 4647fbef04..8fd60a85e8 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1029,7 +1029,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { - zap_set_flag(zchan, ZAP_CHANNEL_OPEN); + zap_set_flag(zchan, ZAP_CHANNEL_OPEN+ZAP_CHANNEL_INUSE); } } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); From 324ec34ce96fdb1f2765c20ee9540d5920219bc0 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Tue, 24 Feb 2009 08:26:52 +0000 Subject: [PATCH 1290/1766] Setting InUse channel flag in function "zap_channel_open_chan" of zap_io.c Without this, inbound calls never were marked as InUse. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@667 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 4647fbef04..8fd60a85e8 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1029,7 +1029,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { - zap_set_flag(zchan, ZAP_CHANNEL_OPEN); + zap_set_flag(zchan, ZAP_CHANNEL_OPEN+ZAP_CHANNEL_INUSE); } } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); From 5d51fdbf5ad42664206d607b83a60cbea6f3599d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 24 Feb 2009 16:37:25 +0000 Subject: [PATCH 1291/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@668 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8fd60a85e8..daaf1061cb 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1029,7 +1029,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { - zap_set_flag(zchan, ZAP_CHANNEL_OPEN+ZAP_CHANNEL_INUSE); + zap_set_flag(zchan, ZAP_CHANNEL_OPEN | ZAP_CHANNEL_INUSE); } } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); From 3c735dcdb6db4e0137e1caded0f8448ae9445fa3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 24 Feb 2009 16:37:25 +0000 Subject: [PATCH 1292/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@668 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8fd60a85e8..daaf1061cb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1029,7 +1029,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { status = zchan->span->zio->open(zchan); if (status == ZAP_SUCCESS) { - zap_set_flag(zchan, ZAP_CHANNEL_OPEN+ZAP_CHANNEL_INUSE); + zap_set_flag(zchan, ZAP_CHANNEL_OPEN | ZAP_CHANNEL_INUSE); } } else { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); From 9fd7b44c8e96470ea965928c5c7772eb97c0ebb8 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 20:50:10 +0000 Subject: [PATCH 1293/1766] Switch hangup cause to NORMAL_CIRCUIT_CONGESTION when no channels are available so it transates into 'no circuit/channel available [Q.850]' git-svn-id: http://svn.openzap.org/svn/openzap/trunk@669 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 49009a1109..c9b200fa2f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -999,7 +999,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; } zap_channel_clear_vars(zchan); From 1086c7c73c5875826ec3bf9b385e4129484bd326 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 20:50:10 +0000 Subject: [PATCH 1294/1766] Switch hangup cause to NORMAL_CIRCUIT_CONGESTION when no channels are available so it transates into 'no circuit/channel available [Q.850]' git-svn-id: http://svn.openzap.org/svn/openzap/trunk@669 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 49009a1109..c9b200fa2f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -999,7 +999,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; } zap_channel_clear_vars(zchan); From fb0777c5039e8b6dfe3340ec76e330821b26898b Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 21:27:35 +0000 Subject: [PATCH 1295/1766] Fix span index issues git-svn-id: http://svn.openzap.org/svn/openzap/trunk@670 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index daaf1061cb..e83bcf3759 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -839,7 +839,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { - if (span_id >= globals.span_index) { + if (span_id > globals.span_index || !globals.span[span_id]) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; @@ -1047,9 +1047,16 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; + + if (span_id > globals.span_index || !globals.span[span_id]) { + zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); + *zchan = NULL; + goto done; + } if (globals.spans[span_id]->channel_request) { zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + *zchan = NULL; goto done; } @@ -1057,6 +1064,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + *zchan = NULL; goto done; } From 6e19d9add7926b6c60224eab00e866284ea4f61f Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 21:27:35 +0000 Subject: [PATCH 1296/1766] Fix span index issues git-svn-id: http://svn.openzap.org/svn/openzap/trunk@670 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index daaf1061cb..e83bcf3759 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -839,7 +839,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { - if (span_id >= globals.span_index) { + if (span_id > globals.span_index || !globals.span[span_id]) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; @@ -1047,9 +1047,16 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; + + if (span_id > globals.span_index || !globals.span[span_id]) { + zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); + *zchan = NULL; + goto done; + } if (globals.spans[span_id]->channel_request) { zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + *zchan = NULL; goto done; } @@ -1057,6 +1064,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + *zchan = NULL; goto done; } From 499ccc1925ee46fd2a13eb8ea8740a55bde51736 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 21:41:16 +0000 Subject: [PATCH 1297/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@671 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index e83bcf3759..16dca8afcd 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -839,7 +839,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { - if (span_id > globals.span_index || !globals.span[span_id]) { + if (span_id > globals.span_index || !globals.spans[span_id]) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; @@ -1048,7 +1048,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; - if (span_id > globals.span_index || !globals.span[span_id]) { + if (span_id > globals.span_index || !globals.spans[span_id]) { zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); *zchan = NULL; goto done; From f0217503362a6b21bd342e22dd24f7d6ebd80f68 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 21:41:16 +0000 Subject: [PATCH 1298/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@671 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index e83bcf3759..16dca8afcd 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -839,7 +839,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z uint32_t span_max; if (span_id) { - if (span_id > globals.span_index || !globals.span[span_id]) { + if (span_id > globals.span_index || !globals.spans[span_id]) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; @@ -1048,7 +1048,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *check; - if (span_id > globals.span_index || !globals.span[span_id]) { + if (span_id > globals.span_index || !globals.spans[span_id]) { zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); *zchan = NULL; goto done; From 60b5da016b1d3a2236a60edac141f857d85a05e6 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 23:48:37 +0000 Subject: [PATCH 1299/1766] Offer media channels on inbound calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@672 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 317e0d8ad1..5ee468a458 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -59,22 +59,17 @@ static void s_pri_error(char *s) static void s_pri_error(struct pri *pri, char *s) #endif { - zap_log(ZAP_LOG_ERROR, "%s", s); - } #ifdef WIN32 static void s_pri_message(char *s) -{ - zap_log(ZAP_LOG_DEBUG, "%s", s); -} #else static void s_pri_message(struct pri *pri, char *s) -{ - zap_log(ZAP_LOG_DEBUG, "%s", s); -} #endif +{ + zap_log(ZAP_LOG_DEBUG, "%s", s); +} static int parse_debug(const char *in) @@ -357,7 +352,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { - pri_progress(isdn_data->spri.pri, call, zchan->chan_id, 0); + pri_progress(isdn_data->spri.pri, call, zchan->chan_id, 1); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } @@ -371,7 +366,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { - pri_proceeding(isdn_data->spri.pri, call, zchan->chan_id, 0); + pri_proceeding(isdn_data->spri.pri, call, zchan->chan_id, 1); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } From 22a817b1b26995b09a3875c955a4d2ecfe450d2a Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 24 Feb 2009 23:48:37 +0000 Subject: [PATCH 1300/1766] Offer media channels on inbound calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@672 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 317e0d8ad1..5ee468a458 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -59,22 +59,17 @@ static void s_pri_error(char *s) static void s_pri_error(struct pri *pri, char *s) #endif { - zap_log(ZAP_LOG_ERROR, "%s", s); - } #ifdef WIN32 static void s_pri_message(char *s) -{ - zap_log(ZAP_LOG_DEBUG, "%s", s); -} #else static void s_pri_message(struct pri *pri, char *s) -{ - zap_log(ZAP_LOG_DEBUG, "%s", s); -} #endif +{ + zap_log(ZAP_LOG_DEBUG, "%s", s); +} static int parse_debug(const char *in) @@ -357,7 +352,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { - pri_progress(isdn_data->spri.pri, call, zchan->chan_id, 0); + pri_progress(isdn_data->spri.pri, call, zchan->chan_id, 1); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } @@ -371,7 +366,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { - pri_proceeding(isdn_data->spri.pri, call, zchan->chan_id, 0); + pri_proceeding(isdn_data->spri.pri, call, zchan->chan_id, 1); } else { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); } From 94a99e9906d1e9cfe61ec766634042ffeb457119 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Wed, 25 Feb 2009 09:49:54 +0000 Subject: [PATCH 1301/1766] Added timestamp for Q931ToPcap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@673 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 24822f107a..43bada21b1 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -163,9 +163,10 @@ static zap_status_t closePcapFile(void) static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) { - L3UCHAR *frame = NULL; + L3UCHAR *frame = NULL; + struct timeval ts; u_char spanid = (u_char)span_id; - unsigned long *tcp_next_seq_no = NULL; + unsigned long *tcp_next_seq_no = NULL; spanid=span_id; @@ -191,8 +192,8 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L if(q931size > MAX_Q931_SIZE) { /*WARNING*/ - zap_log(ZAP_LOG_WARNING, "Q931 packet size is too big (%u)! Limitting it to %u! Q931 packet will be corrupt.\n", q931size, MAX_Q931_SIZE); - q931size=MAX_Q931_SIZE; + zap_log(ZAP_LOG_WARNING, "Q931 packet size is too big (%u)! Ignoring it!\n", q931size); + return ZAP_FAIL; } /*Copy q931 buffer into frame*/ @@ -219,16 +220,16 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L pcaphdr.caplen = SIZE_ETHERNET+SIZE_ETHERNET_CRC+q931size; pcaphdr.len = pcaphdr.caplen; - pcap_dump((u_char*)pcapfile, &pcaphdr, frame); - pcap_dump_flush(pcapfile); - /*Increase microsecond timestamp by 1*/ - pcaphdr.ts.tv_usec++; - if(pcaphdr.ts.tv_usec==1000000) - { - pcaphdr.ts.tv_sec++; - pcaphdr.ts.tv_usec=0; - } + /* 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; @@ -973,9 +974,6 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg { int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; -#ifdef HAVE_LIBPCAP - zap_span_t *span = (zap_span_t *) pvt; /*To get access to spanid for Q931ToPcap*/ -#endif switch(ind) { case Q921_DL_DATA: @@ -984,6 +982,7 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg #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"); } @@ -991,6 +990,7 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg /*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) @@ -1735,9 +1735,6 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I { int offset = 4; char bb[4096] = ""; -#ifdef HAVE_LIBPCAP - zap_span_t *span = (zap_span_t *) pvt; /*To get access to span_id for Q931ToPcap*/ -#endif switch(ind) { case Q921_DL_UNIT_DATA: @@ -1748,6 +1745,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I #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"); } From 6b5e1c48a92029a272b2e99405abdf6f3c630f34 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Wed, 25 Feb 2009 09:49:54 +0000 Subject: [PATCH 1302/1766] Added timestamp for Q931ToPcap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@673 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 24822f107a..43bada21b1 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -163,9 +163,10 @@ static zap_status_t closePcapFile(void) static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) { - L3UCHAR *frame = NULL; + L3UCHAR *frame = NULL; + struct timeval ts; u_char spanid = (u_char)span_id; - unsigned long *tcp_next_seq_no = NULL; + unsigned long *tcp_next_seq_no = NULL; spanid=span_id; @@ -191,8 +192,8 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L if(q931size > MAX_Q931_SIZE) { /*WARNING*/ - zap_log(ZAP_LOG_WARNING, "Q931 packet size is too big (%u)! Limitting it to %u! Q931 packet will be corrupt.\n", q931size, MAX_Q931_SIZE); - q931size=MAX_Q931_SIZE; + zap_log(ZAP_LOG_WARNING, "Q931 packet size is too big (%u)! Ignoring it!\n", q931size); + return ZAP_FAIL; } /*Copy q931 buffer into frame*/ @@ -219,16 +220,16 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L pcaphdr.caplen = SIZE_ETHERNET+SIZE_ETHERNET_CRC+q931size; pcaphdr.len = pcaphdr.caplen; - pcap_dump((u_char*)pcapfile, &pcaphdr, frame); - pcap_dump_flush(pcapfile); - /*Increase microsecond timestamp by 1*/ - pcaphdr.ts.tv_usec++; - if(pcaphdr.ts.tv_usec==1000000) - { - pcaphdr.ts.tv_sec++; - pcaphdr.ts.tv_usec=0; - } + /* 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; @@ -973,9 +974,6 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg { int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3; char bb[4096] = ""; -#ifdef HAVE_LIBPCAP - zap_span_t *span = (zap_span_t *) pvt; /*To get access to spanid for Q931ToPcap*/ -#endif switch(ind) { case Q921_DL_DATA: @@ -984,6 +982,7 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg #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"); } @@ -991,6 +990,7 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg /*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) @@ -1735,9 +1735,6 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I { int offset = 4; char bb[4096] = ""; -#ifdef HAVE_LIBPCAP - zap_span_t *span = (zap_span_t *) pvt; /*To get access to span_id for Q931ToPcap*/ -#endif switch(ind) { case Q921_DL_UNIT_DATA: @@ -1748,6 +1745,7 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I #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"); } From 34c005b3de6ee925dbaa8e5a42a7f90304cfbe7d Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Thu, 26 Feb 2009 08:31:04 +0000 Subject: [PATCH 1303/1766] Enhanced zap_channel_done in zap_io.c to set channel->state to ZAP_CHANNEL_STATE_DOWN. Befor that the function only sets init_state to DOWN, which is quite bad when there are hanging channels with state <> DOWN and ozmod_isdn.c make it decisions on that. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@674 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 16dca8afcd..e71f0cda9c 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1131,6 +1131,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; + zchan->state = ZAP_CHANNEL_STATE_DOWN; zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); return ZAP_SUCCESS; From d7bb5450ae2ab7b3c391f5dedb4c039262efb518 Mon Sep 17 00:00:00 2001 From: Helmut Kuper Date: Thu, 26 Feb 2009 08:31:04 +0000 Subject: [PATCH 1304/1766] Enhanced zap_channel_done in zap_io.c to set channel->state to ZAP_CHANNEL_STATE_DOWN. Befor that the function only sets init_state to DOWN, which is quite bad when there are hanging channels with state <> DOWN and ozmod_isdn.c make it decisions on that. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@674 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 16dca8afcd..e71f0cda9c 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1131,6 +1131,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; + zchan->state = ZAP_CHANNEL_STATE_DOWN; zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); return ZAP_SUCCESS; From 0f896928b30862a4c39253d7c82340a4aa2e7f6a Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Sun, 1 Mar 2009 23:10:17 +0000 Subject: [PATCH 1305/1766] Support more node type values and spam the console if an invalid one is used git-svn-id: http://svn.openzap.org/svn/openzap/trunk@675 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 5ee468a458..169cae6146 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -733,11 +733,11 @@ static zap_status_t zap_libpri_start(zap_span_t *span) static int str2node(char *node) { - if (!strcasecmp(node, "cpe")) + if (!strcasecmp(node, "cpe") || !strcasecmp(node, "user")) return PRI_CPE; - if (!strcasecmp(node, "network")) + if (!strcasecmp(node, "network") || !strcasecmp(node, "net")) return PRI_NETWORK; - return PRI_CPE; + return -1; } static int str2switch(char *swtype) @@ -826,10 +826,16 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "node")) { + int node; if (!(val = va_arg(ap, char *))) { break; } - isdn_data->node = str2node(val); + node = str2node(val); + if (-1 == node) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "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; From c7c8742e159b3e02c185384d9a1b4c9e49b8cd80 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Sun, 1 Mar 2009 23:10:17 +0000 Subject: [PATCH 1306/1766] Support more node type values and spam the console if an invalid one is used git-svn-id: http://svn.openzap.org/svn/openzap/trunk@675 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 5ee468a458..169cae6146 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -733,11 +733,11 @@ static zap_status_t zap_libpri_start(zap_span_t *span) static int str2node(char *node) { - if (!strcasecmp(node, "cpe")) + if (!strcasecmp(node, "cpe") || !strcasecmp(node, "user")) return PRI_CPE; - if (!strcasecmp(node, "network")) + if (!strcasecmp(node, "network") || !strcasecmp(node, "net")) return PRI_NETWORK; - return PRI_CPE; + return -1; } static int str2switch(char *swtype) @@ -826,10 +826,16 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "node")) { + int node; if (!(val = va_arg(ap, char *))) { break; } - isdn_data->node = str2node(val); + node = str2node(val); + if (-1 == node) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "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; From e15a98a9ac98f427a70b8421043eae00d2b2ae15 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Sun, 1 Mar 2009 23:38:33 +0000 Subject: [PATCH 1307/1766] openzap/0/a will pick the first available channel, on the first available span (same rules apply for a and A) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@676 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 11 ++- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/openzap/src/zap_io.c | 75 +++++++++---------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c9b200fa2f..5c9aa41963 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -891,7 +891,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi const char *dest = NULL; char *data = NULL; - int span_id = 0, chan_id = 0; + int span_id = -1, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; @@ -941,7 +941,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi dest = ""; } - if (!span_id && !switch_strlen_zero(span_name)) { + if (span_id == 0 && chan_id != 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Span 0 is used to pick the first available span, selecting a channel is not supported (and doesn't make sense)\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if (span_id == -1 && !switch_strlen_zero(span_name)) { zap_span_t *span; zap_status_t zstatus = zap_span_find_by_name(span_name, &span); if (zstatus == ZAP_SUCCESS && span) { @@ -949,7 +954,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } - if (!span_id) { + if (span_id == -1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 169cae6146..dc6555d1ba 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -832,7 +832,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } node = str2node(val); if (-1 == node) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown node type %s, defaulting to CPE mode\n", val); + zap_log(ZAP_LOG_ERROR, "Unknown node type %s, defaulting to CPE mode\n", val); node = PRI_CPE; } isdn_data->node = node; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index e71f0cda9c..ad00ce9f03 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1041,51 +1041,48 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { + zap_channel_t *check; zap_status_t status = ZAP_FAIL; zap_mutex_lock(globals.mutex); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { - zap_channel_t *check; - - if (span_id > globals.span_index || !globals.spans[span_id]) { - zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); - *zchan = NULL; - goto done; - } - - if (globals.spans[span_id]->channel_request) { - zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); - *zchan = NULL; - goto done; - } - - check = globals.spans[span_id]->channels[chan_id]; - - if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || - !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { - *zchan = NULL; - goto done; - } - - status = ZAP_FAIL; - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || - (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { - if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - } - } else { - status = ZAP_SUCCESS; - } - zap_set_flag(check, ZAP_CHANNEL_INUSE); - *zchan = check; - } - zap_mutex_unlock(check->mutex); + if (span_id > globals.span_index || chan_id >= ZAP_MAX_CHANNELS_SPAN || !globals.spans[span_id]) { + zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); + *zchan = NULL; + goto done; } + if (globals.spans[span_id]->channel_request) { + zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + *zchan = NULL; + goto done; + } + + check = globals.spans[span_id]->channels[chan_id]; + + if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || + !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + *zchan = NULL; + goto done; + } + + status = ZAP_FAIL; + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || + (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { + if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zio->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + } + } else { + status = ZAP_SUCCESS; + } + zap_set_flag(check, ZAP_CHANNEL_INUSE); + *zchan = check; + } + zap_mutex_unlock(check->mutex); + done: zap_mutex_unlock(globals.mutex); From f5c913452a5c12c0ae4e0a6246af25673ad48268 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Sun, 1 Mar 2009 23:38:33 +0000 Subject: [PATCH 1308/1766] openzap/0/a will pick the first available channel, on the first available span (same rules apply for a and A) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@676 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 11 ++- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/freetdm/src/zap_io.c | 75 +++++++++---------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index c9b200fa2f..5c9aa41963 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -891,7 +891,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi const char *dest = NULL; char *data = NULL; - int span_id = 0, chan_id = 0; + int span_id = -1, chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; @@ -941,7 +941,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi dest = ""; } - if (!span_id && !switch_strlen_zero(span_name)) { + if (span_id == 0 && chan_id != 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Span 0 is used to pick the first available span, selecting a channel is not supported (and doesn't make sense)\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } + + if (span_id == -1 && !switch_strlen_zero(span_name)) { zap_span_t *span; zap_status_t zstatus = zap_span_find_by_name(span_name, &span); if (zstatus == ZAP_SUCCESS && span) { @@ -949,7 +954,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } } - if (!span_id) { + if (span_id == -1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 169cae6146..dc6555d1ba 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -832,7 +832,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } node = str2node(val); if (-1 == node) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown node type %s, defaulting to CPE mode\n", val); + zap_log(ZAP_LOG_ERROR, "Unknown node type %s, defaulting to CPE mode\n", val); node = PRI_CPE; } isdn_data->node = node; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index e71f0cda9c..ad00ce9f03 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1041,51 +1041,48 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { + zap_channel_t *check; zap_status_t status = ZAP_FAIL; zap_mutex_lock(globals.mutex); - if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN) { - zap_channel_t *check; - - if (span_id > globals.span_index || !globals.spans[span_id]) { - zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); - *zchan = NULL; - goto done; - } - - if (globals.spans[span_id]->channel_request) { - zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); - *zchan = NULL; - goto done; - } - - check = globals.spans[span_id]->channels[chan_id]; - - if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || - !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { - *zchan = NULL; - goto done; - } - - status = ZAP_FAIL; - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || - (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { - if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - } - } else { - status = ZAP_SUCCESS; - } - zap_set_flag(check, ZAP_CHANNEL_INUSE); - *zchan = check; - } - zap_mutex_unlock(check->mutex); + if (span_id > globals.span_index || chan_id >= ZAP_MAX_CHANNELS_SPAN || !globals.spans[span_id]) { + zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); + *zchan = NULL; + goto done; } + if (globals.spans[span_id]->channel_request) { + zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + *zchan = NULL; + goto done; + } + + check = globals.spans[span_id]->channels[chan_id]; + + if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || + !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { + *zchan = NULL; + goto done; + } + + status = ZAP_FAIL; + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || + (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { + if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { + status = check->zio->open(check); + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_OPEN); + } + } else { + status = ZAP_SUCCESS; + } + zap_set_flag(check, ZAP_CHANNEL_INUSE); + *zchan = check; + } + zap_mutex_unlock(check->mutex); + done: zap_mutex_unlock(globals.mutex); From 60fe2998d554dac159e9c50aa0fff19c22857a3e Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Sun, 1 Mar 2009 23:44:28 +0000 Subject: [PATCH 1309/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@677 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index ad00ce9f03..0f6bf94bf5 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -914,7 +914,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z check->state == ZAP_CHANNEL_STATE_DOWN ) { - if (globals.spans[span_id]->channel_request) { + if (globals.spans[span_id] && globals.spans[span_id]->channel_request) { status = globals.spans[span_id]->channel_request(globals.spans[span_id], i, direction, caller_data, zchan); zap_mutex_unlock(span->mutex); goto done; From 5b6a3b74cfbb4fc14a774dc2d64b570804d62933 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Sun, 1 Mar 2009 23:44:28 +0000 Subject: [PATCH 1310/1766] doh git-svn-id: http://svn.openzap.org/svn/openzap/trunk@677 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index ad00ce9f03..0f6bf94bf5 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -914,7 +914,7 @@ zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, z check->state == ZAP_CHANNEL_STATE_DOWN ) { - if (globals.spans[span_id]->channel_request) { + if (globals.spans[span_id] && globals.spans[span_id]->channel_request) { status = globals.spans[span_id]->channel_request(globals.spans[span_id], i, direction, caller_data, zchan); zap_mutex_unlock(span->mutex); goto done; From 6e210cbed6e014e387ecebbb4077cc310318b42d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Mar 2009 22:05:11 +0000 Subject: [PATCH 1311/1766] add ton support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@678 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 6 +++++ .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 26 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5c9aa41963..590c22112a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -979,6 +979,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { caller_data.ani.type = Q931_TON_NATIONAL; + } else if (!strcasecmp(var, "international")) { + caller_data.ani.type = Q931_TON_INTERNATIONAL; + } else if (!strcasecmp(var, "local")) { + caller_data.ani.type = Q931_TON_SUBSCRIBER_NUMBER; + } else if (!strcasecmp(var, "unknown")) { + caller_data.ani.type = Q931_TON_UNKNOWN; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index dc6555d1ba..5550f9f4b7 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -412,20 +412,38 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DIALING: if (isdn_data) { struct pri_sr *sr; - + int dp; + const char *val; + 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 Q931_TON_NATIONAL: + dp = PRI_NATIONAL_ISDN; + break; + case Q931_TON_INTERNATIONAL: + dp = PRI_INTERNATIONAL_ISDN; + break; + case Q931_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, isdn_data->dp, 1); - pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, zchan->caller_data.cid_name, isdn_data->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); - pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, isdn_data->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL); + pri_sr_set_called(sr, zchan->caller_data.ani.digits, dp, 1); + pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, zchan->caller_data.cid_name, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + 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; From 60a793c03cf24762838c644b5d88d1dc62996a4d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Mar 2009 22:05:11 +0000 Subject: [PATCH 1312/1766] add ton support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@678 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 6 +++++ .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 26 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5c9aa41963..590c22112a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -979,6 +979,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { caller_data.ani.type = Q931_TON_NATIONAL; + } else if (!strcasecmp(var, "international")) { + caller_data.ani.type = Q931_TON_INTERNATIONAL; + } else if (!strcasecmp(var, "local")) { + caller_data.ani.type = Q931_TON_SUBSCRIBER_NUMBER; + } else if (!strcasecmp(var, "unknown")) { + caller_data.ani.type = Q931_TON_UNKNOWN; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index dc6555d1ba..5550f9f4b7 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -412,20 +412,38 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_DIALING: if (isdn_data) { struct pri_sr *sr; - + int dp; + const char *val; + 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 Q931_TON_NATIONAL: + dp = PRI_NATIONAL_ISDN; + break; + case Q931_TON_INTERNATIONAL: + dp = PRI_INTERNATIONAL_ISDN; + break; + case Q931_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, isdn_data->dp, 1); - pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, zchan->caller_data.cid_name, isdn_data->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); - pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, isdn_data->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL); + pri_sr_set_called(sr, zchan->caller_data.ani.digits, dp, 1); + pri_sr_set_caller(sr, zchan->caller_data.cid_num.digits, zchan->caller_data.cid_name, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + 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; From 77e180f2e2ed664cdf0093d7ceb922129efce4fb Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 3 Mar 2009 03:15:54 +0000 Subject: [PATCH 1313/1766] Remove unused variable git-svn-id: http://svn.openzap.org/svn/openzap/trunk@679 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 5550f9f4b7..2e7a00b1f7 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -413,7 +413,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (isdn_data) { struct pri_sr *sr; int dp; - const char *val; if (!(call = pri_new_call(isdn_data->spri.pri))) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); From d0fa5d2f0272f1a4240317ff0043e957f5fbdb38 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 3 Mar 2009 03:15:54 +0000 Subject: [PATCH 1314/1766] Remove unused variable git-svn-id: http://svn.openzap.org/svn/openzap/trunk@679 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 5550f9f4b7..2e7a00b1f7 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -413,7 +413,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (isdn_data) { struct pri_sr *sr; int dp; - const char *val; if (!(call = pri_new_call(isdn_data->spri.pri))) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); From 39f3539d635742e65120ad8305eed18e125a84da Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 4 Mar 2009 21:31:08 +0000 Subject: [PATCH 1315/1766] OPENZAP-54 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@680 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 210 +++++++++++++++++---- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h | 58 ++++++ 2 files changed, 227 insertions(+), 41 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 0648ab28b8..af688836aa 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -44,8 +44,122 @@ static struct { uint32_t etlevel; } zt_globals; +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; +}; + +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 +}; + +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 const char ctlpath[] = "/dev/zap/ctl"; +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); @@ -54,7 +168,6 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event); 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; - char path[] = "/dev/zap/channel"; zt_params_t ztp; memset(&ztp, 0, sizeof(ztp)); @@ -67,11 +180,11 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - sockfd = open(path, O_RDWR); + sockfd = open(chanpath, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { - if (ioctl(sockfd, ZT_SPECIFY, &x)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, sockfd, strerror(errno)); + 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; } @@ -83,8 +196,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za binfo.rxbufpolicy = 0; binfo.numbufs = 32; binfo.bufsize = 1024; - if (ioctl(sockfd, ZT_SET_BUFINFO, &binfo)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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; } @@ -134,8 +247,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za break; } - if (ioctl(CONTROL_FD, ZT_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", path, x, CONTROL_FD, strerror(errno)); + 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)); } } @@ -145,8 +258,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za cc.chan = cc.master = x; cc.sigtype = ZT_SIG_CAS; cc.idlebits = cas_bits; - if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s", path, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); + 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; } @@ -154,9 +267,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za if (zchan->type != ZAP_CHAN_TYPE_DQ921 && zchan->type != ZAP_CHAN_TYPE_DQ931) { len = zt_globals.codec_ms * 8; - if (ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + 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", - path, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); + chanpath, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } @@ -169,21 +282,21 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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; } } - zap_log(ZAP_LOG_INFO, "configuring device %s channel %d as OpenZAP device %d:%d fd:%d\n", path, x, zchan->span_id, zchan->chan_id, sockfd); + 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; @@ -212,8 +325,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; - if (ioctl(sockfd, ZT_SET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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; } @@ -227,7 +340,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } configured++; } else { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", path); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", chanpath); } } @@ -347,7 +460,7 @@ static ZIO_OPEN_FUNCTION(zt_open) } else { int blocksize = zt_globals.codec_ms * (zchan->rate / 1000); int err; - if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &blocksize))) { + if ((err = ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &blocksize))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } else { @@ -358,21 +471,21 @@ static ZIO_OPEN_FUNCTION(zt_open) if (zchan->type == ZAP_CHAN_TYPE_B) { int one = 1; - if (ioctl(zchan->sockfd, ZT_AUDIOMODE, &one)) { + 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; } } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_EM) { int len = zt_globals.eclevel; - if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { + 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); //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); //return ZAP_FAIL; } else { len = zt_globals.etlevel; - if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { + 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); //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); @@ -400,33 +513,33 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_ENABLE_ECHOCANCEL: { int level = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + err = ioctl(zchan->sockfd, codes.ECHOCANCEL, &level); ZAP_COMMAND_OBJ_INT = level; } case ZAP_COMMAND_DISABLE_ECHOCANCEL: { int level = 0; - err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + 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, ZT_ECHOTRAIN, &level); + err = ioctl(zchan->sockfd, codes.ECHOTRAIN, &level); ZAP_COMMAND_OBJ_INT = level; } case ZAP_COMMAND_DISABLE_ECHOTRAIN: { int level = 0; - err = ioctl(zchan->sockfd, ZT_ECHOTRAIN, &level); + 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, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); return ZAP_FAIL; } @@ -436,7 +549,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_ONHOOK: { int command = ZT_ONHOOK; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); return ZAP_FAIL; } @@ -446,7 +559,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_FLASH: { int command = ZT_FLASH; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "FLASH Failed"); return ZAP_FAIL; } @@ -455,7 +568,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_WINK: { int command = ZT_WINK; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "WINK Failed"); return ZAP_FAIL; } @@ -464,7 +577,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_GENERATE_RING_ON: { int command = ZT_RING; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; } @@ -474,7 +587,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_GENERATE_RING_OFF: { int command = ZT_RINGOFF; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off failed"); return ZAP_FAIL; } @@ -484,7 +597,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_GET_INTERVAL: { - if (!(err = ioctl(zchan->sockfd, ZT_GET_BLOCKSIZE, &zchan->packet_len))) { + 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; @@ -498,7 +611,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) int interval = ZAP_COMMAND_OBJ_INT; int len = interval * 8; - if (!(err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &len))) { + if (!(err = ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &len))) { zchan->packet_len = len; zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8; @@ -512,7 +625,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_SET_CAS_BITS: { int bits = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, ZT_SETTXBITS, &bits); + err = ioctl(zchan->sockfd, codes.SETTXBITS, &bits); } break; case ZAP_COMMAND_GET_CAS_BITS: @@ -541,7 +654,7 @@ static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms) memset(&info, 0, sizeof(info)); info.span_no = zchan->physical_span_id; - if (ioctl(CONTROL_FD, ZT_SPANSTAT, &info)) { + 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; @@ -658,7 +771,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) 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, ZT_GETEVENT, &zt_event_id) == -1) { + 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; } @@ -717,7 +830,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) { event_id = ZAP_OOB_CAS_BITS_CHANGE; int bits = 0; - int err = ioctl(span->channels[i]->sockfd, ZT_GETRXBITS, &bits); + int err = ioctl(span->channels[i]->sockfd, codes.GETRXBITS, &bits); if (err) { return ZAP_FAIL; } @@ -801,11 +914,26 @@ static zap_io_interface_t zt_interface; 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\n"); + zap_log(ZAP_LOG_ERROR, "Cannot open control device %s: %s\n", ctlpath, strerror(errno)); return ZAP_FAIL; } diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h index d965de4b93..38de3076e3 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h @@ -75,6 +75,8 @@ struct zt_params { 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; @@ -110,6 +112,18 @@ struct zt_spaninfo { 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 { @@ -245,6 +259,7 @@ ZT_ABIT = 8 /* ioctl defines */ #define ZT_CODE 'J' +#define DAHDI_CODE 0xDA #define ZT_GET_BLOCKSIZE _IOR (ZT_CODE, 1, int) /* Get Transfer Block Size. */ @@ -290,6 +305,49 @@ ZT_ABIT = 8 #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 From 7cde4042bad88a95893e1f5abc40dc11be85d4ea Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 4 Mar 2009 21:31:08 +0000 Subject: [PATCH 1316/1766] OPENZAP-54 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@680 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 210 +++++++++++++++++---- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h | 58 ++++++ 2 files changed, 227 insertions(+), 41 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 0648ab28b8..af688836aa 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -44,8 +44,122 @@ static struct { uint32_t etlevel; } zt_globals; +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; +}; + +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 +}; + +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 const char ctlpath[] = "/dev/zap/ctl"; +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); @@ -54,7 +168,6 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event); 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; - char path[] = "/dev/zap/channel"; zt_params_t ztp; memset(&ztp, 0, sizeof(ztp)); @@ -67,11 +180,11 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - sockfd = open(path, O_RDWR); + sockfd = open(chanpath, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { - if (ioctl(sockfd, ZT_SPECIFY, &x)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n", path, x, sockfd, strerror(errno)); + 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; } @@ -83,8 +196,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za binfo.rxbufpolicy = 0; binfo.numbufs = 32; binfo.bufsize = 1024; - if (ioctl(sockfd, ZT_SET_BUFINFO, &binfo)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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; } @@ -134,8 +247,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za break; } - if (ioctl(CONTROL_FD, ZT_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", path, x, CONTROL_FD, strerror(errno)); + 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)); } } @@ -145,8 +258,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za cc.chan = cc.master = x; cc.sigtype = ZT_SIG_CAS; cc.idlebits = cas_bits; - if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s", path, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); + 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; } @@ -154,9 +267,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za if (zchan->type != ZAP_CHAN_TYPE_DQ921 && zchan->type != ZAP_CHAN_TYPE_DQ931) { len = zt_globals.codec_ms * 8; - if (ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + 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", - path, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); + chanpath, zchan->span_id, zchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } @@ -169,21 +282,21 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } - if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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)) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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; } } - zap_log(ZAP_LOG_INFO, "configuring device %s channel %d as OpenZAP device %d:%d fd:%d\n", path, x, zchan->span_id, zchan->chan_id, sockfd); + 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; @@ -212,8 +325,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; - if (ioctl(sockfd, ZT_SET_PARAMS, &ztp) < 0) { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, zchan->span_id, zchan->chan_id, sockfd); + 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; } @@ -227,7 +340,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } configured++; } else { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", path); + zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", chanpath); } } @@ -347,7 +460,7 @@ static ZIO_OPEN_FUNCTION(zt_open) } else { int blocksize = zt_globals.codec_ms * (zchan->rate / 1000); int err; - if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &blocksize))) { + if ((err = ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &blocksize))) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } else { @@ -358,21 +471,21 @@ static ZIO_OPEN_FUNCTION(zt_open) if (zchan->type == ZAP_CHAN_TYPE_B) { int one = 1; - if (ioctl(zchan->sockfd, ZT_AUDIOMODE, &one)) { + 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; } } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_EM) { int len = zt_globals.eclevel; - if (ioctl(zchan->sockfd, ZT_ECHOCANCEL, &len)) { + 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); //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); //return ZAP_FAIL; } else { len = zt_globals.etlevel; - if (ioctl(zchan->sockfd, ZT_ECHOTRAIN, &len)) { + 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); //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); @@ -400,33 +513,33 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_ENABLE_ECHOCANCEL: { int level = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + err = ioctl(zchan->sockfd, codes.ECHOCANCEL, &level); ZAP_COMMAND_OBJ_INT = level; } case ZAP_COMMAND_DISABLE_ECHOCANCEL: { int level = 0; - err = ioctl(zchan->sockfd, ZT_ECHOCANCEL, &level); + 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, ZT_ECHOTRAIN, &level); + err = ioctl(zchan->sockfd, codes.ECHOTRAIN, &level); ZAP_COMMAND_OBJ_INT = level; } case ZAP_COMMAND_DISABLE_ECHOTRAIN: { int level = 0; - err = ioctl(zchan->sockfd, ZT_ECHOTRAIN, &level); + 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, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); return ZAP_FAIL; } @@ -436,7 +549,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_ONHOOK: { int command = ZT_ONHOOK; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); return ZAP_FAIL; } @@ -446,7 +559,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_FLASH: { int command = ZT_FLASH; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "FLASH Failed"); return ZAP_FAIL; } @@ -455,7 +568,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_WINK: { int command = ZT_WINK; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "WINK Failed"); return ZAP_FAIL; } @@ -464,7 +577,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_GENERATE_RING_ON: { int command = ZT_RING; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; } @@ -474,7 +587,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_GENERATE_RING_OFF: { int command = ZT_RINGOFF; - if (ioctl(zchan->sockfd, ZT_HOOK, &command)) { + if (ioctl(zchan->sockfd, codes.HOOK, &command)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off failed"); return ZAP_FAIL; } @@ -484,7 +597,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_GET_INTERVAL: { - if (!(err = ioctl(zchan->sockfd, ZT_GET_BLOCKSIZE, &zchan->packet_len))) { + 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; @@ -498,7 +611,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) int interval = ZAP_COMMAND_OBJ_INT; int len = interval * 8; - if (!(err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &len))) { + if (!(err = ioctl(zchan->sockfd, codes.SET_BLOCKSIZE, &len))) { zchan->packet_len = len; zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8; @@ -512,7 +625,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) case ZAP_COMMAND_SET_CAS_BITS: { int bits = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, ZT_SETTXBITS, &bits); + err = ioctl(zchan->sockfd, codes.SETTXBITS, &bits); } break; case ZAP_COMMAND_GET_CAS_BITS: @@ -541,7 +654,7 @@ static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms) memset(&info, 0, sizeof(info)); info.span_no = zchan->physical_span_id; - if (ioctl(CONTROL_FD, ZT_SPANSTAT, &info)) { + 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; @@ -658,7 +771,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) 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, ZT_GETEVENT, &zt_event_id) == -1) { + 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; } @@ -717,7 +830,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) { event_id = ZAP_OOB_CAS_BITS_CHANGE; int bits = 0; - int err = ioctl(span->channels[i]->sockfd, ZT_GETRXBITS, &bits); + int err = ioctl(span->channels[i]->sockfd, codes.GETRXBITS, &bits); if (err) { return ZAP_FAIL; } @@ -801,11 +914,26 @@ static zap_io_interface_t zt_interface; 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\n"); + zap_log(ZAP_LOG_ERROR, "Cannot open control device %s: %s\n", ctlpath, strerror(errno)); return ZAP_FAIL; } diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h index d965de4b93..38de3076e3 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h @@ -75,6 +75,8 @@ struct zt_params { 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; @@ -110,6 +112,18 @@ struct zt_spaninfo { 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 { @@ -245,6 +259,7 @@ ZT_ABIT = 8 /* ioctl defines */ #define ZT_CODE 'J' +#define DAHDI_CODE 0xDA #define ZT_GET_BLOCKSIZE _IOR (ZT_CODE, 1, int) /* Get Transfer Block Size. */ @@ -290,6 +305,49 @@ ZT_ABIT = 8 #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 From 7d8ea02776f91db79aed2cb942211ca81c885fb7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Mar 2009 18:17:15 +0000 Subject: [PATCH 1317/1766] build: get base of windows build for openzap going again (OPENZAP-55) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@682 a93c3328-9c30-0410-af19-c9cd2b2d52af --- ...openzap.vcproj => mod_openzap.2005.vcproj} | 10 +- .../mod_openzap/mod_openzap.2008.vcproj | 200 +++++++ libs/openzap/mod_openzap/mod_openzap.c | 8 +- libs/openzap/msvc/openzap.2005.vcproj | 283 +++++++++ libs/openzap/msvc/openzap.2008.vcproj | 284 +++++++++ libs/openzap/msvc/openzap.vcproj | 557 ------------------ ...stanalog.vcproj => testanalog.2005.vcproj} | 0 .../msvc/testanalog/testanalog.2008.vcproj | 190 ++++++ .../{testisdn.vcproj => testisdn.2005.vcproj} | 0 .../msvc/testisdn/testisdn.2008.vcproj | 190 ++++++ .../openzap/{openzap.sln => openzap.2005.sln} | 14 +- libs/openzap/openzap.2008.sln | 47 ++ libs/openzap/src/hashtable.c | 6 +- libs/openzap/src/include/hashtable_private.h | 2 +- libs/openzap/src/include/openzap.h | 4 + libs/openzap/src/isdn/Q921.c | 15 +- libs/openzap/src/zap_buffer.c | 2 +- libs/openzap/src/zap_callerid.c | 2 +- libs/openzap/src/zap_config.c | 2 +- libs/openzap/src/zap_dso.c | 45 ++ libs/openzap/src/zap_io.c | 55 +- 21 files changed, 1317 insertions(+), 599 deletions(-) rename libs/openzap/mod_openzap/{mod_openzap.vcproj => mod_openzap.2005.vcproj} (89%) create mode 100644 libs/openzap/mod_openzap/mod_openzap.2008.vcproj create mode 100644 libs/openzap/msvc/openzap.2005.vcproj create mode 100644 libs/openzap/msvc/openzap.2008.vcproj delete mode 100644 libs/openzap/msvc/openzap.vcproj rename libs/openzap/msvc/testanalog/{testanalog.vcproj => testanalog.2005.vcproj} (100%) create mode 100644 libs/openzap/msvc/testanalog/testanalog.2008.vcproj rename libs/openzap/msvc/testisdn/{testisdn.vcproj => testisdn.2005.vcproj} (100%) create mode 100644 libs/openzap/msvc/testisdn/testisdn.2008.vcproj rename libs/openzap/{openzap.sln => openzap.2005.sln} (79%) create mode 100644 libs/openzap/openzap.2008.sln diff --git a/libs/openzap/mod_openzap/mod_openzap.vcproj b/libs/openzap/mod_openzap/mod_openzap.2005.vcproj similarity index 89% rename from libs/openzap/mod_openzap/mod_openzap.vcproj rename to libs/openzap/mod_openzap/mod_openzap.2005.vcproj index a1ebe71e9a..800fea482c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.vcproj +++ b/libs/openzap/mod_openzap/mod_openzap.2005.vcproj @@ -41,7 +41,7 @@ - @@ -174,9 +171,6 @@ - diff --git a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj new file mode 100644 index 0000000000..68be586a01 --- /dev/null +++ b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 590c22112a..f8a987449f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -617,7 +617,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } *frame = &tech_pvt->read_frame; - tech_pvt->read_frame.datalen = len; + tech_pvt->read_frame.datalen = (uint32_t)len; tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { @@ -2185,7 +2185,7 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR Usage: oz dump []\n"); goto end; } else { - int32_t span_id, chan_id = 0; + uint32_t span_id, chan_id = 0; zap_span_t *span; span_id = atoi(argv[1]); @@ -2204,7 +2204,7 @@ SWITCH_STANDARD_API(oz_function) dump_chan(span, chan_id, stream); } } else { - int j; + uint32_t j; stream->write_function(stream, "+OK\n"); for (j = 1; j <= span->chan_count; j++) { @@ -2271,7 +2271,7 @@ SWITCH_STANDARD_API(oz_function) if (chan_id) { zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); } else { - int j; + uint32_t j; stream->write_function(stream, "+OK\n"); for (j = 1; j <= span->chan_count; j++) { diff --git a/libs/openzap/msvc/openzap.2005.vcproj b/libs/openzap/msvc/openzap.2005.vcproj new file mode 100644 index 0000000000..d02a4ada41 --- /dev/null +++ b/libs/openzap/msvc/openzap.2005.vcproj @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/openzap.2008.vcproj b/libs/openzap/msvc/openzap.2008.vcproj new file mode 100644 index 0000000000..a0d6c2b4b6 --- /dev/null +++ b/libs/openzap/msvc/openzap.2008.vcproj @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/openzap.vcproj b/libs/openzap/msvc/openzap.vcproj deleted file mode 100644 index c3af23614f..0000000000 --- a/libs/openzap/msvc/openzap.vcproj +++ /dev/null @@ -1,557 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libs/openzap/msvc/testanalog/testanalog.vcproj b/libs/openzap/msvc/testanalog/testanalog.2005.vcproj similarity index 100% rename from libs/openzap/msvc/testanalog/testanalog.vcproj rename to libs/openzap/msvc/testanalog/testanalog.2005.vcproj diff --git a/libs/openzap/msvc/testanalog/testanalog.2008.vcproj b/libs/openzap/msvc/testanalog/testanalog.2008.vcproj new file mode 100644 index 0000000000..7400debad0 --- /dev/null +++ b/libs/openzap/msvc/testanalog/testanalog.2008.vcproj @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/testisdn/testisdn.vcproj b/libs/openzap/msvc/testisdn/testisdn.2005.vcproj similarity index 100% rename from libs/openzap/msvc/testisdn/testisdn.vcproj rename to libs/openzap/msvc/testisdn/testisdn.2005.vcproj diff --git a/libs/openzap/msvc/testisdn/testisdn.2008.vcproj b/libs/openzap/msvc/testisdn/testisdn.2008.vcproj new file mode 100644 index 0000000000..32893d6ac7 --- /dev/null +++ b/libs/openzap/msvc/testisdn/testisdn.2008.vcproj @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/openzap.sln b/libs/openzap/openzap.2005.sln similarity index 79% rename from libs/openzap/openzap.sln rename to libs/openzap/openzap.2005.sln index 2e05fb4136..5c34eb2878 100644 --- a/libs/openzap/openzap.sln +++ b/libs/openzap/openzap.2005.sln @@ -1,25 +1,19 @@  Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.2005.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unix Makefiles", "Unix Makefiles", "{214C60D6-6E30-4912-B919-DB76A20CC682}" - ProjectSection(SolutionItems) = preProject - general.makefile = general.makefile - Makefile = Makefile - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.2005.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.2005.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.2005.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection diff --git a/libs/openzap/openzap.2008.sln b/libs/openzap/openzap.2008.sln new file mode 100644 index 0000000000..aaeda35ecb --- /dev/null +++ b/libs/openzap/openzap.2008.sln @@ -0,0 +1,47 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.2008.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.2008.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.2008.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.2008.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.ActiveCfg = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.Build.0 = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.ActiveCfg = Release|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.Build.0 = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.ActiveCfg = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.Build.0 = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.ActiveCfg = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.Build.0 = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.ActiveCfg = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.ActiveCfg = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index d9e0a30a9f..e1deb8912f 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -268,7 +268,7 @@ struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) { if (i->e) { - if ((i->e = i->e->next)) { + if ((i->e = i->e->next) != 0) { return i; } else { i->pos++; @@ -283,7 +283,7 @@ struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) return NULL; } - if ((i->e = i->h->table[i->pos])) { + if ((i->e = i->h->table[i->pos]) != 0) { return i; } @@ -307,7 +307,7 @@ void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, v *key = i->e->k; } if (klen) { - *klen = strlen(i->e->k); + *klen = (int)strlen(i->e->k); } if (val) { *val = i->e->v; diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index 0a20c214fd..0f329ca3a6 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -17,7 +17,7 @@ struct entry }; struct hashtable_iterator { - int pos; + unsigned int pos; struct entry *e; struct hashtable *h; }; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index e35daf1543..399518ba27 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -239,6 +239,10 @@ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } +#ifdef _MSC_VER +/* The while(0) below throws a conditional expression is constant warning */ +#pragma warning(disable:4127) +#endif #define zap_set_state_locked_wait(obj, s) \ do { \ int __safety = 100; \ diff --git a/libs/openzap/src/isdn/Q921.c b/libs/openzap/src/isdn/Q921.c index 7667203227..0496e09f5c 100644 --- a/libs/openzap/src/isdn/Q921.c +++ b/libs/openzap/src/isdn/Q921.c @@ -83,6 +83,9 @@ #include "Q921priv.h" #include "mfifo.h" +#ifdef WIN32 +#pragma warning(disable:4100 4244) +#endif /****************************************************************************************************** * Actual code below this line @@ -650,7 +653,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 if(tei != link->tei) { APPEND_MSG(pbuf, poffset, pleft, " CONTENT:\n"); - len = print_hex(pbuf + poffset, pleft, &pmes[4], size - (trunk->Q921HeaderSpace + 4)); + len = print_hex(pbuf + poffset, (int)pleft, &pmes[4], size - (trunk->Q921HeaderSpace + 4)); poffset += len; pleft -= len; } @@ -775,7 +778,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 else { APPEND_MSG(pbuf, poffset, pleft, " ENT ID: %d (%s), MESSAGE CONTENT:\n", pmes[3], type); - len = print_hex(pbuf + poffset, pleft, &pmes[3], size - (trunk->Q921HeaderSpace + 3)); + len = print_hex(pbuf + poffset, (int)pleft, &pmes[3], size - (trunk->Q921HeaderSpace + 3)); poffset += len; pleft -= len; } @@ -822,7 +825,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 out: buf[sizeof(buf) - 1] = '\0'; - return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, strlen(buf)); + return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, (int)strlen(buf)); } /***************************************************************************** @@ -3108,7 +3111,11 @@ static int Q921TeiSendAssignRequest(L2TRUNK trunk) if (!Q921_IS_PTMP_TE(trunk)) /* only ptmp te mode*/ return 0; - link->ri = (L2USHORT)(random() % 0xffff); +#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); diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 1051f716cc..777151d8b9 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -164,7 +164,7 @@ zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t dat } buffer->head = buffer->data; buffer->used = buffer->actually_used; - len = zap_buffer_read(buffer, data + len, datalen - len); + len = zap_buffer_read(buffer, (char*)data + len, datalen - len); buffer->loops--; } return len; diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 97c0f87223..967b80a40c 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -83,7 +83,7 @@ zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) check = check + state->buf[i]; } - state->checksum = state->buf[state->bpos] = 256 - check; + state->checksum = state->buf[state->bpos] = (uint8_t)(256 - check); state->bpos++; state->dlen = state->bpos; diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index b1f6bd90c4..ab622dd7d3 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -213,6 +213,7 @@ 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", double_colon); @@ -226,7 +227,6 @@ int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) return -1; } zap_log(ZAP_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits); - int x = 0; for (; cas_bits[x]; x++) { if ('1' == cas_bits[x]) { *outbits |= bit; diff --git a/libs/openzap/src/zap_dso.c b/libs/openzap/src/zap_dso.c index 07c25f29fd..ead40e7c4b 100644 --- a/libs/openzap/src/zap_dso.c +++ b/libs/openzap/src/zap_dso.c @@ -21,6 +21,50 @@ #include #include +#ifdef WIN32 +#include +#include + + +void zap_dso_destroy(zap_dso_lib_t *lib) { + if (lib && *lib) { + FreeLibrary(*lib); + *lib = NULL; + } +} + +zap_dso_lib_t zap_dso_open(const char *path, char **err) { + HINSTANCE lib; + + lib = LoadLibraryEx(path, NULL, 0); + + if (!lib) { + LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + } + + if (!lib) { + DWORD error = GetLastError(); + char tmp[80]; + sprintf(tmp, "dll open error [%ul]\n", error); + *err = _strdup(tmp); + } + + return lib; +} + +void* zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { + FARPROC func = GetProcAddress(lib, sym); + if (!func) { + DWORD error = GetLastError(); + char tmp[80]; + sprintf(tmp, "dll sym error [%ul]\n", error); + *err = _strdup(tmp); + } + return (void *)(intptr_t)func; // this should really be addr - zap_dso_func_data +} + +#else + /* ** {======================================================================== ** This is an implementation of loadlib based on the dlfcn interface. @@ -55,6 +99,7 @@ void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { } return func; } +#endif /* }====================================================== */ diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 0f6bf94bf5..88d800a47f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1707,7 +1707,7 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) { zap_buffer_t *buffer = NULL; - zap_size_t dblen; + zap_size_t dblen = 0; if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { char digits[128] = ""; @@ -2362,6 +2362,7 @@ int zap_load_module(const char *name) #ifdef WIN32 const char *ext = ".dll"; //const char *EXT = ".DLL"; +#define ZAP_MOD_DIR "." //todo #elif defined (MACOSX) || defined (DARWIN) const char *ext = ".dylib"; //const char *EXT = ".DYLIB"; @@ -2389,18 +2390,18 @@ int zap_load_module(const char *name) } if (mod->io_load) { - zap_io_interface_t *interface = NULL; + zap_io_interface_t *interface1 = NULL; /* name conflict w/windows here */ - if (mod->io_load(&interface) != ZAP_SUCCESS || !interface || !interface->name) { + if (mod->io_load(&interface1) != ZAP_SUCCESS || !interface1 || !interface1->name) { zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface->name); + zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface1->name); zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.interface_hash, (void *)interface->name)) { - zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); + if (hashtable_search(globals.interface_hash, (void *)interface1->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface1->name); } else { - hashtable_insert(globals.interface_hash, (void *)interface->name, interface, HASHTABLE_FLAG_NONE); - process_module_config(interface); + hashtable_insert(globals.interface_hash, (void *)interface1->name, interface1, HASHTABLE_FLAG_NONE); + process_module_config(interface1); x++; } zap_mutex_unlock(globals.mutex); @@ -2844,6 +2845,42 @@ zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t * return ZAP_SUCCESS; } +int zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ +{ +#ifdef HAVE_VASPRINTF + return vasprintf(ret, fmt, ap); +#else + char *buf; + int len; + size_t buflen; + va_list ap2; + char *tmp = NULL; + +#ifdef _MSC_VER +#if _MSC_VER >= 1500 + /* hack for incorrect assumption in msvc header files for code analysis */ + __analysis_assume(tmp); +#endif + ap2 = ap; +#else + va_copy(ap2, ap); +#endif + + len = vsnprintf(tmp, 0, fmt, ap2); + + if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) { + len = vsnprintf(buf, buflen, fmt, ap); + *ret = buf; + } else { + *ret = NULL; + len = -1; + } + + va_end(ap2); + return len; +#endif +} + zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) { va_list ap; @@ -2857,7 +2894,7 @@ zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *f } va_start(ap, fmt); - ret = vasprintf(&data, fmt, ap); + ret = zap_vasprintf(&data, fmt, ap); va_end(ap); if (data) { From ea72f97b966f77725c6c345162c5b7599d1dd0d6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Mar 2009 18:17:15 +0000 Subject: [PATCH 1318/1766] build: get base of windows build for openzap going again (OPENZAP-55) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@682 a93c3328-9c30-0410-af19-c9cd2b2d52af --- ...openzap.vcproj => mod_openzap.2005.vcproj} | 10 +- .../mod_openzap/mod_openzap.2008.vcproj | 200 +++++++ libs/freetdm/mod_openzap/mod_openzap.c | 8 +- libs/freetdm/msvc/openzap.2005.vcproj | 283 +++++++++ libs/freetdm/msvc/openzap.2008.vcproj | 284 +++++++++ libs/freetdm/msvc/openzap.vcproj | 557 ------------------ ...stanalog.vcproj => testanalog.2005.vcproj} | 0 .../msvc/testanalog/testanalog.2008.vcproj | 190 ++++++ .../{testisdn.vcproj => testisdn.2005.vcproj} | 0 .../msvc/testisdn/testisdn.2008.vcproj | 190 ++++++ .../freetdm/{openzap.sln => openzap.2005.sln} | 14 +- libs/freetdm/openzap.2008.sln | 47 ++ libs/freetdm/src/hashtable.c | 6 +- libs/freetdm/src/include/hashtable_private.h | 2 +- libs/freetdm/src/include/openzap.h | 4 + libs/freetdm/src/isdn/Q921.c | 15 +- libs/freetdm/src/zap_buffer.c | 2 +- libs/freetdm/src/zap_callerid.c | 2 +- libs/freetdm/src/zap_config.c | 2 +- libs/freetdm/src/zap_dso.c | 45 ++ libs/freetdm/src/zap_io.c | 55 +- 21 files changed, 1317 insertions(+), 599 deletions(-) rename libs/freetdm/mod_openzap/{mod_openzap.vcproj => mod_openzap.2005.vcproj} (89%) create mode 100644 libs/freetdm/mod_openzap/mod_openzap.2008.vcproj create mode 100644 libs/freetdm/msvc/openzap.2005.vcproj create mode 100644 libs/freetdm/msvc/openzap.2008.vcproj delete mode 100644 libs/freetdm/msvc/openzap.vcproj rename libs/freetdm/msvc/testanalog/{testanalog.vcproj => testanalog.2005.vcproj} (100%) create mode 100644 libs/freetdm/msvc/testanalog/testanalog.2008.vcproj rename libs/freetdm/msvc/testisdn/{testisdn.vcproj => testisdn.2005.vcproj} (100%) create mode 100644 libs/freetdm/msvc/testisdn/testisdn.2008.vcproj rename libs/freetdm/{openzap.sln => openzap.2005.sln} (79%) create mode 100644 libs/freetdm/openzap.2008.sln diff --git a/libs/freetdm/mod_openzap/mod_openzap.vcproj b/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj similarity index 89% rename from libs/freetdm/mod_openzap/mod_openzap.vcproj rename to libs/freetdm/mod_openzap/mod_openzap.2005.vcproj index a1ebe71e9a..800fea482c 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.vcproj +++ b/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj @@ -41,7 +41,7 @@ - @@ -174,9 +171,6 @@ - diff --git a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj new file mode 100644 index 0000000000..68be586a01 --- /dev/null +++ b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 590c22112a..f8a987449f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -617,7 +617,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } *frame = &tech_pvt->read_frame; - tech_pvt->read_frame.datalen = len; + tech_pvt->read_frame.datalen = (uint32_t)len; tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { @@ -2185,7 +2185,7 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR Usage: oz dump []\n"); goto end; } else { - int32_t span_id, chan_id = 0; + uint32_t span_id, chan_id = 0; zap_span_t *span; span_id = atoi(argv[1]); @@ -2204,7 +2204,7 @@ SWITCH_STANDARD_API(oz_function) dump_chan(span, chan_id, stream); } } else { - int j; + uint32_t j; stream->write_function(stream, "+OK\n"); for (j = 1; j <= span->chan_count; j++) { @@ -2271,7 +2271,7 @@ SWITCH_STANDARD_API(oz_function) if (chan_id) { zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); } else { - int j; + uint32_t j; stream->write_function(stream, "+OK\n"); for (j = 1; j <= span->chan_count; j++) { diff --git a/libs/freetdm/msvc/openzap.2005.vcproj b/libs/freetdm/msvc/openzap.2005.vcproj new file mode 100644 index 0000000000..d02a4ada41 --- /dev/null +++ b/libs/freetdm/msvc/openzap.2005.vcproj @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/openzap.2008.vcproj b/libs/freetdm/msvc/openzap.2008.vcproj new file mode 100644 index 0000000000..a0d6c2b4b6 --- /dev/null +++ b/libs/freetdm/msvc/openzap.2008.vcproj @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/openzap.vcproj b/libs/freetdm/msvc/openzap.vcproj deleted file mode 100644 index c3af23614f..0000000000 --- a/libs/freetdm/msvc/openzap.vcproj +++ /dev/null @@ -1,557 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libs/freetdm/msvc/testanalog/testanalog.vcproj b/libs/freetdm/msvc/testanalog/testanalog.2005.vcproj similarity index 100% rename from libs/freetdm/msvc/testanalog/testanalog.vcproj rename to libs/freetdm/msvc/testanalog/testanalog.2005.vcproj diff --git a/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj b/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj new file mode 100644 index 0000000000..7400debad0 --- /dev/null +++ b/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testisdn/testisdn.vcproj b/libs/freetdm/msvc/testisdn/testisdn.2005.vcproj similarity index 100% rename from libs/freetdm/msvc/testisdn/testisdn.vcproj rename to libs/freetdm/msvc/testisdn/testisdn.2005.vcproj diff --git a/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj b/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj new file mode 100644 index 0000000000..32893d6ac7 --- /dev/null +++ b/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/openzap.sln b/libs/freetdm/openzap.2005.sln similarity index 79% rename from libs/freetdm/openzap.sln rename to libs/freetdm/openzap.2005.sln index 2e05fb4136..5c34eb2878 100644 --- a/libs/freetdm/openzap.sln +++ b/libs/freetdm/openzap.2005.sln @@ -1,25 +1,19 @@  Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.2005.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unix Makefiles", "Unix Makefiles", "{214C60D6-6E30-4912-B919-DB76A20CC682}" - ProjectSection(SolutionItems) = preProject - general.makefile = general.makefile - Makefile = Makefile - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.2005.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.2005.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.2005.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection diff --git a/libs/freetdm/openzap.2008.sln b/libs/freetdm/openzap.2008.sln new file mode 100644 index 0000000000..aaeda35ecb --- /dev/null +++ b/libs/freetdm/openzap.2008.sln @@ -0,0 +1,47 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.2008.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.2008.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\testisdn.2008.vcproj", "{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.2008.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.ActiveCfg = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.Build.0 = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.ActiveCfg = Release|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.Build.0 = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.ActiveCfg = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.Build.0 = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.ActiveCfg = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.Build.0 = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.ActiveCfg = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.ActiveCfg = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index d9e0a30a9f..e1deb8912f 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -268,7 +268,7 @@ struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) { if (i->e) { - if ((i->e = i->e->next)) { + if ((i->e = i->e->next) != 0) { return i; } else { i->pos++; @@ -283,7 +283,7 @@ struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) return NULL; } - if ((i->e = i->h->table[i->pos])) { + if ((i->e = i->h->table[i->pos]) != 0) { return i; } @@ -307,7 +307,7 @@ void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, v *key = i->e->k; } if (klen) { - *klen = strlen(i->e->k); + *klen = (int)strlen(i->e->k); } if (val) { *val = i->e->v; diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index 0a20c214fd..0f329ca3a6 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -17,7 +17,7 @@ struct entry }; struct hashtable_iterator { - int pos; + unsigned int pos; struct entry *e; struct hashtable *h; }; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index e35daf1543..399518ba27 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -239,6 +239,10 @@ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } +#ifdef _MSC_VER +/* The while(0) below throws a conditional expression is constant warning */ +#pragma warning(disable:4127) +#endif #define zap_set_state_locked_wait(obj, s) \ do { \ int __safety = 100; \ diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 7667203227..0496e09f5c 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -83,6 +83,9 @@ #include "Q921priv.h" #include "mfifo.h" +#ifdef WIN32 +#pragma warning(disable:4100 4244) +#endif /****************************************************************************************************** * Actual code below this line @@ -650,7 +653,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 if(tei != link->tei) { APPEND_MSG(pbuf, poffset, pleft, " CONTENT:\n"); - len = print_hex(pbuf + poffset, pleft, &pmes[4], size - (trunk->Q921HeaderSpace + 4)); + len = print_hex(pbuf + poffset, (int)pleft, &pmes[4], size - (trunk->Q921HeaderSpace + 4)); poffset += len; pleft -= len; } @@ -775,7 +778,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 else { APPEND_MSG(pbuf, poffset, pleft, " ENT ID: %d (%s), MESSAGE CONTENT:\n", pmes[3], type); - len = print_hex(pbuf + poffset, pleft, &pmes[3], size - (trunk->Q921HeaderSpace + 3)); + len = print_hex(pbuf + poffset, (int)pleft, &pmes[3], size - (trunk->Q921HeaderSpace + 3)); poffset += len; pleft -= len; } @@ -822,7 +825,7 @@ static int Q921LogMesg(L2TRUNK trunk, Q921LogLevel_t level, L2UCHAR received, L2 out: buf[sizeof(buf) - 1] = '\0'; - return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, strlen(buf)); + return trunk->Q921LogProc(trunk->PrivateDataLog, level, buf, (int)strlen(buf)); } /***************************************************************************** @@ -3108,7 +3111,11 @@ static int Q921TeiSendAssignRequest(L2TRUNK trunk) if (!Q921_IS_PTMP_TE(trunk)) /* only ptmp te mode*/ return 0; - link->ri = (L2USHORT)(random() % 0xffff); +#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); diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 1051f716cc..777151d8b9 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -164,7 +164,7 @@ zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t dat } buffer->head = buffer->data; buffer->used = buffer->actually_used; - len = zap_buffer_read(buffer, data + len, datalen - len); + len = zap_buffer_read(buffer, (char*)data + len, datalen - len); buffer->loops--; } return len; diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 97c0f87223..967b80a40c 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -83,7 +83,7 @@ zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) check = check + state->buf[i]; } - state->checksum = state->buf[state->bpos] = 256 - check; + state->checksum = state->buf[state->bpos] = (uint8_t)(256 - check); state->bpos++; state->dlen = state->bpos; diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index b1f6bd90c4..ab622dd7d3 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -213,6 +213,7 @@ 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", double_colon); @@ -226,7 +227,6 @@ int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) return -1; } zap_log(ZAP_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits); - int x = 0; for (; cas_bits[x]; x++) { if ('1' == cas_bits[x]) { *outbits |= bit; diff --git a/libs/freetdm/src/zap_dso.c b/libs/freetdm/src/zap_dso.c index 07c25f29fd..ead40e7c4b 100644 --- a/libs/freetdm/src/zap_dso.c +++ b/libs/freetdm/src/zap_dso.c @@ -21,6 +21,50 @@ #include #include +#ifdef WIN32 +#include +#include + + +void zap_dso_destroy(zap_dso_lib_t *lib) { + if (lib && *lib) { + FreeLibrary(*lib); + *lib = NULL; + } +} + +zap_dso_lib_t zap_dso_open(const char *path, char **err) { + HINSTANCE lib; + + lib = LoadLibraryEx(path, NULL, 0); + + if (!lib) { + LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + } + + if (!lib) { + DWORD error = GetLastError(); + char tmp[80]; + sprintf(tmp, "dll open error [%ul]\n", error); + *err = _strdup(tmp); + } + + return lib; +} + +void* zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { + FARPROC func = GetProcAddress(lib, sym); + if (!func) { + DWORD error = GetLastError(); + char tmp[80]; + sprintf(tmp, "dll sym error [%ul]\n", error); + *err = _strdup(tmp); + } + return (void *)(intptr_t)func; // this should really be addr - zap_dso_func_data +} + +#else + /* ** {======================================================================== ** This is an implementation of loadlib based on the dlfcn interface. @@ -55,6 +99,7 @@ void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { } return func; } +#endif /* }====================================================== */ diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 0f6bf94bf5..88d800a47f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1707,7 +1707,7 @@ zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) { zap_buffer_t *buffer = NULL; - zap_size_t dblen; + zap_size_t dblen = 0; if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { char digits[128] = ""; @@ -2362,6 +2362,7 @@ int zap_load_module(const char *name) #ifdef WIN32 const char *ext = ".dll"; //const char *EXT = ".DLL"; +#define ZAP_MOD_DIR "." //todo #elif defined (MACOSX) || defined (DARWIN) const char *ext = ".dylib"; //const char *EXT = ".DYLIB"; @@ -2389,18 +2390,18 @@ int zap_load_module(const char *name) } if (mod->io_load) { - zap_io_interface_t *interface = NULL; + zap_io_interface_t *interface1 = NULL; /* name conflict w/windows here */ - if (mod->io_load(&interface) != ZAP_SUCCESS || !interface || !interface->name) { + if (mod->io_load(&interface1) != ZAP_SUCCESS || !interface1 || !interface1->name) { zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface->name); + zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface1->name); zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.interface_hash, (void *)interface->name)) { - zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name); + if (hashtable_search(globals.interface_hash, (void *)interface1->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface1->name); } else { - hashtable_insert(globals.interface_hash, (void *)interface->name, interface, HASHTABLE_FLAG_NONE); - process_module_config(interface); + hashtable_insert(globals.interface_hash, (void *)interface1->name, interface1, HASHTABLE_FLAG_NONE); + process_module_config(interface1); x++; } zap_mutex_unlock(globals.mutex); @@ -2844,6 +2845,42 @@ zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t * return ZAP_SUCCESS; } +int zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ +{ +#ifdef HAVE_VASPRINTF + return vasprintf(ret, fmt, ap); +#else + char *buf; + int len; + size_t buflen; + va_list ap2; + char *tmp = NULL; + +#ifdef _MSC_VER +#if _MSC_VER >= 1500 + /* hack for incorrect assumption in msvc header files for code analysis */ + __analysis_assume(tmp); +#endif + ap2 = ap; +#else + va_copy(ap2, ap); +#endif + + len = vsnprintf(tmp, 0, fmt, ap2); + + if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) { + len = vsnprintf(buf, buflen, fmt, ap); + *ret = buf; + } else { + *ret = NULL; + len = -1; + } + + va_end(ap2); + return len; +#endif +} + zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) { va_list ap; @@ -2857,7 +2894,7 @@ zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *f } va_start(ap, fmt); - ret = vasprintf(&data, fmt, ap); + ret = zap_vasprintf(&data, fmt, ap); va_end(ap); if (data) { From 37ec6300f7b12ed1119a4590125c7bc50244b7a7 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Mar 2009 22:15:53 +0000 Subject: [PATCH 1319/1766] add decl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@683 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 399518ba27..81e7124dfb 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -630,6 +630,7 @@ int zap_load_module(const char *name); int zap_load_module_assume(const char *name); zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); char *zap_api_execute(const char *type, const char *cmd); +int zap_vasprintf(char **ret, const char *fmt, va_list ap); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); From 845235dee9991e1e19406f6bf8b9df9f85935b43 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 6 Mar 2009 22:15:53 +0000 Subject: [PATCH 1320/1766] add decl git-svn-id: http://svn.openzap.org/svn/openzap/trunk@683 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 399518ba27..81e7124dfb 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -630,6 +630,7 @@ int zap_load_module(const char *name); int zap_load_module_assume(const char *name); zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); char *zap_api_execute(const char *type, const char *cmd); +int zap_vasprintf(char **ret, const char *fmt, va_list ap); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); From feda211d90bf7f714621106884529b10041b57bd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 7 Mar 2009 02:20:40 +0000 Subject: [PATCH 1321/1766] performance tuning git-svn-id: http://svn.openzap.org/svn/openzap/trunk@684 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 38 ++++--- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 3 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 100 ++++++++++++------ libs/openzap/src/zap_io.c | 2 + 5 files changed, 99 insertions(+), 45 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 81e7124dfb..9397766bf5 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -87,6 +87,7 @@ #pragma comment(lib, "Winmm") #endif +#define ZAP_THREAD_STACKSIZE 240 * 1024 #define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; #define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); #define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index 3b227c3c9b..1220a93a77 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -97,7 +97,8 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = { {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"} + {18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"}, + {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"} }; #define LINE "--------------------------------------------------------------------------------" @@ -114,8 +115,9 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) int res; if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) { - printf("D-READ FAIL! [%s]\n", spri->zdchan->last_error); - return 0; + zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + zap_clear_flag(spri, LPWRAP_PRI_READY); + return -1; } res = (int)len; memset(&((unsigned char*)buf)[res],0,2); @@ -133,8 +135,9 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) zap_size_t len = buflen -2; if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) { - printf("D-WRITE FAIL! [%s]\n", spri->zdchan->last_error); - return 0; + zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + zap_clear_flag(spri, LPWRAP_PRI_READY); + return -1; } //print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0); @@ -155,6 +158,7 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int spri->span = span; pri_set_debug(spri->pri, debug); ret = 0; + zap_set_flag(spri, LPWRAP_PRI_READY); } else { fprintf(stderr, "Unable to create PRI\n"); } @@ -168,6 +172,7 @@ 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) { @@ -210,7 +215,6 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } 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); @@ -219,16 +223,25 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - return sel; + if (zap_test_flag(spri, LPWRAP_PRI_READY)) { + 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){ + ret = lpwrap_one_loop(spri); + + if (ret < 0) { #ifndef WIN32 //This needs to be adressed fror WIN32 still if (errno == EINTR){ @@ -236,9 +249,8 @@ int lpwrap_run_pri(struct lpwrap_pri *spri) continue; } #endif - printf("Error = %i\n",ret); - perror("Lpwrap Run Pri: "); - break; + zap_log(ZAP_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno)); + break; } } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h index 9333e3a049..8ed6ab016f 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -58,7 +58,8 @@ typedef enum { 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_KEYPAD_DIGIT = PRI_EVENT_KEYPAD_DIGIT, + LPWRAP_PRI_EVENT_IO_FAIL = 19 } lpwrap_pri_event_t; typedef enum { diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 2e7a00b1f7..a3f4a6a205 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -704,28 +704,70 @@ static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev +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, event_type, lpwrap_pri_event_str(event_type)); + return 0; +} + + + 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; - - 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); - - isdn_data->spri.on_loop = check_flags; - isdn_data->spri.private_info = span; + int x, i; - lpwrap_run_pri(&isdn_data->spri); + while(zap_running()) { + x = 0; + + 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; + x++; + break; + } + } + } + + + if (x && lpwrap_init_pri(&isdn_data->spri, + span->span_id, // 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); + + + isdn_data->spri.on_loop = check_flags; + isdn_data->spri.private_info = span; + + lpwrap_run_pri(&isdn_data->spri); + zap_channel_close(&isdn_data->dchan); + } + + zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span); + zap_sleep(5000); + } return NULL; @@ -736,9 +778,10 @@ static zap_status_t zap_libpri_start(zap_span_t *span) zap_status_t ret; zap_libpri_data_t *isdn_data = span->signal_data; - zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING); + zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING); ret = zap_thread_create_detached(zap_libpri_run, span); + if (ret != ZAP_SUCCESS) { return ret; } @@ -806,7 +849,7 @@ static int str2dp(char *dp) static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) { uint32_t i, x = 0; - zap_channel_t *dchans[2] = {0}; + //zap_channel_t *dchans[2] = {0}; zap_libpri_data_t *isdn_data; char *var, *val; int32_t opts = 0; @@ -823,19 +866,23 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) 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); @@ -888,21 +935,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->start = zap_libpri_start; isdn_data->sig_cb = sig_cb; - isdn_data->dchans[0] = dchans[0]; - isdn_data->dchans[1] = dchans[1]; - isdn_data->dchan = isdn_data->dchans[0]; + //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); - if (lpwrap_init_pri(&isdn_data->spri, - span->span_id, // 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!"); - return ZAP_FAIL; - } span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 88d800a47f..a9f6e57fa8 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2563,6 +2563,8 @@ zap_status_t zap_global_init(void) time_init(); + zap_thread_override_default_stacksize(ZAP_THREAD_STACKSIZE); + memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); From 28d431aefdf004edf5694a56cf06122ff77c1d60 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 7 Mar 2009 02:20:40 +0000 Subject: [PATCH 1322/1766] performance tuning git-svn-id: http://svn.openzap.org/svn/openzap/trunk@684 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 38 ++++--- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 3 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 100 ++++++++++++------ libs/freetdm/src/zap_io.c | 2 + 5 files changed, 99 insertions(+), 45 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 81e7124dfb..9397766bf5 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -87,6 +87,7 @@ #pragma comment(lib, "Winmm") #endif +#define ZAP_THREAD_STACKSIZE 240 * 1024 #define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; #define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); #define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index 3b227c3c9b..1220a93a77 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -97,7 +97,8 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = { {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"} + {18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"}, + {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"} }; #define LINE "--------------------------------------------------------------------------------" @@ -114,8 +115,9 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) int res; if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) { - printf("D-READ FAIL! [%s]\n", spri->zdchan->last_error); - return 0; + zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + zap_clear_flag(spri, LPWRAP_PRI_READY); + return -1; } res = (int)len; memset(&((unsigned char*)buf)[res],0,2); @@ -133,8 +135,9 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) zap_size_t len = buflen -2; if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) { - printf("D-WRITE FAIL! [%s]\n", spri->zdchan->last_error); - return 0; + zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + zap_clear_flag(spri, LPWRAP_PRI_READY); + return -1; } //print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0); @@ -155,6 +158,7 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int spri->span = span; pri_set_debug(spri->pri, debug); ret = 0; + zap_set_flag(spri, LPWRAP_PRI_READY); } else { fprintf(stderr, "Unable to create PRI\n"); } @@ -168,6 +172,7 @@ 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) { @@ -210,7 +215,6 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } 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); @@ -219,16 +223,25 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - return sel; + if (zap_test_flag(spri, LPWRAP_PRI_READY)) { + 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){ + ret = lpwrap_one_loop(spri); + + if (ret < 0) { #ifndef WIN32 //This needs to be adressed fror WIN32 still if (errno == EINTR){ @@ -236,9 +249,8 @@ int lpwrap_run_pri(struct lpwrap_pri *spri) continue; } #endif - printf("Error = %i\n",ret); - perror("Lpwrap Run Pri: "); - break; + zap_log(ZAP_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno)); + break; } } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h index 9333e3a049..8ed6ab016f 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -58,7 +58,8 @@ typedef enum { 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_KEYPAD_DIGIT = PRI_EVENT_KEYPAD_DIGIT, + LPWRAP_PRI_EVENT_IO_FAIL = 19 } lpwrap_pri_event_t; typedef enum { diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 2e7a00b1f7..a3f4a6a205 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -704,28 +704,70 @@ static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev +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, event_type, lpwrap_pri_event_str(event_type)); + return 0; +} + + + 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; - - 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); - - isdn_data->spri.on_loop = check_flags; - isdn_data->spri.private_info = span; + int x, i; - lpwrap_run_pri(&isdn_data->spri); + while(zap_running()) { + x = 0; + + 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; + x++; + break; + } + } + } + + + if (x && lpwrap_init_pri(&isdn_data->spri, + span->span_id, // 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); + + + isdn_data->spri.on_loop = check_flags; + isdn_data->spri.private_info = span; + + lpwrap_run_pri(&isdn_data->spri); + zap_channel_close(&isdn_data->dchan); + } + + zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span); + zap_sleep(5000); + } return NULL; @@ -736,9 +778,10 @@ static zap_status_t zap_libpri_start(zap_span_t *span) zap_status_t ret; zap_libpri_data_t *isdn_data = span->signal_data; - zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING); + zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING); ret = zap_thread_create_detached(zap_libpri_run, span); + if (ret != ZAP_SUCCESS) { return ret; } @@ -806,7 +849,7 @@ static int str2dp(char *dp) static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) { uint32_t i, x = 0; - zap_channel_t *dchans[2] = {0}; + //zap_channel_t *dchans[2] = {0}; zap_libpri_data_t *isdn_data; char *var, *val; int32_t opts = 0; @@ -823,19 +866,23 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) 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); @@ -888,21 +935,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->start = zap_libpri_start; isdn_data->sig_cb = sig_cb; - isdn_data->dchans[0] = dchans[0]; - isdn_data->dchans[1] = dchans[1]; - isdn_data->dchan = isdn_data->dchans[0]; + //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); - if (lpwrap_init_pri(&isdn_data->spri, - span->span_id, // 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!"); - return ZAP_FAIL; - } span->signal_data = isdn_data; span->signal_type = ZAP_SIGTYPE_ISDN; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 88d800a47f..a9f6e57fa8 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2563,6 +2563,8 @@ zap_status_t zap_global_init(void) time_init(); + zap_thread_override_default_stacksize(ZAP_THREAD_STACKSIZE); + memset(&interfaces, 0, sizeof(interfaces)); globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); From 49926997e1a72992e13e4ee4bb86b916b0d56224 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Mar 2009 20:02:33 +0000 Subject: [PATCH 1323/1766] build: add signaling mods to windows build (OPENZAP-55) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@685 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.2005.sln | 18 + libs/openzap/openzap.2008.sln | 18 + .../ozmod_analog/ozmod_analog.2005.vcproj | 195 +++++++++++ .../ozmod_analog/ozmod_analog.2008.vcproj | 196 +++++++++++ .../ozmod_analog_em.2005.vcproj | 197 +++++++++++ .../ozmod_analog_em.2008.vcproj | 196 +++++++++++ .../ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj | 311 +++++++++++++++++ .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 312 ++++++++++++++++++ 8 files changed, 1443 insertions(+) create mode 100644 libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj diff --git a/libs/openzap/openzap.2005.sln b/libs/openzap/openzap.2005.sln index 5c34eb2878..47b79d1bce 100644 --- a/libs/openzap/openzap.2005.sln +++ b/libs/openzap/openzap.2005.sln @@ -18,6 +18,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2005.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2005.vcproj", "{C539D7C8-26A8-4A94-B938-77672165C130}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2005.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -40,6 +46,18 @@ Global {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.ActiveCfg = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.Build.0 = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.ActiveCfg = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.Build.0 = Release|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Debug|Win32.ActiveCfg = Debug|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Debug|Win32.Build.0 = Debug|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Release|Win32.ActiveCfg = Release|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Release|Win32.Build.0 = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.ActiveCfg = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.Build.0 = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.ActiveCfg = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/openzap/openzap.2008.sln b/libs/openzap/openzap.2008.sln index aaeda35ecb..12c5ff7dbf 100644 --- a/libs/openzap/openzap.2008.sln +++ b/libs/openzap/openzap.2008.sln @@ -18,6 +18,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2008.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2008.vcproj", "{B3F49375-2834-4937-9D8C-4AC2EC911010}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2008.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -40,6 +46,18 @@ Global {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.ActiveCfg = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.Build.0 = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.ActiveCfg = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.Build.0 = Release|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|Win32.ActiveCfg = Debug|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|Win32.Build.0 = Debug|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.ActiveCfg = Release|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.Build.0 = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.ActiveCfg = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.Build.0 = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.ActiveCfg = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj new file mode 100644 index 0000000000..5aeea53b14 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj new file mode 100644 index 0000000000..b49b57af17 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 0000000000..8c798e2842 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 0000000000..794b12e6ad --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj new file mode 100644 index 0000000000..b5a4c29e5d --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj new file mode 100644 index 0000000000..ab9d9805a4 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -0,0 +1,312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From af8c1bc336395e4f2bc076ef9591cfc2ce96e2c2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Mar 2009 20:02:33 +0000 Subject: [PATCH 1324/1766] build: add signaling mods to windows build (OPENZAP-55) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@685 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.2005.sln | 18 + libs/freetdm/openzap.2008.sln | 18 + .../ozmod_analog/ozmod_analog.2005.vcproj | 195 +++++++++++ .../ozmod_analog/ozmod_analog.2008.vcproj | 196 +++++++++++ .../ozmod_analog_em.2005.vcproj | 197 +++++++++++ .../ozmod_analog_em.2008.vcproj | 196 +++++++++++ .../ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj | 311 +++++++++++++++++ .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 312 ++++++++++++++++++ 8 files changed, 1443 insertions(+) create mode 100644 libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj diff --git a/libs/freetdm/openzap.2005.sln b/libs/freetdm/openzap.2005.sln index 5c34eb2878..47b79d1bce 100644 --- a/libs/freetdm/openzap.2005.sln +++ b/libs/freetdm/openzap.2005.sln @@ -18,6 +18,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2005.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2005.vcproj", "{C539D7C8-26A8-4A94-B938-77672165C130}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2005.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -40,6 +46,18 @@ Global {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.ActiveCfg = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.Build.0 = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.ActiveCfg = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.Build.0 = Release|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Debug|Win32.ActiveCfg = Debug|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Debug|Win32.Build.0 = Debug|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Release|Win32.ActiveCfg = Release|Win32 + {C539D7C8-26A8-4A94-B938-77672165C130}.Release|Win32.Build.0 = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.ActiveCfg = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.Build.0 = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.ActiveCfg = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/freetdm/openzap.2008.sln b/libs/freetdm/openzap.2008.sln index aaeda35ecb..12c5ff7dbf 100644 --- a/libs/freetdm/openzap.2008.sln +++ b/libs/freetdm/openzap.2008.sln @@ -18,6 +18,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2008.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2008.vcproj", "{B3F49375-2834-4937-9D8C-4AC2EC911010}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2008.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -40,6 +46,18 @@ Global {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.ActiveCfg = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.Build.0 = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.ActiveCfg = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.Build.0 = Release|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|Win32.ActiveCfg = Debug|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|Win32.Build.0 = Debug|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.ActiveCfg = Release|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.Build.0 = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.ActiveCfg = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.Build.0 = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.ActiveCfg = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj new file mode 100644 index 0000000000..5aeea53b14 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj new file mode 100644 index 0000000000..b49b57af17 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj new file mode 100644 index 0000000000..8c798e2842 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj new file mode 100644 index 0000000000..794b12e6ad --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj new file mode 100644 index 0000000000..b5a4c29e5d --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj new file mode 100644 index 0000000000..ab9d9805a4 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -0,0 +1,312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 3e9589d426b8777c471d76d06bd2d40b2507a314 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Mar 2009 20:20:00 +0000 Subject: [PATCH 1325/1766] build: add signaling mods to windows build (OPENZAP-55) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@686 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/openzap.2005.sln | 9 +++ libs/openzap/openzap.2008.sln | 9 +++ .../ozmod_analog/ozmod_analog.2005.vcproj | 11 ++- .../ozmod_analog/ozmod_analog.2008.vcproj | 11 ++- .../ozmod_analog_em.2005.vcproj | 7 +- .../ozmod_analog_em.2008.vcproj | 11 ++- .../ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj | 69 +++++++++---------- .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 69 +++++++++---------- 8 files changed, 100 insertions(+), 96 deletions(-) diff --git a/libs/openzap/openzap.2005.sln b/libs/openzap/openzap.2005.sln index 47b79d1bce..adba937d2f 100644 --- a/libs/openzap/openzap.2005.sln +++ b/libs/openzap/openzap.2005.sln @@ -19,10 +19,19 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2005.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2005.vcproj", "{C539D7C8-26A8-4A94-B938-77672165C130}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2005.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/libs/openzap/openzap.2008.sln b/libs/openzap/openzap.2008.sln index 12c5ff7dbf..d0ed62d842 100644 --- a/libs/openzap/openzap.2008.sln +++ b/libs/openzap/openzap.2008.sln @@ -19,10 +19,19 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2008.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2008.vcproj", "{B3F49375-2834-4937-9D8C-4AC2EC911010}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2008.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj index 5aeea53b14..016bd6bc58 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj @@ -40,7 +40,7 @@ @@ -181,14 +182,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj index b49b57af17..1fb02161f1 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -41,7 +41,7 @@ @@ -182,14 +183,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - 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 index 8c798e2842..4f64372f02 100644 --- 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 @@ -40,7 +40,7 @@ @@ -187,7 +188,7 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > 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 index 794b12e6ad..50d0d06d03 100644 --- 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 @@ -41,7 +41,7 @@ @@ -182,14 +183,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj index b5a4c29e5d..80689f6f2d 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj @@ -40,7 +40,7 @@ @@ -261,50 +262,46 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj index ab9d9805a4..77f3bb6f46 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -41,7 +41,7 @@ @@ -262,50 +263,46 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - From 0a3d9653ddc870cb1dbac3a4c8ac911cb48f6c1e Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 9 Mar 2009 20:20:00 +0000 Subject: [PATCH 1326/1766] build: add signaling mods to windows build (OPENZAP-55) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@686 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/openzap.2005.sln | 9 +++ libs/freetdm/openzap.2008.sln | 9 +++ .../ozmod_analog/ozmod_analog.2005.vcproj | 11 ++- .../ozmod_analog/ozmod_analog.2008.vcproj | 11 ++- .../ozmod_analog_em.2005.vcproj | 7 +- .../ozmod_analog_em.2008.vcproj | 11 ++- .../ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj | 69 +++++++++---------- .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 69 +++++++++---------- 8 files changed, 100 insertions(+), 96 deletions(-) diff --git a/libs/freetdm/openzap.2005.sln b/libs/freetdm/openzap.2005.sln index 47b79d1bce..adba937d2f 100644 --- a/libs/freetdm/openzap.2005.sln +++ b/libs/freetdm/openzap.2005.sln @@ -19,10 +19,19 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2005.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2005.vcproj", "{C539D7C8-26A8-4A94-B938-77672165C130}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2005.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/libs/freetdm/openzap.2008.sln b/libs/freetdm/openzap.2008.sln index 12c5ff7dbf..d0ed62d842 100644 --- a/libs/freetdm/openzap.2008.sln +++ b/libs/freetdm/openzap.2008.sln @@ -19,10 +19,19 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\ EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2008.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2008.vcproj", "{B3F49375-2834-4937-9D8C-4AC2EC911010}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2008.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj index 5aeea53b14..016bd6bc58 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj @@ -40,7 +40,7 @@ @@ -181,14 +182,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj index b49b57af17..1fb02161f1 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -41,7 +41,7 @@ @@ -182,14 +183,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj index 8c798e2842..4f64372f02 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj @@ -40,7 +40,7 @@ @@ -187,7 +188,7 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj index 794b12e6ad..50d0d06d03 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj @@ -41,7 +41,7 @@ @@ -182,14 +183,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj index b5a4c29e5d..80689f6f2d 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj @@ -40,7 +40,7 @@ @@ -261,50 +262,46 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj index ab9d9805a4..77f3bb6f46 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -41,7 +41,7 @@ @@ -262,50 +263,46 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - From 6ecd461c223590b4461dc6a0b628a3e20582d5e0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Mar 2009 23:35:01 +0000 Subject: [PATCH 1327/1766] remove log line git-svn-id: http://svn.openzap.org/svn/openzap/trunk@687 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index f8a987449f..ee4ddf5dda 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1692,7 +1692,6 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } - zap_log(ZAP_LOG_ERROR, "SPANID = %i\n", span->span_id); SPAN_CONFIG[span->span_id].span = span; switch_set_string(SPAN_CONFIG[span->span_id].context, context); From 36d330d39fa92cdc946b6cca9f82dfbcfb86f8db Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Mar 2009 23:35:01 +0000 Subject: [PATCH 1328/1766] remove log line git-svn-id: http://svn.openzap.org/svn/openzap/trunk@687 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index f8a987449f..ee4ddf5dda 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1692,7 +1692,6 @@ static switch_status_t load_config(void) zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); continue; } - zap_log(ZAP_LOG_ERROR, "SPANID = %i\n", span->span_id); SPAN_CONFIG[span->span_id].span = span; switch_set_string(SPAN_CONFIG[span->span_id].context, context); From f7ed3201a8800ff1d1eae83958f782c3ccbc787f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 15:49:27 +0000 Subject: [PATCH 1329/1766] add macros for api visibility to openzap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@688 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/msvc/openzap.2005.vcproj | 32 ++- libs/openzap/msvc/openzap.2008.vcproj | 26 ++- libs/openzap/src/include/libteletone.h | 28 ++- libs/openzap/src/include/libteletone_detect.h | 14 +- .../src/include/libteletone_generate.h | 18 +- libs/openzap/src/include/openzap.h | 186 ++++++++++-------- libs/openzap/src/include/zap_buffer.h | 26 +-- libs/openzap/src/include/zap_threadmutex.h | 16 +- libs/openzap/src/include/zap_types.h | 2 +- libs/openzap/src/libteletone_detect.c | 16 +- libs/openzap/src/libteletone_generate.c | 20 +- libs/openzap/src/zap_buffer.c | 26 +-- libs/openzap/src/zap_callerid.c | 26 +-- libs/openzap/src/zap_io.c | 122 ++++++------ libs/openzap/src/zap_threadmutex.c | 16 +- 15 files changed, 328 insertions(+), 246 deletions(-) diff --git a/libs/openzap/msvc/openzap.2005.vcproj b/libs/openzap/msvc/openzap.2005.vcproj index d02a4ada41..59419ea8e9 100644 --- a/libs/openzap/msvc/openzap.2005.vcproj +++ b/libs/openzap/msvc/openzap.2005.vcproj @@ -19,7 +19,7 @@ Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" > @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../src/include;../src/isdn/include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;OPENZAP_EXPORTS;TELETONE_EXPORTS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -52,7 +52,7 @@ WarningLevel="4" WarnAsError="true" Detect64BitPortabilityProblems="true" - DebugInformationFormat="4" + DebugInformationFormat="3" CompileAs="1" /> + @@ -79,6 +82,12 @@ + + @@ -87,7 +96,7 @@ Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" WholeProgramOptimization="1" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" @@ -110,7 +119,7 @@ + @@ -145,6 +157,12 @@ + + diff --git a/libs/openzap/msvc/openzap.2008.vcproj b/libs/openzap/msvc/openzap.2008.vcproj index a0d6c2b4b6..70e20bd2f4 100644 --- a/libs/openzap/msvc/openzap.2008.vcproj +++ b/libs/openzap/msvc/openzap.2008.vcproj @@ -20,7 +20,7 @@ Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" > @@ -43,7 +43,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../src/include;../src/isdn/include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;OPENZAP_EXPORTS;TELETONE_EXPORTS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -53,7 +53,7 @@ WarningLevel="4" WarnAsError="true" Detect64BitPortabilityProblems="false" - DebugInformationFormat="4" + DebugInformationFormat="3" CompileAs="1" /> + @@ -80,6 +83,9 @@ + @@ -88,7 +94,7 @@ Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" WholeProgramOptimization="1" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" @@ -111,7 +117,7 @@ + @@ -146,6 +155,9 @@ + diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index db6accb97e..4029facce8 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -110,6 +110,32 @@ typedef __int16 int16_t; #define teletone_assert(expr) assert(expr) #endif +#ifdef _MSC_VER +#if defined(TT_DECLARE_STATIC) +#define TELETONE_API(type) type __stdcall +#define TELETONE_API_NONSTD(type) type __cdecl +#define TELETONE_API_DATA +#elif defined(TELETONE_EXPORTS) +#define TELETONE_API(type) __declspec(dllexport) type __stdcall +#define TELETONE_API_NONSTD(type) __declspec(dllexport) type __cdecl +#define TELETONE_API_DATA __declspec(dllexport) +#else +#define TELETONE_API(type) __declspec(dllimport) type __stdcall +#define TELETONE_API_NONSTD(type) __declspec(dllimport) type __cdecl +#define TELETONE_API_DATA __declspec(dllimport) +#endif +#else +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) +#define TELETONE_API(type) __attribute__((visibility("default"))) type +#define TELETONE_API_NONSTD(type) __attribute__((visibility("default"))) type +#define TELETONE_API_DATA __attribute__((visibility("default"))) +#else +#define TELETONE_API(type) type +#define TELETONE_API_NONSTD(type) type +#define TELETONE_API_DATA +#endif +#endif + #include #include @@ -131,5 +157,5 @@ typedef __int16 int16_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/libteletone_detect.h b/libs/openzap/src/include/libteletone_detect.h index 3c44d480ee..3d0a5130ec 100644 --- a/libs/openzap/src/include/libteletone_detect.h +++ b/libs/openzap/src/include/libteletone_detect.h @@ -169,7 +169,7 @@ extern "C" { \param mt the multi-frequency tone descriptor \param map a representation of the multi-frequency tone */ - void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); +TELETONE_API(void) teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); /*! \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt @@ -178,7 +178,7 @@ extern "C" { \param samples the number of samples present in sample_buffer \return true when the tone was detected or false when it is not */ - int teletone_multi_tone_detect (teletone_multi_tone_t *mt, +TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples); @@ -187,7 +187,7 @@ extern "C" { \param dtmf_detect_state the DTMF detection state to initilize \param sample_rate the desired sample rate */ - void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); +TELETONE_API(void) teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); /*! \brief Check a sample buffer for the presence of DTMF digits @@ -196,7 +196,7 @@ extern "C" { \param samples the number of samples present in sample_buffer \return true when DTMF was detected or false when it is not */ - int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples); /*! @@ -206,7 +206,7 @@ extern "C" { \param max the maximum length of buf \return the number of characters written to buf */ - int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, int max); @@ -216,7 +216,7 @@ extern "C" { \param sample_buffer an array aof 16 bit signed linear samples \param samples the number of samples present in sample_buffer */ - void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, +TELETONE_API(void) teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int16_t sample_buffer[], int samples); @@ -236,5 +236,5 @@ extern "C" { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/libteletone_generate.h b/libs/openzap/src/include/libteletone_generate.h index d538fdc90a..fce19e7255 100644 --- a/libs/openzap/src/include/libteletone_generate.h +++ b/libs/openzap/src/include/libteletone_generate.h @@ -71,7 +71,7 @@ typedef __int8 int8_t; #include #include #include -#if !defined(powf) +#if !defined(powf) && !defined(_WIN64) extern float powf (float, float); #endif #include @@ -102,7 +102,7 @@ typedef struct teletone_dds_state teletone_dds_state_t; /* 3.02 represents twice the power */ #define DBM0_MAX_POWER (3.14f + 3.02f) -extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; +TELETONE_API_DATA extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint32_t rate) { @@ -220,7 +220,7 @@ typedef struct teletone_generation_session teletone_generation_session_t; \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 \return 0 */ -int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); +TELETONE_API(int) teletone_set_tone(teletone_generation_session_t *ts, int index, ...); /*! \brief Assign a set of tones to a single tone map @@ -228,7 +228,7 @@ int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 \return 0 */ -int teletone_set_map(teletone_tone_map_t *map, ...); +TELETONE_API(int) teletone_set_map(teletone_tone_map_t *map, ...); /*! \brief Initilize a tone generation session @@ -238,14 +238,14 @@ int teletone_set_map(teletone_tone_map_t *map, ...); \param user_data optional user data to send \return 0 */ -int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); +TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); /*! \brief Free the buffer allocated by a tone generation session \param ts the tone generation session to destroy \return 0 */ -int teletone_destroy_session(teletone_generation_session_t *ts); +TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts); /*! \brief Execute a single tone generation instruction @@ -253,7 +253,7 @@ int teletone_destroy_session(teletone_generation_session_t *ts); \param map the tone mapping to use for the frequencies \return 0 */ -int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); +TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); /*! \brief Execute a tone generation script and call callbacks after each instruction @@ -261,7 +261,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m \param cmd the script to execute \return 0 */ -int teletone_run(teletone_generation_session_t *ts, const char *cmd); +TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cmd); #ifdef __cplusplus } @@ -277,5 +277,5 @@ int teletone_run(teletone_generation_session_t *ts, const char *cmd); * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 9397766bf5..ed4308be07 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -47,11 +47,37 @@ #endif #ifndef __WINDOWS__ -#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) #define __WINDOWS__ #endif #endif +#ifdef _MSC_VER +#if defined(OZ_DECLARE_STATIC) +#define OZ_DECLARE(type) type __stdcall +#define OZ_DECLARE_NONSTD(type) type __cdecl +#define OZ_DECLARE_DATA +#elif defined(OPENZAP_EXPORTS) +#define OZ_DECLARE(type) __declspec(dllexport) type __stdcall +#define OZ_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl +#define OZ_DECLARE_DATA __declspec(dllexport) +#else +#define OZ_DECLARE(type) __declspec(dllimport) type __stdcall +#define OZ_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl +#define OZ_DECLARE_DATA __declspec(dllimport) +#endif +#else +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) +#define OZ_DECLARE(type) __attribute__((visibility("default"))) type +#define OZ_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type +#define OZ_DECLARE_DATA __attribute__((visibility("default"))) +#else +#define OZ_DECLARE(type) type +#define OZ_DECLARE_NONSTD(type) type +#define OZ_DECLARE_DATA +#endif +#endif + #ifdef _MSC_VER #ifndef __inline__ #define __inline__ __inline @@ -89,9 +115,9 @@ #define ZAP_THREAD_STACKSIZE 240 * 1024 #define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; -#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); +#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) OZ_DECLARE(_TYPE) _FUNC1 (const char *name); OZ_DECLARE(const char *) _FUNC2 (_TYPE type); #define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ - _TYPE _FUNC1 (const char *name) \ + OZ_DECLARE(_TYPE) _FUNC1 (const char *name) \ { \ int i; \ _TYPE t = _MAX ; \ @@ -105,7 +131,7 @@ \ return t; \ } \ - const char * _FUNC2 (_TYPE type) \ + OZ_DECLARE(const char *) _FUNC2 (_TYPE type) \ { \ if (type > _MAX) { \ type = _MAX; \ @@ -123,7 +149,7 @@ #include -#ifndef WIN32 +#ifndef __WINDOWS__ #include #endif @@ -146,7 +172,7 @@ #define XX if (0) -#ifdef WIN32 +#ifdef __WINDOWS__ #define zap_sleep(x) Sleep(x) #else #define zap_sleep(x) usleep(x * 1000) @@ -304,8 +330,8 @@ struct zap_stream_handle { }; -zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); -zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); #define ZAP_CMD_CHUNK_LEN 1024 #define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ @@ -526,7 +552,7 @@ struct zap_span { }; -extern zap_logger_t zap_log; +OZ_DECLARE_DATA extern zap_logger_t zap_log; struct zap_io_interface { const char *name; @@ -547,16 +573,16 @@ struct zap_io_interface { }; -zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); -int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); -void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); -void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); +OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); +OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); +OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); +OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); #define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ zap_fsk_modulator_send_data(_it); \ zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) -zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, +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, @@ -566,72 +592,72 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, uint32_t chan_sieze_bits, zap_fsk_write_sample_t write_sample_callback, void *user_data); -int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp); -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); -zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); -zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); -zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); -int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); -zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -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); -zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); -zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); -void zap_channel_rotate_tokens(zap_channel_t *zchan); -void zap_channel_clear_detected_tones(zap_channel_t *zchan); -void zap_channel_clear_needed_tones(zap_channel_t *zchan); -zap_status_t zap_channel_get_alarms(zap_channel_t *zchan); -zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); -zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname); -zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); -zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); -void zap_channel_flush_dtmf(zap_channel_t *zchan); -zap_time_t zap_current_time_in_ms(void); -zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); -zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); -zap_status_t zap_span_find(uint32_t id, zap_span_t **span); -zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); -zap_status_t zap_span_close_all(void); -zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); -zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); -zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); -zap_status_t zap_channel_close(zap_channel_t **zchan); -zap_status_t zap_channel_done(zap_channel_t *zchan); -zap_status_t zap_channel_use(zap_channel_t *zchan); -zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); -zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); -zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); -const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name); -zap_status_t zap_channel_clear_vars(zap_channel_t *zchan); -zap_status_t zap_global_init(void); -zap_status_t zap_global_destroy(void); -void zap_global_set_logger(zap_logger_t logger); -void zap_global_set_default_logger(int level); -uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); -void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); -int zap_hash_equalkeys(void *k1, void *k2); -uint32_t zap_hash_hashfromstring(void *ky); -uint32_t zap_running(void); -zap_status_t zap_channel_complete_state(zap_channel_t *zchan); -zap_status_t zap_channel_init(zap_channel_t *zchan); -int zap_load_modules(void); -zap_status_t zap_unload_modules(void); -zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); -zap_status_t zap_span_start(zap_span_t *span); -int zap_load_module(const char *name); -int zap_load_module_assume(const char *name); -zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); -char *zap_api_execute(const char *type, const char *cmd); -int zap_vasprintf(char **ret, const char *fmt, va_list ap); +OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp); +OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); +OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); +OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); +OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state); +OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); +OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); +OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen); +OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); +OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); +OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan); +OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan); +OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan); +OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); +OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token); +OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end); +OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); +OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname); +OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); +OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); +OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan); +OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void); +OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms); +OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event); +OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span); +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span); +OZ_DECLARE(zap_status_t) zap_span_close_all(void); +OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); +OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); +OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); +OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); +OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); +OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); +OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); +OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); +OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name); +OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_global_init(void); +OZ_DECLARE(zap_status_t) zap_global_destroy(void); +OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger); +OZ_DECLARE(void) zap_global_set_default_logger(int level); +OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen); +OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); +OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); +OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2); +OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky); +OZ_DECLARE(uint32_t) zap_running(void); +OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan); +OZ_DECLARE(int) zap_load_modules(void); +OZ_DECLARE(zap_status_t) zap_unload_modules(void); +OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); +OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); +OZ_DECLARE(int) zap_load_module(const char *name); +OZ_DECLARE(int) zap_load_module_assume(const char *name); +OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); +OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd); +OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/include/zap_buffer.h b/libs/openzap/src/include/zap_buffer.h index 958d2fc8e7..2824c7938a 100644 --- a/libs/openzap/src/include/zap_buffer.h +++ b/libs/openzap/src/include/zap_buffer.h @@ -53,25 +53,25 @@ typedef struct zap_buffer zap_buffer_t; * \param max_len length the buffer is allowed to grow to * \return status */ -zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len); +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. */ -zap_size_t zap_buffer_len(zap_buffer_t *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. */ -zap_size_t zap_buffer_freespace(zap_buffer_t *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 */ -zap_size_t zap_buffer_inuse(zap_buffer_t *buffer); +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 @@ -79,7 +79,7 @@ zap_size_t zap_buffer_inuse(zap_buffer_t *buffer); * \param datalen amount of data to be returned * \return int ammount of data actually read */ -zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen); +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 @@ -88,13 +88,13 @@ zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) * \return int ammount of data actually read * \note Once you have read all the data from the buffer it will loop around. */ -zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen); +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) */ -void zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops); +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 @@ -102,36 +102,36 @@ void zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops); * \param datalen amount of data to be written * \return int amount of buffer used after the write, or 0 if no space available */ -zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen); +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 */ -zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen); +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 */ -void zap_buffer_zero(zap_buffer_t *buffer); +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) */ -void zap_buffer_destroy(zap_buffer_t **buffer); +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 */ -zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); +OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); /** @} */ -zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, 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: diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index f187bc516f..8639027ab7 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -27,14 +27,14 @@ typedef struct zap_mutex zap_mutex_t; typedef struct zap_thread zap_thread_t; typedef void *(*zap_thread_function_t) (zap_thread_t *, void *); -zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data); -zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); -void zap_thread_override_default_stacksize(zap_size_t size); -zap_status_t zap_mutex_create(zap_mutex_t **mutex); -zap_status_t zap_mutex_destroy(zap_mutex_t **mutex); -zap_status_t _zap_mutex_lock(zap_mutex_t *mutex); -zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex); -zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex); +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); #endif diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index fee42a14c0..09ea5fa4ac 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -461,7 +461,7 @@ typedef zap_status_t (*zio_api_t) ZIO_API_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) zap_status_t name ZIO_CODEC_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 diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index 79875a0ade..b41a04ae42 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -83,7 +83,7 @@ static void goertzel_init(teletone_goertzel_state_t *goertzel_state, teletone_de goertzel_state->fac = tdesc->fac; } -void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, +TELETONE_API(void) teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int16_t sample_buffer[], int samples) { @@ -102,7 +102,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, #define teletone_goertzel_result(gs) (double)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) -void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) +TELETONE_API(void) teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { int i; float theta; @@ -136,7 +136,7 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, dtmf_detect_state->mhit = 0; } -void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) +TELETONE_API(void) teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) { float theta = 0; int x = 0; @@ -145,7 +145,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma mt->sample_rate = 8000; } - if(!mt->min_samples) { + if (!mt->min_samples) { mt->min_samples = 102; } @@ -176,7 +176,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } -int teletone_multi_tone_detect (teletone_multi_tone_t *mt, +TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples) { @@ -266,7 +266,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } -int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples) { @@ -397,7 +397,7 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, } -int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, int max) { @@ -423,5 +423,5 @@ int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/libteletone_generate.c b/libs/openzap/src/libteletone_generate.c index 84de06853c..1d5d696af2 100644 --- a/libs/openzap/src/libteletone_generate.c +++ b/libs/openzap/src/libteletone_generate.c @@ -43,7 +43,7 @@ #pragma warning(disable:4706) #endif -int16_t TELETONE_SINES[SINE_TABLE_MAX] = { +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, @@ -63,7 +63,7 @@ int16_t TELETONE_SINES[SINE_TABLE_MAX] = { }; -int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) +TELETONE_API(int) teletone_set_tone(teletone_generation_session_t *ts, int index, ...) { va_list ap; int i = 0; @@ -79,7 +79,7 @@ int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) } -int teletone_set_map(teletone_tone_map_t *map, ...) +TELETONE_API(int) teletone_set_map(teletone_tone_map_t *map, ...) { va_list ap; int i = 0; @@ -95,7 +95,7 @@ int teletone_set_map(teletone_tone_map_t *map, ...) } -int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data) +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; @@ -138,7 +138,7 @@ int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_ha return 0; } -int teletone_destroy_session(teletone_generation_session_t *ts) +TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts) { if (ts->buffer) { free(ts->buffer); @@ -167,7 +167,7 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need) return 0; } -int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map) +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; @@ -185,7 +185,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m wait = (ts->tmp_wait > -1) ? ts->tmp_wait : ts->wait; if (map->freqs[0] > 0) { - for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { + 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); } @@ -207,7 +207,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) { vol = nvol; - for (j = 0; map->freqs[j] && j < TELETONE_MAX_TONES; j++) { + for (j = 0; j < TELETONE_MAX_TONES && map->freqs[j]; j++) { teletone_dds_state_set_tx_level(&tones[j], vol); } dc = 0; @@ -282,7 +282,7 @@ static char *my_strdup (const char *s) return (char *) memcpy (new, s, len); } -int teletone_run(teletone_generation_session_t *ts, const char *cmd) +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; @@ -460,5 +460,5 @@ int teletone_run(teletone_generation_session_t *ts, const char *cmd) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 777151d8b9..8315825ff7 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -49,7 +49,7 @@ struct zap_buffer { }; -zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len) +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; @@ -79,7 +79,7 @@ zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_ return ZAP_MEMERR; } -zap_size_t zap_buffer_len(zap_buffer_t *buffer) +OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer) { assert(buffer != NULL); @@ -89,7 +89,7 @@ zap_size_t zap_buffer_len(zap_buffer_t *buffer) } -zap_size_t zap_buffer_freespace(zap_buffer_t *buffer) +OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer) { assert(buffer != NULL); @@ -101,14 +101,14 @@ zap_size_t zap_buffer_freespace(zap_buffer_t *buffer) } -zap_size_t zap_buffer_inuse(zap_buffer_t *buffer) +OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer) { assert(buffer != NULL); return buffer->used; } -zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) { zap_size_t reading = 0; @@ -129,7 +129,7 @@ zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) return reading; } -zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) { zap_size_t reading = 0; @@ -150,12 +150,12 @@ zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) return buffer->used; } -void zap_buffer_set_loops(zap_buffer_t *buffer, int loops) +OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int loops) { buffer->loops = loops; } -zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen) +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) { @@ -170,7 +170,7 @@ zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t dat return len; } -zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) { zap_size_t reading = 0; @@ -195,7 +195,7 @@ zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) return reading; } -zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen) +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; @@ -258,7 +258,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d return buffer->used; } -void zap_buffer_zero(zap_buffer_t *buffer) +OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer) { assert(buffer != NULL); assert(buffer->data != NULL); @@ -268,7 +268,7 @@ void zap_buffer_zero(zap_buffer_t *buffer) buffer->head = buffer->data; } -zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen) { zap_size_t w; @@ -280,7 +280,7 @@ zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t return w; } -void zap_buffer_destroy(zap_buffer_t **buffer) +OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer) { if (*buffer) { free((*buffer)->data); diff --git a/libs/openzap/src/zap_callerid.c b/libs/openzap/src/zap_callerid.c index 967b80a40c..7a6e658261 100644 --- a/libs/openzap/src/zap_callerid.c +++ b/libs/openzap/src/zap_callerid.c @@ -37,7 +37,7 @@ static void fsk_byte_handler (void *x, int data) } } -zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen) +OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen) { memset(state, 0, sizeof(*state)); state->buf = data; @@ -47,7 +47,7 @@ zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint3 return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number) +OZ_DECLARE(zap_status_t) zap_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); @@ -61,7 +61,7 @@ zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen) +OZ_DECLARE(zap_status_t) zap_fsk_data_add_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; @@ -72,7 +72,7 @@ zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t } -zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) +OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) { uint32_t i; uint8_t check = 0; @@ -93,7 +93,7 @@ zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) } -zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) +OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) { zap_size_t i; @@ -146,7 +146,7 @@ zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, c return ZAP_FAIL; } -zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_size_t samples) +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; @@ -166,14 +166,14 @@ zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_ return ZAP_SUCCESS; } -zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state) +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; } -int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_size_t bufsize) +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; @@ -199,7 +199,7 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ return ZAP_SUCCESS; } -zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen) +OZ_DECLARE(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; @@ -217,7 +217,7 @@ zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t } -int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits) +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; @@ -237,7 +237,7 @@ int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, } -void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) +OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) { uint32_t i = 0; zap_size_t r = 0; @@ -258,7 +258,7 @@ void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) } -void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) +OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) { zap_size_t r = 0; int8_t bit = 0; @@ -275,7 +275,7 @@ void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) } -zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, +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, diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a9f6e57fa8..e10928a427 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -63,7 +63,7 @@ static void time_end(void) time_is_init = 0; } -zap_time_t zap_current_time_in_ms(void) +OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void) { #ifdef WIN32 return timeGetTime(); @@ -175,9 +175,9 @@ static void default_logger(const char *file, const char *func, int line, int lev } -zap_logger_t zap_log = null_logger; +OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; -void zap_global_set_logger(zap_logger_t logger) +OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger) { if (logger) { zap_log = logger; @@ -186,7 +186,7 @@ void zap_global_set_logger(zap_logger_t logger) } } -void zap_global_set_default_logger(int level) +OZ_DECLARE(void) zap_global_set_default_logger(int level) { if (level < 0 || level > 7) { level = 7; @@ -196,12 +196,12 @@ void zap_global_set_default_logger(int level) zap_log_level = level; } -int zap_hash_equalkeys(void *k1, void *k2) +OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -uint32_t zap_hash_hashfromstring(void *ky) +OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; uint32_t hash = 0; @@ -270,7 +270,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) -zap_status_t zap_channel_get_alarms(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -304,7 +304,7 @@ zap_status_t zap_channel_get_alarms(zap_channel_t *zchan) return status; } -zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; zap_status_t status = ZAP_FAIL; @@ -343,7 +343,7 @@ done: return status; } -zap_status_t zap_span_close_all(void) +OZ_DECLARE(zap_status_t) zap_span_close_all(void) { zap_span_t *span; uint32_t i, j; @@ -362,7 +362,7 @@ zap_status_t zap_span_close_all(void) return i ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) +OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname) { zap_config_t cfg; char *var, *val; @@ -428,7 +428,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) } -zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) +OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *new_chan = span->channels[++span->chan_count]; @@ -473,7 +473,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span) +OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span) { zap_status_t status = ZAP_FAIL; @@ -486,7 +486,7 @@ zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span) return status; } -zap_status_t zap_span_find(uint32_t id, zap_span_t **span) +OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span) { zap_span_t *fspan; @@ -508,7 +508,7 @@ zap_status_t zap_span_find(uint32_t id, zap_span_t **span) } -zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) +OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) { zap_mutex_lock(span->mutex); span->event_callback = event_callback; @@ -517,7 +517,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ } -zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) +OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms) { assert(span->zio != NULL); @@ -530,7 +530,7 @@ zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) return ZAP_NOTIMPL; } -zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) +OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event) { assert(span->zio != NULL); @@ -550,7 +550,7 @@ static zap_status_t zchan_fsk_write_sample(int16_t *buf, zap_size_t buflen, void return ZAP_SUCCESS; } -zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) +OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) { struct zap_fsk_modulator fsk_trans; @@ -573,7 +573,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ } -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) +OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->mutex); zchan->event_callback = event_callback; @@ -581,7 +581,7 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token) +OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token) { zap_status_t status = ZAP_FAIL; @@ -610,7 +610,7 @@ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token) return status; } -void zap_channel_rotate_tokens(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) { if (zchan->token_count) { memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); @@ -619,7 +619,7 @@ void zap_channel_rotate_tokens(zap_channel_t *zchan) } } -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) +OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end) { zap_status_t status = ZAP_FAIL; @@ -640,7 +640,7 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) } -zap_status_t zap_channel_complete_state(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan) { zap_channel_state_t state = zchan->state; @@ -704,7 +704,7 @@ static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, return ok; } -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) +OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) { int ok = 1; @@ -830,7 +830,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -997,7 +997,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_init(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan) { if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { @@ -1008,7 +1008,7 @@ zap_status_t zap_channel_init(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_open_chan(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -1039,7 +1039,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) return status; } -zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { zap_channel_t *check; zap_status_t status = ZAP_FAIL; @@ -1089,7 +1089,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t return status; } -zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) { zap_status_t status; @@ -1107,7 +1107,7 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) return ZAP_FAIL; } -zap_status_t zap_channel_done(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) { assert(zchan != NULL); @@ -1134,7 +1134,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_use(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan) { assert(zchan != NULL); @@ -1144,7 +1144,7 @@ zap_status_t zap_channel_use(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_close(zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan) { zap_channel_t *check; zap_status_t status = ZAP_FAIL; @@ -1206,7 +1206,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) +OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { zap_status_t status = ZAP_FAIL; @@ -1467,7 +1467,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) +OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) { assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1617,17 +1617,17 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) /******************************/ -void zap_channel_clear_detected_tones(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan) { memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); } -void zap_channel_clear_needed_tones(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan) { memset(zchan->needed_tones, 0, sizeof(zchan->needed_tones[0]) * ZAP_TONEMAP_INVALID); } -zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) +OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) { zap_size_t bytes = 0; @@ -1648,7 +1648,7 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t return bytes; } -void zap_channel_flush_dtmf(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan) { if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { zap_mutex_lock(zchan->mutex); @@ -1657,7 +1657,7 @@ void zap_channel_flush_dtmf(zap_channel_t *zchan) } } -zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) +OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) { zap_status_t status; register zap_size_t len, inuse; @@ -1785,7 +1785,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) -zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) +OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; @@ -1983,7 +1983,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) +OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; @@ -2042,7 +2042,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data return status; } -zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan) { if(zchan->variable_hash) { hashtable_destroy(zchan->variable_hash); @@ -2055,7 +2055,7 @@ zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) +OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) { char *t_name = 0, *t_val = 0; @@ -2073,7 +2073,7 @@ zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, con return ZAP_FAIL; } -const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name) +OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name) { if(!zchan->variable_hash || !var_name) { @@ -2087,7 +2087,7 @@ static struct { } interfaces; -char *zap_api_execute(const char *type, const char *cmd) +OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd) { zap_io_interface_t *zio = NULL; char *dup = NULL, *p; @@ -2351,7 +2351,7 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } -int zap_load_module(const char *name) +OZ_DECLARE(int) zap_load_module(const char *name) { zap_dso_lib_t lib; int count = 0, x = 0; @@ -2445,7 +2445,7 @@ int zap_load_module(const char *name) return count; } -int zap_load_module_assume(const char *name) +OZ_DECLARE(int) zap_load_module_assume(const char *name) { char buf[256] = ""; @@ -2453,7 +2453,7 @@ int zap_load_module_assume(const char *name) return zap_load_module(buf); } -int zap_load_modules(void) +OZ_DECLARE(int) zap_load_modules(void) { char cfg_name[] = "modules.conf"; zap_config_t cfg; @@ -2475,7 +2475,7 @@ int zap_load_modules(void) return count; } -zap_status_t zap_unload_modules(void) +OZ_DECLARE(zap_status_t) zap_unload_modules(void) { zap_hash_iterator_t *i; zap_dso_lib_t lib; @@ -2520,7 +2520,7 @@ zap_status_t zap_unload_modules(void) return ZAP_SUCCESS; } -zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) +OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) { zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_status_t status = ZAP_FAIL; @@ -2545,7 +2545,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c return status; } -zap_status_t zap_span_start(zap_span_t *span) +OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) { if (span->start) { return span->start(span); @@ -2555,7 +2555,7 @@ zap_status_t zap_span_start(zap_span_t *span) } -zap_status_t zap_global_init(void) +OZ_DECLARE(zap_status_t) zap_global_init(void) { int modcount; @@ -2584,13 +2584,13 @@ zap_status_t zap_global_init(void) return ZAP_FAIL; } -uint32_t zap_running(void) +OZ_DECLARE(uint32_t) zap_running(void) { return globals.running; } -zap_status_t zap_global_destroy(void) +OZ_DECLARE(zap_status_t) zap_global_destroy(void) { unsigned int i,j; time_end(); @@ -2650,7 +2650,7 @@ zap_status_t zap_global_destroy(void) } -uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) +OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen) { int argc; char *ptr; @@ -2707,7 +2707,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) +OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) { memset(bsp, 0, sizeof(*bsp)); bsp->data = data; @@ -2725,7 +2725,7 @@ void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, z } -int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) +OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp) { int8_t bit = -1; @@ -2771,7 +2771,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) return bit; } -void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) +OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) { char *bp = buf; uint8_t *byte = data; @@ -2794,7 +2794,7 @@ void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) } -void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) +OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) { zap_bitstream_t bs; int j = 0, c = 0; @@ -2823,7 +2823,7 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t -zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) { zap_size_t need = handle->data_len + datalen; @@ -2847,7 +2847,7 @@ zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t * return ZAP_SUCCESS; } -int zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ +OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ { #ifdef HAVE_VASPRINTF return vasprintf(ret, fmt, ap); @@ -2883,7 +2883,7 @@ int zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_a #endif } -zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) { va_list ap; char *buf = handle->data; diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index abeaa1f9b5..2dc4763068 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -62,7 +62,7 @@ struct zap_thread { zap_size_t thread_default_stacksize = 0; -void zap_thread_override_default_stacksize(zap_size_t size) +OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size) { thread_default_stacksize = size; } @@ -80,12 +80,12 @@ static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) return exit_val; } -zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data) +OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data) { return zap_thread_create_detached_ex(func, data, thread_default_stacksize); } -zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) +OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) { zap_thread_t *thread = NULL; zap_status_t status = ZAP_FAIL; @@ -132,7 +132,7 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat } -zap_status_t zap_mutex_create(zap_mutex_t **mutex) +OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex) { zap_status_t status = ZAP_FAIL; #ifndef WIN32 @@ -170,7 +170,7 @@ zap_status_t zap_mutex_create(zap_mutex_t **mutex) return status; } -zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) +OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex) { zap_mutex_t *mp = *mutex; *mutex = NULL; @@ -187,7 +187,7 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) return ZAP_SUCCESS; } -zap_status_t _zap_mutex_lock(zap_mutex_t *mutex) +OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); @@ -198,7 +198,7 @@ zap_status_t _zap_mutex_lock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex) +OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) @@ -210,7 +210,7 @@ zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex) +OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); From 6c1e0688c3653b7b0480e538ab4038cce828c4d9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 15:49:27 +0000 Subject: [PATCH 1330/1766] add macros for api visibility to openzap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@688 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.2005.vcproj | 32 ++- libs/freetdm/msvc/openzap.2008.vcproj | 26 ++- libs/freetdm/src/include/libteletone.h | 28 ++- libs/freetdm/src/include/libteletone_detect.h | 14 +- .../src/include/libteletone_generate.h | 18 +- libs/freetdm/src/include/openzap.h | 186 ++++++++++-------- libs/freetdm/src/include/zap_buffer.h | 26 +-- libs/freetdm/src/include/zap_threadmutex.h | 16 +- libs/freetdm/src/include/zap_types.h | 2 +- libs/freetdm/src/libteletone_detect.c | 16 +- libs/freetdm/src/libteletone_generate.c | 20 +- libs/freetdm/src/zap_buffer.c | 26 +-- libs/freetdm/src/zap_callerid.c | 26 +-- libs/freetdm/src/zap_io.c | 122 ++++++------ libs/freetdm/src/zap_threadmutex.c | 16 +- 15 files changed, 328 insertions(+), 246 deletions(-) diff --git a/libs/freetdm/msvc/openzap.2005.vcproj b/libs/freetdm/msvc/openzap.2005.vcproj index d02a4ada41..59419ea8e9 100644 --- a/libs/freetdm/msvc/openzap.2005.vcproj +++ b/libs/freetdm/msvc/openzap.2005.vcproj @@ -19,7 +19,7 @@ Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" > @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../src/include;../src/isdn/include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;OPENZAP_EXPORTS;TELETONE_EXPORTS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -52,7 +52,7 @@ WarningLevel="4" WarnAsError="true" Detect64BitPortabilityProblems="true" - DebugInformationFormat="4" + DebugInformationFormat="3" CompileAs="1" /> + @@ -79,6 +82,12 @@ + + @@ -87,7 +96,7 @@ Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" WholeProgramOptimization="1" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" @@ -110,7 +119,7 @@ + @@ -145,6 +157,12 @@ + + diff --git a/libs/freetdm/msvc/openzap.2008.vcproj b/libs/freetdm/msvc/openzap.2008.vcproj index a0d6c2b4b6..70e20bd2f4 100644 --- a/libs/freetdm/msvc/openzap.2008.vcproj +++ b/libs/freetdm/msvc/openzap.2008.vcproj @@ -20,7 +20,7 @@ Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" > @@ -43,7 +43,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../src/include;../src/isdn/include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;OPENZAP_EXPORTS;TELETONE_EXPORTS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -53,7 +53,7 @@ WarningLevel="4" WarnAsError="true" Detect64BitPortabilityProblems="false" - DebugInformationFormat="4" + DebugInformationFormat="3" CompileAs="1" /> + @@ -80,6 +83,9 @@ + @@ -88,7 +94,7 @@ Name="Release|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" + ConfigurationType="2" CharacterSet="2" WholeProgramOptimization="1" BuildLogFile="$(IntDir)\BuildLog-openzap.htm" @@ -111,7 +117,7 @@ + @@ -146,6 +155,9 @@ + diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index db6accb97e..4029facce8 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -110,6 +110,32 @@ typedef __int16 int16_t; #define teletone_assert(expr) assert(expr) #endif +#ifdef _MSC_VER +#if defined(TT_DECLARE_STATIC) +#define TELETONE_API(type) type __stdcall +#define TELETONE_API_NONSTD(type) type __cdecl +#define TELETONE_API_DATA +#elif defined(TELETONE_EXPORTS) +#define TELETONE_API(type) __declspec(dllexport) type __stdcall +#define TELETONE_API_NONSTD(type) __declspec(dllexport) type __cdecl +#define TELETONE_API_DATA __declspec(dllexport) +#else +#define TELETONE_API(type) __declspec(dllimport) type __stdcall +#define TELETONE_API_NONSTD(type) __declspec(dllimport) type __cdecl +#define TELETONE_API_DATA __declspec(dllimport) +#endif +#else +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) +#define TELETONE_API(type) __attribute__((visibility("default"))) type +#define TELETONE_API_NONSTD(type) __attribute__((visibility("default"))) type +#define TELETONE_API_DATA __attribute__((visibility("default"))) +#else +#define TELETONE_API(type) type +#define TELETONE_API_NONSTD(type) type +#define TELETONE_API_DATA +#endif +#endif + #include #include @@ -131,5 +157,5 @@ typedef __int16 int16_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 3c44d480ee..3d0a5130ec 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -169,7 +169,7 @@ extern "C" { \param mt the multi-frequency tone descriptor \param map a representation of the multi-frequency tone */ - void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); +TELETONE_API(void) teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map); /*! \brief Check a sample buffer for the presence of the mulit-frequency tone described by mt @@ -178,7 +178,7 @@ extern "C" { \param samples the number of samples present in sample_buffer \return true when the tone was detected or false when it is not */ - int teletone_multi_tone_detect (teletone_multi_tone_t *mt, +TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples); @@ -187,7 +187,7 @@ extern "C" { \param dtmf_detect_state the DTMF detection state to initilize \param sample_rate the desired sample rate */ - void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); +TELETONE_API(void) teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate); /*! \brief Check a sample buffer for the presence of DTMF digits @@ -196,7 +196,7 @@ extern "C" { \param samples the number of samples present in sample_buffer \return true when DTMF was detected or false when it is not */ - int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples); /*! @@ -206,7 +206,7 @@ extern "C" { \param max the maximum length of buf \return the number of characters written to buf */ - int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, int max); @@ -216,7 +216,7 @@ extern "C" { \param sample_buffer an array aof 16 bit signed linear samples \param samples the number of samples present in sample_buffer */ - void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, +TELETONE_API(void) teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int16_t sample_buffer[], int samples); @@ -236,5 +236,5 @@ extern "C" { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/libteletone_generate.h b/libs/freetdm/src/include/libteletone_generate.h index d538fdc90a..fce19e7255 100644 --- a/libs/freetdm/src/include/libteletone_generate.h +++ b/libs/freetdm/src/include/libteletone_generate.h @@ -71,7 +71,7 @@ typedef __int8 int8_t; #include #include #include -#if !defined(powf) +#if !defined(powf) && !defined(_WIN64) extern float powf (float, float); #endif #include @@ -102,7 +102,7 @@ typedef struct teletone_dds_state teletone_dds_state_t; /* 3.02 represents twice the power */ #define DBM0_MAX_POWER (3.14f + 3.02f) -extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; +TELETONE_API_DATA extern int16_t TELETONE_SINES[SINE_TABLE_MAX]; static __inline__ int32_t teletone_dds_phase_rate(teletone_process_t tone, uint32_t rate) { @@ -220,7 +220,7 @@ typedef struct teletone_generation_session teletone_generation_session_t; \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 \return 0 */ -int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); +TELETONE_API(int) teletone_set_tone(teletone_generation_session_t *ts, int index, ...); /*! \brief Assign a set of tones to a single tone map @@ -228,7 +228,7 @@ int teletone_set_tone(teletone_generation_session_t *ts, int index, ...); \param ... up to TELETONE_MAX_TONES frequencies terminated by 0.0 \return 0 */ -int teletone_set_map(teletone_tone_map_t *map, ...); +TELETONE_API(int) teletone_set_map(teletone_tone_map_t *map, ...); /*! \brief Initilize a tone generation session @@ -238,14 +238,14 @@ int teletone_set_map(teletone_tone_map_t *map, ...); \param user_data optional user data to send \return 0 */ -int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); +TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data); /*! \brief Free the buffer allocated by a tone generation session \param ts the tone generation session to destroy \return 0 */ -int teletone_destroy_session(teletone_generation_session_t *ts); +TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts); /*! \brief Execute a single tone generation instruction @@ -253,7 +253,7 @@ int teletone_destroy_session(teletone_generation_session_t *ts); \param map the tone mapping to use for the frequencies \return 0 */ -int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); +TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map); /*! \brief Execute a tone generation script and call callbacks after each instruction @@ -261,7 +261,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m \param cmd the script to execute \return 0 */ -int teletone_run(teletone_generation_session_t *ts, const char *cmd); +TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cmd); #ifdef __cplusplus } @@ -277,5 +277,5 @@ int teletone_run(teletone_generation_session_t *ts, const char *cmd); * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 9397766bf5..ed4308be07 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -47,11 +47,37 @@ #endif #ifndef __WINDOWS__ -#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) #define __WINDOWS__ #endif #endif +#ifdef _MSC_VER +#if defined(OZ_DECLARE_STATIC) +#define OZ_DECLARE(type) type __stdcall +#define OZ_DECLARE_NONSTD(type) type __cdecl +#define OZ_DECLARE_DATA +#elif defined(OPENZAP_EXPORTS) +#define OZ_DECLARE(type) __declspec(dllexport) type __stdcall +#define OZ_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl +#define OZ_DECLARE_DATA __declspec(dllexport) +#else +#define OZ_DECLARE(type) __declspec(dllimport) type __stdcall +#define OZ_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl +#define OZ_DECLARE_DATA __declspec(dllimport) +#endif +#else +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) +#define OZ_DECLARE(type) __attribute__((visibility("default"))) type +#define OZ_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type +#define OZ_DECLARE_DATA __attribute__((visibility("default"))) +#else +#define OZ_DECLARE(type) type +#define OZ_DECLARE_NONSTD(type) type +#define OZ_DECLARE_DATA +#endif +#endif + #ifdef _MSC_VER #ifndef __inline__ #define __inline__ __inline @@ -89,9 +115,9 @@ #define ZAP_THREAD_STACKSIZE 240 * 1024 #define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; -#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); +#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) OZ_DECLARE(_TYPE) _FUNC1 (const char *name); OZ_DECLARE(const char *) _FUNC2 (_TYPE type); #define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ - _TYPE _FUNC1 (const char *name) \ + OZ_DECLARE(_TYPE) _FUNC1 (const char *name) \ { \ int i; \ _TYPE t = _MAX ; \ @@ -105,7 +131,7 @@ \ return t; \ } \ - const char * _FUNC2 (_TYPE type) \ + OZ_DECLARE(const char *) _FUNC2 (_TYPE type) \ { \ if (type > _MAX) { \ type = _MAX; \ @@ -123,7 +149,7 @@ #include -#ifndef WIN32 +#ifndef __WINDOWS__ #include #endif @@ -146,7 +172,7 @@ #define XX if (0) -#ifdef WIN32 +#ifdef __WINDOWS__ #define zap_sleep(x) Sleep(x) #else #define zap_sleep(x) usleep(x * 1000) @@ -304,8 +330,8 @@ struct zap_stream_handle { }; -zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); -zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); #define ZAP_CMD_CHUNK_LEN 1024 #define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ @@ -526,7 +552,7 @@ struct zap_span { }; -extern zap_logger_t zap_log; +OZ_DECLARE_DATA extern zap_logger_t zap_log; struct zap_io_interface { const char *name; @@ -547,16 +573,16 @@ struct zap_io_interface { }; -zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); -int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); -void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); -void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); +OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); +OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); +OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); +OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); #define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ zap_fsk_modulator_send_data(_it); \ zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) -zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, +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, @@ -566,72 +592,72 @@ zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, uint32_t chan_sieze_bits, zap_fsk_write_sample_t write_sample_callback, void *user_data); -int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp); -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); -zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); -zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); -zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state); -int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); -zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -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); -zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); -zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan); -void zap_channel_rotate_tokens(zap_channel_t *zchan); -void zap_channel_clear_detected_tones(zap_channel_t *zchan); -void zap_channel_clear_needed_tones(zap_channel_t *zchan); -zap_status_t zap_channel_get_alarms(zap_channel_t *zchan); -zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token); -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end); -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); -zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname); -zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); -zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); -void zap_channel_flush_dtmf(zap_channel_t *zchan); -zap_time_t zap_current_time_in_ms(void); -zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms); -zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event); -zap_status_t zap_span_find(uint32_t id, zap_span_t **span); -zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span); -zap_status_t zap_span_close_all(void); -zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); -zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); -zap_status_t zap_channel_open_chan(zap_channel_t *zchan); -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); -zap_status_t zap_channel_close(zap_channel_t **zchan); -zap_status_t zap_channel_done(zap_channel_t *zchan); -zap_status_t zap_channel_use(zap_channel_t *zchan); -zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); -zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); -zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); -const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name); -zap_status_t zap_channel_clear_vars(zap_channel_t *zchan); -zap_status_t zap_global_init(void); -zap_status_t zap_global_destroy(void); -void zap_global_set_logger(zap_logger_t logger); -void zap_global_set_default_logger(int level); -uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen); -void print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); -void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); -int zap_hash_equalkeys(void *k1, void *k2); -uint32_t zap_hash_hashfromstring(void *ky); -uint32_t zap_running(void); -zap_status_t zap_channel_complete_state(zap_channel_t *zchan); -zap_status_t zap_channel_init(zap_channel_t *zchan); -int zap_load_modules(void); -zap_status_t zap_unload_modules(void); -zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); -zap_status_t zap_span_start(zap_span_t *span); -int zap_load_module(const char *name); -int zap_load_module_assume(const char *name); -zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span); -char *zap_api_execute(const char *type, const char *cmd); -int zap_vasprintf(char **ret, const char *fmt, va_list ap); +OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp); +OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); +OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); +OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); +OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state); +OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); +OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); +OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen); +OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); +OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); +OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan); +OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan); +OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan); +OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); +OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token); +OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end); +OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); +OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname); +OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); +OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); +OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan); +OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void); +OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms); +OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event); +OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span); +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span); +OZ_DECLARE(zap_status_t) zap_span_close_all(void); +OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); +OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); +OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); +OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); +OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); +OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); +OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); +OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); +OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name); +OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_global_init(void); +OZ_DECLARE(zap_status_t) zap_global_destroy(void); +OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger); +OZ_DECLARE(void) zap_global_set_default_logger(int level); +OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen); +OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); +OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); +OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2); +OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky); +OZ_DECLARE(uint32_t) zap_running(void); +OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan); +OZ_DECLARE(int) zap_load_modules(void); +OZ_DECLARE(zap_status_t) zap_unload_modules(void); +OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); +OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); +OZ_DECLARE(int) zap_load_module(const char *name); +OZ_DECLARE(int) zap_load_module_assume(const char *name); +OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); +OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd); +OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h index 958d2fc8e7..2824c7938a 100644 --- a/libs/freetdm/src/include/zap_buffer.h +++ b/libs/freetdm/src/include/zap_buffer.h @@ -53,25 +53,25 @@ typedef struct zap_buffer zap_buffer_t; * \param max_len length the buffer is allowed to grow to * \return status */ -zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len); +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. */ -zap_size_t zap_buffer_len(zap_buffer_t *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. */ -zap_size_t zap_buffer_freespace(zap_buffer_t *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 */ -zap_size_t zap_buffer_inuse(zap_buffer_t *buffer); +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 @@ -79,7 +79,7 @@ zap_size_t zap_buffer_inuse(zap_buffer_t *buffer); * \param datalen amount of data to be returned * \return int ammount of data actually read */ -zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen); +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 @@ -88,13 +88,13 @@ zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) * \return int ammount of data actually read * \note Once you have read all the data from the buffer it will loop around. */ -zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen); +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) */ -void zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops); +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 @@ -102,36 +102,36 @@ void zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops); * \param datalen amount of data to be written * \return int amount of buffer used after the write, or 0 if no space available */ -zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen); +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 */ -zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen); +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 */ -void zap_buffer_zero(zap_buffer_t *buffer); +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) */ -void zap_buffer_destroy(zap_buffer_t **buffer); +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 */ -zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); +OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); /** @} */ -zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, 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: diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index f187bc516f..8639027ab7 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -27,14 +27,14 @@ typedef struct zap_mutex zap_mutex_t; typedef struct zap_thread zap_thread_t; typedef void *(*zap_thread_function_t) (zap_thread_t *, void *); -zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data); -zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); -void zap_thread_override_default_stacksize(zap_size_t size); -zap_status_t zap_mutex_create(zap_mutex_t **mutex); -zap_status_t zap_mutex_destroy(zap_mutex_t **mutex); -zap_status_t _zap_mutex_lock(zap_mutex_t *mutex); -zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex); -zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex); +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); #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index fee42a14c0..09ea5fa4ac 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -461,7 +461,7 @@ typedef zap_status_t (*zio_api_t) ZIO_API_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) zap_status_t name ZIO_CODEC_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 diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index 79875a0ade..b41a04ae42 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -83,7 +83,7 @@ static void goertzel_init(teletone_goertzel_state_t *goertzel_state, teletone_de goertzel_state->fac = tdesc->fac; } -void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, +TELETONE_API(void) teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int16_t sample_buffer[], int samples) { @@ -102,7 +102,7 @@ void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, #define teletone_goertzel_result(gs) (double)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) -void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) +TELETONE_API(void) teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate) { int i; float theta; @@ -136,7 +136,7 @@ void teletone_dtmf_detect_init (teletone_dtmf_detect_state_t *dtmf_detect_state, dtmf_detect_state->mhit = 0; } -void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) +TELETONE_API(void) teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map) { float theta = 0; int x = 0; @@ -145,7 +145,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma mt->sample_rate = 8000; } - if(!mt->min_samples) { + if (!mt->min_samples) { mt->min_samples = 102; } @@ -176,7 +176,7 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma } -int teletone_multi_tone_detect (teletone_multi_tone_t *mt, +TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples) { @@ -266,7 +266,7 @@ int teletone_multi_tone_detect (teletone_multi_tone_t *mt, } -int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples) { @@ -397,7 +397,7 @@ int teletone_dtmf_detect (teletone_dtmf_detect_state_t *dtmf_detect_state, } -int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, +TELETONE_API(int) teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, int max) { @@ -423,5 +423,5 @@ int teletone_dtmf_get (teletone_dtmf_detect_state_t *dtmf_detect_state, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 84de06853c..1d5d696af2 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -43,7 +43,7 @@ #pragma warning(disable:4706) #endif -int16_t TELETONE_SINES[SINE_TABLE_MAX] = { +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, @@ -63,7 +63,7 @@ int16_t TELETONE_SINES[SINE_TABLE_MAX] = { }; -int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) +TELETONE_API(int) teletone_set_tone(teletone_generation_session_t *ts, int index, ...) { va_list ap; int i = 0; @@ -79,7 +79,7 @@ int teletone_set_tone(teletone_generation_session_t *ts, int index, ...) } -int teletone_set_map(teletone_tone_map_t *map, ...) +TELETONE_API(int) teletone_set_map(teletone_tone_map_t *map, ...) { va_list ap; int i = 0; @@ -95,7 +95,7 @@ int teletone_set_map(teletone_tone_map_t *map, ...) } -int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_handler handler, void *user_data) +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; @@ -138,7 +138,7 @@ int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_ha return 0; } -int teletone_destroy_session(teletone_generation_session_t *ts) +TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts) { if (ts->buffer) { free(ts->buffer); @@ -167,7 +167,7 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need) return 0; } -int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map) +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; @@ -185,7 +185,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m wait = (ts->tmp_wait > -1) ? ts->tmp_wait : ts->wait; if (map->freqs[0] > 0) { - for (freqlen = 0; map->freqs[freqlen] && freqlen < TELETONE_MAX_TONES; freqlen++) { + 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); } @@ -207,7 +207,7 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m if (nvol <= TELETONE_VOL_DB_MAX && nvol >= TELETONE_VOL_DB_MIN) { vol = nvol; - for (j = 0; map->freqs[j] && j < TELETONE_MAX_TONES; j++) { + for (j = 0; j < TELETONE_MAX_TONES && map->freqs[j]; j++) { teletone_dds_state_set_tx_level(&tones[j], vol); } dc = 0; @@ -282,7 +282,7 @@ static char *my_strdup (const char *s) return (char *) memcpy (new, s, len); } -int teletone_run(teletone_generation_session_t *ts, const char *cmd) +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; @@ -460,5 +460,5 @@ int teletone_run(teletone_generation_session_t *ts, const char *cmd) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 777151d8b9..8315825ff7 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -49,7 +49,7 @@ struct zap_buffer { }; -zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len) +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; @@ -79,7 +79,7 @@ zap_status_t zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_ return ZAP_MEMERR; } -zap_size_t zap_buffer_len(zap_buffer_t *buffer) +OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer) { assert(buffer != NULL); @@ -89,7 +89,7 @@ zap_size_t zap_buffer_len(zap_buffer_t *buffer) } -zap_size_t zap_buffer_freespace(zap_buffer_t *buffer) +OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer) { assert(buffer != NULL); @@ -101,14 +101,14 @@ zap_size_t zap_buffer_freespace(zap_buffer_t *buffer) } -zap_size_t zap_buffer_inuse(zap_buffer_t *buffer) +OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer) { assert(buffer != NULL); return buffer->used; } -zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) { zap_size_t reading = 0; @@ -129,7 +129,7 @@ zap_size_t zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) return reading; } -zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) { zap_size_t reading = 0; @@ -150,12 +150,12 @@ zap_size_t zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) return buffer->used; } -void zap_buffer_set_loops(zap_buffer_t *buffer, int loops) +OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int loops) { buffer->loops = loops; } -zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen) +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) { @@ -170,7 +170,7 @@ zap_size_t zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t dat return len; } -zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) { zap_size_t reading = 0; @@ -195,7 +195,7 @@ zap_size_t zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) return reading; } -zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen) +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; @@ -258,7 +258,7 @@ zap_size_t zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t d return buffer->used; } -void zap_buffer_zero(zap_buffer_t *buffer) +OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer) { assert(buffer != NULL); assert(buffer->data != NULL); @@ -268,7 +268,7 @@ void zap_buffer_zero(zap_buffer_t *buffer) buffer->head = buffer->data; } -zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen) +OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen) { zap_size_t w; @@ -280,7 +280,7 @@ zap_size_t zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t return w; } -void zap_buffer_destroy(zap_buffer_t **buffer) +OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer) { if (*buffer) { free((*buffer)->data); diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/zap_callerid.c index 967b80a40c..7a6e658261 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/zap_callerid.c @@ -37,7 +37,7 @@ static void fsk_byte_handler (void *x, int data) } } -zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen) +OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen) { memset(state, 0, sizeof(*state)); state->buf = data; @@ -47,7 +47,7 @@ zap_status_t zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint3 return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number) +OZ_DECLARE(zap_status_t) zap_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); @@ -61,7 +61,7 @@ zap_status_t zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date return ZAP_SUCCESS; } -zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen) +OZ_DECLARE(zap_status_t) zap_fsk_data_add_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; @@ -72,7 +72,7 @@ zap_status_t zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t } -zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) +OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) { uint32_t i; uint8_t check = 0; @@ -93,7 +93,7 @@ zap_status_t zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) } -zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) +OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) { zap_size_t i; @@ -146,7 +146,7 @@ zap_status_t zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, c return ZAP_FAIL; } -zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_size_t samples) +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; @@ -166,14 +166,14 @@ zap_status_t zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_ return ZAP_SUCCESS; } -zap_status_t zap_fsk_demod_destroy(zap_fsk_data_state_t *state) +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; } -int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_size_t bufsize) +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; @@ -199,7 +199,7 @@ int zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_ return ZAP_SUCCESS; } -zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen) +OZ_DECLARE(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; @@ -217,7 +217,7 @@ zap_size_t zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t } -int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits) +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; @@ -237,7 +237,7 @@ int32_t zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, } -void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) +OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) { uint32_t i = 0; zap_size_t r = 0; @@ -258,7 +258,7 @@ void zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) } -void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) +OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) { zap_size_t r = 0; int8_t bit = 0; @@ -275,7 +275,7 @@ void zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) } -zap_status_t zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, +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, diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a9f6e57fa8..e10928a427 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -63,7 +63,7 @@ static void time_end(void) time_is_init = 0; } -zap_time_t zap_current_time_in_ms(void) +OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void) { #ifdef WIN32 return timeGetTime(); @@ -175,9 +175,9 @@ static void default_logger(const char *file, const char *func, int line, int lev } -zap_logger_t zap_log = null_logger; +OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; -void zap_global_set_logger(zap_logger_t logger) +OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger) { if (logger) { zap_log = logger; @@ -186,7 +186,7 @@ void zap_global_set_logger(zap_logger_t logger) } } -void zap_global_set_default_logger(int level) +OZ_DECLARE(void) zap_global_set_default_logger(int level) { if (level < 0 || level > 7) { level = 7; @@ -196,12 +196,12 @@ void zap_global_set_default_logger(int level) zap_log_level = level; } -int zap_hash_equalkeys(void *k1, void *k2) +OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2) { return strcmp((char *) k1, (char *) k2) ? 0 : 1; } -uint32_t zap_hash_hashfromstring(void *ky) +OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky) { unsigned char *str = (unsigned char *) ky; uint32_t hash = 0; @@ -270,7 +270,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) -zap_status_t zap_channel_get_alarms(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -304,7 +304,7 @@ zap_status_t zap_channel_get_alarms(zap_channel_t *zchan) return status; } -zap_status_t zap_span_create(zap_io_interface_t *zio, zap_span_t **span) +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span) { zap_span_t *new_span = NULL; zap_status_t status = ZAP_FAIL; @@ -343,7 +343,7 @@ done: return status; } -zap_status_t zap_span_close_all(void) +OZ_DECLARE(zap_status_t) zap_span_close_all(void) { zap_span_t *span; uint32_t i, j; @@ -362,7 +362,7 @@ zap_status_t zap_span_close_all(void) return i ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) +OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname) { zap_config_t cfg; char *var, *val; @@ -428,7 +428,7 @@ zap_status_t zap_span_load_tones(zap_span_t *span, const char *mapname) } -zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) +OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *new_chan = span->channels[++span->chan_count]; @@ -473,7 +473,7 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha return ZAP_FAIL; } -zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span) +OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span) { zap_status_t status = ZAP_FAIL; @@ -486,7 +486,7 @@ zap_status_t zap_span_find_by_name(const char *name, zap_span_t **span) return status; } -zap_status_t zap_span_find(uint32_t id, zap_span_t **span) +OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span) { zap_span_t *fspan; @@ -508,7 +508,7 @@ zap_status_t zap_span_find(uint32_t id, zap_span_t **span) } -zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) +OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) { zap_mutex_lock(span->mutex); span->event_callback = event_callback; @@ -517,7 +517,7 @@ zap_status_t zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_ } -zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) +OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms) { assert(span->zio != NULL); @@ -530,7 +530,7 @@ zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms) return ZAP_NOTIMPL; } -zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event) +OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event) { assert(span->zio != NULL); @@ -550,7 +550,7 @@ static zap_status_t zchan_fsk_write_sample(int16_t *buf, zap_size_t buflen, void return ZAP_SUCCESS; } -zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) +OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) { struct zap_fsk_modulator fsk_trans; @@ -573,7 +573,7 @@ zap_status_t zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_ } -zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) +OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) { zap_mutex_lock(zchan->mutex); zchan->event_callback = event_callback; @@ -581,7 +581,7 @@ zap_status_t zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t return ZAP_SUCCESS; } -zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token) +OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token) { zap_status_t status = ZAP_FAIL; @@ -610,7 +610,7 @@ zap_status_t zap_channel_clear_token(zap_channel_t *zchan, const char *token) return status; } -void zap_channel_rotate_tokens(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) { if (zchan->token_count) { memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); @@ -619,7 +619,7 @@ void zap_channel_rotate_tokens(zap_channel_t *zchan) } } -zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) +OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end) { zap_status_t status = ZAP_FAIL; @@ -640,7 +640,7 @@ zap_status_t zap_channel_add_token(zap_channel_t *zchan, char *token, int end) } -zap_status_t zap_channel_complete_state(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan) { zap_channel_state_t state = zchan->state; @@ -704,7 +704,7 @@ static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, return ok; } -zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) +OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) { int ok = 1; @@ -830,7 +830,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta return ok ? ZAP_SUCCESS : ZAP_FAIL; } -zap_status_t zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -997,7 +997,7 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_init(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan) { if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { @@ -1008,7 +1008,7 @@ zap_status_t zap_channel_init(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_open_chan(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -1039,7 +1039,7 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan) return status; } -zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) { zap_channel_t *check; zap_status_t status = ZAP_FAIL; @@ -1089,7 +1089,7 @@ zap_status_t zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t return status; } -zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) { zap_status_t status; @@ -1107,7 +1107,7 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan) return ZAP_FAIL; } -zap_status_t zap_channel_done(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) { assert(zchan != NULL); @@ -1134,7 +1134,7 @@ zap_status_t zap_channel_done(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_use(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan) { assert(zchan != NULL); @@ -1144,7 +1144,7 @@ zap_status_t zap_channel_use(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_close(zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan) { zap_channel_t *check; zap_status_t status = ZAP_FAIL; @@ -1206,7 +1206,7 @@ static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) +OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) { zap_status_t status = ZAP_FAIL; @@ -1467,7 +1467,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } -zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) +OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) { assert(zchan != NULL); assert(zchan->zio != NULL); @@ -1617,17 +1617,17 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) /******************************/ -void zap_channel_clear_detected_tones(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan) { memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); } -void zap_channel_clear_needed_tones(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan) { memset(zchan->needed_tones, 0, sizeof(zchan->needed_tones[0]) * ZAP_TONEMAP_INVALID); } -zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) +OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) { zap_size_t bytes = 0; @@ -1648,7 +1648,7 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t return bytes; } -void zap_channel_flush_dtmf(zap_channel_t *zchan) +OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan) { if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { zap_mutex_lock(zchan->mutex); @@ -1657,7 +1657,7 @@ void zap_channel_flush_dtmf(zap_channel_t *zchan) } } -zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) +OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) { zap_status_t status; register zap_size_t len, inuse; @@ -1785,7 +1785,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) -zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) +OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; @@ -1983,7 +1983,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data } -zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) +OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) { zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; @@ -2042,7 +2042,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data return status; } -zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) +OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan) { if(zchan->variable_hash) { hashtable_destroy(zchan->variable_hash); @@ -2055,7 +2055,7 @@ zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) return ZAP_SUCCESS; } -zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) +OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) { char *t_name = 0, *t_val = 0; @@ -2073,7 +2073,7 @@ zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, con return ZAP_FAIL; } -const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name) +OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name) { if(!zchan->variable_hash || !var_name) { @@ -2087,7 +2087,7 @@ static struct { } interfaces; -char *zap_api_execute(const char *type, const char *cmd) +OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd) { zap_io_interface_t *zio = NULL; char *dup = NULL, *p; @@ -2351,7 +2351,7 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } -int zap_load_module(const char *name) +OZ_DECLARE(int) zap_load_module(const char *name) { zap_dso_lib_t lib; int count = 0, x = 0; @@ -2445,7 +2445,7 @@ int zap_load_module(const char *name) return count; } -int zap_load_module_assume(const char *name) +OZ_DECLARE(int) zap_load_module_assume(const char *name) { char buf[256] = ""; @@ -2453,7 +2453,7 @@ int zap_load_module_assume(const char *name) return zap_load_module(buf); } -int zap_load_modules(void) +OZ_DECLARE(int) zap_load_modules(void) { char cfg_name[] = "modules.conf"; zap_config_t cfg; @@ -2475,7 +2475,7 @@ int zap_load_modules(void) return count; } -zap_status_t zap_unload_modules(void) +OZ_DECLARE(zap_status_t) zap_unload_modules(void) { zap_hash_iterator_t *i; zap_dso_lib_t lib; @@ -2520,7 +2520,7 @@ zap_status_t zap_unload_modules(void) return ZAP_SUCCESS; } -zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) +OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) { zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_status_t status = ZAP_FAIL; @@ -2545,7 +2545,7 @@ zap_status_t zap_configure_span(const char *type, zap_span_t *span, zio_signal_c return status; } -zap_status_t zap_span_start(zap_span_t *span) +OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) { if (span->start) { return span->start(span); @@ -2555,7 +2555,7 @@ zap_status_t zap_span_start(zap_span_t *span) } -zap_status_t zap_global_init(void) +OZ_DECLARE(zap_status_t) zap_global_init(void) { int modcount; @@ -2584,13 +2584,13 @@ zap_status_t zap_global_init(void) return ZAP_FAIL; } -uint32_t zap_running(void) +OZ_DECLARE(uint32_t) zap_running(void) { return globals.running; } -zap_status_t zap_global_destroy(void) +OZ_DECLARE(zap_status_t) zap_global_destroy(void) { unsigned int i,j; time_end(); @@ -2650,7 +2650,7 @@ zap_status_t zap_global_destroy(void) } -uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) +OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen) { int argc; char *ptr; @@ -2707,7 +2707,7 @@ uint32_t zap_separate_string(char *buf, char delim, char **array, int arraylen) return argc; } -void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) +OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) { memset(bsp, 0, sizeof(*bsp)); bsp->data = data; @@ -2725,7 +2725,7 @@ void zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, z } -int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) +OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp) { int8_t bit = -1; @@ -2771,7 +2771,7 @@ int8_t zap_bitstream_get_bit(zap_bitstream_t *bsp) return bit; } -void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) +OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) { char *bp = buf; uint8_t *byte = data; @@ -2794,7 +2794,7 @@ void print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) } -void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) +OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) { zap_bitstream_t bs; int j = 0, c = 0; @@ -2823,7 +2823,7 @@ void print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t -zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) { zap_size_t need = handle->data_len + datalen; @@ -2847,7 +2847,7 @@ zap_status_t zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t * return ZAP_SUCCESS; } -int zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ +OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ { #ifdef HAVE_VASPRINTF return vasprintf(ret, fmt, ap); @@ -2883,7 +2883,7 @@ int zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_a #endif } -zap_status_t zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) +OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) { va_list ap; char *buf = handle->data; diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index abeaa1f9b5..2dc4763068 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -62,7 +62,7 @@ struct zap_thread { zap_size_t thread_default_stacksize = 0; -void zap_thread_override_default_stacksize(zap_size_t size) +OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size) { thread_default_stacksize = size; } @@ -80,12 +80,12 @@ static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) return exit_val; } -zap_status_t zap_thread_create_detached(zap_thread_function_t func, void *data) +OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data) { return zap_thread_create_detached_ex(func, data, thread_default_stacksize); } -zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) +OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) { zap_thread_t *thread = NULL; zap_status_t status = ZAP_FAIL; @@ -132,7 +132,7 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat } -zap_status_t zap_mutex_create(zap_mutex_t **mutex) +OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex) { zap_status_t status = ZAP_FAIL; #ifndef WIN32 @@ -170,7 +170,7 @@ zap_status_t zap_mutex_create(zap_mutex_t **mutex) return status; } -zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) +OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex) { zap_mutex_t *mp = *mutex; *mutex = NULL; @@ -187,7 +187,7 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex) return ZAP_SUCCESS; } -zap_status_t _zap_mutex_lock(zap_mutex_t *mutex) +OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); @@ -198,7 +198,7 @@ zap_status_t _zap_mutex_lock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex) +OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) @@ -210,7 +210,7 @@ zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex) return ZAP_SUCCESS; } -zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex) +OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); From 4a39698133f073ceed1976c8742c238ac264cf9d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 17:42:49 +0000 Subject: [PATCH 1331/1766] cleanup msvc build and fix msvc build warnings git-svn-id: http://svn.openzap.org/svn/openzap/trunk@689 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../mod_openzap/mod_openzap.2005.vcproj | 14 ++++++++++---- .../mod_openzap/mod_openzap.2008.vcproj | 4 ++-- .../msvc/testanalog/testanalog.2008.vcproj | 2 -- .../openzap/msvc/testisdn/testisdn.2008.vcproj | 2 -- .../ozmod_analog/ozmod_analog.2005.vcproj | 14 +++++++++++--- .../ozmod_analog/ozmod_analog.2008.vcproj | 8 +++++--- .../ozmod_analog_em.2005.vcproj | 8 +++++--- .../ozmod_analog_em.2008.vcproj | 8 +++++--- .../ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj | 18 +++++++++++++----- .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 12 +++++++----- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 9 +++++---- libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 2 +- 12 files changed, 64 insertions(+), 37 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.2005.vcproj b/libs/openzap/mod_openzap/mod_openzap.2005.vcproj index 800fea482c..959115d3d8 100644 --- a/libs/openzap/mod_openzap/mod_openzap.2005.vcproj +++ b/libs/openzap/mod_openzap/mod_openzap.2005.vcproj @@ -49,7 +49,7 @@ UsePrecompiledHeader="0" WarningLevel="4" WarnAsError="true" - Detect64BitPortabilityProblems="true" + Detect64BitPortabilityProblems="false" DebugInformationFormat="3" /> + @@ -120,13 +123,13 @@ /> + diff --git a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj index 68be586a01..fca3f9b9d7 100644 --- a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj +++ b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj @@ -123,7 +123,7 @@ /> + @@ -118,8 +122,9 @@ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OZMOD_ANALOG_EXPORTS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" - UsePrecompiledHeader="2" - WarningLevel="3" + UsePrecompiledHeader="0" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="3" /> + diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj index 1fb02161f1..2a07fd9dc6 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -47,7 +47,8 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="4" /> + @@ -115,11 +119,12 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\..\isdn\include;..\..\include" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS;_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" - UsePrecompiledHeader="2" - WarningLevel="3" + UsePrecompiledHeader="0" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="3" /> + diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj index 77f3bb6f46..de6f1718b1 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -42,12 +42,13 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\..\isdn\include;..\..\include" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="4" /> signal_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; - int chan_id = 0; + uint32_t chan_id = 0; int chan_hunt = 0; zap_channel_t *zchan = NULL; zap_caller_data_t *caller_data = NULL; @@ -718,7 +718,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * Channel selection for incoming calls: */ if (ZAP_SPAN_IS_NT(span) && chan_hunt) { - int x; + uint32_t x; /* * In NT-mode with channel selection "any", @@ -1457,9 +1457,10 @@ 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; + teletone_generation_session_t ts = {0}; unsigned char frame[1024]; - int x, interval; + uint32_t x; + int interval = 0; int offset = 0; zap_log(ZAP_LOG_DEBUG, "ISDN tones thread starting.\n"); diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index 14b2731db5..f33a9b211f 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -72,7 +72,7 @@ typedef struct zap_isdn_data zap_isdn_data_t; /* b-channel private data */ struct zap_isdn_bchan_data { - int32_t digit_timeout; + L2ULONG digit_timeout; }; typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; From 1a87e3b3c07cca4151ba3d967e3ad7d713f70d97 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 17:42:49 +0000 Subject: [PATCH 1332/1766] cleanup msvc build and fix msvc build warnings git-svn-id: http://svn.openzap.org/svn/openzap/trunk@689 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../mod_openzap/mod_openzap.2005.vcproj | 14 ++++++++++---- .../mod_openzap/mod_openzap.2008.vcproj | 4 ++-- .../msvc/testanalog/testanalog.2008.vcproj | 2 -- .../freetdm/msvc/testisdn/testisdn.2008.vcproj | 2 -- .../ozmod_analog/ozmod_analog.2005.vcproj | 14 +++++++++++--- .../ozmod_analog/ozmod_analog.2008.vcproj | 8 +++++--- .../ozmod_analog_em.2005.vcproj | 8 +++++--- .../ozmod_analog_em.2008.vcproj | 8 +++++--- .../ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj | 18 +++++++++++++----- .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 12 +++++++----- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 9 +++++---- libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h | 2 +- 12 files changed, 64 insertions(+), 37 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj b/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj index 800fea482c..959115d3d8 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj +++ b/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj @@ -49,7 +49,7 @@ UsePrecompiledHeader="0" WarningLevel="4" WarnAsError="true" - Detect64BitPortabilityProblems="true" + Detect64BitPortabilityProblems="false" DebugInformationFormat="3" /> + @@ -120,13 +123,13 @@ /> + diff --git a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj index 68be586a01..fca3f9b9d7 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj +++ b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj @@ -123,7 +123,7 @@ /> + @@ -118,8 +122,9 @@ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OZMOD_ANALOG_EXPORTS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" - UsePrecompiledHeader="2" - WarningLevel="3" + UsePrecompiledHeader="0" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="3" /> + diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj index 1fb02161f1..2a07fd9dc6 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -47,7 +47,8 @@ BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="4" /> + @@ -115,11 +119,12 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\..\isdn\include;..\..\include" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS;_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" - UsePrecompiledHeader="2" - WarningLevel="3" + UsePrecompiledHeader="0" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="3" /> + diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj index 77f3bb6f46..de6f1718b1 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -42,12 +42,13 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\..\isdn\include;..\..\include" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;OZMOD_ISDN_EXPORTS;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="4" + WarnAsError="true" DebugInformationFormat="4" /> signal_data; Q931mes_Generic *gen = (Q931mes_Generic *) msg; - int chan_id = 0; + uint32_t chan_id = 0; int chan_hunt = 0; zap_channel_t *zchan = NULL; zap_caller_data_t *caller_data = NULL; @@ -718,7 +718,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * Channel selection for incoming calls: */ if (ZAP_SPAN_IS_NT(span) && chan_hunt) { - int x; + uint32_t x; /* * In NT-mode with channel selection "any", @@ -1457,9 +1457,10 @@ 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; + teletone_generation_session_t ts = {0}; unsigned char frame[1024]; - int x, interval; + uint32_t x; + int interval = 0; int offset = 0; zap_log(ZAP_LOG_DEBUG, "ISDN tones thread starting.\n"); diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index 14b2731db5..f33a9b211f 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -72,7 +72,7 @@ typedef struct zap_isdn_data zap_isdn_data_t; /* b-channel private data */ struct zap_isdn_bchan_data { - int32_t digit_timeout; + L2ULONG digit_timeout; }; typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; From 095094ab9d6d1070ab7a2c4701ae06db2c6fdfd3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 20:07:22 +0000 Subject: [PATCH 1333/1766] src/ozmod/ozmod_isdn/ozmod_isdn.c:1460: warning: missing braces around initializer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@691 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 885c4fd9dc..975de0b924 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1457,7 +1457,7 @@ 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}; + teletone_generation_session_t ts = {{0}}; unsigned char frame[1024]; uint32_t x; int interval = 0; From 645e7e77e325c4c2a8010bf2cf3eaf852b14146a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 20:07:22 +0000 Subject: [PATCH 1334/1766] src/ozmod/ozmod_isdn/ozmod_isdn.c:1460: warning: missing braces around initializer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@691 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 885c4fd9dc..975de0b924 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1457,7 +1457,7 @@ 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}; + teletone_generation_session_t ts = {{0}}; unsigned char frame[1024]; uint32_t x; int interval = 0; From 2dcc9f11c8ee9a1d880095eef76371ee1efec1cb Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 20:09:50 +0000 Subject: [PATCH 1335/1766] src/ozmod/ozmod_isdn/ozmod_isdn.c:1460: warning: missing braces around initializer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@692 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 975de0b924..12aaeea02b 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1457,7 +1457,7 @@ 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}}; + teletone_generation_session_t ts = {{{{0}}}}; unsigned char frame[1024]; uint32_t x; int interval = 0; From 1a7fc3bf61f1fd098f4ad2bc18ccdda5dba14416 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Mar 2009 20:09:50 +0000 Subject: [PATCH 1336/1766] src/ozmod/ozmod_isdn/ozmod_isdn.c:1460: warning: missing braces around initializer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@692 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 975de0b924..12aaeea02b 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1457,7 +1457,7 @@ 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}}; + teletone_generation_session_t ts = {{{{0}}}}; unsigned char frame[1024]; uint32_t x; int interval = 0; From f258a0f975336ae888626d13881054d3cb0cef43 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Mar 2009 20:56:38 +0000 Subject: [PATCH 1337/1766] fix unclean shutdown git-svn-id: http://svn.openzap.org/svn/openzap/trunk@693 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_types.h | 5 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 24 +++-- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 10 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 96 ++++++++++++------- libs/openzap/src/zap_io.c | 15 ++- 6 files changed, 98 insertions(+), 53 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index ed4308be07..88fd998b43 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -543,6 +543,7 @@ struct zap_span { zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; zap_span_start_t start; + zap_span_stop_t stop; void *mod_data; char *type; char *dtmf_hangup; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 09ea5fa4ac..e5218ca4b8 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -282,7 +282,9 @@ 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_SUSPENDED = (1 << 3), + ZAP_SPAN_IN_THREAD = (1 << 4), + ZAP_SPAN_STOP_THREAD = (1 << 5) } zap_span_flag_t; typedef enum { @@ -529,6 +531,7 @@ 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, diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index 1220a93a77..ce38d8ea76 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -98,7 +98,8 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = { {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"} + {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"}, + {20, LPWRAP_PRI_EVENT_TIME_CHECK, "TIME_CHECK"} }; #define LINE "--------------------------------------------------------------------------------" @@ -114,8 +115,8 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) zap_size_t len = buflen; int res; - if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + if (zap_channel_read(spri->dchan, buf, &len) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); zap_clear_flag(spri, LPWRAP_PRI_READY); return -1; } @@ -134,8 +135,8 @@ 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->zdchan, buf, buflen, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + 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; } @@ -146,15 +147,15 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) return (int) buflen; } -int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug) +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->zdchan = dchan; + spri->dchan = dchan; - if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){ + if ((spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){ spri->span = span; pri_set_debug(spri->pri, debug); ret = 0; @@ -203,6 +204,13 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) event = NULL; if (!sel) { + if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] ? + spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) { + if (handler(spri, LPWRAP_PRI_EVENT_TIME_CHECK, NULL) < 0) { + return -1; + } + } + 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)) { diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h index 8ed6ab016f..5137ee4190 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -59,7 +59,8 @@ typedef enum { 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 + LPWRAP_PRI_EVENT_IO_FAIL = 19, + LPWRAP_PRI_EVENT_TIME_CHECK = 20 } lpwrap_pri_event_t; typedef enum { @@ -92,13 +93,12 @@ typedef int (*loop_handler)(struct lpwrap_pri *); struct lpwrap_pri { struct pri *pri; - int span; - int dchan; + zap_span_t *span; + zap_channel_t *dchan; unsigned int flags; void *private_info; event_handler eventmap[MAX_EVENT+1]; loop_handler on_loop; - zap_channel_t *zdchan; }; typedef struct lpwrap_pri lpwrap_pri_t; @@ -115,7 +115,7 @@ struct lpwrap_pri_event_list { const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id); int lpwrap_one_loop(struct lpwrap_pri *spri); -int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug); +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 index a3f4a6a205..494751a7ab 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -99,7 +99,7 @@ static int parse_debug(const char *in) if (strstr(in, "q931_dump")) { flags |= PRI_DEBUG_Q931_DUMP; } - + if (strstr(in, "q931_state")) { flags |= PRI_DEBUG_Q931_STATE; } @@ -501,7 +501,7 @@ static __inline__ void check_state(zap_span_t *span) -static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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); @@ -512,7 +512,7 @@ static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event return 0; } -static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -521,20 +521,20 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even if (zchan) { call = (q931_call *) zchan->call_data; - zap_log(ZAP_LOG_DEBUG, "-- Hangup on channel %d:%d\n", spri->span, pevent->hangup.channel); + 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, + 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; } -static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -542,10 +542,10 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even zchan = span->channels[pevent->answer.channel]; if (zchan) { - zap_log(ZAP_LOG_DEBUG, "-- Answer on channel %d:%d\n", spri->span, pevent->answer.channel); + 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, pevent->answer.channel, zchan->chan_id); + 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); } @@ -553,7 +553,7 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even } -static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -561,10 +561,10 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve zchan = span->channels[pevent->proceeding.channel]; if (zchan) { - zap_log(ZAP_LOG_DEBUG, "-- Proceeding on channel %d:%d\n", spri->span, pevent->proceeding.channel); + 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, + 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); } @@ -572,7 +572,7 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve } -static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -580,10 +580,10 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve zchan = span->channels[pevent->ringing.channel]; if (zchan) { - zap_log(ZAP_LOG_DEBUG, "-- Ringing on channel %d:%d\n", spri->span, pevent->ringing.channel); + zap_log(ZAP_LOG_DEBUG, "-- Ringing on channel %d:%d\n", spri->span->span_id, pevent->ringing.channel); 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, + 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); } @@ -601,19 +601,19 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event 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, pevent->ring.channel); + 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, pevent->ring.channel); + 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, pevent->ring.channel, + 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)); @@ -651,12 +651,12 @@ static int check_flags(lpwrap_pri_t *spri) return 0; } -static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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, pevent->restart.channel); + zap_log(ZAP_LOG_NOTICE, "-- Restarting %d:%d\n", spri->span->span_id, pevent->restart.channel); zchan = span->channels[pevent->restart.channel]; @@ -673,45 +673,55 @@ static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve return 0; } -static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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); + zap_log(ZAP_LOG_INFO, "Span %d D-Chan UP!\n", spri->span->span_id); zap_set_flag(spri, LPWRAP_PRI_READY); } return 0; } -static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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); + zap_log(ZAP_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span->span_id); zap_clear_flag(spri, LPWRAP_PRI_READY); } return 0; } -static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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, event_type, lpwrap_pri_event_str(event_type)); + 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; } -static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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, event_type, lpwrap_pri_event_str(event_type)); + 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; } +static int on_time_check(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent) +{ + + if (!zap_running() || zap_test_flag(spri->span, ZAP_SPAN_STOP_THREAD)) { + return -1; + } + + return 0; +} + static void *zap_libpri_run(zap_thread_t *me, void *obj) { @@ -719,7 +729,9 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) zap_libpri_data_t *isdn_data = span->signal_data; int x, i; - while(zap_running()) { + zap_set_flag(span, ZAP_SPAN_IN_THREAD); + + while(zap_running() && !zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { x = 0; for(i = 1; i <= span->chan_count; i++) { @@ -734,12 +746,12 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) } - if (x && lpwrap_init_pri(&isdn_data->spri, - span->span_id, // span - isdn_data->dchan, // dchan - isdn_data->pswitch, - isdn_data->node, - isdn_data->debug) < 0) { + if (!x || 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 { @@ -756,6 +768,7 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); + LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_TIME_CHECK, on_time_check); isdn_data->spri.on_loop = check_flags; @@ -765,14 +778,28 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) zap_channel_close(&isdn_data->dchan); } + 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); zap_sleep(5000); } + zap_clear_flag(span, ZAP_SPAN_IN_THREAD); return NULL; } +static zap_status_t zap_libpri_stop(zap_span_t *span) +{ + zap_set_flag(span, ZAP_SPAN_STOP_THREAD); + while(zap_test_flag(span, ZAP_SPAN_IN_THREAD)) { + zap_sleep(100); + } + return ZAP_SUCCESS; +} + static zap_status_t zap_libpri_start(zap_span_t *span) { zap_status_t ret; @@ -934,6 +961,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->start = zap_libpri_start; + span->stop = zap_libpri_stop; isdn_data->sig_cb = sig_cb; //isdn_data->dchans[0] = dchans[0]; //isdn_data->dchans[1] = dchans[1]; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index e10928a427..8b201853e5 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -219,11 +219,16 @@ static zap_status_t zap_span_destroy(zap_span_t *span) { zap_status_t status = ZAP_FAIL; - if (zap_test_flag(span, ZAP_SPAN_CONFIGURED) && span->zio && span->zio->span_destroy) { - zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); - status = span->zio->span_destroy(span); - zap_safe_free(span->type); - zap_safe_free(span->dtmf_hangup); + if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + if (span->stop) { + span->stop(span); + } + if (span->zio && span->zio->span_destroy) { + zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); + status = span->zio->span_destroy(span); + zap_safe_free(span->type); + zap_safe_free(span->dtmf_hangup); + } } return status; From 2dbf54237732ede557b3625a6d34819416d71ca8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 10 Mar 2009 20:56:38 +0000 Subject: [PATCH 1338/1766] fix unclean shutdown git-svn-id: http://svn.openzap.org/svn/openzap/trunk@693 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 5 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 24 +++-- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 10 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 96 ++++++++++++------- libs/freetdm/src/zap_io.c | 15 ++- 6 files changed, 98 insertions(+), 53 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ed4308be07..88fd998b43 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -543,6 +543,7 @@ struct zap_span { zio_channel_outgoing_call_t outgoing_call; zio_channel_request_t channel_request; zap_span_start_t start; + zap_span_stop_t stop; void *mod_data; char *type; char *dtmf_hangup; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 09ea5fa4ac..e5218ca4b8 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -282,7 +282,9 @@ 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_SUSPENDED = (1 << 3), + ZAP_SPAN_IN_THREAD = (1 << 4), + ZAP_SPAN_STOP_THREAD = (1 << 5) } zap_span_flag_t; typedef enum { @@ -529,6 +531,7 @@ 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, diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index 1220a93a77..ce38d8ea76 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -98,7 +98,8 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = { {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"} + {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"}, + {20, LPWRAP_PRI_EVENT_TIME_CHECK, "TIME_CHECK"} }; #define LINE "--------------------------------------------------------------------------------" @@ -114,8 +115,8 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) zap_size_t len = buflen; int res; - if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + if (zap_channel_read(spri->dchan, buf, &len) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); zap_clear_flag(spri, LPWRAP_PRI_READY); return -1; } @@ -134,8 +135,8 @@ 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->zdchan, buf, buflen, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span, spri->zdchan->last_error); + 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; } @@ -146,15 +147,15 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) return (int) buflen; } -int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug) +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->zdchan = dchan; + spri->dchan = dchan; - if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){ + if ((spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){ spri->span = span; pri_set_debug(spri->pri, debug); ret = 0; @@ -203,6 +204,13 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) event = NULL; if (!sel) { + if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] ? + spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) { + if (handler(spri, LPWRAP_PRI_EVENT_TIME_CHECK, NULL) < 0) { + return -1; + } + } + 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)) { diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h index 8ed6ab016f..5137ee4190 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -59,7 +59,8 @@ typedef enum { 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 + LPWRAP_PRI_EVENT_IO_FAIL = 19, + LPWRAP_PRI_EVENT_TIME_CHECK = 20 } lpwrap_pri_event_t; typedef enum { @@ -92,13 +93,12 @@ typedef int (*loop_handler)(struct lpwrap_pri *); struct lpwrap_pri { struct pri *pri; - int span; - int dchan; + zap_span_t *span; + zap_channel_t *dchan; unsigned int flags; void *private_info; event_handler eventmap[MAX_EVENT+1]; loop_handler on_loop; - zap_channel_t *zdchan; }; typedef struct lpwrap_pri lpwrap_pri_t; @@ -115,7 +115,7 @@ struct lpwrap_pri_event_list { const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id); int lpwrap_one_loop(struct lpwrap_pri *spri); -int lpwrap_init_pri(struct lpwrap_pri *spri, int span, zap_channel_t *dchan, int swtype, int node, int debug); +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/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index a3f4a6a205..494751a7ab 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -99,7 +99,7 @@ static int parse_debug(const char *in) if (strstr(in, "q931_dump")) { flags |= PRI_DEBUG_Q931_DUMP; } - + if (strstr(in, "q931_state")) { flags |= PRI_DEBUG_Q931_STATE; } @@ -501,7 +501,7 @@ static __inline__ void check_state(zap_span_t *span) -static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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); @@ -512,7 +512,7 @@ static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event return 0; } -static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -521,20 +521,20 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even if (zchan) { call = (q931_call *) zchan->call_data; - zap_log(ZAP_LOG_DEBUG, "-- Hangup on channel %d:%d\n", spri->span, pevent->hangup.channel); + 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, + 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; } -static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -542,10 +542,10 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even zchan = span->channels[pevent->answer.channel]; if (zchan) { - zap_log(ZAP_LOG_DEBUG, "-- Answer on channel %d:%d\n", spri->span, pevent->answer.channel); + 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, pevent->answer.channel, zchan->chan_id); + 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); } @@ -553,7 +553,7 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even } -static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -561,10 +561,10 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve zchan = span->channels[pevent->proceeding.channel]; if (zchan) { - zap_log(ZAP_LOG_DEBUG, "-- Proceeding on channel %d:%d\n", spri->span, pevent->proceeding.channel); + 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, + 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); } @@ -572,7 +572,7 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve } -static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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; @@ -580,10 +580,10 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve zchan = span->channels[pevent->ringing.channel]; if (zchan) { - zap_log(ZAP_LOG_DEBUG, "-- Ringing on channel %d:%d\n", spri->span, pevent->ringing.channel); + zap_log(ZAP_LOG_DEBUG, "-- Ringing on channel %d:%d\n", spri->span->span_id, pevent->ringing.channel); 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, + 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); } @@ -601,19 +601,19 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event 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, pevent->ring.channel); + 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, pevent->ring.channel); + 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, pevent->ring.channel, + 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)); @@ -651,12 +651,12 @@ static int check_flags(lpwrap_pri_t *spri) return 0; } -static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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, pevent->restart.channel); + zap_log(ZAP_LOG_NOTICE, "-- Restarting %d:%d\n", spri->span->span_id, pevent->restart.channel); zchan = span->channels[pevent->restart.channel]; @@ -673,45 +673,55 @@ static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve return 0; } -static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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); + zap_log(ZAP_LOG_INFO, "Span %d D-Chan UP!\n", spri->span->span_id); zap_set_flag(spri, LPWRAP_PRI_READY); } return 0; } -static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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); + zap_log(ZAP_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span->span_id); zap_clear_flag(spri, LPWRAP_PRI_READY); } return 0; } -static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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, event_type, lpwrap_pri_event_str(event_type)); + 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; } -static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event * pevent) +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, event_type, lpwrap_pri_event_str(event_type)); + 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; } +static int on_time_check(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent) +{ + + if (!zap_running() || zap_test_flag(spri->span, ZAP_SPAN_STOP_THREAD)) { + return -1; + } + + return 0; +} + static void *zap_libpri_run(zap_thread_t *me, void *obj) { @@ -719,7 +729,9 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) zap_libpri_data_t *isdn_data = span->signal_data; int x, i; - while(zap_running()) { + zap_set_flag(span, ZAP_SPAN_IN_THREAD); + + while(zap_running() && !zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { x = 0; for(i = 1; i <= span->chan_count; i++) { @@ -734,12 +746,12 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) } - if (x && lpwrap_init_pri(&isdn_data->spri, - span->span_id, // span - isdn_data->dchan, // dchan - isdn_data->pswitch, - isdn_data->node, - isdn_data->debug) < 0) { + if (!x || 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 { @@ -756,6 +768,7 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); + LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_TIME_CHECK, on_time_check); isdn_data->spri.on_loop = check_flags; @@ -765,14 +778,28 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) zap_channel_close(&isdn_data->dchan); } + 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); zap_sleep(5000); } + zap_clear_flag(span, ZAP_SPAN_IN_THREAD); return NULL; } +static zap_status_t zap_libpri_stop(zap_span_t *span) +{ + zap_set_flag(span, ZAP_SPAN_STOP_THREAD); + while(zap_test_flag(span, ZAP_SPAN_IN_THREAD)) { + zap_sleep(100); + } + return ZAP_SUCCESS; +} + static zap_status_t zap_libpri_start(zap_span_t *span) { zap_status_t ret; @@ -934,6 +961,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->start = zap_libpri_start; + span->stop = zap_libpri_stop; isdn_data->sig_cb = sig_cb; //isdn_data->dchans[0] = dchans[0]; //isdn_data->dchans[1] = dchans[1]; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index e10928a427..8b201853e5 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -219,11 +219,16 @@ static zap_status_t zap_span_destroy(zap_span_t *span) { zap_status_t status = ZAP_FAIL; - if (zap_test_flag(span, ZAP_SPAN_CONFIGURED) && span->zio && span->zio->span_destroy) { - zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); - status = span->zio->span_destroy(span); - zap_safe_free(span->type); - zap_safe_free(span->dtmf_hangup); + if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + if (span->stop) { + span->stop(span); + } + if (span->zio && span->zio->span_destroy) { + zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); + status = span->zio->span_destroy(span); + zap_safe_free(span->type); + zap_safe_free(span->dtmf_hangup); + } } return status; From 737ce8d437d0b5f7b0b1b59eecde7df85c2aa5e6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 11 Mar 2009 02:04:18 +0000 Subject: [PATCH 1339/1766] add oz span start|stop and ozmod libpri kill to simulate loss of d channel (NEEDS TESTING) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@694 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 61 ++-- libs/openzap/src/include/openzap.h | 4 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 23 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 3 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 93 ++++-- libs/openzap/src/zap_io.c | 300 ++++++++++-------- 6 files changed, 282 insertions(+), 202 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ee4ddf5dda..1b9f96ab45 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2184,16 +2184,16 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR Usage: oz dump []\n"); goto end; } else { - uint32_t span_id, chan_id = 0; + uint32_t chan_id = 0; zap_span_t *span; - - span_id = atoi(argv[1]); - + + zap_span_find_by_name(argv[1], &span); + if (argc > 2) { chan_id = atoi(argv[2]); } - if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + if (!span) { stream->write_function(stream, "-ERR invalid span\n"); } else { if (chan_id) { @@ -2249,38 +2249,31 @@ SWITCH_STANDARD_API(oz_function) ); } } - } else if (!strcasecmp(argv[0], "bounce")) { - /* MSC testing "oz bounce" command */ - if (argc < 2) { - stream->write_function(stream, "-ERR Usage: oz bounce []\n"); + } else if (!strcasecmp(argv[0], "stop") || !strcasecmp(argv[0], "start")) { + char *span_name = argv[1]; + zap_span_t *span = NULL; + zap_status_t status; + + if (span_name) { + zap_span_find_by_name(span_name, &span); + } + + if (!span) { + stream->write_function(stream, "-ERR no span\n"); goto end; + } + + if (!strcasecmp(argv[0], "stop")) { + status = zap_span_stop(span); } else { - int32_t span_id, chan_id = 0; - zap_span_t *span; + status = zap_span_start(span); + } + + stream->write_function(stream, status == ZAP_SUCCESS ? "+OK\n" : "-ERR failure\n"); + + goto end; - span_id = atoi(argv[1]); - - if (argc > 2) { - chan_id = atoi(argv[2]); - } - - if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { - stream->write_function(stream, "-ERR invalid span\n"); - } else { - if (chan_id) { - zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); - } else { - uint32_t j; - - stream->write_function(stream, "+OK\n"); - for (j = 1; j <= span->chan_count; j++) { - zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, j); - } - - } - } - } - /*Q931ToPcap enhancement*/ + /*Q931ToPcap enhancement*/ } else if (!strcasecmp(argv[0], "q931_pcap")) { int32_t span_id = 0; zap_span_t *span; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 88fd998b43..c85233a949 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -550,6 +550,7 @@ struct zap_span { size_t dtmf_hangup_len; int suggest_chan_id; zap_state_map_t *state_map; + struct zap_span *next; }; @@ -620,7 +621,7 @@ OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void); OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms); OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event); OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span); -OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span); +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name); OZ_DECLARE(zap_status_t) zap_span_close_all(void); OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); @@ -654,6 +655,7 @@ OZ_DECLARE(int) zap_load_modules(void); OZ_DECLARE(zap_status_t) zap_unload_modules(void); OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); +OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); OZ_DECLARE(int) zap_load_module(const char *name); OZ_DECLARE(int) zap_load_module_assume(const char *name); OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index ce38d8ea76..bb7b9c3a85 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -99,7 +99,6 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = { {17, LPWRAP_PRI_EVENT_PROGRESS, "PROGRESS"}, {18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"}, {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"}, - {20, LPWRAP_PRI_EVENT_TIME_CHECK, "TIME_CHECK"} }; #define LINE "--------------------------------------------------------------------------------" @@ -125,7 +124,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) res+=2; //print_bits(buf, res-2, bb, sizeof(bb), 1, 0); - //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb); + //zap_log(ZAP_LOG_DEBUG, "READ %d\n", res-2); return res; } @@ -142,7 +141,7 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) } //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); + //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2); return (int) buflen; } @@ -156,10 +155,13 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dc spri->dchan = dchan; 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; spri->span = span; 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"); } @@ -177,7 +179,13 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) int sel; if (spri->on_loop) { - spri->on_loop(spri); + if ((sel = spri->on_loop(spri)) < 0) { + return sel; + } + } + + if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { + return -1; } FD_ZERO(&rfds); @@ -204,13 +212,6 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) event = NULL; if (!sel) { - if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] ? - spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) { - if (handler(spri, LPWRAP_PRI_EVENT_TIME_CHECK, NULL) < 0) { - return -1; - } - } - 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)) { diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h index 5137ee4190..c3832626c1 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -59,8 +59,7 @@ typedef enum { 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, - LPWRAP_PRI_EVENT_TIME_CHECK = 20 + LPWRAP_PRI_EVENT_IO_FAIL = 19 } lpwrap_pri_event_t; typedef enum { diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 494751a7ab..0693edd71c 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -131,7 +131,9 @@ static int parse_debug(const char *in) return flags; } +static zap_io_interface_t zap_libpri_interface; +static zap_status_t zap_libpri_start(zap_span_t *span); static ZIO_API_FUNCTION(zap_libpri_api) { @@ -143,14 +145,40 @@ static ZIO_API_FUNCTION(zap_libpri_api) argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } - - if (argc > 2) { - if (!strcasecmp(argv[0], "debug")) { + 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; @@ -159,6 +187,7 @@ static ZIO_API_FUNCTION(zap_libpri_api) goto done; } } + } stream->write_function(stream, "%s: -ERR invalid command.\n", __FILE__); @@ -171,8 +200,6 @@ static ZIO_API_FUNCTION(zap_libpri_api) } -static zap_io_interface_t zap_libpri_interface; - static ZIO_IO_LOAD_FUNCTION(zap_libpri_io_init) { assert(zio != NULL); @@ -190,7 +217,6 @@ static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) { pri_set_error(s_pri_error); pri_set_message(s_pri_message); - return ZAP_SUCCESS; } @@ -648,6 +674,10 @@ static int check_flags(lpwrap_pri_t *spri) check_state(span); + if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { + return -1; + } + return 0; } @@ -712,22 +742,12 @@ static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve } -static int on_time_check(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent) -{ - - if (!zap_running() || zap_test_flag(spri->span, ZAP_SPAN_STOP_THREAD)) { - return -1; - } - - return 0; -} - - 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 x, i; + int down = 0; zap_set_flag(span, ZAP_SPAN_IN_THREAD); @@ -768,8 +788,12 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); - LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_TIME_CHECK, on_time_check); - + + 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; @@ -782,30 +806,54 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) break; } - zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span); + zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span->span_id); + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + check_state(span); + check_state(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; } + 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; } 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); @@ -817,7 +865,6 @@ static zap_status_t zap_libpri_start(zap_span_t *span) } - static int str2node(char *node) { if (!strcasecmp(node, "cpe") || !strcasecmp(node, "user")) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8b201853e5..c2219d309f 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -79,9 +79,10 @@ static struct { zap_hash_t *module_hash; zap_hash_t *span_hash; zap_mutex_t *mutex; - struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1]; + zap_mutex_t *span_mutex; uint32_t span_index; uint32_t running; + zap_span_t *spans; } globals; @@ -309,7 +310,55 @@ OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) return status; } -OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span) +static void zap_span_add(zap_span_t *span) +{ + zap_span_t *sp; + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp && sp->next; sp = sp->next); + if (sp) { + sp->next = span; + } else { + globals.spans = span; + } + hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); + zap_mutex_unlock(globals.span_mutex); +} + +#if 0 +static void zap_span_del(zap_span_t *span) +{ + zap_span_t *last = NULL, *sp; + + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp; sp = sp->next) { + + if (sp == span) { + if (last) { + last->next = sp->next; + } else { + globals.spans = sp->next; + } + hashtable_remove(globals.span_hash, (void *)sp->name); + break; + } + + last = sp; + } + zap_mutex_unlock(globals.span_mutex); +} +#endif + +OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span) +{ + if (span->stop) { + span->stop(span); + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name) { zap_span_t *new_span = NULL; zap_status_t status = ZAP_FAIL; @@ -317,21 +366,16 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s assert(zio != NULL); zap_mutex_lock(globals.mutex); + if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = globals.spans[++globals.span_index]; - if (!new_span) { - if (!(new_span = malloc(sizeof(*new_span)))) { - goto done; - } - globals.spans[globals.span_index] = new_span; - } + new_span = malloc(sizeof(*new_span)); + assert(new_span); memset(new_span, 0, sizeof(*new_span)); status = zap_mutex_create(&new_span->mutex); - if (status != ZAP_SUCCESS) { - goto done; - } + assert(status == ZAP_SUCCESS); + zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = globals.span_index; + new_span->span_id = ++globals.span_index; new_span->zio = zio; zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); @@ -339,11 +383,24 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); new_span->trunk_type = ZAP_TRUNK_NONE; new_span->data_type = ZAP_TYPE_SPAN; + + zap_mutex_lock(globals.span_mutex); + if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { + zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, new_span->span_id); + name = NULL; + } + zap_mutex_unlock(globals.span_mutex); + + if (!name) { + char buf[128] = ""; + snprintf(buf, sizeof(buf), "span%d", new_span->span_id); + name = buf; + } + new_span->name = strdup(name); + zap_span_add(new_span); *span = new_span; status = ZAP_SUCCESS; } - -done: zap_mutex_unlock(globals.mutex); return status; } @@ -351,18 +408,18 @@ done: OZ_DECLARE(zap_status_t) zap_span_close_all(void) { zap_span_t *span; - uint32_t i, j; + uint32_t i = 0, j; - zap_mutex_lock(globals.mutex); - for(i = 1; i <= globals.span_index; i++) { - span = globals.spans[i]; + zap_mutex_lock(globals.span_mutex); + for (span = globals.spans; span; span = span->next) { if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { for(j = 1; j <= span->chan_count && span->channels[j]; j++) { zap_channel_destroy(span->channels[j]); + i++; } } } - zap_mutex_unlock(globals.mutex); + zap_mutex_unlock(globals.span_mutex); return i ? ZAP_SUCCESS : ZAP_FAIL; } @@ -482,26 +539,40 @@ OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **sp { zap_status_t status = ZAP_FAIL; - zap_mutex_lock(globals.mutex); - if (!zap_strlen_zero(name) && (*span = hashtable_search(globals.span_hash, (void *)name))) { - status = ZAP_SUCCESS; - } - zap_mutex_unlock(globals.mutex); + zap_mutex_lock(globals.span_mutex); + if (!zap_strlen_zero(name)) { + if ((*span = hashtable_search(globals.span_hash, (void *)name))) { + status = ZAP_SUCCESS; + } else { + int span_id = atoi(name); + zap_span_find(span_id, span); + if (*span) { + status = ZAP_SUCCESS; + } + } + } + zap_mutex_unlock(globals.span_mutex); + return status; } OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span) { - zap_span_t *fspan; + zap_span_t *fspan = NULL, *sp; if (id > ZAP_MAX_SPANS_INTERFACE) { return ZAP_FAIL; } - zap_mutex_lock(globals.mutex); - fspan = globals.spans[id]; - zap_mutex_unlock(globals.mutex); + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp; sp = sp->next) { + if (sp->span_id == id) { + fspan = sp; + break; + } + } + zap_mutex_unlock(globals.span_mutex); if (!fspan || !zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; @@ -840,122 +911,94 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; - zap_span_t *span; + zap_span_t *span = NULL; uint32_t span_max; if (span_id) { - if (span_id > globals.span_index || !globals.spans[span_id]) { + zap_span_find(span_id, &span); + + if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; } - if (globals.spans[span_id]->active_count >= globals.spans[span_id]->chan_count) { + if (span->active_count >= span->chan_count) { zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); *zchan = NULL; return ZAP_FAIL; } - if (globals.spans[span_id]->channel_request && !globals.spans[span_id]->suggest_chan_id) { - return globals.spans[span_id]->channel_request(globals.spans[span_id], 0, direction, caller_data, zchan); + if (span->channel_request && !span->suggest_chan_id) { + return span->channel_request(span, 0, direction, caller_data, zchan); } span_max = span_id; j = span_id; } else { - span_max = globals.span_index; - if (direction == ZAP_TOP_DOWN) { - j = 1; - } else { - j = span_max; - } + zap_log(ZAP_LOG_CRIT, "No span supplied\n"); + *zchan = NULL; + return ZAP_FAIL; } + zap_mutex_lock(span->mutex); + + if (direction == ZAP_TOP_DOWN) { + i = 1; + } else { + i = span->chan_count; + } + for(;;) { + if (direction == ZAP_TOP_DOWN) { - if (j > span_max) { - goto done; + if (i > span->chan_count) { + break; } } else { - if (j == 0) { - goto done; + if (i == 0) { + break; } } - - span = globals.spans[j]; - zap_mutex_lock(span->mutex); - - if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - goto next_loop; - } - - if (direction == ZAP_TOP_DOWN) { - i = 1; - } else { - i = span->chan_count; - } - - for(;;) { - - if (direction == ZAP_TOP_DOWN) { - if (i > span->chan_count) { - break; - } - } else { - if (i == 0) { - break; - } - } - if (!(check = span->channels[i])) { - status = ZAP_FAIL; + if (!(check = span->channels[i])) { + status = ZAP_FAIL; + zap_mutex_unlock(span->mutex); + goto done; + } + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && + !zap_test_flag(check, ZAP_CHANNEL_INUSE) && + !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && + check->state == ZAP_CHANNEL_STATE_DOWN + ) { + + if (span && span->channel_request) { + status = span->channel_request(span, i, direction, caller_data, zchan); zap_mutex_unlock(span->mutex); goto done; } - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && - !zap_test_flag(check, ZAP_CHANNEL_INUSE) && - !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && - check->state == ZAP_CHANNEL_STATE_DOWN - ) { - if (globals.spans[span_id] && globals.spans[span_id]->channel_request) { - status = globals.spans[span_id]->channel_request(globals.spans[span_id], i, direction, caller_data, zchan); - zap_mutex_unlock(span->mutex); - goto done; - } - - status = check->zio->open(check); + status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_INUSE); - zap_channel_open_chan(check); - *zchan = check; - zap_mutex_unlock(span->mutex); - goto done; - } - } - - if (direction == ZAP_TOP_DOWN) { - i++; - } else { - i--; + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_INUSE); + zap_channel_open_chan(check); + *zchan = check; + zap_mutex_unlock(span->mutex); + goto done; } } - next_loop: - - zap_mutex_unlock(span->mutex); - if (direction == ZAP_TOP_DOWN) { - j++; + i++; } else { - j--; + i--; } } done: - + return status; } @@ -1048,22 +1091,24 @@ OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, za { zap_channel_t *check; zap_status_t status = ZAP_FAIL; + zap_span_t *span = NULL; - zap_mutex_lock(globals.mutex); + zap_mutex_unlock(globals.mutex); + zap_span_find(span_id, &span); - if (span_id > globals.span_index || chan_id >= ZAP_MAX_CHANNELS_SPAN || !globals.spans[span_id]) { - zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); + if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED) || chan_id >= ZAP_MAX_CHANNELS_SPAN) { + zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; - goto done; + goto done; } - if (globals.spans[span_id]->channel_request) { + if (span->channel_request) { zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); *zchan = NULL; goto done; } - check = globals.spans[span_id]->channels[chan_id]; + check = span->channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { @@ -2202,25 +2247,10 @@ static zap_status_t load_config(void) continue; } - if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + if (zap_span_create(zio, &span, name) == ZAP_SUCCESS) { span->type = strdup(type); d = 0; - zap_mutex_lock(globals.mutex); - if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { - zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, span->span_id); - name = NULL; - } - - if (!name) { - char buf[128] = ""; - snprintf(buf, sizeof(buf), "span%d", span->span_id); - name = buf; - } - span->name = strdup(name); - hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); - zap_mutex_unlock(globals.mutex); - zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); } else { @@ -2576,6 +2606,7 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); + zap_mutex_create(&globals.span_mutex); modcount = zap_load_modules(); zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); @@ -2597,15 +2628,19 @@ OZ_DECLARE(uint32_t) zap_running(void) OZ_DECLARE(zap_status_t) zap_global_destroy(void) { - unsigned int i,j; + unsigned int j; + zap_span_t *sp; + time_end(); globals.running = 0; zap_span_close_all(); zap_sleep(1000); - for(i = 1; i <= globals.span_index; i++) { - zap_span_t *cur_span = globals.spans[i]; + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp;) { + zap_span_t *cur_span = sp; + sp = sp->next; if (cur_span) { if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { @@ -2630,15 +2665,17 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) zap_safe_free(cur_span->signal_data); zap_span_destroy(cur_span); } - zap_mutex_lock(globals.mutex); + hashtable_remove(globals.span_hash, (void *)cur_span->name); - zap_mutex_unlock(globals.mutex); zap_safe_free(cur_span->type); zap_safe_free(cur_span->name); free(cur_span); cur_span = NULL; } } + globals.spans = NULL; + zap_mutex_unlock(globals.span_mutex); + globals.span_index = 0; zap_unload_modules(); @@ -2649,6 +2686,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) hashtable_destroy(globals.span_hash); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); + zap_mutex_destroy(&globals.span_mutex); memset(&globals, 0, sizeof(globals)); return ZAP_SUCCESS; From c4e9f43eaf038db199bc0645d21025cbaee39cfd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 11 Mar 2009 02:04:18 +0000 Subject: [PATCH 1340/1766] add oz span start|stop and ozmod libpri kill to simulate loss of d channel (NEEDS TESTING) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@694 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 61 ++-- libs/freetdm/src/include/openzap.h | 4 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 23 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 3 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 93 ++++-- libs/freetdm/src/zap_io.c | 300 ++++++++++-------- 6 files changed, 282 insertions(+), 202 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ee4ddf5dda..1b9f96ab45 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2184,16 +2184,16 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "-ERR Usage: oz dump []\n"); goto end; } else { - uint32_t span_id, chan_id = 0; + uint32_t chan_id = 0; zap_span_t *span; - - span_id = atoi(argv[1]); - + + zap_span_find_by_name(argv[1], &span); + if (argc > 2) { chan_id = atoi(argv[2]); } - if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { + if (!span) { stream->write_function(stream, "-ERR invalid span\n"); } else { if (chan_id) { @@ -2249,38 +2249,31 @@ SWITCH_STANDARD_API(oz_function) ); } } - } else if (!strcasecmp(argv[0], "bounce")) { - /* MSC testing "oz bounce" command */ - if (argc < 2) { - stream->write_function(stream, "-ERR Usage: oz bounce []\n"); + } else if (!strcasecmp(argv[0], "stop") || !strcasecmp(argv[0], "start")) { + char *span_name = argv[1]; + zap_span_t *span = NULL; + zap_status_t status; + + if (span_name) { + zap_span_find_by_name(span_name, &span); + } + + if (!span) { + stream->write_function(stream, "-ERR no span\n"); goto end; + } + + if (!strcasecmp(argv[0], "stop")) { + status = zap_span_stop(span); } else { - int32_t span_id, chan_id = 0; - zap_span_t *span; + status = zap_span_start(span); + } + + stream->write_function(stream, status == ZAP_SUCCESS ? "+OK\n" : "-ERR failure\n"); + + goto end; - span_id = atoi(argv[1]); - - if (argc > 2) { - chan_id = atoi(argv[2]); - } - - if (!(span_id && (span = SPAN_CONFIG[span_id].span))) { - stream->write_function(stream, "-ERR invalid span\n"); - } else { - if (chan_id) { - zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, chan_id); - } else { - uint32_t j; - - stream->write_function(stream, "+OK\n"); - for (j = 1; j <= span->chan_count; j++) { - zap_log(ZAP_LOG_INFO,"Bounce span: %d, chan: %d\n", span_id, j); - } - - } - } - } - /*Q931ToPcap enhancement*/ + /*Q931ToPcap enhancement*/ } else if (!strcasecmp(argv[0], "q931_pcap")) { int32_t span_id = 0; zap_span_t *span; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 88fd998b43..c85233a949 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -550,6 +550,7 @@ struct zap_span { size_t dtmf_hangup_len; int suggest_chan_id; zap_state_map_t *state_map; + struct zap_span *next; }; @@ -620,7 +621,7 @@ OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void); OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms); OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event); OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span); -OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span); +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name); OZ_DECLARE(zap_status_t) zap_span_close_all(void); OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); @@ -654,6 +655,7 @@ OZ_DECLARE(int) zap_load_modules(void); OZ_DECLARE(zap_status_t) zap_unload_modules(void); OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); +OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); OZ_DECLARE(int) zap_load_module(const char *name); OZ_DECLARE(int) zap_load_module_assume(const char *name); OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index ce38d8ea76..bb7b9c3a85 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -99,7 +99,6 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = { {17, LPWRAP_PRI_EVENT_PROGRESS, "PROGRESS"}, {18, LPWRAP_PRI_EVENT_KEYPAD_DIGIT, "KEYPAD_DIGIT"}, {19, LPWRAP_PRI_EVENT_IO_FAIL, "IO_FAIL"}, - {20, LPWRAP_PRI_EVENT_TIME_CHECK, "TIME_CHECK"} }; #define LINE "--------------------------------------------------------------------------------" @@ -125,7 +124,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) res+=2; //print_bits(buf, res-2, bb, sizeof(bb), 1, 0); - //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb); + //zap_log(ZAP_LOG_DEBUG, "READ %d\n", res-2); return res; } @@ -142,7 +141,7 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) } //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); + //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2); return (int) buflen; } @@ -156,10 +155,13 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dc spri->dchan = dchan; 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; spri->span = span; 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"); } @@ -177,7 +179,13 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) int sel; if (spri->on_loop) { - spri->on_loop(spri); + if ((sel = spri->on_loop(spri)) < 0) { + return sel; + } + } + + if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { + return -1; } FD_ZERO(&rfds); @@ -204,13 +212,6 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) event = NULL; if (!sel) { - if ((handler = spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] ? - spri->eventmap[LPWRAP_PRI_EVENT_TIME_CHECK] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) { - if (handler(spri, LPWRAP_PRI_EVENT_TIME_CHECK, NULL) < 0) { - return -1; - } - } - 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)) { diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h index 5137ee4190..c3832626c1 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -59,8 +59,7 @@ typedef enum { 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, - LPWRAP_PRI_EVENT_TIME_CHECK = 20 + LPWRAP_PRI_EVENT_IO_FAIL = 19 } lpwrap_pri_event_t; typedef enum { diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 494751a7ab..0693edd71c 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -131,7 +131,9 @@ static int parse_debug(const char *in) return flags; } +static zap_io_interface_t zap_libpri_interface; +static zap_status_t zap_libpri_start(zap_span_t *span); static ZIO_API_FUNCTION(zap_libpri_api) { @@ -143,14 +145,40 @@ static ZIO_API_FUNCTION(zap_libpri_api) argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } - - if (argc > 2) { - if (!strcasecmp(argv[0], "debug")) { + 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; @@ -159,6 +187,7 @@ static ZIO_API_FUNCTION(zap_libpri_api) goto done; } } + } stream->write_function(stream, "%s: -ERR invalid command.\n", __FILE__); @@ -171,8 +200,6 @@ static ZIO_API_FUNCTION(zap_libpri_api) } -static zap_io_interface_t zap_libpri_interface; - static ZIO_IO_LOAD_FUNCTION(zap_libpri_io_init) { assert(zio != NULL); @@ -190,7 +217,6 @@ static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) { pri_set_error(s_pri_error); pri_set_message(s_pri_message); - return ZAP_SUCCESS; } @@ -648,6 +674,10 @@ static int check_flags(lpwrap_pri_t *spri) check_state(span); + if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { + return -1; + } + return 0; } @@ -712,22 +742,12 @@ static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve } -static int on_time_check(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event *pevent) -{ - - if (!zap_running() || zap_test_flag(spri->span, ZAP_SPAN_STOP_THREAD)) { - return -1; - } - - return 0; -} - - 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 x, i; + int down = 0; zap_set_flag(span, ZAP_SPAN_IN_THREAD); @@ -768,8 +788,12 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); - LPWRAP_MAP_PRI_EVENT(isdn_data->spri, LPWRAP_PRI_EVENT_TIME_CHECK, on_time_check); - + + 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; @@ -782,30 +806,54 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) break; } - zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span); + zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span->span_id); + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + check_state(span); + check_state(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; } + 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; } 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); @@ -817,7 +865,6 @@ static zap_status_t zap_libpri_start(zap_span_t *span) } - static int str2node(char *node) { if (!strcasecmp(node, "cpe") || !strcasecmp(node, "user")) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8b201853e5..c2219d309f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -79,9 +79,10 @@ static struct { zap_hash_t *module_hash; zap_hash_t *span_hash; zap_mutex_t *mutex; - struct zap_span *spans[ZAP_MAX_SPANS_INTERFACE+1]; + zap_mutex_t *span_mutex; uint32_t span_index; uint32_t running; + zap_span_t *spans; } globals; @@ -309,7 +310,55 @@ OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) return status; } -OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span) +static void zap_span_add(zap_span_t *span) +{ + zap_span_t *sp; + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp && sp->next; sp = sp->next); + if (sp) { + sp->next = span; + } else { + globals.spans = span; + } + hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); + zap_mutex_unlock(globals.span_mutex); +} + +#if 0 +static void zap_span_del(zap_span_t *span) +{ + zap_span_t *last = NULL, *sp; + + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp; sp = sp->next) { + + if (sp == span) { + if (last) { + last->next = sp->next; + } else { + globals.spans = sp->next; + } + hashtable_remove(globals.span_hash, (void *)sp->name); + break; + } + + last = sp; + } + zap_mutex_unlock(globals.span_mutex); +} +#endif + +OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span) +{ + if (span->stop) { + span->stop(span); + return ZAP_SUCCESS; + } + + return ZAP_FAIL; +} + +OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name) { zap_span_t *new_span = NULL; zap_status_t status = ZAP_FAIL; @@ -317,21 +366,16 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s assert(zio != NULL); zap_mutex_lock(globals.mutex); + if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = globals.spans[++globals.span_index]; - if (!new_span) { - if (!(new_span = malloc(sizeof(*new_span)))) { - goto done; - } - globals.spans[globals.span_index] = new_span; - } + new_span = malloc(sizeof(*new_span)); + assert(new_span); memset(new_span, 0, sizeof(*new_span)); status = zap_mutex_create(&new_span->mutex); - if (status != ZAP_SUCCESS) { - goto done; - } + assert(status == ZAP_SUCCESS); + zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = globals.span_index; + new_span->span_id = ++globals.span_index; new_span->zio = zio; zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); @@ -339,11 +383,24 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); new_span->trunk_type = ZAP_TRUNK_NONE; new_span->data_type = ZAP_TYPE_SPAN; + + zap_mutex_lock(globals.span_mutex); + if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { + zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, new_span->span_id); + name = NULL; + } + zap_mutex_unlock(globals.span_mutex); + + if (!name) { + char buf[128] = ""; + snprintf(buf, sizeof(buf), "span%d", new_span->span_id); + name = buf; + } + new_span->name = strdup(name); + zap_span_add(new_span); *span = new_span; status = ZAP_SUCCESS; } - -done: zap_mutex_unlock(globals.mutex); return status; } @@ -351,18 +408,18 @@ done: OZ_DECLARE(zap_status_t) zap_span_close_all(void) { zap_span_t *span; - uint32_t i, j; + uint32_t i = 0, j; - zap_mutex_lock(globals.mutex); - for(i = 1; i <= globals.span_index; i++) { - span = globals.spans[i]; + zap_mutex_lock(globals.span_mutex); + for (span = globals.spans; span; span = span->next) { if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { for(j = 1; j <= span->chan_count && span->channels[j]; j++) { zap_channel_destroy(span->channels[j]); + i++; } } } - zap_mutex_unlock(globals.mutex); + zap_mutex_unlock(globals.span_mutex); return i ? ZAP_SUCCESS : ZAP_FAIL; } @@ -482,26 +539,40 @@ OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **sp { zap_status_t status = ZAP_FAIL; - zap_mutex_lock(globals.mutex); - if (!zap_strlen_zero(name) && (*span = hashtable_search(globals.span_hash, (void *)name))) { - status = ZAP_SUCCESS; - } - zap_mutex_unlock(globals.mutex); + zap_mutex_lock(globals.span_mutex); + if (!zap_strlen_zero(name)) { + if ((*span = hashtable_search(globals.span_hash, (void *)name))) { + status = ZAP_SUCCESS; + } else { + int span_id = atoi(name); + zap_span_find(span_id, span); + if (*span) { + status = ZAP_SUCCESS; + } + } + } + zap_mutex_unlock(globals.span_mutex); + return status; } OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span) { - zap_span_t *fspan; + zap_span_t *fspan = NULL, *sp; if (id > ZAP_MAX_SPANS_INTERFACE) { return ZAP_FAIL; } - zap_mutex_lock(globals.mutex); - fspan = globals.spans[id]; - zap_mutex_unlock(globals.mutex); + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp; sp = sp->next) { + if (sp->span_id == id) { + fspan = sp; + break; + } + } + zap_mutex_unlock(globals.span_mutex); if (!fspan || !zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { return ZAP_FAIL; @@ -840,122 +911,94 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t zap_status_t status = ZAP_FAIL; zap_channel_t *check; uint32_t i,j; - zap_span_t *span; + zap_span_t *span = NULL; uint32_t span_max; if (span_id) { - if (span_id > globals.span_index || !globals.spans[span_id]) { + zap_span_find(span_id, &span); + + if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; return ZAP_FAIL; } - if (globals.spans[span_id]->active_count >= globals.spans[span_id]->chan_count) { + if (span->active_count >= span->chan_count) { zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); *zchan = NULL; return ZAP_FAIL; } - if (globals.spans[span_id]->channel_request && !globals.spans[span_id]->suggest_chan_id) { - return globals.spans[span_id]->channel_request(globals.spans[span_id], 0, direction, caller_data, zchan); + if (span->channel_request && !span->suggest_chan_id) { + return span->channel_request(span, 0, direction, caller_data, zchan); } span_max = span_id; j = span_id; } else { - span_max = globals.span_index; - if (direction == ZAP_TOP_DOWN) { - j = 1; - } else { - j = span_max; - } + zap_log(ZAP_LOG_CRIT, "No span supplied\n"); + *zchan = NULL; + return ZAP_FAIL; } + zap_mutex_lock(span->mutex); + + if (direction == ZAP_TOP_DOWN) { + i = 1; + } else { + i = span->chan_count; + } + for(;;) { + if (direction == ZAP_TOP_DOWN) { - if (j > span_max) { - goto done; + if (i > span->chan_count) { + break; } } else { - if (j == 0) { - goto done; + if (i == 0) { + break; } } - - span = globals.spans[j]; - zap_mutex_lock(span->mutex); - - if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - goto next_loop; - } - - if (direction == ZAP_TOP_DOWN) { - i = 1; - } else { - i = span->chan_count; - } - - for(;;) { - - if (direction == ZAP_TOP_DOWN) { - if (i > span->chan_count) { - break; - } - } else { - if (i == 0) { - break; - } - } - if (!(check = span->channels[i])) { - status = ZAP_FAIL; + if (!(check = span->channels[i])) { + status = ZAP_FAIL; + zap_mutex_unlock(span->mutex); + goto done; + } + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && + !zap_test_flag(check, ZAP_CHANNEL_INUSE) && + !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && + check->state == ZAP_CHANNEL_STATE_DOWN + ) { + + if (span && span->channel_request) { + status = span->channel_request(span, i, direction, caller_data, zchan); zap_mutex_unlock(span->mutex); goto done; } - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && - !zap_test_flag(check, ZAP_CHANNEL_INUSE) && - !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && - check->state == ZAP_CHANNEL_STATE_DOWN - ) { - if (globals.spans[span_id] && globals.spans[span_id]->channel_request) { - status = globals.spans[span_id]->channel_request(globals.spans[span_id], i, direction, caller_data, zchan); - zap_mutex_unlock(span->mutex); - goto done; - } - - status = check->zio->open(check); + status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_INUSE); - zap_channel_open_chan(check); - *zchan = check; - zap_mutex_unlock(span->mutex); - goto done; - } - } - - if (direction == ZAP_TOP_DOWN) { - i++; - } else { - i--; + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_INUSE); + zap_channel_open_chan(check); + *zchan = check; + zap_mutex_unlock(span->mutex); + goto done; } } - next_loop: - - zap_mutex_unlock(span->mutex); - if (direction == ZAP_TOP_DOWN) { - j++; + i++; } else { - j--; + i--; } } done: - + return status; } @@ -1048,22 +1091,24 @@ OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, za { zap_channel_t *check; zap_status_t status = ZAP_FAIL; + zap_span_t *span = NULL; - zap_mutex_lock(globals.mutex); + zap_mutex_unlock(globals.mutex); + zap_span_find(span_id, &span); - if (span_id > globals.span_index || chan_id >= ZAP_MAX_CHANNELS_SPAN || !globals.spans[span_id]) { - zap_log(ZAP_LOG_ERROR, "SPAN NOT DEFINED!\n"); + if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED) || chan_id >= ZAP_MAX_CHANNELS_SPAN) { + zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; - goto done; + goto done; } - if (globals.spans[span_id]->channel_request) { + if (span->channel_request) { zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); *zchan = NULL; goto done; } - check = globals.spans[span_id]->channels[chan_id]; + check = span->channels[chan_id]; if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { @@ -2202,25 +2247,10 @@ static zap_status_t load_config(void) continue; } - if (zap_span_create(zio, &span) == ZAP_SUCCESS) { + if (zap_span_create(zio, &span, name) == ZAP_SUCCESS) { span->type = strdup(type); d = 0; - zap_mutex_lock(globals.mutex); - if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { - zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, span->span_id); - name = NULL; - } - - if (!name) { - char buf[128] = ""; - snprintf(buf, sizeof(buf), "span%d", span->span_id); - name = buf; - } - span->name = strdup(name); - hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); - zap_mutex_unlock(globals.mutex); - zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); } else { @@ -2576,6 +2606,7 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); modcount = 0; zap_mutex_create(&globals.mutex); + zap_mutex_create(&globals.span_mutex); modcount = zap_load_modules(); zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); @@ -2597,15 +2628,19 @@ OZ_DECLARE(uint32_t) zap_running(void) OZ_DECLARE(zap_status_t) zap_global_destroy(void) { - unsigned int i,j; + unsigned int j; + zap_span_t *sp; + time_end(); globals.running = 0; zap_span_close_all(); zap_sleep(1000); - for(i = 1; i <= globals.span_index; i++) { - zap_span_t *cur_span = globals.spans[i]; + zap_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp;) { + zap_span_t *cur_span = sp; + sp = sp->next; if (cur_span) { if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { @@ -2630,15 +2665,17 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) zap_safe_free(cur_span->signal_data); zap_span_destroy(cur_span); } - zap_mutex_lock(globals.mutex); + hashtable_remove(globals.span_hash, (void *)cur_span->name); - zap_mutex_unlock(globals.mutex); zap_safe_free(cur_span->type); zap_safe_free(cur_span->name); free(cur_span); cur_span = NULL; } } + globals.spans = NULL; + zap_mutex_unlock(globals.span_mutex); + globals.span_index = 0; zap_unload_modules(); @@ -2649,6 +2686,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) hashtable_destroy(globals.span_hash); zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); + zap_mutex_destroy(&globals.span_mutex); memset(&globals, 0, sizeof(globals)); return ZAP_SUCCESS; From 537ec1931ccc6a12af369b77eef214654caa8c0b Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 12 Mar 2009 15:27:29 +0000 Subject: [PATCH 1341/1766] Add channel variables git-svn-id: http://svn.openzap.org/svn/openzap/trunk@696 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 1b9f96ab45..a6bbd55c41 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1041,6 +1041,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", zchan->span_id, zchan->chan_id, dest); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); + switch_channel_set_variable(channel, "openzap_span_name", zchan->span->name); + switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", zchan->span_id); + switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", zchan->chan_id); zchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); @@ -1150,6 +1153,10 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + + switch_channel_set_variable(channel, "openzap_span_name", sigmsg->channel->span->name); + switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", sigmsg->channel->span_id); + switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", sigmsg->channel->chan_id); switch_channel_set_state(channel, CS_INIT); if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { From 0c83182d36c8aefa9863f4c4d58e0bb5e702da56 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 12 Mar 2009 15:27:29 +0000 Subject: [PATCH 1342/1766] Add channel variables git-svn-id: http://svn.openzap.org/svn/openzap/trunk@696 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 1b9f96ab45..a6bbd55c41 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1041,6 +1041,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", zchan->span_id, zchan->chan_id, dest); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); + switch_channel_set_variable(channel, "openzap_span_name", zchan->span->name); + switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", zchan->span_id); + switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", zchan->chan_id); zchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); @@ -1150,6 +1153,10 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + + switch_channel_set_variable(channel, "openzap_span_name", sigmsg->channel->span->name); + switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", sigmsg->channel->span_id); + switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", sigmsg->channel->chan_id); switch_channel_set_state(channel, CS_INIT); if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { From dd8d70b0a8a1f93814c1d13a8882a829c4f4f6f5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 12 Mar 2009 17:22:03 +0000 Subject: [PATCH 1343/1766] try to recover from alarm better git-svn-id: http://svn.openzap.org/svn/openzap/trunk@697 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 54 +++++++++++++++++-- libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 4 +- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 12aaeea02b..ec8e7cde6d 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1383,8 +1383,16 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even { sig.event_id = ZAP_OOB_ALARM_TRAP; if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); + if (event->channel->type == ZAP_CHAN_TYPE_B) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); + } } + + if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { + zap_log(ZAP_LOG_WARNING, "Stopping ISDN for span %s\n", span->name); + span->stop(span); + } + zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); @@ -1396,6 +1404,12 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even break; case ZAP_OOB_ALARM_CLEAR: { + + if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { + zap_log(ZAP_LOG_WARNING, "Resuming ISDN for span %s\n", span->name); + span->start(span); + } + sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); @@ -1464,6 +1478,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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!"); @@ -1489,7 +1504,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) ts.duration = ts.rate; /* main loop */ - while(zap_running() && zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { + 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; @@ -1636,6 +1651,7 @@ done: } zap_log(ZAP_LOG_DEBUG, "ISDN tone thread ended.\n"); + zap_clear_flag(isdn_data, ZAP_ISDN_TONES_RUNNING); return NULL; } @@ -1653,10 +1669,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) #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)) { + 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); @@ -1891,14 +1908,40 @@ static zap_state_map_t isdn_state_map = { } }; +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; + +} + static zap_status_t zap_isdn_start(zap_span_t *span) { zap_status_t ret; - zap_isdn_data_t *isdn_data = span->signal_data; - zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); + 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; } @@ -2071,6 +2114,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } span->start = zap_isdn_start; + span->stop = zap_isdn_stop; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index f33a9b211f..689c540aac 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -46,7 +46,9 @@ typedef enum { } zap_isdn_opts_t; typedef enum { - ZAP_ISDN_RUNNING = (1 << 0) + ZAP_ISDN_RUNNING = (1 << 0), + ZAP_ISDN_TONES_RUNNING = (1 << 1), + ZAP_ISDN_STOP = (1 << 2) } zap_isdn_flag_t; From 8b55cdd24962b5c63c880ddeda931b917ec7d657 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 12 Mar 2009 17:22:03 +0000 Subject: [PATCH 1344/1766] try to recover from alarm better git-svn-id: http://svn.openzap.org/svn/openzap/trunk@697 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 54 +++++++++++++++++-- libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h | 4 +- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 12aaeea02b..ec8e7cde6d 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1383,8 +1383,16 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even { sig.event_id = ZAP_OOB_ALARM_TRAP; if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); + if (event->channel->type == ZAP_CHAN_TYPE_B) { + zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); + } } + + if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { + zap_log(ZAP_LOG_WARNING, "Stopping ISDN for span %s\n", span->name); + span->stop(span); + } + zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); @@ -1396,6 +1404,12 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even break; case ZAP_OOB_ALARM_CLEAR: { + + if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { + zap_log(ZAP_LOG_WARNING, "Resuming ISDN for span %s\n", span->name); + span->start(span); + } + sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); @@ -1464,6 +1478,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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!"); @@ -1489,7 +1504,7 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) ts.duration = ts.rate; /* main loop */ - while(zap_running() && zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { + 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; @@ -1636,6 +1651,7 @@ done: } zap_log(ZAP_LOG_DEBUG, "ISDN tone thread ended.\n"); + zap_clear_flag(isdn_data, ZAP_ISDN_TONES_RUNNING); return NULL; } @@ -1653,10 +1669,11 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) #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)) { + 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); @@ -1891,14 +1908,40 @@ static zap_state_map_t isdn_state_map = { } }; +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; + +} + static zap_status_t zap_isdn_start(zap_span_t *span) { zap_status_t ret; - zap_isdn_data_t *isdn_data = span->signal_data; - zap_set_flag(isdn_data, ZAP_ISDN_RUNNING); + 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; } @@ -2071,6 +2114,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } span->start = zap_isdn_start; + span->stop = zap_isdn_stop; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index f33a9b211f..689c540aac 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -46,7 +46,9 @@ typedef enum { } zap_isdn_opts_t; typedef enum { - ZAP_ISDN_RUNNING = (1 << 0) + ZAP_ISDN_RUNNING = (1 << 0), + ZAP_ISDN_TONES_RUNNING = (1 << 1), + ZAP_ISDN_STOP = (1 << 2) } zap_isdn_flag_t; From d95fb86db52d145bf9d746beae58bb8bd754029f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 13 Mar 2009 18:52:35 +0000 Subject: [PATCH 1345/1766] change logic to declinatio mortuus obfirmo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@698 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 10 +++++++++ .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 22 +++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index c85233a949..3bb87a806d 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -712,6 +712,16 @@ static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) zap_mutex_unlock(span->mutex); } +static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag) +{ + uint32_t j; + zap_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + zap_clear_flag_locked((span->channels[j]), flag); + } + zap_mutex_unlock(span->mutex); +} + #endif /* For Emacs: diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index ec8e7cde6d..f8bb7ef7a8 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1387,16 +1387,14 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); } } - - if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { - zap_log(ZAP_LOG_WARNING, "Stopping ISDN for span %s\n", span->name); - span->stop(span); - } + zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + + zap_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); - zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) has alarms [%s]\n", + 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); @@ -1404,11 +1402,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even break; case ZAP_OOB_ALARM_CLEAR: { - - if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { - zap_log(ZAP_LOG_WARNING, "Resuming ISDN for span %s\n", span->name); - span->start(span); - } + + 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); sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); @@ -1705,6 +1701,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) { 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 From d0b8ab150247812cd37d36efff30fe128207ce1f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 13 Mar 2009 18:52:35 +0000 Subject: [PATCH 1346/1766] change logic to declinatio mortuus obfirmo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@698 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 10 +++++++++ .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 22 +++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index c85233a949..3bb87a806d 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -712,6 +712,16 @@ static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) zap_mutex_unlock(span->mutex); } +static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag) +{ + uint32_t j; + zap_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + zap_clear_flag_locked((span->channels[j]), flag); + } + zap_mutex_unlock(span->mutex); +} + #endif /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index ec8e7cde6d..f8bb7ef7a8 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1387,16 +1387,14 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_RESTART); } } - - if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { - zap_log(ZAP_LOG_WARNING, "Stopping ISDN for span %s\n", span->name); - span->stop(span); - } + zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + + zap_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); - zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) has alarms [%s]\n", + 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); @@ -1404,11 +1402,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even break; case ZAP_OOB_ALARM_CLEAR: { - - if (event->channel->type == ZAP_CHAN_TYPE_DQ921) { - zap_log(ZAP_LOG_WARNING, "Resuming ISDN for span %s\n", span->name); - span->start(span); - } + + 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); sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); @@ -1705,6 +1701,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) { 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 From 851bfa7dad1b86d60b13544bcccadd679a7b90d1 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 16 Mar 2009 21:04:22 +0000 Subject: [PATCH 1347/1766] Merge "interval == 0" workaround from personal rework branch, still need to investigate why wanpipe does not provide this information (and if 20ms is a good default value) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@699 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index f8bb7ef7a8..105522cb81 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1490,10 +1490,11 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) break; } } + if (!interval) { + interval = 20; + } zap_log(ZAP_LOG_NOTICE, "Tone generating interval %d\n", interval); - assert(interval != 0); - /* init teletone */ teletone_init_session(&ts, 0, teletone_handler, dt_buffer); ts.rate = 8000; From c30aac4629dcfde3fe2340965c5df48f6d11ba6e Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 16 Mar 2009 21:04:22 +0000 Subject: [PATCH 1348/1766] Merge "interval == 0" workaround from personal rework branch, still need to investigate why wanpipe does not provide this information (and if 20ms is a good default value) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@699 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index f8bb7ef7a8..105522cb81 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1490,10 +1490,11 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) break; } } + if (!interval) { + interval = 20; + } zap_log(ZAP_LOG_NOTICE, "Tone generating interval %d\n", interval); - assert(interval != 0); - /* init teletone */ teletone_init_session(&ts, 0, teletone_handler, dt_buffer); ts.rate = 8000; From b7f3b79a434df3d86fbed3076feba0155a780fd9 Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Wed, 18 Mar 2009 18:09:01 +0000 Subject: [PATCH 1349/1766] Remove oz bounce from oz syntax string git-svn-id: http://svn.openzap.org/svn/openzap/trunk@700 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a6bbd55c41..1f6e02e45e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2171,7 +2171,7 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } -#define OZ_SYNTAX "list || dump [] || bounce [] || q931_pcap on|off [pcapfilename without suffix]" +#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix]" SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; From 79da28cdd7d0816c840f94af6a4b3aa1cb73186c Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Wed, 18 Mar 2009 18:09:01 +0000 Subject: [PATCH 1350/1766] Remove oz bounce from oz syntax string git-svn-id: http://svn.openzap.org/svn/openzap/trunk@700 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a6bbd55c41..1f6e02e45e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2171,7 +2171,7 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } -#define OZ_SYNTAX "list || dump [] || bounce [] || q931_pcap on|off [pcapfilename without suffix]" +#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix]" SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; From 5c3d77cff30eb79de6c6382d1cbf9a7b21677b47 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 19 Mar 2009 20:15:39 +0000 Subject: [PATCH 1351/1766] With libpri, to avoid sending DISPLAY IE, set the opts param to omit_display git-svn-id: http://svn.openzap.org/svn/openzap/trunk@701 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 12 +++---- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 34 ++++++++++++++----- .../src/ozmod/ozmod_libpri/ozmod_libpri.h | 5 +-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 1f6e02e45e..f026debdaf 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1956,12 +1956,12 @@ static switch_status_t load_config(void) const char *o_switch = "dms100"; const char *o_dp = "unknown"; const char *o_l1 = "ulaw"; - const char *o_debug = NULL; - - + const char *o_debug = "none"; + const char* opts = "none"; + uint32_t span_id = 0; zap_span_t *span = NULL; - uint32_t opts = 0; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1979,8 +1979,8 @@ static switch_status_t load_config(void) o_debug = val; } else if (!strcasecmp(var, "context")) { context = val; - } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { - opts |= 1; + } else if (!strcasecmp(var, "opts")) { + opts = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 0693edd71c..f2352b921d 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -71,6 +71,25 @@ static void s_pri_message(struct pri *pri, char *s) zap_log(ZAP_LOG_DEBUG, "%s", s); } +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; + } + + return flags; +} + static int parse_debug(const char *in) { @@ -467,7 +486,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, zchan->caller_data.cid_name, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + 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, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); 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)) { @@ -926,9 +946,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) //zap_channel_t *dchans[2] = {0}; zap_libpri_data_t *isdn_data; char *var, *val; - int32_t opts = 0; 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; @@ -980,11 +999,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } isdn_data->pswitch = str2switch(val); } else if (!strcasecmp(var, "opts")) { - opts = va_arg(ap, uint32_t); - if (opts >= OZMOD_LIBPRI_OPT_MAX) { - return ZAP_FAIL; + if (!(val = va_arg(ap, char *))) { + break; } - isdn_data->opts = opts; + isdn_data->opts = parse_opts(val); } else if (!strcasecmp(var, "dp")) { if (!(val = va_arg(ap, char *))) { break; @@ -1021,7 +1039,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - if ((opts & OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { + if ((isdn_data->opts & OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; span->suggest_chan_id = 1; } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h index 64a0c05ae3..ec00cecef5 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -40,8 +40,9 @@ typedef enum { OZMOD_LIBPRI_OPT_NONE = 0, OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), - - OZMOD_LIBPRI_OPT_MAX = (2 << 0) + OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (2 << 0), + + OZMOD_LIBPRI_OPT_MAX = (3 << 0) } zap_isdn_opts_t; typedef enum { From a6672fc55892b0bb27364e204aa2ac3df2ee559f Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 19 Mar 2009 20:15:39 +0000 Subject: [PATCH 1352/1766] With libpri, to avoid sending DISPLAY IE, set the opts param to omit_display git-svn-id: http://svn.openzap.org/svn/openzap/trunk@701 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 12 +++---- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 34 ++++++++++++++----- .../src/ozmod/ozmod_libpri/ozmod_libpri.h | 5 +-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 1f6e02e45e..f026debdaf 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1956,12 +1956,12 @@ static switch_status_t load_config(void) const char *o_switch = "dms100"; const char *o_dp = "unknown"; const char *o_l1 = "ulaw"; - const char *o_debug = NULL; - - + const char *o_debug = "none"; + const char* opts = "none"; + uint32_t span_id = 0; zap_span_t *span = NULL; - uint32_t opts = 0; + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); @@ -1979,8 +1979,8 @@ static switch_status_t load_config(void) o_debug = val; } else if (!strcasecmp(var, "context")) { context = val; - } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { - opts |= 1; + } else if (!strcasecmp(var, "opts")) { + opts = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 0693edd71c..f2352b921d 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -71,6 +71,25 @@ static void s_pri_message(struct pri *pri, char *s) zap_log(ZAP_LOG_DEBUG, "%s", s); } +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; + } + + return flags; +} + static int parse_debug(const char *in) { @@ -467,7 +486,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, zchan->caller_data.cid_name, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + 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, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); 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)) { @@ -926,9 +946,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) //zap_channel_t *dchans[2] = {0}; zap_libpri_data_t *isdn_data; char *var, *val; - int32_t opts = 0; 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; @@ -980,11 +999,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } isdn_data->pswitch = str2switch(val); } else if (!strcasecmp(var, "opts")) { - opts = va_arg(ap, uint32_t); - if (opts >= OZMOD_LIBPRI_OPT_MAX) { - return ZAP_FAIL; + if (!(val = va_arg(ap, char *))) { + break; } - isdn_data->opts = opts; + isdn_data->opts = parse_opts(val); } else if (!strcasecmp(var, "dp")) { if (!(val = va_arg(ap, char *))) { break; @@ -1021,7 +1039,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - if ((opts & OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { + if ((isdn_data->opts & OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; span->suggest_chan_id = 1; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h index 64a0c05ae3..ec00cecef5 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -40,8 +40,9 @@ typedef enum { OZMOD_LIBPRI_OPT_NONE = 0, OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), - - OZMOD_LIBPRI_OPT_MAX = (2 << 0) + OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (2 << 0), + + OZMOD_LIBPRI_OPT_MAX = (3 << 0) } zap_isdn_opts_t; typedef enum { From 9f892711a58d0460ccec70c75f0c1622d4db2221 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 19 Mar 2009 23:06:04 +0000 Subject: [PATCH 1353/1766] Port mrene's changes to ozmod_isdn: Add "opts" parameter to span definition in pri_spans (removing suggest-channel parameter) Possible options are: suggest_channel - No idea what this one actually does... disable_tones - Disable tone generating thread in NT (net) mode omit_display - Disable sending caller name in call setup message (Display IE) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@702 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 6 +- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 59 +++++++++++++------ libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 2 + 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index f026debdaf..faecee0c06 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1850,8 +1850,8 @@ static switch_status_t load_config(void) zap_span_t *span = NULL; const char *tonegroup = NULL; char *digit_timeout = NULL; + const char *opts = "none"; uint32_t to = 0; - uint32_t opts = 0; int q921loglevel = -1; int q931loglevel = -1; // quick debug @@ -1877,8 +1877,8 @@ static switch_status_t load_config(void) } } else if (!strcasecmp(var, "context")) { context = val; - } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { - opts |= 1; + } else if (!strcasecmp(var, "opts")) { + opts = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 105522cb81..1007900e13 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -341,11 +341,13 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) /* * 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); + 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 @@ -1214,12 +1216,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* * 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); + */ + 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 @@ -1947,13 +1951,34 @@ static zap_status_t zap_isdn_start(zap_span_t *span) return ret; } - if(ZAP_SPAN_IS_NT(span)) { + 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; } +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; +} static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) { @@ -1963,7 +1988,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) const char *tonemap = "us"; char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; - uint32_t opts = 0; int32_t digit_timeout = 0; int q921loglevel = -1; int q931loglevel = -1; @@ -2052,11 +2076,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_FAIL; } } else if (!strcasecmp(var, "opts")) { - opts = va_arg(ap, uint32_t); - if (opts >= ZAP_ISDN_OPT_MAX) { - return ZAP_FAIL; + if (!(val = va_arg(ap, char *))) { + break; } - isdn_data->opts = opts; + isdn_data->opts = parse_opts(val); } else if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { break; @@ -2156,7 +2179,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { + if ((isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; span->suggest_chan_id = 1; } diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index 689c540aac..470a8022bb 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -41,6 +41,8 @@ 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; From 03dbc587fd0ac1261f58c3e98c1947a8c0279fca Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 19 Mar 2009 23:06:04 +0000 Subject: [PATCH 1354/1766] Port mrene's changes to ozmod_isdn: Add "opts" parameter to span definition in pri_spans (removing suggest-channel parameter) Possible options are: suggest_channel - No idea what this one actually does... disable_tones - Disable tone generating thread in NT (net) mode omit_display - Disable sending caller name in call setup message (Display IE) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@702 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 6 +- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 59 +++++++++++++------ libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h | 2 + 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index f026debdaf..faecee0c06 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1850,8 +1850,8 @@ static switch_status_t load_config(void) zap_span_t *span = NULL; const char *tonegroup = NULL; char *digit_timeout = NULL; + const char *opts = "none"; uint32_t to = 0; - uint32_t opts = 0; int q921loglevel = -1; int q931loglevel = -1; // quick debug @@ -1877,8 +1877,8 @@ static switch_status_t load_config(void) } } else if (!strcasecmp(var, "context")) { context = val; - } else if (!strcasecmp(var, "suggest-channel") && switch_true(val)) { - opts |= 1; + } else if (!strcasecmp(var, "opts")) { + opts = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 105522cb81..1007900e13 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -341,11 +341,13 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) /* * 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); + 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 @@ -1214,12 +1216,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* * 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); + */ + 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 @@ -1947,13 +1951,34 @@ static zap_status_t zap_isdn_start(zap_span_t *span) return ret; } - if(ZAP_SPAN_IS_NT(span)) { + 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; } +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; +} static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) { @@ -1963,7 +1988,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) const char *tonemap = "us"; char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; - uint32_t opts = 0; int32_t digit_timeout = 0; int q921loglevel = -1; int q931loglevel = -1; @@ -2052,11 +2076,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_FAIL; } } else if (!strcasecmp(var, "opts")) { - opts = va_arg(ap, uint32_t); - if (opts >= ZAP_ISDN_OPT_MAX) { - return ZAP_FAIL; + if (!(val = va_arg(ap, char *))) { + break; } - isdn_data->opts = opts; + isdn_data->opts = parse_opts(val); } else if (!strcasecmp(var, "tonemap")) { if (!(val = va_arg(ap, char *))) { break; @@ -2156,7 +2179,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) span->signal_type = ZAP_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - if ((opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { + if ((isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; span->suggest_chan_id = 1; } diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index 689c540aac..470a8022bb 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -41,6 +41,8 @@ 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; From 391201452ad593fd8d0fd673a0bbbd52366b623b Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 31 Mar 2009 22:11:40 +0000 Subject: [PATCH 1355/1766] Quick fix to get hex output of D-Channel traffic in ozmod_libpri. Remove the comment chars in front of the #define IODEBUG to enable it (compile time tested only) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@703 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index bb7b9c3a85..8efdafeca8 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -31,6 +31,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +//#define IODEBUG + #include "openzap.h" #include "lpwrap_pri.h" #ifndef HAVE_GETTIMEOFDAY @@ -123,8 +125,14 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) 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", 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; } @@ -137,11 +145,17 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) 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; + return -1; } - - //print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0); - //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2); + +#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; } From f27c8cc07939a369848c066158367b36adb3bef0 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 31 Mar 2009 22:11:40 +0000 Subject: [PATCH 1356/1766] Quick fix to get hex output of D-Channel traffic in ozmod_libpri. Remove the comment chars in front of the #define IODEBUG to enable it (compile time tested only) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@703 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index bb7b9c3a85..8efdafeca8 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -31,6 +31,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +//#define IODEBUG + #include "openzap.h" #include "lpwrap_pri.h" #ifndef HAVE_GETTIMEOFDAY @@ -123,8 +125,14 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) 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", 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; } @@ -137,11 +145,17 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) 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; + return -1; } - - //print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0); - //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2); + +#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; } From 0454c7c91728b6689e6d087bb8d02b4309c8e8a7 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 31 Mar 2009 22:20:39 +0000 Subject: [PATCH 1357/1766] Remove duplicate debug level and a few stray tabs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@704 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index f2352b921d..7985d869c6 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -94,11 +94,11 @@ static uint32_t parse_opts(const char *in) static int parse_debug(const char *in) { int flags = 0; - + if (!in) { return 0; } - + if (strstr(in, "q921_raw")) { flags |= PRI_DEBUG_Q921_RAW; } @@ -118,7 +118,7 @@ static int parse_debug(const char *in) if (strstr(in, "q931_dump")) { flags |= PRI_DEBUG_Q931_DUMP; } - + if (strstr(in, "q931_state")) { flags |= PRI_DEBUG_Q931_STATE; } @@ -127,10 +127,6 @@ static int parse_debug(const char *in) flags |= PRI_DEBUG_Q931_ANOMALY; } - if (strstr(in, "q931_anomaly")) { - flags |= PRI_DEBUG_Q931_ANOMALY; - } - if (strstr(in, "apdu")) { flags |= PRI_DEBUG_APDU; } From fe485675cdbdf4812f7942922caf784b1bd57939 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 31 Mar 2009 22:20:39 +0000 Subject: [PATCH 1358/1766] Remove duplicate debug level and a few stray tabs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@704 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index f2352b921d..7985d869c6 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -94,11 +94,11 @@ static uint32_t parse_opts(const char *in) static int parse_debug(const char *in) { int flags = 0; - + if (!in) { return 0; } - + if (strstr(in, "q921_raw")) { flags |= PRI_DEBUG_Q921_RAW; } @@ -118,7 +118,7 @@ static int parse_debug(const char *in) if (strstr(in, "q931_dump")) { flags |= PRI_DEBUG_Q931_DUMP; } - + if (strstr(in, "q931_state")) { flags |= PRI_DEBUG_Q931_STATE; } @@ -127,10 +127,6 @@ static int parse_debug(const char *in) flags |= PRI_DEBUG_Q931_ANOMALY; } - if (strstr(in, "q931_anomaly")) { - flags |= PRI_DEBUG_Q931_ANOMALY; - } - if (strstr(in, "apdu")) { flags |= PRI_DEBUG_APDU; } From 8a5faab8a7ecf2555da660f899d7cbf6fd7cc881 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 21:35:29 +0000 Subject: [PATCH 1359/1766] Clean up the top-level Makefile.am git-svn-id: http://svn.openzap.org/svn/openzap/trunk@705 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 163 +++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 44df5bcd81..4a7c1e72b0 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -29,22 +29,24 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -PREFIX=$(prefix) - -SRC=src - -moddir=@modinstdir@ - -INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ -COMPILE = $(CC) $(MY_CFLAGS) $(INCS) -LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) -LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ +PREFIX = $(prefix) +SRC = src +moddir = @modinstdir@ libdir = $(PREFIX)/lib/ -library_includedir = $(PREFIX)/include +library_includedir = $(PREFIX)/include -libopenzap_la_SOURCES = \ +INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ +COMPILE = $(CC) $(MY_CFLAGS) $(INCS) +LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) +LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ + + +# +# libopenzap +# +libopenzap_la_SOURCES = \ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ @@ -80,82 +82,73 @@ $(SRC)/include/zap_types.h lib_LTLIBRARIES = libopenzap.la libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) -libopenzap_la_LIBADD = $(LIBS) +libopenzap_la_LIBADD = $(LIBS) -MYLIB=libopenzap.la +MYLIB = libopenzap.la core: libopenzap.la core-install: install-libLTLIBRARIES +# +# tools & test programs +# noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid + testapp_SOURCES = $(SRC)/testapp.c -testapp_LDADD = libopenzap.la -testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testapp_LDADD = libopenzap.la +testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testcid_SOURCES = $(SRC)/testcid.c -testcid_LDADD = libopenzap.la -testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testcid_LDADD = libopenzap.la +testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testtones_SOURCES = $(SRC)/testtones.c -testtones_LDADD = libopenzap.la -testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testtones_LDADD = libopenzap.la +testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + detect_tones_SOURCES = $(SRC)/detect_tones.c -detect_tones_LDADD = libopenzap.la -detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_tones_LDADD = libopenzap.la +detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + detect_dtmf_SOURCES = $(SRC)/detect_dtmf.c -detect_dtmf_LDADD = libopenzap.la -detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_dtmf_LDADD = libopenzap.la +detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testisdn_SOURCES = $(SRC)/testisdn.c -testisdn_LDADD = libopenzap.la -testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testisdn_LDADD = libopenzap.la +testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testboost_SOURCES = $(SRC)/testboost.c -testboost_LDADD = libopenzap.la -testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testboost_LDADD = libopenzap.la +testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testanalog_SOURCES = $(SRC)/testanalog.c -testanalog_LDADD = libopenzap.la -testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) - -dox: - cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf - -mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make - -mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) - -mod_openzap-install: mod_openzap - cd mod_openzap && make install - -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi - -install-data-local: - $(mkinstalldirs) $(DESTDIR)$(PREFIX) - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf - @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) - @echo OpenZAP Installed +testanalog_LDADD = libopenzap.la +testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +# +# ozmod modules +# mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la + if LIBPRI mod_LTLIBRARIES += ozmod_libpri.la endif + ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module -ozmod_zt_la_LIBADD = $(MYLIB) +ozmod_zt_la_LIBADD = $(MYLIB) + ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_skel_la_LDFLAGS = -module -ozmod_skel_la_LIBADD = $(MYLIB) +ozmod_skel_la_LIBADD = $(MYLIB) + ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_wanpipe_la_LDFLAGS = -module -ozmod_wanpipe_la_LIBADD = $(MYLIB) - -#PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -#PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -#$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -# $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) -#pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) +ozmod_wanpipe_la_LIBADD = $(MYLIB) ozmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ @@ -179,28 +172,50 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE + +ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -ozmod_isdn_la_LIBADD = $(MYLIB) +ozmod_isdn_la_LIBADD = $(MYLIB) ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_la_LDFLAGS = -module -ozmod_analog_la_LIBADD = $(MYLIB) +ozmod_analog_la_LIBADD = $(MYLIB) ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c -ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_em_la_LDFLAGS = -module -ozmod_analog_em_la_LIBADD = $(MYLIB) +ozmod_analog_em_la_LIBADD = $(MYLIB) ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_ss7_boost_la_LDFLAGS = -module -ozmod_ss7_boost_la_LIBADD = $(MYLIB) +ozmod_ss7_boost_la_LIBADD = $(MYLIB) if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c -ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_libpri_la_LDFLAGS = -module -lpri -ozmod_libpri_la_LIBADD = $(MYLIB) +ozmod_libpri_la_LIBADD = $(MYLIB) endif + + +dox doxygen: + cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf + +mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(PREFIX) + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf + @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) + @echo OpenZAP Installed From 80d9fcf1bc99433e5993f7692a9bb09807c7d9fb Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 21:35:29 +0000 Subject: [PATCH 1360/1766] Clean up the top-level Makefile.am git-svn-id: http://svn.openzap.org/svn/openzap/trunk@705 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 163 +++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 44df5bcd81..4a7c1e72b0 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -29,22 +29,24 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -PREFIX=$(prefix) - -SRC=src - -moddir=@modinstdir@ - -INCS=-I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ -COMPILE = $(CC) $(MY_CFLAGS) $(INCS) -LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) -LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ +PREFIX = $(prefix) +SRC = src +moddir = @modinstdir@ libdir = $(PREFIX)/lib/ -library_includedir = $(PREFIX)/include +library_includedir = $(PREFIX)/include -libopenzap_la_SOURCES = \ +INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ +COMPILE = $(CC) $(MY_CFLAGS) $(INCS) +LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) +LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ + + +# +# libopenzap +# +libopenzap_la_SOURCES = \ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ @@ -80,82 +82,73 @@ $(SRC)/include/zap_types.h lib_LTLIBRARIES = libopenzap.la libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) -libopenzap_la_LIBADD = $(LIBS) +libopenzap_la_LIBADD = $(LIBS) -MYLIB=libopenzap.la +MYLIB = libopenzap.la core: libopenzap.la core-install: install-libLTLIBRARIES +# +# tools & test programs +# noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid + testapp_SOURCES = $(SRC)/testapp.c -testapp_LDADD = libopenzap.la -testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testapp_LDADD = libopenzap.la +testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testcid_SOURCES = $(SRC)/testcid.c -testcid_LDADD = libopenzap.la -testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testcid_LDADD = libopenzap.la +testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testtones_SOURCES = $(SRC)/testtones.c -testtones_LDADD = libopenzap.la -testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testtones_LDADD = libopenzap.la +testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + detect_tones_SOURCES = $(SRC)/detect_tones.c -detect_tones_LDADD = libopenzap.la -detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_tones_LDADD = libopenzap.la +detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + detect_dtmf_SOURCES = $(SRC)/detect_dtmf.c -detect_dtmf_LDADD = libopenzap.la -detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +detect_dtmf_LDADD = libopenzap.la +detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testisdn_SOURCES = $(SRC)/testisdn.c -testisdn_LDADD = libopenzap.la -testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testisdn_LDADD = libopenzap.la +testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testboost_SOURCES = $(SRC)/testboost.c -testboost_LDADD = libopenzap.la -testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testboost_LDADD = libopenzap.la +testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testanalog_SOURCES = $(SRC)/testanalog.c -testanalog_LDADD = libopenzap.la -testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) - -dox: - cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf - -mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make - -mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) - -mod_openzap-install: mod_openzap - cd mod_openzap && make install - -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi - -install-data-local: - $(mkinstalldirs) $(DESTDIR)$(PREFIX) - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf - @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) - @echo OpenZAP Installed +testanalog_LDADD = libopenzap.la +testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +# +# ozmod modules +# mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la + if LIBPRI mod_LTLIBRARIES += ozmod_libpri.la endif + ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module -ozmod_zt_la_LIBADD = $(MYLIB) +ozmod_zt_la_LIBADD = $(MYLIB) + ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_skel_la_LDFLAGS = -module -ozmod_skel_la_LIBADD = $(MYLIB) +ozmod_skel_la_LIBADD = $(MYLIB) + ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_wanpipe_la_LDFLAGS = -module -ozmod_wanpipe_la_LIBADD = $(MYLIB) - -#PIKA_DIR=$(shell ls -d /usr/include/pika 2>/dev/null) -#PIKA_LIB=$(shell ls /usr/lib/libpikahmpapi.so 2>/dev/null) - -#$(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN): $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -# $(LINK) $(SOLINK) $(SRC)/ozmod/ozmod_pika/ozmod_pika.o $(MYLIB) -rpath $(libdir) -#pikamod: $(SRC)/ozmod/ozmod_pika/ozmod_pika.$(DYNAMIC_LIB_EXTEN) +ozmod_wanpipe_la_LIBADD = $(MYLIB) ozmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ @@ -179,28 +172,50 @@ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c -ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE + +ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -ozmod_isdn_la_LIBADD = $(MYLIB) +ozmod_isdn_la_LIBADD = $(MYLIB) ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_la_LDFLAGS = -module -ozmod_analog_la_LIBADD = $(MYLIB) +ozmod_analog_la_LIBADD = $(MYLIB) ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c -ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_em_la_LDFLAGS = -module -ozmod_analog_em_la_LIBADD = $(MYLIB) +ozmod_analog_em_la_LIBADD = $(MYLIB) ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_ss7_boost_la_LDFLAGS = -module -ozmod_ss7_boost_la_LIBADD = $(MYLIB) +ozmod_ss7_boost_la_LIBADD = $(MYLIB) if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c -ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_libpri_la_LDFLAGS = -module -lpri -ozmod_libpri_la_LIBADD = $(MYLIB) +ozmod_libpri_la_LIBADD = $(MYLIB) endif + + +dox doxygen: + cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf + +mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c + cd mod_openzap && make + +mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) + +mod_openzap-install: mod_openzap + cd mod_openzap && make install + +mod_openzap-clean: + @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(PREFIX) + $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf + @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) + @echo OpenZAP Installed From 406f778846893247a0b600006883e04a676afba1 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 21:44:33 +0000 Subject: [PATCH 1361/1766] Add openzap.pc pkg-config file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@706 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 9 +++++++++ libs/openzap/configure.ac | 1 + libs/openzap/openzap.pc.in | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 libs/openzap/openzap.pc.in diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 4a7c1e72b0..83921b1784 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -43,6 +43,15 @@ LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ +# +# GNU pkgconfig file +# +EXTRA_DIST = openzap.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = openzap.pc + + # # libopenzap # diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 222a1d309d..c16ce2b386 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -160,5 +160,6 @@ AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile + openzap.pc mod_openzap/Makefile]) AC_OUTPUT diff --git a/libs/openzap/openzap.pc.in b/libs/openzap/openzap.pc.in new file mode 100644 index 0000000000..082ed5c8f6 --- /dev/null +++ b/libs/openzap/openzap.pc.in @@ -0,0 +1,17 @@ +# +# OpenZAP pkg-config file +# +prefix=@prefix@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: OpenZAP +Description: +Version: @PACKAGE_VERSION@ +URL: http://www.openzap.org/ +Requires: +Conflicts: +Libs: -L${libdir} -lopenzap +Libs.private: -lm +Cflags: -I${includedir} From 060872082b953a97a64a12e81cdd75a77a9adf81 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 21:44:33 +0000 Subject: [PATCH 1362/1766] Add openzap.pc pkg-config file git-svn-id: http://svn.openzap.org/svn/openzap/trunk@706 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 9 +++++++++ libs/freetdm/configure.ac | 1 + libs/freetdm/openzap.pc.in | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 libs/freetdm/openzap.pc.in diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 4a7c1e72b0..83921b1784 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -43,6 +43,15 @@ LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ +# +# GNU pkgconfig file +# +EXTRA_DIST = openzap.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = openzap.pc + + # # libopenzap # diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 222a1d309d..c16ce2b386 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -160,5 +160,6 @@ AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile + openzap.pc mod_openzap/Makefile]) AC_OUTPUT diff --git a/libs/freetdm/openzap.pc.in b/libs/freetdm/openzap.pc.in new file mode 100644 index 0000000000..082ed5c8f6 --- /dev/null +++ b/libs/freetdm/openzap.pc.in @@ -0,0 +1,17 @@ +# +# OpenZAP pkg-config file +# +prefix=@prefix@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: OpenZAP +Description: +Version: @PACKAGE_VERSION@ +URL: http://www.openzap.org/ +Requires: +Conflicts: +Libs: -L${libdir} -lopenzap +Libs.private: -lm +Cflags: -I${includedir} From d5b33bf9829302bde878ed1f6d89497eb0acaf68 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 21:58:51 +0000 Subject: [PATCH 1363/1766] Add ZAP_TON_* (taken from Q931.h, drop Q921.h and Q931.h include from openzap.h and fixup all users of the old Q931_TON_ enum values) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@707 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 8 ++++---- libs/openzap/src/include/openzap.h | 15 +++++++++++++-- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 ++- .../openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index faecee0c06..a64cea508a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -978,13 +978,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { - caller_data.ani.type = Q931_TON_NATIONAL; + caller_data.ani.type = ZAP_TON_NATIONAL; } else if (!strcasecmp(var, "international")) { - caller_data.ani.type = Q931_TON_INTERNATIONAL; + caller_data.ani.type = ZAP_TON_INTERNATIONAL; } else if (!strcasecmp(var, "local")) { - caller_data.ani.type = Q931_TON_SUBSCRIBER_NUMBER; + caller_data.ani.type = ZAP_TON_SUBSCRIBER_NUMBER; } else if (!strcasecmp(var, "unknown")) { - caller_data.ani.type = Q931_TON_UNKNOWN; + caller_data.ani.type = ZAP_TON_UNKNOWN; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3bb87a806d..0b6e120d30 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -167,8 +167,6 @@ #include "libteletone.h" #include "zap_buffer.h" #include "zap_threadmutex.h" -#include "Q921.h" -#include "Q931.h" #define XX if (0) @@ -410,6 +408,19 @@ struct zap_fsk_modulator { int16_t sample_buffer[64]; }; +/** + * Type Of Number (TON) + */ +typedef enum { + ZAP_TON_UNKNOWN = 0, + ZAP_TON_INTERNATIONAL, + ZAP_TON_NATIONAL, + ZAP_TON_NETWORK_SPECIFIC, + ZAP_TON_SUBSCRIBER_NUMBER, + ZAP_TON_ABBREVIATED_NUMBER, + ZAP_TON_RESERVED +} zap_ton_t; + typedef struct { char digits[25]; uint8_t type; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 1007900e13..f1b4e93aae 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -32,7 +32,6 @@ */ #include "openzap.h" -#include "zap_isdn.h" #include "Q931.h" #include "Q921.h" #ifdef WIN32 @@ -41,6 +40,8 @@ #include #endif +#include "zap_isdn.h" + #define LINE "--------------------------------------------------------------------------------" //#define IODEBUG diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 7985d869c6..fff761035a 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -463,13 +463,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) dp = zchan->caller_data.ani.type; switch(dp) { - case Q931_TON_NATIONAL: + case ZAP_TON_NATIONAL: dp = PRI_NATIONAL_ISDN; break; - case Q931_TON_INTERNATIONAL: + case ZAP_TON_INTERNATIONAL: dp = PRI_INTERNATIONAL_ISDN; break; - case Q931_TON_SUBSCRIBER_NUMBER: + case ZAP_TON_SUBSCRIBER_NUMBER: dp = PRI_LOCAL_ISDN; break; default: From 59fa1965332df03fc040ee354029d56463b9b200 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 21:58:51 +0000 Subject: [PATCH 1364/1766] Add ZAP_TON_* (taken from Q931.h, drop Q921.h and Q931.h include from openzap.h and fixup all users of the old Q931_TON_ enum values) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@707 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 8 ++++---- libs/freetdm/src/include/openzap.h | 15 +++++++++++++-- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 ++- .../freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index faecee0c06..a64cea508a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -978,13 +978,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { if (!strcasecmp(var, "national")) { - caller_data.ani.type = Q931_TON_NATIONAL; + caller_data.ani.type = ZAP_TON_NATIONAL; } else if (!strcasecmp(var, "international")) { - caller_data.ani.type = Q931_TON_INTERNATIONAL; + caller_data.ani.type = ZAP_TON_INTERNATIONAL; } else if (!strcasecmp(var, "local")) { - caller_data.ani.type = Q931_TON_SUBSCRIBER_NUMBER; + caller_data.ani.type = ZAP_TON_SUBSCRIBER_NUMBER; } else if (!strcasecmp(var, "unknown")) { - caller_data.ani.type = Q931_TON_UNKNOWN; + caller_data.ani.type = ZAP_TON_UNKNOWN; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 3bb87a806d..0b6e120d30 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -167,8 +167,6 @@ #include "libteletone.h" #include "zap_buffer.h" #include "zap_threadmutex.h" -#include "Q921.h" -#include "Q931.h" #define XX if (0) @@ -410,6 +408,19 @@ struct zap_fsk_modulator { int16_t sample_buffer[64]; }; +/** + * Type Of Number (TON) + */ +typedef enum { + ZAP_TON_UNKNOWN = 0, + ZAP_TON_INTERNATIONAL, + ZAP_TON_NATIONAL, + ZAP_TON_NETWORK_SPECIFIC, + ZAP_TON_SUBSCRIBER_NUMBER, + ZAP_TON_ABBREVIATED_NUMBER, + ZAP_TON_RESERVED +} zap_ton_t; + typedef struct { char digits[25]; uint8_t type; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 1007900e13..f1b4e93aae 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -32,7 +32,6 @@ */ #include "openzap.h" -#include "zap_isdn.h" #include "Q931.h" #include "Q921.h" #ifdef WIN32 @@ -41,6 +40,8 @@ #include #endif +#include "zap_isdn.h" + #define LINE "--------------------------------------------------------------------------------" //#define IODEBUG diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 7985d869c6..fff761035a 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -463,13 +463,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) dp = zchan->caller_data.ani.type; switch(dp) { - case Q931_TON_NATIONAL: + case ZAP_TON_NATIONAL: dp = PRI_NATIONAL_ISDN; break; - case Q931_TON_INTERNATIONAL: + case ZAP_TON_INTERNATIONAL: dp = PRI_INTERNATIONAL_ISDN; break; - case Q931_TON_SUBSCRIBER_NUMBER: + case ZAP_TON_SUBSCRIBER_NUMBER: dp = PRI_LOCAL_ISDN; break; default: From 9cb2273f8a90291fc32f1d16733b1c510cf1fdda Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 22:19:11 +0000 Subject: [PATCH 1365/1766] clean up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@708 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 0b6e120d30..937a69f502 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -168,15 +168,13 @@ #include "zap_buffer.h" #include "zap_threadmutex.h" -#define XX if (0) - #ifdef __WINDOWS__ #define zap_sleep(x) Sleep(x) #else #define zap_sleep(x) usleep(x * 1000) #endif -#ifdef NDEBUG +#ifdef NDEBUG #undef assert #define assert(_Expression) ((void)(_Expression)) #endif From 688a9750790ef1fc18fb15a44405cb228b6a703b Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 8 Apr 2009 22:19:11 +0000 Subject: [PATCH 1366/1766] clean up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@708 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 0b6e120d30..937a69f502 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -168,15 +168,13 @@ #include "zap_buffer.h" #include "zap_threadmutex.h" -#define XX if (0) - #ifdef __WINDOWS__ #define zap_sleep(x) Sleep(x) #else #define zap_sleep(x) usleep(x * 1000) #endif -#ifdef NDEBUG +#ifdef NDEBUG #undef assert #define assert(_Expression) ((void)(_Expression)) #endif From 88899d2a29193355fc066e3be4548bfebfd197c7 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 9 Apr 2009 15:34:55 +0000 Subject: [PATCH 1367/1766] Add -avoid-version libtool option for modules (we only need an .so file...) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@709 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 83921b1784..4138baf1b2 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -146,17 +146,17 @@ endif ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_zt_la_LDFLAGS = -module +ozmod_zt_la_LDFLAGS = -module -avoid-version ozmod_zt_la_LIBADD = $(MYLIB) ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_skel_la_LDFLAGS = -module +ozmod_skel_la_LDFLAGS = -module -avoid-version ozmod_skel_la_LIBADD = $(MYLIB) ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_wanpipe_la_LDFLAGS = -module +ozmod_wanpipe_la_LDFLAGS = -module -avoid-version ozmod_wanpipe_la_LIBADD = $(MYLIB) ozmod_isdn_la_SOURCES = \ @@ -183,7 +183,7 @@ $(SRC)/isdn/Q932mes.c \ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE -ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module +ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -avoid-version ozmod_isdn_la_LIBADD = $(MYLIB) ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c @@ -193,18 +193,18 @@ ozmod_analog_la_LIBADD = $(MYLIB) ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_analog_em_la_LDFLAGS = -module +ozmod_analog_em_la_LDFLAGS = -module -avoid-version ozmod_analog_em_la_LIBADD = $(MYLIB) ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_ss7_boost_la_LDFLAGS = -module +ozmod_ss7_boost_la_LDFLAGS = -module -avoid-version ozmod_ss7_boost_la_LIBADD = $(MYLIB) if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_libpri_la_LDFLAGS = -module -lpri +ozmod_libpri_la_LDFLAGS = -module -avoid-version -lpri ozmod_libpri_la_LIBADD = $(MYLIB) endif From 41a1d719969c7e2fd337b02a6bac1b52dac555a2 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 9 Apr 2009 15:34:55 +0000 Subject: [PATCH 1368/1766] Add -avoid-version libtool option for modules (we only need an .so file...) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@709 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 83921b1784..4138baf1b2 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -146,17 +146,17 @@ endif ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_zt_la_LDFLAGS = -module +ozmod_zt_la_LDFLAGS = -module -avoid-version ozmod_zt_la_LIBADD = $(MYLIB) ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_skel_la_LDFLAGS = -module +ozmod_skel_la_LDFLAGS = -module -avoid-version ozmod_skel_la_LIBADD = $(MYLIB) ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_wanpipe_la_LDFLAGS = -module +ozmod_wanpipe_la_LDFLAGS = -module -avoid-version ozmod_wanpipe_la_LIBADD = $(MYLIB) ozmod_isdn_la_SOURCES = \ @@ -183,7 +183,7 @@ $(SRC)/isdn/Q932mes.c \ $(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE -ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module +ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -avoid-version ozmod_isdn_la_LIBADD = $(MYLIB) ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c @@ -193,18 +193,18 @@ ozmod_analog_la_LIBADD = $(MYLIB) ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_analog_em_la_LDFLAGS = -module +ozmod_analog_em_la_LDFLAGS = -module -avoid-version ozmod_analog_em_la_LIBADD = $(MYLIB) ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_ss7_boost_la_LDFLAGS = -module +ozmod_ss7_boost_la_LDFLAGS = -module -avoid-version ozmod_ss7_boost_la_LIBADD = $(MYLIB) if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_libpri_la_LDFLAGS = -module -lpri +ozmod_libpri_la_LDFLAGS = -module -avoid-version -lpri ozmod_libpri_la_LIBADD = $(MYLIB) endif From dda1f71279db7735295588d1eb00b378db1dbc53 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 9 Apr 2009 15:54:57 +0000 Subject: [PATCH 1369/1766] ...and do not forget ozmod_analog (-avoid-version for ozmod_*) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@710 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 4138baf1b2..3afec009d7 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -188,7 +188,7 @@ ozmod_isdn_la_LIBADD = $(MYLIB) ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_analog_la_LDFLAGS = -module +ozmod_analog_la_LDFLAGS = -module -avoid-version ozmod_analog_la_LIBADD = $(MYLIB) ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c From c00f23e6329a8167d0ba52e09992046e2d91e7ec Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 9 Apr 2009 15:54:57 +0000 Subject: [PATCH 1370/1766] ...and do not forget ozmod_analog (-avoid-version for ozmod_*) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@710 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 4138baf1b2..3afec009d7 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -188,7 +188,7 @@ ozmod_isdn_la_LIBADD = $(MYLIB) ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_analog_la_LDFLAGS = -module +ozmod_analog_la_LDFLAGS = -module -avoid-version ozmod_analog_la_LIBADD = $(MYLIB) ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c From 2c5d8695eb280defc274c618ad4842440877022b Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 19:50:36 +0000 Subject: [PATCH 1371/1766] Add 'omit_redirecting_number' option to libpri (opts param) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@711 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 11 +++++++++-- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index fff761035a..216782c7c5 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -86,6 +86,10 @@ static uint32_t parse_opts(const char *in) 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; } @@ -484,8 +488,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); - pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL); - + + 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); diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h index ec00cecef5..fd8f45f375 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -41,8 +41,9 @@ typedef enum { OZMOD_LIBPRI_OPT_NONE = 0, OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (2 << 0), - - OZMOD_LIBPRI_OPT_MAX = (3 << 0) + OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (3 << 0), + + OZMOD_LIBPRI_OPT_MAX = (4 << 0) } zap_isdn_opts_t; typedef enum { From 3487435ba9e1373cd1b8e44f55fc2baeed610a61 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 19:50:36 +0000 Subject: [PATCH 1372/1766] Add 'omit_redirecting_number' option to libpri (opts param) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@711 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 11 +++++++++-- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index fff761035a..216782c7c5 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -86,6 +86,10 @@ static uint32_t parse_opts(const char *in) 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; } @@ -484,8 +488,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); - pri_sr_set_redirecting(sr, zchan->caller_data.cid_num.digits, dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL); - + + 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); diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h index ec00cecef5..fd8f45f375 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -41,8 +41,9 @@ typedef enum { OZMOD_LIBPRI_OPT_NONE = 0, OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (2 << 0), - - OZMOD_LIBPRI_OPT_MAX = (3 << 0) + OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (3 << 0), + + OZMOD_LIBPRI_OPT_MAX = (4 << 0) } zap_isdn_opts_t; typedef enum { From 2cef898260210c4b5e0730e05638548cb3ab7316 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 20:27:50 +0000 Subject: [PATCH 1373/1766] right... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@712 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h index fd8f45f375..ac01a1fafa 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -40,10 +40,10 @@ typedef enum { OZMOD_LIBPRI_OPT_NONE = 0, OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), - OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (2 << 0), - OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (3 << 0), + OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1), + OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2), - OZMOD_LIBPRI_OPT_MAX = (4 << 0) + OZMOD_LIBPRI_OPT_MAX = (1 << 3) } zap_isdn_opts_t; typedef enum { From 01ba49d81cf0b017e90e5e05b2bfa1e415a03484 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 20:27:50 +0000 Subject: [PATCH 1374/1766] right... git-svn-id: http://svn.openzap.org/svn/openzap/trunk@712 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h index fd8f45f375..ac01a1fafa 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -40,10 +40,10 @@ typedef enum { OZMOD_LIBPRI_OPT_NONE = 0, OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), - OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (2 << 0), - OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (3 << 0), + OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1), + OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2), - OZMOD_LIBPRI_OPT_MAX = (4 << 0) + OZMOD_LIBPRI_OPT_MAX = (1 << 3) } zap_isdn_opts_t; typedef enum { From f584d301c0cfbb9ae9510b36e1500958f11adc24 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 21:13:16 +0000 Subject: [PATCH 1375/1766] ozmod_libpri: str2switch() Also accept 5ess for lucent5e git-svn-id: http://svn.openzap.org/svn/openzap/trunk@713 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 216782c7c5..e20dceb84d 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -905,7 +905,7 @@ static int str2switch(char *swtype) return PRI_SWITCH_NI2; if (!strcasecmp(swtype, "dms100")) return PRI_SWITCH_DMS100; - if (!strcasecmp(swtype, "lucent5e")) + if (!strcasecmp(swtype, "lucent5e") || !strcasecmp(swtype, "5ess")) return PRI_SWITCH_LUCENT5E; if (!strcasecmp(swtype, "att4ess")) return PRI_SWITCH_ATT4ESS; From c0f359bb4fe19b278de91dba75d1101c267f27e3 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 21:13:16 +0000 Subject: [PATCH 1376/1766] ozmod_libpri: str2switch() Also accept 5ess for lucent5e git-svn-id: http://svn.openzap.org/svn/openzap/trunk@713 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 216782c7c5..e20dceb84d 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -905,7 +905,7 @@ static int str2switch(char *swtype) return PRI_SWITCH_NI2; if (!strcasecmp(swtype, "dms100")) return PRI_SWITCH_DMS100; - if (!strcasecmp(swtype, "lucent5e")) + if (!strcasecmp(swtype, "lucent5e") || !strcasecmp(swtype, "5ess")) return PRI_SWITCH_LUCENT5E; if (!strcasecmp(swtype, "att4ess")) return PRI_SWITCH_ATT4ESS; From 3f89fae214b5609ae3e9eb0459676ce5e87de939 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 21:14:01 +0000 Subject: [PATCH 1377/1766] ozmod_libpri: str2switch() Also accept 4ess for att4ess git-svn-id: http://svn.openzap.org/svn/openzap/trunk@714 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index e20dceb84d..101a09ca85 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -907,7 +907,7 @@ static int str2switch(char *swtype) return PRI_SWITCH_DMS100; if (!strcasecmp(swtype, "lucent5e") || !strcasecmp(swtype, "5ess")) return PRI_SWITCH_LUCENT5E; - if (!strcasecmp(swtype, "att4ess")) + if (!strcasecmp(swtype, "att4ess") || !strcasecmp(swtype, "4ess")) return PRI_SWITCH_ATT4ESS; if (!strcasecmp(swtype, "euroisdn")) return PRI_SWITCH_EUROISDN_E1; From 1cc7635cd033f30c9c1c3b34f5ebb45ef6855da8 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 10 Apr 2009 21:14:01 +0000 Subject: [PATCH 1378/1766] ozmod_libpri: str2switch() Also accept 4ess for att4ess git-svn-id: http://svn.openzap.org/svn/openzap/trunk@714 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index e20dceb84d..101a09ca85 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -907,7 +907,7 @@ static int str2switch(char *swtype) return PRI_SWITCH_DMS100; if (!strcasecmp(swtype, "lucent5e") || !strcasecmp(swtype, "5ess")) return PRI_SWITCH_LUCENT5E; - if (!strcasecmp(swtype, "att4ess")) + if (!strcasecmp(swtype, "att4ess") || !strcasecmp(swtype, "4ess")) return PRI_SWITCH_ATT4ESS; if (!strcasecmp(swtype, "euroisdn")) return PRI_SWITCH_EUROISDN_E1; From cc55c2b6915b6b221d230147691042a7f674cd90 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 13 Apr 2009 19:11:27 +0000 Subject: [PATCH 1379/1766] increse fail count to 300 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@715 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index af688836aa..096b655ceb 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -864,7 +864,7 @@ static ZIO_READ_FUNCTION(zt_read) zap_ssize_t r = 0; int errs = 0; - while (errs++ < 100) { + while (errs++ < 300) { if ((r = read(zchan->sockfd, data, *datalen)) > 0) { break; } From 60ebf581162cfc1426474f075e255a14db25f950 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 13 Apr 2009 19:11:27 +0000 Subject: [PATCH 1380/1766] increse fail count to 300 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@715 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index af688836aa..096b655ceb 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -864,7 +864,7 @@ static ZIO_READ_FUNCTION(zt_read) zap_ssize_t r = 0; int errs = 0; - while (errs++ < 100) { + while (errs++ < 300) { if ((r = read(zchan->sockfd, data, *datalen)) > 0) { break; } From cafe6e82adf4afdcf4bd31872e57cdd1f16aa44d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 14 Apr 2009 19:03:03 +0000 Subject: [PATCH 1381/1766] move codec destroy to destroy method like the other channels git-svn-id: http://svn.openzap.org/svn/openzap/trunk@716 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 36 +++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a64cea508a..74339be232 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -116,6 +116,7 @@ typedef struct private_object private_t; static switch_status_t channel_on_init(switch_core_session_t *session); static switch_status_t channel_on_hangup(switch_core_session_t *session); +static switch_status_t channel_on_destroy(switch_core_session_t *session); static switch_status_t channel_on_routing(switch_core_session_t *session); static switch_status_t channel_on_exchange_media(switch_core_session_t *session); static switch_status_t channel_on_soft_execute(switch_core_session_t *session); @@ -409,6 +410,24 @@ static switch_status_t channel_on_execute(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } +static switch_status_t channel_on_destroy(switch_core_session_t *session) +{ + private_t *tech_pvt = NULL; + + if ((tech_pvt = switch_core_session_get_private(session))) { + + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + } + + return SWITCH_STATUS_SUCCESS; +} + static switch_status_t channel_on_hangup(switch_core_session_t *session) { switch_channel_t *channel = NULL; @@ -462,14 +481,6 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) } switch_clear_flag_locked(tech_pvt, TFLAG_IO); - - if (tech_pvt->read_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->read_codec); - } - - if (tech_pvt->write_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->write_codec); - } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); switch_mutex_lock(globals.mutex); @@ -868,7 +879,14 @@ switch_state_handler_table_t openzap_state_handlers = { /*.on_execute */ channel_on_execute, /*.on_hangup */ channel_on_hangup, /*.on_exchange_media */ channel_on_exchange_media, - /*.on_soft_execute */ channel_on_soft_execute + /*.on_soft_execute */ channel_on_soft_execute, + /*.on_consume_media */ NULL, + /*.on_hibernate */ NULL, + /*.on_reset */ NULL, + /*.on_park*/ NULL, + /*.on_reporting*/ NULL, + /*.on_destroy*/ channel_on_destroy + }; switch_io_routines_t openzap_io_routines = { From 3e4a7c03ab26e8a8ca0e284d897e09e7939c91fd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 14 Apr 2009 19:03:03 +0000 Subject: [PATCH 1382/1766] move codec destroy to destroy method like the other channels git-svn-id: http://svn.openzap.org/svn/openzap/trunk@716 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 36 +++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a64cea508a..74339be232 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -116,6 +116,7 @@ typedef struct private_object private_t; static switch_status_t channel_on_init(switch_core_session_t *session); static switch_status_t channel_on_hangup(switch_core_session_t *session); +static switch_status_t channel_on_destroy(switch_core_session_t *session); static switch_status_t channel_on_routing(switch_core_session_t *session); static switch_status_t channel_on_exchange_media(switch_core_session_t *session); static switch_status_t channel_on_soft_execute(switch_core_session_t *session); @@ -409,6 +410,24 @@ static switch_status_t channel_on_execute(switch_core_session_t *session) return SWITCH_STATUS_SUCCESS; } +static switch_status_t channel_on_destroy(switch_core_session_t *session) +{ + private_t *tech_pvt = NULL; + + if ((tech_pvt = switch_core_session_get_private(session))) { + + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + } + + return SWITCH_STATUS_SUCCESS; +} + static switch_status_t channel_on_hangup(switch_core_session_t *session) { switch_channel_t *channel = NULL; @@ -462,14 +481,6 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) } switch_clear_flag_locked(tech_pvt, TFLAG_IO); - - if (tech_pvt->read_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->read_codec); - } - - if (tech_pvt->write_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->write_codec); - } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); switch_mutex_lock(globals.mutex); @@ -868,7 +879,14 @@ switch_state_handler_table_t openzap_state_handlers = { /*.on_execute */ channel_on_execute, /*.on_hangup */ channel_on_hangup, /*.on_exchange_media */ channel_on_exchange_media, - /*.on_soft_execute */ channel_on_soft_execute + /*.on_soft_execute */ channel_on_soft_execute, + /*.on_consume_media */ NULL, + /*.on_hibernate */ NULL, + /*.on_reset */ NULL, + /*.on_park*/ NULL, + /*.on_reporting*/ NULL, + /*.on_destroy*/ channel_on_destroy + }; switch_io_routines_t openzap_io_routines = { From 25726f7a9bd81d36074e5bb3dba151d34bb34e44 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 14 Apr 2009 19:37:42 +0000 Subject: [PATCH 1383/1766] avoyding dedwock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@717 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index c2219d309f..aea2ae3e42 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -942,7 +942,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t } zap_mutex_lock(span->mutex); - + if (direction == ZAP_TOP_DOWN) { i = 1; } else { @@ -963,8 +963,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t if (!(check = span->channels[i])) { status = ZAP_FAIL; - zap_mutex_unlock(span->mutex); - goto done; + break; } if (zap_test_flag(check, ZAP_CHANNEL_READY) && @@ -975,8 +974,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t if (span && span->channel_request) { status = span->channel_request(span, i, direction, caller_data, zchan); - zap_mutex_unlock(span->mutex); - goto done; + break; } status = check->zio->open(check); @@ -985,8 +983,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_channel_open_chan(check); *zchan = check; - zap_mutex_unlock(span->mutex); - goto done; + break; } } @@ -997,8 +994,8 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t } } - done: - + zap_mutex_unlock(span->mutex); + return status; } From db385f5175c218ebc115bd6dd65828f091a8dc77 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 14 Apr 2009 19:37:42 +0000 Subject: [PATCH 1384/1766] avoyding dedwock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@717 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index c2219d309f..aea2ae3e42 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -942,7 +942,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t } zap_mutex_lock(span->mutex); - + if (direction == ZAP_TOP_DOWN) { i = 1; } else { @@ -963,8 +963,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t if (!(check = span->channels[i])) { status = ZAP_FAIL; - zap_mutex_unlock(span->mutex); - goto done; + break; } if (zap_test_flag(check, ZAP_CHANNEL_READY) && @@ -975,8 +974,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t if (span && span->channel_request) { status = span->channel_request(span, i, direction, caller_data, zchan); - zap_mutex_unlock(span->mutex); - goto done; + break; } status = check->zio->open(check); @@ -985,8 +983,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t zap_set_flag(check, ZAP_CHANNEL_INUSE); zap_channel_open_chan(check); *zchan = check; - zap_mutex_unlock(span->mutex); - goto done; + break; } } @@ -997,8 +994,8 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t } } - done: - + zap_mutex_unlock(span->mutex); + return status; } From 54c7bbecef1802157df32d521c17c09a435e12dc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 Apr 2009 23:06:05 +0000 Subject: [PATCH 1385/1766] _patches git-svn-id: http://svn.openzap.org/svn/openzap/trunk@718 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/patches/oz.diff | 1110 ++++++++++++++++++++++++++++++++++ 1 file changed, 1110 insertions(+) create mode 100644 libs/openzap/patches/oz.diff diff --git a/libs/openzap/patches/oz.diff b/libs/openzap/patches/oz.diff new file mode 100644 index 0000000000..2b8fa60012 --- /dev/null +++ b/libs/openzap/patches/oz.diff @@ -0,0 +1,1110 @@ +Index: src/ozmod/ozmod_ss7_boost/sigboost.h +=================================================================== +--- src/ozmod/ozmod_ss7_boost/sigboost.h (revision 717) ++++ src/ozmod/ozmod_ss7_boost/sigboost.h (working copy) +@@ -1,5 +1,5 @@ + /**************************************************************************** +- * sigboost.h $Revision: 1.5 $ ++ * sigboost.h $Revision: 1.13 $ + * + * Definitions for the sigboost interface. + * +@@ -14,6 +14,8 @@ + #ifndef _SIGBOOST_H_ + #define _SIGBOOST_H_ + ++#define SIGBOOST_VERSION 100 ++ + #include + #include + +@@ -48,16 +50,24 @@ + + 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, ++ //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 */ ++}; ++ + #define MAX_DIALED_DIGITS 31 + + /* Next two defines are used to create the range of values for call_setup_id +@@ -67,63 +77,73 @@ + #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 128 ++#define SIZE_RDNIS 900 + ++ + #pragma pack(1) ++ + typedef struct + { +- uint32_t event_id; ++ uint8_t capability; ++ uint8_t uil1p; ++}t_sigboost_bearer; ++ ++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; +- struct timeval tv; +- 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 */ ++ uint32_t fseqno; ++ uint32_t bseqno; ++ uint16_t call_setup_id; ++ uint32_t trunk_group; ++ uint8_t span; ++ uint8_t chan; ++ struct timeval tv; ++ 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 */ + /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ +- uint8_t calling_number_screening_ind; +- uint8_t calling_number_presentation; +- char calling_name[MAX_DIALED_DIGITS + 1]; +- uint16_t redirection_string_size; +- char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ +- /* redir string format: +- * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection +- * */ ++ uint8_t calling_number_screening_ind; ++ uint8_t calling_number_presentation; ++ char calling_name[MAX_DIALED_DIGITS + 1]; ++ t_sigboost_bearer bearer; ++ uint8_t hunt_group; ++ uint16_t isup_in_rdnis_size; ++ char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ + } t_sigboost_callstart; + +-#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) ++#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS + + typedef struct + { +- uint32_t event_id; ++ 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; +- struct timeval tv; +- uint8_t release_cause; ++ uint32_t fseqno; ++ uint32_t bseqno; ++ uint16_t call_setup_id; ++ uint32_t trunk_group; ++ uint8_t span; ++ uint8_t chan; ++ 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: +- return 1; +- default: +- return 0; +- } ++ switch (event_id) { ++ case SIGBOOST_EVENT_CALL_START: ++ case SIGBOOST_EVENT_DIGIT_IN: ++ return 1; ++ default: ++ return 0; ++ } + +- return 0; ++ return 0; + } + ++ + #endif +Index: src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +=================================================================== +--- src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (revision 717) ++++ src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (working copy) +@@ -73,7 +73,7 @@ + { + if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) + return; +- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", ++ 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]\n", + dir ? "TX":"RX", + ss7bc_event_id_name(event->event_id), + event->event_id, +@@ -91,7 +91,7 @@ + { + if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) + return; +- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", ++ 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", + ss7bc_event_id_name(event->event_id), +@@ -261,6 +261,10 @@ + bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, + (struct sockaddr *) &mcon->local_addr, &fromlen); + ++ 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; +@@ -293,7 +297,7 @@ + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); + } + +-#if 1 ++#if 0 + /* NC: NOT USED ANY MORE */ + if (mcon->rxseq_reset) { + //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { +@@ -310,15 +314,17 @@ + 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, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); ++ zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + return NULL; + } + } +@@ -332,6 +338,10 @@ + int bytes = 0; + + bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); ++ ++ 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(ss7bc_short_event_t)) { + +@@ -356,7 +366,7 @@ + int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) + { + int err; +- int event_size=sizeof(ss7bc_event_t); ++ 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"); +@@ -395,6 +405,7 @@ + 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); +@@ -432,6 +443,7 @@ + gettimeofday(&event->tv, NULL); + + 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); + +Index: src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +=================================================================== +--- src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (revision 717) ++++ src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (working copy) +@@ -215,7 +215,11 @@ + + ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + zap_set_string(event.calling_name, caller_data->cid_name); +- zap_set_string(event.redirection_string, caller_data->rdnis.digits); ++ zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); ++ if (strlen(caller_data->rdnis.digits)) { ++ event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; ++ } ++ + event.calling_number_screening_ind = caller_data->screen; + event.calling_number_presentation = caller_data->pres; + +@@ -483,7 +487,7 @@ + } + zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); +- zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); ++ zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + zchan->caller_data.screen = event->calling_number_screening_ind; + zchan->caller_data.pres = event->calling_number_presentation; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); +@@ -851,7 +855,7 @@ + zap_span_t *span = (zap_span_t *) obj; + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + ss7bc_connection_t *mcon, *pcon; +- uint32_t ms = 10, too_long = 20000; ++ uint32_t ms = 10; //, too_long = 20000; + + + ss7_boost_data->pcon = ss7_boost_data->mcon; +@@ -942,6 +946,8 @@ + 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); +@@ -953,6 +959,7 @@ + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + } ++#endif + + if (zap_running()) { + check_state(span); +@@ -1094,7 +1101,7 @@ + { + zap_ss7_boost_data_t *ss7_boost_data = NULL; + const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; +- int local_port = 5300, remote_port = 5300; ++ int local_port = 53000, remote_port = 53000; + char *var, *val; + int *intval; + +Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +=================================================================== +--- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 717) ++++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) +@@ -38,7 +38,7 @@ + #include "openzap.h" + #include + #include +-#include "wanpipe_tdm_api_iface.h" ++#include "libsangoma.h" + + typedef enum { + WP_RINGING = (1 << 0) +@@ -57,196 +57,28 @@ + ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); + +-#define WP_INVALID_SOCKET -1 +-/* 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 */ +- uint32_t 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; ++#define WP_INVALID_SOCKET -1 + +- 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; +-} +- + /* 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; ++#ifdef LIBSANGOMA_VERSION ++ int err; ++ sangoma_wait_obj_t sangoma_wait_obj; + +- if (!DeviceIoControl( +- fd, +- IoctlApiPoll, +- (LPVOID)NULL, +- 0L, +- (LPVOID)&api_poll, +- sizeof(API_POLL_STRUCT), +- (LPDWORD)(&ln), +- (LPOVERLAPPED)NULL)) { +- return -1; +- } ++ sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); + +- *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; ++ err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); ++ if (err > 0) { ++ *flags=sangoma_wait_obj.flags_out; + } ++ return err; + +- if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { +- return 0; +- } +- +- *flags = api_poll.poll_events_bitmap; +- +- return 1; + #else +- struct pollfd pfds[1]; ++ struct pollfd pfds[1]; + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); +@@ -265,87 +97,18 @@ + + return res; + #endif ++ + } + +-#define FNAME_LEN 128 + static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) + { +- char fname[FNAME_LEN]; +- sng_fd_t fd = WP_INVALID_SOCKET; +-#if defined(__WINDOWS__) +- DWORD ln; +- wan_udp_hdr_t wan_udp; +- +- /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ +- /* Subtract 1 from 'chan'. */ +- _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); +- +- fd = CreateFile( fname, +- GENERIC_READ | GENERIC_WRITE, +- FILE_SHARE_READ | FILE_SHARE_WRITE, +- (LPSECURITY_ATTRIBUTES)NULL, +- OPEN_EXISTING, +- FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, +- (HANDLE)NULL +- ); +- +- /* make sure that we are the only ones who have this chan open */ +- /* is this a threadsafe way to make sure that we are ok and will */ +- /* never return a valid handle to more than one thread for the same channel? */ +- +- wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; +- wan_udp.wan_udphdr_data_len = 0; +- +- DeviceIoControl( +- fd, +- IoctlManagementCommand, +- (LPVOID)&wan_udp, +- sizeof(wan_udp_hdr_t), +- (LPVOID)&wan_udp, +- sizeof(wan_udp_hdr_t), +- (LPDWORD)(&ln), +- (LPOVERLAPPED)NULL +- ); +- +- if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ +- /* somone already has this channel, or somthing else is not right. */ +- tdmv_api_close_socket(&fd); +- } +- +-#else +- /* Does this fail if another thread already has this chan open? */ +- /* if not, we need to add some code to make sure it does */ +- snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); +- +- fd = open(fname, O_RDWR); +- +- if (fd < 0) { +- fd = WP_INVALID_SOCKET; +- } +- +-#endif +- return fd; ++ return sangoma_open_tdmapi_span_chan(span, chan); + } + + + + static zap_io_interface_t wanpipe_interface; + +-static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) +-{ +- int err; +- +- /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ +- err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); +- +- if (err) { +- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); +- return ZAP_FAIL; +- } +- +- return ZAP_SUCCESS; +-} +- + static unsigned char wanpipe_swap_bits(unsigned char cas_bits) + { + unsigned char swapped_bits = 0x0; +@@ -379,43 +142,17 @@ + + if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + wanpipe_tdm_api_t tdm_api; ++ memset(&tdm_api,0,sizeof(tdm_api)); + zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + chan->physical_span_id = spanno; + chan->physical_chan_id = x; + chan->rate = 8000; + +- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { +- +- +-#if 1 +- if (type == ZAP_CHAN_TYPE_FXO) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +- } +-#endif +- +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +-#if 1 +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +-#endif +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +- +- } +- + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; +- wp_tdm_cmd_exec(chan, &tdm_api); ++ int err; ++ ++ /* FIXME: Handle Error Conditino 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 { +@@ -423,10 +160,24 @@ + } + } + ++#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) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; +- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); +- wp_tdm_cmd_exec(chan, &tdm_api); ++#ifdef LIBSANGOMA_VERSION ++ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); ++#else ++ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); ++#endif + } + + if (!zap_strlen_zero(name)) { +@@ -550,18 +301,31 @@ + static ZIO_OPEN_FUNCTION(wanpipe_open) + { + ++ int err; + wanpipe_tdm_api_t tdm_api; + ++ memset(&tdm_api,0,sizeof(tdm_api)); ++ + 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; +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; +- tdm_api.wp_tdm_cmd.tdm_codec = 0; +- wp_tdm_cmd_exec(zchan, &tdm_api); +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; +- tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; +- wp_tdm_cmd_exec(zchan, &tdm_api); ++ ++ sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, wp_globals.codec_ms); ++ ++ err=sangoma_tdm_get_hw_dtmf(zchan->sockfd, &tdm_api); ++ if (err > 0) { ++ err=sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api); ++ if (err == 0) { ++ //zap_log(ZAP_LOG_DEBUG, "Enabling HW DTMF FEATURE\n"); ++ zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); ++ } else { ++ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); ++ } ++ } else { ++ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); ++ } ++ + 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; +@@ -585,10 +349,8 @@ + switch(command) { + case ZAP_COMMAND_OFFHOOK: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); + return ZAP_FAIL; + } +@@ -597,10 +359,8 @@ + break; + case ZAP_COMMAND_ONHOOK: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); + return ZAP_FAIL; + } +@@ -609,9 +369,8 @@ + break; + case ZAP_COMMAND_GENERATE_RING_ON: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); + return ZAP_FAIL; + } +@@ -622,9 +381,8 @@ + break; + case ZAP_COMMAND_GENERATE_RING_OFF: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ 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; + } +@@ -634,27 +392,26 @@ + break; + case ZAP_COMMAND_GET_INTERVAL: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; +- +- if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { +- ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; ++ err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); ++ if (err > 0 ) { ++ ZAP_COMMAND_OBJ_INT = err; ++ err=0; + } +- + } + break; + case ZAP_COMMAND_SET_INTERVAL: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; +- tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; +- err = wp_tdm_cmd_exec(zchan, &tdm_api); ++ 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: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; +- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); +- err = wp_tdm_cmd_exec(zchan, &tdm_api); ++#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: +@@ -683,7 +440,7 @@ + + memset(&hdrframe, 0, sizeof(hdrframe)); + +- rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); ++ rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); + + *datalen = rx_len; + +@@ -702,7 +459,7 @@ + + /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ + memset(&hdrframe, 0, sizeof(hdrframe)); +- bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); ++ 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) { +@@ -759,19 +516,29 @@ + return ZAP_SUCCESS; + } + +-#ifndef WIN32 + ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) + { ++#ifdef LIBSANGOMA_VERSION ++ sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; ++#else + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; ++#endif ++ + uint32_t i, j = 0, k = 0, l = 0; ++ int objects=0; + int r; + + for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = span->channels[i]; ++ ++#ifdef LIBSANGOMA_VERSION ++ sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); ++#else + memset(&pfds[j], 0, sizeof(pfds[j])); + pfds[j].fd = span->channels[i]->sockfd; + pfds[j].events = POLLPRI; +- ++#endif ++ objects++; + /* 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)) { +@@ -789,20 +556,16 @@ + int err; + memset(&tdm_api, 0, sizeof(tdm_api)); + if (zap_test_pflag(zchan, WP_RINGING)) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ 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 { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); + return ZAP_FAIL; + } +@@ -815,9 +578,12 @@ + if (l) { + ms = l; + } ++#ifdef LIBSANGOMA_VERSION ++ r = sangoma_socket_waitfor_many(pfds,objects,ms); ++#else ++ r = poll(pfds, j, ms); ++#endif + +- r = poll(pfds, j, ms); +- + if (r == 0) { + return l ? ZAP_SUCCESS : ZAP_TIMEOUT; + } else if (r < 0) { +@@ -828,7 +594,11 @@ + for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = span->channels[i]; + ++#ifdef LIBSANGOMA_VERSION ++ if (pfds[i-1].flags_out & 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++; +@@ -836,15 +606,43 @@ + } + + +- + return k ? ZAP_SUCCESS : ZAP_FAIL; + } + ++ ++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 = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; ++ ++ return ZAP_SUCCESS; ++} ++ ++ + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) + { +- uint32_t i; ++ uint32_t i,err; + zap_oob_event_t event_id; + + for(i = 1; i <= span->chan_count; i++) { +@@ -869,29 +667,43 @@ + 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)); +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(span->channels[i], &tdm_api); ++ ++ sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + } + 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); + +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; +- if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { ++ 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; + } + + switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { ++ ++ case WP_TDMAPI_EVENT_LINK_STATUS: ++ { ++ 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; ++ }; ++ } ++ break; ++ + case WP_TDMAPI_EVENT_RXHOOK: + { + if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { +@@ -918,11 +730,9 @@ + continue; + } else { + int err; +- +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { ++ 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; + } +@@ -948,6 +758,17 @@ + span->channels[i]->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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); ++ if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { ++ zap_channel_queue_dtmf(zchan, tmp_dtmf); ++ } ++ } ++ break; + default: + { + zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); +@@ -1005,6 +826,7 @@ + #endif + 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; +Index: configure.ac +=================================================================== +--- configure.ac (revision 717) ++++ configure.ac (working copy) +@@ -155,6 +155,9 @@ + [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) + AC_SUBST(enable_libpri) + ++AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) ++AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) ++ + AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) + + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" +Index: Makefile.am +=================================================================== +--- Makefile.am (revision 717) ++++ Makefile.am (working copy) +@@ -154,10 +154,12 @@ + ozmod_skel_la_LDFLAGS = -module -avoid-version + ozmod_skel_la_LIBADD = $(MYLIB) + ++if LIBSANGOMA + ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +-ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +-ozmod_wanpipe_la_LDFLAGS = -module -avoid-version ++ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe ++ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma + ozmod_wanpipe_la_LIBADD = $(MYLIB) ++endif + + ozmod_isdn_la_SOURCES = \ + $(SRC)/isdn/EuroISDNStateNT.c \ From a378191ff60203be2b6d419dd7a9d12a244c1b03 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 Apr 2009 23:06:05 +0000 Subject: [PATCH 1386/1766] _patches git-svn-id: http://svn.openzap.org/svn/openzap/trunk@718 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/patches/oz.diff | 1110 ++++++++++++++++++++++++++++++++++ 1 file changed, 1110 insertions(+) create mode 100644 libs/freetdm/patches/oz.diff diff --git a/libs/freetdm/patches/oz.diff b/libs/freetdm/patches/oz.diff new file mode 100644 index 0000000000..2b8fa60012 --- /dev/null +++ b/libs/freetdm/patches/oz.diff @@ -0,0 +1,1110 @@ +Index: src/ozmod/ozmod_ss7_boost/sigboost.h +=================================================================== +--- src/ozmod/ozmod_ss7_boost/sigboost.h (revision 717) ++++ src/ozmod/ozmod_ss7_boost/sigboost.h (working copy) +@@ -1,5 +1,5 @@ + /**************************************************************************** +- * sigboost.h $Revision: 1.5 $ ++ * sigboost.h $Revision: 1.13 $ + * + * Definitions for the sigboost interface. + * +@@ -14,6 +14,8 @@ + #ifndef _SIGBOOST_H_ + #define _SIGBOOST_H_ + ++#define SIGBOOST_VERSION 100 ++ + #include + #include + +@@ -48,16 +50,24 @@ + + 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, ++ //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 */ ++}; ++ + #define MAX_DIALED_DIGITS 31 + + /* Next two defines are used to create the range of values for call_setup_id +@@ -67,63 +77,73 @@ + #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 128 ++#define SIZE_RDNIS 900 + ++ + #pragma pack(1) ++ + typedef struct + { +- uint32_t event_id; ++ uint8_t capability; ++ uint8_t uil1p; ++}t_sigboost_bearer; ++ ++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; +- struct timeval tv; +- 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 */ ++ uint32_t fseqno; ++ uint32_t bseqno; ++ uint16_t call_setup_id; ++ uint32_t trunk_group; ++ uint8_t span; ++ uint8_t chan; ++ struct timeval tv; ++ 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 */ + /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ +- uint8_t calling_number_screening_ind; +- uint8_t calling_number_presentation; +- char calling_name[MAX_DIALED_DIGITS + 1]; +- uint16_t redirection_string_size; +- char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ +- /* redir string format: +- * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection +- * */ ++ uint8_t calling_number_screening_ind; ++ uint8_t calling_number_presentation; ++ char calling_name[MAX_DIALED_DIGITS + 1]; ++ t_sigboost_bearer bearer; ++ uint8_t hunt_group; ++ uint16_t isup_in_rdnis_size; ++ char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ + } t_sigboost_callstart; + +-#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) ++#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS + + typedef struct + { +- uint32_t event_id; ++ 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; +- struct timeval tv; +- uint8_t release_cause; ++ uint32_t fseqno; ++ uint32_t bseqno; ++ uint16_t call_setup_id; ++ uint32_t trunk_group; ++ uint8_t span; ++ uint8_t chan; ++ 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: +- return 1; +- default: +- return 0; +- } ++ switch (event_id) { ++ case SIGBOOST_EVENT_CALL_START: ++ case SIGBOOST_EVENT_DIGIT_IN: ++ return 1; ++ default: ++ return 0; ++ } + +- return 0; ++ return 0; + } + ++ + #endif +Index: src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +=================================================================== +--- src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (revision 717) ++++ src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (working copy) +@@ -73,7 +73,7 @@ + { + if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) + return; +- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", ++ 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]\n", + dir ? "TX":"RX", + ss7bc_event_id_name(event->event_id), + event->event_id, +@@ -91,7 +91,7 @@ + { + if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) + return; +- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", ++ 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", + ss7bc_event_id_name(event->event_id), +@@ -261,6 +261,10 @@ + bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, + (struct sockaddr *) &mcon->local_addr, &fromlen); + ++ 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; +@@ -293,7 +297,7 @@ + ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); + } + +-#if 1 ++#if 0 + /* NC: NOT USED ANY MORE */ + if (mcon->rxseq_reset) { + //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { +@@ -310,15 +314,17 @@ + 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, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); ++ zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + return NULL; + } + } +@@ -332,6 +338,10 @@ + int bytes = 0; + + bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); ++ ++ 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(ss7bc_short_event_t)) { + +@@ -356,7 +366,7 @@ + int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) + { + int err; +- int event_size=sizeof(ss7bc_event_t); ++ 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"); +@@ -395,6 +405,7 @@ + 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); +@@ -432,6 +443,7 @@ + gettimeofday(&event->tv, NULL); + + 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); + +Index: src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +=================================================================== +--- src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (revision 717) ++++ src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (working copy) +@@ -215,7 +215,11 @@ + + ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + zap_set_string(event.calling_name, caller_data->cid_name); +- zap_set_string(event.redirection_string, caller_data->rdnis.digits); ++ zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); ++ if (strlen(caller_data->rdnis.digits)) { ++ event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; ++ } ++ + event.calling_number_screening_ind = caller_data->screen; + event.calling_number_presentation = caller_data->pres; + +@@ -483,7 +487,7 @@ + } + zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); + zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); +- zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); ++ zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + zchan->caller_data.screen = event->calling_number_screening_ind; + zchan->caller_data.pres = event->calling_number_presentation; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); +@@ -851,7 +855,7 @@ + zap_span_t *span = (zap_span_t *) obj; + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + ss7bc_connection_t *mcon, *pcon; +- uint32_t ms = 10, too_long = 20000; ++ uint32_t ms = 10; //, too_long = 20000; + + + ss7_boost_data->pcon = ss7_boost_data->mcon; +@@ -942,6 +946,8 @@ + 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); +@@ -953,6 +959,7 @@ + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + } ++#endif + + if (zap_running()) { + check_state(span); +@@ -1094,7 +1101,7 @@ + { + zap_ss7_boost_data_t *ss7_boost_data = NULL; + const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; +- int local_port = 5300, remote_port = 5300; ++ int local_port = 53000, remote_port = 53000; + char *var, *val; + int *intval; + +Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +=================================================================== +--- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 717) ++++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) +@@ -38,7 +38,7 @@ + #include "openzap.h" + #include + #include +-#include "wanpipe_tdm_api_iface.h" ++#include "libsangoma.h" + + typedef enum { + WP_RINGING = (1 << 0) +@@ -57,196 +57,28 @@ + ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); + +-#define WP_INVALID_SOCKET -1 +-/* 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 */ +- uint32_t 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; ++#define WP_INVALID_SOCKET -1 + +- 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; +-} +- + /* 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; ++#ifdef LIBSANGOMA_VERSION ++ int err; ++ sangoma_wait_obj_t sangoma_wait_obj; + +- if (!DeviceIoControl( +- fd, +- IoctlApiPoll, +- (LPVOID)NULL, +- 0L, +- (LPVOID)&api_poll, +- sizeof(API_POLL_STRUCT), +- (LPDWORD)(&ln), +- (LPOVERLAPPED)NULL)) { +- return -1; +- } ++ sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); + +- *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; ++ err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); ++ if (err > 0) { ++ *flags=sangoma_wait_obj.flags_out; + } ++ return err; + +- if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { +- return 0; +- } +- +- *flags = api_poll.poll_events_bitmap; +- +- return 1; + #else +- struct pollfd pfds[1]; ++ struct pollfd pfds[1]; + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); +@@ -265,87 +97,18 @@ + + return res; + #endif ++ + } + +-#define FNAME_LEN 128 + static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) + { +- char fname[FNAME_LEN]; +- sng_fd_t fd = WP_INVALID_SOCKET; +-#if defined(__WINDOWS__) +- DWORD ln; +- wan_udp_hdr_t wan_udp; +- +- /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ +- /* Subtract 1 from 'chan'. */ +- _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); +- +- fd = CreateFile( fname, +- GENERIC_READ | GENERIC_WRITE, +- FILE_SHARE_READ | FILE_SHARE_WRITE, +- (LPSECURITY_ATTRIBUTES)NULL, +- OPEN_EXISTING, +- FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, +- (HANDLE)NULL +- ); +- +- /* make sure that we are the only ones who have this chan open */ +- /* is this a threadsafe way to make sure that we are ok and will */ +- /* never return a valid handle to more than one thread for the same channel? */ +- +- wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; +- wan_udp.wan_udphdr_data_len = 0; +- +- DeviceIoControl( +- fd, +- IoctlManagementCommand, +- (LPVOID)&wan_udp, +- sizeof(wan_udp_hdr_t), +- (LPVOID)&wan_udp, +- sizeof(wan_udp_hdr_t), +- (LPDWORD)(&ln), +- (LPOVERLAPPED)NULL +- ); +- +- if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ +- /* somone already has this channel, or somthing else is not right. */ +- tdmv_api_close_socket(&fd); +- } +- +-#else +- /* Does this fail if another thread already has this chan open? */ +- /* if not, we need to add some code to make sure it does */ +- snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); +- +- fd = open(fname, O_RDWR); +- +- if (fd < 0) { +- fd = WP_INVALID_SOCKET; +- } +- +-#endif +- return fd; ++ return sangoma_open_tdmapi_span_chan(span, chan); + } + + + + static zap_io_interface_t wanpipe_interface; + +-static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) +-{ +- int err; +- +- /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ +- err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); +- +- if (err) { +- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); +- return ZAP_FAIL; +- } +- +- return ZAP_SUCCESS; +-} +- + static unsigned char wanpipe_swap_bits(unsigned char cas_bits) + { + unsigned char swapped_bits = 0x0; +@@ -379,43 +142,17 @@ + + if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + wanpipe_tdm_api_t tdm_api; ++ memset(&tdm_api,0,sizeof(tdm_api)); + zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + chan->physical_span_id = spanno; + chan->physical_chan_id = x; + chan->rate = 8000; + +- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { +- +- +-#if 1 +- if (type == ZAP_CHAN_TYPE_FXO) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +- } +-#endif +- +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +-#if 1 +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +-#endif +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(chan, &tdm_api); +- +- } +- + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; +- wp_tdm_cmd_exec(chan, &tdm_api); ++ int err; ++ ++ /* FIXME: Handle Error Conditino 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 { +@@ -423,10 +160,24 @@ + } + } + ++#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) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; +- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); +- wp_tdm_cmd_exec(chan, &tdm_api); ++#ifdef LIBSANGOMA_VERSION ++ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); ++#else ++ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); ++#endif + } + + if (!zap_strlen_zero(name)) { +@@ -550,18 +301,31 @@ + static ZIO_OPEN_FUNCTION(wanpipe_open) + { + ++ int err; + wanpipe_tdm_api_t tdm_api; + ++ memset(&tdm_api,0,sizeof(tdm_api)); ++ + 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; +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; +- tdm_api.wp_tdm_cmd.tdm_codec = 0; +- wp_tdm_cmd_exec(zchan, &tdm_api); +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; +- tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; +- wp_tdm_cmd_exec(zchan, &tdm_api); ++ ++ sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, wp_globals.codec_ms); ++ ++ err=sangoma_tdm_get_hw_dtmf(zchan->sockfd, &tdm_api); ++ if (err > 0) { ++ err=sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api); ++ if (err == 0) { ++ //zap_log(ZAP_LOG_DEBUG, "Enabling HW DTMF FEATURE\n"); ++ zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); ++ } else { ++ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); ++ } ++ } else { ++ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); ++ } ++ + 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; +@@ -585,10 +349,8 @@ + switch(command) { + case ZAP_COMMAND_OFFHOOK: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); + return ZAP_FAIL; + } +@@ -597,10 +359,8 @@ + break; + case ZAP_COMMAND_ONHOOK: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); + return ZAP_FAIL; + } +@@ -609,9 +369,8 @@ + break; + case ZAP_COMMAND_GENERATE_RING_ON: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); + return ZAP_FAIL; + } +@@ -622,9 +381,8 @@ + break; + case ZAP_COMMAND_GENERATE_RING_OFF: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ 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; + } +@@ -634,27 +392,26 @@ + break; + case ZAP_COMMAND_GET_INTERVAL: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; +- +- if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { +- ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; ++ err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); ++ if (err > 0 ) { ++ ZAP_COMMAND_OBJ_INT = err; ++ err=0; + } +- + } + break; + case ZAP_COMMAND_SET_INTERVAL: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; +- tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; +- err = wp_tdm_cmd_exec(zchan, &tdm_api); ++ 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: + { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; +- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); +- err = wp_tdm_cmd_exec(zchan, &tdm_api); ++#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: +@@ -683,7 +440,7 @@ + + memset(&hdrframe, 0, sizeof(hdrframe)); + +- rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); ++ rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); + + *datalen = rx_len; + +@@ -702,7 +459,7 @@ + + /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ + memset(&hdrframe, 0, sizeof(hdrframe)); +- bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); ++ 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) { +@@ -759,19 +516,29 @@ + return ZAP_SUCCESS; + } + +-#ifndef WIN32 + ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) + { ++#ifdef LIBSANGOMA_VERSION ++ sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; ++#else + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; ++#endif ++ + uint32_t i, j = 0, k = 0, l = 0; ++ int objects=0; + int r; + + for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = span->channels[i]; ++ ++#ifdef LIBSANGOMA_VERSION ++ sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); ++#else + memset(&pfds[j], 0, sizeof(pfds[j])); + pfds[j].fd = span->channels[i]->sockfd; + pfds[j].events = POLLPRI; +- ++#endif ++ objects++; + /* 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)) { +@@ -789,20 +556,16 @@ + int err; + memset(&tdm_api, 0, sizeof(tdm_api)); + if (zap_test_pflag(zchan, WP_RINGING)) { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ 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 { +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { ++ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); ++ if (err) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); + return ZAP_FAIL; + } +@@ -815,9 +578,12 @@ + if (l) { + ms = l; + } ++#ifdef LIBSANGOMA_VERSION ++ r = sangoma_socket_waitfor_many(pfds,objects,ms); ++#else ++ r = poll(pfds, j, ms); ++#endif + +- r = poll(pfds, j, ms); +- + if (r == 0) { + return l ? ZAP_SUCCESS : ZAP_TIMEOUT; + } else if (r < 0) { +@@ -828,7 +594,11 @@ + for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = span->channels[i]; + ++#ifdef LIBSANGOMA_VERSION ++ if (pfds[i-1].flags_out & 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++; +@@ -836,15 +606,43 @@ + } + + +- + return k ? ZAP_SUCCESS : ZAP_FAIL; + } + ++ ++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 = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; ++ ++ return ZAP_SUCCESS; ++} ++ ++ + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) + { +- uint32_t i; ++ uint32_t i,err; + zap_oob_event_t event_id; + + for(i = 1; i <= span->chan_count; i++) { +@@ -869,29 +667,43 @@ + 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)); +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- wp_tdm_cmd_exec(span->channels[i], &tdm_api); ++ ++ sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + } + 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); + +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; +- if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { ++ 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; + } + + switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { ++ ++ case WP_TDMAPI_EVENT_LINK_STATUS: ++ { ++ 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; ++ }; ++ } ++ break; ++ + case WP_TDMAPI_EVENT_RXHOOK: + { + if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { +@@ -918,11 +730,9 @@ + continue; + } else { + int err; +- +- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; +- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; +- if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { ++ 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; + } +@@ -948,6 +758,17 @@ + span->channels[i]->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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); ++ if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { ++ zap_channel_queue_dtmf(zchan, tmp_dtmf); ++ } ++ } ++ break; + default: + { + zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); +@@ -1005,6 +826,7 @@ + #endif + 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; +Index: configure.ac +=================================================================== +--- configure.ac (revision 717) ++++ configure.ac (working copy) +@@ -155,6 +155,9 @@ + [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) + AC_SUBST(enable_libpri) + ++AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) ++AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) ++ + AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) + + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" +Index: Makefile.am +=================================================================== +--- Makefile.am (revision 717) ++++ Makefile.am (working copy) +@@ -154,10 +154,12 @@ + ozmod_skel_la_LDFLAGS = -module -avoid-version + ozmod_skel_la_LIBADD = $(MYLIB) + ++if LIBSANGOMA + ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +-ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +-ozmod_wanpipe_la_LDFLAGS = -module -avoid-version ++ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe ++ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma + ozmod_wanpipe_la_LIBADD = $(MYLIB) ++endif + + ozmod_isdn_la_SOURCES = \ + $(SRC)/isdn/EuroISDNStateNT.c \ From bb53daeae2c8cadd6bdc94a5b214997fddd9ac9e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Apr 2009 21:22:42 +0000 Subject: [PATCH 1387/1766] wanpipe commit we've all been waiting for, HW dtmf, ALARMS, proper bounce of PRIs (testers needed) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@719 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 6 +- libs/openzap/configure.ac | 3 + libs/openzap/mod_openzap/mod_openzap.c | 2 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 23 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 130 ++++- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 15 +- .../src/ozmod/ozmod_ss7_boost/sigboost.h | 116 ++-- .../ozmod/ozmod_ss7_boost/ss7_boost_client.c | 22 +- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 529 ++++++------------ libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 5 +- 10 files changed, 414 insertions(+), 437 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 3afec009d7..a7930917d4 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -154,10 +154,12 @@ ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_skel_la_LDFLAGS = -module -avoid-version ozmod_skel_la_LIBADD = $(MYLIB) +if LIBSANGOMA ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_wanpipe_la_LDFLAGS = -module -avoid-version +ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe +ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma ozmod_wanpipe_la_LIBADD = $(MYLIB) +endif ozmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index c16ce2b386..f7a0576809 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -155,6 +155,9 @@ AC_ARG_WITH([libpri], [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) AC_SUBST(enable_libpri) +AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) +AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) + AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 74339be232..feca83dc8b 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -475,7 +475,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); } break; } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index 8efdafeca8..60e6f51d88 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -115,9 +115,14 @@ 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 (zap_channel_read(spri->dchan, buf, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); + 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); + } 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; } @@ -145,7 +150,7 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) 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; + return -1; } #ifdef IODEBUG @@ -198,9 +203,9 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { - return -1; - } + //if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { + //return -1; + //} FD_ZERO(&rfds); FD_ZERO(&efds); @@ -246,9 +251,9 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - if (zap_test_flag(spri, LPWRAP_PRI_READY)) { - return sel; - } + + 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); diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 101a09ca85..7053d3177d 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -691,16 +691,103 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event return ret; } + +static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_sigmsg_t sig; + zap_libpri_data_t *isdn_data = span->signal_data; + + 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:%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: + { + sig.event_id = 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); + isdn_data->sig_cb(&sig); + 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); + + sig.event_id = ZAP_OOB_ALARM_CLEAR; + zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + zap_channel_get_alarms(event->channel); + isdn_data->sig_cb(&sig); + } + break; + } + + return ZAP_SUCCESS; +} + + + +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; + } +} + static int check_flags(lpwrap_pri_t *spri) { zap_span_t *span = spri->private_info; - check_state(span); - if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { return -1; } + check_state(span); + check_events(span); + + return 0; } @@ -769,27 +856,29 @@ 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 x, i; + 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)) { - x = 0; - - 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; - x++; - break; + 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 (!x || lpwrap_init_pri(&isdn_data->spri, + + if (lpwrap_init_pri(&isdn_data->spri, span, // span isdn_data->dchan, // dchan isdn_data->pswitch, @@ -820,9 +909,8 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) isdn_data->spri.on_loop = check_flags; isdn_data->spri.private_info = span; - lpwrap_run_pri(&isdn_data->spri); - zap_channel_close(&isdn_data->dchan); + } if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { @@ -830,9 +918,15 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) } zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span->span_id); - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - check_state(span); + + if (!down) { + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + check_state(span); + } + check_state(span); + check_events(span); + down++; zap_sleep(5000); } diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 656b09a9a5..f5daec4afc 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -215,7 +215,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); zap_set_string(event.calling_name, caller_data->cid_name); - zap_set_string(event.redirection_string, caller_data->rdnis.digits); + zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); + if (strlen(caller_data->rdnis.digits)) { + event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; + } + event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; @@ -483,7 +487,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); zchan->caller_data.screen = event->calling_number_screening_ind; zchan->caller_data.pres = event->calling_number_presentation; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); @@ -851,7 +855,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10, too_long = 20000; + uint32_t ms = 10; //, too_long = 20000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -942,6 +946,8 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) 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); @@ -953,6 +959,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); } +#endif if (zap_running()) { check_state(span); @@ -1094,7 +1101,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; - int local_port = 5300, remote_port = 5300; + int local_port = 53000, remote_port = 53000; char *var, *val; int *intval; diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h index a5a147cd11..f705dfd09f 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h @@ -1,5 +1,5 @@ /**************************************************************************** - * sigboost.h $Revision: 1.5 $ + * sigboost.h $Revision: 1.13 $ * * Definitions for the sigboost interface. * @@ -14,6 +14,8 @@ #ifndef _SIGBOOST_H_ #define _SIGBOOST_H_ +#define SIGBOOST_VERSION 100 + #include #include @@ -48,14 +50,22 @@ enum e_sigboost_release_cause_values 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, + //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 */ }; #define MAX_DIALED_DIGITS 31 @@ -67,63 +77,73 @@ enum e_sigboost_call_setup_ack_nack_cause_values #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 128 +#define SIZE_RDNIS 900 + #pragma pack(1) + typedef struct { - uint32_t event_id; + uint8_t capability; + uint8_t uil1p; +}t_sigboost_bearer; + +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; - struct timeval tv; - 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 */ + uint32_t fseqno; + uint32_t bseqno; + uint16_t call_setup_id; + uint32_t trunk_group; + uint8_t span; + uint8_t chan; + struct timeval tv; + 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 */ /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ - uint8_t calling_number_screening_ind; - uint8_t calling_number_presentation; - char calling_name[MAX_DIALED_DIGITS + 1]; - uint16_t redirection_string_size; - char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ - /* redir string format: - * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection - * */ + uint8_t calling_number_screening_ind; + uint8_t calling_number_presentation; + char calling_name[MAX_DIALED_DIGITS + 1]; + t_sigboost_bearer bearer; + uint8_t hunt_group; + uint16_t isup_in_rdnis_size; + char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ } t_sigboost_callstart; -#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) +#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS typedef struct { - uint32_t event_id; + 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; - struct timeval tv; - uint8_t release_cause; + uint32_t fseqno; + uint32_t bseqno; + uint16_t call_setup_id; + uint32_t trunk_group; + uint8_t span; + uint8_t chan; + 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: - return 1; - default: - return 0; - } + switch (event_id) { + case SIGBOOST_EVENT_CALL_START: + case SIGBOOST_EVENT_DIGIT_IN: + return 1; + default: + return 0; + } - return 0; + return 0; } + #endif diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 20986b30f1..37ad3d02b9 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -73,7 +73,7 @@ static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *even { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + 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]\n", dir ? "TX":"RX", ss7bc_event_id_name(event->event_id), event->event_id, @@ -91,7 +91,7 @@ static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_short_event_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + 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", ss7bc_event_id_name(event->event_id), @@ -261,6 +261,10 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); + 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; @@ -293,7 +297,7 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); } -#if 1 +#if 0 /* NC: NOT USED ANY MORE */ if (mcon->rxseq_reset) { //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { @@ -310,15 +314,17 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, 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, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); return NULL; } } @@ -332,6 +338,10 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, int bytes = 0; bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); + + 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(ss7bc_short_event_t)) { @@ -356,7 +366,7 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) { int err; - int event_size=sizeof(ss7bc_event_t); + 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"); @@ -395,6 +405,7 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con 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); @@ -432,6 +443,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co gettimeofday(&event->tv, NULL); 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); diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 4efdf6dc76..e29f7f3ad4 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -38,7 +38,7 @@ #include "openzap.h" #include #include -#include "wanpipe_tdm_api_iface.h" +#include "libsangoma.h" typedef enum { WP_RINGING = (1 << 0) @@ -57,196 +57,28 @@ static struct { ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); -#define WP_INVALID_SOCKET -1 -/* 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 */ - uint32_t 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; -} +#define WP_INVALID_SOCKET -1 /* 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; +#ifdef LIBSANGOMA_VERSION + int err; + sangoma_wait_obj_t sangoma_wait_obj; - if (!DeviceIoControl( - fd, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)&api_poll, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL)) { - return -1; + sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); + + err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); + if (err > 0) { + *flags=sangoma_wait_obj.flags_out; } + return err; - *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]; + struct pollfd pfds[1]; int res; memset(&pfds[0], 0, sizeof(pfds[0])); @@ -265,87 +97,18 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) return res; #endif + } -#define FNAME_LEN 128 static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) { - char fname[FNAME_LEN]; - sng_fd_t fd = WP_INVALID_SOCKET; -#if defined(__WINDOWS__) - DWORD ln; - wan_udp_hdr_t wan_udp; - - /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ - /* Subtract 1 from 'chan'. */ - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - fd = CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); - - /* make sure that we are the only ones who have this chan open */ - /* is this a threadsafe way to make sure that we are ok and will */ - /* never return a valid handle to more than one thread for the same channel? */ - - wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; - wan_udp.wan_udphdr_data_len = 0; - - DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ); - - if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ - /* somone already has this channel, or somthing else is not right. */ - tdmv_api_close_socket(&fd); - } - -#else - /* Does this fail if another thread already has this chan open? */ - /* if not, we need to add some code to make sure it does */ - snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - -#endif - return fd; + return sangoma_open_tdmapi_span_chan(span, chan); } static zap_io_interface_t wanpipe_interface; -static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) -{ - int err; - - /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ - err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); - - if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; - } - - return ZAP_SUCCESS; -} - static unsigned char wanpipe_swap_bits(unsigned char cas_bits) { unsigned char swapped_bits = 0x0; @@ -374,59 +137,60 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, for(x = start; x < end; x++) { zap_channel_t *chan; zap_socket_t sockfd = WP_INVALID_SOCKET; - + const char *dtmf = "none"; + sockfd = tdmv_api_open_span_chan(spanno, x); if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { wanpipe_tdm_api_t tdm_api; - zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + memset(&tdm_api,0,sizeof(tdm_api)); + chan->physical_span_id = spanno; chan->physical_chan_id = x; chan->rate = 8000; - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { - - -#if 1 - if (type == ZAP_CHAN_TYPE_FXO) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); - } -#endif - - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); -#if 1 - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); -#endif - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); - - } - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; - wp_tdm_cmd_exec(chan, &tdm_api); + int err; + + dtmf = "software"; + + /* FIXME: Handle Error Conditino 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) { + err = sangoma_tdm_enable_dtmf_events(chan->sockfd, &tdm_api); + if (err == 0) { + zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); + dtmf = "hardware"; + } + } } +#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) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; - tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); - wp_tdm_cmd_exec(chan, &tdm_api); +#ifdef LIBSANGOMA_VERSION + sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); +#else + sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); +#endif } if (!zap_strlen_zero(name)) { @@ -439,6 +203,9 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } + + 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); } return configured; @@ -552,16 +319,15 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) wanpipe_tdm_api_t tdm_api; + memset(&tdm_api,0,sizeof(tdm_api)); + 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; - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = 0; - wp_tdm_cmd_exec(zchan, &tdm_api); - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; - tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; - wp_tdm_cmd_exec(zchan, &tdm_api); + + 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; @@ -585,10 +351,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) switch(command) { case ZAP_COMMAND_OFFHOOK: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); return ZAP_FAIL; } @@ -597,10 +361,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_ONHOOK: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); return ZAP_FAIL; } @@ -609,9 +371,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GENERATE_RING_ON: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; } @@ -622,9 +383,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GENERATE_RING_OFF: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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; } @@ -634,27 +394,26 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GET_INTERVAL: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - - if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { - ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; + err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); + if (err > 0 ) { + ZAP_COMMAND_OBJ_INT = err; + err=0; } - } break; case ZAP_COMMAND_SET_INTERVAL: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; - tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; - err = wp_tdm_cmd_exec(zchan, &tdm_api); + 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: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; - tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); - err = wp_tdm_cmd_exec(zchan, &tdm_api); +#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: @@ -683,14 +442,18 @@ static ZIO_READ_FUNCTION(wanpipe_read) memset(&hdrframe, 0, sizeof(hdrframe)); - rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); - + rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); *datalen = rx_len; - if (rx_len <= 0) { + 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; } @@ -702,7 +465,7 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ memset(&hdrframe, 0, sizeof(hdrframe)); - bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); + 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) { @@ -759,19 +522,29 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } -#ifndef WIN32 ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { +#ifdef LIBSANGOMA_VERSION + sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; +#else struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; +#endif + uint32_t i, j = 0, k = 0, l = 0; + int objects=0; int r; for(i = 1; i <= span->chan_count; i++) { zap_channel_t *zchan = span->channels[i]; + +#ifdef LIBSANGOMA_VERSION + sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); +#else memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i]->sockfd; pfds[j].events = POLLPRI; - +#endif + objects++; /* 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)) { @@ -789,20 +562,16 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) int err; memset(&tdm_api, 0, sizeof(tdm_api)); if (zap_test_pflag(zchan, WP_RINGING)) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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 { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; } @@ -815,8 +584,11 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) if (l) { ms = l; } - - r = poll(pfds, j, ms); +#ifdef LIBSANGOMA_VERSION + r = sangoma_socket_waitfor_many(pfds,objects,ms); +#else + r = poll(pfds, j, ms); +#endif if (r == 0) { return l ? ZAP_SUCCESS : ZAP_TIMEOUT; @@ -828,7 +600,11 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) for(i = 1; i <= span->chan_count; i++) { zap_channel_t *zchan = span->channels[i]; +#ifdef LIBSANGOMA_VERSION + if (pfds[i-1].flags_out & 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++; @@ -836,15 +612,43 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } - return k ? ZAP_SUCCESS : ZAP_FAIL; } + +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 = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; + + return ZAP_SUCCESS; +} + + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { - uint32_t i; + uint32_t i,err; zap_oob_event_t event_id; for(i = 1; i <= span->chan_count; i++) { @@ -869,29 +673,43 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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)); - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(span->channels[i], &tdm_api); + + sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); } 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); - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; - if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { + 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; } switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { + + case WP_TDMAPI_EVENT_LINK_STATUS: + { + 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; + }; + } + break; + case WP_TDMAPI_EVENT_RXHOOK: { if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { @@ -918,11 +736,9 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) continue; } else { int err; - - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { + 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; } @@ -948,6 +764,20 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) span->channels[i]->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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); + if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { + zap_channel_queue_dtmf(zchan, tmp_dtmf); + } + } + break; + case WP_TDMAPI_EVENT_ALARM: + event_id = ZAP_OOB_NOOP; + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); @@ -1005,6 +835,7 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) #endif 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; diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 096b655ceb..c3f80e0f6e 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -868,6 +868,9 @@ static ZIO_READ_FUNCTION(zt_read) if ((r = read(zchan->sockfd, data, *datalen)) > 0) { break; } + if (r == 0) { + errs--; + } } if (r > 0) { @@ -878,7 +881,7 @@ static ZIO_READ_FUNCTION(zt_read) return ZAP_SUCCESS; } - return ZAP_FAIL; + return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; } static ZIO_WRITE_FUNCTION(zt_write) From 793792d4f878156477718e859c1beb5d41a938ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Apr 2009 21:22:42 +0000 Subject: [PATCH 1388/1766] wanpipe commit we've all been waiting for, HW dtmf, ALARMS, proper bounce of PRIs (testers needed) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@719 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 6 +- libs/freetdm/configure.ac | 3 + libs/freetdm/mod_openzap/mod_openzap.c | 2 +- .../src/ozmod/ozmod_libpri/lpwrap_pri.c | 23 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 130 ++++- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 15 +- .../src/ozmod/ozmod_ss7_boost/sigboost.h | 116 ++-- .../ozmod/ozmod_ss7_boost/ss7_boost_client.c | 22 +- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 529 ++++++------------ libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 5 +- 10 files changed, 414 insertions(+), 437 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 3afec009d7..a7930917d4 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -154,10 +154,12 @@ ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_skel_la_LDFLAGS = -module -avoid-version ozmod_skel_la_LIBADD = $(MYLIB) +if LIBSANGOMA ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_wanpipe_la_LDFLAGS = -module -avoid-version +ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe +ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma ozmod_wanpipe_la_LIBADD = $(MYLIB) +endif ozmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index c16ce2b386..f7a0576809 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -155,6 +155,9 @@ AC_ARG_WITH([libpri], [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) AC_SUBST(enable_libpri) +AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) +AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) + AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 74339be232..feca83dc8b 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -475,7 +475,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); } break; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index 8efdafeca8..60e6f51d88 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -115,9 +115,14 @@ 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 (zap_channel_read(spri->dchan, buf, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); + 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); + } 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; } @@ -145,7 +150,7 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) 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; + return -1; } #ifdef IODEBUG @@ -198,9 +203,9 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { - return -1; - } + //if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { + //return -1; + //} FD_ZERO(&rfds); FD_ZERO(&efds); @@ -246,9 +251,9 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - if (zap_test_flag(spri, LPWRAP_PRI_READY)) { - return sel; - } + + 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); diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 101a09ca85..7053d3177d 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -691,16 +691,103 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event return ret; } + +static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) +{ + zap_sigmsg_t sig; + zap_libpri_data_t *isdn_data = span->signal_data; + + 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:%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: + { + sig.event_id = 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); + isdn_data->sig_cb(&sig); + 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); + + sig.event_id = ZAP_OOB_ALARM_CLEAR; + zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + zap_channel_get_alarms(event->channel); + isdn_data->sig_cb(&sig); + } + break; + } + + return ZAP_SUCCESS; +} + + + +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; + } +} + static int check_flags(lpwrap_pri_t *spri) { zap_span_t *span = spri->private_info; - check_state(span); - if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { return -1; } + check_state(span); + check_events(span); + + return 0; } @@ -769,27 +856,29 @@ 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 x, i; + 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)) { - x = 0; - - 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; - x++; - break; + 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 (!x || lpwrap_init_pri(&isdn_data->spri, + + if (lpwrap_init_pri(&isdn_data->spri, span, // span isdn_data->dchan, // dchan isdn_data->pswitch, @@ -820,9 +909,8 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) isdn_data->spri.on_loop = check_flags; isdn_data->spri.private_info = span; - lpwrap_run_pri(&isdn_data->spri); - zap_channel_close(&isdn_data->dchan); + } if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { @@ -830,9 +918,15 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) } zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span->span_id); - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - check_state(span); + + if (!down) { + zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + check_state(span); + } + check_state(span); + check_events(span); + down++; zap_sleep(5000); } diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 656b09a9a5..f5daec4afc 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -215,7 +215,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); zap_set_string(event.calling_name, caller_data->cid_name); - zap_set_string(event.redirection_string, caller_data->rdnis.digits); + zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); + if (strlen(caller_data->rdnis.digits)) { + event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; + } + event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; @@ -483,7 +487,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); zchan->caller_data.screen = event->calling_number_screening_ind; zchan->caller_data.pres = event->calling_number_presentation; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); @@ -851,7 +855,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; ss7bc_connection_t *mcon, *pcon; - uint32_t ms = 10, too_long = 20000; + uint32_t ms = 10; //, too_long = 20000; ss7_boost_data->pcon = ss7_boost_data->mcon; @@ -942,6 +946,8 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) 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); @@ -953,6 +959,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); } +#endif if (zap_running()) { check_state(span); @@ -1094,7 +1101,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; - int local_port = 5300, remote_port = 5300; + int local_port = 53000, remote_port = 53000; char *var, *val; int *intval; diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h index a5a147cd11..f705dfd09f 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h @@ -1,5 +1,5 @@ /**************************************************************************** - * sigboost.h $Revision: 1.5 $ + * sigboost.h $Revision: 1.13 $ * * Definitions for the sigboost interface. * @@ -14,6 +14,8 @@ #ifndef _SIGBOOST_H_ #define _SIGBOOST_H_ +#define SIGBOOST_VERSION 100 + #include #include @@ -48,14 +50,22 @@ enum e_sigboost_release_cause_values 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, + //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 */ }; #define MAX_DIALED_DIGITS 31 @@ -67,63 +77,73 @@ enum e_sigboost_call_setup_ack_nack_cause_values #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 128 +#define SIZE_RDNIS 900 + #pragma pack(1) + typedef struct { - uint32_t event_id; + uint8_t capability; + uint8_t uil1p; +}t_sigboost_bearer; + +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; - struct timeval tv; - 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 */ + uint32_t fseqno; + uint32_t bseqno; + uint16_t call_setup_id; + uint32_t trunk_group; + uint8_t span; + uint8_t chan; + struct timeval tv; + 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 */ /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ - uint8_t calling_number_screening_ind; - uint8_t calling_number_presentation; - char calling_name[MAX_DIALED_DIGITS + 1]; - uint16_t redirection_string_size; - char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ - /* redir string format: - * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection - * */ + uint8_t calling_number_screening_ind; + uint8_t calling_number_presentation; + char calling_name[MAX_DIALED_DIGITS + 1]; + t_sigboost_bearer bearer; + uint8_t hunt_group; + uint16_t isup_in_rdnis_size; + char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ } t_sigboost_callstart; -#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) +#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS typedef struct { - uint32_t event_id; + 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; - struct timeval tv; - uint8_t release_cause; + uint32_t fseqno; + uint32_t bseqno; + uint16_t call_setup_id; + uint32_t trunk_group; + uint8_t span; + uint8_t chan; + 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: - return 1; - default: - return 0; - } + switch (event_id) { + case SIGBOOST_EVENT_CALL_START: + case SIGBOOST_EVENT_DIGIT_IN: + return 1; + default: + return 0; + } - return 0; + return 0; } + #endif diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 20986b30f1..37ad3d02b9 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -73,7 +73,7 @@ static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *even { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + 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]\n", dir ? "TX":"RX", ss7bc_event_id_name(event->event_id), event->event_id, @@ -91,7 +91,7 @@ static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_short_event_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + 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", ss7bc_event_id_name(event->event_id), @@ -261,6 +261,10 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); + 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; @@ -293,7 +297,7 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); } -#if 1 +#if 0 /* NC: NOT USED ANY MORE */ if (mcon->rxseq_reset) { //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { @@ -310,15 +314,17 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, 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, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); return NULL; } } @@ -332,6 +338,10 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, int bytes = 0; bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); + + 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(ss7bc_short_event_t)) { @@ -356,7 +366,7 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) { int err; - int event_size=sizeof(ss7bc_event_t); + 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"); @@ -395,6 +405,7 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con 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); @@ -432,6 +443,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co gettimeofday(&event->tv, NULL); 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); diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 4efdf6dc76..e29f7f3ad4 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -38,7 +38,7 @@ #include "openzap.h" #include #include -#include "wanpipe_tdm_api_iface.h" +#include "libsangoma.h" typedef enum { WP_RINGING = (1 << 0) @@ -57,196 +57,28 @@ static struct { ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); -#define WP_INVALID_SOCKET -1 -/* 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 */ - uint32_t 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; -} +#define WP_INVALID_SOCKET -1 /* 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; +#ifdef LIBSANGOMA_VERSION + int err; + sangoma_wait_obj_t sangoma_wait_obj; - if (!DeviceIoControl( - fd, - IoctlApiPoll, - (LPVOID)NULL, - 0L, - (LPVOID)&api_poll, - sizeof(API_POLL_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL)) { - return -1; + sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); + + err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); + if (err > 0) { + *flags=sangoma_wait_obj.flags_out; } + return err; - *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]; + struct pollfd pfds[1]; int res; memset(&pfds[0], 0, sizeof(pfds[0])); @@ -265,87 +97,18 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) return res; #endif + } -#define FNAME_LEN 128 static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) { - char fname[FNAME_LEN]; - sng_fd_t fd = WP_INVALID_SOCKET; -#if defined(__WINDOWS__) - DWORD ln; - wan_udp_hdr_t wan_udp; - - /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ - /* Subtract 1 from 'chan'. */ - _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); - - fd = CreateFile( fname, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, - (HANDLE)NULL - ); - - /* make sure that we are the only ones who have this chan open */ - /* is this a threadsafe way to make sure that we are ok and will */ - /* never return a valid handle to more than one thread for the same channel? */ - - wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; - wan_udp.wan_udphdr_data_len = 0; - - DeviceIoControl( - fd, - IoctlManagementCommand, - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPVOID)&wan_udp, - sizeof(wan_udp_hdr_t), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - ); - - if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ - /* somone already has this channel, or somthing else is not right. */ - tdmv_api_close_socket(&fd); - } - -#else - /* Does this fail if another thread already has this chan open? */ - /* if not, we need to add some code to make sure it does */ - snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); - - fd = open(fname, O_RDWR); - - if (fd < 0) { - fd = WP_INVALID_SOCKET; - } - -#endif - return fd; + return sangoma_open_tdmapi_span_chan(span, chan); } static zap_io_interface_t wanpipe_interface; -static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) -{ - int err; - - /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ - err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); - - if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; - } - - return ZAP_SUCCESS; -} - static unsigned char wanpipe_swap_bits(unsigned char cas_bits) { unsigned char swapped_bits = 0x0; @@ -374,59 +137,60 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, for(x = start; x < end; x++) { zap_channel_t *chan; zap_socket_t sockfd = WP_INVALID_SOCKET; - + const char *dtmf = "none"; + sockfd = tdmv_api_open_span_chan(spanno, x); if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { wanpipe_tdm_api_t tdm_api; - zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); + memset(&tdm_api,0,sizeof(tdm_api)); + chan->physical_span_id = spanno; chan->physical_chan_id = x; chan->rate = 8000; - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { - - -#if 1 - if (type == ZAP_CHAN_TYPE_FXO) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); - } -#endif - - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); -#if 1 - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); -#endif - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(chan, &tdm_api); - - } - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; - wp_tdm_cmd_exec(chan, &tdm_api); + int err; + + dtmf = "software"; + + /* FIXME: Handle Error Conditino 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) { + err = sangoma_tdm_enable_dtmf_events(chan->sockfd, &tdm_api); + if (err == 0) { + zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); + dtmf = "hardware"; + } + } } +#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) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; - tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); - wp_tdm_cmd_exec(chan, &tdm_api); +#ifdef LIBSANGOMA_VERSION + sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); +#else + sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); +#endif } if (!zap_strlen_zero(name)) { @@ -439,6 +203,9 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } + + 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); } return configured; @@ -552,16 +319,15 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) wanpipe_tdm_api_t tdm_api; + memset(&tdm_api,0,sizeof(tdm_api)); + 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; - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; - tdm_api.wp_tdm_cmd.tdm_codec = 0; - wp_tdm_cmd_exec(zchan, &tdm_api); - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; - tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; - wp_tdm_cmd_exec(zchan, &tdm_api); + + 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; @@ -585,10 +351,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) switch(command) { case ZAP_COMMAND_OFFHOOK: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); return ZAP_FAIL; } @@ -597,10 +361,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_ONHOOK: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); return ZAP_FAIL; } @@ -609,9 +371,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GENERATE_RING_ON: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; } @@ -622,9 +383,8 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GENERATE_RING_OFF: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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; } @@ -634,27 +394,26 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_GET_INTERVAL: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; - - if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { - ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; + err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); + if (err > 0 ) { + ZAP_COMMAND_OBJ_INT = err; + err=0; } - } break; case ZAP_COMMAND_SET_INTERVAL: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; - tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; - err = wp_tdm_cmd_exec(zchan, &tdm_api); + 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: { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; - tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); - err = wp_tdm_cmd_exec(zchan, &tdm_api); +#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: @@ -683,14 +442,18 @@ static ZIO_READ_FUNCTION(wanpipe_read) memset(&hdrframe, 0, sizeof(hdrframe)); - rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); - + rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); *datalen = rx_len; - if (rx_len <= 0) { + 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; } @@ -702,7 +465,7 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ memset(&hdrframe, 0, sizeof(hdrframe)); - bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); + 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) { @@ -759,19 +522,29 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) return ZAP_SUCCESS; } -#ifndef WIN32 ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { +#ifdef LIBSANGOMA_VERSION + sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; +#else struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; +#endif + uint32_t i, j = 0, k = 0, l = 0; + int objects=0; int r; for(i = 1; i <= span->chan_count; i++) { zap_channel_t *zchan = span->channels[i]; + +#ifdef LIBSANGOMA_VERSION + sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); +#else memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i]->sockfd; pfds[j].events = POLLPRI; - +#endif + objects++; /* 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)) { @@ -789,20 +562,16 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) int err; memset(&tdm_api, 0, sizeof(tdm_api)); if (zap_test_pflag(zchan, WP_RINGING)) { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + 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 { - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { + err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); + if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); return ZAP_FAIL; } @@ -815,8 +584,11 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) if (l) { ms = l; } - - r = poll(pfds, j, ms); +#ifdef LIBSANGOMA_VERSION + r = sangoma_socket_waitfor_many(pfds,objects,ms); +#else + r = poll(pfds, j, ms); +#endif if (r == 0) { return l ? ZAP_SUCCESS : ZAP_TIMEOUT; @@ -828,7 +600,11 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) for(i = 1; i <= span->chan_count; i++) { zap_channel_t *zchan = span->channels[i]; +#ifdef LIBSANGOMA_VERSION + if (pfds[i-1].flags_out & 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++; @@ -836,15 +612,43 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } - return k ? ZAP_SUCCESS : ZAP_FAIL; } + +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 = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; + + return ZAP_SUCCESS; +} + + ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { - uint32_t i; + uint32_t i,err; zap_oob_event_t event_id; for(i = 1; i <= span->chan_count; i++) { @@ -869,29 +673,43 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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)); - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - wp_tdm_cmd_exec(span->channels[i], &tdm_api); + + sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); } 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); - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; - if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { + 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; } switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { + + case WP_TDMAPI_EVENT_LINK_STATUS: + { + 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; + }; + } + break; + case WP_TDMAPI_EVENT_RXHOOK: { if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { @@ -918,11 +736,9 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) continue; } else { int err; - - tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; - tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; - if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { + 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; } @@ -948,6 +764,20 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) span->channels[i]->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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); + if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { + zap_channel_queue_dtmf(zchan, tmp_dtmf); + } + } + break; + case WP_TDMAPI_EVENT_ALARM: + event_id = ZAP_OOB_NOOP; + break; default: { zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); @@ -1005,6 +835,7 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) #endif 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; diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 096b655ceb..c3f80e0f6e 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -868,6 +868,9 @@ static ZIO_READ_FUNCTION(zt_read) if ((r = read(zchan->sockfd, data, *datalen)) > 0) { break; } + if (r == 0) { + errs--; + } } if (r > 0) { @@ -878,7 +881,7 @@ static ZIO_READ_FUNCTION(zt_read) return ZAP_SUCCESS; } - return ZAP_FAIL; + return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; } static ZIO_WRITE_FUNCTION(zt_write) From e2c2245a3044949704d548783abdc8f86119e733 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Apr 2009 21:23:24 +0000 Subject: [PATCH 1389/1766] del patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@720 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/patches/oz.diff | 1110 ---------------------------------- 1 file changed, 1110 deletions(-) delete mode 100644 libs/openzap/patches/oz.diff diff --git a/libs/openzap/patches/oz.diff b/libs/openzap/patches/oz.diff deleted file mode 100644 index 2b8fa60012..0000000000 --- a/libs/openzap/patches/oz.diff +++ /dev/null @@ -1,1110 +0,0 @@ -Index: src/ozmod/ozmod_ss7_boost/sigboost.h -=================================================================== ---- src/ozmod/ozmod_ss7_boost/sigboost.h (revision 717) -+++ src/ozmod/ozmod_ss7_boost/sigboost.h (working copy) -@@ -1,5 +1,5 @@ - /**************************************************************************** -- * sigboost.h $Revision: 1.5 $ -+ * sigboost.h $Revision: 1.13 $ - * - * Definitions for the sigboost interface. - * -@@ -14,6 +14,8 @@ - #ifndef _SIGBOOST_H_ - #define _SIGBOOST_H_ - -+#define SIGBOOST_VERSION 100 -+ - #include - #include - -@@ -48,16 +50,24 @@ - - 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, -+ //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 */ -+}; -+ - #define MAX_DIALED_DIGITS 31 - - /* Next two defines are used to create the range of values for call_setup_id -@@ -67,63 +77,73 @@ - #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 128 -+#define SIZE_RDNIS 900 - -+ - #pragma pack(1) -+ - typedef struct - { -- uint32_t event_id; -+ uint8_t capability; -+ uint8_t uil1p; -+}t_sigboost_bearer; -+ -+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; -- struct timeval tv; -- 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 */ -+ uint32_t fseqno; -+ uint32_t bseqno; -+ uint16_t call_setup_id; -+ uint32_t trunk_group; -+ uint8_t span; -+ uint8_t chan; -+ struct timeval tv; -+ 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 */ - /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ -- uint8_t calling_number_screening_ind; -- uint8_t calling_number_presentation; -- char calling_name[MAX_DIALED_DIGITS + 1]; -- uint16_t redirection_string_size; -- char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ -- /* redir string format: -- * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection -- * */ -+ uint8_t calling_number_screening_ind; -+ uint8_t calling_number_presentation; -+ char calling_name[MAX_DIALED_DIGITS + 1]; -+ t_sigboost_bearer bearer; -+ uint8_t hunt_group; -+ uint16_t isup_in_rdnis_size; -+ char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ - } t_sigboost_callstart; - --#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) -+#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS - - typedef struct - { -- uint32_t event_id; -+ 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; -- struct timeval tv; -- uint8_t release_cause; -+ uint32_t fseqno; -+ uint32_t bseqno; -+ uint16_t call_setup_id; -+ uint32_t trunk_group; -+ uint8_t span; -+ uint8_t chan; -+ 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: -- return 1; -- default: -- return 0; -- } -+ switch (event_id) { -+ case SIGBOOST_EVENT_CALL_START: -+ case SIGBOOST_EVENT_DIGIT_IN: -+ return 1; -+ default: -+ return 0; -+ } - -- return 0; -+ return 0; - } - -+ - #endif -Index: src/ozmod/ozmod_ss7_boost/ss7_boost_client.c -=================================================================== ---- src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (revision 717) -+++ src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (working copy) -@@ -73,7 +73,7 @@ - { - if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) - return; -- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", -+ 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]\n", - dir ? "TX":"RX", - ss7bc_event_id_name(event->event_id), - event->event_id, -@@ -91,7 +91,7 @@ - { - if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) - return; -- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", -+ 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", - ss7bc_event_id_name(event->event_id), -@@ -261,6 +261,10 @@ - bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, - (struct sockaddr *) &mcon->local_addr, &fromlen); - -+ 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; -@@ -293,7 +297,7 @@ - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); - } - --#if 1 -+#if 0 - /* NC: NOT USED ANY MORE */ - if (mcon->rxseq_reset) { - //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { -@@ -310,15 +314,17 @@ - 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, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); -+ zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); - return NULL; - } - } -@@ -332,6 +338,10 @@ - int bytes = 0; - - bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); -+ -+ 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(ss7bc_short_event_t)) { - -@@ -356,7 +366,7 @@ - int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) - { - int err; -- int event_size=sizeof(ss7bc_event_t); -+ 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"); -@@ -395,6 +405,7 @@ - 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); -@@ -432,6 +443,7 @@ - gettimeofday(&event->tv, NULL); - - 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); - -Index: src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -=================================================================== ---- src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (revision 717) -+++ src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (working copy) -@@ -215,7 +215,11 @@ - - ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); - zap_set_string(event.calling_name, caller_data->cid_name); -- zap_set_string(event.redirection_string, caller_data->rdnis.digits); -+ zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); -+ if (strlen(caller_data->rdnis.digits)) { -+ event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; -+ } -+ - event.calling_number_screening_ind = caller_data->screen; - event.calling_number_presentation = caller_data->pres; - -@@ -483,7 +487,7 @@ - } - zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); - zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); -- zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); -+ zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); - zchan->caller_data.screen = event->calling_number_screening_ind; - zchan->caller_data.pres = event->calling_number_presentation; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); -@@ -851,7 +855,7 @@ - zap_span_t *span = (zap_span_t *) obj; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - ss7bc_connection_t *mcon, *pcon; -- uint32_t ms = 10, too_long = 20000; -+ uint32_t ms = 10; //, too_long = 20000; - - - ss7_boost_data->pcon = ss7_boost_data->mcon; -@@ -942,6 +946,8 @@ - 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); -@@ -953,6 +959,7 @@ - SIGBOOST_EVENT_SYSTEM_RESTART, - 0); - } -+#endif - - if (zap_running()) { - check_state(span); -@@ -1094,7 +1101,7 @@ - { - zap_ss7_boost_data_t *ss7_boost_data = NULL; - const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; -- int local_port = 5300, remote_port = 5300; -+ int local_port = 53000, remote_port = 53000; - char *var, *val; - int *intval; - -Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -=================================================================== ---- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 717) -+++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) -@@ -38,7 +38,7 @@ - #include "openzap.h" - #include - #include --#include "wanpipe_tdm_api_iface.h" -+#include "libsangoma.h" - - typedef enum { - WP_RINGING = (1 << 0) -@@ -57,196 +57,28 @@ - ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); - ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); - --#define WP_INVALID_SOCKET -1 --/* 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 */ -- uint32_t 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; -+#define WP_INVALID_SOCKET -1 - -- 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; --} -- - /* 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; -+#ifdef LIBSANGOMA_VERSION -+ int err; -+ sangoma_wait_obj_t sangoma_wait_obj; - -- if (!DeviceIoControl( -- fd, -- IoctlApiPoll, -- (LPVOID)NULL, -- 0L, -- (LPVOID)&api_poll, -- sizeof(API_POLL_STRUCT), -- (LPDWORD)(&ln), -- (LPOVERLAPPED)NULL)) { -- return -1; -- } -+ sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); - -- *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; -+ err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); -+ if (err > 0) { -+ *flags=sangoma_wait_obj.flags_out; - } -+ return err; - -- if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { -- return 0; -- } -- -- *flags = api_poll.poll_events_bitmap; -- -- return 1; - #else -- struct pollfd pfds[1]; -+ struct pollfd pfds[1]; - int res; - - memset(&pfds[0], 0, sizeof(pfds[0])); -@@ -265,87 +97,18 @@ - - return res; - #endif -+ - } - --#define FNAME_LEN 128 - static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) - { -- char fname[FNAME_LEN]; -- sng_fd_t fd = WP_INVALID_SOCKET; --#if defined(__WINDOWS__) -- DWORD ln; -- wan_udp_hdr_t wan_udp; -- -- /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ -- /* Subtract 1 from 'chan'. */ -- _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); -- -- fd = CreateFile( fname, -- GENERIC_READ | GENERIC_WRITE, -- FILE_SHARE_READ | FILE_SHARE_WRITE, -- (LPSECURITY_ATTRIBUTES)NULL, -- OPEN_EXISTING, -- FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, -- (HANDLE)NULL -- ); -- -- /* make sure that we are the only ones who have this chan open */ -- /* is this a threadsafe way to make sure that we are ok and will */ -- /* never return a valid handle to more than one thread for the same channel? */ -- -- wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; -- wan_udp.wan_udphdr_data_len = 0; -- -- DeviceIoControl( -- fd, -- IoctlManagementCommand, -- (LPVOID)&wan_udp, -- sizeof(wan_udp_hdr_t), -- (LPVOID)&wan_udp, -- sizeof(wan_udp_hdr_t), -- (LPDWORD)(&ln), -- (LPOVERLAPPED)NULL -- ); -- -- if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ -- /* somone already has this channel, or somthing else is not right. */ -- tdmv_api_close_socket(&fd); -- } -- --#else -- /* Does this fail if another thread already has this chan open? */ -- /* if not, we need to add some code to make sure it does */ -- snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); -- -- fd = open(fname, O_RDWR); -- -- if (fd < 0) { -- fd = WP_INVALID_SOCKET; -- } -- --#endif -- return fd; -+ return sangoma_open_tdmapi_span_chan(span, chan); - } - - - - static zap_io_interface_t wanpipe_interface; - --static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) --{ -- int err; -- -- /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ -- err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); -- -- if (err) { -- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); -- return ZAP_FAIL; -- } -- -- return ZAP_SUCCESS; --} -- - static unsigned char wanpipe_swap_bits(unsigned char cas_bits) - { - unsigned char swapped_bits = 0x0; -@@ -379,43 +142,17 @@ - - if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - wanpipe_tdm_api_t tdm_api; -+ memset(&tdm_api,0,sizeof(tdm_api)); - zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); - chan->physical_span_id = spanno; - chan->physical_chan_id = x; - chan->rate = 8000; - -- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { -- -- --#if 1 -- if (type == ZAP_CHAN_TYPE_FXO) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); -- } --#endif -- -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); --#if 1 -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); --#endif -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); -- -- } -- - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; -- wp_tdm_cmd_exec(chan, &tdm_api); -+ int err; -+ -+ /* FIXME: Handle Error Conditino 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 { -@@ -423,10 +160,24 @@ - } - } - -+#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) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; -- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); -- wp_tdm_cmd_exec(chan, &tdm_api); -+#ifdef LIBSANGOMA_VERSION -+ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); -+#else -+ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); -+#endif - } - - if (!zap_strlen_zero(name)) { -@@ -550,18 +301,31 @@ - static ZIO_OPEN_FUNCTION(wanpipe_open) - { - -+ int err; - wanpipe_tdm_api_t tdm_api; - -+ memset(&tdm_api,0,sizeof(tdm_api)); -+ - 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; -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; -- tdm_api.wp_tdm_cmd.tdm_codec = 0; -- wp_tdm_cmd_exec(zchan, &tdm_api); -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; -- tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; -- wp_tdm_cmd_exec(zchan, &tdm_api); -+ -+ sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, wp_globals.codec_ms); -+ -+ err=sangoma_tdm_get_hw_dtmf(zchan->sockfd, &tdm_api); -+ if (err > 0) { -+ err=sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api); -+ if (err == 0) { -+ //zap_log(ZAP_LOG_DEBUG, "Enabling HW DTMF FEATURE\n"); -+ zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); -+ } else { -+ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); -+ } -+ } else { -+ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); -+ } -+ - 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; -@@ -585,10 +349,8 @@ - switch(command) { - case ZAP_COMMAND_OFFHOOK: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); - return ZAP_FAIL; - } -@@ -597,10 +359,8 @@ - break; - case ZAP_COMMAND_ONHOOK: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); - return ZAP_FAIL; - } -@@ -609,9 +369,8 @@ - break; - case ZAP_COMMAND_GENERATE_RING_ON: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); - return ZAP_FAIL; - } -@@ -622,9 +381,8 @@ - break; - case ZAP_COMMAND_GENERATE_RING_OFF: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ 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; - } -@@ -634,27 +392,26 @@ - break; - case ZAP_COMMAND_GET_INTERVAL: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; -- -- if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -- ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; -+ err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); -+ if (err > 0 ) { -+ ZAP_COMMAND_OBJ_INT = err; -+ err=0; - } -- - } - break; - case ZAP_COMMAND_SET_INTERVAL: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; -- tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; -- err = wp_tdm_cmd_exec(zchan, &tdm_api); -+ 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: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; -- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); -- err = wp_tdm_cmd_exec(zchan, &tdm_api); -+#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: -@@ -683,7 +440,7 @@ - - memset(&hdrframe, 0, sizeof(hdrframe)); - -- rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); -+ rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); - - *datalen = rx_len; - -@@ -702,7 +459,7 @@ - - /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ - memset(&hdrframe, 0, sizeof(hdrframe)); -- bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); -+ 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) { -@@ -759,19 +516,29 @@ - return ZAP_SUCCESS; - } - --#ifndef WIN32 - ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) - { -+#ifdef LIBSANGOMA_VERSION -+ sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; -+#else - struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; -+#endif -+ - uint32_t i, j = 0, k = 0, l = 0; -+ int objects=0; - int r; - - for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = span->channels[i]; -+ -+#ifdef LIBSANGOMA_VERSION -+ sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); -+#else - memset(&pfds[j], 0, sizeof(pfds[j])); - pfds[j].fd = span->channels[i]->sockfd; - pfds[j].events = POLLPRI; -- -+#endif -+ objects++; - /* 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)) { -@@ -789,20 +556,16 @@ - int err; - memset(&tdm_api, 0, sizeof(tdm_api)); - if (zap_test_pflag(zchan, WP_RINGING)) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ 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 { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); - return ZAP_FAIL; - } -@@ -815,9 +578,12 @@ - if (l) { - ms = l; - } -+#ifdef LIBSANGOMA_VERSION -+ r = sangoma_socket_waitfor_many(pfds,objects,ms); -+#else -+ r = poll(pfds, j, ms); -+#endif - -- r = poll(pfds, j, ms); -- - if (r == 0) { - return l ? ZAP_SUCCESS : ZAP_TIMEOUT; - } else if (r < 0) { -@@ -828,7 +594,11 @@ - for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = span->channels[i]; - -+#ifdef LIBSANGOMA_VERSION -+ if (pfds[i-1].flags_out & 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++; -@@ -836,15 +606,43 @@ - } - - -- - return k ? ZAP_SUCCESS : ZAP_FAIL; - } - -+ -+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 = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; -+ -+ return ZAP_SUCCESS; -+} -+ -+ - ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) - { -- uint32_t i; -+ uint32_t i,err; - zap_oob_event_t event_id; - - for(i = 1; i <= span->chan_count; i++) { -@@ -869,29 +667,43 @@ - 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)); -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(span->channels[i], &tdm_api); -+ -+ sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); - } - 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); - -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; -- if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { -+ 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; - } - - switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { -+ -+ case WP_TDMAPI_EVENT_LINK_STATUS: -+ { -+ 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; -+ }; -+ } -+ break; -+ - case WP_TDMAPI_EVENT_RXHOOK: - { - if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { -@@ -918,11 +730,9 @@ - continue; - } else { - int err; -- -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { -+ 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; - } -@@ -948,6 +758,17 @@ - span->channels[i]->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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); -+ if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { -+ zap_channel_queue_dtmf(zchan, tmp_dtmf); -+ } -+ } -+ break; - default: - { - zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); -@@ -1005,6 +826,7 @@ - #endif - 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; -Index: configure.ac -=================================================================== ---- configure.ac (revision 717) -+++ configure.ac (working copy) -@@ -155,6 +155,9 @@ - [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) - AC_SUBST(enable_libpri) - -+AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) -+AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) -+ - AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) - - COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" -Index: Makefile.am -=================================================================== ---- Makefile.am (revision 717) -+++ Makefile.am (working copy) -@@ -154,10 +154,12 @@ - ozmod_skel_la_LDFLAGS = -module -avoid-version - ozmod_skel_la_LIBADD = $(MYLIB) - -+if LIBSANGOMA - ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c --ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) --ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -+ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe -+ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma - ozmod_wanpipe_la_LIBADD = $(MYLIB) -+endif - - ozmod_isdn_la_SOURCES = \ - $(SRC)/isdn/EuroISDNStateNT.c \ From c536c5e718aadc71c4fa7b71e2aae41865acdd20 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Apr 2009 21:23:24 +0000 Subject: [PATCH 1390/1766] del patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@720 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/patches/oz.diff | 1110 ---------------------------------- 1 file changed, 1110 deletions(-) delete mode 100644 libs/freetdm/patches/oz.diff diff --git a/libs/freetdm/patches/oz.diff b/libs/freetdm/patches/oz.diff deleted file mode 100644 index 2b8fa60012..0000000000 --- a/libs/freetdm/patches/oz.diff +++ /dev/null @@ -1,1110 +0,0 @@ -Index: src/ozmod/ozmod_ss7_boost/sigboost.h -=================================================================== ---- src/ozmod/ozmod_ss7_boost/sigboost.h (revision 717) -+++ src/ozmod/ozmod_ss7_boost/sigboost.h (working copy) -@@ -1,5 +1,5 @@ - /**************************************************************************** -- * sigboost.h $Revision: 1.5 $ -+ * sigboost.h $Revision: 1.13 $ - * - * Definitions for the sigboost interface. - * -@@ -14,6 +14,8 @@ - #ifndef _SIGBOOST_H_ - #define _SIGBOOST_H_ - -+#define SIGBOOST_VERSION 100 -+ - #include - #include - -@@ -48,16 +50,24 @@ - - 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, -+ //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 */ -+}; -+ - #define MAX_DIALED_DIGITS 31 - - /* Next two defines are used to create the range of values for call_setup_id -@@ -67,63 +77,73 @@ - #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 128 -+#define SIZE_RDNIS 900 - -+ - #pragma pack(1) -+ - typedef struct - { -- uint32_t event_id; -+ uint8_t capability; -+ uint8_t uil1p; -+}t_sigboost_bearer; -+ -+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; -- struct timeval tv; -- 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 */ -+ uint32_t fseqno; -+ uint32_t bseqno; -+ uint16_t call_setup_id; -+ uint32_t trunk_group; -+ uint8_t span; -+ uint8_t chan; -+ struct timeval tv; -+ 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 */ - /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ -- uint8_t calling_number_screening_ind; -- uint8_t calling_number_presentation; -- char calling_name[MAX_DIALED_DIGITS + 1]; -- uint16_t redirection_string_size; -- char redirection_string [SIZE_RDNIS]; /* it's a null terminated string */ -- /* redir string format: -- * http://www.ss7box.com/wiki/tiki-index.php?page=Call+Redirection -- * */ -+ uint8_t calling_number_screening_ind; -+ uint8_t calling_number_presentation; -+ char calling_name[MAX_DIALED_DIGITS + 1]; -+ t_sigboost_bearer bearer; -+ uint8_t hunt_group; -+ uint16_t isup_in_rdnis_size; -+ char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ - } t_sigboost_callstart; - --#define MIN_SIZE_CALLSTART_MSG (sizeof(t_sigboost_callstart) - SIZE_RDNIS) -+#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS - - typedef struct - { -- uint32_t event_id; -+ 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; -- struct timeval tv; -- uint8_t release_cause; -+ uint32_t fseqno; -+ uint32_t bseqno; -+ uint16_t call_setup_id; -+ uint32_t trunk_group; -+ uint8_t span; -+ uint8_t chan; -+ 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: -- return 1; -- default: -- return 0; -- } -+ switch (event_id) { -+ case SIGBOOST_EVENT_CALL_START: -+ case SIGBOOST_EVENT_DIGIT_IN: -+ return 1; -+ default: -+ return 0; -+ } - -- return 0; -+ return 0; - } - -+ - #endif -Index: src/ozmod/ozmod_ss7_boost/ss7_boost_client.c -=================================================================== ---- src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (revision 717) -+++ src/ozmod/ozmod_ss7_boost/ss7_boost_client.c (working copy) -@@ -73,7 +73,7 @@ - { - if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) - return; -- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", -+ 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]\n", - dir ? "TX":"RX", - ss7bc_event_id_name(event->event_id), - event->event_id, -@@ -91,7 +91,7 @@ - { - if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) - return; -- zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", -+ 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", - ss7bc_event_id_name(event->event_id), -@@ -261,6 +261,10 @@ - bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, - (struct sockaddr *) &mcon->local_addr, &fromlen); - -+ 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; -@@ -293,7 +297,7 @@ - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); - } - --#if 1 -+#if 0 - /* NC: NOT USED ANY MORE */ - if (mcon->rxseq_reset) { - //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { -@@ -310,15 +314,17 @@ - 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, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); -+ zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); - return NULL; - } - } -@@ -332,6 +338,10 @@ - int bytes = 0; - - bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); -+ -+ 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(ss7bc_short_event_t)) { - -@@ -356,7 +366,7 @@ - int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line) - { - int err; -- int event_size=sizeof(ss7bc_event_t); -+ 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"); -@@ -395,6 +405,7 @@ - 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); -@@ -432,6 +443,7 @@ - gettimeofday(&event->tv, NULL); - - 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); - -Index: src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -=================================================================== ---- src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (revision 717) -+++ src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c (working copy) -@@ -215,7 +215,11 @@ - - ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); - zap_set_string(event.calling_name, caller_data->cid_name); -- zap_set_string(event.redirection_string, caller_data->rdnis.digits); -+ zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); -+ if (strlen(caller_data->rdnis.digits)) { -+ event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; -+ } -+ - event.calling_number_screening_ind = caller_data->screen; - event.calling_number_presentation = caller_data->pres; - -@@ -483,7 +487,7 @@ - } - zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); - zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); -- zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->redirection_string); -+ zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); - zchan->caller_data.screen = event->calling_number_screening_ind; - zchan->caller_data.pres = event->calling_number_presentation; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); -@@ -851,7 +855,7 @@ - zap_span_t *span = (zap_span_t *) obj; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - ss7bc_connection_t *mcon, *pcon; -- uint32_t ms = 10, too_long = 20000; -+ uint32_t ms = 10; //, too_long = 20000; - - - ss7_boost_data->pcon = ss7_boost_data->mcon; -@@ -942,6 +946,8 @@ - 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); -@@ -953,6 +959,7 @@ - SIGBOOST_EVENT_SYSTEM_RESTART, - 0); - } -+#endif - - if (zap_running()) { - check_state(span); -@@ -1094,7 +1101,7 @@ - { - zap_ss7_boost_data_t *ss7_boost_data = NULL; - const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; -- int local_port = 5300, remote_port = 5300; -+ int local_port = 53000, remote_port = 53000; - char *var, *val; - int *intval; - -Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -=================================================================== ---- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 717) -+++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) -@@ -38,7 +38,7 @@ - #include "openzap.h" - #include - #include --#include "wanpipe_tdm_api_iface.h" -+#include "libsangoma.h" - - typedef enum { - WP_RINGING = (1 << 0) -@@ -57,196 +57,28 @@ - ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); - ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); - --#define WP_INVALID_SOCKET -1 --/* 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 */ -- uint32_t 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; -+#define WP_INVALID_SOCKET -1 - -- 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; --} -- - /* 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; -+#ifdef LIBSANGOMA_VERSION -+ int err; -+ sangoma_wait_obj_t sangoma_wait_obj; - -- if (!DeviceIoControl( -- fd, -- IoctlApiPoll, -- (LPVOID)NULL, -- 0L, -- (LPVOID)&api_poll, -- sizeof(API_POLL_STRUCT), -- (LPDWORD)(&ln), -- (LPOVERLAPPED)NULL)) { -- return -1; -- } -+ sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); - -- *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; -+ err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); -+ if (err > 0) { -+ *flags=sangoma_wait_obj.flags_out; - } -+ return err; - -- if (api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT) { -- return 0; -- } -- -- *flags = api_poll.poll_events_bitmap; -- -- return 1; - #else -- struct pollfd pfds[1]; -+ struct pollfd pfds[1]; - int res; - - memset(&pfds[0], 0, sizeof(pfds[0])); -@@ -265,87 +97,18 @@ - - return res; - #endif -+ - } - --#define FNAME_LEN 128 - static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) - { -- char fname[FNAME_LEN]; -- sng_fd_t fd = WP_INVALID_SOCKET; --#if defined(__WINDOWS__) -- DWORD ln; -- wan_udp_hdr_t wan_udp; -- -- /* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */ -- /* Subtract 1 from 'chan'. */ -- _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1); -- -- fd = CreateFile( fname, -- GENERIC_READ | GENERIC_WRITE, -- FILE_SHARE_READ | FILE_SHARE_WRITE, -- (LPSECURITY_ATTRIBUTES)NULL, -- OPEN_EXISTING, -- FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, -- (HANDLE)NULL -- ); -- -- /* make sure that we are the only ones who have this chan open */ -- /* is this a threadsafe way to make sure that we are ok and will */ -- /* never return a valid handle to more than one thread for the same channel? */ -- -- wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER; -- wan_udp.wan_udphdr_data_len = 0; -- -- DeviceIoControl( -- fd, -- IoctlManagementCommand, -- (LPVOID)&wan_udp, -- sizeof(wan_udp_hdr_t), -- (LPVOID)&wan_udp, -- sizeof(wan_udp_hdr_t), -- (LPDWORD)(&ln), -- (LPOVERLAPPED)NULL -- ); -- -- if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){ -- /* somone already has this channel, or somthing else is not right. */ -- tdmv_api_close_socket(&fd); -- } -- --#else -- /* Does this fail if another thread already has this chan open? */ -- /* if not, we need to add some code to make sure it does */ -- snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan); -- -- fd = open(fname, O_RDWR); -- -- if (fd < 0) { -- fd = WP_INVALID_SOCKET; -- } -- --#endif -- return fd; -+ return sangoma_open_tdmapi_span_chan(span, chan); - } - - - - static zap_io_interface_t wanpipe_interface; - --static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api) --{ -- int err; -- -- /* I'm told the 2nd arg is ignored but i send it as the cmd anyway for good measure */ -- err = ioctl(zchan->sockfd, tdm_api->wp_tdm_cmd.cmd, &tdm_api->wp_tdm_cmd); -- -- if (err) { -- snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); -- return ZAP_FAIL; -- } -- -- return ZAP_SUCCESS; --} -- - static unsigned char wanpipe_swap_bits(unsigned char cas_bits) - { - unsigned char swapped_bits = 0x0; -@@ -379,43 +142,17 @@ - - if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { - wanpipe_tdm_api_t tdm_api; -+ memset(&tdm_api,0,sizeof(tdm_api)); - zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); - chan->physical_span_id = spanno; - chan->physical_chan_id = x; - chan->rate = 8000; - -- if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { -- -- --#if 1 -- if (type == ZAP_CHAN_TYPE_FXO) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); -- } --#endif -- -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_DETECT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); --#if 1 -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RING_TRIP_DETECT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); --#endif -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_RXHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(chan, &tdm_api); -- -- } -- - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; -- wp_tdm_cmd_exec(chan, &tdm_api); -+ int err; -+ -+ /* FIXME: Handle Error Conditino 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 { -@@ -423,10 +160,24 @@ - } - } - -+#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) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; -- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(cas_bits); -- wp_tdm_cmd_exec(chan, &tdm_api); -+#ifdef LIBSANGOMA_VERSION -+ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); -+#else -+ sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); -+#endif - } - - if (!zap_strlen_zero(name)) { -@@ -550,18 +301,31 @@ - static ZIO_OPEN_FUNCTION(wanpipe_open) - { - -+ int err; - wanpipe_tdm_api_t tdm_api; - -+ memset(&tdm_api,0,sizeof(tdm_api)); -+ - 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; -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC; -- tdm_api.wp_tdm_cmd.tdm_codec = 0; -- wp_tdm_cmd_exec(zchan, &tdm_api); -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; -- tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; -- wp_tdm_cmd_exec(zchan, &tdm_api); -+ -+ sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, wp_globals.codec_ms); -+ -+ err=sangoma_tdm_get_hw_dtmf(zchan->sockfd, &tdm_api); -+ if (err > 0) { -+ err=sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api); -+ if (err == 0) { -+ //zap_log(ZAP_LOG_DEBUG, "Enabling HW DTMF FEATURE\n"); -+ zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); -+ } else { -+ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); -+ } -+ } else { -+ //zap_log(ZAP_LOG_DEBUG, "NO HW DTMF FEATURE\n"); -+ } -+ - 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; -@@ -585,10 +349,8 @@ - switch(command) { - case ZAP_COMMAND_OFFHOOK: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); - return ZAP_FAIL; - } -@@ -597,10 +359,8 @@ - break; - case ZAP_COMMAND_ONHOOK: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); - return ZAP_FAIL; - } -@@ -609,9 +369,8 @@ - break; - case ZAP_COMMAND_GENERATE_RING_ON: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); - return ZAP_FAIL; - } -@@ -622,9 +381,8 @@ - break; - case ZAP_COMMAND_GENERATE_RING_OFF: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ 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; - } -@@ -634,27 +392,26 @@ - break; - case ZAP_COMMAND_GET_INTERVAL: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD; -- -- if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -- ZAP_COMMAND_OBJ_INT = tdm_api.wp_tdm_cmd.usr_period; -+ err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); -+ if (err > 0 ) { -+ ZAP_COMMAND_OBJ_INT = err; -+ err=0; - } -- - } - break; - case ZAP_COMMAND_SET_INTERVAL: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; -- tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; -- err = wp_tdm_cmd_exec(zchan, &tdm_api); -+ 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: - { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS; -- tdm_api.wp_tdm_cmd.rbs_tx_bits = wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT); -- err = wp_tdm_cmd_exec(zchan, &tdm_api); -+#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: -@@ -683,7 +440,7 @@ - - memset(&hdrframe, 0, sizeof(hdrframe)); - -- rx_len = tdmv_api_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen); -+ rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); - - *datalen = rx_len; - -@@ -702,7 +459,7 @@ - - /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ - memset(&hdrframe, 0, sizeof(hdrframe)); -- bsent = tdmv_api_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen)); -+ 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) { -@@ -759,19 +516,29 @@ - return ZAP_SUCCESS; - } - --#ifndef WIN32 - ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) - { -+#ifdef LIBSANGOMA_VERSION -+ sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; -+#else - struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; -+#endif -+ - uint32_t i, j = 0, k = 0, l = 0; -+ int objects=0; - int r; - - for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = span->channels[i]; -+ -+#ifdef LIBSANGOMA_VERSION -+ sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); -+#else - memset(&pfds[j], 0, sizeof(pfds[j])); - pfds[j].fd = span->channels[i]->sockfd; - pfds[j].events = POLLPRI; -- -+#endif -+ objects++; - /* 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)) { -@@ -789,20 +556,16 @@ - int err; - memset(&tdm_api, 0, sizeof(tdm_api)); - if (zap_test_pflag(zchan, WP_RINGING)) { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_OFFHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_DISABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ 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 { -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_START; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(zchan, &tdm_api))) { -+ err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); -+ if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); - return ZAP_FAIL; - } -@@ -815,9 +578,12 @@ - if (l) { - ms = l; - } -+#ifdef LIBSANGOMA_VERSION -+ r = sangoma_socket_waitfor_many(pfds,objects,ms); -+#else -+ r = poll(pfds, j, ms); -+#endif - -- r = poll(pfds, j, ms); -- - if (r == 0) { - return l ? ZAP_SUCCESS : ZAP_TIMEOUT; - } else if (r < 0) { -@@ -828,7 +594,11 @@ - for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = span->channels[i]; - -+#ifdef LIBSANGOMA_VERSION -+ if (pfds[i-1].flags_out & 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++; -@@ -836,15 +606,43 @@ - } - - -- - return k ? ZAP_SUCCESS : ZAP_FAIL; - } - -+ -+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 = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; -+ -+ return ZAP_SUCCESS; -+} -+ -+ - ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) - { -- uint32_t i; -+ uint32_t i,err; - zap_oob_event_t event_id; - - for(i = 1; i <= span->chan_count; i++) { -@@ -869,29 +667,43 @@ - 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)); -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- wp_tdm_cmd_exec(span->channels[i], &tdm_api); -+ -+ sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); - } - 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); - -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT; -- if (wp_tdm_cmd_exec(span->channels[i], &tdm_api) != ZAP_SUCCESS) { -+ 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; - } - - switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { -+ -+ case WP_TDMAPI_EVENT_LINK_STATUS: -+ { -+ 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; -+ }; -+ } -+ break; -+ - case WP_TDMAPI_EVENT_RXHOOK: - { - if (span->channels[i]->type == ZAP_CHAN_TYPE_FXS) { -@@ -918,11 +730,9 @@ - continue; - } else { - int err; -- -- tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_EVENT; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type = WP_TDMAPI_EVENT_TXSIG_ONHOOK; -- tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_mode = WP_TDMAPI_EVENT_ENABLE; -- if ((err = wp_tdm_cmd_exec(span->channels[i], &tdm_api))) { -+ 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; - } -@@ -948,6 +758,17 @@ - span->channels[i]->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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); -+ if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { -+ zap_channel_queue_dtmf(zchan, tmp_dtmf); -+ } -+ } -+ break; - default: - { - zap_log(ZAP_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); -@@ -1005,6 +826,7 @@ - #endif - 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; -Index: configure.ac -=================================================================== ---- configure.ac (revision 717) -+++ configure.ac (working copy) -@@ -155,6 +155,9 @@ - [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) - AC_SUBST(enable_libpri) - -+AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) -+AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) -+ - AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) - - COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" -Index: Makefile.am -=================================================================== ---- Makefile.am (revision 717) -+++ Makefile.am (working copy) -@@ -154,10 +154,12 @@ - ozmod_skel_la_LDFLAGS = -module -avoid-version - ozmod_skel_la_LIBADD = $(MYLIB) - -+if LIBSANGOMA - ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c --ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) --ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -+ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe -+ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma - ozmod_wanpipe_la_LIBADD = $(MYLIB) -+endif - - ozmod_isdn_la_SOURCES = \ - $(SRC)/isdn/EuroISDNStateNT.c \ From e1a70efaa7fe911857aab408fed1d06dd9b2eb0e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Apr 2009 01:46:37 +0000 Subject: [PATCH 1391/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@722 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index a7930917d4..964ae5c96e 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -138,7 +138,11 @@ testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # # ozmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la + +if LIBSANGOMA +mod_LTLIBRARIES += ozmod_wanpipe.la +endif if LIBPRI mod_LTLIBRARIES += ozmod_libpri.la From e92f3a75e63161848e16cb6b157ce5c30f307e94 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Apr 2009 01:46:37 +0000 Subject: [PATCH 1392/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@722 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index a7930917d4..964ae5c96e 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -138,7 +138,11 @@ testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # # ozmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_wanpipe.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la + +if LIBSANGOMA +mod_LTLIBRARIES += ozmod_wanpipe.la +endif if LIBPRI mod_LTLIBRARIES += ozmod_libpri.la From 2a0211f4169ab040d73601c182bc1ef5be6b276b Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 15 May 2009 18:26:22 +0000 Subject: [PATCH 1393/1766] OPENZAP-66, thanks Moc git-svn-id: http://svn.openzap.org/svn/openzap/trunk@732 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e29f7f3ad4..7e72f214ea 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -200,12 +200,13 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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, "failure configuring device s%dc%d\n", spanno, x); } - - 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); } return configured; From bfc8ba629c2aef95754f51a644b59b3ee693e10f Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 15 May 2009 18:26:22 +0000 Subject: [PATCH 1394/1766] OPENZAP-66, thanks Moc git-svn-id: http://svn.openzap.org/svn/openzap/trunk@732 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e29f7f3ad4..7e72f214ea 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -200,12 +200,13 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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, "failure configuring device s%dc%d\n", spanno, x); } - - 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); } return configured; From 48b7fc8f1d4d20f24e9b06c2fca41789dceb32dd Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 15 May 2009 19:08:19 +0000 Subject: [PATCH 1395/1766] add wanpipe and pika to windows build (OPENZAP-65) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@733 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../msvc/testanalog/testanalog.2005.vcproj | 2 + .../msvc/testanalog/testanalog.2008.vcproj | 2 + .../msvc/testisdn/testisdn.2005.vcproj | 2 + .../msvc/testisdn/testisdn.2008.vcproj | 2 + libs/openzap/openzap.2005.sln | 8 + libs/openzap/openzap.2008.sln | 11 + libs/openzap/src/hashtable.c | 18 +- libs/openzap/src/include/hashtable.h | 19 +- libs/openzap/src/include/zap_config.h | 2 +- .../ozmod_analog/ozmod_analog.2005.vcproj | 2 + .../ozmod_analog/ozmod_analog.2008.vcproj | 2 + .../ozmod_analog_em.2005.vcproj | 2 + .../ozmod_analog_em.2008.vcproj | 2 + .../ozmod/ozmod_pika/ozmod_pika.2005.vcproj | 197 ++++++++++++++++++ .../ozmod/ozmod_pika/ozmod_pika.2008.vcproj | 197 ++++++++++++++++++ .../openzap/src/ozmod/ozmod_pika/ozmod_pika.c | 22 +- libs/openzap/src/ozmod/ozmod_pika/zap_pika.h | 34 ++- .../ozmod_wanpipe/ozmod_wanpipe.2005.vcproj | 196 +++++++++++++++++ .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 196 +++++++++++++++++ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 27 ++- libs/openzap/src/zap_config.c | 2 +- 21 files changed, 911 insertions(+), 34 deletions(-) create mode 100644 libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj create mode 100644 libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj diff --git a/libs/openzap/msvc/testanalog/testanalog.2005.vcproj b/libs/openzap/msvc/testanalog/testanalog.2005.vcproj index 7f762fe4ad..93553d2a5f 100644 --- a/libs/openzap/msvc/testanalog/testanalog.2005.vcproj +++ b/libs/openzap/msvc/testanalog/testanalog.2005.vcproj @@ -51,6 +51,7 @@ WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + DisableSpecificWarnings="4100" /> entrycount; } /*****************************************************************************/ -int +OZ_DECLARE(int) hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) { /* This method allows duplicate keys - but they shouldn't be used */ @@ -191,7 +191,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) } /*****************************************************************************/ -void * /* returns value associated with key */ +OZ_DECLARE(void *) /* returns value associated with key */ hashtable_search(struct hashtable *h, void *k) { struct entry *e; @@ -209,7 +209,7 @@ hashtable_search(struct hashtable *h, void *k) } /*****************************************************************************/ -void * /* returns value associated with key */ +OZ_DECLARE(void *) /* returns value associated with key */ hashtable_remove(struct hashtable *h, void *k) { /* TODO: consider compacting the table when the load factor drops enough, @@ -246,7 +246,7 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ -void +OZ_DECLARE(void) hashtable_destroy(struct hashtable *h) { unsigned int i; @@ -264,7 +264,7 @@ hashtable_destroy(struct hashtable *h) free(h); } -struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) +OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i) { if (i->e) { @@ -290,7 +290,7 @@ struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) return NULL; } -struct hashtable_iterator *hashtable_first(struct hashtable *h) +OZ_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h) { h->iterator.pos = 0; h->iterator.e = NULL; @@ -300,7 +300,7 @@ struct hashtable_iterator *hashtable_first(struct hashtable *h) -void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) +OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) { if (i->e) { if (key) { diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index 137e9460e6..ea63e2e91d 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -7,6 +7,7 @@ #define __inline__ __inline #endif #endif +#include "openzap.h" struct hashtable; struct hashtable_iterator; @@ -77,7 +78,7 @@ struct hashtable_iterator; * @return newly created hashtable or NULL on failure */ -struct hashtable * +OZ_DECLARE(struct hashtable *) create_hashtable(unsigned int minsize, unsigned int (*hashfunction) (void*), int (*key_eq_fn) (void*,void*)); @@ -108,7 +109,7 @@ typedef enum { HASHTABLE_FLAG_FREE_VALUE = (1 << 1) } hashtable_flag_t; -int +OZ_DECLARE(int) hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); #define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ @@ -126,7 +127,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); * @return the value associated with the key, or NULL if none found */ -void * +OZ_DECLARE(void *) hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ @@ -144,7 +145,7 @@ hashtable_search(struct hashtable *h, void *k); * @return the value associated with the key, or NULL if none found */ -void * /* returns value */ +OZ_DECLARE(void *) /* returns value */ hashtable_remove(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ @@ -161,7 +162,7 @@ hashtable_remove(struct hashtable *h, void *k); * @param h the hashtable * @return the number of items stored in the hashtable */ -unsigned int +OZ_DECLARE(unsigned int) hashtable_count(struct hashtable *h); @@ -173,12 +174,12 @@ hashtable_count(struct hashtable *h); * @param free_values whether to call 'free' on the remaining values */ -void +OZ_DECLARE(void) hashtable_destroy(struct hashtable *h); -struct hashtable_iterator *hashtable_first(struct hashtable *h); -struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i); -void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); +OZ_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h); +OZ_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i); +OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); #endif /* __HASHTABLE_CWC22_H__ */ diff --git a/libs/openzap/src/include/zap_config.h b/libs/openzap/src/include/zap_config.h index f550029388..967c09cd79 100644 --- a/libs/openzap/src/include/zap_config.h +++ b/libs/openzap/src/include/zap_config.h @@ -121,7 +121,7 @@ int zap_config_next_pair(zap_config_t * cfg, char **var, char **val); \param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx) \param outbits pointer to aim at the CAS bits */ -int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); +OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); /** @} */ diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj index f0d697c619..964393805c 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj @@ -49,6 +49,7 @@ WarningLevel="4" WarnAsError="true" DebugInformationFormat="4" + DisableSpecificWarnings="4100" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj new file mode 100644 index 0000000000..2e3cfceb13 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c index c409f9535e..5de8ac3974 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c @@ -35,6 +35,12 @@ #include "openzap.h" #include "zap_pika.h" +#if defined(__WINDOWS__) +#define EX_DECLARE_DATA __declspec(dllexport) +#else +EX_DECLARE_DATA +#endif + #define MAX_NUMBER_OF_TRUNKS 64 #define PIKA_BLOCK_SIZE 160 #define PIKA_BLOCK_LEN 20 @@ -45,19 +51,19 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event); ZAP_ENUM_NAMES(PIKA_SPAN_NAMES, PIKA_SPAN_STRINGS) -ZAP_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID) +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) -ZAP_STR2ENUM(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding, PIKA_SPAN_ENCODING_NAMES, PIKA_SPAN_ENCODING_INVALID) +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) -ZAP_STR2ENUM(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength, PIKA_LL_NAMES, PIKA_SPAN_LOOP_INVALID) +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) -ZAP_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID) +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) -ZAP_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID) +PIKA_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID) typedef enum { @@ -153,7 +159,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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_insert(globals.profile_hash, (void *)profile->name, profile, HASHTABLE_FLAG_NONE); zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } @@ -1335,12 +1341,12 @@ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) zap_log(ZAP_LOG_INFO, "Closing system handle\n"); } - hashtable_destroy(globals.profile_hash, 0, 1); + hashtable_destroy(globals.profile_hash); return ZAP_SUCCESS; } -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "pika", pika_init, pika_destroy, diff --git a/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h index c8401c6aa1..da1864d486 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h +++ b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h @@ -38,6 +38,30 @@ +#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, @@ -47,7 +71,7 @@ typedef enum { PIKA_SPAN_INVALID } PIKA_TSpanFraming; #define PIKA_SPAN_STRINGS "T1_D4", "T1_ESF", "E1_BASIC", "E1_CRC4" -ZAP_STR2ENUM_P(pika_str2span, pika_span2str, PIKA_TSpanFraming) +PIKA_STR2ENUM_P(pika_str2span, pika_span2str, PIKA_TSpanFraming) typedef enum { PIKA_SPAN_ENCODING_T1_AMI_ZS_NONE, @@ -60,7 +84,7 @@ typedef enum { 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" -ZAP_STR2ENUM_P(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding) +PIKA_STR2ENUM_P(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding) typedef enum { PIKA_SPAN_LOOP_LENGTH_SHORT_HAUL, @@ -68,7 +92,7 @@ typedef enum { PIKA_SPAN_LOOP_INVALID } PIKA_TSpanLoopLength; #define PIKA_LL_STRINGS "SHORT_HAUL", "LONG_HAUL" -ZAP_STR2ENUM_P(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength) +PIKA_STR2ENUM_P(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength) typedef enum { PIKA_SPAN_LBO_T1_LONG_0_DB, @@ -84,7 +108,7 @@ typedef enum { 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" -ZAP_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) +PIKA_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) typedef enum { PIKA_SPAN_COMPAND_MODE_MU_LAW = 1, @@ -92,7 +116,7 @@ typedef enum { PIKA_SPAN_COMPAND_MODE_INVALID } PIKA_TSpanCompandMode; #define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW" -ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) +PIKA_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) #endif diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj new file mode 100644 index 0000000000..da21a76b7a --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj new file mode 100644 index 0000000000..1c8685c6d4 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 7e72f214ea..9974d7a786 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -36,10 +36,35 @@ #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 +#define EX_DECLARE_DATA __declspec(dllexport) +#else +WP_DECLARE_DATA +#endif + typedef enum { WP_RINGING = (1 << 0) } wp_flag_t; @@ -849,7 +874,7 @@ static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) } -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "wanpipe", wanpipe_init, wanpipe_destroy, diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index ab622dd7d3..32567041eb 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -209,7 +209,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } -int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) +OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) { char cas_bits[5]; unsigned char bit = 0x8; From dd27345bffb9a6e68e04805e7360ca0ca7b37133 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 15 May 2009 19:08:19 +0000 Subject: [PATCH 1396/1766] add wanpipe and pika to windows build (OPENZAP-65) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@733 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../msvc/testanalog/testanalog.2005.vcproj | 2 + .../msvc/testanalog/testanalog.2008.vcproj | 2 + .../msvc/testisdn/testisdn.2005.vcproj | 2 + .../msvc/testisdn/testisdn.2008.vcproj | 2 + libs/freetdm/openzap.2005.sln | 8 + libs/freetdm/openzap.2008.sln | 11 + libs/freetdm/src/hashtable.c | 18 +- libs/freetdm/src/include/hashtable.h | 19 +- libs/freetdm/src/include/zap_config.h | 2 +- .../ozmod_analog/ozmod_analog.2005.vcproj | 2 + .../ozmod_analog/ozmod_analog.2008.vcproj | 2 + .../ozmod_analog_em.2005.vcproj | 2 + .../ozmod_analog_em.2008.vcproj | 2 + .../ozmod/ozmod_pika/ozmod_pika.2005.vcproj | 197 ++++++++++++++++++ .../ozmod/ozmod_pika/ozmod_pika.2008.vcproj | 197 ++++++++++++++++++ .../freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 22 +- libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h | 34 ++- .../ozmod_wanpipe/ozmod_wanpipe.2005.vcproj | 196 +++++++++++++++++ .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 196 +++++++++++++++++ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 27 ++- libs/freetdm/src/zap_config.c | 2 +- 21 files changed, 911 insertions(+), 34 deletions(-) create mode 100644 libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj create mode 100644 libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj diff --git a/libs/freetdm/msvc/testanalog/testanalog.2005.vcproj b/libs/freetdm/msvc/testanalog/testanalog.2005.vcproj index 7f762fe4ad..93553d2a5f 100644 --- a/libs/freetdm/msvc/testanalog/testanalog.2005.vcproj +++ b/libs/freetdm/msvc/testanalog/testanalog.2005.vcproj @@ -51,6 +51,7 @@ WarnAsError="true" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + DisableSpecificWarnings="4100" /> entrycount; } /*****************************************************************************/ -int +OZ_DECLARE(int) hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) { /* This method allows duplicate keys - but they shouldn't be used */ @@ -191,7 +191,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) } /*****************************************************************************/ -void * /* returns value associated with key */ +OZ_DECLARE(void *) /* returns value associated with key */ hashtable_search(struct hashtable *h, void *k) { struct entry *e; @@ -209,7 +209,7 @@ hashtable_search(struct hashtable *h, void *k) } /*****************************************************************************/ -void * /* returns value associated with key */ +OZ_DECLARE(void *) /* returns value associated with key */ hashtable_remove(struct hashtable *h, void *k) { /* TODO: consider compacting the table when the load factor drops enough, @@ -246,7 +246,7 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ -void +OZ_DECLARE(void) hashtable_destroy(struct hashtable *h) { unsigned int i; @@ -264,7 +264,7 @@ hashtable_destroy(struct hashtable *h) free(h); } -struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) +OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i) { if (i->e) { @@ -290,7 +290,7 @@ struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i) return NULL; } -struct hashtable_iterator *hashtable_first(struct hashtable *h) +OZ_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h) { h->iterator.pos = 0; h->iterator.e = NULL; @@ -300,7 +300,7 @@ struct hashtable_iterator *hashtable_first(struct hashtable *h) -void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) +OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) { if (i->e) { if (key) { diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 137e9460e6..ea63e2e91d 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -7,6 +7,7 @@ #define __inline__ __inline #endif #endif +#include "openzap.h" struct hashtable; struct hashtable_iterator; @@ -77,7 +78,7 @@ struct hashtable_iterator; * @return newly created hashtable or NULL on failure */ -struct hashtable * +OZ_DECLARE(struct hashtable *) create_hashtable(unsigned int minsize, unsigned int (*hashfunction) (void*), int (*key_eq_fn) (void*,void*)); @@ -108,7 +109,7 @@ typedef enum { HASHTABLE_FLAG_FREE_VALUE = (1 << 1) } hashtable_flag_t; -int +OZ_DECLARE(int) hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); #define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ @@ -126,7 +127,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); * @return the value associated with the key, or NULL if none found */ -void * +OZ_DECLARE(void *) hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ @@ -144,7 +145,7 @@ hashtable_search(struct hashtable *h, void *k); * @return the value associated with the key, or NULL if none found */ -void * /* returns value */ +OZ_DECLARE(void *) /* returns value */ hashtable_remove(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ @@ -161,7 +162,7 @@ hashtable_remove(struct hashtable *h, void *k); * @param h the hashtable * @return the number of items stored in the hashtable */ -unsigned int +OZ_DECLARE(unsigned int) hashtable_count(struct hashtable *h); @@ -173,12 +174,12 @@ hashtable_count(struct hashtable *h); * @param free_values whether to call 'free' on the remaining values */ -void +OZ_DECLARE(void) hashtable_destroy(struct hashtable *h); -struct hashtable_iterator *hashtable_first(struct hashtable *h); -struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i); -void hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); +OZ_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h); +OZ_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i); +OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); #endif /* __HASHTABLE_CWC22_H__ */ diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h index f550029388..967c09cd79 100644 --- a/libs/freetdm/src/include/zap_config.h +++ b/libs/freetdm/src/include/zap_config.h @@ -121,7 +121,7 @@ int zap_config_next_pair(zap_config_t * cfg, char **var, char **val); \param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx) \param outbits pointer to aim at the CAS bits */ -int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); +OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); /** @} */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj index f0d697c619..964393805c 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj @@ -49,6 +49,7 @@ WarningLevel="4" WarnAsError="true" DebugInformationFormat="4" + DisableSpecificWarnings="4100" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj new file mode 100644 index 0000000000..2e3cfceb13 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index c409f9535e..5de8ac3974 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -35,6 +35,12 @@ #include "openzap.h" #include "zap_pika.h" +#if defined(__WINDOWS__) +#define EX_DECLARE_DATA __declspec(dllexport) +#else +EX_DECLARE_DATA +#endif + #define MAX_NUMBER_OF_TRUNKS 64 #define PIKA_BLOCK_SIZE 160 #define PIKA_BLOCK_LEN 20 @@ -45,19 +51,19 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event); ZAP_ENUM_NAMES(PIKA_SPAN_NAMES, PIKA_SPAN_STRINGS) -ZAP_STR2ENUM(pika_str2span, pika_span2str, PIKA_TSpanFraming, PIKA_SPAN_NAMES, PIKA_SPAN_INVALID) +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) -ZAP_STR2ENUM(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding, PIKA_SPAN_ENCODING_NAMES, PIKA_SPAN_ENCODING_INVALID) +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) -ZAP_STR2ENUM(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength, PIKA_LL_NAMES, PIKA_SPAN_LOOP_INVALID) +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) -ZAP_STR2ENUM(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut, PIKA_LBO_NAMES, PIKA_SPAN_LBO_INVALID) +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) -ZAP_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID) +PIKA_STR2ENUM(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode, PIKA_SPAN_COMPAND_MODE_NAMES, PIKA_SPAN_COMPAND_MODE_INVALID) typedef enum { @@ -153,7 +159,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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_insert(globals.profile_hash, (void *)profile->name, profile, HASHTABLE_FLAG_NONE); zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); } @@ -1335,12 +1341,12 @@ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) zap_log(ZAP_LOG_INFO, "Closing system handle\n"); } - hashtable_destroy(globals.profile_hash, 0, 1); + hashtable_destroy(globals.profile_hash); return ZAP_SUCCESS; } -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "pika", pika_init, pika_destroy, diff --git a/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h b/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h index c8401c6aa1..da1864d486 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h +++ b/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h @@ -38,6 +38,30 @@ +#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, @@ -47,7 +71,7 @@ typedef enum { PIKA_SPAN_INVALID } PIKA_TSpanFraming; #define PIKA_SPAN_STRINGS "T1_D4", "T1_ESF", "E1_BASIC", "E1_CRC4" -ZAP_STR2ENUM_P(pika_str2span, pika_span2str, PIKA_TSpanFraming) +PIKA_STR2ENUM_P(pika_str2span, pika_span2str, PIKA_TSpanFraming) typedef enum { PIKA_SPAN_ENCODING_T1_AMI_ZS_NONE, @@ -60,7 +84,7 @@ typedef enum { 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" -ZAP_STR2ENUM_P(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding) +PIKA_STR2ENUM_P(pika_str2span_encoding, pika_span_encoding2str, PIKA_TSpanEncoding) typedef enum { PIKA_SPAN_LOOP_LENGTH_SHORT_HAUL, @@ -68,7 +92,7 @@ typedef enum { PIKA_SPAN_LOOP_INVALID } PIKA_TSpanLoopLength; #define PIKA_LL_STRINGS "SHORT_HAUL", "LONG_HAUL" -ZAP_STR2ENUM_P(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength) +PIKA_STR2ENUM_P(pika_str2loop_length, pika_loop_length2str, PIKA_TSpanLoopLength) typedef enum { PIKA_SPAN_LBO_T1_LONG_0_DB, @@ -84,7 +108,7 @@ typedef enum { 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" -ZAP_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) +PIKA_STR2ENUM_P(pika_str2lbo, pika_lbo2str, PIKA_TSpanBuildOut) typedef enum { PIKA_SPAN_COMPAND_MODE_MU_LAW = 1, @@ -92,7 +116,7 @@ typedef enum { PIKA_SPAN_COMPAND_MODE_INVALID } PIKA_TSpanCompandMode; #define PIKA_SPAN_COMPAND_MODE_STRINGS "MU_LAW", "A_LAW" -ZAP_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) +PIKA_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandMode) #endif diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj new file mode 100644 index 0000000000..da21a76b7a --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj new file mode 100644 index 0000000000..1c8685c6d4 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 7e72f214ea..9974d7a786 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -36,10 +36,35 @@ #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 +#define EX_DECLARE_DATA __declspec(dllexport) +#else +WP_DECLARE_DATA +#endif + typedef enum { WP_RINGING = (1 << 0) } wp_flag_t; @@ -849,7 +874,7 @@ static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) } -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "wanpipe", wanpipe_init, wanpipe_destroy, diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index ab622dd7d3..32567041eb 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -209,7 +209,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } -int zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) +OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) { char cas_bits[5]; unsigned char bit = 0x8; From 574ac56a70099af1ea83ccab74b572d7f4584d94 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 15 May 2009 21:24:58 +0000 Subject: [PATCH 1397/1766] fix typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@734 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 9974d7a786..aa32132aa4 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -62,7 +62,7 @@ #define sangoma_create_socket_intr sangoma_open_api_span_chan #define EX_DECLARE_DATA __declspec(dllexport) #else -WP_DECLARE_DATA +#define EX_DECLARE_DATA #endif typedef enum { From 9624461049b23ec17b7a061fb0b02aab7dfa2483 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 15 May 2009 21:24:58 +0000 Subject: [PATCH 1398/1766] fix typo git-svn-id: http://svn.openzap.org/svn/openzap/trunk@734 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 9974d7a786..aa32132aa4 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -62,7 +62,7 @@ #define sangoma_create_socket_intr sangoma_open_api_span_chan #define EX_DECLARE_DATA __declspec(dllexport) #else -WP_DECLARE_DATA +#define EX_DECLARE_DATA #endif typedef enum { From cb362b4d55296a4bcfd6d07d2eb8c6cad2f62f6e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 May 2009 21:47:48 +0000 Subject: [PATCH 1399/1766] extend timeout tolerance on openzap read to fix race in digium/zaptel/dahdi/whatever its called git-svn-id: http://svn.openzap.org/svn/openzap/trunk@735 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index feca83dc8b..5caa9e1a5b 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -566,8 +566,11 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); + /* Digium Cards sometimes timeout several times in a row here. + Yes, we support digium cards, ain't we nice....... + 6 double length intervals should compensate */ chunk = tech_pvt->zchan->effective_interval * 2; - total_to = chunk * 2; + total_to = chunk * 6; if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { return SWITCH_STATUS_FALSE; From 8036f3839ca9e9c1d006eaee9c2be511ea6a9a4c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 May 2009 21:47:48 +0000 Subject: [PATCH 1400/1766] extend timeout tolerance on openzap read to fix race in digium/zaptel/dahdi/whatever its called git-svn-id: http://svn.openzap.org/svn/openzap/trunk@735 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index feca83dc8b..5caa9e1a5b 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -566,8 +566,11 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch assert(tech_pvt->zchan != NULL); + /* Digium Cards sometimes timeout several times in a row here. + Yes, we support digium cards, ain't we nice....... + 6 double length intervals should compensate */ chunk = tech_pvt->zchan->effective_interval * 2; - total_to = chunk * 2; + total_to = chunk * 6; if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { return SWITCH_STATUS_FALSE; From 34a4427fba6a00d378291a6fcae7c485c52066c5 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 4 Jun 2009 16:18:22 +0000 Subject: [PATCH 1401/1766] OPENZAP-74 thx Raul see you at ClueCon git-svn-id: http://svn.openzap.org/svn/openzap/trunk@736 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/zt.conf | 3 + libs/openzap/src/include/zap_types.h | 4 + libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 93 +++++++++++++++++++++- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/libs/openzap/conf/zt.conf b/libs/openzap/conf/zt.conf index ac60475b25..a060a40315 100644 --- a/libs/openzap/conf/zt.conf +++ b/libs/openzap/conf/zt.conf @@ -3,3 +3,6 @@ codec_ms => 20 wink_ms => 150 flash_ms => 750 echo_cancel_level => 64 +rxgain => 0.0 +txgain => 0.0 + diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index e5218ca4b8..13e8c2a7a3 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -275,6 +275,10 @@ typedef enum { 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_COUNT } zap_command_t; diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index c3f80e0f6e..6ffedc29b6 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -42,6 +42,8 @@ static struct { uint32_t flash_ms; uint32_t eclevel; uint32_t etlevel; + float rxgain; + float txgain; } zt_globals; struct ioctl_codes { @@ -165,6 +167,57 @@ 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); +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; + } +} + 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; @@ -319,8 +372,26 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zchan->native_codec = zchan->effective_codec = type; } + if(zt_globals.rxgain || zt_globals.txgain) { + struct zt_gains gains; + memset(&gains, 0, sizeof(gains)); + + gains.chan_no = ztp.chan_no; + 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(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, sockfd); + close(sockfd); + continue; + } + } } - ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; @@ -330,7 +401,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); continue; } - if (!zap_strlen_zero(name)) { zap_copy_string(zchan->chan_name, name, sizeof(zchan->chan_name)); @@ -414,6 +484,7 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) { int num; + float fnum; if (!strcasecmp(category, "defaults")) { if (!strcasecmp(var, "codec_ms")) { @@ -445,6 +516,24 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) zt_globals.eclevel = 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); + } + } } From 385fa177320dc1406eddc8b1cd6135bfa55df810 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 4 Jun 2009 16:18:22 +0000 Subject: [PATCH 1402/1766] OPENZAP-74 thx Raul see you at ClueCon git-svn-id: http://svn.openzap.org/svn/openzap/trunk@736 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/zt.conf | 3 + libs/freetdm/src/include/zap_types.h | 4 + libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 93 +++++++++++++++++++++- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/conf/zt.conf b/libs/freetdm/conf/zt.conf index ac60475b25..a060a40315 100644 --- a/libs/freetdm/conf/zt.conf +++ b/libs/freetdm/conf/zt.conf @@ -3,3 +3,6 @@ codec_ms => 20 wink_ms => 150 flash_ms => 750 echo_cancel_level => 64 +rxgain => 0.0 +txgain => 0.0 + diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index e5218ca4b8..13e8c2a7a3 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -275,6 +275,10 @@ typedef enum { 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_COUNT } zap_command_t; diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index c3f80e0f6e..6ffedc29b6 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -42,6 +42,8 @@ static struct { uint32_t flash_ms; uint32_t eclevel; uint32_t etlevel; + float rxgain; + float txgain; } zt_globals; struct ioctl_codes { @@ -165,6 +167,57 @@ 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); +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; + } +} + 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; @@ -319,8 +372,26 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zchan->native_codec = zchan->effective_codec = type; } + if(zt_globals.rxgain || zt_globals.txgain) { + struct zt_gains gains; + memset(&gains, 0, sizeof(gains)); + + gains.chan_no = ztp.chan_no; + 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(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, sockfd); + close(sockfd); + continue; + } + } } - ztp.wink_time = zt_globals.wink_ms; ztp.flash_time = zt_globals.flash_ms; @@ -330,7 +401,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); continue; } - if (!zap_strlen_zero(name)) { zap_copy_string(zchan->chan_name, name, sizeof(zchan->chan_name)); @@ -414,6 +484,7 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) { int num; + float fnum; if (!strcasecmp(category, "defaults")) { if (!strcasecmp(var, "codec_ms")) { @@ -445,6 +516,24 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) zt_globals.eclevel = 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); + } + } } From 1bfb99db66a0a71c1ed4139f0b6fbe53b0fd5afe Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 4 Jun 2009 17:20:53 +0000 Subject: [PATCH 1403/1766] [ozmod_libpri] Fix array out of bounds error and clean up some enums in lpwrap_pri.h git-svn-id: http://svn.openzap.org/svn/openzap/trunk@737 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 65 ++++++++++--------- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h index c3832626c1..cae88ccb92 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -40,26 +40,29 @@ #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_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 + 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 { @@ -68,17 +71,20 @@ typedef enum { } 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_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 + 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 { @@ -88,7 +94,6 @@ typedef enum { struct lpwrap_pri; typedef int (*event_handler)(struct lpwrap_pri *, lpwrap_pri_event_t, pri_event *); typedef int (*loop_handler)(struct lpwrap_pri *); -#define MAX_EVENT 18 struct lpwrap_pri { struct pri *pri; @@ -96,7 +101,7 @@ struct lpwrap_pri { zap_channel_t *dchan; unsigned int flags; void *private_info; - event_handler eventmap[MAX_EVENT+1]; + event_handler eventmap[LPWRAP_PRI_EVENT_MAX]; loop_handler on_loop; }; diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 7053d3177d..013884da81 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -900,7 +900,7 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); @@ -910,9 +910,9 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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; } From 5954416c96dcdcb9e29c3093f57dfc9de07c201e Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 4 Jun 2009 17:20:53 +0000 Subject: [PATCH 1404/1766] [ozmod_libpri] Fix array out of bounds error and clean up some enums in lpwrap_pri.h git-svn-id: http://svn.openzap.org/svn/openzap/trunk@737 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_libpri/lpwrap_pri.h | 65 ++++++++++--------- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h index c3832626c1..cae88ccb92 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -40,26 +40,29 @@ #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_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 + 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 { @@ -68,17 +71,20 @@ typedef enum { } 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_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 + 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 { @@ -88,7 +94,6 @@ typedef enum { struct lpwrap_pri; typedef int (*event_handler)(struct lpwrap_pri *, lpwrap_pri_event_t, pri_event *); typedef int (*loop_handler)(struct lpwrap_pri *); -#define MAX_EVENT 18 struct lpwrap_pri { struct pri *pri; @@ -96,7 +101,7 @@ struct lpwrap_pri { zap_channel_t *dchan; unsigned int flags; void *private_info; - event_handler eventmap[MAX_EVENT+1]; + event_handler eventmap[LPWRAP_PRI_EVENT_MAX]; loop_handler on_loop; }; diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 7053d3177d..013884da81 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -900,7 +900,7 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); @@ -910,9 +910,9 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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; } From 246cad4ed52f9c686331c77d47777ed856c564e8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 4 Jun 2009 22:31:04 +0000 Subject: [PATCH 1405/1766] add @gx notation to dialed number for bri boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@738 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index f5daec4afc..71ec08d473 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -193,6 +193,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_event_t event = {0}; int sanity = 5000; ss7_boost_request_status_t st; + char ani[128] = ""; + char *gr = NULL; if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); @@ -213,7 +215,39 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + + zap_set_string(ani, caller_data->ani.digits); + + if ((gr = strchr(ani, '@'))) { + *gr++ = '\0'; + } + + ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); + + if (gr) { + switch(*gr) { + event.trunk_group = atoi(gr+1); + + 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.isup_in_rdnis, caller_data->rdnis.digits); if (strlen(caller_data->rdnis.digits)) { From aa5e4207ceb7e602030a977b3d90116f8aaa1390 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 4 Jun 2009 22:31:04 +0000 Subject: [PATCH 1406/1766] add @gx notation to dialed number for bri boost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@738 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index f5daec4afc..71ec08d473 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -193,6 +193,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_event_t event = {0}; int sanity = 5000; ss7_boost_request_status_t st; + char ani[128] = ""; + char *gr = NULL; if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); @@ -213,7 +215,39 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - ss7bc_call_init(&event, caller_data->cid_num.digits, caller_data->ani.digits, r); + + zap_set_string(ani, caller_data->ani.digits); + + if ((gr = strchr(ani, '@'))) { + *gr++ = '\0'; + } + + ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); + + if (gr) { + switch(*gr) { + event.trunk_group = atoi(gr+1); + + 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.isup_in_rdnis, caller_data->rdnis.digits); if (strlen(caller_data->rdnis.digits)) { From 5a4a76a2cacc8e1dbc4d112ffad1343c28162ac2 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 4 Jun 2009 23:08:11 +0000 Subject: [PATCH 1407/1766] OPENZAP-76 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@739 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 6ffedc29b6..db20ef95c5 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -372,25 +372,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zchan->native_codec = zchan->effective_codec = type; } - if(zt_globals.rxgain || zt_globals.txgain) { - struct zt_gains gains; - memset(&gains, 0, sizeof(gains)); - - gains.chan_no = ztp.chan_no; - 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(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, sockfd); - close(sockfd); - continue; - } - } } ztp.wink_time = zt_globals.wink_ms; @@ -582,6 +563,35 @@ static ZIO_OPEN_FUNCTION(zt_open) } } } + 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); + } + } + + int len = zt_globals.eclevel; + zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, 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 { + 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; } From 8502f240e69d7b4c334c541015b2edd6e5c54cdd Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 4 Jun 2009 23:08:11 +0000 Subject: [PATCH 1408/1766] OPENZAP-76 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@739 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 6ffedc29b6..db20ef95c5 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -372,25 +372,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zchan->native_codec = zchan->effective_codec = type; } - if(zt_globals.rxgain || zt_globals.txgain) { - struct zt_gains gains; - memset(&gains, 0, sizeof(gains)); - - gains.chan_no = ztp.chan_no; - 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(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, sockfd); - close(sockfd); - continue; - } - } } ztp.wink_time = zt_globals.wink_ms; @@ -582,6 +563,35 @@ static ZIO_OPEN_FUNCTION(zt_open) } } } + 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); + } + } + + int len = zt_globals.eclevel; + zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, 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 { + 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; } From 9a1c1d21c9bf42c5598cd18522567ea56a2f7fdc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 5 Jun 2009 20:47:53 +0000 Subject: [PATCH 1409/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@740 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 71ec08d473..22ae8e2cbf 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -224,10 +224,10 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); - if (gr) { - switch(*gr) { - event.trunk_group = atoi(gr+1); + if (gr && *(gr+1)) { + event.trunk_group = atoi(gr+1); + switch(*gr) { case 'g': event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC; break; @@ -241,9 +241,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) event.hunt_group = SIGBOOST_HUNTGRP_RR_DESC; break; default: - zap_log(ZAP_LOG_WARNING, - "Failed to determine huntgroup (%s)\n", - gr); + zap_log(ZAP_LOG_WARNING, "Failed to determine huntgroup (%s)\n", gr); event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC; } } From 281177c924b447e83346c2d82114b82aba7396f1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 5 Jun 2009 20:47:53 +0000 Subject: [PATCH 1410/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@740 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 71ec08d473..22ae8e2cbf 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -224,10 +224,10 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); - if (gr) { - switch(*gr) { - event.trunk_group = atoi(gr+1); + if (gr && *(gr+1)) { + event.trunk_group = atoi(gr+1); + switch(*gr) { case 'g': event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC; break; @@ -241,9 +241,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) event.hunt_group = SIGBOOST_HUNTGRP_RR_DESC; break; default: - zap_log(ZAP_LOG_WARNING, - "Failed to determine huntgroup (%s)\n", - gr); + zap_log(ZAP_LOG_WARNING, "Failed to determine huntgroup (%s)\n", gr); event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC; } } From c8a998d73efd37f633f1036eb67233aff956143a Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Mon, 8 Jun 2009 20:01:29 +0000 Subject: [PATCH 1411/1766] Add Doxygen comments. Thanks Francois. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@741 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_analog/ozmod_analog.c | 61 ++++- .../ozmod/ozmod_analog_em/ozmod_analog_em.c | 50 +++- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 166 +++++++++++- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 239 ++++++++++++++++-- .../openzap/src/ozmod/ozmod_pika/ozmod_pika.c | 113 ++++++++- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 154 ++++++++++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 138 +++++++++- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 126 ++++++++- 8 files changed, 989 insertions(+), 58 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 2677085aa8..9dcd8d64fd 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -40,6 +40,13 @@ struct tm * localtime_r(const time_t *clock, struct tm *result); 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)) { @@ -57,6 +64,13 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) 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) { @@ -70,7 +84,11 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) 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; @@ -78,6 +96,13 @@ static zap_status_t zap_analog_start(zap_span_t *span) 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) { @@ -162,6 +187,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } +/** + * \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; @@ -175,6 +206,10 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map 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; @@ -220,6 +255,11 @@ static void send_caller_id(zap_channel_t *zchan) 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; @@ -729,6 +769,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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; @@ -867,6 +913,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -914,12 +965,18 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) 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 + */ zap_module_t zap_module = { "analog", NULL, 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 index 5e8649bf4c..72da381500 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -45,6 +45,13 @@ struct tm * localtime_r(const time_t *clock, struct tm *result); 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)) { @@ -63,7 +70,11 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call) 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; @@ -71,6 +82,13 @@ static zap_status_t zap_analog_em_start(zap_span_t *span) 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) { @@ -136,6 +154,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) } +/** + * \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; @@ -149,6 +173,11 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map 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; @@ -532,6 +561,12 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) 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; @@ -587,6 +622,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -634,12 +674,18 @@ static void *zap_analog_em_run(zap_thread_t *me, void *obj) 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 + */ zap_module_t zap_module = { "analog_em", NULL, diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index f1b4e93aae..213def357e 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -106,6 +106,10 @@ L3UCHAR sendFrame[SNAPLEN]= { 3,0,0,0 }; +/** + * \brief Opens a pcap file for capture + * \return Success or failure + */ static zap_status_t openPcapFile(void) { if(!pcaphandle) @@ -141,6 +145,10 @@ static zap_status_t openPcapFile(void) return ZAP_SUCCESS; } +/** + * \brief Closes a pcap file + * \return Success + */ static zap_status_t closePcapFile(void) { if (pcapfile) { @@ -162,6 +170,10 @@ static zap_status_t closePcapFile(void) 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; @@ -242,6 +254,11 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L } #endif + +/** + * \brief Unloads pcap IO + * \return Success or failure + */ static ZIO_IO_UNLOAD_FUNCTION(close_pcap) { #ifdef HAVE_LIBPCAP @@ -254,12 +271,20 @@ static ZIO_IO_UNLOAD_FUNCTION(close_pcap) /*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; @@ -268,6 +293,15 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) 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; @@ -489,12 +523,27 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) } +/** + * \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; @@ -973,6 +1022,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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; @@ -1004,6 +1062,13 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg 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; @@ -1022,6 +1087,10 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) 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; @@ -1352,6 +1421,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } +/** + * \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)) { @@ -1369,7 +1442,12 @@ static __inline__ void check_state(zap_span_t *span) } } - +/** + * \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_sigmsg_t sig; @@ -1422,7 +1500,10 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -1453,7 +1534,12 @@ static __inline__ void check_events(zap_span_t *span) } } - +/** + * \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; @@ -1467,6 +1553,11 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map 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; @@ -1658,6 +1749,11 @@ done: 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; @@ -1745,6 +1841,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) return NULL; } +/** + * \brief Openzap ISDN signaling module initialisation + * \return Success + */ static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) { Q931Initialize(); @@ -1755,6 +1855,15 @@ static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) 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; @@ -1786,6 +1895,14 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I 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; @@ -1794,6 +1911,14 @@ static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT s 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; @@ -1801,7 +1926,9 @@ static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT 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 = { { { @@ -1914,6 +2041,13 @@ static zap_state_map_t isdn_state_map = { } }; +/** + * \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; @@ -1936,6 +2070,13 @@ static zap_status_t zap_isdn_stop(zap_span_t *span) } +/** + * \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; @@ -1958,6 +2099,11 @@ static zap_status_t zap_isdn_start(zap_span_t *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; @@ -1981,6 +2127,13 @@ static uint32_t parse_opts(const char *in) 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; @@ -2191,6 +2344,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_SUCCESS; } +/** + * \brief Openzap ISDN signaling module definition + */ zap_module_t zap_module = { "isdn", NULL, diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 013884da81..5b07494ef6 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -34,11 +34,20 @@ #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; @@ -47,15 +56,32 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) 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 { @@ -63,14 +89,28 @@ static void s_pri_error(struct pri *pri, char *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; @@ -94,7 +134,11 @@ static uint32_t parse_opts(const char *in) 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; @@ -154,6 +198,12 @@ 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 }; @@ -218,7 +268,11 @@ static ZIO_API_FUNCTION(zap_libpri_api) 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); @@ -232,6 +286,11 @@ static ZIO_IO_LOAD_FUNCTION(zap_libpri_io_init) 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); @@ -239,7 +298,9 @@ static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) return ZAP_SUCCESS; } - +/** + * \brief libpri state map + */ static zap_state_map_t isdn_state_map = { { { @@ -352,10 +413,10 @@ static zap_state_map_t isdn_state_map = { } }; - - - - +/** + * \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; @@ -531,6 +592,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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)) { @@ -548,8 +613,13 @@ static __inline__ void check_state(zap_span_t *span) } } - - +/** + * \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) { @@ -561,6 +631,13 @@ static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event 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; @@ -583,6 +660,13 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even 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; @@ -601,7 +685,13 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even 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; @@ -620,7 +710,13 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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; @@ -639,7 +735,13 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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; @@ -691,7 +793,12 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event 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_sigmsg_t sig; @@ -744,8 +851,10 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -776,6 +885,11 @@ static __inline__ void check_events(zap_span_t *span) } } +/** + * \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; @@ -791,6 +905,13 @@ static int check_flags(lpwrap_pri_t *spri) 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; @@ -813,6 +934,13 @@ static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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) { @@ -824,6 +952,13 @@ static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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) { @@ -835,6 +970,13 @@ static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ 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) { @@ -842,8 +984,13 @@ static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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) { @@ -851,7 +998,11 @@ static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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; @@ -939,7 +1090,13 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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; @@ -959,6 +1116,13 @@ static zap_status_t zap_libpri_stop(zap_span_t *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; @@ -981,7 +1145,11 @@ static zap_status_t zap_libpri_start(zap_span_t *span) 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")) @@ -991,6 +1159,11 @@ static int str2node(char *node) 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")) @@ -1012,7 +1185,11 @@ static int str2switch(char *swtype) 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")) @@ -1021,6 +1198,11 @@ static int str2l1(char *l1) 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")) @@ -1037,6 +1219,13 @@ static int str2dp(char *dp) 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; @@ -1146,6 +1335,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) return ZAP_SUCCESS; } +/** + * \brief Openzap libpri signaling and IO module definition + */ zap_module_t zap_module = { "libpri", zap_libpri_io_init, @@ -1156,9 +1348,6 @@ zap_module_t zap_module = { }; - - - /* For Emacs: * Local Variables: * mode:c diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c index 5de8ac3974..26f72d7f7c 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c @@ -147,6 +147,14 @@ static const char *pika_board_type_string(PK_UINT type) 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; @@ -255,6 +263,10 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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; @@ -296,7 +308,19 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) } - +/** + * \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) { @@ -562,6 +586,15 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; @@ -645,6 +678,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) 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; @@ -663,11 +701,23 @@ static ZIO_OPEN_FUNCTION(pika_open) 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; @@ -700,6 +750,13 @@ static ZIO_WAIT_FUNCTION(pika_wait) 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; @@ -734,6 +791,13 @@ static ZIO_READ_FUNCTION(pika_read) 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; @@ -753,6 +817,13 @@ static ZIO_WRITE_FUNCTION(pika_write) 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; @@ -882,6 +953,12 @@ static ZIO_COMMAND_FUNCTION(pika_command) 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; @@ -984,6 +1061,12 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) 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; @@ -1122,6 +1205,11 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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; @@ -1134,6 +1222,11 @@ static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) 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; @@ -1178,6 +1271,11 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) 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; @@ -1185,6 +1283,11 @@ static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) 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) { @@ -1319,7 +1422,10 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) return ZAP_SUCCESS; } - +/** + * \brief Unloads Pika IO module + * \return Success + */ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) { uint32_t x; @@ -1346,6 +1452,9 @@ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) return ZAP_SUCCESS; } +/** + * \brief Pika IO module definition + */ EX_DECLARE_DATA zap_module_t zap_module = { "pika", pika_init, diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 22ae8e2cbf..469f5fe237 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -38,6 +38,9 @@ #include #endif +/** + * \brief Strange flag + */ typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), SFLAG_SENT_FINAL_RESPONSE = (1 << 1) @@ -45,6 +48,9 @@ typedef enum { typedef uint16_t ss7_boost_request_id_t; +/** + * \brief SS7 boost request status + */ typedef enum { BST_FREE, BST_WAITING, @@ -52,6 +58,9 @@ typedef enum { BST_FAIL } ss7_boost_request_status_t; +/** + * \brief SS7 boost request structure + */ typedef struct { ss7_boost_request_status_t status; ss7bc_short_event_t event; @@ -73,6 +82,14 @@ static zap_mutex_t *signal_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; @@ -87,6 +104,12 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, } #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(ss7_boost_request_id_t r, const char *func, int line) { assert(r <= MAX_REQ_ID); @@ -98,6 +121,12 @@ static void __release_request_id(ss7_boost_request_id_t r, const char *func, int static ss7_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 ss7_boost_request_id_t __next_request_id(const char *func, int line) { ss7_boost_request_id_t r = 0, i = 0; @@ -136,6 +165,13 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) } #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 SS7 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, ss7bc_short_event_t *event, int force) { int i; @@ -185,6 +221,15 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i return zchan; } +/** + * \brief Requests an ss7 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(ss7_boost_channel_request) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; @@ -305,12 +350,22 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return status; } +/** + * \brief Starts an ss7 boost channel (outgoing call) + * \param zchan Channel to initiate call on + * \return Success + */ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; return status; } +/** + * \brief Handler for call start ack event + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -354,6 +409,12 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t } +/** + * \brief Handler for call done event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -384,6 +445,12 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s 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 ss7 boost connection + * \param event Event to handle + */ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -428,11 +495,14 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); - - - } +/** + * \brief Handler for call stop event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -472,6 +542,12 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s release_request_id_span_chan(event->span, event->chan); } +/** + * \brief Handler for call answer event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -499,6 +575,12 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc } } +/** + * \brief Handler for call start event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { zap_channel_t *zchan; @@ -538,7 +620,11 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } - +/** + * \brief Handler for heartbeat event + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { int err; @@ -554,12 +640,23 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *even return; } +/** + * \brief Handler for restart ack event + * \param mcon ss7 boost connection + * \param span Span where event was fired + * \param event Event to handle + */ static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { zap_log(ZAP_LOG_DEBUG, "RECV RESTART ACK\n"); } - +/** + * \brief Handler for restart event + * \param mcon ss7 boost connection + * \param span Span where event was fired + * \param event Event to handle + */ static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; @@ -572,6 +669,12 @@ static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_sho mcon->hb_elapsed = 0; } +/** + * \brief Handler for incoming digit event + * \param mcon ss7 boost connection + * \param span Span where event was fired + * \param event Event to handle + */ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) { zap_channel_t *zchan = NULL; @@ -601,6 +704,12 @@ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss return; } +/** + * \brief Handler for ss7 boost event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -669,6 +778,10 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho return 0; } +/** + * \brief Handler for channel state change + * \param zchan Channel to handle + */ static __inline__ void state_advance(zap_channel_t *zchan) { @@ -831,11 +944,18 @@ static __inline__ void state_advance(zap_channel_t *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_ss7_boost_data_t *ss7_boost_data = span->signal_data; @@ -877,11 +997,13 @@ static __inline__ void check_state(zap_span_t *span) init_outgoing_array(); } } - - } - +/** + * \brief Main thread function for ss7 boost span (monitor) + * \param me Current thread + * \param obj Span to run in this thread + */ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; @@ -1015,6 +1137,11 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) return NULL; } +/** + * \brief Loads ss7 boost signaling module + * \param zio Openzap IO interface + * \return Success + */ static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) { zap_mutex_create(&request_mutex); @@ -1129,6 +1256,13 @@ static zap_state_map_t boost_state_map = { } }; +/** + * \brief Initialises an ss7 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_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; @@ -1190,7 +1324,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) return ZAP_SUCCESS; } - +/** + * \brief Openzap ss7 boost signaling module definition + */ zap_module_t zap_module = { "ss7_boost", NULL, diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index aa32132aa4..038f1c8b37 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -65,10 +65,16 @@ #define EX_DECLARE_DATA #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; @@ -84,9 +90,17 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); #define WP_INVALID_SOCKET -1 -/* 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 */ +/** + * \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(sng_fd_t fd, int timeout, int *flags) { @@ -125,15 +139,24 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) } +/** + * \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); } - - 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; @@ -152,6 +175,18 @@ static unsigned char wanpipe_swap_bits(unsigned char cas_bits) 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; @@ -237,6 +272,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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; @@ -269,6 +312,15 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) 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; @@ -340,6 +392,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) return configured; } +/** + * \brief Opens Wanpipe channel + * \param zchan Channel to open + * \return Success or failure + */ static ZIO_OPEN_FUNCTION(wanpipe_open) { @@ -362,11 +419,23 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) 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; @@ -461,6 +530,13 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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; @@ -484,6 +560,13 @@ static ZIO_READ_FUNCTION(wanpipe_read) 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; @@ -502,7 +585,13 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) 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; @@ -548,6 +637,12 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) 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 @@ -641,7 +736,11 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) 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; @@ -671,7 +770,12 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) 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; @@ -827,6 +931,11 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } +/** + * \brief Destroys a Wanpipe Channel + * \param zchan Channel to destroy + * \return Success + */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { if (zchan->sockfd > -1) { @@ -837,6 +946,11 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) 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); @@ -867,13 +981,19 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) 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, diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index db20ef95c5..7a4de2ad93 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -35,7 +35,9 @@ #include "openzap.h" #include "ozmod_zt.h" - +/** + * \brief Zaptel globals + */ static struct { uint32_t codec_ms; uint32_t wink_ms; @@ -46,6 +48,9 @@ static struct { float txgain; } zt_globals; +/** + * \brief General IOCTL codes + */ struct ioctl_codes { int GET_BLOCKSIZE; int SET_BLOCKSIZE; @@ -81,6 +86,9 @@ struct ioctl_codes { int GETRXBITS; }; +/** + * \brief Zaptel IOCTL codes + */ static struct ioctl_codes zt_ioctl_codes = { .GET_BLOCKSIZE = ZT_GET_BLOCKSIZE, .SET_BLOCKSIZE = ZT_SET_BLOCKSIZE, @@ -116,6 +124,9 @@ static struct ioctl_codes zt_ioctl_codes = { .GETRXBITS = ZT_GETRXBITS }; +/** + * \brief Dahdi IOCTL codes + */ static struct ioctl_codes dahdi_ioctl_codes = { .GET_BLOCKSIZE = DAHDI_GET_BLOCKSIZE, .SET_BLOCKSIZE = DAHDI_SET_BLOCKSIZE, @@ -167,6 +178,13 @@ 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; @@ -218,6 +236,17 @@ static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int c } } +/** + * \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; @@ -400,6 +429,15 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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) { @@ -461,6 +499,14 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) } +/** + * \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) { @@ -521,6 +567,11 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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); @@ -596,11 +647,23 @@ static ZIO_OPEN_FUNCTION(zt_open) 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; @@ -746,6 +809,11 @@ static ZIO_COMMAND_FUNCTION(zt_command) return ZAP_SUCCESS; } +/** + * \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; @@ -764,7 +832,13 @@ static ZIO_GET_ALARMS_FUNCTION(zt_get_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; @@ -825,6 +899,12 @@ static ZIO_WAIT_FUNCTION(zt_wait) } +/** + * \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]; @@ -862,6 +942,12 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) 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 = 0; @@ -957,7 +1043,13 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) } - +/** + * \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; @@ -983,6 +1075,13 @@ static ZIO_READ_FUNCTION(zt_read) 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; @@ -1003,6 +1102,11 @@ static ZIO_WRITE_FUNCTION(zt_write) 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); @@ -1011,8 +1115,16 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) 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); @@ -1063,6 +1175,10 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) return ZAP_SUCCESS; } +/** + * \brief Unloads zaptel IO module + * \return Success + */ static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) { close(CONTROL_FD); @@ -1070,7 +1186,9 @@ static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) return ZAP_SUCCESS; } - +/** + * \brief Openzap zaptel IO module definition + */ zap_module_t zap_module = { "zt", zt_init, From e4ed6a4fa355d5ba5b0e937908c94c47dfb630f4 Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Mon, 8 Jun 2009 20:01:29 +0000 Subject: [PATCH 1412/1766] Add Doxygen comments. Thanks Francois. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@741 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_analog/ozmod_analog.c | 61 ++++- .../ozmod/ozmod_analog_em/ozmod_analog_em.c | 50 +++- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 166 +++++++++++- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 239 ++++++++++++++++-- .../freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 113 ++++++++- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 154 ++++++++++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 138 +++++++++- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 126 ++++++++- 8 files changed, 989 insertions(+), 58 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 2677085aa8..9dcd8d64fd 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -40,6 +40,13 @@ struct tm * localtime_r(const time_t *clock, struct tm *result); 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)) { @@ -57,6 +64,13 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) 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) { @@ -70,7 +84,11 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) 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; @@ -78,6 +96,13 @@ static zap_status_t zap_analog_start(zap_span_t *span) 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) { @@ -162,6 +187,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) } +/** + * \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; @@ -175,6 +206,10 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map 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; @@ -220,6 +255,11 @@ static void send_caller_id(zap_channel_t *zchan) 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; @@ -729,6 +769,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) 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; @@ -867,6 +913,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -914,12 +965,18 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) 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 + */ zap_module_t zap_module = { "analog", NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index 5e8649bf4c..72da381500 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -45,6 +45,13 @@ struct tm * localtime_r(const time_t *clock, struct tm *result); 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)) { @@ -63,7 +70,11 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call) 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; @@ -71,6 +82,13 @@ static zap_status_t zap_analog_em_start(zap_span_t *span) 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) { @@ -136,6 +154,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) } +/** + * \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; @@ -149,6 +173,11 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map 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; @@ -532,6 +561,12 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) 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; @@ -587,6 +622,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -634,12 +674,18 @@ static void *zap_analog_em_run(zap_thread_t *me, void *obj) 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 + */ zap_module_t zap_module = { "analog_em", NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index f1b4e93aae..213def357e 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -106,6 +106,10 @@ L3UCHAR sendFrame[SNAPLEN]= { 3,0,0,0 }; +/** + * \brief Opens a pcap file for capture + * \return Success or failure + */ static zap_status_t openPcapFile(void) { if(!pcaphandle) @@ -141,6 +145,10 @@ static zap_status_t openPcapFile(void) return ZAP_SUCCESS; } +/** + * \brief Closes a pcap file + * \return Success + */ static zap_status_t closePcapFile(void) { if (pcapfile) { @@ -162,6 +170,10 @@ static zap_status_t closePcapFile(void) 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; @@ -242,6 +254,11 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L } #endif + +/** + * \brief Unloads pcap IO + * \return Success or failure + */ static ZIO_IO_UNLOAD_FUNCTION(close_pcap) { #ifdef HAVE_LIBPCAP @@ -254,12 +271,20 @@ static ZIO_IO_UNLOAD_FUNCTION(close_pcap) /*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; @@ -268,6 +293,15 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) 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; @@ -489,12 +523,27 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) } +/** + * \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; @@ -973,6 +1022,15 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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; @@ -1004,6 +1062,13 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg 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; @@ -1022,6 +1087,10 @@ static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) 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; @@ -1352,6 +1421,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } +/** + * \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)) { @@ -1369,7 +1442,12 @@ static __inline__ void check_state(zap_span_t *span) } } - +/** + * \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_sigmsg_t sig; @@ -1422,7 +1500,10 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -1453,7 +1534,12 @@ static __inline__ void check_events(zap_span_t *span) } } - +/** + * \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; @@ -1467,6 +1553,11 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map 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; @@ -1658,6 +1749,11 @@ done: 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; @@ -1745,6 +1841,10 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) return NULL; } +/** + * \brief Openzap ISDN signaling module initialisation + * \return Success + */ static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) { Q931Initialize(); @@ -1755,6 +1855,15 @@ static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) 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; @@ -1786,6 +1895,14 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I 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; @@ -1794,6 +1911,14 @@ static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT s 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; @@ -1801,7 +1926,9 @@ static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT 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 = { { { @@ -1914,6 +2041,13 @@ static zap_state_map_t isdn_state_map = { } }; +/** + * \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; @@ -1936,6 +2070,13 @@ static zap_status_t zap_isdn_stop(zap_span_t *span) } +/** + * \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; @@ -1958,6 +2099,11 @@ static zap_status_t zap_isdn_start(zap_span_t *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; @@ -1981,6 +2127,13 @@ static uint32_t parse_opts(const char *in) 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; @@ -2191,6 +2344,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_SUCCESS; } +/** + * \brief Openzap ISDN signaling module definition + */ zap_module_t zap_module = { "isdn", NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 013884da81..5b07494ef6 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -34,11 +34,20 @@ #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; @@ -47,15 +56,32 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) 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 { @@ -63,14 +89,28 @@ static void s_pri_error(struct pri *pri, char *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; @@ -94,7 +134,11 @@ static uint32_t parse_opts(const char *in) 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; @@ -154,6 +198,12 @@ 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 }; @@ -218,7 +268,11 @@ static ZIO_API_FUNCTION(zap_libpri_api) 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); @@ -232,6 +286,11 @@ static ZIO_IO_LOAD_FUNCTION(zap_libpri_io_init) 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); @@ -239,7 +298,9 @@ static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) return ZAP_SUCCESS; } - +/** + * \brief libpri state map + */ static zap_state_map_t isdn_state_map = { { { @@ -352,10 +413,10 @@ static zap_state_map_t isdn_state_map = { } }; - - - - +/** + * \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; @@ -531,6 +592,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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)) { @@ -548,8 +613,13 @@ static __inline__ void check_state(zap_span_t *span) } } - - +/** + * \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) { @@ -561,6 +631,13 @@ static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event 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; @@ -583,6 +660,13 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even 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; @@ -601,7 +685,13 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even 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; @@ -620,7 +710,13 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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; @@ -639,7 +735,13 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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; @@ -691,7 +793,12 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event 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_sigmsg_t sig; @@ -744,8 +851,10 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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; @@ -776,6 +885,11 @@ static __inline__ void check_events(zap_span_t *span) } } +/** + * \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; @@ -791,6 +905,13 @@ static int check_flags(lpwrap_pri_t *spri) 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; @@ -813,6 +934,13 @@ static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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) { @@ -824,6 +952,13 @@ static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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) { @@ -835,6 +970,13 @@ static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ 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) { @@ -842,8 +984,13 @@ static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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) { @@ -851,7 +998,11 @@ static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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; @@ -939,7 +1090,13 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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; @@ -959,6 +1116,13 @@ static zap_status_t zap_libpri_stop(zap_span_t *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; @@ -981,7 +1145,11 @@ static zap_status_t zap_libpri_start(zap_span_t *span) 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")) @@ -991,6 +1159,11 @@ static int str2node(char *node) 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")) @@ -1012,7 +1185,11 @@ static int str2switch(char *swtype) 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")) @@ -1021,6 +1198,11 @@ static int str2l1(char *l1) 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")) @@ -1037,6 +1219,13 @@ static int str2dp(char *dp) 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; @@ -1146,6 +1335,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) return ZAP_SUCCESS; } +/** + * \brief Openzap libpri signaling and IO module definition + */ zap_module_t zap_module = { "libpri", zap_libpri_io_init, @@ -1156,9 +1348,6 @@ zap_module_t zap_module = { }; - - - /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index 5de8ac3974..26f72d7f7c 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -147,6 +147,14 @@ static const char *pika_board_type_string(PK_UINT type) 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; @@ -255,6 +263,10 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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; @@ -296,7 +308,19 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) } - +/** + * \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) { @@ -562,6 +586,15 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; @@ -645,6 +678,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) 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; @@ -663,11 +701,23 @@ static ZIO_OPEN_FUNCTION(pika_open) 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; @@ -700,6 +750,13 @@ static ZIO_WAIT_FUNCTION(pika_wait) 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; @@ -734,6 +791,13 @@ static ZIO_READ_FUNCTION(pika_read) 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; @@ -753,6 +817,13 @@ static ZIO_WRITE_FUNCTION(pika_write) 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; @@ -882,6 +953,12 @@ static ZIO_COMMAND_FUNCTION(pika_command) 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; @@ -984,6 +1061,12 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) 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; @@ -1122,6 +1205,11 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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; @@ -1134,6 +1222,11 @@ static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) 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; @@ -1178,6 +1271,11 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) 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; @@ -1185,6 +1283,11 @@ static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) 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) { @@ -1319,7 +1422,10 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) return ZAP_SUCCESS; } - +/** + * \brief Unloads Pika IO module + * \return Success + */ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) { uint32_t x; @@ -1346,6 +1452,9 @@ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) return ZAP_SUCCESS; } +/** + * \brief Pika IO module definition + */ EX_DECLARE_DATA zap_module_t zap_module = { "pika", pika_init, diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 22ae8e2cbf..469f5fe237 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -38,6 +38,9 @@ #include #endif +/** + * \brief Strange flag + */ typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), SFLAG_SENT_FINAL_RESPONSE = (1 << 1) @@ -45,6 +48,9 @@ typedef enum { typedef uint16_t ss7_boost_request_id_t; +/** + * \brief SS7 boost request status + */ typedef enum { BST_FREE, BST_WAITING, @@ -52,6 +58,9 @@ typedef enum { BST_FAIL } ss7_boost_request_status_t; +/** + * \brief SS7 boost request structure + */ typedef struct { ss7_boost_request_status_t status; ss7bc_short_event_t event; @@ -73,6 +82,14 @@ static zap_mutex_t *signal_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; @@ -87,6 +104,12 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, } #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(ss7_boost_request_id_t r, const char *func, int line) { assert(r <= MAX_REQ_ID); @@ -98,6 +121,12 @@ static void __release_request_id(ss7_boost_request_id_t r, const char *func, int static ss7_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 ss7_boost_request_id_t __next_request_id(const char *func, int line) { ss7_boost_request_id_t r = 0, i = 0; @@ -136,6 +165,13 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) } #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 SS7 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, ss7bc_short_event_t *event, int force) { int i; @@ -185,6 +221,15 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i return zchan; } +/** + * \brief Requests an ss7 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(ss7_boost_channel_request) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; @@ -305,12 +350,22 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return status; } +/** + * \brief Starts an ss7 boost channel (outgoing call) + * \param zchan Channel to initiate call on + * \return Success + */ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; return status; } +/** + * \brief Handler for call start ack event + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -354,6 +409,12 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t } +/** + * \brief Handler for call done event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -384,6 +445,12 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s 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 ss7 boost connection + * \param event Event to handle + */ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -428,11 +495,14 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); - - - } +/** + * \brief Handler for call stop event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -472,6 +542,12 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s release_request_id_span_chan(event->span, event->chan); } +/** + * \brief Handler for call answer event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_channel_t *zchan; @@ -499,6 +575,12 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc } } +/** + * \brief Handler for call start event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) { zap_channel_t *zchan; @@ -538,7 +620,11 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } - +/** + * \brief Handler for heartbeat event + * \param mcon ss7 boost connection + * \param event Event to handle + */ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { int err; @@ -554,12 +640,23 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *even return; } +/** + * \brief Handler for restart ack event + * \param mcon ss7 boost connection + * \param span Span where event was fired + * \param event Event to handle + */ static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { zap_log(ZAP_LOG_DEBUG, "RECV RESTART ACK\n"); } - +/** + * \brief Handler for restart event + * \param mcon ss7 boost connection + * \param span Span where event was fired + * \param event Event to handle + */ static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) { zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; @@ -572,6 +669,12 @@ static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_sho mcon->hb_elapsed = 0; } +/** + * \brief Handler for incoming digit event + * \param mcon ss7 boost connection + * \param span Span where event was fired + * \param event Event to handle + */ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) { zap_channel_t *zchan = NULL; @@ -601,6 +704,12 @@ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss return; } +/** + * \brief Handler for ss7 boost event + * \param span Span where event was fired + * \param mcon ss7 boost connection + * \param event Event to handle + */ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -669,6 +778,10 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho return 0; } +/** + * \brief Handler for channel state change + * \param zchan Channel to handle + */ static __inline__ void state_advance(zap_channel_t *zchan) { @@ -831,11 +944,18 @@ static __inline__ void state_advance(zap_channel_t *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_ss7_boost_data_t *ss7_boost_data = span->signal_data; @@ -877,11 +997,13 @@ static __inline__ void check_state(zap_span_t *span) init_outgoing_array(); } } - - } - +/** + * \brief Main thread function for ss7 boost span (monitor) + * \param me Current thread + * \param obj Span to run in this thread + */ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; @@ -1015,6 +1137,11 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) return NULL; } +/** + * \brief Loads ss7 boost signaling module + * \param zio Openzap IO interface + * \return Success + */ static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) { zap_mutex_create(&request_mutex); @@ -1129,6 +1256,13 @@ static zap_state_map_t boost_state_map = { } }; +/** + * \brief Initialises an ss7 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_ss7_boost_configure_span) { zap_ss7_boost_data_t *ss7_boost_data = NULL; @@ -1190,7 +1324,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) return ZAP_SUCCESS; } - +/** + * \brief Openzap ss7 boost signaling module definition + */ zap_module_t zap_module = { "ss7_boost", NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index aa32132aa4..038f1c8b37 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -65,10 +65,16 @@ #define EX_DECLARE_DATA #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; @@ -84,9 +90,17 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); #define WP_INVALID_SOCKET -1 -/* 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 */ +/** + * \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(sng_fd_t fd, int timeout, int *flags) { @@ -125,15 +139,24 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int *flags) } +/** + * \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); } - - 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; @@ -152,6 +175,18 @@ static unsigned char wanpipe_swap_bits(unsigned char cas_bits) 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; @@ -237,6 +272,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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; @@ -269,6 +312,15 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) 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; @@ -340,6 +392,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) return configured; } +/** + * \brief Opens Wanpipe channel + * \param zchan Channel to open + * \return Success or failure + */ static ZIO_OPEN_FUNCTION(wanpipe_open) { @@ -362,11 +419,23 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) 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; @@ -461,6 +530,13 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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; @@ -484,6 +560,13 @@ static ZIO_READ_FUNCTION(wanpipe_read) 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; @@ -502,7 +585,13 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) 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; @@ -548,6 +637,12 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) 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 @@ -641,7 +736,11 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) 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; @@ -671,7 +770,12 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) 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; @@ -827,6 +931,11 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } +/** + * \brief Destroys a Wanpipe Channel + * \param zchan Channel to destroy + * \return Success + */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { if (zchan->sockfd > -1) { @@ -837,6 +946,11 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) 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); @@ -867,13 +981,19 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) 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, diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index db20ef95c5..7a4de2ad93 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -35,7 +35,9 @@ #include "openzap.h" #include "ozmod_zt.h" - +/** + * \brief Zaptel globals + */ static struct { uint32_t codec_ms; uint32_t wink_ms; @@ -46,6 +48,9 @@ static struct { float txgain; } zt_globals; +/** + * \brief General IOCTL codes + */ struct ioctl_codes { int GET_BLOCKSIZE; int SET_BLOCKSIZE; @@ -81,6 +86,9 @@ struct ioctl_codes { int GETRXBITS; }; +/** + * \brief Zaptel IOCTL codes + */ static struct ioctl_codes zt_ioctl_codes = { .GET_BLOCKSIZE = ZT_GET_BLOCKSIZE, .SET_BLOCKSIZE = ZT_SET_BLOCKSIZE, @@ -116,6 +124,9 @@ static struct ioctl_codes zt_ioctl_codes = { .GETRXBITS = ZT_GETRXBITS }; +/** + * \brief Dahdi IOCTL codes + */ static struct ioctl_codes dahdi_ioctl_codes = { .GET_BLOCKSIZE = DAHDI_GET_BLOCKSIZE, .SET_BLOCKSIZE = DAHDI_SET_BLOCKSIZE, @@ -167,6 +178,13 @@ 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; @@ -218,6 +236,17 @@ static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int c } } +/** + * \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; @@ -400,6 +429,15 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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) { @@ -461,6 +499,14 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) } +/** + * \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) { @@ -521,6 +567,11 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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); @@ -596,11 +647,23 @@ static ZIO_OPEN_FUNCTION(zt_open) 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; @@ -746,6 +809,11 @@ static ZIO_COMMAND_FUNCTION(zt_command) return ZAP_SUCCESS; } +/** + * \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; @@ -764,7 +832,13 @@ static ZIO_GET_ALARMS_FUNCTION(zt_get_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; @@ -825,6 +899,12 @@ static ZIO_WAIT_FUNCTION(zt_wait) } +/** + * \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]; @@ -862,6 +942,12 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) 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 = 0; @@ -957,7 +1043,13 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) } - +/** + * \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; @@ -983,6 +1075,13 @@ static ZIO_READ_FUNCTION(zt_read) 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; @@ -1003,6 +1102,11 @@ static ZIO_WRITE_FUNCTION(zt_write) 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); @@ -1011,8 +1115,16 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) 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); @@ -1063,6 +1175,10 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) return ZAP_SUCCESS; } +/** + * \brief Unloads zaptel IO module + * \return Success + */ static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) { close(CONTROL_FD); @@ -1070,7 +1186,9 @@ static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) return ZAP_SUCCESS; } - +/** + * \brief Openzap zaptel IO module definition + */ zap_module_t zap_module = { "zt", zt_init, From 3288f821e1cf7f5bea89a08ea5f58d27a8081565 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 8 Jun 2009 21:26:30 +0000 Subject: [PATCH 1413/1766] of corse its zero based that makes a ton of sense git-svn-id: http://svn.openzap.org/svn/openzap/trunk@742 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 469f5fe237..7d141804bc 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -271,6 +271,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) if (gr && *(gr+1)) { event.trunk_group = atoi(gr+1); + if (event.trunk_group > 0) { + event.trunk_group--; + } switch(*gr) { case 'g': From 1b622b585a5dca56cc264d7d6493548d358d3867 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 8 Jun 2009 21:26:30 +0000 Subject: [PATCH 1414/1766] of corse its zero based that makes a ton of sense git-svn-id: http://svn.openzap.org/svn/openzap/trunk@742 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 469f5fe237..7d141804bc 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -271,6 +271,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) if (gr && *(gr+1)) { event.trunk_group = atoi(gr+1); + if (event.trunk_group > 0) { + event.trunk_group--; + } switch(*gr) { case 'g': From 112fd16be987db555710a0487d891d409be945bc Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 9 Jun 2009 15:23:51 +0000 Subject: [PATCH 1415/1766] build: follow --sysconfdir configure arg (OPENZAP-58) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@744 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 6 +++--- libs/openzap/configure.ac | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 964ae5c96e..a7d8f4a9ce 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -37,7 +37,7 @@ libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ @@ -231,6 +231,6 @@ mod_openzap-clean: install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX) - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf - @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) + $(mkinstalldirs) $(DESTDIR)@confdir@ + @[ -f "$(DESTDIR)@confdir@/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@) @echo OpenZAP Installed diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index f7a0576809..e89564af7a 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -25,6 +25,14 @@ oz_builddir=`pwd` AC_SUBST(OZ_SRCDIR) AC_SUBST(oz_builddir) +if test "$sysconfdir" = "\${prefix}/etc" ; then + confdir="$prefix/conf" +else + confdir="$sysconfdir" +fi + +AC_SUBST(confdir) + #override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) From 97f0558886d7f2988ee6440a70883c33acae4c23 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 9 Jun 2009 15:23:51 +0000 Subject: [PATCH 1416/1766] build: follow --sysconfdir configure arg (OPENZAP-58) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@744 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 6 +++--- libs/freetdm/configure.ac | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 964ae5c96e..a7d8f4a9ce 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -37,7 +37,7 @@ libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@prefix@/conf\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ +MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ @@ -231,6 +231,6 @@ mod_openzap-clean: install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX) - $(mkinstalldirs) $(DESTDIR)$(PREFIX)/conf - @[ -f "$(DESTDIR)$(PREFIX)/conf/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)$(PREFIX)/conf) + $(mkinstalldirs) $(DESTDIR)@confdir@ + @[ -f "$(DESTDIR)@confdir@/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@) @echo OpenZAP Installed diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index f7a0576809..e89564af7a 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -25,6 +25,14 @@ oz_builddir=`pwd` AC_SUBST(OZ_SRCDIR) AC_SUBST(oz_builddir) +if test "$sysconfdir" = "\${prefix}/etc" ; then + confdir="$prefix/conf" +else + confdir="$sysconfdir" +fi + +AC_SUBST(confdir) + #override some default libtool behavior and invoke AC_PROG_LIBTOOL (see http://lists.gnu.org/archive/html/libtool/2007-03/msg00000.html) m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) From a9a154dc8bd631eb732dc36999d69cb0998c46be Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 9 Jun 2009 21:17:30 +0000 Subject: [PATCH 1417/1766] fix windows export for data objects git-svn-id: http://svn.openzap.org/svn/openzap/trunk@745 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 ++ libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 2 +- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c | 5 ----- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 --- 6 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 937a69f502..4c14ef845d 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -66,6 +66,7 @@ #define OZ_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl #define OZ_DECLARE_DATA __declspec(dllimport) #endif +#define EX_DECLARE_DATA __declspec(dllexport) #else #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) #define OZ_DECLARE(type) __attribute__((visibility("default"))) type @@ -76,6 +77,7 @@ #define OZ_DECLARE_NONSTD(type) type #define OZ_DECLARE_DATA #endif +#define EX_DECLARE_DATA #endif #ifdef _MSC_VER diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 9dcd8d64fd..20de17dbd1 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -977,7 +977,7 @@ static ZIO_SIG_LOAD_FUNCTION(zap_analog_init) /** * \brief Openzap analog signaling module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "analog", NULL, NULL, 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 index 72da381500..3a8e9a2156 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -686,7 +686,7 @@ static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init) /** * \brief Openzap analog EM module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "analog_em", NULL, NULL, diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 213def357e..192a4446a2 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -2347,7 +2347,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) /** * \brief Openzap ISDN signaling module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "isdn", NULL, close_pcap, diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c index 26f72d7f7c..995c6df554 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c @@ -35,11 +35,6 @@ #include "openzap.h" #include "zap_pika.h" -#if defined(__WINDOWS__) -#define EX_DECLARE_DATA __declspec(dllexport) -#else -EX_DECLARE_DATA -#endif #define MAX_NUMBER_OF_TRUNKS 64 #define PIKA_BLOCK_SIZE 160 diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 038f1c8b37..9dcd6e5ae2 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -60,9 +60,6 @@ #define sangoma_sendmsg_socket sangoma_writemsg #define sangoma_writemsg_tdm sangoma_writemsg #define sangoma_create_socket_intr sangoma_open_api_span_chan -#define EX_DECLARE_DATA __declspec(dllexport) -#else -#define EX_DECLARE_DATA #endif /** From b9856d40dcf52e2658a7332a1f25885dfa160853 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 9 Jun 2009 21:17:30 +0000 Subject: [PATCH 1418/1766] fix windows export for data objects git-svn-id: http://svn.openzap.org/svn/openzap/trunk@745 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 ++ libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 2 +- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 5 ----- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 --- 6 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 937a69f502..4c14ef845d 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -66,6 +66,7 @@ #define OZ_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl #define OZ_DECLARE_DATA __declspec(dllimport) #endif +#define EX_DECLARE_DATA __declspec(dllexport) #else #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) #define OZ_DECLARE(type) __attribute__((visibility("default"))) type @@ -76,6 +77,7 @@ #define OZ_DECLARE_NONSTD(type) type #define OZ_DECLARE_DATA #endif +#define EX_DECLARE_DATA #endif #ifdef _MSC_VER diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 9dcd8d64fd..20de17dbd1 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -977,7 +977,7 @@ static ZIO_SIG_LOAD_FUNCTION(zap_analog_init) /** * \brief Openzap analog signaling module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "analog", NULL, NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index 72da381500..3a8e9a2156 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -686,7 +686,7 @@ static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init) /** * \brief Openzap analog EM module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "analog_em", NULL, NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 213def357e..192a4446a2 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -2347,7 +2347,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) /** * \brief Openzap ISDN signaling module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { "isdn", NULL, close_pcap, diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index 26f72d7f7c..995c6df554 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -35,11 +35,6 @@ #include "openzap.h" #include "zap_pika.h" -#if defined(__WINDOWS__) -#define EX_DECLARE_DATA __declspec(dllexport) -#else -EX_DECLARE_DATA -#endif #define MAX_NUMBER_OF_TRUNKS 64 #define PIKA_BLOCK_SIZE 160 diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 038f1c8b37..9dcd6e5ae2 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -60,9 +60,6 @@ #define sangoma_sendmsg_socket sangoma_writemsg #define sangoma_writemsg_tdm sangoma_writemsg #define sangoma_create_socket_intr sangoma_open_api_span_chan -#define EX_DECLARE_DATA __declspec(dllexport) -#else -#define EX_DECLARE_DATA #endif /** From 2e8e526937155a9b25c8e07a3978273c0ea16ed4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 16 Jun 2009 17:50:24 +0000 Subject: [PATCH 1419/1766] patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@746 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/patches/oz.diff | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 libs/openzap/patches/oz.diff diff --git a/libs/openzap/patches/oz.diff b/libs/openzap/patches/oz.diff new file mode 100644 index 0000000000..2e9c558b7c --- /dev/null +++ b/libs/openzap/patches/oz.diff @@ -0,0 +1,134 @@ +Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +=================================================================== +--- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 745) ++++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) +@@ -98,19 +98,21 @@ + * 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) ++static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, int *flags) + { + + #ifdef LIBSANGOMA_VERSION + int err; +- sangoma_wait_obj_t sangoma_wait_obj; ++ sangoma_wait_obj_t *sangoma_wait_obj = zchan->mod_data; + +- sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); ++ sangoma_init_wait_obj(sangoma_wait_obj, zchan->sockfd, 1, 1, 0, SANGOMA_WAIT_OBJ); + +- err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); ++ err = sangoma_socket_waitfor_many(&sangoma_wait_obj, 1, timeout); ++ + if (err > 0) { +- *flags=sangoma_wait_obj.flags_out; ++ *flags = sangoma_wait_obj.flags_out; + } ++ + return err; + + #else +@@ -118,7 +120,7 @@ + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); +- pfds[0].fd = fd; ++ pfds[0].fd = zchan->sockfd; + pfds[0].events = *flags; + res = poll(pfds, 1, timeout); + *flags = 0; +@@ -200,6 +202,15 @@ + + if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + wanpipe_tdm_api_t tdm_api; ++#ifdef LIBSANGOMA_VERSION ++ sangoma_wait_obj_t *sangoma_wait_obj; ++ ++ sangoma_wait_obj = malloc(sizeof(*sangoma_wait_obj)); ++ memset(sangoma_wait_obj, 0, sizeof(*sangoma_wait_obj)); ++ sangoma_init_wait_obj(sangoma_wait_obj, sockfd, 1, 1, 0, SANGOMA_WAIT_OBJ); ++ chan->mod_data = sangoma_wait_obj; ++#endif ++ + memset(&tdm_api,0,sizeof(tdm_api)); + + chan->physical_span_id = spanno; +@@ -211,7 +222,7 @@ + + dtmf = "software"; + +- /* FIXME: Handle Error Conditino Check for return code */ ++ /* 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) { +@@ -606,7 +617,7 @@ + inflags |= POLLPRI; + } + +- result = tdmv_api_wait_socket(zchan->sockfd, to, &inflags); ++ result = tdmv_api_wait_socket(zchan, to, &inflags); + + *flags = ZAP_NO_FLAGS; + +@@ -643,26 +654,30 @@ + ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) + { + #ifdef LIBSANGOMA_VERSION +- sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; ++ sangoma_wait_obj_t *pfds[ZAP_MAX_CHANNELS_SPAN] = { 0 }; + #else + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + #endif + + uint32_t i, j = 0, k = 0, l = 0; +- int objects=0; + int r; + + for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = span->channels[i]; + ++ + #ifdef LIBSANGOMA_VERSION +- sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); ++ if (!zchan->mod_data) { ++ continue; ++ } ++ pfds[j] = zchan->mod_data; ++ + #else + memset(&pfds[j], 0, sizeof(pfds[j])); + pfds[j].fd = span->channels[i]->sockfd; + pfds[j].events = POLLPRI; + #endif +- objects++; ++ + /* 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)) { +@@ -703,7 +718,7 @@ + ms = l; + } + #ifdef LIBSANGOMA_VERSION +- r = sangoma_socket_waitfor_many(pfds,objects,ms); ++ r = sangoma_socket_waitfor_many(pfds, j, ms); + #else + r = poll(pfds, j, ms); + #endif +@@ -935,6 +950,15 @@ + */ + static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) + { ++ sangoma_wait_obj_t *sangoma_wait_obj; ++ ++ if (zchan->mod_data) { ++ sangoma_wait_obj = zchan->mod_data; ++ zchan->mod_data = NULL; ++ sangoma_release_wait_obj(sangoma_wait_obj); ++ free(sangoma_wait_obj); ++ } ++ + if (zchan->sockfd > -1) { + close(zchan->sockfd); + zchan->sockfd = WP_INVALID_SOCKET; From 215864ca9bc1fd48361c631586ce2dbaeb9aa9da Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 16 Jun 2009 17:50:24 +0000 Subject: [PATCH 1420/1766] patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@746 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/patches/oz.diff | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 libs/freetdm/patches/oz.diff diff --git a/libs/freetdm/patches/oz.diff b/libs/freetdm/patches/oz.diff new file mode 100644 index 0000000000..2e9c558b7c --- /dev/null +++ b/libs/freetdm/patches/oz.diff @@ -0,0 +1,134 @@ +Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +=================================================================== +--- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 745) ++++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) +@@ -98,19 +98,21 @@ + * 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) ++static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, int *flags) + { + + #ifdef LIBSANGOMA_VERSION + int err; +- sangoma_wait_obj_t sangoma_wait_obj; ++ sangoma_wait_obj_t *sangoma_wait_obj = zchan->mod_data; + +- sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); ++ sangoma_init_wait_obj(sangoma_wait_obj, zchan->sockfd, 1, 1, 0, SANGOMA_WAIT_OBJ); + +- err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); ++ err = sangoma_socket_waitfor_many(&sangoma_wait_obj, 1, timeout); ++ + if (err > 0) { +- *flags=sangoma_wait_obj.flags_out; ++ *flags = sangoma_wait_obj.flags_out; + } ++ + return err; + + #else +@@ -118,7 +120,7 @@ + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); +- pfds[0].fd = fd; ++ pfds[0].fd = zchan->sockfd; + pfds[0].events = *flags; + res = poll(pfds, 1, timeout); + *flags = 0; +@@ -200,6 +202,15 @@ + + if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + wanpipe_tdm_api_t tdm_api; ++#ifdef LIBSANGOMA_VERSION ++ sangoma_wait_obj_t *sangoma_wait_obj; ++ ++ sangoma_wait_obj = malloc(sizeof(*sangoma_wait_obj)); ++ memset(sangoma_wait_obj, 0, sizeof(*sangoma_wait_obj)); ++ sangoma_init_wait_obj(sangoma_wait_obj, sockfd, 1, 1, 0, SANGOMA_WAIT_OBJ); ++ chan->mod_data = sangoma_wait_obj; ++#endif ++ + memset(&tdm_api,0,sizeof(tdm_api)); + + chan->physical_span_id = spanno; +@@ -211,7 +222,7 @@ + + dtmf = "software"; + +- /* FIXME: Handle Error Conditino Check for return code */ ++ /* 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) { +@@ -606,7 +617,7 @@ + inflags |= POLLPRI; + } + +- result = tdmv_api_wait_socket(zchan->sockfd, to, &inflags); ++ result = tdmv_api_wait_socket(zchan, to, &inflags); + + *flags = ZAP_NO_FLAGS; + +@@ -643,26 +654,30 @@ + ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) + { + #ifdef LIBSANGOMA_VERSION +- sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; ++ sangoma_wait_obj_t *pfds[ZAP_MAX_CHANNELS_SPAN] = { 0 }; + #else + struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + #endif + + uint32_t i, j = 0, k = 0, l = 0; +- int objects=0; + int r; + + for(i = 1; i <= span->chan_count; i++) { + zap_channel_t *zchan = span->channels[i]; + ++ + #ifdef LIBSANGOMA_VERSION +- sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); ++ if (!zchan->mod_data) { ++ continue; ++ } ++ pfds[j] = zchan->mod_data; ++ + #else + memset(&pfds[j], 0, sizeof(pfds[j])); + pfds[j].fd = span->channels[i]->sockfd; + pfds[j].events = POLLPRI; + #endif +- objects++; ++ + /* 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)) { +@@ -703,7 +718,7 @@ + ms = l; + } + #ifdef LIBSANGOMA_VERSION +- r = sangoma_socket_waitfor_many(pfds,objects,ms); ++ r = sangoma_socket_waitfor_many(pfds, j, ms); + #else + r = poll(pfds, j, ms); + #endif +@@ -935,6 +950,15 @@ + */ + static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) + { ++ sangoma_wait_obj_t *sangoma_wait_obj; ++ ++ if (zchan->mod_data) { ++ sangoma_wait_obj = zchan->mod_data; ++ zchan->mod_data = NULL; ++ sangoma_release_wait_obj(sangoma_wait_obj); ++ free(sangoma_wait_obj); ++ } ++ + if (zchan->sockfd > -1) { + close(zchan->sockfd); + zchan->sockfd = WP_INVALID_SOCKET; From f5c58f696859d7ecc3365e5ada3cd7221b1f2b06 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 17 Jun 2009 18:41:30 +0000 Subject: [PATCH 1421/1766] updated ozmod_wanpipe to use new libsangoma API git-svn-id: http://svn.openzap.org/svn/openzap/trunk@747 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 81 ++++++++++++++----- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 9dcd6e5ae2..e806a2f679 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -62,6 +62,11 @@ #define sangoma_create_socket_intr sangoma_open_api_span_chan #endif +/*! Starting with lbisangoma 3 we can use it, previous versions dont really work so we default to using the old stuff */ +#if defined(LIBSANGOMA_VERSION) && LIBSANGOMA_VERSION_CODE < LIBSANGOMA_VERSION(3,0,0) +#undef LIBSANGOMA_VERSION +#endif + /** * \brief Wanpipe flags */ @@ -98,27 +103,31 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); * 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) +static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, int *flags) { #ifdef LIBSANGOMA_VERSION int err; - sangoma_wait_obj_t sangoma_wait_obj; - - sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); - - err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); - if (err > 0) { - *flags=sangoma_wait_obj.flags_out; - } - return 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 = fd; + pfds[0].fd = zchan->sockfd; pfds[0].events = *flags; res = poll(pfds, 1, timeout); *flags = 0; @@ -200,6 +209,18 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { wanpipe_tdm_api_t tdm_api; +#ifdef LIBSANGOMA_VERSION + sangoma_status_t sangstatus; + sangoma_wait_obj_t *sangoma_wait_obj; + + 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 + memset(&tdm_api,0,sizeof(tdm_api)); chan->physical_span_id = spanno; @@ -211,7 +232,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, dtmf = "software"; - /* FIXME: Handle Error Conditino Check for return code */ + /* 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) { @@ -606,7 +627,7 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) inflags |= POLLPRI; } - result = tdmv_api_wait_socket(zchan->sockfd, to, &inflags); + result = tdmv_api_wait_socket(zchan, to, &inflags); *flags = ZAP_NO_FLAGS; @@ -643,26 +664,33 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { #ifdef LIBSANGOMA_VERSION - sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; + 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 objects=0; int r; for(i = 1; i <= span->chan_count; i++) { zap_channel_t *zchan = span->channels[i]; + #ifdef LIBSANGOMA_VERSION - sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); + 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 - objects++; + /* 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)) { @@ -703,7 +731,14 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) ms = l; } #ifdef LIBSANGOMA_VERSION - r = sangoma_socket_waitfor_many(pfds,objects,ms); + 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 @@ -719,7 +754,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) zap_channel_t *zchan = span->channels[i]; #ifdef LIBSANGOMA_VERSION - if (pfds[i-1].flags_out & POLLPRI) { + if (outflags[i-1] & POLLPRI) { #else if (pfds[i-1].revents & POLLPRI) { #endif @@ -935,6 +970,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { + sangoma_wait_obj_t *sangoma_wait_obj; + + if (zchan->mod_data) { + sangoma_wait_obj = zchan->mod_data; + zchan->mod_data = NULL; + sangoma_wait_obj_delete(&sangoma_wait_obj); + } + if (zchan->sockfd > -1) { close(zchan->sockfd); zchan->sockfd = WP_INVALID_SOCKET; From 3a238fcfdef9df0aa2b22d605b1a90fa1600ec75 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 17 Jun 2009 18:41:30 +0000 Subject: [PATCH 1422/1766] updated ozmod_wanpipe to use new libsangoma API git-svn-id: http://svn.openzap.org/svn/openzap/trunk@747 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 81 ++++++++++++++----- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 9dcd6e5ae2..e806a2f679 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -62,6 +62,11 @@ #define sangoma_create_socket_intr sangoma_open_api_span_chan #endif +/*! Starting with lbisangoma 3 we can use it, previous versions dont really work so we default to using the old stuff */ +#if defined(LIBSANGOMA_VERSION) && LIBSANGOMA_VERSION_CODE < LIBSANGOMA_VERSION(3,0,0) +#undef LIBSANGOMA_VERSION +#endif + /** * \brief Wanpipe flags */ @@ -98,27 +103,31 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); * 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) +static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, int *flags) { #ifdef LIBSANGOMA_VERSION int err; - sangoma_wait_obj_t sangoma_wait_obj; - - sangoma_init_wait_obj(&sangoma_wait_obj, fd, 1, 1, *flags, SANGOMA_WAIT_OBJ); - - err=sangoma_socket_waitfor_many(&sangoma_wait_obj,1 , timeout); - if (err > 0) { - *flags=sangoma_wait_obj.flags_out; - } - return 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 = fd; + pfds[0].fd = zchan->sockfd; pfds[0].events = *flags; res = poll(pfds, 1, timeout); *flags = 0; @@ -200,6 +209,18 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { wanpipe_tdm_api_t tdm_api; +#ifdef LIBSANGOMA_VERSION + sangoma_status_t sangstatus; + sangoma_wait_obj_t *sangoma_wait_obj; + + 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 + memset(&tdm_api,0,sizeof(tdm_api)); chan->physical_span_id = spanno; @@ -211,7 +232,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, dtmf = "software"; - /* FIXME: Handle Error Conditino Check for return code */ + /* 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) { @@ -606,7 +627,7 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) inflags |= POLLPRI; } - result = tdmv_api_wait_socket(zchan->sockfd, to, &inflags); + result = tdmv_api_wait_socket(zchan, to, &inflags); *flags = ZAP_NO_FLAGS; @@ -643,26 +664,33 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { #ifdef LIBSANGOMA_VERSION - sangoma_wait_obj_t pfds[ZAP_MAX_CHANNELS_SPAN]; + 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 objects=0; int r; for(i = 1; i <= span->chan_count; i++) { zap_channel_t *zchan = span->channels[i]; + #ifdef LIBSANGOMA_VERSION - sangoma_init_wait_obj(&pfds[j], zchan->sockfd , 1, 1, POLLPRI, SANGOMA_WAIT_OBJ); + 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 - objects++; + /* 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)) { @@ -703,7 +731,14 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) ms = l; } #ifdef LIBSANGOMA_VERSION - r = sangoma_socket_waitfor_many(pfds,objects,ms); + 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 @@ -719,7 +754,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) zap_channel_t *zchan = span->channels[i]; #ifdef LIBSANGOMA_VERSION - if (pfds[i-1].flags_out & POLLPRI) { + if (outflags[i-1] & POLLPRI) { #else if (pfds[i-1].revents & POLLPRI) { #endif @@ -935,6 +970,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { + sangoma_wait_obj_t *sangoma_wait_obj; + + if (zchan->mod_data) { + sangoma_wait_obj = zchan->mod_data; + zchan->mod_data = NULL; + sangoma_wait_obj_delete(&sangoma_wait_obj); + } + if (zchan->sockfd > -1) { close(zchan->sockfd); zchan->sockfd = WP_INVALID_SOCKET; From 12b62015e05fc649b31e2656f82a0a57872d0af0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 22 Jun 2009 17:30:57 +0000 Subject: [PATCH 1423/1766] fixed small compilation issue when using the libsangoma included in the feature frozen wanpipe driver git-svn-id: http://svn.openzap.org/svn/openzap/trunk@748 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e806a2f679..59386f4712 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -62,10 +62,14 @@ #define sangoma_create_socket_intr sangoma_open_api_span_chan #endif -/*! Starting with lbisangoma 3 we can use it, previous versions dont really work so we default to using the old stuff */ -#if defined(LIBSANGOMA_VERSION) && LIBSANGOMA_VERSION_CODE < LIBSANGOMA_VERSION(3,0,0) +/*! 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 @@ -970,13 +974,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { - sangoma_wait_obj_t *sangoma_wait_obj; - +#ifdef LIBSANGOMA_VERSION if (zchan->mod_data) { sangoma_wait_obj = zchan->mod_data; + sangoma_wait_obj_t *sangoma_wait_obj; zchan->mod_data = NULL; sangoma_wait_obj_delete(&sangoma_wait_obj); } +#endif if (zchan->sockfd > -1) { close(zchan->sockfd); From dbc799696964e8af2781f8c4ceab8e7ccca6edf4 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 22 Jun 2009 17:30:57 +0000 Subject: [PATCH 1424/1766] fixed small compilation issue when using the libsangoma included in the feature frozen wanpipe driver git-svn-id: http://svn.openzap.org/svn/openzap/trunk@748 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e806a2f679..59386f4712 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -62,10 +62,14 @@ #define sangoma_create_socket_intr sangoma_open_api_span_chan #endif -/*! Starting with lbisangoma 3 we can use it, previous versions dont really work so we default to using the old stuff */ -#if defined(LIBSANGOMA_VERSION) && LIBSANGOMA_VERSION_CODE < LIBSANGOMA_VERSION(3,0,0) +/*! 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 @@ -970,13 +974,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { - sangoma_wait_obj_t *sangoma_wait_obj; - +#ifdef LIBSANGOMA_VERSION if (zchan->mod_data) { sangoma_wait_obj = zchan->mod_data; + sangoma_wait_obj_t *sangoma_wait_obj; zchan->mod_data = NULL; sangoma_wait_obj_delete(&sangoma_wait_obj); } +#endif if (zchan->sockfd > -1) { close(zchan->sockfd); From d6d3b67ef4561bff414532057b57d83634755280 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 23 Jun 2009 14:46:11 +0000 Subject: [PATCH 1425/1766] fixed copy-paste error in ozmod_wanpipe git-svn-id: http://svn.openzap.org/svn/openzap/trunk@749 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 59386f4712..7b359ff804 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -976,8 +976,8 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { #ifdef LIBSANGOMA_VERSION if (zchan->mod_data) { - sangoma_wait_obj = 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); } From 7841b7635b739402e45957c15b03fb9a7ad93014 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 23 Jun 2009 14:46:11 +0000 Subject: [PATCH 1426/1766] fixed copy-paste error in ozmod_wanpipe git-svn-id: http://svn.openzap.org/svn/openzap/trunk@749 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 59386f4712..7b359ff804 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -976,8 +976,8 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { #ifdef LIBSANGOMA_VERSION if (zchan->mod_data) { - sangoma_wait_obj = 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); } From d1bdfae6fb5a2c9db99a1b8af25f51ad2b9bca5e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 24 Jun 2009 16:18:41 +0000 Subject: [PATCH 1427/1766] make the in_use count be a function instead of a constant to fix race git-svn-id: http://svn.openzap.org/svn/openzap/trunk@750 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 +- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 5 ++- libs/openzap/src/zap_io.c | 33 ++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 4c14ef845d..fd71e876e1 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -536,7 +536,6 @@ struct zap_span { char *name; uint32_t span_id; uint32_t chan_count; - uint32_t active_count; zap_span_flag_t flags; struct zap_io_interface *zio; zio_event_cb_t event_callback; @@ -639,6 +638,7 @@ OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count); OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan); diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 7d141804bc..462615f74c 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -240,6 +240,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7_boost_request_status_t st; char ani[128] = ""; char *gr = NULL; + uint32_t count = 0; if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); @@ -247,7 +248,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - if (span->active_count >= span->chan_count) { + 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; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index aea2ae3e42..8e5b9381c6 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -887,12 +887,6 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel if (ok) { - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - zchan->span->active_count++; - } else if (state == ZAP_CHANNEL_STATE_DOWN) { - zchan->span->active_count--; - } - zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; @@ -906,11 +900,32 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel return ok ? ZAP_SUCCESS : ZAP_FAIL; } +OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count) +{ + uint32_t j; + + *count = 0; + + if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + return ZAP_FAIL; + } + + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { + if (span->channels[j]) { + if (zap_test_flag(span->channels[j], ZAP_CHANNEL_INUSE)) { + (*count)++; + } + } + } + + return ZAP_SUCCESS; +} + OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; - uint32_t i,j; + uint32_t i, j, count; zap_span_t *span = NULL; uint32_t span_max; @@ -923,7 +938,9 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t return ZAP_FAIL; } - if (span->active_count >= span->chan_count) { + 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; From a6f5392dd658c5c6f6c6e6d2d3d020bb5f53ede6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 24 Jun 2009 16:18:41 +0000 Subject: [PATCH 1428/1766] make the in_use count be a function instead of a constant to fix race git-svn-id: http://svn.openzap.org/svn/openzap/trunk@750 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 +- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 5 ++- libs/freetdm/src/zap_io.c | 33 ++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4c14ef845d..fd71e876e1 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -536,7 +536,6 @@ struct zap_span { char *name; uint32_t span_id; uint32_t chan_count; - uint32_t active_count; zap_span_flag_t flags; struct zap_io_interface *zio; zio_event_cb_t event_callback; @@ -639,6 +638,7 @@ OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count); OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan); diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 7d141804bc..462615f74c 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -240,6 +240,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) ss7_boost_request_status_t st; char ani[128] = ""; char *gr = NULL; + uint32_t count = 0; if (zap_test_flag(span, ZAP_SPAN_SUSPENDED)) { zap_log(ZAP_LOG_CRIT, "SPAN is not online.\n"); @@ -247,7 +248,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - if (span->active_count >= span->chan_count) { + 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; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index aea2ae3e42..8e5b9381c6 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -887,12 +887,6 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel if (ok) { - if (zchan->state == ZAP_CHANNEL_STATE_DOWN) { - zchan->span->active_count++; - } else if (state == ZAP_CHANNEL_STATE_DOWN) { - zchan->span->active_count--; - } - zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); zchan->last_state = zchan->state; @@ -906,11 +900,32 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel return ok ? ZAP_SUCCESS : ZAP_FAIL; } +OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count) +{ + uint32_t j; + + *count = 0; + + if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { + return ZAP_FAIL; + } + + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { + if (span->channels[j]) { + if (zap_test_flag(span->channels[j], ZAP_CHANNEL_INUSE)) { + (*count)++; + } + } + } + + return ZAP_SUCCESS; +} + OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; - uint32_t i,j; + uint32_t i, j, count; zap_span_t *span = NULL; uint32_t span_max; @@ -923,7 +938,9 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t return ZAP_FAIL; } - if (span->active_count >= span->chan_count) { + 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; From 7c6ffbf13149f62b009310b3b425bb3e2a9f02d3 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 30 Jun 2009 09:42:10 +0000 Subject: [PATCH 1429/1766] Fix encoding of Call State IE, Q.931 (05/98) 4.5.7: bit 8 of octet 3 is part of the coding standard git-svn-id: http://svn.openzap.org/svn/openzap/trunk@751 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 61ffc3dcc1..7755e2cbaa 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -519,7 +519,7 @@ L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR pie->IEId = IBuf[Octet++]; /* Octet 2 */ - IESize = IBuf[Octet++]; + IESize = IBuf[Octet++]; /* Octet 3 */ pie->CodStand = (IBuf[Octet + Off] >> 6) & 0x03; @@ -557,7 +557,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = Q931ie_CALL_STATE; li = (*Octet)++; /* remember length position */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + OBuf[(*Octet)++] = (pIE->CodStand << 6) | (pIE->CallState & 0x3f); OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; return rc; From b46cbfd686713e64240e39b7aada1065f00115cc Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 30 Jun 2009 09:42:10 +0000 Subject: [PATCH 1430/1766] Fix encoding of Call State IE, Q.931 (05/98) 4.5.7: bit 8 of octet 3 is part of the coding standard git-svn-id: http://svn.openzap.org/svn/openzap/trunk@751 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 61ffc3dcc1..7755e2cbaa 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -519,7 +519,7 @@ L3INT Q931Uie_CallState(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR pie->IEId = IBuf[Octet++]; /* Octet 2 */ - IESize = IBuf[Octet++]; + IESize = IBuf[Octet++]; /* Octet 3 */ pie->CodStand = (IBuf[Octet + Off] >> 6) & 0x03; @@ -557,7 +557,7 @@ L3INT Q931Pie_CallState(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, OBuf[(*Octet)++] = Q931ie_CALL_STATE; li = (*Octet)++; /* remember length position */ - OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<6) | pIE->CallState; + OBuf[(*Octet)++] = (pIE->CodStand << 6) | (pIE->CallState & 0x3f); OBuf[li] = (L3UCHAR)((*Octet) - Beg) - 2; return rc; From 4c7ca1c801d68f31ed84b621d0b6647f08552f2a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 30 Jun 2009 18:48:37 +0000 Subject: [PATCH 1431/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@752 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 462615f74c..c74bec43f1 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -68,9 +68,8 @@ typedef struct { zap_channel_t *zchan; } ss7_boost_request_t; -#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN - - //#define MAX_REQ_ID 5 +//#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 }}; @@ -140,7 +139,7 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) r = ++last_req; if (r >= MAX_REQ_ID) { - r = last_req = 1; + r = i = last_req = 1; } if (req_map[r]) { @@ -448,7 +447,11 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s zap_mutex_unlock(zchan->mutex); } - release_request_id_span_chan(event->span, event->chan); + if (event->call_setup_id) { + release_request_id(event->call_setup_id); + } else { + release_request_id_span_chan(event->span, event->chan); + } } /** From e4b834b7a2dd4d70e405fb1a5bcf0f1aa693a9ff Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 30 Jun 2009 18:48:37 +0000 Subject: [PATCH 1432/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@752 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 462615f74c..c74bec43f1 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -68,9 +68,8 @@ typedef struct { zap_channel_t *zchan; } ss7_boost_request_t; -#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN - - //#define MAX_REQ_ID 5 +//#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 }}; @@ -140,7 +139,7 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) r = ++last_req; if (r >= MAX_REQ_ID) { - r = last_req = 1; + r = i = last_req = 1; } if (req_map[r]) { @@ -448,7 +447,11 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s zap_mutex_unlock(zchan->mutex); } - release_request_id_span_chan(event->span, event->chan); + if (event->call_setup_id) { + release_request_id(event->call_setup_id); + } else { + release_request_id_span_chan(event->span, event->chan); + } } /** From 93c96452fc4b16ae473e4caa0062ff52b9e9b906 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 3 Jul 2009 09:15:47 +0000 Subject: [PATCH 1433/1766] Fix Q931Uie_UserUser() (broken length handling, IEs always only specify the length of attached data, excluding id and length field!) and allow User-User IE in incoming SETUP, ALERTING, CONNECT, DISCONNECT, RELEASE and RELEASE COMPLETE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@753 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931ie.c | 15 ++++++--------- libs/openzap/src/isdn/Q931mes.c | 6 ++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/isdn/Q931ie.c b/libs/openzap/src/isdn/Q931ie.c index 7755e2cbaa..62312ee654 100644 --- a/libs/openzap/src/isdn/Q931ie.c +++ b/libs/openzap/src/isdn/Q931ie.c @@ -2813,7 +2813,6 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR ie *pIE = &pMsg->UserUser; L3INT Off = 0; L3INT Octet = 0; - L3INT x = 0; L3INT l; *pIE = 0; @@ -2821,22 +2820,20 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR pie->IEId = IBuf[Octet++]; /* Octet 2 */ - l = IBuf[Octet++] - 3; + l = IBuf[Octet++] - 1; /* Octet 3 */ - pie->ProtDisc = IBuf[Octet + Off]; - Octet++; + pie->ProtDisc = IBuf[Octet++]; - for (x = 0; x < l; x++) { - pie->User[x] = IBuf[Octet + Off]; - Off++; + for (Off = 0; Off < l; Off++) { + pie->User[Off] = IBuf[Octet + Off]; } Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + Off - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + Off - 1); return Q931E_NO_ERROR; } diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index b89cf6fbba..8283880288 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -89,6 +89,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; @@ -289,6 +290,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; @@ -448,6 +450,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener 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; @@ -734,6 +737,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; @@ -799,6 +803,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_ 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; @@ -1197,6 +1202,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m case Q931ie_LOW_LAYER_COMPATIBILITY: case Q931ie_HIGH_LAYER_COMPATIBILITY: 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; From 56f9cfccd3508fd06176769cc2ea16e72f04b467 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 3 Jul 2009 09:15:47 +0000 Subject: [PATCH 1434/1766] Fix Q931Uie_UserUser() (broken length handling, IEs always only specify the length of attached data, excluding id and length field!) and allow User-User IE in incoming SETUP, ALERTING, CONNECT, DISCONNECT, RELEASE and RELEASE COMPLETE git-svn-id: http://svn.openzap.org/svn/openzap/trunk@753 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931ie.c | 15 ++++++--------- libs/freetdm/src/isdn/Q931mes.c | 6 ++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931ie.c b/libs/freetdm/src/isdn/Q931ie.c index 7755e2cbaa..62312ee654 100644 --- a/libs/freetdm/src/isdn/Q931ie.c +++ b/libs/freetdm/src/isdn/Q931ie.c @@ -2813,7 +2813,6 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR ie *pIE = &pMsg->UserUser; L3INT Off = 0; L3INT Octet = 0; - L3INT x = 0; L3INT l; *pIE = 0; @@ -2821,22 +2820,20 @@ L3INT Q931Uie_UserUser(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR pie->IEId = IBuf[Octet++]; /* Octet 2 */ - l = IBuf[Octet++] - 3; + l = IBuf[Octet++] - 1; /* Octet 3 */ - pie->ProtDisc = IBuf[Octet + Off]; - Octet++; + pie->ProtDisc = IBuf[Octet++]; - for (x = 0; x < l; x++) { - pie->User[x] = IBuf[Octet + Off]; - Off++; + for (Off = 0; Off < l; Off++) { + pie->User[Off] = IBuf[Octet + Off]; } Q931SetIE(*pIE, *OOff); *IOff = (*IOff) + Octet + Off; - *OOff = (*OOff) + sizeof(Q931ie_UserUser) + x - 1; - pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + x - 1); + *OOff = (*OOff) + sizeof(Q931ie_UserUser) + Off - 1; + pie->Size = (L3UCHAR)(sizeof(Q931ie_UserUser) + Off - 1); return Q931E_NO_ERROR; } diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index b89cf6fbba..8283880288 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -89,6 +89,7 @@ L3INT Q931Umes_Alerting(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; @@ -289,6 +290,7 @@ L3INT Q931Umes_Connect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; @@ -448,6 +450,7 @@ L3INT Q931Umes_Disconnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Gener 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; @@ -734,6 +737,7 @@ L3INT Q931Umes_Release(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic 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; @@ -799,6 +803,7 @@ L3INT Q931Umes_ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_ 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; @@ -1197,6 +1202,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m case Q931ie_LOW_LAYER_COMPATIBILITY: case Q931ie_HIGH_LAYER_COMPATIBILITY: 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; From 92a6bc5dd4317a272d041702d740cc49473e0fe0 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 3 Jul 2009 09:24:52 +0000 Subject: [PATCH 1435/1766] - WARNING - Add STATUS ENQUIRY message handling to ozmod_isdn, this is a bad hack because the current OpenZAP isdn stack is not stateful (the experimental rewritten version is...) and so we have to try to map OpenZAP channel states to ISDN states, which is not possible in all cases. This patch (as long as it sends the right answer) prevents sudden disconnects of (active) calls, caused by not responding to a STATUS ENQUIRY message from the other side. - WARNING - git-svn-id: http://svn.openzap.org/svn/openzap/trunk@754 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 192a4446a2..7aa23604fa 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1013,6 +1013,61 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } 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; From dbe8b148f4f578920d2597e0413a4172c02413af Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Fri, 3 Jul 2009 09:24:52 +0000 Subject: [PATCH 1436/1766] - WARNING - Add STATUS ENQUIRY message handling to ozmod_isdn, this is a bad hack because the current OpenZAP isdn stack is not stateful (the experimental rewritten version is...) and so we have to try to map OpenZAP channel states to ISDN states, which is not possible in all cases. This patch (as long as it sends the right answer) prevents sudden disconnects of (active) calls, caused by not responding to a STATUS ENQUIRY message from the other side. - WARNING - git-svn-id: http://svn.openzap.org/svn/openzap/trunk@754 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 192a4446a2..7aa23604fa 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1013,6 +1013,61 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } 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; From 79cfacd1d48b5da2ea9c4c07ddd9d59c0eca9531 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 7 Jul 2009 18:43:42 +0000 Subject: [PATCH 1437/1766] get boost up to date git-svn-id: http://svn.openzap.org/svn/openzap/trunk@759 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 136 ++++++++++++------ .../ozmod/ozmod_ss7_boost/ss7_boost_client.c | 14 +- 2 files changed, 103 insertions(+), 47 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index c74bec43f1..cd3787c030 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -38,6 +38,9 @@ #include #endif +#define MAX_TRUNK_GROUPS 64 +static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; + /** * \brief Strange flag */ @@ -180,46 +183,41 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i 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) { + if (force || (zchan->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(zchan, ZAP_CHANNEL_INUSE))) { + break; + } else { + zchan = NULL; + zap_log(ZAP_LOG_ERROR, "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; } - 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", - span->channels[i]->span_id, - span->channels[i]->chan_id, - span->channels[i]->physical_span_id, - span->channels[i]->physical_chan_id); - - zap_mutex_unlock(signal_mutex); - for (x = 0; x < 200; x++) { - if (!zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - break; - } - zap_sleep(5); - } - zap_mutex_lock(signal_mutex); - } - if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - zchan = NULL; - zap_log(ZAP_LOG_ERROR, "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; } } - zap_mutex_unlock(signal_mutex); 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 ss7 boost channel on a span (outgoing call) * \param span Span where to get a channel @@ -240,12 +238,33 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) 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. (BOOST REQUESTED BACK OFF)\n"); + *zchan = NULL; + return ZAP_FAIL; + } zap_span_channel_use_count(span, &count); @@ -262,20 +281,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - - zap_set_string(ani, caller_data->ani.digits); - - if ((gr = strchr(ani, '@'))) { - *gr++ = '\0'; - } - ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); if (gr && *(gr+1)) { - event.trunk_group = atoi(gr+1); - if (event.trunk_group > 0) { - event.trunk_group--; - } switch(*gr) { case 'g': @@ -363,6 +371,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; + + if (check_congestion(0)) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy. (BOOST REQUESTED BACK OFF)\n"); + return ZAP_FAIL; + } + return status; } @@ -464,7 +478,35 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s { 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) { + ss7bc_exec_command(mcon, 0, 0, @@ -959,6 +1001,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) static __inline__ void init_outgoing_array(void) { memset(&OUTBOUND_REQUESTS, 0, sizeof(OUTBOUND_REQUESTS)); + } /** @@ -1090,16 +1133,20 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) } if (FD_ISSET(pcon->socket, &rfds)) { - if ((event = ss7bc_connection_readp(pcon, i))) { + while ((event = ss7bc_connection_readp(pcon, i))) { parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); + i++; } } + i=0; if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); + i++; } } + } @@ -1127,7 +1174,6 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (zap_running()) { check_state(span); } - } goto end; diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 37ad3d02b9..216ff8fa0f 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -64,7 +64,9 @@ static struct ss7bc_map ss7bc_table[] = { {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_REMOVE_CHECK_LOOP, "LOOP STOP"}, + {SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE, "AUTO_CALL_GAP_ABATE"}, + {SIGBOOST_EVENT_DIGIT_IN, "DIGIT_IN"} }; @@ -261,6 +263,10 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, 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); } @@ -338,7 +344,11 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, 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); } From 6a34d570aaf482f9e6189060546ca797978a4ba8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 7 Jul 2009 18:43:42 +0000 Subject: [PATCH 1438/1766] get boost up to date git-svn-id: http://svn.openzap.org/svn/openzap/trunk@759 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 136 ++++++++++++------ .../ozmod/ozmod_ss7_boost/ss7_boost_client.c | 14 +- 2 files changed, 103 insertions(+), 47 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index c74bec43f1..cd3787c030 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -38,6 +38,9 @@ #include #endif +#define MAX_TRUNK_GROUPS 64 +static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; + /** * \brief Strange flag */ @@ -180,46 +183,41 @@ static zap_channel_t *find_zchan(zap_span_t *span, ss7bc_short_event_t *event, i 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) { + if (force || (zchan->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(zchan, ZAP_CHANNEL_INUSE))) { + break; + } else { + zchan = NULL; + zap_log(ZAP_LOG_ERROR, "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; } - 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", - span->channels[i]->span_id, - span->channels[i]->chan_id, - span->channels[i]->physical_span_id, - span->channels[i]->physical_chan_id); - - zap_mutex_unlock(signal_mutex); - for (x = 0; x < 200; x++) { - if (!zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - break; - } - zap_sleep(5); - } - zap_mutex_lock(signal_mutex); - } - if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { - zchan = NULL; - zap_log(ZAP_LOG_ERROR, "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; } } - zap_mutex_unlock(signal_mutex); 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 ss7 boost channel on a span (outgoing call) * \param span Span where to get a channel @@ -240,12 +238,33 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) 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. (BOOST REQUESTED BACK OFF)\n"); + *zchan = NULL; + return ZAP_FAIL; + } zap_span_channel_use_count(span, &count); @@ -262,20 +281,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - - zap_set_string(ani, caller_data->ani.digits); - - if ((gr = strchr(ani, '@'))) { - *gr++ = '\0'; - } - ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); if (gr && *(gr+1)) { - event.trunk_group = atoi(gr+1); - if (event.trunk_group > 0) { - event.trunk_group--; - } switch(*gr) { case 'g': @@ -363,6 +371,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; + + if (check_congestion(0)) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy. (BOOST REQUESTED BACK OFF)\n"); + return ZAP_FAIL; + } + return status; } @@ -464,7 +478,35 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s { 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) { + ss7bc_exec_command(mcon, 0, 0, @@ -959,6 +1001,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) static __inline__ void init_outgoing_array(void) { memset(&OUTBOUND_REQUESTS, 0, sizeof(OUTBOUND_REQUESTS)); + } /** @@ -1090,16 +1133,20 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) } if (FD_ISSET(pcon->socket, &rfds)) { - if ((event = ss7bc_connection_readp(pcon, i))) { + while ((event = ss7bc_connection_readp(pcon, i))) { parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); + i++; } } + i=0; if (FD_ISSET(mcon->socket, &rfds)) { if ((event = ss7bc_connection_read(mcon, i))) { parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); + i++; } } + } @@ -1127,7 +1174,6 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) if (zap_running()) { check_state(span); } - } goto end; diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 37ad3d02b9..216ff8fa0f 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -64,7 +64,9 @@ static struct ss7bc_map ss7bc_table[] = { {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_REMOVE_CHECK_LOOP, "LOOP STOP"}, + {SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE, "AUTO_CALL_GAP_ABATE"}, + {SIGBOOST_EVENT_DIGIT_IN, "DIGIT_IN"} }; @@ -261,6 +263,10 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, 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); } @@ -338,7 +344,11 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, 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); } From f5bce01142b11f92085d793b54636a32ec507d1f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jul 2009 19:35:48 +0000 Subject: [PATCH 1439/1766] changed from nenad git-svn-id: http://svn.openzap.org/svn/openzap/trunk@761 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index cd3787c030..722eb1a373 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -261,7 +261,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) event.trunk_group = tg; if (check_congestion(tg)) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy. (BOOST REQUESTED BACK OFF)\n"); + zap_log(ZAP_LOG_CRIT, "All circuits are busy. Trunk Group=%i (BOOST REQUESTED BACK OFF)\n",tg+1); *zchan = NULL; return ZAP_FAIL; } @@ -372,11 +372,6 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; - if (check_congestion(0)) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy. (BOOST REQUESTED BACK OFF)\n"); - return ZAP_FAIL; - } - return status; } @@ -652,7 +647,9 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + if (event->isup_in_rdnis_size) { + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + } zchan->caller_data.screen = event->calling_number_screening_ind; zchan->caller_data.pres = event->calling_number_presentation; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); From 9983a15bc301cc634f2693cdaae2b1a480c30638 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jul 2009 19:35:48 +0000 Subject: [PATCH 1440/1766] changed from nenad git-svn-id: http://svn.openzap.org/svn/openzap/trunk@761 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index cd3787c030..722eb1a373 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -261,7 +261,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) event.trunk_group = tg; if (check_congestion(tg)) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy. (BOOST REQUESTED BACK OFF)\n"); + zap_log(ZAP_LOG_CRIT, "All circuits are busy. Trunk Group=%i (BOOST REQUESTED BACK OFF)\n",tg+1); *zchan = NULL; return ZAP_FAIL; } @@ -372,11 +372,6 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; - if (check_congestion(0)) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy. (BOOST REQUESTED BACK OFF)\n"); - return ZAP_FAIL; - } - return status; } @@ -652,7 +647,9 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ } zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + if (event->isup_in_rdnis_size) { + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + } zchan->caller_data.screen = event->calling_number_screening_ind; zchan->caller_data.pres = event->calling_number_presentation; zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); From e17c30bdc631e86c1dc10d0e35c992a11bf55d0f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 10 Jul 2009 18:45:07 +0000 Subject: [PATCH 1441/1766] avoiding segfault git-svn-id: http://svn.openzap.org/svn/openzap/trunk@765 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index 60e6f51d88..762a939a02 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -172,11 +172,11 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dc 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; - spri->span = span; pri_set_debug(spri->pri, debug); ret = 0; zap_set_flag(spri, LPWRAP_PRI_READY); From 3148bc5eae96e0f876ac5b8004989e87c20e84e9 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 10 Jul 2009 18:45:07 +0000 Subject: [PATCH 1442/1766] avoiding segfault git-svn-id: http://svn.openzap.org/svn/openzap/trunk@765 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index 60e6f51d88..762a939a02 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -172,11 +172,11 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dc 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; - spri->span = span; pri_set_debug(spri->pri, debug); ret = 0; zap_set_flag(spri, LPWRAP_PRI_READY); From 07bbcb6adb70111c99c8746a6e4833a3a343fde4 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 13 Jul 2009 16:29:47 +0000 Subject: [PATCH 1443/1766] removing tv member from sigboost structures git-svn-id: http://svn.openzap.org/svn/openzap/trunk@772 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h | 2 -- libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c | 4 ---- 2 files changed, 6 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h index f705dfd09f..cf35fd5f8f 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h @@ -99,7 +99,6 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; - struct timeval tv; 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 */ @@ -127,7 +126,6 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; - struct timeval tv; uint8_t release_cause; } t_sigboost_short; #pragma pack() diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 216ff8fa0f..1cefc7878a 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -404,8 +404,6 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } } - gettimeofday(&event->tv, NULL); - zap_mutex_lock(mcon->mutex); if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->txseq=0; @@ -450,8 +448,6 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co event_size=sizeof(ss7bc_short_event_t); } - gettimeofday(&event->tv, NULL); - 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)); From d81971970def95c8f677e2fb1432bd91775938e8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 13 Jul 2009 16:29:47 +0000 Subject: [PATCH 1444/1766] removing tv member from sigboost structures git-svn-id: http://svn.openzap.org/svn/openzap/trunk@772 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h | 2 -- libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c | 4 ---- 2 files changed, 6 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h index f705dfd09f..cf35fd5f8f 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h @@ -99,7 +99,6 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; - struct timeval tv; 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 */ @@ -127,7 +126,6 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; - struct timeval tv; uint8_t release_cause; } t_sigboost_short; #pragma pack() diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 216ff8fa0f..1cefc7878a 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -404,8 +404,6 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } } - gettimeofday(&event->tv, NULL); - zap_mutex_lock(mcon->mutex); if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->txseq=0; @@ -450,8 +448,6 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co event_size=sizeof(ss7bc_short_event_t); } - gettimeofday(&event->tv, NULL); - 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)); From 40ddd20beddbee76b85df3fbf207cd271c07a616 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 17 Jul 2009 14:07:55 +0000 Subject: [PATCH 1445/1766] Make callerid privacy work, thx Moc git-svn-id: http://svn.openzap.org/svn/openzap/trunk@775 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5caa9e1a5b..6b5688d2cd 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2346,7 +2346,7 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "+OK\n"); } } else { - stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); goto end; } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 5b07494ef6..3af38e389a 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -548,7 +548,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + 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); From ce9aa8bec38d8167618f71b4e6bb877ac1227a7f Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Fri, 17 Jul 2009 14:07:55 +0000 Subject: [PATCH 1446/1766] Make callerid privacy work, thx Moc git-svn-id: http://svn.openzap.org/svn/openzap/trunk@775 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5caa9e1a5b..6b5688d2cd 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2346,7 +2346,7 @@ SWITCH_STANDARD_API(oz_function) stream->write_function(stream, "+OK\n"); } } else { - stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); goto end; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 5b07494ef6..3af38e389a 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -548,7 +548,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN); + 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); From 79e8060d9ba5bc8e10b09fad07f8cc6bbecea7a1 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 20 Jul 2009 14:27:59 +0000 Subject: [PATCH 1447/1766] move to info. (OPENZAP-85) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@777 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 6b5688d2cd..a13a3026e5 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2383,7 +2383,7 @@ SWITCH_STANDARD_APP(disable_ec_function) tech_pvt = switch_core_session_get_private(session); zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOCANCEL, &x); zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOTRAIN, &x); - zap_log(ZAP_LOG_ERROR, "Echo Canceller Disabled\n"); + zap_log(ZAP_LOG_INFO, "Echo Canceller Disabled\n"); } From c165b8d1eabeddc587bd7eaa6509f7b82e1aab11 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 20 Jul 2009 14:27:59 +0000 Subject: [PATCH 1448/1766] move to info. (OPENZAP-85) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@777 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 6b5688d2cd..a13a3026e5 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2383,7 +2383,7 @@ SWITCH_STANDARD_APP(disable_ec_function) tech_pvt = switch_core_session_get_private(session); zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOCANCEL, &x); zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOTRAIN, &x); - zap_log(ZAP_LOG_ERROR, "Echo Canceller Disabled\n"); + zap_log(ZAP_LOG_INFO, "Echo Canceller Disabled\n"); } From 40f5e07db62dfeef73a686ca5252f5bb4b0e6eae Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 20 Jul 2009 15:13:14 +0000 Subject: [PATCH 1449/1766] add patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@778 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/patches/droptest.diff | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libs/openzap/patches/droptest.diff diff --git a/libs/openzap/patches/droptest.diff b/libs/openzap/patches/droptest.diff new file mode 100644 index 0000000000..5f73a2d42e --- /dev/null +++ b/libs/openzap/patches/droptest.diff @@ -0,0 +1,51 @@ +Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +=================================================================== +--- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 776) ++++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) +@@ -604,6 +604,8 @@ + return ZAP_SUCCESS; + } + ++ zap_log(ZAP_LOG_ERROR, "FAIL %d\n", bsent); ++ + return ZAP_FAIL; + } + +Index: mod_openzap/mod_openzap.c +=================================================================== +--- mod_openzap/mod_openzap.c (revision 776) ++++ mod_openzap/mod_openzap.c (working copy) +@@ -674,6 +674,7 @@ + assert(tech_pvt->zchan != NULL); + + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEAD\n"); + return SWITCH_STATUS_FALSE; + } + +@@ -682,6 +683,7 @@ + } + + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO FLAG IO\n"); + goto fail; + } + +@@ -689,6 +691,7 @@ + frame->data = data; + frame->buflen = sizeof(data); + if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_packet) > frame->buflen) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "BUF ERR\n"); + goto fail; + } + memset(data, 255, frame->datalen); +@@ -697,7 +700,9 @@ + + len = frame->datalen; + if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WR ERR\n"); + if (++tech_pvt->wr_error > 10) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "10 WR ERR\n"); + goto fail; + } + } else { From cc3f3cb16e698072ee6bd22166acec6382c269a3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 20 Jul 2009 15:13:14 +0000 Subject: [PATCH 1450/1766] add patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@778 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/patches/droptest.diff | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libs/freetdm/patches/droptest.diff diff --git a/libs/freetdm/patches/droptest.diff b/libs/freetdm/patches/droptest.diff new file mode 100644 index 0000000000..5f73a2d42e --- /dev/null +++ b/libs/freetdm/patches/droptest.diff @@ -0,0 +1,51 @@ +Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +=================================================================== +--- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 776) ++++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) +@@ -604,6 +604,8 @@ + return ZAP_SUCCESS; + } + ++ zap_log(ZAP_LOG_ERROR, "FAIL %d\n", bsent); ++ + return ZAP_FAIL; + } + +Index: mod_openzap/mod_openzap.c +=================================================================== +--- mod_openzap/mod_openzap.c (revision 776) ++++ mod_openzap/mod_openzap.c (working copy) +@@ -674,6 +674,7 @@ + assert(tech_pvt->zchan != NULL); + + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEAD\n"); + return SWITCH_STATUS_FALSE; + } + +@@ -682,6 +683,7 @@ + } + + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO FLAG IO\n"); + goto fail; + } + +@@ -689,6 +691,7 @@ + frame->data = data; + frame->buflen = sizeof(data); + if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_packet) > frame->buflen) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "BUF ERR\n"); + goto fail; + } + memset(data, 255, frame->datalen); +@@ -697,7 +700,9 @@ + + len = frame->datalen; + if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WR ERR\n"); + if (++tech_pvt->wr_error > 10) { ++ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "10 WR ERR\n"); + goto fail; + } + } else { From b1b47a492a4eaf157d11b65fdddaf9e01163dad4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Jul 2009 16:26:47 +0000 Subject: [PATCH 1451/1766] enable rbs mode on analog over t1/e1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@779 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 7b359ff804..4fa255465b 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -267,7 +267,8 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } #endif - if (type == ZAP_CHAN_TYPE_CAS) { + if (type == ZAP_CHAN_TYPE_CAS || + ((span->trunk_type == ZAP_TRUNK_T1 || span->trunk_type == ZAP_TRUNK_E1) && type != ZAP_CHAN_TYPE_B)) { #ifdef LIBSANGOMA_VERSION sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); #else From f7e05b0b4e091492fc6ff55e3f6218843ee3cc19 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Jul 2009 16:26:47 +0000 Subject: [PATCH 1452/1766] enable rbs mode on analog over t1/e1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@779 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 7b359ff804..4fa255465b 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -267,7 +267,8 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } #endif - if (type == ZAP_CHAN_TYPE_CAS) { + if (type == ZAP_CHAN_TYPE_CAS || + ((span->trunk_type == ZAP_TRUNK_T1 || span->trunk_type == ZAP_TRUNK_E1) && type != ZAP_CHAN_TYPE_B)) { #ifdef LIBSANGOMA_VERSION sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); #else From 1d0b3612375990e0ad8158a6b6e5882f7becb13b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 23 Jul 2009 16:48:23 +0000 Subject: [PATCH 1453/1766] wanpipe for windows (OPENZAP-78). This should work with the next beta driver release from sangoma on windows git-svn-id: http://svn.openzap.org/svn/openzap/trunk@780 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.2008.vcproj | 4 ++-- libs/openzap/msvc/openzap.2008.vcproj | 1 + libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj index fca3f9b9d7..720849dee9 100644 --- a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj +++ b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj @@ -65,7 +65,7 @@ Date: Thu, 23 Jul 2009 16:48:23 +0000 Subject: [PATCH 1454/1766] wanpipe for windows (OPENZAP-78). This should work with the next beta driver release from sangoma on windows git-svn-id: http://svn.openzap.org/svn/openzap/trunk@780 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.2008.vcproj | 4 ++-- libs/freetdm/msvc/openzap.2008.vcproj | 1 + libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj index fca3f9b9d7..720849dee9 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj +++ b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj @@ -65,7 +65,7 @@ Date: Thu, 23 Jul 2009 21:38:42 +0000 Subject: [PATCH 1455/1766] add patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@781 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/patches/droptest2.diff | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libs/openzap/patches/droptest2.diff diff --git a/libs/openzap/patches/droptest2.diff b/libs/openzap/patches/droptest2.diff new file mode 100644 index 0000000000..9af97b75d0 --- /dev/null +++ b/libs/openzap/patches/droptest2.diff @@ -0,0 +1,29 @@ +Index: mod_openzap/mod_openzap.c +=================================================================== +--- mod_openzap/mod_openzap.c (revision 778) ++++ mod_openzap/mod_openzap.c (working copy) +@@ -664,7 +664,9 @@ + private_t *tech_pvt = NULL; + zap_size_t len; + unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; +- ++ zap_wait_flag_t wflags = ZAP_WRITE; ++ zap_status_t status; ++ + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + +@@ -695,6 +697,13 @@ + } + + ++ wflags = ZAP_WRITE; ++ status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); ++ ++ if (!(wflags & ZAP_WRITE)) { ++ goto fail; ++ } ++ + len = frame->datalen; + if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { + if (++tech_pvt->wr_error > 10) { From e0ea30c5da4ee83b6f26c6d3ff5541b189d23fb4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Jul 2009 21:38:42 +0000 Subject: [PATCH 1456/1766] add patch git-svn-id: http://svn.openzap.org/svn/openzap/trunk@781 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/patches/droptest2.diff | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libs/freetdm/patches/droptest2.diff diff --git a/libs/freetdm/patches/droptest2.diff b/libs/freetdm/patches/droptest2.diff new file mode 100644 index 0000000000..9af97b75d0 --- /dev/null +++ b/libs/freetdm/patches/droptest2.diff @@ -0,0 +1,29 @@ +Index: mod_openzap/mod_openzap.c +=================================================================== +--- mod_openzap/mod_openzap.c (revision 778) ++++ mod_openzap/mod_openzap.c (working copy) +@@ -664,7 +664,9 @@ + private_t *tech_pvt = NULL; + zap_size_t len; + unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; +- ++ zap_wait_flag_t wflags = ZAP_WRITE; ++ zap_status_t status; ++ + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + +@@ -695,6 +697,13 @@ + } + + ++ wflags = ZAP_WRITE; ++ status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); ++ ++ if (!(wflags & ZAP_WRITE)) { ++ goto fail; ++ } ++ + len = frame->datalen; + if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { + if (++tech_pvt->wr_error > 10) { From 193bb790a23218a61b90fb997fa0579865ec3249 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Jul 2009 16:01:33 +0000 Subject: [PATCH 1457/1766] select on write for openzap to avoid overrun on the td, channel git-svn-id: http://svn.openzap.org/svn/openzap/trunk@782 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 11 +++++- libs/openzap/patches/droptest.diff | 51 -------------------------- libs/openzap/patches/droptest2.diff | 29 --------------- 3 files changed, 10 insertions(+), 81 deletions(-) delete mode 100644 libs/openzap/patches/droptest.diff delete mode 100644 libs/openzap/patches/droptest2.diff diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a13a3026e5..9f190eef52 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -664,7 +664,9 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc private_t *tech_pvt = NULL; zap_size_t len; unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; - + zap_wait_flag_t wflags = ZAP_WRITE; + zap_status_t status; + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -695,6 +697,13 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } + wflags = ZAP_WRITE; + status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); + + if (!(wflags & ZAP_WRITE)) { + goto fail; + } + len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { diff --git a/libs/openzap/patches/droptest.diff b/libs/openzap/patches/droptest.diff deleted file mode 100644 index 5f73a2d42e..0000000000 --- a/libs/openzap/patches/droptest.diff +++ /dev/null @@ -1,51 +0,0 @@ -Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -=================================================================== ---- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 776) -+++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) -@@ -604,6 +604,8 @@ - return ZAP_SUCCESS; - } - -+ zap_log(ZAP_LOG_ERROR, "FAIL %d\n", bsent); -+ - return ZAP_FAIL; - } - -Index: mod_openzap/mod_openzap.c -=================================================================== ---- mod_openzap/mod_openzap.c (revision 776) -+++ mod_openzap/mod_openzap.c (working copy) -@@ -674,6 +674,7 @@ - assert(tech_pvt->zchan != NULL); - - if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEAD\n"); - return SWITCH_STATUS_FALSE; - } - -@@ -682,6 +683,7 @@ - } - - if (!switch_test_flag(tech_pvt, TFLAG_IO)) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO FLAG IO\n"); - goto fail; - } - -@@ -689,6 +691,7 @@ - frame->data = data; - frame->buflen = sizeof(data); - if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_packet) > frame->buflen) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "BUF ERR\n"); - goto fail; - } - memset(data, 255, frame->datalen); -@@ -697,7 +700,9 @@ - - len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WR ERR\n"); - if (++tech_pvt->wr_error > 10) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "10 WR ERR\n"); - goto fail; - } - } else { diff --git a/libs/openzap/patches/droptest2.diff b/libs/openzap/patches/droptest2.diff deleted file mode 100644 index 9af97b75d0..0000000000 --- a/libs/openzap/patches/droptest2.diff +++ /dev/null @@ -1,29 +0,0 @@ -Index: mod_openzap/mod_openzap.c -=================================================================== ---- mod_openzap/mod_openzap.c (revision 778) -+++ mod_openzap/mod_openzap.c (working copy) -@@ -664,7 +664,9 @@ - private_t *tech_pvt = NULL; - zap_size_t len; - unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; -- -+ zap_wait_flag_t wflags = ZAP_WRITE; -+ zap_status_t status; -+ - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - -@@ -695,6 +697,13 @@ - } - - -+ wflags = ZAP_WRITE; -+ status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); -+ -+ if (!(wflags & ZAP_WRITE)) { -+ goto fail; -+ } -+ - len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { - if (++tech_pvt->wr_error > 10) { From aacd2d68c0ce55199dc57180c9520a2ec6a4f8be Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 24 Jul 2009 16:01:33 +0000 Subject: [PATCH 1458/1766] select on write for openzap to avoid overrun on the td, channel git-svn-id: http://svn.openzap.org/svn/openzap/trunk@782 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 11 +++++- libs/freetdm/patches/droptest.diff | 51 -------------------------- libs/freetdm/patches/droptest2.diff | 29 --------------- 3 files changed, 10 insertions(+), 81 deletions(-) delete mode 100644 libs/freetdm/patches/droptest.diff delete mode 100644 libs/freetdm/patches/droptest2.diff diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index a13a3026e5..9f190eef52 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -664,7 +664,9 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc private_t *tech_pvt = NULL; zap_size_t len; unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; - + zap_wait_flag_t wflags = ZAP_WRITE; + zap_status_t status; + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -695,6 +697,13 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } + wflags = ZAP_WRITE; + status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); + + if (!(wflags & ZAP_WRITE)) { + goto fail; + } + len = frame->datalen; if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { if (++tech_pvt->wr_error > 10) { diff --git a/libs/freetdm/patches/droptest.diff b/libs/freetdm/patches/droptest.diff deleted file mode 100644 index 5f73a2d42e..0000000000 --- a/libs/freetdm/patches/droptest.diff +++ /dev/null @@ -1,51 +0,0 @@ -Index: src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -=================================================================== ---- src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (revision 776) -+++ src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c (working copy) -@@ -604,6 +604,8 @@ - return ZAP_SUCCESS; - } - -+ zap_log(ZAP_LOG_ERROR, "FAIL %d\n", bsent); -+ - return ZAP_FAIL; - } - -Index: mod_openzap/mod_openzap.c -=================================================================== ---- mod_openzap/mod_openzap.c (revision 776) -+++ mod_openzap/mod_openzap.c (working copy) -@@ -674,6 +674,7 @@ - assert(tech_pvt->zchan != NULL); - - if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEAD\n"); - return SWITCH_STATUS_FALSE; - } - -@@ -682,6 +683,7 @@ - } - - if (!switch_test_flag(tech_pvt, TFLAG_IO)) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO FLAG IO\n"); - goto fail; - } - -@@ -689,6 +691,7 @@ - frame->data = data; - frame->buflen = sizeof(data); - if ((frame->datalen = tech_pvt->write_codec.implementation->encoded_bytes_per_packet) > frame->buflen) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "BUF ERR\n"); - goto fail; - } - memset(data, 255, frame->datalen); -@@ -697,7 +700,9 @@ - - len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WR ERR\n"); - if (++tech_pvt->wr_error > 10) { -+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "10 WR ERR\n"); - goto fail; - } - } else { diff --git a/libs/freetdm/patches/droptest2.diff b/libs/freetdm/patches/droptest2.diff deleted file mode 100644 index 9af97b75d0..0000000000 --- a/libs/freetdm/patches/droptest2.diff +++ /dev/null @@ -1,29 +0,0 @@ -Index: mod_openzap/mod_openzap.c -=================================================================== ---- mod_openzap/mod_openzap.c (revision 778) -+++ mod_openzap/mod_openzap.c (working copy) -@@ -664,7 +664,9 @@ - private_t *tech_pvt = NULL; - zap_size_t len; - unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; -- -+ zap_wait_flag_t wflags = ZAP_WRITE; -+ zap_status_t status; -+ - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - -@@ -695,6 +697,13 @@ - } - - -+ wflags = ZAP_WRITE; -+ status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); -+ -+ if (!(wflags & ZAP_WRITE)) { -+ goto fail; -+ } -+ - len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { - if (++tech_pvt->wr_error > 10) { From 60e0a026b59a80f2b78d9b382be826dff5658aaa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Jul 2009 23:18:47 +0000 Subject: [PATCH 1459/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@783 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 4 ++++ libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 3af38e389a..4334f597ce 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -878,6 +878,7 @@ static __inline__ void check_events(zap_span_t *span) case ZAP_FAIL: { zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); + zap_sleep(5000); } break; default: @@ -947,6 +948,7 @@ static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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; @@ -965,6 +967,8 @@ static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ 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; diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 7a4de2ad93..085370b76e 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1055,10 +1055,11 @@ static ZIO_READ_FUNCTION(zt_read) zap_ssize_t r = 0; int errs = 0; - while (errs++ < 300) { + while (errs++ < 30) { if ((r = read(zchan->sockfd, data, *datalen)) > 0) { break; } + zap_sleep(10); if (r == 0) { errs--; } @@ -1070,6 +1071,11 @@ static ZIO_READ_FUNCTION(zt_read) *datalen -= 2; } return ZAP_SUCCESS; + } else { + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + unsigned char buf[25] = {0}; + write(zchan->sockfd, buf, sizeof(buf)); + } } return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; From 5c0671b1fdaa19f4ad4a14450212394e37cc0cb0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Jul 2009 23:18:47 +0000 Subject: [PATCH 1460/1766] tweak git-svn-id: http://svn.openzap.org/svn/openzap/trunk@783 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 4 ++++ libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 3af38e389a..4334f597ce 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -878,6 +878,7 @@ static __inline__ void check_events(zap_span_t *span) case ZAP_FAIL: { zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); + zap_sleep(5000); } break; default: @@ -947,6 +948,7 @@ static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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; @@ -965,6 +967,8 @@ static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ 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; diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 7a4de2ad93..085370b76e 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1055,10 +1055,11 @@ static ZIO_READ_FUNCTION(zt_read) zap_ssize_t r = 0; int errs = 0; - while (errs++ < 300) { + while (errs++ < 30) { if ((r = read(zchan->sockfd, data, *datalen)) > 0) { break; } + zap_sleep(10); if (r == 0) { errs--; } @@ -1070,6 +1071,11 @@ static ZIO_READ_FUNCTION(zt_read) *datalen -= 2; } return ZAP_SUCCESS; + } else { + if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + unsigned char buf[25] = {0}; + write(zchan->sockfd, buf, sizeof(buf)); + } } return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; From 0b34fdfc48cc2271d85d41a76cf59a3548a5bdde Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Jul 2009 23:19:41 +0000 Subject: [PATCH 1461/1766] add unit test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@784 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 6 +- libs/openzap/src/testpri.c | 162 +++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 libs/openzap/src/testpri.c diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index a7d8f4a9ce..bce0cf2bd5 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -101,7 +101,7 @@ core-install: install-libLTLIBRARIES # # tools & test programs # -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -127,6 +127,10 @@ testisdn_SOURCES = $(SRC)/testisdn.c testisdn_LDADD = libopenzap.la testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testpri_SOURCES = $(SRC)/testpri.c +testpri_LDADD = libopenzap.la +testpri_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testboost_SOURCES = $(SRC)/testboost.c testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) diff --git a/libs/openzap/src/testpri.c b/libs/openzap/src/testpri.c new file mode 100644 index 0000000000..a672d9322f --- /dev/null +++ b/libs/openzap/src/testpri.c @@ -0,0 +1,162 @@ +#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 expandtab: + */ From 0b6fdf0e0bbee6f0c0f5b03895427958451ef78f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Jul 2009 23:19:41 +0000 Subject: [PATCH 1462/1766] add unit test git-svn-id: http://svn.openzap.org/svn/openzap/trunk@784 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 6 +- libs/freetdm/src/testpri.c | 162 +++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 libs/freetdm/src/testpri.c diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index a7d8f4a9ce..bce0cf2bd5 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -101,7 +101,7 @@ core-install: install-libLTLIBRARIES # # tools & test programs # -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testboost testanalog testapp testcid +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -127,6 +127,10 @@ testisdn_SOURCES = $(SRC)/testisdn.c testisdn_LDADD = libopenzap.la testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testpri_SOURCES = $(SRC)/testpri.c +testpri_LDADD = libopenzap.la +testpri_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testboost_SOURCES = $(SRC)/testboost.c testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) diff --git a/libs/freetdm/src/testpri.c b/libs/freetdm/src/testpri.c new file mode 100644 index 0000000000..a672d9322f --- /dev/null +++ b/libs/freetdm/src/testpri.c @@ -0,0 +1,162 @@ +#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 expandtab: + */ From 31ca630edc4abac6e8fee91b0682c2829f24a245 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Jul 2009 23:48:52 +0000 Subject: [PATCH 1463/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@785 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c | 9 ++++++--- libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h | 1 + libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 5 ----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index 762a939a02..1c1a31d2c3 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -120,9 +120,11 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) 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; } @@ -203,9 +205,10 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - //if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { - //return -1; - //} + if (spri->errs >= 2) { + spri->errs = 0; + return -1; + } FD_ZERO(&rfds); FD_ZERO(&efds); diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h index cae88ccb92..4c79526b9e 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -103,6 +103,7 @@ struct lpwrap_pri { void *private_info; event_handler eventmap[LPWRAP_PRI_EVENT_MAX]; loop_handler on_loop; + int errs; }; typedef struct lpwrap_pri lpwrap_pri_t; diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 4334f597ce..195af19ed9 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -878,7 +878,7 @@ static __inline__ void check_events(zap_span_t *span) case ZAP_FAIL: { zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); - zap_sleep(5000); + zap_sleep(2000); } break; default: diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 085370b76e..a8ce338a63 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1071,11 +1071,6 @@ static ZIO_READ_FUNCTION(zt_read) *datalen -= 2; } return ZAP_SUCCESS; - } else { - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { - unsigned char buf[25] = {0}; - write(zchan->sockfd, buf, sizeof(buf)); - } } return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; From 98cdec8d6ff3aed3e50e6a8e4bd5ee1a59f9c622 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Jul 2009 23:48:52 +0000 Subject: [PATCH 1464/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@785 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c | 9 ++++++--- libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h | 1 + libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 5 ----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index 762a939a02..1c1a31d2c3 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -120,9 +120,11 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) 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; } @@ -203,9 +205,10 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) } } - //if (!zap_test_flag(spri, LPWRAP_PRI_READY)) { - //return -1; - //} + if (spri->errs >= 2) { + spri->errs = 0; + return -1; + } FD_ZERO(&rfds); FD_ZERO(&efds); diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h index cae88ccb92..4c79526b9e 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h @@ -103,6 +103,7 @@ struct lpwrap_pri { void *private_info; event_handler eventmap[LPWRAP_PRI_EVENT_MAX]; loop_handler on_loop; + int errs; }; typedef struct lpwrap_pri lpwrap_pri_t; diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 4334f597ce..195af19ed9 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -878,7 +878,7 @@ static __inline__ void check_events(zap_span_t *span) case ZAP_FAIL: { zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); - zap_sleep(5000); + zap_sleep(2000); } break; default: diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 085370b76e..a8ce338a63 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1071,11 +1071,6 @@ static ZIO_READ_FUNCTION(zt_read) *datalen -= 2; } return ZAP_SUCCESS; - } else { - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { - unsigned char buf[25] = {0}; - write(zchan->sockfd, buf, sizeof(buf)); - } } return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; From 016d4cd4521326c9fb526c37f9b214fab459d5fa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Jul 2009 01:27:28 +0000 Subject: [PATCH 1465/1766] reset error counter on success git-svn-id: http://svn.openzap.org/svn/openzap/trunk@786 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index 1c1a31d2c3..c75533b223 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -128,6 +128,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) zap_clear_flag(spri, LPWRAP_PRI_READY); return -1; } + spri->errs = 0; res = (int)len; memset(&((unsigned char*)buf)[res],0,2); res+=2; From 0f215da2b1317a79f5b13e7000d0677d8db817a3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Jul 2009 01:27:28 +0000 Subject: [PATCH 1466/1766] reset error counter on success git-svn-id: http://svn.openzap.org/svn/openzap/trunk@786 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index 1c1a31d2c3..c75533b223 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -128,6 +128,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) zap_clear_flag(spri, LPWRAP_PRI_READY); return -1; } + spri->errs = 0; res = (int)len; memset(&((unsigned char*)buf)[res],0,2); res+=2; From b5b1fa667dc8a768c64b9666e57737801e6e0ade Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 31 Jul 2009 15:45:38 +0000 Subject: [PATCH 1467/1766] add error check condition for invalid channel selection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@787 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8e5b9381c6..4b62dd3153 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1122,7 +1122,11 @@ OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, za goto done; } - check = span->channels[chan_id]; + if (!(check = span->channels[chan_id])) { + zap_log(ZAP_LOG_ERROR, "Invalid Channel %d\n", chan_id); + *zchan = NULL; + goto done; + } if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { From f3370d2cb80340c3c4651540d3632bf2ab9c26f8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 31 Jul 2009 15:45:38 +0000 Subject: [PATCH 1468/1766] add error check condition for invalid channel selection git-svn-id: http://svn.openzap.org/svn/openzap/trunk@787 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8e5b9381c6..4b62dd3153 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1122,7 +1122,11 @@ OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, za goto done; } - check = span->channels[chan_id]; + if (!(check = span->channels[chan_id])) { + zap_log(ZAP_LOG_ERROR, "Invalid Channel %d\n", chan_id); + *zchan = NULL; + goto done; + } if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { From 6af827a72dff13f49992a1ddf9613f787d69b551 Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 31 Jul 2009 19:16:47 +0000 Subject: [PATCH 1469/1766] adding oz dump as xml git-svn-id: http://svn.openzap.org/svn/openzap/trunk@788 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 110 +++++++++++++++++++++---- 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 9f190eef52..e2a7db22c0 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -130,6 +130,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp); void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); +void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) @@ -2201,6 +2202,48 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } +void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) +{ + if (chan_id > span->chan_count) { + return; + } + + stream->write_function(stream, + " \n" + " %u\n" + " %u>\n" + " %u\n" + " %u\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " \n", + span->channels[chan_id]->span_id, + span->channels[chan_id]->chan_id, + span->channels[chan_id]->physical_span_id, + span->channels[chan_id]->physical_chan_id, + zap_chan_type2str(span->channels[chan_id]->type), + zap_channel_state2str(span->channels[chan_id]->state), + zap_channel_state2str(span->channels[chan_id]->last_state), + span->channels[chan_id]->caller_data.cid_date, + span->channels[chan_id]->caller_data.cid_name, + span->channels[chan_id]->caller_data.cid_num.digits, + span->channels[chan_id]->caller_data.ani.digits, + span->channels[chan_id]->caller_data.aniII, + span->channels[chan_id]->caller_data.dnis.digits, + span->channels[chan_id]->caller_data.rdnis.digits, + switch_channel_cause2str(span->channels[chan_id]->caller_data.hangup_cause) + ); +} + #define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix]" SWITCH_STANDARD_API(oz_function) { @@ -2223,30 +2266,61 @@ SWITCH_STANDARD_API(oz_function) } else { uint32_t chan_id = 0; zap_span_t *span; + char *as = NULL; zap_span_find_by_name(argv[1], &span); if (argc > 2) { - chan_id = atoi(argv[2]); - } - - if (!span) { - stream->write_function(stream, "-ERR invalid span\n"); - } else { - if (chan_id) { - if(chan_id > span->chan_count) { - stream->write_function(stream, "-ERR invalid channel\n"); - } else { - dump_chan(span, chan_id, stream); - } + if (argv[3] && !strcasecmp(argv[2], "as")) { + as = argv[3]; } else { - uint32_t j; - - stream->write_function(stream, "+OK\n"); - for (j = 1; j <= span->chan_count; j++) { - dump_chan(span, j, stream); - } + chan_id = atoi(argv[2]); + } + } + if (argv[4] && !strcasecmp(argv[3], "as")) { + as = argv[4]; + } + + if (!switch_strlen_zero(as) && !strcasecmp(as, "xml")) { + stream->write_function(stream, "\n"); + if (!span) { + stream->write_function(stream, "invalid span\n"); + } else { + if (chan_id) { + if(chan_id > span->chan_count) { + stream->write_function(stream, "invalid channel\n"); + } else { + dump_chan_xml(span, chan_id, stream); + } + } else { + uint32_t j; + for (j = 1; j <= span->chan_count; j++) { + dump_chan_xml(span, j, stream); + } + + } + } + stream->write_function(stream, "\n"); + } else { + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + } else { + if (chan_id) { + if(chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid channel\n"); + } else { + dump_chan(span, chan_id, stream); + } + } else { + uint32_t j; + + stream->write_function(stream, "+OK\n"); + for (j = 1; j <= span->chan_count; j++) { + dump_chan(span, j, stream); + } + + } } } } From c1879960aa08162d9842f187cdcec7162fdff3f7 Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 31 Jul 2009 19:16:47 +0000 Subject: [PATCH 1470/1766] adding oz dump as xml git-svn-id: http://svn.openzap.org/svn/openzap/trunk@788 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 110 +++++++++++++++++++++---- 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9f190eef52..e2a7db22c0 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -130,6 +130,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp); void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); +void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) @@ -2201,6 +2202,48 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } +void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) +{ + if (chan_id > span->chan_count) { + return; + } + + stream->write_function(stream, + " \n" + " %u\n" + " %u>\n" + " %u\n" + " %u\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " \n", + span->channels[chan_id]->span_id, + span->channels[chan_id]->chan_id, + span->channels[chan_id]->physical_span_id, + span->channels[chan_id]->physical_chan_id, + zap_chan_type2str(span->channels[chan_id]->type), + zap_channel_state2str(span->channels[chan_id]->state), + zap_channel_state2str(span->channels[chan_id]->last_state), + span->channels[chan_id]->caller_data.cid_date, + span->channels[chan_id]->caller_data.cid_name, + span->channels[chan_id]->caller_data.cid_num.digits, + span->channels[chan_id]->caller_data.ani.digits, + span->channels[chan_id]->caller_data.aniII, + span->channels[chan_id]->caller_data.dnis.digits, + span->channels[chan_id]->caller_data.rdnis.digits, + switch_channel_cause2str(span->channels[chan_id]->caller_data.hangup_cause) + ); +} + #define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix]" SWITCH_STANDARD_API(oz_function) { @@ -2223,30 +2266,61 @@ SWITCH_STANDARD_API(oz_function) } else { uint32_t chan_id = 0; zap_span_t *span; + char *as = NULL; zap_span_find_by_name(argv[1], &span); if (argc > 2) { - chan_id = atoi(argv[2]); - } - - if (!span) { - stream->write_function(stream, "-ERR invalid span\n"); - } else { - if (chan_id) { - if(chan_id > span->chan_count) { - stream->write_function(stream, "-ERR invalid channel\n"); - } else { - dump_chan(span, chan_id, stream); - } + if (argv[3] && !strcasecmp(argv[2], "as")) { + as = argv[3]; } else { - uint32_t j; - - stream->write_function(stream, "+OK\n"); - for (j = 1; j <= span->chan_count; j++) { - dump_chan(span, j, stream); - } + chan_id = atoi(argv[2]); + } + } + if (argv[4] && !strcasecmp(argv[3], "as")) { + as = argv[4]; + } + + if (!switch_strlen_zero(as) && !strcasecmp(as, "xml")) { + stream->write_function(stream, "\n"); + if (!span) { + stream->write_function(stream, "invalid span\n"); + } else { + if (chan_id) { + if(chan_id > span->chan_count) { + stream->write_function(stream, "invalid channel\n"); + } else { + dump_chan_xml(span, chan_id, stream); + } + } else { + uint32_t j; + for (j = 1; j <= span->chan_count; j++) { + dump_chan_xml(span, j, stream); + } + + } + } + stream->write_function(stream, "\n"); + } else { + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + } else { + if (chan_id) { + if(chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid channel\n"); + } else { + dump_chan(span, chan_id, stream); + } + } else { + uint32_t j; + + stream->write_function(stream, "+OK\n"); + for (j = 1; j <= span->chan_count; j++) { + dump_chan(span, j, stream); + } + + } } } } From 37079aabb3ed1d32321ae17f732aa44a4fee652d Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 12 Aug 2009 20:32:00 +0000 Subject: [PATCH 1471/1766] hrm hard coded values eh? git-svn-id: http://svn.openzap.org/svn/openzap/trunk@792 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 1cefc7878a..b36bec1ca1 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -384,7 +384,7 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con abort(); } - if (event->span > 16 || event->chan > 31) { + 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", ss7bc_event_id_name(event->event_id), event->span, event->chan); abort(); return -1; From 00e453b2222b5bc0a9ee2050c505871405b50e4f Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 12 Aug 2009 20:32:00 +0000 Subject: [PATCH 1472/1766] hrm hard coded values eh? git-svn-id: http://svn.openzap.org/svn/openzap/trunk@792 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c index 1cefc7878a..b36bec1ca1 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c @@ -384,7 +384,7 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con abort(); } - if (event->span > 16 || event->chan > 31) { + 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", ss7bc_event_id_name(event->event_id), event->span, event->chan); abort(); return -1; From d15539a8aa921c2829fe515a92c185e3082fce90 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 12 Aug 2009 20:39:52 +0000 Subject: [PATCH 1473/1766] support more than 16 T1/E1's git-svn-id: http://svn.openzap.org/svn/openzap/trunk@793 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index fd71e876e1..5600219d96 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -182,7 +182,7 @@ #endif #define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 -#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 16 +#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32 #define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN #define ZAP_MAX_SPANS_INTERFACE 128 From a9b4b1a82f6ed79d49cc836239b03bee68ea6057 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 12 Aug 2009 20:39:52 +0000 Subject: [PATCH 1474/1766] support more than 16 T1/E1's git-svn-id: http://svn.openzap.org/svn/openzap/trunk@793 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index fd71e876e1..5600219d96 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -182,7 +182,7 @@ #endif #define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 -#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 16 +#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32 #define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN #define ZAP_MAX_SPANS_INTERFACE 128 From e3a62ffecfb55e14fdc3f73b4d5803396b333ee5 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 15 Aug 2009 19:15:49 +0000 Subject: [PATCH 1475/1766] small fix to avoid annoying veto warning when trying to move state from PROGRESS_MEDIA to PROGRESS git-svn-id: http://svn.openzap.org/svn/openzap/trunk@794 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 195af19ed9..b15f2dfac7 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -726,6 +726,11 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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, From 14108c572468a47b8ecc75cece8f2c1759bed439 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 15 Aug 2009 19:15:49 +0000 Subject: [PATCH 1476/1766] small fix to avoid annoying veto warning when trying to move state from PROGRESS_MEDIA to PROGRESS git-svn-id: http://svn.openzap.org/svn/openzap/trunk@794 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 195af19ed9..b15f2dfac7 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -726,6 +726,11 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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, From 2ed8ceceb1e4f0b0c764a954c198229f6b4856fa Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 17:38:27 +0000 Subject: [PATCH 1477/1766] fixed dtmf boost issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@806 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 722eb1a373..73492a66f0 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1048,6 +1048,63 @@ static __inline__ void check_state(zap_span_t *span) } } + +/** + * \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) { +#if 0 + /* Do nothing for now */ + if (event->enum_id == ZAP_OOB_NOOP) { + continue; + } + if (process_event(span, event) != ZAP_SUCCESS) { + break; + } +#endif + } + } + 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 ss7 boost span (monitor) + * \param me Current thread + * \param obj Span to run in this thread + */ +static void *zap_ss7_events_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + + while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING) && zap_running()) { + check_events(span,100); + } + + return NULL; +} + /** * \brief Main thread function for ss7 boost span (monitor) * \param me Current thread @@ -1204,9 +1261,20 @@ static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) static zap_status_t zap_ss7_boost_start(zap_span_t *span) { + int err; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); - return zap_thread_create_detached(zap_ss7_boost_run, span); + err=zap_thread_create_detached(zap_ss7_boost_run, span); + if (err) { + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + return err; + } + + err=zap_thread_create_detached(zap_ss7_events_run, span); + if (err) { + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + } + return err; } static zap_state_map_t boost_state_map = { From 3777e8c507a06cb9ffa7b85e1fa9d3a4eb9beba3 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 17:38:27 +0000 Subject: [PATCH 1478/1766] fixed dtmf boost issue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@806 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 722eb1a373..73492a66f0 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1048,6 +1048,63 @@ static __inline__ void check_state(zap_span_t *span) } } + +/** + * \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) { +#if 0 + /* Do nothing for now */ + if (event->enum_id == ZAP_OOB_NOOP) { + continue; + } + if (process_event(span, event) != ZAP_SUCCESS) { + break; + } +#endif + } + } + 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 ss7 boost span (monitor) + * \param me Current thread + * \param obj Span to run in this thread + */ +static void *zap_ss7_events_run(zap_thread_t *me, void *obj) +{ + zap_span_t *span = (zap_span_t *) obj; + zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + + while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING) && zap_running()) { + check_events(span,100); + } + + return NULL; +} + /** * \brief Main thread function for ss7 boost span (monitor) * \param me Current thread @@ -1204,9 +1261,20 @@ static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) static zap_status_t zap_ss7_boost_start(zap_span_t *span) { + int err; zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); - return zap_thread_create_detached(zap_ss7_boost_run, span); + err=zap_thread_create_detached(zap_ss7_boost_run, span); + if (err) { + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + return err; + } + + err=zap_thread_create_detached(zap_ss7_events_run, span); + if (err) { + zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + } + return err; } static zap_state_map_t boost_state_map = { From 1dda64ab7197b40b7b73735134ef06a6f2af026b Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 17:59:39 +0000 Subject: [PATCH 1479/1766] added some comments to clarify zap_ss7_events_run stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@807 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 73492a66f0..33c4523abb 100644 --- a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1064,15 +1064,9 @@ static __inline__ void check_events(zap_span_t *span, int ms_timeout) { zap_event_t *event; while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { -#if 0 - /* Do nothing for now */ - if (event->enum_id == ZAP_OOB_NOOP) { - continue; - } - if (process_event(span, event) != ZAP_SUCCESS) { - break; - } -#endif + // 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; @@ -1269,7 +1263,8 @@ static zap_status_t zap_ss7_boost_start(zap_span_t *span) zap_clear_flag(ss7_boost_data, ZAP_SS7_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_ss7_events_run, span); if (err) { zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); From b429cb1111be77273efc3bb40ed0ff2515aa8b3b Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 17:59:39 +0000 Subject: [PATCH 1480/1766] added some comments to clarify zap_ss7_events_run stuff git-svn-id: http://svn.openzap.org/svn/openzap/trunk@807 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c index 73492a66f0..33c4523abb 100644 --- a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c @@ -1064,15 +1064,9 @@ static __inline__ void check_events(zap_span_t *span, int ms_timeout) { zap_event_t *event; while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { -#if 0 - /* Do nothing for now */ - if (event->enum_id == ZAP_OOB_NOOP) { - continue; - } - if (process_event(span, event) != ZAP_SUCCESS) { - break; - } -#endif + // 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; @@ -1269,7 +1263,8 @@ static zap_status_t zap_ss7_boost_start(zap_span_t *span) zap_clear_flag(ss7_boost_data, ZAP_SS7_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_ss7_events_run, span); if (err) { zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); From 68c889ceb745864d1d1c60f429b1bca744bed280 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 21:47:56 +0000 Subject: [PATCH 1481/1766] added initial OpenR2 support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@808 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 17 +- libs/openzap/configure.ac | 3 + libs/openzap/mod_openzap/mod_openzap.c | 329 +++- libs/openzap/src/include/openzap.h | 13 +- libs/openzap/src/include/zap_types.h | 6 +- libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c | 1368 +++++++++++++++++ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 69 +- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 40 +- libs/openzap/src/testr2.c | 86 ++ libs/openzap/src/zap_config.c | 4 +- libs/openzap/src/zap_io.c | 9 +- 11 files changed, 1899 insertions(+), 45 deletions(-) create mode 100644 libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c create mode 100644 libs/openzap/src/testr2.c diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index bce0cf2bd5..c8d334c864 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -101,7 +101,7 @@ core-install: install-libLTLIBRARIES # # tools & test programs # -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testboost testanalog testapp testcid +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -131,6 +131,10 @@ testpri_SOURCES = $(SRC)/testpri.c testpri_LDADD = libopenzap.la testpri_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testr2_SOURCES = $(SRC)/testr2.c +testr2_LDADD = libopenzap.la +testr2_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testboost_SOURCES = $(SRC)/testboost.c testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) @@ -152,6 +156,10 @@ if LIBPRI mod_LTLIBRARIES += ozmod_libpri.la endif +if OPENR2 +mod_LTLIBRARIES += ozmod_r2.la +endif + ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module -avoid-version @@ -218,6 +226,13 @@ ozmod_libpri_la_LDFLAGS = -module -avoid-version -lpri ozmod_libpri_la_LIBADD = $(MYLIB) endif +if OPENR2 +ozmod_r2_la_SOURCES = $(SRC)/ozmod/ozmod_r2/ozmod_r2.c +ozmod_r2_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_r2_la_LDFLAGS = -module -avoid-version -lopenr2 +ozmod_r2_la_LIBADD = $(MYLIB) +endif + dox doxygen: cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index e89564af7a..64f7a46438 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -168,6 +168,9 @@ AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) +AC_CHECK_LIB([openr2], [openr2_context_set_io_type], [have_openr2="yes"]) +AM_CONDITIONAL([OPENR2],[test "${have_openr2}" = "yes"]) + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index e2a7db22c0..905627920f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -24,6 +24,7 @@ * Contributor(s): * * Anthony Minessale II + * Moises Silva * * * mod_openzap.c -- OPENZAP Endpoint Module @@ -446,6 +447,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: case ZAP_CHAN_TYPE_EM: + case ZAP_CHAN_TYPE_CAS: { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); @@ -723,6 +725,65 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } +static switch_status_t channel_receive_message_cas(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + zap_log(ZAP_LOG_DEBUG, "Got Freeswitch message in R2 channel %d [%d]\n", tech_pvt->zchan->physical_chan_id, + msg->message_id); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_RINGING: + { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + } else { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + } + break; + case SWITCH_MESSAGE_INDICATE_PROGRESS: + { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } + } + break; + case SWITCH_MESSAGE_INDICATE_ANSWER: + { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + } else { + /* lets make the ozmod_r2 module life easier by moving thru each + * state waiting for completion, clumsy, but does the job + */ + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } + } + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) { @@ -876,7 +937,10 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s break; case ZAP_CHAN_TYPE_B: status = channel_receive_message_b(session, msg); - break; + break; + case ZAP_CHAN_TYPE_CAS: + status = channel_receive_message_cas(session, msg); + break; default: status = SWITCH_STATUS_FALSE; break; @@ -1473,6 +1537,106 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } +static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) +{ + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + zap_status_t status = ZAP_SUCCESS; + + zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel %d\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); + + switch(sigmsg->event_id) { + /* on_call_disconnect from the R2 side */ + case ZAP_SIGEVENT_STOP: + { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_rwunlock(session); + } + } + break; + + /* on_call_offered from the R2 side */ + case ZAP_SIGEVENT_START: + { + status = zap_channel_from_event(sigmsg, &session); + } + break; + + /* on DNIS received from the R2 forward side, return status == ZAP_BREAK to stop requesting DNIS */ + case ZAP_SIGEVENT_COLLECTED_DIGIT: + { + char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; + char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; + + if (switch_strlen_zero(regex)) { + regex = NULL; + } + + if (switch_strlen_zero(fail_regex)) { + fail_regex = NULL; + } + + zap_log(ZAP_LOG_DEBUG, "R2 DNIS so far [%s]\n", sigmsg->channel->caller_data.dnis.digits); + + if ((regex || fail_regex) && !switch_strlen_zero(sigmsg->channel->caller_data.dnis.digits)) { + switch_regex_t *re = NULL; + int ovector[30]; + int match = 0; + + if (fail_regex) { + match = switch_regex_perform(sigmsg->channel->caller_data.dnis.digits, fail_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_SUCCESS : ZAP_BREAK; + switch_regex_safe_free(re); + } + + if (status == ZAP_SUCCESS && regex) { + match = switch_regex_perform(sigmsg->channel->caller_data.dnis.digits, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_BREAK : ZAP_SUCCESS; + } + + switch_regex_safe_free(re); + } + } + break; + + case ZAP_SIGEVENT_PROGRESS: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_ring_ready(channel); + switch_core_session_rwunlock(session); + } + } + break; + + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_tone_type_t tt = ZAP_TONE_DTMF; + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to enable DTMF detection in R2 channel %d:%d\n", sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + switch_core_session_rwunlock(session); + } + } + break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled event %d from R2 for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } + + return status; +} + static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; @@ -2154,7 +2318,170 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "r2_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; + /* strings */ + const char *variant = "itu"; + const char *category = "national_subscriber"; + const char *logdir = "/usr/local/freeswitch/log/"; /* FIXME: get PREFIX variable */ + const char *logging = "notice,warning,error"; + const char *advanced_protocol_file = ""; + + /* booleans */ + int call_files = 0; + int get_ani_first = -1; + int immediate_accept = -1; + int double_answer = -1; + int skip_category = -1; + int forced_release = -1; + int charge_calls = -1; + + /* integers */ + int mfback_timeout = -1; + int metering_pulse_timeout = -1; + int allow_collect_calls = -1; + int max_ani = 10; + int max_dnis = 4; + + /* common non r2 stuff */ + const char *context = "default"; + const char *dialplan = "XML"; + char *dial_regex = NULL; + char *fail_dial_regex = NULL; + uint32_t span_id = 0; + zap_span_t *span = NULL; + + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + /* string parameters */ + if (!strcasecmp(var, "variant")) { + variant = val; + } else if (!strcasecmp(var, "category")) { + category = val; + } else if (!strcasecmp(var, "logdir")) { + logdir = val; + } else if (!strcasecmp(var, "logging")) { + logging = val; + } else if (!strcasecmp(var, "advanced_protocol_file")) { + advanced_protocol_file = val; + + /* booleans */ + } else if (!strcasecmp(var, "allow_collect_calls")) { + allow_collect_calls = switch_true(val); + } else if (!strcasecmp(var, "immediate_accept")) { + immediate_accept = switch_true(val); + } else if (!strcasecmp(var, "double_answer")) { + double_answer = switch_true(val); + } else if (!strcasecmp(var, "skip_category")) { + skip_category = switch_true(var); + } else if (!strcasecmp(var, "forced_release")) { + forced_release = switch_true(val); + } else if (!strcasecmp(var, "charge_calls")) { + charge_calls = switch_true(val); + } else if (!strcasecmp(var, "get_ani_first")) { + get_ani_first = switch_true(val); + } else if (!strcasecmp(var, "call_files")) { + call_files = switch_true(val); + + /* integers */ + } else if (!strcasecmp(var, "mfback_timeout")) { + mfback_timeout = atoi(val); + } else if (!strcasecmp(var, "metering_pulse_timeout")) { + metering_pulse_timeout = atoi(val); + } else if (!strcasecmp(var, "max_ani")) { + max_ani = atoi(val); + } else if (!strcasecmp(var, "max_dnis")) { + max_dnis = atoi(val); + + /* common non r2 stuff */ + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } + } + + if (!id && !name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; + } + + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + continue; + } + + if (!span_id) { + span_id = span->span_id; + } + + if (zap_configure_span("r2", span, on_r2_signal, + "variant", variant, + "max_ani", max_ani, + "max_dnis", max_dnis, + "category", category, + "logdir", logdir, + "logging", logging, + "advanced_protocol_file", advanced_protocol_file, + "allow_collect_calls", allow_collect_calls, + "immediate_accept", immediate_accept, + "double_answer", double_answer, + "skip_category", skip_category, + "forced_release", forced_release, + "charge_calls", charge_calls, + "get_ani_first", get_ani_first, + "call_files", call_files, + "mfback_timeout", mfback_timeout, + "metering_pulse_timeout", metering_pulse_timeout, + TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error configuring R2 OpenZAP span %d, error: %s\n", + span_id, span->last_error); + continue; + } + + if (dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); + } + + if (fail_dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "r2", sizeof(SPAN_CONFIG[span->span_id].type)); + + if (zap_span_start(span) == ZAP_FAIL) { + zap_log(ZAP_LOG_ERROR, "Error starting R2 OpenZAP span %d, error: %s\n", span_id, span->last_error); + continue; + } + } + } switch_xml_free(xml); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 5600219d96..6b0c703f23 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -280,6 +280,17 @@ } \ } while(0); +#define zap_locked_wait_for_flag_cleared(obj, flag, time) \ + do { \ + int __safety = time; \ + while(__safety-- && zap_test_flag(obj, flag)) { \ + zap_sleep(10); \ + } \ + if(!__safety) { \ + zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ + } \ + } while(0); + typedef enum { ZAP_STATE_CHANGE_FAIL, @@ -517,7 +528,7 @@ struct zap_channel { struct zap_span *span; struct zap_io_interface *zio; zap_hash_t *variable_hash; - unsigned char cas_bits; + unsigned char rx_cas_bits; }; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 13e8c2a7a3..713e67e3e8 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -175,7 +175,8 @@ typedef enum { ZAP_SIGTYPE_RBS, ZAP_SIGTYPE_ANALOG, ZAP_SIGTYPE_SS7BOOST, - ZAP_SIGTYPE_M3UA + ZAP_SIGTYPE_M3UA, + ZAP_SIGTYPE_R2 } zap_signal_type_t; typedef enum { @@ -279,6 +280,9 @@ typedef enum { 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_COUNT } zap_command_t; diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c new file mode 100644 index 0000000000..0ffb61d0b0 --- /dev/null +++ b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c @@ -0,0 +1,1368 @@ +/* + * 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 { + /* signaling callback */ + zio_signal_cb_t sig_cb; + /* 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_locked_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_locked_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_r2_data_t *r2data = zchan->span->signal_data; + + 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 (r2data->sig_cb(&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; + + r2data->sig_cb(&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; + + r2data->sig_cb(&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 (r2data->sig_cb(&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; + r2data->sig_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_r2_data_t *r2data = zchan->span->signal_data; + + 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 (r2data->sig_cb(&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 (r2data->sig_cb(&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"); + 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; + zap_log(ZAP_LOG_ERROR, "success getting poll event\n"); + 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 + */ diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index c45e5f295b..241d180a37 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -202,7 +202,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned configured = 0, x; if (type == ZAP_CHAN_TYPE_CAS) { - zap_log(ZAP_LOG_DEBUG, "Configuring CAS channels with abcd == 0x%X\n", cas_bits); + 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; @@ -210,22 +210,25 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, const char *dtmf = "none"; sockfd = tdmv_api_open_span_chan(spanno, x); + if (sockfd == WP_INVALID_SOCKET) { + zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x); + continue; + } - if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + 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 - sangoma_status_t sangstatus; + sangoma_status_t sangstatus; sangoma_wait_obj_t *sangoma_wait_obj; - 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; - } + 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 - - memset(&tdm_api,0,sizeof(tdm_api)); chan->physical_span_id = spanno; chan->physical_chan_id = x; @@ -237,7 +240,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, dtmf = "software"; /* FIXME: Handle Error Condition Check for return code */ - err= sangoma_tdm_get_hw_coding(chan->sockfd, &tdm_api); + 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; @@ -270,15 +273,26 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (type == ZAP_CHAN_TYPE_CAS || ((span->trunk_type == ZAP_TRUNK_T1 || span->trunk_type == ZAP_TRUNK_E1) && type != ZAP_CHAN_TYPE_B)) { #ifdef LIBSANGOMA_VERSION - sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); + 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 - sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); + 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)); } @@ -288,7 +302,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, spanno, x, chan->span_id, chan->chan_id, sockfd, dtmf); } else { - zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + zap_log(ZAP_LOG_ERROR, "zap_span_add_channel failed for wanpipe span %d channel %d\n", spanno, x); } } @@ -371,15 +385,13 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) } if (!(sp && ch)) { - zap_log(ZAP_LOG_ERROR, "Invalid input\n"); + 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; @@ -528,16 +540,24 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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)); + 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)); + err = sangoma_tdm_write_rbs(zchan->sockfd, &tdm_api, wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT)); #endif } break; case ZAP_COMMAND_GET_CAS_BITS: { - /* wanpipe does not has a command to get the CAS bits so we emulate it */ - ZAP_COMMAND_OBJ_INT = zchan->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: @@ -817,7 +837,6 @@ 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); @@ -856,7 +875,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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); + 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; @@ -926,9 +945,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) case WP_TDMAPI_EVENT_RBS: { event_id = ZAP_OOB_CAS_BITS_CHANGE; - /* save the CAS bits, user should retrieve it with ZAP_COMMAND_GET_CAS_BITS - is there a best play to store this? instead of adding cas_bits member to zap_chan? */ - span->channels[i]->cas_bits = wanpipe_swap_bits(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rbs_bits); + 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: diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index a8ce338a63..9e4369334b 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -442,7 +442,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { int items, i; - char *mydata, *item_list[10]; + char *mydata, *item_list[10]; char *ch, *mx; unsigned char cas_bits = 0; int channo; @@ -777,10 +777,9 @@ static ZIO_COMMAND_FUNCTION(zt_command) 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 (zchan->effective_codec == ZAP_CODEC_SLIN) { + zchan->packet_len *= 2; + } } } break; @@ -792,21 +791,42 @@ static ZIO_COMMAND_FUNCTION(zt_command) break; case ZAP_COMMAND_GET_CAS_BITS: { - /* probably we should call ZT_GETRXBITS instead? */ - ZAP_COMMAND_OBJ_INT = zchan->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) { + if (err && err != ZAP_NOTIMPL) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } - return ZAP_SUCCESS; + return err == 0 ? ZAP_SUCCESS : err; } /** @@ -1019,7 +1039,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) if (err) { return ZAP_FAIL; } - span->channels[i]->cas_bits = bits; + span->channels[i]->rx_cas_bits = bits; } break; default: diff --git a/libs/openzap/src/testr2.c b/libs/openzap/src/testr2.c new file mode 100644 index 0000000000..f5f093cb4f --- /dev/null +++ b/libs/openzap/src/testr2.c @@ -0,0 +1,86 @@ +#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 expandtab: + */ diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index 32567041eb..05d5db3c61 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -216,14 +216,14 @@ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) 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", 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); + 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); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 4b62dd3153..a20ea0ccf9 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1522,14 +1522,17 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - zap_log(ZAP_LOG_ERROR, "no commnand functon!\n"); + zap_log(ZAP_LOG_ERROR, "no command function defined by the I/O openzap module!\n"); GOTO_STATUS(done, ZAP_FAIL); } status = zchan->zio->command(zchan, command, obj); - - done: + if (status == ZAP_NOTIMPL) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "I/O command %d not implemented in backend", command); + zap_log(ZAP_LOG_ERROR, "I/O backend does not support command %d!\n", command); + } +done: zap_mutex_unlock(zchan->mutex); return status; From f7cd2544398d60afc6999aa41f5f51600a62e301 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 21:47:56 +0000 Subject: [PATCH 1482/1766] added initial OpenR2 support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@808 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 17 +- libs/freetdm/configure.ac | 3 + libs/freetdm/mod_openzap/mod_openzap.c | 329 +++- libs/freetdm/src/include/openzap.h | 13 +- libs/freetdm/src/include/zap_types.h | 6 +- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 1368 +++++++++++++++++ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 69 +- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 40 +- libs/freetdm/src/testr2.c | 86 ++ libs/freetdm/src/zap_config.c | 4 +- libs/freetdm/src/zap_io.c | 9 +- 11 files changed, 1899 insertions(+), 45 deletions(-) create mode 100644 libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c create mode 100644 libs/freetdm/src/testr2.c diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index bce0cf2bd5..c8d334c864 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -101,7 +101,7 @@ core-install: install-libLTLIBRARIES # # tools & test programs # -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testboost testanalog testapp testcid +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 testboost testanalog testapp testcid testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -131,6 +131,10 @@ testpri_SOURCES = $(SRC)/testpri.c testpri_LDADD = libopenzap.la testpri_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +testr2_SOURCES = $(SRC)/testr2.c +testr2_LDADD = libopenzap.la +testr2_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testboost_SOURCES = $(SRC)/testboost.c testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) @@ -152,6 +156,10 @@ if LIBPRI mod_LTLIBRARIES += ozmod_libpri.la endif +if OPENR2 +mod_LTLIBRARIES += ozmod_r2.la +endif + ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_zt_la_LDFLAGS = -module -avoid-version @@ -218,6 +226,13 @@ ozmod_libpri_la_LDFLAGS = -module -avoid-version -lpri ozmod_libpri_la_LIBADD = $(MYLIB) endif +if OPENR2 +ozmod_r2_la_SOURCES = $(SRC)/ozmod/ozmod_r2/ozmod_r2.c +ozmod_r2_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_r2_la_LDFLAGS = -module -avoid-version -lopenr2 +ozmod_r2_la_LIBADD = $(MYLIB) +endif + dox doxygen: cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index e89564af7a..64f7a46438 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -168,6 +168,9 @@ AM_CONDITIONAL([LIBSANGOMA],[test "${have_libsangoma}" = "yes"]) AM_CONDITIONAL([LIBPRI],[test "${enable_libpri}" = "yes"]) +AC_CHECK_LIB([openr2], [openr2_context_set_io_type], [have_openr2="yes"]) +AM_CONDITIONAL([OPENR2],[test "${have_openr2}" = "yes"]) + COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index e2a7db22c0..905627920f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -24,6 +24,7 @@ * Contributor(s): * * Anthony Minessale II + * Moises Silva * * * mod_openzap.c -- OPENZAP Endpoint Module @@ -446,6 +447,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXO: case ZAP_CHAN_TYPE_EM: + case ZAP_CHAN_TYPE_CAS: { zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); @@ -723,6 +725,65 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } +static switch_status_t channel_receive_message_cas(switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_channel_t *channel; + private_t *tech_pvt; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + zap_log(ZAP_LOG_DEBUG, "Got Freeswitch message in R2 channel %d [%d]\n", tech_pvt->zchan->physical_chan_id, + msg->message_id); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_RINGING: + { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + } else { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + } + break; + case SWITCH_MESSAGE_INDICATE_PROGRESS: + { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + } else { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } + } + break; + case SWITCH_MESSAGE_INDICATE_ANSWER: + { + if (switch_channel_test_flag(channel, CF_OUTBOUND)) { + zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + } else { + /* lets make the ozmod_r2 module life easier by moving thru each + * state waiting for completion, clumsy, but does the job + */ + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + } + if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + } + zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + } + } + break; + default: + break; + } + + return SWITCH_STATUS_SUCCESS; +} static switch_status_t channel_receive_message_b(switch_core_session_t *session, switch_core_session_message_t *msg) { @@ -876,7 +937,10 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s break; case ZAP_CHAN_TYPE_B: status = channel_receive_message_b(session, msg); - break; + break; + case ZAP_CHAN_TYPE_CAS: + status = channel_receive_message_cas(session, msg); + break; default: status = SWITCH_STATUS_FALSE; break; @@ -1473,6 +1537,106 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } +static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) +{ + switch_core_session_t *session = NULL; + switch_channel_t *channel = NULL; + zap_status_t status = ZAP_SUCCESS; + + zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel %d\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); + + switch(sigmsg->event_id) { + /* on_call_disconnect from the R2 side */ + case ZAP_SIGEVENT_STOP: + { + while((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); + zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + switch_core_session_rwunlock(session); + } + } + break; + + /* on_call_offered from the R2 side */ + case ZAP_SIGEVENT_START: + { + status = zap_channel_from_event(sigmsg, &session); + } + break; + + /* on DNIS received from the R2 forward side, return status == ZAP_BREAK to stop requesting DNIS */ + case ZAP_SIGEVENT_COLLECTED_DIGIT: + { + char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; + char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; + + if (switch_strlen_zero(regex)) { + regex = NULL; + } + + if (switch_strlen_zero(fail_regex)) { + fail_regex = NULL; + } + + zap_log(ZAP_LOG_DEBUG, "R2 DNIS so far [%s]\n", sigmsg->channel->caller_data.dnis.digits); + + if ((regex || fail_regex) && !switch_strlen_zero(sigmsg->channel->caller_data.dnis.digits)) { + switch_regex_t *re = NULL; + int ovector[30]; + int match = 0; + + if (fail_regex) { + match = switch_regex_perform(sigmsg->channel->caller_data.dnis.digits, fail_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_SUCCESS : ZAP_BREAK; + switch_regex_safe_free(re); + } + + if (status == ZAP_SUCCESS && regex) { + match = switch_regex_perform(sigmsg->channel->caller_data.dnis.digits, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); + status = match ? ZAP_BREAK : ZAP_SUCCESS; + } + + switch_regex_safe_free(re); + } + } + break; + + case ZAP_SIGEVENT_PROGRESS: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + channel = switch_core_session_get_channel(session); + switch_channel_mark_ring_ready(channel); + switch_core_session_rwunlock(session); + } + } + break; + + case ZAP_SIGEVENT_UP: + { + if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + zap_tone_type_t tt = ZAP_TONE_DTMF; + channel = switch_core_session_get_channel(session); + switch_channel_mark_answered(channel); + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to enable DTMF detection in R2 channel %d:%d\n", sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + switch_core_session_rwunlock(session); + } + } + break; + + default: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled event %d from R2 for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); + } + break; + } + + return status; +} + static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; @@ -2154,7 +2318,170 @@ static switch_status_t load_config(void) } } + if ((spans = switch_xml_child(cfg, "r2_spans"))) { + for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { + char *id = (char *) switch_xml_attr(myspan, "id"); + char *name = (char *) switch_xml_attr(myspan, "name"); + zap_status_t zstatus = ZAP_FAIL; + /* strings */ + const char *variant = "itu"; + const char *category = "national_subscriber"; + const char *logdir = "/usr/local/freeswitch/log/"; /* FIXME: get PREFIX variable */ + const char *logging = "notice,warning,error"; + const char *advanced_protocol_file = ""; + + /* booleans */ + int call_files = 0; + int get_ani_first = -1; + int immediate_accept = -1; + int double_answer = -1; + int skip_category = -1; + int forced_release = -1; + int charge_calls = -1; + + /* integers */ + int mfback_timeout = -1; + int metering_pulse_timeout = -1; + int allow_collect_calls = -1; + int max_ani = 10; + int max_dnis = 4; + + /* common non r2 stuff */ + const char *context = "default"; + const char *dialplan = "XML"; + char *dial_regex = NULL; + char *fail_dial_regex = NULL; + uint32_t span_id = 0; + zap_span_t *span = NULL; + + + for (param = switch_xml_child(myspan, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + /* string parameters */ + if (!strcasecmp(var, "variant")) { + variant = val; + } else if (!strcasecmp(var, "category")) { + category = val; + } else if (!strcasecmp(var, "logdir")) { + logdir = val; + } else if (!strcasecmp(var, "logging")) { + logging = val; + } else if (!strcasecmp(var, "advanced_protocol_file")) { + advanced_protocol_file = val; + + /* booleans */ + } else if (!strcasecmp(var, "allow_collect_calls")) { + allow_collect_calls = switch_true(val); + } else if (!strcasecmp(var, "immediate_accept")) { + immediate_accept = switch_true(val); + } else if (!strcasecmp(var, "double_answer")) { + double_answer = switch_true(val); + } else if (!strcasecmp(var, "skip_category")) { + skip_category = switch_true(var); + } else if (!strcasecmp(var, "forced_release")) { + forced_release = switch_true(val); + } else if (!strcasecmp(var, "charge_calls")) { + charge_calls = switch_true(val); + } else if (!strcasecmp(var, "get_ani_first")) { + get_ani_first = switch_true(val); + } else if (!strcasecmp(var, "call_files")) { + call_files = switch_true(val); + + /* integers */ + } else if (!strcasecmp(var, "mfback_timeout")) { + mfback_timeout = atoi(val); + } else if (!strcasecmp(var, "metering_pulse_timeout")) { + metering_pulse_timeout = atoi(val); + } else if (!strcasecmp(var, "max_ani")) { + max_ani = atoi(val); + } else if (!strcasecmp(var, "max_dnis")) { + max_dnis = atoi(val); + + /* common non r2 stuff */ + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } + } + + if (!id && !name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + continue; + } + + if (name) { + zstatus = zap_span_find_by_name(name, &span); + } else { + if (switch_is_number(id)) { + span_id = atoi(id); + zstatus = zap_span_find(span_id, &span); + } + + if (zstatus != ZAP_SUCCESS) { + zstatus = zap_span_find_by_name(id, &span); + } + } + + if (zstatus != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + continue; + } + + if (!span_id) { + span_id = span->span_id; + } + + if (zap_configure_span("r2", span, on_r2_signal, + "variant", variant, + "max_ani", max_ani, + "max_dnis", max_dnis, + "category", category, + "logdir", logdir, + "logging", logging, + "advanced_protocol_file", advanced_protocol_file, + "allow_collect_calls", allow_collect_calls, + "immediate_accept", immediate_accept, + "double_answer", double_answer, + "skip_category", skip_category, + "forced_release", forced_release, + "charge_calls", charge_calls, + "get_ani_first", get_ani_first, + "call_files", call_files, + "mfback_timeout", mfback_timeout, + "metering_pulse_timeout", metering_pulse_timeout, + TAG_END) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error configuring R2 OpenZAP span %d, error: %s\n", + span_id, span->last_error); + continue; + } + + if (dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].dial_regex, dial_regex); + } + + if (fail_dial_regex) { + switch_set_string(SPAN_CONFIG[span->span_id].fail_dial_regex, fail_dial_regex); + } + + SPAN_CONFIG[span->span_id].span = span; + switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); + switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "r2", sizeof(SPAN_CONFIG[span->span_id].type)); + + if (zap_span_start(span) == ZAP_FAIL) { + zap_log(ZAP_LOG_ERROR, "Error starting R2 OpenZAP span %d, error: %s\n", span_id, span->last_error); + continue; + } + } + } switch_xml_free(xml); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 5600219d96..6b0c703f23 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -280,6 +280,17 @@ } \ } while(0); +#define zap_locked_wait_for_flag_cleared(obj, flag, time) \ + do { \ + int __safety = time; \ + while(__safety-- && zap_test_flag(obj, flag)) { \ + zap_sleep(10); \ + } \ + if(!__safety) { \ + zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ + } \ + } while(0); + typedef enum { ZAP_STATE_CHANGE_FAIL, @@ -517,7 +528,7 @@ struct zap_channel { struct zap_span *span; struct zap_io_interface *zio; zap_hash_t *variable_hash; - unsigned char cas_bits; + unsigned char rx_cas_bits; }; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 13e8c2a7a3..713e67e3e8 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -175,7 +175,8 @@ typedef enum { ZAP_SIGTYPE_RBS, ZAP_SIGTYPE_ANALOG, ZAP_SIGTYPE_SS7BOOST, - ZAP_SIGTYPE_M3UA + ZAP_SIGTYPE_M3UA, + ZAP_SIGTYPE_R2 } zap_signal_type_t; typedef enum { @@ -279,6 +280,9 @@ typedef enum { 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_COUNT } zap_command_t; diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c new file mode 100644 index 0000000000..0ffb61d0b0 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -0,0 +1,1368 @@ +/* + * 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 { + /* signaling callback */ + zio_signal_cb_t sig_cb; + /* 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_locked_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_locked_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_r2_data_t *r2data = zchan->span->signal_data; + + 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 (r2data->sig_cb(&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; + + r2data->sig_cb(&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; + + r2data->sig_cb(&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 (r2data->sig_cb(&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; + r2data->sig_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_r2_data_t *r2data = zchan->span->signal_data; + + 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 (r2data->sig_cb(&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 (r2data->sig_cb(&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"); + 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; + zap_log(ZAP_LOG_ERROR, "success getting poll event\n"); + 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 + */ diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index c45e5f295b..241d180a37 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -202,7 +202,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned configured = 0, x; if (type == ZAP_CHAN_TYPE_CAS) { - zap_log(ZAP_LOG_DEBUG, "Configuring CAS channels with abcd == 0x%X\n", cas_bits); + 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; @@ -210,22 +210,25 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, const char *dtmf = "none"; sockfd = tdmv_api_open_span_chan(spanno, x); + if (sockfd == WP_INVALID_SOCKET) { + zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x); + continue; + } - if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + 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 - sangoma_status_t sangstatus; + sangoma_status_t sangstatus; sangoma_wait_obj_t *sangoma_wait_obj; - 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; - } + 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 - - memset(&tdm_api,0,sizeof(tdm_api)); chan->physical_span_id = spanno; chan->physical_chan_id = x; @@ -237,7 +240,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, dtmf = "software"; /* FIXME: Handle Error Condition Check for return code */ - err= sangoma_tdm_get_hw_coding(chan->sockfd, &tdm_api); + 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; @@ -270,15 +273,26 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (type == ZAP_CHAN_TYPE_CAS || ((span->trunk_type == ZAP_TRUNK_T1 || span->trunk_type == ZAP_TRUNK_E1) && type != ZAP_CHAN_TYPE_B)) { #ifdef LIBSANGOMA_VERSION - sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id,wanpipe_swap_bits(cas_bits)); + 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 - sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,wanpipe_swap_bits(cas_bits)); + 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)); } @@ -288,7 +302,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, spanno, x, chan->span_id, chan->chan_id, sockfd, dtmf); } else { - zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); + zap_log(ZAP_LOG_ERROR, "zap_span_add_channel failed for wanpipe span %d channel %d\n", spanno, x); } } @@ -371,15 +385,13 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) } if (!(sp && ch)) { - zap_log(ZAP_LOG_ERROR, "Invalid input\n"); + 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; @@ -528,16 +540,24 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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)); + 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)); + err = sangoma_tdm_write_rbs(zchan->sockfd, &tdm_api, wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT)); #endif } break; case ZAP_COMMAND_GET_CAS_BITS: { - /* wanpipe does not has a command to get the CAS bits so we emulate it */ - ZAP_COMMAND_OBJ_INT = zchan->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: @@ -817,7 +837,6 @@ 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); @@ -856,7 +875,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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); + 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; @@ -926,9 +945,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) case WP_TDMAPI_EVENT_RBS: { event_id = ZAP_OOB_CAS_BITS_CHANGE; - /* save the CAS bits, user should retrieve it with ZAP_COMMAND_GET_CAS_BITS - is there a best play to store this? instead of adding cas_bits member to zap_chan? */ - span->channels[i]->cas_bits = wanpipe_swap_bits(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_rbs_bits); + 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: diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index a8ce338a63..9e4369334b 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -442,7 +442,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { int items, i; - char *mydata, *item_list[10]; + char *mydata, *item_list[10]; char *ch, *mx; unsigned char cas_bits = 0; int channo; @@ -777,10 +777,9 @@ static ZIO_COMMAND_FUNCTION(zt_command) 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 (zchan->effective_codec == ZAP_CODEC_SLIN) { + zchan->packet_len *= 2; + } } } break; @@ -792,21 +791,42 @@ static ZIO_COMMAND_FUNCTION(zt_command) break; case ZAP_COMMAND_GET_CAS_BITS: { - /* probably we should call ZT_GETRXBITS instead? */ - ZAP_COMMAND_OBJ_INT = zchan->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) { + if (err && err != ZAP_NOTIMPL) { snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); return ZAP_FAIL; } - return ZAP_SUCCESS; + return err == 0 ? ZAP_SUCCESS : err; } /** @@ -1019,7 +1039,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) if (err) { return ZAP_FAIL; } - span->channels[i]->cas_bits = bits; + span->channels[i]->rx_cas_bits = bits; } break; default: diff --git a/libs/freetdm/src/testr2.c b/libs/freetdm/src/testr2.c new file mode 100644 index 0000000000..f5f093cb4f --- /dev/null +++ b/libs/freetdm/src/testr2.c @@ -0,0 +1,86 @@ +#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 expandtab: + */ diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index 32567041eb..05d5db3c61 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -216,14 +216,14 @@ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) 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", 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); + 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); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 4b62dd3153..a20ea0ccf9 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1522,14 +1522,17 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - zap_log(ZAP_LOG_ERROR, "no commnand functon!\n"); + zap_log(ZAP_LOG_ERROR, "no command function defined by the I/O openzap module!\n"); GOTO_STATUS(done, ZAP_FAIL); } status = zchan->zio->command(zchan, command, obj); - - done: + if (status == ZAP_NOTIMPL) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "I/O command %d not implemented in backend", command); + zap_log(ZAP_LOG_ERROR, "I/O backend does not support command %d!\n", command); + } +done: zap_mutex_unlock(zchan->mutex); return status; From ba16417660e4af30bc37c0bdabfbe0bc0725da41 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 22:57:52 +0000 Subject: [PATCH 1483/1766] remove error logging in ozmod_r2 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@809 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c index 0ffb61d0b0..0f57f7349d 100644 --- a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c @@ -1142,7 +1142,6 @@ static void *zap_r2_run(zap_thread_t *me, void *obj) } if (ZAP_SUCCESS == status) { zap_event_t *event; - zap_log(ZAP_LOG_ERROR, "success getting poll event\n"); while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { if (event->enum_id == ZAP_OOB_CAS_BITS_CHANGE) { r2chan = R2CALL(event->channel)->r2chan; From 920682ac540c51d51278475926301c73a7c51775 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 19 Aug 2009 22:57:52 +0000 Subject: [PATCH 1484/1766] remove error logging in ozmod_r2 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@809 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c index 0ffb61d0b0..0f57f7349d 100644 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -1142,7 +1142,6 @@ static void *zap_r2_run(zap_thread_t *me, void *obj) } if (ZAP_SUCCESS == status) { zap_event_t *event; - zap_log(ZAP_LOG_ERROR, "success getting poll event\n"); while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { if (event->enum_id == ZAP_OOB_CAS_BITS_CHANGE) { r2chan = R2CALL(event->channel)->r2chan; From 5d28446fbc7085db9b4238c1c1baeff37764917b Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 19 Aug 2009 23:46:05 +0000 Subject: [PATCH 1485/1766] Add REDIRECTING_NUMBER ie support to Q.931 and national dialect (others follow) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@810 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/isdn/Q931StateNT.c | 5 +++-- libs/openzap/src/isdn/Q931StateTE.c | 5 +++-- libs/openzap/src/isdn/Q931mes.c | 1 + libs/openzap/src/isdn/nationalStateNT.c | 1 + libs/openzap/src/isdn/nationalStateTE.c | 1 + libs/openzap/src/isdn/nationalmes.c | 3 ++- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/isdn/Q931StateNT.c b/libs/openzap/src/isdn/Q931StateNT.c index 6a4a37b0e7..8d05fb6d03 100644 --- a/libs/openzap/src/isdn/Q931StateNT.c +++ b/libs/openzap/src/isdn/Q931StateNT.c @@ -116,8 +116,9 @@ void Q931CreateNT(L3UCHAR i) 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_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 diff --git a/libs/openzap/src/isdn/Q931StateTE.c b/libs/openzap/src/isdn/Q931StateTE.c index b5486b37c0..562dd0b458 100644 --- a/libs/openzap/src/isdn/Q931StateTE.c +++ b/libs/openzap/src/isdn/Q931StateTE.c @@ -123,8 +123,9 @@ void Q931CreateTE(L3UCHAR i) 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_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 diff --git a/libs/openzap/src/isdn/Q931mes.c b/libs/openzap/src/isdn/Q931mes.c index 8283880288..8e34a170e1 100644 --- a/libs/openzap/src/isdn/Q931mes.c +++ b/libs/openzap/src/isdn/Q931mes.c @@ -1203,6 +1203,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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; diff --git a/libs/openzap/src/isdn/nationalStateNT.c b/libs/openzap/src/isdn/nationalStateNT.c index 6b6aa305d6..b150999650 100644 --- a/libs/openzap/src/isdn/nationalStateNT.c +++ b/libs/openzap/src/isdn/nationalStateNT.c @@ -120,6 +120,7 @@ void nationalCreateNT(L3UCHAR i) 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 */ diff --git a/libs/openzap/src/isdn/nationalStateTE.c b/libs/openzap/src/isdn/nationalStateTE.c index a50ae3debd..46731d0910 100644 --- a/libs/openzap/src/isdn/nationalStateTE.c +++ b/libs/openzap/src/isdn/nationalStateTE.c @@ -129,6 +129,7 @@ void nationalCreateTE(L3UCHAR i) 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 diff --git a/libs/openzap/src/isdn/nationalmes.c b/libs/openzap/src/isdn/nationalmes.c index 8d75760c8e..6d8350fbcd 100644 --- a/libs/openzap/src/isdn/nationalmes.c +++ b/libs/openzap/src/isdn/nationalmes.c @@ -92,8 +92,9 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: From 2e87d9d315399db11fc29287e0637333de663e1d Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 19 Aug 2009 23:46:05 +0000 Subject: [PATCH 1486/1766] Add REDIRECTING_NUMBER ie support to Q.931 and national dialect (others follow) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@810 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/isdn/Q931StateNT.c | 5 +++-- libs/freetdm/src/isdn/Q931StateTE.c | 5 +++-- libs/freetdm/src/isdn/Q931mes.c | 1 + libs/freetdm/src/isdn/nationalStateNT.c | 1 + libs/freetdm/src/isdn/nationalStateTE.c | 1 + libs/freetdm/src/isdn/nationalmes.c | 3 ++- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/isdn/Q931StateNT.c b/libs/freetdm/src/isdn/Q931StateNT.c index 6a4a37b0e7..8d05fb6d03 100644 --- a/libs/freetdm/src/isdn/Q931StateNT.c +++ b/libs/freetdm/src/isdn/Q931StateNT.c @@ -116,8 +116,9 @@ void Q931CreateNT(L3UCHAR i) 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_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 diff --git a/libs/freetdm/src/isdn/Q931StateTE.c b/libs/freetdm/src/isdn/Q931StateTE.c index b5486b37c0..562dd0b458 100644 --- a/libs/freetdm/src/isdn/Q931StateTE.c +++ b/libs/freetdm/src/isdn/Q931StateTE.c @@ -123,8 +123,9 @@ void Q931CreateTE(L3UCHAR i) 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_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 diff --git a/libs/freetdm/src/isdn/Q931mes.c b/libs/freetdm/src/isdn/Q931mes.c index 8283880288..8e34a170e1 100644 --- a/libs/freetdm/src/isdn/Q931mes.c +++ b/libs/freetdm/src/isdn/Q931mes.c @@ -1203,6 +1203,7 @@ L3INT Q931Umes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *m 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; diff --git a/libs/freetdm/src/isdn/nationalStateNT.c b/libs/freetdm/src/isdn/nationalStateNT.c index 6b6aa305d6..b150999650 100644 --- a/libs/freetdm/src/isdn/nationalStateNT.c +++ b/libs/freetdm/src/isdn/nationalStateNT.c @@ -120,6 +120,7 @@ void nationalCreateNT(L3UCHAR i) 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 */ diff --git a/libs/freetdm/src/isdn/nationalStateTE.c b/libs/freetdm/src/isdn/nationalStateTE.c index a50ae3debd..46731d0910 100644 --- a/libs/freetdm/src/isdn/nationalStateTE.c +++ b/libs/freetdm/src/isdn/nationalStateTE.c @@ -129,6 +129,7 @@ void nationalCreateTE(L3UCHAR i) 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 diff --git a/libs/freetdm/src/isdn/nationalmes.c b/libs/freetdm/src/isdn/nationalmes.c index 8d75760c8e..6d8350fbcd 100644 --- a/libs/freetdm/src/isdn/nationalmes.c +++ b/libs/freetdm/src/isdn/nationalmes.c @@ -92,8 +92,9 @@ L3INT nationalUmes_Setup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generi 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) + if (rc != Q931E_NO_ERROR) return rc; break; case Q931ie_REPEAT_INDICATOR: From d3d36fe7d410a68b151095b57131dc22480ed00e Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 25 Aug 2009 20:59:59 +0000 Subject: [PATCH 1487/1766] Reverse final libpcap check so it does not mess up flags if something goes wrong git-svn-id: http://svn.openzap.org/svn/openzap/trunk@811 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/build/libpcap.m4 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/build/libpcap.m4 b/libs/openzap/build/libpcap.m4 index fd3bbe1da0..8c758a1a5e 100644 --- a/libs/openzap/build/libpcap.m4 +++ b/libs/openzap/build/libpcap.m4 @@ -123,10 +123,7 @@ AC_ARG_WITH(pcap-include, fi AC_MSG_CHECKING(whether to include pcap) - if test "X$ac_cv_pcap_where_lib" = "X" -a "X$ac_cv_pcap_where_inc" = "X"; then - ac_cv_found_pcap=no - AC_MSG_RESULT(no) - else + if test "X$ac_cv_pcap_where_lib" != "X" -a "X$ac_cv_pcap_where_inc" != "X"; then ac_cv_found_pcap=yes AC_MSG_RESULT(yes) PCAP_INC_DIR=$ac_cv_pcap_where_inc @@ -138,6 +135,9 @@ AC_ARG_WITH(pcap-include, AC_SUBST(PCAP_INC_FLAGS) AC_SUBST(PCAP_LIB_FLAGS) AC_DEFINE([HAVE_LIBPCAP],[1],[libpcap]) + else + ac_cv_found_pcap=no + AC_MSG_RESULT(no) fi ]) From 765ab3028205c991449141efdbce778d3378eeb7 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 25 Aug 2009 20:59:59 +0000 Subject: [PATCH 1488/1766] Reverse final libpcap check so it does not mess up flags if something goes wrong git-svn-id: http://svn.openzap.org/svn/openzap/trunk@811 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/build/libpcap.m4 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/build/libpcap.m4 b/libs/freetdm/build/libpcap.m4 index fd3bbe1da0..8c758a1a5e 100644 --- a/libs/freetdm/build/libpcap.m4 +++ b/libs/freetdm/build/libpcap.m4 @@ -123,10 +123,7 @@ AC_ARG_WITH(pcap-include, fi AC_MSG_CHECKING(whether to include pcap) - if test "X$ac_cv_pcap_where_lib" = "X" -a "X$ac_cv_pcap_where_inc" = "X"; then - ac_cv_found_pcap=no - AC_MSG_RESULT(no) - else + if test "X$ac_cv_pcap_where_lib" != "X" -a "X$ac_cv_pcap_where_inc" != "X"; then ac_cv_found_pcap=yes AC_MSG_RESULT(yes) PCAP_INC_DIR=$ac_cv_pcap_where_inc @@ -138,6 +135,9 @@ AC_ARG_WITH(pcap-include, AC_SUBST(PCAP_INC_FLAGS) AC_SUBST(PCAP_LIB_FLAGS) AC_DEFINE([HAVE_LIBPCAP],[1],[libpcap]) + else + ac_cv_found_pcap=no + AC_MSG_RESULT(no) fi ]) From cba78f885ac68732ee9914c73b236d510da4123d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 26 Aug 2009 20:45:51 +0000 Subject: [PATCH 1489/1766] fix to support NFAS with sangoma_prid git-svn-id: http://svn.openzap.org/svn/openzap/trunk@812 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 241d180a37..599d9e1e3a 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -158,7 +158,12 @@ static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, in static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) { return sangoma_open_tdmapi_span_chan(span, chan); -} +} + +static __inline__ sng_fd_t __tdmv_api_open_span_chan(int span, int chan) +{ + return __sangoma_open_tdmapi_span_chan(span, chan); +} static zap_io_interface_t wanpipe_interface; @@ -209,7 +214,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_socket_t sockfd = WP_INVALID_SOCKET; const char *dtmf = "none"; - sockfd = tdmv_api_open_span_chan(spanno, x); + if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == ZAP_TRUNK_T1 && x == 24) { + sockfd = __tdmv_api_open_span_chan(spanno, x); + } else { + sockfd = tdmv_api_open_span_chan(spanno, x); + } + if (sockfd == WP_INVALID_SOCKET) { zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x); continue; @@ -233,7 +243,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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; @@ -635,6 +645,7 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) * \param to Time to wait (in ms) * \return Success, failure or timeout */ + static ZIO_WAIT_FUNCTION(wanpipe_wait) { int32_t inflags = 0; @@ -703,6 +714,9 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) 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) { From 10c93bc239035ae9aa28670b0985bd9439bd47c5 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 26 Aug 2009 20:45:51 +0000 Subject: [PATCH 1490/1766] fix to support NFAS with sangoma_prid git-svn-id: http://svn.openzap.org/svn/openzap/trunk@812 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 241d180a37..599d9e1e3a 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -158,7 +158,12 @@ static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, in static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) { return sangoma_open_tdmapi_span_chan(span, chan); -} +} + +static __inline__ sng_fd_t __tdmv_api_open_span_chan(int span, int chan) +{ + return __sangoma_open_tdmapi_span_chan(span, chan); +} static zap_io_interface_t wanpipe_interface; @@ -209,7 +214,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_socket_t sockfd = WP_INVALID_SOCKET; const char *dtmf = "none"; - sockfd = tdmv_api_open_span_chan(spanno, x); + if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == ZAP_TRUNK_T1 && x == 24) { + sockfd = __tdmv_api_open_span_chan(spanno, x); + } else { + sockfd = tdmv_api_open_span_chan(spanno, x); + } + if (sockfd == WP_INVALID_SOCKET) { zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x); continue; @@ -233,7 +243,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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; @@ -635,6 +645,7 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) * \param to Time to wait (in ms) * \return Success, failure or timeout */ + static ZIO_WAIT_FUNCTION(wanpipe_wait) { int32_t inflags = 0; @@ -703,6 +714,9 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) 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) { From ead30e960e56a71bbf3188659990521ed95c64dd Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 27 Aug 2009 16:34:03 +0000 Subject: [PATCH 1491/1766] intialize r2chan and make the compiler happy git-svn-id: http://svn.openzap.org/svn/openzap/trunk@813 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c index 0f57f7349d..9683aa57b2 100644 --- a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c @@ -1128,6 +1128,7 @@ static void *zap_r2_run(zap_thread_t *me, void *obj) 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); From 62615f199057c047f11850d34878029feb26965a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 27 Aug 2009 16:34:03 +0000 Subject: [PATCH 1492/1766] intialize r2chan and make the compiler happy git-svn-id: http://svn.openzap.org/svn/openzap/trunk@813 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c index 0f57f7349d..9683aa57b2 100644 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -1128,6 +1128,7 @@ static void *zap_r2_run(zap_thread_t *me, void *obj) 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); From 003f52d3cfda82bb0c0d5785ce8b8c90be9e1621 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 27 Aug 2009 16:34:36 +0000 Subject: [PATCH 1493/1766] dont use smg_prid_nfas if old libsangoma is used git-svn-id: http://svn.openzap.org/svn/openzap/trunk@814 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 599d9e1e3a..cb9f28f971 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -160,10 +160,12 @@ 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; @@ -213,9 +215,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_channel_t *chan; zap_socket_t sockfd = WP_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); } From 178259508bf968bb391163a4ee6c8790e111f533 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 27 Aug 2009 16:34:36 +0000 Subject: [PATCH 1494/1766] dont use smg_prid_nfas if old libsangoma is used git-svn-id: http://svn.openzap.org/svn/openzap/trunk@814 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 599d9e1e3a..cb9f28f971 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -160,10 +160,12 @@ 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; @@ -213,9 +215,12 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, zap_channel_t *chan; zap_socket_t sockfd = WP_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); } From 8ef19daa1a54f393049a4d3233f612cd12d38009 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 1 Sep 2009 00:49:10 +0000 Subject: [PATCH 1495/1766] mod_openzap: fix missing rwunlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@815 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 905627920f..87bce7353f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1286,6 +1286,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) if ((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); + switch_core_session_rwunlock(session); } } break; From 2b0109c0c828d149ca3240d295ce9cc554f8e1b4 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 1 Sep 2009 00:49:10 +0000 Subject: [PATCH 1496/1766] mod_openzap: fix missing rwunlock git-svn-id: http://svn.openzap.org/svn/openzap/trunk@815 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 905627920f..87bce7353f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1286,6 +1286,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) if ((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); + switch_core_session_rwunlock(session); } } break; From d0a7af4e6aaa5058a6396dc315c8933d76a83e8e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Sep 2009 19:11:23 +0000 Subject: [PATCH 1497/1766] possible fix for WANPIPE-5 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@816 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 ++- libs/openzap/src/zap_io.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 713e67e3e8..b403f04387 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -371,7 +371,8 @@ typedef enum { ZAP_CHANNEL_3WAY = (1 << 20), ZAP_CHANNEL_PROGRESS = (1 << 21), ZAP_CHANNEL_MEDIA = (1 << 22), - ZAP_CHANNEL_ANSWERED = (1 << 23) + ZAP_CHANNEL_ANSWERED = (1 << 23), + ZAP_CHANNEL_MUTE = (1 << 24) } zap_channel_flag_t; typedef enum { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index a20ea0ccf9..7d2ea3b094 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2011,7 +2011,8 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ } } } - + + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); @@ -2041,15 +2042,18 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { zchan->skip_read_frames = 20; } - if (zchan->skip_read_frames > 0) { - memset(data, 0, *datalen); - zchan->skip_read_frames--; - } } } } } + if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { + memset(data, 0, *datalen); + if (zchan->skip_read_frames > 0) { + zchan->skip_read_frames--; + } + } + return status; } From 36d9fff0d1dbfbfc27181493e2acd24e454bec58 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Sep 2009 19:11:23 +0000 Subject: [PATCH 1498/1766] possible fix for WANPIPE-5 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@816 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 3 ++- libs/freetdm/src/zap_io.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 713e67e3e8..b403f04387 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -371,7 +371,8 @@ typedef enum { ZAP_CHANNEL_3WAY = (1 << 20), ZAP_CHANNEL_PROGRESS = (1 << 21), ZAP_CHANNEL_MEDIA = (1 << 22), - ZAP_CHANNEL_ANSWERED = (1 << 23) + ZAP_CHANNEL_ANSWERED = (1 << 23), + ZAP_CHANNEL_MUTE = (1 << 24) } zap_channel_flag_t; typedef enum { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a20ea0ccf9..7d2ea3b094 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2011,7 +2011,8 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ } } } - + + if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); @@ -2041,15 +2042,18 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { zchan->skip_read_frames = 20; } - if (zchan->skip_read_frames > 0) { - memset(data, 0, *datalen); - zchan->skip_read_frames--; - } } } } } + if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { + memset(data, 0, *datalen); + if (zchan->skip_read_frames > 0) { + zchan->skip_read_frames--; + } + } + return status; } From 191b8ba2d74d509de6ce902c04ea93c79894beeb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Sep 2009 19:13:47 +0000 Subject: [PATCH 1499/1766] possible fix for WANPIPE-5 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@817 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index cb9f28f971..afabfb0a0f 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -973,7 +973,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = ZAP_OOB_NOOP; //zap_log(ZAP_LOG_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); + 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); zap_channel_queue_dtmf(zchan, tmp_dtmf); } } From b41ce2921e048273b69a2abbd6d84429d54000b9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 1 Sep 2009 19:13:47 +0000 Subject: [PATCH 1500/1766] possible fix for WANPIPE-5 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@817 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index cb9f28f971..afabfb0a0f 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -973,7 +973,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = ZAP_OOB_NOOP; //zap_log(ZAP_LOG_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); + 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); zap_channel_queue_dtmf(zchan, tmp_dtmf); } } From b6974bd69d6f87357e51dc10dc1377ecb540fb86 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 17:18:55 +0000 Subject: [PATCH 1501/1766] changing name part 1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@818 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ozmod_ss7_boost => ozmod_sangoma_boost}/ozmod_ss7_boost.c | 0 .../src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/sigboost.h | 0 .../{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.c | 0 .../{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.h | 0 .../{ozmod_ss7_boost => ozmod_sangoma_boost}/zap_ss7_boost.h | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/ozmod_ss7_boost.c (100%) rename libs/openzap/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/sigboost.h (100%) rename libs/openzap/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.c (100%) rename libs/openzap/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.h (100%) rename libs/openzap/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/zap_ss7_boost.h (100%) diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c similarity index 100% rename from libs/openzap/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h similarity index 100% rename from libs/openzap/src/ozmod/ozmod_ss7_boost/sigboost.h rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c similarity index 100% rename from libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h similarity index 100% rename from libs/openzap/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h diff --git a/libs/openzap/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h similarity index 100% rename from libs/openzap/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h From aeff9e7e94947c5fae5a1d606b2bc4a07072145b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 17:18:55 +0000 Subject: [PATCH 1502/1766] changing name part 1 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@818 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ozmod_ss7_boost => ozmod_sangoma_boost}/ozmod_ss7_boost.c | 0 .../src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/sigboost.h | 0 .../{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.c | 0 .../{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.h | 0 .../{ozmod_ss7_boost => ozmod_sangoma_boost}/zap_ss7_boost.h | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/ozmod_ss7_boost.c (100%) rename libs/freetdm/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/sigboost.h (100%) rename libs/freetdm/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.c (100%) rename libs/freetdm/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/ss7_boost_client.h (100%) rename libs/freetdm/src/ozmod/{ozmod_ss7_boost => ozmod_sangoma_boost}/zap_ss7_boost.h (100%) diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_ss7_boost/sigboost.h rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.c rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_ss7_boost/ss7_boost_client.h rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h diff --git a/libs/freetdm/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_ss7_boost/zap_ss7_boost.h rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h From 6a29e94eb39f8c2952070b87f0b7aafbaf75e78f Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 2 Sep 2009 17:28:56 +0000 Subject: [PATCH 1503/1766] change name part 2 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@819 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 12 ++++++------ libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- libs/openzap/src/include/zap_types.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index c8d334c864..0a942a2bfe 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -36,7 +36,7 @@ moddir = @modinstdir@ libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include -INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost +INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) @@ -146,7 +146,7 @@ testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # # ozmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_sangoma_boost.la if LIBSANGOMA mod_LTLIBRARIES += ozmod_wanpipe.la @@ -214,10 +214,10 @@ ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_em_la_LDFLAGS = -module -avoid-version ozmod_analog_em_la_LIBADD = $(MYLIB) -ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_ss7_boost_la_LDFLAGS = -module -avoid-version -ozmod_ss7_boost_la_LIBADD = $(MYLIB) +ozmod_sangoma_boost_la_SOURCES = $(SRC)/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +ozmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_sangoma_boost_la_LDFLAGS = -module -avoid-version +ozmod_sangoma_boost_la_LIBADD = $(MYLIB) if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 87bce7353f..de32b348ce 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2300,7 +2300,7 @@ static switch_status_t load_config(void) span_id = span->span_id; } - if (zap_configure_span("ss7_boost", span, on_clear_channel_signal, + if (zap_configure_span("sangoma_boost", span, on_clear_channel_signal, "local_ip", local_ip, "local_port", &local_port, "remote_ip", remote_ip, @@ -2315,7 +2315,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); zap_span_start(span); - switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "Sangoma (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); } } diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index b403f04387..d745a72f46 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -174,7 +174,7 @@ typedef enum { ZAP_SIGTYPE_ISDN, ZAP_SIGTYPE_RBS, ZAP_SIGTYPE_ANALOG, - ZAP_SIGTYPE_SS7BOOST, + ZAP_SIGTYPE_SANGOMABOOST, ZAP_SIGTYPE_M3UA, ZAP_SIGTYPE_R2 } zap_signal_type_t; From 822b851b237700d3f64017e57be35a35be754caf Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 2 Sep 2009 17:28:56 +0000 Subject: [PATCH 1504/1766] change name part 2 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@819 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 12 ++++++------ libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- libs/freetdm/src/include/zap_types.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index c8d334c864..0a942a2bfe 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -36,7 +36,7 @@ moddir = @modinstdir@ libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include -INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_ss7_boost +INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) @@ -146,7 +146,7 @@ testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # # ozmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_ss7_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_sangoma_boost.la if LIBSANGOMA mod_LTLIBRARIES += ozmod_wanpipe.la @@ -214,10 +214,10 @@ ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_em_la_LDFLAGS = -module -avoid-version ozmod_analog_em_la_LIBADD = $(MYLIB) -ozmod_ss7_boost_la_SOURCES = $(SRC)/ozmod/ozmod_ss7_boost/ss7_boost_client.c $(SRC)/ozmod/ozmod_ss7_boost/ozmod_ss7_boost.c -ozmod_ss7_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_ss7_boost_la_LDFLAGS = -module -avoid-version -ozmod_ss7_boost_la_LIBADD = $(MYLIB) +ozmod_sangoma_boost_la_SOURCES = $(SRC)/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +ozmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ozmod_sangoma_boost_la_LDFLAGS = -module -avoid-version +ozmod_sangoma_boost_la_LIBADD = $(MYLIB) if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 87bce7353f..de32b348ce 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2300,7 +2300,7 @@ static switch_status_t load_config(void) span_id = span->span_id; } - if (zap_configure_span("ss7_boost", span, on_clear_channel_signal, + if (zap_configure_span("sangoma_boost", span, on_clear_channel_signal, "local_ip", local_ip, "local_port", &local_port, "remote_ip", remote_ip, @@ -2315,7 +2315,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); zap_span_start(span); - switch_copy_string(SPAN_CONFIG[span->span_id].type, "ss7 (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); + switch_copy_string(SPAN_CONFIG[span->span_id].type, "Sangoma (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); } } diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b403f04387..d745a72f46 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -174,7 +174,7 @@ typedef enum { ZAP_SIGTYPE_ISDN, ZAP_SIGTYPE_RBS, ZAP_SIGTYPE_ANALOG, - ZAP_SIGTYPE_SS7BOOST, + ZAP_SIGTYPE_SANGOMABOOST, ZAP_SIGTYPE_M3UA, ZAP_SIGTYPE_R2 } zap_signal_type_t; From 83e8b141b08e127d447fd5d284272e62a45326bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 18:58:36 +0000 Subject: [PATCH 1505/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@820 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ozmod_ss7_boost.c => ozmod_sangoma_boost.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/src/ozmod/ozmod_sangoma_boost/{ozmod_ss7_boost.c => ozmod_sangoma_boost.c} (100%) diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c similarity index 100% rename from libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c From 08f74c0bca0c5bcad0ef8698819384306580adbd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 18:58:36 +0000 Subject: [PATCH 1506/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@820 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ozmod_ss7_boost.c => ozmod_sangoma_boost.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/src/ozmod/ozmod_sangoma_boost/{ozmod_ss7_boost.c => ozmod_sangoma_boost.c} (100%) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_ss7_boost.c rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c From 70bcd8c1298fba46bb62b985a52b4854dfb06261 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 18:59:12 +0000 Subject: [PATCH 1507/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@821 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ss7_boost_client.c => sangoma_boost_client.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/src/ozmod/ozmod_sangoma_boost/{ss7_boost_client.c => sangoma_boost_client.c} (100%) diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c similarity index 100% rename from libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c From 2c1ecd07bc26a923b0ae61f94c6350f20391133c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 18:59:12 +0000 Subject: [PATCH 1508/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@821 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ss7_boost_client.c => sangoma_boost_client.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/src/ozmod/ozmod_sangoma_boost/{ss7_boost_client.c => sangoma_boost_client.c} (100%) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.c rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c From 72926d21c931da703ffad2230d32934642cacce4 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 18:59:31 +0000 Subject: [PATCH 1509/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@822 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ss7_boost_client.h => sangoma_boost_client.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/src/ozmod/ozmod_sangoma_boost/{ss7_boost_client.h => sangoma_boost_client.h} (100%) diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h similarity index 100% rename from libs/openzap/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h From 435dadc3f59913892970f18ae8bd1ffd1d9608bb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 18:59:31 +0000 Subject: [PATCH 1510/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@822 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../{ss7_boost_client.h => sangoma_boost_client.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/src/ozmod/ozmod_sangoma_boost/{ss7_boost_client.h => sangoma_boost_client.h} (100%) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/ss7_boost_client.h rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h From e3022ee6b62d7f8c8ad9fe5a07e592e6c2628d26 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 19:02:37 +0000 Subject: [PATCH 1511/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@823 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/{zap_ss7_boost.h => zap_sangoma_boost.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/openzap/src/ozmod/ozmod_sangoma_boost/{zap_ss7_boost.h => zap_sangoma_boost.h} (100%) diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h similarity index 100% rename from libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h rename to libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h From a80a7ea495eea081f8d43887946223856872eeb9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Sep 2009 19:02:37 +0000 Subject: [PATCH 1512/1766] rename git-svn-id: http://svn.openzap.org/svn/openzap/trunk@823 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/{zap_ss7_boost.h => zap_sangoma_boost.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/src/ozmod/ozmod_sangoma_boost/{zap_ss7_boost.h => zap_sangoma_boost.h} (100%) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_ss7_boost.h rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h From fd17b6ba5d4640a23c1cde913f6ac34d88efdf4a Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 2 Sep 2009 19:03:04 +0000 Subject: [PATCH 1513/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@824 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 300 +++++++++--------- .../sangoma_boost_client.c | 96 +++--- .../sangoma_boost_client.h | 62 ++-- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 20 +- 4 files changed, 239 insertions(+), 239 deletions(-) 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 index 33c4523abb..cf9bdc4014 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -32,8 +32,8 @@ */ #include "openzap.h" -#include "ss7_boost_client.h" -#include "zap_ss7_boost.h" +#include "sangoma_boost_client.h" +#include "zap_sangoma_boost.h" #ifdef HAVE_SYS_SELECT_H #include #endif @@ -49,34 +49,34 @@ typedef enum { SFLAG_SENT_FINAL_RESPONSE = (1 << 1) } sflag_t; -typedef uint16_t ss7_boost_request_id_t; +typedef uint16_t sangoma_boost_request_id_t; /** - * \brief SS7 boost request status + * \brief SANGOMA boost request status */ typedef enum { BST_FREE, BST_WAITING, BST_READY, BST_FAIL -} ss7_boost_request_status_t; +} sangoma_boost_request_status_t; /** - * \brief SS7 boost request structure + * \brief SANGOMA boost request structure */ typedef struct { - ss7_boost_request_status_t status; - ss7bc_short_event_t event; + sangoma_boost_request_status_t status; + sangomabc_short_event_t event; zap_span_t *span; zap_channel_t *zchan; -} ss7_boost_request_t; +} 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 ss7_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; +static sangoma_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; @@ -112,7 +112,7 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, * \param line Line number on request * \return NULL if not found, channel otherwise */ -static void __release_request_id(ss7_boost_request_id_t r, const char *func, int line) +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); @@ -121,7 +121,7 @@ static void __release_request_id(ss7_boost_request_id_t r, const char *func, int } #define release_request_id(r) __release_request_id(r, __FUNCTION__, __LINE__) -static ss7_boost_request_id_t last_req = 0; +static sangoma_boost_request_id_t last_req = 0; /** * \brief Gets the first available tank request ID @@ -129,9 +129,9 @@ static ss7_boost_request_id_t last_req = 0; * \param line Line number on request * \return 0 on failure, request ID on success */ -static ss7_boost_request_id_t __next_request_id(const char *func, int line) +static sangoma_boost_request_id_t __next_request_id(const char *func, int line) { - ss7_boost_request_id_t r = 0, i = 0; + sangoma_boost_request_id_t r = 0, i = 0; int found=0; zap_mutex_lock(request_mutex); @@ -170,11 +170,11 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) /** * \brief Finds the channel that triggered an event * \param span Span where to search the channel - * \param event SS7 event + * \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, ss7bc_short_event_t *event, int force) +static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *event, int force) { int i; zap_channel_t *zchan = NULL; @@ -219,7 +219,7 @@ static int check_congestion(int trunk_group) /** - * \brief Requests an ss7 boost channel on a span (outgoing call) + * \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 @@ -227,14 +227,14 @@ static int check_congestion(int trunk_group) * \param zchan Channel to initialise * \return Success or failure */ -static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) +static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) { - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; zap_status_t status = ZAP_FAIL; - ss7_boost_request_id_t r; - ss7bc_event_t event = {0}; + sangoma_boost_request_id_t r; + sangomabc_event_t event = {0}; int sanity = 5000; - ss7_boost_request_status_t st; + sangoma_boost_request_status_t st; char ani[128] = ""; char *gr = NULL; uint32_t count = 0; @@ -281,7 +281,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); + sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r); if (gr && *(gr+1)) { @@ -316,7 +316,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; - if (ss7bc_connection_write(&ss7_boost_data->mcon, &event) <= 0) { + 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; *zchan = NULL; @@ -352,7 +352,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } else if (st != BST_READY) { assert(r <= MAX_REQ_ID); nack_map[r] = 1; - ss7bc_exec_command(&ss7_boost_data->mcon, + sangomabc_exec_command(&sangoma_boost_data->mcon, 0, 0, r, @@ -364,11 +364,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } /** - * \brief Starts an ss7 boost channel (outgoing call) + * \brief Starts an sangoma boost channel (outgoing call) * \param zchan Channel to initiate call on * \return Success */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; @@ -377,10 +377,10 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) /** * \brief Handler for call start ack event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -413,7 +413,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, event->call_setup_id, @@ -426,10 +426,10 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t /** * \brief Handler for call done event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +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; @@ -466,10 +466,10 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s /** * \brief Handler for call start nack event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -502,7 +502,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s if (event->call_setup_id) { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, 0, 0, event->call_setup_id, @@ -535,7 +535,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s /* nobody else will do it so we have to do it ourselves */ - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, 0, @@ -546,10 +546,10 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s /** * \brief Handler for call stop event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -578,7 +578,7 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); } - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, 0, @@ -591,10 +591,10 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s /** * \brief Handler for call answer event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_answer(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -624,14 +624,14 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc /** * \brief Handler for call start event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_event_t *event) { zap_channel_t *zchan; - if (!(zchan = find_zchan(span, (ss7bc_short_event_t*)event, 0))) { + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { goto error; } @@ -659,7 +659,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, 0, @@ -670,14 +670,14 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ /** * \brief Handler for heartbeat event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_heartbeat(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { int err; - err = ss7bc_connection_writep(mcon, (ss7bc_event_t*)event); + 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)); @@ -690,45 +690,45 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *even /** * \brief Handler for restart ack event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param span Span where event was fired * \param event Event to handle */ -static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) +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 ss7 boost connection + * \param mcon sangoma boost connection * \param span Span where event was fired * \param event Event to handle */ -static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) +static void handle_restart(sangomabc_connection_t *mcon, zap_span_t *span, sangomabc_short_event_t *event) { - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon->rxseq_reset = 0; - zap_set_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); + zap_set_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + zap_set_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING); mcon->hb_elapsed = 0; } /** * \brief Handler for incoming digit event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param span Span where event was fired * \param event Event to handle */ -static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) +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, (ss7bc_short_event_t *)event, 1))) { + if (!(zchan = find_zchan(span, (sangomabc_short_event_t *)event, 1))) { zap_log(ZAP_LOG_ERROR, "Invalid channel\n"); return; } @@ -753,12 +753,12 @@ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss } /** - * \brief Handler for ss7 boost event + * \brief Handler for sangoma boost event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -772,7 +772,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: - handle_call_start(span, mcon, (ss7bc_event_t*)event); + handle_call_start(span, mcon, (sangomabc_event_t*)event); break; case SIGBOOST_EVENT_CALL_STOPPED: handle_call_stop(span, mcon, event); @@ -812,10 +812,10 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho //handle_gap_abate(event); break; case SIGBOOST_EVENT_DIGIT_IN: - handle_incoming_digit(mcon, span, (ss7bc_event_t*)event); + handle_incoming_digit(mcon, span, (sangomabc_event_t*)event); break; default: - zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", ss7bc_event_id_name(event->event_id)); + zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", sangomabc_event_id_name(event->event_id)); break; } @@ -833,8 +833,8 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho static __inline__ void state_advance(zap_channel_t *zchan) { - zap_ss7_boost_data_t *ss7_boost_data = zchan->span->signal_data; - ss7bc_connection_t *mcon = &ss7_boost_data->mcon; + 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; @@ -865,11 +865,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -882,7 +882,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_START; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -892,7 +892,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_RESTART: { sig.event_id = ZAP_SIGEVENT_RESTART; - status = ss7_boost_data->signal_cb(&sig); + status = sangoma_boost_data->signal_cb(&sig); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -902,12 +902,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = sangoma_boost_data->signal_cb(&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))) { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -915,7 +915,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 0); } - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -941,14 +941,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED, zchan->caller_data.hangup_cause); } else { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -961,10 +961,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_CANCEL: { sig.event_id = ZAP_SIGEVENT_STOP; - status = ss7_boost_data->signal_cb(&sig); + status = sangoma_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -975,10 +975,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; - status = ss7_boost_data->signal_cb(&sig); + status = sangoma_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -1007,7 +1007,7 @@ static __inline__ void init_outgoing_array(void) */ static __inline__ void check_state(zap_span_t *span) { - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + 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)) { @@ -1031,18 +1031,18 @@ static __inline__ void check_state(zap_span_t *span) } } - if (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING)) { + if (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING)) { if (zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) { - ss7bc_exec_command(&ss7_boost_data->mcon, + sangomabc_exec_command(&sangoma_boost_data->mcon, 0, 0, -1, SIGBOOST_EVENT_SYSTEM_RESTART_ACK, 0); - zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING); zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); - zap_clear_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); - ss7_boost_data->mcon.hb_elapsed = 0; + zap_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); + sangoma_boost_data->mcon.hb_elapsed = 0; init_outgoing_array(); } } @@ -1083,16 +1083,16 @@ static __inline__ void check_events(zap_span_t *span, int ms_timeout) } /** - * \brief Main thread function for ss7 boost span (monitor) + * \brief Main thread function for sangoma boost span (monitor) * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_ss7_events_run(zap_thread_t *me, void *obj) +static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING) && zap_running()) { + while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && zap_running()) { check_events(span,100); } @@ -1100,44 +1100,44 @@ static void *zap_ss7_events_run(zap_thread_t *me, void *obj) } /** - * \brief Main thread function for ss7 boost span (monitor) + * \brief Main thread function for sangoma boost span (monitor) * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) +static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - ss7bc_connection_t *mcon, *pcon; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + sangomabc_connection_t *mcon, *pcon; uint32_t ms = 10; //, too_long = 20000; - ss7_boost_data->pcon = ss7_boost_data->mcon; + sangoma_boost_data->pcon = sangoma_boost_data->mcon; - if (ss7bc_connection_open(&ss7_boost_data->mcon, - ss7_boost_data->mcon.cfg.local_ip, - ss7_boost_data->mcon.cfg.local_port, - ss7_boost_data->mcon.cfg.remote_ip, - ss7_boost_data->mcon.cfg.remote_port) < 0) { - zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", ss7_boost_data->mcon.socket, strerror(errno)); + 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_DEBUG, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); goto end; } - if (ss7bc_connection_open(&ss7_boost_data->pcon, - ss7_boost_data->pcon.cfg.local_ip, - ++ss7_boost_data->pcon.cfg.local_port, - ss7_boost_data->pcon.cfg.remote_ip, - ++ss7_boost_data->pcon.cfg.remote_port) < 0) { - zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", ss7_boost_data->pcon.socket, strerror(errno)); + 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_DEBUG, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); goto end; } - mcon = &ss7_boost_data->mcon; - pcon = &ss7_boost_data->pcon; + mcon = &sangoma_boost_data->mcon; + pcon = &sangoma_boost_data->pcon; init_outgoing_array(); - ss7bc_exec_commandp(pcon, + sangomabc_exec_commandp(pcon, 0, 0, -1, @@ -1145,14 +1145,14 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) 0); zap_set_flag(mcon, MSU_FLAG_DOWN); - while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { + while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; - ss7bc_event_t *event = NULL; + sangomabc_event_t *event = NULL; if (!zap_running()) { - ss7bc_exec_commandp(pcon, + sangomabc_exec_commandp(pcon, 0, 0, -1, @@ -1181,16 +1181,16 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) } if (FD_ISSET(pcon->socket, &rfds)) { - while ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); + 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 = ss7bc_connection_read(mcon, i))) { - parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); + if ((event = sangomabc_connection_read(mcon, i))) { + parse_sangoma_event(span, mcon, (sangomabc_short_event_t*)event); i++; } } @@ -1210,7 +1210,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); zap_set_flag(mcon, MSU_FLAG_DOWN); - ss7bc_exec_commandp(pcon, + sangomabc_exec_commandp(pcon, 0, 0, -1, @@ -1231,21 +1231,21 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) end: - ss7bc_connection_close(&ss7_boost_data->mcon); - ss7bc_connection_close(&ss7_boost_data->pcon); + sangomabc_connection_close(&sangoma_boost_data->mcon); + sangomabc_connection_close(&sangoma_boost_data->pcon); - zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); - zap_log(ZAP_LOG_DEBUG, "SS7_BOOST thread ended.\n"); + zap_log(ZAP_LOG_DEBUG, "SANGOMA_BOOST thread ended.\n"); return NULL; } /** - * \brief Loads ss7 boost signaling module + * \brief Loads sangoma boost signaling module * \param zio Openzap IO interface * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) +static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); @@ -1253,21 +1253,21 @@ static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) return ZAP_SUCCESS; } -static zap_status_t zap_ss7_boost_start(zap_span_t *span) +static zap_status_t zap_sangoma_boost_start(zap_span_t *span) { int err; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); - err=zap_thread_create_detached(zap_ss7_boost_run, span); + 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(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + 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_ss7_events_run, span); + err=zap_thread_create_detached(zap_sangoma_events_run, span); if (err) { - zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); } return err; } @@ -1372,15 +1372,15 @@ static zap_state_map_t boost_state_map = { }; /** - * \brief Initialises an ss7 boost span from configuration variables + * \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_ss7_boost_configure_span) +static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) { - zap_ss7_boost_data_t *ss7_boost_data = NULL; + 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; @@ -1419,20 +1419,20 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) return ZAP_FAIL; } - ss7_boost_data = malloc(sizeof(*ss7_boost_data)); - assert(ss7_boost_data); - memset(ss7_boost_data, 0, sizeof(*ss7_boost_data)); + sangoma_boost_data = malloc(sizeof(*sangoma_boost_data)); + assert(sangoma_boost_data); + memset(sangoma_boost_data, 0, sizeof(*sangoma_boost_data)); - zap_set_string(ss7_boost_data->mcon.cfg.local_ip, local_ip); - ss7_boost_data->mcon.cfg.local_port = local_port; - zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); - ss7_boost_data->mcon.cfg.remote_port = remote_port; - ss7_boost_data->signal_cb = sig_cb; - span->start = zap_ss7_boost_start; - span->signal_data = ss7_boost_data; - span->signal_type = ZAP_SIGTYPE_SS7BOOST; - span->outgoing_call = ss7_boost_outgoing_call; - span->channel_request = ss7_boost_channel_request; + 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; + sangoma_boost_data->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); @@ -1440,14 +1440,14 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) } /** - * \brief Openzap ss7 boost signaling module definition + * \brief Openzap sangoma boost signaling module definition */ zap_module_t zap_module = { - "ss7_boost", + "sangoma_boost", NULL, NULL, - zap_ss7_boost_init, - zap_ss7_boost_configure_span, + zap_sangoma_boost_init, + zap_sangoma_boost_configure_span, NULL }; 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 index b36bec1ca1..43537bc71a 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -36,7 +36,7 @@ #endif #include "openzap.h" -#include +#include #ifndef HAVE_GETHOSTBYNAME_R @@ -47,12 +47,12 @@ extern int gethostbyname_r (const char *__name, int *__h_errnop); #endif -struct ss7bc_map { +struct sangomabc_map { uint32_t event_id; const char *name; }; -static struct ss7bc_map ss7bc_table[] = { +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"}, @@ -71,13 +71,13 @@ static struct ss7bc_map ss7bc_table[] = { -static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *event, int priority, int dir, const char *file, const char *func, int line) +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]\n", dir ? "TX":"RX", - ss7bc_event_id_name(event->event_id), + sangomabc_event_id_name(event->event_id), event->event_id, event->span+1, event->chan+1, @@ -89,14 +89,14 @@ static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *even ); } -static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_short_event_t *event, int priority, int dir, const char *file, const char *func, int line) +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", - ss7bc_event_id_name(event->event_id), + sangomabc_event_id_name(event->event_id), event->event_id, event->span+1, event->chan+1, @@ -106,7 +106,7 @@ static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_short_event_ } -static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) +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; @@ -172,7 +172,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca return mcon->socket; } -int ss7bc_connection_close(ss7bc_connection_t *mcon) +int sangomabc_connection_close(sangomabc_connection_t *mcon) { if (mcon->socket > -1) { close(mcon->socket); @@ -189,19 +189,19 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) return 0; } -int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) +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 ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) +int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) { - ss7bc_short_event_t oevent; + sangomabc_short_event_t oevent; int retry = 5; - ss7bc_event_init(&oevent, cmd, chan, span); + sangomabc_event_init(&oevent, cmd, chan, span); oevent.release_cause = cause; if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { @@ -215,7 +215,7 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int oevent.call_setup_id = id; } - while (ss7bc_connection_write(mcon, (ss7bc_event_t*)&oevent) <= 0) { + 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; @@ -229,19 +229,19 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int } -int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause) +int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause) { - ss7bc_short_event_t oevent; + sangomabc_short_event_t oevent; int retry = 5; - ss7bc_event_init(&oevent, cmd, chan, span); + sangomabc_event_init(&oevent, cmd, chan, span); oevent.release_cause = cause; if (id >= 0) { oevent.call_setup_id = id; } - while (ss7bc_connection_writep(pcon, (ss7bc_event_t*)&oevent) <= 0) { + 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; @@ -254,7 +254,7 @@ int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, in return 0; } -ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line) +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; @@ -278,7 +278,7 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, } else if ((bytes >= MIN_SIZE_CALLSTART_MSG) && boost_full_event(mcon->event.event_id)) { msg_ok=1; - } else if (bytes == sizeof(ss7bc_short_event_t)) { + } else if (bytes == sizeof(sangomabc_short_event_t)) { msg_ok=1; } else { @@ -287,20 +287,20 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, if (msg_ok){ - if (ss7bc_test_flag(mcon, MSU_FLAG_DOWN)) { + 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", - ss7bc_event_id_name(mcon->event.event_id)); + sangomabc_event_id_name(mcon->event.event_id)); return NULL; } } if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); + sangomabc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)&mcon->event, 0, 0, file, func, line); } #if 0 @@ -338,7 +338,7 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, return NULL; } -ss7bc_event_t *__ss7bc_connection_readp(ss7bc_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) { unsigned int fromlen = sizeof(struct sockaddr_in); int bytes = 0; @@ -353,12 +353,12 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); } - if (bytes == sizeof(ss7bc_short_event_t)) { + if (bytes == sizeof(sangomabc_short_event_t)) { if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line); + sangomabc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 1, 0, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)&mcon->event, 1, 0, file, func, line); } return &mcon->event; @@ -373,7 +373,7 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, } -int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, 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 err; int event_size=MIN_SIZE_CALLSTART_MSG+event->isup_in_rdnis_size; @@ -385,21 +385,21 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } 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", ss7bc_event_id_name(event->event_id), event->span, event->chan); + 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(ss7bc_short_event_t); + event_size=sizeof(sangomabc_short_event_t); } - if (ss7bc_test_flag(mcon, MSU_FLAG_DOWN)) { + 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", - ss7bc_event_id_name(event->event_id)); + sangomabc_event_id_name(event->event_id)); return 0; } } @@ -424,19 +424,19 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon, event, 0, 1, file, func, line); + sangomabc_print_event_call(mcon, event, 0, 1, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 0, 1, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)event, 0, 1, file, func, line); } return err; } -int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_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) { int err; - int event_size=sizeof(ss7bc_event_t); + 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"); @@ -445,7 +445,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co } if (!boost_full_event(event->event_id)) { - event_size=sizeof(ss7bc_short_event_t); + event_size=sizeof(sangomabc_short_event_t); } zap_mutex_lock(mcon->mutex); @@ -459,18 +459,18 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon, event, 1, 1, file, func, line); + sangomabc_print_event_call(mcon, event, 1, 1, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 1, 1, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)event, 1, 1, file, func, line); } return err; } -void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id) +void sangomabc_call_init(sangomabc_event_t *event, const char *calling, const char *called, int setup_id) { - memset(event, 0, sizeof(ss7bc_event_t)); + memset(event, 0, sizeof(sangomabc_event_t)); event->event_id = SIGBOOST_EVENT_CALL_START; if (calling) { @@ -487,22 +487,22 @@ void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *call } -void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span) +void sangomabc_event_init(sangomabc_short_event_t *event, sangomabc_event_id_t event_id, int chan, int span) { - memset(event, 0, sizeof(ss7bc_short_event_t)); + memset(event, 0, sizeof(sangomabc_short_event_t)); event->event_id = event_id; event->chan = chan; event->span = span; } -const char *ss7bc_event_id_name(uint32_t event_id) +const char *sangomabc_event_id_name(uint32_t event_id) { unsigned int x; const char *ret = NULL; - for (x = 0 ; x < sizeof(ss7bc_table)/sizeof(struct ss7bc_map); x++) { - if (ss7bc_table[x].event_id == event_id) { - ret = ss7bc_table[x].name; + 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; } } 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 index 292f8dc556..5554cb1ff6 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -31,8 +31,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SS7BC_H -#define _SS7BC_H +#ifndef _SANGOMABC_H +#define _SANGOMABC_H #include #include @@ -53,46 +53,46 @@ #include #include -#define ss7bc_test_flag(p,flag) ({ \ +#define sangomabc_test_flag(p,flag) ({ \ ((p)->flags & (flag)); \ }) -#define ss7bc_set_flag(p,flag) do { \ +#define sangomabc_set_flag(p,flag) do { \ ((p)->flags |= (flag)); \ } while (0) -#define ss7bc_clear_flag(p,flag) do { \ +#define sangomabc_clear_flag(p,flag) do { \ ((p)->flags &= ~(flag)); \ } while (0) -#define ss7bc_copy_flags(dest,src,flagz) do { \ +#define sangomabc_copy_flags(dest,src,flagz) do { \ (dest)->flags &= ~(flagz); \ (dest)->flags |= ((src)->flags & (flagz)); \ } while (0) -typedef t_sigboost_callstart ss7bc_event_t; -typedef t_sigboost_short ss7bc_short_event_t; -typedef uint32_t ss7bc_event_id_t; +typedef t_sigboost_callstart sangomabc_event_t; +typedef t_sigboost_short sangomabc_short_event_t; +typedef uint32_t sangomabc_event_id_t; -typedef struct ss7bc_ip_cfg +typedef struct sangomabc_ip_cfg { char local_ip[25]; int local_port; char remote_ip[25]; int remote_port; -}ss7bc_ip_cfg_t; +}sangomabc_ip_cfg_t; typedef enum { MSU_FLAG_EVENT = (1 << 0), MSU_FLAG_DOWN = (1 << 1) -} ss7bc_flag_t; +} sangomabc_flag_t; -struct ss7bc_connection { +struct sangomabc_connection { zap_socket_t socket; struct sockaddr_in local_addr; struct sockaddr_in remote_addr; - ss7bc_event_t event; + sangomabc_event_t event; struct hostent remote_hp; struct hostent local_hp; unsigned int flags; @@ -102,11 +102,11 @@ struct ss7bc_connection { unsigned int rxseq; unsigned int txwindow; unsigned int rxseq_reset; - ss7bc_ip_cfg_t cfg; + sangomabc_ip_cfg_t cfg; uint32_t hb_elapsed; }; -typedef struct ss7bc_connection ss7bc_connection_t; +typedef struct sangomabc_connection sangomabc_connection_t; /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) @@ -117,21 +117,21 @@ static inline void sctp_no_nagle(int socket) #endif } -int ss7bc_connection_close(ss7bc_connection_t *mcon); -int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); -ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); -ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); -int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); -int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); -#define ss7bc_connection_write(_m,_e) __ss7bc_connection_write(_m, _e, __FILE__, __func__, __LINE__) -#define ss7bc_connection_writep(_m,_e) __ss7bc_connection_writep(_m, _e, __FILE__, __func__, __LINE__) -#define ss7bc_connection_read(_m,_e) __ss7bc_connection_read(_m, _e, __FILE__, __func__, __LINE__) -#define ss7bc_connection_readp(_m,_e) __ss7bc_connection_readp(_m, _e, __FILE__, __func__, __LINE__) -void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span); -void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); -const char *ss7bc_event_id_name(uint32_t event_id); -int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause); -int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); +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 sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); #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 index b3f3e416bf..3d82c6f5c0 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -31,22 +31,22 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_SS7_BOOST_H -#define ZAP_SS7_BOOST_H -#include "ss7_boost_client.h" +#ifndef ZAP_SANGOMA_BOOST_H +#define ZAP_SANGOMA_BOOST_H +#include "sangoma_boost_client.h" #include "openzap.h" typedef enum { - ZAP_SS7_BOOST_RUNNING = (1 << 0), - ZAP_SS7_BOOST_RESTARTING = (1 << 1) -} zap_ss7_boost_flag_t; + ZAP_SANGOMA_BOOST_RUNNING = (1 << 0), + ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1) +} zap_sangoma_boost_flag_t; -typedef struct zap_ss7_boost_data { - ss7bc_connection_t mcon; - ss7bc_connection_t pcon; +typedef struct zap_sangoma_boost_data { + sangomabc_connection_t mcon; + sangomabc_connection_t pcon; zio_signal_cb_t signal_cb; uint32_t flags; -} zap_ss7_boost_data_t; +} zap_sangoma_boost_data_t; #endif From fec13f56a5850ab933d8445467fc970497ec5a22 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 2 Sep 2009 19:03:04 +0000 Subject: [PATCH 1514/1766] up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@824 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 300 +++++++++--------- .../sangoma_boost_client.c | 96 +++--- .../sangoma_boost_client.h | 62 ++-- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 20 +- 4 files changed, 239 insertions(+), 239 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 33c4523abb..cf9bdc4014 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -32,8 +32,8 @@ */ #include "openzap.h" -#include "ss7_boost_client.h" -#include "zap_ss7_boost.h" +#include "sangoma_boost_client.h" +#include "zap_sangoma_boost.h" #ifdef HAVE_SYS_SELECT_H #include #endif @@ -49,34 +49,34 @@ typedef enum { SFLAG_SENT_FINAL_RESPONSE = (1 << 1) } sflag_t; -typedef uint16_t ss7_boost_request_id_t; +typedef uint16_t sangoma_boost_request_id_t; /** - * \brief SS7 boost request status + * \brief SANGOMA boost request status */ typedef enum { BST_FREE, BST_WAITING, BST_READY, BST_FAIL -} ss7_boost_request_status_t; +} sangoma_boost_request_status_t; /** - * \brief SS7 boost request structure + * \brief SANGOMA boost request structure */ typedef struct { - ss7_boost_request_status_t status; - ss7bc_short_event_t event; + sangoma_boost_request_status_t status; + sangomabc_short_event_t event; zap_span_t *span; zap_channel_t *zchan; -} ss7_boost_request_t; +} 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 ss7_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; +static sangoma_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; static zap_mutex_t *signal_mutex = NULL; @@ -112,7 +112,7 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, * \param line Line number on request * \return NULL if not found, channel otherwise */ -static void __release_request_id(ss7_boost_request_id_t r, const char *func, int line) +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); @@ -121,7 +121,7 @@ static void __release_request_id(ss7_boost_request_id_t r, const char *func, int } #define release_request_id(r) __release_request_id(r, __FUNCTION__, __LINE__) -static ss7_boost_request_id_t last_req = 0; +static sangoma_boost_request_id_t last_req = 0; /** * \brief Gets the first available tank request ID @@ -129,9 +129,9 @@ static ss7_boost_request_id_t last_req = 0; * \param line Line number on request * \return 0 on failure, request ID on success */ -static ss7_boost_request_id_t __next_request_id(const char *func, int line) +static sangoma_boost_request_id_t __next_request_id(const char *func, int line) { - ss7_boost_request_id_t r = 0, i = 0; + sangoma_boost_request_id_t r = 0, i = 0; int found=0; zap_mutex_lock(request_mutex); @@ -170,11 +170,11 @@ static ss7_boost_request_id_t __next_request_id(const char *func, int line) /** * \brief Finds the channel that triggered an event * \param span Span where to search the channel - * \param event SS7 event + * \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, ss7bc_short_event_t *event, int force) +static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *event, int force) { int i; zap_channel_t *zchan = NULL; @@ -219,7 +219,7 @@ static int check_congestion(int trunk_group) /** - * \brief Requests an ss7 boost channel on a span (outgoing call) + * \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 @@ -227,14 +227,14 @@ static int check_congestion(int trunk_group) * \param zchan Channel to initialise * \return Success or failure */ -static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) +static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) { - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; zap_status_t status = ZAP_FAIL; - ss7_boost_request_id_t r; - ss7bc_event_t event = {0}; + sangoma_boost_request_id_t r; + sangomabc_event_t event = {0}; int sanity = 5000; - ss7_boost_request_status_t st; + sangoma_boost_request_status_t st; char ani[128] = ""; char *gr = NULL; uint32_t count = 0; @@ -281,7 +281,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) return ZAP_FAIL; } - ss7bc_call_init(&event, caller_data->cid_num.digits, ani, r); + sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r); if (gr && *(gr+1)) { @@ -316,7 +316,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; - if (ss7bc_connection_write(&ss7_boost_data->mcon, &event) <= 0) { + 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; *zchan = NULL; @@ -352,7 +352,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } else if (st != BST_READY) { assert(r <= MAX_REQ_ID); nack_map[r] = 1; - ss7bc_exec_command(&ss7_boost_data->mcon, + sangomabc_exec_command(&sangoma_boost_data->mcon, 0, 0, r, @@ -364,11 +364,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(ss7_boost_channel_request) } /** - * \brief Starts an ss7 boost channel (outgoing call) + * \brief Starts an sangoma boost channel (outgoing call) * \param zchan Channel to initiate call on * \return Success */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) { zap_status_t status = ZAP_SUCCESS; @@ -377,10 +377,10 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(ss7_boost_outgoing_call) /** * \brief Handler for call start ack event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -413,7 +413,7 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, event->call_setup_id, @@ -426,10 +426,10 @@ static void handle_call_start_ack(ss7bc_connection_t *mcon, ss7bc_short_event_t /** * \brief Handler for call done event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +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; @@ -466,10 +466,10 @@ static void handle_call_done(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s /** * \brief Handler for call start nack event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -502,7 +502,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s if (event->call_setup_id) { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, 0, 0, event->call_setup_id, @@ -535,7 +535,7 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s /* nobody else will do it so we have to do it ourselves */ - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, 0, @@ -546,10 +546,10 @@ static void handle_call_start_nack(zap_span_t *span, ss7bc_connection_t *mcon, s /** * \brief Handler for call stop event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -578,7 +578,7 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); } - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, 0, @@ -591,10 +591,10 @@ static void handle_call_stop(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_s /** * \brief Handler for call answer event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_call_answer(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; @@ -624,14 +624,14 @@ static void handle_call_answer(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc /** * \brief Handler for call start event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_event_t *event) +static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_event_t *event) { zap_channel_t *zchan; - if (!(zchan = find_zchan(span, (ss7bc_short_event_t*)event, 0))) { + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { goto error; } @@ -659,7 +659,7 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, event->span, event->chan, 0, @@ -670,14 +670,14 @@ static void handle_call_start(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_ /** * \brief Handler for heartbeat event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static void handle_heartbeat(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { int err; - err = ss7bc_connection_writep(mcon, (ss7bc_event_t*)event); + 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)); @@ -690,45 +690,45 @@ static void handle_heartbeat(ss7bc_connection_t *mcon, ss7bc_short_event_t *even /** * \brief Handler for restart ack event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param span Span where event was fired * \param event Event to handle */ -static void handle_restart_ack(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) +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 ss7 boost connection + * \param mcon sangoma boost connection * \param span Span where event was fired * \param event Event to handle */ -static void handle_restart(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_short_event_t *event) +static void handle_restart(sangomabc_connection_t *mcon, zap_span_t *span, sangomabc_short_event_t *event) { - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon->rxseq_reset = 0; - zap_set_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); + zap_set_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + zap_set_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING); mcon->hb_elapsed = 0; } /** * \brief Handler for incoming digit event - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param span Span where event was fired * \param event Event to handle */ -static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss7bc_event_t *event) +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, (ss7bc_short_event_t *)event, 1))) { + if (!(zchan = find_zchan(span, (sangomabc_short_event_t *)event, 1))) { zap_log(ZAP_LOG_ERROR, "Invalid channel\n"); return; } @@ -753,12 +753,12 @@ static void handle_incoming_digit(ss7bc_connection_t *mcon, zap_span_t *span, ss } /** - * \brief Handler for ss7 boost event + * \brief Handler for sangoma boost event * \param span Span where event was fired - * \param mcon ss7 boost connection + * \param mcon sangoma boost connection * \param event Event to handle */ -static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_short_event_t *event) +static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_mutex_lock(signal_mutex); @@ -772,7 +772,7 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: - handle_call_start(span, mcon, (ss7bc_event_t*)event); + handle_call_start(span, mcon, (sangomabc_event_t*)event); break; case SIGBOOST_EVENT_CALL_STOPPED: handle_call_stop(span, mcon, event); @@ -812,10 +812,10 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho //handle_gap_abate(event); break; case SIGBOOST_EVENT_DIGIT_IN: - handle_incoming_digit(mcon, span, (ss7bc_event_t*)event); + handle_incoming_digit(mcon, span, (sangomabc_event_t*)event); break; default: - zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", ss7bc_event_id_name(event->event_id)); + zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", sangomabc_event_id_name(event->event_id)); break; } @@ -833,8 +833,8 @@ static int parse_ss7_event(zap_span_t *span, ss7bc_connection_t *mcon, ss7bc_sho static __inline__ void state_advance(zap_channel_t *zchan) { - zap_ss7_boost_data_t *ss7_boost_data = zchan->span->signal_data; - ss7bc_connection_t *mcon = &ss7_boost_data->mcon; + 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; @@ -865,11 +865,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -882,7 +882,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_START; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -892,7 +892,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_RESTART: { sig.event_id = ZAP_SIGEVENT_RESTART; - status = ss7_boost_data->signal_cb(&sig); + status = sangoma_boost_data->signal_cb(&sig); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); @@ -902,12 +902,12 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = ss7_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = sangoma_boost_data->signal_cb(&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))) { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -915,7 +915,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 0); } - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -941,14 +941,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED, zchan->caller_data.hangup_cause); } else { - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -961,10 +961,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_CANCEL: { sig.event_id = ZAP_SIGEVENT_STOP; - status = ss7_boost_data->signal_cb(&sig); + status = sangoma_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -975,10 +975,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; - status = ss7_boost_data->signal_cb(&sig); + status = sangoma_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - ss7bc_exec_command(mcon, + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, 0, @@ -1007,7 +1007,7 @@ static __inline__ void init_outgoing_array(void) */ static __inline__ void check_state(zap_span_t *span) { - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + 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)) { @@ -1031,18 +1031,18 @@ static __inline__ void check_state(zap_span_t *span) } } - if (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING)) { + if (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING)) { if (zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) { - ss7bc_exec_command(&ss7_boost_data->mcon, + sangomabc_exec_command(&sangoma_boost_data->mcon, 0, 0, -1, SIGBOOST_EVENT_SYSTEM_RESTART_ACK, 0); - zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RESTARTING); + zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RESTARTING); zap_clear_flag_locked(span, ZAP_SPAN_SUSPENDED); - zap_clear_flag((&ss7_boost_data->mcon), MSU_FLAG_DOWN); - ss7_boost_data->mcon.hb_elapsed = 0; + zap_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); + sangoma_boost_data->mcon.hb_elapsed = 0; init_outgoing_array(); } } @@ -1083,16 +1083,16 @@ static __inline__ void check_events(zap_span_t *span, int ms_timeout) } /** - * \brief Main thread function for ss7 boost span (monitor) + * \brief Main thread function for sangoma boost span (monitor) * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_ss7_events_run(zap_thread_t *me, void *obj) +static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING) && zap_running()) { + while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && zap_running()) { check_events(span,100); } @@ -1100,44 +1100,44 @@ static void *zap_ss7_events_run(zap_thread_t *me, void *obj) } /** - * \brief Main thread function for ss7 boost span (monitor) + * \brief Main thread function for sangoma boost span (monitor) * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) +static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) { zap_span_t *span = (zap_span_t *) obj; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - ss7bc_connection_t *mcon, *pcon; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + sangomabc_connection_t *mcon, *pcon; uint32_t ms = 10; //, too_long = 20000; - ss7_boost_data->pcon = ss7_boost_data->mcon; + sangoma_boost_data->pcon = sangoma_boost_data->mcon; - if (ss7bc_connection_open(&ss7_boost_data->mcon, - ss7_boost_data->mcon.cfg.local_ip, - ss7_boost_data->mcon.cfg.local_port, - ss7_boost_data->mcon.cfg.remote_ip, - ss7_boost_data->mcon.cfg.remote_port) < 0) { - zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", ss7_boost_data->mcon.socket, strerror(errno)); + 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_DEBUG, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); goto end; } - if (ss7bc_connection_open(&ss7_boost_data->pcon, - ss7_boost_data->pcon.cfg.local_ip, - ++ss7_boost_data->pcon.cfg.local_port, - ss7_boost_data->pcon.cfg.remote_ip, - ++ss7_boost_data->pcon.cfg.remote_port) < 0) { - zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", ss7_boost_data->pcon.socket, strerror(errno)); + 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_DEBUG, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); goto end; } - mcon = &ss7_boost_data->mcon; - pcon = &ss7_boost_data->pcon; + mcon = &sangoma_boost_data->mcon; + pcon = &sangoma_boost_data->pcon; init_outgoing_array(); - ss7bc_exec_commandp(pcon, + sangomabc_exec_commandp(pcon, 0, 0, -1, @@ -1145,14 +1145,14 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) 0); zap_set_flag(mcon, MSU_FLAG_DOWN); - while (zap_test_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING)) { + while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; - ss7bc_event_t *event = NULL; + sangomabc_event_t *event = NULL; if (!zap_running()) { - ss7bc_exec_commandp(pcon, + sangomabc_exec_commandp(pcon, 0, 0, -1, @@ -1181,16 +1181,16 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) } if (FD_ISSET(pcon->socket, &rfds)) { - while ((event = ss7bc_connection_readp(pcon, i))) { - parse_ss7_event(span, pcon, (ss7bc_short_event_t*)event); + 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 = ss7bc_connection_read(mcon, i))) { - parse_ss7_event(span, mcon, (ss7bc_short_event_t*)event); + if ((event = sangomabc_connection_read(mcon, i))) { + parse_sangoma_event(span, mcon, (sangomabc_short_event_t*)event); i++; } } @@ -1210,7 +1210,7 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); zap_set_flag(mcon, MSU_FLAG_DOWN); - ss7bc_exec_commandp(pcon, + sangomabc_exec_commandp(pcon, 0, 0, -1, @@ -1231,21 +1231,21 @@ static void *zap_ss7_boost_run(zap_thread_t *me, void *obj) end: - ss7bc_connection_close(&ss7_boost_data->mcon); - ss7bc_connection_close(&ss7_boost_data->pcon); + sangomabc_connection_close(&sangoma_boost_data->mcon); + sangomabc_connection_close(&sangoma_boost_data->pcon); - zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); - zap_log(ZAP_LOG_DEBUG, "SS7_BOOST thread ended.\n"); + zap_log(ZAP_LOG_DEBUG, "SANGOMA_BOOST thread ended.\n"); return NULL; } /** - * \brief Loads ss7 boost signaling module + * \brief Loads sangoma boost signaling module * \param zio Openzap IO interface * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) +static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); @@ -1253,21 +1253,21 @@ static ZIO_SIG_LOAD_FUNCTION(zap_ss7_boost_init) return ZAP_SUCCESS; } -static zap_status_t zap_ss7_boost_start(zap_span_t *span) +static zap_status_t zap_sangoma_boost_start(zap_span_t *span) { int err; - zap_ss7_boost_data_t *ss7_boost_data = span->signal_data; - zap_set_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); - err=zap_thread_create_detached(zap_ss7_boost_run, span); + 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(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + 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_ss7_events_run, span); + err=zap_thread_create_detached(zap_sangoma_events_run, span); if (err) { - zap_clear_flag(ss7_boost_data, ZAP_SS7_BOOST_RUNNING); + zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); } return err; } @@ -1372,15 +1372,15 @@ static zap_state_map_t boost_state_map = { }; /** - * \brief Initialises an ss7 boost span from configuration variables + * \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_ss7_boost_configure_span) +static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) { - zap_ss7_boost_data_t *ss7_boost_data = NULL; + 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; @@ -1419,20 +1419,20 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) return ZAP_FAIL; } - ss7_boost_data = malloc(sizeof(*ss7_boost_data)); - assert(ss7_boost_data); - memset(ss7_boost_data, 0, sizeof(*ss7_boost_data)); + sangoma_boost_data = malloc(sizeof(*sangoma_boost_data)); + assert(sangoma_boost_data); + memset(sangoma_boost_data, 0, sizeof(*sangoma_boost_data)); - zap_set_string(ss7_boost_data->mcon.cfg.local_ip, local_ip); - ss7_boost_data->mcon.cfg.local_port = local_port; - zap_set_string(ss7_boost_data->mcon.cfg.remote_ip, remote_ip); - ss7_boost_data->mcon.cfg.remote_port = remote_port; - ss7_boost_data->signal_cb = sig_cb; - span->start = zap_ss7_boost_start; - span->signal_data = ss7_boost_data; - span->signal_type = ZAP_SIGTYPE_SS7BOOST; - span->outgoing_call = ss7_boost_outgoing_call; - span->channel_request = ss7_boost_channel_request; + 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; + sangoma_boost_data->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); @@ -1440,14 +1440,14 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_ss7_boost_configure_span) } /** - * \brief Openzap ss7 boost signaling module definition + * \brief Openzap sangoma boost signaling module definition */ zap_module_t zap_module = { - "ss7_boost", + "sangoma_boost", NULL, NULL, - zap_ss7_boost_init, - zap_ss7_boost_configure_span, + zap_sangoma_boost_init, + zap_sangoma_boost_configure_span, NULL }; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index b36bec1ca1..43537bc71a 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -36,7 +36,7 @@ #endif #include "openzap.h" -#include +#include #ifndef HAVE_GETHOSTBYNAME_R @@ -47,12 +47,12 @@ extern int gethostbyname_r (const char *__name, int *__h_errnop); #endif -struct ss7bc_map { +struct sangomabc_map { uint32_t event_id; const char *name; }; -static struct ss7bc_map ss7bc_table[] = { +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"}, @@ -71,13 +71,13 @@ static struct ss7bc_map ss7bc_table[] = { -static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *event, int priority, int dir, const char *file, const char *func, int line) +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]\n", dir ? "TX":"RX", - ss7bc_event_id_name(event->event_id), + sangomabc_event_id_name(event->event_id), event->event_id, event->span+1, event->chan+1, @@ -89,14 +89,14 @@ static void ss7bc_print_event_call(ss7bc_connection_t *mcon, ss7bc_event_t *even ); } -static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_short_event_t *event, int priority, int dir, const char *file, const char *func, int line) +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", - ss7bc_event_id_name(event->event_id), + sangomabc_event_id_name(event->event_id), event->event_id, event->span+1, event->chan+1, @@ -106,7 +106,7 @@ static void ss7bc_print_event_short(ss7bc_connection_t *mcon, ss7bc_short_event_ } -static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) +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; @@ -172,7 +172,7 @@ static int create_conn_socket(ss7bc_connection_t *mcon, char *local_ip, int loca return mcon->socket; } -int ss7bc_connection_close(ss7bc_connection_t *mcon) +int sangomabc_connection_close(sangomabc_connection_t *mcon) { if (mcon->socket > -1) { close(mcon->socket); @@ -189,19 +189,19 @@ int ss7bc_connection_close(ss7bc_connection_t *mcon) return 0; } -int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) +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 ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) +int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) { - ss7bc_short_event_t oevent; + sangomabc_short_event_t oevent; int retry = 5; - ss7bc_event_init(&oevent, cmd, chan, span); + sangomabc_event_init(&oevent, cmd, chan, span); oevent.release_cause = cause; if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { @@ -215,7 +215,7 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int oevent.call_setup_id = id; } - while (ss7bc_connection_write(mcon, (ss7bc_event_t*)&oevent) <= 0) { + 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; @@ -229,19 +229,19 @@ int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int } -int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause) +int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause) { - ss7bc_short_event_t oevent; + sangomabc_short_event_t oevent; int retry = 5; - ss7bc_event_init(&oevent, cmd, chan, span); + sangomabc_event_init(&oevent, cmd, chan, span); oevent.release_cause = cause; if (id >= 0) { oevent.call_setup_id = id; } - while (ss7bc_connection_writep(pcon, (ss7bc_event_t*)&oevent) <= 0) { + 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; @@ -254,7 +254,7 @@ int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, in return 0; } -ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line) +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; @@ -278,7 +278,7 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, } else if ((bytes >= MIN_SIZE_CALLSTART_MSG) && boost_full_event(mcon->event.event_id)) { msg_ok=1; - } else if (bytes == sizeof(ss7bc_short_event_t)) { + } else if (bytes == sizeof(sangomabc_short_event_t)) { msg_ok=1; } else { @@ -287,20 +287,20 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, if (msg_ok){ - if (ss7bc_test_flag(mcon, MSU_FLAG_DOWN)) { + 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", - ss7bc_event_id_name(mcon->event.event_id)); + sangomabc_event_id_name(mcon->event.event_id)); return NULL; } } if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); + sangomabc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 0, 0, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)&mcon->event, 0, 0, file, func, line); } #if 0 @@ -338,7 +338,7 @@ ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, return NULL; } -ss7bc_event_t *__ss7bc_connection_readp(ss7bc_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) { unsigned int fromlen = sizeof(struct sockaddr_in); int bytes = 0; @@ -353,12 +353,12 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); } - if (bytes == sizeof(ss7bc_short_event_t)) { + if (bytes == sizeof(sangomabc_short_event_t)) { if (boost_full_event(mcon->event.event_id)) { - ss7bc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line); + sangomabc_print_event_call(mcon, &mcon->event, 1, 0, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)&mcon->event, 1, 0, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)&mcon->event, 1, 0, file, func, line); } return &mcon->event; @@ -373,7 +373,7 @@ ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, } -int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, 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 err; int event_size=MIN_SIZE_CALLSTART_MSG+event->isup_in_rdnis_size; @@ -385,21 +385,21 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } 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", ss7bc_event_id_name(event->event_id), event->span, event->chan); + 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(ss7bc_short_event_t); + event_size=sizeof(sangomabc_short_event_t); } - if (ss7bc_test_flag(mcon, MSU_FLAG_DOWN)) { + 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", - ss7bc_event_id_name(event->event_id)); + sangomabc_event_id_name(event->event_id)); return 0; } } @@ -424,19 +424,19 @@ int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, con } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon, event, 0, 1, file, func, line); + sangomabc_print_event_call(mcon, event, 0, 1, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 0, 1, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)event, 0, 1, file, func, line); } return err; } -int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_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) { int err; - int event_size=sizeof(ss7bc_event_t); + 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"); @@ -445,7 +445,7 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co } if (!boost_full_event(event->event_id)) { - event_size=sizeof(ss7bc_short_event_t); + event_size=sizeof(sangomabc_short_event_t); } zap_mutex_lock(mcon->mutex); @@ -459,18 +459,18 @@ int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, co } if (boost_full_event(event->event_id)) { - ss7bc_print_event_call(mcon, event, 1, 1, file, func, line); + sangomabc_print_event_call(mcon, event, 1, 1, file, func, line); } else { - ss7bc_print_event_short(mcon, (ss7bc_short_event_t*)event, 1, 1, file, func, line); + sangomabc_print_event_short(mcon, (sangomabc_short_event_t*)event, 1, 1, file, func, line); } return err; } -void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id) +void sangomabc_call_init(sangomabc_event_t *event, const char *calling, const char *called, int setup_id) { - memset(event, 0, sizeof(ss7bc_event_t)); + memset(event, 0, sizeof(sangomabc_event_t)); event->event_id = SIGBOOST_EVENT_CALL_START; if (calling) { @@ -487,22 +487,22 @@ void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *call } -void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span) +void sangomabc_event_init(sangomabc_short_event_t *event, sangomabc_event_id_t event_id, int chan, int span) { - memset(event, 0, sizeof(ss7bc_short_event_t)); + memset(event, 0, sizeof(sangomabc_short_event_t)); event->event_id = event_id; event->chan = chan; event->span = span; } -const char *ss7bc_event_id_name(uint32_t event_id) +const char *sangomabc_event_id_name(uint32_t event_id) { unsigned int x; const char *ret = NULL; - for (x = 0 ; x < sizeof(ss7bc_table)/sizeof(struct ss7bc_map); x++) { - if (ss7bc_table[x].event_id == event_id) { - ret = ss7bc_table[x].name; + 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; } } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index 292f8dc556..5554cb1ff6 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -31,8 +31,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SS7BC_H -#define _SS7BC_H +#ifndef _SANGOMABC_H +#define _SANGOMABC_H #include #include @@ -53,46 +53,46 @@ #include #include -#define ss7bc_test_flag(p,flag) ({ \ +#define sangomabc_test_flag(p,flag) ({ \ ((p)->flags & (flag)); \ }) -#define ss7bc_set_flag(p,flag) do { \ +#define sangomabc_set_flag(p,flag) do { \ ((p)->flags |= (flag)); \ } while (0) -#define ss7bc_clear_flag(p,flag) do { \ +#define sangomabc_clear_flag(p,flag) do { \ ((p)->flags &= ~(flag)); \ } while (0) -#define ss7bc_copy_flags(dest,src,flagz) do { \ +#define sangomabc_copy_flags(dest,src,flagz) do { \ (dest)->flags &= ~(flagz); \ (dest)->flags |= ((src)->flags & (flagz)); \ } while (0) -typedef t_sigboost_callstart ss7bc_event_t; -typedef t_sigboost_short ss7bc_short_event_t; -typedef uint32_t ss7bc_event_id_t; +typedef t_sigboost_callstart sangomabc_event_t; +typedef t_sigboost_short sangomabc_short_event_t; +typedef uint32_t sangomabc_event_id_t; -typedef struct ss7bc_ip_cfg +typedef struct sangomabc_ip_cfg { char local_ip[25]; int local_port; char remote_ip[25]; int remote_port; -}ss7bc_ip_cfg_t; +}sangomabc_ip_cfg_t; typedef enum { MSU_FLAG_EVENT = (1 << 0), MSU_FLAG_DOWN = (1 << 1) -} ss7bc_flag_t; +} sangomabc_flag_t; -struct ss7bc_connection { +struct sangomabc_connection { zap_socket_t socket; struct sockaddr_in local_addr; struct sockaddr_in remote_addr; - ss7bc_event_t event; + sangomabc_event_t event; struct hostent remote_hp; struct hostent local_hp; unsigned int flags; @@ -102,11 +102,11 @@ struct ss7bc_connection { unsigned int rxseq; unsigned int txwindow; unsigned int rxseq_reset; - ss7bc_ip_cfg_t cfg; + sangomabc_ip_cfg_t cfg; uint32_t hb_elapsed; }; -typedef struct ss7bc_connection ss7bc_connection_t; +typedef struct sangomabc_connection sangomabc_connection_t; /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) @@ -117,21 +117,21 @@ static inline void sctp_no_nagle(int socket) #endif } -int ss7bc_connection_close(ss7bc_connection_t *mcon); -int ss7bc_connection_open(ss7bc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port); -ss7bc_event_t *__ss7bc_connection_read(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); -ss7bc_event_t *__ss7bc_connection_readp(ss7bc_connection_t *mcon, int iteration, const char *file, const char *func, int line); -int __ss7bc_connection_write(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); -int __ss7bc_connection_writep(ss7bc_connection_t *mcon, ss7bc_event_t *event, const char *file, const char *func, int line); -#define ss7bc_connection_write(_m,_e) __ss7bc_connection_write(_m, _e, __FILE__, __func__, __LINE__) -#define ss7bc_connection_writep(_m,_e) __ss7bc_connection_writep(_m, _e, __FILE__, __func__, __LINE__) -#define ss7bc_connection_read(_m,_e) __ss7bc_connection_read(_m, _e, __FILE__, __func__, __LINE__) -#define ss7bc_connection_readp(_m,_e) __ss7bc_connection_readp(_m, _e, __FILE__, __func__, __LINE__) -void ss7bc_event_init(ss7bc_short_event_t *event, ss7bc_event_id_t event_id, int chan, int span); -void ss7bc_call_init(ss7bc_event_t *event, const char *calling, const char *called, int setup_id); -const char *ss7bc_event_id_name(uint32_t event_id); -int ss7bc_exec_command(ss7bc_connection_t *mcon, int span, int chan, int id, int cmd, int cause); -int ss7bc_exec_commandp(ss7bc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); +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 sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); #endif diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h index b3f3e416bf..3d82c6f5c0 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -31,22 +31,22 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_SS7_BOOST_H -#define ZAP_SS7_BOOST_H -#include "ss7_boost_client.h" +#ifndef ZAP_SANGOMA_BOOST_H +#define ZAP_SANGOMA_BOOST_H +#include "sangoma_boost_client.h" #include "openzap.h" typedef enum { - ZAP_SS7_BOOST_RUNNING = (1 << 0), - ZAP_SS7_BOOST_RESTARTING = (1 << 1) -} zap_ss7_boost_flag_t; + ZAP_SANGOMA_BOOST_RUNNING = (1 << 0), + ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1) +} zap_sangoma_boost_flag_t; -typedef struct zap_ss7_boost_data { - ss7bc_connection_t mcon; - ss7bc_connection_t pcon; +typedef struct zap_sangoma_boost_data { + sangomabc_connection_t mcon; + sangomabc_connection_t pcon; zio_signal_cb_t signal_cb; uint32_t flags; -} zap_ss7_boost_data_t; +} zap_sangoma_boost_data_t; #endif From 0fcad9c945f970d1b35f918129a8c1f11313f202 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 4 Sep 2009 20:28:12 +0000 Subject: [PATCH 1515/1766] fix for trunkgroup not specified on outgoing calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@825 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 ++ 1 file changed, 2 insertions(+) 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 index cf9bdc4014..2b502ba6cd 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -282,6 +282,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } 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)) { From 07cd03daace760694f4f1522efbb50db8133d6cb Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 4 Sep 2009 20:28:12 +0000 Subject: [PATCH 1516/1766] fix for trunkgroup not specified on outgoing calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@825 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index cf9bdc4014..2b502ba6cd 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -282,6 +282,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } 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)) { From 77961a72a57d45ad271939cad74762fedab9b4e5 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 6 Sep 2009 05:28:26 +0000 Subject: [PATCH 1517/1766] enable RBS events when CAS signaling is configured git-svn-id: http://svn.openzap.org/svn/openzap/trunk@826 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index afabfb0a0f..3ac980f4b4 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -300,6 +300,17 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, /* 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 } @@ -1093,5 +1104,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 */ From bcd0c286a1e9adeeeb7c288b9812465f3f0ede58 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 6 Sep 2009 05:28:26 +0000 Subject: [PATCH 1518/1766] enable RBS events when CAS signaling is configured git-svn-id: http://svn.openzap.org/svn/openzap/trunk@826 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index afabfb0a0f..3ac980f4b4 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -300,6 +300,17 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, /* 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 } @@ -1093,5 +1104,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 */ From fa222d0dd04aed3fae5c8fa51149f91abd1a9984 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 6 Sep 2009 14:07:06 +0000 Subject: [PATCH 1519/1766] Print error message if session for a channel could not be found git-svn-id: http://svn.openzap.org/svn/openzap/trunk@827 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index de32b348ce..868109d76e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1649,7 +1649,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_START: { zap_tone_type_t tt = ZAP_TONE_DTMF; - + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } @@ -1659,7 +1659,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) break; case ZAP_SIGEVENT_STOP: case ZAP_SIGEVENT_RESTART: - { + { while((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); @@ -1678,6 +1678,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: @@ -1686,6 +1689,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); } } break; @@ -1695,6 +1701,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); } } break; @@ -1714,7 +1723,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch_status_t status = SWITCH_STATUS_FALSE; - + switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: case ZAP_CHAN_TYPE_EM: From 1e7c5247483902e637542beb865f5da5f0e446ac Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 6 Sep 2009 14:07:06 +0000 Subject: [PATCH 1520/1766] Print error message if session for a channel could not be found git-svn-id: http://svn.openzap.org/svn/openzap/trunk@827 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index de32b348ce..868109d76e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1649,7 +1649,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_START: { zap_tone_type_t tt = ZAP_TONE_DTMF; - + if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } @@ -1659,7 +1659,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) break; case ZAP_SIGEVENT_STOP: case ZAP_SIGEVENT_RESTART: - { + { while((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); @@ -1678,6 +1678,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); } switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: @@ -1686,6 +1689,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); } } break; @@ -1695,6 +1701,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id); } } break; @@ -1714,7 +1723,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch_status_t status = SWITCH_STATUS_FALSE; - + switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: case ZAP_CHAN_TYPE_EM: From 49ff63b75d7f0e2be751467c5e38169d01d6ef8f Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 6 Sep 2009 14:43:58 +0000 Subject: [PATCH 1521/1766] Extend session not found message with UUID git-svn-id: http://svn.openzap.org/svn/openzap/trunk@828 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 868109d76e..02c1eebad9 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -151,6 +151,17 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in return session; } +static const char *zap_channel_get_uuid(zap_channel_t *channel, int32_t id) +{ + if (id > ZAP_MAX_TOKENS) { + return NULL; + } + + if (!switch_strlen_zero(channel->tokens[id])) { + return channel->tokens[id]; + } + return NULL; +} static void stop_hold(switch_core_session_t *session_a, const char *uuid) { @@ -1679,8 +1690,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) } switch_core_session_rwunlock(session); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: @@ -1690,8 +1703,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) switch_channel_mark_pre_answered(channel); switch_core_session_rwunlock(session); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } break; @@ -1702,8 +1717,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } break; From 686f2e2bc5033093f097999d9e646b2fffdec275 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Sun, 6 Sep 2009 14:43:58 +0000 Subject: [PATCH 1522/1766] Extend session not found message with UUID git-svn-id: http://svn.openzap.org/svn/openzap/trunk@828 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 868109d76e..02c1eebad9 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -151,6 +151,17 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in return session; } +static const char *zap_channel_get_uuid(zap_channel_t *channel, int32_t id) +{ + if (id > ZAP_MAX_TOKENS) { + return NULL; + } + + if (!switch_strlen_zero(channel->tokens[id])) { + return channel->tokens[id]; + } + return NULL; +} static void stop_hold(switch_core_session_t *session_a, const char *uuid) { @@ -1679,8 +1690,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) } switch_core_session_rwunlock(session); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } case ZAP_SIGEVENT_PROGRESS_MEDIA: @@ -1690,8 +1703,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) switch_channel_mark_pre_answered(channel); switch_core_session_rwunlock(session); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } break; @@ -1702,8 +1717,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", + sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } break; From 378a339a406b4631a60976036a5136524847a384 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 8 Sep 2009 16:14:57 +0000 Subject: [PATCH 1523/1766] display type of socket created git-svn-id: http://svn.openzap.org/svn/openzap/trunk@829 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 index 43537bc71a..224218c6f2 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -116,14 +116,15 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int 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 - 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; From 1490096bd3724fb2c84e5d3c62b0e91c4faf3fbd Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 8 Sep 2009 16:14:57 +0000 Subject: [PATCH 1524/1766] display type of socket created git-svn-id: http://svn.openzap.org/svn/openzap/trunk@829 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 43537bc71a..224218c6f2 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -116,14 +116,15 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int 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 - 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; From cd26200c6dbb9fcdfd254c18678242b94601d27d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 9 Sep 2009 19:32:20 +0000 Subject: [PATCH 1525/1766] revert git-svn-id: http://svn.openzap.org/svn/openzap/trunk@830 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 3ac980f4b4..e6b26852bb 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -984,12 +984,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = ZAP_OOB_NOOP; //zap_log(ZAP_LOG_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); - 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_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); + //zap_clear_flag_locked(zchan, ZAP_CHANNEL_MUTE); zap_channel_queue_dtmf(zchan, tmp_dtmf); } } From 20266e8c1f228979d97799824fefbd1fcb82a7af Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 9 Sep 2009 19:32:20 +0000 Subject: [PATCH 1526/1766] revert git-svn-id: http://svn.openzap.org/svn/openzap/trunk@830 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 3ac980f4b4..e6b26852bb 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -984,12 +984,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = ZAP_OOB_NOOP; //zap_log(ZAP_LOG_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); - 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_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); + //zap_clear_flag_locked(zchan, ZAP_CHANNEL_MUTE); zap_channel_queue_dtmf(zchan, tmp_dtmf); } } From 098991a58ef39758d251a7454c5bb7b662d4087a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 Sep 2009 14:26:31 +0000 Subject: [PATCH 1527/1766] add openzap_pre_buffer_size= to prebuffer audio and cut out residual dtmf tones git-svn-id: http://svn.openzap.org/svn/openzap/trunk@831 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 29 ++++++- libs/openzap/src/include/openzap.h | 3 + libs/openzap/src/include/zap_types.h | 1 + .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 19 +++-- libs/openzap/src/zap_io.c | 84 +++++++++++++++++-- 5 files changed, 125 insertions(+), 11 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 02c1eebad9..ddefd6e7fd 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -934,10 +934,30 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s { private_t *tech_pvt; switch_status_t status; - + switch_channel_t *channel; + const char *var; + tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_ANSWER: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if ((var = switch_channel_get_variable(channel, "openzap_pre_buffer_size"))) { + int tmp = atoi(var); + if (tmp > -1) { + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); + } + } + } + break; + default: + break; + } + switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: case ZAP_CHAN_TYPE_EM: @@ -1119,6 +1139,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; } + if ((var = switch_event_get_header(var_event, "openzap_pre_buffer_size"))) { + int tmp = atoi(var); + if (tmp > -1) { + zap_channel_command(zchan, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); + } + } + zap_channel_clear_vars(zchan); for (h = var_event->headers; h; h = h->next) { if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 6b0c703f23..ee09acc2fb 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -503,6 +503,7 @@ struct zap_channel { uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; zap_buffer_t *gen_dtmf_buffer; + zap_buffer_t *pre_buffer; zap_buffer_t *digit_buffer; zap_buffer_t *fsk_buffer; uint32_t dtmf_on; @@ -529,6 +530,7 @@ struct zap_channel { struct zap_io_interface *zio; zap_hash_t *variable_hash; unsigned char rx_cas_bits; + uint32_t pre_buffer_size; }; @@ -657,6 +659,7 @@ OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); +OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor); OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name); diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index d745a72f46..2db87513a0 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -283,6 +283,7 @@ typedef enum { ZAP_COMMAND_FLUSH_TX_BUFFERS, ZAP_COMMAND_FLUSH_RX_BUFFERS, ZAP_COMMAND_FLUSH_BUFFERS, + ZAP_COMMAND_SET_PRE_BUFFER_SIZE, ZAP_COMMAND_COUNT } zap_command_t; diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e6b26852bb..a7f54595f2 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -323,7 +323,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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); @@ -557,6 +556,16 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) } } break; + case ZAP_COMMAND_ENABLE_ECHOCANCEL: + { + //code me + } + break; + case ZAP_COMMAND_DISABLE_ECHOCANCEL: + { + //code me + } + break; case ZAP_COMMAND_SET_INTERVAL: { err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT); @@ -984,12 +993,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = ZAP_OOB_NOOP; //zap_log(ZAP_LOG_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); - //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_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); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_MUTE); zap_channel_queue_dtmf(zchan, tmp_dtmf); } } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 7d2ea3b094..98df71f723 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -245,6 +245,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_sleep(500); } + zap_buffer_destroy(&zchan->pre_buffer); zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); @@ -986,7 +987,10 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && - check->state == ZAP_CHANNEL_STATE_DOWN + check->state == ZAP_CHANNEL_STATE_DOWN && + check->type != ZAP_CHAN_TYPE_DQ921 && + check->type != ZAP_CHAN_TYPE_DQ931 + ) { if (span && span->channel_request) { @@ -1195,6 +1199,8 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zap_buffer_destroy(&zchan->pre_buffer); + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); @@ -1457,6 +1463,27 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t } } } + + case ZAP_COMMAND_SET_PRE_BUFFER_SIZE: + { + int val = ZAP_COMMAND_OBJ_INT; + + if (val < 0) { + val = 0; + } + + zchan->pre_buffer_size = val * 8; + + if (!zchan->pre_buffer_size) { + zap_buffer_destroy(&zchan->pre_buffer); + } else if (!zchan->pre_buffer) { + zap_buffer_create(&zchan->pre_buffer, 1024, zchan->pre_buffer_size, 0); + } + + GOTO_STATUS(done, ZAP_SUCCESS); + + } + break; case ZAP_COMMAND_GET_DTMF_ON_PERIOD: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { @@ -1516,6 +1543,13 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t } } break; + + case ZAP_COMMAND_DISABLE_ECHOCANCEL: + { + zap_buffer_destroy(&zchan->pre_buffer); + zchan->pre_buffer_size = 0; + } + break; default: break; } @@ -1737,6 +1771,10 @@ OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char assert(zchan != NULL); + if (zchan->pre_buffer) { + zap_buffer_zero(zchan->pre_buffer); + } + zap_mutex_lock(zchan->mutex); inuse = zap_buffer_inuse(zchan->digit_buffer); @@ -1779,6 +1817,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) { zap_buffer_t *buffer = NULL; zap_size_t dblen = 0; + int wrote = 0; if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { char digits[128] = ""; @@ -1800,7 +1839,6 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } for (; *cur; cur++) { - int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); x++; @@ -1810,7 +1848,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } } - zchan->skip_read_frames = 200 * x; + zchan->skip_read_frames = wrote / (1000 / zchan->effective_interval); } } @@ -1855,6 +1893,28 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } +OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor) +{ + int16_t x; + uint32_t i; + int sum_rnd = 0; + int16_t rnd2 = (int16_t) zap_current_time_in_ms * (int16_t) (intptr_t) data; + + assert(divisor); + + for (i = 0; i < samples; i++, sum_rnd = 0) { + for (x = 0; x < 6; x++) { + rnd2 = rnd2 * 31821U + 13849U; + sum_rnd += rnd2 ; + } + //switch_normalize_to_16bit(sum_rnd); + *data = (int16_t) ((int16_t) sum_rnd / (int) divisor); + + data++; + } +} + + OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { @@ -2048,11 +2108,25 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ } if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { - memset(data, 0, *datalen); + + if (zchan->pre_buffer && zap_buffer_inuse(zchan->pre_buffer)) { + zap_buffer_zero(zchan->pre_buffer); + } + + memset(data, 255, *datalen); + if (zchan->skip_read_frames > 0) { zchan->skip_read_frames--; } - } + } else if (zchan->pre_buffer_size) { + zap_buffer_write(zchan->pre_buffer, data, *datalen); + if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { + zap_buffer_read(zchan->pre_buffer, data, *datalen); + } else { + memset(data, 255, *datalen); + } + } + return status; } From 080436b856512843301f9ad11187aef4476bc5a6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 Sep 2009 14:26:31 +0000 Subject: [PATCH 1528/1766] add openzap_pre_buffer_size= to prebuffer audio and cut out residual dtmf tones git-svn-id: http://svn.openzap.org/svn/openzap/trunk@831 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 29 ++++++- libs/freetdm/src/include/openzap.h | 3 + libs/freetdm/src/include/zap_types.h | 1 + .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 19 +++-- libs/freetdm/src/zap_io.c | 84 +++++++++++++++++-- 5 files changed, 125 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 02c1eebad9..ddefd6e7fd 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -934,10 +934,30 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s { private_t *tech_pvt; switch_status_t status; - + switch_channel_t *channel; + const char *var; + tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_ANSWER: + if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { + if ((var = switch_channel_get_variable(channel, "openzap_pre_buffer_size"))) { + int tmp = atoi(var); + if (tmp > -1) { + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); + } + } + } + break; + default: + break; + } + switch (tech_pvt->zchan->type) { case ZAP_CHAN_TYPE_FXS: case ZAP_CHAN_TYPE_EM: @@ -1119,6 +1139,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; } + if ((var = switch_event_get_header(var_event, "openzap_pre_buffer_size"))) { + int tmp = atoi(var); + if (tmp > -1) { + zap_channel_command(zchan, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); + } + } + zap_channel_clear_vars(zchan); for (h = var_event->headers; h; h = h->next) { if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 6b0c703f23..ee09acc2fb 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -503,6 +503,7 @@ struct zap_channel { uint32_t skip_read_frames; zap_buffer_t *dtmf_buffer; zap_buffer_t *gen_dtmf_buffer; + zap_buffer_t *pre_buffer; zap_buffer_t *digit_buffer; zap_buffer_t *fsk_buffer; uint32_t dtmf_on; @@ -529,6 +530,7 @@ struct zap_channel { struct zap_io_interface *zio; zap_hash_t *variable_hash; unsigned char rx_cas_bits; + uint32_t pre_buffer_size; }; @@ -657,6 +659,7 @@ OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); +OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor); OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index d745a72f46..2db87513a0 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -283,6 +283,7 @@ typedef enum { ZAP_COMMAND_FLUSH_TX_BUFFERS, ZAP_COMMAND_FLUSH_RX_BUFFERS, ZAP_COMMAND_FLUSH_BUFFERS, + ZAP_COMMAND_SET_PRE_BUFFER_SIZE, ZAP_COMMAND_COUNT } zap_command_t; diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index e6b26852bb..a7f54595f2 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -323,7 +323,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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); @@ -557,6 +556,16 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) } } break; + case ZAP_COMMAND_ENABLE_ECHOCANCEL: + { + //code me + } + break; + case ZAP_COMMAND_DISABLE_ECHOCANCEL: + { + //code me + } + break; case ZAP_COMMAND_SET_INTERVAL: { err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT); @@ -984,12 +993,12 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = ZAP_OOB_NOOP; //zap_log(ZAP_LOG_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); - //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_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); + zap_clear_flag_locked(zchan, ZAP_CHANNEL_MUTE); zap_channel_queue_dtmf(zchan, tmp_dtmf); } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 7d2ea3b094..98df71f723 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -245,6 +245,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_sleep(500); } + zap_buffer_destroy(&zchan->pre_buffer); zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); @@ -986,7 +987,10 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_INUSE) && !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && - check->state == ZAP_CHANNEL_STATE_DOWN + check->state == ZAP_CHANNEL_STATE_DOWN && + check->type != ZAP_CHAN_TYPE_DQ921 && + check->type != ZAP_CHAN_TYPE_DQ931 + ) { if (span && span->channel_request) { @@ -1195,6 +1199,8 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zap_buffer_destroy(&zchan->pre_buffer); + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); @@ -1457,6 +1463,27 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t } } } + + case ZAP_COMMAND_SET_PRE_BUFFER_SIZE: + { + int val = ZAP_COMMAND_OBJ_INT; + + if (val < 0) { + val = 0; + } + + zchan->pre_buffer_size = val * 8; + + if (!zchan->pre_buffer_size) { + zap_buffer_destroy(&zchan->pre_buffer); + } else if (!zchan->pre_buffer) { + zap_buffer_create(&zchan->pre_buffer, 1024, zchan->pre_buffer_size, 0); + } + + GOTO_STATUS(done, ZAP_SUCCESS); + + } + break; case ZAP_COMMAND_GET_DTMF_ON_PERIOD: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { @@ -1516,6 +1543,13 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t } } break; + + case ZAP_COMMAND_DISABLE_ECHOCANCEL: + { + zap_buffer_destroy(&zchan->pre_buffer); + zchan->pre_buffer_size = 0; + } + break; default: break; } @@ -1737,6 +1771,10 @@ OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char assert(zchan != NULL); + if (zchan->pre_buffer) { + zap_buffer_zero(zchan->pre_buffer); + } + zap_mutex_lock(zchan->mutex); inuse = zap_buffer_inuse(zchan->digit_buffer); @@ -1779,6 +1817,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) { zap_buffer_t *buffer = NULL; zap_size_t dblen = 0; + int wrote = 0; if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { char digits[128] = ""; @@ -1800,7 +1839,6 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } for (; *cur; cur++) { - int wrote = 0; if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); x++; @@ -1810,7 +1848,7 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } } - zchan->skip_read_frames = 200 * x; + zchan->skip_read_frames = wrote / (1000 / zchan->effective_interval); } } @@ -1855,6 +1893,28 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) } +OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor) +{ + int16_t x; + uint32_t i; + int sum_rnd = 0; + int16_t rnd2 = (int16_t) zap_current_time_in_ms * (int16_t) (intptr_t) data; + + assert(divisor); + + for (i = 0; i < samples; i++, sum_rnd = 0) { + for (x = 0; x < 6; x++) { + rnd2 = rnd2 * 31821U + 13849U; + sum_rnd += rnd2 ; + } + //switch_normalize_to_16bit(sum_rnd); + *data = (int16_t) ((int16_t) sum_rnd / (int) divisor); + + data++; + } +} + + OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) { @@ -2048,11 +2108,25 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ } if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { - memset(data, 0, *datalen); + + if (zchan->pre_buffer && zap_buffer_inuse(zchan->pre_buffer)) { + zap_buffer_zero(zchan->pre_buffer); + } + + memset(data, 255, *datalen); + if (zchan->skip_read_frames > 0) { zchan->skip_read_frames--; } - } + } else if (zchan->pre_buffer_size) { + zap_buffer_write(zchan->pre_buffer, data, *datalen); + if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { + zap_buffer_read(zchan->pre_buffer, data, *datalen); + } else { + memset(data, 255, *datalen); + } + } + return status; } From 6c9f1010750f89388ba44245a63c1c1cd597fda1 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 14 Sep 2009 21:19:07 +0000 Subject: [PATCH 1529/1766] improve error handling in tech_init git-svn-id: http://svn.openzap.org/svn/openzap/trunk@832 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ddefd6e7fd..cb4e8fbae2 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -304,8 +304,15 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses switch_core_session_set_private(session, tech_pvt); tech_pvt->session = session; - zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); - zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec); + if (ZAP_SUCCESS != zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to retrieve channel interval.\n"); + return SWITCH_STATUS_GENERR; + } + + if (ZAP_SUCCESS != zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to retrieve channel codec.\n"); + return SWITCH_STATUS_GENERR; + } switch(codec) { case ZAP_CODEC_ULAW: @@ -324,7 +331,10 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses } break; default: - abort(); + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid codec value retrieved from channel, codec value: %d\n", codec); + return SWITCH_STATUS_GENERR; + } } @@ -2902,5 +2912,5 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 */ From b6590855ffa3ded9e64c306a731fce31c3e262c2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 14 Sep 2009 21:19:07 +0000 Subject: [PATCH 1530/1766] improve error handling in tech_init git-svn-id: http://svn.openzap.org/svn/openzap/trunk@832 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ddefd6e7fd..cb4e8fbae2 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -304,8 +304,15 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses switch_core_session_set_private(session, tech_pvt); tech_pvt->session = session; - zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); - zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec); + if (ZAP_SUCCESS != zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to retrieve channel interval.\n"); + return SWITCH_STATUS_GENERR; + } + + if (ZAP_SUCCESS != zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to retrieve channel codec.\n"); + return SWITCH_STATUS_GENERR; + } switch(codec) { case ZAP_CODEC_ULAW: @@ -324,7 +331,10 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses } break; default: - abort(); + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid codec value retrieved from channel, codec value: %d\n", codec); + return SWITCH_STATUS_GENERR; + } } @@ -2902,5 +2912,5 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 */ From f68d83dda058fa43aba84259b11bb55b1e2fa9af Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 14 Sep 2009 22:06:20 +0000 Subject: [PATCH 1531/1766] fix vim format line git-svn-id: http://svn.openzap.org/svn/openzap/trunk@833 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/g711.c | 2 +- libs/openzap/src/hashtable.c | 2 +- libs/openzap/src/hashtable_itr.c | 2 +- libs/openzap/src/include/g711.h | 2 +- libs/openzap/src/include/hashtable.h | 2 +- libs/openzap/src/include/hashtable_itr.h | 2 +- libs/openzap/src/include/hashtable_private.h | 2 +- libs/openzap/src/include/openzap.h | 2 +- libs/openzap/src/include/sangoma_tdm_api.h | 2 +- libs/openzap/src/include/zap_buffer.h | 2 +- libs/openzap/src/include/zap_config.h | 2 +- libs/openzap/src/include/zap_m3ua.h | 2 +- libs/openzap/src/include/zap_threadmutex.h | 2 +- libs/openzap/src/include/zap_types.h | 2 +- libs/openzap/src/m3ua_client.c | 2 +- libs/openzap/src/m3ua_client.h | 2 +- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- libs/openzap/src/ozmod/ozmod_analog/zap_analog.h | 2 +- libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 2 +- libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h | 2 +- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 2 +- libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c | 2 +- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h | 2 +- libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c | 2 +- libs/openzap/src/ozmod/ozmod_pika/zap_pika.h | 2 +- .../openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 +- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c | 2 +- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h | 2 +- libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h | 2 +- libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c | 2 +- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 2 +- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h | 2 +- libs/openzap/src/priserver.c | 2 +- libs/openzap/src/sangoma_pri.c | 2 +- libs/openzap/src/testanalog.c | 2 +- libs/openzap/src/testapp.c | 2 +- libs/openzap/src/testboost.c | 2 +- libs/openzap/src/testisdn.c | 2 +- libs/openzap/src/testpri.c | 2 +- libs/openzap/src/testr2.c | 2 +- libs/openzap/src/zap_buffer.c | 2 +- libs/openzap/src/zap_config.c | 2 +- libs/openzap/src/zap_io.c | 2 +- libs/openzap/src/zap_threadmutex.c | 2 +- 47 files changed, 47 insertions(+), 47 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index cb4e8fbae2..843e77a9a1 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2912,5 +2912,5 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/g711.c b/libs/openzap/src/g711.c index 97772c25f5..37511c3a9c 100644 --- a/libs/openzap/src/g711.c +++ b/libs/openzap/src/g711.c @@ -99,6 +99,6 @@ uint8_t ulaw_to_alaw(uint8_t ulaw) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/hashtable.c b/libs/openzap/src/hashtable.c index 5dafc09233..eeb2aaa07a 100644 --- a/libs/openzap/src/hashtable.c +++ b/libs/openzap/src/hashtable.c @@ -334,6 +334,6 @@ OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/hashtable_itr.c b/libs/openzap/src/hashtable_itr.c index 8519ab3c77..8973b08ad0 100644 --- a/libs/openzap/src/hashtable_itr.c +++ b/libs/openzap/src/hashtable_itr.c @@ -181,6 +181,6 @@ hashtable_iterator_search(struct hashtable_itr *itr, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/g711.h b/libs/openzap/src/include/g711.h index 2d7e481e48..6f4c1d2542 100644 --- a/libs/openzap/src/include/g711.h +++ b/libs/openzap/src/include/g711.h @@ -391,5 +391,5 @@ extern "C" { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/hashtable.h b/libs/openzap/src/include/hashtable.h index ea63e2e91d..0d185bbc5b 100644 --- a/libs/openzap/src/include/hashtable.h +++ b/libs/openzap/src/include/hashtable.h @@ -224,5 +224,5 @@ OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/hashtable_itr.h b/libs/openzap/src/include/hashtable_itr.h index e14833ab57..6897ce949c 100644 --- a/libs/openzap/src/include/hashtable_itr.h +++ b/libs/openzap/src/include/hashtable_itr.h @@ -124,6 +124,6 @@ hashtable_iterator_search(struct hashtable_itr *itr, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/hashtable_private.h b/libs/openzap/src/include/hashtable_private.h index 0f329ca3a6..1bb10fd016 100644 --- a/libs/openzap/src/include/hashtable_private.h +++ b/libs/openzap/src/include/hashtable_private.h @@ -101,5 +101,5 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index ee09acc2fb..522e435f7c 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -757,5 +757,5 @@ static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 08ae5cf00d..062d4e219d 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -316,6 +316,6 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/zap_buffer.h b/libs/openzap/src/include/zap_buffer.h index 2824c7938a..9a05420979 100644 --- a/libs/openzap/src/include/zap_buffer.h +++ b/libs/openzap/src/include/zap_buffer.h @@ -142,5 +142,5 @@ OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/zap_config.h b/libs/openzap/src/include/zap_config.h index 967c09cd79..f2f2e374bf 100644 --- a/libs/openzap/src/include/zap_config.h +++ b/libs/openzap/src/include/zap_config.h @@ -134,5 +134,5 @@ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/zap_m3ua.h b/libs/openzap/src/include/zap_m3ua.h index 12e6c45582..18de6db838 100644 --- a/libs/openzap/src/include/zap_m3ua.h +++ b/libs/openzap/src/include/zap_m3ua.h @@ -123,6 +123,6 @@ zap_status_t m3ua_start(zap_span_t *span); * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index 8639027ab7..6e2af571ac 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -46,6 +46,6 @@ OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex); * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 2db87513a0..72c467c398 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -618,6 +618,6 @@ typedef enum { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/m3ua_client.c b/libs/openzap/src/m3ua_client.c index 05dfc49523..ba33dd4317 100644 --- a/libs/openzap/src/m3ua_client.c +++ b/libs/openzap/src/m3ua_client.c @@ -327,7 +327,7 @@ const char *m3uac_event_id_name(uint32_t event_id) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/m3ua_client.h b/libs/openzap/src/m3ua_client.h index 29620e0302..b80309017c 100644 --- a/libs/openzap/src/m3ua_client.h +++ b/libs/openzap/src/m3ua_client.h @@ -160,5 +160,5 @@ int m3uac_exec_command(m3uac_connection_t *mcon, int span, int chan, int id, int * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 20de17dbd1..e45d3413db 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -995,5 +995,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h index b48b168e69..563285eb2c 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h @@ -66,5 +66,5 @@ typedef struct zap_analog_data zap_analog_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ 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 index 3a8e9a2156..a756f564f8 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -704,5 +704,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ 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 index 9411844c44..4d34ca98fe 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -65,5 +65,5 @@ typedef struct zap_analog_data zap_analog_em_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 7aa23604fa..d054bd08d1 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -2421,5 +2421,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index 470a8022bb..b16b004a9d 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -92,6 +92,6 @@ typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c index c75533b223..3df1d54d89 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -298,6 +298,6 @@ int lpwrap_run_pri(struct lpwrap_pri *spri) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index b15f2dfac7..809bab2447 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -1365,5 +1365,5 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h index ac01a1fafa..4e33aba17d 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -93,6 +93,6 @@ typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c index 995c6df554..154c1618ff 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/openzap/src/ozmod/ozmod_pika/ozmod_pika.c @@ -1464,6 +1464,6 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h index da1864d486..27c455a429 100644 --- a/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h +++ b/libs/openzap/src/ozmod/ozmod_pika/zap_pika.h @@ -128,5 +128,5 @@ PIKA_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandM * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ 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 index 2b502ba6cd..2e20a9cc25 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1461,5 +1461,5 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ 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 index 224218c6f2..f0ecef1b97 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -520,6 +520,6 @@ const char *sangomabc_event_id_name(uint32_t event_id) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ 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 index 5554cb1ff6..1b86c5df01 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -144,5 +144,5 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ 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 index 3d82c6f5c0..932787c93a 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -58,6 +58,6 @@ typedef struct zap_sangoma_boost_data { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c b/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c index aa468a356f..949e0fbf31 100644 --- a/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c +++ b/libs/openzap/src/ozmod/ozmod_skel/ozmod_skel.c @@ -147,6 +147,6 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 9e4369334b..b8788d2a58 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1224,5 +1224,5 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h index 38de3076e3..14516f6fe9 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h @@ -359,5 +359,5 @@ ZT_ABIT = 8 * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/priserver.c b/libs/openzap/src/priserver.c index 377ded7325..7a37357083 100644 --- a/libs/openzap/src/priserver.c +++ b/libs/openzap/src/priserver.c @@ -324,5 +324,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/sangoma_pri.c b/libs/openzap/src/sangoma_pri.c index bf213699b6..5cf6a5cd10 100644 --- a/libs/openzap/src/sangoma_pri.c +++ b/libs/openzap/src/sangoma_pri.c @@ -246,6 +246,6 @@ int sangoma_run_pri(struct sangoma_pri *spri) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/testanalog.c b/libs/openzap/src/testanalog.c index 274228dea0..1a9542be4f 100644 --- a/libs/openzap/src/testanalog.c +++ b/libs/openzap/src/testanalog.c @@ -128,6 +128,6 @@ done: * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/testapp.c b/libs/openzap/src/testapp.c index ea83419a99..cfa27c9296 100644 --- a/libs/openzap/src/testapp.c +++ b/libs/openzap/src/testapp.c @@ -79,5 +79,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/testboost.c b/libs/openzap/src/testboost.c index 4838f54def..cec952219b 100644 --- a/libs/openzap/src/testboost.c +++ b/libs/openzap/src/testboost.c @@ -71,5 +71,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/testisdn.c b/libs/openzap/src/testisdn.c index 252f0bcec8..f32f47a3f0 100644 --- a/libs/openzap/src/testisdn.c +++ b/libs/openzap/src/testisdn.c @@ -70,5 +70,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/testpri.c b/libs/openzap/src/testpri.c index a672d9322f..1d203eae55 100644 --- a/libs/openzap/src/testpri.c +++ b/libs/openzap/src/testpri.c @@ -158,5 +158,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/testr2.c b/libs/openzap/src/testr2.c index f5f093cb4f..83a950cff0 100644 --- a/libs/openzap/src/testr2.c +++ b/libs/openzap/src/testr2.c @@ -82,5 +82,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/zap_buffer.c b/libs/openzap/src/zap_buffer.c index 8315825ff7..0e2279d7e3 100644 --- a/libs/openzap/src/zap_buffer.c +++ b/libs/openzap/src/zap_buffer.c @@ -298,5 +298,5 @@ OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/zap_config.c b/libs/openzap/src/zap_config.c index 05d5db3c61..ca0315594b 100644 --- a/libs/openzap/src/zap_config.c +++ b/libs/openzap/src/zap_config.c @@ -247,5 +247,5 @@ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 98df71f723..0f1c53647d 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -3088,5 +3088,5 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 2dc4763068..b6bc8435b6 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -233,5 +233,5 @@ OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ From e2004e2d34e61b959db0a1914ae016661f3bfbf4 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 14 Sep 2009 22:06:20 +0000 Subject: [PATCH 1532/1766] fix vim format line git-svn-id: http://svn.openzap.org/svn/openzap/trunk@833 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/g711.c | 2 +- libs/freetdm/src/hashtable.c | 2 +- libs/freetdm/src/hashtable_itr.c | 2 +- libs/freetdm/src/include/g711.h | 2 +- libs/freetdm/src/include/hashtable.h | 2 +- libs/freetdm/src/include/hashtable_itr.h | 2 +- libs/freetdm/src/include/hashtable_private.h | 2 +- libs/freetdm/src/include/openzap.h | 2 +- libs/freetdm/src/include/sangoma_tdm_api.h | 2 +- libs/freetdm/src/include/zap_buffer.h | 2 +- libs/freetdm/src/include/zap_config.h | 2 +- libs/freetdm/src/include/zap_m3ua.h | 2 +- libs/freetdm/src/include/zap_threadmutex.h | 2 +- libs/freetdm/src/include/zap_types.h | 2 +- libs/freetdm/src/m3ua_client.c | 2 +- libs/freetdm/src/m3ua_client.h | 2 +- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h | 2 +- libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 2 +- libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h | 2 +- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h | 2 +- libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c | 2 +- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h | 2 +- libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 2 +- libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h | 2 +- .../freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 +- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c | 2 +- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h | 2 +- libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h | 2 +- libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c | 2 +- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 2 +- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h | 2 +- libs/freetdm/src/priserver.c | 2 +- libs/freetdm/src/sangoma_pri.c | 2 +- libs/freetdm/src/testanalog.c | 2 +- libs/freetdm/src/testapp.c | 2 +- libs/freetdm/src/testboost.c | 2 +- libs/freetdm/src/testisdn.c | 2 +- libs/freetdm/src/testpri.c | 2 +- libs/freetdm/src/testr2.c | 2 +- libs/freetdm/src/zap_buffer.c | 2 +- libs/freetdm/src/zap_config.c | 2 +- libs/freetdm/src/zap_io.c | 2 +- libs/freetdm/src/zap_threadmutex.c | 2 +- 47 files changed, 47 insertions(+), 47 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index cb4e8fbae2..843e77a9a1 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2912,5 +2912,5 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/g711.c b/libs/freetdm/src/g711.c index 97772c25f5..37511c3a9c 100644 --- a/libs/freetdm/src/g711.c +++ b/libs/freetdm/src/g711.c @@ -99,6 +99,6 @@ uint8_t ulaw_to_alaw(uint8_t ulaw) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 5dafc09233..eeb2aaa07a 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -334,6 +334,6 @@ OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index 8519ab3c77..8973b08ad0 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -181,6 +181,6 @@ hashtable_iterator_search(struct hashtable_itr *itr, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/g711.h b/libs/freetdm/src/include/g711.h index 2d7e481e48..6f4c1d2542 100644 --- a/libs/freetdm/src/include/g711.h +++ b/libs/freetdm/src/include/g711.h @@ -391,5 +391,5 @@ extern "C" { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index ea63e2e91d..0d185bbc5b 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -224,5 +224,5 @@ OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/hashtable_itr.h b/libs/freetdm/src/include/hashtable_itr.h index e14833ab57..6897ce949c 100644 --- a/libs/freetdm/src/include/hashtable_itr.h +++ b/libs/freetdm/src/include/hashtable_itr.h @@ -124,6 +124,6 @@ hashtable_iterator_search(struct hashtable_itr *itr, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index 0f329ca3a6..1bb10fd016 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -101,5 +101,5 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ee09acc2fb..522e435f7c 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -757,5 +757,5 @@ static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/sangoma_tdm_api.h b/libs/freetdm/src/include/sangoma_tdm_api.h index 08ae5cf00d..062d4e219d 100644 --- a/libs/freetdm/src/include/sangoma_tdm_api.h +++ b/libs/freetdm/src/include/sangoma_tdm_api.h @@ -316,6 +316,6 @@ static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrle * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h index 2824c7938a..9a05420979 100644 --- a/libs/freetdm/src/include/zap_buffer.h +++ b/libs/freetdm/src/include/zap_buffer.h @@ -142,5 +142,5 @@ OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h index 967c09cd79..f2f2e374bf 100644 --- a/libs/freetdm/src/include/zap_config.h +++ b/libs/freetdm/src/include/zap_config.h @@ -134,5 +134,5 @@ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/zap_m3ua.h b/libs/freetdm/src/include/zap_m3ua.h index 12e6c45582..18de6db838 100644 --- a/libs/freetdm/src/include/zap_m3ua.h +++ b/libs/freetdm/src/include/zap_m3ua.h @@ -123,6 +123,6 @@ zap_status_t m3ua_start(zap_span_t *span); * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index 8639027ab7..6e2af571ac 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -46,6 +46,6 @@ OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex); * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 2db87513a0..72c467c398 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -618,6 +618,6 @@ typedef enum { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/m3ua_client.c b/libs/freetdm/src/m3ua_client.c index 05dfc49523..ba33dd4317 100644 --- a/libs/freetdm/src/m3ua_client.c +++ b/libs/freetdm/src/m3ua_client.c @@ -327,7 +327,7 @@ const char *m3uac_event_id_name(uint32_t event_id) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/m3ua_client.h b/libs/freetdm/src/m3ua_client.h index 29620e0302..b80309017c 100644 --- a/libs/freetdm/src/m3ua_client.h +++ b/libs/freetdm/src/m3ua_client.h @@ -160,5 +160,5 @@ int m3uac_exec_command(m3uac_connection_t *mcon, int span, int chan, int id, int * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 20de17dbd1..e45d3413db 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -995,5 +995,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h index b48b168e69..563285eb2c 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h @@ -66,5 +66,5 @@ typedef struct zap_analog_data zap_analog_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index 3a8e9a2156..a756f564f8 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -704,5 +704,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h index 9411844c44..4d34ca98fe 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -65,5 +65,5 @@ typedef struct zap_analog_data zap_analog_em_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index 7aa23604fa..d054bd08d1 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -2421,5 +2421,5 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h index 470a8022bb..b16b004a9d 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h @@ -92,6 +92,6 @@ typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c index c75533b223..3df1d54d89 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c @@ -298,6 +298,6 @@ int lpwrap_run_pri(struct lpwrap_pri *spri) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index b15f2dfac7..809bab2447 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -1365,5 +1365,5 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h index ac01a1fafa..4e33aba17d 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -93,6 +93,6 @@ typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index 995c6df554..154c1618ff 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -1464,6 +1464,6 @@ EX_DECLARE_DATA zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h b/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h index da1864d486..27c455a429 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h +++ b/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h @@ -128,5 +128,5 @@ PIKA_STR2ENUM_P(pika_str2compand_mode, pika_compand_mode2str, PIKA_TSpanCompandM * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 2b502ba6cd..2e20a9cc25 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1461,5 +1461,5 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 224218c6f2..f0ecef1b97 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -520,6 +520,6 @@ const char *sangomabc_event_id_name(uint32_t event_id) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index 5554cb1ff6..1b86c5df01 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -144,5 +144,5 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h index 3d82c6f5c0..932787c93a 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -58,6 +58,6 @@ typedef struct zap_sangoma_boost_data { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c b/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c index aa468a356f..949e0fbf31 100644 --- a/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c +++ b/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c @@ -147,6 +147,6 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index 9e4369334b..b8788d2a58 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1224,5 +1224,5 @@ zap_module_t zap_module = { * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h index 38de3076e3..14516f6fe9 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h @@ -359,5 +359,5 @@ ZT_ABIT = 8 * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index 377ded7325..7a37357083 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -324,5 +324,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/sangoma_pri.c b/libs/freetdm/src/sangoma_pri.c index bf213699b6..5cf6a5cd10 100644 --- a/libs/freetdm/src/sangoma_pri.c +++ b/libs/freetdm/src/sangoma_pri.c @@ -246,6 +246,6 @@ int sangoma_run_pri(struct sangoma_pri *spri) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 274228dea0..1a9542be4f 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -128,6 +128,6 @@ done: * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index ea83419a99..cfa27c9296 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -79,5 +79,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index 4838f54def..cec952219b 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -71,5 +71,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 252f0bcec8..f32f47a3f0 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -70,5 +70,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/testpri.c b/libs/freetdm/src/testpri.c index a672d9322f..1d203eae55 100644 --- a/libs/freetdm/src/testpri.c +++ b/libs/freetdm/src/testpri.c @@ -158,5 +158,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/testr2.c b/libs/freetdm/src/testr2.c index f5f093cb4f..83a950cff0 100644 --- a/libs/freetdm/src/testr2.c +++ b/libs/freetdm/src/testr2.c @@ -82,5 +82,5 @@ int main(int argc, char *argv[]) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 8315825ff7..0e2279d7e3 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -298,5 +298,5 @@ OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/zap_config.c index 05d5db3c61..ca0315594b 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/zap_config.c @@ -247,5 +247,5 @@ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 98df71f723..0f1c53647d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -3088,5 +3088,5 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 2dc4763068..b6bc8435b6 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -233,5 +233,5 @@ OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex) * c-basic-offset:4 * End: * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: */ From 8291ec982eeeeb788d4b15f0d420e144682a5338 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 Sep 2009 22:13:43 +0000 Subject: [PATCH 1533/1766] fix timer in dtmf generator git-svn-id: http://svn.openzap.org/svn/openzap/trunk@834 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 0f1c53647d..28e6f12686 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1847,8 +1847,10 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) return ZAP_FAIL; } } - - zchan->skip_read_frames = wrote / (1000 / zchan->effective_interval); + + if (x) { + zchan->skip_read_frames = (wrote / (zchan->effective_interval * 8)) + 4; + } } } From 3b69191453a8b900632f6e1649b85a5b7d7267bf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 Sep 2009 22:13:43 +0000 Subject: [PATCH 1534/1766] fix timer in dtmf generator git-svn-id: http://svn.openzap.org/svn/openzap/trunk@834 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 0f1c53647d..28e6f12686 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1847,8 +1847,10 @@ static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) return ZAP_FAIL; } } - - zchan->skip_read_frames = wrote / (1000 / zchan->effective_interval); + + if (x) { + zchan->skip_read_frames = (wrote / (zchan->effective_interval * 8)) + 4; + } } } From 041e45eb78a1a7ec34ffa0e36c45190feb65ac98 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 15 Sep 2009 14:33:28 +0000 Subject: [PATCH 1535/1766] dog git-svn-id: http://svn.openzap.org/svn/openzap/trunk@835 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 28e6f12686..10da9d8361 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1900,7 +1900,7 @@ OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint3 int16_t x; uint32_t i; int sum_rnd = 0; - int16_t rnd2 = (int16_t) zap_current_time_in_ms * (int16_t) (intptr_t) data; + int16_t rnd2 = (int16_t) zap_current_time_in_ms() * (int16_t) (intptr_t) data; assert(divisor); From 3dc0f2569a5b14ff0ab8cd317780e617546c4980 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 15 Sep 2009 14:33:28 +0000 Subject: [PATCH 1536/1766] dog git-svn-id: http://svn.openzap.org/svn/openzap/trunk@835 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 28e6f12686..10da9d8361 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1900,7 +1900,7 @@ OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint3 int16_t x; uint32_t i; int sum_rnd = 0; - int16_t rnd2 = (int16_t) zap_current_time_in_ms * (int16_t) (intptr_t) data; + int16_t rnd2 = (int16_t) zap_current_time_in_ms() * (int16_t) (intptr_t) data; assert(divisor); From 0779d8874f73e3c78fbe674aa7307eaaa4cbd854 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 Sep 2009 17:46:11 +0000 Subject: [PATCH 1537/1766] fix null buffer in pre_buffer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@836 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 10da9d8361..6ce6689544 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -250,6 +250,9 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + zap_buffer_destroy(&zchan->pre_buffer); + zchan->pre_buffer_size = 0; + hashtable_destroy(zchan->variable_hash); zap_safe_free(zchan->dtmf_hangup_buf); @@ -1200,6 +1203,7 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); zap_buffer_destroy(&zchan->pre_buffer); + zchan->pre_buffer_size = 0; zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; @@ -2120,7 +2124,7 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ if (zchan->skip_read_frames > 0) { zchan->skip_read_frames--; } - } else if (zchan->pre_buffer_size) { + } else if (zchan->pre_buffer_size && zchan->pre_buffer) { zap_buffer_write(zchan->pre_buffer, data, *datalen); if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { zap_buffer_read(zchan->pre_buffer, data, *datalen); From 1459cd24c31ce3a781b03a4409f7a2726f9b75cc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 19 Sep 2009 17:46:11 +0000 Subject: [PATCH 1538/1766] fix null buffer in pre_buffer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@836 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 10da9d8361..6ce6689544 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -250,6 +250,9 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + zap_buffer_destroy(&zchan->pre_buffer); + zchan->pre_buffer_size = 0; + hashtable_destroy(zchan->variable_hash); zap_safe_free(zchan->dtmf_hangup_buf); @@ -1200,6 +1203,7 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); zap_buffer_destroy(&zchan->pre_buffer); + zchan->pre_buffer_size = 0; zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; @@ -2120,7 +2124,7 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ if (zchan->skip_read_frames > 0) { zchan->skip_read_frames--; } - } else if (zchan->pre_buffer_size) { + } else if (zchan->pre_buffer_size && zchan->pre_buffer) { zap_buffer_write(zchan->pre_buffer, data, *datalen); if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { zap_buffer_read(zchan->pre_buffer, data, *datalen); From 61597098767e1578332bc3a25a122d74845064d1 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 21 Sep 2009 20:50:14 +0000 Subject: [PATCH 1539/1766] Support for parsing smg_events with additional parameters git-svn-id: http://svn.openzap.org/svn/openzap/trunk@837 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 index 2e20a9cc25..947c9c8754 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -650,7 +650,24 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); if (event->isup_in_rdnis_size) { - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + char* p; + + //Set value of rdnis.digis in case prot daemon is still using older style RDNIS + if (atoi((char *)event->isup_in_rdnis) > 0) { + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + } + + p = strstr((char*)event->isup_in_rdnis,"PRI001-ANI2-"); + if (p!=NULL) { + int ani2 = 0; + sscanf(p, "PRI001-ANI2-%d", &ani2); + snprintf(zchan->caller_data.aniII, 5, "%.2d", ani2); + } + p = strstr((char*)event->isup_in_rdnis,"RDNIS-"); + if (p!=NULL) { + sscanf(p, "RDNIS-%s", &zchan->caller_data.rdnis.digits[0]); + } + } zchan->caller_data.screen = event->calling_number_screening_ind; zchan->caller_data.pres = event->calling_number_presentation; From d128277a08c0aab3aeb3dc410e10e8dc3e876e66 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 21 Sep 2009 20:50:14 +0000 Subject: [PATCH 1540/1766] Support for parsing smg_events with additional parameters git-svn-id: http://svn.openzap.org/svn/openzap/trunk@837 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 2e20a9cc25..947c9c8754 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -650,7 +650,24 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); if (event->isup_in_rdnis_size) { - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + char* p; + + //Set value of rdnis.digis in case prot daemon is still using older style RDNIS + if (atoi((char *)event->isup_in_rdnis) > 0) { + zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + } + + p = strstr((char*)event->isup_in_rdnis,"PRI001-ANI2-"); + if (p!=NULL) { + int ani2 = 0; + sscanf(p, "PRI001-ANI2-%d", &ani2); + snprintf(zchan->caller_data.aniII, 5, "%.2d", ani2); + } + p = strstr((char*)event->isup_in_rdnis,"RDNIS-"); + if (p!=NULL) { + sscanf(p, "RDNIS-%s", &zchan->caller_data.rdnis.digits[0]); + } + } zchan->caller_data.screen = event->calling_number_screening_ind; zchan->caller_data.pres = event->calling_number_presentation; From 59429435925561bb2a61c9a32e14381a622de6df Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 22 Sep 2009 15:45:41 +0000 Subject: [PATCH 1541/1766] add more info to unhandled types errors git-svn-id: http://svn.openzap.org/svn/openzap/trunk@838 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 843e77a9a1..1c093f74bb 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -499,7 +499,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled channel type %d for channel %s\n", tech_pvt->zchan->type, + switch_channel_get_name(channel)); } break; } @@ -1369,8 +1370,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; @@ -1576,8 +1577,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; @@ -1764,8 +1765,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; } @@ -1792,8 +1793,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled analog channel type %d for channel %d:%d\n", + sigmsg->channel->type, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; } From fa924f76a02b8a7f9c4e4602f3ca99bbbc78d154 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 22 Sep 2009 15:45:41 +0000 Subject: [PATCH 1542/1766] add more info to unhandled types errors git-svn-id: http://svn.openzap.org/svn/openzap/trunk@838 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 843e77a9a1..1c093f74bb 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -499,7 +499,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled type for channel %s\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled channel type %d for channel %s\n", tech_pvt->zchan->type, + switch_channel_get_name(channel)); } break; } @@ -1369,8 +1370,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; @@ -1576,8 +1577,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; @@ -1764,8 +1765,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type for channel %d:%d\n", + sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; } @@ -1792,8 +1793,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled type for channel %d:%d\n", - sigmsg->channel->span_id, sigmsg->channel->chan_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled analog channel type %d for channel %d:%d\n", + sigmsg->channel->type, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; } From e2c42c0a9f6cdd7ca1b05f1efa10b3fbc383d77e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 22 Sep 2009 15:50:50 +0000 Subject: [PATCH 1543/1766] enable rbs events just for cas and em channels git-svn-id: http://svn.openzap.org/svn/openzap/trunk@839 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index a7f54595f2..281c0be136 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -285,8 +285,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } #endif - if (type == ZAP_CHAN_TYPE_CAS || - ((span->trunk_type == ZAP_TRUNK_T1 || span->trunk_type == ZAP_TRUNK_E1) && type != ZAP_CHAN_TYPE_B)) { + 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)); From 37743744a9531f5839c41d8f19fcb304170131c9 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 22 Sep 2009 15:50:50 +0000 Subject: [PATCH 1544/1766] enable rbs events just for cas and em channels git-svn-id: http://svn.openzap.org/svn/openzap/trunk@839 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index a7f54595f2..281c0be136 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -285,8 +285,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } #endif - if (type == ZAP_CHAN_TYPE_CAS || - ((span->trunk_type == ZAP_TRUNK_T1 || span->trunk_type == ZAP_TRUNK_E1) && type != ZAP_CHAN_TYPE_B)) { + 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)); From af346dbe4296ae8b0b7fabd424b81296547ce07f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 22 Sep 2009 16:21:32 +0000 Subject: [PATCH 1545/1766] oops, sorry bout that git-svn-id: http://svn.openzap.org/svn/openzap/trunk@840 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 1c093f74bb..5477a9a478 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1765,7 +1765,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type for channel %d:%d\n", + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; From 10b2bbcf986dab91bac64948f4c6d05543a0e67d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 22 Sep 2009 16:21:32 +0000 Subject: [PATCH 1546/1766] oops, sorry bout that git-svn-id: http://svn.openzap.org/svn/openzap/trunk@840 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 1c093f74bb..5477a9a478 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1765,7 +1765,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type for channel %d:%d\n", + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", sigmsg->event_id, sigmsg->channel->span_id, sigmsg->channel->chan_id); } break; From 6084d2b269aec4a6c3237d3139a576495a8861b1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 Sep 2009 16:44:02 +0000 Subject: [PATCH 1547/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@841 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/libteletone_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/libteletone_detect.c b/libs/openzap/src/libteletone_detect.c index b41a04ae42..61fef90149 100644 --- a/libs/openzap/src/libteletone_detect.c +++ b/libs/openzap/src/libteletone_detect.c @@ -182,7 +182,7 @@ TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt, { int sample, limit = 0, j, x = 0; float v1, famp; - float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; + 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) { From bddc498b7bc3adca59bdb061b16f27889d392fb7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 Sep 2009 16:44:02 +0000 Subject: [PATCH 1548/1766] fix build git-svn-id: http://svn.openzap.org/svn/openzap/trunk@841 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/libteletone_detect.c b/libs/freetdm/src/libteletone_detect.c index b41a04ae42..61fef90149 100644 --- a/libs/freetdm/src/libteletone_detect.c +++ b/libs/freetdm/src/libteletone_detect.c @@ -182,7 +182,7 @@ TELETONE_API(int) teletone_multi_tone_detect (teletone_multi_tone_t *mt, { int sample, limit = 0, j, x = 0; float v1, famp; - float eng_sum = 0, eng_all[TELETONE_MAX_TONES]; + 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) { From 8ba94325b26c649a0d91871adc4e5a85d594b162 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 29 Sep 2009 22:29:35 +0000 Subject: [PATCH 1549/1766] dont be fool and use default layer 1 in ozmod_libpri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@842 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 809bab2447..a8e3fea6f7 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -1275,6 +1275,14 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) 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")) { @@ -1318,8 +1326,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) return ZAP_FAIL; } } - - + span->start = zap_libpri_start; span->stop = zap_libpri_stop; isdn_data->sig_cb = sig_cb; From fc0487aced340f5bf153a0b347849ceab00ce6f0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 29 Sep 2009 22:29:35 +0000 Subject: [PATCH 1550/1766] dont be fool and use default layer 1 in ozmod_libpri git-svn-id: http://svn.openzap.org/svn/openzap/trunk@842 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index 809bab2447..a8e3fea6f7 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -1275,6 +1275,14 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) 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")) { @@ -1318,8 +1326,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) return ZAP_FAIL; } } - - + span->start = zap_libpri_start; span->stop = zap_libpri_stop; isdn_data->sig_cb = sig_cb; From 65124ad55567c5c5f1ffe06d36ff4509300952a4 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 6 Oct 2009 17:39:51 +0000 Subject: [PATCH 1551/1766] ozmod_analog_em: allow longer dialstrings git-svn-id: http://svn.openzap.org/svn/openzap/trunk@843 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 5 +++-- libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) 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 index a756f564f8..4468e4b92d 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -137,8 +137,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) digit_timeout = 2000; } - if (max_dialstr < 2 || max_dialstr > 20) { - max_dialstr = 11; + 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; 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 index 4d34ca98fe..5f0f726063 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -40,6 +40,8 @@ #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; From 64b76671eeb0e01778167f242e115ce9ae403d9f Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 6 Oct 2009 17:39:51 +0000 Subject: [PATCH 1552/1766] ozmod_analog_em: allow longer dialstrings git-svn-id: http://svn.openzap.org/svn/openzap/trunk@843 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 5 +++-- libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index a756f564f8..4468e4b92d 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -137,8 +137,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) digit_timeout = 2000; } - if (max_dialstr < 2 || max_dialstr > 20) { - max_dialstr = 11; + 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; diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h index 4d34ca98fe..5f0f726063 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -40,6 +40,8 @@ #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; From 337f06c1039626b7d7362a3de5ea174b99a696f2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Oct 2009 16:53:36 +0000 Subject: [PATCH 1553/1766] add mutex to pre_buffer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@844 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/zap_io.c | 33 ++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 522e435f7c..084b2afe21 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -506,6 +506,7 @@ struct zap_channel { zap_buffer_t *pre_buffer; zap_buffer_t *digit_buffer; zap_buffer_t *fsk_buffer; + zap_mutex_t *pre_buffer_mutex; uint32_t dtmf_on; uint32_t dtmf_off; char *dtmf_hangup_buf; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 6ce6689544..2670c37ea7 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -245,12 +245,14 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_sleep(500); } + zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); + zap_mutex_unlock(zchan->pre_buffer_mutex); + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); - zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; hashtable_destroy(zchan->variable_hash); @@ -273,13 +275,13 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) } zap_mutex_destroy(&zchan->mutex); + zap_mutex_destroy(&zchan->pre_buffer_mutex); } return ZAP_SUCCESS; } - OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -525,6 +527,8 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc } zap_mutex_create(&new_chan->mutex); + zap_mutex_create(&new_chan->pre_buffer_mutex); + zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); @@ -1202,8 +1206,10 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; + zap_mutex_unlock(zchan->pre_buffer_mutex); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; @@ -1478,11 +1484,13 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t zchan->pre_buffer_size = val * 8; + zap_mutex_lock(zchan->pre_buffer_mutex); if (!zchan->pre_buffer_size) { zap_buffer_destroy(&zchan->pre_buffer); } else if (!zchan->pre_buffer) { zap_buffer_create(&zchan->pre_buffer, 1024, zchan->pre_buffer_size, 0); } + zap_mutex_unlock(zchan->pre_buffer_mutex); GOTO_STATUS(done, ZAP_SUCCESS); @@ -1550,8 +1558,10 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t case ZAP_COMMAND_DISABLE_ECHOCANCEL: { + zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; + zap_mutex_unlock(zchan->pre_buffer_mutex); } break; default: @@ -2115,22 +2125,29 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { + zap_mutex_lock(zchan->pre_buffer_mutex); if (zchan->pre_buffer && zap_buffer_inuse(zchan->pre_buffer)) { zap_buffer_zero(zchan->pre_buffer); } + zap_mutex_unlock(zchan->pre_buffer_mutex); + memset(data, 255, *datalen); if (zchan->skip_read_frames > 0) { zchan->skip_read_frames--; } - } else if (zchan->pre_buffer_size && zchan->pre_buffer) { - zap_buffer_write(zchan->pre_buffer, data, *datalen); - if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { - zap_buffer_read(zchan->pre_buffer, data, *datalen); - } else { - memset(data, 255, *datalen); + } else { + zap_mutex_lock(zchan->pre_buffer_mutex); + if (zchan->pre_buffer_size && zchan->pre_buffer) { + zap_buffer_write(zchan->pre_buffer, data, *datalen); + if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { + zap_buffer_read(zchan->pre_buffer, data, *datalen); + } else { + memset(data, 255, *datalen); + } } + zap_mutex_unlock(zchan->pre_buffer_mutex); } From f4a61117e60ae2130165010bb79aa99a5f8f1d5f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Oct 2009 16:53:36 +0000 Subject: [PATCH 1554/1766] add mutex to pre_buffer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@844 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 33 ++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 522e435f7c..084b2afe21 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -506,6 +506,7 @@ struct zap_channel { zap_buffer_t *pre_buffer; zap_buffer_t *digit_buffer; zap_buffer_t *fsk_buffer; + zap_mutex_t *pre_buffer_mutex; uint32_t dtmf_on; uint32_t dtmf_off; char *dtmf_hangup_buf; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 6ce6689544..2670c37ea7 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -245,12 +245,14 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_sleep(500); } + zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); + zap_mutex_unlock(zchan->pre_buffer_mutex); + zap_buffer_destroy(&zchan->digit_buffer); zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); - zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; hashtable_destroy(zchan->variable_hash); @@ -273,13 +275,13 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) } zap_mutex_destroy(&zchan->mutex); + zap_mutex_destroy(&zchan->pre_buffer_mutex); } return ZAP_SUCCESS; } - OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) { zap_status_t status = ZAP_FAIL; @@ -525,6 +527,8 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc } zap_mutex_create(&new_chan->mutex); + zap_mutex_create(&new_chan->pre_buffer_mutex); + zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); @@ -1202,8 +1206,10 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; + zap_mutex_unlock(zchan->pre_buffer_mutex); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; @@ -1478,11 +1484,13 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t zchan->pre_buffer_size = val * 8; + zap_mutex_lock(zchan->pre_buffer_mutex); if (!zchan->pre_buffer_size) { zap_buffer_destroy(&zchan->pre_buffer); } else if (!zchan->pre_buffer) { zap_buffer_create(&zchan->pre_buffer, 1024, zchan->pre_buffer_size, 0); } + zap_mutex_unlock(zchan->pre_buffer_mutex); GOTO_STATUS(done, ZAP_SUCCESS); @@ -1550,8 +1558,10 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t case ZAP_COMMAND_DISABLE_ECHOCANCEL: { + zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; + zap_mutex_unlock(zchan->pre_buffer_mutex); } break; default: @@ -2115,22 +2125,29 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { + zap_mutex_lock(zchan->pre_buffer_mutex); if (zchan->pre_buffer && zap_buffer_inuse(zchan->pre_buffer)) { zap_buffer_zero(zchan->pre_buffer); } + zap_mutex_unlock(zchan->pre_buffer_mutex); + memset(data, 255, *datalen); if (zchan->skip_read_frames > 0) { zchan->skip_read_frames--; } - } else if (zchan->pre_buffer_size && zchan->pre_buffer) { - zap_buffer_write(zchan->pre_buffer, data, *datalen); - if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { - zap_buffer_read(zchan->pre_buffer, data, *datalen); - } else { - memset(data, 255, *datalen); + } else { + zap_mutex_lock(zchan->pre_buffer_mutex); + if (zchan->pre_buffer_size && zchan->pre_buffer) { + zap_buffer_write(zchan->pre_buffer, data, *datalen); + if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { + zap_buffer_read(zchan->pre_buffer, data, *datalen); + } else { + memset(data, 255, *datalen); + } } + zap_mutex_unlock(zchan->pre_buffer_mutex); } From 8fc9022afe63bfa2b0192bd903ccbc8101c6b2e8 Mon Sep 17 00:00:00 2001 From: Brian West Date: Thu, 15 Oct 2009 03:47:33 +0000 Subject: [PATCH 1555/1766] FSBUILD-199 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@845 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 281c0be136..a275acc352 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -207,6 +207,10 @@ static unsigned char wanpipe_swap_bits(unsigned char cas_bits) 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); @@ -234,9 +238,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); #ifdef LIBSANGOMA_VERSION - sangoma_status_t sangstatus; - sangoma_wait_obj_t *sangoma_wait_obj; - 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); From e5a8e8d96359387683ce0848192ea2eca99a2b47 Mon Sep 17 00:00:00 2001 From: Brian West Date: Thu, 15 Oct 2009 03:47:33 +0000 Subject: [PATCH 1556/1766] FSBUILD-199 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@845 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 281c0be136..a275acc352 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -207,6 +207,10 @@ static unsigned char wanpipe_swap_bits(unsigned char cas_bits) 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); @@ -234,9 +238,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); #ifdef LIBSANGOMA_VERSION - sangoma_status_t sangstatus; - sangoma_wait_obj_t *sangoma_wait_obj; - 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); From d55588fe0c6e15581a95252b6f8ece249095285e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 22 Oct 2009 14:55:15 +0000 Subject: [PATCH 1557/1766] use SWITCH_MESSAGE_INDICATE_UUID_CHANGE to change tokens in openzap when a uuid of FS changes OPENZAP-88 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@846 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 5 +++++ libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/zap_io.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5477a9a478..301fefcb84 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -965,6 +965,11 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } break; + case SWITCH_MESSAGE_INDICATE_UUID_CHANGE: + { + zap_channel_replace_token(tech_pvt->zchan, msg->string_array_arg[0], msg->string_array_arg[1]); + } + break; default: break; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 084b2afe21..2c7d132b3b 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -635,6 +635,7 @@ OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token); +OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token); OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end); OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 2670c37ea7..e73f8bdd45 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -703,6 +703,20 @@ OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) } } +OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token) +{ + int i; + + if (zchan->token_count) { + for(i = 0; i < zchan->token_count; i++) { + if (!strcmp(zchan->tokens[i], old_token)) { + zap_copy_string(zchan->tokens[i], new_token, ZAP_TOKEN_STRLEN); + break; + } + } + } +} + OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end) { zap_status_t status = ZAP_FAIL; From 97eb39500850230003e05862578e50fc55365d3c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 22 Oct 2009 14:55:15 +0000 Subject: [PATCH 1558/1766] use SWITCH_MESSAGE_INDICATE_UUID_CHANGE to change tokens in openzap when a uuid of FS changes OPENZAP-88 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@846 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 +++++ libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 5477a9a478..301fefcb84 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -965,6 +965,11 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } } break; + case SWITCH_MESSAGE_INDICATE_UUID_CHANGE: + { + zap_channel_replace_token(tech_pvt->zchan, msg->string_array_arg[0], msg->string_array_arg[1]); + } + break; default: break; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 084b2afe21..2c7d132b3b 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -635,6 +635,7 @@ OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token); +OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token); OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end); OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 2670c37ea7..e73f8bdd45 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -703,6 +703,20 @@ OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) } } +OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token) +{ + int i; + + if (zchan->token_count) { + for(i = 0; i < zchan->token_count; i++) { + if (!strcmp(zchan->tokens[i], old_token)) { + zap_copy_string(zchan->tokens[i], new_token, ZAP_TOKEN_STRLEN); + break; + } + } + } +} + OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end) { zap_status_t status = ZAP_FAIL; From 60b912399e3a0fc4886eb39d2d9644deb9a2e1ca Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Oct 2009 16:03:57 +0000 Subject: [PATCH 1559/1766] change switch_strlen_zero to zstr git-svn-id: http://svn.openzap.org/svn/openzap/trunk@847 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 50 +++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 301fefcb84..886d14a71a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -142,7 +142,7 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in return NULL; } - if (!switch_strlen_zero(channel->tokens[id])) { + if (!zstr(channel->tokens[id])) { if (!(session = switch_core_session_locate(channel->tokens[id]))) { zap_channel_clear_token(channel, channel->tokens[id]); } @@ -157,7 +157,7 @@ static const char *zap_channel_get_uuid(zap_channel_t *channel, int32_t id) return NULL; } - if (!switch_strlen_zero(channel->tokens[id])) { + if (!zstr(channel->tokens[id])) { return channel->tokens[id]; } return NULL; @@ -202,7 +202,7 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { if (!strcasecmp(globals.hold_music, "indicate_hold")) { stream = "indicate_hold"; } @@ -211,24 +211,24 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c } } - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE); } - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { stream = SPAN_CONFIG[zchan->span->span_id].hold_music; } - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { stream = globals.hold_music; } - if (switch_strlen_zero(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { + if (zstr(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { stream = globals.hold_music; } - if (!switch_strlen_zero(stream)) { + if (!zstr(stream)) { if (!strcasecmp(stream, "indicate_hold")) { channel_a = switch_core_session_get_channel(session_a); switch_ivr_hold_uuid(uuid, NULL, 0); @@ -1052,7 +1052,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (switch_strlen_zero(outbound_profile->destination_number)) { + if (zstr(outbound_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -1088,7 +1088,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (span_id == -1 && !switch_strlen_zero(span_name)) { + if (span_id == -1 && !zstr(span_name)) { zap_span_t *span; zap_status_t zstatus = zap_span_find_by_name(span_name, &span); if (zstatus == ZAP_SUCCESS && span) { @@ -1114,7 +1114,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi caller_data.pres = 1; } - if (!switch_strlen_zero(dest)) { + if (!zstr(dest)) { zap_set_string(caller_data.ani.digits, dest); } @@ -1136,7 +1136,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi #if 0 - if (!switch_strlen_zero(outbound_profile->rdnis)) { + if (!zstr(outbound_profile->rdnis)) { zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); } #endif @@ -1166,7 +1166,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi for (h = var_event->headers; h; h = h->next) { if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { char *v = h->name + OPENZAP_VAR_PREFIX_LEN; - if (!switch_strlen_zero(v)) { + if (!zstr(v)) { zap_channel_add_var(zchan, v, h->value); } } @@ -1263,12 +1263,12 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sigmsg->channel->caller_data.collected = '\0'; - if (switch_strlen_zero(sigmsg->channel->caller_data.cid_name)) { + if (zstr(sigmsg->channel->caller_data.cid_name)) { switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); } - if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num.digits)) { - if (!switch_strlen_zero(sigmsg->channel->caller_data.ani.digits)) { + if (zstr(sigmsg->channel->caller_data.cid_num.digits)) { + if (!zstr(sigmsg->channel->caller_data.ani.digits)) { switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->caller_data.ani.digits); } else { switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->chan_number); @@ -1427,7 +1427,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (sigmsg->channel->token_count) { switch_core_session_t *session_a, *session_b, *session_t = NULL; switch_channel_t *channel_a = NULL, *channel_b = NULL; - int digits = !switch_strlen_zero(sigmsg->channel->caller_data.collected); + int digits = !zstr(sigmsg->channel->caller_data.collected); const char *br_a_uuid = NULL, *br_b_uuid = NULL; private_t *tech_pvt = NULL; @@ -1547,18 +1547,18 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; - if (switch_strlen_zero(regex)) { + if (zstr(regex)) { regex = NULL; } - if (switch_strlen_zero(fail_regex)) { + if (zstr(fail_regex)) { fail_regex = NULL; } zap_log(ZAP_LOG_DEBUG, "got DTMF sig [%s]\n", dtmf); switch_set_string(sigmsg->channel->caller_data.collected, dtmf); - if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { + if ((regex || fail_regex) && !zstr(dtmf)) { switch_regex_t *re = NULL; int ovector[30]; int match = 0; @@ -1626,17 +1626,17 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; - if (switch_strlen_zero(regex)) { + if (zstr(regex)) { regex = NULL; } - if (switch_strlen_zero(fail_regex)) { + if (zstr(fail_regex)) { fail_regex = NULL; } zap_log(ZAP_LOG_DEBUG, "R2 DNIS so far [%s]\n", sigmsg->channel->caller_data.dnis.digits); - if ((regex || fail_regex) && !switch_strlen_zero(sigmsg->channel->caller_data.dnis.digits)) { + if ((regex || fail_regex) && !zstr(sigmsg->channel->caller_data.dnis.digits)) { switch_regex_t *re = NULL; int ovector[30]; int match = 0; @@ -2647,7 +2647,7 @@ SWITCH_STANDARD_API(oz_function) char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; - if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) { + if (!zstr(cmd) && (mycmd = strdup(cmd))) { argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } @@ -2679,7 +2679,7 @@ SWITCH_STANDARD_API(oz_function) as = argv[4]; } - if (!switch_strlen_zero(as) && !strcasecmp(as, "xml")) { + if (!zstr(as) && !strcasecmp(as, "xml")) { stream->write_function(stream, "\n"); if (!span) { stream->write_function(stream, "invalid span\n"); From c6bd8b0f9f85bc4ea1b2c61635160bf3e7e34b2c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 23 Oct 2009 16:03:57 +0000 Subject: [PATCH 1560/1766] change switch_strlen_zero to zstr git-svn-id: http://svn.openzap.org/svn/openzap/trunk@847 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 50 +++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 301fefcb84..886d14a71a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -142,7 +142,7 @@ static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, in return NULL; } - if (!switch_strlen_zero(channel->tokens[id])) { + if (!zstr(channel->tokens[id])) { if (!(session = switch_core_session_locate(channel->tokens[id]))) { zap_channel_clear_token(channel, channel->tokens[id]); } @@ -157,7 +157,7 @@ static const char *zap_channel_get_uuid(zap_channel_t *channel, int32_t id) return NULL; } - if (!switch_strlen_zero(channel->tokens[id])) { + if (!zstr(channel->tokens[id])) { return channel->tokens[id]; } return NULL; @@ -202,7 +202,7 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { if (!strcasecmp(globals.hold_music, "indicate_hold")) { stream = "indicate_hold"; } @@ -211,24 +211,24 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c } } - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE); } - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { stream = SPAN_CONFIG[zchan->span->span_id].hold_music; } - if (switch_strlen_zero(stream)) { + if (zstr(stream)) { stream = globals.hold_music; } - if (switch_strlen_zero(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { + if (zstr(stream) && !(stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { stream = globals.hold_music; } - if (!switch_strlen_zero(stream)) { + if (!zstr(stream)) { if (!strcasecmp(stream, "indicate_hold")) { channel_a = switch_core_session_get_channel(session_a); switch_ivr_hold_uuid(uuid, NULL, 0); @@ -1052,7 +1052,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (switch_strlen_zero(outbound_profile->destination_number)) { + if (zstr(outbound_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -1088,7 +1088,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (span_id == -1 && !switch_strlen_zero(span_name)) { + if (span_id == -1 && !zstr(span_name)) { zap_span_t *span; zap_status_t zstatus = zap_span_find_by_name(span_name, &span); if (zstatus == ZAP_SUCCESS && span) { @@ -1114,7 +1114,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi caller_data.pres = 1; } - if (!switch_strlen_zero(dest)) { + if (!zstr(dest)) { zap_set_string(caller_data.ani.digits, dest); } @@ -1136,7 +1136,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi #if 0 - if (!switch_strlen_zero(outbound_profile->rdnis)) { + if (!zstr(outbound_profile->rdnis)) { zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); } #endif @@ -1166,7 +1166,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi for (h = var_event->headers; h; h = h->next) { if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { char *v = h->name + OPENZAP_VAR_PREFIX_LEN; - if (!switch_strlen_zero(v)) { + if (!zstr(v)) { zap_channel_add_var(zchan, v, h->value); } } @@ -1263,12 +1263,12 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sigmsg->channel->caller_data.collected = '\0'; - if (switch_strlen_zero(sigmsg->channel->caller_data.cid_name)) { + if (zstr(sigmsg->channel->caller_data.cid_name)) { switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name); } - if (switch_strlen_zero(sigmsg->channel->caller_data.cid_num.digits)) { - if (!switch_strlen_zero(sigmsg->channel->caller_data.ani.digits)) { + if (zstr(sigmsg->channel->caller_data.cid_num.digits)) { + if (!zstr(sigmsg->channel->caller_data.ani.digits)) { switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->caller_data.ani.digits); } else { switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->chan_number); @@ -1427,7 +1427,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (sigmsg->channel->token_count) { switch_core_session_t *session_a, *session_b, *session_t = NULL; switch_channel_t *channel_a = NULL, *channel_b = NULL; - int digits = !switch_strlen_zero(sigmsg->channel->caller_data.collected); + int digits = !zstr(sigmsg->channel->caller_data.collected); const char *br_a_uuid = NULL, *br_b_uuid = NULL; private_t *tech_pvt = NULL; @@ -1547,18 +1547,18 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; - if (switch_strlen_zero(regex)) { + if (zstr(regex)) { regex = NULL; } - if (switch_strlen_zero(fail_regex)) { + if (zstr(fail_regex)) { fail_regex = NULL; } zap_log(ZAP_LOG_DEBUG, "got DTMF sig [%s]\n", dtmf); switch_set_string(sigmsg->channel->caller_data.collected, dtmf); - if ((regex || fail_regex) && !switch_strlen_zero(dtmf)) { + if ((regex || fail_regex) && !zstr(dtmf)) { switch_regex_t *re = NULL; int ovector[30]; int match = 0; @@ -1626,17 +1626,17 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; - if (switch_strlen_zero(regex)) { + if (zstr(regex)) { regex = NULL; } - if (switch_strlen_zero(fail_regex)) { + if (zstr(fail_regex)) { fail_regex = NULL; } zap_log(ZAP_LOG_DEBUG, "R2 DNIS so far [%s]\n", sigmsg->channel->caller_data.dnis.digits); - if ((regex || fail_regex) && !switch_strlen_zero(sigmsg->channel->caller_data.dnis.digits)) { + if ((regex || fail_regex) && !zstr(sigmsg->channel->caller_data.dnis.digits)) { switch_regex_t *re = NULL; int ovector[30]; int match = 0; @@ -2647,7 +2647,7 @@ SWITCH_STANDARD_API(oz_function) char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; - if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) { + if (!zstr(cmd) && (mycmd = strdup(cmd))) { argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } @@ -2679,7 +2679,7 @@ SWITCH_STANDARD_API(oz_function) as = argv[4]; } - if (!switch_strlen_zero(as) && !strcasecmp(as, "xml")) { + if (!zstr(as) && !strcasecmp(as, "xml")) { stream->write_function(stream, "\n"); if (!span) { stream->write_function(stream, "invalid span\n"); From c5966d058b74cb8665fea008a0648aba072cc5a9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Nov 2009 18:58:55 +0000 Subject: [PATCH 1561/1766] clear tone_count on subsequent calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@848 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index e73f8bdd45..f81e06bd10 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1752,7 +1752,13 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan) { + uint32_t i; + memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); + + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { + zchan->span->tone_finder[i].tone_count = 0; + } } OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan) From acb36c4b9ebcc25554e10b67d00239e924050566 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Nov 2009 18:58:55 +0000 Subject: [PATCH 1562/1766] clear tone_count on subsequent calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@848 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index e73f8bdd45..f81e06bd10 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1752,7 +1752,13 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw) OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan) { + uint32_t i; + memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); + + for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { + zchan->span->tone_finder[i].tone_count = 0; + } } OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan) From 786963c0ae16feb32926563defdefb36ccfd1c40 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 6 Nov 2009 20:04:59 +0000 Subject: [PATCH 1563/1766] more tones git-svn-id: http://svn.openzap.org/svn/openzap/trunk@849 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/libteletone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/include/libteletone.h b/libs/openzap/src/include/libteletone.h index 4029facce8..6e806cec4f 100644 --- a/libs/openzap/src/include/libteletone.h +++ b/libs/openzap/src/include/libteletone.h @@ -78,7 +78,7 @@ extern "C" { #include #define TELETONE_MAX_DTMF_DIGITS 128 -#define TELETONE_MAX_TONES 6 +#define TELETONE_MAX_TONES 18 #define TELETONE_TONE_RANGE 127 typedef double teletone_process_t; From c4b491a7b12313f4dab7bc0fd94cc5fb77b4ab70 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 6 Nov 2009 20:04:59 +0000 Subject: [PATCH 1564/1766] more tones git-svn-id: http://svn.openzap.org/svn/openzap/trunk@849 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/libteletone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index 4029facce8..6e806cec4f 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -78,7 +78,7 @@ extern "C" { #include #define TELETONE_MAX_DTMF_DIGITS 128 -#define TELETONE_MAX_TONES 6 +#define TELETONE_MAX_TONES 18 #define TELETONE_TONE_RANGE 127 typedef double teletone_process_t; From 43644d049a1d7cff0deaab258919f4d54886acae Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Nov 2009 18:31:48 +0000 Subject: [PATCH 1565/1766] exit thread if too many errors occur to prevent endless loop git-svn-id: http://svn.openzap.org/svn/openzap/trunk@850 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index e45d3413db..3978c94106 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -922,14 +922,17 @@ 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; - status = zap_span_poll_event(span, waitms); + if ((status = zap_span_poll_event(span, waitms)) != ZAP_FAIL) { + errs = 0; + } switch(status) { case ZAP_SUCCESS: @@ -948,6 +951,10 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) 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: From c1323ecf10d932b99025ec6bde7c7ac85bcb1fba Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 9 Nov 2009 18:31:48 +0000 Subject: [PATCH 1566/1766] exit thread if too many errors occur to prevent endless loop git-svn-id: http://svn.openzap.org/svn/openzap/trunk@850 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index e45d3413db..3978c94106 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -922,14 +922,17 @@ 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; - status = zap_span_poll_event(span, waitms); + if ((status = zap_span_poll_event(span, waitms)) != ZAP_FAIL) { + errs = 0; + } switch(status) { case ZAP_SUCCESS: @@ -948,6 +951,10 @@ static void *zap_analog_run(zap_thread_t *me, void *obj) 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: From c0c39fcd5b6f686d3ab64c07fd734960cc9f9346 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Nov 2009 23:28:49 +0000 Subject: [PATCH 1567/1766] only build boost module if you have sctp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@852 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 14 ++++++++++++-- libs/openzap/configure.ac | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 0a942a2bfe..b74afc3a6d 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -36,7 +36,10 @@ moddir = @modinstdir@ libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include -INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost +INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include +if HAVE_SCTP +INCS += -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost +endif MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) @@ -101,7 +104,10 @@ core-install: install-libLTLIBRARIES # # tools & test programs # -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 testboost testanalog testapp testcid +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 testanalog testapp testcid +if HAVE_SCTP +noinst_PROGRAMS += testboost +endif testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -135,9 +141,11 @@ testr2_SOURCES = $(SRC)/testr2.c testr2_LDADD = libopenzap.la testr2_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +if HAVE_SCTP testboost_SOURCES = $(SRC)/testboost.c testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +endif testanalog_SOURCES = $(SRC)/testanalog.c testanalog_LDADD = libopenzap.la @@ -214,10 +222,12 @@ ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_em_la_LDFLAGS = -module -avoid-version ozmod_analog_em_la_LIBADD = $(MYLIB) +if HAVE_SCTP ozmod_sangoma_boost_la_SOURCES = $(SRC)/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c ozmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_sangoma_boost_la_LDFLAGS = -module -avoid-version ozmod_sangoma_boost_la_LIBADD = $(MYLIB) +endif if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c diff --git a/libs/openzap/configure.ac b/libs/openzap/configure.ac index 64f7a46438..f1bba93f1e 100644 --- a/libs/openzap/configure.ac +++ b/libs/openzap/configure.ac @@ -116,6 +116,8 @@ AC_CHECK_LIB([m], [cos]) AX_LIB_PCAP AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) +AM_CONDITIONAL([HAVE_SCTP],[test "${ac_cv_header_netinet_sctp_h}" = "yes"]) + AC_CHECK_FUNC([gethostbyname_r], [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] ) From 4b64c098ece0191cbedc7155660308c49914cbea Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 10 Nov 2009 23:28:49 +0000 Subject: [PATCH 1568/1766] only build boost module if you have sctp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@852 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 14 ++++++++++++-- libs/freetdm/configure.ac | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 0a942a2bfe..b74afc3a6d 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -36,7 +36,10 @@ moddir = @modinstdir@ libdir = $(PREFIX)/lib/ library_includedir = $(PREFIX)/include -INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost +INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include +if HAVE_SCTP +INCS += -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost +endif MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) @@ -101,7 +104,10 @@ core-install: install-libLTLIBRARIES # # tools & test programs # -noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 testboost testanalog testapp testcid +noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 testanalog testapp testcid +if HAVE_SCTP +noinst_PROGRAMS += testboost +endif testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -135,9 +141,11 @@ testr2_SOURCES = $(SRC)/testr2.c testr2_LDADD = libopenzap.la testr2_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +if HAVE_SCTP testboost_SOURCES = $(SRC)/testboost.c testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +endif testanalog_SOURCES = $(SRC)/testanalog.c testanalog_LDADD = libopenzap.la @@ -214,10 +222,12 @@ ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_analog_em_la_LDFLAGS = -module -avoid-version ozmod_analog_em_la_LIBADD = $(MYLIB) +if HAVE_SCTP ozmod_sangoma_boost_la_SOURCES = $(SRC)/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c ozmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) ozmod_sangoma_boost_la_LDFLAGS = -module -avoid-version ozmod_sangoma_boost_la_LIBADD = $(MYLIB) +endif if LIBPRI ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index 64f7a46438..f1bba93f1e 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -116,6 +116,8 @@ AC_CHECK_LIB([m], [cos]) AX_LIB_PCAP AC_CHECK_HEADERS([netinet/sctp.h netdb.h sys/select.h]) +AM_CONDITIONAL([HAVE_SCTP],[test "${ac_cv_header_netinet_sctp_h}" = "yes"]) + AC_CHECK_FUNC([gethostbyname_r], [], [AC_CHECK_LIB([nsl], [gethostbyname_r])] ) From 1e5fefeab8b22f6d072a008e198cb3dcc615c774 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 11 Nov 2009 18:51:03 +0000 Subject: [PATCH 1569/1766] whoops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@853 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index b74afc3a6d..d5e1e734ec 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -154,7 +154,12 @@ testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # # ozmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_sangoma_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la + + +if HAVE_SCTP +mod_LTLIBRARIES += ozmod_sangoma_boost.la +endif if LIBSANGOMA mod_LTLIBRARIES += ozmod_wanpipe.la From 087f82018733b4319ec689a4e4f6ddc3b8d83368 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 11 Nov 2009 18:51:03 +0000 Subject: [PATCH 1570/1766] whoops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@853 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index b74afc3a6d..d5e1e734ec 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -154,7 +154,12 @@ testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # # ozmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la ozmod_sangoma_boost.la +mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la + + +if HAVE_SCTP +mod_LTLIBRARIES += ozmod_sangoma_boost.la +endif if LIBSANGOMA mod_LTLIBRARIES += ozmod_wanpipe.la From 3bbcd5369a04683d294340795c1dae6a5f12f835 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 11 Nov 2009 20:19:39 +0000 Subject: [PATCH 1571/1766] fix windows compiler warning-error: unsigned vs signed comparison git-svn-id: http://svn.openzap.org/svn/openzap/trunk@855 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f81e06bd10..5d6910db48 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -705,7 +705,7 @@ OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token) { - int i; + unsigned int i; if (zchan->token_count) { for(i = 0; i < zchan->token_count; i++) { From 66adb741e7b898aefdd59a608da41b1784c00bf2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 12 Nov 2009 19:47:04 +0000 Subject: [PATCH 1572/1766] added sangoma boost sigmod interface git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@856 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 12 ++ .../sangoma_boost_client.c | 2 +- .../sangoma_boost_client.h | 4 + .../sangoma_boost_sigmod.h | 161 ++++++++++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 72c467c398..bff8488379 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -179,6 +179,18 @@ typedef enum { ZAP_SIGTYPE_R2 } zap_signal_type_t; +/*! + \brief Signaling status on the channel + */ +typedef enum { + /* The channel signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */ + ZAP_SIG_STATE_DOWN, + /* The channel signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */ + ZAP_SIG_STATE_SUSPENDED, + /* The channel signaling link is ready and calls can be placed */ + ZAP_SIG_STATE_UP +} zap_channel_sig_status_t; + typedef enum { ZAP_SIGEVENT_START, ZAP_SIGEVENT_STOP, diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index f0ecef1b97..164156b5c1 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -36,7 +36,7 @@ #endif #include "openzap.h" -#include +#include "sangoma_boost_client.h" #ifndef HAVE_GETHOSTBYNAME_R diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index 1b86c5df01..9ed2c5f35e 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -34,6 +34,8 @@ #ifndef _SANGOMABC_H #define _SANGOMABC_H +#include "sangoma_boost_sigmod.h" + #include #include #include @@ -104,6 +106,8 @@ struct sangomabc_connection { unsigned int rxseq_reset; sangomabc_ip_cfg_t cfg; uint32_t hb_elapsed; + /* boost signaling mod interface pointer (if not working in TCP mode) */ + boost_sigmod_interface_t *sigmod; }; typedef struct sangomabc_connection sangomabc_connection_t; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h new file mode 100644 index 0000000000..072558b269 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h @@ -0,0 +1,161 @@ +/* + * 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. + */ + +#ifndef SANGOMA_BOOST_SIGMOD_H +#define SANGOMA_BOOST_SIGMOD_H + +#include "zap_types.h" + +/*! + \brief Callback used to notify signaling status changes on a channel + \param zchan The openzap channel where the signaling status just changed + \param status The new signaling status + */ +#define BOOST_SIG_STATUS_CB_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t status) +typedef void (*boost_sig_status_cb_func_t) BOOST_SIG_STATUS_CB_ARGS; +#define BOOST_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SIG_STATUS_CB_ARGS + +/*! + \brief Write a boost msg to a boost endpoint + \param msg The generic message pointer, owned by the caller + \param msglen The length of the provided structure pointed by msg + \return ZAP_SUCCESS or ZAP_FAIL + + The msg buffer is owned by the caller and it should + be either t_sigboost_callstart or t_sigboost_short + the endpoint receiving the msg will first cast to + t_sigboost_short, check the event type, and if needed. + */ +#define BOOST_WRITE_MSG_ARGS (void *msg, zap_size_t msglen) +typedef zap_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS; +#define BOOST_WRITE_MSG_FUNCTION(name) zap_status_t name BOOST_WRITE_MSG_ARGS + +/*! + \brief Set the callback to be used by a signaling module to write boost messages + \param callback The callback to be used by the signaling module + + The provided callback will be used for the signaling boost module to notify the + user with boost messages. + */ +#define BOOST_SET_WRITE_MSG_CB_ARGS (boost_write_msg_func_t callback) +typedef void (*boost_set_write_msg_cb_func_t) BOOST_SET_WRITE_MSG_CB_ARGS; +#define BOOST_SET_WRITE_MSG_CB_FUNCTION(name) void name BOOST_SET_WRITE_MSG_CB_ARGS + +/*! + \brief Set signaling status callback used by the signaling module to report signaling status changes + \param callback The callback to be used by the signaling module + + The provided callback will be used for the signaling boost module to notify the + user with signaling link status changes. + */ +#define BOOST_SET_SIG_STATUS_CB_ARGS (boost_sig_status_cb_func_t callback) +typedef void (*boost_set_sig_status_cb_func_t) BOOST_SET_SIG_STATUS_CB_ARGS; +#define BOOST_SET_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SET_SIG_STATUS_CB_ARGS + +/*! + \brief Get the signaling status on the given channel. + \param zchan The openzap channel + \param status The status pointer where the current signaling status will be set + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t *status) +typedef zap_status_t (*boost_get_sig_status_func_t) BOOST_GET_SIG_STATUS_ARGS; +#define BOOST_GET_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_SIG_STATUS_ARGS + +/*! + \brief Set the signaling status on the given channel. + \param zchan The openzap channel + \param status The new status for the channel + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_SET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t status) +typedef zap_status_t (*boost_set_sig_status_func_t) BOOST_SET_SIG_STATUS_ARGS; +#define BOOST_SET_SIG_STATUS_FUNCTION(name) zap_status_t BOOST_SET_SIG_STATUS_ARGS + +/*! + \brief Configure the given span signaling + \param span The openzap span + \param ap The list of configuration key,value pairs (must be null terminated) + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_CONFIGURE_SPAN_ARGS (zap_span_t *span, va_list ap) +typedef zap_status_t (*boost_configure_span_func_t) BOOST_CONFIGURE_SPAN_ARGS; +#define BOOST_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name BOOST_CONFIGURE_SPAN_ARGS + +/*! + \brief Start the given span + \param span The openzap span + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_START_SPAN_ARGS (zap_span_t *span) +typedef zap_status_t (*boost_start_span_func_t) BOOST_START_SPAN_ARGS; +#define BOOST_START_SPAN_FUNCTION(name) zap_status_t name BOOST_START_SPAN_ARGS + +/*! + \brief Stop the given span + \param span The openzap span + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_STOP_SPAN_ARGS (zap_span_t *span) +typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; +#define BOOST_STOP_SPAN_FUNCTION(name) zap_status_t name BOOST_STOP_SPAN_ARGS + +/*! + \brief The boost signaling module interface + */ +typedef struct boost_sigmod_interface_s { + const char *name; + boost_write_msg_func_t write_msg; + boost_set_write_msg_cb_func_t set_write_msg_cb; + boost_set_sig_status_cb_func_t set_sig_status_cb; + boost_get_sig_status_func_t get_sig_status; + boost_set_sig_status_func_t set_sig_status; + boost_configure_span_func_t configure_span; + boost_start_span_func_t start_span; + boost_stop_span_func_t stop_stpan; +} boost_sigmod_interface_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: + */ + From 890cba5ba1f47b89f8eec2f8d26c6540115d28e4 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 13 Nov 2009 00:41:50 +0000 Subject: [PATCH 1573/1766] refactoring to use function call based boost instead of sockets git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@857 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 303 ++++++++++++++---- .../sangoma_boost_client.c | 23 +- .../sangoma_boost_sigmod.h | 13 +- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 4 + libs/freetdm/src/zap_io.c | 27 +- 6 files changed, 288 insertions(+), 83 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 2c7d132b3b..9e90209440 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -683,6 +683,7 @@ OZ_DECLARE(zap_status_t) zap_unload_modules(void); OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); +OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len); OZ_DECLARE(int) zap_load_module(const char *name); OZ_DECLARE(int) zap_load_module_assume(const char *name); OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 947c9c8754..349b5133ee 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -38,6 +38,10 @@ #include #endif +/* Boost signaling modules global hash and its mutex */ +zap_mutex_t *g_boost_modules_mutex = NULL; +zap_hash_t *g_boost_modules_hash = NULL; + #define MAX_TRUNK_GROUPS 64 static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; @@ -1118,6 +1122,90 @@ static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) return NULL; } +static int zap_boost_connection_open(zap_span_t *span) +{ + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + if (sangoma_boost_data->sigmod) { + return 0; + } + + 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_DEBUG, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); + return -1; + } + + 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_DEBUG, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); + return -1; + } + return 0; +} + +/*! + \brief wait for a boost event + \return -1 on error, 0 on timeout, 1 when there are events + */ +static int zap_boost_wait_event(zap_span_t *span, int ms) +{ + struct timeval tv = { 0, ms * 1000 }; + int max, activity; + sangomabc_connection_t *mcon, *pcon; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + + mcon = &sangoma_boost_data->mcon; + pcon = &sangoma_boost_data->pcon; + + FD_ZERO(&sangoma_boost_data->rfds); + FD_ZERO(&sangoma_boost_data->efds); + FD_SET(mcon->socket, &sangoma_boost_data->rfds); + FD_SET(mcon->socket, &sangoma_boost_data->efds); + FD_SET(pcon->socket, &sangoma_boost_data->rfds); + FD_SET(pcon->socket, &sangoma_boost_data->efds); + sangoma_boost_data->iteration = 0; + + max = ((pcon->socket > mcon->socket) ? pcon->socket : mcon->socket) + 1; + if ((activity = select(max, &sangoma_boost_data->rfds, NULL, &sangoma_boost_data->efds, &tv)) < 0) { + return -1; + } + + if (FD_ISSET(pcon->socket, &sangoma_boost_data->efds) || FD_ISSET(mcon->socket, &sangoma_boost_data->efds)) { + return -1; + } + + return 1; +} + + +static sangomabc_event_t *zap_boost_read_event(zap_span_t *span) +{ + sangomabc_event_t *event = NULL; + sangomabc_connection_t *mcon, *pcon; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + + mcon = &sangoma_boost_data->mcon; + pcon = &sangoma_boost_data->pcon; + + if (sangoma_boost_data->sigmod || FD_ISSET(pcon->socket, &sangoma_boost_data->rfds)) { + event = sangomabc_connection_readp(pcon, sangoma_boost_data->iteration); + } + + /* if there is no event and this is not a sigmod-driven span it's time to try the other connection for events */ + if (!event && !sangoma_boost_data->sigmod && FD_ISSET(mcon->socket, &sangoma_boost_data->rfds)) { + event = sangomabc_connection_readp(mcon, sangoma_boost_data->iteration); + } + return event; +} + /** * \brief Main thread function for sangoma boost span (monitor) * \param me Current thread @@ -1126,33 +1214,20 @@ static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) 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; - + uint32_t ms = 10; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - sangoma_boost_data->pcon = sangoma_boost_data->mcon; + if (zap_boost_connection_open(span) < 0) { + goto end; + } - 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_DEBUG, "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_DEBUG, "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; + pcon = &sangoma_boost_data->pcon; + + /* sigmod overrides socket functionality if not null */ + mcon->sigmod = sangoma_boost_data->sigmod; + pcon->sigmod = sangoma_boost_data->sigmod; init_outgoing_array(); @@ -1165,10 +1240,8 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) zap_set_flag(mcon, MSU_FLAG_DOWN); while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING)) { - fd_set rfds, efds; - struct timeval tv = { 0, ms * 1000 }; - int max, activity, i = 0; sangomabc_event_t *event = NULL; + int activity = 0; if (!zap_running()) { sangomabc_exec_commandp(pcon, @@ -1181,37 +1254,15 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) 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; - - if ((activity = select(max, &rfds, NULL, &efds, &tv)) < 0) { + if ((activity = zap_boost_wait_event(span, ms)) < 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++; - } + while ((event = zap_boost_read_event(span))) { + parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event); + sangoma_boost_data->iteration++; } } @@ -1246,7 +1297,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) goto end; error: - zap_log(ZAP_LOG_CRIT, "Socket Error!\n"); + zap_log(ZAP_LOG_CRIT, "Boost event processing Error!\n"); end: @@ -1255,7 +1306,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); - zap_log(ZAP_LOG_DEBUG, "SANGOMA_BOOST thread ended.\n"); + zap_log(ZAP_LOG_DEBUG, "Sangoma Boost thread ended.\n"); return NULL; } @@ -1266,9 +1317,35 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) */ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { + g_boost_modules_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys); + if (!g_boost_modules_hash) { + return ZAP_FAIL; + } zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); - + zap_mutex_create(&g_boost_modules_mutex); + return ZAP_SUCCESS; +} + +static ZIO_SIG_UNLOAD_FUNCTION(zap_sangoma_boost_destroy) +{ + zap_hash_iterator_t *i = NULL; + boost_sigmod_interface_t *sigmod = NULL; + const void *key = NULL; + void *val = NULL; + + for (i = hashtable_first(g_boost_modules_hash); i; i = hashtable_next(i)) { + hashtable_this(i, &key, NULL, &val); + if (key && val) { + sigmod = val; + zap_dso_destroy(sigmod->pvt); + } + } + + hashtable_destroy(g_boost_modules_hash); + zap_mutex_destroy(&request_mutex); + zap_mutex_destroy(&signal_mutex); + zap_mutex_destroy(&g_boost_modules_mutex); return ZAP_SUCCESS; } @@ -1291,6 +1368,15 @@ static zap_status_t zap_sangoma_boost_start(zap_span_t *span) return err; } +static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) +{ + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + if (sangoma_boost_data->sigmod) { + return sangoma_boost_data->sigmod->stop_span(span); + } + return ZAP_SUCCESS; +} + static zap_state_map_t boost_state_map = { { { @@ -1390,6 +1476,19 @@ static zap_state_map_t boost_state_map = { } }; +static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) +{ + /* TODO: write to msg queue and kick the pthread condition */ + return ZAP_SUCCESS; +} + +static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) +{ + /* TODO: Notify the upper layer of the signaling status change (via span signaling callback and a new msg type?) */ + return; +} + + /** * \brief Initialises an sangoma boost span from configuration variables * \param span Span to configure @@ -1399,14 +1498,41 @@ static zap_state_map_t boost_state_map = { */ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) { +#define FAIL_CONFIG_RETURN(retstatus) \ + if (sangoma_boost_data) \ + zap_safe_free(sangoma_boost_data); \ + if (err) \ + zap_safe_free(err) \ + if (hash_locked) \ + zap_mutex_unlock(g_boost_modules_mutex); \ + if (lib) \ + zap_dso_destroy(lib); \ + va_end(conflist); \ + return retstatus; + + boost_sigmod_interface_t *sigmod_iface = NULL; zap_sangoma_boost_data_t *sangoma_boost_data = NULL; const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; + const char *sigmod = NULL; int local_port = 53000, remote_port = 53000; - char *var, *val; - int *intval; + char *var = NULL, *val = NULL; + int *intval = NULL; + int hash_locked = 0; + zap_dso_lib_t lib = NULL; + char path[255] = ""; + char *err = NULL; + va_list conflist; + + /* we need to copy the list before moving with va_arg in case this configuration should be handled by a sigmod */ + va_copy(conflist, ap); /* WARNING: must be freed before returning */ while((var = va_arg(ap, char *))) { - if (!strcasecmp(var, "local_ip")) { + if (!strcasecmp(var, "sigmod")) { + if (!(val = va_arg(ap, char *))) { + break; + } + sigmod = val; + } else if (!strcasecmp(var, "local_ip")) { if (!(val = va_arg(ap, char *))) { break; } @@ -1428,26 +1554,63 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) remote_port = *intval; } else { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); - return ZAP_FAIL; + FAIL_CONFIG_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; + if (!sigmod) { + if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { + zap_set_string(span->last_error, "missing Sangoma boost IP parameters"); + FAIL_CONFIG_RETURN(ZAP_FAIL); + } } sangoma_boost_data = malloc(sizeof(*sangoma_boost_data)); - assert(sangoma_boost_data); + if (!sangoma_boost_data) { + FAIL_CONFIG_RETURN(ZAP_FAIL); + } 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; + + /* WARNING: be sure to release this mutex on errors inside this if() */ + zap_mutex_lock(g_boost_modules_mutex); + hash_locked = 1; + if (sigmod && !(sigmod_iface = hashtable_search(g_boost_modules_hash, (void *)sigmod))) { + zap_build_dso_path(sigmod, path, sizeof(path)); + lib = zap_dso_open(path, &err); + if (!lib) { + zap_log(ZAP_LOG_ERROR, "Error loading Sangoma boost signaling module '%s': %s\n", path, err); + snprintf(span->last_error, sizeof(span->last_error), "Failed to load sangoma boost signaling module %s", path); + + FAIL_CONFIG_RETURN(ZAP_FAIL); + } + if (!(sigmod_iface = (boost_sigmod_interface_t *)zap_dso_func_sym(lib, "boost_sigmod_interface", &err))) { + zap_log(ZAP_LOG_ERROR, "Failed to read Sangoma boost signaling module interface '%s': %s\n", path, err); + snprintf(span->last_error, sizeof(span->last_error), "Failed to read Sangoma boost signaling module interface '%s': %s", path, err); + + FAIL_CONFIG_RETURN(ZAP_FAIL); + } + sigmod_iface->pvt = lib; + sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); + sigmod_iface->set_write_msg_cb(zap_boost_write_msg); + hashtable_insert(g_boost_modules_hash, (void *)sigmod_iface->name, sigmod_iface, HASHTABLE_FLAG_NONE); + } + zap_mutex_unlock(g_boost_modules_mutex); + hash_locked = 0; + + if (sigmod_iface) { + zap_log(ZAP_LOG_NOTICE, "Span %s will use Sangoma Boost Signaling Module %s\n", span->name, sigmod_iface->name); + sangoma_boost_data->sigmod = sigmod_iface; + sigmod_iface->configure_span(span, conflist); + } else { + 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; + } sangoma_boost_data->signal_cb = sig_cb; span->start = zap_sangoma_boost_start; + span->stop = zap_sangoma_boost_stop; span->signal_data = sangoma_boost_data; span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; span->outgoing_call = sangoma_boost_outgoing_call; @@ -1455,6 +1618,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) span->state_map = &boost_state_map; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + va_end(conflist); + return ZAP_SUCCESS; } @@ -1467,7 +1632,7 @@ zap_module_t zap_module = { NULL, zap_sangoma_boost_init, zap_sangoma_boost_configure_span, - NULL + zap_sangoma_boost_destroy }; /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 164156b5c1..ec9ce3eaa7 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -113,6 +113,11 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int char buf[512], local_buf[512]; int err = 0, local_err = 0; + if (mcon->sigmod) { + zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); + return 0; + } + memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp)); memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); #ifdef HAVE_NETINET_SCTP_H @@ -175,6 +180,10 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int int sangomabc_connection_close(sangomabc_connection_t *mcon) { + if (mcon->sigmod) { + zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); + return 0; + } if (mcon->socket > -1) { close(mcon->socket); } @@ -192,6 +201,10 @@ 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) { + if (mcon->sigmod) { + zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); + return 0; + } create_conn_socket(mcon, local_ip, local_port, ip, port); return mcon->socket; } @@ -261,8 +274,14 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int 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 (mcon->sigmod) { + /* TODO: implement me */ + zap_log(ZAP_LOG_ERROR, "__sangomabc_connection_read not implemented yet for signaling modules\n"); + return NULL; + } else { + bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, + (struct sockaddr *) &mcon->local_addr, &fromlen); + } if (bytes <= 0) { return NULL; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h index 072558b269..6fd9d071e3 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h @@ -135,15 +135,26 @@ typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; \brief The boost signaling module interface */ typedef struct boost_sigmod_interface_s { + /*! \brief Module name */ const char *name; + /*! \brief write boost message function */ boost_write_msg_func_t write_msg; + /*! \brief set the user write boost message function */ boost_set_write_msg_cb_func_t set_write_msg_cb; + /*! \brief set the user signaling status function */ boost_set_sig_status_cb_func_t set_sig_status_cb; + /*! \brief get channel signaling status */ boost_get_sig_status_func_t get_sig_status; + /*! \brief set channel signaling status */ boost_set_sig_status_func_t set_sig_status; + /*! \brief configure span signaling */ boost_configure_span_func_t configure_span; + /*! \brief start openzap span */ boost_start_span_func_t start_span; - boost_stop_span_func_t stop_stpan; + /*! \brief stop openzap span */ + boost_stop_span_func_t stop_span; + /*! \brief private pointer for the interface user */ + void *pvt; } boost_sigmod_interface_t; #endif diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h index 932787c93a..8459e0883b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -44,8 +44,12 @@ typedef enum { typedef struct zap_sangoma_boost_data { sangomabc_connection_t mcon; sangomabc_connection_t pcon; + fd_set rfds; + fd_set efds; + int iteration; zio_signal_cb_t signal_cb; uint32_t flags; + boost_sigmod_interface_t *sigmod; } zap_sangoma_boost_data_t; #endif diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f81e06bd10..1ae1796057 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2528,14 +2528,8 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) return ZAP_SUCCESS; } -OZ_DECLARE(int) zap_load_module(const char *name) +OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len) { - zap_dso_lib_t lib; - int count = 0, x = 0; - char path[128] = ""; - char *err; - zap_module_t *mod; - #ifdef WIN32 const char *ext = ".dll"; //const char *EXT = ".DLL"; @@ -2547,13 +2541,24 @@ OZ_DECLARE(int) zap_load_module(const char *name) const char *ext = ".so"; //const char *EXT = ".SO"; #endif - if (*name == *ZAP_PATH_SEPARATOR) { - snprintf(path, sizeof(path), "%s%s", name, ext); + snprintf(path, len, "%s%s", name, ext); } else { - snprintf(path, sizeof(path), "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, name, ext); + snprintf(path, len, "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, name, ext); } - + return path; +} + +OZ_DECLARE(int) zap_load_module(const char *name) +{ + zap_dso_lib_t lib; + int count = 0, x = 0; + char path[128] = ""; + char *err; + zap_module_t *mod; + + zap_build_dso_path(name, path, sizeof(path)); + if (!(lib = zap_dso_open(path, &err))) { zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); zap_safe_free(err); From 19a706877b4494d9bcca2d5dfed33dc7ef97a4d7 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 13 Nov 2009 20:48:06 +0000 Subject: [PATCH 1574/1766] added openzap queue stuff, still missing implementation git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@858 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 17 +++++- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 56 +++++++++++++------ .../sangoma_boost_client.c | 34 +++++++++-- .../sangoma_boost_client.h | 7 +++ .../sangoma_boost_sigmod.h | 3 +- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 1 + 6 files changed, 94 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 9e90209440..aa05136378 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -577,7 +577,6 @@ struct zap_span { struct zap_span *next; }; - OZ_DECLARE_DATA extern zap_logger_t zap_log; struct zap_io_interface { @@ -598,6 +597,22 @@ struct zap_io_interface { zio_api_t api; }; +typedef void* zap_queue_t; + +/*! brief create a new queue */ +OZ_DECLARE(zap_queue_t) zap_queue_create(void); + +/*! Enqueue an object */ +OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t queue, void *obj); + +/*! dequeue an object from the queue */ +OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t queue); + +/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ +OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t queue, int ms); + +/*! destroy the queue */ +OZ_DECLARE(void) zap_queue_destroy(zap_queue_t *queue); OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 349b5133ee..688397d870 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1122,11 +1122,11 @@ static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) return NULL; } -static int zap_boost_connection_open(zap_span_t *span) +static zap_status_t zap_boost_connection_open(zap_span_t *span) { zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - return 0; + return sangoma_boost_data->sigmod->start_span(span); } sangoma_boost_data->pcon = sangoma_boost_data->mcon; @@ -1136,8 +1136,8 @@ static int zap_boost_connection_open(zap_span_t *span) 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_DEBUG, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); - return -1; + zap_log(ZAP_LOG_ERROR, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); + return ZAP_FAIL; } if (sangomabc_connection_open(&sangoma_boost_data->pcon, @@ -1145,10 +1145,10 @@ static int zap_boost_connection_open(zap_span_t *span) ++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_DEBUG, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); - return -1; + zap_log(ZAP_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); + return ZAP_FAIL; } - return 0; + return ZAP_SUCCESS; } /*! @@ -1218,16 +1218,20 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) uint32_t ms = 10; zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - if (zap_boost_connection_open(span) < 0) { - goto end; - } - mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; - /* sigmod overrides socket functionality if not null */ - mcon->sigmod = sangoma_boost_data->sigmod; - pcon->sigmod = sangoma_boost_data->sigmod; + if (sangoma_boost_data->sigmod) { + /* sigmod overrides socket functionality if not null */ + mcon->sigmod = sangoma_boost_data->sigmod; + pcon->sigmod = sangoma_boost_data->sigmod; + mcon->span = span; + pcon->span = span; + } + + if (zap_boost_connection_open(span) != ZAP_SUCCESS) { + goto end; + } init_outgoing_array(); @@ -1370,9 +1374,15 @@ static zap_status_t zap_sangoma_boost_start(zap_span_t *span) static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) { + zap_status_t status = ZAP_SUCCESS; zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - return sangoma_boost_data->sigmod->stop_span(span); + /* FIXME: we should make sure the span thread is stopped (use pthread_kill or openzap thread kill function) */ + /* I think stopping the span before destroying the queue makes sense + otherwise may be boost events would still arrive when the queue is already destroyed! */ + status = sangoma_boost_data->sigmod->stop_span(span); + zap_queue_destroy(sangoma_boost_data->boost_queue); + return status; } return ZAP_SUCCESS; } @@ -1478,7 +1488,14 @@ static zap_state_map_t boost_state_map = { static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) { - /* TODO: write to msg queue and kick the pthread condition */ + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + sangomabc_queue_element_t *element = malloc(sizeof(*element)); + if (!element) { + return ZAP_FAIL; + } + memcpy(&element->boostmsg, msg, msglen); + element->size = msglen; + zap_queue_enqueue(sangoma_boost_data->boost_queue, element); return ZAP_SUCCESS; } @@ -1594,11 +1611,18 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); sigmod_iface->set_write_msg_cb(zap_boost_write_msg); hashtable_insert(g_boost_modules_hash, (void *)sigmod_iface->name, sigmod_iface, HASHTABLE_FLAG_NONE); + lib = NULL; /* destroying the lib will be done when going down and NOT on FAIL_CONFIG_RETURN */ } zap_mutex_unlock(g_boost_modules_mutex); hash_locked = 0; if (sigmod_iface) { + /* try to create the boost queue */ + sangoma_boost_data->boost_queue = zap_queue_create(); + if (!sangoma_boost_data->boost_queue) { + zap_log(ZAP_LOG_ERROR, "Span %s could not create its boost queue!\n", span->name); + FAIL_CONFIG_RETURN(ZAP_FAIL); + } zap_log(ZAP_LOG_NOTICE, "Span %s will use Sangoma Boost Signaling Module %s\n", span->name, sigmod_iface->name); sangoma_boost_data->sigmod = sigmod_iface; sigmod_iface->configure_span(span, conflist); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index ec9ce3eaa7..cf421aa4fa 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -273,11 +273,13 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int unsigned int fromlen = sizeof(struct sockaddr_in); int bytes = 0; int msg_ok = 0; + sangomabc_queue_element_t *e = NULL; if (mcon->sigmod) { - /* TODO: implement me */ - zap_log(ZAP_LOG_ERROR, "__sangomabc_connection_read not implemented yet for signaling modules\n"); - return NULL; + e = zap_queue_dequeue(mcon->boost_queue); + bytes = e->size; + memcpy(&mcon->event, e->boostmsg, bytes); + zap_safe_free(e); } else { bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); @@ -362,8 +364,16 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in { unsigned int fromlen = sizeof(struct sockaddr_in); int bytes = 0; + sangomabc_queue_element_t *e = NULL; - bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); + if (mcon->sigmod) { + e = zap_queue_dequeue(mcon->boost_queue); + bytes = e->size; + memcpy(&mcon->event, e->boostmsg, bytes); + zap_safe_free(e); + } else { + bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); + } if (bytes <= 0) { return NULL; @@ -434,7 +444,13 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t } 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)); + + if (mcon->sigmod) { + mcon->sigmod->write_msg(mcon->span, event, event_size); + err = event_size; + } else { + err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); + } zap_mutex_unlock(mcon->mutex); @@ -470,7 +486,13 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ 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)); + if (mcon->sigmod) { + mcon->sigmod->write_msg(mcon->span, event, event_size); + err = event_size; + return -1; + } else { + 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) { diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index 9ed2c5f35e..a18d3e7eeb 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -108,10 +108,17 @@ struct sangomabc_connection { uint32_t hb_elapsed; /* boost signaling mod interface pointer (if not working in TCP mode) */ boost_sigmod_interface_t *sigmod; + zap_queue_t boost_queue; + zap_span_t *span; }; typedef struct sangomabc_connection sangomabc_connection_t; +typedef struct sangomabc_queue_element { + unsigned char boostmsg[sizeof(sangomabc_event_t)]; + zap_size_t size; +} sangomabc_queue_element_t; + /* disable nagle's algorythm */ static inline void sctp_no_nagle(int socket) { diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h index 6fd9d071e3..441536c74f 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h @@ -48,6 +48,7 @@ typedef void (*boost_sig_status_cb_func_t) BOOST_SIG_STATUS_CB_ARGS; /*! \brief Write a boost msg to a boost endpoint + \param span The openzap span where this msg was generated \param msg The generic message pointer, owned by the caller \param msglen The length of the provided structure pointed by msg \return ZAP_SUCCESS or ZAP_FAIL @@ -57,7 +58,7 @@ typedef void (*boost_sig_status_cb_func_t) BOOST_SIG_STATUS_CB_ARGS; the endpoint receiving the msg will first cast to t_sigboost_short, check the event type, and if needed. */ -#define BOOST_WRITE_MSG_ARGS (void *msg, zap_size_t msglen) +#define BOOST_WRITE_MSG_ARGS (zap_span_t *span, void *msg, zap_size_t msglen) typedef zap_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS; #define BOOST_WRITE_MSG_FUNCTION(name) zap_status_t name BOOST_WRITE_MSG_ARGS diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h index 8459e0883b..fc2fc953fd 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -50,6 +50,7 @@ typedef struct zap_sangoma_boost_data { zio_signal_cb_t signal_cb; uint32_t flags; boost_sigmod_interface_t *sigmod; + zap_queue_t boost_queue; } zap_sangoma_boost_data_t; #endif From c46160b4ff387e6bd97fb919f9bb8f0990d4c49f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 13 Nov 2009 21:28:09 +0000 Subject: [PATCH 1575/1766] added zap_queue.c git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@859 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 1 + libs/freetdm/src/include/openzap.h | 2 +- libs/freetdm/src/zap_queue.c | 75 ++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 libs/freetdm/src/zap_queue.c diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index d5e1e734ec..88d2a59815 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -62,6 +62,7 @@ libopenzap_la_SOURCES = \ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ $(SRC)/zap_io.c \ +$(SRC)/zap_queue.c \ $(SRC)/zap_config.c \ $(SRC)/zap_callerid.c \ $(SRC)/fsk.c \ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index aa05136378..8c98240395 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -612,7 +612,7 @@ OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t queue); OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t queue, int ms); /*! destroy the queue */ -OZ_DECLARE(void) zap_queue_destroy(zap_queue_t *queue); +OZ_DECLARE(void) zap_queue_destroy(zap_queue_t queue); OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c new file mode 100644 index 0000000000..24f3dcaf51 --- /dev/null +++ b/libs/freetdm/src/zap_queue.c @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#ifndef ZAP_QUEUE_H +#define ZAP_QUEUE_H + +#include "openzap.h" + +OZ_DECLARE(zap_queue_t) zap_queue_create(void) +{ + return NULL; +} + +OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t queue, void *obj) +{ + return ZAP_FAIL; +} + +OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t queue) +{ + return NULL; +} + +OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t queue, int ms) +{ + return ZAP_FAIL; +} + +OZ_DECLARE(void) zap_queue_destroy(zap_queue_t queue) +{ + +} +#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: + */ From e7a5ecacb149b19da852dbea035b4a40c5b59be0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 14 Nov 2009 02:04:38 +0000 Subject: [PATCH 1576/1766] finished zap queue and zap conditions implementation for Linux git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@860 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 30 +++- libs/freetdm/src/include/zap_threadmutex.h | 9 ++ libs/freetdm/src/include/zap_types.h | 1 - .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 21 +-- .../sangoma_boost_client.h | 2 +- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 2 +- libs/freetdm/src/zap_io.c | 7 + libs/freetdm/src/zap_queue.c | 138 ++++++++++++++++-- libs/freetdm/src/zap_threadmutex.c | 92 ++++++++++++ 9 files changed, 274 insertions(+), 28 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 8c98240395..8f135e173c 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -579,6 +579,13 @@ struct zap_span { OZ_DECLARE_DATA extern zap_logger_t zap_log; +typedef enum { + ZAP_CRASH_NEVER = 0, + ZAP_CRASH_ON_ASSERT +} zap_crash_policy_t; + +OZ_DECLARE_DATA extern zap_crash_policy_t g_zap_crash_policy; + struct zap_io_interface { const char *name; zio_configure_span_t configure_span; @@ -597,22 +604,23 @@ struct zap_io_interface { zio_api_t api; }; -typedef void* zap_queue_t; +struct zap_queue; +#define zap_queue_t struct zap_queue /*! brief create a new queue */ -OZ_DECLARE(zap_queue_t) zap_queue_create(void); +OZ_DECLARE(zap_status_t) zap_queue_create(zap_queue_t **queue, zap_size_t size); /*! Enqueue an object */ -OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t queue, void *obj); +OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t *queue, void *obj); /*! dequeue an object from the queue */ -OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t queue); +OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t *queue); /*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ -OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t queue, int ms); +OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms); /*! destroy the queue */ -OZ_DECLARE(void) zap_queue_destroy(zap_queue_t queue); +OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **queue); OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); @@ -683,6 +691,7 @@ OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *v OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_global_init(void); OZ_DECLARE(zap_status_t) zap_global_destroy(void); +OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy); OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger); OZ_DECLARE(void) zap_global_set_default_logger(int level); OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen); @@ -722,6 +731,15 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) #endif +#define zap_assert(assertion, retval, msg) \ + if (!(assertion)) { \ + zap_log(ZAP_LOG_CRIT, msg); \ + if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ + abort(); \ + } else { \ + return retval; \ + } \ + } static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state) { diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index 6e2af571ac..f131c48cf0 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -15,6 +15,10 @@ * constitutes an essential part of this license. No use of any covered code is authorized hereunder * except under this disclaimer. * + * Contributors: + * + * Moises Silva + * */ @@ -25,6 +29,7 @@ typedef struct zap_mutex zap_mutex_t; typedef struct zap_thread zap_thread_t; +typedef struct zap_condition zap_condition_t; typedef void *(*zap_thread_function_t) (zap_thread_t *, void *); OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data); @@ -35,6 +40,10 @@ OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex); OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex); OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex); OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex); +OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **cond, zap_mutex_t *mutex); +OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **cond); +OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *cond); +OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *cond, int ms); #endif diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index bff8488379..e8fe8bd78f 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -619,7 +619,6 @@ typedef enum { ZAP_CAUSE_MEDIA_TIMEOUT = 604 } zap_call_cause_t; - #endif /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 688397d870..c1f7f74588 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -45,6 +45,8 @@ zap_hash_t *g_boost_modules_hash = NULL; #define MAX_TRUNK_GROUPS 64 static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; +#define BOOST_QUEUE_SIZE 500 + /** * \brief Strange flag */ @@ -1221,12 +1223,15 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; + /* sigmod overrides socket functionality if not null */ if (sangoma_boost_data->sigmod) { - /* sigmod overrides socket functionality if not null */ - mcon->sigmod = sangoma_boost_data->sigmod; - pcon->sigmod = sangoma_boost_data->sigmod; mcon->span = span; pcon->span = span; + /* everything could be retrieved through span, but let's use shortcuts */ + mcon->sigmod = sangoma_boost_data->sigmod; + pcon->sigmod = sangoma_boost_data->sigmod; + mcon->boost_queue = sangoma_boost_data->boost_queue; + pcon->boost_queue = sangoma_boost_data->boost_queue; } if (zap_boost_connection_open(span) != ZAP_SUCCESS) { @@ -1381,7 +1386,7 @@ static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) /* I think stopping the span before destroying the queue makes sense otherwise may be boost events would still arrive when the queue is already destroyed! */ status = sangoma_boost_data->sigmod->stop_span(span); - zap_queue_destroy(sangoma_boost_data->boost_queue); + zap_queue_destroy(&sangoma_boost_data->boost_queue); return status; } return ZAP_SUCCESS; @@ -1489,7 +1494,7 @@ static zap_state_map_t boost_state_map = { static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) { zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - sangomabc_queue_element_t *element = malloc(sizeof(*element)); + sangomabc_queue_element_t *element = calloc(1, sizeof(*element)); if (!element) { return ZAP_FAIL; } @@ -1583,11 +1588,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) } } - sangoma_boost_data = malloc(sizeof(*sangoma_boost_data)); + sangoma_boost_data = calloc(1, sizeof(*sangoma_boost_data)); if (!sangoma_boost_data) { FAIL_CONFIG_RETURN(ZAP_FAIL); } - memset(sangoma_boost_data, 0, sizeof(*sangoma_boost_data)); /* WARNING: be sure to release this mutex on errors inside this if() */ zap_mutex_lock(g_boost_modules_mutex); @@ -1618,8 +1622,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) if (sigmod_iface) { /* try to create the boost queue */ - sangoma_boost_data->boost_queue = zap_queue_create(); - if (!sangoma_boost_data->boost_queue) { + if (zap_queue_create(&sangoma_boost_data->boost_queue, BOOST_QUEUE_SIZE) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Span %s could not create its boost queue!\n", span->name); FAIL_CONFIG_RETURN(ZAP_FAIL); } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index a18d3e7eeb..e38ea050b3 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -108,7 +108,7 @@ struct sangomabc_connection { uint32_t hb_elapsed; /* boost signaling mod interface pointer (if not working in TCP mode) */ boost_sigmod_interface_t *sigmod; - zap_queue_t boost_queue; + zap_queue_t *boost_queue; zap_span_t *span; }; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h index fc2fc953fd..e08d98b598 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -50,7 +50,7 @@ typedef struct zap_sangoma_boost_data { zio_signal_cb_t signal_cb; uint32_t flags; boost_sigmod_interface_t *sigmod; - zap_queue_t boost_queue; + zap_queue_t *boost_queue; } zap_sangoma_boost_data_t; #endif diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 1ae1796057..48ea8e0f05 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -176,8 +176,15 @@ static void default_logger(const char *file, const char *func, int line, int lev } +OZ_DECLARE_DATA zap_crash_policy_t g_zap_crash_policy = ZAP_CRASH_NEVER; + OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; +OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy) +{ + g_zap_crash_policy = policy; +} + OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger) { if (logger) { diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 24f3dcaf51..93fcd76f11 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -37,30 +37,148 @@ #include "openzap.h" -OZ_DECLARE(zap_queue_t) zap_queue_create(void) -{ - return NULL; -} +#undef zap_queue_t +#define ZAP_QUEUE_SIZE +typedef struct zap_queue { + zap_mutex_t *mutex; + zap_condition_t *condition; + zap_size_t size; + unsigned rindex; + unsigned windex; + void **elements; +} zap_queue_t; -OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t queue, void *obj) +OZ_DECLARE(zap_status_t) zap_queue_create(zap_queue_t **outqueue, zap_size_t size) { + zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); + zap_assert(size > 0, ZAP_FAIL, "Queue size is not bigger than 0\n"); + + *outqueue = NULL; + zap_queue_t *queue = calloc(1, sizeof(*queue)); + if (!queue) { + return ZAP_FAIL; + } + + queue->elements = calloc(1, (sizeof(void*)*size)); + if (!queue->elements) { + goto failed; + } + queue->size = size; + + if (zap_mutex_create(&queue->mutex) != ZAP_SUCCESS) { + goto failed; + } + + if (zap_condition_create(&queue->condition, queue->mutex) != ZAP_SUCCESS) { + goto failed; + } + + *outqueue = queue; + return ZAP_SUCCESS; + +failed: + if (queue) { + if (queue->condition) { + zap_condition_destroy(&queue->condition); + } + if (queue->mutex) { + zap_mutex_destroy(&queue->mutex); + } + zap_safe_free(queue->elements); + zap_safe_free(queue); + } return ZAP_FAIL; } -OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t queue) +OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t *queue, void *obj) { - return NULL; + zap_status_t status = ZAP_FAIL; + + zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); + + zap_mutex_lock(queue->mutex); + + if (queue->windex == queue->size) { + /* try to see if we can wrap around */ + queue->windex = 0; + } + + if (queue->windex == queue->rindex) { + zap_log(ZAP_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex); + goto done; + } + queue->elements[queue->windex++] = obj; + status = ZAP_SUCCESS; + + /* wake up queue reader */ + zap_condition_signal(queue->condition); + +done: + + zap_mutex_unlock(queue->mutex); + + return status; } -OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t queue, int ms) +OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t *queue) { - return ZAP_FAIL; + void *obj = NULL; + + zap_assert(queue != NULL, NULL, "Queue is null!"); + + zap_mutex_lock(queue->mutex); + + if (!queue->elements[queue->rindex]) { + goto done; + } + + obj = queue->elements[queue->rindex]; + queue->elements[queue->rindex] = NULL; + if (queue->rindex == queue->size) { + queue->rindex = 0; + } + +done: + zap_mutex_unlock(queue->mutex); + return obj; } -OZ_DECLARE(void) zap_queue_destroy(zap_queue_t queue) +OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms) { + zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); + + zap_mutex_lock(queue->mutex); + if (queue->elements[queue->rindex]) { + zap_mutex_unlock(queue->mutex); + return ZAP_SUCCESS; + } + + if (zap_condition_wait(queue->condition, ms)) { + zap_mutex_unlock(queue->mutex); + return ZAP_FAIL; + } + + zap_mutex_unlock(queue->mutex); + + return ZAP_SUCCESS; } + +OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **inqueue) +{ + zap_queue_t *queue = NULL; + zap_assert(inqueue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); + + queue = *inqueue; + zap_condition_destroy(&queue->condition); + zap_mutex_destroy(&queue->mutex); + zap_safe_free(queue->elements); + zap_safe_free(queue); + *inqueue = NULL; + return ZAP_SUCCESS; +} + #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index b6bc8435b6..fa302e56a6 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -34,6 +34,10 @@ struct zap_mutex { CRITICAL_SECTION mutex; }; +struct zap_condition { + HANDLE condition; +}; + #else #include @@ -44,6 +48,11 @@ struct zap_mutex { pthread_mutex_t mutex; }; +struct zap_condition { + pthread_cond_t condition; + pthread_mutex_t *mutex; +}; + #endif struct zap_thread { @@ -222,8 +231,91 @@ OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex) } +OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap_mutex_t *mutex) +{ + zap_condition_t *condition = NULL; + zap_assert(condition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); + zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); +#ifdef WIN32 + return ZAP_NOTIMPL; +#endif + + condition = malloc(sizeof(*condition)); + if (!condition) { + return ZAP_FAIL; + } + +#ifndef WIN32 + condition->mutex = &mutex->mutex; + + if (pthread_cond_init(&condition->condition, NULL)) { + goto failed; + } + + return ZAP_SUCCESS; + +failed: + if (condition) { + zap_safe_free(condition); + } + return ZAP_FAIL; +#endif +} + +OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) +{ + zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + int res = 0; +#ifdef WIN32 + return ZAP_NOTIMPL; +#else + if (ms > 0) { + struct timespec waitms = { 0, ((ms * 1000) * 1000)}; + res = pthread_cond_timedwait(&condition->condition, condition->mutex, &waitms); + } else { + res = pthread_cond_wait(&condition->condition, condition->mutex); + } + if (res != 0) { + if (res == ETIMEDOUT) { + return ZAP_TIMEOUT; + } + return ZAP_FAIL; + } +#endif + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) +{ + zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); +#ifdef WIN32 + return ZAP_NOTIMPL; +#else + if (pthread_cond_signal(&condition->condition)) { + return ZAP_FAIL; + } +#endif + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) +{ + zap_condition_t *condition = NULL; + zap_assert(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); + condition = *incondition; +#ifdef WIN32 + return ZAP_NOTIMPL; +#else + if (pthread_cond_destroy(&condition->condition)) { + return ZAP_FAIL; + } + zap_safe_free(condition); +#endif + *incondition = NULL; + return ZAP_SUCCESS; +} /* For Emacs: * Local Variables: From c3a1f65be9862566512ffef2396327388ce82b16 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 15 Nov 2009 01:46:43 +0000 Subject: [PATCH 1577/1766] added memory handlers git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@861 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/hashtable_itr.c | 4 +-- libs/freetdm/src/include/openzap.h | 56 +++++++++++++++++++++++++----- libs/freetdm/src/zap_io.c | 45 ++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index 8973b08ad0..cb8165dc91 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -31,6 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "openzap.h" #include "hashtable.h" #include "hashtable_private.h" #include "hashtable_itr.h" @@ -43,8 +44,7 @@ struct hashtable_itr * hashtable_iterator(struct hashtable *h) { unsigned int i, tablelength; - struct hashtable_itr *itr = (struct hashtable_itr *) - malloc(sizeof(struct hashtable_itr)); + struct hashtable_itr *itr = zap_malloc(sizeof(struct hashtable_itr)); if (NULL == itr) return NULL; itr->h = h; itr->e = NULL; diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 8f135e173c..bdd97ca591 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -318,15 +318,6 @@ typedef enum { */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) -/*! - \brief Free a pointer and set it to NULL unless it already is NULL - \command it the pointer -*/ -#define zap_safe_free(it) if (it) {free(it);it=NULL;} - -#define zap_socket_close(it) if (it > -1) { close(it); it = -1;} - - struct zap_stream_handle { zap_stream_handle_write_function_t write_function; zap_stream_handle_raw_write_function_t raw_write_function; @@ -586,6 +577,18 @@ typedef enum { OZ_DECLARE_DATA extern zap_crash_policy_t g_zap_crash_policy; +typedef void *(*zap_malloc_func_t)(void *pool, zap_size_t len); +typedef void *(*zap_calloc_func_t)(void *pool, zap_size_t elements, zap_size_t len); +typedef void (*zap_free_func_t)(void *pool, void *ptr); +typedef struct zap_memory_handler { + void *pool; + zap_malloc_func_t malloc; + zap_calloc_func_t calloc; + zap_free_func_t free; +} zap_memory_handler_t; + +OZ_DECLARE_DATA extern zap_memory_handler_t g_zap_mem_handler; + struct zap_io_interface { const char *name; zio_configure_span_t configure_span; @@ -691,6 +694,7 @@ OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *v OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_global_init(void); OZ_DECLARE(zap_status_t) zap_global_destroy(void); +OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler); OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy); OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger); OZ_DECLARE(void) zap_global_set_default_logger(int level); @@ -731,6 +735,10 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) #endif +/*! + \brief Allocate uninitialized memory + \command chunksize the chunk size +*/ #define zap_assert(assertion, retval, msg) \ if (!(assertion)) { \ zap_log(ZAP_LOG_CRIT, msg); \ @@ -741,6 +749,36 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); } \ } +/*! + \brief Allocate uninitialized memory + \command chunksize the chunk size +*/ +#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize); + +/*! + \brief Allocate initialized memory + \command chunksize the chunk size +*/ +#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize); + +/*! + \brief Free chunk of memory + \command chunksize the chunk size +*/ +#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk); + +/*! + \brief Free a pointer and set it to NULL unless it already is NULL + \command it the pointer +*/ +#define zap_safe_free(it) if (it) { zap_free(it); it = NULL; } + +/*! + \brief Socket the given socket + \command it the socket +*/ +#define zap_socket_close(it) if (it > -1) { close(it); it = -1;} + static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state) { uint32_t j; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 48ea8e0f05..cc4ebb7f42 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -176,6 +176,33 @@ static void default_logger(const char *file, const char *func, int line, int lev } +static inline void *zap_std_malloc(void *pool, zap_size_t size) +{ + void *ptr = malloc(size); + zap_assert(ptr != NULL, NULL, "Out of memory"); + return ptr; +} + +static inline void *zap_std_calloc(void *pool, zap_size_t elements, zap_size_t size) +{ + void *ptr = calloc(elements, size); + zap_assert(ptr != NULL, NULL, "Out of memory"); + return ptr; +} + +static inline void zap_std_free(void *pool, void *ptr) +{ + free(ptr); +} + +OZ_DECLARE_DATA zap_memory_handler_t g_zap_mem_handler = +{ + .pool = NULL, + .malloc = zap_std_malloc, + .calloc = zap_std_calloc, + .free = zap_std_free +}; + OZ_DECLARE_DATA zap_crash_policy_t g_zap_crash_policy = ZAP_CRASH_NEVER; OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; @@ -185,6 +212,24 @@ OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy) g_zap_crash_policy = policy; } +OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler) +{ + if (!handler) { + return ZAP_FAIL; + } + if (!handler->malloc) { + return ZAP_FAIL; + } + if (!handler->calloc) { + return ZAP_FAIL; + } + if (!handler->free) { + return ZAP_FAIL; + } + memcpy(&g_zap_mem_handler, handler, sizeof(*handler)); + return ZAP_SUCCESS; +} + OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger) { if (logger) { From a2b4369cc29002a80d98ada285e4f1e782089914 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 15 Nov 2009 02:14:50 +0000 Subject: [PATCH 1578/1766] replace all malloc calls to zap_malloc git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@862 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/fsk.c | 8 ++++---- libs/freetdm/src/hashtable.c | 9 +++++---- libs/freetdm/src/include/openzap.h | 6 +++--- libs/freetdm/src/isdn/Q921.c | 3 ++- libs/freetdm/src/libteletone_generate.c | 3 ++- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 2 +- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 4 ++-- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 6 +++--- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 9 ++++----- libs/freetdm/src/uart.c | 3 ++- libs/freetdm/src/zap_buffer.c | 4 ++-- libs/freetdm/src/zap_io.c | 8 +++----- libs/freetdm/src/zap_m3ua.c | 2 +- libs/freetdm/src/zap_threadmutex.c | 6 +++--- 16 files changed, 39 insertions(+), 38 deletions(-) diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index 773b0deaae..f55d421559 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -32,7 +32,7 @@ * * 2005 03 20 R. Krten created */ - +#include #include #include #include @@ -134,7 +134,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) double phi_mark, phi_space; dsp_fsk_handle_t *handle; - handle = malloc(sizeof(*handle)); + handle = zap_malloc(sizeof(*handle)); if (!handle) { return NULL; } @@ -157,7 +157,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { - handle->correlates[i] = malloc(sizeof(double) * handle->corrsize); + handle->correlates[i] = zap_malloc(sizeof(double) * handle->corrsize); if (handle->correlates[i] == NULL) { /* some failed, back out memory allocations */ dsp_fsk_destroy(&handle); @@ -177,7 +177,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) } /* initialize the ring buffer */ - handle->buffer = malloc(sizeof(double) * handle->corrsize); + handle->buffer = zap_malloc(sizeof(double) * handle->corrsize); if (!handle->buffer) { /* failed; back out memory allocations */ dsp_fsk_destroy(&handle); return NULL; diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index eeb2aaa07a..415dda7d8d 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -31,6 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "openzap.h" #include "hashtable.h" #include "hashtable_private.h" #include @@ -69,9 +70,9 @@ create_hashtable(unsigned int minsize, for (pindex=0; pindex < prime_table_length; pindex++) { if (primes[pindex] > minsize) { size = primes[pindex]; break; } } - h = (struct hashtable *)malloc(sizeof(struct hashtable)); + h = (struct hashtable *)zap_malloc(sizeof(struct hashtable)); if (NULL == h) return NULL; /*oom*/ - h->table = (struct entry **)malloc(sizeof(struct entry*) * size); + h->table = (struct entry **)zap_malloc(sizeof(struct entry*) * size); if (NULL == h->table) { free(h); return NULL; } /*oom*/ memset(h->table, 0, size * sizeof(struct entry *)); h->tablelength = size; @@ -110,7 +111,7 @@ hashtable_expand(struct hashtable *h) if (h->primeindex == (prime_table_length - 1)) return 0; newsize = primes[++(h->primeindex)]; - newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); + newtable = (struct entry **)zap_malloc(sizeof(struct entry*) * newsize); if (NULL != newtable) { memset(newtable, 0, newsize * sizeof(struct entry *)); @@ -178,7 +179,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) * element may be ok. Next time we insert, we'll try expanding again.*/ hashtable_expand(h); } - e = (struct entry *)malloc(sizeof(struct entry)); + e = (struct entry *)zap_malloc(sizeof(struct entry)); if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ e->h = hash(h,k); index = indexFor(h->tablelength,e->h); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index bdd97ca591..726cee3b09 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -753,19 +753,19 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); \brief Allocate uninitialized memory \command chunksize the chunk size */ -#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize); +#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize) /*! \brief Allocate initialized memory \command chunksize the chunk size */ -#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize); +#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize) /*! \brief Free chunk of memory \command chunksize the chunk size */ -#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk); +#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk) /*! \brief Free a pointer and set it to NULL unless it already is NULL diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 0496e09f5c..9cfd08a07c 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -79,6 +79,7 @@ #include #include +#include "openzap.h" #include "Q921.h" #include "Q921priv.h" #include "mfifo.h" @@ -397,7 +398,7 @@ int Q921_InitTrunk(L2TRUNK trunk, /* * Allocate space for per-link context(s) */ - trunk->context = malloc(numlinks * sizeof(struct Q921_Link)); + trunk->context = zap_malloc(numlinks * sizeof(struct Q921_Link)); if(!trunk->context) return -1; diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 1d5d696af2..d0ae2b01e3 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -34,6 +34,7 @@ */ #include +#include "openzap.h" #define SMAX 32767 #define SMIN -32768 @@ -273,7 +274,7 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone static char *my_strdup (const char *s) { size_t len = strlen (s) + 1; - void *new = malloc (len); + void *new = zap_malloc(len); if (new == NULL) { return NULL; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 3978c94106..4da3e2e564 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -122,7 +122,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) return ZAP_FAIL; } - analog_data = malloc(sizeof(*analog_data)); + analog_data = zap_malloc(sizeof(*analog_data)); assert(analog_data != NULL); memset(analog_data, 0, sizeof(*analog_data)); diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index 4468e4b92d..53bf1a000f 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -106,7 +106,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) return ZAP_FAIL; } - analog_data = malloc(sizeof(*analog_data)); + analog_data = zap_malloc(sizeof(*analog_data)); assert(analog_data != NULL); memset(analog_data, 0, sizeof(*analog_data)); diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index d054bd08d1..a92877ca14 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -2263,7 +2263,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_FAIL; } - isdn_data = malloc(sizeof(*isdn_data)); + isdn_data = zap_malloc(sizeof(*isdn_data)); assert(isdn_data != NULL); memset(isdn_data, 0, sizeof(*isdn_data)); @@ -2333,7 +2333,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) if (isdn_data->mode == Q931_NT) { zap_isdn_bchan_data_t *data; - data = malloc((span->chan_count - 1) * sizeof(zap_isdn_bchan_data_t)); + data = zap_malloc((span->chan_count - 1) * sizeof(zap_isdn_bchan_data_t)); if (!data) { return ZAP_FAIL; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index a8e3fea6f7..e80de2686d 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -1272,7 +1272,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } #endif - isdn_data = malloc(sizeof(*isdn_data)); + isdn_data = zap_malloc(sizeof(*isdn_data)); assert(isdn_data != NULL); memset(isdn_data, 0, sizeof(*isdn_data)); diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index 154c1618ff..536110c32a 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -156,7 +156,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) int ok = 1; if (!(profile = (pika_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { - profile = malloc(sizeof(*profile)); + profile = zap_malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); profile->ec_config = globals.ec_config; @@ -348,7 +348,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa if (span->mod_data) { span_data = span->mod_data; } else { - span_data = malloc(sizeof(*span_data)); + span_data = zap_malloc(sizeof(*span_data)); assert(span_data != NULL); memset(span_data, 0, sizeof(*span_data)); span_data->boardno = boardno; @@ -376,7 +376,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa zap_channel_t *chan; pika_chan_data_t *chan_data = NULL; - chan_data = malloc(sizeof *chan_data); + chan_data = zap_malloc(sizeof *chan_data); assert(chan_data); memset(chan_data, 0, sizeof(*chan_data)); zap_span_add_channel(span, 0, type, &chan); diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c index 9683aa57b2..837a8887b7 100644 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -32,7 +32,6 @@ */ #include -#include #include #include "openzap.h" @@ -738,7 +737,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) } 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 */ + char *logval = zap_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; @@ -811,14 +810,14 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) return ZAP_FAIL; } - r2data = malloc(sizeof(*r2data)); + r2data = zap_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)); + spanpvt = zap_malloc(sizeof(*spanpvt)); if (!spanpvt) { snprintf(span->last_error, sizeof(span->last_error), "Failed to allocate private span data container."); goto fail; @@ -862,7 +861,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) openr2_chan_set_log_level(r2chan, r2conf.loglevel); } - r2call = malloc(sizeof(*r2call)); + r2call = zap_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); diff --git a/libs/freetdm/src/uart.c b/libs/freetdm/src/uart.c index 5e0dd85350..14f066da59 100644 --- a/libs/freetdm/src/uart.c +++ b/libs/freetdm/src/uart.c @@ -32,6 +32,7 @@ * 2005 06 11 R. Krten created */ +#include #include #include #include @@ -76,7 +77,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) { dsp_uart_handle_t *handle; - handle = malloc(sizeof (*handle)); + handle = zap_malloc(sizeof (*handle)); if (handle) { memset(handle, 0, sizeof (*handle)); diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 0e2279d7e3..bd8b0cc307 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -53,12 +53,12 @@ OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blo { zap_buffer_t *new_buffer; - new_buffer = malloc(sizeof(*new_buffer)); + new_buffer = zap_malloc(sizeof(*new_buffer)); if (new_buffer) { memset(new_buffer, 0, sizeof(*new_buffer)); if (start_len) { - new_buffer->data = malloc(start_len); + new_buffer->data = zap_malloc(start_len); if (!new_buffer->data) { free(new_buffer); return ZAP_MEMERR; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index cc4ebb7f42..4a20acf65f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -35,8 +35,6 @@ #ifndef WIN32 #endif #include "openzap.h" -//#include "zap_isdn.h" -//#include "zap_ss7_boost.h" #include #ifdef WIN32 #include @@ -426,7 +424,7 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s zap_mutex_lock(globals.mutex); if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = malloc(sizeof(*new_span)); + new_span = zap_malloc(sizeof(*new_span)); assert(new_span); memset(new_span, 0, sizeof(*new_span)); status = zap_mutex_create(&new_span->mutex); @@ -554,7 +552,7 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc zap_channel_t *new_chan = span->channels[++span->chan_count]; if (!new_chan) { - if (!(new_chan = malloc(sizeof(*new_chan)))) { + if (!(new_chan = zap_malloc(sizeof(*new_chan)))) { return ZAP_FAIL; } span->channels[span->chan_count] = new_chan; @@ -3112,7 +3110,7 @@ OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code f len = vsnprintf(tmp, 0, fmt, ap2); - if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) { + if (len > 0 && (buf = zap_malloc((buflen = (size_t) (len + 1)))) != NULL) { len = vsnprintf(buf, buflen, fmt, ap); *ret = buf; } else { diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index 50736b75e4..8e572c92d7 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -399,7 +399,7 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) int ok = 1; if (!(profile = (m3ua_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { - profile = malloc(sizeof(*profile)); + profile = zap_malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); hashtable_insert(globals.profile_hash, (void *)profile->name, profile); diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index fa302e56a6..d4a12f4186 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -99,7 +99,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun zap_thread_t *thread = NULL; zap_status_t status = ZAP_FAIL; - if (!func || !(thread = (zap_thread_t *)malloc(sizeof(zap_thread_t)))) { + if (!func || !(thread = (zap_thread_t *)zap_malloc(sizeof(zap_thread_t)))) { goto done; } @@ -149,7 +149,7 @@ OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex) #endif zap_mutex_t *check = NULL; - check = (zap_mutex_t *)malloc(sizeof(**mutex)); + check = (zap_mutex_t *)zap_malloc(sizeof(**mutex)); if (!check) goto done; #ifdef WIN32 @@ -242,7 +242,7 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap return ZAP_NOTIMPL; #endif - condition = malloc(sizeof(*condition)); + condition = zap_malloc(sizeof(*condition)); if (!condition) { return ZAP_FAIL; } From f3d2328564ee7084badb8d1d934c2912b4abc4a8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 15 Nov 2009 03:35:01 +0000 Subject: [PATCH 1579/1766] replaced calloc calls for zap_calloc git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@863 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/libteletone_generate.c | 2 +- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 4 ++-- libs/freetdm/src/zap_io.c | 2 +- libs/freetdm/src/zap_queue.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index d0ae2b01e3..bb41224c9a 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -111,7 +111,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b ts->decay_step = 0; ts->decay_factor = 1; if (buflen) { - if ((ts->buffer = calloc(buflen, sizeof(teletone_audio_t))) == 0) { + if ((ts->buffer = zap_calloc(buflen, sizeof(teletone_audio_t))) == 0) { return -1; } ts->datalen = buflen; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index c1f7f74588..5aafbf3734 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1494,7 +1494,7 @@ static zap_state_map_t boost_state_map = { static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) { zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - sangomabc_queue_element_t *element = calloc(1, sizeof(*element)); + sangomabc_queue_element_t *element = zap_calloc(1, sizeof(*element)); if (!element) { return ZAP_FAIL; } @@ -1588,7 +1588,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) } } - sangoma_boost_data = calloc(1, sizeof(*sangoma_boost_data)); + sangoma_boost_data = zap_calloc(1, sizeof(*sangoma_boost_data)); if (!sangoma_boost_data) { FAIL_CONFIG_RETURN(ZAP_FAIL); } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 4a20acf65f..d0a6aaf69d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -583,7 +583,7 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); + new_chan->dtmf_hangup_buf = zap_calloc (span->dtmf_hangup_len + 1, sizeof (char)); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 93fcd76f11..7392c78117 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -54,12 +54,12 @@ OZ_DECLARE(zap_status_t) zap_queue_create(zap_queue_t **outqueue, zap_size_t siz zap_assert(size > 0, ZAP_FAIL, "Queue size is not bigger than 0\n"); *outqueue = NULL; - zap_queue_t *queue = calloc(1, sizeof(*queue)); + zap_queue_t *queue = zap_calloc(1, sizeof(*queue)); if (!queue) { return ZAP_FAIL; } - queue->elements = calloc(1, (sizeof(void*)*size)); + queue->elements = zap_calloc(1, (sizeof(void*)*size)); if (!queue->elements) { goto failed; } From 34307d8e52d97298404ed5fe95e9e08932d2c0db Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 14:52:02 +0000 Subject: [PATCH 1580/1766] replaced a ton of free or strdup calls for zap_safe_free and zap_strdup git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@864 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/fsk.c | 6 ++-- libs/freetdm/src/hashtable.c | 12 +++---- libs/freetdm/src/hashtable_itr.c | 2 +- libs/freetdm/src/include/openzap.h | 3 ++ libs/freetdm/src/libteletone_generate.c | 19 ++---------- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- .../freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 8 ++--- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 4 +-- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 4 +-- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 4 +-- libs/freetdm/src/uart.c | 2 +- libs/freetdm/src/zap_buffer.c | 6 ++-- libs/freetdm/src/zap_dso.c | 9 +++--- libs/freetdm/src/zap_io.c | 31 +++++++++++++------ libs/freetdm/src/zap_m3ua.c | 4 +-- libs/freetdm/src/zap_threadmutex.c | 6 ++-- 16 files changed, 62 insertions(+), 60 deletions(-) diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index f55d421559..16a1bcb7d4 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -226,13 +226,13 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle) for (i = 0; i < 4; i++) { if ((*handle)->correlates[i] != NULL) { - free((*handle)->correlates[i]); + zap_safe_free((*handle)->correlates[i]); (*handle)->correlates[i] = NULL; } } if ((*handle)->buffer != NULL) { - free((*handle)->buffer); + zap_safe_free((*handle)->buffer); (*handle)->buffer = NULL; } @@ -241,7 +241,7 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle) dsp_uart_destroy(dhandle); } - free(*handle); + zap_safe_free(*handle); *handle = NULL; } diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 415dda7d8d..15ec9014f4 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -73,7 +73,7 @@ create_hashtable(unsigned int minsize, h = (struct hashtable *)zap_malloc(sizeof(struct hashtable)); if (NULL == h) return NULL; /*oom*/ h->table = (struct entry **)zap_malloc(sizeof(struct entry*) * size); - if (NULL == h->table) { free(h); return NULL; } /*oom*/ + if (NULL == h->table) { zap_safe_free(h); return NULL; } /*oom*/ memset(h->table, 0, size * sizeof(struct entry *)); h->tablelength = size; h->primeindex = pindex; @@ -125,7 +125,7 @@ hashtable_expand(struct hashtable *h) newtable[index] = e; } } - free(h->table); + zap_safe_free(h->table); h->table = newtable; } /* Plan B: realloc instead */ @@ -236,7 +236,7 @@ hashtable_remove(struct hashtable *h, void *k) if (e->flags & HASHTABLE_FLAG_FREE_KEY) { freekey(e->k); } - free(e); + zap_safe_free(e); return v; } pE = &(e->next); @@ -258,11 +258,11 @@ hashtable_destroy(struct hashtable *h) { e = table[i]; while (NULL != e) - { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) free(f->v); free(f); } + { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) zap_safe_free(f->v); zap_safe_free(f); } } - free(h->table); - free(h); + zap_safe_free(h->table); + zap_safe_free(h); } OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i) diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index cb8165dc91..ab5e1ce0c8 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -138,7 +138,7 @@ hashtable_iterator_remove(struct hashtable_itr *itr) remember_parent = itr->parent; ret = hashtable_iterator_advance(itr); if (itr->parent == remember_e) { itr->parent = remember_parent; } - free(remember_e); + zap_safe_free(remember_e); return ret; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 726cee3b09..bc6b0a9dd3 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -625,6 +625,9 @@ OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms); /*! destroy the queue */ OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **queue); +/* Duplicate string */ +OZ_DECLARE(char *) zap_strdup(const char *str); + OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index bb41224c9a..c261772f92 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -142,7 +142,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts) { if (ts->buffer) { - free(ts->buffer); + zap_safe_free(ts->buffer); ts->buffer = NULL; ts->samples = 0; } @@ -270,19 +270,6 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone return ts->samples; } -/* don't ask */ -static char *my_strdup (const char *s) -{ - size_t len = strlen (s) + 1; - void *new = zap_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; @@ -293,7 +280,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm } do { - if (!(data = my_strdup(cmd))) { + if (!(data = zap_strdup(cmd))) { return -1; } @@ -442,7 +429,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm } } bottom: - free(data); + zap_safe_free(data); data = NULL; if (ts->LOOPS > 0) { ts->LOOPS--; diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index e80de2686d..ec92684a57 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -210,7 +210,7 @@ static ZIO_API_FUNCTION(zap_libpri_api) int argc = 0; if (data) { - mycmd = strdup(data); + mycmd = zap_strdup(data); argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index 536110c32a..2932a342e7 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -358,7 +358,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); + zap_safe_free(span_data); return 0; } @@ -605,7 +605,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) assert(str != NULL); - mydata = strdup(str); + mydata = zap_strdup(str); assert(mydata != NULL); if ((profile_name = strchr(mydata, '@'))) { @@ -668,7 +668,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) } - free(mydata); + zap_safe_free(mydata); return configured; } @@ -1211,7 +1211,7 @@ static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) if (span_data) { PKH_QUEUE_Destroy(span_data->event_queue); - free(span_data); + zap_safe_free(span_data); } return ZAP_SUCCESS; diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c index 837a8887b7..8000aa2a64 100644 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -752,7 +752,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) r2conf.loglevel |= tmplevel; zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with loglevel %s\n", span->span_id, clevel); } - free(logval); + zap_safe_free(logval); } else if (!strcasecmp(var, "advanced_protocol_file")) { if (!(val = va_arg(ap, char *))) { break; @@ -1182,7 +1182,7 @@ static ZIO_API_FUNCTION(zap_r2_api) int argc = 0; if (data) { - mycmd = strdup(data); + mycmd = zap_strdup(data); argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index a275acc352..3d681985fb 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -397,7 +397,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) assert(str != NULL); - mydata = strdup(str); + mydata = zap_strdup(str); assert(mydata != NULL); @@ -447,7 +447,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) } - free(mydata); + zap_safe_free(mydata); return configured; } diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index b8788d2a58..bbd64352f4 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -452,7 +452,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) assert(str != NULL); - mydata = strdup(str); + mydata = zap_strdup(str); assert(mydata != NULL); @@ -493,7 +493,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) } - free(mydata); + zap_safe_free(mydata); return configured; diff --git a/libs/freetdm/src/uart.c b/libs/freetdm/src/uart.c index 14f066da59..b3728e6fc8 100644 --- a/libs/freetdm/src/uart.c +++ b/libs/freetdm/src/uart.c @@ -90,7 +90,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) void dsp_uart_destroy(dsp_uart_handle_t **handle) { if (*handle) { - free(*handle); + zap_safe_free(*handle); *handle = NULL; } } diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index bd8b0cc307..11a7c03d29 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -60,7 +60,7 @@ OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blo if (start_len) { new_buffer->data = zap_malloc(start_len); if (!new_buffer->data) { - free(new_buffer); + zap_safe_free(new_buffer); return ZAP_MEMERR; } memset(new_buffer->data, 0, start_len); @@ -283,8 +283,8 @@ OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer) { if (*buffer) { - free((*buffer)->data); - free(*buffer); + zap_safe_free((*buffer)->data); + zap_safe_free(*buffer); } *buffer = NULL; diff --git a/libs/freetdm/src/zap_dso.c b/libs/freetdm/src/zap_dso.c index ead40e7c4b..eefe6e819c 100644 --- a/libs/freetdm/src/zap_dso.c +++ b/libs/freetdm/src/zap_dso.c @@ -17,6 +17,7 @@ * */ +#include "openzap.h" #include "zap_dso.h" #include #include @@ -46,7 +47,7 @@ zap_dso_lib_t zap_dso_open(const char *path, char **err) { DWORD error = GetLastError(); char tmp[80]; sprintf(tmp, "dll open error [%ul]\n", error); - *err = _strdup(tmp); + *err = zap_strdup(tmp); } return lib; @@ -58,7 +59,7 @@ void* zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { DWORD error = GetLastError(); char tmp[80]; sprintf(tmp, "dll sym error [%ul]\n", error); - *err = _strdup(tmp); + *err = zap_strdup(tmp); } return (void *)(intptr_t)func; // this should really be addr - zap_dso_func_data } @@ -87,7 +88,7 @@ void zap_dso_destroy(zap_dso_lib_t *lib) { zap_dso_lib_t zap_dso_open(const char *path, char **err) { void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (lib == NULL) { - *err = strdup(dlerror()); + *err = zap_strdup(dlerror()); } return lib; } @@ -95,7 +96,7 @@ 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) { void *func = dlsym(lib, sym); if (!func) { - *err = strdup(dlerror()); + *err = zap_strdup(dlerror()); } return func; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index d0a6aaf69d..a8e7329558 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -452,7 +452,7 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s snprintf(buf, sizeof(buf), "span%d", new_span->span_id); name = buf; } - new_span->name = strdup(name); + new_span->name = zap_strdup(name); zap_span_add(new_span); *span = new_span; status = ZAP_SUCCESS; @@ -2306,8 +2306,8 @@ OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *v return ZAP_FAIL; } - t_name = strdup(var_name); - t_val = strdup(value); + t_name = zap_strdup(var_name); + t_val = zap_strdup(value); if(hashtable_insert(zchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) { return ZAP_SUCCESS; @@ -2336,7 +2336,7 @@ OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd) char *rval = NULL; if (type && !cmd) { - dup = strdup(type); + dup = zap_strdup(type); if ((p = strchr(dup, ' '))) { *p++ = '\0'; cmd = p; @@ -2440,7 +2440,7 @@ static zap_status_t load_config(void) } if (zap_span_create(zio, &span, name) == ZAP_SUCCESS) { - span->type = strdup(type); + span->type = zap_strdup(type); d = 0; zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); @@ -2534,7 +2534,7 @@ static zap_status_t load_config(void) } else if (!strcasecmp(var, "cas-channel")) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_CAS, name, number); } else if (!strcasecmp(var, "dtmf_hangup")) { - span->dtmf_hangup = strdup(val); + span->dtmf_hangup = zap_strdup(val); span->dtmf_hangup_len = strlen(val); } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); @@ -2849,7 +2849,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { zap_channel_destroy(cur_chan); } - free(cur_chan); + zap_safe_free(cur_chan); cur_chan = NULL; } } @@ -2866,7 +2866,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) hashtable_remove(globals.span_hash, (void *)cur_span->name); zap_safe_free(cur_span->type); zap_safe_free(cur_span->name); - free(cur_span); + zap_safe_free(cur_span); cur_span = NULL; } } @@ -3157,7 +3157,7 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha end = handle->end; } else { zap_log(ZAP_LOG_CRIT, "Memory Error!\n"); - free(data); + zap_safe_free(data); return ZAP_FAIL; } } @@ -3170,12 +3170,23 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha handle->data_len = strlen(buf); handle->end = (uint8_t *) (handle->data) + handle->data_len; } - free(data); + zap_safe_free(data); } return ret ? ZAP_FAIL : ZAP_SUCCESS; } +OZ_DECLARE(char *) zap_strdup(const char *str) +{ + zap_size_t len = strlen(str) + 1; + void *new = zap_malloc(len); + + if (!new) { + return NULL; + } + + return (char *)memcpy(new, str, len); +} /* For Emacs: diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index 8e572c92d7..bcc0e0559d 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -487,7 +487,7 @@ static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data; if (span_data) { - free(span_data); + zap_safe_free(span_data); } return ZAP_SUCCESS; @@ -513,7 +513,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) zap_safe_free(chan_data); if (span_data) { - free(span_data); + zap_safe_free(span_data); } diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index d4a12f4186..1fb3c479f6 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -84,7 +84,7 @@ static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) #ifndef WIN32 pthread_attr_destroy(&thread->attribute); #endif - free(thread); + zap_safe_free(thread); return exit_val; } @@ -134,7 +134,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun fail: if (thread) { - free(thread); + zap_safe_free(thread); } done: return status; @@ -192,7 +192,7 @@ OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex) if (pthread_mutex_destroy(&mp->mutex)) return ZAP_FAIL; #endif - free(mp); + zap_safe_free(mp); return ZAP_SUCCESS; } From 9750bbed52a4fa1793c1609b4c1c01540080847d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 15:21:08 +0000 Subject: [PATCH 1581/1766] added API and hooks to override the queue implementation git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@865 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 34 ++++++++++++++++++---- libs/freetdm/src/zap_io.c | 5 ++++ libs/freetdm/src/zap_queue.c | 45 ++++++++++++++++++++++-------- libs/freetdm/src/zap_threadmutex.c | 4 +++ 4 files changed, 71 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index bc6b0a9dd3..177d56178f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -29,6 +29,11 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * */ #ifndef OPENZAP_H @@ -610,22 +615,39 @@ struct zap_io_interface { struct zap_queue; #define zap_queue_t struct zap_queue +typedef zap_status_t (*zap_queue_create_func_t)(zap_queue_t **queue, zap_size_t); +typedef zap_status_t (*zap_queue_enqueue_func_t)(zap_queue_t *queue, void *obj); +typedef void *(*zap_queue_dequeue_func_t)(zap_queue_t *queue); +typedef zap_status_t (*zap_queue_wait_func_t)(zap_queue_t *queue, int ms); +typedef zap_status_t (*zap_queue_destroy_func_t)(zap_queue_t **queue); +typedef struct zap_queue_handler { + zap_queue_create_func_t create; + zap_queue_enqueue_func_t enqueue; + zap_queue_dequeue_func_t dequeue; + zap_queue_wait_func_t wait; + zap_queue_destroy_func_t destroy; +} zap_queue_handler_t; +OZ_DECLARE_DATA extern zap_queue_handler_t g_zap_queue_handler; + /*! brief create a new queue */ -OZ_DECLARE(zap_status_t) zap_queue_create(zap_queue_t **queue, zap_size_t size); +#define zap_queue_create(queue, size) g_zap_queue_handler.create(queue, size) /*! Enqueue an object */ -OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t *queue, void *obj); +#define zap_queue_enqueue(queue, obj) g_zap_queue_handler.enqueue(queue, obj) /*! dequeue an object from the queue */ -OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t *queue); +#define zap_queue_dequeue(queue) g_zap_queue_handler.dequeue(queue) /*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ -OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms); +#define zap_queue_wait(queue, ms) g_zap_queue_handler.wait(queue, ms) /*! destroy the queue */ -OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **queue); +#define zap_queue_destroy(queue) g_zap_queue_handler.destroy(queue) -/* Duplicate string */ +/*! \brief Override the default queue handler */ +OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler); + +/*! \brief Duplicate string */ OZ_DECLARE(char *) zap_strdup(const char *str); OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index a8e7329558..c793158b03 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -29,6 +29,11 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * */ #define _GNU_SOURCE diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 7392c78117..88de09351c 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -32,13 +32,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_QUEUE_H -#define ZAP_QUEUE_H - #include "openzap.h" #undef zap_queue_t -#define ZAP_QUEUE_SIZE typedef struct zap_queue { zap_mutex_t *mutex; zap_condition_t *condition; @@ -48,7 +44,36 @@ typedef struct zap_queue { void **elements; } zap_queue_t; -OZ_DECLARE(zap_status_t) zap_queue_create(zap_queue_t **outqueue, zap_size_t size) +static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t size); +static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj); +static void *zap_std_queue_dequeue(zap_queue_t *queue); +static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms); +static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue); + +OZ_DECLARE_DATA zap_queue_handler_t g_zap_queue_handler = +{ + .create = zap_std_queue_create, + .enqueue = zap_std_queue_enqueue, + .dequeue = zap_std_queue_dequeue, + .wait = zap_std_queue_wait, + .destroy = zap_std_queue_destroy +}; + +OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler) +{ + if (!handler || + !handler->create || + !handler->enqueue || + !handler->dequeue || + !handler->wait || + !handler->destroy) { + return ZAP_FAIL; + } + memcpy(&g_zap_queue_handler, handler, sizeof(*handler)); + return ZAP_SUCCESS; +} + +static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t size) { zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); zap_assert(size > 0, ZAP_FAIL, "Queue size is not bigger than 0\n"); @@ -90,7 +115,7 @@ failed: return ZAP_FAIL; } -OZ_DECLARE(zap_status_t) zap_queue_enqueue(zap_queue_t *queue, void *obj) +static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) { zap_status_t status = ZAP_FAIL; @@ -120,7 +145,7 @@ done: return status; } -OZ_DECLARE(void *) zap_queue_dequeue(zap_queue_t *queue) +static void *zap_std_queue_dequeue(zap_queue_t *queue) { void *obj = NULL; @@ -143,7 +168,7 @@ done: return obj; } -OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms) +static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) { zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); @@ -164,7 +189,7 @@ OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms) return ZAP_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **inqueue) +static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue) { zap_queue_t *queue = NULL; zap_assert(inqueue != NULL, ZAP_FAIL, "Queue is null!"); @@ -179,8 +204,6 @@ OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **inqueue) return ZAP_SUCCESS; } -#endif - /* For Emacs: * Local Variables: * mode:c diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 1fb3c479f6..2e0d0d3395 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -15,6 +15,10 @@ * constitutes an essential part of this license. No use of any covered code is authorized hereunder * except under this disclaimer. * + * Contributors: + * + * Moises Silva + * */ #ifdef WIN32 From e0d41a722c62e4e1ef4db070dff03cef87723630 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 15:52:52 +0000 Subject: [PATCH 1582/1766] added Windows zap conditions code git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@866 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 2e0d0d3395..fa4691d03c 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -242,21 +242,22 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap zap_assert(condition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); -#ifdef WIN32 - return ZAP_NOTIMPL; -#endif - - condition = zap_malloc(sizeof(*condition)); + condition = zap_calloc(1, sizeof(*condition)); if (!condition) { return ZAP_FAIL; } -#ifndef WIN32 +#ifdef WIN32 + condition->condition = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!condition->condition) { + goto failed; + } +#else condition->mutex = &mutex->mutex; - if (pthread_cond_init(&condition->condition, NULL)) { goto failed; } +#endif return ZAP_SUCCESS; @@ -265,16 +266,26 @@ failed: zap_safe_free(condition); } return ZAP_FAIL; -#endif } OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) { zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); - int res = 0; #ifdef WIN32 - return ZAP_NOTIMPL; + DWORD res = 0; + res = WaitForSingleObject(condition->condition, waitms > 0 ? waitms : INFINITE); + switch (res) { + case WAIT_ABANDONED: + case WAIT_TIMEOUT: + return ZAP_TIMEOUT; + case WAIT_FAILED: + return ZAP_FAIL; + defaul: + zap_log(ZAP_LOG_ERROR, "Error waiting for openzap condition event\n"); + return ZAP_FAIL; + } #else + int res = 0; if (ms > 0) { struct timespec waitms = { 0, ((ms * 1000) * 1000)}; res = pthread_cond_timedwait(&condition->condition, condition->mutex, &waitms); @@ -295,7 +306,9 @@ OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) { zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 - return ZAP_NOTIMPL; + if (!SetEvent(condition->condition)) { + return ZAP_FAIL; + } #else if (pthread_cond_signal(&condition->condition)) { return ZAP_FAIL; @@ -310,7 +323,7 @@ OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) zap_assert(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); condition = *incondition; #ifdef WIN32 - return ZAP_NOTIMPL; + CloseHandle(condition->condition); #else if (pthread_cond_destroy(&condition->condition)) { return ZAP_FAIL; From c332cceb0d50af4974bff0d093e2653838c07faa Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 16:27:59 +0000 Subject: [PATCH 1583/1766] added zap_global_add_io_interface git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@867 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 177d56178f..44d54473ac 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -737,6 +737,7 @@ OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len); +OZ_DECLARE(zap_status_t) zap_global_add_io_interface(zap_io_interface_t *io_interface); OZ_DECLARE(int) zap_load_module(const char *name); OZ_DECLARE(int) zap_load_module_assume(const char *name); OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index c793158b03..5141e2f524 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2604,6 +2604,19 @@ OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t l return path; } +OZ_DECLARE(zap_status_t) zap_global_add_io_interface(zap_io_interface_t *interface1) +{ + zap_status_t ret = ZAP_SUCCESS; + zap_mutex_lock(globals.mutex); + if (hashtable_search(globals.interface_hash, (void *)interface1->name)) { + zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface1->name); + } else { + hashtable_insert(globals.interface_hash, (void *)interface1->name, interface1, HASHTABLE_FLAG_NONE); + } + zap_mutex_unlock(globals.mutex); + return ret; +} + OZ_DECLARE(int) zap_load_module(const char *name) { zap_dso_lib_t lib; @@ -2633,15 +2646,10 @@ OZ_DECLARE(int) zap_load_module(const char *name) zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); } else { zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface1->name); - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.interface_hash, (void *)interface1->name)) { - zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface1->name); - } else { - hashtable_insert(globals.interface_hash, (void *)interface1->name, interface1, HASHTABLE_FLAG_NONE); + if (zap_global_add_io_interface(interface1) == ZAP_SUCCESS) { process_module_config(interface1); x++; } - zap_mutex_unlock(globals.mutex); } } From 3fee1f6eb10ef7a7f0b0e0ec0335ae574ccf55b4 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 16:51:58 +0000 Subject: [PATCH 1584/1766] added ZAP_COMMNAD_SET_LINK_STATUS for wanpipe boards git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@868 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 7 +++++ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 31 +++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index e8fe8bd78f..3f6d477243 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -296,6 +296,7 @@ typedef enum { ZAP_COMMAND_FLUSH_RX_BUFFERS, ZAP_COMMAND_FLUSH_BUFFERS, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, + ZAP_COMMAND_SET_LINK_STATUS, ZAP_COMMAND_COUNT } zap_command_t; @@ -415,6 +416,12 @@ struct zap_state_map { }; typedef struct zap_state_map zap_state_map_t; +typedef enum zap_hw_link_status { + ZAP_HW_LINK_UNINITIALIZED = 0, + ZAP_HW_LINK_DISCONNECTED, + ZAP_HW_LINK_CONNECTED +} zap_hw_link_status_t; + typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 3d681985fb..88a8aaf574 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -584,17 +584,36 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) 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); - } + 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? + // does sangoma_tdm_read_rbs is available here? ZAP_COMMAND_OBJ_INT = zchan->rx_cas_bits; #endif } break; + case ZAP_COMMAND_SET_LINK_STATUS: + { + zap_hw_link_status_t status = ZAP_COMMAND_OBJ_INT; + char sangoma_status; + switch (status) { + case ZAP_HW_LINK_UNINITIALIZED: + sangoma_status = FE_UNITIALIZED; + break; + case ZAP_HW_LINK_DISCONNECTED: + sangoma_status = FE_DISCONNECTED; + break; + case ZAP_HW_LINK_CONNECTED: + sangoma_status = FE_CONNECTED; + break; + default: + return ZAP_FAIL; + } + err = sangoma_tdm_set_fe_status(zchan->sockfd, &tdm_api, status); + } default: break; }; From d7b1202a1a3c57e2769718c66d76b517fbf92b77 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 18:06:48 +0000 Subject: [PATCH 1585/1766] added get sig status API support git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@869 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 2 ++ libs/freetdm/src/include/zap_types.h | 9 +++++- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 32 +++++++++++++++++-- libs/freetdm/src/zap_io.c | 16 ++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 44d54473ac..7052d8e17b 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -561,6 +561,7 @@ struct zap_span { teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t *channels[ZAP_MAX_CHANNELS_SPAN+1]; zio_channel_outgoing_call_t outgoing_call; + zio_channel_get_sig_status_t get_sig_status; zio_channel_request_t channel_request; zap_span_start_t start; zap_span_stop_t stop; @@ -680,6 +681,7 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_ OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan); +OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *status); OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan); OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan); OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 3f6d477243..38b749c0d7 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -190,6 +190,8 @@ typedef enum { /* The channel signaling link is ready and calls can be placed */ ZAP_SIG_STATE_UP } zap_channel_sig_status_t; +#define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP" +ZAP_STR2ENUM_P(zap_str2zap_channel_sig_status, zap_sig_status2str, zap_channel_sig_status_t) typedef enum { ZAP_SIGEVENT_START, @@ -208,10 +210,12 @@ typedef enum { ZAP_SIGEVENT_COLLECTED_DIGIT, ZAP_SIGEVENT_ADD_CALL, ZAP_SIGEVENT_RESTART, + /* Signaling link status changed (D-chan up, down, R2 blocked etc) */ + ZAP_SIGEVENT_SIGSTATUS_CHANGED, 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" + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGLINK_CHANGED", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -437,6 +441,7 @@ typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t #define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, uint32_t chan_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) #define ZIO_CHANNEL_OUTGOING_CALL_ARGS (zap_channel_t *zchan) +#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t *status) #define ZIO_SPAN_POLL_EVENT_ARGS (zap_span_t *span, uint32_t ms) #define ZIO_SPAN_NEXT_EVENT_ARGS (zap_span_t *span, zap_event_t **event) #define ZIO_SIGNAL_CB_ARGS (zap_sigmsg_t *sigmsg) @@ -462,6 +467,7 @@ typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; typedef zap_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ; +typedef zap_status_t (*zio_channel_get_sig_status_t) ZIO_CHANNEL_GET_SIG_STATUS_ARGS; typedef zap_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ; typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ; typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ; @@ -488,6 +494,7 @@ typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ; #define ZIO_CHANNEL_REQUEST_FUNCTION(name) zap_status_t name ZIO_CHANNEL_REQUEST_ARGS #define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) zap_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS +#define ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_GET_SIG_STATUS_ARGS #define ZIO_SPAN_POLL_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_POLL_EVENT_ARGS #define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_NEXT_EVENT_ARGS #define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 5aafbf3734..59f17ab875 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -29,6 +29,13 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * David Yatzin + * Nenad Corbic + * */ #include "openzap.h" @@ -1506,10 +1513,30 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) { - /* TODO: Notify the upper layer of the signaling status change (via span signaling callback and a new msg type?) */ + zap_sigmsg_t sig; + zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; + zap_log(ZAP_LOG_DEBUG, "%d:%d Signaling link status changed to %s\n", zchan->span_id, zchan->chan_id, zap_sig_status2str(status)); + + 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_SIGSTATUS_CHANGED; + sig.raw_data = &status; + sig.raw_data_len = sizeof(status); + sangoma_boost_data->signal_cb(&sig); return; } +static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_sig_status) +{ + zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; + if (!sangoma_boost_data->sigmod) { + zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost channel with no signaling module configured\n"); + return ZAP_FAIL; + } + return sangoma_boost_data->sigmod->get_sig_status(zchan, status); +} /** * \brief Initialises an sangoma boost span from configuration variables @@ -1612,8 +1639,8 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) FAIL_CONFIG_RETURN(ZAP_FAIL); } sigmod_iface->pvt = lib; - sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); sigmod_iface->set_write_msg_cb(zap_boost_write_msg); + sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); hashtable_insert(g_boost_modules_hash, (void *)sigmod_iface->name, sigmod_iface, HASHTABLE_FLAG_NONE); lib = NULL; /* destroying the lib will be done when going down and NOT on FAIL_CONFIG_RETURN */ } @@ -1642,6 +1669,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; span->outgoing_call = sangoma_boost_outgoing_call; span->channel_request = sangoma_boost_channel_request; + span->get_sig_status = sangoma_boost_get_sig_status; span->state_map = &boost_state_map; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5141e2f524..3a623f3db7 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1255,6 +1255,22 @@ OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) return ZAP_FAIL; } +OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus) +{ + zap_status_t status; + + zap_assert(zchan != NULL, ZAP_FAIL, "Null channel\n"); + zap_assert(sigstatus != NULL, ZAP_FAIL, "Null sig status"); + + if (zchan->span->get_sig_status) { + status = zchan->span->get_sig_status(zchan, sigstatus); + } else { + zap_log(ZAP_LOG_ERROR, "get_sig_status method not implemented!\n"); + } + + return ZAP_FAIL; +} + OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) { assert(zchan != NULL); From c557472f2595f1f860d7448193fbcbf35eebfae6 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 18:42:35 +0000 Subject: [PATCH 1586/1766] added ZAP_COMMAND_GET_LINK_STATUS for sangoma boards git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@870 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 4 +-- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 27 +++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 38b749c0d7..045d60cb2f 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -301,6 +301,7 @@ typedef enum { ZAP_COMMAND_FLUSH_BUFFERS, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, ZAP_COMMAND_SET_LINK_STATUS, + ZAP_COMMAND_GET_LINK_STATUS, ZAP_COMMAND_COUNT } zap_command_t; @@ -421,8 +422,7 @@ struct zap_state_map { typedef struct zap_state_map zap_state_map_t; typedef enum zap_hw_link_status { - ZAP_HW_LINK_UNINITIALIZED = 0, - ZAP_HW_LINK_DISCONNECTED, + ZAP_HW_LINK_DISCONNECTED = 0, ZAP_HW_LINK_CONNECTED } zap_hw_link_status_t; diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 88a8aaf574..02103c6fcd 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -598,22 +598,19 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) case ZAP_COMMAND_SET_LINK_STATUS: { zap_hw_link_status_t status = ZAP_COMMAND_OBJ_INT; - char sangoma_status; - switch (status) { - case ZAP_HW_LINK_UNINITIALIZED: - sangoma_status = FE_UNITIALIZED; - break; - case ZAP_HW_LINK_DISCONNECTED: - sangoma_status = FE_DISCONNECTED; - break; - case ZAP_HW_LINK_CONNECTED: - sangoma_status = FE_CONNECTED; - break; - default: - return ZAP_FAIL; - } - err = sangoma_tdm_set_fe_status(zchan->sockfd, &tdm_api, status); + char sangoma_status = status == ZAP_HW_LINK_CONNECTED ? FE_CONNECTED : FE_DISCONNECTED; + err = sangoma_tdm_set_fe_status(zchan->sockfd, &tdm_api, sangoma_status); } + break; + case ZAP_COMMAND_GET_LINK_STATUS: + { + unsigned char sangoma_status = 0; + err = sangoma_tdm_get_fe_status(zchan->sockfd, &tdm_api, &sangoma_status); + if (!err) { + ZAP_COMMAND_OBJ_INT = sangoma_status == FE_CONNECTED ? ZAP_HW_LINK_CONNECTED : ZAP_HW_LINK_DISCONNECTED; + } + } + break; default: break; }; From c6cf9e61cd5073689506887e1cab4911b16636cc Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 21:09:21 +0000 Subject: [PATCH 1587/1766] added hardware link notification git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@871 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 10 +-- .../src/ozmod/ozmod_analog/ozmod_analog.c | 29 -------- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 6 +- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 6 +- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 29 ++++++-- .../sangoma_boost_sigmod.h | 15 +++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 68 +++++++++---------- 7 files changed, 83 insertions(+), 80 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 045d60cb2f..a6736012a0 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -140,7 +140,6 @@ typedef enum { 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, @@ -212,10 +211,13 @@ typedef enum { ZAP_SIGEVENT_RESTART, /* Signaling link status changed (D-chan up, down, R2 blocked etc) */ ZAP_SIGEVENT_SIGSTATUS_CHANGED, + /* Hardware link status changed (Line connected, disconnected) */ + ZAP_SIGEVENT_HWSTATUS_CHANGED, ZAP_SIGEVENT_INVALID } zap_signal_event_t; #define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \ - "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGLINK_CHANGED", "INVALID" + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", \ + "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGLINK_CHANGED", "HWSTATUS_CHANGED", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) typedef enum { @@ -421,10 +423,10 @@ struct zap_state_map { }; typedef struct zap_state_map zap_state_map_t; -typedef enum zap_hw_link_status { +typedef enum zap_channel_hw_link_status { ZAP_HW_LINK_DISCONNECTED = 0, ZAP_HW_LINK_CONNECTED -} zap_hw_link_status_t; +} zap_channel_hw_link_status_t; typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 4da3e2e564..6e6a4c9664 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -874,35 +874,6 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); - } - } } end: diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index a92877ca14..cd92d2b900 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1519,7 +1519,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even switch(event->enum_id) { case ZAP_OOB_ALARM_TRAP: { - sig.event_id = ZAP_OOB_ALARM_TRAP; + sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)ZAP_HW_LINK_DISCONNECTED; 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); @@ -1544,7 +1545,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); - sig.event_id = ZAP_OOB_ALARM_CLEAR; + sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)ZAP_HW_LINK_CONNECTED; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index ec92684a57..af34e000f7 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -820,7 +820,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even switch(event->enum_id) { case ZAP_OOB_ALARM_TRAP: { - sig.event_id = ZAP_OOB_ALARM_TRAP; + sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)ZAP_HW_LINK_CONNECTED; 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); @@ -845,7 +846,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); - sig.event_id = ZAP_OOB_ALARM_CLEAR; + sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)ZAP_HW_LINK_CONNECTED; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 59f17ab875..7555ad329c 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1088,6 +1088,10 @@ static __inline__ void check_state(zap_span_t *span) static __inline__ void check_events(zap_span_t *span, int ms_timeout) { zap_status_t status; + zap_sigmsg_t sigmsg; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + + memset(&sigmsg, 0, sizeof(sigmsg)); status = zap_span_poll_event(span, ms_timeout); @@ -1096,9 +1100,27 @@ static __inline__ void check_events(zap_span_t *span, int ms_timeout) { 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()) + sigmsg.span_id = event->channel->span_id; + sigmsg.chan_id = event->channel->chan_id; + sigmsg.channel = event->channel; + switch (event->enum_id) { + case ZAP_OOB_ALARM_TRAP: + sigmsg.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; + sigmsg.raw_data = (void *)ZAP_HW_LINK_DISCONNECTED; + if (sangoma_boost_data->sigmod) { + sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, ZAP_HW_LINK_DISCONNECTED); + } + sangoma_boost_data->signal_cb(&sigmsg); + break; + case ZAP_OOB_ALARM_CLEAR: + sigmsg.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; + sigmsg.raw_data = (void *)ZAP_HW_LINK_CONNECTED; + if (sangoma_boost_data->sigmod) { + sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, ZAP_HW_LINK_CONNECTED); + } + sangoma_boost_data->signal_cb(&sigmsg); + break; + } } } break; @@ -1523,7 +1545,6 @@ static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) sig.channel = zchan; sig.event_id = ZAP_SIGEVENT_SIGSTATUS_CHANGED; sig.raw_data = &status; - sig.raw_data_len = sizeof(status); sangoma_boost_data->signal_cb(&sig); return; } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h index 441536c74f..89bec2dce6 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h @@ -85,15 +85,24 @@ typedef void (*boost_set_sig_status_cb_func_t) BOOST_SET_SIG_STATUS_CB_ARGS; #define BOOST_SET_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SET_SIG_STATUS_CB_ARGS /*! - \brief Get the signaling status on the given channel. + \brief Notify hardware status change \param zchan The openzap channel - \param status The status pointer where the current signaling status will be set + \param status The hw status \return ZAP_SUCCESS or ZAP_FAIL */ #define BOOST_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t *status) typedef zap_status_t (*boost_get_sig_status_func_t) BOOST_GET_SIG_STATUS_ARGS; #define BOOST_GET_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_SIG_STATUS_ARGS +/*! + \brief Get the signaling status on the given channel. + \param zchan The openzap channel + \param status The status pointer where the current signaling status will be set + */ +#define BOOST_ON_HW_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) +typedef void (*boost_on_hw_link_status_change_t) BOOST_ON_HW_STATUS_CHANGE_ARGS; +#define BOOST_ON_HW_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_STATUS_CHANGE_ARGS + /*! \brief Set the signaling status on the given channel. \param zchan The openzap channel @@ -148,6 +157,8 @@ typedef struct boost_sigmod_interface_s { boost_get_sig_status_func_t get_sig_status; /*! \brief set channel signaling status */ boost_set_sig_status_func_t set_sig_status; + /*! \brief set notify hardware link status change */ + boost_on_hw_link_status_change_t on_hw_link_status_change; /*! \brief configure span signaling */ boost_configure_span_func_t configure_span; /*! \brief start openzap span */ diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 02103c6fcd..f7dbb042ad 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -597,7 +597,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_SET_LINK_STATUS: { - zap_hw_link_status_t status = ZAP_COMMAND_OBJ_INT; + zap_channel_hw_link_status_t status = ZAP_COMMAND_OBJ_INT; char sangoma_status = status == ZAP_HW_LINK_CONNECTED ? FE_CONNECTED : FE_DISCONNECTED; err = sangoma_tdm_set_fe_status(zchan->sockfd, &tdm_api, sangoma_status); } @@ -741,30 +741,24 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { #ifdef LIBSANGOMA_VERSION - sangoma_status_t sangstatus; + 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]; + 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; + inflags[j] = POLLPRI; #else memset(&pfds[j], 0, sizeof(pfds[j])); pfds[j].fd = span->channels[i]->sockfd; @@ -772,7 +766,6 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) #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; } @@ -788,7 +781,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) 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); + 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; @@ -812,13 +805,13 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } #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; - } + 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 @@ -863,15 +856,15 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) #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; + 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; + 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 @@ -1003,24 +996,25 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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 }; + 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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); - if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_PRESENT) { + 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) { + 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); - zap_channel_queue_dtmf(zchan, tmp_dtmf); - } - } - break; + zap_channel_queue_dtmf(zchan, tmp_dtmf); + } + } + break; case WP_TDMAPI_EVENT_ALARM: - event_id = ZAP_OOB_NOOP; + { + event_id = ZAP_OOB_NOOP; + } break; default: { From 453fe5f72f7c8d5a293018f844b80577be21cd5f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 21:15:54 +0000 Subject: [PATCH 1588/1766] split initialization from configuration git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@872 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 7052d8e17b..4024b40d31 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -720,6 +720,7 @@ OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *v OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name); OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_global_init(void); +OZ_DECLARE(zap_status_t) zap_global_configuration(void); OZ_DECLARE(zap_status_t) zap_global_destroy(void); OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler); OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 3a623f3db7..fba9453e2c 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2818,8 +2818,6 @@ OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) OZ_DECLARE(zap_status_t) zap_global_init(void) { - int modcount; - memset(&globals, 0, sizeof(globals)); time_init(); @@ -2830,20 +2828,22 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - modcount = 0; zap_mutex_create(&globals.mutex); zap_mutex_create(&globals.span_mutex); - - modcount = zap_load_modules(); + return ZAP_FAIL; +} + +OZ_DECLARE(zap_status_t) zap_global_configuration(void) +{ + int modcount = zap_load_modules(); zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); - if (load_config() == ZAP_SUCCESS) { - globals.running = 1; - return ZAP_SUCCESS; + if (load_config() != ZAP_SUCCESS) { + globals.running = 0; + zap_log(ZAP_LOG_ERROR, "OpenZap global configuration failed!\n"); + return ZAP_FAIL; } - - zap_log(ZAP_LOG_ERROR, "No modules configured!\n"); - return ZAP_FAIL; + return ZAP_SUCCESS; } OZ_DECLARE(uint32_t) zap_running(void) From c495be57fb05534cfcede303854b642213791326 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 22:22:02 +0000 Subject: [PATCH 1589/1766] add helper macro to name boost interface git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@873 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 +- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 7555ad329c..5090ca7197 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1653,7 +1653,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) FAIL_CONFIG_RETURN(ZAP_FAIL); } - if (!(sigmod_iface = (boost_sigmod_interface_t *)zap_dso_func_sym(lib, "boost_sigmod_interface", &err))) { + if (!(sigmod_iface = (boost_sigmod_interface_t *)zap_dso_func_sym(lib, BOOST_INTERFACE_NAME, &err))) { zap_log(ZAP_LOG_ERROR, "Failed to read Sangoma boost signaling module interface '%s': %s\n", path, err); snprintf(span->last_error, sizeof(span->last_error), "Failed to read Sangoma boost signaling module interface '%s': %s", path, err); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h index 89bec2dce6..8b09b25261 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h @@ -169,6 +169,9 @@ typedef struct boost_sigmod_interface_s { void *pvt; } boost_sigmod_interface_t; +#define BOOST_INTERFACE_NAME "boost_sigmod_interface" +/* use this in your sig boost module to declare your interface */ +#define BOOST_INTERFACE boost_sigmod_interface_t BOOST_INTERFACE_NAME #endif /* For Emacs: From 7f7fac27afb3bcd603bc9a36d941d7f5d9c6c1f1 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 22:27:41 +0000 Subject: [PATCH 1590/1766] renamed sangoma_boost_sigmod.h to sangoma_boost_interface.h git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@874 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h | 2 +- .../{sangoma_boost_sigmod.h => sangoma_boost_interface.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename libs/freetdm/src/ozmod/ozmod_sangoma_boost/{sangoma_boost_sigmod.h => sangoma_boost_interface.h} (100%) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index e38ea050b3..01eeb0803b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -34,7 +34,7 @@ #ifndef _SANGOMABC_H #define _SANGOMABC_H -#include "sangoma_boost_sigmod.h" +#include "sangoma_boost_interface.h" #include #include diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_sigmod.h rename to libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h From b9270aea0e1fcede93f67cc27ef83ff0022b43a1 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 16 Nov 2009 22:36:11 +0000 Subject: [PATCH 1591/1766] fix ifndef git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@875 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 8b09b25261..63f8194f1b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -32,8 +32,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SANGOMA_BOOST_SIGMOD_H -#define SANGOMA_BOOST_SIGMOD_H +#ifndef SANGOMA_BOOST_INTERFACE_H +#define SANGOMA_BOOST_INTERFACE_H #include "zap_types.h" From fadd0826c7476585d69df7baf6fd66bdebeed20c Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 17 Nov 2009 16:44:29 +0000 Subject: [PATCH 1592/1766] oops git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@876 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index fba9453e2c..941c4facc9 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2830,7 +2830,7 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); zap_mutex_create(&globals.mutex); zap_mutex_create(&globals.span_mutex); - return ZAP_FAIL; + return ZAP_SUCCESS; } OZ_DECLARE(zap_status_t) zap_global_configuration(void) From 29f6db19afe5646234589ea3eb17a917d750f80d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 17 Nov 2009 18:06:57 +0000 Subject: [PATCH 1593/1766] added git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@877 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testsangomaboost.c | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 libs/freetdm/src/testsangomaboost.c diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c new file mode 100644 index 0000000000..a0b02792c4 --- /dev/null +++ b/libs/freetdm/src/testsangomaboost.c @@ -0,0 +1,85 @@ +#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); + } + + if (zap_global_configuration() != ZAP_SUCCESS) { + fprintf(stderr, "Error configuring 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 1 + if (1) { + if (zap_configure_span("sangoma_boost", span, on_signal, + "sigmod", "sangoma_brid", + "local_port", &local_port, + "remote_ip", "127.0.0.66", + "remote_port", &remote_port, + TAG_END) == ZAP_SUCCESS) { + zap_span_start(span); + + } else { + fprintf(stderr, "Error starting sangoma_boost\n"); + goto done; + } + } +#endif + + 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: + */ From 00c5bf00339270e31c9bd406829ddb9d89381af8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 17 Nov 2009 18:12:07 +0000 Subject: [PATCH 1594/1766] renamed a boost interface macro git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@878 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 63f8194f1b..06e65bb974 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -99,9 +99,9 @@ typedef zap_status_t (*boost_get_sig_status_func_t) BOOST_GET_SIG_STATUS_ARGS; \param zchan The openzap channel \param status The status pointer where the current signaling status will be set */ -#define BOOST_ON_HW_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) -typedef void (*boost_on_hw_link_status_change_t) BOOST_ON_HW_STATUS_CHANGE_ARGS; -#define BOOST_ON_HW_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_STATUS_CHANGE_ARGS +#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) +typedef void (*boost_on_hw_link_status_change_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS; +#define BOOST_ON_HW_LINK_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS /*! \brief Set the signaling status on the given channel. From c1ee86a046833e3c2fa5d4b1af7de14179d26116 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 17 Nov 2009 18:47:23 +0000 Subject: [PATCH 1595/1766] simplify openzap signaling configuration API git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@879 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 49 +++++++++--------- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/include/zap_types.h | 24 ++++++++- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 51 +++++-------------- .../sangoma_boost_interface.h | 4 +- libs/freetdm/src/zap_io.c | 26 ++++++++++ 6 files changed, 89 insertions(+), 66 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 886d14a71a..6ba5ee724e 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2306,41 +2306,45 @@ static switch_status_t load_config(void) for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); + char *sigmod = (char *) switch_xml_attr(myspan, "sigmod"); zap_status_t zstatus = ZAP_FAIL; const char *context = "default"; const char *dialplan = "XML"; uint32_t span_id = 0; zap_span_t *span = NULL; const char *tonegroup = NULL; - char *local_ip = NULL; - int local_port = 0; - char *remote_ip = NULL; - int remote_port = 0; + zap_conf_parameter_t spanparameters[30]; + unsigned paramindex = 0; + + if (!id && !name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "boost span requires an id or name as attribute: \n"); + continue; + } + memset(spanparameters, 0, sizeof(spanparameters)); + if (sigmod) { + spanparameters[paramindex].var = "sigmod"; + spanparameters[paramindex].val = sigmod; + paramindex++; + } for (param = switch_xml_child(myspan, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); - + if (sizeof(spanparameters)/sizeof(spanparameters[0]) == paramindex) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Too many parameters for boost span, ignoring any parameter after %s\n", var); + break; + } if (!strcasecmp(var, "tonegroup")) { tonegroup = val; - } else if (!strcasecmp(var, "local-ip")) { - local_ip = val; - } else if (!strcasecmp(var, "local-port")) { - local_port = atoi(val); - } else if (!strcasecmp(var, "remote-ip")) { - remote_ip = val; - } else if (!strcasecmp(var, "remote-port")) { - remote_port = atoi(val); } else if (!strcasecmp(var, "context")) { context = val; } else if (!strcasecmp(var, "dialplan")) { dialplan = val; - } - } - - if (!id && !name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param\n"); - continue; + } else { + spanparameters[paramindex].var = var; + spanparameters[paramindex].val = val; + paramindex++; + } } if (!tonegroup) { @@ -2369,12 +2373,7 @@ static switch_status_t load_config(void) span_id = span->span_id; } - if (zap_configure_span("sangoma_boost", span, on_clear_channel_signal, - "local_ip", local_ip, - "local_port", &local_port, - "remote_ip", remote_ip, - "remote_port", &remote_port, - TAG_END) != ZAP_SUCCESS) { + if (zap_configure_span_signaling("sangoma_boost", span, on_clear_channel_signal, spanparameters) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); continue; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4024b40d31..7c5280e0ee 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -737,6 +737,7 @@ OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan); OZ_DECLARE(int) zap_load_modules(void); OZ_DECLARE(zap_status_t) zap_unload_modules(void); OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); +OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *parameters); OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index a6736012a0..b415ecfb31 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -29,6 +29,11 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * */ #ifndef ZAP_TYPES_H @@ -428,6 +433,11 @@ typedef enum zap_channel_hw_link_status { ZAP_HW_LINK_CONNECTED } zap_channel_hw_link_status_t; +typedef struct zap_conf_parameter_s { + const char *var; + const char *val; +} zap_conf_parameter_t; + typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; @@ -464,6 +474,7 @@ typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t #define ZIO_IO_UNLOAD_ARGS (void) #define ZIO_SIG_LOAD_ARGS (void) #define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap) +#define ZIO_CONFIGURE_SPAN_SIGNALING_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *zap_parameters) #define ZIO_SIG_UNLOAD_ARGS (void) #define ZIO_API_ARGS (zap_stream_handle_t *stream, const char *data) @@ -489,6 +500,7 @@ typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; typedef zap_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ; typedef zap_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ; typedef zap_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ; +typedef zap_status_t (*zio_configure_span_signaling_t) ZIO_CONFIGURE_SPAN_SIGNALING_ARGS ; typedef zap_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ; typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ; typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ; @@ -516,14 +528,13 @@ typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ; #define ZIO_IO_LOAD_FUNCTION(name) zap_status_t name ZIO_IO_LOAD_ARGS #define ZIO_SIG_LOAD_FUNCTION(name) zap_status_t name ZIO_SIG_LOAD_ARGS #define ZIO_SIG_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_SIG_CONFIGURE_ARGS +#define ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_SIGNALING_ARGS #define ZIO_IO_UNLOAD_FUNCTION(name) zap_status_t name ZIO_IO_UNLOAD_ARGS #define ZIO_SIG_UNLOAD_FUNCTION(name) zap_status_t name ZIO_SIG_UNLOAD_ARGS #define ZIO_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS #include "zap_dso.h" - - typedef struct { char name[256]; zio_io_load_t io_load; @@ -533,6 +544,15 @@ typedef struct { zio_sig_unload_t sig_unload; zap_dso_lib_t lib; char path[256]; + /*! + \brief configure a given span signaling + \see sig_configure + This is just like sig_configure but receives + an array of paramters instead of va_list + I'd like to deprecate sig_configure and move + all modules to use sigparam_configure + */ + zio_configure_span_signaling_t configure_span_signaling; } zap_module_t; #ifndef __FUNCTION__ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 5090ca7197..96be901f69 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1566,7 +1566,7 @@ static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_sig_status) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) +static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) { #define FAIL_CONFIG_RETURN(retstatus) \ if (sangoma_boost_data) \ @@ -1577,7 +1577,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) zap_mutex_unlock(g_boost_modules_mutex); \ if (lib) \ zap_dso_destroy(lib); \ - va_end(conflist); \ return retstatus; boost_sigmod_interface_t *sigmod_iface = NULL; @@ -1585,44 +1584,27 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; const char *sigmod = NULL; int local_port = 53000, remote_port = 53000; - char *var = NULL, *val = NULL; - int *intval = NULL; + const char *var = NULL, *val = NULL; int hash_locked = 0; zap_dso_lib_t lib = NULL; char path[255] = ""; char *err = NULL; - va_list conflist; + unsigned paramindex = 0; - /* we need to copy the list before moving with va_arg in case this configuration should be handled by a sigmod */ - va_copy(conflist, ap); /* WARNING: must be freed before returning */ - - while((var = va_arg(ap, char *))) { + for (; zap_parameters[paramindex].var; paramindex++) { + var = zap_parameters[paramindex].var; + val = zap_parameters[paramindex].val; if (!strcasecmp(var, "sigmod")) { - if (!(val = va_arg(ap, char *))) { - break; - } sigmod = val; } else 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; + local_port = atoi(val); } else if (!strcasecmp(var, "remote_port")) { - if (!(intval = va_arg(ap, int *))) { - break; - } - remote_port = *intval; - } else { + remote_port = atoi(val); + } else if (!sigmod) { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); FAIL_CONFIG_RETURN(ZAP_FAIL); } @@ -1676,7 +1658,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) } zap_log(ZAP_LOG_NOTICE, "Span %s will use Sangoma Boost Signaling Module %s\n", span->name, sigmod_iface->name); sangoma_boost_data->sigmod = sigmod_iface; - sigmod_iface->configure_span(span, conflist); + sigmod_iface->configure_span(span, zap_parameters); } else { zap_set_string(sangoma_boost_data->mcon.cfg.local_ip, local_ip); sangoma_boost_data->mcon.cfg.local_port = local_port; @@ -1693,9 +1675,6 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) span->get_sig_status = sangoma_boost_get_sig_status; span->state_map = &boost_state_map; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - - va_end(conflist); - return ZAP_SUCCESS; } @@ -1703,12 +1682,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) * \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, - zap_sangoma_boost_destroy + .name = "sangoma_boost", + .sig_load = zap_sangoma_boost_init, + .sig_unload = zap_sangoma_boost_destroy, + .configure_span_signaling = zap_sangoma_boost_configure_span }; /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 06e65bb974..4d91f86a05 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -116,10 +116,10 @@ typedef zap_status_t (*boost_set_sig_status_func_t) BOOST_SET_SIG_STATUS_ARGS; /*! \brief Configure the given span signaling \param span The openzap span - \param ap The list of configuration key,value pairs (must be null terminated) + \param parameters The array of configuration key,value pairs (must be null terminated) \return ZAP_SUCCESS or ZAP_FAIL */ -#define BOOST_CONFIGURE_SPAN_ARGS (zap_span_t *span, va_list ap) +#define BOOST_CONFIGURE_SPAN_ARGS (zap_span_t *span, zap_conf_parameter_t *parameters) typedef zap_status_t (*boost_configure_span_func_t) BOOST_CONFIGURE_SPAN_ARGS; #define BOOST_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name BOOST_CONFIGURE_SPAN_ARGS diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 941c4facc9..122397bcd2 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2806,6 +2806,32 @@ OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, return status; } +OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *parameters) +{ + zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); + zap_status_t status = ZAP_FAIL; + + zap_assert(type != NULL, ZAP_FAIL, "No signaling type"); + zap_assert(span != NULL, ZAP_FAIL, "No span"); + zap_assert(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); + zap_assert(parameters != NULL, ZAP_FAIL, "No parameters"); + + if (!mod) { + zap_load_module_assume(type); + if ((mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type))) { + zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + + if (mod && mod->configure_span_signaling) { + status = mod->configure_span_signaling(span, sig_cb, parameters); + } else { + zap_log(ZAP_LOG_ERROR, "can't find module '%s' or the module did not implement the signaling configuration method\n", type); + } + + return status; +} + OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) { if (span->start) { From 5a2bb60b40a458fbe9e9e0cc54de60720e320a8c Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 17 Nov 2009 20:49:41 +0000 Subject: [PATCH 1596/1766] added extern C crap git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@880 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/fsk.h | 8 ++++++++ libs/freetdm/src/include/hashtable.h | 7 +++++++ libs/freetdm/src/include/hashtable_itr.h | 7 ++++++- libs/freetdm/src/include/hashtable_private.h | 7 ++++++- libs/freetdm/src/include/openzap.h | 20 +++++++++++++------ libs/freetdm/src/include/uart.h | 7 +++++++ libs/freetdm/src/include/zap_buffer.h | 8 ++++++++ libs/freetdm/src/include/zap_config.h | 7 +++++++ libs/freetdm/src/include/zap_dso.h | 7 +++++++ libs/freetdm/src/include/zap_m3ua.h | 8 +++++++- libs/freetdm/src/include/zap_threadmutex.h | 7 +++++++ libs/freetdm/src/include/zap_types.h | 7 +++++++ .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 +- .../sangoma_boost_interface.h | 7 ++++--- 14 files changed, 96 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/src/include/fsk.h b/libs/freetdm/src/include/fsk.h index b098444d03..66da140df9 100644 --- a/libs/freetdm/src/include/fsk.h +++ b/libs/freetdm/src/include/fsk.h @@ -35,6 +35,10 @@ #define __FSK_H__ #include "uart.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { int freq_space; /* Frequency of the 0 bit */ int freq_mark; /* Frequency of the 1 bit */ @@ -109,5 +113,9 @@ void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); extern fsk_modem_definition_t fsk_modem_definitions[]; +#ifdef __cplusplus +} /* extern C */ +#endif + #endif diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 0d185bbc5b..7a94354d5d 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -9,6 +9,9 @@ #endif #include "openzap.h" +#ifdef __cplusplus +extern "C" { +#endif struct hashtable; struct hashtable_iterator; @@ -181,6 +184,10 @@ OZ_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h); OZ_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i); OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); +#ifdef __cplusplus +} /* extern C */ +#endif + #endif /* __HASHTABLE_CWC22_H__ */ /* diff --git a/libs/freetdm/src/include/hashtable_itr.h b/libs/freetdm/src/include/hashtable_itr.h index 6897ce949c..59b73a5863 100644 --- a/libs/freetdm/src/include/hashtable_itr.h +++ b/libs/freetdm/src/include/hashtable_itr.h @@ -5,6 +5,9 @@ #include "hashtable.h" #include "hashtable_private.h" /* needed to enable inlining */ +#ifdef __cplusplus +extern "C" { +#endif /*****************************************************************************/ /* This struct is only concrete here to allow the inlining of two of the * accessor functions. */ @@ -79,7 +82,9 @@ hashtable_iterator_search(struct hashtable_itr *itr, return (hashtable_iterator_search(i,h,k)); \ } - +#ifdef __cplusplus +} +#endif #endif /* __HASHTABLE_ITR_CWC22__*/ diff --git a/libs/freetdm/src/include/hashtable_private.h b/libs/freetdm/src/include/hashtable_private.h index 1bb10fd016..47988d8d8f 100644 --- a/libs/freetdm/src/include/hashtable_private.h +++ b/libs/freetdm/src/include/hashtable_private.h @@ -5,7 +5,9 @@ #include "hashtable.h" - +#ifdef __cplusplus +extern "C" { +#endif /*****************************************************************************/ struct entry @@ -56,6 +58,9 @@ indexFor(unsigned int tablelength, unsigned int hashvalue) { #define freekey(X) free(X) /*define freekey(X) ; */ +#ifdef __cplusplus +} +#endif /*****************************************************************************/ diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 7c5280e0ee..4547951cd3 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -297,12 +297,6 @@ } while(0); -typedef enum { - ZAP_STATE_CHANGE_FAIL, - ZAP_STATE_CHANGE_SUCCESS, - ZAP_STATE_CHANGE_SAME, -} zap_state_change_result_t; - #define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ @@ -323,6 +317,16 @@ typedef enum { */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + ZAP_STATE_CHANGE_FAIL, + ZAP_STATE_CHANGE_SUCCESS, + ZAP_STATE_CHANGE_SAME, +} zap_state_change_result_t; + struct zap_stream_handle { zap_stream_handle_write_function_t write_function; zap_stream_handle_raw_write_function_t raw_write_function; @@ -851,6 +855,10 @@ static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag) zap_mutex_unlock(span->mutex); } +#ifdef __cplusplus +} /* extern C */ +#endif + #endif /* For Emacs: diff --git a/libs/freetdm/src/include/uart.h b/libs/freetdm/src/include/uart.h index 89c3a13abc..b1b04c09a4 100644 --- a/libs/freetdm/src/include/uart.h +++ b/libs/freetdm/src/include/uart.h @@ -34,6 +34,10 @@ #ifndef __UART_H__ #define __UART_H__ +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*bytehandler_func_t) (void *, int); typedef void (*bithandler_func_t) (void *, int); @@ -72,5 +76,8 @@ void dsp_uart_destroy(dsp_uart_handle_t **handle); void dsp_uart_bit_handler(void *handle, int bit); +#ifdef __cplusplus +} +#endif #endif diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h index 9a05420979..03d4caae11 100644 --- a/libs/freetdm/src/include/zap_buffer.h +++ b/libs/freetdm/src/include/zap_buffer.h @@ -36,6 +36,10 @@ #include "openzap.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * @defgroup zap_buffer Buffer Routines * @ingroup buffer @@ -133,6 +137,10 @@ OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen); +#ifdef __cplusplus +} +#endif + #endif /* For Emacs: * Local Variables: diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h index f2f2e374bf..d961700ea4 100644 --- a/libs/freetdm/src/include/zap_config.h +++ b/libs/freetdm/src/include/zap_config.h @@ -70,6 +70,10 @@ #define zap_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)) #endif +#ifdef __cplusplus +extern "C" { +#endif + typedef struct zap_config zap_config_t; /*! \brief A simple file handle representing an open configuration file **/ @@ -123,6 +127,9 @@ int zap_config_next_pair(zap_config_t * cfg, char **var, char **val); */ OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); +#ifdef __cplusplus +} +#endif /** @} */ #endif diff --git a/libs/freetdm/src/include/zap_dso.h b/libs/freetdm/src/include/zap_dso.h index bf51f92b18..9cfe87e962 100644 --- a/libs/freetdm/src/include/zap_dso.h +++ b/libs/freetdm/src/include/zap_dso.h @@ -21,6 +21,10 @@ #ifndef _ZAP_DSO_H #define _ZAP_DSO_H +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*zap_func_ptr_t) (void); typedef void * zap_dso_lib_t; @@ -28,6 +32,9 @@ 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); +#ifdef __cplusplus +} +#endif #endif diff --git a/libs/freetdm/src/include/zap_m3ua.h b/libs/freetdm/src/include/zap_m3ua.h index 18de6db838..c06d112093 100644 --- a/libs/freetdm/src/include/zap_m3ua.h +++ b/libs/freetdm/src/include/zap_m3ua.h @@ -39,6 +39,10 @@ //#include "m3ua_client.h" #include "openzap.h" + +#ifdef __cplusplus +extern "C" { +#endif enum e_sigboost_event_id_values { SIGBOOST_EVENT_CALL_START = 0x80, /*128*/ @@ -113,7 +117,9 @@ zap_status_t m3ua_init(zap_io_interface_t **zint); zap_status_t m3ua_destroy(void); zap_status_t m3ua_start(zap_span_t *span); - +#ifdef __cplusplus +} +#endif /* For Emacs: * Local Variables: diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h index f131c48cf0..488dca1c42 100644 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ b/libs/freetdm/src/include/zap_threadmutex.h @@ -27,6 +27,9 @@ #include "openzap.h" +#ifdef __cplusplus +extern "C" { +#endif typedef struct zap_mutex zap_mutex_t; typedef struct zap_thread zap_thread_t; typedef struct zap_condition zap_condition_t; @@ -45,6 +48,10 @@ OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **cond); OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *cond); OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *cond, int ms); +#ifdef __cplusplus +} +#endif + #endif /* For Emacs: diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index b415ecfb31..5833e6401a 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -63,6 +63,9 @@ typedef ssize_t zap_ssize_t; typedef int zap_filehandle_t; #endif +#ifdef __cplusplus +extern "C" { +#endif #define TAG_END NULL typedef size_t zap_size_t; @@ -655,6 +658,10 @@ typedef enum { ZAP_CAUSE_MEDIA_TIMEOUT = 604 } zap_call_cause_t; +#ifdef __cplusplus +} +#endif + #endif /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 96be901f69..0ede9ce653 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1635,7 +1635,7 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) FAIL_CONFIG_RETURN(ZAP_FAIL); } - if (!(sigmod_iface = (boost_sigmod_interface_t *)zap_dso_func_sym(lib, BOOST_INTERFACE_NAME, &err))) { + if (!(sigmod_iface = (boost_sigmod_interface_t *)zap_dso_func_sym(lib, BOOST_INTERFACE_NAME_STR, &err))) { zap_log(ZAP_LOG_ERROR, "Failed to read Sangoma boost signaling module interface '%s': %s\n", path, err); snprintf(span->last_error, sizeof(span->last_error), "Failed to read Sangoma boost signaling module interface '%s': %s", path, err); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 4d91f86a05..78e1655d60 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -35,7 +35,7 @@ #ifndef SANGOMA_BOOST_INTERFACE_H #define SANGOMA_BOOST_INTERFACE_H -#include "zap_types.h" +#include "openzap.h" /*! \brief Callback used to notify signaling status changes on a channel @@ -111,7 +111,7 @@ typedef void (*boost_on_hw_link_status_change_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ */ #define BOOST_SET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t status) typedef zap_status_t (*boost_set_sig_status_func_t) BOOST_SET_SIG_STATUS_ARGS; -#define BOOST_SET_SIG_STATUS_FUNCTION(name) zap_status_t BOOST_SET_SIG_STATUS_ARGS +#define BOOST_SET_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_SIG_STATUS_ARGS /*! \brief Configure the given span signaling @@ -169,7 +169,8 @@ typedef struct boost_sigmod_interface_s { void *pvt; } boost_sigmod_interface_t; -#define BOOST_INTERFACE_NAME "boost_sigmod_interface" +#define BOOST_INTERFACE_NAME boost_sigmod_interface +#define BOOST_INTERFACE_NAME_STR "boost_sigmod_interface" /* use this in your sig boost module to declare your interface */ #define BOOST_INTERFACE boost_sigmod_interface_t BOOST_INTERFACE_NAME #endif From 77e5eb21bfde5d0e95ddcc88c296c870748e6719 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 17 Nov 2009 23:13:38 +0000 Subject: [PATCH 1597/1766] Added testsangomaboost git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@881 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 88d2a59815..b86cb530d4 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -109,6 +109,7 @@ noinst_PROGRAMS = testtones detect_tones detect_dtmf testisdn testpri testr2 tes if HAVE_SCTP noinst_PROGRAMS += testboost endif +noinst_PROGRAMS += testsangomaboost testapp_SOURCES = $(SRC)/testapp.c testapp_LDADD = libopenzap.la @@ -148,6 +149,10 @@ testboost_LDADD = libopenzap.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) endif +testsangomaboost_SOURCES = $(SRC)/testsangomaboost.c +testsangomaboost_LDADD = libopenzap.la +testsangomaboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) + testanalog_SOURCES = $(SRC)/testanalog.c testanalog_LDADD = libopenzap.la testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) From 0b75f2de272136bc528adec6677c4150c8e4a48c Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 18 Nov 2009 17:13:33 +0000 Subject: [PATCH 1598/1766] Fix for zap_global_config not called git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@882 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 6ba5ee724e..d5ad1875ef 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2881,6 +2881,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) return SWITCH_STATUS_TERM; } + if (zap_global_configuration() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP\n"); + return SWITCH_STATUS_TERM; + } + if (load_config() != SWITCH_STATUS_SUCCESS) { zap_global_destroy(); return SWITCH_STATUS_TERM; From e909bac50068194a3d866be4cec52cbfb4824540 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 18 Nov 2009 19:23:40 +0000 Subject: [PATCH 1599/1766] fix assertion git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@883 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_io.c | 2 +- libs/freetdm/src/zap_threadmutex.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 122397bcd2..51c7a2e813 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -212,7 +212,7 @@ OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy) { - g_zap_crash_policy = policy; + g_zap_crash_policy |= policy; } OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index fa4691d03c..4d19933b9e 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -239,7 +239,7 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap { zap_condition_t *condition = NULL; - zap_assert(condition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); + zap_assert(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); condition = zap_calloc(1, sizeof(*condition)); From e832b9be2ae51a0cce0dc7880bfbc342bffac4b0 Mon Sep 17 00:00:00 2001 From: Michael Collins Date: Thu, 19 Nov 2009 01:18:59 +0000 Subject: [PATCH 1600/1766] Fix SIT segment frequency in tones.conf git-svn-id: http://svn.openzap.org/svn/openzap/trunk@884 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/tones.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index 8046578c68..db6658d78e 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -19,7 +19,7 @@ detect-callwaiting-cas => 2750,2130 detect-fail1 => 913.8 detect-fail2 => 1370.6 -detect-fail3 => 776.7 +detect-fail3 => 1776.7 From f1f126b5d5d29d38d5e46942b28b95d1fab5db7b Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 19 Nov 2009 19:38:33 +0000 Subject: [PATCH 1601/1766] Added BOOST_ON_LOAD_FUNCTION and BOOST_ON_UNLOAD_FUNCTION git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@885 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../sangoma_boost_interface.h | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 78e1655d60..adc786d3d2 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -100,7 +100,7 @@ typedef zap_status_t (*boost_get_sig_status_func_t) BOOST_GET_SIG_STATUS_ARGS; \param status The status pointer where the current signaling status will be set */ #define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) -typedef void (*boost_on_hw_link_status_change_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS; +typedef void (*boost_on_hw_link_status_change_func_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS; #define BOOST_ON_HW_LINK_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS /*! @@ -141,6 +141,20 @@ typedef zap_status_t (*boost_start_span_func_t) BOOST_START_SPAN_ARGS; typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; #define BOOST_STOP_SPAN_FUNCTION(name) zap_status_t name BOOST_STOP_SPAN_ARGS +/*! + \brief Called when the module is being loaded BEFORE calling anything else + */ +#define BOOST_ON_LOAD_ARGS (void) +typedef void (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; +#define BOOST_ON_LOAD_FUNCTION(name) void name BOOST_ON_LOAD_ARGS + +/*! + \brief Called when the module is being unloaded, last chance to stop everything! + */ +#define BOOST_ON_UNLOAD_ARGS (void) +typedef void (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; +#define BOOST_ON_UNLOAD_FUNCTION(name) void name BOOST_ON_UNLOAD_ARGS + /*! \brief The boost signaling module interface */ @@ -158,13 +172,17 @@ typedef struct boost_sigmod_interface_s { /*! \brief set channel signaling status */ boost_set_sig_status_func_t set_sig_status; /*! \brief set notify hardware link status change */ - boost_on_hw_link_status_change_t on_hw_link_status_change; + boost_on_hw_link_status_change_func_t on_hw_link_status_change; /*! \brief configure span signaling */ boost_configure_span_func_t configure_span; /*! \brief start openzap span */ boost_start_span_func_t start_span; /*! \brief stop openzap span */ boost_stop_span_func_t stop_span; + /*! \brief the module was just loaded */ + boost_on_load_func_t on_load; + /*! \brief the module is about to be unloaded */ + boost_on_load_func_t on_unload; /*! \brief private pointer for the interface user */ void *pvt; } boost_sigmod_interface_t; From c9223883dcf5d7add116c8f98c5e8eb56ae868cc Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 19 Nov 2009 20:10:34 +0000 Subject: [PATCH 1602/1766] call on_load and on_unload methods git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@886 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 11 ++++++++++- .../ozmod_sangoma_boost/sangoma_boost_interface.h | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 0ede9ce653..9ae91de014 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1376,7 +1376,12 @@ static ZIO_SIG_UNLOAD_FUNCTION(zap_sangoma_boost_destroy) hashtable_this(i, &key, NULL, &val); if (key && val) { sigmod = val; - zap_dso_destroy(sigmod->pvt); + if (sigmod->on_unload() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to unload boost signaling module object\n"); + /* hope for the best */ + } else { + zap_dso_destroy(sigmod->pvt); + } } } @@ -1641,6 +1646,10 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) FAIL_CONFIG_RETURN(ZAP_FAIL); } + if (sigmod_iface->on_load() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to load Sangoma boost signaling module interface '%s': on_load method failed\n", path); + FAIL_CONFIG_RETURN(ZAP_FAIL); + } sigmod_iface->pvt = lib; sigmod_iface->set_write_msg_cb(zap_boost_write_msg); sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index adc786d3d2..bcd2184991 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -143,16 +143,17 @@ typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; /*! \brief Called when the module is being loaded BEFORE calling anything else + \return ZAP_SUCCESS or ZAP_FAIL */ #define BOOST_ON_LOAD_ARGS (void) -typedef void (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; +typedef zap_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; #define BOOST_ON_LOAD_FUNCTION(name) void name BOOST_ON_LOAD_ARGS /*! \brief Called when the module is being unloaded, last chance to stop everything! */ #define BOOST_ON_UNLOAD_ARGS (void) -typedef void (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; +typedef zap_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; #define BOOST_ON_UNLOAD_FUNCTION(name) void name BOOST_ON_UNLOAD_ARGS /*! From f1eadddd314f69efbbfdea37e49bd6cdb5063851 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 19 Nov 2009 21:20:19 +0000 Subject: [PATCH 1603/1766] fix channel sig status enum to string converter git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@887 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 6 ++++-- libs/freetdm/src/zap_io.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 5833e6401a..673734ca1c 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -195,9 +195,11 @@ typedef enum { /* The channel signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */ ZAP_SIG_STATE_SUSPENDED, /* The channel signaling link is ready and calls can be placed */ - ZAP_SIG_STATE_UP + ZAP_SIG_STATE_UP, + /* Invalid status */ + ZAP_SIG_STATE_INVALID } zap_channel_sig_status_t; -#define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP" +#define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP", "INVALID" ZAP_STR2ENUM_P(zap_str2zap_channel_sig_status, zap_sig_status2str, zap_channel_sig_status_t) typedef enum { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 51c7a2e813..8f88695893 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -114,6 +114,8 @@ ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYP ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) +ZAP_ENUM_NAMES(CHAN_SIG_STATUS_NAMES, SIGSTATUS_STRINGS) +ZAP_STR2ENUM(zap_str2zap_channel_sig_status, zap_sig_status2str, zap_channel_sig_status_t, CHAN_SIG_STATUS_NAMES, ZAP_SIG_STATE_INVALID) static const char *cut_path(const char *in) { From 44eb096e7639e8da900d2c8626764431dbb1c394 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 20 Nov 2009 02:17:21 +0000 Subject: [PATCH 1604/1766] refactor enterprise_originate git-svn-id: http://svn.openzap.org/svn/openzap/trunk@888 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 886d14a71a..c295113351 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -125,7 +125,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, - switch_originate_flag_t flags); + switch_originate_flag_t flags, switch_call_cause_t *cancel_cause); static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); @@ -1028,7 +1028,7 @@ that allocate memory or you will have 1 channel with memory allocated from anoth static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, - switch_originate_flag_t flags) + switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) { const char *dest = NULL; From ac06f30774895c3afc07eb63867e2a0884c348d4 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 20 Nov 2009 16:20:36 +0000 Subject: [PATCH 1605/1766] Fixed issue when mcon->mutex was not initialized git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@889 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 26 ++++++++----------- .../sangoma_boost_client.c | 22 +++++++++------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 9ae91de014..32af0a5c48 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1157,7 +1157,9 @@ static zap_status_t zap_boost_connection_open(zap_span_t *span) { zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - return sangoma_boost_data->sigmod->start_span(span); + if (sangoma_boost_data->sigmod->start_span(span) != ZAP_SUCCESS) { + return ZAP_FAIL; + } } sangoma_boost_data->pcon = sangoma_boost_data->mcon; @@ -1338,9 +1340,10 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) zap_log(ZAP_LOG_CRIT, "Boost event processing Error!\n"); end: - - sangomabc_connection_close(&sangoma_boost_data->mcon); - sangomabc_connection_close(&sangoma_boost_data->pcon); + if (!sangoma_boost_data->sigmod) { + sangomabc_connection_close(&sangoma_boost_data->mcon); + sangomabc_connection_close(&sangoma_boost_data->pcon); + } zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); @@ -1371,17 +1374,14 @@ static ZIO_SIG_UNLOAD_FUNCTION(zap_sangoma_boost_destroy) boost_sigmod_interface_t *sigmod = NULL; const void *key = NULL; void *val = NULL; + zap_dso_lib_t lib; for (i = hashtable_first(g_boost_modules_hash); i; i = hashtable_next(i)) { hashtable_this(i, &key, NULL, &val); if (key && val) { sigmod = val; - if (sigmod->on_unload() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to unload boost signaling module object\n"); - /* hope for the best */ - } else { - zap_dso_destroy(sigmod->pvt); - } + lib = sigmod->pvt; + zap_dso_destroy(&lib); } } @@ -1581,7 +1581,7 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) if (hash_locked) \ zap_mutex_unlock(g_boost_modules_mutex); \ if (lib) \ - zap_dso_destroy(lib); \ + zap_dso_destroy(&lib); \ return retstatus; boost_sigmod_interface_t *sigmod_iface = NULL; @@ -1646,10 +1646,6 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) FAIL_CONFIG_RETURN(ZAP_FAIL); } - if (sigmod_iface->on_load() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to load Sangoma boost signaling module interface '%s': on_load method failed\n", path); - FAIL_CONFIG_RETURN(ZAP_FAIL); - } sigmod_iface->pvt = lib; sigmod_iface->set_write_msg_cb(zap_boost_write_msg); sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index cf421aa4fa..f2021d5392 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -173,7 +173,6 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int } } - zap_mutex_create(&mcon->mutex); return mcon->socket; } @@ -201,8 +200,9 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon) int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) { + zap_mutex_create(&mcon->mutex); if (mcon->sigmod) { - zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); + /*value of mcon->socket will be ignored in sigmod mode */ return 0; } create_conn_socket(mcon, local_ip, local_port, ip, port); @@ -474,22 +474,24 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ 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 (!mcon->sigmod) { + 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; + event->version = SIGBOOST_VERSION; if (mcon->sigmod) { mcon->sigmod->write_msg(mcon->span, event, event_size); - err = event_size; - return -1; + err = event_size; + } else { err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); } From 4de9a4c0d13a94359b8d1094a76447a3e56e550d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 20 Nov 2009 16:42:31 +0000 Subject: [PATCH 1606/1766] Resolved conflict git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@890 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 6 ++++++ .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 32af0a5c48..783200a536 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1595,6 +1595,7 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) char path[255] = ""; char *err = NULL; unsigned paramindex = 0; + zap_status_t rc = ZAP_SUCCESS; for (; zap_parameters[paramindex].var; paramindex++) { var = zap_parameters[paramindex].var; @@ -1646,6 +1647,11 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) FAIL_CONFIG_RETURN(ZAP_FAIL); } + rc = sigmod_iface->on_load(); + if (rc != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to load Sangoma boost signaling module interface '%s': on_load method failed (%d)\n", path, rc); + FAIL_CONFIG_RETURN(ZAP_FAIL); + } sigmod_iface->pvt = lib; sigmod_iface->set_write_msg_cb(zap_boost_write_msg); sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index bcd2184991..3b5d11b007 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -183,7 +183,7 @@ typedef struct boost_sigmod_interface_s { /*! \brief the module was just loaded */ boost_on_load_func_t on_load; /*! \brief the module is about to be unloaded */ - boost_on_load_func_t on_unload; + boost_on_unload_func_t on_unload; /*! \brief private pointer for the interface user */ void *pvt; } boost_sigmod_interface_t; From 3268b4ae34b428c6a21e95c6bf7ea92fc62571c5 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 20 Nov 2009 16:46:49 +0000 Subject: [PATCH 1607/1766] Fix for ON_LOAD returning zap_status_t git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@891 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 3b5d11b007..c337995dca 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -147,14 +147,14 @@ typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; */ #define BOOST_ON_LOAD_ARGS (void) typedef zap_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; -#define BOOST_ON_LOAD_FUNCTION(name) void name BOOST_ON_LOAD_ARGS +#define BOOST_ON_LOAD_FUNCTION(name) zap_status_t name BOOST_ON_LOAD_ARGS /*! \brief Called when the module is being unloaded, last chance to stop everything! */ #define BOOST_ON_UNLOAD_ARGS (void) typedef zap_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; -#define BOOST_ON_UNLOAD_FUNCTION(name) void name BOOST_ON_UNLOAD_ARGS +#define BOOST_ON_UNLOAD_FUNCTION(name) zap_status_t name BOOST_ON_UNLOAD_ARGS /*! \brief The boost signaling module interface From 3245ec99977818d7163b8c1571a23282bd53aa5a Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 20 Nov 2009 22:57:24 +0000 Subject: [PATCH 1608/1766] Fixed zap_queues git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@892 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 13 +++++++++-- libs/freetdm/src/zap_io.c | 1 + libs/freetdm/src/zap_queue.c | 22 +++++++++---------- libs/freetdm/src/zap_threadmutex.c | 15 ++++++++++--- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 783200a536..3a2752cddb 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1195,6 +1195,13 @@ static int zap_boost_wait_event(zap_span_t *span, int ms) sangomabc_connection_t *mcon, *pcon; zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + if (sangoma_boost_data->sigmod) { + int result; + result = zap_queue_wait(sangoma_boost_data->boost_queue, ms); + if (result == ZAP_TIMEOUT) return 0; + if (result != ZAP_SUCCESS) return -1; + return 1; + } mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; @@ -1266,6 +1273,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) } if (zap_boost_connection_open(span) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "zap_boost_connection failed\n"); goto end; } @@ -1291,10 +1299,12 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); zap_set_flag(mcon, MSU_FLAG_DOWN); + zap_log(ZAP_LOG_DEBUG, "OPENZAP is no longer running\n"); break; } if ((activity = zap_boost_wait_event(span, ms)) < 0) { + zap_log(ZAP_LOG_ERROR, "Zap boost waitevent failed\n"); goto error; } @@ -1534,8 +1544,7 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) } memcpy(&element->boostmsg, msg, msglen); element->size = msglen; - zap_queue_enqueue(sangoma_boost_data->boost_queue, element); - return ZAP_SUCCESS; + return zap_queue_enqueue(sangoma_boost_data->boost_queue, element); } static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 8f88695893..75fa7339db 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2858,6 +2858,7 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); zap_mutex_create(&globals.mutex); zap_mutex_create(&globals.span_mutex); + globals.running = 1; return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 88de09351c..e04707537b 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -39,6 +39,7 @@ typedef struct zap_queue { zap_mutex_t *mutex; zap_condition_t *condition; zap_size_t size; + zap_size_t num_elements; unsigned rindex; unsigned windex; void **elements; @@ -128,13 +129,13 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) queue->windex = 0; } - if (queue->windex == queue->rindex) { + if (queue->num_elements != 0 && queue->windex == queue->rindex) { zap_log(ZAP_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex); goto done; } queue->elements[queue->windex++] = obj; status = ZAP_SUCCESS; - + queue->num_elements++; /* wake up queue reader */ zap_condition_signal(queue->condition); @@ -153,12 +154,13 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) zap_mutex_lock(queue->mutex); - if (!queue->elements[queue->rindex]) { + if (queue->num_elements == 0) { goto done; } - + obj = queue->elements[queue->rindex]; - queue->elements[queue->rindex] = NULL; + queue->elements[queue->rindex++] = NULL; + queue->num_elements--; if (queue->rindex == queue->size) { queue->rindex = 0; } @@ -170,6 +172,7 @@ done: static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) { + zap_status_t ret; zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -179,14 +182,9 @@ static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) return ZAP_SUCCESS; } - if (zap_condition_wait(queue->condition, ms)) { - zap_mutex_unlock(queue->mutex); - return ZAP_FAIL; - } - + ret = zap_condition_wait(queue->condition, ms); zap_mutex_unlock(queue->mutex); - - return ZAP_SUCCESS; + return ret; } static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 4d19933b9e..a6e9dc26c8 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -205,8 +205,11 @@ OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex) #ifdef WIN32 EnterCriticalSection(&mutex->mutex); #else - if (pthread_mutex_lock(&mutex->mutex)) + int err; + if ((err = pthread_mutex_lock(&mutex->mutex))) { + zap_log(ZAP_LOG_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err)); return ZAP_FAIL; + } #endif return ZAP_SUCCESS; } @@ -259,6 +262,7 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap } #endif + *incondition = condition; return ZAP_SUCCESS; failed: @@ -287,7 +291,10 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) #else int res = 0; if (ms > 0) { - struct timespec waitms = { 0, ((ms * 1000) * 1000)}; + struct timespec waitms; + waitms.tv_sec = time(NULL)+(ms/1000); + waitms.tv_nsec = 1000*1000*(ms%1000); + res = pthread_cond_timedwait(&condition->condition, condition->mutex, &waitms); } else { res = pthread_cond_wait(&condition->condition, condition->mutex); @@ -310,7 +317,9 @@ OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) return ZAP_FAIL; } #else - if (pthread_cond_signal(&condition->condition)) { + int err; + if ((err = pthread_cond_signal(&condition->condition))) { + zap_log(ZAP_LOG_ERROR, "Failed to signal condition %d:%s\n", err, strerror(err)); return ZAP_FAIL; } #endif From 10f8ab08067cdb39fc146d8e2140536f9ea9c403 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 21 Nov 2009 04:45:22 +0000 Subject: [PATCH 1609/1766] beautify some code git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@893 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 4 +- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 41 +++++++------------ libs/freetdm/src/zap_queue.c | 33 +++++++++------ libs/freetdm/src/zap_threadmutex.c | 5 +-- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 4547951cd3..1b50a6d31b 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -620,7 +620,7 @@ struct zap_io_interface { struct zap_queue; #define zap_queue_t struct zap_queue -typedef zap_status_t (*zap_queue_create_func_t)(zap_queue_t **queue, zap_size_t); +typedef zap_status_t (*zap_queue_create_func_t)(zap_queue_t **queue, zap_size_t capacity); typedef zap_status_t (*zap_queue_enqueue_func_t)(zap_queue_t *queue, void *obj); typedef void *(*zap_queue_dequeue_func_t)(zap_queue_t *queue); typedef zap_status_t (*zap_queue_wait_func_t)(zap_queue_t *queue, int ms); @@ -635,7 +635,7 @@ typedef struct zap_queue_handler { OZ_DECLARE_DATA extern zap_queue_handler_t g_zap_queue_handler; /*! brief create a new queue */ -#define zap_queue_create(queue, size) g_zap_queue_handler.create(queue, size) +#define zap_queue_create(queue, capacity) g_zap_queue_handler.create(queue, capacity) /*! Enqueue an object */ #define zap_queue_enqueue(queue, obj) g_zap_queue_handler.enqueue(queue, obj) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 3a2752cddb..a33b1cc351 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1164,6 +1164,7 @@ static zap_status_t zap_boost_connection_open(zap_span_t *span) sangoma_boost_data->pcon = sangoma_boost_data->mcon; + /* when sigmod is present, all arguments: local_ip etc, are ignored by sangomabc_connection_open */ if (sangomabc_connection_open(&sangoma_boost_data->mcon, sangoma_boost_data->mcon.cfg.local_ip, sangoma_boost_data->mcon.cfg.local_port, @@ -1196,10 +1197,14 @@ static int zap_boost_wait_event(zap_span_t *span, int ms) zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - int result; - result = zap_queue_wait(sangoma_boost_data->boost_queue, ms); - if (result == ZAP_TIMEOUT) return 0; - if (result != ZAP_SUCCESS) return -1; + zap_status_t res; + res = zap_queue_wait(sangoma_boost_data->boost_queue, ms); + if (ZAP_TIMEOUT == res) { + return 0; + } + if (ZAP_SUCCESS != res) { + return -1; + } return 1; } mcon = &sangoma_boost_data->mcon; @@ -1273,7 +1278,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) } if (zap_boost_connection_open(span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "zap_boost_connection failed\n"); + zap_log(ZAP_LOG_ERROR, "zap_boost_connection_open failed\n"); goto end; } @@ -1299,46 +1304,28 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); zap_set_flag(mcon, MSU_FLAG_DOWN); - zap_log(ZAP_LOG_DEBUG, "OPENZAP is no longer running\n"); + zap_log(ZAP_LOG_DEBUG, "zap is no longer running\n"); break; } if ((activity = zap_boost_wait_event(span, ms)) < 0) { - zap_log(ZAP_LOG_ERROR, "Zap boost waitevent failed\n"); + zap_log(ZAP_LOG_ERROR, "zap_boost_wait_event failed\n"); goto error; } if (activity) { - while ((event = zap_boost_read_event(span))) { parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event); sangoma_boost_data->iteration++; } - } - 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); } @@ -1346,10 +1333,10 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) goto end; - error: +error: zap_log(ZAP_LOG_CRIT, "Boost event processing Error!\n"); - end: +end: if (!sangoma_boost_data->sigmod) { sangomabc_connection_close(&sangoma_boost_data->mcon); sangomabc_connection_close(&sangoma_boost_data->pcon); diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index e04707537b..7f40b036df 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -38,14 +38,14 @@ typedef struct zap_queue { zap_mutex_t *mutex; zap_condition_t *condition; + zap_size_t capacity; zap_size_t size; - zap_size_t num_elements; unsigned rindex; unsigned windex; void **elements; } zap_queue_t; -static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t size); +static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity); static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj); static void *zap_std_queue_dequeue(zap_queue_t *queue); static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms); @@ -74,10 +74,10 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl return ZAP_SUCCESS; } -static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t size) +static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity) { zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); - zap_assert(size > 0, ZAP_FAIL, "Queue size is not bigger than 0\n"); + zap_assert(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); *outqueue = NULL; zap_queue_t *queue = zap_calloc(1, sizeof(*queue)); @@ -85,11 +85,11 @@ static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t size return ZAP_FAIL; } - queue->elements = zap_calloc(1, (sizeof(void*)*size)); + queue->elements = zap_calloc(1, (sizeof(void*)*capacity)); if (!queue->elements) { goto failed; } - queue->size = size; + queue->capacity = capacity; if (zap_mutex_create(&queue->mutex) != ZAP_SUCCESS) { goto failed; @@ -124,18 +124,20 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) zap_mutex_lock(queue->mutex); - if (queue->windex == queue->size) { + if (queue->windex == queue->capacity) { /* try to see if we can wrap around */ queue->windex = 0; } - if (queue->num_elements != 0 && queue->windex == queue->rindex) { + if (queue->size != 0 && queue->windex == queue->rindex) { zap_log(ZAP_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex); goto done; } + queue->elements[queue->windex++] = obj; + queue->size++; status = ZAP_SUCCESS; - queue->num_elements++; + /* wake up queue reader */ zap_condition_signal(queue->condition); @@ -154,19 +156,21 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) zap_mutex_lock(queue->mutex); - if (queue->num_elements == 0) { + if (queue->size == 0) { goto done; } obj = queue->elements[queue->rindex]; queue->elements[queue->rindex++] = NULL; - queue->num_elements--; + queue->size--; if (queue->rindex == queue->size) { queue->rindex = 0; } done: + zap_mutex_unlock(queue->mutex); + return obj; } @@ -177,13 +181,18 @@ static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) zap_mutex_lock(queue->mutex); - if (queue->elements[queue->rindex]) { + /* if there is elements in the queue, no need to wait */ + if (queue->size != 0) { zap_mutex_unlock(queue->mutex); return ZAP_SUCCESS; } + /* no elements on the queue, wait for someone to write an element */ ret = zap_condition_wait(queue->condition, ms); + + /* got an element or timeout, bail out */ zap_mutex_unlock(queue->mutex); + return ret; } diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index a6e9dc26c8..e0744158a7 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -292,9 +292,8 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) int res = 0; if (ms > 0) { struct timespec waitms; - waitms.tv_sec = time(NULL)+(ms/1000); - waitms.tv_nsec = 1000*1000*(ms%1000); - + waitms.tv_sec = time(NULL) + ( ms / 1000 ); + waitms.tv_nsec = 1000 * 1000 * ( ms % 1000 ); res = pthread_cond_timedwait(&condition->condition, condition->mutex, &waitms); } else { res = pthread_cond_wait(&condition->condition, condition->mutex); From a365b7e2382d63a313370156052c263030149e9c Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 23 Nov 2009 16:22:53 +0000 Subject: [PATCH 1610/1766] allow --libdir git-svn-id: http://svn.openzap.org/svn/openzap/trunk@895 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index d5e1e734ec..9f0c74869a 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -33,7 +33,7 @@ PREFIX = $(prefix) SRC = src moddir = @modinstdir@ -libdir = $(PREFIX)/lib/ +libdir = @libdir@ library_includedir = $(PREFIX)/include INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include From e5089386750dc6414032679563e913cfa8a0f5e5 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 23 Nov 2009 16:40:41 +0000 Subject: [PATCH 1611/1766] ignore boost messages with no span git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@896 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index a33b1cc351..ea5c3175b1 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1524,13 +1524,27 @@ static zap_state_map_t boost_state_map = { static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) { - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - sangomabc_queue_element_t *element = zap_calloc(1, sizeof(*element)); + sangomabc_short_event_t *shortmsg = NULL; + zap_sangoma_boost_data_t *sangoma_boost_data = NULL; + sangomabc_queue_element_t *element = NULL; + + zap_assert(msg != NULL, ZAP_FAIL, "Boost message to write was null"); + + if (!span) { + shortmsg = msg; + zap_log(ZAP_LOG_ERROR, "Unexpected boost message %d\n", shortmsg->event_id); + return ZAP_FAIL; + } + + /* duplicate the event and enqueue it */ + element = zap_calloc(1, sizeof(*element)); if (!element) { return ZAP_FAIL; } memcpy(&element->boostmsg, msg, msglen); element->size = msglen; + + sangoma_boost_data = span->signal_data; return zap_queue_enqueue(sangoma_boost_data->boost_queue, element); } From fda2c273d0dfef178b87f61a050d2820441ab494 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 23 Nov 2009 18:19:35 +0000 Subject: [PATCH 1612/1766] merged revisions 855:895 from openzap/trunk git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@897 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 2 +- libs/freetdm/conf/tones.conf | 2 +- libs/freetdm/mod_openzap/mod_openzap.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index b86cb530d4..770291e461 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -33,7 +33,7 @@ PREFIX = $(prefix) SRC = src moddir = @modinstdir@ -libdir = $(PREFIX)/lib/ +libdir = @libdir@ library_includedir = $(PREFIX)/include INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index 8046578c68..db6658d78e 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -19,7 +19,7 @@ detect-callwaiting-cas => 2750,2130 detect-fail1 => 913.8 detect-fail2 => 1370.6 -detect-fail3 => 776.7 +detect-fail3 => 1776.7 diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index d5ad1875ef..ba3e230d60 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -125,7 +125,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, - switch_originate_flag_t flags); + switch_originate_flag_t flags, switch_call_cause_t *cancel_cause); static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); @@ -1028,7 +1028,7 @@ that allocate memory or you will have 1 channel with memory allocated from anoth static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, - switch_originate_flag_t flags) + switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) { const char *dest = NULL; From d27a7e1b7a8f170ad4b1fa591bb5b95837607d06 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 23 Nov 2009 19:19:12 +0000 Subject: [PATCH 1613/1766] clear dtmf buffer on channel close git-svn-id: http://svn.openzap.org/svn/openzap/trunk@898 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 5d6910db48..c4aa3f6d24 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1225,6 +1225,10 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zchan->pre_buffer_size = 0; zap_mutex_unlock(zchan->pre_buffer_mutex); + if (!zchan->dtmf_buffer) { + zap_buffer_zero(zchan->dtmf_buffer); + } + zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); From 3b47c0786b6d05417fe6d895d75a33c67a3eeca2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 24 Nov 2009 18:15:55 +0000 Subject: [PATCH 1614/1766] start boost spans only after all of them have been configured git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@899 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ba3e230d60..89e1e2a9f8 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1841,7 +1841,11 @@ static switch_status_t load_config(void) { const char *cf = "openzap.conf"; switch_xml_t cfg, xml, settings, param, spans, myspan; + zap_span_t *boost_spans[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN]; + zap_span_t *boost_span = NULL; + unsigned boosti = 0; + memset(boost_spans, 0, sizeof(boost_spans)); memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { @@ -2382,8 +2386,8 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].context, context, sizeof(SPAN_CONFIG[span->span_id].context)); switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); - zap_span_start(span); switch_copy_string(SPAN_CONFIG[span->span_id].type, "Sangoma (boost)", sizeof(SPAN_CONFIG[span->span_id].type)); + boost_spans[boosti++] = span; } } @@ -2552,6 +2556,19 @@ static switch_status_t load_config(void) } } + /* start all boost spans now that we're done configuring. Unfortunately at this point boost modules have the limitation + * of needing all spans to be configured before starting them */ + unsigned i = 0; + for ( ; i < boosti; i++) { + boost_span = boost_spans[i]; + zap_log(ZAP_LOG_DEBUG, "Starting boost span %d\n", boost_span->span_id); + if (zap_span_start(boost_span) == ZAP_FAIL) { + zap_log(ZAP_LOG_ERROR, "Error starting boost OpenZAP span %d, error: %s\n", boost_span->span_id, boost_span->last_error); + continue; + } + } + + switch_xml_free(xml); return SWITCH_STATUS_SUCCESS; From 87b19eacb664f1ee6275fbded6e8770461c8a2d2 Mon Sep 17 00:00:00 2001 From: Brian West Date: Tue, 24 Nov 2009 23:02:16 +0000 Subject: [PATCH 1615/1766] wrong week to quit sniffing glue git-svn-id: http://svn.openzap.org/svn/openzap/trunk@900 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index c4aa3f6d24..3abae9fea1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1225,7 +1225,7 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zchan->pre_buffer_size = 0; zap_mutex_unlock(zchan->pre_buffer_mutex); - if (!zchan->dtmf_buffer) { + if (zchan->dtmf_buffer) { zap_buffer_zero(zchan->dtmf_buffer); } From 360638f0dcd6f9de39a731070bedafec336a889a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 25 Nov 2009 01:42:35 +0000 Subject: [PATCH 1616/1766] dont send boost restart when working sigmod is present git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@901 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 43 +++++++++++-------- .../sangoma_boost_client.c | 4 +- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 9 +++- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index ea5c3175b1..c29df99f1b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -246,13 +246,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_status_t status = ZAP_FAIL; sangoma_boost_request_id_t r; sangomabc_event_t event = {0}; - int sanity = 5000; + int boost_request_timeout = 5000; 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; @@ -340,12 +339,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { zap_sleep(1); - if (--sanity <= 0) { + if (--boost_request_timeout <= 0) { status = ZAP_FAIL; *zchan = NULL; + zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response\n"); goto done; } - //printf("WTF %d\n", sanity); } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { @@ -1160,6 +1159,9 @@ static zap_status_t zap_boost_connection_open(zap_span_t *span) if (sangoma_boost_data->sigmod->start_span(span) != ZAP_SUCCESS) { return ZAP_FAIL; } + 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->pcon = sangoma_boost_data->mcon; @@ -1283,27 +1285,30 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) } init_outgoing_array(); - - sangomabc_exec_commandp(pcon, - 0, - 0, - -1, - SIGBOOST_EVENT_SYSTEM_RESTART, - 0); - zap_set_flag(mcon, MSU_FLAG_DOWN); + if (!sangoma_boost_data->sigmod) { + 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)) { sangomabc_event_t *event = NULL; int activity = 0; if (!zap_running()) { - sangomabc_exec_commandp(pcon, - 0, - 0, - -1, - SIGBOOST_EVENT_SYSTEM_RESTART, - 0); - zap_set_flag(mcon, MSU_FLAG_DOWN); + if (!sangoma_boost_data->sigmod) { + sangomabc_exec_commandp(pcon, + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART, + 0); + zap_set_flag(mcon, MSU_FLAG_DOWN); + } zap_log(ZAP_LOG_DEBUG, "zap is no longer running\n"); break; } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index f2021d5392..2030500ffc 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -75,7 +75,7 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", dir ? "TX":"RX", sangomabc_event_id_name(event->event_id), event->event_id, @@ -93,7 +93,7 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%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), diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index f7dbb042ad..f239d59f8c 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -29,6 +29,13 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * David Yatzin + * Nenad Corbic + * */ #ifdef __sun @@ -62,7 +69,7 @@ #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 +/*! Starting with libsangoma 3 we can use the new libsangoma waitable API, the poor souls of those using a release where LIBSANGOMA version * is defined but the version is not higher or equal to 3.0.0 will be forced to upgrade * */ #ifdef LIBSANGOMA_VERSION From c70f0e226c1a8f65f6d971bac0f260796d752c41 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 25 Nov 2009 01:53:54 +0000 Subject: [PATCH 1617/1766] dont use member names on structure initialization, msvc does not like it git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@902 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/zap_types.h | 4 ++-- .../ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 673734ca1c..0e0d232523 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -547,8 +547,6 @@ typedef struct { 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]; /*! \brief configure a given span signaling \see sig_configure @@ -558,6 +556,8 @@ typedef struct { all modules to use sigparam_configure */ zio_configure_span_signaling_t configure_span_signaling; + zap_dso_lib_t lib; + char path[256]; } zap_module_t; #ifndef __FUNCTION__ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index c29df99f1b..2ab181b268 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1708,10 +1708,13 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) * \brief Openzap sangoma boost signaling module definition */ zap_module_t zap_module = { - .name = "sangoma_boost", - .sig_load = zap_sangoma_boost_init, - .sig_unload = zap_sangoma_boost_destroy, - .configure_span_signaling = zap_sangoma_boost_configure_span + /*.name =*/ "sangoma_boost", + /*.io_load =*/ NULL, + /*.io_unload =*/ NULL, + /*.sig_load = */ zap_sangoma_boost_init, + /*.sig_configure =*/ NULL, + /*.sig_unload = */zap_sangoma_boost_destroy, + /*.configure_span_signaling = */ zap_sangoma_boost_configure_span }; /* For Emacs: From bd00467c76d9baf8e1ea6a30dd49dffc1ce6e83c Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 25 Nov 2009 18:50:04 +0000 Subject: [PATCH 1618/1766] set the span when sending a start request and sigmod is available git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@903 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 3 +++ .../src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 2ab181b268..351e2b65c2 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -326,6 +326,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; + if (sangoma_boost_data->sigmod) { + event.span = span->channels[1]->physical_span_id; + } OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 2030500ffc..43b159ff75 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -368,9 +368,11 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in if (mcon->sigmod) { e = zap_queue_dequeue(mcon->boost_queue); - bytes = e->size; - memcpy(&mcon->event, e->boostmsg, bytes); - zap_safe_free(e); + if (e) { + bytes = e->size; + memcpy(&mcon->event, e->boostmsg, bytes); + zap_safe_free(e); + } } else { bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); } From bea687fb76d0d62265952a22d7572dde44c2a03a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 25 Nov 2009 20:18:29 +0000 Subject: [PATCH 1619/1766] fix hunting of zchan on incoming calls and event reading bug git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@904 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 12 ++++++++++-- .../ozmod_sangoma_boost/sangoma_boost_client.c | 17 +++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 351e2b65c2..7cbcf98a7a 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -191,10 +191,18 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even { int i; zap_channel_t *zchan = NULL; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + int targetspan = event->span+1; + int targetchan = event->chan+1; + if (sangoma_boost_data->sigmod) { + /* span is not strictly needed here since we're supposed to get only events for our span */ + targetspan = event->span; + targetchan = event->chan; + } zap_mutex_lock(signal_mutex); 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) { + if (span->channels[i]->physical_span_id == targetspan && span->channels[i]->physical_chan_id == targetchan) { zchan = span->channels[i]; if (force || (zchan->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(zchan, ZAP_CHANNEL_INUSE))) { break; @@ -1549,7 +1557,7 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) if (!element) { return ZAP_FAIL; } - memcpy(&element->boostmsg, msg, msglen); + memcpy(element->boostmsg, msg, msglen); element->size = msglen; sangoma_boost_data = span->signal_data; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 43b159ff75..89e90d39cb 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -277,9 +277,11 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int if (mcon->sigmod) { e = zap_queue_dequeue(mcon->boost_queue); - bytes = e->size; - memcpy(&mcon->event, e->boostmsg, bytes); - zap_safe_free(e); + if (e) { + bytes = e->size; + memcpy(&mcon->event, e->boostmsg, bytes); + zap_safe_free(e); + } } else { bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); @@ -364,15 +366,10 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in { unsigned int fromlen = sizeof(struct sockaddr_in); int bytes = 0; - sangomabc_queue_element_t *e = NULL; if (mcon->sigmod) { - e = zap_queue_dequeue(mcon->boost_queue); - if (e) { - bytes = e->size; - memcpy(&mcon->event, e->boostmsg, bytes); - zap_safe_free(e); - } + /* priority stuff is handled just the same when there is a sigmod */ + return sangomabc_connection_read(mcon, iteration); } else { bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); } From 3e7e7b6879b02e8341232ba67d7cbf8c90c79ff1 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 25 Nov 2009 20:19:36 +0000 Subject: [PATCH 1620/1766] --srcdir fix (FSBUILD-211) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@905 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/configure.gnu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openzap/configure.gnu b/libs/openzap/configure.gnu index 5785ffc0e7..002d5eab53 100644 --- a/libs/openzap/configure.gnu +++ b/libs/openzap/configure.gnu @@ -1,3 +1,4 @@ #! /bin/sh -./configure "$@" --with-pic +srcpath=$(dirname $0 2>/dev/null ) || srcpath="." +$srcpath/configure "$@" --with-pic From bc25bc771ca8ab55ea0b8e25de12bd889bc779ad Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 25 Nov 2009 20:58:31 +0000 Subject: [PATCH 1621/1766] add BOOST_SPAN and BOOST_CHAN macros git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@906 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 7cbcf98a7a..3f449765fa 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -54,6 +54,10 @@ static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; #define BOOST_QUEUE_SIZE 500 +/* get openzap span and chan depending on the span mode */ +#define BOOST_SPAN(zchan) ((zap_sangoma_boost_data_t*)(zchan)->span->signal_data)->sigmod ? zchan->physical_span_id : zchan->physical_span_id-1 +#define BOOST_CHAN(zchan) ((zap_sangoma_boost_data_t*)(zchan)->span->signal_data)->sigmod ? zchan->physical_chan_id : zchan->physical_chan_id-1 + /** * \brief Strange flag */ @@ -408,11 +412,17 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; - + uint32_t event_span = event->span+1; + uint32_t event_chan = event->chan+1; if (nack_map[event->call_setup_id]) { return; } + if (mcon->sigmod) { + event_span = event->span; + event_chan = event->chan; + } + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; SETUP_GRID[event->span][event->chan] = event->call_setup_id; @@ -423,7 +433,7 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ 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); + zap_log(ZAP_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", zchan->span_id, zchan->chan_id, event_span, event_chan, event->call_setup_id); zchan->sflags = 0; OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; @@ -431,13 +441,7 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ } } - //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)); - } - - - zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event_span, event_chan); sangomabc_exec_command(mcon, event->span, event->chan, @@ -445,7 +449,6 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ SIGBOOST_EVENT_CALL_STOPPED, ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - } /** @@ -912,8 +915,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } else { sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_ACK, 0); @@ -950,16 +953,16 @@ static __inline__ void state_advance(zap_channel_t *zchan) } 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, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_ACK, 0); } sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_ANSWERED, 0); @@ -984,15 +987,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || 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, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED, zchan->caller_data.hangup_cause); } else { sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_NACK, zchan->caller_data.hangup_cause); @@ -1007,8 +1010,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); @@ -1021,8 +1024,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); From 2ea4c03e818f1365670bcbeed30448266c819d2c Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 25 Nov 2009 22:53:23 +0000 Subject: [PATCH 1622/1766] show signaling status on oz list git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@907 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 75 ++++++++++++++++++-------- libs/freetdm/src/zap_io.c | 7 +-- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 89e1e2a9f8..defdc25a8a 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2742,35 +2742,64 @@ SWITCH_STANDARD_API(oz_function) for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { if (SPAN_CONFIG[j].span) { const char *flags = "none"; + zap_channel_sig_status_t chanstatus; if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { flags = "3way"; } else if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_CALL_SWAP) { flags = "call swap"; } - - stream->write_function(stream, - "+OK\n" - "span: %u (%s)\n" - "type: %s\n" - "chan_count: %u\n" - "dialplan: %s\n" - "context: %s\n" - "dial_regex: %s\n" - "fail_dial_regex: %s\n" - "hold_music: %s\n" - "analog_options %s\n", - j, - SPAN_CONFIG[j].span->name, - SPAN_CONFIG[j].type, - SPAN_CONFIG[j].span->chan_count, - SPAN_CONFIG[j].dialplan, - SPAN_CONFIG[j].context, - SPAN_CONFIG[j].dial_regex, - SPAN_CONFIG[j].fail_dial_regex, - SPAN_CONFIG[j].hold_music, - flags - ); + + /* check signaling status just in the first span channel */ + if ((ZAP_SUCCESS == zap_channel_get_sig_status(SPAN_CONFIG[j].span->channels[1], &chanstatus))) { + stream->write_function(stream, + "+OK\n" + "span: %u (%s)\n" + "type: %s\n" + "signaling_status: %s\n" + "chan_count: %u\n" + "dialplan: %s\n" + "context: %s\n" + "dial_regex: %s\n" + "fail_dial_regex: %s\n" + "hold_music: %s\n" + "analog_options %s\n", + j, + SPAN_CONFIG[j].span->name, + SPAN_CONFIG[j].type, + zap_sig_status2str(chanstatus), + SPAN_CONFIG[j].span->chan_count, + SPAN_CONFIG[j].dialplan, + SPAN_CONFIG[j].context, + SPAN_CONFIG[j].dial_regex, + SPAN_CONFIG[j].fail_dial_regex, + SPAN_CONFIG[j].hold_music, + flags + ); + } else { + stream->write_function(stream, + "+OK\n" + "span: %u (%s)\n" + "type: %s\n" + "chan_count: %u\n" + "dialplan: %s\n" + "context: %s\n" + "dial_regex: %s\n" + "fail_dial_regex: %s\n" + "hold_music: %s\n" + "analog_options %s\n", + j, + SPAN_CONFIG[j].span->name, + SPAN_CONFIG[j].type, + SPAN_CONFIG[j].span->chan_count, + SPAN_CONFIG[j].dialplan, + SPAN_CONFIG[j].context, + SPAN_CONFIG[j].dial_regex, + SPAN_CONFIG[j].fail_dial_regex, + SPAN_CONFIG[j].hold_music, + flags + ); + } } } } else if (!strcasecmp(argv[0], "stop") || !strcasecmp(argv[0], "start")) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 75fa7339db..f4627ea7fe 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1259,18 +1259,15 @@ OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus) { - zap_status_t status; - zap_assert(zchan != NULL, ZAP_FAIL, "Null channel\n"); zap_assert(sigstatus != NULL, ZAP_FAIL, "Null sig status"); if (zchan->span->get_sig_status) { - status = zchan->span->get_sig_status(zchan, sigstatus); + return zchan->span->get_sig_status(zchan, sigstatus); } else { zap_log(ZAP_LOG_ERROR, "get_sig_status method not implemented!\n"); + return ZAP_FAIL; } - - return ZAP_FAIL; } OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) From c6e7eaac834c1ad1050c6c437dca80d325e4c6a9 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 26 Nov 2009 16:01:55 +0000 Subject: [PATCH 1623/1766] Fix windows build git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@908 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 6 +++--- libs/freetdm/src/zap_io.c | 20 +++++++++++-------- libs/freetdm/src/zap_threadmutex.c | 11 +++++----- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index defdc25a8a..53546e23ec 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1844,6 +1844,7 @@ static switch_status_t load_config(void) zap_span_t *boost_spans[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN]; zap_span_t *boost_span = NULL; unsigned boosti = 0; + unsigned int i = 0; memset(boost_spans, 0, sizeof(boost_spans)); memset(&globals, 0, sizeof(globals)); @@ -2558,7 +2559,6 @@ static switch_status_t load_config(void) /* start all boost spans now that we're done configuring. Unfortunately at this point boost modules have the limitation * of needing all spans to be configured before starting them */ - unsigned i = 0; for ( ; i < boosti; i++) { boost_span = boost_spans[i]; zap_log(ZAP_LOG_DEBUG, "Starting boost span %d\n", boost_span->span_id); diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index f239d59f8c..5e69cf4356 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -271,14 +271,14 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; } - err = sangoma_tdm_get_hw_dtmf(chan->sockfd, &tdm_api); - if (err > 0) { + //err = sangoma_tdm_get_hw_dtmf(chan->sockfd, &tdm_api); + //if (err > 0) { err = sangoma_tdm_enable_dtmf_events(chan->sockfd, &tdm_api); if (err == 0) { zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); dtmf = "hardware"; } - } + //} } #if 0 diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index f4627ea7fe..b048d7a11b 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -181,31 +181,35 @@ static void default_logger(const char *file, const char *func, int line, int lev } -static inline void *zap_std_malloc(void *pool, zap_size_t size) +static __inline__ void *zap_std_malloc(void *pool, zap_size_t size) { void *ptr = malloc(size); + pool = NULL; /* fix warning */ zap_assert(ptr != NULL, NULL, "Out of memory"); return ptr; } -static inline void *zap_std_calloc(void *pool, zap_size_t elements, zap_size_t size) +static __inline__ void *zap_std_calloc(void *pool, zap_size_t elements, zap_size_t size) { void *ptr = calloc(elements, size); + pool = NULL; zap_assert(ptr != NULL, NULL, "Out of memory"); return ptr; } -static inline void zap_std_free(void *pool, void *ptr) +static __inline__ void zap_std_free(void *pool, void *ptr) { + pool = NULL; + zap_assert(ptr != NULL, , "Attempted to free null pointer"); free(ptr); } OZ_DECLARE_DATA zap_memory_handler_t g_zap_mem_handler = { - .pool = NULL, - .malloc = zap_std_malloc, - .calloc = zap_std_calloc, - .free = zap_std_free + /*.pool =*/ NULL, + /*.malloc =*/ zap_std_malloc, + /*.calloc =*/ zap_std_calloc, + /*.free =*/ zap_std_free }; OZ_DECLARE_DATA zap_crash_policy_t g_zap_crash_policy = ZAP_CRASH_NEVER; @@ -762,7 +766,7 @@ OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token) { - int i; + unsigned int i; if (zchan->token_count) { for(i = 0; i < zchan->token_count; i++) { diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index e0744158a7..0661decfd7 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -274,19 +274,20 @@ failed: OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) { - zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 DWORD res = 0; - res = WaitForSingleObject(condition->condition, waitms > 0 ? waitms : INFINITE); +#endif + zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); +#ifdef WIN32 + res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); switch (res) { case WAIT_ABANDONED: case WAIT_TIMEOUT: return ZAP_TIMEOUT; case WAIT_FAILED: return ZAP_FAIL; - defaul: - zap_log(ZAP_LOG_ERROR, "Error waiting for openzap condition event\n"); - return ZAP_FAIL; + default: + zap_log(ZAP_LOG_ERROR, "Error waiting for openzap condition event (WaitForSingleObject returned %d)\n", res); } #else int res = 0; From 7145817da4b9bbec2c4d0f3d73a76ae0168aa70c Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 27 Nov 2009 16:53:16 +0000 Subject: [PATCH 1624/1766] Support for early media git-svn-id: http://svn.openzap.org/svn/openzap/trunk@909 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 111 +++++++++++++++++- .../sangoma_boost_client.c | 11 +- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 16 ++- 3 files changed, 129 insertions(+), 9 deletions(-) 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 index 947c9c8754..ac48ced23f 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -57,6 +57,7 @@ typedef uint16_t sangoma_boost_request_id_t; typedef enum { BST_FREE, BST_WAITING, + BST_ACK, BST_READY, BST_FAIL } sangoma_boost_request_status_t; @@ -217,6 +218,30 @@ static int check_congestion(int trunk_group) return 0; } +/** + * \brief determines whether media is ready + * \param event boost event + * \return 1 true, 0 for false + */ + +static int boost_media_ready(sangomabc_event_t *event) +{ + /* FORMAT is of type: SMG003-EVI-1-MEDIA-# */ + char* p = NULL; + p = strstr(event->isup_in_rdnis, "MEDIA"); + if (p) { + int media_ready = 0; + if ((sscanf(p, "MEDIA-%d", &media_ready)) == 1) { + if (media_ready) { + return 1; + } else { + } + } else { + zap_log(ZAP_LOG_ERROR, "Invalid boost isup_rdnis MEDIA format %s\n", p); + } + } + return 0; +} /** * \brief Requests an sangoma boost channel on a span (outgoing call) @@ -334,11 +359,30 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } //printf("WTF %d\n", sanity); } + + if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].zchan) { + *zchan = OUTBOUND_REQUESTS[r].zchan; + status = ZAP_SUCCESS; + (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS; + zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); + } + + sanity = 5000; + while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { + zap_sleep(1); + if (--sanity <= 0) { + status = ZAP_FAIL; + *zchan = NULL; + goto done; + } + //printf("WTF %d\n", sanity); + } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { *zchan = OUTBOUND_REQUESTS[r].zchan; status = ZAP_SUCCESS; (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; + zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); } else { status = ZAP_FAIL; *zchan = NULL; @@ -377,6 +421,66 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) 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(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + zap_channel_t *zchan; + + if (nack_map[event->call_setup_id]) { + return; + } + + //if we received a progress for this device already + if (OUTBOUND_REQUESTS[event->call_setup_id].status == BST_ACK) { + if (boost_media_ready((sangomabc_event_t*) event)) { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + zap_log(ZAP_LOG_DEBUG, "chan media ready %d:%d CSid:%d\n", event->span+1, event->chan+1, event->call_setup_id); + } + return; + } + + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + SETUP_GRID[event->span][event->chan] = event->call_setup_id; + + if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*) event, 0))) { + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + } else { + 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 = 0; + OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + if (boost_media_ready((sangomabc_event_t*)event)) { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + } else { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_ACK; + } + return; + } + } + + //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)); + } + + + zap_log(ZAP_LOG_CRIT, "START PROGRESS 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); + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; +} + /** * \brief Handler for call start ack event * \param mcon sangoma boost connection @@ -586,8 +690,8 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); - - release_request_id_span_chan(event->span, event->chan); + + release_request_id_span_chan(event->span, event->chan); } /** @@ -799,6 +903,9 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s case SIGBOOST_EVENT_CALL_START_ACK: handle_call_start_ack(mcon, event); break; + case SIGBOOST_EVENT_CALL_PROGRESS: + handle_call_progress(mcon, event); + break; case SIGBOOST_EVENT_CALL_START_NACK: handle_call_start_nack(span, mcon, event); break; 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 index f0ecef1b97..90c73f2626 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -53,9 +53,10 @@ struct sangomabc_map { }; static struct sangomabc_map sangomabc_table[] = { - {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, - {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "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"}, @@ -75,7 +76,7 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + 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, @@ -85,8 +86,8 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e 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->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) diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h index cf35fd5f8f..abb93a310f 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -30,6 +30,7 @@ enum e_sigboost_event_id_values SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ + 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*/ @@ -68,13 +69,21 @@ enum e_sigboost_huntgroup_values 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, +}; + + #define MAX_DIALED_DIGITS 31 /* Next two defines are used to create the range of values for call_setup_id * in the t_sigboost structure. * 0..((CORE_MAX_SPANS * CORE_MAX_CHAN_PER_SPAN) - 1) */ #define CORE_MAX_SPANS 200 -#define CORE_MAX_CHAN_PER_SPAN 30 +#define 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 */ #define SIZE_RDNIS 900 @@ -99,6 +108,7 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + /* struct timeval tv; */ 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 */ @@ -126,15 +136,18 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + /* 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: return 0; @@ -143,5 +156,4 @@ static inline int boost_full_event(int event_id) return 0; } - #endif From 2f0945309540d98ce2b79fbf90ab947af7ea9570 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 27 Nov 2009 16:59:12 +0000 Subject: [PATCH 1625/1766] Merged r 908:909 from trunk to support early media mode git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@910 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 111 +++++++++++++++++- .../sangoma_boost_client.c | 11 +- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 16 ++- 3 files changed, 129 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 3f449765fa..0522a627de 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -74,6 +74,7 @@ typedef uint16_t sangoma_boost_request_id_t; typedef enum { BST_FREE, BST_WAITING, + BST_ACK, BST_READY, BST_FAIL } sangoma_boost_request_status_t; @@ -242,6 +243,30 @@ static int check_congestion(int trunk_group) return 0; } +/** + * \brief determines whether media is ready + * \param event boost event + * \return 1 true, 0 for false + */ + +static int boost_media_ready(sangomabc_event_t *event) +{ + /* FORMAT is of type: SMG003-EVI-1-MEDIA-# */ + char* p = NULL; + p = strstr(event->isup_in_rdnis, "MEDIA"); + if (p) { + int media_ready = 0; + if ((sscanf(p, "MEDIA-%d", &media_ready)) == 1) { + if (media_ready) { + return 1; + } else { + } + } else { + zap_log(ZAP_LOG_ERROR, "Invalid boost isup_rdnis MEDIA format %s\n", p); + } + } + return 0; +} /** * \brief Requests an sangoma boost channel on a span (outgoing call) @@ -361,11 +386,30 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) goto done; } } + + if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].zchan) { + *zchan = OUTBOUND_REQUESTS[r].zchan; + status = ZAP_SUCCESS; + (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS; + zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); + } + + sanity = 5000; + while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { + zap_sleep(1); + if (--sanity <= 0) { + status = ZAP_FAIL; + *zchan = NULL; + goto done; + } + //printf("WTF %d\n", sanity); + } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { *zchan = OUTBOUND_REQUESTS[r].zchan; status = ZAP_SUCCESS; (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; + zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); } else { status = ZAP_FAIL; *zchan = NULL; @@ -404,6 +448,66 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) 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(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + zap_channel_t *zchan; + + if (nack_map[event->call_setup_id]) { + return; + } + + //if we received a progress for this device already + if (OUTBOUND_REQUESTS[event->call_setup_id].status == BST_ACK) { + if (boost_media_ready((sangomabc_event_t*) event)) { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + zap_log(ZAP_LOG_DEBUG, "chan media ready %d:%d CSid:%d\n", event->span+1, event->chan+1, event->call_setup_id); + } + return; + } + + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + SETUP_GRID[event->span][event->chan] = event->call_setup_id; + + if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*) event, 0))) { + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + } else { + 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 = 0; + OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + if (boost_media_ready((sangomabc_event_t*)event)) { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + } else { + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_ACK; + } + return; + } + } + + //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)); + } + + + zap_log(ZAP_LOG_CRIT, "START PROGRESS 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); + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; +} + /** * \brief Handler for call start ack event * \param mcon sangoma boost connection @@ -612,8 +716,8 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); - - release_request_id_span_chan(event->span, event->chan); + + release_request_id_span_chan(event->span, event->chan); } /** @@ -825,6 +929,9 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s case SIGBOOST_EVENT_CALL_START_ACK: handle_call_start_ack(mcon, event); break; + case SIGBOOST_EVENT_CALL_PROGRESS: + handle_call_progress(mcon, event); + break; case SIGBOOST_EVENT_CALL_START_NACK: handle_call_start_nack(span, mcon, event); break; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 89e90d39cb..d50505c310 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -53,9 +53,10 @@ struct sangomabc_map { }; static struct sangomabc_map sangomabc_table[] = { - {SIGBOOST_EVENT_CALL_START, "CALL_START"}, + {SIGBOOST_EVENT_CALL_START, "CALL_START"}, {SIGBOOST_EVENT_CALL_START_ACK, "CALL_START_ACK"}, - {SIGBOOST_EVENT_CALL_START_NACK, "CALL_START_NACK"}, + {SIGBOOST_EVENT_CALL_START_NACK, "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"}, @@ -75,7 +76,7 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s]\n", + 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, @@ -85,8 +86,8 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e 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->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) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h index cf35fd5f8f..abb93a310f 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -30,6 +30,7 @@ enum e_sigboost_event_id_values SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ + 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*/ @@ -68,13 +69,21 @@ enum e_sigboost_huntgroup_values 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, +}; + + #define MAX_DIALED_DIGITS 31 /* Next two defines are used to create the range of values for call_setup_id * in the t_sigboost structure. * 0..((CORE_MAX_SPANS * CORE_MAX_CHAN_PER_SPAN) - 1) */ #define CORE_MAX_SPANS 200 -#define CORE_MAX_CHAN_PER_SPAN 30 +#define 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 */ #define SIZE_RDNIS 900 @@ -99,6 +108,7 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + /* struct timeval tv; */ 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 */ @@ -126,15 +136,18 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + /* 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: return 0; @@ -143,5 +156,4 @@ static inline int boost_full_event(int event_id) return 0; } - #endif From ecf3294a8836b40d8021c4be65690e639ca9bd5c Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 27 Nov 2009 18:57:35 +0000 Subject: [PATCH 1626/1766] added zap_assert_return macro and replaced old use of zap_assert git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@911 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 18 ++++++++++++++---- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 15 ++++++++------- libs/freetdm/src/zap_io.c | 18 +++++++++--------- libs/freetdm/src/zap_queue.c | 14 +++++++------- libs/freetdm/src/zap_threadmutex.c | 10 +++++----- 5 files changed, 43 insertions(+), 32 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 1b50a6d31b..a1fec59b89 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -263,7 +263,7 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ - int st = obj->state; \ + zap_channel_state_t st = obj->state; \ zap_channel_set_state(obj, s, 1); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ @@ -770,10 +770,20 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #endif /*! - \brief Allocate uninitialized memory - \command chunksize the chunk size + \brief Assert condition */ -#define zap_assert(assertion, retval, msg) \ +#define zap_assert(assertion, msg) \ + if (!(assertion)) { \ + zap_log(ZAP_LOG_CRIT, msg); \ + if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ + abort(); \ + } \ + } + +/*! + \brief Assert condition and return +*/ +#define zap_assert_return(assertion, retval, msg) \ if (!(assertion)) { \ zap_log(ZAP_LOG_CRIT, msg); \ if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 0522a627de..59b47c9100 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -382,7 +382,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) if (--boost_request_timeout <= 0) { status = ZAP_FAIL; *zchan = NULL; - zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response\n"); + zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); goto done; } } @@ -394,13 +394,14 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); } - sanity = 5000; + boost_request_timeout = 5000; while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { zap_sleep(1); - if (--sanity <= 0) { - status = ZAP_FAIL; - *zchan = NULL; - goto done; + if (--boost_request_timeout <= 0) { + status = ZAP_FAIL; + *zchan = NULL; + zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n"); + goto done; } //printf("WTF %d\n", sanity); } @@ -1654,7 +1655,7 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) zap_sangoma_boost_data_t *sangoma_boost_data = NULL; sangomabc_queue_element_t *element = NULL; - zap_assert(msg != NULL, ZAP_FAIL, "Boost message to write was null"); + zap_assert_return(msg != NULL, ZAP_FAIL, "Boost message to write was null"); if (!span) { shortmsg = msg; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index b048d7a11b..7d6c0fbd6a 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -185,7 +185,7 @@ static __inline__ void *zap_std_malloc(void *pool, zap_size_t size) { void *ptr = malloc(size); pool = NULL; /* fix warning */ - zap_assert(ptr != NULL, NULL, "Out of memory"); + zap_assert_return(ptr != NULL, NULL, "Out of memory"); return ptr; } @@ -193,14 +193,14 @@ static __inline__ void *zap_std_calloc(void *pool, zap_size_t elements, zap_size { void *ptr = calloc(elements, size); pool = NULL; - zap_assert(ptr != NULL, NULL, "Out of memory"); + zap_assert_return(ptr != NULL, NULL, "Out of memory"); return ptr; } static __inline__ void zap_std_free(void *pool, void *ptr) { pool = NULL; - zap_assert(ptr != NULL, , "Attempted to free null pointer"); + zap_assert_return(ptr != NULL, , "Attempted to free null pointer"); free(ptr); } @@ -1263,8 +1263,8 @@ OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus) { - zap_assert(zchan != NULL, ZAP_FAIL, "Null channel\n"); - zap_assert(sigstatus != NULL, ZAP_FAIL, "Null sig status"); + zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n"); + zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status"); if (zchan->span->get_sig_status) { return zchan->span->get_sig_status(zchan, sigstatus); @@ -2814,10 +2814,10 @@ OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_status_t status = ZAP_FAIL; - zap_assert(type != NULL, ZAP_FAIL, "No signaling type"); - zap_assert(span != NULL, ZAP_FAIL, "No span"); - zap_assert(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); - zap_assert(parameters != NULL, ZAP_FAIL, "No parameters"); + zap_assert_return(type != NULL, ZAP_FAIL, "No signaling type"); + zap_assert_return(span != NULL, ZAP_FAIL, "No span"); + zap_assert_return(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); + zap_assert_return(parameters != NULL, ZAP_FAIL, "No parameters"); if (!mod) { zap_load_module_assume(type); diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 7f40b036df..6a0a05d683 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -76,8 +76,8 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity) { - zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); - zap_assert(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); + zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); + zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); *outqueue = NULL; zap_queue_t *queue = zap_calloc(1, sizeof(*queue)); @@ -120,7 +120,7 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) { zap_status_t status = ZAP_FAIL; - zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -152,7 +152,7 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) { void *obj = NULL; - zap_assert(queue != NULL, NULL, "Queue is null!"); + zap_assert_return(queue != NULL, NULL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -177,7 +177,7 @@ done: static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) { zap_status_t ret; - zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -199,8 +199,8 @@ static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue) { zap_queue_t *queue = NULL; - zap_assert(inqueue != NULL, ZAP_FAIL, "Queue is null!"); - zap_assert(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(inqueue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); queue = *inqueue; zap_condition_destroy(&queue->condition); diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 0661decfd7..3e894737c0 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -242,8 +242,8 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap { zap_condition_t *condition = NULL; - zap_assert(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); - zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); + zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); + zap_assert_return(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); condition = zap_calloc(1, sizeof(*condition)); if (!condition) { @@ -277,7 +277,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) #ifdef WIN32 DWORD res = 0; #endif - zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); switch (res) { @@ -311,7 +311,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) { - zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 if (!SetEvent(condition->condition)) { return ZAP_FAIL; @@ -329,7 +329,7 @@ OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) { zap_condition_t *condition = NULL; - zap_assert(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); + zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); condition = *incondition; #ifdef WIN32 CloseHandle(condition->condition); From 2c976c9f81db4bb9222cfa72e73b9ccd4d2931a2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 27 Nov 2009 19:21:39 +0000 Subject: [PATCH 1627/1766] use ::abort when compiling in a c++ compiler git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@912 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index a1fec59b89..5350489687 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -776,7 +776,7 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); if (!(assertion)) { \ zap_log(ZAP_LOG_CRIT, msg); \ if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ - abort(); \ + zap_abort(); \ } \ } @@ -787,7 +787,7 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); if (!(assertion)) { \ zap_log(ZAP_LOG_CRIT, msg); \ if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ - abort(); \ + zap_abort(); \ } else { \ return retval; \ } \ @@ -823,6 +823,15 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); */ #define zap_socket_close(it) if (it > -1) { close(it); it = -1;} +static __inline__ void zap_abort(void) +{ +#ifdef __cplusplus + ::abort(); +#else + abort(); +#endif +} + static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state) { uint32_t j; From 48f2ed527da2be9436258108b45d315995730a00 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 27 Nov 2009 20:14:42 +0000 Subject: [PATCH 1628/1766] Fixes to compile in Windows C++ compiler git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@913 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 10 +++++----- libs/freetdm/src/include/zap_types.h | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 5350489687..ddcb9b0133 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -175,6 +175,10 @@ #include "zap_buffer.h" #include "zap_threadmutex.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __WINDOWS__ #define zap_sleep(x) Sleep(x) #else @@ -227,7 +231,7 @@ #define zap_set_flag(obj, flag) (obj)->flags |= (flag) #define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ zap_mutex_lock(obj->mutex); \ - (obj)->flags |= (flag); \ + (obj)->flags |= (flag); \ zap_mutex_unlock(obj->mutex); #define zap_set_pflag(obj, flag) (obj)->pflags |= (flag) @@ -317,10 +321,6 @@ */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) -#ifdef __cplusplus -extern "C" { -#endif - typedef enum { ZAP_STATE_CHANGE_FAIL, ZAP_STATE_CHANGE_SUCCESS, diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 0e0d232523..8cf2b6b30c 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -405,6 +405,17 @@ typedef enum { ZAP_CHANNEL_ANSWERED = (1 << 23), ZAP_CHANNEL_MUTE = (1 << 24) } zap_channel_flag_t; +#if defined(__cplusplus) && defined(WIN32) + // fix C2676 +__inline__ zap_channel_flag_t operator|=(zap_channel_flag_t a, int32_t b) { + a = (zap_channel_flag_t)(a | b); + return a; +} +__inline__ zap_channel_flag_t operator&=(zap_channel_flag_t a, int32_t b) { + a = (zap_channel_flag_t)(a & b); + return a; +} +#endif typedef enum { ZSM_NONE, From 5bb2c0eb3f021fe9535c3e15d312ba2e7c735115 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 27 Nov 2009 21:39:09 +0000 Subject: [PATCH 1629/1766] updated sigboost git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@914 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h index abb93a310f..02a580777e 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -16,8 +16,8 @@ #define SIGBOOST_VERSION 100 -#include -#include +// handy to define integer types that actually work on both Lin and Win +#include enum e_sigboost_event_id_values { From 4778d58223c728503b99e9896cda49599a3c1de0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 27 Nov 2009 22:40:45 +0000 Subject: [PATCH 1630/1766] make ozmod_sangoma_boost compile on Windows ... but not linking yet -_- git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@915 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost.2008.vcproj | 213 ++++++++++++++++++ .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 22 +- .../sangoma_boost_client.c | 88 ++++---- .../sangoma_boost_client.h | 30 +-- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 7 +- 5 files changed, 297 insertions(+), 63 deletions(-) create mode 100644 libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj new file mode 100644 index 0000000000..3f7ef8de43 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 59b47c9100..60cda54675 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -38,6 +38,11 @@ * */ +/* NOTE: +On WIN32 platform this code works with sigmod ONLY, don't try to make sense of any socket code for win32 +I basically ifdef out everything that the compiler complained about +*/ + #include "openzap.h" #include "sangoma_boost_client.h" #include "zap_sangoma_boost.h" @@ -194,11 +199,11 @@ static sangoma_boost_request_id_t __next_request_id(const char *func, int line) */ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *event, int force) { - int i; + uint32_t i; zap_channel_t *zchan = NULL; zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - int targetspan = event->span+1; - int targetchan = event->chan+1; + uint32_t targetspan = event->span+1; + uint32_t targetchan = event->chan+1; if (sangoma_boost_data->sigmod) { /* span is not strictly needed here since we're supposed to get only events for our span */ targetspan = event->span; @@ -358,13 +363,13 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_set_string(event.calling_name, caller_data->cid_name); zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); if (strlen(caller_data->rdnis.digits)) { - event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; + event.isup_in_rdnis_size = (uint16_t)strlen(caller_data->rdnis.digits)+1; } event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; if (sangoma_boost_data->sigmod) { - event.span = span->channels[1]->physical_span_id; + event.span = (uint8_t)span->channels[1]->physical_span_id; } OUTBOUND_REQUESTS[r].status = BST_WAITING; @@ -1315,9 +1320,11 @@ static zap_status_t zap_boost_connection_open(zap_span_t *span) */ static int zap_boost_wait_event(zap_span_t *span, int ms) { +#ifndef WIN32 struct timeval tv = { 0, ms * 1000 }; - int max, activity; sangomabc_connection_t *mcon, *pcon; + int max, activity; +#endif zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { @@ -1331,6 +1338,7 @@ static int zap_boost_wait_event(zap_span_t *span, int ms) } return 1; } +#ifndef WIN32 mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; @@ -1352,6 +1360,8 @@ static int zap_boost_wait_event(zap_span_t *span, int ms) } return 1; +#endif + return 0; } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index d50505c310..5d9eea5f36 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -109,6 +109,7 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) { +#ifndef WIN32 int rc; struct hostent *result, *local_result; char buf[512], local_buf[512]; @@ -174,12 +175,15 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int } } - return mcon->socket; +#else + return 0; +#endif // ifndef WIN32 } int sangomabc_connection_close(sangomabc_connection_t *mcon) { +#ifndef WIN32 if (mcon->sigmod) { zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); return 0; @@ -195,7 +199,7 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon) } memset(mcon, 0, sizeof(*mcon)); mcon->socket = -1; - +#endif return 0; } @@ -206,8 +210,12 @@ int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int /*value of mcon->socket will be ignored in sigmod mode */ return 0; } +#ifndef WIN32 create_conn_socket(mcon, local_ip, local_port, ip, port); return mcon->socket; +#else + return 0; +#endif } @@ -217,7 +225,7 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int int retry = 5; sangomabc_event_init(&oevent, cmd, chan, span); - oevent.release_cause = cause; + oevent.release_cause = (uint8_t)cause; if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->rxseq_reset = 1; @@ -227,7 +235,7 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int } if (id >= 0) { - oevent.call_setup_id = id; + oevent.call_setup_id = (uint16_t)id; } while (sangomabc_connection_write(mcon, (sangomabc_event_t*)&oevent) <= 0) { @@ -250,10 +258,10 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in int retry = 5; sangomabc_event_init(&oevent, cmd, chan, span); - oevent.release_cause = cause; + oevent.release_cause = (uint8_t)cause; if (id >= 0) { - oevent.call_setup_id = id; + oevent.call_setup_id = (uint16_t)id; } while (sangomabc_connection_writep(pcon, (sangomabc_event_t*)&oevent) <= 0) { @@ -271,7 +279,9 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line) { +#ifndef WIN32 unsigned int fromlen = sizeof(struct sockaddr_in); +#endif int bytes = 0; int msg_ok = 0; sangomabc_queue_element_t *e = NULL; @@ -283,11 +293,13 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int memcpy(&mcon->event, e->boostmsg, bytes); zap_safe_free(e); } - } else { + } +#ifndef WIN32 + else { bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); } - +#endif if (bytes <= 0) { return NULL; } @@ -365,16 +377,20 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line) { +#ifndef WIN32 unsigned int fromlen = sizeof(struct sockaddr_in); +#endif int bytes = 0; if (mcon->sigmod) { /* priority stuff is handled just the same when there is a sigmod */ return sangomabc_connection_read(mcon, iteration); - } else { + } +#ifndef WIN32 + else { bytes = recvfrom(mcon->socket, &mcon->event, sizeof(mcon->event), MSG_DONTWAIT, (struct sockaddr *) &mcon->local_addr, &fromlen); } - +#endif if (bytes <= 0) { return NULL; } @@ -405,14 +421,12 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line) { - int err; + int err = 0; 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(); - } + + zap_assert_return(event != NULL, -1, "No event!"); + zap_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); + zap_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); 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); @@ -448,16 +462,16 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t if (mcon->sigmod) { mcon->sigmod->write_msg(mcon->span, event, event_size); err = event_size; - } else { + } +#ifndef WIN32 + else { err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); } +#endif zap_mutex_unlock(mcon->mutex); - if (err != event_size) { - err = -1; - abort(); - } + zap_assert_return(err == event_size, -1, "Failed to send the boost message completely!"); if (boost_full_event(event->event_id)) { sangomabc_print_event_call(mcon, event, 0, 1, file, func, line); @@ -471,15 +485,13 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line) { - int err; + int err = 0; int event_size=sizeof(sangomabc_event_t); if (!mcon->sigmod) { - 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(); - } + zap_assert_return(event != NULL, -1, "No event!"); + zap_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); + zap_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); } if (!boost_full_event(event->event_id)) { @@ -492,15 +504,15 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ mcon->sigmod->write_msg(mcon->span, event, event_size); err = event_size; - } else { + } +#ifndef WIN32 + else { err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); } +#endif zap_mutex_unlock(mcon->mutex); - if (err != event_size) { - err = -1; - abort(); - } + zap_assert_return(err == event_size, -1, "Failed to send boost message completely!"); if (boost_full_event(event->event_id)) { sangomabc_print_event_call(mcon, event, 1, 1, file, func, line); @@ -519,15 +531,15 @@ void sangomabc_call_init(sangomabc_event_t *event, const char *calling, const ch if (calling) { strncpy((char*)event->calling_number_digits, calling, sizeof(event->calling_number_digits)-1); - event->calling_number_digits_count = strlen(calling); + event->calling_number_digits_count = (uint8_t)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->called_number_digits_count = (uint8_t)strlen(called); } - event->call_setup_id = setup_id; + event->call_setup_id = (uint16_t)setup_id; } @@ -535,8 +547,8 @@ void sangomabc_event_init(sangomabc_short_event_t *event, sangomabc_event_id_t e { memset(event, 0, sizeof(sangomabc_short_event_t)); event->event_id = event_id; - event->chan = chan; - event->span = span; + event->chan = (uint8_t)chan; + event->span = (uint8_t)span; } const char *sangomabc_event_id_name(uint32_t event_id) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h index 01eeb0803b..24a0a5c600 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -38,26 +38,26 @@ #include #include +#ifndef WIN32 #include -#include -#include -#include -#include -#include #include #include #ifdef HAVE_NETINET_SCTP_H #include #endif #include -#include #include -#include #include +#endif +#include +#include +#include +#include +#include +#include +#include "sigboost.h" -#define sangomabc_test_flag(p,flag) ({ \ - ((p)->flags & (flag)); \ - }) +#define sangomabc_test_flag(p,flag) ((p)->flags & (flag)) #define sangomabc_set_flag(p,flag) do { \ ((p)->flags |= (flag)); \ @@ -120,7 +120,7 @@ typedef struct sangomabc_queue_element { } sangomabc_queue_element_t; /* disable nagle's algorythm */ -static inline void sctp_no_nagle(int socket) +static __inline__ void sctp_no_nagle(int socket) { #ifdef HAVE_NETINET_SCTP_H int flag = 1; @@ -134,10 +134,10 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int 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__) +#define sangomabc_connection_write(_m,_e) __sangomabc_connection_write(_m, _e, __FILE__, __FUNCTION__, __LINE__) +#define sangomabc_connection_writep(_m,_e) __sangomabc_connection_writep(_m, _e, __FILE__, __FUNCTION__, __LINE__) +#define sangomabc_connection_read(_m,_e) __sangomabc_connection_read(_m, _e, __FILE__, __FUNCTION__, __LINE__) +#define sangomabc_connection_readp(_m,_e) __sangomabc_connection_readp(_m, _e, __FILE__, __FUNCTION__, __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); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h index 02a580777e..47849c2c72 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -142,7 +142,7 @@ typedef struct #pragma pack() -static inline int boost_full_event(int event_id) +static __inline__ int boost_full_event(int event_id) { switch (event_id) { case SIGBOOST_EVENT_CALL_START: @@ -150,10 +150,9 @@ static inline int boost_full_event(int event_id) case SIGBOOST_EVENT_CALL_PROGRESS: return 1; default: - return 0; + break; } - - return 0; + return 0; } #endif From 6c21ccb97396bc706c92530b58e0b08a2a3b463f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 30 Nov 2009 12:17:14 +0000 Subject: [PATCH 1631/1766] follow --sysconfdir when installing openzap.conf.xml git-svn-id: http://svn.openzap.org/svn/openzap/trunk@916 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/Makefile.in b/libs/openzap/mod_openzap/Makefile.in index 27eb4f3e8b..85275d1d8d 100644 --- a/libs/openzap/mod_openzap/Makefile.in +++ b/libs/openzap/mod_openzap/Makefile.in @@ -15,7 +15,7 @@ $(OZLA): $(OZ_DIR)/.update local_install: cd $(OZ_DIR) && $(MAKE) install - [ -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs + [ -f $(DESTDIR)@confdir@/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)@confdir@/autoload_configs local_clean: cd $(OZ_DIR) && $(MAKE) clean From 432a1950530e6f98fac352fcc09032921aea1d6d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 30 Nov 2009 16:52:40 +0000 Subject: [PATCH 1632/1766] fix ozmod_sangoma_boost compilation and linking git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@917 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 4 +-- libs/freetdm/src/include/zap_dso.h | 6 ++-- .../ozmod_sangoma_boost.2008.vcproj | 2 ++ .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 9 ++++-- .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 4 +-- libs/freetdm/src/zap_dso.c | 12 ++++---- libs/freetdm/src/zap_queue.c | 30 +++++++++---------- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index ddcb9b0133..b114e844fb 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -617,9 +617,7 @@ struct zap_io_interface { zio_api_t api; }; -struct zap_queue; -#define zap_queue_t struct zap_queue - +typedef struct zap_queue zap_queue_t; typedef zap_status_t (*zap_queue_create_func_t)(zap_queue_t **queue, zap_size_t capacity); typedef zap_status_t (*zap_queue_enqueue_func_t)(zap_queue_t *queue, void *obj); typedef void *(*zap_queue_dequeue_func_t)(zap_queue_t *queue); diff --git a/libs/freetdm/src/include/zap_dso.h b/libs/freetdm/src/include/zap_dso.h index 9cfe87e962..c5d1457b95 100644 --- a/libs/freetdm/src/include/zap_dso.h +++ b/libs/freetdm/src/include/zap_dso.h @@ -28,9 +28,9 @@ extern "C" { 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); +OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib); +OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err); +OZ_DECLARE(void *) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err); #ifdef __cplusplus } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj index 3f7ef8de43..ee9bae316b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj @@ -63,7 +63,9 @@ /> mcon; pcon = &sangoma_boost_data->pcon; - if (sangoma_boost_data->sigmod || FD_ISSET(pcon->socket, &sangoma_boost_data->rfds)) { + if (sangoma_boost_data->sigmod +#ifndef WIN32 + || FD_ISSET(pcon->socket, &sangoma_boost_data->rfds) +#endif + ) { event = sangomabc_connection_readp(pcon, sangoma_boost_data->iteration); } - +#ifndef WIN32 /* if there is no event and this is not a sigmod-driven span it's time to try the other connection for events */ if (!event && !sangoma_boost_data->sigmod && FD_ISSET(mcon->socket, &sangoma_boost_data->rfds)) { event = sangomabc_connection_readp(mcon, sangoma_boost_data->iteration); } +#endif return event; } diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj index 1c8685c6d4..eb4cecb32d 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -41,7 +41,7 @@ -void zap_dso_destroy(zap_dso_lib_t *lib) { +OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib) { if (lib && *lib) { FreeLibrary(*lib); *lib = NULL; } } -zap_dso_lib_t zap_dso_open(const char *path, char **err) { +OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) { HINSTANCE lib; lib = LoadLibraryEx(path, NULL, 0); @@ -53,7 +53,7 @@ zap_dso_lib_t zap_dso_open(const char *path, char **err) { return lib; } -void* zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { +OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { FARPROC func = GetProcAddress(lib, sym); if (!func) { DWORD error = GetLastError(); @@ -78,14 +78,14 @@ void* zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { #include -void zap_dso_destroy(zap_dso_lib_t *lib) { +OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib) { if (lib && *lib) { dlclose(*lib); *lib = NULL; } } -zap_dso_lib_t zap_dso_open(const char *path, char **err) { +OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) { void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (lib == NULL) { *err = zap_strdup(dlerror()); @@ -93,7 +93,7 @@ zap_dso_lib_t zap_dso_open(const char *path, char **err) { return lib; } -void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { +OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { void *func = dlsym(lib, sym); if (!func) { *err = zap_strdup(dlerror()); diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 6a0a05d683..969e170783 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -34,8 +34,13 @@ #include "openzap.h" -#undef zap_queue_t -typedef struct zap_queue { +static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity); +static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj); +static void *zap_std_queue_dequeue(zap_queue_t *queue); +static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms); +static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue); + +struct zap_queue { zap_mutex_t *mutex; zap_condition_t *condition; zap_size_t capacity; @@ -43,21 +48,15 @@ typedef struct zap_queue { unsigned rindex; unsigned windex; void **elements; -} zap_queue_t; - -static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity); -static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj); -static void *zap_std_queue_dequeue(zap_queue_t *queue); -static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms); -static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue); +}; OZ_DECLARE_DATA zap_queue_handler_t g_zap_queue_handler = { - .create = zap_std_queue_create, - .enqueue = zap_std_queue_enqueue, - .dequeue = zap_std_queue_dequeue, - .wait = zap_std_queue_wait, - .destroy = zap_std_queue_destroy + /*.create = */ zap_std_queue_create, + /*.enqueue = */ zap_std_queue_enqueue, + /*.dequeue = */ zap_std_queue_dequeue, + /*.wait = */ zap_std_queue_wait, + /*.destroy = */ zap_std_queue_destroy }; OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler) @@ -76,11 +75,12 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity) { + zap_queue_t *queue = NULL; zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); *outqueue = NULL; - zap_queue_t *queue = zap_calloc(1, sizeof(*queue)); + queue = zap_calloc(1, sizeof(*queue)); if (!queue) { return ZAP_FAIL; } From 98954639f0ee7590ae14af2e99156d6f846ee3b2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 30 Nov 2009 17:00:22 +0000 Subject: [PATCH 1633/1766] add zap_queue.c to Windows build git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@918 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/msvc/openzap.2008.vcproj | 4 ++++ libs/freetdm/openzap.2008.sln | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/libs/freetdm/msvc/openzap.2008.vcproj b/libs/freetdm/msvc/openzap.2008.vcproj index 8e61f61eef..a3751be544 100644 --- a/libs/freetdm/msvc/openzap.2008.vcproj +++ b/libs/freetdm/msvc/openzap.2008.vcproj @@ -286,6 +286,10 @@ RelativePath="..\src\zap_io.c" > + + diff --git a/libs/freetdm/openzap.2008.sln b/libs/freetdm/openzap.2008.sln index 7bf028e616..af52100966 100644 --- a/libs/freetdm/openzap.2008.sln +++ b/libs/freetdm/openzap.2008.sln @@ -40,6 +40,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_pika", "src\ozmod\ozm EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_wanpipe", "src\ozmod\ozmod_wanpipe\ozmod_wanpipe.2008.vcproj", "{1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_sangoma_boost", "src\ozmod\ozmod_sangoma_boost\ozmod_sangoma_boost.2008.vcproj", "{D021EF2A-460D-4827-A0F7-41FDECF46F1B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -78,6 +80,10 @@ Global {E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}.Release|Win32.ActiveCfg = Release|Win32 {1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}.Debug|Win32.ActiveCfg = Debug|Win32 {1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}.Release|Win32.ActiveCfg = Release|Win32 + {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Debug|Win32.Build.0 = Debug|Win32 + {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Release|Win32.ActiveCfg = Release|Win32 + {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 0ee0ff5123bfbb7fda8db68215884a7947787fca Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 30 Nov 2009 17:04:30 +0000 Subject: [PATCH 1634/1766] added cygwin install openzap script git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@919 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/cyginstall.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 libs/freetdm/cyginstall.sh diff --git a/libs/freetdm/cyginstall.sh b/libs/freetdm/cyginstall.sh new file mode 100644 index 0000000000..1bd6510488 --- /dev/null +++ b/libs/freetdm/cyginstall.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# this script must be run from openzap root dir and it is assuming +# FreeSWITCH is trunk is located at ../../ +fsdir=../.. + +cp Debug/*.dll $fsdir/Debug/ +cp Debug/mod/*.dll $fsdir/Debug/mod/ + From 665aa967cd958d05040e246a490af409d28a5311 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 1 Dec 2009 21:49:51 +0000 Subject: [PATCH 1635/1766] fix Windows projects and cyginstall git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@920 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/cyginstall.sh | 3 +- .../msvc/testboost/testboost.2008.vcproj | 191 ++++++++++++++++++ libs/freetdm/openzap.2008.sln | 6 + .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 20 +- .../sangoma_boost_interface.h | 14 ++ .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 2 +- libs/freetdm/src/testboost.c | 29 ++- libs/freetdm/src/zap_io.c | 9 +- 8 files changed, 254 insertions(+), 20 deletions(-) create mode 100644 libs/freetdm/msvc/testboost/testboost.2008.vcproj diff --git a/libs/freetdm/cyginstall.sh b/libs/freetdm/cyginstall.sh index 1bd6510488..eac467d142 100644 --- a/libs/freetdm/cyginstall.sh +++ b/libs/freetdm/cyginstall.sh @@ -2,7 +2,8 @@ # this script must be run from openzap root dir and it is assuming # FreeSWITCH is trunk is located at ../../ fsdir=../.. - +set -x cp Debug/*.dll $fsdir/Debug/ cp Debug/mod/*.dll $fsdir/Debug/mod/ +set +x diff --git a/libs/freetdm/msvc/testboost/testboost.2008.vcproj b/libs/freetdm/msvc/testboost/testboost.2008.vcproj new file mode 100644 index 0000000000..b41bf86051 --- /dev/null +++ b/libs/freetdm/msvc/testboost/testboost.2008.vcproj @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/openzap.2008.sln b/libs/freetdm/openzap.2008.sln index af52100966..a40ff30137 100644 --- a/libs/freetdm/openzap.2008.sln +++ b/libs/freetdm/openzap.2008.sln @@ -42,6 +42,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_wanpipe", "src\ozmod\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_sangoma_boost", "src\ozmod\ozmod_sangoma_boost\ozmod_sangoma_boost.2008.vcproj", "{D021EF2A-460D-4827-A0F7-41FDECF46F1B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testboost", "msvc\testboost\testboost.2008.vcproj", "{2B1BAF36-0241-43E7-B865-A8338AD48E2E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -84,6 +86,10 @@ Global {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Debug|Win32.Build.0 = Debug|Win32 {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Release|Win32.ActiveCfg = Release|Win32 {D021EF2A-460D-4827-A0F7-41FDECF46F1B}.Release|Win32.Build.0 = Release|Win32 + {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Debug|Win32.ActiveCfg = Debug|Win32 + {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Debug|Win32.Build.0 = Debug|Win32 + {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Release|Win32.ActiveCfg = Release|Win32 + {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index f40669d928..99df5c27cb 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1211,7 +1211,7 @@ static __inline__ void check_state(zap_span_t *span) * \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) +static __inline__ zap_status_t check_events(zap_span_t *span, int ms_timeout) { zap_status_t status; zap_sigmsg_t sigmsg; @@ -1252,14 +1252,18 @@ static __inline__ void check_events(zap_span_t *span, int ms_timeout) break; case ZAP_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Boost Check Event Failure Failure! %d\n", zap_running()); + if (!zap_running()) { + break; + } + zap_log(ZAP_LOG_ERROR, "Boost Check Event Failure Failure: %s\n", span->last_error); + return ZAP_FAIL; } break; default: break; } - return; + return ZAP_SUCCESS; } /** @@ -1271,9 +1275,15 @@ 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; + unsigned errs = 0; while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && zap_running()) { - check_events(span,100); + if (check_events(span,100) != ZAP_SUCCESS) { + if (errs++ > 50) { + zap_log(ZAP_LOG_ERROR, "Too many event errors, quitting sangoma events thread\n"); + return NULL; + } + } } return NULL; @@ -1844,7 +1854,7 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) /** * \brief Openzap sangoma boost signaling module definition */ -zap_module_t zap_module = { +EX_DECLARE_DATA zap_module_t zap_module = { /*.name =*/ "sangoma_boost", /*.io_load =*/ NULL, /*.io_unload =*/ NULL, diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index c337995dca..8757adcab3 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -37,6 +37,11 @@ #include "openzap.h" + +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief Callback used to notify signaling status changes on a channel \param zchan The openzap channel where the signaling status just changed @@ -188,11 +193,20 @@ typedef struct boost_sigmod_interface_s { void *pvt; } boost_sigmod_interface_t; +#ifdef __cplusplus +} // extern C +#endif + #define BOOST_INTERFACE_NAME boost_sigmod_interface #define BOOST_INTERFACE_NAME_STR "boost_sigmod_interface" /* use this in your sig boost module to declare your interface */ +#ifndef WIN32 #define BOOST_INTERFACE boost_sigmod_interface_t BOOST_INTERFACE_NAME +#else +#define BOOST_INTERFACE __declspec(dllexport) boost_sigmod_interface_t BOOST_INTERFACE_NAME #endif +#endif + /* For Emacs: * Local Variables: diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj index eb4cecb32d..5802643fec 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -41,7 +41,7 @@ configure_span_signaling) { + if (!mod) { + zap_log(ZAP_LOG_ERROR, "Failed to load module type: %s\n", type); + return ZAP_FAIL; + } + + if (mod->configure_span_signaling) { status = mod->configure_span_signaling(span, sig_cb, parameters); } else { - zap_log(ZAP_LOG_ERROR, "can't find module '%s' or the module did not implement the signaling configuration method\n", type); + zap_log(ZAP_LOG_ERROR, "Module %s did not implement the signaling configuration method\n", type); } return status; From 0b21fe80dcacb1bf4e47fad3d55153f4e53b6d94 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 2 Dec 2009 16:36:42 +0000 Subject: [PATCH 1636/1766] fix expected return code for WaitForSingleObject in zap queue implementation git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@921 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 3e894737c0..6128120934 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -286,8 +286,11 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) return ZAP_TIMEOUT; case WAIT_FAILED: return ZAP_FAIL; + case WAIT_OBJECT_0: + return ZAP_SUCCESS; default: zap_log(ZAP_LOG_ERROR, "Error waiting for openzap condition event (WaitForSingleObject returned %d)\n", res); + return ZAP_FAIL; } #else int res = 0; @@ -305,8 +308,8 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) } return ZAP_FAIL; } -#endif return ZAP_SUCCESS; +#endif } OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) From d94d016cef8c72810c31895985ad2f1b2f976aa1 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 2 Dec 2009 19:10:15 +0000 Subject: [PATCH 1637/1766] debug msgs git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@922 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 8 +++++++- .../sangoma_boost_client.c | 20 +++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 99df5c27cb..8706a1b401 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -369,6 +369,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; if (sangoma_boost_data->sigmod) { + /* boost sigmods only know about physical spans, give them that and let them hunt there */ event.span = (uint8_t)span->channels[1]->physical_span_id; } @@ -777,6 +778,11 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa goto error; } + zap_log(ZAP_LOG_DEBUG, "Got call start from s%dc%d mapped to openzap logical s%dc%d, physical s%dc%d\n", + event->span, event->chan, + zchan->span_id, zchan->chan_id, + zchan->physical_span_id, zchan->physical_chan_id); + zchan->sflags = 0; zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); @@ -812,7 +818,7 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa error: - zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span,event->chan); sangomabc_exec_command(mcon, event->span, diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 5d9eea5f36..111fab6288 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -76,12 +76,12 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [s%dc%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->span, + event->chan, event->call_setup_id, event->fseqno, strlen(event->calling_name)?event->calling_name:"N/A", @@ -94,13 +94,13 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i \n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", dir ? "TX":"RX", priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, - event->span+1, - event->chan+1, + event->span, + event->chan, event->release_cause, event->call_setup_id, event->fseqno); @@ -240,10 +240,10 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int while (sangomabc_connection_write(mcon, (sangomabc_event_t*)&oevent) <= 0) { if (--retry <= 0) { - zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket: %s\n", strerror(errno)); + zap_log(ZAP_LOG_CRIT, "Failed to tx on boost 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_log(ZAP_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); zap_sleep(1); } } @@ -266,10 +266,10 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in while (sangomabc_connection_writep(pcon, (sangomabc_event_t*)&oevent) <= 0) { if (--retry <= 0) { - zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket: %s\n", strerror(errno)); + zap_log(ZAP_LOG_CRIT, "Failed to tx on boost 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_log(ZAP_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); zap_sleep(1); } } From 991dd2551345e7c37147454276bada61ccb8bd3c Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Wed, 2 Dec 2009 21:00:29 +0000 Subject: [PATCH 1638/1766] add windows x64 build support git-svn-id: http://svn.openzap.org/svn/openzap/trunk@923 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../mod_openzap/mod_openzap.2008.vcproj | 169 ++++++++++++++++++ libs/openzap/msvc/openzap.2008.vcproj | 154 ++++++++++++++++ .../msvc/testanalog/testanalog.2008.vcproj | 159 ++++++++++++++++ .../msvc/testisdn/testisdn.2008.vcproj | 159 ++++++++++++++++ libs/openzap/openzap.2008.sln | 34 ++++ libs/openzap/src/isdn/Q931api.c | 2 +- .../ozmod_analog/ozmod_analog.2008.vcproj | 156 ++++++++++++++++ .../ozmod_analog_em.2008.vcproj | 156 ++++++++++++++++ .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 154 ++++++++++++++++ .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 159 ++++++++++++++++ 11 files changed, 1302 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj index 720849dee9..bf5be95c21 100644 --- a/libs/openzap/mod_openzap/mod_openzap.2008.vcproj +++ b/libs/openzap/mod_openzap/mod_openzap.2008.vcproj @@ -12,6 +12,9 @@ + @@ -180,6 +183,172 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/openzap.2008.vcproj b/libs/openzap/msvc/openzap.2008.vcproj index 8e61f61eef..4a7531e3c4 100644 --- a/libs/openzap/msvc/openzap.2008.vcproj +++ b/libs/openzap/msvc/openzap.2008.vcproj @@ -12,6 +12,9 @@ + @@ -163,6 +166,157 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/testanalog/testanalog.2008.vcproj b/libs/openzap/msvc/testanalog/testanalog.2008.vcproj index 7a80eeea94..120eb5fd75 100644 --- a/libs/openzap/msvc/testanalog/testanalog.2008.vcproj +++ b/libs/openzap/msvc/testanalog/testanalog.2008.vcproj @@ -12,6 +12,9 @@ + @@ -170,6 +173,162 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/msvc/testisdn/testisdn.2008.vcproj b/libs/openzap/msvc/testisdn/testisdn.2008.vcproj index 56d8e52983..e350a45edf 100644 --- a/libs/openzap/msvc/testisdn/testisdn.2008.vcproj +++ b/libs/openzap/msvc/testisdn/testisdn.2008.vcproj @@ -12,6 +12,9 @@ + @@ -170,6 +173,162 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/openzap.2008.sln b/libs/openzap/openzap.2008.sln index 7bf028e616..7867bc5939 100644 --- a/libs/openzap/openzap.2008.sln +++ b/libs/openzap/openzap.2008.sln @@ -43,41 +43,75 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.ActiveCfg = Debug|Win32 {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|Win32.Build.0 = Debug|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|x64.ActiveCfg = Debug|x64 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Debug|x64.Build.0 = Debug|x64 {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.ActiveCfg = Release|Win32 {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|Win32.Build.0 = Release|Win32 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|x64.ActiveCfg = Release|x64 + {93B8812C-3EC4-4F78-8970-FFBFC99E167D}.Release|x64.Build.0 = Release|x64 {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.ActiveCfg = Debug|Win32 {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|Win32.Build.0 = Debug|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|x64.ActiveCfg = Debug|x64 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Debug|x64.Build.0 = Debug|x64 {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.ActiveCfg = Release|Win32 {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.Build.0 = Release|Win32 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|x64.ActiveCfg = Release|x64 + {BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|x64.Build.0 = Release|x64 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.ActiveCfg = Debug|Win32 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|x64.ActiveCfg = Debug|x64 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|x64.Build.0 = Debug|x64 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32 {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|x64.ActiveCfg = Release|x64 + {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|x64.Build.0 = Release|x64 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.ActiveCfg = Debug|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.Build.0 = Debug|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|x64.ActiveCfg = Debug|x64 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|x64.Build.0 = Debug|x64 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.ActiveCfg = Release|Win32 {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|Win32.Build.0 = Release|Win32 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|x64.ActiveCfg = Release|x64 + {FE3540C5-3303-46E0-A69E-D92F775687F1}.Release|x64.Build.0 = Release|x64 {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.ActiveCfg = Debug|Win32 {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|Win32.Build.0 = Debug|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|x64.ActiveCfg = Debug|x64 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Debug|x64.Build.0 = Debug|x64 {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.ActiveCfg = Release|Win32 {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|Win32.Build.0 = Release|Win32 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|x64.ActiveCfg = Release|x64 + {37C94798-6E33-4B4F-8EE0-C72A7DC91157}.Release|x64.Build.0 = Release|x64 {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|Win32.ActiveCfg = Debug|Win32 {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|Win32.Build.0 = Debug|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|x64.ActiveCfg = Debug|x64 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Debug|x64.Build.0 = Debug|x64 {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.ActiveCfg = Release|Win32 {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.Build.0 = Release|Win32 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|x64.ActiveCfg = Release|x64 + {B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|x64.Build.0 = Release|x64 {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.ActiveCfg = Debug|Win32 {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.Build.0 = Debug|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|x64.ActiveCfg = Debug|x64 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|x64.Build.0 = Debug|x64 {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.ActiveCfg = Release|Win32 {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.Build.0 = Release|Win32 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|x64.ActiveCfg = Release|x64 + {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|x64.Build.0 = Release|x64 {E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}.Debug|Win32.ActiveCfg = Debug|Win32 + {E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}.Debug|x64.ActiveCfg = Debug|Win32 {E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}.Release|Win32.ActiveCfg = Release|Win32 + {E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}.Release|x64.ActiveCfg = Release|Win32 {1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}.Debug|Win32.ActiveCfg = Debug|Win32 + {1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}.Debug|x64.ActiveCfg = Debug|x64 {1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}.Release|Win32.ActiveCfg = Release|Win32 + {1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}.Release|x64.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/openzap/src/isdn/Q931api.c b/libs/openzap/src/isdn/Q931api.c index e59247a26a..ed0d13836b 100644 --- a/libs/openzap/src/isdn/Q931api.c +++ b/libs/openzap/src/isdn/Q931api.c @@ -207,7 +207,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) L3INT iISize = pIE->Size; L3UCHAR *pBuf = &pMes->buf[0]; - L3INT Off = pMes->Size - (pBuf - pm); + L3INT Off = (L3INT)(pMes->Size - (pBuf - pm)); IE = (ie)(Off | 0x8000); memcpy(&pm[pMes->Size], pi, iISize); diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj index a8211ca10d..da21d1f48f 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -12,6 +12,9 @@ + @@ -167,6 +170,159 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 70f057ab37..35a0d89da0 100644 --- 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 @@ -12,6 +12,9 @@ + @@ -167,6 +170,159 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj index de6f1718b1..75815df561 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -12,6 +12,9 @@ + @@ -165,6 +168,157 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index d054bd08d1..08f5662f9d 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -992,7 +992,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } /* TODO: make this more safe with strncat() */ - pos = strlen(zchan->caller_data.dnis.digits); + pos = (int)strlen(zchan->caller_data.dnis.digits); strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); /* update timer */ diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj index 1c8685c6d4..c66eb3becb 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -12,6 +12,9 @@ + @@ -93,6 +96,84 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ff473f4adc8f5d64d95e8dc50f07e75ad40ceacd Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 2 Dec 2009 21:45:11 +0000 Subject: [PATCH 1639/1766] use an auto-reset event for Windows conditions git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@924 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 +++ libs/freetdm/src/zap_threadmutex.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 5e69cf4356..74368d5354 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -791,6 +791,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) err = sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); + zap_log(ZAP_LOG_ERROR, "sangoma_tdm_txsig_offhook failed\n"); return ZAP_FAIL; } zap_clear_pflag_locked(zchan, WP_RINGING); @@ -799,6 +800,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); if (err) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); + zap_log(ZAP_LOG_ERROR, "sangoma_tdm_txsig_start failed\n"); return ZAP_FAIL; } zap_set_pflag_locked(zchan, WP_RINGING); @@ -817,6 +819,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } else if (SANG_STATUS_SUCCESS == sangstatus) { r = 1; /* hopefully we never need how many changed -_- */ } else { + zap_log(ZAP_LOG_ERROR, "sangoma_waitfor_many failed: %d, %s\n", sangstatus, strerror(errno)); r = -1; } #else diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 6128120934..4c633555e4 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -251,7 +251,7 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap } #ifdef WIN32 - condition->condition = CreateEvent(NULL, TRUE, FALSE, NULL); + condition->condition = CreateEvent(NULL, FALSE, FALSE, NULL); if (!condition->condition) { goto failed; } From fb72b04010cecf200874e3aa8c0f8c562de5309d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 3 Dec 2009 18:13:34 +0000 Subject: [PATCH 1640/1766] allow HARDHDLC option for dahdi git-svn-id: http://svn.openzap.org/svn/openzap/trunk@925 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 8 ++++++-- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index b8788d2a58..3b383d89a4 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -371,8 +371,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } if (zchan->type == ZAP_CHAN_TYPE_DQ921) { - if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) { - 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); + 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; } diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h index 14516f6fe9..f82cf0ff10 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h @@ -241,7 +241,8 @@ 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_CAS = (1 << 15), +ZT_SIG_HARDHDLC = (1 << 19), } zt_sigtype_t; typedef enum { From 86832cb68c6607993bedd8f5fb53a58d4c1075b3 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 3 Dec 2009 19:06:27 +0000 Subject: [PATCH 1641/1766] Fix for openzap sending CALL_STOPPED_ACK before clearing local channel git-svn-id: http://svn.openzap.org/svn/openzap/trunk@926 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 12 ++-- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 66 +++++++++---------- .../sangoma_boost_client.c | 18 ++--- 3 files changed, 45 insertions(+), 51 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c295113351..a71a349c54 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -470,9 +470,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_EM: case ZAP_CHAN_TYPE_CAS: { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); - } break; case ZAP_CHAN_TYPE_FXS: @@ -488,10 +486,12 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; case ZAP_CHAN_TYPE_B: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { - tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); - if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { - tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { + tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); + if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { + tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + } } zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } 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 index ac48ced23f..85fcd88f9c 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -46,7 +46,7 @@ static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; */ typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), - SFLAG_SENT_FINAL_RESPONSE = (1 << 1) + SFLAG_SENT_FINAL_MSG = (1 << 1) } sflag_t; typedef uint16_t sangoma_boost_request_id_t; @@ -472,6 +472,9 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e zap_log(ZAP_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + + zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG); + sangomabc_exec_command(mcon, event->span, event->chan, @@ -517,7 +520,7 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ //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)); } - + 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, @@ -636,10 +639,9 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco } if (zchan) { - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + 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, @@ -674,22 +676,12 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san } zap_mutex_unlock(zchan->mutex); - if (r) { return; } } /* else we have to do it ourselves.... */ - if (zchan) { - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - } - - sangomabc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); + 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); } @@ -983,7 +975,18 @@ static __inline__ void state_advance(zap_channel_t *zchan) } zchan->sflags = 0; - zap_channel_done(zchan); + + if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); + + sangomabc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } + zap_channel_done(zchan); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -1019,9 +1022,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) { sig.event_id = ZAP_SIGEVENT_RESTART; status = sangoma_boost_data->signal_cb(&sig); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } break; case ZAP_CHANNEL_STATE_UP: @@ -1035,7 +1037,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, + zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_START_ACK, 0); @@ -1043,7 +1045,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) sangomabc_exec_command(mcon, zchan->physical_span_id-1, - zchan->physical_chan_id-1, + zchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_ANSWERED, 0); @@ -1061,11 +1063,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_RESPONSE)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + if (zchan->last_state == ZAP_CHANNEL_STATE_TERMINATING || + zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } else { - - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + 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)) { sangomabc_exec_command(mcon, zchan->physical_span_id-1, @@ -1089,7 +1091,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.event_id = ZAP_SIGEVENT_STOP; status = sangoma_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -1100,17 +1102,9 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_TERMINATING: { + sig.event_id = ZAP_SIGEVENT_STOP; status = sangoma_boost_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - } break; default: @@ -1428,7 +1422,7 @@ static zap_state_map_t boost_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END} }, { ZSD_OUTBOUND, @@ -1472,7 +1466,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END}, }, { ZSD_INBOUND, 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 index 90c73f2626..dcdee97730 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -38,7 +38,6 @@ #include "openzap.h" #include - #ifndef HAVE_GETHOSTBYNAME_R extern int gethostbyname_r (const char *__name, struct hostent *__result_buf, @@ -76,16 +75,17 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; + zap_log(file, func, line, ZAP_LOG_LEVEL_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"), + 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); From c722e89b6c6d5c258a02ecf7bf6f306ff0f933f1 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 4 Dec 2009 04:53:04 +0000 Subject: [PATCH 1642/1766] added missing tonemap parameter to configure ISDN stack git-svn-id: http://svn.openzap.org/svn/openzap/trunk@927 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a71a349c54..88c75c2d9d 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2191,6 +2191,7 @@ static switch_status_t load_config(void) "dialect", dialect, "digit_timeout", &to, "opts", opts, + "tonemap", tonegroup, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { From c376f9d0925a7cfdf1a07d7ebd783cb90ea818f7 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 4 Dec 2009 18:25:48 +0000 Subject: [PATCH 1643/1766] added zap_strndup git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@928 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 1 + libs/freetdm/src/zap_io.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index b114e844fb..64791f4eec 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -652,6 +652,7 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl /*! \brief Duplicate string */ OZ_DECLARE(char *) zap_strdup(const char *str); +OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen); OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index b967a4c418..ba95e94bbf 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -3252,6 +3252,24 @@ OZ_DECLARE(char *) zap_strdup(const char *str) return (char *)memcpy(new, str, len); } +OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen) +{ + char *new = NULL; + zap_size_t len = strlen(str) + 1; + if (len > (inlen+1)) { + len = inlen+1; + } + new = (char *)zap_malloc(len); + + if (!new) { + return NULL; + } + + memcpy(new, str, len-1); + new[len-1] = 0; + return new; +} + /* For Emacs: * Local Variables: From 32d3035346c443c4e0490a0bf058ff3149309c20 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 7 Dec 2009 15:18:33 +0000 Subject: [PATCH 1644/1766] a little hack to libpcap detection (OPENZAP-86) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@929 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/build/libpcap.m4 | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openzap/build/libpcap.m4 b/libs/openzap/build/libpcap.m4 index 8c758a1a5e..c20d345ca6 100644 --- a/libs/openzap/build/libpcap.m4 +++ b/libs/openzap/build/libpcap.m4 @@ -72,6 +72,7 @@ test "X$with_lib_subdir" = "Xno" && with_lib_subdir= ac_cv_cmu_lib_subdir=lib if test $ac_cv_sizeof_long -eq 4 ; then test -d /usr/lib32 && ac_cv_cmu_lib_subdir=lib32 + test -r /usr/lib/libpcap.so && ac_cv_cmu_lib_subdir=lib fi if test $ac_cv_sizeof_long -eq 8 ; then test -d /usr/lib64 && ac_cv_cmu_lib_subdir=lib64 From b6a10aa3f9c7d9efdb48671bcc293289d325d15a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 8 Dec 2009 16:20:49 +0000 Subject: [PATCH 1645/1766] add sg tones git-svn-id: http://svn.openzap.org/svn/openzap/trunk@930 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/tones.conf | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index db6658d78e..d687c14d0e 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -22,4 +22,27 @@ detect-fail2 => 1370.6 detect-fail3 => 1776.7 +[sg] +generate-dial => v=-7;%(1000,0,425) +detect-dial => 425 + +generate-ring => v=-7;%(2000,4000,425) +detect-ring => 425 + +generate-busy => v=-7;%(750,750,425) +detect-busy => 425 + +generate-attn => v=0;%(100,100,1400,2060,2450,2600) +detect-attn => 1400,2060,2450,2600 + +generate-callwaiting-sas => v=0;%(300,0,440) +detect-callwaiting-sas => 440 + +generate-callwaiting-cas => v=0;%(80,0,2750,2130) +detect-callwaiting-cas => 2750,2130 + +detect-fail1 => 913.8 +detect-fail2 => 1370.6 +detect-fail3 => 1776.7 + From 07d412879f3ecb917e8153a541903d79becd1b0a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 8 Dec 2009 16:23:49 +0000 Subject: [PATCH 1646/1766] add russian tones git-svn-id: http://svn.openzap.org/svn/openzap/trunk@931 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/conf/tones.conf | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/openzap/conf/tones.conf b/libs/openzap/conf/tones.conf index d687c14d0e..36db1d4d91 100644 --- a/libs/openzap/conf/tones.conf +++ b/libs/openzap/conf/tones.conf @@ -45,4 +45,19 @@ detect-fail1 => 913.8 detect-fail2 => 1370.6 detect-fail3 => 1776.7 - +[ru] +generate-dial => v=-7;%(1000,425) +detect-dial => 0 +generate-ring => v=-7;%(800,5000,425,0) +detect-ring => 425,0 +generate-busy => v=-7;%(350,350,425,0) +detect-busy => 425,0 +generate-attn => v=0;%(100,100,1400,2060,2450,2600) +detect-attn => 1400,2060,2450,2600 +generate-callwaiting-sas => v=0;%(300,0,440) +detect-callwaiting-sas => 440,480 +generate-callwaiting-cas => v=0;%(80,0,2750,2130) +detect-callwaiting-cas => 2750,2130 +detect-fail1 => 913.8 +detect-fail2 => 1370.6 +detect-fail3 => 1776.7 From 15c93b5c0d02b99258a832b864feab0cd5375cc8 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 9 Dec 2009 18:51:55 +0000 Subject: [PATCH 1647/1766] Changes for segfaults on shutdown and cpu usage git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@932 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 14 ++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 13 ++- libs/freetdm/src/zap_io.c | 93 +++++++++++-------- 3 files changed, 74 insertions(+), 46 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 8706a1b401..a1b289a06b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1413,10 +1413,10 @@ static sangomabc_event_t *zap_boost_read_event(zap_span_t *span) */ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) { - zap_span_t *span = (zap_span_t *) obj; + zap_span_t *span = (zap_span_t *) obj; sangomabc_connection_t *mcon, *pcon; uint32_t ms = 10; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; @@ -1466,7 +1466,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) break; } - if ((activity = zap_boost_wait_event(span, ms)) < 0) { + if ((activity = zap_boost_wait_event(span, -1)) < 0) { zap_log(ZAP_LOG_ERROR, "zap_boost_wait_event failed\n"); goto error; } @@ -1568,13 +1568,21 @@ static zap_status_t zap_sangoma_boost_start(zap_span_t *span) static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) { + int cnt = 10; zap_status_t status = ZAP_SUCCESS; zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { + /* FIXME: we should make sure the span thread is stopped (use pthread_kill or openzap thread kill function) */ /* I think stopping the span before destroying the queue makes sense otherwise may be boost events would still arrive when the queue is already destroyed! */ status = sangoma_boost_data->sigmod->stop_span(span); + + zap_queue_enqueue(sangoma_boost_data->boost_queue, NULL); + while(zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && cnt-- > 0) { + zap_log(ZAP_LOG_DEBUG, "Waiting for boost thread\n"); + zap_sleep(500); + } zap_queue_destroy(&sangoma_boost_data->boost_queue); return status; } diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 74368d5354..a6f436ffc5 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -245,7 +245,11 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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); + /* we need SANGOMA_DEVICE_WAIT_OBJ_SIG and not SANGOMA_DEVICE_WAIT_OBJ alone because we need to call + * sangoma_wait_obj_sig to wake up any I/O waiters when closing the channel (typically on zap shutdown) + * this adds an extra pair of file descriptors to the waitable object + * */ + sangstatus = sangoma_wait_obj_create(&sangoma_wait_obj, sockfd, SANGOMA_DEVICE_WAIT_OBJ_SIG); if (sangstatus != SANG_STATUS_SUCCESS) { zap_log(ZAP_LOG_ERROR, "failure create waitable object for s%dc%d\n", spanno, x); continue; @@ -493,6 +497,11 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) */ static ZIO_CLOSE_FUNCTION(wanpipe_close) { +#ifdef LIBSANGOMA_VERSION + sangoma_wait_obj_t *waitobj = zchan->mod_data; + /* kick any I/O waiters */ + sangoma_wait_obj_signal(waitobj); +#endif return ZAP_SUCCESS; } @@ -1058,7 +1067,7 @@ 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_t *sangoma_wait_obj; sangoma_wait_obj = zchan->mod_data; zchan->mod_data = NULL; sangoma_wait_obj_delete(&sangoma_wait_obj); diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index ba95e94bbf..ced0eb82bb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -276,26 +276,6 @@ OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky) return hash; } - -static zap_status_t zap_span_destroy(zap_span_t *span) -{ - zap_status_t status = ZAP_FAIL; - - if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - if (span->stop) { - span->stop(span); - } - if (span->zio && span->zio->span_destroy) { - zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); - status = span->zio->span_destroy(span); - zap_safe_free(span->type); - zap_safe_free(span->dtmf_hangup); - } - } - - return status; -} - static zap_status_t zap_channel_destroy(zap_channel_t *zchan) { @@ -342,6 +322,48 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) return ZAP_SUCCESS; } +static zap_status_t zap_span_destroy(zap_span_t *span) +{ + zap_status_t status = ZAP_SUCCESS; + unsigned j; + + zap_mutex_lock(span->mutex); + + /* stop the signaling */ + if (span->stop) { + status = span->stop(span); + } + + /* destroy the channels */ + zap_clear_flag(span, ZAP_SPAN_CONFIGURED); + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { + zap_channel_t *cur_chan = span->channels[j]; + if (cur_chan) { + if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { + zap_channel_destroy(cur_chan); + } + zap_safe_free(cur_chan); + cur_chan = NULL; + } + } + + /* destroy the I/O for the span */ + if (span->zio && span->zio->span_destroy) { + zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); + if (span->zio->span_destroy(span) != ZAP_SUCCESS) { + status = ZAP_FAIL; + } + zap_safe_free(span->type); + zap_safe_free(span->dtmf_hangup); + } + + /* destroy final basic resources of the span data structure */ + zap_mutex_unlock(span->mutex); + zap_mutex_destroy(&span->mutex); + zap_safe_free(span->signal_data); + + return status; +} OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) { @@ -481,7 +503,10 @@ OZ_DECLARE(zap_status_t) zap_span_close_all(void) for (span = globals.spans; span; span = span->next) { if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { for(j = 1; j <= span->chan_count && span->channels[j]; j++) { - zap_channel_destroy(span->channels[j]); + zap_channel_t *toclose = span->channels[j]; + if (zap_test_flag(toclose, ZAP_CHANNEL_INUSE)) { + zap_channel_close(&toclose); + } i++; } } @@ -1329,11 +1354,17 @@ OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan) return ZAP_FAIL; } + if (!zap_test_flag(check, ZAP_CHANNEL_INUSE)) { + zap_log(ZAP_LOG_WARNING, "Called zap_channel_close but never zap_channel_open in chan %d:%d??\n", check->span_id, check->chan_id); + return ZAP_FAIL; + } + if (zap_test_flag(check, ZAP_CHANNEL_CONFIGURED)) { zap_mutex_lock(check->mutex); if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { status = check->zio->close(check); if (status == ZAP_SUCCESS) { + zap_clear_flag(check, ZAP_CHANNEL_INUSE); zap_channel_reset(check); *zchan = NULL; } @@ -2889,7 +2920,6 @@ OZ_DECLARE(uint32_t) zap_running(void) OZ_DECLARE(zap_status_t) zap_global_destroy(void) { - unsigned int j; zap_span_t *sp; time_end(); @@ -2905,25 +2935,6 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) if (cur_span) { if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { - zap_mutex_lock(cur_span->mutex); - zap_clear_flag(cur_span, ZAP_SPAN_CONFIGURED); - for(j = 1; j <= cur_span->chan_count && cur_span->channels[j]; j++) { - zap_channel_t *cur_chan = cur_span->channels[j]; - if (cur_chan) { - if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_channel_destroy(cur_chan); - } - zap_safe_free(cur_chan); - cur_chan = NULL; - } - } - zap_mutex_unlock(cur_span->mutex); - - if (cur_span->mutex) { - zap_mutex_destroy(&cur_span->mutex); - } - - zap_safe_free(cur_span->signal_data); zap_span_destroy(cur_span); } From 39974a353643e63a70ad5cef4fb5e7eb21c9cfbd Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 9 Dec 2009 20:35:53 +0000 Subject: [PATCH 1648/1766] fix mutex locking in Windows and take back boost 10ms polling, is needed for now git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@933 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 6 ++--- .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 4 ++-- libs/freetdm/src/zap_threadmutex.c | 23 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index a1b289a06b..b4af623c0a 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -377,7 +377,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) 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)); + zap_log(ZAP_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno)); status = ZAP_FAIL; *zchan = NULL; goto done; @@ -1416,7 +1416,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) zap_span_t *span = (zap_span_t *) obj; sangomabc_connection_t *mcon, *pcon; uint32_t ms = 10; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; @@ -1466,7 +1466,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) break; } - if ((activity = zap_boost_wait_event(span, -1)) < 0) { + if ((activity = zap_boost_wait_event(span, ms)) < 0) { zap_log(ZAP_LOG_ERROR, "zap_boost_wait_event failed\n"); goto error; } diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj index 5802643fec..5585e5bfdd 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -41,7 +41,7 @@ @@ -52,12 +48,17 @@ struct zap_mutex { pthread_mutex_t mutex; }; +#endif + struct zap_condition { +#ifdef WIN32 + HANDLE condition; +#else pthread_cond_t condition; - pthread_mutex_t *mutex; +#endif + zap_mutex_t *mutex; }; -#endif struct zap_thread { #ifdef WIN32 @@ -250,13 +251,13 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap return ZAP_FAIL; } + condition->mutex = mutex; #ifdef WIN32 condition->condition = CreateEvent(NULL, FALSE, FALSE, NULL); if (!condition->condition) { goto failed; } #else - condition->mutex = &mutex->mutex; if (pthread_cond_init(&condition->condition, NULL)) { goto failed; } @@ -279,7 +280,9 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) #endif zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 + zap_mutex_unlock(condition->mutex); res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); + zap_mutex_lock(condition->mutex); switch (res) { case WAIT_ABANDONED: case WAIT_TIMEOUT: @@ -298,9 +301,9 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) struct timespec waitms; waitms.tv_sec = time(NULL) + ( ms / 1000 ); waitms.tv_nsec = 1000 * 1000 * ( ms % 1000 ); - res = pthread_cond_timedwait(&condition->condition, condition->mutex, &waitms); + res = pthread_cond_timedwait(&condition->condition, condition->mutex->mutex, &waitms); } else { - res = pthread_cond_wait(&condition->condition, condition->mutex); + res = pthread_cond_wait(&condition->condition, condition->mutex->mutex); } if (res != 0) { if (res == ETIMEDOUT) { @@ -340,8 +343,8 @@ OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) if (pthread_cond_destroy(&condition->condition)) { return ZAP_FAIL; } - zap_safe_free(condition); #endif + zap_safe_free(condition); *incondition = NULL; return ZAP_SUCCESS; } From 27ad281537f884ae55cbcc4bc492b716d599b212 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 9 Dec 2009 21:45:09 +0000 Subject: [PATCH 1649/1766] Fix for pthread_cond_timedwait git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@934 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 2 +- libs/freetdm/src/zap_threadmutex.c | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index b4af623c0a..0d2b30f8bc 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1586,7 +1586,7 @@ static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) zap_queue_destroy(&sangoma_boost_data->boost_queue); return status; } - return ZAP_SUCCESS; + return status; } static zap_state_map_t boost_state_map = { diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index f5cc4a6117..44591eed84 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -39,7 +39,6 @@ struct zap_mutex { }; #else - #include #define ZAP_THREAD_CALLING_CONVENTION @@ -273,6 +272,8 @@ failed: return ZAP_FAIL; } +#define ONE_BILLION 1000000000 + OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) { #ifdef WIN32 @@ -298,17 +299,32 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) #else int res = 0; if (ms > 0) { - struct timespec waitms; - waitms.tv_sec = time(NULL) + ( ms / 1000 ); - waitms.tv_nsec = 1000 * 1000 * ( ms % 1000 ); - res = pthread_cond_timedwait(&condition->condition, condition->mutex->mutex, &waitms); + struct timeval t; + + struct timespec waitms; + + condition->cnt++; + + gettimeofday(&t, NULL); + + waitms.tv_sec = t.tv_sec + ( ms / 1000 ); + + waitms.tv_nsec = 1000*(t.tv_usec + (1000 * ( ms % 1000 ))); + + if (waitms.tv_nsec > ONE_BILLION) { + waitms.tv_sec++; + waitms.tv_nsec-= ONE_BILLION; + } + + res = pthread_cond_timedwait(&condition->condition, &condition->mutex->mutex, &waitms); } else { - res = pthread_cond_wait(&condition->condition, condition->mutex->mutex); + res = pthread_cond_wait(&condition->condition, &condition->mutex->mutex); } if (res != 0) { if (res == ETIMEDOUT) { return ZAP_TIMEOUT; } + zap_log(ZAP_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res); return ZAP_FAIL; } return ZAP_SUCCESS; From 83587669e3a4d3e16373238e898d627d2837174d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 9 Dec 2009 22:57:06 +0000 Subject: [PATCH 1650/1766] added BOOST.limitations file to ozmod_sangoma_boost git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@935 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/BOOST.limitations | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations new file mode 100644 index 0000000000..6da43bae34 --- /dev/null +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations @@ -0,0 +1,30 @@ +== Boost sigmod current limitations == +- we don't support having openzap spans with physical channels + belonging to other physical spans. this is due to netborder sangoma abstraction, therefore + any openzap span using sigboost must have only channels belonging to the corresponding + physical span. + +- all spans must be configured and then started, cannot configure, start, configure start etc + this is due to netborder telesoft abstraction. that requires configuring everything and + then starting everything at once. + +- just per-span hunting for now. We must remove the hunting from sigmods and delegate to ozmod_sangoma_boost + +- sangoma_prid and sangoma_brid on Windows had to be compiled hacking make/Makefile.platform to comment all VC runtime checks, + otherwise when running in debug mode exceptions are thrown due to loss of data ie short to char conversions. + +== TODO == +- proper upper layer management of HW alarms (this must be done in mod_openzap.c) + +- proper boost hunting done in openzap based on channels status + +- move all logging calls to macro-based logging to log the file name and line in sangoma prid + +- add zap_span_get_signaling_status that will check the overall span signaling status + +- fix segfault on unload of mod_openzap, probably due to threads in smgprid not being stopped + +- remove FORCE_SEGFAULT from sangoma_sprid and check if there is anything like that in sangoma_brid + we should be using zap_assert or zap_assert_return which will abort depending on the openzap + crash policy + From 3459cd6bd67324fa784d350f7e80e8e5f6a6fe1c Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 10 Dec 2009 20:59:48 +0000 Subject: [PATCH 1651/1766] Fix for compilation error git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@936 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 44591eed84..0d15cadaa1 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -303,8 +303,6 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) struct timespec waitms; - condition->cnt++; - gettimeofday(&t, NULL); waitms.tv_sec = t.tv_sec + ( ms / 1000 ); From b94dfc5c6af2b562ec4ad318e77d0e7ea3184fa8 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 10 Dec 2009 23:37:44 +0000 Subject: [PATCH 1652/1766] Fix for early media on incoming calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@937 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) 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 index 85fcd88f9c..75ad485bff 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -46,7 +46,8 @@ static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; */ typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), - SFLAG_SENT_FINAL_MSG = (1 << 1) + SFLAG_SENT_FINAL_MSG = (1 << 1), + SFLAG_SENT_ACK = (1 << 2) } sflag_t; typedef uint16_t sangoma_boost_request_id_t; @@ -551,7 +552,6 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san } 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); @@ -974,11 +974,9 @@ static __inline__ void state_advance(zap_channel_t *zchan) release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1); } - zchan->sflags = 0; - if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -986,6 +984,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); } + zchan->sflags = 0; zap_channel_done(zchan); } break; @@ -998,12 +997,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); + 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); + } } } break; @@ -1015,7 +1017,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } - } break; case ZAP_CHANNEL_STATE_RESTART: @@ -1069,6 +1070,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) } 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)) { + sangomabc_exec_command(mcon, zchan->physical_span_id-1, zchan->physical_chan_id-1, @@ -1478,7 +1480,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, }, { ZSD_INBOUND, From 143ba2785fee97d707dc5faa7116f6d073ec9c5d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 14 Dec 2009 17:02:40 +0000 Subject: [PATCH 1653/1766] Fixed race condition on hangup Fixed crash on incoming CALL PROGRESS if cannot find zchan git-svn-id: http://svn.openzap.org/svn/openzap/trunk@938 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) 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 index 75ad485bff..40d310e40d 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -473,9 +473,9 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e zap_log(ZAP_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - - zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG); - + if (zchan) { + zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG); + } sangomabc_exec_command(mcon, event->span, event->chan, @@ -665,7 +665,22 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san int r = 0; zap_mutex_lock(zchan->mutex); - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); + + if (zchan->state == ZAP_CHANNEL_STATE_HANGUP) { + /* 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); + 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; @@ -682,7 +697,6 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san } /* 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); } @@ -1104,7 +1118,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_TERMINATING: { - sig.event_id = ZAP_SIGEVENT_STOP; status = sangoma_boost_data->signal_cb(&sig); } From 6f1cafa983320fa507a2804fe57b4059835d1615 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 14 Dec 2009 17:47:41 +0000 Subject: [PATCH 1654/1766] Merged r910:r938 from trunk git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@939 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/build/libpcap.m4 | 1 + libs/freetdm/conf/tones.conf | 38 ++++ libs/freetdm/mod_openzap/Makefile.in | 2 +- .../mod_openzap/mod_openzap.2008.vcproj | 169 ++++++++++++++++++ libs/freetdm/mod_openzap/mod_openzap.c | 13 +- libs/freetdm/msvc/openzap.2008.vcproj | 154 ++++++++++++++++ .../msvc/testanalog/testanalog.2008.vcproj | 159 ++++++++++++++++ .../msvc/testisdn/testisdn.2008.vcproj | 159 ++++++++++++++++ libs/freetdm/src/isdn/Q931api.c | 2 +- .../ozmod_analog/ozmod_analog.2008.vcproj | 156 ++++++++++++++++ .../ozmod_analog_em.2008.vcproj | 156 ++++++++++++++++ .../ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj | 154 ++++++++++++++++ .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 2 +- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 105 ++++++----- .../sangoma_boost_client.c | 20 +-- .../ozmod_wanpipe/ozmod_wanpipe.2008.vcproj | 159 ++++++++++++++++ libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c | 8 +- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h | 3 +- 18 files changed, 1393 insertions(+), 67 deletions(-) diff --git a/libs/freetdm/build/libpcap.m4 b/libs/freetdm/build/libpcap.m4 index 8c758a1a5e..c20d345ca6 100644 --- a/libs/freetdm/build/libpcap.m4 +++ b/libs/freetdm/build/libpcap.m4 @@ -72,6 +72,7 @@ test "X$with_lib_subdir" = "Xno" && with_lib_subdir= ac_cv_cmu_lib_subdir=lib if test $ac_cv_sizeof_long -eq 4 ; then test -d /usr/lib32 && ac_cv_cmu_lib_subdir=lib32 + test -r /usr/lib/libpcap.so && ac_cv_cmu_lib_subdir=lib fi if test $ac_cv_sizeof_long -eq 8 ; then test -d /usr/lib64 && ac_cv_cmu_lib_subdir=lib64 diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index db6658d78e..36db1d4d91 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -22,4 +22,42 @@ detect-fail2 => 1370.6 detect-fail3 => 1776.7 +[sg] +generate-dial => v=-7;%(1000,0,425) +detect-dial => 425 +generate-ring => v=-7;%(2000,4000,425) +detect-ring => 425 + +generate-busy => v=-7;%(750,750,425) +detect-busy => 425 + +generate-attn => v=0;%(100,100,1400,2060,2450,2600) +detect-attn => 1400,2060,2450,2600 + +generate-callwaiting-sas => v=0;%(300,0,440) +detect-callwaiting-sas => 440 + +generate-callwaiting-cas => v=0;%(80,0,2750,2130) +detect-callwaiting-cas => 2750,2130 + +detect-fail1 => 913.8 +detect-fail2 => 1370.6 +detect-fail3 => 1776.7 + +[ru] +generate-dial => v=-7;%(1000,425) +detect-dial => 0 +generate-ring => v=-7;%(800,5000,425,0) +detect-ring => 425,0 +generate-busy => v=-7;%(350,350,425,0) +detect-busy => 425,0 +generate-attn => v=0;%(100,100,1400,2060,2450,2600) +detect-attn => 1400,2060,2450,2600 +generate-callwaiting-sas => v=0;%(300,0,440) +detect-callwaiting-sas => 440,480 +generate-callwaiting-cas => v=0;%(80,0,2750,2130) +detect-callwaiting-cas => 2750,2130 +detect-fail1 => 913.8 +detect-fail2 => 1370.6 +detect-fail3 => 1776.7 diff --git a/libs/freetdm/mod_openzap/Makefile.in b/libs/freetdm/mod_openzap/Makefile.in index 27eb4f3e8b..85275d1d8d 100644 --- a/libs/freetdm/mod_openzap/Makefile.in +++ b/libs/freetdm/mod_openzap/Makefile.in @@ -15,7 +15,7 @@ $(OZLA): $(OZ_DIR)/.update local_install: cd $(OZ_DIR) && $(MAKE) install - [ -f $(DESTDIR)$(PREFIX)/conf/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)$(PREFIX)/conf/autoload_configs + [ -f $(DESTDIR)@confdir@/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)@confdir@/autoload_configs local_clean: cd $(OZ_DIR) && $(MAKE) clean diff --git a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj index 720849dee9..bf5be95c21 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj +++ b/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj @@ -12,6 +12,9 @@ + @@ -180,6 +183,172 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 53546e23ec..0e4efdb8d5 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -470,9 +470,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) case ZAP_CHAN_TYPE_EM: case ZAP_CHAN_TYPE_CAS: { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); - } break; case ZAP_CHAN_TYPE_FXS: @@ -488,10 +486,12 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; case ZAP_CHAN_TYPE_B: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { - tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); - if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { - tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { + if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { + tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); + if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { + tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + } } zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); } @@ -2196,6 +2196,7 @@ static switch_status_t load_config(void) "dialect", dialect, "digit_timeout", &to, "opts", opts, + "tonemap", tonegroup, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != ZAP_SUCCESS) { diff --git a/libs/freetdm/msvc/openzap.2008.vcproj b/libs/freetdm/msvc/openzap.2008.vcproj index a3751be544..952cdd3822 100644 --- a/libs/freetdm/msvc/openzap.2008.vcproj +++ b/libs/freetdm/msvc/openzap.2008.vcproj @@ -12,6 +12,9 @@ + @@ -163,6 +166,157 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj b/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj index 7a80eeea94..120eb5fd75 100644 --- a/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj +++ b/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj @@ -12,6 +12,9 @@ + @@ -170,6 +173,162 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj b/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj index 56d8e52983..e350a45edf 100644 --- a/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj +++ b/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj @@ -12,6 +12,9 @@ + @@ -170,6 +173,162 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/isdn/Q931api.c b/libs/freetdm/src/isdn/Q931api.c index e59247a26a..ed0d13836b 100644 --- a/libs/freetdm/src/isdn/Q931api.c +++ b/libs/freetdm/src/isdn/Q931api.c @@ -207,7 +207,7 @@ ie Q931AppendIE( L3UCHAR *pm, L3UCHAR *pi) L3INT iISize = pIE->Size; L3UCHAR *pBuf = &pMes->buf[0]; - L3INT Off = pMes->Size - (pBuf - pm); + L3INT Off = (L3INT)(pMes->Size - (pBuf - pm)); IE = (ie)(Off | 0x8000); memcpy(&pm[pMes->Size], pi, iISize); diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj index a8211ca10d..da21d1f48f 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj @@ -12,6 +12,9 @@ + @@ -167,6 +170,159 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj index 70f057ab37..35a0d89da0 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj @@ -12,6 +12,9 @@ + @@ -167,6 +170,159 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj index de6f1718b1..75815df561 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj @@ -12,6 +12,9 @@ + @@ -165,6 +168,157 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index cd92d2b900..f703c86f93 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -992,7 +992,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } /* TODO: make this more safe with strncat() */ - pos = strlen(zchan->caller_data.dnis.digits); + pos = (int)strlen(zchan->caller_data.dnis.digits); strcat(&zchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); /* update timer */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 0d2b30f8bc..66cc64009a 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -68,7 +68,8 @@ static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; */ typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), - SFLAG_SENT_FINAL_RESPONSE = (1 << 1) + SFLAG_SENT_FINAL_MSG = (1 << 1), + SFLAG_SENT_ACK = (1 << 2) } sflag_t; typedef uint16_t sangoma_boost_request_id_t; @@ -506,6 +507,9 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e zap_log(ZAP_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + if (zchan) { + zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG); + } sangomabc_exec_command(mcon, event->span, event->chan, @@ -552,7 +556,13 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ } } - zap_log(ZAP_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event_span, event_chan); + //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)); + } + + 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, @@ -581,7 +591,6 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san } 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); @@ -669,10 +678,9 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco } if (zchan) { - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + 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, @@ -696,7 +704,22 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san int r = 0; zap_mutex_lock(zchan->mutex); - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); + + if (zchan->state == ZAP_CHANNEL_STATE_HANGUP) { + /* 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); + 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; @@ -707,23 +730,12 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san } zap_mutex_unlock(zchan->mutex); - if (r) { return; } } /* else we have to do it ourselves.... */ - if (zchan) { - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - } - - sangomabc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - + 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); } @@ -1020,8 +1032,18 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); + + sangomabc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } zchan->sflags = 0; - zap_channel_done(zchan); + zap_channel_done(zchan); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: @@ -1033,12 +1055,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { - sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); + 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); + } } } break; @@ -1050,16 +1075,14 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } - } break; case ZAP_CHANNEL_STATE_RESTART: { sig.event_id = ZAP_SIGEVENT_RESTART; status = sangoma_boost_data->signal_cb(&sig); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } break; case ZAP_CHANNEL_STATE_UP: @@ -1099,12 +1122,13 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_RESPONSE)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + if (zchan->last_state == ZAP_CHANNEL_STATE_TERMINATING || + zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } else { - - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + 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)) { + sangomabc_exec_command(mcon, BOOST_SPAN(zchan), BOOST_CHAN(zchan), @@ -1127,7 +1151,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) sig.event_id = ZAP_SIGEVENT_STOP; status = sangoma_boost_data->signal_cb(&sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); + zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); sangomabc_exec_command(mcon, BOOST_SPAN(zchan), BOOST_CHAN(zchan), @@ -1140,15 +1164,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) { sig.event_id = ZAP_SIGEVENT_STOP; status = sangoma_boost_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_RESPONSE); - sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); - } break; default: @@ -1619,7 +1634,7 @@ static zap_state_map_t boost_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END} }, { ZSD_OUTBOUND, @@ -1663,7 +1678,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END}, }, { ZSD_INBOUND, @@ -1675,7 +1690,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END}, + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END}, }, { ZSD_INBOUND, diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 111fab6288..1ba67c9834 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -38,7 +38,6 @@ #include "openzap.h" #include "sangoma_boost_client.h" - #ifndef HAVE_GETHOSTBYNAME_R extern int gethostbyname_r (const char *__name, struct hostent *__result_buf, @@ -76,16 +75,17 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT: %s:(%X) [s%dc%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", + + 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, - event->chan, - 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"), + 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); diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj index 5585e5bfdd..fea5e357fe 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj @@ -12,6 +12,9 @@ + @@ -93,6 +96,84 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c index bbd64352f4..4815fbec51 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c @@ -371,8 +371,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } if (zchan->type == ZAP_CHAN_TYPE_DQ921) { - if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) { - 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); + 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; } diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h index 14516f6fe9..f82cf0ff10 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h @@ -241,7 +241,8 @@ 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_CAS = (1 << 15), +ZT_SIG_HARDHDLC = (1 << 19), } zt_sigtype_t; typedef enum { From c569627f6813c22286ae63984fc0cc3d15601ab1 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 14 Dec 2009 21:49:49 +0000 Subject: [PATCH 1655/1766] Fix for zchan not getting unlocked git-svn-id: http://svn.openzap.org/svn/openzap/trunk@940 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 40d310e40d..892094126e 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -677,6 +677,7 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); + zap_mutex_unlock(zchan->mutex); return; } else { zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); @@ -909,7 +910,7 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s case SIGBOOST_EVENT_CALL_START_ACK: handle_call_start_ack(mcon, event); break; - case SIGBOOST_EVENT_CALL_PROGRESS: + case SIGBOOST_EVENT_CALL_PROGRESS: handle_call_progress(mcon, event); break; case SIGBOOST_EVENT_CALL_START_NACK: From 698667a0fbc41c1bf7d94156ff6a526fb0158ed3 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 16 Dec 2009 21:50:46 +0000 Subject: [PATCH 1656/1766] ZT_SIG_HARDHDLC needs ZT_SIG_CLEAR bit set too, fixes OPENZAP-96 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@941 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h index f82cf0ff10..687269a983 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.h @@ -242,7 +242,7 @@ 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_HARDHDLC = ((1 << 19) | ZT_SIG_CLEAR), } zt_sigtype_t; typedef enum { From b43317595030ed5f96a60c356fa15eb07d675272 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 18 Dec 2009 20:53:17 +0000 Subject: [PATCH 1657/1766] Fix for segfault on zap_queue wrap-around git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@942 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 15 +++++++-------- .../ozmod_sangoma_boost/sangoma_boost_client.c | 18 +++++++++--------- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 2 +- libs/freetdm/src/zap_queue.c | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 66cc64009a..5412738bb8 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -33,7 +33,7 @@ * Contributors: * * Moises Silva - * David Yatzin + * David Yat Sin * Nenad Corbic * */ @@ -711,8 +711,8 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san * itself through local initiated hangup */ sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); @@ -1036,8 +1036,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); @@ -1058,8 +1058,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_ACK, 0); @@ -1716,7 +1716,6 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) zap_log(ZAP_LOG_ERROR, "Unexpected boost message %d\n", shortmsg->event_id); return ZAP_FAIL; } - /* duplicate the event and enqueue it */ element = zap_calloc(1, sizeof(*element)); if (!element) { diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 1ba67c9834..0af4664ee7 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -76,12 +76,13 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", - dir ? "TX":"RX", + zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", + dir ? "TX":"RX", + priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, - event->span+1, - event->chan+1, + event->span, + event->chan, event->call_setup_id, event->fseqno, strlen(event->calling_name)?event->calling_name:"N/A", @@ -94,9 +95,9 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", + zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", dir ? "TX":"RX", - priority ? "P":"N", + priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, event->span, @@ -322,8 +323,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int msg_ok=0; } - if (msg_ok){ - + 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 && @@ -333,7 +333,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int return NULL; } } - + if (boost_full_event(mcon->event.event_id)) { sangomabc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); } else { diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h index 47849c2c72..9e97e9014d 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -147,7 +147,7 @@ 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: + case SIGBOOST_EVENT_CALL_PROGRESS: return 1; default: break; diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 969e170783..a714af340c 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -163,7 +163,7 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) obj = queue->elements[queue->rindex]; queue->elements[queue->rindex++] = NULL; queue->size--; - if (queue->rindex == queue->size) { + if (queue->rindex == queue->capacity) { queue->rindex = 0; } From 29436b8cd6fb8664d26bf5123fa928d85fae17aa Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 4 Jan 2010 15:26:23 +0000 Subject: [PATCH 1658/1766] Support for huntgroups git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@944 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 29 +- libs/freetdm/src/include/openzap.h | 23 +- libs/freetdm/src/include/zap_types.h | 1 + .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 185 +++++++---- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 11 +- libs/freetdm/src/zap_io.c | 308 +++++++++++++++++- 6 files changed, 470 insertions(+), 87 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 0e4efdb8d5..ee8234c99f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1033,7 +1033,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi const char *dest = NULL; char *data = NULL; - int span_id = -1, chan_id = 0; + int span_id = -1, group_id = -1,chan_id = 0; zap_channel_t *zchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; @@ -1085,7 +1085,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (span_id == 0 && chan_id != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Span 0 is used to pick the first available span, selecting a channel is not supported (and doesn't make sense)\n"); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } if (span_id == -1 && !zstr(span_name)) { @@ -1097,11 +1097,18 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (span_id == -1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + //Look for a group + zap_group_t *group; + zap_status_t zstatus = zap_group_find_by_name(span_name, &group); + if (zstatus == ZAP_SUCCESS && group) { + group_id = group->group_id; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + } } - if (chan_id < 0) { + if (group_id < 0 && chan_id < 0) { direction = ZAP_BOTTOM_UP; chan_id = 0; } @@ -1143,11 +1150,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); zap_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); - - if (chan_id) { + + if (group_id >= 0) { + status = zap_channel_open_by_group(group_id, direction, &caller_data, &zchan); + } else if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); } else { - status = zap_channel_open_any(span_id, direction, &caller_data, &zchan); + status = zap_channel_open_by_span(span_id, direction, &caller_data, &zchan); } if (status != ZAP_SUCCESS) { @@ -1753,7 +1762,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) } } break; - case ZAP_SIGEVENT_PROGRESS: + case ZAP_SIGEVENT_PROGRESS: { if ((session = zap_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); @@ -1766,8 +1775,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } - break; - default: { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n", diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 64791f4eec..15ddf350c1 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -195,6 +195,9 @@ extern "C" { #define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN #define ZAP_MAX_SPANS_INTERFACE 128 +#define ZAP_MAX_CHANNELS_GROUP 1024 +#define ZAP_MAX_GROUPS_INTERFACE ZAP_MAX_SPANS_INTERFACE + #define GOTO_STATUS(label,st) status = st; goto label ; #define zap_copy_string(x,y,z) strncpy(x, y, z - 1) @@ -578,6 +581,16 @@ struct zap_span { struct zap_span *next; }; +struct zap_group { + char *name; + uint32_t group_id; + uint32_t chan_count; + zap_channel_t *channels[ZAP_MAX_CHANNELS_GROUP]; + uint32_t last_used_index; + zap_mutex_t *mutex; + struct zap_group *next; +}; + OZ_DECLARE_DATA extern zap_logger_t zap_log; typedef enum { @@ -706,11 +719,19 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s OZ_DECLARE(zap_status_t) zap_span_close_all(void); OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); +OZ_DECLARE(zap_status_t) zap_channel_add_to_group(const char* name, zap_channel_t* zchan); +OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* span, const char* val); +OZ_DECLARE(zap_status_t) zap_channel_remove_from_group(zap_group_t* group, zap_channel_t* zchan); +OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group); +OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group); +OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name); OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count); -OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_group_channel_use_count(zap_group_t *group, uint32_t *count); +OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); +OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan); OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan); OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 8cf2b6b30c..98571e9b84 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -458,6 +458,7 @@ typedef struct zap_channel zap_channel_t; typedef struct zap_event zap_event_t; typedef struct zap_sigmsg zap_sigmsg_t; typedef struct zap_span zap_span_t; +typedef struct zap_group zap_group_t; typedef struct zap_caller_data zap_caller_data_t; typedef struct zap_io_interface zap_io_interface_t; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 5412738bb8..3dfe91006c 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -55,8 +55,11 @@ zap_mutex_t *g_boost_modules_mutex = NULL; zap_hash_t *g_boost_modules_hash = NULL; #define MAX_TRUNK_GROUPS 64 +//DAVIDY need to merge congestion_timeouts with zap_sangoma_boost_trunkgroups static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; +static zap_sangoma_boost_trunkgroup_t *g_trunkgroups[MAX_TRUNK_GROUPS]; + #define BOOST_QUEUE_SIZE 500 /* get openzap span and chan depending on the span mode */ @@ -303,76 +306,80 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) 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, 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; + if (sangoma_boost_data->sigmod) { + *zchan = span->channels[chan_id]; + + event.span = (uint8_t) (*zchan)->physical_span_id; + event.chan = (uint8_t) (*zchan)->physical_chan_id; + + zap_set_flag((*zchan), ZAP_CHANNEL_OUTBOUND); + zap_set_flag_locked((*zchan), ZAP_CHANNEL_INUSE); + + OUTBOUND_REQUESTS[r].zchan = *zchan; + } else { + 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; + } + + 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.isup_in_rdnis, caller_data->rdnis.digits); - if (strlen(caller_data->rdnis.digits)) { - event.isup_in_rdnis_size = (uint16_t)strlen(caller_data->rdnis.digits)+1; - } + if (strlen(caller_data->rdnis.digits)) { + event.isup_in_rdnis_size = (uint16_t)strlen(caller_data->rdnis.digits)+1; + } event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; - if (sangoma_boost_data->sigmod) { - /* boost sigmods only know about physical spans, give them that and let them hunt there */ - event.span = (uint8_t)span->channels[1]->physical_span_id; - } OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; @@ -380,7 +387,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) if (sangomabc_connection_write(&sangoma_boost_data->mcon, &event) <= 0) { zap_log(ZAP_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno)); status = ZAP_FAIL; - *zchan = NULL; + if (!sangoma_boost_data->sigmod) { + *zchan = NULL; + } goto done; } @@ -388,8 +397,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_sleep(1); if (--boost_request_timeout <= 0) { status = ZAP_FAIL; - *zchan = NULL; + if (!sangoma_boost_data->sigmod) { + *zchan = NULL; + } zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); + zap_log(ZAP_LOG_CRIT, "DYDBG s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r); goto done; } } @@ -406,7 +418,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_sleep(1); if (--boost_request_timeout <= 0) { status = ZAP_FAIL; - *zchan = NULL; + if (!sangoma_boost_data->sigmod) { + *zchan = NULL; + } zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n"); goto done; } @@ -420,7 +434,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); } else { status = ZAP_FAIL; - *zchan = NULL; + if (!sangoma_boost_data->sigmod) { + *zchan = NULL; + } } done: @@ -433,12 +449,21 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } 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); + if (sangoma_boost_data->sigmod) { + sangomabc_exec_command(&sangoma_boost_data->mcon, + (*zchan)->physical_span_id, + (*zchan)->physical_chan_id, + r, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } else { + sangomabc_exec_command(&sangoma_boost_data->mcon, + 0, + 0, + r, + SIGBOOST_EVENT_CALL_START_NACK, + 0); + } } return status; @@ -526,9 +551,11 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e */ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { + zap_channel_t *zchan; uint32_t event_span = event->span+1; uint32_t event_chan = event->chan+1; + if (nack_map[event->call_setup_id]) { return; } @@ -541,12 +568,19 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ OUTBOUND_REQUESTS[event->call_setup_id].event = *event; SETUP_GRID[event->span][event->chan] = event->call_setup_id; - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0))) { + if (mcon->sigmod) { + zchan = OUTBOUND_REQUESTS[event->call_setup_id].zchan; + zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); + zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); + } else { + zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0); + } + + + if (zchan) { if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); } else { - 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, event_chan, event->call_setup_id); zchan->sflags = 0; @@ -620,6 +654,7 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (event->release_cause == SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY) { uint32_t count = 0; @@ -648,8 +683,10 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco event->release_cause = 17; } - if (event->call_setup_id) { - + zap_log(ZAP_LOG_CRIT, "DYDBG setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); + OUTBOUND_REQUESTS[event->call_setup_id].event = *event; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + if (!sangoma_boost_data->sigmod) { sangomabc_exec_command(mcon, 0, 0, @@ -657,8 +694,6 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; return; } else { if ((zchan = find_zchan(span, event, 1))) { @@ -677,6 +712,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco } } +#if 0 if (zchan) { zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); } @@ -688,6 +724,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); +#endif } /** @@ -1528,6 +1565,7 @@ end: */ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { + int i; g_boost_modules_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys); if (!g_boost_modules_hash) { return ZAP_FAIL; @@ -1535,6 +1573,10 @@ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); zap_mutex_create(&g_boost_modules_mutex); + + for(i=0;i< MAX_TRUNK_GROUPS;i++) { + g_trunkgroups[i]=NULL; + } return ZAP_SUCCESS; } @@ -1806,7 +1848,6 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) } } - if (!sigmod) { if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { zap_set_string(span->last_error, "missing Sangoma boost IP parameters"); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h index e08d98b598..91f54f930b 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -36,6 +36,8 @@ #include "sangoma_boost_client.h" #include "openzap.h" +#define MAX_CHANS_PER_TRUNKGROUP 1024 + typedef enum { ZAP_SANGOMA_BOOST_RUNNING = (1 << 0), ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1) @@ -50,9 +52,16 @@ typedef struct zap_sangoma_boost_data { zio_signal_cb_t signal_cb; uint32_t flags; boost_sigmod_interface_t *sigmod; - zap_queue_t *boost_queue; + zap_queue_t *boost_queue; } zap_sangoma_boost_data_t; +typedef struct zap_sangoma_boost_trunkgroup { + zap_mutex_t *mutex; + zap_size_t size; /* Number of b-channels in group */ + unsigned int last_used_index; /* index of last b-channel used */ + zap_channel_t* zchans[MAX_CHANS_PER_TRUNKGROUP]; + //DAVIDY need to merge congestion timeouts to this struct +} zap_sangoma_boost_trunkgroup_t; #endif /* For Emacs: diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index ced0eb82bb..124e371be3 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -33,6 +33,7 @@ * Contributors: * * Moises Silva + * David Yat Sin * */ @@ -81,11 +82,15 @@ static struct { zap_hash_t *interface_hash; zap_hash_t *module_hash; zap_hash_t *span_hash; + zap_hash_t *group_hash; zap_mutex_t *mutex; zap_mutex_t *span_mutex; + zap_mutex_t *group_mutex; uint32_t span_index; + uint32_t group_index; uint32_t running; zap_span_t *spans; + zap_group_t *groups; } globals; @@ -1008,6 +1013,113 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel return ok ? ZAP_SUCCESS : ZAP_FAIL; } + +OZ_DECLARE(zap_status_t) zap_group_channel_use_count(zap_group_t *group, uint32_t *count) +{ + uint32_t j; + + *count = 0; + + if (!group) { + return ZAP_FAIL; + } + + for(j = 0; j < group->chan_count && group->channels[j]; j++) { + if (group->channels[j]) { + if (zap_test_flag(group->channels[j], ZAP_CHANNEL_INUSE)) { + (*count)++; + } + } + } + + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) +{ + zap_status_t status = ZAP_FAIL; + zap_channel_t *check; + uint32_t i, count; + zap_group_t *group = NULL; + + if (group_id) { + zap_group_find(group_id, &group); + } + + if (!group ) { + zap_log(ZAP_LOG_CRIT, "GROUP NOT DEFINED!\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + zap_group_channel_use_count(group, &count); + + if (count >= group->chan_count) { + zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); + *zchan = NULL; + return ZAP_FAIL; + } + + + if (direction == ZAP_TOP_DOWN) { + i = 0; + } else { + i = group->chan_count-1; + } + + zap_mutex_lock(group->mutex); + for (;;) { + if (direction == ZAP_TOP_DOWN) { + if (i >= group->chan_count) { + break; + } + } else { + if (i < 0) { + break; + } + } + + if (!(check = group->channels[i])) { + status = ZAP_FAIL; + break; + } + + if (zap_test_flag(check, ZAP_CHANNEL_READY) && + !zap_test_flag(check, ZAP_CHANNEL_INUSE) && + !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && + check->state == ZAP_CHANNEL_STATE_DOWN && + check->type != ZAP_CHAN_TYPE_DQ921 && + check->type != ZAP_CHAN_TYPE_DQ931 + + ) { + zap_span_t* span = NULL; + zap_span_find(check->span_id, &span); + if (span && span->channel_request) { + status = span->channel_request(span, check->physical_chan_id, direction, caller_data, zchan); + break; + } + + status = check->zio->open(check); + + if (status == ZAP_SUCCESS) { + zap_set_flag(check, ZAP_CHANNEL_INUSE); + zap_channel_open_chan(check); + *zchan = check; + break; + } + } + + if (direction == ZAP_TOP_DOWN) { + i++; + } else { + i--; + } + } + zap_mutex_unlock(group->mutex); + return status; +} + + OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count) { uint32_t j; @@ -1029,7 +1141,7 @@ OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t * return ZAP_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) +OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) { zap_status_t status = ZAP_FAIL; zap_channel_t *check; @@ -1172,7 +1284,6 @@ static zap_status_t zap_channel_reset(zap_channel_t *zchan) OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan) { - if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { zap_set_state_locked(zchan, zchan->init_state); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; @@ -2438,6 +2549,7 @@ static zap_status_t load_config(void) unsigned configured = 0, d = 0; char name[80] = ""; char number[25] = ""; + char group_name[80] = "default"; zap_io_interface_t *zio = NULL; zap_analog_start_type_t tmp; @@ -2572,6 +2684,9 @@ static zap_status_t load_config(void) } } else if (!strcasecmp(var, "b-channel")) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); + if (zap_group_add_channels(group_name, span, val) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "Failed to add channels (%d:%s) to group\n", number, val); + } } else if (!strcasecmp(var, "d-channel")) { if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); @@ -2591,6 +2706,9 @@ static zap_status_t load_config(void) } else if (!strcasecmp(var, "dtmf_hangup")) { span->dtmf_hangup = zap_strdup(val); span->dtmf_hangup_len = strlen(val); + } else if (!strcasecmp(var, "group")) { + memset(group_name, 0, sizeof(group_name)); + memcpy(group_name, val, sizeof(group_name)); } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } @@ -2880,6 +2998,190 @@ OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) return ZAP_FAIL; } +OZ_DECLARE(zap_status_t) zap_channel_add_to_group(const char* name, zap_channel_t* zchan) +{ + int i; + zap_group_t* group = NULL; + + zap_mutex_lock(globals.group_mutex); + + if (zap_group_find_by_name(name, &group) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_DEBUG, "Creating new group:%s\n", name); + zap_group_create(&group, name); + } + + /*verify that group does not already include this channel first */ + for(i=0; i < group->chan_count; i++) { + if (group->channels[i]->physical_span_id == zchan->physical_span_id && + group->channels[i]->physical_chan_id == zchan->physical_chan_id) { + + zap_mutex_unlock(globals.group_mutex); + return ZAP_SUCCESS; + } + } + + if (group->chan_count >= ZAP_MAX_CHANNELS_GROUP) { + zap_log(ZAP_LOG_CRIT, "Max number of channels exceeded (max:%d)\n", ZAP_MAX_CHANNELS_GROUP); + zap_mutex_unlock(globals.group_mutex); + return ZAP_FAIL; + } + + group->channels[group->chan_count++] = zchan; + zap_mutex_unlock(globals.group_mutex); + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_channel_remove_from_group(zap_group_t* group, zap_channel_t* zchan) +{ + //Need to test this function + zap_mutex_lock(globals.group_mutex); + int i, j; + + for (i=0; i < group->chan_count; i++) { + if (group->channels[i]->physical_span_id == zchan->physical_span_id && + group->channels[i]->physical_chan_id == zchan->physical_chan_id) { + + j=i; + while(j < group->chan_count-1) { + group->channels[j] = group->channels[j+1]; + j++; + } + group->channels[group->chan_count--] = NULL; + if (group->chan_count <=0) { + /* Delete group if it is empty */ + hashtable_remove(globals.group_hash, (void *)group->name); + } + zap_mutex_unlock(globals.group_mutex); + return ZAP_SUCCESS; + } + } + + zap_mutex_unlock(globals.group_mutex); + //Group does not contain this channel + return ZAP_FAIL; +} + +OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* span, const char* val) +{ + char *p, *mydata, *item_list[10]; + int items, i; + + assert(strlen(name) > 0); + + p = strchr(val, ':'); + mydata = zap_strdup(++p); + + assert(mydata != NULL); + + items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); + + for(i=0; i < items; i++) { + if (!strchr(item_list[i], '-')) { + int chan_no; + + chan_no = atoi (item_list[i]); + assert(chan_no > 0); + + if (zap_channel_add_to_group(name, span->channels[chan_no]) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no, name); + } + } else { + int chan_no_start, chan_no_end; + + if (sscanf(item_list[i], "%d-%d", &chan_no_start, &chan_no_end) == 2) { + while (chan_no_start <= chan_no_end) { + if (zap_channel_add_to_group(name, span->channels[chan_no_start++])) { + zap_log(ZAP_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no_start-1, name); + } + } + } + } + } + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group) +{ + zap_group_t *fgroup = NULL, *grp; + + if (id > ZAP_MAX_GROUPS_INTERFACE) { + return ZAP_FAIL; + } + + + zap_mutex_lock(globals.group_mutex); + for (grp = globals.groups; grp; grp = grp->next) { + if (grp->group_id == id) { + fgroup = grp; + break; + } + } + zap_mutex_unlock(globals.group_mutex); + + if (!fgroup) { + return ZAP_FAIL; + } + + *group = fgroup; + + return ZAP_SUCCESS; + +} + +OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group) +{ + zap_status_t status = ZAP_FAIL; + + zap_mutex_lock(globals.group_mutex); + if (!zap_strlen_zero(name)) { + if ((*group = hashtable_search(globals.group_hash, (void *) name))) { + status = ZAP_SUCCESS; + } + } + zap_mutex_unlock(globals.group_mutex); + return status; +} + +static void zap_group_add(zap_group_t *group) +{ + zap_group_t *grp; + zap_mutex_lock(globals.group_mutex); + + for (grp = globals.groups; grp && grp->next; grp = grp->next); + + if (grp) { + grp->next = group; + } else { + globals.groups = group; + } + hashtable_insert(globals.group_hash, (void *)group->name, group, HASHTABLE_FLAG_NONE); + + zap_mutex_unlock(globals.group_mutex); +} + + +OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name) +{ + zap_group_t *new_group = NULL; + zap_status_t status = ZAP_FAIL; + + zap_mutex_lock(globals.mutex); + if (globals.group_index < ZAP_MAX_GROUPS_INTERFACE) { + new_group = zap_malloc(sizeof(*new_group)); + assert(new_group); + memset(new_group, 0, sizeof(*new_group)); + status = zap_mutex_create(&new_group->mutex); + assert(status == ZAP_SUCCESS); + + new_group->group_id = ++globals.group_index; + new_group->name = zap_strdup(name); + zap_group_add(new_group); + *group = new_group; + status = ZAP_SUCCESS; + } + zap_mutex_unlock(globals.mutex); + return status; +} OZ_DECLARE(zap_status_t) zap_global_init(void) { @@ -2893,8 +3195,10 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + globals.group_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); zap_mutex_create(&globals.mutex); zap_mutex_create(&globals.span_mutex); + zap_mutex_create(&globals.group_mutex); globals.running = 1; return ZAP_SUCCESS; } From 5ff8716e8e1902734c787533dbdb0f5276fb2d40 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 5 Jan 2010 16:30:58 +0000 Subject: [PATCH 1659/1766] added more proper checks and fixes to last commit git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@945 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 10 ++---- libs/freetdm/src/zap_io.c | 33 ++++++++++++------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 3dfe91006c..94dbcb58aa 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -401,7 +401,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) *zchan = NULL; } zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); - zap_log(ZAP_LOG_CRIT, "DYDBG s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r); + zap_log(ZAP_LOG_CRIT, "s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r); goto done; } } @@ -683,7 +683,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco event->release_cause = 17; } - zap_log(ZAP_LOG_CRIT, "DYDBG setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); + zap_log(ZAP_LOG_DEBUG, "setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); OUTBOUND_REQUESTS[event->call_setup_id].event = *event; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; if (!sangoma_boost_data->sigmod) { @@ -1565,7 +1565,6 @@ end: */ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { - int i; g_boost_modules_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys); if (!g_boost_modules_hash) { return ZAP_FAIL; @@ -1573,10 +1572,7 @@ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) zap_mutex_create(&request_mutex); zap_mutex_create(&signal_mutex); zap_mutex_create(&g_boost_modules_mutex); - - for(i=0;i< MAX_TRUNK_GROUPS;i++) { - g_trunkgroups[i]=NULL; - } + memset(&g_trunkgroups[0], 0, sizeof(g_trunkgroups)); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 124e371be3..e95550471c 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2552,6 +2552,7 @@ static zap_status_t load_config(void) char group_name[80] = "default"; zap_io_interface_t *zio = NULL; zap_analog_start_type_t tmp; + zap_size_t len = 0; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; @@ -2707,8 +2708,13 @@ static zap_status_t load_config(void) span->dtmf_hangup = zap_strdup(val); span->dtmf_hangup_len = strlen(val); } else if (!strcasecmp(var, "group")) { - memset(group_name, 0, sizeof(group_name)); - memcpy(group_name, val, sizeof(group_name)); + len = strlen(val); + if (len >= sizeof(group_name)) { + len = sizeof(group_name) - 1; + zap_log(ZAP_LOG_WARNING, "Truncating group name %s to %zd length\n", val, len); + } + zap_copy_string(group_name, val, len); + group_name[len] = '\0'; } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } @@ -2728,7 +2734,8 @@ static zap_status_t process_module_config(zap_io_interface_t *zio) zap_config_t cfg; char *var, *val; char filename[256] = ""; - assert(zio != NULL); + + zap_assert_return(zio != NULL, ZAP_FAIL, "zio argument is null\n"); snprintf(filename, sizeof(filename), "%s.conf", zio->name); @@ -3071,7 +3078,7 @@ OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* sp p = strchr(val, ':'); mydata = zap_strdup(++p); - assert(mydata != NULL); + zap_assert_return(mydata != NULL, ZAP_FAIL, "zap_strdup failed when adding channels\n"); items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); @@ -3080,14 +3087,13 @@ OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* sp int chan_no; chan_no = atoi (item_list[i]); - assert(chan_no > 0); + zap_assert(chan_no > 0, "Channel number is not bigger than zero, expect a nasty failure!\n"); if (zap_channel_add_to_group(name, span->channels[chan_no]) != ZAP_SUCCESS) { zap_log(ZAP_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no, name); } } else { int chan_no_start, chan_no_end; - if (sscanf(item_list[i], "%d-%d", &chan_no_start, &chan_no_end) == 2) { while (chan_no_start <= chan_no_end) { if (zap_channel_add_to_group(name, span->channels[chan_no_start++])) { @@ -3097,6 +3103,7 @@ OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* sp } } } + zap_safe_free(mydata); return ZAP_SUCCESS; } @@ -3131,7 +3138,7 @@ OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group) OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group) { zap_status_t status = ZAP_FAIL; - + *group = NULL; zap_mutex_lock(globals.group_mutex); if (!zap_strlen_zero(name)) { if ((*group = hashtable_search(globals.group_hash, (void *) name))) { @@ -3167,17 +3174,21 @@ OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name) zap_mutex_lock(globals.mutex); if (globals.group_index < ZAP_MAX_GROUPS_INTERFACE) { - new_group = zap_malloc(sizeof(*new_group)); - assert(new_group); - memset(new_group, 0, sizeof(*new_group)); + new_group = zap_calloc(1, sizeof(*new_group)); + + zap_assert(new_group != NULL, "Failed to create new zap group, expect a crash\n"); + status = zap_mutex_create(&new_group->mutex); - assert(status == ZAP_SUCCESS); + + zap_assert(status == ZAP_SUCCESS, "Failed to create group mutex, expect a crash\n"); new_group->group_id = ++globals.group_index; new_group->name = zap_strdup(name); zap_group_add(new_group); *group = new_group; status = ZAP_SUCCESS; + } else { + zap_log(ZAP_LOG_CRIT, "Group %s was not added, we exceeded the max number of groups\n", name); } zap_mutex_unlock(globals.mutex); return status; From 85938b212efccefaddca10662ec37761484648c3 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 5 Jan 2010 23:54:53 +0000 Subject: [PATCH 1660/1766] Add possible fix for ozmod_isdn (+ pcap) compile error on solaris. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@946 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 08f5662f9d..68e727ee3d 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -53,6 +53,9 @@ #ifdef HAVE_LIBPCAP /*-------------------------------------------------------------------------*/ /*Q931ToPcap functions*/ +#ifndef WIN32 +#include +#endif #include #endif From 5aa9ff86a8a46a57de6749381320c6775e174eb7 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 6 Jan 2010 17:00:19 +0000 Subject: [PATCH 1661/1766] added span signaling status APIs git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@947 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/openzap.h | 10 ++- libs/freetdm/src/include/zap_types.h | 23 ++++--- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 57 +++++++++++++++-- .../sangoma_boost_interface.h | 61 +++++++++++++------ libs/freetdm/src/zap_io.c | 53 +++++++++++++--- 5 files changed, 165 insertions(+), 39 deletions(-) diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 15ddf350c1..5a311e6c6f 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -568,7 +568,10 @@ struct zap_span { teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; zap_channel_t *channels[ZAP_MAX_CHANNELS_SPAN+1]; zio_channel_outgoing_call_t outgoing_call; - zio_channel_get_sig_status_t get_sig_status; + zio_channel_set_sig_status_t set_channel_sig_status; + zio_channel_get_sig_status_t get_channel_sig_status; + zio_span_set_sig_status_t set_span_sig_status; + zio_span_get_sig_status_t get_span_sig_status; zio_channel_request_t channel_request; zap_span_start_t start; zap_span_stop_t stop; @@ -697,7 +700,10 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_ OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *status); +OZ_DECLARE(zap_status_t) zap_channel_set_sig_status(zap_channel_t *zchan, zap_signaling_status_t status); +OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_signaling_status_t *status); +OZ_DECLARE(zap_status_t) zap_span_set_sig_status(zap_span_t *span, zap_signaling_status_t status); +OZ_DECLARE(zap_status_t) zap_span_get_sig_status(zap_span_t *span, zap_signaling_status_t *status); OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan); OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan); OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index 98571e9b84..eb5c698f5e 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -187,20 +187,20 @@ typedef enum { } zap_signal_type_t; /*! - \brief Signaling status on the channel + \brief Signaling status on a given span or specific channel on protocols that support it */ typedef enum { - /* The channel signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */ + /* The signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */ ZAP_SIG_STATE_DOWN, - /* The channel signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */ + /* The signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */ ZAP_SIG_STATE_SUSPENDED, - /* The channel signaling link is ready and calls can be placed */ + /* The signaling link is ready and calls can be placed */ ZAP_SIG_STATE_UP, /* Invalid status */ ZAP_SIG_STATE_INVALID -} zap_channel_sig_status_t; +} zap_signaling_status_t; #define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_channel_sig_status, zap_sig_status2str, zap_channel_sig_status_t) +ZAP_STR2ENUM_P(zap_str2zap_signaling_status, zap_signaling_status2str, zap_signaling_status_t) typedef enum { ZAP_SIGEVENT_START, @@ -470,7 +470,10 @@ typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t #define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, uint32_t chan_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) #define ZIO_CHANNEL_OUTGOING_CALL_ARGS (zap_channel_t *zchan) -#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t *status) +#define ZIO_CHANNEL_SET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t status) +#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t *status) +#define ZIO_SPAN_SET_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t status) +#define ZIO_SPAN_GET_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t *status) #define ZIO_SPAN_POLL_EVENT_ARGS (zap_span_t *span, uint32_t ms) #define ZIO_SPAN_NEXT_EVENT_ARGS (zap_span_t *span, zap_event_t **event) #define ZIO_SIGNAL_CB_ARGS (zap_sigmsg_t *sigmsg) @@ -497,7 +500,10 @@ typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; typedef zap_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ; +typedef zap_status_t (*zio_channel_set_sig_status_t) ZIO_CHANNEL_SET_SIG_STATUS_ARGS; typedef zap_status_t (*zio_channel_get_sig_status_t) ZIO_CHANNEL_GET_SIG_STATUS_ARGS; +typedef zap_status_t (*zio_span_set_sig_status_t) ZIO_SPAN_SET_SIG_STATUS_ARGS; +typedef zap_status_t (*zio_span_get_sig_status_t) ZIO_SPAN_GET_SIG_STATUS_ARGS; typedef zap_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ; typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ; typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ; @@ -525,7 +531,10 @@ typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ; #define ZIO_CHANNEL_REQUEST_FUNCTION(name) zap_status_t name ZIO_CHANNEL_REQUEST_ARGS #define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) zap_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS +#define ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_SET_SIG_STATUS_ARGS #define ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_GET_SIG_STATUS_ARGS +#define ZIO_SPAN_SET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_SPAN_SET_SIG_STATUS_ARGS +#define ZIO_SPAN_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_SPAN_GET_SIG_STATUS_ARGS #define ZIO_SPAN_POLL_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_POLL_EVENT_ARGS #define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_NEXT_EVENT_ARGS #define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 94dbcb58aa..5e5723dc66 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1770,7 +1770,7 @@ static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) { zap_sigmsg_t sig; zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; - zap_log(ZAP_LOG_DEBUG, "%d:%d Signaling link status changed to %s\n", zchan->span_id, zchan->chan_id, zap_sig_status2str(status)); + zap_log(ZAP_LOG_NOTICE, "%d:%d Signaling link status changed to %s\n", zchan->span_id, zchan->chan_id, zap_signaling_status2str(status)); memset(&sig, 0, sizeof(sig)); sig.chan_id = zchan->chan_id; @@ -1782,14 +1782,60 @@ static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) return; } -static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_sig_status) +static ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_channel_sig_status) +{ + zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; + if (!sangoma_boost_data->sigmod) { + zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost channel with no signaling module configured\n"); + return ZAP_FAIL; + } + if (!sangoma_boost_data->sigmod->set_channel_sig_status) { + zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost channel: method not implemented\n"); + return ZAP_NOTIMPL; + } + return sangoma_boost_data->sigmod->set_channel_sig_status(zchan, status); +} + +static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_channel_sig_status) { zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; if (!sangoma_boost_data->sigmod) { zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost channel with no signaling module configured\n"); return ZAP_FAIL; } - return sangoma_boost_data->sigmod->get_sig_status(zchan, status); + if (!sangoma_boost_data->sigmod->get_channel_sig_status) { + zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost channel: method not implemented\n"); + return ZAP_NOTIMPL; + } + return sangoma_boost_data->sigmod->get_channel_sig_status(zchan, status); +} + +static ZIO_SPAN_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_span_sig_status) +{ + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + if (!sangoma_boost_data->sigmod) { + zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost span with no signaling module configured\n"); + return ZAP_FAIL; + } + if (!sangoma_boost_data->sigmod->set_span_sig_status) { + zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost span: method not implemented\n"); + return ZAP_NOTIMPL; + } + return sangoma_boost_data->sigmod->set_span_sig_status(span, status); +} + +static ZIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) +{ + zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + if (!sangoma_boost_data->sigmod) { + zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost span with no signaling module configured\n"); + return ZAP_FAIL; + } + if (!sangoma_boost_data->sigmod->get_span_sig_status) { + zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost span: method not implemented\n"); + return ZAP_NOTIMPL; + } + return sangoma_boost_data->sigmod->get_span_sig_status(span, status); } /** @@ -1910,7 +1956,10 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; span->outgoing_call = sangoma_boost_outgoing_call; span->channel_request = sangoma_boost_channel_request; - span->get_sig_status = sangoma_boost_get_sig_status; + span->get_channel_sig_status = sangoma_boost_get_channel_sig_status; + span->set_channel_sig_status = sangoma_boost_set_channel_sig_status; + span->get_span_sig_status = sangoma_boost_get_span_sig_status; + span->set_span_sig_status = sangoma_boost_set_span_sig_status; span->state_map = &boost_state_map; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); return ZAP_SUCCESS; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h index 8757adcab3..5faa474727 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h @@ -47,7 +47,7 @@ extern "C" { \param zchan The openzap channel where the signaling status just changed \param status The new signaling status */ -#define BOOST_SIG_STATUS_CB_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t status) +#define BOOST_SIG_STATUS_CB_ARGS (zap_channel_t *zchan, zap_signaling_status_t status) typedef void (*boost_sig_status_cb_func_t) BOOST_SIG_STATUS_CB_ARGS; #define BOOST_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SIG_STATUS_CB_ARGS @@ -78,6 +78,16 @@ typedef zap_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS; typedef void (*boost_set_write_msg_cb_func_t) BOOST_SET_WRITE_MSG_CB_ARGS; #define BOOST_SET_WRITE_MSG_CB_FUNCTION(name) void name BOOST_SET_WRITE_MSG_CB_ARGS +/*! + \brief Notify hardware status change + \param zchan The openzap channel + \param status The hw status + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) +typedef void (*boost_on_hw_link_status_change_func_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS; +#define BOOST_ON_HW_LINK_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS + /*! \brief Set signaling status callback used by the signaling module to report signaling status changes \param callback The callback to be used by the signaling module @@ -89,24 +99,14 @@ typedef void (*boost_set_write_msg_cb_func_t) BOOST_SET_WRITE_MSG_CB_ARGS; typedef void (*boost_set_sig_status_cb_func_t) BOOST_SET_SIG_STATUS_CB_ARGS; #define BOOST_SET_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SET_SIG_STATUS_CB_ARGS -/*! - \brief Notify hardware status change - \param zchan The openzap channel - \param status The hw status - \return ZAP_SUCCESS or ZAP_FAIL - */ -#define BOOST_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t *status) -typedef zap_status_t (*boost_get_sig_status_func_t) BOOST_GET_SIG_STATUS_ARGS; -#define BOOST_GET_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_SIG_STATUS_ARGS - /*! \brief Get the signaling status on the given channel. \param zchan The openzap channel \param status The status pointer where the current signaling status will be set */ -#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) -typedef void (*boost_on_hw_link_status_change_func_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS; -#define BOOST_ON_HW_LINK_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS +#define BOOST_GET_CHANNEL_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t *status) +typedef zap_status_t (*boost_get_channel_sig_status_func_t) BOOST_GET_CHANNEL_SIG_STATUS_ARGS; +#define BOOST_GET_CHANNEL_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_CHANNEL_SIG_STATUS_ARGS /*! \brief Set the signaling status on the given channel. @@ -114,9 +114,28 @@ typedef void (*boost_on_hw_link_status_change_func_t) BOOST_ON_HW_LINK_STATUS_CH \param status The new status for the channel \return ZAP_SUCCESS or ZAP_FAIL */ -#define BOOST_SET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_channel_sig_status_t status) -typedef zap_status_t (*boost_set_sig_status_func_t) BOOST_SET_SIG_STATUS_ARGS; -#define BOOST_SET_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_SIG_STATUS_ARGS +#define BOOST_SET_CHANNEL_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t status) +typedef zap_status_t (*boost_set_channel_sig_status_func_t) BOOST_SET_CHANNEL_SIG_STATUS_ARGS; +#define BOOST_SET_CHANNEL_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_CHANNEL_SIG_STATUS_ARGS + +/*! + \brief Get the signaling status on the given span. + \param span The openzap span + \param status The status pointer where the current signaling status will be set + */ +#define BOOST_GET_SPAN_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t *status) +typedef zap_status_t (*boost_get_span_sig_status_func_t) BOOST_GET_SPAN_SIG_STATUS_ARGS; +#define BOOST_GET_SPAN_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_SPAN_SIG_STATUS_ARGS + +/*! + \brief Set the signaling status on the given span. + \param zchan The openzap span + \param status The new status for the span + \return ZAP_SUCCESS or ZAP_FAIL + */ +#define BOOST_SET_SPAN_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t status) +typedef zap_status_t (*boost_set_span_sig_status_func_t) BOOST_SET_SPAN_SIG_STATUS_ARGS; +#define BOOST_SET_SPAN_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_SPAN_SIG_STATUS_ARGS /*! \brief Configure the given span signaling @@ -174,9 +193,13 @@ typedef struct boost_sigmod_interface_s { /*! \brief set the user signaling status function */ boost_set_sig_status_cb_func_t set_sig_status_cb; /*! \brief get channel signaling status */ - boost_get_sig_status_func_t get_sig_status; + boost_get_channel_sig_status_func_t get_channel_sig_status; /*! \brief set channel signaling status */ - boost_set_sig_status_func_t set_sig_status; + boost_set_channel_sig_status_func_t set_channel_sig_status; + /*! \brief get span signaling status */ + boost_get_span_sig_status_func_t get_span_sig_status; + /*! \brief set span signaling status */ + boost_set_span_sig_status_func_t set_span_sig_status; /*! \brief set notify hardware link status change */ boost_on_hw_link_status_change_func_t on_hw_link_status_change; /*! \brief configure span signaling */ diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index e95550471c..5aec3021fb 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -119,8 +119,8 @@ ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYP ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) -ZAP_ENUM_NAMES(CHAN_SIG_STATUS_NAMES, SIGSTATUS_STRINGS) -ZAP_STR2ENUM(zap_str2zap_channel_sig_status, zap_sig_status2str, zap_channel_sig_status_t, CHAN_SIG_STATUS_NAMES, ZAP_SIG_STATE_INVALID) +ZAP_ENUM_NAMES(SIGNALING_STATUS_NAMES, SIGSTATUS_STRINGS) +ZAP_STR2ENUM(zap_str2zap_signaling_status, zap_signaling_status2str, zap_signaling_status_t, SIGNALING_STATUS_NAMES, ZAP_SIG_STATE_INVALID) static const char *cut_path(const char *in) { @@ -1397,15 +1397,54 @@ OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) return ZAP_FAIL; } -OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus) +OZ_DECLARE(zap_status_t) zap_channel_set_sig_status(zap_channel_t *zchan, zap_signaling_status_t sigstatus) { zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n"); - zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status"); + zap_assert_return(zchan->span != NULL, ZAP_FAIL, "Null span\n"); - if (zchan->span->get_sig_status) { - return zchan->span->get_sig_status(zchan, sigstatus); + if (zchan->span->set_channel_sig_status) { + return zchan->span->set_channel_sig_status(zchan, sigstatus); } else { - zap_log(ZAP_LOG_ERROR, "get_sig_status method not implemented!\n"); + zap_log(ZAP_LOG_ERROR, "set_channel_sig_status method not implemented!\n"); + return ZAP_FAIL; + } +} + +OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_signaling_status_t *sigstatus) +{ + zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n"); + zap_assert_return(zchan->span != NULL, ZAP_FAIL, "Null span\n"); + zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status parameter\n"); + + if (zchan->span->get_channel_sig_status) { + return zchan->span->get_channel_sig_status(zchan, sigstatus); + } else { + zap_log(ZAP_LOG_ERROR, "get_channel_sig_status method not implemented!\n"); + return ZAP_FAIL; + } +} + +OZ_DECLARE(zap_status_t) zap_span_set_sig_status(zap_span_t *span, zap_signaling_status_t sigstatus) +{ + zap_assert_return(span != NULL, ZAP_FAIL, "Null span\n"); + + if (span->set_span_sig_status) { + return span->set_span_sig_status(span, sigstatus); + } else { + zap_log(ZAP_LOG_ERROR, "set_span_sig_status method not implemented!\n"); + return ZAP_FAIL; + } +} + +OZ_DECLARE(zap_status_t) zap_span_get_sig_status(zap_span_t *span, zap_signaling_status_t *sigstatus) +{ + zap_assert_return(span != NULL, ZAP_FAIL, "Null span\n"); + zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status parameter\n"); + + if (span->get_span_sig_status) { + return span->get_span_sig_status(span, sigstatus); + } else { + zap_log(ZAP_LOG_ERROR, "get_span_sig_status method not implemented!\n"); return ZAP_FAIL; } } From 4a5762ada3b6217684f1c61b496d000177479239 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 6 Jan 2010 20:58:21 +0000 Subject: [PATCH 1662/1766] implemented zap gains, not tested git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@948 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 47 +++++++- libs/freetdm/src/include/openzap.h | 7 +- libs/freetdm/src/include/zap_types.h | 5 +- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 2 +- libs/freetdm/src/zap_io.c | 109 +++++++++++++++++- 5 files changed, 159 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index ee8234c99f..3042d8e817 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -2665,7 +2665,7 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s ); } -#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix]" +#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains " SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; @@ -2750,7 +2750,7 @@ SWITCH_STANDARD_API(oz_function) for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { if (SPAN_CONFIG[j].span) { const char *flags = "none"; - zap_channel_sig_status_t chanstatus; + zap_signaling_status_t sigstatus; if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { flags = "3way"; @@ -2758,8 +2758,7 @@ SWITCH_STANDARD_API(oz_function) flags = "call swap"; } - /* check signaling status just in the first span channel */ - if ((ZAP_SUCCESS == zap_channel_get_sig_status(SPAN_CONFIG[j].span->channels[1], &chanstatus))) { + if ((ZAP_SUCCESS == zap_span_get_sig_status(SPAN_CONFIG[j].span, &sigstatus))) { stream->write_function(stream, "+OK\n" "span: %u (%s)\n" @@ -2775,7 +2774,7 @@ SWITCH_STANDARD_API(oz_function) j, SPAN_CONFIG[j].span->name, SPAN_CONFIG[j].type, - zap_sig_status2str(chanstatus), + zap_signaling_status2str(sigstatus), SPAN_CONFIG[j].span->chan_count, SPAN_CONFIG[j].dialplan, SPAN_CONFIG[j].context, @@ -2883,6 +2882,44 @@ SWITCH_STANDARD_API(oz_function) goto end; } + } else if (!strcasecmp(argv[0], "gains")) { + int i = 0; + float txgain = 0.0; + float rxgain = 0.0; + uint32_t chan_id = 0; + zap_span_t *span = NULL; + if (argc < 4) { + stream->write_function(stream, "-ERR Usage: oz gains []\n"); + goto end; + } + zap_span_find_by_name(argv[3], &span); + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + if (argc > 4) { + chan_id = atoi(argv[4]); + if (chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid chan\n"); + goto end; + } + } + i = sscanf(argv[1], "%f", &rxgain); + i += sscanf(argv[2], "%f", &txgain); + if (i != 2) { + stream->write_function(stream, "-ERR invalid gains\n"); + goto end; + } + if (chan_id) { + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_RX_GAIN, &rxgain); + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_TX_GAIN, &txgain); + } else { + for (i = 1; i < span->chan_count; i++) { + zap_channel_command(span->channels[i], ZAP_COMMAND_SET_RX_GAIN, &rxgain); + zap_channel_command(span->channels[i], ZAP_COMMAND_SET_TX_GAIN, &txgain); + } + } + stream->write_function(stream, "+OK gains set to Rx %f and Tx %f\n", rxgain, txgain); } else { char *rply = zap_api_execute(cmd, NULL); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 5a311e6c6f..15996fd64c 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -473,7 +473,8 @@ typedef enum { ZAP_TYPE_CHANNEL } zap_data_type_t; - +/* 2^8 table size, one for each byte value */ +#define ZAP_GAINS_TABLE_SIZE 256 struct zap_channel { zap_data_type_t data_type; uint32_t span_id; @@ -535,6 +536,10 @@ struct zap_channel { zap_hash_t *variable_hash; unsigned char rx_cas_bits; uint32_t pre_buffer_size; + unsigned char rxgain_table[ZAP_GAINS_TABLE_SIZE]; + unsigned char txgain_table[ZAP_GAINS_TABLE_SIZE]; + float rxgain; + float txgain; }; diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h index eb5c698f5e..e4f6811b57 100644 --- a/libs/freetdm/src/include/zap_types.h +++ b/libs/freetdm/src/include/zap_types.h @@ -73,6 +73,7 @@ struct zap_io_interface; #define ZAP_COMMAND_OBJ_INT *((int *)obj) #define ZAP_COMMAND_OBJ_CHAR_P (char *)obj +#define ZAP_COMMAND_OBJ_FLOAT *(float *)obj #define ZAP_FSK_MOD_FACTOR 0x10000 #define ZAP_DEFAULT_DTMF_ON 250 #define ZAP_DEFAULT_DTMF_OFF 50 @@ -403,7 +404,9 @@ typedef enum { ZAP_CHANNEL_PROGRESS = (1 << 21), ZAP_CHANNEL_MEDIA = (1 << 22), ZAP_CHANNEL_ANSWERED = (1 << 23), - ZAP_CHANNEL_MUTE = (1 << 24) + ZAP_CHANNEL_MUTE = (1 << 24), + ZAP_CHANNEL_USE_RX_GAIN = (1 << 25), + ZAP_CHANNEL_USE_TX_GAIN = (1 << 26), } zap_channel_flag_t; #if defined(__cplusplus) && defined(WIN32) // fix C2676 diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index a6f436ffc5..027bdabcea 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -33,7 +33,7 @@ * Contributors: * * Moises Silva - * David Yatzin + * David Yat Sin * Nenad Corbic * */ diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 5aec3021fb..09814a522d 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -587,17 +587,65 @@ OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapna } +#define ZAP_SLINEAR_MAX_VALUE 32767 +#define ZAP_SLINEAR_MIN_VALUE -32767 +static void reset_gain_table(unsigned char *gain_table, float new_gain, zap_codec_t codec_gain) +{ + /* sample value */ + unsigned sv = 0; + /* linear gain factor */ + float lingain = 0; + /* linear value for each table sample */ + float linvalue = 0; + /* amplified (or attenuated in case of negative amplification) sample value */ + int ampvalue = 0; + + /* gain tables are only for alaw and ulaw */ + if (codec_gain != ZAP_CODEC_ALAW && codec_gain != ZAP_CODEC_ULAW) { + zap_log(ZAP_LOG_WARNING, "Not resetting gain table because codec is not ALAW or ULAW but %d\n", codec_gain); + return; + } + + if (!new_gain) { + /* for a 0.0db gain table, each alaw/ulaw sample value is left untouched (0 ==0, 1 == 1, 2 == 2 etc)*/ + for (sv = 0; sv < ZAP_GAINS_TABLE_SIZE; sv++) { + gain_table[sv] = sv; + } + return; + } + + /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wipedia.org/wiki/20_log_rule#Definitions */ + lingain = pow(10.0, new_gain/ 20.0); + for (sv = 0; sv < ZAP_GAINS_TABLE_SIZE; sv++) { + /* get the linear value for this alaw/ulaw sample value */ + linvalue = codec_gain == ZAP_CODEC_ALAW ? alaw_to_linear(sv) : ulaw_to_linear(sv); + + /* multiply the linear value and the previously calculated linear gain */ + ampvalue = (int)(linvalue * lingain); + + /* chop it if goes beyond the limits */ + if (ampvalue > ZAP_SLINEAR_MAX_VALUE) { + ampvalue = ZAP_SLINEAR_MAX_VALUE; + } + + if (ampvalue < ZAP_SLINEAR_MIN_VALUE) { + ampvalue = ZAP_SLINEAR_MIN_VALUE; + } + gain_table[sv] = codec_gain == ZAP_CODEC_ALAW ? linear_to_alaw(ampvalue) : linear_to_ulaw(ampvalue); + } +} + OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { + unsigned i = 0; if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *new_chan = span->channels[++span->chan_count]; if (!new_chan) { - if (!(new_chan = zap_malloc(sizeof(*new_chan)))) { + if (!(new_chan = zap_calloc(1, sizeof(*new_chan)))) { return ZAP_FAIL; } span->channels[span->chan_count] = new_chan; - memset(new_chan, 0, sizeof(*new_chan)); } new_chan->type = type; @@ -626,6 +674,12 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc new_chan->dtmf_hangup_buf = zap_calloc (span->dtmf_hangup_len + 1, sizeof (char)); + /* set 0.0db gain table */ + for (i = 0; i < sizeof(new_chan->txgain_table); i++) { + new_chan->txgain_table[i] = i; + new_chan->rxgain_table[i] = i; + } + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -1833,6 +1887,40 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t zap_mutex_unlock(zchan->pre_buffer_mutex); } break; + + /* FIXME: validate user gain values */ + case ZAP_COMMAND_SET_RX_GAIN: + { + zchan->rxgain = ZAP_COMMAND_OBJ_FLOAT; + reset_gain_table(zchan->rxgain_table, zchan->rxgain, zchan->native_codec); + if (zchan->rxgain == 0.0) { + zap_clear_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); + } + } + break; + case ZAP_COMMAND_GET_RX_GAIN: + { + ZAP_COMMAND_OBJ_FLOAT = zchan->rxgain; + } + break; + case ZAP_COMMAND_SET_TX_GAIN: + { + zchan->txgain = ZAP_COMMAND_OBJ_FLOAT; + reset_gain_table(zchan->txgain_table, zchan->txgain, zchan->native_codec); + if (zchan->txgain == 0.0) { + zap_clear_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); + } + } + break; + case ZAP_COMMAND_GET_TX_GAIN: + { + ZAP_COMMAND_OBJ_FLOAT = zchan->txgain; + } + break; default: break; } @@ -2212,10 +2300,10 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; zap_size_t max = *datalen; + unsigned i = 0; assert(zchan != NULL); assert(zchan->zio != NULL); - assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); @@ -2237,6 +2325,13 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ } if (status == ZAP_SUCCESS) { + if (zap_test_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN) + && (zchan->native_codec == ZAP_CODEC_ALAW || zchan->native_codec == ZAP_CODEC_ULAW)) { + unsigned char *rdata = data; + for (i = 0; i < *datalen; i++) { + rdata[i] = zchan->rxgain_table[rdata[i]]; + } + } handle_dtmf(zchan, *datalen); } @@ -2435,6 +2530,7 @@ OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; zap_size_t max = datasize; + unsigned int i = 0; assert(zchan != NULL); assert(zchan->zio != NULL); @@ -2484,6 +2580,13 @@ OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap } } + if (zap_test_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN) + && (zchan->native_codec == ZAP_CODEC_ALAW || zchan->native_codec == ZAP_CODEC_ULAW)) { + unsigned char *wdata = data; + for (i = 0; i < *datalen; i++) { + wdata[i] = zchan->txgain_table[wdata[i]]; + } + } status = zchan->zio->write(zchan, data, datalen); return status; From 29627360b510953a7b1dd461c22e3fc73a03aee6 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 7 Jan 2010 16:00:28 +0000 Subject: [PATCH 1663/1766] Final workaround for the ozmod_isdn libpcap build failure on solaris. Define __EXTENSIONS__ before including openzap.h to get the required u_int/u_short typedefs that would be disabled otherwise, due to either _XOPEN_SOURCE or _POSIX_C_SOURCE being set. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@949 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 68e727ee3d..e4e9a1511f 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -31,6 +31,13 @@ * 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" @@ -53,9 +60,6 @@ #ifdef HAVE_LIBPCAP /*-------------------------------------------------------------------------*/ /*Q931ToPcap functions*/ -#ifndef WIN32 -#include -#endif #include #endif From 80e1a88b324ead8ba2a822412f34a785633c3445 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 7 Jan 2010 16:55:48 +0000 Subject: [PATCH 1664/1766] dont return error if there are no events on wanpipe_poll, it may be an async signal on the wanpipe device git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@950 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 027bdabcea..713e72498b 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -855,9 +855,8 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) k++; } } - - - return k ? ZAP_SUCCESS : ZAP_FAIL; + /* when k is 0 it might be that an async wanpipe device signal was delivered */ + return ZAP_SUCCESS; } /** From 258e16005780804b06b86fadf3558f9efa9a7209 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 8 Jan 2010 21:02:50 +0000 Subject: [PATCH 1665/1766] Fix for calls not cleared on call abort git-svn-id: http://svn.openzap.org/svn/openzap/trunk@951 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 30 ++++++---- libs/openzap/src/include/openzap.h | 30 ++++++---- libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c | 4 +- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 55 +++++++++---------- 4 files changed, 67 insertions(+), 52 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 88c75c2d9d..ff5a564d51 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -817,50 +817,57 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - + assert(tech_pvt->zchan != NULL); + + zap_mutex_lock(tech_pvt->zchan->mutex); + if (tech_pvt->zchan->state == ZAP_CHANNEL_STATE_TERMINATING) { + zap_mutex_unlock(tech_pvt->zchan->mutex); + return SWITCH_STATUS_SUCCESS; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); } else { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } } break; case SWITCH_MESSAGE_INDICATE_PROGRESS: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); } else { /* Don't skip messages in the ISDN call setup * TODO: make the isdn stack smart enough to handle that itself * until then, this is here for safety... */ if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } break; case SWITCH_MESSAGE_INDICATE_ANSWER: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); } else { /* Don't skip messages in the ISDN call setup * TODO: make the isdn stack smart enough to handle that itself * until then, this is here for safety... */ if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } break; @@ -868,6 +875,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, break; } + zap_mutex_unlock(tech_pvt->zchan->mutex); return SWITCH_STATUS_SUCCESS; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 2c7d132b3b..cfbf065b06 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -268,6 +268,26 @@ /* The while(0) below throws a conditional expression is constant warning */ #pragma warning(disable:4127) #endif + +#define zap_wait_for_flag_cleared(obj, flag, time) \ + do { \ + int __safety = time; \ + while(__safety-- && zap_test_flag(obj, flag)) { \ + zap_mutex_unlock(obj->mutex); \ + zap_sleep(10); \ + zap_mutex_lock(obj->mutex); \ + } \ + if(!__safety) { \ + zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ + } \ + } while(0); + +#define zap_set_state_wait(obj, s) \ + do { \ + zap_channel_set_state(obj, s, 0); \ + zap_wait_for_flag_cleared(obj, ZAP_CHANNEL_STATE_CHANGE, 100); \ + } while(0); + #define zap_set_state_locked_wait(obj, s) \ do { \ int __safety = 100; \ @@ -280,16 +300,6 @@ } \ } while(0); -#define zap_locked_wait_for_flag_cleared(obj, flag, time) \ - do { \ - int __safety = time; \ - while(__safety-- && zap_test_flag(obj, flag)) { \ - zap_sleep(10); \ - } \ - if(!__safety) { \ - zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ - } \ - } while(0); typedef enum { diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c index 9683aa57b2..f911e67d95 100644 --- a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c @@ -166,7 +166,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(r2_outgoing_call) zap_mutex_lock(zchan->mutex); /* the channel may be down but the thread not quite done */ - zap_locked_wait_for_flag_cleared(zchan, ZAP_CHANNEL_INTHREAD, 200); + 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", @@ -217,7 +217,7 @@ static void zap_r2_on_call_init(openr2_chan_t *r2chan) } /* the channel may be down but the thread not quite done */ - zap_locked_wait_for_flag_cleared(zchan, ZAP_CHANNEL_INTHREAD, 200); + 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", 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 index 892094126e..4c4caffb9b 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -372,9 +372,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { zap_sleep(1); if (--sanity <= 0) { - status = ZAP_FAIL; - *zchan = NULL; - goto done; + status = ZAP_FAIL; + *zchan = NULL; + goto done; } //printf("WTF %d\n", sanity); } @@ -625,9 +625,11 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco if ((zchan = find_zchan(span, event, 1))) { int r = 0; assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); + + zchan->call_data = (void*)event->event_id; zap_mutex_lock(zchan->mutex); - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_CANCEL, 0, r); + 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; } @@ -898,9 +900,7 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s } assert(event->call_setup_id <= MAX_REQ_ID); - switch(event->event_id) { - case SIGBOOST_EVENT_CALL_START: handle_call_start(span, mcon, (sangomabc_event_t*)event); break; @@ -992,14 +992,25 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); + if (zchan->call_data && ((uint32_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); + + } else { + sangomabc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } } zchan->sflags = 0; + zchan->call_data = NULL; zap_channel_done(zchan); } break; @@ -1103,20 +1114,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; - case ZAP_CHANNEL_STATE_CANCEL: - { - sig.event_id = ZAP_SIGEVENT_STOP; - status = sangoma_boost_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, - 0, - SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); - } - break; case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; @@ -1476,7 +1473,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_RING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA,ZAP_END} }, { ZSD_INBOUND, @@ -1487,14 +1484,14 @@ static zap_state_map_t boost_state_map = { { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, + {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_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, 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, From 95df158b78456075723d45e83c11640a57421d30 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 8 Jan 2010 21:53:41 +0000 Subject: [PATCH 1666/1766] fix boost span hunting git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@952 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 27 ++++++++++--------- .../sangoma_boost_client.c | 8 +++--- libs/freetdm/src/zap_io.c | 4 +-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 5e5723dc66..59f6f8ecdc 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1230,22 +1230,22 @@ static __inline__ void check_state(zap_span_t *span) 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) { + 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); + 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]); + 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)) { @@ -1953,14 +1953,15 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) span->start = zap_sangoma_boost_start; span->stop = zap_sangoma_boost_stop; span->signal_data = sangoma_boost_data; - span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; - span->outgoing_call = sangoma_boost_outgoing_call; + span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; + span->outgoing_call = sangoma_boost_outgoing_call; span->channel_request = sangoma_boost_channel_request; span->get_channel_sig_status = sangoma_boost_get_channel_sig_status; span->set_channel_sig_status = sangoma_boost_set_channel_sig_status; span->get_span_sig_status = sangoma_boost_get_span_sig_status; span->set_span_sig_status = sangoma_boost_set_span_sig_status; span->state_map = &boost_state_map; + span->suggest_chan_id = 1; zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); return ZAP_SUCCESS; } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 0af4664ee7..9e332d1504 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -76,7 +76,7 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", dir ? "TX":"RX", priority ? "P":"N", sangomabc_event_id_name(event->event_id), @@ -95,7 +95,7 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", + zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", dir ? "TX":"RX", priority ? "P":"N", sangomabc_event_id_name(event->event_id), @@ -305,9 +305,9 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int return NULL; } - if (mcon->event.version != SIGBOOST_VERSION) { + 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) { diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 09814a522d..567c7aff40 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1149,7 +1149,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direct zap_span_t* span = NULL; zap_span_find(check->span_id, &span); if (span && span->channel_request) { - status = span->channel_request(span, check->physical_chan_id, direction, caller_data, zchan); + status = span->channel_request(span, check->chan_id, direction, caller_data, zchan); break; } @@ -1209,7 +1209,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_directio if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); *zchan = NULL; - return ZAP_FAIL; + return ZAP_FAIL; } zap_span_channel_use_count(span, &count); From cf57d7bb0bb16ecd70dabee63e816b5d12466ade Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 9 Jan 2010 17:29:52 +0000 Subject: [PATCH 1667/1766] fix build breakage from r951 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@953 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 25 +++++++++---------- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 4 +-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index cfbf065b06..d773970fb5 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -269,6 +269,18 @@ #pragma warning(disable:4127) #endif +#define zap_set_state_locked_wait(obj, s) \ + do { \ + int __safety = 100; \ + zap_set_state_locked(obj, s); \ + while(__safety-- && zap_test_flag(obj, ZAP_CHANNEL_STATE_CHANGE)) { \ + zap_sleep(10); \ + } \ + if(!__safety) { \ + zap_log(ZAP_LOG_CRIT, "State change not completed\n"); \ + } \ + } while(0); + #define zap_wait_for_flag_cleared(obj, flag, time) \ do { \ int __safety = time; \ @@ -288,19 +300,6 @@ zap_wait_for_flag_cleared(obj, ZAP_CHANNEL_STATE_CHANGE, 100); \ } while(0); -#define zap_set_state_locked_wait(obj, s) \ - do { \ - int __safety = 100; \ - zap_set_state_locked(obj, s); \ - while(__safety-- && zap_test_flag(obj, ZAP_CHANNEL_STATE_CHANGE)) { \ - zap_sleep(10); \ - } \ - if(!__safety) { \ - zap_log(ZAP_LOG_CRIT, "State change not completed\n"); \ - } \ - } while(0); - - typedef enum { ZAP_STATE_CHANGE_FAIL, 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 index 4c4caffb9b..98e00f809b 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -626,7 +626,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco int r = 0; assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); - zchan->call_data = (void*)event->event_id; + 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); @@ -992,7 +992,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - if (zchan->call_data && ((uint32_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) { + 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, From 3ee4713670c8208c854774fa58c761f027509d0e Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 12 Jan 2010 17:52:17 +0000 Subject: [PATCH 1668/1766] Fix for pthread_condtimedwait failing occasionally git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@954 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/zap_threadmutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 0d15cadaa1..edf7d3391c 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -309,7 +309,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) waitms.tv_nsec = 1000*(t.tv_usec + (1000 * ( ms % 1000 ))); - if (waitms.tv_nsec > ONE_BILLION) { + if (waitms.tv_nsec >= ONE_BILLION) { waitms.tv_sec++; waitms.tv_nsec-= ONE_BILLION; } @@ -322,6 +322,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) if (res == ETIMEDOUT) { return ZAP_TIMEOUT; } + zap_log(ZAP_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res); return ZAP_FAIL; } From d6d344974d4a2c5db4da2b034d3f13a408bae599 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 12 Jan 2010 18:09:55 +0000 Subject: [PATCH 1669/1766] fix group configuration bug git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@955 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 2 +- libs/freetdm/src/zap_io.c | 6 ++---- libs/freetdm/src/zap_threadmutex.c | 8 +------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 3042d8e817..9d8120d0fb 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -1103,7 +1103,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (zstatus == ZAP_SUCCESS && group) { group_id = group->group_id; } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing zap span or group: %s\n", span_name); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 567c7aff40..445fb7094f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -2827,9 +2827,7 @@ static zap_status_t load_config(void) } } else if (!strcasecmp(var, "b-channel")) { configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); - if (zap_group_add_channels(group_name, span, val) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to add channels (%d:%s) to group\n", number, val); - } + zap_group_add_channels(group_name, span, val); } else if (!strcasecmp(var, "d-channel")) { if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); @@ -2855,7 +2853,7 @@ static zap_status_t load_config(void) len = sizeof(group_name) - 1; zap_log(ZAP_LOG_WARNING, "Truncating group name %s to %zd length\n", val, len); } - zap_copy_string(group_name, val, len); + memcpy(group_name, val, len); group_name[len] = '\0'; } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index edf7d3391c..bae288c561 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -300,20 +300,14 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) int res = 0; if (ms > 0) { struct timeval t; - struct timespec waitms; - gettimeofday(&t, NULL); - waitms.tv_sec = t.tv_sec + ( ms / 1000 ); - waitms.tv_nsec = 1000*(t.tv_usec + (1000 * ( ms % 1000 ))); - if (waitms.tv_nsec >= ONE_BILLION) { waitms.tv_sec++; - waitms.tv_nsec-= ONE_BILLION; + waitms.tv_nsec -= ONE_BILLION; } - res = pthread_cond_timedwait(&condition->condition, &condition->mutex->mutex, &waitms); } else { res = pthread_cond_wait(&condition->condition, &condition->mutex->mutex); From b11682a956b19e9182eb5c623d2a9a7f278dad30 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 12 Jan 2010 22:39:20 +0000 Subject: [PATCH 1670/1766] Fix for CALL_STOPPED_ACK sent too early in case where both sides of the link hang-up simultaneously git-svn-id: http://svn.openzap.org/svn/openzap/trunk@956 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) 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 index 98e00f809b..89a34eaa42 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -189,7 +189,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even break; } else { zchan = NULL; - zap_log(ZAP_LOG_ERROR, "Channel %d:%d ~ %d:%d is already in use.\n", + 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, @@ -736,6 +736,8 @@ static void handle_call_answer(zap_span_t *span, sangomabc_connection_t *mcon, s } } +static __inline__ void advance_chan_states(zap_channel_t *zchan); + /** * \brief Handler for call start event * \param span Span where event was fired @@ -747,10 +749,19 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_channel_t *zchan; if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { - goto error; + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { + zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); + goto error; + } + advance_chan_states(zchan); + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { + zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\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; } @@ -788,8 +799,9 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa return; error: - - zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + if (!zchan) { + zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + } sangomabc_exec_command(mcon, event->span, @@ -1125,6 +1137,17 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } +static __inline__ void advance_chan_states(zap_channel_t *zchan) +{ + zap_mutex_lock(zchan->mutex); + 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); + } + zap_mutex_unlock(zchan->mutex); +} + /** * \brief Initialises outgoing requests array */ From e9e0edb33f3df2028137b11e808d8016852ee88f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 13 Jan 2010 17:53:22 +0000 Subject: [PATCH 1671/1766] merged revision 938:956 from openzap/trunk git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@959 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_openzap/mod_openzap.c | 30 ++++--- libs/freetdm/src/include/openzap.h | 27 ++++--- .../freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 7 ++ libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 4 +- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 81 +++++++++++-------- libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h | 2 +- 6 files changed, 96 insertions(+), 55 deletions(-) diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_openzap/mod_openzap.c index 9d8120d0fb..6d283eaf3f 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_openzap/mod_openzap.c @@ -817,50 +817,57 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - + assert(tech_pvt->zchan != NULL); + + zap_mutex_lock(tech_pvt->zchan->mutex); + if (tech_pvt->zchan->state == ZAP_CHANNEL_STATE_TERMINATING) { + zap_mutex_unlock(tech_pvt->zchan->mutex); + return SWITCH_STATUS_SUCCESS; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); } else { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } } break; case SWITCH_MESSAGE_INDICATE_PROGRESS: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); } else { /* Don't skip messages in the ISDN call setup * TODO: make the isdn stack smart enough to handle that itself * until then, this is here for safety... */ if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } } break; case SWITCH_MESSAGE_INDICATE_ANSWER: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); } else { /* Don't skip messages in the ISDN call setup * TODO: make the isdn stack smart enough to handle that itself * until then, this is here for safety... */ if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); } if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); } - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); } } break; @@ -868,6 +875,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, break; } + zap_mutex_unlock(tech_pvt->zchan->mutex); return SWITCH_STATUS_SUCCESS; } diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 15996fd64c..7281684afc 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -280,6 +280,7 @@ extern "C" { /* The while(0) below throws a conditional expression is constant warning */ #pragma warning(disable:4127) #endif + #define zap_set_state_locked_wait(obj, s) \ do { \ int __safety = 100; \ @@ -292,17 +293,31 @@ extern "C" { } \ } while(0); -#define zap_locked_wait_for_flag_cleared(obj, flag, time) \ +#define zap_wait_for_flag_cleared(obj, flag, time) \ do { \ int __safety = time; \ - while(__safety-- && zap_test_flag(obj, flag)) { \ + while(__safety-- && zap_test_flag(obj, flag)) { \ + zap_mutex_unlock(obj->mutex); \ zap_sleep(10); \ + zap_mutex_lock(obj->mutex); \ } \ if(!__safety) { \ - zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ + zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ } \ } while(0); +#define zap_set_state_wait(obj, s) \ + do { \ + zap_channel_set_state(obj, s, 0); \ + zap_wait_for_flag_cleared(obj, ZAP_CHANNEL_STATE_CHANGE, 100); \ + } while(0); + + +typedef enum { + ZAP_STATE_CHANGE_FAIL, + ZAP_STATE_CHANGE_SUCCESS, + ZAP_STATE_CHANGE_SAME, +} zap_state_change_result_t; #define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ @@ -324,12 +339,6 @@ extern "C" { */ #define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) -typedef enum { - ZAP_STATE_CHANGE_FAIL, - ZAP_STATE_CHANGE_SUCCESS, - ZAP_STATE_CHANGE_SAME, -} zap_state_change_result_t; - struct zap_stream_handle { zap_stream_handle_write_function_t write_function; zap_stream_handle_raw_write_function_t raw_write_function; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index f703c86f93..d927610668 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -31,6 +31,13 @@ * 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" diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c index 8000aa2a64..acc2de62a1 100644 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -165,7 +165,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(r2_outgoing_call) zap_mutex_lock(zchan->mutex); /* the channel may be down but the thread not quite done */ - zap_locked_wait_for_flag_cleared(zchan, ZAP_CHANNEL_INTHREAD, 200); + 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", @@ -216,7 +216,7 @@ static void zap_r2_on_call_init(openr2_chan_t *r2chan) } /* the channel may be down but the thread not quite done */ - zap_locked_wait_for_flag_cleared(zchan, ZAP_CHANNEL_INTHREAD, 200); + 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", diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 59f6f8ecdc..4d8581f806 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -222,7 +222,7 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even break; } else { zchan = NULL; - zap_log(ZAP_LOG_ERROR, "Channel %d:%d ~ %d:%d is already in use.\n", + 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, @@ -699,9 +699,11 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco 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_CANCEL, 0, r); + 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; } @@ -753,6 +755,7 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); + zap_mutex_unlock(zchan->mutex); return; } else { zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); @@ -809,6 +812,8 @@ static void handle_call_answer(zap_span_t *span, sangomabc_connection_t *mcon, s } } +static __inline__ void advance_chan_states(zap_channel_t *zchan); + /** * \brief Handler for call start event * \param span Span where event was fired @@ -820,10 +825,19 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_channel_t *zchan; if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { - goto error; + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { + zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); + goto error; + } + advance_chan_states(zchan); + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { + zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\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; } @@ -866,9 +880,6 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa return; error: - - zap_log(ZAP_LOG_CRIT, "START CANT FIND A CHAN %d:%d\n", event->span,event->chan); - sangomabc_exec_command(mcon, event->span, event->chan, @@ -978,9 +989,7 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s } assert(event->call_setup_id <= MAX_REQ_ID); - switch(event->event_id) { - case SIGBOOST_EVENT_CALL_START: handle_call_start(span, mcon, (sangomabc_event_t*)event); break; @@ -990,7 +999,7 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s case SIGBOOST_EVENT_CALL_START_ACK: handle_call_start_ack(mcon, event); break; - case SIGBOOST_EVENT_CALL_PROGRESS: + case SIGBOOST_EVENT_CALL_PROGRESS: handle_call_progress(mcon, event); break; case SIGBOOST_EVENT_CALL_START_NACK: @@ -1072,14 +1081,25 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), - 0, - SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); + 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); + + } else { + sangomabc_exec_command(mcon, + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0); + } } zchan->sflags = 0; + zchan->call_data = NULL; zap_channel_done(zchan); } break; @@ -1183,20 +1203,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; - case ZAP_CHANNEL_STATE_CANCEL: - { - sig.event_id = ZAP_SIGEVENT_STOP; - status = sangoma_boost_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), - 0, - SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); - } - break; case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; @@ -1208,6 +1214,17 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } +static __inline__ void advance_chan_states(zap_channel_t *zchan) +{ + zap_mutex_lock(zchan->mutex); + 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); + } + zap_mutex_unlock(zchan->mutex); +} + /** * \brief Initialises outgoing requests array */ @@ -1710,7 +1727,7 @@ static zap_state_map_t boost_state_map = { ZSD_INBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_RING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_PROGRESS, ZAP_CHANNEL_STATE_PROGRESS_MEDIA,ZAP_END} }, { ZSD_INBOUND, @@ -1721,14 +1738,14 @@ static zap_state_map_t boost_state_map = { { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, + {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_CANCEL, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, 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, diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h index f82cf0ff10..687269a983 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h @@ -242,7 +242,7 @@ 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_HARDHDLC = ((1 << 19) | ZT_SIG_CLEAR), } zt_sigtype_t; typedef enum { From 200b25e256bd8f2ab901846b4145101833878759 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 14 Jan 2010 05:23:40 +0000 Subject: [PATCH 1672/1766] added new boost msg EVENT_CALL_RELEASED to fix race condition on call hangup git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@960 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 64 +++++++++++++++---- .../sangoma_boost_client.c | 15 +++-- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 13 ++++ libs/freetdm/src/zap_io.c | 33 ++++++---- 4 files changed, 92 insertions(+), 33 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 4d8581f806..cc85b0bfee 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -451,8 +451,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) nack_map[r] = 1; if (sangoma_boost_data->sigmod) { sangomabc_exec_command(&sangoma_boost_data->mcon, - (*zchan)->physical_span_id, - (*zchan)->physical_chan_id, + BOOST_SPAN((*zchan)), + BOOST_CHAN((*zchan)), r, SIGBOOST_EVENT_CALL_START_NACK, 0); @@ -616,10 +616,22 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san { zap_channel_t *zchan; int r = 0; - + if ((zchan = find_zchan(span, event, 1))) { + zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; zap_mutex_lock(zchan->mutex); + if (sangoma_boost_data->sigmod) { + /* not really completely done, but if we ever get an incoming call before moving to HANGUP_COMPLETE + * handle_incoming_call() will take care of moving the state machine to release the channel */ + sangomabc_exec_command(&sangoma_boost_data->mcon, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), + 0, + SIGBOOST_EVENT_CALL_RELEASED, + 0); + } + if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state == ZAP_CHANNEL_STATE_HANGUP_COMPLETE) { goto done; } @@ -729,6 +741,18 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco #endif } +static void handle_call_released(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_log(ZAP_LOG_DEBUG, "Releasing completely chan s%dc%d\n", event->span, event->chan); + zap_channel_done(zchan); + } else { + zap_log(ZAP_LOG_ERROR, "Odd, We could not find chan: s%dc%d to release the call completely!!\n", event->span, event->chan); + } +} + /** * \brief Handler for call stop event * \param span Span where event was fired @@ -773,10 +797,10 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san 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); + } else { /* we have to do it ourselves.... */ + zap_log(ZAP_LOG_ERROR, "Odd, We could not find chan: s%dc%d\n", event->span, event->chan); + release_request_id_span_chan(event->span, event->chan); + } } /** @@ -829,6 +853,9 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); goto error; } + /* this handles race conditions where state handlers are still pending to be executed for finished calls + but an incoming call arrives first, we must complete the channel states and then try again to get the + zap channel */ advance_chan_states(zchan); if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\n", event->span+1,event->chan+1); @@ -996,6 +1023,9 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s case SIGBOOST_EVENT_CALL_STOPPED: handle_call_stop(span, mcon, event); break; + case SIGBOOST_EVENT_CALL_RELEASED: + handle_call_released(span, mcon, event); + break; case SIGBOOST_EVENT_CALL_START_ACK: handle_call_start_ack(mcon, event); break; @@ -1070,6 +1100,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) switch (zchan->state) { case ZAP_CHANNEL_STATE_DOWN: { + int call_stopped_ack_sent = 0; + zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; if (zchan->extra_id) { zchan->extra_id = 0; } @@ -1083,24 +1115,32 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); } else { + /* we got a call stop msg, time to reply with call stopped ack */ sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); + call_stopped_ack_sent = 1; } } zchan->sflags = 0; zchan->call_data = NULL; - zap_channel_done(zchan); + if (sangoma_boost_data->sigmod && call_stopped_ack_sent) { + /* we dont want to call zap_channel_done just yet until call released is received */ + zap_log(ZAP_LOG_DEBUG, "Waiting for call release confirmation before declaring chan %d:%d as available \n", + zchan->span_id, zchan->chan_id); + } else { + zap_channel_done(zchan); + } } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 9e332d1504..ebd27cccac 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -60,6 +60,7 @@ static struct sangomabc_map sangomabc_table[] = { {SIGBOOST_EVENT_CALL_ANSWERED, "CALL_ANSWERED"}, {SIGBOOST_EVENT_CALL_STOPPED, "CALL_STOPPED"}, {SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"}, + {SIGBOOST_EVENT_CALL_RELEASED, "CALL_RELEASED"}, {SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"}, {SIGBOOST_EVENT_SYSTEM_RESTART_ACK, "SYSTEM_RESTART_ACK"}, {SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"}, @@ -457,7 +458,13 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t event->fseqno = mcon->txseq++; } event->bseqno = mcon->rxseq; - event->version = SIGBOOST_VERSION; + event->version = SIGBOOST_VERSION; + + 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); + } if (mcon->sigmod) { mcon->sigmod->write_msg(mcon->span, event, event_size); @@ -473,12 +480,6 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t zap_assert_return(err == event_size, -1, "Failed to send the boost message completely!"); - 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; } diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h index 9e97e9014d..b9cbf110f6 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -28,6 +28,19 @@ enum e_sigboost_event_id_values SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/ SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/ SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ + /* CALL_RELEASED is aimed to fix a race condition that became obvious + * when the boost socket was replaced by direct function calls + * and the channel hunting was moved to openzap, the problem is + * we can get CALL_STOPPED msg and reply with CALL_STOPPED_ACK + * but the signaling module will still (in PRI) send RELEASE and + * wait for RELEASE_COMPLETE from the isdn network before + * marking the channel as available, therefore openzap should + * 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. + * */ + SIGBOOST_EVENT_CALL_RELEASED = 0x51, /* 81 */ SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ SIGBOOST_EVENT_CALL_PROGRESS = 0x50, /*decimal 80*/ diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index 445fb7094f..6a39c9fc70 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -1507,22 +1507,24 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) { assert(zchan != NULL); + zap_mutex_lock(zchan->mutex); + memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_WINK); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_FLASH); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_3WAY); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_MEDIA); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_ANSWERED); + zap_clear_flag(zchan, ZAP_CHANNEL_INUSE); + zap_clear_flag(zchan, ZAP_CHANNEL_OUTBOUND); + zap_clear_flag(zchan, ZAP_CHANNEL_WINK); + zap_clear_flag(zchan, ZAP_CHANNEL_FLASH); + zap_clear_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); + zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); + zap_clear_flag(zchan, ZAP_CHANNEL_OFFHOOK); + zap_clear_flag(zchan, ZAP_CHANNEL_RINGING); + zap_clear_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_3WAY); + zap_clear_flag(zchan, ZAP_CHANNEL_PROGRESS); + zap_clear_flag(zchan, ZAP_CHANNEL_MEDIA); + zap_clear_flag(zchan, ZAP_CHANNEL_ANSWERED); zap_mutex_lock(zchan->pre_buffer_mutex); zap_buffer_destroy(&zchan->pre_buffer); zchan->pre_buffer_size = 0; @@ -1530,8 +1532,11 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; + zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); + zap_mutex_unlock(zchan->mutex); + return ZAP_SUCCESS; } From baec5f24a87f1ce89b3cd53647cc7273c5ea4792 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 14:59:53 +0000 Subject: [PATCH 1673/1766] updated todo git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@961 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/BOOST.limitations | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations index 6da43bae34..6e382ae897 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations @@ -4,12 +4,14 @@ any openzap span using sigboost must have only channels belonging to the corresponding physical span. + This is the reason we added group functionality in openzap core, furthermore, previous groups in openzap + were only possible through adding of b-channels to a single span, but this forces the user to create groups + of channels only whithin the same type of trunk among other things. + - all spans must be configured and then started, cannot configure, start, configure start etc this is due to netborder telesoft abstraction. that requires configuring everything and then starting everything at once. -- just per-span hunting for now. We must remove the hunting from sigmods and delegate to ozmod_sangoma_boost - - sangoma_prid and sangoma_brid on Windows had to be compiled hacking make/Makefile.platform to comment all VC runtime checks, otherwise when running in debug mode exceptions are thrown due to loss of data ie short to char conversions. @@ -20,10 +22,6 @@ - move all logging calls to macro-based logging to log the file name and line in sangoma prid -- add zap_span_get_signaling_status that will check the overall span signaling status - -- fix segfault on unload of mod_openzap, probably due to threads in smgprid not being stopped - - remove FORCE_SEGFAULT from sangoma_sprid and check if there is anything like that in sangoma_brid we should be using zap_assert or zap_assert_return which will abort depending on the openzap crash policy From f8ff3eaaaf3e637576a12e664e464d7dc21e39f3 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 17:06:20 +0000 Subject: [PATCH 1674/1766] added boostrap script git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@962 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/bootstrap | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 libs/freetdm/bootstrap diff --git a/libs/freetdm/bootstrap b/libs/freetdm/bootstrap new file mode 100755 index 0000000000..8ca4856832 --- /dev/null +++ b/libs/freetdm/bootstrap @@ -0,0 +1,6 @@ +#!/bin/bash +autoheader +libtoolize --force --copy +aclocal +automake -f --copy --add-missing +autoconf From 9f155821081fc06aa0d34feebc0733ffe2a529ae Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 17:06:46 +0000 Subject: [PATCH 1675/1766] added ozrename.sh script git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@963 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/ozrename.sh | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 libs/freetdm/ozrename.sh diff --git a/libs/freetdm/ozrename.sh b/libs/freetdm/ozrename.sh new file mode 100755 index 0000000000..6f61983122 --- /dev/null +++ b/libs/freetdm/ozrename.sh @@ -0,0 +1,73 @@ +# renaming main header and build file +move="cp -r" +$move src/include/openzap.h src/include/freetdm.h +$move openzap.pc.in freetdm.pc.in +$move mod_openzap/mod_openzap.c mod_openzap/mod_freetdm.c +$move mod_openzap mod_freetdm + +# rename anything ozmod to ftmod, including directories first +mkdir -p src/ftmod +for file in `find ./ -name *ozmod_* -type d` +do + $move $file ${file//ozmod/ftmod} +done +$move ozmod ftmod + +# move ozmod c files +for file in `find ./ -name *ozmod_*.c` +do + $move $file ${file//ozmod/ftmod} +done + +# move ozmod h files +for file in `find ./ -name *ozmod_*.h` +do + $move $file ${file//ozmod/ftmod} +done + +# renaming other files +for file in `find ./ -name *zap_*.c` +do + $move $file ${file//zap_/ftdm_} +done + +for file in `find ./ -name *zap_*.h` +do + $move $file ${file//zap_/ftdm_} +done + +# replace full openzap occurences first (handles openzap.h, libopenzap etc) +find ./ -name *.c -exec sed -i 's,openzap,freetdm,g' {} \; + +find ./ -name *.h -exec sed -i 's,openzap,freetdm,g' {} \; + +sed -i 's,openzap,freetdm,g' Makefile.am + +sed -i 's,openzap,freetdm,g' configure.ac + +# replace inside files +find ./ -name *.c -exec sed -i 's,oz,ft,g' {} \; +find ./ -name *.c -exec sed -i 's,OZ,FT,g' {} \; +find ./ -name *.c -exec sed -i 's,zap,ftdm,g' {} \; +find ./ -name *.c -exec sed -i 's,ZAP,FTDM,g' {} \; +find ./ -name *.c -exec sed -i 's,zchan,ftdmchan,g' {} \; + +find ./ -name *.h -exec sed -i 's,oz,ft,g' {} \; +find ./ -name *.h -exec sed -i 's,OZ,FT,g' {} \; +find ./ -name *.h -exec sed -i 's,zap,ftdm,g' {} \; +find ./ -name *.h -exec sed -i 's,ZAP,FTDM,g' {} \; +find ./ -name *.h -exec sed -i 's,zchan,ftdmchan,g' {} \; + +sed -i 's,oz,ft,g' Makefile.am +sed -i 's,OZ,FT,g' Makefile.am +sed -i 's,zap,ftdm,g' Makefile.am +sed -i 's,ZAP,FTDM,g' Makefile.am +sed -i 's,zchan,ftdmchan,g' Makefile.am + +sed -i 's,oz,ft,g' configure.ac +sed -i 's,OZ,FT,g' configure.ac +sed -i 's,zap,ftdm,g' configure.ac +sed -i 's,ZAP,FTDM,g' configure.ac +sed -i 's,zchan,ftdmchan,g' configure.ac + + From f5804eae8e22f77149eb84bcd9de243629cc5c2f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 17:08:24 +0000 Subject: [PATCH 1676/1766] updated ozrename git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@964 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/ozrename.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/ozrename.sh b/libs/freetdm/ozrename.sh index 6f61983122..80e716aca4 100755 --- a/libs/freetdm/ozrename.sh +++ b/libs/freetdm/ozrename.sh @@ -1,17 +1,16 @@ # renaming main header and build file -move="cp -r" +move="mv" $move src/include/openzap.h src/include/freetdm.h $move openzap.pc.in freetdm.pc.in $move mod_openzap/mod_openzap.c mod_openzap/mod_freetdm.c $move mod_openzap mod_freetdm # rename anything ozmod to ftmod, including directories first -mkdir -p src/ftmod +$move ozmod ftmod for file in `find ./ -name *ozmod_* -type d` do $move $file ${file//ozmod/ftmod} done -$move ozmod ftmod # move ozmod c files for file in `find ./ -name *ozmod_*.c` From f45c87f61f80596232f89d5f1941385e21cb4071 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 17:10:23 +0000 Subject: [PATCH 1677/1766] updated ozrename.sh git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@965 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/ozrename.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/ozrename.sh b/libs/freetdm/ozrename.sh index 80e716aca4..0b22539993 100755 --- a/libs/freetdm/ozrename.sh +++ b/libs/freetdm/ozrename.sh @@ -6,7 +6,7 @@ $move mod_openzap/mod_openzap.c mod_openzap/mod_freetdm.c $move mod_openzap mod_freetdm # rename anything ozmod to ftmod, including directories first -$move ozmod ftmod +$move src/ozmod src/ftmod for file in `find ./ -name *ozmod_* -type d` do $move $file ${file//ozmod/ftmod} From 0346bc76cc2fc64c7943c48adcd09454a2456e42 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 18:15:15 +0000 Subject: [PATCH 1678/1766] updated ozrename.sh git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@966 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/ozrename.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/freetdm/ozrename.sh b/libs/freetdm/ozrename.sh index 0b22539993..575e6b0cba 100755 --- a/libs/freetdm/ozrename.sh +++ b/libs/freetdm/ozrename.sh @@ -44,6 +44,8 @@ sed -i 's,openzap,freetdm,g' Makefile.am sed -i 's,openzap,freetdm,g' configure.ac +sed -i 's,openzap,freetdm,g' mod_freetdm/Makefile.in + # replace inside files find ./ -name *.c -exec sed -i 's,oz,ft,g' {} \; find ./ -name *.c -exec sed -i 's,OZ,FT,g' {} \; @@ -69,4 +71,9 @@ sed -i 's,zap,ftdm,g' configure.ac sed -i 's,ZAP,FTDM,g' configure.ac sed -i 's,zchan,ftdmchan,g' configure.ac +sed -i 's,oz,ft,g' mod_freetdm/Makefile.in +sed -i 's,OZ,FT,g' mod_freetdm/Makefile.in +sed -i 's,zap,ftdm,g' mod_freetdm/Makefile.in +sed -i 's,ZAP,FTDM,g' mod_freetdm/Makefile.in +sed -i 's,zchan,ftdmchan,g' mod_freetdm/Makefile.in From 900f1ed2efdeb162116319a0281923cc8756c2e7 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 19:22:49 +0000 Subject: [PATCH 1679/1766] Linux renaming from openzap to freetdm git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@967 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/Makefile.am | 180 +- libs/freetdm/configure.ac | 24 +- libs/freetdm/{openzap.pc.in => freetdm.pc.in} | 0 libs/freetdm/mod_freetdm/Makefile.in | 23 + .../mod_freetdm.c} | 852 ++-- .../mod_openzap.2005.vcproj | 0 .../mod_openzap.2008.vcproj | 0 libs/freetdm/mod_openzap/Makefile.in | 23 - libs/freetdm/ozrename.sh | 54 +- libs/freetdm/src/detect_dtmf.c | 2 +- libs/freetdm/src/detect_tones.c | 2 +- libs/freetdm/src/fsk.c | 14 +- .../src/{zap_buffer.c => ftdm_buffer.c} | 86 +- .../src/{zap_callerid.c => ftdm_callerid.c} | 106 +- .../src/{zap_config.c => ftdm_config.c} | 38 +- libs/freetdm/src/{zap_dso.c => ftdm_dso.c} | 26 +- libs/freetdm/src/ftdm_io.c | 3754 +++++++++++++++++ libs/freetdm/src/{zap_m3ua.c => ftdm_m3ua.c} | 284 +- .../freetdm/src/{zap_queue.c => ftdm_queue.c} | 130 +- .../{zap_threadmutex.c => ftdm_threadmutex.c} | 162 +- .../ftmod_analog/ftdm_analog.h} | 22 +- .../src/ftmod/ftmod_analog/ftmod_analog.c | 977 +++++ .../ftmod_analog}/ozmod_analog.2005.vcproj | 0 .../ftmod_analog}/ozmod_analog.2008.vcproj | 0 .../ftmod_analog_em/ftdm_analog_em.h} | 16 +- .../ftmod/ftmod_analog_em/ftmod_analog_em.c | 709 ++++ .../ozmod_analog_em.2005.vcproj | 0 .../ozmod_analog_em.2008.vcproj | 0 .../ftmod_isdn/ftdm_isdn.h} | 48 +- .../ftmod_isdn/ftmod_isdn.c} | 1120 ++--- .../ftmod_isdn}/ozmod_isdn.2005.vcproj | 0 .../ftmod_isdn}/ozmod_isdn.2008.vcproj | 0 .../ftmod_libpri/ftmod_libpri.c} | 662 +-- .../ftmod_libpri/ftmod_libpri.h} | 38 +- .../ftmod_libpri}/lpwrap_pri.c | 40 +- .../ftmod_libpri}/lpwrap_pri.h | 8 +- .../ftmod_pika/ftdm_pika.h} | 6 +- .../ftmod_pika/ftmod_pika.c} | 620 +-- .../ftmod_pika}/ozmod_pika.2005.vcproj | 0 .../ftmod_pika}/ozmod_pika.2008.vcproj | 0 libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c | 1367 ++++++ .../ftmod_sangoma_boost}/BOOST.limitations | 0 .../ftmod_sangoma_boost/ftdm_sangoma_boost.h} | 28 +- .../ftmod_sangoma_boost.c} | 1088 ++--- .../ozmod_sangoma_boost.2008.vcproj | 0 .../sangoma_boost_client.c | 84 +- .../sangoma_boost_client.h | 10 +- .../sangoma_boost_interface.h | 102 +- .../ftmod_sangoma_boost}/sigboost.h | 6 +- .../ftmod_skel/ftmod_skel.c} | 38 +- .../ftmod_wanpipe/ftmod_wanpipe.c} | 500 +-- .../ftmod_wanpipe}/ozmod_wanpipe.2005.vcproj | 0 .../ftmod_wanpipe}/ozmod_wanpipe.2008.vcproj | 0 .../ftmod_wanpipe}/wanpipe_tdm_api_iface.h | 0 .../ozmod_zt.c => ftmod/ftmod_zt/ftmod_zt.c} | 588 +-- .../ozmod_zt.h => ftmod/ftmod_zt/ftmod_zt.h} | 14 +- libs/freetdm/src/hashtable.c | 40 +- libs/freetdm/src/hashtable_itr.c | 6 +- libs/freetdm/src/include/hashtable.h | 20 +- libs/freetdm/src/include/libteletone.h | 8 +- libs/freetdm/src/include/libteletone_detect.h | 4 +- libs/freetdm/src/include/openzap.h | 932 ---- libs/freetdm/src/include/zap_buffer.h | 154 - libs/freetdm/src/include/zap_config.h | 145 - libs/freetdm/src/include/zap_dso.h | 51 - libs/freetdm/src/include/zap_m3ua.h | 134 - libs/freetdm/src/include/zap_threadmutex.h | 67 - libs/freetdm/src/include/zap_types.h | 703 --- libs/freetdm/src/isdn/Q921.c | 4 +- libs/freetdm/src/libteletone_generate.c | 10 +- libs/freetdm/src/m3ua_client.c | 40 +- libs/freetdm/src/m3ua_client.h | 6 +- .../src/ozmod/ozmod_analog/ozmod_analog.c | 977 ----- .../ozmod/ozmod_analog_em/ozmod_analog_em.c | 709 ---- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 1367 ------ libs/freetdm/src/priserver.c | 56 +- libs/freetdm/src/sangoma_pri.c | 18 +- libs/freetdm/src/sangoma_pri.h | 2 +- libs/freetdm/src/testanalog.c | 76 +- libs/freetdm/src/testapp.c | 40 +- libs/freetdm/src/testboost.c | 34 +- libs/freetdm/src/testcid.c | 50 +- libs/freetdm/src/testisdn.c | 28 +- libs/freetdm/src/testm3ua.c | 32 +- libs/freetdm/src/testpri.c | 70 +- libs/freetdm/src/testr2.c | 42 +- libs/freetdm/src/testsangomaboost.c | 34 +- libs/freetdm/src/testtones.c | 2 +- libs/freetdm/src/uart.c | 6 +- libs/freetdm/src/zap_io.c | 3754 ----------------- 90 files changed, 10653 insertions(+), 12819 deletions(-) rename libs/freetdm/{openzap.pc.in => freetdm.pc.in} (100%) create mode 100644 libs/freetdm/mod_freetdm/Makefile.in rename libs/freetdm/{mod_openzap/mod_openzap.c => mod_freetdm/mod_freetdm.c} (74%) rename libs/freetdm/{mod_openzap => mod_freetdm}/mod_openzap.2005.vcproj (100%) rename libs/freetdm/{mod_openzap => mod_freetdm}/mod_openzap.2008.vcproj (100%) delete mode 100644 libs/freetdm/mod_openzap/Makefile.in rename libs/freetdm/src/{zap_buffer.c => ftdm_buffer.c} (71%) rename libs/freetdm/src/{zap_callerid.c => ftdm_callerid.c} (61%) rename libs/freetdm/src/{zap_config.c => ftdm_config.c} (77%) rename libs/freetdm/src/{zap_dso.c => ftdm_dso.c} (80%) create mode 100644 libs/freetdm/src/ftdm_io.c rename libs/freetdm/src/{zap_m3ua.c => ftdm_m3ua.c} (62%) rename libs/freetdm/src/{zap_queue.c => ftdm_queue.c} (50%) rename libs/freetdm/src/{zap_threadmutex.c => ftdm_threadmutex.c} (59%) rename libs/freetdm/src/{ozmod/ozmod_analog/zap_analog.h => ftmod/ftmod_analog/ftdm_analog.h} (84%) create mode 100644 libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c rename libs/freetdm/src/{ozmod/ozmod_analog => ftmod/ftmod_analog}/ozmod_analog.2005.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_analog => ftmod/ftmod_analog}/ozmod_analog.2008.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_analog_em/zap_analog_em.h => ftmod/ftmod_analog_em/ftdm_analog_em.h} (87%) create mode 100644 libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c rename libs/freetdm/src/{ozmod/ozmod_analog_em => ftmod/ftmod_analog_em}/ozmod_analog_em.2005.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_analog_em => ftmod/ftmod_analog_em}/ozmod_analog_em.2008.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_isdn/zap_isdn.h => ftmod/ftmod_isdn/ftdm_isdn.h} (69%) rename libs/freetdm/src/{ozmod/ozmod_isdn/ozmod_isdn.c => ftmod/ftmod_isdn/ftmod_isdn.c} (55%) rename libs/freetdm/src/{ozmod/ozmod_isdn => ftmod/ftmod_isdn}/ozmod_isdn.2005.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_isdn => ftmod/ftmod_isdn}/ozmod_isdn.2008.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_libpri/ozmod_libpri.c => ftmod/ftmod_libpri/ftmod_libpri.c} (51%) rename libs/freetdm/src/{ozmod/ozmod_libpri/ozmod_libpri.h => ftmod/ftmod_libpri/ftmod_libpri.h} (76%) rename libs/freetdm/src/{ozmod/ozmod_libpri => ftmod/ftmod_libpri}/lpwrap_pri.c (85%) rename libs/freetdm/src/{ozmod/ozmod_libpri => ftmod/ftmod_libpri}/lpwrap_pri.h (95%) rename libs/freetdm/src/{ozmod/ozmod_pika/zap_pika.h => ftmod/ftmod_pika/ftdm_pika.h} (98%) rename libs/freetdm/src/{ozmod/ozmod_pika/ozmod_pika.c => ftmod/ftmod_pika/ftmod_pika.c} (67%) rename libs/freetdm/src/{ozmod/ozmod_pika => ftmod/ftmod_pika}/ozmod_pika.2005.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_pika => ftmod/ftmod_pika}/ozmod_pika.2008.vcproj (100%) create mode 100644 libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost => ftmod/ftmod_sangoma_boost}/BOOST.limitations (100%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h => ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h} (81%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c => ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c} (51%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost => ftmod/ftmod_sangoma_boost}/ozmod_sangoma_boost.2008.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost => ftmod/ftmod_sangoma_boost}/sangoma_boost_client.c (82%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost => ftmod/ftmod_sangoma_boost}/sangoma_boost_client.h (98%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost => ftmod/ftmod_sangoma_boost}/sangoma_boost_interface.h (66%) rename libs/freetdm/src/{ozmod/ozmod_sangoma_boost => ftmod/ftmod_sangoma_boost}/sigboost.h (97%) rename libs/freetdm/src/{ozmod/ozmod_skel/ozmod_skel.c => ftmod/ftmod_skel/ftmod_skel.c} (88%) rename libs/freetdm/src/{ozmod/ozmod_wanpipe/ozmod_wanpipe.c => ftmod/ftmod_wanpipe/ftmod_wanpipe.c} (58%) rename libs/freetdm/src/{ozmod/ozmod_wanpipe => ftmod/ftmod_wanpipe}/ozmod_wanpipe.2005.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_wanpipe => ftmod/ftmod_wanpipe}/ozmod_wanpipe.2008.vcproj (100%) rename libs/freetdm/src/{ozmod/ozmod_wanpipe => ftmod/ftmod_wanpipe}/wanpipe_tdm_api_iface.h (100%) rename libs/freetdm/src/{ozmod/ozmod_zt/ozmod_zt.c => ftmod/ftmod_zt/ftmod_zt.c} (52%) rename libs/freetdm/src/{ozmod/ozmod_zt/ozmod_zt.h => ftmod/ftmod_zt/ftmod_zt.h} (97%) delete mode 100644 libs/freetdm/src/include/openzap.h delete mode 100644 libs/freetdm/src/include/zap_buffer.h delete mode 100644 libs/freetdm/src/include/zap_config.h delete mode 100644 libs/freetdm/src/include/zap_dso.h delete mode 100644 libs/freetdm/src/include/zap_m3ua.h delete mode 100644 libs/freetdm/src/include/zap_threadmutex.h delete mode 100644 libs/freetdm/src/include/zap_types.h delete mode 100644 libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c delete mode 100644 libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c delete mode 100644 libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c delete mode 100644 libs/freetdm/src/zap_io.c diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am index 770291e461..5f829b6614 100644 --- a/libs/freetdm/Makefile.am +++ b/libs/freetdm/Makefile.am @@ -36,11 +36,11 @@ moddir = @modinstdir@ libdir = @libdir@ library_includedir = $(PREFIX)/include -INCS = -I$(OZ_SRCDIR)/$(SRC)/include -I$(OZ_SRCDIR)/$(SRC)/isdn/include +INCS = -I$(FT_SRCDIR)/$(SRC)/include -I$(FT_SRCDIR)/$(SRC)/isdn/include if HAVE_SCTP -INCS += -I$(OZ_SRCDIR)/$(SRC)/ozmod/ozmod_sangoma_boost +INCS += -I$(FT_SRCDIR)/$(SRC)/ftmod/ftmod_sangoma_boost endif -MY_CFLAGS = $(INCS) $(ZAP_CFLAGS) -DZAP_CONFIG_DIR=\"@confdir@\" -DZAP_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ +MY_CFLAGS = $(INCS) $(FTDM_CFLAGS) -DFTDM_CONFIG_DIR=\"@confdir@\" -DFTDM_MOD_DIR=\"$(moddir)\" @COMP_VENDOR_CFLAGS@ @DEFS@ COMPILE = $(CC) $(MY_CFLAGS) $(INCS) LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(COMPILE) LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ @@ -49,30 +49,30 @@ LINK = $(LIBTOOL) --mode=link --tag=CC $(CC) $(MY_CFLAGS) $(LDFLAGS) -o $@ # # GNU pkgconfig file # -EXTRA_DIST = openzap.pc.in +EXTRA_DIST = freetdm.pc.in pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = openzap.pc +pkgconfig_DATA = freetdm.pc # -# libopenzap +# libfreetdm # -libopenzap_la_SOURCES = \ +libfreetdm_la_SOURCES = \ $(SRC)/hashtable.c \ $(SRC)/hashtable_itr.c \ -$(SRC)/zap_io.c \ -$(SRC)/zap_queue.c \ -$(SRC)/zap_config.c \ -$(SRC)/zap_callerid.c \ +$(SRC)/ftdm_io.c \ +$(SRC)/ftdm_queue.c \ +$(SRC)/ftdm_config.c \ +$(SRC)/ftdm_callerid.c \ $(SRC)/fsk.c \ $(SRC)/uart.c \ $(SRC)/g711.c \ $(SRC)/libteletone_detect.c \ $(SRC)/libteletone_generate.c \ -$(SRC)/zap_buffer.c \ -$(SRC)/zap_threadmutex.c \ -$(SRC)/zap_dso.c +$(SRC)/ftdm_buffer.c \ +$(SRC)/ftdm_threadmutex.c \ +$(SRC)/ftdm_dso.c library_include_HEADERS = \ $(SRC)/include/fsk.h \ @@ -83,23 +83,23 @@ $(SRC)/include/hashtable_private.h \ $(SRC)/include/libteletone_detect.h \ $(SRC)/include/libteletone_generate.h \ $(SRC)/include/libteletone.h \ -$(SRC)/include/openzap.h \ +$(SRC)/include/freetdm.h \ $(SRC)/include/sangoma_tdm_api.h \ $(SRC)/include/uart.h \ -$(SRC)/include/zap_buffer.h \ -$(SRC)/include/zap_config.h \ -$(SRC)/include/zap_threadmutex.h \ -$(SRC)/include/zap_dso.h \ -$(SRC)/include/zap_types.h +$(SRC)/include/ftdm_buffer.h \ +$(SRC)/include/ftdm_config.h \ +$(SRC)/include/ftdm_threadmutex.h \ +$(SRC)/include/ftdm_dso.h \ +$(SRC)/include/ftdm_types.h -lib_LTLIBRARIES = libopenzap.la -libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -libopenzap_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) -libopenzap_la_LIBADD = $(LIBS) +lib_LTLIBRARIES = libfreetdm.la +libfreetdm_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +libfreetdm_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) +libfreetdm_la_LIBADD = $(LIBS) -MYLIB = libopenzap.la +MYLIB = libfreetdm.la -core: libopenzap.la +core: libfreetdm.la core-install: install-libLTLIBRARIES # @@ -112,91 +112,91 @@ endif noinst_PROGRAMS += testsangomaboost testapp_SOURCES = $(SRC)/testapp.c -testapp_LDADD = libopenzap.la +testapp_LDADD = libfreetdm.la testapp_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testcid_SOURCES = $(SRC)/testcid.c -testcid_LDADD = libopenzap.la +testcid_LDADD = libfreetdm.la testcid_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testtones_SOURCES = $(SRC)/testtones.c -testtones_LDADD = libopenzap.la +testtones_LDADD = libfreetdm.la testtones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) detect_tones_SOURCES = $(SRC)/detect_tones.c -detect_tones_LDADD = libopenzap.la +detect_tones_LDADD = libfreetdm.la detect_tones_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) detect_dtmf_SOURCES = $(SRC)/detect_dtmf.c -detect_dtmf_LDADD = libopenzap.la +detect_dtmf_LDADD = libfreetdm.la detect_dtmf_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testisdn_SOURCES = $(SRC)/testisdn.c -testisdn_LDADD = libopenzap.la +testisdn_LDADD = libfreetdm.la testisdn_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testpri_SOURCES = $(SRC)/testpri.c -testpri_LDADD = libopenzap.la +testpri_LDADD = libfreetdm.la testpri_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testr2_SOURCES = $(SRC)/testr2.c -testr2_LDADD = libopenzap.la +testr2_LDADD = libfreetdm.la testr2_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) if HAVE_SCTP testboost_SOURCES = $(SRC)/testboost.c -testboost_LDADD = libopenzap.la +testboost_LDADD = libfreetdm.la testboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) endif testsangomaboost_SOURCES = $(SRC)/testsangomaboost.c -testsangomaboost_LDADD = libopenzap.la +testsangomaboost_LDADD = libfreetdm.la testsangomaboost_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) testanalog_SOURCES = $(SRC)/testanalog.c -testanalog_LDADD = libopenzap.la +testanalog_LDADD = libfreetdm.la testanalog_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) # -# ozmod modules +# ftmod modules # -mod_LTLIBRARIES = ozmod_zt.la ozmod_skel.la ozmod_isdn.la ozmod_analog.la ozmod_analog_em.la +mod_LTLIBRARIES = ftmod_zt.la ftmod_skel.la ftmod_isdn.la ftmod_analog.la ftmod_analog_em.la if HAVE_SCTP -mod_LTLIBRARIES += ozmod_sangoma_boost.la +mod_LTLIBRARIES += ftmod_sangoma_boost.la endif if LIBSANGOMA -mod_LTLIBRARIES += ozmod_wanpipe.la +mod_LTLIBRARIES += ftmod_wanpipe.la endif if LIBPRI -mod_LTLIBRARIES += ozmod_libpri.la +mod_LTLIBRARIES += ftmod_libpri.la endif if OPENR2 -mod_LTLIBRARIES += ozmod_r2.la +mod_LTLIBRARIES += ftmod_r2.la endif -ozmod_zt_la_SOURCES = $(SRC)/ozmod/ozmod_zt/ozmod_zt.c -ozmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_zt_la_LDFLAGS = -module -avoid-version -ozmod_zt_la_LIBADD = $(MYLIB) +ftmod_zt_la_SOURCES = $(SRC)/ftmod/ftmod_zt/ftmod_zt.c +ftmod_zt_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_zt_la_LDFLAGS = -module -avoid-version +ftmod_zt_la_LIBADD = $(MYLIB) -ozmod_skel_la_SOURCES = $(SRC)/ozmod/ozmod_skel/ozmod_skel.c -ozmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_skel_la_LDFLAGS = -module -avoid-version -ozmod_skel_la_LIBADD = $(MYLIB) +ftmod_skel_la_SOURCES = $(SRC)/ftmod/ftmod_skel/ftmod_skel.c +ftmod_skel_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_skel_la_LDFLAGS = -module -avoid-version +ftmod_skel_la_LIBADD = $(MYLIB) if LIBSANGOMA -ozmod_wanpipe_la_SOURCES = $(SRC)/ozmod/ozmod_wanpipe/ozmod_wanpipe.c -ozmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe -ozmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma -ozmod_wanpipe_la_LIBADD = $(MYLIB) +ftmod_wanpipe_la_SOURCES = $(SRC)/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +ftmod_wanpipe_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D__LINUX__ -I/usr/include/wanpipe +ftmod_wanpipe_la_LDFLAGS = -module -avoid-version -lsangoma +ftmod_wanpipe_la_LIBADD = $(MYLIB) endif -ozmod_isdn_la_SOURCES = \ +ftmod_isdn_la_SOURCES = \ $(SRC)/isdn/EuroISDNStateNT.c \ $(SRC)/isdn/EuroISDNStateTE.c \ $(SRC)/isdn/mfifo.c \ @@ -217,60 +217,60 @@ $(SRC)/isdn/5ESSmes.c \ $(SRC)/isdn/5ESSStateNT.c \ $(SRC)/isdn/5ESSStateTE.c \ $(SRC)/isdn/Q932mes.c \ -$(SRC)/ozmod/ozmod_isdn/ozmod_isdn.c +$(SRC)/ftmod/ftmod_isdn/ftmod_isdn.c -ozmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE -ozmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -avoid-version -ozmod_isdn_la_LIBADD = $(MYLIB) +ftmod_isdn_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -D_GNU_SOURCE +ftmod_isdn_la_LDFLAGS = $(PCAP_LIB_FLAGS) -module -avoid-version +ftmod_isdn_la_LIBADD = $(MYLIB) -ozmod_analog_la_SOURCES = $(SRC)/ozmod/ozmod_analog/ozmod_analog.c -ozmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_analog_la_LDFLAGS = -module -avoid-version -ozmod_analog_la_LIBADD = $(MYLIB) +ftmod_analog_la_SOURCES = $(SRC)/ftmod/ftmod_analog/ftmod_analog.c +ftmod_analog_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_analog_la_LDFLAGS = -module -avoid-version +ftmod_analog_la_LIBADD = $(MYLIB) -ozmod_analog_em_la_SOURCES = $(SRC)/ozmod/ozmod_analog_em/ozmod_analog_em.c -ozmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_analog_em_la_LDFLAGS = -module -avoid-version -ozmod_analog_em_la_LIBADD = $(MYLIB) +ftmod_analog_em_la_SOURCES = $(SRC)/ftmod/ftmod_analog_em/ftmod_analog_em.c +ftmod_analog_em_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_analog_em_la_LDFLAGS = -module -avoid-version +ftmod_analog_em_la_LIBADD = $(MYLIB) if HAVE_SCTP -ozmod_sangoma_boost_la_SOURCES = $(SRC)/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c -ozmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_sangoma_boost_la_LDFLAGS = -module -avoid-version -ozmod_sangoma_boost_la_LIBADD = $(MYLIB) +ftmod_sangoma_boost_la_SOURCES = $(SRC)/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c $(SRC)/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +ftmod_sangoma_boost_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_sangoma_boost_la_LDFLAGS = -module -avoid-version +ftmod_sangoma_boost_la_LIBADD = $(MYLIB) endif if LIBPRI -ozmod_libpri_la_SOURCES = $(SRC)/ozmod/ozmod_libpri/ozmod_libpri.c $(SRC)/ozmod/ozmod_libpri/lpwrap_pri.c -ozmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_libpri_la_LDFLAGS = -module -avoid-version -lpri -ozmod_libpri_la_LIBADD = $(MYLIB) +ftmod_libpri_la_SOURCES = $(SRC)/ftmod/ftmod_libpri/ftmod_libpri.c $(SRC)/ftmod/ftmod_libpri/lpwrap_pri.c +ftmod_libpri_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_libpri_la_LDFLAGS = -module -avoid-version -lpri +ftmod_libpri_la_LIBADD = $(MYLIB) endif if OPENR2 -ozmod_r2_la_SOURCES = $(SRC)/ozmod/ozmod_r2/ozmod_r2.c -ozmod_r2_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) -ozmod_r2_la_LDFLAGS = -module -avoid-version -lopenr2 -ozmod_r2_la_LIBADD = $(MYLIB) +ftmod_r2_la_SOURCES = $(SRC)/ftmod/ftmod_r2/ftmod_r2.c +ftmod_r2_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) +ftmod_r2_la_LDFLAGS = -module -avoid-version -lopenr2 +ftmod_r2_la_LIBADD = $(MYLIB) endif dox doxygen: - cd docs && doxygen $(OZ_SRCDIR)/docs/Doxygen.conf + cd docs && doxygen $(FT_SRCDIR)/docs/Doxygen.conf -mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_openzap/mod_openzap.c - cd mod_openzap && make +mod_freetdm/mod_freetdm.$(DYNAMIC_LIB_EXTEN): $(MYLIB) mod_freetdm/mod_freetdm.c + cd mod_freetdm && make -mod_openzap: mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) +mod_freetdm: mod_freetdm/mod_freetdm.$(DYNAMIC_LIB_EXTEN) -mod_openzap-install: mod_openzap - cd mod_openzap && make install +mod_freetdm-install: mod_freetdm + cd mod_freetdm && make install -mod_openzap-clean: - @if [ -f mod_openzap/mod_openzap.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_openzap && make clean ; fi +mod_freetdm-clean: + @if [ -f mod_freetdm/mod_freetdm.$(DYNAMIC_LIB_EXTEN) ] ; then cd mod_freetdm && make clean ; fi install-data-local: $(mkinstalldirs) $(DESTDIR)$(PREFIX) $(mkinstalldirs) $(DESTDIR)@confdir@ - @[ -f "$(DESTDIR)@confdir@/openzap.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@) - @echo OpenZAP Installed + @[ -f "$(DESTDIR)@confdir@/freetdm.conf" ] || ( cp conf/*.conf $(DESTDIR)@confdir@) + @echo OpenFTDM Installed diff --git a/libs/freetdm/configure.ac b/libs/freetdm/configure.ac index f1bba93f1e..fc141e888e 100644 --- a/libs/freetdm/configure.ac +++ b/libs/freetdm/configure.ac @@ -2,28 +2,28 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([openzap],[pre-alpha],[bugs@freeswitch.org]) -AC_CONFIG_SRCDIR([src/zap_io.c]) +AC_INIT([freetdm],[pre-alpha],[bugs@freeswitch.org]) +AC_CONFIG_SRCDIR([src/ftdm_io.c]) AC_CONFIG_AUX_DIR(build) -AM_INIT_AUTOMAKE(libopenzap,0.1) +AM_INIT_AUTOMAKE(libfreetdm,0.1) # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET AM_PROG_CC_C_O -AC_PREFIX_DEFAULT(/usr/local/openzap) +AC_PREFIX_DEFAULT(/usr/local/freetdm) # AC_PREFIX_DEFAULT does not get expanded until too late so we need to do this to use prefix in this script if test "x$prefix" = "xNONE" ; then - prefix='/usr/local/openzap' + prefix='/usr/local/freetdm' fi # Absolute source/build directory -OZ_SRCDIR=`(cd $srcdir && pwd)` -oz_builddir=`pwd` -AC_SUBST(OZ_SRCDIR) -AC_SUBST(oz_builddir) +FT_SRCDIR=`(cd $srcdir && pwd)` +ft_builddir=`pwd` +AC_SUBST(FT_SRCDIR) +AC_SUBST(ft_builddir) if test "$sysconfdir" = "\${prefix}/etc" ; then confdir="$prefix/conf" @@ -162,7 +162,7 @@ AC_SUBST(modinstdir) # libpri? AC_ARG_WITH([libpri], - [AS_HELP_STRING([--with-libpri], [Install ozmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) + [AS_HELP_STRING([--with-libpri], [Install ftmod_libpri])], [enable_libpri="yes"], [enable_libpri="no"]) AC_SUBST(enable_libpri) AC_CHECK_LIB([sangoma], [sangoma_span_chan_toif], [have_libsangoma="yes"]) @@ -176,6 +176,6 @@ AM_CONDITIONAL([OPENR2],[test "${have_openr2}" = "yes"]) COMP_VENDOR_CFLAGS="$COMP_VENDOR_CFLAGS" AC_SUBST(COMP_VENDOR_CFLAGS) AC_CONFIG_FILES([Makefile - openzap.pc - mod_openzap/Makefile]) + freetdm.pc + mod_freetdm/Makefile]) AC_OUTPUT diff --git a/libs/freetdm/openzap.pc.in b/libs/freetdm/freetdm.pc.in similarity index 100% rename from libs/freetdm/openzap.pc.in rename to libs/freetdm/freetdm.pc.in diff --git a/libs/freetdm/mod_freetdm/Makefile.in b/libs/freetdm/mod_freetdm/Makefile.in new file mode 100644 index 0000000000..ceea0dfbba --- /dev/null +++ b/libs/freetdm/mod_freetdm/Makefile.in @@ -0,0 +1,23 @@ +FT_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ + +BASE=../../.. +FT_DIR=.. +VERBOSE=1 +FTLA=$(FT_DIR)/libfreetdm.la +LOCAL_CFLAGS=-I$(FT_DIR)/src/include -I$(FT_DIR)/src/isdn/include $(FT_CFLAGS) +LOCAL_LDFLAGS=-L$(FT_DIR) -lfreetdm +include $(BASE)/build/modmake.rules + +local_depend: $(FTLA) + +$(FTLA): $(FT_DIR)/.update + cd $(FT_DIR) && $(MAKE) + +local_install: + cd $(FT_DIR) && $(MAKE) install + [ -f $(DESTDIR)@confdir@/autoload_configs/freetdm.conf.xml ] || cp -f $(FT_DIR)/conf/freetdm.conf.xml $(DESTDIR)@confdir@/autoload_configs + +local_clean: + cd $(FT_DIR) && $(MAKE) clean + + diff --git a/libs/freetdm/mod_openzap/mod_openzap.c b/libs/freetdm/mod_freetdm/mod_freetdm.c similarity index 74% rename from libs/freetdm/mod_openzap/mod_openzap.c rename to libs/freetdm/mod_freetdm/mod_freetdm.c index 6d283eaf3f..f2676ef6c7 100644 --- a/libs/freetdm/mod_openzap/mod_openzap.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -4,10 +4,10 @@ * * Version: MPL 1.1 * - * The contents of this file are subject to the Mozilla Public License Version + * The contents of this file are subject to the Mftilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * http://www.mftilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License @@ -27,24 +27,24 @@ * Moises Silva * * - * mod_openzap.c -- OPENZAP Endpoint Module + * mod_freetdm.c -- OPENFTDM Endpoint Module * */ #include -#include "openzap.h" +#include "freetdm.h" #ifndef __FUNCTION__ #define __FUNCTION__ __SWITCH_FUNC__ #endif -#define OPENZAP_VAR_PREFIX "openzap_" -#define OPENZAP_VAR_PREFIX_LEN 8 +#define OPENFTDM_VAR_PREFIX "freetdm_" +#define OPENFTDM_VAR_PREFIX_LEN 8 -SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); -SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); -SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); +SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load); +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_freetdm_shutdown); +SWITCH_MODULE_DEFINITION(mod_freetdm, mod_freetdm_load, mod_freetdm_shutdown, NULL); -switch_endpoint_interface_t *openzap_endpoint_interface; +switch_endpoint_interface_t *freetdm_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; @@ -55,7 +55,7 @@ typedef enum { } analog_option_t; struct span_config { - zap_span_t *span; + ftdm_span_t *span; char dialplan[80]; char context[80]; char dial_regex[256]; @@ -65,7 +65,7 @@ struct span_config { analog_option_t analog_options; }; -static struct span_config SPAN_CONFIG[ZAP_MAX_SPANS_INTERFACE] = {{0}}; +static struct span_config SPAN_CONFIG[FTDM_MAX_SPANS_INTERFACE] = {{0}}; typedef enum { TFLAG_IO = (1 << 0), @@ -108,7 +108,7 @@ struct private_object { unsigned short samprate; switch_mutex_t *mutex; switch_mutex_t *flag_mutex; - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; uint32_t wr_error; }; @@ -129,31 +129,31 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); -zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp); -void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); -void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); +ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session_t **sp); +void dump_chan(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); +void dump_chan_xml(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); -static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) +static switch_core_session_t *ftdm_channel_get_session(ftdm_channel_t *channel, int32_t id) { switch_core_session_t *session = NULL; - if (id > ZAP_MAX_TOKENS) { + if (id > FTDM_MAX_TOKENS) { return NULL; } if (!zstr(channel->tokens[id])) { if (!(session = switch_core_session_locate(channel->tokens[id]))) { - zap_channel_clear_token(channel, channel->tokens[id]); + ftdm_channel_clear_token(channel, channel->tokens[id]); } } return session; } -static const char *zap_channel_get_uuid(zap_channel_t *channel, int32_t id) +static const char *ftdm_channel_get_uuid(ftdm_channel_t *channel, int32_t id) { - if (id > ZAP_MAX_TOKENS) { + if (id > FTDM_MAX_TOKENS) { return NULL; } @@ -190,7 +190,7 @@ static void stop_hold(switch_core_session_t *session_a, const char *uuid) } } -static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, const char *uuid, const char *stream) +static void start_hold(ftdm_channel_t *ftdmchan, switch_core_session_t *session_a, const char *uuid, const char *stream) { switch_core_session_t *session; switch_channel_t *channel, *channel_a; @@ -206,7 +206,7 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c if (!strcasecmp(globals.hold_music, "indicate_hold")) { stream = "indicate_hold"; } - if (!strcasecmp(SPAN_CONFIG[zchan->span->span_id].hold_music, "indicate_hold")) { + if (!strcasecmp(SPAN_CONFIG[ftdmchan->span->span_id].hold_music, "indicate_hold")) { stream = "indicate_hold"; } } @@ -216,7 +216,7 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c } if (zstr(stream)) { - stream = SPAN_CONFIG[zchan->span->span_id].hold_music; + stream = SPAN_CONFIG[ftdmchan->span->span_id].hold_music; } if (zstr(stream)) { @@ -244,31 +244,31 @@ static void start_hold(zap_channel_t *zchan, switch_core_session_t *session_a, c } -static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) { +static void cycle_foreground(ftdm_channel_t *ftdmchan, int flash, const char *bcast) { uint32_t i = 0; switch_core_session_t *session; switch_channel_t *channel; private_t *tech_pvt; - for (i = 0; i < zchan->token_count; i++) { - if ((session = zap_channel_get_session(zchan, i))) { + for (i = 0; i < ftdmchan->token_count; i++) { + if ((session = ftdm_channel_get_session(ftdmchan, i))) { const char *buuid; tech_pvt = switch_core_session_get_private(session); channel = switch_core_session_get_channel(session); buuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); - if (zchan->token_count == 1 && flash) { + if (ftdmchan->token_count == 1 && flash) { if (switch_test_flag(tech_pvt, TFLAG_HOLD)) { stop_hold(session, buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); } else { - start_hold(zchan, session, buuid, bcast); + start_hold(ftdmchan, session, buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } } else if (i) { - start_hold(zchan, session, buuid, bcast); + start_hold(ftdmchan, session, buuid, bcast); switch_set_flag_locked(tech_pvt, TFLAG_HOLD); } else { stop_hold(session, buuid); @@ -285,13 +285,13 @@ static void cycle_foreground(zap_channel_t *zchan, int flash, const char *bcast) -static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, zap_channel_t *zchan) +static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, ftdm_channel_t *ftdmchan) { const char *dname = NULL; uint32_t interval = 0, srate = 8000; - zap_codec_t codec; + ftdm_codec_t codec; - tech_pvt->zchan = zchan; + tech_pvt->ftdmchan = ftdmchan; tech_pvt->read_frame.data = tech_pvt->databuf; tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); tech_pvt->cng_frame.data = tech_pvt->cng_databuf; @@ -304,28 +304,28 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses switch_core_session_set_private(session, tech_pvt); tech_pvt->session = session; - if (ZAP_SUCCESS != zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval)) { + if (FTDM_SUCCESS != ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_INTERVAL, &interval)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to retrieve channel interval.\n"); return SWITCH_STATUS_GENERR; } - if (ZAP_SUCCESS != zap_channel_command(zchan, ZAP_COMMAND_GET_CODEC, &codec)) { + if (FTDM_SUCCESS != ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_CODEC, &codec)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to retrieve channel codec.\n"); return SWITCH_STATUS_GENERR; } switch(codec) { - case ZAP_CODEC_ULAW: + case FTDM_CODEC_ULAW: { dname = "PCMU"; } break; - case ZAP_CODEC_ALAW: + case FTDM_CODEC_ALAW: { dname = "PCMA"; } break; - case ZAP_CODEC_SLIN: + case FTDM_CODEC_SLIN: { dname = "L16"; } @@ -392,7 +392,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) globals.calls++; switch_mutex_unlock(globals.mutex); - zap_channel_init(tech_pvt->zchan); + ftdm_channel_init(tech_pvt->ftdmchan); //switch_channel_set_flag(channel, CF_ACCEPT_CNG); @@ -463,43 +463,43 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) assert(tech_pvt != NULL); - zap_channel_clear_token(tech_pvt->zchan, switch_core_session_get_uuid(session)); + ftdm_channel_clear_token(tech_pvt->ftdmchan, switch_core_session_get_uuid(session)); - switch (tech_pvt->zchan->type) { - case ZAP_CHAN_TYPE_FXO: - case ZAP_CHAN_TYPE_EM: - case ZAP_CHAN_TYPE_CAS: + switch (tech_pvt->ftdmchan->type) { + case FTDM_CHAN_TYPE_FXO: + case FTDM_CHAN_TYPE_EM: + case FTDM_CHAN_TYPE_CAS: { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + ftdm_set_state_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } break; - case ZAP_CHAN_TYPE_FXS: + case FTDM_CHAN_TYPE_FXS: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_BUSY && tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - if (tech_pvt->zchan->token_count) { - cycle_foreground(tech_pvt->zchan, 0, NULL); + if (tech_pvt->ftdmchan->state != FTDM_CHANNEL_STATE_BUSY && tech_pvt->ftdmchan->state != FTDM_CHANNEL_STATE_DOWN) { + if (tech_pvt->ftdmchan->token_count) { + cycle_foreground(tech_pvt->ftdmchan, 0, NULL); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + ftdm_set_state_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } } break; - case ZAP_CHAN_TYPE_B: + case FTDM_CHAN_TYPE_B: { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_DOWN) { - if (tech_pvt->zchan->state != ZAP_CHANNEL_STATE_TERMINATING) { - tech_pvt->zchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); - if (tech_pvt->zchan->caller_data.hangup_cause < 1 || tech_pvt->zchan->caller_data.hangup_cause > 127) { - tech_pvt->zchan->caller_data.hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; + if (tech_pvt->ftdmchan->state != FTDM_CHANNEL_STATE_DOWN) { + if (tech_pvt->ftdmchan->state != FTDM_CHANNEL_STATE_TERMINATING) { + tech_pvt->ftdmchan->caller_data.hangup_cause = switch_channel_get_cause_q850(channel); + if (tech_pvt->ftdmchan->caller_data.hangup_cause < 1 || tech_pvt->ftdmchan->caller_data.hangup_cause > 127) { + tech_pvt->ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_DESTINATION_OUT_OF_ORDER; } } - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_HANGUP); + ftdm_set_state_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } break; default: { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled channel type %d for channel %s\n", tech_pvt->zchan->type, + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unhandled channel type %d for channel %s\n", tech_pvt->ftdmchan->type, switch_channel_get_name(channel)); } break; @@ -565,7 +565,7 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s assert(tech_pvt != NULL); tmp[0] = dtmf->digit; - zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, tmp); + ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_SEND_DTMF, tmp); return SWITCH_STATUS_SUCCESS; } @@ -574,10 +574,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - zap_size_t len; - zap_wait_flag_t wflags = ZAP_READ; + ftdm_size_t len; + ftdm_wait_flag_t wflags = FTDM_READ; char dtmf[128] = ""; - zap_status_t status; + ftdm_status_t status; int total_to; int chunk, do_break = 0; @@ -589,12 +589,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->zchan != NULL); + assert(tech_pvt->ftdmchan != NULL); /* Digium Cards sometimes timeout several times in a row here. Yes, we support digium cards, ain't we nice....... 6 double length intervals should compensate */ - chunk = tech_pvt->zchan->effective_interval * 2; + chunk = tech_pvt->ftdmchan->effective_interval * 2; total_to = chunk * 6; if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { @@ -613,12 +613,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (switch_test_flag(tech_pvt, TFLAG_HOLD) || do_break) { - switch_yield(tech_pvt->zchan->effective_interval * 1000); - tech_pvt->cng_frame.datalen = tech_pvt->zchan->packet_len; + switch_yield(tech_pvt->ftdmchan->effective_interval * 1000); + tech_pvt->cng_frame.datalen = tech_pvt->ftdmchan->packet_len; tech_pvt->cng_frame.samples = tech_pvt->cng_frame.datalen; tech_pvt->cng_frame.flags = SFF_CNG; *frame = &tech_pvt->cng_frame; - if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { + if (tech_pvt->ftdmchan->effective_codec == FTDM_CODEC_SLIN) { tech_pvt->cng_frame.samples /= 2; } return SWITCH_STATUS_SUCCESS; @@ -628,14 +628,14 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch goto fail; } - wflags = ZAP_READ; - status = zap_channel_wait(tech_pvt->zchan, &wflags, chunk); + wflags = FTDM_READ; + status = ftdm_channel_wait(tech_pvt->ftdmchan, &wflags, chunk); - if (status == ZAP_FAIL) { + if (status == FTDM_FAIL) { goto fail; } - if (status == ZAP_TIMEOUT) { + if (status == FTDM_TIMEOUT) { if (!switch_test_flag(tech_pvt, TFLAG_HOLD)) { total_to -= chunk; if (total_to <= 0) { @@ -646,12 +646,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch goto top; } - if (!(wflags & ZAP_READ)) { + if (!(wflags & FTDM_READ)) { goto fail; } len = tech_pvt->read_frame.buflen; - if (zap_channel_read(tech_pvt->zchan, tech_pvt->read_frame.data, &len) != ZAP_SUCCESS) { + if (ftdm_channel_read(tech_pvt->ftdmchan, tech_pvt->read_frame.data, &len) != FTDM_SUCCESS) { goto fail; } @@ -659,17 +659,17 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt->read_frame.datalen = (uint32_t)len; tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; - if (tech_pvt->zchan->effective_codec == ZAP_CODEC_SLIN) { + if (tech_pvt->ftdmchan->effective_codec == FTDM_CODEC_SLIN) { tech_pvt->read_frame.samples /= 2; } - if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { + if (ftdm_channel_dequeue_dtmf(tech_pvt->ftdmchan, dtmf, sizeof(dtmf))) { switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; char *p; for (p = dtmf; p && *p; p++) { if (is_dtmf(*p)) { _dtmf.digit = *p; - zap_log(ZAP_LOG_DEBUG, "queue DTMF [%c]\n", *p); + ftdm_log(FTDM_LOG_DEBUG, "queue DTMF [%c]\n", *p); switch_channel_queue_dtmf(channel, &_dtmf); } } @@ -687,10 +687,10 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - zap_size_t len; + ftdm_size_t len; unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0}; - zap_wait_flag_t wflags = ZAP_WRITE; - zap_status_t status; + ftdm_wait_flag_t wflags = FTDM_WRITE; + ftdm_status_t status; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -698,7 +698,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->zchan != NULL); + assert(tech_pvt->ftdmchan != NULL); if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { return SWITCH_STATUS_FALSE; @@ -722,15 +722,15 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } - wflags = ZAP_WRITE; - status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); + wflags = FTDM_WRITE; + status = ftdm_channel_wait(tech_pvt->ftdmchan, &wflags, tech_pvt->ftdmchan->effective_interval * 4); - if (!(wflags & ZAP_WRITE)) { + if (!(wflags & FTDM_WRITE)) { goto fail; } len = frame->datalen; - if (zap_channel_write(tech_pvt->zchan, frame->data, frame->buflen, &len) != ZAP_SUCCESS) { + if (ftdm_channel_write(tech_pvt->ftdmchan, frame->data, frame->buflen, &len) != FTDM_SUCCESS) { if (++tech_pvt->wr_error > 10) { goto fail; } @@ -758,45 +758,45 @@ static switch_status_t channel_receive_message_cas(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - zap_log(ZAP_LOG_DEBUG, "Got Freeswitch message in R2 channel %d [%d]\n", tech_pvt->zchan->physical_chan_id, + ftdm_log(FTDM_LOG_DEBUG, "Got Freeswitch message in R2 channel %d [%d]\n", tech_pvt->ftdmchan->physical_chan_id, msg->message_id); switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_RINGING: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_PROGRESS); } else { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + ftdm_set_state_locked_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } } break; case SWITCH_MESSAGE_INDICATE_PROGRESS: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_MEDIA); } else { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + ftdm_set_state_locked_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); + ftdm_set_state_locked_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); } } break; case SWITCH_MESSAGE_INDICATE_ANSWER: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_ANSWERED); } else { - /* lets make the ozmod_r2 module life easier by moving thru each + /* lets make the ftmod_r2 module life easier by moving thru each * state waiting for completion, clumsy, but does the job */ - if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + if (tech_pvt->ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS) { + ftdm_set_state_locked_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } - if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + if (tech_pvt->ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS_MEDIA) { + ftdm_set_state_locked_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); } - zap_set_state_locked_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + ftdm_set_state_locked_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_UP); } } break; @@ -817,11 +817,11 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->zchan != NULL); + assert(tech_pvt->ftdmchan != NULL); - zap_mutex_lock(tech_pvt->zchan->mutex); - if (tech_pvt->zchan->state == ZAP_CHANNEL_STATE_TERMINATING) { - zap_mutex_unlock(tech_pvt->zchan->mutex); + ftdm_mutex_lock(tech_pvt->ftdmchan->mutex); + if (tech_pvt->ftdmchan->state == FTDM_CHANNEL_STATE_TERMINATING) { + ftdm_mutex_unlock(tech_pvt->ftdmchan->mutex); return SWITCH_STATUS_SUCCESS; } @@ -829,45 +829,45 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, case SWITCH_MESSAGE_INDICATE_RINGING: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); + ftdm_set_flag(tech_pvt->ftdmchan, FTDM_CHANNEL_PROGRESS); } else { - zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + ftdm_set_state_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } } break; case SWITCH_MESSAGE_INDICATE_PROGRESS: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + ftdm_set_flag(tech_pvt->ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_set_flag(tech_pvt->ftdmchan, FTDM_CHANNEL_MEDIA); } else { /* Don't skip messages in the ISDN call setup * TODO: make the isdn stack smart enough to handle that itself * until then, this is here for safety... */ - if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + if (tech_pvt->ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS) { + ftdm_set_state_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } - zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + ftdm_set_state_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); } } break; case SWITCH_MESSAGE_INDICATE_ANSWER: { if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); + ftdm_set_flag(tech_pvt->ftdmchan, FTDM_CHANNEL_ANSWERED); } else { /* Don't skip messages in the ISDN call setup * TODO: make the isdn stack smart enough to handle that itself * until then, this is here for safety... */ - if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS); + if (tech_pvt->ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS) { + ftdm_set_state_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } - if (tech_pvt->zchan->state < ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_PROGRESS_MEDIA); + if (tech_pvt->ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS_MEDIA) { + ftdm_set_state_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); } - zap_set_state_wait(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + ftdm_set_state_wait(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_UP); } } break; @@ -875,7 +875,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, break; } - zap_mutex_unlock(tech_pvt->zchan->mutex); + ftdm_mutex_unlock(tech_pvt->ftdmchan->mutex); return SWITCH_STATUS_SUCCESS; } @@ -894,11 +894,11 @@ static switch_status_t channel_receive_message_fxo(switch_core_session_t *sessio case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: if (switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_ANSWERED); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_MEDIA); } else { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + ftdm_set_state_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_UP); } break; default: @@ -923,10 +923,10 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_ANSWERED); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag_locked(tech_pvt->zchan, ZAP_CHANNEL_MEDIA); - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_UP); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_ANSWERED); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_set_flag_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_MEDIA); + ftdm_set_state_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_UP); switch_channel_mark_answered(channel); } break; @@ -937,7 +937,7 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio !switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_RING_READY) ) { - zap_set_state_locked(tech_pvt->zchan, ZAP_CHANNEL_STATE_RING); + ftdm_set_state_locked(tech_pvt->ftdmchan, FTDM_CHANNEL_STATE_RING); switch_channel_mark_ring_ready(channel); } } @@ -965,35 +965,35 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: if (!switch_channel_test_flag(channel, CF_OUTBOUND)) { - if ((var = switch_channel_get_variable(channel, "openzap_pre_buffer_size"))) { + if ((var = switch_channel_get_variable(channel, "freetdm_pre_buffer_size"))) { int tmp = atoi(var); if (tmp > -1) { - zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); + ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); } } } break; case SWITCH_MESSAGE_INDICATE_UUID_CHANGE: { - zap_channel_replace_token(tech_pvt->zchan, msg->string_array_arg[0], msg->string_array_arg[1]); + ftdm_channel_replace_token(tech_pvt->ftdmchan, msg->string_array_arg[0], msg->string_array_arg[1]); } break; default: break; } - switch (tech_pvt->zchan->type) { - case ZAP_CHAN_TYPE_FXS: - case ZAP_CHAN_TYPE_EM: + switch (tech_pvt->ftdmchan->type) { + case FTDM_CHAN_TYPE_FXS: + case FTDM_CHAN_TYPE_EM: status = channel_receive_message_fxs(session, msg); break; - case ZAP_CHAN_TYPE_FXO: + case FTDM_CHAN_TYPE_FXO: status = channel_receive_message_fxo(session, msg); break; - case ZAP_CHAN_TYPE_B: + case FTDM_CHAN_TYPE_B: status = channel_receive_message_b(session, msg); break; - case ZAP_CHAN_TYPE_CAS: + case FTDM_CHAN_TYPE_CAS: status = channel_receive_message_cas(session, msg); break; default: @@ -1005,7 +1005,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s } -switch_state_handler_table_t openzap_state_handlers = { +switch_state_handler_table_t freetdm_state_handlers = { /*.on_init */ channel_on_init, /*.on_routing */ channel_on_routing, /*.on_execute */ channel_on_execute, @@ -1021,7 +1021,7 @@ switch_state_handler_table_t openzap_state_handlers = { }; -switch_io_routines_t openzap_io_routines = { +switch_io_routines_t freetdm_io_routines = { /*.outgoing_channel */ channel_outgoing_channel, /*.read_frame */ channel_read_frame, /*.write_frame */ channel_write_frame, @@ -1042,12 +1042,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi const char *dest = NULL; char *data = NULL; int span_id = -1, group_id = -1,chan_id = 0; - zap_channel_t *zchan = NULL; + ftdm_channel_t *ftdmchan = NULL; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; char name[128]; - zap_status_t status; - int direction = ZAP_TOP_DOWN; - zap_caller_data_t caller_data = {{ 0 }}; + ftdm_status_t status; + int direction = FTDM_TOP_DOWN; + ftdm_caller_data_t caller_data = {{ 0 }}; char *span_name = NULL; switch_event_header_t *h; char *argv[3]; @@ -1080,9 +1080,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (*argv[1] == 'A') { - direction = ZAP_BOTTOM_UP; + direction = FTDM_BOTTOM_UP; } else if (*argv[1] == 'a') { - direction = ZAP_TOP_DOWN; + direction = FTDM_TOP_DOWN; } else { chan_id = atoi(argv[1]); } @@ -1097,27 +1097,27 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (span_id == -1 && !zstr(span_name)) { - zap_span_t *span; - zap_status_t zstatus = zap_span_find_by_name(span_name, &span); - if (zstatus == ZAP_SUCCESS && span) { + ftdm_span_t *span; + ftdm_status_t zstatus = ftdm_span_find_by_name(span_name, &span); + if (zstatus == FTDM_SUCCESS && span) { span_id = span->span_id; } } if (span_id == -1) { //Look for a group - zap_group_t *group; - zap_status_t zstatus = zap_group_find_by_name(span_name, &group); - if (zstatus == ZAP_SUCCESS && group) { + ftdm_group_t *group; + ftdm_status_t zstatus = ftdm_group_find_by_name(span_name, &group); + if (zstatus == FTDM_SUCCESS && group) { group_id = group->group_id; } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing zap span or group: %s\n", span_name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing ftdm span or group: %s\n", span_name); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } } if (group_id < 0 && chan_id < 0) { - direction = ZAP_BOTTOM_UP; + direction = FTDM_BOTTOM_UP; chan_id = 0; } @@ -1130,18 +1130,18 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (!zstr(dest)) { - zap_set_string(caller_data.ani.digits, dest); + ftdm_set_string(caller_data.ani.digits, dest); } - if ((var = switch_event_get_header(var_event, "openzap_outbound_ton")) || (var = switch_core_get_variable("openzap_outbound_ton"))) { + if ((var = switch_event_get_header(var_event, "freetdm_outbound_ton")) || (var = switch_core_get_variable("freetdm_outbound_ton"))) { if (!strcasecmp(var, "national")) { - caller_data.ani.type = ZAP_TON_NATIONAL; + caller_data.ani.type = FTDM_TON_NATIONAL; } else if (!strcasecmp(var, "international")) { - caller_data.ani.type = ZAP_TON_INTERNATIONAL; + caller_data.ani.type = FTDM_TON_INTERNATIONAL; } else if (!strcasecmp(var, "local")) { - caller_data.ani.type = ZAP_TON_SUBSCRIBER_NUMBER; + caller_data.ani.type = FTDM_TON_SUBSCRIBER_NUMBER; } else if (!strcasecmp(var, "unknown")) { - caller_data.ani.type = ZAP_TON_UNKNOWN; + caller_data.ani.type = FTDM_TON_UNKNOWN; } } else { caller_data.ani.type = outbound_profile->destination_number_ton; @@ -1152,51 +1152,51 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi #if 0 if (!zstr(outbound_profile->rdnis)) { - zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); + ftdm_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); } #endif - zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); - zap_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); + ftdm_set_string(caller_data.cid_name, outbound_profile->caller_id_name); + ftdm_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); if (group_id >= 0) { - status = zap_channel_open_by_group(group_id, direction, &caller_data, &zchan); + status = ftdm_channel_open_by_group(group_id, direction, &caller_data, &ftdmchan); } else if (chan_id) { - status = zap_channel_open(span_id, chan_id, &zchan); + status = ftdm_channel_open(span_id, chan_id, &ftdmchan); } else { - status = zap_channel_open_by_span(span_id, direction, &caller_data, &zchan); + status = ftdm_channel_open_by_span(span_id, direction, &caller_data, &ftdmchan); } - if (status != ZAP_SUCCESS) { + if (status != FTDM_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; } - if ((var = switch_event_get_header(var_event, "openzap_pre_buffer_size"))) { + if ((var = switch_event_get_header(var_event, "freetdm_pre_buffer_size"))) { int tmp = atoi(var); if (tmp > -1) { - zap_channel_command(zchan, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); + ftdm_channel_command(ftdmchan, FTDM_COMMAND_SET_PRE_BUFFER_SIZE, &tmp); } } - zap_channel_clear_vars(zchan); + ftdm_channel_clear_vars(ftdmchan); for (h = var_event->headers; h; h = h->next) { - if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { - char *v = h->name + OPENZAP_VAR_PREFIX_LEN; + if (!strncasecmp(h->name, OPENFTDM_VAR_PREFIX, OPENFTDM_VAR_PREFIX_LEN)) { + char *v = h->name + OPENFTDM_VAR_PREFIX_LEN; if (!zstr(v)) { - zap_channel_add_var(zchan, v, h->value); + ftdm_channel_add_var(ftdmchan, v, h->value); } } } - if ((*new_session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) { + if ((*new_session = switch_core_session_request(freetdm_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) { private_t *tech_pvt; switch_caller_profile_t *caller_profile; switch_channel_t *channel = switch_core_session_get_channel(*new_session); switch_core_session_add_stream(*new_session, NULL); if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { - tech_init(tech_pvt, *new_session, zchan); + tech_init(tech_pvt, *new_session, ftdmchan); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_core_session_destroy(new_session); @@ -1204,13 +1204,13 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", zchan->span_id, zchan->chan_id, dest); + snprintf(name, sizeof(name), "OpenFTDM/%u:%u/%s", ftdmchan->span_id, ftdmchan->chan_id, dest); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); - switch_channel_set_variable(channel, "openzap_span_name", zchan->span->name); - switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", zchan->span_id); - switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", zchan->chan_id); - zchan->caller_data = caller_data; + switch_channel_set_variable(channel, "freetdm_span_name", ftdmchan->span->name); + switch_channel_set_variable_printf(channel, "freetdm_span_number", "%d", ftdmchan->span_id); + switch_channel_set_variable_printf(channel, "freetdm_chan_number", "%d", ftdmchan->chan_id); + ftdmchan->caller_data = caller_data; caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -1218,14 +1218,14 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_state(channel, CS_INIT); - if (zap_channel_add_token(zchan, switch_core_session_get_uuid(*new_session), zchan->token_count) != ZAP_SUCCESS) { + if (ftdm_channel_add_token(ftdmchan, switch_core_session_get_uuid(*new_session), ftdmchan->token_count) != FTDM_SUCCESS) { switch_core_session_destroy(new_session); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; goto fail; } - if (zap_channel_outgoing_call(zchan) != ZAP_SUCCESS) { + if (ftdm_channel_outgoing_call(ftdmchan) != FTDM_SUCCESS) { if (tech_pvt->read_codec.implementation) { switch_core_codec_destroy(&tech_pvt->read_codec); } @@ -1238,22 +1238,22 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - zap_channel_init(zchan); + ftdm_channel_init(ftdmchan); return SWITCH_CAUSE_SUCCESS; } fail: - if (zchan) { - zap_channel_done(zchan); + if (ftdmchan) { + ftdm_channel_done(ftdmchan); } return cause; } -zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t **sp) +ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session_t **sp) { switch_core_session_t *session = NULL; private_t *tech_pvt = NULL; @@ -1262,9 +1262,9 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t *sp = NULL; - if (!(session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) { + if (!(session = switch_core_session_request(freetdm_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); - return ZAP_FAIL; + return FTDM_FAIL; } switch_core_session_add_stream(session, NULL); @@ -1275,7 +1275,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Initilization Error!\n"); switch_core_session_destroy(&session); - return ZAP_FAIL; + return FTDM_FAIL; } *sigmsg->channel->caller_data.collected = '\0'; @@ -1293,7 +1293,7 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t } tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), - "OpenZAP", + "OpenFTDM", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, sigmsg->channel->caller_data.cid_name, sigmsg->channel->caller_data.cid_num.digits, @@ -1315,30 +1315,30 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); } - snprintf(name, sizeof(name), "OpenZAP/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number); + snprintf(name, sizeof(name), "OpenFTDM/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - switch_channel_set_variable(channel, "openzap_span_name", sigmsg->channel->span->name); - switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", sigmsg->channel->span_id); - switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", sigmsg->channel->chan_id); + switch_channel_set_variable(channel, "freetdm_span_name", sigmsg->channel->span->name); + switch_channel_set_variable_printf(channel, "freetdm_span_number", "%d", sigmsg->channel->span_id); + switch_channel_set_variable_printf(channel, "freetdm_chan_number", "%d", sigmsg->channel->chan_id); switch_channel_set_state(channel, CS_INIT); if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n"); switch_core_session_destroy(&session); - return ZAP_FAIL; + return FTDM_FAIL; } - if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS) { + if (ftdm_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != FTDM_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding token\n"); switch_core_session_destroy(&session); - return ZAP_FAIL; + return FTDM_FAIL; } *sp = session; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } @@ -1346,46 +1346,46 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_status_t status; + ftdm_status_t status; - zap_log(ZAP_LOG_DEBUG, "got FXO sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, zap_signal_event2str(sigmsg->event_id)); + ftdm_log(FTDM_LOG_DEBUG, "got FXO sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, ftdm_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { - case ZAP_SIGEVENT_PROGRESS_MEDIA: + case FTDM_SIGEVENT_PROGRESS_MEDIA: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); switch_core_session_rwunlock(session); } } break; - case ZAP_SIGEVENT_STOP: + case FTDM_SIGEVENT_STOP: { - while((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_channel_clear_token(sigmsg->channel, 0); + while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + ftdm_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); - zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } break; - case ZAP_SIGEVENT_UP: + case FTDM_SIGEVENT_UP: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); switch_core_session_rwunlock(session); } } break; - case ZAP_SIGEVENT_START: + case FTDM_SIGEVENT_START: { - status = zap_channel_from_event(sigmsg, &session); - if (status != ZAP_SUCCESS) { - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_DOWN); + status = ftdm_channel_from_event(sigmsg, &session); + if (status != FTDM_SUCCESS) { + ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_DOWN); } } break; @@ -1399,46 +1399,46 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_status_t status = ZAP_SUCCESS; + ftdm_status_t status = FTDM_SUCCESS; - zap_log(ZAP_LOG_DEBUG, "got FXS sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + ftdm_log(FTDM_LOG_DEBUG, "got FXS sig [%s]\n", ftdm_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { - case ZAP_SIGEVENT_UP: + case FTDM_SIGEVENT_UP: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); switch_core_session_rwunlock(session); } } break; - case ZAP_SIGEVENT_PROGRESS: + case FTDM_SIGEVENT_PROGRESS: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); } } break; - case ZAP_SIGEVENT_START: + case FTDM_SIGEVENT_START: { - zap_clear_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); - status = zap_channel_from_event(sigmsg, &session); - if (status != ZAP_SUCCESS) { - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_BUSY); + ftdm_clear_flag_locked(sigmsg->channel, FTDM_CHANNEL_HOLD); + status = ftdm_channel_from_event(sigmsg, &session); + if (status != FTDM_SUCCESS) { + ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_BUSY); } } break; - case ZAP_SIGEVENT_STOP: + case FTDM_SIGEVENT_STOP: { switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; if (sigmsg->channel->token_count) { @@ -1494,28 +1494,28 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } - while((session = zap_channel_get_session(sigmsg->channel, 0))) { + while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); - zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } - zap_channel_clear_token(sigmsg->channel, NULL); + ftdm_channel_clear_token(sigmsg->channel, NULL); } break; - case ZAP_SIGEVENT_ADD_CALL: + case FTDM_SIGEVENT_ADD_CALL: { cycle_foreground(sigmsg->channel, 1, NULL); } break; - case ZAP_SIGEVENT_FLASH: + case FTDM_SIGEVENT_FLASH: { - if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_HOLD) && sigmsg->channel->token_count == 1) { + if (ftdm_test_flag(sigmsg->channel, FTDM_CHANNEL_HOLD) && sigmsg->channel->token_count == 1) { switch_core_session_t *session; - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { const char *buuid; switch_channel_t *channel; private_t *tech_pvt; @@ -1523,25 +1523,25 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) tech_pvt = switch_core_session_get_private(session); channel = switch_core_session_get_channel(session); buuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_UP); + ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_UP); stop_hold(session, buuid); switch_clear_flag_locked(tech_pvt, TFLAG_HOLD); switch_core_session_rwunlock(session); } } else if (sigmsg->channel->token_count == 2 && (SPAN_CONFIG[sigmsg->span_id].analog_options & ANALOG_OPTION_3WAY)) { - if (zap_test_flag(sigmsg->channel, ZAP_CHANNEL_3WAY)) { - zap_clear_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); - if ((session = zap_channel_get_session(sigmsg->channel, 1))) { + if (ftdm_test_flag(sigmsg->channel, FTDM_CHANNEL_3WAY)) { + ftdm_clear_flag(sigmsg->channel, FTDM_CHANNEL_3WAY); + if ((session = ftdm_channel_get_session(sigmsg->channel, 1))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } cycle_foreground(sigmsg->channel, 1, NULL); } else { char *cmd; cmd = switch_mprintf("three_way::%s", sigmsg->channel->tokens[0]); - zap_set_flag(sigmsg->channel, ZAP_CHANNEL_3WAY); + ftdm_set_flag(sigmsg->channel, FTDM_CHANNEL_3WAY); cycle_foreground(sigmsg->channel, 1, cmd); free(cmd); } @@ -1550,15 +1550,15 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) ) { cycle_foreground(sigmsg->channel, 1, NULL); if (sigmsg->channel->token_count == 1) { - zap_set_flag_locked(sigmsg->channel, ZAP_CHANNEL_HOLD); - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_DIALTONE); + ftdm_set_flag_locked(sigmsg->channel, FTDM_CHANNEL_HOLD); + ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_DIALTONE); } } } break; - case ZAP_SIGEVENT_COLLECTED_DIGIT: + case FTDM_SIGEVENT_COLLECTED_DIGIT: { char *dtmf = sigmsg->raw_data; char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; @@ -1572,7 +1572,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) fail_regex = NULL; } - zap_log(ZAP_LOG_DEBUG, "got DTMF sig [%s]\n", dtmf); + ftdm_log(FTDM_LOG_DEBUG, "got DTMF sig [%s]\n", dtmf); switch_set_string(sigmsg->channel->caller_data.collected, dtmf); if ((regex || fail_regex) && !zstr(dtmf)) { @@ -1582,13 +1582,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) if (fail_regex) { match = switch_regex_perform(dtmf, fail_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); - status = match ? ZAP_SUCCESS : ZAP_BREAK; + status = match ? FTDM_SUCCESS : FTDM_BREAK; switch_regex_safe_free(re); } - if (status == ZAP_SUCCESS && regex) { + if (status == FTDM_SUCCESS && regex) { match = switch_regex_perform(dtmf, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); - status = match ? ZAP_BREAK : ZAP_SUCCESS; + status = match ? FTDM_BREAK : FTDM_SUCCESS; } switch_regex_safe_free(re); @@ -1613,32 +1613,32 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_status_t status = ZAP_SUCCESS; + ftdm_status_t status = FTDM_SUCCESS; - zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel %d\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); + ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel %d\n", ftdm_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); switch(sigmsg->event_id) { /* on_call_disconnect from the R2 side */ - case ZAP_SIGEVENT_STOP: + case FTDM_SIGEVENT_STOP: { - while((session = zap_channel_get_session(sigmsg->channel, 0))) { + while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); - zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } break; /* on_call_offered from the R2 side */ - case ZAP_SIGEVENT_START: + case FTDM_SIGEVENT_START: { - status = zap_channel_from_event(sigmsg, &session); + status = ftdm_channel_from_event(sigmsg, &session); } break; - /* on DNIS received from the R2 forward side, return status == ZAP_BREAK to stop requesting DNIS */ - case ZAP_SIGEVENT_COLLECTED_DIGIT: + /* on DNIS received from the R2 forward side, return status == FTDM_BREAK to stop requesting DNIS */ + case FTDM_SIGEVENT_COLLECTED_DIGIT: { char *regex = SPAN_CONFIG[sigmsg->channel->span->span_id].dial_regex; char *fail_regex = SPAN_CONFIG[sigmsg->channel->span->span_id].fail_dial_regex; @@ -1651,7 +1651,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) fail_regex = NULL; } - zap_log(ZAP_LOG_DEBUG, "R2 DNIS so far [%s]\n", sigmsg->channel->caller_data.dnis.digits); + ftdm_log(FTDM_LOG_DEBUG, "R2 DNIS so far [%s]\n", sigmsg->channel->caller_data.dnis.digits); if ((regex || fail_regex) && !zstr(sigmsg->channel->caller_data.dnis.digits)) { switch_regex_t *re = NULL; @@ -1660,13 +1660,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) if (fail_regex) { match = switch_regex_perform(sigmsg->channel->caller_data.dnis.digits, fail_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); - status = match ? ZAP_SUCCESS : ZAP_BREAK; + status = match ? FTDM_SUCCESS : FTDM_BREAK; switch_regex_safe_free(re); } - if (status == ZAP_SUCCESS && regex) { + if (status == FTDM_SUCCESS && regex) { match = switch_regex_perform(sigmsg->channel->caller_data.dnis.digits, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])); - status = match ? ZAP_BREAK : ZAP_SUCCESS; + status = match ? FTDM_BREAK : FTDM_SUCCESS; } switch_regex_safe_free(re); @@ -1674,9 +1674,9 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) } break; - case ZAP_SIGEVENT_PROGRESS: + case FTDM_SIGEVENT_PROGRESS: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); @@ -1684,14 +1684,14 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) } break; - case ZAP_SIGEVENT_UP: + case FTDM_SIGEVENT_UP: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_tone_type_t tt = ZAP_TONE_DTMF; + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + ftdm_tone_type_t tt = FTDM_TONE_DTMF; channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); - if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to enable DTMF detection in R2 channel %d:%d\n", sigmsg->channel->span_id, sigmsg->channel->chan_id); + if (ftdm_channel_command(sigmsg->channel, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Failed to enable DTMF detection in R2 channel %d:%d\n", sigmsg->channel->span_id, sigmsg->channel->chan_id); } switch_core_session_rwunlock(session); } @@ -1714,70 +1714,70 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - zap_log(ZAP_LOG_DEBUG, "got clear channel sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + ftdm_log(FTDM_LOG_DEBUG, "got clear channel sig [%s]\n", ftdm_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { - case ZAP_SIGEVENT_START: + case FTDM_SIGEVENT_START: { - zap_tone_type_t tt = ZAP_TONE_DTMF; + ftdm_tone_type_t tt = FTDM_TONE_DTMF; - if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + if (ftdm_channel_command(sigmsg->channel, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "TONE ERROR\n"); } - return zap_channel_from_event(sigmsg, &session); + return ftdm_channel_from_event(sigmsg, &session); } break; - case ZAP_SIGEVENT_STOP: - case ZAP_SIGEVENT_RESTART: + case FTDM_SIGEVENT_STOP: + case FTDM_SIGEVENT_RESTART: { - while((session = zap_channel_get_session(sigmsg->channel, 0))) { + while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); - zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); + ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); switch_core_session_rwunlock(session); } } break; - case ZAP_SIGEVENT_UP: + case FTDM_SIGEVENT_UP: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { - zap_tone_type_t tt = ZAP_TONE_DTMF; + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + ftdm_tone_type_t tt = FTDM_TONE_DTMF; channel = switch_core_session_get_channel(session); switch_channel_mark_answered(channel); - if (zap_channel_command(sigmsg->channel, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); + if (ftdm_channel_command(sigmsg->channel, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "TONE ERROR\n"); } switch_core_session_rwunlock(session); } else { - const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + const char *uuid = ftdm_channel_get_uuid(sigmsg->channel, 0); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } - case ZAP_SIGEVENT_PROGRESS_MEDIA: + case FTDM_SIGEVENT_PROGRESS_MEDIA: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_pre_answered(channel); switch_core_session_rwunlock(session); } else { - const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + const char *uuid = ftdm_channel_get_uuid(sigmsg->channel, 0); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); } } break; - case ZAP_SIGEVENT_PROGRESS: + case FTDM_SIGEVENT_PROGRESS: { - if ((session = zap_channel_get_session(sigmsg->channel, 0))) { + if ((session = ftdm_channel_get_session(sigmsg->channel, 0))) { channel = switch_core_session_get_channel(session); switch_channel_mark_ring_ready(channel); switch_core_session_rwunlock(session); } else { - const char *uuid = zap_channel_get_uuid(sigmsg->channel, 0); + const char *uuid = ftdm_channel_get_uuid(sigmsg->channel, 0); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Session for channel %d:%d not found [UUID: %s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A"); @@ -1791,7 +1791,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) break; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } @@ -1800,13 +1800,13 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) switch_status_t status = SWITCH_STATUS_FALSE; switch (sigmsg->channel->type) { - case ZAP_CHAN_TYPE_FXO: - case ZAP_CHAN_TYPE_EM: + case FTDM_CHAN_TYPE_FXO: + case FTDM_CHAN_TYPE_EM: { status = on_fxo_signal(sigmsg); } break; - case ZAP_CHAN_TYPE_FXS: + case FTDM_CHAN_TYPE_FXS: { status = on_fxs_signal(sigmsg); } @@ -1822,7 +1822,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) return status; } -static void zap_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) +static void ftdm_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { char *data = NULL; va_list ap; @@ -1854,10 +1854,10 @@ static uint32_t enable_analog_option(const char *str, uint32_t current_options) static switch_status_t load_config(void) { - const char *cf = "openzap.conf"; + const char *cf = "freetdm.conf"; switch_xml_t cfg, xml, settings, param, spans, myspan; - zap_span_t *boost_spans[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN]; - zap_span_t *boost_span = NULL; + ftdm_span_t *boost_spans[FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN]; + ftdm_span_t *boost_span = NULL; unsigned boosti = 0; unsigned int i = 0; @@ -1888,7 +1888,7 @@ static switch_status_t load_config(void) for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); - zap_status_t zstatus = ZAP_FAIL; + ftdm_status_t zstatus = FTDM_FAIL; const char *context = "default"; const char *dialplan = "XML"; const char *tonegroup = NULL; @@ -1901,7 +1901,7 @@ static switch_status_t load_config(void) const char *enable_callerid = "true"; uint32_t span_id = 0, to = 0, max = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { @@ -1953,20 +1953,20 @@ static switch_status_t load_config(void) } if (name) { - zstatus = zap_span_find_by_name(name, &span); + zstatus = ftdm_span_find_by_name(name, &span); } else { if (switch_is_number(id)) { span_id = atoi(id); - zstatus = zap_span_find(span_id, &span); + zstatus = ftdm_span_find(span_id, &span); } - if (zstatus != ZAP_SUCCESS) { - zstatus = zap_span_find_by_name(id, &span); + if (zstatus != FTDM_SUCCESS) { + zstatus = ftdm_span_find_by_name(id, &span); } } - if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + if (zstatus != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1974,14 +1974,14 @@ static switch_status_t load_config(void) span_id = span->span_id; } - if (zap_configure_span("analog", span, on_analog_signal, + if (ftdm_configure_span("analog", span, on_analog_signal, "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, "hotline", hotline, "enable_callerid", enable_callerid, - TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); + TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d\n", span_id); continue; } @@ -2002,7 +2002,7 @@ static switch_status_t load_config(void) switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_span_start(span); + ftdm_span_start(span); } } @@ -2010,7 +2010,7 @@ static switch_status_t load_config(void) for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); - zap_status_t zstatus = ZAP_FAIL; + ftdm_status_t zstatus = FTDM_FAIL; const char *context = "default"; const char *dialplan = "XML"; const char *tonegroup = NULL; @@ -2020,7 +2020,7 @@ static switch_status_t load_config(void) char *hold_music = NULL; char *fail_dial_regex = NULL; uint32_t span_id = 0, to = 0, max = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; analog_option_t analog_options = ANALOG_OPTION_NONE; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { @@ -2068,20 +2068,20 @@ static switch_status_t load_config(void) if (name) { - zstatus = zap_span_find_by_name(name, &span); + zstatus = ftdm_span_find_by_name(name, &span); } else { if (switch_is_number(id)) { span_id = atoi(id); - zstatus = zap_span_find(span_id, &span); + zstatus = ftdm_span_find(span_id, &span); } - if (zstatus != ZAP_SUCCESS) { - zstatus = zap_span_find_by_name(id, &span); + if (zstatus != FTDM_SUCCESS) { + zstatus = ftdm_span_find_by_name(id, &span); } } - if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + if (zstatus != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2090,12 +2090,12 @@ static switch_status_t load_config(void) } - if (zap_configure_span("analog_em", span, on_analog_signal, + if (ftdm_configure_span("analog_em", span, on_analog_signal, "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, - TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d\n", span_id); + TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d\n", span_id); continue; } @@ -2116,7 +2116,7 @@ static switch_status_t load_config(void) switch_set_string(SPAN_CONFIG[span->span_id].hold_music, hold_music); } switch_copy_string(SPAN_CONFIG[span->span_id].type, "analog_em", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_span_start(span); + ftdm_span_start(span); } } @@ -2124,7 +2124,7 @@ static switch_status_t load_config(void) for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); - zap_status_t zstatus = ZAP_FAIL; + ftdm_status_t zstatus = FTDM_FAIL; const char *context = "default"; const char *dialplan = "XML"; //Q921NetUser_t mode = Q931_TE; @@ -2132,7 +2132,7 @@ static switch_status_t load_config(void) char *mode = NULL; char *dialect = NULL; uint32_t span_id = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; const char *tonegroup = NULL; char *digit_timeout = NULL; const char *opts = "none"; @@ -2177,15 +2177,15 @@ static switch_status_t load_config(void) } if (name) { - zstatus = zap_span_find_by_name(name, &span); + zstatus = ftdm_span_find_by_name(name, &span); } else { if (switch_is_number(id)) { span_id = atoi(id); - zstatus = zap_span_find(span_id, &span); + zstatus = ftdm_span_find(span_id, &span); } - if (zstatus != ZAP_SUCCESS) { - zstatus = zap_span_find_by_name(id, &span); + if (zstatus != FTDM_SUCCESS) { + zstatus = ftdm_span_find_by_name(id, &span); } } @@ -2193,8 +2193,8 @@ static switch_status_t load_config(void) to = atoi(digit_timeout); } - if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + if (zstatus != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2206,7 +2206,7 @@ static switch_status_t load_config(void) tonegroup = "us"; } - if (zap_configure_span("isdn", span, on_clear_channel_signal, + if (ftdm_configure_span("isdn", span, on_clear_channel_signal, "mode", mode, "dialect", dialect, "digit_timeout", &to, @@ -2214,8 +2214,8 @@ static switch_status_t load_config(void) "tonemap", tonegroup, "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, - TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d mode: %s dialect: %s error: %s\n", span_id, mode, dialect, span->last_error); + TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d mode: %s dialect: %s error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -2224,7 +2224,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_span_start(span); + ftdm_span_start(span); } } @@ -2234,7 +2234,7 @@ static switch_status_t load_config(void) for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); - zap_status_t zstatus = ZAP_FAIL; + ftdm_status_t zstatus = FTDM_FAIL; const char *context = "default"; const char *dialplan = "XML"; @@ -2246,7 +2246,7 @@ static switch_status_t load_config(void) const char* opts = "none"; uint32_t span_id = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { @@ -2278,20 +2278,20 @@ static switch_status_t load_config(void) } if (name) { - zstatus = zap_span_find_by_name(name, &span); + zstatus = ftdm_span_find_by_name(name, &span); } else { if (switch_is_number(id)) { span_id = atoi(id); - zstatus = zap_span_find(span_id, &span); + zstatus = ftdm_span_find(span_id, &span); } - if (zstatus != ZAP_SUCCESS) { - zstatus = zap_span_find_by_name(id, &span); + if (zstatus != FTDM_SUCCESS) { + zstatus = ftdm_span_find_by_name(id, &span); } } - if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + if (zstatus != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2300,15 +2300,15 @@ static switch_status_t load_config(void) } - if (zap_configure_span("libpri", span, on_clear_channel_signal, + if (ftdm_configure_span("libpri", span, on_clear_channel_signal, "node", o_node, "switch", o_switch, "dp", o_dp, "l1", o_l1, "debug", o_debug, "opts", opts, - TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d node: %s switch: %s dp: %s l1: %s debug: %s error: %s\n", + TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d node: %s switch: %s dp: %s l1: %s debug: %s error: %s\n", span_id, switch_str_nil(o_node), switch_str_nil(o_switch), switch_str_nil(o_dp), switch_str_nil(o_l1), switch_str_nil(o_debug), span->last_error); continue; @@ -2319,7 +2319,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); switch_copy_string(SPAN_CONFIG[span->span_id].type, "isdn", sizeof(SPAN_CONFIG[span->span_id].type)); - zap_span_start(span); + ftdm_span_start(span); } } @@ -2328,17 +2328,17 @@ static switch_status_t load_config(void) char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); char *sigmod = (char *) switch_xml_attr(myspan, "sigmod"); - zap_status_t zstatus = ZAP_FAIL; + ftdm_status_t zstatus = FTDM_FAIL; const char *context = "default"; const char *dialplan = "XML"; uint32_t span_id = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; const char *tonegroup = NULL; - zap_conf_parameter_t spanparameters[30]; + ftdm_conf_parameter_t spanparameters[30]; unsigned paramindex = 0; if (!id && !name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "boost span requires an id or name as attribute: \n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "boost span requires an id or name as attribute: \n"); continue; } memset(spanparameters, 0, sizeof(spanparameters)); @@ -2373,20 +2373,20 @@ static switch_status_t load_config(void) } if (name) { - zstatus = zap_span_find_by_name(name, &span); + zstatus = ftdm_span_find_by_name(name, &span); } else { if (switch_is_number(id)) { span_id = atoi(id); - zstatus = zap_span_find(span_id, &span); + zstatus = ftdm_span_find(span_id, &span); } - if (zstatus != ZAP_SUCCESS) { - zstatus = zap_span_find_by_name(id, &span); + if (zstatus != FTDM_SUCCESS) { + zstatus = ftdm_span_find_by_name(id, &span); } } - if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + if (zstatus != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2394,8 +2394,8 @@ static switch_status_t load_config(void) span_id = span->span_id; } - if (zap_configure_span_signaling("sangoma_boost", span, on_clear_channel_signal, spanparameters) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error starting OpenZAP span %d error: %s\n", span_id, span->last_error); + if (ftdm_configure_span_signaling("sangoma_boost", span, on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d error: %s\n", span_id, span->last_error); continue; } @@ -2412,7 +2412,7 @@ static switch_status_t load_config(void) for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *id = (char *) switch_xml_attr(myspan, "id"); char *name = (char *) switch_xml_attr(myspan, "name"); - zap_status_t zstatus = ZAP_FAIL; + ftdm_status_t zstatus = FTDM_FAIL; /* strings */ const char *variant = "itu"; @@ -2443,7 +2443,7 @@ static switch_status_t load_config(void) char *dial_regex = NULL; char *fail_dial_regex = NULL; uint32_t span_id = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; for (param = switch_xml_child(myspan, "param"); param; param = param->next) { @@ -2508,20 +2508,20 @@ static switch_status_t load_config(void) } if (name) { - zstatus = zap_span_find_by_name(name, &span); + zstatus = ftdm_span_find_by_name(name, &span); } else { if (switch_is_number(id)) { span_id = atoi(id); - zstatus = zap_span_find(span_id, &span); + zstatus = ftdm_span_find(span_id, &span); } - if (zstatus != ZAP_SUCCESS) { - zstatus = zap_span_find_by_name(id, &span); + if (zstatus != FTDM_SUCCESS) { + zstatus = ftdm_span_find_by_name(id, &span); } } - if (zstatus != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + if (zstatus != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2529,7 +2529,7 @@ static switch_status_t load_config(void) span_id = span->span_id; } - if (zap_configure_span("r2", span, on_r2_signal, + if (ftdm_configure_span("r2", span, on_r2_signal, "variant", variant, "max_ani", max_ani, "max_dnis", max_dnis, @@ -2547,8 +2547,8 @@ static switch_status_t load_config(void) "call_files", call_files, "mfback_timeout", mfback_timeout, "metering_pulse_timeout", metering_pulse_timeout, - TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error configuring R2 OpenZAP span %d, error: %s\n", + TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error configuring R2 OpenFTDM span %d, error: %s\n", span_id, span->last_error); continue; } @@ -2566,8 +2566,8 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span->span_id].dialplan)); switch_copy_string(SPAN_CONFIG[span->span_id].type, "r2", sizeof(SPAN_CONFIG[span->span_id].type)); - if (zap_span_start(span) == ZAP_FAIL) { - zap_log(ZAP_LOG_ERROR, "Error starting R2 OpenZAP span %d, error: %s\n", span_id, span->last_error); + if (ftdm_span_start(span) == FTDM_FAIL) { + ftdm_log(FTDM_LOG_ERROR, "Error starting R2 OpenFTDM span %d, error: %s\n", span_id, span->last_error); continue; } } @@ -2577,9 +2577,9 @@ static switch_status_t load_config(void) * of needing all spans to be configured before starting them */ for ( ; i < boosti; i++) { boost_span = boost_spans[i]; - zap_log(ZAP_LOG_DEBUG, "Starting boost span %d\n", boost_span->span_id); - if (zap_span_start(boost_span) == ZAP_FAIL) { - zap_log(ZAP_LOG_ERROR, "Error starting boost OpenZAP span %d, error: %s\n", boost_span->span_id, boost_span->last_error); + ftdm_log(FTDM_LOG_DEBUG, "Starting boost span %d\n", boost_span->span_id); + if (ftdm_span_start(boost_span) == FTDM_FAIL) { + ftdm_log(FTDM_LOG_ERROR, "Error starting boost OpenFTDM span %d, error: %s\n", boost_span->span_id, boost_span->last_error); continue; } } @@ -2591,7 +2591,7 @@ static switch_status_t load_config(void) } -void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) +void dump_chan(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) { if (chan_id > span->chan_count) { return; @@ -2617,9 +2617,9 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea span->channels[chan_id]->chan_id, span->channels[chan_id]->physical_span_id, span->channels[chan_id]->physical_chan_id, - zap_chan_type2str(span->channels[chan_id]->type), - zap_channel_state2str(span->channels[chan_id]->state), - zap_channel_state2str(span->channels[chan_id]->last_state), + ftdm_chan_type2str(span->channels[chan_id]->type), + ftdm_channel_state2str(span->channels[chan_id]->state), + ftdm_channel_state2str(span->channels[chan_id]->last_state), span->channels[chan_id]->caller_data.cid_date, span->channels[chan_id]->caller_data.cid_name, span->channels[chan_id]->caller_data.cid_num.digits, @@ -2631,7 +2631,7 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea ); } -void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) +void dump_chan_xml(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream) { if (chan_id > span->chan_count) { return; @@ -2659,9 +2659,9 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s span->channels[chan_id]->chan_id, span->channels[chan_id]->physical_span_id, span->channels[chan_id]->physical_chan_id, - zap_chan_type2str(span->channels[chan_id]->type), - zap_channel_state2str(span->channels[chan_id]->state), - zap_channel_state2str(span->channels[chan_id]->last_state), + ftdm_chan_type2str(span->channels[chan_id]->type), + ftdm_channel_state2str(span->channels[chan_id]->state), + ftdm_channel_state2str(span->channels[chan_id]->last_state), span->channels[chan_id]->caller_data.cid_date, span->channels[chan_id]->caller_data.cid_name, span->channels[chan_id]->caller_data.cid_num.digits, @@ -2673,8 +2673,8 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s ); } -#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains " -SWITCH_STANDARD_API(oz_function) +#define FT_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains " +SWITCH_STANDARD_API(ft_function) { char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; @@ -2684,20 +2684,20 @@ SWITCH_STANDARD_API(oz_function) } if (!argc) { - stream->write_function(stream, "%s", OZ_SYNTAX); + stream->write_function(stream, "%s", FT_SYNTAX); goto end; } if (!strcasecmp(argv[0], "dump")) { if (argc < 2) { - stream->write_function(stream, "-ERR Usage: oz dump []\n"); + stream->write_function(stream, "-ERR Usage: ft dump []\n"); goto end; } else { uint32_t chan_id = 0; - zap_span_t *span; + ftdm_span_t *span; char *as = NULL; - zap_span_find_by_name(argv[1], &span); + ftdm_span_find_by_name(argv[1], &span); if (argc > 2) { if (argv[3] && !strcasecmp(argv[2], "as")) { @@ -2755,10 +2755,10 @@ SWITCH_STANDARD_API(oz_function) } } else if (!strcasecmp(argv[0], "list")) { int j; - for (j = 0 ; j < ZAP_MAX_SPANS_INTERFACE; j++) { + for (j = 0 ; j < FTDM_MAX_SPANS_INTERFACE; j++) { if (SPAN_CONFIG[j].span) { const char *flags = "none"; - zap_signaling_status_t sigstatus; + ftdm_signaling_status_t sigstatus; if (SPAN_CONFIG[j].analog_options & ANALOG_OPTION_3WAY) { flags = "3way"; @@ -2766,7 +2766,7 @@ SWITCH_STANDARD_API(oz_function) flags = "call swap"; } - if ((ZAP_SUCCESS == zap_span_get_sig_status(SPAN_CONFIG[j].span, &sigstatus))) { + if ((FTDM_SUCCESS == ftdm_span_get_sig_status(SPAN_CONFIG[j].span, &sigstatus))) { stream->write_function(stream, "+OK\n" "span: %u (%s)\n" @@ -2782,7 +2782,7 @@ SWITCH_STANDARD_API(oz_function) j, SPAN_CONFIG[j].span->name, SPAN_CONFIG[j].type, - zap_signaling_status2str(sigstatus), + ftdm_signaling_status2str(sigstatus), SPAN_CONFIG[j].span->chan_count, SPAN_CONFIG[j].dialplan, SPAN_CONFIG[j].context, @@ -2819,11 +2819,11 @@ SWITCH_STANDARD_API(oz_function) } } else if (!strcasecmp(argv[0], "stop") || !strcasecmp(argv[0], "start")) { char *span_name = argv[1]; - zap_span_t *span = NULL; - zap_status_t status; + ftdm_span_t *span = NULL; + ftdm_status_t status; if (span_name) { - zap_span_find_by_name(span_name, &span); + ftdm_span_find_by_name(span_name, &span); } if (!span) { @@ -2832,24 +2832,24 @@ SWITCH_STANDARD_API(oz_function) } if (!strcasecmp(argv[0], "stop")) { - status = zap_span_stop(span); + status = ftdm_span_stop(span); } else { - status = zap_span_start(span); + status = ftdm_span_start(span); } - stream->write_function(stream, status == ZAP_SUCCESS ? "+OK\n" : "-ERR failure\n"); + stream->write_function(stream, status == FTDM_SUCCESS ? "+OK\n" : "-ERR failure\n"); goto end; /*Q931ToPcap enhancement*/ } else if (!strcasecmp(argv[0], "q931_pcap")) { int32_t span_id = 0; - zap_span_t *span; + ftdm_span_t *span; const char *pcapfn = NULL; char *tmp_path = NULL; if (argc < 3) { - stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + stream->write_function(stream, "-ERR Usage: ft q931_pcap on|off [pcapfilename without suffix]\n"); goto end; } span_id = atoi(argv[1]); @@ -2872,21 +2872,21 @@ SWITCH_STANDARD_API(oz_function) tmp_path=switch_mprintf("%s%s%s.pcap", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pcapfn); if(!strcasecmp(argv[2], "on")) { - if (zap_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 1, "pcapfilename", tmp_path, TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_WARNING, "Error couldn't (re-)enable Q931-To-Pcap!\n"); + if (ftdm_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 1, "pcapfilename", tmp_path, TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_WARNING, "Error couldn't (re-)enable Q931-To-Pcap!\n"); goto end; } else { stream->write_function(stream, "+OK\n"); } } else if(!strcasecmp(argv[2], "off")) { - if (zap_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 0, TAG_END) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error couldn't enable Q931-To-Pcap!\n"); + if (ftdm_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 0, TAG_END) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error couldn't enable Q931-To-Pcap!\n"); goto end; } else { stream->write_function(stream, "+OK\n"); } } else { - stream->write_function(stream, "-ERR Usage: oz q931_pcap on|off [pcapfilename without suffix]\n"); + stream->write_function(stream, "-ERR Usage: ft q931_pcap on|off [pcapfilename without suffix]\n"); goto end; } @@ -2895,12 +2895,12 @@ SWITCH_STANDARD_API(oz_function) float txgain = 0.0; float rxgain = 0.0; uint32_t chan_id = 0; - zap_span_t *span = NULL; + ftdm_span_t *span = NULL; if (argc < 4) { - stream->write_function(stream, "-ERR Usage: oz gains []\n"); + stream->write_function(stream, "-ERR Usage: ft gains []\n"); goto end; } - zap_span_find_by_name(argv[3], &span); + ftdm_span_find_by_name(argv[3], &span); if (!span) { stream->write_function(stream, "-ERR invalid span\n"); goto end; @@ -2919,23 +2919,23 @@ SWITCH_STANDARD_API(oz_function) goto end; } if (chan_id) { - zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_RX_GAIN, &rxgain); - zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_TX_GAIN, &txgain); + ftdm_channel_command(span->channels[chan_id], FTDM_COMMAND_SET_RX_GAIN, &rxgain); + ftdm_channel_command(span->channels[chan_id], FTDM_COMMAND_SET_TX_GAIN, &txgain); } else { for (i = 1; i < span->chan_count; i++) { - zap_channel_command(span->channels[i], ZAP_COMMAND_SET_RX_GAIN, &rxgain); - zap_channel_command(span->channels[i], ZAP_COMMAND_SET_TX_GAIN, &txgain); + ftdm_channel_command(span->channels[i], FTDM_COMMAND_SET_RX_GAIN, &rxgain); + ftdm_channel_command(span->channels[i], FTDM_COMMAND_SET_TX_GAIN, &txgain); } } stream->write_function(stream, "+OK gains set to Rx %f and Tx %f\n", rxgain, txgain); } else { - char *rply = zap_api_execute(cmd, NULL); + char *rply = ftdm_api_execute(cmd, NULL); if (rply) { stream->write_function(stream, "%s", rply); free(rply); } else { - stream->write_function(stream, "-ERR Usage: %s\n", OZ_SYNTAX); + stream->write_function(stream, "-ERR Usage: %s\n", FT_SYNTAX); } } /*Q931ToPcap enhancement done*/ @@ -2953,19 +2953,19 @@ SWITCH_STANDARD_APP(disable_ec_function) private_t *tech_pvt; int x = 0; - if (!switch_core_session_check_interface(session, openzap_endpoint_interface)) { - zap_log(ZAP_LOG_ERROR, "This application is only for OpenZAP channels.\n"); + if (!switch_core_session_check_interface(session, freetdm_endpoint_interface)) { + ftdm_log(FTDM_LOG_ERROR, "This application is only for OpenFTDM channels.\n"); return; } tech_pvt = switch_core_session_get_private(session); - zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOCANCEL, &x); - zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOTRAIN, &x); - zap_log(ZAP_LOG_INFO, "Echo Canceller Disabled\n"); + ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_DISABLE_ECHOCANCEL, &x); + ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_DISABLE_ECHOTRAIN, &x); + ftdm_log(FTDM_LOG_INFO, "Echo Canceller Disabled\n"); } -SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) +SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load) { switch_api_interface_t *commands_api_interface; @@ -2973,30 +2973,30 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) module_pool = pool; - zap_global_set_logger(zap_logger); + ftdm_global_set_logger(ftdm_logger); - if (zap_global_init() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error loading OpenFTDM\n"); return SWITCH_STATUS_TERM; } - if (zap_global_configuration() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP\n"); + if (ftdm_global_configuration() != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error configuring OpenFTDM\n"); return SWITCH_STATUS_TERM; } if (load_config() != SWITCH_STATUS_SUCCESS) { - zap_global_destroy(); + ftdm_global_destroy(); return SWITCH_STATUS_TERM; } *module_interface = switch_loadable_module_create_module_interface(pool, modname); - openzap_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); - openzap_endpoint_interface->interface_name = "openzap"; - openzap_endpoint_interface->io_routines = &openzap_io_routines; - openzap_endpoint_interface->state_handler = &openzap_state_handlers; + freetdm_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); + freetdm_endpoint_interface->interface_name = "freetdm"; + freetdm_endpoint_interface->io_routines = &freetdm_io_routines; + freetdm_endpoint_interface->state_handler = &freetdm_state_handlers; - SWITCH_ADD_API(commands_api_interface, "oz", "OpenZAP commands", oz_function, OZ_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "ft", "OpenFTDM commands", ft_function, FT_SYNTAX); SWITCH_ADD_APP(app_interface, "disable_ec", "Disable Echo Canceller", "Disable Echo Canceller", disable_ec_function, "", SAF_NONE); @@ -3004,9 +3004,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) return SWITCH_STATUS_SUCCESS; } -SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown) +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_freetdm_shutdown) { - zap_global_destroy(); + ftdm_global_destroy(); // this breaks pika but they are MIA so *shrug* //return SWITCH_STATUS_NOUNLOAD; diff --git a/libs/freetdm/mod_openzap/mod_openzap.2005.vcproj b/libs/freetdm/mod_freetdm/mod_openzap.2005.vcproj similarity index 100% rename from libs/freetdm/mod_openzap/mod_openzap.2005.vcproj rename to libs/freetdm/mod_freetdm/mod_openzap.2005.vcproj diff --git a/libs/freetdm/mod_openzap/mod_openzap.2008.vcproj b/libs/freetdm/mod_freetdm/mod_openzap.2008.vcproj similarity index 100% rename from libs/freetdm/mod_openzap/mod_openzap.2008.vcproj rename to libs/freetdm/mod_freetdm/mod_openzap.2008.vcproj diff --git a/libs/freetdm/mod_openzap/Makefile.in b/libs/freetdm/mod_openzap/Makefile.in deleted file mode 100644 index 85275d1d8d..0000000000 --- a/libs/freetdm/mod_openzap/Makefile.in +++ /dev/null @@ -1,23 +0,0 @@ -OZ_CFLAGS=@CFLAGS@ @COMP_VENDOR_CFLAGS@ @DEFS@ - -BASE=../../.. -OZ_DIR=.. -VERBOSE=1 -OZLA=$(OZ_DIR)/libopenzap.la -LOCAL_CFLAGS=-I$(OZ_DIR)/src/include -I$(OZ_DIR)/src/isdn/include $(OZ_CFLAGS) -LOCAL_LDFLAGS=-L$(OZ_DIR) -lopenzap -include $(BASE)/build/modmake.rules - -local_depend: $(OZLA) - -$(OZLA): $(OZ_DIR)/.update - cd $(OZ_DIR) && $(MAKE) - -local_install: - cd $(OZ_DIR) && $(MAKE) install - [ -f $(DESTDIR)@confdir@/autoload_configs/openzap.conf.xml ] || cp -f $(OZ_DIR)/conf/openzap.conf.xml $(DESTDIR)@confdir@/autoload_configs - -local_clean: - cd $(OZ_DIR) && $(MAKE) clean - - diff --git a/libs/freetdm/ozrename.sh b/libs/freetdm/ozrename.sh index 575e6b0cba..369be1c3a1 100755 --- a/libs/freetdm/ozrename.sh +++ b/libs/freetdm/ozrename.sh @@ -1,40 +1,57 @@ # renaming main header and build file -move="mv" -$move src/include/openzap.h src/include/freetdm.h -$move openzap.pc.in freetdm.pc.in -$move mod_openzap/mod_openzap.c mod_openzap/mod_freetdm.c -$move mod_openzap mod_freetdm +copy="cp -r" +$copy src/include/openzap.h src/include/freetdm.h +svn delete src/include/openzap.h +$copy openzap.pc.in freetdm.pc.in +svn delete openzap.pc.in + +# create mod_freetdm +mkdir mod_freetdm +cp mod_openzap/* mod_freetdm/ +mv mod_freetdm/mod_openzap.c mod_freetdm/mod_freetdm.c +svn delete --force mod_openzap + + +##### ozmod stuff #### # rename anything ozmod to ftmod, including directories first -$move src/ozmod src/ftmod -for file in `find ./ -name *ozmod_* -type d` +mkdir ./src/ftmod +for file in `find ./src/ozmod -name *ozmod_* -type d` do - $move $file ${file//ozmod/ftmod} + $copy ${file} ${file//ozmod/ftmod} done -# move ozmod c files -for file in `find ./ -name *ozmod_*.c` +#remove .svn directories in the copied ozmod dirs +find ./src/ftmod -name *.svn -exec rm -rf {} \; + +# copy ozmod c files +for file in `find ./src/ftmod -name *ozmod_*.c` do - $move $file ${file//ozmod/ftmod} + mv $file ${file//ozmod/ftmod} done -# move ozmod h files -for file in `find ./ -name *ozmod_*.h` +# copy ozmod h files +for file in `find ./src/ftmod -name *ozmod_*.h` do - $move $file ${file//ozmod/ftmod} + mv $file ${file//ozmod/ftmod} done -# renaming other files +#### end ozmod stuff #### + +# renaming other zap files for file in `find ./ -name *zap_*.c` do - $move $file ${file//zap_/ftdm_} + mv $file ${file//zap_/ftdm_} done for file in `find ./ -name *zap_*.h` do - $move $file ${file//zap_/ftdm_} + mv $file ${file//zap_/ftdm_} done +svn revert -R src/ozmod +svn delete --force src/ozmod + # replace full openzap occurences first (handles openzap.h, libopenzap etc) find ./ -name *.c -exec sed -i 's,openzap,freetdm,g' {} \; @@ -77,3 +94,6 @@ sed -i 's,zap,ftdm,g' mod_freetdm/Makefile.in sed -i 's,ZAP,FTDM,g' mod_freetdm/Makefile.in sed -i 's,zchan,ftdmchan,g' mod_freetdm/Makefile.in +svn add src/ftmod/ +svn add mod_freetdm/ + diff --git a/libs/freetdm/src/detect_dtmf.c b/libs/freetdm/src/detect_dtmf.c index f73586adcb..e7d9648192 100644 --- a/libs/freetdm/src/detect_dtmf.c +++ b/libs/freetdm/src/detect_dtmf.c @@ -1,4 +1,4 @@ -//#include "openzap.h" +//#include "freetdm.h" #include "libteletone_detect.h" int main(int argc, char *argv[]) diff --git a/libs/freetdm/src/detect_tones.c b/libs/freetdm/src/detect_tones.c index 580f6a9d17..5cd52d4d99 100644 --- a/libs/freetdm/src/detect_tones.c +++ b/libs/freetdm/src/detect_tones.c @@ -1,4 +1,4 @@ -//#include "openzap.h" +//#include "freetdm.h" #include "libteletone_detect.h" int main(int argc, char *argv[]) diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index 16a1bcb7d4..60a4722a4c 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -32,7 +32,7 @@ * * 2005 03 20 R. Krten created */ -#include +#include #include #include #include @@ -134,7 +134,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) double phi_mark, phi_space; dsp_fsk_handle_t *handle; - handle = zap_malloc(sizeof(*handle)); + handle = ftdm_malloc(sizeof(*handle)); if (!handle) { return NULL; } @@ -157,7 +157,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { - handle->correlates[i] = zap_malloc(sizeof(double) * handle->corrsize); + handle->correlates[i] = ftdm_malloc(sizeof(double) * handle->corrsize); if (handle->correlates[i] == NULL) { /* some failed, back out memory allocations */ dsp_fsk_destroy(&handle); @@ -177,7 +177,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) } /* initialize the ring buffer */ - handle->buffer = zap_malloc(sizeof(double) * handle->corrsize); + handle->buffer = ftdm_malloc(sizeof(double) * handle->corrsize); if (!handle->buffer) { /* failed; back out memory allocations */ dsp_fsk_destroy(&handle); return NULL; @@ -226,13 +226,13 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle) for (i = 0; i < 4; i++) { if ((*handle)->correlates[i] != NULL) { - zap_safe_free((*handle)->correlates[i]); + ftdm_safe_free((*handle)->correlates[i]); (*handle)->correlates[i] = NULL; } } if ((*handle)->buffer != NULL) { - zap_safe_free((*handle)->buffer); + ftdm_safe_free((*handle)->buffer); (*handle)->buffer = NULL; } @@ -241,7 +241,7 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle) dsp_uart_destroy(dhandle); } - zap_safe_free(*handle); + ftdm_safe_free(*handle); *handle = NULL; } diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/ftdm_buffer.c similarity index 71% rename from libs/freetdm/src/zap_buffer.c rename to libs/freetdm/src/ftdm_buffer.c index 11a7c03d29..2f08e7bbee 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/ftdm_buffer.c @@ -31,37 +31,37 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openzap.h" -#include "zap_buffer.h" +#include "freetdm.h" +#include "ftdm_buffer.h" static unsigned buffer_id = 0; -struct zap_buffer { +struct ftdm_buffer { unsigned char *data; unsigned char *head; - zap_size_t used; - zap_size_t actually_used; - zap_size_t datalen; - zap_size_t max_len; - zap_size_t blocksize; + ftdm_size_t used; + ftdm_size_t actually_used; + ftdm_size_t datalen; + ftdm_size_t max_len; + ftdm_size_t blocksize; unsigned id; int loops; }; -OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len) +FT_DECLARE(ftdm_status_t) ftdm_buffer_create(ftdm_buffer_t **buffer, ftdm_size_t blocksize, ftdm_size_t start_len, ftdm_size_t max_len) { - zap_buffer_t *new_buffer; + ftdm_buffer_t *new_buffer; - new_buffer = zap_malloc(sizeof(*new_buffer)); + new_buffer = ftdm_malloc(sizeof(*new_buffer)); if (new_buffer) { memset(new_buffer, 0, sizeof(*new_buffer)); if (start_len) { - new_buffer->data = zap_malloc(start_len); + new_buffer->data = ftdm_malloc(start_len); if (!new_buffer->data) { - zap_safe_free(new_buffer); - return ZAP_MEMERR; + ftdm_safe_free(new_buffer); + return FTDM_MEMERR; } memset(new_buffer->data, 0, start_len); } @@ -73,13 +73,13 @@ OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blo new_buffer->head = new_buffer->data; *buffer = new_buffer; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return ZAP_MEMERR; + return FTDM_MEMERR; } -OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer) +FT_DECLARE(ftdm_size_t) ftdm_buffer_len(ftdm_buffer_t *buffer) { assert(buffer != NULL); @@ -89,28 +89,28 @@ OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer) } -OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer) +FT_DECLARE(ftdm_size_t) ftdm_buffer_freespace(ftdm_buffer_t *buffer) { assert(buffer != NULL); if (buffer->max_len) { - return (zap_size_t) (buffer->max_len - buffer->used); + return (ftdm_size_t) (buffer->max_len - buffer->used); } return 1000000; } -OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer) +FT_DECLARE(ftdm_size_t) ftdm_buffer_inuse(ftdm_buffer_t *buffer) { assert(buffer != NULL); return buffer->used; } -OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) +FT_DECLARE(ftdm_size_t) ftdm_buffer_seek(ftdm_buffer_t *buffer, ftdm_size_t datalen) { - zap_size_t reading = 0; + ftdm_size_t reading = 0; assert(buffer != NULL); @@ -129,9 +129,9 @@ OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen) return reading; } -OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) +FT_DECLARE(ftdm_size_t) ftdm_buffer_toss(ftdm_buffer_t *buffer, ftdm_size_t datalen) { - zap_size_t reading = 0; + ftdm_size_t reading = 0; assert(buffer != NULL); @@ -150,29 +150,29 @@ OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen) return buffer->used; } -OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int loops) +FT_DECLARE(void) ftdm_buffer_set_loops(ftdm_buffer_t *buffer, int loops) { buffer->loops = loops; } -OZ_DECLARE(zap_size_t) zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen) +FT_DECLARE(ftdm_size_t) ftdm_buffer_read_loop(ftdm_buffer_t *buffer, void *data, ftdm_size_t datalen) { - zap_size_t len; - if ((len = zap_buffer_read(buffer, data, datalen)) < datalen) { + ftdm_size_t len; + if ((len = ftdm_buffer_read(buffer, data, datalen)) < datalen) { if (buffer->loops == 0) { return len; } buffer->head = buffer->data; buffer->used = buffer->actually_used; - len = zap_buffer_read(buffer, (char*)data + len, datalen - len); + len = ftdm_buffer_read(buffer, (char*)data + len, datalen - len); buffer->loops--; } return len; } -OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen) +FT_DECLARE(ftdm_size_t) ftdm_buffer_read(ftdm_buffer_t *buffer, void *data, ftdm_size_t datalen) { - zap_size_t reading = 0; + ftdm_size_t reading = 0; assert(buffer != NULL); assert(data != NULL); @@ -195,9 +195,9 @@ OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_siz return reading; } -OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen) +FT_DECLARE(ftdm_size_t) ftdm_buffer_write(ftdm_buffer_t *buffer, const void *data, ftdm_size_t datalen) { - zap_size_t freespace, actual_freespace; + ftdm_size_t freespace, actual_freespace; assert(buffer != NULL); assert(data != NULL); @@ -224,7 +224,7 @@ OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, */ if (freespace < datalen) { - zap_size_t new_size, new_block_size; + ftdm_size_t new_size, new_block_size; void *data; new_size = buffer->datalen + datalen; @@ -258,7 +258,7 @@ OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, return buffer->used; } -OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer) +FT_DECLARE(void) ftdm_buffer_zero(ftdm_buffer_t *buffer) { assert(buffer != NULL); assert(buffer->data != NULL); @@ -268,23 +268,23 @@ OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer) buffer->head = buffer->data; } -OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen) +FT_DECLARE(ftdm_size_t) ftdm_buffer_zwrite(ftdm_buffer_t *buffer, const void *data, ftdm_size_t datalen) { - zap_size_t w; + ftdm_size_t w; - if (!(w = zap_buffer_write(buffer, data, datalen))) { - zap_buffer_zero(buffer); - return zap_buffer_write(buffer, data, datalen); + if (!(w = ftdm_buffer_write(buffer, data, datalen))) { + ftdm_buffer_zero(buffer); + return ftdm_buffer_write(buffer, data, datalen); } return w; } -OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer) +FT_DECLARE(void) ftdm_buffer_destroy(ftdm_buffer_t **buffer) { if (*buffer) { - zap_safe_free((*buffer)->data); - zap_safe_free(*buffer); + ftdm_safe_free((*buffer)->data); + ftdm_safe_free(*buffer); } *buffer = NULL; diff --git a/libs/freetdm/src/zap_callerid.c b/libs/freetdm/src/ftdm_callerid.c similarity index 61% rename from libs/freetdm/src/zap_callerid.c rename to libs/freetdm/src/ftdm_callerid.c index 7a6e658261..16dd5c8ed7 100644 --- a/libs/freetdm/src/zap_callerid.c +++ b/libs/freetdm/src/ftdm_callerid.c @@ -1,4 +1,4 @@ -#include "openzap.h" +#include "freetdm.h" #include "fsk.h" #include "uart.h" @@ -6,7 +6,7 @@ static void fsk_byte_handler (void *x, int data) { - zap_fsk_data_state_t *state = (zap_fsk_data_state_t *) x; + ftdm_fsk_data_state_t *state = (ftdm_fsk_data_state_t *) x; uint8_t byte = (uint8_t)data; top: @@ -37,42 +37,42 @@ static void fsk_byte_handler (void *x, int data) } } -OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen) +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_init(ftdm_fsk_data_state_t *state, uint8_t *data, uint32_t datalen) { memset(state, 0, sizeof(*state)); state->buf = data; state->bufsize = datalen; state->bpos = 2; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number) +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_sdmf(ftdm_fsk_data_state_t *state, const char *date, char *number) { size_t dlen = strlen(date); size_t nlen = strlen(number); - state->buf[0] = ZAP_CID_TYPE_SDMF; + state->buf[0] = FTDM_CID_TYPE_SDMF; memcpy(&state->buf[state->bpos], date, dlen); state->bpos += dlen; memcpy(&state->buf[state->bpos], number, nlen); state->bpos += nlen; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen) +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_mdmf(ftdm_fsk_data_state_t *state, ftdm_mdmf_type_t type, const uint8_t *data, uint32_t datalen) { - state->buf[0] = ZAP_CID_TYPE_MDMF; + state->buf[0] = FTDM_CID_TYPE_MDMF; state->buf[state->bpos++] = type; state->buf[state->bpos++] = (uint8_t)datalen; memcpy(&state->buf[state->bpos], data, datalen); state->bpos += datalen; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_checksum(ftdm_fsk_data_state_t *state) { uint32_t i; uint8_t check = 0; @@ -89,20 +89,20 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state) state->dlen = state->bpos; state->blen = state->buf[1]; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len) +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_parse(ftdm_fsk_data_state_t *state, ftdm_size_t *type, char **data, ftdm_size_t *len) { - zap_size_t i; + ftdm_size_t i; int sum = 0; top: if (state->checksum != 0 || state->ppos >= state->dlen - 1) { - return ZAP_FAIL; + return FTDM_FAIL; } if (!state->ppos) { @@ -112,13 +112,13 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_siz state->checksum = sum % 256; state->ppos = 2; - if (state->buf[0] != ZAP_CID_TYPE_MDMF && state->buf[0] != ZAP_CID_TYPE_SDMF) { + if (state->buf[0] != FTDM_CID_TYPE_MDMF && state->buf[0] != FTDM_CID_TYPE_SDMF) { state->checksum = -1; } goto top; } - if (state->buf[0] == ZAP_CID_TYPE_SDMF) { + if (state->buf[0] == FTDM_CID_TYPE_SDMF) { /* convert sdmf to mdmf so we don't need 2 parsers */ if (state->ppos == 2) { *type = MDMF_DATETIME; @@ -134,46 +134,46 @@ OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_siz } *data = (char *)&state->buf[state->ppos]; state->ppos += *len; - return ZAP_SUCCESS; - } else if (state->buf[0] == ZAP_CID_TYPE_MDMF) { + return FTDM_SUCCESS; + } else if (state->buf[0] == FTDM_CID_TYPE_MDMF) { *type = state->buf[state->ppos++]; *len = state->buf[state->ppos++]; *data = (char *)&state->buf[state->ppos]; state->ppos += *len; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } -OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, zap_size_t samples) +FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_feed(ftdm_fsk_data_state_t *state, int16_t *data, ftdm_size_t samples) { uint32_t x; int16_t *sp = data; if (state->init == 3) { - return ZAP_FAIL; + return FTDM_FAIL; } for (x = 0; x < samples; x++) { dsp_fsk_sample (state->fsk1200_handle, (double) *sp++ / 32767.0); if (state->dlen && state->bpos >= state->dlen) { state->init = 3; - return ZAP_FAIL; + return FTDM_FAIL; } } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state) +FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_destroy(ftdm_fsk_data_state_t *state) { dsp_fsk_destroy(&state->fsk1200_handle); memset(state, 0, sizeof(*state)); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, zap_size_t bufsize) +FT_DECLARE(int) ftdm_fsk_demod_init(ftdm_fsk_data_state_t *state, int rate, uint8_t *buf, ftdm_size_t bufsize) { dsp_fsk_attr_t fsk1200_attr; @@ -193,20 +193,20 @@ OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_ state->fsk1200_handle = dsp_fsk_create (&fsk1200_attr); if (state->fsk1200_handle == NULL) { - return ZAP_FAIL; + return FTDM_FAIL; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen) +FT_DECLARE(ftdm_size_t) ftdm_fsk_modulator_generate_bit(ftdm_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, ftdm_size_t buflen) { - zap_size_t i; + ftdm_size_t i; for(i = 0 ; i < buflen; i++) { fsk_trans->bit_accum += fsk_trans->bit_factor; - if (fsk_trans->bit_accum >= ZAP_FSK_MOD_FACTOR) { - fsk_trans->bit_accum -= (ZAP_FSK_MOD_FACTOR + fsk_trans->bit_factor); + if (fsk_trans->bit_accum >= FTDM_FSK_MOD_FACTOR) { + fsk_trans->bit_accum -= (FTDM_FSK_MOD_FACTOR + fsk_trans->bit_factor); break; } @@ -217,15 +217,15 @@ OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_t } -OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits) +FT_DECLARE(int32_t) ftdm_fsk_modulator_generate_carrier_bits(ftdm_fsk_modulator_t *fsk_trans, uint32_t bits) { uint32_t i = 0; - zap_size_t r = 0; + ftdm_size_t r = 0; int8_t bit = 1; for (i = 0; i < bits; i++) { - if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) { - if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + if ((r = ftdm_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) { + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != FTDM_SUCCESS) { break; } } else { @@ -237,15 +237,15 @@ OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t } -OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans) +FT_DECLARE(void) ftdm_fsk_modulator_generate_chan_sieze(ftdm_fsk_modulator_t *fsk_trans) { uint32_t i = 0; - zap_size_t r = 0; + ftdm_size_t r = 0; int8_t bit = 0; for (i = 0; i < fsk_trans->chan_sieze_bits; i++) { - if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) { - if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + if ((r = ftdm_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) { + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != FTDM_SUCCESS) { break; } } else { @@ -258,14 +258,14 @@ OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_ } -OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) +FT_DECLARE(void) ftdm_fsk_modulator_send_data(ftdm_fsk_modulator_t *fsk_trans) { - zap_size_t r = 0; + ftdm_size_t r = 0; int8_t bit = 0; - while((bit = zap_bitstream_get_bit(&fsk_trans->bs)) > -1) { - if ((r = zap_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) { - if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != ZAP_SUCCESS) { + while((bit = ftdm_bitstream_get_bit(&fsk_trans->bs)) > -1) { + if ((r = ftdm_fsk_modulator_generate_bit(fsk_trans, bit, fsk_trans->sample_buffer, sizeof(fsk_trans->sample_buffer) / 2))) { + if (fsk_trans->write_sample_callback(fsk_trans->sample_buffer, r, fsk_trans->user_data) != FTDM_SUCCESS) { break; } } else { @@ -275,33 +275,33 @@ OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans) } -OZ_DECLARE(zap_status_t) zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, +FT_DECLARE(ftdm_status_t) ftdm_fsk_modulator_init(ftdm_fsk_modulator_t *fsk_trans, fsk_modem_types_t modem_type, uint32_t sample_rate, - zap_fsk_data_state_t *fsk_data, + ftdm_fsk_data_state_t *fsk_data, float db_level, uint32_t carrier_bits_start, uint32_t carrier_bits_stop, uint32_t chan_sieze_bits, - zap_fsk_write_sample_t write_sample_callback, + ftdm_fsk_write_sample_t write_sample_callback, void *user_data) { memset(fsk_trans, 0, sizeof(*fsk_trans)); fsk_trans->modem_type = modem_type; teletone_dds_state_set_tone(&fsk_trans->dds, fsk_modem_definitions[fsk_trans->modem_type].freq_space, sample_rate, 0); teletone_dds_state_set_tone(&fsk_trans->dds, fsk_modem_definitions[fsk_trans->modem_type].freq_mark, sample_rate, 1); - fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * ZAP_FSK_MOD_FACTOR) / (float)sample_rate); + fsk_trans->bit_factor = (uint32_t)((fsk_modem_definitions[fsk_trans->modem_type].baud_rate * FTDM_FSK_MOD_FACTOR) / (float)sample_rate); fsk_trans->samples_per_bit = (uint32_t) (sample_rate / fsk_modem_definitions[fsk_trans->modem_type].baud_rate); fsk_trans->est_bytes = (int32_t)(((fsk_data->dlen * 10) + carrier_bits_start + carrier_bits_stop + chan_sieze_bits) * ((fsk_trans->samples_per_bit + 1) * 2)); fsk_trans->bit_accum = 0; fsk_trans->fsk_data = fsk_data; teletone_dds_state_set_tx_level(&fsk_trans->dds, db_level); - zap_bitstream_init(&fsk_trans->bs, fsk_trans->fsk_data->buf, (uint32_t)fsk_trans->fsk_data->dlen, ZAP_ENDIAN_BIG, 1); + ftdm_bitstream_init(&fsk_trans->bs, fsk_trans->fsk_data->buf, (uint32_t)fsk_trans->fsk_data->dlen, FTDM_ENDIAN_BIG, 1); fsk_trans->carrier_bits_start = carrier_bits_start; fsk_trans->carrier_bits_stop = carrier_bits_stop; fsk_trans->chan_sieze_bits = chan_sieze_bits; fsk_trans->write_sample_callback = write_sample_callback; fsk_trans->user_data = user_data; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/zap_config.c b/libs/freetdm/src/ftdm_config.c similarity index 77% rename from libs/freetdm/src/zap_config.c rename to libs/freetdm/src/ftdm_config.c index ca0315594b..a7a8f041b1 100644 --- a/libs/freetdm/src/zap_config.c +++ b/libs/freetdm/src/ftdm_config.c @@ -31,10 +31,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openzap.h" -#include "zap_config.h" +#include "freetdm.h" +#include "ftdm_config.h" -int zap_config_open_file(zap_config_t *cfg, const char *file_path) +int ftdm_config_open_file(ftdm_config_t *cfg, const char *file_path) { FILE *f; const char *path = NULL; @@ -43,7 +43,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) if (file_path[0] == '/') { path = file_path; } else { - snprintf(path_buf, sizeof(path_buf), "%s%s%s", ZAP_CONFIG_DIR, ZAP_PATH_SEPARATOR, file_path); + snprintf(path_buf, sizeof(path_buf), "%s%s%s", FTDM_CONFIG_DIR, FTDM_PATH_SEPARATOR, file_path); path = path_buf; } @@ -53,7 +53,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) memset(cfg, 0, sizeof(*cfg)); cfg->lockto = -1; - zap_log(ZAP_LOG_DEBUG, "Configuration file is %s.\n", path); + ftdm_log(FTDM_LOG_DEBUG, "Configuration file is %s.\n", path); f = fopen(path, "r"); if (!f) { @@ -61,7 +61,7 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) int last = -1; char *var, *val; - snprintf(path_buf, sizeof(path_buf), "%s%sopenzap.conf", ZAP_CONFIG_DIR, ZAP_PATH_SEPARATOR); + snprintf(path_buf, sizeof(path_buf), "%s%sfreetdm.conf", FTDM_CONFIG_DIR, FTDM_PATH_SEPARATOR); path = path_buf; if ((f = fopen(path, "r")) == 0) { @@ -69,16 +69,16 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) } cfg->file = f; - zap_set_string(cfg->path, path); + ftdm_set_string(cfg->path, path); - while (zap_config_next_pair(cfg, &var, &val)) { + while (ftdm_config_next_pair(cfg, &var, &val)) { if ((cfg->sectno != last) && !strcmp(cfg->section, file_path)) { cfg->lockto = cfg->sectno; return 1; } } - zap_config_close_file(cfg); + ftdm_config_close_file(cfg); memset(cfg, 0, sizeof(*cfg)); return 0; } @@ -86,12 +86,12 @@ int zap_config_open_file(zap_config_t *cfg, const char *file_path) return 0; } else { cfg->file = f; - zap_set_string(cfg->path, path); + ftdm_set_string(cfg->path, path); return 1; } } -void zap_config_close_file(zap_config_t *cfg) +void ftdm_config_close_file(ftdm_config_t *cfg) { if (cfg->file) { @@ -103,7 +103,7 @@ void zap_config_close_file(zap_config_t *cfg) -int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) +int ftdm_config_next_pair(ftdm_config_t *cfg, char **var, char **val) { int ret = 0; char *p, *end; @@ -128,7 +128,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) (*var)++; if (**var == '+') { (*var)++; - zap_copy_string(cfg->section, *var, sizeof(cfg->section)); + ftdm_copy_string(cfg->section, *var, sizeof(cfg->section)); cfg->sectno++; if (cfg->lockto > -1 && cfg->sectno != cfg->lockto) { @@ -140,7 +140,7 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) *val = (char *) ""; return 1; } else { - zap_copy_string(cfg->category, *var, sizeof(cfg->category)); + ftdm_copy_string(cfg->category, *var, sizeof(cfg->category)); cfg->catno++; } continue; @@ -209,29 +209,29 @@ int zap_config_next_pair(zap_config_t *cfg, char **var, char **val) } -OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits) +FT_DECLARE (int) ftdm_config_get_cas_bits(char *strvalue, unsigned char *outbits) { char cas_bits[5]; unsigned char bit = 0x8; int x = 0; char *double_colon = strchr(strvalue, ':'); if (!double_colon) { - zap_log(ZAP_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", strvalue); + ftdm_log(FTDM_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", strvalue); return -1; } double_colon++; *outbits = 0; cas_bits[4] = 0; if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) { - zap_log(ZAP_LOG_ERROR, "Invalid CAS bits specified: '%s', :xxxx definition expected, where x is 1 or 0\n", double_colon); + ftdm_log(FTDM_LOG_ERROR, "Invalid CAS bits specified: '%s', :xxxx definition expected, where x is 1 or 0\n", double_colon); return -1; } - zap_log(ZAP_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits); + ftdm_log(FTDM_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits); for (; cas_bits[x]; x++) { if ('1' == cas_bits[x]) { *outbits |= bit; } else if ('0' != cas_bits[x]) { - zap_log(ZAP_LOG_ERROR, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n"); + ftdm_log(FTDM_LOG_ERROR, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n"); return -1; } bit >>= 1; diff --git a/libs/freetdm/src/zap_dso.c b/libs/freetdm/src/ftdm_dso.c similarity index 80% rename from libs/freetdm/src/zap_dso.c rename to libs/freetdm/src/ftdm_dso.c index b222e24231..a0981ebdd9 100644 --- a/libs/freetdm/src/zap_dso.c +++ b/libs/freetdm/src/ftdm_dso.c @@ -17,8 +17,8 @@ * */ -#include "openzap.h" -#include "zap_dso.h" +#include "freetdm.h" +#include "ftdm_dso.h" #include #include @@ -27,14 +27,14 @@ #include -OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib) { +FT_DECLARE(void) ftdm_dso_destroy(ftdm_dso_lib_t *lib) { if (lib && *lib) { FreeLibrary(*lib); *lib = NULL; } } -OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) { +FT_DECLARE(ftdm_dso_lib_t) ftdm_dso_open(const char *path, char **err) { HINSTANCE lib; lib = LoadLibraryEx(path, NULL, 0); @@ -47,21 +47,21 @@ OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) { DWORD error = GetLastError(); char tmp[80]; sprintf(tmp, "dll open error [%ul]\n", error); - *err = zap_strdup(tmp); + *err = ftdm_strdup(tmp); } return lib; } -OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { +FT_DECLARE(void*) ftdm_dso_func_sym(ftdm_dso_lib_t lib, const char *sym, char **err) { FARPROC func = GetProcAddress(lib, sym); if (!func) { DWORD error = GetLastError(); char tmp[80]; sprintf(tmp, "dll sym error [%ul]\n", error); - *err = zap_strdup(tmp); + *err = ftdm_strdup(tmp); } - return (void *)(intptr_t)func; // this should really be addr - zap_dso_func_data + return (void *)(intptr_t)func; // this should really be addr - ftdm_dso_func_data } #else @@ -78,25 +78,25 @@ OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **er #include -OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib) { +FT_DECLARE(void) ftdm_dso_destroy(ftdm_dso_lib_t *lib) { if (lib && *lib) { dlclose(*lib); *lib = NULL; } } -OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err) { +FT_DECLARE(ftdm_dso_lib_t) ftdm_dso_open(const char *path, char **err) { void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (lib == NULL) { - *err = zap_strdup(dlerror()); + *err = ftdm_strdup(dlerror()); } return lib; } -OZ_DECLARE(void*) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) { +FT_DECLARE(void*) ftdm_dso_func_sym(ftdm_dso_lib_t lib, const char *sym, char **err) { void *func = dlsym(lib, sym); if (!func) { - *err = zap_strdup(dlerror()); + *err = ftdm_strdup(dlerror()); } return func; } diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c new file mode 100644 index 0000000000..fc2c450288 --- /dev/null +++ b/libs/freetdm/src/ftdm_io.c @@ -0,0 +1,3754 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * David Yat Sin + * + */ + +#define _GNU_SOURCE +#ifndef WIN32 +#endif +#include "freetdm.h" +#include +#ifdef WIN32 +#include +#endif +#ifdef FTDM_PIKA_SUPPORT +#include "ftdm_pika.h" +#endif + +static int time_is_init = 0; + +static void time_init(void) +{ +#ifdef WIN32 + timeBeginPeriod(1); +#endif + time_is_init = 1; +} + +static void time_end(void) +{ +#ifdef WIN32 + timeEndPeriod(1); +#endif + time_is_init = 0; +} + +FT_DECLARE(ftdm_time_t) ftdm_current_time_in_ms(void) +{ +#ifdef WIN32 + return timeGetTime(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); +#endif +} + +static struct { + ftdm_hash_t *interface_hash; + ftdm_hash_t *module_hash; + ftdm_hash_t *span_hash; + ftdm_hash_t *group_hash; + ftdm_mutex_t *mutex; + ftdm_mutex_t *span_mutex; + ftdm_mutex_t *group_mutex; + uint32_t span_index; + uint32_t group_index; + uint32_t running; + ftdm_span_t *spans; + ftdm_group_t *groups; +} globals; + + +/* enum lookup funcs */ +FTDM_ENUM_NAMES(TONEMAP_NAMES, TONEMAP_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_tonemap, ftdm_tonemap2str, ftdm_tonemap_t, TONEMAP_NAMES, FTDM_TONEMAP_INVALID) + +FTDM_ENUM_NAMES(OOB_NAMES, OOB_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_oob_event, ftdm_oob_event2str, ftdm_oob_event_t, OOB_NAMES, FTDM_OOB_INVALID) + +FTDM_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_trunk_type, ftdm_trunk_type2str, ftdm_trunk_type_t, TRUNK_TYPE_NAMES, FTDM_TRUNK_NONE) + +FTDM_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_analog_start_type, ftdm_analog_start_type2str, ftdm_analog_start_type_t, START_TYPE_NAMES, FTDM_ANALOG_START_NA) + +FTDM_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_signal_event, ftdm_signal_event2str, ftdm_signal_event_t, SIGNAL_NAMES, FTDM_SIGEVENT_INVALID) + +FTDM_ENUM_NAMES(CHANNEL_STATE_NAMES, CHANNEL_STATE_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_channel_state, ftdm_channel_state2str, ftdm_channel_state_t, CHANNEL_STATE_NAMES, FTDM_CHANNEL_STATE_INVALID) + +FTDM_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_mdmf_type, ftdm_mdmf_type2str, ftdm_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) + +FTDM_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t, CHAN_TYPE_NAMES, FTDM_CHAN_TYPE_COUNT) + +FTDM_ENUM_NAMES(SIGNALING_STATUS_NAMES, SIGSTATUS_STRINGS) +FTDM_STR2ENUM(ftdm_str2ftdm_signaling_status, ftdm_signaling_status2str, ftdm_signaling_status_t, SIGNALING_STATUS_NAMES, FTDM_SIG_STATE_INVALID) + +static const char *cut_path(const char *in) +{ + const char *p, *ret = in; + char delims[] = "/\\"; + char *i; + + for (i = delims; *i; i++) { + p = in; + while ((p = strchr(p, *i)) != 0) { + ret = ++p; + } + } + return ret; +} + +static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) +{ + if (file && func && line && level && fmt) { + return; + } + return; +} + + +static const char *LEVEL_NAMES[] = { + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + NULL +}; + +static int ftdm_log_level = 7; + +static void default_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) +{ + const char *fp; + char data[1024]; + va_list ap; + + if (level < 0 || level > 7) { + level = 7; + } + if (level > ftdm_log_level) { + return; + } + + fp = cut_path(file); + + va_start(ap, fmt); + + vsnprintf(data, sizeof(data), fmt, ap); + + + fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data); + + va_end(ap); + +} + +static __inline__ void *ftdm_std_malloc(void *pool, ftdm_size_t size) +{ + void *ptr = malloc(size); + pool = NULL; /* fix warning */ + ftdm_assert_return(ptr != NULL, NULL, "Out of memory"); + return ptr; +} + +static __inline__ void *ftdm_std_calloc(void *pool, ftdm_size_t elements, ftdm_size_t size) +{ + void *ptr = calloc(elements, size); + pool = NULL; + ftdm_assert_return(ptr != NULL, NULL, "Out of memory"); + return ptr; +} + +static __inline__ void ftdm_std_free(void *pool, void *ptr) +{ + pool = NULL; + ftdm_assert_return(ptr != NULL, , "Attempted to free null pointer"); + free(ptr); +} + +FT_DECLARE_DATA ftdm_memory_handler_t g_ftdm_mem_handler = +{ + /*.pool =*/ NULL, + /*.malloc =*/ ftdm_std_malloc, + /*.calloc =*/ ftdm_std_calloc, + /*.free =*/ ftdm_std_free +}; + +FT_DECLARE_DATA ftdm_crash_policy_t g_ftdm_crash_policy = FTDM_CRASH_NEVER; + +FT_DECLARE_DATA ftdm_logger_t ftdm_log = null_logger; + +FT_DECLARE(void) ftdm_global_set_crash_policy(ftdm_crash_policy_t policy) +{ + g_ftdm_crash_policy |= policy; +} + +FT_DECLARE(ftdm_status_t) ftdm_global_set_memory_handler(ftdm_memory_handler_t *handler) +{ + if (!handler) { + return FTDM_FAIL; + } + if (!handler->malloc) { + return FTDM_FAIL; + } + if (!handler->calloc) { + return FTDM_FAIL; + } + if (!handler->free) { + return FTDM_FAIL; + } + memcpy(&g_ftdm_mem_handler, handler, sizeof(*handler)); + return FTDM_SUCCESS; +} + +FT_DECLARE(void) ftdm_global_set_logger(ftdm_logger_t logger) +{ + if (logger) { + ftdm_log = logger; + } else { + ftdm_log = null_logger; + } +} + +FT_DECLARE(void) ftdm_global_set_default_logger(int level) +{ + if (level < 0 || level > 7) { + level = 7; + } + + ftdm_log = default_logger; + ftdm_log_level = level; +} + +FT_DECLARE_NONSTD(int) ftdm_hash_equalkeys(void *k1, void *k2) +{ + return strcmp((char *) k1, (char *) k2) ? 0 : 1; +} + +FT_DECLARE_NONSTD(uint32_t) ftdm_hash_hashfromstring(void *ky) +{ + unsigned char *str = (unsigned char *) ky; + uint32_t hash = 0; + int c; + + while ((c = *str++)) { + hash = c + (hash << 6) + (hash << 16) - hash; + } + + return hash; +} + +static ftdm_status_t ftdm_channel_destroy(ftdm_channel_t *ftdmchan) +{ + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CONFIGURED)) { + + while (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_log(FTDM_LOG_INFO, "Waiting for thread to exit on channel %u:%u\n", ftdmchan->span_id, ftdmchan->chan_id); + ftdm_sleep(500); + } + + ftdm_mutex_lock(ftdmchan->pre_buffer_mutex); + ftdm_buffer_destroy(&ftdmchan->pre_buffer); + ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex); + + ftdm_buffer_destroy(&ftdmchan->digit_buffer); + ftdm_buffer_destroy(&ftdmchan->gen_dtmf_buffer); + ftdm_buffer_destroy(&ftdmchan->dtmf_buffer); + ftdm_buffer_destroy(&ftdmchan->fsk_buffer); + ftdmchan->pre_buffer_size = 0; + + hashtable_destroy(ftdmchan->variable_hash); + + ftdm_safe_free(ftdmchan->dtmf_hangup_buf); + + if (ftdmchan->tone_session.buffer) { + teletone_destroy_session(&ftdmchan->tone_session); + memset(&ftdmchan->tone_session, 0, sizeof(ftdmchan->tone_session)); + } + + + if (ftdmchan->span->zio->channel_destroy) { + ftdm_log(FTDM_LOG_INFO, "Closing channel %s:%u:%u fd:%d\n", ftdmchan->span->type, ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); + if (ftdmchan->span->zio->channel_destroy(ftdmchan) == FTDM_SUCCESS) { + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_CONFIGURED); + } else { + ftdm_log(FTDM_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); + } + } + + ftdm_mutex_destroy(&ftdmchan->mutex); + ftdm_mutex_destroy(&ftdmchan->pre_buffer_mutex); + } + + return FTDM_SUCCESS; +} + +static ftdm_status_t ftdm_span_destroy(ftdm_span_t *span) +{ + ftdm_status_t status = FTDM_SUCCESS; + unsigned j; + + ftdm_mutex_lock(span->mutex); + + /* stop the signaling */ + if (span->stop) { + status = span->stop(span); + } + + /* destroy the channels */ + ftdm_clear_flag(span, FTDM_SPAN_CONFIGURED); + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { + ftdm_channel_t *cur_chan = span->channels[j]; + if (cur_chan) { + if (ftdm_test_flag(cur_chan, FTDM_CHANNEL_CONFIGURED)) { + ftdm_channel_destroy(cur_chan); + } + ftdm_safe_free(cur_chan); + cur_chan = NULL; + } + } + + /* destroy the I/O for the span */ + if (span->zio && span->zio->span_destroy) { + ftdm_log(FTDM_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); + if (span->zio->span_destroy(span) != FTDM_SUCCESS) { + status = FTDM_FAIL; + } + ftdm_safe_free(span->type); + ftdm_safe_free(span->dtmf_hangup); + } + + /* destroy final basic resources of the span data structure */ + ftdm_mutex_unlock(span->mutex); + ftdm_mutex_destroy(&span->mutex); + ftdm_safe_free(span->signal_data); + + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_get_alarms(ftdm_channel_t *ftdmchan) +{ + ftdm_status_t status = FTDM_FAIL; + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CONFIGURED)) { + if (ftdmchan->span->zio->get_alarms) { + if ((status = ftdmchan->span->zio->get_alarms(ftdmchan)) == FTDM_SUCCESS) { + *ftdmchan->last_error = '\0'; + if (ftdm_test_alarm_flag(ftdmchan, FTDM_ALARM_RED)) { + snprintf(ftdmchan->last_error + strlen(ftdmchan->last_error), sizeof(ftdmchan->last_error) - strlen(ftdmchan->last_error), "RED/"); + } + if (ftdm_test_alarm_flag(ftdmchan, FTDM_ALARM_YELLOW)) { + snprintf(ftdmchan->last_error + strlen(ftdmchan->last_error), sizeof(ftdmchan->last_error) - strlen(ftdmchan->last_error), "YELLOW/"); + } + if (ftdm_test_alarm_flag(ftdmchan, FTDM_ALARM_BLUE)) { + snprintf(ftdmchan->last_error + strlen(ftdmchan->last_error), sizeof(ftdmchan->last_error) - strlen(ftdmchan->last_error), "BLUE/"); + } + if (ftdm_test_alarm_flag(ftdmchan, FTDM_ALARM_LOOPBACK)) { + snprintf(ftdmchan->last_error + strlen(ftdmchan->last_error), sizeof(ftdmchan->last_error) - strlen(ftdmchan->last_error), "LOOP/"); + } + if (ftdm_test_alarm_flag(ftdmchan, FTDM_ALARM_RECOVER)) { + snprintf(ftdmchan->last_error + strlen(ftdmchan->last_error), sizeof(ftdmchan->last_error) - strlen(ftdmchan->last_error), "RECOVER/"); + } + *(ftdmchan->last_error + strlen(ftdmchan->last_error) - 1) = '\0'; + + } + } else { + status = FTDM_NOTIMPL; + } + } + + return status; +} + +static void ftdm_span_add(ftdm_span_t *span) +{ + ftdm_span_t *sp; + ftdm_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp && sp->next; sp = sp->next); + if (sp) { + sp->next = span; + } else { + globals.spans = span; + } + hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); + ftdm_mutex_unlock(globals.span_mutex); +} + +#if 0 +static void ftdm_span_del(ftdm_span_t *span) +{ + ftdm_span_t *last = NULL, *sp; + + ftdm_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp; sp = sp->next) { + + if (sp == span) { + if (last) { + last->next = sp->next; + } else { + globals.spans = sp->next; + } + hashtable_remove(globals.span_hash, (void *)sp->name); + break; + } + + last = sp; + } + ftdm_mutex_unlock(globals.span_mutex); +} +#endif + +FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span) +{ + if (span->stop) { + span->stop(span); + return FTDM_SUCCESS; + } + + return FTDM_FAIL; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *zio, ftdm_span_t **span, const char *name) +{ + ftdm_span_t *new_span = NULL; + ftdm_status_t status = FTDM_FAIL; + + assert(zio != NULL); + + ftdm_mutex_lock(globals.mutex); + + if (globals.span_index < FTDM_MAX_SPANS_INTERFACE) { + new_span = ftdm_malloc(sizeof(*new_span)); + assert(new_span); + memset(new_span, 0, sizeof(*new_span)); + status = ftdm_mutex_create(&new_span->mutex); + assert(status == FTDM_SUCCESS); + + ftdm_set_flag(new_span, FTDM_SPAN_CONFIGURED); + new_span->span_id = ++globals.span_index; + new_span->zio = zio; + ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_DIAL], "%(1000,0,350,440)", FTDM_TONEMAP_LEN); + ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_RING], "%(2000,4000,440,480)", FTDM_TONEMAP_LEN); + ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_BUSY], "%(500,500,480,620)", FTDM_TONEMAP_LEN); + ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", FTDM_TONEMAP_LEN); + new_span->trunk_type = FTDM_TRUNK_NONE; + new_span->data_type = FTDM_TYPE_SPAN; + + ftdm_mutex_lock(globals.span_mutex); + if (!ftdm_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { + ftdm_log(FTDM_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, new_span->span_id); + name = NULL; + } + ftdm_mutex_unlock(globals.span_mutex); + + if (!name) { + char buf[128] = ""; + snprintf(buf, sizeof(buf), "span%d", new_span->span_id); + name = buf; + } + new_span->name = ftdm_strdup(name); + ftdm_span_add(new_span); + *span = new_span; + status = FTDM_SUCCESS; + } + ftdm_mutex_unlock(globals.mutex); + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_close_all(void) +{ + ftdm_span_t *span; + uint32_t i = 0, j; + + ftdm_mutex_lock(globals.span_mutex); + for (span = globals.spans; span; span = span->next) { + if (ftdm_test_flag(span, FTDM_SPAN_CONFIGURED)) { + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { + ftdm_channel_t *toclose = span->channels[j]; + if (ftdm_test_flag(toclose, FTDM_CHANNEL_INUSE)) { + ftdm_channel_close(&toclose); + } + i++; + } + } + } + ftdm_mutex_unlock(globals.span_mutex); + + return i ? FTDM_SUCCESS : FTDM_FAIL; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_load_tones(ftdm_span_t *span, const char *mapname) +{ + ftdm_config_t cfg; + char *var, *val; + int x = 0; + + if (!ftdm_config_open_file(&cfg, "tones.conf")) { + snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); + return FTDM_FAIL; + } + + while (ftdm_config_next_pair(&cfg, &var, &val)) { + int detect = 0; + + if (!strcasecmp(cfg.category, mapname) && var && val) { + uint32_t index; + char *name = NULL; + + if (!strncasecmp(var, "detect-", 7)) { + name = var + 7; + detect = 1; + } else if (!strncasecmp(var, "generate-", 9)) { + name = var + 9; + } else { + ftdm_log(FTDM_LOG_WARNING, "Unknown tone name %s\n", var); + continue; + } + + index = ftdm_str2ftdm_tonemap(name); + + if (index >= FTDM_TONEMAP_INVALID || index == FTDM_TONEMAP_NONE) { + ftdm_log(FTDM_LOG_WARNING, "Unknown tone name %s\n", name); + } else { + if (detect) { + char *p = val, *next; + int i = 0; + do { + teletone_process_t this; + next = strchr(p, ','); + this = (teletone_process_t)atof(p); + span->tone_detect_map[index].freqs[i++] = this; + if (next) { + p = next + 1; + } + } while (next); + ftdm_log(FTDM_LOG_DEBUG, "added tone detect [%s] = [%s]\n", name, val); + } else { + ftdm_log(FTDM_LOG_DEBUG, "added tone generation [%s] = [%s]\n", name, val); + ftdm_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); + } + x++; + } + } + } + + ftdm_config_close_file(&cfg); + + if (!x) { + snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); + return FTDM_FAIL; + } + + return FTDM_SUCCESS; + +} + +#define FTDM_SLINEAR_MAX_VALUE 32767 +#define FTDM_SLINEAR_MIN_VALUE -32767 +static void reset_gain_table(unsigned char *gain_table, float new_gain, ftdm_codec_t codec_gain) +{ + /* sample value */ + unsigned sv = 0; + /* linear gain factor */ + float lingain = 0; + /* linear value for each table sample */ + float linvalue = 0; + /* amplified (or attenuated in case of negative amplification) sample value */ + int ampvalue = 0; + + /* gain tables are only for alaw and ulaw */ + if (codec_gain != FTDM_CODEC_ALAW && codec_gain != FTDM_CODEC_ULAW) { + ftdm_log(FTDM_LOG_WARNING, "Not resetting gain table because codec is not ALAW or ULAW but %d\n", codec_gain); + return; + } + + if (!new_gain) { + /* for a 0.0db gain table, each alaw/ulaw sample value is left untouched (0 ==0, 1 == 1, 2 == 2 etc)*/ + for (sv = 0; sv < FTDM_GAINS_TABLE_SIZE; sv++) { + gain_table[sv] = sv; + } + return; + } + + /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wipedia.org/wiki/20_log_rule#Definitions */ + lingain = pow(10.0, new_gain/ 20.0); + for (sv = 0; sv < FTDM_GAINS_TABLE_SIZE; sv++) { + /* get the linear value for this alaw/ulaw sample value */ + linvalue = codec_gain == FTDM_CODEC_ALAW ? alaw_to_linear(sv) : ulaw_to_linear(sv); + + /* multiply the linear value and the previously calculated linear gain */ + ampvalue = (int)(linvalue * lingain); + + /* chop it if goes beyond the limits */ + if (ampvalue > FTDM_SLINEAR_MAX_VALUE) { + ampvalue = FTDM_SLINEAR_MAX_VALUE; + } + + if (ampvalue < FTDM_SLINEAR_MIN_VALUE) { + ampvalue = FTDM_SLINEAR_MIN_VALUE; + } + gain_table[sv] = codec_gain == FTDM_CODEC_ALAW ? linear_to_alaw(ampvalue) : linear_to_ulaw(ampvalue); + } +} + +FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t sockfd, ftdm_chan_type_t type, ftdm_channel_t **chan) +{ + unsigned i = 0; + if (span->chan_count < FTDM_MAX_CHANNELS_SPAN) { + ftdm_channel_t *new_chan = span->channels[++span->chan_count]; + + if (!new_chan) { + if (!(new_chan = ftdm_calloc(1, sizeof(*new_chan)))) { + return FTDM_FAIL; + } + span->channels[span->chan_count] = new_chan; + } + + new_chan->type = type; + new_chan->sockfd = sockfd; + new_chan->zio = span->zio; + new_chan->span_id = span->span_id; + new_chan->chan_id = span->chan_count; + new_chan->span = span; + new_chan->fds[0] = -1; + new_chan->fds[1] = -1; + new_chan->data_type = FTDM_TYPE_CHANNEL; + if (!new_chan->dtmf_on) { + new_chan->dtmf_on = FTDM_DEFAULT_DTMF_ON; + } + + if (!new_chan->dtmf_off) { + new_chan->dtmf_off = FTDM_DEFAULT_DTMF_OFF; + } + + ftdm_mutex_create(&new_chan->mutex); + ftdm_mutex_create(&new_chan->pre_buffer_mutex); + + ftdm_buffer_create(&new_chan->digit_buffer, 128, 128, 0); + ftdm_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); + new_chan->variable_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + + new_chan->dtmf_hangup_buf = ftdm_calloc (span->dtmf_hangup_len + 1, sizeof (char)); + + /* set 0.0db gain table */ + for (i = 0; i < sizeof(new_chan->txgain_table); i++) { + new_chan->txgain_table[i] = i; + new_chan->rxgain_table[i] = i; + } + + ftdm_set_flag(new_chan, FTDM_CHANNEL_CONFIGURED | FTDM_CHANNEL_READY); + *chan = new_chan; + return FTDM_SUCCESS; + } + + return FTDM_FAIL; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_find_by_name(const char *name, ftdm_span_t **span) +{ + ftdm_status_t status = FTDM_FAIL; + + ftdm_mutex_lock(globals.span_mutex); + if (!ftdm_strlen_zero(name)) { + if ((*span = hashtable_search(globals.span_hash, (void *)name))) { + status = FTDM_SUCCESS; + } else { + int span_id = atoi(name); + + ftdm_span_find(span_id, span); + if (*span) { + status = FTDM_SUCCESS; + } + } + } + ftdm_mutex_unlock(globals.span_mutex); + + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_find(uint32_t id, ftdm_span_t **span) +{ + ftdm_span_t *fspan = NULL, *sp; + + if (id > FTDM_MAX_SPANS_INTERFACE) { + return FTDM_FAIL; + } + + ftdm_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp; sp = sp->next) { + if (sp->span_id == id) { + fspan = sp; + break; + } + } + ftdm_mutex_unlock(globals.span_mutex); + + if (!fspan || !ftdm_test_flag(fspan, FTDM_SPAN_CONFIGURED)) { + return FTDM_FAIL; + } + + *span = fspan; + + return FTDM_SUCCESS; + +} + +FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, zio_event_cb_t event_callback) +{ + ftdm_mutex_lock(span->mutex); + span->event_callback = event_callback; + ftdm_mutex_unlock(span->mutex); + return FTDM_SUCCESS; +} + + +FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms) +{ + assert(span->zio != NULL); + + if (span->zio->poll_event) { + return span->zio->poll_event(span, ms); + } else { + ftdm_log(FTDM_LOG_ERROR, "poll_event method not implemented in module %s!", span->zio->name); + } + + return FTDM_NOTIMPL; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_next_event(ftdm_span_t *span, ftdm_event_t **event) +{ + assert(span->zio != NULL); + + if (span->zio->next_event) { + return span->zio->next_event(span, event); + } else { + ftdm_log(FTDM_LOG_ERROR, "next_event method not implemented in module %s!", span->zio->name); + } + + return FTDM_NOTIMPL; +} + +static ftdm_status_t ftdmchan_fsk_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data) +{ + ftdm_channel_t *ftdmchan = (ftdm_channel_t *) user_data; + ftdm_buffer_write(ftdmchan->fsk_buffer, buf, buflen * 2); + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_send_fsk_data(ftdm_channel_t *ftdmchan, ftdm_fsk_data_state_t *fsk_data, float db_level) +{ + struct ftdm_fsk_modulator fsk_trans; + + if (!ftdmchan->fsk_buffer) { + ftdm_buffer_create(&ftdmchan->fsk_buffer, 128, 128, 0); + } else { + ftdm_buffer_zero(ftdmchan->fsk_buffer); + } + + if (ftdmchan->token_count > 1) { + ftdm_fsk_modulator_init(&fsk_trans, FSK_BELL202, ftdmchan->rate, fsk_data, db_level, 80, 5, 0, ftdmchan_fsk_write_sample, ftdmchan); + ftdm_fsk_modulator_send_all((&fsk_trans)); + } else { + ftdm_fsk_modulator_init(&fsk_trans, FSK_BELL202, ftdmchan->rate, fsk_data, db_level, 180, 5, 300, ftdmchan_fsk_write_sample, ftdmchan); + ftdm_fsk_modulator_send_all((&fsk_trans)); + ftdmchan->buffer_delay = 3500 / ftdmchan->effective_interval; + } + + return FTDM_SUCCESS; +} + + +FT_DECLARE(ftdm_status_t) ftdm_channel_set_event_callback(ftdm_channel_t *ftdmchan, zio_event_cb_t event_callback) +{ + ftdm_mutex_lock(ftdmchan->mutex); + ftdmchan->event_callback = event_callback; + ftdm_mutex_unlock(ftdmchan->mutex); + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_clear_token(ftdm_channel_t *ftdmchan, const char *token) +{ + ftdm_status_t status = FTDM_FAIL; + + ftdm_mutex_lock(ftdmchan->mutex); + if (token == NULL) { + memset(ftdmchan->tokens, 0, sizeof(ftdmchan->tokens)); + ftdmchan->token_count = 0; + } else if (*token != '\0') { + char tokens[FTDM_MAX_TOKENS][FTDM_TOKEN_STRLEN]; + int32_t i, count = ftdmchan->token_count; + memcpy(tokens, ftdmchan->tokens, sizeof(tokens)); + memset(ftdmchan->tokens, 0, sizeof(ftdmchan->tokens)); + ftdmchan->token_count = 0; + + for (i = 0; i < count; i++) { + if (strcmp(tokens[i], token)) { + ftdm_copy_string(ftdmchan->tokens[ftdmchan->token_count], tokens[i], sizeof(ftdmchan->tokens[ftdmchan->token_count])); + ftdmchan->token_count++; + } + } + + status = FTDM_SUCCESS; + } + ftdm_mutex_unlock(ftdmchan->mutex); + + return status; +} + +FT_DECLARE(void) ftdm_channel_rotate_tokens(ftdm_channel_t *ftdmchan) +{ + if (ftdmchan->token_count) { + memmove(ftdmchan->tokens[1], ftdmchan->tokens[0], ftdmchan->token_count * FTDM_TOKEN_STRLEN); + ftdm_copy_string(ftdmchan->tokens[0], ftdmchan->tokens[ftdmchan->token_count], FTDM_TOKEN_STRLEN); + *ftdmchan->tokens[ftdmchan->token_count] = '\0'; + } +} + +FT_DECLARE(void) ftdm_channel_replace_token(ftdm_channel_t *ftdmchan, const char *old_token, const char *new_token) +{ + unsigned int i; + + if (ftdmchan->token_count) { + for(i = 0; i < ftdmchan->token_count; i++) { + if (!strcmp(ftdmchan->tokens[i], old_token)) { + ftdm_copy_string(ftdmchan->tokens[i], new_token, FTDM_TOKEN_STRLEN); + break; + } + } + } +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_add_token(ftdm_channel_t *ftdmchan, char *token, int end) +{ + ftdm_status_t status = FTDM_FAIL; + + ftdm_mutex_lock(ftdmchan->mutex); + if (ftdmchan->token_count < FTDM_MAX_TOKENS) { + if (end) { + ftdm_copy_string(ftdmchan->tokens[ftdmchan->token_count++], token, FTDM_TOKEN_STRLEN); + } else { + memmove(ftdmchan->tokens[1], ftdmchan->tokens[0], ftdmchan->token_count * FTDM_TOKEN_STRLEN); + ftdm_copy_string(ftdmchan->tokens[0], token, FTDM_TOKEN_STRLEN); + ftdmchan->token_count++; + } + status = FTDM_SUCCESS; + } + ftdm_mutex_unlock(ftdmchan->mutex); + + return status; +} + + +FT_DECLARE(ftdm_status_t) ftdm_channel_complete_state(ftdm_channel_t *ftdmchan) +{ + ftdm_channel_state_t state = ftdmchan->state; + + if (state == FTDM_CHANNEL_STATE_PROGRESS) { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_PROGRESS); + } else if (state == FTDM_CHANNEL_STATE_UP) { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_MEDIA); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_ANSWERED); + } else if (state == FTDM_CHANNEL_STATE_PROGRESS_MEDIA) { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_MEDIA); + } + + return FTDM_SUCCESS; +} + +static int ftdm_parse_state_map(ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, ftdm_state_map_t *state_map) +{ + int x = 0, ok = 0; + ftdm_state_direction_t direction = ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? ZSD_OUTBOUND : ZSD_INBOUND; + + for(x = 0; x < FTDM_MAP_NODE_SIZE; x++) { + int i = 0, proceed = 0; + if (!state_map->nodes[x].type) { + break; + } + + if (state_map->nodes[x].direction != direction) { + continue; + } + + if (state_map->nodes[x].check_states[0] == FTDM_ANY_STATE) { + proceed = 1; + } else { + for(i = 0; i < FTDM_MAP_MAX; i++) { + if (state_map->nodes[x].check_states[i] == ftdmchan->state) { + proceed = 1; + break; + } + } + } + + if (!proceed) { + continue; + } + + for(i = 0; i < FTDM_MAP_MAX; i++) { + ok = (state_map->nodes[x].type == ZSM_ACCEPTABLE); + if (state_map->nodes[x].states[i] == FTDM_END) { + break; + } + if (state_map->nodes[x].states[i] == state) { + ok = !ok; + goto end; + } + } + } + end: + + return ok; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int lock) +{ + int ok = 1; + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY)) { + return FTDM_FAIL; + } + + if (ftdm_test_flag(ftdmchan->span, FTDM_SPAN_SUSPENDED)) { + if (state != FTDM_CHANNEL_STATE_RESTART && state != FTDM_CHANNEL_STATE_DOWN) { + return FTDM_FAIL; + } + } + + if (lock) { + ftdm_mutex_lock(ftdmchan->mutex); + } + + if (ftdmchan->span->state_map) { + ok = ftdm_parse_state_map(ftdmchan, state, ftdmchan->span->state_map); + goto end; + } + + switch(ftdmchan->state) { + case FTDM_CHANNEL_STATE_HANGUP: + case FTDM_CHANNEL_STATE_TERMINATING: + { + ok = 0; + switch(state) { + case FTDM_CHANNEL_STATE_DOWN: + case FTDM_CHANNEL_STATE_BUSY: + case FTDM_CHANNEL_STATE_RESTART: + ok = 1; + break; + default: + break; + } + } + break; + case FTDM_CHANNEL_STATE_UP: + { + ok = 1; + switch(state) { + case FTDM_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: + case FTDM_CHANNEL_STATE_RING: + ok = 0; + break; + default: + break; + } + } + break; + case FTDM_CHANNEL_STATE_DOWN: + { + ok = 0; + + switch(state) { + case FTDM_CHANNEL_STATE_DIALTONE: + case FTDM_CHANNEL_STATE_COLLECT: + case FTDM_CHANNEL_STATE_DIALING: + case FTDM_CHANNEL_STATE_RING: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: + case FTDM_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_GET_CALLERID: + case FTDM_CHANNEL_STATE_GENRING: + ok = 1; + break; + default: + break; + } + } + break; + case FTDM_CHANNEL_STATE_BUSY: + { + switch(state) { + case FTDM_CHANNEL_STATE_UP: + ok = 0; + break; + default: + break; + } + } + break; + case FTDM_CHANNEL_STATE_RING: + { + switch(state) { + case FTDM_CHANNEL_STATE_UP: + ok = 1; + break; + default: + break; + } + } + break; + default: + break; + } + + end: + + if (state == ftdmchan->state) { + ok = 0; + } + + + if (ok) { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_set_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); + ftdmchan->last_state = ftdmchan->state; + ftdmchan->state = state; + } + + if (lock) { + ftdm_mutex_unlock(ftdmchan->mutex); + } + + return ok ? FTDM_SUCCESS : FTDM_FAIL; +} + + +FT_DECLARE(ftdm_status_t) ftdm_group_channel_use_count(ftdm_group_t *group, uint32_t *count) +{ + uint32_t j; + + *count = 0; + + if (!group) { + return FTDM_FAIL; + } + + for(j = 0; j < group->chan_count && group->channels[j]; j++) { + if (group->channels[j]) { + if (ftdm_test_flag(group->channels[j], FTDM_CHANNEL_INUSE)) { + (*count)++; + } + } + } + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan) +{ + ftdm_status_t status = FTDM_FAIL; + ftdm_channel_t *check; + uint32_t i, count; + ftdm_group_t *group = NULL; + + if (group_id) { + ftdm_group_find(group_id, &group); + } + + if (!group ) { + ftdm_log(FTDM_LOG_CRIT, "GROUP NOT DEFINED!\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } + + ftdm_group_channel_use_count(group, &count); + + if (count >= group->chan_count) { + ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } + + + if (direction == FTDM_TOP_DOWN) { + i = 0; + } else { + i = group->chan_count-1; + } + + ftdm_mutex_lock(group->mutex); + for (;;) { + if (direction == FTDM_TOP_DOWN) { + if (i >= group->chan_count) { + break; + } + } else { + if (i < 0) { + break; + } + } + + if (!(check = group->channels[i])) { + status = FTDM_FAIL; + break; + } + + if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && + !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && + !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && + check->state == FTDM_CHANNEL_STATE_DOWN && + check->type != FTDM_CHAN_TYPE_DQ921 && + check->type != FTDM_CHAN_TYPE_DQ931 + + ) { + ftdm_span_t* span = NULL; + ftdm_span_find(check->span_id, &span); + if (span && span->channel_request) { + status = span->channel_request(span, check->chan_id, direction, caller_data, ftdmchan); + break; + } + + status = check->zio->open(check); + + if (status == FTDM_SUCCESS) { + ftdm_set_flag(check, FTDM_CHANNEL_INUSE); + ftdm_channel_open_chan(check); + *ftdmchan = check; + break; + } + } + + if (direction == FTDM_TOP_DOWN) { + i++; + } else { + i--; + } + } + ftdm_mutex_unlock(group->mutex); + return status; +} + + +FT_DECLARE(ftdm_status_t) ftdm_span_channel_use_count(ftdm_span_t *span, uint32_t *count) +{ + uint32_t j; + + *count = 0; + + if (!span || !ftdm_test_flag(span, FTDM_SPAN_CONFIGURED)) { + return FTDM_FAIL; + } + + for(j = 1; j <= span->chan_count && span->channels[j]; j++) { + if (span->channels[j]) { + if (ftdm_test_flag(span->channels[j], FTDM_CHANNEL_INUSE)) { + (*count)++; + } + } + } + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan) +{ + ftdm_status_t status = FTDM_FAIL; + ftdm_channel_t *check; + uint32_t i, j, count; + ftdm_span_t *span = NULL; + uint32_t span_max; + + if (span_id) { + ftdm_span_find(span_id, &span); + + if (!span || !ftdm_test_flag(span, FTDM_SPAN_CONFIGURED)) { + ftdm_log(FTDM_LOG_CRIT, "SPAN NOT DEFINED!\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } + + ftdm_span_channel_use_count(span, &count); + + if (count >= span->chan_count) { + ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } + + if (span->channel_request && !span->suggest_chan_id) { + return span->channel_request(span, 0, direction, caller_data, ftdmchan); + } + + span_max = span_id; + j = span_id; + } else { + ftdm_log(FTDM_LOG_CRIT, "No span supplied\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } + + ftdm_mutex_lock(span->mutex); + + if (direction == FTDM_TOP_DOWN) { + i = 1; + } else { + i = span->chan_count; + } + + for(;;) { + + if (direction == FTDM_TOP_DOWN) { + if (i > span->chan_count) { + break; + } + } else { + if (i == 0) { + break; + } + } + + if (!(check = span->channels[i])) { + status = FTDM_FAIL; + break; + } + + if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && + !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && + !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && + check->state == FTDM_CHANNEL_STATE_DOWN && + check->type != FTDM_CHAN_TYPE_DQ921 && + check->type != FTDM_CHAN_TYPE_DQ931 + + ) { + + if (span && span->channel_request) { + status = span->channel_request(span, i, direction, caller_data, ftdmchan); + break; + } + + status = check->zio->open(check); + + if (status == FTDM_SUCCESS) { + ftdm_set_flag(check, FTDM_CHANNEL_INUSE); + ftdm_channel_open_chan(check); + *ftdmchan = check; + break; + } + } + + if (direction == FTDM_TOP_DOWN) { + i++; + } else { + i--; + } + } + + ftdm_mutex_unlock(span->mutex); + + return status; +} + +static ftdm_status_t ftdm_channel_reset(ftdm_channel_t *ftdmchan) +{ + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_OPEN); + ftdmchan->event_callback = NULL; + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_DTMF_DETECT); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_SUPRESS_DTMF); + ftdm_channel_done(ftdmchan); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_HOLD); + + memset(ftdmchan->tokens, 0, sizeof(ftdmchan->tokens)); + ftdmchan->token_count = 0; + + if (ftdmchan->dtmf_buffer) { + ftdm_buffer_zero(ftdmchan->dtmf_buffer); + } + + if (ftdmchan->gen_dtmf_buffer) { + ftdm_buffer_zero(ftdmchan->gen_dtmf_buffer); + } + + if (ftdmchan->digit_buffer) { + ftdm_buffer_zero(ftdmchan->digit_buffer); + } + + if (!ftdmchan->dtmf_on) { + ftdmchan->dtmf_on = FTDM_DEFAULT_DTMF_ON; + } + + if (!ftdmchan->dtmf_off) { + ftdmchan->dtmf_off = FTDM_DEFAULT_DTMF_OFF; + } + + memset(ftdmchan->dtmf_hangup_buf, '\0', ftdmchan->span->dtmf_hangup_len); + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE)) { + ftdmchan->effective_codec = ftdmchan->native_codec; + ftdmchan->packet_len = ftdmchan->native_interval * (ftdmchan->effective_codec == FTDM_CODEC_SLIN ? 16 : 8); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE); + } + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_init(ftdm_channel_t *ftdmchan) +{ + if (ftdmchan->init_state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_set_state_locked(ftdmchan, ftdmchan->init_state); + ftdmchan->init_state = FTDM_CHANNEL_STATE_DOWN; + } + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan) +{ + ftdm_status_t status = FTDM_FAIL; + + assert(ftdmchan != NULL); + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SUSPENDED)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is suspended"); + return FTDM_FAIL; + } + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY) || (status = ftdm_mutex_trylock(ftdmchan->mutex)) != FTDM_SUCCESS) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Channel is not ready or is in use %d %d", ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY), status); + return status; + } + + status = FTDM_FAIL; + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY)) { + status = ftdmchan->span->zio->open(ftdmchan); + if (status == FTDM_SUCCESS) { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OPEN | FTDM_CHANNEL_INUSE); + } + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is not ready"); + } + + ftdm_mutex_unlock(ftdmchan->mutex); + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, ftdm_channel_t **ftdmchan) +{ + ftdm_channel_t *check; + ftdm_status_t status = FTDM_FAIL; + ftdm_span_t *span = NULL; + + ftdm_mutex_unlock(globals.mutex); + ftdm_span_find(span_id, &span); + + if (!span || !ftdm_test_flag(span, FTDM_SPAN_CONFIGURED) || chan_id >= FTDM_MAX_CHANNELS_SPAN) { + ftdm_log(FTDM_LOG_CRIT, "SPAN NOT DEFINED!\n"); + *ftdmchan = NULL; + goto done; + } + + if (span->channel_request) { + ftdm_log(FTDM_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); + *ftdmchan = NULL; + goto done; + } + + if (!(check = span->channels[chan_id])) { + ftdm_log(FTDM_LOG_ERROR, "Invalid Channel %d\n", chan_id); + *ftdmchan = NULL; + goto done; + } + + if (ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || + !ftdm_test_flag(check, FTDM_CHANNEL_READY) || (status = ftdm_mutex_trylock(check->mutex)) != FTDM_SUCCESS) { + *ftdmchan = NULL; + goto done; + } + + status = FTDM_FAIL; + + if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && (!ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || + (check->type == FTDM_CHAN_TYPE_FXS && check->token_count == 1))) { + if (!ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) { + status = check->zio->open(check); + if (status == FTDM_SUCCESS) { + ftdm_set_flag(check, FTDM_CHANNEL_OPEN); + } + } else { + status = FTDM_SUCCESS; + } + ftdm_set_flag(check, FTDM_CHANNEL_INUSE); + *ftdmchan = check; + } + ftdm_mutex_unlock(check->mutex); + + done: + ftdm_mutex_unlock(globals.mutex); + + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_outgoing_call(ftdm_channel_t *ftdmchan) +{ + ftdm_status_t status; + + assert(ftdmchan != NULL); + + if (ftdmchan->span->outgoing_call) { + if ((status = ftdmchan->span->outgoing_call(ftdmchan)) == FTDM_SUCCESS) { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + } + return status; + } else { + ftdm_log(FTDM_LOG_ERROR, "outgoing_call method not implemented!\n"); + } + + return FTDM_FAIL; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_set_sig_status(ftdm_channel_t *ftdmchan, ftdm_signaling_status_t sigstatus) +{ + ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "Null channel\n"); + ftdm_assert_return(ftdmchan->span != NULL, FTDM_FAIL, "Null span\n"); + + if (ftdmchan->span->set_channel_sig_status) { + return ftdmchan->span->set_channel_sig_status(ftdmchan, sigstatus); + } else { + ftdm_log(FTDM_LOG_ERROR, "set_channel_sig_status method not implemented!\n"); + return FTDM_FAIL; + } +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_get_sig_status(ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *sigstatus) +{ + ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "Null channel\n"); + ftdm_assert_return(ftdmchan->span != NULL, FTDM_FAIL, "Null span\n"); + ftdm_assert_return(sigstatus != NULL, FTDM_FAIL, "Null sig status parameter\n"); + + if (ftdmchan->span->get_channel_sig_status) { + return ftdmchan->span->get_channel_sig_status(ftdmchan, sigstatus); + } else { + ftdm_log(FTDM_LOG_ERROR, "get_channel_sig_status method not implemented!\n"); + return FTDM_FAIL; + } +} + +FT_DECLARE(ftdm_status_t) ftdm_span_set_sig_status(ftdm_span_t *span, ftdm_signaling_status_t sigstatus) +{ + ftdm_assert_return(span != NULL, FTDM_FAIL, "Null span\n"); + + if (span->set_span_sig_status) { + return span->set_span_sig_status(span, sigstatus); + } else { + ftdm_log(FTDM_LOG_ERROR, "set_span_sig_status method not implemented!\n"); + return FTDM_FAIL; + } +} + +FT_DECLARE(ftdm_status_t) ftdm_span_get_sig_status(ftdm_span_t *span, ftdm_signaling_status_t *sigstatus) +{ + ftdm_assert_return(span != NULL, FTDM_FAIL, "Null span\n"); + ftdm_assert_return(sigstatus != NULL, FTDM_FAIL, "Null sig status parameter\n"); + + if (span->get_span_sig_status) { + return span->get_span_sig_status(span, sigstatus); + } else { + ftdm_log(FTDM_LOG_ERROR, "get_span_sig_status method not implemented!\n"); + return FTDM_FAIL; + } +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_done(ftdm_channel_t *ftdmchan) +{ + assert(ftdmchan != NULL); + + ftdm_mutex_lock(ftdmchan->mutex); + + memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data)); + + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_INUSE); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_WINK); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_FLASH); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_HOLD); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_RINGING); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_PROGRESS_DETECT); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_3WAY); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_PROGRESS); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_MEDIA); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_ANSWERED); + ftdm_mutex_lock(ftdmchan->pre_buffer_mutex); + ftdm_buffer_destroy(&ftdmchan->pre_buffer); + ftdmchan->pre_buffer_size = 0; + ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex); + + ftdmchan->init_state = FTDM_CHANNEL_STATE_DOWN; + ftdmchan->state = FTDM_CHANNEL_STATE_DOWN; + + ftdm_log(FTDM_LOG_DEBUG, "channel done %u:%u\n", ftdmchan->span_id, ftdmchan->chan_id); + + ftdm_mutex_unlock(ftdmchan->mutex); + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_use(ftdm_channel_t *ftdmchan) +{ + + assert(ftdmchan != NULL); + + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_close(ftdm_channel_t **ftdmchan) +{ + ftdm_channel_t *check; + ftdm_status_t status = FTDM_FAIL; + + assert(ftdmchan != NULL); + check = *ftdmchan; + *ftdmchan = NULL; + + if (!check) { + return FTDM_FAIL; + } + + if (!ftdm_test_flag(check, FTDM_CHANNEL_INUSE)) { + ftdm_log(FTDM_LOG_WARNING, "Called ftdm_channel_close but never ftdm_channel_open in chan %d:%d??\n", check->span_id, check->chan_id); + return FTDM_FAIL; + } + + if (ftdm_test_flag(check, FTDM_CHANNEL_CONFIGURED)) { + ftdm_mutex_lock(check->mutex); + if (ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) { + status = check->zio->close(check); + if (status == FTDM_SUCCESS) { + ftdm_clear_flag(check, FTDM_CHANNEL_INUSE); + ftdm_channel_reset(check); + *ftdmchan = NULL; + } + } + check->ring_count = 0; + ftdm_mutex_unlock(check->mutex); + } + + return status; +} + + +static ftdm_status_t ftdmchan_activate_dtmf_buffer(ftdm_channel_t *ftdmchan) +{ + + if (!ftdmchan->dtmf_buffer) { + if (ftdm_buffer_create(&ftdmchan->dtmf_buffer, 1024, 3192, 0) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "buffer error"); + return FTDM_FAIL; + } else { + ftdm_log(FTDM_LOG_DEBUG, "Created DTMF Buffer!\n"); + } + } + + + if (!ftdmchan->tone_session.buffer) { + memset(&ftdmchan->tone_session, 0, sizeof(ftdmchan->tone_session)); + teletone_init_session(&ftdmchan->tone_session, 0, NULL, NULL); + } + + ftdmchan->tone_session.rate = ftdmchan->rate; + ftdmchan->tone_session.duration = ftdmchan->dtmf_on * (ftdmchan->tone_session.rate / 1000); + ftdmchan->tone_session.wait = ftdmchan->dtmf_off * (ftdmchan->tone_session.rate / 1000); + ftdmchan->tone_session.volume = -7; + + /* + ftdmchan->tone_session.debug = 1; + ftdmchan->tone_session.debug_stream = stdout; + */ + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_command_t command, void *obj) +{ + ftdm_status_t status = FTDM_FAIL; + + assert(ftdmchan != NULL); + assert(ftdmchan->zio != NULL); + + ftdm_mutex_lock(ftdmchan->mutex); + + switch(command) { + + case FTDM_COMMAND_ENABLE_CALLERID_DETECT: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_CALLERID)) { + if (ftdm_fsk_demod_init(&ftdmchan->fsk, ftdmchan->rate, ftdmchan->fsk_buf, sizeof(ftdmchan->fsk_buf)) != FTDM_SUCCESS) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, FTDM_FAIL); + } + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT); + } + } + break; + case FTDM_COMMAND_DISABLE_CALLERID_DETECT: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_CALLERID)) { + ftdm_fsk_demod_destroy(&ftdmchan->fsk); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT); + } + } + break; + case FTDM_COMMAND_TRACE_INPUT: + { + char *path = (char *) obj; + if (ftdmchan->fds[0] > 0) { + close(ftdmchan->fds[0]); + ftdmchan->fds[0] = -1; + } + if ((ftdmchan->fds[0] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + ftdm_log(FTDM_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, path); + GOTO_STATUS(done, FTDM_SUCCESS); + } + + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, FTDM_FAIL); + } + break; + case FTDM_COMMAND_TRACE_OUTPUT: + { + char *path = (char *) obj; + if (ftdmchan->fds[1] > 0) { + close(ftdmchan->fds[1]); + ftdmchan->fds[1] = -1; + } + if ((ftdmchan->fds[1] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + ftdm_log(FTDM_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, path); + GOTO_STATUS(done, FTDM_SUCCESS); + } + + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + GOTO_STATUS(done, FTDM_FAIL); + } + break; + case FTDM_COMMAND_SET_INTERVAL: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_INTERVAL)) { + ftdmchan->effective_interval = FTDM_COMMAND_OBJ_INT; + if (ftdmchan->effective_interval == ftdmchan->native_interval) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_BUFFER); + } else { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_BUFFER); + } + ftdmchan->packet_len = ftdmchan->native_interval * (ftdmchan->effective_codec == FTDM_CODEC_SLIN ? 16 : 8); + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_GET_INTERVAL: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_INTERVAL)) { + FTDM_COMMAND_OBJ_INT = ftdmchan->effective_interval; + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_SET_CODEC: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_CODECS)) { + ftdmchan->effective_codec = FTDM_COMMAND_OBJ_INT; + + if (ftdmchan->effective_codec == ftdmchan->native_codec) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE); + } else { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE); + } + ftdmchan->packet_len = ftdmchan->native_interval * (ftdmchan->effective_codec == FTDM_CODEC_SLIN ? 16 : 8); + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + + case FTDM_COMMAND_SET_NATIVE_CODEC: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_CODECS)) { + ftdmchan->effective_codec = ftdmchan->native_codec; + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE); + ftdmchan->packet_len = ftdmchan->native_interval * (ftdmchan->effective_codec == FTDM_CODEC_SLIN ? 16 : 8); + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + + case FTDM_COMMAND_GET_CODEC: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_CODECS)) { + FTDM_COMMAND_OBJ_INT = ftdmchan->effective_codec; + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_GET_NATIVE_CODEC: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_CODECS)) { + FTDM_COMMAND_OBJ_INT = ftdmchan->native_codec; + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_ENABLE_PROGRESS_DETECT: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_PROGRESS)) { + /* if they don't have thier own, use ours */ + ftdm_channel_clear_detected_tones(ftdmchan); + ftdm_channel_clear_needed_tones(ftdmchan); + teletone_multi_tone_init(&ftdmchan->span->tone_finder[FTDM_TONEMAP_DIAL], &ftdmchan->span->tone_detect_map[FTDM_TONEMAP_DIAL]); + teletone_multi_tone_init(&ftdmchan->span->tone_finder[FTDM_TONEMAP_RING], &ftdmchan->span->tone_detect_map[FTDM_TONEMAP_RING]); + teletone_multi_tone_init(&ftdmchan->span->tone_finder[FTDM_TONEMAP_BUSY], &ftdmchan->span->tone_detect_map[FTDM_TONEMAP_BUSY]); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_PROGRESS_DETECT); + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_DISABLE_PROGRESS_DETECT: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_PROGRESS)) { + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_PROGRESS_DETECT); + ftdm_channel_clear_detected_tones(ftdmchan); + ftdm_channel_clear_needed_tones(ftdmchan); + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_ENABLE_DTMF_DETECT: + { + /* if they don't have thier own, use ours */ + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_DETECT)) { + ftdm_tone_type_t tt = FTDM_COMMAND_OBJ_INT; + if (tt == FTDM_TONE_DTMF) { + teletone_dtmf_detect_init (&ftdmchan->dtmf_detect, ftdmchan->rate); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_DTMF_DETECT); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_SUPRESS_DTMF); + GOTO_STATUS(done, FTDM_SUCCESS); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "invalid command"); + GOTO_STATUS(done, FTDM_FAIL); + } + } + } + break; + case FTDM_COMMAND_DISABLE_DTMF_DETECT: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_DETECT)) { + ftdm_tone_type_t tt = FTDM_COMMAND_OBJ_INT; + if (tt == FTDM_TONE_DTMF) { + teletone_dtmf_detect_init (&ftdmchan->dtmf_detect, ftdmchan->rate); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_DTMF_DETECT); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_SUPRESS_DTMF); + GOTO_STATUS(done, FTDM_SUCCESS); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "invalid command"); + GOTO_STATUS(done, FTDM_FAIL); + } + } + } + + case FTDM_COMMAND_SET_PRE_BUFFER_SIZE: + { + int val = FTDM_COMMAND_OBJ_INT; + + if (val < 0) { + val = 0; + } + + ftdmchan->pre_buffer_size = val * 8; + + ftdm_mutex_lock(ftdmchan->pre_buffer_mutex); + if (!ftdmchan->pre_buffer_size) { + ftdm_buffer_destroy(&ftdmchan->pre_buffer); + } else if (!ftdmchan->pre_buffer) { + ftdm_buffer_create(&ftdmchan->pre_buffer, 1024, ftdmchan->pre_buffer_size, 0); + } + ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex); + + GOTO_STATUS(done, FTDM_SUCCESS); + + } + break; + case FTDM_COMMAND_GET_DTMF_ON_PERIOD: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_GENERATE)) { + FTDM_COMMAND_OBJ_INT = ftdmchan->dtmf_on; + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_GET_DTMF_OFF_PERIOD: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_GENERATE)) { + FTDM_COMMAND_OBJ_INT = ftdmchan->dtmf_on; + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + case FTDM_COMMAND_SET_DTMF_ON_PERIOD: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_GENERATE)) { + int val = FTDM_COMMAND_OBJ_INT; + if (val > 10 && val < 1000) { + ftdmchan->dtmf_on = val; + GOTO_STATUS(done, FTDM_SUCCESS); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "invalid value %d range 10-1000", val); + GOTO_STATUS(done, FTDM_FAIL); + } + } + } + break; + case FTDM_COMMAND_SET_DTMF_OFF_PERIOD: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_GENERATE)) { + int val = FTDM_COMMAND_OBJ_INT; + if (val > 10 && val < 1000) { + ftdmchan->dtmf_off = val; + GOTO_STATUS(done, FTDM_SUCCESS); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "invalid value %d range 10-1000", val); + GOTO_STATUS(done, FTDM_FAIL); + } + } + } + break; + case FTDM_COMMAND_SEND_DTMF: + { + if (!ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_GENERATE)) { + char *digits = FTDM_COMMAND_OBJ_CHAR_P; + + if ((status = ftdmchan_activate_dtmf_buffer(ftdmchan)) != FTDM_SUCCESS) { + GOTO_STATUS(done, status); + } + + ftdm_buffer_write(ftdmchan->gen_dtmf_buffer, digits, strlen(digits)); + + GOTO_STATUS(done, FTDM_SUCCESS); + } + } + break; + + case FTDM_COMMAND_DISABLE_ECHOCANCEL: + { + ftdm_mutex_lock(ftdmchan->pre_buffer_mutex); + ftdm_buffer_destroy(&ftdmchan->pre_buffer); + ftdmchan->pre_buffer_size = 0; + ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex); + } + break; + + /* FIXME: validate user gain values */ + case FTDM_COMMAND_SET_RX_GAIN: + { + ftdmchan->rxgain = FTDM_COMMAND_OBJ_FLOAT; + reset_gain_table(ftdmchan->rxgain_table, ftdmchan->rxgain, ftdmchan->native_codec); + if (ftdmchan->rxgain == 0.0) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_USE_RX_GAIN); + } else { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_USE_RX_GAIN); + } + } + break; + case FTDM_COMMAND_GET_RX_GAIN: + { + FTDM_COMMAND_OBJ_FLOAT = ftdmchan->rxgain; + } + break; + case FTDM_COMMAND_SET_TX_GAIN: + { + ftdmchan->txgain = FTDM_COMMAND_OBJ_FLOAT; + reset_gain_table(ftdmchan->txgain_table, ftdmchan->txgain, ftdmchan->native_codec); + if (ftdmchan->txgain == 0.0) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_USE_TX_GAIN); + } else { + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_USE_TX_GAIN); + } + } + break; + case FTDM_COMMAND_GET_TX_GAIN: + { + FTDM_COMMAND_OBJ_FLOAT = ftdmchan->txgain; + } + break; + default: + break; + } + + if (!ftdmchan->zio->command) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); + ftdm_log(FTDM_LOG_ERROR, "no command function defined by the I/O freetdm module!\n"); + GOTO_STATUS(done, FTDM_FAIL); + } + + status = ftdmchan->zio->command(ftdmchan, command, obj); + + if (status == FTDM_NOTIMPL) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "I/O command %d not implemented in backend", command); + ftdm_log(FTDM_LOG_ERROR, "I/O backend does not support command %d!\n", command); + } +done: + ftdm_mutex_unlock(ftdmchan->mutex); + return status; + +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_wait(ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to) +{ + assert(ftdmchan != NULL); + assert(ftdmchan->zio != NULL); + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); + return FTDM_FAIL; + } + + if (!ftdmchan->zio->wait) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); + return FTDM_FAIL; + } + + return ftdmchan->zio->wait(ftdmchan, flags, to); + +} + +/*******************************/ +ZIO_CODEC_FUNCTION(zio_slin2ulaw) +{ + int16_t sln_buf[512] = {0}, *sln = sln_buf; + uint8_t *lp = data; + uint32_t i; + ftdm_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(sln, data, max); + + for(i = 0; i < max; i++) { + *lp++ = linear_to_ulaw(*sln++); + } + + *datalen = max / 2; + + return FTDM_SUCCESS; + +} + + +ZIO_CODEC_FUNCTION(zio_ulaw2slin) +{ + int16_t *sln = data; + uint8_t law[1024] = {0}, *lp = law; + uint32_t i; + ftdm_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(law, data, max); + + for(i = 0; i < max; i++) { + *sln++ = ulaw_to_linear(*lp++); + } + + *datalen = max * 2; + + return FTDM_SUCCESS; +} + +ZIO_CODEC_FUNCTION(zio_slin2alaw) +{ + int16_t sln_buf[512] = {0}, *sln = sln_buf; + uint8_t *lp = data; + uint32_t i; + ftdm_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(sln, data, max); + + for(i = 0; i < max; i++) { + *lp++ = linear_to_alaw(*sln++); + } + + *datalen = max / 2; + + return FTDM_SUCCESS; + +} + + +ZIO_CODEC_FUNCTION(zio_alaw2slin) +{ + int16_t *sln = data; + uint8_t law[1024] = {0}, *lp = law; + uint32_t i; + ftdm_size_t len = *datalen; + + if (max > len) { + max = len; + } + + memcpy(law, data, max); + + for(i = 0; i < max; i++) { + *sln++ = alaw_to_linear(*lp++); + } + + *datalen = max * 2; + + return FTDM_SUCCESS; +} + +ZIO_CODEC_FUNCTION(zio_ulaw2alaw) +{ + ftdm_size_t len = *datalen; + uint32_t i; + uint8_t *lp = data; + + if (max > len) { + max = len; + } + + for(i = 0; i < max; i++) { + *lp = ulaw_to_alaw(*lp); + lp++; + } + + return FTDM_SUCCESS; +} + +ZIO_CODEC_FUNCTION(zio_alaw2ulaw) +{ + ftdm_size_t len = *datalen; + uint32_t i; + uint8_t *lp = data; + + if (max > len) { + max = len; + } + + for(i = 0; i < max; i++) { + *lp = alaw_to_ulaw(*lp); + lp++; + } + + return FTDM_SUCCESS; +} + +/******************************/ + +FT_DECLARE(void) ftdm_channel_clear_detected_tones(ftdm_channel_t *ftdmchan) +{ + uint32_t i; + + memset(ftdmchan->detected_tones, 0, sizeof(ftdmchan->detected_tones[0]) * FTDM_TONEMAP_INVALID); + + for (i = 1; i < FTDM_TONEMAP_INVALID; i++) { + ftdmchan->span->tone_finder[i].tone_count = 0; + } +} + +FT_DECLARE(void) ftdm_channel_clear_needed_tones(ftdm_channel_t *ftdmchan) +{ + memset(ftdmchan->needed_tones, 0, sizeof(ftdmchan->needed_tones[0]) * FTDM_TONEMAP_INVALID); +} + +FT_DECLARE(ftdm_size_t) ftdm_channel_dequeue_dtmf(ftdm_channel_t *ftdmchan, char *dtmf, ftdm_size_t len) +{ + ftdm_size_t bytes = 0; + + assert(ftdmchan != NULL); + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY)) { + return FTDM_FAIL; + } + + if (ftdmchan->digit_buffer && ftdm_buffer_inuse(ftdmchan->digit_buffer)) { + ftdm_mutex_lock(ftdmchan->mutex); + if ((bytes = ftdm_buffer_read(ftdmchan->digit_buffer, dtmf, len)) > 0) { + *(dtmf + bytes) = '\0'; + } + ftdm_mutex_unlock(ftdmchan->mutex); + } + + return bytes; +} + +FT_DECLARE(void) ftdm_channel_flush_dtmf(ftdm_channel_t *ftdmchan) +{ + if (ftdmchan->digit_buffer && ftdm_buffer_inuse(ftdmchan->digit_buffer)) { + ftdm_mutex_lock(ftdmchan->mutex); + ftdm_buffer_zero(ftdmchan->digit_buffer); + ftdm_mutex_unlock(ftdmchan->mutex); + } +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_queue_dtmf(ftdm_channel_t *ftdmchan, const char *dtmf) +{ + ftdm_status_t status; + register ftdm_size_t len, inuse; + ftdm_size_t wr = 0; + const char *p; + + assert(ftdmchan != NULL); + + if (ftdmchan->pre_buffer) { + ftdm_buffer_zero(ftdmchan->pre_buffer); + } + + ftdm_mutex_lock(ftdmchan->mutex); + + inuse = ftdm_buffer_inuse(ftdmchan->digit_buffer); + len = strlen(dtmf); + + if (len + inuse > ftdm_buffer_len(ftdmchan->digit_buffer)) { + ftdm_buffer_toss(ftdmchan->digit_buffer, strlen(dtmf)); + } + + if (ftdmchan->span->dtmf_hangup_len) { + for (p = dtmf; ftdm_is_dtmf(*p); p++) { + memmove (ftdmchan->dtmf_hangup_buf, ftdmchan->dtmf_hangup_buf + 1, ftdmchan->span->dtmf_hangup_len - 1); + ftdmchan->dtmf_hangup_buf[ftdmchan->span->dtmf_hangup_len - 1] = *p; + if (!strcmp(ftdmchan->dtmf_hangup_buf, ftdmchan->span->dtmf_hangup)) { + ftdm_log(FTDM_LOG_DEBUG, "DTMF hangup detected.\n"); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + break; + } + } + } + + p = dtmf; + while (wr < len && p) { + if (ftdm_is_dtmf(*p)) { + wr++; + } else { + break; + } + p++; + } + + status = ftdm_buffer_write(ftdmchan->digit_buffer, dtmf, wr) ? FTDM_SUCCESS : FTDM_FAIL; + ftdm_mutex_unlock(ftdmchan->mutex); + + return status; +} + + +static ftdm_status_t handle_dtmf(ftdm_channel_t *ftdmchan, ftdm_size_t datalen) +{ + ftdm_buffer_t *buffer = NULL; + ftdm_size_t dblen = 0; + int wrote = 0; + + if (ftdmchan->gen_dtmf_buffer && (dblen = ftdm_buffer_inuse(ftdmchan->gen_dtmf_buffer))) { + char digits[128] = ""; + char *cur; + int x = 0; + + if (dblen > sizeof(digits) - 1) { + dblen = sizeof(digits) - 1; + } + + if (ftdm_buffer_read(ftdmchan->gen_dtmf_buffer, digits, dblen) && !ftdm_strlen_zero_buf(digits)) { + ftdm_log(FTDM_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, digits); + + cur = digits; + + if (*cur == 'F') { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_FLASH, NULL); + cur++; + } + + for (; *cur; cur++) { + if ((wrote = teletone_mux_tones(&ftdmchan->tone_session, &ftdmchan->tone_session.TONES[(int)*cur]))) { + ftdm_buffer_write(ftdmchan->dtmf_buffer, ftdmchan->tone_session.buffer, wrote * 2); + x++; + } else { + ftdm_log(FTDM_LOG_ERROR, "%d:%d Problem Adding DTMF SEQ [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, digits); + return FTDM_FAIL; + } + } + + if (x) { + ftdmchan->skip_read_frames = (wrote / (ftdmchan->effective_interval * 8)) + 4; + } + } + } + + + if (!ftdmchan->buffer_delay || --ftdmchan->buffer_delay == 0) { + if (ftdmchan->dtmf_buffer && (dblen = ftdm_buffer_inuse(ftdmchan->dtmf_buffer))) { + buffer = ftdmchan->dtmf_buffer; + } else if (ftdmchan->fsk_buffer && (dblen = ftdm_buffer_inuse(ftdmchan->fsk_buffer))) { + buffer = ftdmchan->fsk_buffer; + } + } + + if (buffer) { + ftdm_size_t dlen = datalen; + uint8_t auxbuf[1024]; + ftdm_size_t len, br, max = sizeof(auxbuf); + + if (ftdmchan->native_codec != FTDM_CODEC_SLIN) { + dlen *= 2; + } + + len = dblen > dlen ? dlen : dblen; + + br = ftdm_buffer_read(buffer, auxbuf, len); + if (br < dlen) { + memset(auxbuf + br, 0, dlen - br); + } + + if (ftdmchan->native_codec != FTDM_CODEC_SLIN) { + if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { + zio_slin2ulaw(auxbuf, max, &dlen); + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { + zio_slin2alaw(auxbuf, max, &dlen); + } + } + + return ftdmchan->zio->write(ftdmchan, auxbuf, &dlen); + } + + return FTDM_SUCCESS; + +} + + +FT_DECLARE(void) ftdm_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor) +{ + int16_t x; + uint32_t i; + int sum_rnd = 0; + int16_t rnd2 = (int16_t) ftdm_current_time_in_ms() * (int16_t) (intptr_t) data; + + assert(divisor); + + for (i = 0; i < samples; i++, sum_rnd = 0) { + for (x = 0; x < 6; x++) { + rnd2 = rnd2 * 31821U + 13849U; + sum_rnd += rnd2 ; + } + //switch_normalize_to_16bit(sum_rnd); + *data = (int16_t) ((int16_t) sum_rnd / (int) divisor); + + data++; + } +} + + + +FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) +{ + ftdm_status_t status = FTDM_FAIL; + zio_codec_t codec_func = NULL; + ftdm_size_t max = *datalen; + unsigned i = 0; + + assert(ftdmchan != NULL); + assert(ftdmchan->zio != NULL); + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); + return FTDM_FAIL; + } + + if (!ftdmchan->zio->read) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); + return FTDM_FAIL; + } + + status = ftdmchan->zio->read(ftdmchan, data, datalen); + if (ftdmchan->fds[0] > -1) { + int dlen = (int) *datalen; + if (write(ftdmchan->fds[0], data, dlen) != dlen) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "file write error!"); + return FTDM_FAIL; + } + } + + if (status == FTDM_SUCCESS) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_USE_RX_GAIN) + && (ftdmchan->native_codec == FTDM_CODEC_ALAW || ftdmchan->native_codec == FTDM_CODEC_ULAW)) { + unsigned char *rdata = data; + for (i = 0; i < *datalen; i++) { + rdata[i] = ftdmchan->rxgain_table[rdata[i]]; + } + } + handle_dtmf(ftdmchan, *datalen); + } + + if (status == FTDM_SUCCESS && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE) && ftdmchan->effective_codec != ftdmchan->native_codec) { + if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + codec_func = zio_ulaw2slin; + } else if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_ALAW) { + codec_func = zio_ulaw2alaw; + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + codec_func = zio_alaw2slin; + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_ULAW) { + codec_func = zio_alaw2ulaw; + } + + if (codec_func) { + status = codec_func(data, max, datalen); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + status = FTDM_FAIL; + } + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_DTMF_DETECT) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS_DETECT) || + ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT)) { + uint8_t sln_buf[1024] = {0}; + int16_t *sln; + ftdm_size_t slen = 0; + char digit_str[80] = ""; + + if (ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + sln = data; + slen = *datalen / 2; + } else { + ftdm_size_t len = *datalen; + uint32_t i; + uint8_t *lp = data; + + slen = sizeof(sln_buf) / 2; + if (len > slen) { + len = slen; + } + + sln = (int16_t *) sln_buf; + for(i = 0; i < len; i++) { + if (ftdmchan->effective_codec == FTDM_CODEC_ULAW) { + *sln++ = ulaw_to_linear(*lp++); + } else if (ftdmchan->effective_codec == FTDM_CODEC_ALAW) { + *sln++ = alaw_to_linear(*lp++); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + return FTDM_FAIL; + } + } + sln = (int16_t *) sln_buf; + slen = len; + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT)) { + if (ftdm_fsk_demod_feed(&ftdmchan->fsk, sln, slen) != FTDM_SUCCESS) { + ftdm_size_t type, mlen; + char str[128], *sp; + + while(ftdm_fsk_data_parse(&ftdmchan->fsk, &type, &sp, &mlen) == FTDM_SUCCESS) { + *(str+mlen) = '\0'; + ftdm_copy_string(str, sp, ++mlen); + ftdm_clean_string(str); + ftdm_log(FTDM_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", ftdm_mdmf_type2str(type), mlen-1, str); + + switch(type) { + case MDMF_DDN: + case MDMF_PHONE_NUM: + { + if (mlen > sizeof(ftdmchan->caller_data.ani)) { + mlen = sizeof(ftdmchan->caller_data.ani); + } + ftdm_set_string(ftdmchan->caller_data.ani.digits, str); + ftdm_set_string(ftdmchan->caller_data.cid_num.digits, ftdmchan->caller_data.ani.digits); + } + break; + case MDMF_NO_NUM: + { + ftdm_set_string(ftdmchan->caller_data.ani.digits, *str == 'P' ? "private" : "unknown"); + ftdm_set_string(ftdmchan->caller_data.cid_name, ftdmchan->caller_data.ani.digits); + } + break; + case MDMF_PHONE_NAME: + { + if (mlen > sizeof(ftdmchan->caller_data.cid_name)) { + mlen = sizeof(ftdmchan->caller_data.cid_name); + } + ftdm_set_string(ftdmchan->caller_data.cid_name, str); + } + break; + case MDMF_NO_NAME: + { + ftdm_set_string(ftdmchan->caller_data.cid_name, *str == 'P' ? "private" : "unknown"); + } + case MDMF_DATETIME: + { + if (mlen > sizeof(ftdmchan->caller_data.cid_date)) { + mlen = sizeof(ftdmchan->caller_data.cid_date); + } + ftdm_set_string(ftdmchan->caller_data.cid_date, str); + } + break; + } + } + ftdm_channel_command(ftdmchan, FTDM_COMMAND_DISABLE_CALLERID_DETECT, NULL); + } + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS_DETECT) && !ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_PROGRESS)) { + uint32_t i; + + for (i = 1; i < FTDM_TONEMAP_INVALID; i++) { + if (ftdmchan->span->tone_finder[i].tone_count) { + if (ftdmchan->needed_tones[i] && teletone_multi_tone_detect(&ftdmchan->span->tone_finder[i], sln, (int)slen)) { + if (++ftdmchan->detected_tones[i]) { + ftdmchan->needed_tones[i] = 0; + ftdmchan->detected_tones[0]++; + } + } + } + } + } + + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_DTMF_DETECT) && !ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_DTMF_DETECT)) { + teletone_dtmf_detect(&ftdmchan->dtmf_detect, sln, (int)slen); + teletone_dtmf_get(&ftdmchan->dtmf_detect, digit_str, sizeof(digit_str)); + + if(*digit_str) { + zio_event_cb_t event_callback = NULL; + + if (ftdmchan->state == FTDM_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) { + ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]++; + } else { + ftdm_channel_queue_dtmf(ftdmchan, digit_str); + + if (ftdmchan->span->event_callback) { + event_callback = ftdmchan->span->event_callback; + } else if (ftdmchan->event_callback) { + event_callback = ftdmchan->event_callback; + } + + if (event_callback) { + ftdmchan->event_header.channel = ftdmchan; + ftdmchan->event_header.e_type = FTDM_EVENT_DTMF; + ftdmchan->event_header.data = digit_str; + event_callback(ftdmchan, &ftdmchan->event_header); + ftdmchan->event_header.e_type = FTDM_EVENT_NONE; + ftdmchan->event_header.data = NULL; + } + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SUPRESS_DTMF)) { + ftdmchan->skip_read_frames = 20; + } + } + } + } + } + + if (ftdmchan->skip_read_frames > 0 || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MUTE)) { + + ftdm_mutex_lock(ftdmchan->pre_buffer_mutex); + if (ftdmchan->pre_buffer && ftdm_buffer_inuse(ftdmchan->pre_buffer)) { + ftdm_buffer_zero(ftdmchan->pre_buffer); + } + ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex); + + + memset(data, 255, *datalen); + + if (ftdmchan->skip_read_frames > 0) { + ftdmchan->skip_read_frames--; + } + } else { + ftdm_mutex_lock(ftdmchan->pre_buffer_mutex); + if (ftdmchan->pre_buffer_size && ftdmchan->pre_buffer) { + ftdm_buffer_write(ftdmchan->pre_buffer, data, *datalen); + if (ftdm_buffer_inuse(ftdmchan->pre_buffer) >= ftdmchan->pre_buffer_size) { + ftdm_buffer_read(ftdmchan->pre_buffer, data, *datalen); + } else { + memset(data, 255, *datalen); + } + } + ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex); + } + + + return status; +} + + +FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t datasize, ftdm_size_t *datalen) +{ + ftdm_status_t status = FTDM_FAIL; + zio_codec_t codec_func = NULL; + ftdm_size_t max = datasize; + unsigned int i = 0; + + assert(ftdmchan != NULL); + assert(ftdmchan->zio != NULL); + + if (!ftdmchan->buffer_delay && + ((ftdmchan->dtmf_buffer && ftdm_buffer_inuse(ftdmchan->dtmf_buffer)) || + (ftdmchan->fsk_buffer && ftdm_buffer_inuse(ftdmchan->fsk_buffer)))) { + /* read size writing DTMF ATM */ + return FTDM_SUCCESS; + } + + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); + return FTDM_FAIL; + } + + if (!ftdmchan->zio->write) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); + return FTDM_FAIL; + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE) && ftdmchan->effective_codec != ftdmchan->native_codec) { + if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + codec_func = zio_slin2ulaw; + } else if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_ALAW) { + codec_func = zio_alaw2ulaw; + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + codec_func = zio_slin2alaw; + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_ULAW) { + codec_func = zio_ulaw2alaw; + } + + if (codec_func) { + status = codec_func(data, max, datalen); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + status = FTDM_FAIL; + } + } + + if (ftdmchan->fds[1] > -1) { + int dlen = (int) *datalen; + if ((write(ftdmchan->fds[1], data, dlen)) != dlen) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "file write error!"); + return FTDM_FAIL; + } + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_USE_TX_GAIN) + && (ftdmchan->native_codec == FTDM_CODEC_ALAW || ftdmchan->native_codec == FTDM_CODEC_ULAW)) { + unsigned char *wdata = data; + for (i = 0; i < *datalen; i++) { + wdata[i] = ftdmchan->txgain_table[wdata[i]]; + } + } + status = ftdmchan->zio->write(ftdmchan, data, datalen); + + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_clear_vars(ftdm_channel_t *ftdmchan) +{ + if(ftdmchan->variable_hash) { + hashtable_destroy(ftdmchan->variable_hash); + } + ftdmchan->variable_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + + if(!ftdmchan->variable_hash) + return FTDM_FAIL; + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_add_var(ftdm_channel_t *ftdmchan, const char *var_name, const char *value) +{ + char *t_name = 0, *t_val = 0; + + if(!ftdmchan->variable_hash || !var_name || !value) + { + return FTDM_FAIL; + } + + t_name = ftdm_strdup(var_name); + t_val = ftdm_strdup(value); + + if(hashtable_insert(ftdmchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) { + return FTDM_SUCCESS; + } + return FTDM_FAIL; +} + +FT_DECLARE(const char *) ftdm_channel_get_var(ftdm_channel_t *ftdmchan, const char *var_name) +{ + if(!ftdmchan->variable_hash || !var_name) + { + return NULL; + } + return (const char *) hashtable_search(ftdmchan->variable_hash, (void *)var_name); +} + +static struct { + ftdm_io_interface_t *pika_interface; +} interfaces; + + +FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd) +{ + ftdm_io_interface_t *zio = NULL; + char *dup = NULL, *p; + char *rval = NULL; + + if (type && !cmd) { + dup = ftdm_strdup(type); + if ((p = strchr(dup, ' '))) { + *p++ = '\0'; + cmd = p; + } + + type = dup; + } + + ftdm_mutex_lock(globals.mutex); + if (!(zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + ftdm_load_module_assume(type); + if ((zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + ftdm_log(FTDM_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + ftdm_mutex_unlock(globals.mutex); + + if (zio && zio->api) { + ftdm_stream_handle_t stream = { 0 }; + ftdm_status_t status; + FTDM_STANDARD_STREAM(stream); + status = zio->api(&stream, cmd); + + if (status != FTDM_SUCCESS) { + ftdm_safe_free(stream.data); + } else { + rval = (char *) stream.data; + } + } + + ftdm_safe_free(dup); + + return rval; +} + + +static ftdm_status_t load_config(void) +{ + char cfg_name[] = "freetdm.conf"; + ftdm_config_t cfg; + char *var, *val; + int catno = -1; + ftdm_span_t *span = NULL; + unsigned configured = 0, d = 0; + char name[80] = ""; + char number[25] = ""; + char group_name[80] = "default"; + ftdm_io_interface_t *zio = NULL; + ftdm_analog_start_type_t tmp; + ftdm_size_t len = 0; + + if (!ftdm_config_open_file(&cfg, cfg_name)) { + return FTDM_FAIL; + } + + while (ftdm_config_next_pair(&cfg, &var, &val)) { + if (*cfg.category == '#') { + if (cfg.catno != catno) { + ftdm_log(FTDM_LOG_DEBUG, "Skipping %s\n", cfg.category); + catno = cfg.catno; + } + } else if (!strncasecmp(cfg.category, "span", 4)) { + if (cfg.catno != catno) { + char *type = cfg.category + 4; + char *name; + + if (*type == ' ') { + type++; + } + + ftdm_log(FTDM_LOG_DEBUG, "found config for span\n"); + catno = cfg.catno; + + if (ftdm_strlen_zero(type)) { + ftdm_log(FTDM_LOG_CRIT, "failure creating span, no type specified.\n"); + span = NULL; + continue; + } + + if ((name = strchr(type, ' '))) { + *name++ = '\0'; + } + + ftdm_mutex_lock(globals.mutex); + if (!(zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + ftdm_load_module_assume(type); + if ((zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + ftdm_log(FTDM_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + ftdm_mutex_unlock(globals.mutex); + + if (!zio) { + ftdm_log(FTDM_LOG_CRIT, "failure creating span, no such type '%s'\n", type); + span = NULL; + continue; + } + + if (!zio->configure_span) { + ftdm_log(FTDM_LOG_CRIT, "failure creating span, no configure_span method for '%s'\n", type); + span = NULL; + continue; + } + + if (ftdm_span_create(zio, &span, name) == FTDM_SUCCESS) { + span->type = ftdm_strdup(type); + d = 0; + + ftdm_log(FTDM_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); + + } else { + ftdm_log(FTDM_LOG_CRIT, "failure creating span of type %s\n", type); + span = NULL; + continue; + } + } + + if (!span) { + continue; + } + + ftdm_log(FTDM_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); + + if (!strcasecmp(var, "trunk_type")) { + span->trunk_type = ftdm_str2ftdm_trunk_type(val); + ftdm_log(FTDM_LOG_DEBUG, "setting trunk type to '%s'\n", ftdm_trunk_type2str(span->trunk_type)); + } else if (!strcasecmp(var, "name")) { + if (!strcasecmp(val, "undef")) { + *name = '\0'; + } else { + ftdm_copy_string(name, val, sizeof(name)); + } + } else if (!strcasecmp(var, "number")) { + if (!strcasecmp(val, "undef")) { + *number = '\0'; + } else { + ftdm_copy_string(number, val, sizeof(number)); + } + } else if (!strcasecmp(var, "analog-start-type")) { + if (span->trunk_type == FTDM_TRUNK_FXS || span->trunk_type == FTDM_TRUNK_FXO || span->trunk_type == FTDM_TRUNK_EM) { + if ((tmp = ftdm_str2ftdm_analog_start_type(val)) != FTDM_ANALOG_START_NA) { + span->start_type = tmp; + ftdm_log(FTDM_LOG_DEBUG, "changing start type to '%s'\n", ftdm_analog_start_type2str(span->start_type)); + } + } else { + ftdm_log(FTDM_LOG_ERROR, "This option is only valid on analog trunks!\n"); + } + } else if (!strcasecmp(var, "fxo-channel")) { + if (span->trunk_type == FTDM_TRUNK_NONE) { + span->trunk_type = FTDM_TRUNK_FXO; + ftdm_log(FTDM_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", ftdm_trunk_type2str(span->trunk_type), + ftdm_analog_start_type2str(span->start_type)); + } + if (span->trunk_type == FTDM_TRUNK_FXO) { + configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_FXO, name, number); + } else { + ftdm_log(FTDM_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); + } + } else if (!strcasecmp(var, "fxs-channel")) { + if (span->trunk_type == FTDM_TRUNK_NONE) { + span->trunk_type = FTDM_TRUNK_FXS; + ftdm_log(FTDM_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", ftdm_trunk_type2str(span->trunk_type), + ftdm_analog_start_type2str(span->start_type)); + } + if (span->trunk_type == FTDM_TRUNK_FXS) { + configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_FXS, name, number); + } else { + ftdm_log(FTDM_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); + } + } else if (!strcasecmp(var, "em-channel")) { + if (span->trunk_type == FTDM_TRUNK_NONE) { + span->trunk_type = FTDM_TRUNK_EM; + ftdm_log(FTDM_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", ftdm_trunk_type2str(span->trunk_type), + ftdm_analog_start_type2str(span->start_type)); + } + if (span->trunk_type == FTDM_TRUNK_EM) { + configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_EM, name, number); + } else { + ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); + } + } else if (!strcasecmp(var, "b-channel")) { + configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_B, name, number); + ftdm_group_add_channels(group_name, span, val); + } else if (!strcasecmp(var, "d-channel")) { + if (d) { + ftdm_log(FTDM_LOG_WARNING, "ignoring extra d-channel\n"); + } else { + ftdm_chan_type_t qtype; + if (!strncasecmp(val, "lapd:", 5)) { + qtype = FTDM_CHAN_TYPE_DQ931; + val += 5; + } else { + qtype = FTDM_CHAN_TYPE_DQ921; + } + configured += zio->configure_span(span, val, qtype, name, number); + d++; + } + } else if (!strcasecmp(var, "cas-channel")) { + configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_CAS, name, number); + } else if (!strcasecmp(var, "dtmf_hangup")) { + span->dtmf_hangup = ftdm_strdup(val); + span->dtmf_hangup_len = strlen(val); + } else if (!strcasecmp(var, "group")) { + len = strlen(val); + if (len >= sizeof(group_name)) { + len = sizeof(group_name) - 1; + ftdm_log(FTDM_LOG_WARNING, "Truncating group name %s to %zd length\n", val, len); + } + memcpy(group_name, val, len); + group_name[len] = '\0'; + } else { + ftdm_log(FTDM_LOG_ERROR, "unknown span variable '%s'\n", var); + } + } else { + ftdm_log(FTDM_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); + } + } + ftdm_config_close_file(&cfg); + + ftdm_log(FTDM_LOG_INFO, "Configured %u channel(s)\n", configured); + + return configured ? FTDM_SUCCESS : FTDM_FAIL; +} + +static ftdm_status_t process_module_config(ftdm_io_interface_t *zio) +{ + ftdm_config_t cfg; + char *var, *val; + char filename[256] = ""; + + ftdm_assert_return(zio != NULL, FTDM_FAIL, "zio argument is null\n"); + + snprintf(filename, sizeof(filename), "%s.conf", zio->name); + + if (!zio->configure) { + ftdm_log(FTDM_LOG_DEBUG, "Module %s does not support configuration.\n", zio->name); + return FTDM_FAIL; + } + + if (!ftdm_config_open_file(&cfg, filename)) { + ftdm_log(FTDM_LOG_ERROR, "Cannot open %s\n", filename); + return FTDM_FAIL; + } + + while (ftdm_config_next_pair(&cfg, &var, &val)) { + zio->configure(cfg.category, var, val, cfg.lineno); + } + + ftdm_config_close_file(&cfg); + + return FTDM_SUCCESS; +} + +FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t len) +{ +#ifdef WIN32 + const char *ext = ".dll"; + //const char *EXT = ".DLL"; +#define FTDM_MOD_DIR "." //todo +#elif defined (MACOSX) || defined (DARWIN) + const char *ext = ".dylib"; + //const char *EXT = ".DYLIB"; +#else + const char *ext = ".so"; + //const char *EXT = ".SO"; +#endif + if (*name == *FTDM_PATH_SEPARATOR) { + snprintf(path, len, "%s%s", name, ext); + } else { + snprintf(path, len, "%s%s%s%s", FTDM_MOD_DIR, FTDM_PATH_SEPARATOR, name, ext); + } + return path; +} + +FT_DECLARE(ftdm_status_t) ftdm_global_add_io_interface(ftdm_io_interface_t *interface1) +{ + ftdm_status_t ret = FTDM_SUCCESS; + ftdm_mutex_lock(globals.mutex); + if (hashtable_search(globals.interface_hash, (void *)interface1->name)) { + ftdm_log(FTDM_LOG_ERROR, "Interface %s already loaded!\n", interface1->name); + } else { + hashtable_insert(globals.interface_hash, (void *)interface1->name, interface1, HASHTABLE_FLAG_NONE); + } + ftdm_mutex_unlock(globals.mutex); + return ret; +} + +FT_DECLARE(int) ftdm_load_module(const char *name) +{ + ftdm_dso_lib_t lib; + int count = 0, x = 0; + char path[128] = ""; + char *err; + ftdm_module_t *mod; + + ftdm_build_dso_path(name, path, sizeof(path)); + + if (!(lib = ftdm_dso_open(path, &err))) { + ftdm_log(FTDM_LOG_ERROR, "Error loading %s [%s]\n", path, err); + ftdm_safe_free(err); + return 0; + } + + if (!(mod = (ftdm_module_t *) ftdm_dso_func_sym(lib, "ftdm_module", &err))) { + ftdm_log(FTDM_LOG_ERROR, "Error loading %s [%s]\n", path, err); + ftdm_safe_free(err); + return 0; + } + + if (mod->io_load) { + ftdm_io_interface_t *interface1 = NULL; /* name conflict w/windows here */ + + if (mod->io_load(&interface1) != FTDM_SUCCESS || !interface1 || !interface1->name) { + ftdm_log(FTDM_LOG_ERROR, "Error loading %s\n", path); + } else { + ftdm_log(FTDM_LOG_INFO, "Loading IO from %s [%s]\n", path, interface1->name); + if (ftdm_global_add_io_interface(interface1) == FTDM_SUCCESS) { + process_module_config(interface1); + x++; + } + } + } + + if (mod->sig_load) { + if (mod->sig_load() != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error loading %s\n", path); + } else { + ftdm_log(FTDM_LOG_INFO, "Loading SIG from %s\n", path); + x++; + } + } + + if (x) { + char *p; + mod->lib = lib; + ftdm_set_string(mod->path, path); + if (mod->name[0] == '\0') { + if (!(p = strrchr(path, *FTDM_PATH_SEPARATOR))) { + p = path; + } + ftdm_set_string(mod->name, p); + } + + ftdm_mutex_lock(globals.mutex); + if (hashtable_search(globals.module_hash, (void *)mod->name)) { + ftdm_log(FTDM_LOG_ERROR, "Module %s already loaded!\n", mod->name); + ftdm_dso_destroy(&lib); + } else { + hashtable_insert(globals.module_hash, (void *)mod->name, mod, HASHTABLE_FLAG_NONE); + count++; + } + ftdm_mutex_unlock(globals.mutex); + } else { + ftdm_log(FTDM_LOG_ERROR, "Unloading %s\n", path); + ftdm_dso_destroy(&lib); + } + + return count; +} + +FT_DECLARE(int) ftdm_load_module_assume(const char *name) +{ + char buf[256] = ""; + + snprintf(buf, sizeof(buf), "ftmod_%s", name); + return ftdm_load_module(buf); +} + +FT_DECLARE(int) ftdm_load_modules(void) +{ + char cfg_name[] = "modules.conf"; + ftdm_config_t cfg; + char *var, *val; + int count = 0; + + if (!ftdm_config_open_file(&cfg, cfg_name)) { + return FTDM_FAIL; + } + + while (ftdm_config_next_pair(&cfg, &var, &val)) { + if (!strcasecmp(cfg.category, "modules")) { + if (!strcasecmp(var, "load")) { + count += ftdm_load_module(val); + } + } + } + + return count; +} + +FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void) +{ + ftdm_hash_iterator_t *i; + ftdm_dso_lib_t lib; + + for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { + const void *key; + void *val; + + hashtable_this(i, &key, NULL, &val); + + if (key && val) { + ftdm_module_t *mod = (ftdm_module_t *) val; + + if (!mod) { + continue; + } + + if (mod->io_unload) { + if (mod->io_unload() == FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_INFO, "Unloading IO %s\n", mod->name); + } else { + ftdm_log(FTDM_LOG_ERROR, "Error unloading IO %s\n", mod->name); + } + } + + if (mod->sig_unload) { + if (mod->sig_unload() == FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_INFO, "Unloading SIG %s\n", mod->name); + } else { + ftdm_log(FTDM_LOG_ERROR, "Error unloading SIG %s\n", mod->name); + } + } + + + ftdm_log(FTDM_LOG_INFO, "Unloading %s\n", mod->path); + lib = mod->lib; + ftdm_dso_destroy(&lib); + + } + } + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ...) +{ + ftdm_module_t *mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type); + ftdm_status_t status = FTDM_FAIL; + + if (!mod) { + ftdm_load_module_assume(type); + if ((mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type))) { + ftdm_log(FTDM_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + + if (mod && mod->sig_configure) { + va_list ap; + va_start(ap, sig_cb); + status = mod->sig_configure(span, sig_cb, ap); + va_end(ap); + } else { + ftdm_log(FTDM_LOG_ERROR, "can't find '%s'\n", type); + status = FTDM_FAIL; + } + + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters) +{ + ftdm_module_t *mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type); + ftdm_status_t status = FTDM_FAIL; + + ftdm_assert_return(type != NULL, FTDM_FAIL, "No signaling type"); + ftdm_assert_return(span != NULL, FTDM_FAIL, "No span"); + ftdm_assert_return(sig_cb != NULL, FTDM_FAIL, "No signaling callback"); + ftdm_assert_return(parameters != NULL, FTDM_FAIL, "No parameters"); + + if (!mod) { + ftdm_load_module_assume(type); + if ((mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type))) { + ftdm_log(FTDM_LOG_INFO, "auto-loaded '%s'\n", type); + } + } + + if (!mod) { + ftdm_log(FTDM_LOG_ERROR, "Failed to load module type: %s\n", type); + return FTDM_FAIL; + } + + if (mod->configure_span_signaling) { + status = mod->configure_span_signaling(span, sig_cb, parameters); + } else { + ftdm_log(FTDM_LOG_ERROR, "Module %s did not implement the signaling configuration method\n", type); + } + + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span) +{ + if (span->start) { + return span->start(span); + } + + return FTDM_FAIL; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan) +{ + int i; + ftdm_group_t* group = NULL; + + ftdm_mutex_lock(globals.group_mutex); + + if (ftdm_group_find_by_name(name, &group) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_DEBUG, "Creating new group:%s\n", name); + ftdm_group_create(&group, name); + } + + /*verify that group does not already include this channel first */ + for(i=0; i < group->chan_count; i++) { + if (group->channels[i]->physical_span_id == ftdmchan->physical_span_id && + group->channels[i]->physical_chan_id == ftdmchan->physical_chan_id) { + + ftdm_mutex_unlock(globals.group_mutex); + return FTDM_SUCCESS; + } + } + + if (group->chan_count >= FTDM_MAX_CHANNELS_GROUP) { + ftdm_log(FTDM_LOG_CRIT, "Max number of channels exceeded (max:%d)\n", FTDM_MAX_CHANNELS_GROUP); + ftdm_mutex_unlock(globals.group_mutex); + return FTDM_FAIL; + } + + group->channels[group->chan_count++] = ftdmchan; + ftdm_mutex_unlock(globals.group_mutex); + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ftdm_channel_t* ftdmchan) +{ + //Need to test this function + ftdm_mutex_lock(globals.group_mutex); + int i, j; + + for (i=0; i < group->chan_count; i++) { + if (group->channels[i]->physical_span_id == ftdmchan->physical_span_id && + group->channels[i]->physical_chan_id == ftdmchan->physical_chan_id) { + + j=i; + while(j < group->chan_count-1) { + group->channels[j] = group->channels[j+1]; + j++; + } + group->channels[group->chan_count--] = NULL; + if (group->chan_count <=0) { + /* Delete group if it is empty */ + hashtable_remove(globals.group_hash, (void *)group->name); + } + ftdm_mutex_unlock(globals.group_mutex); + return FTDM_SUCCESS; + } + } + + ftdm_mutex_unlock(globals.group_mutex); + //Group does not contain this channel + return FTDM_FAIL; +} + +FT_DECLARE(ftdm_status_t) ftdm_group_add_channels(const char* name, ftdm_span_t* span, const char* val) +{ + char *p, *mydata, *item_list[10]; + int items, i; + + assert(strlen(name) > 0); + + p = strchr(val, ':'); + mydata = ftdm_strdup(++p); + + ftdm_assert_return(mydata != NULL, FTDM_FAIL, "ftdm_strdup failed when adding channels\n"); + + items = ftdm_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); + + for(i=0; i < items; i++) { + if (!strchr(item_list[i], '-')) { + int chan_no; + + chan_no = atoi (item_list[i]); + ftdm_assert(chan_no > 0, "Channel number is not bigger than zero, expect a nasty failure!\n"); + + if (ftdm_channel_add_to_group(name, span->channels[chan_no]) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no, name); + } + } else { + int chan_no_start, chan_no_end; + if (sscanf(item_list[i], "%d-%d", &chan_no_start, &chan_no_end) == 2) { + while (chan_no_start <= chan_no_end) { + if (ftdm_channel_add_to_group(name, span->channels[chan_no_start++])) { + ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no_start-1, name); + } + } + } + } + } + ftdm_safe_free(mydata); + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_group_find(uint32_t id, ftdm_group_t **group) +{ + ftdm_group_t *fgroup = NULL, *grp; + + if (id > FTDM_MAX_GROUPS_INTERFACE) { + return FTDM_FAIL; + } + + + ftdm_mutex_lock(globals.group_mutex); + for (grp = globals.groups; grp; grp = grp->next) { + if (grp->group_id == id) { + fgroup = grp; + break; + } + } + ftdm_mutex_unlock(globals.group_mutex); + + if (!fgroup) { + return FTDM_FAIL; + } + + *group = fgroup; + + return FTDM_SUCCESS; + +} + +FT_DECLARE(ftdm_status_t) ftdm_group_find_by_name(const char *name, ftdm_group_t **group) +{ + ftdm_status_t status = FTDM_FAIL; + *group = NULL; + ftdm_mutex_lock(globals.group_mutex); + if (!ftdm_strlen_zero(name)) { + if ((*group = hashtable_search(globals.group_hash, (void *) name))) { + status = FTDM_SUCCESS; + } + } + ftdm_mutex_unlock(globals.group_mutex); + return status; +} + +static void ftdm_group_add(ftdm_group_t *group) +{ + ftdm_group_t *grp; + ftdm_mutex_lock(globals.group_mutex); + + for (grp = globals.groups; grp && grp->next; grp = grp->next); + + if (grp) { + grp->next = group; + } else { + globals.groups = group; + } + hashtable_insert(globals.group_hash, (void *)group->name, group, HASHTABLE_FLAG_NONE); + + ftdm_mutex_unlock(globals.group_mutex); +} + + +FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *name) +{ + ftdm_group_t *new_group = NULL; + ftdm_status_t status = FTDM_FAIL; + + ftdm_mutex_lock(globals.mutex); + if (globals.group_index < FTDM_MAX_GROUPS_INTERFACE) { + new_group = ftdm_calloc(1, sizeof(*new_group)); + + ftdm_assert(new_group != NULL, "Failed to create new ftdm group, expect a crash\n"); + + status = ftdm_mutex_create(&new_group->mutex); + + ftdm_assert(status == FTDM_SUCCESS, "Failed to create group mutex, expect a crash\n"); + + new_group->group_id = ++globals.group_index; + new_group->name = ftdm_strdup(name); + ftdm_group_add(new_group); + *group = new_group; + status = FTDM_SUCCESS; + } else { + ftdm_log(FTDM_LOG_CRIT, "Group %s was not added, we exceeded the max number of groups\n", name); + } + ftdm_mutex_unlock(globals.mutex); + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_global_init(void) +{ + memset(&globals, 0, sizeof(globals)); + + time_init(); + + ftdm_thread_override_default_stacksize(FTDM_THREAD_STACKSIZE); + + memset(&interfaces, 0, sizeof(interfaces)); + globals.interface_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + globals.module_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + globals.span_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + globals.group_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + ftdm_mutex_create(&globals.mutex); + ftdm_mutex_create(&globals.span_mutex); + ftdm_mutex_create(&globals.group_mutex); + globals.running = 1; + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_global_configuration(void) +{ + int modcount = ftdm_load_modules(); + ftdm_log(FTDM_LOG_NOTICE, "Modules configured: %d \n", modcount); + + if (load_config() != FTDM_SUCCESS) { + globals.running = 0; + ftdm_log(FTDM_LOG_ERROR, "OpenZap global configuration failed!\n"); + return FTDM_FAIL; + } + return FTDM_SUCCESS; +} + +FT_DECLARE(uint32_t) ftdm_running(void) +{ + return globals.running; +} + + +FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) +{ + ftdm_span_t *sp; + + time_end(); + + globals.running = 0; + ftdm_span_close_all(); + ftdm_sleep(1000); + + ftdm_mutex_lock(globals.span_mutex); + for (sp = globals.spans; sp;) { + ftdm_span_t *cur_span = sp; + sp = sp->next; + + if (cur_span) { + if (ftdm_test_flag(cur_span, FTDM_SPAN_CONFIGURED)) { + ftdm_span_destroy(cur_span); + } + + hashtable_remove(globals.span_hash, (void *)cur_span->name); + ftdm_safe_free(cur_span->type); + ftdm_safe_free(cur_span->name); + ftdm_safe_free(cur_span); + cur_span = NULL; + } + } + globals.spans = NULL; + ftdm_mutex_unlock(globals.span_mutex); + + globals.span_index = 0; + + ftdm_unload_modules(); + + ftdm_mutex_lock(globals.mutex); + hashtable_destroy(globals.interface_hash); + hashtable_destroy(globals.module_hash); + hashtable_destroy(globals.span_hash); + ftdm_mutex_unlock(globals.mutex); + ftdm_mutex_destroy(&globals.mutex); + ftdm_mutex_destroy(&globals.span_mutex); + + memset(&globals, 0, sizeof(globals)); + return FTDM_SUCCESS; +} + + +FT_DECLARE(uint32_t) ftdm_separate_string(char *buf, char delim, char **array, int arraylen) +{ + int argc; + char *ptr; + int quot = 0; + char qc = '\''; + int x; + + if (!buf || !array || !arraylen) { + return 0; + } + + memset(array, 0, arraylen * sizeof(*array)); + + ptr = buf; + + for (argc = 0; *ptr && (argc < arraylen - 1); argc++) { + array[argc] = ptr; + for (; *ptr; ptr++) { + if (*ptr == qc) { + if (quot) { + quot--; + } else { + quot++; + } + } else if ((*ptr == delim) && !quot) { + *ptr++ = '\0'; + break; + } + } + } + + if (*ptr) { + array[argc++] = ptr; + } + + /* strip quotes and leading / trailing spaces */ + for (x = 0; x < argc; x++) { + char *p; + + while(*(array[x]) == ' ') { + (array[x])++; + } + p = array[x]; + while((p = strchr(array[x], qc))) { + memmove(p, p+1, strlen(p)); + p++; + } + p = array[x] + (strlen(array[x]) - 1); + while(*p == ' ') { + *p-- = '\0'; + } + } + + return argc; +} + +FT_DECLARE(void) ftdm_bitstream_init(ftdm_bitstream_t *bsp, uint8_t *data, uint32_t datalen, ftdm_endian_t endian, uint8_t ss) +{ + memset(bsp, 0, sizeof(*bsp)); + bsp->data = data; + bsp->datalen = datalen; + bsp->endian = endian; + bsp->ss = ss; + + if (endian < 0) { + bsp->top = bsp->bit_index = 7; + bsp->bot = 0; + } else { + bsp->top = bsp->bit_index = 0; + bsp->bot = 7; + } + +} + +FT_DECLARE(int8_t) ftdm_bitstream_get_bit(ftdm_bitstream_t *bsp) +{ + int8_t bit = -1; + + + if (bsp->byte_index >= bsp->datalen) { + goto done; + } + + if (bsp->ss) { + if (!bsp->ssv) { + bsp->ssv = 1; + return 0; + } else if (bsp->ssv == 2) { + bsp->byte_index++; + bsp->ssv = 0; + return 1; + } + } + + + + + bit = (bsp->data[bsp->byte_index] >> (bsp->bit_index)) & 1; + + if (bsp->bit_index == bsp->bot) { + bsp->bit_index = bsp->top; + if (bsp->ss) { + bsp->ssv = 2; + goto done; + } + + if (++bsp->byte_index > bsp->datalen) { + bit = -1; + goto done; + } + + } else { + bsp->bit_index = bsp->bit_index + bsp->endian; + } + + + done: + return bit; +} + +FT_DECLARE(void) print_hex_bytes(uint8_t *data, ftdm_size_t dlen, char *buf, ftdm_size_t blen) +{ + char *bp = buf; + uint8_t *byte = data; + uint32_t i, j = 0; + + if (blen < (dlen * 3) + 2) { + return; + } + + *bp++ = '['; + j++; + + for(i = 0; i < dlen; i++) { + snprintf(bp, blen-j, "%02x ", *byte++); + bp += 3; + j += 3; + } + + *--bp = ']'; + +} + +FT_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, ftdm_endian_t e, uint8_t ss) +{ + ftdm_bitstream_t bs; + int j = 0, c = 0; + int8_t bit; + uint32_t last; + + if (blen < (bl * 10) + 2) { + return; + } + + ftdm_bitstream_init(&bs, b, bl, e, ss); + last = bs.byte_index; + while((bit = ftdm_bitstream_get_bit(&bs)) > -1) { + buf[j++] = bit ? '1' : '0'; + if (bs.byte_index != last) { + buf[j++] = ' '; + last = bs.byte_index; + if (++c == 8) { + buf[j++] = '\n'; + c = 0; + } + } + } + +} + + + +FT_DECLARE_NONSTD(ftdm_status_t) ftdm_console_stream_raw_write(ftdm_stream_handle_t *handle, uint8_t *data, ftdm_size_t datalen) +{ + ftdm_size_t need = handle->data_len + datalen; + + if (need >= handle->data_size) { + void *new_data; + need += handle->alloc_chunk; + + if (!(new_data = realloc(handle->data, need))) { + return FTDM_MEMERR; + } + + handle->data = new_data; + handle->data_size = need; + } + + memcpy((uint8_t *) (handle->data) + handle->data_len, data, datalen); + handle->data_len += datalen; + handle->end = (uint8_t *) (handle->data) + handle->data_len; + *(uint8_t *)handle->end = '\0'; + + return FTDM_SUCCESS; +} + +FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ +{ +#ifdef HAVE_VASPRINTF + return vasprintf(ret, fmt, ap); +#else + char *buf; + int len; + size_t buflen; + va_list ap2; + char *tmp = NULL; + +#ifdef _MSC_VER +#if _MSC_VER >= 1500 + /* hack for incorrect assumption in msvc header files for code analysis */ + __analysis_assume(tmp); +#endif + ap2 = ap; +#else + va_copy(ap2, ap); +#endif + + len = vsnprintf(tmp, 0, fmt, ap2); + + if (len > 0 && (buf = ftdm_malloc((buflen = (size_t) (len + 1)))) != NULL) { + len = vsnprintf(buf, buflen, fmt, ap); + *ret = buf; + } else { + *ret = NULL; + len = -1; + } + + va_end(ap2); + return len; +#endif +} + +FT_DECLARE_NONSTD(ftdm_status_t) ftdm_console_stream_write(ftdm_stream_handle_t *handle, const char *fmt, ...) +{ + va_list ap; + char *buf = handle->data; + char *end = handle->end; + int ret = 0; + char *data = NULL; + + if (handle->data_len >= handle->data_size) { + return FTDM_FAIL; + } + + va_start(ap, fmt); + ret = ftdm_vasprintf(&data, fmt, ap); + va_end(ap); + + if (data) { + ftdm_size_t remaining = handle->data_size - handle->data_len; + ftdm_size_t need = strlen(data) + 1; + + if ((remaining < need) && handle->alloc_len) { + ftdm_size_t new_len; + void *new_data; + + new_len = handle->data_size + need + handle->alloc_chunk; + if ((new_data = realloc(handle->data, new_len))) { + handle->data_size = handle->alloc_len = new_len; + handle->data = new_data; + buf = handle->data; + remaining = handle->data_size - handle->data_len; + handle->end = (uint8_t *) (handle->data) + handle->data_len; + end = handle->end; + } else { + ftdm_log(FTDM_LOG_CRIT, "Memory Error!\n"); + ftdm_safe_free(data); + return FTDM_FAIL; + } + } + + if (remaining < need) { + ret = -1; + } else { + ret = 0; + snprintf(end, remaining, "%s", data); + handle->data_len = strlen(buf); + handle->end = (uint8_t *) (handle->data) + handle->data_len; + } + ftdm_safe_free(data); + } + + return ret ? FTDM_FAIL : FTDM_SUCCESS; +} + +FT_DECLARE(char *) ftdm_strdup(const char *str) +{ + ftdm_size_t len = strlen(str) + 1; + void *new = ftdm_malloc(len); + + if (!new) { + return NULL; + } + + return (char *)memcpy(new, str, len); +} + +FT_DECLARE(char *) ftdm_strndup(const char *str, ftdm_size_t inlen) +{ + char *new = NULL; + ftdm_size_t len = strlen(str) + 1; + if (len > (inlen+1)) { + len = inlen+1; + } + new = (char *)ftdm_malloc(len); + + if (!new) { + return NULL; + } + + memcpy(new, str, len-1); + new[len-1] = 0; + return new; +} + + +/* 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: + */ diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/ftdm_m3ua.c similarity index 62% rename from libs/freetdm/src/zap_m3ua.c rename to libs/freetdm/src/ftdm_m3ua.c index bcc0e0559d..bb1f06b5e0 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/ftdm_m3ua.c @@ -1,6 +1,6 @@ /* - * zap_m3ua.c - * openzap + * ftdm_m3ua.c + * freetdm * * Created by Shane Burrell on 4/3/08. * Copyright 2008 Shane Burrell. All rights reserved. @@ -38,9 +38,9 @@ */ -#include "openzap.h" +#include "freetdm.h" #include "m3ua_client.h" -#include "zap_m3ua.h" +#include "ftdm_m3ua.h" #define MAX_REQ_ID MAX_PENDING_CALLS typedef uint16_t m3ua_request_id_t; @@ -55,8 +55,8 @@ typedef enum { typedef struct { m3ua_request_status_t status; m3uac_event_t event; - zap_span_t *span; - zap_channel_t *zchan; + ftdm_span_t *span; + ftdm_channel_t *ftdmchan; } m3ua_request_t; @@ -80,7 +80,7 @@ struct m3ua_channel_profile { typedef struct m3ua_channel_profile m3ua_channel_profile_t; static struct { - zap_hash_t *profile_hash; + ftdm_hash_t *profile_hash; general_config_t general_config; } globals; @@ -91,24 +91,24 @@ struct m3ua_span_data { typedef struct m3ua_span_data m3ua_span_data_t; struct m3ua_chan_data { - zap_buffer_t *digit_buffer; - zap_mutex_t *digit_mutex; - zap_size_t dtmf_len; + ftdm_buffer_t *digit_buffer; + ftdm_mutex_t *digit_mutex; + ftdm_size_t dtmf_len; uint32_t flags; uint32_t hdlc_bytes; }; typedef struct m3ua_chan_data m3ua_chan_data_t; -static zap_mutex_t *request_mutex = NULL; -static zap_mutex_t *signal_mutex = NULL; +static ftdm_mutex_t *request_mutex = NULL; +static ftdm_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; static void release_request_id(m3ua_request_id_t r) { - zap_mutex_lock(request_mutex); + ftdm_mutex_lock(request_mutex); req_map[r] = 0; - zap_mutex_unlock(request_mutex); + ftdm_mutex_unlock(request_mutex); } /*static m3ua_request_id_t next_request_id(void) @@ -117,7 +117,7 @@ static void release_request_id(m3ua_request_id_t r) int ok = 0; while(!ok) { - zap_mutex_lock(request_mutex); + ftdm_mutex_lock(request_mutex); for (r = 1; r <= MAX_REQ_ID; r++) { if (!req_map[r]) { ok = 1; @@ -125,153 +125,153 @@ static void release_request_id(m3ua_request_id_t r) break; } } - zap_mutex_unlock(request_mutex); + ftdm_mutex_unlock(request_mutex); if (!ok) { - zap_sleep(5); + ftdm_sleep(5); } } return r; } */ -static __inline__ void state_advance(zap_channel_t *zchan) +static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { - m3ua_data_t *m3ua_data = zchan->span->signal_data; + m3ua_data_t *m3ua_data = ftdmchan->span->signal_data; m3uac_connection_t *mcon = &m3ua_data->mcon; - zap_sigmsg_t sig; - zap_status_t status; + ftdm_sigmsg_t sig; + ftdm_status_t status; - zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n", zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); + ftdm_log(FTDM_LOG_DEBUG, "%d:%d STATE [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; - switch (zchan->state) { - case ZAP_CHANNEL_STATE_DOWN: + switch (ftdmchan->state) { + case FTDM_CHANNEL_STATE_DOWN: { - if (zchan->extra_id) { - release_request_id((m3ua_request_id_t)zchan->extra_id); - zchan->extra_id = 0; + if (ftdmchan->extra_id) { + release_request_id((m3ua_request_id_t)ftdmchan->extra_id); + ftdmchan->extra_id = 0; } - zap_channel_done(zchan); + ftdm_channel_done(ftdmchan); } break; - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - case ZAP_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: + case FTDM_CHANNEL_STATE_PROGRESS: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; + if ((status = m3ua_data->signal_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_START_ACK, 0); } } break; - case ZAP_CHANNEL_STATE_RING: + case FTDM_CHANNEL_STATE_RING: { - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_START; - if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_START; + if ((status = m3ua_data->signal_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } } break; - case ZAP_CHANNEL_STATE_RESTART: + case FTDM_CHANNEL_STATE_RESTART: { - if (zchan->last_state != ZAP_CHANNEL_STATE_HANGUP && zchan->last_state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdmchan->last_state != FTDM_CHANNEL_STATE_HANGUP && ftdmchan->last_state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } } break; - case ZAP_CHANNEL_STATE_UP: + case FTDM_CHANNEL_STATE_UP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_UP; - if ((status = m3ua_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_UP; + if ((status = m3ua_data->signal_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { - if (!(zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA))) { + if (!(ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA))) { m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_START_ACK, 0); } m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_ANSWERED, 0); } } break; - case ZAP_CHANNEL_STATE_DIALING: + case FTDM_CHANNEL_STATE_DIALING: { } break; - case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + case FTDM_CHANNEL_STATE_HANGUP_COMPLETE: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; - case ZAP_CHANNEL_STATE_HANGUP: + case FTDM_CHANNEL_STATE_HANGUP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_ANSWERED) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA)) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_ANSWERED) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA)) { m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED, - zchan->caller_data.hangup_cause); + ftdmchan->caller_data.hangup_cause); } else { m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_START_NACK, - zchan->caller_data.hangup_cause); + ftdmchan->caller_data.hangup_cause); } } break; - case ZAP_CHANNEL_STATE_CANCEL: + case FTDM_CHANNEL_STATE_CANCEL: { - sig.event_id = ZAP_SIGEVENT_STOP; + sig.event_id = FTDM_SIGEVENT_STOP; status = m3ua_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); } break; - case ZAP_CHANNEL_STATE_TERMINATING: + case FTDM_CHANNEL_STATE_TERMINATING: { - sig.event_id = ZAP_SIGEVENT_STOP; + sig.event_id = FTDM_SIGEVENT_STOP; status = m3ua_data->signal_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); m3uac_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + ftdmchan->physical_span_id-1, + ftdmchan->physical_chan_id-1, 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); @@ -283,36 +283,36 @@ static __inline__ void state_advance(zap_channel_t *zchan) } -static __inline__ void check_state(zap_span_t *span) +static __inline__ void check_state(ftdm_span_t *span) { - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + if (ftdm_test_flag(span, FTDM_SPAN_STATE_CHANGE)) { uint32_t j; - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); + ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE); for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - zap_clear_flag_locked((&span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + if (ftdm_test_flag((&span->channels[j]), FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_clear_flag_locked((&span->channels[j]), FTDM_CHANNEL_STATE_CHANGE); state_advance(&span->channels[j]); - zap_channel_complete_state(&span->channels[j]); + ftdm_channel_complete_state(&span->channels[j]); } } } } -static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_event_t *event) +static int parse_ss7_event(ftdm_span_t *span, m3uac_connection_t *mcon, m3uac_event_t *event) { - zap_mutex_lock(signal_mutex); + ftdm_mutex_lock(signal_mutex); - if (!zap_running()) { - zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); + if (!ftdm_running()) { + ftdm_log(FTDM_LOG_WARNING, "System is shutting down.\n"); goto end; } - if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) && + if (ftdm_test_flag(span, FTDM_SPAN_SUSPENDED) && event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { - zap_log(ZAP_LOG_WARNING, + ftdm_log(FTDM_LOG_WARNING, "INVALID EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", m3uac_event_id_name(event->event_id), event->event_id, @@ -329,7 +329,7 @@ static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_eve } - zap_log(ZAP_LOG_DEBUG, + ftdm_log(FTDM_LOG_DEBUG, "RX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", m3uac_event_id_name(event->event_id), event->event_id, @@ -381,13 +381,13 @@ static int parse_ss7_event(zap_span_t *span, m3uac_connection_t *mcon, m3uac_eve //handle_gap_abate(event); break; default: - zap_log(ZAP_LOG_WARNING, "No handler implemented for [%s]\n", m3uac_event_id_name(event->event_id)); + ftdm_log(FTDM_LOG_WARNING, "No handler implemented for [%s]\n", m3uac_event_id_name(event->event_id)); break; } end: - zap_mutex_unlock(signal_mutex); + ftdm_mutex_unlock(signal_mutex); return 0; } @@ -399,14 +399,14 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) int ok = 1; if (!(profile = (m3ua_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { - profile = zap_malloc(sizeof(*profile)); + profile = ftdm_malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); - zap_set_string(profile->name, category); + ftdm_set_string(profile->name, category); hashtable_insert(globals.profile_hash, (void *)profile->name, profile); - zap_log(ZAP_LOG_INFO, "creating profile [%s]\n", category); + ftdm_log(FTDM_LOG_INFO, "creating profile [%s]\n", category); } -// zap_set_string(m3ua_data->mcon. cfg.local_ip, local_ip); +// ftdm_set_string(m3ua_data->mcon. cfg.local_ip, local_ip); if (!strcasecmp(var, "local_sctp_port")) { profile->local_port = 30000 ; profile->remote_port = 30000; @@ -416,30 +416,30 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) if (ok) { - zap_log(ZAP_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category); + ftdm_log(FTDM_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category); } else { - zap_log(ZAP_LOG_ERROR, "unknown param [%s]\n", var); + ftdm_log(FTDM_LOG_ERROR, "unknown param [%s]\n", var); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } static ZIO_CONFIGURE_SPAN_FUNCTION(m3ua_configure_span) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_OPEN_FUNCTION(m3ua_open) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_CLOSE_FUNCTION(m3ua_close) { - return ZAP_FAIL; + return FTDM_FAIL; } /*static ZIO_SET_INTERVAL_FUNCTION(m3ua_set_interval) @@ -451,34 +451,34 @@ static ZIO_CLOSE_FUNCTION(m3ua_close) static ZIO_WAIT_FUNCTION(m3ua_wait) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_READ_FUNCTION(m3ua_read) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_WRITE_FUNCTION(m3ua_write) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_COMMAND_FUNCTION(m3ua_command) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_SPAN_POLL_EVENT_FUNCTION(m3ua_poll_event) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_SPAN_NEXT_EVENT_FUNCTION(m3ua_next_event) { - return ZAP_FAIL; + return FTDM_FAIL; } @@ -487,18 +487,18 @@ static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data; if (span_data) { - zap_safe_free(span_data); + ftdm_safe_free(span_data); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) { - m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) zchan->mod_data; - m3ua_span_data_t *span_data = (m3ua_span_data_t *) zchan->span->mod_data; + m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) ftdmchan->mod_data; + m3ua_span_data_t *span_data = (m3ua_span_data_t *) ftdmchan->span->mod_data; if (!chan_data) { - return ZAP_FAIL; + return FTDM_FAIL; } @@ -506,30 +506,30 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) - zap_mutex_destroy(&chan_data->digit_mutex); - zap_buffer_destroy(&chan_data->digit_buffer); + ftdm_mutex_destroy(&chan_data->digit_mutex); + ftdm_buffer_destroy(&chan_data->digit_buffer); - zap_safe_free(chan_data); + ftdm_safe_free(chan_data); if (span_data) { - zap_safe_free(span_data); + ftdm_safe_free(span_data); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } static ZIO_GET_ALARMS_FUNCTION(m3ua_get_alarms) { - return ZAP_FAIL; + return FTDM_FAIL; } -static zap_io_interface_t m3ua_interface; +static ftdm_io_interface_t m3ua_interface; -zap_status_t m3ua_init(zap_io_interface_t **zint) +ftdm_status_t m3ua_init(ftdm_io_interface_t **zint) { assert(zint != NULL); memset(&m3ua_interface, 0, sizeof(m3ua_interface)); @@ -550,18 +550,18 @@ zap_status_t m3ua_init(zap_io_interface_t **zint) m3ua_interface.get_alarms = m3ua_get_alarms; *zint = &m3ua_interface; - return ZAP_FAIL; + return FTDM_FAIL; } -zap_status_t m3ua_destroy(void) +ftdm_status_t m3ua_destroy(void) { - return ZAP_FAIL; + return FTDM_FAIL; } -static void *m3ua_run(zap_thread_t *me, void *obj) +static void *m3ua_run(ftdm_thread_t *me, void *obj) { - zap_span_t *span = (zap_span_t *) obj; + ftdm_span_t *span = (ftdm_span_t *) obj; m3ua_data_t *m3ua_data = span->signal_data; m3uac_connection_t *mcon, *pcon; uint32_t ms = 10, too_long = 60000; @@ -574,7 +574,7 @@ static void *m3ua_run(zap_thread_t *me, void *obj) m3ua_data->mcon.cfg.local_port, m3ua_data->mcon.cfg.remote_ip, m3ua_data->mcon.cfg.remote_port) < 0) { - zap_log(ZAP_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", m3ua_data->mcon.socket, strerror(errno)); + ftdm_log(FTDM_LOG_DEBUG, "Error: Opening MCON Socket [%d] %s\n", m3ua_data->mcon.socket, strerror(errno)); goto end; } @@ -583,7 +583,7 @@ static void *m3ua_run(zap_thread_t *me, void *obj) ++m3ua_data->pcon.cfg.local_port, m3ua_data->pcon.cfg.remote_ip, m3ua_data->pcon.cfg.remote_port) < 0) { - zap_log(ZAP_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", m3ua_data->pcon.socket, strerror(errno)); + ftdm_log(FTDM_LOG_DEBUG, "Error: Opening PCON Socket [%d] %s\n", m3ua_data->pcon.socket, strerror(errno)); goto end; } @@ -601,13 +601,13 @@ static void *m3ua_run(zap_thread_t *me, void *obj) SIGBOOST_EVENT_SYSTEM_RESTART, 0); - while (zap_test_flag(m3ua_data, ZAP_M3UA_RUNNING)) { + while (ftdm_test_flag(m3ua_data, FTDM_M3UA_RUNNING)) { fd_set rfds, efds; struct timeval tv = { 0, ms * 1000 }; int max, activity, i = 0; m3uac_event_t *event = NULL; - if (!zap_running()) { + if (!ftdm_running()) { m3uac_exec_command(mcon, 0, 0, @@ -651,11 +651,11 @@ static void *m3ua_run(zap_thread_t *me, void *obj) check_state(span); mcon->hb_elapsed += ms; - if (mcon->hb_elapsed >= too_long && (mcon->up || !zap_test_flag(span, ZAP_SPAN_SUSPENDED))) { - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); - zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); + if (mcon->hb_elapsed >= too_long && (mcon->up || !ftdm_test_flag(span, FTDM_SPAN_SUSPENDED))) { + ftdm_set_state_all(span, FTDM_CHANNEL_STATE_RESTART); + ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED); mcon->up = 0; - zap_log(ZAP_LOG_CRIT, "Lost Heartbeat!\n"); + ftdm_log(FTDM_LOG_CRIT, "Lost Heartbeat!\n"); } } @@ -663,23 +663,23 @@ static void *m3ua_run(zap_thread_t *me, void *obj) goto end; error: - zap_log(ZAP_LOG_CRIT, "Socket Error!\n"); + ftdm_log(FTDM_LOG_CRIT, "Socket Error!\n"); end: m3uac_connection_close(&m3ua_data->mcon); m3uac_connection_close(&m3ua_data->pcon); - zap_clear_flag(m3ua_data, ZAP_M3UA_RUNNING); + ftdm_clear_flag(m3ua_data, FTDM_M3UA_RUNNING); - zap_log(ZAP_LOG_DEBUG, "M3UA thread ended.\n"); + ftdm_log(FTDM_LOG_DEBUG, "M3UA thread ended.\n"); return NULL; } -zap_status_t m3ua_start(zap_span_t *span) +ftdm_status_t m3ua_start(ftdm_span_t *span) { m3ua_data_t *m3ua_data = span->signal_data; - zap_set_flag(m3ua_data, ZAP_M3UA_RUNNING); - return zap_thread_create_detached(m3ua_run, span); + ftdm_set_flag(m3ua_data, FTDM_M3UA_RUNNING); + return ftdm_thread_create_detached(m3ua_run, span); } /* For Emacs: diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/ftdm_queue.c similarity index 50% rename from libs/freetdm/src/zap_queue.c rename to libs/freetdm/src/ftdm_queue.c index a714af340c..92ea75c57a 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/ftdm_queue.c @@ -32,34 +32,34 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openzap.h" +#include "freetdm.h" -static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity); -static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj); -static void *zap_std_queue_dequeue(zap_queue_t *queue); -static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms); -static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue); +static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t capacity); +static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj); +static void *ftdm_std_queue_dequeue(ftdm_queue_t *queue); +static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms); +static ftdm_status_t ftdm_std_queue_destroy(ftdm_queue_t **inqueue); -struct zap_queue { - zap_mutex_t *mutex; - zap_condition_t *condition; - zap_size_t capacity; - zap_size_t size; +struct ftdm_queue { + ftdm_mutex_t *mutex; + ftdm_condition_t *condition; + ftdm_size_t capacity; + ftdm_size_t size; unsigned rindex; unsigned windex; void **elements; }; -OZ_DECLARE_DATA zap_queue_handler_t g_zap_queue_handler = +FT_DECLARE_DATA ftdm_queue_handler_t g_ftdm_queue_handler = { - /*.create = */ zap_std_queue_create, - /*.enqueue = */ zap_std_queue_enqueue, - /*.dequeue = */ zap_std_queue_dequeue, - /*.wait = */ zap_std_queue_wait, - /*.destroy = */ zap_std_queue_destroy + /*.create = */ ftdm_std_queue_create, + /*.enqueue = */ ftdm_std_queue_enqueue, + /*.dequeue = */ ftdm_std_queue_dequeue, + /*.wait = */ ftdm_std_queue_wait, + /*.destroy = */ ftdm_std_queue_destroy }; -OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler) +FT_DECLARE(ftdm_status_t) ftdm_global_set_queue_handler(ftdm_queue_handler_t *handler) { if (!handler || !handler->create || @@ -67,62 +67,62 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl !handler->dequeue || !handler->wait || !handler->destroy) { - return ZAP_FAIL; + return FTDM_FAIL; } - memcpy(&g_zap_queue_handler, handler, sizeof(*handler)); - return ZAP_SUCCESS; + memcpy(&g_ftdm_queue_handler, handler, sizeof(*handler)); + return FTDM_SUCCESS; } -static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity) +static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t capacity) { - zap_queue_t *queue = NULL; - zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); - zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); + ftdm_queue_t *queue = NULL; + ftdm_assert_return(outqueue, FTDM_FAIL, "Queue double pointer is null\n"); + ftdm_assert_return(capacity > 0, FTDM_FAIL, "Queue capacity is not bigger than 0\n"); *outqueue = NULL; - queue = zap_calloc(1, sizeof(*queue)); + queue = ftdm_calloc(1, sizeof(*queue)); if (!queue) { - return ZAP_FAIL; + return FTDM_FAIL; } - queue->elements = zap_calloc(1, (sizeof(void*)*capacity)); + queue->elements = ftdm_calloc(1, (sizeof(void*)*capacity)); if (!queue->elements) { goto failed; } queue->capacity = capacity; - if (zap_mutex_create(&queue->mutex) != ZAP_SUCCESS) { + if (ftdm_mutex_create(&queue->mutex) != FTDM_SUCCESS) { goto failed; } - if (zap_condition_create(&queue->condition, queue->mutex) != ZAP_SUCCESS) { + if (ftdm_condition_create(&queue->condition, queue->mutex) != FTDM_SUCCESS) { goto failed; } *outqueue = queue; - return ZAP_SUCCESS; + return FTDM_SUCCESS; failed: if (queue) { if (queue->condition) { - zap_condition_destroy(&queue->condition); + ftdm_condition_destroy(&queue->condition); } if (queue->mutex) { - zap_mutex_destroy(&queue->mutex); + ftdm_mutex_destroy(&queue->mutex); } - zap_safe_free(queue->elements); - zap_safe_free(queue); + ftdm_safe_free(queue->elements); + ftdm_safe_free(queue); } - return ZAP_FAIL; + return FTDM_FAIL; } -static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) +static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj) { - zap_status_t status = ZAP_FAIL; + ftdm_status_t status = FTDM_FAIL; - zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!"); + ftdm_assert_return(queue != NULL, FTDM_FAIL, "Queue is null!"); - zap_mutex_lock(queue->mutex); + ftdm_mutex_lock(queue->mutex); if (queue->windex == queue->capacity) { /* try to see if we can wrap around */ @@ -130,31 +130,31 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) } if (queue->size != 0 && queue->windex == queue->rindex) { - zap_log(ZAP_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex); + ftdm_log(FTDM_LOG_ERROR, "Failed to enqueue obj %p in queue %p, no more room! windex == rindex == %d!\n", obj, queue, queue->windex); goto done; } queue->elements[queue->windex++] = obj; queue->size++; - status = ZAP_SUCCESS; + status = FTDM_SUCCESS; /* wake up queue reader */ - zap_condition_signal(queue->condition); + ftdm_condition_signal(queue->condition); done: - zap_mutex_unlock(queue->mutex); + ftdm_mutex_unlock(queue->mutex); return status; } -static void *zap_std_queue_dequeue(zap_queue_t *queue) +static void *ftdm_std_queue_dequeue(ftdm_queue_t *queue) { void *obj = NULL; - zap_assert_return(queue != NULL, NULL, "Queue is null!"); + ftdm_assert_return(queue != NULL, NULL, "Queue is null!"); - zap_mutex_lock(queue->mutex); + ftdm_mutex_lock(queue->mutex); if (queue->size == 0) { goto done; @@ -169,46 +169,46 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) done: - zap_mutex_unlock(queue->mutex); + ftdm_mutex_unlock(queue->mutex); return obj; } -static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) +static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms) { - zap_status_t ret; - zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!"); + ftdm_status_t ret; + ftdm_assert_return(queue != NULL, FTDM_FAIL, "Queue is null!"); - zap_mutex_lock(queue->mutex); + ftdm_mutex_lock(queue->mutex); /* if there is elements in the queue, no need to wait */ if (queue->size != 0) { - zap_mutex_unlock(queue->mutex); - return ZAP_SUCCESS; + ftdm_mutex_unlock(queue->mutex); + return FTDM_SUCCESS; } /* no elements on the queue, wait for someone to write an element */ - ret = zap_condition_wait(queue->condition, ms); + ret = ftdm_condition_wait(queue->condition, ms); /* got an element or timeout, bail out */ - zap_mutex_unlock(queue->mutex); + ftdm_mutex_unlock(queue->mutex); return ret; } -static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue) +static ftdm_status_t ftdm_std_queue_destroy(ftdm_queue_t **inqueue) { - zap_queue_t *queue = NULL; - zap_assert_return(inqueue != NULL, ZAP_FAIL, "Queue is null!"); - zap_assert_return(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); + ftdm_queue_t *queue = NULL; + ftdm_assert_return(inqueue != NULL, FTDM_FAIL, "Queue is null!"); + ftdm_assert_return(*inqueue != NULL, FTDM_FAIL, "Queue is null!"); queue = *inqueue; - zap_condition_destroy(&queue->condition); - zap_mutex_destroy(&queue->mutex); - zap_safe_free(queue->elements); - zap_safe_free(queue); + ftdm_condition_destroy(&queue->condition); + ftdm_mutex_destroy(&queue->mutex); + ftdm_safe_free(queue->elements); + ftdm_safe_free(queue); *inqueue = NULL; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /* For Emacs: diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/ftdm_threadmutex.c similarity index 59% rename from libs/freetdm/src/zap_threadmutex.c rename to libs/freetdm/src/ftdm_threadmutex.c index bae288c561..7446896dcd 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/ftdm_threadmutex.c @@ -26,84 +26,84 @@ #define _WIN32_WINNT 0x0400 #endif -#include "openzap.h" -#include "zap_threadmutex.h" +#include "freetdm.h" +#include "ftdm_threadmutex.h" #ifdef WIN32 #include -#define ZAP_THREAD_CALLING_CONVENTION __stdcall +#define FTDM_THREAD_CALLING_CONVENTION __stdcall -struct zap_mutex { +struct ftdm_mutex { CRITICAL_SECTION mutex; }; #else #include -#define ZAP_THREAD_CALLING_CONVENTION +#define FTDM_THREAD_CALLING_CONVENTION -struct zap_mutex { +struct ftdm_mutex { pthread_mutex_t mutex; }; #endif -struct zap_condition { +struct ftdm_condition { #ifdef WIN32 HANDLE condition; #else pthread_cond_t condition; #endif - zap_mutex_t *mutex; + ftdm_mutex_t *mutex; }; -struct zap_thread { +struct ftdm_thread { #ifdef WIN32 void *handle; #else pthread_t handle; #endif void *private_data; - zap_thread_function_t function; - zap_size_t stack_size; + ftdm_thread_function_t function; + ftdm_size_t stack_size; #ifndef WIN32 pthread_attr_t attribute; #endif }; -zap_size_t thread_default_stacksize = 0; +ftdm_size_t thread_default_stacksize = 0; -OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size) +FT_DECLARE(void) ftdm_thread_override_default_stacksize(ftdm_size_t size) { thread_default_stacksize = size; } -static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) +static void * FTDM_THREAD_CALLING_CONVENTION thread_launch(void *args) { void *exit_val; - zap_thread_t *thread = (zap_thread_t *)args; + ftdm_thread_t *thread = (ftdm_thread_t *)args; exit_val = thread->function(thread, thread->private_data); #ifndef WIN32 pthread_attr_destroy(&thread->attribute); #endif - zap_safe_free(thread); + ftdm_safe_free(thread); return exit_val; } -OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data) +FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached(ftdm_thread_function_t func, void *data) { - return zap_thread_create_detached_ex(func, data, thread_default_stacksize); + return ftdm_thread_create_detached_ex(func, data, thread_default_stacksize); } -OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size) +FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached_ex(ftdm_thread_function_t func, void *data, ftdm_size_t stack_size) { - zap_thread_t *thread = NULL; - zap_status_t status = ZAP_FAIL; + ftdm_thread_t *thread = NULL; + ftdm_status_t status = FTDM_FAIL; - if (!func || !(thread = (zap_thread_t *)zap_malloc(sizeof(zap_thread_t)))) { + if (!func || !(thread = (ftdm_thread_t *)ftdm_malloc(sizeof(ftdm_thread_t)))) { goto done; } @@ -118,7 +118,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun } CloseHandle(thread->handle); - status = ZAP_SUCCESS; + status = FTDM_SUCCESS; goto done; #else @@ -130,7 +130,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto failpthread; - status = ZAP_SUCCESS; + status = FTDM_SUCCESS; goto done; failpthread: pthread_attr_destroy(&thread->attribute); @@ -138,22 +138,22 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun fail: if (thread) { - zap_safe_free(thread); + ftdm_safe_free(thread); } done: return status; } -OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex) +FT_DECLARE(ftdm_status_t) ftdm_mutex_create(ftdm_mutex_t **mutex) { - zap_status_t status = ZAP_FAIL; + ftdm_status_t status = FTDM_FAIL; #ifndef WIN32 pthread_mutexattr_t attr; #endif - zap_mutex_t *check = NULL; + ftdm_mutex_t *check = NULL; - check = (zap_mutex_t *)zap_malloc(sizeof(**mutex)); + check = (ftdm_mutex_t *)ftdm_malloc(sizeof(**mutex)); if (!check) goto done; #ifdef WIN32 @@ -177,77 +177,77 @@ OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex) success: #endif *mutex = check; - status = ZAP_SUCCESS; + status = FTDM_SUCCESS; done: return status; } -OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex) +FT_DECLARE(ftdm_status_t) ftdm_mutex_destroy(ftdm_mutex_t **mutex) { - zap_mutex_t *mp = *mutex; + ftdm_mutex_t *mp = *mutex; *mutex = NULL; if (!mp) { - return ZAP_FAIL; + return FTDM_FAIL; } #ifdef WIN32 DeleteCriticalSection(&mp->mutex); #else if (pthread_mutex_destroy(&mp->mutex)) - return ZAP_FAIL; + return FTDM_FAIL; #endif - zap_safe_free(mp); - return ZAP_SUCCESS; + ftdm_safe_free(mp); + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex) +FT_DECLARE(ftdm_status_t) _ftdm_mutex_lock(ftdm_mutex_t *mutex) { #ifdef WIN32 EnterCriticalSection(&mutex->mutex); #else int err; if ((err = pthread_mutex_lock(&mutex->mutex))) { - zap_log(ZAP_LOG_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err)); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err)); + return FTDM_FAIL; } #endif - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex) +FT_DECLARE(ftdm_status_t) _ftdm_mutex_trylock(ftdm_mutex_t *mutex) { #ifdef WIN32 if (!TryEnterCriticalSection(&mutex->mutex)) - return ZAP_FAIL; + return FTDM_FAIL; #else if (pthread_mutex_trylock(&mutex->mutex)) - return ZAP_FAIL; + return FTDM_FAIL; #endif - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex) +FT_DECLARE(ftdm_status_t) _ftdm_mutex_unlock(ftdm_mutex_t *mutex) { #ifdef WIN32 LeaveCriticalSection(&mutex->mutex); #else if (pthread_mutex_unlock(&mutex->mutex)) - return ZAP_FAIL; + return FTDM_FAIL; #endif - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap_mutex_t *mutex) +FT_DECLARE(ftdm_status_t) ftdm_condition_create(ftdm_condition_t **incondition, ftdm_mutex_t *mutex) { - zap_condition_t *condition = NULL; + ftdm_condition_t *condition = NULL; - zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); - zap_assert_return(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); + ftdm_assert_return(incondition != NULL, FTDM_FAIL, "Condition double pointer is null!\n"); + ftdm_assert_return(mutex != NULL, FTDM_FAIL, "Mutex for condition must not be null!\n"); - condition = zap_calloc(1, sizeof(*condition)); + condition = ftdm_calloc(1, sizeof(*condition)); if (!condition) { - return ZAP_FAIL; + return FTDM_FAIL; } condition->mutex = mutex; @@ -263,38 +263,38 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap #endif *incondition = condition; - return ZAP_SUCCESS; + return FTDM_SUCCESS; failed: if (condition) { - zap_safe_free(condition); + ftdm_safe_free(condition); } - return ZAP_FAIL; + return FTDM_FAIL; } #define ONE_BILLION 1000000000 -OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) +FT_DECLARE(ftdm_status_t) ftdm_condition_wait(ftdm_condition_t *condition, int ms) { #ifdef WIN32 DWORD res = 0; #endif - zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + ftdm_assert_return(condition != NULL, FTDM_FAIL, "Condition is null!\n"); #ifdef WIN32 - zap_mutex_unlock(condition->mutex); + ftdm_mutex_unlock(condition->mutex); res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); - zap_mutex_lock(condition->mutex); + ftdm_mutex_lock(condition->mutex); switch (res) { case WAIT_ABANDONED: case WAIT_TIMEOUT: - return ZAP_TIMEOUT; + return FTDM_TIMEOUT; case WAIT_FAILED: - return ZAP_FAIL; + return FTDM_FAIL; case WAIT_OBJECT_0: - return ZAP_SUCCESS; + return FTDM_SUCCESS; default: - zap_log(ZAP_LOG_ERROR, "Error waiting for openzap condition event (WaitForSingleObject returned %d)\n", res); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Error waiting for freetdm condition event (WaitForSingleObject returned %d)\n", res); + return FTDM_FAIL; } #else int res = 0; @@ -314,48 +314,48 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) } if (res != 0) { if (res == ETIMEDOUT) { - return ZAP_TIMEOUT; + return FTDM_TIMEOUT; } - zap_log(ZAP_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res); + return FTDM_FAIL; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; #endif } -OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) +FT_DECLARE(ftdm_status_t) ftdm_condition_signal(ftdm_condition_t *condition) { - zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + ftdm_assert_return(condition != NULL, FTDM_FAIL, "Condition is null!\n"); #ifdef WIN32 if (!SetEvent(condition->condition)) { - return ZAP_FAIL; + return FTDM_FAIL; } #else int err; if ((err = pthread_cond_signal(&condition->condition))) { - zap_log(ZAP_LOG_ERROR, "Failed to signal condition %d:%s\n", err, strerror(err)); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Failed to signal condition %d:%s\n", err, strerror(err)); + return FTDM_FAIL; } #endif - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) +FT_DECLARE(ftdm_status_t) ftdm_condition_destroy(ftdm_condition_t **incondition) { - zap_condition_t *condition = NULL; - zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); + ftdm_condition_t *condition = NULL; + ftdm_assert_return(incondition != NULL, FTDM_FAIL, "Condition null when destroying!\n"); condition = *incondition; #ifdef WIN32 CloseHandle(condition->condition); #else if (pthread_cond_destroy(&condition->condition)) { - return ZAP_FAIL; + return FTDM_FAIL; } #endif - zap_safe_free(condition); + ftdm_safe_free(condition); *incondition = NULL; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h similarity index 84% rename from libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h rename to libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h index 563285eb2c..8e1fa7a721 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h @@ -31,30 +31,30 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_ANALOG_H -#define ZAP_ANALOG_H -#include "openzap.h" +#ifndef FTDM_ANALOG_H +#define FTDM_ANALOG_H +#include "freetdm.h" typedef enum { - ZAP_ANALOG_RUNNING = (1 << 0), - ZAP_ANALOG_CALLERID = (1 << 1) -} zap_analog_flag_t; + FTDM_ANALOG_RUNNING = (1 << 0), + FTDM_ANALOG_CALLERID = (1 << 1) +} ftdm_analog_flag_t; -#define ZAP_MAX_HOTLINE_STR 20 +#define FTDM_MAX_HOTLINE_STR 20 #define MAX_DTMF 256 -struct zap_analog_data { +struct ftdm_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; - char hotline[ZAP_MAX_HOTLINE_STR]; + char hotline[FTDM_MAX_HOTLINE_STR]; zio_signal_cb_t sig_cb; }; -static void *zap_analog_run(zap_thread_t *me, void *obj); -typedef struct zap_analog_data zap_analog_data_t; +static void *ftdm_analog_run(ftdm_thread_t *me, void *obj); +typedef struct ftdm_analog_data ftdm_analog_data_t; #endif diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c new file mode 100644 index 0000000000..66192108cd --- /dev/null +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -0,0 +1,977 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "freetdm.h" +#include "ftdm_analog.h" + +#ifndef localtime_r +struct tm * localtime_r(const time_t *clock, struct tm *result); +#endif + +static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj); + +/** + * \brief Starts an FXO channel thread (outgoing call) + * \param ftdmchan Channel to initiate call on + * \return Success or failure + * + * Initialises state, starts tone progress detection and runs the channel in a new a thread. + */ +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) +{ + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_channel_clear_needed_tones(ftdmchan); + ftdm_channel_clear_detected_tones(ftdmchan); + + ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL); + ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_PROGRESS_DETECT, NULL); + ftdmchan->needed_tones[FTDM_TONEMAP_DIAL] = 1; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING); + ftdm_thread_create_detached(ftdm_analog_channel_run, ftdmchan); + return FTDM_SUCCESS; + } + + return FTDM_FAIL; +} + +/** + * \brief Starts an FXS channel thread (outgoing call) + * \param ftdmchan Channel to initiate call on + * \return Success or failure + * + * Indicates call waiting if channel is already in use, otherwise runs the channel in a new thread. + */ +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) +{ + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_CALLWAITING); + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_GENRING); + ftdm_thread_create_detached(ftdm_analog_channel_run, ftdmchan); + } + + return FTDM_SUCCESS; +} + +/** + * \brief Starts an analog span thread (monitor) + * \param span Span to monitor + * \return Success or failure + */ +static ftdm_status_t ftdm_analog_start(ftdm_span_t *span) +{ + ftdm_analog_data_t *analog_data = span->signal_data; + ftdm_set_flag(analog_data, FTDM_ANALOG_RUNNING); + return ftdm_thread_create_detached(ftdm_analog_run, span); +} + +/** + * \brief Initialises an analog span from configuration variables + * \param span Span to configure + * \param sig_cb Callback function for event signals + * \param ap List of configuration variables + * \return Success or failure + */ +static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_configure_span) +//ftdm_status_t ftdm_analog_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb) +{ + ftdm_analog_data_t *analog_data; + const char *tonemap = "us"; + const char *hotline = ""; + uint32_t digit_timeout = 10; + uint32_t max_dialstr = MAX_DTMF; + const char *var, *val; + int *intval; + uint32_t flags = FTDM_ANALOG_CALLERID; + + assert(sig_cb != NULL); + + if (span->signal_type) { + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + return FTDM_FAIL; + } + + analog_data = ftdm_malloc(sizeof(*analog_data)); + assert(analog_data != NULL); + memset(analog_data, 0, sizeof(*analog_data)); + + while ((var = va_arg(ap, char *))) { + if (!strcasecmp(var, "tonemap")) { + if (!(val = va_arg(ap, char *))) { + break; + } + tonemap = val; + } else if (!strcasecmp(var, "digit_timeout")) { + if (!(intval = va_arg(ap, int *))) { + break; + } + digit_timeout = *intval; + } else if (!strcasecmp(var, "enable_callerid")) { + if (!(val = va_arg(ap, char *))) { + break; + } + + if (ftdm_true(val)) { + flags |= FTDM_ANALOG_CALLERID; + } else { + flags &= ~FTDM_ANALOG_CALLERID; + } + } else if (!strcasecmp(var, "max_dialstr")) { + if (!(intval = va_arg(ap, int *))) { + break; + } + max_dialstr = *intval; + } else if (!strcasecmp(var, "hotline")) { + if (!(val = va_arg(ap, char *))) { + break; + } + hotline = val; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return FTDM_FAIL; + } + } + + + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) { + max_dialstr = MAX_DTMF; + } + + span->start = ftdm_analog_start; + analog_data->flags = flags; + analog_data->digit_timeout = digit_timeout; + analog_data->max_dialstr = max_dialstr; + analog_data->sig_cb = sig_cb; + strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline)); + span->signal_type = FTDM_SIGTYPE_ANALOG; + span->signal_data = analog_data; + span->outgoing_call = span->trunk_type == FTDM_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call; + ftdm_span_load_tones(span, tonemap); + + return FTDM_SUCCESS; + +} + +/** + * \brief Retrieves tone generation output to be sent + * \param ts Teletone generator + * \param map Tone map + * \return -1 on error, 0 on success + */ +static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map) +{ + ftdm_buffer_t *dt_buffer = ts->user_data; + int wrote; + + if (!dt_buffer) { + return -1; + } + wrote = teletone_mux_tones(ts, map); + ftdm_buffer_write(dt_buffer, ts->buffer, wrote * 2); + return 0; +} + +/** + * \brief Sends caller id on an analog channel (FSK coded) + * \param ftdmchan Channel to send caller id on + */ +static void send_caller_id(ftdm_channel_t *ftdmchan) +{ + ftdm_fsk_data_state_t fsk_data; + uint8_t databuf[1024] = ""; + char time_str[9]; + struct tm tm; + time_t now; + ftdm_mdmf_type_t mt = MDMF_INVALID; + + time(&now); +#ifdef WIN32 + _tzset(); + _localtime64_s(&tm, &now); +#else + localtime_r(&now, &tm); +#endif + strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm); + + ftdm_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); + ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *) time_str, 8); + + if (ftdm_strlen_zero(ftdmchan->caller_data.cid_num.digits)) { + mt = MDMF_NO_NUM; + ftdm_set_string(ftdmchan->caller_data.cid_num.digits, "O"); + } else if (!strcasecmp(ftdmchan->caller_data.cid_num.digits, "P") || !strcasecmp(ftdmchan->caller_data.cid_num.digits, "O")) { + mt = MDMF_NO_NUM; + } else { + mt = MDMF_PHONE_NUM; + } + ftdm_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) ftdmchan->caller_data.cid_num.digits, (uint8_t)strlen(ftdmchan->caller_data.cid_num.digits)); + + if (ftdm_strlen_zero(ftdmchan->caller_data.cid_name)) { + mt = MDMF_NO_NAME; + ftdm_set_string(ftdmchan->caller_data.cid_name, "O"); + } else if (!strcasecmp(ftdmchan->caller_data.cid_name, "P") || !strcasecmp(ftdmchan->caller_data.cid_name, "O")) { + mt = MDMF_NO_NAME; + } else { + mt = MDMF_PHONE_NAME; + } + ftdm_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) ftdmchan->caller_data.cid_name, (uint8_t)strlen(ftdmchan->caller_data.cid_name)); + + ftdm_fsk_data_add_checksum(&fsk_data); + ftdm_channel_send_fsk_data(ftdmchan, &fsk_data, -14); +} + +/** + * \brief Main thread function for analog channel (outgoing call) + * \param me Current thread + * \param obj Channel to run in this thread + */ +static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) +{ + ftdm_channel_t *ftdmchan = (ftdm_channel_t *) obj; + ftdm_buffer_t *dt_buffer = NULL; + teletone_generation_session_t ts; + uint8_t frame[1024]; + ftdm_size_t len, rlen; + ftdm_tone_type_t tt = FTDM_TONE_DTMF; + char dtmf[MAX_DTMF+1] = ""; + ftdm_size_t dtmf_offset = 0; + ftdm_analog_data_t *analog_data = ftdmchan->span->signal_data; + ftdm_channel_t *closed_chan; + uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; + ftdm_sigmsg_t sig; + ftdm_status_t status; + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); + + ts.buffer = NULL; + + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); + goto done; + } + + if (ftdm_buffer_create(&dt_buffer, 1024, 3192, 0) != FTDM_SUCCESS) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "memory error!"); + ftdm_log(FTDM_LOG_ERROR, "MEM ERROR\n"); + goto done; + } + + if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "error initilizing tone detector!"); + ftdm_log(FTDM_LOG_ERROR, "TONE ERROR\n"); + goto done; + } + + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INTHREAD); + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); + ts.rate = 8000; +#if 0 + ts.debug = 1; + ts.debug_stream = stdout; +#endif + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_INTERVAL, &interval); + ftdm_buffer_set_loops(dt_buffer, -1); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + + assert(interval != 0); + + while (ftdm_running() && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_wait_flag_t flags = FTDM_READ; + ftdm_size_t dlen = 0; + + len = sizeof(frame); + + elapsed += interval; + state_counter += interval; + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + switch(ftdmchan->state) { + case FTDM_CHANNEL_STATE_GET_CALLERID: + { + if (state_counter > 5000 || !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CALLERID_DETECT)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_DISABLE_CALLERID_DETECT, NULL); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE); + } + } + break; + case FTDM_CHANNEL_STATE_DIALING: + { + if (state_counter > dial_timeout) { + if (ftdmchan->needed_tones[FTDM_TONEMAP_DIAL]) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP); + } + } + } + break; + case FTDM_CHANNEL_STATE_GENRING: + { + if (state_counter > 60000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } else if (!ftdmchan->fsk_buffer || !ftdm_buffer_inuse(ftdmchan->fsk_buffer)) { + ftdm_sleep(interval); + continue; + } + } + break; + case FTDM_CHANNEL_STATE_DIALTONE: + { + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_HOLD) && state_counter > 10000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } + } + break; + case FTDM_CHANNEL_STATE_BUSY: + { + if (state_counter > 20000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_ATTN); + } + } + break; + case FTDM_CHANNEL_STATE_ATTN: + { + if (state_counter > 20000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + case FTDM_CHANNEL_STATE_HANGUP: + { + if (state_counter > 500) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_OFF, NULL); + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && + (ftdmchan->last_state == FTDM_CHANNEL_STATE_RING || ftdmchan->last_state == FTDM_CHANNEL_STATE_DIALTONE + || ftdmchan->last_state >= FTDM_CHANNEL_STATE_IDLE)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CLEARING; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + } + break; + case FTDM_CHANNEL_STATE_CALLWAITING: + { + int done = 0; + + if (ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] == 1) { + send_caller_id(ftdmchan); + ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]++; + } else if (state_counter > 600 && !ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]) { + send_caller_id(ftdmchan); + ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]++; + } else if (state_counter > 1000 && !ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]) { + done = 1; + } else if (state_counter > 10000) { + if (ftdmchan->fsk_buffer) { + ftdm_buffer_zero(ftdmchan->fsk_buffer); + } else { + ftdm_buffer_create(&ftdmchan->fsk_buffer, 128, 128, 0); + } + + ts.user_data = ftdmchan->fsk_buffer; + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_CALLWAITING_SAS]); + ts.user_data = dt_buffer; + done = 1; + } + + if (done) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_clear_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); + ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] = 0; + } + } + case FTDM_CHANNEL_STATE_UP: + case FTDM_CHANNEL_STATE_IDLE: + { + ftdm_sleep(interval); + continue; + } + break; + case FTDM_CHANNEL_STATE_DOWN: + { + goto done; + } + break; + default: + break; + } + } else { + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_clear_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); + ftdm_channel_complete_state(ftdmchan); + indicate = 0; + state_counter = 0; + + ftdm_log(FTDM_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", + ftdmchan->span_id, ftdmchan->chan_id, + ftdm_channel_state2str(ftdmchan->state)); + switch(ftdmchan->state) { + case FTDM_CHANNEL_STATE_UP: + { + ftdm_channel_use(ftdmchan); + ftdm_channel_clear_needed_tones(ftdmchan); + ftdm_channel_flush_dtmf(ftdmchan); + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL); + } + + if (ftdmchan->fsk_buffer && ftdm_buffer_inuse(ftdmchan->fsk_buffer)) { + ftdm_log(FTDM_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n"); + ftdm_buffer_zero(ftdmchan->fsk_buffer); + } + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXS && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_OFF, NULL); + } + + if (ftdmchan->token_count == 1) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_HOLD); + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_HOLD)) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_HOLD); + sig.event_id = FTDM_SIGEVENT_ADD_CALL; + } else { + sig.event_id = FTDM_SIGEVENT_UP; + } + + analog_data->sig_cb(&sig); + continue; + } + break; + case FTDM_CHANNEL_STATE_DIALING: + { + ftdm_channel_use(ftdmchan); + } + break; + case FTDM_CHANNEL_STATE_IDLE: + { + ftdm_channel_use(ftdmchan); + sig.event_id = FTDM_SIGEVENT_START; + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXO) { + ftdm_set_string(ftdmchan->caller_data.dnis.digits, ftdmchan->chan_number); + } else { + ftdm_set_string(ftdmchan->caller_data.dnis.digits, dtmf); + } + + analog_data->sig_cb(&sig); + continue; + } + break; + case FTDM_CHANNEL_STATE_DOWN: + { + sig.event_id = FTDM_SIGEVENT_STOP; + analog_data->sig_cb(&sig); + goto done; + } + break; + case FTDM_CHANNEL_STATE_DIALTONE: + { + memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data)); + *dtmf = '\0'; + dtmf_offset = 0; + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_DIAL]); + indicate = 1; + } + break; + case FTDM_CHANNEL_STATE_CALLWAITING: + { + ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] = 0; + if (ftdmchan->fsk_buffer) { + ftdm_buffer_zero(ftdmchan->fsk_buffer); + } else { + ftdm_buffer_create(&ftdmchan->fsk_buffer, 128, 128, 0); + } + + ts.user_data = ftdmchan->fsk_buffer; + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_CALLWAITING_SAS]); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_CALLWAITING_CAS]); + ts.user_data = dt_buffer; + } + break; + case FTDM_CHANNEL_STATE_GENRING: + { + ftdm_sigmsg_t sig; + + send_caller_id(ftdmchan); + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_ON, NULL); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + sig.event_id = FTDM_SIGEVENT_PROGRESS; + analog_data->sig_cb(&sig); + + } + break; + case FTDM_CHANNEL_STATE_GET_CALLERID: + { + memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data)); + ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_CALLERID_DETECT, NULL); + continue; + } + break; + case FTDM_CHANNEL_STATE_RING: + { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_RING]); + indicate = 1; + + } + break; + case FTDM_CHANNEL_STATE_BUSY: + { + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION; + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_BUSY]); + indicate = 1; + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + case FTDM_CHANNEL_STATE_ATTN: + { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_ATTN]); + indicate = 1; + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + default: + break; + } + } + + + if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE || ftdmchan->state == FTDM_CHANNEL_STATE_COLLECT) { + if ((dlen = ftdm_channel_dequeue_dtmf(ftdmchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + + if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_COLLECT); + collecting = 1; + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + sig.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT; + sig.raw_data = dtmf; + if (analog_data->sig_cb(&sig) == FTDM_BREAK) { + collecting = 0; + } + } + else if(!analog_data->max_dialstr) + { + last_digit = elapsed; + collecting = 0; + strcpy(dtmf, analog_data->hotline); + } + } + + + if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) >= analog_data->max_dialstr))) { + ftdm_log(FTDM_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE); + last_digit = 0; + collecting = 0; + } + + if (ftdm_channel_wait(ftdmchan, &flags, interval * 2) != FTDM_SUCCESS) { + continue; + } + + if (!(flags & FTDM_READ)) { + continue; + } + + if (ftdm_channel_read(ftdmchan, frame, &len) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "READ ERROR [%s]\n", ftdmchan->last_error); + goto done; + } + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && ftdmchan->detected_tones[0]) { + ftdm_sigmsg_t sig; + int i; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + sig.event_id = FTDM_SIGEVENT_TONE_DETECTED; + + for (i = 1; i < FTDM_TONEMAP_INVALID; i++) { + if (ftdmchan->detected_tones[i]) { + ftdm_log(FTDM_LOG_DEBUG, "Detected tone %s on %d:%d\n", ftdm_tonemap2str(i), ftdmchan->span_id, ftdmchan->chan_id); + sig.raw_data = &i; + if (analog_data->sig_cb) { + analog_data->sig_cb(&sig); + } + } + } + + if (ftdmchan->detected_tones[FTDM_TONEMAP_BUSY] || + ftdmchan->detected_tones[FTDM_TONEMAP_FAIL1] || + ftdmchan->detected_tones[FTDM_TONEMAP_FAIL2] || + ftdmchan->detected_tones[FTDM_TONEMAP_FAIL3] || + ftdmchan->detected_tones[FTDM_TONEMAP_ATTN] + ) { + ftdm_log(FTDM_LOG_ERROR, "Failure indication detected!\n"); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else if (ftdmchan->detected_tones[FTDM_TONEMAP_DIAL]) { + if (ftdm_strlen_zero(ftdmchan->caller_data.ani.digits)) { + ftdm_log(FTDM_LOG_ERROR, "No Digits to send!\n"); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.ani.digits) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Send Digits Failed [%s]\n", ftdmchan->last_error); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + state_counter = 0; + ftdmchan->needed_tones[FTDM_TONEMAP_RING] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_BUSY] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_FAIL1] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_FAIL2] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_FAIL3] = 1; + dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.ani.digits)) + 2000; + } + } + } else if (ftdmchan->detected_tones[FTDM_TONEMAP_RING]) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP); + } + + ftdm_channel_clear_detected_tones(ftdmchan); + } + + if ((ftdmchan->dtmf_buffer && ftdm_buffer_inuse(ftdmchan->dtmf_buffer)) || (ftdmchan->fsk_buffer && ftdm_buffer_inuse(ftdmchan->fsk_buffer))) { + //rlen = len; + //memset(frame, 0, len); + //ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen); + continue; + } + + if (!indicate) { + continue; + } + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL); + } + + if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { + len *= 2; + } + + rlen = ftdm_buffer_read_loop(dt_buffer, frame, len); + + if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + goto done; + } + } + + ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen); + } + + done: + + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXO && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_ONHOOK, NULL); + } + + if (ftdmchan->type == FTDM_CHAN_TYPE_FXS && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GENERATE_RING_OFF, NULL); + } + + + closed_chan = ftdmchan; + ftdm_channel_close(&ftdmchan); + + ftdm_channel_command(closed_chan, FTDM_COMMAND_SET_NATIVE_CODEC, NULL); + + if (ts.buffer) { + teletone_destroy_session(&ts); + } + + if (dt_buffer) { + ftdm_buffer_destroy(&dt_buffer); + } + + if (closed_chan->state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_set_state_locked(closed_chan, FTDM_CHANNEL_STATE_DOWN); + } + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", closed_chan->span_id, closed_chan->chan_id); + ftdm_clear_flag(closed_chan, FTDM_CHANNEL_INTHREAD); + + return NULL; +} + +/** + * \brief Processes freetdm event + * \param span Span on which the event was fired + * \param event Event to be treated + * \return Success or failure + */ +static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) +{ + ftdm_sigmsg_t sig; + ftdm_analog_data_t *analog_data = event->channel->span->signal_data; + int locked = 0; + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; + + + ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n", + ftdm_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state)); + + ftdm_mutex_lock(event->channel->mutex); + locked++; + + switch(event->enum_id) { + case FTDM_OOB_RING_START: + { + if (event->channel->type != FTDM_CHAN_TYPE_FXO) { + ftdm_log(FTDM_LOG_ERROR, "Cannot get a RING_START event on a non-fxo channel, please check your config.\n"); + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); + goto end; + } + if (!event->channel->ring_count && (event->channel->state == FTDM_CHANNEL_STATE_DOWN && !ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD))) { + if (ftdm_test_flag(analog_data, FTDM_ANALOG_CALLERID)) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_GET_CALLERID); + } else { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_IDLE); + } + event->channel->ring_count = 1; + ftdm_mutex_unlock(event->channel->mutex); + locked = 0; + ftdm_thread_create_detached(ftdm_analog_channel_run, event->channel); + } else { + event->channel->ring_count++; + } + } + break; + case FTDM_OOB_ONHOOK: + { + if (ftdm_test_flag(event->channel, FTDM_CHANNEL_RINGING)) { + ftdm_channel_command(event->channel, FTDM_COMMAND_GENERATE_RING_OFF, NULL); + } + + if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); + } + + } + break; + case FTDM_OOB_FLASH: + { + if (event->channel->state == FTDM_CHANNEL_STATE_CALLWAITING) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP); + ftdm_clear_flag_locked(event->channel, FTDM_CHANNEL_STATE_CHANGE); + ftdm_clear_flag_locked(event->channel->span, FTDM_SPAN_STATE_CHANGE); + event->channel->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK] = 0; + } + + ftdm_channel_rotate_tokens(event->channel); + + if (ftdm_test_flag(event->channel, FTDM_CHANNEL_HOLD) && event->channel->token_count != 1) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP); + } else { + sig.event_id = FTDM_SIGEVENT_FLASH; + analog_data->sig_cb(&sig); + } + } + break; + case FTDM_OOB_OFFHOOK: + { + if (event->channel->type == FTDM_CHAN_TYPE_FXS) { + if (ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD)) { + if (ftdm_test_flag(event->channel, FTDM_CHANNEL_RINGING)) { + ftdm_channel_command(event->channel, FTDM_COMMAND_GENERATE_RING_OFF, NULL); + } + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP); + } else { + if(!analog_data->max_dialstr) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_COLLECT); + } else { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DIALTONE); + } + ftdm_mutex_unlock(event->channel->mutex); + locked = 0; + ftdm_thread_create_detached(ftdm_analog_channel_run, event->channel); + } + } else { + if (!ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD)) { + if (ftdm_test_flag(event->channel, FTDM_CHANNEL_OFFHOOK)) { + ftdm_channel_command(event->channel, FTDM_COMMAND_ONHOOK, NULL); + } + } + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); + } + } + } + + end: + + if (locked) { + ftdm_mutex_unlock(event->channel->mutex); + } + return FTDM_SUCCESS; +} + +/** + * \brief Main thread function for analog span (monitor) + * \param me Current thread + * \param obj Span to run in this thread + */ +static void *ftdm_analog_run(ftdm_thread_t *me, void *obj) +{ + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_analog_data_t *analog_data = span->signal_data; + int errs = 0; + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG thread starting.\n"); + + while(ftdm_running() && ftdm_test_flag(analog_data, FTDM_ANALOG_RUNNING)) { + int waitms = 1000; + ftdm_status_t status; + + if ((status = ftdm_span_poll_event(span, waitms)) != FTDM_FAIL) { + errs = 0; + } + + switch(status) { + case FTDM_SUCCESS: + { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { + if (event->enum_id == FTDM_OOB_NOOP) { + continue; + } + if (process_event(span, event) != FTDM_SUCCESS) { + goto end; + } + } + } + break; + case FTDM_FAIL: + { + ftdm_log(FTDM_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); + if (++errs > 300) { + ftdm_log(FTDM_LOG_CRIT, "Too Many Errors!\n"); + goto end; + } + } + break; + default: + break; + } + + } + + end: + + ftdm_clear_flag(analog_data, FTDM_ANALOG_RUNNING); + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG thread ending.\n"); + + return NULL; +} + +/** + * \brief Openftdm analog signaling module initialisation + * \return Success + */ +static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_init) +{ + return FTDM_SUCCESS; +} + +/** + * \brief Openftdm analog signaling module definition + */ +EX_DECLARE_DATA ftdm_module_t ftdm_module = { + "analog", + NULL, + NULL, + ftdm_analog_init, + ftdm_analog_configure_span, + NULL +}; + + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2005.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2005.vcproj rename to libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2005.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2008.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2008.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h b/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h similarity index 87% rename from libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h rename to libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h index 5f0f726063..fbb268ae1d 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h @@ -36,26 +36,26 @@ * */ -#ifndef ZAP_ANALOG_EM_H -#define ZAP_ANALOG_EM_H -#include "openzap.h" +#ifndef FTDM_ANALOG_EM_H +#define FTDM_ANALOG_EM_H +#include "freetdm.h" #define MAX_DIALSTRING 256 typedef enum { - ZAP_ANALOG_EM_RUNNING = (1 << 0) -} zap_analog_em_flag_t; + FTDM_ANALOG_EM_RUNNING = (1 << 0) +} ftdm_analog_em_flag_t; -struct zap_analog_data { +struct ftdm_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; zio_signal_cb_t sig_cb; }; -static void *zap_analog_em_run(zap_thread_t *me, void *obj); -typedef struct zap_analog_data zap_analog_em_data_t; +static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj); +typedef struct ftdm_analog_data ftdm_analog_em_data_t; #endif diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c new file mode 100644 index 0000000000..2ff3db0990 --- /dev/null +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c @@ -0,0 +1,709 @@ +/* + * Copyright (c) 2008, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributor(s): + * + * John Wehle (john@feith.com) + * + */ + +#include "freetdm.h" +#include "ftdm_analog_em.h" + +#ifndef localtime_r +struct tm * localtime_r(const time_t *clock, struct tm *result); +#endif + +static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj); + +/** + * \brief Starts an EM channel thread (outgoing call) + * \param ftdmchan Channel to initiate call on + * \return Success or failure + * + * Initialises state, starts tone progress detection and runs the channel in a new a thread. + */ +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call) +{ + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_channel_clear_needed_tones(ftdmchan); + ftdm_channel_clear_detected_tones(ftdmchan); + + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + + ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL); + ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_PROGRESS_DETECT, NULL); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING); + ftdm_thread_create_detached(ftdm_analog_em_channel_run, ftdmchan); + return FTDM_SUCCESS; + } + + return FTDM_FAIL; +} + +/** + * \brief Starts an EM span thread (monitor) + * \param span Span to monitor + * \return Success or failure + */ +static ftdm_status_t ftdm_analog_em_start(ftdm_span_t *span) +{ + ftdm_analog_em_data_t *analog_data = span->signal_data; + ftdm_set_flag(analog_data, FTDM_ANALOG_EM_RUNNING); + return ftdm_thread_create_detached(ftdm_analog_em_run, span); +} + +/** + * \brief Initialises an EM span from configuration variables + * \param span Span to configure + * \param sig_cb Callback function for event signals + * \param ap List of configuration variables + * \return Success or failure + */ +static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_em_configure_span) +//ftdm_status_t ftdm_analog_em_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb) +{ + ftdm_analog_em_data_t *analog_data; + const char *tonemap = "us"; + uint32_t digit_timeout = 10; + uint32_t max_dialstr = 11; + const char *var, *val; + int *intval; + + assert(sig_cb != NULL); + + if (span->signal_type) { + snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); + return FTDM_FAIL; + } + + analog_data = ftdm_malloc(sizeof(*analog_data)); + assert(analog_data != NULL); + memset(analog_data, 0, sizeof(*analog_data)); + + while((var = va_arg(ap, char *))) { + if (!strcasecmp(var, "tonemap")) { + if (!(val = va_arg(ap, char *))) { + break; + } + tonemap = val; + } else if (!strcasecmp(var, "digit_timeout")) { + if (!(intval = va_arg(ap, int *))) { + break; + } + digit_timeout = *intval; + } else if (!strcasecmp(var, "max_dialstr")) { + if (!(intval = va_arg(ap, int *))) { + break; + } + max_dialstr = *intval; + } else { + snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); + return FTDM_FAIL; + } + } + + + if (digit_timeout < 2000 || digit_timeout > 10000) { + digit_timeout = 2000; + } + + if (max_dialstr < 2 || max_dialstr > MAX_DIALSTRING) { + ftdm_log(FTDM_LOG_ERROR, "Invalid max_dialstr, setting to %d\n", MAX_DIALSTRING); + max_dialstr = MAX_DIALSTRING; + } + + span->start = ftdm_analog_em_start; + analog_data->digit_timeout = digit_timeout; + analog_data->max_dialstr = max_dialstr; + analog_data->sig_cb = sig_cb; + span->signal_type = FTDM_SIGTYPE_ANALOG; + span->signal_data = analog_data; + span->outgoing_call = analog_em_outgoing_call; + ftdm_span_load_tones(span, tonemap); + + return FTDM_SUCCESS; + +} + +/** + * \brief Retrieves tone generation output to be sent + * \param ts Teletone generator + * \param map Tone map + * \return -1 on error, 0 on success + */ +static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map) +{ + ftdm_buffer_t *dt_buffer = ts->user_data; + int wrote; + + if (!dt_buffer) { + return -1; + } + wrote = teletone_mux_tones(ts, map); + ftdm_buffer_write(dt_buffer, ts->buffer, wrote * 2); + return 0; +} + +/** + * \brief Main thread function for EM channel (outgoing call) + * \param me Current thread + * \param obj Channel to run in this thread + */ +static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) +{ + ftdm_channel_t *ftdmchan = (ftdm_channel_t *) obj; + ftdm_buffer_t *dt_buffer = NULL; + teletone_generation_session_t ts; + uint8_t frame[1024]; + ftdm_size_t len, rlen; + ftdm_tone_type_t tt = FTDM_TONE_DTMF; + char dtmf[128] = ""; + ftdm_size_t dtmf_offset = 0; + ftdm_analog_em_data_t *analog_data = ftdmchan->span->signal_data; + ftdm_channel_t *closed_chan; + uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; + ftdm_sigmsg_t sig; + ftdm_status_t status; + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n"); + + ts.buffer = NULL; + + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); + goto done; + } + + if (ftdm_buffer_create(&dt_buffer, 1024, 3192, 0) != FTDM_SUCCESS) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "memory error!"); + ftdm_log(FTDM_LOG_ERROR, "MEM ERROR\n"); + goto done; + } + + if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "error initilizing tone detector!"); + ftdm_log(FTDM_LOG_ERROR, "TONE ERROR\n"); + goto done; + } + + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INTHREAD); + teletone_init_session(&ts, 0, teletone_handler, dt_buffer); + ts.rate = 8000; +#if 0 + ts.debug = 1; + ts.debug_stream = stdout; +#endif + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_INTERVAL, &interval); + ftdm_buffer_set_loops(dt_buffer, -1); + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + + assert(interval != 0); + + while (ftdm_running() && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_wait_flag_t flags = FTDM_READ; + ftdm_size_t dlen = 0; + + len = sizeof(frame); + + elapsed += interval; + state_counter += interval; + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + switch(ftdmchan->state) { + case FTDM_CHANNEL_STATE_DIALING: + { + if (! ftdmchan->needed_tones[FTDM_TONEMAP_RING] + && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_WINK)) { + if (ftdm_strlen_zero(ftdmchan->caller_data.ani.digits)) { + ftdm_log(FTDM_LOG_ERROR, "No Digits to send!\n"); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.ani.digits) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Send Digits Failed [%s]\n", ftdmchan->last_error); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + state_counter = 0; + ftdmchan->needed_tones[FTDM_TONEMAP_RING] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_BUSY] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_FAIL1] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_FAIL2] = 1; + ftdmchan->needed_tones[FTDM_TONEMAP_FAIL3] = 1; + dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.ani.digits)) + 2000; + } + } + break; + } + if (state_counter > dial_timeout) { + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_WINK)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP); + } + } + } + break; + case FTDM_CHANNEL_STATE_DIALTONE: + { + if (state_counter > 10000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } + } + break; + case FTDM_CHANNEL_STATE_BUSY: + { + if (state_counter > 20000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_ATTN); + } + } + break; + case FTDM_CHANNEL_STATE_ATTN: + { + if (state_counter > 20000) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + case FTDM_CHANNEL_STATE_HANGUP: + { + if (state_counter > 500) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && + (ftdmchan->last_state == FTDM_CHANNEL_STATE_RING || ftdmchan->last_state == FTDM_CHANNEL_STATE_DIALTONE + || ftdmchan->last_state >= FTDM_CHANNEL_STATE_IDLE)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else { + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CLEARING; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + } + break; + case FTDM_CHANNEL_STATE_UP: + case FTDM_CHANNEL_STATE_IDLE: + { + ftdm_sleep(interval); + continue; + } + break; + case FTDM_CHANNEL_STATE_DOWN: + { + goto done; + } + break; + default: + break; + } + } else { + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_clear_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); + ftdm_channel_complete_state(ftdmchan); + indicate = 0; + state_counter = 0; + + ftdm_log(FTDM_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", + ftdmchan->span_id, ftdmchan->chan_id, + ftdm_channel_state2str(ftdmchan->state)); + switch(ftdmchan->state) { + case FTDM_CHANNEL_STATE_UP: + { + ftdm_channel_use(ftdmchan); + ftdm_channel_clear_needed_tones(ftdmchan); + ftdm_channel_flush_dtmf(ftdmchan); + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK)) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_OFFHOOK, NULL); + } + + sig.event_id = FTDM_SIGEVENT_UP; + + analog_data->sig_cb(&sig); + continue; + } + break; + case FTDM_CHANNEL_STATE_DIALING: + { + ftdm_channel_use(ftdmchan); + } + break; + case FTDM_CHANNEL_STATE_IDLE: + { + ftdm_channel_use(ftdmchan); + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + ftdm_set_string(ftdmchan->caller_data.dnis.digits, ftdmchan->chan_number); + } else { + ftdm_set_string(ftdmchan->caller_data.dnis.digits, dtmf); + } + + sig.event_id = FTDM_SIGEVENT_START; + + analog_data->sig_cb(&sig); + continue; + } + break; + case FTDM_CHANNEL_STATE_DOWN: + { + sig.event_id = FTDM_SIGEVENT_STOP; + analog_data->sig_cb(&sig); + goto done; + } + break; + case FTDM_CHANNEL_STATE_DIALTONE: + { + memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data)); + *dtmf = '\0'; + dtmf_offset = 0; + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_DIAL]); + indicate = 1; + + ftdm_channel_command(ftdmchan, FTDM_COMMAND_WINK, NULL); + } + break; + case FTDM_CHANNEL_STATE_RING: + { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_RING]); + indicate = 1; + } + break; + case FTDM_CHANNEL_STATE_BUSY: + { + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION; + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_BUSY]); + indicate = 1; + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + case FTDM_CHANNEL_STATE_ATTN: + { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_ATTN]); + indicate = 1; + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + default: + break; + } + } + + + if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE || ftdmchan->state == FTDM_CHANNEL_STATE_COLLECT) { + if ((dlen = ftdm_channel_dequeue_dtmf(ftdmchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { + + if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALTONE) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_COLLECT); + collecting = 1; + } + dtmf_offset = strlen(dtmf); + last_digit = elapsed; + sig.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT; + sig.raw_data = dtmf; + if (analog_data->sig_cb(&sig) == FTDM_BREAK) { + collecting = 0; + } + } + } + + + if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) { + ftdm_log(FTDM_LOG_DEBUG, "Number obtained [%s]\n", dtmf); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE); + last_digit = 0; + collecting = 0; + } + + if (ftdm_channel_wait(ftdmchan, &flags, interval * 2) != FTDM_SUCCESS) { + continue; + } + + if (!(flags & FTDM_READ)) { + continue; + } + + if (ftdm_channel_read(ftdmchan, frame, &len) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "READ ERROR [%s]\n", ftdmchan->last_error); + goto done; + } + + if (ftdmchan->detected_tones[0]) { + ftdm_sigmsg_t sig; + int i; + memset(&sig, 0, sizeof(sig)); + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + sig.event_id = FTDM_SIGEVENT_TONE_DETECTED; + + for (i = 1; i < FTDM_TONEMAP_INVALID; i++) { + if (ftdmchan->detected_tones[i]) { + ftdm_log(FTDM_LOG_DEBUG, "Detected tone %s on %d:%d\n", ftdm_tonemap2str(i), ftdmchan->span_id, ftdmchan->chan_id); + sig.raw_data = &i; + if (analog_data->sig_cb) { + analog_data->sig_cb(&sig); + } + } + } + + if (ftdmchan->detected_tones[FTDM_TONEMAP_BUSY] || + ftdmchan->detected_tones[FTDM_TONEMAP_FAIL1] || + ftdmchan->detected_tones[FTDM_TONEMAP_FAIL2] || + ftdmchan->detected_tones[FTDM_TONEMAP_FAIL3] || + ftdmchan->detected_tones[FTDM_TONEMAP_ATTN] + ) { + ftdm_log(FTDM_LOG_ERROR, "Failure indication detected!\n"); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); + } else if (ftdmchan->detected_tones[FTDM_TONEMAP_RING]) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP); + } + + ftdm_channel_clear_detected_tones(ftdmchan); + } + + if ((ftdmchan->dtmf_buffer && ftdm_buffer_inuse(ftdmchan->dtmf_buffer))) { + rlen = len; + memset(frame, 0, len); + ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen); + continue; + } + + if (!indicate) { + continue; + } + + if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { + len *= 2; + } + + rlen = ftdm_buffer_read_loop(dt_buffer, frame, len); + + if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { + zio_codec_t codec_func = NULL; + + if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { + codec_func = zio_slin2ulaw; + } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { + codec_func = zio_slin2alaw; + } + + if (codec_func) { + status = codec_func(frame, sizeof(frame), &rlen); + } else { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + goto done; + } + } + + ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen); + } + + done: + + ftdm_channel_command(ftdmchan, FTDM_COMMAND_ONHOOK, NULL); + + closed_chan = ftdmchan; + ftdm_channel_close(&ftdmchan); + + ftdm_channel_command(closed_chan, FTDM_COMMAND_SET_NATIVE_CODEC, NULL); + + if (ts.buffer) { + teletone_destroy_session(&ts); + } + + if (dt_buffer) { + ftdm_buffer_destroy(&dt_buffer); + } + + ftdm_clear_flag(closed_chan, FTDM_CHANNEL_INTHREAD); + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n"); + + return NULL; +} + +/** + * \brief Processes EM events coming from ftdmtel/dahdi + * \param span Span on which the event was fired + * \param event Event to be treated + * \return Success or failure + */ +static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) +{ + ftdm_sigmsg_t sig; + int locked = 0; + + memset(&sig, 0, sizeof(sig)); + sig.chan_id = event->channel->chan_id; + sig.span_id = event->channel->span_id; + sig.channel = event->channel; + + + ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n", + ftdm_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state)); + + ftdm_mutex_lock(event->channel->mutex); + locked++; + + switch(event->enum_id) { + case FTDM_OOB_ONHOOK: + { + if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); + } + + } + break; + case FTDM_OOB_OFFHOOK: + { + if (ftdm_test_flag(event->channel, FTDM_CHANNEL_INTHREAD)) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP); + } else { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DIALTONE); + ftdm_mutex_unlock(event->channel->mutex); + locked = 0; + ftdm_thread_create_detached(ftdm_analog_em_channel_run, event->channel); + } + break; + } + case FTDM_OOB_WINK: + { + if (event->channel->state != FTDM_CHANNEL_STATE_DIALING) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); + } else { + ftdm_set_flag_locked(event->channel, FTDM_CHANNEL_WINK); + } + + } + break; + } + if (locked) { + ftdm_mutex_unlock(event->channel->mutex); + } + return FTDM_SUCCESS; +} + +/** + * \brief Main thread function for EM span (monitor) + * \param me Current thread + * \param obj Span to run in this thread + */ +static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj) +{ + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_analog_em_data_t *analog_data = span->signal_data; + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM thread starting.\n"); + + while(ftdm_running() && ftdm_test_flag(analog_data, FTDM_ANALOG_EM_RUNNING)) { + int waitms = 10; + ftdm_status_t status; + + status = ftdm_span_poll_event(span, waitms); + + switch(status) { + case FTDM_SUCCESS: + { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { + if (event->enum_id == FTDM_OOB_NOOP) { + continue; + } + if (process_event(span, event) != FTDM_SUCCESS) { + goto end; + } + } + } + break; + case FTDM_FAIL: + { + ftdm_log(FTDM_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); + } + break; + default: + break; + } + + } + + end: + + ftdm_clear_flag(analog_data, FTDM_ANALOG_EM_RUNNING); + + ftdm_log(FTDM_LOG_DEBUG, "ANALOG EM thread ending.\n"); + + return NULL; +} + +/** + * \brief Openftdm analog EM module initialisation + * \return Success + */ +static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_em_init) +{ + return FTDM_SUCCESS; +} + +/** + * \brief Openftdm analog EM module definition + */ +EX_DECLARE_DATA ftdm_module_t ftdm_module = { + "analog_em", + NULL, + NULL, + ftdm_analog_em_init, + ftdm_analog_em_configure_span, + NULL +}; + + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2005.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2005.vcproj rename to libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2005.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2008.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2008.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h similarity index 69% rename from libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h rename to libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h index b16b004a9d..c3b44bec5a 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h @@ -31,55 +31,55 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_ISDN_H -#define ZAP_ISDN_H -#include "openzap.h" +#ifndef FTDM_ISDN_H +#define FTDM_ISDN_H +#include "freetdm.h" #define DEFAULT_DIGIT_TIMEOUT 10000 /* default overlap timeout: 10 seconds */ typedef enum { - ZAP_ISDN_OPT_NONE = 0, - ZAP_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0), - ZAP_ISDN_OPT_OMIT_DISPLAY_IE = (1 << 1), /*!< Do not send Caller name in outgoing SETUP message (= Display IE) */ - ZAP_ISDN_OPT_DISABLE_TONES = (1 << 2), /*!< Disable tone generating thread (NT mode) */ + FTDM_ISDN_OPT_NONE = 0, + FTDM_ISDN_OPT_SUGGEST_CHANNEL = (1 << 0), + FTDM_ISDN_OPT_OMIT_DISPLAY_IE = (1 << 1), /*!< Do not send Caller name in outgoing SETUP message (= Display IE) */ + FTDM_ISDN_OPT_DISABLE_TONES = (1 << 2), /*!< Disable tone generating thread (NT mode) */ - ZAP_ISDN_OPT_MAX = (2 << 0) -} zap_isdn_opts_t; + FTDM_ISDN_OPT_MAX = (2 << 0) +} ftdm_isdn_opts_t; typedef enum { - ZAP_ISDN_RUNNING = (1 << 0), - ZAP_ISDN_TONES_RUNNING = (1 << 1), - ZAP_ISDN_STOP = (1 << 2) -} zap_isdn_flag_t; + FTDM_ISDN_RUNNING = (1 << 0), + FTDM_ISDN_TONES_RUNNING = (1 << 1), + FTDM_ISDN_STOP = (1 << 2) +} ftdm_isdn_flag_t; -struct zap_isdn_data { +struct ftdm_isdn_data { Q921Data_t q921; Q931_TrunkInfo_t q931; - zap_channel_t *dchan; - zap_channel_t *dchans[2]; - struct zap_sigmsg sigmsg; + ftdm_channel_t *dchan; + ftdm_channel_t *dchans[2]; + struct ftdm_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; int32_t digit_timeout; - zap_isdn_opts_t opts; - zap_caller_data_t *outbound_crv[32768]; - zap_channel_t *channels_local_crv[32768]; - zap_channel_t *channels_remote_crv[32768]; + ftdm_isdn_opts_t opts; + ftdm_caller_data_t *outbound_crv[32768]; + ftdm_channel_t *channels_local_crv[32768]; + ftdm_channel_t *channels_remote_crv[32768]; }; -typedef struct zap_isdn_data zap_isdn_data_t; +typedef struct ftdm_isdn_data ftdm_isdn_data_t; /* b-channel private data */ -struct zap_isdn_bchan_data +struct ftdm_isdn_bchan_data { L2ULONG digit_timeout; }; -typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; +typedef struct ftdm_isdn_bchan_data ftdm_isdn_bchan_data_t; #endif diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c similarity index 55% rename from libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c rename to libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index d927610668..898d606beb 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -38,7 +38,7 @@ #define __EXTENSIONS__ #endif -#include "openzap.h" +#include "freetdm.h" #include "Q931.h" #include "Q921.h" #ifdef WIN32 @@ -47,14 +47,14 @@ #include #endif -#include "zap_isdn.h" +#include "ftdm_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) +#define FTDM_SPAN_IS_BRI(x) ((x)->trunk_type == FTDM_TRUNK_BRI || (x)->trunk_type == FTDM_TRUNK_BRI_PTMP) +#define FTDM_SPAN_IS_NT(x) (((ftdm_isdn_data_t *)(x)->signal_data)->mode == Q921_NT) #ifdef HAVE_LIBPCAP @@ -117,31 +117,31 @@ L3UCHAR sendFrame[SNAPLEN]= { * \brief Opens a pcap file for capture * \return Success or failure */ -static zap_status_t openPcapFile(void) +static ftdm_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; + ftdm_log(FTDM_LOG_ERROR, "Can't open pcap session: (%s)\n", pcap_geterr(pcaphandle)); + return FTDM_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; + ftdm_log(FTDM_LOG_ERROR, "Error opening output file (%s)\n", pcap_geterr(pcaphandle)); + return FTDM_FAIL; } } else{ - zap_log(ZAP_LOG_WARNING, "Pcap file is already open!\n"); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_WARNING, "Pcap file is already open!\n"); + return FTDM_FAIL; } - zap_log(ZAP_LOG_DEBUG, "Pcap file '%s' successfully opened!\n", pcapfn); + ftdm_log(FTDM_LOG_DEBUG, "Pcap file '%s' successfully opened!\n", pcapfn); pcaphdr.ts.tv_sec = 0; pcaphdr.ts.tv_usec = 0; @@ -149,20 +149,20 @@ static zap_status_t openPcapFile(void) tcp_next_seq_no_send = 0; tcp_next_seq_no_rec = 0; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Closes a pcap file * \return Success */ -static zap_status_t closePcapFile(void) +static ftdm_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); + ftdm_log(FTDM_LOG_DEBUG, "Pcap file closed! File size is %lu bytes.\n", pcapfilesize); pcaphdr.ts.tv_sec = 0; pcaphdr.ts.tv_usec = 0; @@ -174,14 +174,14 @@ static zap_status_t closePcapFile(void) } /*We have allways success with this? I think so*/ - return ZAP_SUCCESS; + return FTDM_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) +static ftdm_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L3ULONG span_id, L3USHORT direction) { L3UCHAR *frame = NULL; struct timeval ts; @@ -212,8 +212,8 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L 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; + ftdm_log(FTDM_LOG_WARNING, "Q931 packet size is too big (%u)! Ignoring it!\n", q931size); + return FTDM_FAIL; } /*Copy q931 buffer into frame*/ @@ -255,9 +255,9 @@ static zap_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, L 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); + ftdm_log(FTDM_LOG_DEBUG, "Added %u bytes to pcap file. File size is now %lu, \n", q931size, pcapfilesize); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } #endif @@ -271,7 +271,7 @@ static ZIO_IO_UNLOAD_FUNCTION(close_pcap) #ifdef HAVE_LIBPCAP return closePcapFile(); #else - return ZAP_SUCCESS; + return FTDM_SUCCESS; #endif } @@ -282,21 +282,21 @@ static ZIO_IO_UNLOAD_FUNCTION(close_pcap) * \brief Gets current time * \return Current time (in ms) */ -static L2ULONG zap_time_now(void) +static L2ULONG ftdm_time_now(void) { - return (L2ULONG)zap_current_time_in_ms(); + return (L2ULONG)ftdm_current_time_in_ms(); } /** * \brief Initialises an ISDN channel (outgoing call) - * \param zchan Channel to initiate call on + * \param ftdmchan 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); + ftdm_status_t status = FTDM_SUCCESS; + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING); return status; } @@ -306,7 +306,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) * \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 + * \param ftdmchan Channel to initialise * \return Success or failure */ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) @@ -321,15 +321,15 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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; + ftdm_status_t status = FTDM_FAIL; + ftdm_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); + ftdm_channel_command(span->channels[chan_id], FTDM_COMMAND_GET_NATIVE_CODEC, &codec); /* * Q.931 Setup Message @@ -347,17 +347,17 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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 */ + BearerCap.UIL1Prot = (codec == FTDM_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 */ + ChanID.IntType = FTDM_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 */ + if(!FTDM_SPAN_IS_NT(span)) { + ChanID.PrefExcl = (isdn_data->opts & FTDM_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */ } else { ChanID.PrefExcl = 1; /* always exclusive in NT-mode */ } @@ -383,12 +383,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) /* * Display IE */ - if (!(isdn_data->opts & ZAP_ISDN_OPT_OMIT_DISPLAY_IE)) { + if (!(isdn_data->opts & FTDM_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); + ftdm_copy_string((char *)ptrDisplay->Display, caller_data->cid_name, strlen(caller_data->cid_name)+1); } /* @@ -402,7 +402,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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); + ftdm_copy_string((char *)ptrCallingNum->Digit, caller_data->cid_num.digits, strlen(caller_data->cid_num.digits)+1); /* @@ -414,7 +414,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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); + ftdm_copy_string((char *)ptrCalledNum->Digit, caller_data->ani.digits, strlen(caller_data->ani.digits)+1); /* * High-Layer Compatibility IE (Note: Required for AVM FritzBox) @@ -426,46 +426,46 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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; + caller_data->call_state = FTDM_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; + //isdn_data->channels_local_crv[gen->CRV] = ftdmchan; - while(zap_running() && caller_data->call_state == ZAP_CALLER_STATE_DIALING) { - zap_sleep(1); + while(ftdm_running() && caller_data->call_state == FTDM_CALLER_STATE_DIALING) { + ftdm_sleep(1); if (!--sanity) { - caller_data->call_state = ZAP_CALLER_STATE_FAIL; + caller_data->call_state = FTDM_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; + if (caller_data->call_state == FTDM_CALLER_STATE_SUCCESS) { + ftdm_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) { + if (caller_data->chan_id < FTDM_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) { + if (new_chan && (status = ftdm_channel_open_chan(new_chan) == FTDM_SUCCESS)) { + if (ftdm_test_flag(new_chan, FTDM_CHANNEL_INUSE) || new_chan->state != FTDM_CHANNEL_STATE_DOWN) { + if (new_chan->state == FTDM_CHANNEL_STATE_DOWN || new_chan->state >= FTDM_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"); + ftdm_log(FTDM_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)) { + if (!ftdm_test_flag(new_chan, FTDM_CHANNEL_INUSE)) { break; } - zap_sleep(5); + ftdm_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", + if (ftdm_test_flag(new_chan, FTDM_CHANNEL_INUSE)) { + ftdm_log(FTDM_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, @@ -475,20 +475,20 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) } } - if (new_chan && new_chan->state == ZAP_CHANNEL_STATE_DOWN) { + if (new_chan && new_chan->state == FTDM_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); + ftdm_set_flag(new_chan, FTDM_CHANNEL_OUTBOUND); + ftdm_set_state_locked(new_chan, FTDM_CHANNEL_STATE_DIALING); switch(gen->MesType) { case Q931mes_ALERTING: - new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; + new_chan->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; break; case Q931mes_CONNECT: - new_chan->init_state = ZAP_CHANNEL_STATE_UP; + new_chan->init_state = FTDM_CHANNEL_STATE_UP; break; default: - new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS; + new_chan->init_state = FTDM_CHANNEL_STATE_PROGRESS; break; } @@ -497,8 +497,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) } if (!fail) { - *zchan = new_chan; - return ZAP_SUCCESS; + *ftdmchan = new_chan; + return FTDM_SUCCESS; } else { Q931ie_Cause cause; gen->MesType = Q931mes_DISCONNECT; @@ -508,7 +508,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) 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.Value = (unsigned char) FTDM_CAUSE_WRONG_CALL_STATE; *cause.Diag = '\0'; gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); @@ -518,15 +518,15 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) } if (new_chan) { - zap_log(ZAP_LOG_CRIT, "Channel is busy\n"); + ftdm_log(FTDM_LOG_CRIT, "Channel is busy\n"); } else { - zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); + ftdm_log(FTDM_LOG_CRIT, "Failed to open channel for new setup message\n"); } } } - *zchan = NULL; - return ZAP_FAIL; + *ftdmchan = NULL; + return FTDM_FAIL; } @@ -538,9 +538,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) * \param p2 ?? * \return 0 */ -static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) +static L3INT ftdm_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); + ftdm_log(FTDM_LOG_ERROR, "ERROR: [%s] [%d] [%d]\n", q931_error_to_name(id), p1, p2); return 0; } @@ -551,15 +551,15 @@ static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2) * \param mlen Message string length * \return 0 */ -static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) +static L3INT ftdm_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; + ftdm_span_t *span = (ftdm_span_t *) pvt; + ftdm_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; + ftdm_channel_t *ftdmchan = NULL; + ftdm_caller_data_t *caller_data = NULL; if (Q931IsIEPresent(gen->ChanID)) { Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf); @@ -573,7 +573,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) if(chanid->InfoChanSel == 3) { chan_hunt++; } - } else if (ZAP_SPAN_IS_NT(span)) { + } else if (FTDM_SPAN_IS_NT(span)) { /* no channel ie */ chan_hunt++; } @@ -581,7 +581,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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"); + ftdm_log(FTDM_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) { @@ -596,11 +596,11 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_PROGRESS: case Q931mes_CONNECT: { - caller_data->call_state = ZAP_CALLER_STATE_SUCCESS; + caller_data->call_state = FTDM_CALLER_STATE_SUCCESS; } break; default: - caller_data->call_state = ZAP_CALLER_STATE_FAIL; + caller_data->call_state = FTDM_CALLER_STATE_FAIL; break; } @@ -608,12 +608,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } if (gen->CRVFlag) { - zchan = isdn_data->channels_local_crv[gen->CRV]; + ftdmchan = isdn_data->channels_local_crv[gen->CRV]; } else { - zchan = isdn_data->channels_remote_crv[gen->CRV]; + ftdmchan = 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); + ftdm_log(FTDM_LOG_DEBUG, "ftdmchan %x (%d:%d) source isdn_data->channels_%s_crv[%#hx]\n", ftdmchan, ftdmchan ? ftdmchan->span_id : -1, ftdmchan ? ftdmchan->chan_id : -1, gen->CRVFlag ? "local" : "remote", gen->CRV); if (gen->ProtDisc == 3) { @@ -621,25 +621,25 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_SERVICE: { Q931ie_ChangeStatus *changestatus = Q931GetIEPtr(gen->ChangeStatus, gen->buf); - if (zchan) { + if (ftdmchan) { 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); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_SUSPENDED); + ftdm_log(FTDM_LOG_DEBUG, "Channel %d:%d in service\n", ftdmchan->span_id, ftdmchan->chan_id); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_SUSPENDED); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_SUSPENDED); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED); } break; default: /* unknown */ @@ -658,14 +658,14 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) case Q931mes_RESTART: { if (chan_id) { - zchan = span->channels[chan_id]; + ftdmchan = span->channels[chan_id]; } - if (zchan) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + if (ftdmchan) { + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_set_state_locked((span->channels[i]), FTDM_CHANNEL_STATE_RESTART); } } } @@ -674,82 +674,82 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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 (ftdmchan) { + if (ftdmchan->state == FTDM_CHANNEL_STATE_TERMINATING || ftdmchan->state == FTDM_CHANNEL_STATE_HANGUP) { if (gen->MesType == Q931mes_RELEASE) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_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)) { + else if((gen->MesType == Q931mes_RELEASE && ftdmchan->state <= FTDM_CHANNEL_STATE_UP) || + (gen->MesType == Q931mes_RELEASE_COMPLETE && ftdmchan->state == FTDM_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; + ftdm_sigmsg_t sig; + ftdm_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.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + sig.channel->caller_data.hangup_cause = (cause) ? cause->Value : FTDM_CAUSE_NORMAL_UNSPECIFIED; - sig.event_id = ZAP_SIGEVENT_STOP; + sig.event_id = FTDM_SIGEVENT_STOP; status = isdn_data->sig_cb(&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); + ftdm_log(FTDM_LOG_DEBUG, "Received %s in state %s, requested hangup for channel %d:%d\n", what, ftdm_channel_state2str(ftdmchan->state), ftdmchan->span_id, chan_id); } else { - zap_log(ZAP_LOG_DEBUG, "Ignoring %s on channel %d\n", what, chan_id); + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_CRIT, "Received %s with no matching channel %d\n", what, chan_id); } } break; case Q931mes_DISCONNECT: { - if (zchan) { + if (ftdmchan) { Q931ie_Cause *cause = Q931GetIEPtr(gen->Cause, gen->buf); - zchan->caller_data.hangup_cause = cause->Value; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_TERMINATING); + ftdmchan->caller_data.hangup_cause = cause->Value; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING); } else { - zap_log(ZAP_LOG_CRIT, "Received Disconnect with no matching channel %d\n", chan_id); + ftdm_log(FTDM_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); + if (ftdmchan) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); } else { - zap_log(ZAP_LOG_CRIT, "Received Alerting with no matching channel %d\n", chan_id); + ftdm_log(FTDM_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); + if (ftdmchan) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } else { - zap_log(ZAP_LOG_CRIT, "Received Progress with no matching channel %d\n", chan_id); + ftdm_log(FTDM_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); + if (ftdmchan) { + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_log(FTDM_LOG_CRIT, "Received Connect with no matching channel %d\n", chan_id); } } break; @@ -762,21 +762,21 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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)); + if(ftdmchan && ftdmchan == isdn_data->channels_remote_crv[gen->CRV]) { + ftdm_log(FTDM_LOG_INFO, "Duplicate SETUP message(?) for Channel %d:%d ~ %d:%d in state %s [ignoring]\n", + ftdmchan->span_id, + ftdmchan->chan_id, + ftdmchan->physical_span_id, + ftdmchan->physical_chan_id, + ftdm_channel_state2str(ftdmchan->state)); break; } - zchan = NULL; + ftdmchan = NULL; /* * Channel selection for incoming calls: */ - if (ZAP_SPAN_IS_NT(span) && chan_hunt) { + if (FTDM_SPAN_IS_NT(span) && chan_hunt) { uint32_t x; /* @@ -784,21 +784,21 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * try to find a free channel */ for (x = 1; x <= span->chan_count; x++) { - zap_channel_t *zc = span->channels[x]; + ftdm_channel_t *zc = span->channels[x]; - if (!zap_test_flag(zc, ZAP_CHANNEL_INUSE) && zc->state == ZAP_CHANNEL_STATE_DOWN) { - zchan = zc; + if (!ftdm_test_flag(zc, FTDM_CHANNEL_INUSE) && zc->state == FTDM_CHANNEL_STATE_DOWN) { + ftdmchan = zc; break; } } } - else if (!ZAP_SPAN_IS_NT(span) && chan_hunt) { + else if (!FTDM_SPAN_IS_NT(span) && chan_hunt) { /* * In TE-mode this ("any") is invalid */ - fail_cause = ZAP_CAUSE_CHANNEL_UNACCEPTABLE; + fail_cause = FTDM_CAUSE_CHANNEL_UNACCEPTABLE; - zap_log(ZAP_LOG_ERROR, "Invalid channel selection in incoming call (network side didn't specify a channel)\n"); + ftdm_log(FTDM_LOG_ERROR, "Invalid channel selection in incoming call (network side didn't specify a channel)\n"); } else { /* @@ -807,78 +807,78 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * 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]; + if (chan_id > 0 && chan_id < FTDM_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) { + ftdmchan = span->channels[chan_id]; } else { /* invalid channel id */ - fail_cause = ZAP_CAUSE_CHANNEL_UNACCEPTABLE; + fail_cause = FTDM_CAUSE_CHANNEL_UNACCEPTABLE; - zap_log(ZAP_LOG_ERROR, "Invalid channel selection in incoming call (none selected or out of bounds)\n"); + ftdm_log(FTDM_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"); + if (FTDM_SPAN_IS_NT(span)) { + ftdm_log(FTDM_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; + ftdm_log(FTDM_LOG_ERROR, "No destination number found\n"); + ftdmchan = 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) { + if (ftdmchan) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE) || ftdmchan->state != FTDM_CHANNEL_STATE_DOWN) { + if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN || ftdmchan->state >= FTDM_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); + ftdm_log(FTDM_LOG_WARNING, "Channel %d:%d ~ %d:%d is already in use waiting for it to become available.\n", + ftdmchan->span_id, + ftdmchan->chan_id, + ftdmchan->physical_span_id, + ftdmchan->physical_chan_id); for (x = 0; x < 200; x++) { - if (!zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) { break; } - zap_sleep(5); + ftdm_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 + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) { + ftdm_log(FTDM_LOG_ERROR, "Channel %d:%d ~ %d:%d is already in use.\n", + ftdmchan->span_id, + ftdmchan->chan_id, + ftdmchan->physical_span_id, + ftdmchan->physical_chan_id ); - zchan = NULL; + ftdmchan = 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 (ftdmchan && ftdmchan->state == FTDM_CHANNEL_STATE_DOWN) { + isdn_data->channels_remote_crv[gen->CRV] = ftdmchan; + memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->caller_data)); - if (zchan->mod_data) { - memset(zchan->mod_data, 0, sizeof(zap_isdn_bchan_data_t)); + if (ftdmchan->mod_data) { + memset(ftdmchan->mod_data, 0, sizeof(ftdm_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); + ftdm_set_string(ftdmchan->caller_data.cid_num.digits, (char *)callingnum->Digit); + ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)callingnum->Digit); + ftdm_set_string(ftdmchan->caller_data.ani.digits, (char *)callingnum->Digit); if (!overlap_dial) { - zap_set_string(zchan->caller_data.dnis.digits, (char *)callednum->Digit); + ftdm_set_string(ftdmchan->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); + ftdmchan->caller_data.CRV = gen->CRV; + if (cplen > sizeof(ftdmchan->caller_data.raw_data)) { + cplen = sizeof(ftdmchan->caller_data.raw_data); } gen->CRVFlag = !(gen->CRVFlag); - memcpy(zchan->caller_data.raw_data, msg, cplen); - zchan->caller_data.raw_data_len = cplen; + memcpy(ftdmchan->caller_data.raw_data, msg, cplen); + ftdmchan->caller_data.raw_data_len = cplen; fail = 0; } } @@ -893,7 +893,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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.Value = (unsigned char)((fail_cause) ? fail_cause : FTDM_CAUSE_WRONG_CALL_STATE); *cause.Diag = '\0'; gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); @@ -902,10 +902,10 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) Q931ReleaseCRV(&isdn_data->q931, gen->CRV); } - if (zchan) { - zap_log(ZAP_LOG_CRIT, "Channel is busy\n"); + if (ftdmchan) { + ftdm_log(FTDM_LOG_CRIT, "Channel is busy\n"); } else { - zap_log(ZAP_LOG_CRIT, "Failed to open channel for new setup message\n"); + ftdm_log(FTDM_LOG_CRIT, "Failed to open channel for new setup message\n"); } } else { @@ -915,14 +915,14 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * 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 */ + ChanID.IntType = FTDM_SPAN_IS_BRI(ftdmchan->span) ? 0 : 1; /* PRI = 1, BRI = 0 */ + ChanID.PrefExcl = FTDM_SPAN_IS_NT(ftdmchan->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; + ChanID.ChanSlot = (unsigned char)ftdmchan->chan_id; } else { - ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */ + ChanID.InfoChanSel = (unsigned char)ftdmchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */ } gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); @@ -946,12 +946,12 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) gen->CRVFlag = 1; /* inbound call */ Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALTONE); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALTONE); } else { /* * Advance to RING state */ - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RING); } } } @@ -959,37 +959,37 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) 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); + if (ftdmchan) { + ftdm_log(FTDM_LOG_CRIT, "Received CALL PROCEEDING message for channel %d\n", chan_id); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); } else { - zap_log(ZAP_LOG_CRIT, "Received CALL PROCEEDING with no matching channel %d\n", chan_id); + ftdm_log(FTDM_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); + if (ftdmchan) { + ftdm_log(FTDM_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); + ftdm_log(FTDM_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 (ftdmchan) { + ftdm_log(FTDM_LOG_CRIT, "Received INFORMATION message for channel %d\n", ftdmchan->chan_id); - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { + if (ftdmchan->state == FTDM_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; + ftdm_isdn_bchan_data_t *data = (ftdm_isdn_bchan_data_t *)ftdmchan->mod_data; Q931ie_CalledNum *callednum = Q931GetIEPtr(gen->CalledNum, gen->buf); int pos; @@ -999,23 +999,23 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) } /* 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); + pos = (int)strlen(ftdmchan->caller_data.dnis.digits); + strcat(&ftdmchan->caller_data.dnis.digits[pos], (char *)callednum->Digit); /* update timer */ - data->digit_timeout = zap_time_now() + isdn_data->digit_timeout; + data->digit_timeout = ftdm_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); + ftdm_log(FTDM_LOG_DEBUG, "Received new overlap digit (%s), destination number: %s\n", callednum->Digit, ftdmchan->caller_data.dnis.digits); } if (Q931IsIEPresent(gen->SendComplete) || digit == '#') { - zap_log(ZAP_LOG_DEBUG, "Leaving overlap dial mode\n"); + ftdm_log(FTDM_LOG_DEBUG, "Leaving overlap dial mode\n"); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RING); } } } else { - zap_log(ZAP_LOG_CRIT, "Received INFORMATION message with no matching channel\n"); + ftdm_log(FTDM_LOG_CRIT, "Received INFORMATION message with no matching channel\n"); } } break; @@ -1025,7 +1025,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) /* * !! HACK ALERT !! * - * Map OpenZAP channel states to Q.931 states + * Map OpenFTDM channel states to Q.931 states */ Q931ie_CallState state; Q931ie_Cause cause; @@ -1043,18 +1043,18 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) cause.Recom = 1; /* */ *cause.Diag = '\0'; - if(zchan) { - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: + if(ftdmchan) { + switch(ftdmchan->state) { + case FTDM_CHANNEL_STATE_UP: state.CallState = Q931_U10; /* Active */ break; - case ZAP_CHANNEL_STATE_RING: + case FTDM_CHANNEL_STATE_RING: state.CallState = Q931_U6; /* Call present */ break; - case ZAP_CHANNEL_STATE_DIALING: + case FTDM_CHANNEL_STATE_DIALING: state.CallState = Q931_U1; /* Call initiated */ break; - case ZAP_CHANNEL_STATE_DIALTONE: + case FTDM_CHANNEL_STATE_DIALTONE: state.CallState = Q931_U25; /* Overlap receiving */ break; @@ -1076,7 +1076,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) break; default: - zap_log(ZAP_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType); + ftdm_log(FTDM_LOG_CRIT, "Received unhandled message %d (%#x)\n", (int)gen->MesType, (int)gen->MesType); break; } } @@ -1093,7 +1093,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) * \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) +static int ftdm_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] = ""; @@ -1105,19 +1105,19 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg #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"); + ftdm_span_t *span = (ftdm_span_t *) pvt; + if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 1) != FTDM_SUCCESS){ + ftdm_log(FTDM_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); + ftdm_log(FTDM_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)); + ftdm_log(FTDM_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret)); break; } @@ -1131,84 +1131,84 @@ static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR tei, L2UCHAR *msg * \param mlen Message string length * \return 0 on success, -1 on failure */ -static int zap_isdn_921_21(void *pvt, L2UCHAR *msg, L2INT mlen) +static int ftdm_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; + ftdm_span_t *span = (ftdm_span_t *) pvt; + ftdm_size_t len = (ftdm_size_t) mlen; + ftdm_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); + print_bits(msg, (int)len, bb, sizeof(bb), FTDM_ENDIAN_LITTLE, 0); + ftdm_log(FTDM_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; + return ftdm_channel_write(isdn_data->dchan, msg, len, &len) == FTDM_SUCCESS ? 0 : -1; } /** * \brief Handler for channel state change - * \param zchan Channel to handle + * \param ftdmchan Channel to handle */ -static __inline__ void state_advance(zap_channel_t *zchan) +static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { - 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; + Q931mes_Generic *gen = (Q931mes_Generic *) ftdmchan->caller_data.raw_data; + ftdm_isdn_data_t *isdn_data = ftdmchan->span->signal_data; + ftdm_sigmsg_t sig; + ftdm_status_t status; - zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n", - zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); + ftdm_log(FTDM_LOG_DEBUG, "%d:%d STATE [%s]\n", + ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; - switch (zchan->state) { - case ZAP_CHANNEL_STATE_DOWN: + switch (ftdmchan->state) { + case FTDM_CHANNEL_STATE_DOWN: { if (gen->CRV) { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + if (ftdm_test_flag(ftdmchan, FTDM_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); + ftdm_channel_done(ftdmchan); } break; - case ZAP_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_PROGRESS: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { gen->MesType = Q931mes_CALL_PROCEEDING; gen->CRVFlag = 1; /* inbound */ - if (ZAP_SPAN_IS_NT(zchan->span)) { + if (FTDM_SPAN_IS_NT(ftdmchan->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.IntType = FTDM_SPAN_IS_BRI(ftdmchan->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; + ChanID.ChanSlot = (unsigned char)ftdmchan->chan_id; } else { - ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */ + ChanID.InfoChanSel = (unsigned char)ftdmchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */ } gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); } @@ -1217,44 +1217,44 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; - case ZAP_CHANNEL_STATE_DIALTONE: + case FTDM_CHANNEL_STATE_DIALTONE: { - zap_isdn_bchan_data_t *data = (zap_isdn_bchan_data_t *)zchan->mod_data; + ftdm_isdn_bchan_data_t *data = (ftdm_isdn_bchan_data_t *)ftdmchan->mod_data; if (data) { - data->digit_timeout = zap_time_now() + isdn_data->digit_timeout; + data->digit_timeout = ftdm_time_now() + isdn_data->digit_timeout; } } break; - case ZAP_CHANNEL_STATE_RING: + case FTDM_CHANNEL_STATE_RING: { - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_START; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_START; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } } break; - case ZAP_CHANNEL_STATE_RESTART: + case FTDM_CHANNEL_STATE_RESTART: { - zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED; - sig.event_id = ZAP_SIGEVENT_RESTART; + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_UNSPECIFIED; + sig.event_id = FTDM_SIGEVENT_RESTART; status = isdn_data->sig_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_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); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); return; } } @@ -1264,29 +1264,29 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; - case ZAP_CHANNEL_STATE_UP: + case FTDM_CHANNEL_STATE_UP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_UP; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_UP; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_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); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_set_state_locked(ftdmchan, FTDM_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); + Q931Rx43(&isdn_data->q931, (void *)gen, ftdmchan->caller_data.raw_data_len); } } break; - case ZAP_CHANNEL_STATE_DIALING: - if (!(isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { + case FTDM_CHANNEL_STATE_DIALING: + if (!(isdn_data->opts & FTDM_ISDN_OPT_SUGGEST_CHANNEL)) { Q931ie_BearerCap BearerCap; Q931ie_ChanID ChanID; Q931ie_CallingNum CallingNum; @@ -1301,7 +1301,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* * get codec type */ - zap_channel_command(zchan->span->channels[zchan->chan_id], ZAP_COMMAND_GET_NATIVE_CODEC, &codec); + ftdm_channel_command(ftdmchan->span->channels[ftdmchan->chan_id], FTDM_COMMAND_GET_NATIVE_CODEC, &codec); /* * Q.931 Setup Message @@ -1319,21 +1319,21 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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 */ + BearerCap.UIL1Prot = (codec == FTDM_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 */ + ChanID.IntType = FTDM_SPAN_IS_BRI(ftdmchan->span) ? 0 : 1; /* PRI = 1, BRI = 0 */ + ChanID.PrefExcl = FTDM_SPAN_IS_NT(ftdmchan->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; + ChanID.ChanSlot = (unsigned char)ftdmchan->chan_id; } else { - ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */ + ChanID.InfoChanSel = (unsigned char)ftdmchan->chan_id & 0x03; /* None = 0, B1 = 1, B2 = 2, Any = 3 */ } gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID); @@ -1349,26 +1349,26 @@ static __inline__ void state_advance(zap_channel_t *zchan) /* * Display IE */ - if (!(isdn_data->opts & ZAP_ISDN_OPT_OMIT_DISPLAY_IE)) { + if (!(isdn_data->opts & FTDM_ISDN_OPT_OMIT_DISPLAY_IE)) { Q931InitIEDisplay(&Display); - Display.Size = Display.Size + (unsigned char)strlen(zchan->caller_data.cid_name); + Display.Size = Display.Size + (unsigned char)strlen(ftdmchan->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); + ftdm_copy_string((char *)ptrDisplay->Display, ftdmchan->caller_data.cid_name, strlen(ftdmchan->caller_data.cid_name)+1); } /* * CallingNum IE */ Q931InitIECallingNum(&CallingNum); - CallingNum.TypNum = zchan->caller_data.ani.type; + CallingNum.TypNum = ftdmchan->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); + CallingNum.Size = CallingNum.Size + (unsigned char)strlen(ftdmchan->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); + ftdm_copy_string((char *)ptrCallingNum->Digit, ftdmchan->caller_data.cid_num.digits, strlen(ftdmchan->caller_data.cid_num.digits)+1); /* * CalledNum IE @@ -1376,10 +1376,10 @@ static __inline__ void state_advance(zap_channel_t *zchan) Q931InitIECalledNum(&CalledNum); CalledNum.TypNum = Q931_TON_UNKNOWN; CalledNum.NumPlanID = Q931_NUMPLAN_E164; - CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani.digits); + CalledNum.Size = CalledNum.Size + (unsigned char)strlen(ftdmchan->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); + ftdm_copy_string((char *)ptrCalledNum->Digit, ftdmchan->caller_data.ani.digits, strlen(ftdmchan->caller_data.ani.digits)+1); /* * High-Layer Compatibility IE (Note: Required for AVM FritzBox) @@ -1392,27 +1392,27 @@ static __inline__ void state_advance(zap_channel_t *zchan) gen->HLComp = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &HLComp); Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size); - isdn_data->channels_local_crv[gen->CRV] = zchan; + isdn_data->channels_local_crv[gen->CRV] = ftdmchan; } break; - case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + case FTDM_CHANNEL_STATE_HANGUP_COMPLETE: { /* reply RELEASE with RELEASE_COMPLETE message */ - if(zchan->last_state == ZAP_CHANNEL_STATE_HANGUP) { + if(ftdmchan->last_state == FTDM_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); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; - case ZAP_CHANNEL_STATE_HANGUP: + case FTDM_CHANNEL_STATE_HANGUP: { Q931ie_Cause cause; - zap_log(ZAP_LOG_DEBUG, "Hangup: Direction %s\n", zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound"); + ftdm_log(FTDM_LOG_DEBUG, "Hangup: Direction %s\n", ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound"); - gen->CRVFlag = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? 0 : 1; + gen->CRVFlag = ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? 0 : 1; cause.IEId = Q931ie_CAUSE; cause.Size = sizeof(Q931ie_Cause); @@ -1424,36 +1424,36 @@ static __inline__ void state_advance(zap_channel_t *zchan) * BRI PTMP needs special handling here... * TODO: cleanup / refine (see above) */ - if (zchan->last_state == ZAP_CHANNEL_STATE_RING) { + if (ftdmchan->last_state == FTDM_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.Value = (unsigned char) FTDM_CAUSE_UNALLOCATED; + cause.Value = (unsigned char) ftdmchan->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); + //ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } - else if (zchan->last_state <= ZAP_CHANNEL_STATE_PROGRESS) { + else if (ftdmchan->last_state <= FTDM_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.Value = (unsigned char) ftdmchan->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); */ + /* ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE); */ } else { /* @@ -1461,21 +1461,21 @@ static __inline__ void state_advance(zap_channel_t *zchan) */ gen->MesType = Q931mes_DISCONNECT; - cause.Value = (unsigned char) zchan->caller_data.hangup_cause; + cause.Value = (unsigned char) ftdmchan->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: + case FTDM_CHANNEL_STATE_TERMINATING: { - zap_log(ZAP_LOG_DEBUG, "Terminating: Direction %s\n", zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound"); + ftdm_log(FTDM_LOG_DEBUG, "Terminating: Direction %s\n", ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound"); - sig.event_id = ZAP_SIGEVENT_STOP; + sig.event_id = FTDM_SIGEVENT_STOP; status = isdn_data->sig_cb(&sig); gen->MesType = Q931mes_RELEASE; - gen->CRVFlag = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? 0 : 1; + gen->CRVFlag = ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? 0 : 1; Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); } default: @@ -1487,110 +1487,110 @@ static __inline__ void state_advance(zap_channel_t *zchan) * \brief Checks current state on a span * \param span Span to check status on */ -static __inline__ void check_state(zap_span_t *span) +static __inline__ void check_state(ftdm_span_t *span) { - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + if (ftdm_test_flag(span, FTDM_SPAN_STATE_CHANGE)) { uint32_t j; - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); + ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE); for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - zap_mutex_lock(span->channels[j]->mutex); - zap_clear_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + if (ftdm_test_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_mutex_lock(span->channels[j]->mutex); + ftdm_clear_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE); state_advance(span->channels[j]); - zap_channel_complete_state(span->channels[j]); - zap_mutex_unlock(span->channels[j]->mutex); + ftdm_channel_complete_state(span->channels[j]); + ftdm_mutex_unlock(span->channels[j]->mutex); } } } } /** - * \brief Processes Openzap event on a span + * \brief Processes Openftdm 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) +static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) { - zap_sigmsg_t sig; - zap_isdn_data_t *isdn_data = span->signal_data; + ftdm_sigmsg_t sig; + ftdm_isdn_data_t *isdn_data = span->signal_data; 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)); + ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n", + ftdm_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state)); switch(event->enum_id) { - case ZAP_OOB_ALARM_TRAP: + case FTDM_OOB_ALARM_TRAP: { - sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)ZAP_HW_LINK_DISCONNECTED; - 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); + sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)FTDM_HW_LINK_DISCONNECTED; + if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) { + if (event->channel->type == FTDM_CHAN_TYPE_B) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_RESTART); } } - zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + ftdm_set_flag(event->channel, FTDM_CHANNEL_SUSPENDED); - zap_channel_get_alarms(event->channel); + ftdm_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); - zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) has alarms! [%s]\n", + ftdm_log(FTDM_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: + case FTDM_OOB_ALARM_CLEAR: { - zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) alarms Cleared!\n", event->channel->span_id, event->channel->chan_id, + ftdm_log(FTDM_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); - sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)ZAP_HW_LINK_CONNECTED; - zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); - zap_channel_get_alarms(event->channel); + sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; + ftdm_clear_flag(event->channel, FTDM_CHANNEL_SUSPENDED); + ftdm_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); } break; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Checks for events on a span * \param span Span to check for events */ -static __inline__ void check_events(zap_span_t *span) +static __inline__ void check_events(ftdm_span_t *span) { - zap_status_t status; + ftdm_status_t status; - status = zap_span_poll_event(span, 5); + status = ftdm_span_poll_event(span, 5); switch(status) { - case ZAP_SUCCESS: + case FTDM_SUCCESS: { - zap_event_t *event; - while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { - if (event->enum_id == ZAP_OOB_NOOP) { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { + if (event->enum_id == FTDM_OOB_NOOP) { continue; } - if (process_event(span, event) != ZAP_SUCCESS) { + if (process_event(span, event) != FTDM_SUCCESS) { break; } } } break; - case ZAP_FAIL: + case FTDM_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); + ftdm_log(FTDM_LOG_DEBUG, "Event Failure! %d\n", ftdm_running()); } break; default: @@ -1606,14 +1606,14 @@ static __inline__ void check_events(zap_span_t *span) */ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map) { - zap_buffer_t *dt_buffer = ts->user_data; + ftdm_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); + ftdm_buffer_write(dt_buffer, ts->buffer, wrote * 2); return 0; } @@ -1622,38 +1622,38 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map * \param me Current thread * \param obj Span to generate tones on */ -static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) +static void *ftdm_isdn_tones_run(ftdm_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; + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_isdn_data_t *isdn_data = span->signal_data; + ftdm_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); + ftdm_log(FTDM_LOG_DEBUG, "ISDN tones thread starting.\n"); + ftdm_set_flag(isdn_data, FTDM_ISDN_TONES_RUNNING); - if (zap_buffer_create(&dt_buffer, 1024, 1024, 0) != ZAP_SUCCESS) { + if (ftdm_buffer_create(&dt_buffer, 1024, 1024, 0) != FTDM_SUCCESS) { snprintf(isdn_data->dchan->last_error, sizeof(isdn_data->dchan->last_error), "memory error!"); - zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); + ftdm_log(FTDM_LOG_ERROR, "MEM ERROR\n"); goto done; } - zap_buffer_set_loops(dt_buffer, -1); + ftdm_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); + if (span->channels[x]->type != FTDM_CHAN_TYPE_DQ921) { + ftdm_channel_command(span->channels[x], FTDM_COMMAND_GET_INTERVAL, &interval); break; } } if (!interval) { interval = 20; } - zap_log(ZAP_LOG_NOTICE, "Tone generating interval %d\n", interval); + ftdm_log(FTDM_LOG_NOTICE, "Tone generating interval %d\n", interval); /* init teletone */ teletone_init_session(&ts, 0, teletone_handler, dt_buffer); @@ -1661,21 +1661,21 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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; + while(ftdm_running() && ftdm_test_flag(isdn_data, FTDM_ISDN_TONES_RUNNING) && !ftdm_test_flag(isdn_data, FTDM_ISDN_STOP)) { + ftdm_wait_flag_t flags; + ftdm_status_t status; int last_chan_state = 0; int gated = 0; - L2ULONG now = zap_time_now(); + L2ULONG now = ftdm_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; + ftdm_channel_t *ftdmchan = span->channels[x]; + ftdm_size_t len = sizeof(frame), rlen; - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { continue; } @@ -1684,40 +1684,40 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) * (Recycle buffer content if succeeding channels share the * same state, this saves some cpu cycles) */ - switch (zchan->state) { - case ZAP_CHANNEL_STATE_DIALTONE: + switch (ftdmchan->state) { + case FTDM_CHANNEL_STATE_DIALTONE: { - zap_isdn_bchan_data_t *data = (zap_isdn_bchan_data_t *)zchan->mod_data; + ftdm_isdn_bchan_data_t *data = (ftdm_isdn_bchan_data_t *)ftdmchan->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); + if (strlen(ftdmchan->caller_data.dnis.digits) > 0) { + ftdm_log(FTDM_LOG_DEBUG, "Overlap dial timeout, advancing to RING state\n"); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "Overlap dial timeout, no digits received, going to HANGUP state\n"); + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_RECOVERY_ON_TIMER_EXPIRE; /* TODO: probably wrong cause value */ + ftdm_set_state_locked(ftdmchan, FTDM_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; + if (last_chan_state != ftdmchan->state) { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_DIAL]); + last_chan_state = ftdmchan->state; } } break; - case ZAP_CHANNEL_STATE_RING: + case FTDM_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; + if (last_chan_state != ftdmchan->state) { + ftdm_buffer_zero(dt_buffer); + teletone_run(&ts, ftdmchan->span->tone_map[FTDM_TONEMAP_RING]); + last_chan_state = ftdmchan->state; } } break; @@ -1726,70 +1726,70 @@ static void *zap_isdn_tones_run(zap_thread_t *me, void *obj) 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); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); continue; } - zap_log(ZAP_LOG_NOTICE, "Successfully opened channel %d:%d\n", zchan->span_id, zchan->chan_id); + ftdm_log(FTDM_LOG_NOTICE, "Successfully opened channel %d:%d\n", ftdmchan->span_id, ftdmchan->chan_id); } - flags = ZAP_READ; + flags = FTDM_READ; - status = zap_channel_wait(zchan, &flags, (gated) ? 0 : interval); + status = ftdm_channel_wait(ftdmchan, &flags, (gated) ? 0 : interval); switch(status) { - case ZAP_FAIL: + case FTDM_FAIL: continue; - case ZAP_TIMEOUT: + case FTDM_TIMEOUT: gated = 1; continue; default: - if (!(flags & ZAP_READ)) { + if (!(flags & FTDM_READ)) { continue; } } gated = 1; - status = zap_channel_read(zchan, frame, &len); - if (status != ZAP_SUCCESS || len <= 0) { + status = ftdm_channel_read(ftdmchan, frame, &len); + if (status != FTDM_SUCCESS || len <= 0) { continue; } - if (zchan->effective_codec != ZAP_CODEC_SLIN) { + if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { len *= 2; } /* seek to current offset */ - zap_buffer_seek(dt_buffer, offset); + ftdm_buffer_seek(dt_buffer, offset); - rlen = zap_buffer_read_loop(dt_buffer, frame, len); + rlen = ftdm_buffer_read_loop(dt_buffer, frame, len); - if (zchan->effective_codec != ZAP_CODEC_SLIN) { + if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { zio_codec_t codec_func = NULL; - if (zchan->native_codec == ZAP_CODEC_ULAW) { + if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { codec_func = zio_slin2ulaw; - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { + } else if (ftdmchan->native_codec == FTDM_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!"); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); goto done; } } - zap_channel_write(zchan, frame, sizeof(frame), &rlen); + ftdm_channel_write(ftdmchan, frame, sizeof(frame), &rlen); } /* * sleep a bit if there was nothing to do */ if (!gated) { - zap_sleep(interval); + ftdm_sleep(interval); } offset += (ts.rate / (1000 / interval)) << 1; @@ -1804,11 +1804,11 @@ done: } if (dt_buffer) { - zap_buffer_destroy(&dt_buffer); + ftdm_buffer_destroy(&dt_buffer); } - zap_log(ZAP_LOG_DEBUG, "ISDN tone thread ended.\n"); - zap_clear_flag(isdn_data, ZAP_ISDN_TONES_RUNNING); + ftdm_log(FTDM_LOG_DEBUG, "ISDN tone thread ended.\n"); + ftdm_clear_flag(isdn_data, FTDM_ISDN_TONES_RUNNING); return NULL; } @@ -1818,26 +1818,26 @@ done: * \param me Current thread * \param obj Span to monitor */ -static void *zap_isdn_run(zap_thread_t *me, void *obj) +static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj) { - zap_span_t *span = (zap_span_t *) obj; - zap_isdn_data_t *isdn_data = span->signal_data; + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_isdn_data_t *isdn_data = span->signal_data; unsigned char frame[1024]; - zap_size_t len = sizeof(frame); + ftdm_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); + ftdm_log(FTDM_LOG_DEBUG, "ISDN thread starting.\n"); + ftdm_set_flag(isdn_data, FTDM_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); + while(ftdm_running() && ftdm_test_flag(isdn_data, FTDM_ISDN_RUNNING) && !ftdm_test_flag(isdn_data, FTDM_ISDN_STOP)) { + ftdm_wait_flag_t flags = FTDM_READ; + ftdm_status_t status = ftdm_channel_wait(isdn_data->dchan, &flags, 100); Q921TimerTick(&isdn_data->q921); Q931TimerTick(&isdn_data->q931); @@ -1848,17 +1848,17 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) * */ switch(status) { - case ZAP_FAIL: + case FTDM_FAIL: { - zap_log(ZAP_LOG_ERROR, "D-Chan Read Error!\n"); + ftdm_log(FTDM_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; + isdn_data->dchan->state = FTDM_CHANNEL_STATE_UP; goto done; } } break; - case ZAP_TIMEOUT: + case FTDM_TIMEOUT: { errs = 0; } @@ -1866,26 +1866,26 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) default: { errs = 0; - if (flags & ZAP_READ) { + if (flags & FTDM_READ) { - if (zap_test_flag(isdn_data->dchan, ZAP_CHANNEL_SUSPENDED)) { - zap_clear_flag_all(span, ZAP_CHANNEL_SUSPENDED); + if (ftdm_test_flag(isdn_data->dchan, FTDM_CHANNEL_SUSPENDED)) { + ftdm_clear_flag_all(span, FTDM_CHANNEL_SUSPENDED); } len = sizeof(frame); - if (zap_channel_read(isdn_data->dchan, frame, &len) == ZAP_SUCCESS) { + if (ftdm_channel_read(isdn_data->dchan, frame, &len) == FTDM_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); + print_bits(frame, (int)len, bb, sizeof(bb), FTDM_ENDIAN_LITTLE, 0); + ftdm_log(FTDM_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"); + ftdm_log(FTDM_LOG_DEBUG, "No Read FLAG!\n"); } } break; @@ -1893,30 +1893,30 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) } done: - zap_channel_close(&isdn_data->dchans[0]); - zap_channel_close(&isdn_data->dchans[1]); - zap_clear_flag(isdn_data, ZAP_ISDN_RUNNING); + ftdm_channel_close(&isdn_data->dchans[0]); + ftdm_channel_close(&isdn_data->dchans[1]); + ftdm_clear_flag(isdn_data, FTDM_ISDN_RUNNING); #ifdef WIN32 timeEndPeriod(1); #endif - zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n"); + ftdm_log(FTDM_LOG_DEBUG, "ISDN thread ended.\n"); return NULL; } /** - * \brief Openzap ISDN signaling module initialisation + * \brief Openftdm ISDN signaling module initialisation * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(zap_isdn_init) +static ZIO_SIG_LOAD_FUNCTION(ftdm_isdn_init) { Q931Initialize(); - Q921SetGetTimeCB(zap_time_now); - Q931SetGetTimeCB(zap_time_now); + Q921SetGetTimeCB(ftdm_time_now); + Q931SetGetTimeCB(ftdm_time_now); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -1942,14 +1942,14 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I #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"); + ftdm_span_t *span = (ftdm_span_t *) pvt; + if(writeQ931PacketToPcap(msg + offset, mlen - offset, span->span_id, 0) != FTDM_SUCCESS){ + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb); break; default: @@ -1967,11 +1967,11 @@ static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR tei, L3UCHAR *msg, L3I * \param size Message string length * \return 0 */ -static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) +static int ftdm_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size) { - zap_span_t *span = (zap_span_t *) pvt; + ftdm_span_t *span = (ftdm_span_t *) pvt; - zap_log("Span", "Q.921", span->span_id, (int)level, "%s", msg); + ftdm_log("Span", "Q.921", span->span_id, (int)level, "%s", msg); return 0; } @@ -1983,122 +1983,122 @@ static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT s * \param size Message string length * \return 0 */ -static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size) +static L3INT ftdm_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size) { - zap_span_t *span = (zap_span_t *) pvt; + ftdm_span_t *span = (ftdm_span_t *) pvt; - zap_log("Span", "Q.931", span->span_id, (int)level, "%s", msg); + ftdm_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 = { +static ftdm_state_map_t isdn_state_map = { { { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_ANY_STATE}, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END} + {FTDM_ANY_STATE}, + {FTDM_CHANNEL_STATE_RESTART, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_DIALING, ZAP_END} + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_DIALING, FTDM_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} + {FTDM_CHANNEL_STATE_DIALING, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_UP, FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_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} + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_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} + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_UP, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END} + {FTDM_CHANNEL_STATE_UP, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END} }, /****************************************/ { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_ANY_STATE}, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END} + {FTDM_ANY_STATE}, + {FTDM_CHANNEL_STATE_RESTART, FTDM_END} }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_RING, ZAP_END} + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_DIALTONE, FTDM_CHANNEL_STATE_RING, FTDM_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} + {FTDM_CHANNEL_STATE_DIALTONE, FTDM_END}, + {FTDM_CHANNEL_STATE_RING, FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_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} + {FTDM_CHANNEL_STATE_RING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_UP, FTDM_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}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_DOWN, FTDM_END}, }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_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}, + {FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, + FTDM_CHANNEL_STATE_CANCEL, FTDM_CHANNEL_STATE_UP, FTDM_END}, }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_UP, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, + {FTDM_CHANNEL_STATE_UP, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, }, @@ -2112,25 +2112,25 @@ static zap_state_map_t isdn_state_map = { * * Sets a stop flag and waits for the threads to end */ -static zap_status_t zap_isdn_stop(zap_span_t *span) +static ftdm_status_t ftdm_isdn_stop(ftdm_span_t *span) { - zap_isdn_data_t *isdn_data = span->signal_data; + ftdm_isdn_data_t *isdn_data = span->signal_data; - if (!zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { - return ZAP_FAIL; + if (!ftdm_test_flag(isdn_data, FTDM_ISDN_RUNNING)) { + return FTDM_FAIL; } - zap_set_flag(isdn_data, ZAP_ISDN_STOP); + ftdm_set_flag(isdn_data, FTDM_ISDN_STOP); - while(zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { - zap_sleep(100); + while(ftdm_test_flag(isdn_data, FTDM_ISDN_RUNNING)) { + ftdm_sleep(100); } - while(zap_test_flag(isdn_data, ZAP_ISDN_TONES_RUNNING)) { - zap_sleep(100); + while(ftdm_test_flag(isdn_data, FTDM_ISDN_TONES_RUNNING)) { + ftdm_sleep(100); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } @@ -2141,24 +2141,24 @@ static zap_status_t zap_isdn_stop(zap_span_t *span) * * 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) +static ftdm_status_t ftdm_isdn_start(ftdm_span_t *span) { - zap_status_t ret; - zap_isdn_data_t *isdn_data = span->signal_data; + ftdm_status_t ret; + ftdm_isdn_data_t *isdn_data = span->signal_data; - if (zap_test_flag(isdn_data, ZAP_ISDN_RUNNING)) { - return ZAP_FAIL; + if (ftdm_test_flag(isdn_data, FTDM_ISDN_RUNNING)) { + return FTDM_FAIL; } - zap_clear_flag(isdn_data, ZAP_ISDN_STOP); - ret = zap_thread_create_detached(zap_isdn_run, span); + ftdm_clear_flag(isdn_data, FTDM_ISDN_STOP); + ret = ftdm_thread_create_detached(ftdm_isdn_run, span); - if (ret != ZAP_SUCCESS) { + if (ret != FTDM_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); + if (FTDM_SPAN_IS_NT(span) && !(isdn_data->opts & FTDM_ISDN_OPT_DISABLE_TONES)) { + ret = ftdm_thread_create_detached(ftdm_isdn_tones_run, span); } return ret; } @@ -2177,15 +2177,15 @@ static uint32_t parse_opts(const char *in) } if (strstr(in, "suggest_channel")) { - flags |= ZAP_ISDN_OPT_SUGGEST_CHANNEL; + flags |= FTDM_ISDN_OPT_SUGGEST_CHANNEL; } if (strstr(in, "omit_display")) { - flags |= ZAP_ISDN_OPT_OMIT_DISPLAY_IE; + flags |= FTDM_ISDN_OPT_OMIT_DISPLAY_IE; } if (strstr(in, "disable_tones")) { - flags |= ZAP_ISDN_OPT_DISABLE_TONES; + flags |= FTDM_ISDN_OPT_DISABLE_TONES; } return flags; @@ -2198,11 +2198,11 @@ static uint32_t parse_opts(const char *in) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) +static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_isdn_configure_span) { uint32_t i, x = 0; - zap_channel_t *dchans[2] = {0}; - zap_isdn_data_t *isdn_data; + ftdm_channel_t *dchans[2] = {0}; + ftdm_isdn_data_t *isdn_data; const char *tonemap = "us"; char *var, *val; Q931Dialect_t dialect = Q931_Dialect_National; @@ -2216,7 +2216,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) if (span->signal_type) { #ifdef HAVE_LIBPCAP - /*Q931ToPcap: Get the content of the q931topcap and pcapfilename args given by mod_openzap */ + /*Q931ToPcap: Get the content of the q931topcap and pcapfilename args given by mod_freetdm */ while((var = va_arg(ap, char *))) { if (!strcasecmp(var, "q931topcap")) { q931topcap = va_arg(ap, int); @@ -2225,9 +2225,9 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) openPcap=1; } else if (q931topcap==0) { /*PCAP off*/ - if (closePcapFile() != ZAP_SUCCESS) return ZAP_FAIL; + if (closePcapFile() != FTDM_SUCCESS) return FTDM_FAIL; do_q931ToPcap=0; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } } if (!strcasecmp(var, "pcapfilename")) { @@ -2237,30 +2237,30 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } /*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; + if(openPcapFile() != FTDM_SUCCESS) return FTDM_FAIL; do_q931ToPcap=1; - return ZAP_SUCCESS; + return FTDM_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; + return FTDM_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; + if (span->trunk_type >= FTDM_TRUNK_NONE) { + ftdm_log(FTDM_LOG_WARNING, "Invalid trunk type '%s' defaulting to T1.\n", ftdm_trunk_type2str(span->trunk_type)); + span->trunk_type = FTDM_TRUNK_T1; } for(i = 1; i <= span->chan_count; i++) { - if (span->channels[i]->type == ZAP_CHAN_TYPE_DQ921) { + if (span->channels[i]->type == FTDM_CHAN_TYPE_DQ921) { if (x > 1) { snprintf(span->last_error, sizeof(span->last_error), "Span has more than 2 D-Channels!"); - return ZAP_FAIL; + return FTDM_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; + if (ftdm_channel_open(span->span_id, i, &dchans[x]) == FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, dchans[x]->span_id, dchans[x]->chan_id); + dchans[x]->state = FTDM_CHANNEL_STATE_UP; x++; } } @@ -2269,10 +2269,10 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) if (!x) { snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!"); - return ZAP_FAIL; + return FTDM_FAIL; } - isdn_data = zap_malloc(sizeof(*isdn_data)); + isdn_data = ftdm_malloc(sizeof(*isdn_data)); assert(isdn_data != NULL); memset(isdn_data, 0, sizeof(*isdn_data)); @@ -2291,7 +2291,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } dialect = q931_str2Q931Dialect_type(val); if (dialect == Q931_Dialect_Count) { - return ZAP_FAIL; + return FTDM_FAIL; } } else if (!strcasecmp(var, "opts")) { if (!(val = va_arg(ap, char *))) { @@ -2325,7 +2325,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) } } else { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); - return ZAP_FAIL; + return FTDM_FAIL; } } @@ -2334,29 +2334,29 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) 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); + ftdm_log(FTDM_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; + ftdm_isdn_bchan_data_t *data; - data = zap_malloc((span->chan_count - 1) * sizeof(zap_isdn_bchan_data_t)); + data = ftdm_malloc((span->chan_count - 1) * sizeof(ftdm_isdn_bchan_data_t)); if (!data) { - return ZAP_FAIL; + return FTDM_FAIL; } for (i = 1; i <= span->chan_count; i++, data++) { - if (span->channels[i]->type == ZAP_CHAN_TYPE_B) { + if (span->channels[i]->type == FTDM_CHAN_TYPE_B) { span->channels[i]->mod_data = data; - memset(data, 0, sizeof(zap_isdn_bchan_data_t)); + memset(data, 0, sizeof(ftdm_isdn_bchan_data_t)); } } } - span->start = zap_isdn_start; - span->stop = zap_isdn_stop; + span->start = ftdm_isdn_start; + span->stop = ftdm_isdn_stop; isdn_data->sig_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; @@ -2367,56 +2367,56 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) 0, 0, isdn_data->mode, - span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP, + span->trunk_type == FTDM_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP, 0, - zap_isdn_921_21, - (Q921Tx23CB_t)zap_isdn_921_23, + ftdm_isdn_921_21, + (Q921Tx23CB_t)ftdm_isdn_921_23, span, &isdn_data->q931); - Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data); + Q921SetLogCB(&isdn_data->q921, &ftdm_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, + ftdm_isdn_931_34, (Q931Tx32CB_t)q931_rx_32, - zap_isdn_931_err, + ftdm_isdn_931_err, &isdn_data->q921, span); - Q931SetLogCB(&isdn_data->q931, &zap_isdn_q931_log, isdn_data); + Q931SetLogCB(&isdn_data->q931, &ftdm_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->signal_type = FTDM_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - if ((isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL)) { + if ((isdn_data->opts & FTDM_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); + ftdm_span_load_tones(span, tonemap); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Openzap ISDN signaling module definition + * \brief Openftdm ISDN signaling module definition */ -EX_DECLARE_DATA zap_module_t zap_module = { +EX_DECLARE_DATA ftdm_module_t ftdm_module = { "isdn", NULL, close_pcap, - zap_isdn_init, - zap_isdn_configure_span, + ftdm_isdn_init, + ftdm_isdn_configure_span, NULL }; diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2005.vcproj rename to libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2008.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2008.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c similarity index 51% rename from libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c rename to libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index af34e000f7..9f6769aca0 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -31,28 +31,28 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openzap.h" -#include "ozmod_libpri.h" +#include "freetdm.h" +#include "ftmod_libpri.h" /** * \brief Unloads libpri IO module * \return Success */ -static ZIO_IO_UNLOAD_FUNCTION(zap_libpri_unload) +static ZIO_IO_UNLOAD_FUNCTION(ftdm_libpri_unload) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Starts a libpri channel (outgoing call) - * \param zchan Channel to initiate call on + * \param ftdmchan 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); + ftdm_status_t status = FTDM_SUCCESS; + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING); return status; } @@ -62,12 +62,12 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) * \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) + * \param ftdmchan Channel to initialise (unused) * \return Failure */ static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) { - return ZAP_FAIL; + return FTDM_FAIL; } #ifdef WIN32 @@ -85,7 +85,7 @@ static void s_pri_error(char *s) static void s_pri_error(struct pri *pri, char *s) #endif { - zap_log(ZAP_LOG_ERROR, "%s", s); + ftdm_log(FTDM_LOG_ERROR, "%s", s); } #ifdef WIN32 @@ -103,7 +103,7 @@ static void s_pri_message(char *s) static void s_pri_message(struct pri *pri, char *s) #endif { - zap_log(ZAP_LOG_DEBUG, "%s", s); + ftdm_log(FTDM_LOG_DEBUG, "%s", s); } /** @@ -120,15 +120,15 @@ static uint32_t parse_opts(const char *in) } if (strstr(in, "suggest_channel")) { - flags |= OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL; + flags |= FTMOD_LIBPRI_OPT_SUGGEST_CHANNEL; } if (strstr(in, "omit_display")) { - flags |= OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE; + flags |= FTMOD_LIBPRI_OPT_OMIT_DISPLAY_IE; } if (strstr(in, "omit_redirecting_number")) { - flags |= OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE; + flags |= FTMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE; } return flags; @@ -194,9 +194,9 @@ static int parse_debug(const char *in) return flags; } -static zap_io_interface_t zap_libpri_interface; +static ftdm_io_interface_t ftdm_libpri_interface; -static zap_status_t zap_libpri_start(zap_span_t *span); +static ftdm_status_t ftdm_libpri_start(ftdm_span_t *span); /** * \brief API function to kill or debug a libpri span @@ -204,30 +204,30 @@ static zap_status_t zap_libpri_start(zap_span_t *span); * \param data String containing argurments * \return Flags */ -static ZIO_API_FUNCTION(zap_libpri_api) +static ZIO_API_FUNCTION(ftdm_libpri_api) { char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; if (data) { - mycmd = zap_strdup(data); - argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + mycmd = ftdm_strdup(data); + argc = ftdm_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; + ftdm_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 (ftdm_span_find_by_name(argv[1], &span) == FTDM_SUCCESS || ftdm_span_find(span_id, &span) == FTDM_SUCCESS) { + ftdm_libpri_data_t *isdn_data = span->signal_data; - if (span->start != zap_libpri_start) { + if (span->start != ftdm_libpri_start) { stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__); goto done; } - zap_clear_flag((&isdn_data->spri), LPWRAP_PRI_READY); + ftdm_clear_flag((&isdn_data->spri), LPWRAP_PRI_READY); stream->write_function(stream, "%s: +OK killed.\n", __FILE__); goto done; } else { @@ -239,11 +239,11 @@ static ZIO_API_FUNCTION(zap_libpri_api) if (argc > 2) { if (!strcasecmp(argv[0], "debug")) { - zap_span_t *span = NULL; + ftdm_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) { + if (ftdm_span_find_by_name(argv[1], &span) == FTDM_SUCCESS) { + ftdm_libpri_data_t *isdn_data = span->signal_data; + if (span->start != ftdm_libpri_start) { stream->write_function(stream, "%s: -ERR invalid span.\n", __FILE__); goto done; } @@ -263,150 +263,150 @@ static ZIO_API_FUNCTION(zap_libpri_api) done: - zap_safe_free(mycmd); + ftdm_safe_free(mycmd); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Loads libpri IO module - * \param zio Openzap IO interface + * \param zio Openftdm IO interface * \return Success */ -static ZIO_IO_LOAD_FUNCTION(zap_libpri_io_init) +static ZIO_IO_LOAD_FUNCTION(ftdm_libpri_io_init) { assert(zio != NULL); - memset(&zap_libpri_interface, 0, sizeof(zap_libpri_interface)); + memset(&ftdm_libpri_interface, 0, sizeof(ftdm_libpri_interface)); - zap_libpri_interface.name = "libpri"; - zap_libpri_interface.api = zap_libpri_api; + ftdm_libpri_interface.name = "libpri"; + ftdm_libpri_interface.api = ftdm_libpri_api; - *zio = &zap_libpri_interface; + *zio = &ftdm_libpri_interface; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Loads libpri signaling module - * \param zio Openzap IO interface + * \param zio Openftdm IO interface * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(zap_libpri_init) +static ZIO_SIG_LOAD_FUNCTION(ftdm_libpri_init) { pri_set_error(s_pri_error); pri_set_message(s_pri_message); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief libpri state map */ -static zap_state_map_t isdn_state_map = { +static ftdm_state_map_t isdn_state_map = { { { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_ANY_STATE}, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END} + {FTDM_ANY_STATE}, + {FTDM_CHANNEL_STATE_RESTART, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_DIALING, ZAP_END} + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_DIALING, FTDM_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} + {FTDM_CHANNEL_STATE_DIALING, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_UP, FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_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} + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_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} + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_UP, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END} + {FTDM_CHANNEL_STATE_UP, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END} }, /****************************************/ { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_ANY_STATE}, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END} + {FTDM_ANY_STATE}, + {FTDM_CHANNEL_STATE_RESTART, FTDM_END} }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_DIALTONE, ZAP_CHANNEL_STATE_RING, ZAP_END} + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_DIALTONE, FTDM_CHANNEL_STATE_RING, FTDM_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} + {FTDM_CHANNEL_STATE_DIALTONE, FTDM_END}, + {FTDM_CHANNEL_STATE_RING, FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_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} + {FTDM_CHANNEL_STATE_RING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_UP, FTDM_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}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_DOWN, FTDM_END}, }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_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}, + {FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, + FTDM_CHANNEL_STATE_CANCEL, FTDM_CHANNEL_STATE_UP, FTDM_END}, }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_UP, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, + {FTDM_CHANNEL_STATE_UP, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, }, @@ -415,172 +415,172 @@ static zap_state_map_t isdn_state_map = { /** * \brief Handler for channel state change - * \param zchan Channel to handle + * \param ftdmchan Channel to handle */ -static __inline__ void state_advance(zap_channel_t *zchan) +static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { - //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; + //Q931mes_Generic *gen = (Q931mes_Generic *) ftdmchan->caller_data.raw_data; + ftdm_libpri_data_t *isdn_data = ftdmchan->span->signal_data; + ftdm_status_t status; + ftdm_sigmsg_t sig; + q931_call *call = (q931_call *) ftdmchan->call_data; - zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n", - zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); + ftdm_log(FTDM_LOG_DEBUG, "%d:%d STATE [%s]\n", + ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); #if 0 - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) && !call) { - zap_log(ZAP_LOG_WARNING, "NO CALL!!!!\n"); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) && !call) { + ftdm_log(FTDM_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; + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; - switch (zchan->state) { - case ZAP_CHANNEL_STATE_DOWN: + switch (ftdmchan->state) { + case FTDM_CHANNEL_STATE_DOWN: { - zchan->call_data = NULL; - zap_channel_done(zchan); + ftdmchan->call_data = NULL; + ftdm_channel_done(ftdmchan); } break; - case ZAP_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_PROGRESS: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else if (call) { - pri_progress(isdn_data->spri.pri, call, zchan->chan_id, 1); + pri_progress(isdn_data->spri.pri, call, ftdmchan->chan_id, 1); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); } } break; - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else if (call) { - pri_proceeding(isdn_data->spri.pri, call, zchan->chan_id, 1); + pri_proceeding(isdn_data->spri.pri, call, ftdmchan->chan_id, 1); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); } } break; - case ZAP_CHANNEL_STATE_RING: + case FTDM_CHANNEL_STATE_RING: { - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { if (call) { - pri_acknowledge(isdn_data->spri.pri, call, zchan->chan_id, 0); - sig.event_id = ZAP_SIGEVENT_START; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + pri_acknowledge(isdn_data->spri.pri, call, ftdmchan->chan_id, 0); + sig.event_id = FTDM_SIGEVENT_START; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); } } } break; - case ZAP_CHANNEL_STATE_RESTART: + case FTDM_CHANNEL_STATE_RESTART: { - zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED; - sig.event_id = ZAP_SIGEVENT_RESTART; + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_UNSPECIFIED; + sig.event_id = FTDM_SIGEVENT_RESTART; status = isdn_data->sig_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; - case ZAP_CHANNEL_STATE_UP: + case FTDM_CHANNEL_STATE_UP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_UP; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_UP; + if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); } } break; - case ZAP_CHANNEL_STATE_DIALING: + case FTDM_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); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); return; } - dp = zchan->caller_data.ani.type; + dp = ftdmchan->caller_data.ani.type; switch(dp) { - case ZAP_TON_NATIONAL: + case FTDM_TON_NATIONAL: dp = PRI_NATIONAL_ISDN; break; - case ZAP_TON_INTERNATIONAL: + case FTDM_TON_INTERNATIONAL: dp = PRI_INTERNATIONAL_ISDN; break; - case ZAP_TON_SUBSCRIBER_NUMBER: + case FTDM_TON_SUBSCRIBER_NUMBER: dp = PRI_LOCAL_ISDN; break; default: dp = isdn_data->dp; } - zchan->call_data = call; + ftdmchan->call_data = call; sr = pri_sr_new(); assert(sr); - pri_sr_set_channel(sr, zchan->chan_id, 0, 0); + pri_sr_set_channel(sr, ftdmchan->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)); + pri_sr_set_called(sr, ftdmchan->caller_data.ani.digits, dp, 1); + pri_sr_set_caller(sr, ftdmchan->caller_data.cid_num.digits, (isdn_data->opts & FTMOD_LIBPRI_OPT_OMIT_DISPLAY_IE ? NULL : ftdmchan->caller_data.cid_name), + dp, (ftdmchan->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 (!(isdn_data->opts & FTMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE)) { + pri_sr_set_redirecting(sr, ftdmchan->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); + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_DESTINATION_OUT_OF_ORDER; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } pri_sr_free(sr); } break; - case ZAP_CHANNEL_STATE_HANGUP: + case FTDM_CHANNEL_STATE_HANGUP: { if (call) { - pri_hangup(isdn_data->spri.pri, call, zchan->caller_data.hangup_cause); + pri_hangup(isdn_data->spri.pri, call, ftdmchan->caller_data.hangup_cause); pri_destroycall(isdn_data->spri.pri, call); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); } } break; - case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + case FTDM_CHANNEL_STATE_HANGUP_COMPLETE: break; - case ZAP_CHANNEL_STATE_TERMINATING: + case FTDM_CHANNEL_STATE_TERMINATING: { - sig.event_id = ZAP_SIGEVENT_STOP; + sig.event_id = FTDM_SIGEVENT_STOP; status = isdn_data->sig_cb(&sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } default: @@ -596,18 +596,18 @@ static __inline__ void state_advance(zap_channel_t *zchan) * \brief Checks current state on a span * \param span Span to check status on */ -static __inline__ void check_state(zap_span_t *span) +static __inline__ void check_state(ftdm_span_t *span) { - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE)) { + if (ftdm_test_flag(span, FTDM_SPAN_STATE_CHANGE)) { uint32_t j; - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); + ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE); for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE)) { - zap_mutex_lock(span->channels[j]->mutex); - zap_clear_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE); + if (ftdm_test_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_mutex_lock(span->channels[j]->mutex); + ftdm_clear_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE); state_advance(span->channels[j]); - zap_channel_complete_state(span->channels[j]); - zap_mutex_unlock(span->channels[j]->mutex); + ftdm_channel_complete_state(span->channels[j]); + ftdm_mutex_unlock(span->channels[j]->mutex); } } } @@ -623,9 +623,9 @@ static __inline__ void check_state(zap_span_t *span) 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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "final number is: %s\n", pevent->ring.callednum); pri_answer(spri->pri, pevent->ring.call, 0, 1); } return 0; @@ -640,21 +640,21 @@ static int on_info(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event */ 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; + ftdm_span_t *span = spri->private_info; + ftdm_channel_t *ftdmchan = NULL; q931_call *call = NULL; - zchan = span->channels[pevent->hangup.channel]; + ftdmchan = 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; + if (ftdmchan) { + call = (q931_call *) ftdmchan->call_data; + ftdm_log(FTDM_LOG_DEBUG, "-- Hangup on channel %d:%d\n", spri->span->span_id, pevent->hangup.channel); + ftdmchan->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); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "-- Hangup on channel %d:%d %s but it's not in use?\n", spri->span->span_id, + pevent->hangup.channel, ftdmchan->chan_id); } return 0; @@ -669,16 +669,16 @@ static int on_hangup(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even */ 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; + ftdm_span_t *span = spri->private_info; + ftdm_channel_t *ftdmchan = NULL; - zchan = span->channels[pevent->answer.channel]; + ftdmchan = 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); + if (ftdmchan) { + ftdm_log(FTDM_LOG_DEBUG, "-- Answer on channel %d:%d\n", spri->span->span_id, pevent->answer.channel); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "-- Answer on channel %d:%d %s but it's not in use?\n", spri->span->span_id, pevent->answer.channel, ftdmchan->chan_id); } @@ -694,17 +694,17 @@ static int on_answer(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_even */ 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; + ftdm_span_t *span = spri->private_info; + ftdm_channel_t *ftdmchan = NULL; - zchan = span->channels[pevent->proceeding.channel]; + ftdmchan = 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); + if (ftdmchan) { + ftdm_log(FTDM_LOG_DEBUG, "-- Proceeding on channel %d:%d\n", spri->span->span_id, pevent->proceeding.channel); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "-- Proceeding on channel %d:%d %s but it's not in use?\n", spri->span->span_id, + pevent->proceeding.channel, ftdmchan->chan_id); } return 0; @@ -719,22 +719,22 @@ static int on_proceed(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve */ 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; + ftdm_span_t *span = spri->private_info; + ftdm_channel_t *ftdmchan = NULL; - zchan = span->channels[pevent->ringing.channel]; + ftdmchan = 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) { + if (ftdmchan) { + ftdm_log(FTDM_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 FTDM_CHANNEL_STATE_PROGRESS_MEDIA */ + if (ftdmchan->state == FTDM_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); + ftdm_set_state_locked(ftdmchan, FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "-- Ringing on channel %d:%d %s but it's not in use?\n", spri->span->span_id, + pevent->ringing.channel, ftdmchan->chan_id); } return 0; @@ -749,48 +749,48 @@ static int on_ringing(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve */ 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; + ftdm_span_t *span = spri->private_info; + ftdm_channel_t *ftdmchan = 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); + ftdmchan = span->channels[pevent->ring.channel]; + if (!ftdmchan || ftdmchan->state != FTDM_CHANNEL_STATE_DOWN || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) { + ftdm_log(FTDM_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); + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_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, + ftdm_log(FTDM_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)); + memset(&ftdmchan->caller_data, 0, sizeof(ftdmchan->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); + ftdm_set_string(ftdmchan->caller_data.cid_num.digits, (char *)pevent->ring.callingnum); + if (!ftdm_strlen_zero((char *)pevent->ring.callingname)) { + ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)pevent->ring.callingname); } else { - zap_set_string(zchan->caller_data.cid_name, (char *)pevent->ring.callingnum); + ftdm_set_string(ftdmchan->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); + ftdm_set_string(ftdmchan->caller_data.ani.digits, (char *)pevent->ring.callingani); + ftdm_set_string(ftdmchan->caller_data.dnis.digits, (char *)pevent->ring.callednum); if (pevent->ring.ani2 >= 0) { - snprintf(zchan->caller_data.aniII, 5, "%.2d", pevent->ring.ani2); + snprintf(ftdmchan->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; + ftdmchan->call_data = pevent->ring.call; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RING); done: //switch_mutex_unlock(globals.channel_mutex); @@ -799,93 +799,93 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event } /** - * \brief Processes openzap event + * \brief Processes freetdm event * \param span Span on which the event was fired * \param event Event to be treated * \return Success or failure */ -static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) +static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) { - zap_sigmsg_t sig; - zap_libpri_data_t *isdn_data = span->signal_data; + ftdm_sigmsg_t sig; + ftdm_libpri_data_t *isdn_data = span->signal_data; 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:%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)); + ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d][%d:%d] STATE [%s]\n", + ftdm_oob_event2str(event->enum_id), event->enum_id, event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state)); switch(event->enum_id) { - case ZAP_OOB_ALARM_TRAP: + case FTDM_OOB_ALARM_TRAP: { - sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)ZAP_HW_LINK_CONNECTED; - 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); + sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; + if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) { + if (event->channel->type == FTDM_CHAN_TYPE_B) { + ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_RESTART); } } - zap_set_flag(event->channel, ZAP_CHANNEL_SUSPENDED); + ftdm_set_flag(event->channel, FTDM_CHANNEL_SUSPENDED); - zap_channel_get_alarms(event->channel); + ftdm_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); - zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) has alarms! [%s]\n", + ftdm_log(FTDM_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: + case FTDM_OOB_ALARM_CLEAR: { - zap_log(ZAP_LOG_WARNING, "channel %d:%d (%d:%d) alarms Cleared!\n", event->channel->span_id, event->channel->chan_id, + ftdm_log(FTDM_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); - sig.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)ZAP_HW_LINK_CONNECTED; - zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); - zap_channel_get_alarms(event->channel); + sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; + sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; + ftdm_clear_flag(event->channel, FTDM_CHANNEL_SUSPENDED); + ftdm_channel_get_alarms(event->channel); isdn_data->sig_cb(&sig); } break; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Checks for events on a span * \param span Span to check for events */ -static __inline__ void check_events(zap_span_t *span) +static __inline__ void check_events(ftdm_span_t *span) { - zap_status_t status; + ftdm_status_t status; - status = zap_span_poll_event(span, 5); + status = ftdm_span_poll_event(span, 5); switch(status) { - case ZAP_SUCCESS: + case FTDM_SUCCESS: { - zap_event_t *event; - while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { - if (event->enum_id == ZAP_OOB_NOOP) { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { + if (event->enum_id == FTDM_OOB_NOOP) { continue; } - if (process_event(span, event) != ZAP_SUCCESS) { + if (process_event(span, event) != FTDM_SUCCESS) { break; } } } break; - case ZAP_FAIL: + case FTDM_FAIL: { - zap_log(ZAP_LOG_DEBUG, "Event Failure! %d\n", zap_running()); - zap_sleep(2000); + ftdm_log(FTDM_LOG_DEBUG, "Event Failure! %d\n", ftdm_running()); + ftdm_sleep(2000); } break; default: @@ -900,9 +900,9 @@ static __inline__ void check_events(zap_span_t *span) */ static int check_flags(lpwrap_pri_t *spri) { - zap_span_t *span = spri->private_info; + ftdm_span_t *span = spri->private_info; - if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { + if (!ftdm_running() || ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD)) { return -1; } @@ -922,21 +922,21 @@ static int check_flags(lpwrap_pri_t *spri) */ 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; + ftdm_span_t *span = spri->private_info; + ftdm_channel_t *ftdmchan; - zap_log(ZAP_LOG_NOTICE, "-- Restarting %d:%d\n", spri->span->span_id, pevent->restart.channel); + ftdm_log(FTDM_LOG_NOTICE, "-- Restarting %d:%d\n", spri->span->span_id, pevent->restart.channel); - zchan = span->channels[pevent->restart.channel]; + ftdmchan = span->channels[pevent->restart.channel]; - if (!zchan) { + if (!ftdmchan) { return 0; } if (pevent->restart.channel < 1) { - zap_set_state_all(zchan->span, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_all(ftdmchan->span, FTDM_CHANNEL_STATE_RESTART); } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); } return 0; @@ -952,10 +952,10 @@ static int on_restart(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve 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); + if (!ftdm_test_flag(spri, LPWRAP_PRI_READY)) { + ftdm_log(FTDM_LOG_INFO, "Span %d D-Chan UP!\n", spri->span->span_id); + ftdm_set_flag(spri, LPWRAP_PRI_READY); + ftdm_set_state_all(spri->span, FTDM_CHANNEL_STATE_RESTART); } return 0; @@ -971,10 +971,10 @@ static int on_dchan_up(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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); + if (ftdm_test_flag(spri, LPWRAP_PRI_READY)) { + ftdm_log(FTDM_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span->span_id); + ftdm_clear_flag(spri, LPWRAP_PRI_READY); + ftdm_set_state_all(spri->span, FTDM_CHANNEL_STATE_RESTART); } @@ -991,7 +991,7 @@ static int on_dchan_down(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ 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)); + ftdm_log(FTDM_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span->span_id, event_type, lpwrap_pri_event_str(event_type)); return 0; } @@ -1005,7 +1005,7 @@ static int on_anything(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_ev 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)); + ftdm_log(FTDM_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span->span_id, event_type, lpwrap_pri_event_str(event_type)); return 0; } @@ -1014,23 +1014,23 @@ static int on_io_fail(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_eve * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_libpri_run(zap_thread_t *me, void *obj) +static void *ftdm_libpri_run(ftdm_thread_t *me, void *obj) { - zap_span_t *span = (zap_span_t *) obj; - zap_libpri_data_t *isdn_data = span->signal_data; + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_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); + ftdm_set_flag(span, FTDM_SPAN_IN_THREAD); - while(zap_running() && !zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { + while(ftdm_running() && !ftdm_test_flag(span, FTDM_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; + if (span->channels[i]->type == FTDM_CHAN_TYPE_DQ921) { + if (ftdm_channel_open(span->span_id, i, &isdn_data->dchan) == FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, isdn_data->dchan->span_id, isdn_data->dchan->chan_id); + isdn_data->dchan->state = FTDM_CHANNEL_STATE_UP; got_d = 1; x++; break; @@ -1064,8 +1064,8 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) 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); + ftdm_log(FTDM_LOG_INFO, "PRI back up on span %d\n", isdn_data->spri.span->span_id); + ftdm_set_state_all(span, FTDM_CHANNEL_STATE_RESTART); down = 0; } @@ -1075,14 +1075,14 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) } - if (!zap_running() || zap_test_flag(span, ZAP_SPAN_STOP_THREAD)) { + if (!ftdm_running() || ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD)) { break; } - zap_log(ZAP_LOG_CRIT, "PRI down on span %d\n", isdn_data->spri.span->span_id); + ftdm_log(FTDM_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); + ftdm_set_state_all(span, FTDM_CHANNEL_STATE_RESTART); check_state(span); } @@ -1090,13 +1090,13 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) check_events(span); down++; - zap_sleep(5000); + ftdm_sleep(5000); } - zap_log(ZAP_LOG_DEBUG, "PRI thread ended on span %d\n", isdn_data->spri.span->span_id); + ftdm_log(FTDM_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); + ftdm_clear_flag(span, FTDM_SPAN_IN_THREAD); + ftdm_clear_flag(isdn_data, FTMOD_LIBPRI_RUNNING); return NULL; } @@ -1108,23 +1108,23 @@ static void *zap_libpri_run(zap_thread_t *me, void *obj) * * Sets a stop flag and waits for the thread to end */ -static zap_status_t zap_libpri_stop(zap_span_t *span) +static ftdm_status_t ftdm_libpri_stop(ftdm_span_t *span) { - zap_libpri_data_t *isdn_data = span->signal_data; + ftdm_libpri_data_t *isdn_data = span->signal_data; - if (!zap_test_flag(isdn_data, OZMOD_LIBPRI_RUNNING)) { - return ZAP_FAIL; + if (!ftdm_test_flag(isdn_data, FTMOD_LIBPRI_RUNNING)) { + return FTDM_FAIL; } - zap_set_state_all(span, ZAP_CHANNEL_STATE_RESTART); + ftdm_set_state_all(span, FTDM_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); + ftdm_set_flag(span, FTDM_SPAN_STOP_THREAD); + while(ftdm_test_flag(span, FTDM_SPAN_IN_THREAD)) { + ftdm_sleep(100); } check_state(span); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -1134,22 +1134,22 @@ static zap_status_t zap_libpri_stop(zap_span_t *span) * * Launches a thread to monitor the span */ -static zap_status_t zap_libpri_start(zap_span_t *span) +static ftdm_status_t ftdm_libpri_start(ftdm_span_t *span) { - zap_status_t ret; - zap_libpri_data_t *isdn_data = span->signal_data; + ftdm_status_t ret; + ftdm_libpri_data_t *isdn_data = span->signal_data; - if (zap_test_flag(isdn_data, OZMOD_LIBPRI_RUNNING)) { - return ZAP_FAIL; + if (ftdm_test_flag(isdn_data, FTMOD_LIBPRI_RUNNING)) { + return FTDM_FAIL; } - zap_clear_flag(span, ZAP_SPAN_STOP_THREAD); - zap_clear_flag(span, ZAP_SPAN_IN_THREAD); + ftdm_clear_flag(span, FTDM_SPAN_STOP_THREAD); + ftdm_clear_flag(span, FTDM_SPAN_IN_THREAD); - zap_set_flag(isdn_data, OZMOD_LIBPRI_RUNNING); - ret = zap_thread_create_detached(zap_libpri_run, span); + ftdm_set_flag(isdn_data, FTMOD_LIBPRI_RUNNING); + ret = ftdm_thread_create_detached(ftdm_libpri_run, span); - if (ret != ZAP_SUCCESS) { + if (ret != FTDM_SUCCESS) { return ret; } @@ -1237,29 +1237,29 @@ static int str2dp(char *dp) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) +static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_libpri_configure_span) { uint32_t i, x = 0; - //zap_channel_t *dchans[2] = {0}; - zap_libpri_data_t *isdn_data; + //ftdm_channel_t *dchans[2] = {0}; + ftdm_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; + if (span->trunk_type >= FTDM_TRUNK_NONE) { + ftdm_log(FTDM_LOG_WARNING, "Invalid trunk type '%s' defaulting to T1.\n", ftdm_trunk_type2str(span->trunk_type)); + span->trunk_type = FTDM_TRUNK_T1; } for(i = 1; i <= span->chan_count; i++) { - if (span->channels[i]->type == ZAP_CHAN_TYPE_DQ921) { + if (span->channels[i]->type == FTDM_CHAN_TYPE_DQ921) { if (x > 1) { snprintf(span->last_error, sizeof(span->last_error), "Span has more than 2 D-Channels!"); - return ZAP_FAIL; + return FTDM_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; + if (ftdm_channel_open(span->span_id, i, &dchans[x]) == FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_DEBUG, "opening d-channel #%d %d:%d\n", x, dchans[x]->span_id, dchans[x]->chan_id); + dchans[x]->state = FTDM_CHANNEL_STATE_UP; x++; } #endif @@ -1270,19 +1270,19 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) #if 0 if (!x) { snprintf(span->last_error, sizeof(span->last_error), "Span has no D-Channels!"); - return ZAP_FAIL; + return FTDM_FAIL; } #endif - isdn_data = zap_malloc(sizeof(*isdn_data)); + isdn_data = ftdm_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"); + if (span->trunk_type == FTDM_TRUNK_E1) { + ftdm_log(FTDM_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"); + } else if (span->trunk_type == FTDM_TRUNK_T1) { + ftdm_log(FTDM_LOG_NOTICE, "Setting default Layer 1 to ULAW since this is a T1 trunk\n"); isdn_data->l1 = PRI_LAYER_1_ULAW; } @@ -1294,7 +1294,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } node = str2node(val); if (-1 == node) { - zap_log(ZAP_LOG_ERROR, "Unknown node type %s, defaulting to CPE mode\n", val); + ftdm_log(FTDM_LOG_ERROR, "Unknown node type %s, defaulting to CPE mode\n", val); node = PRI_CPE; } isdn_data->node = node; @@ -1325,12 +1325,12 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) debug = val; } else { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); - return ZAP_FAIL; + return FTDM_FAIL; } } - span->start = zap_libpri_start; - span->stop = zap_libpri_stop; + span->start = ftdm_libpri_start; + span->stop = ftdm_libpri_stop; isdn_data->sig_cb = sig_cb; //isdn_data->dchans[0] = dchans[0]; //isdn_data->dchans[1] = dchans[1]; @@ -1340,28 +1340,28 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->signal_data = isdn_data; - span->signal_type = ZAP_SIGTYPE_ISDN; + span->signal_type = FTDM_SIGTYPE_ISDN; span->outgoing_call = isdn_outgoing_call; - if ((isdn_data->opts & OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { + if ((isdn_data->opts & FTMOD_LIBPRI_OPT_SUGGEST_CHANNEL)) { span->channel_request = isdn_channel_request; span->suggest_chan_id = 1; } span->state_map = &isdn_state_map; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Openzap libpri signaling and IO module definition + * \brief Openftdm libpri signaling and IO module definition */ -zap_module_t zap_module = { +ftdm_module_t ftdm_module = { "libpri", - zap_libpri_io_init, - zap_libpri_unload, - zap_libpri_init, - zap_libpri_configure_span, + ftdm_libpri_io_init, + ftdm_libpri_unload, + ftdm_libpri_init, + ftdm_libpri_configure_span, NULL }; diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h similarity index 76% rename from libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h rename to libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h index 4e33aba17d..3038624481 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h @@ -32,33 +32,33 @@ */ -#ifndef OZMOD_LIBPRI_H -#define OZMOD_LIBPRI_H -#include "openzap.h" +#ifndef FTMOD_LIBPRI_H +#define FTMOD_LIBPRI_H +#include "freetdm.h" #include "lpwrap_pri.h" typedef enum { - OZMOD_LIBPRI_OPT_NONE = 0, - OZMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), - OZMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1), - OZMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2), + FTMOD_LIBPRI_OPT_NONE = 0, + FTMOD_LIBPRI_OPT_SUGGEST_CHANNEL = (1 << 0), + FTMOD_LIBPRI_OPT_OMIT_DISPLAY_IE = (1 << 1), + FTMOD_LIBPRI_OPT_OMIT_REDIRECTING_NUMBER_IE = (1 << 2), - OZMOD_LIBPRI_OPT_MAX = (1 << 3) -} zap_isdn_opts_t; + FTMOD_LIBPRI_OPT_MAX = (1 << 3) +} ftdm_isdn_opts_t; typedef enum { - OZMOD_LIBPRI_RUNNING = (1 << 0) -} zap_isdn_flag_t; + FTMOD_LIBPRI_RUNNING = (1 << 0) +} ftdm_isdn_flag_t; -struct zap_libpri_data { - zap_channel_t *dchan; - zap_channel_t *dchans[2]; - struct zap_sigmsg sigmsg; +struct ftdm_libpri_data { + ftdm_channel_t *dchan; + ftdm_channel_t *dchans[2]; + struct ftdm_sigmsg sigmsg; zio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; - zap_isdn_opts_t opts; + ftdm_isdn_opts_t opts; int node; int pswitch; @@ -71,16 +71,16 @@ struct zap_libpri_data { lpwrap_pri_t spri; }; -typedef struct zap_libpri_data zap_libpri_data_t; +typedef struct ftdm_libpri_data ftdm_libpri_data_t; /* b-channel private data */ -struct zap_isdn_bchan_data +struct ftdm_isdn_bchan_data { int32_t digit_timeout; }; -typedef struct zap_isdn_bchan_data zap_isdn_bchan_data_t; +typedef struct ftdm_isdn_bchan_data ftdm_isdn_bchan_data_t; #endif diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c b/libs/freetdm/src/ftmod/ftmod_libpri/lpwrap_pri.c similarity index 85% rename from libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c rename to libs/freetdm/src/ftmod/ftmod_libpri/lpwrap_pri.c index 3df1d54d89..de6a311ef9 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/lpwrap_pri.c @@ -33,7 +33,7 @@ //#define IODEBUG -#include "openzap.h" +#include "freetdm.h" #include "lpwrap_pri.h" #ifndef HAVE_GETTIMEOFDAY @@ -113,19 +113,19 @@ const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id) static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) { struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri); - zap_size_t len = buflen; + ftdm_size_t len = buflen; int res; - zap_status_t zst; + ftdm_status_t zst; - if ((zst = zap_channel_read(spri->dchan, buf, &len)) != ZAP_SUCCESS) { - if (zst == ZAP_FAIL) { - zap_log(ZAP_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); + if ((zst = ftdm_channel_read(spri->dchan, buf, &len)) != FTDM_SUCCESS) { + if (zst == FTDM_FAIL) { + ftdm_log(FTDM_LOG_CRIT, "span %d D-READ FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); spri->errs++; } else { - zap_log(ZAP_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id); + ftdm_log(FTDM_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id); } - zap_clear_flag(spri, LPWRAP_PRI_READY); + ftdm_clear_flag(spri, LPWRAP_PRI_READY); return -1; } spri->errs = 0; @@ -138,7 +138,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) char bb[2048] = { 0 }; print_hex_bytes(buf, res - 2, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "READ %d\n", res-2); + ftdm_log(FTDM_LOG_DEBUG, "READ %d\n", res-2); } #endif @@ -148,11 +148,11 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen) static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) { struct lpwrap_pri *spri = (struct lpwrap_pri *) pri_get_userdata(pri); - zap_size_t len = buflen -2; + ftdm_size_t len = buflen -2; - if (zap_channel_write(spri->dchan, buf, buflen, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); - zap_clear_flag(spri, LPWRAP_PRI_READY); + if (ftdm_channel_write(spri->dchan, buf, buflen, &len) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT, "span %d D-WRITE FAIL! [%s]\n", spri->span->span_id, spri->dchan->last_error); + ftdm_clear_flag(spri, LPWRAP_PRI_READY); return -1; } @@ -161,14 +161,14 @@ static int __pri_lpwrap_write(struct pri *pri, void *buf, int buflen) char bb[2048] = { 0 }; print_hex_bytes(buf, buflen - 2, bb, sizeof(bb)); - zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", (int)buflen-2); + ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n", (int)buflen-2); } #endif return (int) buflen; } -int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug) +int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug) { int ret = -1; @@ -182,8 +182,8 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dc size_t buflen = sizeof(buf), len = 0; pri_set_debug(spri->pri, debug); ret = 0; - zap_set_flag(spri, LPWRAP_PRI_READY); - zap_channel_write(spri->dchan, buf, buflen, &len); + ftdm_set_flag(spri, LPWRAP_PRI_READY); + ftdm_channel_write(spri->dchan, buf, buflen, &len); } else { fprintf(stderr, "Unable to create PRI\n"); } @@ -238,7 +238,7 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) if ((next = pri_schedule_next(spri->pri))) { gettimeofday(&now, NULL); if (now.tv_sec >= next->tv_sec && (now.tv_usec >= next->tv_usec || next->tv_usec <= 100000)) { - //zap_log(ZAP_LOG_DEBUG, "Check event\n"); + //ftdm_log(FTDM_LOG_DEBUG, "Check event\n"); event = pri_schedule_run(spri->pri); } } @@ -251,7 +251,7 @@ int lpwrap_one_loop(struct lpwrap_pri *spri) if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) { handler(spri, event->e, event); } else { - zap_log(ZAP_LOG_CRIT, "No event handler found for event %d.\n", event->e); + ftdm_log(FTDM_LOG_CRIT, "No event handler found for event %d.\n", event->e); } } @@ -281,7 +281,7 @@ int lpwrap_run_pri(struct lpwrap_pri *spri) continue; } #endif - zap_log(ZAP_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno)); + ftdm_log(FTDM_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno)); break; } } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h b/libs/freetdm/src/ftmod/ftmod_libpri/lpwrap_pri.h similarity index 95% rename from libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h rename to libs/freetdm/src/ftmod/ftmod_libpri/lpwrap_pri.h index 4c79526b9e..f92c5bbafa 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/lpwrap_pri.h +++ b/libs/freetdm/src/ftmod/ftmod_libpri/lpwrap_pri.h @@ -34,7 +34,7 @@ #ifndef _LPWRAP_PRI_H #define _LPWRAP_PRI_H #include -#include +#include #define LPWRAP_MAX_CHAN_PER_SPAN 32 @@ -97,8 +97,8 @@ typedef int (*loop_handler)(struct lpwrap_pri *); struct lpwrap_pri { struct pri *pri; - zap_span_t *span; - zap_channel_t *dchan; + ftdm_span_t *span; + ftdm_channel_t *dchan; unsigned int flags; void *private_info; event_handler eventmap[LPWRAP_PRI_EVENT_MAX]; @@ -120,7 +120,7 @@ struct lpwrap_pri_event_list { const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id); int lpwrap_one_loop(struct lpwrap_pri *spri); -int lpwrap_init_pri(struct lpwrap_pri *spri, zap_span_t *span, zap_channel_t *dchan, int swtype, int node, int debug); +int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug); int lpwrap_run_pri(struct lpwrap_pri *spri); #endif diff --git a/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h b/libs/freetdm/src/ftmod/ftmod_pika/ftdm_pika.h similarity index 98% rename from libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h rename to libs/freetdm/src/ftmod/ftmod_pika/ftdm_pika.h index 27c455a429..882eaba411 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/zap_pika.h +++ b/libs/freetdm/src/ftmod/ftmod_pika/ftdm_pika.h @@ -31,9 +31,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_PIKA_H -#define ZAP_PIKA_H -#include "openzap.h" +#ifndef FTDM_PIKA_H +#define FTDM_PIKA_H +#include "freetdm.h" #include "pikahmpapi.h" diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c similarity index 67% rename from libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c rename to libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c index 2932a342e7..06ea9f1353 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c @@ -32,8 +32,8 @@ */ -#include "openzap.h" -#include "zap_pika.h" +#include "freetdm.h" +#include "ftdm_pika.h" #define MAX_NUMBER_OF_TRUNKS 64 @@ -45,19 +45,19 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event); -ZAP_ENUM_NAMES(PIKA_SPAN_NAMES, PIKA_SPAN_STRINGS) +FTDM_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) +FTDM_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) +FTDM_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) +FTDM_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) +FTDM_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) @@ -93,7 +93,7 @@ static struct { PKH_TECConfig ec_config; PKH_TSpanConfig t1_span_config; PKH_TSpanConfig e1_span_config; - zap_hash_t *profile_hash; + ftdm_hash_t *profile_hash; general_config_t general_config; } globals; @@ -121,9 +121,9 @@ struct pika_chan_data { 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; + ftdm_buffer_t *digit_buffer; + ftdm_mutex_t *digit_mutex; + ftdm_size_t dtmf_len; uint32_t flags; uint32_t hdlc_bytes; }; @@ -156,20 +156,20 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) int ok = 1; if (!(profile = (pika_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { - profile = zap_malloc(sizeof(*profile)); + profile = ftdm_malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); - zap_set_string(profile->name, category); + ftdm_set_string(profile->name, category); 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); + ftdm_log(FTDM_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); + profile->record_config.AGC.enabled = ftdm_true(val); } else if (!strcasecmp(var, "rx-agc-targetPower")) { profile->record_config.AGC.targetPower = pk_atof(val); } else if (!strcasecmp(var, "rx-agc-minGain")) { @@ -183,7 +183,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } 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); + profile->record_config.VAD.enabled = ftdm_true(val); } else if (!strcasecmp(var, "rx-vad-activationThreshold")) { profile->record_config.VAD.activationThreshold = pk_atof(val); } else if (!strcasecmp(var, "rx-vad-activationDebounceTime")) { @@ -197,7 +197,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } 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); + profile->play_config.AGC.enabled = ftdm_true(val); } else if (!strcasecmp(var, "tx-agc-targetPower")) { profile->play_config.AGC.targetPower = pk_atof(val); } else if (!strcasecmp(var, "tx-agc-minGain")) { @@ -211,7 +211,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } 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); + profile->ec_enabled = ftdm_true(val); } else if (!strcasecmp(var, "ec-doubleTalkerThreshold")) { profile->ec_config.doubleTalkerThreshold = pk_atof(val); } else if (!strcasecmp(var, "ec-speechPresentThreshold")) { @@ -219,11 +219,11 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } 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); + profile->ec_config.echoSuppressionEnabled = ftdm_true(val); } else if (!strcasecmp(var, "ec-comfortNoiseEnabled")) { - profile->ec_config.comfortNoiseEnabled = zap_true(val); + profile->ec_config.comfortNoiseEnabled = ftdm_true(val); } else if (!strcasecmp(var, "ec-adaptationModeEnabled")) { - profile->ec_config.adaptationModeEnabled = zap_true(val); + profile->ec_config.adaptationModeEnabled = ftdm_true(val); } else if (!strcasecmp(var, "framing")) { profile->span_config.framing = pika_str2span(val); profile->cust_span++; @@ -250,12 +250,12 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) } if (ok) { - zap_log(ZAP_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category); + ftdm_log(FTDM_LOG_INFO, "setting param [%s]=[%s] for profile [%s]\n", var, val, category); } else { - zap_log(ZAP_LOG_ERROR, "unknown param [%s]\n", var); + ftdm_log(FTDM_LOG_ERROR, "unknown param [%s]\n", var); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -265,22 +265,22 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) 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; + ftdm_channel_t *ftdmchan = event->userData; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->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); + //ftdm_log(FTDM_LOG_DEBUG, "Event: %s\n", event_text); switch (event->id) { case PKH_EVENT_PLAY_IDLE: { - while (zap_buffer_inuse(chan_data->digit_buffer)) { + while (ftdm_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)); + ftdm_mutex_lock(chan_data->digit_mutex); + chan_data->dtmf_len = ftdm_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); + ftdm_mutex_unlock(chan_data->digit_mutex); } } break; @@ -288,10 +288,10 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) { if (!event->p1) { - zap_mutex_lock(chan_data->digit_mutex); + ftdm_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); + ftdm_mutex_unlock(chan_data->digit_mutex); } @@ -305,19 +305,19 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) /** * \brief Initialises a range of pika channels - * \param span Openzap span + * \param span Openftdm 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 type Openftdm channel type + * \param name Openftdm span name + * \param number Openftdm 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) +static unsigned pika_open_range(ftdm_span_t *span, unsigned boardno, unsigned spanno, unsigned start, unsigned end, + ftdm_chan_type_t type, char *name, char *number, pika_channel_profile_t *profile) { unsigned configured = 0, x; PK_STATUS status; @@ -325,7 +325,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa pika_span_data_t *span_data; if (boardno >= globals.board_list.numberOfBoards) { - zap_log(ZAP_LOG_ERROR, "Board %u is not present!\n", boardno); + ftdm_log(FTDM_LOG_ERROR, "Board %u is not present!\n", boardno); return 0; } @@ -334,12 +334,12 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa NULL, &globals.open_boards[boardno]); if(status != PK_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error: PKH_BOARD_Open %d failed(%s)!\n", boardno, + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "Open board %u\n", boardno); //PKH_BOARD_SetDebugTrace(globals.open_boards[boardno], 1, 0); @@ -348,7 +348,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa if (span->mod_data) { span_data = span->mod_data; } else { - span_data = zap_malloc(sizeof(*span_data)); + span_data = ftdm_malloc(sizeof(*span_data)); assert(span_data != NULL); memset(span_data, 0, sizeof(*span_data)); span_data->boardno = boardno; @@ -356,9 +356,9 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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", + ftdm_log(FTDM_LOG_ERROR, "Error: PKH_QUEUE_Create failed(%s)!\n", PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - zap_safe_free(span_data); + ftdm_safe_free(span_data); return 0; } @@ -367,43 +367,43 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa span->mod_data = span_data; } - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO) { start--; end--; } for(x = start; x < end; x++) { - zap_channel_t *chan; + ftdm_channel_t *chan; pika_chan_data_t *chan_data = NULL; - chan_data = zap_malloc(sizeof *chan_data); + chan_data = ftdm_malloc(sizeof *chan_data); assert(chan_data); memset(chan_data, 0, sizeof(*chan_data)); - zap_span_add_channel(span, 0, type, &chan); + ftdm_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) { + if ((type == FTDM_CHAN_TYPE_B || type == FTDM_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"); + if ((profile && profile->general_config.region == PKH_TRUNK_EU) || ftdm_test_flag(span_data, PK_FLAG_LOCKED)) { + if (span->trunk_type == FTDM_TRUNK_T1) { + ftdm_log(FTDM_LOG_WARNING, "Changing trunk type to E1 based on previous config.\n"); } - span->trunk_type = ZAP_TRUNK_E1; + span->trunk_type = FTDM_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"); + if (span->trunk_type == FTDM_TRUNK_T1) { + if (ftdm_test_flag(span_data, PK_FLAG_LOCKED)) { + ftdm_log(FTDM_LOG_WARNING, "Already locked into E1 mode!\n"); } - } else if (span->trunk_type == ZAP_TRUNK_E1) { + } else if (span->trunk_type == FTDM_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", + ftdm_log(FTDM_LOG_ERROR, "Error: [%s]\n", PKH_ERROR_GetText(status, error_text, sizeof(error_text))); } - zap_set_flag(span_data, PK_FLAG_LOCKED); + ftdm_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); @@ -411,7 +411,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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) { + if (type == FTDM_CHAN_TYPE_FXO) { PKH_TTrunkConfig trunkConfig; TRY_OR_DIE(PKH_TRUNK_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, error); @@ -422,10 +422,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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; + chan->native_codec = chan->effective_codec = FTDM_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; + chan->native_codec = chan->effective_codec = FTDM_CODEC_ULAW; } @@ -437,17 +437,17 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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) { + } else if (type == FTDM_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; + chan->native_codec = chan->effective_codec = FTDM_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; + chan->native_codec = chan->effective_codec = FTDM_CODEC_ULAW; } TRY_OR_DIE(PKH_PHONE_Open(globals.open_boards[boardno], x, &chan_data->handle), PK_SUCCESS, error); @@ -460,7 +460,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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) { + } else if (type == FTDM_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); @@ -468,7 +468,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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) { + } else if (type == FTDM_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; @@ -492,7 +492,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } } } else { - if (span->trunk_type == ZAP_TRUNK_E1) { + if (span->trunk_type == FTDM_TRUNK_E1) { span_data->span_config = globals.e1_span_config; } else { span_data->span_config = globals.t1_span_config; @@ -507,10 +507,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); + ftdm_log(FTDM_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); + ftdm_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; @@ -524,10 +524,10 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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); + ftdm_log(FTDM_LOG_INFO, "configuring device b%ds%dc%d as OpenFTDM 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); + ftdm_log(FTDM_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; @@ -537,11 +537,11 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa chan_data->ec_config = profile->ec_config; } - if (type == ZAP_CHAN_TYPE_B) { + if (type == FTDM_CHAN_TYPE_B) { if (span_data->span_config.compandMode == PKH_SPAN_COMPAND_MODE_A_LAW) { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW; + chan->native_codec = chan->effective_codec = FTDM_CODEC_ALAW; } else { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + chan->native_codec = chan->effective_codec = FTDM_CODEC_ULAW; } } @@ -562,17 +562,17 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa 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 (!ftdm_strlen_zero(name)) { + ftdm_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)); + if (!ftdm_strlen_zero(number)) { + ftdm_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); + ftdm_channel_set_feature(chan, FTDM_CHANNEL_FEATURE_DTMF_GENERATE); + ftdm_buffer_create(&chan_data->digit_buffer, 128, 128, 0); + ftdm_mutex_create(&chan_data->digit_mutex); configured++; } @@ -582,12 +582,12 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa } /** - * \brief Initialises an openzap pika span from a configuration string - * \param span Openzap span + * \brief Initialises an freetdm pika span from a configuration string + * \param span Openftdm span * \param str Configuration string - * \param type Openzap span type - * \param name Openzap span name - * \param number Openzap span number + * \param type Openftdm span type + * \param name Openftdm span name + * \param number Openftdm span number * \return Success or failure */ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) @@ -605,17 +605,17 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) assert(str != NULL); - mydata = zap_strdup(str); + mydata = ftdm_strdup(str); assert(mydata != NULL); if ((profile_name = strchr(mydata, '@'))) { *profile_name++ = '\0'; - if (!zap_strlen_zero(profile_name)) { + if (!ftdm_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]))); + items = ftdm_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); for(i = 0; i < items; i++) { bd = item_list[i]; @@ -627,7 +627,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) } if (!(bd && sp && ch)) { - zap_log(ZAP_LOG_ERROR, "Invalid input\n"); + ftdm_log(FTDM_LOG_ERROR, "Invalid input\n"); continue; } @@ -637,17 +637,17 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) if (boardno < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid board number %d\n", boardno); + ftdm_log(FTDM_LOG_ERROR, "Invalid board number %d\n", boardno); continue; } if (channo < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid channel number %d\n", channo); + ftdm_log(FTDM_LOG_ERROR, "Invalid channel number %d\n", channo); continue; } if (spanno < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid span number %d\n", channo); + ftdm_log(FTDM_LOG_ERROR, "Invalid span number %d\n", channo); continue; } @@ -660,7 +660,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) if (top < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); + ftdm_log(FTDM_LOG_ERROR, "Invalid range number %d\n", top); continue; } @@ -668,108 +668,108 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) } - zap_safe_free(mydata); + ftdm_safe_free(mydata); return configured; } /** * \brief Opens Pika channel - * \param zchan Channel to open + * \param ftdmchan 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; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; - if (!chan_data && !zap_test_flag(chan_data, PK_FLAG_READY)) { - return ZAP_FAIL; + if (!chan_data && !ftdm_test_flag(chan_data, PK_FLAG_READY)) { + return FTDM_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) { + if (ftdmchan->type == FTDM_CHAN_TYPE_FXS || ftdmchan->type == FTDM_CHAN_TYPE_FXO || ftdmchan->type == FTDM_CHAN_TYPE_B) { PKH_PLAY_Start(chan_data->media_out); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Closes Pika channel - * \param zchan Channel to close + * \param ftdmchan Channel to close * \return Success */ static ZIO_CLOSE_FUNCTION(pika_close) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Waits for an event on a Pika channel - * \param zchan Channel to open + * \param ftdmchan 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; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; PK_STATUS status; - zap_wait_flag_t myflags = *flags; + ftdm_wait_flag_t myflags = *flags; PK_CHAR event_text[PKH_EVENT_MAX_NAME_LENGTH]; - *flags = ZAP_NO_FLAGS; + *flags = FTDM_NO_FLAGS; - if (myflags & ZAP_READ) { + if (myflags & FTDM_READ) { if (chan_data->hdlc_bytes) { - *flags |= ZAP_READ; - return ZAP_SUCCESS; + *flags |= FTDM_READ; + return FTDM_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; + return FTDM_TIMEOUT; } - *flags |= ZAP_READ; - return ZAP_SUCCESS; + *flags |= FTDM_READ; + return FTDM_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); + ftdm_log(FTDM_LOG_DEBUG, "Event: %s\n", event_text); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Reads data from a Pika channel - * \param zchan Channel to read from + * \param ftdmchan 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; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->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 (ftdmchan->type == FTDM_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 FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } if (!(len = chan_data->last_media_event.p0)) { - len = zchan->packet_len; + len = ftdmchan->packet_len; } if (len < *datalen) { @@ -777,167 +777,167 @@ static ZIO_READ_FUNCTION(pika_read) } if ((status = PKH_RECORD_GetData(chan_data->media_in, data, *datalen)) == PK_SUCCESS) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } PKH_ERROR_GetText(status, event_text, sizeof(event_text)); - zap_log(ZAP_LOG_DEBUG, "ERR: %s\n", event_text); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_DEBUG, "ERR: %s\n", event_text); + return FTDM_FAIL; } /** * \brief Writes data to a Pika channel - * \param zchan Channel to write to + * \param ftdmchan 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; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; PK_STATUS status; - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { if ((status = PKH_SPAN_HDLC_SendMessage(chan_data->handle, data, *datalen)) == PK_SUCCESS) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } if (PKH_PLAY_AddData(chan_data->media_out, 0, data, *datalen) == PK_SUCCESS) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } /** - * \brief Executes an Openzap command on a Pika channel - * \param zchan Channel to execute command on - * \param command Openzap command to execute + * \brief Executes an Openftdm command on a Pika channel + * \param ftdmchan Channel to execute command on + * \param command Openftdm 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; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; + //pika_span_data_t *span_data = (pika_span_data_t *) ftdmchan->span->mod_data; PK_STATUS pk_status; - zap_status_t status = ZAP_SUCCESS; + ftdm_status_t status = FTDM_SUCCESS; switch(command) { - case ZAP_COMMAND_OFFHOOK: + case FTDM_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); + PKH_ERROR_GetText(pk_status, ftdmchan->last_error, sizeof(ftdmchan->last_error)); + GOTO_STATUS(done, FTDM_FAIL); } else { - zap_set_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); } } break; - case ZAP_COMMAND_ONHOOK: + case FTDM_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); + PKH_ERROR_GetText(pk_status, ftdmchan->last_error, sizeof(ftdmchan->last_error)); + GOTO_STATUS(done, FTDM_FAIL); } else { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); } } break; - case ZAP_COMMAND_GENERATE_RING_ON: + case FTDM_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); + PKH_ERROR_GetText(pk_status, ftdmchan->last_error, sizeof(ftdmchan->last_error)); + GOTO_STATUS(done, FTDM_FAIL); } else { - zap_set_flag_locked(zchan, ZAP_CHANNEL_RINGING); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_RINGING); } } break; - case ZAP_COMMAND_GENERATE_RING_OFF: + case FTDM_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); + PKH_ERROR_GetText(pk_status, ftdmchan->last_error, sizeof(ftdmchan->last_error)); + GOTO_STATUS(done, FTDM_FAIL); } else { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_RINGING); } } break; - case ZAP_COMMAND_GET_INTERVAL: + case FTDM_COMMAND_GET_INTERVAL: { - ZAP_COMMAND_OBJ_INT = zchan->native_interval; + FTDM_COMMAND_OBJ_INT = ftdmchan->native_interval; } break; - case ZAP_COMMAND_SET_INTERVAL: + case FTDM_COMMAND_SET_INTERVAL: { - int interval = ZAP_COMMAND_OBJ_INT; + int interval = FTDM_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; + ftdmchan->packet_len = (uint32_t)chan_data->record_config.bufferSize; + ftdmchan->effective_interval = ftdmchan->native_interval = ftdmchan->packet_len / 8; PKH_RECORD_SetConfig(chan_data->media_in, &chan_data->record_config); - GOTO_STATUS(done, ZAP_SUCCESS); + GOTO_STATUS(done, FTDM_SUCCESS); } break; - case ZAP_COMMAND_GET_DTMF_ON_PERIOD: + case FTDM_COMMAND_GET_DTMF_ON_PERIOD: { - ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - GOTO_STATUS(done, ZAP_SUCCESS); + FTDM_COMMAND_OBJ_INT = ftdmchan->dtmf_on; + GOTO_STATUS(done, FTDM_SUCCESS); } break; - case ZAP_COMMAND_GET_DTMF_OFF_PERIOD: + case FTDM_COMMAND_GET_DTMF_OFF_PERIOD: { - ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - GOTO_STATUS(done, ZAP_SUCCESS); + FTDM_COMMAND_OBJ_INT = ftdmchan->dtmf_on; + GOTO_STATUS(done, FTDM_SUCCESS); } break; - case ZAP_COMMAND_SET_DTMF_ON_PERIOD: + case FTDM_COMMAND_SET_DTMF_ON_PERIOD: { - int val = ZAP_COMMAND_OBJ_INT; + int val = FTDM_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { - zchan->dtmf_on = val; - GOTO_STATUS(done, ZAP_SUCCESS); + ftdmchan->dtmf_on = val; + GOTO_STATUS(done, FTDM_SUCCESS); } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); - GOTO_STATUS(done, ZAP_FAIL); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "invalid value %d range 10-1000", val); + GOTO_STATUS(done, FTDM_FAIL); } } break; - case ZAP_COMMAND_SET_DTMF_OFF_PERIOD: + case FTDM_COMMAND_SET_DTMF_OFF_PERIOD: { - int val = ZAP_COMMAND_OBJ_INT; + int val = FTDM_COMMAND_OBJ_INT; if (val > 10 && val < 1000) { - zchan->dtmf_off = val; - GOTO_STATUS(done, ZAP_SUCCESS); + ftdmchan->dtmf_off = val; + GOTO_STATUS(done, FTDM_SUCCESS); } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid value %d range 10-1000", val); - GOTO_STATUS(done, ZAP_FAIL); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "invalid value %d range 10-1000", val); + GOTO_STATUS(done, FTDM_FAIL); } } break; - case ZAP_COMMAND_SEND_DTMF: + case FTDM_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); + char *digits = FTDM_COMMAND_OBJ_CHAR_P; + ftdm_log(FTDM_LOG_DEBUG, "Adding DTMF SEQ [%s]\n", digits); + ftdm_mutex_lock(chan_data->digit_mutex); + ftdm_buffer_write(chan_data->digit_buffer, digits, strlen(digits)); + ftdm_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); + PKH_ERROR_GetText(pk_status, ftdmchan->last_error, sizeof(ftdmchan->last_error)); + GOTO_STATUS(done, FTDM_FAIL); } - GOTO_STATUS(done, ZAP_SUCCESS); + GOTO_STATUS(done, FTDM_SUCCESS); } break; default: @@ -963,22 +963,22 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) status = PKH_QUEUE_WaitOnEvent(span_data->event_queue, ms, &span_data->last_oob_event); if (status == PK_SUCCESS) { - zap_channel_t *zchan = NULL; + ftdm_channel_t *ftdmchan = NULL; uint32_t *data = (uint32_t *) span_data->last_oob_event.userData; - zap_data_type_t data_type = ZAP_TYPE_NONE; + ftdm_data_type_t data_type = FTDM_TYPE_NONE; if (span_data->last_oob_event.id == PKH_EVENT_QUEUE_TIMEOUT) { - return ZAP_TIMEOUT; + return FTDM_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(); + if (data_type == FTDM_TYPE_CHANNEL) { + ftdmchan = span_data->last_oob_event.userData; + } else if (data_type == FTDM_TYPE_SPAN) { + ftdm_time_t last_event_time = ftdm_current_time_in_ms(); uint32_t event_id = 0; switch (span_data->last_oob_event.id) { @@ -996,7 +996,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) 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; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_T1_RED_CLEAR: case PKH_EVENT_SPAN_ALARM_T1_YELLOW_CLEAR: @@ -1011,7 +1011,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) 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; + event_id = FTDM_OOB_ALARM_CLEAR; break; case PKH_EVENT_SPAN_MESSAGE: case PKH_EVENT_SPAN_ABCD_SIGNAL_CHANGE: @@ -1020,17 +1020,17 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) if (event_id) { uint32_t x = 0; - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; 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; + ftdmchan = span->channels[x]; + assert(ftdmchan != NULL); + chan_data = (pika_chan_data_t *) ftdmchan->mod_data; assert(chan_data != NULL); - zap_set_flag(zchan, ZAP_CHANNEL_EVENT); - zchan->last_event_time = last_event_time; + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_EVENT); + ftdmchan->last_event_time = last_event_time; chan_data->last_oob_event = span_data->last_oob_event; } @@ -1039,27 +1039,27 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_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); + //ftdm_log(FTDM_LOG_DEBUG, "Event: %s\n", event_text); - if (zchan) { - pika_chan_data_t *chan_data = (pika_chan_data_t *) zchan->mod_data; + if (ftdmchan) { + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; assert(chan_data != NULL); - zap_set_flag(zchan, ZAP_CHANNEL_EVENT); - zchan->last_event_time = zap_current_time_in_ms(); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_EVENT); + ftdmchan->last_event_time = ftdm_current_time_in_ms(); chan_data->last_oob_event = span_data->last_oob_event; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } /** * \brief Retrieves an event from a Pika span * \param span Span to retrieve event from - * \param event Openzap event to return + * \param event Openftdm event to return * \return Success or failure */ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) @@ -1067,11 +1067,11 @@ 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)) { + if (ftdm_test_flag(span->channels[i], FTDM_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); + ftdm_clear_flag(span->channels[i], FTDM_CHANNEL_EVENT); PKH_EVENT_GetText(chan_data->last_oob_event.id, event_text, sizeof(event_text)); @@ -1080,58 +1080,58 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) chan_data->hdlc_bytes = chan_data->last_oob_event.p2; continue; case PKH_EVENT_TRUNK_HOOKFLASH: - event_id = ZAP_OOB_FLASH; + event_id = FTDM_OOB_FLASH; break; case PKH_EVENT_TRUNK_RING_OFF: - event_id = ZAP_OOB_RING_STOP; + event_id = FTDM_OOB_RING_STOP; break; case PKH_EVENT_TRUNK_RING_ON: - event_id = ZAP_OOB_RING_START; + event_id = FTDM_OOB_RING_START; break; case PKH_EVENT_PHONE_OFFHOOK: - zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_OFFHOOK); - event_id = ZAP_OOB_OFFHOOK; + ftdm_set_flag_locked(span->channels[i], FTDM_CHANNEL_OFFHOOK); + event_id = FTDM_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; + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_OFFHOOK); + event_id = FTDM_OOB_ONHOOK; break; case PKH_EVENT_SPAN_ALARM_T1_RED: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_RED); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "RED ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_T1_YELLOW: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_YELLOW); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_YELLOW); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "YELLOW ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_T1_AIS: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_AIS); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "AIS ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_E1_RED: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_RED); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "RED ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_E1_RAI: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RAI); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_RAI); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "RAI ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_E1_AIS: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_AIS); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "AIS ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_E1_RMAI: case PKH_EVENT_SPAN_ALARM_E1_TS16AIS: @@ -1141,22 +1141,22 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_GENERAL); snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "GENERAL ALARM"); - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; case PKH_EVENT_SPAN_ALARM_T1_RED_CLEAR: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_RED); case PKH_EVENT_SPAN_ALARM_T1_YELLOW_CLEAR: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_YELLOW); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_YELLOW); case PKH_EVENT_SPAN_ALARM_T1_AIS_CLEAR: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_AIS); case PKH_EVENT_SPAN_ALARM_E1_RED_CLEAR: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RED); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_RED); case PKH_EVENT_SPAN_ALARM_E1_RAI_CLEAR: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_RAI); + ftdm_set_alarm_flag(span->channels[i], FTDM_ALARM_RAI); case PKH_EVENT_SPAN_ALARM_E1_AIS_CLEAR: - zap_set_alarm_flag(span->channels[i], ZAP_ALARM_AIS); + ftdm_set_alarm_flag(span->channels[i], FTDM_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: @@ -1164,8 +1164,8 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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; + ftdm_clear_alarm_flag(span->channels[i], FTDM_ALARM_GENERAL); + event_id = FTDM_OOB_ALARM_CLEAR; break; case PKH_EVENT_SPAN_MESSAGE: case PKH_EVENT_SPAN_ABCD_SIGNAL_CHANGE: @@ -1183,21 +1183,21 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) 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; + ftdm_log(FTDM_LOG_DEBUG, "Unhandled event %d on channel %d [%s]\n", chan_data->last_oob_event.id, i, event_text); + event_id = FTDM_OOB_INVALID; break; } span->channels[i]->last_event_time = 0; - span->event_header.e_type = ZAP_EVENT_OOB; + span->event_header.e_type = FTDM_EVENT_OOB; span->event_header.enum_id = event_id; span->event_header.channel = span->channels[i]; *event = &span->event_header; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } } - return ZAP_FAIL; + return FTDM_FAIL; } /** @@ -1211,27 +1211,27 @@ static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) if (span_data) { PKH_QUEUE_Destroy(span_data->event_queue); - zap_safe_free(span_data); + ftdm_safe_free(span_data); } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Destroys a Pika Channel - * \param zchan Channel to destroy + * \param ftdmchan 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; + pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; + pika_span_data_t *span_data = (pika_span_data_t *) ftdmchan->span->mod_data; if (!chan_data) { - return ZAP_FAIL; + return FTDM_FAIL; } - if (!zap_test_flag(chan_data, PK_FLAG_READY)) { + if (!ftdm_test_flag(chan_data, PK_FLAG_READY)) { goto end; } @@ -1240,16 +1240,16 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) PKH_QUEUE_Destroy(chan_data->media_in_queue); PKH_QUEUE_Destroy(chan_data->media_out_queue); - switch(zchan->type) { - case ZAP_CHAN_TYPE_FXS: + switch(ftdmchan->type) { + case FTDM_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: + case FTDM_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: + case FTDM_CHAN_TYPE_DQ921: PKH_SPAN_Stop(span_data->handle); break; default: @@ -1257,30 +1257,30 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) } - zap_mutex_destroy(&chan_data->digit_mutex); - zap_buffer_destroy(&chan_data->digit_buffer); + ftdm_mutex_destroy(&chan_data->digit_mutex); + ftdm_buffer_destroy(&chan_data->digit_buffer); end: - zap_safe_free(chan_data); + ftdm_safe_free(chan_data); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Gets alarms from a Pika Channel (does nothing) - * \param zchan Channel to get alarms from + * \param ftdmchan Channel to get alarms from * \return Failure */ static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) { - return ZAP_FAIL; + return FTDM_FAIL; } -static zap_io_interface_t pika_interface; +static ftdm_io_interface_t pika_interface; /** * \brief Loads Pika IO module - * \param zio Openzap IO interface + * \param zio Openftdm IO interface * \return Success or failure */ static ZIO_IO_LOAD_FUNCTION(pika_init) @@ -1298,21 +1298,21 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) memset(&globals, 0, sizeof(globals)); globals.general_config.region = PKH_TRUNK_NA; - globals.profile_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + globals.profile_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_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", + ftdm_log(FTDM_LOG_ERROR, "Error: PKH_SYSTEM_Open failed(%s)!\n", PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - return ZAP_FAIL; + return FTDM_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", + ftdm_log(FTDM_LOG_ERROR, "Error: PKH_SYSTEM_Detect failed(%s)!\n", PKH_ERROR_GetText(status, error_text, sizeof(error_text))); - return ZAP_FAIL; + return FTDM_FAIL; } PKH_SYSTEM_GetConfig(globals.system_handle, &globals.system_config); @@ -1330,9 +1330,9 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) - zap_log(ZAP_LOG_DEBUG, "Found %u board%s\n", globals.board_list.numberOfBoards, globals.board_list.numberOfBoards == 1 ? "" : "s"); + ftdm_log(FTDM_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", + ftdm_log(FTDM_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); @@ -1358,7 +1358,7 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) } if (!ok) { - return ZAP_FAIL; + return FTDM_FAIL; } pika_interface.name = "pika"; @@ -1378,35 +1378,35 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) *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"); + ftdm_log(FTDM_LOG_INFO, "Dumping Default configs:\n"); + ftdm_log(FTDM_LOG_INFO, "rx-gain => %0.2f\n", (float)globals.record_config.gain); + ftdm_log(FTDM_LOG_INFO, "rx-agc-enabled => %s\n", globals.record_config.AGC.enabled ? "true" : "false"); + ftdm_log(FTDM_LOG_INFO, "rx-agc-targetPower => %0.2f\n", (float)globals.record_config.AGC.targetPower); + ftdm_log(FTDM_LOG_INFO, "rx-agc-minGain => %0.2f\n", (float)globals.record_config.AGC.minGain); + ftdm_log(FTDM_LOG_INFO, "rx-agc-maxGain => %0.2f\n", (float)globals.record_config.AGC.maxGain); + ftdm_log(FTDM_LOG_INFO, "rx-agc-attackRate => %d\n", (int)globals.record_config.AGC.attackRate); + ftdm_log(FTDM_LOG_INFO, "rx-agc-decayRate => %d\n", (int)globals.record_config.AGC.decayRate); + ftdm_log(FTDM_LOG_INFO, "rx-agc-speechThreshold => %0.2f\n", (float)globals.record_config.AGC.speechThreshold); + ftdm_log(FTDM_LOG_INFO, "rx-vad-enabled => %s\n", globals.record_config.VAD.enabled ? "true" : "false"); + ftdm_log(FTDM_LOG_INFO, "rx-vad-activationThreshold => %0.2f\n", (float)globals.record_config.VAD.activationThreshold); + ftdm_log(FTDM_LOG_INFO, "rx-vad-activationDebounceTime => %d\n", (int)globals.record_config.VAD.activationDebounceTime); + ftdm_log(FTDM_LOG_INFO, "rx-vad-deactivationThreshold => %0.2f\n", (float)globals.record_config.VAD.deactivationThreshold); + ftdm_log(FTDM_LOG_INFO, "rx-vad-deactivationDebounceTime => %d\n", (int)globals.record_config.VAD.deactivationDebounceTime); + ftdm_log(FTDM_LOG_INFO, "rx-vad-preSpeechBufferSize => %d\n", (int)globals.record_config.VAD.preSpeechBufferSize); + ftdm_log(FTDM_LOG_INFO, "tx-gain => %0.2f\n", (float)globals.play_config.gain); + ftdm_log(FTDM_LOG_INFO, "tx-agc-enabled => %s\n", globals.play_config.AGC.enabled ? "true" : "false"); + ftdm_log(FTDM_LOG_INFO, "tx-agc-targetPower => %0.2f\n", (float)globals.play_config.AGC.targetPower); + ftdm_log(FTDM_LOG_INFO, "tx-agc-minGain => %0.2f\n", (float)globals.play_config.AGC.minGain); + ftdm_log(FTDM_LOG_INFO, "tx-agc-maxGain => %0.2f\n", (float)globals.play_config.AGC.maxGain); + ftdm_log(FTDM_LOG_INFO, "tx-agc-attackRate => %d\n", (int)globals.play_config.AGC.attackRate); + ftdm_log(FTDM_LOG_INFO, "tx-agc-decayRate => %d\n", (int)globals.play_config.AGC.decayRate); + ftdm_log(FTDM_LOG_INFO, "tx-agc-speechThreshold => %0.2f\n", (float)globals.play_config.AGC.speechThreshold); + ftdm_log(FTDM_LOG_INFO, "ec-doubleTalkerThreshold => %0.2f\n", (float)globals.ec_config.doubleTalkerThreshold); + ftdm_log(FTDM_LOG_INFO, "ec-speechPresentThreshold => %0.2f\n", (float)globals.ec_config.speechPresentThreshold); + ftdm_log(FTDM_LOG_INFO, "ec-echoSuppressionThreshold => %0.2f\n", (float)globals.ec_config.echoSuppressionThreshold); + ftdm_log(FTDM_LOG_INFO, "ec-echoSuppressionEnabled => %s\n", globals.ec_config.echoSuppressionEnabled ? "true" : "false"); + ftdm_log(FTDM_LOG_INFO, "ec-comfortNoiseEnabled => %s\n", globals.ec_config.comfortNoiseEnabled ? "true" : "false"); + ftdm_log(FTDM_LOG_INFO, "ec-adaptationModeEnabled => %s\n", globals.ec_config.adaptationModeEnabled ? "true" : "false"); @@ -1414,7 +1414,7 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) //m.apiMask = 0xffffffff; //PKH_LOG_SetMasks(&m); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -1429,28 +1429,28 @@ static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) for (x = 0; x < MAX_NUMBER_OF_TRUNKS; x++) { if (globals.open_boards[x]) { - zap_log(ZAP_LOG_INFO, "Closing board %u\n", x); + ftdm_log(FTDM_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", + ftdm_log(FTDM_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"); + ftdm_log(FTDM_LOG_INFO, "Closing system handle\n"); } hashtable_destroy(globals.profile_hash); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Pika IO module definition */ -EX_DECLARE_DATA zap_module_t zap_module = { +EX_DECLARE_DATA ftdm_module_t ftdm_module = { "pika", pika_init, pika_destroy, diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2005.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2005.vcproj rename to libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2005.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2008.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2008.vcproj diff --git a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c new file mode 100644 index 0000000000..3dee603f1a --- /dev/null +++ b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c @@ -0,0 +1,1367 @@ +/* + * 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 "freetdm.h" + +/* debug thread count for r2 legs */ +static ftdm_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 { + FTDM_R2_RUNNING = (1 << 0), +} ftdm_r2_flag_t; + +/* private call information stored in ftdmchan->call_data void* ptr */ +#define R2CALL(ftdmchan) ((ftdm_r2_call_t*)((ftdmchan)->call_data)) +typedef struct ftdm_r2_call_t { + openr2_chan_t *r2chan; + int accepted:1; + int answer_pending:1; + int state_ack_pending:1; + int disconnect_rcvd:1; + int ftdm_started:1; + ftdm_channel_state_t chanstate; + ftdm_size_t dnis_index; + ftdm_size_t ani_index; + char name[10]; +} ftdm_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 ft_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; +} ft_r2_conf_t; + +/* r2 configuration stored in span->signal_data */ +typedef struct ftdm_r2_data_s { + /* signaling callback */ + zio_signal_cb_t sig_cb; + /* span flags */ + ftdm_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; +} ftdm_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 ftdm_r2_span_pvt_s { + openr2_context_t *r2context; /* r2 context allocated for this span */ + ftdm_hash_t *r2calls; /* hash table of allocated call data per channel for this span */ +} ftdm_r2_span_pvt_t; + +/* span monitor thread */ +static void *ftdm_r2_run(ftdm_thread_t *me, void *obj); + +/* channel monitor thread */ +static void *ftdm_r2_channel_run(ftdm_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 freetdm does not notify signaling modules when destroying a span + span -> ftdm_r2_mod_allocs_t */ +static ftdm_hash_t *g_mod_data_hash; + +/* IO interface for the command API */ +static ftdm_io_interface_t g_ftdm_r2_interface; + +static void ft_r2_clean_call(ftdm_r2_call_t *call) +{ + openr2_chan_t *r2chan = call->r2chan; + memset(call, 0, sizeof(*call)); + call->r2chan = r2chan; +} + +static void ft_r2_accept_call(ftdm_channel_t *ftdmchan) +{ + openr2_chan_t *r2chan = R2CALL(ftdmchan)->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(ftdmchan)->accepted = 1; +} + +static void ft_r2_answer_call(ftdm_channel_t *ftdmchan) +{ + openr2_chan_t *r2chan = R2CALL(ftdmchan)->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(ftdmchan)->answer_pending = 0; +} + +static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(r2_outgoing_call) +{ + ftdm_status_t status; + ftdm_mutex_lock(ftdmchan->mutex); + + /* the channel may be down but the thread not quite done */ + ftdm_wait_for_flag_cleared(ftdmchan, FTDM_CHANNEL_INTHREAD, 200); + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_log(FTDM_LOG_ERROR, "%d:%d Yay! R2 outgoing call in channel that is already in thread.\n", + ftdmchan->span_id, ftdmchan->chan_id); + ftdm_mutex_unlock(ftdmchan->mutex); + return FTDM_FAIL; + } + + ft_r2_clean_call(ftdmchan->call_data); + R2CALL(ftdmchan)->chanstate = FTDM_CHANNEL_STATE_DOWN; + ftdm_channel_set_state(ftdmchan, FTDM_CHANNEL_STATE_DIALING, 0); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + R2CALL(ftdmchan)->ftdm_started = 1; + ftdm_mutex_unlock(ftdmchan->mutex); + + status = ftdm_thread_create_detached(ftdm_r2_channel_run, ftdmchan); + if (status == FTDM_FAIL) { + ftdm_log(FTDM_LOG_ERROR, "%d:%d Cannot handle request to start call in channel, failed to create thread!\n", + ftdmchan->span_id, ftdmchan->chan_id); + ftdm_channel_done(ftdmchan); + return FTDM_FAIL; + } + + return FTDM_SUCCESS; +} + +static ftdm_status_t ftdm_r2_start(ftdm_span_t *span) +{ + ftdm_r2_data_t *r2_data = span->signal_data; + ftdm_set_flag(r2_data, FTDM_R2_RUNNING); + return ftdm_thread_create_detached(ftdm_r2_run, span); +} + +/* always called from the monitor thread */ +static void ftdm_r2_on_call_init(openr2_chan_t *r2chan) +{ + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_status_t status; + ftdm_log(FTDM_LOG_NOTICE, "Received request to start call on chan %d\n", openr2_chan_get_number(r2chan)); + + ftdm_mutex_lock(ftdmchan->mutex); + + if (ftdmchan->state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_log(FTDM_LOG_ERROR, "Cannot handle request to start call in channel %d, invalid state (%d)\n", + openr2_chan_get_number(r2chan), ftdmchan->state); + ftdm_mutex_unlock(ftdmchan->mutex); + return; + } + + /* the channel may be down but the thread not quite done */ + ftdm_wait_for_flag_cleared(ftdmchan, FTDM_CHANNEL_INTHREAD, 200); + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { + ftdm_log(FTDM_LOG_ERROR, "Cannot handle request to start call in channel %d, already in thread!\n", + openr2_chan_get_number(r2chan)); + ftdm_mutex_unlock(ftdmchan->mutex); + return; + } + ft_r2_clean_call(ftdmchan->call_data); + R2CALL(ftdmchan)->chanstate = FTDM_CHANNEL_STATE_DOWN; + ftdm_channel_set_state(ftdmchan, FTDM_CHANNEL_STATE_COLLECT, 0); + ftdm_mutex_unlock(ftdmchan->mutex); + + status = ftdm_thread_create_detached(ftdm_r2_channel_run, ftdmchan); + if (status == FTDM_FAIL) { + ftdm_log(FTDM_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 ftdm_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const char *dnis, openr2_calling_party_category_t category) +{ + ftdm_sigmsg_t sigev; + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_r2_data_t *r2data = ftdmchan->span->signal_data; + + ftdm_log(FTDM_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 = ftdmchan->chan_id; + sigev.span_id = ftdmchan->span_id; + sigev.channel = ftdmchan; + sigev.event_id = FTDM_SIGEVENT_START; + + if (r2data->sig_cb(&sigev) != FTDM_SUCCESS) { + ftdm_log(FTDM_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); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_CANCEL); + return; + } + ftdm_channel_use(ftdmchan); + R2CALL(ftdmchan)->ftdm_started = 1; +} + +static void ftdm_r2_on_call_accepted(openr2_chan_t *r2chan, openr2_call_mode_t mode) +{ + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_log(FTDM_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(ftdmchan)->state_ack_pending = 1; + if (R2CALL(ftdmchan)->answer_pending) { + ftdm_log(FTDM_LOG_DEBUG, "Answer was pending on chan %d, answering now.\n", openr2_chan_get_number(r2chan)); + ft_r2_answer_call(ftdmchan); + return; + } + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); + } +} + +static void ftdm_r2_on_call_answered(openr2_chan_t *r2chan) +{ + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_log(FTDM_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)) { + ftdm_set_state_locked(ftdmchan, FTDM_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 ftdm_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_disconnect_cause_t cause) +{ + ftdm_sigmsg_t sigev; + ftdm_r2_data_t *r2data; + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_log(FTDM_LOG_NOTICE, "Call disconnected on chan %d\n", openr2_chan_get_number(r2chan)); + + ftdm_log(FTDM_LOG_DEBUG, "Got openr2 disconnection, clearing call on channel %d\n", ftdmchan->physical_chan_id); + + R2CALL(ftdmchan)->disconnect_rcvd = 1; + + /* acknowledge the hangup, cause will be ignored. From here to -> HANGUP once the freetdm 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(ftdmchan)->ftdm_started) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + return; + } + + /* FIXME: use the cause received from openr2 and map it to ftdm cause */ + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CLEARING; + + /* notify the user of the call terminating */ + memset(&sigev, 0, sizeof(sigev)); + sigev.chan_id = ftdmchan->chan_id; + sigev.span_id = ftdmchan->span_id; + sigev.channel = ftdmchan; + sigev.event_id = FTDM_SIGEVENT_STOP; + r2data = ftdmchan->span->signal_data; + + r2data->sig_cb(&sigev); +} + +static void ftdm_r2_on_call_end(openr2_chan_t *r2chan) +{ + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_log(FTDM_LOG_NOTICE, "Call finished on chan %d\n", openr2_chan_get_number(r2chan)); + /* this means the freetdm side disconnected the call, therefore we must move to DOWN here */ + if (!R2CALL(ftdmchan)->disconnect_rcvd) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + return; + } +} + +static void ftdm_r2_on_call_read(openr2_chan_t *r2chan, const unsigned char *buf, int buflen) +{ + ftdm_log(FTDM_LOG_NOTICE, "Call read data on chan %d\n", openr2_chan_get_number(r2chan)); +} + +static void ftdm_r2_on_hardware_alarm(openr2_chan_t *r2chan, int alarm) +{ + ftdm_log(FTDM_LOG_NOTICE, "Alarm on chan %d (%d)\n", openr2_chan_get_number(r2chan), alarm); +} + +static void ftdm_r2_on_os_error(openr2_chan_t *r2chan, int errorcode) +{ + ftdm_log(FTDM_LOG_ERROR, "OS error on chan %d: %s\n", openr2_chan_get_number(r2chan), strerror(errorcode)); +} + +static void ftdm_r2_on_protocol_error(openr2_chan_t *r2chan, openr2_protocol_error_t reason) +{ + ftdm_sigmsg_t sigev; + ftdm_r2_data_t *r2data; + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + + ftdm_log(FTDM_LOG_ERROR, "Protocol error on chan %d\n", openr2_chan_get_number(r2chan)); + + R2CALL(ftdmchan)->disconnect_rcvd = 1; + + if (!R2CALL(ftdmchan)->ftdm_started) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + return; + } + + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_PROTOCOL_ERROR; + + /* notify the user of the call terminating */ + memset(&sigev, 0, sizeof(sigev)); + sigev.chan_id = ftdmchan->chan_id; + sigev.span_id = ftdmchan->span_id; + sigev.channel = ftdmchan; + sigev.event_id = FTDM_SIGEVENT_STOP; + r2data = ftdmchan->span->signal_data; + + r2data->sig_cb(&sigev); +} + +static void ftdm_r2_on_line_blocked(openr2_chan_t *r2chan) +{ + ftdm_log(FTDM_LOG_NOTICE, "Far end blocked on chan %d\n", openr2_chan_get_number(r2chan)); +} + +static void ftdm_r2_on_line_idle(openr2_chan_t *r2chan) +{ + ftdm_log(FTDM_LOG_NOTICE, "Far end unblocked on chan %d\n", openr2_chan_get_number(r2chan)); +} + +static void ftdm_r2_write_log(openr2_log_level_t level, const char *message) +{ + switch (level) { + case OR2_LOG_NOTICE: + ftdm_log(FTDM_LOG_NOTICE, "%s", message); + break; + case OR2_LOG_WARNING: + ftdm_log(FTDM_LOG_WARNING, "%s", message); + break; + case OR2_LOG_ERROR: + ftdm_log(FTDM_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: + ftdm_log(FTDM_LOG_DEBUG, "%s", message); + break; + default: + ftdm_log(FTDM_LOG_WARNING, "We should handle logging level %d here.\n", level); + ftdm_log(FTDM_LOG_DEBUG, "%s", message); + break; + } +} + +static void ftdm_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); + ftdm_r2_write_log(level, completemsg); +#undef CONTEXT_TAG +} + +static void ftdm_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); + ftdm_r2_write_log(level, completemsg); +#undef CHAN_TAG +} + +static int ftdm_r2_on_dnis_digit_received(openr2_chan_t *r2chan, char digit) +{ + ftdm_sigmsg_t sigev; + ftdm_r2_data_t *r2data; + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_size_t collected_len = R2CALL(ftdmchan)->dnis_index; + + ftdm_log(FTDM_LOG_DEBUG, "DNIS digit %d received chan %d\n", digit, openr2_chan_get_number(r2chan)); + + /* save the digit we just received */ + ftdmchan->caller_data.dnis.digits[collected_len] = digit; + collected_len++; + ftdmchan->caller_data.dnis.digits[collected_len] = '\0'; + R2CALL(ftdmchan)->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 = ftdmchan->chan_id; + sigev.span_id = ftdmchan->span_id; + sigev.channel = ftdmchan; + sigev.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT; + r2data = ftdmchan->span->signal_data; + if (r2data->sig_cb(&sigev) == FTDM_BREAK) { + ftdm_log(FTDM_LOG_NOTICE, "Requested to stop getting DNIS. Current DNIS = %s on chan %d\n", ftdmchan->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(ftdmchan->caller_data.dnis.digits) - 1)) { + ftdm_log(FTDM_LOG_NOTICE, "No more room for DNIS. Current DNIS = %s on chan %d\n", ftdmchan->caller_data.dnis.digits, openr2_chan_get_number(r2chan)); + return OR2_STOP_DNIS_REQUEST; + } + + return OR2_CONTINUE_DNIS_REQUEST; +} + +static void ftdm_r2_on_ani_digit_received(openr2_chan_t *r2chan, char digit) +{ + ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); + ftdm_size_t collected_len = R2CALL(ftdmchan)->ani_index; + + /* check if we should drop ANI */ + if (collected_len == (sizeof(ftdmchan->caller_data.ani.digits) - 1)) { + ftdm_log(FTDM_LOG_NOTICE, "No more room for ANI %c on chan %d, digit dropped.\n", digit, openr2_chan_get_number(r2chan)); + return; + } + ftdm_log(FTDM_LOG_DEBUG, "ANI digit %c received chan %d\n", digit, openr2_chan_get_number(r2chan)); + + /* save the digit we just received */ + ftdmchan->caller_data.ani.digits[collected_len++] = digit; + ftdmchan->caller_data.ani.digits[collected_len] = '\0'; +} + +static openr2_event_interface_t ftdm_r2_event_iface = { + .on_call_init = ftdm_r2_on_call_init, + .on_call_offered = ftdm_r2_on_call_offered, + .on_call_accepted = ftdm_r2_on_call_accepted, + .on_call_answered = ftdm_r2_on_call_answered, + .on_call_disconnect = ftdm_r2_on_call_disconnect, + .on_call_end = ftdm_r2_on_call_end, + .on_call_read = ftdm_r2_on_call_read, + .on_hardware_alarm = ftdm_r2_on_hardware_alarm, + .on_os_error = ftdm_r2_on_os_error, + .on_protocol_error = ftdm_r2_on_protocol_error, + .on_line_blocked = ftdm_r2_on_line_blocked, + .on_line_idle = ftdm_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)ftdm_r2_on_context_log, + .on_dnis_digit_received = ftdm_r2_on_dnis_digit_received, + .on_ani_digit_received = ftdm_r2_on_ani_digit_received, + /* so far we do nothing with billing pulses */ + .on_billing_pulse_received = NULL +}; + +static int ftdm_r2_io_set_cas(openr2_chan_t *r2chan, int cas) +{ + ftdm_channel_t *ftdm_chan = openr2_chan_get_fd(r2chan); + ftdm_status_t status = ftdm_channel_command(ftdm_chan, FTDM_COMMAND_SET_CAS_BITS, &cas); + if (FTDM_FAIL == status) { + return -1; + } + return 0; +} + +static int ftdm_r2_io_get_cas(openr2_chan_t *r2chan, int *cas) +{ + ftdm_channel_t *ftdm_chan = openr2_chan_get_fd(r2chan); + ftdm_status_t status = ftdm_channel_command(ftdm_chan, FTDM_COMMAND_GET_CAS_BITS, cas); + if (FTDM_FAIL == status) { + return -1; + } + return 0; +} + +static int ftdm_r2_io_flush_write_buffers(openr2_chan_t *r2chan) +{ + ftdm_channel_t *ftdm_chan = openr2_chan_get_fd(r2chan); + ftdm_status_t status = ftdm_channel_command(ftdm_chan, FTDM_COMMAND_FLUSH_TX_BUFFERS, NULL); + if (FTDM_FAIL == status) { + return -1; + } + return 0; +} + +static int ftdm_r2_io_write(openr2_chan_t *r2chan, const void *buf, int size) +{ + ftdm_channel_t *ftdm_chan = openr2_chan_get_fd(r2chan); + ftdm_size_t outsize = size; + ftdm_status_t status = ftdm_channel_write(ftdm_chan, (void *)buf, size, &outsize); + if (FTDM_FAIL == status) { + return -1; + } + return outsize; +} + +static int ftdm_r2_io_read(openr2_chan_t *r2chan, const void *buf, int size) +{ + ftdm_channel_t *ftdm_chan = openr2_chan_get_fd(r2chan); + ftdm_size_t outsize = size; + ftdm_status_t status = ftdm_channel_read(ftdm_chan, (void *)buf, &outsize); + if (FTDM_FAIL == status) { + return -1; + } + return outsize; +} + +static int ftdm_r2_io_wait(openr2_chan_t *r2chan, int *flags, int block) +{ + ftdm_status_t status; + ftdm_wait_flag_t ftdmflags = 0; + + ftdm_channel_t *ftdm_chan = openr2_chan_get_fd(r2chan); + int32_t timeout = block ? -1 : 0; + + if (*flags & OR2_IO_READ) { + ftdmflags |= FTDM_READ; + } + if (*flags & OR2_IO_WRITE) { + ftdmflags |= FTDM_WRITE; + } + if (*flags & OR2_IO_OOB_EVENT) { + ftdmflags |= FTDM_EVENTS; + } + + status = ftdm_channel_wait(ftdm_chan, &ftdmflags, timeout); + + if (FTDM_SUCCESS != status) { + return -1; + } + + *flags = 0; + if (ftdmflags & FTDM_READ) { + *flags |= OR2_IO_READ; + } + if (ftdmflags & FTDM_WRITE) { + *flags |= OR2_IO_WRITE; + } + if (ftdmflags & FTDM_EVENTS) { + *flags |= OR2_IO_OOB_EVENT; + } + + return 0; +} + +/* The following openr2 hooks never get called, read on for reasoning ... */ +/* since freetdm 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 ftdm_r2_io_open(openr2_context_t *r2context, int channo) +{ + ftdm_log(FTDM_LOG_ERROR, "I should not be called (I/O open)!!\n"); + return NULL; +} + +/* since freetdm takes care of closing the file descriptor and uses openr2_chan_new_from_fd, openr2 should never call this hook */ +static int ftdm_r2_io_close(openr2_chan_t *r2chan) +{ + ftdm_log(FTDM_LOG_ERROR, "I should not be called (I/O close)!!\n"); + return 0; +} + +/* since freetdm takes care of opening the file descriptor and using openr2_chan_new_from_fd, openr2 should never call this hook */ +static int ftdm_r2_io_setup(openr2_chan_t *r2chan) +{ + ftdm_log(FTDM_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 ftdm_r2_io_get_oob_event(openr2_chan_t *r2chan, openr2_oob_event_t *event) +{ + *event = 0; + ftdm_log(FTDM_LOG_ERROR, "I should not be called (I/O get oob event)!!\n"); + return 0; +} + +static openr2_io_interface_t ftdm_r2_io_iface = { + .open = ftdm_r2_io_open, /* never called */ + .close = ftdm_r2_io_close, /* never called */ + .set_cas = ftdm_r2_io_set_cas, + .get_cas = ftdm_r2_io_get_cas, + .flush_write_buffers = ftdm_r2_io_flush_write_buffers, + .write = ftdm_r2_io_write, + .read = ftdm_r2_io_read, + .setup = ftdm_r2_io_setup, /* never called */ + .wait = ftdm_r2_io_wait, + .get_oob_event = ftdm_r2_io_get_oob_event /* never called */ +}; + +static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_r2_configure_span) + //ftdm_status_t (ftdm_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; + ftdm_r2_data_t *r2data = NULL; + ftdm_r2_span_pvt_t *spanpvt = NULL; + ftdm_r2_call_t *r2call = NULL; + openr2_chan_t *r2chan = NULL; + + assert(sig_cb != NULL); + + ft_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 FTDM_FAIL; + } + + while ((var = va_arg(ap, char *))) { + ftdm_log(FTDM_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 (ftdm_strlen_zero_buf(val)) { + ftdm_log(FTDM_LOG_NOTICE, "Ignoring empty R2 variant parameter\n"); + continue; + } + r2conf.variant = openr2_proto_get_variant(val); + if (r2conf.variant == OR2_VAR_UNKNOWN) { + ftdm_log(FTDM_LOG_ERROR, "Unknown R2 variant %s\n", val); + conf_failure = 1; + break; + } + ftdm_log(FTDM_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 (ftdm_strlen_zero_buf(val)) { + ftdm_log(FTDM_LOG_NOTICE, "Ignoring empty R2 category parameter\n"); + continue; + } + r2conf.category = openr2_proto_get_category(val); + if (r2conf.category == OR2_CALLING_PARTY_CATEGORY_UNKNOWN) { + ftdm_log(FTDM_LOG_ERROR, "Unknown R2 caller category %s\n", val); + conf_failure = 1; + break; + } + ftdm_log(FTDM_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 (ftdm_strlen_zero_buf(val)) { + ftdm_log(FTDM_LOG_NOTICE, "Ignoring empty R2 logdir parameter\n"); + continue; + } + r2conf.logdir = val; + ftdm_log(FTDM_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 (ftdm_strlen_zero_buf(val)) { + ftdm_log(FTDM_LOG_NOTICE, "Ignoring empty R2 logging parameter\n"); + continue; + } + openr2_log_level_t tmplevel; + char *clevel; + char *logval = ftdm_malloc(strlen(val)+1); /* alloca man page scared me, so better to use good ol' malloc */ + if (!logval) { + ftdm_log(FTDM_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))) { + ftdm_log(FTDM_LOG_WARNING, "Ignoring invalid R2 logging level: '%s'\n", clevel); + continue; + } + r2conf.loglevel |= tmplevel; + ftdm_log(FTDM_LOG_DEBUG, "Configuring R2 span %d with loglevel %s\n", span->span_id, clevel); + } + ftdm_safe_free(logval); + } else if (!strcasecmp(var, "advanced_protocol_file")) { + if (!(val = va_arg(ap, char *))) { + break; + } + if (ftdm_strlen_zero_buf(val)) { + ftdm_log(FTDM_LOG_NOTICE, "Ignoring empty R2 advanced_protocol_file parameter\n"); + continue; + } + r2conf.advanced_protocol_file = val; + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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 FTDM_FAIL; + } + } + + if (conf_failure) { + snprintf(span->last_error, sizeof(span->last_error), "R2 configuration error"); + return FTDM_FAIL; + } + + r2data = ftdm_malloc(sizeof(*r2data)); + if (!r2data) { + snprintf(span->last_error, sizeof(span->last_error), "Failed to allocate R2 data."); + return FTDM_FAIL; + } + memset(r2data, 0, sizeof(*r2data)); + + spanpvt = ftdm_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, &ftdm_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, &ftdm_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(FTDM_MAX_CHANNELS_SPAN, ftdm_hash_hashfromstring, ftdm_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 <= FTDM_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 = ftdm_malloc(sizeof(*r2call)); + if (!r2call) { + snprintf(span->last_error, sizeof(span->last_error), "Cannot create all R2 call data structures for the span."); + ftdm_safe_free(r2chan); + goto fail; + } + memset(r2call, 0, sizeof(*r2call)); + openr2_chan_set_logging_func(r2chan, ftdm_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 = ftdm_r2_start; + r2data->flags = 0; + r2data->sig_cb = sig_cb; + span->signal_type = FTDM_SIGTYPE_R2; + span->signal_data = r2data; + span->outgoing_call = r2_outgoing_call; + + return FTDM_SUCCESS; + +fail: + + if (r2data && r2data->r2context) { + openr2_context_delete(r2data->r2context); + } + if (spanpvt && spanpvt->r2calls) { + hashtable_destroy(spanpvt->r2calls); + } + ftdm_safe_free(r2data); + ftdm_safe_free(spanpvt); + return FTDM_FAIL; + +} + +static void *ftdm_r2_channel_run(ftdm_thread_t *me, void *obj) +{ + ftdm_channel_t *closed_chan; + uint32_t interval = 0; + ftdm_sigmsg_t sigev; + ftdm_channel_t *ftdmchan = (ftdm_channel_t *)obj; + openr2_chan_t *r2chan = R2CALL(ftdmchan)->r2chan; + ftdm_r2_data_t *r2data = ftdmchan->span->signal_data; + + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INTHREAD); + + ftdm_mutex_lock(g_thread_count_mutex); + g_thread_count++; + ftdm_mutex_unlock(g_thread_count_mutex); + + ftdm_log(FTDM_LOG_DEBUG, "R2 CHANNEL thread starting on %d in state %s.\n", + ftdmchan->physical_chan_id, + ftdm_channel_state2str(ftdmchan->state)); + + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); + goto endthread; + } + + ftdm_channel_command(ftdmchan, FTDM_COMMAND_GET_INTERVAL, &interval); + + assert(interval != 0); + ftdm_log(FTDM_LOG_DEBUG, "Got %d interval for chan %d\n", interval, ftdmchan->physical_chan_id); + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + /* FIXME: is this needed? */ + memset(ftdmchan->caller_data.dnis.digits, 0, sizeof(ftdmchan->caller_data.collected)); + memset(ftdmchan->caller_data.ani.digits, 0, sizeof(ftdmchan->caller_data.collected)); + } + + memset(&sigev, 0, sizeof(sigev)); + sigev.chan_id = ftdmchan->chan_id; + sigev.span_id = ftdmchan->span_id; + sigev.channel = ftdmchan; + + while (ftdm_running()) { + int32_t read_enabled = openr2_chan_get_read_enabled(r2chan); + ftdm_wait_flag_t flags = read_enabled ? ( FTDM_READ | FTDM_WRITE ) : 0; + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE) && (R2CALL(ftdmchan)->chanstate != ftdmchan->state)) { + + ftdm_log(FTDM_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); + R2CALL(ftdmchan)->chanstate = ftdmchan->state; + + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) && !R2CALL(ftdmchan)->accepted && + (ftdmchan->state == FTDM_CHANNEL_STATE_PROGRESS || + ftdmchan->state == FTDM_CHANNEL_STATE_PROGRESS_MEDIA || + ftdmchan->state == FTDM_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 freetdm calling + openr2_chan_answer_call and openr2 accepting the call first, if freetdm calls openr2_chan_answer_call before the accept cycle + completes, openr2 will fail to answer the call */ + ftdm_log(FTDM_LOG_DEBUG, "State ack in chan %d:%d for state %s will have to wait a bit\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); + } else if (ftdmchan->state != FTDM_CHANNEL_STATE_DOWN){ + /* the down state will be completed in ftdm_channel_done below */ + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_channel_complete_state(ftdmchan); + } + + switch (ftdmchan->state) { + + /* starting an incoming call */ + case FTDM_CHANNEL_STATE_COLLECT: + { + ftdm_log(FTDM_LOG_DEBUG, "COLLECT: Starting processing of incoming call in channel %d with interval %d\n", ftdmchan->physical_chan_id, interval); + } + break; + + /* starting an outgoing call */ + case FTDM_CHANNEL_STATE_DIALING: + { + // FIXME: use user defined calling party + ftdm_channel_use(ftdmchan); + ftdm_log(FTDM_LOG_DEBUG, "DIALING: Starting processing of outgoing call in channel %d with interval %d\n", ftdmchan->physical_chan_id, interval); + if (openr2_chan_make_call(r2chan, ftdmchan->caller_data.cid_num.digits, ftdmchan->caller_data.ani.digits, OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER)) { + ftdm_log(FTDM_LOG_ERROR, "%d:%d Failed to make call in R2 channel, openr2_chan_make_call failed\n", ftdmchan->span_id, ftdmchan->chan_id); + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_DESTINATION_OUT_OF_ORDER; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + } + } + break; + + /* the call is ringing */ + case FTDM_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: + { + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + if (!R2CALL(ftdmchan)->accepted) { + ftdm_log(FTDM_LOG_DEBUG, "PROGRESS: Accepting call on channel %d\n", ftdmchan->physical_chan_id); + ft_r2_accept_call(ftdmchan); + } + } else { + ftdm_log(FTDM_LOG_DEBUG, "PROGRESS: Notifying progress in channel %d\n", ftdmchan->physical_chan_id); + sigev.event_id = FTDM_SIGEVENT_PROGRESS; + if (r2data->sig_cb(&sigev) != FTDM_SUCCESS) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + } + } + } + break; + + /* the call was answered */ + case FTDM_CHANNEL_STATE_UP: + { + ftdm_log(FTDM_LOG_DEBUG, "UP: Call was answered on channel %d\n", ftdmchan->physical_chan_id); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + if (!R2CALL(ftdmchan)->accepted) { + ftdm_log(FTDM_LOG_DEBUG, "UP: Call has not been accepted, need to accept first\n"); + // the answering will be done in the on_call_accepted handler + ft_r2_accept_call(ftdmchan); + R2CALL(ftdmchan)->answer_pending = 1; + } else { + ft_r2_answer_call(ftdmchan); + } + } else { + ftdm_log(FTDM_LOG_DEBUG, "UP: Notifying of call answered in channel %d\n", ftdmchan->physical_chan_id); + sigev.event_id = FTDM_SIGEVENT_UP; + if (r2data->sig_cb(&sigev) != FTDM_SUCCESS) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + } + } + } + break; + + /* just got hangup */ + case FTDM_CHANNEL_STATE_HANGUP: + { + /* FIXME: the cause should be retrieved from ftdmchan->caller_data.hangup_cause and translated from Q931 to R2 cause */ + ftdm_log(FTDM_LOG_DEBUG, "HANGUP: Clearing call on channel %d\n", ftdmchan->physical_chan_id); + if (!R2CALL(ftdmchan)->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 freetdm confirmation before moving to DOWN */ + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } + } + break; + + /* just got hangup from the freetdm side due to abnormal failure */ + case FTDM_CHANNEL_STATE_CANCEL: + { + ftdm_log(FTDM_LOG_DEBUG, "CANCEL: Unable to receive call on channel %d\n", ftdmchan->physical_chan_id); + openr2_chan_disconnect_call(r2chan, OR2_CAUSE_OUT_OF_ORDER); + } + break; + + /* finished call for good */ + case FTDM_CHANNEL_STATE_DOWN: + { + ftdm_log(FTDM_LOG_DEBUG, "DOWN: Placing channel %d back to the pool of available channels\n", ftdmchan->physical_chan_id); + ftdm_channel_done(ftdmchan); + goto endthread; + } + break; + + default: + { + ftdm_log(FTDM_LOG_ERROR, "%s: Unhandled channel state change in channel %d\n", ftdm_channel_state2str(ftdmchan->state), ftdmchan->physical_chan_id); + } + break; + + } + } + + if (flags) { + if (ftdm_channel_wait(ftdmchan, &flags, interval * 2) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_DEBUG, "ftdm_channel_wait did not return FTDM_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(ftdmchan)->state_ack_pending) { + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + ftdm_channel_complete_state(ftdmchan); + R2CALL(ftdmchan)->state_ack_pending = 0; + } + } else { + /* once the MF signaling has end we just loop here waiting for state changes */ + ftdm_sleep(interval); + } + + } + +endthread: + + closed_chan = ftdmchan; + ftdm_channel_close(&closed_chan); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_INTHREAD); + ftdm_log(FTDM_LOG_DEBUG, "R2 channel %d thread ended.\n", ftdmchan->physical_chan_id); + + ftdm_mutex_lock(g_thread_count_mutex); + g_thread_count--; + ftdm_mutex_unlock(g_thread_count_mutex); + + return NULL; +} + +static void *ftdm_r2_run(ftdm_thread_t *me, void *obj) +{ + openr2_chan_t *r2chan; + ftdm_status_t status; + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_r2_data_t *r2data = span->signal_data; + int waitms = 1000; + int i; + + ftdm_log(FTDM_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 (ftdm_running() && ftdm_test_flag(r2data, FTDM_R2_RUNNING)) { + status = ftdm_span_poll_event(span, waitms); + if (FTDM_FAIL == status) { + ftdm_log(FTDM_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); + continue; + } + if (FTDM_SUCCESS == status) { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { + if (event->enum_id == FTDM_OOB_CAS_BITS_CHANGE) { + r2chan = R2CALL(event->channel)->r2chan; + ftdm_log(FTDM_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 { + ftdm_log(FTDM_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 != FTDM_TIMEOUT) { + ftdm_log(FTDM_LOG_ERROR, "ftdm_span_poll_event returned %d.\n", status); + } else { + //ftdm_log(FTDM_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 freetdm caused segfault + for (i = 1; i <= span->chan_count; i++) { + r2chan = R2CALL(span->channels[i])->r2chan; + openr2_chan_set_blocked(r2chan); + } + */ + + ftdm_clear_flag(r2data, FTDM_R2_RUNNING); + ftdm_log(FTDM_LOG_DEBUG, "R2 thread ending.\n"); + + return NULL; + +} + +static ZIO_API_FUNCTION(ftdm_r2_api) +{ + char *mycmd = NULL, *argv[10] = { 0 }; + int argc = 0; + + if (data) { + mycmd = ftdm_strdup(data); + argc = ftdm_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } + + if (argc == 2) { + if (!strcasecmp(argv[0], "kill")) { + int span_id = atoi(argv[1]); + ftdm_span_t *span = NULL; + + if (ftdm_span_find_by_name(argv[1], &span) == FTDM_SUCCESS || ftdm_span_find(span_id, &span) == FTDM_SUCCESS) { + ftdm_r2_data_t *r2data = span->signal_data; + + if (span->start != ftdm_r2_start) { + stream->write_function(stream, "-ERR invalid span.\n"); + goto done; + } + + ftdm_clear_flag(r2data, FTDM_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]); + ftdm_r2_data_t *r2data = NULL; + ftdm_span_t *span = NULL; + openr2_chan_t *r2chan = NULL; + openr2_context_t *r2context = NULL; + int i = 0; + + if (ftdm_span_find_by_name(argv[1], &span) == FTDM_SUCCESS || ftdm_span_find(span_id, &span) == FTDM_SUCCESS) { + if (span->start != ftdm_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")) { + ftdm_mutex_lock(g_thread_count_mutex); + stream->write_function(stream, "%d R2 channel threads up\n", g_thread_count); + ftdm_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: + + ftdm_safe_free(mycmd); + + return FTDM_SUCCESS; + +} + +static ZIO_IO_LOAD_FUNCTION(ftdm_r2_io_init) +{ + assert(zio != NULL); + memset(&g_ftdm_r2_interface, 0, sizeof(g_ftdm_r2_interface)); + + g_ftdm_r2_interface.name = "r2"; + g_ftdm_r2_interface.api = ftdm_r2_api; + + *zio = &g_ftdm_r2_interface; + + return FTDM_SUCCESS; +} + +static ZIO_SIG_LOAD_FUNCTION(ftdm_r2_init) +{ + g_mod_data_hash = create_hashtable(10, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + if (!g_mod_data_hash) { + return FTDM_FAIL; + } + ftdm_mutex_create(&g_thread_count_mutex); + return FTDM_SUCCESS; +} + +static ZIO_SIG_UNLOAD_FUNCTION(ftdm_r2_destroy) +{ + ftdm_hash_iterator_t *i = NULL; + ftdm_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); + ftdm_mutex_destroy(&g_thread_count_mutex); + return FTDM_SUCCESS; +} + +ftdm_module_t ftdm_module = { + "r2", + ftdm_r2_io_init, + NULL, + ftdm_r2_init, + ftdm_r2_configure_span, + ftdm_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 + */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/BOOST.limitations similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/BOOST.limitations rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/BOOST.limitations diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h similarity index 81% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h index 91f54f930b..c3eb739f84 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h @@ -31,19 +31,19 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_SANGOMA_BOOST_H -#define ZAP_SANGOMA_BOOST_H +#ifndef FTDM_SANGOMA_BOOST_H +#define FTDM_SANGOMA_BOOST_H #include "sangoma_boost_client.h" -#include "openzap.h" +#include "freetdm.h" #define MAX_CHANS_PER_TRUNKGROUP 1024 typedef enum { - ZAP_SANGOMA_BOOST_RUNNING = (1 << 0), - ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1) -} zap_sangoma_boost_flag_t; + FTDM_SANGOMA_BOOST_RUNNING = (1 << 0), + FTDM_SANGOMA_BOOST_RESTARTING = (1 << 1) +} ftdm_sangoma_boost_flag_t; -typedef struct zap_sangoma_boost_data { +typedef struct ftdm_sangoma_boost_data { sangomabc_connection_t mcon; sangomabc_connection_t pcon; fd_set rfds; @@ -52,16 +52,16 @@ typedef struct zap_sangoma_boost_data { zio_signal_cb_t signal_cb; uint32_t flags; boost_sigmod_interface_t *sigmod; - zap_queue_t *boost_queue; -} zap_sangoma_boost_data_t; + ftdm_queue_t *boost_queue; +} ftdm_sangoma_boost_data_t; -typedef struct zap_sangoma_boost_trunkgroup { - zap_mutex_t *mutex; - zap_size_t size; /* Number of b-channels in group */ +typedef struct ftdm_sangoma_boost_trunkgroup { + ftdm_mutex_t *mutex; + ftdm_size_t size; /* Number of b-channels in group */ unsigned int last_used_index; /* index of last b-channel used */ - zap_channel_t* zchans[MAX_CHANS_PER_TRUNKGROUP]; + ftdm_channel_t* ftdmchans[MAX_CHANS_PER_TRUNKGROUP]; //DAVIDY need to merge congestion timeouts to this struct -} zap_sangoma_boost_trunkgroup_t; +} ftdm_sangoma_boost_trunkgroup_t; #endif /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c similarity index 51% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index cc85b0bfee..5641086b4d 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -43,28 +43,28 @@ On WIN32 platform this code works with sigmod ONLY, don't try to make sense of a I basically ifdef out everything that the compiler complained about */ -#include "openzap.h" +#include "freetdm.h" #include "sangoma_boost_client.h" -#include "zap_sangoma_boost.h" +#include "ftdm_sangoma_boost.h" #ifdef HAVE_SYS_SELECT_H #include #endif /* Boost signaling modules global hash and its mutex */ -zap_mutex_t *g_boost_modules_mutex = NULL; -zap_hash_t *g_boost_modules_hash = NULL; +ftdm_mutex_t *g_boost_modules_mutex = NULL; +ftdm_hash_t *g_boost_modules_hash = NULL; #define MAX_TRUNK_GROUPS 64 -//DAVIDY need to merge congestion_timeouts with zap_sangoma_boost_trunkgroups +//DAVIDY need to merge congestion_timeouts with ftdm_sangoma_boost_trunkgroups static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; -static zap_sangoma_boost_trunkgroup_t *g_trunkgroups[MAX_TRUNK_GROUPS]; +static ftdm_sangoma_boost_trunkgroup_t *g_trunkgroups[MAX_TRUNK_GROUPS]; #define BOOST_QUEUE_SIZE 500 -/* get openzap span and chan depending on the span mode */ -#define BOOST_SPAN(zchan) ((zap_sangoma_boost_data_t*)(zchan)->span->signal_data)->sigmod ? zchan->physical_span_id : zchan->physical_span_id-1 -#define BOOST_CHAN(zchan) ((zap_sangoma_boost_data_t*)(zchan)->span->signal_data)->sigmod ? zchan->physical_chan_id : zchan->physical_chan_id-1 +/* get freetdm span and chan depending on the span mode */ +#define BOOST_SPAN(ftdmchan) ((ftdm_sangoma_boost_data_t*)(ftdmchan)->span->signal_data)->sigmod ? ftdmchan->physical_span_id : ftdmchan->physical_span_id-1 +#define BOOST_CHAN(ftdmchan) ((ftdm_sangoma_boost_data_t*)(ftdmchan)->span->signal_data)->sigmod ? ftdmchan->physical_chan_id : ftdmchan->physical_chan_id-1 /** * \brief Strange flag @@ -94,19 +94,19 @@ typedef enum { typedef struct { sangoma_boost_request_status_t status; sangomabc_short_event_t event; - zap_span_t *span; - zap_channel_t *zchan; + ftdm_span_t *span; + ftdm_channel_t *ftdmchan; } sangoma_boost_request_t; -//#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN +//#define MAX_REQ_ID FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * FTDM_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 uint16_t SETUP_GRID[FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN+1][FTDM_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 zap_mutex_t *signal_mutex = NULL; +static ftdm_mutex_t *request_mutex = NULL; +static ftdm_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; static uint8_t nack_map[MAX_REQ_ID+1] = { 0 }; @@ -123,13 +123,13 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, { int id; - zap_mutex_lock(request_mutex); + ftdm_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); + ftdm_mutex_unlock(request_mutex); } #define release_request_id_span_chan(s, c) __release_request_id_span_chan(s, c, __FUNCTION__, __LINE__) @@ -142,9 +142,9 @@ static void __release_request_id_span_chan(int span, int chan, const char *func, 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); + ftdm_mutex_lock(request_mutex); req_map[r] = 0; - zap_mutex_unlock(request_mutex); + ftdm_mutex_unlock(request_mutex); } #define release_request_id(r) __release_request_id(r, __FUNCTION__, __LINE__) @@ -161,7 +161,7 @@ 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); + ftdm_mutex_lock(request_mutex); //r = ++last_req; //while(!r || req_map[r]) { @@ -184,7 +184,7 @@ static sangoma_boost_request_id_t __next_request_id(const char *func, int line) } - zap_mutex_unlock(request_mutex); + ftdm_mutex_unlock(request_mutex); if (!found) { return 0; @@ -201,11 +201,11 @@ static sangoma_boost_request_id_t __next_request_id(const char *func, int line) * \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) +static ftdm_channel_t *find_ftdmchan(ftdm_span_t *span, sangomabc_short_event_t *event, int force) { uint32_t i; - zap_channel_t *zchan = NULL; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_channel_t *ftdmchan = NULL; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; uint32_t targetspan = event->span+1; uint32_t targetchan = event->chan+1; if (sangoma_boost_data->sigmod) { @@ -214,15 +214,15 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even targetchan = event->chan; } - zap_mutex_lock(signal_mutex); + ftdm_mutex_lock(signal_mutex); for(i = 1; i <= span->chan_count; i++) { if (span->channels[i]->physical_span_id == targetspan && span->channels[i]->physical_chan_id == targetchan) { - zchan = span->channels[i]; - if (force || (zchan->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(zchan, ZAP_CHANNEL_INUSE))) { + ftdmchan = span->channels[i]; + if (force || (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE))) { break; } else { - zchan = NULL; - zap_log(ZAP_LOG_DEBUG, "Channel %d:%d ~ %d:%d is already in use.\n", + ftdmchan = NULL; + ftdm_log(FTDM_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, @@ -232,9 +232,9 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even } } } - zap_mutex_unlock(signal_mutex); + ftdm_mutex_unlock(signal_mutex); - return zchan; + return ftdmchan; } static int check_congestion(int trunk_group) @@ -271,7 +271,7 @@ static int boost_media_ready(sangomabc_event_t *event) } else { } } else { - zap_log(ZAP_LOG_ERROR, "Invalid boost isup_rdnis MEDIA format %s\n", p); + ftdm_log(FTDM_LOG_ERROR, "Invalid boost isup_rdnis MEDIA format %s\n", p); } } return 0; @@ -283,13 +283,13 @@ static int boost_media_ready(sangomabc_event_t *event) * \param chan_id Specific channel to get (0 for any) * \param direction Call direction * \param caller_data Caller information - * \param zchan Channel to initialise + * \param ftdmchan 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; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_status_t status = FTDM_FAIL; sangoma_boost_request_id_t r; sangomabc_event_t event = {0}; int boost_request_timeout = 5000; @@ -298,32 +298,32 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) 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; + if (ftdm_test_flag(span, FTDM_SPAN_SUSPENDED)) { + ftdm_log(FTDM_LOG_CRIT, "SPAN is not online.\n"); + *ftdmchan = NULL; + return FTDM_FAIL; } - zap_set_string(ani, caller_data->ani.digits); + ftdm_set_string(ani, caller_data->ani.digits); r = next_request_id(); if (r == 0) { - zap_log(ZAP_LOG_CRIT, "All tanks ids are busy.\n"); - *zchan = NULL; - return ZAP_FAIL; + ftdm_log(FTDM_LOG_CRIT, "All tanks ids are busy.\n"); + *ftdmchan = NULL; + return FTDM_FAIL; } sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r); if (sangoma_boost_data->sigmod) { - *zchan = span->channels[chan_id]; + *ftdmchan = span->channels[chan_id]; - event.span = (uint8_t) (*zchan)->physical_span_id; - event.chan = (uint8_t) (*zchan)->physical_chan_id; + event.span = (uint8_t) (*ftdmchan)->physical_span_id; + event.chan = (uint8_t) (*ftdmchan)->physical_chan_id; - zap_set_flag((*zchan), ZAP_CHANNEL_OUTBOUND); - zap_set_flag_locked((*zchan), ZAP_CHANNEL_INUSE); + ftdm_set_flag((*ftdmchan), FTDM_CHANNEL_OUTBOUND); + ftdm_set_flag_locked((*ftdmchan), FTDM_CHANNEL_INUSE); - OUTBOUND_REQUESTS[r].zchan = *zchan; + OUTBOUND_REQUESTS[r].ftdmchan = *ftdmchan; } else { if ((gr = strchr(ani, '@'))) { *gr++ = '\0'; @@ -338,17 +338,17 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) 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; + ftdm_log(FTDM_LOG_CRIT, "All circuits are busy. Trunk Group=%i (BOOST REQUESTED BACK OFF)\n",tg+1); + *ftdmchan = NULL; + return FTDM_FAIL; } - zap_span_channel_use_count(span, &count); + ftdm_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; + ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); + *ftdmchan = NULL; + return FTDM_FAIL; } if (gr && *(gr+1)) { @@ -366,14 +366,14 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) event.hunt_group = SIGBOOST_HUNTGRP_RR_DESC; break; default: - zap_log(ZAP_LOG_WARNING, "Failed to determine huntgroup (%s)\n", gr); + ftdm_log(FTDM_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.isup_in_rdnis, caller_data->rdnis.digits); + ftdm_set_string(event.calling_name, caller_data->cid_name); + ftdm_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); if (strlen(caller_data->rdnis.digits)) { event.isup_in_rdnis_size = (uint16_t)strlen(caller_data->rdnis.digits)+1; } @@ -385,57 +385,57 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) OUTBOUND_REQUESTS[r].span = span; if (sangomabc_connection_write(&sangoma_boost_data->mcon, &event) <= 0) { - zap_log(ZAP_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno)); - status = ZAP_FAIL; + ftdm_log(FTDM_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno)); + status = FTDM_FAIL; if (!sangoma_boost_data->sigmod) { - *zchan = NULL; + *ftdmchan = NULL; } goto done; } - while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { - zap_sleep(1); + while(ftdm_running() && OUTBOUND_REQUESTS[r].status == BST_WAITING) { + ftdm_sleep(1); if (--boost_request_timeout <= 0) { - status = ZAP_FAIL; + status = FTDM_FAIL; if (!sangoma_boost_data->sigmod) { - *zchan = NULL; + *ftdmchan = NULL; } - zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); - zap_log(ZAP_LOG_CRIT, "s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r); + ftdm_log(FTDM_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); + ftdm_log(FTDM_LOG_CRIT, "s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*ftdmchan)->physical_span_id, (*ftdmchan)->physical_chan_id, r); goto done; } } - if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].zchan) { - *zchan = OUTBOUND_REQUESTS[r].zchan; - status = ZAP_SUCCESS; - (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS; - zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); + if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].ftdmchan) { + *ftdmchan = OUTBOUND_REQUESTS[r].ftdmchan; + status = FTDM_SUCCESS; + (*ftdmchan)->init_state = FTDM_CHANNEL_STATE_PROGRESS; + ftdm_log(FTDM_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); } boost_request_timeout = 5000; - while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { - zap_sleep(1); + while(ftdm_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { + ftdm_sleep(1); if (--boost_request_timeout <= 0) { - status = ZAP_FAIL; + status = FTDM_FAIL; if (!sangoma_boost_data->sigmod) { - *zchan = NULL; + *ftdmchan = NULL; } - zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n"); + ftdm_log(FTDM_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n"); goto done; } //printf("WTF %d\n", sanity); } - if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { - *zchan = OUTBOUND_REQUESTS[r].zchan; - status = ZAP_SUCCESS; - (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; - zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); + if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].ftdmchan) { + *ftdmchan = OUTBOUND_REQUESTS[r].ftdmchan; + status = FTDM_SUCCESS; + (*ftdmchan)->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; + ftdm_log(FTDM_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); } else { - status = ZAP_FAIL; + status = FTDM_FAIL; if (!sangoma_boost_data->sigmod) { - *zchan = NULL; + *ftdmchan = NULL; } } @@ -451,8 +451,8 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) nack_map[r] = 1; if (sangoma_boost_data->sigmod) { sangomabc_exec_command(&sangoma_boost_data->mcon, - BOOST_SPAN((*zchan)), - BOOST_CHAN((*zchan)), + BOOST_SPAN((*ftdmchan)), + BOOST_CHAN((*ftdmchan)), r, SIGBOOST_EVENT_CALL_START_NACK, 0); @@ -471,12 +471,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) /** * \brief Starts an sangoma boost channel (outgoing call) - * \param zchan Channel to initiate call on + * \param ftdmchan Channel to initiate call on * \return Success */ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) { - zap_status_t status = ZAP_SUCCESS; + ftdm_status_t status = FTDM_SUCCESS; return status; } @@ -488,7 +488,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) */ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; if (nack_map[event->call_setup_id]) { return; @@ -498,7 +498,7 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e if (OUTBOUND_REQUESTS[event->call_setup_id].status == BST_ACK) { if (boost_media_ready((sangomabc_event_t*) event)) { OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; - zap_log(ZAP_LOG_DEBUG, "chan media ready %d:%d CSid:%d\n", event->span+1, event->chan+1, event->call_setup_id); + ftdm_log(FTDM_LOG_DEBUG, "chan media ready %d:%d CSid:%d\n", event->span+1, event->chan+1, event->call_setup_id); } return; } @@ -506,16 +506,16 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e OUTBOUND_REQUESTS[event->call_setup_id].event = *event; SETUP_GRID[event->span][event->chan] = event->call_setup_id; - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*) event, 0))) { - if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + if ((ftdmchan = find_ftdmchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*) event, 0))) { + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); } else { - 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 = 0; - OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); + ftdmchan->extra_id = event->call_setup_id; + ftdm_log(FTDM_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id); + ftdmchan->sflags = 0; + OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan = ftdmchan; if (boost_media_ready((sangomabc_event_t*)event)) { OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; } else { @@ -526,21 +526,21 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e } //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 ((ftdmchan = find_ftdmchan(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", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, ftdmchan->extra_id, ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), ftdm_channel_state2str(ftdmchan->state)); } - zap_log(ZAP_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - if (zchan) { - zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG); + ftdm_log(FTDM_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + if (ftdmchan) { + ftdm_set_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG); } sangomabc_exec_command(mcon, event->span, event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_STOPPED, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); + FTDM_CAUSE_DESTINATION_OUT_OF_ORDER); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; } @@ -552,7 +552,7 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; uint32_t event_span = event->span+1; uint32_t event_chan = event->chan+1; @@ -569,40 +569,40 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ SETUP_GRID[event->span][event->chan] = event->call_setup_id; if (mcon->sigmod) { - zchan = OUTBOUND_REQUESTS[event->call_setup_id].zchan; - zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); - zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); + ftdmchan = OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan; + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); } else { - zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0); + ftdmchan = find_ftdmchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0); } - if (zchan) { - if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); + if (ftdmchan) { + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); } else { - 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, event_chan, event->call_setup_id); - zchan->sflags = 0; - OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; + ftdmchan->extra_id = event->call_setup_id; + ftdm_log(FTDM_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", ftdmchan->span_id, ftdmchan->chan_id, event_span, event_chan, event->call_setup_id); + ftdmchan->sflags = 0; + OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan = ftdmchan; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; return; } } //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 ((ftdmchan = find_ftdmchan(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", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, ftdmchan->extra_id, ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), ftdm_channel_state2str(ftdmchan->state)); } - 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); + ftdm_set_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG); + ftdm_log(FTDM_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); + FTDM_CAUSE_DESTINATION_OUT_OF_ORDER); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; } @@ -612,42 +612,42 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ * \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) +static void handle_call_done(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; int r = 0; - if ((zchan = find_zchan(span, event, 1))) { - zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; - zap_mutex_lock(zchan->mutex); + if ((ftdmchan = find_ftdmchan(span, event, 1))) { + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; + ftdm_mutex_lock(ftdmchan->mutex); if (sangoma_boost_data->sigmod) { /* not really completely done, but if we ever get an incoming call before moving to HANGUP_COMPLETE * handle_incoming_call() will take care of moving the state machine to release the channel */ sangomabc_exec_command(&sangoma_boost_data->mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_RELEASED, 0); } - if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state == ZAP_CHANNEL_STATE_HANGUP_COMPLETE) { + if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN || ftdmchan->state == FTDM_CHANNEL_STATE_HANGUP_COMPLETE) { goto done; } - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE, 0, r); if (r) { - zap_set_sflag(zchan, SFLAG_FREE_REQ_ID); - zap_mutex_unlock(zchan->mutex); + ftdm_set_sflag(ftdmchan, SFLAG_FREE_REQ_ID); + ftdm_mutex_unlock(ftdmchan->mutex); return; } } done: - if (zchan) { - zap_mutex_unlock(zchan->mutex); + if (ftdmchan) { + ftdm_mutex_unlock(ftdmchan->mutex); } if (event->call_setup_id) { @@ -663,17 +663,17 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san * \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) +static void handle_call_start_nack(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_channel_t *ftdmchan; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; 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); + ftdm_span_channel_use_count(span, &count); delay = (int) (count / 100) * 2; @@ -684,7 +684,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco } if (tg < 0 || tg >= MAX_TRUNK_GROUPS) { - zap_log(ZAP_LOG_CRIT, "Invalid All Ckt Busy trunk group number %i\n", tg); + ftdm_log(FTDM_LOG_CRIT, "Invalid All Ckt Busy trunk group number %i\n", tg); tg=0; } @@ -695,7 +695,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco event->release_cause = 17; } - zap_log(ZAP_LOG_DEBUG, "setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); + ftdm_log(FTDM_LOG_DEBUG, "setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); OUTBOUND_REQUESTS[event->call_setup_id].event = *event; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; if (!sangoma_boost_data->sigmod) { @@ -708,18 +708,18 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco return; } else { - if ((zchan = find_zchan(span, event, 1))) { + if ((ftdmchan = find_ftdmchan(span, event, 1))) { int r = 0; - assert(!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)); + assert(!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)); - zchan->call_data = (void*)(intptr_t)event->event_id; + ftdmchan->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; + ftdm_mutex_lock(ftdmchan->mutex); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING, 0, r); + if (r == FTDM_STATE_CHANGE_SUCCESS) { + ftdmchan->caller_data.hangup_cause = event->release_cause; } - zap_mutex_unlock(zchan->mutex); + ftdm_mutex_unlock(ftdmchan->mutex); if (r) { return; } @@ -727,8 +727,8 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco } #if 0 - if (zchan) { - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); + if (ftdmchan) { + ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); } /* nobody else will do it so we have to do it ourselves */ @@ -741,15 +741,15 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco #endif } -static void handle_call_released(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +static void handle_call_released(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; - if ((zchan = find_zchan(span, event, 1))) { - zap_log(ZAP_LOG_DEBUG, "Releasing completely chan s%dc%d\n", event->span, event->chan); - zap_channel_done(zchan); + if ((ftdmchan = find_ftdmchan(span, event, 1))) { + ftdm_log(FTDM_LOG_DEBUG, "Releasing completely chan s%dc%d\n", event->span, event->chan); + ftdm_channel_done(ftdmchan); } else { - zap_log(ZAP_LOG_ERROR, "Odd, We could not find chan: s%dc%d to release the call completely!!\n", event->span, event->chan); + ftdm_log(FTDM_LOG_ERROR, "Odd, We could not find chan: s%dc%d to release the call completely!!\n", event->span, event->chan); } } @@ -759,46 +759,46 @@ static void handle_call_released(zap_span_t *span, sangomabc_connection_t *mcon, * \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) +static void handle_call_stop(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; - if ((zchan = find_zchan(span, event, 1))) { + if ((ftdmchan = find_ftdmchan(span, event, 1))) { int r = 0; - zap_mutex_lock(zchan->mutex); + ftdm_mutex_lock(ftdmchan->mutex); - if (zchan->state == ZAP_CHANNEL_STATE_HANGUP) { + if (ftdmchan->state == FTDM_CHANNEL_STATE_HANGUP) { /* 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, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); - zap_mutex_unlock(zchan->mutex); + ftdm_mutex_unlock(ftdmchan->mutex); return; } else { - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING, 0, r); } - if (r == ZAP_STATE_CHANGE_SUCCESS) { - zchan->caller_data.hangup_cause = event->release_cause; + if (r == FTDM_STATE_CHANGE_SUCCESS) { + ftdmchan->caller_data.hangup_cause = event->release_cause; } if (r) { - zap_set_sflag(zchan, SFLAG_FREE_REQ_ID); + ftdm_set_sflag(ftdmchan, SFLAG_FREE_REQ_ID); } - zap_mutex_unlock(zchan->mutex); + ftdm_mutex_unlock(ftdmchan->mutex); if (r) { return; } } else { /* we have to do it ourselves.... */ - zap_log(ZAP_LOG_ERROR, "Odd, We could not find chan: s%dc%d\n", event->span, event->chan); + ftdm_log(FTDM_LOG_ERROR, "Odd, We could not find chan: s%dc%d\n", event->span, event->chan); release_request_id_span_chan(event->span, event->chan); } } @@ -809,34 +809,34 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san * \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) +static void handle_call_answer(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; - if ((zchan = find_zchan(span, event, 1))) { + if ((ftdmchan = find_ftdmchan(span, event, 1))) { int r = 0; - if (zchan->extra_id == event->call_setup_id && zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_mutex_lock(zchan->mutex); - if (zchan->state == ZAP_CHANNEL_STATE_DOWN && zchan->init_state != ZAP_CHANNEL_STATE_UP) { - zchan->init_state = ZAP_CHANNEL_STATE_UP; + if (ftdmchan->extra_id == event->call_setup_id && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + ftdm_mutex_lock(ftdmchan->mutex); + if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN && ftdmchan->init_state != FTDM_CHANNEL_STATE_UP) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_UP; r = 1; } else { - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_UP, 0, r); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_UP, 0, r); } - zap_mutex_unlock(zchan->mutex); + ftdm_mutex_unlock(ftdmchan->mutex); } #if 0 if (!r) { - printf("WTF BAD ANSWER %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)); + printf("WTF BAD ANSWER %d:%d (%d:%d) CSid=%d xtra_id=%d out=%d state=%s\n", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, ftdmchan->extra_id, ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), ftdm_channel_state2str(ftdmchan->state)); } #endif } else { - zap_log(ZAP_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + ftdm_log(FTDM_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); } } -static __inline__ void advance_chan_states(zap_channel_t *zchan); +static __inline__ void advance_chan_states(ftdm_channel_t *ftdmchan); /** * \brief Handler for call start event @@ -844,66 +844,66 @@ static __inline__ void advance_chan_states(zap_channel_t *zchan); * \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) +static void handle_call_start(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_event_t *event) { - zap_channel_t *zchan; + ftdm_channel_t *ftdmchan; - if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { - if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { - zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); + if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 0))) { + if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { + ftdm_log(FTDM_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); goto error; } /* this handles race conditions where state handlers are still pending to be executed for finished calls but an incoming call arrives first, we must complete the channel states and then try again to get the - zap channel */ - advance_chan_states(zchan); - if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { - zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\n", event->span+1,event->chan+1); + ftdm channel */ + advance_chan_states(ftdmchan); + if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 0))) { + ftdm_log(FTDM_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\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); + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT, "START CANT OPEN CHAN %d:%d\n", event->span+1,event->chan+1); goto error; } - zap_log(ZAP_LOG_DEBUG, "Got call start from s%dc%d mapped to openzap logical s%dc%d, physical s%dc%d\n", + ftdm_log(FTDM_LOG_DEBUG, "Got call start from s%dc%d mapped to freetdm logical s%dc%d, physical s%dc%d\n", event->span, event->chan, - zchan->span_id, zchan->chan_id, - zchan->physical_span_id, zchan->physical_chan_id); + ftdmchan->span_id, ftdmchan->chan_id, + ftdmchan->physical_span_id, ftdmchan->physical_chan_id); - zchan->sflags = 0; - zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); - zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); + ftdmchan->sflags = 0; + ftdm_set_string(ftdmchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); + ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)event->calling_number_digits); if (strlen(event->calling_name)) { - zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_name); + ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)event->calling_name); } - zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); - zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); + ftdm_set_string(ftdmchan->caller_data.ani.digits, (char *)event->calling_number_digits); + ftdm_set_string(ftdmchan->caller_data.dnis.digits, (char *)event->called_number_digits); if (event->isup_in_rdnis_size) { char* p; //Set value of rdnis.digis in case prot daemon is still using older style RDNIS if (atoi((char *)event->isup_in_rdnis) > 0) { - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); + ftdm_set_string(ftdmchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); } p = strstr((char*)event->isup_in_rdnis,"PRI001-ANI2-"); if (p!=NULL) { int ani2 = 0; sscanf(p, "PRI001-ANI2-%d", &ani2); - snprintf(zchan->caller_data.aniII, 5, "%.2d", ani2); + snprintf(ftdmchan->caller_data.aniII, 5, "%.2d", ani2); } p = strstr((char*)event->isup_in_rdnis,"RDNIS-"); if (p!=NULL) { - sscanf(p, "RDNIS-%s", &zchan->caller_data.rdnis.digits[0]); + sscanf(p, "RDNIS-%s", &ftdmchan->caller_data.rdnis.digits[0]); } } - zchan->caller_data.screen = event->calling_number_screening_ind; - zchan->caller_data.pres = event->calling_number_presentation; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); + ftdmchan->caller_data.screen = event->calling_number_screening_ind; + ftdmchan->caller_data.pres = event->calling_number_presentation; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RING); return; error: @@ -928,7 +928,7 @@ static void handle_heartbeat(sangomabc_connection_t *mcon, sangomabc_short_event 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)); + ftdm_log(FTDM_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno)); } mcon->hb_elapsed = 0; @@ -942,9 +942,9 @@ static void handle_heartbeat(sangomabc_connection_t *mcon, sangomabc_short_event * \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) +static void handle_restart_ack(sangomabc_connection_t *mcon, ftdm_span_t *span, sangomabc_short_event_t *event) { - zap_log(ZAP_LOG_DEBUG, "RECV RESTART ACK\n"); + ftdm_log(FTDM_LOG_DEBUG, "RECV RESTART ACK\n"); } /** @@ -953,14 +953,14 @@ static void handle_restart_ack(sangomabc_connection_t *mcon, zap_span_t *span, s * \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) +static void handle_restart(sangomabc_connection_t *mcon, ftdm_span_t *span, sangomabc_short_event_t *event) { - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_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); + ftdm_set_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); + ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED); + ftdm_set_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING); mcon->hb_elapsed = 0; } @@ -971,31 +971,31 @@ static void handle_restart(sangomabc_connection_t *mcon, zap_span_t *span, sango * \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) +static void handle_incoming_digit(sangomabc_connection_t *mcon, ftdm_span_t *span, sangomabc_event_t *event) { - zap_channel_t *zchan = NULL; + ftdm_channel_t *ftdmchan = 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"); + if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t *)event, 1))) { + ftdm_log(FTDM_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", + ftdm_log(FTDM_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", + ftdm_log(FTDM_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); + ftdm_channel_queue_dtmf(ftdmchan, digits); return; } @@ -1006,12 +1006,12 @@ static void handle_incoming_digit(sangomabc_connection_t *mcon, zap_span_t *span * \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) +static int parse_sangoma_event(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_mutex_lock(signal_mutex); + ftdm_mutex_lock(signal_mutex); - if (!zap_running()) { - zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); + if (!ftdm_running()) { + ftdm_log(FTDM_LOG_WARNING, "System is shutting down.\n"); goto end; } @@ -1067,56 +1067,56 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s 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)); + ftdm_log(FTDM_LOG_WARNING, "No handler implemented for [%s]\n", sangomabc_event_id_name(event->event_id)); break; } end: - zap_mutex_unlock(signal_mutex); + ftdm_mutex_unlock(signal_mutex); return 0; } /** * \brief Handler for channel state change - * \param zchan Channel to handle + * \param ftdmchan Channel to handle */ -static __inline__ void state_advance(zap_channel_t *zchan) +static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { - zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; sangomabc_connection_t *mcon = &sangoma_boost_data->mcon; - zap_sigmsg_t sig; - zap_status_t status; + ftdm_sigmsg_t sig; + ftdm_status_t status; - zap_log(ZAP_LOG_DEBUG, "%d:%d STATE [%s]\n", zchan->span_id, zchan->chan_id, zap_channel_state2str(zchan->state)); + ftdm_log(FTDM_LOG_DEBUG, "%d:%d STATE [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; - switch (zchan->state) { - case ZAP_CHANNEL_STATE_DOWN: + switch (ftdmchan->state) { + case FTDM_CHANNEL_STATE_DOWN: { int call_stopped_ack_sent = 0; - zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; - if (zchan->extra_id) { - zchan->extra_id = 0; + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; + if (ftdmchan->extra_id) { + ftdmchan->extra_id = 0; } - if (zap_test_sflag(zchan, SFLAG_FREE_REQ_ID)) { - release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1); + if (ftdm_test_sflag(ftdmchan, SFLAG_FREE_REQ_ID)) { + release_request_id_span_chan(ftdmchan->physical_span_id-1, ftdmchan->physical_chan_id-1); } - if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); + if (!ftdm_test_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG)) { + ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); - if (zchan->call_data && ((uint32_t)(intptr_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) { + if (ftdmchan->call_data && ((uint32_t)(intptr_t)ftdmchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) { sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0); @@ -1124,39 +1124,39 @@ static __inline__ void state_advance(zap_channel_t *zchan) } else { /* we got a call stop msg, time to reply with call stopped ack */ sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); call_stopped_ack_sent = 1; } } - zchan->sflags = 0; - zchan->call_data = NULL; + ftdmchan->sflags = 0; + ftdmchan->call_data = NULL; if (sangoma_boost_data->sigmod && call_stopped_ack_sent) { - /* we dont want to call zap_channel_done just yet until call released is received */ - zap_log(ZAP_LOG_DEBUG, "Waiting for call release confirmation before declaring chan %d:%d as available \n", - zchan->span_id, zchan->chan_id); + /* we dont want to call ftdm_channel_done just yet until call released is received */ + ftdm_log(FTDM_LOG_DEBUG, "Waiting for call release confirmation before declaring chan %d:%d as available \n", + ftdmchan->span_id, ftdmchan->chan_id); } else { - zap_channel_done(zchan); + ftdm_channel_done(ftdmchan); } } break; - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - case ZAP_CHANNEL_STATE_PROGRESS: + case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: + case FTDM_CHANNEL_STATE_PROGRESS: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; + if ((status = sangoma_boost_data->signal_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { - if (!zap_test_sflag(zchan, SFLAG_SENT_ACK)) { - zap_set_sflag(zchan, SFLAG_SENT_ACK); + if (!ftdm_test_sflag(ftdmchan, SFLAG_SENT_ACK)) { + ftdm_set_sflag(ftdmchan, SFLAG_SENT_ACK); sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_ACK, 0); @@ -1164,88 +1164,88 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } break; - case ZAP_CHANNEL_STATE_RING: + case FTDM_CHANNEL_STATE_RING: { - if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_START; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_START; + if ((status = sangoma_boost_data->signal_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } } break; - case ZAP_CHANNEL_STATE_RESTART: + case FTDM_CHANNEL_STATE_RESTART: { - sig.event_id = ZAP_SIGEVENT_RESTART; + sig.event_id = FTDM_SIGEVENT_RESTART; status = sangoma_boost_data->signal_cb(&sig); - zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; - case ZAP_CHANNEL_STATE_UP: + case FTDM_CHANNEL_STATE_UP: { - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - sig.event_id = ZAP_SIGEVENT_UP; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_UP; + if ((status = sangoma_boost_data->signal_cb(&sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { - if (!(zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS) || zap_test_flag(zchan, ZAP_CHANNEL_MEDIA))) { + if (!(ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA))) { sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_ACK, 0); } sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_ANSWERED, 0); } } break; - case ZAP_CHANNEL_STATE_DIALING: + case FTDM_CHANNEL_STATE_DIALING: { } break; - case ZAP_CHANNEL_STATE_HANGUP_COMPLETE: + case FTDM_CHANNEL_STATE_HANGUP_COMPLETE: { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; - case ZAP_CHANNEL_STATE_HANGUP: + case FTDM_CHANNEL_STATE_HANGUP: { - if (zchan->last_state == ZAP_CHANNEL_STATE_TERMINATING || - zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); + if (ftdmchan->last_state == FTDM_CHANNEL_STATE_TERMINATING || + ftdm_test_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG)) { + ftdm_set_state_locked(ftdmchan, FTDM_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)) { + ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_ANSWERED) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA)) { sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_STOPPED, - zchan->caller_data.hangup_cause); + ftdmchan->caller_data.hangup_cause); } else { sangomabc_exec_command(mcon, - BOOST_SPAN(zchan), - BOOST_CHAN(zchan), + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_NACK, - zchan->caller_data.hangup_cause); + ftdmchan->caller_data.hangup_cause); } } } break; - case ZAP_CHANNEL_STATE_TERMINATING: + case FTDM_CHANNEL_STATE_TERMINATING: { - sig.event_id = ZAP_SIGEVENT_STOP; + sig.event_id = FTDM_SIGEVENT_STOP; status = sangoma_boost_data->signal_cb(&sig); } break; @@ -1254,15 +1254,15 @@ static __inline__ void state_advance(zap_channel_t *zchan) } } -static __inline__ void advance_chan_states(zap_channel_t *zchan) +static __inline__ void advance_chan_states(ftdm_channel_t *ftdmchan) { - zap_mutex_lock(zchan->mutex); - 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); + ftdm_mutex_lock(ftdmchan->mutex); + while (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + state_advance(ftdmchan); + ftdm_channel_complete_state(ftdmchan); } - zap_mutex_unlock(zchan->mutex); + ftdm_mutex_unlock(ftdmchan->mutex); } /** @@ -1278,43 +1278,43 @@ static __inline__ void init_outgoing_array(void) * \brief Checks current state on a span * \param span Span to check status on */ -static __inline__ void check_state(zap_span_t *span) +static __inline__ void check_state(ftdm_span_t *span) { - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - int susp = zap_test_flag(span, ZAP_SPAN_SUSPENDED); + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + int susp = ftdm_test_flag(span, FTDM_SPAN_SUSPENDED); - if (susp && zap_check_state_all(span, ZAP_CHANNEL_STATE_DOWN)) { + if (susp && ftdm_check_state_all(span, FTDM_CHANNEL_STATE_DOWN)) { susp = 0; } - if (zap_test_flag(span, ZAP_SPAN_STATE_CHANGE) || susp) { + if (ftdm_test_flag(span, FTDM_SPAN_STATE_CHANGE) || susp) { uint32_t j; - zap_clear_flag_locked(span, ZAP_SPAN_STATE_CHANGE); + ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE); for(j = 1; j <= span->chan_count; j++) { - if (zap_test_flag((span->channels[j]), ZAP_CHANNEL_STATE_CHANGE) || 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); + if (ftdm_test_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE) || susp) { + ftdm_mutex_lock(span->channels[j]->mutex); + ftdm_clear_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE); + if (susp && span->channels[j]->state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_channel_set_state(span->channels[j], FTDM_CHANNEL_STATE_RESTART, 0); } state_advance(span->channels[j]); - zap_channel_complete_state(span->channels[j]); - zap_mutex_unlock(span->channels[j]->mutex); + ftdm_channel_complete_state(span->channels[j]); + ftdm_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)) { + if (ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING)) { + if (ftdm_check_state_all(span, FTDM_CHANNEL_STATE_DOWN)) { sangomabc_exec_command(&sangoma_boost_data->mcon, 0, 0, -1, SIGBOOST_EVENT_SYSTEM_RESTART_ACK, 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); + ftdm_clear_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING); + ftdm_clear_flag_locked(span, FTDM_SPAN_SUSPENDED); + ftdm_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); sangoma_boost_data->mcon.hb_elapsed = 0; init_outgoing_array(); } @@ -1326,38 +1326,38 @@ static __inline__ void check_state(zap_span_t *span) * \brief Checks for events on a span * \param span Span to check for events */ -static __inline__ zap_status_t check_events(zap_span_t *span, int ms_timeout) +static __inline__ ftdm_status_t check_events(ftdm_span_t *span, int ms_timeout) { - zap_status_t status; - zap_sigmsg_t sigmsg; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_status_t status; + ftdm_sigmsg_t sigmsg; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; memset(&sigmsg, 0, sizeof(sigmsg)); - status = zap_span_poll_event(span, ms_timeout); + status = ftdm_span_poll_event(span, ms_timeout); switch(status) { - case ZAP_SUCCESS: + case FTDM_SUCCESS: { - zap_event_t *event; - while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { sigmsg.span_id = event->channel->span_id; sigmsg.chan_id = event->channel->chan_id; sigmsg.channel = event->channel; switch (event->enum_id) { - case ZAP_OOB_ALARM_TRAP: - sigmsg.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; - sigmsg.raw_data = (void *)ZAP_HW_LINK_DISCONNECTED; + case FTDM_OOB_ALARM_TRAP: + sigmsg.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; + sigmsg.raw_data = (void *)FTDM_HW_LINK_DISCONNECTED; if (sangoma_boost_data->sigmod) { - sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, ZAP_HW_LINK_DISCONNECTED); + sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, FTDM_HW_LINK_DISCONNECTED); } sangoma_boost_data->signal_cb(&sigmsg); break; - case ZAP_OOB_ALARM_CLEAR: - sigmsg.event_id = ZAP_SIGEVENT_HWSTATUS_CHANGED; - sigmsg.raw_data = (void *)ZAP_HW_LINK_CONNECTED; + case FTDM_OOB_ALARM_CLEAR: + sigmsg.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; + sigmsg.raw_data = (void *)FTDM_HW_LINK_CONNECTED; if (sangoma_boost_data->sigmod) { - sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, ZAP_HW_LINK_CONNECTED); + sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, FTDM_HW_LINK_CONNECTED); } sangoma_boost_data->signal_cb(&sigmsg); break; @@ -1365,20 +1365,20 @@ static __inline__ zap_status_t check_events(zap_span_t *span, int ms_timeout) } } break; - case ZAP_FAIL: + case FTDM_FAIL: { - if (!zap_running()) { + if (!ftdm_running()) { break; } - zap_log(ZAP_LOG_ERROR, "Boost Check Event Failure Failure: %s\n", span->last_error); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Boost Check Event Failure Failure: %s\n", span->last_error); + return FTDM_FAIL; } break; default: break; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -1386,16 +1386,16 @@ static __inline__ zap_status_t check_events(zap_span_t *span, int ms_timeout) * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) +static void *ftdm_sangoma_events_run(ftdm_thread_t *me, void *obj) { - zap_span_t *span = (zap_span_t *) obj; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_span_t *span = (ftdm_span_t *) obj; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; unsigned errs = 0; - while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && zap_running()) { - if (check_events(span,100) != ZAP_SUCCESS) { + while (ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING) && ftdm_running()) { + if (check_events(span,100) != FTDM_SUCCESS) { if (errs++ > 50) { - zap_log(ZAP_LOG_ERROR, "Too many event errors, quitting sangoma events thread\n"); + ftdm_log(FTDM_LOG_ERROR, "Too many event errors, quitting sangoma events thread\n"); return NULL; } } @@ -1404,16 +1404,16 @@ static void *zap_sangoma_events_run(zap_thread_t *me, void *obj) return NULL; } -static zap_status_t zap_boost_connection_open(zap_span_t *span) +static ftdm_status_t ftdm_boost_connection_open(ftdm_span_t *span) { - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - if (sangoma_boost_data->sigmod->start_span(span) != ZAP_SUCCESS) { - return ZAP_FAIL; + if (sangoma_boost_data->sigmod->start_span(span) != FTDM_SUCCESS) { + return FTDM_FAIL; } - 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); + ftdm_clear_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING); + ftdm_clear_flag_locked(span, FTDM_SPAN_SUSPENDED); + ftdm_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); } sangoma_boost_data->pcon = sangoma_boost_data->mcon; @@ -1424,8 +1424,8 @@ static zap_status_t zap_boost_connection_open(zap_span_t *span) 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)); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); + return FTDM_FAIL; } if (sangomabc_connection_open(&sangoma_boost_data->pcon, @@ -1433,32 +1433,32 @@ static zap_status_t zap_boost_connection_open(zap_span_t *span) ++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)); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); + return FTDM_FAIL; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /*! \brief wait for a boost event \return -1 on error, 0 on timeout, 1 when there are events */ -static int zap_boost_wait_event(zap_span_t *span, int ms) +static int ftdm_boost_wait_event(ftdm_span_t *span, int ms) { #ifndef WIN32 struct timeval tv = { 0, ms * 1000 }; sangomabc_connection_t *mcon, *pcon; int max, activity; #endif - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - zap_status_t res; - res = zap_queue_wait(sangoma_boost_data->boost_queue, ms); - if (ZAP_TIMEOUT == res) { + ftdm_status_t res; + res = ftdm_queue_wait(sangoma_boost_data->boost_queue, ms); + if (FTDM_TIMEOUT == res) { return 0; } - if (ZAP_SUCCESS != res) { + if (FTDM_SUCCESS != res) { return -1; } return 1; @@ -1490,11 +1490,11 @@ static int zap_boost_wait_event(zap_span_t *span, int ms) } -static sangomabc_event_t *zap_boost_read_event(zap_span_t *span) +static sangomabc_event_t *ftdm_boost_read_event(ftdm_span_t *span) { sangomabc_event_t *event = NULL; sangomabc_connection_t *mcon, *pcon; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; @@ -1520,12 +1520,12 @@ static sangomabc_event_t *zap_boost_read_event(zap_span_t *span) * \param me Current thread * \param obj Span to run in this thread */ -static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) +static void *ftdm_sangoma_boost_run(ftdm_thread_t *me, void *obj) { - zap_span_t *span = (zap_span_t *) obj; + ftdm_span_t *span = (ftdm_span_t *) obj; sangomabc_connection_t *mcon, *pcon; uint32_t ms = 10; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; @@ -1541,8 +1541,8 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) pcon->boost_queue = sangoma_boost_data->boost_queue; } - if (zap_boost_connection_open(span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "zap_boost_connection_open failed\n"); + if (ftdm_boost_connection_open(span) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "ftdm_boost_connection_open failed\n"); goto end; } @@ -1554,14 +1554,14 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0); - zap_set_flag(mcon, MSU_FLAG_DOWN); + ftdm_set_flag(mcon, MSU_FLAG_DOWN); } - while (zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING)) { + while (ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING)) { sangomabc_event_t *event = NULL; int activity = 0; - if (!zap_running()) { + if (!ftdm_running()) { if (!sangoma_boost_data->sigmod) { sangomabc_exec_commandp(pcon, 0, @@ -1569,19 +1569,19 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0); - zap_set_flag(mcon, MSU_FLAG_DOWN); + ftdm_set_flag(mcon, MSU_FLAG_DOWN); } - zap_log(ZAP_LOG_DEBUG, "zap is no longer running\n"); + ftdm_log(FTDM_LOG_DEBUG, "ftdm is no longer running\n"); break; } - if ((activity = zap_boost_wait_event(span, ms)) < 0) { - zap_log(ZAP_LOG_ERROR, "zap_boost_wait_event failed\n"); + if ((activity = ftdm_boost_wait_event(span, ms)) < 0) { + ftdm_log(FTDM_LOG_ERROR, "ftdm_boost_wait_event failed\n"); goto error; } if (activity) { - while ((event = zap_boost_read_event(span))) { + while ((event = ftdm_boost_read_event(span))) { parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event); sangoma_boost_data->iteration++; } @@ -1589,11 +1589,11 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) pcon->hb_elapsed += ms; - if (zap_test_flag(span, ZAP_SPAN_SUSPENDED) || zap_test_flag(mcon, MSU_FLAG_DOWN)) { + if (ftdm_test_flag(span, FTDM_SPAN_SUSPENDED) || ftdm_test_flag(mcon, MSU_FLAG_DOWN)) { pcon->hb_elapsed = 0; } - if (zap_running()) { + if (ftdm_running()) { check_state(span); } } @@ -1601,7 +1601,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) goto end; error: - zap_log(ZAP_LOG_CRIT, "Boost event processing Error!\n"); + ftdm_log(FTDM_LOG_CRIT, "Boost event processing Error!\n"); end: if (!sangoma_boost_data->sigmod) { @@ -1609,231 +1609,231 @@ end: sangomabc_connection_close(&sangoma_boost_data->pcon); } - zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); + ftdm_clear_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING); - zap_log(ZAP_LOG_DEBUG, "Sangoma Boost thread ended.\n"); + ftdm_log(FTDM_LOG_DEBUG, "Sangoma Boost thread ended.\n"); return NULL; } /** * \brief Loads sangoma boost signaling module - * \param zio Openzap IO interface + * \param zio Openftdm IO interface * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) +static ZIO_SIG_LOAD_FUNCTION(ftdm_sangoma_boost_init) { - g_boost_modules_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys); + g_boost_modules_hash = create_hashtable(10, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); if (!g_boost_modules_hash) { - return ZAP_FAIL; + return FTDM_FAIL; } - zap_mutex_create(&request_mutex); - zap_mutex_create(&signal_mutex); - zap_mutex_create(&g_boost_modules_mutex); + ftdm_mutex_create(&request_mutex); + ftdm_mutex_create(&signal_mutex); + ftdm_mutex_create(&g_boost_modules_mutex); memset(&g_trunkgroups[0], 0, sizeof(g_trunkgroups)); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -static ZIO_SIG_UNLOAD_FUNCTION(zap_sangoma_boost_destroy) +static ZIO_SIG_UNLOAD_FUNCTION(ftdm_sangoma_boost_destroy) { - zap_hash_iterator_t *i = NULL; + ftdm_hash_iterator_t *i = NULL; boost_sigmod_interface_t *sigmod = NULL; const void *key = NULL; void *val = NULL; - zap_dso_lib_t lib; + ftdm_dso_lib_t lib; for (i = hashtable_first(g_boost_modules_hash); i; i = hashtable_next(i)) { hashtable_this(i, &key, NULL, &val); if (key && val) { sigmod = val; lib = sigmod->pvt; - zap_dso_destroy(&lib); + ftdm_dso_destroy(&lib); } } hashtable_destroy(g_boost_modules_hash); - zap_mutex_destroy(&request_mutex); - zap_mutex_destroy(&signal_mutex); - zap_mutex_destroy(&g_boost_modules_mutex); - return ZAP_SUCCESS; + ftdm_mutex_destroy(&request_mutex); + ftdm_mutex_destroy(&signal_mutex); + ftdm_mutex_destroy(&g_boost_modules_mutex); + return FTDM_SUCCESS; } -static zap_status_t zap_sangoma_boost_start(zap_span_t *span) +static ftdm_status_t ftdm_sangoma_boost_start(ftdm_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); + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_set_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING); + err=ftdm_thread_create_detached(ftdm_sangoma_boost_run, span); if (err) { - zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); + ftdm_clear_flag(sangoma_boost_data, FTDM_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); + err=ftdm_thread_create_detached(ftdm_sangoma_events_run, span); if (err) { - zap_clear_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING); + ftdm_clear_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING); } return err; } -static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) +static ftdm_status_t ftdm_sangoma_boost_stop(ftdm_span_t *span) { int cnt = 10; - zap_status_t status = ZAP_SUCCESS; - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_status_t status = FTDM_SUCCESS; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (sangoma_boost_data->sigmod) { - /* FIXME: we should make sure the span thread is stopped (use pthread_kill or openzap thread kill function) */ + /* FIXME: we should make sure the span thread is stopped (use pthread_kill or freetdm thread kill function) */ /* I think stopping the span before destroying the queue makes sense otherwise may be boost events would still arrive when the queue is already destroyed! */ status = sangoma_boost_data->sigmod->stop_span(span); - zap_queue_enqueue(sangoma_boost_data->boost_queue, NULL); - while(zap_test_flag(sangoma_boost_data, ZAP_SANGOMA_BOOST_RUNNING) && cnt-- > 0) { - zap_log(ZAP_LOG_DEBUG, "Waiting for boost thread\n"); - zap_sleep(500); + ftdm_queue_enqueue(sangoma_boost_data->boost_queue, NULL); + while(ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING) && cnt-- > 0) { + ftdm_log(FTDM_LOG_DEBUG, "Waiting for boost thread\n"); + ftdm_sleep(500); } - zap_queue_destroy(&sangoma_boost_data->boost_queue); + ftdm_queue_destroy(&sangoma_boost_data->boost_queue); return status; } return status; } -static zap_state_map_t boost_state_map = { +static ftdm_state_map_t boost_state_map = { { { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_ANY_STATE}, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END} + {FTDM_ANY_STATE}, + {FTDM_CHANNEL_STATE_RESTART, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_END} + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_PROGRESS_MEDIA, ZAP_CHANNEL_STATE_PROGRESS, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_CHANNEL_STATE_UP, ZAP_END} + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_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} + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_HANGUP, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_UP, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END} + {FTDM_CHANNEL_STATE_UP, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END} }, /****************************************/ { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_ANY_STATE}, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END} + {FTDM_ANY_STATE}, + {FTDM_CHANNEL_STATE_RESTART, FTDM_END} }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, - {ZAP_CHANNEL_STATE_RING, ZAP_END} + {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_RING, FTDM_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} + {FTDM_CHANNEL_STATE_RING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_PROGRESS_MEDIA,FTDM_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}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_HANGUP, FTDM_END}, }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_DOWN, ZAP_END}, + {FTDM_CHANNEL_STATE_HANGUP_COMPLETE, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_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}, + {FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_END}, }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, - {ZAP_CHANNEL_STATE_UP, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, + {FTDM_CHANNEL_STATE_UP, FTDM_END}, + {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_END}, }, } }; -static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) +static BOOST_WRITE_MSG_FUNCTION(ftdm_boost_write_msg) { sangomabc_short_event_t *shortmsg = NULL; - zap_sangoma_boost_data_t *sangoma_boost_data = NULL; + ftdm_sangoma_boost_data_t *sangoma_boost_data = NULL; sangomabc_queue_element_t *element = NULL; - zap_assert_return(msg != NULL, ZAP_FAIL, "Boost message to write was null"); + ftdm_assert_return(msg != NULL, FTDM_FAIL, "Boost message to write was null"); if (!span) { shortmsg = msg; - zap_log(ZAP_LOG_ERROR, "Unexpected boost message %d\n", shortmsg->event_id); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Unexpected boost message %d\n", shortmsg->event_id); + return FTDM_FAIL; } /* duplicate the event and enqueue it */ - element = zap_calloc(1, sizeof(*element)); + element = ftdm_calloc(1, sizeof(*element)); if (!element) { - return ZAP_FAIL; + return FTDM_FAIL; } memcpy(element->boostmsg, msg, msglen); element->size = msglen; sangoma_boost_data = span->signal_data; - return zap_queue_enqueue(sangoma_boost_data->boost_queue, element); + return ftdm_queue_enqueue(sangoma_boost_data->boost_queue, element); } -static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) +static BOOST_SIG_STATUS_CB_FUNCTION(ftdm_boost_sig_status_change) { - zap_sigmsg_t sig; - zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; - zap_log(ZAP_LOG_NOTICE, "%d:%d Signaling link status changed to %s\n", zchan->span_id, zchan->chan_id, zap_signaling_status2str(status)); + ftdm_sigmsg_t sig; + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; + ftdm_log(FTDM_LOG_NOTICE, "%d:%d Signaling link status changed to %s\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_signaling_status2str(status)); 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_SIGSTATUS_CHANGED; + sig.chan_id = ftdmchan->chan_id; + sig.span_id = ftdmchan->span_id; + sig.channel = ftdmchan; + sig.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED; sig.raw_data = &status; sangoma_boost_data->signal_cb(&sig); return; @@ -1841,56 +1841,56 @@ static BOOST_SIG_STATUS_CB_FUNCTION(zap_boost_sig_status_change) static ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_channel_sig_status) { - zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; if (!sangoma_boost_data->sigmod) { - zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost channel with no signaling module configured\n"); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Cannot set signaling status in boost channel with no signaling module configured\n"); + return FTDM_FAIL; } if (!sangoma_boost_data->sigmod->set_channel_sig_status) { - zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost channel: method not implemented\n"); - return ZAP_NOTIMPL; + ftdm_log(FTDM_LOG_ERROR, "Cannot set signaling status in boost channel: method not implemented\n"); + return FTDM_NOTIMPL; } - return sangoma_boost_data->sigmod->set_channel_sig_status(zchan, status); + return sangoma_boost_data->sigmod->set_channel_sig_status(ftdmchan, status); } static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_channel_sig_status) { - zap_sangoma_boost_data_t *sangoma_boost_data = zchan->span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; if (!sangoma_boost_data->sigmod) { - zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost channel with no signaling module configured\n"); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Cannot get signaling status in boost channel with no signaling module configured\n"); + return FTDM_FAIL; } if (!sangoma_boost_data->sigmod->get_channel_sig_status) { - zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost channel: method not implemented\n"); - return ZAP_NOTIMPL; + ftdm_log(FTDM_LOG_ERROR, "Cannot get signaling status in boost channel: method not implemented\n"); + return FTDM_NOTIMPL; } - return sangoma_boost_data->sigmod->get_channel_sig_status(zchan, status); + return sangoma_boost_data->sigmod->get_channel_sig_status(ftdmchan, status); } static ZIO_SPAN_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_span_sig_status) { - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (!sangoma_boost_data->sigmod) { - zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost span with no signaling module configured\n"); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Cannot set signaling status in boost span with no signaling module configured\n"); + return FTDM_FAIL; } if (!sangoma_boost_data->sigmod->set_span_sig_status) { - zap_log(ZAP_LOG_ERROR, "Cannot set signaling status in boost span: method not implemented\n"); - return ZAP_NOTIMPL; + ftdm_log(FTDM_LOG_ERROR, "Cannot set signaling status in boost span: method not implemented\n"); + return FTDM_NOTIMPL; } return sangoma_boost_data->sigmod->set_span_sig_status(span, status); } static ZIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) { - zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (!sangoma_boost_data->sigmod) { - zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost span with no signaling module configured\n"); - return ZAP_FAIL; + ftdm_log(FTDM_LOG_ERROR, "Cannot get signaling status in boost span with no signaling module configured\n"); + return FTDM_FAIL; } if (!sangoma_boost_data->sigmod->get_span_sig_status) { - zap_log(ZAP_LOG_ERROR, "Cannot get signaling status in boost span: method not implemented\n"); - return ZAP_NOTIMPL; + ftdm_log(FTDM_LOG_ERROR, "Cannot get signaling status in boost span: method not implemented\n"); + return FTDM_NOTIMPL; } return sangoma_boost_data->sigmod->get_span_sig_status(span, status); } @@ -1902,35 +1902,35 @@ static ZIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) +static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) { #define FAIL_CONFIG_RETURN(retstatus) \ if (sangoma_boost_data) \ - zap_safe_free(sangoma_boost_data); \ + ftdm_safe_free(sangoma_boost_data); \ if (err) \ - zap_safe_free(err) \ + ftdm_safe_free(err) \ if (hash_locked) \ - zap_mutex_unlock(g_boost_modules_mutex); \ + ftdm_mutex_unlock(g_boost_modules_mutex); \ if (lib) \ - zap_dso_destroy(&lib); \ + ftdm_dso_destroy(&lib); \ return retstatus; boost_sigmod_interface_t *sigmod_iface = NULL; - zap_sangoma_boost_data_t *sangoma_boost_data = NULL; + ftdm_sangoma_boost_data_t *sangoma_boost_data = NULL; const char *local_ip = "127.0.0.65", *remote_ip = "127.0.0.66"; const char *sigmod = NULL; int local_port = 53000, remote_port = 53000; const char *var = NULL, *val = NULL; int hash_locked = 0; - zap_dso_lib_t lib = NULL; + ftdm_dso_lib_t lib = NULL; char path[255] = ""; char *err = NULL; unsigned paramindex = 0; - zap_status_t rc = ZAP_SUCCESS; + ftdm_status_t rc = FTDM_SUCCESS; - for (; zap_parameters[paramindex].var; paramindex++) { - var = zap_parameters[paramindex].var; - val = zap_parameters[paramindex].val; + for (; ftdm_parameters[paramindex].var; paramindex++) { + var = ftdm_parameters[paramindex].var; + val = ftdm_parameters[paramindex].val; if (!strcasecmp(var, "sigmod")) { sigmod = val; } else if (!strcasecmp(var, "local_ip")) { @@ -1943,74 +1943,74 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) remote_port = atoi(val); } else if (!sigmod) { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); - FAIL_CONFIG_RETURN(ZAP_FAIL); + FAIL_CONFIG_RETURN(FTDM_FAIL); } } if (!sigmod) { if (!local_ip && local_port && remote_ip && remote_port && sig_cb) { - zap_set_string(span->last_error, "missing Sangoma boost IP parameters"); - FAIL_CONFIG_RETURN(ZAP_FAIL); + ftdm_set_string(span->last_error, "missing Sangoma boost IP parameters"); + FAIL_CONFIG_RETURN(FTDM_FAIL); } } - sangoma_boost_data = zap_calloc(1, sizeof(*sangoma_boost_data)); + sangoma_boost_data = ftdm_calloc(1, sizeof(*sangoma_boost_data)); if (!sangoma_boost_data) { - FAIL_CONFIG_RETURN(ZAP_FAIL); + FAIL_CONFIG_RETURN(FTDM_FAIL); } /* WARNING: be sure to release this mutex on errors inside this if() */ - zap_mutex_lock(g_boost_modules_mutex); + ftdm_mutex_lock(g_boost_modules_mutex); hash_locked = 1; if (sigmod && !(sigmod_iface = hashtable_search(g_boost_modules_hash, (void *)sigmod))) { - zap_build_dso_path(sigmod, path, sizeof(path)); - lib = zap_dso_open(path, &err); + ftdm_build_dso_path(sigmod, path, sizeof(path)); + lib = ftdm_dso_open(path, &err); if (!lib) { - zap_log(ZAP_LOG_ERROR, "Error loading Sangoma boost signaling module '%s': %s\n", path, err); + ftdm_log(FTDM_LOG_ERROR, "Error loading Sangoma boost signaling module '%s': %s\n", path, err); snprintf(span->last_error, sizeof(span->last_error), "Failed to load sangoma boost signaling module %s", path); - FAIL_CONFIG_RETURN(ZAP_FAIL); + FAIL_CONFIG_RETURN(FTDM_FAIL); } - if (!(sigmod_iface = (boost_sigmod_interface_t *)zap_dso_func_sym(lib, BOOST_INTERFACE_NAME_STR, &err))) { - zap_log(ZAP_LOG_ERROR, "Failed to read Sangoma boost signaling module interface '%s': %s\n", path, err); + if (!(sigmod_iface = (boost_sigmod_interface_t *)ftdm_dso_func_sym(lib, BOOST_INTERFACE_NAME_STR, &err))) { + ftdm_log(FTDM_LOG_ERROR, "Failed to read Sangoma boost signaling module interface '%s': %s\n", path, err); snprintf(span->last_error, sizeof(span->last_error), "Failed to read Sangoma boost signaling module interface '%s': %s", path, err); - FAIL_CONFIG_RETURN(ZAP_FAIL); + FAIL_CONFIG_RETURN(FTDM_FAIL); } rc = sigmod_iface->on_load(); - if (rc != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to load Sangoma boost signaling module interface '%s': on_load method failed (%d)\n", path, rc); - FAIL_CONFIG_RETURN(ZAP_FAIL); + if (rc != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Failed to load Sangoma boost signaling module interface '%s': on_load method failed (%d)\n", path, rc); + FAIL_CONFIG_RETURN(FTDM_FAIL); } sigmod_iface->pvt = lib; - sigmod_iface->set_write_msg_cb(zap_boost_write_msg); - sigmod_iface->set_sig_status_cb(zap_boost_sig_status_change); + sigmod_iface->set_write_msg_cb(ftdm_boost_write_msg); + sigmod_iface->set_sig_status_cb(ftdm_boost_sig_status_change); hashtable_insert(g_boost_modules_hash, (void *)sigmod_iface->name, sigmod_iface, HASHTABLE_FLAG_NONE); lib = NULL; /* destroying the lib will be done when going down and NOT on FAIL_CONFIG_RETURN */ } - zap_mutex_unlock(g_boost_modules_mutex); + ftdm_mutex_unlock(g_boost_modules_mutex); hash_locked = 0; if (sigmod_iface) { /* try to create the boost queue */ - if (zap_queue_create(&sangoma_boost_data->boost_queue, BOOST_QUEUE_SIZE) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Span %s could not create its boost queue!\n", span->name); - FAIL_CONFIG_RETURN(ZAP_FAIL); + if (ftdm_queue_create(&sangoma_boost_data->boost_queue, BOOST_QUEUE_SIZE) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Span %s could not create its boost queue!\n", span->name); + FAIL_CONFIG_RETURN(FTDM_FAIL); } - zap_log(ZAP_LOG_NOTICE, "Span %s will use Sangoma Boost Signaling Module %s\n", span->name, sigmod_iface->name); + ftdm_log(FTDM_LOG_NOTICE, "Span %s will use Sangoma Boost Signaling Module %s\n", span->name, sigmod_iface->name); sangoma_boost_data->sigmod = sigmod_iface; - sigmod_iface->configure_span(span, zap_parameters); + sigmod_iface->configure_span(span, ftdm_parameters); } else { - zap_set_string(sangoma_boost_data->mcon.cfg.local_ip, local_ip); + ftdm_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); + ftdm_set_string(sangoma_boost_data->mcon.cfg.remote_ip, remote_ip); sangoma_boost_data->mcon.cfg.remote_port = remote_port; } sangoma_boost_data->signal_cb = sig_cb; - span->start = zap_sangoma_boost_start; - span->stop = zap_sangoma_boost_stop; + span->start = ftdm_sangoma_boost_start; + span->stop = ftdm_sangoma_boost_stop; span->signal_data = sangoma_boost_data; - span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; + span->signal_type = FTDM_SIGTYPE_SANGOMABOOST; span->outgoing_call = sangoma_boost_outgoing_call; span->channel_request = sangoma_boost_channel_request; span->get_channel_sig_status = sangoma_boost_get_channel_sig_status; @@ -2019,21 +2019,21 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span) span->set_span_sig_status = sangoma_boost_set_span_sig_status; span->state_map = &boost_state_map; span->suggest_chan_id = 1; - zap_set_flag_locked(span, ZAP_SPAN_SUSPENDED); - return ZAP_SUCCESS; + ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED); + return FTDM_SUCCESS; } /** - * \brief Openzap sangoma boost signaling module definition + * \brief Openftdm sangoma boost signaling module definition */ -EX_DECLARE_DATA zap_module_t zap_module = { +EX_DECLARE_DATA ftdm_module_t ftdm_module = { /*.name =*/ "sangoma_boost", /*.io_load =*/ NULL, /*.io_unload =*/ NULL, - /*.sig_load = */ zap_sangoma_boost_init, + /*.sig_load = */ ftdm_sangoma_boost_init, /*.sig_configure =*/ NULL, - /*.sig_unload = */zap_sangoma_boost_destroy, - /*.configure_span_signaling = */ zap_sangoma_boost_configure_span + /*.sig_unload = */ftdm_sangoma_boost_destroy, + /*.configure_span_signaling = */ ftdm_sangoma_boost_configure_span }; /* For Emacs: diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c similarity index 82% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c index ebd27cccac..1d026f1bf4 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c @@ -35,7 +35,7 @@ #include #endif -#include "openzap.h" +#include "freetdm.h" #include "sangoma_boost_client.h" #ifndef HAVE_GETHOSTBYNAME_R @@ -77,7 +77,7 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", + ftdm_log(file, func, line, FTDM_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", dir ? "TX":"RX", priority ? "P":"N", sangomabc_event_id_name(event->event_id), @@ -96,7 +96,7 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", + ftdm_log(file, func, line, FTDM_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", dir ? "TX":"RX", priority ? "P":"N", sangomabc_event_id_name(event->event_id), @@ -118,18 +118,18 @@ static int create_conn_socket(sangomabc_connection_t *mcon, char *local_ip, int int err = 0, local_err = 0; if (mcon->sigmod) { - zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); + ftdm_log(FTDM_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); return 0; } memset(&mcon->remote_hp, 0, sizeof(mcon->remote_hp)); memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); #ifdef HAVE_NETINET_SCTP_H - zap_log(ZAP_LOG_DEBUG, "Creating SCTP socket L=%s:%d R=%s:%d\n", + ftdm_log(FTDM_LOG_DEBUG, "Creating SCTP socket L=%s:%d R=%s:%d\n", local_ip, local_port, ip, port); mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); #else - zap_log(ZAP_LOG_DEBUG, "Creating UDP socket L=%s:%d R=%s:%d\n", + ftdm_log(FTDM_LOG_DEBUG, "Creating UDP socket L=%s:%d R=%s:%d\n", local_ip, local_port, ip, port); mcon->socket = socket(AF_INET, SOCK_DGRAM, 0); #endif @@ -187,7 +187,7 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon) { #ifndef WIN32 if (mcon->sigmod) { - zap_log(ZAP_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); + ftdm_log(FTDM_LOG_WARNING, "I should not be called on a sigmod-managed connection!\n"); return 0; } if (mcon->socket > -1) { @@ -195,9 +195,9 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon) } if (mcon->mutex) { - zap_mutex_lock(mcon->mutex); - zap_mutex_unlock(mcon->mutex); - zap_mutex_destroy(&mcon->mutex); + ftdm_mutex_lock(mcon->mutex); + ftdm_mutex_unlock(mcon->mutex); + ftdm_mutex_destroy(&mcon->mutex); } memset(mcon, 0, sizeof(*mcon)); mcon->socket = -1; @@ -207,7 +207,7 @@ int sangomabc_connection_close(sangomabc_connection_t *mcon) int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port) { - zap_mutex_create(&mcon->mutex); + ftdm_mutex_create(&mcon->mutex); if (mcon->sigmod) { /*value of mcon->socket will be ignored in sigmod mode */ return 0; @@ -242,11 +242,11 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int while (sangomabc_connection_write(mcon, (sangomabc_event_t*)&oevent) <= 0) { if (--retry <= 0) { - zap_log(ZAP_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno)); + ftdm_log(FTDM_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno)); return -1; } else { - zap_log(ZAP_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); - zap_sleep(1); + ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); + ftdm_sleep(1); } } @@ -268,11 +268,11 @@ int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, in while (sangomabc_connection_writep(pcon, (sangomabc_event_t*)&oevent) <= 0) { if (--retry <= 0) { - zap_log(ZAP_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno)); + ftdm_log(FTDM_LOG_CRIT, "Failed to tx on boost socket: %s\n", strerror(errno)); return -1; } else { - zap_log(ZAP_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); - zap_sleep(1); + ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); + ftdm_sleep(1); } } @@ -289,11 +289,11 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int sangomabc_queue_element_t *e = NULL; if (mcon->sigmod) { - e = zap_queue_dequeue(mcon->boost_queue); + e = ftdm_queue_dequeue(mcon->boost_queue); if (e) { bytes = e->size; memcpy(&mcon->event, e->boostmsg, bytes); - zap_safe_free(e); + ftdm_safe_free(e); } } #ifndef WIN32 @@ -307,7 +307,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int } if (mcon->event.version != SIGBOOST_VERSION) { - zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); + ftdm_log(FTDM_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); } /* Must check for < 0 cannot rely on bytes > MIN_SIZE_... compiler issue */ @@ -329,7 +329,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int if (mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART && mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && mcon->event.event_id != SIGBOOST_EVENT_HEARTBEAT) { - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "Not reading packets when connection is down. [%s]\n", + ftdm_log(file, func, line, FTDM_LOG_LEVEL_WARNING, "Not reading packets when connection is down. [%s]\n", sangomabc_event_id_name(mcon->event.event_id)); return NULL; } @@ -345,12 +345,12 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int /* NC: NOT USED ANY MORE */ if (mcon->rxseq_reset) { //if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { - zap_log(ZAP_LOG_DEBUG, "Rx sync ok\n"); + ftdm_log(FTDM_LOG_DEBUG, "Rx sync ok\n"); mcon->rxseq = mcon->event.fseqno; return &mcon->event; //} errno=EAGAIN; - zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n"); + ftdm_log(FTDM_LOG_DEBUG, "Waiting for rx sync...\n"); return NULL; } #endif @@ -360,7 +360,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int #if 0 if (mcon->rxseq != mcon->event.fseqno) { - zap_log(ZAP_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno); + ftdm_log(FTDM_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno); return NULL; } #endif @@ -368,7 +368,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int return &mcon->event; } else { if (iteration == 0) { - zap_log(ZAP_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + ftdm_log(FTDM_LOG_CRIT, "NC - Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); return NULL; } } @@ -397,7 +397,7 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in } if (mcon->event.version != SIGBOOST_VERSION) { - zap_log(ZAP_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); + ftdm_log(FTDM_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); } if (bytes == sizeof(sangomabc_short_event_t)) { @@ -411,7 +411,7 @@ sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, in return &mcon->event; } else { if (iteration == 0) { - zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + ftdm_log(FTDM_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); return NULL; } } @@ -425,12 +425,12 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t int err = 0; int event_size=MIN_SIZE_CALLSTART_MSG+event->isup_in_rdnis_size; - zap_assert_return(event != NULL, -1, "No event!"); - zap_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); - zap_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); + ftdm_assert_return(event != NULL, -1, "No event!"); + ftdm_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); + ftdm_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); - if (event->span >= ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN || event->chan >= ZAP_MAX_CHANNELS_PHYSICAL_SPAN ) { - zap_log(file, func, line, ZAP_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", sangomabc_event_id_name(event->event_id), event->span, event->chan); + if (event->span >= FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN || event->chan >= FTDM_MAX_CHANNELS_PHYSICAL_SPAN ) { + ftdm_log(file, func, line, FTDM_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", sangomabc_event_id_name(event->event_id), event->span, event->chan); abort(); return -1; } @@ -443,13 +443,13 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t if (event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART && event->event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && event->event_id != SIGBOOST_EVENT_HEARTBEAT) { - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "Not writing packets when connection is down. [%s]\n", + ftdm_log(file, func, line, FTDM_LOG_LEVEL_WARNING, "Not writing packets when connection is down. [%s]\n", sangomabc_event_id_name(event->event_id)); return 0; } } - zap_mutex_lock(mcon->mutex); + ftdm_mutex_lock(mcon->mutex); if (event->event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->txseq=0; mcon->rxseq=0; @@ -476,9 +476,9 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t } #endif - zap_mutex_unlock(mcon->mutex); + ftdm_mutex_unlock(mcon->mutex); - zap_assert_return(err == event_size, -1, "Failed to send the boost message completely!"); + ftdm_assert_return(err == event_size, -1, "Failed to send the boost message completely!"); return err; } @@ -490,16 +490,16 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ int event_size=sizeof(sangomabc_event_t); if (!mcon->sigmod) { - zap_assert_return(event != NULL, -1, "No event!"); - zap_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); - zap_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); + ftdm_assert_return(event != NULL, -1, "No event!"); + ftdm_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); + ftdm_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); } if (!boost_full_event(event->event_id)) { event_size=sizeof(sangomabc_short_event_t); } - zap_mutex_lock(mcon->mutex); + ftdm_mutex_lock(mcon->mutex); event->version = SIGBOOST_VERSION; if (mcon->sigmod) { mcon->sigmod->write_msg(mcon->span, event, event_size); @@ -511,9 +511,9 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ err = sendto(mcon->socket, event, event_size, 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); } #endif - zap_mutex_unlock(mcon->mutex); + ftdm_mutex_unlock(mcon->mutex); - zap_assert_return(err == event_size, -1, "Failed to send boost message completely!"); + ftdm_assert_return(err == event_size, -1, "Failed to send boost message completely!"); if (boost_full_event(event->event_id)) { sangomabc_print_event_call(mcon, event, 1, 1, file, func, line); diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h similarity index 98% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h index 24a0a5c600..9fe2145b94 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h @@ -91,14 +91,14 @@ typedef enum { struct sangomabc_connection { - zap_socket_t socket; + ftdm_socket_t socket; struct sockaddr_in local_addr; struct sockaddr_in remote_addr; sangomabc_event_t event; struct hostent remote_hp; struct hostent local_hp; unsigned int flags; - zap_mutex_t *mutex; + ftdm_mutex_t *mutex; FILE *log; unsigned int txseq; unsigned int rxseq; @@ -108,15 +108,15 @@ struct sangomabc_connection { uint32_t hb_elapsed; /* boost signaling mod interface pointer (if not working in TCP mode) */ boost_sigmod_interface_t *sigmod; - zap_queue_t *boost_queue; - zap_span_t *span; + ftdm_queue_t *boost_queue; + ftdm_span_t *span; }; typedef struct sangomabc_connection sangomabc_connection_t; typedef struct sangomabc_queue_element { unsigned char boostmsg[sizeof(sangomabc_event_t)]; - zap_size_t size; + ftdm_size_t size; } sangomabc_queue_element_t; /* disable nagle's algorythm */ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h similarity index 66% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h index 5faa474727..b555e24338 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h @@ -35,7 +35,7 @@ #ifndef SANGOMA_BOOST_INTERFACE_H #define SANGOMA_BOOST_INTERFACE_H -#include "openzap.h" +#include "freetdm.h" #ifdef __cplusplus @@ -44,28 +44,28 @@ extern "C" { /*! \brief Callback used to notify signaling status changes on a channel - \param zchan The openzap channel where the signaling status just changed + \param ftdmchan The freetdm channel where the signaling status just changed \param status The new signaling status */ -#define BOOST_SIG_STATUS_CB_ARGS (zap_channel_t *zchan, zap_signaling_status_t status) +#define BOOST_SIG_STATUS_CB_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status) typedef void (*boost_sig_status_cb_func_t) BOOST_SIG_STATUS_CB_ARGS; #define BOOST_SIG_STATUS_CB_FUNCTION(name) void name BOOST_SIG_STATUS_CB_ARGS /*! \brief Write a boost msg to a boost endpoint - \param span The openzap span where this msg was generated + \param span The freetdm span where this msg was generated \param msg The generic message pointer, owned by the caller \param msglen The length of the provided structure pointed by msg - \return ZAP_SUCCESS or ZAP_FAIL + \return FTDM_SUCCESS or FTDM_FAIL The msg buffer is owned by the caller and it should be either t_sigboost_callstart or t_sigboost_short the endpoint receiving the msg will first cast to t_sigboost_short, check the event type, and if needed. */ -#define BOOST_WRITE_MSG_ARGS (zap_span_t *span, void *msg, zap_size_t msglen) -typedef zap_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS; -#define BOOST_WRITE_MSG_FUNCTION(name) zap_status_t name BOOST_WRITE_MSG_ARGS +#define BOOST_WRITE_MSG_ARGS (ftdm_span_t *span, void *msg, ftdm_size_t msglen) +typedef ftdm_status_t (*boost_write_msg_func_t) BOOST_WRITE_MSG_ARGS; +#define BOOST_WRITE_MSG_FUNCTION(name) ftdm_status_t name BOOST_WRITE_MSG_ARGS /*! \brief Set the callback to be used by a signaling module to write boost messages @@ -80,11 +80,11 @@ typedef void (*boost_set_write_msg_cb_func_t) BOOST_SET_WRITE_MSG_CB_ARGS; /*! \brief Notify hardware status change - \param zchan The openzap channel + \param ftdmchan The freetdm channel \param status The hw status - \return ZAP_SUCCESS or ZAP_FAIL + \return FTDM_SUCCESS or FTDM_FAIL */ -#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (zap_channel_t *zchan, zap_channel_hw_link_status_t status) +#define BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS (ftdm_channel_t *ftdmchan, ftdm_channel_hw_link_status_t status) typedef void (*boost_on_hw_link_status_change_func_t) BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS; #define BOOST_ON_HW_LINK_STATUS_CHANGE_FUNCTION(name) void name BOOST_ON_HW_LINK_STATUS_CHANGE_ARGS @@ -101,84 +101,84 @@ typedef void (*boost_set_sig_status_cb_func_t) BOOST_SET_SIG_STATUS_CB_ARGS; /*! \brief Get the signaling status on the given channel. - \param zchan The openzap channel + \param ftdmchan The freetdm channel \param status The status pointer where the current signaling status will be set */ -#define BOOST_GET_CHANNEL_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t *status) -typedef zap_status_t (*boost_get_channel_sig_status_func_t) BOOST_GET_CHANNEL_SIG_STATUS_ARGS; -#define BOOST_GET_CHANNEL_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_CHANNEL_SIG_STATUS_ARGS +#define BOOST_GET_CHANNEL_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status) +typedef ftdm_status_t (*boost_get_channel_sig_status_func_t) BOOST_GET_CHANNEL_SIG_STATUS_ARGS; +#define BOOST_GET_CHANNEL_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_GET_CHANNEL_SIG_STATUS_ARGS /*! \brief Set the signaling status on the given channel. - \param zchan The openzap channel + \param ftdmchan The freetdm channel \param status The new status for the channel - \return ZAP_SUCCESS or ZAP_FAIL + \return FTDM_SUCCESS or FTDM_FAIL */ -#define BOOST_SET_CHANNEL_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t status) -typedef zap_status_t (*boost_set_channel_sig_status_func_t) BOOST_SET_CHANNEL_SIG_STATUS_ARGS; -#define BOOST_SET_CHANNEL_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_CHANNEL_SIG_STATUS_ARGS +#define BOOST_SET_CHANNEL_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status) +typedef ftdm_status_t (*boost_set_channel_sig_status_func_t) BOOST_SET_CHANNEL_SIG_STATUS_ARGS; +#define BOOST_SET_CHANNEL_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_SET_CHANNEL_SIG_STATUS_ARGS /*! \brief Get the signaling status on the given span. - \param span The openzap span + \param span The freetdm span \param status The status pointer where the current signaling status will be set */ -#define BOOST_GET_SPAN_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t *status) -typedef zap_status_t (*boost_get_span_sig_status_func_t) BOOST_GET_SPAN_SIG_STATUS_ARGS; -#define BOOST_GET_SPAN_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_GET_SPAN_SIG_STATUS_ARGS +#define BOOST_GET_SPAN_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t *status) +typedef ftdm_status_t (*boost_get_span_sig_status_func_t) BOOST_GET_SPAN_SIG_STATUS_ARGS; +#define BOOST_GET_SPAN_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_GET_SPAN_SIG_STATUS_ARGS /*! \brief Set the signaling status on the given span. - \param zchan The openzap span + \param ftdmchan The freetdm span \param status The new status for the span - \return ZAP_SUCCESS or ZAP_FAIL + \return FTDM_SUCCESS or FTDM_FAIL */ -#define BOOST_SET_SPAN_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t status) -typedef zap_status_t (*boost_set_span_sig_status_func_t) BOOST_SET_SPAN_SIG_STATUS_ARGS; -#define BOOST_SET_SPAN_SIG_STATUS_FUNCTION(name) zap_status_t name BOOST_SET_SPAN_SIG_STATUS_ARGS +#define BOOST_SET_SPAN_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status) +typedef ftdm_status_t (*boost_set_span_sig_status_func_t) BOOST_SET_SPAN_SIG_STATUS_ARGS; +#define BOOST_SET_SPAN_SIG_STATUS_FUNCTION(name) ftdm_status_t name BOOST_SET_SPAN_SIG_STATUS_ARGS /*! \brief Configure the given span signaling - \param span The openzap span + \param span The freetdm span \param parameters The array of configuration key,value pairs (must be null terminated) - \return ZAP_SUCCESS or ZAP_FAIL + \return FTDM_SUCCESS or FTDM_FAIL */ -#define BOOST_CONFIGURE_SPAN_ARGS (zap_span_t *span, zap_conf_parameter_t *parameters) -typedef zap_status_t (*boost_configure_span_func_t) BOOST_CONFIGURE_SPAN_ARGS; -#define BOOST_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name BOOST_CONFIGURE_SPAN_ARGS +#define BOOST_CONFIGURE_SPAN_ARGS (ftdm_span_t *span, ftdm_conf_parameter_t *parameters) +typedef ftdm_status_t (*boost_configure_span_func_t) BOOST_CONFIGURE_SPAN_ARGS; +#define BOOST_CONFIGURE_SPAN_FUNCTION(name) ftdm_status_t name BOOST_CONFIGURE_SPAN_ARGS /*! \brief Start the given span - \param span The openzap span - \return ZAP_SUCCESS or ZAP_FAIL + \param span The freetdm span + \return FTDM_SUCCESS or FTDM_FAIL */ -#define BOOST_START_SPAN_ARGS (zap_span_t *span) -typedef zap_status_t (*boost_start_span_func_t) BOOST_START_SPAN_ARGS; -#define BOOST_START_SPAN_FUNCTION(name) zap_status_t name BOOST_START_SPAN_ARGS +#define BOOST_START_SPAN_ARGS (ftdm_span_t *span) +typedef ftdm_status_t (*boost_start_span_func_t) BOOST_START_SPAN_ARGS; +#define BOOST_START_SPAN_FUNCTION(name) ftdm_status_t name BOOST_START_SPAN_ARGS /*! \brief Stop the given span - \param span The openzap span - \return ZAP_SUCCESS or ZAP_FAIL + \param span The freetdm span + \return FTDM_SUCCESS or FTDM_FAIL */ -#define BOOST_STOP_SPAN_ARGS (zap_span_t *span) -typedef zap_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; -#define BOOST_STOP_SPAN_FUNCTION(name) zap_status_t name BOOST_STOP_SPAN_ARGS +#define BOOST_STOP_SPAN_ARGS (ftdm_span_t *span) +typedef ftdm_status_t (*boost_stop_span_func_t) BOOST_START_SPAN_ARGS; +#define BOOST_STOP_SPAN_FUNCTION(name) ftdm_status_t name BOOST_STOP_SPAN_ARGS /*! \brief Called when the module is being loaded BEFORE calling anything else - \return ZAP_SUCCESS or ZAP_FAIL + \return FTDM_SUCCESS or FTDM_FAIL */ #define BOOST_ON_LOAD_ARGS (void) -typedef zap_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; -#define BOOST_ON_LOAD_FUNCTION(name) zap_status_t name BOOST_ON_LOAD_ARGS +typedef ftdm_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; +#define BOOST_ON_LOAD_FUNCTION(name) ftdm_status_t name BOOST_ON_LOAD_ARGS /*! \brief Called when the module is being unloaded, last chance to stop everything! */ #define BOOST_ON_UNLOAD_ARGS (void) -typedef zap_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; -#define BOOST_ON_UNLOAD_FUNCTION(name) zap_status_t name BOOST_ON_UNLOAD_ARGS +typedef ftdm_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; +#define BOOST_ON_UNLOAD_FUNCTION(name) ftdm_status_t name BOOST_ON_UNLOAD_ARGS /*! \brief The boost signaling module interface @@ -204,9 +204,9 @@ typedef struct boost_sigmod_interface_s { boost_on_hw_link_status_change_func_t on_hw_link_status_change; /*! \brief configure span signaling */ boost_configure_span_func_t configure_span; - /*! \brief start openzap span */ + /*! \brief start freetdm span */ boost_start_span_func_t start_span; - /*! \brief stop openzap span */ + /*! \brief stop freetdm span */ boost_stop_span_func_t stop_span; /*! \brief the module was just loaded */ boost_on_load_func_t on_load; diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h similarity index 97% rename from libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h index b9cbf110f6..37a3803faa 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h @@ -17,7 +17,7 @@ #define SIGBOOST_VERSION 100 // handy to define integer types that actually work on both Lin and Win -#include +#include enum e_sigboost_event_id_values { @@ -30,11 +30,11 @@ enum e_sigboost_event_id_values SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ /* CALL_RELEASED is aimed to fix a race condition that became obvious * when the boost socket was replaced by direct function calls - * and the channel hunting was moved to openzap, the problem is + * and the channel hunting was moved to freetdm, the problem is * we can get CALL_STOPPED msg and reply with CALL_STOPPED_ACK * but the signaling module will still (in PRI) send RELEASE and * wait for RELEASE_COMPLETE from the isdn network before - * marking the channel as available, therefore openzap should + * marking the channel as available, therefore freetdm should * also not mark the channel as available until CALL_RELEASED * is received, for socket mode we can continue working as usual * with CALL_STOPPED being the last step because the hunting is diff --git a/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c b/libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c similarity index 88% rename from libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c rename to libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c index 949e0fbf31..ca01ed1bcc 100644 --- a/libs/freetdm/src/ozmod/ozmod_skel/ozmod_skel.c +++ b/libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c @@ -32,75 +32,75 @@ */ -#include "openzap.h" -//#include "zap_skel.h" +#include "freetdm.h" +//#include "ftdm_skel.h" static ZIO_CONFIGURE_FUNCTION(skel_configure) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_OPEN_FUNCTION(skel_open) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_CLOSE_FUNCTION(skel_close) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_WAIT_FUNCTION(skel_wait) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_READ_FUNCTION(skel_read) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_WRITE_FUNCTION(skel_write) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_COMMAND_FUNCTION(skel_command) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_SPAN_POLL_EVENT_FUNCTION(skel_poll_event) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_SPAN_NEXT_EVENT_FUNCTION(skel_next_event) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy) { - return ZAP_FAIL; + return FTDM_FAIL; } static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) { - return ZAP_FAIL; + return FTDM_FAIL; } -static zap_io_interface_t skel_interface; +static ftdm_io_interface_t skel_interface; static ZIO_IO_LOAD_FUNCTION(skel_init) { @@ -123,16 +123,16 @@ static ZIO_IO_LOAD_FUNCTION(skel_init) skel_interface.get_alarms = skel_get_alarms; *zio = &skel_interface; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } static ZIO_IO_UNLOAD_FUNCTION(skel_destroy) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } -zap_module_t zap_module = { +ftdm_module_t ftdm_module = { "skel", skel_init, skel_destroy, diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c similarity index 58% rename from libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c rename to libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 713e72498b..aebf4735c9 100644 --- a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -42,7 +42,7 @@ #include #include #endif -#include "openzap.h" +#include "freetdm.h" #ifndef __WINDOWS__ #include #include @@ -114,14 +114,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); * 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) +static __inline__ int tdmv_api_wait_socket(ftdm_channel_t *ftdmchan, 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; + sangoma_wait_obj_t *sangoma_wait_obj = ftdmchan->mod_data; err = sangoma_waitfor(sangoma_wait_obj, inflags, &outflags, timeout); *flags = 0; @@ -138,7 +138,7 @@ static __inline__ int tdmv_api_wait_socket(zap_channel_t *zchan, int timeout, in int res; memset(&pfds[0], 0, sizeof(pfds[0])); - pfds[0].fd = zchan->sockfd; + pfds[0].fd = ftdmchan->sockfd; pfds[0].events = *flags; res = poll(pfds, 1, timeout); *flags = 0; @@ -174,7 +174,7 @@ static __inline__ sng_fd_t __tdmv_api_open_span_chan(int span, int chan) } #endif -static zap_io_interface_t wanpipe_interface; +static ftdm_io_interface_t wanpipe_interface; /** * \brief Inverts bit string @@ -201,17 +201,17 @@ static unsigned char wanpipe_swap_bits(unsigned char cas_bits) /** * \brief Initialises a range of wanpipe channels - * \param span Openzap span + * \param span Openftdm 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 type Openftdm channel type + * \param name Openftdm span name + * \param number Openftdm 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) +static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start, unsigned end, ftdm_chan_type_t type, char *name, char *number, unsigned char cas_bits) { unsigned configured = 0, x; #ifdef LIBSANGOMA_VERSION @@ -219,39 +219,39 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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); + if (type == FTDM_CHAN_TYPE_CAS) { + ftdm_log(FTDM_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 = WP_INVALID_SOCKET; + ftdm_channel_t *chan; + ftdm_socket_t sockfd = WP_INVALID_SOCKET; const char *dtmf = "none"; - if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == ZAP_TRUNK_T1 && x == 24) { + if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == FTDM_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); + ftdm_log(FTDM_LOG_ERROR, "span %d channel %d cannot be configured as smg_prid_nfas, you need to compile freetdm with newer libsangoma\n", spanno, x); #endif } else { sockfd = tdmv_api_open_span_chan(spanno, x); } if (sockfd == WP_INVALID_SOCKET) { - zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x); + ftdm_log(FTDM_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) { + if (ftdm_span_add_channel(span, sockfd, type, &chan) == FTDM_SUCCESS) { wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); #ifdef LIBSANGOMA_VERSION /* we need SANGOMA_DEVICE_WAIT_OBJ_SIG and not SANGOMA_DEVICE_WAIT_OBJ alone because we need to call - * sangoma_wait_obj_sig to wake up any I/O waiters when closing the channel (typically on zap shutdown) + * sangoma_wait_obj_sig to wake up any I/O waiters when closing the channel (typically on ftdm shutdown) * this adds an extra pair of file descriptors to the waitable object * */ sangstatus = sangoma_wait_obj_create(&sangoma_wait_obj, sockfd, SANGOMA_DEVICE_WAIT_OBJ_SIG); if (sangstatus != SANG_STATUS_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "failure create waitable object for s%dc%d\n", spanno, x); + ftdm_log(FTDM_LOG_ERROR, "failure create waitable object for s%dc%d\n", spanno, x); continue; } chan->mod_data = sangoma_wait_obj; @@ -261,7 +261,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, chan->physical_chan_id = x; chan->rate = 8000; - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) { + if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO || type == FTDM_CHAN_TYPE_B) { int err; dtmf = "software"; @@ -270,34 +270,34 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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; + chan->native_codec = chan->effective_codec = FTDM_CODEC_ALAW; } else { - chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW; + chan->native_codec = chan->effective_codec = FTDM_CODEC_ULAW; } //err = sangoma_tdm_get_hw_dtmf(chan->sockfd, &tdm_api); //if (err > 0) { err = sangoma_tdm_enable_dtmf_events(chan->sockfd, &tdm_api); if (err == 0) { - zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_DETECT); + ftdm_channel_set_feature(chan, FTDM_CHANNEL_FEATURE_DTMF_DETECT); dtmf = "hardware"; } //} } #if 0 - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_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); + ftdm_log(FTDM_LOG_ERROR, "flash enabled s%dc%d\n", spanno, x); } else { - zap_log(ZAP_LOG_ERROR, "flash disabled s%dc%d\n", spanno, x); + ftdm_log(FTDM_LOG_ERROR, "flash disabled s%dc%d\n", spanno, x); } } #endif - if (type == ZAP_CHAN_TYPE_CAS || type == ZAP_CHAN_TYPE_EM) { + if (type == FTDM_CHAN_TYPE_CAS || type == FTDM_CHAN_TYPE_EM) { #ifdef LIBSANGOMA_VERSION sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id, wanpipe_swap_bits(cas_bits)); @@ -305,7 +305,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, 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); + ftdm_log(FTDM_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 */ @@ -318,7 +318,7 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, * 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); + ftdm_log(FTDM_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); @@ -326,19 +326,19 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, #endif } - if (!zap_strlen_zero(name)) { - zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); + if (!ftdm_strlen_zero(name)) { + ftdm_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)); + if (!ftdm_strlen_zero(number)) { + ftdm_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", + ftdm_log(FTDM_LOG_INFO, "configuring device s%dc%d as OpenFTDM 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); + ftdm_log(FTDM_LOG_ERROR, "ftdm_span_add_channel failed for wanpipe span %d channel %d\n", spanno, x); } } @@ -361,37 +361,37 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) 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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_WARNING, "invalid flash ms at line %d\n", lineno); } else { wp_globals.flash_ms = num; } } } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Initialises an openzap Wanpipe span from a configuration string - * \param span Openzap span + * \brief Initialises an freetdm Wanpipe span from a configuration string + * \param span Openftdm span * \param str Configuration string - * \param type Openzap span type - * \param name Openzap span name - * \param number Openzap span number + * \param type Openftdm span type + * \param name Openftdm span name + * \param number Openftdm span number * \return Success or failure */ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) @@ -408,11 +408,11 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) assert(str != NULL); - mydata = zap_strdup(str); + mydata = ftdm_strdup(str); assert(mydata != NULL); - items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); + items = ftdm_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); for(i = 0; i < items; i++) { sp = item_list[i]; @@ -421,7 +421,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) } if (!(sp && ch)) { - zap_log(ZAP_LOG_ERROR, "No valid wanpipe span and channel was specified\n"); + ftdm_log(FTDM_LOG_ERROR, "No valid wanpipe span and channel was specified\n"); continue; } @@ -429,12 +429,12 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) spanno = atoi(sp); if (channo < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid channel number %d\n", channo); + ftdm_log(FTDM_LOG_ERROR, "Invalid channel number %d\n", channo); continue; } if (spanno < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid span number %d\n", channo); + ftdm_log(FTDM_LOG_ERROR, "Invalid span number %d\n", channo); continue; } @@ -447,25 +447,25 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) if (top < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); + ftdm_log(FTDM_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"); + if (FTDM_CHAN_TYPE_CAS == type && ftdm_config_get_cas_bits(ch, &cas_bits)) { + ftdm_log(FTDM_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); } - zap_safe_free(mydata); + ftdm_safe_free(mydata); return configured; } /** * \brief Opens Wanpipe channel - * \param zchan Channel to open + * \param ftdmchan Channel to open * \return Success or failure */ static ZIO_OPEN_FUNCTION(wanpipe_open) @@ -475,40 +475,40 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) memset(&tdm_api,0,sizeof(tdm_api)); - if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921 || ftdmchan->type == FTDM_CHAN_TYPE_DQ931) { + ftdmchan->native_codec = ftdmchan->effective_codec = FTDM_CODEC_NONE; } else { - zchan->effective_codec = zchan->native_codec; + ftdmchan->effective_codec = ftdmchan->native_codec; - sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, wp_globals.codec_ms); + sangoma_tdm_set_usr_period(ftdmchan->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; + ftdm_channel_set_feature(ftdmchan, FTDM_CHANNEL_FEATURE_INTERVAL); + ftdmchan->effective_interval = ftdmchan->native_interval = wp_globals.codec_ms; + ftdmchan->packet_len = ftdmchan->native_interval * 8; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Closes Wanpipe channel - * \param zchan Channel to close + * \param ftdmchan Channel to close * \return Success */ static ZIO_CLOSE_FUNCTION(wanpipe_close) { #ifdef LIBSANGOMA_VERSION - sangoma_wait_obj_t *waitobj = zchan->mod_data; + sangoma_wait_obj_t *waitobj = ftdmchan->mod_data; /* kick any I/O waiters */ sangoma_wait_obj_signal(waitobj); #endif - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Executes an Openzap command on a Wanpipe channel - * \param zchan Channel to execute command on - * \param command Openzap command to execute + * \brief Executes an Openftdm command on a Wanpipe channel + * \param ftdmchan Channel to execute command on + * \param command Openftdm command to execute * \param obj Object (unused) * \return Success or failure */ @@ -520,110 +520,110 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) memset(&tdm_api, 0, sizeof(tdm_api)); switch(command) { - case ZAP_COMMAND_OFFHOOK: + case FTDM_COMMAND_OFFHOOK: { - err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); + err=sangoma_tdm_txsig_offhook(ftdmchan->sockfd,&tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "OFFHOOK Failed"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "OFFHOOK Failed"); + return FTDM_FAIL; } - zap_set_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); } break; - case ZAP_COMMAND_ONHOOK: + case FTDM_COMMAND_ONHOOK: { - err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + err=sangoma_tdm_txsig_onhook(ftdmchan->sockfd,&tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "ONHOOK Failed"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ONHOOK Failed"); + return FTDM_FAIL; } - zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); } break; - case ZAP_COMMAND_GENERATE_RING_ON: + case FTDM_COMMAND_GENERATE_RING_ON: { - err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); + err=sangoma_tdm_txsig_start(ftdmchan->sockfd,&tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Ring Failed"); + return FTDM_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; + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_RINGING); + ftdm_set_pflag_locked(ftdmchan, WP_RINGING); + ftdmchan->ring_time = ftdm_current_time_in_ms() + wp_globals.ring_on_ms; } break; - case ZAP_COMMAND_GENERATE_RING_OFF: + case FTDM_COMMAND_GENERATE_RING_OFF: { - err=sangoma_tdm_txsig_offhook(zchan->sockfd,&tdm_api); + err=sangoma_tdm_txsig_offhook(ftdmchan->sockfd,&tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Ring-off Failed"); + return FTDM_FAIL; } - zap_clear_pflag_locked(zchan, WP_RINGING); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); + ftdm_clear_pflag_locked(ftdmchan, WP_RINGING); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_RINGING); } break; - case ZAP_COMMAND_GET_INTERVAL: + case FTDM_COMMAND_GET_INTERVAL: { - err=sangoma_tdm_get_usr_period(zchan->sockfd, &tdm_api); + err=sangoma_tdm_get_usr_period(ftdmchan->sockfd, &tdm_api); if (err > 0 ) { - ZAP_COMMAND_OBJ_INT = err; + FTDM_COMMAND_OBJ_INT = err; err=0; } } break; - case ZAP_COMMAND_ENABLE_ECHOCANCEL: + case FTDM_COMMAND_ENABLE_ECHOCANCEL: { //code me } break; - case ZAP_COMMAND_DISABLE_ECHOCANCEL: + case FTDM_COMMAND_DISABLE_ECHOCANCEL: { //code me } break; - case ZAP_COMMAND_SET_INTERVAL: + case FTDM_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); + err=sangoma_tdm_set_usr_period(ftdmchan->sockfd, &tdm_api, FTDM_COMMAND_OBJ_INT); + ftdmchan->packet_len = ftdmchan->native_interval * (ftdmchan->effective_codec == FTDM_CODEC_SLIN ? 16 : 8); } break; - case ZAP_COMMAND_SET_CAS_BITS: + case FTDM_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)); + err = sangoma_tdm_write_rbs(ftdmchan->sockfd,&tdm_api, ftdmchan->physical_chan_id, wanpipe_swap_bits(FTDM_COMMAND_OBJ_INT)); #else - err = sangoma_tdm_write_rbs(zchan->sockfd, &tdm_api, wanpipe_swap_bits(ZAP_COMMAND_OBJ_INT)); + err = sangoma_tdm_write_rbs(ftdmchan->sockfd, &tdm_api, wanpipe_swap_bits(FTDM_COMMAND_OBJ_INT)); #endif } break; - case ZAP_COMMAND_GET_CAS_BITS: + case FTDM_COMMAND_GET_CAS_BITS: { #ifdef LIBSANGOMA_VERSION unsigned char rbsbits; - err = sangoma_tdm_read_rbs(zchan->sockfd, &tdm_api, zchan->physical_chan_id, &rbsbits); + err = sangoma_tdm_read_rbs(ftdmchan->sockfd, &tdm_api, ftdmchan->physical_chan_id, &rbsbits); if (!err) { - ZAP_COMMAND_OBJ_INT = wanpipe_swap_bits(rbsbits); + FTDM_COMMAND_OBJ_INT = wanpipe_swap_bits(rbsbits); } #else // does sangoma_tdm_read_rbs is available here? - ZAP_COMMAND_OBJ_INT = zchan->rx_cas_bits; + FTDM_COMMAND_OBJ_INT = ftdmchan->rx_cas_bits; #endif } break; - case ZAP_COMMAND_SET_LINK_STATUS: + case FTDM_COMMAND_SET_LINK_STATUS: { - zap_channel_hw_link_status_t status = ZAP_COMMAND_OBJ_INT; - char sangoma_status = status == ZAP_HW_LINK_CONNECTED ? FE_CONNECTED : FE_DISCONNECTED; - err = sangoma_tdm_set_fe_status(zchan->sockfd, &tdm_api, sangoma_status); + ftdm_channel_hw_link_status_t status = FTDM_COMMAND_OBJ_INT; + char sangoma_status = status == FTDM_HW_LINK_CONNECTED ? FE_CONNECTED : FE_DISCONNECTED; + err = sangoma_tdm_set_fe_status(ftdmchan->sockfd, &tdm_api, sangoma_status); } break; - case ZAP_COMMAND_GET_LINK_STATUS: + case FTDM_COMMAND_GET_LINK_STATUS: { unsigned char sangoma_status = 0; - err = sangoma_tdm_get_fe_status(zchan->sockfd, &tdm_api, &sangoma_status); + err = sangoma_tdm_get_fe_status(ftdmchan->sockfd, &tdm_api, &sangoma_status); if (!err) { - ZAP_COMMAND_OBJ_INT = sangoma_status == FE_CONNECTED ? ZAP_HW_LINK_CONNECTED : ZAP_HW_LINK_DISCONNECTED; + FTDM_COMMAND_OBJ_INT = sangoma_status == FE_CONNECTED ? FTDM_HW_LINK_CONNECTED : FTDM_HW_LINK_DISCONNECTED; } } break; @@ -632,17 +632,17 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) }; if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + return FTDM_FAIL; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Reads data from a Wanpipe channel - * \param zchan Channel to read from + * \param ftdmchan Channel to read from * \param data Data buffer * \param datalen Size of data buffer * \return Success, failure or timeout @@ -654,25 +654,25 @@ static ZIO_READ_FUNCTION(wanpipe_read) memset(&hdrframe, 0, sizeof(hdrframe)); - rx_len = sangoma_readmsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); + rx_len = sangoma_readmsg_tdm(ftdmchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); *datalen = rx_len; if (rx_len == 0 || rx_len == -17) { - return ZAP_TIMEOUT; + return FTDM_TIMEOUT; } if (rx_len < 0) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + return FTDM_FAIL; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Writes data to a Wanpipe channel - * \param zchan Channel to write to + * \param ftdmchan Channel to write to * \param data Data buffer * \param datalen Size of data buffer * \return Success or failure @@ -684,20 +684,20 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) /* Do we even need the headerframe here? on windows, we don't even pass it to the driver */ memset(&hdrframe, 0, sizeof(hdrframe)); - bsent = sangoma_writemsg_tdm(zchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen),0); + bsent = sangoma_writemsg_tdm(ftdmchan->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 FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } /** * \brief Waits for an event on a Wanpipe channel - * \param zchan Channel to open + * \param ftdmchan Channel to open * \param flags Type of event to wait for * \param to Time to wait (in ms) * \return Success, failure or timeout @@ -708,44 +708,44 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) int32_t inflags = 0; int result; - if (*flags & ZAP_READ) { + if (*flags & FTDM_READ) { inflags |= POLLIN; } - if (*flags & ZAP_WRITE) { + if (*flags & FTDM_WRITE) { inflags |= POLLOUT; } - if (*flags & ZAP_EVENTS) { + if (*flags & FTDM_EVENTS) { inflags |= POLLPRI; } - result = tdmv_api_wait_socket(zchan, to, &inflags); + result = tdmv_api_wait_socket(ftdmchan, to, &inflags); - *flags = ZAP_NO_FLAGS; + *flags = FTDM_NO_FLAGS; if (result < 0){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Poll failed"); + return FTDM_FAIL; } if (result == 0) { - return ZAP_TIMEOUT; + return FTDM_TIMEOUT; } if (inflags & POLLIN) { - *flags |= ZAP_READ; + *flags |= FTDM_READ; } if (inflags & POLLOUT) { - *flags |= ZAP_WRITE; + *flags |= FTDM_WRITE; } if (inflags & POLLPRI) { - *flags |= ZAP_EVENTS; + *flags |= FTDM_EVENTS; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -758,22 +758,22 @@ 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]; + sangoma_wait_obj_t *pfds[FTDM_MAX_CHANNELS_SPAN] = { 0 }; + uint32_t inflags[FTDM_MAX_CHANNELS_SPAN]; + uint32_t outflags[FTDM_MAX_CHANNELS_SPAN]; #else - struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN]; + struct pollfd pfds[FTDM_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]; + ftdm_channel_t *ftdmchan = span->channels[i]; #ifdef LIBSANGOMA_VERSION - if (!zchan->mod_data) { + if (!ftdmchan->mod_data) { continue; /* should never happen but happens when shutting down */ } - pfds[j] = zchan->mod_data; + pfds[j] = ftdmchan->mod_data; inflags[j] = POLLPRI; #else memset(&pfds[j], 0, sizeof(pfds[j])); @@ -782,38 +782,38 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) #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)) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_WINK) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_FLASH)) { l = 5; } j++; - if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING)) { l = 5; } - if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING) && zap_current_time_in_ms() >= zchan->ring_time) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_RINGING) && ftdm_current_time_in_ms() >= ftdmchan->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 (ftdm_test_pflag(ftdmchan, WP_RINGING)) { + err = sangoma_tdm_txsig_offhook(ftdmchan->sockfd,&tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); - zap_log(ZAP_LOG_ERROR, "sangoma_tdm_txsig_offhook failed\n"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Ring-off Failed"); + ftdm_log(FTDM_LOG_ERROR, "sangoma_tdm_txsig_offhook failed\n"); + return FTDM_FAIL; } - zap_clear_pflag_locked(zchan, WP_RINGING); - zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_off_ms; + ftdm_clear_pflag_locked(ftdmchan, WP_RINGING); + ftdmchan->ring_time = ftdm_current_time_in_ms() + wp_globals.ring_off_ms; } else { - err=sangoma_tdm_txsig_start(zchan->sockfd,&tdm_api); + err=sangoma_tdm_txsig_start(ftdmchan->sockfd,&tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring Failed"); - zap_log(ZAP_LOG_ERROR, "sangoma_tdm_txsig_start failed\n"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Ring Failed"); + ftdm_log(FTDM_LOG_ERROR, "sangoma_tdm_txsig_start failed\n"); + return FTDM_FAIL; } - zap_set_pflag_locked(zchan, WP_RINGING); - zchan->ring_time = zap_current_time_in_ms() + wp_globals.ring_on_ms; + ftdm_set_pflag_locked(ftdmchan, WP_RINGING); + ftdmchan->ring_time = ftdm_current_time_in_ms() + wp_globals.ring_on_ms; } } } @@ -828,7 +828,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) } else if (SANG_STATUS_SUCCESS == sangstatus) { r = 1; /* hopefully we never need how many changed -_- */ } else { - zap_log(ZAP_LOG_ERROR, "sangoma_waitfor_many failed: %d, %s\n", sangstatus, strerror(errno)); + ftdm_log(FTDM_LOG_ERROR, "sangoma_waitfor_many failed: %d, %s\n", sangstatus, strerror(errno)); r = -1; } #else @@ -836,32 +836,32 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) #endif if (r == 0) { - return l ? ZAP_SUCCESS : ZAP_TIMEOUT; + return l ? FTDM_SUCCESS : FTDM_TIMEOUT; } else if (r < 0) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); - return ZAP_FAIL; + return FTDM_FAIL; } for(i = 1; i <= span->chan_count; i++) { - zap_channel_t *zchan = span->channels[i]; + ftdm_channel_t *ftdmchan = 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(); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_EVENT); + ftdmchan->last_event_time = ftdm_current_time_in_ms(); k++; } } /* when k is 0 it might be that an async wanpipe device signal was delivered */ - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Gets alarms from a Wanpipe Channel - * \param zchan Channel to get alarms from + * \param ftdmchan Channel to get alarms from * \return Success or failure */ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) @@ -873,78 +873,78 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) 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; + if ((err = sangoma_tdm_get_fe_alarms(ftdmchan->sockfd, &tdm_api, &alarms))) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ioctl failed (%s)", strerror(errno)); + snprintf(ftdmchan->span->last_error, sizeof(ftdmchan->span->last_error), "ioctl failed (%s)", strerror(errno)); + return FTDM_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; + if ((err = sangoma_tdm_get_fe_alarms(ftdmchan->sockfd, &tdm_api)) < 0){ + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ioctl failed (%s)", strerror(errno)); + snprintf(ftdmchan->span->last_error, sizeof(ftdmchan->span->last_error), "ioctl failed (%s)", strerror(errno)); + return FTDM_FAIL; } alarms = tdm_api.wp_tdm_cmd.fe_alarms; #endif - zchan->alarm_flags = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; + ftdmchan->alarm_flags = alarms ? FTDM_ALARM_RED : FTDM_ALARM_NONE; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Retrieves an event from a wanpipe span * \param span Span to retrieve event from - * \param event Openzap event to return + * \param event Openftdm 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; + ftdm_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 (span->channels[i]->last_event_time && !ftdm_test_flag(span->channels[i], FTDM_CHANNEL_EVENT)) { + uint32_t diff = (uint32_t)(ftdm_current_time_in_ms() - span->channels[i]->last_event_time); + /* XX printf("%u %u %u\n", diff, (unsigned)ftdm_current_time_in_ms(), (unsigned)span->channels[i]->last_event_time); */ + if (ftdm_test_flag(span->channels[i], FTDM_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; + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_WINK); + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_FLASH); + ftdm_set_flag_locked(span->channels[i], FTDM_CHANNEL_OFFHOOK); + event_id = FTDM_OOB_OFFHOOK; goto event; } } - if (zap_test_flag(span->channels[i], ZAP_CHANNEL_FLASH)) { + if (ftdm_test_flag(span->channels[i], FTDM_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; + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_FLASH); + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_WINK); + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_OFFHOOK); + event_id = FTDM_OOB_ONHOOK; - if (span->channels[i]->type == ZAP_CHAN_TYPE_FXO) { - zap_channel_t *zchan = span->channels[i]; + if (span->channels[i]->type == FTDM_CHAN_TYPE_FXO) { + ftdm_channel_t *ftdmchan = span->channels[i]; wanpipe_tdm_api_t tdm_api; memset(&tdm_api, 0, sizeof(tdm_api)); - sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + sangoma_tdm_txsig_onhook(ftdmchan->sockfd,&tdm_api); } goto event; } } } - if (zap_test_flag(span->channels[i], ZAP_CHANNEL_EVENT)) { + if (ftdm_test_flag(span->channels[i], FTDM_CHANNEL_EVENT)) { wanpipe_tdm_api_t tdm_api; - zap_channel_t *zchan = span->channels[i]; + ftdm_channel_t *ftdmchan = span->channels[i]; memset(&tdm_api, 0, sizeof(tdm_api)); - zap_clear_flag(span->channels[i], ZAP_CHANNEL_EVENT); + ftdm_clear_flag(span->channels[i], FTDM_CHANNEL_EVENT); - err = sangoma_tdm_read_event(zchan->sockfd, &tdm_api); - if (err != ZAP_SUCCESS) { + err = sangoma_tdm_read_event(ftdmchan->sockfd, &tdm_api); + if (err != FTDM_SUCCESS) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); - return ZAP_FAIL; + return FTDM_FAIL; } switch(tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type) { @@ -953,10 +953,10 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { 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; + event_id = FTDM_OOB_ALARM_CLEAR; break; default: - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; break; }; } @@ -964,80 +964,80 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) case WP_TDMAPI_EVENT_RXHOOK: { - 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; + if (span->channels[i]->type == FTDM_CHAN_TYPE_FXS) { + event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_hook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? FTDM_OOB_OFFHOOK : FTDM_OOB_ONHOOK; + if (event_id == FTDM_OOB_OFFHOOK) { + if (ftdm_test_flag(span->channels[i], FTDM_CHANNEL_FLASH)) { + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_FLASH); + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_WINK); + event_id = FTDM_OOB_FLASH; goto event; } else { - zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_WINK); + ftdm_set_flag_locked(span->channels[i], FTDM_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; + if (ftdm_test_flag(span->channels[i], FTDM_CHANNEL_WINK)) { + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_WINK); + ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_FLASH); + event_id = FTDM_OOB_WINK; goto event; } else { - zap_set_flag_locked(span->channels[i], ZAP_CHANNEL_FLASH); + ftdm_set_flag_locked(span->channels[i], FTDM_CHANNEL_FLASH); } } continue; } else { int err; - zap_channel_t *zchan = span->channels[i]; - err=sangoma_tdm_txsig_onhook(zchan->sockfd,&tdm_api); + ftdm_channel_t *ftdmchan = span->channels[i]; + err=sangoma_tdm_txsig_onhook(ftdmchan->sockfd,&tdm_api); if (err) { snprintf(span->channels[i]->last_error, sizeof(span->channels[i]->last_error), "ONHOOK Failed"); - return ZAP_FAIL; + return FTDM_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; + event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_hook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? FTDM_OOB_ONHOOK : FTDM_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; + event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state == WP_TDMAPI_EVENT_RING_PRESENT ? FTDM_OOB_RING_START : FTDM_OOB_RING_STOP; } break; 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; + event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state == WP_TDMAPI_EVENT_RING_PRESENT ? FTDM_OOB_ONHOOK : FTDM_OOB_OFFHOOK; } break; case WP_TDMAPI_EVENT_RBS: { - event_id = ZAP_OOB_CAS_BITS_CHANGE; + event_id = FTDM_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; + event_id = FTDM_OOB_NOOP; 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); + ftdm_set_flag_locked(ftdmchan, FTDM_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); - zap_channel_queue_dtmf(zchan, tmp_dtmf); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_MUTE); + ftdm_channel_queue_dtmf(ftdmchan, tmp_dtmf); } } break; case WP_TDMAPI_EVENT_ALARM: { - event_id = ZAP_OOB_NOOP; + event_id = FTDM_OOB_NOOP; } 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; + ftdm_log(FTDM_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); + event_id = FTDM_OOB_INVALID; } break; } @@ -1045,45 +1045,45 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event: span->channels[i]->last_event_time = 0; - span->event_header.e_type = ZAP_EVENT_OOB; + span->event_header.e_type = FTDM_EVENT_OOB; span->event_header.enum_id = event_id; span->event_header.channel = span->channels[i]; *event = &span->event_header; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } } - return ZAP_FAIL; + return FTDM_FAIL; } /** * \brief Destroys a Wanpipe Channel - * \param zchan Channel to destroy + * \param ftdmchan Channel to destroy * \return Success */ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { #ifdef LIBSANGOMA_VERSION - if (zchan->mod_data) { + if (ftdmchan->mod_data) { sangoma_wait_obj_t *sangoma_wait_obj; - sangoma_wait_obj = zchan->mod_data; - zchan->mod_data = NULL; + sangoma_wait_obj = ftdmchan->mod_data; + ftdmchan->mod_data = NULL; sangoma_wait_obj_delete(&sangoma_wait_obj); } #endif - if (zchan->sockfd > -1) { - close(zchan->sockfd); - zchan->sockfd = WP_INVALID_SOCKET; + if (ftdmchan->sockfd > -1) { + close(ftdmchan->sockfd); + ftdmchan->sockfd = WP_INVALID_SOCKET; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** * \brief Loads wanpipe IO module - * \param zio Openzap IO interface + * \param zio Openftdm IO interface * \return Success */ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) @@ -1111,7 +1111,7 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) wanpipe_interface.get_alarms = wanpipe_get_alarms; *zio = &wanpipe_interface; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** @@ -1121,13 +1121,13 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) { memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Openzap wanpipe IO module definition + * \brief Openftdm wanpipe IO module definition */ -EX_DECLARE_DATA zap_module_t zap_module = { +EX_DECLARE_DATA ftdm_module_t ftdm_module = { "wanpipe", wanpipe_init, wanpipe_destroy, diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2005.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2005.vcproj rename to libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2005.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2008.vcproj similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2008.vcproj diff --git a/libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h b/libs/freetdm/src/ftmod/ftmod_wanpipe/wanpipe_tdm_api_iface.h similarity index 100% rename from libs/freetdm/src/ozmod/ozmod_wanpipe/wanpipe_tdm_api_iface.h rename to libs/freetdm/src/ftmod/ftmod_wanpipe/wanpipe_tdm_api_iface.h diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c similarity index 52% rename from libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c rename to libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 4815fbec51..46881519cc 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -32,8 +32,8 @@ */ -#include "openzap.h" -#include "ozmod_zt.h" +#include "freetdm.h" +#include "ftmod_zt.h" /** * \brief Zaptel globals @@ -170,10 +170,10 @@ 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 const char zt_ctlpath[] = "/dev/ftdm/ctl"; +static const char zt_chanpath[] = "/dev/ftdm/channel"; -static zap_socket_t CONTROL_FD = ZT_INVALID_SOCKET; +static ftdm_socket_t CONTROL_FD = ZT_INVALID_SOCKET; ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event); ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event); @@ -193,7 +193,7 @@ static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int c float linear_txgain = pow(10.0, txgain / 20.0); switch (codec) { - case ZAP_CODEC_ALAW: + case FTDM_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); @@ -213,7 +213,7 @@ static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int c } } break; - case ZAP_CODEC_ULAW: + case FTDM_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); @@ -237,41 +237,41 @@ static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int c } /** - * \brief Initialises a range of zaptel channels - * \param span Openzap span + * \brief Initialises a range of ftdmtel channels + * \param span Openftdm 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 type Openftdm channel type + * \param name Openftdm span name + * \param number Openftdm 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) +static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, ftdm_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); + if (type == FTDM_CHAN_TYPE_CAS) { + ftdm_log(FTDM_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; + ftdm_channel_t *ftdmchan; + ftdm_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 (sockfd != ZT_INVALID_SOCKET && ftdm_span_add_channel(span, sockfd, type, &ftdmchan) == FTDM_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)); + ftdm_log(FTDM_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) { + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { struct zt_bufferinfo binfo; memset(&binfo, 0, sizeof(binfo)); binfo.txbufpolicy = 0; @@ -279,28 +279,28 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } } - if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { + if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO) { struct zt_chanconfig cc; memset(&cc, 0, sizeof(cc)); cc.chan = cc.master = x; switch(type) { - case ZAP_CHAN_TYPE_FXS: + case FTDM_CHAN_TYPE_FXS: { switch(span->start_type) { - case ZAP_ANALOG_START_KEWL: + case FTDM_ANALOG_START_KEWL: cc.sigtype = ZT_SIG_FXOKS; break; - case ZAP_ANALOG_START_LOOP: + case FTDM_ANALOG_START_LOOP: cc.sigtype = ZT_SIG_FXOLS; break; - case ZAP_ANALOG_START_GROUND: + case FTDM_ANALOG_START_GROUND: cc.sigtype = ZT_SIG_FXOGS; break; default: @@ -308,16 +308,16 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } } break; - case ZAP_CHAN_TYPE_FXO: + case FTDM_CHAN_TYPE_FXO: { switch(span->start_type) { - case ZAP_ANALOG_START_KEWL: + case FTDM_ANALOG_START_KEWL: cc.sigtype = ZT_SIG_FXSKS; break; - case ZAP_ANALOG_START_LOOP: + case FTDM_ANALOG_START_LOOP: cc.sigtype = ZT_SIG_FXSLS; break; - case ZAP_ANALOG_START_GROUND: + case FTDM_ANALOG_START_GROUND: cc.sigtype = ZT_SIG_FXSGS; break; default: @@ -330,79 +330,79 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } 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)); + ftdm_log(FTDM_LOG_WARNING, "this ioctl fails on older ftdmtel 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) { + if (type == FTDM_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)); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d err:%s", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } } - if (zchan->type != ZAP_CHAN_TYPE_DQ921 && zchan->type != ZAP_CHAN_TYPE_DQ931) { + if (ftdmchan->type != FTDM_CHAN_TYPE_DQ921 && ftdmchan->type != FTDM_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)); + if (ioctl(ftdmchan->sockfd, codes.SET_BLOCKSIZE, &len)) { + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d err:%s\n", + chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } - zchan->packet_len = len; - zchan->effective_interval = zchan->native_interval = zchan->packet_len / 8; + ftdmchan->packet_len = len; + ftdmchan->effective_interval = ftdmchan->native_interval = ftdmchan->packet_len / 8; - if (zchan->effective_codec == ZAP_CODEC_SLIN) { - zchan->packet_len *= 2; + if (ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + ftdmchan->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); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + if (ftdmchan->type == FTDM_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); + ftdm_log(FTDM_LOG_ERROR, "Failure configuring device %s as OpenFTDM device %d:%d fd:%d, hardware signaling is not HDLC, fix your Zap/DAHDI configuration!\n", chanpath, ftdmchan->span_id, ftdmchan->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); + ftdm_log(FTDM_LOG_INFO, "configuring device %s channel %d as OpenFTDM device %d:%d fd:%d\n", chanpath, x, ftdmchan->span_id, ftdmchan->chan_id, sockfd); - zchan->rate = 8000; - zchan->physical_span_id = ztp.span_no; - zchan->physical_chan_id = ztp.chan_no; + ftdmchan->rate = 8000; + ftdmchan->physical_span_id = ztp.span_no; + ftdmchan->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 (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO || type == FTDM_CHAN_TYPE_EM || type == FTDM_CHAN_TYPE_B) { if (ztp.g711_type == ZT_G711_ALAW) { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ALAW; + ftdmchan->native_codec = ftdmchan->effective_codec = FTDM_CODEC_ALAW; } else if (ztp.g711_type == ZT_G711_MULAW) { - zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; + ftdmchan->native_codec = ftdmchan->effective_codec = FTDM_CODEC_ULAW; } else { int type; - if (zchan->span->trunk_type == ZAP_TRUNK_E1) { - type = ZAP_CODEC_ALAW; + if (ftdmchan->span->trunk_type == FTDM_TRUNK_E1) { + type = FTDM_CODEC_ALAW; } else { - type = ZAP_CODEC_ULAW; + type = FTDM_CODEC_ULAW; } - zchan->native_codec = zchan->effective_codec = type; + ftdmchan->native_codec = ftdmchan->effective_codec = type; } } @@ -411,20 +411,20 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za 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); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } - if (!zap_strlen_zero(name)) { - zap_copy_string(zchan->chan_name, name, sizeof(zchan->chan_name)); + if (!ftdm_strlen_zero(name)) { + ftdm_copy_string(ftdmchan->chan_name, name, sizeof(ftdmchan->chan_name)); } - if (!zap_strlen_zero(number)) { - zap_copy_string(zchan->chan_number, number, sizeof(zchan->chan_number)); + if (!ftdm_strlen_zero(number)) { + ftdm_copy_string(ftdmchan->chan_number, number, sizeof(ftdmchan->chan_number)); } configured++; } else { - zap_log(ZAP_LOG_ERROR, "failure configuring device %s\n", chanpath); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s\n", chanpath); } } @@ -434,12 +434,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za } /** - * \brief Initialises an openzap zaptel span from a configuration string - * \param span Openzap span + * \brief Initialises an freetdm ftdmtel span from a configuration string + * \param span Openftdm span * \param str Configuration string - * \param type Openzap span type - * \param name Openzap span name - * \param number Openzap span number + * \param type Openftdm span type + * \param name Openftdm span name + * \param number Openftdm span number * \return Success or failure */ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) @@ -456,24 +456,24 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) assert(str != NULL); - mydata = zap_strdup(str); + mydata = ftdm_strdup(str); assert(mydata != NULL); - items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); + items = ftdm_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"); + ftdm_log(FTDM_LOG_ERROR, "Invalid input\n"); continue; } channo = atoi(ch); if (channo < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid channel number %d\n", channo); + ftdm_log(FTDM_LOG_ERROR, "Invalid channel number %d\n", channo); continue; } @@ -486,25 +486,25 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) if (top < 0) { - zap_log(ZAP_LOG_ERROR, "Invalid range number %d\n", top); + ftdm_log(FTDM_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"); + if (FTDM_CHAN_TYPE_CAS == type && ftdm_config_get_cas_bits(ch, &cas_bits)) { + ftdm_log(FTDM_LOG_ERROR, "Failed to get CAS bits in CAS channel\n"); continue; } configured += zt_open_range(span, channo, top, type, name, number, cas_bits); } - zap_safe_free(mydata); + ftdm_safe_free(mydata); return configured; } /** - * \brief Process configuration variable for a zaptel profile + * \brief Process configuration variable for a ftdmtel profile * \param category Wanpipe profile name * \param var Variable name * \param val Variable value @@ -521,28 +521,28 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) 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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_WARNING, "invalid echo can val at line %d\n", lineno); } else { zt_globals.eclevel = num; } @@ -550,71 +550,71 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) } 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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_LOG_INFO, "Setting txgain val to %f\n", fnum); } } } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Opens a zaptel channel - * \param zchan Channel to open + * \brief Opens a ftdmtel channel + * \param ftdmchan Channel to open * \return Success or failure */ static ZIO_OPEN_FUNCTION(zt_open) { - zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); + ftdm_channel_set_feature(ftdmchan, FTDM_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; + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921 || ftdmchan->type == FTDM_CHAN_TYPE_DQ931) { + ftdmchan->native_codec = ftdmchan->effective_codec = FTDM_CODEC_NONE; } else { - int blocksize = zt_globals.codec_ms * (zchan->rate / 1000); + int blocksize = zt_globals.codec_ms * (ftdmchan->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; + if ((err = ioctl(ftdmchan->sockfd, codes.SET_BLOCKSIZE, &blocksize))) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + return FTDM_FAIL; } else { - zchan->effective_interval = zchan->native_interval; - zchan->packet_len = blocksize; - zchan->native_codec = zchan->effective_codec; + ftdmchan->effective_interval = ftdmchan->native_interval; + ftdmchan->packet_len = blocksize; + ftdmchan->native_codec = ftdmchan->effective_codec; } - if (zchan->type == ZAP_CHAN_TYPE_B) { + if (ftdmchan->type == FTDM_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 (ioctl(ftdmchan->sockfd, codes.AUDIOMODE, &one)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + ftdm_log(FTDM_LOG_ERROR, "%s\n", ftdmchan->last_error); + return FTDM_FAIL; } - } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_EM) { + } else if (ftdmchan->type == FTDM_CHAN_TYPE_FXS || ftdmchan->type == FTDM_CHAN_TYPE_FXO || ftdmchan->type == FTDM_CHAN_TYPE_EM) { int len = zt_globals.eclevel; - 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); - //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 (ioctl(ftdmchan->sockfd, codes.ECHOCANCEL, &len)) { + ftdm_log(FTDM_LOG_WARNING, "Echo cancel not available for %d:%d\n", ftdmchan->span_id, ftdmchan->chan_id); + //snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + //ftdm_log(FTDM_LOG_ERROR, "%s\n", ftdmchan->last_error); + //return FTDM_FAIL; } else { 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); - //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 (ioctl(ftdmchan->sockfd, codes.ECHOTRAIN, &len)) { + ftdm_log(FTDM_LOG_WARNING, "Echo training not available for %d:%d\n", ftdmchan->span_id, ftdmchan->chan_id); + //snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + //ftdm_log(FTDM_LOG_ERROR, "%s\n", ftdmchan->last_error); + //return FTDM_FAIL; } } } @@ -622,49 +622,49 @@ static ZIO_OPEN_FUNCTION(zt_open) 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); + gains.chan_no = ftdmchan->physical_chan_id; + zt_build_gains(&gains, zt_globals.rxgain, zt_globals.txgain, ftdmchan->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); + ftdm_log(FTDM_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); + ftdm_log(FTDM_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 (ioctl(ftdmchan->sockfd, codes.SETGAINS, &gains) < 0) { + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); } } int len = zt_globals.eclevel; - zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, 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); + ftdm_log(FTDM_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, ftdmchan->span_id, ftdmchan->chan_id); + if (ioctl(ftdmchan->sockfd, codes.ECHOCANCEL, &len)) { + ftdm_log(FTDM_LOG_WARNING, "Echo cancel not available for %d:%d\n", ftdmchan->span_id, ftdmchan->chan_id); } else { 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); + if (ioctl(ftdmchan->sockfd, codes.ECHOTRAIN, &len)) { + ftdm_log(FTDM_LOG_WARNING, "Echo training not available for %d:%d\n", ftdmchan->span_id, ftdmchan->chan_id); } } } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Closes zaptel channel - * \param zchan Channel to close + * \brief Closes ftdmtel channel + * \param ftdmchan Channel to close * \return Success */ static ZIO_CLOSE_FUNCTION(zt_close) { - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Executes an Openzap command on a zaptel channel - * \param zchan Channel to execute command on - * \param command Openzap command to execute + * \brief Executes an Openftdm command on a ftdmtel channel + * \param ftdmchan Channel to execute command on + * \param command Openftdm command to execute * \param obj Object (unused) * \return Success or failure */ @@ -676,166 +676,166 @@ static ZIO_COMMAND_FUNCTION(zt_command) memset(&ztp, 0, sizeof(ztp)); switch(command) { - case ZAP_COMMAND_ENABLE_ECHOCANCEL: + case FTDM_COMMAND_ENABLE_ECHOCANCEL: { - int level = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, codes.ECHOCANCEL, &level); - ZAP_COMMAND_OBJ_INT = level; + int level = FTDM_COMMAND_OBJ_INT; + err = ioctl(ftdmchan->sockfd, codes.ECHOCANCEL, &level); + FTDM_COMMAND_OBJ_INT = level; } - case ZAP_COMMAND_DISABLE_ECHOCANCEL: + case FTDM_COMMAND_DISABLE_ECHOCANCEL: { int level = 0; - err = ioctl(zchan->sockfd, codes.ECHOCANCEL, &level); - ZAP_COMMAND_OBJ_INT = level; + err = ioctl(ftdmchan->sockfd, codes.ECHOCANCEL, &level); + FTDM_COMMAND_OBJ_INT = level; } break; - case ZAP_COMMAND_ENABLE_ECHOTRAIN: + case FTDM_COMMAND_ENABLE_ECHOTRAIN: { - int level = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, codes.ECHOTRAIN, &level); - ZAP_COMMAND_OBJ_INT = level; + int level = FTDM_COMMAND_OBJ_INT; + err = ioctl(ftdmchan->sockfd, codes.ECHOTRAIN, &level); + FTDM_COMMAND_OBJ_INT = level; } - case ZAP_COMMAND_DISABLE_ECHOTRAIN: + case FTDM_COMMAND_DISABLE_ECHOTRAIN: { int level = 0; - err = ioctl(zchan->sockfd, codes.ECHOTRAIN, &level); - ZAP_COMMAND_OBJ_INT = level; + err = ioctl(ftdmchan->sockfd, codes.ECHOTRAIN, &level); + FTDM_COMMAND_OBJ_INT = level; } break; - case ZAP_COMMAND_OFFHOOK: + case FTDM_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; + if (ioctl(ftdmchan->sockfd, codes.HOOK, &command)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "OFFHOOK Failed"); + return FTDM_FAIL; } - zap_set_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); } break; - case ZAP_COMMAND_ONHOOK: + case FTDM_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; + if (ioctl(ftdmchan->sockfd, codes.HOOK, &command)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ONHOOK Failed"); + return FTDM_FAIL; } - zap_clear_flag_locked(zchan, ZAP_CHANNEL_OFFHOOK); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); } break; - case ZAP_COMMAND_FLASH: + case FTDM_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; + if (ioctl(ftdmchan->sockfd, codes.HOOK, &command)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "FLASH Failed"); + return FTDM_FAIL; } } break; - case ZAP_COMMAND_WINK: + case FTDM_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; + if (ioctl(ftdmchan->sockfd, codes.HOOK, &command)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "WINK Failed"); + return FTDM_FAIL; } } break; - case ZAP_COMMAND_GENERATE_RING_ON: + case FTDM_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; + if (ioctl(ftdmchan->sockfd, codes.HOOK, &command)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Ring Failed"); + return FTDM_FAIL; } - zap_set_flag_locked(zchan, ZAP_CHANNEL_RINGING); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_RINGING); } break; - case ZAP_COMMAND_GENERATE_RING_OFF: + case FTDM_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; + if (ioctl(ftdmchan->sockfd, codes.HOOK, &command)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Ring-off failed"); + return FTDM_FAIL; } - zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); + ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_RINGING); } break; - case ZAP_COMMAND_GET_INTERVAL: + case FTDM_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; + if (!(err = ioctl(ftdmchan->sockfd, codes.GET_BLOCKSIZE, &ftdmchan->packet_len))) { + ftdmchan->native_interval = ftdmchan->packet_len / 8; + if (ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + ftdmchan->packet_len *= 2; } - ZAP_COMMAND_OBJ_INT = zchan->native_interval; + FTDM_COMMAND_OBJ_INT = ftdmchan->native_interval; } } break; - case ZAP_COMMAND_SET_INTERVAL: + case FTDM_COMMAND_SET_INTERVAL: { - int interval = ZAP_COMMAND_OBJ_INT; + int interval = FTDM_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 (!(err = ioctl(ftdmchan->sockfd, codes.SET_BLOCKSIZE, &len))) { + ftdmchan->packet_len = len; + ftdmchan->effective_interval = ftdmchan->native_interval = ftdmchan->packet_len / 8; - if (zchan->effective_codec == ZAP_CODEC_SLIN) { - zchan->packet_len *= 2; + if (ftdmchan->effective_codec == FTDM_CODEC_SLIN) { + ftdmchan->packet_len *= 2; } } } break; - case ZAP_COMMAND_SET_CAS_BITS: + case FTDM_COMMAND_SET_CAS_BITS: { - int bits = ZAP_COMMAND_OBJ_INT; - err = ioctl(zchan->sockfd, codes.SETTXBITS, &bits); + int bits = FTDM_COMMAND_OBJ_INT; + err = ioctl(ftdmchan->sockfd, codes.SETTXBITS, &bits); } break; - case ZAP_COMMAND_GET_CAS_BITS: + case FTDM_COMMAND_GET_CAS_BITS: { - err = ioctl(zchan->sockfd, codes.GETRXBITS, &zchan->rx_cas_bits); + err = ioctl(ftdmchan->sockfd, codes.GETRXBITS, &ftdmchan->rx_cas_bits); if (!err) { - ZAP_COMMAND_OBJ_INT = zchan->rx_cas_bits; + FTDM_COMMAND_OBJ_INT = ftdmchan->rx_cas_bits; } } break; - case ZAP_COMMAND_FLUSH_TX_BUFFERS: + case FTDM_COMMAND_FLUSH_TX_BUFFERS: { int flushmode = ZT_FLUSH_WRITE; - err = ioctl(zchan->sockfd, codes.FLUSH, &flushmode); + err = ioctl(ftdmchan->sockfd, codes.FLUSH, &flushmode); } break; - case ZAP_COMMAND_FLUSH_RX_BUFFERS: + case FTDM_COMMAND_FLUSH_RX_BUFFERS: { int flushmode = ZT_FLUSH_READ; - err = ioctl(zchan->sockfd, codes.FLUSH, &flushmode); + err = ioctl(ftdmchan->sockfd, codes.FLUSH, &flushmode); } break; - case ZAP_COMMAND_FLUSH_BUFFERS: + case FTDM_COMMAND_FLUSH_BUFFERS: { int flushmode = ZT_FLUSH_BOTH; - err = ioctl(zchan->sockfd, codes.FLUSH, &flushmode); + err = ioctl(ftdmchan->sockfd, codes.FLUSH, &flushmode); } break; default: - err = ZAP_NOTIMPL; + err = FTDM_NOTIMPL; break; }; - if (err && err != ZAP_NOTIMPL) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - return ZAP_FAIL; + if (err && err != FTDM_NOTIMPL) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + return FTDM_FAIL; } - return err == 0 ? ZAP_SUCCESS : err; + return err == 0 ? FTDM_SUCCESS : err; } /** - * \brief Gets alarms from a zaptel Channel - * \param zchan Channel to get alarms from + * \brief Gets alarms from a ftdmtel Channel + * \param ftdmchan Channel to get alarms from * \return Success or failure */ static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms) @@ -843,22 +843,22 @@ static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms) struct zt_spaninfo info; memset(&info, 0, sizeof(info)); - info.span_no = zchan->physical_span_id; + info.span_no = ftdmchan->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; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ioctl failed (%s)", strerror(errno)); + snprintf(ftdmchan->span->last_error, sizeof(ftdmchan->span->last_error), "ioctl failed (%s)", strerror(errno)); + return FTDM_FAIL; } - zchan->alarm_flags = info.alarms; + ftdmchan->alarm_flags = info.alarms; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Waits for an event on a zaptel channel - * \param zchan Channel to open + * \brief Waits for an event on a ftdmtel channel + * \param ftdmchan Channel to open * \param flags Type of event to wait for * \param to Time to wait (in ms) * \return Success, failure or timeout @@ -869,21 +869,21 @@ static ZIO_WAIT_FUNCTION(zt_wait) int result; struct pollfd pfds[1]; - if (*flags & ZAP_READ) { + if (*flags & FTDM_READ) { inflags |= POLLIN; } - if (*flags & ZAP_WRITE) { + if (*flags & FTDM_WRITE) { inflags |= POLLOUT; } - if (*flags & ZAP_EVENTS) { + if (*flags & FTDM_EVENTS) { inflags |= POLLPRI; } memset(&pfds[0], 0, sizeof(pfds[0])); - pfds[0].fd = zchan->sockfd; + pfds[0].fd = ftdmchan->sockfd; pfds[0].events = inflags; result = poll(pfds, 1, to); *flags = 0; @@ -896,42 +896,42 @@ static ZIO_WAIT_FUNCTION(zt_wait) inflags = pfds[0].revents; } - *flags = ZAP_NO_FLAGS; + *flags = FTDM_NO_FLAGS; if (result < 0){ - snprintf(zchan->last_error, sizeof(zchan->last_error), "Poll failed"); - return ZAP_FAIL; + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Poll failed"); + return FTDM_FAIL; } if (result == 0) { - return ZAP_TIMEOUT; + return FTDM_TIMEOUT; } if (inflags & POLLIN) { - *flags |= ZAP_READ; + *flags |= FTDM_READ; } if (inflags & POLLOUT) { - *flags |= ZAP_WRITE; + *flags |= FTDM_WRITE; } if (inflags & POLLPRI) { - *flags |= ZAP_EVENTS; + *flags |= FTDM_EVENTS; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Checks for events on a zaptel span + * \brief Checks for events on a ftdmtel 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]; + struct pollfd pfds[FTDM_MAX_CHANNELS_SPAN]; uint32_t i, j = 0, k = 0; int r; @@ -945,16 +945,16 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) r = poll(pfds, j, ms); if (r == 0) { - return ZAP_TIMEOUT; + return FTDM_TIMEOUT; } else if (r < 0 || (pfds[i-1].revents & POLLERR)) { snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); - return ZAP_FAIL; + return FTDM_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(); + ftdm_set_flag(span->channels[i], FTDM_CHANNEL_EVENT); + span->channels[i]->last_event_time = ftdm_current_time_in_ms(); k++; } } @@ -963,127 +963,127 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) snprintf(span->last_error, sizeof(span->last_error), "no matching descriptor"); } - return k ? ZAP_SUCCESS : ZAP_FAIL; + return k ? FTDM_SUCCESS : FTDM_FAIL; } /** - * \brief Retrieves an event from a zaptel span + * \brief Retrieves an event from a ftdmtel span * \param span Span to retrieve event from - * \param event Openzap event to return + * \param event Openftdm event to return * \return Success or failure */ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) { uint32_t i, event_id = 0; - zap_oob_event_t zt_event_id = 0; + ftdm_oob_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 (ftdm_test_flag(span->channels[i], FTDM_CHANNEL_EVENT)) { + ftdm_clear_flag(span->channels[i], FTDM_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; + return FTDM_FAIL; } switch(zt_event_id) { case ZT_EVENT_RINGEROFF: { - return ZAP_FAIL; + return FTDM_FAIL; } break; case ZT_EVENT_RINGERON: { - return ZAP_FAIL; + return FTDM_FAIL; } break; case ZT_EVENT_RINGBEGIN: { - event_id = ZAP_OOB_RING_START; + event_id = FTDM_OOB_RING_START; } break; case ZT_EVENT_ONHOOK: { - event_id = ZAP_OOB_ONHOOK; + event_id = FTDM_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; + if (span->channels[i]->state == FTDM_CHANNEL_STATE_DOWN || span->channels[i]->state == FTDM_CHANNEL_STATE_DIALING) { + event_id = FTDM_OOB_WINK; } else { - event_id = ZAP_OOB_FLASH; + event_id = FTDM_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; + if (span->channels[i]->type == FTDM_CHAN_TYPE_FXS || (span->channels[i]->type == FTDM_CHAN_TYPE_EM && span->channels[i]->state != FTDM_CHANNEL_STATE_UP)) { + ftdm_set_flag_locked(span->channels[i], FTDM_CHANNEL_OFFHOOK); + event_id = FTDM_OOB_OFFHOOK; + } else if (span->channels[i]->type == FTDM_CHAN_TYPE_FXO) { + event_id = FTDM_OOB_RING_START; } } break; case ZT_EVENT_ALARM: { - event_id = ZAP_OOB_ALARM_TRAP; + event_id = FTDM_OOB_ALARM_TRAP; } break; case ZT_EVENT_NOALARM: { - event_id = ZAP_OOB_ALARM_CLEAR; + event_id = FTDM_OOB_ALARM_CLEAR; } break; case ZT_EVENT_BITSCHANGED: { - event_id = ZAP_OOB_CAS_BITS_CHANGE; + event_id = FTDM_OOB_CAS_BITS_CHANGE; int bits = 0; int err = ioctl(span->channels[i]->sockfd, codes.GETRXBITS, &bits); if (err) { - return ZAP_FAIL; + return FTDM_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; + ftdm_log(FTDM_LOG_WARNING, "Unhandled event %d for %d:%d\n", zt_event_id, span->span_id, i); + event_id = FTDM_OOB_INVALID; } break; } span->channels[i]->last_event_time = 0; - span->event_header.e_type = ZAP_EVENT_OOB; + span->event_header.e_type = FTDM_EVENT_OOB; span->event_header.enum_id = event_id; span->event_header.channel = span->channels[i]; *event = &span->event_header; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } } - return ZAP_FAIL; + return FTDM_FAIL; } /** - * \brief Reads data from a zaptel channel - * \param zchan Channel to read from + * \brief Reads data from a ftdmtel channel + * \param ftdmchan 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; + ftdm_ssize_t r = 0; int errs = 0; while (errs++ < 30) { - if ((r = read(zchan->sockfd, data, *datalen)) > 0) { + if ((r = read(ftdmchan->sockfd, data, *datalen)) > 0) { break; } - zap_sleep(10); + ftdm_sleep(10); if (r == 0) { errs--; } @@ -1091,63 +1091,63 @@ static ZIO_READ_FUNCTION(zt_read) if (r > 0) { *datalen = r; - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { *datalen -= 2; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return r == 0 ? ZAP_TIMEOUT : ZAP_FAIL; + return r == 0 ? FTDM_TIMEOUT : FTDM_FAIL; } /** - * \brief Writes data to a zaptel channel - * \param zchan Channel to write to + * \brief Writes data to a ftdmtel channel + * \param ftdmchan 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; + ftdm_ssize_t w = 0; + ftdm_size_t bytes = *datalen; - if (zchan->type == ZAP_CHAN_TYPE_DQ921) { + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { memset(data+bytes, 0, 2); bytes += 2; } - w = write(zchan->sockfd, data, bytes); + w = write(ftdmchan->sockfd, data, bytes); if (w >= 0) { *datalen = w; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } - return ZAP_FAIL; + return FTDM_FAIL; } /** - * \brief Destroys a zaptel Channel - * \param zchan Channel to destroy + * \brief Destroys a ftdmtel Channel + * \param ftdmchan Channel to destroy * \return Success */ static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) { - close(zchan->sockfd); - zchan->sockfd = ZT_INVALID_SOCKET; + close(ftdmchan->sockfd); + ftdmchan->sockfd = ZT_INVALID_SOCKET; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Global Openzap IO interface for zaptel + * \brief Global Openftdm IO interface for ftdmtel */ -static zap_io_interface_t zt_interface; +static ftdm_io_interface_t zt_interface; /** - * \brief Loads zaptel IO module - * \param zio Openzap IO interface + * \brief Loads ftdmtel IO module + * \param zio Openftdm IO interface * \return Success or failure */ static ZIO_IO_LOAD_FUNCTION(zt_init) @@ -1158,22 +1158,22 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) memset(&zt_globals, 0, sizeof(zt_globals)); if (!stat(zt_ctlpath, &statbuf)) { - zap_log(ZAP_LOG_NOTICE, "Using Zaptel control device\n"); + ftdm_log(FTDM_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"); + ftdm_log(FTDM_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; + ftdm_log(FTDM_LOG_ERROR, "No DAHDI or Zap control device found in /dev/\n"); + return FTDM_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; + ftdm_log(FTDM_LOG_ERROR, "Cannot open control device %s: %s\n", ctlpath, strerror(errno)); + return FTDM_FAIL; } zt_globals.codec_ms = 20; @@ -1197,24 +1197,24 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) zt_interface.get_alarms = zt_get_alarms; *zio = &zt_interface; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Unloads zaptel IO module + * \brief Unloads ftdmtel IO module * \return Success */ static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) { close(CONTROL_FD); memset(&zt_interface, 0, sizeof(zt_interface)); - return ZAP_SUCCESS; + return FTDM_SUCCESS; } /** - * \brief Openzap zaptel IO module definition + * \brief Openftdm ftdmtel IO module definition */ -zap_module_t zap_module = { +ftdm_module_t ftdm_module = { "zt", zt_init, zt_destroy, diff --git a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h similarity index 97% rename from libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h rename to libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h index 687269a983..cf5479dba1 100644 --- a/libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.h +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h @@ -31,9 +31,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ZAP_ZT_H -#define ZAP_ZT_H -#include "openzap.h" +#ifndef FTDM_ZT_H +#define FTDM_ZT_H +#include "freetdm.h" #include #include @@ -45,7 +45,7 @@ /* Hardware interface structures and defines */ /* Based on documentation of the structures required for the hardware interface */ -/* from http://wiki.freeswitch.org/wiki/Zapata_zaptel_interface */ +/* from http://wiki.freeswitch.org/wiki/Zapata_ftdmtel_interface */ /* Structures */ @@ -111,9 +111,9 @@ struct zt_spaninfo { int sync_src; /* Span # of sync source (0 = free run) */ int configured_chan_count; /* Count of channels configured on the span */ int channel_count; /* Total count of channels on the span */ - int span_count; /* Total count of zaptel spans on the system*/ + int span_count; /* Total count of ftdmtel spans on the system*/ /* end v1 of the struct */ - /* as long as we don't use the fields below we should be ok regardless of the zaptel/dahdi version */ + /* as long as we don't use the fields below we should be ok regardless of the ftdmtel/dahdi version */ int lbo; /* Line Build Out */ int lineconfig; /* framing/coding */ /* end of v2 of the struct */ @@ -290,7 +290,7 @@ ZT_ABIT = 8 #define ZT_HDLCRAWMODE _IOW (ZT_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */ #define ZT_HDLCFCSMODE _IOW (ZT_CODE, 37, int) /* Set a clear channel into HDLC w/ FCS mode */ -/* Specify a channel on /dev/zap/chan -- must be done before any other ioctl's and is only valid on /dev/zap/chan */ +/* Specify a channel on /dev/ftdm/chan -- must be done before any other ioctl's and is only valid on /dev/ftdm/chan */ #define ZT_SPECIFY _IOW (ZT_CODE, 38, int) /* Temporarily set the law on a channel to ZT_LAW_DEFAULT, ZT_LAW_ALAW, or ZT_LAW_MULAW. Is reset on close. */ diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index 15ec9014f4..1f08abc2b8 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -31,7 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openzap.h" +#include "freetdm.h" #include "hashtable.h" #include "hashtable_private.h" #include @@ -57,7 +57,7 @@ const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); const float max_load_factor = 0.65f; /*****************************************************************************/ -OZ_DECLARE(struct hashtable *) +FT_DECLARE(struct hashtable *) create_hashtable(unsigned int minsize, unsigned int (*hashf) (void*), int (*eqf) (void*,void*)) @@ -70,10 +70,10 @@ create_hashtable(unsigned int minsize, for (pindex=0; pindex < prime_table_length; pindex++) { if (primes[pindex] > minsize) { size = primes[pindex]; break; } } - h = (struct hashtable *)zap_malloc(sizeof(struct hashtable)); + h = (struct hashtable *)ftdm_malloc(sizeof(struct hashtable)); if (NULL == h) return NULL; /*oom*/ - h->table = (struct entry **)zap_malloc(sizeof(struct entry*) * size); - if (NULL == h->table) { zap_safe_free(h); return NULL; } /*oom*/ + h->table = (struct entry **)ftdm_malloc(sizeof(struct entry*) * size); + if (NULL == h->table) { ftdm_safe_free(h); return NULL; } /*oom*/ memset(h->table, 0, size * sizeof(struct entry *)); h->tablelength = size; h->primeindex = pindex; @@ -111,7 +111,7 @@ hashtable_expand(struct hashtable *h) if (h->primeindex == (prime_table_length - 1)) return 0; newsize = primes[++(h->primeindex)]; - newtable = (struct entry **)zap_malloc(sizeof(struct entry*) * newsize); + newtable = (struct entry **)ftdm_malloc(sizeof(struct entry*) * newsize); if (NULL != newtable) { memset(newtable, 0, newsize * sizeof(struct entry *)); @@ -125,7 +125,7 @@ hashtable_expand(struct hashtable *h) newtable[index] = e; } } - zap_safe_free(h->table); + ftdm_safe_free(h->table); h->table = newtable; } /* Plan B: realloc instead */ @@ -158,14 +158,14 @@ hashtable_expand(struct hashtable *h) } /*****************************************************************************/ -OZ_DECLARE(unsigned int) +FT_DECLARE(unsigned int) hashtable_count(struct hashtable *h) { return h->entrycount; } /*****************************************************************************/ -OZ_DECLARE(int) +FT_DECLARE(int) hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) { /* This method allows duplicate keys - but they shouldn't be used */ @@ -179,7 +179,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) * element may be ok. Next time we insert, we'll try expanding again.*/ hashtable_expand(h); } - e = (struct entry *)zap_malloc(sizeof(struct entry)); + e = (struct entry *)ftdm_malloc(sizeof(struct entry)); if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ e->h = hash(h,k); index = indexFor(h->tablelength,e->h); @@ -192,7 +192,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) } /*****************************************************************************/ -OZ_DECLARE(void *) /* returns value associated with key */ +FT_DECLARE(void *) /* returns value associated with key */ hashtable_search(struct hashtable *h, void *k) { struct entry *e; @@ -210,7 +210,7 @@ hashtable_search(struct hashtable *h, void *k) } /*****************************************************************************/ -OZ_DECLARE(void *) /* returns value associated with key */ +FT_DECLARE(void *) /* returns value associated with key */ hashtable_remove(struct hashtable *h, void *k) { /* TODO: consider compacting the table when the load factor drops enough, @@ -236,7 +236,7 @@ hashtable_remove(struct hashtable *h, void *k) if (e->flags & HASHTABLE_FLAG_FREE_KEY) { freekey(e->k); } - zap_safe_free(e); + ftdm_safe_free(e); return v; } pE = &(e->next); @@ -247,7 +247,7 @@ hashtable_remove(struct hashtable *h, void *k) /*****************************************************************************/ /* destroy */ -OZ_DECLARE(void) +FT_DECLARE(void) hashtable_destroy(struct hashtable *h) { unsigned int i; @@ -258,14 +258,14 @@ hashtable_destroy(struct hashtable *h) { e = table[i]; while (NULL != e) - { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) zap_safe_free(f->v); zap_safe_free(f); } + { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) ftdm_safe_free(f->v); ftdm_safe_free(f); } } - zap_safe_free(h->table); - zap_safe_free(h); + ftdm_safe_free(h->table); + ftdm_safe_free(h); } -OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i) +FT_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i) { if (i->e) { @@ -291,7 +291,7 @@ OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator return NULL; } -OZ_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h) +FT_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h) { h->iterator.pos = 0; h->iterator.e = NULL; @@ -301,7 +301,7 @@ OZ_DECLARE(struct hashtable_iterator *) hashtable_first(struct hashtable *h) -OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) +FT_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val) { if (i->e) { if (key) { diff --git a/libs/freetdm/src/hashtable_itr.c b/libs/freetdm/src/hashtable_itr.c index ab5e1ce0c8..a31f5b44c5 100644 --- a/libs/freetdm/src/hashtable_itr.c +++ b/libs/freetdm/src/hashtable_itr.c @@ -31,7 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openzap.h" +#include "freetdm.h" #include "hashtable.h" #include "hashtable_private.h" #include "hashtable_itr.h" @@ -44,7 +44,7 @@ struct hashtable_itr * hashtable_iterator(struct hashtable *h) { unsigned int i, tablelength; - struct hashtable_itr *itr = zap_malloc(sizeof(struct hashtable_itr)); + struct hashtable_itr *itr = ftdm_malloc(sizeof(struct hashtable_itr)); if (NULL == itr) return NULL; itr->h = h; itr->e = NULL; @@ -138,7 +138,7 @@ hashtable_iterator_remove(struct hashtable_itr *itr) remember_parent = itr->parent; ret = hashtable_iterator_advance(itr); if (itr->parent == remember_e) { itr->parent = remember_parent; } - zap_safe_free(remember_e); + ftdm_safe_free(remember_e); return ret; } diff --git a/libs/freetdm/src/include/hashtable.h b/libs/freetdm/src/include/hashtable.h index 7a94354d5d..f08ea817e2 100644 --- a/libs/freetdm/src/include/hashtable.h +++ b/libs/freetdm/src/include/hashtable.h @@ -7,7 +7,7 @@ #define __inline__ __inline #endif #endif -#include "openzap.h" +#include "freetdm.h" #ifdef __cplusplus extern "C" { @@ -81,7 +81,7 @@ struct hashtable_iterator; * @return newly created hashtable or NULL on failure */ -OZ_DECLARE(struct hashtable *) +FT_DECLARE(struct hashtable *) create_hashtable(unsigned int minsize, unsigned int (*hashfunction) (void*), int (*key_eq_fn) (void*,void*)); @@ -112,7 +112,7 @@ typedef enum { HASHTABLE_FLAG_FREE_VALUE = (1 << 1) } hashtable_flag_t; -OZ_DECLARE(int) +FT_DECLARE(int) hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); #define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \ @@ -130,7 +130,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags); * @return the value associated with the key, or NULL if none found */ -OZ_DECLARE(void *) +FT_DECLARE(void *) hashtable_search(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \ @@ -148,7 +148,7 @@ hashtable_search(struct hashtable *h, void *k); * @return the value associated with the key, or NULL if none found */ -OZ_DECLARE(void *) /* returns value */ +FT_DECLARE(void *) /* returns value */ hashtable_remove(struct hashtable *h, void *k); #define DEFINE_HASHTABLE_REMOVE(fnname, keytype, valuetype) \ @@ -165,7 +165,7 @@ hashtable_remove(struct hashtable *h, void *k); * @param h the hashtable * @return the number of items stored in the hashtable */ -OZ_DECLARE(unsigned int) +FT_DECLARE(unsigned int) hashtable_count(struct hashtable *h); @@ -177,12 +177,12 @@ hashtable_count(struct hashtable *h); * @param free_values whether to call 'free' on the remaining values */ -OZ_DECLARE(void) +FT_DECLARE(void) hashtable_destroy(struct hashtable *h); -OZ_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h); -OZ_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i); -OZ_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); +FT_DECLARE(struct hashtable_iterator*) hashtable_first(struct hashtable *h); +FT_DECLARE(struct hashtable_iterator*) hashtable_next(struct hashtable_iterator *i); +FT_DECLARE(void) hashtable_this(struct hashtable_iterator *i, const void **key, int *klen, void **val); #ifdef __cplusplus } /* extern C */ diff --git a/libs/freetdm/src/include/libteletone.h b/libs/freetdm/src/include/libteletone.h index 6e806cec4f..18b95e7f3c 100644 --- a/libs/freetdm/src/include/libteletone.h +++ b/libs/freetdm/src/include/libteletone.h @@ -4,10 +4,10 @@ * * Version: MPL 1.1 * - * The contents of this file are subject to the Mozilla Public License Version + * The contents of this file are subject to the Mftilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * http://www.mftilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License @@ -33,8 +33,8 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the + * as part of the freetdm library. Any use or distribution of this + * source code outside the scope of the freetdm library will nullify the * following license and reinact the MPL 1.1 as stated above. * * Copyright (c) 2007, Anthony Minessale II diff --git a/libs/freetdm/src/include/libteletone_detect.h b/libs/freetdm/src/include/libteletone_detect.h index 3d0a5130ec..dc14356e3e 100644 --- a/libs/freetdm/src/include/libteletone_detect.h +++ b/libs/freetdm/src/include/libteletone_detect.h @@ -7,8 +7,8 @@ * Exception: * The author hereby grants the use of this source code under the * following license if and only if the source code is distributed - * as part of the openzap library. Any use or distribution of this - * source code outside the scope of the openzap library will nullify the + * as part of the freetdm library. Any use or distribution of this + * source code outside the scope of the freetdm library will nullify the * following license and reinact the MPL 1.1 as stated above. * * Copyright (c) 2007, Anthony Minessale II diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h deleted file mode 100644 index 7281684afc..0000000000 --- a/libs/freetdm/src/include/openzap.h +++ /dev/null @@ -1,932 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * - * Moises Silva - * - */ - -#ifndef OPENZAP_H -#define OPENZAP_H - - -#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) -#define _XOPEN_SOURCE 600 -#endif - -#ifndef HAVE_STRINGS_H -#define HAVE_STRINGS_H 1 -#endif -#ifndef HAVE_SYS_SOCKET_H -#define HAVE_SYS_SOCKET_H 1 -#endif - -#ifndef __WINDOWS__ -#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) -#define __WINDOWS__ -#endif -#endif - -#ifdef _MSC_VER -#if defined(OZ_DECLARE_STATIC) -#define OZ_DECLARE(type) type __stdcall -#define OZ_DECLARE_NONSTD(type) type __cdecl -#define OZ_DECLARE_DATA -#elif defined(OPENZAP_EXPORTS) -#define OZ_DECLARE(type) __declspec(dllexport) type __stdcall -#define OZ_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl -#define OZ_DECLARE_DATA __declspec(dllexport) -#else -#define OZ_DECLARE(type) __declspec(dllimport) type __stdcall -#define OZ_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl -#define OZ_DECLARE_DATA __declspec(dllimport) -#endif -#define EX_DECLARE_DATA __declspec(dllexport) -#else -#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) -#define OZ_DECLARE(type) __attribute__((visibility("default"))) type -#define OZ_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type -#define OZ_DECLARE_DATA __attribute__((visibility("default"))) -#else -#define OZ_DECLARE(type) type -#define OZ_DECLARE_NONSTD(type) type -#define OZ_DECLARE_DATA -#endif -#define EX_DECLARE_DATA -#endif - -#ifdef _MSC_VER -#ifndef __inline__ -#define __inline__ __inline -#endif -#if (_MSC_VER >= 1400) /* VC8+ */ -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE -#endif -#ifndef _CRT_NONSTDC_NO_DEPRECATE -#define _CRT_NONSTDC_NO_DEPRECATE -#endif -#endif -#ifndef strcasecmp -#define strcasecmp(s1, s2) _stricmp(s1, s2) -#endif -#ifndef strncasecmp -#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n) -#endif -#ifndef snprintf -#define snprintf _snprintf -#endif -#ifndef S_IRUSR -#define S_IRUSR _S_IREAD -#endif -#ifndef S_IWUSR -#define S_IWUSR _S_IWRITE -#endif -#undef HAVE_STRINGS_H -#undef HAVE_SYS_SOCKET_H -/* disable warning for zero length array in a struct */ -/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ -#pragma warning(disable:4706) -#pragma comment(lib, "Winmm") -#endif - -#define ZAP_THREAD_STACKSIZE 240 * 1024 -#define ZAP_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; -#define ZAP_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) OZ_DECLARE(_TYPE) _FUNC1 (const char *name); OZ_DECLARE(const char *) _FUNC2 (_TYPE type); -#define ZAP_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ - OZ_DECLARE(_TYPE) _FUNC1 (const char *name) \ - { \ - int i; \ - _TYPE t = _MAX ; \ - \ - for (i = 0; i < _MAX ; i++) { \ - if (!strcasecmp(name, _STRINGS[i])) { \ - t = (_TYPE) i; \ - break; \ - } \ - } \ - \ - return t; \ - } \ - OZ_DECLARE(const char *) _FUNC2 (_TYPE type) \ - { \ - if (type > _MAX) { \ - type = _MAX; \ - } \ - return _STRINGS[(int)type]; \ - } \ - -#define zap_true(expr) \ - (expr && ( !strcasecmp(expr, "yes") || \ - !strcasecmp(expr, "on") || \ - !strcasecmp(expr, "true") || \ - !strcasecmp(expr, "enabled") || \ - !strcasecmp(expr, "active") || \ - atoi(expr))) ? 1 : 0 - - -#include -#ifndef __WINDOWS__ -#include -#endif - -#include -#include -#include -#ifdef HAVE_STRINGS_H -#include -#endif -#include -#include "zap_types.h" -#include "hashtable.h" -#include "zap_config.h" -#include "g711.h" -#include "libteletone.h" -#include "zap_buffer.h" -#include "zap_threadmutex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __WINDOWS__ -#define zap_sleep(x) Sleep(x) -#else -#define zap_sleep(x) usleep(x * 1000) -#endif - -#ifdef NDEBUG -#undef assert -#define assert(_Expression) ((void)(_Expression)) -#endif - -#define ZAP_MAX_CHANNELS_PHYSICAL_SPAN 32 -#define ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32 -#define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN -#define ZAP_MAX_SPANS_INTERFACE 128 - -#define ZAP_MAX_CHANNELS_GROUP 1024 -#define ZAP_MAX_GROUPS_INTERFACE ZAP_MAX_SPANS_INTERFACE - -#define GOTO_STATUS(label,st) status = st; goto label ; - -#define zap_copy_string(x,y,z) strncpy(x, y, z - 1) -#define zap_set_string(x,y) strncpy(x, y, sizeof(x)-1) -#define zap_strlen_zero(s) (!s || *s == '\0') -#define zap_strlen_zero_buf(s) (*s == '\0') - - -#define zap_channel_test_feature(obj, flag) ((obj)->features & flag) -#define zap_channel_set_feature(obj, flag) (obj)->features |= (flag) -#define zap_channel_clear_feature(obj, flag) (obj)->features &= ~(flag) -#define zap_channel_set_member_locked(obj, _m, _v) zap_mutex_lock(obj->mutex); obj->_m = _v; zap_mutex_unlock(obj->mutex) - -/*! - \brief Test for the existance of a flag on an arbitary object - \command obj the object to test - \command flag the or'd list of flags to test - \return true value if the object has the flags defined -*/ -#define zap_test_flag(obj, flag) ((obj)->flags & flag) -#define zap_test_pflag(obj, flag) ((obj)->pflags & flag) -#define zap_test_sflag(obj, flag) ((obj)->sflags & flag) - - -#define zap_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag) -#define zap_clear_alarm_flag(obj, flag) (obj)->alarm_flags &= ~(flag) -#define zap_test_alarm_flag(obj, flag) ((obj)->alarm_flags & flag) - -/*! - \brief Set a flag on an arbitrary object - \command obj the object to set the flags on - \command flag the or'd list of flags to set -*/ -#define zap_set_flag(obj, flag) (obj)->flags |= (flag) -#define zap_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ - zap_mutex_lock(obj->mutex); \ - (obj)->flags |= (flag); \ - zap_mutex_unlock(obj->mutex); - -#define zap_set_pflag(obj, flag) (obj)->pflags |= (flag) -#define zap_set_pflag_locked(obj, flag) assert(obj->mutex != NULL); \ - zap_mutex_lock(obj->mutex); \ - (obj)->pflags |= (flag); \ - zap_mutex_unlock(obj->mutex); - -#define zap_set_sflag(obj, flag) (obj)->sflags |= (flag) -#define zap_set_sflag_locked(obj, flag) assert(obj->mutex != NULL); \ - zap_mutex_lock(obj->mutex); \ - (obj)->sflags |= (flag); \ - zap_mutex_unlock(obj->mutex); - -/*! - \brief Clear a flag on an arbitrary object while locked - \command obj the object to test - \command flag the or'd list of flags to clear -*/ -#define zap_clear_flag(obj, flag) (obj)->flags &= ~(flag) - -#define zap_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); zap_mutex_unlock(obj->mutex); - -#define zap_clear_pflag(obj, flag) (obj)->pflags &= ~(flag) - -#define zap_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); zap_mutex_unlock(obj->mutex); - -#define zap_clear_sflag(obj, flag) (obj)->sflags &= ~(flag) - -#define zap_clear_sflag_locked(obj, flag) assert(obj->mutex != NULL); zap_mutex_lock(obj->mutex); (obj)->sflags &= ~(flag); zap_mutex_unlock(obj->mutex); - - -#define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ - } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ - zap_channel_state_t st = obj->state; \ - zap_channel_set_state(obj, s, 1); \ - if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ - else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ - } - -#ifdef _MSC_VER -/* The while(0) below throws a conditional expression is constant warning */ -#pragma warning(disable:4127) -#endif - -#define zap_set_state_locked_wait(obj, s) \ - do { \ - int __safety = 100; \ - zap_set_state_locked(obj, s); \ - while(__safety-- && zap_test_flag(obj, ZAP_CHANNEL_STATE_CHANGE)) { \ - zap_sleep(10); \ - } \ - if(!__safety) { \ - zap_log(ZAP_LOG_CRIT, "State change not completed\n"); \ - } \ - } while(0); - -#define zap_wait_for_flag_cleared(obj, flag, time) \ - do { \ - int __safety = time; \ - while(__safety-- && zap_test_flag(obj, flag)) { \ - zap_mutex_unlock(obj->mutex); \ - zap_sleep(10); \ - zap_mutex_lock(obj->mutex); \ - } \ - if(!__safety) { \ - zap_log(ZAP_LOG_CRIT, "flag %d was never cleared\n", flag); \ - } \ - } while(0); - -#define zap_set_state_wait(obj, s) \ - do { \ - zap_channel_set_state(obj, s, 0); \ - zap_wait_for_flag_cleared(obj, ZAP_CHANNEL_STATE_CHANGE, 100); \ - } while(0); - - -typedef enum { - ZAP_STATE_CHANGE_FAIL, - ZAP_STATE_CHANGE_SUCCESS, - ZAP_STATE_CHANGE_SAME, -} zap_state_change_result_t; - -#define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ - } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ - int st = obj->state; \ - r = (zap_channel_set_state(obj, s, l) == ZAP_SUCCESS) ? ZAP_STATE_CHANGE_SUCCESS : ZAP_STATE_CHANGE_FAIL; \ - if (obj->state == s) {zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s));} \ - else {zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); } \ - } - - -#define zap_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) - -/*! - \brief Copy flags from one arbitrary object to another - \command dest the object to copy the flags to - \command src the object to copy the flags from - \command flags the flags to copy -*/ -#define zap_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) - -struct zap_stream_handle { - zap_stream_handle_write_function_t write_function; - zap_stream_handle_raw_write_function_t raw_write_function; - void *data; - void *end; - zap_size_t data_size; - zap_size_t data_len; - zap_size_t alloc_len; - zap_size_t alloc_chunk; -}; - - -OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); -OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...); - -#define ZAP_CMD_CHUNK_LEN 1024 -#define ZAP_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(ZAP_CMD_CHUNK_LEN); \ - assert(s.data); \ - memset(s.data, 0, ZAP_CMD_CHUNK_LEN); \ - s.end = s.data; \ - s.data_size = ZAP_CMD_CHUNK_LEN; \ - s.write_function = zap_console_stream_write; \ - s.raw_write_function = zap_console_stream_raw_write; \ - s.alloc_len = ZAP_CMD_CHUNK_LEN; \ - s.alloc_chunk = ZAP_CMD_CHUNK_LEN - -struct zap_event { - zap_event_type_t e_type; - uint32_t enum_id; - zap_channel_t *channel; - void *data; -}; - -#define ZAP_TOKEN_STRLEN 128 -#define ZAP_MAX_TOKENS 10 - -static __inline__ char *zap_clean_string(char *s) -{ - char *p; - - for (p = s; p && *p; p++) { - uint8_t x = (uint8_t) *p; - if (x < 32 || x > 127) { - *p = ' '; - } - } - - return s; -} - -struct zap_bitstream { - uint8_t *data; - uint32_t datalen; - uint32_t byte_index; - uint8_t bit_index; - int8_t endian; - uint8_t top; - uint8_t bot; - uint8_t ss; - uint8_t ssv; -}; - -struct zap_fsk_data_state { - dsp_fsk_handle_t *fsk1200_handle; - uint8_t init; - uint8_t *buf; - size_t bufsize; - zap_size_t blen; - zap_size_t bpos; - zap_size_t dlen; - zap_size_t ppos; - int checksum; -}; - -struct zap_fsk_modulator { - teletone_dds_state_t dds; - zap_bitstream_t bs; - uint32_t carrier_bits_start; - uint32_t carrier_bits_stop; - uint32_t chan_sieze_bits; - uint32_t bit_factor; - uint32_t bit_accum; - uint32_t sample_counter; - int32_t samples_per_bit; - int32_t est_bytes; - fsk_modem_types_t modem_type; - zap_fsk_data_state_t *fsk_data; - zap_fsk_write_sample_t write_sample_callback; - void *user_data; - int16_t sample_buffer[64]; -}; - -/** - * Type Of Number (TON) - */ -typedef enum { - ZAP_TON_UNKNOWN = 0, - ZAP_TON_INTERNATIONAL, - ZAP_TON_NATIONAL, - ZAP_TON_NETWORK_SPECIFIC, - ZAP_TON_SUBSCRIBER_NUMBER, - ZAP_TON_ABBREVIATED_NUMBER, - ZAP_TON_RESERVED -} zap_ton_t; - -typedef struct { - char digits[25]; - uint8_t type; - uint8_t plan; -} zap_number_t; - -typedef enum { - ZAP_CALLER_STATE_DIALING, - ZAP_CALLER_STATE_SUCCESS, - ZAP_CALLER_STATE_FAIL -} zap_caller_state_t; - -struct zap_caller_data { - char cid_date[8]; - char cid_name[80]; - zap_number_t cid_num; - zap_number_t ani; - zap_number_t dnis; - zap_number_t rdnis; - char aniII[25]; - uint8_t screen; - uint8_t pres; - char collected[25]; - int CRV; - int hangup_cause; - uint8_t raw_data[1024]; - uint32_t raw_data_len; - uint32_t flags; - zap_caller_state_t call_state; - uint32_t chan_id; -}; - -typedef enum { - ZAP_TYPE_NONE, - ZAP_TYPE_SPAN = 0xFF, - ZAP_TYPE_CHANNEL -} zap_data_type_t; - -/* 2^8 table size, one for each byte value */ -#define ZAP_GAINS_TABLE_SIZE 256 -struct zap_channel { - zap_data_type_t data_type; - uint32_t span_id; - uint32_t chan_id; - uint32_t physical_span_id; - uint32_t physical_chan_id; - uint32_t rate; - uint32_t extra_id; - zap_chan_type_t type; - zap_socket_t sockfd; - zap_channel_flag_t flags; - uint32_t pflags; - uint32_t sflags; - zap_alarm_flag_t alarm_flags; - zap_channel_feature_t features; - zap_codec_t effective_codec; - zap_codec_t native_codec; - uint32_t effective_interval; - uint32_t native_interval; - uint32_t packet_len; - zap_channel_state_t state; - zap_channel_state_t last_state; - zap_channel_state_t init_state; - zap_mutex_t *mutex; - teletone_dtmf_detect_state_t dtmf_detect; - uint32_t buffer_delay; - zap_event_t event_header; - char last_error[256]; - zio_event_cb_t event_callback; - uint32_t skip_read_frames; - zap_buffer_t *dtmf_buffer; - zap_buffer_t *gen_dtmf_buffer; - zap_buffer_t *pre_buffer; - zap_buffer_t *digit_buffer; - zap_buffer_t *fsk_buffer; - zap_mutex_t *pre_buffer_mutex; - uint32_t dtmf_on; - uint32_t dtmf_off; - char *dtmf_hangup_buf; - teletone_generation_session_t tone_session; - zap_time_t last_event_time; - zap_time_t ring_time; - char tokens[ZAP_MAX_TOKENS+1][ZAP_TOKEN_STRLEN]; - uint8_t needed_tones[ZAP_TONEMAP_INVALID]; - uint8_t detected_tones[ZAP_TONEMAP_INVALID]; - zap_tonemap_t last_detected_tone; - uint32_t token_count; - char chan_name[128]; - char chan_number[32]; - zap_filehandle_t fds[2]; - zap_fsk_data_state_t fsk; - uint8_t fsk_buf[80]; - uint32_t ring_count; - void *mod_data; - void *call_data; - struct zap_caller_data caller_data; - struct zap_span *span; - struct zap_io_interface *zio; - zap_hash_t *variable_hash; - unsigned char rx_cas_bits; - uint32_t pre_buffer_size; - unsigned char rxgain_table[ZAP_GAINS_TABLE_SIZE]; - unsigned char txgain_table[ZAP_GAINS_TABLE_SIZE]; - float rxgain; - float txgain; -}; - - -struct zap_sigmsg { - zap_signal_event_t event_id; - uint32_t chan_id; - uint32_t span_id; - zap_channel_t *channel; - void *raw_data; - uint32_t raw_data_len; -}; - - -struct zap_span { - zap_data_type_t data_type; - char *name; - uint32_t span_id; - uint32_t chan_count; - zap_span_flag_t flags; - struct zap_io_interface *zio; - zio_event_cb_t event_callback; - zap_mutex_t *mutex; - zap_trunk_type_t trunk_type; - zap_analog_start_type_t start_type; - zap_signal_type_t signal_type; - void *signal_data; - zap_event_t event_header; - char last_error[256]; - char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; - teletone_tone_map_t tone_detect_map[ZAP_TONEMAP_INVALID+1]; - teletone_multi_tone_t tone_finder[ZAP_TONEMAP_INVALID+1]; - zap_channel_t *channels[ZAP_MAX_CHANNELS_SPAN+1]; - zio_channel_outgoing_call_t outgoing_call; - zio_channel_set_sig_status_t set_channel_sig_status; - zio_channel_get_sig_status_t get_channel_sig_status; - zio_span_set_sig_status_t set_span_sig_status; - zio_span_get_sig_status_t get_span_sig_status; - zio_channel_request_t channel_request; - zap_span_start_t start; - zap_span_stop_t stop; - void *mod_data; - char *type; - char *dtmf_hangup; - size_t dtmf_hangup_len; - int suggest_chan_id; - zap_state_map_t *state_map; - struct zap_span *next; -}; - -struct zap_group { - char *name; - uint32_t group_id; - uint32_t chan_count; - zap_channel_t *channels[ZAP_MAX_CHANNELS_GROUP]; - uint32_t last_used_index; - zap_mutex_t *mutex; - struct zap_group *next; -}; - -OZ_DECLARE_DATA extern zap_logger_t zap_log; - -typedef enum { - ZAP_CRASH_NEVER = 0, - ZAP_CRASH_ON_ASSERT -} zap_crash_policy_t; - -OZ_DECLARE_DATA extern zap_crash_policy_t g_zap_crash_policy; - -typedef void *(*zap_malloc_func_t)(void *pool, zap_size_t len); -typedef void *(*zap_calloc_func_t)(void *pool, zap_size_t elements, zap_size_t len); -typedef void (*zap_free_func_t)(void *pool, void *ptr); -typedef struct zap_memory_handler { - void *pool; - zap_malloc_func_t malloc; - zap_calloc_func_t calloc; - zap_free_func_t free; -} zap_memory_handler_t; - -OZ_DECLARE_DATA extern zap_memory_handler_t g_zap_mem_handler; - -struct zap_io_interface { - const char *name; - zio_configure_span_t configure_span; - zio_configure_t configure; - zio_open_t open; - zio_close_t close; - zio_channel_destroy_t channel_destroy; - zio_span_destroy_t span_destroy; - zio_get_alarms_t get_alarms; - zio_command_t command; - zio_wait_t wait; - zio_read_t read; - zio_write_t write; - zio_span_poll_event_t poll_event; - zio_span_next_event_t next_event; - zio_api_t api; -}; - -typedef struct zap_queue zap_queue_t; -typedef zap_status_t (*zap_queue_create_func_t)(zap_queue_t **queue, zap_size_t capacity); -typedef zap_status_t (*zap_queue_enqueue_func_t)(zap_queue_t *queue, void *obj); -typedef void *(*zap_queue_dequeue_func_t)(zap_queue_t *queue); -typedef zap_status_t (*zap_queue_wait_func_t)(zap_queue_t *queue, int ms); -typedef zap_status_t (*zap_queue_destroy_func_t)(zap_queue_t **queue); -typedef struct zap_queue_handler { - zap_queue_create_func_t create; - zap_queue_enqueue_func_t enqueue; - zap_queue_dequeue_func_t dequeue; - zap_queue_wait_func_t wait; - zap_queue_destroy_func_t destroy; -} zap_queue_handler_t; -OZ_DECLARE_DATA extern zap_queue_handler_t g_zap_queue_handler; - -/*! brief create a new queue */ -#define zap_queue_create(queue, capacity) g_zap_queue_handler.create(queue, capacity) - -/*! Enqueue an object */ -#define zap_queue_enqueue(queue, obj) g_zap_queue_handler.enqueue(queue, obj) - -/*! dequeue an object from the queue */ -#define zap_queue_dequeue(queue) g_zap_queue_handler.dequeue(queue) - -/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ -#define zap_queue_wait(queue, ms) g_zap_queue_handler.wait(queue, ms) - -/*! destroy the queue */ -#define zap_queue_destroy(queue) g_zap_queue_handler.destroy(queue) - -/*! \brief Override the default queue handler */ -OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handler); - -/*! \brief Duplicate string */ -OZ_DECLARE(char *) zap_strdup(const char *str); -OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen); - -OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen); -OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits); -OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans); -OZ_DECLARE(void) zap_fsk_modulator_send_data(zap_fsk_modulator_t *fsk_trans); -#define zap_fsk_modulator_send_all(_it) zap_fsk_modulator_generate_chan_sieze(_it); \ - zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ - zap_fsk_modulator_send_data(_it); \ - zap_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) - -OZ_DECLARE(zap_status_t) zap_fsk_modulator_init(zap_fsk_modulator_t *fsk_trans, - fsk_modem_types_t modem_type, - uint32_t sample_rate, - zap_fsk_data_state_t *fsk_data, - float db_level, - uint32_t carrier_bits_start, - uint32_t carrier_bits_stop, - uint32_t chan_sieze_bits, - zap_fsk_write_sample_t write_sample_callback, - void *user_data); -OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp); -OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss); -OZ_DECLARE(zap_status_t) zap_fsk_data_parse(zap_fsk_data_state_t *state, zap_size_t *type, char **data, zap_size_t *len); -OZ_DECLARE(zap_status_t) zap_fsk_demod_feed(zap_fsk_data_state_t *state, int16_t *data, size_t samples); -OZ_DECLARE(zap_status_t) zap_fsk_demod_destroy(zap_fsk_data_state_t *state); -OZ_DECLARE(int) zap_fsk_demod_init(zap_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); -OZ_DECLARE(zap_status_t) zap_fsk_data_init(zap_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); -OZ_DECLARE(zap_status_t) zap_fsk_data_add_mdmf(zap_fsk_data_state_t *state, zap_mdmf_type_t type, const uint8_t *data, uint32_t datalen); -OZ_DECLARE(zap_status_t) zap_fsk_data_add_checksum(zap_fsk_data_state_t *state); -OZ_DECLARE(zap_status_t) zap_fsk_data_add_sdmf(zap_fsk_data_state_t *state, const char *date, char *number); -OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_set_sig_status(zap_channel_t *zchan, zap_signaling_status_t status); -OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_signaling_status_t *status); -OZ_DECLARE(zap_status_t) zap_span_set_sig_status(zap_span_t *span, zap_signaling_status_t status); -OZ_DECLARE(zap_status_t) zap_span_get_sig_status(zap_span_t *span, zap_signaling_status_t *status); -OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan); -OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan); -OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level); -OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token); -OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token); -OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end); -OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock); -OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname); -OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len); -OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf); -OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan); -OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void); -OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms); -OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event); -OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span); -OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name); -OZ_DECLARE(zap_status_t) zap_span_close_all(void); -OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan); -OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback); -OZ_DECLARE(zap_status_t) zap_channel_add_to_group(const char* name, zap_channel_t* zchan); -OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* span, const char* val); -OZ_DECLARE(zap_status_t) zap_channel_remove_from_group(zap_group_t* group, zap_channel_t* zchan); -OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group); -OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group); -OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name); -OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback); -OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan); -OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count); -OZ_DECLARE(zap_status_t) zap_group_channel_use_count(zap_group_t *group, uint32_t *count); -OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); -OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan); -OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan); -OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj); -OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); -OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); -OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor); -OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); -OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); -OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name); -OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_global_init(void); -OZ_DECLARE(zap_status_t) zap_global_configuration(void); -OZ_DECLARE(zap_status_t) zap_global_destroy(void); -OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler); -OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy); -OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger); -OZ_DECLARE(void) zap_global_set_default_logger(int level); -OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen); -OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); -OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen); -OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2); -OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky); -OZ_DECLARE(uint32_t) zap_running(void); -OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan); -OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan); -OZ_DECLARE(int) zap_load_modules(void); -OZ_DECLARE(zap_status_t) zap_unload_modules(void); -OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); -OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *parameters); -OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); -OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); -OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len); -OZ_DECLARE(zap_status_t) zap_global_add_io_interface(zap_io_interface_t *io_interface); -OZ_DECLARE(int) zap_load_module(const char *name); -OZ_DECLARE(int) zap_load_module_assume(const char *name); -OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); -OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd); -OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap); - -ZIO_CODEC_FUNCTION(zio_slin2ulaw); -ZIO_CODEC_FUNCTION(zio_ulaw2slin); -ZIO_CODEC_FUNCTION(zio_slin2alaw); -ZIO_CODEC_FUNCTION(zio_alaw2slin); -ZIO_CODEC_FUNCTION(zio_ulaw2alaw); -ZIO_CODEC_FUNCTION(zio_alaw2ulaw); - -#ifdef DEBUG_LOCKS -#define zap_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_lock(_x) -#define zap_mutex_trylock(_x) printf("++++++try %s:%d\n", __FILE__, __LINE__) && _zap_mutex_trylock(_x) -#define zap_mutex_unlock(_x) printf("------unlock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_unlock(_x) -#else -#define zap_mutex_lock(_x) _zap_mutex_lock(_x) -#define zap_mutex_trylock(_x) _zap_mutex_trylock(_x) -#define zap_mutex_unlock(_x) _zap_mutex_unlock(_x) -#endif - -/*! - \brief Assert condition -*/ -#define zap_assert(assertion, msg) \ - if (!(assertion)) { \ - zap_log(ZAP_LOG_CRIT, msg); \ - if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ - zap_abort(); \ - } \ - } - -/*! - \brief Assert condition and return -*/ -#define zap_assert_return(assertion, retval, msg) \ - if (!(assertion)) { \ - zap_log(ZAP_LOG_CRIT, msg); \ - if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ - zap_abort(); \ - } else { \ - return retval; \ - } \ - } - -/*! - \brief Allocate uninitialized memory - \command chunksize the chunk size -*/ -#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize) - -/*! - \brief Allocate initialized memory - \command chunksize the chunk size -*/ -#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize) - -/*! - \brief Free chunk of memory - \command chunksize the chunk size -*/ -#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk) - -/*! - \brief Free a pointer and set it to NULL unless it already is NULL - \command it the pointer -*/ -#define zap_safe_free(it) if (it) { zap_free(it); it = NULL; } - -/*! - \brief Socket the given socket - \command it the socket -*/ -#define zap_socket_close(it) if (it > -1) { close(it); it = -1;} - -static __inline__ void zap_abort(void) -{ -#ifdef __cplusplus - ::abort(); -#else - abort(); -#endif -} - -static __inline__ void zap_set_state_all(zap_span_t *span, zap_channel_state_t state) -{ - uint32_t j; - zap_mutex_lock(span->mutex); - for(j = 1; j <= span->chan_count; j++) { - zap_set_state_locked((span->channels[j]), state); - } - zap_mutex_unlock(span->mutex); -} - -static __inline__ int zap_check_state_all(zap_span_t *span, zap_channel_state_t state) -{ - uint32_t j; - for(j = 1; j <= span->chan_count; j++) { - if (span->channels[j]->state != state || zap_test_flag(span->channels[j], ZAP_CHANNEL_STATE_CHANGE)) { - return 0; - } - } - - return 1; -} - -static __inline__ void zap_set_flag_all(zap_span_t *span, uint32_t flag) -{ - uint32_t j; - zap_mutex_lock(span->mutex); - for(j = 1; j <= span->chan_count; j++) { - zap_set_flag_locked((span->channels[j]), flag); - } - zap_mutex_unlock(span->mutex); -} - -static __inline__ void zap_clear_flag_all(zap_span_t *span, uint32_t flag) -{ - uint32_t j; - zap_mutex_lock(span->mutex); - for(j = 1; j <= span->chan_count; j++) { - zap_clear_flag_locked((span->channels[j]), flag); - } - zap_mutex_unlock(span->mutex); -} - -#ifdef __cplusplus -} /* extern C */ -#endif - -#endif - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/libs/freetdm/src/include/zap_buffer.h b/libs/freetdm/src/include/zap_buffer.h deleted file mode 100644 index 03d4caae11..0000000000 --- a/libs/freetdm/src/include/zap_buffer.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ZAP_BUFFER_H -#define ZAP_BUFFER_H - -#include "openzap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup zap_buffer Buffer Routines - * @ingroup buffer - * The purpose of this module is to make a plain buffering interface that can be used for read/write buffers - * throughout the application. - * @{ - */ -struct zap_buffer; -typedef struct zap_buffer zap_buffer_t; - -/*! \brief Allocate a new dynamic zap_buffer - * \param buffer returned pointer to the new buffer - * \param blocksize length to realloc by as data is added - * \param start_len ammount of memory to reserve initially - * \param max_len length the buffer is allowed to grow to - * \return status - */ -OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blocksize, zap_size_t start_len, zap_size_t max_len); - -/*! \brief Get the length of a zap_buffer_t - * \param buffer any buffer of type zap_buffer_t - * \return int size of the buffer. - */ -OZ_DECLARE(zap_size_t) zap_buffer_len(zap_buffer_t *buffer); - -/*! \brief Get the freespace of a zap_buffer_t - * \param buffer any buffer of type zap_buffer_t - * \return int freespace in the buffer. - */ -OZ_DECLARE(zap_size_t) zap_buffer_freespace(zap_buffer_t *buffer); - -/*! \brief Get the in use amount of a zap_buffer_t - * \param buffer any buffer of type zap_buffer_t - * \return int ammount of buffer curently in use - */ -OZ_DECLARE(zap_size_t) zap_buffer_inuse(zap_buffer_t *buffer); - -/*! \brief Read data from a zap_buffer_t up to the ammount of datalen if it is available. Remove read data from buffer. - * \param buffer any buffer of type zap_buffer_t - * \param data pointer to the read data to be returned - * \param datalen amount of data to be returned - * \return int ammount of data actually read - */ -OZ_DECLARE(zap_size_t) zap_buffer_read(zap_buffer_t *buffer, void *data, zap_size_t datalen); - -/*! \brief Read data endlessly from a zap_buffer_t - * \param buffer any buffer of type zap_buffer_t - * \param data pointer to the read data to be returned - * \param datalen amount of data to be returned - * \return int ammount of data actually read - * \note Once you have read all the data from the buffer it will loop around. - */ -OZ_DECLARE(zap_size_t) zap_buffer_read_loop(zap_buffer_t *buffer, void *data, zap_size_t datalen); - -/*! \brief Assign a number of loops to read - * \param buffer any buffer of type zap_buffer_t - * \param loops the number of loops (-1 for infinite) - */ -OZ_DECLARE(void) zap_buffer_set_loops(zap_buffer_t *buffer, int32_t loops); - -/*! \brief Write data into a zap_buffer_t up to the length of datalen - * \param buffer any buffer of type zap_buffer_t - * \param data pointer to the data to be written - * \param datalen amount of data to be written - * \return int amount of buffer used after the write, or 0 if no space available - */ -OZ_DECLARE(zap_size_t) zap_buffer_write(zap_buffer_t *buffer, const void *data, zap_size_t datalen); - -/*! \brief Remove data from the buffer - * \param buffer any buffer of type zap_buffer_t - * \param datalen amount of data to be removed - * \return int size of buffer, or 0 if unable to toss that much data - */ -OZ_DECLARE(zap_size_t) zap_buffer_toss(zap_buffer_t *buffer, zap_size_t datalen); - -/*! \brief Remove all data from the buffer - * \param buffer any buffer of type zap_buffer_t - */ -OZ_DECLARE(void) zap_buffer_zero(zap_buffer_t *buffer); - -/*! \brief Destroy the buffer - * \param buffer buffer to destroy - * \note only neccessary on dynamic buffers (noop on pooled ones) - */ -OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer); - -/*! \brief Seek to offset from the beginning of the buffer - * \param buffer buffer to seek - * \param datalen offset in bytes - * \return new position - */ -OZ_DECLARE(zap_size_t) zap_buffer_seek(zap_buffer_t *buffer, zap_size_t datalen); - -/** @} */ - -OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data, zap_size_t datalen); - -#ifdef __cplusplus -} -#endif - -#endif -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/libs/freetdm/src/include/zap_config.h b/libs/freetdm/src/include/zap_config.h deleted file mode 100644 index d961700ea4..0000000000 --- a/libs/freetdm/src/include/zap_config.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @defgroup config Config File Parser - * @ingroup config - * This module implements a basic interface and file format parser - * - *
- *
- * 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 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct zap_config zap_config_t; - -/*! \brief A simple file handle representing an open configuration file **/ -struct zap_config { - /*! FILE stream buffer to the opened file */ - FILE *file; - /*! path to the file */ - char path[512]; - /*! current category */ - char category[256]; - /*! current section */ - char section[256]; - /*! buffer of current line being read */ - char buf[1024]; - /*! current line number in file */ - int lineno; - /*! current category number in file */ - int catno; - /*! current section number in file */ - int sectno; - - int lockto; -}; - -/*! - \brief Open a configuration file - \param cfg (zap_config_t *) config handle to use - \param file_path path to the file - \return 1 (true) on success 0 (false) on failure -*/ -int zap_config_open_file(zap_config_t * cfg, const char *file_path); - -/*! - \brief Close a previously opened configuration file - \param cfg (zap_config_t *) config handle to use -*/ -void zap_config_close_file(zap_config_t * cfg); - -/*! - \brief Retrieve next name/value pair from configuration file - \param cfg (zap_config_t *) config handle to use - \param var pointer to aim at the new variable name - \param val pointer to aim at the new value -*/ -int zap_config_next_pair(zap_config_t * cfg, char **var, char **val); - -/*! - \brief Retrieve the CAS bits from a configuration string value - \param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx) - \param outbits pointer to aim at the CAS bits -*/ -OZ_DECLARE (int) zap_config_get_cas_bits(char *strvalue, unsigned char *outbits); - -#ifdef __cplusplus -} -#endif - -/** @} */ -#endif -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/libs/freetdm/src/include/zap_dso.h b/libs/freetdm/src/include/zap_dso.h deleted file mode 100644 index c5d1457b95..0000000000 --- a/libs/freetdm/src/include/zap_dso.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Cross Platform dso/dll load abstraction - * Copyright(C) 2008 Michael Jerris - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so. - * - * This work is provided under this license on an "as is" basis, without warranty of any kind, - * either expressed or implied, including, without limitation, warranties that the covered code - * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire - * risk as to the quality and performance of the covered code is with you. Should any covered - * code prove defective in any respect, you (not the initial developer or any other contributor) - * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty - * constitutes an essential part of this license. No use of any covered code is authorized hereunder - * except under this disclaimer. - * - */ - - -#ifndef _ZAP_DSO_H -#define _ZAP_DSO_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*zap_func_ptr_t) (void); -typedef void * zap_dso_lib_t; - -OZ_DECLARE(void) zap_dso_destroy(zap_dso_lib_t *lib); -OZ_DECLARE(zap_dso_lib_t) zap_dso_open(const char *path, char **err); -OZ_DECLARE(void *) zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err); - -#ifdef __cplusplus -} -#endif - -#endif - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4 - */ - diff --git a/libs/freetdm/src/include/zap_m3ua.h b/libs/freetdm/src/include/zap_m3ua.h deleted file mode 100644 index c06d112093..0000000000 --- a/libs/freetdm/src/include/zap_m3ua.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * zap_m3ua.h - * openzap - * - * Created by Shane Burrell on 4/3/08. - * Copyright 2008 Shane Burrell. All rights reserved. - * - * Copyright (c) 2007, Anthony Minessale II, Nenad Corbic - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -//#include "m3ua_client.h" -#include "openzap.h" - -#ifdef __cplusplus -extern "C" { -#endif -enum e_sigboost_event_id_values -{ - SIGBOOST_EVENT_CALL_START = 0x80, /*128*/ - SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/ - SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/ - SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/ - SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/ - SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/ - SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ - SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ - SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ - /* Following IDs are ss7boost to sangoma_mgd only. */ - SIGBOOST_EVENT_HEARTBEAT = 0x89, /*137*/ - SIGBOOST_EVENT_INSERT_CHECK_LOOP = 0x8a, /*138*/ - SIGBOOST_EVENT_REMOVE_CHECK_LOOP = 0x8b, /*139*/ - SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE = 0x8c, /*140*/ -}; -enum e_sigboost_release_cause_values -{ - SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0, - SIGBOOST_RELEASE_CAUSE_NORMAL = 16, - SIGBOOST_RELEASE_CAUSE_BUSY = 17, - /* probable elimination */ - //SIGBOOST_RELEASE_CAUSE_BUSY = 0x91, /* 145 */ - //SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92, /* 146 */ - //SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93, /* 147 */ - //SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94, /* 148 */ -}; - -enum e_sigboost_call_setup_ack_nack_cause_values -{ - SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 117, /* unused Q.850 value */ - SIGBOOST_CALL_SETUP_NACK_TEST_CKT_BUSY = 118, /* unused Q.850 value */ - SIGBOOST_CALL_SETUP_NACK_INVALID_NUMBER = 28, - /* probable elimination */ - //SIGBOOST_CALL_SETUP_RESERVED = 0x00, - //SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10, - //SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11, - //SIGBOOST_CALL_SETUP_NACK_AUTO_CALL_GAP = 0x17, -}; -typedef enum { - M3UA_SPAN_SIGNALING_M3UA, - M3UA_SPAN_SIGNALING_SS7BOX, - -} M3UA_TSpanSignaling; -#define M3UA_SPAN_STRINGS "M3UA", "SS7BOX" -ZAP_STR2ENUM_P(m3ua_str2span, m3ua_span2str, M3UA_TSpanSignaling) - - - -typedef enum { - ZAP_M3UA_RUNNING = (1 << 0) -} zap_m3uat_flag_t; - -/*typedef struct m3ua_data { - m3uac_connection_t mcon; - m3uac_connection_t pcon; - zio_signal_cb_t signal_cb; - uint32_t flags; -} m3ua_data_t; - -*/ -/*typedef struct mu3a_link { - ss7bc_connection_t mcon; - ss7bc_connection_t pcon; - zio_signal_cb_t signal_cb; - uint32_t flags; -} zap_m3ua_data_t; -*/ - -zap_status_t m3ua_init(zap_io_interface_t **zint); -zap_status_t m3ua_destroy(void); -zap_status_t m3ua_start(zap_span_t *span); - -#ifdef __cplusplus -} -#endif - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ - diff --git a/libs/freetdm/src/include/zap_threadmutex.h b/libs/freetdm/src/include/zap_threadmutex.h deleted file mode 100644 index 488dca1c42..0000000000 --- a/libs/freetdm/src/include/zap_threadmutex.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Cross Platform Thread/Mutex abstraction - * Copyright(C) 2007 Michael Jerris - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so. - * - * This work is provided under this license on an "as is" basis, without warranty of any kind, - * either expressed or implied, including, without limitation, warranties that the covered code - * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire - * risk as to the quality and performance of the covered code is with you. Should any covered - * code prove defective in any respect, you (not the initial developer or any other contributor) - * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty - * constitutes an essential part of this license. No use of any covered code is authorized hereunder - * except under this disclaimer. - * - * Contributors: - * - * Moises Silva - * - */ - - -#ifndef _ZAP_THREADMUTEX_H -#define _ZAP_THREADMUTEX_H - -#include "openzap.h" - -#ifdef __cplusplus -extern "C" { -#endif -typedef struct zap_mutex zap_mutex_t; -typedef struct zap_thread zap_thread_t; -typedef struct zap_condition zap_condition_t; -typedef void *(*zap_thread_function_t) (zap_thread_t *, void *); - -OZ_DECLARE(zap_status_t) zap_thread_create_detached(zap_thread_function_t func, void *data); -OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t func, void *data, zap_size_t stack_size); -OZ_DECLARE(void) zap_thread_override_default_stacksize(zap_size_t size); -OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex); -OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex); -OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex); -OZ_DECLARE(zap_status_t) _zap_mutex_trylock(zap_mutex_t *mutex); -OZ_DECLARE(zap_status_t) _zap_mutex_unlock(zap_mutex_t *mutex); -OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **cond, zap_mutex_t *mutex); -OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **cond); -OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *cond); -OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *cond, int ms); - -#ifdef __cplusplus -} -#endif - -#endif - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ - diff --git a/libs/freetdm/src/include/zap_types.h b/libs/freetdm/src/include/zap_types.h deleted file mode 100644 index e4f6811b57..0000000000 --- a/libs/freetdm/src/include/zap_types.h +++ /dev/null @@ -1,703 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * - * Moises Silva - * - */ - -#ifndef ZAP_TYPES_H -#define ZAP_TYPES_H -#include "fsk.h" - -#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 - -#ifdef __cplusplus -extern "C" { -#endif -#define TAG_END NULL - -typedef size_t zap_size_t; -struct zap_io_interface; - -#define ZAP_COMMAND_OBJ_INT *((int *)obj) -#define ZAP_COMMAND_OBJ_CHAR_P (char *)obj -#define ZAP_COMMAND_OBJ_FLOAT *(float *)obj -#define ZAP_FSK_MOD_FACTOR 0x10000 -#define ZAP_DEFAULT_DTMF_ON 250 -#define ZAP_DEFAULT_DTMF_OFF 50 - -#define ZAP_END -1 -#define ZAP_ANY_STATE -1 - -typedef uint64_t zap_time_t; - -typedef enum { - ZAP_ENDIAN_BIG = 1, - ZAP_ENDIAN_LITTLE = -1 -} zap_endian_t; - -typedef enum { - ZAP_CID_TYPE_SDMF = 0x04, - ZAP_CID_TYPE_MDMF = 0x80 -} zap_cid_type_t; - -typedef enum { - MDMF_DATETIME = 1, - MDMF_PHONE_NUM = 2, - MDMF_DDN = 3, - MDMF_NO_NUM = 4, - MDMF_PHONE_NAME = 7, - MDMF_NO_NAME = 8, - MDMF_ALT_ROUTE = 9, - MDMF_INVALID = 10 -} zap_mdmf_type_t; -#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "ALT_ROUTE", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t) - -#define ZAP_TONEMAP_LEN 128 -typedef enum { - ZAP_TONEMAP_NONE, - ZAP_TONEMAP_DIAL, - ZAP_TONEMAP_RING, - ZAP_TONEMAP_BUSY, - ZAP_TONEMAP_FAIL1, - ZAP_TONEMAP_FAIL2, - ZAP_TONEMAP_FAIL3, - ZAP_TONEMAP_ATTN, - ZAP_TONEMAP_CALLWAITING_CAS, - ZAP_TONEMAP_CALLWAITING_SAS, - ZAP_TONEMAP_CALLWAITING_ACK, - ZAP_TONEMAP_INVALID -} zap_tonemap_t; -#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "CALLWAITING-CAS", "CALLWAITING-SAS", "CALLWAITING-ACK", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t) - -typedef enum { - ZAP_TRUNK_E1, - ZAP_TRUNK_T1, - ZAP_TRUNK_J1, - ZAP_TRUNK_BRI, - ZAP_TRUNK_BRI_PTMP, - ZAP_TRUNK_FXO, - ZAP_TRUNK_FXS, - ZAP_TRUNK_EM, - ZAP_TRUNK_NONE -} zap_trunk_type_t; -#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "EM", "NONE" -ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t) - -typedef enum { - ZAP_ANALOG_START_KEWL, - ZAP_ANALOG_START_LOOP, - ZAP_ANALOG_START_GROUND, - ZAP_ANALOG_START_WINK, - ZAP_ANALOG_START_NA -} zap_analog_start_type_t; -#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "WINK", "NA" -ZAP_STR2ENUM_P(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t) - -typedef enum { - ZAP_OOB_ONHOOK, - ZAP_OOB_OFFHOOK, - ZAP_OOB_WINK, - ZAP_OOB_FLASH, - ZAP_OOB_RING_START, - ZAP_OOB_RING_STOP, - ZAP_OOB_ALARM_TRAP, - ZAP_OOB_ALARM_CLEAR, - ZAP_OOB_NOOP, - ZAP_OOB_CAS_BITS_CHANGE, - ZAP_OOB_INVALID -} zap_oob_event_t; -#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "CAS_BITS_CHANGE", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t) - -typedef enum { - ZAP_ALARM_NONE = 0, - ZAP_ALARM_RECOVER = (1 << 0), - ZAP_ALARM_LOOPBACK = (1 << 2), - ZAP_ALARM_YELLOW = (1 << 3), - ZAP_ALARM_RED = (1 << 4), - ZAP_ALARM_BLUE = (1 << 5), - ZAP_ALARM_NOTOPEN = ( 1 << 6), - ZAP_ALARM_AIS = ( 1 << 7), - ZAP_ALARM_RAI = ( 1 << 8), - ZAP_ALARM_GENERAL = ( 1 << 30) -} zap_alarm_flag_t; - -typedef enum { - ZAP_SIGTYPE_NONE, - ZAP_SIGTYPE_ISDN, - ZAP_SIGTYPE_RBS, - ZAP_SIGTYPE_ANALOG, - ZAP_SIGTYPE_SANGOMABOOST, - ZAP_SIGTYPE_M3UA, - ZAP_SIGTYPE_R2 -} zap_signal_type_t; - -/*! - \brief Signaling status on a given span or specific channel on protocols that support it - */ -typedef enum { - /* The signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */ - ZAP_SIG_STATE_DOWN, - /* The signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */ - ZAP_SIG_STATE_SUSPENDED, - /* The signaling link is ready and calls can be placed */ - ZAP_SIG_STATE_UP, - /* Invalid status */ - ZAP_SIG_STATE_INVALID -} zap_signaling_status_t; -#define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_signaling_status, zap_signaling_status2str, zap_signaling_status_t) - -typedef enum { - ZAP_SIGEVENT_START, - ZAP_SIGEVENT_STOP, - ZAP_SIGEVENT_TRANSFER, - ZAP_SIGEVENT_ANSWER, - ZAP_SIGEVENT_UP, - ZAP_SIGEVENT_FLASH, - ZAP_SIGEVENT_PROGRESS, - ZAP_SIGEVENT_PROGRESS_MEDIA, - ZAP_SIGEVENT_NOTIFY, - ZAP_SIGEVENT_TONE_DETECTED, - ZAP_SIGEVENT_ALARM_TRAP, - ZAP_SIGEVENT_ALARM_CLEAR, - ZAP_SIGEVENT_MISC, - ZAP_SIGEVENT_COLLECTED_DIGIT, - ZAP_SIGEVENT_ADD_CALL, - ZAP_SIGEVENT_RESTART, - /* Signaling link status changed (D-chan up, down, R2 blocked etc) */ - ZAP_SIGEVENT_SIGSTATUS_CHANGED, - /* Hardware link status changed (Line connected, disconnected) */ - ZAP_SIGEVENT_HWSTATUS_CHANGED, - ZAP_SIGEVENT_INVALID -} zap_signal_event_t; -#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \ - "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", \ - "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGLINK_CHANGED", "HWSTATUS_CHANGED", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t) - -typedef enum { - ZAP_EVENT_NONE, - ZAP_EVENT_DTMF, - ZAP_EVENT_OOB, - ZAP_EVENT_COUNT -} zap_event_type_t; - -typedef enum { - ZAP_TOP_DOWN, - ZAP_BOTTOM_UP -} zap_direction_t; - -typedef enum { - ZAP_SUCCESS, - ZAP_FAIL, - ZAP_MEMERR, - ZAP_TIMEOUT, - ZAP_NOTIMPL, - ZAP_CHECKSUM_ERROR, - ZAP_STATUS_COUNT, - ZAP_BREAK -} zap_status_t; - -typedef enum { - ZAP_NO_FLAGS = 0, - ZAP_READ = (1 << 0), - ZAP_WRITE = (1 << 1), - ZAP_EVENTS = (1 << 2) -} zap_wait_flag_t; - -typedef enum { - ZAP_CODEC_ULAW = 0, - ZAP_CODEC_ALAW = 8, - ZAP_CODEC_SLIN = 10, - ZAP_CODEC_NONE = (1 << 30) -} zap_codec_t; - -typedef enum { - ZAP_TONE_DTMF = (1 << 0) -} zap_tone_type_t; - -typedef enum { - ZAP_COMMAND_NOOP, - ZAP_COMMAND_SET_INTERVAL, - ZAP_COMMAND_GET_INTERVAL, - ZAP_COMMAND_SET_CODEC, - ZAP_COMMAND_GET_CODEC, - ZAP_COMMAND_SET_NATIVE_CODEC, - ZAP_COMMAND_GET_NATIVE_CODEC, - ZAP_COMMAND_ENABLE_DTMF_DETECT, - ZAP_COMMAND_DISABLE_DTMF_DETECT, - ZAP_COMMAND_SEND_DTMF, - ZAP_COMMAND_SET_DTMF_ON_PERIOD, - ZAP_COMMAND_GET_DTMF_ON_PERIOD, - ZAP_COMMAND_SET_DTMF_OFF_PERIOD, - ZAP_COMMAND_GET_DTMF_OFF_PERIOD, - ZAP_COMMAND_GENERATE_RING_ON, - ZAP_COMMAND_GENERATE_RING_OFF, - ZAP_COMMAND_OFFHOOK, - ZAP_COMMAND_ONHOOK, - ZAP_COMMAND_FLASH, - ZAP_COMMAND_WINK, - ZAP_COMMAND_ENABLE_PROGRESS_DETECT, - ZAP_COMMAND_DISABLE_PROGRESS_DETECT, - ZAP_COMMAND_TRACE_INPUT, - ZAP_COMMAND_TRACE_OUTPUT, - ZAP_COMMAND_ENABLE_CALLERID_DETECT, - ZAP_COMMAND_DISABLE_CALLERID_DETECT, - ZAP_COMMAND_ENABLE_ECHOCANCEL, - ZAP_COMMAND_DISABLE_ECHOCANCEL, - ZAP_COMMAND_ENABLE_ECHOTRAIN, - ZAP_COMMAND_DISABLE_ECHOTRAIN, - ZAP_COMMAND_SET_CAS_BITS, - ZAP_COMMAND_GET_CAS_BITS, - ZAP_COMMAND_SET_RX_GAIN, - ZAP_COMMAND_GET_RX_GAIN, - ZAP_COMMAND_SET_TX_GAIN, - ZAP_COMMAND_GET_TX_GAIN, - ZAP_COMMAND_FLUSH_TX_BUFFERS, - ZAP_COMMAND_FLUSH_RX_BUFFERS, - ZAP_COMMAND_FLUSH_BUFFERS, - ZAP_COMMAND_SET_PRE_BUFFER_SIZE, - ZAP_COMMAND_SET_LINK_STATUS, - ZAP_COMMAND_GET_LINK_STATUS, - ZAP_COMMAND_COUNT -} zap_command_t; - -typedef enum { - ZAP_SPAN_CONFIGURED = (1 << 0), - ZAP_SPAN_READY = (1 << 1), - ZAP_SPAN_STATE_CHANGE = (1 << 2), - ZAP_SPAN_SUSPENDED = (1 << 3), - ZAP_SPAN_IN_THREAD = (1 << 4), - ZAP_SPAN_STOP_THREAD = (1 << 5) -} zap_span_flag_t; - -typedef enum { - ZAP_CHAN_TYPE_B, - ZAP_CHAN_TYPE_DQ921, - ZAP_CHAN_TYPE_DQ931, - ZAP_CHAN_TYPE_FXS, - ZAP_CHAN_TYPE_FXO, - ZAP_CHAN_TYPE_EM, - ZAP_CHAN_TYPE_CAS, - ZAP_CHAN_TYPE_COUNT -} zap_chan_type_t; - -#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t) - -typedef enum { - ZAP_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0), - ZAP_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1), - ZAP_CHANNEL_FEATURE_CODECS = (1 << 2), - ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 3), - ZAP_CHANNEL_FEATURE_CALLERID = (1 << 4), - ZAP_CHANNEL_FEATURE_PROGRESS = (1 << 5) -} zap_channel_feature_t; - -typedef enum { - ZAP_CHANNEL_STATE_DOWN, - ZAP_CHANNEL_STATE_HOLD, - ZAP_CHANNEL_STATE_SUSPENDED, - ZAP_CHANNEL_STATE_DIALTONE, - ZAP_CHANNEL_STATE_COLLECT, - ZAP_CHANNEL_STATE_RING, - ZAP_CHANNEL_STATE_BUSY, - ZAP_CHANNEL_STATE_ATTN, - ZAP_CHANNEL_STATE_GENRING, - ZAP_CHANNEL_STATE_DIALING, - ZAP_CHANNEL_STATE_GET_CALLERID, - ZAP_CHANNEL_STATE_CALLWAITING, - ZAP_CHANNEL_STATE_RESTART, - ZAP_CHANNEL_STATE_PROGRESS, - ZAP_CHANNEL_STATE_PROGRESS_MEDIA, - ZAP_CHANNEL_STATE_UP, - ZAP_CHANNEL_STATE_IDLE, - ZAP_CHANNEL_STATE_TERMINATING, - ZAP_CHANNEL_STATE_CANCEL, - ZAP_CHANNEL_STATE_HANGUP, - ZAP_CHANNEL_STATE_HANGUP_COMPLETE, - ZAP_CHANNEL_STATE_INVALID -} zap_channel_state_t; -#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ - "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ - "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID" -ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t) - -typedef enum { - ZAP_CHANNEL_CONFIGURED = (1 << 0), - ZAP_CHANNEL_READY = (1 << 1), - ZAP_CHANNEL_OPEN = (1 << 2), - ZAP_CHANNEL_DTMF_DETECT = (1 << 3), - ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4), - ZAP_CHANNEL_TRANSCODE = (1 << 5), - ZAP_CHANNEL_BUFFER = (1 << 6), - ZAP_CHANNEL_EVENT = (1 << 7), - ZAP_CHANNEL_INTHREAD = (1 << 8), - ZAP_CHANNEL_WINK = (1 << 9), - ZAP_CHANNEL_FLASH = (1 << 10), - ZAP_CHANNEL_STATE_CHANGE = (1 << 11), - ZAP_CHANNEL_HOLD = (1 << 12), - ZAP_CHANNEL_INUSE = (1 << 13), - ZAP_CHANNEL_OFFHOOK = (1 << 14), - ZAP_CHANNEL_RINGING = (1 << 15), - ZAP_CHANNEL_PROGRESS_DETECT = (1 << 16), - ZAP_CHANNEL_CALLERID_DETECT = (1 << 17), - ZAP_CHANNEL_OUTBOUND = (1 << 18), - ZAP_CHANNEL_SUSPENDED = (1 << 19), - ZAP_CHANNEL_3WAY = (1 << 20), - ZAP_CHANNEL_PROGRESS = (1 << 21), - ZAP_CHANNEL_MEDIA = (1 << 22), - ZAP_CHANNEL_ANSWERED = (1 << 23), - ZAP_CHANNEL_MUTE = (1 << 24), - ZAP_CHANNEL_USE_RX_GAIN = (1 << 25), - ZAP_CHANNEL_USE_TX_GAIN = (1 << 26), -} zap_channel_flag_t; -#if defined(__cplusplus) && defined(WIN32) - // fix C2676 -__inline__ zap_channel_flag_t operator|=(zap_channel_flag_t a, int32_t b) { - a = (zap_channel_flag_t)(a | b); - return a; -} -__inline__ zap_channel_flag_t operator&=(zap_channel_flag_t a, int32_t b) { - a = (zap_channel_flag_t)(a & b); - return a; -} -#endif - -typedef enum { - ZSM_NONE, - ZSM_UNACCEPTABLE, - ZSM_ACCEPTABLE -} zap_state_map_type_t; - -typedef enum { - ZSD_INBOUND, - ZSD_OUTBOUND, -} zap_state_direction_t; - -#define ZAP_MAP_NODE_SIZE 512 -#define ZAP_MAP_MAX ZAP_CHANNEL_STATE_INVALID+2 - -struct zap_state_map_node { - zap_state_direction_t direction; - zap_state_map_type_t type; - zap_channel_state_t check_states[ZAP_MAP_MAX]; - zap_channel_state_t states[ZAP_MAP_MAX]; -}; -typedef struct zap_state_map_node zap_state_map_node_t; - -struct zap_state_map { - zap_state_map_node_t nodes[ZAP_MAP_NODE_SIZE]; -}; -typedef struct zap_state_map zap_state_map_t; - -typedef enum zap_channel_hw_link_status { - ZAP_HW_LINK_DISCONNECTED = 0, - ZAP_HW_LINK_CONNECTED -} zap_channel_hw_link_status_t; - -typedef struct zap_conf_parameter_s { - const char *var; - const char *val; -} zap_conf_parameter_t; - -typedef struct zap_channel zap_channel_t; -typedef struct zap_event zap_event_t; -typedef struct zap_sigmsg zap_sigmsg_t; -typedef struct zap_span zap_span_t; -typedef struct zap_group zap_group_t; -typedef struct zap_caller_data zap_caller_data_t; -typedef struct zap_io_interface zap_io_interface_t; - -struct zap_stream_handle; -typedef struct zap_stream_handle zap_stream_handle_t; - -typedef zap_status_t (*zap_stream_handle_raw_write_function_t) (zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen); -typedef zap_status_t (*zap_stream_handle_write_function_t) (zap_stream_handle_t *handle, const char *fmt, ...); - -#define ZIO_CHANNEL_REQUEST_ARGS (zap_span_t *span, uint32_t chan_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) -#define ZIO_CHANNEL_OUTGOING_CALL_ARGS (zap_channel_t *zchan) -#define ZIO_CHANNEL_SET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t status) -#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (zap_channel_t *zchan, zap_signaling_status_t *status) -#define ZIO_SPAN_SET_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t status) -#define ZIO_SPAN_GET_SIG_STATUS_ARGS (zap_span_t *span, zap_signaling_status_t *status) -#define ZIO_SPAN_POLL_EVENT_ARGS (zap_span_t *span, uint32_t ms) -#define ZIO_SPAN_NEXT_EVENT_ARGS (zap_span_t *span, zap_event_t **event) -#define ZIO_SIGNAL_CB_ARGS (zap_sigmsg_t *sigmsg) -#define ZIO_EVENT_CB_ARGS (zap_channel_t *zchan, zap_event_t *event) -#define ZIO_CODEC_ARGS (void *data, zap_size_t max, zap_size_t *datalen) -#define ZIO_CONFIGURE_SPAN_ARGS (zap_span_t *span, const char *str, zap_chan_type_t type, char *name, char *number) -#define ZIO_CONFIGURE_ARGS (const char *category, const char *var, const char *val, int lineno) -#define ZIO_OPEN_ARGS (zap_channel_t *zchan) -#define ZIO_CLOSE_ARGS (zap_channel_t *zchan) -#define ZIO_CHANNEL_DESTROY_ARGS (zap_channel_t *zchan) -#define ZIO_SPAN_DESTROY_ARGS (zap_span_t *span) -#define ZIO_COMMAND_ARGS (zap_channel_t *zchan, zap_command_t command, void *obj) -#define ZIO_WAIT_ARGS (zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) -#define ZIO_GET_ALARMS_ARGS (zap_channel_t *zchan) -#define ZIO_READ_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) -#define ZIO_WRITE_ARGS (zap_channel_t *zchan, void *data, zap_size_t *datalen) -#define ZIO_IO_LOAD_ARGS (zap_io_interface_t **zio) -#define ZIO_IO_UNLOAD_ARGS (void) -#define ZIO_SIG_LOAD_ARGS (void) -#define ZIO_SIG_CONFIGURE_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, va_list ap) -#define ZIO_CONFIGURE_SPAN_SIGNALING_ARGS (zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *zap_parameters) -#define ZIO_SIG_UNLOAD_ARGS (void) -#define ZIO_API_ARGS (zap_stream_handle_t *stream, const char *data) - -typedef zap_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; -typedef zap_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ; -typedef zap_status_t (*zio_channel_set_sig_status_t) ZIO_CHANNEL_SET_SIG_STATUS_ARGS; -typedef zap_status_t (*zio_channel_get_sig_status_t) ZIO_CHANNEL_GET_SIG_STATUS_ARGS; -typedef zap_status_t (*zio_span_set_sig_status_t) ZIO_SPAN_SET_SIG_STATUS_ARGS; -typedef zap_status_t (*zio_span_get_sig_status_t) ZIO_SPAN_GET_SIG_STATUS_ARGS; -typedef zap_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ; -typedef zap_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ; -typedef zap_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ; -typedef zap_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ; -typedef zap_status_t (*zio_codec_t) ZIO_CODEC_ARGS ; -typedef zap_status_t (*zio_configure_span_t) ZIO_CONFIGURE_SPAN_ARGS ; -typedef zap_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ; -typedef zap_status_t (*zio_open_t) ZIO_OPEN_ARGS ; -typedef zap_status_t (*zio_close_t) ZIO_CLOSE_ARGS ; -typedef zap_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_DESTROY_ARGS ; -typedef zap_status_t (*zio_span_destroy_t) ZIO_SPAN_DESTROY_ARGS ; -typedef zap_status_t (*zio_get_alarms_t) ZIO_GET_ALARMS_ARGS ; -typedef zap_status_t (*zio_command_t) ZIO_COMMAND_ARGS ; -typedef zap_status_t (*zio_wait_t) ZIO_WAIT_ARGS ; -typedef zap_status_t (*zio_read_t) ZIO_READ_ARGS ; -typedef zap_status_t (*zio_write_t) ZIO_WRITE_ARGS ; -typedef zap_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ; -typedef zap_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ; -typedef zap_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ; -typedef zap_status_t (*zio_configure_span_signaling_t) ZIO_CONFIGURE_SPAN_SIGNALING_ARGS ; -typedef zap_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ; -typedef zap_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ; -typedef zap_status_t (*zio_api_t) ZIO_API_ARGS ; - - -#define ZIO_CHANNEL_REQUEST_FUNCTION(name) zap_status_t name ZIO_CHANNEL_REQUEST_ARGS -#define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) zap_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS -#define ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_SET_SIG_STATUS_ARGS -#define ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_CHANNEL_GET_SIG_STATUS_ARGS -#define ZIO_SPAN_SET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_SPAN_SET_SIG_STATUS_ARGS -#define ZIO_SPAN_GET_SIG_STATUS_FUNCTION(name) zap_status_t name ZIO_SPAN_GET_SIG_STATUS_ARGS -#define ZIO_SPAN_POLL_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_POLL_EVENT_ARGS -#define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) zap_status_t name ZIO_SPAN_NEXT_EVENT_ARGS -#define ZIO_SIGNAL_CB_FUNCTION(name) zap_status_t name ZIO_SIGNAL_CB_ARGS -#define ZIO_EVENT_CB_FUNCTION(name) zap_status_t name ZIO_EVENT_CB_ARGS -#define ZIO_CODEC_FUNCTION(name) OZ_DECLARE_NONSTD(zap_status_t) name ZIO_CODEC_ARGS -#define ZIO_CONFIGURE_SPAN_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_ARGS -#define ZIO_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_ARGS -#define ZIO_OPEN_FUNCTION(name) zap_status_t name ZIO_OPEN_ARGS -#define ZIO_CLOSE_FUNCTION(name) zap_status_t name ZIO_CLOSE_ARGS -#define ZIO_CHANNEL_DESTROY_FUNCTION(name) zap_status_t name ZIO_CHANNEL_DESTROY_ARGS -#define ZIO_SPAN_DESTROY_FUNCTION(name) zap_status_t name ZIO_SPAN_DESTROY_ARGS -#define ZIO_GET_ALARMS_FUNCTION(name) zap_status_t name ZIO_GET_ALARMS_ARGS -#define ZIO_COMMAND_FUNCTION(name) zap_status_t name ZIO_COMMAND_ARGS -#define ZIO_WAIT_FUNCTION(name) zap_status_t name ZIO_WAIT_ARGS -#define ZIO_READ_FUNCTION(name) zap_status_t name ZIO_READ_ARGS -#define ZIO_WRITE_FUNCTION(name) zap_status_t name ZIO_WRITE_ARGS -#define ZIO_IO_LOAD_FUNCTION(name) zap_status_t name ZIO_IO_LOAD_ARGS -#define ZIO_SIG_LOAD_FUNCTION(name) zap_status_t name ZIO_SIG_LOAD_ARGS -#define ZIO_SIG_CONFIGURE_FUNCTION(name) zap_status_t name ZIO_SIG_CONFIGURE_ARGS -#define ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) zap_status_t name ZIO_CONFIGURE_SPAN_SIGNALING_ARGS -#define ZIO_IO_UNLOAD_FUNCTION(name) zap_status_t name ZIO_IO_UNLOAD_ARGS -#define ZIO_SIG_UNLOAD_FUNCTION(name) zap_status_t name ZIO_SIG_UNLOAD_ARGS -#define ZIO_API_FUNCTION(name) zap_status_t name ZIO_API_ARGS - -#include "zap_dso.h" - -typedef struct { - char name[256]; - zio_io_load_t io_load; - zio_io_unload_t io_unload; - zio_sig_load_t sig_load; - zio_sig_configure_t sig_configure; - zio_sig_unload_t sig_unload; - /*! - \brief configure a given span signaling - \see sig_configure - This is just like sig_configure but receives - an array of paramters instead of va_list - I'd like to deprecate sig_configure and move - all modules to use sigparam_configure - */ - zio_configure_span_signaling_t configure_span_signaling; - zap_dso_lib_t lib; - char path[256]; -} zap_module_t; - -#ifndef __FUNCTION__ -#define __FUNCTION__ (const char *)__func__ -#endif - -#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__ -#define ZAP_LOG_LEVEL_DEBUG 7 -#define ZAP_LOG_LEVEL_INFO 6 -#define ZAP_LOG_LEVEL_NOTICE 5 -#define ZAP_LOG_LEVEL_WARNING 4 -#define ZAP_LOG_LEVEL_ERROR 3 -#define ZAP_LOG_LEVEL_CRIT 2 -#define ZAP_LOG_LEVEL_ALERT 1 -#define ZAP_LOG_LEVEL_EMERG 0 - -#define ZAP_LOG_DEBUG ZAP_PRE, ZAP_LOG_LEVEL_DEBUG -#define ZAP_LOG_INFO ZAP_PRE, ZAP_LOG_LEVEL_INFO -#define ZAP_LOG_NOTICE ZAP_PRE, ZAP_LOG_LEVEL_NOTICE -#define ZAP_LOG_WARNING ZAP_PRE, ZAP_LOG_LEVEL_WARNING -#define ZAP_LOG_ERROR ZAP_PRE, ZAP_LOG_LEVEL_ERROR -#define ZAP_LOG_CRIT ZAP_PRE, ZAP_LOG_LEVEL_CRIT -#define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT -#define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG - -typedef struct zap_fsk_data_state zap_fsk_data_state_t; -typedef int (*zap_fsk_data_decoder_t)(zap_fsk_data_state_t *state); -typedef zap_status_t (*zap_fsk_write_sample_t)(int16_t *buf, zap_size_t buflen, void *user_data); -typedef void (*zap_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...); -typedef struct hashtable zap_hash_t; -typedef struct hashtable_iterator zap_hash_iterator_t; -typedef struct key zap_hash_key_t; -typedef struct value zap_hash_val_t; -typedef struct zap_bitstream zap_bitstream_t; -typedef struct zap_fsk_modulator zap_fsk_modulator_t; -typedef zap_status_t (*zap_span_start_t)(zap_span_t *span); -typedef zap_status_t (*zap_span_stop_t)(zap_span_t *span); - -typedef enum { - ZAP_CAUSE_NONE = 0, - ZAP_CAUSE_UNALLOCATED = 1, - ZAP_CAUSE_NO_ROUTE_TRANSIT_NET = 2, - ZAP_CAUSE_NO_ROUTE_DESTINATION = 3, - ZAP_CAUSE_CHANNEL_UNACCEPTABLE = 6, - ZAP_CAUSE_CALL_AWARDED_DELIVERED = 7, - ZAP_CAUSE_NORMAL_CLEARING = 16, - ZAP_CAUSE_USER_BUSY = 17, - ZAP_CAUSE_NO_USER_RESPONSE = 18, - ZAP_CAUSE_NO_ANSWER = 19, - ZAP_CAUSE_SUBSCRIBER_ABSENT = 20, - ZAP_CAUSE_CALL_REJECTED = 21, - ZAP_CAUSE_NUMBER_CHANGED = 22, - ZAP_CAUSE_REDIRECTION_TO_NEW_DESTINATION = 23, - ZAP_CAUSE_EXCHANGE_ROUTING_ERROR = 25, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER = 27, - ZAP_CAUSE_INVALID_NUMBER_FORMAT = 28, - ZAP_CAUSE_FACILITY_REJECTED = 29, - ZAP_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30, - ZAP_CAUSE_NORMAL_UNSPECIFIED = 31, - ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34, - ZAP_CAUSE_NETWORK_OUT_OF_ORDER = 38, - ZAP_CAUSE_NORMAL_TEMPORARY_FAILURE = 41, - ZAP_CAUSE_SWITCH_CONGESTION = 42, - ZAP_CAUSE_ACCESS_INFO_DISCARDED = 43, - ZAP_CAUSE_REQUESTED_CHAN_UNAVAIL = 44, - ZAP_CAUSE_PRE_EMPTED = 45, - ZAP_CAUSE_FACILITY_NOT_SUBSCRIBED = 50, - ZAP_CAUSE_OUTGOING_CALL_BARRED = 52, - ZAP_CAUSE_INCOMING_CALL_BARRED = 54, - ZAP_CAUSE_BEARERCAPABILITY_NOTAUTH = 57, - ZAP_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58, - ZAP_CAUSE_SERVICE_UNAVAILABLE = 63, - ZAP_CAUSE_BEARERCAPABILITY_NOTIMPL = 65, - ZAP_CAUSE_CHAN_NOT_IMPLEMENTED = 66, - ZAP_CAUSE_FACILITY_NOT_IMPLEMENTED = 69, - ZAP_CAUSE_SERVICE_NOT_IMPLEMENTED = 79, - ZAP_CAUSE_INVALID_CALL_REFERENCE = 81, - ZAP_CAUSE_INCOMPATIBLE_DESTINATION = 88, - ZAP_CAUSE_INVALID_MSG_UNSPECIFIED = 95, - ZAP_CAUSE_MANDATORY_IE_MISSING = 96, - ZAP_CAUSE_MESSAGE_TYPE_NONEXIST = 97, - ZAP_CAUSE_WRONG_MESSAGE = 98, - ZAP_CAUSE_IE_NONEXIST = 99, - ZAP_CAUSE_INVALID_IE_CONTENTS = 100, - ZAP_CAUSE_WRONG_CALL_STATE = 101, - ZAP_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102, - ZAP_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103, - ZAP_CAUSE_PROTOCOL_ERROR = 111, - ZAP_CAUSE_INTERWORKING = 127, - ZAP_CAUSE_SUCCESS = 142, - ZAP_CAUSE_ORIGINATOR_CANCEL = 487, - ZAP_CAUSE_CRASH = 500, - ZAP_CAUSE_SYSTEM_SHUTDOWN = 501, - ZAP_CAUSE_LOSE_RACE = 502, - ZAP_CAUSE_MANAGER_REQUEST = 503, - ZAP_CAUSE_BLIND_TRANSFER = 600, - ZAP_CAUSE_ATTENDED_TRANSFER = 601, - ZAP_CAUSE_ALLOTTED_TIMEOUT = 602, - ZAP_CAUSE_USER_CHALLENGE = 603, - ZAP_CAUSE_MEDIA_TIMEOUT = 604 -} zap_call_cause_t; - -#ifdef __cplusplus -} -#endif - -#endif - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ - diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 9cfd08a07c..d1cbab6e6f 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -79,7 +79,7 @@ #include #include -#include "openzap.h" +#include "freetdm.h" #include "Q921.h" #include "Q921priv.h" #include "mfifo.h" @@ -398,7 +398,7 @@ int Q921_InitTrunk(L2TRUNK trunk, /* * Allocate space for per-link context(s) */ - trunk->context = zap_malloc(numlinks * sizeof(struct Q921_Link)); + trunk->context = ftdm_malloc(numlinks * sizeof(struct Q921_Link)); if(!trunk->context) return -1; diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index c261772f92..f79c615a36 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -34,7 +34,7 @@ */ #include -#include "openzap.h" +#include "freetdm.h" #define SMAX 32767 #define SMIN -32768 @@ -111,7 +111,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b ts->decay_step = 0; ts->decay_factor = 1; if (buflen) { - if ((ts->buffer = zap_calloc(buflen, sizeof(teletone_audio_t))) == 0) { + if ((ts->buffer = ftdm_calloc(buflen, sizeof(teletone_audio_t))) == 0) { return -1; } ts->datalen = buflen; @@ -142,7 +142,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts) { if (ts->buffer) { - zap_safe_free(ts->buffer); + ftdm_safe_free(ts->buffer); ts->buffer = NULL; ts->samples = 0; } @@ -280,7 +280,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm } do { - if (!(data = zap_strdup(cmd))) { + if (!(data = ftdm_strdup(cmd))) { return -1; } @@ -429,7 +429,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm } } bottom: - zap_safe_free(data); + ftdm_safe_free(data); data = NULL; if (ts->LOOPS > 0) { ts->LOOPS--; diff --git a/libs/freetdm/src/m3ua_client.c b/libs/freetdm/src/m3ua_client.c index ba33dd4317..7608183896 100644 --- a/libs/freetdm/src/m3ua_client.c +++ b/libs/freetdm/src/m3ua_client.c @@ -1,6 +1,6 @@ /* * m3ua_client.c - * openzap + * freetdm * * Created by Shane Burrell on 4/3/08. * Copyright 2008 Shane Burrell. All rights reserved. @@ -40,7 +40,7 @@ #include #endif -#include "openzap.h" +#include "freetdm.h" #include @@ -85,7 +85,7 @@ static int create_conn_socket(m3uac_connection_t *mcon, char *local_ip, int loca memset(&mcon->local_hp, 0, sizeof(mcon->local_hp)); mcon->socket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); - zap_log(ZAP_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n", + ftdm_log(FTDM_LOG_DEBUG, "Creating L=%s:%d R=%s:%d\n", local_ip,local_port,ip,port); if (mcon->socket >= 0) { @@ -115,7 +115,7 @@ static int create_conn_socket(m3uac_connection_t *mcon, char *local_ip, int loca } } - zap_mutex_create(&mcon->mutex); + ftdm_mutex_create(&mcon->mutex); return mcon->socket; } @@ -126,9 +126,9 @@ int m3uac_connection_close(m3uac_connection_t *mcon) close(mcon->socket); } - zap_mutex_lock(mcon->mutex); - zap_mutex_unlock(mcon->mutex); - zap_mutex_destroy(&mcon->mutex); + ftdm_mutex_lock(mcon->mutex); + ftdm_mutex_unlock(mcon->mutex); + ftdm_mutex_destroy(&mcon->mutex); memset(mcon, 0, sizeof(*mcon)); mcon->socket = -1; @@ -163,11 +163,11 @@ int m3uac_exec_command(m3uac_connection_t *mcon, int span, int chan, int id, int while (m3uac_connection_write(mcon, &oevent) <= 0) { if (--retry <= 0) { - zap_log(ZAP_LOG_CRIT, "Failed to tx on M3UA socket: %s\n", strerror(errno)); + ftdm_log(FTDM_LOG_CRIT, "Failed to tx on M3UA socket: %s\n", strerror(errno)); return -1; } else { - zap_log(ZAP_LOG_WARNING, "Failed to tx on M3UA socket: %s :retry %i\n", strerror(errno), retry); - zap_sleep(1); + ftdm_log(FTDM_LOG_WARNING, "Failed to tx on M3UA socket: %s :retry %i\n", strerror(errno), retry); + ftdm_sleep(1); } } @@ -188,12 +188,12 @@ m3uac_event_t *m3uac_connection_read(m3uac_connection_t *mcon, int iteration) if (mcon->rxseq_reset) { if (mcon->event.event_id == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { - zap_log(ZAP_LOG_DEBUG, "Rx sync ok\n"); + ftdm_log(FTDM_LOG_DEBUG, "Rx sync ok\n"); mcon->rxseq = mcon->event.fseqno; return &mcon->event; } errno=EAGAIN; - zap_log(ZAP_LOG_DEBUG, "Waiting for rx sync...\n"); + ftdm_log(FTDM_LOG_DEBUG, "Waiting for rx sync...\n"); return NULL; } @@ -201,14 +201,14 @@ m3uac_event_t *m3uac_connection_read(m3uac_connection_t *mcon, int iteration) mcon->rxseq++; if (mcon->rxseq != mcon->event.fseqno) { - zap_log(ZAP_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno); + ftdm_log(FTDM_LOG_CRIT, "Invalid Sequence Number Expect=%i Rx=%i\n", mcon->rxseq, mcon->event.fseqno); return NULL; } return &mcon->event; } else { if (iteration == 0) { - zap_log(ZAP_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + ftdm_log(FTDM_LOG_CRIT, "Invalid Event length from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); return NULL; } } @@ -227,7 +227,7 @@ m3uac_event_t *m3uac_connection_readp(m3uac_connection_t *mcon, int iteration) return &mcon->event; } else { if (iteration == 0) { - zap_log(ZAP_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); + ftdm_log(FTDM_LOG_CRIT, "Critical Error: PQ Invalid Event lenght from boost rxlen=%i evsz=%i\n", bytes, sizeof(mcon->event)); return NULL; } } @@ -241,28 +241,28 @@ int m3uac_connection_write(m3uac_connection_t *mcon, ss7bc_event_t *event) int err; if (!event || mcon->socket < 0 || !mcon->mutex) { - zap_log(ZAP_LOG_DEBUG, "Critical Error: No Event Device\n"); + ftdm_log(FTDM_LOG_DEBUG, "Critical Error: No Event Device\n"); return -EINVAL; } if (event->span > 16 || event->chan > 31) { - zap_log(ZAP_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", m3uac_event_id_name(event->event_id), event->span,event->chan); + ftdm_log(FTDM_LOG_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", m3uac_event_id_name(event->event_id), event->span,event->chan); return -1; } gettimeofday(&event->tv,NULL); - zap_mutex_lock(mcon->mutex); + ftdm_mutex_lock(mcon->mutex); event->fseqno = mcon->txseq++; event->bseqno = mcon->rxseq; err = sendto(mcon->socket, event, sizeof(m3uac_event_t), 0, (struct sockaddr *) &mcon->remote_addr, sizeof(mcon->remote_addr)); - zap_mutex_unlock(mcon->mutex); + ftdm_mutex_unlock(mcon->mutex); if (err != sizeof(m3uac_event_t)) { err = -1; } - zap_log(ZAP_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", + ftdm_log(FTDM_LOG_DEBUG, "TX EVENT: %s:(%X) [w%dg%d] Rc=%i CSid=%i Seq=%i Cd=[%s] Ci=[%s]\n", m3uac_event_id_name(event->event_id), event->event_id, event->span+1, diff --git a/libs/freetdm/src/m3ua_client.h b/libs/freetdm/src/m3ua_client.h index b80309017c..e451156a41 100644 --- a/libs/freetdm/src/m3ua_client.h +++ b/libs/freetdm/src/m3ua_client.h @@ -1,6 +1,6 @@ /* * m3ua_client.h - * openzap + * freetdm * * Created by Shane Burrell on 4/3/08. * Copyright 2008 Shane Burrell. All rights reserved. @@ -109,14 +109,14 @@ typedef struct m3uac_ip_cfg }m3uac_ip_cfg_t; struct m3uac_connection { - zap_socket_t socket; + ftdm_socket_t socket; struct sockaddr_in local_addr; struct sockaddr_in remote_addr; m3uac_event_t event; struct hostent remote_hp; struct hostent local_hp; unsigned int flags; - zap_mutex_t *mutex; + ftdm_mutex_t *mutex; FILE *log; unsigned int txseq; unsigned int rxseq; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c deleted file mode 100644 index 6e6a4c9664..0000000000 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ /dev/null @@ -1,977 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "openzap.h" -#include "zap_analog.h" - -#ifndef localtime_r -struct tm * localtime_r(const time_t *clock, struct tm *result); -#endif - -static void *zap_analog_channel_run(zap_thread_t *me, void *obj); - -/** - * \brief Starts an FXO channel thread (outgoing call) - * \param zchan Channel to initiate call on - * \return Success or failure - * - * Initialises state, starts tone progress detection and runs the channel in a new a thread. - */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) -{ - if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { - zap_channel_clear_needed_tones(zchan); - zap_channel_clear_detected_tones(zchan); - - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL); - zchan->needed_tones[ZAP_TONEMAP_DIAL] = 1; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); - zap_thread_create_detached(zap_analog_channel_run, zchan); - return ZAP_SUCCESS; - } - - return ZAP_FAIL; -} - -/** - * \brief Starts an FXS channel thread (outgoing call) - * \param zchan Channel to initiate call on - * \return Success or failure - * - * Indicates call waiting if channel is already in use, otherwise runs the channel in a new thread. - */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) -{ - - if (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_CALLWAITING); - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_GENRING); - zap_thread_create_detached(zap_analog_channel_run, zchan); - } - - return ZAP_SUCCESS; -} - -/** - * \brief Starts an analog span thread (monitor) - * \param span Span to monitor - * \return Success or failure - */ -static zap_status_t zap_analog_start(zap_span_t *span) -{ - zap_analog_data_t *analog_data = span->signal_data; - zap_set_flag(analog_data, ZAP_ANALOG_RUNNING); - return zap_thread_create_detached(zap_analog_run, span); -} - -/** - * \brief Initialises an analog span from configuration variables - * \param span Span to configure - * \param sig_cb Callback function for event signals - * \param ap List of configuration variables - * \return Success or failure - */ -static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) -//zap_status_t zap_analog_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb) -{ - zap_analog_data_t *analog_data; - const char *tonemap = "us"; - const char *hotline = ""; - uint32_t digit_timeout = 10; - uint32_t max_dialstr = MAX_DTMF; - const char *var, *val; - int *intval; - uint32_t flags = ZAP_ANALOG_CALLERID; - - assert(sig_cb != NULL); - - if (span->signal_type) { - snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); - return ZAP_FAIL; - } - - analog_data = zap_malloc(sizeof(*analog_data)); - assert(analog_data != NULL); - memset(analog_data, 0, sizeof(*analog_data)); - - while ((var = va_arg(ap, char *))) { - if (!strcasecmp(var, "tonemap")) { - if (!(val = va_arg(ap, char *))) { - break; - } - tonemap = val; - } else if (!strcasecmp(var, "digit_timeout")) { - if (!(intval = va_arg(ap, int *))) { - break; - } - digit_timeout = *intval; - } else if (!strcasecmp(var, "enable_callerid")) { - if (!(val = va_arg(ap, char *))) { - break; - } - - if (zap_true(val)) { - flags |= ZAP_ANALOG_CALLERID; - } else { - flags &= ~ZAP_ANALOG_CALLERID; - } - } else if (!strcasecmp(var, "max_dialstr")) { - if (!(intval = va_arg(ap, int *))) { - break; - } - max_dialstr = *intval; - } else if (!strcasecmp(var, "hotline")) { - if (!(val = va_arg(ap, char *))) { - break; - } - hotline = val; - } else { - snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); - return ZAP_FAIL; - } - } - - - if (digit_timeout < 2000 || digit_timeout > 10000) { - digit_timeout = 2000; - } - - if ((max_dialstr < 1 && !strlen(hotline)) || max_dialstr > MAX_DTMF) { - max_dialstr = MAX_DTMF; - } - - span->start = zap_analog_start; - analog_data->flags = flags; - analog_data->digit_timeout = digit_timeout; - analog_data->max_dialstr = max_dialstr; - analog_data->sig_cb = sig_cb; - strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline)); - span->signal_type = ZAP_SIGTYPE_ANALOG; - span->signal_data = analog_data; - span->outgoing_call = span->trunk_type == ZAP_TRUNK_FXS ? analog_fxs_outgoing_call : analog_fxo_outgoing_call; - zap_span_load_tones(span, tonemap); - - return ZAP_SUCCESS; - -} - -/** - * \brief Retrieves tone generation output to be sent - * \param ts Teletone generator - * \param map Tone map - * \return -1 on error, 0 on success - */ -static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map) -{ - zap_buffer_t *dt_buffer = ts->user_data; - int wrote; - - if (!dt_buffer) { - return -1; - } - wrote = teletone_mux_tones(ts, map); - zap_buffer_write(dt_buffer, ts->buffer, wrote * 2); - return 0; -} - -/** - * \brief Sends caller id on an analog channel (FSK coded) - * \param zchan Channel to send caller id on - */ -static void send_caller_id(zap_channel_t *zchan) -{ - zap_fsk_data_state_t fsk_data; - uint8_t databuf[1024] = ""; - char time_str[9]; - struct tm tm; - time_t now; - zap_mdmf_type_t mt = MDMF_INVALID; - - time(&now); -#ifdef WIN32 - _tzset(); - _localtime64_s(&tm, &now); -#else - localtime_r(&now, &tm); -#endif - strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm); - - zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *) time_str, 8); - - if (zap_strlen_zero(zchan->caller_data.cid_num.digits)) { - mt = MDMF_NO_NUM; - zap_set_string(zchan->caller_data.cid_num.digits, "O"); - } else if (!strcasecmp(zchan->caller_data.cid_num.digits, "P") || !strcasecmp(zchan->caller_data.cid_num.digits, "O")) { - mt = MDMF_NO_NUM; - } else { - mt = MDMF_PHONE_NUM; - } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_num.digits, (uint8_t)strlen(zchan->caller_data.cid_num.digits)); - - if (zap_strlen_zero(zchan->caller_data.cid_name)) { - mt = MDMF_NO_NAME; - zap_set_string(zchan->caller_data.cid_name, "O"); - } else if (!strcasecmp(zchan->caller_data.cid_name, "P") || !strcasecmp(zchan->caller_data.cid_name, "O")) { - mt = MDMF_NO_NAME; - } else { - mt = MDMF_PHONE_NAME; - } - zap_fsk_data_add_mdmf(&fsk_data, mt, (uint8_t *) zchan->caller_data.cid_name, (uint8_t)strlen(zchan->caller_data.cid_name)); - - zap_fsk_data_add_checksum(&fsk_data); - zap_channel_send_fsk_data(zchan, &fsk_data, -14); -} - -/** - * \brief Main thread function for analog channel (outgoing call) - * \param me Current thread - * \param obj Channel to run in this thread - */ -static void *zap_analog_channel_run(zap_thread_t *me, void *obj) -{ - zap_channel_t *zchan = (zap_channel_t *) obj; - zap_buffer_t *dt_buffer = NULL; - teletone_generation_session_t ts; - uint8_t frame[1024]; - zap_size_t len, rlen; - zap_tone_type_t tt = ZAP_TONE_DTMF; - char dtmf[MAX_DTMF+1] = ""; - zap_size_t dtmf_offset = 0; - zap_analog_data_t *analog_data = zchan->span->signal_data; - zap_channel_t *closed_chan; - uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; - zap_sigmsg_t sig; - zap_status_t status; - - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); - - ts.buffer = NULL; - - if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); - goto done; - } - - if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!"); - zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); - goto done; - } - - if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!"); - zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); - goto done; - } - - zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD); - teletone_init_session(&ts, 0, teletone_handler, dt_buffer); - ts.rate = 8000; -#if 0 - ts.debug = 1; - ts.debug_stream = stdout; -#endif - zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); - zap_buffer_set_loops(dt_buffer, -1); - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - - assert(interval != 0); - - while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { - zap_wait_flag_t flags = ZAP_READ; - zap_size_t dlen = 0; - - len = sizeof(frame); - - elapsed += interval; - state_counter += interval; - - if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) { - switch(zchan->state) { - case ZAP_CHANNEL_STATE_GET_CALLERID: - { - if (state_counter > 5000 || !zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { - zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); - } - } - break; - case ZAP_CHANNEL_STATE_DIALING: - { - if (state_counter > dial_timeout) { - if (zchan->needed_tones[ZAP_TONEMAP_DIAL]) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } - } - } - break; - case ZAP_CHANNEL_STATE_GENRING: - { - if (state_counter > 60000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } else if (!zchan->fsk_buffer || !zap_buffer_inuse(zchan->fsk_buffer)) { - zap_sleep(interval); - continue; - } - } - break; - case ZAP_CHANNEL_STATE_DIALTONE: - { - if (!zap_test_flag(zchan, ZAP_CHANNEL_HOLD) && state_counter > 10000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } - } - break; - case ZAP_CHANNEL_STATE_BUSY: - { - if (state_counter > 20000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN); - } - } - break; - case ZAP_CHANNEL_STATE_ATTN: - { - if (state_counter > 20000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - break; - case ZAP_CHANNEL_STATE_HANGUP: - { - if (state_counter > 500) { - if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && - (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE - || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - } - break; - case ZAP_CHANNEL_STATE_CALLWAITING: - { - int done = 0; - - if (zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] == 1) { - send_caller_id(zchan); - zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else if (state_counter > 600 && !zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { - send_caller_id(zchan); - zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else if (state_counter > 1000 && !zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]) { - done = 1; - } else if (state_counter > 10000) { - if (zchan->fsk_buffer) { - zap_buffer_zero(zchan->fsk_buffer); - } else { - zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); - } - - ts.user_data = zchan->fsk_buffer; - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); - ts.user_data = dt_buffer; - done = 1; - } - - if (done) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); - zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; - } - } - case ZAP_CHANNEL_STATE_UP: - case ZAP_CHANNEL_STATE_IDLE: - { - zap_sleep(interval); - continue; - } - break; - case ZAP_CHANNEL_STATE_DOWN: - { - goto done; - } - break; - default: - break; - } - } else { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); - zap_channel_complete_state(zchan); - indicate = 0; - state_counter = 0; - - zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", - zchan->span_id, zchan->chan_id, - zap_channel_state2str(zchan->state)); - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: - { - zap_channel_use(zchan); - zap_channel_clear_needed_tones(zchan); - zap_channel_flush_dtmf(zchan); - - if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - } - - if (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer)) { - zap_log(ZAP_LOG_DEBUG, "Cancel FSK transmit due to early answer.\n"); - zap_buffer_zero(zchan->fsk_buffer); - } - - if (zchan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } - - if (zchan->token_count == 1) { - zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_HOLD)) { - zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); - sig.event_id = ZAP_SIGEVENT_ADD_CALL; - } else { - sig.event_id = ZAP_SIGEVENT_UP; - } - - analog_data->sig_cb(&sig); - continue; - } - break; - case ZAP_CHANNEL_STATE_DIALING: - { - zap_channel_use(zchan); - } - break; - case ZAP_CHANNEL_STATE_IDLE: - { - zap_channel_use(zchan); - sig.event_id = ZAP_SIGEVENT_START; - - if (zchan->type == ZAP_CHAN_TYPE_FXO) { - zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number); - } else { - zap_set_string(zchan->caller_data.dnis.digits, dtmf); - } - - analog_data->sig_cb(&sig); - continue; - } - break; - case ZAP_CHANNEL_STATE_DOWN: - { - sig.event_id = ZAP_SIGEVENT_STOP; - analog_data->sig_cb(&sig); - goto done; - } - break; - case ZAP_CHANNEL_STATE_DIALTONE: - { - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - *dtmf = '\0'; - dtmf_offset = 0; - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); - indicate = 1; - } - break; - case ZAP_CHANNEL_STATE_CALLWAITING: - { - zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; - if (zchan->fsk_buffer) { - zap_buffer_zero(zchan->fsk_buffer); - } else { - zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); - } - - ts.user_data = zchan->fsk_buffer; - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_SAS]); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_CALLWAITING_CAS]); - ts.user_data = dt_buffer; - } - break; - case ZAP_CHANNEL_STATE_GENRING: - { - zap_sigmsg_t sig; - - send_caller_id(zchan); - zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_ON, NULL); - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - sig.event_id = ZAP_SIGEVENT_PROGRESS; - analog_data->sig_cb(&sig); - - } - break; - case ZAP_CHANNEL_STATE_GET_CALLERID: - { - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - zap_channel_command(zchan, ZAP_COMMAND_ENABLE_CALLERID_DETECT, NULL); - continue; - } - break; - case ZAP_CHANNEL_STATE_RING: - { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]); - indicate = 1; - - } - break; - case ZAP_CHANNEL_STATE_BUSY: - { - zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION; - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); - indicate = 1; - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - break; - case ZAP_CHANNEL_STATE_ATTN: - { - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); - indicate = 1; - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - break; - default: - break; - } - } - - - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { - if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); - collecting = 1; - } - dtmf_offset = strlen(dtmf); - last_digit = elapsed; - sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; - sig.raw_data = dtmf; - if (analog_data->sig_cb(&sig) == ZAP_BREAK) { - collecting = 0; - } - } - else if(!analog_data->max_dialstr) - { - last_digit = elapsed; - collecting = 0; - strcpy(dtmf, analog_data->hotline); - } - } - - - if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) >= analog_data->max_dialstr))) { - zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); - last_digit = 0; - collecting = 0; - } - - if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) { - continue; - } - - if (!(flags & ZAP_READ)) { - continue; - } - - if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error); - goto done; - } - - if (zchan->type == ZAP_CHAN_TYPE_FXO && zchan->detected_tones[0]) { - zap_sigmsg_t sig; - int i; - memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; - - for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { - if (zchan->detected_tones[i]) { - zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id); - sig.raw_data = &i; - if (analog_data->sig_cb) { - analog_data->sig_cb(&sig); - } - } - } - - if (zchan->detected_tones[ZAP_TONEMAP_BUSY] || - zchan->detected_tones[ZAP_TONEMAP_FAIL1] || - zchan->detected_tones[ZAP_TONEMAP_FAIL2] || - zchan->detected_tones[ZAP_TONEMAP_FAIL3] || - zchan->detected_tones[ZAP_TONEMAP_ATTN] - ) { - zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n"); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else if (zchan->detected_tones[ZAP_TONEMAP_DIAL]) { - if (zap_strlen_zero(zchan->caller_data.ani.digits)) { - zap_log(ZAP_LOG_ERROR, "No Digits to send!\n"); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - state_counter = 0; - zchan->needed_tones[ZAP_TONEMAP_RING] = 1; - zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1; - zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; - zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; - zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; - dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000; - } - } - } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } - - zap_channel_clear_detected_tones(zchan); - } - - if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer)) || (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer))) { - //rlen = len; - //memset(frame, 0, len); - //zap_channel_write(zchan, frame, sizeof(frame), &rlen); - continue; - } - - if (!indicate) { - continue; - } - - if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - } - - if (zchan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } - - rlen = zap_buffer_read_loop(dt_buffer, frame, len); - - if (zchan->effective_codec != ZAP_CODEC_SLIN) { - zio_codec_t codec_func = NULL; - - if (zchan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } - - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); - goto done; - } - } - - zap_channel_write(zchan, frame, sizeof(frame), &rlen); - } - - done: - - - if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); - } - - if (zchan->type == ZAP_CHAN_TYPE_FXS && zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { - zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } - - - closed_chan = zchan; - zap_channel_close(&zchan); - - zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); - - if (ts.buffer) { - teletone_destroy_session(&ts); - } - - if (dt_buffer) { - zap_buffer_destroy(&dt_buffer); - } - - if (closed_chan->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(closed_chan, ZAP_CHANNEL_STATE_DOWN); - } - - zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL %d:%d thread ended.\n", closed_chan->span_id, closed_chan->chan_id); - zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); - - return NULL; -} - -/** - * \brief Processes openzap event - * \param span Span on which the event was fired - * \param event Event to be treated - * \return Success or failure - */ -static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) -{ - zap_sigmsg_t sig; - zap_analog_data_t *analog_data = event->channel->span->signal_data; - int locked = 0; - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - - - zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n", - zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state)); - - zap_mutex_lock(event->channel->mutex); - locked++; - - switch(event->enum_id) { - case ZAP_OOB_RING_START: - { - if (event->channel->type != ZAP_CHAN_TYPE_FXO) { - zap_log(ZAP_LOG_ERROR, "Cannot get a RING_START event on a non-fxo channel, please check your config.\n"); - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - goto end; - } - if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) { - if (zap_test_flag(analog_data, ZAP_ANALOG_CALLERID)) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID); - } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_IDLE); - } - event->channel->ring_count = 1; - zap_mutex_unlock(event->channel->mutex); - locked = 0; - zap_thread_create_detached(zap_analog_channel_run, event->channel); - } else { - event->channel->ring_count++; - } - } - break; - case ZAP_OOB_ONHOOK: - { - if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) { - zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } - - if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - - } - break; - case ZAP_OOB_FLASH: - { - if (event->channel->state == ZAP_CHANNEL_STATE_CALLWAITING) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - zap_clear_flag_locked(event->channel, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(event->channel->span, ZAP_SPAN_STATE_CHANGE); - event->channel->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK] = 0; - } - - zap_channel_rotate_tokens(event->channel); - - if (zap_test_flag(event->channel, ZAP_CHANNEL_HOLD) && event->channel->token_count != 1) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - sig.event_id = ZAP_SIGEVENT_FLASH; - analog_data->sig_cb(&sig); - } - } - break; - case ZAP_OOB_OFFHOOK: - { - if (event->channel->type == ZAP_CHAN_TYPE_FXS) { - if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) { - zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL); - } - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - if(!analog_data->max_dialstr) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_COLLECT); - } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - } - zap_mutex_unlock(event->channel->mutex); - locked = 0; - zap_thread_create_detached(zap_analog_channel_run, event->channel); - } - } else { - if (!zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - if (zap_test_flag(event->channel, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(event->channel, ZAP_COMMAND_ONHOOK, NULL); - } - } - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - } - } - - end: - - if (locked) { - zap_mutex_unlock(event->channel->mutex); - } - return ZAP_SUCCESS; -} - -/** - * \brief Main thread function for analog span (monitor) - * \param me Current thread - * \param obj Span to run in this thread - */ -static void *zap_analog_run(zap_thread_t *me, void *obj) -{ - zap_span_t *span = (zap_span_t *) obj; - zap_analog_data_t *analog_data = span->signal_data; - int errs = 0; - - zap_log(ZAP_LOG_DEBUG, "ANALOG thread starting.\n"); - - while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_RUNNING)) { - int waitms = 1000; - zap_status_t status; - - if ((status = zap_span_poll_event(span, waitms)) != ZAP_FAIL) { - errs = 0; - } - - switch(status) { - case ZAP_SUCCESS: - { - zap_event_t *event; - while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { - if (event->enum_id == ZAP_OOB_NOOP) { - continue; - } - if (process_event(span, event) != ZAP_SUCCESS) { - goto end; - } - } - } - break; - case ZAP_FAIL: - { - zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); - if (++errs > 300) { - zap_log(ZAP_LOG_CRIT, "Too Many Errors!\n"); - goto end; - } - } - break; - default: - break; - } - - } - - end: - - zap_clear_flag(analog_data, ZAP_ANALOG_RUNNING); - - zap_log(ZAP_LOG_DEBUG, "ANALOG thread ending.\n"); - - return NULL; -} - -/** - * \brief Openzap analog signaling module initialisation - * \return Success - */ -static ZIO_SIG_LOAD_FUNCTION(zap_analog_init) -{ - return ZAP_SUCCESS; -} - -/** - * \brief Openzap analog signaling module definition - */ -EX_DECLARE_DATA zap_module_t zap_module = { - "analog", - NULL, - NULL, - zap_analog_init, - zap_analog_configure_span, - NULL -}; - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c deleted file mode 100644 index 53bf1a000f..0000000000 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ /dev/null @@ -1,709 +0,0 @@ -/* - * Copyright (c) 2008, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributor(s): - * - * John Wehle (john@feith.com) - * - */ - -#include "openzap.h" -#include "zap_analog_em.h" - -#ifndef localtime_r -struct tm * localtime_r(const time_t *clock, struct tm *result); -#endif - -static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj); - -/** - * \brief Starts an EM channel thread (outgoing call) - * \param zchan Channel to initiate call on - * \return Success or failure - * - * Initialises state, starts tone progress detection and runs the channel in a new a thread. - */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call) -{ - if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { - zap_channel_clear_needed_tones(zchan); - zap_channel_clear_detected_tones(zchan); - - zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); - - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - zap_channel_command(zchan, ZAP_COMMAND_ENABLE_PROGRESS_DETECT, NULL); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DIALING); - zap_thread_create_detached(zap_analog_em_channel_run, zchan); - return ZAP_SUCCESS; - } - - return ZAP_FAIL; -} - -/** - * \brief Starts an EM span thread (monitor) - * \param span Span to monitor - * \return Success or failure - */ -static zap_status_t zap_analog_em_start(zap_span_t *span) -{ - zap_analog_em_data_t *analog_data = span->signal_data; - zap_set_flag(analog_data, ZAP_ANALOG_EM_RUNNING); - return zap_thread_create_detached(zap_analog_em_run, span); -} - -/** - * \brief Initialises an EM span from configuration variables - * \param span Span to configure - * \param sig_cb Callback function for event signals - * \param ap List of configuration variables - * \return Success or failure - */ -static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) -//zap_status_t zap_analog_em_configure_span(zap_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb) -{ - zap_analog_em_data_t *analog_data; - const char *tonemap = "us"; - uint32_t digit_timeout = 10; - uint32_t max_dialstr = 11; - const char *var, *val; - int *intval; - - assert(sig_cb != NULL); - - if (span->signal_type) { - snprintf(span->last_error, sizeof(span->last_error), "Span is already configured for signalling."); - return ZAP_FAIL; - } - - analog_data = zap_malloc(sizeof(*analog_data)); - assert(analog_data != NULL); - memset(analog_data, 0, sizeof(*analog_data)); - - while((var = va_arg(ap, char *))) { - if (!strcasecmp(var, "tonemap")) { - if (!(val = va_arg(ap, char *))) { - break; - } - tonemap = val; - } else if (!strcasecmp(var, "digit_timeout")) { - if (!(intval = va_arg(ap, int *))) { - break; - } - digit_timeout = *intval; - } else if (!strcasecmp(var, "max_dialstr")) { - if (!(intval = va_arg(ap, int *))) { - break; - } - max_dialstr = *intval; - } else { - snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); - return ZAP_FAIL; - } - } - - - if (digit_timeout < 2000 || digit_timeout > 10000) { - digit_timeout = 2000; - } - - if (max_dialstr < 2 || max_dialstr > MAX_DIALSTRING) { - zap_log(ZAP_LOG_ERROR, "Invalid max_dialstr, setting to %d\n", MAX_DIALSTRING); - max_dialstr = MAX_DIALSTRING; - } - - span->start = zap_analog_em_start; - analog_data->digit_timeout = digit_timeout; - analog_data->max_dialstr = max_dialstr; - analog_data->sig_cb = sig_cb; - span->signal_type = ZAP_SIGTYPE_ANALOG; - span->signal_data = analog_data; - span->outgoing_call = analog_em_outgoing_call; - zap_span_load_tones(span, tonemap); - - return ZAP_SUCCESS; - -} - -/** - * \brief Retrieves tone generation output to be sent - * \param ts Teletone generator - * \param map Tone map - * \return -1 on error, 0 on success - */ -static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map) -{ - zap_buffer_t *dt_buffer = ts->user_data; - int wrote; - - if (!dt_buffer) { - return -1; - } - wrote = teletone_mux_tones(ts, map); - zap_buffer_write(dt_buffer, ts->buffer, wrote * 2); - return 0; -} - -/** - * \brief Main thread function for EM channel (outgoing call) - * \param me Current thread - * \param obj Channel to run in this thread - */ -static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) -{ - zap_channel_t *zchan = (zap_channel_t *) obj; - zap_buffer_t *dt_buffer = NULL; - teletone_generation_session_t ts; - uint8_t frame[1024]; - zap_size_t len, rlen; - zap_tone_type_t tt = ZAP_TONE_DTMF; - char dtmf[128] = ""; - zap_size_t dtmf_offset = 0; - zap_analog_em_data_t *analog_data = zchan->span->signal_data; - zap_channel_t *closed_chan; - uint32_t state_counter = 0, elapsed = 0, collecting = 0, interval = 0, last_digit = 0, indicate = 0, dial_timeout = 30000; - zap_sigmsg_t sig; - zap_status_t status; - - zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread starting.\n"); - - ts.buffer = NULL; - - if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); - goto done; - } - - if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "memory error!"); - zap_log(ZAP_LOG_ERROR, "MEM ERROR\n"); - goto done; - } - - if (zap_channel_command(zchan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "error initilizing tone detector!"); - zap_log(ZAP_LOG_ERROR, "TONE ERROR\n"); - goto done; - } - - zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD); - teletone_init_session(&ts, 0, teletone_handler, dt_buffer); - ts.rate = 8000; -#if 0 - ts.debug = 1; - ts.debug_stream = stdout; -#endif - zap_channel_command(zchan, ZAP_COMMAND_GET_INTERVAL, &interval); - zap_buffer_set_loops(dt_buffer, -1); - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - - assert(interval != 0); - - while (zap_running() && zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { - zap_wait_flag_t flags = ZAP_READ; - zap_size_t dlen = 0; - - len = sizeof(frame); - - elapsed += interval; - state_counter += interval; - - if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) { - switch(zchan->state) { - case ZAP_CHANNEL_STATE_DIALING: - { - if (! zchan->needed_tones[ZAP_TONEMAP_RING] - && zap_test_flag(zchan, ZAP_CHANNEL_WINK)) { - if (zap_strlen_zero(zchan->caller_data.ani.digits)) { - zap_log(ZAP_LOG_ERROR, "No Digits to send!\n"); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - if (zap_channel_command(zchan, ZAP_COMMAND_SEND_DTMF, zchan->caller_data.ani.digits) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Send Digits Failed [%s]\n", zchan->last_error); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - state_counter = 0; - zchan->needed_tones[ZAP_TONEMAP_RING] = 1; - zchan->needed_tones[ZAP_TONEMAP_BUSY] = 1; - zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1; - zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1; - zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1; - dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani.digits)) + 2000; - } - } - break; - } - if (state_counter > dial_timeout) { - if (!zap_test_flag(zchan, ZAP_CHANNEL_WINK)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } - } - } - break; - case ZAP_CHANNEL_STATE_DIALTONE: - { - if (state_counter > 10000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } - } - break; - case ZAP_CHANNEL_STATE_BUSY: - { - if (state_counter > 20000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_ATTN); - } - } - break; - case ZAP_CHANNEL_STATE_ATTN: - { - if (state_counter > 20000) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - break; - case ZAP_CHANNEL_STATE_HANGUP: - { - if (state_counter > 500) { - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && - (zchan->last_state == ZAP_CHANNEL_STATE_RING || zchan->last_state == ZAP_CHANNEL_STATE_DIALTONE - || zchan->last_state >= ZAP_CHANNEL_STATE_IDLE)) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else { - zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - } - break; - case ZAP_CHANNEL_STATE_UP: - case ZAP_CHANNEL_STATE_IDLE: - { - zap_sleep(interval); - continue; - } - break; - case ZAP_CHANNEL_STATE_DOWN: - { - goto done; - } - break; - default: - break; - } - } else { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); - zap_channel_complete_state(zchan); - indicate = 0; - state_counter = 0; - - zap_log(ZAP_LOG_DEBUG, "Executing state handler on %d:%d for %s\n", - zchan->span_id, zchan->chan_id, - zap_channel_state2str(zchan->state)); - switch(zchan->state) { - case ZAP_CHANNEL_STATE_UP: - { - zap_channel_use(zchan); - zap_channel_clear_needed_tones(zchan); - zap_channel_flush_dtmf(zchan); - - if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { - zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL); - } - - sig.event_id = ZAP_SIGEVENT_UP; - - analog_data->sig_cb(&sig); - continue; - } - break; - case ZAP_CHANNEL_STATE_DIALING: - { - zap_channel_use(zchan); - } - break; - case ZAP_CHANNEL_STATE_IDLE: - { - zap_channel_use(zchan); - - if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_set_string(zchan->caller_data.dnis.digits, zchan->chan_number); - } else { - zap_set_string(zchan->caller_data.dnis.digits, dtmf); - } - - sig.event_id = ZAP_SIGEVENT_START; - - analog_data->sig_cb(&sig); - continue; - } - break; - case ZAP_CHANNEL_STATE_DOWN: - { - sig.event_id = ZAP_SIGEVENT_STOP; - analog_data->sig_cb(&sig); - goto done; - } - break; - case ZAP_CHANNEL_STATE_DIALTONE: - { - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - *dtmf = '\0'; - dtmf_offset = 0; - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_DIAL]); - indicate = 1; - - zap_channel_command(zchan, ZAP_COMMAND_WINK, NULL); - } - break; - case ZAP_CHANNEL_STATE_RING: - { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_RING]); - indicate = 1; - } - break; - case ZAP_CHANNEL_STATE_BUSY: - { - zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CIRCUIT_CONGESTION; - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_BUSY]); - indicate = 1; - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - break; - case ZAP_CHANNEL_STATE_ATTN: - { - if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_buffer_zero(dt_buffer); - teletone_run(&ts, zchan->span->tone_map[ZAP_TONEMAP_ATTN]); - indicate = 1; - } else { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); - } - } - break; - default: - break; - } - } - - - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE || zchan->state == ZAP_CHANNEL_STATE_COLLECT) { - if ((dlen = zap_channel_dequeue_dtmf(zchan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { - - if (zchan->state == ZAP_CHANNEL_STATE_DIALTONE) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_COLLECT); - collecting = 1; - } - dtmf_offset = strlen(dtmf); - last_digit = elapsed; - sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; - sig.raw_data = dtmf; - if (analog_data->sig_cb(&sig) == ZAP_BREAK) { - collecting = 0; - } - } - } - - - if (last_digit && (!collecting || ((elapsed - last_digit > analog_data->digit_timeout) || strlen(dtmf) > analog_data->max_dialstr))) { - zap_log(ZAP_LOG_DEBUG, "Number obtained [%s]\n", dtmf); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE); - last_digit = 0; - collecting = 0; - } - - if (zap_channel_wait(zchan, &flags, interval * 2) != ZAP_SUCCESS) { - continue; - } - - if (!(flags & ZAP_READ)) { - continue; - } - - if (zap_channel_read(zchan, frame, &len) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "READ ERROR [%s]\n", zchan->last_error); - goto done; - } - - if (zchan->detected_tones[0]) { - zap_sigmsg_t sig; - int i; - memset(&sig, 0, sizeof(sig)); - sig.chan_id = zchan->chan_id; - sig.span_id = zchan->span_id; - sig.channel = zchan; - sig.event_id = ZAP_SIGEVENT_TONE_DETECTED; - - for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { - if (zchan->detected_tones[i]) { - zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id); - sig.raw_data = &i; - if (analog_data->sig_cb) { - analog_data->sig_cb(&sig); - } - } - } - - if (zchan->detected_tones[ZAP_TONEMAP_BUSY] || - zchan->detected_tones[ZAP_TONEMAP_FAIL1] || - zchan->detected_tones[ZAP_TONEMAP_FAIL2] || - zchan->detected_tones[ZAP_TONEMAP_FAIL3] || - zchan->detected_tones[ZAP_TONEMAP_ATTN] - ) { - zap_log(ZAP_LOG_ERROR, "Failure indication detected!\n"); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); - } else if (zchan->detected_tones[ZAP_TONEMAP_RING]) { - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_UP); - } - - zap_channel_clear_detected_tones(zchan); - } - - if ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer))) { - rlen = len; - memset(frame, 0, len); - zap_channel_write(zchan, frame, sizeof(frame), &rlen); - continue; - } - - if (!indicate) { - continue; - } - - if (zchan->effective_codec != ZAP_CODEC_SLIN) { - len *= 2; - } - - rlen = zap_buffer_read_loop(dt_buffer, frame, len); - - if (zchan->effective_codec != ZAP_CODEC_SLIN) { - zio_codec_t codec_func = NULL; - - if (zchan->native_codec == ZAP_CODEC_ULAW) { - codec_func = zio_slin2ulaw; - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - codec_func = zio_slin2alaw; - } - - if (codec_func) { - status = codec_func(frame, sizeof(frame), &rlen); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); - goto done; - } - } - - zap_channel_write(zchan, frame, sizeof(frame), &rlen); - } - - done: - - zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); - - closed_chan = zchan; - zap_channel_close(&zchan); - - zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); - - if (ts.buffer) { - teletone_destroy_session(&ts); - } - - if (dt_buffer) { - zap_buffer_destroy(&dt_buffer); - } - - zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); - - zap_log(ZAP_LOG_DEBUG, "ANALOG EM CHANNEL thread ended.\n"); - - return NULL; -} - -/** - * \brief Processes EM events coming from zaptel/dahdi - * \param span Span on which the event was fired - * \param event Event to be treated - * \return Success or failure - */ -static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) -{ - zap_sigmsg_t sig; - int locked = 0; - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - - - zap_log(ZAP_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n", - zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state)); - - zap_mutex_lock(event->channel->mutex); - locked++; - - switch(event->enum_id) { - case ZAP_OOB_ONHOOK: - { - if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } - - } - break; - case ZAP_OOB_OFFHOOK: - { - if (zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); - } else { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE); - zap_mutex_unlock(event->channel->mutex); - locked = 0; - zap_thread_create_detached(zap_analog_em_channel_run, event->channel); - } - break; - } - case ZAP_OOB_WINK: - { - if (event->channel->state != ZAP_CHANNEL_STATE_DIALING) { - zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); - } else { - zap_set_flag_locked(event->channel, ZAP_CHANNEL_WINK); - } - - } - break; - } - if (locked) { - zap_mutex_unlock(event->channel->mutex); - } - return ZAP_SUCCESS; -} - -/** - * \brief Main thread function for EM span (monitor) - * \param me Current thread - * \param obj Span to run in this thread - */ -static void *zap_analog_em_run(zap_thread_t *me, void *obj) -{ - zap_span_t *span = (zap_span_t *) obj; - zap_analog_em_data_t *analog_data = span->signal_data; - - zap_log(ZAP_LOG_DEBUG, "ANALOG EM thread starting.\n"); - - while(zap_running() && zap_test_flag(analog_data, ZAP_ANALOG_EM_RUNNING)) { - int waitms = 10; - zap_status_t status; - - status = zap_span_poll_event(span, waitms); - - switch(status) { - case ZAP_SUCCESS: - { - zap_event_t *event; - while (zap_span_next_event(span, &event) == ZAP_SUCCESS) { - if (event->enum_id == ZAP_OOB_NOOP) { - continue; - } - if (process_event(span, event) != ZAP_SUCCESS) { - goto end; - } - } - } - break; - case ZAP_FAIL: - { - zap_log(ZAP_LOG_ERROR, "Failure Polling event! [%s]\n", span->last_error); - } - break; - default: - break; - } - - } - - end: - - zap_clear_flag(analog_data, ZAP_ANALOG_EM_RUNNING); - - zap_log(ZAP_LOG_DEBUG, "ANALOG EM thread ending.\n"); - - return NULL; -} - -/** - * \brief Openzap analog EM module initialisation - * \return Success - */ -static ZIO_SIG_LOAD_FUNCTION(zap_analog_em_init) -{ - return ZAP_SUCCESS; -} - -/** - * \brief Openzap analog EM module definition - */ -EX_DECLARE_DATA zap_module_t zap_module = { - "analog_em", - NULL, - NULL, - zap_analog_em_init, - zap_analog_em_configure_span, - NULL -}; - - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:t - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c deleted file mode 100644 index acc2de62a1..0000000000 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ /dev/null @@ -1,1367 +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 "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 { - /* signaling callback */ - zio_signal_cb_t sig_cb; - /* 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_r2_data_t *r2data = zchan->span->signal_data; - - 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 (r2data->sig_cb(&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; - - r2data->sig_cb(&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; - - r2data->sig_cb(&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 (r2data->sig_cb(&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 = zap_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); - } - zap_safe_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 = zap_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 = zap_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 = zap_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; - r2data->sig_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_r2_data_t *r2data = zchan->span->signal_data; - - 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 (r2data->sig_cb(&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 (r2data->sig_cb(&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 = zap_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 - */ diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index 7a37357083..a6ca7d5c2f 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -13,7 +13,7 @@ * ============================================================================ */ -#include "openzap.h" +#include "freetdm.h" #include #include #include @@ -33,9 +33,9 @@ typedef struct { static call_info_t pidmap[SANGOMA_MAX_CHAN_PER_SPAN]; -ZIO_EVENT_CB_FUNCTION(my_zap_event_handler) +ZIO_EVENT_CB_FUNCTION(my_ftdm_event_handler) { - if (event->e_type = ZAP_EVENT_DTMF) { + if (event->e_type = FTDM_EVENT_DTMF) { char *dtmf = event->data; printf("DTMF %s\n", dtmf); } @@ -64,12 +64,12 @@ static void launch_channel(struct sangoma_pri *spri, int channo) fd_set readfds; int mtu_mru=BYTES / 2; int err; - zap_channel_t *chan; - zap_codec_t codec = ZAP_CODEC_SLIN; + ftdm_channel_t *chan; + ftdm_codec_t codec = FTDM_CODEC_SLIN; unsigned ms = 20; unsigned int lead = 50; int ifd = -1; - zap_tone_type_t tt = ZAP_TONE_DTMF; + ftdm_tone_type_t tt = FTDM_TONE_DTMF; char dtmf[] = "1234567890"; int loops = 0; @@ -88,47 +88,47 @@ static void launch_channel(struct sangoma_pri *spri, int channo) memset(inframe, 0, MAX_BYTES); memset(outframe, 0, MAX_BYTES); - if (zap_channel_open(spri->span, channo, &chan) != ZAP_SUCCESS) { + if (ftdm_channel_open(spri->span, channo, &chan) != FTDM_SUCCESS) { printf("DEBUG cant open fd!\n"); } #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec) != ZAP_SUCCESS) { + if (ftdm_channel_command(chan, FTDM_COMMAND_SET_CODEC, &codec) != FTDM_SUCCESS) { printf("Critical Error: Failed to set driver codec!\n"); - zap_channel_close(&chan); + ftdm_channel_close(&chan); exit(-1); } #endif #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_DTMF_DETECT, &tt) != ZAP_SUCCESS) { + if (ftdm_channel_command(chan, FTDM_COMMAND_ENABLE_DTMF_DETECT, &tt) != FTDM_SUCCESS) { printf("Critical Error: Failed to set dtmf detect!\n"); - zap_channel_close(&chan); + ftdm_channel_close(&chan); exit(-1); } - zap_channel_set_event_callback(chan, my_zap_event_handler); + ftdm_channel_set_event_callback(chan, my_ftdm_event_handler); #endif - if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) != ZAP_SUCCESS) { + if (ftdm_channel_command(chan, FTDM_COMMAND_SET_INTERVAL, &ms) != FTDM_SUCCESS) { printf("Critical Error: Failed to set codec interval!\n"); - zap_channel_close(&chan); + ftdm_channel_close(&chan); exit(-1); } file = open("sound.raw", O_RDONLY); if (file < 0){ printf("Critical Error: Failed to open sound file!\n"); - zap_channel_close(&chan); + ftdm_channel_close(&chan); exit(-1); } while(ready) { - zap_wait_flag_t flags = ZAP_READ; - zap_size_t len; + ftdm_wait_flag_t flags = FTDM_READ; + ftdm_size_t len; loops++; if (lead) { @@ -137,23 +137,23 @@ static void launch_channel(struct sangoma_pri *spri, int channo) if (!lead && loops == 300) { #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, dtmf) != ZAP_SUCCESS) { + if (ftdm_channel_command(chan, FTDM_COMMAND_SEND_DTMF, dtmf) != FTDM_SUCCESS) { printf("Critical Error: Failed to send dtmf\n"); - zap_channel_close(&chan); + ftdm_channel_close(&chan); exit(-1); } #endif } - if (zap_channel_wait(chan, &flags, 2000) != ZAP_SUCCESS) { + if (ftdm_channel_wait(chan, &flags, 2000) != FTDM_SUCCESS) { printf("wait FAIL! [%s]\n", chan->last_error); break; } - if (flags & ZAP_READ) { + if (flags & FTDM_READ) { len = MAX_BYTES; - if (zap_channel_read(chan, inframe, &len) == ZAP_SUCCESS) { + if (ftdm_channel_read(chan, inframe, &len) == FTDM_SUCCESS) { //printf("READ: %d\n", len); //write(ifd, inframe, len); if(!lead && (outlen = read(file, outframe, len)) <= 0) { @@ -167,7 +167,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) if (lead) { continue; } - zap_channel_write(chan, outframe, sizeof(outframe), &len); + ftdm_channel_write(chan, outframe, sizeof(outframe), &len); } else { printf("BREAK"); break; @@ -181,7 +181,7 @@ static void launch_channel(struct sangoma_pri *spri, int channo) //close(ifd); pri_hangup(spri->pri, channo, 16); - if (zap_channel_close(&chan) != ZAP_SUCCESS) { + if (ftdm_channel_close(&chan) != FTDM_SUCCESS) { printf("Critical Error: Failed to close channel [%s]\n", chan->last_error); } @@ -280,13 +280,13 @@ int main(int argc, char *argv[]) debug = atoi(argv[1]); } - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; diff --git a/libs/freetdm/src/sangoma_pri.c b/libs/freetdm/src/sangoma_pri.c index 5cf6a5cd10..402611e518 100644 --- a/libs/freetdm/src/sangoma_pri.c +++ b/libs/freetdm/src/sangoma_pri.c @@ -13,7 +13,7 @@ * ============================================================================ */ -#include "openzap.h" +#include "freetdm.h" #include #ifndef HAVE_GETTIMEOFDAY @@ -92,12 +92,12 @@ char *sangoma_pri_event_str(sangoma_pri_event_t event_id) static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen) { struct sangoma_pri *spri = (struct sangoma_pri *) pri->userdata; - zap_size_t len = buflen; + ftdm_size_t len = buflen; int res; char bb[4096] = ""; - if (zap_channel_read(spri->zdchan, buf, &len) != ZAP_SUCCESS) { + if (ftdm_channel_read(spri->zdchan, buf, &len) != FTDM_SUCCESS) { printf("D-READ FAIL! [%s]\n", spri->zdchan->last_error); return 0; } @@ -106,7 +106,7 @@ static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen) res+=2; //print_bits(buf, res-2, bb, sizeof(bb), 1, 0); - //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb); + //ftdm_log(FTDM_LOG_DEBUG, "READ %d\n%s\n%s\n\n", res-2, LINE, bb); return res; } @@ -115,16 +115,16 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen) { struct sangoma_pri *spri = (struct sangoma_pri *) pri->userdata; int res; - zap_size_t len = buflen -2; + ftdm_size_t len = buflen -2; char bb[4096] = ""; - if (zap_channel_write(spri->zdchan, buf, buflen, &len) != ZAP_SUCCESS) { + if (ftdm_channel_write(spri->zdchan, buf, buflen, &len) != FTDM_SUCCESS) { printf("D-WRITE FAIL! [%s]\n", spri->zdchan->last_error); return 0; } //print_bits(buf, (int)buflen-2, bb, sizeof(bb), 1, 0); - //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb); + //ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)buflen-2, LINE, bb); return (int) buflen; } @@ -132,11 +132,11 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen) int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype, int node, int debug) { int ret = -1; - zap_socket_t dfd = 0; + ftdm_socket_t dfd = 0; memset(spri, 0, sizeof(struct sangoma_pri)); - if (zap_channel_open(span, dchan, &spri->zdchan) != ZAP_SUCCESS) { + if (ftdm_channel_open(span, dchan, &spri->zdchan) != FTDM_SUCCESS) { fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno)); } else { if ((spri->pri = pri_new_cb(spri->zdchan->sockfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, spri))){ diff --git a/libs/freetdm/src/sangoma_pri.h b/libs/freetdm/src/sangoma_pri.h index 5ea21eb7b5..2a1b2a2cef 100644 --- a/libs/freetdm/src/sangoma_pri.h +++ b/libs/freetdm/src/sangoma_pri.h @@ -79,7 +79,7 @@ struct sangoma_pri { void *private_info; event_handler eventmap[MAX_EVENT+1]; loop_handler on_loop; - zap_channel_t *zdchan; + ftdm_channel_t *zdchan; }; struct sangoma_pri_event_list { diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 1a9542be4f..7b5d3db874 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -1,61 +1,61 @@ -#include "openzap.h" +#include "freetdm.h" -static void *test_call(zap_thread_t *me, void *obj) +static void *test_call(ftdm_thread_t *me, void *obj) { - zap_channel_t *chan = (zap_channel_t *) obj; + ftdm_channel_t *chan = (ftdm_channel_t *) obj; uint8_t frame[1024]; - zap_size_t len; + ftdm_size_t len; char *number = strdup("5551212"); - zap_sleep(10 * 1000); + ftdm_sleep(10 * 1000); - zap_log(ZAP_LOG_DEBUG, "answer call and start echo test\n"); + ftdm_log(FTDM_LOG_DEBUG, "answer call and start echo test\n"); - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_UP); - zap_channel_command(chan, ZAP_COMMAND_SEND_DTMF, number); + ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_UP); + ftdm_channel_command(chan, FTDM_COMMAND_SEND_DTMF, number); - while (chan->state == ZAP_CHANNEL_STATE_UP) { - zap_wait_flag_t flags = ZAP_READ; + while (chan->state == FTDM_CHANNEL_STATE_UP) { + ftdm_wait_flag_t flags = FTDM_READ; - if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { + if (ftdm_channel_wait(chan, &flags, -1) == FTDM_FAIL) { break; } len = sizeof(frame); - if (flags & ZAP_READ) { - if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { - //zap_log(ZAP_LOG_DEBUG, "WRITE %d\n", len); - zap_channel_write(chan, frame, sizeof(frame), &len); + if (flags & FTDM_READ) { + if (ftdm_channel_read(chan, frame, &len) == FTDM_SUCCESS) { + //ftdm_log(FTDM_LOG_DEBUG, "WRITE %d\n", len); + ftdm_channel_write(chan, frame, sizeof(frame), &len); } else { break; } } } - if (chan->state == ZAP_CHANNEL_STATE_UP) { - zap_set_state_locked(chan, ZAP_CHANNEL_STATE_BUSY); + if (chan->state == FTDM_CHANNEL_STATE_UP) { + ftdm_set_state_locked(chan, FTDM_CHANNEL_STATE_BUSY); } - zap_log(ZAP_LOG_DEBUG, "call over\n"); + ftdm_log(FTDM_LOG_DEBUG, "call over\n"); free(number); return NULL; } static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - zap_log(ZAP_LOG_DEBUG, "got sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + ftdm_log(FTDM_LOG_DEBUG, "got sig [%s]\n", ftdm_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { - case ZAP_SIGEVENT_START: - zap_set_state_locked(sigmsg->channel, ZAP_CHANNEL_STATE_RING); - zap_log(ZAP_LOG_DEBUG, "launching thread and indicating ring\n"); - zap_thread_create_detached(test_call, sigmsg->channel); + case FTDM_SIGEVENT_START: + ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_RING); + ftdm_log(FTDM_LOG_DEBUG, "launching thread and indicating ring\n"); + ftdm_thread_create_detached(test_call, sigmsg->channel); break; default: break; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } static int R = 0; @@ -70,7 +70,7 @@ static void handle_SIGINT(int sig) int main(int argc, char *argv[]) { - zap_span_t *span; + ftdm_span_t *span; int span_id; int digit_timeout = 2000; int max_dialstr = 11; @@ -82,41 +82,41 @@ int main(int argc, char *argv[]) span_id = atoi(argv[1]); - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); - if (zap_global_init() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error loading OpenFTDM\n"); exit(-1); } - zap_log(ZAP_LOG_DEBUG, "OpenZAP loaded\n"); + ftdm_log(FTDM_LOG_DEBUG, "OpenFTDM loaded\n"); - if (zap_span_find(span_id, &span) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error finding OpenZAP span\n"); + if (ftdm_span_find(span_id, &span) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span\n"); goto done; } - if (zap_configure_span("analog", span, on_signal, + if (ftdm_configure_span("analog", span, on_signal, "tonemap", "us", "digit_timeout", &digit_timeout, "max_dialstr", &max_dialstr, TAG_END - ) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error configuring OpenZAP span\n"); + ) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error configuring OpenFTDM span\n"); goto done; } - zap_span_start(span); + ftdm_span_start(span); R = 1; - while(zap_running() && R) { - zap_sleep(1 * 1000); + while(ftdm_running() && R) { + ftdm_sleep(1 * 1000); } done: - zap_global_destroy(); + ftdm_global_destroy(); return 0; } diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index cfa27c9296..ffc79e047b 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -1,39 +1,39 @@ -#include "openzap.h" +#include "freetdm.h" int main(int argc, char *argv[]) { - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); - zap_channel_t *chan; + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); + ftdm_channel_t *chan; unsigned ms = 20; - zap_codec_t codec = ZAP_CODEC_SLIN; + ftdm_codec_t codec = FTDM_CODEC_SLIN; unsigned runs = 1; - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); top: - //if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { - if (zap_channel_open(1, 1, &chan) == ZAP_SUCCESS) { + //if (ftdm_channel_open_any("wanpipe", 0, FTDM_TOP_DOWN, &chan) == FTDM_SUCCESS) { + if (ftdm_channel_open(1, 1, &chan) == FTDM_SUCCESS) { int x = 0; printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); #if 1 - if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { + if (ftdm_channel_command(chan, FTDM_COMMAND_SET_INTERVAL, &ms) == FTDM_SUCCESS) { ms = 0; - zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &ms); + ftdm_channel_command(chan, FTDM_COMMAND_GET_INTERVAL, &ms); printf("interval set to %u\n", ms); } else { printf("set interval failed [%s]\n", chan->last_error); } #endif - if (zap_channel_command(chan, ZAP_COMMAND_SET_CODEC, &codec) == ZAP_SUCCESS) { + if (ftdm_channel_command(chan, FTDM_COMMAND_SET_CODEC, &codec) == FTDM_SUCCESS) { codec = 1; - zap_channel_command(chan, ZAP_COMMAND_GET_CODEC, &codec); + ftdm_channel_command(chan, FTDM_COMMAND_GET_CODEC, &codec); printf("codec set to %u\n", codec); } else { printf("set codec failed [%s]\n", chan->last_error); @@ -41,14 +41,14 @@ int main(int argc, char *argv[]) for(x = 0; x < 25; x++) { unsigned char buf[2048]; - zap_size_t len = sizeof(buf); - zap_wait_flag_t flags = ZAP_READ; + ftdm_size_t len = sizeof(buf); + ftdm_wait_flag_t flags = FTDM_READ; - if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { + if (ftdm_channel_wait(chan, &flags, -1) == FTDM_FAIL) { printf("wait FAIL! %u [%s]\n", (unsigned)len, chan->last_error); } - if (flags & ZAP_READ) { - if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) { + if (flags & FTDM_READ) { + if (ftdm_channel_read(chan, buf, &len) == FTDM_SUCCESS) { printf("READ: %u\n", (unsigned)len); } else { printf("READ FAIL! %u [%s]\n", (unsigned)len, chan->last_error); @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) printf("wait fail [%s]\n", chan->last_error); } } - zap_channel_close(&chan); + ftdm_channel_close(&chan); } else { printf("open fail [%s]\n", chan->last_error); } @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) goto top; } - zap_global_destroy(); + ftdm_global_destroy(); return 0; } diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index a3aea1cfe5..9b68034418 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -1,8 +1,8 @@ -#include "openzap.h" +#include "freetdm.h" static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - return ZAP_FAIL; + return FTDM_FAIL; } static int R = 0; @@ -16,13 +16,13 @@ static void handle_SIGINT(int sig) #endif int main(int argc, char *argv[]) { - zap_conf_parameter_t parameters[20]; - zap_span_t *span; + ftdm_conf_parameter_t parameters[20]; + ftdm_span_t *span; int local_port, remote_port; local_port = remote_port = 53000; - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); #if 0 if (argc < 2) { printf("invalid arguments\n"); @@ -30,19 +30,19 @@ int main(int argc, char *argv[]) } #endif - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - if (zap_global_configuration() != ZAP_SUCCESS) { - fprintf(stderr, "Error configuring OpenZAP\n"); + if (ftdm_global_configuration() != FTDM_SUCCESS) { + fprintf(stderr, "Error configuring OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); - if (zap_span_find_by_name("wp1", &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span %s\n", argv[1]); + if (ftdm_span_find_by_name("wp1", &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding OpenFTDM span %s\n", argv[1]); goto done; } parameters[0].var = "sigmod"; @@ -52,20 +52,20 @@ int main(int argc, char *argv[]) parameters[1].var = "signalling"; parameters[1].val = "pri_cpe"; parameters[2].var = NULL; - if (zap_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == ZAP_SUCCESS) { - zap_span_start(span); + if (ftdm_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == FTDM_SUCCESS) { + ftdm_span_start(span); } else { fprintf(stderr, "Error starting SS7_BOOST\n"); goto done; } - while(zap_running() && R) { - zap_sleep(1 * 1000); + while(ftdm_running() && R) { + ftdm_sleep(1 * 1000); } done: - zap_global_destroy(); + ftdm_global_destroy(); return 0; } diff --git a/libs/freetdm/src/testcid.c b/libs/freetdm/src/testcid.c index 0018bb9a5d..59086d003d 100644 --- a/libs/freetdm/src/testcid.c +++ b/libs/freetdm/src/testcid.c @@ -1,25 +1,25 @@ -#include "openzap.h" -zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data); +#include "freetdm.h" +ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data); struct helper { int fd; int wrote; }; -zap_status_t my_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) +ftdm_status_t my_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data) { struct helper *foo = (struct helper *) user_data; size_t len; len = write(foo->fd, buf, buflen * 2); - if (!len) return ZAP_FAIL; + if (!len) return FTDM_FAIL; foo->wrote += buflen * 2; - return ZAP_SUCCESS; + return FTDM_SUCCESS; } int main(int argc, char *argv[]) { - struct zap_fsk_modulator fsk_trans; - zap_fsk_data_state_t fsk_data = {0}; + struct ftdm_fsk_modulator fsk_trans; + ftdm_fsk_data_state_t fsk_data = {0}; int fd = -1; int16_t buf[160] = {0}; ssize_t len = 0; @@ -48,26 +48,26 @@ int main(int argc, char *argv[]) localtime_r(&now, &tm); strftime(time_str, sizeof(time_str), "%m%d%H%M", &tm); - zap_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); + ftdm_fsk_data_init(&fsk_data, databuf, sizeof(databuf)); #if 1 - zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *)time_str, strlen(time_str)); - //zap_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06091213", 8); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, (uint8_t *)"14149361212", 7); - zap_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, (uint8_t *)"Fred Smith", 10); + ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, (uint8_t *)time_str, strlen(time_str)); + //ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_DATETIME, "06091213", 8); + ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NUM, (uint8_t *)"14149361212", 7); + ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_PHONE_NAME, (uint8_t *)"Fred Smith", 10); for(x = 0; x < 0; x++) - zap_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, (uint8_t *)url, strlen(url)); + ftdm_fsk_data_add_mdmf(&fsk_data, MDMF_ALT_ROUTE, (uint8_t *)url, strlen(url)); #else - zap_fsk_data_add_sdmf(&fsk_data, "06061234", "0"); - //zap_fsk_data_add_sdmf(&state, "06061234", "5551212"); + ftdm_fsk_data_add_sdmf(&fsk_data, "06061234", "0"); + //ftdm_fsk_data_add_sdmf(&state, "06061234", "5551212"); #endif - zap_fsk_data_add_checksum(&fsk_data); + ftdm_fsk_data_add_checksum(&fsk_data); foo.fd = fd; - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, 8000, &fsk_data, -14, 180, 5, 300, my_write_sample, &foo); - zap_fsk_modulator_send_all((&fsk_trans)); + ftdm_fsk_modulator_init(&fsk_trans, FSK_BELL202, 8000, &fsk_data, -14, 180, 5, 300, my_write_sample, &foo); + ftdm_fsk_modulator_send_all((&fsk_trans)); printf("%u %d %d\n", (unsigned) fsk_data.dlen, foo.wrote, fsk_trans.est_bytes); @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) return 0; } - if (zap_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) { + if (ftdm_fsk_demod_init(&fsk_data, 8000, (uint8_t *)fbuf, sizeof(fbuf))) { printf("wtf\n"); return 0; } @@ -89,19 +89,19 @@ int main(int argc, char *argv[]) } while((len = read(fd, buf, sizeof(buf))) > 0) { - if (zap_fsk_demod_feed(&fsk_data, buf, len / 2) != ZAP_SUCCESS) { + if (ftdm_fsk_demod_feed(&fsk_data, buf, len / 2) != FTDM_SUCCESS) { break; } } - while(zap_fsk_data_parse(&fsk_data, &type, &sp, &mlen) == ZAP_SUCCESS) { - zap_copy_string(str, sp, mlen+1); + while(ftdm_fsk_data_parse(&fsk_data, &type, &sp, &mlen) == FTDM_SUCCESS) { + ftdm_copy_string(str, sp, mlen+1); *(str+mlen) = '\0'; - zap_clean_string(str); - printf("TYPE %u (%s) LEN %u VAL [%s]\n", (unsigned)type, zap_mdmf_type2str(type), (unsigned)mlen, str); + ftdm_clean_string(str); + printf("TYPE %u (%s) LEN %u VAL [%s]\n", (unsigned)type, ftdm_mdmf_type2str(type), (unsigned)mlen, str); } - zap_fsk_demod_destroy(&fsk_data); + ftdm_fsk_demod_destroy(&fsk_data); close(fd); return 0; diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index f32f47a3f0..61eb235e25 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -1,10 +1,10 @@ -#include "openzap.h" +#include "freetdm.h" #include static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - return ZAP_FAIL; + return FTDM_FAIL; } static int R = 0; @@ -17,32 +17,32 @@ static void handle_SIGINT(int sig) int main(int argc, char *argv[]) { - zap_span_t *span; + ftdm_span_t *span; - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (argc < 2) { printf("umm no\n"); exit(-1); } - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); - if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding OpenFTDM span\n"); goto done; } - if (zap_configure_span("isdn", span, on_signal, + if (ftdm_configure_span("isdn", span, on_signal, "mode", "te", "dialect", "national", - TAG_END) == ZAP_SUCCESS) { - zap_span_start(span); + TAG_END) == FTDM_SUCCESS) { + ftdm_span_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; @@ -51,12 +51,12 @@ int main(int argc, char *argv[]) signal(SIGINT, handle_SIGINT); R = 1; while(R) { - zap_sleep(1 * 1000); + ftdm_sleep(1 * 1000); } done: - zap_global_destroy(); + ftdm_global_destroy(); return 1; diff --git a/libs/freetdm/src/testm3ua.c b/libs/freetdm/src/testm3ua.c index 16377cd067..d66952ce34 100644 --- a/libs/freetdm/src/testm3ua.c +++ b/libs/freetdm/src/testm3ua.c @@ -1,6 +1,6 @@ /* * testm3ua.c - * openzap + * freetdm * * Created by Shane Burrell on 4/8/08. * Copyright 2008 __MyCompanyName__. All rights reserved. @@ -8,53 +8,53 @@ */ #include "testm3ua.h" -#include "openzap.h" -#include "zap_m3ua.h" +#include "freetdm.h" +#include "ftdm_m3ua.h" static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - return ZAP_FAIL; + return FTDM_FAIL; } int main(int argc, char *argv[]) { - zap_span_t *span; + ftdm_span_t *span; //m3ua_data_t *data; - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (argc < 5) { printf("more args needed\n"); exit(-1); } - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); - if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding OpenFTDM span\n"); goto done; } - if (zap_m3ua_configure_span(span) == ZAP_SUCCESS) { + if (ftdm_m3ua_configure_span(span) == FTDM_SUCCESS) { //data = span->signal_data; - zap_m3ua_start(span); + ftdm_m3ua_start(span); } else { fprintf(stderr, "Error starting M3UA\n"); goto done; } - //while(zap_test_flag(data, ZAP_M3UA_RUNNING)) { - // zap_sleep(1 * 1000); + //while(ftdm_test_flag(data, FTDM_M3UA_RUNNING)) { + // ftdm_sleep(1 * 1000); //} done: - zap_global_destroy(); + ftdm_global_destroy(); } diff --git a/libs/freetdm/src/testpri.c b/libs/freetdm/src/testpri.c index 1d203eae55..542f94e549 100644 --- a/libs/freetdm/src/testpri.c +++ b/libs/freetdm/src/testpri.c @@ -1,29 +1,29 @@ -#include "openzap.h" +#include "freetdm.h" #include static int THREADS[4][31] = { {0} }; static int R = 0; static int T = 0; -static zap_mutex_t *mutex = NULL; +static ftdm_mutex_t *mutex = NULL; -static void *channel_run(zap_thread_t *me, void *obj) +static void *channel_run(ftdm_thread_t *me, void *obj) { - zap_channel_t *zchan = obj; + ftdm_channel_t *ftdmchan = obj; int fd = -1; short buf[160]; - zap_mutex_lock(mutex); + ftdm_mutex_lock(mutex); T++; - zap_mutex_unlock(mutex); + ftdm_mutex_unlock(mutex); - zap_set_state_locked_wait(zchan, ZAP_CHANNEL_STATE_UP); + ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_UP); if ((fd = open("test.raw", O_RDONLY, 0)) < 0) { goto end; } - while(R == 1 && THREADS[zchan->span_id][zchan->chan_id] == 1) { + while(R == 1 && THREADS[ftdmchan->span_id][ftdmchan->chan_id] == 1) { ssize_t bytes = read(fd, buf, sizeof(buf)); size_t bbytes; @@ -35,7 +35,7 @@ static void *channel_run(zap_thread_t *me, void *obj) zio_slin2alaw(buf, sizeof(buf), &bbytes); - if (zap_channel_write(zchan, buf, sizeof(buf), &bbytes) != ZAP_SUCCESS) { + if (ftdm_channel_write(ftdmchan, buf, sizeof(buf), &bbytes) != FTDM_SUCCESS) { break; } } @@ -44,31 +44,31 @@ static void *channel_run(zap_thread_t *me, void *obj) end: - zap_set_state_locked_wait(zchan, ZAP_CHANNEL_STATE_HANGUP); + ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); - THREADS[zchan->span_id][zchan->chan_id] = 0; + THREADS[ftdmchan->span_id][ftdmchan->chan_id] = 0; - zap_mutex_lock(mutex); + ftdm_mutex_lock(mutex); T = 0; - zap_mutex_unlock(mutex); + ftdm_mutex_unlock(mutex); return NULL; } static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - zap_log(ZAP_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, zap_signal_event2str(sigmsg->event_id)); + ftdm_log(FTDM_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, ftdm_signal_event2str(sigmsg->event_id)); switch(sigmsg->event_id) { - case ZAP_SIGEVENT_STOP: + case FTDM_SIGEVENT_STOP: THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = -1; break; - case ZAP_SIGEVENT_START: + case FTDM_SIGEVENT_START: if (!THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id]) { THREADS[sigmsg->channel->span_id][sigmsg->channel->chan_id] = 1; - zap_thread_create_detached(channel_run, sigmsg->channel); + ftdm_thread_create_detached(channel_run, sigmsg->channel); } break; @@ -76,7 +76,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_signal) break; } - return ZAP_SUCCESS; + return FTDM_SUCCESS; } @@ -84,40 +84,40 @@ static void handle_SIGINT(int sig) { if (sig); - zap_mutex_lock(mutex); + ftdm_mutex_lock(mutex); R = 0; - zap_mutex_unlock(mutex); + ftdm_mutex_unlock(mutex); return; } int main(int argc, char *argv[]) { - zap_span_t *span; - zap_mutex_create(&mutex); + ftdm_span_t *span; + ftdm_mutex_create(&mutex); - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (argc < 2) { printf("umm no\n"); exit(-1); } - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); - if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding OpenFTDM span\n"); goto done; } - if (zap_configure_span( + if (ftdm_configure_span( "libpri", span, on_signal, "node", "cpe", "switch", "euroisdn", @@ -125,26 +125,26 @@ int main(int argc, char *argv[]) "l1", "alaw", "debug", NULL, "opts", 0, - TAG_END) == ZAP_SUCCESS) { + TAG_END) == FTDM_SUCCESS) { - zap_span_start(span); + ftdm_span_start(span); } else { fprintf(stderr, "Error starting ISDN D-Channel\n"); goto done; } signal(SIGINT, handle_SIGINT); - zap_mutex_lock(mutex); + ftdm_mutex_lock(mutex); R = 1; - zap_mutex_unlock(mutex); + ftdm_mutex_unlock(mutex); while(R || T) { - zap_sleep(1 * 1000); + ftdm_sleep(1 * 1000); } done: - zap_global_destroy(); + ftdm_global_destroy(); return 1; diff --git a/libs/freetdm/src/testr2.c b/libs/freetdm/src/testr2.c index 83a950cff0..e83004e20e 100644 --- a/libs/freetdm/src/testr2.c +++ b/libs/freetdm/src/testr2.c @@ -1,74 +1,74 @@ -#include "openzap.h" +#include "freetdm.h" #include static int R = 0; -static zap_mutex_t *mutex = NULL; +static ftdm_mutex_t *mutex = NULL; static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) { - zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); - return ZAP_SUCCESS; + ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", ftdm_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); + return FTDM_SUCCESS; } static void handle_SIGINT(int sig) { - zap_mutex_lock(mutex); + ftdm_mutex_lock(mutex); R = 0; - zap_mutex_unlock(mutex); + ftdm_mutex_unlock(mutex); return; } int main(int argc, char *argv[]) { - zap_span_t *span; - zap_mutex_create(&mutex); + ftdm_span_t *span; + ftdm_mutex_create(&mutex); - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (argc < 2) { printf("umm no\n"); exit(-1); } - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); - if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding OpenFTDM span\n"); goto done; } - if (zap_configure_span("r2", span, on_r2_signal, + if (ftdm_configure_span("r2", span, on_r2_signal, "variant", "mx", "max_ani", 10, "max_dnis", 4, "logging", "all", - TAG_END) == ZAP_SUCCESS) { + TAG_END) == FTDM_SUCCESS) { - zap_span_start(span); + ftdm_span_start(span); } else { fprintf(stderr, "Error starting R2 span\n"); goto done; } signal(SIGINT, handle_SIGINT); - zap_mutex_lock(mutex); + ftdm_mutex_lock(mutex); R = 1; - zap_mutex_unlock(mutex); + ftdm_mutex_unlock(mutex); while(R) { - zap_sleep(1 * 1000); + ftdm_sleep(1 * 1000); } done: - zap_global_destroy(); + ftdm_global_destroy(); return 1; diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index a0b02792c4..30733a1770 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -1,8 +1,8 @@ -#include "openzap.h" +#include "freetdm.h" static ZIO_SIGNAL_CB_FUNCTION(on_signal) { - return ZAP_FAIL; + return FTDM_FAIL; } static int R = 0; @@ -16,44 +16,44 @@ static void handle_SIGINT(int sig) #endif int main(int argc, char *argv[]) { - zap_span_t *span; + ftdm_span_t *span; int local_port, remote_port; local_port = remote_port = 53000; - zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG); + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (argc < 2) { printf("umm no\n"); exit(-1); } - if (zap_global_init() != ZAP_SUCCESS) { - fprintf(stderr, "Error loading OpenZAP\n"); + if (ftdm_global_init() != FTDM_SUCCESS) { + fprintf(stderr, "Error loading OpenFTDM\n"); exit(-1); } - if (zap_global_configuration() != ZAP_SUCCESS) { - fprintf(stderr, "Error configuring OpenZAP\n"); + if (ftdm_global_configuration() != FTDM_SUCCESS) { + fprintf(stderr, "Error configuring OpenFTDM\n"); exit(-1); } - printf("OpenZAP loaded\n"); + printf("OpenFTDM loaded\n"); - if (zap_span_find(atoi(argv[1]), &span) != ZAP_SUCCESS) { - fprintf(stderr, "Error finding OpenZAP span\n"); + if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding OpenFTDM span\n"); goto done; } #if 1 if (1) { - if (zap_configure_span("sangoma_boost", span, on_signal, + if (ftdm_configure_span("sangoma_boost", span, on_signal, "sigmod", "sangoma_brid", "local_port", &local_port, "remote_ip", "127.0.0.66", "remote_port", &remote_port, - TAG_END) == ZAP_SUCCESS) { - zap_span_start(span); + TAG_END) == FTDM_SUCCESS) { + ftdm_span_start(span); } else { fprintf(stderr, "Error starting sangoma_boost\n"); @@ -62,13 +62,13 @@ int main(int argc, char *argv[]) } #endif - while(zap_running() && R) { - zap_sleep(1 * 1000); + while(ftdm_running() && R) { + ftdm_sleep(1 * 1000); } done: - zap_global_destroy(); + ftdm_global_destroy(); return 0; } diff --git a/libs/freetdm/src/testtones.c b/libs/freetdm/src/testtones.c index 273b793acf..c4cc327772 100644 --- a/libs/freetdm/src/testtones.c +++ b/libs/freetdm/src/testtones.c @@ -1,4 +1,4 @@ -#include "openzap.h" +#include "freetdm.h" struct ttmp { int fd; diff --git a/libs/freetdm/src/uart.c b/libs/freetdm/src/uart.c index b3728e6fc8..d042496a86 100644 --- a/libs/freetdm/src/uart.c +++ b/libs/freetdm/src/uart.c @@ -32,7 +32,7 @@ * 2005 06 11 R. Krten created */ -#include +#include #include #include #include @@ -77,7 +77,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) { dsp_uart_handle_t *handle; - handle = zap_malloc(sizeof (*handle)); + handle = ftdm_malloc(sizeof (*handle)); if (handle) { memset(handle, 0, sizeof (*handle)); @@ -90,7 +90,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) void dsp_uart_destroy(dsp_uart_handle_t **handle) { if (*handle) { - zap_safe_free(*handle); + ftdm_safe_free(*handle); *handle = NULL; } } diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c deleted file mode 100644 index 6a39c9fc70..0000000000 --- a/libs/freetdm/src/zap_io.c +++ /dev/null @@ -1,3754 +0,0 @@ -/* - * Copyright (c) 2007, Anthony Minessale II - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the original author; nor the names of any contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * - * Moises Silva - * David Yat Sin - * - */ - -#define _GNU_SOURCE -#ifndef WIN32 -#endif -#include "openzap.h" -#include -#ifdef WIN32 -#include -#endif -#ifdef ZAP_PIKA_SUPPORT -#include "zap_pika.h" -#endif - -static int time_is_init = 0; - -static void time_init(void) -{ -#ifdef WIN32 - timeBeginPeriod(1); -#endif - time_is_init = 1; -} - -static void time_end(void) -{ -#ifdef WIN32 - timeEndPeriod(1); -#endif - time_is_init = 0; -} - -OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void) -{ -#ifdef WIN32 - return timeGetTime(); -#else - struct timeval tv; - gettimeofday(&tv, NULL); - return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); -#endif -} - -static struct { - zap_hash_t *interface_hash; - zap_hash_t *module_hash; - zap_hash_t *span_hash; - zap_hash_t *group_hash; - zap_mutex_t *mutex; - zap_mutex_t *span_mutex; - zap_mutex_t *group_mutex; - uint32_t span_index; - uint32_t group_index; - uint32_t running; - zap_span_t *spans; - zap_group_t *groups; -} globals; - - -/* enum lookup funcs */ -ZAP_ENUM_NAMES(TONEMAP_NAMES, TONEMAP_STRINGS) -ZAP_STR2ENUM(zap_str2zap_tonemap, zap_tonemap2str, zap_tonemap_t, TONEMAP_NAMES, ZAP_TONEMAP_INVALID) - -ZAP_ENUM_NAMES(OOB_NAMES, OOB_STRINGS) -ZAP_STR2ENUM(zap_str2zap_oob_event, zap_oob_event2str, zap_oob_event_t, OOB_NAMES, ZAP_OOB_INVALID) - -ZAP_ENUM_NAMES(TRUNK_TYPE_NAMES, TRUNK_STRINGS) -ZAP_STR2ENUM(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t, TRUNK_TYPE_NAMES, ZAP_TRUNK_NONE) - -ZAP_ENUM_NAMES(START_TYPE_NAMES, START_TYPE_STRINGS) -ZAP_STR2ENUM(zap_str2zap_analog_start_type, zap_analog_start_type2str, zap_analog_start_type_t, START_TYPE_NAMES, ZAP_ANALOG_START_NA) - -ZAP_ENUM_NAMES(SIGNAL_NAMES, SIGNAL_STRINGS) -ZAP_STR2ENUM(zap_str2zap_signal_event, zap_signal_event2str, zap_signal_event_t, SIGNAL_NAMES, ZAP_SIGEVENT_INVALID) - -ZAP_ENUM_NAMES(CHANNEL_STATE_NAMES, CHANNEL_STATE_STRINGS) -ZAP_STR2ENUM(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t, CHANNEL_STATE_NAMES, ZAP_CHANNEL_STATE_INVALID) - -ZAP_ENUM_NAMES(MDMF_TYPE_NAMES, MDMF_STRINGS) -ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYPE_NAMES, MDMF_INVALID) - -ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) -ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) - -ZAP_ENUM_NAMES(SIGNALING_STATUS_NAMES, SIGSTATUS_STRINGS) -ZAP_STR2ENUM(zap_str2zap_signaling_status, zap_signaling_status2str, zap_signaling_status_t, SIGNALING_STATUS_NAMES, ZAP_SIG_STATE_INVALID) - -static const char *cut_path(const char *in) -{ - const char *p, *ret = in; - char delims[] = "/\\"; - char *i; - - for (i = delims; *i; i++) { - p = in; - while ((p = strchr(p, *i)) != 0) { - ret = ++p; - } - } - return ret; -} - -static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) -{ - if (file && func && line && level && fmt) { - return; - } - return; -} - - -static const char *LEVEL_NAMES[] = { - "EMERG", - "ALERT", - "CRIT", - "ERROR", - "WARNING", - "NOTICE", - "INFO", - "DEBUG", - NULL -}; - -static int zap_log_level = 7; - -static void default_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) -{ - const char *fp; - char data[1024]; - va_list ap; - - if (level < 0 || level > 7) { - level = 7; - } - if (level > zap_log_level) { - return; - } - - fp = cut_path(file); - - va_start(ap, fmt); - - vsnprintf(data, sizeof(data), fmt, ap); - - - fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data); - - va_end(ap); - -} - -static __inline__ void *zap_std_malloc(void *pool, zap_size_t size) -{ - void *ptr = malloc(size); - pool = NULL; /* fix warning */ - zap_assert_return(ptr != NULL, NULL, "Out of memory"); - return ptr; -} - -static __inline__ void *zap_std_calloc(void *pool, zap_size_t elements, zap_size_t size) -{ - void *ptr = calloc(elements, size); - pool = NULL; - zap_assert_return(ptr != NULL, NULL, "Out of memory"); - return ptr; -} - -static __inline__ void zap_std_free(void *pool, void *ptr) -{ - pool = NULL; - zap_assert_return(ptr != NULL, , "Attempted to free null pointer"); - free(ptr); -} - -OZ_DECLARE_DATA zap_memory_handler_t g_zap_mem_handler = -{ - /*.pool =*/ NULL, - /*.malloc =*/ zap_std_malloc, - /*.calloc =*/ zap_std_calloc, - /*.free =*/ zap_std_free -}; - -OZ_DECLARE_DATA zap_crash_policy_t g_zap_crash_policy = ZAP_CRASH_NEVER; - -OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; - -OZ_DECLARE(void) zap_global_set_crash_policy(zap_crash_policy_t policy) -{ - g_zap_crash_policy |= policy; -} - -OZ_DECLARE(zap_status_t) zap_global_set_memory_handler(zap_memory_handler_t *handler) -{ - if (!handler) { - return ZAP_FAIL; - } - if (!handler->malloc) { - return ZAP_FAIL; - } - if (!handler->calloc) { - return ZAP_FAIL; - } - if (!handler->free) { - return ZAP_FAIL; - } - memcpy(&g_zap_mem_handler, handler, sizeof(*handler)); - return ZAP_SUCCESS; -} - -OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger) -{ - if (logger) { - zap_log = logger; - } else { - zap_log = null_logger; - } -} - -OZ_DECLARE(void) zap_global_set_default_logger(int level) -{ - if (level < 0 || level > 7) { - level = 7; - } - - zap_log = default_logger; - zap_log_level = level; -} - -OZ_DECLARE_NONSTD(int) zap_hash_equalkeys(void *k1, void *k2) -{ - return strcmp((char *) k1, (char *) k2) ? 0 : 1; -} - -OZ_DECLARE_NONSTD(uint32_t) zap_hash_hashfromstring(void *ky) -{ - unsigned char *str = (unsigned char *) ky; - uint32_t hash = 0; - int c; - - while ((c = *str++)) { - hash = c + (hash << 6) + (hash << 16) - hash; - } - - return hash; -} - -static zap_status_t zap_channel_destroy(zap_channel_t *zchan) -{ - - if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { - - while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { - zap_log(ZAP_LOG_INFO, "Waiting for thread to exit on channel %u:%u\n", zchan->span_id, zchan->chan_id); - zap_sleep(500); - } - - zap_mutex_lock(zchan->pre_buffer_mutex); - zap_buffer_destroy(&zchan->pre_buffer); - zap_mutex_unlock(zchan->pre_buffer_mutex); - - zap_buffer_destroy(&zchan->digit_buffer); - zap_buffer_destroy(&zchan->gen_dtmf_buffer); - zap_buffer_destroy(&zchan->dtmf_buffer); - zap_buffer_destroy(&zchan->fsk_buffer); - zchan->pre_buffer_size = 0; - - hashtable_destroy(zchan->variable_hash); - - zap_safe_free(zchan->dtmf_hangup_buf); - - if (zchan->tone_session.buffer) { - teletone_destroy_session(&zchan->tone_session); - memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - } - - - if (zchan->span->zio->channel_destroy) { - zap_log(ZAP_LOG_INFO, "Closing channel %s:%u:%u fd:%d\n", zchan->span->type, zchan->span_id, zchan->chan_id, zchan->sockfd); - if (zchan->span->zio->channel_destroy(zchan) == ZAP_SUCCESS) { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_CONFIGURED); - } else { - zap_log(ZAP_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", zchan->span_id, zchan->chan_id, zchan->sockfd); - } - } - - zap_mutex_destroy(&zchan->mutex); - zap_mutex_destroy(&zchan->pre_buffer_mutex); - } - - return ZAP_SUCCESS; -} - -static zap_status_t zap_span_destroy(zap_span_t *span) -{ - zap_status_t status = ZAP_SUCCESS; - unsigned j; - - zap_mutex_lock(span->mutex); - - /* stop the signaling */ - if (span->stop) { - status = span->stop(span); - } - - /* destroy the channels */ - zap_clear_flag(span, ZAP_SPAN_CONFIGURED); - for(j = 1; j <= span->chan_count && span->channels[j]; j++) { - zap_channel_t *cur_chan = span->channels[j]; - if (cur_chan) { - if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) { - zap_channel_destroy(cur_chan); - } - zap_safe_free(cur_chan); - cur_chan = NULL; - } - } - - /* destroy the I/O for the span */ - if (span->zio && span->zio->span_destroy) { - zap_log(ZAP_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); - if (span->zio->span_destroy(span) != ZAP_SUCCESS) { - status = ZAP_FAIL; - } - zap_safe_free(span->type); - zap_safe_free(span->dtmf_hangup); - } - - /* destroy final basic resources of the span data structure */ - zap_mutex_unlock(span->mutex); - zap_mutex_destroy(&span->mutex); - zap_safe_free(span->signal_data); - - return status; -} - -OZ_DECLARE(zap_status_t) zap_channel_get_alarms(zap_channel_t *zchan) -{ - zap_status_t status = ZAP_FAIL; - - if (zap_test_flag(zchan, ZAP_CHANNEL_CONFIGURED)) { - if (zchan->span->zio->get_alarms) { - if ((status = zchan->span->zio->get_alarms(zchan)) == ZAP_SUCCESS) { - *zchan->last_error = '\0'; - if (zap_test_alarm_flag(zchan, ZAP_ALARM_RED)) { - snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "RED/"); - } - if (zap_test_alarm_flag(zchan, ZAP_ALARM_YELLOW)) { - snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "YELLOW/"); - } - if (zap_test_alarm_flag(zchan, ZAP_ALARM_BLUE)) { - snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "BLUE/"); - } - if (zap_test_alarm_flag(zchan, ZAP_ALARM_LOOPBACK)) { - snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "LOOP/"); - } - if (zap_test_alarm_flag(zchan, ZAP_ALARM_RECOVER)) { - snprintf(zchan->last_error + strlen(zchan->last_error), sizeof(zchan->last_error) - strlen(zchan->last_error), "RECOVER/"); - } - *(zchan->last_error + strlen(zchan->last_error) - 1) = '\0'; - - } - } else { - status = ZAP_NOTIMPL; - } - } - - return status; -} - -static void zap_span_add(zap_span_t *span) -{ - zap_span_t *sp; - zap_mutex_lock(globals.span_mutex); - for (sp = globals.spans; sp && sp->next; sp = sp->next); - if (sp) { - sp->next = span; - } else { - globals.spans = span; - } - hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE); - zap_mutex_unlock(globals.span_mutex); -} - -#if 0 -static void zap_span_del(zap_span_t *span) -{ - zap_span_t *last = NULL, *sp; - - zap_mutex_lock(globals.span_mutex); - for (sp = globals.spans; sp; sp = sp->next) { - - if (sp == span) { - if (last) { - last->next = sp->next; - } else { - globals.spans = sp->next; - } - hashtable_remove(globals.span_hash, (void *)sp->name); - break; - } - - last = sp; - } - zap_mutex_unlock(globals.span_mutex); -} -#endif - -OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span) -{ - if (span->stop) { - span->stop(span); - return ZAP_SUCCESS; - } - - return ZAP_FAIL; -} - -OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **span, const char *name) -{ - zap_span_t *new_span = NULL; - zap_status_t status = ZAP_FAIL; - - assert(zio != NULL); - - zap_mutex_lock(globals.mutex); - - if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = zap_malloc(sizeof(*new_span)); - assert(new_span); - memset(new_span, 0, sizeof(*new_span)); - status = zap_mutex_create(&new_span->mutex); - assert(status == ZAP_SUCCESS); - - zap_set_flag(new_span, ZAP_SPAN_CONFIGURED); - new_span->span_id = ++globals.span_index; - new_span->zio = zio; - zap_copy_string(new_span->tone_map[ZAP_TONEMAP_DIAL], "%(1000,0,350,440)", ZAP_TONEMAP_LEN); - zap_copy_string(new_span->tone_map[ZAP_TONEMAP_RING], "%(2000,4000,440,480)", ZAP_TONEMAP_LEN); - zap_copy_string(new_span->tone_map[ZAP_TONEMAP_BUSY], "%(500,500,480,620)", ZAP_TONEMAP_LEN); - zap_copy_string(new_span->tone_map[ZAP_TONEMAP_ATTN], "%(100,100,1400,2060,2450,2600)", ZAP_TONEMAP_LEN); - new_span->trunk_type = ZAP_TRUNK_NONE; - new_span->data_type = ZAP_TYPE_SPAN; - - zap_mutex_lock(globals.span_mutex); - if (!zap_strlen_zero(name) && hashtable_search(globals.span_hash, (void *)name)) { - zap_log(ZAP_LOG_WARNING, "name %s is already used, substituting 'span%d' as the name\n", name, new_span->span_id); - name = NULL; - } - zap_mutex_unlock(globals.span_mutex); - - if (!name) { - char buf[128] = ""; - snprintf(buf, sizeof(buf), "span%d", new_span->span_id); - name = buf; - } - new_span->name = zap_strdup(name); - zap_span_add(new_span); - *span = new_span; - status = ZAP_SUCCESS; - } - zap_mutex_unlock(globals.mutex); - return status; -} - -OZ_DECLARE(zap_status_t) zap_span_close_all(void) -{ - zap_span_t *span; - uint32_t i = 0, j; - - zap_mutex_lock(globals.span_mutex); - for (span = globals.spans; span; span = span->next) { - if (zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - for(j = 1; j <= span->chan_count && span->channels[j]; j++) { - zap_channel_t *toclose = span->channels[j]; - if (zap_test_flag(toclose, ZAP_CHANNEL_INUSE)) { - zap_channel_close(&toclose); - } - i++; - } - } - } - zap_mutex_unlock(globals.span_mutex); - - return i ? ZAP_SUCCESS : ZAP_FAIL; -} - -OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapname) -{ - zap_config_t cfg; - char *var, *val; - int x = 0; - - if (!zap_config_open_file(&cfg, "tones.conf")) { - snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - int detect = 0; - - if (!strcasecmp(cfg.category, mapname) && var && val) { - uint32_t index; - char *name = NULL; - - if (!strncasecmp(var, "detect-", 7)) { - name = var + 7; - detect = 1; - } else if (!strncasecmp(var, "generate-", 9)) { - name = var + 9; - } else { - zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", var); - continue; - } - - index = zap_str2zap_tonemap(name); - - if (index >= ZAP_TONEMAP_INVALID || index == ZAP_TONEMAP_NONE) { - zap_log(ZAP_LOG_WARNING, "Unknown tone name %s\n", name); - } else { - if (detect) { - char *p = val, *next; - int i = 0; - do { - teletone_process_t this; - next = strchr(p, ','); - this = (teletone_process_t)atof(p); - span->tone_detect_map[index].freqs[i++] = this; - if (next) { - p = next + 1; - } - } while (next); - zap_log(ZAP_LOG_DEBUG, "added tone detect [%s] = [%s]\n", name, val); - } else { - zap_log(ZAP_LOG_DEBUG, "added tone generation [%s] = [%s]\n", name, val); - zap_copy_string(span->tone_map[index], val, sizeof(span->tone_map[index])); - } - x++; - } - } - } - - zap_config_close_file(&cfg); - - if (!x) { - snprintf(span->last_error, sizeof(span->last_error), "error loading tones."); - return ZAP_FAIL; - } - - return ZAP_SUCCESS; - -} - -#define ZAP_SLINEAR_MAX_VALUE 32767 -#define ZAP_SLINEAR_MIN_VALUE -32767 -static void reset_gain_table(unsigned char *gain_table, float new_gain, zap_codec_t codec_gain) -{ - /* sample value */ - unsigned sv = 0; - /* linear gain factor */ - float lingain = 0; - /* linear value for each table sample */ - float linvalue = 0; - /* amplified (or attenuated in case of negative amplification) sample value */ - int ampvalue = 0; - - /* gain tables are only for alaw and ulaw */ - if (codec_gain != ZAP_CODEC_ALAW && codec_gain != ZAP_CODEC_ULAW) { - zap_log(ZAP_LOG_WARNING, "Not resetting gain table because codec is not ALAW or ULAW but %d\n", codec_gain); - return; - } - - if (!new_gain) { - /* for a 0.0db gain table, each alaw/ulaw sample value is left untouched (0 ==0, 1 == 1, 2 == 2 etc)*/ - for (sv = 0; sv < ZAP_GAINS_TABLE_SIZE; sv++) { - gain_table[sv] = sv; - } - return; - } - - /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wipedia.org/wiki/20_log_rule#Definitions */ - lingain = pow(10.0, new_gain/ 20.0); - for (sv = 0; sv < ZAP_GAINS_TABLE_SIZE; sv++) { - /* get the linear value for this alaw/ulaw sample value */ - linvalue = codec_gain == ZAP_CODEC_ALAW ? alaw_to_linear(sv) : ulaw_to_linear(sv); - - /* multiply the linear value and the previously calculated linear gain */ - ampvalue = (int)(linvalue * lingain); - - /* chop it if goes beyond the limits */ - if (ampvalue > ZAP_SLINEAR_MAX_VALUE) { - ampvalue = ZAP_SLINEAR_MAX_VALUE; - } - - if (ampvalue < ZAP_SLINEAR_MIN_VALUE) { - ampvalue = ZAP_SLINEAR_MIN_VALUE; - } - gain_table[sv] = codec_gain == ZAP_CODEC_ALAW ? linear_to_alaw(ampvalue) : linear_to_ulaw(ampvalue); - } -} - -OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) -{ - unsigned i = 0; - if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { - zap_channel_t *new_chan = span->channels[++span->chan_count]; - - if (!new_chan) { - if (!(new_chan = zap_calloc(1, sizeof(*new_chan)))) { - return ZAP_FAIL; - } - span->channels[span->chan_count] = new_chan; - } - - new_chan->type = type; - new_chan->sockfd = sockfd; - new_chan->zio = span->zio; - new_chan->span_id = span->span_id; - new_chan->chan_id = span->chan_count; - new_chan->span = span; - new_chan->fds[0] = -1; - new_chan->fds[1] = -1; - new_chan->data_type = ZAP_TYPE_CHANNEL; - if (!new_chan->dtmf_on) { - new_chan->dtmf_on = ZAP_DEFAULT_DTMF_ON; - } - - if (!new_chan->dtmf_off) { - new_chan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; - } - - zap_mutex_create(&new_chan->mutex); - zap_mutex_create(&new_chan->pre_buffer_mutex); - - zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); - zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); - new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - - new_chan->dtmf_hangup_buf = zap_calloc (span->dtmf_hangup_len + 1, sizeof (char)); - - /* set 0.0db gain table */ - for (i = 0; i < sizeof(new_chan->txgain_table); i++) { - new_chan->txgain_table[i] = i; - new_chan->rxgain_table[i] = i; - } - - zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); - *chan = new_chan; - return ZAP_SUCCESS; - } - - return ZAP_FAIL; -} - -OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span) -{ - zap_status_t status = ZAP_FAIL; - - zap_mutex_lock(globals.span_mutex); - if (!zap_strlen_zero(name)) { - if ((*span = hashtable_search(globals.span_hash, (void *)name))) { - status = ZAP_SUCCESS; - } else { - int span_id = atoi(name); - - zap_span_find(span_id, span); - if (*span) { - status = ZAP_SUCCESS; - } - } - } - zap_mutex_unlock(globals.span_mutex); - - return status; -} - -OZ_DECLARE(zap_status_t) zap_span_find(uint32_t id, zap_span_t **span) -{ - zap_span_t *fspan = NULL, *sp; - - if (id > ZAP_MAX_SPANS_INTERFACE) { - return ZAP_FAIL; - } - - zap_mutex_lock(globals.span_mutex); - for (sp = globals.spans; sp; sp = sp->next) { - if (sp->span_id == id) { - fspan = sp; - break; - } - } - zap_mutex_unlock(globals.span_mutex); - - if (!fspan || !zap_test_flag(fspan, ZAP_SPAN_CONFIGURED)) { - return ZAP_FAIL; - } - - *span = fspan; - - return ZAP_SUCCESS; - -} - -OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback) -{ - zap_mutex_lock(span->mutex); - span->event_callback = event_callback; - zap_mutex_unlock(span->mutex); - return ZAP_SUCCESS; -} - - -OZ_DECLARE(zap_status_t) zap_span_poll_event(zap_span_t *span, uint32_t ms) -{ - assert(span->zio != NULL); - - if (span->zio->poll_event) { - return span->zio->poll_event(span, ms); - } else { - zap_log(ZAP_LOG_ERROR, "poll_event method not implemented in module %s!", span->zio->name); - } - - return ZAP_NOTIMPL; -} - -OZ_DECLARE(zap_status_t) zap_span_next_event(zap_span_t *span, zap_event_t **event) -{ - assert(span->zio != NULL); - - if (span->zio->next_event) { - return span->zio->next_event(span, event); - } else { - zap_log(ZAP_LOG_ERROR, "next_event method not implemented in module %s!", span->zio->name); - } - - return ZAP_NOTIMPL; -} - -static zap_status_t zchan_fsk_write_sample(int16_t *buf, zap_size_t buflen, void *user_data) -{ - zap_channel_t *zchan = (zap_channel_t *) user_data; - zap_buffer_write(zchan->fsk_buffer, buf, buflen * 2); - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_send_fsk_data(zap_channel_t *zchan, zap_fsk_data_state_t *fsk_data, float db_level) -{ - struct zap_fsk_modulator fsk_trans; - - if (!zchan->fsk_buffer) { - zap_buffer_create(&zchan->fsk_buffer, 128, 128, 0); - } else { - zap_buffer_zero(zchan->fsk_buffer); - } - - if (zchan->token_count > 1) { - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 80, 5, 0, zchan_fsk_write_sample, zchan); - zap_fsk_modulator_send_all((&fsk_trans)); - } else { - zap_fsk_modulator_init(&fsk_trans, FSK_BELL202, zchan->rate, fsk_data, db_level, 180, 5, 300, zchan_fsk_write_sample, zchan); - zap_fsk_modulator_send_all((&fsk_trans)); - zchan->buffer_delay = 3500 / zchan->effective_interval; - } - - return ZAP_SUCCESS; -} - - -OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback) -{ - zap_mutex_lock(zchan->mutex); - zchan->event_callback = event_callback; - zap_mutex_unlock(zchan->mutex); - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_clear_token(zap_channel_t *zchan, const char *token) -{ - zap_status_t status = ZAP_FAIL; - - zap_mutex_lock(zchan->mutex); - if (token == NULL) { - memset(zchan->tokens, 0, sizeof(zchan->tokens)); - zchan->token_count = 0; - } else if (*token != '\0') { - char tokens[ZAP_MAX_TOKENS][ZAP_TOKEN_STRLEN]; - int32_t i, count = zchan->token_count; - memcpy(tokens, zchan->tokens, sizeof(tokens)); - memset(zchan->tokens, 0, sizeof(zchan->tokens)); - zchan->token_count = 0; - - for (i = 0; i < count; i++) { - if (strcmp(tokens[i], token)) { - zap_copy_string(zchan->tokens[zchan->token_count], tokens[i], sizeof(zchan->tokens[zchan->token_count])); - zchan->token_count++; - } - } - - status = ZAP_SUCCESS; - } - zap_mutex_unlock(zchan->mutex); - - return status; -} - -OZ_DECLARE(void) zap_channel_rotate_tokens(zap_channel_t *zchan) -{ - if (zchan->token_count) { - memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); - zap_copy_string(zchan->tokens[0], zchan->tokens[zchan->token_count], ZAP_TOKEN_STRLEN); - *zchan->tokens[zchan->token_count] = '\0'; - } -} - -OZ_DECLARE(void) zap_channel_replace_token(zap_channel_t *zchan, const char *old_token, const char *new_token) -{ - unsigned int i; - - if (zchan->token_count) { - for(i = 0; i < zchan->token_count; i++) { - if (!strcmp(zchan->tokens[i], old_token)) { - zap_copy_string(zchan->tokens[i], new_token, ZAP_TOKEN_STRLEN); - break; - } - } - } -} - -OZ_DECLARE(zap_status_t) zap_channel_add_token(zap_channel_t *zchan, char *token, int end) -{ - zap_status_t status = ZAP_FAIL; - - zap_mutex_lock(zchan->mutex); - if (zchan->token_count < ZAP_MAX_TOKENS) { - if (end) { - zap_copy_string(zchan->tokens[zchan->token_count++], token, ZAP_TOKEN_STRLEN); - } else { - memmove(zchan->tokens[1], zchan->tokens[0], zchan->token_count * ZAP_TOKEN_STRLEN); - zap_copy_string(zchan->tokens[0], token, ZAP_TOKEN_STRLEN); - zchan->token_count++; - } - status = ZAP_SUCCESS; - } - zap_mutex_unlock(zchan->mutex); - - return status; -} - - -OZ_DECLARE(zap_status_t) zap_channel_complete_state(zap_channel_t *zchan) -{ - zap_channel_state_t state = zchan->state; - - if (state == ZAP_CHANNEL_STATE_PROGRESS) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - } else if (state == ZAP_CHANNEL_STATE_UP) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); - zap_set_flag(zchan, ZAP_CHANNEL_ANSWERED); - } else if (state == ZAP_CHANNEL_STATE_PROGRESS_MEDIA) { - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_set_flag(zchan, ZAP_CHANNEL_MEDIA); - } - - return ZAP_SUCCESS; -} - -static int zap_parse_state_map(zap_channel_t *zchan, zap_channel_state_t state, zap_state_map_t *state_map) -{ - int x = 0, ok = 0; - zap_state_direction_t direction = zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND) ? ZSD_OUTBOUND : ZSD_INBOUND; - - for(x = 0; x < ZAP_MAP_NODE_SIZE; x++) { - int i = 0, proceed = 0; - if (!state_map->nodes[x].type) { - break; - } - - if (state_map->nodes[x].direction != direction) { - continue; - } - - if (state_map->nodes[x].check_states[0] == ZAP_ANY_STATE) { - proceed = 1; - } else { - for(i = 0; i < ZAP_MAP_MAX; i++) { - if (state_map->nodes[x].check_states[i] == zchan->state) { - proceed = 1; - break; - } - } - } - - if (!proceed) { - continue; - } - - for(i = 0; i < ZAP_MAP_MAX; i++) { - ok = (state_map->nodes[x].type == ZSM_ACCEPTABLE); - if (state_map->nodes[x].states[i] == ZAP_END) { - break; - } - if (state_map->nodes[x].states[i] == state) { - ok = !ok; - goto end; - } - } - } - end: - - return ok; -} - -OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t state, int lock) -{ - int ok = 1; - - if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { - return ZAP_FAIL; - } - - if (zap_test_flag(zchan->span, ZAP_SPAN_SUSPENDED)) { - if (state != ZAP_CHANNEL_STATE_RESTART && state != ZAP_CHANNEL_STATE_DOWN) { - return ZAP_FAIL; - } - } - - if (lock) { - zap_mutex_lock(zchan->mutex); - } - - if (zchan->span->state_map) { - ok = zap_parse_state_map(zchan, state, zchan->span->state_map); - goto end; - } - - switch(zchan->state) { - case ZAP_CHANNEL_STATE_HANGUP: - case ZAP_CHANNEL_STATE_TERMINATING: - { - ok = 0; - switch(state) { - case ZAP_CHANNEL_STATE_DOWN: - case ZAP_CHANNEL_STATE_BUSY: - case ZAP_CHANNEL_STATE_RESTART: - ok = 1; - break; - default: - break; - } - } - break; - case ZAP_CHANNEL_STATE_UP: - { - ok = 1; - switch(state) { - case ZAP_CHANNEL_STATE_PROGRESS: - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - case ZAP_CHANNEL_STATE_RING: - ok = 0; - break; - default: - break; - } - } - break; - case ZAP_CHANNEL_STATE_DOWN: - { - ok = 0; - - switch(state) { - case ZAP_CHANNEL_STATE_DIALTONE: - case ZAP_CHANNEL_STATE_COLLECT: - case ZAP_CHANNEL_STATE_DIALING: - case ZAP_CHANNEL_STATE_RING: - case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - case ZAP_CHANNEL_STATE_PROGRESS: - case ZAP_CHANNEL_STATE_GET_CALLERID: - case ZAP_CHANNEL_STATE_GENRING: - ok = 1; - break; - default: - break; - } - } - break; - case ZAP_CHANNEL_STATE_BUSY: - { - switch(state) { - case ZAP_CHANNEL_STATE_UP: - ok = 0; - break; - default: - break; - } - } - break; - case ZAP_CHANNEL_STATE_RING: - { - switch(state) { - case ZAP_CHANNEL_STATE_UP: - ok = 1; - break; - default: - break; - } - } - break; - default: - break; - } - - end: - - if (state == zchan->state) { - ok = 0; - } - - - if (ok) { - zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_set_flag_locked(zchan->span, ZAP_SPAN_STATE_CHANGE); - zchan->last_state = zchan->state; - zchan->state = state; - } - - if (lock) { - zap_mutex_unlock(zchan->mutex); - } - - return ok ? ZAP_SUCCESS : ZAP_FAIL; -} - - -OZ_DECLARE(zap_status_t) zap_group_channel_use_count(zap_group_t *group, uint32_t *count) -{ - uint32_t j; - - *count = 0; - - if (!group) { - return ZAP_FAIL; - } - - for(j = 0; j < group->chan_count && group->channels[j]; j++) { - if (group->channels[j]) { - if (zap_test_flag(group->channels[j], ZAP_CHANNEL_INUSE)) { - (*count)++; - } - } - } - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) -{ - zap_status_t status = ZAP_FAIL; - zap_channel_t *check; - uint32_t i, count; - zap_group_t *group = NULL; - - if (group_id) { - zap_group_find(group_id, &group); - } - - if (!group ) { - zap_log(ZAP_LOG_CRIT, "GROUP NOT DEFINED!\n"); - *zchan = NULL; - return ZAP_FAIL; - } - - zap_group_channel_use_count(group, &count); - - if (count >= group->chan_count) { - zap_log(ZAP_LOG_CRIT, "All circuits are busy.\n"); - *zchan = NULL; - return ZAP_FAIL; - } - - - if (direction == ZAP_TOP_DOWN) { - i = 0; - } else { - i = group->chan_count-1; - } - - zap_mutex_lock(group->mutex); - for (;;) { - if (direction == ZAP_TOP_DOWN) { - if (i >= group->chan_count) { - break; - } - } else { - if (i < 0) { - break; - } - } - - if (!(check = group->channels[i])) { - status = ZAP_FAIL; - break; - } - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && - !zap_test_flag(check, ZAP_CHANNEL_INUSE) && - !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && - check->state == ZAP_CHANNEL_STATE_DOWN && - check->type != ZAP_CHAN_TYPE_DQ921 && - check->type != ZAP_CHAN_TYPE_DQ931 - - ) { - zap_span_t* span = NULL; - zap_span_find(check->span_id, &span); - if (span && span->channel_request) { - status = span->channel_request(span, check->chan_id, direction, caller_data, zchan); - break; - } - - status = check->zio->open(check); - - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_INUSE); - zap_channel_open_chan(check); - *zchan = check; - break; - } - } - - if (direction == ZAP_TOP_DOWN) { - i++; - } else { - i--; - } - } - zap_mutex_unlock(group->mutex); - return status; -} - - -OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count) -{ - uint32_t j; - - *count = 0; - - if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - return ZAP_FAIL; - } - - for(j = 1; j <= span->chan_count && span->channels[j]; j++) { - if (span->channels[j]) { - if (zap_test_flag(span->channels[j], ZAP_CHANNEL_INUSE)) { - (*count)++; - } - } - } - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan) -{ - zap_status_t status = ZAP_FAIL; - zap_channel_t *check; - uint32_t i, j, count; - zap_span_t *span = NULL; - uint32_t span_max; - - if (span_id) { - zap_span_find(span_id, &span); - - if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { - zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); - *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; - } - - if (span->channel_request && !span->suggest_chan_id) { - return span->channel_request(span, 0, direction, caller_data, zchan); - } - - span_max = span_id; - j = span_id; - } else { - zap_log(ZAP_LOG_CRIT, "No span supplied\n"); - *zchan = NULL; - return ZAP_FAIL; - } - - zap_mutex_lock(span->mutex); - - if (direction == ZAP_TOP_DOWN) { - i = 1; - } else { - i = span->chan_count; - } - - for(;;) { - - if (direction == ZAP_TOP_DOWN) { - if (i > span->chan_count) { - break; - } - } else { - if (i == 0) { - break; - } - } - - if (!(check = span->channels[i])) { - status = ZAP_FAIL; - break; - } - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && - !zap_test_flag(check, ZAP_CHANNEL_INUSE) && - !zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) && - check->state == ZAP_CHANNEL_STATE_DOWN && - check->type != ZAP_CHAN_TYPE_DQ921 && - check->type != ZAP_CHAN_TYPE_DQ931 - - ) { - - if (span && span->channel_request) { - status = span->channel_request(span, i, direction, caller_data, zchan); - break; - } - - status = check->zio->open(check); - - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_INUSE); - zap_channel_open_chan(check); - *zchan = check; - break; - } - } - - if (direction == ZAP_TOP_DOWN) { - i++; - } else { - i--; - } - } - - zap_mutex_unlock(span->mutex); - - return status; -} - -static zap_status_t zap_channel_reset(zap_channel_t *zchan) -{ - zap_clear_flag(zchan, ZAP_CHANNEL_OPEN); - zchan->event_callback = NULL; - zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - zap_channel_done(zchan); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_HOLD); - - memset(zchan->tokens, 0, sizeof(zchan->tokens)); - zchan->token_count = 0; - - if (zchan->dtmf_buffer) { - zap_buffer_zero(zchan->dtmf_buffer); - } - - if (zchan->gen_dtmf_buffer) { - zap_buffer_zero(zchan->gen_dtmf_buffer); - } - - if (zchan->digit_buffer) { - zap_buffer_zero(zchan->digit_buffer); - } - - if (!zchan->dtmf_on) { - zchan->dtmf_on = ZAP_DEFAULT_DTMF_ON; - } - - if (!zchan->dtmf_off) { - zchan->dtmf_off = ZAP_DEFAULT_DTMF_OFF; - } - - memset(zchan->dtmf_hangup_buf, '\0', zchan->span->dtmf_hangup_len); - - if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE)) { - zchan->effective_codec = zchan->native_codec; - zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); - } - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_init(zap_channel_t *zchan) -{ - if (zchan->init_state != ZAP_CHANNEL_STATE_DOWN) { - zap_set_state_locked(zchan, zchan->init_state); - zchan->init_state = ZAP_CHANNEL_STATE_DOWN; - } - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan) -{ - zap_status_t status = ZAP_FAIL; - - assert(zchan != NULL); - - if (zap_test_flag(zchan, ZAP_CHANNEL_SUSPENDED)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is suspended"); - return ZAP_FAIL; - } - - if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "Channel is not ready or is in use %d %d", zap_test_flag(zchan, ZAP_CHANNEL_READY), status); - return status; - } - - status = ZAP_FAIL; - - if (zap_test_flag(zchan, ZAP_CHANNEL_READY)) { - status = zchan->span->zio->open(zchan); - if (status == ZAP_SUCCESS) { - zap_set_flag(zchan, ZAP_CHANNEL_OPEN | ZAP_CHANNEL_INUSE); - } - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready"); - } - - zap_mutex_unlock(zchan->mutex); - return status; -} - -OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan) -{ - zap_channel_t *check; - zap_status_t status = ZAP_FAIL; - zap_span_t *span = NULL; - - zap_mutex_unlock(globals.mutex); - zap_span_find(span_id, &span); - - if (!span || !zap_test_flag(span, ZAP_SPAN_CONFIGURED) || chan_id >= ZAP_MAX_CHANNELS_SPAN) { - zap_log(ZAP_LOG_CRIT, "SPAN NOT DEFINED!\n"); - *zchan = NULL; - goto done; - } - - if (span->channel_request) { - zap_log(ZAP_LOG_ERROR, "Individual channel selection not implemented on this span.\n"); - *zchan = NULL; - goto done; - } - - if (!(check = span->channels[chan_id])) { - zap_log(ZAP_LOG_ERROR, "Invalid Channel %d\n", chan_id); - *zchan = NULL; - goto done; - } - - if (zap_test_flag(check, ZAP_CHANNEL_SUSPENDED) || - !zap_test_flag(check, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(check->mutex)) != ZAP_SUCCESS) { - *zchan = NULL; - goto done; - } - - status = ZAP_FAIL; - - if (zap_test_flag(check, ZAP_CHANNEL_READY) && (!zap_test_flag(check, ZAP_CHANNEL_INUSE) || - (check->type == ZAP_CHAN_TYPE_FXS && check->token_count == 1))) { - if (!zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->open(check); - if (status == ZAP_SUCCESS) { - zap_set_flag(check, ZAP_CHANNEL_OPEN); - } - } else { - status = ZAP_SUCCESS; - } - zap_set_flag(check, ZAP_CHANNEL_INUSE); - *zchan = check; - } - zap_mutex_unlock(check->mutex); - - done: - zap_mutex_unlock(globals.mutex); - - return status; -} - -OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) -{ - zap_status_t status; - - assert(zchan != NULL); - - if (zchan->span->outgoing_call) { - if ((status = zchan->span->outgoing_call(zchan)) == ZAP_SUCCESS) { - zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND); - } - return status; - } else { - zap_log(ZAP_LOG_ERROR, "outgoing_call method not implemented!\n"); - } - - return ZAP_FAIL; -} - -OZ_DECLARE(zap_status_t) zap_channel_set_sig_status(zap_channel_t *zchan, zap_signaling_status_t sigstatus) -{ - zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n"); - zap_assert_return(zchan->span != NULL, ZAP_FAIL, "Null span\n"); - - if (zchan->span->set_channel_sig_status) { - return zchan->span->set_channel_sig_status(zchan, sigstatus); - } else { - zap_log(ZAP_LOG_ERROR, "set_channel_sig_status method not implemented!\n"); - return ZAP_FAIL; - } -} - -OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_signaling_status_t *sigstatus) -{ - zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n"); - zap_assert_return(zchan->span != NULL, ZAP_FAIL, "Null span\n"); - zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status parameter\n"); - - if (zchan->span->get_channel_sig_status) { - return zchan->span->get_channel_sig_status(zchan, sigstatus); - } else { - zap_log(ZAP_LOG_ERROR, "get_channel_sig_status method not implemented!\n"); - return ZAP_FAIL; - } -} - -OZ_DECLARE(zap_status_t) zap_span_set_sig_status(zap_span_t *span, zap_signaling_status_t sigstatus) -{ - zap_assert_return(span != NULL, ZAP_FAIL, "Null span\n"); - - if (span->set_span_sig_status) { - return span->set_span_sig_status(span, sigstatus); - } else { - zap_log(ZAP_LOG_ERROR, "set_span_sig_status method not implemented!\n"); - return ZAP_FAIL; - } -} - -OZ_DECLARE(zap_status_t) zap_span_get_sig_status(zap_span_t *span, zap_signaling_status_t *sigstatus) -{ - zap_assert_return(span != NULL, ZAP_FAIL, "Null span\n"); - zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status parameter\n"); - - if (span->get_span_sig_status) { - return span->get_span_sig_status(span, sigstatus); - } else { - zap_log(ZAP_LOG_ERROR, "get_span_sig_status method not implemented!\n"); - return ZAP_FAIL; - } -} - -OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) -{ - assert(zchan != NULL); - - zap_mutex_lock(zchan->mutex); - - memset(&zchan->caller_data, 0, sizeof(zchan->caller_data)); - - zap_clear_flag(zchan, ZAP_CHANNEL_INUSE); - zap_clear_flag(zchan, ZAP_CHANNEL_OUTBOUND); - zap_clear_flag(zchan, ZAP_CHANNEL_WINK); - zap_clear_flag(zchan, ZAP_CHANNEL_FLASH); - zap_clear_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); - zap_clear_flag(zchan, ZAP_CHANNEL_HOLD); - zap_clear_flag(zchan, ZAP_CHANNEL_OFFHOOK); - zap_clear_flag(zchan, ZAP_CHANNEL_RINGING); - zap_clear_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - zap_clear_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT); - zap_clear_flag(zchan, ZAP_CHANNEL_3WAY); - zap_clear_flag(zchan, ZAP_CHANNEL_PROGRESS); - zap_clear_flag(zchan, ZAP_CHANNEL_MEDIA); - zap_clear_flag(zchan, ZAP_CHANNEL_ANSWERED); - zap_mutex_lock(zchan->pre_buffer_mutex); - zap_buffer_destroy(&zchan->pre_buffer); - zchan->pre_buffer_size = 0; - zap_mutex_unlock(zchan->pre_buffer_mutex); - - zchan->init_state = ZAP_CHANNEL_STATE_DOWN; - zchan->state = ZAP_CHANNEL_STATE_DOWN; - - zap_log(ZAP_LOG_DEBUG, "channel done %u:%u\n", zchan->span_id, zchan->chan_id); - - zap_mutex_unlock(zchan->mutex); - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan) -{ - - assert(zchan != NULL); - - zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE); - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan) -{ - zap_channel_t *check; - zap_status_t status = ZAP_FAIL; - - assert(zchan != NULL); - check = *zchan; - *zchan = NULL; - - if (!check) { - return ZAP_FAIL; - } - - if (!zap_test_flag(check, ZAP_CHANNEL_INUSE)) { - zap_log(ZAP_LOG_WARNING, "Called zap_channel_close but never zap_channel_open in chan %d:%d??\n", check->span_id, check->chan_id); - return ZAP_FAIL; - } - - if (zap_test_flag(check, ZAP_CHANNEL_CONFIGURED)) { - zap_mutex_lock(check->mutex); - if (zap_test_flag(check, ZAP_CHANNEL_OPEN)) { - status = check->zio->close(check); - if (status == ZAP_SUCCESS) { - zap_clear_flag(check, ZAP_CHANNEL_INUSE); - zap_channel_reset(check); - *zchan = NULL; - } - } - check->ring_count = 0; - zap_mutex_unlock(check->mutex); - } - - return status; -} - - -static zap_status_t zchan_activate_dtmf_buffer(zap_channel_t *zchan) -{ - - if (!zchan->dtmf_buffer) { - if (zap_buffer_create(&zchan->dtmf_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Failed to allocate DTMF Buffer!\n"); - snprintf(zchan->last_error, sizeof(zchan->last_error), "buffer error"); - return ZAP_FAIL; - } else { - zap_log(ZAP_LOG_DEBUG, "Created DTMF Buffer!\n"); - } - } - - - if (!zchan->tone_session.buffer) { - memset(&zchan->tone_session, 0, sizeof(zchan->tone_session)); - teletone_init_session(&zchan->tone_session, 0, NULL, NULL); - } - - zchan->tone_session.rate = zchan->rate; - zchan->tone_session.duration = zchan->dtmf_on * (zchan->tone_session.rate / 1000); - zchan->tone_session.wait = zchan->dtmf_off * (zchan->tone_session.rate / 1000); - zchan->tone_session.volume = -7; - - /* - zchan->tone_session.debug = 1; - zchan->tone_session.debug_stream = stdout; - */ - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t command, void *obj) -{ - zap_status_t status = ZAP_FAIL; - - assert(zchan != NULL); - assert(zchan->zio != NULL); - - zap_mutex_lock(zchan->mutex); - - switch(command) { - - case ZAP_COMMAND_ENABLE_CALLERID_DETECT: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CALLERID)) { - if (zap_fsk_demod_init(&zchan->fsk, zchan->rate, zchan->fsk_buf, sizeof(zchan->fsk_buf)) != ZAP_SUCCESS) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - GOTO_STATUS(done, ZAP_FAIL); - } - zap_set_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); - } - } - break; - case ZAP_COMMAND_DISABLE_CALLERID_DETECT: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CALLERID)) { - zap_fsk_demod_destroy(&zchan->fsk); - zap_clear_flag_locked(zchan, ZAP_CHANNEL_CALLERID_DETECT); - } - } - break; - case ZAP_COMMAND_TRACE_INPUT: - { - char *path = (char *) obj; - if (zchan->fds[0] > 0) { - close(zchan->fds[0]); - zchan->fds[0] = -1; - } - if ((zchan->fds[0] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { - zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path); - GOTO_STATUS(done, ZAP_SUCCESS); - } - - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - GOTO_STATUS(done, ZAP_FAIL); - } - break; - case ZAP_COMMAND_TRACE_OUTPUT: - { - char *path = (char *) obj; - if (zchan->fds[1] > 0) { - close(zchan->fds[1]); - zchan->fds[1] = -1; - } - if ((zchan->fds[1] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { - zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path); - GOTO_STATUS(done, ZAP_SUCCESS); - } - - snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - GOTO_STATUS(done, ZAP_FAIL); - } - break; - case ZAP_COMMAND_SET_INTERVAL: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { - zchan->effective_interval = ZAP_COMMAND_OBJ_INT; - if (zchan->effective_interval == zchan->native_interval) { - zap_clear_flag(zchan, ZAP_CHANNEL_BUFFER); - } else { - zap_set_flag(zchan, ZAP_CHANNEL_BUFFER); - } - zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_GET_INTERVAL: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { - ZAP_COMMAND_OBJ_INT = zchan->effective_interval; - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_SET_CODEC: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { - zchan->effective_codec = ZAP_COMMAND_OBJ_INT; - - if (zchan->effective_codec == zchan->native_codec) { - zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); - } else { - zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); - } - zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - - case ZAP_COMMAND_SET_NATIVE_CODEC: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { - zchan->effective_codec = zchan->native_codec; - zap_clear_flag(zchan, ZAP_CHANNEL_TRANSCODE); - zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - - case ZAP_COMMAND_GET_CODEC: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { - ZAP_COMMAND_OBJ_INT = zchan->effective_codec; - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_GET_NATIVE_CODEC: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { - ZAP_COMMAND_OBJ_INT = zchan->native_codec; - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_ENABLE_PROGRESS_DETECT: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { - /* if they don't have thier own, use ours */ - zap_channel_clear_detected_tones(zchan); - zap_channel_clear_needed_tones(zchan); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_DIAL], &zchan->span->tone_detect_map[ZAP_TONEMAP_DIAL]); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_RING], &zchan->span->tone_detect_map[ZAP_TONEMAP_RING]); - teletone_multi_tone_init(&zchan->span->tone_finder[ZAP_TONEMAP_BUSY], &zchan->span->tone_detect_map[ZAP_TONEMAP_BUSY]); - zap_set_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_DISABLE_PROGRESS_DETECT: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { - zap_clear_flag_locked(zchan, ZAP_CHANNEL_PROGRESS_DETECT); - zap_channel_clear_detected_tones(zchan); - zap_channel_clear_needed_tones(zchan); - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_ENABLE_DTMF_DETECT: - { - /* if they don't have thier own, use ours */ - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { - zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; - if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); - zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - GOTO_STATUS(done, ZAP_SUCCESS); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - GOTO_STATUS(done, ZAP_FAIL); - } - } - } - break; - case ZAP_COMMAND_DISABLE_DTMF_DETECT: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { - zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; - if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); - zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - GOTO_STATUS(done, ZAP_SUCCESS); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - GOTO_STATUS(done, ZAP_FAIL); - } - } - } - - case ZAP_COMMAND_SET_PRE_BUFFER_SIZE: - { - int val = ZAP_COMMAND_OBJ_INT; - - if (val < 0) { - val = 0; - } - - zchan->pre_buffer_size = val * 8; - - zap_mutex_lock(zchan->pre_buffer_mutex); - if (!zchan->pre_buffer_size) { - zap_buffer_destroy(&zchan->pre_buffer); - } else if (!zchan->pre_buffer) { - zap_buffer_create(&zchan->pre_buffer, 1024, zchan->pre_buffer_size, 0); - } - zap_mutex_unlock(zchan->pre_buffer_mutex); - - GOTO_STATUS(done, ZAP_SUCCESS); - - } - break; - case ZAP_COMMAND_GET_DTMF_ON_PERIOD: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_GET_DTMF_OFF_PERIOD: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - ZAP_COMMAND_OBJ_INT = zchan->dtmf_on; - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - case ZAP_COMMAND_SET_DTMF_ON_PERIOD: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - 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: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - 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: - { - if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_GENERATE)) { - char *digits = ZAP_COMMAND_OBJ_CHAR_P; - - if ((status = zchan_activate_dtmf_buffer(zchan)) != ZAP_SUCCESS) { - GOTO_STATUS(done, status); - } - - zap_buffer_write(zchan->gen_dtmf_buffer, digits, strlen(digits)); - - GOTO_STATUS(done, ZAP_SUCCESS); - } - } - break; - - case ZAP_COMMAND_DISABLE_ECHOCANCEL: - { - zap_mutex_lock(zchan->pre_buffer_mutex); - zap_buffer_destroy(&zchan->pre_buffer); - zchan->pre_buffer_size = 0; - zap_mutex_unlock(zchan->pre_buffer_mutex); - } - break; - - /* FIXME: validate user gain values */ - case ZAP_COMMAND_SET_RX_GAIN: - { - zchan->rxgain = ZAP_COMMAND_OBJ_FLOAT; - reset_gain_table(zchan->rxgain_table, zchan->rxgain, zchan->native_codec); - if (zchan->rxgain == 0.0) { - zap_clear_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); - } else { - zap_set_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); - } - } - break; - case ZAP_COMMAND_GET_RX_GAIN: - { - ZAP_COMMAND_OBJ_FLOAT = zchan->rxgain; - } - break; - case ZAP_COMMAND_SET_TX_GAIN: - { - zchan->txgain = ZAP_COMMAND_OBJ_FLOAT; - reset_gain_table(zchan->txgain_table, zchan->txgain, zchan->native_codec); - if (zchan->txgain == 0.0) { - zap_clear_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); - } else { - zap_set_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); - } - } - break; - case ZAP_COMMAND_GET_TX_GAIN: - { - ZAP_COMMAND_OBJ_FLOAT = zchan->txgain; - } - break; - default: - break; - } - - if (!zchan->zio->command) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - zap_log(ZAP_LOG_ERROR, "no command function defined by the I/O openzap module!\n"); - GOTO_STATUS(done, ZAP_FAIL); - } - - status = zchan->zio->command(zchan, command, obj); - - if (status == ZAP_NOTIMPL) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "I/O command %d not implemented in backend", command); - zap_log(ZAP_LOG_ERROR, "I/O backend does not support command %d!\n", command); - } -done: - zap_mutex_unlock(zchan->mutex); - return status; - -} - -OZ_DECLARE(zap_status_t) zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to) -{ - assert(zchan != NULL); - assert(zchan->zio != NULL); - - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); - return ZAP_FAIL; - } - - if (!zchan->zio->wait) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - return ZAP_FAIL; - } - - return zchan->zio->wait(zchan, flags, to); - -} - -/*******************************/ -ZIO_CODEC_FUNCTION(zio_slin2ulaw) -{ - int16_t sln_buf[512] = {0}, *sln = sln_buf; - uint8_t *lp = data; - uint32_t i; - zap_size_t len = *datalen; - - if (max > len) { - max = len; - } - - memcpy(sln, data, max); - - for(i = 0; i < max; i++) { - *lp++ = linear_to_ulaw(*sln++); - } - - *datalen = max / 2; - - return ZAP_SUCCESS; - -} - - -ZIO_CODEC_FUNCTION(zio_ulaw2slin) -{ - int16_t *sln = data; - uint8_t law[1024] = {0}, *lp = law; - uint32_t i; - zap_size_t len = *datalen; - - if (max > len) { - max = len; - } - - memcpy(law, data, max); - - for(i = 0; i < max; i++) { - *sln++ = ulaw_to_linear(*lp++); - } - - *datalen = max * 2; - - return ZAP_SUCCESS; -} - -ZIO_CODEC_FUNCTION(zio_slin2alaw) -{ - int16_t sln_buf[512] = {0}, *sln = sln_buf; - uint8_t *lp = data; - uint32_t i; - zap_size_t len = *datalen; - - if (max > len) { - max = len; - } - - memcpy(sln, data, max); - - for(i = 0; i < max; i++) { - *lp++ = linear_to_alaw(*sln++); - } - - *datalen = max / 2; - - return ZAP_SUCCESS; - -} - - -ZIO_CODEC_FUNCTION(zio_alaw2slin) -{ - int16_t *sln = data; - uint8_t law[1024] = {0}, *lp = law; - uint32_t i; - zap_size_t len = *datalen; - - if (max > len) { - max = len; - } - - memcpy(law, data, max); - - for(i = 0; i < max; i++) { - *sln++ = alaw_to_linear(*lp++); - } - - *datalen = max * 2; - - return ZAP_SUCCESS; -} - -ZIO_CODEC_FUNCTION(zio_ulaw2alaw) -{ - zap_size_t len = *datalen; - uint32_t i; - uint8_t *lp = data; - - if (max > len) { - max = len; - } - - for(i = 0; i < max; i++) { - *lp = ulaw_to_alaw(*lp); - lp++; - } - - return ZAP_SUCCESS; -} - -ZIO_CODEC_FUNCTION(zio_alaw2ulaw) -{ - zap_size_t len = *datalen; - uint32_t i; - uint8_t *lp = data; - - if (max > len) { - max = len; - } - - for(i = 0; i < max; i++) { - *lp = alaw_to_ulaw(*lp); - lp++; - } - - return ZAP_SUCCESS; -} - -/******************************/ - -OZ_DECLARE(void) zap_channel_clear_detected_tones(zap_channel_t *zchan) -{ - uint32_t i; - - memset(zchan->detected_tones, 0, sizeof(zchan->detected_tones[0]) * ZAP_TONEMAP_INVALID); - - for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { - zchan->span->tone_finder[i].tone_count = 0; - } -} - -OZ_DECLARE(void) zap_channel_clear_needed_tones(zap_channel_t *zchan) -{ - memset(zchan->needed_tones, 0, sizeof(zchan->needed_tones[0]) * ZAP_TONEMAP_INVALID); -} - -OZ_DECLARE(zap_size_t) zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len) -{ - zap_size_t bytes = 0; - - assert(zchan != NULL); - - if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { - return ZAP_FAIL; - } - - if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { - zap_mutex_lock(zchan->mutex); - if ((bytes = zap_buffer_read(zchan->digit_buffer, dtmf, len)) > 0) { - *(dtmf + bytes) = '\0'; - } - zap_mutex_unlock(zchan->mutex); - } - - return bytes; -} - -OZ_DECLARE(void) zap_channel_flush_dtmf(zap_channel_t *zchan) -{ - if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) { - zap_mutex_lock(zchan->mutex); - zap_buffer_zero(zchan->digit_buffer); - zap_mutex_unlock(zchan->mutex); - } -} - -OZ_DECLARE(zap_status_t) zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf) -{ - zap_status_t status; - register zap_size_t len, inuse; - zap_size_t wr = 0; - const char *p; - - assert(zchan != NULL); - - if (zchan->pre_buffer) { - zap_buffer_zero(zchan->pre_buffer); - } - - zap_mutex_lock(zchan->mutex); - - inuse = zap_buffer_inuse(zchan->digit_buffer); - len = strlen(dtmf); - - if (len + inuse > zap_buffer_len(zchan->digit_buffer)) { - zap_buffer_toss(zchan->digit_buffer, strlen(dtmf)); - } - - if (zchan->span->dtmf_hangup_len) { - for (p = dtmf; zap_is_dtmf(*p); p++) { - memmove (zchan->dtmf_hangup_buf, zchan->dtmf_hangup_buf + 1, zchan->span->dtmf_hangup_len - 1); - zchan->dtmf_hangup_buf[zchan->span->dtmf_hangup_len - 1] = *p; - if (!strcmp(zchan->dtmf_hangup_buf, zchan->span->dtmf_hangup)) { - zap_log(ZAP_LOG_DEBUG, "DTMF hangup detected.\n"); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); - break; - } - } - } - - p = dtmf; - while (wr < len && p) { - if (zap_is_dtmf(*p)) { - wr++; - } else { - break; - } - p++; - } - - status = zap_buffer_write(zchan->digit_buffer, dtmf, wr) ? ZAP_SUCCESS : ZAP_FAIL; - zap_mutex_unlock(zchan->mutex); - - return status; -} - - -static zap_status_t handle_dtmf(zap_channel_t *zchan, zap_size_t datalen) -{ - zap_buffer_t *buffer = NULL; - zap_size_t dblen = 0; - int wrote = 0; - - if (zchan->gen_dtmf_buffer && (dblen = zap_buffer_inuse(zchan->gen_dtmf_buffer))) { - char digits[128] = ""; - char *cur; - int x = 0; - - if (dblen > sizeof(digits) - 1) { - dblen = sizeof(digits) - 1; - } - - if (zap_buffer_read(zchan->gen_dtmf_buffer, digits, dblen) && !zap_strlen_zero_buf(digits)) { - zap_log(ZAP_LOG_DEBUG, "%d:%d GENERATE DTMF [%s]\n", zchan->span_id, zchan->chan_id, digits); - - cur = digits; - - if (*cur == 'F') { - zap_channel_command(zchan, ZAP_COMMAND_FLASH, NULL); - cur++; - } - - for (; *cur; cur++) { - if ((wrote = teletone_mux_tones(&zchan->tone_session, &zchan->tone_session.TONES[(int)*cur]))) { - zap_buffer_write(zchan->dtmf_buffer, zchan->tone_session.buffer, wrote * 2); - x++; - } else { - zap_log(ZAP_LOG_ERROR, "%d:%d Problem Adding DTMF SEQ [%s]\n", zchan->span_id, zchan->chan_id, digits); - return ZAP_FAIL; - } - } - - if (x) { - zchan->skip_read_frames = (wrote / (zchan->effective_interval * 8)) + 4; - } - } - } - - - if (!zchan->buffer_delay || --zchan->buffer_delay == 0) { - if (zchan->dtmf_buffer && (dblen = zap_buffer_inuse(zchan->dtmf_buffer))) { - buffer = zchan->dtmf_buffer; - } else if (zchan->fsk_buffer && (dblen = zap_buffer_inuse(zchan->fsk_buffer))) { - buffer = zchan->fsk_buffer; - } - } - - if (buffer) { - zap_size_t dlen = datalen; - uint8_t auxbuf[1024]; - zap_size_t len, br, max = sizeof(auxbuf); - - if (zchan->native_codec != ZAP_CODEC_SLIN) { - dlen *= 2; - } - - len = dblen > dlen ? dlen : dblen; - - br = zap_buffer_read(buffer, auxbuf, len); - if (br < dlen) { - memset(auxbuf + br, 0, dlen - br); - } - - if (zchan->native_codec != ZAP_CODEC_SLIN) { - if (zchan->native_codec == ZAP_CODEC_ULAW) { - zio_slin2ulaw(auxbuf, max, &dlen); - } else if (zchan->native_codec == ZAP_CODEC_ALAW) { - zio_slin2alaw(auxbuf, max, &dlen); - } - } - - return zchan->zio->write(zchan, auxbuf, &dlen); - } - - return ZAP_SUCCESS; - -} - - -OZ_DECLARE(void) zap_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor) -{ - int16_t x; - uint32_t i; - int sum_rnd = 0; - int16_t rnd2 = (int16_t) zap_current_time_in_ms() * (int16_t) (intptr_t) data; - - assert(divisor); - - for (i = 0; i < samples; i++, sum_rnd = 0) { - for (x = 0; x < 6; x++) { - rnd2 = rnd2 * 31821U + 13849U; - sum_rnd += rnd2 ; - } - //switch_normalize_to_16bit(sum_rnd); - *data = (int16_t) ((int16_t) sum_rnd / (int) divisor); - - data++; - } -} - - - -OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen) -{ - zap_status_t status = ZAP_FAIL; - zio_codec_t codec_func = NULL; - zap_size_t max = *datalen; - unsigned i = 0; - - assert(zchan != NULL); - assert(zchan->zio != NULL); - - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); - return ZAP_FAIL; - } - - if (!zchan->zio->read) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - return ZAP_FAIL; - } - - status = zchan->zio->read(zchan, data, datalen); - if (zchan->fds[0] > -1) { - int dlen = (int) *datalen; - if (write(zchan->fds[0], data, dlen) != dlen) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "file write error!"); - return ZAP_FAIL; - } - } - - if (status == ZAP_SUCCESS) { - if (zap_test_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN) - && (zchan->native_codec == ZAP_CODEC_ALAW || zchan->native_codec == ZAP_CODEC_ULAW)) { - unsigned char *rdata = data; - for (i = 0; i < *datalen; i++) { - rdata[i] = zchan->rxgain_table[rdata[i]]; - } - } - handle_dtmf(zchan, *datalen); - } - - if (status == ZAP_SUCCESS && zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { - if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zio_ulaw2slin; - } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { - codec_func = zio_ulaw2alaw; - } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zio_alaw2slin; - } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { - codec_func = zio_alaw2ulaw; - } - - if (codec_func) { - status = codec_func(data, max, datalen); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); - status = ZAP_FAIL; - } - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) || zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) || - zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { - uint8_t sln_buf[1024] = {0}; - int16_t *sln; - zap_size_t slen = 0; - char digit_str[80] = ""; - - if (zchan->effective_codec == ZAP_CODEC_SLIN) { - sln = data; - slen = *datalen / 2; - } else { - zap_size_t len = *datalen; - uint32_t i; - uint8_t *lp = data; - - slen = sizeof(sln_buf) / 2; - if (len > slen) { - len = slen; - } - - sln = (int16_t *) sln_buf; - for(i = 0; i < len; i++) { - if (zchan->effective_codec == ZAP_CODEC_ULAW) { - *sln++ = ulaw_to_linear(*lp++); - } else if (zchan->effective_codec == ZAP_CODEC_ALAW) { - *sln++ = alaw_to_linear(*lp++); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); - return ZAP_FAIL; - } - } - sln = (int16_t *) sln_buf; - slen = len; - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) { - if (zap_fsk_demod_feed(&zchan->fsk, sln, slen) != ZAP_SUCCESS) { - zap_size_t type, mlen; - char str[128], *sp; - - while(zap_fsk_data_parse(&zchan->fsk, &type, &sp, &mlen) == ZAP_SUCCESS) { - *(str+mlen) = '\0'; - zap_copy_string(str, sp, ++mlen); - zap_clean_string(str); - zap_log(ZAP_LOG_DEBUG, "FSK: TYPE %s LEN %d VAL [%s]\n", zap_mdmf_type2str(type), mlen-1, str); - - switch(type) { - case MDMF_DDN: - case MDMF_PHONE_NUM: - { - if (mlen > sizeof(zchan->caller_data.ani)) { - mlen = sizeof(zchan->caller_data.ani); - } - zap_set_string(zchan->caller_data.ani.digits, str); - zap_set_string(zchan->caller_data.cid_num.digits, zchan->caller_data.ani.digits); - } - break; - case MDMF_NO_NUM: - { - zap_set_string(zchan->caller_data.ani.digits, *str == 'P' ? "private" : "unknown"); - zap_set_string(zchan->caller_data.cid_name, zchan->caller_data.ani.digits); - } - break; - case MDMF_PHONE_NAME: - { - if (mlen > sizeof(zchan->caller_data.cid_name)) { - mlen = sizeof(zchan->caller_data.cid_name); - } - zap_set_string(zchan->caller_data.cid_name, str); - } - break; - case MDMF_NO_NAME: - { - zap_set_string(zchan->caller_data.cid_name, *str == 'P' ? "private" : "unknown"); - } - case MDMF_DATETIME: - { - if (mlen > sizeof(zchan->caller_data.cid_date)) { - mlen = sizeof(zchan->caller_data.cid_date); - } - zap_set_string(zchan->caller_data.cid_date, str); - } - break; - } - } - zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL); - } - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_PROGRESS_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_PROGRESS)) { - uint32_t i; - - for (i = 1; i < ZAP_TONEMAP_INVALID; i++) { - if (zchan->span->tone_finder[i].tone_count) { - if (zchan->needed_tones[i] && teletone_multi_tone_detect(&zchan->span->tone_finder[i], sln, (int)slen)) { - if (++zchan->detected_tones[i]) { - zchan->needed_tones[i] = 0; - zchan->detected_tones[0]++; - } - } - } - } - } - - - if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT) && !zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { - teletone_dtmf_detect(&zchan->dtmf_detect, sln, (int)slen); - teletone_dtmf_get(&zchan->dtmf_detect, digit_str, sizeof(digit_str)); - - if(*digit_str) { - zio_event_cb_t event_callback = NULL; - - if (zchan->state == ZAP_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) { - zchan->detected_tones[ZAP_TONEMAP_CALLWAITING_ACK]++; - } else { - zap_channel_queue_dtmf(zchan, digit_str); - - if (zchan->span->event_callback) { - event_callback = zchan->span->event_callback; - } else if (zchan->event_callback) { - event_callback = zchan->event_callback; - } - - if (event_callback) { - zchan->event_header.channel = zchan; - zchan->event_header.e_type = ZAP_EVENT_DTMF; - zchan->event_header.data = digit_str; - event_callback(zchan, &zchan->event_header); - zchan->event_header.e_type = ZAP_EVENT_NONE; - zchan->event_header.data = NULL; - } - if (zap_test_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF)) { - zchan->skip_read_frames = 20; - } - } - } - } - } - - if (zchan->skip_read_frames > 0 || zap_test_flag(zchan, ZAP_CHANNEL_MUTE)) { - - zap_mutex_lock(zchan->pre_buffer_mutex); - if (zchan->pre_buffer && zap_buffer_inuse(zchan->pre_buffer)) { - zap_buffer_zero(zchan->pre_buffer); - } - zap_mutex_unlock(zchan->pre_buffer_mutex); - - - memset(data, 255, *datalen); - - if (zchan->skip_read_frames > 0) { - zchan->skip_read_frames--; - } - } else { - zap_mutex_lock(zchan->pre_buffer_mutex); - if (zchan->pre_buffer_size && zchan->pre_buffer) { - zap_buffer_write(zchan->pre_buffer, data, *datalen); - if (zap_buffer_inuse(zchan->pre_buffer) >= zchan->pre_buffer_size) { - zap_buffer_read(zchan->pre_buffer, data, *datalen); - } else { - memset(data, 255, *datalen); - } - } - zap_mutex_unlock(zchan->pre_buffer_mutex); - } - - - return status; -} - - -OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen) -{ - zap_status_t status = ZAP_FAIL; - zio_codec_t codec_func = NULL; - zap_size_t max = datasize; - unsigned int i = 0; - - assert(zchan != NULL); - assert(zchan->zio != NULL); - - if (!zchan->buffer_delay && - ((zchan->dtmf_buffer && zap_buffer_inuse(zchan->dtmf_buffer)) || - (zchan->fsk_buffer && zap_buffer_inuse(zchan->fsk_buffer)))) { - /* read size writing DTMF ATM */ - return ZAP_SUCCESS; - } - - - if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); - return ZAP_FAIL; - } - - if (!zchan->zio->write) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); - return ZAP_FAIL; - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_TRANSCODE) && zchan->effective_codec != zchan->native_codec) { - if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zio_slin2ulaw; - } else if (zchan->native_codec == ZAP_CODEC_ULAW && zchan->effective_codec == ZAP_CODEC_ALAW) { - codec_func = zio_alaw2ulaw; - } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_SLIN) { - codec_func = zio_slin2alaw; - } else if (zchan->native_codec == ZAP_CODEC_ALAW && zchan->effective_codec == ZAP_CODEC_ULAW) { - codec_func = zio_ulaw2alaw; - } - - if (codec_func) { - status = codec_func(data, max, datalen); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "codec error!"); - status = ZAP_FAIL; - } - } - - if (zchan->fds[1] > -1) { - int dlen = (int) *datalen; - if ((write(zchan->fds[1], data, dlen)) != dlen) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "file write error!"); - return ZAP_FAIL; - } - } - - if (zap_test_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN) - && (zchan->native_codec == ZAP_CODEC_ALAW || zchan->native_codec == ZAP_CODEC_ULAW)) { - unsigned char *wdata = data; - for (i = 0; i < *datalen; i++) { - wdata[i] = zchan->txgain_table[wdata[i]]; - } - } - status = zchan->zio->write(zchan, data, datalen); - - return status; -} - -OZ_DECLARE(zap_status_t) zap_channel_clear_vars(zap_channel_t *zchan) -{ - if(zchan->variable_hash) { - hashtable_destroy(zchan->variable_hash); - } - zchan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - - if(!zchan->variable_hash) - return ZAP_FAIL; - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) -{ - char *t_name = 0, *t_val = 0; - - if(!zchan->variable_hash || !var_name || !value) - { - return ZAP_FAIL; - } - - t_name = zap_strdup(var_name); - t_val = zap_strdup(value); - - if(hashtable_insert(zchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) { - return ZAP_SUCCESS; - } - return ZAP_FAIL; -} - -OZ_DECLARE(const char *) zap_channel_get_var(zap_channel_t *zchan, const char *var_name) -{ - if(!zchan->variable_hash || !var_name) - { - return NULL; - } - return (const char *) hashtable_search(zchan->variable_hash, (void *)var_name); -} - -static struct { - zap_io_interface_t *pika_interface; -} interfaces; - - -OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd) -{ - zap_io_interface_t *zio = NULL; - char *dup = NULL, *p; - char *rval = NULL; - - if (type && !cmd) { - dup = zap_strdup(type); - if ((p = strchr(dup, ' '))) { - *p++ = '\0'; - cmd = p; - } - - type = dup; - } - - zap_mutex_lock(globals.mutex); - if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { - zap_load_module_assume(type); - if ((zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { - zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); - } - } - zap_mutex_unlock(globals.mutex); - - if (zio && zio->api) { - zap_stream_handle_t stream = { 0 }; - zap_status_t status; - ZAP_STANDARD_STREAM(stream); - status = zio->api(&stream, cmd); - - if (status != ZAP_SUCCESS) { - zap_safe_free(stream.data); - } else { - rval = (char *) stream.data; - } - } - - zap_safe_free(dup); - - return rval; -} - - -static zap_status_t load_config(void) -{ - char cfg_name[] = "openzap.conf"; - zap_config_t cfg; - char *var, *val; - int catno = -1; - zap_span_t *span = NULL; - unsigned configured = 0, d = 0; - char name[80] = ""; - char number[25] = ""; - char group_name[80] = "default"; - zap_io_interface_t *zio = NULL; - zap_analog_start_type_t tmp; - zap_size_t len = 0; - - if (!zap_config_open_file(&cfg, cfg_name)) { - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - if (*cfg.category == '#') { - if (cfg.catno != catno) { - zap_log(ZAP_LOG_DEBUG, "Skipping %s\n", cfg.category); - catno = cfg.catno; - } - } else if (!strncasecmp(cfg.category, "span", 4)) { - if (cfg.catno != catno) { - char *type = cfg.category + 4; - char *name; - - if (*type == ' ') { - type++; - } - - zap_log(ZAP_LOG_DEBUG, "found config for span\n"); - catno = cfg.catno; - - if (zap_strlen_zero(type)) { - zap_log(ZAP_LOG_CRIT, "failure creating span, no type specified.\n"); - span = NULL; - continue; - } - - if ((name = strchr(type, ' '))) { - *name++ = '\0'; - } - - zap_mutex_lock(globals.mutex); - if (!(zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { - zap_load_module_assume(type); - if ((zio = (zap_io_interface_t *) hashtable_search(globals.interface_hash, type))) { - zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); - } - } - zap_mutex_unlock(globals.mutex); - - if (!zio) { - zap_log(ZAP_LOG_CRIT, "failure creating span, no such type '%s'\n", type); - span = NULL; - continue; - } - - if (!zio->configure_span) { - zap_log(ZAP_LOG_CRIT, "failure creating span, no configure_span method for '%s'\n", type); - span = NULL; - continue; - } - - if (zap_span_create(zio, &span, name) == ZAP_SUCCESS) { - span->type = zap_strdup(type); - d = 0; - - zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type); - - } else { - zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); - span = NULL; - continue; - } - } - - if (!span) { - continue; - } - - zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val); - - if (!strcasecmp(var, "trunk_type")) { - span->trunk_type = zap_str2zap_trunk_type(val); - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s'\n", zap_trunk_type2str(span->trunk_type)); - } else if (!strcasecmp(var, "name")) { - if (!strcasecmp(val, "undef")) { - *name = '\0'; - } else { - zap_copy_string(name, val, sizeof(name)); - } - } else if (!strcasecmp(var, "number")) { - if (!strcasecmp(val, "undef")) { - *number = '\0'; - } else { - zap_copy_string(number, val, sizeof(number)); - } - } else if (!strcasecmp(var, "analog-start-type")) { - if (span->trunk_type == ZAP_TRUNK_FXS || span->trunk_type == ZAP_TRUNK_FXO || span->trunk_type == ZAP_TRUNK_EM) { - if ((tmp = zap_str2zap_analog_start_type(val)) != ZAP_ANALOG_START_NA) { - span->start_type = tmp; - zap_log(ZAP_LOG_DEBUG, "changing start type to '%s'\n", zap_analog_start_type2str(span->start_type)); - } - } else { - zap_log(ZAP_LOG_ERROR, "This option is only valid on analog trunks!\n"); - } - } else if (!strcasecmp(var, "fxo-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXO; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(span->start_type)); - } - if (span->trunk_type == ZAP_TRUNK_FXO) { - configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); - } - } else if (!strcasecmp(var, "fxs-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_FXS; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(span->start_type)); - } - if (span->trunk_type == ZAP_TRUNK_FXS) { - configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); - } - } else if (!strcasecmp(var, "em-channel")) { - if (span->trunk_type == ZAP_TRUNK_NONE) { - span->trunk_type = ZAP_TRUNK_EM; - zap_log(ZAP_LOG_DEBUG, "setting trunk type to '%s' start(%s)\n", zap_trunk_type2str(span->trunk_type), - zap_analog_start_type2str(span->start_type)); - } - if (span->trunk_type == ZAP_TRUNK_EM) { - configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_EM, name, number); - } else { - zap_log(ZAP_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); - } - } else if (!strcasecmp(var, "b-channel")) { - configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); - zap_group_add_channels(group_name, span, val); - } else if (!strcasecmp(var, "d-channel")) { - if (d) { - zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); - } else { - zap_chan_type_t qtype; - if (!strncasecmp(val, "lapd:", 5)) { - qtype = ZAP_CHAN_TYPE_DQ931; - val += 5; - } else { - qtype = ZAP_CHAN_TYPE_DQ921; - } - configured += zio->configure_span(span, val, qtype, name, number); - d++; - } - } else if (!strcasecmp(var, "cas-channel")) { - configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_CAS, name, number); - } else if (!strcasecmp(var, "dtmf_hangup")) { - span->dtmf_hangup = zap_strdup(val); - span->dtmf_hangup_len = strlen(val); - } else if (!strcasecmp(var, "group")) { - len = strlen(val); - if (len >= sizeof(group_name)) { - len = sizeof(group_name) - 1; - zap_log(ZAP_LOG_WARNING, "Truncating group name %s to %zd length\n", val, len); - } - memcpy(group_name, val, len); - group_name[len] = '\0'; - } else { - zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); - } - } else { - zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); - } - } - zap_config_close_file(&cfg); - - zap_log(ZAP_LOG_INFO, "Configured %u channel(s)\n", configured); - - return configured ? ZAP_SUCCESS : ZAP_FAIL; -} - -static zap_status_t process_module_config(zap_io_interface_t *zio) -{ - zap_config_t cfg; - char *var, *val; - char filename[256] = ""; - - zap_assert_return(zio != NULL, ZAP_FAIL, "zio argument is null\n"); - - snprintf(filename, sizeof(filename), "%s.conf", zio->name); - - if (!zio->configure) { - zap_log(ZAP_LOG_DEBUG, "Module %s does not support configuration.\n", zio->name); - return ZAP_FAIL; - } - - if (!zap_config_open_file(&cfg, filename)) { - zap_log(ZAP_LOG_ERROR, "Cannot open %s\n", filename); - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - zio->configure(cfg.category, var, val, cfg.lineno); - } - - zap_config_close_file(&cfg); - - return ZAP_SUCCESS; -} - -OZ_DECLARE(char *) zap_build_dso_path(const char *name, char *path, zap_size_t len) -{ -#ifdef WIN32 - const char *ext = ".dll"; - //const char *EXT = ".DLL"; -#define ZAP_MOD_DIR "." //todo -#elif defined (MACOSX) || defined (DARWIN) - const char *ext = ".dylib"; - //const char *EXT = ".DYLIB"; -#else - const char *ext = ".so"; - //const char *EXT = ".SO"; -#endif - if (*name == *ZAP_PATH_SEPARATOR) { - snprintf(path, len, "%s%s", name, ext); - } else { - snprintf(path, len, "%s%s%s%s", ZAP_MOD_DIR, ZAP_PATH_SEPARATOR, name, ext); - } - return path; -} - -OZ_DECLARE(zap_status_t) zap_global_add_io_interface(zap_io_interface_t *interface1) -{ - zap_status_t ret = ZAP_SUCCESS; - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.interface_hash, (void *)interface1->name)) { - zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface1->name); - } else { - hashtable_insert(globals.interface_hash, (void *)interface1->name, interface1, HASHTABLE_FLAG_NONE); - } - zap_mutex_unlock(globals.mutex); - return ret; -} - -OZ_DECLARE(int) zap_load_module(const char *name) -{ - zap_dso_lib_t lib; - int count = 0, x = 0; - char path[128] = ""; - char *err; - zap_module_t *mod; - - zap_build_dso_path(name, path, sizeof(path)); - - if (!(lib = zap_dso_open(path, &err))) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - zap_safe_free(err); - return 0; - } - - if (!(mod = (zap_module_t *) zap_dso_func_sym(lib, "zap_module", &err))) { - zap_log(ZAP_LOG_ERROR, "Error loading %s [%s]\n", path, err); - zap_safe_free(err); - return 0; - } - - if (mod->io_load) { - zap_io_interface_t *interface1 = NULL; /* name conflict w/windows here */ - - if (mod->io_load(&interface1) != ZAP_SUCCESS || !interface1 || !interface1->name) { - zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); - } else { - zap_log(ZAP_LOG_INFO, "Loading IO from %s [%s]\n", path, interface1->name); - if (zap_global_add_io_interface(interface1) == ZAP_SUCCESS) { - process_module_config(interface1); - x++; - } - } - } - - if (mod->sig_load) { - if (mod->sig_load() != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "Error loading %s\n", path); - } else { - zap_log(ZAP_LOG_INFO, "Loading SIG from %s\n", path); - x++; - } - } - - if (x) { - char *p; - mod->lib = lib; - zap_set_string(mod->path, path); - if (mod->name[0] == '\0') { - if (!(p = strrchr(path, *ZAP_PATH_SEPARATOR))) { - p = path; - } - zap_set_string(mod->name, p); - } - - zap_mutex_lock(globals.mutex); - if (hashtable_search(globals.module_hash, (void *)mod->name)) { - zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name); - zap_dso_destroy(&lib); - } else { - hashtable_insert(globals.module_hash, (void *)mod->name, mod, HASHTABLE_FLAG_NONE); - count++; - } - zap_mutex_unlock(globals.mutex); - } else { - zap_log(ZAP_LOG_ERROR, "Unloading %s\n", path); - zap_dso_destroy(&lib); - } - - return count; -} - -OZ_DECLARE(int) zap_load_module_assume(const char *name) -{ - char buf[256] = ""; - - snprintf(buf, sizeof(buf), "ozmod_%s", name); - return zap_load_module(buf); -} - -OZ_DECLARE(int) zap_load_modules(void) -{ - char cfg_name[] = "modules.conf"; - zap_config_t cfg; - char *var, *val; - int count = 0; - - if (!zap_config_open_file(&cfg, cfg_name)) { - return ZAP_FAIL; - } - - while (zap_config_next_pair(&cfg, &var, &val)) { - if (!strcasecmp(cfg.category, "modules")) { - if (!strcasecmp(var, "load")) { - count += zap_load_module(val); - } - } - } - - return count; -} - -OZ_DECLARE(zap_status_t) zap_unload_modules(void) -{ - zap_hash_iterator_t *i; - zap_dso_lib_t lib; - - for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { - const void *key; - void *val; - - hashtable_this(i, &key, NULL, &val); - - if (key && val) { - zap_module_t *mod = (zap_module_t *) val; - - if (!mod) { - continue; - } - - if (mod->io_unload) { - if (mod->io_unload() == ZAP_SUCCESS) { - zap_log(ZAP_LOG_INFO, "Unloading IO %s\n", mod->name); - } else { - zap_log(ZAP_LOG_ERROR, "Error unloading IO %s\n", mod->name); - } - } - - if (mod->sig_unload) { - if (mod->sig_unload() == ZAP_SUCCESS) { - zap_log(ZAP_LOG_INFO, "Unloading SIG %s\n", mod->name); - } else { - zap_log(ZAP_LOG_ERROR, "Error unloading SIG %s\n", mod->name); - } - } - - - zap_log(ZAP_LOG_INFO, "Unloading %s\n", mod->path); - lib = mod->lib; - zap_dso_destroy(&lib); - - } - } - - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...) -{ - zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); - zap_status_t status = ZAP_FAIL; - - if (!mod) { - zap_load_module_assume(type); - if ((mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type))) { - zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); - } - } - - if (mod && mod->sig_configure) { - va_list ap; - va_start(ap, sig_cb); - status = mod->sig_configure(span, sig_cb, ap); - va_end(ap); - } else { - zap_log(ZAP_LOG_ERROR, "can't find '%s'\n", type); - status = ZAP_FAIL; - } - - return status; -} - -OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, zap_conf_parameter_t *parameters) -{ - zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); - zap_status_t status = ZAP_FAIL; - - zap_assert_return(type != NULL, ZAP_FAIL, "No signaling type"); - zap_assert_return(span != NULL, ZAP_FAIL, "No span"); - zap_assert_return(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); - zap_assert_return(parameters != NULL, ZAP_FAIL, "No parameters"); - - if (!mod) { - zap_load_module_assume(type); - if ((mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type))) { - zap_log(ZAP_LOG_INFO, "auto-loaded '%s'\n", type); - } - } - - if (!mod) { - zap_log(ZAP_LOG_ERROR, "Failed to load module type: %s\n", type); - return ZAP_FAIL; - } - - if (mod->configure_span_signaling) { - status = mod->configure_span_signaling(span, sig_cb, parameters); - } else { - zap_log(ZAP_LOG_ERROR, "Module %s did not implement the signaling configuration method\n", type); - } - - return status; -} - -OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) -{ - if (span->start) { - return span->start(span); - } - - return ZAP_FAIL; -} - -OZ_DECLARE(zap_status_t) zap_channel_add_to_group(const char* name, zap_channel_t* zchan) -{ - int i; - zap_group_t* group = NULL; - - zap_mutex_lock(globals.group_mutex); - - if (zap_group_find_by_name(name, &group) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_DEBUG, "Creating new group:%s\n", name); - zap_group_create(&group, name); - } - - /*verify that group does not already include this channel first */ - for(i=0; i < group->chan_count; i++) { - if (group->channels[i]->physical_span_id == zchan->physical_span_id && - group->channels[i]->physical_chan_id == zchan->physical_chan_id) { - - zap_mutex_unlock(globals.group_mutex); - return ZAP_SUCCESS; - } - } - - if (group->chan_count >= ZAP_MAX_CHANNELS_GROUP) { - zap_log(ZAP_LOG_CRIT, "Max number of channels exceeded (max:%d)\n", ZAP_MAX_CHANNELS_GROUP); - zap_mutex_unlock(globals.group_mutex); - return ZAP_FAIL; - } - - group->channels[group->chan_count++] = zchan; - zap_mutex_unlock(globals.group_mutex); - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_channel_remove_from_group(zap_group_t* group, zap_channel_t* zchan) -{ - //Need to test this function - zap_mutex_lock(globals.group_mutex); - int i, j; - - for (i=0; i < group->chan_count; i++) { - if (group->channels[i]->physical_span_id == zchan->physical_span_id && - group->channels[i]->physical_chan_id == zchan->physical_chan_id) { - - j=i; - while(j < group->chan_count-1) { - group->channels[j] = group->channels[j+1]; - j++; - } - group->channels[group->chan_count--] = NULL; - if (group->chan_count <=0) { - /* Delete group if it is empty */ - hashtable_remove(globals.group_hash, (void *)group->name); - } - zap_mutex_unlock(globals.group_mutex); - return ZAP_SUCCESS; - } - } - - zap_mutex_unlock(globals.group_mutex); - //Group does not contain this channel - return ZAP_FAIL; -} - -OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* span, const char* val) -{ - char *p, *mydata, *item_list[10]; - int items, i; - - assert(strlen(name) > 0); - - p = strchr(val, ':'); - mydata = zap_strdup(++p); - - zap_assert_return(mydata != NULL, ZAP_FAIL, "zap_strdup failed when adding channels\n"); - - items = zap_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); - - for(i=0; i < items; i++) { - if (!strchr(item_list[i], '-')) { - int chan_no; - - chan_no = atoi (item_list[i]); - zap_assert(chan_no > 0, "Channel number is not bigger than zero, expect a nasty failure!\n"); - - if (zap_channel_add_to_group(name, span->channels[chan_no]) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no, name); - } - } else { - int chan_no_start, chan_no_end; - if (sscanf(item_list[i], "%d-%d", &chan_no_start, &chan_no_end) == 2) { - while (chan_no_start <= chan_no_end) { - if (zap_channel_add_to_group(name, span->channels[chan_no_start++])) { - zap_log(ZAP_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no_start-1, name); - } - } - } - } - } - zap_safe_free(mydata); - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group) -{ - zap_group_t *fgroup = NULL, *grp; - - if (id > ZAP_MAX_GROUPS_INTERFACE) { - return ZAP_FAIL; - } - - - zap_mutex_lock(globals.group_mutex); - for (grp = globals.groups; grp; grp = grp->next) { - if (grp->group_id == id) { - fgroup = grp; - break; - } - } - zap_mutex_unlock(globals.group_mutex); - - if (!fgroup) { - return ZAP_FAIL; - } - - *group = fgroup; - - return ZAP_SUCCESS; - -} - -OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group) -{ - zap_status_t status = ZAP_FAIL; - *group = NULL; - zap_mutex_lock(globals.group_mutex); - if (!zap_strlen_zero(name)) { - if ((*group = hashtable_search(globals.group_hash, (void *) name))) { - status = ZAP_SUCCESS; - } - } - zap_mutex_unlock(globals.group_mutex); - return status; -} - -static void zap_group_add(zap_group_t *group) -{ - zap_group_t *grp; - zap_mutex_lock(globals.group_mutex); - - for (grp = globals.groups; grp && grp->next; grp = grp->next); - - if (grp) { - grp->next = group; - } else { - globals.groups = group; - } - hashtable_insert(globals.group_hash, (void *)group->name, group, HASHTABLE_FLAG_NONE); - - zap_mutex_unlock(globals.group_mutex); -} - - -OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name) -{ - zap_group_t *new_group = NULL; - zap_status_t status = ZAP_FAIL; - - zap_mutex_lock(globals.mutex); - if (globals.group_index < ZAP_MAX_GROUPS_INTERFACE) { - new_group = zap_calloc(1, sizeof(*new_group)); - - zap_assert(new_group != NULL, "Failed to create new zap group, expect a crash\n"); - - status = zap_mutex_create(&new_group->mutex); - - zap_assert(status == ZAP_SUCCESS, "Failed to create group mutex, expect a crash\n"); - - new_group->group_id = ++globals.group_index; - new_group->name = zap_strdup(name); - zap_group_add(new_group); - *group = new_group; - status = ZAP_SUCCESS; - } else { - zap_log(ZAP_LOG_CRIT, "Group %s was not added, we exceeded the max number of groups\n", name); - } - zap_mutex_unlock(globals.mutex); - return status; -} - -OZ_DECLARE(zap_status_t) zap_global_init(void) -{ - memset(&globals, 0, sizeof(globals)); - - time_init(); - - zap_thread_override_default_stacksize(ZAP_THREAD_STACKSIZE); - - memset(&interfaces, 0, sizeof(interfaces)); - globals.interface_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - globals.module_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - globals.span_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - globals.group_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); - zap_mutex_create(&globals.mutex); - zap_mutex_create(&globals.span_mutex); - zap_mutex_create(&globals.group_mutex); - globals.running = 1; - return ZAP_SUCCESS; -} - -OZ_DECLARE(zap_status_t) zap_global_configuration(void) -{ - int modcount = zap_load_modules(); - zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); - - if (load_config() != ZAP_SUCCESS) { - globals.running = 0; - zap_log(ZAP_LOG_ERROR, "OpenZap global configuration failed!\n"); - return ZAP_FAIL; - } - return ZAP_SUCCESS; -} - -OZ_DECLARE(uint32_t) zap_running(void) -{ - return globals.running; -} - - -OZ_DECLARE(zap_status_t) zap_global_destroy(void) -{ - zap_span_t *sp; - - time_end(); - - globals.running = 0; - zap_span_close_all(); - zap_sleep(1000); - - zap_mutex_lock(globals.span_mutex); - for (sp = globals.spans; sp;) { - zap_span_t *cur_span = sp; - sp = sp->next; - - if (cur_span) { - if (zap_test_flag(cur_span, ZAP_SPAN_CONFIGURED)) { - zap_span_destroy(cur_span); - } - - hashtable_remove(globals.span_hash, (void *)cur_span->name); - zap_safe_free(cur_span->type); - zap_safe_free(cur_span->name); - zap_safe_free(cur_span); - cur_span = NULL; - } - } - globals.spans = NULL; - zap_mutex_unlock(globals.span_mutex); - - globals.span_index = 0; - - zap_unload_modules(); - - zap_mutex_lock(globals.mutex); - hashtable_destroy(globals.interface_hash); - hashtable_destroy(globals.module_hash); - hashtable_destroy(globals.span_hash); - zap_mutex_unlock(globals.mutex); - zap_mutex_destroy(&globals.mutex); - zap_mutex_destroy(&globals.span_mutex); - - memset(&globals, 0, sizeof(globals)); - return ZAP_SUCCESS; -} - - -OZ_DECLARE(uint32_t) zap_separate_string(char *buf, char delim, char **array, int arraylen) -{ - int argc; - char *ptr; - int quot = 0; - char qc = '\''; - int x; - - if (!buf || !array || !arraylen) { - return 0; - } - - memset(array, 0, arraylen * sizeof(*array)); - - ptr = buf; - - for (argc = 0; *ptr && (argc < arraylen - 1); argc++) { - array[argc] = ptr; - for (; *ptr; ptr++) { - if (*ptr == qc) { - if (quot) { - quot--; - } else { - quot++; - } - } else if ((*ptr == delim) && !quot) { - *ptr++ = '\0'; - break; - } - } - } - - if (*ptr) { - array[argc++] = ptr; - } - - /* strip quotes and leading / trailing spaces */ - for (x = 0; x < argc; x++) { - char *p; - - while(*(array[x]) == ' ') { - (array[x])++; - } - p = array[x]; - while((p = strchr(array[x], qc))) { - memmove(p, p+1, strlen(p)); - p++; - } - p = array[x] + (strlen(array[x]) - 1); - while(*p == ' ') { - *p-- = '\0'; - } - } - - return argc; -} - -OZ_DECLARE(void) zap_bitstream_init(zap_bitstream_t *bsp, uint8_t *data, uint32_t datalen, zap_endian_t endian, uint8_t ss) -{ - memset(bsp, 0, sizeof(*bsp)); - bsp->data = data; - bsp->datalen = datalen; - bsp->endian = endian; - bsp->ss = ss; - - if (endian < 0) { - bsp->top = bsp->bit_index = 7; - bsp->bot = 0; - } else { - bsp->top = bsp->bit_index = 0; - bsp->bot = 7; - } - -} - -OZ_DECLARE(int8_t) zap_bitstream_get_bit(zap_bitstream_t *bsp) -{ - int8_t bit = -1; - - - if (bsp->byte_index >= bsp->datalen) { - goto done; - } - - if (bsp->ss) { - if (!bsp->ssv) { - bsp->ssv = 1; - return 0; - } else if (bsp->ssv == 2) { - bsp->byte_index++; - bsp->ssv = 0; - return 1; - } - } - - - - - bit = (bsp->data[bsp->byte_index] >> (bsp->bit_index)) & 1; - - if (bsp->bit_index == bsp->bot) { - bsp->bit_index = bsp->top; - if (bsp->ss) { - bsp->ssv = 2; - goto done; - } - - if (++bsp->byte_index > bsp->datalen) { - bit = -1; - goto done; - } - - } else { - bsp->bit_index = bsp->bit_index + bsp->endian; - } - - - done: - return bit; -} - -OZ_DECLARE(void) print_hex_bytes(uint8_t *data, zap_size_t dlen, char *buf, zap_size_t blen) -{ - char *bp = buf; - uint8_t *byte = data; - uint32_t i, j = 0; - - if (blen < (dlen * 3) + 2) { - return; - } - - *bp++ = '['; - j++; - - for(i = 0; i < dlen; i++) { - snprintf(bp, blen-j, "%02x ", *byte++); - bp += 3; - j += 3; - } - - *--bp = ']'; - -} - -OZ_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, zap_endian_t e, uint8_t ss) -{ - zap_bitstream_t bs; - int j = 0, c = 0; - int8_t bit; - uint32_t last; - - if (blen < (bl * 10) + 2) { - return; - } - - zap_bitstream_init(&bs, b, bl, e, ss); - last = bs.byte_index; - while((bit = zap_bitstream_get_bit(&bs)) > -1) { - buf[j++] = bit ? '1' : '0'; - if (bs.byte_index != last) { - buf[j++] = ' '; - last = bs.byte_index; - if (++c == 8) { - buf[j++] = '\n'; - c = 0; - } - } - } - -} - - - -OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_raw_write(zap_stream_handle_t *handle, uint8_t *data, zap_size_t datalen) -{ - zap_size_t need = handle->data_len + datalen; - - if (need >= handle->data_size) { - void *new_data; - need += handle->alloc_chunk; - - if (!(new_data = realloc(handle->data, need))) { - return ZAP_MEMERR; - } - - handle->data = new_data; - handle->data_size = need; - } - - memcpy((uint8_t *) (handle->data) + handle->data_len, data, datalen); - handle->data_len += datalen; - handle->end = (uint8_t *) (handle->data) + handle->data_len; - *(uint8_t *)handle->end = '\0'; - - return ZAP_SUCCESS; -} - -OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code from switch_apr.c */ -{ -#ifdef HAVE_VASPRINTF - return vasprintf(ret, fmt, ap); -#else - char *buf; - int len; - size_t buflen; - va_list ap2; - char *tmp = NULL; - -#ifdef _MSC_VER -#if _MSC_VER >= 1500 - /* hack for incorrect assumption in msvc header files for code analysis */ - __analysis_assume(tmp); -#endif - ap2 = ap; -#else - va_copy(ap2, ap); -#endif - - len = vsnprintf(tmp, 0, fmt, ap2); - - if (len > 0 && (buf = zap_malloc((buflen = (size_t) (len + 1)))) != NULL) { - len = vsnprintf(buf, buflen, fmt, ap); - *ret = buf; - } else { - *ret = NULL; - len = -1; - } - - va_end(ap2); - return len; -#endif -} - -OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *handle, const char *fmt, ...) -{ - va_list ap; - char *buf = handle->data; - char *end = handle->end; - int ret = 0; - char *data = NULL; - - if (handle->data_len >= handle->data_size) { - return ZAP_FAIL; - } - - va_start(ap, fmt); - ret = zap_vasprintf(&data, fmt, ap); - va_end(ap); - - if (data) { - zap_size_t remaining = handle->data_size - handle->data_len; - zap_size_t need = strlen(data) + 1; - - if ((remaining < need) && handle->alloc_len) { - zap_size_t new_len; - void *new_data; - - new_len = handle->data_size + need + handle->alloc_chunk; - if ((new_data = realloc(handle->data, new_len))) { - handle->data_size = handle->alloc_len = new_len; - handle->data = new_data; - buf = handle->data; - remaining = handle->data_size - handle->data_len; - handle->end = (uint8_t *) (handle->data) + handle->data_len; - end = handle->end; - } else { - zap_log(ZAP_LOG_CRIT, "Memory Error!\n"); - zap_safe_free(data); - return ZAP_FAIL; - } - } - - if (remaining < need) { - ret = -1; - } else { - ret = 0; - snprintf(end, remaining, "%s", data); - handle->data_len = strlen(buf); - handle->end = (uint8_t *) (handle->data) + handle->data_len; - } - zap_safe_free(data); - } - - return ret ? ZAP_FAIL : ZAP_SUCCESS; -} - -OZ_DECLARE(char *) zap_strdup(const char *str) -{ - zap_size_t len = strlen(str) + 1; - void *new = zap_malloc(len); - - if (!new) { - return NULL; - } - - return (char *)memcpy(new, str, len); -} - -OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen) -{ - char *new = NULL; - zap_size_t len = strlen(str) + 1; - if (len > (inlen+1)) { - len = inlen+1; - } - new = (char *)zap_malloc(len); - - if (!new) { - return NULL; - } - - memcpy(new, str, len-1); - new[len-1] = 0; - return new; -} - - -/* 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: - */ From e512bb8eb344e33319b186e222f83f1a205860fc Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 19:34:49 +0000 Subject: [PATCH 1680/1766] change configuration file names for freetdm renaming git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@968 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/conf/{openzap.conf => freetdm.conf} | 6 +++--- libs/freetdm/conf/{openzap.conf.xml => freetdm.conf.xml} | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename libs/freetdm/conf/{openzap.conf => freetdm.conf} (77%) rename libs/freetdm/conf/{openzap.conf.xml => freetdm.conf.xml} (96%) diff --git a/libs/freetdm/conf/openzap.conf b/libs/freetdm/conf/freetdm.conf similarity index 77% rename from libs/freetdm/conf/openzap.conf rename to libs/freetdm/conf/freetdm.conf index d8a2f4b792..1ea1a9f62a 100644 --- a/libs/freetdm/conf/openzap.conf +++ b/libs/freetdm/conf/freetdm.conf @@ -1,5 +1,5 @@ [span wanpipe] -name => OpenZAP +name => FreeTDM number => 1 fxs-channel => 1:3-4 @@ -7,12 +7,12 @@ fxs-channel => 1:3-4 fxo-channel => 1:1-2 [span zt] -name => OpenZAP +name => FreeTDM number => 2 fxs-channel => 1 [span zt] -name => OpenZAP +name => FreeTDM number => 2 fxo-channel => 3 diff --git a/libs/freetdm/conf/openzap.conf.xml b/libs/freetdm/conf/freetdm.conf.xml similarity index 96% rename from libs/freetdm/conf/openzap.conf.xml rename to libs/freetdm/conf/freetdm.conf.xml index bfa2bc0391..69bf99a0a0 100644 --- a/libs/freetdm/conf/openzap.conf.xml +++ b/libs/freetdm/conf/freetdm.conf.xml @@ -1,4 +1,4 @@ - + From 62a406b2a2076cb2ccea2326d68c6cc4371bd5f6 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 19:38:33 +0000 Subject: [PATCH 1681/1766] oops, missing freetdm.h git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@969 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/freetdm.h | 932 +++++++++++++++++++++++++++++ 1 file changed, 932 insertions(+) create mode 100644 libs/freetdm/src/include/freetdm.h diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h new file mode 100644 index 0000000000..95b15d358c --- /dev/null +++ b/libs/freetdm/src/include/freetdm.h @@ -0,0 +1,932 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * + */ + +#ifndef OPENFTDM_H +#define OPENFTDM_H + + +#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) +#define _XOPEN_SOURCE 600 +#endif + +#ifndef HAVE_STRINGS_H +#define HAVE_STRINGS_H 1 +#endif +#ifndef HAVE_SYS_SOCKET_H +#define HAVE_SYS_SOCKET_H 1 +#endif + +#ifndef __WINDOWS__ +#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) +#define __WINDOWS__ +#endif +#endif + +#ifdef _MSC_VER +#if defined(FT_DECLARE_STATIC) +#define FT_DECLARE(type) type __stdcall +#define FT_DECLARE_NONSTD(type) type __cdecl +#define FT_DECLARE_DATA +#elif defined(OPENFTDM_EXPORTS) +#define FT_DECLARE(type) __declspec(dllexport) type __stdcall +#define FT_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl +#define FT_DECLARE_DATA __declspec(dllexport) +#else +#define FT_DECLARE(type) __declspec(dllimport) type __stdcall +#define FT_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl +#define FT_DECLARE_DATA __declspec(dllimport) +#endif +#define EX_DECLARE_DATA __declspec(dllexport) +#else +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) +#define FT_DECLARE(type) __attribute__((visibility("default"))) type +#define FT_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type +#define FT_DECLARE_DATA __attribute__((visibility("default"))) +#else +#define FT_DECLARE(type) type +#define FT_DECLARE_NONSTD(type) type +#define FT_DECLARE_DATA +#endif +#define EX_DECLARE_DATA +#endif + +#ifdef _MSC_VER +#ifndef __inline__ +#define __inline__ __inline +#endif +#if (_MSC_VER >= 1400) /* VC8+ */ +#ifndef _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE +#endif +#ifndef _CRT_NONSTDC_NO_DEPRECATE +#define _CRT_NONSTDC_NO_DEPRECATE +#endif +#endif +#ifndef strcasecmp +#define strcasecmp(s1, s2) _stricmp(s1, s2) +#endif +#ifndef strncasecmp +#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n) +#endif +#ifndef snprintf +#define snprintf _snprintf +#endif +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif +#undef HAVE_STRINGS_H +#undef HAVE_SYS_SOCKET_H +/* disable warning for zero length array in a struct */ +/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ +#pragma warning(disable:4706) +#pragma comment(lib, "Winmm") +#endif + +#define FTDM_THREAD_STACKSIZE 240 * 1024 +#define FTDM_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; +#define FTDM_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) FT_DECLARE(_TYPE) _FUNC1 (const char *name); FT_DECLARE(const char *) _FUNC2 (_TYPE type); +#define FTDM_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ + FT_DECLARE(_TYPE) _FUNC1 (const char *name) \ + { \ + int i; \ + _TYPE t = _MAX ; \ + \ + for (i = 0; i < _MAX ; i++) { \ + if (!strcasecmp(name, _STRINGS[i])) { \ + t = (_TYPE) i; \ + break; \ + } \ + } \ + \ + return t; \ + } \ + FT_DECLARE(const char *) _FUNC2 (_TYPE type) \ + { \ + if (type > _MAX) { \ + type = _MAX; \ + } \ + return _STRINGS[(int)type]; \ + } \ + +#define ftdm_true(expr) \ + (expr && ( !strcasecmp(expr, "yes") || \ + !strcasecmp(expr, "on") || \ + !strcasecmp(expr, "true") || \ + !strcasecmp(expr, "enabled") || \ + !strcasecmp(expr, "active") || \ + atoi(expr))) ? 1 : 0 + + +#include +#ifndef __WINDOWS__ +#include +#endif + +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#include +#include "ftdm_types.h" +#include "hashtable.h" +#include "ftdm_config.h" +#include "g711.h" +#include "libteletone.h" +#include "ftdm_buffer.h" +#include "ftdm_threadmutex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __WINDOWS__ +#define ftdm_sleep(x) Sleep(x) +#else +#define ftdm_sleep(x) usleep(x * 1000) +#endif + +#ifdef NDEBUG +#undef assert +#define assert(_Expression) ((void)(_Expression)) +#endif + +#define FTDM_MAX_CHANNELS_PHYSICAL_SPAN 32 +#define FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32 +#define FTDM_MAX_CHANNELS_SPAN FTDM_MAX_CHANNELS_PHYSICAL_SPAN * FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN +#define FTDM_MAX_SPANS_INTERFACE 128 + +#define FTDM_MAX_CHANNELS_GROUP 1024 +#define FTDM_MAX_GROUPS_INTERFACE FTDM_MAX_SPANS_INTERFACE + +#define GOTO_STATUS(label,st) status = st; goto label ; + +#define ftdm_copy_string(x,y,z) strncpy(x, y, z - 1) +#define ftdm_set_string(x,y) strncpy(x, y, sizeof(x)-1) +#define ftdm_strlen_zero(s) (!s || *s == '\0') +#define ftdm_strlen_zero_buf(s) (*s == '\0') + + +#define ftdm_channel_test_feature(obj, flag) ((obj)->features & flag) +#define ftdm_channel_set_feature(obj, flag) (obj)->features |= (flag) +#define ftdm_channel_clear_feature(obj, flag) (obj)->features &= ~(flag) +#define ftdm_channel_set_member_locked(obj, _m, _v) ftdm_mutex_lock(obj->mutex); obj->_m = _v; ftdm_mutex_unlock(obj->mutex) + +/*! + \brief Test for the existance of a flag on an arbitary object + \command obj the object to test + \command flag the or'd list of flags to test + \return true value if the object has the flags defined +*/ +#define ftdm_test_flag(obj, flag) ((obj)->flags & flag) +#define ftdm_test_pflag(obj, flag) ((obj)->pflags & flag) +#define ftdm_test_sflag(obj, flag) ((obj)->sflags & flag) + + +#define ftdm_set_alarm_flag(obj, flag) (obj)->alarm_flags |= (flag) +#define ftdm_clear_alarm_flag(obj, flag) (obj)->alarm_flags &= ~(flag) +#define ftdm_test_alarm_flag(obj, flag) ((obj)->alarm_flags & flag) + +/*! + \brief Set a flag on an arbitrary object + \command obj the object to set the flags on + \command flag the or'd list of flags to set +*/ +#define ftdm_set_flag(obj, flag) (obj)->flags |= (flag) +#define ftdm_set_flag_locked(obj, flag) assert(obj->mutex != NULL); \ + ftdm_mutex_lock(obj->mutex); \ + (obj)->flags |= (flag); \ + ftdm_mutex_unlock(obj->mutex); + +#define ftdm_set_pflag(obj, flag) (obj)->pflags |= (flag) +#define ftdm_set_pflag_locked(obj, flag) assert(obj->mutex != NULL); \ + ftdm_mutex_lock(obj->mutex); \ + (obj)->pflags |= (flag); \ + ftdm_mutex_unlock(obj->mutex); + +#define ftdm_set_sflag(obj, flag) (obj)->sflags |= (flag) +#define ftdm_set_sflag_locked(obj, flag) assert(obj->mutex != NULL); \ + ftdm_mutex_lock(obj->mutex); \ + (obj)->sflags |= (flag); \ + ftdm_mutex_unlock(obj->mutex); + +/*! + \brief Clear a flag on an arbitrary object while locked + \command obj the object to test + \command flag the or'd list of flags to clear +*/ +#define ftdm_clear_flag(obj, flag) (obj)->flags &= ~(flag) + +#define ftdm_clear_flag_locked(obj, flag) assert(obj->mutex != NULL); ftdm_mutex_lock(obj->mutex); (obj)->flags &= ~(flag); ftdm_mutex_unlock(obj->mutex); + +#define ftdm_clear_pflag(obj, flag) (obj)->pflags &= ~(flag) + +#define ftdm_clear_pflag_locked(obj, flag) assert(obj->mutex != NULL); ftdm_mutex_lock(obj->mutex); (obj)->pflags &= ~(flag); ftdm_mutex_unlock(obj->mutex); + +#define ftdm_clear_sflag(obj, flag) (obj)->sflags &= ~(flag) + +#define ftdm_clear_sflag_locked(obj, flag) assert(obj->mutex != NULL); ftdm_mutex_lock(obj->mutex); (obj)->sflags &= ~(flag); ftdm_mutex_unlock(obj->mutex); + + +#define ftdm_set_state_locked(obj, s) if ( obj->state == s ) { \ + ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); \ + } else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \ + ftdm_channel_state_t st = obj->state; \ + ftdm_channel_set_state(obj, s, 1); \ + if (obj->state == s) ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \ + else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \ + } + +#ifdef _MSC_VER +/* The while(0) below throws a conditional expression is constant warning */ +#pragma warning(disable:4127) +#endif + +#define ftdm_set_state_locked_wait(obj, s) \ + do { \ + int __safety = 100; \ + ftdm_set_state_locked(obj, s); \ + while(__safety-- && ftdm_test_flag(obj, FTDM_CHANNEL_STATE_CHANGE)) { \ + ftdm_sleep(10); \ + } \ + if(!__safety) { \ + ftdm_log(FTDM_LOG_CRIT, "State change not completed\n"); \ + } \ + } while(0); + +#define ftdm_wait_for_flag_cleared(obj, flag, time) \ + do { \ + int __safety = time; \ + while(__safety-- && ftdm_test_flag(obj, flag)) { \ + ftdm_mutex_unlock(obj->mutex); \ + ftdm_sleep(10); \ + ftdm_mutex_lock(obj->mutex); \ + } \ + if(!__safety) { \ + ftdm_log(FTDM_LOG_CRIT, "flag %d was never cleared\n", flag); \ + } \ + } while(0); + +#define ftdm_set_state_wait(obj, s) \ + do { \ + ftdm_channel_set_state(obj, s, 0); \ + ftdm_wait_for_flag_cleared(obj, FTDM_CHANNEL_STATE_CHANGE, 100); \ + } while(0); + + +typedef enum { + FTDM_STATE_CHANGE_FAIL, + FTDM_STATE_CHANGE_SUCCESS, + FTDM_STATE_CHANGE_SAME, +} ftdm_state_change_result_t; + +#define ftdm_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ + ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); r = FTDM_STATE_CHANGE_SAME; \ + } else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \ + int st = obj->state; \ + r = (ftdm_channel_set_state(obj, s, l) == FTDM_SUCCESS) ? FTDM_STATE_CHANGE_SUCCESS : FTDM_STATE_CHANGE_FAIL; \ + if (obj->state == s) {ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s));} \ + else {ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); } \ + } + + +#define ftdm_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) + +/*! + \brief Copy flags from one arbitrary object to another + \command dest the object to copy the flags to + \command src the object to copy the flags from + \command flags the flags to copy +*/ +#define ftdm_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) + +struct ftdm_stream_handle { + ftdm_stream_handle_write_function_t write_function; + ftdm_stream_handle_raw_write_function_t raw_write_function; + void *data; + void *end; + ftdm_size_t data_size; + ftdm_size_t data_len; + ftdm_size_t alloc_len; + ftdm_size_t alloc_chunk; +}; + + +FT_DECLARE_NONSTD(ftdm_status_t) ftdm_console_stream_raw_write(ftdm_stream_handle_t *handle, uint8_t *data, ftdm_size_t datalen); +FT_DECLARE_NONSTD(ftdm_status_t) ftdm_console_stream_write(ftdm_stream_handle_t *handle, const char *fmt, ...); + +#define FTDM_CMD_CHUNK_LEN 1024 +#define FTDM_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(FTDM_CMD_CHUNK_LEN); \ + assert(s.data); \ + memset(s.data, 0, FTDM_CMD_CHUNK_LEN); \ + s.end = s.data; \ + s.data_size = FTDM_CMD_CHUNK_LEN; \ + s.write_function = ftdm_console_stream_write; \ + s.raw_write_function = ftdm_console_stream_raw_write; \ + s.alloc_len = FTDM_CMD_CHUNK_LEN; \ + s.alloc_chunk = FTDM_CMD_CHUNK_LEN + +struct ftdm_event { + ftdm_event_type_t e_type; + uint32_t enum_id; + ftdm_channel_t *channel; + void *data; +}; + +#define FTDM_TOKEN_STRLEN 128 +#define FTDM_MAX_TOKENS 10 + +static __inline__ char *ftdm_clean_string(char *s) +{ + char *p; + + for (p = s; p && *p; p++) { + uint8_t x = (uint8_t) *p; + if (x < 32 || x > 127) { + *p = ' '; + } + } + + return s; +} + +struct ftdm_bitstream { + uint8_t *data; + uint32_t datalen; + uint32_t byte_index; + uint8_t bit_index; + int8_t endian; + uint8_t top; + uint8_t bot; + uint8_t ss; + uint8_t ssv; +}; + +struct ftdm_fsk_data_state { + dsp_fsk_handle_t *fsk1200_handle; + uint8_t init; + uint8_t *buf; + size_t bufsize; + ftdm_size_t blen; + ftdm_size_t bpos; + ftdm_size_t dlen; + ftdm_size_t ppos; + int checksum; +}; + +struct ftdm_fsk_modulator { + teletone_dds_state_t dds; + ftdm_bitstream_t bs; + uint32_t carrier_bits_start; + uint32_t carrier_bits_stop; + uint32_t chan_sieze_bits; + uint32_t bit_factor; + uint32_t bit_accum; + uint32_t sample_counter; + int32_t samples_per_bit; + int32_t est_bytes; + fsk_modem_types_t modem_type; + ftdm_fsk_data_state_t *fsk_data; + ftdm_fsk_write_sample_t write_sample_callback; + void *user_data; + int16_t sample_buffer[64]; +}; + +/** + * Type Of Number (TON) + */ +typedef enum { + FTDM_TON_UNKNOWN = 0, + FTDM_TON_INTERNATIONAL, + FTDM_TON_NATIONAL, + FTDM_TON_NETWORK_SPECIFIC, + FTDM_TON_SUBSCRIBER_NUMBER, + FTDM_TON_ABBREVIATED_NUMBER, + FTDM_TON_RESERVED +} ftdm_ton_t; + +typedef struct { + char digits[25]; + uint8_t type; + uint8_t plan; +} ftdm_number_t; + +typedef enum { + FTDM_CALLER_STATE_DIALING, + FTDM_CALLER_STATE_SUCCESS, + FTDM_CALLER_STATE_FAIL +} ftdm_caller_state_t; + +struct ftdm_caller_data { + char cid_date[8]; + char cid_name[80]; + ftdm_number_t cid_num; + ftdm_number_t ani; + ftdm_number_t dnis; + ftdm_number_t rdnis; + char aniII[25]; + uint8_t screen; + uint8_t pres; + char collected[25]; + int CRV; + int hangup_cause; + uint8_t raw_data[1024]; + uint32_t raw_data_len; + uint32_t flags; + ftdm_caller_state_t call_state; + uint32_t chan_id; +}; + +typedef enum { + FTDM_TYPE_NONE, + FTDM_TYPE_SPAN = 0xFF, + FTDM_TYPE_CHANNEL +} ftdm_data_type_t; + +/* 2^8 table size, one for each byte value */ +#define FTDM_GAINS_TABLE_SIZE 256 +struct ftdm_channel { + ftdm_data_type_t data_type; + uint32_t span_id; + uint32_t chan_id; + uint32_t physical_span_id; + uint32_t physical_chan_id; + uint32_t rate; + uint32_t extra_id; + ftdm_chan_type_t type; + ftdm_socket_t sockfd; + ftdm_channel_flag_t flags; + uint32_t pflags; + uint32_t sflags; + ftdm_alarm_flag_t alarm_flags; + ftdm_channel_feature_t features; + ftdm_codec_t effective_codec; + ftdm_codec_t native_codec; + uint32_t effective_interval; + uint32_t native_interval; + uint32_t packet_len; + ftdm_channel_state_t state; + ftdm_channel_state_t last_state; + ftdm_channel_state_t init_state; + ftdm_mutex_t *mutex; + teletone_dtmf_detect_state_t dtmf_detect; + uint32_t buffer_delay; + ftdm_event_t event_header; + char last_error[256]; + zio_event_cb_t event_callback; + uint32_t skip_read_frames; + ftdm_buffer_t *dtmf_buffer; + ftdm_buffer_t *gen_dtmf_buffer; + ftdm_buffer_t *pre_buffer; + ftdm_buffer_t *digit_buffer; + ftdm_buffer_t *fsk_buffer; + ftdm_mutex_t *pre_buffer_mutex; + uint32_t dtmf_on; + uint32_t dtmf_off; + char *dtmf_hangup_buf; + teletone_generation_session_t tone_session; + ftdm_time_t last_event_time; + ftdm_time_t ring_time; + char tokens[FTDM_MAX_TOKENS+1][FTDM_TOKEN_STRLEN]; + uint8_t needed_tones[FTDM_TONEMAP_INVALID]; + uint8_t detected_tones[FTDM_TONEMAP_INVALID]; + ftdm_tonemap_t last_detected_tone; + uint32_t token_count; + char chan_name[128]; + char chan_number[32]; + ftdm_filehandle_t fds[2]; + ftdm_fsk_data_state_t fsk; + uint8_t fsk_buf[80]; + uint32_t ring_count; + void *mod_data; + void *call_data; + struct ftdm_caller_data caller_data; + struct ftdm_span *span; + struct ftdm_io_interface *zio; + ftdm_hash_t *variable_hash; + unsigned char rx_cas_bits; + uint32_t pre_buffer_size; + unsigned char rxgain_table[FTDM_GAINS_TABLE_SIZE]; + unsigned char txgain_table[FTDM_GAINS_TABLE_SIZE]; + float rxgain; + float txgain; +}; + + +struct ftdm_sigmsg { + ftdm_signal_event_t event_id; + uint32_t chan_id; + uint32_t span_id; + ftdm_channel_t *channel; + void *raw_data; + uint32_t raw_data_len; +}; + + +struct ftdm_span { + ftdm_data_type_t data_type; + char *name; + uint32_t span_id; + uint32_t chan_count; + ftdm_span_flag_t flags; + struct ftdm_io_interface *zio; + zio_event_cb_t event_callback; + ftdm_mutex_t *mutex; + ftdm_trunk_type_t trunk_type; + ftdm_analog_start_type_t start_type; + ftdm_signal_type_t signal_type; + void *signal_data; + ftdm_event_t event_header; + char last_error[256]; + char tone_map[FTDM_TONEMAP_INVALID+1][FTDM_TONEMAP_LEN]; + teletone_tone_map_t tone_detect_map[FTDM_TONEMAP_INVALID+1]; + teletone_multi_tone_t tone_finder[FTDM_TONEMAP_INVALID+1]; + ftdm_channel_t *channels[FTDM_MAX_CHANNELS_SPAN+1]; + zio_channel_outgoing_call_t outgoing_call; + zio_channel_set_sig_status_t set_channel_sig_status; + zio_channel_get_sig_status_t get_channel_sig_status; + zio_span_set_sig_status_t set_span_sig_status; + zio_span_get_sig_status_t get_span_sig_status; + zio_channel_request_t channel_request; + ftdm_span_start_t start; + ftdm_span_stop_t stop; + void *mod_data; + char *type; + char *dtmf_hangup; + size_t dtmf_hangup_len; + int suggest_chan_id; + ftdm_state_map_t *state_map; + struct ftdm_span *next; +}; + +struct ftdm_group { + char *name; + uint32_t group_id; + uint32_t chan_count; + ftdm_channel_t *channels[FTDM_MAX_CHANNELS_GROUP]; + uint32_t last_used_index; + ftdm_mutex_t *mutex; + struct ftdm_group *next; +}; + +FT_DECLARE_DATA extern ftdm_logger_t ftdm_log; + +typedef enum { + FTDM_CRASH_NEVER = 0, + FTDM_CRASH_ON_ASSERT +} ftdm_crash_policy_t; + +FT_DECLARE_DATA extern ftdm_crash_policy_t g_ftdm_crash_policy; + +typedef void *(*ftdm_malloc_func_t)(void *pool, ftdm_size_t len); +typedef void *(*ftdm_calloc_func_t)(void *pool, ftdm_size_t elements, ftdm_size_t len); +typedef void (*ftdm_free_func_t)(void *pool, void *ptr); +typedef struct ftdm_memory_handler { + void *pool; + ftdm_malloc_func_t malloc; + ftdm_calloc_func_t calloc; + ftdm_free_func_t free; +} ftdm_memory_handler_t; + +FT_DECLARE_DATA extern ftdm_memory_handler_t g_ftdm_mem_handler; + +struct ftdm_io_interface { + const char *name; + zio_configure_span_t configure_span; + zio_configure_t configure; + zio_open_t open; + zio_close_t close; + zio_channel_destroy_t channel_destroy; + zio_span_destroy_t span_destroy; + zio_get_alarms_t get_alarms; + zio_command_t command; + zio_wait_t wait; + zio_read_t read; + zio_write_t write; + zio_span_poll_event_t poll_event; + zio_span_next_event_t next_event; + zio_api_t api; +}; + +typedef struct ftdm_queue ftdm_queue_t; +typedef ftdm_status_t (*ftdm_queue_create_func_t)(ftdm_queue_t **queue, ftdm_size_t capacity); +typedef ftdm_status_t (*ftdm_queue_enqueue_func_t)(ftdm_queue_t *queue, void *obj); +typedef void *(*ftdm_queue_dequeue_func_t)(ftdm_queue_t *queue); +typedef ftdm_status_t (*ftdm_queue_wait_func_t)(ftdm_queue_t *queue, int ms); +typedef ftdm_status_t (*ftdm_queue_destroy_func_t)(ftdm_queue_t **queue); +typedef struct ftdm_queue_handler { + ftdm_queue_create_func_t create; + ftdm_queue_enqueue_func_t enqueue; + ftdm_queue_dequeue_func_t dequeue; + ftdm_queue_wait_func_t wait; + ftdm_queue_destroy_func_t destroy; +} ftdm_queue_handler_t; +FT_DECLARE_DATA extern ftdm_queue_handler_t g_ftdm_queue_handler; + +/*! brief create a new queue */ +#define ftdm_queue_create(queue, capacity) g_ftdm_queue_handler.create(queue, capacity) + +/*! Enqueue an object */ +#define ftdm_queue_enqueue(queue, obj) g_ftdm_queue_handler.enqueue(queue, obj) + +/*! dequeue an object from the queue */ +#define ftdm_queue_dequeue(queue) g_ftdm_queue_handler.dequeue(queue) + +/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ +#define ftdm_queue_wait(queue, ms) g_ftdm_queue_handler.wait(queue, ms) + +/*! destroy the queue */ +#define ftdm_queue_destroy(queue) g_ftdm_queue_handler.destroy(queue) + +/*! \brief Override the default queue handler */ +FT_DECLARE(ftdm_status_t) ftdm_global_set_queue_handler(ftdm_queue_handler_t *handler); + +/*! \brief Duplicate string */ +FT_DECLARE(char *) ftdm_strdup(const char *str); +FT_DECLARE(char *) ftdm_strndup(const char *str, ftdm_size_t inlen); + +FT_DECLARE(ftdm_size_t) ftdm_fsk_modulator_generate_bit(ftdm_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, ftdm_size_t buflen); +FT_DECLARE(int32_t) ftdm_fsk_modulator_generate_carrier_bits(ftdm_fsk_modulator_t *fsk_trans, uint32_t bits); +FT_DECLARE(void) ftdm_fsk_modulator_generate_chan_sieze(ftdm_fsk_modulator_t *fsk_trans); +FT_DECLARE(void) ftdm_fsk_modulator_send_data(ftdm_fsk_modulator_t *fsk_trans); +#define ftdm_fsk_modulator_send_all(_it) ftdm_fsk_modulator_generate_chan_sieze(_it); \ + ftdm_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_start); \ + ftdm_fsk_modulator_send_data(_it); \ + ftdm_fsk_modulator_generate_carrier_bits(_it, _it->carrier_bits_stop) + +FT_DECLARE(ftdm_status_t) ftdm_fsk_modulator_init(ftdm_fsk_modulator_t *fsk_trans, + fsk_modem_types_t modem_type, + uint32_t sample_rate, + ftdm_fsk_data_state_t *fsk_data, + float db_level, + uint32_t carrier_bits_start, + uint32_t carrier_bits_stop, + uint32_t chan_sieze_bits, + ftdm_fsk_write_sample_t write_sample_callback, + void *user_data); +FT_DECLARE(int8_t) ftdm_bitstream_get_bit(ftdm_bitstream_t *bsp); +FT_DECLARE(void) ftdm_bitstream_init(ftdm_bitstream_t *bsp, uint8_t *data, uint32_t datalen, ftdm_endian_t endian, uint8_t ss); +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_parse(ftdm_fsk_data_state_t *state, ftdm_size_t *type, char **data, ftdm_size_t *len); +FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_feed(ftdm_fsk_data_state_t *state, int16_t *data, size_t samples); +FT_DECLARE(ftdm_status_t) ftdm_fsk_demod_destroy(ftdm_fsk_data_state_t *state); +FT_DECLARE(int) ftdm_fsk_demod_init(ftdm_fsk_data_state_t *state, int rate, uint8_t *buf, size_t bufsize); +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_init(ftdm_fsk_data_state_t *state, uint8_t *data, uint32_t datalen); +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_mdmf(ftdm_fsk_data_state_t *state, ftdm_mdmf_type_t type, const uint8_t *data, uint32_t datalen); +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_checksum(ftdm_fsk_data_state_t *state); +FT_DECLARE(ftdm_status_t) ftdm_fsk_data_add_sdmf(ftdm_fsk_data_state_t *state, const char *date, char *number); +FT_DECLARE(ftdm_status_t) ftdm_channel_outgoing_call(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_set_sig_status(ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status); +FT_DECLARE(ftdm_status_t) ftdm_channel_get_sig_status(ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status); +FT_DECLARE(ftdm_status_t) ftdm_span_set_sig_status(ftdm_span_t *span, ftdm_signaling_status_t status); +FT_DECLARE(ftdm_status_t) ftdm_span_get_sig_status(ftdm_span_t *span, ftdm_signaling_status_t *status); +FT_DECLARE(void) ftdm_channel_rotate_tokens(ftdm_channel_t *ftdmchan); +FT_DECLARE(void) ftdm_channel_clear_detected_tones(ftdm_channel_t *ftdmchan); +FT_DECLARE(void) ftdm_channel_clear_needed_tones(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_get_alarms(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_send_fsk_data(ftdm_channel_t *ftdmchan, ftdm_fsk_data_state_t *fsk_data, float db_level); +FT_DECLARE(ftdm_status_t) ftdm_channel_clear_token(ftdm_channel_t *ftdmchan, const char *token); +FT_DECLARE(void) ftdm_channel_replace_token(ftdm_channel_t *ftdmchan, const char *old_token, const char *new_token); +FT_DECLARE(ftdm_status_t) ftdm_channel_add_token(ftdm_channel_t *ftdmchan, char *token, int end); +FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int lock); +FT_DECLARE(ftdm_status_t) ftdm_span_load_tones(ftdm_span_t *span, const char *mapname); +FT_DECLARE(ftdm_size_t) ftdm_channel_dequeue_dtmf(ftdm_channel_t *ftdmchan, char *dtmf, ftdm_size_t len); +FT_DECLARE(ftdm_status_t) ftdm_channel_queue_dtmf(ftdm_channel_t *ftdmchan, const char *dtmf); +FT_DECLARE(void) ftdm_channel_flush_dtmf(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_time_t) ftdm_current_time_in_ms(void); +FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms); +FT_DECLARE(ftdm_status_t) ftdm_span_next_event(ftdm_span_t *span, ftdm_event_t **event); +FT_DECLARE(ftdm_status_t) ftdm_span_find(uint32_t id, ftdm_span_t **span); +FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *zio, ftdm_span_t **span, const char *name); +FT_DECLARE(ftdm_status_t) ftdm_span_close_all(void); +FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t sockfd, ftdm_chan_type_t type, ftdm_channel_t **chan); +FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, zio_event_cb_t event_callback); +FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_group_add_channels(const char* name, ftdm_span_t* span, const char* val); +FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ftdm_channel_t* ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_group_find(uint32_t id, ftdm_group_t **group); +FT_DECLARE(ftdm_status_t) ftdm_group_find_by_name(const char *name, ftdm_group_t **group); +FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *name); +FT_DECLARE(ftdm_status_t) ftdm_channel_set_event_callback(ftdm_channel_t *ftdmchan, zio_event_cb_t event_callback); +FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, ftdm_channel_t **ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_span_channel_use_count(ftdm_span_t *span, uint32_t *count); +FT_DECLARE(ftdm_status_t) ftdm_group_channel_use_count(ftdm_group_t *group, uint32_t *count); +FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_close(ftdm_channel_t **ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_done(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_use(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_command_t command, void *obj); +FT_DECLARE(ftdm_status_t) ftdm_channel_wait(ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to); +FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen); +FT_DECLARE(void) ftdm_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor); +FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t datasize, ftdm_size_t *datalen); +FT_DECLARE(ftdm_status_t) ftdm_channel_add_var(ftdm_channel_t *ftdmchan, const char *var_name, const char *value); +FT_DECLARE(const char *) ftdm_channel_get_var(ftdm_channel_t *ftdmchan, const char *var_name); +FT_DECLARE(ftdm_status_t) ftdm_channel_clear_vars(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_global_init(void); +FT_DECLARE(ftdm_status_t) ftdm_global_configuration(void); +FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void); +FT_DECLARE(ftdm_status_t) ftdm_global_set_memory_handler(ftdm_memory_handler_t *handler); +FT_DECLARE(void) ftdm_global_set_crash_policy(ftdm_crash_policy_t policy); +FT_DECLARE(void) ftdm_global_set_logger(ftdm_logger_t logger); +FT_DECLARE(void) ftdm_global_set_default_logger(int level); +FT_DECLARE(uint32_t) ftdm_separate_string(char *buf, char delim, char **array, int arraylen); +FT_DECLARE(void) print_bits(uint8_t *b, int bl, char *buf, int blen, int e, uint8_t ss); +FT_DECLARE(void) print_hex_bytes(uint8_t *data, ftdm_size_t dlen, char *buf, ftdm_size_t blen); +FT_DECLARE_NONSTD(int) ftdm_hash_equalkeys(void *k1, void *k2); +FT_DECLARE_NONSTD(uint32_t) ftdm_hash_hashfromstring(void *ky); +FT_DECLARE(uint32_t) ftdm_running(void); +FT_DECLARE(ftdm_status_t) ftdm_channel_complete_state(ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) ftdm_channel_init(ftdm_channel_t *ftdmchan); +FT_DECLARE(int) ftdm_load_modules(void); +FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void); +FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ...); +FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters); +FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span); +FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span); +FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t len); +FT_DECLARE(ftdm_status_t) ftdm_global_add_io_interface(ftdm_io_interface_t *io_interface); +FT_DECLARE(int) ftdm_load_module(const char *name); +FT_DECLARE(int) ftdm_load_module_assume(const char *name); +FT_DECLARE(ftdm_status_t) ftdm_span_find_by_name(const char *name, ftdm_span_t **span); +FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd); +FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap); + +ZIO_CODEC_FUNCTION(zio_slin2ulaw); +ZIO_CODEC_FUNCTION(zio_ulaw2slin); +ZIO_CODEC_FUNCTION(zio_slin2alaw); +ZIO_CODEC_FUNCTION(zio_alaw2slin); +ZIO_CODEC_FUNCTION(zio_ulaw2alaw); +ZIO_CODEC_FUNCTION(zio_alaw2ulaw); + +#ifdef DEBUG_LOCKS +#define ftdm_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _ftdm_mutex_lock(_x) +#define ftdm_mutex_trylock(_x) printf("++++++try %s:%d\n", __FILE__, __LINE__) && _ftdm_mutex_trylock(_x) +#define ftdm_mutex_unlock(_x) printf("------unlock %s:%d\n", __FILE__, __LINE__) && _ftdm_mutex_unlock(_x) +#else +#define ftdm_mutex_lock(_x) _ftdm_mutex_lock(_x) +#define ftdm_mutex_trylock(_x) _ftdm_mutex_trylock(_x) +#define ftdm_mutex_unlock(_x) _ftdm_mutex_unlock(_x) +#endif + +/*! + \brief Assert condition +*/ +#define ftdm_assert(assertion, msg) \ + if (!(assertion)) { \ + ftdm_log(FTDM_LOG_CRIT, msg); \ + if (g_ftdm_crash_policy & FTDM_CRASH_ON_ASSERT) { \ + ftdm_abort(); \ + } \ + } + +/*! + \brief Assert condition and return +*/ +#define ftdm_assert_return(assertion, retval, msg) \ + if (!(assertion)) { \ + ftdm_log(FTDM_LOG_CRIT, msg); \ + if (g_ftdm_crash_policy & FTDM_CRASH_ON_ASSERT) { \ + ftdm_abort(); \ + } else { \ + return retval; \ + } \ + } + +/*! + \brief Allocate uninitialized memory + \command chunksize the chunk size +*/ +#define ftdm_malloc(chunksize) g_ftdm_mem_handler.malloc(g_ftdm_mem_handler.pool, chunksize) + +/*! + \brief Allocate initialized memory + \command chunksize the chunk size +*/ +#define ftdm_calloc(elements, chunksize) g_ftdm_mem_handler.calloc(g_ftdm_mem_handler.pool, elements, chunksize) + +/*! + \brief Free chunk of memory + \command chunksize the chunk size +*/ +#define ftdm_free(chunk) g_ftdm_mem_handler.free(g_ftdm_mem_handler.pool, chunk) + +/*! + \brief Free a pointer and set it to NULL unless it already is NULL + \command it the pointer +*/ +#define ftdm_safe_free(it) if (it) { ftdm_free(it); it = NULL; } + +/*! + \brief Socket the given socket + \command it the socket +*/ +#define ftdm_socket_close(it) if (it > -1) { close(it); it = -1;} + +static __inline__ void ftdm_abort(void) +{ +#ifdef __cplusplus + ::abort(); +#else + abort(); +#endif +} + +static __inline__ void ftdm_set_state_all(ftdm_span_t *span, ftdm_channel_state_t state) +{ + uint32_t j; + ftdm_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + ftdm_set_state_locked((span->channels[j]), state); + } + ftdm_mutex_unlock(span->mutex); +} + +static __inline__ int ftdm_check_state_all(ftdm_span_t *span, ftdm_channel_state_t state) +{ + uint32_t j; + for(j = 1; j <= span->chan_count; j++) { + if (span->channels[j]->state != state || ftdm_test_flag(span->channels[j], FTDM_CHANNEL_STATE_CHANGE)) { + return 0; + } + } + + return 1; +} + +static __inline__ void ftdm_set_flag_all(ftdm_span_t *span, uint32_t flag) +{ + uint32_t j; + ftdm_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + ftdm_set_flag_locked((span->channels[j]), flag); + } + ftdm_mutex_unlock(span->mutex); +} + +static __inline__ void ftdm_clear_flag_all(ftdm_span_t *span, uint32_t flag) +{ + uint32_t j; + ftdm_mutex_lock(span->mutex); + for(j = 1; j <= span->chan_count; j++) { + ftdm_clear_flag_locked((span->channels[j]), flag); + } + ftdm_mutex_unlock(span->mutex); +} + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ From 526cb45c93d76101df5e5dda5c54f4a152a49eb8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 19:38:56 +0000 Subject: [PATCH 1682/1766] more freetdm headers missing git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@970 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/ftdm_buffer.h | 154 +++++ libs/freetdm/src/include/ftdm_config.h | 145 ++++ libs/freetdm/src/include/ftdm_dso.h | 51 ++ libs/freetdm/src/include/ftdm_m3ua.h | 134 ++++ libs/freetdm/src/include/ftdm_threadmutex.h | 67 ++ libs/freetdm/src/include/ftdm_types.h | 703 ++++++++++++++++++++ 6 files changed, 1254 insertions(+) create mode 100644 libs/freetdm/src/include/ftdm_buffer.h create mode 100644 libs/freetdm/src/include/ftdm_config.h create mode 100644 libs/freetdm/src/include/ftdm_dso.h create mode 100644 libs/freetdm/src/include/ftdm_m3ua.h create mode 100644 libs/freetdm/src/include/ftdm_threadmutex.h create mode 100644 libs/freetdm/src/include/ftdm_types.h diff --git a/libs/freetdm/src/include/ftdm_buffer.h b/libs/freetdm/src/include/ftdm_buffer.h new file mode 100644 index 0000000000..e069e2d44b --- /dev/null +++ b/libs/freetdm/src/include/ftdm_buffer.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef FTDM_BUFFER_H +#define FTDM_BUFFER_H + +#include "freetdm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup ftdm_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 ftdm_buffer; +typedef struct ftdm_buffer ftdm_buffer_t; + +/*! \brief Allocate a new dynamic ftdm_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 + */ +FT_DECLARE(ftdm_status_t) ftdm_buffer_create(ftdm_buffer_t **buffer, ftdm_size_t blocksize, ftdm_size_t start_len, ftdm_size_t max_len); + +/*! \brief Get the length of a ftdm_buffer_t + * \param buffer any buffer of type ftdm_buffer_t + * \return int size of the buffer. + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_len(ftdm_buffer_t *buffer); + +/*! \brief Get the freespace of a ftdm_buffer_t + * \param buffer any buffer of type ftdm_buffer_t + * \return int freespace in the buffer. + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_freespace(ftdm_buffer_t *buffer); + +/*! \brief Get the in use amount of a ftdm_buffer_t + * \param buffer any buffer of type ftdm_buffer_t + * \return int ammount of buffer curently in use + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_inuse(ftdm_buffer_t *buffer); + +/*! \brief Read data from a ftdm_buffer_t up to the ammount of datalen if it is available. Remove read data from buffer. + * \param buffer any buffer of type ftdm_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 + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_read(ftdm_buffer_t *buffer, void *data, ftdm_size_t datalen); + +/*! \brief Read data endlessly from a ftdm_buffer_t + * \param buffer any buffer of type ftdm_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. + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_read_loop(ftdm_buffer_t *buffer, void *data, ftdm_size_t datalen); + +/*! \brief Assign a number of loops to read + * \param buffer any buffer of type ftdm_buffer_t + * \param loops the number of loops (-1 for infinite) + */ +FT_DECLARE(void) ftdm_buffer_set_loops(ftdm_buffer_t *buffer, int32_t loops); + +/*! \brief Write data into a ftdm_buffer_t up to the length of datalen + * \param buffer any buffer of type ftdm_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 + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_write(ftdm_buffer_t *buffer, const void *data, ftdm_size_t datalen); + +/*! \brief Remove data from the buffer + * \param buffer any buffer of type ftdm_buffer_t + * \param datalen amount of data to be removed + * \return int size of buffer, or 0 if unable to toss that much data + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_toss(ftdm_buffer_t *buffer, ftdm_size_t datalen); + +/*! \brief Remove all data from the buffer + * \param buffer any buffer of type ftdm_buffer_t + */ +FT_DECLARE(void) ftdm_buffer_zero(ftdm_buffer_t *buffer); + +/*! \brief Destroy the buffer + * \param buffer buffer to destroy + * \note only neccessary on dynamic buffers (noop on pooled ones) + */ +FT_DECLARE(void) ftdm_buffer_destroy(ftdm_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 + */ +FT_DECLARE(ftdm_size_t) ftdm_buffer_seek(ftdm_buffer_t *buffer, ftdm_size_t datalen); + +/** @} */ + +FT_DECLARE(ftdm_size_t) ftdm_buffer_zwrite(ftdm_buffer_t *buffer, const void *data, ftdm_size_t datalen); + +#ifdef __cplusplus +} +#endif + +#endif +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ diff --git a/libs/freetdm/src/include/ftdm_config.h b/libs/freetdm/src/include/ftdm_config.h new file mode 100644 index 0000000000..0f96a8f872 --- /dev/null +++ b/libs/freetdm/src/include/ftdm_config.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup config Config File Parser + * @ingroup config + * This module implements a basic interface and file format parser + * + *
+ *
+ * EXAMPLE 
+ * 
+ * [category1]
+ * var1 => val1
+ * var2 => val2
+ * \# lines that begin with \# are comments
+ * \#var3 => val3
+ * 
+ * @{ + */ + +#ifndef FTDM_CONFIG_H +#define FTDM_CONFIG_H + +#include "freetdm.h" +#define FTDM_URL_SEPARATOR "://" + + +#ifdef WIN32 +#define FTDM_PATH_SEPARATOR "\\" +#ifndef FTDM_CONFIG_DIR +#define FTDM_CONFIG_DIR "c:\\freetdm" +#endif +#define ftdm_is_file_path(file) (*(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)) +#else +#define FTDM_PATH_SEPARATOR "/" +#ifndef FTDM_CONFIG_DIR +#define FTDM_CONFIG_DIR "/etc/freetdm" +#endif +#define ftdm_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ftdm_config ftdm_config_t; + +/*! \brief A simple file handle representing an open configuration file **/ +struct ftdm_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 (ftdm_config_t *) config handle to use + \param file_path path to the file + \return 1 (true) on success 0 (false) on failure +*/ +int ftdm_config_open_file(ftdm_config_t * cfg, const char *file_path); + +/*! + \brief Close a previously opened configuration file + \param cfg (ftdm_config_t *) config handle to use +*/ +void ftdm_config_close_file(ftdm_config_t * cfg); + +/*! + \brief Retrieve next name/value pair from configuration file + \param cfg (ftdm_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 ftdm_config_next_pair(ftdm_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 +*/ +FT_DECLARE (int) ftdm_config_get_cas_bits(char *strvalue, unsigned char *outbits); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ diff --git a/libs/freetdm/src/include/ftdm_dso.h b/libs/freetdm/src/include/ftdm_dso.h new file mode 100644 index 0000000000..c4c4b705d1 --- /dev/null +++ b/libs/freetdm/src/include/ftdm_dso.h @@ -0,0 +1,51 @@ +/* + * 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 _FTDM_DSO_H +#define _FTDM_DSO_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*ftdm_func_ptr_t) (void); +typedef void * ftdm_dso_lib_t; + +FT_DECLARE(void) ftdm_dso_destroy(ftdm_dso_lib_t *lib); +FT_DECLARE(ftdm_dso_lib_t) ftdm_dso_open(const char *path, char **err); +FT_DECLARE(void *) ftdm_dso_func_sym(ftdm_dso_lib_t lib, const char *sym, char **err); + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 + */ + diff --git a/libs/freetdm/src/include/ftdm_m3ua.h b/libs/freetdm/src/include/ftdm_m3ua.h new file mode 100644 index 0000000000..ae2abb5022 --- /dev/null +++ b/libs/freetdm/src/include/ftdm_m3ua.h @@ -0,0 +1,134 @@ +/* + * ftdm_m3ua.h + * freetdm + * + * 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 "freetdm.h" + +#ifdef __cplusplus +extern "C" { +#endif +enum e_sigboost_event_id_values +{ + SIGBOOST_EVENT_CALL_START = 0x80, /*128*/ + SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/ + SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/ + SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/ + SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/ + SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/ + SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ + SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ + SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ + /* Following IDs are ss7boost to sangoma_mgd only. */ + SIGBOOST_EVENT_HEARTBEAT = 0x89, /*137*/ + SIGBOOST_EVENT_INSERT_CHECK_LOOP = 0x8a, /*138*/ + SIGBOOST_EVENT_REMOVE_CHECK_LOOP = 0x8b, /*139*/ + SIGBOOST_EVENT_AUTO_CALL_GAP_ABATE = 0x8c, /*140*/ +}; +enum e_sigboost_release_cause_values +{ + SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0, + SIGBOOST_RELEASE_CAUSE_NORMAL = 16, + SIGBOOST_RELEASE_CAUSE_BUSY = 17, + /* probable elimination */ + //SIGBOOST_RELEASE_CAUSE_BUSY = 0x91, /* 145 */ + //SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92, /* 146 */ + //SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93, /* 147 */ + //SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94, /* 148 */ +}; + +enum e_sigboost_call_setup_ack_nack_cause_values +{ + SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 117, /* unused Q.850 value */ + SIGBOOST_CALL_SETUP_NACK_TEST_CKT_BUSY = 118, /* unused Q.850 value */ + SIGBOOST_CALL_SETUP_NACK_INVALID_NUMBER = 28, + /* probable elimination */ + //SIGBOOST_CALL_SETUP_RESERVED = 0x00, + //SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10, + //SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11, + //SIGBOOST_CALL_SETUP_NACK_AUTO_CALL_GAP = 0x17, +}; +typedef enum { + M3UA_SPAN_SIGNALING_M3UA, + M3UA_SPAN_SIGNALING_SS7BOX, + +} M3UA_TSpanSignaling; +#define M3UA_SPAN_STRINGS "M3UA", "SS7BOX" +FTDM_STR2ENUM_P(m3ua_str2span, m3ua_span2str, M3UA_TSpanSignaling) + + + +typedef enum { + FTDM_M3UA_RUNNING = (1 << 0) +} ftdm_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; +} ftdm_m3ua_data_t; +*/ + +ftdm_status_t m3ua_init(ftdm_io_interface_t **zint); +ftdm_status_t m3ua_destroy(void); +ftdm_status_t m3ua_start(ftdm_span_t *span); + +#ifdef __cplusplus +} +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ + diff --git a/libs/freetdm/src/include/ftdm_threadmutex.h b/libs/freetdm/src/include/ftdm_threadmutex.h new file mode 100644 index 0000000000..a970eda522 --- /dev/null +++ b/libs/freetdm/src/include/ftdm_threadmutex.h @@ -0,0 +1,67 @@ +/* + * Cross Platform Thread/Mutex abstraction + * Copyright(C) 2007 Michael Jerris + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so. + * + * This work is provided under this license on an "as is" basis, without warranty of any kind, + * either expressed or implied, including, without limitation, warranties that the covered code + * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire + * risk as to the quality and performance of the covered code is with you. Should any covered + * code prove defective in any respect, you (not the initial developer or any other contributor) + * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty + * constitutes an essential part of this license. No use of any covered code is authorized hereunder + * except under this disclaimer. + * + * Contributors: + * + * Moises Silva + * + */ + + +#ifndef _FTDM_THREADMUTEX_H +#define _FTDM_THREADMUTEX_H + +#include "freetdm.h" + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct ftdm_mutex ftdm_mutex_t; +typedef struct ftdm_thread ftdm_thread_t; +typedef struct ftdm_condition ftdm_condition_t; +typedef void *(*ftdm_thread_function_t) (ftdm_thread_t *, void *); + +FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached(ftdm_thread_function_t func, void *data); +FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached_ex(ftdm_thread_function_t func, void *data, ftdm_size_t stack_size); +FT_DECLARE(void) ftdm_thread_override_default_stacksize(ftdm_size_t size); +FT_DECLARE(ftdm_status_t) ftdm_mutex_create(ftdm_mutex_t **mutex); +FT_DECLARE(ftdm_status_t) ftdm_mutex_destroy(ftdm_mutex_t **mutex); +FT_DECLARE(ftdm_status_t) _ftdm_mutex_lock(ftdm_mutex_t *mutex); +FT_DECLARE(ftdm_status_t) _ftdm_mutex_trylock(ftdm_mutex_t *mutex); +FT_DECLARE(ftdm_status_t) _ftdm_mutex_unlock(ftdm_mutex_t *mutex); +FT_DECLARE(ftdm_status_t) ftdm_condition_create(ftdm_condition_t **cond, ftdm_mutex_t *mutex); +FT_DECLARE(ftdm_status_t) ftdm_condition_destroy(ftdm_condition_t **cond); +FT_DECLARE(ftdm_status_t) ftdm_condition_signal(ftdm_condition_t *cond); +FT_DECLARE(ftdm_status_t) ftdm_condition_wait(ftdm_condition_t *cond, int ms); + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ + diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h new file mode 100644 index 0000000000..680ba0feb4 --- /dev/null +++ b/libs/freetdm/src/include/ftdm_types.h @@ -0,0 +1,703 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * + */ + +#ifndef FTDM_TYPES_H +#define FTDM_TYPES_H +#include "fsk.h" + +#ifdef WIN32 +#include +typedef HANDLE ftdm_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 ftdm_ssize_t; +typedef int ftdm_filehandle_t; +#else +#include +#include +#include +#include +typedef int ftdm_socket_t; +typedef ssize_t ftdm_ssize_t; +typedef int ftdm_filehandle_t; +#endif + +#ifdef __cplusplus +extern "C" { +#endif +#define TAG_END NULL + +typedef size_t ftdm_size_t; +struct ftdm_io_interface; + +#define FTDM_COMMAND_OBJ_INT *((int *)obj) +#define FTDM_COMMAND_OBJ_CHAR_P (char *)obj +#define FTDM_COMMAND_OBJ_FLOAT *(float *)obj +#define FTDM_FSK_MOD_FACTOR 0x10000 +#define FTDM_DEFAULT_DTMF_ON 250 +#define FTDM_DEFAULT_DTMF_OFF 50 + +#define FTDM_END -1 +#define FTDM_ANY_STATE -1 + +typedef uint64_t ftdm_time_t; + +typedef enum { + FTDM_ENDIAN_BIG = 1, + FTDM_ENDIAN_LITTLE = -1 +} ftdm_endian_t; + +typedef enum { + FTDM_CID_TYPE_SDMF = 0x04, + FTDM_CID_TYPE_MDMF = 0x80 +} ftdm_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 +} ftdm_mdmf_type_t; +#define MDMF_STRINGS "X", "DATETIME", "PHONE_NUM", "DDN", "NO_NUM", "X", "X", "PHONE_NAME", "NO_NAME", "ALT_ROUTE", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_mdmf_type, ftdm_mdmf_type2str, ftdm_mdmf_type_t) + +#define FTDM_TONEMAP_LEN 128 +typedef enum { + FTDM_TONEMAP_NONE, + FTDM_TONEMAP_DIAL, + FTDM_TONEMAP_RING, + FTDM_TONEMAP_BUSY, + FTDM_TONEMAP_FAIL1, + FTDM_TONEMAP_FAIL2, + FTDM_TONEMAP_FAIL3, + FTDM_TONEMAP_ATTN, + FTDM_TONEMAP_CALLWAITING_CAS, + FTDM_TONEMAP_CALLWAITING_SAS, + FTDM_TONEMAP_CALLWAITING_ACK, + FTDM_TONEMAP_INVALID +} ftdm_tonemap_t; +#define TONEMAP_STRINGS "NONE", "DIAL", "RING", "BUSY", "FAIL1", "FAIL2", "FAIL3", "ATTN", "CALLWAITING-CAS", "CALLWAITING-SAS", "CALLWAITING-ACK", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_tonemap, ftdm_tonemap2str, ftdm_tonemap_t) + +typedef enum { + FTDM_TRUNK_E1, + FTDM_TRUNK_T1, + FTDM_TRUNK_J1, + FTDM_TRUNK_BRI, + FTDM_TRUNK_BRI_PTMP, + FTDM_TRUNK_FXO, + FTDM_TRUNK_FXS, + FTDM_TRUNK_EM, + FTDM_TRUNK_NONE +} ftdm_trunk_type_t; +#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "EM", "NONE" +FTDM_STR2ENUM_P(ftdm_str2ftdm_trunk_type, ftdm_trunk_type2str, ftdm_trunk_type_t) + +typedef enum { + FTDM_ANALOG_START_KEWL, + FTDM_ANALOG_START_LOOP, + FTDM_ANALOG_START_GROUND, + FTDM_ANALOG_START_WINK, + FTDM_ANALOG_START_NA +} ftdm_analog_start_type_t; +#define START_TYPE_STRINGS "KEWL", "LOOP", "GROUND", "WINK", "NA" +FTDM_STR2ENUM_P(ftdm_str2ftdm_analog_start_type, ftdm_analog_start_type2str, ftdm_analog_start_type_t) + +typedef enum { + FTDM_OOB_ONHOOK, + FTDM_OOB_OFFHOOK, + FTDM_OOB_WINK, + FTDM_OOB_FLASH, + FTDM_OOB_RING_START, + FTDM_OOB_RING_STOP, + FTDM_OOB_ALARM_TRAP, + FTDM_OOB_ALARM_CLEAR, + FTDM_OOB_NOOP, + FTDM_OOB_CAS_BITS_CHANGE, + FTDM_OOB_INVALID +} ftdm_oob_event_t; +#define OOB_STRINGS "DTMF", "ONHOOK", "OFFHOOK", "WINK", "FLASH", "RING_START", "RING_STOP", "ALARM_TRAP", "ALARM_CLEAR", "NOOP", "CAS_BITS_CHANGE", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_oob_event, ftdm_oob_event2str, ftdm_oob_event_t) + +typedef enum { + FTDM_ALARM_NONE = 0, + FTDM_ALARM_RECOVER = (1 << 0), + FTDM_ALARM_LOOPBACK = (1 << 2), + FTDM_ALARM_YELLOW = (1 << 3), + FTDM_ALARM_RED = (1 << 4), + FTDM_ALARM_BLUE = (1 << 5), + FTDM_ALARM_NOTOPEN = ( 1 << 6), + FTDM_ALARM_AIS = ( 1 << 7), + FTDM_ALARM_RAI = ( 1 << 8), + FTDM_ALARM_GENERAL = ( 1 << 30) +} ftdm_alarm_flag_t; + +typedef enum { + FTDM_SIGTYPE_NONE, + FTDM_SIGTYPE_ISDN, + FTDM_SIGTYPE_RBS, + FTDM_SIGTYPE_ANALOG, + FTDM_SIGTYPE_SANGOMABOOST, + FTDM_SIGTYPE_M3UA, + FTDM_SIGTYPE_R2 +} ftdm_signal_type_t; + +/*! + \brief Signaling status on a given span or specific channel on protocols that support it + */ +typedef enum { + /* The signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */ + FTDM_SIG_STATE_DOWN, + /* The signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */ + FTDM_SIG_STATE_SUSPENDED, + /* The signaling link is ready and calls can be placed */ + FTDM_SIG_STATE_UP, + /* Invalid status */ + FTDM_SIG_STATE_INVALID +} ftdm_signaling_status_t; +#define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_signaling_status, ftdm_signaling_status2str, ftdm_signaling_status_t) + +typedef enum { + FTDM_SIGEVENT_START, + FTDM_SIGEVENT_STOP, + FTDM_SIGEVENT_TRANSFER, + FTDM_SIGEVENT_ANSWER, + FTDM_SIGEVENT_UP, + FTDM_SIGEVENT_FLASH, + FTDM_SIGEVENT_PROGRESS, + FTDM_SIGEVENT_PROGRESS_MEDIA, + FTDM_SIGEVENT_NOTIFY, + FTDM_SIGEVENT_TONE_DETECTED, + FTDM_SIGEVENT_ALARM_TRAP, + FTDM_SIGEVENT_ALARM_CLEAR, + FTDM_SIGEVENT_MISC, + FTDM_SIGEVENT_COLLECTED_DIGIT, + FTDM_SIGEVENT_ADD_CALL, + FTDM_SIGEVENT_RESTART, + /* Signaling link status changed (D-chan up, down, R2 blocked etc) */ + FTDM_SIGEVENT_SIGSTATUS_CHANGED, + /* Hardware link status changed (Line connected, disconnected) */ + FTDM_SIGEVENT_HWSTATUS_CHANGED, + FTDM_SIGEVENT_INVALID +} ftdm_signal_event_t; +#define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \ + "PROGRESS_MEDIA", "NOTIFY", "TONE_DETECTED", "ALARM_TRAP", "ALARM_CLEAR", "MISC", \ + "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGLINK_CHANGED", "HWSTATUS_CHANGED", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_signal_event, ftdm_signal_event2str, ftdm_signal_event_t) + +typedef enum { + FTDM_EVENT_NONE, + FTDM_EVENT_DTMF, + FTDM_EVENT_OOB, + FTDM_EVENT_COUNT +} ftdm_event_type_t; + +typedef enum { + FTDM_TOP_DOWN, + FTDM_BOTTOM_UP +} ftdm_direction_t; + +typedef enum { + FTDM_SUCCESS, + FTDM_FAIL, + FTDM_MEMERR, + FTDM_TIMEOUT, + FTDM_NOTIMPL, + FTDM_CHECKSUM_ERROR, + FTDM_STATUS_COUNT, + FTDM_BREAK +} ftdm_status_t; + +typedef enum { + FTDM_NO_FLAGS = 0, + FTDM_READ = (1 << 0), + FTDM_WRITE = (1 << 1), + FTDM_EVENTS = (1 << 2) +} ftdm_wait_flag_t; + +typedef enum { + FTDM_CODEC_ULAW = 0, + FTDM_CODEC_ALAW = 8, + FTDM_CODEC_SLIN = 10, + FTDM_CODEC_NONE = (1 << 30) +} ftdm_codec_t; + +typedef enum { + FTDM_TONE_DTMF = (1 << 0) +} ftdm_tone_type_t; + +typedef enum { + FTDM_COMMAND_NOOP, + FTDM_COMMAND_SET_INTERVAL, + FTDM_COMMAND_GET_INTERVAL, + FTDM_COMMAND_SET_CODEC, + FTDM_COMMAND_GET_CODEC, + FTDM_COMMAND_SET_NATIVE_CODEC, + FTDM_COMMAND_GET_NATIVE_CODEC, + FTDM_COMMAND_ENABLE_DTMF_DETECT, + FTDM_COMMAND_DISABLE_DTMF_DETECT, + FTDM_COMMAND_SEND_DTMF, + FTDM_COMMAND_SET_DTMF_ON_PERIOD, + FTDM_COMMAND_GET_DTMF_ON_PERIOD, + FTDM_COMMAND_SET_DTMF_OFF_PERIOD, + FTDM_COMMAND_GET_DTMF_OFF_PERIOD, + FTDM_COMMAND_GENERATE_RING_ON, + FTDM_COMMAND_GENERATE_RING_OFF, + FTDM_COMMAND_OFFHOOK, + FTDM_COMMAND_ONHOOK, + FTDM_COMMAND_FLASH, + FTDM_COMMAND_WINK, + FTDM_COMMAND_ENABLE_PROGRESS_DETECT, + FTDM_COMMAND_DISABLE_PROGRESS_DETECT, + FTDM_COMMAND_TRACE_INPUT, + FTDM_COMMAND_TRACE_OUTPUT, + FTDM_COMMAND_ENABLE_CALLERID_DETECT, + FTDM_COMMAND_DISABLE_CALLERID_DETECT, + FTDM_COMMAND_ENABLE_ECHOCANCEL, + FTDM_COMMAND_DISABLE_ECHOCANCEL, + FTDM_COMMAND_ENABLE_ECHOTRAIN, + FTDM_COMMAND_DISABLE_ECHOTRAIN, + FTDM_COMMAND_SET_CAS_BITS, + FTDM_COMMAND_GET_CAS_BITS, + FTDM_COMMAND_SET_RX_GAIN, + FTDM_COMMAND_GET_RX_GAIN, + FTDM_COMMAND_SET_TX_GAIN, + FTDM_COMMAND_GET_TX_GAIN, + FTDM_COMMAND_FLUSH_TX_BUFFERS, + FTDM_COMMAND_FLUSH_RX_BUFFERS, + FTDM_COMMAND_FLUSH_BUFFERS, + FTDM_COMMAND_SET_PRE_BUFFER_SIZE, + FTDM_COMMAND_SET_LINK_STATUS, + FTDM_COMMAND_GET_LINK_STATUS, + FTDM_COMMAND_COUNT +} ftdm_command_t; + +typedef enum { + FTDM_SPAN_CONFIGURED = (1 << 0), + FTDM_SPAN_READY = (1 << 1), + FTDM_SPAN_STATE_CHANGE = (1 << 2), + FTDM_SPAN_SUSPENDED = (1 << 3), + FTDM_SPAN_IN_THREAD = (1 << 4), + FTDM_SPAN_STOP_THREAD = (1 << 5) +} ftdm_span_flag_t; + +typedef enum { + FTDM_CHAN_TYPE_B, + FTDM_CHAN_TYPE_DQ921, + FTDM_CHAN_TYPE_DQ931, + FTDM_CHAN_TYPE_FXS, + FTDM_CHAN_TYPE_FXO, + FTDM_CHAN_TYPE_EM, + FTDM_CHAN_TYPE_CAS, + FTDM_CHAN_TYPE_COUNT +} ftdm_chan_type_t; + +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t) + +typedef enum { + FTDM_CHANNEL_FEATURE_DTMF_DETECT = (1 << 0), + FTDM_CHANNEL_FEATURE_DTMF_GENERATE = (1 << 1), + FTDM_CHANNEL_FEATURE_CODECS = (1 << 2), + FTDM_CHANNEL_FEATURE_INTERVAL = (1 << 3), + FTDM_CHANNEL_FEATURE_CALLERID = (1 << 4), + FTDM_CHANNEL_FEATURE_PROGRESS = (1 << 5) +} ftdm_channel_feature_t; + +typedef enum { + FTDM_CHANNEL_STATE_DOWN, + FTDM_CHANNEL_STATE_HOLD, + FTDM_CHANNEL_STATE_SUSPENDED, + FTDM_CHANNEL_STATE_DIALTONE, + FTDM_CHANNEL_STATE_COLLECT, + FTDM_CHANNEL_STATE_RING, + FTDM_CHANNEL_STATE_BUSY, + FTDM_CHANNEL_STATE_ATTN, + FTDM_CHANNEL_STATE_GENRING, + FTDM_CHANNEL_STATE_DIALING, + FTDM_CHANNEL_STATE_GET_CALLERID, + FTDM_CHANNEL_STATE_CALLWAITING, + FTDM_CHANNEL_STATE_RESTART, + FTDM_CHANNEL_STATE_PROGRESS, + FTDM_CHANNEL_STATE_PROGRESS_MEDIA, + FTDM_CHANNEL_STATE_UP, + FTDM_CHANNEL_STATE_IDLE, + FTDM_CHANNEL_STATE_TERMINATING, + FTDM_CHANNEL_STATE_CANCEL, + FTDM_CHANNEL_STATE_HANGUP, + FTDM_CHANNEL_STATE_HANGUP_COMPLETE, + FTDM_CHANNEL_STATE_INVALID +} ftdm_channel_state_t; +#define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ + "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \ + "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID" +FTDM_STR2ENUM_P(ftdm_str2ftdm_channel_state, ftdm_channel_state2str, ftdm_channel_state_t) + +typedef enum { + FTDM_CHANNEL_CONFIGURED = (1 << 0), + FTDM_CHANNEL_READY = (1 << 1), + FTDM_CHANNEL_OPEN = (1 << 2), + FTDM_CHANNEL_DTMF_DETECT = (1 << 3), + FTDM_CHANNEL_SUPRESS_DTMF = (1 << 4), + FTDM_CHANNEL_TRANSCODE = (1 << 5), + FTDM_CHANNEL_BUFFER = (1 << 6), + FTDM_CHANNEL_EVENT = (1 << 7), + FTDM_CHANNEL_INTHREAD = (1 << 8), + FTDM_CHANNEL_WINK = (1 << 9), + FTDM_CHANNEL_FLASH = (1 << 10), + FTDM_CHANNEL_STATE_CHANGE = (1 << 11), + FTDM_CHANNEL_HOLD = (1 << 12), + FTDM_CHANNEL_INUSE = (1 << 13), + FTDM_CHANNEL_OFFHOOK = (1 << 14), + FTDM_CHANNEL_RINGING = (1 << 15), + FTDM_CHANNEL_PROGRESS_DETECT = (1 << 16), + FTDM_CHANNEL_CALLERID_DETECT = (1 << 17), + FTDM_CHANNEL_OUTBOUND = (1 << 18), + FTDM_CHANNEL_SUSPENDED = (1 << 19), + FTDM_CHANNEL_3WAY = (1 << 20), + FTDM_CHANNEL_PROGRESS = (1 << 21), + FTDM_CHANNEL_MEDIA = (1 << 22), + FTDM_CHANNEL_ANSWERED = (1 << 23), + FTDM_CHANNEL_MUTE = (1 << 24), + FTDM_CHANNEL_USE_RX_GAIN = (1 << 25), + FTDM_CHANNEL_USE_TX_GAIN = (1 << 26), +} ftdm_channel_flag_t; +#if defined(__cplusplus) && defined(WIN32) + // fix C2676 +__inline__ ftdm_channel_flag_t operator|=(ftdm_channel_flag_t a, int32_t b) { + a = (ftdm_channel_flag_t)(a | b); + return a; +} +__inline__ ftdm_channel_flag_t operator&=(ftdm_channel_flag_t a, int32_t b) { + a = (ftdm_channel_flag_t)(a & b); + return a; +} +#endif + +typedef enum { + ZSM_NONE, + ZSM_UNACCEPTABLE, + ZSM_ACCEPTABLE +} ftdm_state_map_type_t; + +typedef enum { + ZSD_INBOUND, + ZSD_OUTBOUND, +} ftdm_state_direction_t; + +#define FTDM_MAP_NODE_SIZE 512 +#define FTDM_MAP_MAX FTDM_CHANNEL_STATE_INVALID+2 + +struct ftdm_state_map_node { + ftdm_state_direction_t direction; + ftdm_state_map_type_t type; + ftdm_channel_state_t check_states[FTDM_MAP_MAX]; + ftdm_channel_state_t states[FTDM_MAP_MAX]; +}; +typedef struct ftdm_state_map_node ftdm_state_map_node_t; + +struct ftdm_state_map { + ftdm_state_map_node_t nodes[FTDM_MAP_NODE_SIZE]; +}; +typedef struct ftdm_state_map ftdm_state_map_t; + +typedef enum ftdm_channel_hw_link_status { + FTDM_HW_LINK_DISCONNECTED = 0, + FTDM_HW_LINK_CONNECTED +} ftdm_channel_hw_link_status_t; + +typedef struct ftdm_conf_parameter_s { + const char *var; + const char *val; +} ftdm_conf_parameter_t; + +typedef struct ftdm_channel ftdm_channel_t; +typedef struct ftdm_event ftdm_event_t; +typedef struct ftdm_sigmsg ftdm_sigmsg_t; +typedef struct ftdm_span ftdm_span_t; +typedef struct ftdm_group ftdm_group_t; +typedef struct ftdm_caller_data ftdm_caller_data_t; +typedef struct ftdm_io_interface ftdm_io_interface_t; + +struct ftdm_stream_handle; +typedef struct ftdm_stream_handle ftdm_stream_handle_t; + +typedef ftdm_status_t (*ftdm_stream_handle_raw_write_function_t) (ftdm_stream_handle_t *handle, uint8_t *data, ftdm_size_t datalen); +typedef ftdm_status_t (*ftdm_stream_handle_write_function_t) (ftdm_stream_handle_t *handle, const char *fmt, ...); + +#define ZIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan) +#define ZIO_CHANNEL_OUTGOING_CALL_ARGS (ftdm_channel_t *ftdmchan) +#define ZIO_CHANNEL_SET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status) +#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status) +#define ZIO_SPAN_SET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status) +#define ZIO_SPAN_GET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t *status) +#define ZIO_SPAN_POLL_EVENT_ARGS (ftdm_span_t *span, uint32_t ms) +#define ZIO_SPAN_NEXT_EVENT_ARGS (ftdm_span_t *span, ftdm_event_t **event) +#define ZIO_SIGNAL_CB_ARGS (ftdm_sigmsg_t *sigmsg) +#define ZIO_EVENT_CB_ARGS (ftdm_channel_t *ftdmchan, ftdm_event_t *event) +#define ZIO_CODEC_ARGS (void *data, ftdm_size_t max, ftdm_size_t *datalen) +#define ZIO_CONFIGURE_SPAN_ARGS (ftdm_span_t *span, const char *str, ftdm_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 (ftdm_channel_t *ftdmchan) +#define ZIO_CLOSE_ARGS (ftdm_channel_t *ftdmchan) +#define ZIO_CHANNEL_DESTROY_ARGS (ftdm_channel_t *ftdmchan) +#define ZIO_SPAN_DESTROY_ARGS (ftdm_span_t *span) +#define ZIO_COMMAND_ARGS (ftdm_channel_t *ftdmchan, ftdm_command_t command, void *obj) +#define ZIO_WAIT_ARGS (ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to) +#define ZIO_GET_ALARMS_ARGS (ftdm_channel_t *ftdmchan) +#define ZIO_READ_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) +#define ZIO_WRITE_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) +#define ZIO_IO_LOAD_ARGS (ftdm_io_interface_t **zio) +#define ZIO_IO_UNLOAD_ARGS (void) +#define ZIO_SIG_LOAD_ARGS (void) +#define ZIO_SIG_CONFIGURE_ARGS (ftdm_span_t *span, zio_signal_cb_t sig_cb, va_list ap) +#define ZIO_CONFIGURE_SPAN_SIGNALING_ARGS (ftdm_span_t *span, zio_signal_cb_t sig_cb, ftdm_conf_parameter_t *ftdm_parameters) +#define ZIO_SIG_UNLOAD_ARGS (void) +#define ZIO_API_ARGS (ftdm_stream_handle_t *stream, const char *data) + +typedef ftdm_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; +typedef ftdm_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ; +typedef ftdm_status_t (*zio_channel_set_sig_status_t) ZIO_CHANNEL_SET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*zio_channel_get_sig_status_t) ZIO_CHANNEL_GET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*zio_span_set_sig_status_t) ZIO_SPAN_SET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*zio_span_get_sig_status_t) ZIO_SPAN_GET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ; +typedef ftdm_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ; +typedef ftdm_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ; +typedef ftdm_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ; +typedef ftdm_status_t (*zio_codec_t) ZIO_CODEC_ARGS ; +typedef ftdm_status_t (*zio_configure_span_t) ZIO_CONFIGURE_SPAN_ARGS ; +typedef ftdm_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ; +typedef ftdm_status_t (*zio_open_t) ZIO_OPEN_ARGS ; +typedef ftdm_status_t (*zio_close_t) ZIO_CLOSE_ARGS ; +typedef ftdm_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_DESTROY_ARGS ; +typedef ftdm_status_t (*zio_span_destroy_t) ZIO_SPAN_DESTROY_ARGS ; +typedef ftdm_status_t (*zio_get_alarms_t) ZIO_GET_ALARMS_ARGS ; +typedef ftdm_status_t (*zio_command_t) ZIO_COMMAND_ARGS ; +typedef ftdm_status_t (*zio_wait_t) ZIO_WAIT_ARGS ; +typedef ftdm_status_t (*zio_read_t) ZIO_READ_ARGS ; +typedef ftdm_status_t (*zio_write_t) ZIO_WRITE_ARGS ; +typedef ftdm_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ; +typedef ftdm_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ; +typedef ftdm_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ; +typedef ftdm_status_t (*zio_configure_span_signaling_t) ZIO_CONFIGURE_SPAN_SIGNALING_ARGS ; +typedef ftdm_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ; +typedef ftdm_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ; +typedef ftdm_status_t (*zio_api_t) ZIO_API_ARGS ; + + +#define ZIO_CHANNEL_REQUEST_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_REQUEST_ARGS +#define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS +#define ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_SET_SIG_STATUS_ARGS +#define ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_GET_SIG_STATUS_ARGS +#define ZIO_SPAN_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_SPAN_SET_SIG_STATUS_ARGS +#define ZIO_SPAN_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_SPAN_GET_SIG_STATUS_ARGS +#define ZIO_SPAN_POLL_EVENT_FUNCTION(name) ftdm_status_t name ZIO_SPAN_POLL_EVENT_ARGS +#define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) ftdm_status_t name ZIO_SPAN_NEXT_EVENT_ARGS +#define ZIO_SIGNAL_CB_FUNCTION(name) ftdm_status_t name ZIO_SIGNAL_CB_ARGS +#define ZIO_EVENT_CB_FUNCTION(name) ftdm_status_t name ZIO_EVENT_CB_ARGS +#define ZIO_CODEC_FUNCTION(name) FT_DECLARE_NONSTD(ftdm_status_t) name ZIO_CODEC_ARGS +#define ZIO_CONFIGURE_SPAN_FUNCTION(name) ftdm_status_t name ZIO_CONFIGURE_SPAN_ARGS +#define ZIO_CONFIGURE_FUNCTION(name) ftdm_status_t name ZIO_CONFIGURE_ARGS +#define ZIO_OPEN_FUNCTION(name) ftdm_status_t name ZIO_OPEN_ARGS +#define ZIO_CLOSE_FUNCTION(name) ftdm_status_t name ZIO_CLOSE_ARGS +#define ZIO_CHANNEL_DESTROY_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_DESTROY_ARGS +#define ZIO_SPAN_DESTROY_FUNCTION(name) ftdm_status_t name ZIO_SPAN_DESTROY_ARGS +#define ZIO_GET_ALARMS_FUNCTION(name) ftdm_status_t name ZIO_GET_ALARMS_ARGS +#define ZIO_COMMAND_FUNCTION(name) ftdm_status_t name ZIO_COMMAND_ARGS +#define ZIO_WAIT_FUNCTION(name) ftdm_status_t name ZIO_WAIT_ARGS +#define ZIO_READ_FUNCTION(name) ftdm_status_t name ZIO_READ_ARGS +#define ZIO_WRITE_FUNCTION(name) ftdm_status_t name ZIO_WRITE_ARGS +#define ZIO_IO_LOAD_FUNCTION(name) ftdm_status_t name ZIO_IO_LOAD_ARGS +#define ZIO_SIG_LOAD_FUNCTION(name) ftdm_status_t name ZIO_SIG_LOAD_ARGS +#define ZIO_SIG_CONFIGURE_FUNCTION(name) ftdm_status_t name ZIO_SIG_CONFIGURE_ARGS +#define ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) ftdm_status_t name ZIO_CONFIGURE_SPAN_SIGNALING_ARGS +#define ZIO_IO_UNLOAD_FUNCTION(name) ftdm_status_t name ZIO_IO_UNLOAD_ARGS +#define ZIO_SIG_UNLOAD_FUNCTION(name) ftdm_status_t name ZIO_SIG_UNLOAD_ARGS +#define ZIO_API_FUNCTION(name) ftdm_status_t name ZIO_API_ARGS + +#include "ftdm_dso.h" + +typedef struct { + char name[256]; + zio_io_load_t io_load; + zio_io_unload_t io_unload; + zio_sig_load_t sig_load; + zio_sig_configure_t sig_configure; + zio_sig_unload_t sig_unload; + /*! + \brief configure a given span signaling + \see sig_configure + This is just like sig_configure but receives + an array of paramters instead of va_list + I'd like to deprecate sig_configure and move + all modules to use sigparam_configure + */ + zio_configure_span_signaling_t configure_span_signaling; + ftdm_dso_lib_t lib; + char path[256]; +} ftdm_module_t; + +#ifndef __FUNCTION__ +#define __FUNCTION__ (const char *)__func__ +#endif + +#define FTDM_PRE __FILE__, __FUNCTION__, __LINE__ +#define FTDM_LOG_LEVEL_DEBUG 7 +#define FTDM_LOG_LEVEL_INFO 6 +#define FTDM_LOG_LEVEL_NOTICE 5 +#define FTDM_LOG_LEVEL_WARNING 4 +#define FTDM_LOG_LEVEL_ERROR 3 +#define FTDM_LOG_LEVEL_CRIT 2 +#define FTDM_LOG_LEVEL_ALERT 1 +#define FTDM_LOG_LEVEL_EMERG 0 + +#define FTDM_LOG_DEBUG FTDM_PRE, FTDM_LOG_LEVEL_DEBUG +#define FTDM_LOG_INFO FTDM_PRE, FTDM_LOG_LEVEL_INFO +#define FTDM_LOG_NOTICE FTDM_PRE, FTDM_LOG_LEVEL_NOTICE +#define FTDM_LOG_WARNING FTDM_PRE, FTDM_LOG_LEVEL_WARNING +#define FTDM_LOG_ERROR FTDM_PRE, FTDM_LOG_LEVEL_ERROR +#define FTDM_LOG_CRIT FTDM_PRE, FTDM_LOG_LEVEL_CRIT +#define FTDM_LOG_ALERT FTDM_PRE, FTDM_LOG_LEVEL_ALERT +#define FTDM_LOG_EMERG FTDM_PRE, FTDM_LOG_LEVEL_EMERG + +typedef struct ftdm_fsk_data_state ftdm_fsk_data_state_t; +typedef int (*ftdm_fsk_data_decoder_t)(ftdm_fsk_data_state_t *state); +typedef ftdm_status_t (*ftdm_fsk_write_sample_t)(int16_t *buf, ftdm_size_t buflen, void *user_data); +typedef void (*ftdm_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...); +typedef struct hashtable ftdm_hash_t; +typedef struct hashtable_iterator ftdm_hash_iterator_t; +typedef struct key ftdm_hash_key_t; +typedef struct value ftdm_hash_val_t; +typedef struct ftdm_bitstream ftdm_bitstream_t; +typedef struct ftdm_fsk_modulator ftdm_fsk_modulator_t; +typedef ftdm_status_t (*ftdm_span_start_t)(ftdm_span_t *span); +typedef ftdm_status_t (*ftdm_span_stop_t)(ftdm_span_t *span); + +typedef enum { + FTDM_CAUSE_NONE = 0, + FTDM_CAUSE_UNALLOCATED = 1, + FTDM_CAUSE_NO_ROUTE_TRANSIT_NET = 2, + FTDM_CAUSE_NO_ROUTE_DESTINATION = 3, + FTDM_CAUSE_CHANNEL_UNACCEPTABLE = 6, + FTDM_CAUSE_CALL_AWARDED_DELIVERED = 7, + FTDM_CAUSE_NORMAL_CLEARING = 16, + FTDM_CAUSE_USER_BUSY = 17, + FTDM_CAUSE_NO_USER_RESPONSE = 18, + FTDM_CAUSE_NO_ANSWER = 19, + FTDM_CAUSE_SUBSCRIBER_ABSENT = 20, + FTDM_CAUSE_CALL_REJECTED = 21, + FTDM_CAUSE_NUMBER_CHANGED = 22, + FTDM_CAUSE_REDIRECTION_TO_NEW_DESTINATION = 23, + FTDM_CAUSE_EXCHANGE_ROUTING_ERROR = 25, + FTDM_CAUSE_DESTINATION_OUT_OF_ORDER = 27, + FTDM_CAUSE_INVALID_NUMBER_FORMAT = 28, + FTDM_CAUSE_FACILITY_REJECTED = 29, + FTDM_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30, + FTDM_CAUSE_NORMAL_UNSPECIFIED = 31, + FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34, + FTDM_CAUSE_NETWORK_OUT_OF_ORDER = 38, + FTDM_CAUSE_NORMAL_TEMPORARY_FAILURE = 41, + FTDM_CAUSE_SWITCH_CONGESTION = 42, + FTDM_CAUSE_ACCESS_INFO_DISCARDED = 43, + FTDM_CAUSE_REQUESTED_CHAN_UNAVAIL = 44, + FTDM_CAUSE_PRE_EMPTED = 45, + FTDM_CAUSE_FACILITY_NOT_SUBSCRIBED = 50, + FTDM_CAUSE_OUTGOING_CALL_BARRED = 52, + FTDM_CAUSE_INCOMING_CALL_BARRED = 54, + FTDM_CAUSE_BEARERCAPABILITY_NOTAUTH = 57, + FTDM_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58, + FTDM_CAUSE_SERVICE_UNAVAILABLE = 63, + FTDM_CAUSE_BEARERCAPABILITY_NOTIMPL = 65, + FTDM_CAUSE_CHAN_NOT_IMPLEMENTED = 66, + FTDM_CAUSE_FACILITY_NOT_IMPLEMENTED = 69, + FTDM_CAUSE_SERVICE_NOT_IMPLEMENTED = 79, + FTDM_CAUSE_INVALID_CALL_REFERENCE = 81, + FTDM_CAUSE_INCOMPATIBLE_DESTINATION = 88, + FTDM_CAUSE_INVALID_MSG_UNSPECIFIED = 95, + FTDM_CAUSE_MANDATORY_IE_MISSING = 96, + FTDM_CAUSE_MESSAGE_TYPE_NONEXIST = 97, + FTDM_CAUSE_WRONG_MESSAGE = 98, + FTDM_CAUSE_IE_NONEXIST = 99, + FTDM_CAUSE_INVALID_IE_CONTENTS = 100, + FTDM_CAUSE_WRONG_CALL_STATE = 101, + FTDM_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102, + FTDM_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103, + FTDM_CAUSE_PROTOCOL_ERROR = 111, + FTDM_CAUSE_INTERWORKING = 127, + FTDM_CAUSE_SUCCESS = 142, + FTDM_CAUSE_ORIGINATOR_CANCEL = 487, + FTDM_CAUSE_CRASH = 500, + FTDM_CAUSE_SYSTEM_SHUTDOWN = 501, + FTDM_CAUSE_LOSE_RACE = 502, + FTDM_CAUSE_MANAGER_REQUEST = 503, + FTDM_CAUSE_BLIND_TRANSFER = 600, + FTDM_CAUSE_ATTENDED_TRANSFER = 601, + FTDM_CAUSE_ALLOTTED_TIMEOUT = 602, + FTDM_CAUSE_USER_CHALLENGE = 603, + FTDM_CAUSE_MEDIA_TIMEOUT = 604 +} ftdm_call_cause_t; + +#ifdef __cplusplus +} +#endif + +#endif + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4: + */ + From 1b47133795d60c5cb99b4c853bc1d73bea51617e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 19:56:54 +0000 Subject: [PATCH 1683/1766] more naming changes git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@971 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 52 +++++++++---------- .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 2 +- .../freetdm/src/ftmod/ftmod_pika/ftmod_pika.c | 2 +- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 2 +- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 16 +++--- libs/freetdm/src/priserver.c | 4 +- libs/freetdm/src/testanalog.c | 8 +-- libs/freetdm/src/testapp.c | 4 +- libs/freetdm/src/testboost.c | 8 +-- libs/freetdm/src/testisdn.c | 6 +-- libs/freetdm/src/testm3ua.c | 6 +-- libs/freetdm/src/testpri.c | 6 +-- libs/freetdm/src/testr2.c | 6 +-- libs/freetdm/src/testsangomaboost.c | 8 +-- 14 files changed, 65 insertions(+), 65 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index f2676ef6c7..849ce09a23 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -27,7 +27,7 @@ * Moises Silva * * - * mod_freetdm.c -- OPENFTDM Endpoint Module + * mod_freetdm.c -- FreeTDM Endpoint Module * */ #include @@ -37,8 +37,8 @@ #define __FUNCTION__ __SWITCH_FUNC__ #endif -#define OPENFTDM_VAR_PREFIX "freetdm_" -#define OPENFTDM_VAR_PREFIX_LEN 8 +#define FREETDM_VAR_PREFIX "freetdm_" +#define FREETDM_VAR_PREFIX_LEN 8 SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_freetdm_shutdown); @@ -1181,8 +1181,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi ftdm_channel_clear_vars(ftdmchan); for (h = var_event->headers; h; h = h->next) { - if (!strncasecmp(h->name, OPENFTDM_VAR_PREFIX, OPENFTDM_VAR_PREFIX_LEN)) { - char *v = h->name + OPENFTDM_VAR_PREFIX_LEN; + if (!strncasecmp(h->name, FREETDM_VAR_PREFIX, FREETDM_VAR_PREFIX_LEN)) { + char *v = h->name + FREETDM_VAR_PREFIX_LEN; if (!zstr(v)) { ftdm_channel_add_var(ftdmchan, v, h->value); } @@ -1204,7 +1204,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } - snprintf(name, sizeof(name), "OpenFTDM/%u:%u/%s", ftdmchan->span_id, ftdmchan->chan_id, dest); + snprintf(name, sizeof(name), "FreeTDM/%u:%u/%s", ftdmchan->span_id, ftdmchan->chan_id, dest); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_variable(channel, "freetdm_span_name", ftdmchan->span->name); @@ -1293,7 +1293,7 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session } tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), - "OpenFTDM", + "FreeTDM", SPAN_CONFIG[sigmsg->channel->span_id].dialplan, sigmsg->channel->caller_data.cid_name, sigmsg->channel->caller_data.cid_num.digits, @@ -1315,7 +1315,7 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); } - snprintf(name, sizeof(name), "OpenFTDM/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number); + snprintf(name, sizeof(name), "FreeTDM/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); @@ -1966,7 +1966,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -1981,7 +1981,7 @@ static switch_status_t load_config(void) "hotline", hotline, "enable_callerid", enable_callerid, TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d\n", span_id); + ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d\n", span_id); continue; } @@ -2081,7 +2081,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2095,7 +2095,7 @@ static switch_status_t load_config(void) "digit_timeout", &to, "max_dialstr", &max, TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d\n", span_id); + ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d\n", span_id); continue; } @@ -2194,7 +2194,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2215,7 +2215,7 @@ static switch_status_t load_config(void) "q921loglevel", q921loglevel, "q931loglevel", q931loglevel, TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d mode: %s dialect: %s error: %s\n", span_id, mode, dialect, span->last_error); + ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d mode: %s dialect: %s error: %s\n", span_id, mode, dialect, span->last_error); continue; } @@ -2291,7 +2291,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2308,7 +2308,7 @@ static switch_status_t load_config(void) "debug", o_debug, "opts", opts, TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d node: %s switch: %s dp: %s l1: %s debug: %s error: %s\n", + ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d node: %s switch: %s dp: %s l1: %s debug: %s error: %s\n", span_id, switch_str_nil(o_node), switch_str_nil(o_switch), switch_str_nil(o_dp), switch_str_nil(o_l1), switch_str_nil(o_debug), span->last_error); continue; @@ -2386,7 +2386,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2395,7 +2395,7 @@ static switch_status_t load_config(void) } if (ftdm_configure_span_signaling("sangoma_boost", span, on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting OpenFTDM span %d error: %s\n", span_id, span->last_error); + ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d error: %s\n", span_id, span->last_error); continue; } @@ -2521,7 +2521,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2548,7 +2548,7 @@ static switch_status_t load_config(void) "mfback_timeout", mfback_timeout, "metering_pulse_timeout", metering_pulse_timeout, TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring R2 OpenFTDM span %d, error: %s\n", + ftdm_log(FTDM_LOG_ERROR, "Error configuring R2 FreeTDM span %d, error: %s\n", span_id, span->last_error); continue; } @@ -2567,7 +2567,7 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span->span_id].type, "r2", sizeof(SPAN_CONFIG[span->span_id].type)); if (ftdm_span_start(span) == FTDM_FAIL) { - ftdm_log(FTDM_LOG_ERROR, "Error starting R2 OpenFTDM span %d, error: %s\n", span_id, span->last_error); + ftdm_log(FTDM_LOG_ERROR, "Error starting R2 FreeTDM span %d, error: %s\n", span_id, span->last_error); continue; } } @@ -2579,7 +2579,7 @@ static switch_status_t load_config(void) boost_span = boost_spans[i]; ftdm_log(FTDM_LOG_DEBUG, "Starting boost span %d\n", boost_span->span_id); if (ftdm_span_start(boost_span) == FTDM_FAIL) { - ftdm_log(FTDM_LOG_ERROR, "Error starting boost OpenFTDM span %d, error: %s\n", boost_span->span_id, boost_span->last_error); + ftdm_log(FTDM_LOG_ERROR, "Error starting boost FreeTDM span %d, error: %s\n", boost_span->span_id, boost_span->last_error); continue; } } @@ -2954,7 +2954,7 @@ SWITCH_STANDARD_APP(disable_ec_function) int x = 0; if (!switch_core_session_check_interface(session, freetdm_endpoint_interface)) { - ftdm_log(FTDM_LOG_ERROR, "This application is only for OpenFTDM channels.\n"); + ftdm_log(FTDM_LOG_ERROR, "This application is only for FreeTDM channels.\n"); return; } @@ -2976,12 +2976,12 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load) ftdm_global_set_logger(ftdm_logger); if (ftdm_global_init() != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error loading OpenFTDM\n"); + ftdm_log(FTDM_LOG_ERROR, "Error loading FreeTDM\n"); return SWITCH_STATUS_TERM; } if (ftdm_global_configuration() != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring OpenFTDM\n"); + ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM\n"); return SWITCH_STATUS_TERM; } @@ -2996,7 +2996,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load) freetdm_endpoint_interface->io_routines = &freetdm_io_routines; freetdm_endpoint_interface->state_handler = &freetdm_state_handlers; - SWITCH_ADD_API(commands_api_interface, "ft", "OpenFTDM commands", ft_function, FT_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "ft", "FreeTDM commands", ft_function, FT_SYNTAX); SWITCH_ADD_APP(app_interface, "disable_ec", "Disable Echo Canceller", "Disable Echo Canceller", disable_ec_function, "", SAF_NONE); diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index 898d606beb..ff878a5a57 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -1025,7 +1025,7 @@ static L3INT ftdm_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) /* * !! HACK ALERT !! * - * Map OpenFTDM channel states to Q.931 states + * Map FreeTDM channel states to Q.931 states */ Q931ie_CallState state; Q931ie_Cause cause; diff --git a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c index 06ea9f1353..740506dba6 100644 --- a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c +++ b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c @@ -524,7 +524,7 @@ static unsigned pika_open_range(ftdm_span_t *span, unsigned boardno, unsigned sp 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; - ftdm_log(FTDM_LOG_INFO, "configuring device b%ds%dc%d as OpenFTDM device %d:%d\n", boardno, spanno, x, chan->span_id, chan->chan_id); + ftdm_log(FTDM_LOG_INFO, "configuring device b%ds%dc%d as FreeTDM device %d:%d\n", boardno, spanno, x, chan->span_id, chan->chan_id); if (profile) { ftdm_log(FTDM_LOG_INFO, "applying config profile %s to device %d:%d\n", profile->name, chan->span_id, chan->chan_id); diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index aebf4735c9..d7e7de8115 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -334,7 +334,7 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start ftdm_copy_string(chan->chan_number, number, sizeof(chan->chan_number)); } configured++; - ftdm_log(FTDM_LOG_INFO, "configuring device s%dc%d as OpenFTDM device %d:%d fd:%d DTMF: %s\n", + ftdm_log(FTDM_LOG_INFO, "configuring device s%dc%d as FreeTDM device %d:%d fd:%d DTMF: %s\n", spanno, x, chan->span_id, chan->chan_id, sockfd, dtmf); } else { diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 46881519cc..65d39ed3ac 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -279,7 +279,7 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f binfo.numbufs = 32; binfo.bufsize = 1024; if (ioctl(sockfd, codes.SET_BUFINFO, &binfo)) { - ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as FreeTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } @@ -341,7 +341,7 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f cc.sigtype = ZT_SIG_CAS; cc.idlebits = cas_bits; if (ioctl(CONTROL_FD, codes.CHANCONFIG, &cc)) { - ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d err:%s", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd, strerror(errno)); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as FreeTDM device %d:%d fd:%d err:%s", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; } @@ -350,7 +350,7 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f if (ftdmchan->type != FTDM_CHAN_TYPE_DQ921 && ftdmchan->type != FTDM_CHAN_TYPE_DQ931) { len = zt_globals.codec_ms * 8; if (ioctl(ftdmchan->sockfd, codes.SET_BLOCKSIZE, &len)) { - ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d err:%s\n", + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as FreeTDM device %d:%d fd:%d err:%s\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd, strerror(errno)); close(sockfd); continue; @@ -365,7 +365,7 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f } if (ioctl(sockfd, codes.GET_PARAMS, &ztp) < 0) { - ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as FreeTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } @@ -376,13 +376,13 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f (ztp.sig_type != ZT_SIG_HDLCFCS) && (ztp.sig_type != ZT_SIG_HARDHDLC) ) { - ftdm_log(FTDM_LOG_ERROR, "Failure configuring device %s as OpenFTDM device %d:%d fd:%d, hardware signaling is not HDLC, fix your Zap/DAHDI configuration!\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); + ftdm_log(FTDM_LOG_ERROR, "Failure configuring device %s as FreeTDM device %d:%d fd:%d, hardware signaling is not HDLC, fix your Zap/DAHDI configuration!\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } } - ftdm_log(FTDM_LOG_INFO, "configuring device %s channel %d as OpenFTDM device %d:%d fd:%d\n", chanpath, x, ftdmchan->span_id, ftdmchan->chan_id, sockfd); + ftdm_log(FTDM_LOG_INFO, "configuring device %s channel %d as FreeTDM device %d:%d fd:%d\n", chanpath, x, ftdmchan->span_id, ftdmchan->chan_id, sockfd); ftdmchan->rate = 8000; ftdmchan->physical_span_id = ztp.span_no; @@ -411,7 +411,7 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f ztp.flash_time = zt_globals.flash_ms; if (ioctl(sockfd, codes.SET_PARAMS, &ztp) < 0) { - ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as FreeTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, sockfd); close(sockfd); continue; } @@ -632,7 +632,7 @@ static ZIO_OPEN_FUNCTION(zt_open) ftdm_log(FTDM_LOG_INFO, "Setting txgain to %f on channel %d\n", zt_globals.txgain, gains.chan_no); if (ioctl(ftdmchan->sockfd, codes.SETGAINS, &gains) < 0) { - ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as OpenFTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); + ftdm_log(FTDM_LOG_ERROR, "failure configuring device %s as FreeTDM device %d:%d fd:%d\n", chanpath, ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); } } diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index a6ca7d5c2f..f8b3817f38 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -282,11 +282,11 @@ int main(int argc, char *argv[]) ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); debug = PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 7b5d3db874..50310e1383 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -85,14 +85,14 @@ int main(int argc, char *argv[]) ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (ftdm_global_init() != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error loading OpenFTDM\n"); + ftdm_log(FTDM_LOG_ERROR, "Error loading FreeTDM\n"); exit(-1); } - ftdm_log(FTDM_LOG_DEBUG, "OpenFTDM loaded\n"); + ftdm_log(FTDM_LOG_DEBUG, "FreeTDM loaded\n"); if (ftdm_span_find(span_id, &span) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding OpenFTDM span\n"); + ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span\n"); goto done; } @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) "max_dialstr", &max_dialstr, TAG_END ) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring OpenFTDM span\n"); + ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM span\n"); goto done; } ftdm_span_start(span); diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index ffc79e047b..0cb2822712 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -10,11 +10,11 @@ int main(int argc, char *argv[]) if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); top: //if (ftdm_channel_open_any("wanpipe", 0, FTDM_TOP_DOWN, &chan) == FTDM_SUCCESS) { diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index 9b68034418..ad7a75d71a 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -31,18 +31,18 @@ int main(int argc, char *argv[]) #endif if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } if (ftdm_global_configuration() != FTDM_SUCCESS) { - fprintf(stderr, "Error configuring OpenFTDM\n"); + fprintf(stderr, "Error configuring FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); if (ftdm_span_find_by_name("wp1", &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding OpenFTDM span %s\n", argv[1]); + fprintf(stderr, "Error finding FreeTDM span %s\n", argv[1]); goto done; } parameters[0].var = "sigmod"; diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index 61eb235e25..a133f995ac 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -27,14 +27,14 @@ int main(int argc, char *argv[]) } if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding OpenFTDM span\n"); + fprintf(stderr, "Error finding FreeTDM span\n"); goto done; } diff --git a/libs/freetdm/src/testm3ua.c b/libs/freetdm/src/testm3ua.c index d66952ce34..63500f6d9a 100644 --- a/libs/freetdm/src/testm3ua.c +++ b/libs/freetdm/src/testm3ua.c @@ -29,14 +29,14 @@ int main(int argc, char *argv[]) } if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding OpenFTDM span\n"); + fprintf(stderr, "Error finding FreeTDM span\n"); goto done; } diff --git a/libs/freetdm/src/testpri.c b/libs/freetdm/src/testpri.c index 542f94e549..5c32adb22f 100644 --- a/libs/freetdm/src/testpri.c +++ b/libs/freetdm/src/testpri.c @@ -104,14 +104,14 @@ int main(int argc, char *argv[]) } if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding OpenFTDM span\n"); + fprintf(stderr, "Error finding FreeTDM span\n"); goto done; } diff --git a/libs/freetdm/src/testr2.c b/libs/freetdm/src/testr2.c index e83004e20e..bcec7eb9d3 100644 --- a/libs/freetdm/src/testr2.c +++ b/libs/freetdm/src/testr2.c @@ -31,14 +31,14 @@ int main(int argc, char *argv[]) } if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding OpenFTDM span\n"); + fprintf(stderr, "Error finding FreeTDM span\n"); goto done; } diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 30733a1770..4c78007097 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -29,19 +29,19 @@ int main(int argc, char *argv[]) } if (ftdm_global_init() != FTDM_SUCCESS) { - fprintf(stderr, "Error loading OpenFTDM\n"); + fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } if (ftdm_global_configuration() != FTDM_SUCCESS) { - fprintf(stderr, "Error configuring OpenFTDM\n"); + fprintf(stderr, "Error configuring FreeTDM\n"); exit(-1); } - printf("OpenFTDM loaded\n"); + printf("FreeTDM loaded\n"); if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding OpenFTDM span\n"); + fprintf(stderr, "Error finding FreeTDM span\n"); goto done; } From a5bd5142da21634885006f83575b4013b970d9f2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 20:08:43 +0000 Subject: [PATCH 1684/1766] more freetdm renaming changes git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@973 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ftmod/ftmod_analog/ftmod_analog.c | 4 +-- .../ftmod/ftmod_analog_em/ftmod_analog_em.c | 4 +-- .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 6 ++-- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 6 ++-- .../freetdm/src/ftmod/ftmod_pika/ftmod_pika.c | 24 ++++++++-------- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 4 +-- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 26 ++++++++--------- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 28 +++++++++---------- 8 files changed, 51 insertions(+), 51 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index 66192108cd..1cc7658263 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -944,7 +944,7 @@ static void *ftdm_analog_run(ftdm_thread_t *me, void *obj) } /** - * \brief Openftdm analog signaling module initialisation + * \brief FreeTDM analog signaling module initialisation * \return Success */ static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_init) @@ -953,7 +953,7 @@ static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_init) } /** - * \brief Openftdm analog signaling module definition + * \brief FreeTDM analog signaling module definition */ EX_DECLARE_DATA ftdm_module_t ftdm_module = { "analog", diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c index 2ff3db0990..3fffd158e4 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c @@ -676,7 +676,7 @@ static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj) } /** - * \brief Openftdm analog EM module initialisation + * \brief FreeTDM analog EM module initialisation * \return Success */ static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_em_init) @@ -685,7 +685,7 @@ static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_em_init) } /** - * \brief Openftdm analog EM module definition + * \brief FreeTDM analog EM module definition */ EX_DECLARE_DATA ftdm_module_t ftdm_module = { "analog_em", diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index ff878a5a57..bf89dbbb4d 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -1505,7 +1505,7 @@ static __inline__ void check_state(ftdm_span_t *span) } /** - * \brief Processes Openftdm event on a span + * \brief Processes FreeTDM event on a span * \param span Span to process event on * \param event Event to process * \return Success or failure @@ -1906,7 +1906,7 @@ static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj) } /** - * \brief Openftdm ISDN signaling module initialisation + * \brief FreeTDM ISDN signaling module initialisation * \return Success */ static ZIO_SIG_LOAD_FUNCTION(ftdm_isdn_init) @@ -2409,7 +2409,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_isdn_configure_span) } /** - * \brief Openftdm ISDN signaling module definition + * \brief FreeTDM ISDN signaling module definition */ EX_DECLARE_DATA ftdm_module_t ftdm_module = { "isdn", diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index 9f6769aca0..6d14f5e474 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -270,7 +270,7 @@ static ZIO_API_FUNCTION(ftdm_libpri_api) /** * \brief Loads libpri IO module - * \param zio Openftdm IO interface + * \param zio FreeTDM IO interface * \return Success */ static ZIO_IO_LOAD_FUNCTION(ftdm_libpri_io_init) @@ -288,7 +288,7 @@ static ZIO_IO_LOAD_FUNCTION(ftdm_libpri_io_init) /** * \brief Loads libpri signaling module - * \param zio Openftdm IO interface + * \param zio FreeTDM IO interface * \return Success */ static ZIO_SIG_LOAD_FUNCTION(ftdm_libpri_init) @@ -1354,7 +1354,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_libpri_configure_span) } /** - * \brief Openftdm libpri signaling and IO module definition + * \brief FreeTDM libpri signaling and IO module definition */ ftdm_module_t ftdm_module = { "libpri", diff --git a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c index 740506dba6..7eba47fe8c 100644 --- a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c +++ b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c @@ -305,14 +305,14 @@ PK_VOID PK_CALLBACK media_out_callback(PKH_TPikaEvent *event) /** * \brief Initialises a range of pika channels - * \param span Openftdm span + * \param span FreeTDM 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 Openftdm channel type - * \param name Openftdm span name - * \param number Openftdm span number + * \param type FreeTDM channel type + * \param name FreeTDM span name + * \param number FreeTDM span number * \param profile Pika channel profile * \return number of spans configured */ @@ -583,11 +583,11 @@ static unsigned pika_open_range(ftdm_span_t *span, unsigned boardno, unsigned sp /** * \brief Initialises an freetdm pika span from a configuration string - * \param span Openftdm span + * \param span FreeTDM span * \param str Configuration string - * \param type Openftdm span type - * \param name Openftdm span name - * \param number Openftdm span number + * \param type FreeTDM span type + * \param name FreeTDM span name + * \param number FreeTDM span number * \return Success or failure */ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) @@ -813,9 +813,9 @@ static ZIO_WRITE_FUNCTION(pika_write) } /** - * \brief Executes an Openftdm command on a Pika channel + * \brief Executes an FreeTDM command on a Pika channel * \param ftdmchan Channel to execute command on - * \param command Openftdm command to execute + * \param command FreeTDM command to execute * \param obj Object (unused) * \return Success or failure */ @@ -1059,7 +1059,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) /** * \brief Retrieves an event from a Pika span * \param span Span to retrieve event from - * \param event Openftdm event to return + * \param event FreeTDM event to return * \return Success or failure */ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) @@ -1280,7 +1280,7 @@ static ftdm_io_interface_t pika_interface; /** * \brief Loads Pika IO module - * \param zio Openftdm IO interface + * \param zio FreeTDM IO interface * \return Success or failure */ static ZIO_IO_LOAD_FUNCTION(pika_init) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 5641086b4d..916e281e20 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -1617,7 +1617,7 @@ end: /** * \brief Loads sangoma boost signaling module - * \param zio Openftdm IO interface + * \param zio FreeTDM IO interface * \return Success */ static ZIO_SIG_LOAD_FUNCTION(ftdm_sangoma_boost_init) @@ -2024,7 +2024,7 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) } /** - * \brief Openftdm sangoma boost signaling module definition + * \brief FreeTDM sangoma boost signaling module definition */ EX_DECLARE_DATA ftdm_module_t ftdm_module = { /*.name =*/ "sangoma_boost", diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index d7e7de8115..46d5e0a859 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -201,13 +201,13 @@ static unsigned char wanpipe_swap_bits(unsigned char cas_bits) /** * \brief Initialises a range of wanpipe channels - * \param span Openftdm span + * \param span FreeTDM span * \param spanno Wanpipe span number * \param start Initial wanpipe channel number * \param end Final wanpipe channel number - * \param type Openftdm channel type - * \param name Openftdm span name - * \param number Openftdm span number + * \param type FreeTDM channel type + * \param name FreeTDM span name + * \param number FreeTDM span number * \param cas_bits CAS bits * \return number of spans configured */ @@ -387,11 +387,11 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) /** * \brief Initialises an freetdm Wanpipe span from a configuration string - * \param span Openftdm span + * \param span FreeTDM span * \param str Configuration string - * \param type Openftdm span type - * \param name Openftdm span name - * \param number Openftdm span number + * \param type FreeTDM span type + * \param name FreeTDM span name + * \param number FreeTDM span number * \return Success or failure */ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) @@ -506,9 +506,9 @@ static ZIO_CLOSE_FUNCTION(wanpipe_close) } /** - * \brief Executes an Openftdm command on a Wanpipe channel + * \brief Executes an FreeTDM command on a Wanpipe channel * \param ftdmchan Channel to execute command on - * \param command Openftdm command to execute + * \param command FreeTDM command to execute * \param obj Object (unused) * \return Success or failure */ @@ -896,7 +896,7 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) /** * \brief Retrieves an event from a wanpipe span * \param span Span to retrieve event from - * \param event Openftdm event to return + * \param event FreeTDM event to return * \return Success or failure */ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) @@ -1083,7 +1083,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) /** * \brief Loads wanpipe IO module - * \param zio Openftdm IO interface + * \param zio FreeTDM IO interface * \return Success */ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) @@ -1125,7 +1125,7 @@ static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) } /** - * \brief Openftdm wanpipe IO module definition + * \brief FreeTDM wanpipe IO module definition */ EX_DECLARE_DATA ftdm_module_t ftdm_module = { "wanpipe", diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 65d39ed3ac..3a1908e2be 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -238,12 +238,12 @@ static void zt_build_gains(struct zt_gains *g, float rxgain, float txgain, int c /** * \brief Initialises a range of ftdmtel channels - * \param span Openftdm span + * \param span FreeTDM span * \param start Initial wanpipe channel number * \param end Final wanpipe channel number - * \param type Openftdm channel type - * \param name Openftdm span name - * \param number Openftdm span number + * \param type FreeTDM channel type + * \param name FreeTDM span name + * \param number FreeTDM span number * \param cas_bits CAS bits * \return number of spans configured */ @@ -435,11 +435,11 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f /** * \brief Initialises an freetdm ftdmtel span from a configuration string - * \param span Openftdm span + * \param span FreeTDM span * \param str Configuration string - * \param type Openftdm span type - * \param name Openftdm span name - * \param number Openftdm span number + * \param type FreeTDM span type + * \param name FreeTDM span name + * \param number FreeTDM span number * \return Success or failure */ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) @@ -662,9 +662,9 @@ static ZIO_CLOSE_FUNCTION(zt_close) } /** - * \brief Executes an Openftdm command on a ftdmtel channel + * \brief Executes an FreeTDM command on a ftdmtel channel * \param ftdmchan Channel to execute command on - * \param command Openftdm command to execute + * \param command FreeTDM command to execute * \param obj Object (unused) * \return Success or failure */ @@ -969,7 +969,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) /** * \brief Retrieves an event from a ftdmtel span * \param span Span to retrieve event from - * \param event Openftdm event to return + * \param event FreeTDM event to return * \return Success or failure */ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) @@ -1141,13 +1141,13 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) } /** - * \brief Global Openftdm IO interface for ftdmtel + * \brief Global FreeTDM IO interface for ftdmtel */ static ftdm_io_interface_t zt_interface; /** * \brief Loads ftdmtel IO module - * \param zio Openftdm IO interface + * \param zio FreeTDM IO interface * \return Success or failure */ static ZIO_IO_LOAD_FUNCTION(zt_init) @@ -1212,7 +1212,7 @@ static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) } /** - * \brief Openftdm ftdmtel IO module definition + * \brief FreeTDM ftdmtel IO module definition */ ftdm_module_t ftdm_module = { "zt", From a8ddece1b685b2bd324f555a52b17ef4a89a7b6a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 20:35:11 +0000 Subject: [PATCH 1685/1766] more freetdm changes git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@974 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 10 +- libs/freetdm/src/ftdm_io.c | 164 +++++++-------- libs/freetdm/src/ftdm_m3ua.c | 28 +-- .../src/ftmod/ftmod_analog/ftdm_analog.h | 2 +- .../src/ftmod/ftmod_analog/ftmod_analog.c | 16 +- .../ftmod/ftmod_analog_em/ftdm_analog_em.h | 2 +- .../ftmod/ftmod_analog_em/ftmod_analog_em.c | 14 +- libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h | 2 +- .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 16 +- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 22 +-- .../src/ftmod/ftmod_libpri/ftmod_libpri.h | 2 +- .../freetdm/src/ftmod/ftmod_pika/ftmod_pika.c | 36 ++-- libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c | 20 +- .../ftmod_sangoma_boost/ftdm_sangoma_boost.h | 2 +- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 20 +- .../freetdm/src/ftmod/ftmod_skel/ftmod_skel.c | 34 ++-- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 38 ++-- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 38 ++-- libs/freetdm/src/include/freetdm.h | 70 +++---- libs/freetdm/src/include/ftdm_m3ua.h | 4 +- libs/freetdm/src/include/ftdm_types.h | 186 +++++++++--------- libs/freetdm/src/priserver.c | 2 +- libs/freetdm/src/testanalog.c | 2 +- libs/freetdm/src/testboost.c | 2 +- libs/freetdm/src/testisdn.c | 2 +- libs/freetdm/src/testm3ua.c | 2 +- libs/freetdm/src/testpri.c | 4 +- libs/freetdm/src/testr2.c | 2 +- libs/freetdm/src/testsangomaboost.c | 2 +- 29 files changed, 372 insertions(+), 372 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 849ce09a23..0e85265ca5 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -1342,7 +1342,7 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session } -static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) +static FIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; @@ -1402,7 +1402,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) return FTDM_SUCCESS; } -static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) +static FIO_SIGNAL_CB_FUNCTION(on_fxs_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; @@ -1609,7 +1609,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) +static FIO_SIGNAL_CB_FUNCTION(on_r2_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; @@ -1709,7 +1709,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) +static FIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; @@ -1795,7 +1795,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) } -static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) +static FIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch_status_t status = SWITCH_STATUS_FALSE; diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index fc2c450288..ce67a4943c 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -311,9 +311,9 @@ static ftdm_status_t ftdm_channel_destroy(ftdm_channel_t *ftdmchan) } - if (ftdmchan->span->zio->channel_destroy) { + if (ftdmchan->span->fio->channel_destroy) { ftdm_log(FTDM_LOG_INFO, "Closing channel %s:%u:%u fd:%d\n", ftdmchan->span->type, ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); - if (ftdmchan->span->zio->channel_destroy(ftdmchan) == FTDM_SUCCESS) { + if (ftdmchan->span->fio->channel_destroy(ftdmchan) == FTDM_SUCCESS) { ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_CONFIGURED); } else { ftdm_log(FTDM_LOG_ERROR, "Error Closing channel %u:%u fd:%d\n", ftdmchan->span_id, ftdmchan->chan_id, ftdmchan->sockfd); @@ -353,9 +353,9 @@ static ftdm_status_t ftdm_span_destroy(ftdm_span_t *span) } /* destroy the I/O for the span */ - if (span->zio && span->zio->span_destroy) { + if (span->fio && span->fio->span_destroy) { ftdm_log(FTDM_LOG_INFO, "Destroying span %u type (%s)\n", span->span_id, span->type); - if (span->zio->span_destroy(span) != FTDM_SUCCESS) { + if (span->fio->span_destroy(span) != FTDM_SUCCESS) { status = FTDM_FAIL; } ftdm_safe_free(span->type); @@ -375,8 +375,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_get_alarms(ftdm_channel_t *ftdmchan) ftdm_status_t status = FTDM_FAIL; if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_CONFIGURED)) { - if (ftdmchan->span->zio->get_alarms) { - if ((status = ftdmchan->span->zio->get_alarms(ftdmchan)) == FTDM_SUCCESS) { + if (ftdmchan->span->fio->get_alarms) { + if ((status = ftdmchan->span->fio->get_alarms(ftdmchan)) == FTDM_SUCCESS) { *ftdmchan->last_error = '\0'; if (ftdm_test_alarm_flag(ftdmchan, FTDM_ALARM_RED)) { snprintf(ftdmchan->last_error + strlen(ftdmchan->last_error), sizeof(ftdmchan->last_error) - strlen(ftdmchan->last_error), "RED/"); @@ -452,12 +452,12 @@ FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span) return FTDM_FAIL; } -FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *zio, ftdm_span_t **span, const char *name) +FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *fio, ftdm_span_t **span, const char *name) { ftdm_span_t *new_span = NULL; ftdm_status_t status = FTDM_FAIL; - assert(zio != NULL); + assert(fio != NULL); ftdm_mutex_lock(globals.mutex); @@ -470,7 +470,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *zio, ftdm_span_t ftdm_set_flag(new_span, FTDM_SPAN_CONFIGURED); new_span->span_id = ++globals.span_index; - new_span->zio = zio; + new_span->fio = fio; ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_DIAL], "%(1000,0,350,440)", FTDM_TONEMAP_LEN); ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_RING], "%(2000,4000,440,480)", FTDM_TONEMAP_LEN); ftdm_copy_string(new_span->tone_map[FTDM_TONEMAP_BUSY], "%(500,500,480,620)", FTDM_TONEMAP_LEN); @@ -650,7 +650,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t new_chan->type = type; new_chan->sockfd = sockfd; - new_chan->zio = span->zio; + new_chan->fio = span->fio; new_chan->span_id = span->span_id; new_chan->chan_id = span->chan_count; new_chan->span = span; @@ -737,7 +737,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_find(uint32_t id, ftdm_span_t **span) } -FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, zio_event_cb_t event_callback) +FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, fio_event_cb_t event_callback) { ftdm_mutex_lock(span->mutex); span->event_callback = event_callback; @@ -748,12 +748,12 @@ FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, zio_ev FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms) { - assert(span->zio != NULL); + assert(span->fio != NULL); - if (span->zio->poll_event) { - return span->zio->poll_event(span, ms); + if (span->fio->poll_event) { + return span->fio->poll_event(span, ms); } else { - ftdm_log(FTDM_LOG_ERROR, "poll_event method not implemented in module %s!", span->zio->name); + ftdm_log(FTDM_LOG_ERROR, "poll_event method not implemented in module %s!", span->fio->name); } return FTDM_NOTIMPL; @@ -761,12 +761,12 @@ FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms) FT_DECLARE(ftdm_status_t) ftdm_span_next_event(ftdm_span_t *span, ftdm_event_t **event) { - assert(span->zio != NULL); + assert(span->fio != NULL); - if (span->zio->next_event) { - return span->zio->next_event(span, event); + if (span->fio->next_event) { + return span->fio->next_event(span, event); } else { - ftdm_log(FTDM_LOG_ERROR, "next_event method not implemented in module %s!", span->zio->name); + ftdm_log(FTDM_LOG_ERROR, "next_event method not implemented in module %s!", span->fio->name); } return FTDM_NOTIMPL; @@ -802,7 +802,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_send_fsk_data(ftdm_channel_t *ftdmchan, f } -FT_DECLARE(ftdm_status_t) ftdm_channel_set_event_callback(ftdm_channel_t *ftdmchan, zio_event_cb_t event_callback) +FT_DECLARE(ftdm_status_t) ftdm_channel_set_event_callback(ftdm_channel_t *ftdmchan, fio_event_cb_t event_callback) { ftdm_mutex_lock(ftdmchan->mutex); ftdmchan->event_callback = event_callback; @@ -1153,7 +1153,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir break; } - status = check->zio->open(check); + status = check->fio->open(check); if (status == FTDM_SUCCESS) { ftdm_set_flag(check, FTDM_CHANNEL_INUSE); @@ -1271,7 +1271,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc break; } - status = check->zio->open(check); + status = check->fio->open(check); if (status == FTDM_SUCCESS) { ftdm_set_flag(check, FTDM_CHANNEL_INUSE); @@ -1365,7 +1365,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan) status = FTDM_FAIL; if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY)) { - status = ftdmchan->span->zio->open(ftdmchan); + status = ftdmchan->span->fio->open(ftdmchan); if (status == FTDM_SUCCESS) { ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OPEN | FTDM_CHANNEL_INUSE); } @@ -1415,7 +1415,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && (!ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || (check->type == FTDM_CHAN_TYPE_FXS && check->token_count == 1))) { if (!ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) { - status = check->zio->open(check); + status = check->fio->open(check); if (status == FTDM_SUCCESS) { ftdm_set_flag(check, FTDM_CHANNEL_OPEN); } @@ -1571,7 +1571,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_close(ftdm_channel_t **ftdmchan) if (ftdm_test_flag(check, FTDM_CHANNEL_CONFIGURED)) { ftdm_mutex_lock(check->mutex); if (ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) { - status = check->zio->close(check); + status = check->fio->close(check); if (status == FTDM_SUCCESS) { ftdm_clear_flag(check, FTDM_CHANNEL_INUSE); ftdm_channel_reset(check); @@ -1623,7 +1623,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co ftdm_status_t status = FTDM_FAIL; assert(ftdmchan != NULL); - assert(ftdmchan->zio != NULL); + assert(ftdmchan->fio != NULL); ftdm_mutex_lock(ftdmchan->mutex); @@ -1930,13 +1930,13 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co break; } - if (!ftdmchan->zio->command) { + if (!ftdmchan->fio->command) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); ftdm_log(FTDM_LOG_ERROR, "no command function defined by the I/O freetdm module!\n"); GOTO_STATUS(done, FTDM_FAIL); } - status = ftdmchan->zio->command(ftdmchan, command, obj); + status = ftdmchan->fio->command(ftdmchan, command, obj); if (status == FTDM_NOTIMPL) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "I/O command %d not implemented in backend", command); @@ -1951,24 +1951,24 @@ done: FT_DECLARE(ftdm_status_t) ftdm_channel_wait(ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to) { assert(ftdmchan != NULL); - assert(ftdmchan->zio != NULL); + assert(ftdmchan->fio != NULL); if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); return FTDM_FAIL; } - if (!ftdmchan->zio->wait) { + if (!ftdmchan->fio->wait) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); return FTDM_FAIL; } - return ftdmchan->zio->wait(ftdmchan, flags, to); + return ftdmchan->fio->wait(ftdmchan, flags, to); } /*******************************/ -ZIO_CODEC_FUNCTION(zio_slin2ulaw) +FIO_CODEC_FUNCTION(fio_slin2ulaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; @@ -1992,7 +1992,7 @@ ZIO_CODEC_FUNCTION(zio_slin2ulaw) } -ZIO_CODEC_FUNCTION(zio_ulaw2slin) +FIO_CODEC_FUNCTION(fio_ulaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; @@ -2014,7 +2014,7 @@ ZIO_CODEC_FUNCTION(zio_ulaw2slin) return FTDM_SUCCESS; } -ZIO_CODEC_FUNCTION(zio_slin2alaw) +FIO_CODEC_FUNCTION(fio_slin2alaw) { int16_t sln_buf[512] = {0}, *sln = sln_buf; uint8_t *lp = data; @@ -2038,7 +2038,7 @@ ZIO_CODEC_FUNCTION(zio_slin2alaw) } -ZIO_CODEC_FUNCTION(zio_alaw2slin) +FIO_CODEC_FUNCTION(fio_alaw2slin) { int16_t *sln = data; uint8_t law[1024] = {0}, *lp = law; @@ -2060,7 +2060,7 @@ ZIO_CODEC_FUNCTION(zio_alaw2slin) return FTDM_SUCCESS; } -ZIO_CODEC_FUNCTION(zio_ulaw2alaw) +FIO_CODEC_FUNCTION(fio_ulaw2alaw) { ftdm_size_t len = *datalen; uint32_t i; @@ -2078,7 +2078,7 @@ ZIO_CODEC_FUNCTION(zio_ulaw2alaw) return FTDM_SUCCESS; } -ZIO_CODEC_FUNCTION(zio_alaw2ulaw) +FIO_CODEC_FUNCTION(fio_alaw2ulaw) { ftdm_size_t len = *datalen; uint32_t i; @@ -2263,13 +2263,13 @@ static ftdm_status_t handle_dtmf(ftdm_channel_t *ftdmchan, ftdm_size_t datalen) if (ftdmchan->native_codec != FTDM_CODEC_SLIN) { if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { - zio_slin2ulaw(auxbuf, max, &dlen); + fio_slin2ulaw(auxbuf, max, &dlen); } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { - zio_slin2alaw(auxbuf, max, &dlen); + fio_slin2alaw(auxbuf, max, &dlen); } } - return ftdmchan->zio->write(ftdmchan, auxbuf, &dlen); + return ftdmchan->fio->write(ftdmchan, auxbuf, &dlen); } return FTDM_SUCCESS; @@ -2303,24 +2303,24 @@ FT_DECLARE(void) ftdm_generate_sln_silence(int16_t *data, uint32_t samples, uint FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) { ftdm_status_t status = FTDM_FAIL; - zio_codec_t codec_func = NULL; + fio_codec_t codec_func = NULL; ftdm_size_t max = *datalen; unsigned i = 0; assert(ftdmchan != NULL); - assert(ftdmchan->zio != NULL); + assert(ftdmchan->fio != NULL); if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); return FTDM_FAIL; } - if (!ftdmchan->zio->read) { + if (!ftdmchan->fio->read) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); return FTDM_FAIL; } - status = ftdmchan->zio->read(ftdmchan, data, datalen); + status = ftdmchan->fio->read(ftdmchan, data, datalen); if (ftdmchan->fds[0] > -1) { int dlen = (int) *datalen; if (write(ftdmchan->fds[0], data, dlen) != dlen) { @@ -2342,13 +2342,13 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data if (status == FTDM_SUCCESS && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE) && ftdmchan->effective_codec != ftdmchan->native_codec) { if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { - codec_func = zio_ulaw2slin; + codec_func = fio_ulaw2slin; } else if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_ALAW) { - codec_func = zio_ulaw2alaw; + codec_func = fio_ulaw2alaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { - codec_func = zio_alaw2slin; + codec_func = fio_alaw2slin; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_ULAW) { - codec_func = zio_alaw2ulaw; + codec_func = fio_alaw2ulaw; } if (codec_func) { @@ -2469,7 +2469,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data teletone_dtmf_get(&ftdmchan->dtmf_detect, digit_str, sizeof(digit_str)); if(*digit_str) { - zio_event_cb_t event_callback = NULL; + fio_event_cb_t event_callback = NULL; if (ftdmchan->state == FTDM_CHANNEL_STATE_CALLWAITING && (*digit_str == 'D' || *digit_str == 'A')) { ftdmchan->detected_tones[FTDM_TONEMAP_CALLWAITING_ACK]++; @@ -2533,12 +2533,12 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t datasize, ftdm_size_t *datalen) { ftdm_status_t status = FTDM_FAIL; - zio_codec_t codec_func = NULL; + fio_codec_t codec_func = NULL; ftdm_size_t max = datasize; unsigned int i = 0; assert(ftdmchan != NULL); - assert(ftdmchan->zio != NULL); + assert(ftdmchan->fio != NULL); if (!ftdmchan->buffer_delay && ((ftdmchan->dtmf_buffer && ftdm_buffer_inuse(ftdmchan->dtmf_buffer)) || @@ -2553,20 +2553,20 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *dat return FTDM_FAIL; } - if (!ftdmchan->zio->write) { + if (!ftdmchan->fio->write) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); return FTDM_FAIL; } if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_TRANSCODE) && ftdmchan->effective_codec != ftdmchan->native_codec) { if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { - codec_func = zio_slin2ulaw; + codec_func = fio_slin2ulaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ULAW && ftdmchan->effective_codec == FTDM_CODEC_ALAW) { - codec_func = zio_alaw2ulaw; + codec_func = fio_alaw2ulaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_SLIN) { - codec_func = zio_slin2alaw; + codec_func = fio_slin2alaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW && ftdmchan->effective_codec == FTDM_CODEC_ULAW) { - codec_func = zio_ulaw2alaw; + codec_func = fio_ulaw2alaw; } if (codec_func) { @@ -2592,7 +2592,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *dat wdata[i] = ftdmchan->txgain_table[wdata[i]]; } } - status = ftdmchan->zio->write(ftdmchan, data, datalen); + status = ftdmchan->fio->write(ftdmchan, data, datalen); return status; } @@ -2644,7 +2644,7 @@ static struct { FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd) { - ftdm_io_interface_t *zio = NULL; + ftdm_io_interface_t *fio = NULL; char *dup = NULL, *p; char *rval = NULL; @@ -2659,19 +2659,19 @@ FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd) } ftdm_mutex_lock(globals.mutex); - if (!(zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + if (!(fio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { ftdm_load_module_assume(type); - if ((zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { + if ((fio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, (void *)type))) { ftdm_log(FTDM_LOG_INFO, "auto-loaded '%s'\n", type); } } ftdm_mutex_unlock(globals.mutex); - if (zio && zio->api) { + if (fio && fio->api) { ftdm_stream_handle_t stream = { 0 }; ftdm_status_t status; FTDM_STANDARD_STREAM(stream); - status = zio->api(&stream, cmd); + status = fio->api(&stream, cmd); if (status != FTDM_SUCCESS) { ftdm_safe_free(stream.data); @@ -2697,7 +2697,7 @@ static ftdm_status_t load_config(void) char name[80] = ""; char number[25] = ""; char group_name[80] = "default"; - ftdm_io_interface_t *zio = NULL; + ftdm_io_interface_t *fio = NULL; ftdm_analog_start_type_t tmp; ftdm_size_t len = 0; @@ -2734,27 +2734,27 @@ static ftdm_status_t load_config(void) } ftdm_mutex_lock(globals.mutex); - if (!(zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + if (!(fio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, type))) { ftdm_load_module_assume(type); - if ((zio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, type))) { + if ((fio = (ftdm_io_interface_t *) hashtable_search(globals.interface_hash, type))) { ftdm_log(FTDM_LOG_INFO, "auto-loaded '%s'\n", type); } } ftdm_mutex_unlock(globals.mutex); - if (!zio) { + if (!fio) { ftdm_log(FTDM_LOG_CRIT, "failure creating span, no such type '%s'\n", type); span = NULL; continue; } - if (!zio->configure_span) { + if (!fio->configure_span) { ftdm_log(FTDM_LOG_CRIT, "failure creating span, no configure_span method for '%s'\n", type); span = NULL; continue; } - if (ftdm_span_create(zio, &span, name) == FTDM_SUCCESS) { + if (ftdm_span_create(fio, &span, name) == FTDM_SUCCESS) { span->type = ftdm_strdup(type); d = 0; @@ -2804,7 +2804,7 @@ static ftdm_status_t load_config(void) ftdm_analog_start_type2str(span->start_type)); } if (span->trunk_type == FTDM_TRUNK_FXO) { - configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_FXO, name, number); + configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_FXO, name, number); } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); } @@ -2815,7 +2815,7 @@ static ftdm_status_t load_config(void) ftdm_analog_start_type2str(span->start_type)); } if (span->trunk_type == FTDM_TRUNK_FXS) { - configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_FXS, name, number); + configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_FXS, name, number); } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } @@ -2826,12 +2826,12 @@ static ftdm_status_t load_config(void) ftdm_analog_start_type2str(span->start_type)); } if (span->trunk_type == FTDM_TRUNK_EM) { - configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_EM, name, number); + configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_EM, name, number); } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); } } else if (!strcasecmp(var, "b-channel")) { - configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_B, name, number); + configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_B, name, number); ftdm_group_add_channels(group_name, span, val); } else if (!strcasecmp(var, "d-channel")) { if (d) { @@ -2844,11 +2844,11 @@ static ftdm_status_t load_config(void) } else { qtype = FTDM_CHAN_TYPE_DQ921; } - configured += zio->configure_span(span, val, qtype, name, number); + configured += fio->configure_span(span, val, qtype, name, number); d++; } } else if (!strcasecmp(var, "cas-channel")) { - configured += zio->configure_span(span, val, FTDM_CHAN_TYPE_CAS, name, number); + configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_CAS, name, number); } else if (!strcasecmp(var, "dtmf_hangup")) { span->dtmf_hangup = ftdm_strdup(val); span->dtmf_hangup_len = strlen(val); @@ -2874,18 +2874,18 @@ static ftdm_status_t load_config(void) return configured ? FTDM_SUCCESS : FTDM_FAIL; } -static ftdm_status_t process_module_config(ftdm_io_interface_t *zio) +static ftdm_status_t process_module_config(ftdm_io_interface_t *fio) { ftdm_config_t cfg; char *var, *val; char filename[256] = ""; - ftdm_assert_return(zio != NULL, FTDM_FAIL, "zio argument is null\n"); + ftdm_assert_return(fio != NULL, FTDM_FAIL, "fio argument is null\n"); - snprintf(filename, sizeof(filename), "%s.conf", zio->name); + snprintf(filename, sizeof(filename), "%s.conf", fio->name); - if (!zio->configure) { - ftdm_log(FTDM_LOG_DEBUG, "Module %s does not support configuration.\n", zio->name); + if (!fio->configure) { + ftdm_log(FTDM_LOG_DEBUG, "Module %s does not support configuration.\n", fio->name); return FTDM_FAIL; } @@ -2895,7 +2895,7 @@ static ftdm_status_t process_module_config(ftdm_io_interface_t *zio) } while (ftdm_config_next_pair(&cfg, &var, &val)) { - zio->configure(cfg.category, var, val, cfg.lineno); + fio->configure(cfg.category, var, val, cfg.lineno); } ftdm_config_close_file(&cfg); @@ -3085,7 +3085,7 @@ FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void) return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ...) +FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ...) { ftdm_module_t *mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type); ftdm_status_t status = FTDM_FAIL; @@ -3110,7 +3110,7 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *spa return status; } -FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters) +FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters) { ftdm_module_t *mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type); ftdm_status_t status = FTDM_FAIL; diff --git a/libs/freetdm/src/ftdm_m3ua.c b/libs/freetdm/src/ftdm_m3ua.c index bb1f06b5e0..31f4cd5c5e 100644 --- a/libs/freetdm/src/ftdm_m3ua.c +++ b/libs/freetdm/src/ftdm_m3ua.c @@ -392,7 +392,7 @@ static int parse_ss7_event(ftdm_span_t *span, m3uac_connection_t *mcon, m3uac_ev return 0; } -static ZIO_CONFIGURE_FUNCTION(m3ua_configure) +static FIO_CONFIGURE_FUNCTION(m3ua_configure) { m3ua_channel_profile_t *profile = NULL; @@ -424,65 +424,65 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) return FTDM_SUCCESS; } -static ZIO_CONFIGURE_SPAN_FUNCTION(m3ua_configure_span) +static FIO_CONFIGURE_SPAN_FUNCTION(m3ua_configure_span) { return FTDM_FAIL; } -static ZIO_OPEN_FUNCTION(m3ua_open) +static FIO_OPEN_FUNCTION(m3ua_open) { return FTDM_FAIL; } -static ZIO_CLOSE_FUNCTION(m3ua_close) +static FIO_CLOSE_FUNCTION(m3ua_close) { return FTDM_FAIL; } -/*static ZIO_SET_INTERVAL_FUNCTION(m3ua_set_interval) +/*static FIO_SET_INTERVAL_FUNCTION(m3ua_set_interval) { return 0; }*/ -static ZIO_WAIT_FUNCTION(m3ua_wait) +static FIO_WAIT_FUNCTION(m3ua_wait) { return FTDM_FAIL; } -static ZIO_READ_FUNCTION(m3ua_read) +static FIO_READ_FUNCTION(m3ua_read) { return FTDM_FAIL; } -static ZIO_WRITE_FUNCTION(m3ua_write) +static FIO_WRITE_FUNCTION(m3ua_write) { return FTDM_FAIL; } -static ZIO_COMMAND_FUNCTION(m3ua_command) +static FIO_COMMAND_FUNCTION(m3ua_command) { return FTDM_FAIL; } -static ZIO_SPAN_POLL_EVENT_FUNCTION(m3ua_poll_event) +static FIO_SPAN_POLL_EVENT_FUNCTION(m3ua_poll_event) { return FTDM_FAIL; } -static ZIO_SPAN_NEXT_EVENT_FUNCTION(m3ua_next_event) +static FIO_SPAN_NEXT_EVENT_FUNCTION(m3ua_next_event) { return FTDM_FAIL; } -static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) +static FIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) { m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data; @@ -492,7 +492,7 @@ static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy) return FTDM_SUCCESS; } -static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) +static FIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) { m3ua_chan_data_t *chan_data = (m3ua_chan_data_t *) ftdmchan->mod_data; m3ua_span_data_t *span_data = (m3ua_span_data_t *) ftdmchan->span->mod_data; @@ -522,7 +522,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy) -static ZIO_GET_ALARMS_FUNCTION(m3ua_get_alarms) +static FIO_GET_ALARMS_FUNCTION(m3ua_get_alarms) { return FTDM_FAIL; } diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h index 8e1fa7a721..4b9f02e16c 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h @@ -48,7 +48,7 @@ struct ftdm_analog_data { uint32_t max_dialstr; uint32_t digit_timeout; char hotline[FTDM_MAX_HOTLINE_STR]; - zio_signal_cb_t sig_cb; + fio_signal_cb_t sig_cb; }; diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index 1cc7658263..feb4d5cbdf 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -47,7 +47,7 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj); * * 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) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) { if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { ftdm_channel_clear_needed_tones(ftdmchan); @@ -71,7 +71,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call) * * 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) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxs_outgoing_call) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { @@ -103,8 +103,8 @@ static ftdm_status_t ftdm_analog_start(ftdm_span_t *span) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_configure_span) -//ftdm_status_t ftdm_analog_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb) +static FIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_configure_span) +//ftdm_status_t ftdm_analog_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, fio_signal_cb_t sig_cb) { ftdm_analog_data_t *analog_data; const char *tonemap = "us"; @@ -715,12 +715,12 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) rlen = ftdm_buffer_read_loop(dt_buffer, frame, len); if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { - zio_codec_t codec_func = NULL; + fio_codec_t codec_func = NULL; if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { - codec_func = zio_slin2ulaw; + codec_func = fio_slin2ulaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { - codec_func = zio_slin2alaw; + codec_func = fio_slin2alaw; } if (codec_func) { @@ -947,7 +947,7 @@ static void *ftdm_analog_run(ftdm_thread_t *me, void *obj) * \brief FreeTDM analog signaling module initialisation * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_init) +static FIO_SIG_LOAD_FUNCTION(ftdm_analog_init) { return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h b/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h index fbb268ae1d..353ea108d6 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h @@ -51,7 +51,7 @@ struct ftdm_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; - zio_signal_cb_t sig_cb; + fio_signal_cb_t sig_cb; }; static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj); diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c index 3fffd158e4..edadc25222 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c @@ -52,7 +52,7 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj); * * 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) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_em_outgoing_call) { if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK) && !ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INTHREAD)) { ftdm_channel_clear_needed_tones(ftdmchan); @@ -89,8 +89,8 @@ static ftdm_status_t ftdm_analog_em_start(ftdm_span_t *span) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_em_configure_span) -//ftdm_status_t ftdm_analog_em_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, zio_signal_cb_t sig_cb) +static FIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_em_configure_span) +//ftdm_status_t ftdm_analog_em_configure_span(ftdm_span_t *span, char *tonemap, uint32_t digit_timeout, uint32_t max_dialstr, fio_signal_cb_t sig_cb) { ftdm_analog_em_data_t *analog_data; const char *tonemap = "us"; @@ -519,12 +519,12 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) rlen = ftdm_buffer_read_loop(dt_buffer, frame, len); if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { - zio_codec_t codec_func = NULL; + fio_codec_t codec_func = NULL; if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { - codec_func = zio_slin2ulaw; + codec_func = fio_slin2ulaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { - codec_func = zio_slin2alaw; + codec_func = fio_slin2alaw; } if (codec_func) { @@ -679,7 +679,7 @@ static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj) * \brief FreeTDM analog EM module initialisation * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(ftdm_analog_em_init) +static FIO_SIG_LOAD_FUNCTION(ftdm_analog_em_init) { return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h b/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h index c3b44bec5a..d550f01557 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h @@ -60,7 +60,7 @@ struct ftdm_isdn_data { ftdm_channel_t *dchan; ftdm_channel_t *dchans[2]; struct ftdm_sigmsg sigmsg; - zio_signal_cb_t sig_cb; + fio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; int32_t digit_timeout; diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index bf89dbbb4d..fa9e176972 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -266,7 +266,7 @@ static ftdm_status_t writeQ931PacketToPcap(L3UCHAR* q931buf, L3USHORT q931size, * \brief Unloads pcap IO * \return Success or failure */ -static ZIO_IO_UNLOAD_FUNCTION(close_pcap) +static FIO_IO_UNLOAD_FUNCTION(close_pcap) { #ifdef HAVE_LIBPCAP return closePcapFile(); @@ -292,7 +292,7 @@ static L2ULONG ftdm_time_now(void) * \param ftdmchan Channel to initiate call on * \return Success or failure */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) { ftdm_status_t status = FTDM_SUCCESS; ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); @@ -309,7 +309,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) * \param ftdmchan Channel to initialise * \return Success or failure */ -static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) +static FIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) { Q931mes_Generic *gen = (Q931mes_Generic *) caller_data->raw_data; Q931ie_BearerCap BearerCap; @@ -1767,12 +1767,12 @@ static void *ftdm_isdn_tones_run(ftdm_thread_t *me, void *obj) rlen = ftdm_buffer_read_loop(dt_buffer, frame, len); if (ftdmchan->effective_codec != FTDM_CODEC_SLIN) { - zio_codec_t codec_func = NULL; + fio_codec_t codec_func = NULL; if (ftdmchan->native_codec == FTDM_CODEC_ULAW) { - codec_func = zio_slin2ulaw; + codec_func = fio_slin2ulaw; } else if (ftdmchan->native_codec == FTDM_CODEC_ALAW) { - codec_func = zio_slin2alaw; + codec_func = fio_slin2alaw; } if (codec_func) { @@ -1909,7 +1909,7 @@ static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj) * \brief FreeTDM ISDN signaling module initialisation * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(ftdm_isdn_init) +static FIO_SIG_LOAD_FUNCTION(ftdm_isdn_init) { Q931Initialize(); @@ -2198,7 +2198,7 @@ static uint32_t parse_opts(const char *in) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_isdn_configure_span) +static FIO_SIG_CONFIGURE_FUNCTION(ftdm_isdn_configure_span) { uint32_t i, x = 0; ftdm_channel_t *dchans[2] = {0}; diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index 6d14f5e474..c8189d91c1 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -38,7 +38,7 @@ * \brief Unloads libpri IO module * \return Success */ -static ZIO_IO_UNLOAD_FUNCTION(ftdm_libpri_unload) +static FIO_IO_UNLOAD_FUNCTION(ftdm_libpri_unload) { return FTDM_SUCCESS; } @@ -48,7 +48,7 @@ static ZIO_IO_UNLOAD_FUNCTION(ftdm_libpri_unload) * \param ftdmchan Channel to initiate call on * \return Success or failure */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) { ftdm_status_t status = FTDM_SUCCESS; ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); @@ -65,7 +65,7 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) * \param ftdmchan Channel to initialise (unused) * \return Failure */ -static ZIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) +static FIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) { return FTDM_FAIL; } @@ -204,7 +204,7 @@ static ftdm_status_t ftdm_libpri_start(ftdm_span_t *span); * \param data String containing argurments * \return Flags */ -static ZIO_API_FUNCTION(ftdm_libpri_api) +static FIO_API_FUNCTION(ftdm_libpri_api) { char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; @@ -270,28 +270,28 @@ static ZIO_API_FUNCTION(ftdm_libpri_api) /** * \brief Loads libpri IO module - * \param zio FreeTDM IO interface + * \param fio FreeTDM IO interface * \return Success */ -static ZIO_IO_LOAD_FUNCTION(ftdm_libpri_io_init) +static FIO_IO_LOAD_FUNCTION(ftdm_libpri_io_init) { - assert(zio != NULL); + assert(fio != NULL); memset(&ftdm_libpri_interface, 0, sizeof(ftdm_libpri_interface)); ftdm_libpri_interface.name = "libpri"; ftdm_libpri_interface.api = ftdm_libpri_api; - *zio = &ftdm_libpri_interface; + *fio = &ftdm_libpri_interface; return FTDM_SUCCESS; } /** * \brief Loads libpri signaling module - * \param zio FreeTDM IO interface + * \param fio FreeTDM IO interface * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(ftdm_libpri_init) +static FIO_SIG_LOAD_FUNCTION(ftdm_libpri_init) { pri_set_error(s_pri_error); pri_set_message(s_pri_message); @@ -1237,7 +1237,7 @@ static int str2dp(char *dp) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_libpri_configure_span) +static FIO_SIG_CONFIGURE_FUNCTION(ftdm_libpri_configure_span) { uint32_t i, x = 0; //ftdm_channel_t *dchans[2] = {0}; diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h index 3038624481..534bd9896b 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h @@ -55,7 +55,7 @@ struct ftdm_libpri_data { ftdm_channel_t *dchan; ftdm_channel_t *dchans[2]; struct ftdm_sigmsg sigmsg; - zio_signal_cb_t sig_cb; + fio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; ftdm_isdn_opts_t opts; diff --git a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c index 7eba47fe8c..f20cbc53a7 100644 --- a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c +++ b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.c @@ -150,7 +150,7 @@ static const char *pika_board_type_string(PK_UINT type) * \param lineno Line number from configuration file (unused) * \return Success */ -static ZIO_CONFIGURE_FUNCTION(pika_configure) +static FIO_CONFIGURE_FUNCTION(pika_configure) { pika_channel_profile_t *profile = NULL; int ok = 1; @@ -590,7 +590,7 @@ static unsigned pika_open_range(ftdm_span_t *span, unsigned boardno, unsigned sp * \param number FreeTDM span number * \return Success or failure */ -static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) +static FIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) { int items, i; char *mydata, *item_list[10]; @@ -678,7 +678,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span) * \param ftdmchan Channel to open * \return Success or failure */ -static ZIO_OPEN_FUNCTION(pika_open) +static FIO_OPEN_FUNCTION(pika_open) { pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; @@ -701,7 +701,7 @@ static ZIO_OPEN_FUNCTION(pika_open) * \param ftdmchan Channel to close * \return Success */ -static ZIO_CLOSE_FUNCTION(pika_close) +static FIO_CLOSE_FUNCTION(pika_close) { return FTDM_SUCCESS; } @@ -713,7 +713,7 @@ static ZIO_CLOSE_FUNCTION(pika_close) * \param to Time to wait (in ms) * \return Success, failure or timeout */ -static ZIO_WAIT_FUNCTION(pika_wait) +static FIO_WAIT_FUNCTION(pika_wait) { pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; PK_STATUS status; @@ -752,7 +752,7 @@ static ZIO_WAIT_FUNCTION(pika_wait) * \param datalen Size of data buffer * \return Success or failure */ -static ZIO_READ_FUNCTION(pika_read) +static FIO_READ_FUNCTION(pika_read) { pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; PK_STATUS status; @@ -793,7 +793,7 @@ static ZIO_READ_FUNCTION(pika_read) * \param datalen Size of data buffer * \return Success or failure */ -static ZIO_WRITE_FUNCTION(pika_write) +static FIO_WRITE_FUNCTION(pika_write) { pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; PK_STATUS status; @@ -819,7 +819,7 @@ static ZIO_WRITE_FUNCTION(pika_write) * \param obj Object (unused) * \return Success or failure */ -static ZIO_COMMAND_FUNCTION(pika_command) +static FIO_COMMAND_FUNCTION(pika_command) { pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; //pika_span_data_t *span_data = (pika_span_data_t *) ftdmchan->span->mod_data; @@ -954,7 +954,7 @@ static ZIO_COMMAND_FUNCTION(pika_command) * \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) +static FIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) { pika_span_data_t *span_data = (pika_span_data_t *) span->mod_data; PK_STATUS status; @@ -1062,7 +1062,7 @@ static ZIO_SPAN_POLL_EVENT_FUNCTION(pika_poll_event) * \param event FreeTDM event to return * \return Success or failure */ -static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) +static FIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) { uint32_t i, event_id = 0; @@ -1205,7 +1205,7 @@ static ZIO_SPAN_NEXT_EVENT_FUNCTION(pika_next_event) * \param span Span to destroy * \return Success */ -static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) +static FIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) { pika_span_data_t *span_data = (pika_span_data_t *) span->mod_data; @@ -1222,7 +1222,7 @@ static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy) * \param ftdmchan Channel to destroy * \return Success or failure */ -static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) +static FIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) { pika_chan_data_t *chan_data = (pika_chan_data_t *) ftdmchan->mod_data; pika_span_data_t *span_data = (pika_span_data_t *) ftdmchan->span->mod_data; @@ -1271,7 +1271,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(pika_channel_destroy) * \param ftdmchan Channel to get alarms from * \return Failure */ -static ZIO_GET_ALARMS_FUNCTION(pika_get_alarms) +static FIO_GET_ALARMS_FUNCTION(pika_get_alarms) { return FTDM_FAIL; } @@ -1280,10 +1280,10 @@ static ftdm_io_interface_t pika_interface; /** * \brief Loads Pika IO module - * \param zio FreeTDM IO interface + * \param fio FreeTDM IO interface * \return Success or failure */ -static ZIO_IO_LOAD_FUNCTION(pika_init) +static FIO_IO_LOAD_FUNCTION(pika_init) { PK_STATUS status; @@ -1293,7 +1293,7 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) PKH_TLogMasks m; TPikaHandle tmpHandle; - assert(zio != NULL); + assert(fio != NULL); memset(&pika_interface, 0, sizeof(pika_interface)); memset(&globals, 0, sizeof(globals)); globals.general_config.region = PKH_TRUNK_NA; @@ -1375,7 +1375,7 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) pika_interface.channel_destroy = pika_channel_destroy; pika_interface.span_destroy = pika_span_destroy; pika_interface.get_alarms = pika_get_alarms; - *zio = &pika_interface; + *fio = &pika_interface; ftdm_log(FTDM_LOG_INFO, "Dumping Default configs:\n"); @@ -1421,7 +1421,7 @@ static ZIO_IO_LOAD_FUNCTION(pika_init) * \brief Unloads Pika IO module * \return Success */ -static ZIO_IO_UNLOAD_FUNCTION(pika_destroy) +static FIO_IO_UNLOAD_FUNCTION(pika_destroy) { uint32_t x; PK_STATUS status; diff --git a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c index 3dee603f1a..f9f78c230f 100644 --- a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c +++ b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c @@ -91,7 +91,7 @@ typedef struct ft_r2_conf_s { /* r2 configuration stored in span->signal_data */ typedef struct ftdm_r2_data_s { /* signaling callback */ - zio_signal_cb_t sig_cb; + fio_signal_cb_t sig_cb; /* span flags */ ftdm_r2_flag_t flags; /* openr2 handle for the R2 variant context */ @@ -159,7 +159,7 @@ static void ft_r2_answer_call(ftdm_channel_t *ftdmchan) R2CALL(ftdmchan)->answer_pending = 0; } -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(r2_outgoing_call) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(r2_outgoing_call) { ftdm_status_t status; ftdm_mutex_lock(ftdmchan->mutex); @@ -645,8 +645,8 @@ static openr2_io_interface_t ftdm_r2_io_iface = { .get_oob_event = ftdm_r2_io_get_oob_event /* never called */ }; -static ZIO_SIG_CONFIGURE_FUNCTION(ftdm_r2_configure_span) - //ftdm_status_t (ftdm_span_t *span, zio_signal_cb_t sig_cb, va_list ap) +static FIO_SIG_CONFIGURE_FUNCTION(ftdm_r2_configure_span) + //ftdm_status_t (ftdm_span_t *span, fio_signal_cb_t sig_cb, va_list ap) { int i = 0; int conf_failure = 0; @@ -1176,7 +1176,7 @@ static void *ftdm_r2_run(ftdm_thread_t *me, void *obj) } -static ZIO_API_FUNCTION(ftdm_r2_api) +static FIO_API_FUNCTION(ftdm_r2_api) { char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; @@ -1303,20 +1303,20 @@ done: } -static ZIO_IO_LOAD_FUNCTION(ftdm_r2_io_init) +static FIO_IO_LOAD_FUNCTION(ftdm_r2_io_init) { - assert(zio != NULL); + assert(fio != NULL); memset(&g_ftdm_r2_interface, 0, sizeof(g_ftdm_r2_interface)); g_ftdm_r2_interface.name = "r2"; g_ftdm_r2_interface.api = ftdm_r2_api; - *zio = &g_ftdm_r2_interface; + *fio = &g_ftdm_r2_interface; return FTDM_SUCCESS; } -static ZIO_SIG_LOAD_FUNCTION(ftdm_r2_init) +static FIO_SIG_LOAD_FUNCTION(ftdm_r2_init) { g_mod_data_hash = create_hashtable(10, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); if (!g_mod_data_hash) { @@ -1326,7 +1326,7 @@ static ZIO_SIG_LOAD_FUNCTION(ftdm_r2_init) return FTDM_SUCCESS; } -static ZIO_SIG_UNLOAD_FUNCTION(ftdm_r2_destroy) +static FIO_SIG_UNLOAD_FUNCTION(ftdm_r2_destroy) { ftdm_hash_iterator_t *i = NULL; ftdm_r2_span_pvt_t *spanpvt = NULL; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h index c3eb739f84..7b98a166c8 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h @@ -49,7 +49,7 @@ typedef struct ftdm_sangoma_boost_data { fd_set rfds; fd_set efds; int iteration; - zio_signal_cb_t signal_cb; + fio_signal_cb_t signal_cb; uint32_t flags; boost_sigmod_interface_t *sigmod; ftdm_queue_t *boost_queue; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 916e281e20..7e82c84479 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -286,7 +286,7 @@ static int boost_media_ready(sangomabc_event_t *event) * \param ftdmchan Channel to initialise * \return Success or failure */ -static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) +static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) { ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; ftdm_status_t status = FTDM_FAIL; @@ -474,7 +474,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) * \param ftdmchan Channel to initiate call on * \return Success */ -static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) +static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) { ftdm_status_t status = FTDM_SUCCESS; @@ -1617,10 +1617,10 @@ end: /** * \brief Loads sangoma boost signaling module - * \param zio FreeTDM IO interface + * \param fio FreeTDM IO interface * \return Success */ -static ZIO_SIG_LOAD_FUNCTION(ftdm_sangoma_boost_init) +static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_boost_init) { g_boost_modules_hash = create_hashtable(10, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); if (!g_boost_modules_hash) { @@ -1633,7 +1633,7 @@ static ZIO_SIG_LOAD_FUNCTION(ftdm_sangoma_boost_init) return FTDM_SUCCESS; } -static ZIO_SIG_UNLOAD_FUNCTION(ftdm_sangoma_boost_destroy) +static FIO_SIG_UNLOAD_FUNCTION(ftdm_sangoma_boost_destroy) { ftdm_hash_iterator_t *i = NULL; boost_sigmod_interface_t *sigmod = NULL; @@ -1839,7 +1839,7 @@ static BOOST_SIG_STATUS_CB_FUNCTION(ftdm_boost_sig_status_change) return; } -static ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_channel_sig_status) +static FIO_CHANNEL_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_channel_sig_status) { ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; if (!sangoma_boost_data->sigmod) { @@ -1853,7 +1853,7 @@ static ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_channel_sig_status) return sangoma_boost_data->sigmod->set_channel_sig_status(ftdmchan, status); } -static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_channel_sig_status) +static FIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_channel_sig_status) { ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; if (!sangoma_boost_data->sigmod) { @@ -1867,7 +1867,7 @@ static ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_channel_sig_status) return sangoma_boost_data->sigmod->get_channel_sig_status(ftdmchan, status); } -static ZIO_SPAN_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_span_sig_status) +static FIO_SPAN_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_span_sig_status) { ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (!sangoma_boost_data->sigmod) { @@ -1881,7 +1881,7 @@ static ZIO_SPAN_SET_SIG_STATUS_FUNCTION(sangoma_boost_set_span_sig_status) return sangoma_boost_data->sigmod->set_span_sig_status(span, status); } -static ZIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) +static FIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) { ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; if (!sangoma_boost_data->sigmod) { @@ -1902,7 +1902,7 @@ static ZIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) * \param ap List of configuration variables * \return Success or failure */ -static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) +static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) { #define FAIL_CONFIG_RETURN(retstatus) \ if (sangoma_boost_data) \ diff --git a/libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c b/libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c index ca01ed1bcc..62c4942e7c 100644 --- a/libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c +++ b/libs/freetdm/src/ftmod/ftmod_skel/ftmod_skel.c @@ -35,76 +35,76 @@ #include "freetdm.h" //#include "ftdm_skel.h" -static ZIO_CONFIGURE_FUNCTION(skel_configure) +static FIO_CONFIGURE_FUNCTION(skel_configure) { return FTDM_FAIL; } -static ZIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) +static FIO_CONFIGURE_SPAN_FUNCTION(skel_configure_span) { return FTDM_FAIL; } -static ZIO_OPEN_FUNCTION(skel_open) +static FIO_OPEN_FUNCTION(skel_open) { return FTDM_FAIL; } -static ZIO_CLOSE_FUNCTION(skel_close) +static FIO_CLOSE_FUNCTION(skel_close) { return FTDM_FAIL; } -static ZIO_WAIT_FUNCTION(skel_wait) +static FIO_WAIT_FUNCTION(skel_wait) { return FTDM_FAIL; } -static ZIO_READ_FUNCTION(skel_read) +static FIO_READ_FUNCTION(skel_read) { return FTDM_FAIL; } -static ZIO_WRITE_FUNCTION(skel_write) +static FIO_WRITE_FUNCTION(skel_write) { return FTDM_FAIL; } -static ZIO_COMMAND_FUNCTION(skel_command) +static FIO_COMMAND_FUNCTION(skel_command) { return FTDM_FAIL; } -static ZIO_SPAN_POLL_EVENT_FUNCTION(skel_poll_event) +static FIO_SPAN_POLL_EVENT_FUNCTION(skel_poll_event) { return FTDM_FAIL; } -static ZIO_SPAN_NEXT_EVENT_FUNCTION(skel_next_event) +static FIO_SPAN_NEXT_EVENT_FUNCTION(skel_next_event) { return FTDM_FAIL; } -static ZIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) +static FIO_CHANNEL_DESTROY_FUNCTION(skel_channel_destroy) { return FTDM_FAIL; } -static ZIO_SPAN_DESTROY_FUNCTION(skel_span_destroy) +static FIO_SPAN_DESTROY_FUNCTION(skel_span_destroy) { return FTDM_FAIL; } -static ZIO_GET_ALARMS_FUNCTION(skel_get_alarms) +static FIO_GET_ALARMS_FUNCTION(skel_get_alarms) { return FTDM_FAIL; } static ftdm_io_interface_t skel_interface; -static ZIO_IO_LOAD_FUNCTION(skel_init) +static FIO_IO_LOAD_FUNCTION(skel_init) { - assert(zio != NULL); + assert(fio != NULL); memset(&skel_interface, 0, sizeof(skel_interface)); skel_interface.name = "skel"; @@ -121,12 +121,12 @@ static ZIO_IO_LOAD_FUNCTION(skel_init) skel_interface.channel_destroy = skel_channel_destroy; skel_interface.span_destroy = skel_span_destroy; skel_interface.get_alarms = skel_get_alarms; - *zio = &skel_interface; + *fio = &skel_interface; return FTDM_SUCCESS; } -static ZIO_IO_UNLOAD_FUNCTION(skel_destroy) +static FIO_IO_UNLOAD_FUNCTION(skel_destroy) { return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 46d5e0a859..27c13d716a 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -98,8 +98,8 @@ static struct { /* 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); +FIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event); +FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); #define WP_INVALID_SOCKET -1 @@ -353,7 +353,7 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start * \param lineno Line number from configuration file * \return Success */ -static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) +static FIO_CONFIGURE_FUNCTION(wanpipe_configure) { int num; @@ -394,7 +394,7 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) * \param number FreeTDM span number * \return Success or failure */ -static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) +static FIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) { int items, i; char *mydata, *item_list[10]; @@ -468,7 +468,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span) * \param ftdmchan Channel to open * \return Success or failure */ -static ZIO_OPEN_FUNCTION(wanpipe_open) +static FIO_OPEN_FUNCTION(wanpipe_open) { wanpipe_tdm_api_t tdm_api; @@ -495,7 +495,7 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) * \param ftdmchan Channel to close * \return Success */ -static ZIO_CLOSE_FUNCTION(wanpipe_close) +static FIO_CLOSE_FUNCTION(wanpipe_close) { #ifdef LIBSANGOMA_VERSION sangoma_wait_obj_t *waitobj = ftdmchan->mod_data; @@ -512,7 +512,7 @@ static ZIO_CLOSE_FUNCTION(wanpipe_close) * \param obj Object (unused) * \return Success or failure */ -static ZIO_COMMAND_FUNCTION(wanpipe_command) +static FIO_COMMAND_FUNCTION(wanpipe_command) { wanpipe_tdm_api_t tdm_api; int err = 0; @@ -647,7 +647,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) * \param datalen Size of data buffer * \return Success, failure or timeout */ -static ZIO_READ_FUNCTION(wanpipe_read) +static FIO_READ_FUNCTION(wanpipe_read) { int rx_len = 0; wp_tdm_api_rx_hdr_t hdrframe; @@ -677,7 +677,7 @@ static ZIO_READ_FUNCTION(wanpipe_read) * \param datalen Size of data buffer * \return Success or failure */ -static ZIO_WRITE_FUNCTION(wanpipe_write) +static FIO_WRITE_FUNCTION(wanpipe_write) { int bsent; wp_tdm_api_tx_hdr_t hdrframe; @@ -703,7 +703,7 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) * \return Success, failure or timeout */ -static ZIO_WAIT_FUNCTION(wanpipe_wait) +static FIO_WAIT_FUNCTION(wanpipe_wait) { int32_t inflags = 0; int result; @@ -754,7 +754,7 @@ static ZIO_WAIT_FUNCTION(wanpipe_wait) * \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) +FIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) { #ifdef LIBSANGOMA_VERSION sangoma_status_t sangstatus; @@ -864,7 +864,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(wanpipe_poll_event) * \param ftdmchan Channel to get alarms from * \return Success or failure */ -static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) +static FIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) { wanpipe_tdm_api_t tdm_api; unsigned int alarms = 0; @@ -899,7 +899,7 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) * \param event FreeTDM event to return * \return Success or failure */ -ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) +FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) { uint32_t i,err; ftdm_oob_event_t event_id; @@ -1062,7 +1062,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) * \param ftdmchan Channel to destroy * \return Success */ -static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) +static FIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) { #ifdef LIBSANGOMA_VERSION if (ftdmchan->mod_data) { @@ -1083,12 +1083,12 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(wanpipe_channel_destroy) /** * \brief Loads wanpipe IO module - * \param zio FreeTDM IO interface + * \param fio FreeTDM IO interface * \return Success */ -static ZIO_IO_LOAD_FUNCTION(wanpipe_init) +static FIO_IO_LOAD_FUNCTION(wanpipe_init) { - assert(zio != NULL); + assert(fio != NULL); memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); wp_globals.codec_ms = 20; @@ -1109,7 +1109,7 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) wanpipe_interface.next_event = wanpipe_next_event; wanpipe_interface.channel_destroy = wanpipe_channel_destroy; wanpipe_interface.get_alarms = wanpipe_get_alarms; - *zio = &wanpipe_interface; + *fio = &wanpipe_interface; return FTDM_SUCCESS; } @@ -1118,7 +1118,7 @@ static ZIO_IO_LOAD_FUNCTION(wanpipe_init) * \brief Unloads wanpipe IO module * \return Success */ -static ZIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) +static FIO_IO_UNLOAD_FUNCTION(wanpipe_destroy) { memset(&wanpipe_interface, 0, sizeof(wanpipe_interface)); return FTDM_SUCCESS; diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 3a1908e2be..0ab9553307 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -175,8 +175,8 @@ static const char zt_chanpath[] = "/dev/ftdm/channel"; static ftdm_socket_t CONTROL_FD = ZT_INVALID_SOCKET; -ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event); -ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event); +FIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event); +FIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event); /** * \brief Initialises codec, and rx/tx gains @@ -442,7 +442,7 @@ static unsigned zt_open_range(ftdm_span_t *span, unsigned start, unsigned end, f * \param number FreeTDM span number * \return Success or failure */ -static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) +static FIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) { int items, i; @@ -511,7 +511,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span) * \param lineno Line number from configuration file * \return Success */ -static ZIO_CONFIGURE_FUNCTION(zt_configure) +static FIO_CONFIGURE_FUNCTION(zt_configure) { int num; @@ -576,7 +576,7 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) * \param ftdmchan Channel to open * \return Success or failure */ -static ZIO_OPEN_FUNCTION(zt_open) +static FIO_OPEN_FUNCTION(zt_open) { ftdm_channel_set_feature(ftdmchan, FTDM_CHANNEL_FEATURE_INTERVAL); @@ -656,7 +656,7 @@ static ZIO_OPEN_FUNCTION(zt_open) * \param ftdmchan Channel to close * \return Success */ -static ZIO_CLOSE_FUNCTION(zt_close) +static FIO_CLOSE_FUNCTION(zt_close) { return FTDM_SUCCESS; } @@ -668,7 +668,7 @@ static ZIO_CLOSE_FUNCTION(zt_close) * \param obj Object (unused) * \return Success or failure */ -static ZIO_COMMAND_FUNCTION(zt_command) +static FIO_COMMAND_FUNCTION(zt_command) { zt_params_t ztp; int err = 0; @@ -838,7 +838,7 @@ static ZIO_COMMAND_FUNCTION(zt_command) * \param ftdmchan Channel to get alarms from * \return Success or failure */ -static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms) +static FIO_GET_ALARMS_FUNCTION(zt_get_alarms) { struct zt_spaninfo info; @@ -863,7 +863,7 @@ static ZIO_GET_ALARMS_FUNCTION(zt_get_alarms) * \param to Time to wait (in ms) * \return Success, failure or timeout */ -static ZIO_WAIT_FUNCTION(zt_wait) +static FIO_WAIT_FUNCTION(zt_wait) { int32_t inflags = 0; int result; @@ -929,7 +929,7 @@ static ZIO_WAIT_FUNCTION(zt_wait) * \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) +FIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) { struct pollfd pfds[FTDM_MAX_CHANNELS_SPAN]; uint32_t i, j = 0, k = 0; @@ -972,7 +972,7 @@ ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event) * \param event FreeTDM event to return * \return Success or failure */ -ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) +FIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) { uint32_t i, event_id = 0; ftdm_oob_event_t zt_event_id = 0; @@ -1074,7 +1074,7 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) * \param datalen Size of data buffer * \return Success, failure or timeout */ -static ZIO_READ_FUNCTION(zt_read) +static FIO_READ_FUNCTION(zt_read) { ftdm_ssize_t r = 0; int errs = 0; @@ -1107,7 +1107,7 @@ static ZIO_READ_FUNCTION(zt_read) * \param datalen Size of data buffer * \return Success or failure */ -static ZIO_WRITE_FUNCTION(zt_write) +static FIO_WRITE_FUNCTION(zt_write) { ftdm_ssize_t w = 0; ftdm_size_t bytes = *datalen; @@ -1132,7 +1132,7 @@ static ZIO_WRITE_FUNCTION(zt_write) * \param ftdmchan Channel to destroy * \return Success */ -static ZIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) +static FIO_CHANNEL_DESTROY_FUNCTION(zt_channel_destroy) { close(ftdmchan->sockfd); ftdmchan->sockfd = ZT_INVALID_SOCKET; @@ -1147,12 +1147,12 @@ static ftdm_io_interface_t zt_interface; /** * \brief Loads ftdmtel IO module - * \param zio FreeTDM IO interface + * \param fio FreeTDM IO interface * \return Success or failure */ -static ZIO_IO_LOAD_FUNCTION(zt_init) +static FIO_IO_LOAD_FUNCTION(zt_init) { - assert(zio != NULL); + assert(fio != NULL); struct stat statbuf; memset(&zt_interface, 0, sizeof(zt_interface)); memset(&zt_globals, 0, sizeof(zt_globals)); @@ -1195,7 +1195,7 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) zt_interface.next_event = zt_next_event; zt_interface.channel_destroy = zt_channel_destroy; zt_interface.get_alarms = zt_get_alarms; - *zio = &zt_interface; + *fio = &zt_interface; return FTDM_SUCCESS; } @@ -1204,7 +1204,7 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) * \brief Unloads ftdmtel IO module * \return Success */ -static ZIO_IO_UNLOAD_FUNCTION(zt_destroy) +static FIO_IO_UNLOAD_FUNCTION(zt_destroy) { close(CONTROL_FD); memset(&zt_interface, 0, sizeof(zt_interface)); diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 95b15d358c..d940d6e9f3 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -512,7 +512,7 @@ struct ftdm_channel { uint32_t buffer_delay; ftdm_event_t event_header; char last_error[256]; - zio_event_cb_t event_callback; + fio_event_cb_t event_callback; uint32_t skip_read_frames; ftdm_buffer_t *dtmf_buffer; ftdm_buffer_t *gen_dtmf_buffer; @@ -541,7 +541,7 @@ struct ftdm_channel { void *call_data; struct ftdm_caller_data caller_data; struct ftdm_span *span; - struct ftdm_io_interface *zio; + struct ftdm_io_interface *fio; ftdm_hash_t *variable_hash; unsigned char rx_cas_bits; uint32_t pre_buffer_size; @@ -568,8 +568,8 @@ struct ftdm_span { uint32_t span_id; uint32_t chan_count; ftdm_span_flag_t flags; - struct ftdm_io_interface *zio; - zio_event_cb_t event_callback; + struct ftdm_io_interface *fio; + fio_event_cb_t event_callback; ftdm_mutex_t *mutex; ftdm_trunk_type_t trunk_type; ftdm_analog_start_type_t start_type; @@ -581,12 +581,12 @@ struct ftdm_span { teletone_tone_map_t tone_detect_map[FTDM_TONEMAP_INVALID+1]; teletone_multi_tone_t tone_finder[FTDM_TONEMAP_INVALID+1]; ftdm_channel_t *channels[FTDM_MAX_CHANNELS_SPAN+1]; - zio_channel_outgoing_call_t outgoing_call; - zio_channel_set_sig_status_t set_channel_sig_status; - zio_channel_get_sig_status_t get_channel_sig_status; - zio_span_set_sig_status_t set_span_sig_status; - zio_span_get_sig_status_t get_span_sig_status; - zio_channel_request_t channel_request; + fio_channel_outgoing_call_t outgoing_call; + fio_channel_set_sig_status_t set_channel_sig_status; + fio_channel_get_sig_status_t get_channel_sig_status; + fio_span_set_sig_status_t set_span_sig_status; + fio_span_get_sig_status_t get_span_sig_status; + fio_channel_request_t channel_request; ftdm_span_start_t start; ftdm_span_stop_t stop; void *mod_data; @@ -631,20 +631,20 @@ FT_DECLARE_DATA extern ftdm_memory_handler_t g_ftdm_mem_handler; struct ftdm_io_interface { const char *name; - zio_configure_span_t configure_span; - zio_configure_t configure; - zio_open_t open; - zio_close_t close; - zio_channel_destroy_t channel_destroy; - zio_span_destroy_t span_destroy; - zio_get_alarms_t get_alarms; - zio_command_t command; - zio_wait_t wait; - zio_read_t read; - zio_write_t write; - zio_span_poll_event_t poll_event; - zio_span_next_event_t next_event; - zio_api_t api; + fio_configure_span_t configure_span; + fio_configure_t configure; + fio_open_t open; + fio_close_t close; + fio_channel_destroy_t channel_destroy; + fio_span_destroy_t span_destroy; + fio_get_alarms_t get_alarms; + fio_command_t command; + fio_wait_t wait; + fio_read_t read; + fio_write_t write; + fio_span_poll_event_t poll_event; + fio_span_next_event_t next_event; + fio_api_t api; }; typedef struct ftdm_queue ftdm_queue_t; @@ -735,17 +735,17 @@ FT_DECLARE(ftdm_time_t) ftdm_current_time_in_ms(void); FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms); FT_DECLARE(ftdm_status_t) ftdm_span_next_event(ftdm_span_t *span, ftdm_event_t **event); FT_DECLARE(ftdm_status_t) ftdm_span_find(uint32_t id, ftdm_span_t **span); -FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *zio, ftdm_span_t **span, const char *name); +FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *fio, ftdm_span_t **span, const char *name); FT_DECLARE(ftdm_status_t) ftdm_span_close_all(void); FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t sockfd, ftdm_chan_type_t type, ftdm_channel_t **chan); -FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, zio_event_cb_t event_callback); +FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, fio_event_cb_t event_callback); FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan); FT_DECLARE(ftdm_status_t) ftdm_group_add_channels(const char* name, ftdm_span_t* span, const char* val); FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ftdm_channel_t* ftdmchan); FT_DECLARE(ftdm_status_t) ftdm_group_find(uint32_t id, ftdm_group_t **group); FT_DECLARE(ftdm_status_t) ftdm_group_find_by_name(const char *name, ftdm_group_t **group); FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *name); -FT_DECLARE(ftdm_status_t) ftdm_channel_set_event_callback(ftdm_channel_t *ftdmchan, zio_event_cb_t event_callback); +FT_DECLARE(ftdm_status_t) ftdm_channel_set_event_callback(ftdm_channel_t *ftdmchan, fio_event_cb_t event_callback); FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, ftdm_channel_t **ftdmchan); FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan); FT_DECLARE(ftdm_status_t) ftdm_span_channel_use_count(ftdm_span_t *span, uint32_t *count); @@ -780,8 +780,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_complete_state(ftdm_channel_t *ftdmchan); FT_DECLARE(ftdm_status_t) ftdm_channel_init(ftdm_channel_t *ftdmchan); FT_DECLARE(int) ftdm_load_modules(void); FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void); -FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ...); -FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, zio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters); +FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ...); +FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters); FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span); FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span); FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t len); @@ -792,12 +792,12 @@ FT_DECLARE(ftdm_status_t) ftdm_span_find_by_name(const char *name, ftdm_span_t * FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd); FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap); -ZIO_CODEC_FUNCTION(zio_slin2ulaw); -ZIO_CODEC_FUNCTION(zio_ulaw2slin); -ZIO_CODEC_FUNCTION(zio_slin2alaw); -ZIO_CODEC_FUNCTION(zio_alaw2slin); -ZIO_CODEC_FUNCTION(zio_ulaw2alaw); -ZIO_CODEC_FUNCTION(zio_alaw2ulaw); +FIO_CODEC_FUNCTION(fio_slin2ulaw); +FIO_CODEC_FUNCTION(fio_ulaw2slin); +FIO_CODEC_FUNCTION(fio_slin2alaw); +FIO_CODEC_FUNCTION(fio_alaw2slin); +FIO_CODEC_FUNCTION(fio_ulaw2alaw); +FIO_CODEC_FUNCTION(fio_alaw2ulaw); #ifdef DEBUG_LOCKS #define ftdm_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _ftdm_mutex_lock(_x) diff --git a/libs/freetdm/src/include/ftdm_m3ua.h b/libs/freetdm/src/include/ftdm_m3ua.h index ae2abb5022..1bf830853c 100644 --- a/libs/freetdm/src/include/ftdm_m3ua.h +++ b/libs/freetdm/src/include/ftdm_m3ua.h @@ -100,7 +100,7 @@ typedef enum { /*typedef struct m3ua_data { m3uac_connection_t mcon; m3uac_connection_t pcon; - zio_signal_cb_t signal_cb; + fio_signal_cb_t signal_cb; uint32_t flags; } m3ua_data_t; @@ -108,7 +108,7 @@ typedef enum { /*typedef struct mu3a_link { ss7bc_connection_t mcon; ss7bc_connection_t pcon; - zio_signal_cb_t signal_cb; + fio_signal_cb_t signal_cb; uint32_t flags; } ftdm_m3ua_data_t; */ diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h index 680ba0feb4..73e499cf7e 100644 --- a/libs/freetdm/src/include/ftdm_types.h +++ b/libs/freetdm/src/include/ftdm_types.h @@ -471,106 +471,106 @@ typedef struct ftdm_stream_handle ftdm_stream_handle_t; typedef ftdm_status_t (*ftdm_stream_handle_raw_write_function_t) (ftdm_stream_handle_t *handle, uint8_t *data, ftdm_size_t datalen); typedef ftdm_status_t (*ftdm_stream_handle_write_function_t) (ftdm_stream_handle_t *handle, const char *fmt, ...); -#define ZIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan) -#define ZIO_CHANNEL_OUTGOING_CALL_ARGS (ftdm_channel_t *ftdmchan) -#define ZIO_CHANNEL_SET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status) -#define ZIO_CHANNEL_GET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status) -#define ZIO_SPAN_SET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status) -#define ZIO_SPAN_GET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t *status) -#define ZIO_SPAN_POLL_EVENT_ARGS (ftdm_span_t *span, uint32_t ms) -#define ZIO_SPAN_NEXT_EVENT_ARGS (ftdm_span_t *span, ftdm_event_t **event) -#define ZIO_SIGNAL_CB_ARGS (ftdm_sigmsg_t *sigmsg) -#define ZIO_EVENT_CB_ARGS (ftdm_channel_t *ftdmchan, ftdm_event_t *event) -#define ZIO_CODEC_ARGS (void *data, ftdm_size_t max, ftdm_size_t *datalen) -#define ZIO_CONFIGURE_SPAN_ARGS (ftdm_span_t *span, const char *str, ftdm_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 (ftdm_channel_t *ftdmchan) -#define ZIO_CLOSE_ARGS (ftdm_channel_t *ftdmchan) -#define ZIO_CHANNEL_DESTROY_ARGS (ftdm_channel_t *ftdmchan) -#define ZIO_SPAN_DESTROY_ARGS (ftdm_span_t *span) -#define ZIO_COMMAND_ARGS (ftdm_channel_t *ftdmchan, ftdm_command_t command, void *obj) -#define ZIO_WAIT_ARGS (ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to) -#define ZIO_GET_ALARMS_ARGS (ftdm_channel_t *ftdmchan) -#define ZIO_READ_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) -#define ZIO_WRITE_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) -#define ZIO_IO_LOAD_ARGS (ftdm_io_interface_t **zio) -#define ZIO_IO_UNLOAD_ARGS (void) -#define ZIO_SIG_LOAD_ARGS (void) -#define ZIO_SIG_CONFIGURE_ARGS (ftdm_span_t *span, zio_signal_cb_t sig_cb, va_list ap) -#define ZIO_CONFIGURE_SPAN_SIGNALING_ARGS (ftdm_span_t *span, zio_signal_cb_t sig_cb, ftdm_conf_parameter_t *ftdm_parameters) -#define ZIO_SIG_UNLOAD_ARGS (void) -#define ZIO_API_ARGS (ftdm_stream_handle_t *stream, const char *data) +#define FIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan) +#define FIO_CHANNEL_OUTGOING_CALL_ARGS (ftdm_channel_t *ftdmchan) +#define FIO_CHANNEL_SET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status) +#define FIO_CHANNEL_GET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status) +#define FIO_SPAN_SET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status) +#define FIO_SPAN_GET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t *status) +#define FIO_SPAN_POLL_EVENT_ARGS (ftdm_span_t *span, uint32_t ms) +#define FIO_SPAN_NEXT_EVENT_ARGS (ftdm_span_t *span, ftdm_event_t **event) +#define FIO_SIGNAL_CB_ARGS (ftdm_sigmsg_t *sigmsg) +#define FIO_EVENT_CB_ARGS (ftdm_channel_t *ftdmchan, ftdm_event_t *event) +#define FIO_CODEC_ARGS (void *data, ftdm_size_t max, ftdm_size_t *datalen) +#define FIO_CONFIGURE_SPAN_ARGS (ftdm_span_t *span, const char *str, ftdm_chan_type_t type, char *name, char *number) +#define FIO_CONFIGURE_ARGS (const char *category, const char *var, const char *val, int lineno) +#define FIO_OPEN_ARGS (ftdm_channel_t *ftdmchan) +#define FIO_CLOSE_ARGS (ftdm_channel_t *ftdmchan) +#define FIO_CHANNEL_DESTROY_ARGS (ftdm_channel_t *ftdmchan) +#define FIO_SPAN_DESTROY_ARGS (ftdm_span_t *span) +#define FIO_COMMAND_ARGS (ftdm_channel_t *ftdmchan, ftdm_command_t command, void *obj) +#define FIO_WAIT_ARGS (ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to) +#define FIO_GET_ALARMS_ARGS (ftdm_channel_t *ftdmchan) +#define FIO_READ_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) +#define FIO_WRITE_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen) +#define FIO_IO_LOAD_ARGS (ftdm_io_interface_t **fio) +#define FIO_IO_UNLOAD_ARGS (void) +#define FIO_SIG_LOAD_ARGS (void) +#define FIO_SIG_CONFIGURE_ARGS (ftdm_span_t *span, fio_signal_cb_t sig_cb, va_list ap) +#define FIO_CONFIGURE_SPAN_SIGNALING_ARGS (ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *ftdm_parameters) +#define FIO_SIG_UNLOAD_ARGS (void) +#define FIO_API_ARGS (ftdm_stream_handle_t *stream, const char *data) -typedef ftdm_status_t (*zio_channel_request_t) ZIO_CHANNEL_REQUEST_ARGS ; -typedef ftdm_status_t (*zio_channel_outgoing_call_t) ZIO_CHANNEL_OUTGOING_CALL_ARGS ; -typedef ftdm_status_t (*zio_channel_set_sig_status_t) ZIO_CHANNEL_SET_SIG_STATUS_ARGS; -typedef ftdm_status_t (*zio_channel_get_sig_status_t) ZIO_CHANNEL_GET_SIG_STATUS_ARGS; -typedef ftdm_status_t (*zio_span_set_sig_status_t) ZIO_SPAN_SET_SIG_STATUS_ARGS; -typedef ftdm_status_t (*zio_span_get_sig_status_t) ZIO_SPAN_GET_SIG_STATUS_ARGS; -typedef ftdm_status_t (*zio_span_poll_event_t) ZIO_SPAN_POLL_EVENT_ARGS ; -typedef ftdm_status_t (*zio_span_next_event_t) ZIO_SPAN_NEXT_EVENT_ARGS ; -typedef ftdm_status_t (*zio_signal_cb_t) ZIO_SIGNAL_CB_ARGS ; -typedef ftdm_status_t (*zio_event_cb_t) ZIO_EVENT_CB_ARGS ; -typedef ftdm_status_t (*zio_codec_t) ZIO_CODEC_ARGS ; -typedef ftdm_status_t (*zio_configure_span_t) ZIO_CONFIGURE_SPAN_ARGS ; -typedef ftdm_status_t (*zio_configure_t) ZIO_CONFIGURE_ARGS ; -typedef ftdm_status_t (*zio_open_t) ZIO_OPEN_ARGS ; -typedef ftdm_status_t (*zio_close_t) ZIO_CLOSE_ARGS ; -typedef ftdm_status_t (*zio_channel_destroy_t) ZIO_CHANNEL_DESTROY_ARGS ; -typedef ftdm_status_t (*zio_span_destroy_t) ZIO_SPAN_DESTROY_ARGS ; -typedef ftdm_status_t (*zio_get_alarms_t) ZIO_GET_ALARMS_ARGS ; -typedef ftdm_status_t (*zio_command_t) ZIO_COMMAND_ARGS ; -typedef ftdm_status_t (*zio_wait_t) ZIO_WAIT_ARGS ; -typedef ftdm_status_t (*zio_read_t) ZIO_READ_ARGS ; -typedef ftdm_status_t (*zio_write_t) ZIO_WRITE_ARGS ; -typedef ftdm_status_t (*zio_io_load_t) ZIO_IO_LOAD_ARGS ; -typedef ftdm_status_t (*zio_sig_load_t) ZIO_SIG_LOAD_ARGS ; -typedef ftdm_status_t (*zio_sig_configure_t) ZIO_SIG_CONFIGURE_ARGS ; -typedef ftdm_status_t (*zio_configure_span_signaling_t) ZIO_CONFIGURE_SPAN_SIGNALING_ARGS ; -typedef ftdm_status_t (*zio_io_unload_t) ZIO_IO_UNLOAD_ARGS ; -typedef ftdm_status_t (*zio_sig_unload_t) ZIO_SIG_UNLOAD_ARGS ; -typedef ftdm_status_t (*zio_api_t) ZIO_API_ARGS ; +typedef ftdm_status_t (*fio_channel_request_t) FIO_CHANNEL_REQUEST_ARGS ; +typedef ftdm_status_t (*fio_channel_outgoing_call_t) FIO_CHANNEL_OUTGOING_CALL_ARGS ; +typedef ftdm_status_t (*fio_channel_set_sig_status_t) FIO_CHANNEL_SET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*fio_channel_get_sig_status_t) FIO_CHANNEL_GET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*fio_span_set_sig_status_t) FIO_SPAN_SET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*fio_span_get_sig_status_t) FIO_SPAN_GET_SIG_STATUS_ARGS; +typedef ftdm_status_t (*fio_span_poll_event_t) FIO_SPAN_POLL_EVENT_ARGS ; +typedef ftdm_status_t (*fio_span_next_event_t) FIO_SPAN_NEXT_EVENT_ARGS ; +typedef ftdm_status_t (*fio_signal_cb_t) FIO_SIGNAL_CB_ARGS ; +typedef ftdm_status_t (*fio_event_cb_t) FIO_EVENT_CB_ARGS ; +typedef ftdm_status_t (*fio_codec_t) FIO_CODEC_ARGS ; +typedef ftdm_status_t (*fio_configure_span_t) FIO_CONFIGURE_SPAN_ARGS ; +typedef ftdm_status_t (*fio_configure_t) FIO_CONFIGURE_ARGS ; +typedef ftdm_status_t (*fio_open_t) FIO_OPEN_ARGS ; +typedef ftdm_status_t (*fio_close_t) FIO_CLOSE_ARGS ; +typedef ftdm_status_t (*fio_channel_destroy_t) FIO_CHANNEL_DESTROY_ARGS ; +typedef ftdm_status_t (*fio_span_destroy_t) FIO_SPAN_DESTROY_ARGS ; +typedef ftdm_status_t (*fio_get_alarms_t) FIO_GET_ALARMS_ARGS ; +typedef ftdm_status_t (*fio_command_t) FIO_COMMAND_ARGS ; +typedef ftdm_status_t (*fio_wait_t) FIO_WAIT_ARGS ; +typedef ftdm_status_t (*fio_read_t) FIO_READ_ARGS ; +typedef ftdm_status_t (*fio_write_t) FIO_WRITE_ARGS ; +typedef ftdm_status_t (*fio_io_load_t) FIO_IO_LOAD_ARGS ; +typedef ftdm_status_t (*fio_sig_load_t) FIO_SIG_LOAD_ARGS ; +typedef ftdm_status_t (*fio_sig_configure_t) FIO_SIG_CONFIGURE_ARGS ; +typedef ftdm_status_t (*fio_configure_span_signaling_t) FIO_CONFIGURE_SPAN_SIGNALING_ARGS ; +typedef ftdm_status_t (*fio_io_unload_t) FIO_IO_UNLOAD_ARGS ; +typedef ftdm_status_t (*fio_sig_unload_t) FIO_SIG_UNLOAD_ARGS ; +typedef ftdm_status_t (*fio_api_t) FIO_API_ARGS ; -#define ZIO_CHANNEL_REQUEST_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_REQUEST_ARGS -#define ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_OUTGOING_CALL_ARGS -#define ZIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_SET_SIG_STATUS_ARGS -#define ZIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_GET_SIG_STATUS_ARGS -#define ZIO_SPAN_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_SPAN_SET_SIG_STATUS_ARGS -#define ZIO_SPAN_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name ZIO_SPAN_GET_SIG_STATUS_ARGS -#define ZIO_SPAN_POLL_EVENT_FUNCTION(name) ftdm_status_t name ZIO_SPAN_POLL_EVENT_ARGS -#define ZIO_SPAN_NEXT_EVENT_FUNCTION(name) ftdm_status_t name ZIO_SPAN_NEXT_EVENT_ARGS -#define ZIO_SIGNAL_CB_FUNCTION(name) ftdm_status_t name ZIO_SIGNAL_CB_ARGS -#define ZIO_EVENT_CB_FUNCTION(name) ftdm_status_t name ZIO_EVENT_CB_ARGS -#define ZIO_CODEC_FUNCTION(name) FT_DECLARE_NONSTD(ftdm_status_t) name ZIO_CODEC_ARGS -#define ZIO_CONFIGURE_SPAN_FUNCTION(name) ftdm_status_t name ZIO_CONFIGURE_SPAN_ARGS -#define ZIO_CONFIGURE_FUNCTION(name) ftdm_status_t name ZIO_CONFIGURE_ARGS -#define ZIO_OPEN_FUNCTION(name) ftdm_status_t name ZIO_OPEN_ARGS -#define ZIO_CLOSE_FUNCTION(name) ftdm_status_t name ZIO_CLOSE_ARGS -#define ZIO_CHANNEL_DESTROY_FUNCTION(name) ftdm_status_t name ZIO_CHANNEL_DESTROY_ARGS -#define ZIO_SPAN_DESTROY_FUNCTION(name) ftdm_status_t name ZIO_SPAN_DESTROY_ARGS -#define ZIO_GET_ALARMS_FUNCTION(name) ftdm_status_t name ZIO_GET_ALARMS_ARGS -#define ZIO_COMMAND_FUNCTION(name) ftdm_status_t name ZIO_COMMAND_ARGS -#define ZIO_WAIT_FUNCTION(name) ftdm_status_t name ZIO_WAIT_ARGS -#define ZIO_READ_FUNCTION(name) ftdm_status_t name ZIO_READ_ARGS -#define ZIO_WRITE_FUNCTION(name) ftdm_status_t name ZIO_WRITE_ARGS -#define ZIO_IO_LOAD_FUNCTION(name) ftdm_status_t name ZIO_IO_LOAD_ARGS -#define ZIO_SIG_LOAD_FUNCTION(name) ftdm_status_t name ZIO_SIG_LOAD_ARGS -#define ZIO_SIG_CONFIGURE_FUNCTION(name) ftdm_status_t name ZIO_SIG_CONFIGURE_ARGS -#define ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) ftdm_status_t name ZIO_CONFIGURE_SPAN_SIGNALING_ARGS -#define ZIO_IO_UNLOAD_FUNCTION(name) ftdm_status_t name ZIO_IO_UNLOAD_ARGS -#define ZIO_SIG_UNLOAD_FUNCTION(name) ftdm_status_t name ZIO_SIG_UNLOAD_ARGS -#define ZIO_API_FUNCTION(name) ftdm_status_t name ZIO_API_ARGS +#define FIO_CHANNEL_REQUEST_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_REQUEST_ARGS +#define FIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_OUTGOING_CALL_ARGS +#define FIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_SET_SIG_STATUS_ARGS +#define FIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_GET_SIG_STATUS_ARGS +#define FIO_SPAN_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_SPAN_SET_SIG_STATUS_ARGS +#define FIO_SPAN_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_SPAN_GET_SIG_STATUS_ARGS +#define FIO_SPAN_POLL_EVENT_FUNCTION(name) ftdm_status_t name FIO_SPAN_POLL_EVENT_ARGS +#define FIO_SPAN_NEXT_EVENT_FUNCTION(name) ftdm_status_t name FIO_SPAN_NEXT_EVENT_ARGS +#define FIO_SIGNAL_CB_FUNCTION(name) ftdm_status_t name FIO_SIGNAL_CB_ARGS +#define FIO_EVENT_CB_FUNCTION(name) ftdm_status_t name FIO_EVENT_CB_ARGS +#define FIO_CODEC_FUNCTION(name) FT_DECLARE_NONSTD(ftdm_status_t) name FIO_CODEC_ARGS +#define FIO_CONFIGURE_SPAN_FUNCTION(name) ftdm_status_t name FIO_CONFIGURE_SPAN_ARGS +#define FIO_CONFIGURE_FUNCTION(name) ftdm_status_t name FIO_CONFIGURE_ARGS +#define FIO_OPEN_FUNCTION(name) ftdm_status_t name FIO_OPEN_ARGS +#define FIO_CLOSE_FUNCTION(name) ftdm_status_t name FIO_CLOSE_ARGS +#define FIO_CHANNEL_DESTROY_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_DESTROY_ARGS +#define FIO_SPAN_DESTROY_FUNCTION(name) ftdm_status_t name FIO_SPAN_DESTROY_ARGS +#define FIO_GET_ALARMS_FUNCTION(name) ftdm_status_t name FIO_GET_ALARMS_ARGS +#define FIO_COMMAND_FUNCTION(name) ftdm_status_t name FIO_COMMAND_ARGS +#define FIO_WAIT_FUNCTION(name) ftdm_status_t name FIO_WAIT_ARGS +#define FIO_READ_FUNCTION(name) ftdm_status_t name FIO_READ_ARGS +#define FIO_WRITE_FUNCTION(name) ftdm_status_t name FIO_WRITE_ARGS +#define FIO_IO_LOAD_FUNCTION(name) ftdm_status_t name FIO_IO_LOAD_ARGS +#define FIO_SIG_LOAD_FUNCTION(name) ftdm_status_t name FIO_SIG_LOAD_ARGS +#define FIO_SIG_CONFIGURE_FUNCTION(name) ftdm_status_t name FIO_SIG_CONFIGURE_ARGS +#define FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) ftdm_status_t name FIO_CONFIGURE_SPAN_SIGNALING_ARGS +#define FIO_IO_UNLOAD_FUNCTION(name) ftdm_status_t name FIO_IO_UNLOAD_ARGS +#define FIO_SIG_UNLOAD_FUNCTION(name) ftdm_status_t name FIO_SIG_UNLOAD_ARGS +#define FIO_API_FUNCTION(name) ftdm_status_t name FIO_API_ARGS #include "ftdm_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; + fio_io_load_t io_load; + fio_io_unload_t io_unload; + fio_sig_load_t sig_load; + fio_sig_configure_t sig_configure; + fio_sig_unload_t sig_unload; /*! \brief configure a given span signaling \see sig_configure @@ -579,7 +579,7 @@ typedef struct { I'd like to deprecate sig_configure and move all modules to use sigparam_configure */ - zio_configure_span_signaling_t configure_span_signaling; + fio_configure_span_signaling_t configure_span_signaling; ftdm_dso_lib_t lib; char path[256]; } ftdm_module_t; diff --git a/libs/freetdm/src/priserver.c b/libs/freetdm/src/priserver.c index f8b3817f38..b67fa04483 100644 --- a/libs/freetdm/src/priserver.c +++ b/libs/freetdm/src/priserver.c @@ -33,7 +33,7 @@ typedef struct { static call_info_t pidmap[SANGOMA_MAX_CHAN_PER_SPAN]; -ZIO_EVENT_CB_FUNCTION(my_ftdm_event_handler) +FIO_EVENT_CB_FUNCTION(my_ftdm_event_handler) { if (event->e_type = FTDM_EVENT_DTMF) { char *dtmf = event->data; diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index 50310e1383..52b79f16bc 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -41,7 +41,7 @@ static void *test_call(ftdm_thread_t *me, void *obj) return NULL; } -static ZIO_SIGNAL_CB_FUNCTION(on_signal) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { ftdm_log(FTDM_LOG_DEBUG, "got sig [%s]\n", ftdm_signal_event2str(sigmsg->event_id)); diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index ad7a75d71a..152cae35ec 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -1,6 +1,6 @@ #include "freetdm.h" -static ZIO_SIGNAL_CB_FUNCTION(on_signal) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { return FTDM_FAIL; } diff --git a/libs/freetdm/src/testisdn.c b/libs/freetdm/src/testisdn.c index a133f995ac..c4b7295832 100644 --- a/libs/freetdm/src/testisdn.c +++ b/libs/freetdm/src/testisdn.c @@ -2,7 +2,7 @@ #include -static ZIO_SIGNAL_CB_FUNCTION(on_signal) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { return FTDM_FAIL; } diff --git a/libs/freetdm/src/testm3ua.c b/libs/freetdm/src/testm3ua.c index 63500f6d9a..5848470e7a 100644 --- a/libs/freetdm/src/testm3ua.c +++ b/libs/freetdm/src/testm3ua.c @@ -11,7 +11,7 @@ #include "freetdm.h" #include "ftdm_m3ua.h" -static ZIO_SIGNAL_CB_FUNCTION(on_signal) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { return FTDM_FAIL; } diff --git a/libs/freetdm/src/testpri.c b/libs/freetdm/src/testpri.c index 5c32adb22f..42afe2ffd3 100644 --- a/libs/freetdm/src/testpri.c +++ b/libs/freetdm/src/testpri.c @@ -33,7 +33,7 @@ static void *channel_run(ftdm_thread_t *me, void *obj) bbytes = (size_t) bytes; - zio_slin2alaw(buf, sizeof(buf), &bbytes); + fio_slin2alaw(buf, sizeof(buf), &bbytes); if (ftdm_channel_write(ftdmchan, buf, sizeof(buf), &bbytes) != FTDM_SUCCESS) { break; @@ -55,7 +55,7 @@ static void *channel_run(ftdm_thread_t *me, void *obj) return NULL; } -static ZIO_SIGNAL_CB_FUNCTION(on_signal) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { ftdm_log(FTDM_LOG_DEBUG, "got sig %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id, ftdm_signal_event2str(sigmsg->event_id)); diff --git a/libs/freetdm/src/testr2.c b/libs/freetdm/src/testr2.c index bcec7eb9d3..5eb80dfe7a 100644 --- a/libs/freetdm/src/testr2.c +++ b/libs/freetdm/src/testr2.c @@ -4,7 +4,7 @@ static int R = 0; static ftdm_mutex_t *mutex = NULL; -static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) +static FIO_SIGNAL_CB_FUNCTION(on_r2_signal) { ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel\n", ftdm_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); return FTDM_SUCCESS; diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 4c78007097..376be72dd6 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -1,6 +1,6 @@ #include "freetdm.h" -static ZIO_SIGNAL_CB_FUNCTION(on_signal) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { return FTDM_FAIL; } From 6a3784523e4f63f15123c9e0ae7cc7605c0ffb33 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 20:51:41 +0000 Subject: [PATCH 1686/1766] change 2008 windows project file to freetdm git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@975 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/{openzap.2008.sln => freetdm.2008.sln} | 0 .../{mod_openzap.2008.vcproj => mod_freetdm.2008.vcproj} | 0 libs/freetdm/msvc/{openzap.2008.vcproj => freetdm.2008.vcproj} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename libs/freetdm/{openzap.2008.sln => freetdm.2008.sln} (100%) rename libs/freetdm/mod_freetdm/{mod_openzap.2008.vcproj => mod_freetdm.2008.vcproj} (100%) rename libs/freetdm/msvc/{openzap.2008.vcproj => freetdm.2008.vcproj} (100%) diff --git a/libs/freetdm/openzap.2008.sln b/libs/freetdm/freetdm.2008.sln similarity index 100% rename from libs/freetdm/openzap.2008.sln rename to libs/freetdm/freetdm.2008.sln diff --git a/libs/freetdm/mod_freetdm/mod_openzap.2008.vcproj b/libs/freetdm/mod_freetdm/mod_freetdm.2008.vcproj similarity index 100% rename from libs/freetdm/mod_freetdm/mod_openzap.2008.vcproj rename to libs/freetdm/mod_freetdm/mod_freetdm.2008.vcproj diff --git a/libs/freetdm/msvc/openzap.2008.vcproj b/libs/freetdm/msvc/freetdm.2008.vcproj similarity index 100% rename from libs/freetdm/msvc/openzap.2008.vcproj rename to libs/freetdm/msvc/freetdm.2008.vcproj From d7018dcd5bf04d67adbfdc378de7c6ea83e6cb08 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 20:58:52 +0000 Subject: [PATCH 1687/1766] renamed bunch of visual studio 2008 project to freetdm git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@976 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/freetdm.2008.sln | 16 ++++++++-------- ...alog.2008.vcproj => ftmod_analog.2008.vcproj} | 0 ...m.2008.vcproj => ftmod_analog_em.2008.vcproj} | 0 ...d_isdn.2008.vcproj => ftmod_isdn.2008.vcproj} | 0 ...d_pika.2008.vcproj => ftmod_pika.2008.vcproj} | 0 ...08.vcproj => ftmod_sangoma_boost.2008.vcproj} | 0 ...ipe.2008.vcproj => ftmod_wanpipe.2008.vcproj} | 0 7 files changed, 8 insertions(+), 8 deletions(-) rename libs/freetdm/src/ftmod/ftmod_analog/{ozmod_analog.2008.vcproj => ftmod_analog.2008.vcproj} (100%) rename libs/freetdm/src/ftmod/ftmod_analog_em/{ozmod_analog_em.2008.vcproj => ftmod_analog_em.2008.vcproj} (100%) rename libs/freetdm/src/ftmod/ftmod_isdn/{ozmod_isdn.2008.vcproj => ftmod_isdn.2008.vcproj} (100%) rename libs/freetdm/src/ftmod/ftmod_pika/{ozmod_pika.2008.vcproj => ftmod_pika.2008.vcproj} (100%) rename libs/freetdm/src/ftmod/ftmod_sangoma_boost/{ozmod_sangoma_boost.2008.vcproj => ftmod_sangoma_boost.2008.vcproj} (100%) rename libs/freetdm/src/ftmod/ftmod_wanpipe/{ozmod_wanpipe.2008.vcproj => ftmod_wanpipe.2008.vcproj} (100%) diff --git a/libs/freetdm/freetdm.2008.sln b/libs/freetdm/freetdm.2008.sln index a40ff30137..6db8c4ec21 100644 --- a/libs/freetdm/freetdm.2008.sln +++ b/libs/freetdm/freetdm.2008.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openzap", "msvc\openzap.2008.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freetdm", "msvc\freetdm.2008.vcproj", "{93B8812C-3EC4-4F78-8970-FFBFC99E167D}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testanalog", "msvc\testanalog\testanalog.2008.vcproj", "{BB833648-BAFF-4BE2-94DB-F8BB043C588C}" ProjectSection(ProjectDependencies) = postProject @@ -13,34 +13,34 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testisdn", "msvc\testisdn\t {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_openzap", "mod_openzap\mod_openzap.2008.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_freetdm", "mod_freetdm\mod_freetdm.2008.vcproj", "{FE3540C5-3303-46E0-A69E-D92F775687F1}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog", "src\ozmod\ozmod_analog\ozmod_analog.2008.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_analog", "src\ftmod\ftmod_analog\ftmod_analog.2008.vcproj", "{37C94798-6E33-4B4F-8EE0-C72A7DC91157}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_analog_em", "src\ozmod\ozmod_analog_em\ozmod_analog_em.2008.vcproj", "{B3F49375-2834-4937-9D8C-4AC2EC911010}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_analog_em", "src\ftmod\ftmod_analog_em\ftmod_analog_em.2008.vcproj", "{B3F49375-2834-4937-9D8C-4AC2EC911010}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_isdn", "src\ozmod\ozmod_isdn\ozmod_isdn.2008.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_isdn", "src\ftmod\ftmod_isdn\ftmod_isdn.2008.vcproj", "{729344A5-D5E9-434D-8EE8-AF8C6C795D15}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_pika", "src\ozmod\ozmod_pika\ozmod_pika.2008.vcproj", "{E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_pika", "src\ftmod\ftmod_pika\ftmod_pika.2008.vcproj", "{E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}" ProjectSection(ProjectDependencies) = postProject {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_wanpipe", "src\ozmod\ozmod_wanpipe\ozmod_wanpipe.2008.vcproj", "{1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_wanpipe", "src\ftmod\ftmod_wanpipe\ftmod_wanpipe.2008.vcproj", "{1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ozmod_sangoma_boost", "src\ozmod\ozmod_sangoma_boost\ozmod_sangoma_boost.2008.vcproj", "{D021EF2A-460D-4827-A0F7-41FDECF46F1B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_sangoma_boost", "src\ftmod\ftmod_sangoma_boost\ftmod_sangoma_boost.2008.vcproj", "{D021EF2A-460D-4827-A0F7-41FDECF46F1B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testboost", "msvc\testboost\testboost.2008.vcproj", "{2B1BAF36-0241-43E7-B865-A8338AD48E2E}" EndProject diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.2008.vcproj similarity index 100% rename from libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.2008.vcproj diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.2008.vcproj similarity index 100% rename from libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.2008.vcproj diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj similarity index 100% rename from libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj diff --git a/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.2008.vcproj similarity index 100% rename from libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.2008.vcproj diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.2008.vcproj similarity index 100% rename from libs/freetdm/src/ftmod/ftmod_sangoma_boost/ozmod_sangoma_boost.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.2008.vcproj diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj similarity index 100% rename from libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2008.vcproj rename to libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj From ac7c608620484c6bda09ef364f72fd30677bd544 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 21:43:41 +0000 Subject: [PATCH 1688/1766] windows renaming to freetdm changes git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@977 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../mod_freetdm/mod_freetdm.2008.vcproj | 738 +++++++------- libs/freetdm/mod_freetdm/mod_freetdm.c | 2 +- .../mod_freetdm/mod_openzap.2005.vcproj | 402 ++++---- libs/freetdm/msvc/freetdm.2008.vcproj | 910 ++++++++--------- libs/freetdm/msvc/openzap.2005.vcproj | 36 +- .../msvc/testanalog/testanalog.2008.vcproj | 698 ++++++------- .../msvc/testboost/testboost.2008.vcproj | 382 +++---- .../msvc/testisdn/testisdn.2008.vcproj | 698 ++++++------- libs/freetdm/src/ftdm_io.c | 14 +- .../ftmod_analog/ftmod_analog.2008.vcproj | 706 ++++++------- .../ftmod_analog/ozmod_analog.2005.vcproj | 404 ++++---- .../ftmod_analog_em.2008.vcproj | 706 ++++++------- .../ozmod_analog_em.2005.vcproj | 404 ++++---- .../ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj | 930 +++++++++--------- .../ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj | 632 ++++++------ .../ftmod/ftmod_pika/ftmod_pika.2008.vcproj | 394 ++++---- .../ftmod/ftmod_pika/ozmod_pika.2005.vcproj | 394 ++++---- .../ftmod_sangoma_boost.2008.vcproj | 430 ++++---- .../ftmod_wanpipe/ftmod_wanpipe.2008.vcproj | 710 ++++++------- .../ftmod_wanpipe/ozmod_wanpipe.2005.vcproj | 392 ++++---- libs/freetdm/src/include/freetdm.h | 6 +- libs/freetdm/src/isdn/include/5ESS.h | 206 ++-- 22 files changed, 5097 insertions(+), 5097 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.2008.vcproj b/libs/freetdm/mod_freetdm/mod_freetdm.2008.vcproj index bf5be95c21..b59214cf89 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.2008.vcproj +++ b/libs/freetdm/mod_freetdm/mod_freetdm.2008.vcproj @@ -1,369 +1,369 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 0e85265ca5..0e33faa973 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -2891,7 +2891,7 @@ SWITCH_STANDARD_API(ft_function) } } else if (!strcasecmp(argv[0], "gains")) { - int i = 0; + unsigned int i = 0; float txgain = 0.0; float rxgain = 0.0; uint32_t chan_id = 0; diff --git a/libs/freetdm/mod_freetdm/mod_openzap.2005.vcproj b/libs/freetdm/mod_freetdm/mod_openzap.2005.vcproj index 959115d3d8..491d0d574a 100644 --- a/libs/freetdm/mod_freetdm/mod_openzap.2005.vcproj +++ b/libs/freetdm/mod_freetdm/mod_openzap.2005.vcproj @@ -1,201 +1,201 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/freetdm.2008.vcproj b/libs/freetdm/msvc/freetdm.2008.vcproj index 952cdd3822..8540fce75e 100644 --- a/libs/freetdm/msvc/freetdm.2008.vcproj +++ b/libs/freetdm/msvc/freetdm.2008.vcproj @@ -1,455 +1,455 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/openzap.2005.vcproj b/libs/freetdm/msvc/openzap.2005.vcproj index 59419ea8e9..85d4a89206 100644 --- a/libs/freetdm/msvc/openzap.2005.vcproj +++ b/libs/freetdm/msvc/openzap.2005.vcproj @@ -2,9 +2,9 @@ @@ -21,7 +21,7 @@ IntermediateDirectory="$(ConfigurationName)" ConfigurationType="2" CharacterSet="2" - BuildLogFile="$(IntDir)\BuildLog-openzap.htm" + BuildLogFile="$(IntDir)\BuildLog-freetdm.htm" >
@@ -267,7 +267,7 @@ >
diff --git a/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj b/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj index 120eb5fd75..24f418ab19 100644 --- a/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj +++ b/libs/freetdm/msvc/testanalog/testanalog.2008.vcproj @@ -1,349 +1,349 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testboost/testboost.2008.vcproj b/libs/freetdm/msvc/testboost/testboost.2008.vcproj index b41bf86051..d525f1c784 100644 --- a/libs/freetdm/msvc/testboost/testboost.2008.vcproj +++ b/libs/freetdm/msvc/testboost/testboost.2008.vcproj @@ -1,191 +1,191 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj b/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj index e350a45edf..86698ec3e4 100644 --- a/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj +++ b/libs/freetdm/msvc/testisdn/testisdn.2008.vcproj @@ -1,349 +1,349 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index ce67a4943c..8993c3e3f8 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -592,7 +592,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_load_tones(ftdm_span_t *span, const char *ma static void reset_gain_table(unsigned char *gain_table, float new_gain, ftdm_codec_t codec_gain) { /* sample value */ - unsigned sv = 0; + unsigned char sv = 0; /* linear gain factor */ float lingain = 0; /* linear value for each table sample */ @@ -615,10 +615,10 @@ static void reset_gain_table(unsigned char *gain_table, float new_gain, ftdm_cod } /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wipedia.org/wiki/20_log_rule#Definitions */ - lingain = pow(10.0, new_gain/ 20.0); + lingain = (float)pow(10.0, new_gain/ 20.0); for (sv = 0; sv < FTDM_GAINS_TABLE_SIZE; sv++) { /* get the linear value for this alaw/ulaw sample value */ - linvalue = codec_gain == FTDM_CODEC_ALAW ? alaw_to_linear(sv) : ulaw_to_linear(sv); + linvalue = codec_gain == FTDM_CODEC_ALAW ? (float)alaw_to_linear(sv) : (float)ulaw_to_linear(sv); /* multiply the linear value and the previously calculated linear gain */ ampvalue = (int)(linvalue * lingain); @@ -637,7 +637,7 @@ static void reset_gain_table(unsigned char *gain_table, float new_gain, ftdm_cod FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t sockfd, ftdm_chan_type_t type, ftdm_channel_t **chan) { - unsigned i = 0; + unsigned char i = 0; if (span->chan_count < FTDM_MAX_CHANNELS_SPAN) { ftdm_channel_t *new_chan = span->channels[++span->chan_count]; @@ -3152,7 +3152,7 @@ FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span) FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan) { - int i; + unsigned int i; ftdm_group_t* group = NULL; ftdm_mutex_lock(globals.group_mutex); @@ -3163,7 +3163,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_chann } /*verify that group does not already include this channel first */ - for(i=0; i < group->chan_count; i++) { + for(i = 0; i < group->chan_count; i++) { if (group->channels[i]->physical_span_id == ftdmchan->physical_span_id && group->channels[i]->physical_chan_id == ftdmchan->physical_chan_id) { @@ -3185,9 +3185,9 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_chann FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ftdm_channel_t* ftdmchan) { + unsigned int i, j; //Need to test this function ftdm_mutex_lock(globals.group_mutex); - int i, j; for (i=0; i < group->chan_count; i++) { if (group->channels[i]->physical_span_id == ftdmchan->physical_span_id && diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.2008.vcproj index da21d1f48f..448f03a545 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.2008.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.2008.vcproj @@ -1,353 +1,353 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2005.vcproj index 964393805c..7a1cf53b20 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2005.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_analog/ozmod_analog.2005.vcproj @@ -1,202 +1,202 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.2008.vcproj index 35a0d89da0..8ad183797a 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.2008.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.2008.vcproj @@ -1,353 +1,353 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2005.vcproj index bff0716d4c..9ecbadc232 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2005.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ozmod_analog_em.2005.vcproj @@ -1,202 +1,202 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj index 75815df561..0177d4246a 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.2008.vcproj @@ -1,465 +1,465 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj index 19dc74fd8f..5c8d2efc0f 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ozmod_isdn.2005.vcproj @@ -1,316 +1,316 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.2008.vcproj index 2e3cfceb13..905fdd0b5c 100644 --- a/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.2008.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_pika/ftmod_pika.2008.vcproj @@ -1,197 +1,197 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2005.vcproj index c62eddd423..646cc11428 100644 --- a/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2005.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_pika/ozmod_pika.2005.vcproj @@ -1,197 +1,197 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.2008.vcproj index ee9bae316b..12efa0384c 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.2008.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.2008.vcproj @@ -1,215 +1,215 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj index fea5e357fe..bfc50b7468 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj @@ -1,355 +1,355 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2005.vcproj b/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2005.vcproj index da21a76b7a..abebf30427 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2005.vcproj +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ozmod_wanpipe.2005.vcproj @@ -1,196 +1,196 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index d940d6e9f3..ef23bd02fb 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -36,8 +36,8 @@ * */ -#ifndef OPENFTDM_H -#define OPENFTDM_H +#ifndef FREETDM_H +#define FREETDM_H #if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) @@ -62,7 +62,7 @@ #define FT_DECLARE(type) type __stdcall #define FT_DECLARE_NONSTD(type) type __cdecl #define FT_DECLARE_DATA -#elif defined(OPENFTDM_EXPORTS) +#elif defined(FREETDM_EXPORTS) #define FT_DECLARE(type) __declspec(dllexport) type __stdcall #define FT_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl #define FT_DECLARE_DATA __declspec(dllexport) diff --git a/libs/freetdm/src/isdn/include/5ESS.h b/libs/freetdm/src/isdn/include/5ESS.h index dd364ed537..882b257395 100644 --- a/libs/freetdm/src/isdn/include/5ESS.h +++ b/libs/freetdm/src/isdn/include/5ESS.h @@ -1,103 +1,103 @@ -/****************************************************************************** - - 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 */ +/****************************************************************************** + + 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 */ From 4ef72cfef615a8d5b4ee4c8d3021b9490ab450ca Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 21:58:36 +0000 Subject: [PATCH 1689/1766] gain value adjustment fixes git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@978 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 8993c3e3f8..9d4b96cb2f 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -608,15 +608,21 @@ static void reset_gain_table(unsigned char *gain_table, float new_gain, ftdm_cod if (!new_gain) { /* for a 0.0db gain table, each alaw/ulaw sample value is left untouched (0 ==0, 1 == 1, 2 == 2 etc)*/ - for (sv = 0; sv < FTDM_GAINS_TABLE_SIZE; sv++) { + sv = 0; + while (1) { gain_table[sv] = sv; + if (sv == (FTDM_GAINS_TABLE_SIZE-1)) { + break; + } + sv++; } return; } /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wipedia.org/wiki/20_log_rule#Definitions */ lingain = (float)pow(10.0, new_gain/ 20.0); - for (sv = 0; sv < FTDM_GAINS_TABLE_SIZE; sv++) { + sv = 0; + while (1) { /* get the linear value for this alaw/ulaw sample value */ linvalue = codec_gain == FTDM_CODEC_ALAW ? (float)alaw_to_linear(sv) : (float)ulaw_to_linear(sv); @@ -632,6 +638,10 @@ static void reset_gain_table(unsigned char *gain_table, float new_gain, ftdm_cod ampvalue = FTDM_SLINEAR_MIN_VALUE; } gain_table[sv] = codec_gain == FTDM_CODEC_ALAW ? linear_to_alaw(ampvalue) : linear_to_ulaw(ampvalue); + if (sv == (FTDM_GAINS_TABLE_SIZE-1)) { + break; + } + sv++; } } @@ -675,9 +685,14 @@ FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t new_chan->dtmf_hangup_buf = ftdm_calloc (span->dtmf_hangup_len + 1, sizeof (char)); /* set 0.0db gain table */ - for (i = 0; i < sizeof(new_chan->txgain_table); i++) { + i = 0; + while (1) { new_chan->txgain_table[i] = i; new_chan->rxgain_table[i] = i; + if (i == (sizeof(new_chan->txgain_table)-1)) { + break; + } + i++; } ftdm_set_flag(new_chan, FTDM_CHANNEL_CONFIGURED | FTDM_CHANNEL_READY); From bc90d7274fda46f4c7770266eae38433f4eb3ecb Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 22:09:36 +0000 Subject: [PATCH 1690/1766] FreeSWITCH command will be ftdm and not ft git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@979 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 0e33faa973..023ab8e26e 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -2996,7 +2996,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load) freetdm_endpoint_interface->io_routines = &freetdm_io_routines; freetdm_endpoint_interface->state_handler = &freetdm_state_handlers; - SWITCH_ADD_API(commands_api_interface, "ft", "FreeTDM commands", ft_function, FT_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "ftdm", "FreeTDM commands", ft_function, FT_SYNTAX); SWITCH_ADD_APP(app_interface, "disable_ec", "Disable Echo Canceller", "Disable Echo Canceller", disable_ec_function, "", SAF_NONE); From aa58073e03de6a25d6a1e3d8d0425cebac85f69f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 15 Jan 2010 22:17:26 +0000 Subject: [PATCH 1691/1766] more freetdm git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@980 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 9d4b96cb2f..90936ee6c7 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -3381,7 +3381,7 @@ FT_DECLARE(ftdm_status_t) ftdm_global_configuration(void) if (load_config() != FTDM_SUCCESS) { globals.running = 0; - ftdm_log(FTDM_LOG_ERROR, "OpenZap global configuration failed!\n"); + ftdm_log(FTDM_LOG_ERROR, "FreeTDM global configuration failed!\n"); return FTDM_FAIL; } return FTDM_SUCCESS; From 22355d197b432a0b5326f40c400dbfba6aee0146 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 18 Jan 2010 17:00:20 +0000 Subject: [PATCH 1692/1766] fix abort in sangoma_boost_client git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@985 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c index 1d026f1bf4..163e1acd84 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c @@ -429,11 +429,8 @@ int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t ftdm_assert_return(mcon->socket >= 0, -1, "No mcon->socket!"); ftdm_assert_return(mcon->mutex != NULL, -1, "No mcon->mutex!"); - if (event->span >= FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN || event->chan >= FTDM_MAX_CHANNELS_PHYSICAL_SPAN ) { - ftdm_log(file, func, line, FTDM_LOG_LEVEL_CRIT, "Critical Error: TX Cmd=%s Invalid Span=%i Chan=%i\n", sangomabc_event_id_name(event->event_id), event->span, event->chan); - abort(); - return -1; - } + ftdm_assert_return(event->span <= FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN, -1, "Invalid span when writing boost event\n"); + ftdm_assert_return(event->chan <= FTDM_MAX_CHANNELS_PHYSICAL_SPAN, -1, "Invalid chan when writing boost event\n"); if (!boost_full_event(event->event_id)) { event_size=sizeof(sangomabc_short_event_t); From abdb9b1f3fa69c2dbba314c70d5a147a2309772a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 19 Jan 2010 19:45:52 +0000 Subject: [PATCH 1693/1766] added support to read from the configuration file ring_on_ms and ring_off_msg git-svn-id: http://svn.openzap.org/svn/openzap/trunk@990 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index a275acc352..8dad35dca5 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -368,6 +368,20 @@ static ZIO_CONFIGURE_FUNCTION(wanpipe_configure) } 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; + } } } From ec7319135d2f7a8454604d38b8a0a67f6ef65930 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 20 Jan 2010 16:23:57 +0000 Subject: [PATCH 1694/1766] Increased timeout to wait for second BOOST progress message on outgoing calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@992 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 index 89a34eaa42..35f5e3876d 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -334,10 +334,10 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_set_string(event.calling_name, caller_data->cid_name); zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); - if (strlen(caller_data->rdnis.digits)) { - event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; - } - + if (strlen(caller_data->rdnis.digits)) { + event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; + } + event.calling_number_screening_ind = caller_data->screen; event.calling_number_presentation = caller_data->pres; @@ -368,7 +368,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); } - sanity = 5000; + sanity = 60000; while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { zap_sleep(1); if (--sanity <= 0) { From 72e37bd888cecdbe693d5618e552a232be22833d Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jan 2010 04:54:05 +0000 Subject: [PATCH 1695/1766] fix stuck zchans on pri boost on call failure between proceeding and media being active (this needs to be completely reworked and is a hack fix) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@993 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) 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 index 35f5e3876d..a863c68d67 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -358,7 +358,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) *zchan = NULL; goto done; } - //printf("WTF %d\n", sanity); } if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].zchan) { @@ -368,15 +367,14 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); } + /* This is blocking the channel thread in openzap */ + /* Once we know the channel we need to get out of here and move to a state */ sanity = 60000; while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { zap_sleep(1); if (--sanity <= 0) { - status = ZAP_FAIL; - *zchan = NULL; - goto done; + break; } - //printf("WTF %d\n", sanity); } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { @@ -390,7 +388,22 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } done: - + + /* We failed to ever setup media, we need to let go of the channel */ + /* All of this early media stuff should not be in this function at all */ + /* Everything after we know the channel should be moved to a new state */ + if (OUTBOUND_REQUESTS[r].zchan && OUTBOUND_REQUESTS[r].status != BST_READY && zap_test_flag((OUTBOUND_REQUESTS[r].zchan), ZAP_CHANNEL_INUSE)) { + status = ZAP_FAIL; + *zchan = NULL; + OUTBOUND_REQUESTS[event->call_setup_id].zchan = NULL; + if (zchan->extra_id) { + zchan->extra_id = 0; + } + zchan->sflags = 0; + zchan->call_data = NULL; + zap_channel_done(zchan); + } + st = OUTBOUND_REQUESTS[r].status; OUTBOUND_REQUESTS[r].status = BST_FREE; From a9953ac8e165ed958d8c25da32ed60457ec399a8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 21 Jan 2010 05:35:53 +0000 Subject: [PATCH 1696/1766] fix last commit typos and return hangup cause on failure in funky pri boost early media fail scenario git-svn-id: http://svn.openzap.org/svn/openzap/trunk@994 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 7 ++++- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 30 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ff5a564d51..a3539d755e 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1160,7 +1160,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (status != ZAP_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); - return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; + + if (caller_data.hangup_cause == SWITCH_CAUSE_NONE) { + caller_data.hangup_cause = SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; + } + + return caller_data.hangup_cause; } if ((var = switch_event_get_header(var_event, "openzap_pre_buffer_size"))) { 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 index a863c68d67..afb9e97fd5 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -71,6 +71,7 @@ typedef struct { sangomabc_short_event_t event; zap_span_t *span; zap_channel_t *zchan; + int hangup_cause; } sangoma_boost_request_t; //#define MAX_REQ_ID ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * ZAP_MAX_CHANNELS_PHYSICAL_SPAN @@ -395,18 +396,26 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) if (OUTBOUND_REQUESTS[r].zchan && OUTBOUND_REQUESTS[r].status != BST_READY && zap_test_flag((OUTBOUND_REQUESTS[r].zchan), ZAP_CHANNEL_INUSE)) { status = ZAP_FAIL; *zchan = NULL; - OUTBOUND_REQUESTS[event->call_setup_id].zchan = NULL; - if (zchan->extra_id) { - zchan->extra_id = 0; + if (OUTBOUND_REQUESTS[r].zchan->extra_id) { + OUTBOUND_REQUESTS[r].zchan->extra_id = 0; } - zchan->sflags = 0; - zchan->call_data = NULL; - zap_channel_done(zchan); - } + (OUTBOUND_REQUESTS[r].zchan)->sflags = 0; + (OUTBOUND_REQUESTS[r].zchan)->call_data = NULL; + zap_channel_done((OUTBOUND_REQUESTS[r].zchan)); + OUTBOUND_REQUESTS[r].zchan = NULL; + } 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) { @@ -495,7 +504,8 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e event->call_setup_id, SIGBOOST_EVENT_CALL_STOPPED, ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; } /** @@ -543,6 +553,7 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ SIGBOOST_EVENT_CALL_STOPPED, ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -633,6 +644,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco 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))) { From 44acc4a042e9d9e6d89685ea1c5e3c77b0fd3231 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 22 Jan 2010 20:40:23 +0000 Subject: [PATCH 1697/1766] fix vs2008 solution project dependencies git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@997 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/freetdm.2008.sln | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/freetdm/freetdm.2008.sln b/libs/freetdm/freetdm.2008.sln index 6db8c4ec21..8766670aa1 100644 --- a/libs/freetdm/freetdm.2008.sln +++ b/libs/freetdm/freetdm.2008.sln @@ -39,10 +39,19 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_pika", "src\ftmod\ftm EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_wanpipe", "src\ftmod\ftmod_wanpipe\ftmod_wanpipe.2008.vcproj", "{1A145EE9-BBD8-45E5-98CD-EB4BE99E1DCD}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftmod_sangoma_boost", "src\ftmod\ftmod_sangoma_boost\ftmod_sangoma_boost.2008.vcproj", "{D021EF2A-460D-4827-A0F7-41FDECF46F1B}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testboost", "msvc\testboost\testboost.2008.vcproj", "{2B1BAF36-0241-43E7-B865-A8338AD48E2E}" + ProjectSection(ProjectDependencies) = postProject + {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 2b3dd0473c9f2080675b2244bf9b3d5a4f58dc62 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 23 Jan 2010 04:50:32 +0000 Subject: [PATCH 1698/1766] silence incorrect error log git-svn-id: http://svn.openzap.org/svn/openzap/trunk@999 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a3539d755e..fb9443e332 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1159,12 +1159,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (status != ZAP_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); - if (caller_data.hangup_cause == SWITCH_CAUSE_NONE) { caller_data.hangup_cause = SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; } - return caller_data.hangup_cause; } From cec179037f90247de0ce43a85164958c3d7cecd2 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 23 Jan 2010 04:52:16 +0000 Subject: [PATCH 1699/1766] make veto logs not spew warnings for normal state veto conditions git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1000 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d773970fb5..c45aaf911a 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -256,12 +256,12 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ + if (s != ZAP_CHANNEL_STATE_HANGUP) zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ zap_channel_set_state(obj, s, 1); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ - else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ + else if (!((obj->state == ZAP_CHANNEL_STATE_HANGUP && s == ZAP_CHANNEL_STATE_TERMINATING) || (obj->state == ZAP_CHANNEL_STATE_HANGUP_COMPLETE && s == ZAP_CHANNEL_STATE_HANGUP) || (obj->state == ZAP_CHANNEL_STATE_TERMINATING && s == ZAP_CHANNEL_STATE_HANGUP))) zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ } #ifdef _MSC_VER @@ -308,12 +308,12 @@ typedef enum { } zap_state_change_result_t; #define zap_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ - zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ + if (s != ZAP_CHANNEL_STATE_HANGUP) zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); r = ZAP_STATE_CHANGE_SAME; \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ int st = obj->state; \ r = (zap_channel_set_state(obj, s, l) == ZAP_SUCCESS) ? ZAP_STATE_CHANGE_SUCCESS : ZAP_STATE_CHANGE_FAIL; \ if (obj->state == s) {zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s));} \ - else {zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); } \ + else { if (!((obj->state == ZAP_CHANNEL_STATE_HANGUP && s == ZAP_CHANNEL_STATE_TERMINATING) || (obj->state == ZAP_CHANNEL_STATE_HANGUP_COMPLETE && s == ZAP_CHANNEL_STATE_HANGUP) || (obj->state == ZAP_CHANNEL_STATE_TERMINATING && s == ZAP_CHANNEL_STATE_HANGUP))) zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); } \ } From 7f746a7064cffa841ff2d1e8917cb724e48921d8 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 23 Jan 2010 05:27:01 +0000 Subject: [PATCH 1700/1766] update to new boost api SIGBOOST_VERSION 101. Fixes multiple race condition issues with thread waiting for chan and better handling of call rejects. This requires sangoma_prid v1.48 or later git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1001 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 411 +++++++++--------- .../sangoma_boost_client.c | 3 +- .../sangoma_boost_client.h | 2 +- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 9 +- 4 files changed, 209 insertions(+), 216 deletions(-) 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 index afb9e97fd5..ffbc4c8d33 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -47,7 +47,10 @@ static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), SFLAG_SENT_FINAL_MSG = (1 << 1), - SFLAG_SENT_ACK = (1 << 2) + 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; @@ -72,6 +75,7 @@ typedef struct { 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 @@ -220,30 +224,6 @@ static int check_congestion(int trunk_group) return 0; } -/** - * \brief determines whether media is ready - * \param event boost event - * \return 1 true, 0 for false - */ - -static int boost_media_ready(sangomabc_event_t *event) -{ - /* FORMAT is of type: SMG003-EVI-1-MEDIA-# */ - char* p = NULL; - p = strstr(event->isup_in_rdnis, "MEDIA"); - if (p) { - int media_ready = 0; - if ((sscanf(p, "MEDIA-%d", &media_ready)) == 1) { - if (media_ready) { - return 1; - } else { - } - } else { - zap_log(ZAP_LOG_ERROR, "Invalid boost isup_rdnis MEDIA format %s\n", p); - } - } - return 0; -} /** * \brief Requests an sangoma boost channel on a span (outgoing call) @@ -361,28 +341,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } } - if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].zchan) { - *zchan = OUTBOUND_REQUESTS[r].zchan; - status = ZAP_SUCCESS; - (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS; - zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); - } - - /* This is blocking the channel thread in openzap */ - /* Once we know the channel we need to get out of here and move to a state */ - sanity = 60000; - while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { - zap_sleep(1); - if (--sanity <= 0) { - break; - } - } - if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].zchan) { *zchan = OUTBOUND_REQUESTS[r].zchan; status = ZAP_SUCCESS; - (*zchan)->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA; - zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); } else { status = ZAP_FAIL; *zchan = NULL; @@ -390,21 +351,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) done: - /* We failed to ever setup media, we need to let go of the channel */ - /* All of this early media stuff should not be in this function at all */ - /* Everything after we know the channel should be moved to a new state */ - if (OUTBOUND_REQUESTS[r].zchan && OUTBOUND_REQUESTS[r].status != BST_READY && zap_test_flag((OUTBOUND_REQUESTS[r].zchan), ZAP_CHANNEL_INUSE)) { - status = ZAP_FAIL; - *zchan = NULL; - if (OUTBOUND_REQUESTS[r].zchan->extra_id) { - OUTBOUND_REQUESTS[r].zchan->extra_id = 0; - } - (OUTBOUND_REQUESTS[r].zchan)->sflags = 0; - (OUTBOUND_REQUESTS[r].zchan)->call_data = NULL; - zap_channel_done((OUTBOUND_REQUESTS[r].zchan)); - OUTBOUND_REQUESTS[r].zchan = NULL; - } - st = OUTBOUND_REQUESTS[r].status; OUTBOUND_REQUESTS[r].status = BST_FREE; @@ -422,11 +368,12 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) 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, + 0, + r, + SIGBOOST_EVENT_CALL_START_NACK, + 0, + 0); } return status; @@ -449,63 +396,35 @@ static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +static void handle_call_progress(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { zap_channel_t *zchan; - if (nack_map[event->call_setup_id]) { - return; - } - //if we received a progress for this device already - if (OUTBOUND_REQUESTS[event->call_setup_id].status == BST_ACK) { - if (boost_media_ready((sangomabc_event_t*) event)) { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; - zap_log(ZAP_LOG_DEBUG, "chan media ready %d:%d CSid:%d\n", event->span+1, event->chan+1, event->call_setup_id); - } - return; - } - - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - SETUP_GRID[event->span][event->chan] = event->call_setup_id; - - if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*) event, 0))) { - if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error); - } else { - 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 = 0; - OUTBOUND_REQUESTS[event->call_setup_id].zchan = zchan; - if (boost_media_ready((sangomabc_event_t*)event)) { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + 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 { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_ACK; + 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); } - return; } - } - - //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)); + zap_mutex_unlock(zchan->mutex); } - - - zap_log(ZAP_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - if (zchan) { - zap_set_sflag(zchan, SFLAG_SENT_FINAL_MSG); - } - sangomabc_exec_command(mcon, - event->span, - event->chan, - event->call_setup_id, - SIGBOOST_EVENT_CALL_STOPPED, - ZAP_CAUSE_DESTINATION_OUT_OF_ORDER); - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = ZAP_CAUSE_DESTINATION_OUT_OF_ORDER; } /** @@ -532,7 +451,22 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ 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 = 0; + 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; @@ -547,11 +481,11 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ 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); + 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; @@ -571,7 +505,7 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san 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) { + if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state == ZAP_CHANNEL_STATE_HANGUP_COMPLETE || zap_test_sflag(zchan, SFLAG_TERMINATING)) { goto done; } @@ -636,12 +570,12 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco if (event->call_setup_id) { sangomabc_exec_command(mcon, - 0, - 0, - event->call_setup_id, - SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); - + 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; @@ -671,11 +605,11 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco /* 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); + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK_ACK, + 0, 0); } /** @@ -692,22 +626,31 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san int r = 0; zap_mutex_lock(zchan->mutex); - - if (zchan->state == ZAP_CHANNEL_STATE_HANGUP) { + + if (zap_test_sflag(zchan, SFLAG_HANGUP)) { /* 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); + 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 { - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); + 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) { @@ -719,6 +662,7 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san } zap_mutex_unlock(zchan->mutex); + if (r) { return; } @@ -739,25 +683,22 @@ static void handle_call_answer(zap_span_t *span, sangomabc_connection_t *mcon, s zap_channel_t *zchan; if ((zchan = find_zchan(span, event, 1))) { - int r = 0; - - if (zchan->extra_id == event->call_setup_id && zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { - zap_mutex_lock(zchan->mutex); - if (zchan->state == ZAP_CHANNEL_STATE_DOWN && zchan->init_state != ZAP_CHANNEL_STATE_UP) { - zchan->init_state = ZAP_CHANNEL_STATE_UP; - r = 1; - } else { - zap_set_state_r(zchan, ZAP_CHANNEL_STATE_UP, 0, r); - } - zap_mutex_unlock(zchan->mutex); - } -#if 0 - if (!r) { - printf("WTF BAD ANSWER %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)); + zap_mutex_lock(zchan->mutex); + 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); } -#endif + 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); } } @@ -829,11 +770,11 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa } sangomabc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_NACK, - 0); + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + 0, 0); } @@ -948,7 +889,7 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s handle_call_start_ack(mcon, event); break; case SIGBOOST_EVENT_CALL_PROGRESS: - handle_call_progress(mcon, event); + handle_call_progress(span, mcon, event); break; case SIGBOOST_EVENT_CALL_START_NACK: handle_call_start_nack(span, mcon, event); @@ -1018,10 +959,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) switch (zchan->state) { case ZAP_CHANNEL_STATE_DOWN: { - if (zchan->extra_id) { - zchan->extra_id = 0; - } - if (zap_test_sflag(zchan, SFLAG_FREE_REQ_ID)) { release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1); } @@ -1031,28 +968,31 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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); + 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); + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_STOPPED_ACK, + 0, 0); } } + + if (zchan->extra_id) { + zchan->extra_id = 0; + } zchan->sflags = 0; zchan->call_data = NULL; zap_channel_done(zchan); } break; case ZAP_CHANNEL_STATE_PROGRESS_MEDIA: - case ZAP_CHANNEL_STATE_PROGRESS: { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; @@ -1062,16 +1002,42 @@ static __inline__ void state_advance(zap_channel_t *zchan) } 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); + 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 = sangoma_boost_data->signal_cb(&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)) { @@ -1100,19 +1066,19 @@ static __inline__ void state_advance(zap_channel_t *zchan) } 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); + 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); + zchan->physical_span_id-1, + zchan->physical_chan_id-1, + 0, + SIGBOOST_EVENT_CALL_ANSWERED, + 0, 0); } } break; @@ -1127,34 +1093,40 @@ static __inline__ void state_advance(zap_channel_t *zchan) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (zchan->last_state == ZAP_CHANNEL_STATE_TERMINATING || - zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { + zap_set_sflag_locked(zchan, SFLAG_HANGUP); + + if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { 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)) { - + + 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); + 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); + 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 = sangoma_boost_data->signal_cb(&sig); + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } break; default: @@ -1215,11 +1187,11 @@ static __inline__ void check_state(zap_span_t *span) 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, + 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); @@ -1471,19 +1443,32 @@ static zap_state_map_t boost_state_map = { 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_END}, + {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} + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END} }, { ZSD_OUTBOUND, 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 index dcdee97730..5b3e5b87ad 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -198,13 +198,14 @@ int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int } -int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) +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; 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 index 1b86c5df01..861f941ceb 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.h @@ -130,7 +130,7 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ 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 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 diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h index abb93a310f..1b90930ffe 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -14,7 +14,7 @@ #ifndef _SIGBOOST_H_ #define _SIGBOOST_H_ -#define SIGBOOST_VERSION 100 +#define SIGBOOST_VERSION 101 #include #include @@ -76,6 +76,11 @@ enum e_sigboost_event_info_par_values SIGBOOST_EVI_PROGRESS = 0x02, }; +enum e_sigboost_progress_flags +{ + SIGBOOST_PROGRESS_RING = (1 << 0), + SIGBOOST_PROGRESS_MEDIA = (1 << 1) +}; #define MAX_DIALED_DIGITS 31 @@ -108,6 +113,7 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + uint32_t flags; /* struct timeval tv; */ uint8_t called_number_digits_count; char called_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */ @@ -136,6 +142,7 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + uint32_t flags; /* struct timeval tv; */ uint8_t release_cause; } t_sigboost_short; From af2b34f1e1f254173a9f684cb4ea77a9c5e5af10 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 25 Jan 2010 17:24:52 +0000 Subject: [PATCH 1701/1766] sanitize number on outbound caller_profile we do this in mod_Sofia too git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1003 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index fb9443e332..c94fff67a4 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1068,6 +1068,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); + outbound_profile->destination_number = switch_sanitize_number(outbound_profile->destination_number); + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; From 08df1fd80cbaef50fc83c776ea5f6c901c2193c8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 25 Jan 2010 18:52:47 +0000 Subject: [PATCH 1702/1766] update BOOST.limitations file git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1004 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ftmod/ftmod_sangoma_boost/BOOST.limitations | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/BOOST.limitations b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/BOOST.limitations index 6e382ae897..663b7d376a 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/BOOST.limitations +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/BOOST.limitations @@ -18,11 +18,3 @@ == TODO == - proper upper layer management of HW alarms (this must be done in mod_openzap.c) -- proper boost hunting done in openzap based on channels status - -- move all logging calls to macro-based logging to log the file name and line in sangoma prid - -- remove FORCE_SEGFAULT from sangoma_sprid and check if there is anything like that in sangoma_brid - we should be using zap_assert or zap_assert_return which will abort depending on the openzap - crash policy - From 448d2e8566f6616001e67b7479617b15936f5beb Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 25 Jan 2010 18:53:27 +0000 Subject: [PATCH 1703/1766] fix adding of span channels to group for E1 lines git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1005 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 53 +++++++++++++----------------- libs/freetdm/src/include/freetdm.h | 1 - 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 90936ee6c7..5adaa27a96 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -2701,12 +2701,14 @@ FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd) } +static ftdm_status_t ftdm_group_add_channels(const char* name, ftdm_span_t* span, int currindex); static ftdm_status_t load_config(void) { char cfg_name[] = "freetdm.conf"; ftdm_config_t cfg; char *var, *val; int catno = -1; + int currindex = 0; ftdm_span_t *span = NULL; unsigned configured = 0, d = 0; char name[80] = ""; @@ -2819,7 +2821,9 @@ static ftdm_status_t load_config(void) ftdm_analog_start_type2str(span->start_type)); } if (span->trunk_type == FTDM_TRUNK_FXO) { + currindex = span->chan_count; configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_FXO, name, number); + ftdm_group_add_channels(group_name, span, currindex); } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); } @@ -2830,7 +2834,9 @@ static ftdm_status_t load_config(void) ftdm_analog_start_type2str(span->start_type)); } if (span->trunk_type == FTDM_TRUNK_FXS) { + currindex = span->chan_count; configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_FXS, name, number); + ftdm_group_add_channels(group_name, span, currindex); } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } @@ -2841,13 +2847,16 @@ static ftdm_status_t load_config(void) ftdm_analog_start_type2str(span->start_type)); } if (span->trunk_type == FTDM_TRUNK_EM) { + currindex = span->chan_count; configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_EM, name, number); + ftdm_group_add_channels(group_name, span, currindex); } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); } } else if (!strcasecmp(var, "b-channel")) { + currindex = span->chan_count; configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_B, name, number); - ftdm_group_add_channels(group_name, span, val); + ftdm_group_add_channels(group_name, span, currindex); } else if (!strcasecmp(var, "d-channel")) { if (d) { ftdm_log(FTDM_LOG_WARNING, "ignoring extra d-channel\n"); @@ -2863,7 +2872,9 @@ static ftdm_status_t load_config(void) d++; } } else if (!strcasecmp(var, "cas-channel")) { + currindex = span->chan_count; configured += fio->configure_span(span, val, FTDM_CHAN_TYPE_CAS, name, number); + ftdm_group_add_channels(group_name, span, currindex); } else if (!strcasecmp(var, "dtmf_hangup")) { span->dtmf_hangup = ftdm_strdup(val); span->dtmf_hangup_len = strlen(val); @@ -3228,42 +3239,22 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ft return FTDM_FAIL; } -FT_DECLARE(ftdm_status_t) ftdm_group_add_channels(const char* name, ftdm_span_t* span, const char* val) +static ftdm_status_t ftdm_group_add_channels(const char* name, ftdm_span_t* span, int currindex) { - char *p, *mydata, *item_list[10]; - int items, i; - - assert(strlen(name) > 0); + int chan_index = 0; - p = strchr(val, ':'); - mydata = ftdm_strdup(++p); - - ftdm_assert_return(mydata != NULL, FTDM_FAIL, "ftdm_strdup failed when adding channels\n"); + ftdm_assert_return(strlen(name) > 0, FTDM_FAIL, "Invalid group name provided\n"); + ftdm_assert_return(currindex >= 0, FTDM_FAIL, "Invalid current channel index provided\n"); - items = ftdm_separate_string(mydata, ',', item_list, (sizeof(item_list) / sizeof(item_list[0]))); + if (!span->chan_count) { + return FTDM_SUCCESS; + } - for(i=0; i < items; i++) { - if (!strchr(item_list[i], '-')) { - int chan_no; - - chan_no = atoi (item_list[i]); - ftdm_assert(chan_no > 0, "Channel number is not bigger than zero, expect a nasty failure!\n"); - - if (ftdm_channel_add_to_group(name, span->channels[chan_no]) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no, name); - } - } else { - int chan_no_start, chan_no_end; - if (sscanf(item_list[i], "%d-%d", &chan_no_start, &chan_no_end) == 2) { - while (chan_no_start <= chan_no_end) { - if (ftdm_channel_add_to_group(name, span->channels[chan_no_start++])) { - ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_no_start-1, name); - } - } - } + for (chan_index = (span->chan_count - currindex); chan_index <= span->chan_count; chan_index++) { + if (ftdm_channel_add_to_group(name, span->channels[chan_index])) { + ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_index, name); } } - ftdm_safe_free(mydata); return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index ef23bd02fb..5984290666 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -740,7 +740,6 @@ FT_DECLARE(ftdm_status_t) ftdm_span_close_all(void); FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t sockfd, ftdm_chan_type_t type, ftdm_channel_t **chan); FT_DECLARE(ftdm_status_t) ftdm_span_set_event_callback(ftdm_span_t *span, fio_event_cb_t event_callback); FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan); -FT_DECLARE(ftdm_status_t) ftdm_group_add_channels(const char* name, ftdm_span_t* span, const char* val); FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ftdm_channel_t* ftdmchan); FT_DECLARE(ftdm_status_t) ftdm_group_find(uint32_t id, ftdm_group_t **group); FT_DECLARE(ftdm_status_t) ftdm_group_find_by_name(const char *name, ftdm_group_t **group); From 0979265548bc83d6b22bb2a93edbd3f563c42b4a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 28 Jan 2010 16:50:34 +0000 Subject: [PATCH 1704/1766] improve sangoma boost test git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1006 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 6 + libs/freetdm/src/include/freetdm.h | 9 + libs/freetdm/src/testboost.c | 259 +++++++++++++++++++++++++---- 3 files changed, 245 insertions(+), 29 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 5adaa27a96..f3456a2f45 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -976,6 +976,12 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_ } } + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_log(FTDM_LOG_WARNING, "Ignored state change request from %s to %s, the previous state change has not been processed yet\n", + ftdm_channel_state2str(ftdmchan->state), ftdm_channel_state2str(state)); + return FTDM_FAIL; + } + if (lock) { ftdm_mutex_lock(ftdmchan->mutex); } diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 5984290666..2d3e9d861c 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -276,6 +276,15 @@ extern "C" { else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \ } +#define ftdm_set_state(obj, s) if ( obj->state == s ) { \ + ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); \ + } else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \ + ftdm_channel_state_t st = obj->state; \ + ftdm_channel_set_state(obj, s, 0); \ + if (obj->state == s) ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \ + else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \ + } + #ifdef _MSC_VER /* The while(0) below throws a conditional expression is constant warning */ #pragma warning(disable:4127) diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index 152cae35ec..1cabf60e09 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -1,70 +1,271 @@ +/* + * Copyright (c) 2010, 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. + */ + +/** + * Sample program for the boost signaling absraction. + * Usage: boostsample + * The span name must be a valid span defined in freetdm.conf + * compile this program linking to the freetdm library (ie -lfreetdm) + **/ + #include "freetdm.h" -static FIO_SIGNAL_CB_FUNCTION(on_signal) +/* arbitrary limit for max calls in this sample program */ +#define MAX_CALLS 255 + +/* some timers (in seconds) to fake responses in incoming calls */ +#define PROGRESS_TIMER 1 +#define ANSWER_TIMER 5 +#define HANGUP_TIMER 15 + +/* simple variable used to stop the application */ +static int app_running = 0; + +typedef void (*expired_function_t)(ftdm_channel_t *channel); +typedef struct dummy_timer_s { + int time; + ftdm_channel_t *channel; + expired_function_t expired; +} dummy_timer_t; + +/* dummy second resolution timers */ +static dummy_timer_t g_timers[MAX_CALLS]; + +/* mutex to protect the timers (both, the test thread and the signaling thread may modify them) */ +static ftdm_mutex_t *g_schedule_mutex; + +static void schedule_timer(ftdm_channel_t *channel, int sec, expired_function_t expired) { + int i; + ftdm_mutex_lock(g_schedule_mutex); + for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { + /* check the timer slot is free to use */ + if (!g_timers[i].time) { + g_timers[i].time = sec; + g_timers[i].channel = channel; + g_timers[i].expired = expired; + ftdm_mutex_unlock(g_schedule_mutex); + return; + } + } + ftdm_log(FTDM_LOG_ERROR, "Failed to schedule timer\n"); + ftdm_mutex_unlock(g_schedule_mutex); +} + +static void run_timers(void) +{ + int i; + void *channel; + expired_function_t expired_func = NULL; + ftdm_mutex_lock(g_schedule_mutex); + for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { + /* if there's time left, decrement */ + if (g_timers[i].time) { + g_timers[i].time--; + } + + /* if time expired and we have an expired function, call it */ + if (!g_timers[i].time && g_timers[i].expired) { + expired_func = g_timers[i].expired; + channel = g_timers[i].channel; + memset(&g_timers[i], 0, sizeof(g_timers[i])); + expired_func(channel); + } + } + ftdm_mutex_unlock(g_schedule_mutex); +} + +static void release_timers(ftdm_channel_t *channel) +{ + int i; + ftdm_mutex_lock(g_schedule_mutex); + for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { + /* clear any timer belonging to the given channel */ + if (g_timers[i].channel == channel) { + memset(&g_timers[i], 0, sizeof(g_timers[i])); + } + } + ftdm_mutex_unlock(g_schedule_mutex); +} + +/* hangup the call */ +static void send_hangup(ftdm_channel_t *channel) +{ + ftdm_log(FTDM_LOG_NOTICE, "-- Requesting hangup in channel %d:%d\n", channel->span_id, channel->chan_id); + ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_HANGUP); +} + +/* send answer for an incoming call */ +static void send_answer(ftdm_channel_t *channel) +{ + /* we move the channel signaling state machine to UP (answered) */ + ftdm_log(FTDM_LOG_NOTICE, "-- Requesting answer in channel %d:%d\n", channel->span_id, channel->chan_id); + ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_UP); + schedule_timer(channel, HANGUP_TIMER, send_hangup); +} + +/* send progress for an incoming */ +static void send_progress(ftdm_channel_t *channel) +{ + /* we move the channel signaling state machine to UP (answered) */ + ftdm_log(FTDM_LOG_NOTICE, "-- Requesting progress\n", channel->span_id, channel->chan_id); + ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_PROGRESS); + schedule_timer(channel, ANSWER_TIMER, send_answer); +} + +/* This function will be called in an undetermined signaling thread, you must not do + * any blocking operations here or the signaling stack may delay other call event processing + * The arguments for this function are defined in FIO_SIGNAL_CB_FUNCTION prototype, I just + * name them here for your convenience: + * ftdm_sigmsg_t *sigmsg + * - The sigmsg structure contains the ftdm_channel structure that represents the channel where + * the event occurred and the event_id of the signaling event that just occurred. + * */ +static FIO_SIGNAL_CB_FUNCTION(on_signaling_event) +{ + switch (sigmsg->event_id) { + /* This event signals the start of an incoming call */ + case FTDM_SIGEVENT_START: + ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_START received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + schedule_timer(sigmsg->channel, PROGRESS_TIMER, send_progress); + break; + /* This event signals progress on an outgoing call */ + case FTDM_SIGEVENT_PROGRESS_MEDIA: + ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_PROGRESS_MEDIA received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + break; + /* This event signals answer in an outgoing call */ + case FTDM_SIGEVENT_UP: + ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_UP received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + break; + /* This event signals hangup from the other end */ + case FTDM_SIGEVENT_STOP: + ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_STOP received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + /* release any timer for this channel */ + release_timers(sigmsg->channel); + break; + default: + break; + } return FTDM_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[]) { ftdm_conf_parameter_t parameters[20]; ftdm_span_t *span; - int local_port, remote_port; - local_port = remote_port = 53000; - - ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); -#if 0 if (argc < 2) { - printf("invalid arguments\n"); + fprintf(stderr, "Usage: boostsample \n"); exit(-1); } -#endif + /* clear any outstanding timers */ + memset(&g_timers, 0, sizeof(g_timers)); + + /* set the logging level to use */ + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); + + /* Initialize the FTDM library */ if (ftdm_global_init() != FTDM_SUCCESS) { fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } + + /* create the schedule mutex */ + ftdm_mutex_create(&g_schedule_mutex); + + /* Load the FreeTDM configuration */ if (ftdm_global_configuration() != FTDM_SUCCESS) { fprintf(stderr, "Error configuring FreeTDM\n"); exit(-1); } - printf("FreeTDM loaded\n"); + /* At this point FreeTDM is ready to be used, the spans defined in freetdm.conf have the basic I/O board configuration + * but no telephony signaling configuration at all. */ + printf("FreeTDM loaded ...\n"); - if (ftdm_span_find_by_name("wp1", &span) != FTDM_SUCCESS) { + /* Retrieve a span by name (according to freetdm.conf) */ + if (ftdm_span_find_by_name(argv[1], &span) != FTDM_SUCCESS) { fprintf(stderr, "Error finding FreeTDM span %s\n", argv[1]); goto done; } + + /* prepare the configuration parameters that will be sent down to the signaling stack, the array of paramters must be terminated by an + * array element with a null .var member */ + + /* for sangoma_boost signaling (abstraction signaling used by Sangoma for PRI, BRI and SS7) the first parameter you must send + * is sigmod, which must be either sangoma_prid, if you have the PRI stack available, or sangoma_brid for the BRI stack */ parameters[0].var = "sigmod"; parameters[0].val = "sangoma_prid"; - parameters[1].var = "switchtype"; - parameters[1].val = "euroisdn"; - parameters[1].var = "signalling"; - parameters[1].val = "pri_cpe"; - parameters[2].var = NULL; - if (ftdm_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == FTDM_SUCCESS) { - ftdm_span_start(span); - } else { - fprintf(stderr, "Error starting SS7_BOOST\n"); + + /* following parameters are signaling stack specific, this ones are for PRI */ + parameters[1].var = "switchtype"; + parameters[1].val = "euroisdn"; + + parameters[2].var = "signalling"; + parameters[2].val = "pri_cpe"; + + /* the last parameter .var member must be NULL! */ + parameters[3].var = NULL; + + /* send the configuration values down to the stack */ + if (ftdm_configure_span_signaling("sangoma_boost", span, on_signaling_event, parameters) != FTDM_SUCCESS) { + fprintf(stderr, "Error configuring sangoma_boost signaling abstraction in span %s\n", span->name); goto done; } - while(ftdm_running() && R) { + /* configuration succeeded, we can proceed now to start the span + * This step will launch at least 1 background (may be more, depending on the signaling stack used) + * to handle *ALL* signaling events for this span, your on_signaling_event callback will be called always + * in one of those infraestructure threads and you MUST NOT block in that handler to avoid delays and errors + * in the signaling processing for any call. + * */ + ftdm_span_start(span); + + app_running = 1; + + /* The application thread can go on and do anything else, like waiting for a shutdown signal */ + while(ftdm_running() && app_running) { ftdm_sleep(1 * 1000); + run_timers(); } done: + ftdm_mutex_destroy(&g_schedule_mutex); + + /* whenever you're done, this function will shutdown the signaling threads in any span that was started */ ftdm_global_destroy(); return 0; From 339e2087bb3a6e052bd44f37128faaeb0e8e733f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 28 Jan 2010 21:06:11 +0000 Subject: [PATCH 1705/1766] done with outgoing sangoma boost sample program git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1007 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testboost.c | 259 +++---------------------- libs/freetdm/src/testsangomaboost.c | 280 ++++++++++++++++++++++++---- 2 files changed, 275 insertions(+), 264 deletions(-) diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index 1cabf60e09..152cae35ec 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -1,271 +1,70 @@ -/* - * Copyright (c) 2010, 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. - */ - -/** - * Sample program for the boost signaling absraction. - * Usage: boostsample - * The span name must be a valid span defined in freetdm.conf - * compile this program linking to the freetdm library (ie -lfreetdm) - **/ - #include "freetdm.h" -/* arbitrary limit for max calls in this sample program */ -#define MAX_CALLS 255 - -/* some timers (in seconds) to fake responses in incoming calls */ -#define PROGRESS_TIMER 1 -#define ANSWER_TIMER 5 -#define HANGUP_TIMER 15 - -/* simple variable used to stop the application */ -static int app_running = 0; - -typedef void (*expired_function_t)(ftdm_channel_t *channel); -typedef struct dummy_timer_s { - int time; - ftdm_channel_t *channel; - expired_function_t expired; -} dummy_timer_t; - -/* dummy second resolution timers */ -static dummy_timer_t g_timers[MAX_CALLS]; - -/* mutex to protect the timers (both, the test thread and the signaling thread may modify them) */ -static ftdm_mutex_t *g_schedule_mutex; - -static void schedule_timer(ftdm_channel_t *channel, int sec, expired_function_t expired) +static FIO_SIGNAL_CB_FUNCTION(on_signal) { - int i; - ftdm_mutex_lock(g_schedule_mutex); - for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { - /* check the timer slot is free to use */ - if (!g_timers[i].time) { - g_timers[i].time = sec; - g_timers[i].channel = channel; - g_timers[i].expired = expired; - ftdm_mutex_unlock(g_schedule_mutex); - return; - } - } - ftdm_log(FTDM_LOG_ERROR, "Failed to schedule timer\n"); - ftdm_mutex_unlock(g_schedule_mutex); -} - -static void run_timers(void) -{ - int i; - void *channel; - expired_function_t expired_func = NULL; - ftdm_mutex_lock(g_schedule_mutex); - for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { - /* if there's time left, decrement */ - if (g_timers[i].time) { - g_timers[i].time--; - } - - /* if time expired and we have an expired function, call it */ - if (!g_timers[i].time && g_timers[i].expired) { - expired_func = g_timers[i].expired; - channel = g_timers[i].channel; - memset(&g_timers[i], 0, sizeof(g_timers[i])); - expired_func(channel); - } - } - ftdm_mutex_unlock(g_schedule_mutex); -} - -static void release_timers(ftdm_channel_t *channel) -{ - int i; - ftdm_mutex_lock(g_schedule_mutex); - for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { - /* clear any timer belonging to the given channel */ - if (g_timers[i].channel == channel) { - memset(&g_timers[i], 0, sizeof(g_timers[i])); - } - } - ftdm_mutex_unlock(g_schedule_mutex); -} - -/* hangup the call */ -static void send_hangup(ftdm_channel_t *channel) -{ - ftdm_log(FTDM_LOG_NOTICE, "-- Requesting hangup in channel %d:%d\n", channel->span_id, channel->chan_id); - ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_HANGUP); -} - -/* send answer for an incoming call */ -static void send_answer(ftdm_channel_t *channel) -{ - /* we move the channel signaling state machine to UP (answered) */ - ftdm_log(FTDM_LOG_NOTICE, "-- Requesting answer in channel %d:%d\n", channel->span_id, channel->chan_id); - ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_UP); - schedule_timer(channel, HANGUP_TIMER, send_hangup); -} - -/* send progress for an incoming */ -static void send_progress(ftdm_channel_t *channel) -{ - /* we move the channel signaling state machine to UP (answered) */ - ftdm_log(FTDM_LOG_NOTICE, "-- Requesting progress\n", channel->span_id, channel->chan_id); - ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_PROGRESS); - schedule_timer(channel, ANSWER_TIMER, send_answer); -} - -/* This function will be called in an undetermined signaling thread, you must not do - * any blocking operations here or the signaling stack may delay other call event processing - * The arguments for this function are defined in FIO_SIGNAL_CB_FUNCTION prototype, I just - * name them here for your convenience: - * ftdm_sigmsg_t *sigmsg - * - The sigmsg structure contains the ftdm_channel structure that represents the channel where - * the event occurred and the event_id of the signaling event that just occurred. - * */ -static FIO_SIGNAL_CB_FUNCTION(on_signaling_event) -{ - switch (sigmsg->event_id) { - /* This event signals the start of an incoming call */ - case FTDM_SIGEVENT_START: - ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_START received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); - schedule_timer(sigmsg->channel, PROGRESS_TIMER, send_progress); - break; - /* This event signals progress on an outgoing call */ - case FTDM_SIGEVENT_PROGRESS_MEDIA: - ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_PROGRESS_MEDIA received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); - break; - /* This event signals answer in an outgoing call */ - case FTDM_SIGEVENT_UP: - ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_UP received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); - break; - /* This event signals hangup from the other end */ - case FTDM_SIGEVENT_STOP: - ftdm_log(FTDM_LOG_NOTICE, "FTDM_SIGEVENT_STOP received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); - /* release any timer for this channel */ - release_timers(sigmsg->channel); - break; - default: - break; - } return FTDM_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[]) { ftdm_conf_parameter_t parameters[20]; ftdm_span_t *span; + int local_port, remote_port; + local_port = remote_port = 53000; + + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); +#if 0 if (argc < 2) { - fprintf(stderr, "Usage: boostsample \n"); + printf("invalid arguments\n"); exit(-1); } +#endif - /* clear any outstanding timers */ - memset(&g_timers, 0, sizeof(g_timers)); - - /* set the logging level to use */ - ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); - - /* Initialize the FTDM library */ if (ftdm_global_init() != FTDM_SUCCESS) { fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } - - /* create the schedule mutex */ - ftdm_mutex_create(&g_schedule_mutex); - - /* Load the FreeTDM configuration */ if (ftdm_global_configuration() != FTDM_SUCCESS) { fprintf(stderr, "Error configuring FreeTDM\n"); exit(-1); } - /* At this point FreeTDM is ready to be used, the spans defined in freetdm.conf have the basic I/O board configuration - * but no telephony signaling configuration at all. */ - printf("FreeTDM loaded ...\n"); + printf("FreeTDM loaded\n"); - /* Retrieve a span by name (according to freetdm.conf) */ - if (ftdm_span_find_by_name(argv[1], &span) != FTDM_SUCCESS) { + if (ftdm_span_find_by_name("wp1", &span) != FTDM_SUCCESS) { fprintf(stderr, "Error finding FreeTDM span %s\n", argv[1]); goto done; } - - /* prepare the configuration parameters that will be sent down to the signaling stack, the array of paramters must be terminated by an - * array element with a null .var member */ - - /* for sangoma_boost signaling (abstraction signaling used by Sangoma for PRI, BRI and SS7) the first parameter you must send - * is sigmod, which must be either sangoma_prid, if you have the PRI stack available, or sangoma_brid for the BRI stack */ parameters[0].var = "sigmod"; parameters[0].val = "sangoma_prid"; - - /* following parameters are signaling stack specific, this ones are for PRI */ - parameters[1].var = "switchtype"; - parameters[1].val = "euroisdn"; - - parameters[2].var = "signalling"; - parameters[2].val = "pri_cpe"; - - /* the last parameter .var member must be NULL! */ - parameters[3].var = NULL; - - /* send the configuration values down to the stack */ - if (ftdm_configure_span_signaling("sangoma_boost", span, on_signaling_event, parameters) != FTDM_SUCCESS) { - fprintf(stderr, "Error configuring sangoma_boost signaling abstraction in span %s\n", span->name); + parameters[1].var = "switchtype"; + parameters[1].val = "euroisdn"; + parameters[1].var = "signalling"; + parameters[1].val = "pri_cpe"; + parameters[2].var = NULL; + if (ftdm_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == FTDM_SUCCESS) { + ftdm_span_start(span); + } else { + fprintf(stderr, "Error starting SS7_BOOST\n"); goto done; } - /* configuration succeeded, we can proceed now to start the span - * This step will launch at least 1 background (may be more, depending on the signaling stack used) - * to handle *ALL* signaling events for this span, your on_signaling_event callback will be called always - * in one of those infraestructure threads and you MUST NOT block in that handler to avoid delays and errors - * in the signaling processing for any call. - * */ - ftdm_span_start(span); - - app_running = 1; - - /* The application thread can go on and do anything else, like waiting for a shutdown signal */ - while(ftdm_running() && app_running) { + while(ftdm_running() && R) { ftdm_sleep(1 * 1000); - run_timers(); } done: - ftdm_mutex_destroy(&g_schedule_mutex); - - /* whenever you're done, this function will shutdown the signaling threads in any span that was started */ ftdm_global_destroy(); return 0; diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 376be72dd6..2adb6c69b5 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -1,73 +1,285 @@ +/* + * Copyright (c) 2010, 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. + */ + +/** + * Sample program for the boost signaling absraction. + * Usage: boostsample + * The span name must be a valid span defined in freetdm.conf + * compile this program linking to the freetdm library (ie -lfreetdm) + **/ + +#include + #include "freetdm.h" -static FIO_SIGNAL_CB_FUNCTION(on_signal) +/* arbitrary limit for max calls in this sample program */ +#define MAX_CALLS 255 + +/* some timers (in seconds) to fake responses in incoming calls */ +#define PROGRESS_TIMER 1 +#define ANSWER_TIMER 5 +#define HANGUP_TIMER 15 + +/* simple variable used to stop the application */ +static int app_running = 0; + +typedef void (*expired_function_t)(ftdm_channel_t *channel); +typedef struct dummy_timer_s { + int time; + ftdm_channel_t *channel; + expired_function_t expired; +} dummy_timer_t; + +/* dummy second resolution timers */ +static dummy_timer_t g_timers[MAX_CALLS]; + +/* mutex to protect the timers (both, the test thread and the signaling thread may modify them) */ +static ftdm_mutex_t *g_schedule_mutex; + +static void interrupt_requested(int signal) { - return FTDM_FAIL; + app_running = 0; } -static int R = 0; -#if 0 -static void handle_SIGINT(int sig) +static void schedule_timer(ftdm_channel_t *channel, int sec, expired_function_t expired) { - if (sig); - R = 0; - return; + int i; + ftdm_mutex_lock(g_schedule_mutex); + for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { + /* check the timer slot is free to use */ + if (!g_timers[i].time) { + g_timers[i].time = sec; + g_timers[i].channel = channel; + g_timers[i].expired = expired; + ftdm_mutex_unlock(g_schedule_mutex); + return; + } + } + ftdm_log(FTDM_LOG_ERROR, "Failed to schedule timer\n"); + ftdm_mutex_unlock(g_schedule_mutex); } -#endif + +static void run_timers(void) +{ + int i; + void *channel; + expired_function_t expired_func = NULL; + ftdm_mutex_lock(g_schedule_mutex); + for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { + /* if there's time left, decrement */ + if (g_timers[i].time) { + g_timers[i].time--; + } + + /* if time expired and we have an expired function, call it */ + if (!g_timers[i].time && g_timers[i].expired) { + expired_func = g_timers[i].expired; + channel = g_timers[i].channel; + memset(&g_timers[i], 0, sizeof(g_timers[i])); + expired_func(channel); + } + } + ftdm_mutex_unlock(g_schedule_mutex); +} + +static void release_timers(ftdm_channel_t *channel) +{ + int i; + ftdm_mutex_lock(g_schedule_mutex); + for (i = 0; i < sizeof(g_timers)/sizeof(g_timers[0]); i++) { + /* clear any timer belonging to the given channel */ + if (g_timers[i].channel == channel) { + memset(&g_timers[i], 0, sizeof(g_timers[i])); + } + } + ftdm_mutex_unlock(g_schedule_mutex); +} + +/* hangup the call */ +static void send_hangup(ftdm_channel_t *channel) +{ + ftdm_log(FTDM_LOG_NOTICE, "-- Requesting hangup in channel %d:%d\n", channel->span_id, channel->chan_id); + ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_HANGUP); +} + +/* send answer for an incoming call */ +static void send_answer(ftdm_channel_t *channel) +{ + /* we move the channel signaling state machine to UP (answered) */ + ftdm_log(FTDM_LOG_NOTICE, "-- Requesting answer in channel %d:%d\n", channel->span_id, channel->chan_id); + ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_UP); + schedule_timer(channel, HANGUP_TIMER, send_hangup); +} + +/* send progress for an incoming */ +static void send_progress(ftdm_channel_t *channel) +{ + /* we move the channel signaling state machine to UP (answered) */ + ftdm_log(FTDM_LOG_NOTICE, "-- Requesting progress\n", channel->span_id, channel->chan_id); + ftdm_set_state_locked(channel, FTDM_CHANNEL_STATE_PROGRESS); + schedule_timer(channel, ANSWER_TIMER, send_answer); +} + +/* This function will be called in an undetermined signaling thread, you must not do + * any blocking operations here or the signaling stack may delay other call event processing + * The arguments for this function are defined in FIO_SIGNAL_CB_FUNCTION prototype, I just + * name them here for your convenience: + * ftdm_sigmsg_t *sigmsg + * - The sigmsg structure contains the ftdm_channel structure that represents the channel where + * the event occurred and the event_id of the signaling event that just occurred. + * */ +static FIO_SIGNAL_CB_FUNCTION(on_signaling_event) +{ + switch (sigmsg->event_id) { + /* This event signals the start of an incoming call */ + case FTDM_SIGEVENT_START: + ftdm_log(FTDM_LOG_NOTICE, "Incoming call received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + schedule_timer(sigmsg->channel, PROGRESS_TIMER, send_progress); + break; + /* This event signals progress on an outgoing call */ + case FTDM_SIGEVENT_PROGRESS_MEDIA: + ftdm_log(FTDM_LOG_NOTICE, "Progress message received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + break; + /* This event signals answer in an outgoing call */ + case FTDM_SIGEVENT_UP: + ftdm_log(FTDM_LOG_NOTICE, "Answer received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + break; + /* This event signals hangup from the other end */ + case FTDM_SIGEVENT_STOP: + ftdm_log(FTDM_LOG_NOTICE, "Hangup received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + /* release any timer for this channel */ + release_timers(sigmsg->channel); + break; + default: + ftdm_log(FTDM_LOG_WARNING, "Unhandled event %s in channel %d:%d\n", ftdm_signal_event2str(sigmsg->event_id), + sigmsg->span_id, sigmsg->chan_id); + break; + } + return FTDM_SUCCESS; +} + int main(int argc, char *argv[]) { + ftdm_conf_parameter_t parameters[20]; ftdm_span_t *span; - int local_port, remote_port; - - local_port = remote_port = 53000; - - ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); if (argc < 2) { - printf("umm no\n"); + fprintf(stderr, "Usage: %s \n", argv[0]); exit(-1); } + if (signal(SIGINT, interrupt_requested) == SIG_ERR) { + fprintf(stderr, "Could not set the SIGINT signal handler: %s\n", strerror(errno)); + exit(-1); + } + + /* clear any outstanding timers */ + memset(&g_timers, 0, sizeof(g_timers)); + + /* set the logging level to use */ + ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); + + /* Initialize the FTDM library */ if (ftdm_global_init() != FTDM_SUCCESS) { fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); } + /* create the schedule mutex */ + ftdm_mutex_create(&g_schedule_mutex); + + /* Load the FreeTDM configuration */ if (ftdm_global_configuration() != FTDM_SUCCESS) { fprintf(stderr, "Error configuring FreeTDM\n"); exit(-1); } - printf("FreeTDM loaded\n"); + /* At this point FreeTDM is ready to be used, the spans defined in freetdm.conf have the basic I/O board configuration + * but no telephony signaling configuration at all. */ + printf("FreeTDM loaded ...\n"); - if (ftdm_span_find(atoi(argv[1]), &span) != FTDM_SUCCESS) { - fprintf(stderr, "Error finding FreeTDM span\n"); + /* Retrieve a span by name (according to freetdm.conf) */ + if (ftdm_span_find_by_name(argv[1], &span) != FTDM_SUCCESS) { + fprintf(stderr, "Error finding FreeTDM span %s\n", argv[1]); goto done; } -#if 1 - if (1) { - if (ftdm_configure_span("sangoma_boost", span, on_signal, - "sigmod", "sangoma_brid", - "local_port", &local_port, - "remote_ip", "127.0.0.66", - "remote_port", &remote_port, - TAG_END) == FTDM_SUCCESS) { - ftdm_span_start(span); + /* prepare the configuration parameters that will be sent down to the signaling stack, the array of paramters must be terminated by an + * array element with a null .var member */ - } else { - fprintf(stderr, "Error starting sangoma_boost\n"); - goto done; - } + /* for sangoma_boost signaling (abstraction signaling used by Sangoma for PRI, BRI and SS7) the first parameter you must send + * is sigmod, which must be either sangoma_prid, if you have the PRI stack available, or sangoma_brid for the BRI stack */ + parameters[0].var = "sigmod"; + parameters[0].val = "sangoma_prid"; + + /* following parameters are signaling stack specific, this ones are for PRI */ + parameters[1].var = "switchtype"; + parameters[1].val = "national"; + + parameters[2].var = "signalling"; + parameters[2].val = "pri_cpe"; + + /* the last parameter .var member must be NULL! */ + parameters[3].var = NULL; + + /* send the configuration values down to the stack */ + if (ftdm_configure_span_signaling("sangoma_boost", span, on_signaling_event, parameters) != FTDM_SUCCESS) { + fprintf(stderr, "Error configuring sangoma_boost signaling abstraction in span %s\n", span->name); + goto done; } -#endif - while(ftdm_running() && R) { + /* configuration succeeded, we can proceed now to start the span + * This step will launch at least 1 background (may be more, depending on the signaling stack used) + * to handle *ALL* signaling events for this span, your on_signaling_event callback will be called always + * in one of those infraestructure threads and you MUST NOT block in that handler to avoid delays and errors + * in the signaling processing for any call. + * */ + ftdm_span_start(span); + + app_running = 1; + + /* The application thread can go on and do anything else, like waiting for a shutdown signal */ + while(ftdm_running() && app_running) { ftdm_sleep(1 * 1000); + run_timers(); } - + printf("Shutting down FreeTDM ...\n"); done: + ftdm_mutex_destroy(&g_schedule_mutex); + + /* whenever you're done, this function will shutdown the signaling threads in any span that was started */ ftdm_global_destroy(); return 0; From c1851e2ac4b3573d7da97e58b21a44ee8fe8e589 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 28 Jan 2010 21:37:50 +0000 Subject: [PATCH 1706/1766] add nfas properties to sangoma boost sample program git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1008 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testsangomaboost.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 2adb6c69b5..0998f8d5c1 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -250,6 +250,17 @@ int main(int argc, char *argv[]) parameters[2].var = "signalling"; parameters[2].val = "pri_cpe"; + /* + * parameters[3].var = "nfas_primary"; + * parameters[3].val = "4"; //span number + * + * parameters[4].var = "nfas_secondary"; + * parameters[4].val = "2"; //span number + * + * parameters[5].var = "nfas_group"; + * parameters[5].val = "1"; + * */ + /* the last parameter .var member must be NULL! */ parameters[3].var = NULL; From 558ca085de2effc9ea1f8b595178beff062e7f85 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 29 Jan 2010 19:03:45 +0000 Subject: [PATCH 1707/1766] update sigboost.h to version 102 git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1009 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ftmod/ftmod_sangoma_boost/sigboost.h | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h index 37a3803faa..f115f1e493 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h @@ -14,7 +14,7 @@ #ifndef _SIGBOOST_H_ #define _SIGBOOST_H_ -#define SIGBOOST_VERSION 100 +#define SIGBOOST_VERSION 102 // handy to define integer types that actually work on both Lin and Win #include @@ -28,22 +28,22 @@ enum e_sigboost_event_id_values SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/ SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/ SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ - /* CALL_RELEASED is aimed to fix a race condition that became obvious - * when the boost socket was replaced by direct function calls - * and the channel hunting was moved to 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. - * */ - SIGBOOST_EVENT_CALL_RELEASED = 0x51, /* 81 */ SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ - SIGBOOST_EVENT_CALL_PROGRESS = 0x50, /*decimal 80*/ + /* 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. + * */ + 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*/ @@ -89,6 +89,11 @@ enum e_sigboost_event_info_par_values SIGBOOST_EVI_PROGRESS = 0x02, }; +enum e_sigboost_progress_flags +{ + SIGBOOST_PROGRESS_RING = (1 << 0), + SIGBOOST_PROGRESS_MEDIA = (1 << 1) +}; #define MAX_DIALED_DIGITS 31 @@ -121,6 +126,7 @@ typedef struct uint32_t trunk_group; uint8_t span; uint8_t chan; + uint32_t flags; /* struct timeval tv; */ uint8_t called_number_digits_count; char called_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */ @@ -149,13 +155,14 @@ typedef struct 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) +static inline int boost_full_event(int event_id) { switch (event_id) { case SIGBOOST_EVENT_CALL_START: @@ -163,9 +170,10 @@ static __inline__ int boost_full_event(int event_id) case SIGBOOST_EVENT_CALL_PROGRESS: return 1; default: - break; + break; } - return 0; + + return 0; } #endif From b7b263e1ce3b18d4b67556159f3a19d4c4154b98 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 29 Jan 2010 19:06:21 +0000 Subject: [PATCH 1708/1766] fix hunting groups to include only voice channels git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1010 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 31 ++++++++++++++++----------- libs/freetdm/src/include/ftdm_types.h | 2 ++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index f3456a2f45..baceacddbc 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1121,8 +1121,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir ftdm_group_find(group_id, &group); } - if (!group ) { - ftdm_log(FTDM_LOG_CRIT, "GROUP NOT DEFINED!\n"); + if (!group) { + ftdm_log(FTDM_LOG_ERROR, "Group %d not defined!\n", group_id); *ftdmchan = NULL; return FTDM_FAIL; } @@ -1130,7 +1130,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir ftdm_group_channel_use_count(group, &count); if (count >= group->chan_count) { - ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); + ftdm_log(FTDM_LOG_ERROR, "All circuits are busy (%d channels used out of %d available).\n", count, group->chan_count); *ftdmchan = NULL; return FTDM_FAIL; } @@ -1163,9 +1163,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && check->state == FTDM_CHANNEL_STATE_DOWN && - check->type != FTDM_CHAN_TYPE_DQ921 && - check->type != FTDM_CHAN_TYPE_DQ931 - + FTDM_IS_VOICE_CHANNEL(check) ) { ftdm_span_t* span = NULL; ftdm_span_find(check->span_id, &span); @@ -1282,9 +1280,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && check->state == FTDM_CHANNEL_STATE_DOWN && - check->type != FTDM_CHAN_TYPE_DQ921 && - check->type != FTDM_CHAN_TYPE_DQ931 - + FTDM_IS_VOICE_CHANNEL(check) ) { if (span && span->channel_request) { @@ -3189,6 +3185,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_chann ftdm_mutex_lock(globals.group_mutex); + ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "Cannot add a null channel to a group\n"); + if (ftdm_group_find_by_name(name, &group) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_DEBUG, "Creating new group:%s\n", name); ftdm_group_create(&group, name); @@ -3200,12 +3198,16 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_chann group->channels[i]->physical_chan_id == ftdmchan->physical_chan_id) { ftdm_mutex_unlock(globals.group_mutex); + ftdm_log(FTDM_LOG_DEBUG, "Channel %d:%d is already added to group %s\n", + group->channels[i]->physical_span_id, + group->channels[i]->physical_chan_id, + name); return FTDM_SUCCESS; } } if (group->chan_count >= FTDM_MAX_CHANNELS_GROUP) { - ftdm_log(FTDM_LOG_CRIT, "Max number of channels exceeded (max:%d)\n", FTDM_MAX_CHANNELS_GROUP); + ftdm_log(FTDM_LOG_ERROR, "Max number of channels exceeded (max:%d)\n", FTDM_MAX_CHANNELS_GROUP); ftdm_mutex_unlock(globals.group_mutex); return FTDM_FAIL; } @@ -3256,9 +3258,12 @@ static ftdm_status_t ftdm_group_add_channels(const char* name, ftdm_span_t* span return FTDM_SUCCESS; } - for (chan_index = (span->chan_count - currindex); chan_index <= span->chan_count; chan_index++) { + for (chan_index = currindex+1; chan_index <= span->chan_count; chan_index++) { + if (!FTDM_IS_VOICE_CHANNEL(span->channels[chan_index])) { + continue; + } if (ftdm_channel_add_to_group(name, span->channels[chan_index])) { - ftdm_log(FTDM_LOG_CRIT, "Failed to add chan:%d to group:%s\n", chan_index, name); + ftdm_log(FTDM_LOG_ERROR, "Failed to add chan:%d to group:%s\n", chan_index, name); } } return FTDM_SUCCESS; @@ -3345,7 +3350,7 @@ FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *na *group = new_group; status = FTDM_SUCCESS; } else { - ftdm_log(FTDM_LOG_CRIT, "Group %s was not added, we exceeded the max number of groups\n", name); + ftdm_log(FTDM_LOG_ERROR, "Group %s was not added, we exceeded the max number of groups\n", name); } ftdm_mutex_unlock(globals.mutex); return status; diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h index 73e499cf7e..d1b3a4f711 100644 --- a/libs/freetdm/src/include/ftdm_types.h +++ b/libs/freetdm/src/include/ftdm_types.h @@ -338,6 +338,8 @@ typedef enum { FTDM_CHAN_TYPE_COUNT } ftdm_chan_type_t; +#define FTDM_IS_VOICE_CHANNEL(ftdm_chan) ((ftdm_chan)->type != FTDM_CHAN_TYPE_DQ921 && (ftdm_chan)->type != FTDM_CHAN_TYPE_DQ931) + #define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t) From 3cfd874ebe475bd20987f0573c66592ecba2e502 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 29 Jan 2010 22:15:05 +0000 Subject: [PATCH 1709/1766] try this git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1011 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c94fff67a4..ef6f183cf6 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -462,6 +462,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (!tech_pvt->zchan) { + goto end; + } zap_channel_clear_token(tech_pvt->zchan, switch_core_session_get_uuid(session)); @@ -505,6 +508,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; } + end: + switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); @@ -1358,7 +1363,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) break; case ZAP_SIGEVENT_STOP: { + private_t *tech_pvt = NULL; while((session = zap_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + tech_pvt->zchan = NULL; zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); @@ -1435,6 +1443,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case ZAP_SIGEVENT_STOP: { + private_t *tech_pvt = NULL; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; if (sigmsg->channel->token_count) { switch_core_session_t *session_a, *session_b, *session_t = NULL; @@ -1490,6 +1499,8 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } while((session = zap_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + tech_pvt->zchan = NULL; channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -1616,7 +1627,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) /* on_call_disconnect from the R2 side */ case ZAP_SIGEVENT_STOP: { + private_t *tech_pvt = NULL; while((session = zap_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + tech_pvt->zchan = NULL; channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -1726,7 +1740,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case ZAP_SIGEVENT_STOP: case ZAP_SIGEVENT_RESTART: { + private_t *tech_pvt = NULL; while((session = zap_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + tech_pvt->zchan = NULL; channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); From 3e8ee9b3e89725e16b32ac0907d2142b17620b00 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 30 Jan 2010 01:57:34 +0000 Subject: [PATCH 1710/1766] add outgoing call support to testsangomaboost git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1012 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testsangomaboost.c | 60 ++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 0998f8d5c1..8caccff5e8 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -67,6 +67,9 @@ static dummy_timer_t g_timers[MAX_CALLS]; /* mutex to protect the timers (both, the test thread and the signaling thread may modify them) */ static ftdm_mutex_t *g_schedule_mutex; +/* unique outgoing channel */ +static ftdm_channel_t *g_outgoing_channel = NULL; + static void interrupt_requested(int signal) { app_running = 0; @@ -174,10 +177,17 @@ static FIO_SIGNAL_CB_FUNCTION(on_signaling_event) /* This event signals answer in an outgoing call */ case FTDM_SIGEVENT_UP: ftdm_log(FTDM_LOG_NOTICE, "Answer received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + /* now the channel is answered and we can use + * ftdm_channel_wait() to wait for input/output in a channel (equivalent to poll() or select()) + * ftdm_channel_read() to read available data in a channel + * ftdm_channel_write() to write to the channel */ break; /* This event signals hangup from the other end */ case FTDM_SIGEVENT_STOP: ftdm_log(FTDM_LOG_NOTICE, "Hangup received in channel %d:%d\n", sigmsg->span_id, sigmsg->chan_id); + if (g_outgoing_channel == sigmsg->channel) { + g_outgoing_channel = NULL; + } /* release any timer for this channel */ release_timers(sigmsg->channel); break; @@ -189,21 +199,62 @@ static FIO_SIGNAL_CB_FUNCTION(on_signaling_event) return FTDM_SUCCESS; } +static void place_call(const ftdm_span_t *span, const char *number) +{ + ftdm_channel_t *ftdmchan = NULL; + ftdm_caller_data_t caller_data = {{ 0 }}; + ftdm_status_t status = FTDM_FAIL; + + caller_data.ani.type = FTDM_TON_NATIONAL; + + /* set destiny number (FIXME: this should be DNIS member in FreeTDM core and signaling module) */ + ftdm_set_string(caller_data.ani.digits, number); + + /* set callerid */ + ftdm_set_string(caller_data.cid_name, "testsangomaboost"); + ftdm_set_string(caller_data.cid_num.digits, "1234"); + + /* request to search for an outgoing channel top down with the given caller data */ + status = ftdm_channel_open_by_span(span->span_id, FTDM_TOP_DOWN, &caller_data, &ftdmchan); + if (status != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n"); + return; + } + + status = ftdm_channel_outgoing_call(ftdmchan); + if (status != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n"); + return; + } + + ftdm_channel_init(ftdmchan); +} + int main(int argc, char *argv[]) { ftdm_conf_parameter_t parameters[20]; ftdm_span_t *span; + char *todial = NULL; + int32_t ticks = 0; if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s [number to dial if any]\n", argv[0]); exit(-1); } + /* register a handler to shutdown things properly */ if (signal(SIGINT, interrupt_requested) == SIG_ERR) { fprintf(stderr, "Could not set the SIGINT signal handler: %s\n", strerror(errno)); exit(-1); } + if (argc >= 3) { + todial = argv[2]; + if (!strlen(todial)) { + todial = NULL; + } + } + /* clear any outstanding timers */ memset(&g_timers, 0, sizeof(g_timers)); @@ -282,8 +333,13 @@ int main(int argc, char *argv[]) /* The application thread can go on and do anything else, like waiting for a shutdown signal */ while(ftdm_running() && app_running) { - ftdm_sleep(1 * 1000); + ftdm_sleep(1000); run_timers(); + ticks++; + if (!(ticks % 10) && todial && !g_outgoing_channel) { + ftdm_log(FTDM_LOG_NOTICE, "Originating call to number %s\n", todial); + place_call(span, todial); + } } printf("Shutting down FreeTDM ...\n"); done: From f1140c352d69df95c85d1a5bfbfcab367cbe9cd6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 1 Feb 2010 15:36:32 +0000 Subject: [PATCH 1711/1766] suppliment to last commit git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1014 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 44 ++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ef6f183cf6..c74d8640bd 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -385,6 +385,10 @@ static switch_status_t channel_on_init(switch_core_session_t *session) channel = switch_core_session_get_channel(session); assert(channel != NULL); + if (!tech_pvt->zchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_SUCCESS; + } /* Move channel's state machine to ROUTING */ switch_channel_set_state(channel, CS_ROUTING); @@ -569,6 +573,11 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (!tech_pvt->zchan) { + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + tmp[0] = dtmf->digit; zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_SEND_DTMF, tmp); @@ -594,7 +603,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->zchan != NULL); + if (!tech_pvt->zchan) { + return SWITCH_STATUS_FALSE; + } /* Digium Cards sometimes timeout several times in a row here. Yes, we support digium cards, ain't we nice....... @@ -703,7 +714,9 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->zchan != NULL); + if (!tech_pvt->zchan) { + return SWITCH_STATUS_FALSE; + } if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { return SWITCH_STATUS_FALSE; @@ -763,6 +776,11 @@ static switch_status_t channel_receive_message_cas(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (!tech_pvt->zchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + zap_log(ZAP_LOG_DEBUG, "Got Freeswitch message in R2 channel %d [%d]\n", tech_pvt->zchan->physical_chan_id, msg->message_id); @@ -822,7 +840,11 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->zchan != NULL); + + if (!tech_pvt->zchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } zap_mutex_lock(tech_pvt->zchan->mutex); if (tech_pvt->zchan->state == ZAP_CHANNEL_STATE_TERMINATING) { @@ -895,6 +917,11 @@ static switch_status_t channel_receive_message_fxo(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (!tech_pvt->zchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: @@ -924,6 +951,11 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (!tech_pvt->zchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: @@ -2891,6 +2923,12 @@ SWITCH_STANDARD_APP(disable_ec_function) } tech_pvt = switch_core_session_get_private(session); + + if (!tech_pvt->zchan) { + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); + return; + } + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOCANCEL, &x); zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_ECHOTRAIN, &x); zap_log(ZAP_LOG_INFO, "Echo Canceller Disabled\n"); From 000b7e78b2ba85a2c7cbf927cdfd436f36e47b6f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 1 Feb 2010 18:16:13 +0000 Subject: [PATCH 1712/1766] move sig callback pointer to the span so it can be called from a function git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1015 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 20 ++++++++++++++++-- libs/openzap/src/include/openzap.h | 2 ++ .../src/ozmod/ozmod_analog/ozmod_analog.c | 18 +++++++--------- .../src/ozmod/ozmod_analog/zap_analog.h | 1 - .../ozmod/ozmod_analog_em/ozmod_analog_em.c | 14 ++++++------- .../src/ozmod/ozmod_analog_em/zap_analog_em.h | 1 - .../openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 21 +++++++++---------- libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h | 1 - .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 19 ++++++++--------- .../src/ozmod/ozmod_libpri/ozmod_libpri.h | 1 - libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c | 16 +++++++------- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 14 ++++++------- .../ozmod_sangoma_boost/zap_sangoma_boost.h | 1 - libs/openzap/src/zap_io.c | 20 ++++++++++++++++++ 14 files changed, 87 insertions(+), 62 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c74d8640bd..b8ca4fe71a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -846,7 +846,6 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, return SWITCH_STATUS_FALSE; } - zap_mutex_lock(tech_pvt->zchan->mutex); if (tech_pvt->zchan->state == ZAP_CHANNEL_STATE_TERMINATING) { zap_mutex_unlock(tech_pvt->zchan->mutex); return SWITCH_STATUS_SUCCESS; @@ -902,7 +901,6 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, break; } - zap_mutex_unlock(tech_pvt->zchan->mutex); return SWITCH_STATUS_SUCCESS; } @@ -992,12 +990,26 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch_status_t status; switch_channel_t *channel; const char *var; + zap_channel_t *zchan = NULL; tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); channel = switch_core_session_get_channel(session); + if (!(zchan = tech_pvt->zchan)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + + zap_mutex_lock(zchan->mutex); + + if (!tech_pvt->zchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + status = SWITCH_STATUS_FALSE; + goto end; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: @@ -1038,6 +1050,10 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s break; } + end: + + zap_mutex_unlock(zchan->mutex); + return status; } diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index c45aaf911a..2a654f2406 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -567,6 +567,7 @@ struct zap_span { zap_analog_start_type_t start_type; zap_signal_type_t signal_type; void *signal_data; + zio_signal_cb_t signal_cb; zap_event_t event_header; char last_error[256]; char tone_map[ZAP_TONEMAP_INVALID+1][ZAP_TONEMAP_LEN]; @@ -692,6 +693,7 @@ OZ_DECLARE(zap_status_t) zap_unload_modules(void); OZ_DECLARE(zap_status_t) zap_configure_span(const char *type, zap_span_t *span, zio_signal_cb_t sig_cb, ...); OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span); OZ_DECLARE(zap_status_t) zap_span_stop(zap_span_t *span); +OZ_DECLARE(zap_status_t) zap_span_send_signal(zap_span_t *span, zap_sigmsg_t *sigmsg); OZ_DECLARE(int) zap_load_module(const char *name); OZ_DECLARE(int) zap_load_module_assume(const char *name); OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 3978c94106..595f0ecebc 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -176,7 +176,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) analog_data->flags = flags; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; - analog_data->sig_cb = sig_cb; + 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; @@ -481,7 +481,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_UP; } - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); continue; } break; @@ -501,14 +501,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) zap_set_string(zchan->caller_data.dnis.digits, dtmf); } - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); continue; } break; case ZAP_CHANNEL_STATE_DOWN: { sig.event_id = ZAP_SIGEVENT_STOP; - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); goto done; } break; @@ -549,7 +549,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.span_id = zchan->span_id; sig.channel = zchan; sig.event_id = ZAP_SIGEVENT_PROGRESS; - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); } break; @@ -608,7 +608,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) last_digit = elapsed; sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; sig.raw_data = dtmf; - if (analog_data->sig_cb(&sig) == ZAP_BREAK) { + if (zap_span_send_signal(zchan->span, &sig) == ZAP_BREAK) { collecting = 0; } } @@ -654,9 +654,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) if (zchan->detected_tones[i]) { zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id); sig.raw_data = &i; - if (analog_data->sig_cb) { - analog_data->sig_cb(&sig); - } + zap_span_send_signal(zchan->span, &sig); } } @@ -843,7 +841,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP); } else { sig.event_id = ZAP_SIGEVENT_FLASH; - analog_data->sig_cb(&sig); + zap_span_send_signal(span, &sig); } } break; diff --git a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h index 563285eb2c..3ffa422ead 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h +++ b/libs/openzap/src/ozmod/ozmod_analog/zap_analog.h @@ -48,7 +48,6 @@ struct zap_analog_data { uint32_t max_dialstr; uint32_t digit_timeout; char hotline[ZAP_MAX_HOTLINE_STR]; - zio_signal_cb_t sig_cb; }; 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 index 4468e4b92d..581c6dd45a 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/openzap/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -145,7 +145,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) span->start = zap_analog_em_start; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; - analog_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_ANALOG; span->signal_data = analog_data; span->outgoing_call = analog_em_outgoing_call; @@ -349,7 +349,7 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_UP; - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); continue; } break; @@ -370,14 +370,14 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) sig.event_id = ZAP_SIGEVENT_START; - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); continue; } break; case ZAP_CHANNEL_STATE_DOWN: { sig.event_id = ZAP_SIGEVENT_STOP; - analog_data->sig_cb(&sig); + zap_span_send_signal(zchan->span, &sig); goto done; } break; @@ -440,7 +440,7 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) last_digit = elapsed; sig.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; sig.raw_data = dtmf; - if (analog_data->sig_cb(&sig) == ZAP_BREAK) { + if (zap_span_send_signal(zchan->span, &sig) == ZAP_BREAK) { collecting = 0; } } @@ -480,9 +480,7 @@ static void *zap_analog_em_channel_run(zap_thread_t *me, void *obj) if (zchan->detected_tones[i]) { zap_log(ZAP_LOG_DEBUG, "Detected tone %s on %d:%d\n", zap_tonemap2str(i), zchan->span_id, zchan->chan_id); sig.raw_data = &i; - if (analog_data->sig_cb) { - analog_data->sig_cb(&sig); - } + zap_span_send_signal(zchan->span, &sig); } } 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 index 5f0f726063..eb9f9f3d20 100644 --- a/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h +++ b/libs/openzap/src/ozmod/ozmod_analog_em/zap_analog_em.h @@ -51,7 +51,6 @@ struct zap_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; - zio_signal_cb_t sig_cb; }; static void *zap_analog_em_run(zap_thread_t *me, void *obj); diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index e4e9a1511f..3c061960a1 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -699,7 +699,7 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) sig.channel->caller_data.hangup_cause = (cause) ? cause->Value : ZAP_CAUSE_NORMAL_UNSPECIFIED; sig.event_id = ZAP_SIGEVENT_STOP; - status = isdn_data->sig_cb(&sig); + 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); } @@ -1186,7 +1186,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -1230,7 +1230,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_START; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -1240,7 +1240,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED; sig.event_id = ZAP_SIGEVENT_RESTART; - status = isdn_data->sig_cb(&sig); + status = zap_span_send_signal(zchan->span, &sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; @@ -1248,7 +1248,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -1268,7 +1268,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -1473,7 +1473,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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 = isdn_data->sig_cb(&sig); + 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); @@ -1513,7 +1513,6 @@ static __inline__ void check_state(zap_span_t *span) static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; - zap_isdn_data_t *isdn_data = span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -1538,7 +1537,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + zap_span_send_signal(span, &sig); 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, @@ -1554,7 +1553,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + zap_span_send_signal(span, &sig); } break; } @@ -2355,7 +2354,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) span->start = zap_isdn_start; span->stop = zap_isdn_stop; - isdn_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; diff --git a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h index b16b004a9d..c5e0e5a711 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h +++ b/libs/openzap/src/ozmod/ozmod_isdn/zap_isdn.h @@ -60,7 +60,6 @@ struct zap_isdn_data { zap_channel_t *dchan; zap_channel_t *dchans[2]; struct zap_sigmsg sigmsg; - zio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; int32_t digit_timeout; diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index a8e3fea6f7..0c8aadede3 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -454,7 +454,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { @@ -468,7 +468,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { @@ -484,7 +484,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (call) { pri_acknowledge(isdn_data->spri.pri, call, zchan->chan_id, 0); sig.event_id = ZAP_SIGEVENT_START; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -497,7 +497,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_UNSPECIFIED; sig.event_id = ZAP_SIGEVENT_RESTART; - status = isdn_data->sig_cb(&sig); + status = zap_span_send_signal(zchan->span, &sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } break; @@ -505,7 +505,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = isdn_data->sig_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else if (call) { @@ -579,7 +579,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_TERMINATING: { sig.event_id = ZAP_SIGEVENT_STOP; - status = isdn_data->sig_cb(&sig); + status = zap_span_send_signal(zchan->span, &sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } @@ -807,7 +807,6 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { zap_sigmsg_t sig; - zap_libpri_data_t *isdn_data = span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -832,7 +831,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + zap_span_send_signal(span, &sig); 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, @@ -848,7 +847,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + zap_span_send_signal(span, &sig); } break; } @@ -1329,7 +1328,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) span->start = zap_libpri_start; span->stop = zap_libpri_stop; - isdn_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; //isdn_data->dchans[0] = dchans[0]; //isdn_data->dchans[1] = dchans[1]; //isdn_data->dchan = isdn_data->dchans[0]; diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h index 4e33aba17d..8c929516ba 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.h @@ -55,7 +55,6 @@ struct zap_libpri_data { zap_channel_t *dchan; zap_channel_t *dchans[2]; struct zap_sigmsg sigmsg; - zio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; zap_isdn_opts_t opts; diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c index f911e67d95..a8c8abf0fc 100644 --- a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c @@ -91,8 +91,6 @@ typedef struct oz_r2_conf_s { /* r2 configuration stored in span->signal_data */ typedef struct zap_r2_data_s { - /* signaling callback */ - zio_signal_cb_t sig_cb; /* span flags */ zap_r2_flag_t flags; /* openr2 handle for the R2 variant context */ @@ -254,7 +252,7 @@ static void zap_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const sigev.channel = zchan; sigev.event_id = ZAP_SIGEVENT_START; - if (r2data->sig_cb(&sigev) != ZAP_SUCCESS) { + 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); @@ -324,7 +322,7 @@ static void zap_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_disconn sigev.event_id = ZAP_SIGEVENT_STOP; r2data = zchan->span->signal_data; - r2data->sig_cb(&sigev); + zap_span_send_signal(zchan->span, &sigev); } static void zap_r2_on_call_end(openr2_chan_t *r2chan) @@ -378,7 +376,7 @@ static void zap_r2_on_protocol_error(openr2_chan_t *r2chan, openr2_protocol_erro sigev.event_id = ZAP_SIGEVENT_STOP; r2data = zchan->span->signal_data; - r2data->sig_cb(&sigev); + zap_span_send_signal(zchan->span, &sigev); } static void zap_r2_on_line_blocked(openr2_chan_t *r2chan) @@ -461,7 +459,7 @@ static int zap_r2_on_dnis_digit_received(openr2_chan_t *r2chan, char digit) sigev.channel = zchan; sigev.event_id = ZAP_SIGEVENT_COLLECTED_DIGIT; r2data = zchan->span->signal_data; - if (r2data->sig_cb(&sigev) == ZAP_BREAK) { + 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; } @@ -885,7 +883,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) span->start = zap_r2_start; r2data->flags = 0; - r2data->sig_cb = sig_cb; + span->signal_cb = sig_cb; span->signal_type = ZAP_SIGTYPE_R2; span->signal_data = r2data; span->outgoing_call = r2_outgoing_call; @@ -1005,7 +1003,7 @@ static void *zap_r2_channel_run(zap_thread_t *me, void *obj) } else { zap_log(ZAP_LOG_DEBUG, "PROGRESS: Notifying progress in channel %d\n", zchan->physical_chan_id); sigev.event_id = ZAP_SIGEVENT_PROGRESS; - if (r2data->sig_cb(&sigev) != ZAP_SUCCESS) { + if (zap_span_send_signal(zchan->span, &sigev) != ZAP_SUCCESS) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -1028,7 +1026,7 @@ static void *zap_r2_channel_run(zap_thread_t *me, void *obj) } 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 (r2data->sig_cb(&sigev) != ZAP_SUCCESS) { + if (zap_span_send_signal(zchan->span, &sigev) != ZAP_SUCCESS) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } 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 index ffbc4c8d33..9b97c93803 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -996,7 +996,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS_MEDIA; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -1017,7 +1017,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_PROGRESS; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -1042,7 +1042,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (!zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_START; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } @@ -1051,7 +1051,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) case ZAP_CHANNEL_STATE_RESTART: { sig.event_id = ZAP_SIGEVENT_RESTART; - status = sangoma_boost_data->signal_cb(&sig); + 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); } @@ -1060,7 +1060,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { if (zap_test_flag(zchan, ZAP_CHANNEL_OUTBOUND)) { sig.event_id = ZAP_SIGEVENT_UP; - if ((status = sangoma_boost_data->signal_cb(&sig) != ZAP_SUCCESS)) { + if ((status = zap_span_send_signal(zchan->span, &sig) != ZAP_SUCCESS)) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); } } else { @@ -1125,7 +1125,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { zap_set_sflag_locked(zchan, SFLAG_TERMINATING); sig.event_id = ZAP_SIGEVENT_STOP; - status = sangoma_boost_data->signal_cb(&sig); + status = zap_span_send_signal(zchan->span, &sig); zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } break; @@ -1593,7 +1593,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_sangoma_boost_configure_span) 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; - sangoma_boost_data->signal_cb = sig_cb; + span->signal_cb = sig_cb; span->start = zap_sangoma_boost_start; span->signal_data = sangoma_boost_data; span->signal_type = ZAP_SIGTYPE_SANGOMABOOST; 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 index 932787c93a..a48060812b 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/zap_sangoma_boost.h @@ -44,7 +44,6 @@ typedef enum { typedef struct zap_sangoma_boost_data { sangomabc_connection_t mcon; sangomabc_connection_t pcon; - zio_signal_cb_t signal_cb; uint32_t flags; } zap_sangoma_boost_data_t; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 3abae9fea1..4044621825 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2735,6 +2735,26 @@ OZ_DECLARE(zap_status_t) zap_span_start(zap_span_t *span) return ZAP_FAIL; } +OZ_DECLARE(zap_status_t) zap_span_send_signal(zap_span_t *span, zap_sigmsg_t *sigmsg) +{ + zap_status_t status = ZAP_FAIL; + + if (span->signal_cb) { + + if (sigmsg->channel) { + zap_mutex_lock(sigmsg->channel->mutex); + } + + status = span->signal_cb(sigmsg); + + if (sigmsg->channel) { + zap_mutex_unlock(sigmsg->channel->mutex); + } + } + + return status; +} + OZ_DECLARE(zap_status_t) zap_global_init(void) { From 926f140754ed3ac560c459c5ab8c7a2416b9aa14 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 1 Feb 2010 21:40:01 +0000 Subject: [PATCH 1713/1766] replace use of ani in favor of dnis in caller_data structure for the destiny number in outgoing calls git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1017 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 14 +++++++------- .../src/ftmod/ftmod_analog/ftmod_analog.c | 6 +++--- .../src/ftmod/ftmod_analog_em/ftmod_analog_em.c | 6 +++--- libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 10 +++++----- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 4 ++-- libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c | 2 +- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 8 ++++---- libs/freetdm/src/testsangomaboost.c | 16 +++++++++++----- 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 023ab8e26e..ba34f8db86 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -1130,24 +1130,24 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (!zstr(dest)) { - ftdm_set_string(caller_data.ani.digits, dest); + ftdm_set_string(caller_data.dnis.digits, dest); } if ((var = switch_event_get_header(var_event, "freetdm_outbound_ton")) || (var = switch_core_get_variable("freetdm_outbound_ton"))) { if (!strcasecmp(var, "national")) { - caller_data.ani.type = FTDM_TON_NATIONAL; + caller_data.dnis.type = FTDM_TON_NATIONAL; } else if (!strcasecmp(var, "international")) { - caller_data.ani.type = FTDM_TON_INTERNATIONAL; + caller_data.dnis.type = FTDM_TON_INTERNATIONAL; } else if (!strcasecmp(var, "local")) { - caller_data.ani.type = FTDM_TON_SUBSCRIBER_NUMBER; + caller_data.dnis.type = FTDM_TON_SUBSCRIBER_NUMBER; } else if (!strcasecmp(var, "unknown")) { - caller_data.ani.type = FTDM_TON_UNKNOWN; + caller_data.dnis.type = FTDM_TON_UNKNOWN; } } else { - caller_data.ani.type = outbound_profile->destination_number_ton; + caller_data.dnis.type = outbound_profile->destination_number_ton; } - caller_data.ani.plan = outbound_profile->destination_number_numplan; + caller_data.dnis.plan = outbound_profile->destination_number_numplan; #if 0 diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index feb4d5cbdf..4ef3d2a13e 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -669,11 +669,11 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) ftdm_log(FTDM_LOG_ERROR, "Failure indication detected!\n"); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); } else if (ftdmchan->detected_tones[FTDM_TONEMAP_DIAL]) { - if (ftdm_strlen_zero(ftdmchan->caller_data.ani.digits)) { + if (ftdm_strlen_zero(ftdmchan->caller_data.dnis.digits)) { ftdm_log(FTDM_LOG_ERROR, "No Digits to send!\n"); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); } else { - if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.ani.digits) != FTDM_SUCCESS) { + if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.dnis.digits) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Send Digits Failed [%s]\n", ftdmchan->last_error); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); } else { @@ -683,7 +683,7 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) ftdmchan->needed_tones[FTDM_TONEMAP_FAIL1] = 1; ftdmchan->needed_tones[FTDM_TONEMAP_FAIL2] = 1; ftdmchan->needed_tones[FTDM_TONEMAP_FAIL3] = 1; - dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.ani.digits)) + 2000; + dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.dnis.digits)) + 2000; } } } else if (ftdmchan->detected_tones[FTDM_TONEMAP_RING]) { diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c index edadc25222..42e1ab1ee8 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c @@ -248,11 +248,11 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) { if (! ftdmchan->needed_tones[FTDM_TONEMAP_RING] && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_WINK)) { - if (ftdm_strlen_zero(ftdmchan->caller_data.ani.digits)) { + if (ftdm_strlen_zero(ftdmchan->caller_data.dnis.digits)) { ftdm_log(FTDM_LOG_ERROR, "No Digits to send!\n"); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); } else { - if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.ani.digits) != FTDM_SUCCESS) { + if (ftdm_channel_command(ftdmchan, FTDM_COMMAND_SEND_DTMF, ftdmchan->caller_data.dnis.digits) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Send Digits Failed [%s]\n", ftdmchan->last_error); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_BUSY); } else { @@ -262,7 +262,7 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) ftdmchan->needed_tones[FTDM_TONEMAP_FAIL1] = 1; ftdmchan->needed_tones[FTDM_TONEMAP_FAIL2] = 1; ftdmchan->needed_tones[FTDM_TONEMAP_FAIL3] = 1; - dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.ani.digits)) + 2000; + dial_timeout = ((ftdmchan->dtmf_on + ftdmchan->dtmf_off) * strlen(ftdmchan->caller_data.dnis.digits)) + 2000; } } break; diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index fa9e176972..fe9009da58 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -411,10 +411,10 @@ static FIO_CHANNEL_REQUEST_FUNCTION(isdn_channel_request) Q931InitIECalledNum(&CalledNum); CalledNum.TypNum = Q931_TON_UNKNOWN; CalledNum.NumPlanID = Q931_NUMPLAN_E164; - CalledNum.Size = CalledNum.Size + (unsigned char)strlen(caller_data->ani.digits); + CalledNum.Size = CalledNum.Size + (unsigned char)strlen(caller_data->dnis.digits); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); - ftdm_copy_string((char *)ptrCalledNum->Digit, caller_data->ani.digits, strlen(caller_data->ani.digits)+1); + ftdm_copy_string((char *)ptrCalledNum->Digit, caller_data->dnis.digits, strlen(caller_data->dnis.digits)+1); /* * High-Layer Compatibility IE (Note: Required for AVM FritzBox) @@ -1374,12 +1374,12 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) * CalledNum IE */ Q931InitIECalledNum(&CalledNum); - CalledNum.TypNum = Q931_TON_UNKNOWN; + CalledNum.TypNum = ftdmchan->caller_data.dnis.type; CalledNum.NumPlanID = Q931_NUMPLAN_E164; - CalledNum.Size = CalledNum.Size + (unsigned char)strlen(ftdmchan->caller_data.ani.digits); + CalledNum.Size = CalledNum.Size + (unsigned char)strlen(ftdmchan->caller_data.dnis.digits); gen->CalledNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CalledNum); ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf); - ftdm_copy_string((char *)ptrCalledNum->Digit, ftdmchan->caller_data.ani.digits, strlen(ftdmchan->caller_data.ani.digits)+1); + ftdm_copy_string((char *)ptrCalledNum->Digit, ftdmchan->caller_data.dnis.digits, strlen(ftdmchan->caller_data.dnis.digits)+1); /* * High-Layer Compatibility IE (Note: Required for AVM FritzBox) diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index c8189d91c1..0874bfafa1 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -526,7 +526,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) } - dp = ftdmchan->caller_data.ani.type; + dp = ftdmchan->caller_data.dnis.type; switch(dp) { case FTDM_TON_NATIONAL: dp = PRI_NATIONAL_ISDN; @@ -546,7 +546,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) assert(sr); pri_sr_set_channel(sr, ftdmchan->chan_id, 0, 0); pri_sr_set_bearer(sr, 0, isdn_data->l1); - pri_sr_set_called(sr, ftdmchan->caller_data.ani.digits, dp, 1); + pri_sr_set_called(sr, ftdmchan->caller_data.dnis.digits, dp, 1); pri_sr_set_caller(sr, ftdmchan->caller_data.cid_num.digits, (isdn_data->opts & FTMOD_LIBPRI_OPT_OMIT_DISPLAY_IE ? NULL : ftdmchan->caller_data.cid_name), dp, (ftdmchan->caller_data.pres != 1 ? PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN : PRES_PROHIB_USER_NUMBER_NOT_SCREENED)); diff --git a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c index f9f78c230f..4453bce887 100644 --- a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c +++ b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c @@ -984,7 +984,7 @@ static void *ftdm_r2_channel_run(ftdm_thread_t *me, void *obj) // FIXME: use user defined calling party ftdm_channel_use(ftdmchan); ftdm_log(FTDM_LOG_DEBUG, "DIALING: Starting processing of outgoing call in channel %d with interval %d\n", ftdmchan->physical_chan_id, interval); - if (openr2_chan_make_call(r2chan, ftdmchan->caller_data.cid_num.digits, ftdmchan->caller_data.ani.digits, OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER)) { + if (openr2_chan_make_call(r2chan, ftdmchan->caller_data.cid_num.digits, ftdmchan->caller_data.dnis.digits, OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER)) { ftdm_log(FTDM_LOG_ERROR, "%d:%d Failed to make call in R2 channel, openr2_chan_make_call failed\n", ftdmchan->span_id, ftdmchan->chan_id); ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_DESTINATION_OUT_OF_ORDER; ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 7e82c84479..7326289f25 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -294,7 +294,7 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) sangomabc_event_t event = {0}; int boost_request_timeout = 5000; sangoma_boost_request_status_t st; - char ani[128] = ""; + char dnis[128] = ""; char *gr = NULL; uint32_t count = 0; int tg=0; @@ -304,7 +304,7 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) return FTDM_FAIL; } - ftdm_set_string(ani, caller_data->ani.digits); + ftdm_set_string(dnis, caller_data->dnis.digits); r = next_request_id(); if (r == 0) { @@ -312,7 +312,7 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) *ftdmchan = NULL; return FTDM_FAIL; } - sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r); + sangomabc_call_init(&event, caller_data->cid_num.digits, dnis, r); if (sangoma_boost_data->sigmod) { *ftdmchan = span->channels[chan_id]; @@ -325,7 +325,7 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) OUTBOUND_REQUESTS[r].ftdmchan = *ftdmchan; } else { - if ((gr = strchr(ani, '@'))) { + if ((gr = strchr(dnis, '@'))) { *gr++ = '\0'; } diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 8caccff5e8..d50f5e54f9 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -190,6 +190,8 @@ static FIO_SIGNAL_CB_FUNCTION(on_signaling_event) } /* release any timer for this channel */ release_timers(sigmsg->channel); + /* acknowledge the hangup */ + ftdm_set_state_locked(sigmsg->channel, FTDM_CHANNEL_STATE_HANGUP); break; default: ftdm_log(FTDM_LOG_WARNING, "Unhandled event %s in channel %d:%d\n", ftdm_signal_event2str(sigmsg->event_id), @@ -205,28 +207,32 @@ static void place_call(const ftdm_span_t *span, const char *number) ftdm_caller_data_t caller_data = {{ 0 }}; ftdm_status_t status = FTDM_FAIL; - caller_data.ani.type = FTDM_TON_NATIONAL; - - /* set destiny number (FIXME: this should be DNIS member in FreeTDM core and signaling module) */ - ftdm_set_string(caller_data.ani.digits, number); + /* set destiny number */ + ftdm_set_string(caller_data.dnis.digits, number); /* set callerid */ ftdm_set_string(caller_data.cid_name, "testsangomaboost"); ftdm_set_string(caller_data.cid_num.digits, "1234"); - /* request to search for an outgoing channel top down with the given caller data */ + /* request to search for an outgoing channel top down with the given caller data. + * it is also an option to use ftdm_channel_open_by_group to let freetdm hunt + * an available channel in a given group instead of per span + * */ status = ftdm_channel_open_by_span(span->span_id, FTDM_TOP_DOWN, &caller_data, &ftdmchan); if (status != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n"); return; } + g_outgoing_channel = ftdmchan; + status = ftdm_channel_outgoing_call(ftdmchan); if (status != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n"); return; } + /* this is required to initialize the outgoing channel */ ftdm_channel_init(ftdmchan); } From 91c53552b695c5e479c4ed3df97adb4ebe50753d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 1 Feb 2010 23:26:34 +0000 Subject: [PATCH 1714/1766] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1018 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 35 +++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index b8ca4fe71a..958d327365 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -385,7 +385,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session) channel = switch_core_session_get_channel(session); assert(channel != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_SUCCESS; } @@ -573,7 +573,7 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_FALSE; } @@ -599,11 +599,11 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch channel = switch_core_session_get_channel(session); assert(channel != NULL); - + tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { return SWITCH_STATUS_FALSE; } @@ -613,10 +613,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch chunk = tech_pvt->zchan->effective_interval * 2; total_to = chunk * 6; - if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { - return SWITCH_STATUS_FALSE; - } - top: if (switch_channel_test_flag(channel, CF_SUSPEND)) { @@ -776,7 +772,7 @@ static switch_status_t channel_receive_message_cas(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_FALSE; } @@ -841,7 +837,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_FALSE; } @@ -915,7 +911,7 @@ static switch_status_t channel_receive_message_fxo(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_FALSE; } @@ -949,7 +945,7 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_FALSE; } @@ -997,6 +993,11 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s channel = switch_core_session_get_channel(session); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + if (!(zchan = tech_pvt->zchan)) { switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); return SWITCH_STATUS_FALSE; @@ -1414,7 +1415,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) private_t *tech_pvt = NULL; while((session = zap_channel_get_session(sigmsg->channel, 0))) { tech_pvt = switch_core_session_get_private(session); - tech_pvt->zchan = NULL; + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); zap_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); @@ -1548,7 +1549,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_fxs_signal) while((session = zap_channel_get_session(sigmsg->channel, 0))) { tech_pvt = switch_core_session_get_private(session); - tech_pvt->zchan = NULL; + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -1678,7 +1679,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) private_t *tech_pvt = NULL; while((session = zap_channel_get_session(sigmsg->channel, 0))) { tech_pvt = switch_core_session_get_private(session); - tech_pvt->zchan = NULL; + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -1791,7 +1792,7 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) private_t *tech_pvt = NULL; while((session = zap_channel_get_session(sigmsg->channel, 0))) { tech_pvt = switch_core_session_get_private(session); - tech_pvt->zchan = NULL; + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); zap_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -2940,7 +2941,7 @@ SWITCH_STANDARD_APP(disable_ec_function) tech_pvt = switch_core_session_get_private(session); - if (!tech_pvt->zchan) { + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); return; } From 8667596ab449f84d735b0fd4181aa0d3c6a7f94d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 2 Feb 2010 19:11:07 +0000 Subject: [PATCH 1715/1766] Windows build fixes, inline and unsigned stuff git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1019 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 2 +- libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index baceacddbc..a1fee89395 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -3249,7 +3249,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ft static ftdm_status_t ftdm_group_add_channels(const char* name, ftdm_span_t* span, int currindex) { - int chan_index = 0; + unsigned chan_index = 0; ftdm_assert_return(strlen(name) > 0, FTDM_FAIL, "Invalid group name provided\n"); ftdm_assert_return(currindex >= 0, FTDM_FAIL, "Invalid current channel index provided\n"); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h index f115f1e493..9c3be35260 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h @@ -162,12 +162,12 @@ typedef struct #pragma pack() -static inline int boost_full_event(int event_id) +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: + case SIGBOOST_EVENT_CALL_PROGRESS: return 1; default: break; From e0a1c77c60f99766b90695d3c4b86a48c2dad345 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 2 Feb 2010 20:30:00 +0000 Subject: [PATCH 1716/1766] add testsangomaboost visual studio project git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1020 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/freetdm.2008.sln | 6 ++++++ libs/freetdm/src/testsangomaboost.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/libs/freetdm/freetdm.2008.sln b/libs/freetdm/freetdm.2008.sln index 8766670aa1..363ea1e996 100644 --- a/libs/freetdm/freetdm.2008.sln +++ b/libs/freetdm/freetdm.2008.sln @@ -53,6 +53,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testboost", "msvc\testboost {93B8812C-3EC4-4F78-8970-FFBFC99E167D} = {93B8812C-3EC4-4F78-8970-FFBFC99E167D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsangomaboost", "msvc\testboost\testsangomaboost.2008.vcproj", "{0DA69C18-4FA1-4E8C-89CE-12498637C5BE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -99,6 +101,10 @@ Global {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Debug|Win32.Build.0 = Debug|Win32 {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Release|Win32.ActiveCfg = Release|Win32 {2B1BAF36-0241-43E7-B865-A8338AD48E2E}.Release|Win32.Build.0 = Release|Win32 + {0DA69C18-4FA1-4E8C-89CE-12498637C5BE}.Debug|Win32.ActiveCfg = Debug|Win32 + {0DA69C18-4FA1-4E8C-89CE-12498637C5BE}.Debug|Win32.Build.0 = Debug|Win32 + {0DA69C18-4FA1-4E8C-89CE-12498637C5BE}.Release|Win32.ActiveCfg = Release|Win32 + {0DA69C18-4FA1-4E8C-89CE-12498637C5BE}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index d50f5e54f9..37ffc5dd26 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -39,10 +39,15 @@ * compile this program linking to the freetdm library (ie -lfreetdm) **/ +#ifndef __linux__ +#define _CRT_SECURE_NO_WARNINGS 1 +#endif + #include #include "freetdm.h" + /* arbitrary limit for max calls in this sample program */ #define MAX_CALLS 255 From 3bcd1c1f2d5dd6b0b3f12e300cdeade7d102bfa8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 3 Feb 2010 01:30:06 +0000 Subject: [PATCH 1717/1766] try disabling ring trip events in fxs channels to avoid issue with calls being hung up incorrectly on answer git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1021 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 8dad35dca5..0ef2e02287 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -274,6 +274,15 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, } } +#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 */ @@ -990,11 +999,14 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; From 05da6d928a6d5950188f69ae4e7e8129a99bb3fc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 4 Feb 2010 19:21:22 +0000 Subject: [PATCH 1718/1766] added valid state from TERMINATING to HANGUP for outbound calls fixed state changes when remote side hangs up git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1023 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 index 9b97c93803..b9d3460988 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1095,7 +1095,7 @@ static __inline__ void state_advance(zap_channel_t *zchan) { zap_set_sflag_locked(zchan, SFLAG_HANGUP); - if (zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) { + 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); @@ -1126,7 +1126,6 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_sflag_locked(zchan, SFLAG_TERMINATING); sig.event_id = ZAP_SIGEVENT_STOP; status = zap_span_send_signal(zchan->span, &sig); - zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE); } break; default: @@ -1468,7 +1467,7 @@ static zap_state_map_t boost_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_TERMINATING, ZAP_END}, - {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_END} + {ZAP_CHANNEL_STATE_HANGUP_COMPLETE, ZAP_CHANNEL_STATE_HANGUP, ZAP_END} }, { ZSD_OUTBOUND, From dd77a7c5cf6583d896f3b55b3e205db31dbcb5d6 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 9 Feb 2010 19:25:26 +0000 Subject: [PATCH 1719/1766] added ozreplace.sh handy script git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1024 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/ozreplace.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 libs/freetdm/ozreplace.sh diff --git a/libs/freetdm/ozreplace.sh b/libs/freetdm/ozreplace.sh new file mode 100755 index 0000000000..71f4b13766 --- /dev/null +++ b/libs/freetdm/ozreplace.sh @@ -0,0 +1,13 @@ +##### ozmod stuff #### +# replace full openzap occurences first (handles openzap.h, libopenzap etc) +sed -i 's,openzap,freetdm,g' $1 +sed -i 's,ozmod,ftmod,g' $1 + +sed -i 's,zchan,ftdmchan,g' $1 +sed -i 's,oz,ft,g' $1 +sed -i 's,OZ,FT,g' $1 +sed -i 's,zap,ftdm,g' $1 +sed -i 's,ZAP,FTDM,g' $1 +sed -i 's,zio,fio,g' $1 +sed -i 's,ZIO,FIO,g' $1 + From 0900125be498137fa41f8a08e8655f5e623b38ee Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 9 Feb 2010 21:51:08 +0000 Subject: [PATCH 1720/1766] use suggest_chan_id when sigmod is present git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1025 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 7326289f25..cb6c2522ed 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -2018,7 +2018,11 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) span->get_span_sig_status = sangoma_boost_get_span_sig_status; span->set_span_sig_status = sangoma_boost_set_span_sig_status; span->state_map = &boost_state_map; - span->suggest_chan_id = 1; + if (sigmod_iface) { + span->suggest_chan_id = 1; + } else { + span->suggest_chan_id = 0; + } ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED); return FTDM_SUCCESS; } From 0d392527dc66b97146de2b3d1977e382d1231939 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 9 Feb 2010 22:01:15 +0000 Subject: [PATCH 1721/1766] merged 956:1023 (partial merge - anything non-boost related) git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1026 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 100 +++++++++++++++--- libs/freetdm/src/ftdm_io.c | 19 ++++ .../src/ftmod/ftmod_analog/ftdm_analog.h | 1 - .../src/ftmod/ftmod_analog/ftmod_analog.c | 18 ++-- .../ftmod/ftmod_analog_em/ftdm_analog_em.h | 1 - .../ftmod/ftmod_analog_em/ftmod_analog_em.c | 14 ++- libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h | 1 - .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 21 ++-- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 19 ++-- .../src/ftmod/ftmod_libpri/ftmod_libpri.h | 1 - libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c | 16 ++- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 26 +++++ libs/freetdm/src/include/freetdm.h | 6 +- 13 files changed, 177 insertions(+), 66 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index ba34f8db86..496131a213 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -385,6 +385,10 @@ static switch_status_t channel_on_init(switch_core_session_t *session) channel = switch_core_session_get_channel(session); assert(channel != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_SUCCESS; + } /* Move channel's state machine to ROUTING */ switch_channel_set_state(channel, CS_ROUTING); @@ -462,6 +466,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (!tech_pvt->ftdmchan) { + goto end; + } ftdm_channel_clear_token(tech_pvt->ftdmchan, switch_core_session_get_uuid(session)); @@ -505,6 +512,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) break; } + end: + switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); @@ -564,6 +573,11 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + tmp[0] = dtmf->digit; ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_SEND_DTMF, tmp); @@ -585,11 +599,13 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch channel = switch_core_session_get_channel(session); assert(channel != NULL); - + tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->ftdmchan != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + return SWITCH_STATUS_FALSE; + } /* Digium Cards sometimes timeout several times in a row here. Yes, we support digium cards, ain't we nice....... @@ -597,10 +613,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch chunk = tech_pvt->ftdmchan->effective_interval * 2; total_to = chunk * 6; - if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { - return SWITCH_STATUS_FALSE; - } - top: if (switch_channel_test_flag(channel, CF_SUSPEND)) { @@ -698,7 +710,9 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->ftdmchan != NULL); + if (!tech_pvt->ftdmchan) { + return SWITCH_STATUS_FALSE; + } if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { return SWITCH_STATUS_FALSE; @@ -758,6 +772,11 @@ static switch_status_t channel_receive_message_cas(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + ftdm_log(FTDM_LOG_DEBUG, "Got Freeswitch message in R2 channel %d [%d]\n", tech_pvt->ftdmchan->physical_chan_id, msg->message_id); @@ -817,9 +836,12 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); - assert(tech_pvt->ftdmchan != NULL); - ftdm_mutex_lock(tech_pvt->ftdmchan->mutex); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + if (tech_pvt->ftdmchan->state == FTDM_CHANNEL_STATE_TERMINATING) { ftdm_mutex_unlock(tech_pvt->ftdmchan->mutex); return SWITCH_STATUS_SUCCESS; @@ -875,7 +897,6 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session, break; } - ftdm_mutex_unlock(tech_pvt->ftdmchan->mutex); return SWITCH_STATUS_SUCCESS; } @@ -890,6 +911,11 @@ static switch_status_t channel_receive_message_fxo(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: @@ -919,6 +945,11 @@ static switch_status_t channel_receive_message_fxs(switch_core_session_t *sessio tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: @@ -955,12 +986,31 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch_status_t status; switch_channel_t *channel; const char *var; + ftdm_channel_t *ftdmchan = NULL; tech_pvt = (private_t *) switch_core_session_get_private(session); assert(tech_pvt != NULL); channel = switch_core_session_get_channel(session); + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + + if (!(ftdmchan = tech_pvt->ftdmchan)) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + return SWITCH_STATUS_FALSE; + } + + ftdm_mutex_lock(ftdmchan->mutex); + + if (!tech_pvt->ftdmchan) { + switch_channel_hangup(channel, SWITCH_CAUSE_LOSE_RACE); + status = SWITCH_STATUS_FALSE; + goto end; + } + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_PROGRESS: case SWITCH_MESSAGE_INDICATE_ANSWER: @@ -1001,6 +1051,10 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s break; } + end: + + ftdm_mutex_unlock(ftdmchan->mutex); + return status; } @@ -1068,6 +1122,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); + outbound_profile->destination_number = switch_sanitize_number(outbound_profile->destination_number); + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -1168,8 +1224,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } if (status != FTDM_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channels available\n"); - return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; + if (caller_data.hangup_cause == SWITCH_CAUSE_NONE) { + caller_data.hangup_cause = SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION; + } + return caller_data.hangup_cause; } if ((var = switch_event_get_header(var_event, "freetdm_pre_buffer_size"))) { @@ -1363,7 +1421,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_fxo_signal) break; case FTDM_SIGEVENT_STOP: { + private_t *tech_pvt = NULL; while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); ftdm_channel_clear_token(sigmsg->channel, 0); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); @@ -1440,6 +1501,7 @@ static FIO_SIGNAL_CB_FUNCTION(on_fxs_signal) break; case FTDM_SIGEVENT_STOP: { + private_t *tech_pvt = NULL; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; if (sigmsg->channel->token_count) { switch_core_session_t *session_a, *session_b, *session_t = NULL; @@ -1495,6 +1557,8 @@ static FIO_SIGNAL_CB_FUNCTION(on_fxs_signal) } while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, cause); ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -1621,7 +1685,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_r2_signal) /* on_call_disconnect from the R2 side */ case FTDM_SIGEVENT_STOP: { + private_t *tech_pvt = NULL; while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -1731,7 +1798,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) case FTDM_SIGEVENT_STOP: case FTDM_SIGEVENT_RESTART: { + private_t *tech_pvt = NULL; while((session = ftdm_channel_get_session(sigmsg->channel, 0))) { + tech_pvt = switch_core_session_get_private(session); + switch_set_flag_locked(tech_pvt, TFLAG_DEAD); channel = switch_core_session_get_channel(session); switch_channel_hangup(channel, sigmsg->channel->caller_data.hangup_cause); ftdm_channel_clear_token(sigmsg->channel, switch_core_session_get_uuid(session)); @@ -2959,6 +3029,12 @@ SWITCH_STANDARD_APP(disable_ec_function) } tech_pvt = switch_core_session_get_private(session); + + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); + return; + } + ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_DISABLE_ECHOCANCEL, &x); ftdm_channel_command(tech_pvt->ftdmchan, FTDM_COMMAND_DISABLE_ECHOTRAIN, &x); ftdm_log(FTDM_LOG_INFO, "Echo Canceller Disabled\n"); diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index a1fee89395..7c6ca108ec 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -3356,6 +3356,25 @@ FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *na return status; } +FT_DECLARE(ftdm_status_t) ftdm_span_send_signal(ftdm_span_t *span, ftdm_sigmsg_t *sigmsg) +{ + ftdm_status_t status = FTDM_FAIL; + + if (span->signal_cb) { + if (sigmsg->channel) { + ftdm_mutex_lock(sigmsg->channel->mutex); + } + + status = span->signal_cb(sigmsg); + + if (sigmsg->channel) { + ftdm_mutex_unlock(sigmsg->channel->mutex); + } + } + + return status; +} + FT_DECLARE(ftdm_status_t) ftdm_global_init(void) { memset(&globals, 0, sizeof(globals)); diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h index 4b9f02e16c..487829fd7b 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h @@ -48,7 +48,6 @@ struct ftdm_analog_data { uint32_t max_dialstr; uint32_t digit_timeout; char hotline[FTDM_MAX_HOTLINE_STR]; - fio_signal_cb_t sig_cb; }; diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index 4ef3d2a13e..c71b19d202 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -176,7 +176,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_configure_span) analog_data->flags = flags; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; - analog_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; strncpy(analog_data->hotline, hotline, sizeof(analog_data->hotline)); span->signal_type = FTDM_SIGTYPE_ANALOG; span->signal_data = analog_data; @@ -481,7 +481,7 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) sig.event_id = FTDM_SIGEVENT_UP; } - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); continue; } break; @@ -501,14 +501,14 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) ftdm_set_string(ftdmchan->caller_data.dnis.digits, dtmf); } - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); continue; } break; case FTDM_CHANNEL_STATE_DOWN: { sig.event_id = FTDM_SIGEVENT_STOP; - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); goto done; } break; @@ -549,7 +549,7 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) sig.span_id = ftdmchan->span_id; sig.channel = ftdmchan; sig.event_id = FTDM_SIGEVENT_PROGRESS; - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); } break; @@ -608,7 +608,7 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) last_digit = elapsed; sig.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT; sig.raw_data = dtmf; - if (analog_data->sig_cb(&sig) == FTDM_BREAK) { + if (ftdm_span_send_signal(ftdmchan->span, &sig) == FTDM_BREAK) { collecting = 0; } } @@ -654,9 +654,7 @@ static void *ftdm_analog_channel_run(ftdm_thread_t *me, void *obj) if (ftdmchan->detected_tones[i]) { ftdm_log(FTDM_LOG_DEBUG, "Detected tone %s on %d:%d\n", ftdm_tonemap2str(i), ftdmchan->span_id, ftdmchan->chan_id); sig.raw_data = &i; - if (analog_data->sig_cb) { - analog_data->sig_cb(&sig); - } + ftdm_span_send_signal(ftdmchan->span, &sig); } } @@ -843,7 +841,7 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_UP); } else { sig.event_id = FTDM_SIGEVENT_FLASH; - analog_data->sig_cb(&sig); + ftdm_span_send_signal(span, &sig); } } break; diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h b/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h index 353ea108d6..83d5bb31d9 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftdm_analog_em.h @@ -51,7 +51,6 @@ struct ftdm_analog_data { uint32_t flags; uint32_t max_dialstr; uint32_t digit_timeout; - fio_signal_cb_t sig_cb; }; static void *ftdm_analog_em_run(ftdm_thread_t *me, void *obj); diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c index 42e1ab1ee8..bb11798c68 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c @@ -145,7 +145,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_em_configure_span) span->start = ftdm_analog_em_start; analog_data->digit_timeout = digit_timeout; analog_data->max_dialstr = max_dialstr; - analog_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; span->signal_type = FTDM_SIGTYPE_ANALOG; span->signal_data = analog_data; span->outgoing_call = analog_em_outgoing_call; @@ -349,7 +349,7 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) sig.event_id = FTDM_SIGEVENT_UP; - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); continue; } break; @@ -370,14 +370,14 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) sig.event_id = FTDM_SIGEVENT_START; - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); continue; } break; case FTDM_CHANNEL_STATE_DOWN: { sig.event_id = FTDM_SIGEVENT_STOP; - analog_data->sig_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); goto done; } break; @@ -440,7 +440,7 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) last_digit = elapsed; sig.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT; sig.raw_data = dtmf; - if (analog_data->sig_cb(&sig) == FTDM_BREAK) { + if (ftdm_span_send_signal(ftdmchan->span, &sig) == FTDM_BREAK) { collecting = 0; } } @@ -480,9 +480,7 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) if (ftdmchan->detected_tones[i]) { ftdm_log(FTDM_LOG_DEBUG, "Detected tone %s on %d:%d\n", ftdm_tonemap2str(i), ftdmchan->span_id, ftdmchan->chan_id); sig.raw_data = &i; - if (analog_data->sig_cb) { - analog_data->sig_cb(&sig); - } + ftdm_span_send_signal(ftdmchan->span, &sig); } } diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h b/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h index d550f01557..7168abeb3b 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftdm_isdn.h @@ -60,7 +60,6 @@ struct ftdm_isdn_data { ftdm_channel_t *dchan; ftdm_channel_t *dchans[2]; struct ftdm_sigmsg sigmsg; - fio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; int32_t digit_timeout; diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index fe9009da58..547c6feaa0 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -699,7 +699,7 @@ static L3INT ftdm_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen) sig.channel->caller_data.hangup_cause = (cause) ? cause->Value : FTDM_CAUSE_NORMAL_UNSPECIFIED; sig.event_id = FTDM_SIGEVENT_STOP; - status = isdn_data->sig_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); ftdm_log(FTDM_LOG_DEBUG, "Received %s in state %s, requested hangup for channel %d:%d\n", what, ftdm_channel_state2str(ftdmchan->state), ftdmchan->span_id, chan_id); } @@ -1186,7 +1186,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_PROGRESS; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { @@ -1230,7 +1230,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_START; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } @@ -1240,7 +1240,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_UNSPECIFIED; sig.event_id = FTDM_SIGEVENT_RESTART; - status = isdn_data->sig_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; @@ -1248,7 +1248,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { @@ -1268,7 +1268,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_UP; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { @@ -1473,7 +1473,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) ftdm_log(FTDM_LOG_DEBUG, "Terminating: Direction %s\n", ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? "Outbound" : "Inbound"); sig.event_id = FTDM_SIGEVENT_STOP; - status = isdn_data->sig_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); gen->MesType = Q931mes_RELEASE; gen->CRVFlag = ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND) ? 0 : 1; Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size); @@ -1513,7 +1513,6 @@ static __inline__ void check_state(ftdm_span_t *span) static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) { ftdm_sigmsg_t sig; - ftdm_isdn_data_t *isdn_data = span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -1539,7 +1538,7 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + ftdm_span_send_signal(span, &sig); ftdm_log(FTDM_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, @@ -1556,7 +1555,7 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; ftdm_clear_flag(event->channel, FTDM_CHANNEL_SUSPENDED); ftdm_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + ftdm_span_send_signal(span, &sig); } break; } @@ -2357,7 +2356,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_isdn_configure_span) span->start = ftdm_isdn_start; span->stop = ftdm_isdn_stop; - isdn_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; isdn_data->dchans[0] = dchans[0]; isdn_data->dchans[1] = dchans[1]; isdn_data->dchan = isdn_data->dchans[0]; diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index 0874bfafa1..a3885ff856 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -454,7 +454,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_PROGRESS; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else if (call) { @@ -468,7 +468,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else if (call) { @@ -484,7 +484,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) if (call) { pri_acknowledge(isdn_data->spri.pri, call, ftdmchan->chan_id, 0); sig.event_id = FTDM_SIGEVENT_START; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { @@ -497,7 +497,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_UNSPECIFIED; sig.event_id = FTDM_SIGEVENT_RESTART; - status = isdn_data->sig_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } break; @@ -505,7 +505,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_UP; - if ((status = isdn_data->sig_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else if (call) { @@ -579,7 +579,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) case FTDM_CHANNEL_STATE_TERMINATING: { sig.event_id = FTDM_SIGEVENT_STOP; - status = isdn_data->sig_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } @@ -807,7 +807,6 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) { ftdm_sigmsg_t sig; - ftdm_libpri_data_t *isdn_data = span->signal_data; memset(&sig, 0, sizeof(sig)); sig.chan_id = event->channel->chan_id; @@ -833,7 +832,7 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + ftdm_span_send_signal(span, &sig); ftdm_log(FTDM_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, @@ -850,7 +849,7 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; ftdm_clear_flag(event->channel, FTDM_CHANNEL_SUSPENDED); ftdm_channel_get_alarms(event->channel); - isdn_data->sig_cb(&sig); + ftdm_span_send_signal(span, &sig); } break; } @@ -1331,7 +1330,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_libpri_configure_span) span->start = ftdm_libpri_start; span->stop = ftdm_libpri_stop; - isdn_data->sig_cb = sig_cb; + span->signal_cb = sig_cb; //isdn_data->dchans[0] = dchans[0]; //isdn_data->dchans[1] = dchans[1]; //isdn_data->dchan = isdn_data->dchans[0]; diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h index 534bd9896b..0bf8c46817 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.h @@ -55,7 +55,6 @@ struct ftdm_libpri_data { ftdm_channel_t *dchan; ftdm_channel_t *dchans[2]; struct ftdm_sigmsg sigmsg; - fio_signal_cb_t sig_cb; uint32_t flags; int32_t mode; ftdm_isdn_opts_t opts; diff --git a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c index 4453bce887..758942452e 100644 --- a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c +++ b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c @@ -90,8 +90,6 @@ typedef struct ft_r2_conf_s { /* r2 configuration stored in span->signal_data */ typedef struct ftdm_r2_data_s { - /* signaling callback */ - fio_signal_cb_t sig_cb; /* span flags */ ftdm_r2_flag_t flags; /* openr2 handle for the R2 variant context */ @@ -253,7 +251,7 @@ static void ftdm_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, cons sigev.channel = ftdmchan; sigev.event_id = FTDM_SIGEVENT_START; - if (r2data->sig_cb(&sigev) != FTDM_SUCCESS) { + if (ftdm_span_send_signal(ftdmchan->span, &sigev) != FTDM_SUCCESS) { ftdm_log(FTDM_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); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_CANCEL); @@ -323,7 +321,7 @@ static void ftdm_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_discon sigev.event_id = FTDM_SIGEVENT_STOP; r2data = ftdmchan->span->signal_data; - r2data->sig_cb(&sigev); + ftdm_span_send_signal(ftdmchan->span, &sigev); } static void ftdm_r2_on_call_end(openr2_chan_t *r2chan) @@ -377,7 +375,7 @@ static void ftdm_r2_on_protocol_error(openr2_chan_t *r2chan, openr2_protocol_err sigev.event_id = FTDM_SIGEVENT_STOP; r2data = ftdmchan->span->signal_data; - r2data->sig_cb(&sigev); + ftdm_span_send_signal(ftdmchan->span, &sigev); } static void ftdm_r2_on_line_blocked(openr2_chan_t *r2chan) @@ -460,7 +458,7 @@ static int ftdm_r2_on_dnis_digit_received(openr2_chan_t *r2chan, char digit) sigev.channel = ftdmchan; sigev.event_id = FTDM_SIGEVENT_COLLECTED_DIGIT; r2data = ftdmchan->span->signal_data; - if (r2data->sig_cb(&sigev) == FTDM_BREAK) { + if (ftdm_span_send_signal(ftdmchan->span, &sigev) == FTDM_BREAK) { ftdm_log(FTDM_LOG_NOTICE, "Requested to stop getting DNIS. Current DNIS = %s on chan %d\n", ftdmchan->caller_data.dnis.digits, openr2_chan_get_number(r2chan)); return OR2_STOP_DNIS_REQUEST; } @@ -884,7 +882,7 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_r2_configure_span) span->start = ftdm_r2_start; r2data->flags = 0; - r2data->sig_cb = sig_cb; + span->signal_cb = sig_cb; span->signal_type = FTDM_SIGTYPE_R2; span->signal_data = r2data; span->outgoing_call = r2_outgoing_call; @@ -1004,7 +1002,7 @@ static void *ftdm_r2_channel_run(ftdm_thread_t *me, void *obj) } else { ftdm_log(FTDM_LOG_DEBUG, "PROGRESS: Notifying progress in channel %d\n", ftdmchan->physical_chan_id); sigev.event_id = FTDM_SIGEVENT_PROGRESS; - if (r2data->sig_cb(&sigev) != FTDM_SUCCESS) { + if (ftdm_span_send_signal(ftdmchan->span, &sigev) != FTDM_SUCCESS) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } @@ -1027,7 +1025,7 @@ static void *ftdm_r2_channel_run(ftdm_thread_t *me, void *obj) } else { ftdm_log(FTDM_LOG_DEBUG, "UP: Notifying of call answered in channel %d\n", ftdmchan->physical_chan_id); sigev.event_id = FTDM_SIGEVENT_UP; - if (r2data->sig_cb(&sigev) != FTDM_SUCCESS) { + if (ftdm_span_send_signal(ftdmchan->span, &sigev) != FTDM_SUCCESS) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 27c13d716a..9e66d8ec53 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -285,6 +285,15 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start //} } +#ifdef LIBSANGOMA_VERSION + if (type == FTDM_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 */ + ftdm_log(FTDM_LOG_WARNING, "Failed to disable ring trip events in channel s%dc%d\n", spanno, x); + } + } +#endif #if 0 if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO) { /* Enable FLASH/Wink Events */ @@ -379,6 +388,20 @@ static FIO_CONFIGURE_FUNCTION(wanpipe_configure) } else { wp_globals.flash_ms = num; } + } else if (!strcasecmp(var, "ring_on_ms")) { + num = atoi(val); + if (num < 500 || num > 5000) { + ftdm_log(FTDM_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) { + ftdm_log(FTDM_LOG_WARNING, "invalid ring_off_ms at line %d (valid range 500 to 5000)\n", lineno); + } else { + wp_globals.ring_off_ms = num; + } } } @@ -1003,11 +1026,14 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_ring_state == WP_TDMAPI_EVENT_RING_PRESENT ? FTDM_OOB_RING_START : FTDM_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 ? FTDM_OOB_ONHOOK : FTDM_OOB_OFFHOOK; } break; + */ case WP_TDMAPI_EVENT_RBS: { event_id = FTDM_OOB_CAS_BITS_CHANGE; diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 2d3e9d861c..6c66759ef8 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -329,12 +329,12 @@ typedef enum { } ftdm_state_change_result_t; #define ftdm_set_state_r(obj, s, l, r) if ( obj->state == s ) { \ - ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); r = FTDM_STATE_CHANGE_SAME; \ + if (s != FTDM_CHANNEL_STATE_HANGUP) ftdm_log(FTDM_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(obj->state), ftdm_channel_state2str(s)); r = FTDM_STATE_CHANGE_SAME; \ } else if (ftdm_test_flag(obj, FTDM_CHANNEL_READY)) { \ int st = obj->state; \ r = (ftdm_channel_set_state(obj, s, l) == FTDM_SUCCESS) ? FTDM_STATE_CHANGE_SUCCESS : FTDM_STATE_CHANGE_FAIL; \ if (obj->state == s) {ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s));} \ - else {ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); } \ + else { if (!((obj->state == FTDM_CHANNEL_STATE_HANGUP && s == FTDM_CHANNEL_STATE_TERMINATING) || (obj->state == FTDM_CHANNEL_STATE_HANGUP_COMPLETE && s == FTDM_CHANNEL_STATE_HANGUP) || (obj->state == FTDM_CHANNEL_STATE_TERMINATING && s == FTDM_CHANNEL_STATE_HANGUP))) ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); } \ } @@ -584,6 +584,7 @@ struct ftdm_span { ftdm_analog_start_type_t start_type; ftdm_signal_type_t signal_type; void *signal_data; + fio_signal_cb_t signal_cb; ftdm_event_t event_header; char last_error[256]; char tone_map[FTDM_TONEMAP_INVALID+1][FTDM_TONEMAP_LEN]; @@ -792,6 +793,7 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *spa FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters); FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span); FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span); +FT_DECLARE(ftdm_status_t) ftdm_span_send_signal(ftdm_span_t *span, ftdm_sigmsg_t *sigmsg); FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t len); FT_DECLARE(ftdm_status_t) ftdm_global_add_io_interface(ftdm_io_interface_t *io_interface); FT_DECLARE(int) ftdm_load_module(const char *name); From 10f673cadd856d5bad529985bfb7c37162a31066 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 10 Feb 2010 23:00:17 +0000 Subject: [PATCH 1722/1766] Pending channel state changes are processed before each new boost messages to fix race conditions git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1027 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 76 ++++++++++++++----- 1 file changed, 58 insertions(+), 18 deletions(-) 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 index b9d3460988..e658854cb1 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -86,7 +86,6 @@ static uint16_t SETUP_GRID[ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN+1][ZAP_MAX_CH static sangoma_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; static zap_mutex_t *request_mutex = NULL; -static zap_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; static uint8_t nack_map[MAX_REQ_ID+1] = { 0 }; @@ -186,7 +185,6 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even int i; zap_channel_t *zchan = NULL; - zap_mutex_lock(signal_mutex); 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]; @@ -204,7 +202,6 @@ static zap_channel_t *find_zchan(zap_span_t *span, sangomabc_short_event_t *even } } } - zap_mutex_unlock(signal_mutex); return zchan; } @@ -715,15 +712,8 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_channel_t *zchan; if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { - if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { - zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); - goto error; - } - advance_chan_states(zchan); - if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { - zap_log(ZAP_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\n", event->span+1,event->chan+1); - goto error; - } + 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) { @@ -862,6 +852,52 @@ static void handle_incoming_digit(sangomabc_connection_t *mcon, zap_span_t *span 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 @@ -870,7 +906,7 @@ static void handle_incoming_digit(sangomabc_connection_t *mcon, zap_span_t *span */ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - zap_mutex_lock(signal_mutex); + zap_channel_t* zchan = NULL; if (!zap_running()) { zap_log(ZAP_LOG_WARNING, "System is shutting down.\n"); @@ -878,6 +914,11 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s } 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); @@ -931,8 +972,10 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s } end: - - zap_mutex_unlock(signal_mutex); + if(zchan != NULL) { + advance_chan_states(zchan); + zap_mutex_unlock(zchan->mutex); + } return 0; } @@ -1135,13 +1178,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) static __inline__ void advance_chan_states(zap_channel_t *zchan) { - zap_mutex_lock(zchan->mutex); 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); } - zap_mutex_unlock(zchan->mutex); } /** @@ -1400,7 +1441,6 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init) { zap_mutex_create(&request_mutex); - zap_mutex_create(&signal_mutex); return ZAP_SUCCESS; } From 28584115594d095597f7a031448973c852a1a9d9 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 11 Feb 2010 20:51:00 +0000 Subject: [PATCH 1723/1766] merged 956:1023 (partial merge - boost related stuff) git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1028 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 2 +- .../ftmod_sangoma_boost/ftdm_sangoma_boost.h | 1 - .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 376 +++++++++--------- .../sangoma_boost_client.c | 3 +- .../sangoma_boost_client.h | 2 +- libs/freetdm/src/include/freetdm.h | 2 +- 6 files changed, 191 insertions(+), 195 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 7c6ca108ec..d81737886b 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -977,7 +977,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_ } if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { - ftdm_log(FTDM_LOG_WARNING, "Ignored state change request from %s to %s, the previous state change has not been processed yet\n", + ftdm_log(FTDM_LOG_CRIT, "Ignored state change request from %s to %s, the previous state change has not been processed yet\n", ftdm_channel_state2str(ftdmchan->state), ftdm_channel_state2str(state)); return FTDM_FAIL; } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h index 7b98a166c8..d4659b1141 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h @@ -49,7 +49,6 @@ typedef struct ftdm_sangoma_boost_data { fd_set rfds; fd_set efds; int iteration; - fio_signal_cb_t signal_cb; uint32_t flags; boost_sigmod_interface_t *sigmod; ftdm_queue_t *boost_queue; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index cb6c2522ed..3d764b5faa 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -72,7 +72,10 @@ static ftdm_sangoma_boost_trunkgroup_t *g_trunkgroups[MAX_TRUNK_GROUPS]; typedef enum { SFLAG_FREE_REQ_ID = (1 << 0), SFLAG_SENT_FINAL_MSG = (1 << 1), - SFLAG_SENT_ACK = (1 << 2) + 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; @@ -96,6 +99,8 @@ typedef struct { sangomabc_short_event_t event; ftdm_span_t *span; ftdm_channel_t *ftdmchan; + int hangup_cause; + int flags; } sangoma_boost_request_t; //#define MAX_REQ_ID FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN * FTDM_MAX_CHANNELS_PHYSICAL_SPAN @@ -252,30 +257,6 @@ static int check_congestion(int trunk_group) return 0; } -/** - * \brief determines whether media is ready - * \param event boost event - * \return 1 true, 0 for false - */ - -static int boost_media_ready(sangomabc_event_t *event) -{ - /* FORMAT is of type: SMG003-EVI-1-MEDIA-# */ - char* p = NULL; - p = strstr(event->isup_in_rdnis, "MEDIA"); - if (p) { - int media_ready = 0; - if ((sscanf(p, "MEDIA-%d", &media_ready)) == 1) { - if (media_ready) { - return 1; - } else { - } - } else { - ftdm_log(FTDM_LOG_ERROR, "Invalid boost isup_rdnis MEDIA format %s\n", p); - } - } - return 0; -} /** * \brief Requests an sangoma boost channel on a span (outgoing call) @@ -400,38 +381,14 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) if (!sangoma_boost_data->sigmod) { *ftdmchan = NULL; } - ftdm_log(FTDM_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); ftdm_log(FTDM_LOG_CRIT, "s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*ftdmchan)->physical_span_id, (*ftdmchan)->physical_chan_id, r); goto done; } } - - if (OUTBOUND_REQUESTS[r].status == BST_ACK && OUTBOUND_REQUESTS[r].ftdmchan) { - *ftdmchan = OUTBOUND_REQUESTS[r].ftdmchan; - status = FTDM_SUCCESS; - (*ftdmchan)->init_state = FTDM_CHANNEL_STATE_PROGRESS; - ftdm_log(FTDM_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); - } - - boost_request_timeout = 5000; - while(ftdm_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { - ftdm_sleep(1); - if (--boost_request_timeout <= 0) { - status = FTDM_FAIL; - if (!sangoma_boost_data->sigmod) { - *ftdmchan = NULL; - } - ftdm_log(FTDM_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n"); - goto done; - } - //printf("WTF %d\n", sanity); - } if (OUTBOUND_REQUESTS[r].status == BST_READY && OUTBOUND_REQUESTS[r].ftdmchan) { *ftdmchan = OUTBOUND_REQUESTS[r].ftdmchan; status = FTDM_SUCCESS; - (*ftdmchan)->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; - ftdm_log(FTDM_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r); } else { status = FTDM_FAIL; if (!sangoma_boost_data->sigmod) { @@ -443,11 +400,19 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) st = OUTBOUND_REQUESTS[r].status; OUTBOUND_REQUESTS[r].status = BST_FREE; + + if (status == FTDM_FAIL) { + if (st == BST_FAIL) { + caller_data->hangup_cause = OUTBOUND_REQUESTS[r].hangup_cause; + } else { + caller_data->hangup_cause = FTDM_CAUSE_RECOVERY_ON_TIMER_EXPIRE; + } + } if (st == BST_FAIL) { release_request_id(r); } else if (st != BST_READY) { - assert(r <= MAX_REQ_ID); + ftdm_assert_return(r <= MAX_REQ_ID, FTDM_FAIL, "Invalid index\n"); nack_map[r] = 1; if (sangoma_boost_data->sigmod) { sangomabc_exec_command(&sangoma_boost_data->mcon, @@ -455,14 +420,14 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) BOOST_CHAN((*ftdmchan)), r, SIGBOOST_EVENT_CALL_START_NACK, - 0); + 0, 0); } else { sangomabc_exec_command(&sangoma_boost_data->mcon, 0, 0, r, SIGBOOST_EVENT_CALL_START_NACK, - 0); + 0, 0); } } @@ -486,62 +451,35 @@ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) * \param mcon sangoma boost connection * \param event Event to handle */ -static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +static void handle_call_progress(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { ftdm_channel_t *ftdmchan; - if (nack_map[event->call_setup_id]) { - return; - } - //if we received a progress for this device already - if (OUTBOUND_REQUESTS[event->call_setup_id].status == BST_ACK) { - if (boost_media_ready((sangomabc_event_t*) event)) { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; - ftdm_log(FTDM_LOG_DEBUG, "chan media ready %d:%d CSid:%d\n", event->span+1, event->chan+1, event->call_setup_id); - } - return; - } - - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - SETUP_GRID[event->span][event->chan] = event->call_setup_id; - - if ((ftdmchan = find_ftdmchan(OUTBOUND_REQUESTS[event->call_setup_id].span, (sangomabc_short_event_t*) event, 0))) { - if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); - } else { - ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); - ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); - ftdmchan->extra_id = event->call_setup_id; - ftdm_log(FTDM_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id); - ftdmchan->sflags = 0; - OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan = ftdmchan; - if (boost_media_ready((sangomabc_event_t*)event)) { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + if ((ftdmchan = find_ftdmchan(span, event, 1))) { + ftdm_mutex_lock(ftdmchan->mutex); + if (ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) { + if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state updated to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id); + } else if ((event->flags & SIGBOOST_PROGRESS_RING)) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state updated to PROGRESS [Csid:%d]\n", event->call_setup_id); } else { - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_ACK; + ftdmchan->init_state = FTDM_CHANNEL_STATE_IDLE; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state updated to IDLE [Csid:%d]\n", event->call_setup_id); + } + } else { + if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); + } else if ((event->flags & SIGBOOST_PROGRESS_RING)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); + } else { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE); } - return; } - } - - //printf("WTF BAD ACK CSid=%d span=%d chan=%d\n", event->call_setup_id, event->span+1,event->chan+1); - if ((ftdmchan = find_ftdmchan(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", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, ftdmchan->extra_id, ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), ftdm_channel_state2str(ftdmchan->state)); + ftdm_mutex_unlock(ftdmchan->mutex); } - - - ftdm_log(FTDM_LOG_CRIT, "START PROGRESS CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); - if (ftdmchan) { - ftdm_set_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG); - } - sangomabc_exec_command(mcon, - event->span, - event->chan, - event->call_setup_id, - SIGBOOST_EVENT_CALL_STOPPED, - FTDM_CAUSE_DESTINATION_OUT_OF_ORDER); - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; } /** @@ -570,8 +508,6 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ if (mcon->sigmod) { ftdmchan = OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan; - ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); - ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); } else { ftdmchan = find_ftdmchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0); } @@ -581,20 +517,30 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); } else { - ftdmchan->extra_id = event->call_setup_id; - ftdm_log(FTDM_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", ftdmchan->span_id, ftdmchan->chan_id, event_span, event_chan, event->call_setup_id); - ftdmchan->sflags = 0; + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); + ftdmchan->sflags = SFLAG_RECVD_ACK; + + if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id); + } else if ((event->flags & SIGBOOST_PROGRESS_RING)) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to PROGRESS [Csid:%d]\n", event->call_setup_id); + } else { + ftdmchan->init_state = FTDM_CHANNEL_STATE_IDLE; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to IDLE [Csid:%d]\n", event->call_setup_id); + } + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HOLD); + OUTBOUND_REQUESTS[event->call_setup_id].flags = event->flags; OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan = ftdmchan; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; + ftdm_log(FTDM_LOG_DEBUG, "Assigned chan %d:%d (%d:%d) to CSid=%d\n", + ftdmchan->span_id, ftdmchan->chan_id, event_span, event_chan, event->call_setup_id); return; } } - //printf("WTF BAD ACK CSid=%d span=%d chan=%d\n", event->call_setup_id, event->span+1,event->chan+1); - if ((ftdmchan = find_ftdmchan(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", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, ftdmchan->extra_id, ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), ftdm_channel_state2str(ftdmchan->state)); - } - ftdm_set_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG); ftdm_log(FTDM_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); sangomabc_exec_command(mcon, @@ -602,8 +548,9 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_STOPPED, - FTDM_CAUSE_DESTINATION_OUT_OF_ORDER); + FTDM_CAUSE_DESTINATION_OUT_OF_ORDER, 0); OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; + OUTBOUND_REQUESTS[event->call_setup_id].hangup_cause = FTDM_CAUSE_DESTINATION_OUT_OF_ORDER; } /** @@ -629,10 +576,10 @@ static void handle_call_done(ftdm_span_t *span, sangomabc_connection_t *mcon, sa BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_RELEASED, - 0); + 0, 0); } - if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN || ftdmchan->state == FTDM_CHANNEL_STATE_HANGUP_COMPLETE) { + if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN || ftdmchan->state == FTDM_CHANNEL_STATE_HANGUP_COMPLETE || ftdm_test_sflag(ftdmchan, SFLAG_TERMINATING)) { goto done; } @@ -695,23 +642,31 @@ static void handle_call_start_nack(ftdm_span_t *span, sangomabc_connection_t *mc event->release_cause = 17; } - ftdm_log(FTDM_LOG_DEBUG, "setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id); - OUTBOUND_REQUESTS[event->call_setup_id].event = *event; - OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL; - if (!sangoma_boost_data->sigmod) { + if (event->call_setup_id) { + int span = 0; + int chan = 0; + if (sangoma_boost_data->sigmod) { + span = BOOST_SPAN(OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan); + chan = BOOST_CHAN(OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan); + } sangomabc_exec_command(mcon, - 0, - 0, - event->call_setup_id, - SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); - + span, + chan, + 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; + ftdm_log(FTDM_LOG_DEBUG, "setting outbound request status %d to BST_FAIL\n", event->call_setup_id); return; } else { if ((ftdmchan = find_ftdmchan(span, event, 1))) { int r = 0; - assert(!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)); - + + /* if there is no call setup id this should not be an outbound channel for sure */ + ftdm_assert(!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), "Yay, outbound flag should not be set here!\n"); + ftdmchan->call_data = (void*)(intptr_t)event->event_id; ftdm_mutex_lock(ftdmchan->mutex); @@ -723,10 +678,9 @@ static void handle_call_start_nack(ftdm_span_t *span, sangomabc_connection_t *mc if (r) { return; } - } + } } -#if 0 if (ftdmchan) { ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); } @@ -737,8 +691,7 @@ static void handle_call_start_nack(ftdm_span_t *span, sangomabc_connection_t *mc event->chan, 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); -#endif + 0, 0); } static void handle_call_released(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) @@ -768,7 +721,7 @@ static void handle_call_stop(ftdm_span_t *span, sangomabc_connection_t *mcon, sa ftdm_mutex_lock(ftdmchan->mutex); - if (ftdmchan->state == FTDM_CHANNEL_STATE_HANGUP) { + if (ftdm_test_sflag(ftdmchan, SFLAG_HANGUP)) { /* racing condition where both sides initiated a hangup * Do not change current state as channel is already clearing * itself through local initiated hangup */ @@ -778,7 +731,14 @@ static void handle_call_stop(ftdm_span_t *span, sangomabc_connection_t *mcon, sa BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); + 0, 0); + ftdm_mutex_unlock(ftdmchan->mutex); + return; + } else if (ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_TERMINATING; + ftdm_log(FTDM_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; + ftdmchan->caller_data.hangup_cause = event->release_cause; ftdm_mutex_unlock(ftdmchan->mutex); return; } else { @@ -794,6 +754,7 @@ static void handle_call_stop(ftdm_span_t *span, sangomabc_connection_t *mcon, sa } ftdm_mutex_unlock(ftdmchan->mutex); + if (r) { return; } @@ -814,25 +775,22 @@ static void handle_call_answer(ftdm_span_t *span, sangomabc_connection_t *mcon, ftdm_channel_t *ftdmchan; if ((ftdmchan = find_ftdmchan(span, event, 1))) { - int r = 0; - - if (ftdmchan->extra_id == event->call_setup_id && ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { - ftdm_mutex_lock(ftdmchan->mutex); - if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN && ftdmchan->init_state != FTDM_CHANNEL_STATE_UP) { - ftdmchan->init_state = FTDM_CHANNEL_STATE_UP; - r = 1; - } else { - ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_UP, 0, r); - } - ftdm_mutex_unlock(ftdmchan->mutex); - } -#if 0 - if (!r) { - printf("WTF BAD ANSWER %d:%d (%d:%d) CSid=%d xtra_id=%d out=%d state=%s\n", ftdmchan->span_id, ftdmchan->chan_id, event->span+1,event->chan+1, event->call_setup_id, ftdmchan->extra_id, ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), ftdm_channel_state2str(ftdmchan->state)); + ftdm_mutex_lock(ftdmchan->mutex); + if (ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) { + ftdmchan->init_state = FTDM_CHANNEL_STATE_UP; + } else { + int r = 0; + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_UP, 0, r); } -#endif + ftdm_mutex_unlock(ftdmchan->mutex); } else { ftdm_log(FTDM_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, + FTDM_CAUSE_DESTINATION_OUT_OF_ORDER, 0); } } @@ -908,11 +866,11 @@ static void handle_call_start(ftdm_span_t *span, sangomabc_connection_t *mcon, s error: sangomabc_exec_command(mcon, - event->span, - event->chan, - 0, - SIGBOOST_EVENT_CALL_START_NACK, - 0); + event->span, + event->chan, + 0, + SIGBOOST_EVENT_CALL_START_NACK, + 0, 0); } @@ -1015,7 +973,7 @@ static int parse_sangoma_event(ftdm_span_t *span, sangomabc_connection_t *mcon, goto end; } - assert(event->call_setup_id <= MAX_REQ_ID); + ftdm_assert_return(event->call_setup_id <= MAX_REQ_ID, -1, "Unexpected call setup id\n"); switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: handle_call_start(span, mcon, (sangomabc_event_t*)event); @@ -1030,7 +988,7 @@ static int parse_sangoma_event(ftdm_span_t *span, sangomabc_connection_t *mcon, handle_call_start_ack(mcon, event); break; case SIGBOOST_EVENT_CALL_PROGRESS: - handle_call_progress(mcon, event); + handle_call_progress(span, mcon, event); break; case SIGBOOST_EVENT_CALL_START_NACK: handle_call_start_nack(span, mcon, event); @@ -1102,9 +1060,6 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { int call_stopped_ack_sent = 0; ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; - if (ftdmchan->extra_id) { - ftdmchan->extra_id = 0; - } if (ftdm_test_sflag(ftdmchan, SFLAG_FREE_REQ_ID)) { release_request_id_span_chan(ftdmchan->physical_span_id-1, ftdmchan->physical_chan_id-1); @@ -1119,7 +1074,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_NACK_ACK, - 0); + 0, 0); } else { /* we got a call stop msg, time to reply with call stopped ack */ @@ -1128,7 +1083,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, - 0); + 0, 0); call_stopped_ack_sent = 1; } } @@ -1144,31 +1099,56 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) } break; case FTDM_CHANNEL_STATE_PROGRESS_MEDIA: - case FTDM_CHANNEL_STATE_PROGRESS: { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA; - if ((status = sangoma_boost_data->signal_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { if (!ftdm_test_sflag(ftdmchan, SFLAG_SENT_ACK)) { ftdm_set_sflag(ftdmchan, SFLAG_SENT_ACK); - sangomabc_exec_command(mcon, - BOOST_SPAN(ftdmchan), - BOOST_CHAN(ftdmchan), - 0, - SIGBOOST_EVENT_CALL_START_ACK, - 0); + sangomabc_exec_command(mcon, + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0, SIGBOOST_PROGRESS_MEDIA); } } } break; + case FTDM_CHANNEL_STATE_PROGRESS: + { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { + sig.event_id = FTDM_SIGEVENT_PROGRESS; + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + } + } else { + if (!ftdm_test_sflag(ftdmchan, SFLAG_SENT_ACK)) { + ftdm_set_sflag(ftdmchan, SFLAG_SENT_ACK); + sangomabc_exec_command(mcon, + BOOST_SPAN(ftdmchan), + BOOST_CHAN(ftdmchan), + 0, + SIGBOOST_EVENT_CALL_START_ACK, + 0, SIGBOOST_PROGRESS_RING); + } + } + } + break; + case FTDM_CHANNEL_STATE_IDLE: + case FTDM_CHANNEL_STATE_HOLD: + { + /* twiddle */ + } + break; case FTDM_CHANNEL_STATE_RING: { if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_START; - if ((status = sangoma_boost_data->signal_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } @@ -1177,7 +1157,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) case FTDM_CHANNEL_STATE_RESTART: { sig.event_id = FTDM_SIGEVENT_RESTART; - status = sangoma_boost_data->signal_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); } @@ -1186,7 +1166,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) { sig.event_id = FTDM_SIGEVENT_UP; - if ((status = sangoma_boost_data->signal_cb(&sig) != FTDM_SUCCESS)) { + if ((status = ftdm_span_send_signal(ftdmchan->span, &sig) != FTDM_SUCCESS)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); } } else { @@ -1196,7 +1176,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_ACK, - 0); + 0, 0); } sangomabc_exec_command(mcon, @@ -1204,7 +1184,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_ANSWERED, - 0); + 0, 0); } } break; @@ -1219,34 +1199,38 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) break; case FTDM_CHANNEL_STATE_HANGUP: { - if (ftdmchan->last_state == FTDM_CHANNEL_STATE_TERMINATING || - ftdm_test_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG)) { + ftdm_set_sflag_locked(ftdmchan, SFLAG_HANGUP); + + if (ftdm_test_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG) || ftdm_test_sflag(ftdmchan, SFLAG_TERMINATING)) { ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE); } else { ftdm_set_sflag_locked(ftdmchan, SFLAG_SENT_FINAL_MSG); - if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_ANSWERED) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA)) { - + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_ANSWERED) || + ftdm_test_flag(ftdmchan, FTDM_CHANNEL_PROGRESS) || + ftdm_test_flag(ftdmchan, FTDM_CHANNEL_MEDIA) || + ftdm_test_sflag(ftdmchan, SFLAG_RECVD_ACK)) { sangomabc_exec_command(mcon, BOOST_SPAN(ftdmchan), BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_STOPPED, - ftdmchan->caller_data.hangup_cause); + ftdmchan->caller_data.hangup_cause, 0); } else { sangomabc_exec_command(mcon, BOOST_SPAN(ftdmchan), BOOST_CHAN(ftdmchan), 0, SIGBOOST_EVENT_CALL_START_NACK, - ftdmchan->caller_data.hangup_cause); + ftdmchan->caller_data.hangup_cause, 0); } } } break; case FTDM_CHANNEL_STATE_TERMINATING: { + ftdm_set_sflag_locked(ftdmchan, SFLAG_TERMINATING); sig.event_id = FTDM_SIGEVENT_STOP; - status = sangoma_boost_data->signal_cb(&sig); + status = ftdm_span_send_signal(ftdmchan->span, &sig); } break; default: @@ -1307,11 +1291,11 @@ static __inline__ void check_state(ftdm_span_t *span) if (ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING)) { if (ftdm_check_state_all(span, FTDM_CHANNEL_STATE_DOWN)) { sangomabc_exec_command(&sangoma_boost_data->mcon, - 0, - 0, - -1, - SIGBOOST_EVENT_SYSTEM_RESTART_ACK, - 0); + 0, + 0, + -1, + SIGBOOST_EVENT_SYSTEM_RESTART_ACK, + 0, 0); ftdm_clear_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING); ftdm_clear_flag_locked(span, FTDM_SPAN_SUSPENDED); ftdm_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); @@ -1351,7 +1335,7 @@ static __inline__ ftdm_status_t check_events(ftdm_span_t *span, int ms_timeout) if (sangoma_boost_data->sigmod) { sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, FTDM_HW_LINK_DISCONNECTED); } - sangoma_boost_data->signal_cb(&sigmsg); + ftdm_span_send_signal(span, &sigmsg); break; case FTDM_OOB_ALARM_CLEAR: sigmsg.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; @@ -1359,7 +1343,7 @@ static __inline__ ftdm_status_t check_events(ftdm_span_t *span, int ms_timeout) if (sangoma_boost_data->sigmod) { sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, FTDM_HW_LINK_CONNECTED); } - sangoma_boost_data->signal_cb(&sigmsg); + ftdm_span_send_signal(span, &sigmsg); break; } } @@ -1717,12 +1701,25 @@ static ftdm_state_map_t boost_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_HOLD, FTDM_END} + }, + { + ZSD_OUTBOUND, + ZSM_UNACCEPTABLE, + {FTDM_CHANNEL_STATE_HOLD, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, + FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_END} + }, + { + ZSD_OUTBOUND, + ZSM_UNACCEPTABLE, + {FTDM_CHANNEL_STATE_IDLE, FTDM_END}, {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_IDLE, FTDM_END}, {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_END} }, { @@ -1826,7 +1823,6 @@ static BOOST_WRITE_MSG_FUNCTION(ftdm_boost_write_msg) static BOOST_SIG_STATUS_CB_FUNCTION(ftdm_boost_sig_status_change) { ftdm_sigmsg_t sig; - ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; ftdm_log(FTDM_LOG_NOTICE, "%d:%d Signaling link status changed to %s\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_signaling_status2str(status)); memset(&sig, 0, sizeof(sig)); @@ -1835,7 +1831,7 @@ static BOOST_SIG_STATUS_CB_FUNCTION(ftdm_boost_sig_status_change) sig.channel = ftdmchan; sig.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED; sig.raw_data = &status; - sangoma_boost_data->signal_cb(&sig); + ftdm_span_send_signal(ftdmchan->span, &sig); return; } @@ -2006,7 +2002,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) ftdm_set_string(sangoma_boost_data->mcon.cfg.remote_ip, remote_ip); sangoma_boost_data->mcon.cfg.remote_port = remote_port; } - sangoma_boost_data->signal_cb = sig_cb; + span->signal_cb = sig_cb; span->start = ftdm_sangoma_boost_start; span->stop = ftdm_sangoma_boost_stop; span->signal_data = sangoma_boost_data; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c index 163e1acd84..626074dc84 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c @@ -221,13 +221,14 @@ int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int } -int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause) +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 = (uint8_t)cause; + oevent.flags = flags; if (cmd == SIGBOOST_EVENT_SYSTEM_RESTART || cmd == SIGBOOST_EVENT_SYSTEM_RESTART_ACK) { mcon->rxseq_reset = 1; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h index 9fe2145b94..2e18d406e5 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h @@ -141,7 +141,7 @@ int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_ 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 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 diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 6c66759ef8..2113f1d347 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -334,7 +334,7 @@ typedef enum { int st = obj->state; \ r = (ftdm_channel_set_state(obj, s, l) == FTDM_SUCCESS) ? FTDM_STATE_CHANGE_SUCCESS : FTDM_STATE_CHANGE_FAIL; \ if (obj->state == s) {ftdm_log(FTDM_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s));} \ - else { if (!((obj->state == FTDM_CHANNEL_STATE_HANGUP && s == FTDM_CHANNEL_STATE_TERMINATING) || (obj->state == FTDM_CHANNEL_STATE_HANGUP_COMPLETE && s == FTDM_CHANNEL_STATE_HANGUP) || (obj->state == FTDM_CHANNEL_STATE_TERMINATING && s == FTDM_CHANNEL_STATE_HANGUP))) ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); } \ + else ftdm_log(FTDM_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, ftdm_channel_state2str(st), ftdm_channel_state2str(s)); \ } From 5db5b8e608cfbfd82ed51369b0303743e76a29cf Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Feb 2010 17:19:45 +0000 Subject: [PATCH 1724/1766] set caller data in sangomaboost test git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1029 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/testsangomaboost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 37ffc5dd26..8c888633f1 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -231,6 +231,9 @@ static void place_call(const ftdm_span_t *span, const char *number) g_outgoing_channel = ftdmchan; + /* set the caller data for the outgoing channel */ + memcpy(&ftdmchan->caller_data, &caller_data, sizeof(caller_data)); + status = ftdm_channel_outgoing_call(ftdmchan); if (status != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Failed to originate call\n"); From 7f81ff8e46c404e75d748311dd6a5082f4cedb0d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Feb 2010 18:32:16 +0000 Subject: [PATCH 1725/1766] remove the channel_request pointer in favor of implementing outgoing call when boost is in queue mode git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1030 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 233 +++++++++++------- 1 file changed, 145 insertions(+), 88 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 3d764b5faa..88e19454de 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -279,6 +279,13 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) char *gr = NULL; uint32_t count = 0; int tg=0; + + if (sangoma_boost_data->sigmod) { + ftdm_log(FTDM_LOG_CRIT, "This function should not be called when sigmod was configured in boost\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } + if (ftdm_test_flag(span, FTDM_SPAN_SUSPENDED)) { ftdm_log(FTDM_LOG_CRIT, "SPAN is not online.\n"); *ftdmchan = NULL; @@ -295,61 +302,49 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } sangomabc_call_init(&event, caller_data->cid_num.digits, dnis, r); - if (sangoma_boost_data->sigmod) { - *ftdmchan = span->channels[chan_id]; + if ((gr = strchr(dnis, '@'))) { + *gr++ = '\0'; + } - event.span = (uint8_t) (*ftdmchan)->physical_span_id; - event.chan = (uint8_t) (*ftdmchan)->physical_chan_id; - - ftdm_set_flag((*ftdmchan), FTDM_CHANNEL_OUTBOUND); - ftdm_set_flag_locked((*ftdmchan), FTDM_CHANNEL_INUSE); - - OUTBOUND_REQUESTS[r].ftdmchan = *ftdmchan; - } else { - if ((gr = strchr(dnis, '@'))) { - *gr++ = '\0'; + if (gr && *(gr+1)) { + tg = atoi(gr+1); + if (tg > 0) { + tg--; } + } + event.trunk_group = tg; - if (gr && *(gr+1)) { - tg = atoi(gr+1); - if (tg > 0) { - tg--; - } - } - event.trunk_group = tg; + if (check_congestion(tg)) { + ftdm_log(FTDM_LOG_CRIT, "All circuits are busy. Trunk Group=%i (BOOST REQUESTED BACK OFF)\n",tg+1); + *ftdmchan = NULL; + return FTDM_FAIL; + } - if (check_congestion(tg)) { - ftdm_log(FTDM_LOG_CRIT, "All circuits are busy. Trunk Group=%i (BOOST REQUESTED BACK OFF)\n",tg+1); - *ftdmchan = NULL; - return FTDM_FAIL; - } + ftdm_span_channel_use_count(span, &count); - ftdm_span_channel_use_count(span, &count); + if (count >= span->chan_count) { + ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); + *ftdmchan = NULL; + return FTDM_FAIL; + } - if (count >= span->chan_count) { - ftdm_log(FTDM_LOG_CRIT, "All circuits are busy.\n"); - *ftdmchan = NULL; - return FTDM_FAIL; - } - - 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: - ftdm_log(FTDM_LOG_WARNING, "Failed to determine huntgroup (%s)\n", gr); - event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC; - } + 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: + ftdm_log(FTDM_LOG_WARNING, "Failed to determine huntgroup (%s)\n", gr); + event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC; } } @@ -441,9 +436,49 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) */ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) { - ftdm_status_t status = FTDM_SUCCESS; + char dnis[128] = ""; + sangoma_boost_request_id_t r; + sangomabc_event_t event = {0}; + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; + if (!sangoma_boost_data->sigmod) { + return FTDM_SUCCESS; + } + ftdm_set_string(dnis, ftdmchan->caller_data.dnis.digits); - return status; + r = next_request_id(); + if (r == 0) { + ftdm_log(FTDM_LOG_CRIT, "All boost request ids are busy.\n"); + return FTDM_FAIL; + } + + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); + + sangomabc_call_init(&event, ftdmchan->caller_data.cid_num.digits, dnis, r); + + event.span = (uint8_t)ftdmchan->physical_span_id; + event.chan = (uint8_t)ftdmchan->physical_chan_id; + ftdm_set_string(event.calling_name, ftdmchan->caller_data.cid_name); + ftdm_set_string(event.isup_in_rdnis, ftdmchan->caller_data.rdnis.digits); + if (strlen(ftdmchan->caller_data.rdnis.digits)) { + event.isup_in_rdnis_size = (uint16_t)strlen(ftdmchan->caller_data.rdnis.digits)+1; + } + + event.calling_number_screening_ind = ftdmchan->caller_data.screen; + event.calling_number_presentation = ftdmchan->caller_data.pres; + + OUTBOUND_REQUESTS[r].status = BST_WAITING; + OUTBOUND_REQUESTS[r].span = ftdmchan->span; + OUTBOUND_REQUESTS[r].ftdmchan = ftdmchan; + + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DIALING); + + ftdm_log(FTDM_LOG_DEBUG, "Dialing number %s over boost channel with request id %d\n", event.called_number_digits, r); + if (sangomabc_connection_write(&sangoma_boost_data->mcon, &event) <= 0) { + ftdm_log(FTDM_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno)); + return FTDM_FAIL; + } + + return FTDM_SUCCESS; } /** @@ -457,8 +492,9 @@ static void handle_call_progress(ftdm_span_t *span, sangomabc_connection_t *mcon if ((ftdmchan = find_ftdmchan(span, event, 1))) { + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; ftdm_mutex_lock(ftdmchan->mutex); - if (ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) { + if (!sangoma_boost_data->sigmod && ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) { if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) { ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; ftdm_log(FTDM_LOG_DEBUG, "Channel init state updated to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id); @@ -490,7 +526,7 @@ static void handle_call_progress(ftdm_span_t *span, sangomabc_connection_t *mcon static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - ftdm_channel_t *ftdmchan; + ftdm_channel_t *ftdmchan = NULL; uint32_t event_span = event->span+1; uint32_t event_chan = event->chan+1; @@ -514,35 +550,57 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_ if (ftdmchan) { + ftdm_sangoma_boost_data_t *sangoma_boost_data = ftdmchan->span->signal_data; if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "OPEN ERROR [%s]\n", ftdmchan->last_error); + ftdm_log(FTDM_LOG_ERROR, "Failed to open FTDM channel [%s]\n", ftdmchan->last_error); } else { ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INUSE); ftdmchan->sflags = SFLAG_RECVD_ACK; if ((event->flags & SIGBOOST_PROGRESS_MEDIA)) { - ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; - ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id); + if (sangoma_boost_data->sigmod) { + ftdm_log(FTDM_LOG_DEBUG, "Channel state changing to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA); + } else { + ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS_MEDIA; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to PROGRESS_MEDIA [Csid:%d]\n", event->call_setup_id); + } } else if ((event->flags & SIGBOOST_PROGRESS_RING)) { - ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS; - ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to PROGRESS [Csid:%d]\n", event->call_setup_id); + if (sangoma_boost_data->sigmod) { + ftdm_log(FTDM_LOG_DEBUG, "Channel state changing to PROGRESS [Csid:%d]\n", event->call_setup_id); + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS); + } else { + ftdmchan->init_state = FTDM_CHANNEL_STATE_PROGRESS; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to PROGRESS [Csid:%d]\n", event->call_setup_id); + } } else { - ftdmchan->init_state = FTDM_CHANNEL_STATE_IDLE; - ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to IDLE [Csid:%d]\n", event->call_setup_id); + if (sangoma_boost_data->sigmod) { + /* should we set a state here? */ + } else { + ftdmchan->init_state = FTDM_CHANNEL_STATE_IDLE; + ftdm_log(FTDM_LOG_DEBUG, "Channel init state changed to IDLE [Csid:%d]\n", event->call_setup_id); + } + } + if (!sangoma_boost_data->sigmod) { + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HOLD); + ftdm_log(FTDM_LOG_DEBUG, "Assigned chan %d:%d (%d:%d) to CSid=%d\n", + ftdmchan->span_id, ftdmchan->chan_id, event_span, event_chan, event->call_setup_id); + OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan = ftdmchan; } - ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HOLD); OUTBOUND_REQUESTS[event->call_setup_id].flags = event->flags; - OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan = ftdmchan; OUTBOUND_REQUESTS[event->call_setup_id].status = BST_READY; - ftdm_log(FTDM_LOG_DEBUG, "Assigned chan %d:%d (%d:%d) to CSid=%d\n", - ftdmchan->span_id, ftdmchan->chan_id, event_span, event_chan, event->call_setup_id); return; } } - + + if (!ftdmchan) { + ftdm_log(FTDM_LOG_CRIT, "START ACK CANT FIND A CHAN %d:%d\n", event->span+1,event->chan+1); + } else { + /* only reason to be here is failed to open channel when we we're in sigmod */ + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING); + } ftdm_set_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG); - ftdm_log(FTDM_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, @@ -643,22 +701,22 @@ static void handle_call_start_nack(ftdm_span_t *span, sangomabc_connection_t *mc } if (event->call_setup_id) { - int span = 0; - int chan = 0; if (sangoma_boost_data->sigmod) { - span = BOOST_SPAN(OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan); - chan = BOOST_CHAN(OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan); + ftdmchan = OUTBOUND_REQUESTS[event->call_setup_id].ftdmchan; + ftdmchan->call_data = (void*)(intptr_t)event->event_id; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING); + } else { + 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; + ftdm_log(FTDM_LOG_DEBUG, "setting outbound request status %d to BST_FAIL\n", event->call_setup_id); } - sangomabc_exec_command(mcon, - span, - chan, - 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; - ftdm_log(FTDM_LOG_DEBUG, "setting outbound request status %d to BST_FAIL\n", event->call_setup_id); return; } else { if ((ftdmchan = find_ftdmchan(span, event, 1))) { @@ -668,7 +726,6 @@ static void handle_call_start_nack(ftdm_span_t *span, sangomabc_connection_t *mc ftdm_assert(!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), "Yay, outbound flag should not be set here!\n"); ftdmchan->call_data = (void*)(intptr_t)event->event_id; - ftdm_mutex_lock(ftdmchan->mutex); ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING, 0, r); if (r == FTDM_STATE_CHANGE_SUCCESS) { @@ -1701,7 +1758,7 @@ static ftdm_state_map_t boost_state_map = { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, {FTDM_CHANNEL_STATE_DOWN, FTDM_END}, - {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_HOLD, FTDM_END} + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_DIALING, FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_HOLD, FTDM_END} }, { ZSD_OUTBOUND, @@ -1713,13 +1770,13 @@ static ftdm_state_map_t boost_state_map = { { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {FTDM_CHANNEL_STATE_IDLE, FTDM_END}, + {FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_DIALING, FTDM_END}, {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_END} }, { ZSD_OUTBOUND, ZSM_UNACCEPTABLE, - {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_IDLE, FTDM_END}, + {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_DIALING, FTDM_END}, {FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_END} }, { @@ -2014,11 +2071,11 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) span->get_span_sig_status = sangoma_boost_get_span_sig_status; span->set_span_sig_status = sangoma_boost_set_span_sig_status; span->state_map = &boost_state_map; + span->suggest_chan_id = 0; if (sigmod_iface) { - span->suggest_chan_id = 1; - } else { - span->suggest_chan_id = 0; - } + /* the core will do the hunting */ + span->channel_request = NULL; + } ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED); return FTDM_SUCCESS; } From fa836e6e0898ced40dbbf0097c9c97e312580c29 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 14 Feb 2010 16:59:39 +0000 Subject: [PATCH 1726/1766] dont use r2data in ozmod_r2 since zap_span_send_signal is now being used git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1031 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c index a8c8abf0fc..64a2d8aa0a 100644 --- a/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/openzap/src/ozmod/ozmod_r2/ozmod_r2.c @@ -240,7 +240,6 @@ static void zap_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const { zap_sigmsg_t sigev; zap_channel_t *zchan = openr2_chan_get_client_data(r2chan); - zap_r2_data_t *r2data = zchan->span->signal_data; 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)); @@ -911,7 +910,6 @@ static void *zap_r2_channel_run(zap_thread_t *me, void *obj) zap_sigmsg_t sigev; zap_channel_t *zchan = (zap_channel_t *)obj; openr2_chan_t *r2chan = R2CALL(zchan)->r2chan; - zap_r2_data_t *r2data = zchan->span->signal_data; zap_set_flag_locked(zchan, ZAP_CHANNEL_INTHREAD); From 165bb800721745770495e07d457272ca4e59a8e4 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 16 Feb 2010 17:06:00 +0000 Subject: [PATCH 1727/1766] update cygwin install script git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1032 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/cyginstall.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/freetdm/cyginstall.sh b/libs/freetdm/cyginstall.sh index eac467d142..2536889a65 100644 --- a/libs/freetdm/cyginstall.sh +++ b/libs/freetdm/cyginstall.sh @@ -5,5 +5,7 @@ fsdir=../.. set -x cp Debug/*.dll $fsdir/Debug/ cp Debug/mod/*.dll $fsdir/Debug/mod/ +cp Debug/*.pdb $fsdir/Debug/ +echo "FRIENDLY REMINDER: RECOMPILE ftmod_wanpipe WHENEVER YOU INSTALL NEW DRIVERS" set +x From 5aa34213dfa63b7eb5919fa516e13ebec937b790 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 18 Feb 2010 18:42:36 +0000 Subject: [PATCH 1728/1766] Increased timeout in sangoma_boost_channel_request to match PRI specs git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1035 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 index e658854cb1..04ee26ccb0 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -237,7 +237,13 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_status_t status = ZAP_FAIL; sangoma_boost_request_id_t r; sangomabc_event_t event = {0}; - int sanity = 5000; + + /* 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; From 34f45f3c67a34907dd4cf1aec4d46fc737c8154f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 18 Feb 2010 18:55:03 +0000 Subject: [PATCH 1729/1766] OPENZAP-99 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1036 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 7 ++++--- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 9 +++++++-- libs/openzap/src/zap_io.c | 4 +--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 958d327365..f542908f33 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -675,7 +675,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt->read_frame.samples /= 2; } - if (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { + while (zap_channel_dequeue_dtmf(tech_pvt->zchan, dtmf, sizeof(dtmf))) { switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; char *p; for (p = dtmf; p && *p; p++) { @@ -737,10 +737,11 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc wflags = ZAP_WRITE; - status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 4); + status = zap_channel_wait(tech_pvt->zchan, &wflags, tech_pvt->zchan->effective_interval * 10); if (!(wflags & ZAP_WRITE)) { - goto fail; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Dropping frame! (write not ready)\n"); + return SWITCH_STATUS_SUCCESS; } len = frame->datalen; diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 0ef2e02287..dcf55826c3 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -486,6 +486,8 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) wanpipe_tdm_api_t tdm_api; memset(&tdm_api,0,sizeof(tdm_api)); + sangoma_flush_bufs(zchan->sockfd, &tdm_api); + sangoma_flush_event_bufs(zchan->sockfd, &tdm_api); if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; @@ -1018,14 +1020,17 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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_DEBUG, "%d:%d queue hardware dtmf %s\n", zchan->span_id, zchan->chan_id, tmp_dtmf); + //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 (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); - zap_channel_queue_dtmf(zchan, tmp_dtmf); + if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE)) { + zap_channel_queue_dtmf(zchan, tmp_dtmf); + } } } break; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 4044621825..92ec4419e8 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1225,9 +1225,7 @@ OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan) zchan->pre_buffer_size = 0; zap_mutex_unlock(zchan->pre_buffer_mutex); - if (zchan->dtmf_buffer) { - zap_buffer_zero(zchan->dtmf_buffer); - } + zap_channel_flush_dtmf(zchan); zchan->init_state = ZAP_CHANNEL_STATE_DOWN; zchan->state = ZAP_CHANNEL_STATE_DOWN; From ba1f719c3e45470e90669dfe5c15adfd720700cd Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 18 Feb 2010 19:13:54 +0000 Subject: [PATCH 1730/1766] Fixed flush buffer command so that its backward compatible with 3.4 release git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1037 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index dcf55826c3..eba1db3465 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -486,8 +486,10 @@ static ZIO_OPEN_FUNCTION(wanpipe_open) wanpipe_tdm_api_t tdm_api; memset(&tdm_api,0,sizeof(tdm_api)); - sangoma_flush_bufs(zchan->sockfd, &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; From 8d980e65f6fb2e2aba0cf8e8f8df44a4079fc0cb Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 19 Feb 2010 21:18:13 +0000 Subject: [PATCH 1731/1766] added new commands to enable/disable hardware loop and some boost code to handle ss7 loops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1038 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 + .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 63 ++++++++++++++++++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 8 +++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 72c467c398..f318da6d56 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -284,6 +284,8 @@ typedef enum { 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; @@ -341,6 +343,7 @@ typedef enum { 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", \ 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 index 04ee26ccb0..ffecef279d 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -774,6 +774,48 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa } +static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + zap_status_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_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); + /* FIXME: do we need to send an error? */ + return; + } + zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL); +} + +static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + zap_channel_t *zchan; + zap_status_t res = ZAP_FAIL; + 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"); + /* FIXME: do we need to send an error? */ + return; + } + zap_channel_command(zchan, ZAP_COMMAND_DISABLE_LOOP, NULL); + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_DOWN, 0, res); +} + /** * \brief Handler for heartbeat event * \param mcon sangoma boost connection @@ -955,10 +997,10 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s nack_map[event->call_setup_id] = 0; break; case SIGBOOST_EVENT_INSERT_CHECK_LOOP: - //handle_call_loop_start(event); + handle_call_loop_start(span, mcon, event); break; case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: - //handle_call_stop(event); + handle_call_loop_stop(span, mcon, event); break; case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: handle_restart_ack(mcon, span, event); @@ -1177,6 +1219,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) 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; } @@ -1541,6 +1588,18 @@ static zap_state_map_t boost_state_map = { {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, diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index eba1db3465..190edc2a8d 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -593,6 +593,14 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) //code me } break; + case ZAP_COMMAND_ENABLE_LOOP: + { + // code me + } + case ZAP_COMMAND_DISABLE_LOOP: + { + // code me + } case ZAP_COMMAND_SET_INTERVAL: { err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT); From dd2a805fa5fa6ff0148aad012d24c6acde5c75d0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 19 Feb 2010 22:43:29 +0000 Subject: [PATCH 1732/1766] set SFLAG_SENT_FINAL_MSG when going down in loop mode git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1039 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index ffecef279d..b0953f2b4d 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -793,7 +793,6 @@ static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mco if (res != ZAP_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); - /* FIXME: do we need to send an error? */ return; } zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL); @@ -809,10 +808,11 @@ static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon } 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"); - /* FIXME: do we need to send an error? */ return; } 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); } From 5df64c1d3836ada341075cf5d3a7db55cae702cd Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 25 Feb 2010 23:36:18 +0000 Subject: [PATCH 1733/1766] merged 1023:1039 http://svn.openzap.org/svn/openzap/trunk git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1040 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 7 +- libs/freetdm/src/ftdm_io.c | 4 +- libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c | 2 - .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 155 +++++++++++++++--- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 16 +- libs/freetdm/src/include/ftdm_types.h | 3 + 6 files changed, 151 insertions(+), 36 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 496131a213..8a19d3d725 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -675,7 +675,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt->read_frame.samples /= 2; } - if (ftdm_channel_dequeue_dtmf(tech_pvt->ftdmchan, dtmf, sizeof(dtmf))) { + while (ftdm_channel_dequeue_dtmf(tech_pvt->ftdmchan, dtmf, sizeof(dtmf))) { switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; char *p; for (p = dtmf; p && *p; p++) { @@ -737,10 +737,11 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc wflags = FTDM_WRITE; - status = ftdm_channel_wait(tech_pvt->ftdmchan, &wflags, tech_pvt->ftdmchan->effective_interval * 4); + status = ftdm_channel_wait(tech_pvt->ftdmchan, &wflags, tech_pvt->ftdmchan->effective_interval * 10); if (!(wflags & FTDM_WRITE)) { - goto fail; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Dropping frame! (write not ready)\n"); + return SWITCH_STATUS_SUCCESS; } len = frame->datalen; diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index d81737886b..2ea9ad7d77 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1322,9 +1322,7 @@ static ftdm_status_t ftdm_channel_reset(ftdm_channel_t *ftdmchan) memset(ftdmchan->tokens, 0, sizeof(ftdmchan->tokens)); ftdmchan->token_count = 0; - if (ftdmchan->dtmf_buffer) { - ftdm_buffer_zero(ftdmchan->dtmf_buffer); - } + ftdm_channel_flush_dtmf(ftdmchan); if (ftdmchan->gen_dtmf_buffer) { ftdm_buffer_zero(ftdmchan->gen_dtmf_buffer); diff --git a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c index 758942452e..85fe09f7bc 100644 --- a/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c +++ b/libs/freetdm/src/ftmod/ftmod_r2/ftmod_r2.c @@ -239,7 +239,6 @@ static void ftdm_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, cons { ftdm_sigmsg_t sigev; ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan); - ftdm_r2_data_t *r2data = ftdmchan->span->signal_data; ftdm_log(FTDM_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)); @@ -910,7 +909,6 @@ static void *ftdm_r2_channel_run(ftdm_thread_t *me, void *obj) ftdm_sigmsg_t sigev; ftdm_channel_t *ftdmchan = (ftdm_channel_t *)obj; openr2_chan_t *r2chan = R2CALL(ftdmchan)->r2chan; - ftdm_r2_data_t *r2data = ftdmchan->span->signal_data; ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_INTHREAD); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 88e19454de..53e1beb9b4 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -111,7 +111,6 @@ static uint16_t SETUP_GRID[FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN+1][FTDM_MAX_ static sangoma_boost_request_t OUTBOUND_REQUESTS[MAX_REQ_ID+1] = {{ 0 }}; static ftdm_mutex_t *request_mutex = NULL; -static ftdm_mutex_t *signal_mutex = NULL; static uint8_t req_map[MAX_REQ_ID+1] = { 0 }; static uint8_t nack_map[MAX_REQ_ID+1] = { 0 }; @@ -219,7 +218,6 @@ static ftdm_channel_t *find_ftdmchan(ftdm_span_t *span, sangomabc_short_event_t targetchan = event->chan; } - ftdm_mutex_lock(signal_mutex); for(i = 1; i <= span->chan_count; i++) { if (span->channels[i]->physical_span_id == targetspan && span->channels[i]->physical_chan_id == targetchan) { ftdmchan = span->channels[i]; @@ -237,7 +235,6 @@ static ftdm_channel_t *find_ftdmchan(ftdm_span_t *span, sangomabc_short_event_t } } } - ftdm_mutex_unlock(signal_mutex); return ftdmchan; } @@ -273,7 +270,12 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) ftdm_status_t status = FTDM_FAIL; sangoma_boost_request_id_t r; sangomabc_event_t event = {0}; - int boost_request_timeout = 5000; + /* 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 boost_request_timeout = 10000; sangoma_boost_request_status_t st; char dnis[128] = ""; char *gr = NULL; @@ -864,18 +866,8 @@ static void handle_call_start(ftdm_span_t *span, sangomabc_connection_t *mcon, s ftdm_channel_t *ftdmchan; if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 0))) { - if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { - ftdm_log(FTDM_LOG_CRIT, "START CANT FIND CHAN %d:%d AT ALL\n", event->span+1,event->chan+1); - goto error; - } - /* this handles race conditions where state handlers are still pending to be executed for finished calls - but an incoming call arrives first, we must complete the channel states and then try again to get the - ftdm channel */ - advance_chan_states(ftdmchan); - if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 0))) { - ftdm_log(FTDM_LOG_CRIT, "START CANT FIND CHAN %d:%d EVEN AFTER STATE ADVANCE\n", event->span+1,event->chan+1); - goto error; - } + ftdm_log(FTDM_LOG_CRIT, "START CANT FIND CHAN %d:%d\n", event->span+1,event->chan+1); + goto error; } if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { @@ -931,6 +923,48 @@ static void handle_call_start(ftdm_span_t *span, sangomabc_connection_t *mcon, s } +static void handle_call_loop_start(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + ftdm_status_t res = FTDM_FAIL; + ftdm_channel_t *ftdmchan; + + if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 0))) { + ftdm_log(FTDM_LOG_CRIT, "CANNOT START LOOP, CHAN NOT AVAILABLE %d:%d\n", event->span+1,event->chan+1); + return; + } + + if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT, "CANNOT START LOOP, CANT OPEN CHAN %d:%d\n", event->span+1,event->chan+1); + return; + } + + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_IN_LOOP, 0, res); + if (res != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT, "yay, could not set the state of the channel to IN_LOOP, loop will fail\n"); + ftdm_channel_done(ftdmchan); + return; + } + ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_LOOP, NULL); +} + +static void handle_call_loop_stop(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + ftdm_channel_t *ftdmchan; + ftdm_status_t res = FTDM_FAIL; + if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { + ftdm_log(FTDM_LOG_CRIT, "CANNOT STOP LOOP, INVALID CHAN REQUESTED %d:%d\n", event->span+1,event->chan+1); + return; + } + if (ftdmchan->state != FTDM_CHANNEL_STATE_IN_LOOP) { + ftdm_log(FTDM_LOG_ERROR, "Got stop loop request in a channel that is not in loop, ignoring ...\n"); + return; + } + ftdm_channel_command(ftdmchan, FTDM_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 */ + ftdm_set_flag(ftdmchan, SFLAG_SENT_FINAL_MSG); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_DOWN, 0, res); +} + /** * \brief Handler for heartbeat event * \param mcon sangoma boost connection @@ -1015,6 +1049,53 @@ static void handle_incoming_digit(sangomabc_connection_t *mcon, ftdm_span_t *spa return; } + +/** + * \brief Checks if span has state changes pending and processes + * \param span Span where event was fired + * \param event Event to handle + * \return The locked FTDM channel associated to the event if any, NULL otherwise + */ +static ftdm_channel_t* event_process_states(ftdm_span_t *span, sangomabc_short_event_t *event) +{ + ftdm_channel_t *ftdmchan = 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 (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { + ftdm_log(FTDM_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: + ftdm_log(FTDM_LOG_CRIT, "Unhandled event id:%d\n", event->event_id); + return NULL; + } + + ftdm_mutex_lock(ftdmchan->mutex); + advance_chan_states(ftdmchan); + return ftdmchan; +} + /** * \brief Handler for sangoma boost event * \param span Span where event was fired @@ -1023,14 +1104,19 @@ static void handle_incoming_digit(sangomabc_connection_t *mcon, ftdm_span_t *spa */ static int parse_sangoma_event(ftdm_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) { - ftdm_mutex_lock(signal_mutex); + ftdm_channel_t* ftdmchan = NULL; if (!ftdm_running()) { ftdm_log(FTDM_LOG_WARNING, "System is shutting down.\n"); - goto end; + return -1; } ftdm_assert_return(event->call_setup_id <= MAX_REQ_ID, -1, "Unexpected call setup id\n"); + + /* process all pending state changes for that channel before + * processing the new boost event */ + ftdmchan = event_process_states(span, event); + switch(event->event_id) { case SIGBOOST_EVENT_CALL_START: handle_call_start(span, mcon, (sangomabc_event_t*)event); @@ -1064,10 +1150,10 @@ static int parse_sangoma_event(ftdm_span_t *span, sangomabc_connection_t *mcon, nack_map[event->call_setup_id] = 0; break; case SIGBOOST_EVENT_INSERT_CHECK_LOOP: - //handle_call_loop_start(event); + handle_call_loop_start(span, mcon, event); break; case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: - //handle_call_stop(event); + handle_call_loop_stop(span, mcon, event); break; case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: handle_restart_ack(mcon, span, event); @@ -1086,11 +1172,13 @@ static int parse_sangoma_event(ftdm_span_t *span, sangomabc_connection_t *mcon, break; } - end: - - ftdm_mutex_unlock(signal_mutex); + if(ftdmchan != NULL) { + advance_chan_states(ftdmchan); + ftdm_mutex_unlock(ftdmchan->mutex); + } return 0; + } /** @@ -1290,6 +1378,11 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) status = ftdm_span_send_signal(ftdmchan->span, &sig); } break; + case FTDM_CHANNEL_STATE_IN_LOOP: + { + /* nothing to do, we sent the FTDM_COMMAND_ENABLE_LOOP command in handle_call_loop_start() right away */ + } + break; default: break; } @@ -1297,13 +1390,11 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) static __inline__ void advance_chan_states(ftdm_channel_t *ftdmchan) { - ftdm_mutex_lock(ftdmchan->mutex); while (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); state_advance(ftdmchan); ftdm_channel_complete_state(ftdmchan); } - ftdm_mutex_unlock(ftdmchan->mutex); } /** @@ -1668,7 +1759,6 @@ static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_boost_init) return FTDM_FAIL; } ftdm_mutex_create(&request_mutex); - ftdm_mutex_create(&signal_mutex); ftdm_mutex_create(&g_boost_modules_mutex); memset(&g_trunkgroups[0], 0, sizeof(g_trunkgroups)); return FTDM_SUCCESS; @@ -1693,7 +1783,6 @@ static FIO_SIG_UNLOAD_FUNCTION(ftdm_sangoma_boost_destroy) hashtable_destroy(g_boost_modules_hash); ftdm_mutex_destroy(&request_mutex); - ftdm_mutex_destroy(&signal_mutex); ftdm_mutex_destroy(&g_boost_modules_mutex); return FTDM_SUCCESS; } @@ -1811,6 +1900,18 @@ static ftdm_state_map_t boost_state_map = { {FTDM_CHANNEL_STATE_RESTART, FTDM_END}, {FTDM_CHANNEL_STATE_DOWN, FTDM_END} }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {FTDM_CHANNEL_STATE_DOWN}, + {FTDM_CHANNEL_STATE_IN_LOOP, FTDM_END} + }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {FTDM_CHANNEL_STATE_IN_LOOP}, + {FTDM_CHANNEL_STATE_DOWN, FTDM_END} + }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 9e66d8ec53..c7723e94a9 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -497,6 +497,10 @@ static FIO_OPEN_FUNCTION(wanpipe_open) wanpipe_tdm_api_t tdm_api; memset(&tdm_api,0,sizeof(tdm_api)); + sangoma_tdm_flush_bufs(ftdmchan->sockfd, &tdm_api); +#ifdef LIBSANGOMA_VERSION + sangoma_flush_event_bufs(ftdmchan->sockfd, &tdm_api); +#endif if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921 || ftdmchan->type == FTDM_CHAN_TYPE_DQ931) { ftdmchan->native_codec = ftdmchan->effective_codec = FTDM_CODEC_NONE; @@ -605,6 +609,14 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) //code me } break; + case FTDM_COMMAND_ENABLE_LOOP: + { + // code me + } + case FTDM_COMMAND_DISABLE_LOOP: + { + // code me + } case FTDM_COMMAND_SET_INTERVAL: { err=sangoma_tdm_set_usr_period(ftdmchan->sockfd, &tdm_api, FTDM_COMMAND_OBJ_INT); @@ -1051,7 +1063,9 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_MUTE); - ftdm_channel_queue_dtmf(ftdmchan, tmp_dtmf); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) { + ftdm_channel_queue_dtmf(ftdmchan, tmp_dtmf); + } } } break; diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h index d1b3a4f711..776ec07367 100644 --- a/libs/freetdm/src/include/ftdm_types.h +++ b/libs/freetdm/src/include/ftdm_types.h @@ -315,6 +315,8 @@ typedef enum { FTDM_COMMAND_SET_PRE_BUFFER_SIZE, FTDM_COMMAND_SET_LINK_STATUS, FTDM_COMMAND_GET_LINK_STATUS, + FTDM_COMMAND_ENABLE_LOOP, + FTDM_COMMAND_DISABLE_LOOP, FTDM_COMMAND_COUNT } ftdm_command_t; @@ -374,6 +376,7 @@ typedef enum { FTDM_CHANNEL_STATE_CANCEL, FTDM_CHANNEL_STATE_HANGUP, FTDM_CHANNEL_STATE_HANGUP_COMPLETE, + FTDM_CHANNEL_STATE_IN_LOOP, FTDM_CHANNEL_STATE_INVALID } ftdm_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ From a825c1bbf5fc5331a47d1cf8b56578a8466da23b Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 26 Feb 2010 20:57:59 +0000 Subject: [PATCH 1734/1766] Support for SIGBOOST Version 103 Allows passthrough for TON and NPI on outgoing calls via sigboost git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1041 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 79 +++++++++++++++++-- libs/openzap/src/include/openzap.h | 20 ++++- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 61 ++++++++------ .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 73 +++++++++++++---- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 3 + libs/openzap/src/zap_io.c | 43 +++++++++- 6 files changed, 235 insertions(+), 44 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index f542908f33..2961cd0804 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -61,7 +61,7 @@ struct span_config { char dial_regex[256]; char fail_dial_regex[256]; char hold_music[256]; - char type[256]; + char type[256]; analog_option_t analog_options; }; @@ -133,6 +133,43 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); +static void zap_set_npi(const char *npi_string, uint8_t *target) +{ + if (!strcasecmp(npi_string, "isdn") || !strcasecmp(npi_string, "e164")) { + *target = ZAP_NPI_ISDN; + } else if (!strcasecmp(npi_string, "data")) { + *target = ZAP_NPI_DATA; + } else if (!strcasecmp(npi_string, "telex")) { + *target = ZAP_NPI_TELEX; + } else if (!strcasecmp(npi_string, "national")) { + *target = ZAP_NPI_NATIONAL; + } else if (!strcasecmp(npi_string, "private")) { + *target = ZAP_NPI_PRIVATE; + } else if (!strcasecmp(npi_string, "reserved")) { + *target = ZAP_NPI_RESERVED; + } else if (!strcasecmp(npi_string, "unknown")) { + *target = ZAP_NPI_UNKNOWN; + } else { + zap_log(ZAP_LOG_WARNING, "Invalid NPI value (%s)\n", npi_string); + *target = ZAP_NPI_UNKNOWN; + } +} + +static void zap_set_ton(const char *ton_string, uint8_t *target) +{ + if (!strcasecmp(ton_string, "national")) { + *target = ZAP_TON_NATIONAL; + } else if (!strcasecmp(ton_string, "international")) { + *target = ZAP_TON_INTERNATIONAL; + } else if (!strcasecmp(ton_string, "local")) { + *target = ZAP_TON_SUBSCRIBER_NUMBER; + } else if (!strcasecmp(ton_string, "unknown")) { + *target = ZAP_TON_UNKNOWN; + } else { + zap_log(ZAP_LOG_WARNING, "Invalid TON value (%s)\n", ton_string); + *target = ZAP_TON_UNKNOWN; + } +} static switch_core_session_t *zap_channel_get_session(zap_channel_t *channel, int32_t id) { @@ -1109,7 +1146,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi int argc = 0; const char *var; - if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -1196,10 +1232,17 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } else { caller_data.ani.type = outbound_profile->destination_number_ton; } - + caller_data.ani.plan = outbound_profile->destination_number_numplan; + /* blindly copy data from outbound_profile. They will be overwritten + * by calling zap_caller_data if needed after */ + caller_data.cid_num.type = outbound_profile->caller_ton; + caller_data.cid_num.plan = outbound_profile->caller_numplan; + caller_data.rdnis.type = outbound_profile->rdnis_ton; + caller_data.rdnis.plan = outbound_profile->rdnis_numplan; + #if 0 if (!zstr(outbound_profile->rdnis)) { zap_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); @@ -1211,6 +1254,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); + zap_set_caller_data(span_id, &caller_data); } else { status = zap_channel_open_any(span_id, direction, &caller_data, &zchan); } @@ -2198,6 +2242,7 @@ static switch_status_t load_config(void) uint32_t to = 0; int q921loglevel = -1; int q931loglevel = -1; + // quick debug //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); @@ -2389,6 +2434,12 @@ static switch_status_t load_config(void) zap_status_t zstatus = ZAP_FAIL; const char *context = "default"; const char *dialplan = "XML"; + const char *outbound_called_ton = "unknown"; + const char *outbound_called_npi = "unknown"; + const char *outbound_calling_ton = "unknown"; + const char *outbound_calling_npi = "unknown"; + const char *outbound_rdnis_ton = "unknown"; + const char *outbound_rdnis_npi = "unknown"; uint32_t span_id = 0; zap_span_t *span = NULL; const char *tonegroup = NULL; @@ -2413,8 +2464,18 @@ static switch_status_t load_config(void) remote_port = atoi(val); } else if (!strcasecmp(var, "context")) { context = val; - } else if (!strcasecmp(var, "dialplan")) { - dialplan = val; + } else if (!strcasecmp(var, "outbound-called-ton")) { + outbound_called_ton = val; + } else if (!strcasecmp(var, "outbound-called-npi")) { + outbound_called_npi = val; + } else if (!strcasecmp(var, "outbound-calling-ton")) { + outbound_calling_ton = val; + } else if (!strcasecmp(var, "outbound-calling-npi")) { + outbound_calling_npi = val; + } else if (!strcasecmp(var, "outbound-rdnis-ton")) { + outbound_rdnis_ton = val; + } else if (!strcasecmp(var, "outbound-rdnis-npi")) { + outbound_rdnis_npi = val; } } @@ -2449,6 +2510,14 @@ static switch_status_t load_config(void) span_id = span->span_id; } + zap_set_npi(outbound_called_npi, &span->default_caller_data.ani.plan); + zap_set_npi(outbound_calling_npi, &span->default_caller_data.cid_num.plan); + zap_set_npi(outbound_rdnis_npi, &span->default_caller_data.rdnis.plan); + + zap_set_ton(outbound_called_ton, &span->default_caller_data.ani.type); + zap_set_ton(outbound_calling_ton, &span->default_caller_data.cid_num.type); + zap_set_ton(outbound_rdnis_ton, &span->default_caller_data.rdnis.type); + if (zap_configure_span("sangoma_boost", span, on_clear_channel_signal, "local_ip", local_ip, "local_port", &local_port, diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 2a654f2406..b7e75575c8 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -438,9 +438,24 @@ typedef enum { ZAP_TON_NETWORK_SPECIFIC, ZAP_TON_SUBSCRIBER_NUMBER, ZAP_TON_ABBREVIATED_NUMBER, - ZAP_TON_RESERVED + ZAP_TON_RESERVED, + ZAP_TON_INVALID = 255 } zap_ton_t; +/** + * Numbering Plan Identification (NPI) + */ +typedef enum { + ZAP_NPI_UNKNOWN = 0, + ZAP_NPI_ISDN = 1, + ZAP_NPI_DATA = 3, + ZAP_NPI_TELEX = 4, + ZAP_NPI_NATIONAL = 8, + ZAP_NPI_PRIVATE = 9, + ZAP_NPI_RESERVED = 10, + ZAP_NPI_INVALID = 255 +} zap_npi_t; + typedef struct { char digits[25]; uint8_t type; @@ -584,6 +599,7 @@ struct zap_span { size_t dtmf_hangup_len; int suggest_chan_id; zap_state_map_t *state_map; + zap_caller_data_t default_caller_data; struct zap_span *next; }; @@ -700,6 +716,8 @@ OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **sp OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd); OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap); +OZ_DECLARE(void) zap_set_caller_data(uint32_t span_id, zap_caller_data_t *caller_data); + ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); ZIO_CODEC_FUNCTION(zio_slin2alaw); 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 index b0953f2b4d..ae79918b42 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -291,6 +291,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) 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; @@ -317,13 +318,22 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } zap_set_string(event.calling_name, caller_data->cid_name); - zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); + zap_set_string(event.rdnis.digits, caller_data->rdnis.digits); + if (strlen(caller_data->rdnis.digits)) { - event.isup_in_rdnis_size = strlen(caller_data->rdnis.digits)+1; + 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_number_screening_ind = caller_data->screen; - event.calling_number_presentation = caller_data->pres; + 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; OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; @@ -728,35 +738,42 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa } zchan->sflags = 0; - zap_set_string(zchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); - zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_number_digits); + 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 (strlen(event->calling_name)) { zap_set_string(zchan->caller_data.cid_name, (char *)event->calling_name); } - zap_set_string(zchan->caller_data.ani.digits, (char *)event->calling_number_digits); - zap_set_string(zchan->caller_data.dnis.digits, (char *)event->called_number_digits); - if (event->isup_in_rdnis_size) { - char* p; - //Set value of rdnis.digis in case prot daemon is still using older style RDNIS - if (atoi((char *)event->isup_in_rdnis) > 0) { - zap_set_string(zchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); - } + zchan->caller_data.cid_num.plan = event->calling.npi; + zchan->caller_data.cid_num.type = event->calling.ton; - p = strstr((char*)event->isup_in_rdnis,"PRI001-ANI2-"); + 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; + + if (event->custom_data_size) { + char* p = NULL; + + p = strstr((char*)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); } - p = strstr((char*)event->isup_in_rdnis,"RDNIS-"); - if (p!=NULL) { - sscanf(p, "RDNIS-%s", &zchan->caller_data.rdnis.digits[0]); - } - } - zchan->caller_data.screen = event->calling_number_screening_ind; - zchan->caller_data.pres = event->calling_number_presentation; + zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_RING); return; diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h index 1b90930ffe..1281069536 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -14,11 +14,15 @@ #ifndef _SIGBOOST_H_ #define _SIGBOOST_H_ -#define SIGBOOST_VERSION 101 +#define SIGBOOST_VERSION 103 #include #include +#ifdef HAVE_FREETDM +#include +#endif + enum e_sigboost_event_id_values { SIGBOOST_EVENT_CALL_START = 0x80, /*128*/ @@ -30,7 +34,22 @@ enum e_sigboost_event_id_values SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/ SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/ SIGBOOST_EVENT_SYSTEM_RESTART_ACK = 0x88, /*136*/ - SIGBOOST_EVENT_CALL_PROGRESS = 0x50, /*decimal 80*/ + /* 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*/ @@ -91,7 +110,12 @@ enum e_sigboost_progress_flags #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 */ -#define SIZE_RDNIS 900 + +/* Should only be used by server */ +#define MAX_CALL_SETUP_ID 0xFFFF + +#define SIZE_CUSTOM 900 +#define SIZE_RDNIS SIZE_CUSTOM #pragma pack(1) @@ -100,7 +124,17 @@ typedef struct { uint8_t capability; uint8_t uil1p; -}t_sigboost_bearer; +} 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 { @@ -115,21 +149,30 @@ typedef struct uint8_t chan; uint32_t flags; /* struct timeval tv; */ - 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 */ + t_sigboost_digits called; + t_sigboost_digits calling; + t_sigboost_digits rdnis; /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ - uint8_t calling_number_screening_ind; - uint8_t calling_number_presentation; char calling_name[MAX_DIALED_DIGITS + 1]; t_sigboost_bearer bearer; uint8_t hunt_group; - uint16_t isup_in_rdnis_size; - char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ + uint16_t custom_data_size; + char custom_data[SIZE_CUSTOM]; /* it's a null terminated string */ + } t_sigboost_callstart; -#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS +#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 { @@ -154,10 +197,10 @@ 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: + case SIGBOOST_EVENT_CALL_PROGRESS: return 1; default: - return 0; + break; } return 0; diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 190edc2a8d..59d4155d33 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -687,6 +687,9 @@ static ZIO_WRITE_FUNCTION(wanpipe_write) /* 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? */ diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 92ec4419e8..e0768e145e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -176,6 +176,45 @@ static void default_logger(const char *file, const char *func, int line, int lev } +OZ_DECLARE(void) zap_set_caller_data(uint32_t span_id, zap_caller_data_t *caller_data) +{ + zap_span_t *span = NULL; + if (!span_id) { + zap_log(ZAP_LOG_CRIT, "Error: trying to set caller data, but no span id?\n"); + return; + } + + zap_span_find(span_id, &span); + if (!span) { + zap_log(ZAP_LOG_CRIT, "Error: trying to set caller data, but could not find span\n"); + return; + } + + if (caller_data->cid_num.plan == ZAP_NPI_INVALID) { + caller_data->cid_num.plan = span->default_caller_data.cid_num.plan; + } + + if (caller_data->cid_num.type == ZAP_TON_INVALID) { + caller_data->cid_num.type = span->default_caller_data.cid_num.type; + } + + if (caller_data->ani.plan == ZAP_NPI_INVALID) { + caller_data->ani.plan = span->default_caller_data.ani.plan; + } + + if (caller_data->ani.type == ZAP_TON_INVALID) { + caller_data->ani.type = span->default_caller_data.ani.type; + } + + if (caller_data->rdnis.plan == ZAP_NPI_INVALID) { + caller_data->rdnis.plan = span->default_caller_data.rdnis.plan; + } + + if (caller_data->rdnis.type == ZAP_NPI_INVALID) { + caller_data->rdnis.type = span->default_caller_data.rdnis.type; + } +} + OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; OZ_DECLARE(void) zap_global_set_logger(zap_logger_t logger) @@ -967,7 +1006,9 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t *zchan = NULL; return ZAP_FAIL; } - + + zap_set_caller_data(span_id, caller_data); + if (span->channel_request && !span->suggest_chan_id) { return span->channel_request(span, 0, direction, caller_data, zchan); } From c34e5320d3a93fb85986236958569f86c092eb18 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 26 Feb 2010 22:54:59 +0000 Subject: [PATCH 1735/1766] Changed zap_channel_set_caller_data Set default NPI to e164 and default TON to national git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1042 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 15 ++++++------ libs/openzap/src/include/openzap.h | 3 +-- libs/openzap/src/zap_io.c | 34 ++++++++++++++++---------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 2961cd0804..f98d571702 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1254,7 +1254,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); - zap_set_caller_data(span_id, &caller_data); } else { status = zap_channel_open_any(span_id, direction, &caller_data, &zchan); } @@ -1304,7 +1303,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_variable(channel, "openzap_span_name", zchan->span->name); switch_channel_set_variable_printf(channel, "openzap_span_number", "%d", zchan->span_id); switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", zchan->chan_id); - zchan->caller_data = caller_data; + zap_channel_set_caller_data(zchan, &caller_data); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -2434,12 +2433,12 @@ static switch_status_t load_config(void) zap_status_t zstatus = ZAP_FAIL; const char *context = "default"; const char *dialplan = "XML"; - const char *outbound_called_ton = "unknown"; - const char *outbound_called_npi = "unknown"; - const char *outbound_calling_ton = "unknown"; - const char *outbound_calling_npi = "unknown"; - const char *outbound_rdnis_ton = "unknown"; - const char *outbound_rdnis_npi = "unknown"; + const char *outbound_called_ton = "national"; + const char *outbound_called_npi = "isdn"; + const char *outbound_calling_ton = "national"; + const char *outbound_calling_npi = "isdn"; + const char *outbound_rdnis_ton = "national"; + const char *outbound_rdnis_npi = "isdn"; uint32_t span_id = 0; zap_span_t *span = NULL; const char *tonegroup = NULL; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index b7e75575c8..3f88772cd8 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -715,8 +715,7 @@ OZ_DECLARE(int) zap_load_module_assume(const char *name); OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **span); OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd); OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap); - -OZ_DECLARE(void) zap_set_caller_data(uint32_t span_id, zap_caller_data_t *caller_data); +OZ_DECLARE(zap_status_t) zap_channel_set_caller_data(zap_channel_t *zchan, zap_caller_data_t *caller_data); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index e0768e145e..8c11bae87e 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -176,18 +176,11 @@ static void default_logger(const char *file, const char *func, int line, int lev } -OZ_DECLARE(void) zap_set_caller_data(uint32_t span_id, zap_caller_data_t *caller_data) +static zap_status_t zap_set_caller_data(zap_span_t *span, zap_caller_data_t *caller_data) { - zap_span_t *span = NULL; - if (!span_id) { - zap_log(ZAP_LOG_CRIT, "Error: trying to set caller data, but no span id?\n"); - return; - } - - zap_span_find(span_id, &span); - if (!span) { - zap_log(ZAP_LOG_CRIT, "Error: trying to set caller data, but could not find span\n"); - return; + if (!caller_data) { + zap_log(ZAP_LOG_CRIT, "Error: trying to set caller data, but no caller_data!\n"); + return ZAP_FAIL; } if (caller_data->cid_num.plan == ZAP_NPI_INVALID) { @@ -213,6 +206,21 @@ OZ_DECLARE(void) zap_set_caller_data(uint32_t span_id, zap_caller_data_t *caller if (caller_data->rdnis.type == ZAP_NPI_INVALID) { caller_data->rdnis.type = span->default_caller_data.rdnis.type; } + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_channel_set_caller_data(zap_channel_t *zchan, zap_caller_data_t *caller_data) +{ + zap_status_t err = ZAP_SUCCESS; + if (!zchan) { + zap_log(ZAP_LOG_CRIT, "Error: trying to set caller data, but no zchan!\n"); + return ZAP_FAIL; + } + if ((err = zap_set_caller_data(zchan->span, caller_data)) != ZAP_SUCCESS) { + return err; + } + zchan->caller_data = *caller_data; + return ZAP_SUCCESS; } OZ_DECLARE_DATA zap_logger_t zap_log = null_logger; @@ -1007,9 +1015,8 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t return ZAP_FAIL; } - zap_set_caller_data(span_id, caller_data); - if (span->channel_request && !span->suggest_chan_id) { + zap_set_caller_data(span, caller_data); return span->channel_request(span, 0, direction, caller_data, zchan); } @@ -1056,6 +1063,7 @@ OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t ) { if (span && span->channel_request) { + zap_set_caller_data(span, caller_data); status = span->channel_request(span, i, direction, caller_data, zchan); break; } From b7f198ba18e877c2f47c028092118ee2076c4179 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 27 Feb 2010 18:47:19 +0000 Subject: [PATCH 1736/1766] added boost-tasks.txt old doc, it might be useful later git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1043 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ftmod/ftmod_sangoma_boost/boost-tasks.txt | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 libs/freetdm/src/ftmod/ftmod_sangoma_boost/boost-tasks.txt diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/boost-tasks.txt b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/boost-tasks.txt new file mode 100644 index 0000000000..f0eab3a277 --- /dev/null +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/boost-tasks.txt @@ -0,0 +1,146 @@ +== General Design == + +NBE will do its current loading of spans and configuration process through Sangoma Board Manager (SBM). +After doing SangomaBoardManager::getInstance().configure -> start. It will proceed to initalize +the openzap stack (just as the TelesoftStack is loaded after starting SMB. The procedure will be: + +- create a static or malloced zap_io_interface_t +- call zap_global_set_logger with the logging hooks. +- call zap_global_set_memhandler() with the memory hooks. +- call zap_global_init() to initialize the stack +- call zap_add_io_iface() to add the I/O iface. +- iterate over all SBM spans configured for BRI or any boost-managed signaling and: + * call zap_span_create(NBE I/O mod, in_ptrSpan, SMB span name) + * Fill in some members like: + span->trunk_type = E1/T1/J1/FXO/FXS etc ... + * iterate over all channels in SMB span and: + * zap_span_add_channel(zap_span, sock, type:CAS|BCHAN|DCHAN|ETC) + * call zap_configure_span("sangoma_boost", span, sigmsg_callback, "param1", value1, "param2", value1 ...) + * zap_span_start(span); + + +At this point, NBE would receive signaling msgs via sigmsg_callback registered when configuring +and NBE would request hangup or making calls throug openzap API, like zap_set_state_* and zap_channel_outgoing_call() to place calls. + +When NBE wants to check for link status. + + zap_get_siglink_state() which would return + ZAP_SIG_STATE_UP (D-chan UP, R2 bits in IDLE, ss7?) + ZAP_SIG_STATE_SUSPENDED (D-chan in power saving mode?) + ZAP_SIG_STATE_DOWN (D-chan down, R2 bits in blocked, ss7?) + + Whenever a state in sig link changes, the sigmsg_callback will be used to notify NBE or any other user. + +NOTE: right now hardware alarms notification in openzap is seriously broken, +see ozmod_libpri.c process_event ... reads an event from hardware (zap_event_t *), +then checks the event type, if its ZAP_OOB_ALARM_TRAP prepares a zap_sigmsg_t +(signaling event) setting its event_id to ZAP_OOB_ALARM_TRAP, which is *WRONG* +because event_id is of type zap_signal_event_t and not zap_oob_event_t! +this means on alarm the user will get ZAP_SIGEVENT_PROGRESS_MEDIA!! which is +value 7 that is in conflict with ZAP_OOB_ALARM_TRAP, I think a separate +callback should be used if the outside user wants to be notified about +hardware events like HW DTMF or so. Currently there is alreadya generic DTMF +listener. + +== Tasks Stage 1 / OpenZAP and Boost changes (To be tested with FreeSWITCH) == + +- Change malloc and other mem functions in openzap + to use internal hooks provided via zap_global_set_memhandler() + which would be called before zap_global_init(), this is + already done for the logger via zap_global_set_logger() + + question: should the mem routines allow for memory pool ptr? + this could be useful to provide a memory pool to + the whole module. + + question: should we allow hooks for threads and locking? + I think we can skip this one unless needed. They already + use their own threading abstraction which is working for + Linux and Windows. If we ever need to profile threading + we can add profiling hooks. + + question: I had to add openzap calls to the hash table and libteletone implementations, is that acceptable? + +- Modify zap_global_init() API + + This API must just initialize vars, mutexes etc. + and NOT DO ANY CONFIGURATION LOADING, PARSING, SPAN CREATION and I/O + configuration, which is what is currently doing. + We don't want zap_global_init() to create the spans based on that configuration + since NBE will have its own configuration and will take care of creating + the needed data structures on its own. + +- Add new zap_std_io_config() API + + This API will parse the standard openzap.conf module and create the spans. + This will be used by FS but not by NBE, which will create the openzap spans by itself. + The NBE flow to initialize openzap will be: + +- Add new API zap_global_add_io_iface(), + + This API will add a new I/O interface structure to the internal openzap hash of I/O structs. + This is needed because NBE I/O structure will NOT be loaded from an openzap module (.so/.dll) + but rather just registered on runtime (probably from a static structure in NBE code). + This openzap hash is used by zap_api_execute() for example, to find the module that can + handle a given API, ie (oz libpri status). This is an example of how an openzap I/O interface + can decide to implement just the ->api() member to handle commands and NOTHING else, + so I/O interfaces not necessary are hardware-related. + +- Add new zap_channel_get_siglink_state(zap_channel, zap_siglink_status_t &status) + +- Modify mod_openzap.c to read proto= setting in boost spans, this will determine wich boost sig + module will handle the configuration and those channels. + + + + Then as first config arg to zap_config_span() the boost proto module name would be included as "sigmod" which will be used + by ozmod_sangoma_boost to decide which sig module must handle that span configuration + +- Create minimal boost mod interface. + + ozmod_boost_ss7 should load sig boost mods and get interface via dlsym(boost_get_interface) boost_get_interface(boost_iface); + The boost interface will have + * const char *name // boost sigmod name (brid,ss7d) + * set_write_boost_msg_cb(callback) // tell the stack how to send us boost messages + * set_sig_status_cb(callback); // tell the stack how to notify us about link status changes + * write_boost_msg(struct boost_msg) // send a boost msg to the stack + * configure_span(zap_span_t span, "configuration", value, "configuration", value) // configure a given span + * get_sig_status(openzap_sigstatus_t status) + * start(span) // to start a given openzap span + * stop(span) // to stop the stack on a given openzap span + +- Migrate current sangoma_brid sig module to openzap + * Make sangoma_brid a library + * Move from using malloc, threading, locking, logging and I/O to openzap functions. Export the boost sigmod interface and its supporting code. + +== State 2 Tasks == + +- Create the I/O NBE interface and supporting functions. It must be possible to poll over the span + given that ozmod_sangoma_boost BRI module and others may need to *wait* for data. The poll() + function in I/O NBE interface would wait on a pthread condition or Windows event, which would + be triggered by some external NBE component registered with Sangoma Board Manager (SMB) for d-chan + data, whenever d-chan data arrives, saves the data in a buffer and triggers the condition to wakeup + any waiter, then the waiter (sangoma_brid or any other boost client) calls zap_channel_read which calls + our own I/O NBE interface read method and retrieves the data from the buffer. + + Dropped alternative design: + Another option is to add a new API zap_span_push_incoming_data(span/chan, data); However this changes + the model openzap has followed and I don't think fits that well, since now we have 2 different models + to support in openzap. + +== TODO == + +- how about logging specific modules, like, just ozmod_boost, or just the BRI stack? + more work to be done so the BRI module uses zap_log instead of current syslog + then work to be done to be able to filter logs from specific openzap code? is it worth it? + +- remove FORCE_SEGFAULT from sprid + + +=== Shortcomings == + +- we had to drop smg support in the branch where we work on sangoma prid. + After all, most people using sangoma_prid is using freeswitch/openzap and not Sangoma Media Gateway + The problem is in freeswitch/openzap mode, sangoma_boost ozmod takes care of span events (POLLPRI) + where in SMG and Netborder POLLPRI is done typically by sangoma board manager. + From 7ffddd316a45491a840ee387c4b93eeb36b02317 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 1 Mar 2010 19:52:01 +0000 Subject: [PATCH 1737/1766] commit testsangomaboost.2008 vc project git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1044 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../testboost/testsangomaboost.2008.vcproj | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 libs/freetdm/msvc/testboost/testsangomaboost.2008.vcproj diff --git a/libs/freetdm/msvc/testboost/testsangomaboost.2008.vcproj b/libs/freetdm/msvc/testboost/testsangomaboost.2008.vcproj new file mode 100644 index 0000000000..f6aec0b1de --- /dev/null +++ b/libs/freetdm/msvc/testboost/testsangomaboost.2008.vcproj @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 3a4deae812c74aa8cb2e4d8934e59055f539ae5e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 1 Mar 2010 20:50:40 +0000 Subject: [PATCH 1738/1766] handle SIGBOOST_EVENT_CALL_RELEASED git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1045 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 53e1beb9b4..48b8efebaf 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -1076,6 +1076,7 @@ static ftdm_channel_t* event_process_states(ftdm_span_t *span, sangomabc_short_e case SIGBOOST_EVENT_DIGIT_IN: case SIGBOOST_EVENT_INSERT_CHECK_LOOP: case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: + case SIGBOOST_EVENT_CALL_RELEASED: if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { ftdm_log(FTDM_LOG_DEBUG, "PROCESS STATES CANT FIND CHAN %d:%d\n", event->span+1,event->chan+1); return NULL; From 46470d503096208fe4099a6a1ea46b8263a3ae22 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 1 Mar 2010 23:23:51 +0000 Subject: [PATCH 1739/1766] cleanup caller id handling on originate to bridge git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1046 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index f98d571702..6eeda6420f 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1145,6 +1145,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char *argv[3]; int argc = 0; const char *var; + const char *dest_num = NULL, *callerid_num = NULL; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -1159,8 +1160,18 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); - outbound_profile->destination_number = switch_sanitize_number(outbound_profile->destination_number); + if (!zstr(outbound_profile->destination_number)) { + dest_num = switch_sanitize_number(switch_core_session_strdup(session, outbound_profile->destination_number)); + } + if (!zstr(outbound_profile->caller_id_number)) { + callerid_num = switch_sanitize_number(switch_core_session_strdup(session, outbound_profile->caller_id_number)); + } + + if (!zstr(callerid_num) && !strcmp(callerid_num, "0000000000")) { + callerid_num = NULL; + } + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -1250,7 +1261,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi #endif zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name); - zap_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); + zap_set_string(caller_data.cid_num.digits, switch_str_nil(callerid_num)); if (chan_id) { status = zap_channel_open(span_id, chan_id, &zchan); @@ -1305,6 +1316,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_variable_printf(channel, "openzap_chan_number", "%d", zchan->chan_id); zap_channel_set_caller_data(zchan, &caller_data); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + caller_profile->destination_number = switch_core_strdup(caller_profile->pool, switch_str_nil(dest_num)); + caller_profile->caller_id_number = switch_core_strdup(caller_profile->pool, switch_str_nil(callerid_num)); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; From 58274f03867cdae2005b5d5c8bb28ad742fecf38 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 2 Mar 2010 00:15:52 +0000 Subject: [PATCH 1740/1766] cleanup caller id handling on originate to bridge git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1047 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 6eeda6420f..6787108f49 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1161,11 +1161,11 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); if (!zstr(outbound_profile->destination_number)) { - dest_num = switch_sanitize_number(switch_core_session_strdup(session, outbound_profile->destination_number)); + dest_num = switch_sanitize_number(switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number)); } if (!zstr(outbound_profile->caller_id_number)) { - callerid_num = switch_sanitize_number(switch_core_session_strdup(session, outbound_profile->caller_id_number)); + callerid_num = switch_sanitize_number(switch_core_strdup(outbound_profile->pool, outbound_profile->caller_id_number)); } if (!zstr(callerid_num) && !strcmp(callerid_num, "0000000000")) { From 46175f6f1141ccfbb3ffcf55485913be9947a4c0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 2 Mar 2010 15:43:02 +0000 Subject: [PATCH 1741/1766] set analog channel suspended when in alarm git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1048 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c index 595f0ecebc..943badb1dd 100644 --- a/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/openzap/src/ozmod/ozmod_analog/ozmod_analog.c @@ -901,6 +901,14 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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: From 18d34771314f23a643d45868b550d7ab22d04d7d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 5 Mar 2010 16:30:02 +0000 Subject: [PATCH 1742/1766] send signaling alarm notification from the IO modules git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1049 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c | 11 ----------- .../src/ozmod/ozmod_libpri/ozmod_libpri.c | 12 ------------ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 7 +++++++ libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c index 3c061960a1..fc998b126f 100644 --- a/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/openzap/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -1512,20 +1512,12 @@ static __inline__ void check_state(zap_span_t *span) */ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { - zap_sigmsg_t sig; - - 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)); switch(event->enum_id) { case ZAP_OOB_ALARM_TRAP: { - sig.event_id = 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); @@ -1537,7 +1529,6 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_channel_get_alarms(event->channel); - zap_span_send_signal(span, &sig); 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, @@ -1550,10 +1541,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); - sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - zap_span_send_signal(span, &sig); } break; } diff --git a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c index 0c8aadede3..f18aa1fc54 100644 --- a/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/openzap/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -806,20 +806,12 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event */ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *event) { - zap_sigmsg_t sig; - - 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:%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: { - sig.event_id = 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); @@ -831,7 +823,6 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even zap_channel_get_alarms(event->channel); - zap_span_send_signal(span, &sig); 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, @@ -840,14 +831,11 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even 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); - sig.event_id = ZAP_OOB_ALARM_CLEAR; zap_clear_flag(event->channel, ZAP_CHANNEL_SUSPENDED); zap_channel_get_alarms(event->channel); - zap_span_send_signal(span, &sig); } break; } diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 59d4155d33..ea9d58a43d 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -962,6 +962,8 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; @@ -970,6 +972,11 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) 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; diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 3b383d89a4..111e5a26ab 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -1027,12 +1027,28 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) 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: From 737597eba606731a3c6e967ac94f1c5befb9d605 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 5 Mar 2010 20:14:44 +0000 Subject: [PATCH 1743/1766] boostrap git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1050 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/bootstrap | 6 ++++ libs/openzap/mod_openzap/mod_openzap.c | 47 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 libs/openzap/bootstrap diff --git a/libs/openzap/bootstrap b/libs/openzap/bootstrap new file mode 100755 index 0000000000..8ca4856832 --- /dev/null +++ b/libs/openzap/bootstrap @@ -0,0 +1,6 @@ +#!/bin/bash +autoheader +libtoolize --force --copy +aclocal +automake -f --copy --add-missing +autoconf diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 6787108f49..a117e14a05 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1824,6 +1824,49 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) return status; } +static ZIO_SIGNAL_CB_FUNCTION(on_common_signal) +{ + switch_event_t *event = NULL; + + switch (sigmsg->event_id) { + + case ZAP_SIGEVENT_ALARM_CLEAR: + case ZAP_SIGEVENT_ALARM_TRAP: + { + if (zap_channel_get_alarms(sigmsg->channel) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "failed to retrieve alarms\n"); + return ZAP_FAIL; + } + if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "failed to create alarms events\n"); + return ZAP_FAIL; + } + if (sigmsg->event_id == ZAP_SIGEVENT_ALARM_CLEAR) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "zap-alarm-clear"); + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "zap-alarm-trap"); + } + } + break; + default: + return ZAP_SUCCESS; + break; + } + + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_RED)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "red"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_YELLOW)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "yellow"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_BLUE)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "blue"); + } + switch_event_fire(&event); + + return ZAP_BREAK; +} + static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; @@ -1831,6 +1874,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) zap_log(ZAP_LOG_DEBUG, "got clear channel sig [%s]\n", zap_signal_event2str(sigmsg->event_id)); + if (on_common_signal(sigmsg) == ZAP_BREAK) { + return ZAP_SUCCESS; + } + switch(sigmsg->event_id) { case ZAP_SIGEVENT_START: { From d32f7f67a33d15fdc1a38d8c560991e60b84bb51 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 5 Mar 2010 21:59:00 +0000 Subject: [PATCH 1744/1766] more alarms git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1051 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 111 +++++++++++------- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 43 ++++++- 2 files changed, 107 insertions(+), 47 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a117e14a05..80c612987c 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1447,6 +1447,66 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t return ZAP_SUCCESS; } +static ZIO_SIGNAL_CB_FUNCTION(on_common_signal) +{ + switch_event_t *event = NULL; + + switch (sigmsg->event_id) { + + case ZAP_SIGEVENT_ALARM_CLEAR: + case ZAP_SIGEVENT_ALARM_TRAP: + { + if (zap_channel_get_alarms(sigmsg->channel) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "failed to retrieve alarms\n"); + return ZAP_FAIL; + } + if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "failed to create alarms events\n"); + return ZAP_FAIL; + } + if (sigmsg->event_id == ZAP_SIGEVENT_ALARM_CLEAR) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "zap-alarm-clear"); + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "zap-alarm-trap"); + } + } + break; + default: + return ZAP_SUCCESS; + break; + } + + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_RECOVER)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "recover"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_LOOPBACK)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "loopback"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_YELLOW)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "yellow"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_RED)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "red"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_BLUE)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "blue"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_NOTOPEN)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "notopen"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_AIS)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "ais"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_RAI)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "rai"); + } + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_GENERAL)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "general"); + } + switch_event_fire(&event); + + return ZAP_BREAK; +} static ZIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { @@ -1729,6 +1789,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) zap_log(ZAP_LOG_DEBUG, "Got R2 channel sig [%s] in channel %d\n", zap_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); + if (on_common_signal(sigmsg) == ZAP_BREAK) { + return ZAP_SUCCESS; + } + switch(sigmsg->event_id) { /* on_call_disconnect from the R2 side */ case ZAP_SIGEVENT_STOP: @@ -1824,49 +1888,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_r2_signal) return status; } -static ZIO_SIGNAL_CB_FUNCTION(on_common_signal) -{ - switch_event_t *event = NULL; - - switch (sigmsg->event_id) { - - case ZAP_SIGEVENT_ALARM_CLEAR: - case ZAP_SIGEVENT_ALARM_TRAP: - { - if (zap_channel_get_alarms(sigmsg->channel) != ZAP_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "failed to retrieve alarms\n"); - return ZAP_FAIL; - } - if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) { - zap_log(ZAP_LOG_ERROR, "failed to create alarms events\n"); - return ZAP_FAIL; - } - if (sigmsg->event_id == ZAP_SIGEVENT_ALARM_CLEAR) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "zap-alarm-clear"); - } else { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "zap-alarm-trap"); - } - } - break; - default: - return ZAP_SUCCESS; - break; - } - - if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_RED)) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "red"); - } - if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_YELLOW)) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "yellow"); - } - if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_BLUE)) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "blue"); - } - switch_event_fire(&event); - - return ZAP_BREAK; -} - static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) { switch_core_session_t *session = NULL; @@ -1966,6 +1987,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch_status_t status = SWITCH_STATUS_FALSE; + if (on_common_signal(sigmsg) == ZAP_BREAK) { + return ZAP_SUCCESS; + } + switch (sigmsg->channel->type) { case ZAP_CHAN_TYPE_FXO: case ZAP_CHAN_TYPE_EM: diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index ea9d58a43d..fafa7a447c 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -897,11 +897,38 @@ static ZIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) } alarms = tdm_api.wp_tdm_cmd.fe_alarms; #endif + zchan->alarm_flags = ZAP_ALARM_NONE; - - zchan->alarm_flags = alarms ? ZAP_ALARM_RED : ZAP_ALARM_NONE; + if (alarms & WAN_TE_BIT_ALARM_RED) { + zchan->alarm_flags |= ZAP_ALARM_RED; + alarms &= ~WAN_TE_BIT_ALARM_RED; + } - return ZAP_SUCCESS; + 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; } /** @@ -1055,7 +1082,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } break; case WP_TDMAPI_EVENT_ALARM: - event_id = ZAP_OOB_NOOP; + zap_log(ZAP_LOG_DEBUG, "Got wanpipe alarms %d\n", tdm_api.wp_tdm_cmd.event.wp_api_event_alarm); + zap_sigmsg_t sigmsg; + 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: { From 82f46fd7f3e8f014167eee2615873cbfeacb3f99 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 5 Mar 2010 23:01:23 +0000 Subject: [PATCH 1745/1766] adding span name, number and chan to trap event git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1052 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 80c612987c..fddf2de69a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1476,6 +1476,10 @@ static ZIO_SIGNAL_CB_FUNCTION(on_common_signal) break; } + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-name", "%s", sigmsg->channel->span->name); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-number", "%d", sigmsg->channel->span_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "chan-number", "%d", sigmsg->channel->chan_id); + if (zap_test_alarm_flag(sigmsg->channel, ZAP_ALARM_RECOVER)) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "recover"); } From d6fcb65606c00dfdb75fe009f297d02e6b6ca8d5 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 5 Mar 2010 23:05:59 +0000 Subject: [PATCH 1746/1766] NC: Added a sanity check on call start. In case of know sangoma_isupd boost errors Added Loop command to enable channel looping on CCR tests in ss7. Added hwec enable disable commands that are available in CLI git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1053 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 15 ++++++++++ .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 28 ++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) 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 index ae79918b42..a8609a0652 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -728,6 +728,21 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa zap_channel_t *zchan; if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { + if ((zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { + int r; + if (zchan->state == ZAP_CHANNEL_STATE_UP) { + zap_log(ZAP_LOG_CRIT, "ZCHAN STATE UP -> Changed to TERMINATING %d:%d\n", event->span+1,event->chan+1); + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_TERMINATING, 0, r); + } else if (zap_test_sflag(zchan, SFLAG_HANGUP)) { + zap_log(ZAP_LOG_CRIT, "ZCHAN STATE HANGUP -> Changed to HANGUP COMPLETE %d:%d\n", event->span+1,event->chan+1); + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, 0, r); + } else { + zap_log(ZAP_LOG_CRIT, "ZCHAN STATE INVALID %s on IN CALL %d:%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; } diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index fafa7a447c..58dfb86a8e 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -585,21 +585,41 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_ENABLE_ECHOCANCEL: { - //code me + 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: { - //code me + 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_LOOP: { - // code me +#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 } case ZAP_COMMAND_DISABLE_LOOP: { - // code me +#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 } case ZAP_COMMAND_SET_INTERVAL: { From 66bc2e43c8ad41c9b24c79b766e52b0cbaacafe2 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 10 Mar 2010 20:06:31 +0000 Subject: [PATCH 1747/1766] merged 1039:1053 openzap/trunk git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1054 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 112 ++++++++++++-- libs/freetdm/src/ftdm_io.c | 51 ++++++- .../src/ftmod/ftmod_analog/ftmod_analog.c | 8 + .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 13 -- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 13 -- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 143 ++++++++++++++---- .../src/ftmod/ftmod_sangoma_boost/sigboost.h | 54 +++++-- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 82 +++++++++- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 16 ++ libs/freetdm/src/include/freetdm.h | 19 ++- 10 files changed, 422 insertions(+), 89 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 8a19d3d725..ea59263b08 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -61,7 +61,7 @@ struct span_config { char dial_regex[256]; char fail_dial_regex[256]; char hold_music[256]; - char type[256]; + char type[256]; analog_option_t analog_options; }; @@ -133,7 +133,6 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session void dump_chan(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); void dump_chan_xml(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); - static switch_core_session_t *ftdm_channel_get_session(ftdm_channel_t *channel, int32_t id) { switch_core_session_t *session = NULL; @@ -1108,7 +1107,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi char *argv[3]; int argc = 0; const char *var; - + const char *dest_num = NULL, *callerid_num = NULL; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -1123,8 +1122,18 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi data = switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number); - outbound_profile->destination_number = switch_sanitize_number(outbound_profile->destination_number); + if (!zstr(outbound_profile->destination_number)) { + dest_num = switch_sanitize_number(switch_core_strdup(outbound_profile->pool, outbound_profile->destination_number)); + } + if (!zstr(outbound_profile->caller_id_number)) { + callerid_num = switch_sanitize_number(switch_core_strdup(outbound_profile->pool, outbound_profile->caller_id_number)); + } + + if (!zstr(callerid_num) && !strcmp(callerid_num, "0000000000")) { + callerid_num = NULL; + } + if ((argc = switch_separate_string(data, '/', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid dial string\n"); return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; @@ -1206,15 +1215,15 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi caller_data.dnis.plan = outbound_profile->destination_number_numplan; - -#if 0 - if (!zstr(outbound_profile->rdnis)) { - ftdm_set_string(caller_data.rdnis.digits, outbound_profile->rdnis); - } -#endif + /* blindly copy data from outbound_profile. They will be overwritten + * by calling ftdm_caller_data if needed after */ + caller_data.cid_num.type = outbound_profile->caller_ton; + caller_data.cid_num.plan = outbound_profile->caller_numplan; + caller_data.rdnis.type = outbound_profile->rdnis_ton; + caller_data.rdnis.plan = outbound_profile->rdnis_numplan; ftdm_set_string(caller_data.cid_name, outbound_profile->caller_id_name); - ftdm_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number); + ftdm_set_string(caller_data.cid_num.digits, switch_str_nil(outbound_profile->caller_id_number)); if (group_id >= 0) { status = ftdm_channel_open_by_group(group_id, direction, &caller_data, &ftdmchan); @@ -1269,8 +1278,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_channel_set_variable(channel, "freetdm_span_name", ftdmchan->span->name); switch_channel_set_variable_printf(channel, "freetdm_span_number", "%d", ftdmchan->span_id); switch_channel_set_variable_printf(channel, "freetdm_chan_number", "%d", ftdmchan->chan_id); - ftdmchan->caller_data = caller_data; + ftdm_channel_set_caller_data(ftdmchan, &caller_data); caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + caller_profile->destination_number = switch_core_strdup(caller_profile->pool, switch_str_nil(dest_num)); + caller_profile->caller_id_number = switch_core_strdup(caller_profile->pool, switch_str_nil(callerid_num)); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; @@ -1400,6 +1411,70 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session return FTDM_SUCCESS; } +static FIO_SIGNAL_CB_FUNCTION(on_common_signal) +{ + switch_event_t *event = NULL; + + switch (sigmsg->event_id) { + + case FTDM_SIGEVENT_ALARM_CLEAR: + case FTDM_SIGEVENT_ALARM_TRAP: + { + if (ftdm_channel_get_alarms(sigmsg->channel) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "failed to retrieve alarms\n"); + return FTDM_FAIL; + } + if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "failed to create alarms events\n"); + return FTDM_FAIL; + } + if (sigmsg->event_id == FTDM_SIGEVENT_ALARM_CLEAR) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "ftdm-alarm-clear"); + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "ftdm-alarm-trap"); + } + } + break; + default: + return FTDM_SUCCESS; + break; + } + + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-name", "%s", sigmsg->channel->span->name); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-number", "%d", sigmsg->channel->span_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "chan-number", "%d", sigmsg->channel->chan_id); + + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_RECOVER)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "recover"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_LOOPBACK)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "loopback"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_YELLOW)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "yellow"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_RED)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "red"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_BLUE)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "blue"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_NOTOPEN)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "notopen"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_AIS)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "ais"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_RAI)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "rai"); + } + if (ftdm_test_alarm_flag(sigmsg->channel, FTDM_ALARM_GENERAL)) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alarm", "general"); + } + switch_event_fire(&event); + + return FTDM_BREAK; +} static FIO_SIGNAL_CB_FUNCTION(on_fxo_signal) { @@ -1682,6 +1757,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_r2_signal) ftdm_log(FTDM_LOG_DEBUG, "Got R2 channel sig [%s] in channel %d\n", ftdm_signal_event2str(sigmsg->event_id), sigmsg->channel->physical_chan_id); + if (on_common_signal(sigmsg) == FTDM_BREAK) { + return FTDM_SUCCESS; + } + switch(sigmsg->event_id) { /* on_call_disconnect from the R2 side */ case FTDM_SIGEVENT_STOP: @@ -1784,6 +1863,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal) ftdm_log(FTDM_LOG_DEBUG, "got clear channel sig [%s]\n", ftdm_signal_event2str(sigmsg->event_id)); + if (on_common_signal(sigmsg) == FTDM_BREAK) { + return FTDM_SUCCESS; + } + switch(sigmsg->event_id) { case FTDM_SIGEVENT_START: { @@ -1870,6 +1953,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_analog_signal) { switch_status_t status = SWITCH_STATUS_FALSE; + if (on_common_signal(sigmsg) == FTDM_BREAK) { + return FTDM_SUCCESS; + } + switch (sigmsg->channel->type) { case FTDM_CHAN_TYPE_FXO: case FTDM_CHAN_TYPE_EM: @@ -2210,6 +2297,7 @@ static switch_status_t load_config(void) uint32_t to = 0; int q921loglevel = -1; int q931loglevel = -1; + // quick debug //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ID: '%s', Name:'%s'\n",id,name); diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 2ea9ad7d77..b7d2a36e20 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -219,6 +219,53 @@ FT_DECLARE_DATA ftdm_memory_handler_t g_ftdm_mem_handler = FT_DECLARE_DATA ftdm_crash_policy_t g_ftdm_crash_policy = FTDM_CRASH_NEVER; +static ftdm_status_t ftdm_set_caller_data(ftdm_span_t *span, ftdm_caller_data_t *caller_data) +{ + if (!caller_data) { + ftdm_log(FTDM_LOG_CRIT, "Error: trying to set caller data, but no caller_data!\n"); + return FTDM_FAIL; + } + + if (caller_data->cid_num.plan == FTDM_NPI_INVALID) { + caller_data->cid_num.plan = span->default_caller_data.cid_num.plan; + } + + if (caller_data->cid_num.type == FTDM_TON_INVALID) { + caller_data->cid_num.type = span->default_caller_data.cid_num.type; + } + + if (caller_data->ani.plan == FTDM_NPI_INVALID) { + caller_data->ani.plan = span->default_caller_data.ani.plan; + } + + if (caller_data->ani.type == FTDM_TON_INVALID) { + caller_data->ani.type = span->default_caller_data.ani.type; + } + + if (caller_data->rdnis.plan == FTDM_NPI_INVALID) { + caller_data->rdnis.plan = span->default_caller_data.rdnis.plan; + } + + if (caller_data->rdnis.type == FTDM_NPI_INVALID) { + caller_data->rdnis.type = span->default_caller_data.rdnis.type; + } + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_set_caller_data(ftdm_channel_t *ftdmchan, ftdm_caller_data_t *caller_data) +{ + ftdm_status_t err = FTDM_SUCCESS; + if (!ftdmchan) { + ftdm_log(FTDM_LOG_CRIT, "Error: trying to set caller data, but no ftdmchan!\n"); + return FTDM_FAIL; + } + if ((err = ftdm_set_caller_data(ftdmchan->span, caller_data)) != FTDM_SUCCESS) { + return err; + } + ftdmchan->caller_data = *caller_data; + return FTDM_SUCCESS; +} + FT_DECLARE_DATA ftdm_logger_t ftdm_log = null_logger; FT_DECLARE(void) ftdm_global_set_crash_policy(ftdm_crash_policy_t policy) @@ -1238,8 +1285,9 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc *ftdmchan = NULL; return FTDM_FAIL; } - + if (span->channel_request && !span->suggest_chan_id) { + ftdm_set_caller_data(span, caller_data); return span->channel_request(span, 0, direction, caller_data, ftdmchan); } @@ -1284,6 +1332,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc ) { if (span && span->channel_request) { + ftdm_set_caller_data(span, caller_data); status = span->channel_request(span, i, direction, caller_data, ftdmchan); break; } diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index c71b19d202..26c26e3a02 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -872,6 +872,14 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); } } + case FTDM_OOB_ALARM_TRAP: + { + ftdm_set_flag_locked(event->channel, FTDM_CHANNEL_SUSPENDED); + } + case FTDM_OOB_ALARM_CLEAR: + { + ftdm_clear_flag_locked(event->channel, FTDM_CHANNEL_SUSPENDED); + } } end: diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index 547c6feaa0..3445599d13 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -1512,21 +1512,12 @@ static __inline__ void check_state(ftdm_span_t *span) */ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) { - ftdm_sigmsg_t sig; - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d:%d] STATE [%s]\n", ftdm_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state)); switch(event->enum_id) { case FTDM_OOB_ALARM_TRAP: { - sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)FTDM_HW_LINK_DISCONNECTED; if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) { if (event->channel->type == FTDM_CHAN_TYPE_B) { ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_RESTART); @@ -1538,7 +1529,6 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_channel_get_alarms(event->channel); - ftdm_span_send_signal(span, &sig); ftdm_log(FTDM_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, @@ -1551,11 +1541,8 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_log(FTDM_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); - sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; ftdm_clear_flag(event->channel, FTDM_CHANNEL_SUSPENDED); ftdm_channel_get_alarms(event->channel); - ftdm_span_send_signal(span, &sig); } break; } diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index a3885ff856..929a874657 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -806,21 +806,12 @@ static int on_ring(lpwrap_pri_t *spri, lpwrap_pri_event_t event_type, pri_event */ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *event) { - ftdm_sigmsg_t sig; - - memset(&sig, 0, sizeof(sig)); - sig.chan_id = event->channel->chan_id; - sig.span_id = event->channel->span_id; - sig.channel = event->channel; - ftdm_log(FTDM_LOG_DEBUG, "EVENT [%s][%d][%d:%d] STATE [%s]\n", ftdm_oob_event2str(event->enum_id), event->enum_id, event->channel->span_id, event->channel->chan_id, ftdm_channel_state2str(event->channel->state)); switch(event->enum_id) { case FTDM_OOB_ALARM_TRAP: { - sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; if (event->channel->state != FTDM_CHANNEL_STATE_DOWN) { if (event->channel->type == FTDM_CHAN_TYPE_B) { ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_RESTART); @@ -832,7 +823,6 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_channel_get_alarms(event->channel); - ftdm_span_send_signal(span, &sig); ftdm_log(FTDM_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, @@ -845,11 +835,8 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_log(FTDM_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); - sig.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; - sig.raw_data = (void *)FTDM_HW_LINK_CONNECTED; ftdm_clear_flag(event->channel, FTDM_CHANNEL_SUSPENDED); ftdm_channel_get_alarms(event->channel); - ftdm_span_send_signal(span, &sig); } break; } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 48b8efebaf..d60732a589 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -351,13 +351,21 @@ static FIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) } ftdm_set_string(event.calling_name, caller_data->cid_name); - ftdm_set_string(event.isup_in_rdnis, caller_data->rdnis.digits); + ftdm_set_string(event.rdnis.digits, caller_data->rdnis.digits); if (strlen(caller_data->rdnis.digits)) { - event.isup_in_rdnis_size = (uint16_t)strlen(caller_data->rdnis.digits)+1; + 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_number_screening_ind = caller_data->screen; - event.calling_number_presentation = caller_data->pres; + 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->dnis.type; + event.called.npi = caller_data->dnis.plan; OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = span; @@ -459,14 +467,23 @@ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(sangoma_boost_outgoing_call) event.span = (uint8_t)ftdmchan->physical_span_id; event.chan = (uint8_t)ftdmchan->physical_chan_id; + ftdm_set_string(event.calling_name, ftdmchan->caller_data.cid_name); - ftdm_set_string(event.isup_in_rdnis, ftdmchan->caller_data.rdnis.digits); + ftdm_set_string(event.rdnis.digits, ftdmchan->caller_data.rdnis.digits); if (strlen(ftdmchan->caller_data.rdnis.digits)) { - event.isup_in_rdnis_size = (uint16_t)strlen(ftdmchan->caller_data.rdnis.digits)+1; + event.rdnis.digits_count = strlen(ftdmchan->caller_data.rdnis.digits)+1; + event.rdnis.ton = ftdmchan->caller_data.rdnis.type; + event.rdnis.npi = ftdmchan->caller_data.rdnis.plan; } - event.calling_number_screening_ind = ftdmchan->caller_data.screen; - event.calling_number_presentation = ftdmchan->caller_data.pres; + event.calling.screening_ind = ftdmchan->caller_data.screen; + event.calling.presentation_ind = ftdmchan->caller_data.pres; + + event.calling.ton = ftdmchan->caller_data.cid_num.type; + event.calling.npi = ftdmchan->caller_data.cid_num.plan; + + event.called.ton = ftdmchan->caller_data.dnis.type; + event.called.npi = ftdmchan->caller_data.dnis.plan; OUTBOUND_REQUESTS[r].status = BST_WAITING; OUTBOUND_REQUESTS[r].span = ftdmchan->span; @@ -866,6 +883,21 @@ static void handle_call_start(ftdm_span_t *span, sangomabc_connection_t *mcon, s ftdm_channel_t *ftdmchan; if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 0))) { + if ((ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { + int r; + if (ftdmchan->state == FTDM_CHANNEL_STATE_UP) { + ftdm_log(FTDM_LOG_CRIT, "ZCHAN STATE UP -> Changed to TERMINATING %d:%d\n", event->span+1,event->chan+1); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING, 0, r); + } else if (ftdm_test_sflag(ftdmchan, SFLAG_HANGUP)) { + ftdm_log(FTDM_LOG_CRIT, "ZCHAN STATE HANGUP -> Changed to HANGUP COMPLETE %d:%d\n", event->span+1,event->chan+1); + ftdm_set_state_r(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE, 0, r); + } else { + ftdm_log(FTDM_LOG_CRIT, "ZCHAN STATE INVALID %s on IN CALL %d:%d\n", ftdm_channel_state2str(ftdmchan->state),event->span+1,event->chan+1); + + } + ftdm_set_sflag(ftdmchan, SFLAG_SENT_FINAL_MSG); + ftdmchan=NULL; + } ftdm_log(FTDM_LOG_CRIT, "START CANT FIND CHAN %d:%d\n", event->span+1,event->chan+1); goto error; } @@ -881,35 +913,42 @@ static void handle_call_start(ftdm_span_t *span, sangomabc_connection_t *mcon, s ftdmchan->physical_span_id, ftdmchan->physical_chan_id); ftdmchan->sflags = 0; - ftdm_set_string(ftdmchan->caller_data.cid_num.digits, (char *)event->calling_number_digits); - ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)event->calling_number_digits); + ftdm_set_string(ftdmchan->caller_data.cid_num.digits, (char *)event->calling.digits); + ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)event->calling.digits); + ftdm_set_string(ftdmchan->caller_data.ani.digits, (char *)event->calling.digits); + ftdm_set_string(ftdmchan->caller_data.dnis.digits, (char *)event->called.digits); + ftdm_set_string(ftdmchan->caller_data.rdnis.digits, (char *)event->rdnis.digits); + if (strlen(event->calling_name)) { ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)event->calling_name); } - ftdm_set_string(ftdmchan->caller_data.ani.digits, (char *)event->calling_number_digits); - ftdm_set_string(ftdmchan->caller_data.dnis.digits, (char *)event->called_number_digits); - if (event->isup_in_rdnis_size) { - char* p; - //Set value of rdnis.digis in case prot daemon is still using older style RDNIS - if (atoi((char *)event->isup_in_rdnis) > 0) { - ftdm_set_string(ftdmchan->caller_data.rdnis.digits, (char *)event->isup_in_rdnis); - } + ftdmchan->caller_data.cid_num.plan = event->calling.npi; + ftdmchan->caller_data.cid_num.type = event->calling.ton; - p = strstr((char*)event->isup_in_rdnis,"PRI001-ANI2-"); + ftdmchan->caller_data.ani.plan = event->calling.npi; + ftdmchan->caller_data.ani.type = event->calling.ton; + + ftdmchan->caller_data.dnis.plan = event->called.npi; + ftdmchan->caller_data.dnis.type = event->called.ton; + + ftdmchan->caller_data.rdnis.plan = event->rdnis.npi; + ftdmchan->caller_data.rdnis.type = event->rdnis.ton; + + ftdmchan->caller_data.screen = event->calling.screening_ind; + ftdmchan->caller_data.pres = event->calling.presentation_ind; + + if (event->custom_data_size) { + char* p = NULL; + + p = strstr((char*)event->custom_data,"PRI001-ANI2-"); if (p!=NULL) { int ani2 = 0; sscanf(p, "PRI001-ANI2-%d", &ani2); snprintf(ftdmchan->caller_data.aniII, 5, "%.2d", ani2); } - p = strstr((char*)event->isup_in_rdnis,"RDNIS-"); - if (p!=NULL) { - sscanf(p, "RDNIS-%s", &ftdmchan->caller_data.rdnis.digits[0]); - } - } - ftdmchan->caller_data.screen = event->calling_number_screening_ind; - ftdmchan->caller_data.pres = event->calling_number_presentation; + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RING); return; @@ -2050,6 +2089,46 @@ static FIO_SPAN_GET_SIG_STATUS_FUNCTION(sangoma_boost_get_span_sig_status) return sangoma_boost_data->sigmod->get_span_sig_status(span, status); } +/* TODO: move these ones to a common private header so other ISDN mods can use them */ +static void ftdm_span_set_npi(const char *npi_string, uint8_t *target) +{ + if (!strcasecmp(npi_string, "isdn") || !strcasecmp(npi_string, "e164")) { + *target = FTDM_NPI_ISDN; + } else if (!strcasecmp(npi_string, "data")) { + *target = FTDM_NPI_DATA; + } else if (!strcasecmp(npi_string, "telex")) { + *target = FTDM_NPI_TELEX; + } else if (!strcasecmp(npi_string, "national")) { + *target = FTDM_NPI_NATIONAL; + } else if (!strcasecmp(npi_string, "private")) { + *target = FTDM_NPI_PRIVATE; + } else if (!strcasecmp(npi_string, "reserved")) { + *target = FTDM_NPI_RESERVED; + } else if (!strcasecmp(npi_string, "unknown")) { + *target = FTDM_NPI_UNKNOWN; + } else { + ftdm_log(FTDM_LOG_WARNING, "Invalid NPI value (%s)\n", npi_string); + *target = FTDM_NPI_UNKNOWN; + } +} + +static void ftdm_span_set_ton(const char *ton_string, uint8_t *target) +{ + if (!strcasecmp(ton_string, "national")) { + *target = FTDM_TON_NATIONAL; + } else if (!strcasecmp(ton_string, "international")) { + *target = FTDM_TON_INTERNATIONAL; + } else if (!strcasecmp(ton_string, "local")) { + *target = FTDM_TON_SUBSCRIBER_NUMBER; + } else if (!strcasecmp(ton_string, "unknown")) { + *target = FTDM_TON_UNKNOWN; + } else { + ftdm_log(FTDM_LOG_WARNING, "Invalid TON value (%s)\n", ton_string); + *target = FTDM_TON_UNKNOWN; + } +} + + /** * \brief Initialises an sangoma boost span from configuration variables * \param span Span to configure @@ -2096,6 +2175,18 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) local_port = atoi(val); } else if (!strcasecmp(var, "remote_port")) { remote_port = atoi(val); + } else if (!strcasecmp(var, "outbound-called-ton")) { + ftdm_span_set_ton(val, &span->default_caller_data.dnis.type); + } else if (!strcasecmp(var, "outbound-called-npi")) { + ftdm_span_set_npi(val, &span->default_caller_data.dnis.plan); + } else if (!strcasecmp(var, "outbound-calling-ton")) { + ftdm_span_set_ton(val, &span->default_caller_data.cid_num.type); + } else if (!strcasecmp(var, "outbound-calling-npi")) { + ftdm_span_set_npi(val, &span->default_caller_data.cid_num.plan); + } else if (!strcasecmp(var, "outbound-rdnis-ton")) { + ftdm_span_set_ton(val, &span->default_caller_data.rdnis.type); + } else if (!strcasecmp(var, "outbound-rdnis-npi")) { + ftdm_span_set_npi(val, &span->default_caller_data.rdnis.plan); } else if (!sigmod) { snprintf(span->last_error, sizeof(span->last_error), "Unknown parameter [%s]", var); FAIL_CONFIG_RETURN(FTDM_FAIL); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h index 9c3be35260..05ca52a487 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sigboost.h @@ -14,7 +14,7 @@ #ifndef _SIGBOOST_H_ #define _SIGBOOST_H_ -#define SIGBOOST_VERSION 102 +#define SIGBOOST_VERSION 103 // handy to define integer types that actually work on both Lin and Win #include @@ -104,7 +104,12 @@ enum e_sigboost_progress_flags #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 */ -#define SIZE_RDNIS 900 + +/* Should only be used by server */ +#define MAX_CALL_SETUP_ID 0xFFFF + +#define SIZE_CUSTOM 900 +#define SIZE_RDNIS SIZE_CUSTOM #pragma pack(1) @@ -113,7 +118,17 @@ typedef struct { uint8_t capability; uint8_t uil1p; -}t_sigboost_bearer; +} 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 { @@ -128,21 +143,30 @@ typedef struct uint8_t chan; uint32_t flags; /* struct timeval tv; */ - 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 */ + t_sigboost_digits called; + t_sigboost_digits calling; + t_sigboost_digits rdnis; /* ref. Q.931 Table 4-11 and Q.951 Section 3 */ - uint8_t calling_number_screening_ind; - uint8_t calling_number_presentation; char calling_name[MAX_DIALED_DIGITS + 1]; t_sigboost_bearer bearer; uint8_t hunt_group; - uint16_t isup_in_rdnis_size; - char isup_in_rdnis [SIZE_RDNIS]; /* it's a null terminated string */ + uint16_t custom_data_size; + char custom_data[SIZE_CUSTOM]; /* it's a null terminated string */ + } t_sigboost_callstart; -#define MIN_SIZE_CALLSTART_MSG sizeof(t_sigboost_callstart) - SIZE_RDNIS +#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 { @@ -167,10 +191,10 @@ 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; + case SIGBOOST_EVENT_CALL_PROGRESS: + return 1; default: - break; + break; } return 0; diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index c7723e94a9..4ad3ea79a0 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -601,21 +601,41 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) break; case FTDM_COMMAND_ENABLE_ECHOCANCEL: { - //code me + err=sangoma_tdm_enable_hwec(ftdmchan->sockfd, &tdm_api); + if (err) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "HWEC Enable Failed"); + return FTDM_FAIL; + } } break; case FTDM_COMMAND_DISABLE_ECHOCANCEL: { - //code me + err=sangoma_tdm_disable_hwec(ftdmchan->sockfd, &tdm_api); + if (err) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "HWEC Disable Failed"); + return FTDM_FAIL; + } } break; case FTDM_COMMAND_ENABLE_LOOP: { - // code me +#ifdef WP_API_FEATURE_LOOP + err=sangoma_tdm_enable_loop(ftdmchan->sockfd, &tdm_api); + if (err) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Loop Enable Failed"); + return FTDM_FAIL; + } +#endif } case FTDM_COMMAND_DISABLE_LOOP: { - // code me +#ifdef WP_API_FEATURE_LOOP + err=sangoma_tdm_disable_loop(ftdmchan->sockfd, &tdm_api); + if (err) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "Loop Disable Failed"); + return FTDM_FAIL; + } +#endif } case FTDM_COMMAND_SET_INTERVAL: { @@ -719,6 +739,9 @@ static FIO_WRITE_FUNCTION(wanpipe_write) /* 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 FTDM_SUCCESS; + } bsent = sangoma_writemsg_tdm(ftdmchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (unsigned short)(*datalen),0); /* should we be checking if bsent == *datalen here? */ @@ -921,11 +944,38 @@ static FIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms) } alarms = tdm_api.wp_tdm_cmd.fe_alarms; #endif + ftdmchan->alarm_flags = FTDM_ALARM_NONE; - - ftdmchan->alarm_flags = alarms ? FTDM_ALARM_RED : FTDM_ALARM_NONE; + if (alarms & WAN_TE_BIT_ALARM_RED) { + ftdmchan->alarm_flags |= FTDM_ALARM_RED; + alarms &= ~WAN_TE_BIT_ALARM_RED; + } - return FTDM_SUCCESS; + if (alarms & WAN_TE_BIT_ALARM_AIS) { + ftdmchan->alarm_flags |= FTDM_ALARM_AIS; + ftdmchan->alarm_flags |= FTDM_ALARM_BLUE; + alarms &= ~WAN_TE_BIT_ALARM_AIS; + } + + if (alarms & WAN_TE_BIT_ALARM_RAI) { + ftdmchan->alarm_flags |= FTDM_ALARM_RAI; + ftdmchan->alarm_flags |= FTDM_ALARM_YELLOW; + alarms &= ~WAN_TE_BIT_ALARM_RAI; + } + + /* still missing to map: + * FTDM_ALARM_RECOVER + * FTDM_ALARM_LOOPBACK + * FTDM_ALARM_NOTOPEN + * */ + + /* if we still have alarms that we did not map, set the general alarm */ + if (alarms) { + ftdm_log(FTDM_LOG_DEBUG, "Unmapped wanpipe alarms: %d\n", alarms); + ftdmchan->alarm_flags |= FTDM_ALARM_GENERAL; + } + + return FTDM_SUCCESS; } /** @@ -986,6 +1036,8 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) case WP_TDMAPI_EVENT_LINK_STATUS: { + ftdm_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 = FTDM_OOB_ALARM_CLEAR; @@ -994,6 +1046,11 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = FTDM_OOB_ALARM_TRAP; break; }; + sigmsg.chan_id = ftdmchan->chan_id; + sigmsg.span_id = ftdmchan->span_id; + sigmsg.channel = ftdmchan; + sigmsg.event_id = (event_id == FTDM_OOB_ALARM_CLEAR) ? FTDM_SIGEVENT_ALARM_CLEAR : FTDM_SIGEVENT_ALARM_TRAP; + ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; @@ -1071,7 +1128,16 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) break; case WP_TDMAPI_EVENT_ALARM: { - event_id = FTDM_OOB_NOOP; + ftdm_log(FTDM_LOG_DEBUG, "Got wanpipe alarms %d\n", tdm_api.wp_tdm_cmd.event.wp_api_event_alarm); + ftdm_sigmsg_t sigmsg; + memset(&sigmsg, 0, sizeof(sigmsg)); + /* FIXME: is this always alarm trap? what about clearing? */ + event_id = FTDM_OOB_ALARM_TRAP; + sigmsg.chan_id = ftdmchan->chan_id; + sigmsg.span_id = ftdmchan->span_id; + sigmsg.channel = ftdmchan; + sigmsg.event_id = (event_id == FTDM_OOB_ALARM_CLEAR) ? FTDM_SIGEVENT_ALARM_CLEAR : FTDM_SIGEVENT_ALARM_TRAP; + ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; default: diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 0ab9553307..c8fc9bd003 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -1027,12 +1027,28 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_ALARM: { + ftdm_sigmsg_t sigmsg; + ftdm_channel_t *ftdmchan = span->channels[i]; event_id = FTDM_OOB_ALARM_TRAP; + memset(&sigmsg, 0, sizeof(sigmsg)); + sigmsg.chan_id = ftdmchan->chan_id; + sigmsg.span_id = ftdmchan->span_id; + sigmsg.channel = ftdmchan; + sigmsg.event_id = FTDM_SIGEVENT_ALARM_TRAP; + ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; case ZT_EVENT_NOALARM: { + ftdm_sigmsg_t sigmsg; + ftdm_channel_t *ftdmchan = span->channels[i]; event_id = FTDM_OOB_ALARM_CLEAR; + memset(&sigmsg, 0, sizeof(sigmsg)); + sigmsg.chan_id = ftdmchan->chan_id; + sigmsg.span_id = ftdmchan->span_id; + sigmsg.channel = ftdmchan; + sigmsg.event_id = FTDM_SIGEVENT_ALARM_CLEAR; + ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; case ZT_EVENT_BITSCHANGED: diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 2113f1d347..aa1da3af56 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -450,9 +450,24 @@ typedef enum { FTDM_TON_NETWORK_SPECIFIC, FTDM_TON_SUBSCRIBER_NUMBER, FTDM_TON_ABBREVIATED_NUMBER, - FTDM_TON_RESERVED + FTDM_TON_RESERVED, + FTDM_TON_INVALID = 255 } ftdm_ton_t; +/** + * Numbering Plan Identification (NPI) + */ +typedef enum { + FTDM_NPI_UNKNOWN = 0, + FTDM_NPI_ISDN = 1, + FTDM_NPI_DATA = 3, + FTDM_NPI_TELEX = 4, + FTDM_NPI_NATIONAL = 8, + FTDM_NPI_PRIVATE = 9, + FTDM_NPI_RESERVED = 10, + FTDM_NPI_INVALID = 255 +} ftdm_npi_t; + typedef struct { char digits[25]; uint8_t type; @@ -605,6 +620,7 @@ struct ftdm_span { size_t dtmf_hangup_len; int suggest_chan_id; ftdm_state_map_t *state_map; + ftdm_caller_data_t default_caller_data; struct ftdm_span *next; }; @@ -801,6 +817,7 @@ FT_DECLARE(int) ftdm_load_module_assume(const char *name); FT_DECLARE(ftdm_status_t) ftdm_span_find_by_name(const char *name, ftdm_span_t **span); FT_DECLARE(char *) ftdm_api_execute(const char *type, const char *cmd); FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap); +FT_DECLARE(ftdm_status_t) ftdm_channel_set_caller_data(ftdm_channel_t *ftdmchan, ftdm_caller_data_t *caller_data); FIO_CODEC_FUNCTION(fio_slin2ulaw); FIO_CODEC_FUNCTION(fio_ulaw2slin); From 617020ea0c1f72f7633100f9c9633539ec34e87c Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 10 Mar 2010 21:47:28 +0000 Subject: [PATCH 1748/1766] process alarms in the core git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1055 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/README | 2 +- libs/freetdm/TODO | 7 +++ libs/freetdm/mod_freetdm/mod_freetdm.c | 2 + libs/freetdm/src/ftdm_io.c | 58 +++++++++++++++---- .../src/ftmod/ftmod_analog/ftmod_analog.c | 8 --- .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 12 ---- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 19 +----- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 16 ----- libs/freetdm/src/include/ftdm_types.h | 5 +- 9 files changed, 63 insertions(+), 66 deletions(-) create mode 100644 libs/freetdm/TODO diff --git a/libs/freetdm/README b/libs/freetdm/README index 4ef720b10a..2c2119f55b 100644 --- a/libs/freetdm/README +++ b/libs/freetdm/README @@ -1,3 +1,3 @@ -OPENZAP (WORK IN PROGRESS) +FREETDM (WORK IN PROGRESS) *shrug* diff --git a/libs/freetdm/TODO b/libs/freetdm/TODO new file mode 100644 index 0000000000..fb297b2eef --- /dev/null +++ b/libs/freetdm/TODO @@ -0,0 +1,7 @@ +== Interface inconsistency == +- enum_id member of ftdm_event_t is inconsistent. Most of the time is just for OOB events, the only other + type of event as of now is FTDM_EVENT_DTMF and is not using the enum_id member. I think we can get rid + of the FTDM_EVENT_DTMF and create ftdm_dtmf_event_t type instead of reusing ftdm_event_t + then ftdm_event_t would be renamed to ftdm_oob_event_t and the enum_id renamed to type, then ftdm_span_next_event() + will only return OOB events + diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index ea59263b08..800f5e23f6 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -1429,8 +1429,10 @@ static FIO_SIGNAL_CB_FUNCTION(on_common_signal) return FTDM_FAIL; } if (sigmsg->event_id == FTDM_SIGEVENT_ALARM_CLEAR) { + ftdm_log(FTDM_LOG_NOTICE, "Alarm cleared on channel %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "ftdm-alarm-clear"); } else { + ftdm_log(FTDM_LOG_NOTICE, "Alarm raised on channel %d:%d [%s]\n", sigmsg->channel->span_id, sigmsg->channel->chan_id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "ftdm-alarm-trap"); } } diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index b7d2a36e20..3e6cdef0e9 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -823,15 +823,46 @@ FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms) FT_DECLARE(ftdm_status_t) ftdm_span_next_event(ftdm_span_t *span, ftdm_event_t **event) { - assert(span->fio != NULL); + ftdm_status_t status = FTDM_FAIL; + ftdm_sigmsg_t sigmsg; + ftdm_assert_return(span->fio != NULL, FTDM_FAIL, "No I/O module attached to this span!\n"); - if (span->fio->next_event) { - return span->fio->next_event(span, event); - } else { + if (!span->fio->next_event) { ftdm_log(FTDM_LOG_ERROR, "next_event method not implemented in module %s!", span->fio->name); + return FTDM_NOTIMPL; } - - return FTDM_NOTIMPL; + + status = span->fio->next_event(span, event); + if (status != FTDM_SUCCESS) { + return status; + } + + /* before returning the event to the user we do some core operations with certain OOB events */ + memset(&sigmsg, 0, sizeof(sigmsg)); + sigmsg.span_id = span->span_id; + sigmsg.chan_id = (*event)->channel->chan_id; + sigmsg.channel = (*event)->channel; + switch ((*event)->enum_id) { + case FTDM_OOB_ALARM_CLEAR: + { + sigmsg.event_id = FTDM_SIGEVENT_ALARM_CLEAR; + ftdm_clear_flag_locked((*event)->channel, FTDM_CHANNEL_IN_ALARM); + ftdm_span_send_signal(span, &sigmsg); + } + break; + case FTDM_OOB_ALARM_TRAP: + { + sigmsg.event_id = FTDM_SIGEVENT_ALARM_TRAP; + ftdm_set_flag_locked((*event)->channel, FTDM_CHANNEL_IN_ALARM); + ftdm_span_send_signal(span, &sigmsg); + } + break; + default: + /* NOOP */ + break; + } + + return status; } static ftdm_status_t ftdmchan_fsk_write_sample(int16_t *buf, ftdm_size_t buflen, void *user_data) @@ -1209,6 +1240,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && + !ftdm_test_flag(check, FTDM_CHANNEL_IN_ALARM) && check->state == FTDM_CHANNEL_STATE_DOWN && FTDM_IS_VOICE_CHANNEL(check) ) { @@ -1327,6 +1359,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && !ftdm_test_flag(check, FTDM_CHANNEL_INUSE) && !ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) && + !ftdm_test_flag(check, FTDM_CHANNEL_IN_ALARM) && check->state == FTDM_CHANNEL_STATE_DOWN && FTDM_IS_VOICE_CHANNEL(check) ) { @@ -1417,7 +1450,12 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan) assert(ftdmchan != NULL); if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SUSPENDED)) { - snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is suspended"); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is suspended\n"); + return FTDM_FAIL; + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_IN_ALARM)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is alarmed\n"); return FTDM_FAIL; } @@ -1468,7 +1506,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, goto done; } - if (ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || + if (ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || ftdm_test_flag(check, FTDM_CHANNEL_IN_ALARM) || !ftdm_test_flag(check, FTDM_CHANNEL_READY) || (status = ftdm_mutex_trylock(check->mutex)) != FTDM_SUCCESS) { *ftdmchan = NULL; goto done; @@ -2371,8 +2409,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data ftdm_size_t max = *datalen; unsigned i = 0; - assert(ftdmchan != NULL); - assert(ftdmchan->fio != NULL); + ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "ftdmchan is null\n"); + ftdm_assert_return(ftdmchan->fio != NULL, FTDM_FAIL, "No I/O module attached to ftdmchan\n"); if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index 26c26e3a02..c71b19d202 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -872,14 +872,6 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e ftdm_set_state_locked(event->channel, FTDM_CHANNEL_STATE_DOWN); } } - case FTDM_OOB_ALARM_TRAP: - { - ftdm_set_flag_locked(event->channel, FTDM_CHANNEL_SUSPENDED); - } - case FTDM_OOB_ALARM_CLEAR: - { - ftdm_clear_flag_locked(event->channel, FTDM_CHANNEL_SUSPENDED); - } } end: diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index d60732a589..339a5a4203 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -1501,11 +1501,8 @@ static __inline__ void check_state(ftdm_span_t *span) static __inline__ ftdm_status_t check_events(ftdm_span_t *span, int ms_timeout) { ftdm_status_t status; - ftdm_sigmsg_t sigmsg; ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; - memset(&sigmsg, 0, sizeof(sigmsg)); - status = ftdm_span_poll_event(span, ms_timeout); switch(status) { @@ -1513,25 +1510,16 @@ static __inline__ ftdm_status_t check_events(ftdm_span_t *span, int ms_timeout) { ftdm_event_t *event; while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { - sigmsg.span_id = event->channel->span_id; - sigmsg.chan_id = event->channel->chan_id; - sigmsg.channel = event->channel; switch (event->enum_id) { case FTDM_OOB_ALARM_TRAP: - sigmsg.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; - sigmsg.raw_data = (void *)FTDM_HW_LINK_DISCONNECTED; if (sangoma_boost_data->sigmod) { sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, FTDM_HW_LINK_DISCONNECTED); } - ftdm_span_send_signal(span, &sigmsg); break; case FTDM_OOB_ALARM_CLEAR: - sigmsg.event_id = FTDM_SIGEVENT_HWSTATUS_CHANGED; - sigmsg.raw_data = (void *)FTDM_HW_LINK_CONNECTED; if (sangoma_boost_data->sigmod) { sangoma_boost_data->sigmod->on_hw_link_status_change(event->channel, FTDM_HW_LINK_CONNECTED); } - ftdm_span_send_signal(span, &sigmsg); break; } } diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 4ad3ea79a0..46be23f60b 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -1032,12 +1032,11 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) return FTDM_FAIL; } + ftdm_log(FTDM_LOG_DEBUG, "read wanpipe event %d\n", 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: { - ftdm_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 = FTDM_OOB_ALARM_CLEAR; @@ -1046,11 +1045,6 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) event_id = FTDM_OOB_ALARM_TRAP; break; }; - sigmsg.chan_id = ftdmchan->chan_id; - sigmsg.span_id = ftdmchan->span_id; - sigmsg.channel = ftdmchan; - sigmsg.event_id = (event_id == FTDM_OOB_ALARM_CLEAR) ? FTDM_SIGEVENT_ALARM_CLEAR : FTDM_SIGEVENT_ALARM_TRAP; - ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; @@ -1121,6 +1115,7 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) if (tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) { ftdm_clear_flag_locked(ftdmchan, FTDM_CHANNEL_MUTE); if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) { + ftdm_log(FTDM_LOG_DEBUG, "Queuing wanpipe DTMF: %c\n", tmp_dtmf[0]); ftdm_channel_queue_dtmf(ftdmchan, tmp_dtmf); } } @@ -1129,20 +1124,12 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) case WP_TDMAPI_EVENT_ALARM: { ftdm_log(FTDM_LOG_DEBUG, "Got wanpipe alarms %d\n", tdm_api.wp_tdm_cmd.event.wp_api_event_alarm); - ftdm_sigmsg_t sigmsg; - memset(&sigmsg, 0, sizeof(sigmsg)); - /* FIXME: is this always alarm trap? what about clearing? */ event_id = FTDM_OOB_ALARM_TRAP; - sigmsg.chan_id = ftdmchan->chan_id; - sigmsg.span_id = ftdmchan->span_id; - sigmsg.channel = ftdmchan; - sigmsg.event_id = (event_id == FTDM_OOB_ALARM_CLEAR) ? FTDM_SIGEVENT_ALARM_CLEAR : FTDM_SIGEVENT_ALARM_TRAP; - ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; default: { - ftdm_log(FTDM_LOG_WARNING, "Unhandled event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); + ftdm_log(FTDM_LOG_WARNING, "Unhandled wanpipe event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type); event_id = FTDM_OOB_INVALID; } break; diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index c8fc9bd003..0ab9553307 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -1027,28 +1027,12 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event) break; case ZT_EVENT_ALARM: { - ftdm_sigmsg_t sigmsg; - ftdm_channel_t *ftdmchan = span->channels[i]; event_id = FTDM_OOB_ALARM_TRAP; - memset(&sigmsg, 0, sizeof(sigmsg)); - sigmsg.chan_id = ftdmchan->chan_id; - sigmsg.span_id = ftdmchan->span_id; - sigmsg.channel = ftdmchan; - sigmsg.event_id = FTDM_SIGEVENT_ALARM_TRAP; - ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; case ZT_EVENT_NOALARM: { - ftdm_sigmsg_t sigmsg; - ftdm_channel_t *ftdmchan = span->channels[i]; event_id = FTDM_OOB_ALARM_CLEAR; - memset(&sigmsg, 0, sizeof(sigmsg)); - sigmsg.chan_id = ftdmchan->chan_id; - sigmsg.span_id = ftdmchan->span_id; - sigmsg.channel = ftdmchan; - sigmsg.event_id = FTDM_SIGEVENT_ALARM_CLEAR; - ftdm_span_send_signal(ftdmchan->span, &sigmsg); } break; case ZT_EVENT_BITSCHANGED: diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h index 776ec07367..3d45185073 100644 --- a/libs/freetdm/src/include/ftdm_types.h +++ b/libs/freetdm/src/include/ftdm_types.h @@ -220,10 +220,8 @@ typedef enum { FTDM_SIGEVENT_COLLECTED_DIGIT, FTDM_SIGEVENT_ADD_CALL, FTDM_SIGEVENT_RESTART, - /* Signaling link status changed (D-chan up, down, R2 blocked etc) */ + /* Signaling status changed (D-chan up, down, R2 blocked etc) */ FTDM_SIGEVENT_SIGSTATUS_CHANGED, - /* Hardware link status changed (Line connected, disconnected) */ - FTDM_SIGEVENT_HWSTATUS_CHANGED, FTDM_SIGEVENT_INVALID } ftdm_signal_event_t; #define SIGNAL_STRINGS "START", "STOP", "TRANSFER", "ANSWER", "UP", "FLASH", "PROGRESS", \ @@ -412,6 +410,7 @@ typedef enum { FTDM_CHANNEL_MUTE = (1 << 24), FTDM_CHANNEL_USE_RX_GAIN = (1 << 25), FTDM_CHANNEL_USE_TX_GAIN = (1 << 26), + FTDM_CHANNEL_IN_ALARM = (1 << 27), } ftdm_channel_flag_t; #if defined(__cplusplus) && defined(WIN32) // fix C2676 From 6c8caec2e4d8f6b4c613bf2f5c7009f2b988636a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 11 Mar 2010 16:58:36 +0000 Subject: [PATCH 1749/1766] temporarily remove some libsangoma APIs from ozmod_wanpipe until the Windows driver release is fixed git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1056 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 58dfb86a8e..87aa0d0079 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -43,6 +43,8 @@ #include "libsangoma.h" #if defined(__WINDOWS__) +/* remove this when http://jira.freeswitch.org/browse/FSBUILD-259 wanpipe issue is fixed */ +#define WINDOWS_BUILD_BROKEN 1 /*! 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 @@ -585,24 +587,29 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) break; case ZAP_COMMAND_ENABLE_ECHOCANCEL: { +#ifndef WINDOWS_BUILD_BROKEN 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; } +#endif /* WINDOWS_BUILD_BROKEN */ } break; case ZAP_COMMAND_DISABLE_ECHOCANCEL: { +#ifndef WINDOWS_BUILD_BROKEN 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; } +#endif /* WINDOWS_BUILD_BROKEN */ } break; case ZAP_COMMAND_ENABLE_LOOP: { +#ifndef WINDOWS_BUILD_BROKEN #ifdef WP_API_FEATURE_LOOP err=sangoma_tdm_enable_loop(zchan->sockfd, &tdm_api); if (err) { @@ -610,9 +617,11 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) return ZAP_FAIL; } #endif +#endif /* WINDOWS_BUILD_BROKEN */ } case ZAP_COMMAND_DISABLE_LOOP: { +#ifndef WINDOWS_BUILD_BROKEN #ifdef WP_API_FEATURE_LOOP err=sangoma_tdm_disable_loop(zchan->sockfd, &tdm_api); if (err) { @@ -620,6 +629,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) return ZAP_FAIL; } #endif +#endif /* WINDOWS_BUILD_BROKEN */ } case ZAP_COMMAND_SET_INTERVAL: { @@ -1102,15 +1112,17 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event) } break; case WP_TDMAPI_EVENT_ALARM: - zap_log(ZAP_LOG_DEBUG, "Got wanpipe alarms %d\n", tdm_api.wp_tdm_cmd.event.wp_api_event_alarm); - zap_sigmsg_t sigmsg; - 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); + { + 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: { From 5305611be392b20c02c54f1f9868fe15c974e5fc Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Mar 2010 18:27:24 +0000 Subject: [PATCH 1750/1766] added generic interrupt support git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1057 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/TODO | 2 + libs/freetdm/src/ftdm_io.c | 138 ++++++++---- libs/freetdm/src/ftdm_queue.c | 29 ++- libs/freetdm/src/ftdm_threadmutex.c | 209 +++++++++++++----- .../ftmod_sangoma_boost/ftdm_sangoma_boost.h | 2 - .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 136 +++++------- .../sangoma_boost_client.c | 6 +- .../sangoma_boost_client.h | 2 +- libs/freetdm/src/include/freetdm.h | 69 +++--- libs/freetdm/src/include/ftdm_threadmutex.h | 11 +- libs/freetdm/src/include/ftdm_types.h | 1 + 11 files changed, 372 insertions(+), 233 deletions(-) diff --git a/libs/freetdm/TODO b/libs/freetdm/TODO index fb297b2eef..45b134bad3 100644 --- a/libs/freetdm/TODO +++ b/libs/freetdm/TODO @@ -5,3 +5,5 @@ then ftdm_event_t would be renamed to ftdm_oob_event_t and the enum_id renamed to type, then ftdm_span_next_event() will only return OOB events +- query span hw status (connected/disconnected) on startup + diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 3e6cdef0e9..221bf34117 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -49,6 +49,8 @@ #include "ftdm_pika.h" #endif +#define SPAN_PENDING_CHANS_QUEUE_SIZE 1000 + static int time_is_init = 0; static void time_init(void) @@ -410,6 +412,7 @@ static ftdm_status_t ftdm_span_destroy(ftdm_span_t *span) } /* destroy final basic resources of the span data structure */ + ftdm_queue_destroy(&span->pendingchans); ftdm_mutex_unlock(span->mutex); ftdm_mutex_destroy(&span->mutex); ftdm_safe_free(span->signal_data); @@ -504,16 +507,19 @@ FT_DECLARE(ftdm_status_t) ftdm_span_create(ftdm_io_interface_t *fio, ftdm_span_t ftdm_span_t *new_span = NULL; ftdm_status_t status = FTDM_FAIL; - assert(fio != NULL); + ftdm_assert(fio != NULL, "No IO provided\n"); ftdm_mutex_lock(globals.mutex); if (globals.span_index < FTDM_MAX_SPANS_INTERFACE) { - new_span = ftdm_malloc(sizeof(*new_span)); - assert(new_span); - memset(new_span, 0, sizeof(*new_span)); + new_span = ftdm_calloc(sizeof(*new_span), 1); + ftdm_assert(new_span, "allocating span failed\n"); + status = ftdm_mutex_create(&new_span->mutex); - assert(status == FTDM_SUCCESS); + ftdm_assert(status == FTDM_SUCCESS, "mutex creation failed\n"); + + status = ftdm_queue_create(&new_span->pendingchans, SPAN_PENDING_CHANS_QUEUE_SIZE); + ftdm_assert(status == FTDM_SUCCESS, "span chans queue creation failed\n"); ftdm_set_flag(new_span, FTDM_SPAN_CONFIGURED); new_span->span_id = ++globals.span_index; @@ -1154,7 +1160,12 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(ftdm_channel_t *ftdmchan, ftdm_ if (ok) { ftdm_set_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); - ftdm_set_flag_locked(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); + + ftdm_mutex_lock(ftdmchan->span->mutex); + ftdm_set_flag(ftdmchan->span, FTDM_SPAN_STATE_CHANGE); + ftdm_queue_enqueue(ftdmchan->span->pendingchans, ftdmchan); + ftdm_mutex_unlock(ftdmchan->span->mutex); + ftdmchan->last_state = ftdmchan->state; ftdmchan->state = state; } @@ -3155,44 +3166,85 @@ FT_DECLARE(int) ftdm_load_modules(void) FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void) { - ftdm_hash_iterator_t *i; - ftdm_dso_lib_t lib; + ftdm_hash_iterator_t *i = NULL; + ftdm_dso_lib_t lib = NULL; + char modpath[255] = { 0 }; + /* stop signaling interfaces first as signaling depends on I/O and not the other way around */ for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { - const void *key; - void *val; + const void *key = NULL; + void *val = NULL; + ftdm_module_t *mod = NULL; hashtable_this(i, &key, NULL, &val); - if (key && val) { - ftdm_module_t *mod = (ftdm_module_t *) val; - - if (!mod) { - continue; - } - - if (mod->io_unload) { - if (mod->io_unload() == FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_INFO, "Unloading IO %s\n", mod->name); - } else { - ftdm_log(FTDM_LOG_ERROR, "Error unloading IO %s\n", mod->name); - } - } - - if (mod->sig_unload) { - if (mod->sig_unload() == FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_INFO, "Unloading SIG %s\n", mod->name); - } else { - ftdm_log(FTDM_LOG_ERROR, "Error unloading SIG %s\n", mod->name); - } - } - - - ftdm_log(FTDM_LOG_INFO, "Unloading %s\n", mod->path); - lib = mod->lib; - ftdm_dso_destroy(&lib); - + if (!key || !val) { + continue; } + + mod = (ftdm_module_t *) val; + + if (!mod->sig_unload) { + continue; + } + + ftdm_log(FTDM_LOG_INFO, "Unloading signaling interface %s\n", mod->name); + + if (mod->sig_unload() != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error unloading signaling interface %s\n", mod->name); + continue; + } + + ftdm_log(FTDM_LOG_INFO, "Unloaded signaling interface %s\n", mod->name); + } + + /* Now go ahead with I/O interfaces */ + for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { + const void *key = NULL; + void *val = NULL; + ftdm_module_t *mod = NULL; + + hashtable_this(i, &key, NULL, &val); + + if (!key || !val) { + continue; + } + + mod = (ftdm_module_t *) val; + + if (!mod->io_unload) { + continue; + } + + ftdm_log(FTDM_LOG_INFO, "Unloading I/O interface %s\n", mod->name); + + if (mod->io_unload() != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Error unloading I/O interface %s\n", mod->name); + continue; + } + + ftdm_log(FTDM_LOG_INFO, "Unloaded I/O interface %s\n", mod->name); + } + + /* Now unload the actual shared object/dll */ + for (i = hashtable_first(globals.module_hash); i; i = hashtable_next(i)) { + ftdm_module_t *mod = NULL; + const void *key = NULL; + void *val = NULL; + + hashtable_this(i, &key, NULL, &val); + + if (!key || !val) { + continue; + } + + mod = (ftdm_module_t *) val; + + lib = mod->lib; + snprintf(modpath, sizeof(modpath), "%s", mod->path); + ftdm_log(FTDM_LOG_INFO, "Unloading module %s\n", modpath); + ftdm_dso_destroy(&lib); + ftdm_log(FTDM_LOG_INFO, "Unloaded module %s\n", modpath); } return FTDM_SUCCESS; @@ -3506,8 +3558,12 @@ FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) time_end(); globals.running = 0; + + globals.span_index = 0; + ftdm_span_close_all(); - ftdm_sleep(1000); + + ftdm_unload_modules(); ftdm_mutex_lock(globals.span_mutex); for (sp = globals.spans; sp;) { @@ -3529,10 +3585,6 @@ FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) globals.spans = NULL; ftdm_mutex_unlock(globals.span_mutex); - globals.span_index = 0; - - ftdm_unload_modules(); - ftdm_mutex_lock(globals.mutex); hashtable_destroy(globals.interface_hash); hashtable_destroy(globals.module_hash); diff --git a/libs/freetdm/src/ftdm_queue.c b/libs/freetdm/src/ftdm_queue.c index 92ea75c57a..60ee74737d 100644 --- a/libs/freetdm/src/ftdm_queue.c +++ b/libs/freetdm/src/ftdm_queue.c @@ -38,11 +38,12 @@ static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj); static void *ftdm_std_queue_dequeue(ftdm_queue_t *queue); static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms); +static ftdm_status_t ftdm_std_queue_get_interrupt(ftdm_queue_t *queue, ftdm_interrupt_t **interrupt); static ftdm_status_t ftdm_std_queue_destroy(ftdm_queue_t **inqueue); struct ftdm_queue { ftdm_mutex_t *mutex; - ftdm_condition_t *condition; + ftdm_interrupt_t *interrupt; ftdm_size_t capacity; ftdm_size_t size; unsigned rindex; @@ -56,6 +57,7 @@ FT_DECLARE_DATA ftdm_queue_handler_t g_ftdm_queue_handler = /*.enqueue = */ ftdm_std_queue_enqueue, /*.dequeue = */ ftdm_std_queue_dequeue, /*.wait = */ ftdm_std_queue_wait, + /*.get_interrupt = */ ftdm_std_queue_get_interrupt, /*.destroy = */ ftdm_std_queue_destroy }; @@ -66,6 +68,7 @@ FT_DECLARE(ftdm_status_t) ftdm_global_set_queue_handler(ftdm_queue_handler_t *ha !handler->enqueue || !handler->dequeue || !handler->wait || + !handler->get_interrupt || !handler->destroy) { return FTDM_FAIL; } @@ -95,7 +98,7 @@ static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t goto failed; } - if (ftdm_condition_create(&queue->condition, queue->mutex) != FTDM_SUCCESS) { + if (ftdm_interrupt_create(&queue->interrupt, FTDM_INVALID_SOCKET) != FTDM_SUCCESS) { goto failed; } @@ -104,8 +107,8 @@ static ftdm_status_t ftdm_std_queue_create(ftdm_queue_t **outqueue, ftdm_size_t failed: if (queue) { - if (queue->condition) { - ftdm_condition_destroy(&queue->condition); + if (queue->interrupt) { + ftdm_interrupt_destroy(&queue->interrupt); } if (queue->mutex) { ftdm_mutex_destroy(&queue->mutex); @@ -139,7 +142,7 @@ static ftdm_status_t ftdm_std_queue_enqueue(ftdm_queue_t *queue, void *obj) status = FTDM_SUCCESS; /* wake up queue reader */ - ftdm_condition_signal(queue->condition); + ftdm_interrupt_signal(queue->interrupt); done: @@ -188,7 +191,7 @@ static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms) } /* no elements on the queue, wait for someone to write an element */ - ret = ftdm_condition_wait(queue->condition, ms); + ret = ftdm_interrupt_wait(queue->interrupt, ms); /* got an element or timeout, bail out */ ftdm_mutex_unlock(queue->mutex); @@ -196,14 +199,22 @@ static ftdm_status_t ftdm_std_queue_wait(ftdm_queue_t *queue, int ms) return ret; } +static ftdm_status_t ftdm_std_queue_get_interrupt(ftdm_queue_t *queue, ftdm_interrupt_t **interrupt) +{ + ftdm_assert_return(queue != NULL, FTDM_FAIL, "Queue is null!\n"); + ftdm_assert_return(interrupt != NULL, FTDM_FAIL, "Queue is null!\n"); + *interrupt = queue->interrupt; + return FTDM_SUCCESS; +} + static ftdm_status_t ftdm_std_queue_destroy(ftdm_queue_t **inqueue) { ftdm_queue_t *queue = NULL; - ftdm_assert_return(inqueue != NULL, FTDM_FAIL, "Queue is null!"); - ftdm_assert_return(*inqueue != NULL, FTDM_FAIL, "Queue is null!"); + ftdm_assert_return(inqueue != NULL, FTDM_FAIL, "Queue is null!\n"); + ftdm_assert_return(*inqueue != NULL, FTDM_FAIL, "Queue is null!\n"); queue = *inqueue; - ftdm_condition_destroy(&queue->condition); + ftdm_interrupt_destroy(&queue->interrupt); ftdm_mutex_destroy(&queue->mutex); ftdm_safe_free(queue->elements); ftdm_safe_free(queue); diff --git a/libs/freetdm/src/ftdm_threadmutex.c b/libs/freetdm/src/ftdm_threadmutex.c index 7446896dcd..49cdb59cc1 100644 --- a/libs/freetdm/src/ftdm_threadmutex.c +++ b/libs/freetdm/src/ftdm_threadmutex.c @@ -40,6 +40,7 @@ struct ftdm_mutex { #else #include +#include #define FTDM_THREAD_CALLING_CONVENTION @@ -49,16 +50,18 @@ struct ftdm_mutex { #endif -struct ftdm_condition { +struct ftdm_interrupt { + ftdm_socket_t device; #ifdef WIN32 - HANDLE condition; + /* for generic interruption */ + HANDLE event; #else - pthread_cond_t condition; + /* for generic interruption */ + int readfd; + int writefd; #endif - ftdm_mutex_t *mutex; }; - struct ftdm_thread { #ifdef WIN32 void *handle; @@ -238,123 +241,207 @@ FT_DECLARE(ftdm_status_t) _ftdm_mutex_unlock(ftdm_mutex_t *mutex) } -FT_DECLARE(ftdm_status_t) ftdm_condition_create(ftdm_condition_t **incondition, ftdm_mutex_t *mutex) +FT_DECLARE(ftdm_status_t) ftdm_interrupt_create(ftdm_interrupt_t **ininterrupt, ftdm_socket_t device) { - ftdm_condition_t *condition = NULL; + ftdm_interrupt_t *interrupt = NULL; +#ifndef WIN32 + int fds[2]; +#endif - ftdm_assert_return(incondition != NULL, FTDM_FAIL, "Condition double pointer is null!\n"); - ftdm_assert_return(mutex != NULL, FTDM_FAIL, "Mutex for condition must not be null!\n"); + ftdm_assert_return(ininterrupt != NULL, FTDM_FAIL, "interrupt double pointer is null!\n"); - condition = ftdm_calloc(1, sizeof(*condition)); - if (!condition) { + interrupt = ftdm_calloc(1, sizeof(*interrupt)); + if (!interrupt) { + ftdm_log(FTDM_LOG_ERROR, "Failed to allocate interrupt memory\n"); return FTDM_FAIL; } - condition->mutex = mutex; + interrupt->device = device; #ifdef WIN32 - condition->condition = CreateEvent(NULL, FALSE, FALSE, NULL); - if (!condition->condition) { + interrupt->interrupt = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!interrupt->interrupt) { + ftdm_log(FTDM_LOG_ERROR, "Failed to allocate interrupt event\n"); goto failed; } #else - if (pthread_cond_init(&condition->condition, NULL)) { + if (pipe(fds)) { + ftdm_log(FTDM_LOG_ERROR, "Failed to allocate interrupt pipe: %s\n", strerror(errno)); goto failed; } + interrupt->readfd = fds[0]; + interrupt->writefd = fds[1]; #endif - *incondition = condition; + *ininterrupt = interrupt; return FTDM_SUCCESS; failed: - if (condition) { - ftdm_safe_free(condition); + if (interrupt) { +#ifndef WIN32 + if (interrupt->readfd) { + close(interrupt->readfd); + close(interrupt->writefd); + interrupt->readfd = -1; + interrupt->writefd = -1; + } +#endif + ftdm_safe_free(interrupt); } return FTDM_FAIL; } #define ONE_BILLION 1000000000 -FT_DECLARE(ftdm_status_t) ftdm_condition_wait(ftdm_condition_t *condition, int ms) +FT_DECLARE(ftdm_status_t) ftdm_interrupt_wait(ftdm_interrupt_t *interrupt, int ms) { + int num = 1; #ifdef WIN32 DWORD res = 0; + HANDLE ints[2]; +#else + int res = 0; + struct pollfd ints[2]; + char pipebuf[255]; #endif - ftdm_assert_return(condition != NULL, FTDM_FAIL, "Condition is null!\n"); + + ftdm_assert_return(interrupt != NULL, FTDM_FAIL, "Condition is null!\n"); + + + /* start implementation */ #ifdef WIN32 - ftdm_mutex_unlock(condition->mutex); - res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); - ftdm_mutex_lock(condition->mutex); + ints[0] = interrupt->event; + if (interrupt->device != FTDM_INVALID_SOCKET) { + num++; + ints[1] = interrupt->device; + } + res = WaitForMultipleObjects(num, &ints, FALSE, ms >= 0 ? ms : INFINITE); switch (res) { - case WAIT_ABANDONED: case WAIT_TIMEOUT: return FTDM_TIMEOUT; case WAIT_FAILED: + case WAIT_ABANDONED: /* is it right to fail with abandoned? */ return FTDM_FAIL; - case WAIT_OBJECT_0: - return FTDM_SUCCESS; default: - ftdm_log(FTDM_LOG_ERROR, "Error waiting for freetdm condition event (WaitForSingleObject returned %d)\n", res); - return FTDM_FAIL; + if (res >= (sizeof(ints)/sizeof(ints[0]))) { + ftdm_log(FTDM_LOG_ERROR, "Error waiting for freetdm interrupt event (WaitForSingleObject returned %d)\n", res); + return FTDM_FAIL; + } + return FTDM_SUCCESS; } #else - int res = 0; - if (ms > 0) { - struct timeval t; - struct timespec waitms; - gettimeofday(&t, NULL); - waitms.tv_sec = t.tv_sec + ( ms / 1000 ); - waitms.tv_nsec = 1000*(t.tv_usec + (1000 * ( ms % 1000 ))); - if (waitms.tv_nsec >= ONE_BILLION) { - waitms.tv_sec++; - waitms.tv_nsec -= ONE_BILLION; - } - res = pthread_cond_timedwait(&condition->condition, &condition->mutex->mutex, &waitms); - } else { - res = pthread_cond_wait(&condition->condition, &condition->mutex->mutex); - } - if (res != 0) { - if (res == ETIMEDOUT) { - return FTDM_TIMEOUT; - } + ints[0].fd = interrupt->readfd; + ints[0].events = POLLIN; + ints[0].revents = 0; - ftdm_log(FTDM_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res); + if (interrupt->device != FTDM_INVALID_SOCKET) { + num++; + ints[1].fd = interrupt->device; + ints[1].events = POLLIN; + ints[1].revents = 0; + } + + res = poll(ints, num, ms); + + if (res == -1) { + ftdm_log(FTDM_LOG_CRIT, "interrupt poll failed (%s)\n", strerror(errno)); return FTDM_FAIL; } + + if (res == 0) { + return FTDM_TIMEOUT; + } + + if (ints[0].revents & POLLIN) { + res = read(ints[0].fd, pipebuf, sizeof(pipebuf)); + if (res == -1) { + ftdm_log(FTDM_LOG_CRIT, "reading interrupt descriptor failed (%s)\n", strerror(errno)); + } + } + return FTDM_SUCCESS; #endif } -FT_DECLARE(ftdm_status_t) ftdm_condition_signal(ftdm_condition_t *condition) +FT_DECLARE(ftdm_status_t) ftdm_interrupt_signal(ftdm_interrupt_t *interrupt) { - ftdm_assert_return(condition != NULL, FTDM_FAIL, "Condition is null!\n"); + ftdm_assert_return(interrupt != NULL, FTDM_FAIL, "Interrupt is null!\n"); #ifdef WIN32 - if (!SetEvent(condition->condition)) { + if (!SetEvent(interrupt->interrupt)) { + ftdm_log(FTDM_LOG_ERROR, "Failed to signal interrupt\n"); return FTDM_FAIL; } #else int err; - if ((err = pthread_cond_signal(&condition->condition))) { - ftdm_log(FTDM_LOG_ERROR, "Failed to signal condition %d:%s\n", err, strerror(err)); + if ((err = write(interrupt->writefd, "w", 1)) != 1) { + ftdm_log(FTDM_LOG_ERROR, "Failed to signal interrupt: %s\n", errno, strerror(errno)); return FTDM_FAIL; } #endif return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) ftdm_condition_destroy(ftdm_condition_t **incondition) +FT_DECLARE(ftdm_status_t) ftdm_interrupt_destroy(ftdm_interrupt_t **ininterrupt) { - ftdm_condition_t *condition = NULL; - ftdm_assert_return(incondition != NULL, FTDM_FAIL, "Condition null when destroying!\n"); - condition = *incondition; + ftdm_interrupt_t *interrupt = NULL; + ftdm_assert_return(ininterrupt != NULL, FTDM_FAIL, "Interrupt null when destroying!\n"); + interrupt = *ininterrupt; #ifdef WIN32 - CloseHandle(condition->condition); + CloseHandle(interrupt->interrupt); #else - if (pthread_cond_destroy(&condition->condition)) { + close(interrupt->readfd); + close(interrupt->writefd); + interrupt->readfd = -1; + interrupt->writefd = -1; +#endif + ftdm_safe_free(interrupt); + *ininterrupt = NULL; + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_interrupt_multiple_wait(ftdm_interrupt_t *interrupts[], ftdm_size_t size, int ms) +{ +#ifndef WIN32 + int i; + int res = 0; + int numdevices = 0; + char pipebuf[255]; + struct pollfd ints[size*2]; + + memset(&ints, 0, sizeof(ints)); + + for (i = 0; i < size; i++) { + ints[i].events = POLLIN; + ints[i].revents = 0; + ints[i].fd = interrupts[i]->readfd; + if (interrupts[i]->device != FTDM_INVALID_SOCKET) { + ints[i+numdevices].events = POLLIN; + ints[i+numdevices].revents = 0; + ints[i+numdevices].fd = interrupts[i]->device; + numdevices++; + } + } + + res = poll(ints, size + numdevices, ms); + + if (res == -1) { + ftdm_log(FTDM_LOG_CRIT, "interrupt poll failed (%s)\n", strerror(errno)); return FTDM_FAIL; } + + if (res == 0) { + return FTDM_TIMEOUT; + } + + for (i = size; i < ftdm_array_len(ints); i++) { + if (ints[i].revents & POLLIN) { + res = read(ints[0].fd, pipebuf, sizeof(pipebuf)); + if (res == -1) { + ftdm_log(FTDM_LOG_CRIT, "reading interrupt descriptor failed (%s)\n", strerror(errno)); + } + } + } + #endif - ftdm_safe_free(condition); - *incondition = NULL; return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h index d4659b1141..31a231f309 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftdm_sangoma_boost.h @@ -46,8 +46,6 @@ typedef enum { typedef struct ftdm_sangoma_boost_data { sangomabc_connection_t mcon; sangomabc_connection_t pcon; - fd_set rfds; - fd_set efds; int iteration; uint32_t flags; boost_sigmod_interface_t *sigmod; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 339a5a4203..1f9e607490 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -39,7 +39,7 @@ */ /* NOTE: -On WIN32 platform this code works with sigmod ONLY, don't try to make sense of any socket code for win32 +On __WINDOWS__ platform this code works with sigmod ONLY, don't try to make sense of any socket code for win I basically ifdef out everything that the compiler complained about */ @@ -1016,11 +1016,8 @@ static void handle_heartbeat(sangomabc_connection_t *mcon, sangomabc_short_event err = sangomabc_connection_writep(mcon, (sangomabc_event_t*)event); if (err <= 0) { - ftdm_log(FTDM_LOG_CRIT, "Failed to tx on ISUP socket [%s]: %s\n", strerror(errno)); + ftdm_log(FTDM_LOG_CRIT, "Failed to tx on boost connection [%s]: %s\n", strerror(errno)); } - - mcon->hb_elapsed = 0; - return; } @@ -1050,7 +1047,6 @@ static void handle_restart(sangomabc_connection_t *mcon, ftdm_span_t *span, sang ftdm_set_flag_locked(span, FTDM_SPAN_SUSPENDED); ftdm_set_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING); - mcon->hb_elapsed = 0; } /** @@ -1452,6 +1448,7 @@ static __inline__ void init_outgoing_array(void) */ static __inline__ void check_state(ftdm_span_t *span) { + ftdm_channel_t *ftdmchan = NULL; ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; int susp = ftdm_test_flag(span, FTDM_SPAN_SUSPENDED); @@ -1462,17 +1459,23 @@ static __inline__ void check_state(ftdm_span_t *span) if (ftdm_test_flag(span, FTDM_SPAN_STATE_CHANGE) || susp) { uint32_t j; ftdm_clear_flag_locked(span, FTDM_SPAN_STATE_CHANGE); - for(j = 1; j <= span->chan_count; j++) { - if (ftdm_test_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE) || susp) { + if (susp) { + for (j = 0; j <= span->chan_count; j++) { ftdm_mutex_lock(span->channels[j]->mutex); ftdm_clear_flag((span->channels[j]), FTDM_CHANNEL_STATE_CHANGE); - if (susp && span->channels[j]->state != FTDM_CHANNEL_STATE_DOWN) { - ftdm_channel_set_state(span->channels[j], FTDM_CHANNEL_STATE_RESTART, 0); - } + ftdm_channel_set_state(span->channels[j], FTDM_CHANNEL_STATE_RESTART, 0); state_advance(span->channels[j]); ftdm_channel_complete_state(span->channels[j]); ftdm_mutex_unlock(span->channels[j]->mutex); } + } else { + while ((ftdmchan = ftdm_queue_dequeue(span->pendingchans))) { + ftdm_mutex_lock(ftdmchan->mutex); + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + state_advance(ftdmchan); + ftdm_channel_complete_state(ftdmchan); + ftdm_mutex_unlock(ftdmchan->mutex); + } } } @@ -1487,7 +1490,6 @@ static __inline__ void check_state(ftdm_span_t *span) ftdm_clear_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RESTARTING); ftdm_clear_flag_locked(span, FTDM_SPAN_SUSPENDED); ftdm_clear_flag((&sangoma_boost_data->mcon), MSU_FLAG_DOWN); - sangoma_boost_data->mcon.hb_elapsed = 0; init_outgoing_array(); } } @@ -1596,6 +1598,18 @@ static ftdm_status_t ftdm_boost_connection_open(ftdm_span_t *span) ftdm_log(FTDM_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); return FTDM_FAIL; } + + /* try to create the boost sockets interrupt objects */ + if (ftdm_interrupt_create(&sangoma_boost_data->pcon.sock_interrupt, sangoma_boost_data->pcon.socket) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Span %s could not create its boost msock interrupt!\n", span->name); + return FTDM_FAIL; + } + + if (ftdm_interrupt_create(&sangoma_boost_data->mcon.sock_interrupt, sangoma_boost_data->mcon.socket) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_ERROR, "Span %s could not create its boost psock interrupt!\n", span->name); + return FTDM_FAIL; + } + return FTDM_SUCCESS; } @@ -1603,49 +1617,34 @@ static ftdm_status_t ftdm_boost_connection_open(ftdm_span_t *span) \brief wait for a boost event \return -1 on error, 0 on timeout, 1 when there are events */ -static int ftdm_boost_wait_event(ftdm_span_t *span, int ms) +static int ftdm_boost_wait_event(ftdm_span_t *span) { -#ifndef WIN32 - struct timeval tv = { 0, ms * 1000 }; - sangomabc_connection_t *mcon, *pcon; - int max, activity; -#endif + ftdm_status_t res; + ftdm_interrupt_t *ints[3]; + int numints; ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; + ftdm_queue_get_interrupt(span->pendingchans, &ints[0]); + numints = 1; + /* if in queue mode wait for both the pendingchans queue and the boost msg queue */ if (sangoma_boost_data->sigmod) { - ftdm_status_t res; - res = ftdm_queue_wait(sangoma_boost_data->boost_queue, ms); - if (FTDM_TIMEOUT == res) { - return 0; - } - if (FTDM_SUCCESS != res) { - return -1; - } - return 1; + ftdm_queue_get_interrupt(sangoma_boost_data->boost_queue, &ints[1]); + numints = 2; + } +#ifndef __WINDOWS__ + else { + /* socket mode ... */ + ints[1] = sangoma_boost_data->mcon.sock_interrupt; + ints[2] = sangoma_boost_data->pcon.sock_interrupt; + numints = 3; + sangoma_boost_data->iteration = 0; } -#ifndef WIN32 - mcon = &sangoma_boost_data->mcon; - pcon = &sangoma_boost_data->pcon; - - FD_ZERO(&sangoma_boost_data->rfds); - FD_ZERO(&sangoma_boost_data->efds); - FD_SET(mcon->socket, &sangoma_boost_data->rfds); - FD_SET(mcon->socket, &sangoma_boost_data->efds); - FD_SET(pcon->socket, &sangoma_boost_data->rfds); - FD_SET(pcon->socket, &sangoma_boost_data->efds); - sangoma_boost_data->iteration = 0; - - max = ((pcon->socket > mcon->socket) ? pcon->socket : mcon->socket) + 1; - if ((activity = select(max, &sangoma_boost_data->rfds, NULL, &sangoma_boost_data->efds, &tv)) < 0) { - return -1; - } - - if (FD_ISSET(pcon->socket, &sangoma_boost_data->efds) || FD_ISSET(mcon->socket, &sangoma_boost_data->efds)) { - return -1; - } - - return 1; #endif + res = ftdm_interrupt_multiple_wait(ints, numints, -1); + if (FTDM_SUCCESS != res) { + ftdm_log(FTDM_LOG_CRIT, "Unexpected return value from interrupt waiting: %d\n", res); + return -1; + } return 0; } @@ -1659,19 +1658,13 @@ static sangomabc_event_t *ftdm_boost_read_event(ftdm_span_t *span) mcon = &sangoma_boost_data->mcon; pcon = &sangoma_boost_data->pcon; - if (sangoma_boost_data->sigmod -#ifndef WIN32 - || FD_ISSET(pcon->socket, &sangoma_boost_data->rfds) -#endif - ) { - event = sangomabc_connection_readp(pcon, sangoma_boost_data->iteration); - } -#ifndef WIN32 + event = sangomabc_connection_readp(pcon, sangoma_boost_data->iteration); + /* if there is no event and this is not a sigmod-driven span it's time to try the other connection for events */ - if (!event && !sangoma_boost_data->sigmod && FD_ISSET(mcon->socket, &sangoma_boost_data->rfds)) { - event = sangomabc_connection_readp(mcon, sangoma_boost_data->iteration); + if (!event && !sangoma_boost_data->sigmod) { + event = sangomabc_connection_read(mcon, sangoma_boost_data->iteration); } -#endif + return event; } @@ -1684,7 +1677,6 @@ static void *ftdm_sangoma_boost_run(ftdm_thread_t *me, void *obj) { ftdm_span_t *span = (ftdm_span_t *) obj; sangomabc_connection_t *mcon, *pcon; - uint32_t ms = 10; ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data; mcon = &sangoma_boost_data->mcon; @@ -1719,7 +1711,6 @@ static void *ftdm_sangoma_boost_run(ftdm_thread_t *me, void *obj) while (ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING)) { sangomabc_event_t *event = NULL; - int activity = 0; if (!ftdm_running()) { if (!sangoma_boost_data->sigmod) { @@ -1735,27 +1726,17 @@ static void *ftdm_sangoma_boost_run(ftdm_thread_t *me, void *obj) break; } - if ((activity = ftdm_boost_wait_event(span, ms)) < 0) { + if (ftdm_boost_wait_event(span) < 0) { ftdm_log(FTDM_LOG_ERROR, "ftdm_boost_wait_event failed\n"); goto error; } - if (activity) { - while ((event = ftdm_boost_read_event(span))) { - parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event); - sangoma_boost_data->iteration++; - } + while ((event = ftdm_boost_read_event(span))) { + parse_sangoma_event(span, pcon, (sangomabc_short_event_t*)event); + sangoma_boost_data->iteration++; } - pcon->hb_elapsed += ms; - - if (ftdm_test_flag(span, FTDM_SPAN_SUSPENDED) || ftdm_test_flag(mcon, MSU_FLAG_DOWN)) { - pcon->hb_elapsed = 0; - } - - if (ftdm_running()) { - check_state(span); - } + check_state(span); } goto end; @@ -2235,6 +2216,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) sangoma_boost_data->sigmod = sigmod_iface; sigmod_iface->configure_span(span, ftdm_parameters); } else { + ftdm_log(FTDM_LOG_NOTICE, "Span %s will use boost socket mode\n", span->name); ftdm_set_string(sangoma_boost_data->mcon.cfg.local_ip, local_ip); sangoma_boost_data->mcon.cfg.local_port = local_port; ftdm_set_string(sangoma_boost_data->mcon.cfg.remote_ip, remote_ip); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c index 626074dc84..c5cb97119f 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c @@ -311,11 +311,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int ftdm_log(FTDM_LOG_CRIT, "Invalid Boost Version %i Expecting %i\n",mcon->event.version, SIGBOOST_VERSION); } - /* Must check for < 0 cannot rely on bytes > MIN_SIZE_... compiler issue */ - if (bytes < 0) { - msg_ok=0; - - } else if ((bytes >= MIN_SIZE_CALLSTART_MSG) && boost_full_event(mcon->event.event_id)) { + if ((bytes >= MIN_SIZE_CALLSTART_MSG) && boost_full_event(mcon->event.event_id)) { msg_ok=1; } else if (bytes == sizeof(sangomabc_short_event_t)) { diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h index 2e18d406e5..12c3f12b8c 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h @@ -105,10 +105,10 @@ struct sangomabc_connection { unsigned int txwindow; unsigned int rxseq_reset; sangomabc_ip_cfg_t cfg; - uint32_t hb_elapsed; /* boost signaling mod interface pointer (if not working in TCP mode) */ boost_sigmod_interface_t *sigmod; ftdm_queue_t *boost_queue; + ftdm_interrupt_t *sock_interrupt; ftdm_span_t *span; }; diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index aa1da3af56..966cca210b 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -381,6 +381,42 @@ struct ftdm_event { void *data; }; +typedef struct ftdm_queue ftdm_queue_t; +typedef ftdm_status_t (*ftdm_queue_create_func_t)(ftdm_queue_t **queue, ftdm_size_t capacity); +typedef ftdm_status_t (*ftdm_queue_enqueue_func_t)(ftdm_queue_t *queue, void *obj); +typedef void *(*ftdm_queue_dequeue_func_t)(ftdm_queue_t *queue); +typedef ftdm_status_t (*ftdm_queue_wait_func_t)(ftdm_queue_t *queue, int ms); +typedef ftdm_status_t (*ftdm_queue_get_interrupt_func_t)(ftdm_queue_t *queue, ftdm_interrupt_t **interrupt); +typedef ftdm_status_t (*ftdm_queue_destroy_func_t)(ftdm_queue_t **queue); +typedef struct ftdm_queue_handler { + ftdm_queue_create_func_t create; + ftdm_queue_enqueue_func_t enqueue; + ftdm_queue_dequeue_func_t dequeue; + ftdm_queue_wait_func_t wait; + ftdm_queue_get_interrupt_func_t get_interrupt; + ftdm_queue_destroy_func_t destroy; +} ftdm_queue_handler_t; +FT_DECLARE_DATA extern ftdm_queue_handler_t g_ftdm_queue_handler; + +/*! brief create a new queue */ +#define ftdm_queue_create(queue, capacity) g_ftdm_queue_handler.create(queue, capacity) + +/*! Enqueue an object */ +#define ftdm_queue_enqueue(queue, obj) g_ftdm_queue_handler.enqueue(queue, obj) + +/*! dequeue an object from the queue */ +#define ftdm_queue_dequeue(queue) g_ftdm_queue_handler.dequeue(queue) + +/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ +#define ftdm_queue_wait(queue, ms) g_ftdm_queue_handler.wait(queue, ms) + +/*! get the internal interrupt object (to wait for elements to be added from the outside bypassing ftdm_queue_wait) */ +#define ftdm_queue_get_interrupt(queue, ms) g_ftdm_queue_handler.get_interrupt(queue, ms) + +/*! destroy the queue */ +#define ftdm_queue_destroy(queue) g_ftdm_queue_handler.destroy(queue) + + #define FTDM_TOKEN_STRLEN 128 #define FTDM_MAX_TOKENS 10 @@ -621,6 +657,7 @@ struct ftdm_span { int suggest_chan_id; ftdm_state_map_t *state_map; ftdm_caller_data_t default_caller_data; + ftdm_queue_t *pendingchans; struct ftdm_span *next; }; @@ -673,36 +710,6 @@ struct ftdm_io_interface { fio_api_t api; }; -typedef struct ftdm_queue ftdm_queue_t; -typedef ftdm_status_t (*ftdm_queue_create_func_t)(ftdm_queue_t **queue, ftdm_size_t capacity); -typedef ftdm_status_t (*ftdm_queue_enqueue_func_t)(ftdm_queue_t *queue, void *obj); -typedef void *(*ftdm_queue_dequeue_func_t)(ftdm_queue_t *queue); -typedef ftdm_status_t (*ftdm_queue_wait_func_t)(ftdm_queue_t *queue, int ms); -typedef ftdm_status_t (*ftdm_queue_destroy_func_t)(ftdm_queue_t **queue); -typedef struct ftdm_queue_handler { - ftdm_queue_create_func_t create; - ftdm_queue_enqueue_func_t enqueue; - ftdm_queue_dequeue_func_t dequeue; - ftdm_queue_wait_func_t wait; - ftdm_queue_destroy_func_t destroy; -} ftdm_queue_handler_t; -FT_DECLARE_DATA extern ftdm_queue_handler_t g_ftdm_queue_handler; - -/*! brief create a new queue */ -#define ftdm_queue_create(queue, capacity) g_ftdm_queue_handler.create(queue, capacity) - -/*! Enqueue an object */ -#define ftdm_queue_enqueue(queue, obj) g_ftdm_queue_handler.enqueue(queue, obj) - -/*! dequeue an object from the queue */ -#define ftdm_queue_dequeue(queue) g_ftdm_queue_handler.dequeue(queue) - -/*! wait ms milliseconds for a queue to have available objects, -1 to wait forever */ -#define ftdm_queue_wait(queue, ms) g_ftdm_queue_handler.wait(queue, ms) - -/*! destroy the queue */ -#define ftdm_queue_destroy(queue) g_ftdm_queue_handler.destroy(queue) - /*! \brief Override the default queue handler */ FT_DECLARE(ftdm_status_t) ftdm_global_set_queue_handler(ftdm_queue_handler_t *handler); @@ -890,6 +897,8 @@ FIO_CODEC_FUNCTION(fio_alaw2ulaw); */ #define ftdm_socket_close(it) if (it > -1) { close(it); it = -1;} +#define ftdm_array_len(array) sizeof(array)/sizeof(array[0]) + static __inline__ void ftdm_abort(void) { #ifdef __cplusplus diff --git a/libs/freetdm/src/include/ftdm_threadmutex.h b/libs/freetdm/src/include/ftdm_threadmutex.h index a970eda522..f67d2840fe 100644 --- a/libs/freetdm/src/include/ftdm_threadmutex.h +++ b/libs/freetdm/src/include/ftdm_threadmutex.h @@ -32,7 +32,7 @@ extern "C" { #endif typedef struct ftdm_mutex ftdm_mutex_t; typedef struct ftdm_thread ftdm_thread_t; -typedef struct ftdm_condition ftdm_condition_t; +typedef struct ftdm_interrupt ftdm_interrupt_t; typedef void *(*ftdm_thread_function_t) (ftdm_thread_t *, void *); FT_DECLARE(ftdm_status_t) ftdm_thread_create_detached(ftdm_thread_function_t func, void *data); @@ -43,10 +43,11 @@ FT_DECLARE(ftdm_status_t) ftdm_mutex_destroy(ftdm_mutex_t **mutex); FT_DECLARE(ftdm_status_t) _ftdm_mutex_lock(ftdm_mutex_t *mutex); FT_DECLARE(ftdm_status_t) _ftdm_mutex_trylock(ftdm_mutex_t *mutex); FT_DECLARE(ftdm_status_t) _ftdm_mutex_unlock(ftdm_mutex_t *mutex); -FT_DECLARE(ftdm_status_t) ftdm_condition_create(ftdm_condition_t **cond, ftdm_mutex_t *mutex); -FT_DECLARE(ftdm_status_t) ftdm_condition_destroy(ftdm_condition_t **cond); -FT_DECLARE(ftdm_status_t) ftdm_condition_signal(ftdm_condition_t *cond); -FT_DECLARE(ftdm_status_t) ftdm_condition_wait(ftdm_condition_t *cond, int ms); +FT_DECLARE(ftdm_status_t) ftdm_interrupt_create(ftdm_interrupt_t **cond, ftdm_socket_t device); +FT_DECLARE(ftdm_status_t) ftdm_interrupt_destroy(ftdm_interrupt_t **cond); +FT_DECLARE(ftdm_status_t) ftdm_interrupt_signal(ftdm_interrupt_t *cond); +FT_DECLARE(ftdm_status_t) ftdm_interrupt_wait(ftdm_interrupt_t *cond, int ms); +FT_DECLARE(ftdm_status_t) ftdm_interrupt_multiple_wait(ftdm_interrupt_t *interrupts[], ftdm_size_t size, int ms); #ifdef __cplusplus } diff --git a/libs/freetdm/src/include/ftdm_types.h b/libs/freetdm/src/include/ftdm_types.h index 3d45185073..7260358c8f 100644 --- a/libs/freetdm/src/include/ftdm_types.h +++ b/libs/freetdm/src/include/ftdm_types.h @@ -40,6 +40,7 @@ #define FTDM_TYPES_H #include "fsk.h" +#define FTDM_INVALID_SOCKET -1 #ifdef WIN32 #include typedef HANDLE ftdm_socket_t; From dd39a902e64ff908e87f6b54816c0f5fd1de4e0d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Mar 2010 19:25:44 +0000 Subject: [PATCH 1751/1766] fix double call to state_advance git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1058 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/mod_freetdm/mod_freetdm.c | 1 + .../ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 800f5e23f6..468bcf10de 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -746,6 +746,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc len = frame->datalen; if (ftdm_channel_write(tech_pvt->ftdmchan, frame->data, frame->buflen, &len) != FTDM_SUCCESS) { if (++tech_pvt->wr_error > 10) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "too many I/O write errors!\n"); goto fail; } } else { diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 1f9e607490..e7317e3679 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -1229,7 +1229,7 @@ static __inline__ void state_advance(ftdm_channel_t *ftdmchan) ftdm_sigmsg_t sig; ftdm_status_t status; - ftdm_log(FTDM_LOG_DEBUG, "%d:%d STATE [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); + ftdm_log(FTDM_LOG_DEBUG, "%d:%d PROCESSING STATE [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, ftdm_channel_state2str(ftdmchan->state)); memset(&sig, 0, sizeof(sig)); sig.chan_id = ftdmchan->chan_id; @@ -1470,10 +1470,15 @@ static __inline__ void check_state(ftdm_span_t *span) } } else { while ((ftdmchan = ftdm_queue_dequeue(span->pendingchans))) { + /* it can happen that someone else processed the chan states + * but without taking the chan out of the queue, so check th + * flag before advancing the state */ ftdm_mutex_lock(ftdmchan->mutex); - ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); - state_advance(ftdmchan); - ftdm_channel_complete_state(ftdmchan); + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE); + state_advance(ftdmchan); + ftdm_channel_complete_state(ftdmchan); + } ftdm_mutex_unlock(ftdmchan->mutex); } } From bcb7f36a16ec09200b2ba87d01b15eab775ed40e Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 12 Mar 2010 20:08:30 +0000 Subject: [PATCH 1752/1766] Added CPU Monitor. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1059 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/Makefile.am | 6 +- libs/openzap/mod_openzap/mod_openzap.c | 3 +- libs/openzap/src/include/openzap.h | 1 + libs/openzap/src/include/zap_threadmutex.h | 5 + libs/openzap/src/include/zap_types.h | 4 + .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 9 +- libs/openzap/src/zap_io.c | 164 ++++++++++++- libs/openzap/src/zap_threadmutex.c | 225 +++++++++++++++++- 8 files changed, 395 insertions(+), 22 deletions(-) diff --git a/libs/openzap/Makefile.am b/libs/openzap/Makefile.am index 9f0c74869a..3d8094fba2 100644 --- a/libs/openzap/Makefile.am +++ b/libs/openzap/Makefile.am @@ -71,7 +71,8 @@ $(SRC)/libteletone_detect.c \ $(SRC)/libteletone_generate.c \ $(SRC)/zap_buffer.c \ $(SRC)/zap_threadmutex.c \ -$(SRC)/zap_dso.c +$(SRC)/zap_dso.c \ +$(SRC)/zap_cpu_monitor.c library_include_HEADERS = \ $(SRC)/include/fsk.h \ @@ -89,7 +90,8 @@ $(SRC)/include/zap_buffer.h \ $(SRC)/include/zap_config.h \ $(SRC)/include/zap_threadmutex.h \ $(SRC)/include/zap_dso.h \ -$(SRC)/include/zap_types.h +$(SRC)/include/zap_types.h \ +$(SRC)/include/zap_cpu_monitor.h lib_LTLIBRARIES = libopenzap.la libopenzap_la_CFLAGS = $(AM_CFLAGS) $(MY_CFLAGS) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index fddf2de69a..c9159f3cb7 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -3119,7 +3119,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) module_pool = pool; zap_global_set_logger(zap_logger); - + zap_cpu_monitor_disable(); + if (zap_global_init() != ZAP_SUCCESS) { zap_log(ZAP_LOG_ERROR, "Error loading OpenZAP\n"); return SWITCH_STATUS_TERM; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 3f88772cd8..18275c43bf 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -716,6 +716,7 @@ OZ_DECLARE(zap_status_t) zap_span_find_by_name(const char *name, zap_span_t **sp OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd); OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap); OZ_DECLARE(zap_status_t) zap_channel_set_caller_data(zap_channel_t *zchan, zap_caller_data_t *caller_data); +OZ_DECLARE(void) zap_cpu_monitor_disable(void); ZIO_CODEC_FUNCTION(zio_slin2ulaw); ZIO_CODEC_FUNCTION(zio_ulaw2slin); diff --git a/libs/openzap/src/include/zap_threadmutex.h b/libs/openzap/src/include/zap_threadmutex.h index 6e2af571ac..bc043ca180 100644 --- a/libs/openzap/src/include/zap_threadmutex.h +++ b/libs/openzap/src/include/zap_threadmutex.h @@ -36,6 +36,11 @@ 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: diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index f318da6d56..1ac2e86ba4 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -35,6 +35,9 @@ #define ZAP_TYPES_H #include "fsk.h" +#define ZAP_INVALID_SOCKET -1 +#define zap_array_len(obj) sizeof(obj)/sizeof(obj[0]) + #ifdef WIN32 #include typedef HANDLE zap_socket_t; @@ -62,6 +65,7 @@ typedef int zap_filehandle_t; 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 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 index a8609a0652..6149cb1c9b 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -726,6 +726,7 @@ static __inline__ void advance_chan_states(zap_channel_t *zchan); 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; if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { if ((zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { @@ -793,16 +794,18 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa return; error: - if (!zchan) { + 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, - 0, 0); + hangup_cause, 0); } diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8c11bae87e..f0acf1ba27 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -44,6 +44,7 @@ #ifdef ZAP_PIKA_SUPPORT #include "zap_pika.h" #endif +#include "zap_cpu_monitor.h" static int time_is_init = 0; @@ -63,6 +64,7 @@ static void time_end(void) time_is_init = 0; } + OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void) { #ifdef WIN32 @@ -74,6 +76,16 @@ OZ_DECLARE(zap_time_t) zap_current_time_in_ms(void) #endif } +typedef struct { + uint8_t running; + uint8_t alarm; + uint32_t interval; + uint8_t alarm_action_flags; + uint8_t set_alarm_threshold; + uint8_t reset_alarm_threshold; + zap_interrupt_t *interrupt; +} cpu_monitor_t; + static struct { zap_hash_t *interface_hash; zap_hash_t *module_hash; @@ -83,8 +95,16 @@ static struct { uint32_t span_index; uint32_t running; zap_span_t *spans; + cpu_monitor_t cpu_monitor; } globals; +static uint8_t zap_cpu_monitor_disabled = 0; + +enum zap_enum_cpu_alarm_action_flags +{ + ZAP_CPU_ALARM_ACTION_WARN = (1 << 0), + ZAP_CPU_ALARM_ACTION_REJECT = (1 << 1) +}; /* enum lookup funcs */ ZAP_ENUM_NAMES(TONEMAP_NAMES, TONEMAP_STRINGS) @@ -111,6 +131,8 @@ ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYP ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) +static zap_status_t zap_cpu_monitor_start(cpu_monitor_t* monitor_params); +static void zap_cpu_monitor_stop(cpu_monitor_t* monitor_params); static const char *cut_path(const char *in) { @@ -148,8 +170,12 @@ static const char *LEVEL_NAMES[] = { NULL }; + static int zap_log_level = 7; +/* Cpu monitor thread */ +static void *zap_cpu_monitor_run(zap_thread_t *me, void *obj); + static void default_logger(const char *file, const char *func, int line, int level, const char *fmt, ...) { const char *fp; @@ -1154,6 +1180,14 @@ OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan) snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is suspended"); return ZAP_FAIL; } + if (globals.cpu_monitor.alarm && + globals.cpu_monitor.alarm_action_flags & ZAP_CPU_ALARM_ACTION_REJECT) { + + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "CPU usage alarm is on - refusing to open channel\n"); + zap_log(ZAP_LOG_WARNING, "CPU usage alarm is on - refusing to open channel\n"); + zchan->caller_data.hangup_cause = ZAP_CAUSE_SWITCH_CONGESTION; + return ZAP_FAIL; + } if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) { snprintf(zchan->last_error, sizeof(zchan->last_error), "Channel is not ready or is in use %d %d", zap_test_flag(zchan, ZAP_CHANNEL_READY), status); @@ -2540,6 +2574,43 @@ static zap_status_t load_config(void) } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } + } else if (!strncasecmp(cfg.category, "general", 7)) { + if (!strncasecmp(var, "cpu_monitoring_interval", 24)) { + if (atoi(val) > 0) { + globals.cpu_monitor.interval = atoi(val); + } else { + zap_log(ZAP_LOG_ERROR, "Invalid cpu monitoring interval %s\n", val); + } + } else if (!strncasecmp(var, "cpu_set_alarm_threshold", 22)) { + if (atoi(val) > 0 && atoi(val) < 100) { + globals.cpu_monitor.set_alarm_threshold = atoi(val); + } else { + zap_log(ZAP_LOG_ERROR, "Invalid cpu alarm set threshold %s\n", val); + } + } else if (!strncasecmp(var, "cpu_reset_alarm_threshold", 22)) { + if (atoi(val) > 0 && atoi(val) < 100) { + globals.cpu_monitor.reset_alarm_threshold = atoi(val); + if (globals.cpu_monitor.reset_alarm_threshold > globals.cpu_monitor.set_alarm_threshold) { + globals.cpu_monitor.reset_alarm_threshold = globals.cpu_monitor.set_alarm_threshold-10; + zap_log(ZAP_LOG_ERROR, "Cpu alarm reset threshold must be lower than set threshold, set threshold to %d\n", globals.cpu_monitor.reset_alarm_threshold); + } + } else { + zap_log(ZAP_LOG_ERROR, "Invalid cpu alarm reset threshold %s\n", val); + } + } else if (!strncasecmp(var, "cpu_alarm_action", 16)) { + char* p = val; + do { + if (!strncasecmp(p, "reject", 6)) { + globals.cpu_monitor.alarm_action_flags |= ZAP_CPU_ALARM_ACTION_REJECT; + } else if (!strncasecmp(p, "warn", 4)) { + globals.cpu_monitor.alarm_action_flags |= ZAP_CPU_ALARM_ACTION_WARN; + } + p = strchr(p, ','); + if (p) { + while(++p) if (*p != 0x20) break; + } + } while (p); + } } else { zap_log(ZAP_LOG_ERROR, "unknown param [%s] '%s' / '%s'\n", cfg.category, var, val); } @@ -2547,7 +2618,6 @@ static zap_status_t load_config(void) zap_config_close_file(&cfg); zap_log(ZAP_LOG_INFO, "Configured %u channel(s)\n", configured); - return configured ? ZAP_SUCCESS : ZAP_FAIL; } @@ -2806,7 +2876,7 @@ OZ_DECLARE(zap_status_t) zap_span_send_signal(zap_span_t *span, zap_sigmsg_t *si OZ_DECLARE(zap_status_t) zap_global_init(void) { int modcount; - + memset(&globals, 0, sizeof(globals)); time_init(); @@ -2824,13 +2894,23 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) modcount = zap_load_modules(); zap_log(ZAP_LOG_NOTICE, "Modules configured: %d \n", modcount); - if (load_config() == ZAP_SUCCESS) { - globals.running = 1; - return ZAP_SUCCESS; + globals.cpu_monitor.interval = 1000; + globals.cpu_monitor.alarm_action_flags = ZAP_CPU_ALARM_ACTION_WARN | ZAP_CPU_ALARM_ACTION_REJECT; + globals.cpu_monitor.set_alarm_threshold = 80; + globals.cpu_monitor.reset_alarm_threshold = 70; + + if (load_config() != ZAP_SUCCESS) { + zap_log(ZAP_LOG_ERROR, "No modules configured!\n"); + return ZAP_FAIL; } - zap_log(ZAP_LOG_ERROR, "No modules configured!\n"); - return ZAP_FAIL; + globals.running = 1; + if (!zap_cpu_monitor_disabled) { + if (zap_cpu_monitor_start(&globals.cpu_monitor) != ZAP_SUCCESS) { + return ZAP_FAIL; + } + } + return ZAP_SUCCESS; } OZ_DECLARE(uint32_t) zap_running(void) @@ -2846,10 +2926,11 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) time_end(); - globals.running = 0; + globals.running = 0; + zap_cpu_monitor_stop(&globals.cpu_monitor); zap_span_close_all(); zap_sleep(1000); - + zap_mutex_lock(globals.span_mutex); for (sp = globals.spans; sp;) { zap_span_t *cur_span = sp; @@ -2900,7 +2981,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); zap_mutex_destroy(&globals.span_mutex); - + zap_interrupt_destroy(&globals.cpu_monitor.interrupt); memset(&globals, 0, sizeof(globals)); return ZAP_SUCCESS; } @@ -3192,6 +3273,69 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha return ret ? ZAP_FAIL : ZAP_SUCCESS; } +static void *zap_cpu_monitor_run(zap_thread_t *me, void *obj) +{ + cpu_monitor_t *monitor = (cpu_monitor_t *)obj; + struct zap_cpu_monitor_stats *cpu_stats = zap_new_cpu_monitor(); + if (!cpu_stats) { + return NULL; + } + monitor->running = 1; + + while(zap_running()) { + double time; + if (zap_cpu_get_system_idle_time(cpu_stats, &time)) { + break; + } + + if (monitor->alarm) { + if ((int)time >= (100-monitor->set_alarm_threshold)) { + zap_log(ZAP_LOG_DEBUG, "CPU alarm OFF (idle:%d)\n", (int) time); + monitor->alarm = 0; + } + if (monitor->alarm_action_flags & ZAP_CPU_ALARM_ACTION_WARN) { + zap_log(ZAP_LOG_WARNING, "CPU alarm is ON (cpu usage:%d)\n", (int) (100-time)); + } + } else { + if ((int)time <= (100-monitor->reset_alarm_threshold)) { + zap_log(ZAP_LOG_DEBUG, "CPU alarm ON (idle:%d)\n", (int) time); + monitor->alarm = 1; + } + } + zap_interrupt_wait(monitor->interrupt, monitor->interval); + } + zap_delete_cpu_monitor(cpu_stats); + monitor->running = 0; + return NULL; +} + + +static zap_status_t zap_cpu_monitor_start(cpu_monitor_t* monitor) +{ + if (zap_interrupt_create(&monitor->interrupt, ZAP_INVALID_SOCKET) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "Failed to create CPU monitor interrupt\n"); + return ZAP_FAIL; + } + + if (zap_thread_create_detached(zap_cpu_monitor_run, monitor) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "Failed to create cpu monitor thread!!\n"); + return ZAP_FAIL; + } + return ZAP_SUCCESS; +} + +static void zap_cpu_monitor_stop(cpu_monitor_t* monitor) +{ + zap_interrupt_signal(monitor->interrupt); + while(monitor->running) { + zap_sleep(10); + } +} + +OZ_DECLARE(void) zap_cpu_monitor_disable(void) +{ + zap_cpu_monitor_disabled = 1; +} /* For Emacs: diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index b6bc8435b6..5307f2bd7e 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -3,7 +3,7 @@ * 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 + * copies of the Soozware, and permit persons to whom the Soozware is * furnished to do so. * * This work is provided under this license on an "as is" basis, without warranty of any kind, @@ -15,6 +15,10 @@ * constitutes an essential part of this license. No use of any covered code is authorized hereunder * except under this disclaimer. * + * Contributors: + * + * Moises Silva + * */ #ifdef WIN32 @@ -35,8 +39,8 @@ struct zap_mutex { }; #else - #include +#include #define ZAP_THREAD_CALLING_CONVENTION @@ -46,6 +50,18 @@ struct zap_mutex { #endif +struct zap_interrupt { + zap_socket_t device; +#ifdef WIN32 + /* for generic interruption */ + HANDLE event; +#else + /* for generic interruption */ + int readfd; + int writefd; +#endif +}; + struct zap_thread { #ifdef WIN32 void *handle; @@ -75,7 +91,7 @@ static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args) #ifndef WIN32 pthread_attr_destroy(&thread->attribute); #endif - free(thread); + zap_safe_free(thread); return exit_val; } @@ -125,7 +141,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun fail: if (thread) { - free(thread); + zap_safe_free(thread); } done: return status; @@ -183,7 +199,7 @@ OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex) if (pthread_mutex_destroy(&mp->mutex)) return ZAP_FAIL; #endif - free(mp); + zap_safe_free(mp); return ZAP_SUCCESS; } @@ -192,8 +208,11 @@ OZ_DECLARE(zap_status_t) _zap_mutex_lock(zap_mutex_t *mutex) #ifdef WIN32 EnterCriticalSection(&mutex->mutex); #else - if (pthread_mutex_lock(&mutex->mutex)) + int err; + if ((err = pthread_mutex_lock(&mutex->mutex))) { + zap_log(ZAP_LOG_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err)); return ZAP_FAIL; + } #endif return ZAP_SUCCESS; } @@ -222,8 +241,202 @@ 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) +{ + zap_interrupt_t *interrupt = NULL; +#ifndef WIN32 + int fds[2]; +#endif + interrupt = calloc(1, sizeof(*interrupt)); + if (!interrupt) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate interrupt memory\n"); + return ZAP_FAIL; + } + interrupt->device = device; +#ifdef WIN32 + interrupt->interrupt = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!interrupt->interrupt) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate interrupt event\n"); + goto failed; + } +#else + if (pipe(fds)) { + zap_log(ZAP_LOG_ERROR, "Failed to allocate interrupt pipe: %s\n", strerror(errno)); + goto failed; + } + + interrupt->readfd = fds[0]; + interrupt->writefd = fds[1]; +#endif + + *ininterrupt = interrupt; + return ZAP_SUCCESS; + +failed: + if (interrupt) { +#ifndef WIN32 + if (interrupt->readfd) { + close(interrupt->readfd); + close(interrupt->writefd); + interrupt->readfd = -1; + interrupt->writefd = -1; + } +#endif + zap_safe_free(interrupt); + } + return ZAP_FAIL; +} + +#define ONE_BILLION 1000000000 + +OZ_DECLARE(zap_status_t) zap_interrupt_wait(zap_interrupt_t *interrupt, int ms) +{ + int num = 1; +#ifdef WIN32 + DWORD res = 0; + HANDLE ints[2]; +#else + int res = 0; + struct pollfd ints[2]; + char pipebuf[255]; +#endif + + /* start implementation */ +#ifdef WIN32 + ints[0] = interrupt->event; + if (interrupt->device != ZAP_INVALID_SOCKET) { + num++; + ints[1] = interrupt->device; + } + res = WaitForMultipleObjects(num, &ints, FALSE, ms >= 0 ? ms : INFINITE); + switch (res) { + case WAIT_TIMEOUT: + return ZAP_TIMEOUT; + case WAIT_FAILED: + case WAIT_ABANDONED: /* is it right to fail with abandoned? */ + return ZAP_FAIL; + default: + if (res >= (sizeof(ints)/sizeof(ints[0]))) { + zap_log(ZAP_LOG_ERROR, "Error waiting for openzap interrupt event (WaitForSingleObject returned %d)\n", res); + return ZAP_FAIL; + } + return ZAP_SUCCESS; + } +#else + ints[0].fd = interrupt->readfd; + ints[0].events = POLLIN; + ints[0].revents = 0; + + if (interrupt->device != ZAP_INVALID_SOCKET) { + num++; + ints[1].fd = interrupt->device; + ints[1].events = POLLIN; + ints[1].revents = 0; + } + + res = poll(ints, num, ms); + if (res == -1) { + zap_log(ZAP_LOG_CRIT, "interrupt poll failed (%s)\n", strerror(errno)); + return ZAP_FAIL; + } + + if (res == 0) { + return ZAP_TIMEOUT; + } + + if (ints[0].revents & POLLIN) { + res = read(ints[0].fd, pipebuf, sizeof(pipebuf)); + if (res == -1) { + zap_log(ZAP_LOG_CRIT, "reading interrupt descriptor failed (%s)\n", strerror(errno)); + } + } + + return ZAP_SUCCESS; +#endif +} + +OZ_DECLARE(zap_status_t) zap_interrupt_signal(zap_interrupt_t *interrupt) +{ +#ifdef WIN32 + if (!SetEvent(interrupt->interrupt)) { + zap_log(ZAP_LOG_ERROR, "Failed to signal interrupt\n"); + return ZAP_FAIL; + } +#else + int err; + if ((err = write(interrupt->writefd, "w", 1)) != 1) { + zap_log(ZAP_LOG_ERROR, "Failed to signal interrupt: %s\n", errno, strerror(errno)); + return ZAP_FAIL; + } +#endif + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_interrupt_destroy(zap_interrupt_t **ininterrupt) +{ + zap_interrupt_t *interrupt = NULL; + interrupt = *ininterrupt; +#ifdef WIN32 + CloseHandle(interrupt->interrupt); +#else + close(interrupt->readfd); + close(interrupt->writefd); + interrupt->readfd = -1; + interrupt->writefd = -1; +#endif + zap_safe_free(interrupt); + *ininterrupt = NULL; + return ZAP_SUCCESS; +} + +OZ_DECLARE(zap_status_t) zap_interrupt_multiple_wait(zap_interrupt_t *interrupts[], zap_size_t size, int ms) +{ +#ifndef WIN32 + int i; + int res = 0; + int numdevices = 0; + char pipebuf[255]; + struct pollfd ints[size*2]; + + memset(&ints, 0, sizeof(ints)); + + for (i = 0; i < size; i++) { + ints[i].events = POLLIN; + ints[i].revents = 0; + ints[i].fd = interrupts[i]->readfd; + if (interrupts[i]->device != ZAP_INVALID_SOCKET) { + ints[i+numdevices].events = POLLIN; + ints[i+numdevices].revents = 0; + ints[i+numdevices].fd = interrupts[i]->device; + numdevices++; + } + } + + res = poll(ints, size + numdevices, ms); + + if (res == -1) { + zap_log(ZAP_LOG_CRIT, "interrupt poll failed (%s)\n", strerror(errno)); + return ZAP_FAIL; + } + + if (res == 0) { + return ZAP_TIMEOUT; + } + + for (i = size; i < zap_array_len(ints); i++) { + if (ints[i].revents & POLLIN) { + res = read(ints[0].fd, pipebuf, sizeof(pipebuf)); + if (res == -1) { + zap_log(ZAP_LOG_CRIT, "reading interrupt descriptor failed (%s)\n", strerror(errno)); + } + } + } + +#endif + return ZAP_SUCCESS; +} /* For Emacs: * Local Variables: From abace923c4b8aa60daf3da41e0f53ab553dd5163 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 12 Mar 2010 21:22:42 +0000 Subject: [PATCH 1753/1766] Included zap_cpu_monitor files git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1060 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_cpu_monitor.h | 74 ++++++ libs/openzap/src/zap_cpu_monitor.c | 271 +++++++++++++++++++++ 2 files changed, 345 insertions(+) create mode 100644 libs/openzap/src/include/zap_cpu_monitor.h create mode 100644 libs/openzap/src/zap_cpu_monitor.c diff --git a/libs/openzap/src/include/zap_cpu_monitor.h b/libs/openzap/src/include/zap_cpu_monitor.h new file mode 100644 index 0000000000..d16c7ad175 --- /dev/null +++ b/libs/openzap/src/include/zap_cpu_monitor.h @@ -0,0 +1,74 @@ +/* * 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: + */ diff --git a/libs/openzap/src/zap_cpu_monitor.c b/libs/openzap/src/zap_cpu_monitor.c new file mode 100644 index 0000000000..548fd176d3 --- /dev/null +++ b/libs/openzap/src/zap_cpu_monitor.c @@ -0,0 +1,271 @@ +/* + * 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 +#else /* LINUX */ + +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "openzap.h" +#include "zap_cpu_monitor.h" +struct zap_cpu_monitor_stats +{ + /* bool, just used to retrieve the values for the first time and not calculate the percentage of idle time */ + int valid_last_times; + + /* last calculated percentage of idle time */ + double last_percentage_of_idle_time; + +#ifdef __linux__ + /* all of these are the Linux jiffies last retrieved count */ + unsigned long long last_user_time; + unsigned long long last_system_time; + unsigned long long last_idle_time; + + unsigned long long last_nice_time; + unsigned long long last_irq_time; + unsigned long long last_soft_irq_time; + unsigned long long last_io_wait_time; + unsigned long long last_steal_time; + + /* /proc/stat file descriptor used to retrieve the counters */ + int procfd; + int initd; +#elif defined (WIN32) || defined (WIN64) + __int64 i64LastUserTime; + __int64 i64LastKernelTime; + __int64 i64LastIdleTime; +#else +/* Unsupported */ +#endif +}; + +#ifdef __linux__ +static zap_status_t zap_cpu_read_stats(struct zap_cpu_monitor_stats *p, + unsigned long long *user, + unsigned long long *nice, + unsigned long long *system, + unsigned long long *idle, + unsigned long long *iowait, + unsigned long long *irq, + unsigned long long *softirq, + unsigned long long *steal) +{ +// the output of proc should not change that often from one kernel to other +// see fs/proc/proc_misc.c or fs/proc/stat.c in the Linux kernel for more details +// also man 5 proc is useful +#define CPU_ELEMENTS 8 // change this if you change the format string +#define CPU_INFO_FORMAT "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu" + static const char procfile[] = "/proc/stat"; + int rc = 0; + int myerrno = 0; + int elements = 0; + const char *cpustr = NULL; + char statbuff[1024]; + + if (!p->initd) { + p->procfd = open(procfile, O_RDONLY, 0); + if(p->procfd == -1) { + zap_log(ZAP_LOG_ERROR, "Failed to open CPU statistics file %s: %s\n", procfile, strerror(myerrno)); + return ZAP_FAIL; + } + p->initd = 1; + } else { + lseek(p->procfd, 0L, SEEK_SET); + } + + rc = read(p->procfd, statbuff, sizeof(statbuff) - 1); + if (rc <= 0) { + myerrno = errno; + zap_log(ZAP_LOG_ERROR, "Failed to read CPU statistics file %s: %s\n", procfile, strerror(myerrno)); + return ZAP_FAIL; + } + + cpustr = strstr(statbuff, "cpu "); + if (!cpustr) { + zap_log(ZAP_LOG_ERROR, "wrong format for Linux proc cpu statistics: missing cpu string\n"); + return ZAP_FAIL; + } + + elements = sscanf(cpustr, CPU_INFO_FORMAT, user, nice, system, idle, iowait, irq, softirq, steal); + if (elements != CPU_ELEMENTS) { + zap_log(ZAP_LOG_ERROR, "wrong format for Linux proc cpu statistics: expected %d elements, but just found %d\n", CPU_ELEMENTS, elements); + return ZAP_FAIL; + } + return ZAP_SUCCESS; +} +#endif + +#ifdef __linux__ +OZ_DECLARE(zap_status_t) zap_cpu_get_system_idle_time (struct zap_cpu_monitor_stats *p, double *idle_percentage) +{ + unsigned long long user, nice, system, idle, iowait, irq, softirq, steal; + unsigned long long usertime, kerneltime, idletime, totaltime, halftime; + + if (zap_cpu_read_stats(p, &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal)) { + zap_log(ZAP_LOG_ERROR, "Failed to retrieve Linux CPU statistics\n"); + return ZAP_FAIL; + } + + if (!p->valid_last_times) { + // we dont strictly need to save all of them but I feel code is more clear if we do + p->valid_last_times = 1; + p->last_user_time = user; + p->last_nice_time = nice; + p->last_system_time = system; + p->last_irq_time = irq; + p->last_soft_irq_time = softirq; + p->last_io_wait_time = iowait; + p->last_steal_time = steal; + p->last_idle_time = idle; + p->last_percentage_of_idle_time = 100.0; + *idle_percentage = p->last_percentage_of_idle_time; + return ZAP_SUCCESS; + } + + usertime = (user - p->last_user_time) + (nice - p->last_nice_time); + kerneltime = (system - p->last_system_time) + (irq - p->last_irq_time) + (softirq - p->last_soft_irq_time); + kerneltime += (iowait - p->last_io_wait_time); + kerneltime += (steal - p->last_steal_time); + idletime = (idle - p->last_idle_time); + + totaltime = usertime + kerneltime + idletime; + + if (totaltime <= 0) { + // this may happen if not enough time has elapsed and the jiffies counters are the same than the last time we checked + // jiffies depend on timer interrupts which depend on the number of HZ compile time setting of the kernel + // typical configs set HZ to 100 (that means, 100 jiffies updates per second, that is one each 10ms) + // avoid an arithmetic exception and return the same values + *idle_percentage = p->last_percentage_of_idle_time; + return ZAP_SUCCESS; + } + + halftime = totaltime / 2UL; + + p->last_percentage_of_idle_time = ((100 * idletime + halftime) / totaltime); + *idle_percentage = p->last_percentage_of_idle_time; + + p->last_user_time = user; + p->last_nice_time = nice; + p->last_system_time = system; + p->last_irq_time = irq; + p->last_soft_irq_time = softirq; + p->last_io_wait_time = iowait; + p->last_steal_time = steal; + p->last_idle_time = idle; + + return ZAP_SUCCESS; +} + +#elif defined (WIN32) || defined (WIN64) +OZ_DECLARE(zap_status_t) zap_cpu_get_system_idle_time(struct zap_cpu_monitor_stats *p, double *idle_percentage) +{ + FILETIME idleTime; + FILETIME kernelTime; + FILETIME userTime; + + if (!::GetSystemTimes(&idleTime, &kernelTime, &userTime)) { + return false; + } + + __int64 i64UserTime = (__int64)userTime.dwLowDateTime | ((__int64)userTime.dwHighDateTime << 32); + + __int64 i64KernelTime = (__int64)kernelTime.dwLowDateTime | ((__int64)kernelTime.dwHighDateTime << 32); + + __int64 i64IdleTime = (__int64)idleTime.dwLowDateTime | ((__int64)idleTime.dwHighDateTime << 32); + + if (p->valid_last_times) { + __int64 i64User = i64UserTime - p->i64LastUserTime; + __int64 i64Kernel = i64KernelTime - p->i64LastKernelTime; + __int64 i64Idle = i64IdleTime - p->i64LastIdleTime; + __int64 i64System = i64User + i64Kernel; + *idle_percentage = 100.0 * i64Idle / i64System; + } else { + *idle_percentage = 100.0; + p->valid_last_times = 1; + } + + /* Remember current value for the next call */ + p->i64LastUserTime = i64UserTime; + p->i64LastKernelTime = i64KernelTime; + p->i64LastIdleTime = i64IdleTime; + + /* Success */ + return ZAP_SUCCESS; +} +#else +/* Unsupported */ +OZ_DECLARE(zap_status_t) zap_cpu_get_system_idle_time(struct zap_cpu_monitor_stats *p, double *idle_percentage) +{ + return ZAP_FAIL; +} +#endif + +OZ_DECLARE(struct zap_cpu_monitor_stats*) zap_new_cpu_monitor(void) +{ + return calloc(1, sizeof(struct zap_cpu_monitor_stats)); +} + +OZ_DECLARE(void) zap_delete_cpu_monitor(struct zap_cpu_monitor_stats *p) +{ +#ifdef __linux__ + close(p->procfd); +#endif + free(p); +} + + +/* 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: + */ From db6194be569def3ee28b29631995a8a500464e9e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Mar 2010 21:52:41 +0000 Subject: [PATCH 1754/1766] added the ability to set the audio gain in openzap channels via software git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1061 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 40 +++++++- libs/openzap/src/include/openzap.h | 7 +- libs/openzap/src/include/zap_types.h | 5 +- libs/openzap/src/zap_io.c | 122 ++++++++++++++++++++++++- 4 files changed, 168 insertions(+), 6 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index c9159f3cb7..5cad5abb79 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2878,7 +2878,7 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s ); } -#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix]" +#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains " SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; @@ -3067,6 +3067,44 @@ SWITCH_STANDARD_API(oz_function) goto end; } + } else if (!strcasecmp(argv[0], "gains")) { + int i = 0; + float txgain = 0.0; + float rxgain = 0.0; + uint32_t chan_id = 0; + zap_span_t *span = NULL; + if (argc < 4) { + stream->write_function(stream, "-ERR Usage: oz gains []\n"); + goto end; + } + zap_span_find_by_name(argv[3], &span); + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + if (argc > 4) { + chan_id = atoi(argv[4]); + if (chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid chan\n"); + goto end; + } + } + i = sscanf(argv[1], "%f", &rxgain); + i += sscanf(argv[2], "%f", &txgain); + if (i != 2) { + stream->write_function(stream, "-ERR invalid gains\n"); + goto end; + } + if (chan_id) { + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_RX_GAIN, &rxgain); + zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_TX_GAIN, &txgain); + } else { + for (i = 1; i < span->chan_count; i++) { + zap_channel_command(span->channels[i], ZAP_COMMAND_SET_RX_GAIN, &rxgain); + zap_channel_command(span->channels[i], ZAP_COMMAND_SET_TX_GAIN, &txgain); + } + } + stream->write_function(stream, "+OK gains set to Rx %f and Tx %f\n", rxgain, txgain); } else { char *rply = zap_api_execute(cmd, NULL); diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 18275c43bf..8fde5795d5 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -494,7 +494,8 @@ typedef enum { ZAP_TYPE_CHANNEL } zap_data_type_t; - +/* 2^8 table size, one for each byte value */ +#define ZAP_GAINS_TABLE_SIZE 256 struct zap_channel { zap_data_type_t data_type; uint32_t span_id; @@ -556,6 +557,10 @@ struct zap_channel { zap_hash_t *variable_hash; unsigned char rx_cas_bits; uint32_t pre_buffer_size; + unsigned char rxgain_table[ZAP_GAINS_TABLE_SIZE]; + unsigned char txgain_table[ZAP_GAINS_TABLE_SIZE]; + float rxgain; + float txgain; }; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1ac2e86ba4..3bb726148e 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -69,6 +69,7 @@ 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 @@ -380,7 +381,9 @@ typedef enum { ZAP_CHANNEL_PROGRESS = (1 << 21), ZAP_CHANNEL_MEDIA = (1 << 22), ZAP_CHANNEL_ANSWERED = (1 << 23), - ZAP_CHANNEL_MUTE = (1 << 24) + 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 { diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index f0acf1ba27..8ca5e71b56 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -35,8 +35,6 @@ #ifndef WIN32 #endif #include "openzap.h" -//#include "zap_isdn.h" -//#include "zap_ss7_boost.h" #include #ifdef WIN32 #include @@ -569,8 +567,67 @@ OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapna } +#define ZAP_SLINEAR_MAX_VALUE 32767 +#define ZAP_SLINEAR_MIN_VALUE -32767 +static void reset_gain_table(unsigned char *gain_table, float new_gain, zap_codec_t codec_gain) +{ + /* sample value */ + unsigned sv = 0; + /* linear gain factor */ + float lingain = 0; + /* linear value for each table sample */ + float linvalue = 0; + /* amplified (or attenuated in case of negative amplification) sample value */ + int ampvalue = 0; + + /* gain tables are only for alaw and ulaw */ + if (codec_gain != ZAP_CODEC_ALAW && codec_gain != ZAP_CODEC_ULAW) { + zap_log(ZAP_LOG_WARNING, "Not resetting gain table because codec is not ALAW or ULAW but %d\n", codec_gain); + return; + } + + if (!new_gain) { + /* for a 0.0db gain table, each alaw/ulaw sample value is left untouched (0 ==0, 1 == 1, 2 == 2 etc)*/ + sv = 0; + while (1) { + gain_table[sv] = sv; + if (sv == (ZAP_GAINS_TABLE_SIZE - 1)) { + break; + } + sv++; + } + return; + } + + /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wikipedia.org/wiki/20_log_rule#Definitions */ + lingain = pow(10.0, new_gain/ 20.0); + sv = 0; + while (1) { + /* get the linear value for this alaw/ulaw sample value */ + linvalue = codec_gain == ZAP_CODEC_ALAW ? alaw_to_linear(sv) : ulaw_to_linear(sv); + + /* multiply the linear value and the previously calculated linear gain */ + ampvalue = (int)(linvalue * lingain); + + /* chop it if goes beyond the limits */ + if (ampvalue > ZAP_SLINEAR_MAX_VALUE) { + ampvalue = ZAP_SLINEAR_MAX_VALUE; + } + + if (ampvalue < ZAP_SLINEAR_MIN_VALUE) { + ampvalue = ZAP_SLINEAR_MIN_VALUE; + } + gain_table[sv] = codec_gain == ZAP_CODEC_ALAW ? linear_to_alaw(ampvalue) : linear_to_ulaw(ampvalue); + if (sv == (ZAP_GAINS_TABLE_SIZE-1)) { + break; + } + sv++; + } +} + OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan) { + unsigned i = 0; if (span->chan_count < ZAP_MAX_CHANNELS_SPAN) { zap_channel_t *new_chan = span->channels[++span->chan_count]; @@ -608,6 +665,17 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); + /* set 0.0db gain table */ + i = 0; + while (1) { + new_chan->txgain_table[i] = i; + new_chan->rxgain_table[i] = i; + if (i == (sizeof(new_chan->txgain_table)-1)) { + break; + } + i++; + } + zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); *chan = new_chan; return ZAP_SUCCESS; @@ -1663,6 +1731,39 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t zap_mutex_unlock(zchan->pre_buffer_mutex); } break; + + case ZAP_COMMAND_SET_RX_GAIN: + { + zchan->rxgain = ZAP_COMMAND_OBJ_FLOAT; + reset_gain_table(zchan->rxgain_table, zchan->rxgain, zchan->native_codec); + if (zchan->rxgain == 0.0) { + zap_clear_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); + } + } + break; + case ZAP_COMMAND_GET_RX_GAIN: + { + ZAP_COMMAND_OBJ_FLOAT = zchan->rxgain; + } + break; + case ZAP_COMMAND_SET_TX_GAIN: + { + zchan->txgain = ZAP_COMMAND_OBJ_FLOAT; + reset_gain_table(zchan->txgain_table, zchan->txgain, zchan->native_codec); + if (zchan->txgain == 0.0) { + zap_clear_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); + } + } + break; + case ZAP_COMMAND_GET_TX_GAIN: + { + ZAP_COMMAND_OBJ_FLOAT = zchan->txgain; + } + break; default: break; } @@ -2042,10 +2143,10 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; zap_size_t max = *datalen; + unsigned i = 0; assert(zchan != NULL); assert(zchan->zio != NULL); - assert(zchan->zio != NULL); if (!zap_test_flag(zchan, ZAP_CHANNEL_OPEN)) { snprintf(zchan->last_error, sizeof(zchan->last_error), "channel not open"); @@ -2067,6 +2168,13 @@ OZ_DECLARE(zap_status_t) zap_channel_read(zap_channel_t *zchan, void *data, zap_ } if (status == ZAP_SUCCESS) { + if (zap_test_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN) + && (zchan->native_codec == ZAP_CODEC_ALAW || zchan->native_codec == ZAP_CODEC_ULAW)) { + unsigned char *rdata = data; + for (i = 0; i < *datalen; i++) { + rdata[i] = zchan->rxgain_table[rdata[i]]; + } + } handle_dtmf(zchan, *datalen); } @@ -2265,6 +2373,7 @@ OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap zap_status_t status = ZAP_FAIL; zio_codec_t codec_func = NULL; zap_size_t max = datasize; + unsigned i = 0; assert(zchan != NULL); assert(zchan->zio != NULL); @@ -2314,6 +2423,13 @@ OZ_DECLARE(zap_status_t) zap_channel_write(zap_channel_t *zchan, void *data, zap } } + if (zap_test_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN) + && (zchan->native_codec == ZAP_CODEC_ALAW || zchan->native_codec == ZAP_CODEC_ULAW)) { + unsigned char *wdata = data; + for (i = 0; i < *datalen; i++) { + wdata[i] = zchan->txgain_table[wdata[i]]; + } + } status = zchan->zio->write(zchan, data, datalen); return status; From b07a41cec088cf2a000ecb1e872e92856ea6ba86 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Mar 2010 22:47:50 +0000 Subject: [PATCH 1755/1766] added configuration of gains in openzap.conf and display through CLI git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1062 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 8 ++++++ libs/openzap/src/include/zap_types.h | 2 ++ libs/openzap/src/zap_io.c | 37 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 5cad5abb79..f03f8309db 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2810,6 +2810,8 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea "type: %s\n" "state: %s\n" "last_state: %s\n" + "txgain: %3.2f\n" + "rxgain: %3.2f\n" "cid_date: %s\n" "cid_name: %s\n" "cid_num: %s\n" @@ -2825,6 +2827,8 @@ void dump_chan(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *strea zap_chan_type2str(span->channels[chan_id]->type), zap_channel_state2str(span->channels[chan_id]->state), zap_channel_state2str(span->channels[chan_id]->last_state), + span->channels[chan_id]->txgain, + span->channels[chan_id]->rxgain, span->channels[chan_id]->caller_data.cid_date, span->channels[chan_id]->caller_data.cid_name, span->channels[chan_id]->caller_data.cid_num.digits, @@ -2851,6 +2855,8 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s " %s\n" " %s\n" " %s\n" + " %3.2f\n" + " %3.2f\n" " %s\n" " %s\n" " %s\n" @@ -2867,6 +2873,8 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s zap_chan_type2str(span->channels[chan_id]->type), zap_channel_state2str(span->channels[chan_id]->state), zap_channel_state2str(span->channels[chan_id]->last_state), + span->channels[chan_id]->txgain, + span->channels[chan_id]->rxgain, span->channels[chan_id]->caller_data.cid_date, span->channels[chan_id]->caller_data.cid_name, span->channels[chan_id]->caller_data.cid_num.digits, diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 3bb726148e..effd2c41e1 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -317,6 +317,8 @@ typedef enum { #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), diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8ca5e71b56..ea6d987b7a 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -2523,6 +2523,22 @@ OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd) return rval; } +static void zap_set_channels_gains(zap_span_t *span, int currindex, float rxgain, float txgain) +{ + unsigned chan_index = 0; + + if (!span->chan_count) { + return; + } + + for (chan_index = currindex+1; chan_index <= span->chan_count; chan_index++) { + if (!ZAP_IS_VOICE_CHANNEL(span->channels[chan_index])) { + continue; + } + zap_channel_command(span->channels[chan_index], ZAP_COMMAND_SET_RX_GAIN, &rxgain); + zap_channel_command(span->channels[chan_index], ZAP_COMMAND_SET_TX_GAIN, &txgain); + } +} static zap_status_t load_config(void) { @@ -2536,6 +2552,9 @@ static zap_status_t load_config(void) char number[25] = ""; zap_io_interface_t *zio = NULL; zap_analog_start_type_t tmp; + float rxgain = 0.0; + float txgain = 0.0; + int chanindex = 0; if (!zap_config_open_file(&cfg, cfg_name)) { return ZAP_FAIL; @@ -2640,7 +2659,9 @@ static zap_status_t load_config(void) zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_FXO) { + chanindex = span->chan_count; configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXO, name, number); + zap_set_channels_gains(span, chanindex, rxgain, txgain); } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXO channels to an FXS trunk!\n"); } @@ -2651,7 +2672,9 @@ static zap_status_t load_config(void) zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_FXS) { + chanindex = span->chan_count; configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_FXS, name, number); + zap_set_channels_gains(span, chanindex, rxgain, txgain); } else { zap_log(ZAP_LOG_WARNING, "Cannot add FXS channels to an FXO trunk!\n"); } @@ -2662,12 +2685,16 @@ static zap_status_t load_config(void) zap_analog_start_type2str(span->start_type)); } if (span->trunk_type == ZAP_TRUNK_EM) { + chanindex = span->chan_count; configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_EM, name, number); + zap_set_channels_gains(span, chanindex, rxgain, txgain); } else { zap_log(ZAP_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); } } else if (!strcasecmp(var, "b-channel")) { + chanindex = span->chan_count; configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_B, name, number); + zap_set_channels_gains(span, chanindex, rxgain, txgain); } else if (!strcasecmp(var, "d-channel")) { if (d) { zap_log(ZAP_LOG_WARNING, "ignoring extra d-channel\n"); @@ -2683,10 +2710,20 @@ static zap_status_t load_config(void) d++; } } else if (!strcasecmp(var, "cas-channel")) { + chanindex = span->chan_count; configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_CAS, name, number); + zap_set_channels_gains(span, chanindex, rxgain, txgain); } else if (!strcasecmp(var, "dtmf_hangup")) { span->dtmf_hangup = strdup(val); span->dtmf_hangup_len = strlen(val); + } else if (!strcasecmp(var, "txgain")) { + if (sscanf(val, "%f", &txgain) != 1) { + zap_log(ZAP_LOG_ERROR, "invalid txgain: '%s'\n", val); + } + } else if (!strcasecmp(var, "rxgain")) { + if (sscanf(val, "%f", &rxgain) != 1) { + zap_log(ZAP_LOG_ERROR, "invalid rxgain: '%s'\n", val); + } } else { zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var); } From fa61207e4cb183c1e02f08cea6506621a95ea087 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 12 Mar 2010 23:09:15 +0000 Subject: [PATCH 1756/1766] fix segfault in the cpu monitor code git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1063 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index ea6d987b7a..858635f128 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -129,8 +129,8 @@ ZAP_STR2ENUM(zap_str2zap_mdmf_type, zap_mdmf_type2str, zap_mdmf_type_t, MDMF_TYP ZAP_ENUM_NAMES(CHAN_TYPE_NAMES, CHAN_TYPE_STRINGS) ZAP_STR2ENUM(zap_str2zap_chan_type, zap_chan_type2str, zap_chan_type_t, CHAN_TYPE_NAMES, ZAP_CHAN_TYPE_COUNT) -static zap_status_t zap_cpu_monitor_start(cpu_monitor_t* monitor_params); -static void zap_cpu_monitor_stop(cpu_monitor_t* monitor_params); +static zap_status_t zap_cpu_monitor_start(void); +static void zap_cpu_monitor_stop(void); static const char *cut_path(const char *in) { @@ -3059,7 +3059,7 @@ OZ_DECLARE(zap_status_t) zap_global_init(void) globals.running = 1; if (!zap_cpu_monitor_disabled) { - if (zap_cpu_monitor_start(&globals.cpu_monitor) != ZAP_SUCCESS) { + if (zap_cpu_monitor_start() != ZAP_SUCCESS) { return ZAP_FAIL; } } @@ -3080,7 +3080,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) time_end(); globals.running = 0; - zap_cpu_monitor_stop(&globals.cpu_monitor); + zap_cpu_monitor_stop(); zap_span_close_all(); zap_sleep(1000); @@ -3134,7 +3134,6 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void) zap_mutex_unlock(globals.mutex); zap_mutex_destroy(&globals.mutex); zap_mutex_destroy(&globals.span_mutex); - zap_interrupt_destroy(&globals.cpu_monitor.interrupt); memset(&globals, 0, sizeof(globals)); return ZAP_SUCCESS; } @@ -3463,26 +3462,40 @@ static void *zap_cpu_monitor_run(zap_thread_t *me, void *obj) } -static zap_status_t zap_cpu_monitor_start(cpu_monitor_t* monitor) +static zap_status_t zap_cpu_monitor_start(void) { - if (zap_interrupt_create(&monitor->interrupt, ZAP_INVALID_SOCKET) != ZAP_SUCCESS) { + if (zap_interrupt_create(&globals.cpu_monitor.interrupt, ZAP_INVALID_SOCKET) != ZAP_SUCCESS) { zap_log(ZAP_LOG_CRIT, "Failed to create CPU monitor interrupt\n"); return ZAP_FAIL; } - if (zap_thread_create_detached(zap_cpu_monitor_run, monitor) != ZAP_SUCCESS) { + if (zap_thread_create_detached(zap_cpu_monitor_run, &globals.cpu_monitor) != ZAP_SUCCESS) { zap_log(ZAP_LOG_CRIT, "Failed to create cpu monitor thread!!\n"); return ZAP_FAIL; } return ZAP_SUCCESS; } -static void zap_cpu_monitor_stop(cpu_monitor_t* monitor) +static void zap_cpu_monitor_stop(void) { - zap_interrupt_signal(monitor->interrupt); - while(monitor->running) { + if (!globals.cpu_monitor.interrupt) { + return; + } + + if (!globals.cpu_monitor.running) { + return; + } + + if (zap_interrupt_signal(globals.cpu_monitor.interrupt) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "Failed to stop CPU monitor\n"); + return; + } + + while(globals.cpu_monitor.running) { zap_sleep(10); } + + zap_interrupt_destroy(&globals.cpu_monitor.interrupt); } OZ_DECLARE(void) zap_cpu_monitor_disable(void) From 1caf72ed8662fa2fdae77246dc81c439726d2ee9 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 15 Mar 2010 13:57:04 +0000 Subject: [PATCH 1757/1766] log as error socket open failure git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1064 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 6149cb1c9b..5e0e32d9ee 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -1400,7 +1400,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) 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_DEBUG, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); + zap_log(ZAP_LOG_ERROR, "Error: Opening MCON Socket [%d] %s\n", sangoma_boost_data->mcon.socket, strerror(errno)); goto end; } @@ -1409,7 +1409,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj) ++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_DEBUG, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); + zap_log(ZAP_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); goto end; } From 174b1a3622bbb1e1493854521d949a64e07a9be1 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 15 Mar 2010 14:57:00 +0000 Subject: [PATCH 1758/1766] unloading modules has to be the last thing to do git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1065 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 221bf34117..6a1b21c6ad 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -3563,8 +3563,6 @@ FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) ftdm_span_close_all(); - ftdm_unload_modules(); - ftdm_mutex_lock(globals.span_mutex); for (sp = globals.spans; sp;) { ftdm_span_t *cur_span = sp; @@ -3585,6 +3583,8 @@ FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) globals.spans = NULL; ftdm_mutex_unlock(globals.span_mutex); + ftdm_unload_modules(); + ftdm_mutex_lock(globals.mutex); hashtable_destroy(globals.interface_hash); hashtable_destroy(globals.module_hash); From d875a8ae781c71714de35a452bda4a958b4505d9 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 16 Mar 2010 14:12:42 +0000 Subject: [PATCH 1759/1766] fix windows compilation git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1066 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- libs/openzap/src/include/zap_types.h | 4 ++++ libs/openzap/src/zap_io.c | 22 ++++++++++++++-------- libs/openzap/src/zap_threadmutex.c | 14 +++++++++----- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index f03f8309db..a6b6c33c03 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -3107,7 +3107,7 @@ SWITCH_STANDARD_API(oz_function) zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_RX_GAIN, &rxgain); zap_channel_command(span->channels[chan_id], ZAP_COMMAND_SET_TX_GAIN, &txgain); } else { - for (i = 1; i < span->chan_count; i++) { + for (i = 1; i < (int)span->chan_count; i++) { zap_channel_command(span->channels[i], ZAP_COMMAND_SET_RX_GAIN, &rxgain); zap_channel_command(span->channels[i], ZAP_COMMAND_SET_TX_GAIN, &txgain); } diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index effd2c41e1..a97f98abd7 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -35,7 +35,11 @@ #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 diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 858635f128..d7bf941341 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -572,7 +572,7 @@ OZ_DECLARE(zap_status_t) zap_span_load_tones(zap_span_t *span, const char *mapna static void reset_gain_table(unsigned char *gain_table, float new_gain, zap_codec_t codec_gain) { /* sample value */ - unsigned sv = 0; + uint8_t sv = 0; /* linear gain factor */ float lingain = 0; /* linear value for each table sample */ @@ -590,7 +590,7 @@ static void reset_gain_table(unsigned char *gain_table, float new_gain, zap_code /* for a 0.0db gain table, each alaw/ulaw sample value is left untouched (0 ==0, 1 == 1, 2 == 2 etc)*/ sv = 0; while (1) { - gain_table[sv] = sv; + gain_table[sv] = (unsigned char)sv; if (sv == (ZAP_GAINS_TABLE_SIZE - 1)) { break; } @@ -600,11 +600,11 @@ static void reset_gain_table(unsigned char *gain_table, float new_gain, zap_code } /* use the 20log rule to increase the gain: http://en.wikipedia.org/wiki/Gain, http:/en.wikipedia.org/wiki/20_log_rule#Definitions */ - lingain = pow(10.0, new_gain/ 20.0); + lingain = (float)pow(10.0f, new_gain/20.0f); sv = 0; while (1) { /* get the linear value for this alaw/ulaw sample value */ - linvalue = codec_gain == ZAP_CODEC_ALAW ? alaw_to_linear(sv) : ulaw_to_linear(sv); + linvalue = codec_gain == ZAP_CODEC_ALAW ? (float)alaw_to_linear(sv) : (float)ulaw_to_linear(sv); /* multiply the linear value and the previously calculated linear gain */ ampvalue = (int)(linvalue * lingain); @@ -668,8 +668,8 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc /* set 0.0db gain table */ i = 0; while (1) { - new_chan->txgain_table[i] = i; - new_chan->rxgain_table[i] = i; + new_chan->txgain_table[i] = (unsigned char)i; + new_chan->rxgain_table[i] = (unsigned char)i; if (i == (sizeof(new_chan->txgain_table)-1)) { break; } @@ -2736,13 +2736,13 @@ static zap_status_t load_config(void) } } else if (!strncasecmp(var, "cpu_set_alarm_threshold", 22)) { if (atoi(val) > 0 && atoi(val) < 100) { - globals.cpu_monitor.set_alarm_threshold = atoi(val); + globals.cpu_monitor.set_alarm_threshold = (uint8_t)atoi(val); } else { zap_log(ZAP_LOG_ERROR, "Invalid cpu alarm set threshold %s\n", val); } } else if (!strncasecmp(var, "cpu_reset_alarm_threshold", 22)) { if (atoi(val) > 0 && atoi(val) < 100) { - globals.cpu_monitor.reset_alarm_threshold = atoi(val); + globals.cpu_monitor.reset_alarm_threshold = (uint8_t)atoi(val); if (globals.cpu_monitor.reset_alarm_threshold > globals.cpu_monitor.set_alarm_threshold) { globals.cpu_monitor.reset_alarm_threshold = globals.cpu_monitor.set_alarm_threshold-10; zap_log(ZAP_LOG_ERROR, "Cpu alarm reset threshold must be lower than set threshold, set threshold to %d\n", globals.cpu_monitor.reset_alarm_threshold); @@ -3427,6 +3427,7 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha static void *zap_cpu_monitor_run(zap_thread_t *me, void *obj) { +#ifndef WIN32 cpu_monitor_t *monitor = (cpu_monitor_t *)obj; struct zap_cpu_monitor_stats *cpu_stats = zap_new_cpu_monitor(); if (!cpu_stats) { @@ -3458,6 +3459,11 @@ static void *zap_cpu_monitor_run(zap_thread_t *me, void *obj) } zap_delete_cpu_monitor(cpu_stats); monitor->running = 0; +#else + UNREFERENCED_PARAMETER(me); + UNREFERENCED_PARAMETER(obj); +#endif + return NULL; } diff --git a/libs/openzap/src/zap_threadmutex.c b/libs/openzap/src/zap_threadmutex.c index 5307f2bd7e..4c2f8ac312 100644 --- a/libs/openzap/src/zap_threadmutex.c +++ b/libs/openzap/src/zap_threadmutex.c @@ -256,8 +256,8 @@ OZ_DECLARE(zap_status_t) zap_interrupt_create(zap_interrupt_t **ininterrupt, zap interrupt->device = device; #ifdef WIN32 - interrupt->interrupt = CreateEvent(NULL, FALSE, FALSE, NULL); - if (!interrupt->interrupt) { + interrupt->event = CreateEvent(NULL, FALSE, FALSE, NULL); + if (!interrupt->event) { zap_log(ZAP_LOG_ERROR, "Failed to allocate interrupt event\n"); goto failed; } @@ -310,7 +310,7 @@ OZ_DECLARE(zap_status_t) zap_interrupt_wait(zap_interrupt_t *interrupt, int ms) num++; ints[1] = interrupt->device; } - res = WaitForMultipleObjects(num, &ints, FALSE, ms >= 0 ? ms : INFINITE); + res = WaitForMultipleObjects(num, ints, FALSE, ms >= 0 ? ms : INFINITE); switch (res) { case WAIT_TIMEOUT: return ZAP_TIMEOUT; @@ -360,7 +360,7 @@ 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) { #ifdef WIN32 - if (!SetEvent(interrupt->interrupt)) { + if (!SetEvent(interrupt->event)) { zap_log(ZAP_LOG_ERROR, "Failed to signal interrupt\n"); return ZAP_FAIL; } @@ -379,7 +379,7 @@ OZ_DECLARE(zap_status_t) zap_interrupt_destroy(zap_interrupt_t **ininterrupt) zap_interrupt_t *interrupt = NULL; interrupt = *ininterrupt; #ifdef WIN32 - CloseHandle(interrupt->interrupt); + CloseHandle(interrupt->event); #else close(interrupt->readfd); close(interrupt->writefd); @@ -434,6 +434,10 @@ OZ_DECLARE(zap_status_t) zap_interrupt_multiple_wait(zap_interrupt_t *interrupts } } +#elif defined(__WINDOWS__) + UNREFERENCED_PARAMETER(interrupts); + UNREFERENCED_PARAMETER(size); + UNREFERENCED_PARAMETER(ms); #endif return ZAP_SUCCESS; } From afab7cdff9d2297761efd870eaba5989dd8d1f83 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 17 Mar 2010 22:35:29 +0000 Subject: [PATCH 1760/1766] Fix for TON and NPI not passed through to channel variables on incoming calls git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1067 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index a6b6c33c03..ca7ba37b7a 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -1417,6 +1417,15 @@ zap_status_t zap_channel_from_event(zap_sigmsg_t *sigmsg, switch_core_session_t switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_SCREEN); } + tech_pvt->caller_profile->caller_ton = sigmsg->channel->caller_data.cid_num.type; + tech_pvt->caller_profile->caller_numplan = sigmsg->channel->caller_data.cid_num.plan; + tech_pvt->caller_profile->ani_ton = sigmsg->channel->caller_data.ani.type; + tech_pvt->caller_profile->ani_numplan = sigmsg->channel->caller_data.ani.plan; + tech_pvt->caller_profile->destination_number_ton = sigmsg->channel->caller_data.dnis.type; + tech_pvt->caller_profile->destination_number_numplan = sigmsg->channel->caller_data.dnis.plan; + tech_pvt->caller_profile->rdnis_ton = sigmsg->channel->caller_data.rdnis.type; + tech_pvt->caller_profile->rdnis_numplan = sigmsg->channel->caller_data.rdnis.plan; + if (sigmsg->channel->caller_data.pres) { switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER); } From c5266d1ebaa4bacfdd0b6fec5772c911a56eb525 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 18 Mar 2010 04:10:40 +0000 Subject: [PATCH 1761/1766] fix gains syntax string git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1068 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/mod_openzap/mod_openzap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index ca7ba37b7a..563972f5a4 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2895,7 +2895,7 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s ); } -#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains " +#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains []" SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; From df91a7c8bdddebe09977edaca92ebbab70de8b02 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 18 Mar 2010 14:13:05 +0000 Subject: [PATCH 1762/1766] return success after setting gains git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1069 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/zap_io.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index d7bf941341..dc747d9429 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1741,11 +1741,13 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t } else { zap_set_flag(zchan, ZAP_CHANNEL_USE_RX_GAIN); } + GOTO_STATUS(done, ZAP_SUCCESS); } break; case ZAP_COMMAND_GET_RX_GAIN: { ZAP_COMMAND_OBJ_FLOAT = zchan->rxgain; + GOTO_STATUS(done, ZAP_SUCCESS); } break; case ZAP_COMMAND_SET_TX_GAIN: @@ -1757,11 +1759,13 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t } else { zap_set_flag(zchan, ZAP_CHANNEL_USE_TX_GAIN); } + GOTO_STATUS(done, ZAP_SUCCESS); } break; case ZAP_COMMAND_GET_TX_GAIN: { ZAP_COMMAND_OBJ_FLOAT = zchan->txgain; + GOTO_STATUS(done, ZAP_SUCCESS); } break; default: From 28561b8867e43681c67dcc203402c9931fccbeab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 19 Mar 2010 18:49:29 +0000 Subject: [PATCH 1763/1766] change zt echo can to default to off and do not engage it when there is no preference and fix regression from OPENZAP-76 git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1070 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 49 ++++++++++------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 111e5a26ab..9061b7c562 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -546,7 +546,17 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) } 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) { @@ -601,24 +611,9 @@ static ZIO_OPEN_FUNCTION(zt_open) zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); return ZAP_FAIL; } - } else if (zchan->type == ZAP_CHAN_TYPE_FXS || zchan->type == ZAP_CHAN_TYPE_FXO || zchan->type == ZAP_CHAN_TYPE_EM) { - int len = zt_globals.eclevel; - 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); - //snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); - //zap_log(ZAP_LOG_ERROR, "%s\n", zchan->last_error); - //return ZAP_FAIL; - } else { - 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); - //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) { + + if (zt_globals.rxgain || zt_globals.txgain) { struct zt_gains gains; memset(&gains, 0, sizeof(gains)); @@ -636,17 +631,19 @@ static ZIO_OPEN_FUNCTION(zt_open) } } - int len = zt_globals.eclevel; - zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, zchan->span_id, zchan->chan_id); - if (ioctl(zchan->sockfd, codes.ECHOCANCEL, &len)) { + if (zt_globals.eclevel > 0) { + int len = zt_globals.eclevel; + zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, 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 { + } 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); + zap_log(ZAP_LOG_WARNING, "Echo training not available for %d:%d\n", zchan->span_id, zchan->chan_id); } - } - + } + } + } return ZAP_SUCCESS; } @@ -1195,7 +1192,7 @@ static ZIO_IO_LOAD_FUNCTION(zt_init) zt_globals.codec_ms = 20; zt_globals.wink_ms = 150; zt_globals.flash_ms = 750; - zt_globals.eclevel = 64; + zt_globals.eclevel = 0; zt_globals.etlevel = 0; zt_interface.name = "zt"; From efe0bdede74982a8b931f795b605004ad3c15732 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 19 Mar 2010 19:00:02 +0000 Subject: [PATCH 1764/1766] tweak on last commit git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1071 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c index 9061b7c562..15803017b5 100644 --- a/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c +++ b/libs/openzap/src/ozmod/ozmod_zt/ozmod_zt.c @@ -631,12 +631,18 @@ static ZIO_OPEN_FUNCTION(zt_open) } } - if (zt_globals.eclevel > 0) { + if (zt_globals.eclevel >= 0) { int len = zt_globals.eclevel; - zap_log(ZAP_LOG_INFO, "Setting echo cancel to %d taps for %d:%d\n", len, zchan->span_id, zchan->chan_id); + + 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) { + } 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); From 6d05c98a8257cd61131720a043d45e76ec4ca20d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 24 Mar 2010 21:48:53 +0000 Subject: [PATCH 1765/1766] fix for warnings when including freetdm.h git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1072 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/include/freetdm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 966cca210b..0900c62800 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -554,7 +554,7 @@ struct ftdm_channel { uint32_t extra_id; ftdm_chan_type_t type; ftdm_socket_t sockfd; - ftdm_channel_flag_t flags; + uint32_t flags; uint32_t pflags; uint32_t sflags; ftdm_alarm_flag_t alarm_flags; From 2340dfeac15c9297ef4a7b6e2306debdef118ee6 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 26 Mar 2010 15:08:54 +0000 Subject: [PATCH 1766/1766] Fix for ftdm_multiple_wait not reading proper file descriptors git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@1073 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/ftdm_threadmutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftdm_threadmutex.c b/libs/freetdm/src/ftdm_threadmutex.c index 49cdb59cc1..34c802b1de 100644 --- a/libs/freetdm/src/ftdm_threadmutex.c +++ b/libs/freetdm/src/ftdm_threadmutex.c @@ -432,9 +432,9 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_multiple_wait(ftdm_interrupt_t *interru return FTDM_TIMEOUT; } - for (i = size; i < ftdm_array_len(ints); i++) { + for (i = 0; i < size; i++) { if (ints[i].revents & POLLIN) { - res = read(ints[0].fd, pipebuf, sizeof(pipebuf)); + res = read(ints[i].fd, pipebuf, sizeof(pipebuf)); if (res == -1) { ftdm_log(FTDM_LOG_CRIT, "reading interrupt descriptor failed (%s)\n", strerror(errno)); }